@owlmeans/payment 0.1.18-rc.9 → 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.
- package/README.md +95 -57
- package/agent-meta/manifest.json +10 -3
- package/agent-meta/skills/entitlements/SKILL.md +159 -0
- package/agent-meta/skills/payment/SKILL.md +491 -28
- package/build/advertise.d.ts +2 -0
- package/build/advertise.d.ts.map +1 -0
- package/build/advertise.js +10 -0
- package/build/advertise.js.map +1 -0
- package/build/checkout/consts.d.ts +2 -0
- package/build/checkout/consts.d.ts.map +1 -0
- package/build/checkout/consts.js +2 -0
- package/build/checkout/consts.js.map +1 -0
- package/build/checkout/index.d.ts +6 -0
- package/build/checkout/index.d.ts.map +1 -0
- package/build/checkout/index.js +4 -0
- package/build/checkout/index.js.map +1 -0
- package/build/checkout/narrow/types.d.ts +25 -0
- package/build/checkout/narrow/types.d.ts.map +1 -0
- package/build/checkout/narrow/types.js +2 -0
- package/build/checkout/narrow/types.js.map +1 -0
- package/build/checkout/narrow.d.ts +8 -0
- package/build/checkout/narrow.d.ts.map +1 -0
- package/build/checkout/narrow.js +47 -0
- package/build/checkout/narrow.js.map +1 -0
- package/build/checkout/protocols.d.ts +8 -0
- package/build/checkout/protocols.d.ts.map +1 -0
- package/build/checkout/protocols.js +28 -0
- package/build/checkout/protocols.js.map +1 -0
- package/build/checkout/types.d.ts +29 -0
- package/build/checkout/types.d.ts.map +1 -0
- package/build/checkout/types.js +2 -0
- package/build/checkout/types.js.map +1 -0
- package/build/consts.d.ts +242 -25
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +377 -24
- package/build/consts.js.map +1 -1
- package/build/consts.local.d.ts +20 -0
- package/build/consts.local.d.ts.map +1 -0
- package/build/consts.local.js +23 -0
- package/build/consts.local.js.map +1 -0
- package/build/consumer/cancel.d.ts +11 -0
- package/build/consumer/cancel.d.ts.map +1 -0
- package/build/consumer/cancel.js +33 -0
- package/build/consumer/cancel.js.map +1 -0
- package/build/consumer/consts.d.ts +20 -0
- package/build/consumer/consts.d.ts.map +1 -0
- package/build/consumer/consts.js +39 -0
- package/build/consumer/consts.js.map +1 -0
- package/build/consumer/consts.local.d.ts +7 -0
- package/build/consumer/consts.local.d.ts.map +1 -0
- package/build/consumer/consts.local.js +13 -0
- package/build/consumer/consts.local.js.map +1 -0
- package/build/consumer/copy/types.d.ts +56 -0
- package/build/consumer/copy/types.d.ts.map +1 -0
- package/build/consumer/copy/types.js +2 -0
- package/build/consumer/copy/types.js.map +1 -0
- package/build/consumer/copy.d.ts +22 -0
- package/build/consumer/copy.d.ts.map +1 -0
- package/build/consumer/copy.js +87 -0
- package/build/consumer/copy.js.map +1 -0
- package/build/consumer/deadline/types.d.ts +30 -0
- package/build/consumer/deadline/types.d.ts.map +1 -0
- package/build/consumer/deadline/types.js +2 -0
- package/build/consumer/deadline/types.js.map +1 -0
- package/build/consumer/deadline.d.ts +12 -0
- package/build/consumer/deadline.d.ts.map +1 -0
- package/build/consumer/deadline.js +44 -0
- package/build/consumer/deadline.js.map +1 -0
- package/build/consumer/fifo/types.d.ts +17 -0
- package/build/consumer/fifo/types.d.ts.map +1 -0
- package/build/consumer/fifo/types.js +2 -0
- package/build/consumer/fifo/types.js.map +1 -0
- package/build/consumer/fifo.d.ts +4 -0
- package/build/consumer/fifo.d.ts.map +1 -0
- package/build/consumer/fifo.js +34 -0
- package/build/consumer/fifo.js.map +1 -0
- package/build/consumer/index.d.ts +18 -0
- package/build/consumer/index.d.ts.map +1 -0
- package/build/consumer/index.js +11 -0
- package/build/consumer/index.js.map +1 -0
- package/build/consumer/policy/types.d.ts +20 -0
- package/build/consumer/policy/types.d.ts.map +1 -0
- package/build/consumer/policy/types.js +2 -0
- package/build/consumer/policy/types.js.map +1 -0
- package/build/consumer/policy.d.ts +17 -0
- package/build/consumer/policy.d.ts.map +1 -0
- package/build/consumer/policy.js +91 -0
- package/build/consumer/policy.js.map +1 -0
- package/build/consumer/protocols.d.ts +20 -0
- package/build/consumer/protocols.d.ts.map +1 -0
- package/build/consumer/protocols.js +70 -0
- package/build/consumer/protocols.js.map +1 -0
- package/build/consumer/refund/types.d.ts +27 -0
- package/build/consumer/refund/types.d.ts.map +1 -0
- package/build/consumer/refund/types.js +2 -0
- package/build/consumer/refund/types.js.map +1 -0
- package/build/consumer/refund.d.ts +9 -0
- package/build/consumer/refund.d.ts.map +1 -0
- package/build/consumer/refund.js +112 -0
- package/build/consumer/refund.js.map +1 -0
- package/build/consumer/refusal.d.ts +10 -0
- package/build/consumer/refusal.d.ts.map +1 -0
- package/build/consumer/refusal.js +35 -0
- package/build/consumer/refusal.js.map +1 -0
- package/build/consumer/revive/types.d.ts +19 -0
- package/build/consumer/revive/types.d.ts.map +1 -0
- package/build/consumer/revive/types.js +2 -0
- package/build/consumer/revive/types.js.map +1 -0
- package/build/consumer/revive.d.ts +13 -0
- package/build/consumer/revive.d.ts.map +1 -0
- package/build/consumer/revive.js +43 -0
- package/build/consumer/revive.js.map +1 -0
- package/build/consumer/types.d.ts +196 -0
- package/build/consumer/types.d.ts.map +1 -0
- package/build/consumer/types.js +2 -0
- package/build/consumer/types.js.map +1 -0
- package/build/consumer/types.local.d.ts +11 -0
- package/build/consumer/types.local.d.ts.map +1 -0
- package/build/consumer/types.local.js +2 -0
- package/build/consumer/types.local.js.map +1 -0
- package/build/countries.d.ts +3 -0
- package/build/countries.d.ts.map +1 -0
- package/build/countries.js +4 -0
- package/build/countries.js.map +1 -0
- package/build/entitled.d.ts +14 -0
- package/build/entitled.d.ts.map +1 -0
- package/build/entitled.js +17 -0
- package/build/entitled.js.map +1 -0
- package/build/entitlement/types.d.ts +29 -0
- package/build/entitlement/types.d.ts.map +1 -0
- package/build/entitlement/types.js +2 -0
- package/build/entitlement/types.js.map +1 -0
- package/build/entitlement.d.ts +7 -55
- package/build/entitlement.d.ts.map +1 -1
- package/build/entitlement.js +55 -86
- package/build/entitlement.js.map +1 -1
- package/build/errors.d.ts +189 -0
- package/build/errors.d.ts.map +1 -1
- package/build/errors.js +361 -0
- package/build/errors.js.map +1 -1
- package/build/estimate/types.d.ts +34 -0
- package/build/estimate/types.d.ts.map +1 -0
- package/build/estimate/types.js +2 -0
- package/build/estimate/types.js.map +1 -0
- package/build/estimate.d.ts +11 -0
- package/build/estimate.d.ts.map +1 -0
- package/build/estimate.js +76 -0
- package/build/estimate.js.map +1 -0
- package/build/i18n/consumer-rights/be.json +131 -0
- package/build/i18n/consumer-rights/de.json +131 -0
- package/build/i18n/consumer-rights/en.json +131 -0
- package/build/i18n/consumer-rights/es.json +131 -0
- package/build/i18n/consumer-rights/fr.json +131 -0
- package/build/i18n/consumer-rights/pl.json +131 -0
- package/build/i18n/consumer-rights/ru.json +131 -0
- package/build/i18n/consumer-rights/uk.json +131 -0
- package/build/i18n/errors/be.json +30 -0
- package/build/i18n/errors/de.json +30 -0
- package/build/i18n/errors/en.json +30 -0
- package/build/i18n/errors/es.json +30 -0
- package/build/i18n/errors/fr.json +30 -0
- package/build/i18n/errors/pl.json +30 -0
- package/build/i18n/errors/ru.json +30 -0
- package/build/i18n/errors/uk.json +30 -0
- package/build/i18n/fr.json +39 -0
- package/build/i18n.js +53 -8
- package/build/i18n.js.map +1 -1
- package/build/index.d.ts +18 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +11 -1
- package/build/index.js.map +1 -1
- package/build/limit/types.d.ts +44 -0
- package/build/limit/types.d.ts.map +1 -0
- package/build/limit/types.js +2 -0
- package/build/limit/types.js.map +1 -0
- package/build/limit.d.ts +23 -0
- package/build/limit.d.ts.map +1 -0
- package/build/limit.js +97 -0
- package/build/limit.js.map +1 -0
- package/build/model/checkout.d.ts +2 -3
- package/build/model/checkout.d.ts.map +1 -1
- package/build/model/checkout.js +12 -7
- package/build/model/checkout.js.map +1 -1
- package/build/model/consts.d.ts +15 -0
- package/build/model/consts.d.ts.map +1 -0
- package/build/model/consts.js +193 -0
- package/build/model/consts.js.map +1 -0
- package/build/model/consts.local.d.ts +35 -0
- package/build/model/consts.local.d.ts.map +1 -0
- package/build/model/consts.local.js +65 -0
- package/build/model/consts.local.js.map +1 -0
- package/build/model/consumer.d.ts +23 -0
- package/build/model/consumer.d.ts.map +1 -0
- package/build/model/consumer.js +272 -0
- package/build/model/consumer.js.map +1 -0
- package/build/model/estimate.d.ts +5 -0
- package/build/model/estimate.d.ts.map +1 -0
- package/build/model/estimate.js +69 -0
- package/build/model/estimate.js.map +1 -0
- package/build/model/index.d.ts +7 -2
- package/build/model/index.d.ts.map +1 -1
- package/build/model/index.js +7 -2
- package/build/model/index.js.map +1 -1
- package/build/model/limit.d.ts +7 -0
- package/build/model/limit.d.ts.map +1 -0
- package/build/model/limit.js +32 -0
- package/build/model/limit.js.map +1 -0
- package/build/model/plan.d.ts.map +1 -1
- package/build/model/plan.js +24 -11
- package/build/model/plan.js.map +1 -1
- package/build/model/portal.d.ts +4 -0
- package/build/model/portal.d.ts.map +1 -0
- package/build/model/portal.js +22 -0
- package/build/model/portal.js.map +1 -0
- package/build/model/pricing.d.ts +4 -0
- package/build/model/pricing.d.ts.map +1 -0
- package/build/model/pricing.js +31 -0
- package/build/model/pricing.js.map +1 -0
- package/build/model/view.d.ts +3 -0
- package/build/model/view.d.ts.map +1 -0
- package/build/model/view.js +15 -0
- package/build/model/view.js.map +1 -0
- package/build/pricing/types.d.ts +13 -0
- package/build/pricing/types.d.ts.map +1 -0
- package/build/pricing/types.js +2 -0
- package/build/pricing/types.js.map +1 -0
- package/build/pricing.d.ts +13 -0
- package/build/pricing.d.ts.map +1 -0
- package/build/pricing.js +74 -0
- package/build/pricing.js.map +1 -0
- package/build/promo/types.d.ts +14 -0
- package/build/promo/types.d.ts.map +1 -0
- package/build/promo/types.js +2 -0
- package/build/promo/types.js.map +1 -0
- package/build/promo.d.ts +7 -0
- package/build/promo.d.ts.map +1 -0
- package/build/promo.js +25 -0
- package/build/promo.js.map +1 -0
- package/build/regions/types.d.ts +32 -0
- package/build/regions/types.d.ts.map +1 -0
- package/build/regions/types.js +2 -0
- package/build/regions/types.js.map +1 -0
- package/build/regions.d.ts +15 -0
- package/build/regions.d.ts.map +1 -0
- package/build/regions.js +43 -0
- package/build/regions.js.map +1 -0
- package/build/service.d.ts.map +1 -1
- package/build/service.js +24 -9
- package/build/service.js.map +1 -1
- package/build/types.d.ts +619 -52
- package/build/types.d.ts.map +1 -1
- package/build/types.local.d.ts +4 -0
- package/build/types.local.d.ts.map +1 -0
- package/build/types.local.js +2 -0
- package/build/types.local.js.map +1 -0
- package/build/view/types.d.ts +33 -0
- package/build/view/types.d.ts.map +1 -0
- package/build/view/types.js +2 -0
- package/build/view/types.js.map +1 -0
- package/build/view.d.ts +13 -0
- package/build/view.d.ts.map +1 -0
- package/build/view.js +78 -0
- package/build/view.js.map +1 -0
- package/package.json +14 -12
- package/src/advertise.ts +13 -0
- package/src/checkout/consts.ts +1 -0
- package/src/checkout/index.ts +5 -0
- package/src/checkout/narrow/types.ts +27 -0
- package/src/checkout/narrow.ts +63 -0
- package/src/checkout/protocols.ts +39 -0
- package/src/checkout/types.ts +27 -0
- package/src/consts.local.ts +34 -0
- package/src/consts.ts +417 -24
- package/src/consumer/cancel.ts +40 -0
- package/src/consumer/consts.local.ts +16 -0
- package/src/consumer/consts.ts +46 -0
- package/src/consumer/copy/types.ts +54 -0
- package/src/consumer/copy.ts +121 -0
- package/src/consumer/deadline/types.ts +30 -0
- package/src/consumer/deadline.ts +61 -0
- package/src/consumer/fifo/types.ts +17 -0
- package/src/consumer/fifo.ts +42 -0
- package/src/consumer/index.ts +17 -0
- package/src/consumer/policy/types.ts +20 -0
- package/src/consumer/policy.ts +101 -0
- package/src/consumer/protocols.ts +116 -0
- package/src/consumer/refund/types.ts +27 -0
- package/src/consumer/refund.ts +136 -0
- package/src/consumer/refusal.ts +35 -0
- package/src/consumer/revive/types.ts +23 -0
- package/src/consumer/revive.ts +82 -0
- package/src/consumer/types.local.ts +10 -0
- package/src/consumer/types.ts +189 -0
- package/src/countries.ts +5 -0
- package/src/entitled.ts +20 -0
- package/src/entitlement/types.ts +29 -0
- package/src/entitlement.ts +67 -103
- package/src/errors.ts +445 -0
- package/src/estimate/types.ts +34 -0
- package/src/estimate.ts +90 -0
- package/src/i18n/consumer-rights/be.json +131 -0
- package/src/i18n/consumer-rights/de.json +131 -0
- package/src/i18n/consumer-rights/en.json +131 -0
- package/src/i18n/consumer-rights/es.json +131 -0
- package/src/i18n/consumer-rights/fr.json +131 -0
- package/src/i18n/consumer-rights/pl.json +131 -0
- package/src/i18n/consumer-rights/ru.json +131 -0
- package/src/i18n/consumer-rights/uk.json +131 -0
- package/src/i18n/errors/be.json +30 -0
- package/src/i18n/errors/de.json +30 -0
- package/src/i18n/errors/en.json +30 -0
- package/src/i18n/errors/es.json +30 -0
- package/src/i18n/errors/fr.json +30 -0
- package/src/i18n/errors/pl.json +30 -0
- package/src/i18n/errors/ru.json +30 -0
- package/src/i18n/errors/uk.json +30 -0
- package/src/i18n/fr.json +39 -0
- package/src/i18n.ts +58 -8
- package/src/index.ts +18 -2
- package/src/limit/types.ts +41 -0
- package/src/limit.ts +132 -0
- package/src/model/checkout.ts +12 -7
- package/src/model/consts.local.ts +83 -0
- package/src/model/consts.ts +206 -0
- package/src/model/consumer.ts +294 -0
- package/src/model/estimate.ts +73 -0
- package/src/model/index.ts +7 -2
- package/src/model/limit.ts +36 -0
- package/src/model/plan.ts +25 -12
- package/src/model/portal.ts +25 -0
- package/src/model/pricing.ts +34 -0
- package/src/model/view.ts +17 -0
- package/src/pricing/types.ts +13 -0
- package/src/pricing.ts +110 -0
- package/src/promo/types.ts +18 -0
- package/src/promo.ts +46 -0
- package/src/regions/types.ts +42 -0
- package/src/regions.ts +85 -0
- package/src/service.ts +32 -15
- package/src/types.local.ts +5 -0
- package/src/types.ts +669 -49
- package/src/view/types.ts +39 -0
- package/src/view.ts +119 -0
- package/tests/checkout-narrow.spec.ts +75 -0
- package/tests/consumer-copy.spec.ts +378 -0
- package/tests/consumer-deadline.spec.ts +85 -0
- package/tests/consumer-fifo.spec.ts +61 -0
- package/tests/consumer-protocols.spec.ts +103 -0
- package/tests/consumer-refund.spec.ts +134 -0
- package/tests/consumer-regions.spec.ts +140 -0
- package/tests/consumer-wire.spec.ts +170 -0
- package/tests/contract.spec.ts +183 -0
- package/tests/entitlement.spec.ts +38 -25
- package/tests/errors.spec.ts +168 -0
- package/tests/estimate.spec.ts +139 -0
- package/tests/limit.spec.ts +117 -0
- package/tests/pricing.spec.ts +30 -0
- package/tests/view.spec.ts +130 -0
- package/build/.gitkeep +0 -0
- package/src/model/subscription.ts +0 -63
- package/src/model/utils.ts +0 -32
- package/src/modules.ts +0 -43
- package/tests/entitlement.spec.d.ts +0 -2
- package/tests/entitlement.spec.d.ts.map +0 -1
- package/tests/entitlement.spec.js +0 -72
- package/tests/entitlement.spec.js.map +0 -1
|
@@ -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>)
|
package/src/model/index.ts
CHANGED
|
@@ -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,
|
|
3
|
+
import { ResourceValueSchema, DateSchema, IdValueSchema } from '@owlmeans/auth'
|
|
4
4
|
import {
|
|
5
|
-
PlanDurationSchema,
|
|
6
|
-
|
|
5
|
+
CheckoutPricingModeSchema, PlanDurationSchema, PlanStatusSchema, ProductDescriptionSchema,
|
|
6
|
+
ProductTitleSchema
|
|
7
7
|
} from '../consts.js'
|
|
8
|
-
import {
|
|
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:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
39
|
+
suspendedAt: { ...DateSchema, nullable: true },
|
|
39
40
|
|
|
40
|
-
capabilities: { type: 'array', items:
|
|
41
|
+
capabilities: { type: 'array', items: PlanCapabilitySchema, nullable: true },
|
|
41
42
|
limits: {
|
|
42
43
|
type: 'object', required: [], nullable: true,
|
|
43
|
-
additionalProperties:
|
|
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
|
+
}
|