@forklaunch/implementation-billing-base 0.3.2 → 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,48 +1,55 @@
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
- transformIntoInternalDtoMapper
8
- } from "@forklaunch/core/mappers";
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;
14
17
  this.schemaValidator = schemaValidator;
15
18
  this.mappers = mappers;
16
19
  this.options = options;
17
- this.#mappers = transformIntoInternalDtoMapper(mappers, schemaValidator);
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
- };
24
- }
25
- #mappers;
22
+ this.evaluatedTelemetryOptions = options?.telemetry
23
+ ? evaluateTelemetryOptions(options.telemetry).enabled
24
+ : {
25
+ logging: false,
26
+ metrics: false,
27
+ tracing: false
28
+ };
29
+ }
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.CreateBillingPortalDtoMapper.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.BillingPortalDtoMapper.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.UpdateBillingPortalDtoMapper.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.BillingPortalDtoMapper.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,54 +116,61 @@ 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
- transformIntoInternalDtoMapper as transformIntoInternalDtoMapper2
122
- } from "@forklaunch/core/mappers";
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;
128
141
  this.schemaValidator = schemaValidator;
129
142
  this.mappers = mappers;
130
143
  this.options = options;
131
- this.#mappers = transformIntoInternalDtoMapper2(mappers, schemaValidator);
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
- };
138
- }
139
- #mappers;
146
+ this.evaluatedTelemetryOptions = options?.telemetry
147
+ ? evaluateTelemetryOptions2(options.telemetry).enabled
148
+ : {
149
+ logging: false,
150
+ metrics: false,
151
+ tracing: false
152
+ };
153
+ }
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.CreateCheckoutSessionDtoMapper.deserializeDtoToEntity(
151
- checkoutSessionDto,
152
- this.em
153
- );
154
- const createdCheckoutSessionDto = await this.#mappers.CheckoutSessionDtoMapper.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,14 +181,14 @@ 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
- return this.#mappers.CheckoutSessionDtoMapper.serializeEntityToDto(
191
+ return this._mappers.CheckoutSessionMapper.serializeEntityToDto(
175
192
  checkoutSessionDetails.value
176
193
  );
177
194
  }
@@ -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,48 +230,53 @@ 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
- transformIntoInternalDtoMapper as transformIntoInternalDtoMapper3
222
- } from "@forklaunch/core/mappers";
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;
228
248
  this.schemaValidator = schemaValidator;
229
249
  this.mappers = mappers;
230
250
  this.options = options;
