Initial import of verae-activate from zapier monorepo

This commit is contained in:
George Lambert 2026-09-11 14:59:35 -04:00
commit 132616d74b
12 changed files with 1367 additions and 0 deletions

94
creates/add_numbers.js Normal file
View file

@ -0,0 +1,94 @@
/**
* Add Numbers Zapier create that needs no backend.
*
* Inputs: number1, number2 (Zapier number fields).
* Output: { number1, number2, sum, mode }.
*
* If both api_base and api_key are set on the connection, POST /v1/add on the
* zappier commercial edge instead of adding locally.
*
* @module creates/add_numbers
*/
/**
* @param {unknown} value
* @param {string} name
* @returns {number}
*/
function toFiniteNumber(value, name) {
const n = typeof value === 'number' ? value : Number(value);
if (!Number.isFinite(n)) {
throw new Error(`${name} must be a finite number`);
}
return n;
}
/**
* @param {object} z Zapier z toolkit
* @param {object} bundle
* @param {object} bundle.inputData
* @param {string|number} bundle.inputData.number1
* @param {string|number} bundle.inputData.number2
* @param {object} bundle.authData
* @returns {Promise<{number1: number, number2: number, sum: number, mode: string}>}
*/
const perform = async (z, bundle) => {
const number1 = toFiniteNumber(bundle.inputData.number1, 'number1');
const number2 = toFiniteNumber(bundle.inputData.number2, 'number2');
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({
method: 'POST',
url: `${base}/v1/add`,
headers: { 'x-api-key': key, 'content-type': 'application/json' },
body: { number1, number2 },
});
const data = response.data || {};
return {
number1: data.number1 ?? number1,
number2: data.number2 ?? number2,
sum: data.sum,
mode: 'hosted',
};
}
return { number1, number2, sum: number1 + number2, mode: 'local' };
};
module.exports = {
key: 'add_numbers',
noun: 'Sum',
display: {
label: 'Add Numbers',
description: 'Adds number1 and number2. Works with no API — use this to prove the Zapier connection.',
},
operation: {
cleanInputData: false,
inputFields: [
{
key: 'number1',
label: 'Number 1',
type: 'number',
required: true,
helpText: 'First addend.',
},
{
key: 'number2',
label: 'Number 2',
type: 'number',
required: true,
helpText: 'Second addend.',
},
],
perform,
sample: { number1: 2, number2: 3, sum: 5, mode: 'local' },
outputFields: [
{ key: 'number1', label: 'Number 1', type: 'number' },
{ key: 'number2', label: 'Number 2', type: 'number' },
{ key: 'sum', label: 'Sum', type: 'number' },
{ key: 'mode', label: 'Mode', type: 'string' },
],
},
};

29
creates/echo.js Normal file
View file

@ -0,0 +1,29 @@
/**
* Echo returns the input string. Second activate-now action (no backend).
* @module creates/echo
*/
const perform = async (_z, bundle) => {
const text = String(bundle.inputData.text ?? '');
return { text, length: text.length, mode: 'local' };
};
module.exports = {
key: 'echo',
noun: 'Echo',
display: {
label: 'Echo Text',
description: 'Returns the text you send. No API required.',
},
operation: {
cleanInputData: false,
inputFields: [{ key: 'text', label: 'Text', type: 'string', required: true }],
perform,
sample: { text: 'hello', length: 5, mode: 'local' },
outputFields: [
{ key: 'text', type: 'string' },
{ key: 'length', type: 'integer' },
{ key: 'mode', type: 'string' },
],
},
};

36
creates/sha256.js Normal file
View file

@ -0,0 +1,36 @@
/**
* SHA256 of a string local, no API. Lets you hash a file/text in a Zap.
* @module creates/sha256
*/
const { createHash } = require('node:crypto');
const perform = async (_z, bundle) => {
const text = String(bundle.inputData.text ?? '');
const sha256 = createHash('sha256').update(text, 'utf8').digest('hex');
return { textLength: text.length, sha256, mode: 'local' };
};
module.exports = {
key: 'sha256_hash',
noun: 'Hash',
display: {
label: 'SHA256 Hash Text',
description: 'Computes SHA256 hex of text inside Zapier. No Verae call.',
},
operation: {
cleanInputData: false,
inputFields: [{ key: 'text', label: 'Text', type: 'text', required: true }],
perform,
sample: {
textLength: 5,
sha256: '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824',
mode: 'local',
},
outputFields: [
{ key: 'sha256', type: 'string' },
{ key: 'textLength', type: 'integer' },
{ key: 'mode', type: 'string' },
],
},
};

54
creates/timestamp.js Normal file
View file

@ -0,0 +1,54 @@
/**
* Create Timestamp hosted if api_base+api_key, else local mock job.
* @module creates/timestamp
*/
const { randomUUID } = require('node:crypto');
const perform = async (z, bundle) => {
const data = String(bundle.inputData.data ?? '');
const sha256 = bundle.inputData.sha256;
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({
method: 'POST',
url: `${base}/v1/timestamp`,
headers: { 'x-api-key': key, 'content-type': 'application/json' },
body: { data, sha256, hashAlg: bundle.inputData.hashAlg },
});
return { ...(response.data || {}), mode: 'hosted' };
}
return {
jobId: randomUUID(),
sha256: sha256 || null,
existing: false,
mode: 'local-mock',
note: 'No API configured — mock jobId only. Set API base + key to hit zappier /v1/timestamp.',
};
};
module.exports = {
key: 'create_timestamp',
noun: 'Timestamp',
display: {
label: 'Create Timestamp',
description: 'Registers data/SHA256. Local mock if no API; hosted zappier when connected.',
},
operation: {
cleanInputData: false,
inputFields: [
{ key: 'data', label: 'Data', type: 'text', required: false },
{ key: 'sha256', label: 'SHA256 hex', type: 'string', required: false },
{ key: 'hashAlg', label: 'Hash algorithm', type: 'string', required: false, default: 'SHA256' },
],
perform,
sample: { jobId: '00000000-0000-4000-8000-000000000000', existing: false, mode: 'local-mock' },
outputFields: [
{ key: 'jobId', type: 'string' },
{ key: 'sha256', type: 'string' },
{ key: 'existing', type: 'boolean' },
{ key: 'mode', type: 'string' },
],
},
};