@owlmeans/payment 0.1.18-rc.8 → 0.1.18

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 (364) hide show
  1. package/README.md +95 -57
  2. package/agent-meta/manifest.json +10 -3
  3. package/agent-meta/skills/entitlements/SKILL.md +159 -0
  4. package/agent-meta/skills/payment/SKILL.md +491 -28
  5. package/build/advertise.d.ts +2 -0
  6. package/build/advertise.d.ts.map +1 -0
  7. package/build/advertise.js +10 -0
  8. package/build/advertise.js.map +1 -0
  9. package/build/checkout/consts.d.ts +2 -0
  10. package/build/checkout/consts.d.ts.map +1 -0
  11. package/build/checkout/consts.js +2 -0
  12. package/build/checkout/consts.js.map +1 -0
  13. package/build/checkout/index.d.ts +6 -0
  14. package/build/checkout/index.d.ts.map +1 -0
  15. package/build/checkout/index.js +4 -0
  16. package/build/checkout/index.js.map +1 -0
  17. package/build/checkout/narrow/types.d.ts +25 -0
  18. package/build/checkout/narrow/types.d.ts.map +1 -0
  19. package/build/checkout/narrow/types.js +2 -0
  20. package/build/checkout/narrow/types.js.map +1 -0
  21. package/build/checkout/narrow.d.ts +8 -0
  22. package/build/checkout/narrow.d.ts.map +1 -0
  23. package/build/checkout/narrow.js +47 -0
  24. package/build/checkout/narrow.js.map +1 -0
  25. package/build/checkout/protocols.d.ts +8 -0
  26. package/build/checkout/protocols.d.ts.map +1 -0
  27. package/build/checkout/protocols.js +28 -0
  28. package/build/checkout/protocols.js.map +1 -0
  29. package/build/checkout/types.d.ts +29 -0
  30. package/build/checkout/types.d.ts.map +1 -0
  31. package/build/checkout/types.js +2 -0
  32. package/build/checkout/types.js.map +1 -0
  33. package/build/consts.d.ts +242 -25
  34. package/build/consts.d.ts.map +1 -1
  35. package/build/consts.js +377 -24
  36. package/build/consts.js.map +1 -1
  37. package/build/consts.local.d.ts +20 -0
  38. package/build/consts.local.d.ts.map +1 -0
  39. package/build/consts.local.js +23 -0
  40. package/build/consts.local.js.map +1 -0
  41. package/build/consumer/cancel.d.ts +11 -0
  42. package/build/consumer/cancel.d.ts.map +1 -0
  43. package/build/consumer/cancel.js +33 -0
  44. package/build/consumer/cancel.js.map +1 -0
  45. package/build/consumer/consts.d.ts +20 -0
  46. package/build/consumer/consts.d.ts.map +1 -0
  47. package/build/consumer/consts.js +39 -0
  48. package/build/consumer/consts.js.map +1 -0
  49. package/build/consumer/consts.local.d.ts +7 -0
  50. package/build/consumer/consts.local.d.ts.map +1 -0
  51. package/build/consumer/consts.local.js +13 -0
  52. package/build/consumer/consts.local.js.map +1 -0
  53. package/build/consumer/copy/types.d.ts +56 -0
  54. package/build/consumer/copy/types.d.ts.map +1 -0
  55. package/build/consumer/copy/types.js +2 -0
  56. package/build/consumer/copy/types.js.map +1 -0
  57. package/build/consumer/copy.d.ts +22 -0
  58. package/build/consumer/copy.d.ts.map +1 -0
  59. package/build/consumer/copy.js +87 -0
  60. package/build/consumer/copy.js.map +1 -0
  61. package/build/consumer/deadline/types.d.ts +30 -0
  62. package/build/consumer/deadline/types.d.ts.map +1 -0
  63. package/build/consumer/deadline/types.js +2 -0
  64. package/build/consumer/deadline/types.js.map +1 -0
  65. package/build/consumer/deadline.d.ts +12 -0
  66. package/build/consumer/deadline.d.ts.map +1 -0
  67. package/build/consumer/deadline.js +44 -0
  68. package/build/consumer/deadline.js.map +1 -0
  69. package/build/consumer/fifo/types.d.ts +17 -0
  70. package/build/consumer/fifo/types.d.ts.map +1 -0
  71. package/build/consumer/fifo/types.js +2 -0
  72. package/build/consumer/fifo/types.js.map +1 -0
  73. package/build/consumer/fifo.d.ts +4 -0
  74. package/build/consumer/fifo.d.ts.map +1 -0
  75. package/build/consumer/fifo.js +34 -0
  76. package/build/consumer/fifo.js.map +1 -0
  77. package/build/consumer/index.d.ts +18 -0
  78. package/build/consumer/index.d.ts.map +1 -0
  79. package/build/consumer/index.js +11 -0
  80. package/build/consumer/index.js.map +1 -0
  81. package/build/consumer/policy/types.d.ts +20 -0
  82. package/build/consumer/policy/types.d.ts.map +1 -0
  83. package/build/consumer/policy/types.js +2 -0
  84. package/build/consumer/policy/types.js.map +1 -0
  85. package/build/consumer/policy.d.ts +17 -0
  86. package/build/consumer/policy.d.ts.map +1 -0
  87. package/build/consumer/policy.js +91 -0
  88. package/build/consumer/policy.js.map +1 -0
  89. package/build/consumer/protocols.d.ts +20 -0
  90. package/build/consumer/protocols.d.ts.map +1 -0
  91. package/build/consumer/protocols.js +70 -0
  92. package/build/consumer/protocols.js.map +1 -0
  93. package/build/consumer/refund/types.d.ts +27 -0
  94. package/build/consumer/refund/types.d.ts.map +1 -0
  95. package/build/consumer/refund/types.js +2 -0
  96. package/build/consumer/refund/types.js.map +1 -0
  97. package/build/consumer/refund.d.ts +9 -0
  98. package/build/consumer/refund.d.ts.map +1 -0
  99. package/build/consumer/refund.js +112 -0
  100. package/build/consumer/refund.js.map +1 -0
  101. package/build/consumer/refusal.d.ts +10 -0
  102. package/build/consumer/refusal.d.ts.map +1 -0
  103. package/build/consumer/refusal.js +35 -0
  104. package/build/consumer/refusal.js.map +1 -0
  105. package/build/consumer/revive/types.d.ts +19 -0
  106. package/build/consumer/revive/types.d.ts.map +1 -0
  107. package/build/consumer/revive/types.js +2 -0
  108. package/build/consumer/revive/types.js.map +1 -0
  109. package/build/consumer/revive.d.ts +13 -0
  110. package/build/consumer/revive.d.ts.map +1 -0
  111. package/build/consumer/revive.js +43 -0
  112. package/build/consumer/revive.js.map +1 -0
  113. package/build/consumer/types.d.ts +196 -0
  114. package/build/consumer/types.d.ts.map +1 -0
  115. package/build/consumer/types.js +2 -0
  116. package/build/consumer/types.js.map +1 -0
  117. package/build/consumer/types.local.d.ts +11 -0
  118. package/build/consumer/types.local.d.ts.map +1 -0
  119. package/build/consumer/types.local.js +2 -0
  120. package/build/consumer/types.local.js.map +1 -0
  121. package/build/countries.d.ts +3 -0
  122. package/build/countries.d.ts.map +1 -0
  123. package/build/countries.js +4 -0
  124. package/build/countries.js.map +1 -0
  125. package/build/entitled.d.ts +14 -0
  126. package/build/entitled.d.ts.map +1 -0
  127. package/build/entitled.js +17 -0
  128. package/build/entitled.js.map +1 -0
  129. package/build/entitlement/types.d.ts +29 -0
  130. package/build/entitlement/types.d.ts.map +1 -0
  131. package/build/entitlement/types.js +2 -0
  132. package/build/entitlement/types.js.map +1 -0
  133. package/build/entitlement.d.ts +12 -0
  134. package/build/entitlement.d.ts.map +1 -0
  135. package/build/entitlement.js +64 -0
  136. package/build/entitlement.js.map +1 -0
  137. package/build/errors.d.ts +189 -0
  138. package/build/errors.d.ts.map +1 -1
  139. package/build/errors.js +361 -0
  140. package/build/errors.js.map +1 -1
  141. package/build/estimate/types.d.ts +34 -0
  142. package/build/estimate/types.d.ts.map +1 -0
  143. package/build/estimate/types.js +2 -0
  144. package/build/estimate/types.js.map +1 -0
  145. package/build/estimate.d.ts +11 -0
  146. package/build/estimate.d.ts.map +1 -0
  147. package/build/estimate.js +76 -0
  148. package/build/estimate.js.map +1 -0
  149. package/build/i18n/consumer-rights/be.json +131 -0
  150. package/build/i18n/consumer-rights/de.json +131 -0
  151. package/build/i18n/consumer-rights/en.json +131 -0
  152. package/build/i18n/consumer-rights/es.json +131 -0
  153. package/build/i18n/consumer-rights/fr.json +131 -0
  154. package/build/i18n/consumer-rights/pl.json +131 -0
  155. package/build/i18n/consumer-rights/ru.json +131 -0
  156. package/build/i18n/consumer-rights/uk.json +131 -0
  157. package/build/i18n/errors/be.json +30 -0
  158. package/build/i18n/errors/de.json +30 -0
  159. package/build/i18n/errors/en.json +30 -0
  160. package/build/i18n/errors/es.json +30 -0
  161. package/build/i18n/errors/fr.json +30 -0
  162. package/build/i18n/errors/pl.json +30 -0
  163. package/build/i18n/errors/ru.json +30 -0
  164. package/build/i18n/errors/uk.json +30 -0
  165. package/build/i18n/fr.json +39 -0
  166. package/build/i18n.js +53 -8
  167. package/build/i18n.js.map +1 -1
  168. package/build/index.d.ts +19 -1
  169. package/build/index.d.ts.map +1 -1
  170. package/build/index.js +12 -1
  171. package/build/index.js.map +1 -1
  172. package/build/limit/types.d.ts +44 -0
  173. package/build/limit/types.d.ts.map +1 -0
  174. package/build/limit/types.js +2 -0
  175. package/build/limit/types.js.map +1 -0
  176. package/build/limit.d.ts +23 -0
  177. package/build/limit.d.ts.map +1 -0
  178. package/build/limit.js +97 -0
  179. package/build/limit.js.map +1 -0
  180. package/build/model/checkout.d.ts +2 -3
  181. package/build/model/checkout.d.ts.map +1 -1
  182. package/build/model/checkout.js +12 -7
  183. package/build/model/checkout.js.map +1 -1
  184. package/build/model/consts.d.ts +15 -0
  185. package/build/model/consts.d.ts.map +1 -0
  186. package/build/model/consts.js +193 -0
  187. package/build/model/consts.js.map +1 -0
  188. package/build/model/consts.local.d.ts +35 -0
  189. package/build/model/consts.local.d.ts.map +1 -0
  190. package/build/model/consts.local.js +65 -0
  191. package/build/model/consts.local.js.map +1 -0
  192. package/build/model/consumer.d.ts +23 -0
  193. package/build/model/consumer.d.ts.map +1 -0
  194. package/build/model/consumer.js +272 -0
  195. package/build/model/consumer.js.map +1 -0
  196. package/build/model/estimate.d.ts +5 -0
  197. package/build/model/estimate.d.ts.map +1 -0
  198. package/build/model/estimate.js +69 -0
  199. package/build/model/estimate.js.map +1 -0
  200. package/build/model/index.d.ts +7 -2
  201. package/build/model/index.d.ts.map +1 -1
  202. package/build/model/index.js +7 -2
  203. package/build/model/index.js.map +1 -1
  204. package/build/model/limit.d.ts +7 -0
  205. package/build/model/limit.d.ts.map +1 -0
  206. package/build/model/limit.js +32 -0
  207. package/build/model/limit.js.map +1 -0
  208. package/build/model/plan.d.ts.map +1 -1
  209. package/build/model/plan.js +24 -11
  210. package/build/model/plan.js.map +1 -1
  211. package/build/model/portal.d.ts +4 -0
  212. package/build/model/portal.d.ts.map +1 -0
  213. package/build/model/portal.js +22 -0
  214. package/build/model/portal.js.map +1 -0
  215. package/build/model/pricing.d.ts +4 -0
  216. package/build/model/pricing.d.ts.map +1 -0
  217. package/build/model/pricing.js +31 -0
  218. package/build/model/pricing.js.map +1 -0
  219. package/build/model/view.d.ts +3 -0
  220. package/build/model/view.d.ts.map +1 -0
  221. package/build/model/view.js +15 -0
  222. package/build/model/view.js.map +1 -0
  223. package/build/pricing/types.d.ts +13 -0
  224. package/build/pricing/types.d.ts.map +1 -0
  225. package/build/pricing/types.js +2 -0
  226. package/build/pricing/types.js.map +1 -0
  227. package/build/pricing.d.ts +13 -0
  228. package/build/pricing.d.ts.map +1 -0
  229. package/build/pricing.js +74 -0
  230. package/build/pricing.js.map +1 -0
  231. package/build/promo/types.d.ts +14 -0
  232. package/build/promo/types.d.ts.map +1 -0
  233. package/build/promo/types.js +2 -0
  234. package/build/promo/types.js.map +1 -0
  235. package/build/promo.d.ts +7 -0
  236. package/build/promo.d.ts.map +1 -0
  237. package/build/promo.js +25 -0
  238. package/build/promo.js.map +1 -0
  239. package/build/regions/types.d.ts +32 -0
  240. package/build/regions/types.d.ts.map +1 -0
  241. package/build/regions/types.js +2 -0
  242. package/build/regions/types.js.map +1 -0
  243. package/build/regions.d.ts +15 -0
  244. package/build/regions.d.ts.map +1 -0
  245. package/build/regions.js +43 -0
  246. package/build/regions.js.map +1 -0
  247. package/build/service.d.ts.map +1 -1
  248. package/build/service.js +24 -9
  249. package/build/service.js.map +1 -1
  250. package/build/types.d.ts +619 -52
  251. package/build/types.d.ts.map +1 -1
  252. package/build/types.local.d.ts +4 -0
  253. package/build/types.local.d.ts.map +1 -0
  254. package/build/types.local.js +2 -0
  255. package/build/types.local.js.map +1 -0
  256. package/build/view/types.d.ts +33 -0
  257. package/build/view/types.d.ts.map +1 -0
  258. package/build/view/types.js +2 -0
  259. package/build/view/types.js.map +1 -0
  260. package/build/view.d.ts +13 -0
  261. package/build/view.d.ts.map +1 -0
  262. package/build/view.js +78 -0
  263. package/build/view.js.map +1 -0
  264. package/package.json +14 -12
  265. package/src/advertise.ts +13 -0
  266. package/src/checkout/consts.ts +1 -0
  267. package/src/checkout/index.ts +5 -0
  268. package/src/checkout/narrow/types.ts +27 -0
  269. package/src/checkout/narrow.ts +63 -0
  270. package/src/checkout/protocols.ts +39 -0
  271. package/src/checkout/types.ts +27 -0
  272. package/src/consts.local.ts +34 -0
  273. package/src/consts.ts +417 -24
  274. package/src/consumer/cancel.ts +40 -0
  275. package/src/consumer/consts.local.ts +16 -0
  276. package/src/consumer/consts.ts +46 -0
  277. package/src/consumer/copy/types.ts +54 -0
  278. package/src/consumer/copy.ts +121 -0
  279. package/src/consumer/deadline/types.ts +30 -0
  280. package/src/consumer/deadline.ts +61 -0
  281. package/src/consumer/fifo/types.ts +17 -0
  282. package/src/consumer/fifo.ts +42 -0
  283. package/src/consumer/index.ts +17 -0
  284. package/src/consumer/policy/types.ts +20 -0
  285. package/src/consumer/policy.ts +101 -0
  286. package/src/consumer/protocols.ts +116 -0
  287. package/src/consumer/refund/types.ts +27 -0
  288. package/src/consumer/refund.ts +136 -0
  289. package/src/consumer/refusal.ts +35 -0
  290. package/src/consumer/revive/types.ts +23 -0
  291. package/src/consumer/revive.ts +82 -0
  292. package/src/consumer/types.local.ts +10 -0
  293. package/src/consumer/types.ts +189 -0
  294. package/src/countries.ts +5 -0
  295. package/src/entitled.ts +20 -0
  296. package/src/entitlement/types.ts +29 -0
  297. package/src/entitlement.ts +86 -0
  298. package/src/errors.ts +445 -0
  299. package/src/estimate/types.ts +34 -0
  300. package/src/estimate.ts +90 -0
  301. package/src/i18n/consumer-rights/be.json +131 -0
  302. package/src/i18n/consumer-rights/de.json +131 -0
  303. package/src/i18n/consumer-rights/en.json +131 -0
  304. package/src/i18n/consumer-rights/es.json +131 -0
  305. package/src/i18n/consumer-rights/fr.json +131 -0
  306. package/src/i18n/consumer-rights/pl.json +131 -0
  307. package/src/i18n/consumer-rights/ru.json +131 -0
  308. package/src/i18n/consumer-rights/uk.json +131 -0
  309. package/src/i18n/errors/be.json +30 -0
  310. package/src/i18n/errors/de.json +30 -0
  311. package/src/i18n/errors/en.json +30 -0
  312. package/src/i18n/errors/es.json +30 -0
  313. package/src/i18n/errors/fr.json +30 -0
  314. package/src/i18n/errors/pl.json +30 -0
  315. package/src/i18n/errors/ru.json +30 -0
  316. package/src/i18n/errors/uk.json +30 -0
  317. package/src/i18n/fr.json +39 -0
  318. package/src/i18n.ts +58 -8
  319. package/src/index.ts +19 -2
  320. package/src/limit/types.ts +41 -0
  321. package/src/limit.ts +132 -0
  322. package/src/model/checkout.ts +12 -7
  323. package/src/model/consts.local.ts +83 -0
  324. package/src/model/consts.ts +206 -0
  325. package/src/model/consumer.ts +294 -0
  326. package/src/model/estimate.ts +73 -0
  327. package/src/model/index.ts +7 -2
  328. package/src/model/limit.ts +36 -0
  329. package/src/model/plan.ts +25 -12
  330. package/src/model/portal.ts +25 -0
  331. package/src/model/pricing.ts +34 -0
  332. package/src/model/view.ts +17 -0
  333. package/src/pricing/types.ts +13 -0
  334. package/src/pricing.ts +110 -0
  335. package/src/promo/types.ts +18 -0
  336. package/src/promo.ts +46 -0
  337. package/src/regions/types.ts +42 -0
  338. package/src/regions.ts +85 -0
  339. package/src/service.ts +32 -15
  340. package/src/types.local.ts +5 -0
  341. package/src/types.ts +669 -49
  342. package/src/view/types.ts +39 -0
  343. package/src/view.ts +119 -0
  344. package/tests/checkout-narrow.spec.ts +75 -0
  345. package/tests/consumer-copy.spec.ts +378 -0
  346. package/tests/consumer-deadline.spec.ts +85 -0
  347. package/tests/consumer-fifo.spec.ts +61 -0
  348. package/tests/consumer-protocols.spec.ts +103 -0
  349. package/tests/consumer-refund.spec.ts +134 -0
  350. package/tests/consumer-regions.spec.ts +140 -0
  351. package/tests/consumer-wire.spec.ts +170 -0
  352. package/tests/contract.spec.ts +183 -0
  353. package/tests/entitlement.spec.ts +103 -0
  354. package/tests/errors.spec.ts +168 -0
  355. package/tests/estimate.spec.ts +139 -0
  356. package/tests/limit.spec.ts +117 -0
  357. package/tests/pricing.spec.ts +30 -0
  358. package/tests/tsconfig.json +11 -0
  359. package/tests/view.spec.ts +130 -0
  360. package/tsconfig.json +6 -1
  361. package/build/.gitkeep +0 -0
  362. package/src/model/subscription.ts +0 -63
  363. package/src/model/utils.ts +0 -32
  364. package/src/modules.ts +0 -43
