@peable.to/contracts 0.4.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (322) hide show
  1. package/dist/cjs/common/address.js +81 -0
  2. package/dist/cjs/common/envelopes.js +101 -0
  3. package/dist/cjs/common/objects.js +85 -0
  4. package/dist/cjs/common/params.js +211 -0
  5. package/dist/cjs/common/primitives.js +39 -0
  6. package/dist/cjs/contributions.js +22 -0
  7. package/dist/cjs/index.js +40 -137
  8. package/dist/cjs/openapi/document.js +297 -0
  9. package/dist/cjs/openapi/index.js +7 -0
  10. package/dist/cjs/openapi/webhooks.js +17 -0
  11. package/dist/cjs/resources/billingEngine/billingPortal.js +237 -0
  12. package/dist/cjs/resources/billingEngine/creditNotes.js +189 -0
  13. package/dist/cjs/resources/billingEngine/customerBalanceTransactions.js +90 -0
  14. package/dist/cjs/resources/billingEngine/index.js +43 -0
  15. package/dist/cjs/resources/billingEngine/invoiceItems.js +155 -0
  16. package/dist/cjs/resources/billingEngine/invoices.js +509 -0
  17. package/dist/cjs/resources/billingEngine/params.js +43 -0
  18. package/dist/cjs/resources/billingEngine/public.js +326 -0
  19. package/dist/cjs/resources/billingEngine/subscriptions.js +476 -0
  20. package/dist/cjs/resources/catalog/billing.js +755 -0
  21. package/dist/cjs/resources/catalog/billingSettings.js +131 -0
  22. package/dist/cjs/resources/catalog/coupons.js +222 -0
  23. package/dist/cjs/resources/catalog/entitlements.js +257 -0
  24. package/dist/cjs/resources/catalog/index.js +58 -0
  25. package/dist/cjs/resources/catalog/meters.js +279 -0
  26. package/dist/cjs/resources/catalog/prices.js +423 -0
  27. package/dist/cjs/resources/catalog/products.js +228 -0
  28. package/dist/cjs/resources/catalog/promotionCodes.js +174 -0
  29. package/dist/cjs/resources/catalog/shared.js +75 -0
  30. package/dist/cjs/resources/catalog/testClocks.js +127 -0
  31. package/dist/cjs/resources/checkout/checkoutSessions.js +582 -0
  32. package/dist/cjs/resources/checkout/contributions.js +172 -0
  33. package/dist/cjs/resources/checkout/files.js +133 -0
  34. package/dist/cjs/resources/checkout/index.js +57 -0
  35. package/dist/cjs/resources/checkout/merchants.js +290 -0
  36. package/dist/cjs/resources/checkout/paymentLinks.js +330 -0
  37. package/dist/cjs/resources/checkout/paymentMethodConfigurations.js +262 -0
  38. package/dist/cjs/resources/checkout/shared.js +368 -0
  39. package/dist/cjs/resources/connect/account.js +332 -0
  40. package/dist/cjs/resources/connect/applicationFees.js +113 -0
  41. package/dist/cjs/resources/connect/balance.js +212 -0
  42. package/dist/cjs/resources/connect/connectedAccounts.js +260 -0
  43. package/dist/cjs/resources/connect/index.js +51 -0
  44. package/dist/cjs/resources/connect/onboarding.js +82 -0
  45. package/dist/cjs/resources/connect/payouts.js +196 -0
  46. package/dist/cjs/resources/connect/reporting.js +235 -0
  47. package/dist/cjs/resources/connect/requestLogs.js +110 -0
  48. package/dist/cjs/resources/connect/transfers.js +227 -0
  49. package/dist/cjs/resources/core/customers.js +194 -0
  50. package/dist/cjs/resources/core/index.js +23 -0
  51. package/dist/cjs/resources/core/paymentMethods.js +134 -0
  52. package/dist/cjs/resources/events/events.js +357 -0
  53. package/dist/cjs/resources/events/index.js +29 -0
  54. package/dist/cjs/resources/events/webhookDeliveries.js +93 -0
  55. package/dist/cjs/resources/events/webhookEndpoints.js +215 -0
  56. package/dist/cjs/resources/payments/charges.js +157 -0
  57. package/dist/cjs/resources/payments/disputes.js +204 -0
  58. package/dist/cjs/resources/payments/index.js +41 -0
  59. package/dist/cjs/resources/payments/paymentIntents.js +529 -0
  60. package/dist/cjs/resources/payments/refunds.js +245 -0
  61. package/dist/cjs/resources/payments/setupIntents.js +158 -0
  62. package/dist/cjs/resources/payments/social.js +182 -0
  63. package/dist/cjs/resources/payments/testHelpers.js +39 -0
  64. package/dist/cjs/resources/tax/assessments.js +217 -0
  65. package/dist/cjs/resources/tax/businessProfile.js +99 -0
  66. package/dist/cjs/resources/tax/calculations.js +176 -0
  67. package/dist/cjs/resources/tax/capabilities.js +42 -0
  68. package/dist/cjs/resources/tax/codes.js +37 -0
  69. package/dist/cjs/resources/tax/complianceActions.js +56 -0
  70. package/dist/cjs/resources/tax/deadlines.js +59 -0
  71. package/dist/cjs/resources/tax/documents.js +128 -0
  72. package/dist/cjs/resources/tax/index.js +80 -0
  73. package/dist/cjs/resources/tax/locationEvidence.js +131 -0
  74. package/dist/cjs/resources/tax/operatingLocations.js +98 -0
  75. package/dist/cjs/resources/tax/products.js +67 -0
  76. package/dist/cjs/resources/tax/registrationDeclarations.js +124 -0
  77. package/dist/cjs/resources/tax/registrations.js +82 -0
  78. package/dist/cjs/resources/tax/reports.js +92 -0
  79. package/dist/cjs/resources/tax/reviewItems.js +116 -0
  80. package/dist/cjs/resources/tax/ruleSet.js +68 -0
  81. package/dist/cjs/resources/tax/salesDestinations.js +94 -0
  82. package/dist/cjs/resources/tax/settings.js +104 -0
  83. package/dist/cjs/resources/tax/shared.js +62 -0
  84. package/dist/cjs/resources/tax/transactions.js +102 -0
  85. package/dist/cjs/route.js +22 -0
  86. package/dist/cjs/routes.js +31 -0
  87. package/dist/cjs/vocabulary/billingPortal.js +15 -0
  88. package/dist/cjs/vocabulary/catalog.js +110 -0
  89. package/dist/cjs/vocabulary/checkout.js +53 -0
  90. package/dist/cjs/vocabulary/connect.js +95 -0
  91. package/dist/cjs/vocabulary/dashboard.js +68 -0
  92. package/dist/cjs/vocabulary/errors.js +175 -0
  93. package/dist/cjs/vocabulary/events.js +176 -0
  94. package/dist/cjs/vocabulary/files.js +44 -0
  95. package/dist/cjs/vocabulary/identity.js +12 -0
  96. package/dist/cjs/vocabulary/index.js +39 -0
  97. package/dist/cjs/vocabulary/invoices.js +52 -0
  98. package/dist/cjs/vocabulary/lists.js +22 -0
  99. package/dist/cjs/vocabulary/merchants.js +23 -0
  100. package/dist/cjs/vocabulary/money.js +104 -0
  101. package/dist/cjs/vocabulary/paymentMethodConfigurations.js +36 -0
  102. package/dist/cjs/vocabulary/payments.js +195 -0
  103. package/dist/cjs/vocabulary/reporting.js +27 -0
  104. package/dist/cjs/vocabulary/subscriptions.js +60 -0
  105. package/dist/cjs/vocabulary/tax.js +237 -0
  106. package/dist/cjs/vocabulary/version.js +12 -0
  107. package/dist/esm/common/address.js +76 -0
  108. package/dist/esm/common/envelopes.js +95 -0
  109. package/dist/esm/common/objects.js +74 -0
  110. package/dist/esm/common/params.js +203 -0
  111. package/dist/esm/common/primitives.js +35 -0
  112. package/dist/esm/contributions.js +5 -0
  113. package/dist/esm/index.js +26 -134
  114. package/dist/esm/openapi/document.js +294 -0
  115. package/dist/esm/openapi/index.js +2 -0
  116. package/dist/esm/openapi/webhooks.js +14 -0
  117. package/dist/esm/resources/billingEngine/billingPortal.js +234 -0
  118. package/dist/esm/resources/billingEngine/creditNotes.js +186 -0
  119. package/dist/esm/resources/billingEngine/customerBalanceTransactions.js +87 -0
  120. package/dist/esm/resources/billingEngine/index.js +26 -0
  121. package/dist/esm/resources/billingEngine/invoiceItems.js +152 -0
  122. package/dist/esm/resources/billingEngine/invoices.js +506 -0
  123. package/dist/esm/resources/billingEngine/params.js +39 -0
  124. package/dist/esm/resources/billingEngine/public.js +323 -0
  125. package/dist/esm/resources/billingEngine/subscriptions.js +473 -0
  126. package/dist/esm/resources/catalog/billing.js +752 -0
  127. package/dist/esm/resources/catalog/billingSettings.js +128 -0
  128. package/dist/esm/resources/catalog/coupons.js +219 -0
  129. package/dist/esm/resources/catalog/entitlements.js +254 -0
  130. package/dist/esm/resources/catalog/index.js +38 -0
  131. package/dist/esm/resources/catalog/meters.js +276 -0
  132. package/dist/esm/resources/catalog/prices.js +419 -0
  133. package/dist/esm/resources/catalog/products.js +225 -0
  134. package/dist/esm/resources/catalog/promotionCodes.js +171 -0
  135. package/dist/esm/resources/catalog/shared.js +67 -0
  136. package/dist/esm/resources/catalog/testClocks.js +124 -0
  137. package/dist/esm/resources/checkout/checkoutSessions.js +579 -0
  138. package/dist/esm/resources/checkout/contributions.js +167 -0
  139. package/dist/esm/resources/checkout/files.js +130 -0
  140. package/dist/esm/resources/checkout/index.js +25 -0
  141. package/dist/esm/resources/checkout/merchants.js +287 -0
  142. package/dist/esm/resources/checkout/paymentLinks.js +327 -0
  143. package/dist/esm/resources/checkout/paymentMethodConfigurations.js +259 -0
  144. package/dist/esm/resources/checkout/shared.js +363 -0
  145. package/dist/esm/resources/connect/account.js +329 -0
  146. package/dist/esm/resources/connect/applicationFees.js +110 -0
  147. package/dist/esm/resources/connect/balance.js +209 -0
  148. package/dist/esm/resources/connect/connectedAccounts.js +257 -0
  149. package/dist/esm/resources/connect/index.js +34 -0
  150. package/dist/esm/resources/connect/onboarding.js +79 -0
  151. package/dist/esm/resources/connect/payouts.js +193 -0
  152. package/dist/esm/resources/connect/reporting.js +232 -0
  153. package/dist/esm/resources/connect/requestLogs.js +107 -0
  154. package/dist/esm/resources/connect/transfers.js +224 -0
  155. package/dist/esm/resources/core/customers.js +191 -0
  156. package/dist/esm/resources/core/index.js +6 -0
  157. package/dist/esm/resources/core/paymentMethods.js +131 -0
  158. package/dist/esm/resources/events/events.js +353 -0
  159. package/dist/esm/resources/events/index.js +12 -0
  160. package/dist/esm/resources/events/webhookDeliveries.js +90 -0
  161. package/dist/esm/resources/events/webhookEndpoints.js +212 -0
  162. package/dist/esm/resources/payments/charges.js +154 -0
  163. package/dist/esm/resources/payments/disputes.js +201 -0
  164. package/dist/esm/resources/payments/index.js +24 -0
  165. package/dist/esm/resources/payments/paymentIntents.js +526 -0
  166. package/dist/esm/resources/payments/refunds.js +242 -0
  167. package/dist/esm/resources/payments/setupIntents.js +155 -0
  168. package/dist/esm/resources/payments/social.js +179 -0
  169. package/dist/esm/resources/payments/testHelpers.js +36 -0
  170. package/dist/esm/resources/tax/assessments.js +214 -0
  171. package/dist/esm/resources/tax/businessProfile.js +96 -0
  172. package/dist/esm/resources/tax/calculations.js +173 -0
  173. package/dist/esm/resources/tax/capabilities.js +39 -0
  174. package/dist/esm/resources/tax/codes.js +34 -0
  175. package/dist/esm/resources/tax/complianceActions.js +53 -0
  176. package/dist/esm/resources/tax/deadlines.js +56 -0
  177. package/dist/esm/resources/tax/documents.js +125 -0
  178. package/dist/esm/resources/tax/index.js +63 -0
  179. package/dist/esm/resources/tax/locationEvidence.js +128 -0
  180. package/dist/esm/resources/tax/operatingLocations.js +95 -0
  181. package/dist/esm/resources/tax/products.js +64 -0
  182. package/dist/esm/resources/tax/registrationDeclarations.js +121 -0
  183. package/dist/esm/resources/tax/registrations.js +79 -0
  184. package/dist/esm/resources/tax/reports.js +89 -0
  185. package/dist/esm/resources/tax/reviewItems.js +113 -0
  186. package/dist/esm/resources/tax/ruleSet.js +65 -0
  187. package/dist/esm/resources/tax/salesDestinations.js +91 -0
  188. package/dist/esm/resources/tax/settings.js +101 -0
  189. package/dist/esm/resources/tax/shared.js +58 -0
  190. package/dist/esm/resources/tax/transactions.js +99 -0
  191. package/dist/esm/route.js +16 -0
  192. package/dist/esm/routes.js +27 -0
  193. package/dist/esm/vocabulary/billingPortal.js +12 -0
  194. package/dist/esm/vocabulary/catalog.js +106 -0
  195. package/dist/esm/vocabulary/checkout.js +50 -0
  196. package/dist/esm/vocabulary/connect.js +92 -0
  197. package/dist/esm/vocabulary/dashboard.js +64 -0
  198. package/dist/esm/vocabulary/errors.js +170 -0
  199. package/dist/esm/vocabulary/events.js +173 -0
  200. package/dist/esm/vocabulary/files.js +41 -0
  201. package/dist/esm/vocabulary/identity.js +9 -0
  202. package/dist/esm/vocabulary/index.js +23 -0
  203. package/dist/esm/vocabulary/invoices.js +49 -0
  204. package/dist/esm/vocabulary/lists.js +19 -0
  205. package/dist/esm/vocabulary/merchants.js +20 -0
  206. package/dist/esm/vocabulary/money.js +98 -0
  207. package/dist/esm/vocabulary/paymentMethodConfigurations.js +33 -0
  208. package/dist/esm/vocabulary/payments.js +192 -0
  209. package/dist/esm/vocabulary/reporting.js +24 -0
  210. package/dist/esm/vocabulary/subscriptions.js +57 -0
  211. package/dist/esm/vocabulary/tax.js +233 -0
  212. package/dist/esm/vocabulary/version.js +9 -0
  213. package/dist/types/common/address.d.ts +62 -0
  214. package/dist/types/common/envelopes.d.ts +88 -0
  215. package/dist/types/common/objects.d.ts +107 -0
  216. package/dist/types/common/params.d.ts +156 -0
  217. package/dist/types/common/primitives.d.ts +56 -0
  218. package/dist/types/contributions.d.ts +1 -0
  219. package/dist/types/index.d.ts +16 -171
  220. package/dist/types/openapi/document.d.ts +16 -0
  221. package/dist/types/openapi/index.d.ts +2 -0
  222. package/dist/types/openapi/webhooks.d.ts +15 -0
  223. package/dist/types/resources/billingEngine/billingPortal.d.ts +742 -0
  224. package/dist/types/resources/billingEngine/creditNotes.d.ts +655 -0
  225. package/dist/types/resources/billingEngine/customerBalanceTransactions.d.ts +282 -0
  226. package/dist/types/resources/billingEngine/index.d.ts +6071 -0
  227. package/dist/types/resources/billingEngine/invoiceItems.d.ts +502 -0
  228. package/dist/types/resources/billingEngine/invoices.d.ts +2547 -0
  229. package/dist/types/resources/billingEngine/params.d.ts +51 -0
  230. package/dist/types/resources/billingEngine/public.d.ts +1860 -0
  231. package/dist/types/resources/billingEngine/subscriptions.d.ts +1519 -0
  232. package/dist/types/resources/catalog/billing.d.ts +1723 -0
  233. package/dist/types/resources/catalog/billingSettings.d.ts +160 -0
  234. package/dist/types/resources/catalog/coupons.d.ts +403 -0
  235. package/dist/types/resources/catalog/entitlements.d.ts +422 -0
  236. package/dist/types/resources/catalog/index.d.ts +3155 -0
  237. package/dist/types/resources/catalog/meters.d.ts +474 -0
  238. package/dist/types/resources/catalog/prices.d.ts +1091 -0
  239. package/dist/types/resources/catalog/products.d.ts +430 -0
  240. package/dist/types/resources/catalog/promotionCodes.d.ts +369 -0
  241. package/dist/types/resources/catalog/shared.d.ts +34 -0
  242. package/dist/types/resources/catalog/testClocks.d.ts +220 -0
  243. package/dist/types/resources/checkout/checkoutSessions.d.ts +3207 -0
  244. package/dist/types/resources/checkout/contributions.d.ts +375 -0
  245. package/dist/types/resources/checkout/files.d.ts +280 -0
  246. package/dist/types/resources/checkout/index.d.ts +5678 -0
  247. package/dist/types/resources/checkout/merchants.d.ts +395 -0
  248. package/dist/types/resources/checkout/paymentLinks.d.ts +1728 -0
  249. package/dist/types/resources/checkout/paymentMethodConfigurations.d.ts +2104 -0
  250. package/dist/types/resources/checkout/shared.d.ts +419 -0
  251. package/dist/types/resources/connect/account.d.ts +483 -0
  252. package/dist/types/resources/connect/applicationFees.d.ts +198 -0
  253. package/dist/types/resources/connect/balance.d.ts +399 -0
  254. package/dist/types/resources/connect/connectedAccounts.d.ts +494 -0
  255. package/dist/types/resources/connect/index.d.ts +2094 -0
  256. package/dist/types/resources/connect/onboarding.d.ts +95 -0
  257. package/dist/types/resources/connect/payouts.d.ts +527 -0
  258. package/dist/types/resources/connect/reporting.d.ts +506 -0
  259. package/dist/types/resources/connect/requestLogs.d.ts +236 -0
  260. package/dist/types/resources/connect/transfers.d.ts +436 -0
  261. package/dist/types/resources/core/customers.d.ts +619 -0
  262. package/dist/types/resources/core/index.d.ts +679 -0
  263. package/dist/types/resources/core/paymentMethods.d.ts +336 -0
  264. package/dist/types/resources/events/events.d.ts +731 -0
  265. package/dist/types/resources/events/index.d.ts +1727 -0
  266. package/dist/types/resources/events/webhookDeliveries.d.ts +436 -0
  267. package/dist/types/resources/events/webhookEndpoints.d.ts +1502 -0
  268. package/dist/types/resources/payments/charges.d.ts +390 -0
  269. package/dist/types/resources/payments/disputes.d.ts +822 -0
  270. package/dist/types/resources/payments/index.d.ts +3517 -0
  271. package/dist/types/resources/payments/paymentIntents.d.ts +2080 -0
  272. package/dist/types/resources/payments/refunds.d.ts +684 -0
  273. package/dist/types/resources/payments/setupIntents.d.ts +391 -0
  274. package/dist/types/resources/payments/social.d.ts +266 -0
  275. package/dist/types/resources/payments/testHelpers.d.ts +178 -0
  276. package/dist/types/resources/tax/assessments.d.ts +787 -0
  277. package/dist/types/resources/tax/businessProfile.d.ts +134 -0
  278. package/dist/types/resources/tax/calculations.d.ts +261 -0
  279. package/dist/types/resources/tax/capabilities.d.ts +81 -0
  280. package/dist/types/resources/tax/codes.d.ts +29 -0
  281. package/dist/types/resources/tax/complianceActions.d.ts +97 -0
  282. package/dist/types/resources/tax/deadlines.d.ts +133 -0
  283. package/dist/types/resources/tax/documents.d.ts +257 -0
  284. package/dist/types/resources/tax/index.d.ts +1946 -0
  285. package/dist/types/resources/tax/locationEvidence.d.ts +246 -0
  286. package/dist/types/resources/tax/operatingLocations.d.ts +170 -0
  287. package/dist/types/resources/tax/products.d.ts +68 -0
  288. package/dist/types/resources/tax/registrationDeclarations.d.ts +270 -0
  289. package/dist/types/resources/tax/registrations.d.ts +103 -0
  290. package/dist/types/resources/tax/reports.d.ts +129 -0
  291. package/dist/types/resources/tax/reviewItems.d.ts +226 -0
  292. package/dist/types/resources/tax/ruleSet.d.ts +219 -0
  293. package/dist/types/resources/tax/salesDestinations.d.ts +158 -0
  294. package/dist/types/resources/tax/settings.d.ts +122 -0
  295. package/dist/types/resources/tax/shared.d.ts +43 -0
  296. package/dist/types/resources/tax/transactions.d.ts +404 -0
  297. package/dist/types/route.d.ts +86 -0
  298. package/dist/types/routes.d.ts +23 -0
  299. package/dist/types/vocabulary/billingPortal.d.ts +15 -0
  300. package/dist/types/vocabulary/catalog.d.ts +97 -0
  301. package/dist/types/vocabulary/checkout.d.ts +49 -0
  302. package/dist/types/vocabulary/connect.d.ts +62 -0
  303. package/dist/types/vocabulary/dashboard.d.ts +44 -0
  304. package/dist/types/vocabulary/errors.d.ts +146 -0
  305. package/dist/types/vocabulary/events.d.ts +171 -0
  306. package/dist/types/vocabulary/files.d.ts +30 -0
  307. package/dist/types/vocabulary/identity.d.ts +9 -0
  308. package/dist/types/vocabulary/index.d.ts +19 -0
  309. package/dist/types/vocabulary/invoices.d.ts +39 -0
  310. package/dist/types/vocabulary/lists.d.ts +9 -0
  311. package/dist/types/vocabulary/merchants.d.ts +9 -0
  312. package/dist/types/vocabulary/money.d.ts +59 -0
  313. package/dist/types/vocabulary/paymentMethodConfigurations.d.ts +22 -0
  314. package/dist/types/vocabulary/payments.d.ts +117 -0
  315. package/dist/types/vocabulary/reporting.d.ts +18 -0
  316. package/dist/types/vocabulary/subscriptions.d.ts +45 -0
  317. package/dist/types/vocabulary/tax.d.ts +163 -0
  318. package/dist/types/vocabulary/version.d.ts +10 -0
  319. package/package.json +51 -11
  320. package/dist/cjs/openapi.js +0 -165
  321. package/dist/esm/openapi.js +0 -161
  322. package/dist/types/openapi.d.ts +0 -148
