@forklaunch/implementation-billing-base 0.1.11 → 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 (51) hide show
  1. package/lib/__test__/schemaEquality.test.d.ts +1 -1
  2. package/lib/__test__/schemaEquality.test.js +146 -305
  3. package/lib/eject/domain/schemas/billingPortal.schema.ts +7 -1
  4. package/lib/jest.config.d.ts +1 -1
  5. package/lib/jest.config.js +16 -16
  6. package/lib/schemas/billingPortal.schema.d.ts +34 -107
  7. package/lib/schemas/billingPortal.schema.js +1 -4
  8. package/lib/schemas/checkoutSession.schema.d.ts +54 -169
  9. package/lib/schemas/checkoutSession.schema.js +1 -4
  10. package/lib/schemas/index.d.ts +1 -1
  11. package/lib/schemas/paymentLink.schema.d.ts +64 -210
  12. package/lib/schemas/paymentLink.schema.js +1 -4
  13. package/lib/schemas/plan.schema.d.ts +76 -326
  14. package/lib/schemas/plan.schema.js +1 -4
  15. package/lib/schemas/subscription.schema.d.ts +88 -364
  16. package/lib/schemas/subscription.schema.js +1 -4
  17. package/lib/schemas/typebox/billingPortal.schema.d.ts +38 -172
  18. package/lib/schemas/typebox/billingPortal.schema.js +17 -23
  19. package/lib/schemas/typebox/checkoutSession.schema.d.ts +55 -197
  20. package/lib/schemas/typebox/checkoutSession.schema.js +13 -25
  21. package/lib/schemas/typebox/paymentLink.schema.d.ts +65 -275
  22. package/lib/schemas/typebox/paymentLink.schema.js +15 -27
  23. package/lib/schemas/typebox/plan.schema.d.ts +77 -409
  24. package/lib/schemas/typebox/plan.schema.js +17 -31
  25. package/lib/schemas/typebox/subscription.schema.d.ts +89 -481
  26. package/lib/schemas/typebox/subscription.schema.js +19 -31
  27. package/lib/schemas/zod/billingPortal.schema.d.ts +38 -42
  28. package/lib/schemas/zod/billingPortal.schema.js +17 -23
  29. package/lib/schemas/zod/checkoutSession.schema.d.ts +55 -107
  30. package/lib/schemas/zod/checkoutSession.schema.js +13 -25
  31. package/lib/schemas/zod/paymentLink.schema.d.ts +65 -99
  32. package/lib/schemas/zod/paymentLink.schema.js +15 -27
  33. package/lib/schemas/zod/plan.schema.d.ts +77 -177
  34. package/lib/schemas/zod/plan.schema.js +17 -31
  35. package/lib/schemas/zod/subscription.schema.d.ts +89 -181
  36. package/lib/schemas/zod/subscription.schema.js +19 -31
  37. package/lib/services/billingPortal.service.d.ts +28 -77
  38. package/lib/services/billingPortal.service.js +45 -64
  39. package/lib/services/checkoutSession.service.d.ts +29 -77
  40. package/lib/services/checkoutSession.service.js +43 -54
  41. package/lib/services/index.d.ts +1 -1
  42. package/lib/services/paymentLink.service.d.ts +32 -82
  43. package/lib/services/paymentLink.service.js +66 -84
  44. package/lib/services/plan.service.d.ts +26 -73
  45. package/lib/services/plan.service.js +40 -45
  46. package/lib/services/subscription.service.d.ts +44 -136
  47. package/lib/services/subscription.service.js +88 -111
  48. package/lib/tsconfig.tsbuildinfo +1 -1
  49. package/lib/vitest.config.d.ts +2 -2
  50. package/lib/vitest.config.js +4 -4
  51. package/package.json +5 -5
