@peable.to/contracts 0.3.0 → 1.0.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 (316) 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 -97
  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/errors.js +174 -0
  92. package/dist/cjs/vocabulary/events.js +176 -0
  93. package/dist/cjs/vocabulary/files.js +44 -0
  94. package/dist/cjs/vocabulary/index.js +37 -0
  95. package/dist/cjs/vocabulary/invoices.js +52 -0
  96. package/dist/cjs/vocabulary/lists.js +22 -0
  97. package/dist/cjs/vocabulary/merchants.js +23 -0
  98. package/dist/cjs/vocabulary/money.js +104 -0
  99. package/dist/cjs/vocabulary/paymentMethodConfigurations.js +36 -0
  100. package/dist/cjs/vocabulary/payments.js +195 -0
  101. package/dist/cjs/vocabulary/reporting.js +27 -0
  102. package/dist/cjs/vocabulary/subscriptions.js +60 -0
  103. package/dist/cjs/vocabulary/tax.js +237 -0
  104. package/dist/cjs/vocabulary/version.js +12 -0
  105. package/dist/esm/common/address.js +76 -0
  106. package/dist/esm/common/envelopes.js +95 -0
  107. package/dist/esm/common/objects.js +74 -0
  108. package/dist/esm/common/params.js +203 -0
  109. package/dist/esm/common/primitives.js +35 -0
  110. package/dist/esm/contributions.js +5 -0
  111. package/dist/esm/index.js +26 -94
  112. package/dist/esm/openapi/document.js +294 -0
  113. package/dist/esm/openapi/index.js +2 -0
  114. package/dist/esm/openapi/webhooks.js +14 -0
  115. package/dist/esm/resources/billingEngine/billingPortal.js +234 -0
  116. package/dist/esm/resources/billingEngine/creditNotes.js +186 -0
  117. package/dist/esm/resources/billingEngine/customerBalanceTransactions.js +87 -0
  118. package/dist/esm/resources/billingEngine/index.js +26 -0
  119. package/dist/esm/resources/billingEngine/invoiceItems.js +152 -0
  120. package/dist/esm/resources/billingEngine/invoices.js +506 -0
  121. package/dist/esm/resources/billingEngine/params.js +39 -0
  122. package/dist/esm/resources/billingEngine/public.js +323 -0
  123. package/dist/esm/resources/billingEngine/subscriptions.js +473 -0
  124. package/dist/esm/resources/catalog/billing.js +752 -0
  125. package/dist/esm/resources/catalog/billingSettings.js +128 -0
  126. package/dist/esm/resources/catalog/coupons.js +219 -0
  127. package/dist/esm/resources/catalog/entitlements.js +254 -0
  128. package/dist/esm/resources/catalog/index.js +38 -0
  129. package/dist/esm/resources/catalog/meters.js +276 -0
  130. package/dist/esm/resources/catalog/prices.js +419 -0
  131. package/dist/esm/resources/catalog/products.js +225 -0
  132. package/dist/esm/resources/catalog/promotionCodes.js +171 -0
  133. package/dist/esm/resources/catalog/shared.js +67 -0
  134. package/dist/esm/resources/catalog/testClocks.js +124 -0
  135. package/dist/esm/resources/checkout/checkoutSessions.js +579 -0
  136. package/dist/esm/resources/checkout/contributions.js +167 -0
  137. package/dist/esm/resources/checkout/files.js +130 -0
  138. package/dist/esm/resources/checkout/index.js +25 -0
  139. package/dist/esm/resources/checkout/merchants.js +287 -0
  140. package/dist/esm/resources/checkout/paymentLinks.js +327 -0
  141. package/dist/esm/resources/checkout/paymentMethodConfigurations.js +259 -0
  142. package/dist/esm/resources/checkout/shared.js +363 -0
  143. package/dist/esm/resources/connect/account.js +329 -0
  144. package/dist/esm/resources/connect/applicationFees.js +110 -0
  145. package/dist/esm/resources/connect/balance.js +209 -0
  146. package/dist/esm/resources/connect/connectedAccounts.js +257 -0
  147. package/dist/esm/resources/connect/index.js +34 -0
  148. package/dist/esm/resources/connect/onboarding.js +79 -0
  149. package/dist/esm/resources/connect/payouts.js +193 -0
  150. package/dist/esm/resources/connect/reporting.js +232 -0
  151. package/dist/esm/resources/connect/requestLogs.js +107 -0
  152. package/dist/esm/resources/connect/transfers.js +224 -0
  153. package/dist/esm/resources/core/customers.js +191 -0
  154. package/dist/esm/resources/core/index.js +6 -0
  155. package/dist/esm/resources/core/paymentMethods.js +131 -0
  156. package/dist/esm/resources/events/events.js +353 -0
  157. package/dist/esm/resources/events/index.js +12 -0
  158. package/dist/esm/resources/events/webhookDeliveries.js +90 -0
  159. package/dist/esm/resources/events/webhookEndpoints.js +212 -0
  160. package/dist/esm/resources/payments/charges.js +154 -0
  161. package/dist/esm/resources/payments/disputes.js +201 -0
  162. package/dist/esm/resources/payments/index.js +24 -0
  163. package/dist/esm/resources/payments/paymentIntents.js +526 -0
  164. package/dist/esm/resources/payments/refunds.js +242 -0
  165. package/dist/esm/resources/payments/setupIntents.js +155 -0
  166. package/dist/esm/resources/payments/social.js +179 -0
  167. package/dist/esm/resources/payments/testHelpers.js +36 -0
  168. package/dist/esm/resources/tax/assessments.js +214 -0
  169. package/dist/esm/resources/tax/businessProfile.js +96 -0
  170. package/dist/esm/resources/tax/calculations.js +173 -0
  171. package/dist/esm/resources/tax/capabilities.js +39 -0
  172. package/dist/esm/resources/tax/codes.js +34 -0
  173. package/dist/esm/resources/tax/complianceActions.js +53 -0
  174. package/dist/esm/resources/tax/deadlines.js +56 -0
  175. package/dist/esm/resources/tax/documents.js +125 -0
  176. package/dist/esm/resources/tax/index.js +63 -0
  177. package/dist/esm/resources/tax/locationEvidence.js +128 -0
  178. package/dist/esm/resources/tax/operatingLocations.js +95 -0
  179. package/dist/esm/resources/tax/products.js +64 -0
  180. package/dist/esm/resources/tax/registrationDeclarations.js +121 -0
  181. package/dist/esm/resources/tax/registrations.js +79 -0
  182. package/dist/esm/resources/tax/reports.js +89 -0
  183. package/dist/esm/resources/tax/reviewItems.js +113 -0
  184. package/dist/esm/resources/tax/ruleSet.js +65 -0
  185. package/dist/esm/resources/tax/salesDestinations.js +91 -0
  186. package/dist/esm/resources/tax/settings.js +101 -0
  187. package/dist/esm/resources/tax/shared.js +58 -0
  188. package/dist/esm/resources/tax/transactions.js +99 -0
  189. package/dist/esm/route.js +16 -0
  190. package/dist/esm/routes.js +27 -0
  191. package/dist/esm/vocabulary/billingPortal.js +12 -0
  192. package/dist/esm/vocabulary/catalog.js +106 -0
  193. package/dist/esm/vocabulary/checkout.js +50 -0
  194. package/dist/esm/vocabulary/connect.js +92 -0
  195. package/dist/esm/vocabulary/errors.js +169 -0
  196. package/dist/esm/vocabulary/events.js +173 -0
  197. package/dist/esm/vocabulary/files.js +41 -0
  198. package/dist/esm/vocabulary/index.js +21 -0
  199. package/dist/esm/vocabulary/invoices.js +49 -0
  200. package/dist/esm/vocabulary/lists.js +19 -0
  201. package/dist/esm/vocabulary/merchants.js +20 -0
  202. package/dist/esm/vocabulary/money.js +98 -0
  203. package/dist/esm/vocabulary/paymentMethodConfigurations.js +33 -0
  204. package/dist/esm/vocabulary/payments.js +192 -0
  205. package/dist/esm/vocabulary/reporting.js +24 -0
  206. package/dist/esm/vocabulary/subscriptions.js +57 -0
  207. package/dist/esm/vocabulary/tax.js +233 -0
  208. package/dist/esm/vocabulary/version.js +9 -0
  209. package/dist/types/common/address.d.ts +62 -0
  210. package/dist/types/common/envelopes.d.ts +88 -0
  211. package/dist/types/common/objects.d.ts +107 -0
  212. package/dist/types/common/params.d.ts +156 -0
  213. package/dist/types/common/primitives.d.ts +56 -0
  214. package/dist/types/contributions.d.ts +1 -0
  215. package/dist/types/index.d.ts +16 -134
  216. package/dist/types/openapi/document.d.ts +16 -0
  217. package/dist/types/openapi/index.d.ts +2 -0
  218. package/dist/types/openapi/webhooks.d.ts +15 -0
  219. package/dist/types/resources/billingEngine/billingPortal.d.ts +742 -0
  220. package/dist/types/resources/billingEngine/creditNotes.d.ts +655 -0
  221. package/dist/types/resources/billingEngine/customerBalanceTransactions.d.ts +282 -0
  222. package/dist/types/resources/billingEngine/index.d.ts +6071 -0
  223. package/dist/types/resources/billingEngine/invoiceItems.d.ts +502 -0
  224. package/dist/types/resources/billingEngine/invoices.d.ts +2547 -0
  225. package/dist/types/resources/billingEngine/params.d.ts +51 -0
  226. package/dist/types/resources/billingEngine/public.d.ts +1860 -0
  227. package/dist/types/resources/billingEngine/subscriptions.d.ts +1519 -0
  228. package/dist/types/resources/catalog/billing.d.ts +1723 -0
  229. package/dist/types/resources/catalog/billingSettings.d.ts +160 -0
  230. package/dist/types/resources/catalog/coupons.d.ts +403 -0
  231. package/dist/types/resources/catalog/entitlements.d.ts +422 -0
  232. package/dist/types/resources/catalog/index.d.ts +3155 -0
  233. package/dist/types/resources/catalog/meters.d.ts +474 -0
  234. package/dist/types/resources/catalog/prices.d.ts +1091 -0
  235. package/dist/types/resources/catalog/products.d.ts +430 -0
  236. package/dist/types/resources/catalog/promotionCodes.d.ts +369 -0
  237. package/dist/types/resources/catalog/shared.d.ts +34 -0
  238. package/dist/types/resources/catalog/testClocks.d.ts +220 -0
  239. package/dist/types/resources/checkout/checkoutSessions.d.ts +3207 -0
  240. package/dist/types/resources/checkout/contributions.d.ts +375 -0
  241. package/dist/types/resources/checkout/files.d.ts +280 -0
  242. package/dist/types/resources/checkout/index.d.ts +5678 -0
  243. package/dist/types/resources/checkout/merchants.d.ts +395 -0
  244. package/dist/types/resources/checkout/paymentLinks.d.ts +1728 -0
  245. package/dist/types/resources/checkout/paymentMethodConfigurations.d.ts +2104 -0
  246. package/dist/types/resources/checkout/shared.d.ts +419 -0
  247. package/dist/types/resources/connect/account.d.ts +483 -0
  248. package/dist/types/resources/connect/applicationFees.d.ts +198 -0
  249. package/dist/types/resources/connect/balance.d.ts +399 -0
  250. package/dist/types/resources/connect/connectedAccounts.d.ts +494 -0
  251. package/dist/types/resources/connect/index.d.ts +2094 -0
  252. package/dist/types/resources/connect/onboarding.d.ts +95 -0
  253. package/dist/types/resources/connect/payouts.d.ts +527 -0
  254. package/dist/types/resources/connect/reporting.d.ts +506 -0
  255. package/dist/types/resources/connect/requestLogs.d.ts +236 -0
  256. package/dist/types/resources/connect/transfers.d.ts +436 -0
  257. package/dist/types/resources/core/customers.d.ts +619 -0
  258. package/dist/types/resources/core/index.d.ts +679 -0
  259. package/dist/types/resources/core/paymentMethods.d.ts +336 -0
  260. package/dist/types/resources/events/events.d.ts +731 -0
  261. package/dist/types/resources/events/index.d.ts +1727 -0
  262. package/dist/types/resources/events/webhookDeliveries.d.ts +436 -0
  263. package/dist/types/resources/events/webhookEndpoints.d.ts +1502 -0
  264. package/dist/types/resources/payments/charges.d.ts +390 -0
  265. package/dist/types/resources/payments/disputes.d.ts +822 -0
  266. package/dist/types/resources/payments/index.d.ts +3517 -0
  267. package/dist/types/resources/payments/paymentIntents.d.ts +2080 -0
  268. package/dist/types/resources/payments/refunds.d.ts +684 -0
  269. package/dist/types/resources/payments/setupIntents.d.ts +391 -0
  270. package/dist/types/resources/payments/social.d.ts +266 -0
  271. package/dist/types/resources/payments/testHelpers.d.ts +178 -0
  272. package/dist/types/resources/tax/assessments.d.ts +787 -0
  273. package/dist/types/resources/tax/businessProfile.d.ts +134 -0
  274. package/dist/types/resources/tax/calculations.d.ts +261 -0
  275. package/dist/types/resources/tax/capabilities.d.ts +81 -0
  276. package/dist/types/resources/tax/codes.d.ts +29 -0
  277. package/dist/types/resources/tax/complianceActions.d.ts +97 -0
  278. package/dist/types/resources/tax/deadlines.d.ts +133 -0
  279. package/dist/types/resources/tax/documents.d.ts +257 -0
  280. package/dist/types/resources/tax/index.d.ts +1946 -0
  281. package/dist/types/resources/tax/locationEvidence.d.ts +246 -0
  282. package/dist/types/resources/tax/operatingLocations.d.ts +170 -0
  283. package/dist/types/resources/tax/products.d.ts +68 -0
  284. package/dist/types/resources/tax/registrationDeclarations.d.ts +270 -0
  285. package/dist/types/resources/tax/registrations.d.ts +103 -0
  286. package/dist/types/resources/tax/reports.d.ts +129 -0
  287. package/dist/types/resources/tax/reviewItems.d.ts +226 -0
  288. package/dist/types/resources/tax/ruleSet.d.ts +219 -0
  289. package/dist/types/resources/tax/salesDestinations.d.ts +158 -0
  290. package/dist/types/resources/tax/settings.d.ts +122 -0
  291. package/dist/types/resources/tax/shared.d.ts +43 -0
  292. package/dist/types/resources/tax/transactions.d.ts +404 -0
  293. package/dist/types/route.d.ts +86 -0
  294. package/dist/types/routes.d.ts +23 -0
  295. package/dist/types/vocabulary/billingPortal.d.ts +15 -0
  296. package/dist/types/vocabulary/catalog.d.ts +97 -0
  297. package/dist/types/vocabulary/checkout.d.ts +49 -0
  298. package/dist/types/vocabulary/connect.d.ts +62 -0
  299. package/dist/types/vocabulary/errors.d.ts +145 -0
  300. package/dist/types/vocabulary/events.d.ts +171 -0
  301. package/dist/types/vocabulary/files.d.ts +30 -0
  302. package/dist/types/vocabulary/index.d.ts +17 -0
  303. package/dist/types/vocabulary/invoices.d.ts +39 -0
  304. package/dist/types/vocabulary/lists.d.ts +9 -0
  305. package/dist/types/vocabulary/merchants.d.ts +9 -0
  306. package/dist/types/vocabulary/money.d.ts +59 -0
  307. package/dist/types/vocabulary/paymentMethodConfigurations.d.ts +22 -0
  308. package/dist/types/vocabulary/payments.d.ts +117 -0
  309. package/dist/types/vocabulary/reporting.d.ts +18 -0
  310. package/dist/types/vocabulary/subscriptions.d.ts +45 -0
  311. package/dist/types/vocabulary/tax.d.ts +163 -0
  312. package/dist/types/vocabulary/version.d.ts +10 -0
  313. package/package.json +51 -11
  314. package/dist/cjs/openapi.js +0 -138
  315. package/dist/esm/openapi.js +0 -134
  316. package/dist/types/openapi.d.ts +0 -145
