@forklaunch/implementation-billing-base 0.5.4 → 0.5.6

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