@saasicat/adapter-prisma 1.0.0-rc.21 → 1.0.0-rc.22

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.
package/dist/index.cjs CHANGED
@@ -47,6 +47,7 @@ __export(index_exports, {
47
47
  PrismaPromoCodeValidationLogRepository: () => PrismaPromoCodeValidationLogRepository,
48
48
  PrismaPromoSubscriptionLookup: () => PrismaPromoSubscriptionLookup,
49
49
  PrismaPromotionRepository: () => PrismaPromotionRepository,
50
+ PrismaSubscriberLedgerRepository: () => PrismaSubscriberLedgerRepository,
50
51
  PrismaSubscriberPaymentMethodRepository: () => PrismaSubscriberPaymentMethodRepository,
51
52
  PrismaSubscriberRepository: () => PrismaSubscriberRepository,
52
53
  PrismaSubscriptionBundleRepository: () => PrismaSubscriptionBundleRepository,
@@ -3973,6 +3974,7 @@ PrismaPromoSubscriptionLookup = _ts_decorate21([
3973
3974
 
3974
3975
  // src/prisma-subscription-bundle.repository.ts
3975
3976
  var import_common22 = require("@nestjs/common");
3977
+ var import_core7 = require("@saasicat/core");
3976
3978
  function _ts_decorate22(decorators, target, key, desc) {
3977
3979
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3978
3980
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -4010,7 +4012,7 @@ var PrismaSubscriptionBundleRepository = class {
4010
4012
  startedAt: "desc"
4011
4013
  }
4012
4014
  });
4013
- return rows.map(toRecord3);
4015
+ return rows.map(import_core7.toSubscriptionBundleRecord);
4014
4016
  }
4015
4017
  async findById(subscriptionBundleId) {
4016
4018
  const row = await this.db().subscriptionBundle.findUnique({
@@ -4018,7 +4020,7 @@ var PrismaSubscriptionBundleRepository = class {
4018
4020
  id: subscriptionBundleId
4019
4021
  }
4020
4022
  });
4021
- return row ? toRecord3(row) : null;
4023
+ return row ? (0, import_core7.toSubscriptionBundleRecord)(row) : null;
4022
4024
  }
4023
4025
  async listActiveBySubscription(subscriptionId, asOf = /* @__PURE__ */ new Date(), tx) {
4024
4026
  const rows = await this.db(tx).subscriptionBundle.findMany({
@@ -4039,7 +4041,7 @@ var PrismaSubscriptionBundleRepository = class {
4039
4041
  startedAt: "desc"
4040
4042
  }
4041
4043
  });
4042
- return rows.map(toRecord3);
4044
+ return rows.map(import_core7.toSubscriptionBundleRecord);
4043
4045
  }
4044
4046
  async add(data) {
4045
4047
  const row = await this.db().subscriptionBundle.create({
@@ -4053,7 +4055,7 @@ var PrismaSubscriptionBundleRepository = class {
4053
4055
  currentPeriodEnd: data.currentPeriodEnd ?? null
4054
4056
  }
4055
4057
  });
4056
- return toRecord3(row);
4058
+ return (0, import_core7.toSubscriptionBundleRecord)(row);
4057
4059
  }
4058
4060
  async cancel(subscriptionBundleId, data) {
4059
4061
  const { count } = await this.db().subscriptionBundle.updateMany({
@@ -4075,7 +4077,7 @@ var PrismaSubscriptionBundleRepository = class {
4075
4077
  }
4076
4078
  });
4077
4079
  if (!row) throw new Error(`SubscriptionBundle '${subscriptionBundleId}' disappeared`);
4078
- return toRecord3(row);
4080
+ return (0, import_core7.toSubscriptionBundleRecord)(row);
4079
4081
  }
4080
4082
  async reactivate(subscriptionBundleId) {
4081
4083
  const row = await this.db().subscriptionBundle.update({
@@ -4087,7 +4089,7 @@ var PrismaSubscriptionBundleRepository = class {
4087
4089
  canceledEffectiveAt: null
4088
4090
  }
4089
4091
  });
4090
- return toRecord3(row);
4092
+ return (0, import_core7.toSubscriptionBundleRecord)(row);
4091
4093
  }
4092
4094
  async countActiveByBundleVersionId(bundleVersionId, asOf = /* @__PURE__ */ new Date()) {
4093
4095
  return this.db().subscriptionBundle.count({
@@ -4115,27 +4117,10 @@ PrismaSubscriptionBundleRepository = _ts_decorate22([
4115
4117
  typeof SubscriptionBundleClient === "undefined" ? Object : SubscriptionBundleClient
4116
4118
  ])
4117
4119
  ], PrismaSubscriptionBundleRepository);
4118
- function toRecord3(row) {
4119
- return {
4120
- id: row.id,
4121
- subscriptionId: row.subscriptionId,
4122
- bundleVersionId: row.bundleVersionId,
4123
- startedAt: row.startedAt,
4124
- minimumTermEndsAt: row.minimumTermEndsAt,
4125
- billingCycle: row.billingCycle ?? null,
4126
- currentPeriodStart: row.currentPeriodStart ?? null,
4127
- currentPeriodEnd: row.currentPeriodEnd ?? null,
4128
- canceledAt: row.canceledAt,
4129
- canceledEffectiveAt: row.canceledEffectiveAt,
4130
- createdAt: row.createdAt,
4131
- updatedAt: row.updatedAt
4132
- };
4133
- }
4134
- __name(toRecord3, "toRecord");
4135
4120
 
4136
4121
  // src/prisma-subscription-contract.repository.ts
4137
4122
  var import_common23 = require("@nestjs/common");
4138
- var import_core7 = require("@saasicat/core");
4123
+ var import_core8 = require("@saasicat/core");
4139
4124
  function _ts_decorate23(decorators, target, key, desc) {
4140
4125
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4141
4126
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -4201,7 +4186,7 @@ var PrismaSubscriptionContractRepository = class {
4201
4186
  }
4202
4187
  ]
4203
4188
  });
4204
- return rows.map((row) => (0, import_core7.toSubscriptionContractRecord)(row, row.lineItems));
4189
+ return rows.map((row) => (0, import_core8.toSubscriptionContractRecord)(row, row.lineItems));
4205
4190
  }
