@forklaunch/implementation-billing-base 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/eject/domain/schemas/billingPortal.schema.ts +7 -5
- package/lib/eject/domain/schemas/checkoutSession.schema.ts +21 -13
- package/lib/eject/domain/schemas/paymentLink.schema.ts +22 -27
- package/lib/eject/domain/schemas/plan.schema.ts +21 -12
- package/lib/eject/domain/schemas/subscription.schema.ts +5 -5
- package/lib/eject/services/billingPortal.service.ts +42 -57
- package/lib/eject/services/checkoutSession.service.ts +48 -79
- package/lib/eject/services/paymentLink.service.ts +56 -67
- package/lib/eject/services/plan.service.ts +57 -67
- package/lib/eject/services/subscription.service.ts +55 -100
- package/lib/eject/types/baseBillingDto.types.ts +94 -0
- package/lib/eject/types/baseBillingEntity.types.ts +78 -0
- package/lib/schemas/index.d.mts +114 -124
- package/lib/schemas/index.d.ts +114 -124
- package/lib/schemas/index.js +102 -112
- package/lib/schemas/index.mjs +105 -113
- package/lib/services/index.d.mts +156 -162
- package/lib/services/index.d.ts +156 -162
- package/lib/services/index.js +42 -46
- package/lib/services/index.mjs +47 -51
- package/package.json +9 -8
package/lib/services/index.js
CHANGED
|
@@ -31,7 +31,7 @@ module.exports = __toCommonJS(services_exports);
|
|
|
31
31
|
// services/billingPortal.service.ts
|
|
32
32
|
var import_cache = require("@forklaunch/core/cache");
|
|
33
33
|
var import_http = require("@forklaunch/core/http");
|
|
34
|
-
var
|
|
34
|
+
var import_internal = require("@forklaunch/internal");
|
|
35
35
|
var BaseBillingPortalService = class {
|
|
36
36
|
constructor(em, cache, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
37
37
|
this.em = em;
|
|
@@ -40,7 +40,7 @@ var BaseBillingPortalService = class {
|
|
|
40
40
|
this.schemaValidator = schemaValidator;
|
|
41
41
|
this.mappers = mappers;
|
|
42
42
|
this.options = options;
|
|
43
|
-
this
|
|
43
|
+
this._mappers = (0, import_internal.transformIntoInternalMapper)(mappers, schemaValidator);
|
|
44
44
|
this.enableDatabaseBackup = options?.enableDatabaseBackup ?? false;
|
|
45
45
|
this.evaluatedTelemetryOptions = options?.telemetry ? (0, import_http.evaluateTelemetryOptions)(options.telemetry).enabled : {
|
|
46
46
|
logging: false,
|
|
@@ -48,7 +48,7 @@ var BaseBillingPortalService = class {
|
|
|
48
48
|
tracing: false
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
_mappers;
|
|
52
52
|
evaluatedTelemetryOptions;
|
|
53
53
|
enableDatabaseBackup;
|
|
54
54
|
createCacheKey = (0, import_cache.createCacheKey)("billing_portal_session");
|
|
@@ -59,14 +59,14 @@ var BaseBillingPortalService = class {
|
|
|
59
59
|
billingPortalDto
|
|
60
60
|
);
|
|
61
61
|
}
|
|
62
|
-
const billingPortal = await this
|
|
62
|
+
const billingPortal = await this._mappers.CreateBillingPortalMapper.deserializeDtoToEntity(
|
|
63
63
|
billingPortalDto,
|
|
64
64
|
this.em
|
|
65
65
|
);
|
|
66
66
|
if (this.enableDatabaseBackup) {
|
|
67
67
|
await this.em.persistAndFlush(billingPortal);
|
|
68
68
|
}
|
|
69
|
-
const createdBillingPortalDto = await this
|
|
69
|
+
const createdBillingPortalDto = await this._mappers.BillingPortalMapper.serializeEntityToDto(
|
|
70
70
|
billingPortal
|
|
71
71
|
);
|
|
72
72
|
await this.cache.putRecord({
|
|
@@ -99,7 +99,7 @@ var BaseBillingPortalService = class {
|
|
|
99
99
|
if (!existingBillingPortal) {
|
|
100
100
|
throw new Error("Session not found");
|
|
101
101
|
}
|
|
102
|
-
const billingPortal = await this
|
|
102
|
+
const billingPortal = await this._mappers.UpdateBillingPortalMapper.deserializeDtoToEntity(
|
|
103
103
|
billingPortalDto,
|
|
104
104
|
this.em
|
|
105
105
|
);
|
|
@@ -110,7 +110,7 @@ var BaseBillingPortalService = class {
|
|
|
110
110
|
}
|
|
111
111
|
const updatedBillingPortalDto = {
|
|
112
112
|
...existingBillingPortal,
|
|
113
|
-
...await this
|
|
113
|
+
...await this._mappers.BillingPortalMapper.serializeEntityToDto(
|
|
114
114
|
billingPortal
|
|
115
115
|
)
|
|
116
116
|
};
|
|
@@ -141,7 +141,7 @@ var BaseBillingPortalService = class {
|
|
|
141
141
|
// services/checkoutSession.service.ts
|
|
142
142
|
var import_cache2 = require("@forklaunch/core/cache");
|
|
143
143
|
var import_http2 = require("@forklaunch/core/http");
|
|
144
|
-
var
|
|
144
|
+
var import_internal2 = require("@forklaunch/internal");
|
|
145
145
|
var BaseCheckoutSessionService = class {
|
|
146
146
|
constructor(em, cache, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
147
147
|
this.em = em;
|
|
@@ -150,7 +150,7 @@ var BaseCheckoutSessionService = class {
|
|
|
150
150
|
this.schemaValidator = schemaValidator;
|
|
151
151
|
this.mappers = mappers;
|
|
152
152
|
this.options = options;
|
|
153
|
-
this
|
|
153
|
+
this._mappers = (0, import_internal2.transformIntoInternalMapper)(mappers, schemaValidator);
|
|
154
154
|
this.enableDatabaseBackup = options?.enableDatabaseBackup ?? false;
|
|
155
155
|
this.evaluatedTelemetryOptions = options?.telemetry ? (0, import_http2.evaluateTelemetryOptions)(options.telemetry).enabled : {
|
|
156
156
|
logging: false,
|
|
@@ -158,7 +158,7 @@ var BaseCheckoutSessionService = class {
|
|
|
158
158
|
tracing: false
|
|
159
159
|
};
|
|
160
160
|
}
|
|
161
|
-
|
|
161
|
+
_mappers;
|
|
162
162
|
evaluatedTelemetryOptions;
|
|
163
163
|
enableDatabaseBackup;
|
|
164
164
|
createCacheKey = (0, import_cache2.createCacheKey)("checkout_session");
|
|
@@ -169,11 +169,11 @@ var BaseCheckoutSessionService = class {
|
|
|
169
169
|
checkoutSessionDto
|
|
170
170
|
);
|
|
171
171
|
}
|
|
172
|
-
const checkoutSession = await this
|
|
172
|
+
const checkoutSession = await this._mappers.CreateCheckoutSessionMapper.deserializeDtoToEntity(
|
|
173
173
|
checkoutSessionDto,
|
|
174
174
|
this.em
|
|
175
175
|
);
|
|
176
|
-
const createdCheckoutSessionDto = await this
|
|
176
|
+
const createdCheckoutSessionDto = await this._mappers.CheckoutSessionMapper.serializeEntityToDto(
|
|
177
177
|
checkoutSession
|
|
178
178
|
);
|
|
179
179
|
if (this.enableDatabaseBackup) {
|
|
@@ -193,7 +193,7 @@ var BaseCheckoutSessionService = class {
|
|
|
193
193
|
if (!checkoutSessionDetails) {
|
|
194
194
|
throw new Error("Session not found");
|
|
195
195
|
}
|
|
196
|
-
return this
|
|
196
|
+
return this._mappers.CheckoutSessionMapper.serializeEntityToDto(
|
|
197
197
|
checkoutSessionDetails.value
|
|
198
198
|
);
|
|
199
199
|
}
|
|
@@ -237,7 +237,7 @@ var BaseCheckoutSessionService = class {
|
|
|
237
237
|
// services/paymentLink.service.ts
|
|
238
238
|
var import_cache3 = require("@forklaunch/core/cache");
|
|
239
239
|
var import_http3 = require("@forklaunch/core/http");
|
|
240
|
-
var
|
|
240
|
+
var import_internal3 = require("@forklaunch/internal");
|
|
241
241
|
var BasePaymentLinkService = class {
|
|
242
242
|
constructor(em, cache, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
243
243
|
this.em = em;
|
|
@@ -246,7 +246,7 @@ var BasePaymentLinkService = class {
|
|
|
246
246
|
this.schemaValidator = schemaValidator;
|
|
247
247
|
this.mappers = mappers;
|
|
248
248
|
this.options = options;
|
|
249
|
-
this
|
|
249
|
+
this._mappers = (0, import_internal3.transformIntoInternalMapper)(mappers, schemaValidator);
|
|
250
250
|
this.enableDatabaseBackup = options?.enableDatabaseBackup ?? false;
|
|
251
251
|
this.evaluatedTelemetryOptions = options?.telemetry ? (0, import_http3.evaluateTelemetryOptions)(options.telemetry).enabled : {
|
|
252
252
|
logging: false,
|
|
@@ -254,7 +254,7 @@ var BasePaymentLinkService = class {
|
|
|
254
254
|
tracing: false
|
|
255
255
|
};
|
|
256
256
|
}
|
|
257
|
-
|
|
257
|
+
_mappers;
|
|
258
258
|
evaluatedTelemetryOptions;
|
|
259
259
|
enableDatabaseBackup;
|
|
260
260
|
cacheKeyPrefix = "payment_link";
|
|
@@ -263,16 +263,14 @@ var BasePaymentLinkService = class {
|
|
|
263
263
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
264
264
|
this.openTelemetryCollector.info("Creating payment link", paymentLinkDto);
|
|
265
265
|
}
|
|
266
|
-
const paymentLink = await this
|
|
266
|
+
const paymentLink = await this._mappers.CreatePaymentLinkMapper.deserializeDtoToEntity(
|
|
267
267
|
paymentLinkDto,
|
|
268
268
|
this.em
|
|
269
269
|
);
|
|
270
270
|
if (this.enableDatabaseBackup) {
|
|
271
271
|
await this.em.persistAndFlush(paymentLink);
|
|
272
272
|
}
|
|
273
|
-
const createdPaymentLinkDto = await this
|
|
274
|
-
paymentLink
|
|
275
|
-
);
|
|
273
|
+
const createdPaymentLinkDto = await this._mappers.PaymentLinkMapper.serializeEntityToDto(paymentLink);
|
|
276
274
|
await this.cache.putRecord({
|
|
277
275
|
key: this.createCacheKey(createdPaymentLinkDto.id),
|
|
278
276
|
value: createdPaymentLinkDto,
|
|
@@ -289,7 +287,7 @@ var BasePaymentLinkService = class {
|
|
|
289
287
|
if (!existingLink) {
|
|
290
288
|
throw new Error("Payment link not found");
|
|
291
289
|
}
|
|
292
|
-
const paymentLink = await this
|
|
290
|
+
const paymentLink = await this._mappers.UpdatePaymentLinkMapper.deserializeDtoToEntity(
|
|
293
291
|
paymentLinkDto,
|
|
294
292
|
this.em
|
|
295
293
|
);
|
|
@@ -298,7 +296,7 @@ var BasePaymentLinkService = class {
|
|
|
298
296
|
}
|
|
299
297
|
const updatedLinkDto = {
|
|
300
298
|
...existingLink,
|
|
301
|
-
...await this
|
|
299
|
+
...await this._mappers.PaymentLinkMapper.serializeEntityToDto(
|
|
302
300
|
paymentLink
|
|
303
301
|
)
|
|
304
302
|
};
|
|
@@ -318,7 +316,7 @@ var BasePaymentLinkService = class {
|
|
|
318
316
|
if (!paymentLink) {
|
|
319
317
|
throw new Error("Payment link not found");
|
|
320
318
|
}
|
|
321
|
-
return this
|
|
319
|
+
return this._mappers.PaymentLinkMapper.serializeEntityToDto(
|
|
322
320
|
paymentLink.value
|
|
323
321
|
);
|
|
324
322
|
}
|
|
@@ -360,7 +358,7 @@ var BasePaymentLinkService = class {
|
|
|
360
358
|
return Promise.all(
|
|
361
359
|
keys.map(async (key) => {
|
|
362
360
|
const paymentLink = await this.cache.readRecord(key);
|
|
363
|
-
const paymentLinkDto = this
|
|
361
|
+
const paymentLinkDto = this._mappers.PaymentLinkMapper.serializeEntityToDto(
|
|
364
362
|
paymentLink.value
|
|
365
363
|
);
|
|
366
364
|
return paymentLinkDto;
|
|
@@ -371,7 +369,7 @@ var BasePaymentLinkService = class {
|
|
|
371
369
|
|
|
372
370
|
// services/plan.service.ts
|
|
373
371
|
var import_http4 = require("@forklaunch/core/http");
|
|
374
|
-
var
|
|
372
|
+
var import_internal4 = require("@forklaunch/internal");
|
|
375
373
|
var BasePlanService = class {
|
|
376
374
|
constructor(em, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
377
375
|
this.em = em;
|
|
@@ -379,14 +377,14 @@ var BasePlanService = class {
|
|
|
379
377
|
this.schemaValidator = schemaValidator;
|
|
380
378
|
this.mappers = mappers;
|
|
381
379
|
this.options = options;
|
|
382
|
-
this
|
|
380
|
+
this._mappers = (0, import_internal4.transformIntoInternalMapper)(mappers, schemaValidator);
|
|
383
381
|
this.evaluatedTelemetryOptions = options?.telemetry ? (0, import_http4.evaluateTelemetryOptions)(options.telemetry).enabled : {
|
|
384
382
|
logging: false,
|
|
385
383
|
metrics: false,
|
|
386
384
|
tracing: false
|
|
387
385
|
};
|
|
388
386
|
}
|
|
389
|
-
|
|
387
|
+
_mappers;
|
|
390
388
|
evaluatedTelemetryOptions;
|
|
391
389
|
async listPlans(idsDto, em) {
|
|
392
390
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
@@ -396,7 +394,7 @@ var BasePlanService = class {
|
|
|
396
394
|
(await (em ?? this.em).findAll("Plan", {
|
|
397
395
|
filters: idsDto?.ids ? { id: { $in: idsDto.ids } } : void 0
|
|
398
396
|
})).map(
|
|
399
|
-
(plan) => this
|
|
397
|
+
(plan) => this._mappers.PlanMapper.serializeEntityToDto(
|
|
400
398
|
plan
|
|
401
399
|
)
|
|
402
400
|
)
|
|
@@ -406,21 +404,21 @@ var BasePlanService = class {
|
|
|
406
404
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
407
405
|
this.openTelemetryCollector.info("Creating plan", planDto);
|
|
408
406
|
}
|
|
409
|
-
const plan = await this
|
|
407
|
+
const plan = await this._mappers.CreatePlanMapper.deserializeDtoToEntity(
|
|
410
408
|
planDto,
|
|
411
409
|
em ?? this.em
|
|
412
410
|
);
|
|
413
411
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
414
412
|
await innerEm.persist(plan);
|
|
415
413
|
});
|
|
416
|
-
return this
|
|
414
|
+
return this._mappers.PlanMapper.serializeEntityToDto(plan);
|
|
417
415
|
}
|
|
418
416
|
async getPlan(idDto, em) {
|
|
419
417
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
420
418
|
this.openTelemetryCollector.info("Getting plan", idDto);
|
|
421
419
|
}
|
|
422
420
|
const plan = await (em ?? this.em).findOneOrFail("Plan", idDto);
|
|
423
|
-
return this
|
|
421
|
+
return this._mappers.PlanMapper.serializeEntityToDto(
|
|
424
422
|
plan
|
|
425
423
|
);
|
|
426
424
|
}
|
|
@@ -428,7 +426,7 @@ var BasePlanService = class {
|
|
|
428
426
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
429
427
|
this.openTelemetryCollector.info("Updating plan", planDto);
|
|
430
428
|
}
|
|
431
|
-
const plan = await this
|
|
429
|
+
const plan = await this._mappers.UpdatePlanMapper.deserializeDtoToEntity(
|
|
432
430
|
planDto,
|
|
433
431
|
em ?? this.em
|
|
434
432
|
);
|
|
@@ -436,7 +434,7 @@ var BasePlanService = class {
|
|
|
436
434
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
437
435
|
await innerEm.persist(plan);
|
|
438
436
|
});
|
|
439
|
-
const updatedPlanDto = await this
|
|
437
|
+
const updatedPlanDto = await this._mappers.PlanMapper.serializeEntityToDto(updatedPlan);
|
|
440
438
|
return updatedPlanDto;
|
|
441
439
|
}
|
|
442
440
|
async deletePlan(idDto, em) {
|
|
@@ -449,7 +447,7 @@ var BasePlanService = class {
|
|
|
449
447
|
|
|
450
448
|
// services/subscription.service.ts
|
|
451
449
|
var import_http5 = require("@forklaunch/core/http");
|
|
452
|
-
var
|
|
450
|
+
var import_internal5 = require("@forklaunch/internal");
|
|
453
451
|
var BaseSubscriptionService = class {
|
|
454
452
|
constructor(em, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
455
453
|
this.em = em;
|
|
@@ -457,14 +455,14 @@ var BaseSubscriptionService = class {
|
|
|
457
455
|
this.schemaValidator = schemaValidator;
|
|
458
456
|
this.mappers = mappers;
|
|
459
457
|
this.options = options;
|
|
460
|
-
this
|
|
458
|
+
this._mappers = (0, import_internal5.transformIntoInternalMapper)(mappers, this.schemaValidator);
|
|
461
459
|
this.evaluatedTelemetryOptions = options?.telemetry ? (0, import_http5.evaluateTelemetryOptions)(options.telemetry).enabled : {
|
|
462
460
|
logging: false,
|
|
463
461
|
metrics: false,
|
|
464
462
|
tracing: false
|
|
465
463
|
};
|
|
466
464
|
}
|
|
467
|
-
|
|
465
|
+
_mappers;
|
|
468
466
|
evaluatedTelemetryOptions;
|
|
469
467
|
async createSubscription(subscriptionDto, em) {
|
|
470
468
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
@@ -473,16 +471,14 @@ var BaseSubscriptionService = class {
|
|
|
473
471
|
subscriptionDto
|
|
474
472
|
);
|
|
475
473
|
}
|
|
476
|
-
const subscription = await this
|
|
474
|
+
const subscription = await this._mappers.CreateSubscriptionMapper.deserializeDtoToEntity(
|
|
477
475
|
subscriptionDto,
|
|
478
476
|
em ?? this.em
|
|
479
477
|
);
|
|
480
478
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
481
479
|
await innerEm.persist(subscription);
|
|
482
480
|
});
|
|
483
|
-
const createdSubscriptionDto = await this
|
|
484
|
-
subscription
|
|
485
|
-
);
|
|
481
|
+
const createdSubscriptionDto = await this._mappers.SubscriptionMapper.serializeEntityToDto(subscription);
|
|
486
482
|
return createdSubscriptionDto;
|
|
487
483
|
}
|
|
488
484
|
async getSubscription(idDto, em) {
|
|
@@ -493,7 +489,7 @@ var BaseSubscriptionService = class {
|
|
|
493
489
|
"Subscription",
|
|
494
490
|
idDto
|
|
495
491
|
);
|
|
496
|
-
return this
|
|
492
|
+
return this._mappers.SubscriptionMapper.serializeEntityToDto(
|
|
497
493
|
subscription
|
|
498
494
|
);
|
|
499
495
|
}
|
|
@@ -506,7 +502,7 @@ var BaseSubscriptionService = class {
|
|
|
506
502
|
partyType: "USER",
|
|
507
503
|
active: true
|
|
508
504
|
});
|
|
509
|
-
return this
|
|
505
|
+
return this._mappers.SubscriptionMapper.serializeEntityToDto(
|
|
510
506
|
subscription
|
|
511
507
|
);
|
|
512
508
|
}
|
|
@@ -519,7 +515,7 @@ var BaseSubscriptionService = class {
|
|
|
519
515
|
partyType: "ORGANIZATION",
|
|
520
516
|
active: true
|
|
521
517
|
});
|
|
522
|
-
return this
|
|
518
|
+
return this._mappers.SubscriptionMapper.serializeEntityToDto(
|
|
523
519
|
subscription
|
|
524
520
|
);
|
|
525
521
|
}
|
|
@@ -530,7 +526,7 @@ var BaseSubscriptionService = class {
|
|
|
530
526
|
subscriptionDto
|
|
531
527
|
);
|
|
532
528
|
}
|
|
533
|
-
const subscription = this
|
|
529
|
+
const subscription = this._mappers.UpdateSubscriptionMapper.deserializeDtoToEntity(
|
|
534
530
|
subscriptionDto,
|
|
535
531
|
em ?? this.em
|
|
536
532
|
);
|
|
@@ -538,7 +534,7 @@ var BaseSubscriptionService = class {
|
|
|
538
534
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
539
535
|
await innerEm.persist(updatedSubscription);
|
|
540
536
|
});
|
|
541
|
-
const updatedSubscriptionDto = await this
|
|
537
|
+
const updatedSubscriptionDto = await this._mappers.SubscriptionMapper.serializeEntityToDto(
|
|
542
538
|
updatedSubscription
|
|
543
539
|
);
|
|
544
540
|
return updatedSubscriptionDto;
|
|
@@ -566,7 +562,7 @@ var BaseSubscriptionService = class {
|
|
|
566
562
|
});
|
|
567
563
|
return Promise.all(
|
|
568
564
|
subscriptions.map((subscription) => {
|
|
569
|
-
const subscriptionDto = this
|
|
565
|
+
const subscriptionDto = this._mappers.SubscriptionMapper.serializeEntityToDto(
|
|
570
566
|
subscription
|
|
571
567
|
);
|
|
572
568
|
return subscriptionDto;
|