@zapier/zapier-sdk 0.18.3 → 0.19.0

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 (417) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +44 -32
  3. package/dist/index.cjs +658 -693
  4. package/dist/index.d.mts +272 -138
  5. package/dist/index.d.ts +2541 -40
  6. package/dist/index.mjs +638 -692
  7. package/package.json +14 -13
  8. package/dist/api/auth.d.ts +0 -19
  9. package/dist/api/auth.d.ts.map +0 -1
  10. package/dist/api/auth.js +0 -70
  11. package/dist/api/auth.test.d.ts +0 -2
  12. package/dist/api/auth.test.d.ts.map +0 -1
  13. package/dist/api/auth.test.js +0 -220
  14. package/dist/api/client.d.ts +0 -9
  15. package/dist/api/client.d.ts.map +0 -1
  16. package/dist/api/client.integration.test.d.ts +0 -5
  17. package/dist/api/client.integration.test.d.ts.map +0 -1
  18. package/dist/api/client.integration.test.js +0 -318
  19. package/dist/api/client.js +0 -374
  20. package/dist/api/client.methods.test.d.ts +0 -2
  21. package/dist/api/client.methods.test.d.ts.map +0 -1
  22. package/dist/api/client.methods.test.js +0 -158
  23. package/dist/api/client.test.d.ts +0 -2
  24. package/dist/api/client.test.d.ts.map +0 -1
  25. package/dist/api/client.test.js +0 -96
  26. package/dist/api/debug.d.ts +0 -14
  27. package/dist/api/debug.d.ts.map +0 -1
  28. package/dist/api/debug.js +0 -131
  29. package/dist/api/debug.test.d.ts +0 -2
  30. package/dist/api/debug.test.d.ts.map +0 -1
  31. package/dist/api/debug.test.js +0 -59
  32. package/dist/api/index.d.ts +0 -30
  33. package/dist/api/index.d.ts.map +0 -1
  34. package/dist/api/index.js +0 -43
  35. package/dist/api/polling.d.ts +0 -46
  36. package/dist/api/polling.d.ts.map +0 -1
  37. package/dist/api/polling.js +0 -139
  38. package/dist/api/polling.test.d.ts +0 -2
  39. package/dist/api/polling.test.d.ts.map +0 -1
  40. package/dist/api/polling.test.js +0 -318
  41. package/dist/api/router.d.ts +0 -16
  42. package/dist/api/router.d.ts.map +0 -1
  43. package/dist/api/router.js +0 -31
  44. package/dist/api/router.test.d.ts +0 -2
  45. package/dist/api/router.test.d.ts.map +0 -1
  46. package/dist/api/router.test.js +0 -103
  47. package/dist/api/schemas.d.ts +0 -531
  48. package/dist/api/schemas.d.ts.map +0 -1
  49. package/dist/api/schemas.js +0 -389
  50. package/dist/api/types.d.ts +0 -82
  51. package/dist/api/types.d.ts.map +0 -1
  52. package/dist/api/types.js +0 -1
  53. package/dist/auth.d.ts +0 -52
  54. package/dist/auth.d.ts.map +0 -1
  55. package/dist/auth.js +0 -72
  56. package/dist/auth.test.d.ts +0 -2
  57. package/dist/auth.test.d.ts.map +0 -1
  58. package/dist/auth.test.js +0 -102
  59. package/dist/constants.d.ts +0 -14
  60. package/dist/constants.d.ts.map +0 -1
  61. package/dist/constants.js +0 -13
  62. package/dist/index.d.ts.map +0 -1
  63. package/dist/index.js +0 -42
  64. package/dist/plugins/api/index.d.ts +0 -12
  65. package/dist/plugins/api/index.d.ts.map +0 -1
  66. package/dist/plugins/api/index.js +0 -24
  67. package/dist/plugins/apps/index.d.ts +0 -15
  68. package/dist/plugins/apps/index.d.ts.map +0 -1
  69. package/dist/plugins/apps/index.js +0 -112
  70. package/dist/plugins/apps/schemas.d.ts +0 -42
  71. package/dist/plugins/apps/schemas.d.ts.map +0 -1
  72. package/dist/plugins/apps/schemas.js +0 -14
  73. package/dist/plugins/eventEmission/builders.d.ts +0 -14
  74. package/dist/plugins/eventEmission/builders.d.ts.map +0 -1
  75. package/dist/plugins/eventEmission/builders.js +0 -109
  76. package/dist/plugins/eventEmission/index.d.ts +0 -38
  77. package/dist/plugins/eventEmission/index.d.ts.map +0 -1
  78. package/dist/plugins/eventEmission/index.js +0 -336
  79. package/dist/plugins/eventEmission/index.test.d.ts +0 -5
  80. package/dist/plugins/eventEmission/index.test.d.ts.map +0 -1
  81. package/dist/plugins/eventEmission/index.test.js +0 -581
  82. package/dist/plugins/eventEmission/transport.d.ts +0 -27
  83. package/dist/plugins/eventEmission/transport.d.ts.map +0 -1
  84. package/dist/plugins/eventEmission/transport.js +0 -104
  85. package/dist/plugins/eventEmission/transport.test.d.ts +0 -5
  86. package/dist/plugins/eventEmission/transport.test.d.ts.map +0 -1
  87. package/dist/plugins/eventEmission/transport.test.js +0 -164
  88. package/dist/plugins/eventEmission/types.d.ts +0 -63
  89. package/dist/plugins/eventEmission/types.d.ts.map +0 -1
  90. package/dist/plugins/eventEmission/types.js +0 -1
  91. package/dist/plugins/eventEmission/utils.d.ts +0 -45
  92. package/dist/plugins/eventEmission/utils.d.ts.map +0 -1
  93. package/dist/plugins/eventEmission/utils.js +0 -114
  94. package/dist/plugins/fetch/index.d.ts +0 -36
  95. package/dist/plugins/fetch/index.d.ts.map +0 -1
  96. package/dist/plugins/fetch/index.js +0 -62
  97. package/dist/plugins/fetch/schemas.d.ts +0 -19
  98. package/dist/plugins/fetch/schemas.d.ts.map +0 -1
  99. package/dist/plugins/fetch/schemas.js +0 -31
  100. package/dist/plugins/findFirstAuthentication/index.d.ts +0 -21
  101. package/dist/plugins/findFirstAuthentication/index.d.ts.map +0 -1
  102. package/dist/plugins/findFirstAuthentication/index.js +0 -36
  103. package/dist/plugins/findFirstAuthentication/index.test.d.ts +0 -2
  104. package/dist/plugins/findFirstAuthentication/index.test.d.ts.map +0 -1
  105. package/dist/plugins/findFirstAuthentication/index.test.js +0 -177
  106. package/dist/plugins/findFirstAuthentication/schemas.d.ts +0 -20
  107. package/dist/plugins/findFirstAuthentication/schemas.d.ts.map +0 -1
  108. package/dist/plugins/findFirstAuthentication/schemas.js +0 -18
  109. package/dist/plugins/findUniqueAuthentication/index.d.ts +0 -21
  110. package/dist/plugins/findUniqueAuthentication/index.d.ts.map +0 -1
  111. package/dist/plugins/findUniqueAuthentication/index.js +0 -39
  112. package/dist/plugins/findUniqueAuthentication/index.test.d.ts +0 -2
  113. package/dist/plugins/findUniqueAuthentication/index.test.d.ts.map +0 -1
  114. package/dist/plugins/findUniqueAuthentication/index.test.js +0 -159
  115. package/dist/plugins/findUniqueAuthentication/schemas.d.ts +0 -20
  116. package/dist/plugins/findUniqueAuthentication/schemas.d.ts.map +0 -1
  117. package/dist/plugins/findUniqueAuthentication/schemas.js +0 -18
  118. package/dist/plugins/getAction/index.d.ts +0 -25
  119. package/dist/plugins/getAction/index.d.ts.map +0 -1
  120. package/dist/plugins/getAction/index.js +0 -42
  121. package/dist/plugins/getAction/index.test.d.ts +0 -2
  122. package/dist/plugins/getAction/index.test.d.ts.map +0 -1
  123. package/dist/plugins/getAction/index.test.js +0 -211
  124. package/dist/plugins/getAction/schemas.d.ts +0 -30
  125. package/dist/plugins/getAction/schemas.d.ts.map +0 -1
  126. package/dist/plugins/getAction/schemas.js +0 -12
  127. package/dist/plugins/getApp/index.d.ts +0 -21
  128. package/dist/plugins/getApp/index.d.ts.map +0 -1
  129. package/dist/plugins/getApp/index.js +0 -44
  130. package/dist/plugins/getApp/index.test.d.ts +0 -2
  131. package/dist/plugins/getApp/index.test.d.ts.map +0 -1
  132. package/dist/plugins/getApp/index.test.js +0 -157
  133. package/dist/plugins/getApp/schemas.d.ts +0 -16
  134. package/dist/plugins/getApp/schemas.d.ts.map +0 -1
  135. package/dist/plugins/getApp/schemas.js +0 -8
  136. package/dist/plugins/getAuthentication/index.d.ts +0 -21
  137. package/dist/plugins/getAuthentication/index.d.ts.map +0 -1
  138. package/dist/plugins/getAuthentication/index.js +0 -29
  139. package/dist/plugins/getAuthentication/index.test.d.ts +0 -2
  140. package/dist/plugins/getAuthentication/index.test.d.ts.map +0 -1
  141. package/dist/plugins/getAuthentication/index.test.js +0 -106
  142. package/dist/plugins/getAuthentication/schemas.d.ts +0 -7
  143. package/dist/plugins/getAuthentication/schemas.d.ts.map +0 -1
  144. package/dist/plugins/getAuthentication/schemas.js +0 -1
  145. package/dist/plugins/getInputFieldsSchema/index.d.ts +0 -23
  146. package/dist/plugins/getInputFieldsSchema/index.d.ts.map +0 -1
  147. package/dist/plugins/getInputFieldsSchema/index.js +0 -53
  148. package/dist/plugins/getInputFieldsSchema/index.test.d.ts +0 -2
  149. package/dist/plugins/getInputFieldsSchema/index.test.d.ts.map +0 -1
  150. package/dist/plugins/getInputFieldsSchema/index.test.js +0 -291
  151. package/dist/plugins/getInputFieldsSchema/schemas.d.ts +0 -28
  152. package/dist/plugins/getInputFieldsSchema/schemas.d.ts.map +0 -1
  153. package/dist/plugins/getInputFieldsSchema/schemas.js +0 -13
  154. package/dist/plugins/getProfile/index.d.ts +0 -25
  155. package/dist/plugins/getProfile/index.d.ts.map +0 -1
  156. package/dist/plugins/getProfile/index.js +0 -39
  157. package/dist/plugins/getProfile/schemas.d.ts +0 -13
  158. package/dist/plugins/getProfile/schemas.d.ts.map +0 -1
  159. package/dist/plugins/getProfile/schemas.js +0 -6
  160. package/dist/plugins/listActions/index.d.ts +0 -30
  161. package/dist/plugins/listActions/index.d.ts.map +0 -1
  162. package/dist/plugins/listActions/index.js +0 -75
  163. package/dist/plugins/listActions/index.test.d.ts +0 -2
  164. package/dist/plugins/listActions/index.test.d.ts.map +0 -1
  165. package/dist/plugins/listActions/index.test.js +0 -453
  166. package/dist/plugins/listActions/schemas.d.ts +0 -35
  167. package/dist/plugins/listActions/schemas.d.ts.map +0 -1
  168. package/dist/plugins/listActions/schemas.js +0 -22
  169. package/dist/plugins/listApps/index.d.ts +0 -25
  170. package/dist/plugins/listApps/index.d.ts.map +0 -1
  171. package/dist/plugins/listApps/index.js +0 -69
  172. package/dist/plugins/listApps/index.test.d.ts +0 -2
  173. package/dist/plugins/listApps/index.test.d.ts.map +0 -1
  174. package/dist/plugins/listApps/index.test.js +0 -141
  175. package/dist/plugins/listApps/schemas.d.ts +0 -26
  176. package/dist/plugins/listApps/schemas.d.ts.map +0 -1
  177. package/dist/plugins/listApps/schemas.js +0 -19
  178. package/dist/plugins/listAuthentications/index.d.ts +0 -24
  179. package/dist/plugins/listAuthentications/index.d.ts.map +0 -1
  180. package/dist/plugins/listAuthentications/index.js +0 -77
  181. package/dist/plugins/listAuthentications/index.test.d.ts +0 -2
  182. package/dist/plugins/listAuthentications/index.test.d.ts.map +0 -1
  183. package/dist/plugins/listAuthentications/index.test.js +0 -832
  184. package/dist/plugins/listAuthentications/schemas.d.ts +0 -30
  185. package/dist/plugins/listAuthentications/schemas.d.ts.map +0 -1
  186. package/dist/plugins/listAuthentications/schemas.js +0 -32
  187. package/dist/plugins/listInputFieldChoices/index.d.ts +0 -33
  188. package/dist/plugins/listInputFieldChoices/index.d.ts.map +0 -1
  189. package/dist/plugins/listInputFieldChoices/index.js +0 -115
  190. package/dist/plugins/listInputFieldChoices/index.test.d.ts +0 -2
  191. package/dist/plugins/listInputFieldChoices/index.test.d.ts.map +0 -1
  192. package/dist/plugins/listInputFieldChoices/index.test.js +0 -717
  193. package/dist/plugins/listInputFieldChoices/schemas.d.ts +0 -43
  194. package/dist/plugins/listInputFieldChoices/schemas.d.ts.map +0 -1
  195. package/dist/plugins/listInputFieldChoices/schemas.js +0 -65
  196. package/dist/plugins/listInputFields/index.d.ts +0 -34
  197. package/dist/plugins/listInputFields/index.d.ts.map +0 -1
  198. package/dist/plugins/listInputFields/index.js +0 -204
  199. package/dist/plugins/listInputFields/index.test.d.ts +0 -2
  200. package/dist/plugins/listInputFields/index.test.d.ts.map +0 -1
  201. package/dist/plugins/listInputFields/index.test.js +0 -359
  202. package/dist/plugins/listInputFields/schemas.d.ts +0 -35
  203. package/dist/plugins/listInputFields/schemas.d.ts.map +0 -1
  204. package/dist/plugins/listInputFields/schemas.js +0 -23
  205. package/dist/plugins/manifest/index.d.ts +0 -85
  206. package/dist/plugins/manifest/index.d.ts.map +0 -1
  207. package/dist/plugins/manifest/index.js +0 -376
  208. package/dist/plugins/manifest/index.test.d.ts +0 -2
  209. package/dist/plugins/manifest/index.test.d.ts.map +0 -1
  210. package/dist/plugins/manifest/index.test.js +0 -1139
  211. package/dist/plugins/manifest/schemas.d.ts +0 -57
  212. package/dist/plugins/manifest/schemas.d.ts.map +0 -1
  213. package/dist/plugins/manifest/schemas.js +0 -50
  214. package/dist/plugins/registry/index.d.ts +0 -21
  215. package/dist/plugins/registry/index.d.ts.map +0 -1
  216. package/dist/plugins/registry/index.js +0 -117
  217. package/dist/plugins/request/index.d.ts +0 -21
  218. package/dist/plugins/request/index.d.ts.map +0 -1
  219. package/dist/plugins/request/index.js +0 -76
  220. package/dist/plugins/request/index.test.d.ts +0 -2
  221. package/dist/plugins/request/index.test.d.ts.map +0 -1
  222. package/dist/plugins/request/index.test.js +0 -337
  223. package/dist/plugins/request/schemas.d.ts +0 -54
  224. package/dist/plugins/request/schemas.d.ts.map +0 -1
  225. package/dist/plugins/request/schemas.js +0 -41
  226. package/dist/plugins/runAction/index.d.ts +0 -33
  227. package/dist/plugins/runAction/index.d.ts.map +0 -1
  228. package/dist/plugins/runAction/index.js +0 -108
  229. package/dist/plugins/runAction/index.test.d.ts +0 -2
  230. package/dist/plugins/runAction/index.test.d.ts.map +0 -1
  231. package/dist/plugins/runAction/index.test.js +0 -333
  232. package/dist/plugins/runAction/schemas.d.ts +0 -34
  233. package/dist/plugins/runAction/schemas.d.ts.map +0 -1
  234. package/dist/plugins/runAction/schemas.js +0 -23
  235. package/dist/resolvers/actionKey.d.ts +0 -15
  236. package/dist/resolvers/actionKey.d.ts.map +0 -1
  237. package/dist/resolvers/actionKey.js +0 -19
  238. package/dist/resolvers/actionType.d.ts +0 -10
  239. package/dist/resolvers/actionType.d.ts.map +0 -1
  240. package/dist/resolvers/actionType.js +0 -21
  241. package/dist/resolvers/appKey.d.ts +0 -3
  242. package/dist/resolvers/appKey.d.ts.map +0 -1
  243. package/dist/resolvers/appKey.js +0 -5
  244. package/dist/resolvers/authenticationId.d.ts +0 -9
  245. package/dist/resolvers/authenticationId.d.ts.map +0 -1
  246. package/dist/resolvers/authenticationId.js +0 -42
  247. package/dist/resolvers/index.d.ts +0 -8
  248. package/dist/resolvers/index.d.ts.map +0 -1
  249. package/dist/resolvers/index.js +0 -8
  250. package/dist/resolvers/inputFieldKey.d.ts +0 -11
  251. package/dist/resolvers/inputFieldKey.d.ts.map +0 -1
  252. package/dist/resolvers/inputFieldKey.js +0 -47
  253. package/dist/resolvers/inputs.d.ts +0 -17
  254. package/dist/resolvers/inputs.d.ts.map +0 -1
  255. package/dist/resolvers/inputs.js +0 -50
  256. package/dist/schemas/Action.d.ts +0 -24
  257. package/dist/schemas/Action.d.ts.map +0 -1
  258. package/dist/schemas/Action.js +0 -40
  259. package/dist/schemas/App.d.ts +0 -57
  260. package/dist/schemas/App.d.ts.map +0 -1
  261. package/dist/schemas/App.js +0 -31
  262. package/dist/schemas/Auth.d.ts +0 -55
  263. package/dist/schemas/Auth.d.ts.map +0 -1
  264. package/dist/schemas/Auth.js +0 -33
  265. package/dist/schemas/Field.d.ts +0 -61
  266. package/dist/schemas/Field.d.ts.map +0 -1
  267. package/dist/schemas/Field.js +0 -116
  268. package/dist/schemas/Run.d.ts +0 -3
  269. package/dist/schemas/Run.d.ts.map +0 -1
  270. package/dist/schemas/Run.js +0 -31
  271. package/dist/schemas/UserProfile.d.ts +0 -13
  272. package/dist/schemas/UserProfile.d.ts.map +0 -1
  273. package/dist/schemas/UserProfile.js +0 -32
  274. package/dist/sdk.d.ts +0 -146
  275. package/dist/sdk.d.ts.map +0 -1
  276. package/dist/sdk.js +0 -112
  277. package/dist/sdk.test.d.ts +0 -2
  278. package/dist/sdk.test.d.ts.map +0 -1
  279. package/dist/sdk.test.js +0 -255
  280. package/dist/services/implementations.d.ts +0 -63
  281. package/dist/services/implementations.d.ts.map +0 -1
  282. package/dist/services/implementations.js +0 -80
  283. package/dist/temporary-internal-core/handlers/listApps.d.ts +0 -67
  284. package/dist/temporary-internal-core/handlers/listApps.d.ts.map +0 -1
  285. package/dist/temporary-internal-core/handlers/listApps.js +0 -134
  286. package/dist/temporary-internal-core/handlers/listApps.test.d.ts +0 -2
  287. package/dist/temporary-internal-core/handlers/listApps.test.d.ts.map +0 -1
  288. package/dist/temporary-internal-core/handlers/listApps.test.js +0 -367
  289. package/dist/temporary-internal-core/index.d.ts +0 -18
  290. package/dist/temporary-internal-core/index.d.ts.map +0 -1
  291. package/dist/temporary-internal-core/index.js +0 -18
  292. package/dist/temporary-internal-core/schemas/apps/index.d.ts +0 -175
  293. package/dist/temporary-internal-core/schemas/apps/index.d.ts.map +0 -1
  294. package/dist/temporary-internal-core/schemas/apps/index.js +0 -97
  295. package/dist/temporary-internal-core/schemas/errors/index.d.ts +0 -139
  296. package/dist/temporary-internal-core/schemas/errors/index.d.ts.map +0 -1
  297. package/dist/temporary-internal-core/schemas/errors/index.js +0 -129
  298. package/dist/temporary-internal-core/schemas/implementations/index.d.ts +0 -127
  299. package/dist/temporary-internal-core/schemas/implementations/index.d.ts.map +0 -1
  300. package/dist/temporary-internal-core/schemas/implementations/index.js +0 -79
  301. package/dist/temporary-internal-core/types/handler.d.ts +0 -51
  302. package/dist/temporary-internal-core/types/handler.d.ts.map +0 -1
  303. package/dist/temporary-internal-core/types/handler.js +0 -8
  304. package/dist/temporary-internal-core/types/index.d.ts +0 -5
  305. package/dist/temporary-internal-core/types/index.d.ts.map +0 -1
  306. package/dist/temporary-internal-core/types/index.js +0 -4
  307. package/dist/temporary-internal-core/utils/app-locators.d.ts +0 -34
  308. package/dist/temporary-internal-core/utils/app-locators.d.ts.map +0 -1
  309. package/dist/temporary-internal-core/utils/app-locators.js +0 -39
  310. package/dist/temporary-internal-core/utils/string-utils.d.ts +0 -28
  311. package/dist/temporary-internal-core/utils/string-utils.d.ts.map +0 -1
  312. package/dist/temporary-internal-core/utils/string-utils.js +0 -52
  313. package/dist/temporary-internal-core/utils/transformations.d.ts +0 -18
  314. package/dist/temporary-internal-core/utils/transformations.d.ts.map +0 -1
  315. package/dist/temporary-internal-core/utils/transformations.js +0 -36
  316. package/dist/types/domain.d.ts +0 -52
  317. package/dist/types/domain.d.ts.map +0 -1
  318. package/dist/types/domain.js +0 -1
  319. package/dist/types/domain.test.d.ts +0 -2
  320. package/dist/types/domain.test.d.ts.map +0 -1
  321. package/dist/types/domain.test.js +0 -39
  322. package/dist/types/errors.d.ts +0 -143
  323. package/dist/types/errors.d.ts.map +0 -1
  324. package/dist/types/errors.js +0 -187
  325. package/dist/types/events.d.ts +0 -38
  326. package/dist/types/events.d.ts.map +0 -1
  327. package/dist/types/events.js +0 -7
  328. package/dist/types/functions.d.ts +0 -27
  329. package/dist/types/functions.d.ts.map +0 -1
  330. package/dist/types/functions.js +0 -1
  331. package/dist/types/plugin.d.ts +0 -75
  332. package/dist/types/plugin.d.ts.map +0 -1
  333. package/dist/types/plugin.js +0 -9
  334. package/dist/types/properties.d.ts +0 -33
  335. package/dist/types/properties.d.ts.map +0 -1
  336. package/dist/types/properties.js +0 -52
  337. package/dist/types/sdk.d.ts +0 -69
  338. package/dist/types/sdk.d.ts.map +0 -1
  339. package/dist/types/sdk.js +0 -4
  340. package/dist/types/telemetry-events.d.ts +0 -105
  341. package/dist/types/telemetry-events.d.ts.map +0 -1
  342. package/dist/types/telemetry-events.js +0 -8
  343. package/dist/utils/array-utils.d.ts +0 -31
  344. package/dist/utils/array-utils.d.ts.map +0 -1
  345. package/dist/utils/array-utils.js +0 -36
  346. package/dist/utils/array-utils.test.d.ts +0 -2
  347. package/dist/utils/array-utils.test.d.ts.map +0 -1
  348. package/dist/utils/array-utils.test.js +0 -107
  349. package/dist/utils/batch-utils.d.ts +0 -72
  350. package/dist/utils/batch-utils.d.ts.map +0 -1
  351. package/dist/utils/batch-utils.js +0 -162
  352. package/dist/utils/batch-utils.test.d.ts +0 -2
  353. package/dist/utils/batch-utils.test.d.ts.map +0 -1
  354. package/dist/utils/batch-utils.test.js +0 -476
  355. package/dist/utils/domain-utils.d.ts +0 -66
  356. package/dist/utils/domain-utils.d.ts.map +0 -1
  357. package/dist/utils/domain-utils.js +0 -164
  358. package/dist/utils/domain-utils.test.d.ts +0 -2
  359. package/dist/utils/domain-utils.test.d.ts.map +0 -1
  360. package/dist/utils/domain-utils.test.js +0 -346
  361. package/dist/utils/file-utils.d.ts +0 -4
  362. package/dist/utils/file-utils.d.ts.map +0 -1
  363. package/dist/utils/file-utils.js +0 -74
  364. package/dist/utils/file-utils.test.d.ts +0 -2
  365. package/dist/utils/file-utils.test.d.ts.map +0 -1
  366. package/dist/utils/file-utils.test.js +0 -51
  367. package/dist/utils/function-utils.d.ts +0 -73
  368. package/dist/utils/function-utils.d.ts.map +0 -1
  369. package/dist/utils/function-utils.js +0 -245
  370. package/dist/utils/function-utils.test.d.ts +0 -2
  371. package/dist/utils/function-utils.test.d.ts.map +0 -1
  372. package/dist/utils/function-utils.test.js +0 -110
  373. package/dist/utils/id-utils.d.ts +0 -13
  374. package/dist/utils/id-utils.d.ts.map +0 -1
  375. package/dist/utils/id-utils.js +0 -22
  376. package/dist/utils/id-utils.test.d.ts +0 -2
  377. package/dist/utils/id-utils.test.d.ts.map +0 -1
  378. package/dist/utils/id-utils.test.js +0 -22
  379. package/dist/utils/pagination-utils.d.ts +0 -37
  380. package/dist/utils/pagination-utils.d.ts.map +0 -1
  381. package/dist/utils/pagination-utils.js +0 -165
  382. package/dist/utils/pagination-utils.test.d.ts +0 -17
  383. package/dist/utils/pagination-utils.test.d.ts.map +0 -1
  384. package/dist/utils/pagination-utils.test.js +0 -461
  385. package/dist/utils/retry-utils.d.ts +0 -45
  386. package/dist/utils/retry-utils.d.ts.map +0 -1
  387. package/dist/utils/retry-utils.js +0 -51
  388. package/dist/utils/retry-utils.test.d.ts +0 -2
  389. package/dist/utils/retry-utils.test.d.ts.map +0 -1
  390. package/dist/utils/retry-utils.test.js +0 -90
  391. package/dist/utils/schema-utils.d.ts +0 -69
  392. package/dist/utils/schema-utils.d.ts.map +0 -1
  393. package/dist/utils/schema-utils.js +0 -72
  394. package/dist/utils/string-utils.d.ts +0 -40
  395. package/dist/utils/string-utils.d.ts.map +0 -1
  396. package/dist/utils/string-utils.js +0 -69
  397. package/dist/utils/string-utils.test.d.ts +0 -2
  398. package/dist/utils/string-utils.test.d.ts.map +0 -1
  399. package/dist/utils/string-utils.test.js +0 -59
  400. package/dist/utils/telemetry-utils.d.ts +0 -44
  401. package/dist/utils/telemetry-utils.d.ts.map +0 -1
  402. package/dist/utils/telemetry-utils.js +0 -55
  403. package/dist/utils/telemetry-utils.test.d.ts +0 -2
  404. package/dist/utils/telemetry-utils.test.d.ts.map +0 -1
  405. package/dist/utils/telemetry-utils.test.js +0 -94
  406. package/dist/utils/url-utils.d.ts +0 -19
  407. package/dist/utils/url-utils.d.ts.map +0 -1
  408. package/dist/utils/url-utils.js +0 -62
  409. package/dist/utils/url-utils.test.d.ts +0 -2
  410. package/dist/utils/url-utils.test.d.ts.map +0 -1
  411. package/dist/utils/url-utils.test.js +0 -103
  412. package/dist/utils/validation.d.ts +0 -4
  413. package/dist/utils/validation.d.ts.map +0 -1
  414. package/dist/utils/validation.js +0 -30
  415. package/dist/utils/validation.test.d.ts +0 -2
  416. package/dist/utils/validation.test.d.ts.map +0 -1
  417. package/dist/utils/validation.test.js +0 -44