@@ -0,0 +1,294 @@
1
+ import type { JSONSchemaType } from 'ajv'
2
+ import { IdValueSchema, ResourceValueSchema } from '@owlmeans/auth'
3
+ import { schema } from '@owlmeans/entrypoint'
4
+ import { CancellationKindSchema, CancellationStatusSchema, WithdrawalStatusSchema, CountrySchema } from '../consts.js'
5
+ import { AmountCheckoutPolicySchema } from './pricing.js'
6
+ import type { AmountPolicyQuery, AmountPolicyView, BillingProfileView, CancellationBody, CancellationReceipt, ConsumerRightsPolicy, ConsumerRightsPublicView, DeclarationReceipt, PerformanceConsentBody, PerformanceConsentResponse, PerformanceConsentView, PlanPriceList, PlanPricesQuery, PurchaseList, SubscriptionStartBody, SubscriptionStartQuery, SubscriptionStartResponse, SubscriptionStartView, WithdrawalBody, WithdrawalCandidateList, WithdrawalReceipt } from '../types.js'
7
+ import { AcknowledgedSchema, ConsentContextSchema, CurrencySchema, declarationReceiptProperties, EmailSchema, HoneypotSchema, IsoDateSchema, KeySchema, LanguageSchema, MinorSchema, NameSchema, VersionSchema } from './consts.local.js'
8
+ import { CheckoutLimitViewSchema, ConsumerRightsLinksSchema, ConsumerRightsMechanismsSchema, PlanPriceViewSchema, PurchaseViewSchema, WithdrawalCandidateSchema } from './consts.js'
9
+ import { NullableRegionSchema } from './consts.local.js'
10
+
11
+ export const ConsumerRightsPolicySchema = schema<ConsumerRightsPolicy>({
12
+ type: 'object',
13
+ properties: {
14
+ textVersion: VersionSchema,
15
+ countries: { type: 'array', items: CountrySchema },
16
+ unknownCountry: { type: 'string', enum: ['protect', 'ignore'] },
17
+ withdrawalDays: { type: 'number', minimum: 14, multipleOf: 1 },
18
+ deadline: {
19
+ type: 'object',
20
+ properties: {
21
+ weekendRollover: { type: 'boolean' },
22
+ marginDays: { type: 'number', minimum: 0, maximum: 7, multipleOf: 1 },
23
+ },
24
+ required: ['weekendRollover', 'marginDays'],
25
+ additionalProperties: false,
26
+ },
27
+ mechanisms: ConsumerRightsMechanismsSchema,
28
+ currencies: {
29
+ type: 'object',
30
+ properties: {
31
+ eu: { ...CurrencySchema, nullable: true },
32
+ other: { ...CurrencySchema, nullable: true },
33
+ },
34
+ required: [],
35
+ additionalProperties: false,
36
+ nullable: true,
37
+ },
38
+ languages: { type: 'object', required: [], additionalProperties: LanguageSchema, nullable: true },
39
+ defaultLanguage: LanguageSchema,
40
+ links: { type: 'object', required: [], additionalProperties: ConsumerRightsLinksSchema },
41
+ renewalOpensWindow: { type: 'boolean', nullable: true },
42
+ startRequestTtlSeconds: { type: 'number', minimum: 1, multipleOf: 1, nullable: true },
43
+ exemptBusinesses: { type: 'boolean', nullable: true },
44
+ consentContext: { ...ConsentContextSchema, nullable: true },
45
+ },
46
+ required: [
47
+ 'textVersion', 'countries', 'unknownCountry', 'withdrawalDays', 'deadline', 'mechanisms', 'defaultLanguage',
48
+ 'links',
49
+ ],
50
+ additionalProperties: false,
51
+ } as unknown as JSONSchemaType<ConsumerRightsPolicy>)
52
+
53
+ export const BillingProfileViewSchema = schema<BillingProfileView>({
54
+ type: 'object',
55
+ properties: {
56
+ country: { ...CountrySchema, nullable: true },
57
+ region: NullableRegionSchema,
58
+ currency: { ...CurrencySchema, nullable: true },
59
+ locked: { type: 'boolean' },
60
+ lockedAt: { ...IsoDateSchema, nullable: true },
61
+ language: LanguageSchema,
62
+ inScope: { type: 'boolean' },
63
+ },
64
+ required: ['country', 'region', 'currency', 'locked', 'language', 'inScope'],
65
+ additionalProperties: false,
66
+ } as unknown as JSONSchemaType<BillingProfileView>)
67
+
68
+ export const PurchaseListSchema = schema<PurchaseList>({
69
+ type: 'object',
70
+ properties: { purchases: { type: 'array', items: PurchaseViewSchema } },
71
+ required: ['purchases'],
72
+ additionalProperties: false,
73
+ })
74
+
75
+ export const PerformanceConsentViewSchema = schema<PerformanceConsentView>({
76
+ type: 'object',
77
+ properties: {
78
+ required: { type: 'boolean' },
79
+ region: NullableRegionSchema,
80
+ country: { ...CountrySchema, nullable: true },
81
+ language: LanguageSchema,
82
+ trader: NameSchema,
83
+ context: { ...ConsentContextSchema, nullable: true },
84
+ textVersion: VersionSchema,
85
+ copyVersion: VersionSchema,
86
+ links: ConsumerRightsLinksSchema,
87
+ purchases: { type: 'array', items: PurchaseViewSchema },
88
+ deadline: { ...IsoDateSchema, nullable: true },
89
+ at: IsoDateSchema,
90
+ },
91
+ required: [
92
+ 'required', 'region', 'country', 'language', 'trader', 'textVersion', 'copyVersion', 'links', 'purchases', 'at',
93
+ ],
94
+ additionalProperties: false,
95
+ } as unknown as JSONSchemaType<PerformanceConsentView>)
96
+
97
+ export const PerformanceConsentBodySchema = schema<PerformanceConsentBody>({
98
+ type: 'object',
99
+ properties: {
100
+ purchaseIds: { type: 'array', items: IdValueSchema, maxItems: 100, uniqueItems: true },
101
+ textVersion: VersionSchema,
102
+ language: LanguageSchema,
103
+ acknowledged: AcknowledgedSchema,
104
+ uiLanguage: { ...LanguageSchema, nullable: true },
105
+ },
106
+ required: ['purchaseIds', 'textVersion', 'language', 'acknowledged'],
107
+ additionalProperties: false,
108
+ } as unknown as JSONSchemaType<PerformanceConsentBody>)
109
+
110
+ export const PerformanceConsentResponseSchema = schema<PerformanceConsentResponse>({
111
+ type: 'object',
112
+ properties: {
113
+ consentId: IdValueSchema,
114
+ consentedAt: IsoDateSchema,
115
+ purchaseIds: { type: 'array', items: IdValueSchema },
116
+ mailed: { type: 'boolean' },
117
+ },
118
+ required: ['consentId', 'consentedAt', 'purchaseIds', 'mailed'],
119
+ additionalProperties: false,
120
+ })
121
+
122
+ export const SubscriptionStartQuerySchema = schema<SubscriptionStartQuery>({
123
+ type: 'object',
124
+ properties: { planSku: ResourceValueSchema },
125
+ required: ['planSku'],
126
+ additionalProperties: false,
127
+ })
128
+
129
+ export const SubscriptionStartViewSchema = schema<SubscriptionStartView>({
130
+ type: 'object',
131
+ properties: {
132
+ required: { type: 'boolean' },
133
+ planSku: KeySchema,
134
+ language: LanguageSchema,
135
+ trader: NameSchema,
136
+ context: { ...ConsentContextSchema, nullable: true },
137
+ textVersion: VersionSchema,
138
+ copyVersion: VersionSchema,
139
+ links: ConsumerRightsLinksSchema,
140
+ region: NullableRegionSchema,
141
+ },
142
+ required: ['required', 'planSku', 'language', 'trader', 'textVersion', 'copyVersion', 'links', 'region'],
143
+ additionalProperties: false,
144
+ } as unknown as JSONSchemaType<SubscriptionStartView>)
145
+
146
+ export const SubscriptionStartBodySchema = schema<SubscriptionStartBody>({
147
+ type: 'object',
148
+ properties: {
149
+ planSku: ResourceValueSchema,
150
+ textVersion: VersionSchema,
151
+ language: LanguageSchema,
152
+ acknowledged: AcknowledgedSchema,
153
+ },
154
+ required: ['planSku', 'textVersion', 'language', 'acknowledged'],
155
+ additionalProperties: false,
156
+ } as unknown as JSONSchemaType<SubscriptionStartBody>)
157
+
158
+ export const SubscriptionStartResponseSchema = schema<SubscriptionStartResponse>({
159
+ type: 'object',
160
+ properties: {
161
+ startRequestId: IdValueSchema,
162
+ requestedAt: IsoDateSchema,
163
+ expiresAt: IsoDateSchema,
164
+ },
165
+ required: ['startRequestId', 'requestedAt', 'expiresAt'],
166
+ additionalProperties: false,
167
+ })
168
+
169
+ export const WithdrawalCandidateListSchema = schema<WithdrawalCandidateList>({
170
+ type: 'object',
171
+ properties: {
172
+ candidates: { type: 'array', items: WithdrawalCandidateSchema },
173
+ language: LanguageSchema,
174
+ links: ConsumerRightsLinksSchema,
175
+ name: { ...NameSchema, nullable: true },
176
+ email: { ...EmailSchema, nullable: true },
177
+ },
178
+ required: ['candidates', 'language', 'links'],
179
+ additionalProperties: false,
180
+ })
181
+
182
+ export const WithdrawalBodySchema = schema<WithdrawalBody>({
183
+ type: 'object',
184
+ properties: {
185
+ purchaseId: { ...IdValueSchema, nullable: true },
186
+ contractRef: { ...IdValueSchema, nullable: true },
187
+ name: NameSchema,
188
+ email: EmailSchema,
189
+ language: { ...LanguageSchema, nullable: true },
190
+ honeypot: { ...HoneypotSchema, nullable: true },
191
+ },
192
+ required: ['name', 'email'],
193
+ additionalProperties: false,
194
+ })
195
+
196
+ export const DeclarationReceiptSchema = schema<DeclarationReceipt>({
197
+ type: 'object',
198
+ properties: declarationReceiptProperties,
199
+ required: ['declarationId', 'receivedAt', 'content', 'mailed'],
200
+ additionalProperties: false,
201
+ } as unknown as JSONSchemaType<DeclarationReceipt>)
202
+
203
+ export const WithdrawalReceiptSchema = schema<WithdrawalReceipt>({
204
+ type: 'object',
205
+ properties: {
206
+ ...declarationReceiptProperties,
207
+ status: WithdrawalStatusSchema,
208
+ refundMinor: { ...MinorSchema, nullable: true },
209
+ currency: { ...CurrencySchema, nullable: true },
210
+ subscriptionCanceled: { type: 'boolean', nullable: true },
211
+ },
212
+ required: ['declarationId', 'receivedAt', 'content', 'mailed', 'status'],
213
+ additionalProperties: false,
214
+ } as unknown as JSONSchemaType<WithdrawalReceipt>)
215
+
216
+ export const CancellationBodySchema = schema<CancellationBody>({
217
+ type: 'object',
218
+ properties: {
219
+ kind: CancellationKindSchema,
220
+ reason: { type: 'string', maxLength: 2000, nullable: true },
221
+ name: NameSchema,
222
+ contractRef: { ...IdValueSchema, nullable: true },
223
+ subscriptionId: { ...IdValueSchema, nullable: true },
224
+ effective: { type: 'string', enum: ['earliest', 'date'] },
225
+ date: { type: 'string', pattern: '^\\d{4}-\\d{2}-\\d{2}$', nullable: true },
226
+ email: EmailSchema,
227
+ language: { ...LanguageSchema, nullable: true },
228
+ honeypot: { ...HoneypotSchema, nullable: true },
229
+ },
230
+ required: ['kind', 'name', 'effective', 'email'],
231
+ additionalProperties: false,
232
+ } as unknown as JSONSchemaType<CancellationBody>)
233
+
234
+ export const CancellationReceiptSchema = schema<CancellationReceipt>({
235
+ type: 'object',
236
+ properties: {
237
+ ...declarationReceiptProperties,
238
+ status: CancellationStatusSchema,
239
+ effectiveAt: { ...IsoDateSchema, nullable: true },
240
+ },
241
+ required: ['declarationId', 'receivedAt', 'content', 'mailed', 'status'],
242
+ additionalProperties: false,
243
+ } as unknown as JSONSchemaType<CancellationReceipt>)
244
+
245
+ export const ConsumerRightsPublicViewSchema = schema<ConsumerRightsPublicView>({
246
+ type: 'object',
247
+ properties: {
248
+ mechanisms: {
249
+ type: 'object',
250
+ properties: { withdrawal: { type: 'boolean' }, cancellation: { type: 'boolean' } },
251
+ required: ['withdrawal', 'cancellation'],
252
+ additionalProperties: false,
253
+ },
254
+ languages: { type: 'array', items: LanguageSchema },
255
+ links: { type: 'object', required: [], additionalProperties: ConsumerRightsLinksSchema },
256
+ textVersion: VersionSchema,
257
+ },
258
+ required: ['mechanisms', 'languages', 'links', 'textVersion'],
259
+ additionalProperties: false,
260
+ } as unknown as JSONSchemaType<ConsumerRightsPublicView>)
261
+
262
+ export const AmountPolicyViewSchema = schema<AmountPolicyView>({
263
+ type: 'object',
264
+ properties: {
265
+ policy: AmountCheckoutPolicySchema,
266
+ limit: { ...CheckoutLimitViewSchema, nullable: true },
267
+ },
268
+ required: ['policy', 'limit'],
269
+ additionalProperties: false,
270
+ } as unknown as JSONSchemaType<AmountPolicyView>)
271
+
272
+ export const AmountPolicyQuerySchema = schema<AmountPolicyQuery>({
273
+ type: 'object',
274
+ properties: {
275
+ productSku: ResourceValueSchema,
276
+ planSku: { ...ResourceValueSchema, nullable: true },
277
+ },
278
+ required: ['productSku'],
279
+ additionalProperties: false,
280
+ } as JSONSchemaType<AmountPolicyQuery>)
281
+
282
+ export const PlanPriceListSchema = schema<PlanPriceList>({
283
+ type: 'object',
284
+ properties: { prices: { type: 'array', items: PlanPriceViewSchema } },
285
+ required: ['prices'],
286
+ additionalProperties: false,
287
+ })
288
+
289
+ export const PlanPricesQuerySchema = schema<PlanPricesQuery>({
290
+ type: 'object',
291
+ properties: { productSku: ResourceValueSchema },
292
+ required: ['productSku'],
293
+ additionalProperties: false,
294
+ })
@@ -0,0 +1,73 @@
1
+ import type { JSONSchemaType } from 'ajv'
2
+ import type { PriceEstimate, PriceEstimateBody, PricingPolicy } from '../types.js'
3
+ import { ResourceValueSchema } from '@owlmeans/auth'
4
+ import { schema } from '@owlmeans/entrypoint'
5
+ import { CountrySchema, ConsumerRegionSchema, TaxBehaviorSchema } from '../consts.js'
6
+ import { TaxEstimateSchema } from './consts.local.js'
7
+
8
+ export const PricingPolicySchema = schema<PricingPolicy>({
9
+ type: 'object',
10
+ properties: {
11
+ tax: {
12
+ type: 'object',
13
+ properties: {
14
+ automatic: { type: 'boolean' },
15
+ behavior: { ...TaxBehaviorSchema, nullable: true },
16
+ collectTaxId: { type: 'boolean' },
17
+ estimate: { type: 'boolean' },
18
+ estimateTtlSeconds: { type: 'number', minimum: 1, multipleOf: 1, nullable: true },
19
+ },
20
+ required: ['automatic', 'collectTaxId', 'estimate'],
21
+ additionalProperties: false,
22
+ },
23
+ currency: {
24
+ type: 'object',
25
+ properties: {
26
+ adaptive: { type: 'boolean', nullable: true },
27
+ adaptiveFeeRate: { type: 'number', minimum: 0, maximum: 1, nullable: true },
28
+ estimate: { type: 'boolean' },
29
+ estimateTtlSeconds: { type: 'number', minimum: 1, multipleOf: 1, nullable: true },
30
+ },
31
+ required: ['estimate'],
32
+ additionalProperties: false,
33
+ },
34
+ },
35
+ required: ['tax', 'currency'],
36
+ additionalProperties: false,
37
+ } as JSONSchemaType<PricingPolicy>)
38
+
39
+ export const PriceEstimateBodySchema = schema<PriceEstimateBody>({
40
+ type: 'object',
41
+ properties: {
42
+ planSku: { ...ResourceValueSchema, nullable: true },
43
+ country: { ...CountrySchema, nullable: true },
44
+ },
45
+ required: [],
46
+ additionalProperties: false,
47
+ } as JSONSchemaType<PriceEstimateBody>)
48
+
49
+ export const PriceEstimateSchema = schema<PriceEstimate>({
50
+ type: 'object',
51
+ properties: {
52
+ country: { ...CountrySchema, nullable: true },
53
+ source: { type: 'string', enum: ['request', 'customer', 'profile'], nullable: true },
54
+ locked: { type: 'boolean', nullable: true },
55
+ region: { ...ConsumerRegionSchema, nullable: true },
56
+ currency: { type: 'string', minLength: 3, maxLength: 3 },
57
+ behavior: TaxBehaviorSchema,
58
+ tax: TaxEstimateSchema,
59
+ local: {
60
+ type: 'object',
61
+ properties: {
62
+ currency: { type: 'string', minLength: 3, maxLength: 3 },
63
+ exchangeRate: { type: 'number', exclusiveMinimum: 0 },
64
+ fxFeeRate: { type: 'number', minimum: 0, nullable: true },
65
+ },
66
+ required: ['currency', 'exchangeRate'],
67
+ additionalProperties: false,
68
+ nullable: true,
69
+ },
70
+ },
71
+ required: ['currency', 'behavior', 'tax'],
72
+ additionalProperties: false,
73
+ } as JSONSchemaType<PriceEstimate>)
@@ -1,7 +1,12 @@
1
1
 
