@forklaunch/implementation-billing-base 0.2.0 → 0.2.2
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 +97 -25
- package/lib/eject/services/checkoutSession.service.ts +106 -23
- package/lib/eject/services/paymentLink.service.ts +104 -25
- package/lib/eject/services/plan.service.ts +41 -5
- package/lib/eject/services/subscription.service.ts +56 -3
- 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 +20 -2
- package/lib/services/billingPortal.service.d.ts.map +1 -1
- package/lib/services/billingPortal.service.js +83 -25
- package/lib/services/checkoutSession.service.d.ts +58 -15
- package/lib/services/checkoutSession.service.d.ts.map +1 -1
- package/lib/services/checkoutSession.service.js +61 -10
- package/lib/services/paymentLink.service.d.ts +34 -15
- package/lib/services/paymentLink.service.d.ts.map +1 -1
- package/lib/services/paymentLink.service.js +79 -11
- package/lib/services/plan.service.d.ts +14 -2
- package/lib/services/plan.service.d.ts.map +1 -1
- package/lib/services/plan.service.js +35 -5
- package/lib/services/subscription.service.d.ts +16 -2
- package/lib/services/subscription.service.d.ts.map +1 -1
- package/lib/services/subscription.service.js +49 -3
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { IdDto, IdsDto, InstanceTypeRecord } from '@forklaunch/common';
|
|
2
2
|
import { createCacheKey, TtlCache } from '@forklaunch/core/cache';
|
|
3
3
|
import {
|
|
4
|
+
evaluateTelemetryOptions,
|
|
4
5
|
MetricsDefinition,
|
|
5
|
-
OpenTelemetryCollector
|
|
6
|
+
OpenTelemetryCollector,
|
|
7
|
+
TelemetryOptions
|
|
6
8
|
} from '@forklaunch/core/http';
|
|
7
9
|
import {
|
|
8
10
|
InternalDtoMapper,
|
|
@@ -17,38 +19,47 @@ import {
|
|
|
17
19
|
UpdatePaymentLinkDto
|
|
18
20
|
} from '@forklaunch/interfaces-billing/types';
|
|
19
21
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
22
|
+
import { EntityManager } from '@mikro-orm/core';
|
|
20
23
|
|
|
21
24
|
export class BasePaymentLinkService<
|
|
22
25
|
SchemaValidator extends AnySchemaValidator,
|
|
23
26
|
CurrencyEnum,
|
|
27
|
+
StatusEnum,
|
|
24
28
|
Metrics extends MetricsDefinition = MetricsDefinition,
|
|
25
29
|
Dto extends {
|
|
26
|
-
PaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
|
|
27
|
-
CreatePaymentLinkDtoMapper: CreatePaymentLinkDto<CurrencyEnum>;
|
|
28
|
-
UpdatePaymentLinkDtoMapper: UpdatePaymentLinkDto<CurrencyEnum>;
|
|
30
|
+
PaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum, StatusEnum>;
|
|
31
|
+
CreatePaymentLinkDtoMapper: CreatePaymentLinkDto<CurrencyEnum, StatusEnum>;
|
|
32
|
+
UpdatePaymentLinkDtoMapper: UpdatePaymentLinkDto<CurrencyEnum, StatusEnum>;
|
|
29
33
|
} = {
|
|
30
|
-
PaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
|
|
31
|
-
CreatePaymentLinkDtoMapper: CreatePaymentLinkDto<CurrencyEnum>;
|
|
32
|
-
UpdatePaymentLinkDtoMapper: UpdatePaymentLinkDto<CurrencyEnum>;
|
|
34
|
+
PaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum, StatusEnum>;
|
|
35
|
+
CreatePaymentLinkDtoMapper: CreatePaymentLinkDto<CurrencyEnum, StatusEnum>;
|
|
36
|
+
UpdatePaymentLinkDtoMapper: UpdatePaymentLinkDto<CurrencyEnum, StatusEnum>;
|
|
33
37
|
},
|
|
34
38
|
Entities extends {
|
|
35
|
-
PaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
|
|
36
|
-
CreatePaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
|
|
37
|
-
UpdatePaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
|
|
39
|
+
PaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum, StatusEnum>;
|
|
40
|
+
CreatePaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum, StatusEnum>;
|
|
41
|
+
UpdatePaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum, StatusEnum>;
|
|
38
42
|
} = {
|
|
39
|
-
PaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
|
|
40
|
-
CreatePaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
|
|
41
|
-
UpdatePaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum>;
|
|
43
|
+
PaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum, StatusEnum>;
|
|
44
|
+
CreatePaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum, StatusEnum>;
|
|
45
|
+
UpdatePaymentLinkDtoMapper: PaymentLinkDto<CurrencyEnum, StatusEnum>;
|
|
42
46
|
}
|
|
43
|
-
> implements PaymentLinkService<CurrencyEnum>
|
|
47
|
+
> implements PaymentLinkService<CurrencyEnum, StatusEnum>
|
|
44
48
|
{
|
|
45
49
|
#mappers: InternalDtoMapper<
|
|
46
50
|
InstanceTypeRecord<typeof this.mappers>,
|
|
47
51
|
Entities,
|
|
48
52
|
Dto
|
|
49
53
|
>;
|
|
54
|
+
private evaluatedTelemetryOptions: {
|
|
55
|
+
logging?: boolean;
|
|
56
|
+
metrics?: boolean;
|
|
57
|
+
tracing?: boolean;
|
|
58
|
+
};
|
|
59
|
+
private enableDatabaseBackup: boolean;
|
|
50
60
|
|
|
51
61
|
constructor(
|
|
62
|
+
protected readonly em: EntityManager,
|
|
52
63
|
protected readonly cache: TtlCache,
|
|
53
64
|
protected readonly openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
54
65
|
protected readonly schemaValidator: SchemaValidator,
|
|
@@ -68,9 +79,21 @@ export class BasePaymentLinkService<
|
|
|
68
79
|
Dto['UpdatePaymentLinkDtoMapper'],
|
|
69
80
|
Entities['UpdatePaymentLinkDtoMapper']
|
|
70
81
|
>;
|
|
82
|
+
},
|
|
83
|
+
readonly options?: {
|
|
84
|
+
enableDatabaseBackup?: boolean;
|
|
85
|
+
telemetry?: TelemetryOptions;
|
|
71
86
|
}
|
|
72
87
|
) {
|
|
73
88
|
this.#mappers = transformIntoInternalDtoMapper(mappers, schemaValidator);
|
|
89
|
+
this.enableDatabaseBackup = options?.enableDatabaseBackup ?? false;
|
|
90
|
+
this.evaluatedTelemetryOptions = options?.telemetry
|
|
91
|
+
? evaluateTelemetryOptions(options.telemetry).enabled
|
|
92
|
+
: {
|
|
93
|
+
logging: false,
|
|
94
|
+
metrics: false,
|
|
95
|
+
tracing: false
|
|
96
|
+
};
|
|
74
97
|
}
|
|
75
98
|
|
|
76
99
|
protected cacheKeyPrefix = 'payment_link';
|
|
@@ -79,44 +102,78 @@ export class BasePaymentLinkService<
|
|
|
79
102
|
async createPaymentLink(
|
|
80
103
|
paymentLinkDto: Dto['CreatePaymentLinkDtoMapper']
|
|
81
104
|
): Promise<Dto['PaymentLinkDtoMapper']> {
|
|
82
|
-
|
|
105
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
106
|
+
this.openTelemetryCollector.info('Creating payment link', paymentLinkDto);
|
|
107
|
+
}
|
|
108
|
+
|
|
83
109
|
const paymentLink =
|
|
84
110
|
await this.#mappers.CreatePaymentLinkDtoMapper.deserializeDtoToEntity(
|
|
85
|
-
paymentLinkDto
|
|
111
|
+
paymentLinkDto,
|
|
112
|
+
this.em
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
if (this.enableDatabaseBackup) {
|
|
116
|
+
await this.em.persistAndFlush(paymentLink);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const createdPaymentLinkDto =
|
|
120
|
+
await this.#mappers.PaymentLinkDtoMapper.serializeEntityToDto(
|
|
121
|
+
paymentLink
|
|
86
122
|
);
|
|
123
|
+
|
|
87
124
|
await this.cache.putRecord({
|
|
88
|
-
key: this.createCacheKey(
|
|
89
|
-
value:
|
|
125
|
+
key: this.createCacheKey(createdPaymentLinkDto.id),
|
|
126
|
+
value: createdPaymentLinkDto,
|
|
90
127
|
ttlMilliseconds: this.cache.getTtlMilliseconds()
|
|
91
128
|
});
|
|
92
129
|
|
|
93
|
-
return
|
|
130
|
+
return createdPaymentLinkDto;
|
|
94
131
|
}
|
|
95
132
|
|
|
96
133
|
async updatePaymentLink(
|
|
97
134
|
paymentLinkDto: Dto['UpdatePaymentLinkDtoMapper']
|
|
98
135
|
): Promise<Dto['PaymentLinkDtoMapper']> {
|
|
136
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
137
|
+
this.openTelemetryCollector.info('Updating payment link', paymentLinkDto);
|
|
138
|
+
}
|
|
139
|
+
|
|
99
140
|
const cacheKey = this.createCacheKey(paymentLinkDto.id);
|
|
100
|
-
const existingLink =
|
|
101
|
-
await this.cache.readRecord<Entities['PaymentLinkDtoMapper']>(cacheKey)
|
|
141
|
+
const existingLink = (
|
|
142
|
+
await this.cache.readRecord<Entities['PaymentLinkDtoMapper']>(cacheKey)
|
|
143
|
+
)?.value;
|
|
102
144
|
if (!existingLink) {
|
|
103
145
|
throw new Error('Payment link not found');
|
|
104
146
|
}
|
|
105
147
|
const paymentLink =
|
|
106
148
|
await this.#mappers.UpdatePaymentLinkDtoMapper.deserializeDtoToEntity(
|
|
107
|
-
paymentLinkDto
|
|
149
|
+
paymentLinkDto,
|
|
150
|
+
this.em
|
|
108
151
|
);
|
|
109
|
-
|
|
152
|
+
|
|
153
|
+
if (this.enableDatabaseBackup) {
|
|
154
|
+
await this.em.persistAndFlush(paymentLink);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const updatedLinkDto = {
|
|
158
|
+
...existingLink,
|
|
159
|
+
...(await this.#mappers.PaymentLinkDtoMapper.serializeEntityToDto(
|
|
160
|
+
paymentLink
|
|
161
|
+
))
|
|
162
|
+
};
|
|
163
|
+
|
|
110
164
|
await this.cache.putRecord({
|
|
111
165
|
key: cacheKey,
|
|
112
|
-
value:
|
|
166
|
+
value: updatedLinkDto,
|
|
113
167
|
ttlMilliseconds: this.cache.getTtlMilliseconds()
|
|
114
168
|
});
|
|
115
169
|
|
|
116
|
-
return
|
|
170
|
+
return updatedLinkDto;
|
|
117
171
|
}
|
|
118
172
|
|
|
119
173
|
async getPaymentLink({ id }: IdDto): Promise<Dto['PaymentLinkDtoMapper']> {
|
|
174
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
175
|
+
this.openTelemetryCollector.info('Getting payment link', { id });
|
|
176
|
+
}
|
|
120
177
|
const cacheKey = this.createCacheKey(id);
|
|
121
178
|
const paymentLink =
|
|
122
179
|
await this.cache.readRecord<Entities['PaymentLinkDtoMapper']>(cacheKey);
|
|
@@ -131,16 +188,38 @@ export class BasePaymentLinkService<
|
|
|
131
188
|
|
|
132
189
|
async expirePaymentLink({ id }: IdDto): Promise<void> {
|
|
133
190
|
this.openTelemetryCollector.info('Payment link expired', { id });
|
|
191
|
+
|
|
192
|
+
if (this.enableDatabaseBackup) {
|
|
193
|
+
const paymentLink = await this.em.upsert('PaymentLink', {
|
|
194
|
+
id,
|
|
195
|
+
status: 'EXPIRED'
|
|
196
|
+
});
|
|
197
|
+
await this.em.removeAndFlush(paymentLink);
|
|
198
|
+
}
|
|
134
199
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
135
200
|
}
|
|
136
201
|
|
|
137
202
|
async handlePaymentSuccess({ id }: IdDto): Promise<void> {
|
|
138
203
|
this.openTelemetryCollector.info('Payment link success', { id });
|
|
204
|
+
if (this.enableDatabaseBackup) {
|
|
205
|
+
const paymentLink = await this.em.upsert('PaymentLink', {
|
|
206
|
+
id,
|
|
207
|
+
status: 'COMPLETED'
|
|
208
|
+
});
|
|
209
|
+
await this.em.removeAndFlush(paymentLink);
|
|
210
|
+
}
|
|
139
211
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
140
212
|
}
|
|
141
213
|
|
|
142
214
|
async handlePaymentFailure({ id }: IdDto): Promise<void> {
|
|
143
215
|
this.openTelemetryCollector.info('Payment link failure', { id });
|
|
216
|
+
if (this.enableDatabaseBackup) {
|
|
217
|
+
const paymentLink = await this.em.upsert('PaymentLink', {
|
|
218
|
+
id,
|
|
219
|
+
status: 'FAILED'
|
|
220
|
+
});
|
|
221
|
+
await this.em.removeAndFlush(paymentLink);
|
|
222
|
+
}
|
|
144
223
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
145
224
|
}
|
|
146
225
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { IdDto, IdsDto, InstanceTypeRecord } from '@forklaunch/common';
|
|
2
2
|
import {
|
|
3
|
+
evaluateTelemetryOptions,
|
|
3
4
|
MetricsDefinition,
|
|
4
|
-
OpenTelemetryCollector
|
|
5
|
+
OpenTelemetryCollector,
|
|
6
|
+
TelemetryOptions
|
|
5
7
|
} from '@forklaunch/core/http';
|
|
6
8
|
import {
|
|
7
9
|
InternalDtoMapper,
|
|
@@ -48,6 +50,11 @@ export class BasePlanService<
|
|
|
48
50
|
Entities,
|
|
49
51
|
Dto
|
|
50
52
|
>;
|
|
53
|
+
private evaluatedTelemetryOptions: {
|
|
54
|
+
logging?: boolean;
|
|
55
|
+
metrics?: boolean;
|
|
56
|
+
tracing?: boolean;
|
|
57
|
+
};
|
|
51
58
|
|
|
52
59
|
constructor(
|
|
53
60
|
private em: EntityManager,
|
|
@@ -69,15 +76,28 @@ export class BasePlanService<
|
|
|
69
76
|
Dto['UpdatePlanDtoMapper'],
|
|
70
77
|
Entities['UpdatePlanDtoMapper']
|
|
71
78
|
>;
|
|
79
|
+
},
|
|
80
|
+
readonly options?: {
|
|
81
|
+
telemetry?: TelemetryOptions;
|
|
72
82
|
}
|
|
73
83
|
) {
|
|
74
84
|
this.#mappers = transformIntoInternalDtoMapper(mappers, schemaValidator);
|
|
85
|
+
this.evaluatedTelemetryOptions = options?.telemetry
|
|
86
|
+
? evaluateTelemetryOptions(options.telemetry).enabled
|
|
87
|
+
: {
|
|
88
|
+
logging: false,
|
|
89
|
+
metrics: false,
|
|
90
|
+
tracing: false
|
|
91
|
+
};
|
|
75
92
|
}
|
|
76
93
|
|
|
77
94
|
async listPlans(
|
|
78
95
|
idsDto?: IdsDto,
|
|
79
96
|
em?: EntityManager
|
|
80
97
|
): Promise<Dto['PlanDtoMapper'][]> {
|
|
98
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
99
|
+
this.openTelemetryCollector.info('Listing plans', idsDto);
|
|
100
|
+
}
|
|
81
101
|
return Promise.all(
|
|
82
102
|
(
|
|
83
103
|
await (em ?? this.em).findAll('Plan', {
|
|
@@ -95,8 +115,13 @@ export class BasePlanService<
|
|
|
95
115
|
planDto: Dto['CreatePlanDtoMapper'],
|
|
96
116
|
em?: EntityManager
|
|
97
117
|
): Promise<Dto['PlanDtoMapper']> {
|
|
98
|
-
|
|
99
|
-
|
|
118
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
119
|
+
this.openTelemetryCollector.info('Creating plan', planDto);
|
|
120
|
+
}
|
|
121
|
+
const plan = await this.#mappers.CreatePlanDtoMapper.deserializeDtoToEntity(
|
|
122
|
+
planDto,
|
|
123
|
+
em ?? this.em
|
|
124
|
+
);
|
|
100
125
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
101
126
|
await innerEm.persist(plan);
|
|
102
127
|
});
|
|
@@ -107,6 +132,9 @@ export class BasePlanService<
|
|
|
107
132
|
idDto: IdDto,
|
|
108
133
|
em?: EntityManager
|
|
109
134
|
): Promise<Dto['PlanDtoMapper']> {
|
|
135
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
136
|
+
this.openTelemetryCollector.info('Getting plan', idDto);
|
|
137
|
+
}
|
|
110
138
|
const plan = await (em ?? this.em).findOneOrFail('Plan', idDto);
|
|
111
139
|
return this.#mappers.PlanDtoMapper.serializeEntityToDto(
|
|
112
140
|
plan as Entities['PlanDtoMapper']
|
|
@@ -117,8 +145,13 @@ export class BasePlanService<
|
|
|
117
145
|
planDto: Dto['UpdatePlanDtoMapper'],
|
|
118
146
|
em?: EntityManager
|
|
119
147
|
): Promise<Dto['PlanDtoMapper']> {
|
|
120
|
-
|
|
121
|
-
|
|
148
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
149
|
+
this.openTelemetryCollector.info('Updating plan', planDto);
|
|
150
|
+
}
|
|
151
|
+
const plan = await this.#mappers.UpdatePlanDtoMapper.deserializeDtoToEntity(
|
|
152
|
+
planDto,
|
|
153
|
+
em ?? this.em
|
|
154
|
+
);
|
|
122
155
|
const updatedPlan = await (em ?? this.em).upsert(plan);
|
|
123
156
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
124
157
|
await innerEm.persist(plan);
|
|
@@ -129,6 +162,9 @@ export class BasePlanService<
|
|
|
129
162
|
}
|
|
130
163
|
|
|
131
164
|
async deletePlan(idDto: { id: string }, em?: EntityManager): Promise<void> {
|
|
165
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
166
|
+
this.openTelemetryCollector.info('Deleting plan', idDto);
|
|
167
|
+
}
|
|
132
168
|
await (em ?? this.em).nativeDelete('Plan', idDto);
|
|
133
169
|
}
|
|
134
170
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { IdDto, InstanceTypeRecord } from '@forklaunch/common';
|
|
2
2
|
import {
|
|
3
|
+
evaluateTelemetryOptions,
|
|
3
4
|
MetricsDefinition,
|
|
4
|
-
OpenTelemetryCollector
|
|
5
|
+
OpenTelemetryCollector,
|
|
6
|
+
TelemetryOptions
|
|
5
7
|
} from '@forklaunch/core/http';
|
|
6
8
|
import {
|
|
7
9
|
InternalDtoMapper,
|
|
@@ -72,6 +74,11 @@ export class BaseSubscriptionService<
|
|
|
72
74
|
Entities,
|
|
73
75
|
Dto
|
|
74
76
|
>;
|
|
77
|
+
private evaluatedTelemetryOptions: {
|
|
78
|
+
logging?: boolean;
|
|
79
|
+
metrics?: boolean;
|
|
80
|
+
tracing?: boolean;
|
|
81
|
+
};
|
|
75
82
|
|
|
76
83
|
constructor(
|
|
77
84
|
protected em: EntityManager,
|
|
@@ -93,6 +100,10 @@ export class BaseSubscriptionService<
|
|
|
93
100
|
Dto['UpdateSubscriptionDtoMapper'],
|
|
94
101
|
Entities['UpdateSubscriptionDtoMapper']
|
|
95
102
|
>;
|
|
103
|
+
},
|
|
104
|
+
readonly options?: {
|
|
105
|
+
enableDatabaseBackup?: boolean;
|
|
106
|
+
telemetry?: TelemetryOptions;
|
|
96
107
|
}
|
|
97
108
|
) {
|
|
98
109
|
this.#mappers = transformIntoInternalDtoMapper<
|
|
@@ -101,15 +112,29 @@ export class BaseSubscriptionService<
|
|
|
101
112
|
Entities,
|
|
102
113
|
Dto
|
|
103
114
|
>(mappers, this.schemaValidator);
|
|
115
|
+
this.evaluatedTelemetryOptions = options?.telemetry
|
|
116
|
+
? evaluateTelemetryOptions(options.telemetry).enabled
|
|
117
|
+
: {
|
|
118
|
+
logging: false,
|
|
119
|
+
metrics: false,
|
|
120
|
+
tracing: false
|
|
121
|
+
};
|
|
104
122
|
}
|
|
105
123
|
|
|
106
124
|
async createSubscription(
|
|
107
125
|
subscriptionDto: Dto['CreateSubscriptionDtoMapper'],
|
|
108
126
|
em?: EntityManager
|
|
109
127
|
): Promise<Dto['SubscriptionDtoMapper']> {
|
|
128
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
129
|
+
this.openTelemetryCollector.info(
|
|
130
|
+
'Creating subscription',
|
|
131
|
+
subscriptionDto
|
|
132
|
+
);
|
|
133
|
+
}
|
|
110
134
|
const subscription =
|
|
111
135
|
await this.#mappers.CreateSubscriptionDtoMapper.deserializeDtoToEntity(
|
|
112
|
-
subscriptionDto
|
|
136
|
+
subscriptionDto,
|
|
137
|
+
em ?? this.em
|
|
113
138
|
);
|
|
114
139
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
115
140
|
await innerEm.persist(subscription);
|
|
@@ -125,6 +150,9 @@ export class BaseSubscriptionService<
|
|
|
125
150
|
idDto: IdDto,
|
|
126
151
|
em?: EntityManager
|
|
127
152
|
): Promise<Dto['SubscriptionDtoMapper']> {
|
|
153
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
154
|
+
this.openTelemetryCollector.info('Getting subscription', idDto);
|
|
155
|
+
}
|
|
128
156
|
const subscription = await (em ?? this.em).findOneOrFail(
|
|
129
157
|
'Subscription',
|
|
130
158
|
idDto
|
|
@@ -138,6 +166,9 @@ export class BaseSubscriptionService<
|
|
|
138
166
|
{ id }: IdDto,
|
|
139
167
|
em?: EntityManager
|
|
140
168
|
): Promise<Dto['SubscriptionDtoMapper']> {
|
|
169
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
170
|
+
this.openTelemetryCollector.info('Getting user subscription', id);
|
|
171
|
+
}
|
|
141
172
|
const subscription = await (em ?? this.em).findOneOrFail('Subscription', {
|
|
142
173
|
partyId: id,
|
|
143
174
|
partyType: 'USER',
|
|
@@ -153,6 +184,9 @@ export class BaseSubscriptionService<
|
|
|
153
184
|
{ id }: IdDto,
|
|
154
185
|
em?: EntityManager
|
|
155
186
|
): Promise<Dto['SubscriptionDtoMapper']> {
|
|
187
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
188
|
+
this.openTelemetryCollector.info('Getting organization subscription', id);
|
|
189
|
+
}
|
|
156
190
|
const subscription = await (em ?? this.em).findOneOrFail('Subscription', {
|
|
157
191
|
partyId: id,
|
|
158
192
|
partyType: 'ORGANIZATION',
|
|
@@ -167,9 +201,16 @@ export class BaseSubscriptionService<
|
|
|
167
201
|
subscriptionDto: Dto['UpdateSubscriptionDtoMapper'],
|
|
168
202
|
em?: EntityManager
|
|
169
203
|
): Promise<Dto['SubscriptionDtoMapper']> {
|
|
204
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
205
|
+
this.openTelemetryCollector.info(
|
|
206
|
+
'Updating subscription',
|
|
207
|
+
subscriptionDto
|
|
208
|
+
);
|
|
209
|
+
}
|
|
170
210
|
const subscription =
|
|
171
211
|
this.#mappers.UpdateSubscriptionDtoMapper.deserializeDtoToEntity(
|
|
172
|
-
subscriptionDto
|
|
212
|
+
subscriptionDto,
|
|
213
|
+
em ?? this.em
|
|
173
214
|
);
|
|
174
215
|
const updatedSubscription = await (em ?? this.em).upsert(subscription);
|
|
175
216
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
@@ -187,6 +228,9 @@ export class BaseSubscriptionService<
|
|
|
187
228
|
idDto: { id: string },
|
|
188
229
|
em?: EntityManager
|
|
189
230
|
): Promise<void> {
|
|
231
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
232
|
+
this.openTelemetryCollector.info('Deleting subscription', idDto);
|
|
233
|
+
}
|
|
190
234
|
const subscription = await (em ?? this.em).findOne('Subscription', idDto);
|
|
191
235
|
if (!subscription) {
|
|
192
236
|
throw new Error('Subscription not found');
|
|
@@ -198,6 +242,9 @@ export class BaseSubscriptionService<
|
|
|
198
242
|
idsDto: { ids?: string[] },
|
|
199
243
|
em?: EntityManager
|
|
200
244
|
): Promise<Dto['SubscriptionDtoMapper'][]> {
|
|
245
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
246
|
+
this.openTelemetryCollector.info('Listing subscriptions', idsDto);
|
|
247
|
+
}
|
|
201
248
|
const subscriptions = await (em ?? this.em).findAll('Subscription', {
|
|
202
249
|
where: idsDto.ids
|
|
203
250
|
? {
|
|
@@ -220,6 +267,9 @@ export class BaseSubscriptionService<
|
|
|
220
267
|
}
|
|
221
268
|
|
|
222
269
|
async cancelSubscription(idDto: IdDto, em?: EntityManager): Promise<void> {
|
|
270
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
271
|
+
this.openTelemetryCollector.info('Canceling subscription', idDto);
|
|
272
|
+
}
|
|
223
273
|
const subscription = await (em ?? this.em).findOne('Subscription', idDto);
|
|
224
274
|
if (!subscription) {
|
|
225
275
|
throw new Error('Subscription not found');
|
|
@@ -231,6 +281,9 @@ export class BaseSubscriptionService<
|
|
|
231
281
|
}
|
|
232
282
|
|
|
233
283
|
async resumeSubscription(idDto: IdDto, em?: EntityManager): Promise<void> {
|
|
284
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
285
|
+
this.openTelemetryCollector.info('Resuming subscription', idDto);
|
|
286
|
+
}
|
|
234
287
|
const subscription = await (em ?? this.em).findOne('Subscription', idDto);
|
|
235
288
|
if (!subscription) {
|
|
236
289
|
throw new Error('Subscription not found');
|
|
@@ -14,7 +14,8 @@ export declare const BaseCheckoutSessionServiceSchemas: <
|
|
|
14
14
|
CreateCheckoutSessionSchema: <
|
|
15
15
|
T extends Record<string, import('@forklaunch/validator').LiteralSchema>
|
|
16
16
|
>(
|
|
17
|
-
PaymentMethodEnum: T
|
|
17
|
+
PaymentMethodEnum: T,
|
|
18
|
+
StatusEnum: T
|
|
18
19
|
) => {
|
|
19
20
|
customerId: import('@sinclair/typebox').TString;
|
|
20
21
|
paymentMethods: import('@sinclair/typebox').TArray<
|
|
@@ -28,14 +29,33 @@ export declare const BaseCheckoutSessionServiceSchemas: <
|
|
|
28
29
|
>;
|
|
29
30
|
successRedirectUri: import('@sinclair/typebox').TString;
|
|
30
31
|
cancelRedirectUri: import('@sinclair/typebox').TString;
|
|
32
|
+
expiresAt: import('@sinclair/typebox').TTransform<
|
|
33
|
+
import('@sinclair/typebox').TUnion<
|
|
34
|
+
[
|
|
35
|
+
import('@sinclair/typebox').TString,
|
|
36
|
+
import('@sinclair/typebox').TNumber,
|
|
37
|
+
import('@sinclair/typebox').TDate
|
|
38
|
+
]
|
|
39
|
+
>,
|
|
40
|
+
Date
|
|
41
|
+
>;
|
|
42
|
+
status: import('@sinclair/typebox').TUnion<
|
|
43
|
+
[
|
|
44
|
+
{
|
|
45
|
+
[K in keyof T]: import('@sinclair/typebox').TLiteral<T[K]>;
|
|
46
|
+
}[keyof T]
|
|
47
|
+
]
|
|
48
|
+
>;
|
|
31
49
|
extraFields: import('@sinclair/typebox').TOptional<
|
|
32
50
|
import('@sinclair/typebox').TUnknown
|
|
33
51
|
>;
|
|
34
52
|
};
|
|
35
53
|
UpdateCheckoutSessionSchema: <
|
|
36
|
-
T extends Record<string, import('@forklaunch/validator').LiteralSchema
|
|
54
|
+
T extends Record<string, import('@forklaunch/validator').LiteralSchema>,
|
|
55
|
+
U extends Record<string, import('@forklaunch/validator').LiteralSchema>
|
|
37
56
|
>(
|
|
38
|
-
PaymentMethodEnum: T
|
|
57
|
+
PaymentMethodEnum: T,
|
|
58
|
+
StatusEnum: U
|
|
39
59
|
) => {
|
|
40
60
|
id: import('@sinclair/typebox').TString;
|
|
41
61
|
customerId: import('@sinclair/typebox').TOptional<
|
|
@@ -58,14 +78,37 @@ export declare const BaseCheckoutSessionServiceSchemas: <
|
|
|
58
78
|
cancelRedirectUri: import('@sinclair/typebox').TOptional<
|
|
59
79
|
import('@sinclair/typebox').TString
|
|
60
80
|
>;
|
|
81
|
+
expiresAt: import('@sinclair/typebox').TOptional<
|
|
82
|
+
import('@sinclair/typebox').TTransform<
|
|
83
|
+
import('@sinclair/typebox').TUnion<
|
|
84
|
+
[
|
|
85
|
+
import('@sinclair/typebox').TString,
|
|
86
|
+
import('@sinclair/typebox').TNumber,
|
|
87
|
+
import('@sinclair/typebox').TDate
|
|
88
|
+
]
|
|
89
|
+
>,
|
|
90
|
+
Date
|
|
91
|
+
>
|
|
92
|
+
>;
|
|
93
|
+
status: import('@sinclair/typebox').TOptional<
|
|
94
|
+
import('@sinclair/typebox').TUnion<
|
|
95
|
+
[
|
|
96
|
+
{
|
|
97
|
+
[K_1 in keyof U]: import('@sinclair/typebox').TLiteral<U[K_1]>;
|
|
98
|
+
}[keyof U]
|
|
99
|
+
]
|
|
100
|
+
>
|
|
101
|
+
>;
|
|
61
102
|
extraFields: import('@sinclair/typebox').TOptional<
|
|
62
103
|
import('@sinclair/typebox').TUnknown
|
|
63
104
|
>;
|
|
64
105
|
};
|
|
65
106
|
CheckoutSessionSchema: <
|
|
66
|
-
T extends Record<string, import('@forklaunch/validator').LiteralSchema
|
|
107
|
+
T extends Record<string, import('@forklaunch/validator').LiteralSchema>,
|
|
108
|
+
U_1 extends Record<string, import('@forklaunch/validator').LiteralSchema>
|
|
67
109
|
>(
|
|
68
|
-
PaymentMethodEnum: T
|
|
110
|
+
PaymentMethodEnum: T,
|
|
111
|
+
StatusEnum: U_1
|
|
69
112
|
) => {
|
|
70
113
|
id: import('@sinclair/typebox').TString;
|
|
71
114
|
customerId: import('@sinclair/typebox').TString;
|
|
@@ -83,6 +126,23 @@ export declare const BaseCheckoutSessionServiceSchemas: <
|
|
|
83
126
|
>;
|
|
84
127
|
successRedirectUri: import('@sinclair/typebox').TString;
|
|
85
128
|
cancelRedirectUri: import('@sinclair/typebox').TString;
|
|
129
|
+
expiresAt: import('@sinclair/typebox').TTransform<
|
|
130
|
+
import('@sinclair/typebox').TUnion<
|
|
131
|
+
[
|
|
132
|
+
import('@sinclair/typebox').TString,
|
|
133
|
+
import('@sinclair/typebox').TNumber,
|
|
134
|
+
import('@sinclair/typebox').TDate
|
|
135
|
+
]
|
|
136
|
+
>,
|
|
137
|
+
Date
|
|
138
|
+
>;
|
|
139
|
+
status: import('@sinclair/typebox').TUnion<
|
|
140
|
+
[
|
|
141
|
+
{
|
|
142
|
+
[K_1 in keyof U_1]: import('@sinclair/typebox').TLiteral<U_1[K_1]>;
|
|
143
|
+
}[keyof U_1]
|
|
144
|
+
]
|
|
145
|
+
>;
|
|
86
146
|
extraFields: import('@sinclair/typebox').TOptional<
|
|
87
147
|
import('@sinclair/typebox').TUnknown
|
|
88
148
|
>;
|
|
@@ -116,9 +176,11 @@ export declare const BaseCheckoutSessionServiceSchemas: <
|
|
|
116
176
|
uuidId: boolean;
|
|
117
177
|
}) => {
|
|
118
178
|
CreateCheckoutSessionSchema: <
|
|
119
|
-
T extends Record<string, import('@forklaunch/validator').LiteralSchema
|
|
179
|
+
T extends Record<string, import('@forklaunch/validator').LiteralSchema>,
|
|
180
|
+
U_2 extends Record<string, import('@forklaunch/validator').LiteralSchema>
|
|
120
181
|
>(
|
|
121
|
-
PaymentMethodEnum: T
|
|
182
|
+
PaymentMethodEnum: T,
|
|
183
|
+
StatusEnum: U_2
|
|
122
184
|
) => {
|
|
123
185
|
customerId: import('zod').ZodString;
|
|
124
186
|
paymentMethods: import('zod').ZodArray<
|
|
@@ -129,12 +191,18 @@ export declare const BaseCheckoutSessionServiceSchemas: <
|
|
|
129
191
|
>;
|
|
130
192
|
successRedirectUri: import('zod').ZodString;
|
|
131
193
|
cancelRedirectUri: import('zod').ZodString;
|
|
194
|
+
expiresAt: import('zod').ZodEffects<import('zod').ZodDate, Date, unknown>;
|
|
195
|
+
status: import('zod').ZodUnion<
|
|
196
|
+
[{ [K_1 in keyof U_2]: import('zod').ZodLiteral<U_2[K_1]> }[keyof U_2]]
|
|
197
|
+
>;
|
|
132
198
|
extraFields: import('zod').ZodOptional<import('zod').ZodUnknown>;
|
|
133
199
|
};
|
|
134
200
|
UpdateCheckoutSessionSchema: <
|
|
135
|
-
T extends Record<string, import('@forklaunch/validator').LiteralSchema
|
|
201
|
+
T extends Record<string, import('@forklaunch/validator').LiteralSchema>,
|
|
202
|
+
U_3 extends Record<string, import('@forklaunch/validator').LiteralSchema>
|
|
136
203
|
>(
|
|
137
|
-
PaymentMethodEnum: T
|
|
204
|
+
PaymentMethodEnum: T,
|
|
205
|
+
StatusEnum: U_3
|
|
138
206
|
) => {
|
|
139
207
|
id: import('zod').ZodString;
|
|
140
208
|
customerId: import('zod').ZodOptional<import('zod').ZodString>;
|
|
@@ -148,12 +216,26 @@ export declare const BaseCheckoutSessionServiceSchemas: <
|
|
|
148
216
|
>;
|
|
149
217
|
successRedirectUri: import('zod').ZodOptional<import('zod').ZodString>;
|
|
150
218
|
cancelRedirectUri: import('zod').ZodOptional<import('zod').ZodString>;
|
|
219
|
+
expiresAt: import('zod').ZodOptional<
|
|
220
|
+
import('zod').ZodEffects<import('zod').ZodDate, Date, unknown>
|
|
221
|
+
>;
|
|
222
|
+
status: import('zod').ZodOptional<
|
|
223
|
+
import('zod').ZodUnion<
|
|
224
|
+
[
|
|
225
|
+
{
|
|
226
|
+
[K_1 in keyof U_3]: import('zod').ZodLiteral<U_3[K_1]>;
|
|
227
|
+
}[keyof U_3]
|
|
228
|
+
]
|
|
229
|
+
>
|
|
230
|
+
>;
|
|
151
231
|
extraFields: import('zod').ZodOptional<import('zod').ZodUnknown>;
|
|
152
232
|
};
|
|
153
233
|
CheckoutSessionSchema: <
|
|
154
|
-
T extends Record<string, import('@forklaunch/validator').LiteralSchema
|
|
234
|
+
T extends Record<string, import('@forklaunch/validator').LiteralSchema>,
|
|
235
|
+
U_4 extends Record<string, import('@forklaunch/validator').LiteralSchema>
|
|
155
236
|
>(
|
|
156
|
-
PaymentMethodEnum: T
|
|
237
|
+
PaymentMethodEnum: T,
|
|
238
|
+
StatusEnum: U_4
|
|
157
239
|
) => {
|
|
158
240
|
id: import('zod').ZodString;
|
|
159
241
|
customerId: import('zod').ZodString;
|
|
@@ -166,6 +248,10 @@ export declare const BaseCheckoutSessionServiceSchemas: <
|
|
|
166
248
|
>;
|
|
167
249
|
successRedirectUri: import('zod').ZodString;
|
|
168
250
|
cancelRedirectUri: import('zod').ZodString;
|
|
251
|
+
expiresAt: import('zod').ZodEffects<import('zod').ZodDate, Date, unknown>;
|
|
252
|
+
status: import('zod').ZodUnion<
|
|
253
|
+
[{ [K_1 in keyof U_4]: import('zod').ZodLiteral<U_4[K_1]> }[keyof U_4]]
|
|
254
|
+
>;
|
|
169
255
|
extraFields: import('zod').ZodOptional<import('zod').ZodUnknown>;
|
|
170
256
|
createdAt: import('zod').ZodOptional<
|
|
171
257
|
import('zod').ZodEffects<import('zod').ZodDate, Date, unknown>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkoutSession.schema.d.ts","sourceRoot":"","sources":["../../schemas/checkoutSession.schema.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,iCAAiC
|
|
1
|
+
{"version":3,"file":"checkoutSession.schema.d.ts","sourceRoot":"","sources":["../../schemas/checkoutSession.schema.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAG7C,CAAC"}
|