@forklaunch/implementation-billing-base 0.6.0 → 0.6.2

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