@owlmeans/payment 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +524 -0
  3. package/build/.gitkeep +0 -0
  4. package/build/consts.d.ts +62 -0
  5. package/build/consts.d.ts.map +1 -0
  6. package/build/consts.js +87 -0
  7. package/build/consts.js.map +1 -0
  8. package/build/errors.d.ts +42 -0
  9. package/build/errors.d.ts.map +1 -0
  10. package/build/errors.js +81 -0
  11. package/build/errors.js.map +1 -0
  12. package/build/helper.d.ts +3 -0
  13. package/build/helper.d.ts.map +1 -0
  14. package/build/helper.js +3 -0
  15. package/build/helper.js.map +1 -0
  16. package/build/i18n/en.json +39 -0
  17. package/build/i18n.d.ts +2 -0
  18. package/build/i18n.d.ts.map +1 -0
  19. package/build/i18n.js +4 -0
  20. package/build/i18n.js.map +1 -0
  21. package/build/index.d.ts +9 -0
  22. package/build/index.d.ts.map +1 -0
  23. package/build/index.js +8 -0
  24. package/build/index.js.map +1 -0
  25. package/build/model/index.d.ts +6 -0
  26. package/build/model/index.d.ts.map +1 -0
  27. package/build/model/index.js +6 -0
  28. package/build/model/index.js.map +1 -0
  29. package/build/model/localization.d.ts +4 -0
  30. package/build/model/localization.d.ts.map +1 -0
  31. package/build/model/localization.js +19 -0
  32. package/build/model/localization.js.map +1 -0
  33. package/build/model/plan.d.ts +4 -0
  34. package/build/model/plan.d.ts.map +1 -0
  35. package/build/model/plan.js +43 -0
  36. package/build/model/plan.js.map +1 -0
  37. package/build/model/product.d.ts +4 -0
  38. package/build/model/product.d.ts.map +1 -0
  39. package/build/model/product.js +17 -0
  40. package/build/model/product.js.map +1 -0
  41. package/build/model/subscription.d.ts +5 -0
  42. package/build/model/subscription.d.ts.map +1 -0
  43. package/build/model/subscription.js +46 -0
  44. package/build/model/subscription.js.map +1 -0
  45. package/build/model/utils.d.ts +5 -0
  46. package/build/model/utils.d.ts.map +1 -0
  47. package/build/model/utils.js +28 -0
  48. package/build/model/utils.js.map +1 -0
  49. package/build/modules.d.ts +2 -0
  50. package/build/modules.d.ts.map +1 -0
  51. package/build/modules.js +9 -0
  52. package/build/modules.js.map +1 -0
  53. package/build/service.d.ts +5 -0
  54. package/build/service.d.ts.map +1 -0
  55. package/build/service.js +71 -0
  56. package/build/service.js.map +1 -0
  57. package/build/types.d.ts +116 -0
  58. package/build/types.d.ts.map +1 -0
  59. package/build/types.js +2 -0
  60. package/build/types.js.map +1 -0
  61. package/build/utils/index.d.ts +2 -0
  62. package/build/utils/index.d.ts.map +1 -0
  63. package/build/utils/index.js +2 -0
  64. package/build/utils/index.js.map +1 -0
  65. package/build/utils/types.d.ts +7 -0
  66. package/build/utils/types.d.ts.map +1 -0
  67. package/build/utils/types.js +2 -0
  68. package/build/utils/types.js.map +1 -0
  69. package/package.json +52 -0
  70. package/src/consts.ts +100 -0
  71. package/src/errors.ts +102 -0
  72. package/src/helper.ts +5 -0
  73. package/src/i18n/en.json +39 -0
  74. package/src/i18n.ts +6 -0
  75. package/src/index.ts +9 -0
  76. package/src/model/index.ts +6 -0
  77. package/src/model/localization.ts +24 -0
  78. package/src/model/plan.ts +51 -0
  79. package/src/model/product.ts +21 -0
  80. package/src/model/subscription.ts +49 -0
  81. package/src/model/utils.ts +32 -0
  82. package/src/modules.ts +15 -0
  83. package/src/service.ts +95 -0
  84. package/src/types.ts +119 -0
  85. package/src/utils/index.ts +2 -0
  86. package/src/utils/types.ts +9 -0
  87. package/tsconfig.json +15 -0
  88. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEhE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAG9D,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,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CAAC,WAAW,CAAC,CAAA;YACnD,CAAC;YAED,OAAO,IAAI,CAAC,SAAS,CAAA;QACvB,CAAC;KACF,EAAE,OAAO,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE;QACvB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAA;IAC5B,CAAC,CAAC,CAAA;IAEF,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,OAAU,EAAE,QAAgB,aAAa,EACtC,EAAE,CAAC,OAAO,CAAC,eAAe,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAA"}
