@zapier/zapier-sdk 0.4.1 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (375) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +343 -0
  3. package/dist/api/auth.d.ts +9 -0
  4. package/dist/api/auth.d.ts.map +1 -0
  5. package/dist/api/auth.js +25 -0
  6. package/dist/api/client.d.ts +9 -0
  7. package/dist/api/client.d.ts.map +1 -0
  8. package/dist/api/client.js +322 -0
  9. package/dist/api/debug.d.ts +13 -0
  10. package/dist/api/debug.d.ts.map +1 -0
  11. package/dist/api/debug.js +55 -0
  12. package/dist/api/index.d.ts +29 -0
  13. package/dist/api/index.d.ts.map +1 -0
  14. package/dist/api/index.js +41 -0
  15. package/dist/api/polling.d.ts +16 -0
  16. package/dist/api/polling.d.ts.map +1 -0
  17. package/dist/api/polling.js +45 -0
  18. package/dist/api/schemas.d.ts +2473 -0
  19. package/dist/api/schemas.d.ts.map +1 -0
  20. package/dist/api/schemas.js +355 -0
  21. package/dist/api/types.d.ts +75 -0
  22. package/dist/api/types.d.ts.map +1 -0
  23. package/dist/api/types.js +11 -0
  24. package/dist/auth.d.ts +34 -0
  25. package/dist/auth.d.ts.map +1 -0
  26. package/dist/auth.js +47 -0
  27. package/dist/constants.d.ts +10 -0
  28. package/dist/constants.d.ts.map +1 -0
  29. package/dist/constants.js +9 -0
  30. package/dist/index.cjs +2108 -1379
  31. package/dist/index.d.mts +2440 -620
  32. package/dist/index.d.ts +17 -892
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +20 -0
  35. package/dist/index.mjs +2093 -1362
  36. package/dist/plugins/api/index.d.ts +14 -0
  37. package/dist/plugins/api/index.d.ts.map +1 -0
  38. package/dist/plugins/api/index.js +21 -0
  39. package/dist/plugins/apps/index.d.ts +11 -0
  40. package/dist/plugins/apps/index.d.ts.map +1 -0
  41. package/dist/plugins/apps/index.js +91 -0
  42. package/dist/plugins/apps/types.d.ts +30 -0
  43. package/dist/plugins/apps/types.d.ts.map +1 -0
  44. package/dist/plugins/apps/types.js +2 -0
  45. package/dist/plugins/fetch/index.d.ts +21 -0
  46. package/dist/plugins/fetch/index.d.ts.map +1 -0
  47. package/dist/plugins/fetch/index.js +20 -0
  48. package/dist/plugins/findFirstAuthentication/index.d.ts +20 -0
  49. package/dist/plugins/findFirstAuthentication/index.d.ts.map +1 -0
  50. package/dist/plugins/findFirstAuthentication/index.js +24 -0
  51. package/dist/plugins/findFirstAuthentication/index.test.d.ts +2 -0
  52. package/dist/plugins/findFirstAuthentication/index.test.d.ts.map +1 -0
  53. package/dist/plugins/findFirstAuthentication/index.test.js +171 -0
  54. package/dist/plugins/findFirstAuthentication/schemas.d.ts +29 -0
  55. package/dist/plugins/findFirstAuthentication/schemas.d.ts.map +1 -0
  56. package/dist/plugins/findFirstAuthentication/schemas.js +18 -0
  57. package/dist/plugins/findUniqueAuthentication/index.d.ts +20 -0
  58. package/dist/plugins/findUniqueAuthentication/index.d.ts.map +1 -0
  59. package/dist/plugins/findUniqueAuthentication/index.js +31 -0
  60. package/dist/plugins/findUniqueAuthentication/index.test.d.ts +2 -0
  61. package/dist/plugins/findUniqueAuthentication/index.test.d.ts.map +1 -0
  62. package/dist/plugins/findUniqueAuthentication/index.test.js +152 -0
  63. package/dist/plugins/findUniqueAuthentication/schemas.d.ts +29 -0
  64. package/dist/plugins/findUniqueAuthentication/schemas.d.ts.map +1 -0
  65. package/dist/plugins/findUniqueAuthentication/schemas.js +18 -0
  66. package/dist/plugins/getAction/index.d.ts +23 -0
  67. package/dist/plugins/getAction/index.d.ts.map +1 -0
  68. package/dist/plugins/getAction/index.js +28 -0
  69. package/dist/plugins/getAction/index.test.d.ts +2 -0
  70. package/dist/plugins/getAction/index.test.d.ts.map +1 -0
  71. package/dist/plugins/getAction/index.test.js +186 -0
  72. package/dist/plugins/getAction/schemas.d.ts +23 -0
  73. package/dist/plugins/getAction/schemas.d.ts.map +1 -0
  74. package/dist/plugins/getAction/schemas.js +10 -0
  75. package/dist/plugins/getApp/index.d.ts +22 -0
  76. package/dist/plugins/getApp/index.d.ts.map +1 -0
  77. package/dist/plugins/getApp/index.js +39 -0
  78. package/dist/plugins/getApp/index.test.d.ts +2 -0
  79. package/dist/plugins/getApp/index.test.d.ts.map +1 -0
  80. package/dist/plugins/getApp/index.test.js +100 -0
  81. package/dist/plugins/getApp/schemas.d.ts +18 -0
  82. package/dist/plugins/getApp/schemas.d.ts.map +1 -0
  83. package/dist/plugins/getApp/schemas.js +10 -0
  84. package/dist/plugins/getAuthentication/index.d.ts +22 -0
  85. package/dist/plugins/getAuthentication/index.d.ts.map +1 -0
  86. package/dist/plugins/getAuthentication/index.js +41 -0
  87. package/dist/plugins/getAuthentication/index.test.d.ts +2 -0
  88. package/dist/plugins/getAuthentication/index.test.d.ts.map +1 -0
  89. package/dist/plugins/getAuthentication/index.test.js +205 -0
  90. package/dist/plugins/getAuthentication/schemas.d.ts +17 -0
  91. package/dist/plugins/getAuthentication/schemas.d.ts.map +1 -0
  92. package/dist/plugins/getAuthentication/schemas.js +11 -0
  93. package/dist/plugins/getProfile/index.d.ts +23 -0
  94. package/dist/plugins/getProfile/index.d.ts.map +1 -0
  95. package/dist/plugins/getProfile/index.js +29 -0
  96. package/dist/plugins/getProfile/schemas.d.ts +13 -0
  97. package/dist/plugins/getProfile/schemas.d.ts.map +1 -0
  98. package/dist/plugins/getProfile/schemas.js +5 -0
  99. package/dist/plugins/listActions/index.d.ts +28 -0
  100. package/dist/plugins/listActions/index.d.ts.map +1 -0
  101. package/dist/plugins/listActions/index.js +61 -0
  102. package/dist/plugins/listActions/index.test.d.ts +2 -0
  103. package/dist/plugins/listActions/index.test.d.ts.map +1 -0
  104. package/dist/plugins/listActions/index.test.js +467 -0
  105. package/dist/plugins/listActions/schemas.d.ts +29 -0
  106. package/dist/plugins/listActions/schemas.d.ts.map +1 -0
  107. package/dist/plugins/listActions/schemas.js +21 -0
  108. package/dist/plugins/listApps/index.d.ts +28 -0
  109. package/dist/plugins/listApps/index.d.ts.map +1 -0
  110. package/dist/plugins/listApps/index.js +62 -0
  111. package/dist/plugins/listApps/index.test.d.ts +2 -0
  112. package/dist/plugins/listApps/index.test.d.ts.map +1 -0
  113. package/dist/plugins/listApps/index.test.js +313 -0
  114. package/dist/plugins/listApps/schemas.d.ts +30 -0
  115. package/dist/plugins/listApps/schemas.d.ts.map +1 -0
  116. package/dist/plugins/listApps/schemas.js +23 -0
  117. package/dist/plugins/listAuthentications/index.d.ts +28 -0
  118. package/dist/plugins/listAuthentications/index.d.ts.map +1 -0
  119. package/dist/plugins/listAuthentications/index.js +77 -0
  120. package/dist/plugins/listAuthentications/index.test.d.ts +2 -0
  121. package/dist/plugins/listAuthentications/index.test.d.ts.map +1 -0
  122. package/dist/plugins/listAuthentications/index.test.js +564 -0
  123. package/dist/plugins/listAuthentications/schemas.d.ts +38 -0
  124. package/dist/plugins/listAuthentications/schemas.d.ts.map +1 -0
  125. package/dist/plugins/listAuthentications/schemas.js +28 -0
  126. package/dist/plugins/listInputFields/index.d.ts +28 -0
  127. package/dist/plugins/listInputFields/index.d.ts.map +1 -0
  128. package/dist/plugins/listInputFields/index.js +133 -0
  129. package/dist/plugins/listInputFields/index.test.d.ts +2 -0
  130. package/dist/plugins/listInputFields/index.test.d.ts.map +1 -0
  131. package/dist/plugins/listInputFields/index.test.js +325 -0
  132. package/dist/plugins/listInputFields/schemas.d.ts +38 -0
  133. package/dist/plugins/listInputFields/schemas.d.ts.map +1 -0
  134. package/dist/plugins/listInputFields/schemas.js +22 -0
  135. package/dist/plugins/registry/index.d.ts +11 -0
  136. package/dist/plugins/registry/index.d.ts.map +1 -0
  137. package/dist/plugins/registry/index.js +14 -0
  138. package/dist/plugins/request/index.d.ts +19 -0
  139. package/dist/plugins/request/index.d.ts.map +1 -0
  140. package/dist/plugins/request/index.js +62 -0
  141. package/dist/plugins/request/index.test.d.ts +2 -0
  142. package/dist/plugins/request/index.test.d.ts.map +1 -0
  143. package/dist/plugins/request/index.test.js +256 -0
  144. package/dist/plugins/request/schemas.d.ts +69 -0
  145. package/dist/plugins/request/schemas.d.ts.map +1 -0
  146. package/dist/plugins/request/schemas.js +42 -0
  147. package/dist/plugins/runAction/index.d.ts +28 -0
  148. package/dist/plugins/runAction/index.d.ts.map +1 -0
  149. package/dist/plugins/runAction/index.js +86 -0
  150. package/dist/plugins/runAction/index.test.d.ts +2 -0
  151. package/dist/plugins/runAction/index.test.d.ts.map +1 -0
  152. package/dist/plugins/runAction/index.test.js +320 -0
  153. package/dist/plugins/runAction/schemas.d.ts +37 -0
  154. package/dist/plugins/runAction/schemas.d.ts.map +1 -0
  155. package/dist/plugins/runAction/schemas.js +22 -0
  156. package/dist/resolvers/actionKey.d.ts +9 -0
  157. package/dist/resolvers/actionKey.d.ts.map +1 -0
  158. package/dist/resolvers/actionKey.js +19 -0
  159. package/dist/resolvers/actionType.d.ts +9 -0
  160. package/dist/resolvers/actionType.d.ts.map +1 -0
  161. package/dist/resolvers/actionType.js +22 -0
  162. package/dist/resolvers/appKey.d.ts +7 -0
  163. package/dist/resolvers/appKey.d.ts.map +1 -0
  164. package/dist/resolvers/appKey.js +5 -0
  165. package/dist/resolvers/authenticationId.d.ts +9 -0
  166. package/dist/resolvers/authenticationId.d.ts.map +1 -0
  167. package/dist/resolvers/authenticationId.js +33 -0
  168. package/dist/resolvers/index.d.ts +40 -0
  169. package/dist/resolvers/index.d.ts.map +1 -0
  170. package/dist/resolvers/index.js +91 -0
  171. package/dist/resolvers/inputs.d.ts +8 -0
  172. package/dist/resolvers/inputs.d.ts.map +1 -0
  173. package/dist/resolvers/inputs.js +14 -0
  174. package/dist/schemas/Action.d.ts +243 -0
  175. package/dist/schemas/Action.d.ts.map +1 -0
  176. package/dist/schemas/Action.js +34 -0
  177. package/dist/schemas/App.d.ts +26 -0
  178. package/dist/schemas/App.d.ts.map +1 -0
  179. package/dist/schemas/App.js +22 -0
  180. package/dist/schemas/Auth.d.ts +161 -0
  181. package/dist/schemas/Auth.d.ts.map +1 -0
  182. package/dist/schemas/Auth.js +41 -0
  183. package/dist/schemas/Field.d.ts +144 -0
  184. package/dist/schemas/Field.d.ts.map +1 -0
  185. package/dist/schemas/Field.js +105 -0
  186. package/dist/schemas/UserProfile.d.ts +163 -0
  187. package/dist/schemas/UserProfile.d.ts.map +1 -0
  188. package/dist/schemas/UserProfile.js +29 -0
  189. package/dist/sdk.d.ts +10 -0
  190. package/dist/sdk.d.ts.map +1 -0
  191. package/dist/sdk.js +94 -0
  192. package/dist/sdk.test.d.ts +2 -0
  193. package/dist/sdk.test.d.ts.map +1 -0
  194. package/dist/sdk.test.js +135 -0
  195. package/dist/types/domain.d.ts +36 -0
  196. package/dist/types/domain.d.ts.map +1 -0
  197. package/dist/types/domain.js +1 -0
  198. package/dist/types/domain.test.d.ts +2 -0
  199. package/dist/types/domain.test.d.ts.map +1 -0
  200. package/dist/types/domain.test.js +39 -0
  201. package/dist/types/errors.d.ts +143 -0
  202. package/dist/types/errors.d.ts.map +1 -0
  203. package/dist/types/errors.js +187 -0
  204. package/dist/types/events.d.ts +38 -0
  205. package/dist/types/events.d.ts.map +1 -0
  206. package/dist/types/events.js +7 -0
  207. package/dist/types/functions.d.ts +26 -0
  208. package/dist/types/functions.d.ts.map +1 -0
  209. package/dist/types/functions.js +4 -0
  210. package/dist/types/plugin.d.ts +61 -0
  211. package/dist/types/plugin.d.ts.map +1 -0
  212. package/dist/types/plugin.js +9 -0
  213. package/dist/types/properties.d.ts +22 -0
  214. package/dist/types/properties.d.ts.map +1 -0
  215. package/dist/types/properties.js +50 -0
  216. package/dist/types/sdk.d.ts +43 -0
  217. package/dist/types/sdk.d.ts.map +1 -0
  218. package/dist/types/sdk.js +4 -0
  219. package/dist/utils/array-utils.d.ts +31 -0
  220. package/dist/utils/array-utils.d.ts.map +1 -0
  221. package/dist/utils/array-utils.js +36 -0
  222. package/dist/utils/array-utils.test.d.ts +2 -0
  223. package/dist/utils/array-utils.test.d.ts.map +1 -0
  224. package/dist/utils/array-utils.test.js +107 -0
  225. package/dist/utils/domain-utils.d.ts +78 -0
  226. package/dist/utils/domain-utils.d.ts.map +1 -0
  227. package/dist/utils/domain-utils.js +218 -0
  228. package/dist/utils/domain-utils.test.d.ts +2 -0
  229. package/dist/utils/domain-utils.test.d.ts.map +1 -0
  230. package/dist/utils/domain-utils.test.js +192 -0
  231. package/dist/utils/function-utils.d.ts +45 -0
  232. package/dist/utils/function-utils.d.ts.map +1 -0
  233. package/dist/utils/function-utils.js +158 -0
  234. package/dist/utils/function-utils.test.d.ts +2 -0
  235. package/dist/utils/function-utils.test.d.ts.map +1 -0
  236. package/dist/utils/function-utils.test.js +110 -0
  237. package/dist/utils/pagination-utils.d.ts +37 -0
  238. package/dist/utils/pagination-utils.d.ts.map +1 -0
  239. package/dist/utils/pagination-utils.js +165 -0
  240. package/dist/utils/pagination-utils.test.d.ts +17 -0
  241. package/dist/utils/pagination-utils.test.d.ts.map +1 -0
  242. package/dist/utils/pagination-utils.test.js +461 -0
  243. package/dist/utils/schema-utils.d.ts +45 -0
  244. package/dist/utils/schema-utils.d.ts.map +1 -0
  245. package/dist/utils/schema-utils.js +65 -0
  246. package/dist/utils/validation.d.ts +4 -0
  247. package/dist/utils/validation.d.ts.map +1 -0
  248. package/dist/utils/validation.js +30 -0
  249. package/dist/utils/validation.test.d.ts +2 -0
  250. package/dist/utils/validation.test.d.ts.map +1 -0
  251. package/dist/utils/validation.test.js +43 -0
  252. package/package.json +12 -3
  253. package/src/api/client.ts +394 -171
  254. package/src/api/debug.ts +10 -1
  255. package/src/api/index.ts +0 -2
  256. package/src/api/polling.ts +28 -7
  257. package/src/api/schemas.ts +387 -0
  258. package/src/api/types.ts +72 -136
  259. package/src/constants.ts +10 -0
  260. package/src/index.ts +40 -19
  261. package/src/plugins/api/index.ts +47 -0
  262. package/src/plugins/apps/index.ts +25 -19
  263. package/src/plugins/apps/types.ts +7 -11
  264. package/src/plugins/fetch/index.ts +48 -40
  265. package/src/plugins/findFirstAuthentication/index.test.ts +206 -0
  266. package/src/plugins/findFirstAuthentication/index.ts +55 -0
  267. package/src/plugins/findFirstAuthentication/schemas.ts +41 -0
  268. package/src/plugins/findUniqueAuthentication/index.test.ts +197 -0
  269. package/src/plugins/findUniqueAuthentication/index.ts +72 -0
  270. package/src/plugins/findUniqueAuthentication/schemas.ts +42 -0
  271. package/src/plugins/getAction/index.test.ts +239 -0
  272. package/src/plugins/getAction/index.ts +57 -0
  273. package/src/plugins/getAction/schemas.ts +33 -0
  274. package/src/plugins/getApp/index.test.ts +127 -0
  275. package/src/plugins/getApp/index.ts +66 -0
  276. package/src/plugins/getApp/schemas.ts +38 -0
  277. package/src/plugins/getAuthentication/index.test.ts +284 -0
  278. package/src/plugins/getAuthentication/index.ts +86 -0
  279. package/src/plugins/getAuthentication/schemas.ts +31 -0
  280. package/src/plugins/getProfile/index.ts +55 -0
  281. package/src/plugins/getProfile/schemas.ts +26 -0
  282. package/src/plugins/listActions/index.test.ts +582 -0
  283. package/src/plugins/listActions/index.ts +115 -0
  284. package/src/plugins/listActions/schemas.ts +54 -0
  285. package/src/plugins/listApps/index.test.ts +357 -0
  286. package/src/plugins/listApps/index.ts +121 -0
  287. package/src/plugins/listApps/schemas.ts +49 -0
  288. package/src/plugins/listAuthentications/index.test.ts +709 -0
  289. package/src/plugins/listAuthentications/index.ts +136 -0
  290. package/src/plugins/listAuthentications/schemas.ts +60 -0
  291. package/src/plugins/listInputFields/index.test.ts +408 -0
  292. package/src/plugins/listInputFields/index.ts +204 -0
  293. package/src/plugins/listInputFields/schemas.ts +56 -0
  294. package/src/plugins/registry/index.ts +30 -0
  295. package/src/plugins/request/index.test.ts +329 -0
  296. package/src/plugins/request/index.ts +103 -0
  297. package/src/{functions → plugins}/request/schemas.ts +20 -9
  298. package/src/plugins/runAction/index.test.ts +387 -0
  299. package/src/plugins/runAction/index.ts +176 -0
  300. package/src/plugins/runAction/schemas.ts +53 -0
  301. package/src/resolvers/actionKey.ts +6 -4
  302. package/src/resolvers/actionType.ts +7 -2
  303. package/src/resolvers/appKey.ts +1 -1
  304. package/src/resolvers/authenticationId.ts +12 -3
  305. package/src/resolvers/inputs.ts +3 -1
  306. package/src/schemas/Action.ts +18 -12
  307. package/src/schemas/App.ts +11 -19
  308. package/src/schemas/Auth.ts +18 -13
  309. package/src/schemas/Field.ts +106 -11
  310. package/src/schemas/UserProfile.ts +43 -0
  311. package/src/sdk.test.ts +212 -0
  312. package/src/sdk.ts +132 -102
  313. package/src/types/domain.test.ts +50 -0
  314. package/src/types/domain.ts +43 -75
  315. package/src/types/errors.ts +275 -0
  316. package/src/types/functions.ts +27 -0
  317. package/src/types/optional-zapier-sdk-cli-login.d.ts +37 -0
  318. package/src/types/plugin.ts +105 -0
  319. package/src/types/properties.ts +4 -3
  320. package/src/types/sdk.ts +70 -48
  321. package/src/utils/array-utils.test.ts +131 -0
  322. package/src/utils/array-utils.ts +41 -0
  323. package/src/utils/domain-utils.test.ts +239 -0
  324. package/src/utils/domain-utils.ts +283 -0
  325. package/src/utils/function-utils.test.ts +141 -0
  326. package/src/utils/function-utils.ts +245 -0
  327. package/src/utils/pagination-utils.test.ts +620 -0
  328. package/src/utils/pagination-utils.ts +242 -0
  329. package/src/utils/validation.test.ts +50 -0
  330. package/src/utils/validation.ts +44 -0
  331. package/tsconfig.build.json +16 -2
  332. package/tsconfig.json +3 -1
  333. package/tsconfig.tsbuildinfo +1 -0
  334. package/tsup.config.ts +2 -0
  335. package/src/functions/bundleCode/index.ts +0 -78
  336. package/src/functions/bundleCode/info.ts +0 -9
  337. package/src/functions/bundleCode/schemas.ts +0 -30
  338. package/src/functions/findFirstAuthentication/index.ts +0 -24
  339. package/src/functions/findFirstAuthentication/info.ts +0 -9
  340. package/src/functions/findFirstAuthentication/schemas.ts +0 -50
  341. package/src/functions/findUniqueAuthentication/index.ts +0 -35
  342. package/src/functions/findUniqueAuthentication/info.ts +0 -9
  343. package/src/functions/findUniqueAuthentication/schemas.ts +0 -50
  344. package/src/functions/generateTypes/index.ts +0 -363
  345. package/src/functions/generateTypes/info.ts +0 -9
  346. package/src/functions/generateTypes/schemas.ts +0 -31
  347. package/src/functions/getAction/index.ts +0 -33
  348. package/src/functions/getAction/info.ts +0 -9
  349. package/src/functions/getAction/schemas.ts +0 -25
  350. package/src/functions/getApp/index.ts +0 -41
  351. package/src/functions/getApp/info.ts +0 -9
  352. package/src/functions/getApp/schemas.ts +0 -20
  353. package/src/functions/getAuthentication/index.ts +0 -50
  354. package/src/functions/getAuthentication/info.ts +0 -9
  355. package/src/functions/getAuthentication/schemas.ts +0 -29
  356. package/src/functions/listActions/index.ts +0 -149
  357. package/src/functions/listActions/info.ts +0 -9
  358. package/src/functions/listActions/schemas.ts +0 -30
  359. package/src/functions/listApps/index.ts +0 -60
  360. package/src/functions/listApps/info.ts +0 -9
  361. package/src/functions/listApps/schemas.ts +0 -32
  362. package/src/functions/listAuthentications/index.ts +0 -162
  363. package/src/functions/listAuthentications/info.ts +0 -9
  364. package/src/functions/listAuthentications/schemas.ts +0 -50
  365. package/src/functions/listFields/index.ts +0 -86
  366. package/src/functions/listFields/info.ts +0 -9
  367. package/src/functions/listFields/schemas.ts +0 -36
  368. package/src/functions/request/index.ts +0 -150
  369. package/src/functions/request/info.ts +0 -11
  370. package/src/functions/runAction/index.ts +0 -127
  371. package/src/functions/runAction/info.ts +0 -9
  372. package/src/functions/runAction/schemas.ts +0 -34
  373. package/src/plugins/apps/info.ts +0 -12
  374. package/src/plugins/fetch/types.ts +0 -2
  375. /package/src/{schema-utils.ts → utils/schema-utils.ts} +0 -0
