@flintpay/node 0.2.0-beta.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 (1012) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +43 -0
  3. package/REFERENCE.md +5967 -0
  4. package/canonical.d.ts +1 -0
  5. package/canonical.js +4 -0
  6. package/codec-plan.d.ts +77 -0
  7. package/codec-plan.js +369 -0
  8. package/contract.d.ts +225 -0
  9. package/diagnostic.d.ts +4 -0
  10. package/diagnostic.js +9 -0
  11. package/examples/api-addOrderCharge.mjs +16 -0
  12. package/examples/api-addOrderCharge.ts +16 -0
  13. package/examples/api-addOrderLineItems.mjs +13 -0
  14. package/examples/api-addOrderLineItems.ts +13 -0
  15. package/examples/api-addReturnLineItem.mjs +13 -0
  16. package/examples/api-addReturnLineItem.ts +13 -0
  17. package/examples/api-addRiskListItems.mjs +11 -0
  18. package/examples/api-addRiskListItems.ts +11 -0
  19. package/examples/api-advanceOnboarding.mjs +6 -0
  20. package/examples/api-advanceOnboarding.ts +6 -0
  21. package/examples/api-applyInventoryCount.mjs +8 -0
  22. package/examples/api-applyInventoryCount.ts +8 -0
  23. package/examples/api-applyOrderDiscount.mjs +11 -0
  24. package/examples/api-applyOrderDiscount.ts +11 -0
  25. package/examples/api-approveReview.mjs +6 -0
  26. package/examples/api-approveReview.ts +6 -0
  27. package/examples/api-assignToUnconfiguredDeliveryProfile.mjs +7 -0
  28. package/examples/api-assignToUnconfiguredDeliveryProfile.ts +7 -0
  29. package/examples/api-authorizePartnerInstall.mjs +10 -0
  30. package/examples/api-authorizePartnerInstall.ts +10 -0
  31. package/examples/api-cancelInventoryCount.mjs +8 -0
  32. package/examples/api-cancelInventoryCount.ts +8 -0
  33. package/examples/api-cancelInvoicePaymentAttempt.mjs +7 -0
  34. package/examples/api-cancelInvoicePaymentAttempt.ts +7 -0
  35. package/examples/api-cancelMeReturn.mjs +9 -0
  36. package/examples/api-cancelMeReturn.ts +9 -0
  37. package/examples/api-cancelMeSubscription.mjs +7 -0
  38. package/examples/api-cancelMeSubscription.ts +7 -0
  39. package/examples/api-cancelOrderPayment.mjs +7 -0
  40. package/examples/api-cancelOrderPayment.ts +7 -0
  41. package/examples/api-cancelOrderPaymentAttempt.mjs +7 -0
  42. package/examples/api-cancelOrderPaymentAttempt.ts +7 -0
  43. package/examples/api-cancelPaymentIntent.mjs +7 -0
  44. package/examples/api-cancelPaymentIntent.ts +7 -0
  45. package/examples/api-cancelPayout.mjs +7 -0
  46. package/examples/api-cancelPayout.ts +7 -0
  47. package/examples/api-cancelReturn.mjs +9 -0
  48. package/examples/api-cancelReturn.ts +9 -0
  49. package/examples/api-cancelReturnDisposition.mjs +9 -0
  50. package/examples/api-cancelReturnDisposition.ts +9 -0
  51. package/examples/api-cancelReturnLineItem.mjs +12 -0
  52. package/examples/api-cancelReturnLineItem.ts +12 -0
  53. package/examples/api-cancelReturnResolution.mjs +9 -0
  54. package/examples/api-cancelReturnResolution.ts +9 -0
  55. package/examples/api-cancelSubscription.mjs +7 -0
  56. package/examples/api-cancelSubscription.ts +7 -0
  57. package/examples/api-captureOrderPayment.mjs +7 -0
  58. package/examples/api-captureOrderPayment.ts +7 -0
  59. package/examples/api-capturePaymentIntent.mjs +7 -0
  60. package/examples/api-capturePaymentIntent.ts +7 -0
  61. package/examples/api-changeMeSubscriptionPaymentMethod.mjs +9 -0
  62. package/examples/api-changeMeSubscriptionPaymentMethod.ts +9 -0
  63. package/examples/api-changeSubscriptionPaymentMethod.mjs +9 -0
  64. package/examples/api-changeSubscriptionPaymentMethod.ts +9 -0
  65. package/examples/api-checkDeliveryRateCallbackConnection.mjs +6 -0
  66. package/examples/api-checkDeliveryRateCallbackConnection.ts +6 -0
  67. package/examples/api-closeCheckoutSession.mjs +7 -0
  68. package/examples/api-closeCheckoutSession.ts +7 -0
  69. package/examples/api-closeOrder.mjs +7 -0
  70. package/examples/api-closeOrder.ts +7 -0
  71. package/examples/api-collectInvoice.mjs +8 -0
  72. package/examples/api-collectInvoice.ts +8 -0
  73. package/examples/api-commitInventoryReservation.mjs +10 -0
  74. package/examples/api-commitInventoryReservation.ts +10 -0
  75. package/examples/api-completeReturn.mjs +7 -0
  76. package/examples/api-completeReturn.ts +7 -0
  77. package/examples/api-confirmMeEmailChangeRequest.mjs +9 -0
  78. package/examples/api-confirmMeEmailChangeRequest.ts +9 -0
  79. package/examples/api-confirmPaymentIntent.mjs +7 -0
  80. package/examples/api-confirmPaymentIntent.ts +7 -0
  81. package/examples/api-confirmReturnResolution.mjs +7 -0
  82. package/examples/api-confirmReturnResolution.ts +7 -0
  83. package/examples/api-consumeInventoryReservation.mjs +11 -0
  84. package/examples/api-consumeInventoryReservation.ts +11 -0
  85. package/examples/api-createAPIKey.mjs +9 -0
  86. package/examples/api-createAPIKey.ts +9 -0
  87. package/examples/api-createBundle.mjs +12 -0
  88. package/examples/api-createBundle.ts +12 -0
  89. package/examples/api-createCategory.mjs +8 -0
  90. package/examples/api-createCategory.ts +8 -0
  91. package/examples/api-createCheckoutSession.mjs +8 -0
  92. package/examples/api-createCheckoutSession.ts +8 -0
  93. package/examples/api-createCheckoutSessionDeliveryQuote.mjs +9 -0
  94. package/examples/api-createCheckoutSessionDeliveryQuote.ts +9 -0
  95. package/examples/api-createCheckoutSessionDeliverySelection.mjs +11 -0
  96. package/examples/api-createCheckoutSessionDeliverySelection.ts +11 -0
  97. package/examples/api-createCreditNote.mjs +9 -0
  98. package/examples/api-createCreditNote.ts +9 -0
  99. package/examples/api-createCreditNoteAllocation.mjs +13 -0
  100. package/examples/api-createCreditNoteAllocation.ts +13 -0
  101. package/examples/api-createCustomer.mjs +8 -0
  102. package/examples/api-createCustomer.ts +8 -0
  103. package/examples/api-createCustomerAddress.mjs +16 -0
  104. package/examples/api-createCustomerAddress.ts +16 -0
  105. package/examples/api-createCustomerDeletionRequest.mjs +6 -0
  106. package/examples/api-createCustomerDeletionRequest.ts +6 -0
  107. package/examples/api-createCustomerSession.mjs +8 -0
  108. package/examples/api-createCustomerSession.ts +8 -0
  109. package/examples/api-createDeliveryLocationSet.mjs +11 -0
  110. package/examples/api-createDeliveryLocationSet.ts +11 -0
  111. package/examples/api-createDeliveryMethod.mjs +20 -0
  112. package/examples/api-createDeliveryMethod.ts +20 -0
  113. package/examples/api-createDeliveryPreview.mjs +14 -0
  114. package/examples/api-createDeliveryPreview.ts +14 -0
  115. package/examples/api-createDeliveryProfile.mjs +11 -0
  116. package/examples/api-createDeliveryProfile.ts +11 -0
  117. package/examples/api-createDeliveryRateCallback.mjs +11 -0
  118. package/examples/api-createDeliveryRateCallback.ts +11 -0
  119. package/examples/api-createDeliveryRateCallbackTestDelivery.mjs +6 -0
  120. package/examples/api-createDeliveryRateCallbackTestDelivery.ts +6 -0
  121. package/examples/api-createDeliveryZone.mjs +15 -0
  122. package/examples/api-createDeliveryZone.ts +15 -0
  123. package/examples/api-createDemoSession.mjs +6 -0
  124. package/examples/api-createDemoSession.ts +6 -0
  125. package/examples/api-createDeveloperPartnerApp.mjs +10 -0
  126. package/examples/api-createDeveloperPartnerApp.ts +10 -0
  127. package/examples/api-createDeveloperSandbox.mjs +8 -0
  128. package/examples/api-createDeveloperSandbox.ts +8 -0
  129. package/examples/api-createDevice.mjs +8 -0
  130. package/examples/api-createDevice.ts +8 -0
  131. package/examples/api-createFeedbackReport.mjs +10 -0
  132. package/examples/api-createFeedbackReport.ts +10 -0
  133. package/examples/api-createFulfillment.mjs +15 -0
  134. package/examples/api-createFulfillment.ts +15 -0
  135. package/examples/api-createFulfillmentEvent.mjs +9 -0
  136. package/examples/api-createFulfillmentEvent.ts +9 -0
  137. package/examples/api-createInventoryAdjustment.mjs +10 -0
  138. package/examples/api-createInventoryAdjustment.ts +10 -0
  139. package/examples/api-createInventoryAllocationPolicy.mjs +18 -0
  140. package/examples/api-createInventoryAllocationPolicy.ts +18 -0
  141. package/examples/api-createInventoryCount.mjs +12 -0
  142. package/examples/api-createInventoryCount.ts +12 -0
  143. package/examples/api-createInventoryItem.mjs +8 -0
  144. package/examples/api-createInventoryItem.ts +8 -0
  145. package/examples/api-createInventoryReceipt.mjs +9 -0
  146. package/examples/api-createInventoryReceipt.ts +9 -0
  147. package/examples/api-createInventoryReservation.mjs +17 -0
  148. package/examples/api-createInventoryReservation.ts +17 -0
  149. package/examples/api-createInventoryTransfer.mjs +16 -0
  150. package/examples/api-createInventoryTransfer.ts +16 -0
  151. package/examples/api-createInvoice.mjs +8 -0
  152. package/examples/api-createInvoice.ts +8 -0
  153. package/examples/api-createInvoicePaymentTerm.mjs +11 -0
  154. package/examples/api-createInvoicePaymentTerm.ts +11 -0
  155. package/examples/api-createLocation.mjs +10 -0
  156. package/examples/api-createLocation.ts +10 -0
  157. package/examples/api-createMeAddress.mjs +15 -0
  158. package/examples/api-createMeAddress.ts +15 -0
  159. package/examples/api-createMeDeletionRequest.mjs +4 -0
  160. package/examples/api-createMeDeletionRequest.ts +4 -0
  161. package/examples/api-createMeEmailChangeRequest.mjs +8 -0
  162. package/examples/api-createMeEmailChangeRequest.ts +8 -0
  163. package/examples/api-createMeInvoiceCheckoutSession.mjs +6 -0
  164. package/examples/api-createMeInvoiceCheckoutSession.ts +6 -0
  165. package/examples/api-createMeReturn.mjs +15 -0
  166. package/examples/api-createMeReturn.ts +15 -0
  167. package/examples/api-createMeReturnPreview.mjs +14 -0
  168. package/examples/api-createMeReturnPreview.ts +14 -0
  169. package/examples/api-createMeReturnResolutionCheckoutSession.mjs +6 -0
  170. package/examples/api-createMeReturnResolutionCheckoutSession.ts +6 -0
  171. package/examples/api-createMerchantAccountSession.mjs +10 -0
  172. package/examples/api-createMerchantAccountSession.ts +10 -0
  173. package/examples/api-createModifierGroup.mjs +8 -0
  174. package/examples/api-createModifierGroup.ts +8 -0
  175. package/examples/api-createModifierSet.mjs +8 -0
  176. package/examples/api-createModifierSet.ts +8 -0
  177. package/examples/api-createOnboardingAPIKey.mjs +8 -0
  178. package/examples/api-createOnboardingAPIKey.ts +8 -0
  179. package/examples/api-createOrder.mjs +12 -0
  180. package/examples/api-createOrder.ts +12 -0
  181. package/examples/api-createOrderPaymentIntent.mjs +7 -0
  182. package/examples/api-createOrderPaymentIntent.ts +7 -0
  183. package/examples/api-createOrganization.mjs +8 -0
  184. package/examples/api-createOrganization.ts +8 -0
  185. package/examples/api-createPackage.mjs +7 -0
  186. package/examples/api-createPackage.ts +7 -0
  187. package/examples/api-createPackageItem.mjs +10 -0
  188. package/examples/api-createPackageItem.ts +10 -0
  189. package/examples/api-createPaymentIntent.mjs +14 -0
  190. package/examples/api-createPaymentIntent.ts +14 -0
  191. package/examples/api-createPaymentLink.mjs +8 -0
  192. package/examples/api-createPaymentLink.ts +8 -0
  193. package/examples/api-createPaymentMethodDomain.mjs +8 -0
  194. package/examples/api-createPaymentMethodDomain.ts +8 -0
  195. package/examples/api-createPayout.mjs +11 -0
  196. package/examples/api-createPayout.ts +11 -0
  197. package/examples/api-createProduct.mjs +15 -0
  198. package/examples/api-createProduct.ts +15 -0
  199. package/examples/api-createProductVariant.mjs +14 -0
  200. package/examples/api-createProductVariant.ts +14 -0
  201. package/examples/api-createPromotion.mjs +11 -0
  202. package/examples/api-createPromotion.ts +11 -0
  203. package/examples/api-createPromotionCode.mjs +9 -0
  204. package/examples/api-createPromotionCode.ts +9 -0
  205. package/examples/api-createRefund.mjs +8 -0
  206. package/examples/api-createRefund.ts +8 -0
  207. package/examples/api-createReport.mjs +11 -0
  208. package/examples/api-createReport.ts +11 -0
  209. package/examples/api-createReturn.mjs +15 -0
  210. package/examples/api-createReturn.ts +15 -0
  211. package/examples/api-createReturnDisposition.mjs +13 -0
  212. package/examples/api-createReturnDisposition.ts +13 -0
  213. package/examples/api-createReturnInspection.mjs +19 -0
  214. package/examples/api-createReturnInspection.ts +19 -0
  215. package/examples/api-createReturnPolicy.mjs +15 -0
  216. package/examples/api-createReturnPolicy.ts +15 -0
  217. package/examples/api-createReturnPreview.mjs +14 -0
  218. package/examples/api-createReturnPreview.ts +14 -0
  219. package/examples/api-createReturnReason.mjs +9 -0
  220. package/examples/api-createReturnReason.ts +9 -0
  221. package/examples/api-createReturnReceipt.mjs +16 -0
  222. package/examples/api-createReturnReceipt.ts +16 -0
  223. package/examples/api-createReturnResolution.mjs +15 -0
  224. package/examples/api-createReturnResolution.ts +15 -0
  225. package/examples/api-createRiskList.mjs +10 -0
  226. package/examples/api-createRiskList.ts +10 -0
  227. package/examples/api-createRiskPreview.mjs +8 -0
  228. package/examples/api-createRiskPreview.ts +8 -0
  229. package/examples/api-createRiskRule.mjs +14 -0
  230. package/examples/api-createRiskRule.ts +14 -0
  231. package/examples/api-createShipment.mjs +7 -0
  232. package/examples/api-createShipment.ts +7 -0
  233. package/examples/api-createSubscription.mjs +15 -0
  234. package/examples/api-createSubscription.ts +15 -0
  235. package/examples/api-createSubscriptionPaymentRetry.mjs +7 -0
  236. package/examples/api-createSubscriptionPaymentRetry.ts +7 -0
  237. package/examples/api-createSubscriptionPlan.mjs +11 -0
  238. package/examples/api-createSubscriptionPlan.ts +11 -0
  239. package/examples/api-createWebhookEndpoint.mjs +8 -0
  240. package/examples/api-createWebhookEndpoint.ts +8 -0
  241. package/examples/api-createWebhookTestEvent.mjs +9 -0
  242. package/examples/api-createWebhookTestEvent.ts +9 -0
  243. package/examples/api-decideReturn.mjs +15 -0
  244. package/examples/api-decideReturn.ts +15 -0
  245. package/examples/api-decideReturnInspectionLineItem.mjs +11 -0
  246. package/examples/api-decideReturnInspectionLineItem.ts +11 -0
  247. package/examples/api-declineReview.mjs +6 -0
  248. package/examples/api-declineReview.ts +6 -0
  249. package/examples/api-deleteBundle.mjs +6 -0
  250. package/examples/api-deleteBundle.ts +6 -0
  251. package/examples/api-deleteCategory.mjs +6 -0
  252. package/examples/api-deleteCategory.ts +6 -0
  253. package/examples/api-deleteCheckoutSessionCurrentDeliverySelection.mjs +7 -0
  254. package/examples/api-deleteCheckoutSessionCurrentDeliverySelection.ts +7 -0
  255. package/examples/api-deleteCustomerAddress.mjs +7 -0
  256. package/examples/api-deleteCustomerAddress.ts +7 -0
  257. package/examples/api-deleteDeliveryLocationSet.mjs +6 -0
  258. package/examples/api-deleteDeliveryLocationSet.ts +6 -0
  259. package/examples/api-deleteDeliveryMethod.mjs +6 -0
  260. package/examples/api-deleteDeliveryMethod.ts +6 -0
  261. package/examples/api-deleteDeliveryProfile.mjs +6 -0
  262. package/examples/api-deleteDeliveryProfile.ts +6 -0
  263. package/examples/api-deleteDeliveryRateCallback.mjs +6 -0
  264. package/examples/api-deleteDeliveryRateCallback.ts +6 -0
  265. package/examples/api-deleteDeliveryZone.mjs +6 -0
  266. package/examples/api-deleteDeliveryZone.ts +6 -0
  267. package/examples/api-deleteDeveloperSandbox.mjs +6 -0
  268. package/examples/api-deleteDeveloperSandbox.ts +6 -0
  269. package/examples/api-deleteDevice.mjs +6 -0
  270. package/examples/api-deleteDevice.ts +6 -0
  271. package/examples/api-deleteInventoryAllocationPolicy.mjs +6 -0
  272. package/examples/api-deleteInventoryAllocationPolicy.ts +6 -0
  273. package/examples/api-deleteInventoryItem.mjs +6 -0
  274. package/examples/api-deleteInventoryItem.ts +6 -0
  275. package/examples/api-deleteInvoicePaymentTerm.mjs +6 -0
  276. package/examples/api-deleteInvoicePaymentTerm.ts +6 -0
  277. package/examples/api-deleteLocation.mjs +6 -0
  278. package/examples/api-deleteLocation.ts +6 -0
  279. package/examples/api-deleteMeAddress.mjs +6 -0
  280. package/examples/api-deleteMeAddress.ts +6 -0
  281. package/examples/api-deleteModifierGroup.mjs +6 -0
  282. package/examples/api-deleteModifierGroup.ts +6 -0
  283. package/examples/api-deleteModifierSet.mjs +6 -0
  284. package/examples/api-deleteModifierSet.ts +6 -0
  285. package/examples/api-deleteOrderCharge.mjs +7 -0
  286. package/examples/api-deleteOrderCharge.ts +7 -0
  287. package/examples/api-deleteOrderLineItem.mjs +7 -0
  288. package/examples/api-deleteOrderLineItem.ts +7 -0
  289. package/examples/api-deleteOrganization.mjs +6 -0
  290. package/examples/api-deleteOrganization.ts +6 -0
  291. package/examples/api-deletePackageItem.mjs +7 -0
  292. package/examples/api-deletePackageItem.ts +7 -0
  293. package/examples/api-deletePayoutDestination.mjs +7 -0
  294. package/examples/api-deletePayoutDestination.ts +7 -0
  295. package/examples/api-deleteProduct.mjs +6 -0
  296. package/examples/api-deleteProduct.ts +6 -0
  297. package/examples/api-deleteProductVariant.mjs +7 -0
  298. package/examples/api-deleteProductVariant.ts +7 -0
  299. package/examples/api-deletePromotion.mjs +6 -0
  300. package/examples/api-deletePromotion.ts +6 -0
  301. package/examples/api-deletePromotionCode.mjs +7 -0
  302. package/examples/api-deletePromotionCode.ts +7 -0
  303. package/examples/api-deleteReturnLineItem.mjs +7 -0
  304. package/examples/api-deleteReturnLineItem.ts +7 -0
  305. package/examples/api-deleteReturnPolicy.mjs +6 -0
  306. package/examples/api-deleteReturnPolicy.ts +6 -0
  307. package/examples/api-deleteReturnReason.mjs +6 -0
  308. package/examples/api-deleteReturnReason.ts +6 -0
  309. package/examples/api-deleteRiskList.mjs +6 -0
  310. package/examples/api-deleteRiskList.ts +6 -0
  311. package/examples/api-deleteRiskListItem.mjs +7 -0
  312. package/examples/api-deleteRiskListItem.ts +7 -0
  313. package/examples/api-deleteRiskRule.mjs +6 -0
  314. package/examples/api-deleteRiskRule.ts +6 -0
  315. package/examples/api-deleteSubscriptionPlan.mjs +6 -0
  316. package/examples/api-deleteSubscriptionPlan.ts +6 -0
  317. package/examples/api-deleteWebhookEndpoint.mjs +6 -0
  318. package/examples/api-deleteWebhookEndpoint.ts +6 -0
  319. package/examples/api-exchangePartnerInstallToken.mjs +10 -0
  320. package/examples/api-exchangePartnerInstallToken.ts +10 -0
  321. package/examples/api-getAPIKey.mjs +6 -0
  322. package/examples/api-getAPIKey.ts +6 -0
  323. package/examples/api-getAnalyticsOverview.mjs +6 -0
  324. package/examples/api-getAnalyticsOverview.ts +6 -0
  325. package/examples/api-getBalanceTransaction.mjs +6 -0
  326. package/examples/api-getBalanceTransaction.ts +6 -0
  327. package/examples/api-getBundle.mjs +6 -0
  328. package/examples/api-getBundle.ts +6 -0
  329. package/examples/api-getCategory.mjs +6 -0
  330. package/examples/api-getCategory.ts +6 -0
  331. package/examples/api-getCheckoutSession.mjs +6 -0
  332. package/examples/api-getCheckoutSession.ts +6 -0
  333. package/examples/api-getCheckoutSessionCurrentDeliverySelection.mjs +6 -0
  334. package/examples/api-getCheckoutSessionCurrentDeliverySelection.ts +6 -0
  335. package/examples/api-getCheckoutSessionDeliveryQuote.mjs +7 -0
  336. package/examples/api-getCheckoutSessionDeliveryQuote.ts +7 -0
  337. package/examples/api-getCheckoutSessionDeliverySelectionHistory.mjs +7 -0
  338. package/examples/api-getCheckoutSessionDeliverySelectionHistory.ts +7 -0
  339. package/examples/api-getCreditNote.mjs +6 -0
  340. package/examples/api-getCreditNote.ts +6 -0
  341. package/examples/api-getCreditNoteAllocation.mjs +7 -0
  342. package/examples/api-getCreditNoteAllocation.ts +7 -0
  343. package/examples/api-getCreditNotePDF.mjs +6 -0
  344. package/examples/api-getCreditNotePDF.ts +6 -0
  345. package/examples/api-getCurrentAPIKeyRequestLog.mjs +6 -0
  346. package/examples/api-getCurrentAPIKeyRequestLog.ts +6 -0
  347. package/examples/api-getCustomer.mjs +6 -0
  348. package/examples/api-getCustomer.ts +6 -0
  349. package/examples/api-getCustomerAddress.mjs +7 -0
  350. package/examples/api-getCustomerAddress.ts +7 -0
  351. package/examples/api-getCustomerDeletionRequest.mjs +7 -0
  352. package/examples/api-getCustomerDeletionRequest.ts +7 -0
  353. package/examples/api-getDeliveryLocationSet.mjs +6 -0
  354. package/examples/api-getDeliveryLocationSet.ts +6 -0
  355. package/examples/api-getDeliveryMethod.mjs +6 -0
  356. package/examples/api-getDeliveryMethod.ts +6 -0
  357. package/examples/api-getDeliveryProfile.mjs +6 -0
  358. package/examples/api-getDeliveryProfile.ts +6 -0
  359. package/examples/api-getDeliveryRateCallback.mjs +6 -0
  360. package/examples/api-getDeliveryRateCallback.ts +6 -0
  361. package/examples/api-getDeliveryRevocation.mjs +6 -0
  362. package/examples/api-getDeliveryRevocation.ts +6 -0
  363. package/examples/api-getDeliveryZone.mjs +6 -0
  364. package/examples/api-getDeliveryZone.ts +6 -0
  365. package/examples/api-getDeveloperAuthContext.mjs +4 -0
  366. package/examples/api-getDeveloperAuthContext.ts +4 -0
  367. package/examples/api-getDeveloperPartnerApp.mjs +6 -0
  368. package/examples/api-getDeveloperPartnerApp.ts +6 -0
  369. package/examples/api-getDeveloperPartnerAppInstall.mjs +7 -0
  370. package/examples/api-getDeveloperPartnerAppInstall.ts +7 -0
  371. package/examples/api-getDeveloperSandbox.mjs +6 -0
  372. package/examples/api-getDeveloperSandbox.ts +6 -0
  373. package/examples/api-getDevice.mjs +6 -0
  374. package/examples/api-getDevice.ts +6 -0
  375. package/examples/api-getDispute.mjs +6 -0
  376. package/examples/api-getDispute.ts +6 -0
  377. package/examples/api-getEffectiveSettings.mjs +4 -0
  378. package/examples/api-getEffectiveSettings.ts +4 -0
  379. package/examples/api-getFeedbackReport.mjs +6 -0
  380. package/examples/api-getFeedbackReport.ts +6 -0
  381. package/examples/api-getFraudWarning.mjs +6 -0
  382. package/examples/api-getFraudWarning.ts +6 -0
  383. package/examples/api-getFulfillment.mjs +6 -0
  384. package/examples/api-getFulfillment.ts +6 -0
  385. package/examples/api-getFulfillmentEvent.mjs +6 -0
  386. package/examples/api-getFulfillmentEvent.ts +6 -0
  387. package/examples/api-getFulfillmentNotification.mjs +6 -0
  388. package/examples/api-getFulfillmentNotification.ts +6 -0
  389. package/examples/api-getInvoice.mjs +6 -0
  390. package/examples/api-getInvoice.ts +6 -0
  391. package/examples/api-getInvoicePDF.mjs +6 -0
  392. package/examples/api-getInvoicePDF.ts +6 -0
  393. package/examples/api-getInvoicePaymentAttempt.mjs +7 -0
  394. package/examples/api-getInvoicePaymentAttempt.ts +7 -0
  395. package/examples/api-getInvoicePaymentTerm.mjs +6 -0
  396. package/examples/api-getInvoicePaymentTerm.ts +6 -0
  397. package/examples/api-getLocation.mjs +6 -0
  398. package/examples/api-getLocation.ts +6 -0
  399. package/examples/api-getMe.mjs +4 -0
  400. package/examples/api-getMe.ts +4 -0
  401. package/examples/api-getMeAddress.mjs +6 -0
  402. package/examples/api-getMeAddress.ts +6 -0
  403. package/examples/api-getMeCreditNote.mjs +7 -0
  404. package/examples/api-getMeCreditNote.ts +7 -0
  405. package/examples/api-getMeCreditNotePDF.mjs +7 -0
  406. package/examples/api-getMeCreditNotePDF.ts +7 -0
  407. package/examples/api-getMeDeletionRequest.mjs +6 -0
  408. package/examples/api-getMeDeletionRequest.ts +6 -0
  409. package/examples/api-getMeInvoice.mjs +6 -0
  410. package/examples/api-getMeInvoice.ts +6 -0
  411. package/examples/api-getMeInvoicePDF.mjs +6 -0
  412. package/examples/api-getMeInvoicePDF.ts +6 -0
  413. package/examples/api-getMeOrder.mjs +6 -0
  414. package/examples/api-getMeOrder.ts +6 -0
  415. package/examples/api-getMeReturn.mjs +6 -0
  416. package/examples/api-getMeReturn.ts +6 -0
  417. package/examples/api-getMeSubscription.mjs +6 -0
  418. package/examples/api-getMeSubscription.ts +6 -0
  419. package/examples/api-getMerchant.mjs +6 -0
  420. package/examples/api-getMerchant.ts +6 -0
  421. package/examples/api-getMerchantBillingBalance.mjs +6 -0
  422. package/examples/api-getMerchantBillingBalance.ts +6 -0
  423. package/examples/api-getMerchantSubscriptionInvoice.mjs +6 -0
  424. package/examples/api-getMerchantSubscriptionInvoice.ts +6 -0
  425. package/examples/api-getModifierGroup.mjs +6 -0
  426. package/examples/api-getModifierGroup.ts +6 -0
  427. package/examples/api-getModifierSet.mjs +6 -0
  428. package/examples/api-getModifierSet.ts +6 -0
  429. package/examples/api-getOnboardingState.mjs +4 -0
  430. package/examples/api-getOnboardingState.ts +4 -0
  431. package/examples/api-getOpenAPISpec.mjs +4 -0
  432. package/examples/api-getOpenAPISpec.ts +4 -0
  433. package/examples/api-getOrCreateInvoiceCheckoutSession.mjs +6 -0
  434. package/examples/api-getOrCreateInvoiceCheckoutSession.ts +6 -0
  435. package/examples/api-getOrCreateReturnResolutionCheckoutSession.mjs +6 -0
  436. package/examples/api-getOrCreateReturnResolutionCheckoutSession.ts +6 -0
  437. package/examples/api-getOrder.mjs +6 -0
  438. package/examples/api-getOrder.ts +6 -0
  439. package/examples/api-getOrderCurrentDeliverySelection.mjs +6 -0
  440. package/examples/api-getOrderCurrentDeliverySelection.ts +6 -0
  441. package/examples/api-getOrderPaymentAttempt.mjs +7 -0
  442. package/examples/api-getOrderPaymentAttempt.ts +7 -0
  443. package/examples/api-getOrganization.mjs +6 -0
  444. package/examples/api-getOrganization.ts +6 -0
  445. package/examples/api-getPackage.mjs +6 -0
  446. package/examples/api-getPackage.ts +6 -0
  447. package/examples/api-getPackageItem.mjs +7 -0
  448. package/examples/api-getPackageItem.ts +7 -0
  449. package/examples/api-getPaymentIntent.mjs +6 -0
  450. package/examples/api-getPaymentIntent.ts +6 -0
  451. package/examples/api-getPaymentLink.mjs +6 -0
  452. package/examples/api-getPaymentLink.ts +6 -0
  453. package/examples/api-getPaymentLinkPublic.mjs +6 -0
  454. package/examples/api-getPaymentLinkPublic.ts +6 -0
  455. package/examples/api-getPaymentMethod.mjs +6 -0
  456. package/examples/api-getPaymentMethod.ts +6 -0
  457. package/examples/api-getPaymentMethodDomain.mjs +6 -0
  458. package/examples/api-getPaymentMethodDomain.ts +6 -0
  459. package/examples/api-getPaymentVolumeTimeseries.mjs +6 -0
  460. package/examples/api-getPaymentVolumeTimeseries.ts +6 -0
  461. package/examples/api-getPayout.mjs +6 -0
  462. package/examples/api-getPayout.ts +6 -0
  463. package/examples/api-getPayoutDestination.mjs +6 -0
  464. package/examples/api-getPayoutDestination.ts +6 -0
  465. package/examples/api-getPayoutSettings.mjs +4 -0
  466. package/examples/api-getPayoutSettings.ts +4 -0
  467. package/examples/api-getProduct.mjs +6 -0
  468. package/examples/api-getProduct.ts +6 -0
  469. package/examples/api-getProductOption.mjs +7 -0
  470. package/examples/api-getProductOption.ts +7 -0
  471. package/examples/api-getProductVariant.mjs +7 -0
  472. package/examples/api-getProductVariant.ts +7 -0
  473. package/examples/api-getPromotion.mjs +6 -0
  474. package/examples/api-getPromotion.ts +6 -0
  475. package/examples/api-getRefund.mjs +6 -0
  476. package/examples/api-getRefund.ts +6 -0
  477. package/examples/api-getReport.mjs +6 -0
  478. package/examples/api-getReport.ts +6 -0
  479. package/examples/api-getReportDownload.mjs +6 -0
  480. package/examples/api-getReportDownload.ts +6 -0
  481. package/examples/api-getResourceTimeline.mjs +6 -0
  482. package/examples/api-getResourceTimeline.ts +6 -0
  483. package/examples/api-getReturn.mjs +6 -0
  484. package/examples/api-getReturn.ts +6 -0
  485. package/examples/api-getReturnDisposition.mjs +6 -0
  486. package/examples/api-getReturnDisposition.ts +6 -0
  487. package/examples/api-getReturnInspection.mjs +6 -0
  488. package/examples/api-getReturnInspection.ts +6 -0
  489. package/examples/api-getReturnLineItem.mjs +7 -0
  490. package/examples/api-getReturnLineItem.ts +7 -0
  491. package/examples/api-getReturnPolicy.mjs +6 -0
  492. package/examples/api-getReturnPolicy.ts +6 -0
  493. package/examples/api-getReturnPolicyRevision.mjs +7 -0
  494. package/examples/api-getReturnPolicyRevision.ts +7 -0
  495. package/examples/api-getReturnReason.mjs +6 -0
  496. package/examples/api-getReturnReason.ts +6 -0
  497. package/examples/api-getReturnReceipt.mjs +6 -0
  498. package/examples/api-getReturnReceipt.ts +6 -0
  499. package/examples/api-getReturnResolution.mjs +6 -0
  500. package/examples/api-getReturnResolution.ts +6 -0
  501. package/examples/api-getReview.mjs +6 -0
  502. package/examples/api-getReview.ts +6 -0
  503. package/examples/api-getRiskList.mjs +6 -0
  504. package/examples/api-getRiskList.ts +6 -0
  505. package/examples/api-getRiskListItem.mjs +7 -0
  506. package/examples/api-getRiskListItem.ts +7 -0
  507. package/examples/api-getRiskRule.mjs +6 -0
  508. package/examples/api-getRiskRule.ts +6 -0
  509. package/examples/api-getRiskRuleAttributeRegistry.mjs +4 -0
  510. package/examples/api-getRiskRuleAttributeRegistry.ts +4 -0
  511. package/examples/api-getSettings.mjs +4 -0
  512. package/examples/api-getSettings.ts +4 -0
  513. package/examples/api-getShipment.mjs +6 -0
  514. package/examples/api-getShipment.ts +6 -0
  515. package/examples/api-getSubscription.mjs +6 -0
  516. package/examples/api-getSubscription.ts +6 -0
  517. package/examples/api-getSubscriptionAnalytics.mjs +6 -0
  518. package/examples/api-getSubscriptionAnalytics.ts +6 -0
  519. package/examples/api-getSubscriptionPaymentRetry.mjs +7 -0
  520. package/examples/api-getSubscriptionPaymentRetry.ts +7 -0
  521. package/examples/api-getSubscriptionPlan.mjs +6 -0
  522. package/examples/api-getSubscriptionPlan.ts +6 -0
  523. package/examples/api-getWebhookDelivery.mjs +6 -0
  524. package/examples/api-getWebhookDelivery.ts +6 -0
  525. package/examples/api-getWebhookEndpoint.mjs +6 -0
  526. package/examples/api-getWebhookEndpoint.ts +6 -0
  527. package/examples/api-getWebhookEvent.mjs +6 -0
  528. package/examples/api-getWebhookEvent.ts +6 -0
  529. package/examples/api-grantOrganizationMembership.mjs +10 -0
  530. package/examples/api-grantOrganizationMembership.ts +10 -0
  531. package/examples/api-issueCreditNote.mjs +6 -0
  532. package/examples/api-issueCreditNote.ts +6 -0
  533. package/examples/api-issueDeveloperSandboxTestKey.mjs +9 -0
  534. package/examples/api-issueDeveloperSandboxTestKey.ts +9 -0
  535. package/examples/api-issueInvoice.mjs +7 -0
  536. package/examples/api-issueInvoice.ts +7 -0
  537. package/examples/api-listAPIKeys.mjs +4 -0
  538. package/examples/api-listAPIKeys.ts +4 -0
  539. package/examples/api-listBalanceTransactions.mjs +4 -0
  540. package/examples/api-listBalanceTransactions.ts +4 -0
  541. package/examples/api-listBalances.mjs +4 -0
  542. package/examples/api-listBalances.ts +4 -0
  543. package/examples/api-listBundleComponents.mjs +6 -0
  544. package/examples/api-listBundleComponents.ts +6 -0
  545. package/examples/api-listBundles.mjs +4 -0
  546. package/examples/api-listBundles.ts +4 -0
  547. package/examples/api-listCapabilities.mjs +4 -0
  548. package/examples/api-listCapabilities.ts +4 -0
  549. package/examples/api-listCategories.mjs +4 -0
  550. package/examples/api-listCategories.ts +4 -0
  551. package/examples/api-listCheckoutSessions.mjs +4 -0
  552. package/examples/api-listCheckoutSessions.ts +4 -0
  553. package/examples/api-listCreditNoteAllocations.mjs +6 -0
  554. package/examples/api-listCreditNoteAllocations.ts +6 -0
  555. package/examples/api-listCreditNotes.mjs +4 -0
  556. package/examples/api-listCreditNotes.ts +4 -0
  557. package/examples/api-listCurrentAPIKeyRequestLogs.mjs +4 -0
  558. package/examples/api-listCurrentAPIKeyRequestLogs.ts +4 -0
  559. package/examples/api-listCustomerAddresses.mjs +6 -0
  560. package/examples/api-listCustomerAddresses.ts +6 -0
  561. package/examples/api-listCustomerDeletionRequests.mjs +4 -0
  562. package/examples/api-listCustomerDeletionRequests.ts +4 -0
  563. package/examples/api-listCustomers.mjs +4 -0
  564. package/examples/api-listCustomers.ts +4 -0
  565. package/examples/api-listDeliveryLocationSets.mjs +4 -0
  566. package/examples/api-listDeliveryLocationSets.ts +4 -0
  567. package/examples/api-listDeliveryMethods.mjs +4 -0
  568. package/examples/api-listDeliveryMethods.ts +4 -0
  569. package/examples/api-listDeliveryProfiles.mjs +4 -0
  570. package/examples/api-listDeliveryProfiles.ts +4 -0
  571. package/examples/api-listDeliveryQuotes.mjs +4 -0
  572. package/examples/api-listDeliveryQuotes.ts +4 -0
  573. package/examples/api-listDeliveryRateCallbacks.mjs +4 -0
  574. package/examples/api-listDeliveryRateCallbacks.ts +4 -0
  575. package/examples/api-listDeliveryZones.mjs +4 -0
  576. package/examples/api-listDeliveryZones.ts +4 -0
  577. package/examples/api-listDeveloperPartnerAppInstalls.mjs +6 -0
  578. package/examples/api-listDeveloperPartnerAppInstalls.ts +6 -0
  579. package/examples/api-listDeveloperPartnerApps.mjs +4 -0
  580. package/examples/api-listDeveloperPartnerApps.ts +4 -0
  581. package/examples/api-listDeveloperSandboxes.mjs +4 -0
  582. package/examples/api-listDeveloperSandboxes.ts +4 -0
  583. package/examples/api-listDevices.mjs +4 -0
  584. package/examples/api-listDevices.ts +4 -0
  585. package/examples/api-listDisputes.mjs +4 -0
  586. package/examples/api-listDisputes.ts +4 -0
  587. package/examples/api-listFeedbackReports.mjs +4 -0
  588. package/examples/api-listFeedbackReports.ts +4 -0
  589. package/examples/api-listFraudWarnings.mjs +4 -0
  590. package/examples/api-listFraudWarnings.ts +4 -0
  591. package/examples/api-listFulfillmentEvents.mjs +4 -0
  592. package/examples/api-listFulfillmentEvents.ts +4 -0
  593. package/examples/api-listFulfillmentNotifications.mjs +4 -0
  594. package/examples/api-listFulfillmentNotifications.ts +4 -0
  595. package/examples/api-listFulfillments.mjs +4 -0
  596. package/examples/api-listFulfillments.ts +4 -0
  597. package/examples/api-listInventoryAdjustments.mjs +4 -0
  598. package/examples/api-listInventoryAdjustments.ts +4 -0
  599. package/examples/api-listInventoryAllocationPolicies.mjs +4 -0
  600. package/examples/api-listInventoryAllocationPolicies.ts +4 -0
  601. package/examples/api-listInventoryCounts.mjs +4 -0
  602. package/examples/api-listInventoryCounts.ts +4 -0
  603. package/examples/api-listInventoryItems.mjs +4 -0
  604. package/examples/api-listInventoryItems.ts +4 -0
  605. package/examples/api-listInventoryLevels.mjs +4 -0
  606. package/examples/api-listInventoryLevels.ts +4 -0
  607. package/examples/api-listInventoryMovements.mjs +4 -0
  608. package/examples/api-listInventoryMovements.ts +4 -0
  609. package/examples/api-listInventoryReceipts.mjs +4 -0
  610. package/examples/api-listInventoryReceipts.ts +4 -0
  611. package/examples/api-listInventoryReservations.mjs +4 -0
  612. package/examples/api-listInventoryReservations.ts +4 -0
  613. package/examples/api-listInventoryTransfers.mjs +4 -0
  614. package/examples/api-listInventoryTransfers.ts +4 -0
  615. package/examples/api-listInvoiceDeliveryAttempts.mjs +6 -0
  616. package/examples/api-listInvoiceDeliveryAttempts.ts +6 -0
  617. package/examples/api-listInvoiceEvents.mjs +6 -0
  618. package/examples/api-listInvoiceEvents.ts +6 -0
  619. package/examples/api-listInvoicePaymentAttempts.mjs +6 -0
  620. package/examples/api-listInvoicePaymentAttempts.ts +6 -0
  621. package/examples/api-listInvoicePaymentTerms.mjs +4 -0
  622. package/examples/api-listInvoicePaymentTerms.ts +4 -0
  623. package/examples/api-listInvoices.mjs +4 -0
  624. package/examples/api-listInvoices.ts +4 -0
  625. package/examples/api-listLocations.mjs +4 -0
  626. package/examples/api-listLocations.ts +4 -0
  627. package/examples/api-listMeAddresses.mjs +4 -0
  628. package/examples/api-listMeAddresses.ts +4 -0
  629. package/examples/api-listMeCreditNotes.mjs +6 -0
  630. package/examples/api-listMeCreditNotes.ts +6 -0
  631. package/examples/api-listMeFulfillments.mjs +4 -0
  632. package/examples/api-listMeFulfillments.ts +4 -0
  633. package/examples/api-listMeInvoices.mjs +4 -0
  634. package/examples/api-listMeInvoices.ts +4 -0
  635. package/examples/api-listMeOrderActivities.mjs +6 -0
  636. package/examples/api-listMeOrderActivities.ts +6 -0
  637. package/examples/api-listMeOrders.mjs +4 -0
  638. package/examples/api-listMeOrders.ts +4 -0
  639. package/examples/api-listMePackages.mjs +4 -0
  640. package/examples/api-listMePackages.ts +4 -0
  641. package/examples/api-listMePaymentMethods.mjs +4 -0
  642. package/examples/api-listMePaymentMethods.ts +4 -0
  643. package/examples/api-listMePayments.mjs +4 -0
  644. package/examples/api-listMePayments.ts +4 -0
  645. package/examples/api-listMeRefunds.mjs +4 -0
  646. package/examples/api-listMeRefunds.ts +4 -0
  647. package/examples/api-listMeReturns.mjs +4 -0
  648. package/examples/api-listMeReturns.ts +4 -0
  649. package/examples/api-listMeShipments.mjs +4 -0
  650. package/examples/api-listMeShipments.ts +4 -0
  651. package/examples/api-listMeSubscriptions.mjs +4 -0
  652. package/examples/api-listMeSubscriptions.ts +4 -0
  653. package/examples/api-listMerchantBillingBalances.mjs +4 -0
  654. package/examples/api-listMerchantBillingBalances.ts +4 -0
  655. package/examples/api-listMerchantSubscriptionInvoices.mjs +4 -0
  656. package/examples/api-listMerchantSubscriptionInvoices.ts +4 -0
  657. package/examples/api-listModifierGroups.mjs +4 -0
  658. package/examples/api-listModifierGroups.ts +4 -0
  659. package/examples/api-listModifierSets.mjs +4 -0
  660. package/examples/api-listModifierSets.ts +4 -0
  661. package/examples/api-listOrderActivities.mjs +6 -0
  662. package/examples/api-listOrderActivities.ts +6 -0
  663. package/examples/api-listOrderPaymentAttempts.mjs +6 -0
  664. package/examples/api-listOrderPaymentAttempts.ts +6 -0
  665. package/examples/api-listOrders.mjs +4 -0
  666. package/examples/api-listOrders.ts +4 -0
  667. package/examples/api-listOrganizationMemberships.mjs +6 -0
  668. package/examples/api-listOrganizationMemberships.ts +6 -0
  669. package/examples/api-listOrganizations.mjs +4 -0
  670. package/examples/api-listOrganizations.ts +4 -0
  671. package/examples/api-listPackageItems.mjs +6 -0
  672. package/examples/api-listPackageItems.ts +6 -0
  673. package/examples/api-listPackages.mjs +4 -0
  674. package/examples/api-listPackages.ts +4 -0
  675. package/examples/api-listPaymentIntents.mjs +4 -0
  676. package/examples/api-listPaymentIntents.ts +4 -0
  677. package/examples/api-listPaymentLinks.mjs +4 -0
  678. package/examples/api-listPaymentLinks.ts +4 -0
  679. package/examples/api-listPaymentMethodDomains.mjs +4 -0
  680. package/examples/api-listPaymentMethodDomains.ts +4 -0
  681. package/examples/api-listPaymentMethods.mjs +4 -0
  682. package/examples/api-listPaymentMethods.ts +4 -0
  683. package/examples/api-listPayoutDestinations.mjs +4 -0
  684. package/examples/api-listPayoutDestinations.ts +4 -0
  685. package/examples/api-listPayoutEntries.mjs +6 -0
  686. package/examples/api-listPayoutEntries.ts +6 -0
  687. package/examples/api-listPayouts.mjs +4 -0
  688. package/examples/api-listPayouts.ts +4 -0
  689. package/examples/api-listProductOptions.mjs +6 -0
  690. package/examples/api-listProductOptions.ts +6 -0
  691. package/examples/api-listProductVariants.mjs +6 -0
  692. package/examples/api-listProductVariants.ts +6 -0
  693. package/examples/api-listProducts.mjs +4 -0
  694. package/examples/api-listProducts.ts +4 -0
  695. package/examples/api-listPromotionCodes.mjs +6 -0
  696. package/examples/api-listPromotionCodes.ts +6 -0
  697. package/examples/api-listPromotions.mjs +4 -0
  698. package/examples/api-listPromotions.ts +4 -0
  699. package/examples/api-listRefunds.mjs +4 -0
  700. package/examples/api-listRefunds.ts +4 -0
  701. package/examples/api-listReports.mjs +4 -0
  702. package/examples/api-listReports.ts +4 -0
  703. package/examples/api-listReturnDispositions.mjs +4 -0
  704. package/examples/api-listReturnDispositions.ts +4 -0
  705. package/examples/api-listReturnInspections.mjs +4 -0
  706. package/examples/api-listReturnInspections.ts +4 -0
  707. package/examples/api-listReturnLineItems.mjs +6 -0
  708. package/examples/api-listReturnLineItems.ts +6 -0
  709. package/examples/api-listReturnPolicies.mjs +4 -0
  710. package/examples/api-listReturnPolicies.ts +4 -0
  711. package/examples/api-listReturnPolicyRevisions.mjs +6 -0
  712. package/examples/api-listReturnPolicyRevisions.ts +6 -0
  713. package/examples/api-listReturnReasons.mjs +4 -0
  714. package/examples/api-listReturnReasons.ts +4 -0
  715. package/examples/api-listReturnReceipts.mjs +4 -0
  716. package/examples/api-listReturnReceipts.ts +4 -0
  717. package/examples/api-listReturnResolutions.mjs +4 -0
  718. package/examples/api-listReturnResolutions.ts +4 -0
  719. package/examples/api-listReturns.mjs +4 -0
  720. package/examples/api-listReturns.ts +4 -0
  721. package/examples/api-listReviews.mjs +4 -0
  722. package/examples/api-listReviews.ts +4 -0
  723. package/examples/api-listRiskListItems.mjs +6 -0
  724. package/examples/api-listRiskListItems.ts +6 -0
  725. package/examples/api-listRiskLists.mjs +4 -0
  726. package/examples/api-listRiskLists.ts +4 -0
  727. package/examples/api-listRiskRules.mjs +4 -0
  728. package/examples/api-listRiskRules.ts +4 -0
  729. package/examples/api-listShipments.mjs +4 -0
  730. package/examples/api-listShipments.ts +4 -0
  731. package/examples/api-listSubscriptionPaymentRetries.mjs +6 -0
  732. package/examples/api-listSubscriptionPaymentRetries.ts +6 -0
  733. package/examples/api-listSubscriptionPlans.mjs +4 -0
  734. package/examples/api-listSubscriptionPlans.ts +4 -0
  735. package/examples/api-listSubscriptions.mjs +4 -0
  736. package/examples/api-listSubscriptions.ts +4 -0
  737. package/examples/api-listWebhookDeliveries.mjs +6 -0
  738. package/examples/api-listWebhookDeliveries.ts +6 -0
  739. package/examples/api-listWebhookDeliveryAttempts.mjs +6 -0
  740. package/examples/api-listWebhookDeliveryAttempts.ts +6 -0
  741. package/examples/api-listWebhookEndpoints.mjs +4 -0
  742. package/examples/api-listWebhookEndpoints.ts +4 -0
  743. package/examples/api-listWebhookEventTypes.mjs +4 -0
  744. package/examples/api-listWebhookEventTypes.ts +4 -0
  745. package/examples/api-listWebhookEvents.mjs +4 -0
  746. package/examples/api-listWebhookEvents.ts +4 -0
  747. package/examples/api-markInvoiceUncollectible.mjs +6 -0
  748. package/examples/api-markInvoiceUncollectible.ts +6 -0
  749. package/examples/api-pauseInvoiceReminders.mjs +6 -0
  750. package/examples/api-pauseInvoiceReminders.ts +6 -0
  751. package/examples/api-pauseMeSubscription.mjs +7 -0
  752. package/examples/api-pauseMeSubscription.ts +7 -0
  753. package/examples/api-pauseSubscription.mjs +7 -0
  754. package/examples/api-pauseSubscription.ts +7 -0
  755. package/examples/api-payOrder.mjs +9 -0
  756. package/examples/api-payOrder.ts +9 -0
  757. package/examples/api-previewOrderDiscounts.mjs +6 -0
  758. package/examples/api-previewOrderDiscounts.ts +6 -0
  759. package/examples/api-previewPartnerInstallAuthorization.mjs +8 -0
  760. package/examples/api-previewPartnerInstallAuthorization.ts +8 -0
  761. package/examples/api-processExistingReturn.mjs +14 -0
  762. package/examples/api-processExistingReturn.ts +14 -0
  763. package/examples/api-publishLocationGeography.mjs +11 -0
  764. package/examples/api-publishLocationGeography.ts +11 -0
  765. package/examples/api-publishReturnPolicyRevision.mjs +16 -0
  766. package/examples/api-publishReturnPolicyRevision.ts +16 -0
  767. package/examples/api-queryCheckoutSessionPickupAvailability.mjs +7 -0
  768. package/examples/api-queryCheckoutSessionPickupAvailability.ts +7 -0
  769. package/examples/api-reactivateMeSubscription.mjs +6 -0
  770. package/examples/api-reactivateMeSubscription.ts +6 -0
  771. package/examples/api-reactivateSubscription.mjs +6 -0
  772. package/examples/api-reactivateSubscription.ts +6 -0
  773. package/examples/api-recordManualInvoicePayment.mjs +12 -0
  774. package/examples/api-recordManualInvoicePayment.ts +12 -0
  775. package/examples/api-refreshCustomerSession.mjs +9 -0
  776. package/examples/api-refreshCustomerSession.ts +9 -0
  777. package/examples/api-refreshMerchantAccountSession.mjs +8 -0
  778. package/examples/api-refreshMerchantAccountSession.ts +8 -0
  779. package/examples/api-regenerateInvoicePublicLink.mjs +6 -0
  780. package/examples/api-regenerateInvoicePublicLink.ts +6 -0
  781. package/examples/api-releaseInventoryReservation.mjs +10 -0
  782. package/examples/api-releaseInventoryReservation.ts +10 -0
  783. package/examples/api-releaseReturnResolution.mjs +9 -0
  784. package/examples/api-releaseReturnResolution.ts +9 -0
  785. package/examples/api-removeMePaymentMethod.mjs +6 -0
  786. package/examples/api-removeMePaymentMethod.ts +6 -0
  787. package/examples/api-removeOrderDiscounts.mjs +9 -0
  788. package/examples/api-removeOrderDiscounts.ts +9 -0
  789. package/examples/api-removePaymentMethod.mjs +6 -0
  790. package/examples/api-removePaymentMethod.ts +6 -0
  791. package/examples/api-reopenReturn.mjs +9 -0
  792. package/examples/api-reopenReturn.ts +9 -0
  793. package/examples/api-repriceOrderDiscounts.mjs +6 -0
  794. package/examples/api-repriceOrderDiscounts.ts +6 -0
  795. package/examples/api-resendMeOrderReceipt.mjs +6 -0
  796. package/examples/api-resendMeOrderReceipt.ts +6 -0
  797. package/examples/api-resendOrderReceipt.mjs +6 -0
  798. package/examples/api-resendOrderReceipt.ts +6 -0
  799. package/examples/api-resendWebhookDelivery.mjs +6 -0
  800. package/examples/api-resendWebhookDelivery.ts +6 -0
  801. package/examples/api-resetDemoSession.mjs +6 -0
  802. package/examples/api-resetDemoSession.ts +6 -0
  803. package/examples/api-resetDeveloperSandbox.mjs +6 -0
  804. package/examples/api-resetDeveloperSandbox.ts +6 -0
  805. package/examples/api-resolveCustomerDeletionRequest.mjs +9 -0
  806. package/examples/api-resolveCustomerDeletionRequest.ts +9 -0
  807. package/examples/api-resolveOrderInventoryException.mjs +6 -0
  808. package/examples/api-resolveOrderInventoryException.ts +6 -0
  809. package/examples/api-resolvePaymentLink.mjs +10 -0
  810. package/examples/api-resolvePaymentLink.ts +10 -0
  811. package/examples/api-resolvePromotionCode.mjs +6 -0
  812. package/examples/api-resolvePromotionCode.ts +6 -0
  813. package/examples/api-resumeInvoiceReminders.mjs +6 -0
  814. package/examples/api-resumeInvoiceReminders.ts +6 -0
  815. package/examples/api-resumeMeSubscription.mjs +6 -0
  816. package/examples/api-resumeMeSubscription.ts +6 -0
  817. package/examples/api-resumeSubscription.mjs +6 -0
  818. package/examples/api-resumeSubscription.ts +6 -0
  819. package/examples/api-retryReturnDisposition.mjs +9 -0
  820. package/examples/api-retryReturnDisposition.ts +9 -0
  821. package/examples/api-retryReturnResolution.mjs +9 -0
  822. package/examples/api-retryReturnResolution.ts +9 -0
  823. package/examples/api-reverseCreditNoteAllocation.mjs +7 -0
  824. package/examples/api-reverseCreditNoteAllocation.ts +7 -0
  825. package/examples/api-reverseManualInvoicePayment.mjs +12 -0
  826. package/examples/api-reverseManualInvoicePayment.ts +12 -0
  827. package/examples/api-revokeAPIKey.mjs +6 -0
  828. package/examples/api-revokeAPIKey.ts +6 -0
  829. package/examples/api-revokeCustomerSession.mjs +6 -0
  830. package/examples/api-revokeCustomerSession.ts +6 -0
  831. package/examples/api-revokeCustomerSessions.mjs +6 -0
  832. package/examples/api-revokeCustomerSessions.ts +6 -0
  833. package/examples/api-revokeDeliveryDependency.mjs +13 -0
  834. package/examples/api-revokeDeliveryDependency.ts +13 -0
  835. package/examples/api-revokeDeveloperPartnerAppInstall.mjs +7 -0
  836. package/examples/api-revokeDeveloperPartnerAppInstall.ts +7 -0
  837. package/examples/api-revokeDeveloperPartnerEnvironmentGrant.mjs +8 -0
  838. package/examples/api-revokeDeveloperPartnerEnvironmentGrant.ts +8 -0
  839. package/examples/api-revokeOrganizationMembership.mjs +7 -0
  840. package/examples/api-revokeOrganizationMembership.ts +7 -0
  841. package/examples/api-rotateDeliveryRateCallbackSigningKey.mjs +6 -0
  842. package/examples/api-rotateDeliveryRateCallbackSigningKey.ts +6 -0
  843. package/examples/api-rotateDeveloperPartnerAppSecret.mjs +6 -0
  844. package/examples/api-rotateDeveloperPartnerAppSecret.ts +6 -0
  845. package/examples/api-rotateWebhookSecret.mjs +6 -0
  846. package/examples/api-rotateWebhookSecret.ts +6 -0
  847. package/examples/api-saveMePaymentMethod.mjs +6 -0
  848. package/examples/api-saveMePaymentMethod.ts +6 -0
  849. package/examples/api-savePaymentMethod.mjs +8 -0
  850. package/examples/api-savePaymentMethod.ts +8 -0
  851. package/examples/api-sendInvoiceReminder.mjs +6 -0
  852. package/examples/api-sendInvoiceReminder.ts +6 -0
  853. package/examples/api-setDefaultCustomerAddress.mjs +10 -0
  854. package/examples/api-setDefaultCustomerAddress.ts +10 -0
  855. package/examples/api-setDefaultMeAddress.mjs +9 -0
  856. package/examples/api-setDefaultMeAddress.ts +9 -0
  857. package/examples/api-setDefaultMePaymentMethod.mjs +6 -0
  858. package/examples/api-setDefaultMePaymentMethod.ts +6 -0
  859. package/examples/api-setDefaultPaymentMethod.mjs +6 -0
  860. package/examples/api-setDefaultPaymentMethod.ts +6 -0
  861. package/examples/api-skipSubscriptionCycle.mjs +7 -0
  862. package/examples/api-skipSubscriptionCycle.ts +7 -0
  863. package/examples/api-startOnboarding.mjs +10 -0
  864. package/examples/api-startOnboarding.ts +10 -0
  865. package/examples/api-streamWebhookEvents.mjs +8 -0
  866. package/examples/api-streamWebhookEvents.ts +8 -0
  867. package/examples/api-transferOrganizationOwnership.mjs +9 -0
  868. package/examples/api-transferOrganizationOwnership.ts +9 -0
  869. package/examples/api-transitionFulfillment.mjs +9 -0
  870. package/examples/api-transitionFulfillment.ts +9 -0
  871. package/examples/api-transitionInventoryTransfer.mjs +17 -0
  872. package/examples/api-transitionInventoryTransfer.ts +17 -0
  873. package/examples/api-transitionPackage.mjs +9 -0
  874. package/examples/api-transitionPackage.ts +9 -0
  875. package/examples/api-updateAPIKey.mjs +7 -0
  876. package/examples/api-updateAPIKey.ts +7 -0
  877. package/examples/api-updateBundle.mjs +7 -0
  878. package/examples/api-updateBundle.ts +7 -0
  879. package/examples/api-updateCategory.mjs +7 -0
  880. package/examples/api-updateCategory.ts +7 -0
  881. package/examples/api-updateCheckoutSession.mjs +7 -0
  882. package/examples/api-updateCheckoutSession.ts +7 -0
  883. package/examples/api-updateCreditNote.mjs +7 -0
  884. package/examples/api-updateCreditNote.ts +7 -0
  885. package/examples/api-updateCustomer.mjs +7 -0
  886. package/examples/api-updateCustomer.ts +7 -0
  887. package/examples/api-updateCustomerAddress.mjs +8 -0
  888. package/examples/api-updateCustomerAddress.ts +8 -0
  889. package/examples/api-updateDeliveryLocationSet.mjs +9 -0
  890. package/examples/api-updateDeliveryLocationSet.ts +9 -0
  891. package/examples/api-updateDeliveryMethod.mjs +9 -0
  892. package/examples/api-updateDeliveryMethod.ts +9 -0
  893. package/examples/api-updateDeliveryProfile.mjs +9 -0
  894. package/examples/api-updateDeliveryProfile.ts +9 -0
  895. package/examples/api-updateDeliveryRateCallback.mjs +9 -0
  896. package/examples/api-updateDeliveryRateCallback.ts +9 -0
  897. package/examples/api-updateDeliveryZone.mjs +9 -0
  898. package/examples/api-updateDeliveryZone.ts +9 -0
  899. package/examples/api-updateDeveloperPartnerApp.mjs +7 -0
  900. package/examples/api-updateDeveloperPartnerApp.ts +7 -0
  901. package/examples/api-updateDevice.mjs +7 -0
  902. package/examples/api-updateDevice.ts +7 -0
  903. package/examples/api-updateFulfillment.mjs +7 -0
  904. package/examples/api-updateFulfillment.ts +7 -0
  905. package/examples/api-updateInventoryAllocationPolicy.mjs +7 -0
  906. package/examples/api-updateInventoryAllocationPolicy.ts +7 -0
  907. package/examples/api-updateInventoryCount.mjs +22 -0
  908. package/examples/api-updateInventoryCount.ts +22 -0
  909. package/examples/api-updateInventoryItem.mjs +7 -0
  910. package/examples/api-updateInventoryItem.ts +7 -0
  911. package/examples/api-updateInventoryLevel.mjs +10 -0
  912. package/examples/api-updateInventoryLevel.ts +10 -0
  913. package/examples/api-updateInventoryTransfer.mjs +7 -0
  914. package/examples/api-updateInventoryTransfer.ts +7 -0
  915. package/examples/api-updateInvoice.mjs +7 -0
  916. package/examples/api-updateInvoice.ts +7 -0
  917. package/examples/api-updateInvoicePaymentTerm.mjs +11 -0
  918. package/examples/api-updateInvoicePaymentTerm.ts +11 -0
  919. package/examples/api-updateLocation.mjs +7 -0
  920. package/examples/api-updateLocation.ts +7 -0
  921. package/examples/api-updateLocationInventory.mjs +9 -0
  922. package/examples/api-updateLocationInventory.ts +9 -0
  923. package/examples/api-updateMe.mjs +6 -0
  924. package/examples/api-updateMe.ts +6 -0
  925. package/examples/api-updateMeAddress.mjs +7 -0
  926. package/examples/api-updateMeAddress.ts +7 -0
  927. package/examples/api-updateMerchant.mjs +7 -0
  928. package/examples/api-updateMerchant.ts +7 -0
  929. package/examples/api-updateModifierGroup.mjs +7 -0
  930. package/examples/api-updateModifierGroup.ts +7 -0
  931. package/examples/api-updateModifierSet.mjs +7 -0
  932. package/examples/api-updateModifierSet.ts +7 -0
  933. package/examples/api-updateOrder.mjs +9 -0
  934. package/examples/api-updateOrder.ts +9 -0
  935. package/examples/api-updateOrderCharge.mjs +8 -0
  936. package/examples/api-updateOrderCharge.ts +8 -0
  937. package/examples/api-updateOrderLineItem.mjs +8 -0
  938. package/examples/api-updateOrderLineItem.ts +8 -0
  939. package/examples/api-updateOrganization.mjs +7 -0
  940. package/examples/api-updateOrganization.ts +7 -0
  941. package/examples/api-updatePackage.mjs +7 -0
  942. package/examples/api-updatePackage.ts +7 -0
  943. package/examples/api-updatePackageItem.mjs +8 -0
  944. package/examples/api-updatePackageItem.ts +8 -0
  945. package/examples/api-updatePaymentIntent.mjs +7 -0
  946. package/examples/api-updatePaymentIntent.ts +7 -0
  947. package/examples/api-updatePaymentLink.mjs +7 -0
  948. package/examples/api-updatePaymentLink.ts +7 -0
  949. package/examples/api-updatePaymentMethodDomain.mjs +9 -0
  950. package/examples/api-updatePaymentMethodDomain.ts +9 -0
  951. package/examples/api-updatePayoutDestination.mjs +7 -0
  952. package/examples/api-updatePayoutDestination.ts +7 -0
  953. package/examples/api-updatePayoutSettings.mjs +6 -0
  954. package/examples/api-updatePayoutSettings.ts +6 -0
  955. package/examples/api-updateProduct.mjs +7 -0
  956. package/examples/api-updateProduct.ts +7 -0
  957. package/examples/api-updateProductVariant.mjs +8 -0
  958. package/examples/api-updateProductVariant.ts +8 -0
  959. package/examples/api-updatePromotion.mjs +7 -0
  960. package/examples/api-updatePromotion.ts +7 -0
  961. package/examples/api-updatePromotionCode.mjs +8 -0
  962. package/examples/api-updatePromotionCode.ts +8 -0
  963. package/examples/api-updateRefund.mjs +7 -0
  964. package/examples/api-updateRefund.ts +7 -0
  965. package/examples/api-updateReturn.mjs +7 -0
  966. package/examples/api-updateReturn.ts +7 -0
  967. package/examples/api-updateReturnLineItem.mjs +8 -0
  968. package/examples/api-updateReturnLineItem.ts +8 -0
  969. package/examples/api-updateReturnPolicy.mjs +7 -0
  970. package/examples/api-updateReturnPolicy.ts +7 -0
  971. package/examples/api-updateReturnReason.mjs +7 -0
  972. package/examples/api-updateReturnReason.ts +7 -0
  973. package/examples/api-updateReturnResolution.mjs +7 -0
  974. package/examples/api-updateReturnResolution.ts +7 -0
  975. package/examples/api-updateRiskList.mjs +9 -0
  976. package/examples/api-updateRiskList.ts +9 -0
  977. package/examples/api-updateRiskRule.mjs +9 -0
  978. package/examples/api-updateRiskRule.ts +9 -0
  979. package/examples/api-updateSettings.mjs +6 -0
  980. package/examples/api-updateSettings.ts +6 -0
  981. package/examples/api-updateShipment.mjs +7 -0
  982. package/examples/api-updateShipment.ts +7 -0
  983. package/examples/api-updateSubscription.mjs +7 -0
  984. package/examples/api-updateSubscription.ts +7 -0
  985. package/examples/api-updateSubscriptionBillingSchedule.mjs +11 -0
  986. package/examples/api-updateSubscriptionBillingSchedule.ts +11 -0
  987. package/examples/api-updateSubscriptionPlan.mjs +7 -0
  988. package/examples/api-updateSubscriptionPlan.ts +7 -0
  989. package/examples/api-updateWebhookEndpoint.mjs +7 -0
  990. package/examples/api-updateWebhookEndpoint.ts +7 -0
  991. package/examples/api-verifyOnboardingEmail.mjs +9 -0
  992. package/examples/api-verifyOnboardingEmail.ts +9 -0
  993. package/examples/api-verifyReturnReceiptLineItem.mjs +11 -0
  994. package/examples/api-verifyReturnReceiptLineItem.ts +11 -0
  995. package/examples/api-voidCreditNote.mjs +6 -0
  996. package/examples/api-voidCreditNote.ts +6 -0
  997. package/examples/api-voidInvoice.mjs +6 -0
  998. package/examples/api-voidInvoice.ts +6 -0
  999. package/examples/api-voidPackage.mjs +6 -0
  1000. package/examples/api-voidPackage.ts +6 -0
  1001. package/examples/api-voidShipment.mjs +6 -0
  1002. package/examples/api-voidShipment.ts +6 -0
  1003. package/examples/api-waiveReturnLineInspection.mjs +10 -0
  1004. package/examples/api-waiveReturnLineInspection.ts +10 -0
  1005. package/examples/webhook-inbox.mjs +82 -0
  1006. package/index.d.ts +9372 -0
  1007. package/index.js +544284 -0
  1008. package/package.json +45 -0
  1009. package/runtime-plan.d.ts +50 -0
  1010. package/runtime-plan.js +187 -0
  1011. package/runtime.d.ts +192 -0
  1012. package/runtime.js +2072 -0
