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