@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,709 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import {
3
+ ZapierValidationError,
4
+ ZapierAuthenticationError,
5
+ } from "../../types/errors";
6
+ import { listAuthenticationsPlugin } from "./index";
7
+ import { createSdk } from "../../sdk";
8
+ import type { ApiClient } from "../../api";
9
+ import type { App } from "../../api/types";
10
+
11
+ const mockAuthenticationsResponse = {
12
+ results: [
13
+ {
14
+ id: 123,
15
+ date: "2021-01-01",
16
+ account_id: 456 as any,
17
+ selected_api: "SlackCLIAPI@1.21.1",
18
+ is_invite_only: false,
19
+ is_private: false,
20
+ shared_with_all: false,
21
+ is_stale: "false",
22
+ marked_stale_at: null,
23
+ label: "My Slack Workspace",
24
+ title: "My Slack Workspace",
25
+ },
26
+ {
27
+ id: 789,
28
+ date: "2021-02-01",
29
+ account_id: 456 as any,
30
+ selected_api: "GitHubAPI@2.1.0",
31
+ is_invite_only: false,
32
+ is_private: false,
33
+ shared_with_all: true,
34
+ is_stale: "true",
35
+ marked_stale_at: "2021-06-01",
36
+ label: "GitHub Integration",
37
+ title: "GitHub Integration",
38
+ },
39
+ ],
40
+ count: 2,
41
+ next: null,
42
+ previous: null,
43
+ };
44
+
45
+ const mockSlackApp = {
46
+ data: {
47
+ id: 1,
48
+ key: "slack",
49
+ title: "Slack",
50
+ hex_color: "#000000",
51
+ age_in_days: "100",
52
+ api_docs_url: "https://slack.com/api-docs",
53
+ app_profile_url: "https://slack.com",
54
+ banner: "https://slack.com/banner.png",
55
+ categories: [],
56
+ canonical_id: "slack",
57
+ zap_usage_count: 100,
58
+ zap_usage_count_last_updated: "2021-01-01",
59
+ zap_usage_count_last_updated_by: "user1",
60
+ zap_usage_count_last_updated_by_id: 123,
61
+ current_implementation_id: "SlackCLIAPI@1.21.1",
62
+ } as Partial<App> as App,
63
+ };
64
+
65
+ describe("listAuthentications plugin", () => {
66
+ let mockApiClient: ApiClient;
67
+ let mockGetApp: any;
68
+
69
+ beforeEach(() => {
70
+ vi.clearAllMocks();
71
+ mockApiClient = {
72
+ get: vi.fn().mockResolvedValue(mockAuthenticationsResponse),
73
+ } as Partial<ApiClient> as ApiClient;
74
+
75
+ mockGetApp = vi.fn().mockResolvedValue(mockSlackApp);
76
+ });
77
+
78
+ function createTestSdk() {
79
+ return createSdk(
80
+ { getApp: mockGetApp }, // Provide getApp in SDK
81
+ { api: mockApiClient, meta: {} },
82
+ ).addPlugin(listAuthenticationsPlugin as any);
83
+ }
84
+
85
+ describe("schema validation", () => {
86
+ it("should pass validation with empty options", async () => {
87
+ const sdk = createTestSdk();
88
+ const result = await sdk.listAuthentications({});
89
+ expect(result.data).toHaveLength(2);
90
+ });
91
+
92
+ it("should handle undefined options", async () => {
93
+ const sdk = createTestSdk();
94
+ const result = await sdk.listAuthentications();
95
+ expect(result.data).toHaveLength(2);
96
+ expect(result.data[0]).toMatchObject({
97
+ id: 123,
98
+ });
99
+ });
100
+
101
+ it("should throw validation error for invalid appKey type", () => {
102
+ const sdk = createTestSdk();
103
+ expect(() => {
104
+ sdk.listAuthentications({
105
+ appKey: 123 as any,
106
+ });
107
+ }).toThrow(ZapierValidationError);
108
+ });
109
+
110
+ it("should throw validation error for invalid search type", () => {
111
+ const sdk = createTestSdk();
112
+ expect(() => {
113
+ sdk.listAuthentications({
114
+ search: 123 as any,
115
+ });
116
+ }).toThrow(ZapierValidationError);
117
+ });
118
+
119
+ it("should throw validation error for invalid title type", () => {
120
+ const sdk = createTestSdk();
121
+ expect(() => {
122
+ sdk.listAuthentications({
123
+ title: 123 as any,
124
+ });
125
+ }).toThrow(ZapierValidationError);
126
+ });
127
+
128
+ it("should throw validation error for invalid account_id type", () => {
129
+ const sdk = createTestSdk();
130
+ expect(() => {
131
+ sdk.listAuthentications({
132
+ account_id: 123,
133
+ });
134
+ }).toThrow(ZapierValidationError);
135
+ });
136
+
137
+ it("should throw validation error for invalid owner type", () => {
138
+ const sdk = createTestSdk();
139
+ expect(() => {
140
+ sdk.listAuthentications({
141
+ owner: 123 as any,
142
+ });
143
+ }).toThrow(ZapierValidationError);
144
+ });
145
+
146
+ it("should throw validation error for invalid pageSize", () => {
147
+ const sdk = createTestSdk();
148
+ expect(() => {
149
+ sdk.listAuthentications({
150
+ pageSize: 0, // Should be >= 1
151
+ });
152
+ }).toThrow(ZapierValidationError);
153
+
154
+ expect(() => {
155
+ sdk.listAuthentications({
156
+ pageSize: -5, // Should be >= 1
157
+ });
158
+ }).toThrow(ZapierValidationError);
159
+ });
160
+
161
+ it("should throw validation error for invalid maxItems", () => {
162
+ const sdk = createTestSdk();
163
+ expect(() => {
164
+ sdk.listAuthentications({
165
+ maxItems: 0 as any, // Should be >= 1
166
+ });
167
+ }).toThrow(ZapierValidationError);
168
+
169
+ expect(() => {
170
+ sdk.listAuthentications({
171
+ maxItems: -10 as any, // Should be >= 1
172
+ });
173
+ }).toThrow(ZapierValidationError);
174
+ });
175
+
176
+ it("should pass validation with all valid fields", async () => {
177
+ const sdk = createTestSdk();
178
+ const result = await sdk.listAuthentications({
179
+ appKey: "slack",
180
+ search: "workspace",
181
+ title: "My Slack Workspace",
182
+ account_id: "acc_123",
183
+ owner: "me",
184
+ pageSize: 10,
185
+ maxItems: 50,
186
+ });
187
+
188
+ expect(result.data).toBeDefined();
189
+ });
190
+ });
191
+
192
+ describe("data mapping", () => {
193
+ it("should map is_stale to is_expired and marked_stale_at to expired_at", async () => {
194
+ const sdk = createTestSdk();
195
+ const result = await sdk.listAuthentications({});
196
+
197
+ expect(result.data[0].is_expired).toBe("false");
198
+ expect(result.data[0].expired_at).toBe(null);
199
+ expect(result.data[1].is_expired).toBe("true");
200
+ expect(result.data[1].expired_at).toBe("2021-06-01");
201
+ });
202
+
203
+ it("should coerce title from label when title is missing", async () => {
204
+ const responseWithoutTitle = {
205
+ ...mockAuthenticationsResponse,
206
+ results: [
207
+ {
208
+ ...mockAuthenticationsResponse.results[0],
209
+ title: undefined,
210
+ label: "Label Only Auth",
211
+ },
212
+ ],
213
+ };
214
+
215
+ mockApiClient.get = vi.fn().mockResolvedValue(responseWithoutTitle);
216
+
217
+ const sdk = createTestSdk();
218
+ const result = await sdk.listAuthentications({});
219
+
220
+ expect(result.data[0].title).toBe("Label Only Auth");
221
+ });
222
+
223
+ it("should handle authentications with neither title nor label", async () => {
224
+ const responseWithoutTitleOrLabel = {
225
+ ...mockAuthenticationsResponse,
226
+ results: [
227
+ {
228
+ ...mockAuthenticationsResponse.results[0],
229
+ title: undefined,
230
+ label: undefined,
231
+ },
232
+ ],
233
+ };
234
+
235
+ mockApiClient.get = vi
236
+ .fn()
237
+ .mockResolvedValue(responseWithoutTitleOrLabel);
238
+
239
+ const sdk = createTestSdk();
240
+ const result = await sdk.listAuthentications({});
241
+
242
+ expect(result.data[0].title).toBeUndefined();
243
+ });
244
+ });
245
+
246
+ describe("filtering", () => {
247
+ it("should filter by exact title match", async () => {
248
+ const sdk = createTestSdk();
249
+ const result = await sdk.listAuthentications({
250
+ title: "My Slack Workspace",
251
+ });
252
+
253
+ // Should filter to exact match
254
+ expect(result.data).toHaveLength(1);
255
+ expect(result.data[0].title).toBe("My Slack Workspace");
256
+ });
257
+
258
+ it("should use search parameter when provided", async () => {
259
+ const sdk = createTestSdk();
260
+ await sdk.listAuthentications({ search: "workspace" });
261
+
262
+ expect(mockApiClient.get).toHaveBeenCalledWith(
263
+ "/api/v4/authentications/",
264
+ expect.objectContaining({
265
+ searchParams: expect.objectContaining({
266
+ search: "workspace",
267
+ }),
268
+ }),
269
+ );
270
+ });
271
+
272
+ it("should use title as search when search not provided", async () => {
273
+ const sdk = createTestSdk();
274
+ await sdk.listAuthentications({ title: "My Slack Workspace" });
275
+
276
+ expect(mockApiClient.get).toHaveBeenCalledWith(
277
+ "/api/v4/authentications/",
278
+ expect.objectContaining({
279
+ searchParams: expect.objectContaining({
280
+ search: "My Slack Workspace",
281
+ }),
282
+ }),
283
+ );
284
+ });
285
+
286
+ it("should prefer search over title when both provided", async () => {
287
+ const sdk = createTestSdk();
288
+ await sdk.listAuthentications({
289
+ search: "explicit search",
290
+ title: "My Title",
291
+ });
292
+
293
+ expect(mockApiClient.get).toHaveBeenCalledWith(
294
+ "/api/v4/authentications/",
295
+ expect.objectContaining({
296
+ searchParams: expect.objectContaining({
297
+ search: "explicit search",
298
+ }),
299
+ }),
300
+ );
301
+ });
302
+
303
+ it("should pass account_id filter to API", async () => {
304
+ const sdk = createTestSdk();
305
+ await sdk.listAuthentications({ account_id: "acc_123" });
306
+
307
+ expect(mockApiClient.get).toHaveBeenCalledWith(
308
+ "/api/v4/authentications/",
309
+ expect.objectContaining({
310
+ searchParams: expect.objectContaining({
311
+ account_id: "acc_123",
312
+ }),
313
+ }),
314
+ );
315
+ });
316
+
317
+ it("should pass owner filter to API", async () => {
318
+ const sdk = createTestSdk();
319
+ await sdk.listAuthentications({ owner: "me" });
320
+
321
+ expect(mockApiClient.get).toHaveBeenCalledWith(
322
+ "/api/v4/authentications/",
323
+ expect.objectContaining({
324
+ searchParams: expect.objectContaining({
325
+ owner: "me",
326
+ }),
327
+ }),
328
+ );
329
+ });
330
+ });
331
+
332
+ describe("pagination", () => {
333
+ it("should handle pagination with maxItems by collecting all items", async () => {
334
+ // Mock multiple pages - first page has 2 items, second page has 1 item
335
+ mockApiClient.get = vi
336
+ .fn()
337
+ .mockResolvedValueOnce({
338
+ results: mockAuthenticationsResponse.results,
339
+ count: 3,
340
+ next: "http://example.com/api/v4/authentications/?offset=2",
341
+ })
342
+ .mockResolvedValueOnce({
343
+ results: [
344
+ {
345
+ id: 999,
346
+ date: "2021-03-01",
347
+ account_id: 456 as any,
348
+ selected_api: "DropboxAPI@3.0.0",
349
+ is_invite_only: false,
350
+ is_private: false,
351
+ shared_with_all: false,
352
+ is_stale: "false",
353
+ marked_stale_at: null,
354
+ title: "Dropbox Integration",
355
+ },
356
+ ],
357
+ count: 3,
358
+ next: null,
359
+ });
360
+
361
+ const sdk = createTestSdk();
362
+ // Collect all items using the items() iterator
363
+ const items = [];
364
+ for await (const item of sdk
365
+ .listAuthentications({ maxItems: 3 })
366
+ .items()) {
367
+ items.push(item);
368
+ }
369
+
370
+ expect(items).toHaveLength(3); // Should stop at maxItems
371
+ expect(mockApiClient.get).toHaveBeenCalledTimes(2); // Should fetch both pages
372
+ });
373
+
374
+ it("should return first page when awaited", async () => {
375
+ mockApiClient.get = vi.fn().mockResolvedValue({
376
+ results: mockAuthenticationsResponse.results,
377
+ count: 2,
378
+ next: null, // No more pages to prevent automatic fetching
379
+ });
380
+
381
+ const sdk = createTestSdk();
382
+ const result = await sdk.listAuthentications({});
383
+
384
+ // Await returns first page only
385
+ expect(result.data).toHaveLength(2);
386
+ expect(mockApiClient.get).toHaveBeenCalledTimes(1);
387
+ });
388
+
389
+ it("should support async iteration over pages", async () => {
390
+ mockApiClient.get = vi
391
+ .fn()
392
+ .mockResolvedValueOnce({
393
+ results: mockAuthenticationsResponse.results.slice(0, 1),
394
+ count: 2,
395
+ next: "http://example.com/api/v4/authentications/?offset=1",
396
+ })
397
+ .mockResolvedValueOnce({
398
+ results: mockAuthenticationsResponse.results.slice(1, 2),
399
+ count: 2,
400
+ next: null,
401
+ });
402
+
403
+ const sdk = createTestSdk();
404
+ const pages = [];
405
+ for await (const page of sdk.listAuthentications({ pageSize: 1 })) {
406
+ pages.push(page);
407
+ if (pages.length >= 2) break;
408
+ }
409
+
410
+ expect(pages).toHaveLength(2);
411
+ expect(pages[0].data).toHaveLength(1);
412
+ expect(pages[1].data).toHaveLength(1);
413
+ expect(pages[0].data[0].id).toBe(123);
414
+ expect(pages[1].data[0].id).toBe(789);
415
+ });
416
+
417
+ it("should support async iteration over individual items", async () => {
418
+ const sdk = createTestSdk();
419
+ const items = [];
420
+ for await (const item of sdk
421
+ .listAuthentications({ maxItems: 2 })
422
+ .items()) {
423
+ items.push(item);
424
+ }
425
+
426
+ expect(items).toHaveLength(2);
427
+ expect(items[0].id).toBe(123);
428
+ expect(items[1].id).toBe(789);
429
+ });
430
+
431
+ it("should set appropriate pageSize for API calls", async () => {
432
+ const sdk = createTestSdk();
433
+ await sdk.listAuthentications({ pageSize: 1 });
434
+
435
+ expect(mockApiClient.get).toHaveBeenCalledWith(
436
+ "/api/v4/authentications/",
437
+ expect.objectContaining({
438
+ searchParams: expect.objectContaining({
439
+ limit: "1",
440
+ }),
441
+ }),
442
+ );
443
+ });
444
+ });
445
+
446
+ describe("API integration", () => {
447
+ it("should call the correct API endpoint", async () => {
448
+ const sdk = createTestSdk();
449
+ await sdk.listAuthentications({});
450
+
451
+ expect(mockApiClient.get).toHaveBeenCalledWith(
452
+ "/api/v4/authentications/",
453
+ expect.any(Object),
454
+ );
455
+ });
456
+
457
+ it("should pass pageSize as limit parameter", async () => {
458
+ const sdk = createTestSdk();
459
+ await sdk.listAuthentications({ pageSize: 25 });
460
+
461
+ expect(mockApiClient.get).toHaveBeenCalledWith(
462
+ "/api/v4/authentications/",
463
+ expect.objectContaining({
464
+ searchParams: expect.objectContaining({
465
+ limit: "25",
466
+ }),
467
+ }),
468
+ );
469
+ });
470
+
471
+ it("should handle cursor-based pagination internally", async () => {
472
+ mockApiClient.get = vi
473
+ .fn()
474
+ .mockResolvedValueOnce({
475
+ results: mockAuthenticationsResponse.results.slice(0, 1),
476
+ count: 2,
477
+ next: "http://example.com/api/v4/authentications/?offset=1",
478
+ })
479
+ .mockResolvedValueOnce({
480
+ results: mockAuthenticationsResponse.results.slice(1, 2),
481
+ count: 2,
482
+ next: null,
483
+ });
484
+
485
+ const sdk = createTestSdk();
486
+ // Test that the function can handle multiple pages
487
+ let pageCount = 0;
488
+ for await (const _page of sdk.listAuthentications({ pageSize: 1 })) {
489
+ pageCount++;
490
+ if (pageCount >= 2) break;
491
+ }
492
+
493
+ expect(pageCount).toBe(2);
494
+ expect(mockApiClient.get).toHaveBeenCalledTimes(2);
495
+ // The second call should include the offset from the cursor
496
+ expect(mockApiClient.get).toHaveBeenNthCalledWith(
497
+ 2,
498
+ "/api/v4/authentications/",
499
+ expect.objectContaining({
500
+ searchParams: expect.objectContaining({
501
+ offset: "1",
502
+ }),
503
+ }),
504
+ );
505
+ });
506
+ });
507
+
508
+ describe("error handling", () => {
509
+ it("should throw ZapierAuthenticationError for 401 responses", async () => {
510
+ const customErrorHandler = vi
511
+ .fn()
512
+ .mockReturnValue(
513
+ new ZapierAuthenticationError(
514
+ "Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP 401)",
515
+ { statusCode: 401 },
516
+ ),
517
+ );
518
+
519
+ mockApiClient.get = vi.fn().mockImplementation(() => {
520
+ const error = customErrorHandler({ status: 401 });
521
+ throw error;
522
+ });
523
+
524
+ const sdk = createTestSdk();
525
+ await expect(sdk.listAuthentications({})).rejects.toThrow(
526
+ ZapierAuthenticationError,
527
+ );
528
+ });
529
+
530
+ it("should throw ZapierAuthenticationError for 403 responses", async () => {
531
+ const customErrorHandler = vi
532
+ .fn()
533
+ .mockReturnValue(
534
+ new ZapierAuthenticationError(
535
+ "Access forbidden. Your token may not have the required scopes to list authentications. (HTTP 403)",
536
+ { statusCode: 403 },
537
+ ),
538
+ );
539
+
540
+ mockApiClient.get = vi.fn().mockImplementation(() => {
541
+ const error = customErrorHandler({ status: 403 });
542
+ throw error;
543
+ });
544
+
545
+ const sdk = createTestSdk();
546
+ await expect(sdk.listAuthentications({})).rejects.toThrow(
547
+ ZapierAuthenticationError,
548
+ );
549
+ });
550
+
551
+ it("should handle empty results", async () => {
552
+ const emptyResponse = {
553
+ results: [],
554
+ count: 0,
555
+ next: null,
556
+ };
557
+
558
+ mockApiClient.get = vi.fn().mockResolvedValue(emptyResponse);
559
+
560
+ const sdk = createTestSdk();
561
+ const result = await sdk.listAuthentications({});
562
+
563
+ expect(result.data).toHaveLength(0);
564
+ expect(Array.isArray(result.data)).toBe(true);
565
+ });
566
+
567
+ it("should handle missing results field", async () => {
568
+ const responseWithoutResults = {
569
+ count: 0,
570
+ next: null,
571
+ };
572
+
573
+ mockApiClient.get = vi.fn().mockResolvedValue(responseWithoutResults);
574
+
575
+ const sdk = createTestSdk();
576
+ const result = await sdk.listAuthentications({});
577
+
578
+ expect(result.data).toHaveLength(0);
579
+ expect(Array.isArray(result.data)).toBe(true);
580
+ });
581
+ });
582
+
583
+ describe("app key integration", () => {
584
+ it("should handle app without current_implementation_id", async () => {
585
+ const appWithoutImplementation = {
586
+ data: {
587
+ id: 123,
588
+ key: "slack",
589
+ title: "Slack",
590
+ current_implementation_id: undefined,
591
+ } as Partial<App> as App,
592
+ };
593
+
594
+ mockGetApp.mockResolvedValue(appWithoutImplementation);
595
+
596
+ const sdk = createTestSdk();
597
+ await sdk.listAuthentications({ appKey: "slack" });
598
+
599
+ // Should not add versionless_selected_api parameter
600
+ expect(mockApiClient.get).toHaveBeenCalledWith(
601
+ "/api/v4/authentications/",
602
+ expect.objectContaining({
603
+ searchParams: expect.not.objectContaining({
604
+ versionless_selected_api: expect.any(String),
605
+ }),
606
+ }),
607
+ );
608
+ });
609
+
610
+ it("should extract versionless API from versioned implementation ID", async () => {
611
+ const appWithVersionedApi = {
612
+ data: {
613
+ id: 123,
614
+ key: "slack",
615
+ title: "Slack",
616
+ current_implementation_id: "SlackCLIAPI@2.1.3",
617
+ } as Partial<App> as App,
618
+ };
619
+
620
+ mockGetApp.mockResolvedValue(appWithVersionedApi);
621
+
622
+ const sdk = createTestSdk();
623
+ await sdk.listAuthentications({ appKey: "slack" });
624
+
625
+ expect(mockApiClient.get).toHaveBeenCalledWith(
626
+ "/api/v4/authentications/",
627
+ expect.objectContaining({
628
+ searchParams: expect.objectContaining({
629
+ versionless_selected_api: "SlackCLIAPI",
630
+ }),
631
+ }),
632
+ );
633
+ });
634
+ });
635
+
636
+ describe("response transformation", () => {
637
+ it("should preserve all original authentication fields", async () => {
638
+ const authWithAllFields = {
639
+ results: [
640
+ {
641
+ id: 123,
642
+ date: "2021-01-01",
643
+ lastchanged: "2021-01-02",
644
+ account_id: 456 as any,
645
+ customuser_id: 789,
646
+ selected_api: "SlackCLIAPI@1.21.1",
647
+ destination_selected_api: "SlackDestAPI@1.0.0",
648
+ is_invite_only: true,
649
+ is_private: true,
650
+ shared_with_all: false,
651
+ is_stale: "true",
652
+ is_shared: "false",
653
+ marked_stale_at: "2021-06-01",
654
+ label: "Auth Label",
655
+ title: "Auth Title",
656
+ identifier: "auth-identifier",
657
+ url: "https://example.com",
658
+ groups: "group1,group2",
659
+ members: "user1,user2",
660
+ permissions: { read: true, write: false },
661
+ },
662
+ ],
663
+ count: 1,
664
+ };
665
+
666
+ mockApiClient.get = vi.fn().mockResolvedValue(authWithAllFields);
667
+
668
+ const sdk = createTestSdk();
669
+ const result = await sdk.listAuthentications({});
670
+ const auth = result.data[0];
671
+
672
+ // Verify original fields are preserved
673
+ expect(auth.id).toBe(123);
674
+ expect(auth.date).toBe("2021-01-01");
675
+ expect(auth.lastchanged).toBe("2021-01-02");
676
+ expect(auth.account_id).toBe(456);
677
+ expect(auth.user_id).toBe(789);
678
+ expect(auth.implementation_id).toBe("SlackCLIAPI@1.21.1");
679
+ expect(auth.destination_selected_api).toBe("SlackDestAPI@1.0.0");
680
+ expect(auth.is_invite_only).toBe(true);
681
+ expect(auth.is_private).toBe(true);
682
+ expect(auth.shared_with_all).toBe(false);
683
+ expect(auth.is_shared).toBe("false");
684
+ expect(auth.label).toBe("Auth Label");
685
+ expect(auth.title).toBe("Auth Title");
686
+ expect(auth.identifier).toBe("auth-identifier");
687
+ expect(auth.url).toBe("https://example.com");
688
+ expect(auth.groups).toBe("group1,group2");
689
+ expect(auth.members).toBe("user1,user2");
690
+ expect(auth.permissions).toEqual({ read: true, write: false });
691
+
692
+ // Verify mapped fields
693
+ expect(auth.is_expired).toBe("true");
694
+ expect(auth.expired_at).toBe("2021-06-01");
695
+ });
696
+ });
697
+
698
+ describe("context and metadata", () => {
699
+ it("should provide context with meta information", () => {
700
+ const sdk = createTestSdk();
701
+ const context = sdk.getContext();
702
+
703
+ expect((context.meta as any).listAuthentications).toBeDefined();
704
+ expect(
705
+ (context.meta as any).listAuthentications.inputSchema,
706
+ ).toBeDefined();
707
+ });
708
+ });
709
+ });