@forklaunch/implementation-billing-base 0.5.7 → 0.6.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.
@@ -35,8 +35,14 @@ module.exports = __toCommonJS(services_exports);
35
35
  // services/billingPortal.service.ts
36
36
  var import_cache = require('@forklaunch/core/cache');
37
37
  var import_http = require('@forklaunch/core/http');
38
- var import_internal = require('@forklaunch/internal');
39
38
  var BaseBillingPortalService = class {
39
+ evaluatedTelemetryOptions;
40
+ enableDatabaseBackup;
41
+ em;
42
+ cache;
43
+ openTelemetryCollector;
44
+ schemaValidator;
45
+ mappers;
40
46
  constructor(
41
47
  em,
42
48
  cache,
@@ -45,16 +51,11 @@ var BaseBillingPortalService = class {
45
51
  mappers,
46
52
  options
47
53
  ) {
48
- this.options = options;
49
54
  this.em = em;
50
55
  this.cache = cache;
51
56
  this.openTelemetryCollector = openTelemetryCollector;
52
57
  this.schemaValidator = schemaValidator;
53
58
  this.mappers = mappers;
54
- this._mappers = (0, import_internal.transformIntoInternalMapper)(
55
- mappers,
56
- schemaValidator
57
- );
58
59
  this.enableDatabaseBackup = options?.enableDatabaseBackup ?? false;
59
60
  this.evaluatedTelemetryOptions = options?.telemetry
60
61
  ? (0, import_http.evaluateTelemetryOptions)(options.telemetry).enabled
@@ -64,34 +65,24 @@ var BaseBillingPortalService = class {
64
65
  tracing: false
65
66
  };
66
67
  }
67
- _mappers;
68
- evaluatedTelemetryOptions;
69
- enableDatabaseBackup;
70
- em;
71
- cache;
72
- openTelemetryCollector;
73
- schemaValidator;
74
- mappers;
75
68
  createCacheKey = (0, import_cache.createCacheKey)('billing_portal_session');
76
- async createBillingPortalSession(billingPortalDto) {
69
+ async createBillingPortalSession(billingPortalDto, ...args) {
77
70
  if (this.evaluatedTelemetryOptions.logging) {
78
71
  this.openTelemetryCollector.info(
79
72
  'Creating billing portal session',
80
73
  billingPortalDto
81
74
  );
82
75
  }
83
- const billingPortal =
84
- await this._mappers.CreateBillingPortalMapper.deserializeDtoToEntity(
85
- billingPortalDto,
86
- this.em
87
- );
76
+ const billingPortal = await this.mappers.CreateBillingPortalMapper.toEntity(
77
+ billingPortalDto,
78
+ this.em,
79
+ ...args
80
+ );
88
81
  if (this.enableDatabaseBackup) {
89
82
  await this.em.persistAndFlush(billingPortal);
90
83
  }
91
84
  const createdBillingPortalDto =
92
- await this._mappers.BillingPortalMapper.serializeEntityToDto(
93
- billingPortal
94
- );
85
+ await this.mappers.BillingPortalMapper.toDto(billingPortal);
95
86
  await this.cache.putRecord({
96
87
  key: this.createCacheKey(createdBillingPortalDto.id),
97
88
  value: createdBillingPortalDto,
@@ -111,7 +102,7 @@ var BaseBillingPortalService = class {
111
102
  }
112
103
  return billingPortalDetails.value;
113
104
  }
114
- async updateBillingPortalSession(billingPortalDto) {
105
+ async updateBillingPortalSession(billingPortalDto, ...args) {
115
106
  if (this.evaluatedTelemetryOptions.logging) {
116
107
  this.openTelemetryCollector.info(
117
108
  'Updating billing portal session',
@@ -124,11 +115,11 @@ var BaseBillingPortalService = class {
124
115
  if (!existingBillingPortal) {
125
116
  throw new Error('Session not found');
126
117
  }
127
- const billingPortal =
128
- await this._mappers.UpdateBillingPortalMapper.deserializeDtoToEntity(
129
- billingPortalDto,
130
- this.em
131
- );
118
+ const billingPortal = await this.mappers.UpdateBillingPortalMapper.toEntity(
119
+ billingPortalDto,
120
+ this.em,
121
+ ...args
122
+ );
132
123
  if (this.enableDatabaseBackup) {
133
124
  await this.em.persistAndFlush({
134
125
  billingPortal
@@ -136,9 +127,7 @@ var BaseBillingPortalService = class {
136
127
  }
137
128
  const updatedBillingPortalDto = {
138
129
  ...existingBillingPortal,
139
- ...(await this._mappers.BillingPortalMapper.serializeEntityToDto(
140
- billingPortal
141
- ))
130
+ ...(await this.mappers.BillingPortalMapper.toDto(billingPortal))
142
131
  };
143
132
  await this.cache.putRecord({
144
133
  key: this.createCacheKey(updatedBillingPortalDto.id),
@@ -167,8 +156,14 @@ var BaseBillingPortalService = class {
167
156
  // services/checkoutSession.service.ts
168
157
  var import_cache2 = require('@forklaunch/core/cache');
169
158
  var import_http2 = require('@forklaunch/core/http');
170
- var import_internal2 = require('@forklaunch/internal');
171
159
  var BaseCheckoutSessionService = class {
160
+ evaluatedTelemetryOptions;
161
+ enableDatabaseBackup;
162
+ em;
163
+ cache;
164
+ openTelemetryCollector;
165
+ schemaValidator;
166
+ mappers;
172
167
  constructor(
173
168
  em,
174
169
  cache,
@@ -177,16 +172,11 @@ var BaseCheckoutSessionService = class {
177
172
  mappers,
178
173
  options
179
174
  ) {
180
- this.options = options;
181
175
  this.em = em;
182
176
  this.cache = cache;
183
177
  this.openTelemetryCollector = openTelemetryCollector;
184
178
  this.schemaValidator = schemaValidator;
185
179
  this.mappers = mappers;
186
- this._mappers = (0, import_internal2.transformIntoInternalMapper)(
187
- mappers,
188
- schemaValidator
189
- );
190
180
  this.enableDatabaseBackup = options?.enableDatabaseBackup ?? false;
191
181
  this.evaluatedTelemetryOptions = options?.telemetry
192
182
  ? (0, import_http2.evaluateTelemetryOptions)(options.telemetry).enabled
@@ -196,16 +186,8 @@ var BaseCheckoutSessionService = class {
196
186
  tracing: false
197
187
  };
198
188
  }
199
- _mappers;
200
- evaluatedTelemetryOptions;
201
- enableDatabaseBackup;
202
- em;
203
- cache;
204
- openTelemetryCollector;
205
- schemaValidator;
206
- mappers;
207
189
  createCacheKey = (0, import_cache2.createCacheKey)('checkout_session');
208
- async createCheckoutSession(checkoutSessionDto) {
190
+ async createCheckoutSession(checkoutSessionDto, ...args) {
209
191
  if (this.evaluatedTelemetryOptions.logging) {
210
192
  this.openTelemetryCollector.info(
211
193
  'Creating checkout session',
@@ -213,14 +195,13 @@ var BaseCheckoutSessionService = class {
213
195
  );
214
196
  }
215
197
  const checkoutSession =
216
- await this._mappers.CreateCheckoutSessionMapper.deserializeDtoToEntity(
198
+ await this.mappers.CreateCheckoutSessionMapper.toEntity(
217
199
  checkoutSessionDto,
218
- this.em
200
+ this.em,
201
+ ...args
219
202
  );
220
203
  const createdCheckoutSessionDto =
221
- await this._mappers.CheckoutSessionMapper.serializeEntityToDto(
222
- checkoutSession
223
- );
204
+ await this.mappers.CheckoutSessionMapper.toDto(checkoutSession);
224
205
  if (this.enableDatabaseBackup) {
225
206
  await this.em.persistAndFlush(checkoutSession);
226
207
  }
@@ -238,7 +219,7 @@ var BaseCheckoutSessionService = class {
238
219
  if (!checkoutSessionDetails) {
239
220
  throw new Error('Session not found');
240
221
  }
241
- return this._mappers.CheckoutSessionMapper.serializeEntityToDto(
222
+ return this.mappers.CheckoutSessionMapper.toDto(
242
223
  checkoutSessionDetails.value
243
224
  );
244
225
  }
@@ -282,8 +263,14 @@ var BaseCheckoutSessionService = class {
282
263
  // services/paymentLink.service.ts
283
264
  var import_cache3 = require('@forklaunch/core/cache');
284
265
  var import_http3 = require('@forklaunch/core/http');
285
- var import_internal3 = require('@forklaunch/internal');
286
266
  var BasePaymentLinkService = class {
267
+ evaluatedTelemetryOptions;
268
+ enableDatabaseBackup;
269
+ em;
270
+ cache;
271
+ openTelemetryCollector;
272
+ schemaValidator;
273
+ mappers;
287
274
  constructor(
288
275
  em,
289
276
  cache,
@@ -292,16 +279,11 @@ var BasePaymentLinkService = class {
292
279
  mappers,
293
280
  options
294
281
  ) {
295
- this.options = options;
296
282
  this.em = em;
297
283
  this.cache = cache;
298
284
  this.openTelemetryCollector = openTelemetryCollector;
299
285
  this.schemaValidator = schemaValidator;
300
286
  this.mappers = mappers;
301
- this._mappers = (0, import_internal3.transformIntoInternalMapper)(
302
- mappers,
303
- schemaValidator
304
- );
305
287
  this.enableDatabaseBackup = options?.enableDatabaseBackup ?? false;
306
288
  this.evaluatedTelemetryOptions = options?.telemetry
307
289
  ? (0, import_http3.evaluateTelemetryOptions)(options.telemetry).enabled
@@ -311,30 +293,22 @@ var BasePaymentLinkService = class {
311
293
  tracing: false
312
294
  };
313
295
  }
314
- _mappers;
315
- evaluatedTelemetryOptions;
316
- enableDatabaseBackup;
317
- em;
318
- cache;
319
- openTelemetryCollector;
320
- schemaValidator;
321
- mappers;
322
296
  cacheKeyPrefix = 'payment_link';
323
297
  createCacheKey = (0, import_cache3.createCacheKey)(this.cacheKeyPrefix);
324
- async createPaymentLink(paymentLinkDto) {
298
+ async createPaymentLink(paymentLinkDto, ...args) {
325
299
  if (this.evaluatedTelemetryOptions.logging) {
326
300
  this.openTelemetryCollector.info('Creating payment link', paymentLinkDto);
327
301
  }
328
- const paymentLink =
329
- await this._mappers.CreatePaymentLinkMapper.deserializeDtoToEntity(
330
- paymentLinkDto,
331
- this.em
332
- );
302
+ const paymentLink = await this.mappers.CreatePaymentLinkMapper.toEntity(
303
+ paymentLinkDto,
304
+ this.em,
305
+ ...args
306
+ );
333
307
  if (this.enableDatabaseBackup) {
334
308
  await this.em.persistAndFlush(paymentLink);
335
309
  }
336
310
  const createdPaymentLinkDto =
337
- await this._mappers.PaymentLinkMapper.serializeEntityToDto(paymentLink);
311
+ await this.mappers.PaymentLinkMapper.toDto(paymentLink);
338
312
  await this.cache.putRecord({
339
313
  key: this.createCacheKey(createdPaymentLinkDto.id),
340
314
  value: createdPaymentLinkDto,
@@ -342,7 +316,7 @@ var BasePaymentLinkService = class {
342
316
  });
343
317
  return createdPaymentLinkDto;
344
318
  }
345
- async updatePaymentLink(paymentLinkDto) {
319
+ async updatePaymentLink(paymentLinkDto, ...args) {
346
320
  if (this.evaluatedTelemetryOptions.logging) {
347
321
  this.openTelemetryCollector.info('Updating payment link', paymentLinkDto);
348
322
  }
@@ -351,19 +325,17 @@ var BasePaymentLinkService = class {
351
325
  if (!existingLink) {
352
326
  throw new Error('Payment link not found');
353
327
  }
354
- const paymentLink =
355
- await this._mappers.UpdatePaymentLinkMapper.deserializeDtoToEntity(
356
- paymentLinkDto,
357
- this.em
358
- );
328
+ const paymentLink = await this.mappers.UpdatePaymentLinkMapper.toEntity(
329
+ paymentLinkDto,
330
+ this.em,
331
+ ...args
332
+ );
359
333
  if (this.enableDatabaseBackup) {
360
334
  await this.em.persistAndFlush(paymentLink);
361
335
  }
362
336
  const updatedLinkDto = {
363
337
  ...existingLink,
364
- ...(await this._mappers.PaymentLinkMapper.serializeEntityToDto(
365
- paymentLink
366
- ))
338
+ ...(await this.mappers.PaymentLinkMapper.toDto(paymentLink))
367
339
  };
368
340
  await this.cache.putRecord({
369
341
  key: cacheKey,
@@ -381,9 +353,7 @@ var BasePaymentLinkService = class {
381
353
  if (!paymentLink) {
382
354
  throw new Error('Payment link not found');
383
355
  }
384
- return this._mappers.PaymentLinkMapper.serializeEntityToDto(
385
- paymentLink.value
386
- );
356
+ return this.mappers.PaymentLinkMapper.toDto(paymentLink.value);
387
357
  }
388
358
  async expirePaymentLink({ id }) {
389
359
  this.openTelemetryCollector.info('Payment link expired', { id });
@@ -425,10 +395,9 @@ var BasePaymentLinkService = class {
425
395
  return Promise.all(
426
396
  keys.map(async (key) => {
427
397
  const paymentLink = await this.cache.readRecord(key);
428
- const paymentLinkDto =
429
- this._mappers.PaymentLinkMapper.serializeEntityToDto(
430
- paymentLink.value
431
- );
398
+ const paymentLinkDto = this.mappers.PaymentLinkMapper.toDto(
399
+ paymentLink.value
400
+ );
432
401
  return paymentLinkDto;
433
402
  })
434
403
  );
@@ -437,18 +406,17 @@ var BasePaymentLinkService = class {
437
406
 
438
407
  // services/plan.service.ts
439
408
  var import_http4 = require('@forklaunch/core/http');
440
- var import_internal4 = require('@forklaunch/internal');
441
409
  var BasePlanService = class {
410
+ evaluatedTelemetryOptions;
411
+ em;
412
+ openTelemetryCollector;
413
+ schemaValidator;
414
+ mappers;
442
415
  constructor(em, openTelemetryCollector, schemaValidator, mappers, options) {
443
- this.options = options;
444
416
  this.em = em;
445
417
  this.openTelemetryCollector = openTelemetryCollector;
446
418
  this.schemaValidator = schemaValidator;
447
419
  this.mappers = mappers;
448
- this._mappers = (0, import_internal4.transformIntoInternalMapper)(
449
- mappers,
450
- schemaValidator
451
- );
452
420
  this.evaluatedTelemetryOptions = options?.telemetry
453
421
  ? (0, import_http4.evaluateTelemetryOptions)(options.telemetry).enabled
454
422
  : {
@@ -457,12 +425,6 @@ var BasePlanService = class {
457
425
  tracing: false
458
426
  };
459
427
  }
460
- _mappers;
461
- evaluatedTelemetryOptions;
462
- em;
463
- openTelemetryCollector;
464
- schemaValidator;
465
- mappers;
466
428
  async listPlans(idsDto, em) {
467
429
  if (this.evaluatedTelemetryOptions.logging) {
468
430
  this.openTelemetryCollector.info('Listing plans', idsDto);
@@ -472,43 +434,44 @@ var BasePlanService = class {
472
434
  await (em ?? this.em).findAll('Plan', {
473
435
  filters: idsDto?.ids ? { id: { $in: idsDto.ids } } : void 0
474
436
  })
475
- ).map((plan) => this._mappers.PlanMapper.serializeEntityToDto(plan))
437
+ ).map((plan) => this.mappers.PlanMapper.toDto(plan))
476
438
  );
477
439
  }
478
- async createPlan(planDto, em) {
440
+ async createPlan(planDto, em, ...args) {
479
441
  if (this.evaluatedTelemetryOptions.logging) {
480
442
  this.openTelemetryCollector.info('Creating plan', planDto);
481
443
  }
482
- const plan = await this._mappers.CreatePlanMapper.deserializeDtoToEntity(
444
+ const plan = await this.mappers.CreatePlanMapper.toEntity(
483
445
  planDto,
484
- em ?? this.em
446
+ em ?? this.em,
447
+ ...args
485
448
  );
486
449
  await (em ?? this.em).transactional(async (innerEm) => {
487
450
  await innerEm.persist(plan);
488
451
  });
489
- return this._mappers.PlanMapper.serializeEntityToDto(plan);
452
+ return this.mappers.PlanMapper.toDto(plan);
490
453
  }
491
454
  async getPlan(idDto, em) {
492
455
  if (this.evaluatedTelemetryOptions.logging) {
493
456
  this.openTelemetryCollector.info('Getting plan', idDto);
494
457
  }
495
458
  const plan = await (em ?? this.em).findOneOrFail('Plan', idDto);
496
- return this._mappers.PlanMapper.serializeEntityToDto(plan);
459
+ return this.mappers.PlanMapper.toDto(plan);
497
460
  }
498
- async updatePlan(planDto, em) {
461
+ async updatePlan(planDto, em, ...args) {
499
462
  if (this.evaluatedTelemetryOptions.logging) {
500
463
  this.openTelemetryCollector.info('Updating plan', planDto);
501
464
  }
502
- const plan = await this._mappers.UpdatePlanMapper.deserializeDtoToEntity(
465
+ const plan = await this.mappers.UpdatePlanMapper.toEntity(
503
466
  planDto,
504
- em ?? this.em
467
+ em ?? this.em,
468
+ ...args
505
469
  );
506
470
  const updatedPlan = await (em ?? this.em).upsert(plan);
507
471
  await (em ?? this.em).transactional(async (innerEm) => {
508
472
  await innerEm.persist(plan);
509
473
  });
510
- const updatedPlanDto =
511
- await this._mappers.PlanMapper.serializeEntityToDto(updatedPlan);
474
+ const updatedPlanDto = await this.mappers.PlanMapper.toDto(updatedPlan);
512
475
  return updatedPlanDto;
513
476
  }
514
477
  async deletePlan(idDto, em) {
@@ -521,7 +484,6 @@ var BasePlanService = class {
521
484
 
522
485
  // services/subscription.service.ts
523
486
  var import_http5 = require('@forklaunch/core/http');
524
- var import_internal5 = require('@forklaunch/internal');
525
487
  var BaseSubscriptionService = class {
526
488
  constructor(em, openTelemetryCollector, schemaValidator, mappers, options) {
527
489
  this.options = options;
@@ -529,10 +491,6 @@ var BaseSubscriptionService = class {
529
491
  this.openTelemetryCollector = openTelemetryCollector;
530
492
  this.schemaValidator = schemaValidator;
531
493
  this.mappers = mappers;
532
- this._mappers = (0, import_internal5.transformIntoInternalMapper)(
533
- mappers,
534
- this.schemaValidator
535
- );
536
494
  this.evaluatedTelemetryOptions = options?.telemetry
537
495
  ? (0, import_http5.evaluateTelemetryOptions)(options.telemetry).enabled
538
496
  : {
@@ -541,29 +499,28 @@ var BaseSubscriptionService = class {
541
499
  tracing: false
542
500
  };
543
501
  }
544
- _mappers;
545
502
  evaluatedTelemetryOptions;
546
503
  em;
547
504
  openTelemetryCollector;
548
505
  schemaValidator;
549
506
  mappers;
550
- async createSubscription(subscriptionDto, em) {
507
+ async createSubscription(subscriptionDto, em, ...args) {
551
508
  if (this.evaluatedTelemetryOptions.logging) {
552
509
  this.openTelemetryCollector.info(
553
510
  'Creating subscription',
554
511
  subscriptionDto
555
512
  );
556
513
  }
557
- const subscription =
558
- await this._mappers.CreateSubscriptionMapper.deserializeDtoToEntity(
559
- subscriptionDto,
560
- em ?? this.em
561
- );
514
+ const subscription = await this.mappers.CreateSubscriptionMapper.toEntity(
515
+ subscriptionDto,
516
+ em ?? this.em,
517
+ ...args
518
+ );
562
519
  await (em ?? this.em).transactional(async (innerEm) => {
563
520
  await innerEm.persist(subscription);
564
521
  });
565
522
  const createdSubscriptionDto =
566
- await this._mappers.SubscriptionMapper.serializeEntityToDto(subscription);
523
+ await this.mappers.SubscriptionMapper.toDto(subscription);
567
524
  return createdSubscriptionDto;
568
525
  }
569
526
  async getSubscription(idDto, em) {
@@ -574,7 +531,7 @@ var BaseSubscriptionService = class {
574
531
  'Subscription',
575
532
  idDto
576
533
  );
577
- return this._mappers.SubscriptionMapper.serializeEntityToDto(subscription);
534
+ return this.mappers.SubscriptionMapper.toDto(subscription);
578
535
  }
579
536
  async getUserSubscription({ id }, em) {
580
537
  if (this.evaluatedTelemetryOptions.logging) {
@@ -585,7 +542,7 @@ var BaseSubscriptionService = class {
585
542
  partyType: 'USER',
586
543
  active: true
587
544
  });
588
- return this._mappers.SubscriptionMapper.serializeEntityToDto(subscription);
545
+ return this.mappers.SubscriptionMapper.toDto(subscription);
589
546
  }
590
547
  async getOrganizationSubscription({ id }, em) {
591
548
  if (this.evaluatedTelemetryOptions.logging) {
@@ -596,28 +553,26 @@ var BaseSubscriptionService = class {
596
553
  partyType: 'ORGANIZATION',
597
554
  active: true
598
555
  });
599
- return this._mappers.SubscriptionMapper.serializeEntityToDto(subscription);
556
+ return this.mappers.SubscriptionMapper.toDto(subscription);
600
557
  }
601
- async updateSubscription(subscriptionDto, em) {
558
+ async updateSubscription(subscriptionDto, em, ...args) {
602
559
  if (this.evaluatedTelemetryOptions.logging) {
603
560
  this.openTelemetryCollector.info(
604
561
  'Updating subscription',
605
562
  subscriptionDto
606
563
  );
607
564
  }
608
- const subscription =
609
- this._mappers.UpdateSubscriptionMapper.deserializeDtoToEntity(
610
- subscriptionDto,
611
- em ?? this.em
612
- );
565
+ const subscription = await this.mappers.UpdateSubscriptionMapper.toEntity(
566
+ subscriptionDto,
567
+ em ?? this.em,
568
+ ...args
569
+ );
613
570
  const updatedSubscription = await (em ?? this.em).upsert(subscription);
614
571
  await (em ?? this.em).transactional(async (innerEm) => {
615
572
  await innerEm.persist(updatedSubscription);
616
573
  });
617
574
  const updatedSubscriptionDto =
618
- await this._mappers.SubscriptionMapper.serializeEntityToDto(
619
- updatedSubscription
620
- );
575
+ await this.mappers.SubscriptionMapper.toDto(updatedSubscription);
621
576
  return updatedSubscriptionDto;
622
577
  }
623
578
  async deleteSubscription(idDto, em) {
@@ -646,7 +601,7 @@ var BaseSubscriptionService = class {
646
601
  return Promise.all(
647
602
  subscriptions.map((subscription) => {
648
603
  const subscriptionDto =
649
- this._mappers.SubscriptionMapper.serializeEntityToDto(subscription);
604
+ this.mappers.SubscriptionMapper.toDto(subscription);
650
605
  return subscriptionDto;
651
606
  })
652
607
  );