@forklaunch/implementation-billing-base 0.1.12 → 0.1.13

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 (89) hide show
  1. package/lib/__test__/schemaEquality.test.d.ts +2 -0
  2. package/lib/__test__/schemaEquality.test.d.ts.map +1 -0
  3. package/lib/__test__/schemaEquality.test.js +250 -0
  4. package/lib/eject/domain/schemas/billingPortal.schema.ts +37 -0
  5. package/lib/eject/domain/schemas/checkoutSession.schema.ts +55 -0
  6. package/lib/eject/domain/schemas/index.ts +5 -0
  7. package/lib/eject/domain/schemas/paymentLink.schema.ts +60 -0
  8. package/lib/eject/domain/schemas/plan.schema.ts +80 -0
  9. package/lib/eject/domain/schemas/subscription.schema.ts +86 -0
  10. package/lib/eject/services/billingPortal.service.ts +145 -0
  11. package/lib/eject/services/checkoutSession.service.ts +132 -0
  12. package/lib/eject/services/index.ts +5 -0
  13. package/lib/eject/services/paymentLink.service.ts +170 -0
  14. package/lib/eject/services/plan.service.ts +132 -0
  15. package/lib/eject/services/subscription.service.ts +239 -0
  16. package/lib/jest.config.d.ts +4 -0
  17. package/lib/jest.config.d.ts.map +1 -0
  18. package/lib/jest.config.js +19 -0
  19. package/lib/schemas/billingPortal.schema.d.ts +50 -0
  20. package/lib/schemas/billingPortal.schema.d.ts.map +1 -0
  21. package/lib/schemas/billingPortal.schema.js +4 -0
  22. package/lib/schemas/checkoutSession.schema.d.ts +64 -0
  23. package/lib/schemas/checkoutSession.schema.d.ts.map +1 -0
  24. package/lib/schemas/checkoutSession.schema.js +4 -0
  25. package/lib/schemas/index.d.ts +6 -0
  26. package/lib/schemas/index.d.ts.map +1 -0
  27. package/lib/schemas/index.js +5 -0
  28. package/lib/schemas/paymentLink.schema.d.ts +74 -0
  29. package/lib/schemas/paymentLink.schema.d.ts.map +1 -0
  30. package/lib/schemas/paymentLink.schema.js +4 -0
  31. package/lib/schemas/plan.schema.d.ts +86 -0
  32. package/lib/schemas/plan.schema.d.ts.map +1 -0
  33. package/lib/schemas/plan.schema.js +4 -0
  34. package/lib/schemas/subscription.schema.d.ts +98 -0
  35. package/lib/schemas/subscription.schema.d.ts.map +1 -0
  36. package/lib/schemas/subscription.schema.js +4 -0
  37. package/lib/schemas/typebox/billingPortal.schema.d.ts +47 -0
  38. package/lib/schemas/typebox/billingPortal.schema.d.ts.map +1 -0
  39. package/lib/schemas/typebox/billingPortal.schema.js +25 -0
  40. package/lib/schemas/typebox/checkoutSession.schema.d.ts +62 -0
  41. package/lib/schemas/typebox/checkoutSession.schema.d.ts.map +1 -0
  42. package/lib/schemas/typebox/checkoutSession.schema.js +32 -0
  43. package/lib/schemas/typebox/paymentLink.schema.d.ts +72 -0
  44. package/lib/schemas/typebox/paymentLink.schema.d.ts.map +1 -0
  45. package/lib/schemas/typebox/paymentLink.schema.js +37 -0
  46. package/lib/schemas/typebox/plan.schema.d.ts +84 -0
  47. package/lib/schemas/typebox/plan.schema.d.ts.map +1 -0
  48. package/lib/schemas/typebox/plan.schema.js +43 -0
  49. package/lib/schemas/typebox/subscription.schema.d.ts +96 -0
  50. package/lib/schemas/typebox/subscription.schema.d.ts.map +1 -0
  51. package/lib/schemas/typebox/subscription.schema.js +49 -0
  52. package/lib/schemas/zod/billingPortal.schema.d.ts +47 -0
  53. package/lib/schemas/zod/billingPortal.schema.d.ts.map +1 -0
  54. package/lib/schemas/zod/billingPortal.schema.js +25 -0
  55. package/lib/schemas/zod/checkoutSession.schema.d.ts +62 -0
  56. package/lib/schemas/zod/checkoutSession.schema.d.ts.map +1 -0
  57. package/lib/schemas/zod/checkoutSession.schema.js +32 -0
  58. package/lib/schemas/zod/paymentLink.schema.d.ts +72 -0
  59. package/lib/schemas/zod/paymentLink.schema.d.ts.map +1 -0
  60. package/lib/schemas/zod/paymentLink.schema.js +37 -0
  61. package/lib/schemas/zod/plan.schema.d.ts +84 -0
  62. package/lib/schemas/zod/plan.schema.d.ts.map +1 -0
  63. package/lib/schemas/zod/plan.schema.js +43 -0
  64. package/lib/schemas/zod/subscription.schema.d.ts +96 -0
  65. package/lib/schemas/zod/subscription.schema.d.ts.map +1 -0
  66. package/lib/schemas/zod/subscription.schema.js +49 -0
  67. package/lib/services/billingPortal.service.d.ts +45 -0
  68. package/lib/services/billingPortal.service.d.ts.map +1 -0
  69. package/lib/services/billingPortal.service.js +51 -0
  70. package/lib/services/checkoutSession.service.d.ts +46 -0
  71. package/lib/services/checkoutSession.service.d.ts.map +1 -0
  72. package/lib/services/checkoutSession.service.js +49 -0
  73. package/lib/services/index.d.ts +6 -0
  74. package/lib/services/index.d.ts.map +1 -0
  75. package/lib/services/index.js +5 -0
  76. package/lib/services/paymentLink.service.d.ts +49 -0
  77. package/lib/services/paymentLink.service.d.ts.map +1 -0
  78. package/lib/services/paymentLink.service.js +72 -0
  79. package/lib/services/plan.service.d.ts +43 -0
  80. package/lib/services/plan.service.d.ts.map +1 -0
  81. package/lib/services/plan.service.js +43 -0
  82. package/lib/services/subscription.service.d.ts +53 -0
  83. package/lib/services/subscription.service.d.ts.map +1 -0
  84. package/lib/services/subscription.service.js +94 -0
  85. package/lib/tsconfig.tsbuildinfo +1 -0
  86. package/lib/vitest.config.d.ts +3 -0
  87. package/lib/vitest.config.d.ts.map +1 -0
  88. package/lib/vitest.config.js +7 -0
  89. package/package.json +2 -2
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=schemaEquality.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaEquality.test.d.ts","sourceRoot":"","sources":["../../__test__/schemaEquality.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,250 @@
1
+ import { isTrue } from '@forklaunch/common';
2
+ import { DummyEnum, testSchemaEquality } from '@forklaunch/core/test';
3
+ import { BillingPortalSchema as TypeboxBillingPortalSchema, CreateBillingPortalSchema as TypeboxCreateBillingPortalSchema, UpdateBillingPortalSchema as TypeboxUpdateBillingPortalSchema } from '../schemas/typebox/billingPortal.schema';
4
+ import { CheckoutSessionSchema as TypeboxCheckoutSessionSchema, CreateCheckoutSessionSchema as TypeboxCreateCheckoutSessionSchema, UpdateCheckoutSessionSchema as TypeboxUpdateCheckoutSessionSchema } from '../schemas/typebox/checkoutSession.schema';
5
+ import { CreatePaymentLinkSchema as TypeboxCreatePaymentLinkSchema, PaymentLinkSchema as TypeboxPaymentLinkSchema, UpdatePaymentLinkSchema as TypeboxUpdatePaymentLinkSchema } from '../schemas/typebox/paymentLink.schema';
6
+ import { CreatePlanSchema as TypeboxCreatePlanSchema, PlanSchema as TypeboxPlanSchema, UpdatePlanSchema as TypeboxUpdatePlanSchema } from '../schemas/typebox/plan.schema';
7
+ import { CreateSubscriptionSchema as TypeboxCreateSubscriptionSchema, SubscriptionSchema as TypeboxSubscriptionSchema, UpdateSubscriptionSchema as TypeboxUpdateSubscriptionSchema } from '../schemas/typebox/subscription.schema';
8
+ import { BillingPortalSchema as ZodBillingPortalSchema, CreateBillingPortalSchema as ZodCreateBillingPortalSchema, UpdateBillingPortalSchema as ZodUpdateBillingPortalSchema } from '../schemas/zod/billingPortal.schema';
9
+ import { CheckoutSessionSchema as ZodCheckoutSessionSchema, CreateCheckoutSessionSchema as ZodCreateCheckoutSessionSchema, UpdateCheckoutSessionSchema as ZodUpdateCheckoutSessionSchema } from '../schemas/zod/checkoutSession.schema';
10
+ import { CreatePaymentLinkSchema as ZodCreatePaymentLinkSchema, PaymentLinkSchema as ZodPaymentLinkSchema, UpdatePaymentLinkSchema as ZodUpdatePaymentLinkSchema } from '../schemas/zod/paymentLink.schema';
11
+ import { CreatePlanSchema as ZodCreatePlanSchema, PlanSchema as ZodPlanSchema, UpdatePlanSchema as ZodUpdatePlanSchema } from '../schemas/zod/plan.schema';
12
+ import { CreateSubscriptionSchema as ZodCreateSubscriptionSchema, SubscriptionSchema as ZodSubscriptionSchema, UpdateSubscriptionSchema as ZodUpdateSubscriptionSchema } from '../schemas/zod/subscription.schema';
13
+ const zodUpdateBillingPortalSchema = ZodUpdateBillingPortalSchema({
14
+ uuidId: false
15
+ });
16
+ const typeboxUpdateBillingPortalSchema = TypeboxUpdateBillingPortalSchema({
17
+ uuidId: false
18
+ });
19
+ const zodBillingPortalSchema = ZodBillingPortalSchema({ uuidId: false });
20
+ const typeboxBillingPortalSchema = TypeboxBillingPortalSchema({
21
+ uuidId: false
22
+ });
23
+ const zodCreateCheckoutSessionSchema = ZodCreateCheckoutSessionSchema(DummyEnum);
24
+ const typeboxCreateCheckoutSessionSchema = TypeboxCreateCheckoutSessionSchema(DummyEnum);
25
+ const zodUpdateCheckoutSessionSchema = ZodUpdateCheckoutSessionSchema({
26
+ uuidId: false
27
+ })(DummyEnum);
28
+ const typeboxUpdateCheckoutSessionSchema = TypeboxUpdateCheckoutSessionSchema({
29
+ uuidId: false
30
+ })(DummyEnum);
31
+ const zodCheckoutSessionSchema = ZodCheckoutSessionSchema({ uuidId: true })(DummyEnum);
32
+ const typeboxCheckoutSessionSchema = TypeboxCheckoutSessionSchema({
33
+ uuidId: true
34
+ })(DummyEnum);
35
+ const zodCreatePaymentLinkSchema = ZodCreatePaymentLinkSchema(DummyEnum);
36
+ const typeboxCreatePaymentLinkSchema = TypeboxCreatePaymentLinkSchema(DummyEnum);
37
+ const zodUpdatePaymentLinkSchema = ZodUpdatePaymentLinkSchema({
38
+ uuidId: false
39
+ })(DummyEnum);
40
+ const typeboxUpdatePaymentLinkSchema = TypeboxUpdatePaymentLinkSchema({
41
+ uuidId: false
42
+ })(DummyEnum);
43
+ const zodPaymentLinkSchema = ZodPaymentLinkSchema({ uuidId: true })(DummyEnum);
44
+ const typeboxPaymentLinkSchema = TypeboxPaymentLinkSchema({
45
+ uuidId: false
46
+ })(DummyEnum);
47
+ const zodCreatePlanSchema = ZodCreatePlanSchema(DummyEnum, DummyEnum);
48
+ const typeboxCreatePlanSchema = TypeboxCreatePlanSchema(DummyEnum, DummyEnum);
49
+ const zodUpdatePlanSchema = ZodUpdatePlanSchema({ uuidId: false })(DummyEnum, DummyEnum);
50
+ const typeboxUpdatePlanSchema = TypeboxUpdatePlanSchema({ uuidId: false })(DummyEnum, DummyEnum);
51
+ const zodPlanSchema = ZodPlanSchema({ uuidId: true })(DummyEnum, DummyEnum);
52
+ const typeboxPlanSchema = TypeboxPlanSchema({ uuidId: true })(DummyEnum, DummyEnum);
53
+ const zodCreateSubscriptionSchema = ZodCreateSubscriptionSchema(DummyEnum, DummyEnum);
54
+ const typeboxCreateSubscriptionSchema = TypeboxCreateSubscriptionSchema(DummyEnum, DummyEnum);
55
+ const zodUpdateSubscriptionSchema = ZodUpdateSubscriptionSchema({
56
+ uuidId: false
57
+ })(DummyEnum, DummyEnum);
58
+ const typeboxUpdateSubscriptionSchema = TypeboxUpdateSubscriptionSchema({
59
+ uuidId: false
60
+ })(DummyEnum, DummyEnum);
61
+ const zodSubscriptionSchema = ZodSubscriptionSchema({ uuidId: true })(DummyEnum, DummyEnum);
62
+ const typeboxSubscriptionSchema = TypeboxSubscriptionSchema({
63
+ uuidId: true
64
+ })(DummyEnum, DummyEnum);
65
+ describe('schema equality', () => {
66
+ it('should be equal for billing portal', () => {
67
+ expect(isTrue(testSchemaEquality(ZodCreateBillingPortalSchema, TypeboxCreateBillingPortalSchema, {
68
+ customerId: 'test',
69
+ uri: 'https://example.com',
70
+ expiresAt: new Date()
71
+ }))).toBeTruthy();
72
+ expect(isTrue(testSchemaEquality(zodUpdateBillingPortalSchema, typeboxUpdateBillingPortalSchema, {
73
+ id: 'test',
74
+ uri: 'https://example.com',
75
+ expiresAt: new Date()
76
+ }))).toBeTruthy();
77
+ expect(isTrue(testSchemaEquality(zodBillingPortalSchema, typeboxBillingPortalSchema, {
78
+ id: 'test',
79
+ customerId: 'test',
80
+ uri: 'https://example.com',
81
+ expiresAt: new Date(),
82
+ extraFields: {
83
+ test: 'test'
84
+ }
85
+ }))).toBeTruthy();
86
+ });
87
+ it('should be equal for checkout session', () => {
88
+ expect(isTrue(testSchemaEquality(zodCreateCheckoutSessionSchema, typeboxCreateCheckoutSessionSchema, {
89
+ customerId: 'test',
90
+ paymentMethods: [DummyEnum.A, DummyEnum.B],
91
+ successRedirectUri: 'https://example.com',
92
+ cancelRedirectUri: 'https://example.com',
93
+ extraFields: {
94
+ test: 'test'
95
+ }
96
+ }))).toBeTruthy();
97
+ expect(isTrue(testSchemaEquality(zodUpdateCheckoutSessionSchema, typeboxUpdateCheckoutSessionSchema, {
98
+ id: 'test',
99
+ customerId: 'test',
100
+ paymentMethods: [DummyEnum.A, DummyEnum.B],
101
+ successRedirectUri: 'https://example.com',
102
+ cancelRedirectUri: 'https://example.com',
103
+ extraFields: {
104
+ test: 'test'
105
+ }
106
+ }))).toBeTruthy();
107
+ expect(isTrue(testSchemaEquality(zodCheckoutSessionSchema, typeboxCheckoutSessionSchema, {
108
+ id: 'test',
109
+ customerId: 'test',
110
+ paymentMethods: [DummyEnum.A, DummyEnum.B],
111
+ successRedirectUri: 'https://example.com',
112
+ cancelRedirectUri: 'https://example.com',
113
+ extraFields: {
114
+ test: 'test'
115
+ }
116
+ }))).toBeTruthy();
117
+ });
118
+ it('should be equal for payment link', () => {
119
+ expect(isTrue(testSchemaEquality(zodCreatePaymentLinkSchema, typeboxCreatePaymentLinkSchema, {
120
+ amount: 100,
121
+ currency: DummyEnum.A,
122
+ successRedirectUri: 'https://example.com',
123
+ cancelRedirectUri: 'https://example.com',
124
+ description: 'test',
125
+ metadata: {
126
+ test: 'test'
127
+ },
128
+ extraFields: {
129
+ test: 'test'
130
+ }
131
+ }))).toBeTruthy();
132
+ expect(isTrue(testSchemaEquality(zodUpdatePaymentLinkSchema, typeboxUpdatePaymentLinkSchema, {
133
+ id: 'test',
134
+ amount: 100,
135
+ currency: DummyEnum.A,
136
+ successRedirectUri: 'https://example.com',
137
+ cancelRedirectUri: 'https://example.com',
138
+ description: 'test',
139
+ metadata: {
140
+ test: 'test'
141
+ },
142
+ extraFields: {
143
+ test: 'test'
144
+ }
145
+ })));
146
+ expect(isTrue(testSchemaEquality(zodPaymentLinkSchema, typeboxPaymentLinkSchema, {
147
+ id: 'test',
148
+ amount: 100,
149
+ currency: DummyEnum.A,
150
+ successRedirectUri: 'https://example.com',
151
+ cancelRedirectUri: 'https://example.com',
152
+ description: 'test',
153
+ metadata: {
154
+ test: 'test'
155
+ },
156
+ extraFields: {
157
+ test: 'test'
158
+ }
159
+ }))).toBeTruthy();
160
+ });
161
+ it('should be equal for plan', () => {
162
+ expect(isTrue(testSchemaEquality(zodCreatePlanSchema, typeboxCreatePlanSchema, {
163
+ name: 'test',
164
+ price: 100,
165
+ cadence: DummyEnum.A,
166
+ features: [DummyEnum.A, DummyEnum.B],
167
+ externalId: 'test',
168
+ active: true,
169
+ description: 'test',
170
+ extraFields: {
171
+ test: 'test'
172
+ }
173
+ }))).toBeTruthy();
174
+ expect(isTrue(testSchemaEquality(zodUpdatePlanSchema, typeboxUpdatePlanSchema, {
175
+ id: 'test',
176
+ name: 'test',
177
+ price: 100,
178
+ cadence: DummyEnum.A,
179
+ features: [DummyEnum.A, DummyEnum.B],
180
+ externalId: 'test',
181
+ active: true,
182
+ description: 'test',
183
+ extraFields: {
184
+ test: 'test'
185
+ }
186
+ }))).toBeTruthy();
187
+ expect(isTrue(testSchemaEquality(zodPlanSchema, typeboxPlanSchema, {
188
+ id: 'test',
189
+ name: 'test',
190
+ price: 100,
191
+ cadence: DummyEnum.A,
192
+ features: [DummyEnum.A, DummyEnum.B],
193
+ externalId: 'test',
194
+ active: true,
195
+ description: 'test',
196
+ extraFields: {
197
+ test: 'test'
198
+ }
199
+ }))).toBeTruthy();
200
+ });
201
+ it('should be equal for subscription', () => {
202
+ expect(isTrue(testSchemaEquality(zodCreateSubscriptionSchema, typeboxCreateSubscriptionSchema, {
203
+ partyId: 'test',
204
+ partyType: DummyEnum.A,
205
+ productId: 'test',
206
+ status: DummyEnum.A,
207
+ active: true,
208
+ externalId: 'test',
209
+ startDate: new Date(),
210
+ endDate: new Date(),
211
+ description: 'test',
212
+ extraFields: {
213
+ test: 'test'
214
+ },
215
+ billingProvider: DummyEnum.A
216
+ }))).toBeTruthy();
217
+ expect(isTrue(testSchemaEquality(zodUpdateSubscriptionSchema, typeboxUpdateSubscriptionSchema, {
218
+ id: 'test',
219
+ partyId: 'test',
220
+ partyType: DummyEnum.A,
221
+ productId: 'test',
222
+ status: DummyEnum.A,
223
+ active: true,
224
+ externalId: 'test',
225
+ startDate: new Date(),
226
+ endDate: new Date(),
227
+ description: 'test',
228
+ extraFields: {
229
+ test: 'test'
230
+ },
231
+ billingProvider: DummyEnum.A
232
+ }))).toBeTruthy();
233
+ expect(isTrue(testSchemaEquality(zodSubscriptionSchema, typeboxSubscriptionSchema, {
234
+ id: 'test',
235
+ partyId: 'test',
236
+ partyType: DummyEnum.A,
237
+ productId: 'test',
238
+ status: DummyEnum.A,
239
+ active: true,
240
+ externalId: 'test',
241
+ startDate: new Date(),
242
+ endDate: new Date(),
243
+ description: 'test',
244
+ extraFields: {
245
+ test: 'test'
246
+ },
247
+ billingProvider: DummyEnum.A
248
+ }))).toBeTruthy();
249
+ });
250
+ });
@@ -0,0 +1,37 @@
1
+ import {
2
+ date,
3
+ optional,
4
+ string,
5
+ unknown,
6
+ uuid
7
+ } from '@{{app_name}}/core';
8
+
9
+ export const CreateBillingPortalSchema = {
10
+ customerId: string,
11
+ uri: string,
12
+ expiresAt: date
13
+ };
14
+
15
+ export const UpdateBillingPortalSchema = ({ uuidId }: { uuidId: boolean }) => ({
16
+ id: uuidId ? uuid : string,
17
+ uri: optional(string),
18
+ expiresAt: optional(date)
19
+ });
20
+
21
+ export const BillingPortalSchema = ({ uuidId }: { uuidId: boolean }) => ({
22
+ id: uuidId ? uuid : string,
23
+ customerId: string,
24
+ uri: string,
25
+ expiresAt: date,
26
+ extraFields: optional(unknown),
27
+ createdAt: optional(date),
28
+ updatedAt: optional(date)
29
+ });
30
+
31
+ export const BaseBillingPortalServiceSchemas = (options: {
32
+ uuidId: boolean;
33
+ }) => ({
34
+ CreateBillingPortalSchema,
35
+ UpdateBillingPortalSchema: UpdateBillingPortalSchema(options),
36
+ BillingPortalSchema: BillingPortalSchema(options)
37
+ });
@@ -0,0 +1,55 @@
1
+ import { LiteralSchema } from '@forklaunch/validator';
2
+ import {
3
+ array,
4
+ date,
5
+ enum_,
6
+ optional,
7
+ string,
8
+ unknown,
9
+ uuid
10
+ } from '@{{app_name}}/core';
11
+
12
+ export const CreateCheckoutSessionSchema = <
13
+ T extends Record<string, LiteralSchema>
14
+ >(
15
+ PaymentMethodEnum: T
16
+ ) => ({
17
+ customerId: string,
18
+ paymentMethods: array(enum_(PaymentMethodEnum)),
19
+ successRedirectUri: string,
20
+ cancelRedirectUri: string,
21
+ extraFields: optional(unknown)
22
+ });
23
+
24
+ export const UpdateCheckoutSessionSchema =
25
+ ({ uuidId }: { uuidId: boolean }) =>
26
+ <T extends Record<string, LiteralSchema>>(PaymentMethodEnum: T) => ({
27
+ id: uuidId ? uuid : string,
28
+ customerId: optional(string),
29
+ paymentMethods: optional(array(enum_(PaymentMethodEnum))),
30
+ successRedirectUri: optional(string),
31
+ cancelRedirectUri: optional(string),
32
+ extraFields: optional(unknown)
33
+ });
34
+
35
+ export const CheckoutSessionSchema =
36
+ ({ uuidId }: { uuidId: boolean }) =>
37
+ <T extends Record<string, LiteralSchema>>(PaymentMethodEnum: T) => ({
38
+ id: uuidId ? uuid : string,
39
+ customerId: string,
40
+ metadata: optional(unknown),
41
+ paymentMethods: array(enum_(PaymentMethodEnum)),
42
+ successRedirectUri: string,
43
+ cancelRedirectUri: string,
44
+ extraFields: optional(unknown),
45
+ createdAt: optional(date),
46
+ updatedAt: optional(date)
47
+ });
48
+
49
+ export const BaseCheckoutSessionServiceSchemas = (options: {
50
+ uuidId: boolean;
51
+ }) => ({
52
+ CreateCheckoutSessionSchema,
53
+ UpdateCheckoutSessionSchema: UpdateCheckoutSessionSchema(options),
54
+ CheckoutSessionSchema: CheckoutSessionSchema(options)
55
+ });
@@ -0,0 +1,5 @@
1
+ export * from './billingPortal.schema';
2
+ export * from './checkoutSession.schema';
3
+ export * from './paymentLink.schema';
4
+ export * from './plan.schema';
5
+ export * from './subscription.schema';
@@ -0,0 +1,60 @@
1
+ import { LiteralSchema } from '@forklaunch/validator';
2
+ import {
3
+ date,
4
+ enum_,
5
+ number,
6
+ optional,
7
+ string,
8
+ unknown,
9
+ uuid
10
+ } from '@{{app_name}}/core';
11
+
12
+ export const CreatePaymentLinkSchema = <
13
+ T extends Record<string, LiteralSchema>
14
+ >(
15
+ CurrencyEnum: T
16
+ ) => ({
17
+ amount: number,
18
+ currency: enum_(CurrencyEnum),
19
+ description: optional(string),
20
+ metadata: optional(unknown),
21
+ successRedirectUri: string,
22
+ cancelRedirectUri: string,
23
+ extraFields: optional(unknown)
24
+ });
25
+
26
+ export const UpdatePaymentLinkSchema =
27
+ ({ uuidId }: { uuidId: boolean }) =>
28
+ <T extends Record<string, LiteralSchema>>(CurrencyEnum: T) => ({
29
+ id: uuidId ? uuid : string,
30
+ amount: optional(number),
31
+ currency: optional(enum_(CurrencyEnum)),
32
+ description: optional(string),
33
+ metadata: optional(unknown),
34
+ successRedirectUri: optional(string),
35
+ cancelRedirectUri: optional(string),
36
+ extraFields: optional(unknown)
37
+ });
38
+
39
+ export const PaymentLinkSchema =
40
+ ({ uuidId }: { uuidId: boolean }) =>
41
+ <T extends Record<string, LiteralSchema>>(CurrencyEnum: T) => ({
42
+ id: uuidId ? uuid : string,
43
+ amount: number,
44
+ currency: enum_(CurrencyEnum),
45
+ description: optional(string),
46
+ metadata: optional(unknown),
47
+ successRedirectUri: string,
48
+ cancelRedirectUri: string,
49
+ extraFields: optional(unknown),
50
+ createdAt: optional(date),
51
+ updatedAt: optional(date)
52
+ });
53
+
54
+ export const BasePaymentLinkServiceSchemas = (options: {
55
+ uuidId: boolean;
56
+ }) => ({
57
+ CreatePaymentLinkSchema,
58
+ UpdatePaymentLinkSchema: UpdatePaymentLinkSchema(options),
59
+ PaymentLinkSchema: PaymentLinkSchema(options)
60
+ });
@@ -0,0 +1,80 @@
1
+ import { LiteralSchema } from '@forklaunch/validator';
2
+ import {
3
+ array,
4
+ boolean,
5
+ date,
6
+ enum_,
7
+ number,
8
+ optional,
9
+ string,
10
+ unknown,
11
+ uuid
12
+ } from '@{{app_name}}/core';
13
+
14
+ export const CreatePlanSchema = <
15
+ T extends Record<string, LiteralSchema>,
16
+ U extends Record<string, LiteralSchema>
17
+ >(
18
+ PlanCadenceEnum: T,
19
+ BillingProviderEnum: U
20
+ ) => ({
21
+ name: string,
22
+ description: optional(string),
23
+ price: number,
24
+ cadence: enum_(PlanCadenceEnum),
25
+ features: array(string),
26
+ extraFields: optional(unknown),
27
+ externalId: string,
28
+ billingProvider: optional(enum_(BillingProviderEnum)),
29
+ active: boolean
30
+ });
31
+
32
+ export const UpdatePlanSchema =
33
+ ({ uuidId }: { uuidId: boolean }) =>
34
+ <
35
+ T extends Record<string, LiteralSchema>,
36
+ U extends Record<string, LiteralSchema>
37
+ >(
38
+ PlanCadenceEnum: T,
39
+ BillingProviderEnum: U
40
+ ) => ({
41
+ id: uuidId ? uuid : string,
42
+ name: optional(string),
43
+ description: optional(string),
44
+ price: optional(number),
45
+ cadence: optional(enum_(PlanCadenceEnum)),
46
+ features: optional(array(string)),
47
+ extraFields: optional(unknown),
48
+ externalId: optional(string),
49
+ billingProvider: optional(enum_(BillingProviderEnum)),
50
+ active: optional(boolean)
51
+ });
52
+
53
+ export const PlanSchema =
54
+ ({ uuidId }: { uuidId: boolean }) =>
55
+ <
56
+ T extends Record<string, LiteralSchema>,
57
+ U extends Record<string, LiteralSchema>
58
+ >(
59
+ PlanCadenceEnum: T,
60
+ BillingProviderEnum: U
61
+ ) => ({
62
+ id: uuidId ? uuid : string,
63
+ name: string,
64
+ description: optional(string),
65
+ price: number,
66
+ cadence: enum_(PlanCadenceEnum),
67
+ features: optional(array(string)),
68
+ extraFields: optional(unknown),
69
+ externalId: string,
70
+ billingProvider: optional(enum_(BillingProviderEnum)),
71
+ active: boolean,
72
+ createdAt: optional(date),
73
+ updatedAt: optional(date)
74
+ });
75
+
76
+ export const BasePlanServiceSchemas = (options: { uuidId: boolean }) => ({
77
+ CreatePlanSchema,
78
+ UpdatePlanSchema: UpdatePlanSchema(options),
79
+ PlanSchema: PlanSchema(options)
80
+ });
@@ -0,0 +1,86 @@
1
+ import { LiteralSchema } from '@forklaunch/validator';
2
+ import {
3
+ boolean,
4
+ date,
5
+ enum_,
6
+ optional,
7
+ string,
8
+ unknown,
9
+ uuid
10
+ } from '@{{app_name}}/core';
11
+
12
+ export const CreateSubscriptionSchema = <
13
+ T extends Record<string, LiteralSchema>,
14
+ U extends Record<string, LiteralSchema>
15
+ >(
16
+ PartyEnum: T,
17
+ BillingProviderEnum: U
18
+ ) => ({
19
+ partyId: string,
20
+ partyType: enum_(PartyEnum),
21
+ productId: string,
22
+ description: optional(string),
23
+ active: boolean,
24
+ externalId: string,
25
+ startDate: date,
26
+ endDate: date,
27
+ status: string,
28
+ billingProvider: optional(enum_(BillingProviderEnum)),
29
+ extraFields: optional(unknown)
30
+ });
31
+
32
+ export const UpdateSubscriptionSchema =
33
+ ({ uuidId }: { uuidId: boolean }) =>
34
+ <
35
+ T extends Record<string, LiteralSchema>,
36
+ U extends Record<string, LiteralSchema>
37
+ >(
38
+ PartyEnum: T,
39
+ BillingProviderEnum: U
40
+ ) => ({
41
+ id: uuidId ? uuid : string,
42
+ partyId: optional(string),
43
+ partyType: optional(enum_(PartyEnum)),
44
+ productId: optional(string),
45
+ description: optional(string),
46
+ active: optional(boolean),
47
+ externalId: optional(string),
48
+ startDate: optional(date),
49
+ endDate: optional(date),
50
+ status: optional(string),
51
+ billingProvider: optional(enum_(BillingProviderEnum)),
52
+ extraFields: optional(unknown)
53
+ });
54
+
55
+ export const SubscriptionSchema =
56
+ ({ uuidId }: { uuidId: boolean }) =>
57
+ <
58
+ T extends Record<string, LiteralSchema>,
59
+ U extends Record<string, LiteralSchema>
60
+ >(
61
+ PartyEnum: T,
62
+ BillingProviderEnum: U
63
+ ) => ({
64
+ id: uuidId ? uuid : string,
65
+ partyId: string,
66
+ partyType: enum_(PartyEnum),
67
+ productId: string,
68
+ description: optional(string),
69
+ active: boolean,
70
+ externalId: string,
71
+ startDate: date,
72
+ endDate: date,
73
+ status: string,
74
+ billingProvider: optional(enum_(BillingProviderEnum)),
75
+ extraFields: optional(unknown),
76
+ createdAt: optional(date),
77
+ updatedAt: optional(date)
78
+ });
79
+
80
+ export const BaseSubscriptionServiceSchemas = (options: {
81
+ uuidId: boolean;
82
+ }) => ({
83
+ CreateSubscriptionSchema,
84
+ UpdateSubscriptionSchema: UpdateSubscriptionSchema(options),
85
+ SubscriptionSchema: SubscriptionSchema(options)
86
+ });