@@ -1,28 +1,18 @@
1
- import {
2
- boolean,
3
- date,
4
- enum_,
5
- optional,
6
- string,
7
- unknown,
8
- uuid
9
- } from '@forklaunch/validator/zod';
1
+ import { boolean, date, enum_, optional, string, unknown, uuid } from '@forklaunch/validator/zod';
10
2
  export const CreateSubscriptionSchema = (PartyEnum, BillingProviderEnum) => ({
11
- partyId: string,
12
- partyType: enum_(PartyEnum),
13
- productId: string,
14
- description: optional(string),
15
- active: boolean,
16
- externalId: string,
17
- startDate: date,
18
- endDate: date,
19
- status: string,
20
- billingProvider: optional(enum_(BillingProviderEnum)),
21
- extraFields: optional(unknown)
3
+ partyId: string,
4
+ partyType: enum_(PartyEnum),
5
+ productId: string,
6
+ description: optional(string),
7
+ active: boolean,
8
+ externalId: string,
9
+ startDate: date,
10
+ endDate: date,
11
+ status: string,
12
+ billingProvider: optional(enum_(BillingProviderEnum)),
13
+ extraFields: optional(unknown)
22
14
  });
23
- export const UpdateSubscriptionSchema =
24
- ({ uuidId }) =>
25
- (PartyEnum, BillingProviderEnum) => ({
15
+ export const UpdateSubscriptionSchema = ({ uuidId }) => (PartyEnum, BillingProviderEnum) => ({
26
16
  id: uuidId ? uuid : string,
27
17
  partyId: optional(string),
28
18
  partyType: optional(enum_(PartyEnum)),
@@ -35,10 +25,8 @@ export const UpdateSubscriptionSchema =
35
25
  status: optional(string),
36
26
  billingProvider: optional(enum_(BillingProviderEnum)),
37
27
  extraFields: optional(unknown)
38
- });
39
- export const SubscriptionSchema =
40
- ({ uuidId }) =>
41
- (PartyEnum, BillingProviderEnum) => ({
28
+ });
29
+ export const SubscriptionSchema = ({ uuidId }) => (PartyEnum, BillingProviderEnum) => ({
42
30
  id: uuidId ? uuid : string,
43
31
  partyId: string,
44
32
  partyType: enum_(PartyEnum),
@@ -53,9 +41,9 @@ export const SubscriptionSchema =
53
41
  extraFields: optional(unknown),
54
42
  createdAt: optional(date),
55
43
  updatedAt: optional(date)
56
- });
44
+ });
57
45
  export const BaseSubscriptionServiceSchemas = (options) => ({
58
- CreateSubscriptionSchema,
59
- UpdateSubscriptionSchema: UpdateSubscriptionSchema(options),
60
- SubscriptionSchema: SubscriptionSchema(options)
46
+ CreateSubscriptionSchema,
47
+ UpdateSubscriptionSchema: UpdateSubscriptionSchema(options),
48
+ SubscriptionSchema: SubscriptionSchema(options)
61
49
  });
@@ -1,94 +1,45 @@
1
1
  import { IdDto } from '@forklaunch/common';
2
2
  import { TtlCache } from '@forklaunch/core/cache';
3
- import {
4
- RequestDtoMapperConstructor,
5
- ResponseDtoMapperConstructor
6
- } from '@forklaunch/core/mappers';
7
- import {
8
- MetricsDefinition,
9
- OpenTelemetryCollector
10
- } from '@forklaunch/core/http';
3
+ import { RequestDtoMapperConstructor, ResponseDtoMapperConstructor } from '@forklaunch/core/mappers';
4
+ import { MetricsDefinition, OpenTelemetryCollector } from '@forklaunch/core/http';
11
5
  import { BillingPortalService } from '@forklaunch/interfaces-billing/interfaces';
12
- import {
13
- BillingPortalDto,
14
- CreateBillingPortalDto,
15
- UpdateBillingPortalDto
16
- } from '@forklaunch/interfaces-billing/types';
6
+ import { BillingPortalDto, CreateBillingPortalDto, UpdateBillingPortalDto } from '@forklaunch/interfaces-billing/types';
17
7
  import { AnySchemaValidator } from '@forklaunch/validator';
