@forklaunch/implementation-billing-base 0.1.13 → 0.1.14

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 +305 -146
  3. package/lib/eject/domain/schemas/billingPortal.schema.ts +1 -7
  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 +107 -34
  7. package/lib/schemas/billingPortal.schema.js +4 -1
  8. package/lib/schemas/checkoutSession.schema.d.ts +169 -54
  9. package/lib/schemas/checkoutSession.schema.js +4 -1
  10. package/lib/schemas/index.d.ts +1 -1
  11. package/lib/schemas/paymentLink.schema.d.ts +210 -64
  12. package/lib/schemas/paymentLink.schema.js +4 -1
  13. package/lib/schemas/plan.schema.d.ts +326 -76
  14. package/lib/schemas/plan.schema.js +4 -1
  15. package/lib/schemas/subscription.schema.d.ts +364 -88
  16. package/lib/schemas/subscription.schema.js +4 -1
  17. package/lib/schemas/typebox/billingPortal.schema.d.ts +172 -38
  18. package/lib/schemas/typebox/billingPortal.schema.js +23 -17
  19. package/lib/schemas/typebox/checkoutSession.schema.d.ts +197 -55
  20. package/lib/schemas/typebox/checkoutSession.schema.js +25 -13
  21. package/lib/schemas/typebox/paymentLink.schema.d.ts +275 -65
  22. package/lib/schemas/typebox/paymentLink.schema.js +27 -15
  23. package/lib/schemas/typebox/plan.schema.d.ts +409 -77
  24. package/lib/schemas/typebox/plan.schema.js +31 -17
  25. package/lib/schemas/typebox/subscription.schema.d.ts +481 -89
  26. package/lib/schemas/typebox/subscription.schema.js +31 -19
  27. package/lib/schemas/zod/billingPortal.schema.d.ts +42 -38
  28. package/lib/schemas/zod/billingPortal.schema.js +23 -17
  29. package/lib/schemas/zod/checkoutSession.schema.d.ts +107 -55
  30. package/lib/schemas/zod/checkoutSession.schema.js +25 -13
  31. package/lib/schemas/zod/paymentLink.schema.d.ts +99 -65
  32. package/lib/schemas/zod/paymentLink.schema.js +27 -15
  33. package/lib/schemas/zod/plan.schema.d.ts +177 -77
  34. package/lib/schemas/zod/plan.schema.js +31 -17
  35. package/lib/schemas/zod/subscription.schema.d.ts +181 -89
  36. package/lib/schemas/zod/subscription.schema.js +31 -19
  37. package/lib/services/billingPortal.service.d.ts +77 -28
  38. package/lib/services/billingPortal.service.js +64 -45
  39. package/lib/services/checkoutSession.service.d.ts +77 -29
  40. package/lib/services/checkoutSession.service.js +54 -43
  41. package/lib/services/index.d.ts +1 -1
  42. package/lib/services/paymentLink.service.d.ts +82 -32
  43. package/lib/services/paymentLink.service.js +84 -66
  44. package/lib/services/plan.service.d.ts +73 -26
  45. package/lib/services/plan.service.js +45 -40
  46. package/lib/services/subscription.service.d.ts +136 -44
  47. package/lib/services/subscription.service.js +111 -88
  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 +8 -8
@@ -1,18 +1,28 @@
1
- import { boolean, date, enum_, optional, string, unknown, uuid } from '@forklaunch/validator/zod';
1
+ import {
2
+ boolean,
3
+ date,
4
+ enum_,
5
+ optional,
6
+ string,
7
+ unknown,
8
+ uuid
9
+ } from '@forklaunch/validator/zod';
2
10
  export const CreateSubscriptionSchema = (PartyEnum, BillingProviderEnum) => ({
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)
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)
14
22
  });