4206
4191
  async findById(contractId) {
4207
4192
  const row = await this.db().subscriptionContract.findUnique({
@@ -4212,7 +4197,7 @@ var PrismaSubscriptionContractRepository = class {
4212
4197
  lineItems: true
4213
4198
  }
4214
4199
  });
4215
- return row ? (0, import_core7.toSubscriptionContractRecord)(row, row.lineItems) : null;
4200
+ return row ? (0, import_core8.toSubscriptionContractRecord)(row, row.lineItems) : null;
4216
4201
  }
4217
4202
  async findActiveByTenantId(tenantId, asOf = /* @__PURE__ */ new Date(), tx) {
4218
4203
  const row = await this.db(tx).subscriptionContract.findFirst({
@@ -4220,7 +4205,7 @@ var PrismaSubscriptionContractRepository = class {
4220
4205
  tenantId,
4221
4206
  status: {
4222
4207
  in: [
4223
- ...import_core7.ACTIVE_SUBSCRIPTION_CONTRACT_STATUSES
4208
+ ...import_core8.ACTIVE_SUBSCRIPTION_CONTRACT_STATUSES
4224
4209
  ]
4225
4210
  },
4226
4211
  effectiveFrom: {
@@ -4249,7 +4234,7 @@ var PrismaSubscriptionContractRepository = class {
4249
4234
  }
4250
4235
  ]
4251
4236
  });
4252
- return row ? (0, import_core7.toSubscriptionContractRecord)(row, row.lineItems) : null;
4237
+ return row ? (0, import_core8.toSubscriptionContractRecord)(row, row.lineItems) : null;
4253
4238
  }
4254
4239
  async findByOriginalOfferId(offerId, tx) {
4255
4240
  const row = await this.db(tx).subscriptionContract.findFirst({
@@ -4268,7 +4253,7 @@ var PrismaSubscriptionContractRepository = class {
4268
4253
  }
4269
4254
  ]
4270
4255
  });
4271
- return row ? (0, import_core7.toSubscriptionContractRecord)(row, row.lineItems) : null;
4256
+ return row ? (0, import_core8.toSubscriptionContractRecord)(row, row.lineItems) : null;
4272
4257
  }
4273
4258
  async create(data, tx) {
4274
4259
  const row = await this.db(tx).subscriptionContract.create({
@@ -4304,13 +4289,13 @@ var PrismaSubscriptionContractRepository = class {
4304
4289
  lineItems: true
4305
4290
  }
4306
4291
  });
4307
- return (0, import_core7.toSubscriptionContractRecord)(row, row.lineItems);
4292
+ return (0, import_core8.toSubscriptionContractRecord)(row, row.lineItems);
4308
4293
  }
4309
4294
  async listRunningIssuers(limit, asOf = /* @__PURE__ */ new Date()) {
4310
4295
  const where = {
4311
4296
  status: {
4312
4297
  in: [
4313
- ...import_core7.ACTIVE_SUBSCRIPTION_CONTRACT_STATUSES
4298
+ ...import_core8.ACTIVE_SUBSCRIPTION_CONTRACT_STATUSES
4314
4299
  ]
4315
4300
  },
4316
4301
  OR: [
@@ -4357,7 +4342,7 @@ var PrismaSubscriptionContractRepository = class {
4357
4342
  ]);
4358
4343
  return {
4359
4344
  total,
4360
- contracts: rows.map(import_core7.toRunningContractIssuer)
4345
+ contracts: rows.map(import_core8.toRunningContractIssuer)
4361
4346
  };
4362
4347
  }
4363
4348
  async terminate(contractId, data) {
@@ -4378,7 +4363,7 @@ var PrismaSubscriptionContractRepository = class {
4378
4363
  lineItems: true
4379
4364
  }
4380
4365
  });
4381
- return (0, import_core7.toSubscriptionContractRecord)(row, row.lineItems);
4366
+ return (0, import_core8.toSubscriptionContractRecord)(row, row.lineItems);
4382
4367
  }
4383
4368
  };