231
- this.#mappers = transformIntoInternalDtoMapper3(mappers, schemaValidator);
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
- };
238
- }
239
- #mappers;
253
+ this.evaluatedTelemetryOptions = options?.telemetry
254
+ ? evaluateTelemetryOptions3(options.telemetry).enabled
255
+ : {
256
+ logging: false,
257
+ metrics: false,
258
+ tracing: false
259
+ };
260
+ }
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.CreatePaymentLinkDtoMapper.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.PaymentLinkDtoMapper.serializeEntityToDto(
256
- paymentLink
257
- );
278
+ const createdPaymentLinkDto =
279
+ await this._mappers.PaymentLinkMapper.serializeEntityToDto(paymentLink);
258
280
  await this.cache.putRecord({
259
281
  key: this.createCacheKey(createdPaymentLinkDto.id),
260
282
  value: createdPaymentLinkDto,
@@ -264,25 +286,26 @@ var BasePaymentLinkService = class {
264
286
  }
265
287
  async updatePaymentLink(paymentLinkDto) {
266
288
  if (this.evaluatedTelemetryOptions.logging) {
267
- this.openTelemetryCollector.info("Updating payment link", paymentLinkDto);
289
+ this.openTelemetryCollector.info('Updating payment link', paymentLinkDto);
268
290
  }
269
291
  const cacheKey = this.createCacheKey(paymentLinkDto.id);
270
292
  const existingLink = (await this.cache.readRecord(cacheKey))?.value;
271
293
  if (!existingLink) {
272
- throw new Error("Payment link not found");
294
+ throw new Error('Payment link not found');
273
295
  }
274
- const paymentLink = await this.#mappers.UpdatePaymentLinkDtoMapper.deserializeDtoToEntity(
275
- paymentLinkDto,
276
- this.em
277
- );
296
+ const paymentLink =
297
+ await this._mappers.UpdatePaymentLinkMapper.deserializeDtoToEntity(
298
+ paymentLinkDto,
299
+ this.em
300
+ );
278
301
  if (this.enableDatabaseBackup) {
279
302
  await this.em.persistAndFlush(paymentLink);
280
303
  }
281
304
  const updatedLinkDto = {
282
305
  ...existingLink,
283
- ...await this.#mappers.PaymentLinkDtoMapper.serializeEntityToDto(
306
+ ...(await this._mappers.PaymentLinkMapper.serializeEntityToDto(
284
307
  paymentLink
285
- )
308
+ ))
286
309
  };
287
310
  await this.cache.putRecord({
288
311
  key: cacheKey,
@@ -293,58 +316,61 @@ var BasePaymentLinkService = class {
293
316
  }
294
317
  async getPaymentLink({ id }) {
295
318
  if (this.evaluatedTelemetryOptions.logging) {
296
- this.openTelemetryCollector.info("Getting payment link", { id });
319
+ this.openTelemetryCollector.info('Getting payment link', { id });
297
320
  }
298
321
  const cacheKey = this.createCacheKey(id);
299
322
  const paymentLink = await this.cache.readRecord(cacheKey);
300
323
  if (!paymentLink) {
301
- throw new Error("Payment link not found");
324
+ throw new Error('Payment link not found');
302
325
  }
303
- return this.#mappers.PaymentLinkDtoMapper.serializeEntityToDto(
326
+ return this._mappers.PaymentLinkMapper.serializeEntityToDto(
304
327
  paymentLink.value
305
328
  );
306
329
  }
307
330
  async expirePaymentLink({ id }) {
308
- this.openTelemetryCollector.info("Payment link expired", { id });
331
+ this.openTelemetryCollector.info('Payment link expired', { id });
309
332
  if (this.enableDatabaseBackup) {
310
- const paymentLink = await this.em.upsert("PaymentLink", {
333
+ const paymentLink = await this.em.upsert('PaymentLink', {
311
334
  id,
312
- status: "EXPIRED"
335
+ status: 'EXPIRED'
313
336
  });
314
337
  await this.em.removeAndFlush(paymentLink);
315
338
  }
316
339
  await this.cache.deleteRecord(this.createCacheKey(id));
317
340
  }
318
341
  async handlePaymentSuccess({ id }) {
319
- this.openTelemetryCollector.info("Payment link success", { id });
342
+ this.openTelemetryCollector.info('Payment link success', { id });
320
343
  if (this.enableDatabaseBackup) {
321
- const paymentLink = await this.em.upsert("PaymentLink", {
344
+ const paymentLink = await this.em.upsert('PaymentLink', {
322
345
  id,
323
- status: "COMPLETED"
346
+ status: 'COMPLETED'
324
347
  });
325
348
  await this.em.removeAndFlush(paymentLink);
326
349
  }
327
350
  await this.cache.deleteRecord(this.createCacheKey(id));
328
351
  }
329
352
  async handlePaymentFailure({ id }) {
330
- this.openTelemetryCollector.info("Payment link failure", { id });
353
+ this.openTelemetryCollector.info('Payment link failure', { id });
331
354
  if (this.enableDatabaseBackup) {
332
- const paymentLink = await this.em.upsert("PaymentLink", {
355
+ const paymentLink = await this.em.upsert('PaymentLink', {
333
356
  id,
334
- status: "FAILED"
357
+ status: 'FAILED'
335
358
  });
336
359
  await this.em.removeAndFlush(paymentLink);
337
360
  }
338
361
  await this.cache.deleteRecord(this.createCacheKey(id));
339
362
  }
340
363
  async listPaymentLinks(idsDto) {
341
- 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));
342
367
  return Promise.all(
343
368
  keys.map(async (key) => {
344
369
  const paymentLink = await this.cache.readRecord(key);
345
- const paymentLinkDto = this.#mappers.PaymentLinkDtoMapper.serializeEntityToDto(
346
- paymentLink.value
347
- );
370
+ const paymentLinkDto =
371
+ this._mappers.PaymentLinkMapper.serializeEntityToDto(
372
+ paymentLink.value
373
+ );
348
374
  return paymentLinkDto;
349
375
  })
350
376
  );
@@ -352,12 +378,8 @@ var BasePaymentLinkService = class {
352
378
  };
353
379
 
354
380
  // services/plan.service.ts
355
- import {
356
- evaluateTelemetryOptions as evaluateTelemetryOptions4
357
- } from "@forklaunch/core/http";
358
- import {
359
- transformIntoInternalDtoMapper as transformIntoInternalDtoMapper4
360
- } from "@forklaunch/core/mappers";
381
+ import { evaluateTelemetryOptions as evaluateTelemetryOptions4 } from '@forklaunch/core/http';
382
+ import { transformIntoInternalMapper as transformIntoInternalMapper4 } from '@forklaunch/internal';
361
383
  var BasePlanService = class {
362
384
  constructor(em, openTelemetryCollector, schemaValidator, mappers, options) {
363
385
  this.em = em;
@@ -365,56 +387,54 @@ var BasePlanService = class {
365
387
  this.schemaValidator = schemaValidator;
366
388
  this.mappers = mappers;
367
389
  this.options = options;
368
- this.#mappers = transformIntoInternalDtoMapper4(mappers, schemaValidator);
369
- this.evaluatedTelemetryOptions = options?.telemetry ? evaluateTelemetryOptions4(options.telemetry).enabled : {
370
- logging: false,
371
- metrics: false,
372
- tracing: false
373
- };
374
- }
375
- #mappers;
390
+ this._mappers = transformIntoInternalMapper4(mappers, schemaValidator);
391
+ this.evaluatedTelemetryOptions = options?.telemetry
392
+ ? evaluateTelemetryOptions4(options.telemetry).enabled
393
+ : {
394
+ logging: false,
395
+ metrics: false,
396
+ tracing: false
397
+ };
398
+ }
399
+ _mappers;
376
400
  evaluatedTelemetryOptions;
377
401
  async listPlans(idsDto, em) {
378
402
  if (this.evaluatedTelemetryOptions.logging) {
379
- this.openTelemetryCollector.info("Listing plans", idsDto);
403
+ this.openTelemetryCollector.info('Listing plans', idsDto);
380
404
  }
381
405
  return Promise.all(
382
- (await (em ?? this.em).findAll("Plan", {
383
- filters: idsDto?.ids ? { id: { $in: idsDto.ids } } : void 0
384
- })).map(
385
- (plan) => this.#mappers.PlanDtoMapper.serializeEntityToDto(
386
- plan
387
- )
388
- )
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))
389
411
  );
390
412
  }
391
413
  async createPlan(planDto, em) {
392
414
  if (this.evaluatedTelemetryOptions.logging) {
393
- this.openTelemetryCollector.info("Creating plan", planDto);
415
+ this.openTelemetryCollector.info('Creating plan', planDto);
394
416
  }
395
- const plan = await this.#mappers.CreatePlanDtoMapper.deserializeDtoToEntity(
417
+ const plan = await this._mappers.CreatePlanMapper.deserializeDtoToEntity(
396
418
  planDto,
397
419
  em ?? this.em
398
420
  );
399
421
  await (em ?? this.em).transactional(async (innerEm) => {
400
422
  await innerEm.persist(plan);
401
423
  });
402
- return this.#mappers.PlanDtoMapper.serializeEntityToDto(plan);
424
+ return this._mappers.PlanMapper.serializeEntityToDto(plan);
403
425
  }
404
426
  async getPlan(idDto, em) {
405
427
  if (this.evaluatedTelemetryOptions.logging) {
406
- this.openTelemetryCollector.info("Getting plan", idDto);
428
+ this.openTelemetryCollector.info('Getting plan', idDto);
407
429
  }
408
- const plan = await (em ?? this.em).findOneOrFail("Plan", idDto);
409
- return this.#mappers.PlanDtoMapper.serializeEntityToDto(
410
- plan
411
- );
430
+ const plan = await (em ?? this.em).findOneOrFail('Plan', idDto);
431
+ return this._mappers.PlanMapper.serializeEntityToDto(plan);
412
432
  }
413
433
  async updatePlan(planDto, em) {
414
434
  if (this.evaluatedTelemetryOptions.logging) {
415
- this.openTelemetryCollector.info("Updating plan", planDto);
435
+ this.openTelemetryCollector.info('Updating plan', planDto);
416
436
  }
417
- const plan = await this.#mappers.UpdatePlanDtoMapper.deserializeDtoToEntity(
437
+ const plan = await this._mappers.UpdatePlanMapper.deserializeDtoToEntity(
418
438
  planDto,
419
439
  em ?? this.em
420
440
  );
@@ -422,24 +442,21 @@ var BasePlanService = class {
422
442
  await (em ?? this.em).transactional(async (innerEm) => {
423
443
  await innerEm.persist(plan);
424
444
  });
425
- const updatedPlanDto = await this.#mappers.PlanDtoMapper.serializeEntityToDto(updatedPlan);
445
+ const updatedPlanDto =
446
+ await this._mappers.PlanMapper.serializeEntityToDto(updatedPlan);
426
447
  return updatedPlanDto;
427
448
  }
428
449
  async deletePlan(idDto, em) {
429
450
  if (this.evaluatedTelemetryOptions.logging) {
430
- this.openTelemetryCollector.info("Deleting plan", idDto);
451
+ this.openTelemetryCollector.info('Deleting plan', idDto);
431
452
  }
432
- await (em ?? this.em).nativeDelete("Plan", idDto);
453
+ await (em ?? this.em).nativeDelete('Plan', idDto);
433
454
  }
434
455
  };
435
456
 
436
457
  // services/subscription.service.ts
437
- import {
438
- evaluateTelemetryOptions as evaluateTelemetryOptions5
439
- } from "@forklaunch/core/http";
440
- import {
441
- transformIntoInternalDtoMapper as transformIntoInternalDtoMapper5
442
- } from "@forklaunch/core/mappers";
458
+ import { evaluateTelemetryOptions as evaluateTelemetryOptions5 } from '@forklaunch/core/http';
459
+ import { transformIntoInternalMapper as transformIntoInternalMapper5 } from '@forklaunch/internal';
443
460
  var BaseSubscriptionService = class {
444
461
  constructor(em, openTelemetryCollector, schemaValidator, mappers, options) {
445
462
  this.em = em;
@@ -447,129 +464,128 @@ var BaseSubscriptionService = class {
447
464
  this.schemaValidator = schemaValidator;
448
465
  this.mappers = mappers;
449
466
  this.options = options;
450
- this.#mappers = transformIntoInternalDtoMapper5(mappers, this.schemaValidator);
451
- this.evaluatedTelemetryOptions = options?.telemetry ? evaluateTelemetryOptions5(options.telemetry).enabled : {
452
- logging: false,
453
- metrics: false,
454
- tracing: false
455
- };
456
- }
457
- #mappers;
467
+ this._mappers = transformIntoInternalMapper5(mappers, this.schemaValidator);
468
+ this.evaluatedTelemetryOptions = options?.telemetry
469
+ ? evaluateTelemetryOptions5(options.telemetry).enabled
470
+ : {
471
+ logging: false,
472
+ metrics: false,
473
+ tracing: false
474
+ };
475
+ }
476
+ _mappers;
458
477
  evaluatedTelemetryOptions;
459
478
  async createSubscription(subscriptionDto, em) {
460
479
  if (this.evaluatedTelemetryOptions.logging) {
461
480
  this.openTelemetryCollector.info(
462
- "Creating subscription",
481
+ 'Creating subscription',
463
482
  subscriptionDto
464
483
  );
465
484
  }
466
- const subscription = await this.#mappers.CreateSubscriptionDtoMapper.deserializeDtoToEntity(
467
- subscriptionDto,
468
- em ?? this.em
469
- );
485
+ const subscription =
486
+ await this._mappers.CreateSubscriptionMapper.deserializeDtoToEntity(
487
+ subscriptionDto,
488
+ em ?? this.em
489
+ );
470
490
  await (em ?? this.em).transactional(async (innerEm) => {
471
491
  await innerEm.persist(subscription);
472
492
  });
473
- const createdSubscriptionDto = await this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
474
- subscription
475
- );
493
+ const createdSubscriptionDto =
494
+ await this._mappers.SubscriptionMapper.serializeEntityToDto(subscription);
476
495
  return createdSubscriptionDto;
477
496
  }
478
497
  async getSubscription(idDto, em) {
479
498
  if (this.evaluatedTelemetryOptions.logging) {
480
- this.openTelemetryCollector.info("Getting subscription", idDto);
499
+ this.openTelemetryCollector.info('Getting subscription', idDto);
481
500
  }
482
501
  const subscription = await (em ?? this.em).findOneOrFail(
483
- "Subscription",
502
+ 'Subscription',
484
503
  idDto
485
504
  );
486
- return this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
487
- subscription
488
- );
505
+ return this._mappers.SubscriptionMapper.serializeEntityToDto(subscription);
489
506
  }
490
507
  async getUserSubscription({ id }, em) {
491
508
  if (this.evaluatedTelemetryOptions.logging) {
492
- this.openTelemetryCollector.info("Getting user subscription", id);
509
+ this.openTelemetryCollector.info('Getting user subscription', id);
493
510
  }
494
- const subscription = await (em ?? this.em).findOneOrFail("Subscription", {
511
+ const subscription = await (em ?? this.em).findOneOrFail('Subscription', {
495
512
  partyId: id,
496
- partyType: "USER",
513
+ partyType: 'USER',
497
514
  active: true
498
515
  });
499
- return this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
500
- subscription
501
- );
516
+ return this._mappers.SubscriptionMapper.serializeEntityToDto(subscription);
502
517
  }
503
518
  async getOrganizationSubscription({ id }, em) {
504
519
  if (this.evaluatedTelemetryOptions.logging) {
505
- this.openTelemetryCollector.info("Getting organization subscription", id);
520
+ this.openTelemetryCollector.info('Getting organization subscription', id);
506
521
  }
507
- const subscription = await (em ?? this.em).findOneOrFail("Subscription", {
522
+ const subscription = await (em ?? this.em).findOneOrFail('Subscription', {
508
523
  partyId: id,
509
- partyType: "ORGANIZATION",
524
+ partyType: 'ORGANIZATION',
510
525
  active: true
511
526
  });
512
- return this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
513
- subscription
514
- );
527
+ return this._mappers.SubscriptionMapper.serializeEntityToDto(subscription);
515
528
  }
516
529
  async updateSubscription(subscriptionDto, em) {
517
530
  if (this.evaluatedTelemetryOptions.logging) {
518
531
  this.openTelemetryCollector.info(
519
- "Updating subscription",
532
+ 'Updating subscription',
520
533
  subscriptionDto
521
534
  );
522
535
  }
523
- const subscription = this.#mappers.UpdateSubscriptionDtoMapper.deserializeDtoToEntity(
524
- subscriptionDto,
525
- em ?? this.em
526
- );
536
+ const subscription =
537
+ this._mappers.UpdateSubscriptionMapper.deserializeDtoToEntity(
538
+ subscriptionDto,
539
+ em ?? this.em
540
+ );
527
541
  const updatedSubscription = await (em ?? this.em).upsert(subscription);
528
542
  await (em ?? this.em).transactional(async (innerEm) => {
529
543
  await innerEm.persist(updatedSubscription);
530
544
  });
531
- const updatedSubscriptionDto = await this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
532
- updatedSubscription
533
- );
545
+ const updatedSubscriptionDto =
546
+ await this._mappers.SubscriptionMapper.serializeEntityToDto(
547
+ updatedSubscription
548
+ );
534
549
  return updatedSubscriptionDto;
535
550
  }
536
551
  async deleteSubscription(idDto, em) {
537
552
  if (this.evaluatedTelemetryOptions.logging) {
538
- this.openTelemetryCollector.info("Deleting subscription", idDto);
553
+ this.openTelemetryCollector.info('Deleting subscription', idDto);
539
554
  }
540
- const subscription = await (em ?? this.em).findOne("Subscription", idDto);
555
+ const subscription = await (em ?? this.em).findOne('Subscription', idDto);
541
556
  if (!subscription) {
542
- throw new Error("Subscription not found");
557
+ throw new Error('Subscription not found');
543
558
  }
544
559
  await (em ?? this.em).removeAndFlush(subscription);
545
560
  }
546
561
  async listSubscriptions(idsDto, em) {
547
562
  if (this.evaluatedTelemetryOptions.logging) {
548
- this.openTelemetryCollector.info("Listing subscriptions", idsDto);
549
- }
550
- const subscriptions = await (em ?? this.em).findAll("Subscription", {
551
- where: idsDto.ids ? {
552
- id: {
553
- $in: idsDto.ids
554
- }
555
- } : 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
556
573
  });
557
574
  return Promise.all(
558
575
  subscriptions.map((subscription) => {
559
- const subscriptionDto = this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
560
- subscription
561
- );
576
+ const subscriptionDto =
577
+ this._mappers.SubscriptionMapper.serializeEntityToDto(subscription);
562
578
  return subscriptionDto;
563
579
  })
564
580
  );
565
581
  }
566
582
  async cancelSubscription(idDto, em) {
567
583
  if (this.evaluatedTelemetryOptions.logging) {
568
- this.openTelemetryCollector.info("Canceling subscription", idDto);
584
+ this.openTelemetryCollector.info('Canceling subscription', idDto);
569
585
  }
570
- const subscription = await (em ?? this.em).findOne("Subscription", idDto);
586
+ const subscription = await (em ?? this.em).findOne('Subscription', idDto);
571
587
  if (!subscription) {
572
- throw new Error("Subscription not found");
588
+ throw new Error('Subscription not found');
573
589
  }
574
590
  subscription.active = false;
575
591
  await (em ?? this.em).transactional(async (innerEm) => {
@@ -578,11 +594,11 @@ var BaseSubscriptionService = class {
578
594
  }
579
595
  async resumeSubscription(idDto, em) {
580
596
  if (this.evaluatedTelemetryOptions.logging) {
581
- this.openTelemetryCollector.info("Resuming subscription", idDto);
597
+ this.openTelemetryCollector.info('Resuming subscription', idDto);
582
598
  }
583
- const subscription = await (em ?? this.em).findOne("Subscription", idDto);
599
+ const subscription = await (em ?? this.em).findOne('Subscription', idDto);
584
600
  if (!subscription) {
585
- throw new Error("Subscription not found");
601
+ throw new Error('Subscription not found');
586
602
  }
587
603
  subscription.active = true;
588
604
  await (em ?? this.em).transactional(async (innerEm) => {