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.
78 lines
2.2 KiB
JavaScript
78 lines
2.2 KiB
JavaScript
/**
|
|
* Verae Zapier Platform app definition.
|
|
* @module index
|
|
*/
|
|
|
|
const authentication = require('./authentication');
|
|
const timestampAndWait = require('./creates/timestamp_and_wait');
|
|
const createTimestamp = require('./creates/create_timestamp');
|
|
const verifyTimestamp = require('./creates/verify_timestamp');
|
|
const batchTimestamp = require('./creates/batch_timestamp');
|
|
const addNumbers = require('./creates/add_numbers');
|
|
const jobStatus = require('./searches/job_status');
|
|
const timestampCompleted = require('./triggers/timestamp_completed');
|
|
|
|
/**
|
|
* Attach middleware API key to every outbound request.
|
|
* @param {object} request
|
|
* @param {object} _z
|
|
* @param {object} bundle
|
|
*/
|
|
const addApiKey = (request, _z, bundle) => {
|
|
request.headers = request.headers || {};
|
|
request.headers.Authorization = `Bearer ${bundle.authData.api_key}`;
|
|
return request;
|
|
};
|
|
|
|
/**
|
|
* Map middleware billing errors to Zapier errors.
|
|
* @param {object} response
|
|
* @param {object} z
|
|
*/
|
|
const mapMiddlewareErrors = (response, z) => {
|
|
if (response.status === 402) {
|
|
throw new z.errors.Error(
|
|
`${response.data?.error ?? 'Quota exceeded'}. Upgrade at ${response.data?.details?.upgradeUrl ?? response.data?.upgradeUrl ?? 'your billing portal'}.`,
|
|
'QuotaExceeded',
|
|
402,
|
|
);
|
|
}
|
|
|
|
if (response.status === 403 && response.data?.code === 'PLAN_UPGRADE_REQUIRED') {
|
|
throw new z.errors.Error(
|
|
response.data?.error ?? 'This action requires a paid plan.',
|
|
'PlanUpgradeRequired',
|
|
403,
|
|
);
|
|
}
|
|
|
|
return response;
|
|
};
|
|
|
|
let platformVersion = '15.19.0';
|
|
try {
|
|
platformVersion = require('zapier-platform-core').version;
|
|
} catch {
|
|
// optional for unit tests without full install
|
|
}
|
|
|
|
module.exports = {
|
|
version: require('./package.json').version,
|
|
platformVersion,
|
|
authentication,
|
|
beforeRequest: [addApiKey],
|
|
afterResponse: [mapMiddlewareErrors],
|
|
triggers: {
|
|
[timestampCompleted.key]: timestampCompleted,
|
|
},
|
|
creates: {
|
|
[addNumbers.key]: addNumbers,
|
|
[timestampAndWait.key]: timestampAndWait,
|
|
[createTimestamp.key]: createTimestamp,
|
|
[verifyTimestamp.key]: verifyTimestamp,
|
|
[batchTimestamp.key]: batchTimestamp,
|
|
},
|
|
searches: {
|
|
[jobStatus.key]: jobStatus,
|
|
},
|
|
};
|