@zapier/zapier-sdk 0.4.1 → 0.5.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 (374) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/api/auth.d.ts +9 -0
  3. package/dist/api/auth.d.ts.map +1 -0
  4. package/dist/api/auth.js +25 -0
  5. package/dist/api/client.d.ts +9 -0
  6. package/dist/api/client.d.ts.map +1 -0
  7. package/dist/api/client.js +322 -0
  8. package/dist/api/debug.d.ts +13 -0
  9. package/dist/api/debug.d.ts.map +1 -0
  10. package/dist/api/debug.js +55 -0
  11. package/dist/api/index.d.ts +29 -0
  12. package/dist/api/index.d.ts.map +1 -0
  13. package/dist/api/index.js +41 -0
  14. package/dist/api/polling.d.ts +16 -0
  15. package/dist/api/polling.d.ts.map +1 -0
  16. package/dist/api/polling.js +45 -0
  17. package/dist/api/schemas.d.ts +2473 -0
  18. package/dist/api/schemas.d.ts.map +1 -0
  19. package/dist/api/schemas.js +355 -0
  20. package/dist/api/types.d.ts +75 -0
  21. package/dist/api/types.d.ts.map +1 -0
  22. package/dist/api/types.js +11 -0
  23. package/dist/auth.d.ts +34 -0
  24. package/dist/auth.d.ts.map +1 -0
  25. package/dist/auth.js +47 -0
  26. package/dist/constants.d.ts +10 -0
  27. package/dist/constants.d.ts.map +1 -0
  28. package/dist/constants.js +9 -0
  29. package/dist/index.cjs +2108 -1379
  30. package/dist/index.d.mts +2440 -620
  31. package/dist/index.d.ts +17 -892
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +20 -0
  34. package/dist/index.mjs +2093 -1362
  35. package/dist/plugins/api/index.d.ts +14 -0
  36. package/dist/plugins/api/index.d.ts.map +1 -0
  37. package/dist/plugins/api/index.js +21 -0
  38. package/dist/plugins/apps/index.d.ts +11 -0
  39. package/dist/plugins/apps/index.d.ts.map +1 -0
  40. package/dist/plugins/apps/index.js +91 -0
  41. package/dist/plugins/apps/types.d.ts +30 -0
  42. package/dist/plugins/apps/types.d.ts.map +1 -0
  43. package/dist/plugins/apps/types.js +2 -0
  44. package/dist/plugins/fetch/index.d.ts +21 -0
  45. package/dist/plugins/fetch/index.d.ts.map +1 -0
  46. package/dist/plugins/fetch/index.js +20 -0
  47. package/dist/plugins/findFirstAuthentication/index.d.ts +20 -0
  48. package/dist/plugins/findFirstAuthentication/index.d.ts.map +1 -0
  49. package/dist/plugins/findFirstAuthentication/index.js +24 -0
  50. package/dist/plugins/findFirstAuthentication/index.test.d.ts +2 -0
  51. package/dist/plugins/findFirstAuthentication/index.test.d.ts.map +1 -0
  52. package/dist/plugins/findFirstAuthentication/index.test.js +171 -0
  53. package/dist/plugins/findFirstAuthentication/schemas.d.ts +29 -0
  54. package/dist/plugins/findFirstAuthentication/schemas.d.ts.map +1 -0
  55. package/dist/plugins/findFirstAuthentication/schemas.js +18 -0
  56. package/dist/plugins/findUniqueAuthentication/index.d.ts +20 -0
  57. package/dist/plugins/findUniqueAuthentication/index.d.ts.map +1 -0
  58. package/dist/plugins/findUniqueAuthentication/index.js +31 -0
  59. package/dist/plugins/findUniqueAuthentication/index.test.d.ts +2 -0
  60. package/dist/plugins/findUniqueAuthentication/index.test.d.ts.map +1 -0
  61. package/dist/plugins/findUniqueAuthentication/index.test.js +152 -0
  62. package/dist/plugins/findUniqueAuthentication/schemas.d.ts +29 -0
  63. package/dist/plugins/findUniqueAuthentication/schemas.d.ts.map +1 -0
  64. package/dist/plugins/findUniqueAuthentication/schemas.js +18 -0
  65. package/dist/plugins/getAction/index.d.ts +23 -0
  66. package/dist/plugins/getAction/index.d.ts.map +1 -0
  67. package/dist/plugins/getAction/index.js +28 -0
  68. package/dist/plugins/getAction/index.test.d.ts +2 -0
  69. package/dist/plugins/getAction/index.test.d.ts.map +1 -0
  70. package/dist/plugins/getAction/index.test.js +186 -0
  71. package/dist/plugins/getAction/schemas.d.ts +23 -0
  72. package/dist/plugins/getAction/schemas.d.ts.map +1 -0
  73. package/dist/plugins/getAction/schemas.js +10 -0
  74. package/dist/plugins/getApp/index.d.ts +22 -0
  75. package/dist/plugins/getApp/index.d.ts.map +1 -0
  76. package/dist/plugins/getApp/index.js +39 -0
  77. package/dist/plugins/getApp/index.test.d.ts +2 -0
  78. package/dist/plugins/getApp/index.test.d.ts.map +1 -0
  79. package/dist/plugins/getApp/index.test.js +100 -0
  80. package/dist/plugins/getApp/schemas.d.ts +18 -0
  81. package/dist/plugins/getApp/schemas.d.ts.map +1 -0
  82. package/dist/plugins/getApp/schemas.js +10 -0
  83. package/dist/plugins/getAuthentication/index.d.ts +22 -0
  84. package/dist/plugins/getAuthentication/index.d.ts.map +1 -0
  85. package/dist/plugins/getAuthentication/index.js +41 -0
  86. package/dist/plugins/getAuthentication/index.test.d.ts +2 -0
  87. package/dist/plugins/getAuthentication/index.test.d.ts.map +1 -0
  88. package/dist/plugins/getAuthentication/index.test.js +205 -0
  89. package/dist/plugins/getAuthentication/schemas.d.ts +17 -0
  90. package/dist/plugins/getAuthentication/schemas.d.ts.map +1 -0
  91. package/dist/plugins/getAuthentication/schemas.js +11 -0
  92. package/dist/plugins/getProfile/index.d.ts +23 -0
  93. package/dist/plugins/getProfile/index.d.ts.map +1 -0
  94. package/dist/plugins/getProfile/index.js +29 -0
  95. package/dist/plugins/getProfile/schemas.d.ts +13 -0
  96. package/dist/plugins/getProfile/schemas.d.ts.map +1 -0
  97. package/dist/plugins/getProfile/schemas.js +5 -0
  98. package/dist/plugins/listActions/index.d.ts +28 -0
  99. package/dist/plugins/listActions/index.d.ts.map +1 -0
  100. package/dist/plugins/listActions/index.js +61 -0
  101. package/dist/plugins/listActions/index.test.d.ts +2 -0
  102. package/dist/plugins/listActions/index.test.d.ts.map +1 -0
  103. package/dist/plugins/listActions/index.test.js +467 -0
  104. package/dist/plugins/listActions/schemas.d.ts +29 -0
  105. package/dist/plugins/listActions/schemas.d.ts.map +1 -0
  106. package/dist/plugins/listActions/schemas.js +21 -0
  107. package/dist/plugins/listApps/index.d.ts +28 -0
  108. package/dist/plugins/listApps/index.d.ts.map +1 -0
  109. package/dist/plugins/listApps/index.js +62 -0
  110. package/dist/plugins/listApps/index.test.d.ts +2 -0
  111. package/dist/plugins/listApps/index.test.d.ts.map +1 -0
  112. package/dist/plugins/listApps/index.test.js +313 -0
  113. package/dist/plugins/listApps/schemas.d.ts +30 -0
  114. package/dist/plugins/listApps/schemas.d.ts.map +1 -0
  115. package/dist/plugins/listApps/schemas.js +23 -0
  116. package/dist/plugins/listAuthentications/index.d.ts +28 -0
  117. package/dist/plugins/listAuthentications/index.d.ts.map +1 -0
  118. package/dist/plugins/listAuthentications/index.js +77 -0
  119. package/dist/plugins/listAuthentications/index.test.d.ts +2 -0
  120. package/dist/plugins/listAuthentications/index.test.d.ts.map +1 -0
  121. package/dist/plugins/listAuthentications/index.test.js +564 -0
  122. package/dist/plugins/listAuthentications/schemas.d.ts +38 -0
  123. package/dist/plugins/listAuthentications/schemas.d.ts.map +1 -0
  124. package/dist/plugins/listAuthentications/schemas.js +28 -0
  125. package/dist/plugins/listInputFields/index.d.ts +28 -0
  126. package/dist/plugins/listInputFields/index.d.ts.map +1 -0
  127. package/dist/plugins/listInputFields/index.js +133 -0
  128. package/dist/plugins/listInputFields/index.test.d.ts +2 -0
  129. package/dist/plugins/listInputFields/index.test.d.ts.map +1 -0
  130. package/dist/plugins/listInputFields/index.test.js +325 -0
  131. package/dist/plugins/listInputFields/schemas.d.ts +38 -0
  132. package/dist/plugins/listInputFields/schemas.d.ts.map +1 -0
  133. package/dist/plugins/listInputFields/schemas.js +22 -0
  134. package/dist/plugins/registry/index.d.ts +11 -0
  135. package/dist/plugins/registry/index.d.ts.map +1 -0
  136. package/dist/plugins/registry/index.js +14 -0
  137. package/dist/plugins/request/index.d.ts +19 -0
  138. package/dist/plugins/request/index.d.ts.map +1 -0
  139. package/dist/plugins/request/index.js +62 -0
  140. package/dist/plugins/request/index.test.d.ts +2 -0
  141. package/dist/plugins/request/index.test.d.ts.map +1 -0
  142. package/dist/plugins/request/index.test.js +256 -0
  143. package/dist/plugins/request/schemas.d.ts +69 -0
  144. package/dist/plugins/request/schemas.d.ts.map +1 -0
  145. package/dist/plugins/request/schemas.js +42 -0
  146. package/dist/plugins/runAction/index.d.ts +28 -0
  147. package/dist/plugins/runAction/index.d.ts.map +1 -0
  148. package/dist/plugins/runAction/index.js +86 -0
  149. package/dist/plugins/runAction/index.test.d.ts +2 -0
  150. package/dist/plugins/runAction/index.test.d.ts.map +1 -0
  151. package/dist/plugins/runAction/index.test.js +320 -0
  152. package/dist/plugins/runAction/schemas.d.ts +37 -0
  153. package/dist/plugins/runAction/schemas.d.ts.map +1 -0
  154. package/dist/plugins/runAction/schemas.js +22 -0
  155. package/dist/resolvers/actionKey.d.ts +9 -0
  156. package/dist/resolvers/actionKey.d.ts.map +1 -0
  157. package/dist/resolvers/actionKey.js +19 -0
  158. package/dist/resolvers/actionType.d.ts +9 -0
  159. package/dist/resolvers/actionType.d.ts.map +1 -0
  160. package/dist/resolvers/actionType.js +22 -0
  161. package/dist/resolvers/appKey.d.ts +7 -0
  162. package/dist/resolvers/appKey.d.ts.map +1 -0
  163. package/dist/resolvers/appKey.js +5 -0
  164. package/dist/resolvers/authenticationId.d.ts +9 -0
  165. package/dist/resolvers/authenticationId.d.ts.map +1 -0
  166. package/dist/resolvers/authenticationId.js +33 -0
  167. package/dist/resolvers/index.d.ts +40 -0
  168. package/dist/resolvers/index.d.ts.map +1 -0
  169. package/dist/resolvers/index.js +91 -0
  170. package/dist/resolvers/inputs.d.ts +8 -0
  171. package/dist/resolvers/inputs.d.ts.map +1 -0
  172. package/dist/resolvers/inputs.js +14 -0
  173. package/dist/schemas/Action.d.ts +243 -0
  174. package/dist/schemas/Action.d.ts.map +1 -0
  175. package/dist/schemas/Action.js +34 -0
  176. package/dist/schemas/App.d.ts +26 -0
  177. package/dist/schemas/App.d.ts.map +1 -0
  178. package/dist/schemas/App.js +22 -0
  179. package/dist/schemas/Auth.d.ts +161 -0
  180. package/dist/schemas/Auth.d.ts.map +1 -0
  181. package/dist/schemas/Auth.js +41 -0
  182. package/dist/schemas/Field.d.ts +144 -0
  183. package/dist/schemas/Field.d.ts.map +1 -0
  184. package/dist/schemas/Field.js +105 -0
  185. package/dist/schemas/UserProfile.d.ts +163 -0
  186. package/dist/schemas/UserProfile.d.ts.map +1 -0
  187. package/dist/schemas/UserProfile.js +29 -0
  188. package/dist/sdk.d.ts +10 -0
  189. package/dist/sdk.d.ts.map +1 -0
  190. package/dist/sdk.js +94 -0
  191. package/dist/sdk.test.d.ts +2 -0
  192. package/dist/sdk.test.d.ts.map +1 -0
  193. package/dist/sdk.test.js +135 -0
  194. package/dist/types/domain.d.ts +36 -0
  195. package/dist/types/domain.d.ts.map +1 -0
  196. package/dist/types/domain.js +1 -0
  197. package/dist/types/domain.test.d.ts +2 -0
  198. package/dist/types/domain.test.d.ts.map +1 -0
  199. package/dist/types/domain.test.js +39 -0
  200. package/dist/types/errors.d.ts +143 -0
  201. package/dist/types/errors.d.ts.map +1 -0
  202. package/dist/types/errors.js +187 -0
  203. package/dist/types/events.d.ts +38 -0
  204. package/dist/types/events.d.ts.map +1 -0
  205. package/dist/types/events.js +7 -0
  206. package/dist/types/functions.d.ts +26 -0
  207. package/dist/types/functions.d.ts.map +1 -0
  208. package/dist/types/functions.js +4 -0
  209. package/dist/types/plugin.d.ts +61 -0
  210. package/dist/types/plugin.d.ts.map +1 -0
  211. package/dist/types/plugin.js +9 -0
  212. package/dist/types/properties.d.ts +22 -0
  213. package/dist/types/properties.d.ts.map +1 -0
  214. package/dist/types/properties.js +50 -0
  215. package/dist/types/sdk.d.ts +43 -0
  216. package/dist/types/sdk.d.ts.map +1 -0
  217. package/dist/types/sdk.js +4 -0
  218. package/dist/utils/array-utils.d.ts +31 -0
  219. package/dist/utils/array-utils.d.ts.map +1 -0
  220. package/dist/utils/array-utils.js +36 -0
  221. package/dist/utils/array-utils.test.d.ts +2 -0
  222. package/dist/utils/array-utils.test.d.ts.map +1 -0
  223. package/dist/utils/array-utils.test.js +107 -0
  224. package/dist/utils/domain-utils.d.ts +78 -0
  225. package/dist/utils/domain-utils.d.ts.map +1 -0
  226. package/dist/utils/domain-utils.js +218 -0
  227. package/dist/utils/domain-utils.test.d.ts +2 -0
  228. package/dist/utils/domain-utils.test.d.ts.map +1 -0
  229. package/dist/utils/domain-utils.test.js +192 -0
  230. package/dist/utils/function-utils.d.ts +45 -0
  231. package/dist/utils/function-utils.d.ts.map +1 -0
  232. package/dist/utils/function-utils.js +158 -0
  233. package/dist/utils/function-utils.test.d.ts +2 -0
  234. package/dist/utils/function-utils.test.d.ts.map +1 -0
  235. package/dist/utils/function-utils.test.js +110 -0
  236. package/dist/utils/pagination-utils.d.ts +37 -0
  237. package/dist/utils/pagination-utils.d.ts.map +1 -0
  238. package/dist/utils/pagination-utils.js +165 -0
  239. package/dist/utils/pagination-utils.test.d.ts +17 -0
  240. package/dist/utils/pagination-utils.test.d.ts.map +1 -0
  241. package/dist/utils/pagination-utils.test.js +461 -0
  242. package/dist/utils/schema-utils.d.ts +45 -0
  243. package/dist/utils/schema-utils.d.ts.map +1 -0
  244. package/dist/utils/schema-utils.js +65 -0
  245. package/dist/utils/validation.d.ts +4 -0
  246. package/dist/utils/validation.d.ts.map +1 -0
  247. package/dist/utils/validation.js +30 -0
  248. package/dist/utils/validation.test.d.ts +2 -0
  249. package/dist/utils/validation.test.d.ts.map +1 -0
  250. package/dist/utils/validation.test.js +43 -0
  251. package/package.json +12 -3
  252. package/src/api/client.ts +394 -171
  253. package/src/api/debug.ts +10 -1
  254. package/src/api/index.ts +0 -2
  255. package/src/api/polling.ts +28 -7
  256. package/src/api/schemas.ts +387 -0
  257. package/src/api/types.ts +72 -136
  258. package/src/constants.ts +10 -0
  259. package/src/index.ts +40 -19
  260. package/src/plugins/api/index.ts +47 -0
  261. package/src/plugins/apps/index.ts +25 -19
  262. package/src/plugins/apps/types.ts +7 -11
  263. package/src/plugins/fetch/index.ts +48 -40
  264. package/src/plugins/findFirstAuthentication/index.test.ts +206 -0
  265. package/src/plugins/findFirstAuthentication/index.ts +55 -0
  266. package/src/plugins/findFirstAuthentication/schemas.ts +41 -0
  267. package/src/plugins/findUniqueAuthentication/index.test.ts +197 -0
  268. package/src/plugins/findUniqueAuthentication/index.ts +72 -0
  269. package/src/plugins/findUniqueAuthentication/schemas.ts +42 -0
  270. package/src/plugins/getAction/index.test.ts +239 -0
  271. package/src/plugins/getAction/index.ts +57 -0
  272. package/src/plugins/getAction/schemas.ts +33 -0
  273. package/src/plugins/getApp/index.test.ts +127 -0
  274. package/src/plugins/getApp/index.ts +66 -0
  275. package/src/plugins/getApp/schemas.ts +38 -0
  276. package/src/plugins/getAuthentication/index.test.ts +284 -0
  277. package/src/plugins/getAuthentication/index.ts +86 -0
  278. package/src/plugins/getAuthentication/schemas.ts +31 -0
  279. package/src/plugins/getProfile/index.ts +55 -0
  280. package/src/plugins/getProfile/schemas.ts +26 -0
  281. package/src/plugins/listActions/index.test.ts +582 -0
  282. package/src/plugins/listActions/index.ts +115 -0
  283. package/src/plugins/listActions/schemas.ts +54 -0
  284. package/src/plugins/listApps/index.test.ts +357 -0
  285. package/src/plugins/listApps/index.ts +121 -0
  286. package/src/plugins/listApps/schemas.ts +49 -0
  287. package/src/plugins/listAuthentications/index.test.ts +709 -0
  288. package/src/plugins/listAuthentications/index.ts +136 -0
  289. package/src/plugins/listAuthentications/schemas.ts +60 -0
  290. package/src/plugins/listInputFields/index.test.ts +408 -0
  291. package/src/plugins/listInputFields/index.ts +204 -0
  292. package/src/plugins/listInputFields/schemas.ts +56 -0
  293. package/src/plugins/registry/index.ts +30 -0
  294. package/src/plugins/request/index.test.ts +329 -0
  295. package/src/plugins/request/index.ts +103 -0
  296. package/src/{functions → plugins}/request/schemas.ts +20 -9
  297. package/src/plugins/runAction/index.test.ts +387 -0
  298. package/src/plugins/runAction/index.ts +176 -0
  299. package/src/plugins/runAction/schemas.ts +53 -0
  300. package/src/resolvers/actionKey.ts +6 -4
  301. package/src/resolvers/actionType.ts +7 -2
  302. package/src/resolvers/appKey.ts +1 -1
  303. package/src/resolvers/authenticationId.ts +12 -3
  304. package/src/resolvers/inputs.ts +3 -1
  305. package/src/schemas/Action.ts +18 -12
  306. package/src/schemas/App.ts +11 -19
  307. package/src/schemas/Auth.ts +18 -13
  308. package/src/schemas/Field.ts +106 -11
  309. package/src/schemas/UserProfile.ts +43 -0
  310. package/src/sdk.test.ts +212 -0
  311. package/src/sdk.ts +132 -102
  312. package/src/types/domain.test.ts +50 -0
  313. package/src/types/domain.ts +43 -75
  314. package/src/types/errors.ts +275 -0
  315. package/src/types/functions.ts +27 -0
  316. package/src/types/optional-zapier-sdk-cli-login.d.ts +37 -0
  317. package/src/types/plugin.ts +105 -0
  318. package/src/types/properties.ts +4 -3
  319. package/src/types/sdk.ts +70 -48
  320. package/src/utils/array-utils.test.ts +131 -0
  321. package/src/utils/array-utils.ts +41 -0
  322. package/src/utils/domain-utils.test.ts +239 -0
  323. package/src/utils/domain-utils.ts +283 -0
  324. package/src/utils/function-utils.test.ts +141 -0
  325. package/src/utils/function-utils.ts +245 -0
  326. package/src/utils/pagination-utils.test.ts +620 -0
  327. package/src/utils/pagination-utils.ts +242 -0
  328. package/src/utils/validation.test.ts +50 -0
  329. package/src/utils/validation.ts +44 -0
  330. package/tsconfig.build.json +16 -2
  331. package/tsconfig.json +3 -1
  332. package/tsconfig.tsbuildinfo +1 -0
  333. package/tsup.config.ts +2 -0
  334. package/src/functions/bundleCode/index.ts +0 -78
  335. package/src/functions/bundleCode/info.ts +0 -9
  336. package/src/functions/bundleCode/schemas.ts +0 -30
  337. package/src/functions/findFirstAuthentication/index.ts +0 -24
  338. package/src/functions/findFirstAuthentication/info.ts +0 -9
  339. package/src/functions/findFirstAuthentication/schemas.ts +0 -50
  340. package/src/functions/findUniqueAuthentication/index.ts +0 -35
  341. package/src/functions/findUniqueAuthentication/info.ts +0 -9
  342. package/src/functions/findUniqueAuthentication/schemas.ts +0 -50
  343. package/src/functions/generateTypes/index.ts +0 -363
  344. package/src/functions/generateTypes/info.ts +0 -9
  345. package/src/functions/generateTypes/schemas.ts +0 -31
  346. package/src/functions/getAction/index.ts +0 -33
  347. package/src/functions/getAction/info.ts +0 -9
  348. package/src/functions/getAction/schemas.ts +0 -25
  349. package/src/functions/getApp/index.ts +0 -41
  350. package/src/functions/getApp/info.ts +0 -9
  351. package/src/functions/getApp/schemas.ts +0 -20
  352. package/src/functions/getAuthentication/index.ts +0 -50
  353. package/src/functions/getAuthentication/info.ts +0 -9
  354. package/src/functions/getAuthentication/schemas.ts +0 -29
  355. package/src/functions/listActions/index.ts +0 -149
  356. package/src/functions/listActions/info.ts +0 -9
  357. package/src/functions/listActions/schemas.ts +0 -30
  358. package/src/functions/listApps/index.ts +0 -60
  359. package/src/functions/listApps/info.ts +0 -9
  360. package/src/functions/listApps/schemas.ts +0 -32
  361. package/src/functions/listAuthentications/index.ts +0 -162
  362. package/src/functions/listAuthentications/info.ts +0 -9
  363. package/src/functions/listAuthentications/schemas.ts +0 -50
  364. package/src/functions/listFields/index.ts +0 -86
  365. package/src/functions/listFields/info.ts +0 -9
  366. package/src/functions/listFields/schemas.ts +0 -36
  367. package/src/functions/request/index.ts +0 -150
  368. package/src/functions/request/info.ts +0 -11
  369. package/src/functions/runAction/index.ts +0 -127
  370. package/src/functions/runAction/info.ts +0 -9
  371. package/src/functions/runAction/schemas.ts +0 -34
  372. package/src/plugins/apps/info.ts +0 -12
  373. package/src/plugins/fetch/types.ts +0 -2
  374. /package/src/{schema-utils.ts → utils/schema-utils.ts} +0 -0