18
- export declare class BaseBillingPortalService<
19
- SchemaValidator extends AnySchemaValidator,
20
- Metrics extends MetricsDefinition = MetricsDefinition,
21
- Dto extends {
8
+ export declare class BaseBillingPortalService<SchemaValidator extends AnySchemaValidator, Metrics extends MetricsDefinition = MetricsDefinition, Dto extends {
22
9
  BillingPortalDtoMapper: BillingPortalDto;
23
10
  CreateBillingPortalDtoMapper: CreateBillingPortalDto;
24
11
  UpdateBillingPortalDtoMapper: UpdateBillingPortalDto;
25
- } = {
12
+ } = {
26
13
  BillingPortalDtoMapper: BillingPortalDto;
27
14
  CreateBillingPortalDtoMapper: CreateBillingPortalDto;
28
15
  UpdateBillingPortalDtoMapper: UpdateBillingPortalDto;
29
- },
30
- Entities extends {
16
+ }, Entities extends {
31
17
  BillingPortalDtoMapper: BillingPortalDto;
32
18
  CreateBillingPortalDtoMapper: BillingPortalDto;
33
19
  UpdateBillingPortalDtoMapper: BillingPortalDto;
34
- } = {
20
+ } = {
35
21
  BillingPortalDtoMapper: BillingPortalDto;
36
22
  CreateBillingPortalDtoMapper: BillingPortalDto;
37
23
  UpdateBillingPortalDtoMapper: BillingPortalDto;
38
- }
39
- > implements BillingPortalService
40
- {
41
- #private;
42
- protected cache: TtlCache;
43
- protected openTelemetryCollector: OpenTelemetryCollector<Metrics>;
44
- protected schemaValidator: SchemaValidator;
45
- protected mapperss: {
46
- BillingPortalDtoMapper: ResponseDtoMapperConstructor<
47
- SchemaValidator,
48
- Dto['BillingPortalDtoMapper'],
49
- Entities['BillingPortalDtoMapper']
50
- >;
51
- CreateBillingPortalDtoMapper: RequestDtoMapperConstructor<
52
- SchemaValidator,
53
- Dto['CreateBillingPortalDtoMapper'],
54
- Entities['CreateBillingPortalDtoMapper']
55
- >;
56
- UpdateBillingPortalDtoMapper: RequestDtoMapperConstructor<
57
- SchemaValidator,
58
- Dto['UpdateBillingPortalDtoMapper'],
59
- Entities['UpdateBillingPortalDtoMapper']
60
- >;
61
- };
62
- constructor(
63
- cache: TtlCache,
64
- openTelemetryCollector: OpenTelemetryCollector<Metrics>,
65
- schemaValidator: SchemaValidator,
66
- mapperss: {
67
- BillingPortalDtoMapper: ResponseDtoMapperConstructor<
68
- SchemaValidator,
69
- Dto['BillingPortalDtoMapper'],
70
- Entities['BillingPortalDtoMapper']
71
- >;
72
- CreateBillingPortalDtoMapper: RequestDtoMapperConstructor<
73
- SchemaValidator,
74
- Dto['CreateBillingPortalDtoMapper'],
75
- Entities['CreateBillingPortalDtoMapper']
76
- >;
77
- UpdateBillingPortalDtoMapper: RequestDtoMapperConstructor<
78
- SchemaValidator,
79
- Dto['UpdateBillingPortalDtoMapper'],
80
- Entities['UpdateBillingPortalDtoMapper']
81
- >;
82
- }
83
- );
84
- protected createCacheKey: (id: string) => string;
85
- createBillingPortalSession(
86
- billingPortalDto: Dto['CreateBillingPortalDtoMapper']
87
- ): Promise<Dto['BillingPortalDtoMapper']>;
88
- getBillingPortalSession(idDto: IdDto): Promise<Dto['BillingPortalDtoMapper']>;
89
- updateBillingPortalSession(
90
- billingPortalDto: UpdateBillingPortalDto
91
- ): Promise<Dto['BillingPortalDtoMapper']>;
92
- expireBillingPortalSession(idDto: IdDto): Promise<void>;
24
+ }> implements BillingPortalService {
25
+ #private;
26
+ protected cache: TtlCache;
27
+ protected openTelemetryCollector: OpenTelemetryCollector<Metrics>;
28
+ protected schemaValidator: SchemaValidator;
29
+ protected mapperss: {
30
+ BillingPortalDtoMapper: ResponseDtoMapperConstructor<SchemaValidator, Dto['BillingPortalDtoMapper'], Entities['BillingPortalDtoMapper']>;
31
+ CreateBillingPortalDtoMapper: RequestDtoMapperConstructor<SchemaValidator, Dto['CreateBillingPortalDtoMapper'], Entities['CreateBillingPortalDtoMapper']>;
32
+ UpdateBillingPortalDtoMapper: RequestDtoMapperConstructor<SchemaValidator, Dto['UpdateBillingPortalDtoMapper'], Entities['UpdateBillingPortalDtoMapper']>;
33
+ };
34
+ constructor(cache: TtlCache, openTelemetryCollector: OpenTelemetryCollector<Metrics>, schemaValidator: SchemaValidator, mapperss: {
35
+ BillingPortalDtoMapper: ResponseDtoMapperConstructor<SchemaValidator, Dto['BillingPortalDtoMapper'], Entities['BillingPortalDtoMapper']>;
36
+ CreateBillingPortalDtoMapper: RequestDtoMapperConstructor<SchemaValidator, Dto['CreateBillingPortalDtoMapper'], Entities['CreateBillingPortalDtoMapper']>;
37
+ UpdateBillingPortalDtoMapper: RequestDtoMapperConstructor<SchemaValidator, Dto['UpdateBillingPortalDtoMapper'], Entities['UpdateBillingPortalDtoMapper']>;
38
+ });
39
+ protected createCacheKey: (id: string) => string;
40
+ createBillingPortalSession(billingPortalDto: Dto['CreateBillingPortalDtoMapper']): Promise<Dto['BillingPortalDtoMapper']>;
41
+ getBillingPortalSession(idDto: IdDto): Promise<Dto['BillingPortalDtoMapper']>;
42
+ updateBillingPortalSession(billingPortalDto: UpdateBillingPortalDto): Promise<Dto['BillingPortalDtoMapper']>;
43
+ expireBillingPortalSession(idDto: IdDto): Promise<void>;
93
44
  }
94
- //# sourceMappingURL=billingPortal.service.d.ts.map
45
+ //# sourceMappingURL=billingPortal.service.d.ts.map
@@ -1,70 +1,51 @@
1
1
  import { createCacheKey } from '@forklaunch/core/cache';
2
2
  import { transformIntoInternalDtoMapper } from '@forklaunch/core/mappers';
3
3
  export class BaseBillingPortalService {
4
- cache;
5
- openTelemetryCollector;
6
- schemaValidator;
7
- mapperss;
8
- #mapperss;
9
- constructor(cache, openTelemetryCollector, schemaValidator, mapperss) {
10
- this.cache = cache;
11
- this.openTelemetryCollector = openTelemetryCollector;
12
- this.schemaValidator = schemaValidator;
13
- this.mapperss = mapperss;
14
- this.#mapperss = transformIntoInternalDtoMapper(mapperss, schemaValidator);
15
- }
16
- createCacheKey = createCacheKey('billing_portal_session');
17
- async createBillingPortalSession(billingPortalDto) {
18
- const billingPortalSession =
19
- this.#mapperss.CreateBillingPortalDtoMapper.deserializeDtoToEntity(
20
- billingPortalDto
21
- );
22
- this.openTelemetryCollector.debug(
23
- 'Create billing portal session',
24
- billingPortalSession
25
- );
26
- await this.cache.putRecord({
27
- key: this.createCacheKey(billingPortalSession.id),
28
- value: billingPortalSession,
29
- ttlMilliseconds: this.cache.getTtlMilliseconds()
30
- });
31
- return this.#mapperss.BillingPortalDtoMapper.serializeEntityToDto(
32
- billingPortalSession
33
- );
34
- }
35
- async getBillingPortalSession(idDto) {
36
- const billingPortalSessionDetails = await this.cache.readRecord(
37
- this.createCacheKey(idDto.id)
38
- );
39
- if (!billingPortalSessionDetails) {
40
- throw new Error('Session not found');
4
+ cache;
5
+ openTelemetryCollector;
6
+ schemaValidator;
7
+ mapperss;
8
+ #mapperss;
9
+ constructor(cache, openTelemetryCollector, schemaValidator, mapperss) {
10
+ this.cache = cache;
11
+ this.openTelemetryCollector = openTelemetryCollector;
12
+ this.schemaValidator = schemaValidator;
13
+ this.mapperss = mapperss;
14
+ this.#mapperss = transformIntoInternalDtoMapper(mapperss, schemaValidator);
41
15
  }
42
- return this.#mapperss.BillingPortalDtoMapper.serializeEntityToDto(
43
- billingPortalSessionDetails.value
44
- );
45
- }
46
- async updateBillingPortalSession(billingPortalDto) {
47
- const billingPortalSession =
48
- this.#mapperss.UpdateBillingPortalDtoMapper.deserializeDtoToEntity(
49
- billingPortalDto
50
- );
51
- // Save the updated session to your database or external service
52
- await this.cache.putRecord({
53
- key: this.createCacheKey(billingPortalSession.id),
54
- value: billingPortalSession,
55
- ttlMilliseconds: this.cache.getTtlMilliseconds()
56
- });
57
- return this.#mapperss.BillingPortalDtoMapper.serializeEntityToDto(
58
- billingPortalSession
59
- );
60
- }
61
- async expireBillingPortalSession(idDto) {
62
- const sessionExists = await this.cache.readRecord(
63
- this.createCacheKey(idDto.id)
64
- );
65
- if (!sessionExists) {
66
- throw new Error('Session not found');
16
+ createCacheKey = createCacheKey('billing_portal_session');
17
+ async createBillingPortalSession(billingPortalDto) {
18
+ const billingPortalSession = this.#mapperss.CreateBillingPortalDtoMapper.deserializeDtoToEntity(billingPortalDto);
19
+ this.openTelemetryCollector.debug('Create billing portal session', billingPortalSession);
20
+ await this.cache.putRecord({
21
+ key: this.createCacheKey(billingPortalSession.id),
22
+ value: billingPortalSession,
23
+ ttlMilliseconds: this.cache.getTtlMilliseconds()
24
+ });
25
+ return this.#mapperss.BillingPortalDtoMapper.serializeEntityToDto(billingPortalSession);
26
+ }
27
+ async getBillingPortalSession(idDto) {
28
+ const billingPortalSessionDetails = await this.cache.readRecord(this.createCacheKey(idDto.id));
29
+ if (!billingPortalSessionDetails) {
30
+ throw new Error('Session not found');
31
+ }
32
+ return this.#mapperss.BillingPortalDtoMapper.serializeEntityToDto(billingPortalSessionDetails.value);
33
+ }
34
+ async updateBillingPortalSession(billingPortalDto) {
35
+ const billingPortalSession = this.#mapperss.UpdateBillingPortalDtoMapper.deserializeDtoToEntity(billingPortalDto);
36
+ // Save the updated session to your database or external service
37
+ await this.cache.putRecord({
38
+ key: this.createCacheKey(billingPortalSession.id),
39
+ value: billingPortalSession,
40
+ ttlMilliseconds: this.cache.getTtlMilliseconds()
41
+ });
42
+ return this.#mapperss.BillingPortalDtoMapper.serializeEntityToDto(billingPortalSession);
43
+ }
44
+ async expireBillingPortalSession(idDto) {
45
+ const sessionExists = await this.cache.readRecord(this.createCacheKey(idDto.id));
46
+ if (!sessionExists) {
47
+ throw new Error('Session not found');
48
+ }
49
+ await this.cache.deleteRecord(this.createCacheKey(idDto.id));
67
50
  }
68
- await this.cache.deleteRecord(this.createCacheKey(idDto.id));
69
- }
70
51
  }