@@ -0,0 +1,116 @@
1
+ import type { InitializedService } from '@owlmeans/context';
2
+ import type { PaymentEntityType, PlanDuration, PlanStatus, ProductType, SubscriptionStatus } from './consts.js';
3
+ import type { PermissionSet } from '@owlmeans/auth';
4
+ export interface Product {
5
+ type: ProductType;
6
+ sku: string;
7
+ title: string;
8
+ description?: string;
9
+ defaultLng?: string;
10
+ /**
11
+ * Related software services.
12
+ * Actually even if it's a physical product, it can have related
13
+ * software services.
14
+ */
15
+ services?: string[];
16
+ capabilities?: PermissionSet[];
17
+ }
18
+ export interface Localization {
19
+ sku: string;
20
+ type: PaymentEntityType;
21
+ lng: string;
22
+ title?: string;
23
+ description?: string;
24
+ keywords?: {
25
+ [key: string]: string;
26
+ };
27
+ }
28
+ export interface ProductPlan {
29
+ productSku: string;
30
+ sku: string;
31
+ status: PlanStatus;
32
+ payagateAliases?: {
33
+ [paygate: string]: string;
34
+ };
35
+ duration: PlanDuration;
36
+ trial?: number;
37
+ gatedTrial?: boolean;
38
+ price: number;
39
+ order?: number;
40
+ highlight?: string;
41
+ currency?: string;
42
+ originalPrice?: number;
43
+ discount?: number;
44
+ awaitingInterval?: number;
45
+ title: string;
46
+ description?: string;
47
+ customUrl?: string;
48
+ createdAt?: Date;
49
+ archivedAt?: Date;
50
+ /**
51
+ * Deprecation date should be set alongside suspnsion date (that should be set to the future).
52
+ * This way we can plan event when users loose access in case they don't upgrade.
53
+ */
54
+ deprecatedAt?: Date;
55
+ supsendedAt?: Date;
56
+ capabilities?: PermissionSet[];
57
+ limits?: {
58
+ [key: string]: LimitConfig;
59
+ };
60
+ }
61
+ export interface PlanSubscription {
62
+ sku: string;
63
+ entityId: string;
64
+ paymentMethod?: string;
65
+ externalId?: string;
66
+ createdAt: Date;
67
+ lastPaymentAt?: Date;
68
+ trialUntil?: Date;
69
+ startsdAt: Date;
70
+ expirationAt?: Date;
71
+ endsAt?: Date;
72
+ archiveAt?: Date;
73
+ suspendedAt?: Date;
74
+ canceledAt?: Date;
75
+ blockedAt?: Date;
76
+ suspendedUntil?: Date;
77
+ status: SubscriptionStatus;
78
+ /**
79
+ * Custom capabilities for the particular subscription.
80
+ */
81
+ capabilities?: PermissionSet[];
82
+ /**
83
+ * Custom limits for the particular subscription.
84
+ */
85
+ limits?: {
86
+ [key: string]: LimitConfig;
87
+ };
88
+ consumptions?: {
89
+ [key: string]: CapabilityUsage;
90
+ };
91
+ }
92
+ export interface SubscriptionPropogateBody extends PlanSubscription {
93
+ service: string;
94
+ externalId: string;
95
+ }
96
+ export interface LimitConfig {
97
+ interval: PlanDuration;
98
+ limit: number;
99
+ measurment?: string;
100
+ }
101
+ export interface CapabilityUsage extends LimitConfig {
102
+ startedAt: Date;
103
+ refreshedAt?: Date;
104
+ refreshAt?: Date;
105
+ lastConsumedAt?: Date;
106
+ consumption: number;
107
+ }
108
+ type PaymentEntity = Product | ProductPlan | PermissionSet;
109
+ export interface PaymentService extends InitializedService {
110
+ product: (sku: string) => Promise<Product>;
111
+ plans: (productSku: string, duration: PlanDuration) => Promise<ProductPlan[]>;
112
+ localize: (lng: string, entity: PaymentEntity) => Promise<Localization | null>;
113
+ shallowAuthentication: (token: string | null) => Promise<string>;
114
+ }
115
+ export {};
116
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/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AAA;KAAE,CAAA;IACvC,YAAY,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAAA;KAAE,CAAA;CAClD;AAED,MAAM,WAAW,yBAA0B,SAAQ,gBAAgB;IACjE,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,YAAY,CAAA;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,eAAgB,SAAQ,WAAW;IAClD,SAAS,EAAE,IAAI,CAAA;IACf,WAAW,CAAC,EAAE,IAAI,CAAA;IAClB,SAAS,CAAC,EAAE,IAAI,CAAA;IAChB,cAAc,CAAC,EAAE,IAAI,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,KAAK,aAAa,GAAG,OAAO,GAAG,WAAW,GAAG,aAAa,CAAA;AAE1D,MAAM,WAAW,cAAe,SAAQ,kBAAkB;IACxD,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAE1C,KAAK,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,KAAK,OAAO,CAAC,WAAW,EAAE,CAAC,CAAA;IAE7E,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAA;IAE9E,qBAAqB,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CACjE"}
package/build/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export type * from './types.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ import type { CommonConfig, ConfigResourceAppend } from '@owlmeans/config';
2
+ import type { BasicContext } from '@owlmeans/context';
3
+ export interface Config extends CommonConfig {
4
+ }
5
+ export interface Context<C extends Config = Config> extends BasicContext<C>, ConfigResourceAppend {
6
+ }
7
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAC1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,MAAM,WAAW,MAAO,SAAQ,YAAY;CAAI;AAEhD,MAAM,WAAW,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,YAAY,CAAC,CAAC,CAAC,EACvE,oBAAoB;CACvB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@owlmeans/payment",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "scripts": {
6
+ "build": "tsc -b",
7
+ "dev": "sleep 228 && nodemon -e ts,tsx,json --watch src --exec \"tsc -p ./tsconfig.json\"",
8
+ "watch": "tsc -b -w --preserveWatchOutput --pretty"
9
+ },
10
+ "main": "build/index.js",
11
+ "module": "build/index.js",
12
+ "types": "build/index.d.ts",
13
+ "exports": {
14
+ ".": {
15
+ "import": "./build/index.js",
16
+ "require": "./build/index.js",
17
+ "default": "./build/index.js",
18
+ "module": "./build/index.js",
19
+ "types": "./build/index.d.ts"
20
+ },
21
+ "./utils": {
22
+ "import": "./build/utils/index.js",
23
+ "require": "./build/utils/index.js",
24
+ "default": "./build/utils/index.js",
25
+ "module": "./build/utils/index.js",
26
+ "types": "./build/utils/index.d.ts"
27
+ }
28
+ },
29
+ "peerDependencies": {
30
+ "ajv": "*"
31
+ },
32
+ "dependencies": {
33
+ "@owlmeans/auth": "^0.1.0",
34
+ "@owlmeans/basic-envelope": "^0.1.0",
35
+ "@owlmeans/config": "^0.1.0",
36
+ "@owlmeans/context": "^0.1.0",
37
+ "@owlmeans/error": "^0.1.0",
38
+ "@owlmeans/i18n": "^0.1.0",
39
+ "@owlmeans/module": "^0.1.0",
40
+ "@owlmeans/resource": "^0.1.0",
41
+ "@owlmeans/route": "^0.1.0"
42
+ },
43
+ "devDependencies": {
44
+ "nodemon": "^3.1.7",
45
+ "npm-check": "^6.0.1",
46
+ "typescript": "^5.6.3"
47
+ },
48
+ "private": false,
49
+ "publishConfig": {
50
+ "access": "public"
51
+ }
52
+ }
package/src/consts.ts ADDED
@@ -0,0 +1,100 @@
1
+ import type { JSONSchemaType } from 'ajv'
2
+
3
+ export enum ProductType {
4
+ Simple = 'simple',
5
+ Service = 'service'
6
+ }
7
+
8
+ export enum PaymentEntityType {
9
+ Product = 'product',
10
+ Plan = 'plan',
11
+ CapabilitySet = 'capability-set',
12
+ }
13
+
14
+ export enum PlanStatus {
15
+ Active = 'active',
16
+ Custom = 'custom',
17
+ Hidden = 'hidden',
18
+ Archived = 'archived',
19
+ Deprecated = 'deprecated',
20
+ Suspended = 'suspended'
21
+ }
22
+
23
+ export enum PlanDuration {
24
+ Monthly = 'monthly',
25
+ Yearly = 'yearly',
26
+ Lifetime = 'lifetime',
27
+ Reusable = 'reusable',
28
+ /**
29
+ * It means it requires some tokens to be consumed to use the
30
+ * capability.
31
+ */
32
+ Consumable = 'consumable'
33
+ }
34
+
35
+ export enum SubscriptionStatus {
36
+ Created = 'created',
37
+ Trial = 'trial',
38
+ Canceled = 'canceled',
39
+ Expired = 'expired',
40
+ Suspended = 'suspended',
41
+ Blocked = 'blocked',
42
+ Ended = 'ended',
43
+ Free = 'free',
44
+ Active = 'active'
45
+ }
46
+
47
+ export const ProductTypeSchema: JSONSchemaType<ProductType> = {
48
+ type: 'string',
49
+ enum: Object.values(ProductType)
50
+ }
51
+
52
+ export const PaymentEntityTypeSchema: JSONSchemaType<PaymentEntityType> = {
53
+ type: 'string',
54
+ enum: Object.values(PaymentEntityType)
55
+ }
56
+
57
+ export const PlanStatusSchema: JSONSchemaType<PlanStatus> = {
58
+ type: 'string',
59
+ enum: Object.values(PlanStatus)
60
+ }
61
+
62
+ export const PlanDurationSchema: JSONSchemaType<PlanDuration> = {
63
+ type: 'string',
64
+ enum: Object.values(PlanDuration)
65
+ }
66
+
67
+ export const SubscriptionStatusSchema: JSONSchemaType<SubscriptionStatus> = {
68
+ type: 'string',
69
+ enum: Object.values(SubscriptionStatus)
70
+ }
71
+
72
+ export const ProductTitleSchema: JSONSchemaType<string> = {
73
+ type: 'string', minLength: 1, maxLength: 128
74
+ }
75
+
76
+ export const ProductDescriptionSchema: JSONSchemaType<string> = {
77
+ type: 'string', minLength: 0, maxLength: 1024, nullable: true
78
+ }
79
+
80
+ export const LocalizationLngSchema: JSONSchemaType<string> = {
81
+ type: 'string', minLength: 2, maxLength: 3
82
+ }
83
+
84
+ export const PRODUCT_RECORD_TYPE = 'product'
85
+ export const PRODUCT_RECORD_PREFIX = PRODUCT_RECORD_TYPE
86
+
87
+ export const PLAN_RECORD_TYPE = 'plan'
88
+ export const PLAN_RECORD_PREFIX = PLAN_RECORD_TYPE
89
+
90
+ export const L10N_RECORD_TYPE = 'l10n'
91
+ export const L10N_RECORD_PREFIX = L10N_RECORD_TYPE
92
+
93
+ export const DEFAULT_ALIAS = 'payment'
94
+
95
+ export const paymentApi = {
96
+ subscription: {
97
+ base: 'payment-api:subscription',
98
+ propogate: 'payment-api:subscription:propogate',
99
+ }
100
+ }
package/src/errors.ts ADDED
@@ -0,0 +1,102 @@
1
+
2
+ import { ResilientError } from '@owlmeans/error'
3
+
4
+ export class PaymentError extends ResilientError {
5
+ public static override typeName: string = 'PaymentError'
6
+
7
+ constructor(message: string = 'error') {
8
+ super(PaymentError.typeName, `payment:${message}`)
9
+ }
10
+ }
11
+
12
+ export class PaygateError extends PaymentError {
13
+ public static override typeName: string = `${PaymentError.typeName}Paygate`
14
+
15
+ constructor(message: string = 'error') {
16
+ super(`paygate:${message}`)
17
+ this.type = PaygateError.typeName
18
+ }
19
+ }
20
+
21
+ export class UnknownPaygate extends PaygateError {
22
+ public static override typeName: string = `${PaygateError.typeName}Unknown`
23
+
24
+ constructor(message: string = 'error') {
25
+ super(`unknown:${message}`)
26
+ this.type = UnknownPaygate.typeName
27
+ }
28
+ }
29
+
30
+ export class PaygateMappingError extends PaygateError {
31
+ public static override typeName: string = `${PaygateError.typeName}Mapping`
32
+
33
+ constructor(message: string = 'error') {
34
+ super(`mapping:${message}`)
35
+ this.type = PaygateMappingError.typeName
36
+ }
37
+ }
38
+
39
+ export class ProductError extends PaymentError {
40
+ public static override typeName: string = `${PaymentError.typeName}Product`
41
+
42
+ constructor(message: string = 'error') {
43
+ super(`product:${message}`)
44
+ this.type = ProductError.typeName
45
+ }
46
+ }
47
+
48
+ export class UnknownProduct extends ProductError {
49
+ public static override typeName: string = `${ProductError.typeName}Unknown`
50
+
51
+ constructor(message: string = 'error') {
52
+ super(`unknown:${message}`)
53
+ this.type = UnknownProduct.typeName
54
+ }
55
+ }
56
+
57
+ export class UnknownPlan extends ProductError {
58
+ public static override typeName: string = `${ProductError.typeName}Plan`
59
+
60
+ constructor(message: string = 'error') {
61
+ super(`unknown:${message}`)
62
+ this.type = UnknownPlan.typeName
63
+ }
64
+ }
65
+
66
+ export class PaymentIdentificationError extends PaymentError {
67
+ public static override typeName: string = `${PaymentError.typeName}Identification`
68
+
69
+ constructor(message: string = 'error') {
70
+ super(`identification:${message}`)
71
+ this.type = PaymentIdentificationError.typeName
72
+ }
73
+ }
74
+
75
+ export class SubscriptionError extends PaymentError {
76
+ public static override typeName: string = `${PaymentError.typeName}Subscription`
77
+
78
+ constructor(message: string = 'error') {
79
+ super(`subscription:${message}`)
80
+ this.type = SubscriptionError.typeName
81
+ }
82
+ }
83
+
84
+ export class UnknownSubscription extends SubscriptionError {
85
+ public static override typeName: string = `${SubscriptionError.typeName}Unknown`
86
+
87
+ constructor(message: string = 'error') {
88
+ super(`unknown:${message}`)
89
+ this.type = UnknownSubscription.typeName
90
+ }
91
+ }
92
+
93
+ ResilientError.registerErrorClass(PaymentError)
94
+ ResilientError.registerErrorClass(PaygateError)
95
+ ResilientError.registerErrorClass(UnknownPaygate)
96
+ ResilientError.registerErrorClass(PaygateMappingError)
97
+ ResilientError.registerErrorClass(ProductError)
98
+ ResilientError.registerErrorClass(UnknownProduct)
99
+ ResilientError.registerErrorClass(UnknownPlan)
100
+ ResilientError.registerErrorClass(PaymentIdentificationError)
101
+ ResilientError.registerErrorClass(SubscriptionError)
102
+ ResilientError.registerErrorClass(UnknownSubscription)
package/src/helper.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { L10N_RECORD_PREFIX } from './consts.js'
2
+ import type { Localization } from './types.js'
3
+
4
+ export const l10nToId = (l10n: Localization, prefix?: boolean): string =>
5
+ `${prefix ? L10N_RECORD_PREFIX + ':' : ''}${l10n.type}:${l10n.sku}:${l10n.lng}`
@@ -0,0 +1,39 @@
1
+ {
2
+ "plan": {
3
+ "duration": {
4
+ "monthly": "Montly subscription",
5
+ "yearly": "Yerly subscription"
6
+ },
7
+ "trial": {
8
+ "gated": "Free trial — {{days}} days",
9
+ "open": "No card required — {{days}} free trial"
10
+ },
11
+ "highlight": {
12
+ "custom": "Tell us about your custom needs",
13
+ "comming-soon": "Required features comming soon!",
14
+ "best-value": "Best value!"
15
+ },
16
+ "label": {
17
+ "monthly": "a month",
18
+ "discount": "with discount: {{discount}}%"
19
+ }
20
+ },
21
+ "measurement": {
22
+ "yes": "Yes",
23
+ "no": "No",
24
+ "comming-soon": "Comming soon",
25
+ "custom": "custom",
26
+ "mb": "Mb"
27
+ },
28
+ "action": {
29
+ "start": "Start now",
30
+ "custom": "Contact us",
31
+ "active": "Try now",
32
+ "gated": "Subscribe now",
33
+ "best-value": "Start free trial",
34
+ "comming-soon": "Join now"
35
+ },
36
+ "success": {
37
+ "guideline": "Your payment is processing. You will be redirected to the service soon..."
38
+ }
39
+ }
package/src/i18n.ts ADDED
@@ -0,0 +1,6 @@
1
+
2
+ import { addI18nLib } from '@owlmeans/i18n'
3
+
4
+ import en from './i18n/en.json' with {type: "json"}
5
+
6
+ addI18nLib('en', 'payment', en)
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+
2
+ export type * from './types.js'
3
+ export * from './model/index.js'
4
+ export * from './errors.js'
5
+ export * from './consts.js'
6
+ export * from './service.js'
7
+ export * from './i18n.js'
8
+ export * from './helper.js'
9
+ export * from './modules.js'
@@ -0,0 +1,6 @@
1
+
2
+ export * from './product.js'
3
+ export * from './localization.js'
4
+ export * from './subscription.js'
5
+ export * from './plan.js'
6
+ export * from './utils.js'
@@ -0,0 +1,24 @@
1
+ import type { JSONSchemaType } from 'ajv'
2
+ import type { Localization } from '../types.js'
3
+ import {
4
+ ProductDescriptionSchema, ProductTitleSchema, PaymentEntityTypeSchema,
5
+ LocalizationLngSchema
6
+ } from '../consts.js'
7
+ import { IdValueSchema } from '@owlmeans/auth'
8
+
9
+ export const LocalizationSchema: JSONSchemaType<Localization> = {
10
+ type: 'object',
11
+ properties: {
12
+ type: PaymentEntityTypeSchema,
13
+ sku: IdValueSchema,
14
+ lng: LocalizationLngSchema,
15
+ title: { ...ProductTitleSchema, nullable: true },
16
+ description: { ...ProductDescriptionSchema, nullable: true },
17
+ keywords: {
18
+ type: 'object', required: [], nullable: true,
19
+ additionalProperties: { type: 'string' }
20
+ }
21
+ },
22
+ required: ['type', 'sku', 'lng'],
23
+ additionalProperties: false,
24
+ }
@@ -0,0 +1,51 @@
1
+ import type { JSONSchemaType } from 'ajv'
2
+ import type { ProductPlan } from '../types.js'
3
+ import { ResourceValueSchema, PermissionSetSchema, DateSchema } from '@owlmeans/auth'
4
+ import {
5
+ PlanDurationSchema, ProductDescriptionSchema, ProductTitleSchema,
6
+ SubscriptionStatusSchema
7
+ } from '../consts.js'
8
+ import { LimitConfigSchema } from './utils.js'
9
+
10
+ export const ProductPlanSchema: JSONSchemaType<ProductPlan> = {
11
+ type: 'object',
12
+ properties: {
13
+ productSku: ResourceValueSchema,
14
+ sku: ResourceValueSchema,
15
+ status: SubscriptionStatusSchema,
16
+ payagateAliases: {
17
+ type: 'object', required: [], nullable: true,
18
+ additionalProperties: { type: 'string' },
19
+ },
20
+ duration: PlanDurationSchema,
21
+ trial: { type: 'number', nullable: true },
22
+ gatedTrial: { type: 'boolean', nullable: true },
23
+ price: { type: 'number', minimum: 0 },
24
+ order: { type: 'number', nullable: true },
25
+ highlight: { type: 'string', minLength: 1, maxLength: 32, nullable: true },
26
+ currency: { type: 'string', minLength: 2, maxLength: 3, nullable: true },
27
+ originalPrice: { type: 'number', minimum: 0, nullable: true },
28
+ discount: { type: 'number', minimum: 0, nullable: true },
29
+ awaitingInterval: { type: 'number', minimum: 0, nullable: true },
30
+
31
+ title: ProductTitleSchema,
32
+ description: { ...ProductDescriptionSchema, nullable: true },
33
+ customUrl: { type: 'string', maxLength: 256, nullable: true },
34
+
35
+ createdAt: { ...DateSchema, nullable: true },
36
+ archivedAt: { ...DateSchema, nullable: true },
37
+ deprecatedAt: { ...DateSchema, nullable: true },
38
+ supsendedAt: { ...DateSchema, nullable: true },
39
+
40
+ capabilities: { type: 'array', items: PermissionSetSchema, nullable: true },
41
+ limits: {
42
+ type: 'object', required: [], nullable: true,
43
+ additionalProperties: LimitConfigSchema
44
+ },
45
+ },
46
+ required: [
47
+ 'productSku', 'sku', 'status', 'duration',
48
+ 'price', 'title'
49
+ ],
50
+ additionalProperties: false,
51
+ }
@@ -0,0 +1,21 @@
1
+ import type { JSONSchemaType } from 'ajv'
2
+ import type { Product } from '../types.js'
3
+ import {
4
+ LocalizationLngSchema, ProductDescriptionSchema, ProductTitleSchema, ProductTypeSchema
5
+ } from '../consts.js'
6
+ import { ResourceValueSchema, PermissionSetSchema } from '@owlmeans/auth'
7
+
8
+ export const ProductSchema: JSONSchemaType<Product> = {
9
+ type: 'object',
10
+ properties: {
11
+ type: ProductTypeSchema,
12
+ sku: ResourceValueSchema,
13
+ title: ProductTitleSchema,
14
+ description: { ...ProductDescriptionSchema, nullable: true },
15
+ defaultLng: { ...LocalizationLngSchema, nullable: true },
16
+ services: { type: 'array', items: ResourceValueSchema, nullable: true },
17
+ capabilities: { type: 'array', items: PermissionSetSchema, nullable: true }
18
+ },
19
+ required: ['type', 'sku', 'title'],
20
+ additionalProperties: false,
21
+ }
@@ -0,0 +1,49 @@
1
+ import type { JSONSchemaType } from 'ajv'
2
+ import type { PlanSubscription, SubscriptionPropogateBody } from '../types.js'
3
+ import { ResourceValueSchema, PermissionSetSchema, DateSchema, EntityValueSchema, IdValueSchema } from '@owlmeans/auth'
4
+ import { SubscriptionStatusSchema } from '../consts.js'
5
+ import { CapabilityUsageSchema, LimitConfigSchema } from './utils.js'
6
+
7
+ export const PlanSubscriptionSchema: JSONSchemaType<PlanSubscription> = {
8
+ type: 'object',
9
+ properties: {
10
+ sku: ResourceValueSchema,
11
+ entityId: EntityValueSchema,
12
+ paymentMethod: { ...IdValueSchema, nullable: true },
13
+ externalId: { ...IdValueSchema, nullable: true },
14
+ createdAt: DateSchema,
15
+ lastPaymentAt: { ...DateSchema, nullable: true },
16
+ trialUntil: { ...DateSchema, nullable: true },
17
+ startsdAt: DateSchema,
18
+ expirationAt: { ...DateSchema, nullable: true },
19
+ endsAt: { ...DateSchema, nullable: true },
20
+ archiveAt: { ...DateSchema, nullable: true },
21
+ suspendedAt: { ...DateSchema, nullable: true },
22
+ canceledAt: { ...DateSchema, nullable: true },
23
+ blockedAt: { ...DateSchema, nullable: true },
24
+ suspendedUntil: { ...DateSchema, nullable: true },
25
+ status: SubscriptionStatusSchema,
26
+ capabilities: { type: 'array', items: PermissionSetSchema, nullable: true },
27
+ limits: {
28
+ type: 'object', required: [], nullable: true,
29
+ additionalProperties: LimitConfigSchema
30
+ },
31
+ consumptions: {
32
+ type: 'object', required: [], nullable: true,
33
+ additionalProperties: CapabilityUsageSchema
34
+ }
35
+ },
36
+ required: ['sku', 'entityId', 'createdAt', 'startsdAt', 'status'],
37
+ additionalProperties: false,
38
+ }
39
+
40
+ export const SubscriptionPropogateBodySchema: JSONSchemaType<SubscriptionPropogateBody> = {
41
+ type: 'object',
42
+ properties: {
43
+ ...PlanSubscriptionSchema.properties,
44
+ service: { ...ResourceValueSchema, minLength: 2 },
45
+ externalId: IdValueSchema,
46
+ } as any, // @TODO Figure out why it doesn't work (probably different version of ajv)
47
+ required: ['externalId', 'service', ...PlanSubscriptionSchema.required],
48
+ additionalProperties: false,
49
+ }