@forklaunch/implementation-billing-base 0.1.3 → 0.1.5

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 (43) hide show
  1. package/lib/eject/schemas/billingPortal.schema.ts +1 -1
  2. package/lib/eject/schemas/checkoutSession.schema.ts +1 -1
  3. package/lib/eject/schemas/index.ts +5 -0
  4. package/lib/eject/schemas/paymentLink.schema.ts +1 -1
  5. package/lib/eject/schemas/plan.schema.ts +1 -1
  6. package/lib/eject/schemas/subscription.schema.ts +1 -1
  7. package/lib/eject/services/billingPortal.service.ts +6 -6
  8. package/lib/eject/services/checkoutSession.service.ts +6 -6
  9. package/lib/eject/services/index.ts +5 -0
  10. package/lib/eject/services/paymentLink.service.ts +6 -6
  11. package/lib/eject/services/plan.service.ts +6 -6
  12. package/lib/eject/services/subscription.service.ts +6 -6
  13. package/lib/schemas/index.d.ts +6 -0
  14. package/lib/schemas/index.d.ts.map +1 -0
  15. package/lib/schemas/index.js +5 -0
  16. package/lib/services/billingPortal.service.d.ts +2 -1
  17. package/lib/services/billingPortal.service.d.ts.map +1 -1
  18. package/lib/services/checkoutSession.service.d.ts +2 -1
  19. package/lib/services/checkoutSession.service.d.ts.map +1 -1
  20. package/lib/services/index.d.ts +6 -0
  21. package/lib/services/index.d.ts.map +1 -0
  22. package/lib/services/index.js +5 -0
  23. package/lib/services/paymentLink.service.d.ts +2 -1
  24. package/lib/services/paymentLink.service.d.ts.map +1 -1
  25. package/lib/services/plan.service.d.ts +2 -1
  26. package/lib/services/plan.service.d.ts.map +1 -1
  27. package/lib/services/subscription.service.d.ts +2 -1
  28. package/lib/services/subscription.service.d.ts.map +1 -1
  29. package/lib/tsconfig.tsbuildinfo +1 -1
  30. package/package.json +19 -10
  31. package/lib/eject/schemas/zod/billingPortal.schema.ts +0 -29
  32. package/lib/eject/schemas/zod/checkoutSession.schema.ts +0 -46
  33. package/lib/eject/schemas/zod/paymentLink.schema.ts +0 -52
  34. package/lib/eject/schemas/zod/plan.schema.ts +0 -74
  35. package/lib/eject/schemas/zod/subscription.schema.ts +0 -78
  36. package/lib/eject/services/services/billingPortal.service.ts +0 -148
  37. package/lib/eject/services/services/checkoutSession.service.ts +0 -135
  38. package/lib/eject/services/services/paymentLink.service.ts +0 -173
  39. package/lib/eject/services/services/plan.service.ts +0 -135
  40. package/lib/eject/services/services/subscription.service.ts +0 -239
  41. package/lib/index.d.ts +0 -11
  42. package/lib/index.d.ts.map +0 -1
  43. package/lib/index.js +0 -10
