This repository was archived by the owner on Mar 9, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +103
-16
lines changed Expand file tree Collapse file tree 7 files changed +103
-16
lines changed Original file line number Diff line number Diff line change 55 "version" : " 1.0.0" ,
66 "main" : " index.js" ,
77 "scripts" : {
8- "build" : " npm run clean && tsc" ,
8+ "build" : " yarn run clean && yarn tsc" ,
99 "clean" : " rimraf ./lib ./build" ,
10- "lint:fix" : " yarn lint:package && yarn lint:ts --fix && prettier --write ./src" ,
10+ "lint:fix" : " yarn lint:package && yarn lint:ts --fix && prettier --write ./src && yarn typecheck " ,
1111 "lint:fix:md" : " prettier --write *.md" ,
1212 "lint:package" : " prettier-package-json --write ./package.json" ,
1313 "lint:ts" : " eslint './src/**/*.ts'" ,
14- "test" : " npm run build && jest --testTimeout 10000 --rootDir ./lib/test" ,
15- "watch" : " npm run clean && tsc --watch"
14+ "test" : " yarn run build && jest --testTimeout 10000 --rootDir ./lib/test" ,
15+ "typecheck" : " yarn tsc --noEmit" ,
16+ "watch" : " yarn run clean && yarn tsc --watch"
1617 },
1718 "dependencies" : {
1819 "zapier-platform-core" : " 10.1.1"
Original file line number Diff line number Diff line change 11import { Bundle , ZObject } from "zapier-platform-core" ;
2- import { PatchResponse } from "../types" ;
2+ import { ZapierCreate , PatchResponse } from "../types" ;
33
44type CreateData = {
55 mass_g : number ;
@@ -20,15 +20,13 @@ const perform = async (
2020 return ( data as PatchResponse ) . data ;
2121} ;
2222
23- export const OrderCreate = {
23+ export const OrderCreate : ZapierCreate < CreateData > = {
2424 key : "order" ,
2525 noun : "order" ,
26-
2726 display : {
2827 label : "Create Order" ,
2928 description : "Creates a new order." ,
3029 } ,
31-
3230 operation : {
3331 perform,
3432 inputFields : [
Original file line number Diff line number Diff line change 11import { Bundle , HttpRequestOptions , ZObject } from "zapier-platform-core" ;
2- import { ProjectTrigger } from "./triggers" ;
2+ import { OrderTrigger , ProjectTrigger } from "./triggers" ;
33import { OrderCreate } from "./creates" ;
44import { version as platformVersion } from "zapier-platform-core" ;
55const { version } = require ( "../package.json" ) ; // eslint-disable-line
@@ -33,6 +33,7 @@ export default {
3333
3434 triggers : {
3535 [ ProjectTrigger . key ] : ProjectTrigger ,
36+ [ OrderTrigger . key ] : OrderTrigger ,
3637 } ,
3738
3839 creates : {
Original file line number Diff line number Diff line change 1+ export * from "./order" ;
12export * from "./project" ;
Original file line number Diff line number Diff line change 1+ import { Bundle , ZObject } from "zapier-platform-core" ;
2+ import { PatchResponse , ZapierTrigger } from "../types" ;
3+
4+ const perform = async ( z : ZObject , bundle : Bundle ) : Promise < unknown > => {
5+ // zapier starts with page 0
6+ const page = bundle . meta . page + 1 ;
7+ const { data } = await z . request ( "https://api.usepatch.com/v1/orders" , {
8+ json : { page } ,
9+ } ) ;
10+ return ( data as PatchResponse ) . data ;
11+ } ;
12+
13+ export const OrderTrigger : ZapierTrigger = {
14+ key : "order" ,
15+ noun : "order" ,
16+ display : {
17+ label : "New Order" ,
18+ description : "Triggers when a new order is created." ,
19+ } ,
20+ operation : {
21+ type : "polling" ,
22+ canPaginate : true ,
23+ perform,
24+ sample : {
25+ id : "ord_test_16d8054a8f8502d81a830252d58024bb" ,
26+ allocation_state : "allocated" ,
27+ allocations : [
28+ {
29+ id : "all_test_be33c362135078d77cce3e8ab242dac1" ,
30+ mass_g : 34 ,
31+ offset : {
32+ id : "off_test_a6a8c407b8f3e9f783f9aa41fb833d1a" ,
33+ developer : "Carbo Culture" ,
34+ production : false ,
35+ serial_number : null ,
36+ vintage_year : 2020 ,
37+ } ,
38+ production : false ,
39+ } ,
40+ ] ,
41+ mass_g : 34 ,
42+ metadata : {
43+ foo : "bar" ,
44+ } ,
45+ price_cents_usd : "1.0" ,
46+ production : false ,
47+ state : "placed" ,
48+ } ,
49+ } ,
50+ } ;
Original file line number Diff line number Diff line change 1- import { ZObject } from "zapier-platform-core" ;
2- import { PatchResponse } from "../types" ;
1+ import { Bundle , ZObject } from "zapier-platform-core" ;
2+ import { PatchResponse , ZapierTrigger } from "../types" ;
33
4- const perform = async ( z : ZObject ) : Promise < unknown > => {
4+ const perform = async ( z : ZObject , bundle : Bundle ) : Promise < unknown > => {
5+ // zapier starts with page 0
6+ const page = bundle . meta . page + 1 ;
57 const { data } = await z . request ( "https://api.usepatch.com/v1/projects" , {
6- json : { page : 1 } ,
8+ json : { page } ,
79 } ) ;
810 return ( data as PatchResponse ) . data ;
911} ;
1012
11- export const ProjectTrigger = {
13+ export const ProjectTrigger : ZapierTrigger = {
1214 key : "project" ,
1315 noun : "project" ,
14-
1516 display : {
1617 label : "New Project" ,
1718 description : "Triggers when a new project is created." ,
1819 } ,
19-
2020 operation : {
21+ type : "polling" ,
22+ canPaginate : true ,
2123 perform,
2224 sample : {
2325 id : "pro_test_2e049bbfe8c998ca82025d776f8289ff" ,
Original file line number Diff line number Diff line change 1+ import { Bundle , ZObject } from "zapier-platform-core" ;
2+
13export type PatchResponse = { data : unknown } ;
4+
5+ type DefaultBundleConfig = Record < string , unknown > ;
6+
7+ type ZapierBase < BundleConfig > = {
8+ key : string ;
9+ noun : string ;
10+ display : {
11+ label : string ;
12+ description : string ;
13+ } ;
14+ operation : {
15+ perform : ( z : ZObject , bundle : Bundle < BundleConfig > ) => Promise < unknown > ;
16+ sample : Record < string , unknown > ;
17+ } ;
18+ } ;
19+
20+ export type ZapierTrigger < BundleConfig = DefaultBundleConfig > = ZapierBase <
21+ BundleConfig
22+ > & {
23+ operation : {
24+ type : "polling" ;
25+ canPaginate : true ;
26+ } ;
27+ } ;
28+
29+ export type ZapierCreate < BundleConfig = DefaultBundleConfig > = ZapierBase <
30+ BundleConfig
31+ > & {
32+ operation : {
33+ inputFields : Array < Record < string , unknown > > ;
34+ } ;
35+ } ;
You can’t perform that action at this time.
0 commit comments