@@ -0,0 +1,204 @@
1
+ import type { Plugin, GetSdkType } from "../../types/plugin";
2
+ import type { ApiClient } from "../../api";
3
+ import type { NeedsRequest, NeedsResponse, Need } from "../../api/types";
4
+ import type { InputFieldItem } from "../../types/domain";
5
+ import {
6
+ ListInputFieldsSchema,
7
+ type ListInputFieldsOptions,
8
+ type ListInputFieldsPage,
9
+ } from "./schemas";
10
+ import { ZapierConfigurationError, ZapierApiError } from "../../types/errors";
11
+ import { createPaginatedFunction } from "../../utils/function-utils";
12
+ import type { GetAppPluginProvides } from "../getApp";
13
+
14
+ // Enums for input field transformation
15
+ enum InputFieldType {
16
+ STRING = "STRING",
17
+ NUMBER = "NUMBER",
18
+ INTEGER = "INTEGER",
19
+ BOOLEAN = "BOOLEAN",
20
+ OBJECT = "OBJECT",
21
+ ARRAY = "ARRAY",
22
+ }
23
+
24
+ enum InputFieldFormat {
25
+ DATETIME = "DATETIME",
26
+ SELECT = "SELECT",
27
+ MULTILINE = "MULTILINE",
28
+ FILE = "FILE",
29
+ PASSWORD = "PASSWORD",
30
+ CODE = "CODE",
31
+ }
32
+
33
+ enum ItemsType {
34
+ STRING = "STRING",
35
+ NUMBER = "NUMBER",
36
+ INTEGER = "INTEGER",
37
+ BOOLEAN = "BOOLEAN",
38
+ OBJECT = "OBJECT",
39
+ }
40
+
41
+ // Transformation helper functions
42
+ function getInputFieldTypeFromNeed(need: Need): InputFieldType {
43
+ if (need.list) {
44
+ return InputFieldType.ARRAY;
45
+ }
46
+
47
+ const typeMap: Record<string, InputFieldType> = {
48
+ string: InputFieldType.STRING,
49
+ decimal: InputFieldType.NUMBER,
50
+ integer: InputFieldType.INTEGER,
51
+ boolean: InputFieldType.BOOLEAN,
52
+ dict: InputFieldType.OBJECT,
53
+ };
54
+
55
+ return typeMap[need.type || ""] || InputFieldType.STRING;
56
+ }
57
+
58
+ function getInputFieldFormatFromNeed(need: Need): InputFieldFormat | undefined {
59
+ if (need.prefill || need.choices) {
60
+ return InputFieldFormat.SELECT;
61
+ }
62
+
63
+ const formatMap: Record<string, InputFieldFormat> = {
64
+ text: InputFieldFormat.MULTILINE,
65
+ datetime: InputFieldFormat.DATETIME,
66
+ file: InputFieldFormat.FILE,
67
+ password: InputFieldFormat.PASSWORD,
68
+ code: InputFieldFormat.CODE,
69
+ };
70
+
71
+ return formatMap[need.type || ""];
72
+ }
73
+
74
+ function getItemsTypeFromNeed(need: Need): ItemsType | undefined {
75
+ if (!need.list) {
76
+ return undefined;
77
+ }
78
+
79
+ const typeMap: Record<string, ItemsType> = {
80
+ string: ItemsType.STRING,
81
+ decimal: ItemsType.NUMBER,
82
+ integer: ItemsType.INTEGER,
83
+ boolean: ItemsType.BOOLEAN,
84
+ dict: ItemsType.OBJECT,
85
+ };
86
+
87
+ return typeMap[need.type || ""] || ItemsType.STRING;
88
+ }
89
+
90
+ // Transform Need to InputFieldItem
91
+ function transformNeedToInputFieldItem(need: Need): InputFieldItem {
92
+ const itemsType = getItemsTypeFromNeed(need);
93
+
94
+ return {
95
+ ...need, // Pass through all original Need fields
96
+ id: need.key,
97
+ default_value: need.default || "",
98
+ depends_on: need.depends_on || [],
99
+ description: need.help_text || "",
100
+ invalidates_input_fields: need.alters_custom_fields || false,
101
+ is_required: need.required || false,
102
+ placeholder: need.placeholder || "",
103
+ title: need.label || "",
104
+ value_type: getInputFieldTypeFromNeed(need),
105
+ format: getInputFieldFormatFromNeed(need),
106
+ items: itemsType ? { type: itemsType } : undefined,
107
+ };
108
+ }
109
+
110
+ export interface ListInputFieldsPluginProvides {
111
+ listInputFields: (options?: ListInputFieldsOptions) => Promise<{
112
+ data: InputFieldItem[];
113
+ }> &
114
+ AsyncIterable<{ data: InputFieldItem[]; nextCursor?: string }> & {
115
+ items(): AsyncIterable<InputFieldItem>;
116
+ };
117
+ context: {
118
+ meta: {
119
+ listInputFields: {
120
+ inputSchema: typeof ListInputFieldsSchema;
121
+ };
122
+ };
123
+ };
124
+ }
125
+
126
+ export const listInputFieldsPlugin: Plugin<
127
+ GetSdkType<GetAppPluginProvides>, // requires getApp in SDK
128
+ { api: ApiClient }, // requires api in context
129
+ ListInputFieldsPluginProvides
130
+ > = ({ sdk, context }) => {
131
+ const listInputFields = createPaginatedFunction(
132
+ async function listInputFieldsPage(
133
+ options: ListInputFieldsOptions & { cursor?: string } & {
134
+ pageSize: number;
135
+ },
136
+ ): Promise<ListInputFieldsPage> {
137
+ // Note: This function ignores pageSize and cursor since it's not actually paginated internally
138
+ const { api } = context;
139
+
140
+ // Extract parameters
141
+ const { appKey, actionKey, actionType, authenticationId, inputs } =
142
+ options;
143
+
144
+ // Use the getApp plugin
145
+ const appData = await sdk.getApp({ appKey });
146
+ const selectedApi = appData.data.current_implementation_id;
147
+
148
+ if (!selectedApi) {
149
+ throw new ZapierConfigurationError(
150
+ "No current_implementation_id found for app",
151
+ { configType: "current_implementation_id" },
152
+ );
153
+ }
154
+
155
+ // Build needs request
156
+ const needsRequest: NeedsRequest = {
157
+ selected_api: selectedApi,
158
+ action: actionKey,
159
+ type_of: actionType,
160
+ params: inputs || {},
161
+ };
162
+
163
+ // Only include authentication_id if it's not null (skip authentication when null)
164
+ if (authenticationId !== null) {
165
+ needsRequest.authentication_id = authenticationId;
166
+ }
167
+
168
+ const needsData: NeedsResponse = await api.post(
169
+ "/api/v4/implementations/needs/",
170
+ needsRequest,
171
+ );
172
+
173
+ if (!needsData.success) {
174
+ throw new ZapierApiError(
175
+ `Failed to get action fields: ${
176
+ needsData.errors?.join(", ") || "Unknown error"
177
+ }`,
178
+ );
179
+ }
180
+
181
+ // Transform Need objects to InputFieldItem objects
182
+ const inputFields: InputFieldItem[] = (needsData.needs || []).map(
183
+ transformNeedToInputFieldItem,
184
+ );
185
+
186
+ return {
187
+ data: inputFields,
188
+ nextCursor: undefined, // No pagination needed since we return all input fields
189
+ };
190
+ },
191
+ ListInputFieldsSchema,
192
+ );
193
+
194
+ return {
195
+ listInputFields,
196
+ context: {
197
+ meta: {
198
+ listInputFields: {
199
+ inputSchema: ListInputFieldsSchema,
200
+ },
201
+ },
202
+ },
203
+ };
204
+ };
@@ -0,0 +1,56 @@
1
+ import { z } from "zod";
2
+ import {
3
+ AppKeyPropertySchema,
4
+ ActionTypePropertySchema,
5
+ ActionKeyPropertySchema,
6
+ AuthenticationIdPropertySchema,
7
+ InputsPropertySchema,
8
+ } from "../../types/properties";
9
+ import type { InputFieldItem } from "../../types/domain";
10
+ import type { PaginatedSdkFunction } from "../../types/functions";
11
+
12
+ // Pure Zod schema - no resolver metadata!
13
+ export const ListInputFieldsSchema = z
14
+ .object({
15
+ appKey: AppKeyPropertySchema,
16
+ actionType: ActionTypePropertySchema,
17
+ actionKey: ActionKeyPropertySchema,
18
+ authenticationId: AuthenticationIdPropertySchema.nullable().optional(),
19
+ inputs: InputsPropertySchema.optional().describe(
20
+ "Current input values that may affect available fields",
21
+ ),
22
+ pageSize: z
23
+ .number()
24
+ .min(1)
25
+ .optional()
26
+ .describe("Number of input fields per page"),
27
+ maxItems: z
28
+ .number()
29
+ .min(1)
30
+ .optional()
31
+ .describe("Maximum total items to return across all pages"),
32
+ })
33
+ .describe("Get the input fields required for a specific action");
34
+
35
+ // Type inferred from schema
36
+ export type ListInputFieldsOptions = z.infer<typeof ListInputFieldsSchema>;
37
+
38
+ // Error union for this function
39
+ export type ListInputFieldsError =
40
+ | import("../../types/errors").ZapierConfigurationError
41
+ | import("../../types/errors").ZapierApiError
42
+ | import("../../types/errors").ZapierAuthenticationError
43
+ | import("../../types/errors").ZapierAppNotFoundError
44
+ | import("../../types/errors").ZapierValidationError
45
+ | import("../../types/errors").ZapierUnknownError;
46
+
47
+ // Page result structure
48
+ export interface ListInputFieldsPage {
49
+ data: InputFieldItem[];
50
+ nextCursor?: string;
51
+ }
52
+
53
+ // SDK function interface
54
+ export interface ListInputFieldsSdkFunction {
55
+ listInputFields: PaginatedSdkFunction<ListInputFieldsOptions, InputFieldItem>;
56
+ }
@@ -0,0 +1,30 @@
1
+ import type { Plugin } from "../../types/plugin";
2
+ import { FunctionRegistryEntry } from "../../types/sdk";
3
+
4
+ export interface RegisterPluginFunctionOptions {}
5
+
6
+ // Registry plugin creates and populates __registry for CLI backward compatibility
7
+ export interface RegistryPluginProvides {
8
+ __registry: FunctionRegistryEntry[];
9
+ }
10
+
11
+ // Registry plugin requires no context but collects SDK metadata
12
+ export const registryPlugin: Plugin<
13
+ {}, // accepts any SDK shape
14
+ {}, // requires no context
15
+ RegistryPluginProvides
16
+ > = ({ sdk, context }) => {
17
+ const metaKeys = Object.keys(context.meta || {});
18
+
19
+ const registryEntries = metaKeys.map((key) => {
20
+ return {
21
+ ...context.meta[key],
22
+ name: key,
23
+ implementation: sdk[key as keyof typeof sdk],
24
+ };
25
+ });
26
+
27
+ return {
28
+ __registry: registryEntries,
29
+ };
30
+ };
@@ -0,0 +1,329 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { ZapierValidationError } from "../../types/errors";
3
+ import { requestPlugin } from "./index";
4
+ import { createSdk } from "../../sdk";
5
+ import type { ApiClient } from "../../api";
6
+ import type { RelayRequestOptions } from "./schemas";
7
+
8
+ describe("request plugin", () => {
9
+ let mockApiClient: ApiClient;
10
+ let mockFetch: any;
11
+
12
+ beforeEach(() => {
13
+ vi.clearAllMocks();
14
+ mockFetch = vi.fn().mockResolvedValue(
15
+ new Response('{"success": true}', {
16
+ status: 200,
17
+ headers: { "Content-Type": "application/json" },
18
+ }),
19
+ );
20
+
21
+ mockApiClient = {
22
+ fetch: mockFetch,
23
+ } as Partial<ApiClient> as ApiClient;
24
+ });
25
+
26
+ function createTestSdk() {
27
+ return createSdk({}, { api: mockApiClient, meta: {} }).addPlugin(
28
+ requestPlugin,
29
+ );
30
+ }
31
+
32
+ describe("schema validation", () => {
33
+ it("should throw validation error for missing url", async () => {
34
+ const sdk = createTestSdk();
35
+ await expect(sdk.request({} as RelayRequestOptions)).rejects.toThrow(
36
+ ZapierValidationError,
37
+ );
38
+ });
39
+
40
+ it("should throw validation error for invalid url", async () => {
41
+ const sdk = createTestSdk();
42
+ await expect(sdk.request({ url: "not-a-url" })).rejects.toThrow(
43
+ ZapierValidationError,
44
+ );
45
+ });
46
+
47
+ it("should throw validation error for invalid method", async () => {
48
+ const sdk = createTestSdk();
49
+ await expect(
50
+ sdk.request({
51
+ url: "https://api.example.com/data",
52
+ method: "INVALID" as any,
53
+ }),
54
+ ).rejects.toThrow(ZapierValidationError);
55
+ });
56
+
57
+ it("should throw validation error for invalid authenticationId type", async () => {
58
+ const sdk = createTestSdk();
59
+ await expect(
60
+ sdk.request({
61
+ url: "https://api.example.com/data",
62
+ authenticationId: "not-a-number" as any,
63
+ }),
64
+ ).rejects.toThrow(ZapierValidationError);
65
+ });
66
+
67
+ it("should throw validation error for invalid callbackUrl", async () => {
68
+ const sdk = createTestSdk();
69
+ await expect(
70
+ sdk.request({
71
+ url: "https://api.example.com/data",
72
+ callbackUrl: "not-a-url",
73
+ }),
74
+ ).rejects.toThrow(ZapierValidationError);
75
+ });
76
+
77
+ it("should pass validation with valid minimal options", async () => {
78
+ const sdk = createTestSdk();
79
+ await sdk.request({ url: "https://api.example.com/data" });
80
+
81
+ expect(mockFetch).toHaveBeenCalled();
82
+ });
83
+
84
+ it("should pass validation with all valid options", async () => {
85
+ const sdk = createTestSdk();
86
+ await sdk.request({
87
+ url: "https://api.example.com/data",
88
+ method: "POST",
89
+ body: '{"test": true}',
90
+ headers: { "Content-Type": "application/json" },
91
+ authenticationId: 123,
92
+ callbackUrl: "https://webhook.example.com/callback",
93
+ authenticationTemplate: '{"token": "{{auth.token}}"}',
94
+ });
95
+
96
+ expect(mockFetch).toHaveBeenCalled();
97
+ });
98
+ });
99
+
100
+ describe("URL transformation", () => {
101
+ it("should transform full URLs to relay path format", async () => {
102
+ const sdk = createTestSdk();
103
+ await sdk.request({
104
+ url: "https://api.github.com/user",
105
+ method: "GET",
106
+ });
107
+
108
+ expect(mockFetch).toHaveBeenCalledWith(
109
+ "/relay/api.github.com/user",
110
+ expect.any(Object),
111
+ );
112
+ });
113
+
114
+ it("should preserve query parameters and fragments", async () => {
115
+ const sdk = createTestSdk();
116
+ await sdk.request({
117
+ url: "https://api.example.com/search?q=test&limit=10#section",
118
+ method: "GET",
119
+ });
120
+
121
+ expect(mockFetch).toHaveBeenCalledWith(
122
+ "/relay/api.example.com/search?q=test&limit=10#section",
123
+ expect.any(Object),
124
+ );
125
+ });
126
+
127
+ it("should handle URLs with ports", async () => {
128
+ const sdk = createTestSdk();
129
+ await sdk.request({
130
+ url: "https://api.example.com:8443/data",
131
+ method: "GET",
132
+ });
133
+
134
+ expect(mockFetch).toHaveBeenCalledWith(
135
+ "/relay/api.example.com:8443/data",
136
+ expect.any(Object),
137
+ );
138
+ });
139
+ });
140
+
141
+ describe("headers handling", () => {
142
+ it("should pass through regular headers", async () => {
143
+ const sdk = createTestSdk();
144
+ const headers = {
145
+ "Content-Type": "application/json",
146
+ "X-Custom-Header": "test-value",
147
+ };
148
+
149
+ await sdk.request({
150
+ url: "https://api.example.com/data",
151
+ method: "POST",
152
+ headers,
153
+ });
154
+
155
+ expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
156
+ method: "POST",
157
+ body: undefined,
158
+ headers: {
159
+ "Content-Type": "application/json",
160
+ "X-Custom-Header": "test-value",
161
+ },
162
+ });
163
+ });
164
+
165
+ it("should add relay-specific headers when provided", async () => {
166
+ const sdk = createTestSdk();
167
+ await sdk.request({
168
+ url: "https://api.example.com/data",
169
+ method: "POST",
170
+ authenticationId: 123,
171
+ callbackUrl: "https://webhook.example.com/callback",
172
+ authenticationTemplate: '{"token": "{{auth.token}}"}',
173
+ });
174
+
175
+ expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
176
+ method: "POST",
177
+ body: undefined,
178
+ headers: {
179
+ "X-Relay-Authentication-Id": "123",
180
+ "X-Relay-Callback-Url": "https://webhook.example.com/callback",
181
+ "X-Authentication-Template": '{"token": "{{auth.token}}"}',
182
+ },
183
+ });
184
+ });
185
+
186
+ it("should handle Headers object", async () => {
187
+ const sdk = createTestSdk();
188
+ const headers = new Headers();
189
+ headers.set("Content-Type", "application/json");
190
+ headers.set("Authorization", "Bearer token");
191
+
192
+ await sdk.request({
193
+ url: "https://api.example.com/data",
194
+ headers,
195
+ });
196
+
197
+ expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
198
+ method: "GET",
199
+ body: undefined,
200
+ headers: {
201
+ "content-type": "application/json", // Headers constructor lowercases names
202
+ authorization: "Bearer token", // Headers constructor lowercases names
203
+ },
204
+ });
205
+ });
206
+
207
+ it("should handle headers as array of tuples", async () => {
208
+ const sdk = createTestSdk();
209
+ const headers: [string, string][] = [
210
+ ["Content-Type", "application/json"],
211
+ ["X-Api-Key", "secret"],
212
+ ];
213
+
214
+ await sdk.request({
215
+ url: "https://api.example.com/data",
216
+ headers,
217
+ });
218
+
219
+ expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
220
+ method: "GET",
221
+ body: undefined,
222
+ headers: {
223
+ "Content-Type": "application/json",
224
+ "X-Api-Key": "secret",
225
+ },
226
+ });
227
+ });
228
+ });
229
+
230
+ describe("HTTP methods", () => {
231
+ const methods = [
232
+ "GET",
233
+ "POST",
234
+ "PUT",
235
+ "DELETE",
236
+ "PATCH",
237
+ "HEAD",
238
+ "OPTIONS",
239
+ ] as const;
240
+
241
+ methods.forEach((method) => {
242
+ it(`should support ${method} method`, async () => {
243
+ const sdk = createTestSdk();
244
+ await sdk.request({
245
+ url: "https://api.example.com/data",
246
+ method,
247
+ });
248
+
249
+ expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
250
+ method,
251
+ body: undefined,
252
+ headers: {},
253
+ });
254
+ });
255
+ });
256
+
257
+ it("should default to GET method", async () => {
258
+ const sdk = createTestSdk();
259
+ await sdk.request({
260
+ url: "https://api.example.com/data",
261
+ });
262
+
263
+ expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
264
+ method: "GET",
265
+ body: undefined,
266
+ headers: {},
267
+ });
268
+ });
269
+ });
270
+
271
+ describe("request body", () => {
272
+ it("should pass through request body", async () => {
273
+ const sdk = createTestSdk();
274
+ const body = '{"name": "test", "value": 42}';
275
+
276
+ await sdk.request({
277
+ url: "https://api.example.com/data",
278
+ method: "POST",
279
+ body,
280
+ });
281
+
282
+ expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
283
+ method: "POST",
284
+ body,
285
+ headers: {},
286
+ });
287
+ });
288
+ });
289
+
290
+ describe("response handling", () => {
291
+ it("should return the response from api.fetch", async () => {
292
+ const mockResponse = new Response('{"result": "success"}', {
293
+ status: 200,
294
+ statusText: "OK",
295
+ headers: { "Content-Type": "application/json" },
296
+ });
297
+
298
+ mockFetch.mockResolvedValue(mockResponse);
299
+
300
+ const sdk = createTestSdk();
301
+ const response = await sdk.request({
302
+ url: "https://api.example.com/data",
303
+ });
304
+
305
+ expect(response).toBe(mockResponse);
306
+ expect(response.status).toBe(200);
307
+ });
308
+
309
+ it("should handle API errors", async () => {
310
+ const error = new Error("Network error");
311
+ mockFetch.mockRejectedValue(error);
312
+
313
+ const sdk = createTestSdk();
314
+ await expect(
315
+ sdk.request({ url: "https://api.example.com/data" }),
316
+ ).rejects.toThrow("Network error");
317
+ });
318
+ });
319
+
320
+ describe("context and metadata", () => {
321
+ it("should provide context with meta information", () => {
322
+ const sdk = createTestSdk();
323
+ const context = sdk.getContext();
324
+
325
+ expect((context.meta as any).request).toBeDefined();
326
+ expect((context.meta as any).request.inputSchema).toBeDefined();
327
+ });
328
+ });
329
+ });