@forklaunch/implementation-billing-base 0.6.5 → 0.7.0

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