@forklaunch/implementation-billing-base 0.6.3 → 0.6.5

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