@forklaunch/implementation-billing-base 0.5.3 → 0.5.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.
- package/lib/domain/schemas/index.d.mts +1190 -336
- package/lib/domain/schemas/index.d.ts +1190 -336
- package/lib/domain/schemas/index.js +385 -246
- package/lib/domain/schemas/index.mjs +277 -221
- package/lib/eject/domain/schemas/billingPortal.schema.ts +1 -7
- package/lib/services/index.d.mts +661 -206
- package/lib/services/index.d.ts +661 -206
- package/lib/services/index.js +262 -202
- package/lib/services/index.mjs +226 -206
- package/package.json +8 -8
package/lib/services/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -8,14 +8,18 @@ var __export = (target, all) => {
|
|
|
8
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
9
|
};
|
|
10
10
|
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from ===
|
|
11
|
+
if ((from && typeof from === 'object') || typeof from === 'function') {
|
|
12
12
|
for (let key of __getOwnPropNames(from))
|
|
13
13
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, {
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
15
18
|
}
|
|
16
19
|
return to;
|
|
17
20
|
};
|
|
18
|
-
var __toCommonJS = (mod) =>
|
|
21
|
+
var __toCommonJS = (mod) =>
|
|
22
|
+
__copyProps(__defProp({}, '__esModule', { value: true }), mod);
|
|
19
23
|
|
|
20
24
|
// services/index.ts
|
|
21
25
|
var services_exports = {};
|
|
@@ -29,24 +33,36 @@ __export(services_exports, {
|
|
|
29
33
|
module.exports = __toCommonJS(services_exports);
|
|
30
34
|
|
|
31
35
|
// services/billingPortal.service.ts
|
|
32
|
-
var import_cache = require(
|
|
33
|
-
var import_http = require(
|
|
34
|
-
var import_internal = require(
|
|
36
|
+
var import_cache = require('@forklaunch/core/cache');
|
|
37
|
+
var import_http = require('@forklaunch/core/http');
|
|
38
|
+
var import_internal = require('@forklaunch/internal');
|
|
35
39
|
var BaseBillingPortalService = class {
|
|
36
|
-
constructor(
|
|
40
|
+
constructor(
|
|
41
|
+
em,
|
|
42
|
+
cache,
|
|
43
|
+
openTelemetryCollector,
|
|
44
|
+
schemaValidator,
|
|
45
|
+
mappers,
|
|
46
|
+
options
|
|
47
|
+
) {
|
|
37
48
|
this.options = options;
|
|
38
49
|
this.em = em;
|
|
39
50
|
this.cache = cache;
|
|
40
51
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
41
52
|
this.schemaValidator = schemaValidator;
|
|
42
53
|
this.mappers = mappers;
|
|
43
|
-
this._mappers = (0, import_internal.transformIntoInternalMapper)(
|
|
54
|
+
this._mappers = (0, import_internal.transformIntoInternalMapper)(
|
|
55
|
+
mappers,
|
|
56
|
+
schemaValidator
|
|
57
|
+
);
|
|
44
58
|
this.enableDatabaseBackup = options?.enableDatabaseBackup ?? false;
|
|
45
|
-
this.evaluatedTelemetryOptions = options?.telemetry
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
59
|
+
this.evaluatedTelemetryOptions = options?.telemetry
|
|
60
|
+
? (0, import_http.evaluateTelemetryOptions)(options.telemetry).enabled
|
|
61
|
+
: {
|
|
62
|
+
logging: false,
|
|
63
|
+
metrics: false,
|
|
64
|
+
tracing: false
|
|
65
|
+
};
|
|
50
66
|
}
|
|
51
67
|
_mappers;
|
|
52
68
|
evaluatedTelemetryOptions;
|
|
@@ -56,24 +72,26 @@ var BaseBillingPortalService = class {
|
|
|
56
72
|
openTelemetryCollector;
|
|
57
73
|
schemaValidator;
|
|
58
74
|
mappers;
|
|
59
|
-
createCacheKey = (0, import_cache.createCacheKey)(
|
|
75
|
+
createCacheKey = (0, import_cache.createCacheKey)('billing_portal_session');
|
|
60
76
|
async createBillingPortalSession(billingPortalDto) {
|
|
61
77
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
62
78
|
this.openTelemetryCollector.info(
|
|
63
|
-
|
|
79
|
+
'Creating billing portal session',
|
|
64
80
|
billingPortalDto
|
|
65
81
|
);
|
|
66
82
|
}
|
|
67
|
-
const billingPortal =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
83
|
+
const billingPortal =
|
|
84
|
+
await this._mappers.CreateBillingPortalMapper.deserializeDtoToEntity(
|
|
85
|
+
billingPortalDto,
|
|
86
|
+
this.em
|
|
87
|
+
);
|
|
71
88
|
if (this.enableDatabaseBackup) {
|
|
72
89
|
await this.em.persistAndFlush(billingPortal);
|
|
73
90
|
}
|
|
74
|
-
const createdBillingPortalDto =
|
|
75
|
-
|
|
76
|
-
|
|
91
|
+
const createdBillingPortalDto =
|
|
92
|
+
await this._mappers.BillingPortalMapper.serializeEntityToDto(
|
|
93
|
+
billingPortal
|
|
94
|
+
);
|
|
77
95
|
await this.cache.putRecord({
|
|
78
96
|
key: this.createCacheKey(createdBillingPortalDto.id),
|
|
79
97
|
value: createdBillingPortalDto,
|
|
@@ -83,31 +101,34 @@ var BaseBillingPortalService = class {
|
|
|
83
101
|
}
|
|
84
102
|
async getBillingPortalSession(idDto) {
|
|
85
103
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
86
|
-
this.openTelemetryCollector.info(
|
|
104
|
+
this.openTelemetryCollector.info('Getting billing portal session', idDto);
|
|
87
105
|
}
|
|
88
|
-
const billingPortalDetails = await this.cache.readRecord(
|
|
106
|
+
const billingPortalDetails = await this.cache.readRecord(
|
|
107
|
+
this.createCacheKey(idDto.id)
|
|
108
|
+
);
|
|
89
109
|
if (!billingPortalDetails) {
|
|
90
|
-
throw new Error(
|
|
110
|
+
throw new Error('Session not found');
|
|
91
111
|
}
|
|
92
112
|
return billingPortalDetails.value;
|
|
93
113
|
}
|
|
94
114
|
async updateBillingPortalSession(billingPortalDto) {
|
|
95
115
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
96
116
|
this.openTelemetryCollector.info(
|
|
97
|
-
|
|
117
|
+
'Updating billing portal session',
|
|
98
118
|
billingPortalDto
|
|
99
119
|
);
|
|
100
120
|
}
|
|
101
|
-
const existingBillingPortal = (
|
|
102
|
-
this.createCacheKey(billingPortalDto.id)
|
|
103
|
-
)
|
|
121
|
+
const existingBillingPortal = (
|
|
122
|
+
await this.cache.readRecord(this.createCacheKey(billingPortalDto.id))
|
|
123
|
+
)?.value;
|
|
104
124
|
if (!existingBillingPortal) {
|
|
105
|
-
throw new Error(
|
|
125
|
+
throw new Error('Session not found');
|
|
106
126
|
}
|
|
107
|
-
const billingPortal =
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
127
|
+
const billingPortal =
|
|
128
|
+
await this._mappers.UpdateBillingPortalMapper.deserializeDtoToEntity(
|
|
129
|
+
billingPortalDto,
|
|
130
|
+
this.em
|
|
131
|
+
);
|
|
111
132
|
if (this.enableDatabaseBackup) {
|
|
112
133
|
await this.em.persistAndFlush({
|
|
113
134
|
billingPortal
|
|
@@ -115,9 +136,9 @@ var BaseBillingPortalService = class {
|
|
|
115
136
|
}
|
|
116
137
|
const updatedBillingPortalDto = {
|
|
117
138
|
...existingBillingPortal,
|
|
118
|
-
...await this._mappers.BillingPortalMapper.serializeEntityToDto(
|
|
139
|
+
...(await this._mappers.BillingPortalMapper.serializeEntityToDto(
|
|
119
140
|
billingPortal
|
|
120
|
-
)
|
|
141
|
+
))
|
|
121
142
|
};
|
|
122
143
|
await this.cache.putRecord({
|
|
123
144
|
key: this.createCacheKey(updatedBillingPortalDto.id),
|
|
@@ -129,7 +150,7 @@ var BaseBillingPortalService = class {
|
|
|
129
150
|
async expireBillingPortalSession(idDto) {
|
|
130
151
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
131
152
|
this.openTelemetryCollector.info(
|
|
132
|
-
|
|
153
|
+
'Expiring billing portal session',
|
|
133
154
|
idDto
|
|
134
155
|
);
|
|
135
156
|
}
|
|
@@ -137,31 +158,43 @@ var BaseBillingPortalService = class {
|
|
|
137
158
|
this.createCacheKey(idDto.id)
|
|
138
159
|
);
|
|
139
160
|
if (!sessionExists) {
|
|
140
|
-
throw new Error(
|
|
161
|
+
throw new Error('Session not found');
|
|
141
162
|
}
|
|
142
163
|
await this.cache.deleteRecord(this.createCacheKey(idDto.id));
|
|
143
164
|
}
|
|
144
165
|
};
|
|
145
166
|
|
|
146
167
|
// services/checkoutSession.service.ts
|
|
147
|
-
var import_cache2 = require(
|
|
148
|
-
var import_http2 = require(
|
|
149
|
-
var import_internal2 = require(
|
|
168
|
+
var import_cache2 = require('@forklaunch/core/cache');
|
|
169
|
+
var import_http2 = require('@forklaunch/core/http');
|
|
170
|
+
var import_internal2 = require('@forklaunch/internal');
|
|
150
171
|
var BaseCheckoutSessionService = class {
|
|
151
|
-
constructor(
|
|
172
|
+
constructor(
|
|
173
|
+
em,
|
|
174
|
+
cache,
|
|
175
|
+
openTelemetryCollector,
|
|
176
|
+
schemaValidator,
|
|
177
|
+
mappers,
|
|
178
|
+
options
|
|
179
|
+
) {
|
|
152
180
|
this.options = options;
|
|
153
181
|
this.em = em;
|
|
154
182
|
this.cache = cache;
|
|
155
183
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
156
184
|
this.schemaValidator = schemaValidator;
|
|
157
185
|
this.mappers = mappers;
|
|
158
|
-
this._mappers = (0, import_internal2.transformIntoInternalMapper)(
|
|
186
|
+
this._mappers = (0, import_internal2.transformIntoInternalMapper)(
|
|
187
|
+
mappers,
|
|
188
|
+
schemaValidator
|
|
189
|
+
);
|
|
159
190
|
this.enableDatabaseBackup = options?.enableDatabaseBackup ?? false;
|
|
160
|
-
this.evaluatedTelemetryOptions = options?.telemetry
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
191
|
+
this.evaluatedTelemetryOptions = options?.telemetry
|
|
192
|
+
? (0, import_http2.evaluateTelemetryOptions)(options.telemetry).enabled
|
|
193
|
+
: {
|
|
194
|
+
logging: false,
|
|
195
|
+
metrics: false,
|
|
196
|
+
tracing: false
|
|
197
|
+
};
|
|
165
198
|
}
|
|
166
199
|
_mappers;
|
|
167
200
|
evaluatedTelemetryOptions;
|
|
@@ -171,21 +204,23 @@ var BaseCheckoutSessionService = class {
|
|
|
171
204
|
openTelemetryCollector;
|
|
172
205
|
schemaValidator;
|
|
173
206
|
mappers;
|
|
174
|
-
createCacheKey = (0, import_cache2.createCacheKey)(
|
|
207
|
+
createCacheKey = (0, import_cache2.createCacheKey)('checkout_session');
|
|
175
208
|
async createCheckoutSession(checkoutSessionDto) {
|
|
176
209
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
177
210
|
this.openTelemetryCollector.info(
|
|
178
|
-
|
|
211
|
+
'Creating checkout session',
|
|
179
212
|
checkoutSessionDto
|
|
180
213
|
);
|
|
181
214
|
}
|
|
182
|
-
const checkoutSession =
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
215
|
+
const checkoutSession =
|
|
216
|
+
await this._mappers.CreateCheckoutSessionMapper.deserializeDtoToEntity(
|
|
217
|
+
checkoutSessionDto,
|
|
218
|
+
this.em
|
|
219
|
+
);
|
|
220
|
+
const createdCheckoutSessionDto =
|
|
221
|
+
await this._mappers.CheckoutSessionMapper.serializeEntityToDto(
|
|
222
|
+
checkoutSession
|
|
223
|
+
);
|
|
189
224
|
if (this.enableDatabaseBackup) {
|
|
190
225
|
await this.em.persistAndFlush(checkoutSession);
|
|
191
226
|
}
|
|
@@ -196,12 +231,12 @@ var BaseCheckoutSessionService = class {
|
|
|
196
231
|
});
|
|
197
232
|
return createdCheckoutSessionDto;
|
|
198
233
|
}
|
|
199
|
-
async getCheckoutSession({
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
234
|
+
async getCheckoutSession({ id }) {
|
|
235
|
+
const checkoutSessionDetails = await this.cache.readRecord(
|
|
236
|
+
this.createCacheKey(id)
|
|
237
|
+
);
|
|
203
238
|
if (!checkoutSessionDetails) {
|
|
204
|
-
throw new Error(
|
|
239
|
+
throw new Error('Session not found');
|
|
205
240
|
}
|
|
206
241
|
return this._mappers.CheckoutSessionMapper.serializeEntityToDto(
|
|
207
242
|
checkoutSessionDetails.value
|
|
@@ -212,18 +247,18 @@ var BaseCheckoutSessionService = class {
|
|
|
212
247
|
this.createCacheKey(id)
|
|
213
248
|
);
|
|
214
249
|
if (!checkoutSessionDetails) {
|
|
215
|
-
throw new Error(
|
|
250
|
+
throw new Error('Session not found');
|
|
216
251
|
}
|
|
217
252
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
218
253
|
}
|
|
219
254
|
async handleCheckoutSuccess({ id }) {
|
|
220
255
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
221
|
-
this.openTelemetryCollector.info(
|
|
256
|
+
this.openTelemetryCollector.info('Checkout success', { id });
|
|
222
257
|
}
|
|
223
258
|
if (this.enableDatabaseBackup) {
|
|
224
|
-
const checkoutSession = await this.em.upsert(
|
|
259
|
+
const checkoutSession = await this.em.upsert('CheckoutSession', {
|
|
225
260
|
id,
|
|
226
|
-
status:
|
|
261
|
+
status: 'SUCCESS'
|
|
227
262
|
});
|
|
228
263
|
await this.em.persistAndFlush(checkoutSession);
|
|
229
264
|
}
|
|
@@ -231,12 +266,12 @@ var BaseCheckoutSessionService = class {
|
|
|
231
266
|
}
|
|
232
267
|
async handleCheckoutFailure({ id }) {
|
|
233
268
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
234
|
-
this.openTelemetryCollector.info(
|
|
269
|
+
this.openTelemetryCollector.info('Checkout failure', { id });
|
|
235
270
|
}
|
|
236
271
|
if (this.enableDatabaseBackup) {
|
|
237
|
-
const checkoutSession = await this.em.upsert(
|
|
272
|
+
const checkoutSession = await this.em.upsert('CheckoutSession', {
|
|
238
273
|
id,
|
|
239
|
-
status:
|
|
274
|
+
status: 'FAILED'
|
|
240
275
|
});
|
|
241
276
|
await this.em.persistAndFlush(checkoutSession);
|
|
242
277
|
}
|
|
@@ -245,24 +280,36 @@ var BaseCheckoutSessionService = class {
|
|
|
245
280
|
};
|
|
246
281
|
|
|
247
282
|
// services/paymentLink.service.ts
|
|
248
|
-
var import_cache3 = require(
|
|
249
|
-
var import_http3 = require(
|
|
250
|
-
var import_internal3 = require(
|
|
283
|
+
var import_cache3 = require('@forklaunch/core/cache');
|
|
284
|
+
var import_http3 = require('@forklaunch/core/http');
|
|
285
|
+
var import_internal3 = require('@forklaunch/internal');
|
|
251
286
|
var BasePaymentLinkService = class {
|
|
252
|
-
constructor(
|
|
287
|
+
constructor(
|
|
288
|
+
em,
|
|
289
|
+
cache,
|
|
290
|
+
openTelemetryCollector,
|
|
291
|
+
schemaValidator,
|
|
292
|
+
mappers,
|
|
293
|
+
options
|
|
294
|
+
) {
|
|
253
295
|
this.options = options;
|
|
254
296
|
this.em = em;
|
|
255
297
|
this.cache = cache;
|
|
256
298
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
257
299
|
this.schemaValidator = schemaValidator;
|
|
258
300
|
this.mappers = mappers;
|
|
259
|
-
this._mappers = (0, import_internal3.transformIntoInternalMapper)(
|
|
301
|
+
this._mappers = (0, import_internal3.transformIntoInternalMapper)(
|
|
302
|
+
mappers,
|
|
303
|
+
schemaValidator
|
|
304
|
+
);
|
|
260
305
|
this.enableDatabaseBackup = options?.enableDatabaseBackup ?? false;
|
|
261
|
-
this.evaluatedTelemetryOptions = options?.telemetry
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
306
|
+
this.evaluatedTelemetryOptions = options?.telemetry
|
|
307
|
+
? (0, import_http3.evaluateTelemetryOptions)(options.telemetry).enabled
|
|
308
|
+
: {
|
|
309
|
+
logging: false,
|
|
310
|
+
metrics: false,
|
|
311
|
+
tracing: false
|
|
312
|
+
};
|
|
266
313
|
}
|
|
267
314
|
_mappers;
|
|
268
315
|
evaluatedTelemetryOptions;
|
|
@@ -272,20 +319,22 @@ var BasePaymentLinkService = class {
|
|
|
272
319
|
openTelemetryCollector;
|
|
273
320
|
schemaValidator;
|
|
274
321
|
mappers;
|
|
275
|
-
cacheKeyPrefix =
|
|
322
|
+
cacheKeyPrefix = 'payment_link';
|
|
276
323
|
createCacheKey = (0, import_cache3.createCacheKey)(this.cacheKeyPrefix);
|
|
277
324
|
async createPaymentLink(paymentLinkDto) {
|
|
278
325
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
279
|
-
this.openTelemetryCollector.info(
|
|
326
|
+
this.openTelemetryCollector.info('Creating payment link', paymentLinkDto);
|
|
280
327
|
}
|
|
281
|
-
const paymentLink =
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
328
|
+
const paymentLink =
|
|
329
|
+
await this._mappers.CreatePaymentLinkMapper.deserializeDtoToEntity(
|
|
330
|
+
paymentLinkDto,
|
|
331
|
+
this.em
|
|
332
|
+
);
|
|
285
333
|
if (this.enableDatabaseBackup) {
|
|
286
334
|
await this.em.persistAndFlush(paymentLink);
|
|
287
335
|
}
|
|
288
|
-
const createdPaymentLinkDto =
|
|
336
|
+
const createdPaymentLinkDto =
|
|
337
|
+
await this._mappers.PaymentLinkMapper.serializeEntityToDto(paymentLink);
|
|
289
338
|
await this.cache.putRecord({
|
|
290
339
|
key: this.createCacheKey(createdPaymentLinkDto.id),
|
|
291
340
|
value: createdPaymentLinkDto,
|
|
@@ -295,25 +344,26 @@ var BasePaymentLinkService = class {
|
|
|
295
344
|
}
|
|
296
345
|
async updatePaymentLink(paymentLinkDto) {
|
|
297
346
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
298
|
-
this.openTelemetryCollector.info(
|
|
347
|
+
this.openTelemetryCollector.info('Updating payment link', paymentLinkDto);
|
|
299
348
|
}
|
|
300
349
|
const cacheKey = this.createCacheKey(paymentLinkDto.id);
|
|
301
350
|
const existingLink = (await this.cache.readRecord(cacheKey))?.value;
|
|
302
351
|
if (!existingLink) {
|
|
303
|
-
throw new Error(
|
|
352
|
+
throw new Error('Payment link not found');
|
|
304
353
|
}
|
|
305
|
-
const paymentLink =
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
354
|
+
const paymentLink =
|
|
355
|
+
await this._mappers.UpdatePaymentLinkMapper.deserializeDtoToEntity(
|
|
356
|
+
paymentLinkDto,
|
|
357
|
+
this.em
|
|
358
|
+
);
|
|
309
359
|
if (this.enableDatabaseBackup) {
|
|
310
360
|
await this.em.persistAndFlush(paymentLink);
|
|
311
361
|
}
|
|
312
362
|
const updatedLinkDto = {
|
|
313
363
|
...existingLink,
|
|
314
|
-
...await this._mappers.PaymentLinkMapper.serializeEntityToDto(
|
|
364
|
+
...(await this._mappers.PaymentLinkMapper.serializeEntityToDto(
|
|
315
365
|
paymentLink
|
|
316
|
-
)
|
|
366
|
+
))
|
|
317
367
|
};
|
|
318
368
|
await this.cache.putRecord({
|
|
319
369
|
key: cacheKey,
|
|
@@ -324,58 +374,61 @@ var BasePaymentLinkService = class {
|
|
|
324
374
|
}
|
|
325
375
|
async getPaymentLink({ id }) {
|
|
326
376
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
327
|
-
this.openTelemetryCollector.info(
|
|
377
|
+
this.openTelemetryCollector.info('Getting payment link', { id });
|
|
328
378
|
}
|
|
329
379
|
const cacheKey = this.createCacheKey(id);
|
|
330
380
|
const paymentLink = await this.cache.readRecord(cacheKey);
|
|
331
381
|
if (!paymentLink) {
|
|
332
|
-
throw new Error(
|
|
382
|
+
throw new Error('Payment link not found');
|
|
333
383
|
}
|
|
334
384
|
return this._mappers.PaymentLinkMapper.serializeEntityToDto(
|
|
335
385
|
paymentLink.value
|
|
336
386
|
);
|
|
337
387
|
}
|
|
338
388
|
async expirePaymentLink({ id }) {
|
|
339
|
-
this.openTelemetryCollector.info(
|
|
389
|
+
this.openTelemetryCollector.info('Payment link expired', { id });
|
|
340
390
|
if (this.enableDatabaseBackup) {
|
|
341
|
-
const paymentLink = await this.em.upsert(
|
|
391
|
+
const paymentLink = await this.em.upsert('PaymentLink', {
|
|
342
392
|
id,
|
|
343
|
-
status:
|
|
393
|
+
status: 'EXPIRED'
|
|
344
394
|
});
|
|
345
395
|
await this.em.removeAndFlush(paymentLink);
|
|
346
396
|
}
|
|
347
397
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
348
398
|
}
|
|
349
399
|
async handlePaymentSuccess({ id }) {
|
|
350
|
-
this.openTelemetryCollector.info(
|
|
400
|
+
this.openTelemetryCollector.info('Payment link success', { id });
|
|
351
401
|
if (this.enableDatabaseBackup) {
|
|
352
|
-
const paymentLink = await this.em.upsert(
|
|
402
|
+
const paymentLink = await this.em.upsert('PaymentLink', {
|
|
353
403
|
id,
|
|
354
|
-
status:
|
|
404
|
+
status: 'COMPLETED'
|
|
355
405
|
});
|
|
356
406
|
await this.em.removeAndFlush(paymentLink);
|
|
357
407
|
}
|
|
358
408
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
359
409
|
}
|
|
360
410
|
async handlePaymentFailure({ id }) {
|
|
361
|
-
this.openTelemetryCollector.info(
|
|
411
|
+
this.openTelemetryCollector.info('Payment link failure', { id });
|
|
362
412
|
if (this.enableDatabaseBackup) {
|
|
363
|
-
const paymentLink = await this.em.upsert(
|
|
413
|
+
const paymentLink = await this.em.upsert('PaymentLink', {
|
|
364
414
|
id,
|
|
365
|
-
status:
|
|
415
|
+
status: 'FAILED'
|
|
366
416
|
});
|
|
367
417
|
await this.em.removeAndFlush(paymentLink);
|
|
368
418
|
}
|
|
369
419
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
370
420
|
}
|
|
371
421
|
async listPaymentLinks(idsDto) {
|
|
372
|
-
const keys =
|
|
422
|
+
const keys =
|
|
423
|
+
idsDto?.ids.map((id) => this.createCacheKey(id)) ??
|
|
424
|
+
(await this.cache.listKeys(this.cacheKeyPrefix));
|
|
373
425
|
return Promise.all(
|
|
374
426
|
keys.map(async (key) => {
|
|
375
427
|
const paymentLink = await this.cache.readRecord(key);
|
|
376
|
-
const paymentLinkDto =
|
|
377
|
-
|
|
378
|
-
|
|
428
|
+
const paymentLinkDto =
|
|
429
|
+
this._mappers.PaymentLinkMapper.serializeEntityToDto(
|
|
430
|
+
paymentLink.value
|
|
431
|
+
);
|
|
379
432
|
return paymentLinkDto;
|
|
380
433
|
})
|
|
381
434
|
);
|
|
@@ -383,8 +436,8 @@ var BasePaymentLinkService = class {
|
|
|
383
436
|
};
|
|
384
437
|
|
|
385
438
|
// services/plan.service.ts
|
|
386
|
-
var import_http4 = require(
|
|
387
|
-
var import_internal4 = require(
|
|
439
|
+
var import_http4 = require('@forklaunch/core/http');
|
|
440
|
+
var import_internal4 = require('@forklaunch/internal');
|
|
388
441
|
var BasePlanService = class {
|
|
389
442
|
constructor(em, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
390
443
|
this.options = options;
|
|
@@ -392,12 +445,17 @@ var BasePlanService = class {
|
|
|
392
445
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
393
446
|
this.schemaValidator = schemaValidator;
|
|
394
447
|
this.mappers = mappers;
|
|
395
|
-
this._mappers = (0, import_internal4.transformIntoInternalMapper)(
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
448
|
+
this._mappers = (0, import_internal4.transformIntoInternalMapper)(
|
|
449
|
+
mappers,
|
|
450
|
+
schemaValidator
|
|
451
|
+
);
|
|
452
|
+
this.evaluatedTelemetryOptions = options?.telemetry
|
|
453
|
+
? (0, import_http4.evaluateTelemetryOptions)(options.telemetry).enabled
|
|
454
|
+
: {
|
|
455
|
+
logging: false,
|
|
456
|
+
metrics: false,
|
|
457
|
+
tracing: false
|
|
458
|
+
};
|
|
401
459
|
}
|
|
402
460
|
_mappers;
|
|
403
461
|
evaluatedTelemetryOptions;
|
|
@@ -407,21 +465,19 @@ var BasePlanService = class {
|
|
|
407
465
|
mappers;
|
|
408
466
|
async listPlans(idsDto, em) {
|
|
409
467
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
410
|
-
this.openTelemetryCollector.info(
|
|
468
|
+
this.openTelemetryCollector.info('Listing plans', idsDto);
|
|
411
469
|
}
|
|
412
470
|
return Promise.all(
|
|
413
|
-
(
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
)
|
|
419
|
-
)
|
|
471
|
+
(
|
|
472
|
+
await (em ?? this.em).findAll('Plan', {
|
|
473
|
+
filters: idsDto?.ids ? { id: { $in: idsDto.ids } } : void 0
|
|
474
|
+
})
|
|
475
|
+
).map((plan) => this._mappers.PlanMapper.serializeEntityToDto(plan))
|
|
420
476
|
);
|
|
421
477
|
}
|
|
422
478
|
async createPlan(planDto, em) {
|
|
423
479
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
424
|
-
this.openTelemetryCollector.info(
|
|
480
|
+
this.openTelemetryCollector.info('Creating plan', planDto);
|
|
425
481
|
}
|
|
426
482
|
const plan = await this._mappers.CreatePlanMapper.deserializeDtoToEntity(
|
|
427
483
|
planDto,
|
|
@@ -434,16 +490,14 @@ var BasePlanService = class {
|
|
|
434
490
|
}
|
|
435
491
|
async getPlan(idDto, em) {
|
|
436
492
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
437
|
-
this.openTelemetryCollector.info(
|
|
493
|
+
this.openTelemetryCollector.info('Getting plan', idDto);
|
|
438
494
|
}
|
|
439
|
-
const plan = await (em ?? this.em).findOneOrFail(
|
|
440
|
-
return this._mappers.PlanMapper.serializeEntityToDto(
|
|
441
|
-
plan
|
|
442
|
-
);
|
|
495
|
+
const plan = await (em ?? this.em).findOneOrFail('Plan', idDto);
|
|
496
|
+
return this._mappers.PlanMapper.serializeEntityToDto(plan);
|
|
443
497
|
}
|
|
444
498
|
async updatePlan(planDto, em) {
|
|
445
499
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
446
|
-
this.openTelemetryCollector.info(
|
|
500
|
+
this.openTelemetryCollector.info('Updating plan', planDto);
|
|
447
501
|
}
|
|
448
502
|
const plan = await this._mappers.UpdatePlanMapper.deserializeDtoToEntity(
|
|
449
503
|
planDto,
|
|
@@ -453,20 +507,21 @@ var BasePlanService = class {
|
|
|
453
507
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
454
508
|
await innerEm.persist(plan);
|
|
455
509
|
});
|
|
456
|
-
const updatedPlanDto =
|
|
510
|
+
const updatedPlanDto =
|
|
511
|
+
await this._mappers.PlanMapper.serializeEntityToDto(updatedPlan);
|
|
457
512
|
return updatedPlanDto;
|
|
458
513
|
}
|
|
459
514
|
async deletePlan(idDto, em) {
|
|
460
515
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
461
|
-
this.openTelemetryCollector.info(
|
|
516
|
+
this.openTelemetryCollector.info('Deleting plan', idDto);
|
|
462
517
|
}
|
|
463
|
-
await (em ?? this.em).nativeDelete(
|
|
518
|
+
await (em ?? this.em).nativeDelete('Plan', idDto);
|
|
464
519
|
}
|
|
465
520
|
};
|
|
466
521
|
|
|
467
522
|
// services/subscription.service.ts
|
|
468
|
-
var import_http5 = require(
|
|
469
|
-
var import_internal5 = require(
|
|
523
|
+
var import_http5 = require('@forklaunch/core/http');
|
|
524
|
+
var import_internal5 = require('@forklaunch/internal');
|
|
470
525
|
var BaseSubscriptionService = class {
|
|
471
526
|
constructor(em, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
472
527
|
this.options = options;
|
|
@@ -474,12 +529,17 @@ var BaseSubscriptionService = class {
|
|
|
474
529
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
475
530
|
this.schemaValidator = schemaValidator;
|
|
476
531
|
this.mappers = mappers;
|
|
477
|
-
this._mappers = (0, import_internal5.transformIntoInternalMapper)(
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
532
|
+
this._mappers = (0, import_internal5.transformIntoInternalMapper)(
|
|
533
|
+
mappers,
|
|
534
|
+
this.schemaValidator
|
|
535
|
+
);
|
|
536
|
+
this.evaluatedTelemetryOptions = options?.telemetry
|
|
537
|
+
? (0, import_http5.evaluateTelemetryOptions)(options.telemetry).enabled
|
|
538
|
+
: {
|
|
539
|
+
logging: false,
|
|
540
|
+
metrics: false,
|
|
541
|
+
tracing: false
|
|
542
|
+
};
|
|
483
543
|
}
|
|
484
544
|
_mappers;
|
|
485
545
|
evaluatedTelemetryOptions;
|
|
@@ -490,115 +550,114 @@ var BaseSubscriptionService = class {
|
|
|
490
550
|
async createSubscription(subscriptionDto, em) {
|
|
491
551
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
492
552
|
this.openTelemetryCollector.info(
|
|
493
|
-
|
|
553
|
+
'Creating subscription',
|
|
494
554
|
subscriptionDto
|
|
495
555
|
);
|
|
496
556
|
}
|
|
497
|
-
const subscription =
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
557
|
+
const subscription =
|
|
558
|
+
await this._mappers.CreateSubscriptionMapper.deserializeDtoToEntity(
|
|
559
|
+
subscriptionDto,
|
|
560
|
+
em ?? this.em
|
|
561
|
+
);
|
|
501
562
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
502
563
|
await innerEm.persist(subscription);
|
|
503
564
|
});
|
|
504
|
-
const createdSubscriptionDto =
|
|
565
|
+
const createdSubscriptionDto =
|
|
566
|
+
await this._mappers.SubscriptionMapper.serializeEntityToDto(subscription);
|
|
505
567
|
return createdSubscriptionDto;
|
|
506
568
|
}
|
|
507
569
|
async getSubscription(idDto, em) {
|
|
508
570
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
509
|
-
this.openTelemetryCollector.info(
|
|
571
|
+
this.openTelemetryCollector.info('Getting subscription', idDto);
|
|
510
572
|
}
|
|
511
573
|
const subscription = await (em ?? this.em).findOneOrFail(
|
|
512
|
-
|
|
574
|
+
'Subscription',
|
|
513
575
|
idDto
|
|
514
576
|
);
|
|
515
|
-
return this._mappers.SubscriptionMapper.serializeEntityToDto(
|
|
516
|
-
subscription
|
|
517
|
-
);
|
|
577
|
+
return this._mappers.SubscriptionMapper.serializeEntityToDto(subscription);
|
|
518
578
|
}
|
|
519
579
|
async getUserSubscription({ id }, em) {
|
|
520
580
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
521
|
-
this.openTelemetryCollector.info(
|
|
581
|
+
this.openTelemetryCollector.info('Getting user subscription', id);
|
|
522
582
|
}
|
|
523
|
-
const subscription = await (em ?? this.em).findOneOrFail(
|
|
583
|
+
const subscription = await (em ?? this.em).findOneOrFail('Subscription', {
|
|
524
584
|
partyId: id,
|
|
525
|
-
partyType:
|
|
585
|
+
partyType: 'USER',
|
|
526
586
|
active: true
|
|
527
587
|
});
|
|
528
|
-
return this._mappers.SubscriptionMapper.serializeEntityToDto(
|
|
529
|
-
subscription
|
|
530
|
-
);
|
|
588
|
+
return this._mappers.SubscriptionMapper.serializeEntityToDto(subscription);
|
|
531
589
|
}
|
|
532
590
|
async getOrganizationSubscription({ id }, em) {
|
|
533
591
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
534
|
-
this.openTelemetryCollector.info(
|
|
592
|
+
this.openTelemetryCollector.info('Getting organization subscription', id);
|
|
535
593
|
}
|
|
536
|
-
const subscription = await (em ?? this.em).findOneOrFail(
|
|
594
|
+
const subscription = await (em ?? this.em).findOneOrFail('Subscription', {
|
|
537
595
|
partyId: id,
|
|
538
|
-
partyType:
|
|
596
|
+
partyType: 'ORGANIZATION',
|
|
539
597
|
active: true
|
|
540
598
|
});
|
|
541
|
-
return this._mappers.SubscriptionMapper.serializeEntityToDto(
|
|
542
|
-
subscription
|
|
543
|
-
);
|
|
599
|
+
return this._mappers.SubscriptionMapper.serializeEntityToDto(subscription);
|
|
544
600
|
}
|
|
545
601
|
async updateSubscription(subscriptionDto, em) {
|
|
546
602
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
547
603
|
this.openTelemetryCollector.info(
|
|
548
|
-
|
|
604
|
+
'Updating subscription',
|
|
549
605
|
subscriptionDto
|
|
550
606
|
);
|
|
551
607
|
}
|
|
552
|
-
const subscription =
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
608
|
+
const subscription =
|
|
609
|
+
this._mappers.UpdateSubscriptionMapper.deserializeDtoToEntity(
|
|
610
|
+
subscriptionDto,
|
|
611
|
+
em ?? this.em
|
|
612
|
+
);
|
|
556
613
|
const updatedSubscription = await (em ?? this.em).upsert(subscription);
|
|
557
614
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
558
615
|
await innerEm.persist(updatedSubscription);
|
|
559
616
|
});
|
|
560
|
-
const updatedSubscriptionDto =
|
|
561
|
-
|
|
562
|
-
|
|
617
|
+
const updatedSubscriptionDto =
|
|
618
|
+
await this._mappers.SubscriptionMapper.serializeEntityToDto(
|
|
619
|
+
updatedSubscription
|
|
620
|
+
);
|
|
563
621
|
return updatedSubscriptionDto;
|
|
564
622
|
}
|
|
565
623
|
async deleteSubscription(idDto, em) {
|
|
566
624
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
567
|
-
this.openTelemetryCollector.info(
|
|
625
|
+
this.openTelemetryCollector.info('Deleting subscription', idDto);
|
|
568
626
|
}
|
|
569
|
-
const subscription = await (em ?? this.em).findOne(
|
|
627
|
+
const subscription = await (em ?? this.em).findOne('Subscription', idDto);
|
|
570
628
|
if (!subscription) {
|
|
571
|
-
throw new Error(
|
|
629
|
+
throw new Error('Subscription not found');
|
|
572
630
|
}
|
|
573
631
|
await (em ?? this.em).removeAndFlush(subscription);
|
|
574
632
|
}
|
|
575
633
|
async listSubscriptions(idsDto, em) {
|
|
576
634
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
577
|
-
this.openTelemetryCollector.info(
|
|
578
|
-
}
|
|
579
|
-
const subscriptions = await (em ?? this.em).findAll(
|
|
580
|
-
where: idsDto.ids
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
635
|
+
this.openTelemetryCollector.info('Listing subscriptions', idsDto);
|
|
636
|
+
}
|
|
637
|
+
const subscriptions = await (em ?? this.em).findAll('Subscription', {
|
|
638
|
+
where: idsDto.ids
|
|
639
|
+
? {
|
|
640
|
+
id: {
|
|
641
|
+
$in: idsDto.ids
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
: void 0
|
|
585
645
|
});
|
|
586
646
|
return Promise.all(
|
|
587
647
|
subscriptions.map((subscription) => {
|
|
588
|
-
const subscriptionDto =
|
|
589
|
-
subscription
|
|
590
|
-
);
|
|
648
|
+
const subscriptionDto =
|
|
649
|
+
this._mappers.SubscriptionMapper.serializeEntityToDto(subscription);
|
|
591
650
|
return subscriptionDto;
|
|
592
651
|
})
|
|
593
652
|
);
|
|
594
653
|
}
|
|
595
654
|
async cancelSubscription(idDto, em) {
|
|
596
655
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
597
|
-
this.openTelemetryCollector.info(
|
|
656
|
+
this.openTelemetryCollector.info('Canceling subscription', idDto);
|
|
598
657
|
}
|
|
599
|
-
const subscription = await (em ?? this.em).findOne(
|
|
658
|
+
const subscription = await (em ?? this.em).findOne('Subscription', idDto);
|
|
600
659
|
if (!subscription) {
|
|
601
|
-
throw new Error(
|
|
660
|
+
throw new Error('Subscription not found');
|
|
602
661
|
}
|
|
603
662
|
subscription.active = false;
|
|
604
663
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
@@ -607,11 +666,11 @@ var BaseSubscriptionService = class {
|
|
|
607
666
|
}
|
|
608
667
|
async resumeSubscription(idDto, em) {
|
|
609
668
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
610
|
-
this.openTelemetryCollector.info(
|
|
669
|
+
this.openTelemetryCollector.info('Resuming subscription', idDto);
|
|
611
670
|
}
|
|
612
|
-
const subscription = await (em ?? this.em).findOne(
|
|
671
|
+
const subscription = await (em ?? this.em).findOne('Subscription', idDto);
|
|
613
672
|
if (!subscription) {
|
|
614
|
-
throw new Error(
|
|
673
|
+
throw new Error('Subscription not found');
|
|
615
674
|
}
|
|
616
675
|
subscription.active = true;
|
|
617
676
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
@@ -620,10 +679,11 @@ var BaseSubscriptionService = class {
|
|
|
620
679
|
}
|
|
621
680
|
};
|
|
622
681
|
// Annotate the CommonJS export names for ESM import in node:
|
|
623
|
-
0 &&
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
682
|
+
0 &&
|
|
683
|
+
(module.exports = {
|
|
684
|
+
BaseBillingPortalService,
|
|
685
|
+
BaseCheckoutSessionService,
|
|
686
|
+
BasePaymentLinkService,
|
|
687
|
+
BasePlanService,
|
|
688
|
+
BaseSubscriptionService
|
|
689
|
+
});
|