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