2
2
  export * from './product.js'
3
3
  export * from './localization.js'
4
- export * from './subscription.js'
5
4
  export * from './plan.js'
6
- export * from './utils.js'
7
5
  export * from './checkout.js'
6
+ export * from './pricing.js'
7
+ export * from './limit.js'
8
+ export * from './view.js'
9
+ export * from './consts.js'
10
+ export * from './portal.js'
11
+ export * from './estimate.js'
12
+ export * from './consumer.js'
@@ -0,0 +1,36 @@
1
+ import type { JSONSchemaType } from 'ajv'
2
+ import type { LimitDeclaration, PlanCapability, PromoDeclaration } from '../types.js'
3
+ import { DateSchema, PermissionSetSchema } from '@owlmeans/auth'
4
+ import { LimitKindSchema, LimitWindowSchema } from '../consts.js'
5
+
6
+ /** A promo on a plan declaration. Dates follow the record convention (`DateSchema`). */
7
+ export const PromoDeclarationSchema: JSONSchemaType<PromoDeclaration> = {
8
+ type: 'object',
9
+ properties: {
10
+ until: DateSchema,
11
+ grandfather: { type: 'boolean', nullable: true },
12
+ },
13
+ required: ['until'],
14
+ additionalProperties: false,
15
+ }
16
+
17
+ export const LimitDeclarationSchema: JSONSchemaType<LimitDeclaration> = {
18
+ type: 'object',
19
+ properties: {
20
+ kind: LimitKindSchema,
21
+ limit: { type: 'number', minimum: 0 },
22
+ window: { ...LimitWindowSchema, nullable: true },
23
+ unit: { type: 'string', minLength: 1, maxLength: 16, nullable: true },
24
+ promo: { ...PromoDeclarationSchema, nullable: true },
25
+ },
26
+ required: ['kind', 'limit'],
27
+ additionalProperties: false,
28
+ } as JSONSchemaType<LimitDeclaration>
29
+
30
+ export const PlanCapabilitySchema: JSONSchemaType<PlanCapability> = {
31
+ ...PermissionSetSchema,
32
+ properties: {
33
+ ...PermissionSetSchema.properties,
34
+ promo: { ...PromoDeclarationSchema, nullable: true },
35
+ },
36
+ } as JSONSchemaType<PlanCapability>
package/src/model/plan.ts CHANGED
@@ -1,22 +1,23 @@
1
1
  import type { JSONSchemaType } from 'ajv'