@@ -0,0 +1,294 @@
1
+ import { z } from 'zod';
2
+ import { errorEnvelopeSchema } from '../common/envelopes.js';
3
+ import { contractRegistry } from '../common/objects.js';
4
+ import { isJsonResponse, pathParamNames } from '../route.js';
5
+ import { routes } from '../routes.js';
6
+ import { PEABLE_API_VERSION } from '../vocabulary/version.js';
7
+ import { webhookEvents } from './webhooks.js';
8
+ const COMPONENT_PREFIX = '#/components/schemas/';
9
+ /** Apply the registry's documentation (`jsonSchema` replacements, `x-peable-expandable`) to a generated node. */
10
+ function override(ctx) {
11
+ const meta = contractRegistry.get(ctx.zodSchema);
12
+ const global = z.globalRegistry.get(ctx.zodSchema);
13
+ if (meta?.jsonSchema) {
14
+ for (const key of Object.keys(ctx.jsonSchema))
15
+ delete ctx.jsonSchema[key];
16
+ Object.assign(ctx.jsonSchema, meta.jsonSchema);
17
+ }
18
+ const description = meta?.description ?? global?.description;
19
+ if (description !== undefined && ctx.jsonSchema.description === undefined)
20
+ ctx.jsonSchema.description = description;
21
+ if (meta?.['x-peable-expandable'] !== undefined)
22
+ ctx.jsonSchema['x-peable-expandable'] = meta['x-peable-expandable'];
23
+ if (meta?.examples !== undefined)
24
+ ctx.jsonSchema.examples = [...meta.examples];
25
+ // `jsonSchema`/`id` are registry bookkeeping, never document fields.
26
+ delete ctx.jsonSchema.jsonSchema;
27
+ delete ctx.jsonSchema.id;
28
+ }
29
+ function toJson(schema, io) {
30
+ const json = z.toJSONSchema(schema, {
31
+ target: 'draft-2020-12',
32
+ metadata: contractRegistry,
33
+ io,
34
+ unrepresentable: 'any',
35
+ reused: 'inline',
36
+ cycles: 'ref',
37
+ override,
38
+ });
39
+ delete json.$schema;
40
+ return hoistDefinitions(json);
41
+ }
42
+ /** Every `$defs` entry produced while converting one schema, by component name. */
43
+ const collected = new Map();
44
+ /**
45
+ * `z.toJSONSchema` puts the registered objects a schema reaches into its own
46
+ * `$defs` and points at them with `#/components/schemas/<id>`; lift them into
47
+ * the document's components once.
48
+ */
49
+ function hoistDefinitions(json) {
50
+ const defs = json.$defs;
51
+ delete json.$defs;
52
+ const rewritten = rewriteRefs(json);
53
+ if (defs) {
54
+ for (const [id, def] of Object.entries(defs)) {
55
+ if (id.startsWith('__schema'))
56
+ throw new Error(`an unregistered recursive schema produced '${id}'; register it with defineComponent`);
57
+ if (!collected.has(id))
58
+ collected.set(id, rewriteRefs(def));
59
+ }
60
+ }
61
+ return rewritten;
62
+ }
63
+ /** `#/$defs/<id>` → `#/components/schemas/<id>`, everywhere in a node. */
64
+ function rewriteRefs(value) {
65
+ if (Array.isArray(value))
66
+ return value.map(rewriteRefs);
67
+ if (value === null || typeof value !== 'object')
68
+ return value;
69
+ return Object.fromEntries(Object.entries(value).map(([key, inner]) => [
70
+ key,
71
+ key === '$ref' && typeof inner === 'string'
72
+ ? inner.replace(/^#\/\$defs\//, COMPONENT_PREFIX)
73
+ : rewriteRefs(inner),
74
+ ]));
75
+ }
76
+ /** The JSON Schema of a registered component, or the inline one. */
77
+ function schemaRef(schema, io) {
78
+ const id = contractRegistry.get(schema)?.id;
79
+ if (id !== undefined) {
80
+ if (!collected.has(id)) {
81
+ // A registered root converts to a `$ref` plus its own definition in
82
+ // `$defs`, which `hoistDefinitions` has just collected under `id`.
83
+ const json = toJson(schema, io);
84
+ if (!collected.has(id)) {
85
+ delete json.$id;
86
+ collected.set(id, json);
87
+ }
88
+ }
89
+ return { $ref: `${COMPONENT_PREFIX}${id}` };
90
+ }
91
+ return toJson(schema, io);
92
+ }
93
+ const requestIdHeader = {
94
+ 'Request-Id': {
95
+ description: 'Identifies this request to Peable support.',
96
+ schema: { type: 'string' },
97
+ },
98
+ 'Peable-Version': {
99
+ description: 'The date of the wire this answer is spelled in.',
100
+ schema: { type: 'string', example: PEABLE_API_VERSION },
101
+ },
102
+ };
103
+ const SECURITY = {
104
+ service: [{ oxyServiceToken: [] }],
105
+ user: [{ oxyUserSession: [] }],
106
+ public: [],
107
+ };
108
+ /** A query schema's properties as OpenAPI parameters. */
109
+ function queryParameters(query) {
110
+ const json = toJson(query, 'input');
111
+ const properties = (json.properties ?? {});
112
+ const required = new Set(json.required ?? []);
113
+ return Object.entries(properties).map(([name, schema]) => {
114
+ const { description, ...rest } = schema;
115
+ const isArray = rest.type === 'array';
116
+ const isObject = rest.type === 'object' || Array.isArray(rest.oneOf);
117
+ return {
118
+ in: 'query',
119
+ name: isArray ? `${name}[]` : name,
120
+ ...(required.has(name) ? { required: true } : {}),
121
+ ...(description === undefined ? {} : { description }),
122
+ ...(isObject ? { style: 'deepObject', explode: true } : {}),
123
+ schema: rest,
124
+ };
125
+ });
126
+ }
127
+ function operation(route) {
128
+ const parameters = pathParamNames(route.path).map((name) => ({
129
+ in: 'path',
130
+ name,
131
+ required: true,
132
+ ...(route.params?.[name] === undefined ? {} : { description: route.params[name] }),
133
+ schema: { type: 'string' },
134
+ }));
135
+ if (route.query)
136
+ parameters.push(...queryParameters(route.query));
137
+ if (route.idempotent)
138
+ parameters.push({
139
+ in: 'header',
140
+ name: 'Idempotency-Key',
141
+ description: 'Makes a retry safe: the same key with the same request answers the stored response for 24 hours (ADR 0014 D3). The SDK sends one on every POST.',
142
+ schema: { type: 'string', maxLength: 255 },
143
+ });
144
+ if (route.peableAccount)
145
+ parameters.push({
146
+ in: 'header',
147
+ name: 'Peable-Account',
148
+ description: 'A platform acting on one of its connected accounts (`ca_…`).',
149
+ schema: { type: 'string' },
150
+ });
151
+ parameters.push({
152
+ in: 'header',
153
+ name: 'Peable-Version',
154
+ description: `The wire date the caller was written against. Only \`${PEABLE_API_VERSION}\` exists.`,
155
+ schema: { type: 'string', enum: [PEABLE_API_VERSION] },
156
+ });
157
+ const status = String(route.status ?? 200);
158
+ const response = route.response;
159
+ let content;
160
+ if (isJsonResponse(response)) {
161
+ content = { 'application/json': { schema: schemaRef(response, 'output') } };
162
+ }
163
+ else if (response.kind === 'binary') {
164
+ content = { [response.contentType]: { schema: { type: 'string', format: 'binary' } } };
165
+ }
166
+ else {
167
+ content = {
168
+ 'text/event-stream': {
169
+ schema: { type: 'string' },
170
+ 'x-peable-event': schemaRef(response.event, 'output'),
171
+ },
172
+ };
173
+ }
174
+ return {
175
+ operationId: route.operationId,
176
+ tags: [route.tag],
177
+ summary: route.summary,
178
+ ...(route.description === undefined ? {} : { description: route.description }),
179
+ security: SECURITY[route.auth],
180
+ ...(route.scope === undefined ? {} : { 'x-peable-scope': route.scope }),
181
+ ...(route.sdk === undefined ? {} : { 'x-peable-sdk': route.sdk }),
182
+ ...(route.expandable === undefined ? {} : { 'x-peable-expandable': route.expandable }),
183
+ ...(route.testModeOnly ? { 'x-peable-test-mode-only': true } : {}),
184
+ parameters,
185
+ ...(route.body
186
+ ? {
187
+ requestBody: {
188
+ required: true,
189
+ content: {
190
+ [route.bodyEncoding === 'multipart' ? 'multipart/form-data' : 'application/json']: {
191
+ schema: toJson(route.body, 'input'),
192
+ },
193
+ },
194
+ },
195
+ }
196
+ : {}),
197
+ responses: {
198
+ [status]: {
199
+ description: 'Success',
200
+ headers: requestIdHeader,
201
+ ...(status === '204' ? {} : { content }),
202
+ },
203
+ default: {
204
+ description: 'The error envelope; the HTTP status and `error.type` identify the failure.',
205
+ headers: requestIdHeader,
206
+ content: { 'application/json': { schema: schemaRef(errorEnvelopeSchema, 'output') } },
207
+ },
208
+ },
209
+ };
210
+ }
211
+ /** Sort an object's keys, recursively, so the document is byte-stable. */
212
+ function sortKeys(value, depth = 0) {
213
+ if (Array.isArray(value))
214
+ return value.map((item) => sortKeys(item, depth + 1));
215
+ if (value === null || typeof value !== 'object')
216
+ return value;
217
+ const entries = Object.entries(value);
218
+ // Only component and path maps are sorted: a schema's own key order (type
219
+ // before properties) reads better as generated.
220
+ return Object.fromEntries(entries.map(([k, v]) => [k, sortKeys(v, depth + 1)]));
221
+ }
222
+ /** Generate the whole document. Pure: the same contracts give the same bytes. */
223
+ export function buildOpenApiDocument() {
224
+ var _a;
225
+ collected.clear();
226
+ const paths = {};
227
+ const tags = new Set();
228
+ for (const route of routes) {
229
+ paths[_a = route.path] ?? (paths[_a] = {});
230
+ const methods = paths[route.path];
231
+ if (methods[route.method] !== undefined)
232
+ throw new Error(`${route.method.toUpperCase()} ${route.path} is declared twice`);
233
+ methods[route.method] = operation(route);
234
+ tags.add(route.tag);
235
+ }
236
+ const webhooks = {};
237
+ for (const event of webhookEvents()) {
238
+ webhooks[event.type] = {
239
+ post: {
240
+ operationId: `webhook_${event.type.replace(/[^a-z0-9]+/g, '_')}`,
241
+ summary: event.type,
242
+ ...(event.description === undefined ? {} : { description: event.description }),
243
+ tags: ['Webhook events'],
244
+ parameters: [
245
+ {
246
+ in: 'header',
247
+ name: 'Peable-Signature',
248
+ required: true,
249
+ description: '`t=<unix seconds>,v1=<hex HMAC-SHA256 of "<t>.<raw body>">`, one `v1=` per active secret while a secret is rolling. Verify with `peable.webhooks.constructEvent`.',
250
+ schema: { type: 'string' },
251
+ },
252
+ ],
253
+ requestBody: {
254
+ required: true,
255
+ content: { 'application/json': { schema: schemaRef(event.schema, 'output') } },
256
+ },
257
+ responses: { '2XX': { description: 'Acknowledged. Anything else is retried.' } },
258
+ },
259
+ };
260
+ tags.add('Webhook events');
261
+ }
262
+ const schemas = Object.fromEntries([...collected.entries()].sort(([a], [b]) => a.localeCompare(b)));
263
+ return sortKeys({
264
+ openapi: '3.1.0',
265
+ info: {
266
+ title: 'Peable API',
267
+ version: PEABLE_API_VERSION,
268
+ description: 'The Peable payments API (Orbit): FairCoin and card payments, Checkout, Payment Links, Billing, Connect and Tax. Amounts are base-unit integer strings; instants are Unix seconds; every object carries `id`, `object` and `livemode`. Guides: https://oxy.so/developers/docs/peable/.',
269
+ contact: { name: 'Peable', url: 'https://oxy.so/developers/docs/peable/' },
270
+ license: { name: 'MIT', identifier: 'MIT' },
271
+ },
272
+ servers: [{ url: 'https://api.peable.to', description: 'Production (test and live modes)' }],
273
+ tags: [...tags].sort().map((name) => ({ name })),
274
+ paths: Object.fromEntries(Object.entries(paths).sort(([a], [b]) => a.localeCompare(b))),
275
+ webhooks: Object.fromEntries(Object.entries(webhooks).sort(([a], [b]) => a.localeCompare(b))),
276
+ components: {
277
+ securitySchemes: {
278
+ oxyServiceToken: {
279
+ type: 'http',
280
+ scheme: 'bearer',
281
+ bearerFormat: 'Oxy service token (EdDSA JWT)',
282
+ description: "Your server's Oxy service token, minted from its application credential. `@peable.to/sdk` mints and refreshes it for you.",
283
+ },
284
+ oxyUserSession: {
285
+ type: 'http',
286
+ scheme: 'bearer',
287
+ bearerFormat: 'Oxy user session',
288
+ description: 'A signed-in Oxy user (the Peable app, an Oxy app acting for its user).',
289
+ },
290
+ },
291
+ schemas,
292
+ },
293
+ });
294
+ }
@@ -0,0 +1,2 @@
1
+ export { buildOpenApiDocument } from './document.js';
2
+ export { webhookEvents } from './webhooks.js';
@@ -0,0 +1,14 @@
1
+ import { eventSchemaOf, WEBHOOK_EVENT_DESCRIPTIONS } from '../resources/events/events.js';
2
+ import { WEBHOOK_EVENT_TYPES } from '../vocabulary/events.js';
3
+ /**
4
+ * Every event type the gateway emits, with its payload: one entry per member
5
+ * of `WEBHOOK_EVENT_TYPES`, its body the `Event` envelope with `type` fixed and
6
+ * `data.object` the object `WEBHOOK_EVENT_OBJECTS` names.
7
+ */
8
+ export function webhookEvents() {
9
+ return WEBHOOK_EVENT_TYPES.map((type) => ({
10
+ type,
11
+ description: WEBHOOK_EVENT_DESCRIPTIONS[type],
12
+ schema: eventSchemaOf(type),
13
+ }));
14
+ }
@@ -0,0 +1,234 @@
1
+ import { z } from 'zod';
2
+ import { listOf } from '../../common/envelopes.js';
3
+ import { defineComponent, defineObject } from '../../common/objects.js';
4
+ import { expandOnlyQuery, idParam, listQuery, metadataCreateParam, metadataUpdateParam, queryBoolean, } from '../../common/params.js';
5
+ import { livemode, metadata, unixSeconds } from '../../common/primitives.js';
6
+ import { defineRoute } from '../../route.js';
7
+ import { PORTAL_CANCEL_MODES, PORTAL_CANCEL_PRORATION_BEHAVIORS, PORTAL_CUSTOMER_UPDATES, PORTAL_SUBSCRIPTION_UPDATES, } from '../../vocabulary/billingPortal.js';
8
+ import { PRORATION_BEHAVIORS } from '../../vocabulary/subscriptions.js';
9
+ import { httpUrlParam, shortText } from './params.js';
10
+ /**
11
+ * The customer portal's merchant side (ADR 0018 §9): configurations (`bpc_…`)
12
+ * say what the Orbit-hosted portal lets a customer do; a session (`bps_…`) is
13
+ * a short-lived URL for ONE customer.
14
+ */
15
+ /** What the hosted portal lets a customer do. */
16
+ export const billingPortalFeaturesSchema = defineComponent('BillingPortalFeatures', z
17
+ .object({
18
+ customer_update: z
19
+ .object({
20
+ enabled: z.boolean(),
21
+ allowed_updates: z.array(z.enum(PORTAL_CUSTOMER_UPDATES)),
22
+ })
23
+ .strict(),
24
+ invoice_history: z.object({ enabled: z.boolean() }).strict(),
25
+ payment_method_update: z.object({ enabled: z.boolean() }).strict(),
26
+ subscription_cancel: z
27
+ .object({
28
+ enabled: z.boolean(),
29
+ mode: z.enum(PORTAL_CANCEL_MODES),
30
+ proration_behavior: z.enum(PORTAL_CANCEL_PRORATION_BEHAVIORS),
31
+ })
32
+ .strict(),
33
+ subscription_update: z
34
+ .object({
35
+ enabled: z.boolean(),
36
+ default_allowed_updates: z.array(z.enum(PORTAL_SUBSCRIPTION_UPDATES)),
37
+ proration_behavior: z.enum(PRORATION_BEHAVIORS),
38
+ products: z
39
+ .array(z.object({ product: z.string(), prices: z.array(z.string()) }).strict())
40
+ .describe('The plans a customer may switch between: per product, its allowed prices.'),
41
+ })
42
+ .strict(),
43
+ })
44
+ .strict());
45
+ /** The business the portal presents. */
46
+ export const billingPortalBusinessProfileSchema = defineComponent('BillingPortalBusinessProfile', z
47
+ .object({
48
+ headline: z.string().nullable(),
49
+ privacy_policy_url: z.string().nullable(),
50
+ terms_of_service_url: z.string().nullable(),
51
+ })
52
+ .strict());
53
+ export const billingPortalConfigurationSchema = defineObject('billing_portal.configuration', 'BillingPortalConfiguration', z
54
+ .object({
55
+ id: z.string(),
56
+ object: z.literal('billing_portal.configuration'),
57
+ livemode,
58
+ active: z.boolean(),
59
+ is_default: z
60
+ .boolean()
61
+ .describe('The configuration a session uses when it names none (created on first use).'),
62
+ business_profile: billingPortalBusinessProfileSchema,
63
+ default_return_url: z.string().nullable(),
64
+ features: billingPortalFeaturesSchema,
65
+ metadata,
66
+ created: unixSeconds,
67
+ updated: unixSeconds,
68
+ })
69
+ .strict());
70
+ /**
71
+ * A portal session: a short-lived URL for ONE customer. The URL is a bearer
72
+ * credential — hand it to that customer only, right away. It is answered once
73
+ * and never stored.
74
+ */
75
+ export const billingPortalSessionSchema = defineObject('billing_portal.session', 'BillingPortalSession', z
76
+ .object({
77
+ id: z.string(),
78
+ object: z.literal('billing_portal.session'),
79
+ livemode,
80
+ customer: z.string().describe('The customer (`cus_…`) the portal is for.'),
81
+ configuration: z.string().describe('The configuration (`bpc_…`) it applies.'),
82
+ return_url: z.string().nullable(),
83
+ url: z.string().describe('The portal, for this customer only. A bearer credential.'),
84
+ expires_at: unixSeconds.describe('The URL stops working after this instant.'),
85
+ created: unixSeconds,
86
+ })
87
+ .strict());
88
+ // ---- Requests ------------------------------------------------------------------------
89
+ const businessProfileParams = z
90
+ .object({
91
+ headline: shortText(60).optional(),
92
+ privacy_policy_url: httpUrlParam.optional(),
93
+ terms_of_service_url: httpUrlParam.optional(),
94
+ })
95
+ .strict();
96
+ /** Each named feature field replaces that field; the others keep their value (or default). */
97
+ const featuresParams = z
98
+ .object({
99
+ customer_update: z
100
+ .object({
101
+ enabled: z.boolean().optional(),
102
+ allowed_updates: z.array(z.enum(PORTAL_CUSTOMER_UPDATES)).max(4).optional(),
103
+ })
104
+ .strict()
105
+ .optional(),
106
+ invoice_history: z.object({ enabled: z.boolean() }).strict().optional(),
107
+ payment_method_update: z.object({ enabled: z.boolean() }).strict().optional(),
108
+ subscription_cancel: z
109
+ .object({
110
+ enabled: z.boolean().optional(),
111
+ mode: z.enum(PORTAL_CANCEL_MODES).optional(),
112
+ proration_behavior: z.enum(PORTAL_CANCEL_PRORATION_BEHAVIORS).optional(),
113
+ })
114
+ .strict()
115
+ .optional(),
116
+ subscription_update: z
117
+ .object({
118
+ enabled: z.boolean().optional(),
119
+ default_allowed_updates: z.array(z.enum(PORTAL_SUBSCRIPTION_UPDATES)).max(2).optional(),
120
+ proration_behavior: z.enum(PRORATION_BEHAVIORS).optional(),
121
+ products: z
122
+ .array(z.object({ product: idParam, prices: z.array(idParam).min(1).max(10) }).strict())
123
+ .max(10)
124
+ .optional(),
125
+ })
126
+ .strict()
127
+ .optional(),
128
+ })
129
+ .strict();
130
+ export const createBillingPortalConfigurationParams = z
131
+ .object({
132
+ business_profile: businessProfileParams.optional(),
133
+ default_return_url: httpUrlParam.optional(),
134
+ features: featuresParams,
135
+ metadata: metadataCreateParam.optional(),
136
+ })
137
+ .strict();
138
+ /** A field sent as `""` is cleared; `metadata` is a patch. */
139
+ export const updateBillingPortalConfigurationParams = z
140
+ .object({
141
+ active: z.boolean().optional().describe('The default configuration cannot be deactivated.'),
142
+ business_profile: businessProfileParams.optional(),
143
+ default_return_url: z.union([httpUrlParam, z.literal('')]).optional(),
144
+ features: featuresParams.optional(),
145
+ metadata: metadataUpdateParam.optional(),
146
+ })
147
+ .strict();
148
+ export const listBillingPortalConfigurationsQuery = listQuery({
149
+ active: queryBoolean.optional(),
150
+ is_default: queryBoolean.optional(),
151
+ });
152
+ export const createBillingPortalSessionParams = z
153
+ .object({
154
+ customer: idParam,
155
+ configuration: idParam
156
+ .optional()
157
+ .describe("Default: the merchant's default configuration (created on first use)."),
158
+ return_url: httpUrlParam.optional(),
159
+ })
160
+ .strict();
161
+ // ---- Routes --------------------------------------------------------------------------
162
+ const configurationId = { id: 'The portal configuration (`bpc_…`).' };
163
+ export const billingPortalRoutes = [
164
+ defineRoute({
165
+ operationId: 'createBillingPortalConfiguration',
166
+ method: 'post',
167
+ path: '/v1/billing_portal/configurations',
168
+ tag: 'Customer portal',
169
+ summary: 'Create a portal configuration',
170
+ description: "Features not named take the safe defaults. The merchant's first configuration becomes the default.",
171
+ auth: 'service',
172
+ scope: 'payments:write',
173
+ idempotent: true,
174
+ body: createBillingPortalConfigurationParams,
175
+ response: billingPortalConfigurationSchema,
176
+ sdk: 'billingPortal.configurations.create',
177
+ }),
178
+ defineRoute({
179
+ operationId: 'listBillingPortalConfigurations',
180
+ method: 'get',
181
+ path: '/v1/billing_portal/configurations',
182
+ tag: 'Customer portal',
183
+ summary: 'List portal configurations',
184
+ auth: 'service',
185
+ scope: 'payments:read',
186
+ query: listBillingPortalConfigurationsQuery,
187
+ response: listOf(billingPortalConfigurationSchema),
188
+ sdk: 'billingPortal.configurations.list',
189
+ expandable: 'billing_portal.configuration',
190
+ }),
191
+ defineRoute({
192
+ operationId: 'retrieveBillingPortalConfiguration',
193
+ method: 'get',
194
+ path: '/v1/billing_portal/configurations/{id}',
195
+ tag: 'Customer portal',
196
+ summary: 'Retrieve a portal configuration',
197
+ auth: 'service',
198
+ scope: 'payments:read',
199
+ params: configurationId,
200
+ query: expandOnlyQuery,
201
+ response: billingPortalConfigurationSchema,
202
+ sdk: 'billingPortal.configurations.retrieve',
203
+ expandable: 'billing_portal.configuration',
204
+ }),
205
+ defineRoute({
206
+ operationId: 'updateBillingPortalConfiguration',
207
+ method: 'post',
208
+ path: '/v1/billing_portal/configurations/{id}',
209
+ tag: 'Customer portal',
210
+ summary: 'Update a portal configuration',
211
+ description: 'Each named feature field replaces that field; the others are kept.',
212
+ auth: 'service',
213
+ scope: 'payments:write',
214
+ idempotent: true,
215
+ params: configurationId,
216
+ body: updateBillingPortalConfigurationParams,
217
+ response: billingPortalConfigurationSchema,
218
+ sdk: 'billingPortal.configurations.update',
219
+ }),
220
+ defineRoute({
221
+ operationId: 'createBillingPortalSession',
222
+ method: 'post',
223
+ path: '/v1/billing_portal/sessions',
224
+ tag: 'Customer portal',
225
+ summary: 'Create a portal session',
226
+ description: 'A one-hour URL of the Orbit-hosted portal for one customer. The URL is a bearer credential: hand it to that customer only, right away.',
227
+ auth: 'service',
228
+ scope: 'payments:write',
229
+ idempotent: true,
230
+ body: createBillingPortalSessionParams,
231
+ response: billingPortalSessionSchema,
232
+ sdk: 'billingPortal.sessions.create',
233
+ }),
234
+ ];