@zapier/zapier-sdk 0.4.1 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (375) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +343 -0
  3. package/dist/api/auth.d.ts +9 -0
  4. package/dist/api/auth.d.ts.map +1 -0
  5. package/dist/api/auth.js +25 -0
  6. package/dist/api/client.d.ts +9 -0
  7. package/dist/api/client.d.ts.map +1 -0
  8. package/dist/api/client.js +322 -0
  9. package/dist/api/debug.d.ts +13 -0
  10. package/dist/api/debug.d.ts.map +1 -0
  11. package/dist/api/debug.js +55 -0
  12. package/dist/api/index.d.ts +29 -0
  13. package/dist/api/index.d.ts.map +1 -0
  14. package/dist/api/index.js +41 -0
  15. package/dist/api/polling.d.ts +16 -0
  16. package/dist/api/polling.d.ts.map +1 -0
  17. package/dist/api/polling.js +45 -0
  18. package/dist/api/schemas.d.ts +2473 -0
  19. package/dist/api/schemas.d.ts.map +1 -0
  20. package/dist/api/schemas.js +355 -0
  21. package/dist/api/types.d.ts +75 -0
  22. package/dist/api/types.d.ts.map +1 -0
  23. package/dist/api/types.js +11 -0
  24. package/dist/auth.d.ts +34 -0
  25. package/dist/auth.d.ts.map +1 -0
  26. package/dist/auth.js +47 -0
  27. package/dist/constants.d.ts +10 -0
  28. package/dist/constants.d.ts.map +1 -0
  29. package/dist/constants.js +9 -0
  30. package/dist/index.cjs +2108 -1379
  31. package/dist/index.d.mts +2440 -620
  32. package/dist/index.d.ts +17 -892
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +20 -0
  35. package/dist/index.mjs +2093 -1362
  36. package/dist/plugins/api/index.d.ts +14 -0
  37. package/dist/plugins/api/index.d.ts.map +1 -0
  38. package/dist/plugins/api/index.js +21 -0
  39. package/dist/plugins/apps/index.d.ts +11 -0
  40. package/dist/plugins/apps/index.d.ts.map +1 -0
  41. package/dist/plugins/apps/index.js +91 -0
  42. package/dist/plugins/apps/types.d.ts +30 -0
  43. package/dist/plugins/apps/types.d.ts.map +1 -0
  44. package/dist/plugins/apps/types.js +2 -0
  45. package/dist/plugins/fetch/index.d.ts +21 -0
  46. package/dist/plugins/fetch/index.d.ts.map +1 -0
  47. package/dist/plugins/fetch/index.js +20 -0
  48. package/dist/plugins/findFirstAuthentication/index.d.ts +20 -0
  49. package/dist/plugins/findFirstAuthentication/index.d.ts.map +1 -0
  50. package/dist/plugins/findFirstAuthentication/index.js +24 -0
  51. package/dist/plugins/findFirstAuthentication/index.test.d.ts +2 -0
  52. package/dist/plugins/findFirstAuthentication/index.test.d.ts.map +1 -0
  53. package/dist/plugins/findFirstAuthentication/index.test.js +171 -0
  54. package/dist/plugins/findFirstAuthentication/schemas.d.ts +29 -0
  55. package/dist/plugins/findFirstAuthentication/schemas.d.ts.map +1 -0
  56. package/dist/plugins/findFirstAuthentication/schemas.js +18 -0
  57. package/dist/plugins/findUniqueAuthentication/index.d.ts +20 -0
  58. package/dist/plugins/findUniqueAuthentication/index.d.ts.map +1 -0
  59. package/dist/plugins/findUniqueAuthentication/index.js +31 -0
  60. package/dist/plugins/findUniqueAuthentication/index.test.d.ts +2 -0
  61. package/dist/plugins/findUniqueAuthentication/index.test.d.ts.map +1 -0
  62. package/dist/plugins/findUniqueAuthentication/index.test.js +152 -0
  63. package/dist/plugins/findUniqueAuthentication/schemas.d.ts +29 -0
  64. package/dist/plugins/findUniqueAuthentication/schemas.d.ts.map +1 -0
  65. package/dist/plugins/findUniqueAuthentication/schemas.js +18 -0
  66. package/dist/plugins/getAction/index.d.ts +23 -0
  67. package/dist/plugins/getAction/index.d.ts.map +1 -0
  68. package/dist/plugins/getAction/index.js +28 -0
  69. package/dist/plugins/getAction/index.test.d.ts +2 -0
  70. package/dist/plugins/getAction/index.test.d.ts.map +1 -0
  71. package/dist/plugins/getAction/index.test.js +186 -0
  72. package/dist/plugins/getAction/schemas.d.ts +23 -0
  73. package/dist/plugins/getAction/schemas.d.ts.map +1 -0
  74. package/dist/plugins/getAction/schemas.js +10 -0
  75. package/dist/plugins/getApp/index.d.ts +22 -0
  76. package/dist/plugins/getApp/index.d.ts.map +1 -0
  77. package/dist/plugins/getApp/index.js +39 -0
  78. package/dist/plugins/getApp/index.test.d.ts +2 -0
  79. package/dist/plugins/getApp/index.test.d.ts.map +1 -0
  80. package/dist/plugins/getApp/index.test.js +100 -0
  81. package/dist/plugins/getApp/schemas.d.ts +18 -0
  82. package/dist/plugins/getApp/schemas.d.ts.map +1 -0
  83. package/dist/plugins/getApp/schemas.js +10 -0
  84. package/dist/plugins/getAuthentication/index.d.ts +22 -0
  85. package/dist/plugins/getAuthentication/index.d.ts.map +1 -0
  86. package/dist/plugins/getAuthentication/index.js +41 -0
  87. package/dist/plugins/getAuthentication/index.test.d.ts +2 -0
  88. package/dist/plugins/getAuthentication/index.test.d.ts.map +1 -0
  89. package/dist/plugins/getAuthentication/index.test.js +205 -0
  90. package/dist/plugins/getAuthentication/schemas.d.ts +17 -0
  91. package/dist/plugins/getAuthentication/schemas.d.ts.map +1 -0
  92. package/dist/plugins/getAuthentication/schemas.js +11 -0
  93. package/dist/plugins/getProfile/index.d.ts +23 -0
  94. package/dist/plugins/getProfile/index.d.ts.map +1 -0
  95. package/dist/plugins/getProfile/index.js +29 -0
  96. package/dist/plugins/getProfile/schemas.d.ts +13 -0
  97. package/dist/plugins/getProfile/schemas.d.ts.map +1 -0
  98. package/dist/plugins/getProfile/schemas.js +5 -0
  99. package/dist/plugins/listActions/index.d.ts +28 -0
  100. package/dist/plugins/listActions/index.d.ts.map +1 -0
  101. package/dist/plugins/listActions/index.js +61 -0
  102. package/dist/plugins/listActions/index.test.d.ts +2 -0
  103. package/dist/plugins/listActions/index.test.d.ts.map +1 -0
  104. package/dist/plugins/listActions/index.test.js +467 -0
  105. package/dist/plugins/listActions/schemas.d.ts +29 -0
  106. package/dist/plugins/listActions/schemas.d.ts.map +1 -0
  107. package/dist/plugins/listActions/schemas.js +21 -0
  108. package/dist/plugins/listApps/index.d.ts +28 -0
  109. package/dist/plugins/listApps/index.d.ts.map +1 -0
  110. package/dist/plugins/listApps/index.js +62 -0
  111. package/dist/plugins/listApps/index.test.d.ts +2 -0
  112. package/dist/plugins/listApps/index.test.d.ts.map +1 -0
  113. package/dist/plugins/listApps/index.test.js +313 -0
  114. package/dist/plugins/listApps/schemas.d.ts +30 -0
  115. package/dist/plugins/listApps/schemas.d.ts.map +1 -0
  116. package/dist/plugins/listApps/schemas.js +23 -0
  117. package/dist/plugins/listAuthentications/index.d.ts +28 -0
  118. package/dist/plugins/listAuthentications/index.d.ts.map +1 -0
  119. package/dist/plugins/listAuthentications/index.js +77 -0
  120. package/dist/plugins/listAuthentications/index.test.d.ts +2 -0
  121. package/dist/plugins/listAuthentications/index.test.d.ts.map +1 -0
  122. package/dist/plugins/listAuthentications/index.test.js +564 -0
  123. package/dist/plugins/listAuthentications/schemas.d.ts +38 -0
  124. package/dist/plugins/listAuthentications/schemas.d.ts.map +1 -0
  125. package/dist/plugins/listAuthentications/schemas.js +28 -0
  126. package/dist/plugins/listInputFields/index.d.ts +28 -0
  127. package/dist/plugins/listInputFields/index.d.ts.map +1 -0
  128. package/dist/plugins/listInputFields/index.js +133 -0
  129. package/dist/plugins/listInputFields/index.test.d.ts +2 -0
  130. package/dist/plugins/listInputFields/index.test.d.ts.map +1 -0
  131. package/dist/plugins/listInputFields/index.test.js +325 -0
  132. package/dist/plugins/listInputFields/schemas.d.ts +38 -0
  133. package/dist/plugins/listInputFields/schemas.d.ts.map +1 -0
  134. package/dist/plugins/listInputFields/schemas.js +22 -0
  135. package/dist/plugins/registry/index.d.ts +11 -0
  136. package/dist/plugins/registry/index.d.ts.map +1 -0
  137. package/dist/plugins/registry/index.js +14 -0
  138. package/dist/plugins/request/index.d.ts +19 -0
  139. package/dist/plugins/request/index.d.ts.map +1 -0
  140. package/dist/plugins/request/index.js +62 -0
  141. package/dist/plugins/request/index.test.d.ts +2 -0
  142. package/dist/plugins/request/index.test.d.ts.map +1 -0
  143. package/dist/plugins/request/index.test.js +256 -0
  144. package/dist/plugins/request/schemas.d.ts +69 -0
  145. package/dist/plugins/request/schemas.d.ts.map +1 -0
  146. package/dist/plugins/request/schemas.js +42 -0
  147. package/dist/plugins/runAction/index.d.ts +28 -0
  148. package/dist/plugins/runAction/index.d.ts.map +1 -0
  149. package/dist/plugins/runAction/index.js +86 -0
  150. package/dist/plugins/runAction/index.test.d.ts +2 -0
  151. package/dist/plugins/runAction/index.test.d.ts.map +1 -0
  152. package/dist/plugins/runAction/index.test.js +320 -0
  153. package/dist/plugins/runAction/schemas.d.ts +37 -0
  154. package/dist/plugins/runAction/schemas.d.ts.map +1 -0
  155. package/dist/plugins/runAction/schemas.js +22 -0
  156. package/dist/resolvers/actionKey.d.ts +9 -0
  157. package/dist/resolvers/actionKey.d.ts.map +1 -0
  158. package/dist/resolvers/actionKey.js +19 -0
  159. package/dist/resolvers/actionType.d.ts +9 -0
  160. package/dist/resolvers/actionType.d.ts.map +1 -0
  161. package/dist/resolvers/actionType.js +22 -0
  162. package/dist/resolvers/appKey.d.ts +7 -0
  163. package/dist/resolvers/appKey.d.ts.map +1 -0
  164. package/dist/resolvers/appKey.js +5 -0
  165. package/dist/resolvers/authenticationId.d.ts +9 -0
  166. package/dist/resolvers/authenticationId.d.ts.map +1 -0
  167. package/dist/resolvers/authenticationId.js +33 -0
  168. package/dist/resolvers/index.d.ts +40 -0
  169. package/dist/resolvers/index.d.ts.map +1 -0
  170. package/dist/resolvers/index.js +91 -0
  171. package/dist/resolvers/inputs.d.ts +8 -0
  172. package/dist/resolvers/inputs.d.ts.map +1 -0
  173. package/dist/resolvers/inputs.js +14 -0
  174. package/dist/schemas/Action.d.ts +243 -0
  175. package/dist/schemas/Action.d.ts.map +1 -0
  176. package/dist/schemas/Action.js +34 -0
  177. package/dist/schemas/App.d.ts +26 -0
  178. package/dist/schemas/App.d.ts.map +1 -0
  179. package/dist/schemas/App.js +22 -0
  180. package/dist/schemas/Auth.d.ts +161 -0
  181. package/dist/schemas/Auth.d.ts.map +1 -0
  182. package/dist/schemas/Auth.js +41 -0
  183. package/dist/schemas/Field.d.ts +144 -0
  184. package/dist/schemas/Field.d.ts.map +1 -0
  185. package/dist/schemas/Field.js +105 -0
  186. package/dist/schemas/UserProfile.d.ts +163 -0
  187. package/dist/schemas/UserProfile.d.ts.map +1 -0
  188. package/dist/schemas/UserProfile.js +29 -0
  189. package/dist/sdk.d.ts +10 -0
  190. package/dist/sdk.d.ts.map +1 -0
  191. package/dist/sdk.js +94 -0
  192. package/dist/sdk.test.d.ts +2 -0
  193. package/dist/sdk.test.d.ts.map +1 -0
  194. package/dist/sdk.test.js +135 -0
  195. package/dist/types/domain.d.ts +36 -0
  196. package/dist/types/domain.d.ts.map +1 -0
  197. package/dist/types/domain.js +1 -0
  198. package/dist/types/domain.test.d.ts +2 -0
  199. package/dist/types/domain.test.d.ts.map +1 -0
  200. package/dist/types/domain.test.js +39 -0
  201. package/dist/types/errors.d.ts +143 -0
  202. package/dist/types/errors.d.ts.map +1 -0
  203. package/dist/types/errors.js +187 -0
  204. package/dist/types/events.d.ts +38 -0
  205. package/dist/types/events.d.ts.map +1 -0
  206. package/dist/types/events.js +7 -0
  207. package/dist/types/functions.d.ts +26 -0
  208. package/dist/types/functions.d.ts.map +1 -0
  209. package/dist/types/functions.js +4 -0
  210. package/dist/types/plugin.d.ts +61 -0
  211. package/dist/types/plugin.d.ts.map +1 -0
  212. package/dist/types/plugin.js +9 -0
  213. package/dist/types/properties.d.ts +22 -0
  214. package/dist/types/properties.d.ts.map +1 -0
  215. package/dist/types/properties.js +50 -0
  216. package/dist/types/sdk.d.ts +43 -0
  217. package/dist/types/sdk.d.ts.map +1 -0
  218. package/dist/types/sdk.js +4 -0
  219. package/dist/utils/array-utils.d.ts +31 -0
  220. package/dist/utils/array-utils.d.ts.map +1 -0
  221. package/dist/utils/array-utils.js +36 -0
  222. package/dist/utils/array-utils.test.d.ts +2 -0
  223. package/dist/utils/array-utils.test.d.ts.map +1 -0
  224. package/dist/utils/array-utils.test.js +107 -0
  225. package/dist/utils/domain-utils.d.ts +78 -0
  226. package/dist/utils/domain-utils.d.ts.map +1 -0
  227. package/dist/utils/domain-utils.js +218 -0
  228. package/dist/utils/domain-utils.test.d.ts +2 -0
  229. package/dist/utils/domain-utils.test.d.ts.map +1 -0
  230. package/dist/utils/domain-utils.test.js +192 -0
  231. package/dist/utils/function-utils.d.ts +45 -0
  232. package/dist/utils/function-utils.d.ts.map +1 -0
  233. package/dist/utils/function-utils.js +158 -0
  234. package/dist/utils/function-utils.test.d.ts +2 -0
  235. package/dist/utils/function-utils.test.d.ts.map +1 -0
  236. package/dist/utils/function-utils.test.js +110 -0
  237. package/dist/utils/pagination-utils.d.ts +37 -0
  238. package/dist/utils/pagination-utils.d.ts.map +1 -0
  239. package/dist/utils/pagination-utils.js +165 -0
  240. package/dist/utils/pagination-utils.test.d.ts +17 -0
  241. package/dist/utils/pagination-utils.test.d.ts.map +1 -0
  242. package/dist/utils/pagination-utils.test.js +461 -0
  243. package/dist/utils/schema-utils.d.ts +45 -0
  244. package/dist/utils/schema-utils.d.ts.map +1 -0
  245. package/dist/utils/schema-utils.js +65 -0
  246. package/dist/utils/validation.d.ts +4 -0
  247. package/dist/utils/validation.d.ts.map +1 -0
  248. package/dist/utils/validation.js +30 -0
  249. package/dist/utils/validation.test.d.ts +2 -0
  250. package/dist/utils/validation.test.d.ts.map +1 -0
  251. package/dist/utils/validation.test.js +43 -0
  252. package/package.json +12 -3
  253. package/src/api/client.ts +394 -171
  254. package/src/api/debug.ts +10 -1
  255. package/src/api/index.ts +0 -2
  256. package/src/api/polling.ts +28 -7
  257. package/src/api/schemas.ts +387 -0
  258. package/src/api/types.ts +72 -136
  259. package/src/constants.ts +10 -0
  260. package/src/index.ts +40 -19
  261. package/src/plugins/api/index.ts +47 -0
  262. package/src/plugins/apps/index.ts +25 -19
  263. package/src/plugins/apps/types.ts +7 -11
  264. package/src/plugins/fetch/index.ts +48 -40
  265. package/src/plugins/findFirstAuthentication/index.test.ts +206 -0
  266. package/src/plugins/findFirstAuthentication/index.ts +55 -0
  267. package/src/plugins/findFirstAuthentication/schemas.ts +41 -0
  268. package/src/plugins/findUniqueAuthentication/index.test.ts +197 -0
  269. package/src/plugins/findUniqueAuthentication/index.ts +72 -0
  270. package/src/plugins/findUniqueAuthentication/schemas.ts +42 -0
  271. package/src/plugins/getAction/index.test.ts +239 -0
  272. package/src/plugins/getAction/index.ts +57 -0
  273. package/src/plugins/getAction/schemas.ts +33 -0
  274. package/src/plugins/getApp/index.test.ts +127 -0
  275. package/src/plugins/getApp/index.ts +66 -0
  276. package/src/plugins/getApp/schemas.ts +38 -0
  277. package/src/plugins/getAuthentication/index.test.ts +284 -0
  278. package/src/plugins/getAuthentication/index.ts +86 -0
  279. package/src/plugins/getAuthentication/schemas.ts +31 -0
  280. package/src/plugins/getProfile/index.ts +55 -0
  281. package/src/plugins/getProfile/schemas.ts +26 -0
  282. package/src/plugins/listActions/index.test.ts +582 -0
  283. package/src/plugins/listActions/index.ts +115 -0
  284. package/src/plugins/listActions/schemas.ts +54 -0
  285. package/src/plugins/listApps/index.test.ts +357 -0
  286. package/src/plugins/listApps/index.ts +121 -0
  287. package/src/plugins/listApps/schemas.ts +49 -0
  288. package/src/plugins/listAuthentications/index.test.ts +709 -0
  289. package/src/plugins/listAuthentications/index.ts +136 -0
  290. package/src/plugins/listAuthentications/schemas.ts +60 -0
  291. package/src/plugins/listInputFields/index.test.ts +408 -0
  292. package/src/plugins/listInputFields/index.ts +204 -0
  293. package/src/plugins/listInputFields/schemas.ts +56 -0
  294. package/src/plugins/registry/index.ts +30 -0
  295. package/src/plugins/request/index.test.ts +329 -0
  296. package/src/plugins/request/index.ts +103 -0
  297. package/src/{functions → plugins}/request/schemas.ts +20 -9
  298. package/src/plugins/runAction/index.test.ts +387 -0
  299. package/src/plugins/runAction/index.ts +176 -0
  300. package/src/plugins/runAction/schemas.ts +53 -0
  301. package/src/resolvers/actionKey.ts +6 -4
  302. package/src/resolvers/actionType.ts +7 -2
  303. package/src/resolvers/appKey.ts +1 -1
  304. package/src/resolvers/authenticationId.ts +12 -3
  305. package/src/resolvers/inputs.ts +3 -1
  306. package/src/schemas/Action.ts +18 -12
  307. package/src/schemas/App.ts +11 -19
  308. package/src/schemas/Auth.ts +18 -13
  309. package/src/schemas/Field.ts +106 -11
  310. package/src/schemas/UserProfile.ts +43 -0
  311. package/src/sdk.test.ts +212 -0
  312. package/src/sdk.ts +132 -102
  313. package/src/types/domain.test.ts +50 -0
  314. package/src/types/domain.ts +43 -75
  315. package/src/types/errors.ts +275 -0
  316. package/src/types/functions.ts +27 -0
  317. package/src/types/optional-zapier-sdk-cli-login.d.ts +37 -0
  318. package/src/types/plugin.ts +105 -0
  319. package/src/types/properties.ts +4 -3
  320. package/src/types/sdk.ts +70 -48
  321. package/src/utils/array-utils.test.ts +131 -0
  322. package/src/utils/array-utils.ts +41 -0
  323. package/src/utils/domain-utils.test.ts +239 -0
  324. package/src/utils/domain-utils.ts +283 -0
  325. package/src/utils/function-utils.test.ts +141 -0
  326. package/src/utils/function-utils.ts +245 -0
  327. package/src/utils/pagination-utils.test.ts +620 -0
  328. package/src/utils/pagination-utils.ts +242 -0
  329. package/src/utils/validation.test.ts +50 -0
  330. package/src/utils/validation.ts +44 -0
  331. package/tsconfig.build.json +16 -2
  332. package/tsconfig.json +3 -1
  333. package/tsconfig.tsbuildinfo +1 -0
  334. package/tsup.config.ts +2 -0
  335. package/src/functions/bundleCode/index.ts +0 -78
  336. package/src/functions/bundleCode/info.ts +0 -9
  337. package/src/functions/bundleCode/schemas.ts +0 -30
  338. package/src/functions/findFirstAuthentication/index.ts +0 -24
  339. package/src/functions/findFirstAuthentication/info.ts +0 -9
  340. package/src/functions/findFirstAuthentication/schemas.ts +0 -50
  341. package/src/functions/findUniqueAuthentication/index.ts +0 -35
  342. package/src/functions/findUniqueAuthentication/info.ts +0 -9
  343. package/src/functions/findUniqueAuthentication/schemas.ts +0 -50
  344. package/src/functions/generateTypes/index.ts +0 -363
  345. package/src/functions/generateTypes/info.ts +0 -9
  346. package/src/functions/generateTypes/schemas.ts +0 -31
  347. package/src/functions/getAction/index.ts +0 -33
  348. package/src/functions/getAction/info.ts +0 -9
  349. package/src/functions/getAction/schemas.ts +0 -25
  350. package/src/functions/getApp/index.ts +0 -41
  351. package/src/functions/getApp/info.ts +0 -9
  352. package/src/functions/getApp/schemas.ts +0 -20
  353. package/src/functions/getAuthentication/index.ts +0 -50
  354. package/src/functions/getAuthentication/info.ts +0 -9
  355. package/src/functions/getAuthentication/schemas.ts +0 -29
  356. package/src/functions/listActions/index.ts +0 -149
  357. package/src/functions/listActions/info.ts +0 -9
  358. package/src/functions/listActions/schemas.ts +0 -30
  359. package/src/functions/listApps/index.ts +0 -60
  360. package/src/functions/listApps/info.ts +0 -9
  361. package/src/functions/listApps/schemas.ts +0 -32
  362. package/src/functions/listAuthentications/index.ts +0 -162
  363. package/src/functions/listAuthentications/info.ts +0 -9
  364. package/src/functions/listAuthentications/schemas.ts +0 -50
  365. package/src/functions/listFields/index.ts +0 -86
  366. package/src/functions/listFields/info.ts +0 -9
  367. package/src/functions/listFields/schemas.ts +0 -36
  368. package/src/functions/request/index.ts +0 -150
  369. package/src/functions/request/info.ts +0 -11
  370. package/src/functions/runAction/index.ts +0 -127
  371. package/src/functions/runAction/info.ts +0 -9
  372. package/src/functions/runAction/schemas.ts +0 -34
  373. package/src/plugins/apps/info.ts +0 -12
  374. package/src/plugins/fetch/types.ts +0 -2
  375. /package/src/{schema-utils.ts → utils/schema-utils.ts} +0 -0
