verae-edge-billing/client/zapier-app/creates/timestamp.js

106 lines
3.4 KiB
JavaScript

const perform = async (z, bundle) => {
const body = {};
if (bundle.inputData.sha256) body.sha256 = String(bundle.inputData.sha256).toLowerCase();
if (bundle.inputData.data) body.data = bundle.inputData.data;
if (bundle.inputData.documentName) body.documentName = String(bundle.inputData.documentName);
if (bundle.inputData.metadata) {
try {
body.metadata =
typeof bundle.inputData.metadata === 'string'
? JSON.parse(bundle.inputData.metadata)
: bundle.inputData.metadata;
} catch (e) {
throw new z.errors.Error('metadata must be JSON', 'InvalidData', 400);
}
}
// Opt-in registration PDF (Verae Timestamp Registration Document).
if (bundle.inputData.attachPdf) {
body.attachPdf = true;
body.formats = ['json', 'pdf'];
}
// Always wait for Verae /api/timestamp completion (MCP-style) unless disabled.
body.wait = bundle.inputData.wait === false || bundle.inputData.wait === 'false' ? false : true;
const response = await z.request({
url: `${bundle.authData.baseUrl}/v1/timestamp`,
method: 'POST',
body,
headers: {
'content-type': 'application/json',
'x-billing-channel': 'zapier',
},
});
return response.data;
};
module.exports = {
key: 'timestamp',
noun: 'Timestamp',
display: {
label: 'Create Timestamp',
description:
'Registers a SHA-256 timestamp (waits for Verae /api/timestamp completion). Prefer hashing client-side (WASM) and pass sha256 only. Optional registration PDF.',
},
operation: {
inputFields: [
{
key: 'sha256',
label: 'SHA-256 hex',
type: 'string',
required: false,
helpText: 'Preferred. Hash locally with Verae WASM (/client/hasher/) then paste hex.',
},
{
key: 'data',
label: 'Raw data',
type: 'text',
required: false,
helpText: 'If sha256 omitted, server hashes this UTF-8 string.',
},
{
key: 'documentName',
label: 'Document name',
type: 'string',
required: false,
helpText: 'Shown on the registration PDF / text export when attach PDF is enabled.',
},
{
key: 'metadata',
label: 'Metadata JSON',
type: 'text',
required: false,
helpText: 'Optional JSON object. Stamp+metadata uses metadata credit SKU.',
},
{
key: 'attachPdf',
label: 'Attach registration PDF',
type: 'boolean',
required: false,
default: 'false',
helpText:
'If true, response includes pdfBase64 + pdfFilename (Verae Timestamp Registration Document, same style as mcp.verae.ai/register.html). Off by default.',
},
{
key: 'wait',
label: 'Wait for completion',
type: 'boolean',
required: false,
default: 'true',
helpText: 'Wait for Verae job completion and return receipt_id / timestamp (recommended).',
},
],
perform,
sample: {
jobId: 'job_sample',
sha256: '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824',
existing: false,
status: 'completed',
receipt_id: 'QmSampleCid',
created_at: '2026-10-03T00:00:00.000Z',
timestamp: '2026-10-03T00:00:00.000Z',
merkle: '113198',
lookup_url:
'https://mcp.verae.ai/register.html?sha256=2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824&receipt=QmSampleCid',
},
},
};