2
2
  import type { ProductPlan } from '../types.js'
3
- import { ResourceValueSchema, PermissionSetSchema, DateSchema } from '@owlmeans/auth'
3
+ import { ResourceValueSchema, DateSchema, IdValueSchema } from '@owlmeans/auth'
4
4
  import {
5
- PlanDurationSchema, ProductDescriptionSchema, ProductTitleSchema,
6
- SubscriptionStatusSchema
5
+ CheckoutPricingModeSchema, PlanDurationSchema, PlanStatusSchema, ProductDescriptionSchema,
6
+ ProductTitleSchema
7
7
  } from '../consts.js'
8
- import { LimitConfigSchema } from './utils.js'
8
+ import { LimitDeclarationSchema, PlanCapabilitySchema } from './limit.js'
9
+ import { AmountCheckoutPolicySchema, QuantityCheckoutPolicySchema } from './pricing.js'
10
+ import { PlanWithdrawalComponentSchema } from './consts.js'
9
11
 
10
12
  export const ProductPlanSchema: JSONSchemaType<ProductPlan> = {
11
13
  type: 'object',
12
14
  properties: {
13
15
  productSku: ResourceValueSchema,
14
16
  sku: ResourceValueSchema,
15
- status: SubscriptionStatusSchema,
16
- payagateAliases: {
17
- type: 'object', required: [], nullable: true,
18
- additionalProperties: { type: 'string' },
19
- },
17
+ status: PlanStatusSchema,
18
+ rank: { type: 'number', minimum: 0, multipleOf: 1, nullable: true },
19
+ free: { type: 'boolean', nullable: true },
20
+ gateways: { type: 'array', items: IdValueSchema, nullable: true },
20
21
  duration: PlanDurationSchema,
21
22
  trial: { type: 'number', nullable: true },
22
23
  gatedTrial: { type: 'boolean', nullable: true },
@@ -35,12 +36,24 @@ export const ProductPlanSchema: JSONSchemaType<ProductPlan> = {
35
36
  createdAt: { ...DateSchema, nullable: true },
36
37
  archivedAt: { ...DateSchema, nullable: true },
37
38
  deprecatedAt: { ...DateSchema, nullable: true },
38
- supsendedAt: { ...DateSchema, nullable: true },
39
+ suspendedAt: { ...DateSchema, nullable: true },
39
40
 
40
- capabilities: { type: 'array', items: PermissionSetSchema, nullable: true },
41
+ capabilities: { type: 'array', items: PlanCapabilitySchema, nullable: true },
41
42
  limits: {
42
43
  type: 'object', required: [], nullable: true,
43
- additionalProperties: LimitConfigSchema
44
+ additionalProperties: LimitDeclarationSchema
45
+ },
46
+ pricingMode: { ...CheckoutPricingModeSchema, nullable: true },
47
+ amountPolicy: { ...AmountCheckoutPolicySchema, nullable: true },
48
+ quantityPolicy: { ...QuantityCheckoutPolicySchema, nullable: true },
49
+ withdrawal: {
50
+ type: 'object',
51
+ properties: {
52
+ components: { type: 'array', items: PlanWithdrawalComponentSchema, minItems: 1 },
53
+ },
54
+ required: ['components'],
55
+ additionalProperties: false,
56
+ nullable: true,
44
57
  },
45
58
  },
46
59
  required: [
@@ -0,0 +1,25 @@
1
+ import type { JSONSchemaType } from 'ajv'
2
+ import type { PortalLinkBody, PortalLinkResponse } from '../types.js'
3
+ import { ResourceValueSchema } from '@owlmeans/auth'
4
+ import { schema } from '@owlmeans/entrypoint'
5
+ import { PortalFlowSchema } from '../consts.js'
6
+
7
+ export const PortalLinkBodySchema = schema<PortalLinkBody>({
8
+ type: 'object',
9
+ properties: {
10
+ flow: PortalFlowSchema,
11
+ planSku: { ...ResourceValueSchema, nullable: true },
12
+ returnUrl: { type: 'string', minLength: 1, maxLength: 2048, nullable: true },
13
+ },
14
+ required: ['flow'],
15
+ additionalProperties: false,
16
+ } as JSONSchemaType<PortalLinkBody>)
17
+
18
+ export const PortalLinkResponseSchema = schema<PortalLinkResponse>({
19
+ type: 'object',
20
+ properties: {
21
+ url: { type: 'string', minLength: 1 },
22
+ },
23
+ required: ['url'],
24
+ additionalProperties: false,
25
+ } as JSONSchemaType<PortalLinkResponse>)
@@ -0,0 +1,34 @@
1
+ import type { JSONSchemaType } from 'ajv'
2
+ import { schema } from '@owlmeans/entrypoint'
3
+ import type { AmountCheckoutPolicy, QuantityCheckoutPolicy } from '../types.js'
4
+
5
+ export const AmountCheckoutPolicySchema = schema<AmountCheckoutPolicy>({
6
+ type: 'object',
7
+ properties: {
8
+ currency: { type: 'string', minLength: 3, maxLength: 3 },
9
+ minimumMinor: { type: 'number', minimum: 0, multipleOf: 1 },
10
+ maximumMinor: { type: 'number', minimum: 0, multipleOf: 1 },
11
+ defaultMinor: { type: 'number', minimum: 0, multipleOf: 1 },
12
+ presetsMinor: {
13
+ type: 'array', items: { type: 'number', minimum: 0, multipleOf: 1 }, uniqueItems: true,
14
+ },
15
+ fixedMinor: { type: 'number', minimum: 0, multipleOf: 1 },
16
+ rateBps: { type: 'number', minimum: 0, maximum: 9999, multipleOf: 1 },
17
+ },
18
+ required: [
19
+ 'currency', 'minimumMinor', 'maximumMinor', 'defaultMinor', 'presetsMinor',
20
+ 'fixedMinor', 'rateBps',
21
+ ],
22
+ additionalProperties: false,
23
+ } as JSONSchemaType<AmountCheckoutPolicy>)
24
+
25
+ export const QuantityCheckoutPolicySchema = schema<QuantityCheckoutPolicy>({
26
+ type: 'object',
27
+ properties: {
28
+ minimum: { type: 'number', minimum: 1, multipleOf: 1 },
29
+ maximum: { type: 'number', minimum: 1, multipleOf: 1 },
30
+ default: { type: 'number', minimum: 1, multipleOf: 1 },
31
+ },
32
+ required: ['minimum', 'maximum', 'default'],
33
+ additionalProperties: false,
34
+ } as JSONSchemaType<QuantityCheckoutPolicy>)
@@ -0,0 +1,17 @@
1
+ import type { JSONSchemaType } from 'ajv'
2
+ import type { EntitlementView } from '../types.js'
3
+ import { schema } from '@owlmeans/entrypoint'
4
+ import { IsoDateSchema } from './consts.local.js'
5
+ import { CapabilityViewSchema, EntitlementPlanViewSchema, LimitViewSchema } from './consts.js'
6
+
7
+ export const EntitlementViewSchema = schema<EntitlementView>({
8
+ type: 'object',
9
+ properties: {
10
+ plan: EntitlementPlanViewSchema,
11
+ capabilities: { type: 'array', items: CapabilityViewSchema },
12
+ limits: { type: 'array', items: LimitViewSchema },
13
+ at: IsoDateSchema,
14
+ },
15
+ required: ['plan', 'capabilities', 'limits', 'at'],
16
+ additionalProperties: false,
17
+ } as JSONSchemaType<EntitlementView>)
@@ -0,0 +1,13 @@
1
+ import type { AmountCheckoutPolicy, QuantityCheckoutPolicy } from '../types.js'
2
+
3
+ /** The checkout policies' invariants and the charge an amount grosses up to. */
4
+ export interface CheckoutPricingHelper {
5
+ /** @throws PaymentError (`checkout-policy:amount`, `checkout-policy:presets`) for an invalid policy. */
6
+ assertAmountCheckoutPolicy: (policy: AmountCheckoutPolicy) => AmountCheckoutPolicy
7
+ /** @throws PaymentError (`checkout-policy:quantity`) for an invalid policy. */
8
+ assertQuantityCheckoutPolicy: (policy: QuantityCheckoutPolicy) => QuantityCheckoutPolicy
9
+ /** @throws PaymentError (`checkout-amount:*`) for an amount the policy does not allow. */
10
+ assertCheckoutAmount: (policy: AmountCheckoutPolicy, amountMinor: number) => number
11
+ /** Gross up a net credit value so the configured adjustment remains outside the credit grant. */
12
+ chargeAmountMinor: (amountMinor: number, policy: Pick<AmountCheckoutPolicy, 'fixedMinor' | 'rateBps'>) => number
13
+ }