@@ -1,94 +1,46 @@
1
1
  import { IdDto } from '@forklaunch/common';
2
2
  import { TtlCache } from '@forklaunch/core/cache';
3
- import {
4
- RequestDtoMapperConstructor,
5
- ResponseDtoMapperConstructor
6
- } from '@forklaunch/core/mappers';
7
- import {
8
- MetricsDefinition,
9
- OpenTelemetryCollector
10
- } from '@forklaunch/core/http';
3
+ import { RequestDtoMapperConstructor, ResponseDtoMapperConstructor } from '@forklaunch/core/mappers';
4
+ import { MetricsDefinition, OpenTelemetryCollector } from '@forklaunch/core/http';
11
5
  import { CheckoutSessionService } from '@forklaunch/interfaces-billing/interfaces';
12
- import {
13
- CheckoutSessionDto,
14
- CreateCheckoutSessionDto,
15
- UpdateCheckoutSessionDto
16
- } from '@forklaunch/interfaces-billing/types';
6
+ import { CheckoutSessionDto, CreateCheckoutSessionDto, UpdateCheckoutSessionDto } from '@forklaunch/interfaces-billing/types';
17
7
  import { AnySchemaValidator } from '@forklaunch/validator';
18
- export declare class BaseCheckoutSessionService<
19
- SchemaValidator extends AnySchemaValidator,
20
- PaymentMethodEnum,
21
- Metrics extends MetricsDefinition = MetricsDefinition,
22
- Dto extends {
8
+ export declare class BaseCheckoutSessionService<SchemaValidator extends AnySchemaValidator, PaymentMethodEnum, Metrics extends MetricsDefinition = MetricsDefinition, Dto extends {
23
9
  CheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
24
10
  CreateCheckoutSessionDtoMapper: CreateCheckoutSessionDto<PaymentMethodEnum>;
25
11
  UpdateCheckoutSessionDtoMapper: UpdateCheckoutSessionDto<PaymentMethodEnum>;
26
- } = {
12
+ } = {
27
13
  CheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
28
14
  CreateCheckoutSessionDtoMapper: CreateCheckoutSessionDto<PaymentMethodEnum>;
29
15
  UpdateCheckoutSessionDtoMapper: UpdateCheckoutSessionDto<PaymentMethodEnum>;
30
- },
31
- Entities extends {
16
+ }, Entities extends {
32
17
  CheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
33
18
  CreateCheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
34
19
  UpdateCheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
35
- } = {
20
+ } = {
36
21
  CheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
37
22
  CreateCheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
38
23
  UpdateCheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
39
- }
40
- > implements CheckoutSessionService<PaymentMethodEnum>
41
- {
42
- #private;
43
- protected readonly cache: TtlCache;
44
- protected readonly openTelemetryCollector: OpenTelemetryCollector<Metrics>;
45
- protected readonly schemaValidator: SchemaValidator;
46
- protected readonly mapperss: {
47
- CheckoutSessionDtoMapper: ResponseDtoMapperConstructor<
48
- SchemaValidator,
49
- Dto['CheckoutSessionDtoMapper'],
50
- Entities['CheckoutSessionDtoMapper']
51
- >;
52
- CreateCheckoutSessionDtoMapper: RequestDtoMapperConstructor<
53
- SchemaValidator,
54
- Dto['CreateCheckoutSessionDtoMapper'],
55
- Entities['CreateCheckoutSessionDtoMapper']
56
- >;
57
- UpdateCheckoutSessionDtoMapper: RequestDtoMapperConstructor<
58
- SchemaValidator,
59
- Dto['UpdateCheckoutSessionDtoMapper'],
60
- Entities['UpdateCheckoutSessionDtoMapper']
61
- >;
62
- };
63
- constructor(
64
- cache: TtlCache,
65
- openTelemetryCollector: OpenTelemetryCollector<Metrics>,
66
- schemaValidator: SchemaValidator,
67
- mapperss: {
68
- CheckoutSessionDtoMapper: ResponseDtoMapperConstructor<
69
- SchemaValidator,
70
- Dto['CheckoutSessionDtoMapper'],
71
- Entities['CheckoutSessionDtoMapper']
72
- >;
73
- CreateCheckoutSessionDtoMapper: RequestDtoMapperConstructor<
74
- SchemaValidator,
75
- Dto['CreateCheckoutSessionDtoMapper'],
76
- Entities['CreateCheckoutSessionDtoMapper']
77
- >;
78
- UpdateCheckoutSessionDtoMapper: RequestDtoMapperConstructor<
79
- SchemaValidator,
80
- Dto['UpdateCheckoutSessionDtoMapper'],
81
- Entities['UpdateCheckoutSessionDtoMapper']
82
- >;
83
- }
84
- );
85
- protected createCacheKey: (id: string) => string;
86
- createCheckoutSession(
87
- checkoutSessionDto: Dto['CreateCheckoutSessionDtoMapper']
88
- ): Promise<Dto['CheckoutSessionDtoMapper']>;
89
- getCheckoutSession({ id }: IdDto): Promise<Dto['CheckoutSessionDtoMapper']>;
90
- expireCheckoutSession({ id }: IdDto): Promise<void>;
91
- handleCheckoutSuccess({ id }: IdDto): Promise<void>;
92
- handleCheckoutFailure({ id }: IdDto): Promise<void>;
24
+ }> implements CheckoutSessionService<PaymentMethodEnum> {
25
+ #private;
26
+ protected readonly cache: TtlCache;
27
+ protected readonly openTelemetryCollector: OpenTelemetryCollector<Metrics>;
28
+ protected readonly schemaValidator: SchemaValidator;
29
+ protected readonly mapperss: {
30
+ CheckoutSessionDtoMapper: ResponseDtoMapperConstructor<SchemaValidator, Dto['CheckoutSessionDtoMapper'], Entities['CheckoutSessionDtoMapper']>;
31
+ CreateCheckoutSessionDtoMapper: RequestDtoMapperConstructor<SchemaValidator, Dto['CreateCheckoutSessionDtoMapper'], Entities['CreateCheckoutSessionDtoMapper']>;
32
+ UpdateCheckoutSessionDtoMapper: RequestDtoMapperConstructor<SchemaValidator, Dto['UpdateCheckoutSessionDtoMapper'], Entities['UpdateCheckoutSessionDtoMapper']>;
33
+ };
34
+ constructor(cache: TtlCache, openTelemetryCollector: OpenTelemetryCollector<Metrics>, schemaValidator: SchemaValidator, mapperss: {
35
+ CheckoutSessionDtoMapper: ResponseDtoMapperConstructor<SchemaValidator, Dto['CheckoutSessionDtoMapper'], Entities['CheckoutSessionDtoMapper']>;
36
+ CreateCheckoutSessionDtoMapper: RequestDtoMapperConstructor<SchemaValidator, Dto['CreateCheckoutSessionDtoMapper'], Entities['CreateCheckoutSessionDtoMapper']>;
37
+ UpdateCheckoutSessionDtoMapper: RequestDtoMapperConstructor<SchemaValidator, Dto['UpdateCheckoutSessionDtoMapper'], Entities['UpdateCheckoutSessionDtoMapper']>;
38
+ });
39
+ protected createCacheKey: (id: string) => string;
40
+ createCheckoutSession(checkoutSessionDto: Dto['CreateCheckoutSessionDtoMapper']): Promise<Dto['CheckoutSessionDtoMapper']>;
41
+ getCheckoutSession({ id }: IdDto): Promise<Dto['CheckoutSessionDtoMapper']>;
42
+ expireCheckoutSession({ id }: IdDto): Promise<void>;
43
+ handleCheckoutSuccess({ id }: IdDto): Promise<void>;
44
+ handleCheckoutFailure({ id }: IdDto): Promise<void>;
93
45
  }
94
- //# sourceMappingURL=checkoutSession.service.d.ts.map
46
+ //# sourceMappingURL=checkoutSession.service.d.ts.map
@@ -1,60 +1,49 @@
1
1
  import { createCacheKey } from '@forklaunch/core/cache';
2
2
  import { transformIntoInternalDtoMapper } from '@forklaunch/core/mappers';
3
3
  export class BaseCheckoutSessionService {
4
- cache;
5
- openTelemetryCollector;
6
- schemaValidator;
7
- mapperss;
8
- #mapperss;
9
- constructor(cache, openTelemetryCollector, schemaValidator, mapperss) {
10
- this.cache = cache;
11
- this.openTelemetryCollector = openTelemetryCollector;
12
- this.schemaValidator = schemaValidator;
13
- this.mapperss = mapperss;
14
- this.#mapperss = transformIntoInternalDtoMapper(mapperss, schemaValidator);
15
- }
16
- createCacheKey = createCacheKey('checkout_session');
17
- async createCheckoutSession(checkoutSessionDto) {
18
- const checkoutSession =
19
- this.#mapperss.CreateCheckoutSessionDtoMapper.deserializeDtoToEntity(
20
- checkoutSessionDto
21
- );
22
- // Store the checkoutSession details in the cache
23
- await this.cache.putRecord({
24
- key: this.createCacheKey(checkoutSession.id),
25
- value: checkoutSession,
26
- ttlMilliseconds: this.cache.getTtlMilliseconds()
27
- });
28
- return this.#mapperss.CheckoutSessionDtoMapper.serializeEntityToDto(
29
- checkoutSession
30
- );
31
- }
32
- async getCheckoutSession({ id }) {
33
- const checkoutSessionDetails = await this.cache.readRecord(
34
- this.createCacheKey(id)
35
- );
36
- if (!checkoutSessionDetails) {
37
- throw new Error('Session not found');
4
+ cache;
5
+ openTelemetryCollector;
6
+ schemaValidator;
7
+ mapperss;
8
+ #mapperss;
9
+ constructor(cache, openTelemetryCollector, schemaValidator, mapperss) {
10
+ this.cache = cache;
11
+ this.openTelemetryCollector = openTelemetryCollector;
12
+ this.schemaValidator = schemaValidator;
13
+ this.mapperss = mapperss;
14
+ this.#mapperss = transformIntoInternalDtoMapper(mapperss, schemaValidator);
38
15
  }
39
- return this.#mapperss.CheckoutSessionDtoMapper.serializeEntityToDto(
40
- checkoutSessionDetails.value
41
- );
42
- }
43
- async expireCheckoutSession({ id }) {
44
- const checkoutSessionDetails = await this.cache.readRecord(
45
- this.createCacheKey(id)
46
- );
47
- if (!checkoutSessionDetails) {
48
- throw new Error('Session not found');
16
+ createCacheKey = createCacheKey('checkout_session');
17
+ async createCheckoutSession(checkoutSessionDto) {
18
+ const checkoutSession = this.#mapperss.CreateCheckoutSessionDtoMapper.deserializeDtoToEntity(checkoutSessionDto);
19
+ // Store the checkoutSession details in the cache
20
+ await this.cache.putRecord({
21
+ key: this.createCacheKey(checkoutSession.id),
22
+ value: checkoutSession,
23
+ ttlMilliseconds: this.cache.getTtlMilliseconds()
24
+ });
25
+ return this.#mapperss.CheckoutSessionDtoMapper.serializeEntityToDto(checkoutSession);
26
+ }
27
+ async getCheckoutSession({ id }) {
28
+ const checkoutSessionDetails = await this.cache.readRecord(this.createCacheKey(id));
29
+ if (!checkoutSessionDetails) {
30
+ throw new Error('Session not found');
31
+ }
32
+ return this.#mapperss.CheckoutSessionDtoMapper.serializeEntityToDto(checkoutSessionDetails.value);
33
+ }
34
+ async expireCheckoutSession({ id }) {
35
+ const checkoutSessionDetails = await this.cache.readRecord(this.createCacheKey(id));
36
+ if (!checkoutSessionDetails) {
37
+ throw new Error('Session not found');
38
+ }
39
+ await this.cache.deleteRecord(this.createCacheKey(id));
40
+ }
41
+ async handleCheckoutSuccess({ id }) {
42
+ this.openTelemetryCollector.info('Checkout success', { id });
43
+ await this.cache.deleteRecord(this.createCacheKey(id));
44
+ }
45
+ async handleCheckoutFailure({ id }) {
46
+ this.openTelemetryCollector.info('Checkout failure', { id });
47
+ await this.cache.deleteRecord(this.createCacheKey(id));
49
48
  }
50
- await this.cache.deleteRecord(this.createCacheKey(id));
51
- }
52
- async handleCheckoutSuccess({ id }) {
53
- this.openTelemetryCollector.info('Checkout success', { id });
54
- await this.cache.deleteRecord(this.createCacheKey(id));
55
- }
56
- async handleCheckoutFailure({ id }) {
57
- this.openTelemetryCollector.info('Checkout failure', { id });
58
- await this.cache.deleteRecord(this.createCacheKey(id));
59
- }
60
49
  }
@@ -3,4 +3,4 @@ export * from './checkoutSession.service';
3
3
  export * from './paymentLink.service';
4
4
  export * from './plan.service';
5
5
  export * from './subscription.service';
6
- //# sourceMappingURL=index.d.ts.map
6
+ //# sourceMappingURL=index.d.ts.map