package/src/api/debug.ts CHANGED
@@ -31,7 +31,16 @@ export function createDebugFetch(options: {
31
31
 
32
32
  debugLog(`→ ${method} ${url}`, {
33
33
  headers: options?.headers,
34
- body: options?.body ? JSON.parse(options.body as string) : undefined,
34
+ body:
35
+ options?.body && typeof options.body === "string"
36
+ ? (() => {
37
+ try {
38
+ return JSON.parse(options.body);
39
+ } catch {
40
+ return options.body;
41
+ }
42
+ })()
43
+ : options?.body,
35
44
  });
36
45
 
37
46
  try {
package/src/api/index.ts CHANGED
@@ -15,9 +15,7 @@ export type {
15
15
  PollOptions,
16
16
  DebugLogger,
17
17
  // API Response Model Types
18
- Integration,
19
18
  Action,
20
- Trigger,
21
19
  Field,
22
20
  Choice,
23
21
  ActionExecutionResult,
@@ -5,6 +5,8 @@
5
5
  * with configurable retry logic and exponential backoff.
6
6
  */
7
7
 
8
+ import { ZapierTimeoutError, ZapierApiError } from "../types/errors";
9
+
8
10
  export async function pollUntilComplete(options: {
9
11
  fetchPoll: () => Promise<Response>;
10
12
  maxAttempts?: number;
@@ -25,28 +27,47 @@ export async function pollUntilComplete(options: {
25
27
  } = options;
26
28
 
27
29
  let delay = initialDelay;
30
+ let errorCount = 0;
28
31
 
29
32
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
30
33
  const response = await fetchPoll();
31
34
 
32
35
  if (response.status === successStatus) {
33
- // Success - extract and return results
36
+ // Success - reset error count and return results
37
+ errorCount = 0;
34
38
  const result = await response.json();
35
39
  return resultExtractor(result);
36
40
  } else if (response.status === pendingStatus) {
37
- // Still processing - wait and retry
41
+ // Still processing - reset error count and wait and retry
42
+ errorCount = 0;
38
43
  if (attempt < maxAttempts - 1) {
39
44
  await new Promise((resolve) => setTimeout(resolve, delay));
40
45
  delay = Math.min(delay * 2, maxDelay); // Exponential backoff
41
46
  continue;
42
47
  }
43
48
  } else {
44
- // Error occurred
45
- throw new Error(
46
- `Poll request failed: ${response.status} ${response.statusText}`,
47
- );
49
+ // Error occurred - increment error count
50
+ errorCount++;
51
+
52
+ if (errorCount >= 3) {
53
+ // Too many consecutive errors, fail
54
+ throw new ZapierApiError(
55
+ `Poll request failed: ${response.status} ${response.statusText}`,
56
+ { statusCode: response.status },
57
+ );
58
+ }
59
+
60
+ // Treat as pending for up to 3 errors - wait and retry
61
+ if (attempt < maxAttempts - 1) {
62
+ await new Promise((resolve) => setTimeout(resolve, delay));
63
+ delay = Math.min(delay * 2, maxDelay); // Exponential backoff
64
+ continue;
65
+ }
48
66
  }
49
67
  }
50
68
 
51
- throw new Error(`Operation timed out after ${maxAttempts} attempts`);
69
+ throw new ZapierTimeoutError(
70
+ `Operation timed out after ${maxAttempts} attempts`,
71
+ { attempts: maxAttempts, maxAttempts: maxAttempts },
72
+ );
52
73
  }
@@ -0,0 +1,387 @@
1
+ import { z } from "zod";
2
+
3
+ /**
4
+ * Base Zod schemas for API response models.
5
+ * These schemas represent the raw data structures returned by Zapier API endpoints.
6
+ * All TypeScript types in api/types.ts are inferred from these schemas.
7
+ */
8
+
9
+ // ============================================================================
10
+ // Basic Building Block Schemas
11
+ // ============================================================================
12
+
13
+ export const NeedChoicesSchema = z.object({
14
+ key: z.string().optional(),
15
+ label: z.string().optional(),
16
+ sample: z.string().optional(),
17
+ value: z.string().optional(),
18
+ });
19
+
20
+ export const NeedSchema = z.object({
21
+ key: z.string(),
22
+ alters_custom_fields: z.boolean().nullable().optional(),
23
+ capabilities: z.array(z.string()).optional(),
24
+ choices: z.array(NeedChoicesSchema).optional(),
25
+ computed: z.boolean().nullable().optional(),
26
+ custom_field: z.boolean().optional(),
27
+ default: z.string().optional(),
28
+ depends_on: z.array(z.string()).optional(),
29
+ format: z.literal("SELECT").optional(),
30
+ from_search: z.boolean().optional(),
31
+ from_write: z.boolean().optional(),
32
+ help_text: z.string().optional(),
33
+ help_text_html: z.string().optional(),
34
+ input_format: z.array(z.string()).optional(),
35
+ label: z.string().optional(),
36
+ language: z.string().optional(),
37
+ parent_key: z.string().optional(),
38
+ placeholder: z.string().optional(),
39
+ prefill: z.string().optional(),
40
+ required: z.boolean().optional(),
41
+ searchfill: z.string().optional(),
42
+ send_in_json: z.boolean().optional(),
43
+ regex: z.string().optional(),
44
+ type: z
45
+ .enum([
46
+ "integer",
47
+ "string",
48
+ "text",
49
+ "datetime",
50
+ "boolean",
51
+ "file",
52
+ "decimal",
53
+ "copy",
54
+ "password",
55
+ "dict",
56
+ "code",
57
+ "filter",
58
+ "json",
59
+ ])
60
+ .optional(),
61
+ list: z.boolean().optional(),
62
+ });
63
+
64
+ export const ActionLinksSchema = z.object({
65
+ action_url: z.string().optional(),
66
+ });
67
+
68
+ export const ActionPermissionsSchema = z.object({
69
+ can_use: z.boolean().optional(),
70
+ });
71
+
72
+ export const ActionSchema = z.object({
73
+ id: z.string().optional(),
74
+ type: z.enum([
75
+ "filter",
76
+ "read",
77
+ "read_bulk",
78
+ "run",
79
+ "search",
80
+ "search_and_write",
81
+ "search_or_write",
82
+ "write",
83
+ ]),
84
+ key: z.string(),
85
+ name: z.string(),
86
+ noun: z.string().optional(),
87
+ description: z.string(),
88
+ description_html: z.string().optional(),
89
+ is_important: z.boolean().optional(),
90
+ is_hidden: z.boolean().optional(),
91
+ needs: z.array(NeedSchema).optional(),
92
+ meta: z.string().optional(),
93
+ selected_api: z.string().optional(),
94
+ links: ActionLinksSchema.optional(),
95
+ permissions: ActionPermissionsSchema.optional(),
96
+ });
97
+
98
+ export const ChoiceSchema = z.object({
99
+ value: z.union([z.string(), z.number()]),
100
+ label: z.string(),
101
+ });
102
+
103
+ export const FieldSchema = z.object({
104
+ key: z.string(),
105
+ label: z.string(),
106
+ type: z.enum([
107
+ "string",
108
+ "number",
109
+ "boolean",
110
+ "datetime",
111
+ "file",
112
+ "object",
113
+ "array",
114
+ ]),
115
+ required: z.boolean(),
116
+ description: z.string().optional(),
117
+ choices: z.array(ChoiceSchema).optional(),
118
+ });
119
+
120
+ export const ActionExecutionResultSchema = z.object({
121
+ data: z.array(z.any()),
122
+ });
123
+
124
+ export const ActionFieldChoiceSchema = z.object({
125
+ value: z.union([z.string(), z.number()]),
126
+ label: z.string(),
127
+ });
128
+
129
+ export const ActionFieldSchema = z.object({
130
+ key: z.string(),
131
+ label: z.string().optional(),
132
+ required: z.boolean(),
133
+ type: z.string().optional(),
134
+ helpText: z.string().optional(),
135
+ helpTextHtml: z.string().optional(),
136
+ choices: z.array(ActionFieldChoiceSchema).optional(),
137
+ default: z.string().optional(),
138
+ placeholder: z.string().optional(),
139
+ computed: z.boolean().optional(),
140
+ customField: z.boolean().optional(),
141
+ dependsOn: z.array(z.string()).optional(),
142
+ format: z.string().optional(),
143
+ inputFormat: z.array(z.string()).optional(),
144
+ });
145
+
146
+ // ============================================================================
147
+ // Main API Entity Schemas
148
+ // ============================================================================
149
+
150
+ export const AuthenticationSchema = z.object({
151
+ id: z.number(),
152
+ date: z.string(),
153
+ lastchanged: z.string().optional(),
154
+ account_id: z.number(),
155
+ customuser_id: z.number().optional(),
156
+ selected_api: z.string(),
157
+ destination_selected_api: z.string().nullable().optional(),
158
+ is_invite_only: z.boolean(),
159
+ is_private: z.boolean(),
160
+ shared_with_all: z.boolean(),
161
+ is_stale: z.string().optional(),
162
+ is_shared: z.string().optional(),
163
+ marked_stale_at: z.string().nullable().optional(),
164
+ label: z.string().nullable().optional(),
165
+ identifier: z.string().nullable().optional(),
166
+ title: z.string().nullable().optional(),
167
+ url: z.string().optional(),
168
+ groups: z.string().optional(),
169
+ members: z.string().optional(),
170
+ permissions: z.record(z.boolean()).optional(),
171
+ });
172
+
173
+ export const AuthenticationsResponseSchema = z.object({
174
+ count: z.number(),
175
+ next: z.string().nullable().optional(),
176
+ previous: z.string().nullable().optional(),
177
+ results: z.array(AuthenticationSchema),
178
+ });
179
+
180
+ export const UserProfileSchema = z.object({
181
+ id: z.number(),
182
+ code: z.string(),
183
+ user_id: z.number(),
184
+ auto_provisioned: z.boolean(),
185
+ first_name: z.string(),
186
+ last_name: z.string(),
187
+ username: z.string(),
188
+ personas: z.string(),
189
+ user_generated_personas: z.string(),
190
+ last_login: z.string(),
191
+ email: z.string(),
192
+ email_hash: z.string(),
193
+ email_confirmed: z.boolean(),
194
+ timezone: z.string(),
195
+ photo_url: z.string(),
196
+ has_seen_notifications: z.record(z.boolean().nullable()),
197
+ signup: z.string(),
198
+ since_signup: z.string(),
199
+ has_activated: z.boolean(),
200
+ enable_gz_creator: z.boolean(),
201
+ should_see_nps_survey: z.boolean(),
202
+ is_developer: z.boolean(),
203
+ is_expert: z.boolean(),
204
+ tos_agreement: z.boolean(),
205
+ should_renew_tos: z.boolean(),
206
+ is_gdpr_consented: z.boolean(),
207
+ disable_ssl_check: z.boolean(),
208
+ identity: z.number(),
209
+ summary_schedule: z.string(),
210
+ alert_triggers: z.string(),
211
+ alert_actions: z.string(),
212
+ is_staff: z.boolean(),
213
+ is_zt_reviewer: z.boolean(),
214
+ is_high_value: z.boolean(),
215
+ is_temporary: z.boolean(),
216
+ banner_message: z.string(),
217
+ enable_totp_2fa: z.boolean(),
218
+ viewed_help: z.record(z.boolean()),
219
+ show_editor_migration_mesaging: z.boolean(),
220
+ switches: z.record(z.any()),
221
+ organizations: z.array(z.any().nullable()),
222
+ primary_organization: z.any().nullable(),
223
+ has_active_zaps: z.boolean(),
224
+ has_google_sso: z.boolean(),
225
+ auth_realm: z.string(),
226
+ roles: z.array(
227
+ z.object({
228
+ account_id: z.number(),
229
+ role: z.string(),
230
+ }),
231
+ ),
232
+ });
233
+
234
+ export const AppSchema = z.object({
235
+ age_in_days: z.string().optional(),
236
+ api_docs_url: z.string().nullable().optional(),
237
+ app_profile_url: z.string(),
238
+ banner: z.string().optional(),
239
+ categories: z.array(z.any()).optional(), // TODO: Define proper service_category type
240
+ canonical_id: z.string().optional(),
241
+ current_implementation_id: z.string(),
242
+ days_since_last_update: z.string().optional(),
243
+ description: z.string(),
244
+ external_url: z.string(),
245
+ hashtag: z.string().optional(),
246
+ id: z.number().optional(),
247
+ image: z.string().optional(),
248
+ images: z.string().optional(),
249
+ integration_overview_html: z.string().nullable().optional(),
250
+ internal_id: z.string(),
251
+ invite_url: z.string().nullable().optional(),
252
+ is_beta: z.string().optional(),
253
+ is_built_in: z.string().optional(),
254
+ is_featured: z.string().optional(),
255
+ is_premium: z.boolean().optional(),
256
+ is_public: z.string().optional(),
257
+ is_upcoming: z.string().optional(),
258
+ learn_more_url: z.string(),
259
+ name: z.string(),
260
+ popularity: z.number(),
261
+ primary_color: z.string(),
262
+ request_count: z.string().optional(),
263
+ slug: z.string(),
264
+ zap_usage_count: z.number().nullable().optional(),
265
+ });
266
+
267
+ export const ServiceSchema = z.object({
268
+ id: z.number().optional(),
269
+ canonical_id: z.string().optional(),
270
+ current_implementation_id: z.string(),
271
+ name: z.string(),
272
+ slug: z.string(),
273
+ app_url: z.string().optional(),
274
+ learn_more_url: z.string().optional(),
275
+ description: z.string(),
276
+ primary_color: z.string(),
277
+ popularity: z.number(),
278
+ image: z.string().optional(),
279
+ images: z.string().optional(),
280
+ });
281
+
282
+ export const ServicesResponseSchema = z.object({
283
+ results: z.array(ServiceSchema),
284
+ next: z.string().nullable().optional(),
285
+ previous: z.string().nullable().optional(),
286
+ });
287
+
288
+ // ============================================================================
289
+ // Request/Response Schemas
290
+ // ============================================================================
291
+
292
+ export const NeedsRequestSchema = z.object({
293
+ selected_api: z.string(),
294
+ action: z.string(),
295
+ type_of: z.string(),
296
+ authentication_id: z.number().optional(),
297
+ params: z.record(z.any()).optional(),
298
+ });
299
+
300
+ export const NeedsResponseSchema = z.object({
301
+ success: z.boolean(),
302
+ needs: z.array(NeedSchema).optional(),
303
+ errors: z.array(z.string()).optional(),
304
+ last_fetched_at: z.string().optional(),
305
+ });
306
+
307
+ // ============================================================================
308
+ // Implementation Schema
309
+ // ============================================================================
310
+
311
+ export const ImplementationSchema = z.object({
312
+ selected_api: z.string(),
313
+ app_id: z.number().optional(),
314
+ auth_type: z.string().optional(),
315
+ auth_fields: z.string().optional(),
316
+ actions: z.array(ActionSchema).optional(),
317
+ is_deprecated: z.boolean().optional(),
318
+ is_private_only: z.boolean().optional(),
319
+ is_invite_only: z.boolean().optional(),
320
+ is_beta: z.boolean().optional().default(false),
321
+ is_premium: z.boolean().optional().default(false),
322
+ is_hidden: z.string().optional(),
323
+ name: z.string().optional(),
324
+ slug: z.string().optional(),
325
+ images: z.record(z.string().nullable()).optional(),
326
+ primary_color: z.string().optional(),
327
+ secondary_color: z.string().optional(),
328
+ current_implementation: z.string().optional(),
329
+ other_implementations: z.string().optional(),
330
+ });
331
+
332
+ export const ImplementationsResponseSchema = z.object({
333
+ count: z.number(),
334
+ next: z.string().nullable().optional(),
335
+ previous: z.string().nullable().optional(),
336
+ results: z.array(ImplementationSchema),
337
+ });
338
+
339
+ // ============================================================================
340
+ // Lightweight Implementation Meta Schema
341
+ // ============================================================================
342
+
343
+ export const ImplementationMetaSchema = z.object({
344
+ id: z.string(), // e.g. "ZapierFormatterCLIAPI@1.0.7"
345
+ name: z.string(),
346
+ slug: z.string(),
347
+ images: z
348
+ .object({
349
+ url_16x16: z.string().optional(),
350
+ url_32x32: z.string().optional(),
351
+ url_64x64: z.string().optional(),
352
+ url_128x128: z.string().optional(),
353
+ })
354
+ .optional(),
355
+ // Include other fields for completeness but we'll only use what we need
356
+ ageInDays: z.union([z.string(), z.number()]).optional(),
357
+ authType: z.string().nullable().optional(),
358
+ banner: z.string().optional(),
359
+ categories: z
360
+ .array(
361
+ z.object({
362
+ id: z.number(),
363
+ name: z.string(),
364
+ slug: z.string(),
365
+ }),
366
+ )
367
+ .optional(),
368
+ isBeta: z.boolean().optional(),
369
+ isBuiltIn: z.boolean().optional(),
370
+ isDeprecated: z.boolean().optional(),
371
+ isFeatured: z.boolean().optional(),
372
+ isHidden: z.boolean().optional(),
373
+ isInvite: z.boolean().optional(),
374
+ isPremium: z.boolean().optional(),
375
+ isPublic: z.boolean().optional(),
376
+ isUpcoming: z.boolean().optional(),
377
+ popularity: z.number().optional(),
378
+ apiDocsUrl: z.string().optional(),
379
+ classification: z.string().optional(),
380
+ });
381
+
382
+ export const ImplementationsMetaResponseSchema = z.object({
383
+ count: z.number(),
384
+ next: z.string().nullable().optional(),
385
+ previous: z.string().nullable().optional(),
386
+ results: z.array(ImplementationMetaSchema),
387
+ });
package/src/api/types.ts CHANGED
@@ -4,8 +4,37 @@
4
4
  * This module contains all type definitions related to the Zapier API client,
5
5
  * including configuration options, client interfaces, request/response types,
6
6
  * and API response models.
7
+ *
8
+ * API response model types are inferred from Zod schemas defined in api/schemas.ts
9
+ * to ensure a single source of truth and eliminate duplication.
7
10
  */
8
11
 
12
+ import { z } from "zod";
13
+ import {
14
+ NeedChoicesSchema,
15
+ NeedSchema,
16
+ ActionLinksSchema,
17
+ ActionPermissionsSchema,
18
+ ActionSchema,
19
+ ChoiceSchema,
20
+ FieldSchema,
21
+ ActionExecutionResultSchema,
22
+ ActionFieldChoiceSchema,
23
+ ActionFieldSchema,
24
+ AuthenticationSchema,
25
+ AuthenticationsResponseSchema,
26
+ UserProfileSchema,
27
+ AppSchema,
28
+ NeedsRequestSchema,
29
+ NeedsResponseSchema,
30
+ ImplementationSchema,
31
+ ImplementationsResponseSchema,
32
+ ImplementationMetaSchema,
33
+ ImplementationsMetaResponseSchema,
34
+ ServiceSchema,
35
+ ServicesResponseSchema,
36
+ } from "./schemas";
37
+
9
38
  // ============================================================================
10
39
  // API Client Infrastructure Types
11
40
  // ============================================================================
@@ -38,7 +67,11 @@ export interface RequestOptions {
38
67
  headers?: Record<string, string>;
39
68
  searchParams?: Record<string, string>;
40
69
  authRequired?: boolean;
41
- customErrorHandler?: (response: Response) => Error | undefined;
70
+ customErrorHandler?: (errorInfo: {
71
+ status: number;
72
+ statusText: string;
73
+ data: any;
74
+ }) => Error | undefined;
42
75
  }
43
76
 
44
77
  export interface PollOptions extends RequestOptions {
@@ -55,140 +88,43 @@ export interface DebugLogger {
55
88
  }
56
89
 
57
90
  // ============================================================================
58
- // API Response Models
91
+ // API Response Models (inferred from Zod schemas)
59
92
  // ============================================================================
60
93
 
61
- export interface Integration {
62
- key: string;
63
- name: string;
64
- description: string;
65
- version: string;
66
- category?: string;
67
- actions: Action[];
68
- triggers: Trigger[];
69
- current_implementation_id?: string;
70
- }
71
-
72
- export interface Action {
73
- key: string;
74
- name: string;
75
- description: string;
76
- appKey: string;
77
- type:
78
- | "read"
79
- | "read_bulk"
80
- | "write"
81
- | "run"
82
- | "search"
83
- | "search_or_write"
84
- | "search_and_write"
85
- | "filter";
86
- inputFields: Field[];
87
- outputFields: Field[];
88
- }
89
-
90
- export interface Trigger {
91
- key: string;
92
- name: string;
93
- description: string;
94
- appKey: string;
95
- type: "instant" | "polling" | "webhook";
96
- outputFields: Field[];
97
- }
98
-
99
- export interface Field {
100
- key: string;
101
- label: string;
102
- type:
103
- | "string"
104
- | "number"
105
- | "boolean"
106
- | "datetime"
107
- | "file"
108
- | "object"
109
- | "array";
110
- required: boolean;
111
- description?: string;
112
- choices?: Choice[];
113
- }
114
-
115
- export interface Choice {
116
- value: string | number;
117
- label: string;
118
- }
119
-
120
- export interface ActionExecutionResult {
121
- success: boolean;
122
- data?: any;
123
- error?: string;
124
- metadata?: {
125
- executionTime?: number;
126
- requestId?: string;
127
- };
128
- }
129
-
130
- export interface ActionField {
131
- key: string;
132
- label?: string;
133
- required: boolean;
134
- type?: string;
135
- helpText?: string;
136
- helpTextHtml?: string;
137
- choices?: ActionFieldChoice[];
138
- default?: string;
139
- placeholder?: string;
140
- computed?: boolean;
141
- customField?: boolean;
142
- dependsOn?: string[];
143
- format?: string;
144
- inputFormat?: string[];
145
- }
146
-
147
- export interface ActionFieldChoice {
148
- value: string | number;
149
- label: string;
150
- }
151
-
152
- export interface NeedsRequest {
153
- selected_api: string;
154
- action: string;
155
- type_of: string;
156
- authentication_id?: number;
157
- params?: Record<string, any>;
158
- }
159
-
160
- export interface NeedsResponse {
161
- success: boolean;
162
- needs?: ActionField[];
163
- errors?: string[];
164
- }
165
-
166
- export interface Authentication {
167
- id: number;
168
- date: string;
169
- lastchanged?: string;
170
- account_id: number;
171
- customuser_id?: number;
172
- selected_api: string;
173
- destination_selected_api?: string | null;
174
- is_invite_only: boolean;
175
- is_private: boolean;
176
- shared_with_all: boolean;
177
- is_stale?: string;
178
- is_shared?: string;
179
- marked_stale_at?: string | null;
180
- label?: string | null;
181
- identifier?: string | null;
182
- title?: string | null;
183
- url?: string;
184
- groups?: string;
185
- members?: string;
186
- permissions?: Record<string, boolean>;
187
- }
188
-
189
- export interface AuthenticationsResponse {
190
- count: number;
191
- next?: string | null;
192
- previous?: string | null;
193
- results: Authentication[];
194
- }
94
+ // Basic building blocks
95
+ export type NeedChoices = z.infer<typeof NeedChoicesSchema>;
96
+ export type Need = z.infer<typeof NeedSchema>;
97
+ export type ActionLinks = z.infer<typeof ActionLinksSchema>;
98
+ export type ActionPermissions = z.infer<typeof ActionPermissionsSchema>;
99
+ export type Action = z.infer<typeof ActionSchema>;
100
+ export type Choice = z.infer<typeof ChoiceSchema>;
101
+ export type Field = z.infer<typeof FieldSchema>;
102
+ export type ActionExecutionResult = z.infer<typeof ActionExecutionResultSchema>;
103
+ export type ActionFieldChoice = z.infer<typeof ActionFieldChoiceSchema>;
104
+ export type ActionField = z.infer<typeof ActionFieldSchema>;
105
+
106
+ // Main API entities
107
+ export type Authentication = z.infer<typeof AuthenticationSchema>;
108
+ export type AuthenticationsResponse = z.infer<
109
+ typeof AuthenticationsResponseSchema
110
+ >;
111
+ export type UserProfile = z.infer<typeof UserProfileSchema>;
112
+ export type App = z.infer<typeof AppSchema>;
113
+ export type Service = z.infer<typeof ServiceSchema>;
114
+ export type ServicesResponse = z.infer<typeof ServicesResponseSchema>;
115
+
116
+ // Request/Response types
117
+ export type NeedsRequest = z.infer<typeof NeedsRequestSchema>;
118
+ export type NeedsResponse = z.infer<typeof NeedsResponseSchema>;
119
+
120
+ // Implementation types
121
+ export type Implementation = z.infer<typeof ImplementationSchema>;
122
+ export type ImplementationsResponse = z.infer<
123
+ typeof ImplementationsResponseSchema
124
+ >;
125
+
126
+ // Implementation Meta types (lightweight)
127
+ export type ImplementationMeta = z.infer<typeof ImplementationMetaSchema>;
128
+ export type ImplementationsMetaResponse = z.infer<
129
+ typeof ImplementationsMetaResponseSchema
130
+ >;