@forklaunch/implementation-billing-base 0.1.17 → 0.2.0
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.
- package/lib/eject/domain/schemas/billingPortal.schema.ts +7 -1
- package/lib/eject/services/billingPortal.service.ts +13 -13
- package/lib/eject/services/checkoutSession.service.ts +11 -11
- package/lib/eject/services/paymentLink.service.ts +15 -19
- package/lib/eject/services/plan.service.ts +22 -20
- package/lib/eject/services/subscription.service.ts +28 -24
- package/lib/services/billingPortal.service.d.ts +6 -6
- package/lib/services/billingPortal.service.d.ts.map +1 -1
- package/lib/services/billingPortal.service.js +10 -10
- package/lib/services/checkoutSession.service.d.ts +6 -6
- package/lib/services/checkoutSession.service.d.ts.map +1 -1
- package/lib/services/checkoutSession.service.js +8 -8
- package/lib/services/paymentLink.service.d.ts +6 -6
- package/lib/services/paymentLink.service.d.ts.map +1 -1
- package/lib/services/paymentLink.service.js +12 -16
- package/lib/services/plan.service.d.ts +6 -6
- package/lib/services/plan.service.d.ts.map +1 -1
- package/lib/services/plan.service.js +17 -15
- package/lib/services/subscription.service.d.ts +6 -6
- package/lib/services/subscription.service.d.ts.map +1 -1
- package/lib/services/subscription.service.js +24 -18
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { IdDto, InstanceTypeRecord } from '@forklaunch/common';
|
|
2
2
|
import { createCacheKey, TtlCache } from '@forklaunch/core/cache';
|
|
3
|
+
import {
|
|
4
|
+
MetricsDefinition,
|
|
5
|
+
OpenTelemetryCollector
|
|
6
|
+
} from '@forklaunch/core/http';
|
|
3
7
|
import {
|
|
4
8
|
InternalDtoMapper,
|
|
5
9
|
RequestDtoMapperConstructor,
|
|
6
10
|
ResponseDtoMapperConstructor,
|
|
7
11
|
transformIntoInternalDtoMapper
|
|
8
12
|
} from '@forklaunch/core/mappers';
|
|
9
|
-
import {
|
|
10
|
-
MetricsDefinition,
|
|
11
|
-
OpenTelemetryCollector
|
|
12
|
-
} from '@forklaunch/core/http';
|
|
13
13
|
import { BillingPortalService } from '@forklaunch/interfaces-billing/interfaces';
|
|
14
14
|
import {
|
|
15
15
|
BillingPortalDto,
|
|
@@ -41,8 +41,8 @@ export class BaseBillingPortalService<
|
|
|
41
41
|
}
|
|
42
42
|
> implements BillingPortalService
|
|
43
43
|
{
|
|
44
|
-
#
|
|
45
|
-
InstanceTypeRecord<typeof this.
|
|
44
|
+
#mappers: InternalDtoMapper<
|
|
45
|
+
InstanceTypeRecord<typeof this.mappers>,
|
|
46
46
|
Entities,
|
|
47
47
|
Dto
|
|
48
48
|
>;
|
|
@@ -51,7 +51,7 @@ export class BaseBillingPortalService<
|
|
|
51
51
|
protected cache: TtlCache,
|
|
52
52
|
protected openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
53
53
|
protected schemaValidator: SchemaValidator,
|
|
54
|
-
protected
|
|
54
|
+
protected mappers: {
|
|
55
55
|
BillingPortalDtoMapper: ResponseDtoMapperConstructor<
|
|
56
56
|
SchemaValidator,
|
|
57
57
|
Dto['BillingPortalDtoMapper'],
|
|
@@ -69,7 +69,7 @@ export class BaseBillingPortalService<
|
|
|
69
69
|
>;
|
|
70
70
|
}
|
|
71
71
|
) {
|
|
72
|
-
this.#
|
|
72
|
+
this.#mappers = transformIntoInternalDtoMapper(mappers, schemaValidator);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
protected createCacheKey = createCacheKey('billing_portal_session');
|
|
@@ -78,7 +78,7 @@ export class BaseBillingPortalService<
|
|
|
78
78
|
billingPortalDto: Dto['CreateBillingPortalDtoMapper']
|
|
79
79
|
): Promise<Dto['BillingPortalDtoMapper']> {
|
|
80
80
|
const billingPortalSession =
|
|
81
|
-
this.#
|
|
81
|
+
await this.#mappers.CreateBillingPortalDtoMapper.deserializeDtoToEntity(
|
|
82
82
|
billingPortalDto
|
|
83
83
|
);
|
|
84
84
|
|
|
@@ -93,7 +93,7 @@ export class BaseBillingPortalService<
|
|
|
93
93
|
ttlMilliseconds: this.cache.getTtlMilliseconds()
|
|
94
94
|
});
|
|
95
95
|
|
|
96
|
-
return this.#
|
|
96
|
+
return this.#mappers.BillingPortalDtoMapper.serializeEntityToDto(
|
|
97
97
|
billingPortalSession
|
|
98
98
|
);
|
|
99
99
|
}
|
|
@@ -108,7 +108,7 @@ export class BaseBillingPortalService<
|
|
|
108
108
|
throw new Error('Session not found');
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
return this.#
|
|
111
|
+
return this.#mappers.BillingPortalDtoMapper.serializeEntityToDto(
|
|
112
112
|
billingPortalSessionDetails.value
|
|
113
113
|
);
|
|
114
114
|
}
|
|
@@ -117,7 +117,7 @@ export class BaseBillingPortalService<
|
|
|
117
117
|
billingPortalDto: UpdateBillingPortalDto
|
|
118
118
|
): Promise<Dto['BillingPortalDtoMapper']> {
|
|
119
119
|
const billingPortalSession =
|
|
120
|
-
this.#
|
|
120
|
+
await this.#mappers.UpdateBillingPortalDtoMapper.deserializeDtoToEntity(
|
|
121
121
|
billingPortalDto
|
|
122
122
|
);
|
|
123
123
|
// Save the updated session to your database or external service
|
|
@@ -127,7 +127,7 @@ export class BaseBillingPortalService<
|
|
|
127
127
|
ttlMilliseconds: this.cache.getTtlMilliseconds()
|
|
128
128
|
});
|
|
129
129
|
|
|
130
|
-
return this.#
|
|
130
|
+
return this.#mappers.BillingPortalDtoMapper.serializeEntityToDto(
|
|
131
131
|
billingPortalSession
|
|
132
132
|
);
|
|
133
133
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { IdDto, InstanceTypeRecord } from '@forklaunch/common';
|
|
2
2
|
import { createCacheKey, TtlCache } from '@forklaunch/core/cache';
|
|
3
|
+
import {
|
|
4
|
+
MetricsDefinition,
|
|
5
|
+
OpenTelemetryCollector
|
|
6
|
+
} from '@forklaunch/core/http';
|
|
3
7
|
import {
|
|
4
8
|
InternalDtoMapper,
|
|
5
9
|
RequestDtoMapperConstructor,
|
|
6
10
|
ResponseDtoMapperConstructor,
|
|
7
11
|
transformIntoInternalDtoMapper
|
|
8
12
|
} from '@forklaunch/core/mappers';
|
|
9
|
-
import {
|
|
10
|
-
MetricsDefinition,
|
|
11
|
-
OpenTelemetryCollector
|
|
12
|
-
} from '@forklaunch/core/http';
|
|
13
13
|
import { CheckoutSessionService } from '@forklaunch/interfaces-billing/interfaces';
|
|
14
14
|
import {
|
|
15
15
|
CheckoutSessionDto,
|
|
@@ -42,8 +42,8 @@ export class BaseCheckoutSessionService<
|
|
|
42
42
|
}
|
|
43
43
|
> implements CheckoutSessionService<PaymentMethodEnum>
|
|
44
44
|
{
|
|
45
|
-
#
|
|
46
|
-
InstanceTypeRecord<typeof this.
|
|
45
|
+
#mappers: InternalDtoMapper<
|
|
46
|
+
InstanceTypeRecord<typeof this.mappers>,
|
|
47
47
|
Entities,
|
|
48
48
|
Dto
|
|
49
49
|
>;
|
|
@@ -52,7 +52,7 @@ export class BaseCheckoutSessionService<
|
|
|
52
52
|
protected readonly cache: TtlCache,
|
|
53
53
|
protected readonly openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
54
54
|
protected readonly schemaValidator: SchemaValidator,
|
|
55
|
-
protected readonly
|
|
55
|
+
protected readonly mappers: {
|
|
56
56
|
CheckoutSessionDtoMapper: ResponseDtoMapperConstructor<
|
|
57
57
|
SchemaValidator,
|
|
58
58
|
Dto['CheckoutSessionDtoMapper'],
|
|
@@ -70,7 +70,7 @@ export class BaseCheckoutSessionService<
|
|
|
70
70
|
>;
|
|
71
71
|
}
|
|
72
72
|
) {
|
|
73
|
-
this.#
|
|
73
|
+
this.#mappers = transformIntoInternalDtoMapper(mappers, schemaValidator);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
protected createCacheKey = createCacheKey('checkout_session');
|
|
@@ -79,7 +79,7 @@ export class BaseCheckoutSessionService<
|
|
|
79
79
|
checkoutSessionDto: Dto['CreateCheckoutSessionDtoMapper']
|
|
80
80
|
): Promise<Dto['CheckoutSessionDtoMapper']> {
|
|
81
81
|
const checkoutSession =
|
|
82
|
-
this.#
|
|
82
|
+
await this.#mappers.CreateCheckoutSessionDtoMapper.deserializeDtoToEntity(
|
|
83
83
|
checkoutSessionDto
|
|
84
84
|
);
|
|
85
85
|
|
|
@@ -90,7 +90,7 @@ export class BaseCheckoutSessionService<
|
|
|
90
90
|
ttlMilliseconds: this.cache.getTtlMilliseconds()
|
|
91
91
|
});
|
|
92
92
|
|
|
93
|
-
return this.#
|
|
93
|
+
return this.#mappers.CheckoutSessionDtoMapper.serializeEntityToDto(
|
|
94
94
|
checkoutSession
|
|
95
95
|
);
|
|
96
96
|
}
|
|
@@ -105,7 +105,7 @@ export class BaseCheckoutSessionService<
|
|
|
105
105
|
throw new Error('Session not found');
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
return this.#
|
|
108
|
+
return this.#mappers.CheckoutSessionDtoMapper.serializeEntityToDto(
|
|
109
109
|
checkoutSessionDetails.value
|
|
110
110
|
);
|
|
111
111
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { IdDto, IdsDto, InstanceTypeRecord } from '@forklaunch/common';
|
|
2
2
|
import { createCacheKey, TtlCache } from '@forklaunch/core/cache';
|
|
3
|
+
import {
|
|
4
|
+
MetricsDefinition,
|
|
5
|
+
OpenTelemetryCollector
|
|
6
|
+
} from '@forklaunch/core/http';
|
|
3
7
|
import {
|
|
4
8
|
InternalDtoMapper,
|
|
5
9
|
RequestDtoMapperConstructor,
|
|
6
10
|
ResponseDtoMapperConstructor,
|
|
7
11
|
transformIntoInternalDtoMapper
|
|
8
12
|
} from '@forklaunch/core/mappers';
|
|
9
|
-
import {
|
|
10
|
-
MetricsDefinition,
|
|
11
|
-
OpenTelemetryCollector
|
|
12
|
-
} from '@forklaunch/core/http';
|
|
13
13
|
import { PaymentLinkService } from '@forklaunch/interfaces-billing/interfaces';
|
|
14
14
|
import {
|
|
15
15
|
CreatePaymentLinkDto,
|
|
@@ -42,8 +42,8 @@ export class BasePaymentLinkService<
|
|
|
42
42
|
}
|
|
43
43
|
> implements PaymentLinkService<CurrencyEnum>
|
|
44
44
|
{
|
|
45
|
-
#
|
|
46
|
-
InstanceTypeRecord<typeof this.
|
|
45
|
+
#mappers: InternalDtoMapper<
|
|
46
|
+
InstanceTypeRecord<typeof this.mappers>,
|
|
47
47
|
Entities,
|
|
48
48
|
Dto
|
|
49
49
|
>;
|
|
@@ -52,7 +52,7 @@ export class BasePaymentLinkService<
|
|
|
52
52
|
protected readonly cache: TtlCache,
|
|
53
53
|
protected readonly openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
54
54
|
protected readonly schemaValidator: SchemaValidator,
|
|
55
|
-
protected readonly
|
|
55
|
+
protected readonly mappers: {
|
|
56
56
|
PaymentLinkDtoMapper: ResponseDtoMapperConstructor<
|
|
57
57
|
SchemaValidator,
|
|
58
58
|
Dto['PaymentLinkDtoMapper'],
|
|
@@ -70,7 +70,7 @@ export class BasePaymentLinkService<
|
|
|
70
70
|
>;
|
|
71
71
|
}
|
|
72
72
|
) {
|
|
73
|
-
this.#
|
|
73
|
+
this.#mappers = transformIntoInternalDtoMapper(mappers, schemaValidator);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
protected cacheKeyPrefix = 'payment_link';
|
|
@@ -81,7 +81,7 @@ export class BasePaymentLinkService<
|
|
|
81
81
|
): Promise<Dto['PaymentLinkDtoMapper']> {
|
|
82
82
|
// TODO: Perform permission checks here
|
|
83
83
|
const paymentLink =
|
|
84
|
-
this.#
|
|
84
|
+
await this.#mappers.CreatePaymentLinkDtoMapper.deserializeDtoToEntity(
|
|
85
85
|
paymentLinkDto
|
|
86
86
|
);
|
|
87
87
|
await this.cache.putRecord({
|
|
@@ -90,9 +90,7 @@ export class BasePaymentLinkService<
|
|
|
90
90
|
ttlMilliseconds: this.cache.getTtlMilliseconds()
|
|
91
91
|
});
|
|
92
92
|
|
|
93
|
-
return this.#
|
|
94
|
-
paymentLink
|
|
95
|
-
);
|
|
93
|
+
return this.#mappers.PaymentLinkDtoMapper.serializeEntityToDto(paymentLink);
|
|
96
94
|
}
|
|
97
95
|
|
|
98
96
|
async updatePaymentLink(
|
|
@@ -105,7 +103,7 @@ export class BasePaymentLinkService<
|
|
|
105
103
|
throw new Error('Payment link not found');
|
|
106
104
|
}
|
|
107
105
|
const paymentLink =
|
|
108
|
-
this.#
|
|
106
|
+
await this.#mappers.UpdatePaymentLinkDtoMapper.deserializeDtoToEntity(
|
|
109
107
|
paymentLinkDto
|
|
110
108
|
);
|
|
111
109
|
const updatedLink = { ...existingLink, ...paymentLink };
|
|
@@ -115,9 +113,7 @@ export class BasePaymentLinkService<
|
|
|
115
113
|
ttlMilliseconds: this.cache.getTtlMilliseconds()
|
|
116
114
|
});
|
|
117
115
|
|
|
118
|
-
return this.#
|
|
119
|
-
updatedLink
|
|
120
|
-
);
|
|
116
|
+
return this.#mappers.PaymentLinkDtoMapper.serializeEntityToDto(updatedLink);
|
|
121
117
|
}
|
|
122
118
|
|
|
123
119
|
async getPaymentLink({ id }: IdDto): Promise<Dto['PaymentLinkDtoMapper']> {
|
|
@@ -128,7 +124,7 @@ export class BasePaymentLinkService<
|
|
|
128
124
|
throw new Error('Payment link not found');
|
|
129
125
|
}
|
|
130
126
|
|
|
131
|
-
return this.#
|
|
127
|
+
return this.#mappers.PaymentLinkDtoMapper.serializeEntityToDto(
|
|
132
128
|
paymentLink.value
|
|
133
129
|
);
|
|
134
130
|
}
|
|
@@ -155,12 +151,12 @@ export class BasePaymentLinkService<
|
|
|
155
151
|
idsDto?.ids.map((id) => this.createCacheKey(id)) ??
|
|
156
152
|
(await this.cache.listKeys(this.cacheKeyPrefix));
|
|
157
153
|
|
|
158
|
-
return
|
|
154
|
+
return Promise.all(
|
|
159
155
|
keys.map(async (key) => {
|
|
160
156
|
const paymentLink =
|
|
161
157
|
await this.cache.readRecord<Entities['PaymentLinkDtoMapper']>(key);
|
|
162
158
|
const paymentLinkDto =
|
|
163
|
-
this.#
|
|
159
|
+
this.#mappers.PaymentLinkDtoMapper.serializeEntityToDto(
|
|
164
160
|
paymentLink.value
|
|
165
161
|
);
|
|
166
162
|
return paymentLinkDto;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { IdDto, IdsDto, InstanceTypeRecord } from '@forklaunch/common';
|
|
2
|
+
import {
|
|
3
|
+
MetricsDefinition,
|
|
4
|
+
OpenTelemetryCollector
|
|
5
|
+
} from '@forklaunch/core/http';
|
|
2
6
|
import {
|
|
3
7
|
InternalDtoMapper,
|
|
4
8
|
RequestDtoMapperConstructor,
|
|
5
9
|
ResponseDtoMapperConstructor,
|
|
6
10
|
transformIntoInternalDtoMapper
|
|
7
11
|
} from '@forklaunch/core/mappers';
|
|
8
|
-
import {
|
|
9
|
-
MetricsDefinition,
|
|
10
|
-
OpenTelemetryCollector
|
|
11
|
-
} from '@forklaunch/core/http';
|
|
12
12
|
import { PlanService } from '@forklaunch/interfaces-billing/interfaces';
|
|
13
13
|
import {
|
|
14
14
|
CreatePlanDto,
|
|
@@ -43,8 +43,8 @@ export class BasePlanService<
|
|
|
43
43
|
}
|
|
44
44
|
> implements PlanService<PlanCadenceEnum, BillingProviderEnum>
|
|
45
45
|
{
|
|
46
|
-
#
|
|
47
|
-
InstanceTypeRecord<typeof this.
|
|
46
|
+
#mappers: InternalDtoMapper<
|
|
47
|
+
InstanceTypeRecord<typeof this.mappers>,
|
|
48
48
|
Entities,
|
|
49
49
|
Dto
|
|
50
50
|
>;
|
|
@@ -53,7 +53,7 @@ export class BasePlanService<
|
|
|
53
53
|
private em: EntityManager,
|
|
54
54
|
private readonly openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
55
55
|
private readonly schemaValidator: SchemaValidator,
|
|
56
|
-
private readonly
|
|
56
|
+
private readonly mappers: {
|
|
57
57
|
PlanDtoMapper: ResponseDtoMapperConstructor<
|
|
58
58
|
SchemaValidator,
|
|
59
59
|
Dto['PlanDtoMapper'],
|
|
@@ -71,20 +71,22 @@ export class BasePlanService<
|
|
|
71
71
|
>;
|
|
72
72
|
}
|
|
73
73
|
) {
|
|
74
|
-
this.#
|
|
74
|
+
this.#mappers = transformIntoInternalDtoMapper(mappers, schemaValidator);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
async listPlans(
|
|
78
78
|
idsDto?: IdsDto,
|
|
79
79
|
em?: EntityManager
|
|
80
80
|
): Promise<Dto['PlanDtoMapper'][]> {
|
|
81
|
-
return (
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
return Promise.all(
|
|
82
|
+
(
|
|
83
|
+
await (em ?? this.em).findAll('Plan', {
|
|
84
|
+
filters: idsDto?.ids ? { id: { $in: idsDto.ids } } : undefined
|
|
85
|
+
})
|
|
86
|
+
).map((plan) =>
|
|
87
|
+
this.#mappers.PlanDtoMapper.serializeEntityToDto(
|
|
88
|
+
plan as Entities['PlanDtoMapper']
|
|
89
|
+
)
|
|
88
90
|
)
|
|
89
91
|
);
|
|
90
92
|
}
|
|
@@ -94,11 +96,11 @@ export class BasePlanService<
|
|
|
94
96
|
em?: EntityManager
|
|
95
97
|
): Promise<Dto['PlanDtoMapper']> {
|
|
96
98
|
const plan =
|
|
97
|
-
this.#
|
|
99
|
+
await this.#mappers.CreatePlanDtoMapper.deserializeDtoToEntity(planDto);
|
|
98
100
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
99
101
|
await innerEm.persist(plan);
|
|
100
102
|
});
|
|
101
|
-
return this.#
|
|
103
|
+
return this.#mappers.PlanDtoMapper.serializeEntityToDto(plan);
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
async getPlan(
|
|
@@ -106,7 +108,7 @@ export class BasePlanService<
|
|
|
106
108
|
em?: EntityManager
|
|
107
109
|
): Promise<Dto['PlanDtoMapper']> {
|
|
108
110
|
const plan = await (em ?? this.em).findOneOrFail('Plan', idDto);
|
|
109
|
-
return this.#
|
|
111
|
+
return this.#mappers.PlanDtoMapper.serializeEntityToDto(
|
|
110
112
|
plan as Entities['PlanDtoMapper']
|
|
111
113
|
);
|
|
112
114
|
}
|
|
@@ -116,13 +118,13 @@ export class BasePlanService<
|
|
|
116
118
|
em?: EntityManager
|
|
117
119
|
): Promise<Dto['PlanDtoMapper']> {
|
|
118
120
|
const plan =
|
|
119
|
-
this.#
|
|
121
|
+
await this.#mappers.UpdatePlanDtoMapper.deserializeDtoToEntity(planDto);
|
|
120
122
|
const updatedPlan = await (em ?? this.em).upsert(plan);
|
|
121
123
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
122
124
|
await innerEm.persist(plan);
|
|
123
125
|
});
|
|
124
126
|
const updatedPlanDto =
|
|
125
|
-
this.#
|
|
127
|
+
await this.#mappers.PlanDtoMapper.serializeEntityToDto(updatedPlan);
|
|
126
128
|
return updatedPlanDto;
|
|
127
129
|
}
|
|
128
130
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { IdDto, InstanceTypeRecord } from '@forklaunch/common';
|
|
2
|
+
import {
|
|
3
|
+
MetricsDefinition,
|
|
4
|
+
OpenTelemetryCollector
|
|
5
|
+
} from '@forklaunch/core/http';
|
|
2
6
|
import {
|
|
3
7
|
InternalDtoMapper,
|
|
4
8
|
RequestDtoMapperConstructor,
|
|
5
9
|
ResponseDtoMapperConstructor,
|
|
6
10
|
transformIntoInternalDtoMapper
|
|
7
11
|
} from '@forklaunch/core/mappers';
|
|
8
|
-
import {
|
|
9
|
-
MetricsDefinition,
|
|
10
|
-
OpenTelemetryCollector
|
|
11
|
-
} from '@forklaunch/core/http';
|
|
12
12
|
import { SubscriptionService } from '@forklaunch/interfaces-billing/interfaces';
|
|
13
13
|
import {
|
|
14
14
|
CreateSubscriptionDto,
|
|
@@ -67,8 +67,8 @@ export class BaseSubscriptionService<
|
|
|
67
67
|
}
|
|
68
68
|
> implements SubscriptionService<PartyType, BillingProviderType>
|
|
69
69
|
{
|
|
70
|
-
#
|
|
71
|
-
InstanceTypeRecord<typeof this.
|
|
70
|
+
#mappers: InternalDtoMapper<
|
|
71
|
+
InstanceTypeRecord<typeof this.mappers>,
|
|
72
72
|
Entities,
|
|
73
73
|
Dto
|
|
74
74
|
>;
|
|
@@ -77,7 +77,7 @@ export class BaseSubscriptionService<
|
|
|
77
77
|
protected em: EntityManager,
|
|
78
78
|
protected readonly openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
79
79
|
protected readonly schemaValidator: SchemaValidator,
|
|
80
|
-
protected readonly
|
|
80
|
+
protected readonly mappers: {
|
|
81
81
|
SubscriptionDtoMapper: ResponseDtoMapperConstructor<
|
|
82
82
|
SchemaValidator,
|
|
83
83
|
Dto['SubscriptionDtoMapper'],
|
|
@@ -95,12 +95,12 @@ export class BaseSubscriptionService<
|
|
|
95
95
|
>;
|
|
96
96
|
}
|
|
97
97
|
) {
|
|
98
|
-
this.#
|
|
98
|
+
this.#mappers = transformIntoInternalDtoMapper<
|
|
99
99
|
SchemaValidator,
|
|
100
|
-
typeof this.
|
|
100
|
+
typeof this.mappers,
|
|
101
101
|
Entities,
|
|
102
102
|
Dto
|
|
103
|
-
>(
|
|
103
|
+
>(mappers, this.schemaValidator);
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
async createSubscription(
|
|
@@ -108,14 +108,16 @@ export class BaseSubscriptionService<
|
|
|
108
108
|
em?: EntityManager
|
|
109
109
|
): Promise<Dto['SubscriptionDtoMapper']> {
|
|
110
110
|
const subscription =
|
|
111
|
-
this.#
|
|
111
|
+
await this.#mappers.CreateSubscriptionDtoMapper.deserializeDtoToEntity(
|
|
112
112
|
subscriptionDto
|
|
113
113
|
);
|
|
114
114
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
115
115
|
await innerEm.persist(subscription);
|
|
116
116
|
});
|
|
117
117
|
const createdSubscriptionDto =
|
|
118
|
-
this.#
|
|
118
|
+
await this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
|
|
119
|
+
subscription
|
|
120
|
+
);
|
|
119
121
|
return createdSubscriptionDto;
|
|
120
122
|
}
|
|
121
123
|
|
|
@@ -127,7 +129,7 @@ export class BaseSubscriptionService<
|
|
|
127
129
|
'Subscription',
|
|
128
130
|
idDto
|
|
129
131
|
);
|
|
130
|
-
return this.#
|
|
132
|
+
return this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
|
|
131
133
|
subscription as Entities['SubscriptionDtoMapper']
|
|
132
134
|
);
|
|
133
135
|
}
|
|
@@ -142,7 +144,7 @@ export class BaseSubscriptionService<
|
|
|
142
144
|
active: true
|
|
143
145
|
});
|
|
144
146
|
|
|
145
|
-
return this.#
|
|
147
|
+
return this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
|
|
146
148
|
subscription as Entities['SubscriptionDtoMapper']
|
|
147
149
|
);
|
|
148
150
|
}
|
|
@@ -156,7 +158,7 @@ export class BaseSubscriptionService<
|
|
|
156
158
|
partyType: 'ORGANIZATION',
|
|
157
159
|
active: true
|
|
158
160
|
});
|
|
159
|
-
return this.#
|
|
161
|
+
return this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
|
|
160
162
|
subscription as Entities['SubscriptionDtoMapper']
|
|
161
163
|
);
|
|
162
164
|
}
|
|
@@ -166,7 +168,7 @@ export class BaseSubscriptionService<
|
|
|
166
168
|
em?: EntityManager
|
|
167
169
|
): Promise<Dto['SubscriptionDtoMapper']> {
|
|
168
170
|
const subscription =
|
|
169
|
-
this.#
|
|
171
|
+
this.#mappers.UpdateSubscriptionDtoMapper.deserializeDtoToEntity(
|
|
170
172
|
subscriptionDto
|
|
171
173
|
);
|
|
172
174
|
const updatedSubscription = await (em ?? this.em).upsert(subscription);
|
|
@@ -174,7 +176,7 @@ export class BaseSubscriptionService<
|
|
|
174
176
|
await innerEm.persist(updatedSubscription);
|
|
175
177
|
});
|
|
176
178
|
const updatedSubscriptionDto =
|
|
177
|
-
this.#
|
|
179
|
+
await this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
|
|
178
180
|
updatedSubscription
|
|
179
181
|
);
|
|
180
182
|
|
|
@@ -206,13 +208,15 @@ export class BaseSubscriptionService<
|
|
|
206
208
|
: undefined
|
|
207
209
|
});
|
|
208
210
|
|
|
209
|
-
return
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
211
|
+
return Promise.all(
|
|
212
|
+
subscriptions.map((subscription) => {
|
|
213
|
+
const subscriptionDto =
|
|
214
|
+
this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
|
|
215
|
+
subscription as Entities['SubscriptionDtoMapper']
|
|
216
|
+
);
|
|
217
|
+
return subscriptionDto;
|
|
218
|
+
})
|
|
219
|
+
);
|
|
216
220
|
}
|
|
217
221
|
|
|
218
222
|
async cancelSubscription(idDto: IdDto, em?: EntityManager): Promise<void> {
|
|
@@ -1,13 +1,13 @@
|
|
|
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
3
|
import {
|
|
8
4
|
MetricsDefinition,
|
|
9
5
|
OpenTelemetryCollector
|
|
10
6
|
} from '@forklaunch/core/http';
|
|
7
|
+
import {
|
|
8
|
+
RequestDtoMapperConstructor,
|
|
9
|
+
ResponseDtoMapperConstructor
|
|
10
|
+
} from '@forklaunch/core/mappers';
|
|
11
11
|
import { BillingPortalService } from '@forklaunch/interfaces-billing/interfaces';
|
|
12
12
|
import {
|
|
13
13
|
BillingPortalDto,
|
|
@@ -42,7 +42,7 @@ export declare class BaseBillingPortalService<
|
|
|
42
42
|
protected cache: TtlCache;
|
|
43
43
|
protected openTelemetryCollector: OpenTelemetryCollector<Metrics>;
|
|
44
44
|
protected schemaValidator: SchemaValidator;
|
|
45
|
-
protected
|
|
45
|
+
protected mappers: {
|
|
46
46
|
BillingPortalDtoMapper: ResponseDtoMapperConstructor<
|
|
47
47
|
SchemaValidator,
|
|
48
48
|
Dto['BillingPortalDtoMapper'],
|
|
@@ -63,7 +63,7 @@ export declare class BaseBillingPortalService<
|
|
|
63
63
|
cache: TtlCache,
|
|
64
64
|
openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
65
65
|
schemaValidator: SchemaValidator,
|
|
66
|
-
|
|
66
|
+
mappers: {
|
|
67
67
|
BillingPortalDtoMapper: ResponseDtoMapperConstructor<
|
|
68
68
|
SchemaValidator,
|
|
69
69
|
Dto['BillingPortalDtoMapper'],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"billingPortal.service.d.ts","sourceRoot":"","sources":["../../services/billingPortal.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAsB,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAkB,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,
|
|
1
|
+
{"version":3,"file":"billingPortal.service.d.ts","sourceRoot":"","sources":["../../services/billingPortal.service.ts"],"names":[],"mappings":"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"}
|
|
@@ -4,19 +4,19 @@ export class BaseBillingPortalService {
|
|
|
4
4
|
cache;
|
|
5
5
|
openTelemetryCollector;
|
|
6
6
|
schemaValidator;
|
|
7
|
-
|
|
8
|
-
#
|
|
9
|
-
constructor(cache, openTelemetryCollector, schemaValidator,
|
|
7
|
+
mappers;
|
|
8
|
+
#mappers;
|
|
9
|
+
constructor(cache, openTelemetryCollector, schemaValidator, mappers) {
|
|
10
10
|
this.cache = cache;
|
|
11
11
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
12
12
|
this.schemaValidator = schemaValidator;
|
|
13
|
-
this.
|
|
14
|
-
this.#
|
|
13
|
+
this.mappers = mappers;
|
|
14
|
+
this.#mappers = transformIntoInternalDtoMapper(mappers, schemaValidator);
|
|
15
15
|
}
|
|
16
16
|
createCacheKey = createCacheKey('billing_portal_session');
|
|
17
17
|
async createBillingPortalSession(billingPortalDto) {
|
|
18
18
|
const billingPortalSession =
|
|
19
|
-
this.#
|
|
19
|
+
await this.#mappers.CreateBillingPortalDtoMapper.deserializeDtoToEntity(
|
|
20
20
|
billingPortalDto
|
|
21
21
|
);
|
|
22
22
|
this.openTelemetryCollector.debug(
|
|
@@ -28,7 +28,7 @@ export class BaseBillingPortalService {
|
|
|
28
28
|
value: billingPortalSession,
|
|
29
29
|
ttlMilliseconds: this.cache.getTtlMilliseconds()
|
|
30
30
|
});
|
|
31
|
-
return this.#
|
|
31
|
+
return this.#mappers.BillingPortalDtoMapper.serializeEntityToDto(
|
|
32
32
|
billingPortalSession
|
|
33
33
|
);
|
|
34
34
|
}
|
|
@@ -39,13 +39,13 @@ export class BaseBillingPortalService {
|
|
|
39
39
|
if (!billingPortalSessionDetails) {
|
|
40
40
|
throw new Error('Session not found');
|
|
41
41
|
}
|
|
42
|
-
return this.#
|
|
42
|
+
return this.#mappers.BillingPortalDtoMapper.serializeEntityToDto(
|
|
43
43
|
billingPortalSessionDetails.value
|
|
44
44
|
);
|
|
45
45
|
}
|
|
46
46
|
async updateBillingPortalSession(billingPortalDto) {
|
|
47
47
|
const billingPortalSession =
|
|
48
|
-
this.#
|
|
48
|
+
await this.#mappers.UpdateBillingPortalDtoMapper.deserializeDtoToEntity(
|
|
49
49
|
billingPortalDto
|
|
50
50
|
);
|
|
51
51
|
// Save the updated session to your database or external service
|
|
@@ -54,7 +54,7 @@ export class BaseBillingPortalService {
|
|
|
54
54
|
value: billingPortalSession,
|
|
55
55
|
ttlMilliseconds: this.cache.getTtlMilliseconds()
|
|
56
56
|
});
|
|
57
|
-
return this.#
|
|
57
|
+
return this.#mappers.BillingPortalDtoMapper.serializeEntityToDto(
|
|
58
58
|
billingPortalSession
|
|
59
59
|
);
|
|
60
60
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
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
3
|
import {
|
|
8
4
|
MetricsDefinition,
|
|
9
5
|
OpenTelemetryCollector
|
|
10
6
|
} from '@forklaunch/core/http';
|
|
7
|
+
import {
|
|
8
|
+
RequestDtoMapperConstructor,
|
|
9
|
+
ResponseDtoMapperConstructor
|
|
10
|
+
} from '@forklaunch/core/mappers';
|
|
11
11
|
import { CheckoutSessionService } from '@forklaunch/interfaces-billing/interfaces';
|
|
12
12
|
import {
|
|
13
13
|
CheckoutSessionDto,
|
|
@@ -43,7 +43,7 @@ export declare class BaseCheckoutSessionService<
|
|
|
43
43
|
protected readonly cache: TtlCache;
|
|
44
44
|
protected readonly openTelemetryCollector: OpenTelemetryCollector<Metrics>;
|
|
45
45
|
protected readonly schemaValidator: SchemaValidator;
|
|
46
|
-
protected readonly
|
|
46
|
+
protected readonly mappers: {
|
|
47
47
|
CheckoutSessionDtoMapper: ResponseDtoMapperConstructor<
|
|
48
48
|
SchemaValidator,
|
|
49
49
|
Dto['CheckoutSessionDtoMapper'],
|
|
@@ -64,7 +64,7 @@ export declare class BaseCheckoutSessionService<
|
|
|
64
64
|
cache: TtlCache,
|
|
65
65
|
openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
66
66
|
schemaValidator: SchemaValidator,
|
|
67
|
-
|
|
67
|
+
mappers: {
|
|
68
68
|
CheckoutSessionDtoMapper: ResponseDtoMapperConstructor<
|
|
69
69
|
SchemaValidator,
|
|
70
70
|
Dto['CheckoutSessionDtoMapper'],
|