@forklaunch/implementation-billing-base 0.1.17 → 0.2.1
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/__test__/schemaEquality.test.js +35 -14
- package/lib/eject/domain/schemas/checkoutSession.schema.ts +24 -4
- package/lib/eject/domain/schemas/paymentLink.schema.ts +24 -4
- package/lib/eject/services/billingPortal.service.ts +104 -32
- package/lib/eject/services/checkoutSession.service.ts +115 -32
- package/lib/eject/services/paymentLink.service.ts +116 -41
- package/lib/eject/services/plan.service.ts +60 -22
- package/lib/eject/services/subscription.service.ts +83 -26
- package/lib/schemas/checkoutSession.schema.d.ts +97 -11
- package/lib/schemas/checkoutSession.schema.d.ts.map +1 -1
- package/lib/schemas/paymentLink.schema.d.ts +101 -12
- package/lib/schemas/paymentLink.schema.d.ts.map +1 -1
- package/lib/schemas/typebox/checkoutSession.schema.d.ts +130 -10
- package/lib/schemas/typebox/checkoutSession.schema.d.ts.map +1 -1
- package/lib/schemas/typebox/checkoutSession.schema.js +9 -3
- package/lib/schemas/typebox/paymentLink.schema.d.ts +144 -12
- package/lib/schemas/typebox/paymentLink.schema.d.ts.map +1 -1
- package/lib/schemas/typebox/paymentLink.schema.js +9 -3
- package/lib/schemas/zod/checkoutSession.schema.d.ts +66 -12
- package/lib/schemas/zod/checkoutSession.schema.d.ts.map +1 -1
- package/lib/schemas/zod/checkoutSession.schema.js +9 -3
- package/lib/schemas/zod/paymentLink.schema.d.ts +66 -12
- package/lib/schemas/zod/paymentLink.schema.d.ts.map +1 -1
- package/lib/schemas/zod/paymentLink.schema.js +9 -3
- package/lib/services/billingPortal.service.d.ts +25 -7
- package/lib/services/billingPortal.service.d.ts.map +1 -1
- package/lib/services/billingPortal.service.js +87 -29
- package/lib/services/checkoutSession.service.d.ts +63 -20
- package/lib/services/checkoutSession.service.d.ts.map +1 -1
- package/lib/services/checkoutSession.service.js +67 -16
- package/lib/services/paymentLink.service.d.ts +39 -20
- package/lib/services/paymentLink.service.d.ts.map +1 -1
- package/lib/services/paymentLink.service.js +88 -24
- package/lib/services/plan.service.d.ts +19 -7
- package/lib/services/plan.service.d.ts.map +1 -1
- package/lib/services/plan.service.js +49 -17
- package/lib/services/subscription.service.d.ts +21 -7
- package/lib/services/subscription.service.d.ts.map +1 -1
- package/lib/services/subscription.service.js +72 -20
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paymentLink.service.d.ts","sourceRoot":"","sources":["../../services/paymentLink.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAsB,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAkB,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAEL,
|
|
1
|
+
{"version":3,"file":"paymentLink.service.d.ts","sourceRoot":"","sources":["../../services/paymentLink.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAsB,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAkB,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAEL,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAEL,2BAA2B,EAC3B,4BAA4B,EAE7B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAC/E,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,oBAAoB,EACrB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,qBAAa,sBAAsB,CACjC,eAAe,SAAS,kBAAkB,EAC1C,YAAY,EACZ,UAAU,EACV,OAAO,SAAS,iBAAiB,GAAG,iBAAiB,EACrD,GAAG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B,CAAC,CAAC;IA6BjC,iBAAiB,CACrB,cAAc,EAAE,GAAG,CAAC,4BAA4B,CAAC,GAChD,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;IAsCjC,cAAc,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;IAgBnE,iBAAiB,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAa/C,oBAAoB,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAYlD,oBAAoB,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAYlD,gBAAgB,CACpB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,EAAE,CAAC;CAiB1C"}
|
|
@@ -1,86 +1,150 @@
|
|
|
1
1
|
import { createCacheKey } from '@forklaunch/core/cache';
|
|
2
|
+
import { evaluateTelemetryOptions } from '@forklaunch/core/http';
|
|
2
3
|
import { transformIntoInternalDtoMapper } from '@forklaunch/core/mappers';
|
|
3
4
|
export class BasePaymentLinkService {
|
|
5
|
+
em;
|
|
4
6
|
cache;
|
|
5
7
|
openTelemetryCollector;
|
|
6
8
|
schemaValidator;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
mappers;
|
|
10
|
+
options;
|
|
11
|
+
#mappers;
|
|
12
|
+
evaluatedTelemetryOptions;
|
|
13
|
+
enableDatabaseBackup;
|
|
14
|
+
constructor(
|
|
15
|
+
em,
|
|
16
|
+
cache,
|
|
17
|
+
openTelemetryCollector,
|
|
18
|
+
schemaValidator,
|
|
19
|
+
mappers,
|
|
20
|
+
options
|
|
21
|
+
) {
|
|
22
|
+
this.em = em;
|
|
10
23
|
this.cache = cache;
|
|
11
24
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
12
25
|
this.schemaValidator = schemaValidator;
|
|
13
|
-
this.
|
|
14
|
-
this
|
|
26
|
+
this.mappers = mappers;
|
|
27
|
+
this.options = options;
|
|
28
|
+
this.#mappers = transformIntoInternalDtoMapper(mappers, schemaValidator);
|
|
29
|
+
this.enableDatabaseBackup = options?.enableDatabaseBackup ?? false;
|
|
30
|
+
this.evaluatedTelemetryOptions = options?.telemetry
|
|
31
|
+
? evaluateTelemetryOptions(options.telemetry).enabled
|
|
32
|
+
: {
|
|
33
|
+
logging: false,
|
|
34
|
+
metrics: false,
|
|
35
|
+
tracing: false
|
|
36
|
+
};
|
|
15
37
|
}
|
|
16
38
|
cacheKeyPrefix = 'payment_link';
|
|
17
39
|
createCacheKey = createCacheKey(this.cacheKeyPrefix);
|
|
18
40
|
async createPaymentLink(paymentLinkDto) {
|
|
19
|
-
|
|
41
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
42
|
+
this.openTelemetryCollector.info('Creating payment link', paymentLinkDto);
|
|
43
|
+
}
|
|
20
44
|
const paymentLink =
|
|
21
|
-
this.#
|
|
22
|
-
paymentLinkDto
|
|
45
|
+
await this.#mappers.CreatePaymentLinkDtoMapper.deserializeDtoToEntity(
|
|
46
|
+
paymentLinkDto,
|
|
47
|
+
this.em
|
|
48
|
+
);
|
|
49
|
+
if (this.enableDatabaseBackup) {
|
|
50
|
+
await this.em.persistAndFlush(paymentLink);
|
|
51
|
+
}
|
|
52
|
+
const createdPaymentLinkDto =
|
|
53
|
+
await this.#mappers.PaymentLinkDtoMapper.serializeEntityToDto(
|
|
54
|
+
paymentLink
|
|
23
55
|
);
|
|
24
56
|
await this.cache.putRecord({
|
|
25
|
-
key: this.createCacheKey(
|
|
26
|
-
value:
|
|
57
|
+
key: this.createCacheKey(createdPaymentLinkDto.id),
|
|
58
|
+
value: createdPaymentLinkDto,
|
|
27
59
|
ttlMilliseconds: this.cache.getTtlMilliseconds()
|
|
28
60
|
});
|
|
29
|
-
return
|
|
30
|
-
paymentLink
|
|
31
|
-
);
|
|
61
|
+
return createdPaymentLinkDto;
|
|
32
62
|
}
|
|
33
63
|
async updatePaymentLink(paymentLinkDto) {
|
|
64
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
65
|
+
this.openTelemetryCollector.info('Updating payment link', paymentLinkDto);
|
|
66
|
+
}
|
|
34
67
|
const cacheKey = this.createCacheKey(paymentLinkDto.id);
|
|
35
|
-
const existingLink = await this.cache.readRecord(cacheKey);
|
|
68
|
+
const existingLink = (await this.cache.readRecord(cacheKey))?.value;
|
|
36
69
|
if (!existingLink) {
|
|
37
70
|
throw new Error('Payment link not found');
|
|
38
71
|
}
|
|
39
72
|
const paymentLink =
|
|
40
|
-
this.#
|
|
41
|
-
paymentLinkDto
|
|
73
|
+
await this.#mappers.UpdatePaymentLinkDtoMapper.deserializeDtoToEntity(
|
|
74
|
+
paymentLinkDto,
|
|
75
|
+
this.em
|
|
42
76
|
);
|
|
43
|
-
|
|
77
|
+
if (this.enableDatabaseBackup) {
|
|
78
|
+
await this.em.persistAndFlush(paymentLink);
|
|
79
|
+
}
|
|
80
|
+
const updatedLinkDto = {
|
|
81
|
+
...existingLink,
|
|
82
|
+
...(await this.#mappers.PaymentLinkDtoMapper.serializeEntityToDto(
|
|
83
|
+
paymentLink
|
|
84
|
+
))
|
|
85
|
+
};
|
|
44
86
|
await this.cache.putRecord({
|
|
45
87
|
key: cacheKey,
|
|
46
|
-
value:
|
|
88
|
+
value: updatedLinkDto,
|
|
47
89
|
ttlMilliseconds: this.cache.getTtlMilliseconds()
|
|
48
90
|
});
|
|
49
|
-
return
|
|
50
|
-
updatedLink
|
|
51
|
-
);
|
|
91
|
+
return updatedLinkDto;
|
|
52
92
|
}
|
|
53
93
|
async getPaymentLink({ id }) {
|
|
94
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
95
|
+
this.openTelemetryCollector.info('Getting payment link', { id });
|
|
96
|
+
}
|
|
54
97
|
const cacheKey = this.createCacheKey(id);
|
|
55
98
|
const paymentLink = await this.cache.readRecord(cacheKey);
|
|
56
99
|
if (!paymentLink) {
|
|
57
100
|
throw new Error('Payment link not found');
|
|
58
101
|
}
|
|
59
|
-
return this.#
|
|
102
|
+
return this.#mappers.PaymentLinkDtoMapper.serializeEntityToDto(
|
|
60
103
|
paymentLink.value
|
|
61
104
|
);
|
|
62
105
|
}
|
|
63
106
|
async expirePaymentLink({ id }) {
|
|
64
107
|
this.openTelemetryCollector.info('Payment link expired', { id });
|
|
108
|
+
if (this.enableDatabaseBackup) {
|
|
109
|
+
const paymentLink = await this.em.upsert('PaymentLink', {
|
|
110
|
+
id,
|
|
111
|
+
status: 'EXPIRED'
|
|
112
|
+
});
|
|
113
|
+
await this.em.removeAndFlush(paymentLink);
|
|
114
|
+
}
|
|
65
115
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
66
116
|
}
|
|
67
117
|
async handlePaymentSuccess({ id }) {
|
|
68
118
|
this.openTelemetryCollector.info('Payment link success', { id });
|
|
119
|
+
if (this.enableDatabaseBackup) {
|
|
120
|
+
const paymentLink = await this.em.upsert('PaymentLink', {
|
|
121
|
+
id,
|
|
122
|
+
status: 'COMPLETED'
|
|
123
|
+
});
|
|
124
|
+
await this.em.removeAndFlush(paymentLink);
|
|
125
|
+
}
|
|
69
126
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
70
127
|
}
|
|
71
128
|
async handlePaymentFailure({ id }) {
|
|
72
129
|
this.openTelemetryCollector.info('Payment link failure', { id });
|
|
130
|
+
if (this.enableDatabaseBackup) {
|
|
131
|
+
const paymentLink = await this.em.upsert('PaymentLink', {
|
|
132
|
+
id,
|
|
133
|
+
status: 'FAILED'
|
|
134
|
+
});
|
|
135
|
+
await this.em.removeAndFlush(paymentLink);
|
|
136
|
+
}
|
|
73
137
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
74
138
|
}
|
|
75
139
|
async listPaymentLinks(idsDto) {
|
|
76
140
|
const keys =
|
|
77
141
|
idsDto?.ids.map((id) => this.createCacheKey(id)) ??
|
|
78
142
|
(await this.cache.listKeys(this.cacheKeyPrefix));
|
|
79
|
-
return
|
|
143
|
+
return Promise.all(
|
|
80
144
|
keys.map(async (key) => {
|
|
81
145
|
const paymentLink = await this.cache.readRecord(key);
|
|
82
146
|
const paymentLinkDto =
|
|
83
|
-
this.#
|
|
147
|
+
this.#mappers.PaymentLinkDtoMapper.serializeEntityToDto(
|
|
84
148
|
paymentLink.value
|
|
85
149
|
);
|
|
86
150
|
return paymentLinkDto;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { IdDto, IdsDto } from '@forklaunch/common';
|
|
2
|
+
import {
|
|
3
|
+
MetricsDefinition,
|
|
4
|
+
OpenTelemetryCollector,
|
|
5
|
+
TelemetryOptions
|
|
6
|
+
} from '@forklaunch/core/http';
|
|
2
7
|
import {
|
|
3
8
|
RequestDtoMapperConstructor,
|
|
4
9
|
ResponseDtoMapperConstructor
|
|
5
10
|
} from '@forklaunch/core/mappers';
|
|
6
|
-
import {
|
|
7
|
-
MetricsDefinition,
|
|
8
|
-
OpenTelemetryCollector
|
|
9
|
-
} from '@forklaunch/core/http';
|
|
10
11
|
import { PlanService } from '@forklaunch/interfaces-billing/interfaces';
|
|
11
12
|
import {
|
|
12
13
|
CreatePlanDto,
|
|
@@ -44,12 +45,18 @@ export declare class BasePlanService<
|
|
|
44
45
|
private em;
|
|
45
46
|
private readonly openTelemetryCollector;
|
|
46
47
|
private readonly schemaValidator;
|
|
47
|
-
private readonly
|
|
48
|
+
private readonly mappers;
|
|
49
|
+
readonly options?:
|
|
50
|
+
| {
|
|
51
|
+
telemetry?: TelemetryOptions;
|
|
52
|
+
}
|
|
53
|
+
| undefined;
|
|
54
|
+
private evaluatedTelemetryOptions;
|
|
48
55
|
constructor(
|
|
49
56
|
em: EntityManager,
|
|
50
57
|
openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
51
58
|
schemaValidator: SchemaValidator,
|
|
52
|
-
|
|
59
|
+
mappers: {
|
|
53
60
|
PlanDtoMapper: ResponseDtoMapperConstructor<
|
|
54
61
|
SchemaValidator,
|
|
55
62
|
Dto['PlanDtoMapper'],
|
|
@@ -65,7 +72,12 @@ export declare class BasePlanService<
|
|
|
65
72
|
Dto['UpdatePlanDtoMapper'],
|
|
66
73
|
Entities['UpdatePlanDtoMapper']
|
|
67
74
|
>;
|
|
68
|
-
}
|
|
75
|
+
},
|
|
76
|
+
options?:
|
|
77
|
+
| {
|
|
78
|
+
telemetry?: TelemetryOptions;
|
|
79
|
+
}
|
|
80
|
+
| undefined
|
|
69
81
|
);
|
|
70
82
|
listPlans(
|
|
71
83
|
idsDto?: IdsDto,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plan.service.d.ts","sourceRoot":"","sources":["../../services/plan.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAsB,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAEL,
|
|
1
|
+
{"version":3,"file":"plan.service.d.ts","sourceRoot":"","sources":["../../services/plan.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAsB,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAEL,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAEL,2BAA2B,EAC3B,4BAA4B,EAE7B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AACxE,OAAO,EACL,aAAa,EACb,OAAO,EACP,aAAa,EACd,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,qBAAa,eAAe,CAC1B,eAAe,SAAS,kBAAkB,EAC1C,eAAe,EACf,mBAAmB,EACnB,OAAO,SAAS,iBAAiB,G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} from '@forklaunch/core/mappers';
|
|
2
3
|
export class BasePlanService {
|
|
3
4
|
em;
|
|
4
5
|
openTelemetryCollector;
|
|
5
6
|
schemaValidator;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
mappers;
|
|
8
|
+
options;
|
|
9
|
+
#mappers;
|
|
10
|
+
evaluatedTelemetryOptions;
|
|
11
|
+
constructor(em, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
9
12
|
this.em = em;
|
|
10
13
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
11
14
|
this.schemaValidator = schemaValidator;
|
|
12
|
-
this.
|
|
13
|
-
this
|
|
15
|
+
this.mappers = mappers;
|
|
16
|
+
this.options = options;
|
|
17
|
+
this.#mappers = transformIntoInternalDtoMapper(mappers, schemaValidator);
|
|
18
|
+
this.evaluatedTelemetryOptions = options?.telemetry
|
|
19
|
+
? evaluateTelemetryOptions(options.telemetry).enabled
|
|
20
|
+
: {
|
|
21
|
+
logging: false,
|
|
22
|
+
metrics: false,
|
|
23
|
+
tracing: false
|
|
24
|
+
};
|
|
14
25
|
}
|
|
15
26
|
async listPlans(idsDto, em) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
28
|
+
this.openTelemetryCollector.info('Listing plans', idsDto);
|
|
29
|
+
}
|
|
30
|
+
return Promise.all(
|
|
31
|
+
(
|
|
32
|
+
await (em ?? this.em).findAll('Plan', {
|
|
33
|
+
filters: idsDto?.ids ? { id: { $in: idsDto.ids } } : undefined
|
|
34
|
+
})
|
|
35
|
+
).map((plan) => this.#mappers.PlanDtoMapper.serializeEntityToDto(plan))
|
|
36
|
+
);
|
|
21
37
|
}
|
|
22
38
|
async createPlan(planDto, em) {
|
|
23
|
-
|
|
24
|
-
this
|
|
39
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
40
|
+
this.openTelemetryCollector.info('Creating plan', planDto);
|
|
41
|
+
}
|
|
42
|
+
const plan = await this.#mappers.CreatePlanDtoMapper.deserializeDtoToEntity(
|
|
43
|
+
planDto,
|
|
44
|
+
em ?? this.em
|
|
45
|
+
);
|
|
25
46
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
26
47
|
await innerEm.persist(plan);
|
|
27
48
|
});
|
|
28
|
-
return this.#
|
|
49
|
+
return this.#mappers.PlanDtoMapper.serializeEntityToDto(plan);
|
|
29
50
|
}
|
|
30
51
|
async getPlan(idDto, em) {
|
|
52
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
53
|
+
this.openTelemetryCollector.info('Getting plan', idDto);
|
|
54
|
+
}
|
|
31
55
|
const plan = await (em ?? this.em).findOneOrFail('Plan', idDto);
|
|
32
|
-
return this.#
|
|
56
|
+
return this.#mappers.PlanDtoMapper.serializeEntityToDto(plan);
|
|
33
57
|
}
|
|
34
58
|
async updatePlan(planDto, em) {
|
|
35
|
-
|
|
36
|
-
this
|
|
59
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
60
|
+
this.openTelemetryCollector.info('Updating plan', planDto);
|
|
61
|
+
}
|
|
62
|
+
const plan = await this.#mappers.UpdatePlanDtoMapper.deserializeDtoToEntity(
|
|
63
|
+
planDto,
|
|
64
|
+
em ?? this.em
|
|
65
|
+
);
|
|
37
66
|
const updatedPlan = await (em ?? this.em).upsert(plan);
|
|
38
67
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
39
68
|
await innerEm.persist(plan);
|
|
40
69
|
});
|
|
41
70
|
const updatedPlanDto =
|
|
42
|
-
this.#
|
|
71
|
+
await this.#mappers.PlanDtoMapper.serializeEntityToDto(updatedPlan);
|
|
43
72
|
return updatedPlanDto;
|
|
44
73
|
}
|
|
45
74
|
async deletePlan(idDto, em) {
|
|
75
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
76
|
+
this.openTelemetryCollector.info('Deleting plan', idDto);
|
|
77
|
+
}
|
|
46
78
|
await (em ?? this.em).nativeDelete('Plan', idDto);
|
|
47
79
|
}
|
|
48
80
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { IdDto } from '@forklaunch/common';
|
|
2
|
+
import {
|
|
3
|
+
MetricsDefinition,
|
|
4
|
+
OpenTelemetryCollector,
|
|
5
|
+
TelemetryOptions
|
|
6
|
+
} from '@forklaunch/core/http';
|
|
2
7
|
import {
|
|
3
8
|
RequestDtoMapperConstructor,
|
|
4
9
|
ResponseDtoMapperConstructor
|
|
5
10
|
} from '@forklaunch/core/mappers';
|
|
6
|
-
import {
|
|
7
|
-
MetricsDefinition,
|
|
8
|
-
OpenTelemetryCollector
|
|
9
|
-
} from '@forklaunch/core/http';
|
|
10
11
|
import { SubscriptionService } from '@forklaunch/interfaces-billing/interfaces';
|
|
11
12
|
import {
|
|
12
13
|
CreateSubscriptionDto,
|
|
@@ -68,7 +69,7 @@ export declare class BaseSubscriptionService<
|
|
|
68
69
|
protected em: EntityManager;
|
|
69
70
|
protected readonly openTelemetryCollector: OpenTelemetryCollector<Metrics>;
|
|
70
71
|
protected readonly schemaValidator: SchemaValidator;
|
|
71
|
-
protected readonly
|
|
72
|
+
protected readonly mappers: {
|
|
72
73
|
SubscriptionDtoMapper: ResponseDtoMapperConstructor<
|
|
73
74
|
SchemaValidator,
|
|
74
75
|
Dto['SubscriptionDtoMapper'],
|
|
@@ -85,11 +86,18 @@ export declare class BaseSubscriptionService<
|
|
|
85
86
|
Entities['UpdateSubscriptionDtoMapper']
|
|
86
87
|
>;
|
|
87
88
|
};
|
|
89
|
+
readonly options?:
|
|
90
|
+
| {
|
|
91
|
+
enableDatabaseBackup?: boolean;
|
|
92
|
+
telemetry?: TelemetryOptions;
|
|
93
|
+
}
|
|
94
|
+
| undefined;
|
|
95
|
+
private evaluatedTelemetryOptions;
|
|
88
96
|
constructor(
|
|
89
97
|
em: EntityManager,
|
|
90
98
|
openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
91
99
|
schemaValidator: SchemaValidator,
|
|
92
|
-
|
|
100
|
+
mappers: {
|
|
93
101
|
SubscriptionDtoMapper: ResponseDtoMapperConstructor<
|
|
94
102
|
SchemaValidator,
|
|
95
103
|
Dto['SubscriptionDtoMapper'],
|
|
@@ -105,7 +113,13 @@ export declare class BaseSubscriptionService<
|
|
|
105
113
|
Dto['UpdateSubscriptionDtoMapper'],
|
|
106
114
|
Entities['UpdateSubscriptionDtoMapper']
|
|
107
115
|
>;
|
|
108
|
-
}
|
|
116
|
+
},
|
|
117
|
+
options?:
|
|
118
|
+
| {
|
|
119
|
+
enableDatabaseBackup?: boolean;
|
|
120
|
+
telemetry?: TelemetryOptions;
|
|
121
|
+
}
|
|
122
|
+
| undefined
|
|
109
123
|
);
|
|
110
124
|
createSubscription(
|
|
111
125
|
subscriptionDto: Dto['CreateSubscriptionDtoMapper'],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.service.d.ts","sourceRoot":"","sources":["../../services/subscription.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAsB,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAEL,
|
|
1
|
+
{"version":3,"file":"subscription.service.d.ts","sourceRoot":"","sources":["../../services/subscription.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAsB,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAEL,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAEL,2BAA2B,EAC3B,4BAA4B,EAE7B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAChF,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,qBAAqB,EACtB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,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e,CACnB,KAAK,EAAE,KAAK,EACZ,EAAE,CAAC,EAAE,aAAa,GACjB,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;IAalC,mBAAmB,CACvB,EAAE,EAAE,EAAE,EAAE,KAAK,EACb,EAAE,CAAC,EAAE,aAAa,GACjB,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;IAelC,2BAA2B,CAC/B,EAAE,EAAE,EAAE,EAAE,KAAK,EACb,EAAE,CAAC,EAAE,aAAa,GACjB,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;IAclC,kBAAkB,CACtB,eAAe,EAAE,GAAG,CAAC,6BAA6B,CAAC,EACnD,EAAE,CAAC,EAAE,aAAa,GACjB,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;IAwBlC,kBAAkB,CACtB,KAAK,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,EACrB,EAAE,CAAC,EAAE,aAAa,GACjB,OAAO,CAAC,IAAI,CAAC;IAWV,iBAAiB,CACrB,MAAM,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,EAC1B,EAAE,CAAC,EAAE,aAAa,GACjB,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,EAAE,CAAC;IAyBpC,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAcnE,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAa1E"}
|
|
@@ -1,77 +1,116 @@
|
|
|
1
|
+
import { evaluateTelemetryOptions } from '@forklaunch/core/http';
|
|
1
2
|
import { transformIntoInternalDtoMapper } from '@forklaunch/core/mappers';
|
|
2
3
|
export class BaseSubscriptionService {
|
|
3
4
|
em;
|
|
4
5
|
openTelemetryCollector;
|
|
5
6
|
schemaValidator;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
mappers;
|
|
8
|
+
options;
|
|
9
|
+
#mappers;
|
|
10
|
+
evaluatedTelemetryOptions;
|
|
11
|
+
constructor(em, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
9
12
|
this.em = em;
|
|
10
13
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
11
14
|
this.schemaValidator = schemaValidator;
|
|
12
|
-
this.
|
|
13
|
-
this
|
|
14
|
-
|
|
15
|
+
this.mappers = mappers;
|
|
16
|
+
this.options = options;
|
|
17
|
+
this.#mappers = transformIntoInternalDtoMapper(
|
|
18
|
+
mappers,
|
|
15
19
|
this.schemaValidator
|
|
16
20
|
);
|
|
21
|
+
this.evaluatedTelemetryOptions = options?.telemetry
|
|
22
|
+
? evaluateTelemetryOptions(options.telemetry).enabled
|
|
23
|
+
: {
|
|
24
|
+
logging: false,
|
|
25
|
+
metrics: false,
|
|
26
|
+
tracing: false
|
|
27
|
+
};
|
|
17
28
|
}
|
|
18
29
|
async createSubscription(subscriptionDto, em) {
|
|
19
|
-
|
|
20
|
-
this
|
|
30
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
31
|
+
this.openTelemetryCollector.info(
|
|
32
|
+
'Creating subscription',
|
|
21
33
|
subscriptionDto
|
|
22
34
|
);
|
|
35
|
+
}
|
|
36
|
+
const subscription =
|
|
37
|
+
await this.#mappers.CreateSubscriptionDtoMapper.deserializeDtoToEntity(
|
|
38
|
+
subscriptionDto,
|
|
39
|
+
em ?? this.em
|
|
40
|
+
);
|
|
23
41
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
24
42
|
await innerEm.persist(subscription);
|
|
25
43
|
});
|
|
26
44
|
const createdSubscriptionDto =
|
|
27
|
-
this.#
|
|
45
|
+
await this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
|
|
46
|
+
subscription
|
|
47
|
+
);
|
|
28
48
|
return createdSubscriptionDto;
|
|
29
49
|
}
|
|
30
50
|
async getSubscription(idDto, em) {
|
|
51
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
52
|
+
this.openTelemetryCollector.info('Getting subscription', idDto);
|
|
53
|
+
}
|
|
31
54
|
const subscription = await (em ?? this.em).findOneOrFail(
|
|
32
55
|
'Subscription',
|
|
33
56
|
idDto
|
|
34
57
|
);
|
|
35
|
-
return this.#
|
|
58
|
+
return this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
|
|
36
59
|
subscription
|
|
37
60
|
);
|
|
38
61
|
}
|
|
39
62
|
async getUserSubscription({ id }, em) {
|
|
63
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
64
|
+
this.openTelemetryCollector.info('Getting user subscription', id);
|
|
65
|
+
}
|
|
40
66
|
const subscription = await (em ?? this.em).findOneOrFail('Subscription', {
|
|
41
67
|
partyId: id,
|
|
42
68
|
partyType: 'USER',
|
|
43
69
|
active: true
|
|
44
70
|
});
|
|
45
|
-
return this.#
|
|
71
|
+
return this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
|
|
46
72
|
subscription
|
|
47
73
|
);
|
|
48
74
|
}
|
|
49
75
|
async getOrganizationSubscription({ id }, em) {
|
|
76
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
77
|
+
this.openTelemetryCollector.info('Getting organization subscription', id);
|
|
78
|
+
}
|
|
50
79
|
const subscription = await (em ?? this.em).findOneOrFail('Subscription', {
|
|
51
80
|
partyId: id,
|
|
52
81
|
partyType: 'ORGANIZATION',
|
|
53
82
|
active: true
|
|
54
83
|
});
|
|
55
|
-
return this.#
|
|
84
|
+
return this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
|
|
56
85
|
subscription
|
|
57
86
|
);
|
|
58
87
|
}
|
|
59
88
|
async updateSubscription(subscriptionDto, em) {
|
|
60
|
-
|
|
61
|
-
this
|
|
89
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
90
|
+
this.openTelemetryCollector.info(
|
|
91
|
+
'Updating subscription',
|
|
62
92
|
subscriptionDto
|
|
63
93
|
);
|
|
94
|
+
}
|
|
95
|
+
const subscription =
|
|
96
|
+
this.#mappers.UpdateSubscriptionDtoMapper.deserializeDtoToEntity(
|
|
97
|
+
subscriptionDto,
|
|
98
|
+
em ?? this.em
|
|
99
|
+
);
|
|
64
100
|
const updatedSubscription = await (em ?? this.em).upsert(subscription);
|
|
65
101
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
66
102
|
await innerEm.persist(updatedSubscription);
|
|
67
103
|
});
|
|
68
104
|
const updatedSubscriptionDto =
|
|
69
|
-
this.#
|
|
105
|
+
await this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
|
|
70
106
|
updatedSubscription
|
|
71
107
|
);
|
|
72
108
|
return updatedSubscriptionDto;
|
|
73
109
|
}
|
|
74
110
|
async deleteSubscription(idDto, em) {
|
|
111
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
112
|
+
this.openTelemetryCollector.info('Deleting subscription', idDto);
|
|
113
|
+
}
|
|
75
114
|
const subscription = await (em ?? this.em).findOne('Subscription', idDto);
|
|
76
115
|
if (!subscription) {
|
|
77
116
|
throw new Error('Subscription not found');
|
|
@@ -79,6 +118,9 @@ export class BaseSubscriptionService {
|
|
|
79
118
|
await (em ?? this.em).removeAndFlush(subscription);
|
|
80
119
|
}
|
|
81
120
|
async listSubscriptions(idsDto, em) {
|
|
121
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
122
|
+
this.openTelemetryCollector.info('Listing subscriptions', idsDto);
|
|
123
|
+
}
|
|
82
124
|
const subscriptions = await (em ?? this.em).findAll('Subscription', {
|
|
83
125
|
where: idsDto.ids
|
|
84
126
|
? {
|
|
@@ -88,13 +130,20 @@ export class BaseSubscriptionService {
|
|
|
88
130
|
}
|
|
89
131
|
: undefined
|
|
90
132
|
});
|
|
91
|
-
return
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
133
|
+
return Promise.all(
|
|
134
|
+
subscriptions.map((subscription) => {
|
|
135
|
+
const subscriptionDto =
|
|
136
|
+
this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
|
|
137
|
+
subscription
|
|
138
|
+
);
|
|
139
|
+
return subscriptionDto;
|
|
140
|
+
})
|
|
141
|
+
);
|
|
96
142
|
}
|
|
97
143
|
async cancelSubscription(idDto, em) {
|
|
144
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
145
|
+
this.openTelemetryCollector.info('Canceling subscription', idDto);
|
|
146
|
+
}
|
|
98
147
|
const subscription = await (em ?? this.em).findOne('Subscription', idDto);
|
|
99
148
|
if (!subscription) {
|
|
100
149
|
throw new Error('Subscription not found');
|
|
@@ -105,6 +154,9 @@ export class BaseSubscriptionService {
|
|
|
105
154
|
});
|
|
106
155
|
}
|
|
107
156
|
async resumeSubscription(idDto, em) {
|
|
157
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
158
|
+
this.openTelemetryCollector.info('Resuming subscription', idDto);
|
|
159
|
+
}
|
|
108
160
|
const subscription = await (em ?? this.em).findOne('Subscription', idDto);
|
|
109
161
|
if (!subscription) {
|
|
110
162
|
throw new Error('Subscription not found');
|