@forklaunch/implementation-billing-base 0.3.3 → 0.3.4

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