@forklaunch/implementation-billing-base 0.8.23 → 1.0.0
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 +8 -8
- package/lib/domain/schemas/index.d.ts +8 -8
- package/lib/domain/schemas/index.js +8 -8
- package/lib/domain/schemas/index.mjs +8 -8
- package/lib/domain/types/index.d.mts +459 -31
- package/lib/domain/types/index.d.ts +459 -31
- package/lib/eject/domain/schemas/plan.schema.ts +2 -2
- package/lib/eject/domain/schemas/subscription.schema.ts +2 -2
- package/lib/eject/domain/types/baseBillingEntity.types.ts +97 -46
- package/lib/eject/domain/types/billingPortal.mapper.types.ts +7 -4
- package/lib/eject/domain/types/checkoutSession.mapper.types.ts +7 -4
- package/lib/eject/domain/types/paymentLink.mapper.types.ts +7 -4
- package/lib/eject/domain/types/plan.mapper.types.ts +7 -4
- package/lib/eject/domain/types/subscription.mapper.types.ts +7 -4
- package/lib/eject/services/billingPortal.service.ts +3 -5
- package/lib/eject/services/checkoutSession.service.ts +19 -12
- package/lib/eject/services/paymentLink.service.ts +27 -17
- package/lib/eject/services/plan.service.ts +22 -8
- package/lib/eject/services/subscription.service.ts +55 -28
- package/lib/services/index.d.mts +4 -3
- package/lib/services/index.d.ts +4 -3
- package/lib/services/index.js +101 -57
- package/lib/services/index.mjs +101 -57
- package/package.json +9 -9
package/lib/services/index.mjs
CHANGED
|
@@ -39,7 +39,7 @@ var BaseBillingPortalService = class {
|
|
|
39
39
|
...args[0] instanceof EntityManager ? args.slice(1) : args
|
|
40
40
|
);
|
|
41
41
|
if (this.enableDatabaseBackup) {
|
|
42
|
-
await this.em.
|
|
42
|
+
await this.em.persist(billingPortal).flush();
|
|
43
43
|
}
|
|
44
44
|
const createdBillingPortalDto = await this.mappers.BillingPortalMapper.toDto(billingPortal);
|
|
45
45
|
await this.cache.putRecord({
|
|
@@ -83,9 +83,7 @@ var BaseBillingPortalService = class {
|
|
|
83
83
|
...args[0] instanceof EntityManager ? args.slice(1) : args
|
|
84
84
|
);
|
|
85
85
|
if (this.enableDatabaseBackup) {
|
|
86
|
-
await this.em.
|
|
87
|
-
billingPortal
|
|
88
|
-
});
|
|
86
|
+
await this.em.persist(billingPortal).flush();
|
|
89
87
|
}
|
|
90
88
|
const updatedBillingPortalDto = {
|
|
91
89
|
...existingBillingPortal,
|
|
@@ -162,7 +160,7 @@ var BaseCheckoutSessionService = class {
|
|
|
162
160
|
);
|
|
163
161
|
const createdCheckoutSessionDto = await this.mappers.CheckoutSessionMapper.toDto(checkoutSession);
|
|
164
162
|
if (this.enableDatabaseBackup) {
|
|
165
|
-
await this.em.
|
|
163
|
+
await this.em.persist(checkoutSession).flush();
|
|
166
164
|
}
|
|
167
165
|
await this.cache.putRecord({
|
|
168
166
|
key: this.createCacheKey(createdCheckoutSessionDto.id),
|
|
@@ -199,11 +197,14 @@ var BaseCheckoutSessionService = class {
|
|
|
199
197
|
this.openTelemetryCollector.info("Checkout success", { id });
|
|
200
198
|
}
|
|
201
199
|
if (this.enableDatabaseBackup) {
|
|
202
|
-
const checkoutSession = await this.em.upsert(
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
200
|
+
const checkoutSession = await this.em.upsert(
|
|
201
|
+
this.mappers.CheckoutSessionMapper.entity,
|
|
202
|
+
{
|
|
203
|
+
id,
|
|
204
|
+
status: "SUCCESS"
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
await this.em.persist(checkoutSession).flush();
|
|
207
208
|
}
|
|
208
209
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
209
210
|
}
|
|
@@ -212,11 +213,14 @@ var BaseCheckoutSessionService = class {
|
|
|
212
213
|
this.openTelemetryCollector.info("Checkout failure", { id });
|
|
213
214
|
}
|
|
214
215
|
if (this.enableDatabaseBackup) {
|
|
215
|
-
const checkoutSession = await this.em.upsert(
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
216
|
+
const checkoutSession = await this.em.upsert(
|
|
217
|
+
this.mappers.CheckoutSessionMapper.entity,
|
|
218
|
+
{
|
|
219
|
+
id,
|
|
220
|
+
status: "FAILED"
|
|
221
|
+
}
|
|
222
|
+
);
|
|
223
|
+
await this.em.persist(checkoutSession).flush();
|
|
220
224
|
}
|
|
221
225
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
222
226
|
}
|
|
@@ -261,7 +265,7 @@ var BasePaymentLinkService = class {
|
|
|
261
265
|
...args[0] instanceof EntityManager3 ? args.slice(1) : args
|
|
262
266
|
);
|
|
263
267
|
if (this.enableDatabaseBackup) {
|
|
264
|
-
await this.em.
|
|
268
|
+
await this.em.persist(paymentLink).flush();
|
|
265
269
|
}
|
|
266
270
|
const createdPaymentLinkDto = await this.mappers.PaymentLinkMapper.toDto(paymentLink);
|
|
267
271
|
await this.cache.putRecord({
|
|
@@ -286,7 +290,7 @@ var BasePaymentLinkService = class {
|
|
|
286
290
|
...args[0] instanceof EntityManager3 ? args.slice(1) : args
|
|
287
291
|
);
|
|
288
292
|
if (this.enableDatabaseBackup) {
|
|
289
|
-
await this.em.
|
|
293
|
+
await this.em.persist(paymentLink).flush();
|
|
290
294
|
}
|
|
291
295
|
const updatedLinkDto = {
|
|
292
296
|
...existingLink,
|
|
@@ -315,33 +319,42 @@ var BasePaymentLinkService = class {
|
|
|
315
319
|
async expirePaymentLink({ id }) {
|
|
316
320
|
this.openTelemetryCollector.info("Payment link expired", { id });
|
|
317
321
|
if (this.enableDatabaseBackup) {
|
|
318
|
-
const paymentLink = await this.em.upsert(
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
322
|
+
const paymentLink = await this.em.upsert(
|
|
323
|
+
this.mappers.PaymentLinkMapper.entity,
|
|
324
|
+
{
|
|
325
|
+
id,
|
|
326
|
+
status: "EXPIRED"
|
|
327
|
+
}
|
|
328
|
+
);
|
|
329
|
+
await this.em.remove(paymentLink).flush();
|
|
323
330
|
}
|
|
324
331
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
325
332
|
}
|
|
326
333
|
async handlePaymentSuccess({ id }) {
|
|
327
334
|
this.openTelemetryCollector.info("Payment link success", { id });
|
|
328
335
|
if (this.enableDatabaseBackup) {
|
|
329
|
-
const paymentLink = await this.em.upsert(
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
336
|
+
const paymentLink = await this.em.upsert(
|
|
337
|
+
this.mappers.PaymentLinkMapper.entity,
|
|
338
|
+
{
|
|
339
|
+
id,
|
|
340
|
+
status: "COMPLETED"
|
|
341
|
+
}
|
|
342
|
+
);
|
|
343
|
+
await this.em.remove(paymentLink).flush();
|
|
334
344
|
}
|
|
335
345
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
336
346
|
}
|
|
337
347
|
async handlePaymentFailure({ id }) {
|
|
338
348
|
this.openTelemetryCollector.info("Payment link failure", { id });
|
|
339
349
|
if (this.enableDatabaseBackup) {
|
|
340
|
-
const paymentLink = await this.em.upsert(
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
350
|
+
const paymentLink = await this.em.upsert(
|
|
351
|
+
this.mappers.PaymentLinkMapper.entity,
|
|
352
|
+
{
|
|
353
|
+
id,
|
|
354
|
+
status: "FAILED"
|
|
355
|
+
}
|
|
356
|
+
);
|
|
357
|
+
await this.em.remove(paymentLink).flush();
|
|
345
358
|
}
|
|
346
359
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
347
360
|
}
|
|
@@ -383,10 +396,15 @@ var BasePlanService = class {
|
|
|
383
396
|
this.openTelemetryCollector.info("Listing plans", idsDto);
|
|
384
397
|
}
|
|
385
398
|
return Promise.all(
|
|
386
|
-
(await (em ?? this.em).findAll(
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
399
|
+
(await (em ?? this.em).findAll(
|
|
400
|
+
this.mappers.PlanMapper.entity,
|
|
401
|
+
{
|
|
402
|
+
where: idsDto?.ids?.length ? { id: { $in: idsDto.ids } } : void 0
|
|
403
|
+
}
|
|
404
|
+
)).map(
|
|
405
|
+
(plan) => this.mappers.PlanMapper.toDto(
|
|
406
|
+
plan
|
|
407
|
+
)
|
|
390
408
|
)
|
|
391
409
|
);
|
|
392
410
|
}
|
|
@@ -408,8 +426,13 @@ var BasePlanService = class {
|
|
|
408
426
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
409
427
|
this.openTelemetryCollector.info("Getting plan", idDto);
|
|
410
428
|
}
|
|
411
|
-
const plan = await (em ?? this.em).findOneOrFail(
|
|
412
|
-
|
|
429
|
+
const plan = await (em ?? this.em).findOneOrFail(
|
|
430
|
+
this.mappers.PlanMapper.entity,
|
|
431
|
+
idDto
|
|
432
|
+
);
|
|
433
|
+
return this.mappers.PlanMapper.toDto(
|
|
434
|
+
plan
|
|
435
|
+
);
|
|
413
436
|
}
|
|
414
437
|
async updatePlan(planDto, em, ...args) {
|
|
415
438
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
@@ -431,7 +454,10 @@ var BasePlanService = class {
|
|
|
431
454
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
432
455
|
this.openTelemetryCollector.info("Deleting plan", idDto);
|
|
433
456
|
}
|
|
434
|
-
await (em ?? this.em).nativeDelete(
|
|
457
|
+
await (em ?? this.em).nativeDelete(
|
|
458
|
+
this.mappers.PlanMapper.entity,
|
|
459
|
+
idDto
|
|
460
|
+
);
|
|
435
461
|
}
|
|
436
462
|
};
|
|
437
463
|
|
|
@@ -481,7 +507,7 @@ var BaseSubscriptionService = class {
|
|
|
481
507
|
this.openTelemetryCollector.info("Getting subscription", idDto);
|
|
482
508
|
}
|
|
483
509
|
const subscription = await (em ?? this.em).findOneOrFail(
|
|
484
|
-
|
|
510
|
+
this.mappers.SubscriptionMapper.entity,
|
|
485
511
|
idDto
|
|
486
512
|
);
|
|
487
513
|
return this.mappers.SubscriptionMapper.toDto(
|
|
@@ -492,11 +518,14 @@ var BaseSubscriptionService = class {
|
|
|
492
518
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
493
519
|
this.openTelemetryCollector.info("Getting user subscription", id);
|
|
494
520
|
}
|
|
495
|
-
const subscription = await (em ?? this.em).findOneOrFail(
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
521
|
+
const subscription = await (em ?? this.em).findOneOrFail(
|
|
522
|
+
this.mappers.SubscriptionMapper.entity,
|
|
523
|
+
{
|
|
524
|
+
partyId: id,
|
|
525
|
+
partyType: "USER",
|
|
526
|
+
active: true
|
|
527
|
+
}
|
|
528
|
+
);
|
|
500
529
|
return this.mappers.SubscriptionMapper.toDto(
|
|
501
530
|
subscription
|
|
502
531
|
);
|
|
@@ -505,11 +534,14 @@ var BaseSubscriptionService = class {
|
|
|
505
534
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
506
535
|
this.openTelemetryCollector.info("Getting organization subscription", id);
|
|
507
536
|
}
|
|
508
|
-
const subscription = await (em ?? this.em).findOneOrFail(
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
537
|
+
const subscription = await (em ?? this.em).findOneOrFail(
|
|
538
|
+
this.mappers.SubscriptionMapper.entity,
|
|
539
|
+
{
|
|
540
|
+
partyId: id,
|
|
541
|
+
partyType: "ORGANIZATION",
|
|
542
|
+
active: true
|
|
543
|
+
}
|
|
544
|
+
);
|
|
513
545
|
return this.mappers.SubscriptionMapper.toDto(
|
|
514
546
|
subscription
|
|
515
547
|
);
|
|
@@ -537,20 +569,26 @@ var BaseSubscriptionService = class {
|
|
|
537
569
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
538
570
|
this.openTelemetryCollector.info("Deleting subscription", idDto);
|
|
539
571
|
}
|
|
540
|
-
const subscription = await (em ?? this.em).findOne(
|
|
572
|
+
const subscription = await (em ?? this.em).findOne(
|
|
573
|
+
this.mappers.SubscriptionMapper.entity,
|
|
574
|
+
idDto
|
|
575
|
+
);
|
|
541
576
|
if (!subscription) {
|
|
542
577
|
throw new Error("Subscription not found");
|
|
543
578
|
}
|
|
544
|
-
await (em ?? this.em).
|
|
579
|
+
await (em ?? this.em).remove(subscription).flush();
|
|
545
580
|
}
|
|
546
581
|
async listSubscriptions(idsDto, em) {
|
|
547
582
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
548
583
|
this.openTelemetryCollector.info("Listing subscriptions", idsDto);
|
|
549
584
|
}
|
|
550
585
|
return Promise.all(
|
|
551
|
-
(await (em ?? this.em).findAll(
|
|
552
|
-
|
|
553
|
-
|
|
586
|
+
(await (em ?? this.em).findAll(
|
|
587
|
+
this.mappers.SubscriptionMapper.entity,
|
|
588
|
+
{
|
|
589
|
+
where: idsDto?.ids?.length ? { id: { $in: idsDto.ids } } : void 0
|
|
590
|
+
}
|
|
591
|
+
)).map(
|
|
554
592
|
(subscription) => this.mappers.SubscriptionMapper.toDto(
|
|
555
593
|
subscription
|
|
556
594
|
)
|
|
@@ -561,7 +599,10 @@ var BaseSubscriptionService = class {
|
|
|
561
599
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
562
600
|
this.openTelemetryCollector.info("Canceling subscription", idDto);
|
|
563
601
|
}
|
|
564
|
-
const subscription = await (em ?? this.em).findOne(
|
|
602
|
+
const subscription = await (em ?? this.em).findOne(
|
|
603
|
+
this.mappers.SubscriptionMapper.entity,
|
|
604
|
+
idDto
|
|
605
|
+
);
|
|
565
606
|
if (!subscription) {
|
|
566
607
|
throw new Error("Subscription not found");
|
|
567
608
|
}
|
|
@@ -574,7 +615,10 @@ var BaseSubscriptionService = class {
|
|
|
574
615
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
575
616
|
this.openTelemetryCollector.info("Resuming subscription", idDto);
|
|
576
617
|
}
|
|
577
|
-
const subscription = await (em ?? this.em).findOne(
|
|
618
|
+
const subscription = await (em ?? this.em).findOne(
|
|
619
|
+
this.mappers.SubscriptionMapper.entity,
|
|
620
|
+
idDto
|
|
621
|
+
);
|
|
578
622
|
if (!subscription) {
|
|
579
623
|
throw new Error("Subscription not found");
|
|
580
624
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forklaunch/implementation-billing-base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Billing basic implementation for forklaunch",
|
|
5
5
|
"homepage": "https://github.com/forklaunch/forklaunch-js#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -36,21 +36,21 @@
|
|
|
36
36
|
"lib/**"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@forklaunch/common": "^0.
|
|
40
|
-
"@forklaunch/core": "^0.
|
|
41
|
-
"@forklaunch/internal": "^0.
|
|
42
|
-
"@forklaunch/validator": "^0.
|
|
43
|
-
"@mikro-orm/core": "
|
|
39
|
+
"@forklaunch/common": "^1.0.13",
|
|
40
|
+
"@forklaunch/core": "^1.0.13",
|
|
41
|
+
"@forklaunch/internal": "^1.0.13",
|
|
42
|
+
"@forklaunch/validator": "^1.0.13",
|
|
43
|
+
"@mikro-orm/core": "7.0.5",
|
|
44
44
|
"@sinclair/typebox": "^0.34.48",
|
|
45
45
|
"ajv": "^8.18.0",
|
|
46
46
|
"zod": "^4.3.6",
|
|
47
|
-
"@forklaunch/interfaces-billing": "0.
|
|
47
|
+
"@forklaunch/interfaces-billing": "1.0.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
50
|
+
"@typescript/native-preview": "7.0.0-dev.20260301.1",
|
|
51
51
|
"depcheck": "^1.4.7",
|
|
52
52
|
"prettier": "^3.8.1",
|
|
53
|
-
"typedoc": "^0.28.
|
|
53
|
+
"typedoc": "^0.28.18"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"build": "tsgo --noEmit && tsup domain/schemas/index.ts services/index.ts domain/types/index.ts --format cjs,esm --no-splitting --dts --tsconfig tsconfig.json --out-dir lib --clean && if [ -f eject-package.bash ]; then pnpm package:eject; fi",
|