@@ -1,318 +0,0 @@
1
- /**
2
- * Integration tests for API client handler override mechanism
3
- */
4
- import { describe, it, expect, vi, beforeEach } from "vitest";
5
- import { createZapierApi } from "./client";
6
- describe("Handler Override Mechanism Integration", () => {
7
- let mockFetch;
8
- beforeEach(() => {
9
- mockFetch = vi.fn();
10
- });
11
- describe("listApps handler override", () => {
12
- it("should invoke handler instead of making HTTP request to /api/v0/apps", async () => {
13
- // Mock the nested API call that the handler makes
14
- mockFetch.mockResolvedValueOnce({
15
- ok: true,
16
- status: 200,
17
- json: async () => ({
18
- results: [
19
- {
20
- api: "slack",
21
- name: "Slack",
22
- id: "SlackAPI@1.0.0",
23
- logo_url: "https://example.com/slack.png",
24
- categories: ["communication"],
25
- },
26
- ],
27
- next: null,
28
- }),
29
- });
30
- const api = createZapierApi({
31
- fetch: mockFetch,
32
- token: "test-token",
33
- baseUrl: "https://api.zapier.com",
34
- });
35
- // Call the path with handler override
36
- const result = await api.get("/api/v0/apps", {
37
- searchParams: { implementationIds: "SlackAPI@1.0.0" },
38
- });
39
- // Assert: No direct call to /api/v0/apps (handler intercepted it)
40
- const fetchCalls = mockFetch.mock.calls;
41
- const appsEndpointCalls = fetchCalls.filter((call) => typeof call[0] === "string" && call[0].includes("/api/v0/apps"));
42
- expect(appsEndpointCalls).toHaveLength(0);
43
- // Assert: Handler made nested call to lookup endpoint
44
- const lookupCalls = fetchCalls.filter((call) => typeof call[0] === "string" &&
45
- call[0].includes("/zapier/api/v4/implementations-meta/lookup/"));
46
- expect(lookupCalls.length).toBeGreaterThan(0);
47
- // Assert: Result has correct structure from handler
48
- expect(result).toHaveProperty("data");
49
- expect(result).toHaveProperty("nextCursor");
50
- expect(Array.isArray(result.data)).toBe(true);
51
- expect(result.data).toHaveLength(1);
52
- expect(result.data[0]).toMatchObject({
53
- key: "SlackAPI",
54
- title: "Slack",
55
- implementation_id: "SlackAPI@1.0.0",
56
- });
57
- });
58
- it("should pass httpClient to handler for nested API calls", async () => {
59
- // Mock response for the nested lookup call
60
- mockFetch.mockResolvedValueOnce({
61
- ok: true,
62
- status: 200,
63
- json: async () => ({
64
- results: [
65
- {
66
- api: "github",
67
- name: "GitHub",
68
- id: "GitHubAPI@2.1.0",
69
- logo_url: "https://example.com/github.png",
70
- categories: ["developer-tools"],
71
- },
72
- ],
73
- next: null,
74
- }),
75
- });
76
- const api = createZapierApi({
77
- fetch: mockFetch,
78
- token: "test-token",
79
- baseUrl: "https://api.zapier.com",
80
- });
81
- // Request with multiple implementation IDs
82
- await api.get("/api/v0/apps", {
83
- searchParams: {
84
- implementationIds: "GitHubAPI@2.1.0,SlackAPI@1.0.0",
85
- },
86
- });
87
- // Verify that nested API call was made
88
- expect(mockFetch).toHaveBeenCalledWith(expect.stringContaining("/zapier/api/v4/implementations-meta/lookup/"), expect.any(Object));
89
- // Verify the request includes proper configuration
90
- const fetchCall = mockFetch.mock.calls[0];
91
- expect(fetchCall[0]).toContain("selected_apis=GitHubAPI%402.1.0%2CSlackAPI%401.0.0");
92
- expect(fetchCall[1]).toHaveProperty("method", "GET");
93
- });
94
- it("should handle search augmentation through handler", async () => {
95
- // Mock search endpoint response
96
- mockFetch
97
- .mockResolvedValueOnce({
98
- ok: true,
99
- status: 200,
100
- json: async () => ({
101
- results: [
102
- {
103
- api: "gmail",
104
- name: "Gmail",
105
- id: "GmailAPI@1.5.0",
106
- logo_url: "https://example.com/gmail.png",
107
- categories: ["email"],
108
- },
109
- ],
110
- next: null,
111
- }),
112
- })
113
- // Mock lookup endpoint response
114
- .mockResolvedValueOnce({
115
- ok: true,
116
- status: 200,
117
- json: async () => ({
118
- results: [
119
- {
120
- api: "slack",
121
- name: "Slack",
122
- id: "SlackAPI@1.0.0",
123
- logo_url: "https://example.com/slack.png",
124
- categories: ["communication"],
125
- },
126
- {
127
- api: "gmail",
128
- name: "Gmail",
129
- id: "GmailAPI@1.5.0",
130
- logo_url: "https://example.com/gmail.png",
131
- categories: ["email"],
132
- },
133
- ],
134
- next: null,
135
- }),
136
- });
137
- const api = createZapierApi({
138
- fetch: mockFetch,
139
- token: "test-token",
140
- baseUrl: "https://api.zapier.com",
141
- });
142
- // Request with search term and specific implementation
143
- const result = await api.get("/api/v0/apps", {
144
- searchParams: {
145
- implementationIds: "SlackAPI@1.0.0",
146
- search: "email",
147
- },
148
- });
149
- // Verify search endpoint was called
150
- const searchCalls = mockFetch.mock.calls.filter((call) => typeof call[0] === "string" &&
151
- call[0].includes("/zapier/api/v4/implementations-meta/search/"));
152
- expect(searchCalls.length).toBeGreaterThan(0);
153
- // Verify lookup endpoint was called with augmented IDs
154
- const lookupCalls = mockFetch.mock.calls.filter((call) => typeof call[0] === "string" &&
155
- call[0].includes("/zapier/api/v4/implementations-meta/lookup/"));
156
- expect(lookupCalls.length).toBeGreaterThan(0);
157
- // Verify result contains both original and search results
158
- expect(result.data).toHaveLength(2);
159
- });
160
- it("should handle pagination through handler", async () => {
161
- // Mock first page response
162
- mockFetch.mockResolvedValueOnce({
163
- ok: true,
164
- status: 200,
165
- json: async () => ({
166
- results: [
167
- {
168
- api: "app1",
169
- name: "App 1",
170
- id: "App1API@1.0.0",
171
- logo_url: "https://example.com/app1.png",
172
- categories: ["productivity"],
173
- },
174
- ],
175
- next: "https://example.com/api?offset=20",
176
- }),
177
- });
178
- const api = createZapierApi({
179
- fetch: mockFetch,
180
- token: "test-token",
181
- baseUrl: "https://api.zapier.com",
182
- });
183
- const result = await api.get("/api/v0/apps", {
184
- searchParams: { pageSize: "10" },
185
- });
186
- // Verify pagination cursor is extracted
187
- expect(result.nextCursor).toBe("20");
188
- // Mock second page response
189
- mockFetch.mockResolvedValueOnce({
190
- ok: true,
191
- status: 200,
192
- json: async () => ({
193
- results: [
194
- {
195
- api: "app2",
196
- name: "App 2",
197
- id: "App2API@1.0.0",
198
- logo_url: "https://example.com/app2.png",
199
- categories: ["productivity"],
200
- },
201
- ],
202
- next: null,
203
- }),
204
- });
205
- // Request second page
206
- const secondPageResult = await api.get("/api/v0/apps", {
207
- searchParams: { cursor: "20" },
208
- });
209
- expect(secondPageResult.nextCursor).toBeUndefined();
210
- });
211
- it("should handle errors from handler correctly", async () => {
212
- // Mock an error response from nested API call
213
- mockFetch.mockResolvedValueOnce({
214
- ok: false,
215
- status: 404,
216
- statusText: "Not Found",
217
- json: async () => ({
218
- errors: [
219
- {
220
- message: "Implementation not found",
221
- },
222
- ],
223
- }),
224
- });
225
- const api = createZapierApi({
226
- fetch: mockFetch,
227
- token: "test-token",
228
- baseUrl: "https://api.zapier.com",
229
- });
230
- // Request should propagate the error from handler
231
- await expect(api.get("/api/v0/apps", {
232
- searchParams: { implementationIds: "NonExistentAPI" },
233
- })).rejects.toThrow();
234
- });
235
- it("should handle empty search results correctly", async () => {
236
- // Mock empty search response
237
- mockFetch.mockResolvedValueOnce({
238
- ok: true,
239
- status: 200,
240
- json: async () => ({
241
- results: [],
242
- next: null,
243
- }),
244
- });
245
- const api = createZapierApi({
246
- fetch: mockFetch,
247
- token: "test-token",
248
- baseUrl: "https://api.zapier.com",
249
- });
250
- const result = await api.get("/api/v0/apps", {
251
- searchParams: {
252
- implementationIds: "",
253
- search: "nonexistentapp",
254
- },
255
- });
256
- // Should return empty results without calling lookup endpoint
257
- expect(result.data).toEqual([]);
258
- expect(result.nextCursor).toBeUndefined();
259
- // Verify only search endpoint was called, not lookup
260
- const lookupCalls = mockFetch.mock.calls.filter((call) => typeof call[0] === "string" &&
261
- call[0].includes("/zapier/api/v4/implementations-meta/lookup/"));
262
- expect(lookupCalls).toHaveLength(0);
263
- });
264
- });
265
- describe("standard path handling (non-override)", () => {
266
- it("should make normal HTTP requests for paths without handler override", async () => {
267
- mockFetch.mockResolvedValueOnce({
268
- ok: true,
269
- status: 200,
270
- json: async () => ({ result: "direct HTTP response" }),
271
- });
272
- const api = createZapierApi({
273
- fetch: mockFetch,
274
- token: "test-token",
275
- baseUrl: "https://api.zapier.com",
276
- });
277
- // Request to a path without handler override
278
- await api.get("/zapier/some-other-endpoint");
279
- // Verify HTTP request was made directly
280
- expect(mockFetch).toHaveBeenCalledWith(expect.stringContaining("/zapier/some-other-endpoint"), expect.any(Object));
281
- });
282
- });
283
- describe("handler override type safety", () => {
284
- it("should handle handler request transformation correctly", async () => {
285
- // Mock response for lookup
286
- mockFetch.mockResolvedValueOnce({
287
- ok: true,
288
- status: 200,
289
- json: async () => ({
290
- results: [],
291
- next: null,
292
- }),
293
- });
294
- const api = createZapierApi({
295
- fetch: mockFetch,
296
- token: "test-token",
297
- baseUrl: "https://api.zapier.com",
298
- });
299
- // Test that string implementationIds are properly handled
300
- const result = await api.get("/api/v0/apps", {
301
- searchParams: {
302
- implementationIds: "App1,App2,App3",
303
- pageSize: "15",
304
- },
305
- });
306
- // Verify the handler received and processed the request
307
- expect(result).toHaveProperty("data");
308
- expect(Array.isArray(result.data)).toBe(true);
309
- // Check that lookup endpoint was called with proper params
310
- const lookupCall = mockFetch.mock.calls.find((call) => typeof call[0] === "string" &&
311
- call[0].includes("/zapier/api/v4/implementations-meta/lookup/"));
312
- expect(lookupCall).toBeDefined();
313
- // Commas are URL-encoded as %2C
314
- expect(lookupCall[0]).toContain("selected_apis=App1%2CApp2%2CApp3");
315
- expect(lookupCall[0]).toContain("limit=15");
316
- });
317
- });
318
- });
@@ -1,374 +0,0 @@
1
- /**
2
- * API Client Implementation
3
- *
4
- * This module contains the core API client implementation, including
5
- * HTTP method handlers, response processing, and client factory functions.
6
- */
7
- import { getAuthorizationHeader } from "./auth";
8
- import { createDebugLogger, createDebugFetch } from "./debug";
9
- import { pollUntilComplete } from "./polling";
10
- import { resolveAuthToken } from "../auth";
11
- import { getZapierBaseUrl } from "../utils/url-utils";
12
- import { ZapierApiError, ZapierAuthenticationError, ZapierValidationError, ZapierNotFoundError, } from "../types/errors";
13
- import { matchRoute } from "./router";
14
- // Configuration for paths
15
- const pathConfig = {
16
- // e.g. /relay -> https://sdkapi.zapier.com/api/v0/sdk/relay/...
17
- "/relay": {
18
- authHeader: "X-Relay-Authorization",
19
- pathPrefix: "/api/v0/sdk/relay",
20
- },
21
- // e.g. /zapier -> https://sdkapi.zapier.com/api/v0/sdk/zapier/...
22
- "/zapier": {
23
- authHeader: "Authorization",
24
- pathPrefix: "/api/v0/sdk/zapier",
25
- },
26
- };
27
- class ZapierApiClient {
28
- constructor(options) {
29
- this.options = options;
30
- this.fetch = async (path, init) => {
31
- return this.plainFetch(path, init);
32
- };
33
- this.get = async (path, options = {}) => {
34
- return this.fetchJson("GET", path, undefined, options);
35
- };
36
- this.post = async (path, data, options = {}) => {
37
- return this.fetchJson("POST", path, data, options);
38
- };
39
- this.put = async (path, data, options = {}) => {
40
- return this.fetchJson("PUT", path, data, options);
41
- };
42
- this.delete = async (path, options = {}) => {
43
- return this.fetchJson("DELETE", path, undefined, options);
44
- };
45
- this.poll = async (path, options = {}) => {
46
- return pollUntilComplete({
47
- fetchPoll: () => this.plainFetch(path, {
48
- method: "GET",
49
- searchParams: options.searchParams,
50
- authRequired: options.authRequired,
51
- }),
52
- initialDelay: options.initialDelay,
53
- timeoutMs: options.timeoutMs,
54
- successStatus: options.successStatus,
55
- pendingStatus: options.pendingStatus,
56
- resultExtractor: options.resultExtractor,
57
- });
58
- };
59
- }
60
- // Helper to parse response data
61
- async parseResult(response) {
62
- try {
63
- return { type: "json", data: await response.json() };
64
- }
65
- catch {
66
- return { type: "text", data: await response.text() };
67
- }
68
- }
69
- // Helper to get a token from the different places it could be gotten
70
- async getAuthToken() {
71
- return resolveAuthToken({
72
- token: this.options.token,
73
- getToken: this.options.getToken,
74
- onEvent: this.options.onEvent,
75
- fetch: this.options.fetch,
76
- baseUrl: this.options.baseUrl,
77
- authBaseUrl: this.options.authBaseUrl,
78
- authClientId: this.options.authClientId,
79
- });
80
- }
81
- // Helper to handle responses
82
- async handleResponse(params) {
83
- const { response, customErrorHandler, wasMissingAuthToken } = params;
84
- const { data: responseData } = await this.parseResult(response);
85
- if (response.ok) {
86
- return responseData;
87
- }
88
- const errorInfo = {
89
- status: response.status,
90
- statusText: response.statusText,
91
- data: responseData,
92
- };
93
- // Check for custom error handling first
94
- if (customErrorHandler) {
95
- const customError = customErrorHandler(errorInfo);
96
- if (customError) {
97
- // javascript may not respect customErrorHandler return type, so we need to throw a proper error if it's not an Error
98
- if (customError instanceof Error) {
99
- throw customError;
100
- }
101
- else {
102
- throw new Error(`customErrorHandler returned a non-Error: ${JSON.stringify(customError)}`);
103
- }
104
- }
105
- }
106
- // Parse the error response
107
- const { message, errors } = this.parseErrorResponse(errorInfo);
108
- const errorOptions = {
109
- statusCode: response.status,
110
- errors,
111
- };
112
- // Use appropriate error type based on status code
113
- if (response.status === 404) {
114
- throw new ZapierNotFoundError(message, errorOptions);
115
- }
116
- if (response.status === 401 || response.status === 403) {
117
- // If we get a 401/403 error and no auth token was provided, give helpful message
118
- if (wasMissingAuthToken) {
119
- throw new ZapierAuthenticationError(`Authentication required (HTTP ${response.status}). Please provide a token in options or set ZAPIER_TOKEN environment variable.`, errorOptions);
120
- }
121
- throw new ZapierAuthenticationError(message, errorOptions);
122
- }
123
- if (response.status === 400) {
124
- throw new ZapierValidationError(message, errorOptions);
125
- }
126
- // Generic API error for other status codes
127
- throw new ZapierApiError(message, errorOptions);
128
- }
129
- hasErrorArray(data) {
130
- return (typeof data === "object" &&
131
- data !== null &&
132
- "errors" in data &&
133
- Array.isArray(data.errors));
134
- }
135
- // Helper to check if data has API errors
136
- isApiErrorArray(dataArray) {
137
- const data = dataArray[0];
138
- return (typeof data === "object" &&
139
- data !== null &&
140
- "message" in data &&
141
- "code" in data &&
142
- "title" in data &&
143
- "detail" in data);
144
- }
145
- // Do our best to extract an error message from the response data
146
- extractErrorMessage(data) {
147
- if (typeof data === "string") {
148
- return data;
149
- }
150
- if (typeof data === "object" && data !== null) {
151
- if ("message" in data && typeof data.message === "string") {
152
- return data.message;
153
- }
154
- if ("error" in data) {
155
- if (typeof data.error === "string") {
156
- return data.error;
157
- }
158
- if (typeof data.error === "object" && data.error !== null) {
159
- if ("message" in data.error &&
160
- typeof data.error.message === "string") {
161
- return data.error.message;
162
- }
163
- }
164
- try {
165
- return JSON.stringify(data.error);
166
- }
167
- catch {
168
- /* defend against circular objects, even though they shouldn't be coming back from the wire */
169
- }
170
- }
171
- if ("errors" in data && Array.isArray(data.errors)) {
172
- if (this.isApiErrorArray(data.errors)) {
173
- return data.errors[0].detail || data.errors[0].title;
174
- }
175
- else if (data.errors.length > 0) {
176
- // Handle simple string errors array
177
- const firstError = data.errors[0];
178
- if (typeof firstError === "string") {
179
- return firstError;
180
- }
181
- // For non-string errors, stringify them
182
- try {
183
- return JSON.stringify(firstError);
184
- }
185
- catch {
186
- return String(firstError);
187
- }
188
- }
189
- }
190
- }
191
- return undefined;
192
- }
193
- // Helper to parse API error response
194
- parseErrorResponse(errorInfo) {
195
- // If we can't parse data, use status text
196
- const fallbackMessage = `HTTP ${errorInfo.status}: ${errorInfo.statusText}`;
197
- try {
198
- // Check if the response has the standard error format
199
- if (typeof errorInfo.data === "string") {
200
- return { message: `${fallbackMessage}: ${errorInfo.data}` };
201
- }
202
- const errorMessage = this.extractErrorMessage(errorInfo.data) || fallbackMessage;
203
- if (this.hasErrorArray(errorInfo.data)) {
204
- if (this.isApiErrorArray(errorInfo.data.errors)) {
205
- return {
206
- message: errorMessage,
207
- errors: errorInfo.data.errors,
208
- };
209
- }
210
- else {
211
- return {
212
- message: errorMessage,
213
- errors: errorInfo.data.errors.map((e) => ({
214
- status: errorInfo.status,
215
- code: String(errorInfo.status),
216
- title: errorInfo.statusText,
217
- detail: JSON.stringify(e),
218
- })),
219
- };
220
- }
221
- }
222
- return { message: errorMessage };
223
- }
224
- catch {
225
- return { message: fallbackMessage };
226
- }
227
- }
228
- // Apply any special routing logic for configured paths.
229
- applyPathConfiguration(path) {
230
- // Find matching path configuration.
231
- const matchingPathKey = Object.keys(pathConfig).find((configPath) => path === configPath || path.startsWith(configPath + "/"));
232
- const config = matchingPathKey ? pathConfig[matchingPathKey] : undefined;
233
- // Check if baseUrl is a Zapier-inferred base URL.
234
- const zapierBaseUrl = getZapierBaseUrl(this.options.baseUrl);
235
- // Let's remain compatible with a base URL that is set to a Zapier-inferred
236
- // domain, rather than requiring the base URL to go to our proxy. Later, the
237
- // proxy will be removed, so this should make that transition easier.
238
- if (zapierBaseUrl === this.options.baseUrl) {
239
- // If baseUrl is already the Zapier base URL, use sdkapi subdomain.
240
- const originalBaseUrl = new URL(this.options.baseUrl);
241
- const finalBaseUrl = `https://sdkapi.${originalBaseUrl.hostname}`;
242
- // Only prepend pathPrefix if there's a matching config with pathPrefix.
243
- let finalPath = path;
244
- if (config &&
245
- "pathPrefix" in config &&
246
- config.pathPrefix &&
247
- matchingPathKey) {
248
- // Strip the matching path key, and use the pathPrefix instead.
249
- const pathWithoutPrefix = path.slice(matchingPathKey.length) || "/";
250
- finalPath = `${config.pathPrefix}${pathWithoutPrefix}`;
251
- }
252
- return {
253
- url: new URL(finalPath, finalBaseUrl),
254
- pathConfig: config,
255
- };
256
- }
257
- // For a base URL that isn't a Zapier-inferred domain, use the whole base URL.
258
- const baseUrl = new URL(this.options.baseUrl);
259
- const fullPath = baseUrl.pathname.replace(/\/$/, "") + path;
260
- return {
261
- url: new URL(fullPath, baseUrl.origin),
262
- pathConfig: config,
263
- };
264
- }
265
- // Helper to build full URLs and return routing info
266
- buildUrl(path, searchParams) {
267
- const { url, pathConfig: config } = this.applyPathConfiguration(path);
268
- if (searchParams) {
269
- Object.entries(searchParams).forEach(([key, value]) => {
270
- url.searchParams.set(key, value);
271
- });
272
- }
273
- return { url: url.toString(), pathConfig: config };
274
- }
275
- // Helper to build headers
276
- async buildHeaders(options = {}, pathConfig) {
277
- const headers = new Headers(options.headers ?? {});
278
- // Even if auth is not required, we still want to add it in case it adds
279
- // useful context to the API. The session is a good example of this. Auth
280
- // is not required, but if we don't add auth, then we won't get the user's
281
- // session!
282
- const authToken = await this.getAuthToken();
283
- if (authToken) {
284
- const authHeaderName = pathConfig && pathConfig.authHeader
285
- ? pathConfig.authHeader
286
- : "Authorization";
287
- headers.set(authHeaderName, getAuthorizationHeader(authToken));
288
- }
289
- // If we know auth is required, and we don't have a token, throw an error
290
- // before we even make a request.
291
- if (options.authRequired) {
292
- if (headers.get("Authorization") == null && authToken == null) {
293
- throw new ZapierAuthenticationError(`Authentication required but no token available. Please set ZAPIER_TOKEN, or run the 'login' command with the CLI.`);
294
- }
295
- }
296
- return headers;
297
- }
298
- // Helper to perform HTTP requests with JSON handling
299
- async fetchJson(method, path, data, options = {}) {
300
- // Check if this path has a handler override
301
- const routeMatch = matchRoute(method, path);
302
- if (routeMatch) {
303
- // Invoke the handler instead of making an HTTP request
304
- // Merge params from all sources: body, searchParams, and route params
305
- const handlerRequest = {
306
- ...(typeof data === "object" ? data : {}),
307
- ...options.searchParams,
308
- ...routeMatch.params,
309
- };
310
- return routeMatch.handler({
311
- request: handlerRequest,
312
- deps: {
313
- httpClient: this,
314
- },
315
- });
316
- }
317
- const headers = { ...options.headers };
318
- // Add Content-Type for JSON requests with body data
319
- if (data && typeof data === "object") {
320
- headers["Content-Type"] = "application/json";
321
- }
322
- // Check if we have an auth token available
323
- const wasMissingAuthToken = options.authRequired && (await this.getAuthToken()) == null;
324
- const response = await this.plainFetch(path, {
325
- ...options,
326
- method,
327
- body: data != null ? JSON.stringify(data) : undefined,
328
- headers,
329
- });
330
- // plainFetch already handled all auth and headers
331
- const result = await this.handleResponse({
332
- response,
333
- customErrorHandler: options.customErrorHandler,
334
- wasMissingAuthToken,
335
- });
336
- if (typeof result === "string") {
337
- throw new ZapierValidationError(`Response could not be parsed as JSON: ${result}`);
338
- }
339
- return result;
340
- }
341
- // Plain fetch method for API paths (must start with /)
342
- async plainFetch(path, fetchOptions) {
343
- if (!path.startsWith("/")) {
344
- throw new ZapierValidationError(`plainFetch expects a path starting with '/', got: ${path}`);
345
- }
346
- if (fetchOptions?.body && typeof fetchOptions.body === "object") {
347
- fetchOptions.body = JSON.stringify(fetchOptions.body);
348
- }
349
- const { url, pathConfig } = this.buildUrl(path, fetchOptions?.searchParams);
350
- const builtHeaders = await this.buildHeaders(fetchOptions, pathConfig);
351
- const inputHeaders = new Headers(fetchOptions?.headers ?? {});
352
- const mergedHeaders = new Headers();
353
- builtHeaders.forEach((value, key) => {
354
- mergedHeaders.set(key, value);
355
- });
356
- inputHeaders.forEach((value, key) => {
357
- mergedHeaders.set(key, value);
358
- });
359
- return await this.options.fetch(url, {
360
- ...fetchOptions,
361
- headers: mergedHeaders,
362
- });
363
- }
364
- }
365
- export const createZapierApi = (options) => {
366
- const { debug = false, fetch: originalFetch = globalThis.fetch } = options;
367
- const debugLog = createDebugLogger(debug);
368
- const debugFetch = createDebugFetch({ originalFetch, debugLog });
369
- return new ZapierApiClient({
370
- ...options,
371
- debug,
372
- fetch: debugFetch,
373
- });
374
- };