@forklaunch/implementation-billing-base 0.5.8 → 0.6.1

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