package/runtime.js ADDED
@@ -0,0 +1,2072 @@
1
+ import { createHmac, randomUUID, timingSafeEqual } from 'node:crypto';
2
+ import { inspect } from 'node:util';
3
+ import { compileRuntimePlan, assertRuntimePlan, } from './runtime-plan.js';
4
+ import { compileCodec, ANY_CODEC, exactValue, wireKind } from './codec-plan.js';
5
+ export { directionalSchema } from './codec-plan.js';
6
+ export class SdkError extends Error {
7
+ kind;
8
+ outcome;
9
+ retryAllowed;
10
+ meta;
11
+ code;
12
+ details;
13
+ raw;
14
+ constructor(kind, message, outcome = 'not_sent', retryAllowed = false, meta, code, details, options, raw) {
15
+ super(message, options);
16
+ this.kind = kind;
17
+ this.outcome = outcome;
18
+ this.retryAllowed = retryAllowed;
19
+ this.meta = meta;
20
+ this.code = code;
21
+ this.details = details;
22
+ this.raw = raw;
23
+ this.name = 'SdkError';
24
+ }
25
+ [inspect.custom]() {
26
+ return {
27
+ name: this.name,
28
+ kind: this.kind,
29
+ message: this.message,
30
+ outcome: this.outcome,
31
+ retryAllowed: this.retryAllowed,
32
+ requestId: this.meta?.requestId,
33
+ status: this.meta?.status,
34
+ };
35
+ }
36
+ }
37
+ // Node truncates delays above 2^31-1 to one millisecond. Keep the actual
38
+ // monotonic deadline and schedule bounded chunks, including for retry waits.
39
+ function schedule(callback, duration) {
40
+ const deadline = performance.now() + duration;
41
+ let timer;
42
+ const tick = () => {
43
+ const remaining = deadline - performance.now();
44
+ if (remaining <= 0)
45
+ callback();
46
+ else
47
+ timer = setTimeout(tick, Math.min(2147483647, Math.ceil(remaining)));
48
+ };
49
+ timer = setTimeout(tick, Math.min(2147483647, Math.max(0, Math.ceil(duration))));
50
+ return { cancel: () => clearTimeout(timer) };
51
+ }
52
+ function inspectedMetadata(meta) {
53
+ return {
54
+ status: meta.status,
55
+ requestId: meta.requestId,
56
+ attempts: meta.attempts,
57
+ durationMs: meta.durationMs,
58
+ };
59
+ }
60
+ /** A single-consumer stream. Breaking iteration releases the response connection. */
61
+ export class EventStream {
62
+ reader;
63
+ meta;
64
+ settings;
65
+ decodeEvent;
66
+ released;
67
+ closed = false;
68
+ started = false;
69
+ failure;
70
+ lifetime;
71
+ abort = () => {
72
+ this.failure = new SdkError('cancelled', 'Stream cancelled', 'response', false, this.meta);
73
+ void this.close();
74
+ };
75
+ constructor(reader, meta, settings, decodeEvent = (_event, data) => data, released = () => { }) {
76
+ this.reader = reader;
77
+ this.meta = meta;
78
+ this.settings = settings;
79
+ this.decodeEvent = decodeEvent;
80
+ this.released = released;
81
+ settings.signal?.addEventListener('abort', this.abort, { once: true });
82
+ if (settings.signal?.aborted)
83
+ this.abort();
84
+ if (settings.lifetimeMs)
85
+ this.lifetime = schedule(() => {
86
+ this.failure = new SdkError('deadline', 'Stream lifetime exceeded', 'response', false, this.meta);
87
+ void this.close();
88
+ }, settings.lifetimeMs);
89
+ }
90
+ async close() {
91
+ if (this.closed)
92
+ return;
93
+ this.closed = true;
94
+ this.lifetime?.cancel();
95
+ this.settings.signal?.removeEventListener('abort', this.abort);
96
+ this.released();
97
+ await this.reader.cancel().catch(() => { });
98
+ }
99
+ [inspect.custom]() {
100
+ return { meta: inspectedMetadata(this.meta), closed: this.closed };
101
+ }
102
+ async *[Symbol.asyncIterator]() {
103
+ if (this.started)
104
+ throw new SdkError('validation', 'A stream can only be consumed once');
105
+ this.started = true;
106
+ const decoder = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true });
107
+ let firstCharacter = true;
108
+ let line = '', data = '', event = '', id = '', skipLF = false, bytes = 0;
109
+ let retry;
110
+ const consumeLine = () => {
111
+ if (line === '') {
112
+ const frame = data === ''
113
+ ? undefined
114
+ : {
115
+ event: event || 'message',
116
+ id,
117
+ rawData: data.slice(0, -1),
118
+ data: this.decodeEvent(event || 'message', data.slice(0, -1)),
119
+ ...(retry !== undefined ? { retry } : {}),
120
+ };
121
+ if (frame)
122
+ Object.defineProperty(frame, inspect.custom, {
123
+ value: () => ({ event: frame.event }),
124
+ });
125
+ data = '';
126
+ event = '';
127
+ bytes = 0;
128
+ return frame;
129
+ }
130
+ if (!line.startsWith(':')) {
131
+ const colon = line.indexOf(':');
132
+ const field = colon < 0 ? line : line.slice(0, colon);
133
+ let value = colon < 0 ? '' : line.slice(colon + 1);
134
+ if (value.startsWith(' '))
135
+ value = value.slice(1);
136
+ if (field === 'data')
137
+ data += value + '\n';
138
+ else if (field === 'event')
139
+ event = value;
140
+ else if (field === 'id' && !value.includes('\0'))
141
+ id = value;
142
+ else if (field === 'retry' && /^\d+$/.test(value) && Number.isSafeInteger(Number(value)))
143
+ retry = Number(value);
144
+ }
145
+ line = '';
146
+ return undefined;
147
+ };
148
+ try {
149
+ while (!this.closed) {
150
+ let timer;
151
+ const next = await Promise.race([
152
+ this.reader.read(),
153
+ new Promise((_resolve, reject) => {
154
+ timer = schedule(() => reject(new SdkError('deadline', 'Stream idle timeout exceeded', 'response', false, this.meta)), this.settings.idleTimeoutMs);
155
+ }),
156
+ ]).finally(() => timer?.cancel());
157
+ if (this.failure)
158
+ throw this.failure;
159
+ if (next.done) {
160
+ decoder.decode();
161
+ break;
162
+ }
163
+ const text = decoder.decode(next.value, { stream: true });
164
+ for (const character of text) {
165
+ if (this.closed)
166
+ break;
167
+ if (firstCharacter) {
168
+ firstCharacter = false;
169
+ if (character === '\ufeff') {
170
+ bytes = 3;
171
+ if (bytes > this.settings.maxEventBytes)
172
+ throw new SdkError('protocol', 'SSE event exceeds configured size limit', 'response');
173
+ continue;
174
+ }
175
+ }
176
+ if (skipLF) {
177
+ skipLF = false;
178
+ if (character === '\n')
179
+ continue;
180
+ }
181
+ if (character === '\r' || character === '\n') {
182
+ if (++bytes > this.settings.maxEventBytes)
183
+ throw new SdkError('protocol', 'SSE event exceeds configured size limit', 'response', false, this.meta);
184
+ skipLF = character === '\r';
185
+ const frame = consumeLine();
186
+ if (frame)
187
+ yield frame;
188
+ }
189
+ else {
190
+ bytes += Buffer.byteLength(character);
191
+ if (bytes > this.settings.maxEventBytes)
192
+ throw new SdkError('protocol', 'SSE event exceeds configured size limit', 'response', false, this.meta);
193
+ line += character;
194
+ }
195
+ }
196
+ }
197
+ if (this.failure)
198
+ throw this.failure;
199
+ }
200
+ catch (cause) {
201
+ if (cause instanceof SdkError && cause.kind !== 'validation')
202
+ throw cause;
203
+ throw new SdkError('protocol', 'Invalid or interrupted SSE stream', 'response', false, this.meta, undefined, undefined, { cause });
204
+ }
205
+ finally {
206
+ await this.close();
207
+ }
208
+ }
209
+ }
210
+ const bad = (path, reason) => {
211
+ throw new SdkError('validation', `${path}: ${reason}`);
212
+ };
213
+ const exactInteger = /^-?(?:0|[1-9]\d*)$/;
214
+ const exactDecimal = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;
215
+ class RawNumber {
216
+ value;
217
+ constructor(value) {
218
+ this.value = value;
219
+ }
220
+ }
221
+ // JSON numeric meaning, established by the wire parser or a positive codec declaration.
222
+ class ParsedNumber {
223
+ value;
224
+ constructor(value) {
225
+ this.value = value;
226
+ }
227
+ }
228
+ /** An explicit JSON number for inputs whose schema also permits JSON strings. */
229
+ export class ExactNumber extends ParsedNumber {
230
+ constructor(value) {
231
+ if (typeof value !== 'string' || !exactDecimal.test(value))
232
+ bad('ExactNumber', 'expected a JSON number token');
233
+ super(value);
234
+ Object.freeze(this);
235
+ }
236
+ }
237
+ /** Parse JSON without rounding integers or decimal tokens. Unknown numeric tokens remain exact strings. */
238
+ export function parseExact(text) {
239
+ return parseJson(text);
240
+ }
241
+ function parseJson(text, preserveNumbers = false) {
242
+ let encoded = '';
243
+ let quoted = false;
244
+ let escaped = false;
245
+ for (let i = 0; i < text.length;) {
246
+ const c = text[i];
247
+ if (quoted) {
248
+ encoded += c;
249
+ i++;
250
+ if (escaped)
251
+ escaped = false;
252
+ else if (c === '\\')
253
+ escaped = true;
254
+ else if (c === '"')
255
+ quoted = false;
256
+ continue;
257
+ }
258
+ if (c === '"') {
259
+ quoted = true;
260
+ encoded += c;
261
+ i++;
262
+ continue;
263
+ }
264
+ if (c === '-' || /[0-9]/.test(c)) {
265
+ const match = text.slice(i).match(/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/);
266
+ if (!match)
267
+ throw new SyntaxError('Invalid JSON number');
268
+ const token = match[0];
269
+ const n = Number(token);
270
+ encoded +=
271
+ exactInteger.test(token) && Number.isSafeInteger(n) ? token : JSON.stringify(token);
272
+ i += token.length;
273
+ continue;
274
+ }
275
+ encoded += c;
276
+ i++;
277
+ }
278
+ // Validate original grammar as well: quoting tokens must not repair malformed JSON.
279
+ const original = JSON.parse(text);
280
+ const parsed = JSON.parse(encoded, (key, value) => {
281
+ if (/[\uD800-\uDFFF]/u.test(key) ||
282
+ (typeof value === 'string' && /[\uD800-\uDFFF]/u.test(value)))
283
+ throw new SyntaxError('JSON strings must contain well-formed Unicode');
284
+ return value;
285
+ });
286
+ // The original tree supplies only token kinds, never rounded numeric values.
287
+ const mark = (value, source) => {
288
+ if (typeof source === 'number' && typeof value === 'string')
289
+ return new ParsedNumber(value);
290
+ if (value && typeof value === 'object')
291
+ for (const key of Object.keys(value))
292
+ value[key] = mark(value[key], source[key]);
293
+ return value;
294
+ };
295
+ return preserveNumbers ? mark(parsed, original) : parsed;
296
+ }
297
+ function plainNumbers(value) {
298
+ if (value instanceof ParsedNumber)
299
+ return value.value;
300
+ if (value && typeof value === 'object')
301
+ for (const key of Object.keys(value))
302
+ value[key] = plainNumbers(value[key]);
303
+ return value;
304
+ }
305
+ /** Expand integral decimal/exponent tokens exactly, with bounded exponent expansion. */
306
+ function integerToken(token, path) {
307
+ if (exactInteger.test(token))
308
+ return token;
309
+ const [coefficient, exponent = '0'] = token.toLowerCase().split('e');
310
+ const fraction = coefficient.split('.')[1]?.length ?? 0;
311
+ let digits = coefficient.replace(/^-/, '').replace('.', '').replace(/^0+/, '');
312
+ if (!digits)
313
+ return '0';
314
+ const shift = Number(exponent) - fraction;
315
+ if (shift < 0) {
316
+ if (-shift >= digits.length || /[1-9]/.test(digits.slice(shift)))
317
+ return bad(path, 'expected an integral JSON number');
318
+ digits = digits.slice(0, shift);
319
+ }
320
+ else {
321
+ if (shift > 10000)
322
+ return bad(path, 'integer exponent expansion exceeds 10000 digits');
323
+ digits += '0'.repeat(shift);
324
+ }
325
+ return (token.startsWith('-') ? '-' : '') + digits;
326
+ }
327
+ function denseArray(value, path) {
328
+ for (let i = 0; i < value.length; i++)
329
+ if (!Object.hasOwn(value, i))
330
+ bad(`${path}[${i}]`, 'sparse arrays are unsupported');
331
+ }
332
+ function encode(value, depth = 0) {
333
+ if (depth > 256)
334
+ bad('value', 'value exceeds the supported nesting depth or contains a cycle');
335
+ if (value instanceof Model)
336
+ return encode(value.toJSON(), depth + 1);
337
+ if (value instanceof RawNumber)
338
+ return value.value;
339
+ if (value === null)
340
+ return 'null';
341
+ if (typeof value === 'string' || typeof value === 'boolean')
342
+ return JSON.stringify(value);
343
+ if (typeof value === 'number') {
344
+ if (!Number.isSafeInteger(value))
345
+ bad('value', 'use a decimal or integer string for exact numbers');
346
+ return String(value);
347
+ }
348
+ if (Array.isArray(value)) {
349
+ denseArray(value, 'value');
350
+ return '[' + value.map((v) => encode(v, depth + 1)).join(',') + ']';
351
+ }
352
+ if (value && typeof value === 'object')
353
+ return ('{' +
354
+ Object.entries(value)
355
+ .filter(([, v]) => v !== undefined)
356
+ .map(([k, v]) => JSON.stringify(k) + ':' + encode(v, depth + 1))
357
+ .join(',') +
358
+ '}');
359
+ return bad('value', 'unsupported JSON value');
360
+ }
361
+ /** Merge independently validated representations without discarding typed numeric tokens. */
362
+ function combine(left, right, path, source) {
363
+ if (left instanceof ParsedNumber || right instanceof ParsedNumber) {
364
+ const token = left instanceof ParsedNumber ? left : right;
365
+ const other = left instanceof ParsedNumber ? right : left;
366
+ const text = other instanceof ParsedNumber || other instanceof RawNumber ? other.value : String(other);
367
+ if (!exactDecimal.test(text) || compareDecimal(token.value, text) !== 0)
368
+ bad(path, 'alternatives have incompatible numeric representations');
369
+ return other instanceof RawNumber ? new RawNumber(token.value) : other;
370
+ }
371
+ if (left instanceof RawNumber || right instanceof RawNumber) {
372
+ const token = left instanceof RawNumber ? left : right;
373
+ const other = left instanceof RawNumber ? right : left;
374
+ const text = other instanceof RawNumber ? other.value : String(other);
375
+ if (!exactDecimal.test(text) || compareDecimal(token.value, text) !== 0)
376
+ bad(path, 'alternatives have incompatible numeric representations');
377
+ return token;
378
+ }
379
+ // Decoding can unwrap both numeric tokens into SDK strings before a later
380
+ // branch is merged. The shared source view proves these are JSON numbers.
381
+ if (source instanceof ParsedNumber &&
382
+ typeof left === 'string' &&
383
+ typeof right === 'string' &&
384
+ left !== right) {
385
+ if (!exactDecimal.test(left) ||
386
+ !exactDecimal.test(right) ||
387
+ compareDecimal(source.value, left) !== 0 ||
388
+ compareDecimal(source.value, right) !== 0)
389
+ bad(path, 'alternatives have incompatible numeric representations');
390
+ return source.value;
391
+ }
392
+ const childSource = (key) => source && typeof source === 'object' && Object.hasOwn(source, key)
393
+ ? source[key]
394
+ : undefined;
395
+ if (Array.isArray(left) && Array.isArray(right))
396
+ return left.map((v, i) => combine(v, right[i], `${path}[${i}]`, childSource(String(i))));
397
+ if (left && right && typeof left === 'object' && typeof right === 'object')
398
+ return Object.fromEntries([...new Set([...Object.keys(left), ...Object.keys(right)])].map((key) => [
399
+ key,
400
+ Object.hasOwn(left, key) && Object.hasOwn(right, key)
401
+ ? combine(left[key], right[key], `${path}.${key}`, childSource(key))
402
+ : Object.hasOwn(left, key)
403
+ ? left[key]
404
+ : right[key],
405
+ ]));
406
+ if (left === right)
407
+ return right;
408
+ if (typeof left === 'number' && typeof right === 'string' && String(left) === right)
409
+ return right;
410
+ if (typeof right === 'number' && typeof left === 'string' && String(right) === left)
411
+ return left;
412
+ return bad(path, 'alternatives have incompatible representations');
413
+ }
414
+ // Compare finite decimal tokens without floating-point conversion or expanding
415
+ // exponents. Bounds originate in the contract; even enormous caller exponents
416
+ // can be ordered against them with bounded memory.
417
+ function compareDecimal(left, right) {
418
+ const parts = (value) => {
419
+ const [coefficient, exponent = '0'] = value.toLowerCase().split('e');
420
+ const negative = coefficient.startsWith('-');
421
+ const unsigned = coefficient.replace(/^-/, '');
422
+ const fraction = unsigned.split('.')[1]?.length ?? 0;
423
+ const digits = unsigned.replace('.', '').replace(/^0+/, '');
424
+ const power = Math.max(-1e9, Math.min(1e9, Number(exponent))) - fraction + digits.length;
425
+ return { sign: digits ? (negative ? -1 : 1) : 0, digits, power };
426
+ };
427
+ const a = parts(left), b = parts(right);
428
+ if (a.sign !== b.sign)
429
+ return Math.sign(a.sign - b.sign);
430
+ if (!a.sign)
431
+ return 0;
432
+ if (a.power !== b.power)
433
+ return a.sign * Math.sign(a.power - b.power);
434
+ const size = Math.max(a.digits.length, b.digits.length);
435
+ const x = a.digits.padEnd(size, '0'), y = b.digits.padEnd(size, '0');
436
+ return a.sign * (x < y ? -1 : x > y ? 1 : 0);
437
+ }
438
+ // Collision-free JSON value identity: numeric spellings and object key order
439
+ // are immaterial, while arrays and JSON strings retain their own identity.
440
+ function jsonIdentity(value, depth = 0) {
441
+ if (depth > 256)
442
+ return bad('value', 'JSON equality exceeds nesting limit or contains a cycle');
443
+ if (value instanceof ParsedNumber || value instanceof RawNumber || typeof value === 'number') {
444
+ const text = typeof value === 'number' ? String(value) : value.value;
445
+ const [coefficient = '', exponent = '0'] = text.toLowerCase().split('e');
446
+ const fraction = coefficient.split('.')[1]?.length ?? 0;
447
+ const digits = coefficient.replace(/[-.]/g, '').replace(/^0+/, '');
448
+ const trimmed = digits.replace(/0+$/, '');
449
+ if (!trimmed)
450
+ return '["number","0"]';
451
+ return JSON.stringify([
452
+ 'number',
453
+ coefficient.startsWith('-') ? '-' + trimmed : trimmed,
454
+ String(BigInt(exponent) - BigInt(fraction) + BigInt(digits.length - trimmed.length)),
455
+ ]);
456
+ }
457
+ if (Array.isArray(value))
458
+ return JSON.stringify(['array', value.map((child) => jsonIdentity(child, depth + 1))]);
459
+ if (value && typeof value === 'object')
460
+ return JSON.stringify([
461
+ 'object',
462
+ Object.entries(value)
463
+ .filter(([, child]) => child !== undefined)
464
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
465
+ .map(([key, child]) => [key, jsonIdentity(child, depth + 1)]),
466
+ ]);
467
+ return JSON.stringify([typeof value, value]);
468
+ }
469
+ function decimalMultiple(token, divisor, path) {
470
+ const parts = (text) => {
471
+ const [coefficient = '', exponent = '0'] = text.toLowerCase().split('e');
472
+ const fraction = coefficient.split('.')[1]?.length ?? 0;
473
+ const digits = coefficient.replace(/[-.]/g, '').replace(/^0+/, '');
474
+ const trimmed = digits.replace(/0+$/, '');
475
+ return {
476
+ digits: trimmed,
477
+ power: Math.max(-1e9, Math.min(1e9, Number(exponent))) - fraction + digits.length - trimmed.length,
478
+ };
479
+ };
480
+ const a = parts(token), b = parts(divisor);
481
+ if (!a.digits)
482
+ return true;
483
+ const shift = a.power - b.power;
484
+ if (shift < 0)
485
+ return false;
486
+ if (b.digits === '1')
487
+ return true;
488
+ if (shift > 10000)
489
+ return bad(path, 'multipleOf exponent expansion exceeds 10000 digits');
490
+ return BigInt(a.digits + '0'.repeat(shift)) % BigInt(b.digits) === 0n;
491
+ }
492
+ function numericConstraints(token, s, path, full = true) {
493
+ const range = s.range;
494
+ if (range && (compareDecimal(token, range[0]) < 0 || compareDecimal(token, range[1]) > 0))
495
+ bad(path, 'value is outside the declared integer format range');
496
+ if (!full)
497
+ return;
498
+ if (s.checks.multipleOf !== undefined &&
499
+ !decimalMultiple(token, String(s.checks.multipleOf), path))
500
+ bad(path, 'value violates multipleOf');
501
+ for (const keyword of ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum']) {
502
+ if (s.checks[keyword] === undefined)
503
+ continue;
504
+ const order = compareDecimal(token, String(s.checks[keyword]));
505
+ if ((keyword === 'minimum' && order < 0) ||
506
+ (keyword === 'maximum' && order > 0) ||
507
+ (keyword === 'exclusiveMinimum' && order <= 0) ||
508
+ (keyword === 'exclusiveMaximum' && order >= 0))
509
+ bad(path, 'value violates ' + keyword);
510
+ }
511
+ }
512
+ export function normalize(value, s, path = 'input', response = false, redactFields = [], matching = false, definitions = {}, depth = 0, validateConstraints = true, allowUnknownResponseFields = false) {
513
+ return executeCodec(value, compileCodec(schemaWithDefinitions(s, definitions)), {
514
+ ...codecMode(response, matching),
515
+ path,
516
+ redactFields,
517
+ depth,
518
+ validateConstraints,
519
+ allowUnknownResponseFields,
520
+ });
521
+ }
522
+ function schemaWithDefinitions(schema, definitions) {
523
+ return Object.keys(definitions).length && !schema['x-sdk-definitions']
524
+ ? { ...schema, 'x-sdk-definitions': definitions }
525
+ : schema;
526
+ }
527
+ function codecMode(response, matching) {
528
+ return matching
529
+ ? { mode: 'match', direction: response ? 'response' : 'request' }
530
+ : { mode: response ? 'response' : 'request' };
531
+ }
532
+ /** Keep branch selection identical during numeric interpretation and validation. */
533
+ function selectAlternatives(value, branches, oneOf, tag, context, matches) {
534
+ const response = (context.direction ?? context.mode) === 'response';
535
+ const matching = context.mode === 'match';
536
+ const path = context.path ?? 'input';
537
+ let tolerateUnknownFields = context.allowUnknownResponseFields ?? false;
538
+ let selected;
539
+ if (oneOf && tag) {
540
+ if (!value ||
541
+ typeof value !== 'object' ||
542
+ Array.isArray(value) ||
543
+ !Object.hasOwn(value, tag) ||
544
+ typeof value[tag] !== 'string')
545
+ bad(path, 'expected a string discriminator');
546
+ selected = branches.filter((branch) => (branch.tagValues ?? branch.fields?.[tag]?.members)?.some((member) => member === value[tag]));
547
+ }
548
+ else {
549
+ // anyOf response selection always uses the compatible set. Computing the
550
+ // discarded closed set first doubles work at each recursive anyOf edge.
551
+ selected =
552
+ !oneOf && response && (!matching || tolerateUnknownFields)
553
+ ? []
554
+ : branches.filter((branch) => matches(branch, false));
555
+ // Prefer closed oneOf matches before tolerating new response fields. anyOf
556
+ // retains every compatible branch's declared numeric representations.
557
+ if ((!oneOf || !selected.length) && response && (!matching || tolerateUnknownFields)) {
558
+ const compatible = branches.filter((branch) => matches(branch, true));
559
+ if (!oneOf || compatible.length === 1) {
560
+ selected = compatible;
561
+ tolerateUnknownFields = true;
562
+ }
563
+ }
564
+ }
565
+ if (!selected.length && response && !matching) {
566
+ if (branches.every((branch) => branch.objectOnlyAlternative) &&
567
+ (!value || typeof value !== 'object' || Array.isArray(value)))
568
+ bad(path, 'expected an object response alternative');
569
+ }
570
+ else if (!selected.length || (oneOf && selected.length !== 1)) {
571
+ bad(path, oneOf
572
+ ? 'value must match exactly one alternative'
573
+ : 'value must match at least one alternative');
574
+ }
575
+ return { selected, tolerateUnknownFields };
576
+ }
577
+ function conditionalBranch(value, { codec, definitions }, context) {
578
+ if (!codec.when)
579
+ return undefined;
580
+ let matched = true;
581
+ try {
582
+ executeNode(value, codec.when.test, {
583
+ ...codecMode((context.direction ?? context.mode) === 'response', true),
584
+ path: context.path ?? 'input',
585
+ depth: (context.depth ?? 0) + 1,
586
+ definitions,
587
+ allowUnknownResponseFields: false,
588
+ });
589
+ }
590
+ catch (error) {
591
+ if (!(error instanceof SdkError) || error.kind !== 'validation')
592
+ throw error;
593
+ matched = false;
594
+ }
595
+ return matched ? codec.when.then : codec.when.else;
596
+ }
597
+ const numericSearchLimit = 256;
598
+ /** Resolve circular dependencies only after ordinary union selection stalls.
599
+ * A hypothesis contributes numeric meaning only if its branches are selected
600
+ * by the original unions, including their oneOf and response-tolerance policies.
601
+ */
602
+ function jointNumericView(value, unions, context) {
603
+ if (unions.length < 2)
604
+ return undefined;
605
+ const convertible = (child, depth = 0) => {
606
+ if (depth > 256)
607
+ bad(context.path ?? 'input', 'value exceeds supported nesting depth or contains a cycle');
608
+ if (typeof child === 'string')
609
+ return exactDecimal.test(child);
610
+ if (child instanceof ParsedNumber || child instanceof RawNumber)
611
+ return false;
612
+ if (child instanceof Model)
613
+ child = modelInputs.get(child) ?? child.toJSON();
614
+ return Boolean(child &&
615
+ typeof child === 'object' &&
616
+ Object.values(child).some((value) => convertible(value, depth + 1)));
617
+ };
618
+ if (!convertible(value))
619
+ return undefined;
620
+ const path = context.path ?? 'input';
621
+ // An explicitly string-valued field cannot change under a numeric hypothesis.
622
+ // Reuse full validation for these fields to prune incompatible literal tags.
623
+ const choices = unions.map(({ codec, definitions, branches }) => branches.filter((branch) => {
624
+ if ((branches === codec.exactlyOne && codec.tag) || !value || typeof value !== 'object')
625
+ return true;
626
+ try {
627
+ for (const [key, field] of Object.entries(branch.fields ?? {}))
628
+ if (field.value.kind === 'string' && Object.hasOwn(value, key))
629
+ executeNode(value[key], field, {
630
+ ...codecMode((context.direction ?? context.mode) === 'response', true),
631
+ definitions: branch.definitions ?? codec.definitions ?? definitions,
632
+ path: `${path}.${key}`,
633
+ depth: (context.depth ?? 0) + 1,
634
+ });
635
+ return true;
636
+ }
637
+ catch (error) {
638
+ if (error instanceof SdkError && error.kind === 'validation')
639
+ return false;
640
+ throw error;
641
+ }
642
+ }));
643
+ function* groups(branches, multiple, start = 0, prefix = []) {
644
+ for (let i = start; i < branches.length; i++) {
645
+ const branch = branches[i];
646
+ if (!branch)
647
+ continue;
648
+ const selected = [...prefix, branch];
649
+ yield selected;
650
+ if (multiple)
651
+ yield* groups(branches, true, i + 1, selected);
652
+ }
653
+ }
654
+ const chosen = [];
655
+ const search = (index) => {
656
+ const scope = unions[index];
657
+ if (scope) {
658
+ for (const branches of groups(choices[index] ?? [], scope.branches === scope.codec.some)) {
659
+ chosen.push({ scope, branches });
660
+ const found = search(index + 1);
661
+ chosen.pop();
662
+ if (found)
663
+ return found;
664
+ }
665
+ return undefined;
666
+ }
667
+ const remaining = context.search.remaining.get(path) ?? numericSearchLimit;
668
+ context.search.remaining.set(path, remaining - 1);
669
+ if (remaining <= 0) {
670
+ context.search.exhausted = true;
671
+ bad(path, 'numeric interpretation exceeds 256 alternative combinations');
672
+ }
673
+ try {
674
+ const candidate = numericView(value, chosen.flatMap(({ scope, branches }) => branches.map((codec) => ({ codec, definitions: scope.definitions }))), { ...context, depth: (context.depth ?? 0) + 1 });
675
+ if (!numericViewChanged(value, candidate))
676
+ return undefined;
677
+ for (const { scope, branches } of chosen) {
678
+ const branchContext = {
679
+ ...codecMode((context.direction ?? context.mode) === 'response', true),
680
+ path: context.path ?? 'input',
681
+ definitions: scope.definitions,
682
+ depth: (context.depth ?? 0) + 1,
683
+ };
684
+ const { selected } = selectAlternatives(candidate, scope.branches, scope.branches === scope.codec.exactlyOne, scope.codec.tag, context, (branch, allowUnknownResponseFields) => {
685
+ try {
686
+ executeNode(candidate, branch, { ...branchContext, allowUnknownResponseFields });
687
+ return true;
688
+ }
689
+ catch (error) {
690
+ if (error instanceof SdkError && error.kind === 'validation')
691
+ return false;
692
+ throw error;
693
+ }
694
+ });
695
+ if (branches.some((branch) => !selected.includes(branch)))
696
+ return undefined;
697
+ // Untagged selection fully validates its branches. Tagged selection
698
+ // deliberately leaves other constraints to the caller's validation mode.
699
+ }
700
+ return { value: candidate };
701
+ }
702
+ catch (error) {
703
+ if (context.search.exhausted)
704
+ throw error;
705
+ if (error instanceof SdkError && error.kind === 'validation')
706
+ return undefined;
707
+ throw error;
708
+ }
709
+ };
710
+ return search(0);
711
+ }
712
+ /** Interpretation only adds numeric meaning; unchanged subtrees need no traversal. */
713
+ function numericViewChanged(before, after, depth = 0) {
714
+ if (before === after || depth > 256)
715
+ return false;
716
+ if (after instanceof ParsedNumber)
717
+ return !(before instanceof ParsedNumber);
718
+ if (!before || !after || typeof before !== 'object' || typeof after !== 'object')
719
+ return false;
720
+ return Object.entries(after).some(([key, child]) => numericViewChanged(before[key], child, depth + 1));
721
+ }
722
+ /** Branch views differ only in established numeric meaning, never in JSON data. */
723
+ function mergeNumericViews(left, right, depth = 0) {
724
+ if (depth > 256)
725
+ bad('value', 'value exceeds the supported nesting depth (256) or contains a cycle');
726
+ if (left === right || left instanceof ParsedNumber)
727
+ return left;
728
+ if (right instanceof ParsedNumber)
729
+ return right;
730
+ if (left instanceof Model)
731
+ left = left.toJSON();
732
+ if (right instanceof Model)
733
+ right = right.toJSON();
734
+ if (!left || !right || typeof left !== 'object' || typeof right !== 'object')
735
+ return left;
736
+ if (Array.isArray(left)) {
737
+ const children = left.map((child, index) => mergeNumericViews(child, right[index], depth + 1));
738
+ return children.every((child, index) => child === left[index]) ? left : children;
739
+ }
740
+ const entries = Object.entries(left).map(([key, child]) => [key, mergeNumericViews(child, right[key], depth + 1)]);
741
+ if (entries.every(([key, child]) => child === left[key]))
742
+ return left;
743
+ return Object.fromEntries(entries);
744
+ }
745
+ /** Follow same-instance declarations with the registry of each reference. */
746
+ function codecShapes(scopes, path, depth, alternatives) {
747
+ const shapes = [];
748
+ const collect = ({ codec, definitions }, level) => {
749
+ if (level > 256)
750
+ bad(path, 'value exceeds the supported nesting depth (256) or contains a cycle');
751
+ definitions = codec.definitions ?? definitions;
752
+ if (codec.reference) {
753
+ const target = Object.hasOwn(definitions, codec.reference)
754
+ ? definitions[codec.reference]
755
+ : undefined;
756
+ if (!target)
757
+ bad(path, 'unresolved recursive model ' + codec.reference);
758
+ collect({ codec: target, definitions }, level + 1);
759
+ }
760
+ else {
761
+ shapes.push({ codec, definitions });
762
+ for (const child of [
763
+ ...(codec.every ?? []),
764
+ ...(alternatives?.({ codec, definitions }) ?? []),
765
+ ])
766
+ collect({ codec: child, definitions }, level + 1);
767
+ }
768
+ };
769
+ scopes.forEach((scope) => collect(scope, depth));
770
+ return shapes;
771
+ }
772
+ /** Every added number must still have a positive declaration in the final selection.
773
+ * Interpretation can invalidate a previously matching branch through negation.
774
+ * Validate provenance before any encoding, including fields accepted as unknown.
775
+ */
776
+ function assertNumericSources(source, value, scopes, context) {
777
+ if (source instanceof Model)
778
+ source = source.toJSON();
779
+ if (!numericViewChanged(source, value))
780
+ return;
781
+ const path = context.path ?? 'input';
782
+ const depth = context.depth ?? 0;
783
+ const shapes = codecShapes(scopes, path, depth, ({ codec, definitions }) => {
784
+ const conditional = conditionalBranch(value, { codec, definitions }, context);
785
+ return [
786
+ ...(conditional ? [conditional] : []),
787
+ ...[codec.exactlyOne, codec.some].flatMap((branches) => {
788
+ if (!branches)
789
+ return [];
790
+ return selectAlternatives(value, branches, branches === codec.exactlyOne, codec.tag, context, (branch, allowUnknownResponseFields) => {
791
+ try {
792
+ executeNode(value, branch, {
793
+ ...codecMode((context.direction ?? context.mode) === 'response', true),
794
+ path,
795
+ depth: depth + 1,
796
+ definitions,
797
+ allowUnknownResponseFields,
798
+ });
799
+ return true;
800
+ }
801
+ catch (error) {
802
+ if (error instanceof SdkError && error.kind === 'validation')
803
+ return false;
804
+ throw error;
805
+ }
806
+ }).selected;
807
+ }),
808
+ ];
809
+ });
810
+ if (value instanceof ParsedNumber) {
811
+ if (!shapes.some(({ codec }) => exactValue(codec.value)))
812
+ bad(path, 'numeric interpretation depends on an unmatched alternative');
813
+ return;
814
+ }
815
+ if (!value || typeof value !== 'object')
816
+ return;
817
+ const original = source && typeof source === 'object' ? source : {};
818
+ for (const [key, child] of Object.entries(value)) {
819
+ const children = shapes.flatMap(({ codec, definitions }) => {
820
+ const field = Array.isArray(value)
821
+ ? codec.element
822
+ : Object.hasOwn(codec.fields ?? {}, key)
823
+ ? codec.fields?.[key]
824
+ : typeof codec.extra === 'object'
825
+ ? codec.extra
826
+ : undefined;
827
+ return field ? [{ codec: field, definitions }] : [];
828
+ });
829
+ assertNumericSources(original[key], child, children, {
830
+ ...context,
831
+ path: Array.isArray(value) ? `${path}[${key}]` : `${path}.${key}`,
832
+ depth: depth + 1,
833
+ });
834
+ }
835
+ }
836
+ /** Give every conjunct the same JSON numeric view of caller-owned SDK values.
837
+ * Walk the finite value, resolving named shapes as needed; never expand a recursive
838
+ * schema or infer a number from a string without a positive numeric declaration.
839
+ * Alternative candidates establish their own view before full branch matching.
840
+ */
841
+ function numericView(value, scopes, context, previous) {
842
+ if (!scopes.length)
843
+ return value;
844
+ // Revisit a matched branch only where another branch added numeric meaning.
845
+ // The previous view was computed with these same scopes and direction policy.
846
+ if (previous && !numericViewChanged(previous.value, value))
847
+ return value;
848
+ const previousChild = (key) => previous && previous.value && typeof previous.value === 'object'
849
+ ? { value: previous.value[key] }
850
+ : undefined;
851
+ const depth = context.depth ?? 0;
852
+ const path = context.path ?? 'input';
853
+ if (context.search.exhausted)
854
+ bad(path, 'numeric interpretation exceeds 256 alternative combinations');
855
+ if (depth > 256)
856
+ bad(path, 'value exceeds the supported nesting depth (256) or contains a cycle');
857
+ if (value instanceof Model)
858
+ value = modelInputs.get(value) ?? value.toJSON();
859
+ const shapes = codecShapes(scopes, path, depth);
860
+ if (typeof value === 'string' &&
861
+ shapes.some(({ codec }) => exactValue(codec.value) &&
862
+ codec.numberInput !== 'explicit' &&
863
+ (codec.value.kind === 'exact-integer' ? exactInteger : exactDecimal).test(value)))
864
+ value = new ParsedNumber(value);
865
+ if (Array.isArray(value)) {
866
+ const children = shapes.flatMap(({ codec, definitions }) => codec.element ? [{ codec: codec.element, definitions }] : []);
867
+ if (children.length) {
868
+ denseArray(value, path);
869
+ value = value.map((child, i) => numericView(child, children, { ...context, path: `${path}[${i}]`, depth: depth + 1 }, previousChild(String(i))));
870
+ }
871
+ }
872
+ else if (value && typeof value === 'object' && !(value instanceof ParsedNumber)) {
873
+ value = Object.fromEntries(Object.entries(value).map(([key, child]) => {
874
+ // Request omission is decided before a property's union is matched.
875
+ // Required fields are still checked by executeNode on the parent.
876
+ if (child === undefined && (context.direction ?? context.mode) !== 'response')
877
+ return [key, child];
878
+ const children = shapes.flatMap(({ codec, definitions }) => {
879
+ const field = Object.hasOwn(codec.fields ?? {}, key)
880
+ ? codec.fields[key]
881
+ : typeof codec.extra === 'object'
882
+ ? codec.extra
883
+ : undefined;
884
+ return field ? [{ codec: field, definitions }] : [];
885
+ });
886
+ return [
887
+ key,
888
+ numericView(child, children, { ...context, path: `${path}.${key}`, depth: depth + 1 }, previousChild(key)),
889
+ ];
890
+ }));
891
+ }
892
+ const unions = shapes.flatMap(({ codec, definitions }) => [codec.exactlyOne, codec.some].flatMap((branches) => branches ? [{ codec, definitions, branches }] : []));
893
+ let pending = unions;
894
+ // A constraint-only union may need the numeric view supplied by another
895
+ // conjunct. Retry it after successful selections, independent of allOf order.
896
+ // Each productive pass removes a union. If no selection can progress, retain
897
+ // the validation failure rather than returning a partially interpreted value.
898
+ while (pending.length) {
899
+ const before = value;
900
+ const deferred = [];
901
+ let failure;
902
+ for (const scope of pending) {
903
+ const { codec, definitions, branches } = scope;
904
+ try {
905
+ const candidates = new Map();
906
+ const { selected, tolerateUnknownFields } = selectAlternatives(value, branches, branches === codec.exactlyOne, codec.tag, context, (branch, allowUnknownFields) => {
907
+ try {
908
+ const branchContext = {
909
+ ...codecMode((context.direction ?? context.mode) === 'response', true),
910
+ search: context.search,
911
+ path,
912
+ definitions,
913
+ depth: depth + 1,
914
+ allowUnknownResponseFields: allowUnknownFields,
915
+ };
916
+ const candidate = numericView(value, [{ codec: branch, definitions }], branchContext);
917
+ executeNode(candidate, branch, branchContext);
918
+ candidates.set(branch, candidate);
919
+ return true;
920
+ }
921
+ catch (error) {
922
+ if (error instanceof SdkError && error.kind === 'validation')
923
+ return false;
924
+ throw error;
925
+ }
926
+ });
927
+ if (!selected.length) {
928
+ deferred.push(scope);
929
+ continue;
930
+ }
931
+ // Reuse every matched view. Rewalking all selected branches makes
932
+ // overlapping recursive anyOf schemas exponential even without numbers.
933
+ if (selected.every((branch) => candidates.has(branch))) {
934
+ for (const branch of selected)
935
+ value = mergeNumericViews(value, candidates.get(branch));
936
+ let changed;
937
+ do {
938
+ const beforeRefinement = value;
939
+ for (const branch of selected) {
940
+ const candidate = candidates.get(branch);
941
+ if (!numericViewChanged(candidate, value))
942
+ continue;
943
+ const refined = numericView(value, [{ codec: branch, definitions }], {
944
+ ...codecMode((context.direction ?? context.mode) === 'response', true),
945
+ search: context.search,
946
+ path,
947
+ depth: depth + 1,
948
+ allowUnknownResponseFields: tolerateUnknownFields,
949
+ }, { value: candidate });
950
+ candidates.set(branch, refined);
951
+ value = mergeNumericViews(value, refined);
952
+ }
953
+ changed = numericViewChanged(beforeRefinement, value);
954
+ } while (changed);
955
+ }
956
+ else {
957
+ value = numericView(value, selected.map((branch) => ({ codec: branch, definitions })), {
958
+ ...context,
959
+ depth: depth + 1,
960
+ allowUnknownResponseFields: tolerateUnknownFields,
961
+ });
962
+ }
963
+ }
964
+ catch (error) {
965
+ if (!(error instanceof SdkError) || error.kind !== 'validation')
966
+ throw error;
967
+ failure ??= error;
968
+ deferred.push(scope);
969
+ }
970
+ }
971
+ // An earlier anyOf may gain compatible numeric branches after a later
972
+ // conjunct supplies their required numeric context. Retry all unions only
973
+ // when numeric meaning changed; single recursive unions keep their fast path.
974
+ if (unions.length > 1 && numericViewChanged(before, value)) {
975
+ pending = unions;
976
+ continue;
977
+ }
978
+ if (deferred.length === pending.length) {
979
+ const joint = jointNumericView(value, unions, context);
980
+ if (joint) {
981
+ value = joint.value;
982
+ pending = unions;
983
+ continue;
984
+ }
985
+ if (failure)
986
+ throw failure;
987
+ break;
988
+ }
989
+ pending = deferred;
990
+ }
991
+ if (context.search.exhausted)
992
+ bad(path, 'numeric interpretation exceeds 256 alternative combinations');
993
+ for (const scope of shapes) {
994
+ const branch = conditionalBranch(value, scope, context);
995
+ if (branch)
996
+ value = numericView(value, [{ codec: branch, definitions: scope.definitions }], {
997
+ ...context,
998
+ depth: depth + 1,
999
+ });
1000
+ }
1001
+ return value;
1002
+ }
1003
+ /** Internal descriptor entry point. Raw schemas are accepted only by the adapter above. */
1004
+ export function executeCodec(value, s, context) {
1005
+ if (!['request', 'response', 'match'].includes(context.mode))
1006
+ throw new Error('Unknown codec execution mode');
1007
+ const scopes = [{ codec: s, definitions: context.definitions ?? {} }];
1008
+ const interpreted = numericView(value, scopes, {
1009
+ ...context,
1010
+ search: { remaining: new Map(), exhausted: false },
1011
+ });
1012
+ assertNumericSources(value, interpreted, scopes, context);
1013
+ return executeNode(interpreted, s, context);
1014
+ }
1015
+ function executeNode(value, s, context) {
1016
+ const { path = 'input', redactFields = [], depth = 0, allowUnknownResponseFields = false, } = context;
1017
+ const response = (context.direction ?? context.mode) === 'response';
1018
+ const matching = context.mode === 'match';
1019
+ let validateConstraints = s.constraints ?? context.validateConstraints ?? true;
1020
+ let definitions = s.definitions ?? context.definitions ?? {};
1021
+ if ((!response || matching) &&
1022
+ s.literal !== undefined &&
1023
+ jsonIdentity(value) !== jsonIdentity(parseJson(s.literal, true)))
1024
+ bad(path, 'value is outside the declared const');
1025
+ if (depth > 256)
1026
+ bad(path, 'value exceeds the supported nesting depth (256) or contains a cycle');
1027
+ if (s.reference) {
1028
+ const target = Object.hasOwn(definitions, s.reference) ? definitions[s.reference] : undefined;
1029
+ if (!target)
1030
+ return bad(path, 'unresolved recursive model ' + s.reference);
1031
+ return executeNode(value, target, {
1032
+ ...codecMode(response, matching),
1033
+ path: path,
1034
+ redactFields: redactFields,
1035
+ definitions: definitions,
1036
+ depth: depth + 1,
1037
+ validateConstraints: validateConstraints,
1038
+ allowUnknownResponseFields: allowUnknownResponseFields,
1039
+ });
1040
+ }
1041
+ if (value instanceof Model)
1042
+ value = modelInputs.get(value) ?? value.toJSON();
1043
+ wireKind(s.value); // Exhaustively reject unknown instruction kinds.
1044
+ if (s.every || s.some || s.exactlyOne || s.exclude || s.when) {
1045
+ const { every: allOf, some: anyOf, exactlyOne: oneOf, exclude: not, tag: discriminator, when, ...base } = s;
1046
+ let result = executeNode(value, base, {
1047
+ ...codecMode(response, matching),
1048
+ path: path,
1049
+ redactFields: redactFields,
1050
+ definitions: definitions,
1051
+ depth: depth + 1,
1052
+ validateConstraints: validateConstraints,
1053
+ allowUnknownResponseFields: allowUnknownResponseFields,
1054
+ });
1055
+ // Matching executes the complete branch. Reuse that result when this node
1056
+ // is itself matching; re-executing each selected recursive branch doubles
1057
+ // the work at every value depth. Ordinary decoding/encoding still runs in
1058
+ // its own mode, whose enum, bound and unknown-field policies differ.
1059
+ const matched = new Map();
1060
+ const matches = (branch, allowUnknownFields) => {
1061
+ try {
1062
+ const result = executeNode(value, branch, {
1063
+ ...codecMode(response, true),
1064
+ path: path,
1065
+ redactFields: redactFields,
1066
+ definitions: definitions,
1067
+ depth: depth + 1,
1068
+ validateConstraints: validateConstraints,
1069
+ allowUnknownResponseFields: allowUnknownFields,
1070
+ });
1071
+ const results = matched.get(branch) ?? new Map();
1072
+ results.set(allowUnknownFields, result);
1073
+ matched.set(branch, results);
1074
+ return true;
1075
+ }
1076
+ catch (error) {
1077
+ if (error instanceof SdkError && error.kind === 'validation')
1078
+ return false;
1079
+ throw error;
1080
+ }
1081
+ };
1082
+ if (not && matches(not, false))
1083
+ bad(path, 'value matches a forbidden combination');
1084
+ const conditional = conditionalBranch(value, { codec: s, definitions }, context);
1085
+ for (const branch of [...(allOf ?? []), ...(conditional ? [conditional] : [])])
1086
+ result = combine(result, executeNode(value, branch, {
1087
+ ...codecMode(response, matching),
1088
+ path: path,
1089
+ redactFields: redactFields,
1090
+ definitions: definitions,
1091
+ depth: depth + 1,
1092
+ validateConstraints: validateConstraints,
1093
+ allowUnknownResponseFields: allowUnknownResponseFields,
1094
+ }), path, value);
1095
+ for (const [keyword, branches] of [
1096
+ ['oneOf', oneOf],
1097
+ ['anyOf', anyOf],
1098
+ ]) {
1099
+ if (!branches)
1100
+ continue;
1101
+ const { selected, tolerateUnknownFields } = selectAlternatives(value, branches, keyword === 'oneOf', discriminator, context, matches);
1102
+ for (const branch of selected) {
1103
+ const results = matched.get(branch);
1104
+ result = combine(result, matching && results?.has(tolerateUnknownFields)
1105
+ ? results.get(tolerateUnknownFields)
1106
+ : executeNode(value, branch, {
1107
+ ...codecMode(response, matching),
1108
+ path: path,
1109
+ redactFields: redactFields,
1110
+ definitions: definitions,
1111
+ depth: depth + 1,
1112
+ validateConstraints: validateConstraints,
1113
+ allowUnknownResponseFields: tolerateUnknownFields,
1114
+ }), path, value);
1115
+ }
1116
+ }
1117
+ if (response &&
1118
+ result &&
1119
+ typeof result === 'object' &&
1120
+ !Array.isArray(result) &&
1121
+ !(result instanceof ParsedNumber)) {
1122
+ const object = Object.assign(Object.create(null), result);
1123
+ Object.defineProperty(object, inspect.custom, {
1124
+ value: () => redactCodec(object, s, redactFields, definitions),
1125
+ });
1126
+ return object;
1127
+ }
1128
+ return result;
1129
+ }
1130
+ if (value === null) {
1131
+ if ((!response || matching) && s.members && !s.members.includes(null))
1132
+ bad(path, 'null is outside the declared enum');
1133
+ if (s.nullable)
1134
+ return null;
1135
+ return bad(path, 'null is not permitted');
1136
+ }
1137
+ const type = wireKind(s.value);
1138
+ // Positive declarations establish numeric meaning in numericView before
1139
+ // matching. A remaining string is JSON text, including inside a negation;
1140
+ // the numeric branch being tested must not reinterpret it as an SDK number.
1141
+ if ((matching || (!response && s.numberInput === 'explicit')) &&
1142
+ exactValue(s.value) &&
1143
+ typeof value === 'string')
1144
+ return bad(path, `expected ${type}; received a JSON string`);
1145
+ if (value instanceof ParsedNumber) {
1146
+ if (type === undefined) {
1147
+ const token = value.value;
1148
+ if ((!response || matching) &&
1149
+ s.members &&
1150
+ !s.members.some((v) => typeof v === 'number' && compareDecimal(token, String(v)) === 0))
1151
+ bad(path, 'value is outside the declared enum');
1152
+ if (!response || matching)
1153
+ numericConstraints(value.value, s, path, validateConstraints || matching);
1154
+ return response ? value : new RawNumber(value.value);
1155
+ }
1156
+ if (type === 'integer') {
1157
+ const token = integerToken(value.value, path);
1158
+ value = exactValue(s.value) ? token : Number(token);
1159
+ }
1160
+ else if (type === 'number')
1161
+ value = value.value;
1162
+ else
1163
+ return bad(path, `expected ${type}; received a JSON number`);
1164
+ }
1165
+ const exactEnum = exactValue(s.value);
1166
+ if ((!response || matching) &&
1167
+ s.members &&
1168
+ !(exactEnum
1169
+ ? (typeof value === 'string' || typeof value === 'number') &&
1170
+ exactDecimal.test(String(value)) &&
1171
+ s.members.some((member) => typeof member === 'number' && compareDecimal(String(value), String(member)) === 0)
1172
+ : s.members.some((member) => member === value)))
1173
+ bad(path, 'value is outside the declared enum');
1174
+ if (type === 'integer' || type === 'number') {
1175
+ const exact = exactValue(s.value);
1176
+ if (exact) {
1177
+ const token = typeof value === 'number' && Number.isSafeInteger(value) ? String(value) : value;
1178
+ if (typeof token !== 'string' ||
1179
+ !(type === 'integer' ? exactInteger : exactDecimal).test(token))
1180
+ return bad(path, 'expected an exact numeric string');
1181
+ if (!response || matching)
1182
+ numericConstraints(token, s, path, validateConstraints || matching);
1183
+ return response ? token : new RawNumber(token);
1184
+ }
1185
+ if (typeof value !== 'number' || !Number.isSafeInteger(value))
1186
+ return bad(path, 'expected a safe integer; declare int64 for larger values');
1187
+ if (!response || matching)
1188
+ numericConstraints(String(value), s, path, validateConstraints || matching);
1189
+ return value;
1190
+ }
1191
+ if (type === 'null')
1192
+ return bad(path, 'expected null');
1193
+ if (type === 'object' ||
1194
+ (type === undefined && value && typeof value === 'object' && !Array.isArray(value))) {
1195
+ if (!value || typeof value !== 'object' || Array.isArray(value))
1196
+ return bad(path, 'expected an object');
1197
+ const entries = value;
1198
+ for (const k of response ? s.requiredOutput : s.requiredInput)
1199
+ if (!Object.hasOwn(entries, k) || entries[k] === undefined)
1200
+ bad(`${path}.${k}`, 'required field is missing');
1201
+ const out = Object.create(null);
1202
+ for (const [k, v] of Object.entries(entries)) {
1203
+ if (v === undefined && !response)
1204
+ continue;
1205
+ const child = Object.hasOwn(s.fields ?? {}, k) ? s.fields[k] : undefined;
1206
+ if (!response && child?.rejectInput)
1207
+ bad(`${path}.${k}`, 'readOnly fields cannot be sent');
1208
+ if (child)
1209
+ out[k] = executeNode(v, child, {
1210
+ ...codecMode(response, matching),
1211
+ path: `${path}.${k}`,
1212
+ redactFields: redactFields,
1213
+ definitions: definitions,
1214
+ depth: depth + 1,
1215
+ validateConstraints: validateConstraints,
1216
+ allowUnknownResponseFields: allowUnknownResponseFields,
1217
+ });
1218
+ else if ((!response || (matching && !allowUnknownResponseFields)) && s.extra === false)
1219
+ bad(`${path}.${k}`, 'unknown request field');
1220
+ else if (typeof s.extra === 'object')
1221
+ out[k] = executeNode(v, s.extra, {
1222
+ ...codecMode(response, matching),
1223
+ path: `${path}.${k}`,
1224
+ redactFields: redactFields,
1225
+ definitions: definitions,
1226
+ depth: depth + 1,
1227
+ validateConstraints: validateConstraints,
1228
+ allowUnknownResponseFields: allowUnknownResponseFields,
1229
+ });
1230
+ else
1231
+ out[k] = v;
1232
+ }
1233
+ if ((!response || matching) && (validateConstraints || matching)) {
1234
+ const count = Object.keys(out).length;
1235
+ if (s.checks.minProperties !== undefined && count < s.checks.minProperties)
1236
+ bad(path, 'object violates minProperties');
1237
+ if (s.checks.maxProperties !== undefined && count > s.checks.maxProperties)
1238
+ bad(path, 'object violates maxProperties');
1239
+ }
1240
+ if (response)
1241
+ Object.defineProperty(out, inspect.custom, {
1242
+ value: () => redactCodec(out, s, redactFields, definitions),
1243
+ enumerable: false,
1244
+ });
1245
+ return out;
1246
+ }
1247
+ if (type === 'array' || (type === undefined && Array.isArray(value))) {
1248
+ if (!Array.isArray(value))
1249
+ return bad(path, 'expected an array');
1250
+ denseArray(value, path);
1251
+ if ((!response || matching) && (validateConstraints || matching)) {
1252
+ if (s.checks.minItems !== undefined && value.length < s.checks.minItems)
1253
+ bad(path, 'array violates minItems');
1254
+ if (s.checks.maxItems !== undefined && value.length > s.checks.maxItems)
1255
+ bad(path, 'array violates maxItems');
1256
+ if (s.checks.uniqueItems &&
1257
+ new Set(value.map((child) => jsonIdentity(child, depth + 1))).size !== value.length)
1258
+ bad(path, 'array violates uniqueItems');
1259
+ if (s.includes &&
1260
+ !value.some((child, index) => {
1261
+ try {
1262
+ executeNode(child, s.includes, {
1263
+ ...codecMode(response, true),
1264
+ path: `${path}[${index}]`,
1265
+ definitions,
1266
+ depth: depth + 1,
1267
+ allowUnknownResponseFields: false,
1268
+ });
1269
+ return true;
1270
+ }
1271
+ catch (error) {
1272
+ if (error instanceof SdkError && error.kind === 'validation')
1273
+ return false;
1274
+ throw error;
1275
+ }
1276
+ }))
1277
+ bad(path, 'array violates contains');
1278
+ }
1279
+ return value.map((v, i) => executeNode(v, s.element ?? ANY_CODEC, {
1280
+ ...codecMode(response, matching),
1281
+ path: `${path}[${i}]`,
1282
+ redactFields: redactFields,
1283
+ definitions: definitions,
1284
+ depth: depth + 1,
1285
+ validateConstraints: validateConstraints,
1286
+ allowUnknownResponseFields: allowUnknownResponseFields,
1287
+ }));
1288
+ }
1289
+ if (type === 'string' && typeof value !== 'string')
1290
+ return bad(path, 'expected a string');
1291
+ if (typeof value === 'string' && (!response || matching)) {
1292
+ if (/[\uD800-\uDFFF]/u.test(value))
1293
+ bad(path, 'expected well-formed Unicode');
1294
+ if (validateConstraints || matching) {
1295
+ const length = [...value].length;
1296
+ if (s.checks.minLength !== undefined && length < s.checks.minLength)
1297
+ bad(path, 'string violates minLength');
1298
+ if (s.checks.maxLength !== undefined && length > s.checks.maxLength)
1299
+ bad(path, 'string violates maxLength');
1300
+ if (s.checks.pattern !== undefined && !new RegExp(s.checks.pattern, 'u').test(value))
1301
+ bad(path, 'string violates pattern');
1302
+ }
1303
+ }
1304
+ if (type === undefined && typeof value === 'number' && (!response || matching))
1305
+ numericConstraints(String(value), s, path, validateConstraints || matching);
1306
+ if (type === 'boolean' && typeof value !== 'boolean')
1307
+ return bad(path, 'expected a boolean');
1308
+ return value;
1309
+ }
1310
+ export function serialize(value, schema) {
1311
+ return encode(normalize(value, schema));
1312
+ }
1313
+ export function isKnownVariant(value, schema) {
1314
+ return isKnownCodec(value, compileCodec(schema));
1315
+ }
1316
+ export function isKnownCodec(value, codec) {
1317
+ try {
1318
+ let definitions = codec.definitions ?? {};
1319
+ for (let depth = 0; codec.reference; depth++) {
1320
+ if (depth > 256)
1321
+ bad('response', 'codec reference exceeds nesting limit');
1322
+ const target = Object.hasOwn(definitions, codec.reference)
1323
+ ? definitions[codec.reference]
1324
+ : undefined;
1325
+ if (!target)
1326
+ return false;
1327
+ codec = target;
1328
+ definitions = codec.definitions ?? definitions;
1329
+ }
1330
+ if (!codec.exactlyOne && !codec.some)
1331
+ return false;
1332
+ const tag = codec.tag;
1333
+ if (tag &&
1334
+ (!value ||
1335
+ typeof value !== 'object' ||
1336
+ !Object.hasOwn(value, tag) ||
1337
+ !codec.exactlyOne?.some((branch) => (branch.tagValues ?? branch.fields?.[tag]?.members)?.some((member) => member === value[tag]))))
1338
+ return false;
1339
+ executeCodec(value, codec, {
1340
+ mode: 'match',
1341
+ direction: 'response',
1342
+ path: 'response',
1343
+ allowUnknownResponseFields: true,
1344
+ definitions,
1345
+ });
1346
+ return true;
1347
+ }
1348
+ catch (error) {
1349
+ if (error instanceof SdkError && error.kind === 'validation')
1350
+ return false;
1351
+ throw error;
1352
+ }
1353
+ }
1354
+ export function redact(value, schema, fields = [], definitions = {}, depth = 0) {
1355
+ return redactCodec(value, schema ? compileCodec(schemaWithDefinitions(schema, definitions)) : undefined, fields, {}, depth);
1356
+ }
1357
+ export function redactCodec(value, schema, fields = [], definitions = {}, depth = 0) {
1358
+ if (depth > 256)
1359
+ return '[Nesting limit]';
1360
+ definitions = schema?.definitions ?? definitions;
1361
+ if (schema?.reference) {
1362
+ const target = definitions[schema.reference];
1363
+ return target
1364
+ ? redactCodec(value, target, fields, definitions, depth + 1)
1365
+ : '[Unresolved model]';
1366
+ }
1367
+ const shapes = (s) => s?.reference
1368
+ ? shapes(definitions[s.reference])
1369
+ : s
1370
+ ? [
1371
+ s,
1372
+ ...[
1373
+ ...(s.every ?? []),
1374
+ ...(s.some ?? []),
1375
+ ...(s.exactlyOne ?? []),
1376
+ ...(s.when?.then ? [s.when.then] : []),
1377
+ ...(s.when?.else ? [s.when.else] : []),
1378
+ ].flatMap(shapes),
1379
+ ]
1380
+ : [];
1381
+ const schemas = shapes(schema);
1382
+ if (schemas.some((s) => s.sensitive))
1383
+ return '[REDACTED]';
1384
+ if (Array.isArray(value))
1385
+ return value.map((v) => redactCodec(v, { ...ANY_CODEC, every: schemas.flatMap((s) => (s.element ? [s.element] : [])) }, fields, definitions, depth + 1));
1386
+ if (value && typeof value === 'object')
1387
+ return Object.fromEntries(Object.entries(value).map(([k, v]) => [
1388
+ k,
1389
+ fields.includes(k) || /authorization|token|secret|password|api.?key/i.test(k)
1390
+ ? '[REDACTED]'
1391
+ : redactCodec(v, {
1392
+ ...ANY_CODEC,
1393
+ every: schemas.flatMap((s) => Object.hasOwn(s.fields ?? {}, k)
1394
+ ? [s.fields[k]]
1395
+ : typeof s.extra === 'object'
1396
+ ? [s.extra]
1397
+ : []),
1398
+ }, fields, definitions, depth + 1),
1399
+ ]));
1400
+ return value;
1401
+ }
1402
+ const modelInputs = new WeakMap();
1403
+ export class Model {
1404
+ value;
1405
+ codec;
1406
+ dynamicSchema;
1407
+ constructor(value, schema, compiled) {
1408
+ this.dynamicSchema = compiled ? undefined : schema;
1409
+ this.codec = compiled ?? compileCodec(schema);
1410
+ const unwrap = (v, depth = 0) => {
1411
+ if (depth > 256)
1412
+ bad('value', 'value exceeds the supported nesting depth or contains a cycle');
1413
+ if (v instanceof Model)
1414
+ return unwrap(v.toJSON(), depth + 1);
1415
+ if (v instanceof RawNumber)
1416
+ return v.value;
1417
+ if (Array.isArray(v))
1418
+ return v.map((child) => unwrap(child, depth + 1));
1419
+ if (v && typeof v === 'object')
1420
+ return Object.assign(Object.create(null), Object.fromEntries(Object.entries(v).map(([key, child]) => [key, unwrap(child, depth + 1)])));
1421
+ return v;
1422
+ };
1423
+ const normalized = executeCodec(value, this.codec, { mode: 'request' });
1424
+ modelInputs.set(this, parseJson(encode(normalized), true));
1425
+ this.value = unwrap(normalized);
1426
+ }
1427
+ toJSON() {
1428
+ return structuredClone(this.value);
1429
+ }
1430
+ [inspect.custom]() {
1431
+ return redactCodec(this.value, this.dynamicSchema ? compileCodec(this.dynamicSchema) : this.codec);
1432
+ }
1433
+ }
1434
+ /** Internal factory; does not expand the public Model class method surface. */
1435
+ export function modelFromCodec(value, codec) {
1436
+ // Reflect invokes the implementation-only third argument on the known Model constructor.
1437
+ return Reflect.construct(Model, [value, {}, codec]);
1438
+ }
1439
+ const field = (value, path) => path
1440
+ .split('.')
1441
+ .reduce((v, key) => (v != null && Object.hasOwn(v, key) ? v[key] : undefined), value);
1442
+ const encoded = (s) => encodeURIComponent(s).replace(/[!'()*]/g, (c) => '%' + c.charCodeAt(0).toString(16).toUpperCase());
1443
+ function scalar(v) {
1444
+ return v instanceof RawNumber ? v.value : String(v);
1445
+ }
1446
+ function positive(v, label) {
1447
+ if (!Number.isFinite(v) || v <= 0)
1448
+ bad(label, 'must be a positive finite number');
1449
+ return v;
1450
+ }
1451
+ function stopped(signal, outcome = 'unknown') {
1452
+ if (signal?.aborted)
1453
+ throw new SdkError('cancelled', 'Local request cancelled; this does not cancel the remote operation', outcome);
1454
+ }
1455
+ function abortable(promise, signal) {
1456
+ return new Promise((resolve, reject) => {
1457
+ const abort = () => {
1458
+ signal.removeEventListener('abort', abort);
1459
+ reject(new Error('HTTP attempt aborted'));
1460
+ };
1461
+ if (signal.aborted)
1462
+ abort();
1463
+ else
1464
+ signal.addEventListener('abort', abort, { once: true });
1465
+ promise.then((value) => {
1466
+ signal.removeEventListener('abort', abort);
1467
+ resolve(value);
1468
+ }, (error) => {
1469
+ signal.removeEventListener('abort', abort);
1470
+ reject(error);
1471
+ });
1472
+ });
1473
+ }
1474
+ async function delay(ms, signal) {
1475
+ stopped(signal);
1476
+ await new Promise((resolve, reject) => {
1477
+ const timer = schedule(() => {
1478
+ signal?.removeEventListener('abort', cancel);
1479
+ resolve();
1480
+ }, ms);
1481
+ const cancel = () => {
1482
+ timer?.cancel();
1483
+ reject(new SdkError('cancelled', 'Local waiting cancelled', 'unknown'));
1484
+ };
1485
+ signal?.addEventListener('abort', cancel, { once: true });
1486
+ });
1487
+ }
1488
+ export class Runtime {
1489
+ streams = new Set();
1490
+ async close() {
1491
+ await Promise.all([...this.streams].map((stream) => stream.close()));
1492
+ }
1493
+ options;
1494
+ base;
1495
+ allowed;
1496
+ compiledContract;
1497
+ dynamicContract;
1498
+ get contract() {
1499
+ // Public source-taking Runtime construction retains caller-owned schemas.
1500
+ // Generated clients always supply compiledContract and never enter this adapter.
1501
+ return this.dynamicContract ? compileRuntimePlan(this.dynamicContract) : this.compiledContract;
1502
+ }
1503
+ constructor(contract, options, compiled) {
1504
+ this.dynamicContract = compiled ? undefined : contract;
1505
+ this.compiledContract = compiled ?? compileRuntimePlan(contract);
1506
+ assertRuntimePlan(this.compiledContract);
1507
+ this.options = { ...options };
1508
+ if (/[\\\r\n]/.test(options.baseUrl))
1509
+ bad('baseUrl', 'invalid URL');
1510
+ this.base = new URL(options.baseUrl.endsWith('/') ? options.baseUrl : options.baseUrl + '/');
1511
+ if (this.base.search || this.base.hash)
1512
+ bad('baseUrl', 'base URL must not contain a query or fragment');
1513
+ this.allowed = new Set(options.allowedOrigins ?? [this.base.origin]);
1514
+ this.checkUrl(this.base);
1515
+ positive(options.timeoutMs ?? 10000, 'timeoutMs');
1516
+ positive(options.deadlineMs ?? 30000, 'deadlineMs');
1517
+ }
1518
+ [inspect.custom]() {
1519
+ return { baseUrl: this.base.origin, credentials: '[REDACTED]' };
1520
+ }
1521
+ decode(value, codec, context) {
1522
+ return executeCodec(value, codec, { ...context, definitions: this.contract.definitions ?? {} });
1523
+ }
1524
+ checkUrl(url) {
1525
+ if (url.username ||
1526
+ url.password ||
1527
+ url.hash ||
1528
+ !['https:', ...(this.options.allowInsecureHttp ? ['http:'] : [])].includes(url.protocol) ||
1529
+ !this.allowed.has(url.origin))
1530
+ throw new SdkError('destination', 'Destination is outside the explicit credential policy');
1531
+ }
1532
+ async request(id, input = {}, options = {}, continuation) {
1533
+ if (!input || typeof input !== 'object' || Array.isArray(input))
1534
+ bad('input', 'expected an object');
1535
+ if (!options || typeof options !== 'object' || Array.isArray(options))
1536
+ bad('options', 'expected an object');
1537
+ const op = this.contract.operations.find((v) => v.id === id);
1538
+ if (!op)
1539
+ return bad('operation', 'operation is not included in this SDK');
1540
+ const start = performance.now();
1541
+ const deadline = start + positive(options.deadlineMs ?? this.options.deadlineMs ?? 30000, 'deadlineMs');
1542
+ const timeout = positive(options.timeoutMs ?? this.options.timeoutMs ?? 10000, 'timeoutMs');
1543
+ if (options.streamIdleTimeoutMs !== undefined)
1544
+ positive(options.streamIdleTimeoutMs, 'streamIdleTimeoutMs');
1545
+ if (options.streamLifetimeMs !== undefined)
1546
+ positive(options.streamLifetimeMs, 'streamLifetimeMs');
1547
+ const policy = op.retry ?? { maxAttempts: 1, statuses: [], transport: false, baseDelayMs: 100 };
1548
+ const attempts = options.maxAttempts ?? this.options.maxAttempts ?? policy.maxAttempts;
1549
+ if (!Number.isInteger(attempts) || attempts < 1 || attempts > policy.maxAttempts)
1550
+ bad('maxAttempts', 'must be within the provider-declared retry limit');
1551
+ const headers = Object.assign(Object.create(null), {
1552
+ accept: [
1553
+ ...new Set(Object.values(op.responses)
1554
+ .filter((response) => response.classification === 'success')
1555
+ .map((response) => response.mediaType)
1556
+ .filter(Boolean)),
1557
+ ].join(', ') || 'application/json',
1558
+ 'user-agent': this.contract.userAgent ?? 'PublicSDK (Node.js)',
1559
+ });
1560
+ const setHeader = (name, value) => {
1561
+ if (!/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/.test(name) || /[\r\n]/.test(value))
1562
+ bad('headers', 'invalid HTTP header');
1563
+ const existing = headers[name.toLowerCase()];
1564
+ if (op.idempotency?.header.toLowerCase() === name.toLowerCase() &&
1565
+ existing !== undefined &&
1566
+ existing !== value)
1567
+ bad('idempotencyKey', 'conflicting keys were supplied through input headers or request options');
1568
+ headers[name.toLowerCase()] = value;
1569
+ };
1570
+ let path = op.path;
1571
+ const query = [];
1572
+ for (const p of op.parameters) {
1573
+ const value = Object.hasOwn(input, p.name) ? input[p.name] : undefined;
1574
+ if (value === undefined) {
1575
+ if (p.required)
1576
+ bad(p.name, 'required parameter is missing');
1577
+ continue;
1578
+ }
1579
+ const normalized = this.decode(value, p.codec, { mode: 'request', path: p.name });
1580
+ const values = Array.isArray(normalized) ? normalized.map(scalar) : [scalar(normalized)];
1581
+ if (p.in === 'path') {
1582
+ if (values.some((v) => v === '.' || v === '..'))
1583
+ bad(p.name, 'dot path segments are unsupported');
1584
+ path = path.replaceAll(`{${p.name}}`, values.map(encoded).join(','));
1585
+ }
1586
+ if (p.in === 'query') {
1587
+ if (Array.isArray(normalized) && p.explode !== false)
1588
+ for (const v of values)
1589
+ query.push(encoded(p.name) + '=' + encoded(v));
1590
+ else
1591
+ query.push(encoded(p.name) + '=' + values.map(encoded).join(','));
1592
+ }
1593
+ if (p.in === 'header')
1594
+ setHeader(p.name, values.join(','));
1595
+ }
1596
+ const url = continuation
1597
+ ? new URL(continuation, this.base)
1598
+ : new URL(this.base.href.replace(/\/$/, '') + path + (query.length ? '?' + query.join('&') : ''));
1599
+ this.checkUrl(url);
1600
+ for (const [k, v] of Object.entries(options.headers ?? {}))
1601
+ setHeader(k, v);
1602
+ if (this.contract.authentication) {
1603
+ const permitted = op.authModes ?? [];
1604
+ let modeName = options.authMode ?? (permitted.length ? this.options.authMode : undefined);
1605
+ if (modeName === undefined && op.authenticated && permitted.length === 1)
1606
+ modeName = permitted[0];
1607
+ if (modeName === undefined && op.authenticated)
1608
+ throw new SdkError('authentication', 'Select an explicit authentication mode');
1609
+ const selected = modeName === undefined ? undefined : this.contract.authentication[modeName];
1610
+ if (modeName !== undefined && (!selected || !permitted.includes(modeName)))
1611
+ throw new SdkError('authentication', 'Authentication mode is not permitted for this operation');
1612
+ const expected = Object.create(null);
1613
+ if (selected && modeName !== undefined) {
1614
+ const credentials = options.credentials ?? this.options.credentials?.[modeName];
1615
+ for (const scheme of selected.schemes) {
1616
+ const credential = credentials?.[scheme.name];
1617
+ if (typeof credential !== 'string' || !credential || /[\r\n]/.test(credential))
1618
+ throw new SdkError('authentication', 'A complete credential set is required for the selected mode');
1619
+ expected[scheme.header.toLowerCase()] =
1620
+ scheme.type === 'bearer' ? 'Bearer ' + credential : credential;
1621
+ }
1622
+ }
1623
+ for (const mode of Object.values(this.contract.authentication))
1624
+ for (const scheme of mode.schemes) {
1625
+ const name = scheme.header.toLowerCase();
1626
+ if (headers[name] !== undefined && headers[name] !== expected[name])
1627
+ throw new SdkError('authentication', 'Request headers conflict with the selected authentication mode');
1628
+ }
1629
+ for (const [name, value] of Object.entries(expected))
1630
+ setHeader(name, value);
1631
+ }
1632
+ else if (op.authenticated || (op.optionalAuthentication && this.options.token)) {
1633
+ if (!this.options.token || !this.contract.auth)
1634
+ throw new SdkError('authentication', 'Explicit API credentials are required');
1635
+ setHeader(this.contract.auth.header, this.contract.auth.type === 'bearer' ? `Bearer ${this.options.token}` : this.options.token);
1636
+ }
1637
+ if (this.contract.apiVersion)
1638
+ setHeader(this.contract.apiVersion.header, this.contract.apiVersion.value);
1639
+ if (options.ifMatch !== undefined) {
1640
+ if (!op.conditional)
1641
+ bad('ifMatch', 'operation does not declare conditional requests');
1642
+ setHeader(op.conditional.header, options.ifMatch);
1643
+ }
1644
+ const key = options.idempotencyKey ??
1645
+ (op.idempotency ? headers[op.idempotency.header.toLowerCase()] : undefined) ??
1646
+ (op.idempotency?.auto ? randomUUID() : undefined);
1647
+ if (key !== undefined) {
1648
+ if (!op.idempotency || !key)
1649
+ bad('idempotencyKey', 'a nonempty key and declared capability are required');
1650
+ if (/^[ \t]|[ \t]$/.test(key))
1651
+ bad('idempotencyKey', 'leading or trailing HTTP whitespace would change the key on the wire');
1652
+ setHeader(op.idempotency.header, key);
1653
+ }
1654
+ const safe = ['GET', 'HEAD', 'OPTIONS'].includes(op.verb) ||
1655
+ Boolean(op.idempotency && headers[op.idempotency.header.toLowerCase()]);
1656
+ if (attempts > 1 && !safe)
1657
+ bad('idempotencyKey', 'persist and supply an idempotency key before enabling mutation retries');
1658
+ let body;
1659
+ if (Object.hasOwn(input, 'body') && input.body !== undefined) {
1660
+ if (!op.body)
1661
+ bad('body', 'operation does not accept a body');
1662
+ if (['GET', 'HEAD'].includes(op.verb))
1663
+ bad('body', 'GET/HEAD request bodies are unsupported by the Node transport');
1664
+ body = encode(this.decode(input.body, op.body, { mode: 'request' }));
1665
+ setHeader('content-type', op.mediaType);
1666
+ }
1667
+ else if (op.bodyRequired)
1668
+ bad('body', 'required body is missing');
1669
+ for (const key of Object.keys(input))
1670
+ if (key !== 'body' && !op.parameters.some((p) => p.name === key))
1671
+ bad(key, 'unknown input parameter');
1672
+ const transport = this.options.transport ?? fetch;
1673
+ for (let attempt = 1; attempt <= attempts; attempt++) {
1674
+ stopped(options.signal, attempt === 1 ? 'not_sent' : 'unknown');
1675
+ const remaining = deadline - performance.now();
1676
+ if (remaining <= 0)
1677
+ throw new SdkError('deadline', 'Overall deadline exceeded', attempt === 1 ? 'not_sent' : 'unknown');
1678
+ const controller = new AbortController();
1679
+ const abort = () => controller.abort();
1680
+ options.signal?.addEventListener('abort', abort, { once: true });
1681
+ // Timers truncate fractional durations; rounding up prevents an overall
1682
+ // deadline from being reported as an earlier per-attempt transport error.
1683
+ const timer = schedule(abort, Math.ceil(Math.min(timeout, remaining)));
1684
+ let retryAfter = 0;
1685
+ let error;
1686
+ let diagnosticMeta;
1687
+ let diagnosticError;
1688
+ try {
1689
+ const response = await abortable(transport(url, {
1690
+ method: op.verb,
1691
+ headers: { ...headers },
1692
+ ...(body === undefined ? {} : { body }),
1693
+ signal: controller.signal,
1694
+ redirect: 'manual',
1695
+ }), controller.signal);
1696
+ const responseHeaders = Object.fromEntries(response.headers.entries());
1697
+ const meta = {
1698
+ status: response.status,
1699
+ headers: responseHeaders,
1700
+ attempts: attempt,
1701
+ durationMs: performance.now() - start,
1702
+ url: url.href,
1703
+ ...(response.headers.get(this.contract.errors?.requestIdHeader ?? 'x-request-id')
1704
+ ? {
1705
+ requestId: response.headers.get(this.contract.errors?.requestIdHeader ?? 'x-request-id'),
1706
+ }
1707
+ : {}),
1708
+ };
1709
+ diagnosticMeta = meta;
1710
+ const declaredResponse = op.responses[String(response.status)] ?? op.responses.default;
1711
+ if (response.ok && declaredResponse?.bodyKind === 'sse') {
1712
+ if (response.headers.get('content-type')?.split(';')[0]?.trim().toLowerCase() !==
1713
+ 'text/event-stream' ||
1714
+ !response.body) {
1715
+ await response.body?.cancel();
1716
+ throw new SdkError('protocol', 'Expected an SSE response stream', 'response', false, meta);
1717
+ }
1718
+ const idleTimeoutMs = options.streamIdleTimeoutMs ?? op.stream?.idleTimeoutMs ?? 30000;
1719
+ positive(idleTimeoutMs, 'streamIdleTimeoutMs');
1720
+ if (options.streamLifetimeMs !== undefined)
1721
+ positive(options.streamLifetimeMs, 'streamLifetimeMs');
1722
+ const stream = new EventStream(response.body.getReader(), meta, {
1723
+ idleTimeoutMs,
1724
+ maxEventBytes: op.stream?.maxEventBytes ?? 1048576,
1725
+ ...(options.streamLifetimeMs !== undefined
1726
+ ? { lifetimeMs: options.streamLifetimeMs }
1727
+ : {}),
1728
+ ...(options.signal ? { signal: options.signal } : {}),
1729
+ }, (event, raw) => {
1730
+ const codec = op.streamEventCodecs && Object.hasOwn(op.streamEventCodecs, event)
1731
+ ? op.streamEventCodecs[event]
1732
+ : undefined;
1733
+ return codec
1734
+ ? plainNumbers(this.decode(parseJson(raw, true), codec, {
1735
+ mode: 'response',
1736
+ path: 'event',
1737
+ redactFields: this.options.redactFields ?? [],
1738
+ }))
1739
+ : raw;
1740
+ }, () => this.streams.delete(stream));
1741
+ this.streams.add(stream);
1742
+ const result = { data: stream, meta, raw: '' };
1743
+ Object.defineProperty(result, inspect.custom, {
1744
+ value: () => ({ data: '[Event stream]', meta: inspectedMetadata(meta) }),
1745
+ });
1746
+ return result;
1747
+ }
1748
+ const bytes = await abortable(response.arrayBuffer(), controller.signal);
1749
+ const redirect = op.responses[String(response.status)]?.classification === 'redirect';
1750
+ if (response.ok && declaredResponse?.bodyKind === 'binary') {
1751
+ const contentType = response.headers
1752
+ .get('content-type')
1753
+ ?.split(';')[0]
1754
+ ?.trim()
1755
+ .toLowerCase();
1756
+ if (contentType !== declaredResponse.mediaType)
1757
+ throw new SdkError('protocol', 'Unexpected binary response media type', 'response', false, meta);
1758
+ meta.durationMs = performance.now() - start;
1759
+ if (performance.now() >= deadline)
1760
+ throw new SdkError('deadline', 'Response exceeded the overall deadline', 'response', false, meta);
1761
+ const data = new Uint8Array(bytes);
1762
+ const result = { data, meta, raw: data };
1763
+ Object.defineProperty(result, inspect.custom, {
1764
+ value: () => ({ data: '[Binary response]', meta: inspectedMetadata(meta) }),
1765
+ });
1766
+ return result;
1767
+ }
1768
+ let raw = Buffer.from(bytes).toString('utf8');
1769
+ meta.durationMs = performance.now() - start;
1770
+ let data;
1771
+ try {
1772
+ raw = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes);
1773
+ data =
1774
+ raw && !redirect ? parseJson(raw, response.ok || response.status === 304) : undefined;
1775
+ }
1776
+ catch (cause) {
1777
+ if (response.ok)
1778
+ throw new SdkError('protocol', 'Invalid JSON success response', 'response', false, meta, undefined, undefined, { cause }, raw);
1779
+ }
1780
+ if (response.status >= 300 && response.status < 400 && response.status !== 304 && !redirect)
1781
+ throw new SdkError('destination', 'Redirects are not followed; explicitly configure an approved endpoint', 'response', false, meta);
1782
+ if (response.ok || response.status === 304 || redirect) {
1783
+ const declared = op.responses[String(response.status)] ?? op.responses.default;
1784
+ if (!declared)
1785
+ throw new SdkError('protocol', 'Undeclared success status', 'response', false, meta);
1786
+ try {
1787
+ if (redirect) {
1788
+ const location = response.headers.get('location');
1789
+ if (declared.locationRequired && !location)
1790
+ throw new Error('Missing Location header');
1791
+ if (location !== null && /[\u0000-\u001f\u007f]/.test(location))
1792
+ throw new Error('Invalid Location header');
1793
+ data = location === null ? {} : { location };
1794
+ }
1795
+ else if (declared.codec) {
1796
+ if (data === undefined)
1797
+ throw new Error('Missing body');
1798
+ data = plainNumbers(this.decode(data, declared.codec, {
1799
+ mode: 'response',
1800
+ path: 'response',
1801
+ redactFields: this.options.redactFields ?? [],
1802
+ }));
1803
+ }
1804
+ else if (raw)
1805
+ throw new Error('Unexpected body for an empty response');
1806
+ }
1807
+ catch (cause) {
1808
+ throw new SdkError('protocol', 'Response cannot be represented by the declared schema', 'response', false, meta, undefined, undefined, { cause }, raw);
1809
+ }
1810
+ // Synchronous decoding cannot yield to the abort timer. Check the
1811
+ // overall duration again before reporting a successful response.
1812
+ meta.durationMs = performance.now() - start;
1813
+ if (performance.now() >= deadline)
1814
+ throw new SdkError('deadline', 'Response decoding exceeded the overall deadline', 'response', false, meta);
1815
+ const result = { data: data, meta, raw };
1816
+ Object.defineProperty(result, inspect.custom, {
1817
+ value: () => ({
1818
+ data: redactCodec(data, declared.codec, this.options.redactFields, this.contract.definitions),
1819
+ meta: inspectedMetadata(meta),
1820
+ }),
1821
+ });
1822
+ return result;
1823
+ }
1824
+ const kind = [401, 403].includes(response.status)
1825
+ ? 'authentication'
1826
+ : response.status === 429
1827
+ ? 'rate_limit'
1828
+ : [400, 422].includes(response.status)
1829
+ ? 'validation'
1830
+ : [409, 412].includes(response.status)
1831
+ ? 'conflict'
1832
+ : 'api';
1833
+ const code = field(data, this.contract.errors?.codePath ?? 'code');
1834
+ const eligible = safe &&
1835
+ (policy.statuses.includes(response.status) ||
1836
+ (typeof code === 'string' &&
1837
+ (policy.errors ?? []).some((rule) => rule.status === response.status && rule.codes.includes(code))));
1838
+ error = new SdkError(kind, `API returned HTTP ${response.status}`, 'response', eligible, meta, typeof code === 'string' ? code : undefined, this.contract.errors?.detailsPath
1839
+ ? field(redactCodec(data, (op.responses[String(response.status)] ?? op.responses.default)?.codec, this.options.redactFields, this.contract.definitions), this.contract.errors.detailsPath)
1840
+ : redactCodec(data, (op.responses[String(response.status)] ?? op.responses.default)?.codec, this.options.redactFields, this.contract.definitions), undefined, raw);
1841
+ diagnosticError = kind;
1842
+ const instruction = response.headers.get('retry-after');
1843
+ if (instruction) {
1844
+ const seconds = /^\d+(\.\d+)?$/.test(instruction)
1845
+ ? Number(instruction) * 1000
1846
+ : Date.parse(instruction) - Date.now();
1847
+ if (Number.isFinite(seconds))
1848
+ retryAfter = Math.max(0, seconds);
1849
+ }
1850
+ }
1851
+ catch (cause) {
1852
+ if (cause instanceof SdkError) {
1853
+ diagnosticError = cause.kind;
1854
+ throw cause;
1855
+ }
1856
+ diagnosticError = options.signal?.aborted
1857
+ ? 'cancelled'
1858
+ : performance.now() >= deadline
1859
+ ? 'deadline'
1860
+ : 'transport';
1861
+ stopped(options.signal);
1862
+ error = new SdkError(performance.now() >= deadline ? 'deadline' : 'transport', 'Request did not produce a usable response; remote outcome is unknown', 'unknown', safe && policy.transport, diagnosticMeta, undefined, undefined, { cause });
1863
+ }
1864
+ finally {
1865
+ timer?.cancel();
1866
+ options.signal?.removeEventListener('abort', abort);
1867
+ try {
1868
+ this.options.diagnostics?.({
1869
+ operation: id,
1870
+ attempt,
1871
+ durationMs: performance.now() - start,
1872
+ ...(diagnosticMeta
1873
+ ? {
1874
+ status: diagnosticMeta.status,
1875
+ ...(diagnosticMeta.requestId ? { requestId: diagnosticMeta.requestId } : {}),
1876
+ }
1877
+ : {}),
1878
+ ...(diagnosticError ? { errorKind: diagnosticError } : {}),
1879
+ });
1880
+ }
1881
+ catch {
1882
+ /* Diagnostics cannot change an operation's outcome. */
1883
+ }
1884
+ }
1885
+ if (!error?.retryAllowed || attempt >= attempts || performance.now() >= deadline)
1886
+ throw error;
1887
+ const wait = Math.max(retryAfter, Math.random() * policy.baseDelayMs * 2 ** (attempt - 1));
1888
+ if (performance.now() + wait >= deadline)
1889
+ throw new SdkError('deadline', 'Retry wait would exceed the overall deadline', error.outcome, error.retryAllowed, error.meta);
1890
+ await delay(wait, options.signal);
1891
+ }
1892
+ throw new Error('Unreachable retry state');
1893
+ }
1894
+ async *pages(id, input = {}, options = {}) {
1895
+ const op = this.contract.operations.find((v) => v.id === id);
1896
+ if (!op?.pagination)
1897
+ return bad('pagination', 'capability is not declared');
1898
+ const p = op.pagination;
1899
+ let next;
1900
+ const request = { ...input };
1901
+ const deadline = performance.now() +
1902
+ positive(options.deadlineMs ?? this.options.deadlineMs ?? 30000, 'deadlineMs');
1903
+ const limit = options.maxPages ?? Number.MAX_SAFE_INTEGER;
1904
+ if (!Number.isSafeInteger(limit) || limit < 1)
1905
+ bad('maxPages', 'must be a positive safe integer');
1906
+ for (let page = 0; page < limit; page++) {
1907
+ stopped(options.signal);
1908
+ const remaining = deadline - performance.now();
1909
+ if (remaining <= 0)
1910
+ throw new SdkError('deadline', 'Pagination deadline exceeded', 'unknown');
1911
+ const result = await this.request(id, request, { ...options, deadlineMs: remaining }, p.kind === 'link' && typeof next === 'string' ? next : undefined);
1912
+ yield result;
1913
+ const sent = p.kind === 'link' ? next : request[p.parameter];
1914
+ const previous = sent instanceof Model ? sent.toJSON() : sent;
1915
+ next = field(result.data, p.next);
1916
+ if (next === undefined || next === null || next === '')
1917
+ return;
1918
+ if (p.kind === 'link' && typeof next !== 'string')
1919
+ throw new SdkError('protocol', 'Expected a pagination URL', 'response');
1920
+ if (p.kind === 'link')
1921
+ next = new URL(next, result.meta.url ?? this.base).href;
1922
+ if (next === previous ||
1923
+ (p.kind === 'offset' && previous !== undefined && String(next) === String(previous)) ||
1924
+ (p.kind === 'link' && next === result.meta.url))
1925
+ throw new SdkError('protocol', 'Pagination returned a non-advancing continuation', 'response');
1926
+ if (p.kind !== 'link')
1927
+ request[p.parameter] = next;
1928
+ }
1929
+ }
1930
+ async *items(id, input = {}, options = {}) {
1931
+ const p = this.contract.operations.find((v) => v.id === id)?.pagination;
1932
+ if (!p)
1933
+ return bad('pagination', 'capability is not declared');
1934
+ const limit = options.maxItems ?? Number.MAX_SAFE_INTEGER;
1935
+ if (!Number.isSafeInteger(limit) || limit < 1)
1936
+ bad('maxItems', 'must be a positive safe integer');
1937
+ let count = 0;
1938
+ for await (const page of this.pages(id, input, options)) {
1939
+ const values = field(page.data, p.items);
1940
+ if (!Array.isArray(values))
1941
+ throw new SdkError('protocol', 'Pagination items field is not an array', 'response');
1942
+ for (const value of values) {
1943
+ stopped(options.signal);
1944
+ yield value;
1945
+ if (++count >= limit)
1946
+ return;
1947
+ }
1948
+ }
1949
+ }
1950
+ async wait(id, input, options = {}) {
1951
+ const p = this.contract.operations.find((v) => v.id === id)?.polling;
1952
+ if (!p)
1953
+ return bad('polling', 'capability is not declared');
1954
+ const deadline = performance.now() +
1955
+ positive(options.deadlineMs ?? this.options.deadlineMs ?? 30000, 'deadlineMs');
1956
+ let interval = p.intervalMs;
1957
+ for (;;) {
1958
+ const remaining = deadline - performance.now();
1959
+ if (remaining <= 0)
1960
+ throw new SdkError('deadline', 'Polling deadline exceeded; remote operation may still be running', 'unknown');
1961
+ const result = await this.request(id, input, { ...options, deadlineMs: remaining });
1962
+ const state = field(result.data, p.state);
1963
+ if (p.success.includes(state))
1964
+ return result;
1965
+ if (p.failure.includes(state))
1966
+ throw new SdkError('api', 'Operation reached a declared failure state', 'response', false, result.meta);
1967
+ await delay(Math.min(interval, Math.max(0, deadline - performance.now())), options.signal);
1968
+ interval = Math.min(interval * 1.5, 10000);
1969
+ }
1970
+ }
1971
+ verifyWebhook(rawBody, headers, secrets, nowSeconds = Date.now() / 1000) {
1972
+ const w = this.contract.webhook;
1973
+ if (!w)
1974
+ return bad('webhook', 'capability is not declared');
1975
+ const normalized = Object.fromEntries(Object.entries(headers).map(([k, v]) => [k.toLowerCase(), v]));
1976
+ let timestamp = normalized[w.timestampHeader?.toLowerCase() ?? ''] ?? '';
1977
+ const signature = normalized[w.header.toLowerCase()] ?? '';
1978
+ const format = w.format ?? 'hex';
1979
+ let candidates = [signature];
1980
+ let prefix = '';
1981
+ if (format === 'timestamped-hex') {
1982
+ const parts = signature.split(',').map((part) => part.trim());
1983
+ const timestamps = parts.filter((part) => part.startsWith('t='));
1984
+ timestamp = timestamps.length === 1 ? timestamps[0].slice(2) : '';
1985
+ candidates = parts.filter((part) => part.startsWith('v1=')).map((part) => part.slice(3));
1986
+ }
1987
+ else if (format === 'standard-webhooks') {
1988
+ const id = normalized[w.idHeader.toLowerCase()]?.trim();
1989
+ if (!id)
1990
+ throw new SdkError('authentication', 'Invalid webhook signature or timestamp');
1991
+ prefix = id + '.';
1992
+ candidates = signature
1993
+ .trim()
1994
+ .split(/\s+/)
1995
+ .filter((part) => part.startsWith('v1,'))
1996
+ .map((part) => part.slice(3));
1997
+ }
1998
+ if (!/^\d+$/.test(timestamp) ||
1999
+ !Number.isSafeInteger(Number(timestamp)) ||
2000
+ !Number.isFinite(nowSeconds) ||
2001
+ Math.abs(nowSeconds - Number(timestamp)) > w.toleranceSeconds ||
2002
+ !secrets.length)
2003
+ throw new SdkError('authentication', 'Invalid webhook signature or timestamp');
2004
+ const signed = Buffer.concat([
2005
+ Buffer.from(prefix + timestamp + w.separator),
2006
+ Buffer.from(rawBody),
2007
+ ]);
2008
+ const signatures = candidates
2009
+ .filter((candidate) => format === 'standard-webhooks'
2010
+ ? /^[A-Za-z0-9+/]{43}=$/.test(candidate) &&
2011
+ Buffer.from(candidate, 'base64').toString('base64') === candidate
2012
+ : /^[a-fA-F0-9]{64}$/.test(candidate))
2013
+ .map((candidate) => Buffer.from(candidate, format === 'standard-webhooks' ? 'base64' : 'hex'));
2014
+ let valid = false;
2015
+ for (const secret of secrets) {
2016
+ if (!secret)
2017
+ continue;
2018
+ let key = secret;
2019
+ if (format === 'standard-webhooks') {
2020
+ if (!/^whsec_[A-Za-z0-9+/]{43}=$/.test(secret))
2021
+ continue;
2022
+ key = Buffer.from(secret.slice(6), 'base64');
2023
+ if (key.length !== 32 || key.toString('base64') !== secret.slice(6))
2024
+ continue;
2025
+ }
2026
+ const expected = createHmac('sha256', key).update(signed).digest();
2027
+ for (const actual of signatures)
2028
+ valid = timingSafeEqual(expected, actual) || valid;
2029
+ }
2030
+ if (!valid)
2031
+ throw new SdkError('authentication', 'Invalid webhook signature or timestamp');
2032
+ let event;
2033
+ try {
2034
+ event = parseJson(new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(Buffer.from(rawBody)), true);
2035
+ }
2036
+ catch (cause) {
2037
+ throw new SdkError('protocol', 'Invalid webhook JSON', 'response', false, undefined, undefined, undefined, { cause });
2038
+ }
2039
+ const eventType = field(event, w.typeField);
2040
+ const schema = typeof eventType === 'string' && Object.hasOwn(w.events, eventType)
2041
+ ? w.events[eventType]
2042
+ : undefined;
2043
+ return {
2044
+ event: plainNumbers(schema
2045
+ ? this.decode(event, schema, {
2046
+ mode: 'response',
2047
+ path: 'event',
2048
+ redactFields: this.options.redactFields ?? [],
2049
+ })
2050
+ : event),
2051
+ known: Boolean(schema),
2052
+ };
2053
+ }
2054
+ money(currency, major) {
2055
+ const currencies = this.contract.money?.currencies;
2056
+ const digits = currencies && Object.hasOwn(currencies, currency) ? currencies[currency] : undefined;
2057
+ if (digits === undefined)
2058
+ return bad('currency', 'currency is not declared by this provider');
2059
+ if (!/^-?(0|[1-9]\d*)(\.\d+)?$/.test(major))
2060
+ return bad('amount', 'expected an exact decimal string');
2061
+ const negative = major.startsWith('-');
2062
+ const [whole, fraction = ''] = major.replace(/^-/, '').split('.');
2063
+ if (fraction.length > digits)
2064
+ return bad('amount', 'unsupported precision; rounding must be explicit in application code');
2065
+ const amount = BigInt(whole + fraction.padEnd(digits, '0')) * (negative ? -1n : 1n);
2066
+ return { currency, amount: amount.toString() };
2067
+ }
2068
+ }
2069
+ /** Internal factory for generated clients; public Runtime construction remains schema-based. */
2070
+ export function runtimeFromPlan(contract, options) {
2071
+ return Reflect.construct(Runtime, [{ operations: [] }, options, contract]);
2072
+ }