15
- export const UpdateSubscriptionSchema = ({ uuidId }) => (PartyEnum, BillingProviderEnum) => ({
23
+ export const UpdateSubscriptionSchema =
24
+ ({ uuidId }) =>
25
+ (PartyEnum, BillingProviderEnum) => ({
16
26
  id: uuidId ? uuid : string,
17
27
  partyId: optional(string),
18
28
  partyType: optional(enum_(PartyEnum)),
@@ -25,8 +35,10 @@ export const UpdateSubscriptionSchema = ({ uuidId }) => (PartyEnum, BillingProvi
25
35
  status: optional(string),
26
36
  billingProvider: optional(enum_(BillingProviderEnum)),
27
37
  extraFields: optional(unknown)
28
- });
29
- export const SubscriptionSchema = ({ uuidId }) => (PartyEnum, BillingProviderEnum) => ({
38
+ });
39
+ export const SubscriptionSchema =
40
+ ({ uuidId }) =>
41
+ (PartyEnum, BillingProviderEnum) => ({
30
42
  id: uuidId ? uuid : string,
31
43
  partyId: string,
32
44
  partyType: enum_(PartyEnum),
@@ -41,9 +53,9 @@ export const SubscriptionSchema = ({ uuidId }) => (PartyEnum, BillingProviderEnu
41
53
  extraFields: optional(unknown),
42
54
  createdAt: optional(date),
43
55
  updatedAt: optional(date)
44
- });
56
+ });
45
57
  export const BaseSubscriptionServiceSchemas = (options) => ({
46
- CreateSubscriptionSchema,
47
- UpdateSubscriptionSchema: UpdateSubscriptionSchema(options),
48
- SubscriptionSchema: SubscriptionSchema(options)
58
+ CreateSubscriptionSchema,
59
+ UpdateSubscriptionSchema: UpdateSubscriptionSchema(options),
60
+ SubscriptionSchema: SubscriptionSchema(options)
49
61
  });
@@ -1,45 +1,94 @@
1
1
  import { IdDto } from '@forklaunch/common';
2
2
  import { TtlCache } from '@forklaunch/core/cache';
3
- import { RequestDtoMapperConstructor, ResponseDtoMapperConstructor } from '@forklaunch/core/mappers';
4
- import { MetricsDefinition, OpenTelemetryCollector } from '@forklaunch/core/http';
3
+ import {
4
+ RequestDtoMapperConstructor,
5
+ ResponseDtoMapperConstructor
6
+ } from '@forklaunch/core/mappers';
7
+ import {
8
+ MetricsDefinition,
9
+ OpenTelemetryCollector
10
+ } from '@forklaunch/core/http';
5
11
  import { BillingPortalService } from '@forklaunch/interfaces-billing/interfaces';
6
- import { BillingPortalDto, CreateBillingPortalDto, UpdateBillingPortalDto } from '@forklaunch/interfaces-billing/types';
12
+ import {
13
+ BillingPortalDto,
14
+ CreateBillingPortalDto,
15
+ UpdateBillingPortalDto
16
+ } from '@forklaunch/interfaces-billing/types';
7
17
  import { AnySchemaValidator } from '@forklaunch/validator';
8
- export declare class BaseBillingPortalService<SchemaValidator extends AnySchemaValidator, Metrics extends MetricsDefinition = MetricsDefinition, Dto extends {
18
+ export declare class BaseBillingPortalService<
19
+ SchemaValidator extends AnySchemaValidator,
20
+ Metrics extends MetricsDefinition = MetricsDefinition,
21
+ Dto extends {
9
22
  BillingPortalDtoMapper: BillingPortalDto;
10
23
  CreateBillingPortalDtoMapper: CreateBillingPortalDto;
11
24
  UpdateBillingPortalDtoMapper: UpdateBillingPortalDto;
12
- } = {
25
+ } = {
13
26
  BillingPortalDtoMapper: BillingPortalDto;
14
27
  CreateBillingPortalDtoMapper: CreateBillingPortalDto;
15
28
  UpdateBillingPortalDtoMapper: UpdateBillingPortalDto;
16
- }, Entities extends {
29
+ },
30
+ Entities extends {
17
31
  BillingPortalDtoMapper: BillingPortalDto;
18
32
  CreateBillingPortalDtoMapper: BillingPortalDto;
19
33
  UpdateBillingPortalDtoMapper: BillingPortalDto;
20
- } = {
34
+ } = {
21
35
  BillingPortalDtoMapper: BillingPortalDto;
22
36
  CreateBillingPortalDtoMapper: BillingPortalDto;
23
37
  UpdateBillingPortalDtoMapper: BillingPortalDto;
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>;
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>;
44
93
  }
45
- //# sourceMappingURL=billingPortal.service.d.ts.map
94
+ //# sourceMappingURL=billingPortal.service.d.ts.map
@@ -1,51 +1,70 @@
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);
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');
15
41
  }
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));
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');
50
67
  }
