53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
const base = () => process.env.MIDDLEWARE_BASE_URL || 'http://127.0.0.1:3100';
|
|
|
|
const subscribeHook = async (z, bundle) => {
|
|
const response = await z.request({
|
|
method: 'POST',
|
|
url: `${base()}/zapier/v1/webhooks/subscribe`,
|
|
body: {
|
|
targetUrl: bundle.targetUrl,
|
|
event: 'timestamp.completed',
|
|
},
|
|
});
|
|
return response.data.id;
|
|
};
|
|
|
|
const unsubscribeHook = async (z, bundle) => {
|
|
await z.request({
|
|
method: 'DELETE',
|
|
url: `${base()}/zapier/v1/webhooks/unsubscribe`,
|
|
body: {
|
|
hookId: bundle.subscribeData,
|
|
},
|
|
});
|
|
return {};
|
|
};
|
|
|
|
const perform = async (z, bundle) => [bundle.cleanedRequest];
|
|
|
|
const performList = async () => [];
|
|
|
|
module.exports = {
|
|
key: 'timestamp_completed',
|
|
noun: 'Timestamp',
|
|
display: {
|
|
label: 'Timestamp Completed',
|
|
description: 'Triggers when a blockchain timestamp job completes.',
|
|
},
|
|
operation: {
|
|
type: 'hook',
|
|
perform,
|
|
performList,
|
|
performSubscribe: subscribeHook,
|
|
performUnsubscribe: unsubscribeHook,
|
|
sample: {
|
|
event: 'timestamp.completed',
|
|
jobId: '550e8400-e29b-41d4-a716-446655440000',
|
|
status: { id: '550e8400-e29b-41d4-a716-446655440000', status: 'completed' },
|
|
},
|
|
outputFields: [
|
|
{ key: 'event', label: 'Event' },
|
|
{ key: 'jobId', label: 'Job ID' },
|
|
],
|
|
},
|
|
};
|