@@ -0,0 +1,276 @@
1
+ import { z } from 'zod';
2
+ import { listOf } from '../../common/envelopes.js';
3
+ import { defineObject } from '../../common/objects.js';
4
+ import { expandOnlyQuery, idParam, listQuery, queryUnixSeconds, unixSecondsParam, } from '../../common/params.js';
5
+ import { livemode, unixSeconds } from '../../common/primitives.js';
6
+ import { defineRoute } from '../../route.js';
7
+ import { METER_AGGREGATIONS, METER_STATUSES } from '../../vocabulary/catalog.js';
8
+ /**
9
+ * Usage meters (`mtr_…`, ADR 0018 §7): usage events named `event_name`,
10
+ * attributed to a customer by `customer_mapping.event_payload_key` of their
11
+ * payload and measured by `value_settings.event_payload_key`. A metered price
12
+ * (`recurring.meter`) bills its aggregate per period, in arrears.
13
+ */
14
+ export const billingMeterSchema = defineObject('billing.meter', 'BillingMeter', z
15
+ .object({
16
+ id: z.string(),
17
+ object: z.literal('billing.meter'),
18
+ livemode,
19
+ display_name: z.string(),
20
+ event_name: z.string().describe('The `event_name` of the meter events it counts.'),
21
+ default_aggregation: z
22
+ .object({
23
+ formula: z
24
+ .enum(METER_AGGREGATIONS)
25
+ .describe("How a period's events combine into the quantity billed."),
26
+ })
27
+ .strict(),
28
+ customer_mapping: z
29
+ .object({
30
+ type: z.literal('by_id'),
31
+ event_payload_key: z
32
+ .string()
33
+ .describe('The payload key carrying the customer (`cus_…`).'),
34
+ })
35
+ .strict(),
36
+ value_settings: z
37
+ .object({
38
+ event_payload_key: z.string().describe('The payload key carrying the value.'),
39
+ })
40
+ .strict(),
41
+ status: z.enum(METER_STATUSES),
42
+ created: unixSeconds,
43
+ updated: unixSeconds,
44
+ })
45
+ .strict(), {
46
+ examples: [
47
+ {
48
+ id: 'mtr_0193b8f2c1a87d3e9f4e',
49
+ object: 'billing.meter',
50
+ livemode: false,
51
+ display_name: 'API calls',
52
+ event_name: 'api_call',
53
+ default_aggregation: { formula: 'sum' },
54
+ customer_mapping: { type: 'by_id', event_payload_key: 'peable_customer_id' },
55
+ value_settings: { event_payload_key: 'value' },
56
+ status: 'active',
57
+ created: 1793750400,
58
+ updated: 1793750400,
59
+ },
60
+ ],
61
+ });
62
+ /**
63
+ * One usage event, `POST /v1/billing/meter_events`. `identifier` makes it
64
+ * idempotent: the same identifier is the same event, forever.
65
+ */
66
+ export const billingMeterEventSchema = defineObject('billing.meter_event', 'BillingMeterEvent', z
67
+ .object({
68
+ object: z.literal('billing.meter_event'),
69
+ livemode,
70
+ identifier: z.string(),
71
+ event_name: z.string(),
72
+ payload: z
73
+ .record(z.string(), z.string())
74
+ .describe('The payload as received: the customer key and the value, as strings.'),
75
+ timestamp: unixSeconds,
76
+ created: unixSeconds,
77
+ })
78
+ .strict(), {
79
+ examples: [
80
+ {
81
+ object: 'billing.meter_event',
82
+ livemode: false,
83
+ identifier: 'req_8f3a2c',
84
+ event_name: 'api_call',
85
+ payload: { peable_customer_id: 'cus_0193b8f2c1a87d3e9f4a', value: '25' },
86
+ timestamp: 1793750400,
87
+ created: 1793750400,
88
+ },
89
+ ],
90
+ });
91
+ /** A customer's aggregate over a window: `GET /v1/billing/meters/{id}/event_summaries`. */
92
+ export const billingMeterEventSummarySchema = defineObject('billing.meter_event_summary', 'BillingMeterEventSummary', z
93
+ .object({
94
+ id: z.string(),
95
+ object: z.literal('billing.meter_event_summary'),
96
+ livemode,
97
+ meter: z.string().describe('The meter (`mtr_…`).'),
98
+ aggregated_value: z
99
+ .string()
100
+ .describe('The aggregate, as an integer string (it can exceed a JS number).'),
101
+ start_time: unixSeconds,
102
+ end_time: unixSeconds,
103
+ })
104
+ .strict(), {
105
+ examples: [
106
+ {
107
+ id: 'mtrsum_0193b8f2c1a87d3e9f4e_1793750400',
108
+ object: 'billing.meter_event_summary',
109
+ livemode: false,
110
+ meter: 'mtr_0193b8f2c1a87d3e9f4e',
111
+ aggregated_value: '1250',
112
+ start_time: 1793750400,
113
+ end_time: 1796342400,
114
+ },
115
+ ],
116
+ });
117
+ const payloadKey = z.string().regex(/^[A-Za-z0-9_]{1,100}$/);
118
+ const eventName = z.string().regex(/^[A-Za-z0-9_.:-]{1,100}$/);
119
+ const displayName = z.string().min(1).max(250);
120
+ export const createBillingMeterParams = z
121
+ .object({
122
+ display_name: displayName,
123
+ event_name: eventName,
124
+ default_aggregation: z.object({ formula: z.enum(METER_AGGREGATIONS) }).strict(),
125
+ customer_mapping: z
126
+ .object({ type: z.literal('by_id'), event_payload_key: payloadKey })
127
+ .strict()
128
+ .optional()
129
+ .describe("Default `{ type: 'by_id', event_payload_key: 'peable_customer_id' }`."),
130
+ value_settings: z
131
+ .object({ event_payload_key: payloadKey })
132
+ .strict()
133
+ .optional()
134
+ .describe("Default `{ event_payload_key: 'value' }`."),
135
+ })
136
+ .strict();
137
+ export const updateBillingMeterParams = z.object({ display_name: displayName.optional() }).strict();
138
+ /** The body of `deactivate` / `reactivate`: nothing. */
139
+ export const billingMeterStatusParams = z.object({}).strict();
140
+ export const listBillingMetersQuery = listQuery({ status: z.enum(METER_STATUSES).optional() });
141
+ export const billingMeterEventSummariesQuery = z
142
+ .object({
143
+ customer: idParam.describe('The customer (`cus_…`) whose usage is aggregated.'),
144
+ start_time: queryUnixSeconds.describe('The window start (inclusive).'),
145
+ end_time: queryUnixSeconds.describe('The window end (exclusive), after `start_time`.'),
146
+ })
147
+ .strict();
148
+ export const createBillingMeterEventParams = z
149
+ .object({
150
+ event_name: eventName,
151
+ payload: z.record(z.string().max(100), z.string().max(255)),
152
+ identifier: z
153
+ .string()
154
+ .min(1)
155
+ .max(100)
156
+ .optional()
157
+ .describe('Default: a fresh one — pass your own so a retry is not counted twice.'),
158
+ timestamp: unixSecondsParam
159
+ .optional()
160
+ .describe('Default now. At most 35 days in the past, 5 minutes in the future.'),
161
+ })
162
+ .strict();
163
+ const id = { id: 'The meter (`mtr_…`).' };
164
+ export const meterRoutes = [
165
+ defineRoute({
166
+ operationId: 'createBillingMeter',
167
+ method: 'post',
168
+ path: '/v1/billing/meters',
169
+ tag: 'Meters',
170
+ summary: 'Create a meter',
171
+ auth: 'service',
172
+ scope: 'payments:write',
173
+ idempotent: true,
174
+ body: createBillingMeterParams,
175
+ response: billingMeterSchema,
176
+ sdk: 'billing.meters.create',
177
+ }),
178
+ defineRoute({
179
+ operationId: 'listBillingMeters',
180
+ method: 'get',
181
+ path: '/v1/billing/meters',
182
+ tag: 'Meters',
183
+ summary: 'List meters',
184
+ auth: 'service',
185
+ scope: 'payments:read',
186
+ query: listBillingMetersQuery,
187
+ response: listOf(billingMeterSchema),
188
+ sdk: 'billing.meters.list',
189
+ expandable: 'billing.meter',
190
+ }),
191
+ defineRoute({
192
+ operationId: 'retrieveBillingMeter',
193
+ method: 'get',
194
+ path: '/v1/billing/meters/{id}',
195
+ tag: 'Meters',
196
+ summary: 'Retrieve a meter',
197
+ auth: 'service',
198
+ scope: 'payments:read',
199
+ params: id,
200
+ query: expandOnlyQuery,
201
+ response: billingMeterSchema,
202
+ sdk: 'billing.meters.retrieve',
203
+ }),
204
+ defineRoute({
205
+ operationId: 'updateBillingMeter',
206
+ method: 'post',
207
+ path: '/v1/billing/meters/{id}',
208
+ tag: 'Meters',
209
+ summary: 'Update a meter',
210
+ description: 'Only `display_name` changes.',
211
+ auth: 'service',
212
+ scope: 'payments:write',
213
+ idempotent: true,
214
+ params: id,
215
+ body: updateBillingMeterParams,
216
+ response: billingMeterSchema,
217
+ sdk: 'billing.meters.update',
218
+ }),
219
+ defineRoute({
220
+ operationId: 'deactivateBillingMeter',
221
+ method: 'post',
222
+ path: '/v1/billing/meters/{id}/deactivate',
223
+ tag: 'Meters',
224
+ summary: 'Deactivate a meter',
225
+ description: 'An inactive meter accepts no events.',
226
+ auth: 'service',
227
+ scope: 'payments:write',
228
+ idempotent: true,
229
+ params: id,
230
+ body: billingMeterStatusParams,
231
+ response: billingMeterSchema,
232
+ sdk: 'billing.meters.deactivate',
233
+ }),
234
+ defineRoute({
235
+ operationId: 'reactivateBillingMeter',
236
+ method: 'post',
237
+ path: '/v1/billing/meters/{id}/reactivate',
238
+ tag: 'Meters',
239
+ summary: 'Reactivate a meter',
240
+ auth: 'service',
241
+ scope: 'payments:write',
242
+ idempotent: true,
243
+ params: id,
244
+ body: billingMeterStatusParams,
245
+ response: billingMeterSchema,
246
+ sdk: 'billing.meters.reactivate',
247
+ }),
248
+ defineRoute({
249
+ operationId: 'listBillingMeterEventSummaries',
250
+ method: 'get',
251
+ path: '/v1/billing/meters/{id}/event_summaries',
252
+ tag: 'Meters',
253
+ summary: "A customer's usage over a window",
254
+ description: 'One summary: the aggregate of the window `[start_time, end_time)`.',
255
+ auth: 'service',
256
+ scope: 'payments:read',
257
+ params: id,
258
+ query: billingMeterEventSummariesQuery,
259
+ response: listOf(billingMeterEventSummarySchema),
260
+ sdk: 'billing.meters.listEventSummaries',
261
+ }),
262
+ defineRoute({
263
+ operationId: 'createBillingMeterEvent',
264
+ method: 'post',
265
+ path: '/v1/billing/meter_events',
266
+ tag: 'Meters',
267
+ summary: 'Record a meter event',
268
+ description: 'The customer must be yours and the value a non-negative integer. A repeated `identifier` answers the stored event.',
269
+ auth: 'service',
270
+ scope: 'payments:write',
271
+ idempotent: true,
272
+ body: createBillingMeterEventParams,
273
+ response: billingMeterEventSchema,
274
+ sdk: 'billing.meterEvents.create',
275
+ }),
276
+ ];
@@ -0,0 +1,419 @@
1
+ import { z } from 'zod';
2
+ import { listOf, searchResultOf } from '../../common/envelopes.js';
3
+ import { defineComponent, defineObject, expandable } from '../../common/objects.js';
4
+ import { expandOnlyQuery, expandParam, idParam, listQuery, metadataCreateParam, metadataUpdateParam, searchQuery, } from '../../common/params.js';
5
+ import { amount, currency, livemode, metadata, unixSeconds } from '../../common/primitives.js';
6
+ import { defineRoute } from '../../route.js';
7
+ import { CATALOG_LIMITS, PRICE_BILLING_SCHEMES, PRICE_TAX_BEHAVIORS, PRICE_TIERS_MODES, PRICE_TYPES, RECURRING_INTERVAL_COUNT_MAX, RECURRING_INTERVALS, RECURRING_USAGE_TYPES, TRANSFORM_QUANTITY_ROUNDS, } from '../../vocabulary/catalog.js';
8
+ import { amountWithinBound, baseUnitAmountParam, clearing, countParam, issuer, queryFlag, queryIdList, } from './shared.js';
9
+ /**
10
+ * Prices (`price_…`, ADR 0018) — how much a product costs, in one currency,
11
+ * once or per interval. A price is never deleted and its amount never
12
+ * changes: archive it (`active: false`) and create another.
13
+ */
14
+ /**
15
+ * One tier of a tiered price. `up_to` is the last quantity the tier covers
16
+ * (inclusive), and `null` on the last tier, which covers everything above —
17
+ * sent as `'inf'`. Each amount is a base-unit string; at least one is set.
18
+ */
19
+ export const priceTierSchema = defineComponent('PriceTier', z
20
+ .object({
21
+ up_to: z
22
+ .number()
23
+ .int()
24
+ .nullable()
25
+ .describe('The last quantity this tier covers; `null` on the last tier.'),
26
+ unit_amount: amount.nullable(),
27
+ flat_amount: amount.nullable(),
28
+ })
29
+ .strict());
30
+ /**
31
+ * Divide the quantity before pricing it: `divide_by: 10, round: 'up'` bills
32
+ * 11 units as 2 packs of ten. Per-unit prices only.
33
+ */
34
+ export const priceTransformQuantitySchema = defineComponent('PriceTransformQuantity', z
35
+ .object({
36
+ divide_by: z.number().int(),
37
+ round: z.enum(TRANSFORM_QUANTITY_ROUNDS),
38
+ })
39
+ .strict());
40
+ export const priceRecurringSchema = defineComponent('PriceRecurring', z
41
+ .object({
42
+ interval: z.enum(RECURRING_INTERVALS),
43
+ interval_count: z
44
+ .number()
45
+ .int()
46
+ .describe("Intervals between billings: `interval: 'month', interval_count: 3` is quarterly. At most three years."),
47
+ usage_type: z.enum(RECURRING_USAGE_TYPES),
48
+ meter: z
49
+ .string()
50
+ .nullable()
51
+ .describe('The meter (`mtr_…`) a `metered` price bills; `null` when `licensed`.'),
52
+ })
53
+ .strict());
54
+ export const priceSchema = defineObject('price', 'Price', z
55
+ .object({
56
+ id: z.string(),
57
+ object: z.literal('price'),
58
+ livemode,
59
+ active: z.boolean(),
60
+ product: expandable('product', 'The product it prices: `prod_…`, or the Product with `expand[]=product`.'),
61
+ currency,
62
+ unit_amount: amount.nullable().describe('Base units per unit; `null` on a tiered price.'),
63
+ billing_scheme: z.enum(PRICE_BILLING_SCHEMES),
64
+ tiers: z
65
+ .array(priceTierSchema)
66
+ .nullable()
67
+ .describe('`null` unless `billing_scheme` is `tiered`.'),
68
+ tiers_mode: z.enum(PRICE_TIERS_MODES).nullable(),
69
+ transform_quantity: priceTransformQuantitySchema.nullable(),
70
+ type: z.enum(PRICE_TYPES),
71
+ recurring: priceRecurringSchema
72
+ .nullable()
73
+ .describe('`null` exactly when `type` is `one_time`.'),
74
+ tax_behavior: z
75
+ .enum(PRICE_TAX_BEHAVIORS)
76
+ .describe('Whether the price includes tax (Peable Tax). `unspecified` defers to the merchant default; once `inclusive` or `exclusive` it never changes.'),
77
+ lookup_key: z
78
+ .string()
79
+ .nullable()
80
+ .describe("The merchant's own stable name for this price, unique among its prices (per mode): retrieve the current price of a plan with `lookup_keys[]`."),
81
+ nickname: z.string().nullable(),
82
+ metadata,
83
+ created: unixSeconds,
84
+ })
85
+ .strict(), {
86
+ description: 'How much a product costs, in one currency, once or per interval. Immutable once created except for `active`, `nickname`, `metadata`, `lookup_key` and — while `unspecified` — `tax_behavior`.',
87
+ examples: [
88
+ {
89
+ id: 'price_0193b8f2c1a87d3e9f4b',
90
+ object: 'price',
91
+ livemode: false,
92
+ active: true,
93
+ product: 'prod_0193b8f2c1a87d3e9f4a',
94
+ currency: 'EUR',
95
+ unit_amount: '999',
96
+ billing_scheme: 'per_unit',
97
+ tiers: null,
98
+ tiers_mode: null,
99
+ transform_quantity: null,
100
+ type: 'recurring',
101
+ recurring: { interval: 'month', interval_count: 1, usage_type: 'licensed', meter: null },
102
+ tax_behavior: 'inclusive',
103
+ lookup_key: 'plus_monthly',
104
+ nickname: 'Plus, monthly',
105
+ metadata: {},
106
+ created: 1793750400,
107
+ },
108
+ ],
109
+ });
110
+ // ---- The price shape, as a request names it --------------------------------------
111
+ const recurringParams = z
112
+ .object({
113
+ interval: z.enum(RECURRING_INTERVALS),
114
+ interval_count: countParam.optional().describe('Default 1.'),
115
+ usage_type: z.enum(RECURRING_USAGE_TYPES).optional().describe('Default `licensed`.'),
116
+ meter: z
117
+ .string()
118
+ .min(1)
119
+ .max(255)
120
+ .optional()
121
+ .describe("Required with `usage_type: 'metered'`: the meter (`mtr_…`) it bills."),
122
+ })
123
+ .strict();
124
+ const tierParams = z
125
+ .object({
126
+ up_to: z
127
+ .union([z.number().int().min(1).max(Number.MAX_SAFE_INTEGER), z.literal('inf')])
128
+ .describe("A positive integer, ascending; the last tier is `'inf'`."),
129
+ unit_amount: baseUnitAmountParam.optional(),
130
+ flat_amount: baseUnitAmountParam.optional(),
131
+ })
132
+ .strict();
133
+ const transformQuantityParams = z
134
+ .object({
135
+ divide_by: countParam,
136
+ round: z.enum(TRANSFORM_QUANTITY_ROUNDS),
137
+ })
138
+ .strict();
139
+ /** The fields that make up a price's shape, as a request names them. */
140
+ const priceShapeFields = {
141
+ currency,
142
+ unit_amount: baseUnitAmountParam
143
+ .optional()
144
+ .describe('Required for `per_unit`; absent for `tiered`.'),
145
+ billing_scheme: z.enum(PRICE_BILLING_SCHEMES).optional().describe('Default `per_unit`.'),
146
+ tiers: z.array(tierParams).min(1).max(CATALOG_LIMITS.priceTiersMax).optional(),
147
+ tiers_mode: z.enum(PRICE_TIERS_MODES).optional(),
148
+ transform_quantity: transformQuantityParams.optional(),
149
+ recurring: recurringParams.optional().describe('Present: a recurring price. Absent: one-time.'),
150
+ tax_behavior: z.enum(PRICE_TAX_BEHAVIORS).optional().describe('Default `unspecified`.'),
151
+ };
152
+ function tiersOf(input, currency, issue) {
153
+ let previous = 0;
154
+ return input.map((tier, index) => {
155
+ const last = index === input.length - 1;
156
+ const path = ['tiers', index];
157
+ if (last && tier.up_to !== 'inf') {
158
+ issue([...path, 'up_to'], "the last tier's up_to must be 'inf'");
159
+ }
160
+ else if (!last && tier.up_to === 'inf') {
161
+ issue([...path, 'up_to'], "only the last tier's up_to may be 'inf'");
162
+ }
163
+ else if (tier.up_to !== 'inf') {
164
+ if (tier.up_to <= previous) {
165
+ issue([...path, 'up_to'], 'tier up_to values must ascend');
166
+ }
167
+ previous = tier.up_to;
168
+ }
169
+ if (tier.unit_amount === undefined && tier.flat_amount === undefined) {
170
+ issue(path, 'a tier needs a unit_amount, a flat_amount or both');
171
+ }
172
+ amountWithinBound(issue, tier.unit_amount, currency, [...path, 'unit_amount']);
173
+ amountWithinBound(issue, tier.flat_amount, currency, [...path, 'flat_amount']);
174
+ return {
175
+ up_to: tier.up_to === 'inf' ? null : tier.up_to,
176
+ unit_amount: tier.unit_amount ?? null,
177
+ flat_amount: tier.flat_amount ?? null,
178
+ };
179
+ });
180
+ }
181
+ /**
182
+ * Decide the stored shape of a price from its request fields, adding an issue
183
+ * (with the field's path) for every rule it breaks. Returns `null` when any
184
+ * rule was broken. Amounts are bounded per currency by its decimals
185
+ * (`maxBaseUnits`).
186
+ */
187
+ export function priceShapeOf(input, ctx) {
188
+ const { issue, failed } = issuer(ctx);
189
+ const scheme = input.billing_scheme ?? 'per_unit';
190
+ let tiers = null;
191
+ if (scheme === 'per_unit') {
192
+ if (input.unit_amount === undefined) {
193
+ issue(['unit_amount'], 'unit_amount is required for a per_unit price');
194
+ }
195
+ if (input.tiers !== undefined)
196
+ issue(['tiers'], 'tiers are only for a tiered price');
197
+ if (input.tiers_mode !== undefined) {
198
+ issue(['tiers_mode'], 'tiers_mode is only for a tiered price');
199
+ }
200
+ amountWithinBound(issue, input.unit_amount, input.currency, ['unit_amount']);
201
+ }
202
+ else {
203
+ if (input.unit_amount !== undefined) {
204
+ issue(['unit_amount'], 'a tiered price takes its amounts from tiers, not unit_amount');
205
+ }
206
+ if (input.tiers_mode === undefined)
207
+ issue(['tiers_mode'], 'tiers_mode is required');
208
+ if (input.transform_quantity !== undefined) {
209
+ issue(['transform_quantity'], 'transform_quantity is only for a per_unit price');
210
+ }
211
+ if (input.tiers === undefined)
212
+ issue(['tiers'], 'tiers are required for a tiered price');
213
+ else
214
+ tiers = tiersOf(input.tiers, input.currency, issue);
215
+ }
216
+ let recurring = null;
217
+ if (input.recurring) {
218
+ const count = input.recurring.interval_count ?? 1;
219
+ const max = RECURRING_INTERVAL_COUNT_MAX[input.recurring.interval];
220
+ if (count > max) {
221
+ issue(['recurring', 'interval_count'], `an interval is at most three years (${max} ${input.recurring.interval}s)`);
222
+ }
223
+ const usageType = input.recurring.usage_type ?? 'licensed';
224
+ const meter = input.recurring.meter;
225
+ if (usageType === 'metered' && meter === undefined) {
226
+ issue(['recurring', 'meter'], 'a metered price names the meter (mtr_…) it bills');
227
+ }
228
+ if (usageType === 'licensed' && meter !== undefined) {
229
+ issue(['recurring', 'meter'], 'only a metered price has a meter');
230
+ }
231
+ recurring = {
232
+ interval: input.recurring.interval,
233
+ intervalCount: count,
234
+ usageType,
235
+ ...(meter !== undefined ? { meterPublicId: meter } : {}),
236
+ };
237
+ }
238
+ if (failed())
239
+ return null;
240
+ return {
241
+ currency: input.currency,
242
+ unitAmount: scheme === 'per_unit' ? (input.unit_amount ?? null) : null,
243
+ billingScheme: scheme,
244
+ tiers,
245
+ tiersMode: scheme === 'tiered' ? (input.tiers_mode ?? null) : null,
246
+ transformQuantity: input.transform_quantity
247
+ ? { divideBy: input.transform_quantity.divide_by, round: input.transform_quantity.round }
248
+ : null,
249
+ recurring,
250
+ taxBehavior: input.tax_behavior ?? 'unspecified',
251
+ };
252
+ }
253
+ /**
254
+ * Inline `price_data` (Stripe's): a one-off per-unit price for a checkout
255
+ * line item or an invoice item that names no stored price. Never stored as a
256
+ * `price_…` by itself.
257
+ */
258
+ const inlinePriceFields = {
259
+ currency,
260
+ unit_amount: baseUnitAmountParam,
261
+ recurring: recurringParams.omit({ usage_type: true, meter: true }).optional(),
262
+ tax_behavior: z.enum(PRICE_TAX_BEHAVIORS).optional(),
263
+ };
264
+ /** `price_data` — an inline price of an existing product (`product: 'prod_…'`). */
265
+ export const priceDataParams = z
266
+ .object({
267
+ ...inlinePriceFields,
268
+ product: z.string().min(1).max(255).describe('The `prod_…` it prices.'),
269
+ })
270
+ .strict()
271
+ .transform((input, ctx) => {
272
+ const shape = priceShapeOf(input, ctx);
273
+ return shape === null ? z.NEVER : { product: input.product, shape };
274
+ });
275
+ /** `default_price_data` on a product create — `price_data` for the product being made. */
276
+ export const defaultPriceDataParams = z
277
+ .object(inlinePriceFields)
278
+ .strict()
279
+ .transform((input, ctx) => priceShapeOf(input, ctx) ?? z.NEVER);
280
+ const lookupKey = z.string().min(1).max(CATALOG_LIMITS.lookupKeyMax);
281
+ const nickname = z.string().min(1).max(CATALOG_LIMITS.priceNicknameMax);
282
+ export const createPriceParams = z
283
+ .object({
284
+ ...priceShapeFields,
285
+ product: z.string().min(1).max(255),
286
+ lookup_key: lookupKey.optional(),
287
+ transfer_lookup_key: z
288
+ .boolean()
289
+ .optional()
290
+ .describe('Move `lookup_key` here from the price that holds it.'),
291
+ nickname: nickname.optional(),
292
+ active: z.boolean().optional(),
293
+ metadata: metadataCreateParam.optional(),
294
+ expand: expandParam.optional(),
295
+ })
296
+ .strict()
297
+ .transform((input, ctx) => {
298
+ if (input.transfer_lookup_key && input.lookup_key === undefined) {
299
+ ctx.addIssue({
300
+ code: 'custom',
301
+ path: ['transfer_lookup_key'],
302
+ message: 'transfer_lookup_key needs a lookup_key',
303
+ });
304
+ }
305
+ const shape = priceShapeOf(input, ctx);
306
+ return shape === null ? z.NEVER : { ...input, shape };
307
+ });
308
+ /** The only mutable fields. `""` clears `nickname` and `lookup_key`. */
309
+ export const updatePriceParams = z
310
+ .object({
311
+ active: z.boolean().optional(),
312
+ nickname: clearing(nickname).optional(),
313
+ lookup_key: clearing(lookupKey).optional(),
314
+ transfer_lookup_key: z.boolean().optional(),
315
+ tax_behavior: z
316
+ .enum(PRICE_TAX_BEHAVIORS)
317
+ .optional()
318
+ .describe("Only while the price's is `unspecified`."),
319
+ metadata: metadataUpdateParam.optional(),
320
+ expand: expandParam.optional(),
321
+ })
322
+ .strict()
323
+ .superRefine((body, ctx) => {
324
+ if (body.transfer_lookup_key && (body.lookup_key === undefined || body.lookup_key === null)) {
325
+ ctx.addIssue({
326
+ code: 'custom',
327
+ path: ['transfer_lookup_key'],
328
+ message: 'transfer_lookup_key needs a lookup_key',
329
+ });
330
+ }
331
+ });
332
+ export const listPricesQuery = listQuery({
333
+ product: idParam.optional(),
334
+ active: queryFlag.optional(),
335
+ type: z.enum(PRICE_TYPES).optional(),
336
+ currency: currency.optional(),
337
+ lookup_keys: queryIdList(CATALOG_LIMITS.lookupKeysFilterMax).optional().describe('At most 10.'),
338
+ recurring: z
339
+ .object({
340
+ interval: z.enum(RECURRING_INTERVALS).optional(),
341
+ usage_type: z.enum(RECURRING_USAGE_TYPES).optional(),
342
+ })
343
+ .strict()
344
+ .optional(),
345
+ });
346
+ export const priceRoutes = [
347
+ defineRoute({
348
+ operationId: 'createPrice',
349
+ method: 'post',
350
+ path: '/v1/prices',
351
+ tag: 'Prices',
352
+ summary: 'Create a price',
353
+ auth: 'service',
354
+ scope: 'payments:write',
355
+ idempotent: true,
356
+ body: createPriceParams,
357
+ response: priceSchema,
358
+ sdk: 'prices.create',
359
+ expandable: 'price',
360
+ }),
361
+ defineRoute({
362
+ operationId: 'listPrices',
363
+ method: 'get',
364
+ path: '/v1/prices',
365
+ tag: 'Prices',
366
+ summary: 'List prices',
367
+ description: '`lookup_keys` (at most 10) finds the current price of a plan by its stable name.',
368
+ auth: 'service',
369
+ scope: 'payments:read',
370
+ query: listPricesQuery,
371
+ response: listOf(priceSchema),
372
+ sdk: 'prices.list',
373
+ expandable: 'price',
374
+ }),
375
+ defineRoute({
376
+ operationId: 'retrievePrice',
377
+ method: 'get',
378
+ path: '/v1/prices/{id}',
379
+ tag: 'Prices',
380
+ summary: 'Retrieve a price',
381
+ auth: 'service',
382
+ scope: 'payments:read',
383
+ params: { id: 'The price (`price_…`).' },
384
+ query: expandOnlyQuery,
385
+ response: priceSchema,
386
+ sdk: 'prices.retrieve',
387
+ expandable: 'price',
388
+ }),
389
+ defineRoute({
390
+ operationId: 'updatePrice',
391
+ method: 'post',
392
+ path: '/v1/prices/{id}',
393
+ tag: 'Prices',
394
+ summary: 'Update a price',
395
+ description: 'Only `active`, `nickname`, `metadata`, `lookup_key` and — while it is `unspecified` — `tax_behavior` change. To change an amount, create a new price and archive this one.',
396
+ auth: 'service',
397
+ scope: 'payments:write',
398
+ idempotent: true,
399
+ params: { id: 'The price (`price_…`).' },
400
+ body: updatePriceParams,
401
+ response: priceSchema,
402
+ sdk: 'prices.update',
403
+ expandable: 'price',
404
+ }),
405
+ defineRoute({
406
+ operationId: 'searchPrices',
407
+ method: 'get',
408
+ path: '/v1/prices/search',
409
+ tag: 'Prices',
410
+ summary: 'Search prices',
411
+ description: "Stripe's query language over `active`, `currency`, `product`, `type`, `lookup_key`, `created` and `metadata['key']`.",
412
+ auth: 'service',
413
+ scope: 'payments:read',
414
+ query: searchQuery,
415
+ response: searchResultOf(priceSchema),
416
+ sdk: 'prices.search',
417
+ expandable: 'price',
418
+ }),
419
+ ];