Compose-ready workspace: packages/zappier (rate card, portal, Stripe), packages/verae-zapier-middleware (timestamp + NATS), packages/verae-zapier (CLI app), vendor/zapier-platform, and research/zapier vendor corpus. Gate 0 structure checks pass. Product code and research are not yet wired.
80 lines
2.8 KiB
JavaScript
80 lines
2.8 KiB
JavaScript
// We recommend writing your creates separate like this and rolling them
|
|
// into the App definition at the end.
|
|
module.exports = {
|
|
key: 'recipe',
|
|
|
|
// You'll want to provide some helpful display labels and descriptions
|
|
// for users. Zapier will put them into the UX.
|
|
noun: 'Recipe',
|
|
display: {
|
|
label: 'Create Recipe',
|
|
description: 'Creates a new recipe.',
|
|
},
|
|
|
|
// `operation` is where the business logic goes.
|
|
operation: {
|
|
inputFields: [
|
|
{ key: 'name', required: true, type: 'string' },
|
|
{
|
|
key: 'directions',
|
|
required: true,
|
|
type: 'text',
|
|
helpText: 'Explain how should one make the recipe, step by step.',
|
|
},
|
|
{ key: 'authorId', required: true, type: 'integer', label: 'Author ID' },
|
|
{
|
|
key: 'style',
|
|
required: false,
|
|
type: 'string',
|
|
helpText: 'Explain what style of cuisine this is.',
|
|
},
|
|
],
|
|
perform: (z, bundle) => {
|
|
const promise = z.request({
|
|
url: 'https://auth-json-server.zapier-staging.com/recipes',
|
|
method: 'POST',
|
|
body: {
|
|
name: bundle.inputData.name,
|
|
directions: bundle.inputData.directions,
|
|
authorId: bundle.inputData.authorId,
|
|
style: bundle.inputData.style,
|
|
},
|
|
headers: {
|
|
'content-type': 'application/json',
|
|
|
|
// This is NOT how you normally do authentication. This is just to demo how to write a create here.
|
|
// Refer to this doc to set up authentication:
|
|
// https://docs.zapier.com/platform/reference/cli-docs#authentication
|
|
'X-API-Key': 'secret',
|
|
},
|
|
});
|
|
|
|
return promise.then((response) => response.data);
|
|
},
|
|
|
|
// In cases where Zapier needs to show an example record to the user, but we are unable to get a live example
|
|
// from the API, Zapier will fallback to this hard-coded sample. It should reflect the data structure of
|
|
// returned records, and have obviously dummy values that we can show to any user.
|
|
sample: {
|
|
id: 1,
|
|
createdAt: 1472069465,
|
|
name: 'Best Spagetti Ever',
|
|
authorId: 1,
|
|
directions: '1. Boil Noodles\n2.Serve with sauce',
|
|
style: 'italian',
|
|
},
|
|
|
|
// If the resource can have fields that are custom on a per-user basis, define a function to fetch the custom
|
|
// field definitions. The result will be used to augment the sample.
|
|
// outputFields: () => { return []; }
|
|
// Alternatively, a static field definition should be provided, to specify labels for the fields
|
|
outputFields: [
|
|
{ key: 'id', label: 'ID' },
|
|
{ key: 'createdAt', label: 'Created At' },
|
|
{ key: 'name', label: 'Name' },
|
|
{ key: 'directions', label: 'Directions' },
|
|
{ key: 'authorId', label: 'Author ID' },
|
|
{ key: 'style', label: 'Style' },
|
|
],
|
|
},
|
|
};
|