import type { Bundle, ZObject } from 'zapier-platform-core'; import { zapierV1 } from '../lib/base.js'; const subscribe = async (z: ZObject, bundle: Bundle) => { const response = await z.request({ url: zapierV1(bundle, '/webhooks/subscribe'), method: 'POST', headers: { 'content-type': 'application/json', accept: 'application/json' }, json: { targetUrl: bundle.targetUrl, event: 'timestamp.completed', }, }); return response.data; }; const unsubscribe = async (z: ZObject, bundle: Bundle) => { const hookId = bundle.subscribeData?.id; const response = await z.request({ url: zapierV1(bundle, '/webhooks/unsubscribe'), method: 'DELETE', headers: { 'content-type': 'application/json', accept: 'application/json' }, json: { hookId }, }); return response.data; }; const perform = async (_z: ZObject, bundle: Bundle) => { const payload = bundle.cleanedRequest; if (!payload) return []; return Array.isArray(payload) ? payload : [payload]; }; const performList = async () => [ { id: 'sample-job', event: 'timestamp.completed', jobId: '550e8400-e29b-41d4-a716-446655440000', status: 'completed', result: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...', }, ]; export default { key: 'timestamp_completed', noun: 'Timestamp', display: { label: 'Timestamp Completed', description: 'Triggers when the middleware finishes a timestamp job (REST Hook).', }, operation: { type: 'hook' as const, performSubscribe: subscribe, performUnsubscribe: unsubscribe, perform, performList, sample: { id: 'sample-job', event: 'timestamp.completed', jobId: '550e8400-e29b-41d4-a716-446655440000', status: 'completed', }, }, };