@@ -1,173 +0,0 @@
1
- import {
2
- CreatePaymentLinkDto,
3
- PaymentLinkDto,
4
- PaymentLinkService,
5
- UpdatePaymentLinkDto
6
- } from '@forklaunch/interfaces-billing';
7
- import { IdDto, IdsDto, InstanceTypeRecord } from '@forklaunch/common';
8
- import { createCacheKey, TtlCache } from '@forklaunch/core/cache';
9
- import {
10
- InternalDtoMapper,
11
- RequestDtoMapperConstructor,
12
- ResponseDtoMapperConstructor,
13
- transformIntoInternalDtoMapper
14
- } from '@forklaunch/core/dtoMapper';
15
- import {
16
- MetricsDefinition,
17
- OpenTelemetryCollector
18
- } from '@forklaunch/core/http';
19
- import { AnySchemaValidator } from '@forklaunch/validator';
20
-
21
- export class BasePaymentLinkService<
22
- SchemaValidator extends AnySchemaValidator,
23
- CurrencyEnum,
24
- Metrics extends MetricsDefinition = MetricsDefinition,
25
- Dto extends {
26
- PaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
27
- CreatePaymentLinkDtoMapper: CreatePaymentLinkDto<CurrencyEnum>;
28
- UpdatePaymentLinkDtoMapper: UpdatePaymentLinkDto<CurrencyEnum>;
29
- } = {
30
- PaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
31
- CreatePaymentLinkDtoMapper: CreatePaymentLinkDto<CurrencyEnum>;
32
- UpdatePaymentLinkDtoMapper: UpdatePaymentLinkDto<CurrencyEnum>;
33
- },
34
- Entities extends {
35
- PaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
36
- CreatePaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
37
- UpdatePaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
38
- } = {
39
- PaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
40
- CreatePaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
41
- UpdatePaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
42
- }
43
- > implements PaymentLinkService<CurrencyEnum>
44
- {
45
- #dtoMappers: InternalDtoMapper<
46
- InstanceTypeRecord<typeof this.dtoMappers>,
47
- Entities,
48
- Dto
49
- >;
50
-
51
- constructor(
52
- protected readonly cache: TtlCache,
53
- protected readonly openTelemetryCollector: OpenTelemetryCollector<Metrics>,
54
- protected readonly schemaValidator: SchemaValidator,
55
- protected readonly dtoMappers: {
56
- PaymentLinkDtoMapper: ResponseDtoMapperConstructor<
57
- SchemaValidator,
58
- Dto['PaymentLinkDtoMapper'],
59
- Entities['PaymentLinkDtoMapper']
60
- >;
61
- CreatePaymentLinkDtoMapper: RequestDtoMapperConstructor<
62
- SchemaValidator,
63
- Dto['CreatePaymentLinkDtoMapper'],
64
- Entities['CreatePaymentLinkDtoMapper']
65
- >;
66
- UpdatePaymentLinkDtoMapper: RequestDtoMapperConstructor<
67
- SchemaValidator,
68
- Dto['UpdatePaymentLinkDtoMapper'],
69
- Entities['UpdatePaymentLinkDtoMapper']
70
- >;
71
- }
72
- ) {
73
- this.#dtoMappers = transformIntoInternalDtoMapper(
74
- dtoMappers,
75
- schemaValidator
76
- );
77
- }
78
-
79
- protected cacheKeyPrefix = 'payment_link';
80
- protected createCacheKey = createCacheKey(this.cacheKeyPrefix);
81
-
82
- async createPaymentLink(
83
- paymentLinkDto: Dto['CreatePaymentLinkDtoMapper']
84
- ): Promise<Dto['PaymentLinkDtoMapper']> {
85
- // TODO: Perform permission checks here
86
- const paymentLink =
87
- this.#dtoMappers.CreatePaymentLinkDtoMapper.deserializeDtoToEntity(
88
- paymentLinkDto
89
- );
90
- await this.cache.putRecord({
91
- key: this.createCacheKey(paymentLink.id),
92
- value: paymentLink,
93
- ttlMilliseconds: this.cache.getTtlMilliseconds()
94
- });
95
-
96
- return this.#dtoMappers.PaymentLinkDtoMapper.serializeEntityToDto(
97
- paymentLink
98
- );
99
- }
100
-
101
- async updatePaymentLink(
102
- paymentLinkDto: Dto['UpdatePaymentLinkDtoMapper']
103
- ): Promise<Dto['PaymentLinkDtoMapper']> {
104
- const cacheKey = this.createCacheKey(paymentLinkDto.id);
105
- const existingLink =
106
- await this.cache.readRecord<Entities['PaymentLinkDtoMapper']>(cacheKey);
107
- if (!existingLink) {
108
- throw new Error('Payment link not found');
109
- }
110
- const paymentLink =
111
- this.#dtoMappers.UpdatePaymentLinkDtoMapper.deserializeDtoToEntity(
112
- paymentLinkDto
113
- );
114
- const updatedLink = { ...existingLink, ...paymentLink };
115
- await this.cache.putRecord({
116
- key: cacheKey,
117
- value: updatedLink,
118
- ttlMilliseconds: this.cache.getTtlMilliseconds()
119
- });
120
-
121
- return this.#dtoMappers.PaymentLinkDtoMapper.serializeEntityToDto(
122
- updatedLink
123
- );
124
- }
125
-
126
- async getPaymentLink({ id }: IdDto): Promise<Dto['PaymentLinkDtoMapper']> {
127
- const cacheKey = this.createCacheKey(id);
128
- const paymentLink =
129
- await this.cache.readRecord<Entities['PaymentLinkDtoMapper']>(cacheKey);
130
- if (!paymentLink) {
131
- throw new Error('Payment link not found');
132
- }
133
-
134
- return this.#dtoMappers.PaymentLinkDtoMapper.serializeEntityToDto(
135
- paymentLink.value
136
- );
137
- }
138
-
139
- async expirePaymentLink({ id }: IdDto): Promise<void> {
140
- this.openTelemetryCollector.info('Payment link expired', { id });
141
- await this.cache.deleteRecord(this.createCacheKey(id));
142
- }
143
-
144
- async handlePaymentSuccess({ id }: IdDto): Promise<void> {
145
- this.openTelemetryCollector.info('Payment link success', { id });
146
- await this.cache.deleteRecord(this.createCacheKey(id));
147
- }
148
-
149
- async handlePaymentFailure({ id }: IdDto): Promise<void> {
150
- this.openTelemetryCollector.info('Payment link failure', { id });
151
- await this.cache.deleteRecord(this.createCacheKey(id));
152
- }
153
-
154
- async listPaymentLinks(
155
- idsDto?: IdsDto
156
- ): Promise<Dto['PaymentLinkDtoMapper'][]> {
157
- const keys =
158
- idsDto?.ids.map((id) => this.createCacheKey(id)) ??
159
- (await this.cache.listKeys(this.cacheKeyPrefix));
160
-
161
- return await Promise.all(
162
- keys.map(async (key) => {
163
- const paymentLink =
164
- await this.cache.readRecord<Entities['PaymentLinkDtoMapper']>(key);
165
- const paymentLinkDto =
166
- this.#dtoMappers.PaymentLinkDtoMapper.serializeEntityToDto(
167
- paymentLink.value
168
- );
169
- return paymentLinkDto;
170
- })
171
- );
172
- }
173
- }
@@ -1,135 +0,0 @@
1
- import {
2
- CreatePlanDto,
3
- PlanDto,
4
- PlanService,
5
- UpdatePlanDto
6
- } from '@forklaunch/interfaces-billing';
7
- import { IdDto, IdsDto, InstanceTypeRecord } from '@forklaunch/common';
8
- import {
9
- InternalDtoMapper,
10
- RequestDtoMapperConstructor,
11
- ResponseDtoMapperConstructor,
12
- transformIntoInternalDtoMapper
13
- } from '@forklaunch/core/dtoMapper';
14
- import {
15
- MetricsDefinition,
16
- OpenTelemetryCollector
17
- } from '@forklaunch/core/http';
18
- import { AnySchemaValidator } from '@forklaunch/validator';
19
- import { EntityManager } from '@mikro-orm/core';
20
-
21
- export class BasePlanService<
22
- SchemaValidator extends AnySchemaValidator,
23
- PlanCadenceEnum,
24
- BillingProviderEnum,
25
- Metrics extends MetricsDefinition = MetricsDefinition,
26
- Dto extends {
27
- PlanDtoMapper: PlanDto<PlanCadenceEnum, BillingProviderEnum>;
28
- CreatePlanDtoMapper: CreatePlanDto<PlanCadenceEnum, BillingProviderEnum>;
29
- UpdatePlanDtoMapper: UpdatePlanDto<PlanCadenceEnum, BillingProviderEnum>;
30
- } = {
31
- PlanDtoMapper: PlanDto<PlanCadenceEnum, BillingProviderEnum>;
32
- CreatePlanDtoMapper: CreatePlanDto<PlanCadenceEnum, BillingProviderEnum>;
33
- UpdatePlanDtoMapper: UpdatePlanDto<PlanCadenceEnum, BillingProviderEnum>;
34
- },
35
- Entities extends {
36
- PlanDtoMapper: PlanDto<PlanCadenceEnum, BillingProviderEnum>;
37
- CreatePlanDtoMapper: PlanDto<PlanCadenceEnum, BillingProviderEnum>;
38
- UpdatePlanDtoMapper: PlanDto<PlanCadenceEnum, BillingProviderEnum>;
39
- } = {
40
- PlanDtoMapper: PlanDto<PlanCadenceEnum, BillingProviderEnum>;
41
- CreatePlanDtoMapper: PlanDto<PlanCadenceEnum, BillingProviderEnum>;
42
- UpdatePlanDtoMapper: PlanDto<PlanCadenceEnum, BillingProviderEnum>;
43
- }
44
- > implements PlanService<PlanCadenceEnum, BillingProviderEnum>
45
- {
46
- #dtoMappers: InternalDtoMapper<
47
- InstanceTypeRecord<typeof this.dtoMappers>,
48
- Entities,
49
- Dto
50
- >;
51
-
52
- constructor(
53
- private em: EntityManager,
54
- private readonly openTelemetryCollector: OpenTelemetryCollector<Metrics>,
55
- private readonly schemaValidator: SchemaValidator,
56
- private readonly dtoMappers: {
57
- PlanDtoMapper: ResponseDtoMapperConstructor<
58
- SchemaValidator,
59
- Dto['PlanDtoMapper'],
60
- Entities['PlanDtoMapper']
61
- >;
62
- CreatePlanDtoMapper: RequestDtoMapperConstructor<
63
- SchemaValidator,
64
- Dto['CreatePlanDtoMapper'],
65
- Entities['CreatePlanDtoMapper']
66
- >;
67
- UpdatePlanDtoMapper: RequestDtoMapperConstructor<
68
- SchemaValidator,
69
- Dto['UpdatePlanDtoMapper'],
70
- Entities['UpdatePlanDtoMapper']
71
- >;
72
- }
73
- ) {
74
- this.#dtoMappers = transformIntoInternalDtoMapper(
75
- dtoMappers,
76
- schemaValidator
77
- );
78
- }
79
-
80
- async listPlans(
81
- idsDto?: IdsDto,
82
- em?: EntityManager
83
- ): Promise<Dto['PlanDtoMapper'][]> {
84
- return (
85
- await (em ?? this.em).findAll('Plan', {
86
- filters: idsDto?.ids ? { id: { $in: idsDto.ids } } : undefined
87
- })
88
- ).map((plan) =>
89
- this.#dtoMappers.PlanDtoMapper.serializeEntityToDto(
90
- plan as Entities['PlanDtoMapper']
91
- )
92
- );
93
- }
94
-
95
- async createPlan(
96
- planDto: Dto['CreatePlanDtoMapper'],
97
- em?: EntityManager
98
- ): Promise<Dto['PlanDtoMapper']> {
99
- const plan =
100
- this.#dtoMappers.CreatePlanDtoMapper.deserializeDtoToEntity(planDto);
101
- await (em ?? this.em).transactional(async (innerEm) => {
102
- await innerEm.persist(plan);
103
- });
104
- return this.#dtoMappers.PlanDtoMapper.serializeEntityToDto(plan);
105
- }
106
-
107
- async getPlan(
108
- idDto: IdDto,
109
- em?: EntityManager
110
- ): Promise<Dto['PlanDtoMapper']> {
111
- const plan = await (em ?? this.em).findOneOrFail('Plan', idDto);
112
- return this.#dtoMappers.PlanDtoMapper.serializeEntityToDto(
113
- plan as Entities['PlanDtoMapper']
114
- );
115
- }
116
-
117
- async updatePlan(
118
- planDto: Dto['UpdatePlanDtoMapper'],
119
- em?: EntityManager
120
- ): Promise<Dto['PlanDtoMapper']> {
121
- const plan =
122
- this.#dtoMappers.UpdatePlanDtoMapper.deserializeDtoToEntity(planDto);
123
- const updatedPlan = await (em ?? this.em).upsert(plan);
124
- await (em ?? this.em).transactional(async (innerEm) => {
125
- await innerEm.persist(plan);
126
- });
127
- const updatedPlanDto =
128
- this.#dtoMappers.PlanDtoMapper.serializeEntityToDto(updatedPlan);
129
- return updatedPlanDto;
130
- }
131
-
132
- async deletePlan(idDto: { id: string }, em?: EntityManager): Promise<void> {
133
- await (em ?? this.em).nativeDelete('Plan', idDto);
134
- }
135
- }
@@ -1,239 +0,0 @@
1
- import {
2
- CreateSubscriptionDto,
3
- SubscriptionDto,
4
- SubscriptionService,
5
- UpdateSubscriptionDto
6
- } from '@forklaunch/interfaces-billing';
7
- import { IdDto, InstanceTypeRecord } from '@forklaunch/common';
8
- import {
9
- InternalDtoMapper,
10
- RequestDtoMapperConstructor,
11
- ResponseDtoMapperConstructor,
12
- transformIntoInternalDtoMapper
13
- } from '@forklaunch/core/dtoMapper';
14
- import {
15
- MetricsDefinition,
16
- OpenTelemetryCollector
17
- } from '@forklaunch/core/http';
18
- import { AnySchemaValidator } from '@forklaunch/validator';
19
- import { EntityManager } from '@mikro-orm/core';
20
-
21
- export class BaseSubscriptionService<
22
- SchemaValidator extends AnySchemaValidator,
23
- PartyType,
24
- BillingProviderType,
25
- Metrics extends MetricsDefinition = MetricsDefinition,
26
- Dto extends {
27
- SubscriptionDtoMapper: SubscriptionDto<PartyType, BillingProviderType>;
28
- CreateSubscriptionDtoMapper: CreateSubscriptionDto<
29
- PartyType,
30
- BillingProviderType
31
- >;
32
- UpdateSubscriptionDtoMapper: UpdateSubscriptionDto<
33
- PartyType,
34
- BillingProviderType
35
- >;
36
- } = {
37
- SubscriptionDtoMapper: SubscriptionDto<PartyType, BillingProviderType>;
38
- CreateSubscriptionDtoMapper: CreateSubscriptionDto<
39
- PartyType,
40
- BillingProviderType
41
- >;
42
- UpdateSubscriptionDtoMapper: UpdateSubscriptionDto<
43
- PartyType,
44
- BillingProviderType
45
- >;
46
- },
47
- Entities extends {
48
- SubscriptionDtoMapper: SubscriptionDto<PartyType, BillingProviderType>;
49
- CreateSubscriptionDtoMapper: SubscriptionDto<
50
- PartyType,
51
- BillingProviderType
52
- >;
53
- UpdateSubscriptionDtoMapper: SubscriptionDto<
54
- PartyType,
55
- BillingProviderType
56
- >;
57
- } = {
58
- SubscriptionDtoMapper: SubscriptionDto<PartyType, BillingProviderType>;
59
- CreateSubscriptionDtoMapper: SubscriptionDto<
60
- PartyType,
61
- BillingProviderType
62
- >;
63
- UpdateSubscriptionDtoMapper: SubscriptionDto<
64
- PartyType,
65
- BillingProviderType
66
- >;
67
- }
68
- > implements SubscriptionService<PartyType, BillingProviderType>
69
- {
70
- #dtoMappers: InternalDtoMapper<
71
- InstanceTypeRecord<typeof this.dtoMappers>,
72
- Entities,
73
- Dto
74
- >;
75
-
76
- constructor(
77
- protected em: EntityManager,
78
- protected readonly openTelemetryCollector: OpenTelemetryCollector<Metrics>,
79
- protected readonly schemaValidator: SchemaValidator,
80
- protected readonly dtoMappers: {
81
- SubscriptionDtoMapper: ResponseDtoMapperConstructor<
82
- SchemaValidator,
83
- Dto['SubscriptionDtoMapper'],
84
- Entities['SubscriptionDtoMapper']
85
- >;
86
- CreateSubscriptionDtoMapper: RequestDtoMapperConstructor<
87
- SchemaValidator,
88
- Dto['CreateSubscriptionDtoMapper'],
89
- Entities['CreateSubscriptionDtoMapper']
90
- >;
91
- UpdateSubscriptionDtoMapper: RequestDtoMapperConstructor<
92
- SchemaValidator,
93
- Dto['UpdateSubscriptionDtoMapper'],
94
- Entities['UpdateSubscriptionDtoMapper']
95
- >;
96
- }
97
- ) {
98
- this.#dtoMappers = transformIntoInternalDtoMapper<
99
- SchemaValidator,
100
- typeof this.dtoMappers,
101
- Entities,
102
- Dto
103
- >(dtoMappers, this.schemaValidator);
104
- }
105
-
106
- async createSubscription(
107
- subscriptionDto: Dto['CreateSubscriptionDtoMapper'],
108
- em?: EntityManager
109
- ): Promise<Dto['SubscriptionDtoMapper']> {
110
- const subscription =
111
- this.#dtoMappers.CreateSubscriptionDtoMapper.deserializeDtoToEntity(
112
- subscriptionDto
113
- );
114
- await (em ?? this.em).transactional(async (innerEm) => {
115
- await innerEm.persist(subscription);
116
- });
117
- const createdSubscriptionDto =
118
- this.#dtoMappers.SubscriptionDtoMapper.serializeEntityToDto(subscription);
119
- return createdSubscriptionDto;
120
- }
121
-
122
- async getSubscription(
123
- idDto: IdDto,
124
- em?: EntityManager
125
- ): Promise<Dto['SubscriptionDtoMapper']> {
126
- const subscription = await (em ?? this.em).findOneOrFail(
127
- 'Subscription',
128
- idDto
129
- );
130
- return this.#dtoMappers.SubscriptionDtoMapper.serializeEntityToDto(
131
- subscription as Entities['SubscriptionDtoMapper']
132
- );
133
- }
134
-
135
- async getUserSubscription(
136
- { id }: IdDto,
137
- em?: EntityManager
138
- ): Promise<Dto['SubscriptionDtoMapper']> {
139
- const subscription = await (em ?? this.em).findOneOrFail('Subscription', {
140
- partyId: id,
141
- partyType: 'USER',
142
- active: true
143
- });
144
-
145
- return this.#dtoMappers.SubscriptionDtoMapper.serializeEntityToDto(
146
- subscription as Entities['SubscriptionDtoMapper']
147
- );
148
- }
149
-
150
- async getOrganizationSubscription(
151
- { id }: IdDto,
152
- em?: EntityManager
153
- ): Promise<Dto['SubscriptionDtoMapper']> {
154
- const subscription = await (em ?? this.em).findOneOrFail('Subscription', {
155
- partyId: id,
156
- partyType: 'ORGANIZATION',
157
- active: true
158
- });
159
- return this.#dtoMappers.SubscriptionDtoMapper.serializeEntityToDto(
160
- subscription as Entities['SubscriptionDtoMapper']
161
- );
162
- }
163
-
164
- async updateSubscription(
165
- subscriptionDto: Dto['UpdateSubscriptionDtoMapper'],
166
- em?: EntityManager
167
- ): Promise<Dto['SubscriptionDtoMapper']> {
168
- const subscription =
169
- this.#dtoMappers.UpdateSubscriptionDtoMapper.deserializeDtoToEntity(
170
- subscriptionDto
171
- );
172
- const updatedSubscription = await (em ?? this.em).upsert(subscription);
173
- await (em ?? this.em).transactional(async (innerEm) => {
174
- await innerEm.persist(updatedSubscription);
175
- });
176
- const updatedSubscriptionDto =
177
- this.#dtoMappers.SubscriptionDtoMapper.serializeEntityToDto(
178
- updatedSubscription
179
- );
180
-
181
- return updatedSubscriptionDto;
182
- }
183
-
184
- async deleteSubscription(
185
- idDto: { id: string },
186
- em?: EntityManager
187
- ): Promise<void> {
188
- const subscription = await (em ?? this.em).findOne('Subscription', idDto);
189
- if (!subscription) {
190
- throw new Error('Subscription not found');
191
- }
192
- await (em ?? this.em).removeAndFlush(subscription);
193
- }
194
-
195
- async listSubscriptions(
196
- idsDto: { ids?: string[] },
197
- em?: EntityManager
198
- ): Promise<Dto['SubscriptionDtoMapper'][]> {
199
- const subscriptions = await (em ?? this.em).findAll('Subscription', {
200
- where: idsDto.ids
201
- ? {
202
- id: {
203
- $in: idsDto.ids
204
- }
205
- }
206
- : undefined
207
- });
208
-
209
- return subscriptions.map((subscription) => {
210
- const subscriptionDto =
211
- this.#dtoMappers.SubscriptionDtoMapper.serializeEntityToDto(
212
- subscription as Entities['SubscriptionDtoMapper']
213
- );
214
- return subscriptionDto;
215
- });
216
- }
217
-
218
- async cancelSubscription(idDto: IdDto, em?: EntityManager): Promise<void> {
219
- const subscription = await (em ?? this.em).findOne('Subscription', idDto);
220
- if (!subscription) {
221
- throw new Error('Subscription not found');
222
- }
223
- (subscription as Entities['SubscriptionDtoMapper']).active = false;
224
- await (em ?? this.em).transactional(async (innerEm) => {
225
- await innerEm.persist(subscription);
226
- });
227
- }
228
-
229
- async resumeSubscription(idDto: IdDto, em?: EntityManager): Promise<void> {
230
- const subscription = await (em ?? this.em).findOne('Subscription', idDto);
231
- if (!subscription) {
232
- throw new Error('Subscription not found');
233
- }
234
- (subscription as Entities['SubscriptionDtoMapper']).active = true;
235
- await (em ?? this.em).transactional(async (innerEm) => {
236
- await innerEm.persist(subscription);
237
- });
238
- }
239
- }
package/lib/index.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export * from './schemas/billingPortal.schema';
2
- export * from './schemas/checkoutSession.schema';
3
- export * from './schemas/paymentLink.schema';
4
- export * from './schemas/plan.schema';
5
- export * from './schemas/subscription.schema';
6
- export * from './services/billingPortal.service';
7
- export * from './services/checkoutSession.service';
8
- export * from './services/paymentLink.service';
9
- export * from './services/plan.service';
10
- export * from './services/subscription.service';
11
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,kCAAkC,CAAC;AACjD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,oCAAoC,CAAC;AACnD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC"}
package/lib/index.js DELETED
@@ -1,10 +0,0 @@
1
- export * from './schemas/billingPortal.schema';
2
- export * from './schemas/checkoutSession.schema';
3
- export * from './schemas/paymentLink.schema';
4
- export * from './schemas/plan.schema';
5
- export * from './schemas/subscription.schema';
6
- export * from './services/billingPortal.service';
7
- export * from './services/checkoutSession.service';
8
- export * from './services/paymentLink.service';
9
- export * from './services/plan.service';
10
- export * from './services/subscription.service';