@forklaunch/implementation-billing-base 0.7.4 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -76,8 +76,8 @@ export class BaseBillingPortalService<
76
76
 
77
77
  const billingPortal = await this.mappers.CreateBillingPortalMapper.toEntity(
78
78
  billingPortalDto,
79
- this.em,
80
- ...args
79
+ args[0] instanceof EntityManager ? args[0] : this.em,
80
+ ...(args[0] instanceof EntityManager ? args.slice(1) : args)
81
81
  );
82
82
 
83
83
  if (this.enableDatabaseBackup) {
@@ -111,7 +111,12 @@ export class BaseBillingPortalService<
111
111
  throw new Error('Session not found');
112
112
  }
113
113
 
114
- return billingPortalDetails.value;
114
+ return this.mappers.BillingPortalMapper.toDto(
115
+ await this.mappers.UpdateBillingPortalMapper.toEntity(
116
+ billingPortalDetails.value,
117
+ this.em
118
+ )
119
+ );
115
120
  }
116
121
 
117
122
  async updateBillingPortalSession(
@@ -137,8 +142,8 @@ export class BaseBillingPortalService<
137
142
 
138
143
  const billingPortal = await this.mappers.UpdateBillingPortalMapper.toEntity(
139
144
  billingPortalDto,
140
- this.em,
141
- ...args
145
+ args[0] instanceof EntityManager ? args[0] : this.em,
146
+ ...(args[0] instanceof EntityManager ? args.slice(1) : args)
142
147
  );
143
148
 
144
149
  if (this.enableDatabaseBackup) {
@@ -158,7 +163,12 @@ export class BaseBillingPortalService<
158
163
  ttlMilliseconds: this.cache.getTtlMilliseconds()
159
164
  });
160
165
 
161
- return updatedBillingPortalDto;
166
+ return this.mappers.BillingPortalMapper.toDto(
167
+ await this.mappers.UpdateBillingPortalMapper.toEntity(
168
+ billingPortal,
169
+ this.em
170
+ )
171
+ );
162
172
  }
163
173
 
164
174
  async expireBillingPortalSession(idDto: IdDto): Promise<void> {
@@ -101,8 +101,8 @@ export class BaseCheckoutSessionService<
101
101
  const checkoutSession =
102
102
  await this.mappers.CreateCheckoutSessionMapper.toEntity(
103
103
  checkoutSessionDto,
104
- this.em,
105
- ...args
104
+ args[0] instanceof EntityManager ? args[0] : this.em,
105
+ ...(args[0] instanceof EntityManager ? args.slice(1) : args)
106
106
  );
107
107
 
108
108
  const createdCheckoutSessionDto =
@@ -132,7 +132,10 @@ export class BaseCheckoutSessionService<
132
132
  }
133
133
 
134
134
  return this.mappers.CheckoutSessionMapper.toDto(
135
- checkoutSessionDetails.value
135
+ await this.mappers.UpdateCheckoutSessionMapper.toEntity(
136
+ checkoutSessionDetails.value,
137
+ this.em
138
+ )
136
139
  );
137
140
  }
138
141
 
@@ -101,8 +101,8 @@ export class BasePaymentLinkService<
101
101
 
102
102
  const paymentLink = await this.mappers.CreatePaymentLinkMapper.toEntity(
103
103
  paymentLinkDto,
104
- this.em,
105
- ...args
104
+ args[0] instanceof EntityManager ? args[0] : this.em,
105
+ ...(args[0] instanceof EntityManager ? args.slice(1) : args)
106
106
  );
107
107
 
108
108
  if (this.enableDatabaseBackup) {
@@ -142,8 +142,8 @@ export class BasePaymentLinkService<
142
142
  }
143
143
  const paymentLink = await this.mappers.UpdatePaymentLinkMapper.toEntity(
144
144
  paymentLinkDto,
145
- this.em,
146
- ...args
145
+ args[0] instanceof EntityManager ? args[0] : this.em,
146
+ ...(args[0] instanceof EntityManager ? args.slice(1) : args)
147
147
  );
148
148
 
149
149
  if (this.enableDatabaseBackup) {
@@ -179,7 +179,12 @@ export class BasePaymentLinkService<
179
179
  throw new Error('Payment link not found');
180
180
  }
181
181
 
