@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,99 +1,49 @@
1
1
  import { IdDto, IdsDto } 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 { PaymentLinkService } from '@forklaunch/interfaces-billing/interfaces';
12
- import {
13
- CreatePaymentLinkDto,
14
- PaymentLinkDto,
15
- UpdatePaymentLinkDto
16
- } from '@forklaunch/interfaces-billing/types';
6
+ import { CreatePaymentLinkDto, PaymentLinkDto, UpdatePaymentLinkDto } from '@forklaunch/interfaces-billing/types';
17
7
  import { AnySchemaValidator } from '@forklaunch/validator';
18
- export declare class BasePaymentLinkService<
19
- SchemaValidator extends AnySchemaValidator,
20
- CurrencyEnum,
21
- Metrics extends MetricsDefinition = MetricsDefinition,
22
- Dto extends {
8
+ export declare class BasePaymentLinkService<SchemaValidator extends AnySchemaValidator, CurrencyEnum, Metrics extends MetricsDefinition = MetricsDefinition, Dto extends {
23
9
  PaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
24
10
  CreatePaymentLinkDtoMapper: CreatePaymentLinkDto<CurrencyEnum>;
25
11
  UpdatePaymentLinkDtoMapper: UpdatePaymentLinkDto<CurrencyEnum>;
26
- } = {
12
+ } = {
27
13
  PaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
28
14
  CreatePaymentLinkDtoMapper: CreatePaymentLinkDto<CurrencyEnum>;
29
15
  UpdatePaymentLinkDtoMapper: UpdatePaymentLinkDto<CurrencyEnum>;
30
- },
31
- Entities extends {
16
+ }, Entities extends {
32
17
  PaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
33
18
  CreatePaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
34
19
  UpdatePaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
35
- } = {
20
+ } = {
36
21
  PaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
37
22
  CreatePaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
38
23
  UpdatePaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
39
- }
40
- > implements PaymentLinkService<CurrencyEnum>
41
- {
42
- #private;
43
- protected readonly cache: TtlCache;
44
- protected readonly openTelemetryCollector: OpenTelemetryCollector<Metrics>;
45
- protected readonly schemaValidator: SchemaValidator;
46
- protected readonly mapperss: {
47
- PaymentLinkDtoMapper: ResponseDtoMapperConstructor<
48
- SchemaValidator,
49
- Dto['PaymentLinkDtoMapper'],
50
- Entities['PaymentLinkDtoMapper']
51
- >;
52
- CreatePaymentLinkDtoMapper: RequestDtoMapperConstructor<
53
- SchemaValidator,
54
- Dto['CreatePaymentLinkDtoMapper'],
55
- Entities['CreatePaymentLinkDtoMapper']
56
- >;
57
- UpdatePaymentLinkDtoMapper: RequestDtoMapperConstructor<
58
- SchemaValidator,
59
- Dto['UpdatePaymentLinkDtoMapper'],
60
- Entities['UpdatePaymentLinkDtoMapper']
61
- >;
62
- };
63
- constructor(
64
- cache: TtlCache,
65
- openTelemetryCollector: OpenTelemetryCollector<Metrics>,
66
- schemaValidator: SchemaValidator,
67
- mapperss: {
68
- PaymentLinkDtoMapper: ResponseDtoMapperConstructor<
69
- SchemaValidator,
70
- Dto['PaymentLinkDtoMapper'],
71
- Entities['PaymentLinkDtoMapper']
72
- >;
73
- CreatePaymentLinkDtoMapper: RequestDtoMapperConstructor<
74
- SchemaValidator,
75
- Dto['CreatePaymentLinkDtoMapper'],
76
- Entities['CreatePaymentLinkDtoMapper']
77
- >;
78
- UpdatePaymentLinkDtoMapper: RequestDtoMapperConstructor<
79
- SchemaValidator,
80
- Dto['UpdatePaymentLinkDtoMapper'],
81
- Entities['UpdatePaymentLinkDtoMapper']
82
- >;
83
- }
84
- );
85
- protected cacheKeyPrefix: string;
86
- protected createCacheKey: (id: string) => string;
87
- createPaymentLink(
88
- paymentLinkDto: Dto['CreatePaymentLinkDtoMapper']
89
- ): Promise<Dto['PaymentLinkDtoMapper']>;
90
- updatePaymentLink(
91
- paymentLinkDto: Dto['UpdatePaymentLinkDtoMapper']
92
- ): Promise<Dto['PaymentLinkDtoMapper']>;
93
- getPaymentLink({ id }: IdDto): Promise<Dto['PaymentLinkDtoMapper']>;
94
- expirePaymentLink({ id }: IdDto): Promise<void>;
95
- handlePaymentSuccess({ id }: IdDto): Promise<void>;
96
- handlePaymentFailure({ id }: IdDto): Promise<void>;
97
- listPaymentLinks(idsDto?: IdsDto): Promise<Dto['PaymentLinkDtoMapper'][]>;
24
+ }> implements PaymentLinkService<CurrencyEnum> {
25
+ #private;
26
+ protected readonly cache: TtlCache;
27
+ protected readonly openTelemetryCollector: OpenTelemetryCollector<Metrics>;
28
+ protected readonly schemaValidator: SchemaValidator;
29
+ protected readonly mapperss: {
30
+ PaymentLinkDtoMapper: ResponseDtoMapperConstructor<SchemaValidator, Dto['PaymentLinkDtoMapper'], Entities['PaymentLinkDtoMapper']>;
31
+ CreatePaymentLinkDtoMapper: RequestDtoMapperConstructor<SchemaValidator, Dto['CreatePaymentLinkDtoMapper'], Entities['CreatePaymentLinkDtoMapper']>;
32
+ UpdatePaymentLinkDtoMapper: RequestDtoMapperConstructor<SchemaValidator, Dto['UpdatePaymentLinkDtoMapper'], Entities['UpdatePaymentLinkDtoMapper']>;
33
+ };
34
+ constructor(cache: TtlCache, openTelemetryCollector: OpenTelemetryCollector<Metrics>, schemaValidator: SchemaValidator, mapperss: {
35
+ PaymentLinkDtoMapper: ResponseDtoMapperConstructor<SchemaValidator, Dto['PaymentLinkDtoMapper'], Entities['PaymentLinkDtoMapper']>;
36
+ CreatePaymentLinkDtoMapper: RequestDtoMapperConstructor<SchemaValidator, Dto['CreatePaymentLinkDtoMapper'], Entities['CreatePaymentLinkDtoMapper']>;
37
+ UpdatePaymentLinkDtoMapper: RequestDtoMapperConstructor<SchemaValidator, Dto['UpdatePaymentLinkDtoMapper'], Entities['UpdatePaymentLinkDtoMapper']>;
38
+ });
39
+ protected cacheKeyPrefix: string;
40
+ protected createCacheKey: (id: string) => string;
41
+ createPaymentLink(paymentLinkDto: Dto['CreatePaymentLinkDtoMapper']): Promise<Dto['PaymentLinkDtoMapper']>;
42
+ updatePaymentLink(paymentLinkDto: Dto['UpdatePaymentLinkDtoMapper']): Promise<Dto['PaymentLinkDtoMapper']>;
43
+ getPaymentLink({ id }: IdDto): Promise<Dto['PaymentLinkDtoMapper']>;
44
+ expirePaymentLink({ id }: IdDto): Promise<void>;
45
+ handlePaymentSuccess({ id }: IdDto): Promise<void>;
46
+ handlePaymentFailure({ id }: IdDto): Promise<void>;
47
+ listPaymentLinks(idsDto?: IdsDto): Promise<Dto['PaymentLinkDtoMapper'][]>;
98
48
  }
99
- //# sourceMappingURL=paymentLink.service.d.ts.map
49
+ //# sourceMappingURL=paymentLink.service.d.ts.map
@@ -1,90 +1,72 @@
1
1
  import { createCacheKey } from '@forklaunch/core/cache';
2
2
  import { transformIntoInternalDtoMapper } from '@forklaunch/core/mappers';
3
3
  export class BasePaymentLinkService {
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
- cacheKeyPrefix = 'payment_link';
17
- createCacheKey = createCacheKey(this.cacheKeyPrefix);
18
- async createPaymentLink(paymentLinkDto) {
19
- // TODO: Perform permission checks here
20
- const paymentLink =
21
- this.#mapperss.CreatePaymentLinkDtoMapper.deserializeDtoToEntity(
22
- paymentLinkDto
23
- );
24
- await this.cache.putRecord({
25
- key: this.createCacheKey(paymentLink.id),
26
- value: paymentLink,
27
- ttlMilliseconds: this.cache.getTtlMilliseconds()
28
- });
29
- return this.#mapperss.PaymentLinkDtoMapper.serializeEntityToDto(
30
- paymentLink
31
- );
32
- }
33
- async updatePaymentLink(paymentLinkDto) {
34
- const cacheKey = this.createCacheKey(paymentLinkDto.id);
35
- const existingLink = await this.cache.readRecord(cacheKey);
36
- if (!existingLink) {
37
- throw new Error('Payment link 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
- const paymentLink =
40
- this.#mapperss.UpdatePaymentLinkDtoMapper.deserializeDtoToEntity(
41
- paymentLinkDto
42
- );
43
- const updatedLink = { ...existingLink, ...paymentLink };
44
- await this.cache.putRecord({
45
- key: cacheKey,
46
- value: updatedLink,
47
- ttlMilliseconds: this.cache.getTtlMilliseconds()
48
- });
49
- return this.#mapperss.PaymentLinkDtoMapper.serializeEntityToDto(
50
- updatedLink
51
- );
52
- }
53
- async getPaymentLink({ id }) {
54
- const cacheKey = this.createCacheKey(id);
55
- const paymentLink = await this.cache.readRecord(cacheKey);
56
- if (!paymentLink) {
57
- throw new Error('Payment link not found');
16
+ cacheKeyPrefix = 'payment_link';
17
+ createCacheKey = createCacheKey(this.cacheKeyPrefix);
18
+ async createPaymentLink(paymentLinkDto) {
19
+ // TODO: Perform permission checks here
20
+ const paymentLink = this.#mapperss.CreatePaymentLinkDtoMapper.deserializeDtoToEntity(paymentLinkDto);
21
+ await this.cache.putRecord({
22
+ key: this.createCacheKey(paymentLink.id),
23
+ value: paymentLink,
24
+ ttlMilliseconds: this.cache.getTtlMilliseconds()
25
+ });
26
+ return this.#mapperss.PaymentLinkDtoMapper.serializeEntityToDto(paymentLink);
27
+ }
28
+ async updatePaymentLink(paymentLinkDto) {
29
+ const cacheKey = this.createCacheKey(paymentLinkDto.id);
30
+ const existingLink = await this.cache.readRecord(cacheKey);
31
+ if (!existingLink) {
32
+ throw new Error('Payment link not found');
33
+ }
34
+ const paymentLink = this.#mapperss.UpdatePaymentLinkDtoMapper.deserializeDtoToEntity(paymentLinkDto);
35
+ const updatedLink = { ...existingLink, ...paymentLink };
36
+ await this.cache.putRecord({
37
+ key: cacheKey,
38
+ value: updatedLink,
39
+ ttlMilliseconds: this.cache.getTtlMilliseconds()
40
+ });
41
+ return this.#mapperss.PaymentLinkDtoMapper.serializeEntityToDto(updatedLink);
42
+ }
43
+ async getPaymentLink({ id }) {
44
+ const cacheKey = this.createCacheKey(id);
45
+ const paymentLink = await this.cache.readRecord(cacheKey);
46
+ if (!paymentLink) {
47
+ throw new Error('Payment link not found');
48
+ }
49
+ return this.#mapperss.PaymentLinkDtoMapper.serializeEntityToDto(paymentLink.value);
50
+ }
51
+ async expirePaymentLink({ id }) {
52
+ this.openTelemetryCollector.info('Payment link expired', { id });
53
+ await this.cache.deleteRecord(this.createCacheKey(id));
54
+ }
55
+ async handlePaymentSuccess({ id }) {
56
+ this.openTelemetryCollector.info('Payment link success', { id });
57
+ await this.cache.deleteRecord(this.createCacheKey(id));
58
+ }
59
+ async handlePaymentFailure({ id }) {
60
+ this.openTelemetryCollector.info('Payment link failure', { id });
61
+ await this.cache.deleteRecord(this.createCacheKey(id));
62
+ }
63
+ async listPaymentLinks(idsDto) {
64
+ const keys = idsDto?.ids.map((id) => this.createCacheKey(id)) ??
65
+ (await this.cache.listKeys(this.cacheKeyPrefix));
66
+ return await Promise.all(keys.map(async (key) => {
67
+ const paymentLink = await this.cache.readRecord(key);
68
+ const paymentLinkDto = this.#mapperss.PaymentLinkDtoMapper.serializeEntityToDto(paymentLink.value);
69
+ return paymentLinkDto;
70
+ }));
58
71
  }
59
- return this.#mapperss.PaymentLinkDtoMapper.serializeEntityToDto(
60
- paymentLink.value
61
- );
62
- }
63
- async expirePaymentLink({ id }) {
64
- this.openTelemetryCollector.info('Payment link expired', { id });
65
- await this.cache.deleteRecord(this.createCacheKey(id));
66
- }
67
- async handlePaymentSuccess({ id }) {
68
- this.openTelemetryCollector.info('Payment link success', { id });
69
- await this.cache.deleteRecord(this.createCacheKey(id));
70
- }
71
- async handlePaymentFailure({ id }) {
72
- this.openTelemetryCollector.info('Payment link failure', { id });
73
- await this.cache.deleteRecord(this.createCacheKey(id));
74
- }
75
- async listPaymentLinks(idsDto) {
76
- const keys =
77
- idsDto?.ids.map((id) => this.createCacheKey(id)) ??
78
- (await this.cache.listKeys(this.cacheKeyPrefix));
79
- return await Promise.all(
80
- keys.map(async (key) => {
81
- const paymentLink = await this.cache.readRecord(key);
82
- const paymentLinkDto =
83
- this.#mapperss.PaymentLinkDtoMapper.serializeEntityToDto(
84
- paymentLink.value
85
- );
86
- return paymentLinkDto;
87
- })
88
- );
89
- }
90
72
  }
