zap-step
Boilerplate for writing, testing and packaging Zapier JavaScript steps.
Features
- Lets you write your step as a function that is testable
- Packages up your code and dependencies (via Parcel) into a single file
- Helpers for testing your functions
- TypeScript types for your functions and tests
- Builds with Parcel so you can take advantage of all the tooling you enjoy, like Babel, TypeScript, etc.
zap-step
Writing Zap steps with 1. Write a function that you want to run on Zapier.
- Instead of using an
inputData
global variable, the input data is passed as the first argument to your function. - Instead of setting the
output
variable (or writing a nakedreturn
outside a function), the return value of your function is used as the output. - Export your function as
default
to make it the entry point for the zap step.
zap-step
The old way, before // 👎 Codeconst addBusinessDays = { const date = timestamp const hours = date const numWeekDays = 0 while numWeekDays < amount date date if date == 6 || date == 0 numWeekDays++ return date} return tenBusinessDaysAfter: // Tests// ??? 👎👎 Good luck with that
zap-step
The new way, with // 👍 tenBusinessDaysAfter.js tenBusinessDaysAfter: // Tests 👌
2. Write your tests
To test functions besides your main one, use named exports.
// myStep.js { /*...*/ } { /*...*/ } myDifficultLogic: otherDifficultLogic: // test/myStep.test.js
3. Use TypeScript types
Use types to help guide your implementation and testing.
// Code
zapify
to bundle it up
4. yarn zapify src/tenBusinessDaysAfter.js dist/tenBusinessDaysAfter.js
The zapify
command builds & bundles your file with Parcel, then adds some special code to make it work as a Zapier JS code step.
5. Copy & paste into Zapier
Copy & paste the contents of your built file into a Zapier zap step.
Testing bundled (and hand-written) steps
Using the provided zapStep
helper, one can test a file that contains code for a Zapier step.
This can handle code bundled with our zapify
command, as well as code written by hand.
Provide it with a file name and it will read the file and eval the code inside an environment that simulates a Zapier step.
const input = /*...*/ const output =