@@ -0,0 +1,461 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { paginate, paginateMaxItems } from "./pagination-utils";
3
+ // Test data set - simulating a large dataset with cursor-based pagination
4
+ export const ALL_ITEMS = Array.from({ length: 25 }, (_, i) => ({
5
+ id: i + 1,
6
+ name: `Item ${i + 1}`,
7
+ }));
8
+ // Test page function that implements cursor-based pagination logic
9
+ export async function listTestItems(options) {
10
+ const { pageSize = 5, cursor, filter, maxItems } = options;
11
+ // Cap pageSize at 10 to simulate real API limits
12
+ let actualPageSize = Math.min(pageSize, 10);
13
+ // If maxItems hint is provided, further limit the page size for optimization
14
+ if (maxItems !== undefined && maxItems > 0) {
15
+ actualPageSize = Math.min(actualPageSize, maxItems);
16
+ }
17
+ // Filter items if filter is provided
18
+ let items = ALL_ITEMS;
19
+ if (filter) {
20
+ items = items.filter((item) => item.name.toLowerCase().includes(filter.toLowerCase()));
21
+ }
22
+ // Find starting position based on cursor
23
+ let startIndex = 0;
24
+ if (cursor) {
25
+ // Cursor format: "cursor-{itemId}"
26
+ const cursorId = parseInt(cursor.replace("cursor-", ""));
27
+ startIndex = items.findIndex((item) => item.id > cursorId);
28
+ if (startIndex === -1) {
29
+ // No more items after cursor
30
+ return { data: [], nextCursor: undefined };
31
+ }
32
+ }
33
+ // Get page of items
34
+ const pageItems = items.slice(startIndex, startIndex + actualPageSize);
35
+ // Determine next cursor
36
+ let nextCursor;
37
+ if (startIndex + actualPageSize < items.length && pageItems.length > 0) {
38
+ const lastItem = pageItems[pageItems.length - 1];
39
+ nextCursor = `cursor-${lastItem.id}`;
40
+ }
41
+ return {
42
+ data: pageItems,
43
+ nextCursor,
44
+ };
45
+ }
46
+ describe("paginate", () => {
47
+ it("should paginate through multiple pages", async () => {
48
+ const pageIterator = paginate(listTestItems, { pageSize: 3 });
49
+ const pages = [];
50
+ for await (const page of pageIterator) {
51
+ pages.push(page);
52
+ }
53
+ // With 25 items and pageSize 3, should have 9 pages (8 full + 1 partial)
54
+ expect(pages).toHaveLength(9);
55
+ // Check first page
56
+ expect(pages[0]).toEqual({
57
+ data: ALL_ITEMS.slice(0, 3),
58
+ nextCursor: "cursor-3",
59
+ });
60
+ // Check second page (cursor should be passed correctly)
61
+ expect(pages[1]).toEqual({
62
+ data: ALL_ITEMS.slice(3, 6),
63
+ nextCursor: "cursor-6",
64
+ });
65
+ // Check last page (should have no nextCursor)
66
+ expect(pages[8]).toEqual({
67
+ data: ALL_ITEMS.slice(24, 25),
68
+ nextCursor: undefined,
69
+ });
70
+ // Verify we got all 25 items across all pages
71
+ const allItems = pages.flatMap((page) => page.data);
72
+ expect(allItems).toHaveLength(25);
73
+ });
74
+ it("should cap pageSize at 10 when unbuffered", async () => {
75
+ // Use a page size larger than 10, should get capped
76
+ const pageIterator = paginateMaxItems(listTestItems, { pageSize: 50 });
77
+ const pages = [];
78
+ for await (const page of pageIterator) {
79
+ pages.push(page);
80
+ }
81
+ // Should get 3 pages: 10+10+5=25 (pageSize capped at 10)
82
+ expect(pages).toHaveLength(3);
83
+ expect(pages[0].data).toHaveLength(10); // First page capped at 10
84
+ expect(pages[1].data).toHaveLength(10); // Second page capped at 10
85
+ expect(pages[2].data).toHaveLength(5); // Last page has remaining 5
86
+ expect(pages[2].nextCursor).toBeUndefined(); // Last page has no nextCursor
87
+ });
88
+ it("should not cap pageSize when buffered", async () => {
89
+ const pageIterator = paginate(listTestItems, { pageSize: 50 });
90
+ for await (const page of pageIterator) {
91
+ expect(page.data).toHaveLength(25);
92
+ break;
93
+ }
94
+ });
95
+ it("should not cap pageSize when buffered", async () => {
96
+ const pageIterator = paginate(listTestItems, { pageSize: 15 });
97
+ const pages = [];
98
+ for await (const page of pageIterator) {
99
+ pages.push(page);
100
+ }
101
+ expect(pages).toHaveLength(2);
102
+ expect(pages[0].data).toHaveLength(15);
103
+ expect(pages[1].data).toHaveLength(10);
104
+ });
105
+ it("should continue from pseudo cursor", async () => {
106
+ const pageIterator = paginate(listTestItems, { pageSize: 15 });
107
+ const pages = [];
108
+ for await (const page of pageIterator) {
109
+ pages.push(page);
110
+ break;
111
+ }
112
+ const nextPageIterator = paginate(listTestItems, {
113
+ pageSize: 15,
114
+ cursor: pages[0].nextCursor,
115
+ });
116
+ for await (const page of nextPageIterator) {
117
+ pages.push(page);
118
+ }
119
+ expect(pages).toHaveLength(2);
120
+ expect(pages[0].data).toHaveLength(15);
121
+ expect(pages[1].data).toHaveLength(10);
122
+ });
123
+ it("should handle filtered results", async () => {
124
+ // Filter for items containing "1" (should match Item 1, Item 10-19, Item 21)
125
+ const pageIterator = paginate(listTestItems, {
126
+ pageSize: 4,
127
+ filter: "1",
128
+ });
129
+ const pages = [];
130
+ for await (const page of pageIterator) {
131
+ pages.push(page);
132
+ }
133
+ // Should have multiple pages due to pageSize: 4
134
+ expect(pages.length).toBeGreaterThan(1);
135
+ // All items should contain "1"
136
+ const allItems = pages.flatMap((page) => page.data);
137
+ expect(allItems.every((item) => item.name.includes("1"))).toBe(true);
138
+ // Should include items like Item 1, Item 10, Item 11, etc.
139
+ expect(allItems).toContainEqual(ALL_ITEMS[0]); // Item 1
140
+ expect(allItems).toContainEqual(ALL_ITEMS[9]); // Item 10
141
+ expect(allItems).toContainEqual(ALL_ITEMS[20]); // Item 21
142
+ });
143
+ it("should handle empty results", async () => {
144
+ // Filter that matches no items
145
+ const pageIterator = paginate(listTestItems, {
146
+ pageSize: 10,
147
+ filter: "nonexistent",
148
+ });
149
+ const pages = [];
150
+ for await (const page of pageIterator) {
151
+ pages.push(page);
152
+ }
153
+ expect(pages).toHaveLength(1);
154
+ expect(pages[0]).toEqual({
155
+ data: [],
156
+ nextCursor: undefined,
157
+ });
158
+ });
159
+ it("should pass through errors from the page function", async () => {
160
+ // Create a page function that throws an error
161
+ const errorPageFunction = async () => {
162
+ throw new Error("Page function failed");
163
+ };
164
+ const pageIterator = paginate(errorPageFunction, {});
165
+ let reachedUnreachableCode = undefined;
166
+ await expect(async () => {
167
+ for await (const page of pageIterator) {
168
+ // Should never reach here due to error
169
+ reachedUnreachableCode = page;
170
+ }
171
+ }).rejects.toThrow("Page function failed");
172
+ // Verify we never reached the unreachable code
173
+ expect(reachedUnreachableCode).toBeUndefined();
174
+ });
175
+ it("should start pagination from provided cursor", async () => {
176
+ // Test that pagination can start from a specific cursor position
177
+ const pageIterator = paginate(listTestItems, {
178
+ pageSize: 3,
179
+ cursor: "cursor-5", // Start after item 5
180
+ });
181
+ const pages = [];
182
+ for await (const page of pageIterator) {
183
+ pages.push(page);
184
+ if (pages.length >= 2)
185
+ break; // Just test first 2 pages
186
+ }
187
+ expect(pages).toHaveLength(2);
188
+ // First page should start after cursor-5 (from item 6)
189
+ expect(pages[0].data[0]).toEqual(ALL_ITEMS[5]); // Item 6
190
+ // Second page should continue properly
191
+ expect(pages[1].data[0]).toEqual(ALL_ITEMS[8]); // Item 9
192
+ });
193
+ it("should allow breaking out of pagination early", async () => {
194
+ // Test that users can break out of the iterator manually
195
+ const pageIterator = paginate(listTestItems, { pageSize: 3 });
196
+ const pages = [];
197
+ for await (const page of pageIterator) {
198
+ pages.push(page);
199
+ // Break after getting 3 pages
200
+ if (pages.length >= 3) {
201
+ break;
202
+ }
203
+ }
204
+ // Should have stopped at exactly 3 pages with 9 items (3+3+3=9)
205
+ const allItems = pages.flatMap((page) => page.data);
206
+ expect(allItems).toHaveLength(9);
207
+ expect(pages).toHaveLength(3);
208
+ // Should be first 9 items
209
+ expect(allItems).toEqual(ALL_ITEMS.slice(0, 9));
210
+ });
211
+ describe("conditional types for optional options", () => {
212
+ it("should work with function that takes no options", async () => {
213
+ async function fetchWithNoOptions(_options) {
214
+ return { data: [1, 2, 3] };
215
+ }
216
+ const pages = [];
217
+ for await (const page of paginate(fetchWithNoOptions)) {
218
+ pages.push(...page.data);
219
+ }
220
+ expect(pages).toEqual([1, 2, 3]);
221
+ });
222
+ it("should work with function that takes optional options", async () => {
223
+ async function fetchWithOptionalOptions(options) {
224
+ return { data: [`page-${options?.cursor || "1"}`] };
225
+ }
226
+ const pages = [];
227
+ for await (const page of paginate(fetchWithOptionalOptions, {
228
+ limit: 5,
229
+ })) {
230
+ pages.push(...page.data);
231
+ }
232
+ expect(pages).toEqual(["page-1"]);
233
+ });
234
+ it("should work with function that takes only cursor", async () => {
235
+ async function fetchWithOnlyCursor(_options) {
236
+ return { data: [true] };
237
+ }
238
+ const pages = [];
239
+ for await (const page of paginate(fetchWithOnlyCursor, {
240
+ cursor: "start",
241
+ })) {
242
+ pages.push(...page.data);
243
+ }
244
+ expect(pages).toEqual([true]);
245
+ });
246
+ it("should work when baseOptions is omitted entirely", async () => {
247
+ async function fetchSimple(_options) {
248
+ return { data: ["simple"] };
249
+ }
250
+ const pages = [];
251
+ for await (const page of paginate(fetchSimple)) {
252
+ pages.push(...page.data);
253
+ }
254
+ expect(pages).toEqual(["simple"]);
255
+ });
256
+ });
257
+ describe("maxItems functionality", () => {
258
+ it("should limit total items across pages", async () => {
259
+ const items = [];
260
+ for await (const page of paginate(listTestItems, {
261
+ pageSize: 3,
262
+ maxItems: 7,
263
+ })) {
264
+ items.push(...page.data);
265
+ }
266
+ expect(items).toHaveLength(7);
267
+ expect(items).toEqual(ALL_ITEMS.slice(0, 7));
268
+ });
269
+ it("should truncate the final page when maxItems is exceeded", async () => {
270
+ // Create a function that ignores maxItems hint to force truncation
271
+ async function fetchIgnoringMaxItems(options) {
272
+ return listTestItems({
273
+ pageSize: options.pageSize,
274
+ cursor: options.cursor,
275
+ });
276
+ }
277
+ const pageData = [];
278
+ for await (const page of paginate(fetchIgnoringMaxItems, {
279
+ pageSize: 3,
280
+ maxItems: 7,
281
+ })) {
282
+ pageData.push(page);
283
+ }
284
+ // Should have 3 pages: [3 items], [3 items], [1 item (truncated)]
285
+ expect(pageData).toHaveLength(3);
286
+ expect(pageData[0].data).toHaveLength(3);
287
+ expect(pageData[1].data).toHaveLength(3);
288
+ expect(pageData[2].data).toHaveLength(1); // Truncated page
289
+ expect(pageData[2].nextCursor).toBeUndefined(); // Should clear cursor
290
+ });
291
+ it("should stop early when maxItems is exactly a page boundary", async () => {
292
+ const items = [];
293
+ for await (const page of paginate(listTestItems, {
294
+ pageSize: 3,
295
+ maxItems: 6,
296
+ })) {
297
+ items.push(...page.data);
298
+ }
299
+ expect(items).toHaveLength(6);
300
+ expect(items).toEqual(ALL_ITEMS.slice(0, 6));
301
+ });
302
+ it("should handle maxItems of 0", async () => {
303
+ const items = [];
304
+ for await (const page of paginate(listTestItems, {
305
+ pageSize: 3,
306
+ maxItems: 0,
307
+ })) {
308
+ items.push(...page.data);
309
+ }
310
+ expect(items).toHaveLength(0);
311
+ });
312
+ it("should work normally when maxItems is larger than total items", async () => {
313
+ const items = [];
314
+ for await (const page of paginate(listTestItems, {
315
+ pageSize: 3,
316
+ maxItems: 100,
317
+ })) {
318
+ items.push(...page.data);
319
+ }
320
+ // Should get all items since limit is higher than total
321
+ expect(items).toEqual(ALL_ITEMS);
322
+ });
323
+ it("should work with maxItems and other options combined", async () => {
324
+ async function fetchWithLimit(options) {
325
+ const start = parseInt(options.cursor || "0");
326
+ let limit = options.limit;
327
+ // Apply maxItems hint for optimization
328
+ if (options.maxItems !== undefined && options.maxItems > 0) {
329
+ limit = Math.min(limit, options.maxItems);
330
+ }
331
+ const items = ALL_ITEMS.slice(start, start + limit);
332
+ const nextCursor = start + limit < ALL_ITEMS.length
333
+ ? (start + limit).toString()
334
+ : undefined;
335
+ return { data: items, nextCursor };
336
+ }
337
+ const items = [];
338
+ for await (const page of paginate(fetchWithLimit, {
339
+ limit: 2,
340
+ maxItems: 5,
341
+ })) {
342
+ items.push(...page.data);
343
+ }
344
+ expect(items).toHaveLength(5);
345
+ expect(items).toEqual(ALL_ITEMS.slice(0, 5));
346
+ });
347
+ it("should preserve original page structure except for truncation", async () => {
348
+ // Create a function that ignores maxItems hint to force truncation
349
+ async function fetchIgnoringMaxItems(options) {
350
+ const pageSize = options.pageSize || 3;
351
+ const start = options.cursor
352
+ ? parseInt(options.cursor.replace("cursor-", "")) + 1
353
+ : 0;
354
+ const items = ALL_ITEMS.slice(start, start + pageSize);
355
+ const nextCursor = start + pageSize <= ALL_ITEMS.length
356
+ ? `cursor-${ALL_ITEMS[start + pageSize - 1].id}`
357
+ : undefined;
358
+ return { data: items, nextCursor };
359
+ }
360
+ let pageCount = 0;
361
+ for await (const page of paginate(fetchIgnoringMaxItems, {
362
+ pageSize: 3,
363
+ maxItems: 7,
364
+ })) {
365
+ pageCount++;
366
+ // All pages should have the expected structure
367
+ expect(page).toHaveProperty("data");
368
+ expect(Array.isArray(page.data)).toBe(true);
369
+ if (pageCount === 3) {
370
+ // Final truncated page
371
+ expect(page.data).toHaveLength(1);
372
+ expect(page.nextCursor).toBeUndefined();
373
+ }
374
+ else {
375
+ // Regular pages
376
+ expect(page.data).toHaveLength(3);
377
+ expect(typeof page.nextCursor).toBe("string");
378
+ }
379
+ }
380
+ expect(pageCount).toBe(3);
381
+ });
382
+ it("should handle API that ignores pageSize and returns more items on first page", async () => {
383
+ // Simulate an API that ignores pageSize and always returns 10 items per page
384
+ async function apiIgnoresPageSize(options) {
385
+ return listTestItems({
386
+ cursor: options.cursor,
387
+ pageSize: 10,
388
+ });
389
+ }
390
+ const pages = [];
391
+ // User requests pageSize: 3, but API returns 10 per page
392
+ for await (const page of paginate(apiIgnoresPageSize, {
393
+ pageSize: 3,
394
+ })) {
395
+ pages.push(page);
396
+ // Only get first page to test the behavior
397
+ break;
398
+ }
399
+ // Should get 1 page with only 3 items (paginate enforces pageSize limit)
400
+ expect(pages).toHaveLength(1);
401
+ expect(pages[0].data).toHaveLength(3);
402
+ expect(pages[0].data).toEqual(ALL_ITEMS.slice(0, 3));
403
+ // Cursor should still be present since there are more items available
404
+ expect(pages[0].nextCursor).toBeDefined();
405
+ });
406
+ it("should truncate oversized API response to pageSize", async () => {
407
+ // API always returns 10 items, but user wants pageSize: 3
408
+ async function apiReturns10Items(options) {
409
+ return listTestItems({
410
+ cursor: options.cursor,
411
+ pageSize: 10,
412
+ });
413
+ }
414
+ const pages = [];
415
+ for await (const page of paginate(apiReturns10Items, {
416
+ pageSize: 3,
417
+ })) {
418
+ pages.push(page);
419
+ }
420
+ // Should truncate each 10-item API response to 3 items per page
421
+ expect(pages).toHaveLength(9);
422
+ expect(pages[0].data).toHaveLength(3);
423
+ expect(pages[1].data).toHaveLength(3);
424
+ expect(pages[8].data).toHaveLength(1);
425
+ // Verify items are from different API calls
426
+ expect(pages[0].data).toEqual(ALL_ITEMS.slice(0, 3)); // Items 1-3 from first API call
427
+ expect(pages[1].data).toEqual(ALL_ITEMS.slice(3, 6)); // Items 11-13 from second API call
428
+ expect(pages[8].data).toEqual(ALL_ITEMS.slice(24, 25)); // Items 21-23 from third API call
429
+ // All pages should have nextCursor since API has more data
430
+ expect(pages[0].nextCursor).toBe('["$$offset$$",3,null]');
431
+ expect(pages[8].nextCursor).toBeUndefined();
432
+ });
433
+ it("should handle pageSize enforcement with maxItems limit", async () => {
434
+ // API returns 10 items, user wants pageSize: 3, maxItems: 7
435
+ async function apiReturns10Items(options) {
436
+ return listTestItems({
437
+ cursor: options.cursor,
438
+ pageSize: 10,
439
+ });
440
+ }
441
+ const pages = [];
442
+ for await (const page of paginate(apiReturns10Items, {
443
+ pageSize: 3,
444
+ maxItems: 7,
445
+ })) {
446
+ pages.push(page);
447
+ }
448
+ // Should get: [3, 3, 1] items (total 7, respecting maxItems)
449
+ expect(pages).toHaveLength(3);
450
+ expect(pages[0].data).toHaveLength(3);
451
+ expect(pages[1].data).toHaveLength(3);
452
+ expect(pages[2].data).toHaveLength(1); // Truncated to respect maxItems
453
+ // Last page should have no nextCursor (maxItems reached)
454
+ expect(pages[2].nextCursor).toBeUndefined();
455
+ // Verify total items
456
+ const allItems = pages.flatMap((p) => p.data);
457
+ expect(allItems).toHaveLength(7);
458
+ expect(allItems).toEqual(ALL_ITEMS.slice(0, 7));
459
+ });
460
+ });
461
+ });
@@ -0,0 +1,45 @@
1
+ import { z } from "zod";
2
+ export interface FormattedItem {
3
+ title: string;
4
+ subtitle?: string;
5
+ details: Array<{
6
+ text: string;
7
+ style: "normal" | "dim" | "accent" | "warning" | "success";
8
+ }>;
9
+ }
10
+ export interface FormatMetadata {
11
+ format: (item: any) => FormattedItem;
12
+ }
13
+ export declare function withFormatter<T extends z.ZodType>(schema: T, formatMeta: FormatMetadata): T;
14
+ export declare function getFormatMetadata(schema: z.ZodType): FormatMetadata | undefined;
15
+ export declare function withOutputSchema<T extends z.ZodType>(inputSchema: T, outputSchema: z.ZodType): T;
16
+ export declare function getOutputSchema(inputSchema: z.ZodType): z.ZodType | undefined;
17
+ export interface StaticResolver {
18
+ type: "static";
19
+ inputType?: "text" | "password" | "email";
20
+ placeholder?: string;
21
+ }
22
+ export interface DynamicResolver {
23
+ type: "dynamic";
24
+ fetch: (sdk: any, resolvedParams: any) => Promise<any[]>;
25
+ prompt: (items: any[], params: any) => any;
26
+ depends?: string[];
27
+ }
28
+ export interface FieldsResolver {
29
+ type: "fields";
30
+ fetch: (sdk: any, resolvedParams: any) => Promise<any[]>;
31
+ depends?: string[];
32
+ }
33
+ export type ResolverMetadata = StaticResolver | DynamicResolver | FieldsResolver;
34
+ export interface ResolverConfig {
35
+ resolver: ResolverMetadata;
36
+ }
37
+ export declare function withResolver<T extends z.ZodType>(schema: T, config: ResolverConfig): T;
38
+ export declare function getSchemaDescription(schema: z.ZodSchema): string | undefined;
39
+ export declare function getFieldDescriptions(schema: z.ZodObject<any>): Record<string, string>;
40
+ export interface PositionalMetadata {
41
+ positional: true;
42
+ }
43
+ export declare function withPositional<T extends z.ZodType>(schema: T): T;
44
+ export declare function isPositional(schema: z.ZodType): boolean;
45
+ //# sourceMappingURL=schema-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-utils.d.ts","sourceRoot":"","sources":["../../src/utils/schema-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,KAAK,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,QAAQ,GAAG,KAAK,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;KAC5D,CAAC,CAAC;CACJ;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,aAAa,CAAC;CACtC;AAGD,wBAAgB,aAAa,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAC/C,MAAM,EAAE,CAAC,EACT,UAAU,EAAE,cAAc,GACzB,CAAC,CAIH;AAGD,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,CAAC,CAAC,OAAO,GAChB,cAAc,GAAG,SAAS,CAE5B;AAGD,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAClD,WAAW,EAAE,CAAC,EACd,YAAY,EAAE,CAAC,CAAC,OAAO,GACtB,CAAC,CAIH;AAGD,wBAAgB,eAAe,CAAC,WAAW,EAAE,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,GAAG,SAAS,CAE7E;AAMD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,QAAQ,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACzD,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;IAC3C,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACzD,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,MAAM,gBAAgB,GACxB,cAAc,GACd,eAAe,GACf,cAAc,CAAC;AAGnB,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,gBAAgB,CAAC;CAI5B;AAGD,wBAAgB,YAAY,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAC9C,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,cAAc,GACrB,CAAC,CAIH;AAMD,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,CAAC,CAAC,SAAS,GAAG,MAAM,GAAG,SAAS,CAE5E;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GACvB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAWxB;AAMD,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,IAAI,CAAC;CAClB;AAGD,wBAAgB,cAAc,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAIhE;AAGD,wBAAgB,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,GAAG,OAAO,CAiBvD"}
@@ -0,0 +1,65 @@
1
+ import { z } from "zod";
2
+ // Helper function to add format metadata to schemas
3
+ export function withFormatter(schema, formatMeta) {
4
+ // Store format metadata on the schema definition
5
+ schema._def.formatMeta = formatMeta;
6
+ return schema;
7
+ }
8
+ // Helper function to get format metadata from a schema
9
+ export function getFormatMetadata(schema) {
10
+ return schema._def.formatMeta;
11
+ }
12
+ // Helper function to link input schemas to output schemas
13
+ export function withOutputSchema(inputSchema, outputSchema) {
14
+ // Store output schema reference on the input schema
15
+ inputSchema._def.outputSchema = outputSchema;
16
+ return inputSchema;
17
+ }
18
+ // Helper function to get output schema from an input schema
19
+ export function getOutputSchema(inputSchema) {
20
+ return inputSchema._def.outputSchema;
21
+ }
22
+ // Helper function to add resolver metadata to schemas
23
+ export function withResolver(schema, config) {
24
+ // Store resolver metadata on the schema definition
25
+ schema._def.resolverMeta = config;
26
+ return schema;
27
+ }
28
+ // ============================================================================
29
+ // Schema Description Utilities
30
+ // ============================================================================
31
+ export function getSchemaDescription(schema) {
32
+ return schema.description;
33
+ }
34
+ export function getFieldDescriptions(schema) {
35
+ const descriptions = {};
36
+ const shape = schema.shape;
37
+ for (const [key, fieldSchema] of Object.entries(shape)) {
38
+ if (fieldSchema instanceof z.ZodType && fieldSchema.description) {
39
+ descriptions[key] = fieldSchema.description;
40
+ }
41
+ }
42
+ return descriptions;
43
+ }
44
+ // Helper function to mark a parameter as positional for CLI
45
+ export function withPositional(schema) {
46
+ // Store positional metadata on the schema definition
47
+ schema._def.positionalMeta = { positional: true };
48
+ return schema;
49
+ }
50
+ // Helper function to check if a parameter should be positional
51
+ export function isPositional(schema) {
52
+ // Check the current schema first
53
+ if (schema._def.positionalMeta?.positional) {
54
+ return true;
55
+ }
56
+ // If this is a ZodOptional, check the inner type
57
+ if (schema instanceof z.ZodOptional) {
58
+ return isPositional(schema._def.innerType);
59
+ }
60
+ // If this is a ZodDefault, check the inner type
61
+ if (schema instanceof z.ZodDefault) {
62
+ return isPositional(schema._def.innerType);
63
+ }
64
+ return false;
65
+ }
@@ -0,0 +1,4 @@
1
+ import { z } from "zod";
2
+ export declare function createValidator<TSchema extends z.ZodSchema>(schema: TSchema): (input: unknown) => z.infer<TSchema>;
3
+ export declare const validateOptions: <TOptions, TSchemaOptions extends TOptions>(schema: z.ZodSchema<TSchemaOptions>, options: TOptions) => any;
4
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAgCxB,wBAAgB,eAAe,CAAC,OAAO,SAAS,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,IAC/C,OAAO,OAAO,KAAG,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAG7D;AAED,eAAO,MAAM,eAAe,GAAI,QAAQ,EAAE,cAAc,SAAS,QAAQ,EACvE,QAAQ,CAAC,CAAC,SAAS,CAAC,cAAc,CAAC,EACnC,SAAS,QAAQ,QAGlB,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { ZapierValidationError } from "../types/errors";
2
+ /**
3
+ * Throws clean ZapierValidationError on validation failures
4
+ */
5
+ const validate = (schema, input) => {
6
+ const result = schema.safeParse(input);
7
+ if (!result.success) {
8
+ // Format Zod errors into a clean, user-friendly message
9
+ const errorMessages = result.error.errors.map((error) => {
10
+ const path = error.path.length > 0 ? error.path.join(".") : "input";
11
+ return `${path}: ${error.message}`;
12
+ });
13
+ const message = `Validation failed:\n ${errorMessages.join("\n ")}`;
14
+ throw new ZapierValidationError(message, {
15
+ details: {
16
+ zodErrors: result.error.errors,
17
+ input,
18
+ },
19
+ });
20
+ }
21
+ return result.data;
22
+ };
23
+ export function createValidator(schema) {
24
+ return function validateFn(input) {
25
+ return validate(schema, input);
26
+ };
27
+ }
28
+ export const validateOptions = (schema, options) => {
29
+ return validate(schema, options);
30
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=validation.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.test.d.ts","sourceRoot":"","sources":["../../src/utils/validation.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,43 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { z } from "zod";
3
+ import { createValidator } from "./validation";
4
+ import { ZapierValidationError } from "../types/errors";
5
+ describe("validation utilities", () => {
6
+ describe("createValidator", () => {
7
+ it("should validate valid input", () => {
8
+ const schema = z.object({
9
+ name: z.string(),
10
+ age: z.number(),
11
+ });
12
+ const validator = createValidator(schema);
13
+ const result = validator({ name: "John", age: 30 });
14
+ expect(result).toEqual({ name: "John", age: 30 });
15
+ });
16
+ it("should throw ZapierValidationError for invalid input", () => {
17
+ const schema = z.object({
18
+ name: z.string(),
19
+ age: z.number(),
20
+ });
21
+ const validator = createValidator(schema);
22
+ expect(() => {
23
+ validator({ name: "John", age: "not-a-number" });
24
+ }).toThrow(ZapierValidationError);
25
+ });
26
+ it("should include helpful error messages", () => {
27
+ const schema = z.object({
28
+ name: z.string(),
29
+ age: z.number().min(0),
30
+ });
31
+ const validator = createValidator(schema);
32
+ try {
33
+ validator({ name: 123, age: -5 });
34
+ }
35
+ catch (error) {
36
+ expect(error).toBeInstanceOf(ZapierValidationError);
37
+ expect(error.message).toContain("name:");
38
+ expect(error.message).toContain("age:");
39
+ expect(error.details.zodErrors).toBeDefined();
40
+ }
41
+ });
42
+ });
43
+ });