68
+ await this.cache.deleteRecord(this.createCacheKey(idDto.id));
69
+ }
51
70
  }
@@ -1,46 +1,94 @@
1
1
  import { IdDto } from '@forklaunch/common';
2
2
  import { TtlCache } from '@forklaunch/core/cache';
3
- import { RequestDtoMapperConstructor, ResponseDtoMapperConstructor } from '@forklaunch/core/mappers';
4
- import { MetricsDefinition, OpenTelemetryCollector } from '@forklaunch/core/http';
3
+ import {
4
+ RequestDtoMapperConstructor,
5
+ ResponseDtoMapperConstructor
6
+ } from '@forklaunch/core/mappers';
7
+ import {
8
+ MetricsDefinition,
9
+ OpenTelemetryCollector
10
+ } from '@forklaunch/core/http';
5
11
  import { CheckoutSessionService } from '@forklaunch/interfaces-billing/interfaces';
6
- import { CheckoutSessionDto, CreateCheckoutSessionDto, UpdateCheckoutSessionDto } from '@forklaunch/interfaces-billing/types';
12
+ import {
13
+ CheckoutSessionDto,
14
+ CreateCheckoutSessionDto,
15
+ UpdateCheckoutSessionDto
16
+ } from '@forklaunch/interfaces-billing/types';
7
17
  import { AnySchemaValidator } from '@forklaunch/validator';
8
- export declare class BaseCheckoutSessionService<SchemaValidator extends AnySchemaValidator, PaymentMethodEnum, Metrics extends MetricsDefinition = MetricsDefinition, Dto extends {
18
+ export declare class BaseCheckoutSessionService<
19
+ SchemaValidator extends AnySchemaValidator,
20
+ PaymentMethodEnum,
21
+ Metrics extends MetricsDefinition = MetricsDefinition,
22
+ Dto extends {
9
23
  CheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
10
24
  CreateCheckoutSessionDtoMapper: CreateCheckoutSessionDto<PaymentMethodEnum>;
11
25
  UpdateCheckoutSessionDtoMapper: UpdateCheckoutSessionDto<PaymentMethodEnum>;
12
- } = {
26
+ } = {
13
27
  CheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
14
28
  CreateCheckoutSessionDtoMapper: CreateCheckoutSessionDto<PaymentMethodEnum>;
15
29
  UpdateCheckoutSessionDtoMapper: UpdateCheckoutSessionDto<PaymentMethodEnum>;
16
- }, Entities extends {
30
+ },
31
+ Entities extends {
17
32
  CheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
18
33
  CreateCheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
19
34
  UpdateCheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
20
- } = {
35
+ } = {
21
36
  CheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
22
37
  CreateCheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
23
38
  UpdateCheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
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>;
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>;
45
93
  }
46
- //# sourceMappingURL=checkoutSession.service.d.ts.map
94
+ //# sourceMappingURL=checkoutSession.service.d.ts.map
@@ -1,49 +1,60 @@
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);
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');
15
38
  }
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));
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');
48
49
  }
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
+ }
49
60
  }
@@ -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