4384
4369
  PrismaSubscriptionContractRepository = _ts_decorate23([
@@ -4414,9 +4399,9 @@ function toLineItemCreate(item) {
4414
4399
  }
4415
4400
  __name(toLineItemCreate, "toLineItemCreate");
4416
4401
 
4417
- // src/prisma-subscriber-payment-method.repository.ts
4402
+ // src/prisma-subscriber-ledger.repository.ts
4418
4403
  var import_common24 = require("@nestjs/common");
4419
- var import_core8 = require("@saasicat/core");
4404
+ var import_core9 = require("@saasicat/core");
4420
4405
  function _ts_decorate24(decorators, target, key, desc) {
4421
4406
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4422
4407
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -4434,6 +4419,84 @@ function _ts_param23(paramIndex, decorator) {
4434
4419
  };
4435
4420
  }
4436
4421
  __name(_ts_param23, "_ts_param");
4422
+ var PrismaSubscriberLedgerRepository = class {
4423
+ static {
4424
+ __name(this, "PrismaSubscriberLedgerRepository");
4425
+ }
4426
+ prisma;
4427
+ constructor(prisma) {
4428
+ this.prisma = prisma;
4429
+ }
4430
+ db(tx) {
4431
+ return tx ?? this.prisma;
4432
+ }
4433
+ /**
4434
+ * One statement, `skipDuplicates` being `ON CONFLICT DO NOTHING`: a charge
4435
+ * another caller wrote first — committed or still in flight — is waited for
4436
+ * and skipped rather than raised, and only what this call wrote comes back.
4437
+ * It names no conflict target, so it suppresses every unique key; the only
4438
+ * one besides the natural key is the primary key, a uuid made per row here.
4439
+ */
4440
+ async recordCharges(charges, tx) {
4441
+ if (charges.length === 0) return [];
4442
+ const rows = await this.db(tx).subscriberLedgerEntry.createManyAndReturn({
4443
+ data: charges.map(import_core9.subscriberChargeColumns),
4444
+ skipDuplicates: true
4445
+ });
4446
+ return rows.map(import_core9.toSubscriberChargeRecord);
4447
+ }
4448
+ async listBySubscription(subscriptionId, tx) {
4449
+ const rows = await this.db(tx).subscriberLedgerEntry.findMany({
4450
+ where: {
4451
+ subscriptionId
4452
+ },
4453
+ orderBy: [
4454
+ {
4455
+ periodStart: "asc"
4456
+ },
4457
+ {
4458
+ source: "asc"
4459
+ },
4460
+ {
4461
+ sourceRef: "asc"
4462
+ },
4463
+ {
4464
+ origin: "asc"
4465
+ }
4466
+ ]
4467
+ });
4468
+ return rows.map(import_core9.toSubscriberChargeRecord);
4469
+ }
4470
+ };
4471
+ PrismaSubscriberLedgerRepository = _ts_decorate24([
4472
+ (0, import_common24.Injectable)(),
4473
+ _ts_param23(0, (0, import_common24.Inject)(PRISMA_CLIENT_TOKEN)),
4474
+ _ts_metadata23("design:type", Function),
4475
+ _ts_metadata23("design:paramtypes", [
4476
+ typeof LedgerClient === "undefined" ? Object : LedgerClient
4477
+ ])
4478
+ ], PrismaSubscriberLedgerRepository);
4479
+
4480
+ // src/prisma-subscriber-payment-method.repository.ts
4481
+ var import_common25 = require("@nestjs/common");
4482
+ var import_core10 = require("@saasicat/core");
4483
+ function _ts_decorate25(decorators, target, key, desc) {
4484
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4485
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4486
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4487
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
4488
+ }
4489
+ __name(_ts_decorate25, "_ts_decorate");
4490
+ function _ts_metadata24(k, v) {
4491
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
4492
+ }
4493
+ __name(_ts_metadata24, "_ts_metadata");
4494
+ function _ts_param24(paramIndex, decorator) {
4495
+ return function(target, key) {
4496
+ decorator(target, key, paramIndex);
4497
+ };
4498
+ }
4499
+ __name(_ts_param24, "_ts_param");
4437
4500
  var PrismaSubscriberPaymentMethodRepository = class {
4438
4501
  static {
4439
4502
  __name(this, "PrismaSubscriberPaymentMethodRepository");
@@ -4465,9 +4528,9 @@ var PrismaSubscriberPaymentMethodRepository = class {
4465
4528
  }
4466
4529
  });
4467
4530
  if (recorded) {
4468
- (0, import_core8.refuseForeignPaymentMethodReference)(recorded, data.subscriberId);
4531
+ (0, import_core10.refuseForeignPaymentMethodReference)(recorded, data.subscriberId);
4469
4532
  return {
4470
- method: (0, import_core8.toSubscriberPaymentMethodRecord)(recorded),
4533
+ method: (0, import_core10.toSubscriberPaymentMethodRecord)(recorded),
4471
4534
  outcome: "already-recorded"
4472
4535
  };
4473
4536
  }
@@ -4479,13 +4542,13 @@ var PrismaSubscriberPaymentMethodRepository = class {
4479
4542
  });
4480
4543
  const replacedOnArrival = active && active.confirmedAt.getTime() > data.confirmedAt.getTime() ? active.confirmedAt : null;
4481
4544
  const claimed = await this.claimReference(db, {
4482
- ...(0, import_core8.subscriberPaymentMethodColumns)(data),
4545
+ ...(0, import_core10.subscriberPaymentMethodColumns)(data),
4483
4546
  status: "REPLACED",
4484
4547
  replacedAt: replacedOnArrival ?? data.confirmedAt
4485
4548
  });
4486
4549
  if (replacedOnArrival) {
4487
4550
  return {
4488
- method: (0, import_core8.toSubscriberPaymentMethodRecord)(claimed),
4551
+ method: (0, import_core10.toSubscriberPaymentMethodRecord)(claimed),
4489
4552
  outcome: "superseded"
4490
4553
  };
4491
4554
  }
@@ -4510,7 +4573,7 @@ var PrismaSubscriberPaymentMethodRepository = class {
4510
4573
  }
4511
4574
  });
4512
4575
  return {
4513
- method: (0, import_core8.toSubscriberPaymentMethodRecord)(inUse),
4576
+ method: (0, import_core10.toSubscriberPaymentMethodRecord)(inUse),
4514
4577
  outcome: "activated"
4515
4578
  };
