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