@@ -1,90 +1,43 @@
1
1
  import { IdDto, IdsDto } from '@forklaunch/common';
2
- import {
3
- RequestDtoMapperConstructor,
4
- ResponseDtoMapperConstructor
5
- } from '@forklaunch/core/mappers';
6
- import {
7
- MetricsDefinition,
8
- OpenTelemetryCollector
9
- } from '@forklaunch/core/http';
2
+ import { RequestDtoMapperConstructor, ResponseDtoMapperConstructor } from '@forklaunch/core/mappers';
3
+ import { MetricsDefinition, OpenTelemetryCollector } from '@forklaunch/core/http';
10
4
  import { PlanService } from '@forklaunch/interfaces-billing/interfaces';
11
- import {
12
- CreatePlanDto,
13
- PlanDto,
14
- UpdatePlanDto
15
- } from '@forklaunch/interfaces-billing/types';
5
+ import { CreatePlanDto, PlanDto, UpdatePlanDto } from '@forklaunch/interfaces-billing/types';
16
6
  import { AnySchemaValidator } from '@forklaunch/validator';
17
7
  import { EntityManager } from '@mikro-orm/core';
18
- export declare class BasePlanService<
19
- SchemaValidator extends AnySchemaValidator,
20
- PlanCadenceEnum,
21
- BillingProviderEnum,
22
- Metrics extends MetricsDefinition = MetricsDefinition,
23
- Dto extends {
8
+ export declare class BasePlanService<SchemaValidator extends AnySchemaValidator, PlanCadenceEnum, BillingProviderEnum, Metrics extends MetricsDefinition = MetricsDefinition, Dto extends {
24
9
  PlanDtoMapper: PlanDto<PlanCadenceEnum, BillingProviderEnum>;
25
10
  CreatePlanDtoMapper: CreatePlanDto<PlanCadenceEnum, BillingProviderEnum>;
26
11
  UpdatePlanDtoMapper: UpdatePlanDto<PlanCadenceEnum, BillingProviderEnum>;
27
- } = {
12
+ } = {
28
13
  PlanDtoMapper: PlanDto<PlanCadenceEnum, BillingProviderEnum>;
29
14
  CreatePlanDtoMapper: CreatePlanDto<PlanCadenceEnum, BillingProviderEnum>;
30
15
  UpdatePlanDtoMapper: UpdatePlanDto<PlanCadenceEnum, BillingProviderEnum>;
31
- },
32
- Entities extends {
16
+ }, Entities extends {
33
17
  PlanDtoMapper: PlanDto<PlanCadenceEnum, BillingProviderEnum>;
34
18
  CreatePlanDtoMapper: PlanDto<PlanCadenceEnum, BillingProviderEnum>;
35
19
  UpdatePlanDtoMapper: PlanDto<PlanCadenceEnum, BillingProviderEnum>;
36
- } = {
20
+ } = {
37
21
  PlanDtoMapper: PlanDto<PlanCadenceEnum, BillingProviderEnum>;
38
22
  CreatePlanDtoMapper: PlanDto<PlanCadenceEnum, BillingProviderEnum>;
39
23
  UpdatePlanDtoMapper: PlanDto<PlanCadenceEnum, BillingProviderEnum>;
40
- }
41
- > implements PlanService<PlanCadenceEnum, BillingProviderEnum>
42
- {
43
- #private;
44
- private em;
45
- private readonly openTelemetryCollector;
46
- private readonly schemaValidator;
47
- private readonly mapperss;
48
- constructor(
49
- em: EntityManager,
50
- openTelemetryCollector: OpenTelemetryCollector<Metrics>,
51
- schemaValidator: SchemaValidator,
52
- mapperss: {
53
- PlanDtoMapper: ResponseDtoMapperConstructor<
54
- SchemaValidator,
55
- Dto['PlanDtoMapper'],
56
- Entities['PlanDtoMapper']
57
- >;
58
- CreatePlanDtoMapper: RequestDtoMapperConstructor<
59
- SchemaValidator,
60
- Dto['CreatePlanDtoMapper'],
61
- Entities['CreatePlanDtoMapper']
62
- >;
63
- UpdatePlanDtoMapper: RequestDtoMapperConstructor<
64
- SchemaValidator,
65
- Dto['UpdatePlanDtoMapper'],
66
- Entities['UpdatePlanDtoMapper']
67
- >;
68
- }
69
- );
70
- listPlans(
71
- idsDto?: IdsDto,
72
- em?: EntityManager
73
- ): Promise<Dto['PlanDtoMapper'][]>;
74
- createPlan(
75
- planDto: Dto['CreatePlanDtoMapper'],
76
- em?: EntityManager
77
- ): Promise<Dto['PlanDtoMapper']>;
78
- getPlan(idDto: IdDto, em?: EntityManager): Promise<Dto['PlanDtoMapper']>;
79
- updatePlan(
80
- planDto: Dto['UpdatePlanDtoMapper'],
81
- em?: EntityManager
82
- ): Promise<Dto['PlanDtoMapper']>;
83
- deletePlan(
84
- idDto: {
85
- id: string;
86
- },
87
- em?: EntityManager
88
- ): Promise<void>;
24
+ }> implements PlanService<PlanCadenceEnum, BillingProviderEnum> {
25
+ #private;
26
+ private em;
27
+ private readonly openTelemetryCollector;
28
+ private readonly schemaValidator;
29
+ private readonly mapperss;
30
+ constructor(em: EntityManager, openTelemetryCollector: OpenTelemetryCollector<Metrics>, schemaValidator: SchemaValidator, mapperss: {
31
+ PlanDtoMapper: ResponseDtoMapperConstructor<SchemaValidator, Dto['PlanDtoMapper'], Entities['PlanDtoMapper']>;
32
+ CreatePlanDtoMapper: RequestDtoMapperConstructor<SchemaValidator, Dto['CreatePlanDtoMapper'], Entities['CreatePlanDtoMapper']>;
33
+ UpdatePlanDtoMapper: RequestDtoMapperConstructor<SchemaValidator, Dto['UpdatePlanDtoMapper'], Entities['UpdatePlanDtoMapper']>;
34
+ });
35
+ listPlans(idsDto?: IdsDto, em?: EntityManager): Promise<Dto['PlanDtoMapper'][]>;
36
+ createPlan(planDto: Dto['CreatePlanDtoMapper'], em?: EntityManager): Promise<Dto['PlanDtoMapper']>;
37
+ getPlan(idDto: IdDto, em?: EntityManager): Promise<Dto['PlanDtoMapper']>;
38
+ updatePlan(planDto: Dto['UpdatePlanDtoMapper'], em?: EntityManager): Promise<Dto['PlanDtoMapper']>;
39
+ deletePlan(idDto: {
40
+ id: string;
41
+ }, em?: EntityManager): Promise<void>;
89
42
  }
90
- //# sourceMappingURL=plan.service.d.ts.map
43
+ //# sourceMappingURL=plan.service.d.ts.map
@@ -1,48 +1,43 @@
1
1
  import { transformIntoInternalDtoMapper } from '@forklaunch/core/mappers';
2
2
  export class BasePlanService {
3
- em;
4
- openTelemetryCollector;
5
- schemaValidator;
6
- mapperss;
7
- #mapperss;
8
- constructor(em, openTelemetryCollector, schemaValidator, mapperss) {
9
- this.em = em;
10
- this.openTelemetryCollector = openTelemetryCollector;
11
- this.schemaValidator = schemaValidator;
12
- this.mapperss = mapperss;
13
- this.#mapperss = transformIntoInternalDtoMapper(mapperss, schemaValidator);
14
- }
15
- async listPlans(idsDto, em) {
16
- return (
17
- await (em ?? this.em).findAll('Plan', {
18
- filters: idsDto?.ids ? { id: { $in: idsDto.ids } } : undefined
19
- })
20
- ).map((plan) => this.#mapperss.PlanDtoMapper.serializeEntityToDto(plan));
21
- }
22
- async createPlan(planDto, em) {
23
- const plan =
24
- this.#mapperss.CreatePlanDtoMapper.deserializeDtoToEntity(planDto);
25
- await (em ?? this.em).transactional(async (innerEm) => {
26
- await innerEm.persist(plan);
27
- });
28
- return this.#mapperss.PlanDtoMapper.serializeEntityToDto(plan);
29
- }
30
- async getPlan(idDto, em) {
31
- const plan = await (em ?? this.em).findOneOrFail('Plan', idDto);
32
- return this.#mapperss.PlanDtoMapper.serializeEntityToDto(plan);
33
- }
34
- async updatePlan(planDto, em) {
35
- const plan =
36
- this.#mapperss.UpdatePlanDtoMapper.deserializeDtoToEntity(planDto);
37
- const updatedPlan = await (em ?? this.em).upsert(plan);
38
- await (em ?? this.em).transactional(async (innerEm) => {
39
- await innerEm.persist(plan);
40
- });
41
- const updatedPlanDto =
42
- this.#mapperss.PlanDtoMapper.serializeEntityToDto(updatedPlan);
43
- return updatedPlanDto;
44
- }
45
- async deletePlan(idDto, em) {
46
- await (em ?? this.em).nativeDelete('Plan', idDto);
47
- }
3
+ em;
4
+ openTelemetryCollector;
5
+ schemaValidator;
6
+ mapperss;
7
+ #mapperss;
8
+ constructor(em, openTelemetryCollector, schemaValidator, mapperss) {
9
+ this.em = em;
10
+ this.openTelemetryCollector = openTelemetryCollector;
11
+ this.schemaValidator = schemaValidator;
12
+ this.mapperss = mapperss;
13
+ this.#mapperss = transformIntoInternalDtoMapper(mapperss, schemaValidator);
14
+ }
15
+ async listPlans(idsDto, em) {
16
+ return (await (em ?? this.em).findAll('Plan', {
17
+ filters: idsDto?.ids ? { id: { $in: idsDto.ids } } : undefined
18
+ })).map((plan) => this.#mapperss.PlanDtoMapper.serializeEntityToDto(plan));
19
+ }
20
+ async createPlan(planDto, em) {
21
+ const plan = this.#mapperss.CreatePlanDtoMapper.deserializeDtoToEntity(planDto);
22
+ await (em ?? this.em).transactional(async (innerEm) => {
23
+ await innerEm.persist(plan);
24
+ });
25
+ return this.#mapperss.PlanDtoMapper.serializeEntityToDto(plan);
26
+ }
27
+ async getPlan(idDto, em) {
28
+ const plan = await (em ?? this.em).findOneOrFail('Plan', idDto);
29
+ return this.#mapperss.PlanDtoMapper.serializeEntityToDto(plan);
30
+ }
31
+ async updatePlan(planDto, em) {
32
+ const plan = this.#mapperss.UpdatePlanDtoMapper.deserializeDtoToEntity(planDto);
33
+ const updatedPlan = await (em ?? this.em).upsert(plan);
34
+ await (em ?? this.em).transactional(async (innerEm) => {
35
+ await innerEm.persist(plan);
36
+ });
37
+ const updatedPlanDto = this.#mapperss.PlanDtoMapper.serializeEntityToDto(updatedPlan);
38
+ return updatedPlanDto;
39
+ }
40
+ async deletePlan(idDto, em) {
41
+ await (em ?? this.em).nativeDelete('Plan', idDto);
42
+ }
48
43
  }