4516
4579
  });
@@ -4570,7 +4633,7 @@ var PrismaSubscriberPaymentMethodRepository = class {
4570
4633
  skipDuplicates: true
4571
4634
  });
4572
4635
  if (!claimed) {
4573
- throw new import_core8.ForeignPaymentMethodReferenceError(row.gatewayAccount, row.paymentMethodRef);
4636
+ throw new import_core10.ForeignPaymentMethodReferenceError(row.gatewayAccount, row.paymentMethodRef);
4574
4637
  }
4575
4638
  return claimed;
4576
4639
  }
@@ -4581,7 +4644,7 @@ var PrismaSubscriberPaymentMethodRepository = class {
4581
4644
  status: "ACTIVE"
4582
4645
  }
4583
4646
  });
4584
- return row ? (0, import_core8.toSubscriberPaymentMethodRecord)(row) : null;
4647
+ return row ? (0, import_core10.toSubscriberPaymentMethodRecord)(row) : null;
4585
4648
  }
4586
4649
  async findByReference(reference, tx) {
4587
4650
  const row = await this.db(tx).subscriberPaymentMethod.findFirst({
@@ -4591,7 +4654,7 @@ var PrismaSubscriberPaymentMethodRepository = class {
4591
4654
  paymentMethodRef: reference.paymentMethodRef
4592
4655
  }
4593
4656
  });
4594
- return row ? (0, import_core8.toSubscriberPaymentMethodRecord)(row) : null;
4657
+ return row ? (0, import_core10.toSubscriberPaymentMethodRecord)(row) : null;
4595
4658
  }
4596
4659
  async accountsInUse() {
4597
4660
  const rows = await this.db().subscriberPaymentMethod.findMany({
@@ -4636,35 +4699,35 @@ var PrismaSubscriberPaymentMethodRepository = class {
4636
4699
  return count === 1;
4637
4700
  }
4638
4701
  };
4639
- PrismaSubscriberPaymentMethodRepository = _ts_decorate24([
4640
- (0, import_common24.Injectable)(),
4641
- _ts_param23(0, (0, import_common24.Inject)(PRISMA_CLIENT_TOKEN)),
4642
- _ts_metadata23("design:type", Function),
4643
- _ts_metadata23("design:paramtypes", [
4702
+ PrismaSubscriberPaymentMethodRepository = _ts_decorate25([
4703
+ (0, import_common25.Injectable)(),
4704
+ _ts_param24(0, (0, import_common25.Inject)(PRISMA_CLIENT_TOKEN)),
4705
+ _ts_metadata24("design:type", Function),
4706
+ _ts_metadata24("design:paramtypes", [
4644
4707
  typeof PaymentMethodRepositoryClient === "undefined" ? Object : PaymentMethodRepositoryClient
4645
4708
  ])
4646
4709
  ], PrismaSubscriberPaymentMethodRepository);
4647
4710
 
4648
4711
  // src/prisma-subscriber.repository.ts
4649
- var import_common25 = require("@nestjs/common");
4650
- var import_core9 = require("@saasicat/core");
4651
- function _ts_decorate25(decorators, target, key, desc) {
4712
+ var import_common26 = require("@nestjs/common");
4713
+ var import_core11 = require("@saasicat/core");
4714
+ function _ts_decorate26(decorators, target, key, desc) {
4652
4715
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4653
4716
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4654
4717
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4655
4718
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4656
4719
  }
4657
- __name(_ts_decorate25, "_ts_decorate");
4658
- function _ts_metadata24(k, v) {
4720
+ __name(_ts_decorate26, "_ts_decorate");
4721
+ function _ts_metadata25(k, v) {
4659
4722
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
4660
4723
  }
4661
- __name(_ts_metadata24, "_ts_metadata");
4662
- function _ts_param24(paramIndex, decorator) {
4724
+ __name(_ts_metadata25, "_ts_metadata");
4725
+ function _ts_param25(paramIndex, decorator) {
4663
4726
  return function(target, key) {
4664
4727
  decorator(target, key, paramIndex);
4665
4728
  };
4666
4729
  }
4667
- __name(_ts_param24, "_ts_param");
4730
+ __name(_ts_param25, "_ts_param");
4668
4731
  var WITH_LIVE_TENANT = {
4669
4732
  tenants: {
4670
4733
  where: {
@@ -4715,7 +4778,7 @@ var PrismaSubscriberRepository = class {
4715
4778
  });
4716
4779
  return null;
4717
4780
  }
4718
- return (0, import_core9.toSubscriberRecord)(created, tenantId);
4781
+ return (0, import_core11.toSubscriberRecord)(created, tenantId);
4719
4782
  });
4720
4783
  }
4721
4784
  async findById(subscriberId, tx) {
@@ -4725,7 +4788,7 @@ var PrismaSubscriberRepository = class {
4725
4788
  },
4726
4789
  include: WITH_LIVE_TENANT
4727
4790
  });
4728
- return row ? toRecord4(row) : null;
4791
+ return row ? toRecord3(row) : null;
4729
4792
  }
4730
4793
  async findByTenantId(tenantId, tx) {
4731
4794
  const row = await this.db(tx).subscriber.findFirst({
@@ -4738,7 +4801,7 @@ var PrismaSubscriberRepository = class {
4738
4801
  }
4739
4802
  }
4740
4803
  });
4741
- return row ? (0, import_core9.toSubscriberRecord)(row, tenantId) : null;
4804
+ return row ? (0, import_core11.toSubscriberRecord)(row, tenantId) : null;
4742
4805
  }
4743
4806
  async updateContact(subscriberId, change, tx) {
4744
4807
  const db = this.db(tx);
@@ -4761,10 +4824,10 @@ var PrismaSubscriberRepository = class {
4761
4824
  include: WITH_LIVE_TENANT
4762
4825
  });
4763
4826
  if (!current) return null;
4764
- const delta = (0, import_core9.identityCorrectionDelta)(current, data.corrected);
4827
+ const delta = (0, import_core11.identityCorrectionDelta)(current, data.corrected);
4765
4828
  if (Object.keys(delta.corrected).length === 0) {
4766
4829
  return {
4767
- subscriber: toRecord4(current),
4830
+ subscriber: toRecord3(current),
4768
4831
  correction: null
4769
4832
  };
4770
4833
  }
@@ -4786,8 +4849,8 @@ var PrismaSubscriberRepository = class {
4786
4849
  }
4787
4850
  });
4788
4851
  return {
4789
- subscriber: toRecord4(updated),
4790
- correction: (0, import_core9.toSubscriberCorrectionRecord)(correction)
4852
+ subscriber: toRecord3(updated),
4853
+ correction: (0, import_core11.toSubscriberCorrectionRecord)(correction)
4791
4854
  };
4792
4855
  });
