@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/dist/index.cjs CHANGED
@@ -2,22 +2,7 @@
2
2
 
3
3
  var zod = require('zod');
4
4
 
5
- // src/types/domain.ts
6
- var ZapierSdkError = class extends Error {
7
- constructor(message, code) {
8
- super(message);
9
- this.code = code;
10
- this.name = "ZapierSdkError";
11
- }
12
- };
13
- var AppNotFoundError = class extends ZapierSdkError {
14
- constructor(appKey) {
15
- super(`App "${appKey}" not found`);
16
- this.name = "AppNotFoundError";
17
- this.code = "APP_NOT_FOUND";
18
- this.appKey = appKey;
19
- }
20
- };
5
+ // src/types/properties.ts
21
6
  function withFormatter(schema, formatMeta) {
22
7
  schema._def.formatMeta = formatMeta;
23
8
  return schema;
@@ -43,9 +28,12 @@ function isPositional(schema) {
43
28
  return false;
44
29
  }
45
30
 
31
+ // src/constants.ts
32
+ var MAX_PAGE_LIMIT = 1e4;
33
+
46
34
  // src/types/properties.ts
47
35
  var AppKeyPropertySchema = withPositional(
48
- zod.z.string().min(1).describe("App slug (e.g., 'slack', 'github')")
36
+ zod.z.string().min(1).describe("App key (e.g., 'SlackCLIAPI')")
49
37
  );
50
38
  var ActionTypePropertySchema = zod.z.enum([
51
39
  "read",
@@ -60,20 +48,155 @@ var ActionTypePropertySchema = zod.z.enum([
60
48
  var ActionKeyPropertySchema = zod.z.string().min(1).describe("Action key to execute");
61
49
  var AuthenticationIdPropertySchema = zod.z.number().int().describe("Authentication ID to use for this action");
62
50
  var InputsPropertySchema = zod.z.record(zod.z.any()).describe("Input parameters for the action");
63
- var LimitPropertySchema = zod.z.number().int().min(1).max(1e3).default(50).describe("Maximum number of items to return");
51
+ var LimitPropertySchema = zod.z.number().int().min(1).max(MAX_PAGE_LIMIT).default(50).describe("Maximum number of items to return");
64
52
  var OffsetPropertySchema = zod.z.number().int().min(0).default(0).describe("Number of items to skip for pagination");
65
53
  var OutputPropertySchema = zod.z.string().describe("Output file path");
66
54
  var DebugPropertySchema = zod.z.boolean().default(false).describe("Enable debug logging");
67
55
  var ParamsPropertySchema = zod.z.record(zod.z.any()).describe("Additional parameters");
68
56
 
57
+ // src/types/errors.ts
58
+ var ZapierError = class extends Error {
59
+ constructor(message, options = {}) {
60
+ super(message);
61
+ this.statusCode = options.statusCode;
62
+ this.errors = options.errors;
63
+ this.cause = options.cause;
64
+ this.response = options.response;
65
+ Object.setPrototypeOf(this, new.target.prototype);
66
+ }
67
+ };
68
+ var ZapierApiError = class extends ZapierError {
69
+ constructor(message, options = {}) {
70
+ super(message, options);
71
+ this.name = "ZapierApiError";
72
+ }
73
+ };
74
+ var ZapierAppNotFoundError = class extends ZapierError {
75
+ constructor(message, options = {}) {
76
+ super(message, options);
77
+ this.name = "ZapierAppNotFoundError";
78
+ this.appKey = options.appKey;
79
+ }
80
+ };
81
+ var ZapierValidationError = class extends ZapierError {
82
+ constructor(message, options = {}) {
83
+ super(message, options);
84
+ this.name = "ZapierValidationError";
85
+ this.details = options.details;
86
+ }
87
+ };
88
+ var ZapierUnknownError = class extends ZapierError {
89
+ constructor(message, options = {}) {
90
+ super(message, options);
91
+ this.name = "ZapierUnknownError";
92
+ }
93
+ };
94
+ var ZapierAuthenticationError = class extends ZapierError {
95
+ constructor(message, options = {}) {
96
+ super(message, options);
97
+ this.name = "ZapierAuthenticationError";
98
+ }
99
+ };
100
+ var ZapierResourceNotFoundError = class extends ZapierError {
101
+ constructor(message, options = {}) {
102
+ super(message, options);
103
+ this.name = "ZapierResourceNotFoundError";
104
+ this.resourceType = options.resourceType;
105
+ this.resourceId = options.resourceId;
106
+ }
107
+ };
108
+ var ZapierConfigurationError = class extends ZapierError {
109
+ constructor(message, options = {}) {
110
+ super(message, options);
111
+ this.name = "ZapierConfigurationError";
112
+ this.configType = options.configType;
113
+ }
114
+ };
115
+ var ZapierBundleError = class extends ZapierError {
116
+ constructor(message, options = {}) {
117
+ super(message, options);
118
+ this.name = "ZapierBundleError";
119
+ this.buildErrors = options.buildErrors;
120
+ }
121
+ };
122
+ var ZapierTimeoutError = class extends ZapierError {
123
+ constructor(message, options = {}) {
124
+ super(message, options);
125
+ this.name = "ZapierTimeoutError";
126
+ this.attempts = options.attempts;
127
+ this.maxAttempts = options.maxAttempts;
128
+ }
129
+ };
130
+ var ZapierActionError = class extends ZapierError {
131
+ constructor(message, options = {}) {
132
+ super(message, options);
133
+ this.name = "ZapierActionError";
134
+ this.appKey = options.appKey;
135
+ this.actionKey = options.actionKey;
136
+ }
137
+ // Legacy accessor for backward compatibility
138
+ get actionErrors() {
139
+ return this.errors;
140
+ }
141
+ };
142
+ var ZapierNotFoundError = class extends ZapierError {
143
+ constructor(message, options = {}) {
144
+ super(message, options);
145
+ this.name = "ZapierNotFoundError";
146
+ }
147
+ };
148
+ function formatErrorMessage(error) {
149
+ let message = error.message;
150
+ if (error.errors && error.errors.length > 0) {
151
+ const additionalErrors = error.errors.slice(1);
152
+ if (additionalErrors.length > 0) {
153
+ const errorDetails = additionalErrors.map((err) => ` \u2022 ${err.detail || err.title || err.code}`).join("\n");
154
+ message += "\n\nAdditional errors:\n" + errorDetails;
155
+ }
156
+ }
157
+ if (error instanceof ZapierAppNotFoundError && error.appKey) {
158
+ message += `
159
+ App key: ${error.appKey}`;
160
+ }
161
+ if (error instanceof ZapierActionError && (error.appKey || error.actionKey)) {
162
+ const context = [];
163
+ if (error.appKey) context.push(`App: ${error.appKey}`);
164
+ if (error.actionKey) context.push(`Action: ${error.actionKey}`);
165
+ message += `
166
+ ${context.join(", ")}`;
167
+ }
168
+ if (error instanceof ZapierResourceNotFoundError && (error.resourceType || error.resourceId)) {
169
+ const context = [];
170
+ if (error.resourceType) context.push(`Type: ${error.resourceType}`);
171
+ if (error.resourceId) context.push(`ID: ${error.resourceId}`);
172
+ message += `
173
+ ${context.join(", ")}`;
174
+ }
175
+ if (error instanceof ZapierTimeoutError && (error.attempts || error.maxAttempts)) {
176
+ const context = [];
177
+ if (error.attempts) context.push(`Attempts: ${error.attempts}`);
178
+ if (error.maxAttempts) context.push(`Max attempts: ${error.maxAttempts}`);
179
+ message += `
180
+ ${context.join(", ")}`;
181
+ }
182
+ if (error instanceof ZapierBundleError && error.buildErrors && error.buildErrors.length > 0) {
183
+ message += "\n\nBuild errors:\n" + error.buildErrors.map((err) => ` \u2022 ${err}`).join("\n");
184
+ }
185
+ if (error.statusCode && !message.includes(`${error.statusCode}`)) {
186
+ message += `
187
+ HTTP Status: ${error.statusCode}`;
188
+ }
189
+ return message;
190
+ }
191
+
69
192
  // src/plugins/apps/index.ts
70
193
  function createActionFunction(appKey, actionType, actionKey, options, pinnedAuthId) {
71
- return async (actionOptions = {}) => {
194
+ return (actionOptions = {}) => {
72
195
  const { sdk } = options;
73
196
  const { inputs, authenticationId: providedAuthenticationId } = actionOptions;
74
197
  const authenticationId = pinnedAuthId || providedAuthenticationId;
75
198
  if (!authenticationId) {
76
- throw new Error(
199
+ throw new ZapierValidationError(
77
200
  `Authentication ID is required. Either use the factory pattern: sdk.apps.${appKey}({ authenticationId }) or provide authenticationId in the action call.`
78
201
  );
79
202
  }
@@ -92,7 +215,7 @@ function createActionTypeProxy(appKey, actionType, options, pinnedAuthId) {
92
215
  const { sdk } = options;
93
216
  const authenticationId = pinnedAuthId || init?.authenticationId;
94
217
  if (!authenticationId) {
95
- throw new Error(
218
+ throw new ZapierValidationError(
96
219
  `Authentication ID is required for fetch. Either use the factory pattern: sdk.apps.${appKey}({ authenticationId }).fetch(...) or provide authenticationId in the fetch call.`
97
220
  );
98
221
  }
@@ -166,57 +289,40 @@ function createAppsProxy(options) {
166
289
  });
167
290
  return appsProxy;
168
291
  }
169
- function createAppsPlugin(options) {
170
- return createAppsProxy(options);
171
- }
292
+ var appsPlugin = ({ sdk }) => {
293
+ return {
294
+ apps: createAppsProxy({ sdk })
295
+ };
296
+ };
172
297
 
173
298
  // src/plugins/fetch/index.ts
174
- function createFetchPlugin(options) {
175
- const { sdk } = options;
176
- return async function fetch(url, init) {
177
- const {
178
- authenticationId,
179
- callbackUrl,
180
- authenticationTemplate,
181
- ...fetchInit
182
- } = init || {};
183
- return sdk.request({
184
- url: url.toString(),
185
- method: fetchInit.method,
186
- body: fetchInit.body,
187
- headers: fetchInit.headers,
188
- authenticationId,
189
- callbackUrl,
190
- authenticationTemplate
191
- });
299
+ var fetchPlugin = ({ sdk }) => {
300
+ return {
301
+ fetch: async function fetch(url, init) {
302
+ const {
303
+ authenticationId,
304
+ callbackUrl,
305
+ authenticationTemplate,
306
+ ...fetchInit
307
+ } = init || {};
308
+ return sdk.request({
309
+ url: url.toString(),
310
+ method: fetchInit.method,
311
+ body: fetchInit.body,
312
+ headers: fetchInit.headers,
313
+ authenticationId,
314
+ callbackUrl,
315
+ authenticationTemplate
316
+ });
317
+ }
192
318
  };
193
- }
194
-
195
- // src/auth.ts
196
- function getTokenFromEnv() {
197
- return process.env.ZAPIER_TOKEN;
198
- }
199
- async function getTokenFromCliLogin(options = {}) {
200
- try {
201
- const { getToken } = await import('@zapier/zapier-sdk-cli-login');
202
- return await getToken(options);
203
- } catch {
204
- return void 0;
205
- }
206
- }
207
- async function getTokenFromEnvOrConfig(options = {}) {
208
- const envToken = getTokenFromEnv();
209
- if (envToken) {
210
- return envToken;
211
- }
212
- return getTokenFromCliLogin(options);
213
- }
319
+ };
214
320
 
215
321
  // src/resolvers/appKey.ts
216
322
  var appKeyResolver = {
217
323
  type: "static",
218
324
  inputType: "text",
219
- placeholder: "Enter app slug (e.g., 'slack', 'github')"
325
+ placeholder: "Enter app key (e.g., 'SlackCLIAPI' or slug like 'github')"
220
326
  };
221
327
 
222
328
  // src/resolvers/actionType.ts
@@ -224,8 +330,12 @@ var actionTypeResolver = {
224
330
  type: "dynamic",
225
331
  depends: ["appKey"],
226
332
  fetch: async (sdk, resolvedParams) => {
227
- const actions = await sdk.listActions({ appKey: resolvedParams.appKey });
228
- const types = [...new Set(actions.map((action) => action.type))];
333
+ const actionsResponse = await sdk.listActions({
334
+ appKey: resolvedParams.appKey
335
+ });
336
+ const types = [
337
+ ...new Set(actionsResponse.data.map((action) => action.action_type))
338
+ ];
229
339
  return types.map((type) => ({ key: type, name: type }));
230
340
  },
231
341
  prompt: (types) => ({
@@ -244,9 +354,11 @@ var actionKeyResolver = {
244
354
  type: "dynamic",
245
355
  depends: ["appKey", "actionType"],
246
356
  fetch: async (sdk, resolvedParams) => {
247
- const actions = await sdk.listActions({ appKey: resolvedParams.appKey });
248
- return actions.filter(
249
- (action) => action.type === resolvedParams.actionType
357
+ const actionsResponse = await sdk.listActions({
358
+ appKey: resolvedParams.appKey
359
+ });
360
+ return actionsResponse.data.filter(
361
+ (action) => action.action_type === resolvedParams.actionType
250
362
  );
251
363
  },
252
364
  prompt: (actions) => ({
@@ -254,7 +366,7 @@ var actionKeyResolver = {
254
366
  name: "actionKey",
255
367
  message: "Select action:",
256
368
  choices: actions.map((action) => ({
257
- name: `${action.name || action.key} - ${action.description || "No description"}`,
369
+ name: `${action.title || action.name || action.key} - ${action.description || "No description"}`,
258
370
  value: action.key
259
371
  }))
260
372
  })
@@ -265,10 +377,19 @@ var authenticationIdResolver = {
265
377
  type: "dynamic",
266
378
  depends: ["appKey"],
267
379
  fetch: async (sdk, resolvedParams) => {
268
- return await sdk.listAuthentications({
380
+ const myAuths = await sdk.listAuthentications({
381
+ appKey: resolvedParams.appKey,
382
+ maxItems: 1e3,
383
+ owner: "me"
384
+ });
385
+ const allAuths = await sdk.listAuthentications({
269
386
  appKey: resolvedParams.appKey,
270
- limit: 1e3
387
+ maxItems: 1e3
271
388
  });
389
+ const otherAuths = allAuths.data.filter(
390
+ (auth) => !myAuths.data.some((myAuth) => myAuth.id === auth.id)
391
+ );
392
+ return [...myAuths.data, ...otherAuths];
272
393
  },
273
394
  prompt: (auths, params) => ({
274
395
  type: "list",
@@ -292,12 +413,15 @@ var inputsResolver = {
292
413
  type: "fields",
293
414
  depends: ["appKey", "actionKey", "actionType", "authenticationId"],
294
415
  fetch: async (sdk, resolvedParams) => {
295
- return await sdk.listFields({
416
+ const fieldsResponse = await sdk.listInputFields({
296
417
  appKey: resolvedParams.appKey,
297
418
  actionKey: resolvedParams.actionKey,
298
419
  actionType: resolvedParams.actionType,
299
- authenticationId: resolvedParams.authenticationId
420
+ authenticationId: resolvedParams.authenticationId,
421
+ inputs: resolvedParams.inputs
422
+ // Pass along currently resolved inputs
300
423
  });
424
+ return fieldsResponse.data;
301
425
  }
302
426
  };
303
427
 
@@ -362,6 +486,59 @@ function getResolutionOrderForParams(paramNames) {
362
486
  return order;
363
487
  }
364
488
 
489
+ // src/auth.ts
490
+ function getTokenFromEnv() {
491
+ return process.env.ZAPIER_TOKEN;
492
+ }
493
+ async function getTokenFromCliLogin(options = {}) {
494
+ try {
495
+ const { getToken } = await import('@zapier/zapier-sdk-cli-login');
496
+ return await getToken(options);
497
+ } catch {
498
+ return void 0;
499
+ }
500
+ }
501
+ async function getTokenFromEnvOrConfig(options = {}) {
502
+ const envToken = getTokenFromEnv();
503
+ if (envToken) {
504
+ return envToken;
505
+ }
506
+ return getTokenFromCliLogin(options);
507
+ }
508
+ var RelayRequestSchema = zod.z.object({
509
+ url: zod.z.string().url().describe("The URL to request (will be proxied through Relay)"),
510
+ method: zod.z.enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"]).optional().describe("HTTP method"),
511
+ body: zod.z.any().optional().describe("Request body as a string"),
512
+ authenticationId: zod.z.number().int().optional().describe("Zapier authentication ID to use for the request"),
513
+ callbackUrl: zod.z.string().url().optional().describe("URL to send async response to (makes request async)"),
514
+ authenticationTemplate: zod.z.string().optional().describe(
515
+ "Optional JSON string authentication template to bypass Notary lookup"
516
+ ),
517
+ headers: zod.z.union([
518
+ zod.z.record(zod.z.string()),
519
+ zod.z.instanceof(Headers),
520
+ zod.z.array(zod.z.tuple([zod.z.string(), zod.z.string()]))
521
+ ]).optional().describe("Request headers")
522
+ }).extend({
523
+ relayBaseUrl: zod.z.string().optional().describe("Base URL for Relay service")
524
+ }).describe("Make authenticated HTTP requests through Zapier's Relay service");
525
+ var RelayFetchSchema = RelayRequestSchema;
526
+
527
+ // src/plugins/registry/index.ts
528
+ var registryPlugin = ({ sdk, context }) => {
529
+ const metaKeys = Object.keys(context.meta || {});
530
+ const registryEntries = metaKeys.map((key) => {
531
+ return {
532
+ ...context.meta[key],
533
+ name: key,
534
+ implementation: sdk[key]
535
+ };
536
+ });
537
+ return {
538
+ __registry: registryEntries
539
+ };
540
+ };
541
+
365
542
  // src/api/auth.ts
366
543
  function isJwt(token) {
367
544
  const parts = token.split(".");
@@ -396,7 +573,13 @@ function createDebugFetch(options) {
396
573
  const method = options2?.method || "GET";
397
574
  debugLog(`\u2192 ${method} ${url}`, {
398
575
  headers: options2?.headers,
399
- body: options2?.body ? JSON.parse(options2.body) : void 0
576
+ body: options2?.body && typeof options2.body === "string" ? (() => {
577
+ try {
578
+ return JSON.parse(options2.body);
579
+ } catch {
580
+ return options2.body;
581
+ }
582
+ })() : options2?.body
400
583
  });
401
584
  try {
402
585
  const response = await originalFetch(input, options2);
@@ -431,1168 +614,1360 @@ async function pollUntilComplete(options) {
431
614
  resultExtractor = (response) => response
432
615
  } = options;
433
616
  let delay = initialDelay;
617
+ let errorCount = 0;
434
618
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
435
619
  const response = await fetchPoll();
436
620
  if (response.status === successStatus) {
621
+ errorCount = 0;
437
622
  const result = await response.json();
438
623
  return resultExtractor(result);
439
624
  } else if (response.status === pendingStatus) {
625
+ errorCount = 0;
440
626
  if (attempt < maxAttempts - 1) {
441
627
  await new Promise((resolve) => setTimeout(resolve, delay));
442
628
  delay = Math.min(delay * 2, maxDelay);
443
629
  continue;
444
630
  }
445
631
  } else {
446
- throw new Error(
447
- `Poll request failed: ${response.status} ${response.statusText}`
448
- );
632
+ errorCount++;
633
+ if (errorCount >= 3) {
634
+ throw new ZapierApiError(
635
+ `Poll request failed: ${response.status} ${response.statusText}`,
636
+ { statusCode: response.status }
637
+ );
638
+ }
639
+ if (attempt < maxAttempts - 1) {
640
+ await new Promise((resolve) => setTimeout(resolve, delay));
641
+ delay = Math.min(delay * 2, maxDelay);
642
+ continue;
643
+ }
449
644
  }
450
645
  }
451
- throw new Error(`Operation timed out after ${maxAttempts} attempts`);
646
+ throw new ZapierTimeoutError(
647
+ `Operation timed out after ${maxAttempts} attempts`,
648
+ { attempts: maxAttempts, maxAttempts }
649
+ );
452
650
  }
453
651
 
454
652
  // src/api/client.ts
455
- var SUBDOMAIN_PREFIXES = {
653
+ var SubdomainConfigMap = {
654
+ // e.g. https://relay.zapier.com
456
655
  relay: {
457
656
  authHeader: "X-Relay-Authorization"
458
657
  }
459
658
  };
460
- function createZapierApi(options) {
461
- const {
462
- baseUrl,
463
- token,
464
- getToken,
465
- debug = false,
466
- fetch: originalFetch = globalThis.fetch,
467
- onEvent
468
- } = options;
469
- const debugLog = createDebugLogger(debug);
470
- const fetch = createDebugFetch({ originalFetch, debugLog });
471
- function buildUrl(path, searchParams) {
472
- const pathSegments = path.split("/").filter(Boolean);
473
- let finalBaseUrl = baseUrl;
474
- let subdomainConfig;
475
- if (pathSegments.length > 0 && pathSegments[0] in SUBDOMAIN_PREFIXES) {
476
- const subdomain = pathSegments[0];
477
- subdomainConfig = SUBDOMAIN_PREFIXES[subdomain];
478
- const baseUrlObj = new URL(baseUrl);
479
- baseUrlObj.hostname = `${subdomain}.${baseUrlObj.hostname}`;
480
- finalBaseUrl = baseUrlObj.toString();
481
- path = "/" + pathSegments.slice(1).join("/");
482
- }
483
- const url = new URL(path, finalBaseUrl);
484
- if (searchParams) {
485
- Object.entries(searchParams).forEach(([key, value]) => {
486
- url.searchParams.set(key, value);
659
+ var ZapierApiClient = class {
660
+ constructor(options) {
661
+ this.options = options;
662
+ this.fetch = async (path, init) => {
663
+ return this.plainFetch(path, init);
664
+ };
665
+ this.get = async (path, options = {}) => {
666
+ return this.fetchJson("GET", path, void 0, options);
667
+ };
668
+ this.post = async (path, data, options = {}) => {
669
+ return this.fetchJson("POST", path, data, options);
670
+ };
671
+ this.put = async (path, data, options = {}) => {
672
+ return this.fetchJson("PUT", path, data, options);
673
+ };
674
+ this.delete = async (path, options = {}) => {
675
+ return this.fetchJson("DELETE", path, void 0, options);
676
+ };
677
+ this.poll = async (path, options = {}) => {
678
+ return pollUntilComplete({
679
+ fetchPoll: () => this.plainFetch(path, {
680
+ method: "GET",
681
+ searchParams: options.searchParams,
682
+ authRequired: options.authRequired
683
+ }),
684
+ maxAttempts: options.maxAttempts,
685
+ initialDelay: options.initialDelay,
686
+ maxDelay: options.maxDelay,
687
+ successStatus: options.successStatus,
688
+ pendingStatus: options.pendingStatus,
689
+ resultExtractor: options.resultExtractor
487
690
  });
691
+ };
692
+ }
693
+ // Helper to parse response data
694
+ async parseResult(response) {
695
+ try {
696
+ return { type: "json", data: await response.json() };
697
+ } catch {
698
+ return { type: "text", data: await response.text() };
488
699
  }
489
- return { url: url.toString(), subdomainConfig };
490
700
  }
491
- async function buildHeaders(options2 = {}, subdomainConfig) {
492
- const headers = {
493
- ...options2.headers
494
- };
495
- if (options2.authRequired !== false) {
496
- let resolvedToken = token;
497
- if (!resolvedToken && getToken) {
498
- resolvedToken = await getToken();
499
- }
500
- if (!resolvedToken) {
501
- resolvedToken = await getTokenFromEnvOrConfig({
502
- onEvent,
503
- fetch: originalFetch
504
- });
505
- }
506
- if (resolvedToken) {
507
- const authHeaderName = subdomainConfig?.authHeader || "Authorization";
508
- headers[authHeaderName] = getAuthorizationHeader(resolvedToken);
701
+ // Helper to get a token from the different places it could be gotten
702
+ async getAuthToken() {
703
+ if (this.options.token) {
704
+ return this.options.token;
705
+ }
706
+ if (this.options.getToken) {
707
+ const token = await this.options.getToken();
708
+ if (token) {
709
+ return token;
509
710
  }
510
711
  }
511
- return headers;
712
+ return getTokenFromEnvOrConfig({
713
+ onEvent: this.options.onEvent,
714
+ fetch: this.options.fetch
715
+ });
512
716
  }
513
- async function handleResponse(response, customErrorHandler, hadAuthToken) {
514
- if (!response.ok) {
515
- if (customErrorHandler) {
516
- const customError = customErrorHandler(response);
517
- if (customError) {
717
+ // Helper to handle responses
718
+ async handleResponse(params) {
719
+ const { response, customErrorHandler, wasMissingAuthToken } = params;
720
+ const { data: responseData } = await this.parseResult(response);
721
+ if (response.ok) {
722
+ return responseData;
723
+ }
724
+ const errorInfo = {
725
+ status: response.status,
726
+ statusText: response.statusText,
727
+ data: responseData
728
+ };
729
+ if (customErrorHandler) {
730
+ const customError = customErrorHandler(errorInfo);
731
+ if (customError) {
732
+ if (customError instanceof Error) {
518
733
  throw customError;
734
+ } else {
735
+ throw new Error(
736
+ `customErrorHandler returned a non-Error: ${JSON.stringify(customError)}`
737
+ );
519
738
  }
520
739
  }
521
- if (response.status >= 400 && response.status < 500 && true) {
522
- throw new Error(
523
- `Authentication required (HTTP ${response.status}). Please provide a token in options or set ZAPIER_TOKEN environment variable.`
740
+ }
741
+ const { message, errors } = this.parseErrorResponse(errorInfo);
742
+ const errorOptions = {
743
+ statusCode: response.status,
744
+ errors
745
+ };
746
+ if (response.status === 404) {
747
+ throw new ZapierNotFoundError(message, errorOptions);
748
+ }
749
+ if (response.status === 401 || response.status === 403) {
750
+ if (wasMissingAuthToken) {
751
+ throw new ZapierAuthenticationError(
752
+ `Authentication required (HTTP ${response.status}). Please provide a token in options or set ZAPIER_TOKEN environment variable.`,
753
+ errorOptions
524
754
  );
525
755
  }
526
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
756
+ throw new ZapierAuthenticationError(message, errorOptions);
757
+ }
758
+ if (response.status === 400) {
759
+ throw new ZapierValidationError(message, errorOptions);
760
+ }
761
+ throw new ZapierApiError(message, errorOptions);
762
+ }
763
+ hasErrorArray(data) {
764
+ return typeof data === "object" && data !== null && "errors" in data && Array.isArray(data.errors);
765
+ }
766
+ // Helper to check if data has API errors
767
+ isApiErrorArray(dataArray) {
768
+ const data = dataArray[0];
769
+ return typeof data === "object" && data !== null && "message" in data && "code" in data && "title" in data && "detail" in data;
770
+ }
771
+ // Do our best to extract an error message from the response data
772
+ extractErrorMessage(data) {
773
+ if (typeof data === "string") {
774
+ return data;
775
+ }
776
+ if (typeof data === "object" && data !== null) {
777
+ if ("message" in data && typeof data.message === "string") {
778
+ return data.message;
779
+ }
780
+ if ("error" in data) {
781
+ if (typeof data.error === "string") {
782
+ return data.error;
783
+ }
784
+ if (typeof data.error === "object" && data.error !== null) {
785
+ if ("message" in data.error && typeof data.error.message === "string") {
786
+ return data.error.message;
787
+ }
788
+ }
789
+ try {
790
+ return JSON.stringify(data.error);
791
+ } catch {
792
+ }
793
+ }
794
+ if ("errors" in data && Array.isArray(data.errors)) {
795
+ if (this.isApiErrorArray(data.errors)) {
796
+ return data.errors[0].detail || data.errors[0].title;
797
+ }
798
+ }
527
799
  }
800
+ return void 0;
801
+ }
802
+ // Helper to parse API error response
803
+ parseErrorResponse(errorInfo) {
804
+ const fallbackMessage = `HTTP ${errorInfo.status}: ${errorInfo.statusText}`;
528
805
  try {
529
- return await response.json();
806
+ if (typeof errorInfo.data === "string") {
807
+ return { message: `${fallbackMessage}: ${errorInfo.data}` };
808
+ }
809
+ const errorMessage = this.extractErrorMessage(errorInfo.data) || fallbackMessage;
810
+ if (this.hasErrorArray(errorInfo.data)) {
811
+ if (this.isApiErrorArray(errorInfo.data.errors)) {
812
+ return {
813
+ message: errorMessage,
814
+ errors: errorInfo.data.errors
815
+ };
816
+ } else {
817
+ return {
818
+ message: errorMessage,
819
+ errors: errorInfo.data.errors.map((e) => ({
820
+ status: errorInfo.status,
821
+ code: String(errorInfo.status),
822
+ title: errorInfo.statusText,
823
+ detail: JSON.stringify(e)
824
+ }))
825
+ };
826
+ }
827
+ }
828
+ return { message: errorMessage };
530
829
  } catch {
531
- return await response.text();
830
+ return { message: fallbackMessage };
532
831
  }
533
832
  }
534
- async function plainFetch(path, init) {
535
- if (!path.startsWith("/")) {
536
- throw new Error(
537
- `plainFetch expects a path starting with '/', got: ${path}`
538
- );
833
+ // Check if this is a path that needs subdomain routing
834
+ // e.g. /relay/workflows -> relay.zapier.com/workflows
835
+ applySubdomainBehavior(path) {
836
+ const pathSegments = path.split("/").filter(Boolean);
837
+ if (pathSegments.length > 0 && pathSegments[0] in SubdomainConfigMap) {
838
+ const domainPrefix = pathSegments[0];
839
+ const subdomainConfig = SubdomainConfigMap[domainPrefix];
840
+ const originalBaseUrl = new URL(this.options.baseUrl);
841
+ const finalBaseUrl = `https://${domainPrefix}.${originalBaseUrl.hostname}`;
842
+ const pathWithoutPrefix = "/" + pathSegments.slice(1).join("/");
843
+ return { url: new URL(pathWithoutPrefix, finalBaseUrl), subdomainConfig };
539
844
  }
540
- const { url, subdomainConfig } = buildUrl(path, init?.searchParams);
541
- const headers = await buildHeaders(init, subdomainConfig);
542
- const finalHeaders = {
543
- ...headers,
544
- ...init?.headers ? init.headers instanceof Headers ? Object.fromEntries(init.headers.entries()) : init.headers : {}
845
+ return {
846
+ url: new URL(path, this.options.baseUrl),
847
+ subdomainConfig: void 0
545
848
  };
546
- return await fetch(url, {
547
- ...init,
548
- headers: finalHeaders
549
- });
550
849
  }
551
- async function fetchJson(method, path, data, options2 = {}) {
552
- const headers = { ...options2.headers };
850
+ // Helper to build full URLs and return routing info
851
+ buildUrl(path, searchParams) {
852
+ const { url, subdomainConfig } = this.applySubdomainBehavior(path);
853
+ if (searchParams) {
854
+ Object.entries(searchParams).forEach(([key, value]) => {
855
+ url.searchParams.set(key, value);
856
+ });
857
+ }
858
+ return { url: url.toString(), subdomainConfig };
859
+ }
860
+ // Helper to build headers
861
+ async buildHeaders(options = {}, subdomainConfig) {
862
+ const headers = new Headers(options.headers ?? {});
863
+ const authToken = await this.getAuthToken();
864
+ if (authToken) {
865
+ const authHeaderName = subdomainConfig?.authHeader || "Authorization";
866
+ headers.set(authHeaderName, getAuthorizationHeader(authToken));
867
+ }
868
+ if (options.authRequired) {
869
+ if (headers.get("Authorization") == null && authToken == null) {
870
+ throw new ZapierAuthenticationError(
871
+ `Authentication required but no token available. Please set ZAPIER_TOKEN, or run the 'login' command with the CLI.`
872
+ );
873
+ }
874
+ }
875
+ return headers;
876
+ }
877
+ // Helper to perform HTTP requests with JSON handling
878
+ async fetchJson(method, path, data, options = {}) {
879
+ const headers = { ...options.headers };
553
880
  if (data && typeof data === "object") {
554
881
  headers["Content-Type"] = "application/json";
555
882
  }
556
- const response = await plainFetch(path, {
883
+ const wasMissingAuthToken = options.authRequired && await this.getAuthToken() == null;
884
+ const response = await this.plainFetch(path, {
885
+ ...options,
557
886
  method,
558
- body: data ? JSON.stringify(data) : void 0,
559
- headers,
560
- searchParams: options2.searchParams,
561
- authRequired: options2.authRequired
887
+ body: data != null ? JSON.stringify(data) : void 0,
888
+ headers
562
889
  });
563
- return handleResponse(response, options2.customErrorHandler);
890
+ const result = await this.handleResponse({
891
+ response,
892
+ customErrorHandler: options.customErrorHandler,
893
+ wasMissingAuthToken
894
+ });
895
+ if (typeof result === "string") {
896
+ throw new ZapierValidationError(
897
+ `Response could not be parsed as JSON: ${result}`
898
+ );
899
+ }
900
+ return result;
564
901
  }
565
- return {
566
- async get(path, options2 = {}) {
567
- return fetchJson("GET", path, void 0, options2);
568
- },
569
- async post(path, data, options2 = {}) {
570
- return fetchJson("POST", path, data, options2);
571
- },
572
- async put(path, data, options2 = {}) {
573
- return fetchJson("PUT", path, data, options2);
574
- },
575
- async delete(path, options2 = {}) {
576
- return fetchJson("DELETE", path, void 0, options2);
577
- },
578
- async poll(path, options2 = {}) {
579
- return pollUntilComplete({
580
- fetchPoll: () => plainFetch(path, {
581
- method: "GET",
582
- searchParams: options2.searchParams,
583
- authRequired: options2.authRequired
584
- }),
585
- maxAttempts: options2.maxAttempts,
586
- initialDelay: options2.initialDelay,
587
- maxDelay: options2.maxDelay,
588
- successStatus: options2.successStatus,
589
- pendingStatus: options2.pendingStatus,
590
- resultExtractor: options2.resultExtractor
591
- });
592
- },
593
- async fetch(path, init) {
594
- return plainFetch(path, init);
902
+ // Plain fetch method for API paths (must start with /)
903
+ async plainFetch(path, fetchOptions) {
904
+ if (!path.startsWith("/")) {
905
+ throw new ZapierValidationError(
906
+ `plainFetch expects a path starting with '/', got: ${path}`
907
+ );
595
908
  }
596
- };
597
- }
598
-
599
- // src/api/index.ts
600
- function generateRequestId() {
601
- return Math.random().toString(36).substring(2) + Date.now().toString(36);
602
- }
603
- function getOrCreateApiClient(config) {
909
+ if (fetchOptions?.body && typeof fetchOptions.body === "object") {
910
+ fetchOptions.body = JSON.stringify(fetchOptions.body);
911
+ }
912
+ const { url, subdomainConfig } = this.buildUrl(
913
+ path,
914
+ fetchOptions?.searchParams
915
+ );
916
+ const builtHeaders = await this.buildHeaders(
917
+ fetchOptions,
918
+ subdomainConfig
919
+ );
920
+ const inputHeaders = new Headers(fetchOptions?.headers ?? {});
921
+ const mergedHeaders = new Headers();
922
+ builtHeaders.forEach((value, key) => {
923
+ mergedHeaders.set(key, value);
924
+ });
925
+ inputHeaders.forEach((value, key) => {
926
+ mergedHeaders.set(key, value);
927
+ });
928
+ return await this.options.fetch(url, {
929
+ ...fetchOptions,
930
+ headers: mergedHeaders
931
+ });
932
+ }
933
+ };
934
+ var createZapierApi = (options) => {
604
935
  const {
605
- baseUrl = "https://zapier.com",
936
+ baseUrl,
606
937
  token,
607
938
  getToken,
608
- api: providedApi,
609
939
  debug = false,
610
- fetch: customFetch
611
- } = config;
612
- if (providedApi) {
613
- return providedApi;
614
- }
615
- return createZapierApi({
940
+ fetch: originalFetch = globalThis.fetch,
941
+ onEvent
942
+ } = options;
943
+ const debugLog = createDebugLogger(debug);
944
+ const debugFetch = createDebugFetch({ originalFetch, debugLog });
945
+ return new ZapierApiClient({
616
946
  baseUrl,
617
947
  token,
618
948
  getToken,
619
949
  debug,
620
- fetch: customFetch
621
- });
622
- }
623
-
624
- // src/functions/getApp/index.ts
625
- async function getApp(options) {
626
- const api = getOrCreateApiClient(options);
627
- const { appKey } = options;
628
- const app = await api.get(`/api/v4/apps/${appKey}/`, {
629
- customErrorHandler: (response) => {
630
- if (response.status === 404) {
631
- return new AppNotFoundError(appKey);
632
- }
633
- return void 0;
634
- }
950
+ fetch: debugFetch,
951
+ onEvent
635
952
  });
636
- return {
637
- key: app.slug,
638
- name: app.name,
639
- description: app.description,
640
- version: "1.0.0",
641
- category: app.category?.name,
642
- actions: [],
643
- triggers: [],
644
- current_implementation_id: app.current_implementation_id
645
- };
646
- }
953
+ };
647
954
 
648
- // src/functions/listAuthentications/index.ts
649
- async function listAuthentications(options = {}) {
650
- const api = getOrCreateApiClient(options);
651
- const listAuthenticationsInternal = async (options2 = {}) => {
652
- const searchParams = {};
653
- if (options2.appKey) {
654
- try {
655
- const app = await getApp({
656
- appKey: options2.appKey,
657
- api,
658
- token: options2.token,
659
- baseUrl: options2.baseUrl,
660
- debug: options2.debug,
661
- fetch: options2.fetch
662
- });
663
- const selectedApi = app.current_implementation_id;
664
- if (selectedApi) {
665
- const versionlessApi = selectedApi.split("@")[0];
666
- searchParams.versionless_selected_api = versionlessApi;
667
- }
668
- } catch (error) {
669
- if (error instanceof Error && error.name === "AppNotFoundError") {
670
- throw error;
671
- }
672
- console.warn(
673
- `Warning: Could not filter by app ${options2.appKey}:`,
674
- error instanceof Error ? error.message : "Unknown error"
675
- );
676
- }
677
- }
678
- if (options2.search) {
679
- searchParams.search = options2.search;
680
- } else if (options2.title) {
681
- searchParams.search = options2.title;
955
+ // src/plugins/api/index.ts
956
+ var apiPlugin = (params) => {
957
+ const {
958
+ fetch: customFetch = globalThis.fetch,
959
+ baseUrl = "https://zapier.com",
960
+ token,
961
+ getToken,
962
+ onEvent,
963
+ debug = false
964
+ } = params;
965
+ const api = createZapierApi({
966
+ baseUrl,
967
+ token,
968
+ getToken,
969
+ debug,
970
+ fetch: customFetch,
971
+ onEvent
972
+ });
973
+ return {
974
+ context: {
975
+ api
976
+ // Provide API client in context for other plugins to use
682
977
  }
683
- if (options2.account_id) {
684
- searchParams.account_id = options2.account_id;
978
+ };
979
+ };
980
+
981
+ // src/utils/pagination-utils.ts
982
+ var offsetCursorMarker = "$$offset$$";
983
+ function splitOffsetCursor(cursor) {
984
+ if (!cursor) {
985
+ return [0, cursor];
986
+ }
987
+ try {
988
+ const parsedCursor = JSON.parse(cursor);
989
+ if (!Array.isArray(parsedCursor)) {
990
+ return [0, cursor];
685
991
  }
686
- if (options2.owner) {
687
- searchParams.owner = options2.owner;
992
+ const [marker, offset, currentCursor] = parsedCursor;
993
+ if (marker !== offsetCursorMarker) {
994
+ return [0, cursor];
688
995
  }
689
- if (options2.limit) {
690
- searchParams.limit = options2.limit.toString();
996
+ if (typeof offset !== "number") {
997
+ return [0, cursor];
691
998
  }
692
- if (options2.offset) {
693
- searchParams.offset = options2.offset.toString();
999
+ return [offset, currentCursor];
1000
+ } catch {
1001
+ return [0, cursor];
1002
+ }
1003
+ }
1004
+ function createOffsetCursor(offset, currentCursor) {
1005
+ return JSON.stringify([offsetCursorMarker, offset, currentCursor]);
1006
+ }
1007
+ async function* paginateMaxItems(pageFunction, pageOptions) {
1008
+ let cursor = pageOptions?.cursor;
1009
+ let totalItemsYielded = 0;
1010
+ const maxItems = pageOptions?.maxItems;
1011
+ const pageSize = pageOptions?.pageSize;
1012
+ do {
1013
+ const options = {
1014
+ ...pageOptions || {},
1015
+ cursor,
1016
+ pageSize: maxItems !== void 0 && pageSize !== void 0 ? Math.min(pageSize, maxItems) : pageSize
1017
+ };
1018
+ const page = await pageFunction(options);
1019
+ if (maxItems !== void 0) {
1020
+ const remainingItems = maxItems - totalItemsYielded;
1021
+ if (page.data.length >= remainingItems) {
1022
+ const yieldedPage = {
1023
+ ...page,
1024
+ data: page.data.slice(0, remainingItems),
1025
+ nextCursor: void 0
1026
+ };
1027
+ yield yieldedPage;
1028
+ break;
1029
+ }
694
1030
  }
695
- const data = await api.get(
696
- "/api/v4/authentications/",
697
- {
698
- searchParams,
699
- customErrorHandler: (response) => {
700
- if (response.status === 401) {
701
- return new Error(
702
- `Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP ${response.status})`
703
- );
704
- }
705
- if (response.status === 403) {
706
- return new Error(
707
- `Access forbidden. Your token may not have the required scopes to list authentications. (HTTP ${response.status})`
708
- );
709
- }
710
- return void 0;
711
- }
1031
+ yield page;
1032
+ totalItemsYielded += page.data.length;
1033
+ cursor = page.nextCursor;
1034
+ } while (cursor);
1035
+ }
1036
+ async function* paginateBuffered(pageFunction, pageOptions) {
1037
+ const pageSize = pageOptions?.pageSize;
1038
+ const [cursorOffset, currentCursor] = splitOffsetCursor(pageOptions?.cursor);
1039
+ const options = {
1040
+ ...pageOptions || {},
1041
+ cursor: currentCursor
1042
+ };
1043
+ const iterator = paginateMaxItems(pageFunction, options);
1044
+ let bufferedPages = [];
1045
+ let isFirstPage = true;
1046
+ let cursor;
1047
+ for await (let page of iterator) {
1048
+ if (isFirstPage) {
1049
+ isFirstPage = false;
1050
+ if (cursorOffset) {
1051
+ page = {
1052
+ ...page,
1053
+ data: page.data.slice(cursorOffset)
1054
+ };
712
1055
  }
1056
+ }
1057
+ if (!pageSize) {
1058
+ yield page;
1059
+ cursor = page.nextCursor;
1060
+ continue;
1061
+ }
1062
+ const bufferedLength = bufferedPages.reduce(
1063
+ (acc, page2) => acc + page2.data.length,
1064
+ 0
713
1065
  );
714
- let auths = data.results || [];
715
- auths = auths.map((auth) => ({
716
- ...auth,
717
- title: auth.title || auth.label || void 0
718
- }));
719
- if (options2.title) {
720
- auths = auths.filter((auth) => auth.title === options2.title);
721
- }
722
- if (auths.length > 0) {
723
- auths.__pagination = {
724
- count: data.count,
725
- hasNext: !!data.next,
726
- hasPrevious: !!data.previous,
727
- nextUrl: data.next,
728
- previousUrl: data.previous
1066
+ if (bufferedLength + page.data.length < pageSize) {
1067
+ bufferedPages.push(page);
1068
+ cursor = page.nextCursor;
1069
+ continue;
1070
+ }
1071
+ const bufferedItems = bufferedPages.map((p) => p.data).flat();
1072
+ const allItems = [...bufferedItems, ...page.data];
1073
+ const pageItems = allItems.slice(0, pageSize);
1074
+ const remainingItems = allItems.slice(pageItems.length);
1075
+ if (remainingItems.length === 0) {
1076
+ yield {
1077
+ ...page,
1078
+ data: pageItems,
1079
+ nextCursor: page.nextCursor
729
1080
  };
1081
+ bufferedPages = [];
1082
+ cursor = page.nextCursor;
1083
+ continue;
730
1084
  }
731
- return auths;
732
- };
733
- if (options.limit && options.owner === void 0) {
734
- const ownedAuths = await listAuthenticationsInternal({
735
- ...options,
736
- owner: "me"
737
- });
738
- if (ownedAuths.length >= options.limit) {
739
- return ownedAuths.slice(0, options.limit);
1085
+ yield {
1086
+ ...page,
1087
+ data: pageItems,
1088
+ nextCursor: createOffsetCursor(
1089
+ page.data.length - remainingItems.length,
1090
+ cursor
1091
+ )
1092
+ };
1093
+ while (remainingItems.length > pageSize) {
1094
+ const pageItems2 = remainingItems.splice(0, pageSize);
1095
+ yield {
1096
+ ...page,
1097
+ data: pageItems2,
1098
+ nextCursor: createOffsetCursor(
1099
+ page.data.length - remainingItems.length,
1100
+ cursor
1101
+ )
1102
+ };
740
1103
  }
741
- const allAuths = await listAuthenticationsInternal({
742
- ...options,
743
- owner: void 0
744
- });
745
- const ownedAuthenticationIds = new Set(ownedAuths.map((auth) => auth.id));
746
- const additionalAuths = allAuths.filter(
747
- (auth) => !ownedAuthenticationIds.has(auth.id)
748
- );
749
- const combined = [...ownedAuths, ...additionalAuths];
750
- return combined.slice(0, options.limit);
1104
+ bufferedPages = [
1105
+ {
1106
+ ...page,
1107
+ data: remainingItems
1108
+ }
1109
+ ];
1110
+ cursor = page.nextCursor;
1111
+ }
1112
+ if (bufferedPages.length > 0) {
1113
+ const lastBufferedPage = bufferedPages.slice(-1)[0];
1114
+ const bufferedItems = bufferedPages.map((p) => p.data).flat();
1115
+ yield {
1116
+ ...lastBufferedPage,
1117
+ data: bufferedItems
1118
+ };
751
1119
  }
752
- return listAuthenticationsInternal(options);
753
1120
  }
1121
+ var paginate = paginateBuffered;
754
1122
 
755
- // src/functions/getAuthentication/index.ts
756
- async function getAuthentication(options) {
757
- const { authenticationId } = options;
758
- const api = getOrCreateApiClient(options);
759
- const data = await api.get(
760
- `/api/v4/authentications/${authenticationId}/`,
761
- {
762
- customErrorHandler: (response) => {
763
- if (response.status === 401) {
764
- return new Error(
765
- `Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP ${response.status})`
766
- );
767
- }
768
- if (response.status === 403) {
769
- return new Error(
770
- `Access forbidden. Your token may not have the required scopes to get authentication ${authenticationId}. (HTTP ${response.status})`
771
- );
772
- }
773
- if (response.status === 404) {
774
- return new Error(
775
- `Authentication ${authenticationId} not found. It may not exist or you may not have access to it. (HTTP ${response.status})`
776
- );
777
- }
778
- return void 0;
1123
+ // src/utils/validation.ts
1124
+ var validate = (schema, input) => {
1125
+ const result = schema.safeParse(input);
1126
+ if (!result.success) {
1127
+ const errorMessages = result.error.errors.map((error) => {
1128
+ const path = error.path.length > 0 ? error.path.join(".") : "input";
1129
+ return `${path}: ${error.message}`;
1130
+ });
1131
+ const message = `Validation failed:
1132
+ ${errorMessages.join("\n ")}`;
1133
+ throw new ZapierValidationError(message, {
1134
+ details: {
1135
+ zodErrors: result.error.errors,
1136
+ input
779
1137
  }
780
- }
781
- );
782
- return {
783
- ...data,
784
- title: data.title || data.label || void 0
1138
+ });
1139
+ }
1140
+ return result.data;
1141
+ };
1142
+ function createValidator(schema) {
1143
+ return function validateFn(input) {
1144
+ return validate(schema, input);
785
1145
  };
786
1146
  }
1147
+ var validateOptions = (schema, options) => {
1148
+ return validate(schema, options);
1149
+ };
787
1150
 
788
- // src/functions/findFirstAuthentication/index.ts
789
- async function findFirstAuthentication(options = {}) {
790
- const auths = await listAuthentications({
791
- ...options,
792
- limit: 1
793
- });
794
- return auths.length > 0 ? auths[0] : null;
795
- }
796
-
797
- // src/functions/findUniqueAuthentication/index.ts
798
- async function findUniqueAuthentication(options = {}) {
799
- const auths = await listAuthentications({
800
- ...options,
801
- limit: 2
802
- // Get up to 2 to check for uniqueness
803
- });
804
- if (auths.length === 0) {
805
- throw new Error("No authentication found matching the specified criteria");
1151
+ // src/utils/function-utils.ts
1152
+ function extractCursor(data) {
1153
+ if (!data?.next) {
1154
+ return void 0;
806
1155
  }
807
- if (auths.length > 1) {
808
- throw new Error(
809
- "Multiple authentications found matching the specified criteria. Expected exactly one."
810
- );
1156
+ try {
1157
+ const urlObj = new URL(data.next);
1158
+ const offset = urlObj.searchParams.get("offset");
1159
+ return offset || void 0;
1160
+ } catch {
1161
+ return void 0;
811
1162
  }
812
- return auths[0];
813
1163
  }
814
-
815
- // src/functions/listApps/index.ts
816
- async function listApps(options = {}) {
817
- const api = getOrCreateApiClient(options);
818
- const searchParams = {};
819
- if (options.category) {
820
- searchParams.category = options.category;
821
- }
822
- if (options.limit) {
823
- searchParams.limit = options.limit.toString();
824
- }
825
- if (options.offset) {
826
- searchParams.offset = options.offset.toString();
827
- }
828
- const data = await api.get("/api/v4/apps/", { searchParams });
829
- const apps = data.results?.map(
830
- (app) => ({
831
- key: app.slug,
832
- name: app.name,
833
- description: app.description,
834
- version: "1.0.0",
835
- // API doesn't provide version
836
- category: app.category?.name,
837
- actions: [],
838
- // Will be populated separately
839
- triggers: [],
840
- current_implementation_id: app.current_implementation_id
841
- })
842
- ) || [];
843
- if (apps.length > 0) {
844
- apps.__pagination = {
845
- count: data.count,
846
- hasNext: !!data.next,
847
- hasPrevious: !!data.previous,
848
- nextUrl: data.next,
849
- previousUrl: data.previous
850
- };
1164
+ function normalizeError(error) {
1165
+ if (error instanceof ZapierError) {
1166
+ return error;
851
1167
  }
852
- return apps;
1168
+ const message = error instanceof Error ? error.message : String(error);
1169
+ return new ZapierUnknownError(`Unknown error: ${message}`, { cause: error });
853
1170
  }
854
-
855
- // src/functions/listActions/index.ts
856
- async function listActions(options = {}) {
857
- const api = getOrCreateApiClient(options);
858
- if (options.appKey) {
859
- try {
860
- const appData = await getApp({
861
- appKey: options.appKey,
862
- api,
863
- token: options.token,
864
- baseUrl: options.baseUrl,
865
- debug: options.debug,
866
- fetch: options.fetch
867
- });
868
- const implementationId = appData.current_implementation_id?.split("@")[0];
869
- if (!implementationId) {
870
- throw new Error("No current_implementation_id found for app");
871
- }
872
- const searchParams2 = {
873
- global: "true",
874
- public_only: "true",
875
- selected_apis: implementationId
876
- };
877
- const data2 = await api.get("/api/v4/implementations/", {
878
- searchParams: searchParams2
879
- });
880
- const actions2 = [];
881
- for (const implementation of data2.results || []) {
882
- if (implementation.actions) {
883
- for (const action of implementation.actions) {
884
- const transformedAction = {
885
- key: action.key,
886
- name: action.name || action.label,
887
- description: action.description || "",
888
- appKey: implementation.slug || "",
889
- type: action.type || action.type_of || "read",
890
- inputFields: [],
891
- // Would need additional API call for detailed fields
892
- outputFields: []
893
- };
894
- if (options?.type && transformedAction.type !== options.type) {
895
- continue;
896
- }
897
- actions2.push(transformedAction);
898
- }
1171
+ function createFunction(coreFn, schema) {
1172
+ const functionName = coreFn.name;
1173
+ const namedFunctions = {
1174
+ [functionName]: async function(options) {
1175
+ try {
1176
+ const normalizedOptions = options ?? {};
1177
+ if (schema) {
1178
+ const validatedOptions = validateOptions(schema, normalizedOptions);
1179
+ return await coreFn({
1180
+ ...normalizedOptions,
1181
+ ...validatedOptions
1182
+ });
899
1183
  }
1184
+ return await coreFn(normalizedOptions);
1185
+ } catch (error) {
1186
+ throw normalizeError(error);
900
1187
  }
901
- if (actions2.length > 0) {
902
- actions2.__pagination = {
903
- count: data2.count,
904
- hasNext: !!data2.next,
905
- hasPrevious: !!data2.previous,
906
- nextUrl: data2.next,
907
- previousUrl: data2.previous
908
- };
909
- }
910
- return actions2;
911
- } catch (error) {
912
- if (error instanceof Error && error.name === "AppNotFoundError") {
913
- throw error;
1188
+ }
1189
+ };
1190
+ return namedFunctions[functionName];
1191
+ }
1192
+ function createPageFunction(coreFn) {
1193
+ const functionName = coreFn.name + "Page";
1194
+ const namedFunctions = {
1195
+ [functionName]: async function(options) {
1196
+ try {
1197
+ const result = await coreFn(options);
1198
+ if (result && typeof result === "object" && "data" in result) {
1199
+ const data = result.data;
1200
+ return {
1201
+ data: Array.isArray(data) ? data : [data],
1202
+ nextCursor: result.nextCursor
1203
+ };
1204
+ }
1205
+ if (Array.isArray(result)) {
1206
+ return { data: result };
1207
+ }
1208
+ return { data: [result] };
1209
+ } catch (error) {
1210
+ throw normalizeError(error);
914
1211
  }
915
- console.warn(
916
- "Optimized app lookup failed, falling back to full scan:",
917
- error
918
- );
919
1212
  }
920
- }
921
- const searchParams = {
922
- global: "true",
923
- public_only: "true"
924
1213
  };
925
- const data = await api.get("/api/v4/implementations/", { searchParams });
926
- const actions = [];
927
- for (const implementation of data.results || []) {
928
- if (implementation.actions) {
929
- for (const action of implementation.actions) {
930
- const transformedAction = {
931
- key: action.key,
932
- name: action.name || action.label,
933
- description: action.description || "",
934
- appKey: implementation.slug || "",
935
- type: action.type || action.type_of || "read",
936
- inputFields: [],
937
- // Would need additional API call for detailed fields
938
- outputFields: []
939
- };
940
- if (options?.appKey && transformedAction.appKey !== options.appKey) {
941
- continue;
1214
+ return namedFunctions[functionName];
1215
+ }
1216
+ function createPaginatedFunction(coreFn, schema) {
1217
+ const pageFunction = createPageFunction(coreFn);
1218
+ const functionName = coreFn.name;
1219
+ const validator = schema ? createValidator(schema) : null;
1220
+ const namedFunctions = {
1221
+ [functionName]: function(options) {
1222
+ const normalizedOptions = options ?? {};
1223
+ const validatedOptions = {
1224
+ ...normalizedOptions,
1225
+ ...validator ? validator(normalizedOptions) : normalizedOptions
1226
+ };
1227
+ const pageSize = validatedOptions.pageSize || 100;
1228
+ const optimizedOptions = {
1229
+ ...validatedOptions,
1230
+ pageSize
1231
+ };
1232
+ const iterator = paginate(pageFunction, optimizedOptions);
1233
+ const firstPagePromise = iterator.next().then((result) => {
1234
+ if (result.done) {
1235
+ throw new Error("Paginate should always iterate at least once");
942
1236
  }
943
- if (options?.type && transformedAction.type !== options.type) {
944
- continue;
1237
+ return result.value;
1238
+ });
1239
+ return Object.assign(firstPagePromise, {
1240
+ [Symbol.asyncIterator]: async function* () {
1241
+ yield await firstPagePromise;
1242
+ for await (const page of iterator) {
1243
+ yield page;
1244
+ }
1245
+ },
1246
+ items: function() {
1247
+ return {
1248
+ [Symbol.asyncIterator]: async function* () {
1249
+ const firstPage = await firstPagePromise;
1250
+ for (const item of firstPage.data) {
1251
+ yield item;
1252
+ }
1253
+ for await (const page of iterator) {
1254
+ for (const item of page.data) {
1255
+ yield item;
1256
+ }
1257
+ }
1258
+ }
1259
+ };
945
1260
  }
946
- actions.push(transformedAction);
1261
+ });
1262
+ }
1263
+ };
1264
+ return namedFunctions[functionName];
1265
+ }
1266
+ var NeedChoicesSchema = zod.z.object({
1267
+ key: zod.z.string().optional(),
1268
+ label: zod.z.string().optional(),
1269
+ sample: zod.z.string().optional(),
1270
+ value: zod.z.string().optional()
1271
+ });
1272
+ var NeedSchema = zod.z.object({
1273
+ key: zod.z.string(),
1274
+ alters_custom_fields: zod.z.boolean().nullable().optional(),
1275
+ capabilities: zod.z.array(zod.z.string()).optional(),
1276
+ choices: zod.z.array(NeedChoicesSchema).optional(),
1277
+ computed: zod.z.boolean().nullable().optional(),
1278
+ custom_field: zod.z.boolean().optional(),
1279
+ default: zod.z.string().optional(),
1280
+ depends_on: zod.z.array(zod.z.string()).optional(),
1281
+ format: zod.z.literal("SELECT").optional(),
1282
+ from_search: zod.z.boolean().optional(),
1283
+ from_write: zod.z.boolean().optional(),
1284
+ help_text: zod.z.string().optional(),
1285
+ help_text_html: zod.z.string().optional(),
1286
+ input_format: zod.z.array(zod.z.string()).optional(),
1287
+ label: zod.z.string().optional(),
1288
+ language: zod.z.string().optional(),
1289
+ parent_key: zod.z.string().optional(),
1290
+ placeholder: zod.z.string().optional(),
1291
+ prefill: zod.z.string().optional(),
1292
+ required: zod.z.boolean().optional(),
1293
+ searchfill: zod.z.string().optional(),
1294
+ send_in_json: zod.z.boolean().optional(),
1295
+ regex: zod.z.string().optional(),
1296
+ type: zod.z.enum([
1297
+ "integer",
1298
+ "string",
1299
+ "text",
1300
+ "datetime",
1301
+ "boolean",
1302
+ "file",
1303
+ "decimal",
1304
+ "copy",
1305
+ "password",
1306
+ "dict",
1307
+ "code",
1308
+ "filter",
1309
+ "json"
1310
+ ]).optional(),
1311
+ list: zod.z.boolean().optional()
1312
+ });
1313
+ var ActionLinksSchema = zod.z.object({
1314
+ action_url: zod.z.string().optional()
1315
+ });
1316
+ var ActionPermissionsSchema = zod.z.object({
1317
+ can_use: zod.z.boolean().optional()
1318
+ });
1319
+ var ActionSchema = zod.z.object({
1320
+ id: zod.z.string().optional(),
1321
+ type: zod.z.enum([
1322
+ "filter",
1323
+ "read",
1324
+ "read_bulk",
1325
+ "run",
1326
+ "search",
1327
+ "search_and_write",
1328
+ "search_or_write",
1329
+ "write"
1330
+ ]),
1331
+ key: zod.z.string(),
1332
+ name: zod.z.string(),
1333
+ noun: zod.z.string().optional(),
1334
+ description: zod.z.string(),
1335
+ description_html: zod.z.string().optional(),
1336
+ is_important: zod.z.boolean().optional(),
1337
+ is_hidden: zod.z.boolean().optional(),
1338
+ needs: zod.z.array(NeedSchema).optional(),
1339
+ meta: zod.z.string().optional(),
1340
+ selected_api: zod.z.string().optional(),
1341
+ links: ActionLinksSchema.optional(),
1342
+ permissions: ActionPermissionsSchema.optional()
1343
+ });
1344
+ var ChoiceSchema = zod.z.object({
1345
+ value: zod.z.union([zod.z.string(), zod.z.number()]),
1346
+ label: zod.z.string()
1347
+ });
1348
+ zod.z.object({
1349
+ key: zod.z.string(),
1350
+ label: zod.z.string(),
1351
+ type: zod.z.enum([
1352
+ "string",
1353
+ "number",
1354
+ "boolean",
1355
+ "datetime",
1356
+ "file",
1357
+ "object",
1358
+ "array"
1359
+ ]),
1360
+ required: zod.z.boolean(),
1361
+ description: zod.z.string().optional(),
1362
+ choices: zod.z.array(ChoiceSchema).optional()
1363
+ });
1364
+ zod.z.object({
1365
+ data: zod.z.array(zod.z.any())
1366
+ });
1367
+ var ActionFieldChoiceSchema = zod.z.object({
1368
+ value: zod.z.union([zod.z.string(), zod.z.number()]),
1369
+ label: zod.z.string()
1370
+ });
1371
+ zod.z.object({
1372
+ key: zod.z.string(),
1373
+ label: zod.z.string().optional(),
1374
+ required: zod.z.boolean(),
1375
+ type: zod.z.string().optional(),
1376
+ helpText: zod.z.string().optional(),
1377
+ helpTextHtml: zod.z.string().optional(),
1378
+ choices: zod.z.array(ActionFieldChoiceSchema).optional(),
1379
+ default: zod.z.string().optional(),
1380
+ placeholder: zod.z.string().optional(),
1381
+ computed: zod.z.boolean().optional(),
1382
+ customField: zod.z.boolean().optional(),
1383
+ dependsOn: zod.z.array(zod.z.string()).optional(),
1384
+ format: zod.z.string().optional(),
1385
+ inputFormat: zod.z.array(zod.z.string()).optional()
1386
+ });
1387
+ var AuthenticationSchema = zod.z.object({
1388
+ id: zod.z.number(),
1389
+ date: zod.z.string(),
1390
+ lastchanged: zod.z.string().optional(),
1391
+ account_id: zod.z.number(),
1392
+ customuser_id: zod.z.number().optional(),
1393
+ selected_api: zod.z.string(),
1394
+ destination_selected_api: zod.z.string().nullable().optional(),
1395
+ is_invite_only: zod.z.boolean(),
1396
+ is_private: zod.z.boolean(),
1397
+ shared_with_all: zod.z.boolean(),
1398
+ is_stale: zod.z.string().optional(),
1399
+ is_shared: zod.z.string().optional(),
1400
+ marked_stale_at: zod.z.string().nullable().optional(),
1401
+ label: zod.z.string().nullable().optional(),
1402
+ identifier: zod.z.string().nullable().optional(),
1403
+ title: zod.z.string().nullable().optional(),
1404
+ url: zod.z.string().optional(),
1405
+ groups: zod.z.string().optional(),
1406
+ members: zod.z.string().optional(),
1407
+ permissions: zod.z.record(zod.z.boolean()).optional()
1408
+ });
1409
+ zod.z.object({
1410
+ count: zod.z.number(),
1411
+ next: zod.z.string().nullable().optional(),
1412
+ previous: zod.z.string().nullable().optional(),
1413
+ results: zod.z.array(AuthenticationSchema)
1414
+ });
1415
+ var UserProfileSchema = zod.z.object({
1416
+ id: zod.z.number(),
1417
+ code: zod.z.string(),
1418
+ user_id: zod.z.number(),
1419
+ auto_provisioned: zod.z.boolean(),
1420
+ first_name: zod.z.string(),
1421
+ last_name: zod.z.string(),
1422
+ username: zod.z.string(),
1423
+ personas: zod.z.string(),
1424
+ user_generated_personas: zod.z.string(),
1425
+ last_login: zod.z.string(),
1426
+ email: zod.z.string(),
1427
+ email_hash: zod.z.string(),
1428
+ email_confirmed: zod.z.boolean(),
1429
+ timezone: zod.z.string(),
1430
+ photo_url: zod.z.string(),
1431
+ has_seen_notifications: zod.z.record(zod.z.boolean().nullable()),
1432
+ signup: zod.z.string(),
1433
+ since_signup: zod.z.string(),
1434
+ has_activated: zod.z.boolean(),
1435
+ enable_gz_creator: zod.z.boolean(),
1436
+ should_see_nps_survey: zod.z.boolean(),
1437
+ is_developer: zod.z.boolean(),
1438
+ is_expert: zod.z.boolean(),
1439
+ tos_agreement: zod.z.boolean(),
1440
+ should_renew_tos: zod.z.boolean(),
1441
+ is_gdpr_consented: zod.z.boolean(),
1442
+ disable_ssl_check: zod.z.boolean(),
1443
+ identity: zod.z.number(),
1444
+ summary_schedule: zod.z.string(),
1445
+ alert_triggers: zod.z.string(),
1446
+ alert_actions: zod.z.string(),
1447
+ is_staff: zod.z.boolean(),
1448
+ is_zt_reviewer: zod.z.boolean(),
1449
+ is_high_value: zod.z.boolean(),
1450
+ is_temporary: zod.z.boolean(),
1451
+ banner_message: zod.z.string(),
1452
+ enable_totp_2fa: zod.z.boolean(),
1453
+ viewed_help: zod.z.record(zod.z.boolean()),
1454
+ show_editor_migration_mesaging: zod.z.boolean(),
1455
+ switches: zod.z.record(zod.z.any()),
1456
+ organizations: zod.z.array(zod.z.any().nullable()),
1457
+ primary_organization: zod.z.any().nullable(),
1458
+ has_active_zaps: zod.z.boolean(),
1459
+ has_google_sso: zod.z.boolean(),
1460
+ auth_realm: zod.z.string(),
1461
+ roles: zod.z.array(
1462
+ zod.z.object({
1463
+ account_id: zod.z.number(),
1464
+ role: zod.z.string()
1465
+ })
1466
+ )
1467
+ });
1468
+ zod.z.object({
1469
+ age_in_days: zod.z.string().optional(),
1470
+ api_docs_url: zod.z.string().nullable().optional(),
1471
+ app_profile_url: zod.z.string(),
1472
+ banner: zod.z.string().optional(),
1473
+ categories: zod.z.array(zod.z.any()).optional(),
1474
+ // TODO: Define proper service_category type
1475
+ canonical_id: zod.z.string().optional(),
1476
+ current_implementation_id: zod.z.string(),
1477
+ days_since_last_update: zod.z.string().optional(),
1478
+ description: zod.z.string(),
1479
+ external_url: zod.z.string(),
1480
+ hashtag: zod.z.string().optional(),
1481
+ id: zod.z.number().optional(),
1482
+ image: zod.z.string().optional(),
1483
+ images: zod.z.string().optional(),
1484
+ integration_overview_html: zod.z.string().nullable().optional(),
1485
+ internal_id: zod.z.string(),
1486
+ invite_url: zod.z.string().nullable().optional(),
1487
+ is_beta: zod.z.string().optional(),
1488
+ is_built_in: zod.z.string().optional(),
1489
+ is_featured: zod.z.string().optional(),
1490
+ is_premium: zod.z.boolean().optional(),
1491
+ is_public: zod.z.string().optional(),
1492
+ is_upcoming: zod.z.string().optional(),
1493
+ learn_more_url: zod.z.string(),
1494
+ name: zod.z.string(),
1495
+ popularity: zod.z.number(),
1496
+ primary_color: zod.z.string(),
1497
+ request_count: zod.z.string().optional(),
1498
+ slug: zod.z.string(),
1499
+ zap_usage_count: zod.z.number().nullable().optional()
1500
+ });
1501
+ var ServiceSchema = zod.z.object({
1502
+ id: zod.z.number().optional(),
1503
+ canonical_id: zod.z.string().optional(),
1504
+ current_implementation_id: zod.z.string(),
1505
+ name: zod.z.string(),
1506
+ slug: zod.z.string(),
1507
+ app_url: zod.z.string().optional(),
1508
+ learn_more_url: zod.z.string().optional(),
1509
+ description: zod.z.string(),
1510
+ primary_color: zod.z.string(),
1511
+ popularity: zod.z.number(),
1512
+ image: zod.z.string().optional(),
1513
+ images: zod.z.string().optional()
1514
+ });
1515
+ zod.z.object({
1516
+ results: zod.z.array(ServiceSchema),
1517
+ next: zod.z.string().nullable().optional(),
1518
+ previous: zod.z.string().nullable().optional()
1519
+ });
1520
+ zod.z.object({
1521
+ selected_api: zod.z.string(),
1522
+ action: zod.z.string(),
1523
+ type_of: zod.z.string(),
1524
+ authentication_id: zod.z.number().optional(),
1525
+ params: zod.z.record(zod.z.any()).optional()
1526
+ });
1527
+ zod.z.object({
1528
+ success: zod.z.boolean(),
1529
+ needs: zod.z.array(NeedSchema).optional(),
1530
+ errors: zod.z.array(zod.z.string()).optional(),
1531
+ last_fetched_at: zod.z.string().optional()
1532
+ });
1533
+ var ImplementationSchema = zod.z.object({
1534
+ selected_api: zod.z.string(),
1535
+ app_id: zod.z.number().optional(),
1536
+ auth_type: zod.z.string().optional(),
1537
+ auth_fields: zod.z.string().optional(),
1538
+ actions: zod.z.array(ActionSchema).optional(),
1539
+ is_deprecated: zod.z.boolean().optional(),
1540
+ is_private_only: zod.z.boolean().optional(),
1541
+ is_invite_only: zod.z.boolean().optional(),
1542
+ is_beta: zod.z.boolean().optional().default(false),
1543
+ is_premium: zod.z.boolean().optional().default(false),
1544
+ is_hidden: zod.z.string().optional(),
1545
+ name: zod.z.string().optional(),
1546
+ slug: zod.z.string().optional(),
1547
+ images: zod.z.record(zod.z.string().nullable()).optional(),
1548
+ primary_color: zod.z.string().optional(),
1549
+ secondary_color: zod.z.string().optional(),
1550
+ current_implementation: zod.z.string().optional(),
1551
+ other_implementations: zod.z.string().optional()
1552
+ });
1553
+ zod.z.object({
1554
+ count: zod.z.number(),
1555
+ next: zod.z.string().nullable().optional(),
1556
+ previous: zod.z.string().nullable().optional(),
1557
+ results: zod.z.array(ImplementationSchema)
1558
+ });
1559
+ var ImplementationMetaSchema = zod.z.object({
1560
+ id: zod.z.string(),
1561
+ // e.g. "ZapierFormatterCLIAPI@1.0.7"
1562
+ name: zod.z.string(),
1563
+ slug: zod.z.string(),
1564
+ images: zod.z.object({
1565
+ url_16x16: zod.z.string().optional(),
1566
+ url_32x32: zod.z.string().optional(),
1567
+ url_64x64: zod.z.string().optional(),
1568
+ url_128x128: zod.z.string().optional()
1569
+ }).optional(),
1570
+ // Include other fields for completeness but we'll only use what we need
1571
+ ageInDays: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
1572
+ authType: zod.z.string().nullable().optional(),
1573
+ banner: zod.z.string().optional(),
1574
+ categories: zod.z.array(
1575
+ zod.z.object({
1576
+ id: zod.z.number(),
1577
+ name: zod.z.string(),
1578
+ slug: zod.z.string()
1579
+ })
1580
+ ).optional(),
1581
+ isBeta: zod.z.boolean().optional(),
1582
+ isBuiltIn: zod.z.boolean().optional(),
1583
+ isDeprecated: zod.z.boolean().optional(),
1584
+ isFeatured: zod.z.boolean().optional(),
1585
+ isHidden: zod.z.boolean().optional(),
1586
+ isInvite: zod.z.boolean().optional(),
1587
+ isPremium: zod.z.boolean().optional(),
1588
+ isPublic: zod.z.boolean().optional(),
1589
+ isUpcoming: zod.z.boolean().optional(),
1590
+ popularity: zod.z.number().optional(),
1591
+ apiDocsUrl: zod.z.string().optional(),
1592
+ classification: zod.z.string().optional()
1593
+ });
1594
+ zod.z.object({
1595
+ count: zod.z.number(),
1596
+ next: zod.z.string().nullable().optional(),
1597
+ previous: zod.z.string().nullable().optional(),
1598
+ results: zod.z.array(ImplementationMetaSchema)
1599
+ });
1600
+
1601
+ // src/schemas/UserProfile.ts
1602
+ var UserProfileItemSchema = withFormatter(
1603
+ UserProfileSchema.omit({ user_id: true }).extend({
1604
+ full_name: zod.z.string()
1605
+ // Computed field: first_name + " " + last_name
1606
+ }),
1607
+ {
1608
+ format: (item) => {
1609
+ const details = [];
1610
+ details.push({ text: item.email, style: "dim" });
1611
+ if (item.timezone) {
1612
+ details.push({
1613
+ text: `Timezone: ${item.timezone}`,
1614
+ style: "accent"
1615
+ });
947
1616
  }
1617
+ details.push({
1618
+ text: `Member since: ${item.since_signup}`,
1619
+ style: "dim"
1620
+ });
1621
+ return {
1622
+ title: item.full_name,
1623
+ subtitle: `@${item.username}`,
1624
+ details
1625
+ };
948
1626
  }
949
1627
  }
950
- if (actions.length > 0) {
951
- actions.__pagination = {
952
- count: data.count,
953
- hasNext: !!data.next,
954
- hasPrevious: !!data.previous,
955
- nextUrl: data.next,
956
- previousUrl: data.previous
1628
+ );
1629
+
1630
+ // src/plugins/getProfile/schemas.ts
1631
+ var GetProfileSchema = withOutputSchema(
1632
+ zod.z.object({}).optional().describe("Get current user's profile information"),
1633
+ UserProfileItemSchema
1634
+ );
1635
+
1636
+ // src/plugins/getProfile/index.ts
1637
+ var getProfilePlugin = ({ context }) => {
1638
+ const getProfile = createFunction(async function getProfile2() {
1639
+ const profile = await context.api.get("/api/v4/profile/", {
1640
+ authRequired: true
1641
+ });
1642
+ const { user_id: _unusedUserId, ...data } = profile;
1643
+ return {
1644
+ data: {
1645
+ ...data,
1646
+ // Pass through all API response fields
1647
+ full_name: `${profile.first_name} ${profile.last_name}`
1648
+ // Computed field
1649
+ }
957
1650
  };
1651
+ }, GetProfileSchema);
1652
+ return {
1653
+ getProfile,
1654
+ context: {
1655
+ meta: {
1656
+ getProfile: {
1657
+ inputSchema: GetProfileSchema
1658
+ }
1659
+ }
1660
+ }
1661
+ };
1662
+ };
1663
+ var AppItemSchema = withFormatter(
1664
+ zod.z.object({
1665
+ // Essential properties only
1666
+ title: zod.z.string(),
1667
+ // Mapped from name
1668
+ key: zod.z.string(),
1669
+ // Mapped from selected_api
1670
+ current_implementation_id: zod.z.string(),
1671
+ // From id, keeps the full version
1672
+ version: zod.z.string().optional(),
1673
+ // Extracted from implementation ID
1674
+ description: zod.z.string().optional(),
1675
+ slug: zod.z.string().optional()
1676
+ }),
1677
+ {
1678
+ format: (item) => {
1679
+ return {
1680
+ title: item.title,
1681
+ subtitle: `(${item.key})`,
1682
+ details: []
1683
+ };
1684
+ }
958
1685
  }
959
- return actions;
960
- }
1686
+ );
961
1687
 
962
- // src/functions/getAction/index.ts
963
- async function getAction(options) {
964
- const { appKey, actionKey, actionType } = options;
965
- const actions = await listActions({
966
- ...options,
967
- appKey
968
- });
969
- const action = actions.find(
970
- (a) => a.key === actionKey && a.type === actionType
971
- );
972
- if (!action) {
973
- throw new Error(`Action not found: ${actionKey} with type ${actionType}`);
974
- }
975
- return action;
976
- }
1688
+ // src/plugins/listApps/schemas.ts
1689
+ var ListAppsSchema = withOutputSchema(
1690
+ zod.z.object({
1691
+ appKeys: zod.z.array(zod.z.string()).optional().describe(
1692
+ "Filter apps by app keys (e.g., 'SlackCLIAPI' or slug like 'github')"
1693
+ ),
1694
+ search: zod.z.string().optional().describe("Search for apps by name"),
1695
+ pageSize: zod.z.number().min(1).optional().describe("Number of apps per page"),
1696
+ maxItems: zod.z.number().min(1).optional().describe("Maximum total items to return across all pages")
1697
+ }).describe("List all available apps with optional filtering"),
1698
+ AppItemSchema
1699
+ );
977
1700
 
978
- // src/functions/runAction/index.ts
979
- async function runAction(options) {
980
- const {
981
- appKey,
982
- actionType,
983
- actionKey,
984
- inputs,
985
- authenticationId: providedAuthenticationId
986
- } = options;
987
- const api = getOrCreateApiClient(options);
988
- const actionData = await getAction({
989
- ...options,
990
- appKey,
991
- actionKey,
992
- actionType
993
- });
994
- if (actionData.type !== actionType) {
995
- throw new Error(
996
- `Action type mismatch: expected ${actionType}, got ${actionData.type}`
997
- );
1701
+ // src/utils/domain-utils.ts
1702
+ function splitVersionedKey(versionedKey) {
1703
+ const parts = versionedKey.split("@");
1704
+ if (parts.length >= 2) {
1705
+ const baseKey = parts[0];
1706
+ const version = parts.slice(1).join("@");
1707
+ return [baseKey, version];
998
1708
  }
999
- const startTime = Date.now();
1000
- const result = await executeAction({
1001
- api,
1002
- appSlug: appKey,
1003
- actionKey,
1004
- actionType: actionData.type,
1005
- executionOptions: { inputs: inputs || {} },
1006
- authenticationId: providedAuthenticationId,
1007
- options
1008
- });
1009
- const executionTime = Date.now() - startTime;
1709
+ return [versionedKey, void 0];
1710
+ }
1711
+ function normalizeImplementationMetaToAppItem(implementationMeta) {
1712
+ const [selectedApi, appVersion] = splitVersionedKey(implementationMeta.id);
1010
1713
  return {
1011
- success: true,
1012
- data: result,
1013
- metadata: {
1014
- executionTime,
1015
- requestId: generateRequestId()
1016
- }
1714
+ title: implementationMeta.name,
1715
+ key: selectedApi,
1716
+ current_implementation_id: implementationMeta.id,
1717
+ // Keep the full versioned ID
1718
+ version: appVersion,
1719
+ // Extract version separately
1720
+ slug: implementationMeta.slug
1017
1721
  };
1018
1722
  }
1019
- async function executeAction(actionOptions) {
1020
- const {
1021
- api,
1022
- appSlug,
1023
- actionKey,
1024
- actionType,
1025
- executionOptions,
1026
- authenticationId,
1027
- options
1028
- } = actionOptions;
1029
- const appData = await getApp({
1030
- appKey: appSlug,
1031
- api,
1032
- token: options.token,
1033
- baseUrl: options.baseUrl,
1034
- debug: options.debug,
1035
- fetch: options.fetch
1036
- });
1037
- const selectedApi = appData.current_implementation_id;
1038
- if (!selectedApi) {
1039
- throw new Error("No current_implementation_id found for app");
1040
- }
1041
- const runRequest = {
1042
- data: {
1043
- authentication_id: authenticationId || 1,
1044
- selected_api: selectedApi,
1045
- action_key: actionKey,
1046
- action_type: actionType,
1047
- inputs: executionOptions.inputs || {}
1723
+ function normalizeAuthenticationItem(auth, options = {}) {
1724
+ let appKey = options.app_key;
1725
+ let version = options.version;
1726
+ if (auth.selected_api) {
1727
+ const [extractedAppKey, extractedVersion] = splitVersionedKey(
1728
+ auth.selected_api
1729
+ );
1730
+ if (!appKey) {
1731
+ appKey = extractedAppKey;
1732
+ }
1733
+ if (!version) {
1734
+ version = extractedVersion;
1048
1735
  }
1049
- };
1050
- const runData = await api.post("/api/actions/v1/runs", runRequest);
1051
- const runId = runData.data.id;
1052
- return await api.poll(`/api/actions/v1/runs/${runId}`, {
1053
- successStatus: 200,
1054
- pendingStatus: 202,
1055
- resultExtractor: (result) => result.data
1056
- });
1057
- }
1058
-
1059
- // src/functions/listFields/index.ts
1060
- async function listFields(options) {
1061
- const api = getOrCreateApiClient(options);
1062
- const { appKey, actionKey, actionType, authenticationId, params } = options;
1063
- const appData = await getApp({
1064
- appKey,
1065
- api,
1066
- token: options.token,
1067
- baseUrl: options.baseUrl,
1068
- debug: options.debug,
1069
- fetch: options.fetch
1070
- });
1071
- const selectedApi = appData.current_implementation_id;
1072
- if (!selectedApi) {
1073
- throw new Error("No current_implementation_id found for app");
1074
1736
  }
1075
- const needsRequest = {
1737
+ const {
1076
1738
  selected_api: selectedApi,
1077
- action: actionKey,
1078
- type_of: actionType,
1079
- authentication_id: authenticationId,
1080
- params: params || {}
1739
+ customuser_id: userId,
1740
+ ...restOfAuth
1741
+ } = auth;
1742
+ return {
1743
+ ...restOfAuth,
1744
+ // Pass through all other API response fields except selected_api
1745
+ implementation_id: selectedApi,
1746
+ // Rename selected_api to implementation_id
1747
+ title: auth.title || auth.label || void 0,
1748
+ // Coerce title from label if missing
1749
+ is_expired: auth.is_stale,
1750
+ // Map is_stale to is_expired
1751
+ expired_at: auth.marked_stale_at,
1752
+ // Map marked_stale_at to expired_at
1753
+ app_key: appKey,
1754
+ // App key from implementations endpoint or parsed from selected_api
1755
+ version,
1756
+ // Version from selected_api or provided
1757
+ user_id: userId
1758
+ // Map customuser_id to user_id
1081
1759
  };
1082
- const needsData = await api.post(
1083
- "/api/v4/implementations/needs/",
1084
- needsRequest
1085
- );
1086
- if (!needsData.success) {
1087
- throw new Error(
1088
- `Failed to get action fields: ${needsData.errors?.join(", ") || "Unknown error"}`
1089
- );
1090
- }
1091
- return (needsData.needs || []).map((need) => ({
1092
- key: need.key,
1093
- label: need.label,
1094
- required: need.required || false,
1095
- type: need.type,
1096
- helpText: need.help_text,
1097
- helpTextHtml: need.help_text_html,
1098
- choices: need.choices?.map((choice) => ({
1099
- value: choice.value,
1100
- label: choice.label
1101
- })),
1102
- default: need.default,
1103
- placeholder: need.placeholder,
1104
- computed: need.computed,
1105
- customField: need.custom_field,
1106
- dependsOn: need.depends_on,
1107
- format: need.format,
1108
- inputFormat: need.input_format
1109
- }));
1110
1760
  }
1111
-
1112
- // src/functions/generateTypes/index.ts
1113
- function generateFetchMethodSignature() {
1114
- return ` /** Make authenticated HTTP requests through Zapier's Relay service */
1115
- fetch: (options: Omit<z.infer<typeof RelayFetchSchema>, 'authenticationId'>) => Promise<Response>`;
1761
+ function normalizeActionItem(action) {
1762
+ const { name, type, selected_api: appKey, ...restOfAction } = action;
1763
+ return {
1764
+ ...restOfAction,
1765
+ app_key: appKey || "",
1766
+ action_type: type,
1767
+ title: name,
1768
+ // Map name to title
1769
+ type: "action"
1770
+ };
1116
1771
  }
1117
- async function generateTypes(options) {
1118
- const {
1119
- appKey,
1120
- authenticationId,
1121
- output = `./types/${appKey}.d.ts`
1122
- } = options;
1123
- const { app, version } = parseAppIdentifier(appKey);
1124
- const actions = await listActions({
1125
- ...options,
1126
- appKey: app
1127
- });
1128
- if (actions.length === 0) {
1129
- const typeDefinitions2 = generateEmptyTypesFile(app, version);
1130
- if (output) {
1131
- const fs = await import('fs');
1132
- const path = await import('path');
1133
- fs.mkdirSync(path.dirname(output), { recursive: true });
1134
- fs.writeFileSync(output, typeDefinitions2, "utf8");
1135
- }
1136
- return typeDefinitions2;
1137
- }
1138
- const actionsWithFields = [];
1139
- if (authenticationId) {
1140
- for (const action of actions) {
1141
- try {
1142
- const fields = await listFields({
1143
- ...options,
1144
- appKey: action.appKey,
1145
- actionKey: action.key,
1146
- actionType: action.type,
1147
- authenticationId
1148
- });
1149
- actionsWithFields.push({ ...action, inputFields: fields });
1150
- } catch {
1151
- actionsWithFields.push({ ...action, inputFields: [] });
1772
+ function groupVersionedAppKeysByType(appKeys) {
1773
+ const result = {
1774
+ selectedApi: [],
1775
+ slug: []
1776
+ };
1777
+ const seenSelectedApi = /* @__PURE__ */ new Set();
1778
+ const seenSlugs = /* @__PURE__ */ new Set();
1779
+ for (const key of appKeys) {
1780
+ const [keyWithoutVersion, version] = splitVersionedKey(key);
1781
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1782
+ if (uuidRegex.test(keyWithoutVersion)) {
1783
+ throw new Error(
1784
+ `UUID app keys are not supported. Use app slug or implementation ID instead of: ${key}`
1785
+ );
1786
+ }
1787
+ if (isSnakeCasedSlug(keyWithoutVersion)) {
1788
+ const dashified = dashifySnakeCasedSlug(keyWithoutVersion);
1789
+ const slugWithVersion = version ? `${dashified}@${version}` : dashified;
1790
+ if (!seenSlugs.has(slugWithVersion)) {
1791
+ seenSlugs.add(slugWithVersion);
1792
+ result.slug.push(slugWithVersion);
1152
1793
  }
1794
+ continue;
1795
+ }
1796
+ if (keyWithoutVersion.match(/^[a-z0-9]+(?:-[a-z0-9]+)*$/)) {
1797
+ seenSlugs.add(key);
1798
+ result.slug.push(key);
1799
+ continue;
1800
+ }
1801
+ if (!seenSelectedApi.has(key)) {
1802
+ seenSelectedApi.add(key);
1803
+ result.selectedApi.push(key);
1153
1804
  }
1154
- } else {
1155
- actions.forEach((action) => {
1156
- actionsWithFields.push({ ...action, inputFields: [] });
1157
- });
1158
- }
1159
- const typeDefinitions = generateTypeDefinitions(
1160
- app,
1161
- actionsWithFields,
1162
- version
1163
- );
1164
- if (output) {
1165
- const fs = await import('fs');
1166
- const path = await import('path');
1167
- fs.mkdirSync(path.dirname(output), { recursive: true });
1168
- fs.writeFileSync(output, typeDefinitions, "utf8");
1169
1805
  }
1170
- return typeDefinitions;
1806
+ return result;
1171
1807
  }
1172
- function parseAppIdentifier(identifier) {
1173
- const parts = identifier.split("@");
1808
+ function groupAppKeysByType(appKeys) {
1809
+ const grouped = groupVersionedAppKeysByType(appKeys);
1174
1810
  return {
1175
- app: parts[0],
1176
- version: parts[1]
1811
+ selectedApi: [
1812
+ ...new Set(grouped.selectedApi.map((key) => key.split("@")[0]))
1813
+ ],
1814
+ slug: [...new Set(grouped.slug.map((key) => key.split("@")[0]))]
1177
1815
  };
1178
1816
  }
1179
- function generateTypeDefinitions(appKey, actions, version) {
1180
- if (actions.length === 0) {
1181
- return generateEmptyTypesFile(appKey, version);
1817
+ function isSnakeCasedSlug(slug) {
1818
+ if (slug.match(/^_[0-9]/)) {
1819
+ slug = slug.slice(1);
1182
1820
  }
1183
- const actionsByType = actions.reduce(
1184
- (acc, action) => {
1185
- if (!acc[action.type]) {
1186
- acc[action.type] = [];
1187
- }
1188
- acc[action.type].push(action);
1189
- return acc;
1190
- },
1191
- {}
1192
- );
1193
- const appName = capitalize(appKey);
1194
- const versionComment = version ? ` * Generated for ${appKey}@${version}` : ` * Generated for ${appKey}`;
1195
- let output = `/* eslint-disable @typescript-eslint/naming-convention */
1196
- /**
1197
- * Auto-generated TypeScript types for Zapier ${appKey} actions
1198
- ${versionComment}
1199
- * Generated on: ${(/* @__PURE__ */ new Date()).toISOString()}
1200
- *
1201
- * Usage:
1202
- * import type { ${appName}Sdk } from './path/to/this/file'
1203
- * const sdk = createZapierSdk() as unknown as ${appName}Sdk
1204
- *
1205
- * // Direct usage (per-call auth):
1206
- * await sdk.apps.${appKey}.search.user_by_email({ authenticationId: 123, inputs: { email } })
1207
- *
1208
- * // Factory usage (pinned auth):
1209
- * const my${appName} = sdk.apps.${appKey}({ authenticationId: 123 })
1210
- * await my${appName}.search.user_by_email({ inputs: { email } })
1211
- */
1212
-
1213
- import type { ActionExecutionOptions, ActionExecutionResult } from '@zapier/zapier-sdk'
1214
- import { z } from 'zod'
1215
- import { RelayFetchSchema } from '@zapier/zapier-sdk'
1216
-
1217
- `;
1218
- actions.forEach((action) => {
1219
- if (action.inputFields.length > 0) {
1220
- const inputTypeName = `${appName}${capitalize(action.type)}${capitalize(
1221
- sanitizeActionName(action.key)
1222
- )}Inputs`;
1223
- output += `interface ${inputTypeName} {
1224
- `;
1225
- action.inputFields.forEach((field) => {
1226
- const isOptional = !field.required;
1227
- const fieldType = mapFieldTypeToTypeScript(field);
1228
- const description = field.helpText ? ` /** ${escapeComment(field.helpText)} */
1229
- ` : "";
1230
- output += `${description} ${sanitizeFieldName(field.key)}${isOptional ? "?" : ""}: ${fieldType}
1231
- `;
1232
- });
1233
- output += `}
1821
+ return !!slug.match(/^[a-z0-9]+(?:_[a-z0-9]+)*$/);
1822
+ }
1823
+ function dashifySnakeCasedSlug(slug) {
1824
+ if (!isSnakeCasedSlug(slug)) {
1825
+ return slug;
1826
+ }
1827
+ if (slug.startsWith("_")) {
1828
+ slug = slug.slice(1);
1829
+ }
1830
+ return slug.replace(/_/g, "-");
1831
+ }
1234
1832
 
1235
- `;
1236
- }
1237
- });
1238
- Object.entries(actionsByType).forEach(([actionType, typeActions]) => {
1239
- const typeName = `${appName}${capitalize(actionType)}Actions`;
1240
- output += `interface ${typeName} {
1241
- `;
1242
- typeActions.forEach((action) => {
1243
- const actionName = sanitizeActionName(action.key);
1244
- const description = action.description ? ` /** ${escapeComment(action.description)} */
1245
- ` : "";
1246
- if (action.inputFields.length > 0) {
1247
- const inputTypeName = `${appName}${capitalize(action.type)}${capitalize(
1248
- sanitizeActionName(action.key)
1249
- )}Inputs`;
1250
- output += `${description} ${actionName}: (options: { inputs: ${inputTypeName} } & Omit<ActionExecutionOptions, 'inputs'>) => Promise<ActionExecutionResult>
1251
- `;
1252
- } else {
1253
- output += `${description} ${actionName}: (options?: { inputs?: Record<string, any> } & ActionExecutionOptions) => Promise<ActionExecutionResult>
1254
- `;
1255
- }
1256
- });
1257
- output += `}
1258
-
1259
- `;
1260
- });
1261
- output += `interface ${appName}AppProxy {
1262
- `;
1263
- Object.keys(actionsByType).forEach((actionType) => {
1264
- const typeName = `${appName}${capitalize(actionType)}Actions`;
1265
- output += ` ${actionType}: ${typeName}
1266
- `;
1267
- });
1268
- output += generateFetchMethodSignature() + "\n";
1269
- output += `}
1270
-
1271
- `;
1272
- output += `interface ${appName}AppFactory {
1273
- `;
1274
- output += ` (options: { authenticationId: number }): ${appName}AppProxy
1275
- `;
1276
- output += `}
1277
-
1278
- `;
1279
- output += `type ${appName}AppWithFactory = ${appName}AppFactory & ${appName}AppProxy
1280
-
1281
- `;
1282
- output += `export interface ${appName}Sdk {
1283
- `;
1284
- output += ` apps: {
1285
- `;
1286
- output += ` ${appKey}: ${appName}AppWithFactory
1287
- `;
1288
- output += ` }
1289
- `;
1290
- output += `}
1291
- `;
1292
- return output;
1293
- }
1294
- function generateEmptyTypesFile(appKey, version) {
1295
- const appName = capitalize(appKey);
1296
- const versionComment = version ? ` * Generated for ${appKey}@${version}` : ` * Generated for ${appKey}`;
1297
- return `/* eslint-disable @typescript-eslint/naming-convention */
1298
- /**
1299
- * Auto-generated TypeScript types for Zapier ${appKey} actions
1300
- ${versionComment}
1301
- * Generated on: ${(/* @__PURE__ */ new Date()).toISOString()}
1302
- *
1303
- * No actions found for this app.
1304
- */
1305
-
1306
- import type { ActionExecutionOptions, ActionExecutionResult } from '@zapier/zapier-sdk'
1307
- import { z } from 'zod'
1308
- import { RelayFetchSchema } from '@zapier/zapier-sdk'
1309
-
1310
- interface ${appName}AppProxy {
1311
- // No actions available
1312
- ${generateFetchMethodSignature()}
1313
- }
1314
-
1315
- interface ${appName}AppFactory {
1316
- (options: { authenticationId: number }): ${appName}AppProxy
1317
- }
1318
-
1319
- type ${appName}AppWithFactory = ${appName}AppFactory & ${appName}AppProxy
1320
-
1321
- export interface ${appName}Sdk {
1322
- apps: {
1323
- ${appKey}: ${appName}AppWithFactory
1324
- }
1325
- }
1326
- `;
1327
- }
1328
- function capitalize(str) {
1329
- return str.charAt(0).toUpperCase() + str.slice(1).replace(/[-_]/g, "");
1330
- }
1331
- function sanitizeActionName(actionKey) {
1332
- let sanitized = actionKey.replace(/[^a-zA-Z0-9_$]/g, "_");
1333
- if (/^[0-9]/.test(sanitized)) {
1334
- sanitized = "_" + sanitized;
1335
- }
1336
- return sanitized;
1337
- }
1338
- function sanitizeFieldName(fieldKey) {
1339
- let sanitized = fieldKey.replace(/[^a-zA-Z0-9_$]/g, "_");
1340
- if (/^[0-9]/.test(sanitized)) {
1341
- sanitized = "_" + sanitized;
1342
- }
1343
- return sanitized;
1344
- }
1345
- function escapeComment(comment) {
1346
- return comment.replace(/\*\//g, "*\\/").replace(/\r?\n/g, " ");
1347
- }
1348
- function mapFieldTypeToTypeScript(field) {
1349
- if (field.choices && field.choices.length > 0) {
1350
- const choiceValues = field.choices.filter(
1351
- (choice) => choice.value !== void 0 && choice.value !== null && choice.value !== ""
1352
- ).map(
1353
- (choice) => typeof choice.value === "string" ? `"${choice.value}"` : choice.value
1833
+ // src/plugins/listApps/index.ts
1834
+ var listAppsPlugin = ({ context }) => {
1835
+ const listApps = createPaginatedFunction(async function listAppsPage(options) {
1836
+ const api = context.api;
1837
+ const opts = options;
1838
+ const appKeys = [...opts.appKeys ?? []].map(
1839
+ (key) => splitVersionedKey(key)[0]
1354
1840
  );
1355
- if (choiceValues.length > 0) {
1356
- return choiceValues.join(" | ");
1357
- }
1358
- }
1359
- switch (field.type?.toLowerCase()) {
1360
- case "string":
1361
- case "text":
1362
- case "email":
1363
- case "url":
1364
- case "password":
1365
- return "string";
1366
- case "integer":
1367
- case "number":
1368
- return "number";
1369
- case "boolean":
1370
- return "boolean";
1371
- case "datetime":
1372
- case "date":
1373
- return "string";
1374
- // ISO date strings
1375
- case "file":
1376
- return "string";
1377
- // File URL or content
1378
- case "array":
1379
- return "any[]";
1380
- case "object":
1381
- return "Record<string, any>";
1382
- default:
1383
- return "string | number | boolean";
1384
- }
1385
- }
1386
-
1387
- // src/functions/bundleCode/index.ts
1388
- async function bundleCode(options) {
1389
- const {
1390
- input,
1391
- output,
1392
- target = "es2020",
1393
- cjs = false,
1394
- minify = false,
1395
- string: returnString = false
1396
- } = options;
1397
- const { buildSync } = await import('esbuild');
1398
- const fs = await import('fs');
1399
- const path = await import('path');
1400
- const resolvedInput = path.resolve(process.cwd(), input);
1401
- try {
1402
- const result = buildSync({
1403
- entryPoints: [resolvedInput],
1404
- bundle: true,
1405
- platform: "node",
1406
- target,
1407
- format: cjs ? "cjs" : "esm",
1408
- minify,
1409
- write: false,
1410
- external: [],
1411
- // Bundle everything
1412
- banner: {
1413
- js: "#!/usr/bin/env node"
1414
- }
1415
- });
1416
- if (result.errors.length > 0) {
1417
- throw new Error(
1418
- `Bundle failed: ${result.errors.map((e) => e.text).join(", ")}`
1841
+ if (opts.search) {
1842
+ const searchParams2 = {};
1843
+ searchParams2.term = opts.search;
1844
+ const searchEnvelope = await api.get(
1845
+ "/api/v4/implementations-meta/search/",
1846
+ {
1847
+ searchParams: searchParams2
1848
+ }
1419
1849
  );
1850
+ const implementations = searchEnvelope.results.map(
1851
+ normalizeImplementationMetaToAppItem
1852
+ );
1853
+ const appKeysSet = new Set(appKeys);
1854
+ for (const implementation of implementations) {
1855
+ if (!appKeysSet.has(implementation.key)) {
1856
+ appKeysSet.add(implementation.key);
1857
+ appKeys.push(implementation.key);
1858
+ }
1859
+ }
1420
1860
  }
1421
- const bundledCode = result.outputFiles?.[0]?.text;
1422
- if (!bundledCode) {
1423
- throw new Error("No output generated");
1424
- }
1425
- let finalOutput = bundledCode;
1426
- if (returnString) {
1427
- finalOutput = JSON.stringify(bundledCode);
1861
+ const searchParams = {};
1862
+ if (opts.pageSize) {
1863
+ searchParams.limit = opts.pageSize.toString();
1428
1864
  }
1429
- if (output) {
1430
- fs.mkdirSync(path.dirname(output), { recursive: true });
1431
- fs.writeFileSync(output, finalOutput, "utf8");
1865
+ searchParams.latest_only = "true";
1866
+ if (opts.cursor) {
1867
+ searchParams.offset = opts.cursor;
1432
1868
  }
1433
- return finalOutput;
1434
- } catch (error) {
1435
- throw new Error(
1436
- `Bundle failed: ${error instanceof Error ? error.message : "Unknown error"}`
1437
- );
1438
- }
1439
- }
1440
-
1441
- // src/functions/request/index.ts
1442
- function transformUrlToRelayPath(url) {
1443
- const targetUrl = new URL(url);
1444
- const relayPath = `/relay/${targetUrl.hostname}${targetUrl.pathname}${targetUrl.search}${targetUrl.hash}`;
1445
- return relayPath;
1446
- }
1447
- async function request(options) {
1448
- const {
1449
- url,
1450
- method = "GET",
1451
- body,
1452
- headers,
1453
- authenticationId,
1454
- callbackUrl,
1455
- authenticationTemplate,
1456
- ...config
1457
- } = options;
1458
- return relayFetch(
1459
- url,
1460
- {
1461
- method,
1462
- body,
1463
- headers,
1464
- authenticationId,
1465
- callbackUrl,
1466
- authenticationTemplate
1467
- },
1468
- config
1469
- );
1470
- }
1471
- async function relayFetch(url, options = {}, config = {}) {
1472
- const api = getOrCreateApiClient(config);
1473
- const {
1474
- authenticationId,
1475
- callbackUrl,
1476
- authenticationTemplate,
1477
- method = "GET",
1478
- body,
1479
- ...fetchOptions
1480
- } = options;
1481
- const relayPath = transformUrlToRelayPath(url);
1482
- const headers = {};
1483
- if (fetchOptions.headers) {
1484
- const headerEntries = fetchOptions.headers instanceof Headers ? Array.from(fetchOptions.headers.entries()) : Object.entries(fetchOptions.headers);
1485
- for (const [key, value] of headerEntries) {
1486
- headers[key] = value;
1869
+ if (appKeys.length > 0) {
1870
+ const groupedAppKeys = groupAppKeysByType(appKeys);
1871
+ if (groupedAppKeys.selectedApi.length > 0) {
1872
+ searchParams.selected_apis = groupedAppKeys.selectedApi.join(",");
1873
+ }
1874
+ if (groupedAppKeys.slug.length > 0) {
1875
+ searchParams.slugs = groupedAppKeys.slug.join(",");
1876
+ }
1487
1877
  }
1488
- }
1489
- if (authenticationId) {
1490
- headers["X-Relay-Authentication-Id"] = authenticationId.toString();
1491
- }
1492
- if (callbackUrl) {
1493
- headers["X-Relay-Callback-Url"] = callbackUrl;
1494
- }
1495
- if (authenticationTemplate) {
1496
- headers["X-Authentication-Template"] = authenticationTemplate;
1497
- }
1498
- return await api.fetch(relayPath, {
1499
- method,
1500
- body,
1501
- headers
1502
- });
1503
- }
1504
- var RelayRequestSchema = zod.z.object({
1505
- url: zod.z.string().url().describe("The URL to request (will be proxied through Relay)"),
1506
- method: zod.z.enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"]).optional().describe("HTTP method"),
1507
- body: zod.z.string().optional().describe("Request body as a string"),
1508
- authenticationId: zod.z.number().int().optional().describe("Zapier authentication ID to use for the request"),
1509
- callbackUrl: zod.z.string().url().optional().describe("URL to send async response to (makes request async)"),
1510
- authenticationTemplate: zod.z.string().optional().describe(
1511
- "Optional JSON string authentication template to bypass Notary lookup"
1512
- ),
1513
- headers: zod.z.record(zod.z.string()).optional().describe("Request headers")
1514
- }).describe("Make authenticated HTTP requests through Zapier's Relay service");
1515
- var RelayFetchSchema = RelayRequestSchema;
1516
- var AppItemSchema = withFormatter(
1517
- zod.z.object({
1518
- key: zod.z.string(),
1519
- name: zod.z.string().optional(),
1520
- description: zod.z.string().optional(),
1521
- category: zod.z.string().optional()
1522
- }),
1523
- {
1524
- format: (item) => {
1525
- const details = [];
1526
- if (item.description) {
1527
- details.push({ text: item.description, style: "dim" });
1878
+ const implementationsEnvelope = await api.get(
1879
+ "/api/v4/implementations-meta/lookup/",
1880
+ {
1881
+ searchParams
1528
1882
  }
1529
- if (item.category) {
1530
- details.push({
1531
- text: `Category: ${item.category}`,
1532
- style: "accent"
1533
- });
1883
+ );
1884
+ return {
1885
+ data: implementationsEnvelope.results.map(
1886
+ normalizeImplementationMetaToAppItem
1887
+ ),
1888
+ nextCursor: extractCursor(implementationsEnvelope)
1889
+ };
1890
+ }, ListAppsSchema);
1891
+ return {
1892
+ listApps,
1893
+ context: {
1894
+ meta: {
1895
+ listApps: {
1896
+ inputSchema: ListAppsSchema
1897
+ }
1534
1898
  }
1535
- return {
1536
- title: item.name || item.key,
1537
- subtitle: `(${item.key})`,
1538
- details
1539
- };
1540
1899
  }
1541
- }
1542
- );
1543
-
1544
- // src/functions/listApps/schemas.ts
1545
- var ListAppsSchema = withOutputSchema(
1900
+ };
1901
+ };
1902
+ var GetAppSchema = withOutputSchema(
1546
1903
  zod.z.object({
1547
- category: zod.z.string().optional().describe("Filter apps by category"),
1548
- limit: LimitPropertySchema.optional().describe(
1549
- "Maximum number of items to return (1-200)"
1550
- ),
1551
- offset: OffsetPropertySchema.optional().describe(
1552
- "Number of items to skip for pagination"
1904
+ appKey: AppKeyPropertySchema.describe(
1905
+ "App key of app to fetch (e.g., 'SlackCLIAPI')"
1553
1906
  )
1554
- }).describe("List all available apps with optional filtering"),
1907
+ }).describe("Get detailed information about a specific app"),
1555
1908
  AppItemSchema
1556
1909
  );
1557
1910
 
1558
- // src/functions/listApps/info.ts
1559
- var listAppsInfo = {
1560
- name: listApps.name,
1561
- inputSchema: ListAppsSchema,
1562
- implementation: listApps
1563
- };
1564
- var GetAppSchema = zod.z.object({
1565
- appKey: AppKeyPropertySchema.describe(
1566
- "App key or slug to fetch (e.g., google-sheets, slack, github)"
1567
- )
1568
- }).describe("Get detailed information about a specific app");
1569
-
1570
- // src/functions/getApp/info.ts
1571
- var getAppInfo = {
1572
- name: getApp.name,
1573
- inputSchema: GetAppSchema,
1574
- implementation: getApp
1911
+ // src/plugins/getApp/index.ts
1912
+ var getAppPlugin = ({ sdk }) => {
1913
+ const getApp = createFunction(async function getApp2(options) {
1914
+ const { appKey } = options;
1915
+ const appsIterator = sdk.listApps({
1916
+ ...options,
1917
+ appKeys: [appKey]
1918
+ }).items();
1919
+ const apps = [];
1920
+ for await (const app of appsIterator) {
1921
+ apps.push(app);
1922
+ break;
1923
+ }
1924
+ if (apps.length === 0) {
1925
+ throw new ZapierAppNotFoundError(appKey);
1926
+ }
1927
+ return {
1928
+ data: apps[0]
1929
+ };
1930
+ }, GetAppSchema);
1931
+ return {
1932
+ getApp,
1933
+ context: {
1934
+ meta: {
1935
+ getApp: {
1936
+ inputSchema: GetAppSchema
1937
+ }
1938
+ }
1939
+ }
1940
+ };
1575
1941
  };
1576
1942
  var ActionItemSchema = withFormatter(
1577
- zod.z.object({
1578
- key: zod.z.string(),
1579
- name: zod.z.string().optional(),
1580
- type: zod.z.string(),
1581
- appKey: zod.z.string().optional(),
1582
- description: zod.z.string().optional()
1943
+ ActionSchema.omit({ type: true, name: true }).extend({
1944
+ app_key: zod.z.string(),
1945
+ // Mapped from selected_api
1946
+ action_type: ActionSchema.shape.type,
1947
+ // Mapped from original 'type' field
1948
+ title: zod.z.string(),
1949
+ // Mapped from original 'name' field
1950
+ type: zod.z.literal("action")
1951
+ // Fixed type identifier
1583
1952
  }),
1584
1953
  {
1585
1954
  format: (item) => {
1586
1955
  const details = [];
1587
- details.push({ text: `Type: ${item.type}`, style: "accent" });
1588
- if (item.appKey) {
1589
- details.push({ text: `App: ${item.appKey}`, style: "normal" });
1956
+ details.push({
1957
+ text: `Type: ${item.action_type}`,
1958
+ style: "accent"
1959
+ });
1960
+ if (item.app_key) {
1961
+ details.push({
1962
+ text: `App: ${item.app_key}`,
1963
+ style: "normal"
1964
+ });
1590
1965
  }
1591
1966
  if (item.description) {
1592
1967
  details.push({ text: item.description, style: "dim" });
1593
1968
  }
1594
1969
  return {
1595
- title: item.name || item.key,
1970
+ title: item.title || item.name || item.key,
1596
1971
  subtitle: `(${item.key})`,
1597
1972
  details
1598
1973
  };
@@ -1600,22 +1975,88 @@ var ActionItemSchema = withFormatter(
1600
1975
  }
1601
1976
  );
1602
1977
 
1603
- // src/functions/listActions/schemas.ts
1978
+ // src/plugins/listActions/schemas.ts
1604
1979
  var ListActionsSchema = withOutputSchema(
1605
1980
  zod.z.object({
1606
- appKey: AppKeyPropertySchema.optional(),
1607
- type: ActionTypePropertySchema.optional().describe(
1981
+ appKey: AppKeyPropertySchema.describe(
1982
+ "App key of actions to list (e.g., 'SlackCLIAPI')"
1983
+ ),
1984
+ actionType: ActionTypePropertySchema.optional().describe(
1608
1985
  "Filter actions by type"
1609
- )
1986
+ ),
1987
+ pageSize: zod.z.number().min(1).optional().describe("Number of actions per page"),
1988
+ maxItems: zod.z.number().min(1).optional().describe("Maximum total items to return across all pages")
1610
1989
  }).describe("List all actions for a specific app"),
1611
1990
  ActionItemSchema
1612
1991
  );
1613
1992
 
1614
- // src/functions/listActions/info.ts
1615
- var listActionsInfo = {
1616
- name: listActions.name,
1617
- inputSchema: ListActionsSchema,
1618
- implementation: listActions
1993
+ // src/plugins/listActions/index.ts
1994
+ var listActionsPlugin = ({ sdk, context }) => {
1995
+ const listActions = createPaginatedFunction(async function listActionsPage(options) {
1996
+ const { api } = context;
1997
+ const app = await sdk.getApp({ appKey: options.appKey });
1998
+ const implementationId = app.data.current_implementation_id?.split("@")[0];
1999
+ if (!implementationId) {
2000
+ throw new ZapierConfigurationError(
2001
+ "No current_implementation_id found for app",
2002
+ { configType: "current_implementation_id" }
2003
+ );
2004
+ }
2005
+ const searchParams = {
2006
+ global: "true",
2007
+ public_only: "true",
2008
+ selected_apis: implementationId
2009
+ };
2010
+ const data = await api.get("/api/v4/implementations/", {
2011
+ searchParams,
2012
+ customErrorHandler: ({ status }) => {
2013
+ if (status === 401) {
2014
+ return new ZapierAuthenticationError(
2015
+ `Authentication failed. Your token may not have permission to access implementations or may be expired. (HTTP ${status})`,
2016
+ { statusCode: status }
2017
+ );
2018
+ }
2019
+ if (status === 403) {
2020
+ return new ZapierAuthenticationError(
2021
+ `Access forbidden. Your token may not have the required scopes to list implementations. (HTTP ${status})`,
2022
+ { statusCode: status }
2023
+ );
2024
+ }
2025
+ return void 0;
2026
+ }
2027
+ });
2028
+ let allActions = [];
2029
+ for (const implementation of data.results || []) {
2030
+ if (implementation.actions) {
2031
+ for (const action of implementation.actions) {
2032
+ const actionWithContext = {
2033
+ ...action,
2034
+ selected_api: action.selected_api || implementation.selected_api
2035
+ };
2036
+ allActions.push(normalizeActionItem(actionWithContext));
2037
+ }
2038
+ }
2039
+ }
2040
+ if (options.actionType) {
2041
+ allActions = allActions.filter(
2042
+ (action) => action.action_type === options.actionType
2043
+ );
2044
+ }
2045
+ return {
2046
+ data: allActions,
2047
+ nextCursor: void 0
2048
+ };
2049
+ }, ListActionsSchema);
2050
+ return {
2051
+ listActions,
2052
+ context: {
2053
+ meta: {
2054
+ listActions: {
2055
+ inputSchema: ListActionsSchema
2056
+ }
2057
+ }
2058
+ }
2059
+ };
1619
2060
  };
1620
2061
  var GetActionSchema = zod.z.object({
1621
2062
  appKey: AppKeyPropertySchema,
@@ -1623,300 +2064,589 @@ var GetActionSchema = zod.z.object({
1623
2064
  actionKey: ActionKeyPropertySchema
1624
2065
  }).describe("Get detailed information about a specific action");
1625
2066
 
1626
- // src/functions/getAction/info.ts
1627
- var getActionInfo = {
1628
- name: getAction.name,
1629
- inputSchema: GetActionSchema,
1630
- implementation: getAction
2067
+ // src/plugins/getAction/index.ts
2068
+ var getActionPlugin = ({ sdk }) => {
2069
+ const getAction = createFunction(async function getAction2(options) {
2070
+ const { actionKey, actionType, appKey } = options;
2071
+ const actionsResult = await sdk.listActions({ appKey });
2072
+ for (const action of actionsResult.data) {
2073
+ if (action.key === actionKey && action.action_type === actionType) {
2074
+ return { data: action };
2075
+ }
2076
+ }
2077
+ throw new ZapierResourceNotFoundError(
2078
+ `Action not found: ${actionKey} with type ${actionType}`,
2079
+ { resourceType: "Action", resourceId: `${actionKey} (${actionType})` }
2080
+ );
2081
+ }, GetActionSchema);
2082
+ return {
2083
+ getAction,
2084
+ context: {
2085
+ meta: {
2086
+ getAction: {
2087
+ inputSchema: GetActionSchema
2088
+ }
2089
+ }
2090
+ }
2091
+ };
1631
2092
  };
1632
2093
  var RunActionSchema = zod.z.object({
1633
2094
  appKey: AppKeyPropertySchema,
1634
2095
  actionType: ActionTypePropertySchema,
1635
2096
  actionKey: ActionKeyPropertySchema,
2097
+ authenticationId: AuthenticationIdPropertySchema.nullable().optional(),
1636
2098
  inputs: InputsPropertySchema.optional().describe(
1637
2099
  "Input parameters for the action"
1638
2100
  ),
1639
- authenticationId: AuthenticationIdPropertySchema.optional()
2101
+ pageSize: zod.z.number().min(1).optional().describe("Number of results per page"),
2102
+ maxItems: zod.z.number().min(1).optional().describe("Maximum total items to return across all pages")
1640
2103
  }).describe("Execute an action with the given inputs");
1641
2104
 
1642
- // src/functions/runAction/info.ts
1643
- var runActionInfo = {
1644
- name: runAction.name,
1645
- inputSchema: RunActionSchema,
1646
- implementation: runAction
2105
+ // src/plugins/runAction/index.ts
2106
+ async function executeAction(actionOptions) {
2107
+ const {
2108
+ api,
2109
+ sdk,
2110
+ appKey,
2111
+ actionKey,
2112
+ actionType,
2113
+ executionOptions,
2114
+ authenticationId
2115
+ } = actionOptions;
2116
+ const appData = await sdk.getApp({ appKey });
2117
+ const selectedApi = appData.data.current_implementation_id;
2118
+ if (!selectedApi) {
2119
+ throw new ZapierConfigurationError(
2120
+ "No current_implementation_id found for app",
2121
+ { configType: "current_implementation_id" }
2122
+ );
2123
+ }
2124
+ const runRequestData = {
2125
+ selected_api: selectedApi,
2126
+ action_key: actionKey,
2127
+ action_type: actionType,
2128
+ inputs: executionOptions.inputs || {}
2129
+ };
2130
+ if (authenticationId !== null && authenticationId !== void 0) {
2131
+ runRequestData.authentication_id = authenticationId;
2132
+ }
2133
+ const runRequest = {
2134
+ data: runRequestData
2135
+ };
2136
+ const runData = await api.post("/api/actions/v1/runs", runRequest);
2137
+ const runId = runData.data.id;
2138
+ return await api.poll(`/api/actions/v1/runs/${runId}`, {
2139
+ successStatus: 200,
2140
+ pendingStatus: 202,
2141
+ resultExtractor: (result) => result.data
2142
+ });
2143
+ }
2144
+ var runActionPlugin = ({ sdk, context }) => {
2145
+ const runAction = createPaginatedFunction(async function runActionPage(options) {
2146
+ const { api } = context;
2147
+ const {
2148
+ appKey,
2149
+ actionKey,
2150
+ actionType,
2151
+ authenticationId,
2152
+ inputs = {}
2153
+ } = options;
2154
+ const actionData = await sdk.getAction({
2155
+ appKey,
2156
+ actionKey,
2157
+ actionType
2158
+ });
2159
+ if (actionData.data.action_type !== actionType) {
2160
+ throw new ZapierValidationError(
2161
+ `Action type mismatch: expected ${actionType}, got ${actionData.data.action_type}`
2162
+ );
2163
+ }
2164
+ const result = await executeAction({
2165
+ api,
2166
+ sdk,
2167
+ appKey,
2168
+ actionKey,
2169
+ actionType,
2170
+ executionOptions: { inputs },
2171
+ authenticationId});
2172
+ if (result.errors && result.errors.length > 0) {
2173
+ const errorMessage = result.errors.map(
2174
+ (error) => error.detail || error.title || "Unknown error"
2175
+ ).join("; ");
2176
+ throw new ZapierActionError(`Action execution failed: ${errorMessage}`, {
2177
+ appKey,
2178
+ actionKey
2179
+ });
2180
+ }
2181
+ return {
2182
+ data: result.results || [],
2183
+ nextCursor: void 0
2184
+ // No pagination implemented yet
2185
+ };
2186
+ }, RunActionSchema);
2187
+ return {
2188
+ runAction,
2189
+ context: {
2190
+ meta: {
2191
+ runAction: {
2192
+ inputSchema: RunActionSchema
2193
+ }
2194
+ }
2195
+ }
2196
+ };
1647
2197
  };
1648
- var AuthItemSchema = withFormatter(
1649
- zod.z.object({
1650
- id: zod.z.number(),
1651
- title: zod.z.string().optional(),
1652
- identifier: zod.z.string().optional(),
1653
- account_id: zod.z.string().optional(),
1654
- is_private: zod.z.boolean().optional(),
1655
- shared_with_all: zod.z.boolean().optional(),
1656
- marked_stale_at: zod.z.string().optional()
1657
- }),
1658
- {
1659
- format: (item) => {
1660
- const details = [];
1661
- if (item.identifier) {
1662
- details.push({
1663
- text: `Identifier: ${item.identifier}`,
1664
- style: "accent"
2198
+ var ListAuthenticationsSchema = zod.z.object({
2199
+ appKey: AppKeyPropertySchema.optional().describe(
2200
+ "App key of authentications to list (e.g., 'SlackCLIAPI')"
2201
+ ),
2202
+ search: zod.z.string().optional().describe("Search term to filter authentications by title"),
2203
+ title: zod.z.string().optional().describe("Filter authentications by exact title match"),
2204
+ account_id: zod.z.string().optional().describe("Filter by account ID"),
2205
+ owner: zod.z.string().optional().describe("Filter by owner"),
2206
+ pageSize: zod.z.number().min(1).optional().describe("Number of authentications per page"),
2207
+ maxItems: zod.z.number().min(1).optional().describe("Maximum total items to return across all pages")
2208
+ }).describe("List available authentications with optional filtering");
2209
+
2210
+ // src/plugins/listAuthentications/index.ts
2211
+ var listAuthenticationsPlugin = ({ sdk, context }) => {
2212
+ const listAuthentications = createPaginatedFunction(
2213
+ async function listAuthenticationsPage(options) {
2214
+ const { api } = context;
2215
+ const searchParams = {};
2216
+ if (options.appKey) {
2217
+ const app = await sdk.getApp({
2218
+ appKey: options.appKey
1665
2219
  });
2220
+ const selectedApi = app.data.current_implementation_id;
2221
+ if (selectedApi) {
2222
+ const versionlessApi = selectedApi.split("@")[0];
2223
+ searchParams.versionless_selected_api = versionlessApi;
2224
+ }
1666
2225
  }
1667
- details.push({
1668
- text: `Account: ${item.account_id || "unknown"} | Private: ${item.is_private || false} | Shared: ${item.shared_with_all || false}`,
1669
- style: "dim"
1670
- });
1671
- if (item.marked_stale_at) {
1672
- details.push({
1673
- text: `\u26A0\uFE0F Marked stale: ${new Date(item.marked_stale_at).toLocaleDateString()}`,
1674
- style: "warning"
1675
- });
2226
+ if (options.search) {
2227
+ searchParams.search = options.search;
2228
+ } else if (options.title) {
2229
+ searchParams.search = options.title;
2230
+ }
2231
+ if (options.account_id) {
2232
+ searchParams.account_id = options.account_id;
2233
+ }
2234
+ if (options.owner) {
2235
+ searchParams.owner = options.owner;
2236
+ }
2237
+ searchParams.limit = options.pageSize.toString();
2238
+ if (options.cursor) {
2239
+ searchParams.offset = options.cursor;
2240
+ }
2241
+ const data = await api.get(
2242
+ "/api/v4/authentications/",
2243
+ {
2244
+ searchParams,
2245
+ customErrorHandler: ({ status }) => {
2246
+ if (status === 401) {
2247
+ return new ZapierAuthenticationError(
2248
+ `Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP ${status})`,
2249
+ { statusCode: status }
2250
+ );
2251
+ }
2252
+ if (status === 403) {
2253
+ return new ZapierAuthenticationError(
2254
+ `Access forbidden. Your token may not have the required scopes to list authentications. (HTTP ${status})`,
2255
+ { statusCode: status }
2256
+ );
2257
+ }
2258
+ return void 0;
2259
+ },
2260
+ authRequired: true
2261
+ }
2262
+ );
2263
+ let auths = (data.results || []).map(
2264
+ (auth) => normalizeAuthenticationItem(auth)
2265
+ );
2266
+ if (options.title) {
2267
+ auths = auths.filter((auth) => auth.title === options.title);
1676
2268
  }
1677
2269
  return {
1678
- title: item.title || `Authentication ${item.id}`,
1679
- subtitle: `(ID: ${item.id})`,
1680
- details
2270
+ data: auths,
2271
+ nextCursor: extractCursor(data)
1681
2272
  };
2273
+ },
2274
+ ListAuthenticationsSchema
2275
+ );
2276
+ return {
2277
+ listAuthentications,
2278
+ context: {
2279
+ meta: {
2280
+ listAuthentications: {
2281
+ inputSchema: ListAuthenticationsSchema
2282
+ }
2283
+ }
1682
2284
  }
1683
- }
1684
- );
1685
-
1686
- // src/functions/listAuthentications/schemas.ts
1687
- var ListAuthenticationsSchema = withOutputSchema(
1688
- zod.z.object({
1689
- appKey: AppKeyPropertySchema.optional().describe(
1690
- "App slug to get authentications for (e.g., 'slack', 'github')"
1691
- ),
1692
- search: zod.z.string().optional().describe("Search term to filter authentications by title"),
1693
- title: zod.z.string().optional().describe("Filter authentications by exact title match"),
1694
- account_id: zod.z.string().optional().describe("Filter by account ID"),
1695
- owner: zod.z.string().optional().describe("Filter by owner"),
1696
- limit: LimitPropertySchema.optional().describe(
1697
- "Maximum number of items to return (1-200)"
1698
- ),
1699
- offset: OffsetPropertySchema.optional().describe(
1700
- "Number of items to skip for pagination"
1701
- )
1702
- }).describe("List available authentications with optional filtering"),
1703
- AuthItemSchema
1704
- );
1705
-
1706
- // src/functions/listAuthentications/info.ts
1707
- var listAuthenticationsInfo = {
1708
- name: listAuthentications.name,
1709
- inputSchema: ListAuthenticationsSchema,
1710
- implementation: listAuthentications
2285
+ };
1711
2286
  };
1712
- var GetAuthenticationSchema = withOutputSchema(
1713
- zod.z.object({
1714
- authenticationId: zod.z.number().int().positive().describe("Authentication ID to retrieve")
1715
- }).describe("Get a specific authentication by ID"),
1716
- AuthItemSchema
1717
- );
2287
+ var GetAuthenticationSchema = zod.z.object({
2288
+ authenticationId: zod.z.number().int().positive().describe("Authentication ID to retrieve")
2289
+ }).describe("Get a specific authentication by ID");
1718
2290
 
1719
- // src/functions/getAuthentication/info.ts
1720
- var getAuthenticationInfo = {
1721
- name: getAuthentication.name,
1722
- inputSchema: GetAuthenticationSchema,
1723
- implementation: getAuthentication
1724
- };
1725
- var FindFirstAuthenticationSchema = withOutputSchema(
1726
- zod.z.object({
1727
- appKey: AppKeyPropertySchema.optional().describe(
1728
- "App slug to get authentications for (e.g., 'slack', 'github')"
1729
- ),
1730
- search: zod.z.string().optional().describe("Search term to filter authentications by title"),
1731
- title: zod.z.string().optional().describe("Filter authentications by exact title match"),
1732
- account_id: zod.z.string().optional().describe("Filter by account ID"),
1733
- owner: zod.z.string().optional().describe("Filter by owner"),
1734
- limit: LimitPropertySchema.optional().describe(
1735
- "Maximum number of items to return (1-200)"
1736
- ),
1737
- offset: OffsetPropertySchema.optional().describe(
1738
- "Number of items to skip for pagination"
1739
- )
1740
- }).describe("Find the first authentication matching the criteria"),
1741
- AuthItemSchema
1742
- );
1743
-
1744
- // src/functions/findFirstAuthentication/info.ts
1745
- var findFirstAuthenticationInfo = {
1746
- name: findFirstAuthentication.name,
1747
- inputSchema: FindFirstAuthenticationSchema,
1748
- implementation: findFirstAuthentication
2291
+ // src/plugins/getAuthentication/index.ts
2292
+ var getAuthenticationPlugin = ({ context }) => {
2293
+ const getAuthentication = createFunction(async function getAuthentication2(options) {
2294
+ const { api } = context;
2295
+ const { authenticationId } = options;
2296
+ const data = await api.get(
2297
+ `/api/v4/authentications/${authenticationId}/`,
2298
+ {
2299
+ customErrorHandler: ({ status }) => {
2300
+ if (status === 401) {
2301
+ return new ZapierAuthenticationError(
2302
+ `Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP ${status})`,
2303
+ { statusCode: status }
2304
+ );
2305
+ }
2306
+ if (status === 403) {
2307
+ return new ZapierAuthenticationError(
2308
+ `Access forbidden. Your token may not have the required scopes to get authentication ${authenticationId}. (HTTP ${status})`,
2309
+ { statusCode: status }
2310
+ );
2311
+ }
2312
+ if (status === 404) {
2313
+ return new ZapierResourceNotFoundError(
2314
+ `Authentication ${authenticationId} not found. It may not exist or you may not have access to it. (HTTP ${status})`,
2315
+ {
2316
+ resourceType: "Authentication",
2317
+ resourceId: String(authenticationId)
2318
+ }
2319
+ );
2320
+ }
2321
+ return void 0;
2322
+ },
2323
+ authRequired: true
2324
+ }
2325
+ );
2326
+ return {
2327
+ data: normalizeAuthenticationItem(data)
2328
+ };
2329
+ }, GetAuthenticationSchema);
2330
+ return {
2331
+ getAuthentication,
2332
+ context: {
2333
+ meta: {
2334
+ getAuthentication: {
2335
+ inputSchema: GetAuthenticationSchema
2336
+ }
2337
+ }
2338
+ }
2339
+ };
1749
2340
  };
1750
- var FindUniqueAuthenticationSchema = withOutputSchema(
1751
- zod.z.object({
1752
- appKey: AppKeyPropertySchema.optional().describe(
1753
- "App slug to get authentications for (e.g., 'slack', 'github')"
1754
- ),
1755
- search: zod.z.string().optional().describe("Search term to filter authentications by title"),
1756
- title: zod.z.string().optional().describe("Filter authentications by exact title match"),
1757
- account_id: zod.z.string().optional().describe("Filter by account ID"),
1758
- owner: zod.z.string().optional().describe("Filter by owner"),
1759
- limit: LimitPropertySchema.optional().describe(
1760
- "Maximum number of items to return (1-200)"
1761
- ),
1762
- offset: OffsetPropertySchema.optional().describe(
1763
- "Number of items to skip for pagination"
1764
- )
1765
- }).describe("Find a unique authentication matching the criteria"),
1766
- AuthItemSchema
1767
- );
2341
+ var FindFirstAuthenticationSchema = zod.z.object({
2342
+ appKey: AppKeyPropertySchema.optional().describe(
2343
+ "App key of authentication to find (e.g., 'SlackCLIAPI')"
2344
+ ),
2345
+ search: zod.z.string().optional().describe("Search term to filter authentications by title"),
2346
+ title: zod.z.string().optional().describe("Filter authentications by exact title match"),
2347
+ account_id: zod.z.string().optional().describe("Filter by account ID"),
2348
+ owner: zod.z.string().optional().describe("Filter by owner")
2349
+ }).describe("Find the first authentication matching the criteria");
1768
2350
 
1769
- // src/functions/findUniqueAuthentication/info.ts
1770
- var findUniqueAuthenticationInfo = {
1771
- name: findUniqueAuthentication.name,
1772
- inputSchema: FindUniqueAuthenticationSchema,
1773
- implementation: findUniqueAuthentication
1774
- };
1775
- var FieldItemSchema = withFormatter(
1776
- zod.z.object({
1777
- key: zod.z.string(),
1778
- name: zod.z.string().optional(),
1779
- description: zod.z.string().optional()
1780
- }),
1781
- {
1782
- format: (item) => {
1783
- const details = [];
1784
- if (item.description) {
1785
- details.push({ text: item.description, style: "dim" });
1786
- }
2351
+ // src/plugins/findFirstAuthentication/index.ts
2352
+ var findFirstAuthenticationPlugin = ({ sdk }) => {
2353
+ const findFirstAuthentication = createFunction(
2354
+ async function findFirstAuthentication2(options = {}) {
2355
+ const authsResponse = await sdk.listAuthentications({
2356
+ ...options,
2357
+ maxItems: 1
2358
+ });
1787
2359
  return {
1788
- title: item.name || item.key,
1789
- subtitle: `(${item.key})`,
1790
- details
2360
+ data: authsResponse.data.length > 0 ? authsResponse.data[0] : null
1791
2361
  };
2362
+ },
2363
+ FindFirstAuthenticationSchema
2364
+ );
2365
+ return {
2366
+ findFirstAuthentication,
2367
+ context: {
2368
+ meta: {
2369
+ findFirstAuthentication: {
2370
+ inputSchema: FindFirstAuthenticationSchema
2371
+ }
2372
+ }
1792
2373
  }
1793
- }
1794
- );
1795
-
1796
- // src/functions/listFields/schemas.ts
1797
- var ListFieldsSchema = withOutputSchema(
1798
- zod.z.object({
1799
- appKey: AppKeyPropertySchema,
1800
- actionType: ActionTypePropertySchema,
1801
- actionKey: ActionKeyPropertySchema,
1802
- authenticationId: AuthenticationIdPropertySchema.optional(),
1803
- params: ParamsPropertySchema.optional().describe(
1804
- "Additional parameters that may affect available fields"
1805
- )
1806
- }).describe("Get the input fields required for a specific action"),
1807
- FieldItemSchema
1808
- );
1809
-
1810
- // src/functions/listFields/info.ts
1811
- var listFieldsInfo = {
1812
- name: listFields.name,
1813
- inputSchema: ListFieldsSchema,
1814
- implementation: listFields
2374
+ };
1815
2375
  };
1816
- var GenerateTypesSchema = zod.z.object({
1817
- appKey: AppKeyPropertySchema.describe("App key to generate SDK code for"),
1818
- authenticationId: AuthenticationIdPropertySchema.optional(),
1819
- output: OutputPropertySchema.optional().describe(
1820
- "Output file path (defaults to generated/<appKey>.ts)"
2376
+ var FindUniqueAuthenticationSchema = zod.z.object({
2377
+ appKey: AppKeyPropertySchema.optional().describe(
2378
+ "App key of authentication to find (e.g., 'SlackCLIAPI')"
1821
2379
  ),
1822
- debug: DebugPropertySchema.describe(
1823
- "Enable debug logging during generation"
1824
- )
1825
- }).describe("Generate TypeScript SDK code for a specific app");
2380
+ search: zod.z.string().optional().describe("Search term to filter authentications by title"),
2381
+ title: zod.z.string().optional().describe("Filter authentications by exact title match"),
2382
+ account_id: zod.z.string().optional().describe("Filter by account ID"),
2383
+ owner: zod.z.string().optional().describe("Filter by owner")
2384
+ }).describe("Find a unique authentication matching the criteria");
1826
2385
 
1827
- // src/functions/generateTypes/info.ts
1828
- var generateTypesInfo = {
1829
- name: generateTypes.name,
1830
- inputSchema: GenerateTypesSchema,
1831
- implementation: generateTypes
2386
+ // src/plugins/findUniqueAuthentication/index.ts
2387
+ var findUniqueAuthenticationPlugin = ({ sdk }) => {
2388
+ const findUniqueAuthentication = createFunction(
2389
+ async function findUniqueAuthentication2(options = {}) {
2390
+ const authsResponse = await sdk.listAuthentications({
2391
+ ...options,
2392
+ maxItems: 2
2393
+ // Get up to 2 to check for uniqueness
2394
+ });
2395
+ if (authsResponse.data.length === 0) {
2396
+ throw new ZapierResourceNotFoundError(
2397
+ "No authentication found matching the specified criteria",
2398
+ { resourceType: "Authentication" }
2399
+ );
2400
+ }
2401
+ if (authsResponse.data.length > 1) {
2402
+ throw new ZapierValidationError(
2403
+ "Multiple authentications found matching the specified criteria. Expected exactly one."
2404
+ );
2405
+ }
2406
+ return {
2407
+ data: authsResponse.data[0]
2408
+ };
2409
+ },
2410
+ FindUniqueAuthenticationSchema
2411
+ );
2412
+ return {
2413
+ findUniqueAuthentication,
2414
+ context: {
2415
+ meta: {
2416
+ findUniqueAuthentication: {
2417
+ inputSchema: FindUniqueAuthenticationSchema
2418
+ }
2419
+ }
2420
+ }
2421
+ };
1832
2422
  };
1833
- var BundleCodeSchema = zod.z.object({
1834
- input: zod.z.string().min(1).describe("Input TypeScript file path to bundle"),
1835
- output: OutputPropertySchema.optional().describe(
1836
- "Output file path (defaults to input with .js extension)"
2423
+ var ListInputFieldsSchema = zod.z.object({
2424
+ appKey: AppKeyPropertySchema,
2425
+ actionType: ActionTypePropertySchema,
2426
+ actionKey: ActionKeyPropertySchema,
2427
+ authenticationId: AuthenticationIdPropertySchema.nullable().optional(),
2428
+ inputs: InputsPropertySchema.optional().describe(
2429
+ "Current input values that may affect available fields"
1837
2430
  ),
1838
- string: zod.z.boolean().default(false).describe("Return bundled code as string instead of writing to file"),
1839
- minify: zod.z.boolean().default(false).describe("Minify the bundled output"),
1840
- target: zod.z.string().default("es2017").describe("ECMAScript target version"),
1841
- cjs: zod.z.boolean().default(false).describe("Output CommonJS format instead of ESM")
1842
- }).describe("Bundle TypeScript code into executable JavaScript");
2431
+ pageSize: zod.z.number().min(1).optional().describe("Number of input fields per page"),
2432
+ maxItems: zod.z.number().min(1).optional().describe("Maximum total items to return across all pages")
2433
+ }).describe("Get the input fields required for a specific action");
1843
2434
 
1844
- // src/functions/bundleCode/info.ts
1845
- var bundleCodeInfo = {
1846
- name: bundleCode.name,
1847
- inputSchema: BundleCodeSchema,
1848
- implementation: bundleCode
2435
+ // src/plugins/listInputFields/index.ts
2436
+ function getInputFieldTypeFromNeed(need) {
2437
+ if (need.list) {
2438
+ return "ARRAY" /* ARRAY */;
2439
+ }
2440
+ const typeMap = {
2441
+ string: "STRING" /* STRING */,
2442
+ decimal: "NUMBER" /* NUMBER */,
2443
+ integer: "INTEGER" /* INTEGER */,
2444
+ boolean: "BOOLEAN" /* BOOLEAN */,
2445
+ dict: "OBJECT" /* OBJECT */
2446
+ };
2447
+ return typeMap[need.type || ""] || "STRING" /* STRING */;
2448
+ }
2449
+ function getInputFieldFormatFromNeed(need) {
2450
+ if (need.prefill || need.choices) {
2451
+ return "SELECT" /* SELECT */;
2452
+ }
2453
+ const formatMap = {
2454
+ text: "MULTILINE" /* MULTILINE */,
2455
+ datetime: "DATETIME" /* DATETIME */,
2456
+ file: "FILE" /* FILE */,
2457
+ password: "PASSWORD" /* PASSWORD */,
2458
+ code: "CODE" /* CODE */
2459
+ };
2460
+ return formatMap[need.type || ""];
2461
+ }
2462
+ function getItemsTypeFromNeed(need) {
2463
+ if (!need.list) {
2464
+ return void 0;
2465
+ }
2466
+ const typeMap = {
2467
+ string: "STRING" /* STRING */,
2468
+ decimal: "NUMBER" /* NUMBER */,
2469
+ integer: "INTEGER" /* INTEGER */,
2470
+ boolean: "BOOLEAN" /* BOOLEAN */,
2471
+ dict: "OBJECT" /* OBJECT */
2472
+ };
2473
+ return typeMap[need.type || ""] || "STRING" /* STRING */;
2474
+ }
2475
+ function transformNeedToInputFieldItem(need) {
2476
+ const itemsType = getItemsTypeFromNeed(need);
2477
+ return {
2478
+ ...need,
2479
+ // Pass through all original Need fields
2480
+ id: need.key,
2481
+ default_value: need.default || "",
2482
+ depends_on: need.depends_on || [],
2483
+ description: need.help_text || "",
2484
+ invalidates_input_fields: need.alters_custom_fields || false,
2485
+ is_required: need.required || false,
2486
+ placeholder: need.placeholder || "",
2487
+ title: need.label || "",
2488
+ value_type: getInputFieldTypeFromNeed(need),
2489
+ format: getInputFieldFormatFromNeed(need),
2490
+ items: itemsType ? { type: itemsType } : void 0
2491
+ };
2492
+ }
2493
+ var listInputFieldsPlugin = ({ sdk, context }) => {
2494
+ const listInputFields = createPaginatedFunction(
2495
+ async function listInputFieldsPage(options) {
2496
+ const { api } = context;
2497
+ const { appKey, actionKey, actionType, authenticationId, inputs } = options;
2498
+ const appData = await sdk.getApp({ appKey });
2499
+ const selectedApi = appData.data.current_implementation_id;
2500
+ if (!selectedApi) {
2501
+ throw new ZapierConfigurationError(
2502
+ "No current_implementation_id found for app",
2503
+ { configType: "current_implementation_id" }
2504
+ );
2505
+ }
2506
+ const needsRequest = {
2507
+ selected_api: selectedApi,
2508
+ action: actionKey,
2509
+ type_of: actionType,
2510
+ params: inputs || {}
2511
+ };
2512
+ if (authenticationId !== null) {
2513
+ needsRequest.authentication_id = authenticationId;
2514
+ }
2515
+ const needsData = await api.post(
2516
+ "/api/v4/implementations/needs/",
2517
+ needsRequest
2518
+ );
2519
+ if (!needsData.success) {
2520
+ throw new ZapierApiError(
2521
+ `Failed to get action fields: ${needsData.errors?.join(", ") || "Unknown error"}`
2522
+ );
2523
+ }
2524
+ const inputFields = (needsData.needs || []).map(
2525
+ transformNeedToInputFieldItem
2526
+ );
2527
+ return {
2528
+ data: inputFields,
2529
+ nextCursor: void 0
2530
+ // No pagination needed since we return all input fields
2531
+ };
2532
+ },
2533
+ ListInputFieldsSchema
2534
+ );
2535
+ return {
2536
+ listInputFields,
2537
+ context: {
2538
+ meta: {
2539
+ listInputFields: {
2540
+ inputSchema: ListInputFieldsSchema
2541
+ }
2542
+ }
2543
+ }
2544
+ };
1849
2545
  };
1850
2546
 
1851
- // src/functions/request/info.ts
1852
- var requestInfo = {
1853
- name: "request",
1854
- inputSchema: RelayRequestSchema,
1855
- implementation: request
2547
+ // src/plugins/request/index.ts
2548
+ function transformUrlToRelayPath(url) {
2549
+ const targetUrl = new URL(url);
2550
+ const relayPath = `/relay/${targetUrl.host}${targetUrl.pathname}${targetUrl.search}${targetUrl.hash}`;
2551
+ return relayPath;
2552
+ }
2553
+ var requestPlugin = ({ context }) => {
2554
+ const request = createFunction(async function request2(options) {
2555
+ const { api } = context;
2556
+ const {
2557
+ url,
2558
+ method = "GET",
2559
+ body,
2560
+ headers: optionsHeaders,
2561
+ authenticationId,
2562
+ callbackUrl,
2563
+ authenticationTemplate
2564
+ } = options;
2565
+ const relayPath = transformUrlToRelayPath(url);
2566
+ const headers = {};
2567
+ if (optionsHeaders) {
2568
+ const headerEntries = optionsHeaders instanceof Headers ? Array.from(optionsHeaders.entries()) : Array.isArray(optionsHeaders) ? optionsHeaders : Object.entries(optionsHeaders);
2569
+ for (const [key, value] of headerEntries) {
2570
+ headers[key] = value;
2571
+ }
2572
+ }
2573
+ if (authenticationId) {
2574
+ headers["X-Relay-Authentication-Id"] = authenticationId.toString();
2575
+ }
2576
+ if (callbackUrl) {
2577
+ headers["X-Relay-Callback-Url"] = callbackUrl;
2578
+ }
2579
+ if (authenticationTemplate) {
2580
+ headers["X-Authentication-Template"] = authenticationTemplate;
2581
+ }
2582
+ return await api.fetch(relayPath, {
2583
+ method,
2584
+ body,
2585
+ headers
2586
+ });
2587
+ }, RelayRequestSchema);
2588
+ return {
2589
+ request,
2590
+ context: {
2591
+ meta: {
2592
+ request: {
2593
+ inputSchema: RelayRequestSchema
2594
+ }
2595
+ }
2596
+ }
2597
+ };
1856
2598
  };
1857
2599
 
1858
2600
  // src/sdk.ts
1859
- var functionRegistry = [
1860
- listAppsInfo,
1861
- getAppInfo,
1862
- listActionsInfo,
1863
- getActionInfo,
1864
- runActionInfo,
1865
- listAuthenticationsInfo,
1866
- getAuthenticationInfo,
1867
- findFirstAuthenticationInfo,
1868
- findUniqueAuthenticationInfo,
1869
- listFieldsInfo,
1870
- generateTypesInfo,
1871
- bundleCodeInfo,
1872
- requestInfo
1873
- ];
1874
- function createZapierSdk(options = {}) {
1875
- const {
1876
- fetch: customFetch = globalThis.fetch,
1877
- baseUrl = "https://zapier.com",
1878
- token,
1879
- getToken,
1880
- onEvent,
1881
- debug = false
1882
- } = options;
1883
- const api = createZapierApi({
1884
- baseUrl,
1885
- token,
1886
- getToken,
1887
- debug,
1888
- fetch: customFetch,
1889
- onEvent
1890
- });
1891
- const baseSdk = {
1892
- // Registry for CLI
1893
- __registry: functionRegistry,
1894
- // Function implementations with API config injection
1895
- listApps: (options2 = {}) => listApps({ ...options2, api }),
1896
- getApp: (options2) => getApp({ ...options2, api }),
1897
- listActions: (options2 = {}) => listActions({ ...options2, api }),
1898
- getAction: (options2) => getAction({ ...options2, api }),
1899
- runAction: (options2) => runAction({ ...options2, api }),
1900
- listAuthentications: (options2 = {}) => listAuthentications({ ...options2, api }),
1901
- getAuthentication: (options2) => getAuthentication({ ...options2, api }),
1902
- findFirstAuthentication: (options2 = {}) => findFirstAuthentication({ ...options2, api }),
1903
- findUniqueAuthentication: (options2 = {}) => findUniqueAuthentication({ ...options2, api }),
1904
- listFields: (options2) => listFields({ ...options2, api }),
1905
- generateTypes: (options2) => generateTypes({ ...options2, api }),
1906
- bundleCode: (options2) => bundleCode(options2),
1907
- // No API config needed
1908
- request: (options2) => request({ ...options2, api })
2601
+ function createSdk(initialSdk = {}, initialContext = { meta: {} }) {
2602
+ return {
2603
+ ...initialSdk,
2604
+ getContext: () => initialContext,
2605
+ addPlugin(plugin, options = {}) {
2606
+ const currentSdkWithContext = {
2607
+ ...initialSdk,
2608
+ getContext: () => initialContext
2609
+ };
2610
+ const pluginResult = plugin({
2611
+ sdk: currentSdkWithContext,
2612
+ context: initialContext,
2613
+ ...options
2614
+ });
2615
+ const { context: pluginContext, ...sdkProperties } = pluginResult;
2616
+ const newSdk = { ...initialSdk, ...sdkProperties };
2617
+ let newContext = {
2618
+ ...initialContext,
2619
+ meta: initialContext.meta || {}
2620
+ };
2621
+ if (pluginContext) {
2622
+ const { meta: pluginMeta, ...otherPluginContext } = pluginContext;
2623
+ newContext = {
2624
+ ...newContext,
2625
+ ...otherPluginContext
2626
+ };
2627
+ if (pluginMeta) {
2628
+ newContext = {
2629
+ ...newContext,
2630
+ meta: {
2631
+ ...newContext.meta,
2632
+ // Existing meta (now guaranteed to exist)
2633
+ ...pluginMeta
2634
+ // New meta from plugin
2635
+ }
2636
+ };
2637
+ }
2638
+ }
2639
+ return createSdk(newSdk, newContext);
2640
+ }
1909
2641
  };
1910
- const fullSdk = baseSdk;
1911
- fullSdk.apps = createAppsPlugin({ sdk: fullSdk });
1912
- fullSdk.fetch = createFetchPlugin({ sdk: fullSdk });
1913
- return fullSdk;
2642
+ }
2643
+ function createZapierSdk(options = {}) {
2644
+ return createSdk().addPlugin(apiPlugin, options).addPlugin(listAppsPlugin).addPlugin(getAppPlugin).addPlugin(listActionsPlugin).addPlugin(getActionPlugin).addPlugin(listInputFieldsPlugin).addPlugin(runActionPlugin).addPlugin(listAuthenticationsPlugin).addPlugin(getAuthenticationPlugin).addPlugin(findFirstAuthenticationPlugin).addPlugin(findUniqueAuthenticationPlugin).addPlugin(requestPlugin).addPlugin(fetchPlugin).addPlugin(appsPlugin).addPlugin(getProfilePlugin).addPlugin(registryPlugin);
1914
2645
  }
1915
2646
 
1916
2647
  exports.ActionKeyPropertySchema = ActionKeyPropertySchema;
1917
2648
  exports.ActionTypePropertySchema = ActionTypePropertySchema;
1918
2649
  exports.AppKeyPropertySchema = AppKeyPropertySchema;
1919
- exports.AppNotFoundError = AppNotFoundError;
1920
2650
  exports.AuthenticationIdPropertySchema = AuthenticationIdPropertySchema;
1921
2651
  exports.DebugPropertySchema = DebugPropertySchema;
1922
2652
  exports.InputsPropertySchema = InputsPropertySchema;
@@ -1926,21 +2656,27 @@ exports.OutputPropertySchema = OutputPropertySchema;
1926
2656
  exports.ParamsPropertySchema = ParamsPropertySchema;
1927
2657
  exports.RelayFetchSchema = RelayFetchSchema;
1928
2658
  exports.RelayRequestSchema = RelayRequestSchema;
1929
- exports.ZapierSdkError = ZapierSdkError;
2659
+ exports.ZapierActionError = ZapierActionError;
2660
+ exports.ZapierApiError = ZapierApiError;
2661
+ exports.ZapierAppNotFoundError = ZapierAppNotFoundError;
2662
+ exports.ZapierAuthenticationError = ZapierAuthenticationError;
2663
+ exports.ZapierBundleError = ZapierBundleError;
2664
+ exports.ZapierConfigurationError = ZapierConfigurationError;
2665
+ exports.ZapierError = ZapierError;
2666
+ exports.ZapierNotFoundError = ZapierNotFoundError;
2667
+ exports.ZapierResourceNotFoundError = ZapierResourceNotFoundError;
2668
+ exports.ZapierTimeoutError = ZapierTimeoutError;
2669
+ exports.ZapierUnknownError = ZapierUnknownError;
2670
+ exports.ZapierValidationError = ZapierValidationError;
1930
2671
  exports.actionKeyResolver = actionKeyResolver;
1931
2672
  exports.actionTypeResolver = actionTypeResolver;
1932
2673
  exports.appKeyResolver = appKeyResolver;
2674
+ exports.appsPlugin = appsPlugin;
1933
2675
  exports.authenticationIdResolver = authenticationIdResolver;
1934
- exports.bundleCode = bundleCode;
1935
- exports.createAppsPlugin = createAppsPlugin;
1936
- exports.createFetchPlugin = createFetchPlugin;
2676
+ exports.createSdk = createSdk;
1937
2677
  exports.createZapierSdk = createZapierSdk;
1938
- exports.findFirstAuthentication = findFirstAuthentication;
1939
- exports.findUniqueAuthentication = findUniqueAuthentication;
1940
- exports.generateTypes = generateTypes;
1941
- exports.getAction = getAction;
1942
- exports.getApp = getApp;
1943
- exports.getAuthentication = getAuthentication;
2678
+ exports.fetchPlugin = fetchPlugin;
2679
+ exports.formatErrorMessage = formatErrorMessage;
1944
2680
  exports.getResolutionOrder = getResolutionOrder;
1945
2681
  exports.getResolutionOrderForParams = getResolutionOrderForParams;
1946
2682
  exports.getResolvableParams = getResolvableParams;
@@ -1952,11 +2688,4 @@ exports.getTokenFromEnvOrConfig = getTokenFromEnvOrConfig;
1952
2688
  exports.hasResolver = hasResolver;
1953
2689
  exports.inputsResolver = inputsResolver;
1954
2690
  exports.isPositional = isPositional;
1955
- exports.listActions = listActions;
1956
- exports.listApps = listApps;
1957
- exports.listAuthentications = listAuthentications;
1958
- exports.listFields = listFields;
1959
- exports.relayFetch = relayFetch;
1960
- exports.request = request;
1961
2691
  exports.resolverRegistry = resolverRegistry;
1962
- exports.runAction = runAction;