@forklaunch/implementation-billing-base 0.6.4 → 0.6.5

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