4793
4856
  }
@@ -4805,41 +4868,41 @@ var PrismaSubscriberRepository = class {
4805
4868
  }
4806
4869
  ]
4807
4870
  });
4808
- return rows.map(import_core9.toSubscriberCorrectionRecord);
4871
+ return rows.map(import_core11.toSubscriberCorrectionRecord);
4809
4872
  }
4810
4873
  };
4811
- PrismaSubscriberRepository = _ts_decorate25([
4812
- (0, import_common25.Injectable)(),
4813
- _ts_param24(0, (0, import_common25.Inject)(PRISMA_CLIENT_TOKEN)),
4814
- _ts_metadata24("design:type", Function),
4815
- _ts_metadata24("design:paramtypes", [
4874
+ PrismaSubscriberRepository = _ts_decorate26([
4875
+ (0, import_common26.Injectable)(),
4876
+ _ts_param25(0, (0, import_common26.Inject)(PRISMA_CLIENT_TOKEN)),
4877
+ _ts_metadata25("design:type", Function),
4878
+ _ts_metadata25("design:paramtypes", [
4816
4879
  typeof SubscriberRepositoryClient === "undefined" ? Object : SubscriberRepositoryClient
4817
4880
  ])
4818
4881
  ], PrismaSubscriberRepository);
4819
- function toRecord4(row) {
4820
- return (0, import_core9.toSubscriberRecord)(row, row.tenants?.[0]?.tenantId ?? null);
4882
+ function toRecord3(row) {
4883
+ return (0, import_core11.toSubscriberRecord)(row, row.tenants?.[0]?.tenantId ?? null);
4821
4884
  }
4822
- __name(toRecord4, "toRecord");
4885
+ __name(toRecord3, "toRecord");
4823
4886
 
4824
4887
  // src/prisma-subscription.repository.ts
4825
- var import_common26 = require("@nestjs/common");
4826
- function _ts_decorate26(decorators, target, key, desc) {
4888
+ var import_common27 = require("@nestjs/common");
4889
+ function _ts_decorate27(decorators, target, key, desc) {
4827
4890
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4828
4891
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4829
4892
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4830
4893
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4831
4894
  }
4832
- __name(_ts_decorate26, "_ts_decorate");
4833
- function _ts_metadata25(k, v) {
4895
+ __name(_ts_decorate27, "_ts_decorate");
4896
+ function _ts_metadata26(k, v) {
4834
4897
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
4835
4898
  }
4836
- __name(_ts_metadata25, "_ts_metadata");
4837
- function _ts_param25(paramIndex, decorator) {
4899
+ __name(_ts_metadata26, "_ts_metadata");
4900
+ function _ts_param26(paramIndex, decorator) {
4838
4901
  return function(target, key) {
4839
4902
  decorator(target, key, paramIndex);
4840
4903
  };
4841
4904
  }
4842
- __name(_ts_param25, "_ts_param");
4905
+ __name(_ts_param26, "_ts_param");
4843
4906
  var ACTIVE_STATUSES = [
4844
4907
  "ACTIVE",
4845
4908
  "TRIAL"
@@ -5074,37 +5137,37 @@ var PrismaSubscriptionRepository = class {
5074
5137
  ]));
5075
5138
  }
5076
5139
  };
5077
- PrismaSubscriptionRepository = _ts_decorate26([
5078
- (0, import_common26.Injectable)(),
5079
- _ts_param25(0, (0, import_common26.Inject)(PRISMA_CLIENT_TOKEN)),
5080
- _ts_param25(1, (0, import_common26.Optional)()),
5081
- _ts_param25(1, (0, import_common26.Inject)(PRISMA_SCHEMA_OPTIONS_TOKEN)),
5082
- _ts_metadata25("design:type", Function),
5083
- _ts_metadata25("design:paramtypes", [
5140
+ PrismaSubscriptionRepository = _ts_decorate27([
5141
+ (0, import_common27.Injectable)(),
5142
+ _ts_param26(0, (0, import_common27.Inject)(PRISMA_CLIENT_TOKEN)),
5143
+ _ts_param26(1, (0, import_common27.Optional)()),
5144
+ _ts_param26(1, (0, import_common27.Inject)(PRISMA_SCHEMA_OPTIONS_TOKEN)),
5145
+ _ts_metadata26("design:type", Function),
5146
+ _ts_metadata26("design:paramtypes", [
5084
5147
  typeof SubscriptionRepositoryClient === "undefined" ? Object : SubscriptionRepositoryClient,
5085
5148
  typeof PrismaSchemaOptions === "undefined" ? Object : PrismaSchemaOptions
5086
5149
  ])
5087
5150
  ], PrismaSubscriptionRepository);
5088
5151
 
5089
5152
  // src/prisma-subscription-usage.adapter.ts
5090
- var import_common27 = require("@nestjs/common");
5091
- function _ts_decorate27(decorators, target, key, desc) {
5153
+ var import_common28 = require("@nestjs/common");
5154
+ function _ts_decorate28(decorators, target, key, desc) {
5092
5155
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5093
5156
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5094
5157
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5095
5158
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5096
5159
  }
5097
- __name(_ts_decorate27, "_ts_decorate");
5098
- function _ts_metadata26(k, v) {
5160
+ __name(_ts_decorate28, "_ts_decorate");
5161
+ function _ts_metadata27(k, v) {
5099
5162
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
5100
5163
  }
5101
- __name(_ts_metadata26, "_ts_metadata");
5102
- function _ts_param26(paramIndex, decorator) {
5164
+ __name(_ts_metadata27, "_ts_metadata");
5165
+ function _ts_param27(paramIndex, decorator) {
5103
5166
  return function(target, key) {
5104
5167
  decorator(target, key, paramIndex);
5105
5168
  };
5106
5169
  }
5107
- __name(_ts_param26, "_ts_param");
5170
+ __name(_ts_param27, "_ts_param");
5108
5171
  var PrismaSubscriptionUsageAdapter = class {
5109
5172
  static {
5110
5173
  __name(this, "PrismaSubscriptionUsageAdapter");
@@ -5195,38 +5258,38 @@ var PrismaSubscriptionUsageAdapter = class {
5195
5258
  return getPrismaDelegate(this.prisma, this.planVersionDelegateName);
5196
5259
  }
5197
5260
  };
5198
- PrismaSubscriptionUsageAdapter = _ts_decorate27([
5199
- (0, import_common27.Injectable)(),
5200
- _ts_param26(0, (0, import_common27.Inject)(PRISMA_CLIENT_TOKEN)),
5201
- _ts_param26(1, (0, import_common27.Optional)()),
5202
- _ts_param26(1, (0, import_common27.Inject)(PRISMA_SCHEMA_OPTIONS_TOKEN)),
5203
- _ts_metadata26("design:type", Function),
5204
- _ts_metadata26("design:paramtypes", [
5261
+ PrismaSubscriptionUsageAdapter = _ts_decorate28([
5262
+ (0, import_common28.Injectable)(),
5263
+ _ts_param27(0, (0, import_common28.Inject)(PRISMA_CLIENT_TOKEN)),
5264
+ _ts_param27(1, (0, import_common28.Optional)()),
5265
+ _ts_param27(1, (0, import_common28.Inject)(PRISMA_SCHEMA_OPTIONS_TOKEN)),
5266
+ _ts_metadata27("design:type", Function),
5267
+ _ts_metadata27("design:paramtypes", [
5205
5268
  typeof SubscriptionUsageClient === "undefined" ? Object : SubscriptionUsageClient,
5206
5269
  typeof PrismaSchemaOptions === "undefined" ? Object : PrismaSchemaOptions
5207
5270
  ])
5208
5271
  ], PrismaSubscriptionUsageAdapter);
5209
5272
 
5210
5273
  // src/prisma-super-admin-bootstrap.adapter.ts
5211
- var import_common28 = require("@nestjs/common");
5212
- var import_core10 = require("@saasicat/core");
5213
- function _ts_decorate28(decorators, target, key, desc) {
5274
+ var import_common29 = require("@nestjs/common");
5275
+ var import_core12 = require("@saasicat/core");
5276
+ function _ts_decorate29(decorators, target, key, desc) {
5214
5277
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5215
5278
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5216
5279
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5217
5280
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5218
5281
  }
5219
- __name(_ts_decorate28, "_ts_decorate");
5220
- function _ts_metadata27(k, v) {
5282
+ __name(_ts_decorate29, "_ts_decorate");
5283
+ function _ts_metadata28(k, v) {
5221
5284
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
5222
5285
  }
5223
- __name(_ts_metadata27, "_ts_metadata");
5224
- function _ts_param27(paramIndex, decorator) {
5286
+ __name(_ts_metadata28, "_ts_metadata");
5287
+ function _ts_param28(paramIndex, decorator) {
5225
5288
  return function(target, key) {
5226
5289
  decorator(target, key, paramIndex);
5227
5290
  };
5228
5291
  }
5229
- __name(_ts_param27, "_ts_param");
5292
+ __name(_ts_param28, "_ts_param");
5230
5293
  var PASSWORD_HASHER_TOKEN = /* @__PURE__ */ Symbol.for("saasicat/adapter-prisma/PasswordHasher");
5231
5294
  var PrismaSuperAdminBootstrapAdapter = class {
5232
5295
  static {
@@ -5254,7 +5317,7 @@ var PrismaSuperAdminBootstrapAdapter = class {
5254
5317
  }
5255
5318
  });
5256
5319
  if (existing) {
5257
- throw new import_core10.PlatformUserExistsError(email, existing.platformRole);
5320
+ throw new import_core12.PlatformUserExistsError(email, existing.platformRole);
5258
5321
  }
5259
5322
  const row = await this.prisma.superAdminUser.create({
5260
5323
  data: {
@@ -5276,37 +5339,37 @@ var PrismaSuperAdminBootstrapAdapter = class {
5276
5339
  };
5277
5340
  }
5278
5341
  };
5279
- PrismaSuperAdminBootstrapAdapter = _ts_decorate28([
5280
- (0, import_common28.Injectable)(),
5281
- _ts_param27(0, (0, import_common28.Inject)(PRISMA_CLIENT_TOKEN)),
5282
- _ts_param27(1, (0, import_common28.Inject)(PASSWORD_HASHER_TOKEN)),
5283
- _ts_metadata27("design:type", Function),
5284
- _ts_metadata27("design:paramtypes", [
5342
+ PrismaSuperAdminBootstrapAdapter = _ts_decorate29([
5343
+ (0, import_common29.Injectable)(),
5344
+ _ts_param28(0, (0, import_common29.Inject)(PRISMA_CLIENT_TOKEN)),
5345
+ _ts_param28(1, (0, import_common29.Inject)(PASSWORD_HASHER_TOKEN)),
5346
+ _ts_metadata28("design:type", Function),
5347
+ _ts_metadata28("design:paramtypes", [
5285
5348
  typeof PrismaLike === "undefined" ? Object : PrismaLike,
5286
5349
  typeof PasswordHasher === "undefined" ? Object : PasswordHasher
5287
5350
  ])
5288
5351
  ], PrismaSuperAdminBootstrapAdapter);
5289
5352
 
5290
5353
  // src/prisma-tenant-subscription-write.adapter.ts
5291
- var import_common29 = require("@nestjs/common");
5292
- var import_core11 = require("@saasicat/core");
5293
- function _ts_decorate29(decorators, target, key, desc) {
5354
+ var import_common30 = require("@nestjs/common");
5355
+ var import_core13 = require("@saasicat/core");
5356
+ function _ts_decorate30(decorators, target, key, desc) {
5294
5357
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5295
5358
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5296
5359
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5297
5360
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5298
5361
  }
5299
- __name(_ts_decorate29, "_ts_decorate");
5300
- function _ts_metadata28(k, v) {
5362
+ __name(_ts_decorate30, "_ts_decorate");
5363
+ function _ts_metadata29(k, v) {
5301
5364
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
5302
5365
  }
5303
- __name(_ts_metadata28, "_ts_metadata");
5304
- function _ts_param28(paramIndex, decorator) {
5366
+ __name(_ts_metadata29, "_ts_metadata");
5367
+ function _ts_param29(paramIndex, decorator) {
5305
5368
  return function(target, key) {
5306
5369
  decorator(target, key, paramIndex);
5307
5370
  };
5308
5371
  }
5309
- __name(_ts_param28, "_ts_param");
5372
+ __name(_ts_param29, "_ts_param");
5310
5373
  var PrismaTenantSubscriptionWriteAdapter = class {
5311
5374
  static {
5312
5375
  __name(this, "PrismaTenantSubscriptionWriteAdapter");
@@ -5590,9 +5653,9 @@ var PrismaTenantSubscriptionWriteAdapter = class {
5590
5653
  }
5591
5654
  async findTargetPlanVersionId(client, storagePlanId, asOf) {
5592
5655
  const activeWindow = this.schema.tenantSubscription.activeVersionSelection === "validity-window";
5593
- const activeVersionWhere = this.schema.tenantSubscription.withEndsAt ? (0, import_core11.buildActivePlanVersionWhere)(asOf, {
5656
+ const activeVersionWhere = this.schema.tenantSubscription.withEndsAt ? (0, import_core13.buildActivePlanVersionWhere)(asOf, {
5594
5657
  withEndsAt: true
5595
- }) : (0, import_core11.buildActivePlanVersionWhere)(asOf);
5658
+ }) : (0, import_core13.buildActivePlanVersionWhere)(asOf);
5596
5659
  const where = activeWindow ? {
5597
5660
  planId: storagePlanId,
5598
5661
  ...activeVersionWhere
@@ -5663,13 +5726,13 @@ var PrismaTenantSubscriptionWriteAdapter = class {
5663
5726
  }
5664
5727
  }
5665
5728
  };
5666
- PrismaTenantSubscriptionWriteAdapter = _ts_decorate29([
5667
- (0, import_common29.Injectable)(),
5668
- _ts_param28(0, (0, import_common29.Inject)(PRISMA_CLIENT_TOKEN)),
5669
- _ts_param28(1, (0, import_common29.Optional)()),
5670
- _ts_param28(1, (0, import_common29.Inject)(PRISMA_SCHEMA_OPTIONS_TOKEN)),
5671
- _ts_metadata28("design:type", Function),
5672
- _ts_metadata28("design:paramtypes", [
5729
+ PrismaTenantSubscriptionWriteAdapter = _ts_decorate30([
5730
+ (0, import_common30.Injectable)(),
5731
+ _ts_param29(0, (0, import_common30.Inject)(PRISMA_CLIENT_TOKEN)),
5732
+ _ts_param29(1, (0, import_common30.Optional)()),
5733
+ _ts_param29(1, (0, import_common30.Inject)(PRISMA_SCHEMA_OPTIONS_TOKEN)),
5734
+ _ts_metadata29("design:type", Function),
5735
+ _ts_metadata29("design:paramtypes", [
5673
5736
  typeof TransactionalPrismaClient === "undefined" ? Object : TransactionalPrismaClient,
5674
5737
  typeof PrismaSchemaOptions === "undefined" ? Object : PrismaSchemaOptions
5675
5738
  ])
@@ -5688,24 +5751,24 @@ function clearedPendingVersionData() {
5688
5751
  __name(clearedPendingVersionData, "clearedPendingVersionData");
5689
5752
 
5690
5753
  // src/prisma-transaction-runner.adapter.ts
5691
- var import_common30 = require("@nestjs/common");
5692
- function _ts_decorate30(decorators, target, key, desc) {
5754
+ var import_common31 = require("@nestjs/common");
5755
+ function _ts_decorate31(decorators, target, key, desc) {
5693
5756
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5694
5757
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5695
5758
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5696
5759
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5697
5760
  }
5698
- __name(_ts_decorate30, "_ts_decorate");
5699
- function _ts_metadata29(k, v) {
5761
+ __name(_ts_decorate31, "_ts_decorate");
5762
+ function _ts_metadata30(k, v) {
5700
5763
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
5701
5764
  }
5702
- __name(_ts_metadata29, "_ts_metadata");
5703
- function _ts_param29(paramIndex, decorator) {
5765
+ __name(_ts_metadata30, "_ts_metadata");
5766
+ function _ts_param30(paramIndex, decorator) {
5704
5767
  return function(target, key) {
5705
5768
  decorator(target, key, paramIndex);
5706
5769
  };
5707
5770
  }
5708
- __name(_ts_param29, "_ts_param");
5771
+ __name(_ts_param30, "_ts_param");
5709
5772
  var PrismaTransactionRunner = class {
5710
5773
  static {
5711
5774
  __name(this, "PrismaTransactionRunner");
@@ -5719,24 +5782,24 @@ var PrismaTransactionRunner = class {
5719
5782
  return transaction((tx) => fn(tx));
5720
5783
  }
5721
5784
  };
5722
- PrismaTransactionRunner = _ts_decorate30([
5723
- (0, import_common30.Injectable)(),
5724
- _ts_param29(0, (0, import_common30.Inject)(PRISMA_CLIENT_TOKEN)),
5725
- _ts_metadata29("design:type", Function),
5726
- _ts_metadata29("design:paramtypes", [
5785
+ PrismaTransactionRunner = _ts_decorate31([
5786
+ (0, import_common31.Injectable)(),
5787
+ _ts_param30(0, (0, import_common31.Inject)(PRISMA_CLIENT_TOKEN)),
5788
+ _ts_metadata30("design:type", Function),
5789
+ _ts_metadata30("design:paramtypes", [
5727
5790
  typeof Record === "undefined" ? Object : Record
5728
5791
  ])
5729
5792
  ], PrismaTransactionRunner);
5730
5793
 
5731
5794
  // src/zero-promo-revenue-aggregator.adapter.ts
5732
- var import_common31 = require("@nestjs/common");
5733
- function _ts_decorate31(decorators, target, key, desc) {
5795
+ var import_common32 = require("@nestjs/common");
5796
+ function _ts_decorate32(decorators, target, key, desc) {
5734
5797
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5735
5798
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5736
5799
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5737
5800
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5738
5801
  }
5739
- __name(_ts_decorate31, "_ts_decorate");
5802
+ __name(_ts_decorate32, "_ts_decorate");
5740
5803
  var ZeroPromoRevenueDeductionAggregator = class {
5741
5804
  static {
5742
5805
  __name(this, "ZeroPromoRevenueDeductionAggregator");
@@ -5745,8 +5808,8 @@ var ZeroPromoRevenueDeductionAggregator = class {
5745
5808
  return "0.00";
5746
5809
  }
5747
5810
  };
5748
- ZeroPromoRevenueDeductionAggregator = _ts_decorate31([
5749
- (0, import_common31.Injectable)()
5811
+ ZeroPromoRevenueDeductionAggregator = _ts_decorate32([
5812
+ (0, import_common32.Injectable)()
5750
5813
  ], ZeroPromoRevenueDeductionAggregator);
5751
5814
 
5752
5815
  // src/prisma-persistence.ts
@@ -5780,6 +5843,8 @@ function prismaPersistence(options) {
5780
5843
  planVersionRepository: provide((prisma) => new PrismaPlanVersionRepository(prisma, options.schema)),
5781
5844
  subscriptionContractRepository: provide((prisma) => new PrismaSubscriptionContractRepository(prisma)),
5782
5845
  subscriberRepository: provide((prisma) => new PrismaSubscriberRepository(canonical(prisma))),
5846
+ // The charges those contracts give rise to, written once each.
5847
+ subscriberLedgerRepository: provide((prisma) => new PrismaSubscriberLedgerRepository(canonical(prisma))),
5783
5848
  subscriptionBundleRepository: provide((prisma) => new PrismaSubscriptionBundleRepository(canonical(prisma))),
5784
5849
  bundleRepository: provide((prisma) => new PrismaBundleRepository(canonical(prisma), options.bundle))
5785
5850
  },
@@ -5884,6 +5949,7 @@ __name(buildProvisioning, "buildProvisioning");
5884
5949
  PrismaPromoCodeValidationLogRepository,
5885
5950
  PrismaPromoSubscriptionLookup,
5886
5951
  PrismaPromotionRepository,
5952
+ PrismaSubscriberLedgerRepository,
5887
5953
  PrismaSubscriberPaymentMethodRepository,
5888
5954
  PrismaSubscriberRepository,
5889
5955
  PrismaSubscriptionBundleRepository,