master-zapier-plan-draft/packages/verae-activate/authentication.js
George Lambert b814501441 Milestone 1: Add Numbers Zapier app, /v1/add, developer setup guide
packages/verae-activate is pushable with zapier-platform 19.1.0: local
Add Numbers (number1+number2=sum) needs no hosted API. zapier-platform
validate is clean (0 warnings). zappier POST /v1/add is a free metered
endpoint for the optional hosted path.

Tests: verae-activate 7/7, zappier 176/176, verae-zapier 5/5, middleware
gate 1 11/11. Morning steps: docs/04-activate/SETUP-ZAPIER-DEVELOPER.md

Learned: perform runs on Zapier cloud so arithmetic needs no public URL;
CLI and zapier-platform-core majors must match; do not mix zapier-sdk.
2026-09-09 02:41:34 -04:00

57 lines
1.6 KiB
JavaScript

/**
* Connection for the activate-now Zapier app.
*
* No live Verae or zappier server is required. The test always succeeds so a
* developer can push and run Add Numbers before billing or timestamping is wired.
*
* Optional later: set ZAPPIER_API_BASE + api_key to send Add Numbers through
* packages/zappier POST /v1/add.
*
* @module authentication
*/
/**
* @param {object} z
* @param {object} bundle
* @returns {Promise<{ok: boolean, mode: string, label: string}>}
*/
const testAuth = async (z, bundle) => {
const base = (bundle.authData.api_base || process.env.ZAPPIER_API_BASE || '').replace(/\/$/, '');
const key = bundle.authData.api_key || '';
if (base && key) {
const response = await z.request({
url: `${base}/v1/status`,
headers: { 'x-api-key': key },
});
return {
ok: true,
mode: 'hosted',
label: response.data?.status === 'ok' ? 'zappier' : 'hosted',
};
}
return { ok: true, mode: 'local', label: 'Verae Time (Add Numbers)' };
};
module.exports = {
type: 'custom',
fields: [
{
key: 'api_key',
type: 'string',
required: false,
label: 'API Key (optional)',
helpText:
'Leave blank for Add Numbers (runs inside Zapier). Later, paste a key from your zappier portal. See https://github.com/zapier/zapier-platform#authentication',
},
{
key: 'api_base',
type: 'string',
required: false,
label: 'API base URL (optional)',
helpText:
'Example: https://your-host.example.com — only needed when routing Add Numbers to hosted /v1/add.',
},
],
test: testAuth,
connectionLabel: '{{label}}',
};