182
- return this.mappers.PaymentLinkMapper.toDto(paymentLink.value);
182
+ return this.mappers.PaymentLinkMapper.toDto(
183
+ await this.mappers.UpdatePaymentLinkMapper.toEntity(
184
+ paymentLink.value,
185
+ this.em
186
+ )
187
+ );
183
188
  }
184
189
 
185
190
  async expirePaymentLink({ id }: IdDto): Promise<void> {
@@ -223,15 +228,20 @@ export class BasePaymentLinkService<
223
228
  idsDto?: IdsDto
224
229
  ): Promise<MapperDomains['PaymentLinkMapper'][]> {
225
230
  const keys =
226
- idsDto?.ids.map((id) => this.createCacheKey(id)) ??
227
- (await this.cache.listKeys(this.cacheKeyPrefix));
231
+ idsDto?.ids && idsDto.ids.length > 0
232
+ ? idsDto?.ids.map((id) => this.createCacheKey(id))
233
+ : await this.cache.listKeys(this.cacheKeyPrefix);
228
234
 
235
+ console.log('keys', keys);
229
236
  return Promise.all(
230
237
  keys.map(async (key) => {
231
238
  const paymentLink =
232
239
  await this.cache.readRecord<MapperEntities['PaymentLinkMapper']>(key);
233
240
  const paymentLinkDto = this.mappers.PaymentLinkMapper.toDto(
234
- paymentLink.value
241
+ await this.mappers.UpdatePaymentLinkMapper.toEntity(
242
+ paymentLink.value,
243
+ this.em
244
+ )
235
245
  );
236
246
  return paymentLinkDto;
237
247
  })
@@ -84,10 +84,11 @@ export class BasePlanService<
84
84
  if (this.evaluatedTelemetryOptions.logging) {
85
85
  this.openTelemetryCollector.info('Listing plans', idsDto);
86
86
  }
87
+
87
88
  return Promise.all(
88
89
  (
89
90
  await (em ?? this.em).findAll('Plan', {
90
- filters: idsDto?.ids ? { id: { $in: idsDto.ids } } : undefined
91
+ where: idsDto?.ids?.length ? { id: { $in: idsDto.ids } } : undefined
91
92
  })
92
93
  ).map((plan) =>
93
94
  this.mappers.PlanMapper.toDto(plan as MapperEntities['PlanMapper'])
@@ -106,7 +107,7 @@ export class BasePlanService<
106
107
  const plan = await this.mappers.CreatePlanMapper.toEntity(
107
108
  planDto,
108
109
  em ?? this.em,
109
- ...args
110
+ ...(args[0] instanceof EntityManager ? args.slice(1) : args)
110
111
  );
111
112
  await (em ?? this.em).transactional(async (innerEm) => {
112
113
  await innerEm.persist(plan);
@@ -1,4 +1,4 @@
1
- import { IdDto } from '@forklaunch/common';
1
+ import { IdDto, IdsDto } from '@forklaunch/common';
2
2
  import {
3
3
  evaluateTelemetryOptions,
4
4
  MetricsDefinition,
@@ -78,7 +78,7 @@ export class BaseSubscriptionService<
78
78
  const subscription = await this.mappers.CreateSubscriptionMapper.toEntity(
79
79
  subscriptionDto,
80
80
  em ?? this.em,
81
- ...args
81
+ ...(args[0] instanceof EntityManager ? args.slice(1) : args)
82
82
  );
83
83
  await (em ?? this.em).transactional(async (innerEm) => {
84
84
  await innerEm.persist(subscription);
@@ -180,29 +180,22 @@ export class BaseSubscriptionService<
180
180
  }
181
181
 
182
182
  async listSubscriptions(
183
- idsDto: { ids?: string[] },
183
+ idsDto?: IdsDto,
184
184
  em?: EntityManager
185
185
  ): Promise<Dto['SubscriptionMapper'][]> {
186
186
  if (this.evaluatedTelemetryOptions.logging) {
187
187
  this.openTelemetryCollector.info('Listing subscriptions', idsDto);
188
188
  }
189
- const subscriptions = await (em ?? this.em).findAll('Subscription', {
190
- where: idsDto.ids
191
- ? {
192
- id: {
193
- $in: idsDto.ids
194
- }
195
- }
196
- : undefined
197
- });
198
-
199
189
  return Promise.all(
200
- subscriptions.map((subscription) => {
201
- const subscriptionDto = this.mappers.SubscriptionMapper.toDto(
190
+ (
191
+ await (em ?? this.em).findAll('Subscription', {
192
+ where: idsDto?.ids?.length ? { id: { $in: idsDto.ids } } : undefined
193
+ })
194
+ ).map((subscription) =>
195
+ this.mappers.SubscriptionMapper.toDto(
202
196
  subscription as Entities['SubscriptionMapper']
203
- );
204
- return subscriptionDto;
205
- })
197
+ )
198
+ )
206
199
  );
207
200
  }
208
201
 
@@ -113,9 +113,7 @@ declare class BaseSubscriptionService<SchemaValidator extends AnySchemaValidator
113
113
  deleteSubscription(idDto: {
114
114
  id: string;
115
115
  }, em?: EntityManager): Promise<void>;
116
- listSubscriptions(idsDto: {
117
- ids?: string[];
118
- }, em?: EntityManager): Promise<Dto['SubscriptionMapper'][]>;
116
+ listSubscriptions(idsDto?: IdsDto, em?: EntityManager): Promise<Dto['SubscriptionMapper'][]>;
119
117
  cancelSubscription(idDto: IdDto, em?: EntityManager): Promise<void>;
120
118
  resumeSubscription(idDto: IdDto, em?: EntityManager): Promise<void>;
121
119
  }
@@ -113,9 +113,7 @@ declare class BaseSubscriptionService<SchemaValidator extends AnySchemaValidator
113
113
  deleteSubscription(idDto: {
114
114
  id: string;
115
115
  }, em?: EntityManager): Promise<void>;
116
- listSubscriptions(idsDto: {
117
- ids?: string[];
118
- }, em?: EntityManager): Promise<Dto['SubscriptionMapper'][]>;
116
+ listSubscriptions(idsDto?: IdsDto, em?: EntityManager): Promise<Dto['SubscriptionMapper'][]>;
119
117
  cancelSubscription(idDto: IdDto, em?: EntityManager): Promise<void>;
120
118
  resumeSubscription(idDto: IdDto, em?: EntityManager): Promise<void>;
121
119
  }
@@ -32,6 +32,7 @@ module.exports = __toCommonJS(services_exports);
32
32
  // services/billingPortal.service.ts
33
33
  var import_cache = require("@forklaunch/core/cache");
34
34
  var import_http = require("@forklaunch/core/http");
35
+ var import_core = require("@mikro-orm/core");
35
36
  var BaseBillingPortalService = class {
36
37
  evaluatedTelemetryOptions;
37
38
  enableDatabaseBackup;
@@ -63,8 +64,8 @@ var BaseBillingPortalService = class {
63
64
  }
64
65
  const billingPortal = await this.mappers.CreateBillingPortalMapper.toEntity(
65
66
  billingPortalDto,
66
- this.em,
67
- ...args
67
+ args[0] instanceof import_core.EntityManager ? args[0] : this.em,
68
+ ...args[0] instanceof import_core.EntityManager ? args.slice(1) : args
68
69
  );
69
70
  if (this.enableDatabaseBackup) {
70
71
  await this.em.persistAndFlush(billingPortal);
@@ -85,7 +86,12 @@ var BaseBillingPortalService = class {
85
86
  if (!billingPortalDetails) {
86
87
  throw new Error("Session not found");
87
88
  }
88
- return billingPortalDetails.value;
89
+ return this.mappers.BillingPortalMapper.toDto(
90
+ await this.mappers.UpdateBillingPortalMapper.toEntity(
91
+ billingPortalDetails.value,
92
+ this.em
93
+ )
94
+ );
89
95
  }
90
96
  async updateBillingPortalSession(billingPortalDto, ...args) {
91
97
  if (this.evaluatedTelemetryOptions.logging) {
@@ -102,8 +108,8 @@ var BaseBillingPortalService = class {
102
108
  }
103
109
  const billingPortal = await this.mappers.UpdateBillingPortalMapper.toEntity(
104
110
  billingPortalDto,
105
- this.em,
106
- ...args
111
+ args[0] instanceof import_core.EntityManager ? args[0] : this.em,
112
+ ...args[0] instanceof import_core.EntityManager ? args.slice(1) : args
107
113
  );
108
114
  if (this.enableDatabaseBackup) {
109
115
  await this.em.persistAndFlush({
@@ -119,7 +125,12 @@ var BaseBillingPortalService = class {
119
125
  value: updatedBillingPortalDto,
120
126
  ttlMilliseconds: this.cache.getTtlMilliseconds()
121
127
  });
122
- return updatedBillingPortalDto;
128
+ return this.mappers.BillingPortalMapper.toDto(
129
+ await this.mappers.UpdateBillingPortalMapper.toEntity(
130
+ billingPortal,
131
+ this.em
132
+ )
133
+ );
123
134
  }
124
135
  async expireBillingPortalSession(idDto) {
125
136
  if (this.evaluatedTelemetryOptions.logging) {
@@ -141,6 +152,7 @@ var BaseBillingPortalService = class {
141
152
  // services/checkoutSession.service.ts
142
153
  var import_cache2 = require("@forklaunch/core/cache");
143
154
  var import_http2 = require("@forklaunch/core/http");
155
+ var import_core2 = require("@mikro-orm/core");
144
156
  var BaseCheckoutSessionService = class {
145
157
  evaluatedTelemetryOptions;
146
158
  enableDatabaseBackup;
@@ -172,8 +184,8 @@ var BaseCheckoutSessionService = class {
172
184
  }
173
185
  const checkoutSession = await this.mappers.CreateCheckoutSessionMapper.toEntity(
174
186
  checkoutSessionDto,
175
- this.em,
176
- ...args
187
+ args[0] instanceof import_core2.EntityManager ? args[0] : this.em,
188
+ ...args[0] instanceof import_core2.EntityManager ? args.slice(1) : args
177
189
  );
178
190
  const createdCheckoutSessionDto = await this.mappers.CheckoutSessionMapper.toDto(checkoutSession);
179
191
  if (this.enableDatabaseBackup) {
@@ -194,7 +206,10 @@ var BaseCheckoutSessionService = class {
194
206
  throw new Error("Session not found");
195
207
  }
196
208
  return this.mappers.CheckoutSessionMapper.toDto(
197
- checkoutSessionDetails.value
209
+ await this.mappers.UpdateCheckoutSessionMapper.toEntity(
210
+ checkoutSessionDetails.value,
211
+ this.em
212
+ )
198
213
  );
199
214
  }
200
215
  async expireCheckoutSession({ id }) {
@@ -237,6 +252,7 @@ var BaseCheckoutSessionService = class {
237
252
  // services/paymentLink.service.ts
238
253
  var import_cache3 = require("@forklaunch/core/cache");
239
254
  var import_http3 = require("@forklaunch/core/http");
255
+ var import_core3 = require("@mikro-orm/core");
240
256
  var BasePaymentLinkService = class {
241
257
  evaluatedTelemetryOptions;
242
258
  enableDatabaseBackup;
@@ -266,8 +282,8 @@ var BasePaymentLinkService = class {
266
282
  }
267
283
  const paymentLink = await this.mappers.CreatePaymentLinkMapper.toEntity(
268
284
  paymentLinkDto,
269
- this.em,
270
- ...args
285
+ args[0] instanceof import_core3.EntityManager ? args[0] : this.em,
286
+ ...args[0] instanceof import_core3.EntityManager ? args.slice(1) : args
271
287
  );
272
288
  if (this.enableDatabaseBackup) {
273
289
  await this.em.persistAndFlush(paymentLink);
@@ -291,8 +307,8 @@ var BasePaymentLinkService = class {
291
307
  }
292
308
  const paymentLink = await this.mappers.UpdatePaymentLinkMapper.toEntity(
293
309
  paymentLinkDto,
294
- this.em,
295
- ...args
310
+ args[0] instanceof import_core3.EntityManager ? args[0] : this.em,
311
+ ...args[0] instanceof import_core3.EntityManager ? args.slice(1) : args
296
312
  );
297
313
  if (this.enableDatabaseBackup) {
298
314
  await this.em.persistAndFlush(paymentLink);
@@ -321,7 +337,12 @@ var BasePaymentLinkService = class {
321
337
  if (!paymentLink) {
322
338
  throw new Error("Payment link not found");
323
339
  }
324
- return this.mappers.PaymentLinkMapper.toDto(paymentLink.value);
340
+ return this.mappers.PaymentLinkMapper.toDto(
341
+ await this.mappers.UpdatePaymentLinkMapper.toEntity(
342
+ paymentLink.value,
343
+ this.em
344
+ )
345
+ );
325
346
  }
326
347
  async expirePaymentLink({ id }) {
327
348
  this.openTelemetryCollector.info("Payment link expired", { id });
@@ -357,12 +378,16 @@ var BasePaymentLinkService = class {
357
378
  await this.cache.deleteRecord(this.createCacheKey(id));
358
379
  }
359
380
  async listPaymentLinks(idsDto) {
360
- const keys = idsDto?.ids.map((id) => this.createCacheKey(id)) ?? await this.cache.listKeys(this.cacheKeyPrefix);
381
+ const keys = idsDto?.ids && idsDto.ids.length > 0 ? idsDto?.ids.map((id) => this.createCacheKey(id)) : await this.cache.listKeys(this.cacheKeyPrefix);
382
+ console.log("keys", keys);
361
383
  return Promise.all(
362
384
  keys.map(async (key) => {
363
385
  const paymentLink = await this.cache.readRecord(key);
364
386
  const paymentLinkDto = this.mappers.PaymentLinkMapper.toDto(
365
- paymentLink.value
387
+ await this.mappers.UpdatePaymentLinkMapper.toEntity(
388
+ paymentLink.value,
389
+ this.em
390
+ )
366
391
  );
367
392
  return paymentLinkDto;
368
393
  })
@@ -372,6 +397,7 @@ var BasePaymentLinkService = class {
372
397
 
373
398
  // services/plan.service.ts
374
399
  var import_http4 = require("@forklaunch/core/http");
400
+ var import_core4 = require("@mikro-orm/core");
375
401
  var BasePlanService = class {
376
402
  evaluatedTelemetryOptions;
377
403
  em;
@@ -395,7 +421,7 @@ var BasePlanService = class {
395
421
  }
396
422
  return Promise.all(
397
423
  (await (em ?? this.em).findAll("Plan", {
398
- filters: idsDto?.ids ? { id: { $in: idsDto.ids } } : void 0
424
+ where: idsDto?.ids?.length ? { id: { $in: idsDto.ids } } : void 0
399
425
  })).map(
400
426
  (plan) => this.mappers.PlanMapper.toDto(plan)
401
427
  )
@@ -408,7 +434,7 @@ var BasePlanService = class {
408
434
  const plan = await this.mappers.CreatePlanMapper.toEntity(
409
435
  planDto,
410
436
  em ?? this.em,
411
- ...args
437
+ ...args[0] instanceof import_core4.EntityManager ? args.slice(1) : args
412
438
  );
413
439
  await (em ?? this.em).transactional(async (innerEm) => {
414
440
  await innerEm.persist(plan);
@@ -448,6 +474,7 @@ var BasePlanService = class {
448
474
 
449
475
  // services/subscription.service.ts
450
476
  var import_http5 = require("@forklaunch/core/http");
477
+ var import_core5 = require("@mikro-orm/core");
451
478
  var BaseSubscriptionService = class {
452
479
  constructor(em, openTelemetryCollector, schemaValidator, mappers, options) {
453
480
  this.options = options;
@@ -476,7 +503,7 @@ var BaseSubscriptionService = class {
476
503
  const subscription = await this.mappers.CreateSubscriptionMapper.toEntity(
477
504
  subscriptionDto,
478
505
  em ?? this.em,
479
- ...args
506
+ ...args[0] instanceof import_core5.EntityManager ? args.slice(1) : args
480
507
  );
481
508
  await (em ?? this.em).transactional(async (innerEm) => {
482
509
  await innerEm.persist(subscription);
@@ -555,20 +582,14 @@ var BaseSubscriptionService = class {
555
582
  if (this.evaluatedTelemetryOptions.logging) {
556
583
  this.openTelemetryCollector.info("Listing subscriptions", idsDto);
557
584
  }
558
- const subscriptions = await (em ?? this.em).findAll("Subscription", {
559
- where: idsDto.ids ? {
560
- id: {
561
- $in: idsDto.ids
562
- }
563
- } : void 0
564
- });
565
585
  return Promise.all(
566
- subscriptions.map((subscription) => {
567
- const subscriptionDto = this.mappers.SubscriptionMapper.toDto(
586
+ (await (em ?? this.em).findAll("Subscription", {
587
+ where: idsDto?.ids?.length ? { id: { $in: idsDto.ids } } : void 0
588
+ })).map(
589
+ (subscription) => this.mappers.SubscriptionMapper.toDto(
568
590
  subscription
569
- );
570
- return subscriptionDto;
571
- })
591
+ )
592
+ )
572
593
  );
573
594
  }
574
595
  async cancelSubscription(idDto, em) {
@@ -3,6 +3,7 @@ import { createCacheKey } from "@forklaunch/core/cache";
3
3
  import {
4
4
  evaluateTelemetryOptions
5
5
  } from "@forklaunch/core/http";
6
+ import { EntityManager } from "@mikro-orm/core";
6
7
  var BaseBillingPortalService = class {
7
8
  evaluatedTelemetryOptions;
8
9
  enableDatabaseBackup;
@@ -34,8 +35,8 @@ var BaseBillingPortalService = class {
34
35
  }
35
36
  const billingPortal = await this.mappers.CreateBillingPortalMapper.toEntity(
36
37
  billingPortalDto,
37
- this.em,
38
- ...args
38
+ args[0] instanceof EntityManager ? args[0] : this.em,
39
+ ...args[0] instanceof EntityManager ? args.slice(1) : args
39
40
  );
40
41
  if (this.enableDatabaseBackup) {
41
42
  await this.em.persistAndFlush(billingPortal);
@@ -56,7 +57,12 @@ var BaseBillingPortalService = class {
56
57
  if (!billingPortalDetails) {
57
58
  throw new Error("Session not found");
58
59
  }
59
- return billingPortalDetails.value;
60
+ return this.mappers.BillingPortalMapper.toDto(
61
+ await this.mappers.UpdateBillingPortalMapper.toEntity(
62
+ billingPortalDetails.value,
63
+ this.em
64
+ )
65
+ );
60
66
  }
61
67
  async updateBillingPortalSession(billingPortalDto, ...args) {
62
68
  if (this.evaluatedTelemetryOptions.logging) {
@@ -73,8 +79,8 @@ var BaseBillingPortalService = class {
73
79
  }
74
80
  const billingPortal = await this.mappers.UpdateBillingPortalMapper.toEntity(
75
81
  billingPortalDto,
76
- this.em,
77
- ...args
82
+ args[0] instanceof EntityManager ? args[0] : this.em,
83
+ ...args[0] instanceof EntityManager ? args.slice(1) : args
78
84
  );
79
85
  if (this.enableDatabaseBackup) {
80
86
  await this.em.persistAndFlush({
@@ -90,7 +96,12 @@ var BaseBillingPortalService = class {
90
96
  value: updatedBillingPortalDto,
91
97
  ttlMilliseconds: this.cache.getTtlMilliseconds()
92
98
  });
93
- return updatedBillingPortalDto;
99
+ return this.mappers.BillingPortalMapper.toDto(
100
+ await this.mappers.UpdateBillingPortalMapper.toEntity(
101
+ billingPortal,
102
+ this.em
103
+ )
104
+ );
94
105
  }
95
106
  async expireBillingPortalSession(idDto) {
96
107
  if (this.evaluatedTelemetryOptions.logging) {
@@ -114,6 +125,7 @@ import { createCacheKey as createCacheKey2 } from "@forklaunch/core/cache";
114
125
  import {
115
126
  evaluateTelemetryOptions as evaluateTelemetryOptions2
116
127
  } from "@forklaunch/core/http";
128
+ import { EntityManager as EntityManager2 } from "@mikro-orm/core";
117
129
  var BaseCheckoutSessionService = class {
118
130
  evaluatedTelemetryOptions;
119
131
  enableDatabaseBackup;
@@ -145,8 +157,8 @@ var BaseCheckoutSessionService = class {
145
157
  }
146
158
  const checkoutSession = await this.mappers.CreateCheckoutSessionMapper.toEntity(
147
159
  checkoutSessionDto,
148
- this.em,
149
- ...args
160
+ args[0] instanceof EntityManager2 ? args[0] : this.em,
161
+ ...args[0] instanceof EntityManager2 ? args.slice(1) : args
150
162
  );
151
163
  const createdCheckoutSessionDto = await this.mappers.CheckoutSessionMapper.toDto(checkoutSession);
152
164
  if (this.enableDatabaseBackup) {
@@ -167,7 +179,10 @@ var BaseCheckoutSessionService = class {
167
179
  throw new Error("Session not found");
168
180
  }
169
181
  return this.mappers.CheckoutSessionMapper.toDto(
170
- checkoutSessionDetails.value
182
+ await this.mappers.UpdateCheckoutSessionMapper.toEntity(
183
+ checkoutSessionDetails.value,
184
+ this.em
185
+ )
171
186
  );
172
187
  }
173
188
  async expireCheckoutSession({ id }) {
@@ -212,6 +227,7 @@ import { createCacheKey as createCacheKey3 } from "@forklaunch/core/cache";
212
227
  import {
213
228
  evaluateTelemetryOptions as evaluateTelemetryOptions3
214
229
  } from "@forklaunch/core/http";
230
+ import { EntityManager as EntityManager3 } from "@mikro-orm/core";
215
231
  var BasePaymentLinkService = class {
216
232
  evaluatedTelemetryOptions;
217
233
  enableDatabaseBackup;
@@ -241,8 +257,8 @@ var BasePaymentLinkService = class {
241
257
  }
242
258
  const paymentLink = await this.mappers.CreatePaymentLinkMapper.toEntity(
243
259
  paymentLinkDto,
244
- this.em,
245
- ...args
260
+ args[0] instanceof EntityManager3 ? args[0] : this.em,
261
+ ...args[0] instanceof EntityManager3 ? args.slice(1) : args
246
262
  );
247
263
  if (this.enableDatabaseBackup) {
248
264
  await this.em.persistAndFlush(paymentLink);
@@ -266,8 +282,8 @@ var BasePaymentLinkService = class {
266
282
  }
267
283
  const paymentLink = await this.mappers.UpdatePaymentLinkMapper.toEntity(
268
284
  paymentLinkDto,
269
- this.em,
270
- ...args
285
+ args[0] instanceof EntityManager3 ? args[0] : this.em,
286
+ ...args[0] instanceof EntityManager3 ? args.slice(1) : args
271
287
  );
272
288
  if (this.enableDatabaseBackup) {
273
289
  await this.em.persistAndFlush(paymentLink);
@@ -296,7 +312,12 @@ var BasePaymentLinkService = class {
296
312
  if (!paymentLink) {
297
313
  throw new Error("Payment link not found");
298
314
  }
299
- return this.mappers.PaymentLinkMapper.toDto(paymentLink.value);
315
+ return this.mappers.PaymentLinkMapper.toDto(
316
+ await this.mappers.UpdatePaymentLinkMapper.toEntity(
317
+ paymentLink.value,
318
+ this.em
319
+ )
320
+ );
300
321
  }
301
322
  async expirePaymentLink({ id }) {
302
323
  this.openTelemetryCollector.info("Payment link expired", { id });
@@ -332,12 +353,16 @@ var BasePaymentLinkService = class {
332
353
  await this.cache.deleteRecord(this.createCacheKey(id));
333
354
  }
334
355
  async listPaymentLinks(idsDto) {
335
- const keys = idsDto?.ids.map((id) => this.createCacheKey(id)) ?? await this.cache.listKeys(this.cacheKeyPrefix);
356
+ const keys = idsDto?.ids && idsDto.ids.length > 0 ? idsDto?.ids.map((id) => this.createCacheKey(id)) : await this.cache.listKeys(this.cacheKeyPrefix);
357
+ console.log("keys", keys);
336
358
  return Promise.all(
337
359
  keys.map(async (key) => {
338
360
  const paymentLink = await this.cache.readRecord(key);
339
361
  const paymentLinkDto = this.mappers.PaymentLinkMapper.toDto(
340
- paymentLink.value
362
+ await this.mappers.UpdatePaymentLinkMapper.toEntity(
363
+ paymentLink.value,
364
+ this.em
365
+ )
341
366
  );
342
367
  return paymentLinkDto;
343
368
  })
@@ -349,6 +374,7 @@ var BasePaymentLinkService = class {
349
374
  import {
350
375
  evaluateTelemetryOptions as evaluateTelemetryOptions4
351
376
  } from "@forklaunch/core/http";
377
+ import { EntityManager as EntityManager4 } from "@mikro-orm/core";
352
378
  var BasePlanService = class {
353
379
  evaluatedTelemetryOptions;
354
380
  em;
@@ -372,7 +398,7 @@ var BasePlanService = class {
372
398
  }
373
399
  return Promise.all(
374
400
  (await (em ?? this.em).findAll("Plan", {
375
- filters: idsDto?.ids ? { id: { $in: idsDto.ids } } : void 0
401
+ where: idsDto?.ids?.length ? { id: { $in: idsDto.ids } } : void 0
376
402
  })).map(
377
403
  (plan) => this.mappers.PlanMapper.toDto(plan)
378
404
  )
@@ -385,7 +411,7 @@ var BasePlanService = class {
385
411
  const plan = await this.mappers.CreatePlanMapper.toEntity(
386
412
  planDto,
387
413
  em ?? this.em,
388
- ...args
414
+ ...args[0] instanceof EntityManager4 ? args.slice(1) : args
389
415
  );
390
416
  await (em ?? this.em).transactional(async (innerEm) => {
391
417
  await innerEm.persist(plan);
@@ -427,6 +453,7 @@ var BasePlanService = class {
427
453
  import {
428
454
  evaluateTelemetryOptions as evaluateTelemetryOptions5
429
455
  } from "@forklaunch/core/http";
456
+ import { EntityManager as EntityManager5 } from "@mikro-orm/core";
430
457
  var BaseSubscriptionService = class {
431
458
  constructor(em, openTelemetryCollector, schemaValidator, mappers, options) {
432
459
  this.options = options;
@@ -455,7 +482,7 @@ var BaseSubscriptionService = class {
455
482
  const subscription = await this.mappers.CreateSubscriptionMapper.toEntity(
456
483
  subscriptionDto,
457
484
  em ?? this.em,
458
- ...args
485
+ ...args[0] instanceof EntityManager5 ? args.slice(1) : args
459
486
  );
460
487
  await (em ?? this.em).transactional(async (innerEm) => {
461
488
  await innerEm.persist(subscription);
@@ -534,20 +561,14 @@ var BaseSubscriptionService = class {
534
561
  if (this.evaluatedTelemetryOptions.logging) {
535
562
  this.openTelemetryCollector.info("Listing subscriptions", idsDto);
536
563
  }
537
- const subscriptions = await (em ?? this.em).findAll("Subscription", {
538
- where: idsDto.ids ? {
539
- id: {
540
- $in: idsDto.ids
541
- }
542
- } : void 0
543
- });
544
564
  return Promise.all(
545
- subscriptions.map((subscription) => {
546
- const subscriptionDto = this.mappers.SubscriptionMapper.toDto(
565
+ (await (em ?? this.em).findAll("Subscription", {
566
+ where: idsDto?.ids?.length ? { id: { $in: idsDto.ids } } : void 0
567
+ })).map(
568
+ (subscription) => this.mappers.SubscriptionMapper.toDto(
547
569
  subscription
548
- );
549
- return subscriptionDto;
550
- })
570
+ )
571
+ )
551
572
  );
552
573
  }
553
574
  async cancelSubscription(idDto, em) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/implementation-billing-base",
3
- "version": "0.7.4",
3
+ "version": "0.8.1",
4
4
  "description": "Billing basic implementation for forklaunch",
5
5
  "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
6
  "bugs": {
@@ -36,18 +36,18 @@
36
36
  "lib/**"
37
37
  ],
38
38
  "dependencies": {
39
- "@forklaunch/common": "^0.6.14",
40
- "@forklaunch/core": "^0.15.3",
41
- "@forklaunch/internal": "^0.3.14",
42
- "@forklaunch/validator": "^0.10.14",
43
- "@mikro-orm/core": "^6.5.6",
39
+ "@forklaunch/common": "^0.6.18",
40
+ "@forklaunch/core": "^0.15.7",
41
+ "@forklaunch/internal": "^0.3.18",
42
+ "@forklaunch/validator": "^0.10.18",
43
+ "@mikro-orm/core": "^6.5.7",
44
44
  "@sinclair/typebox": "^0.34.41",
45
45
  "ajv": "^8.17.1",
46
- "zod": "^4.1.11",
47
- "@forklaunch/interfaces-billing": "0.7.3"
46
+ "zod": "^4.1.12",
47
+ "@forklaunch/interfaces-billing": "0.8.1"
48
48
  },
49
49
  "devDependencies": {
50
- "@typescript/native-preview": "7.0.0-dev.20250930.1",
50
+ "@typescript/native-preview": "7.0.0-dev.20251008.1",
51
51
  "depcheck": "^1.4.7",
52
52
  "prettier": "^3.6.2",
53
53
  "typedoc": "^0.28.13"