@qazuor/qzpay-drizzle 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -473,18 +473,7 @@ function mapCoreGrantEntitlementToDrizzle(input, livemode) {
473
473
  grantedAt: /* @__PURE__ */ new Date(),
474
474
  expiresAt: input.expiresAt ?? null,
475
475
  source: input.source ?? "manual",
476
- sourceId: null,
477
- livemode
478
- };
479
- }
480
- function mapCoreGrantEntitlementWithSourceToDrizzle(customerId, entitlementKey, source, sourceId, expiresAt, livemode) {
481
- return {
482
- customerId,
483
- entitlementKey,
484
- grantedAt: /* @__PURE__ */ new Date(),
485
- expiresAt,
486
- source,
487
- sourceId,
476
+ sourceId: input.sourceId ?? null,
488
477
  livemode
489
478
  };
490
479
  }
@@ -630,19 +619,7 @@ function mapCoreSetLimitToDrizzle(input, livemode) {
630
619
  currentValue: 0,
631
620
  resetAt: input.resetAt ?? null,
632
621
  source: input.source ?? "manual",
633
- sourceId: null,
634
- livemode
635
- };
636
- }
637
- function mapCoreSetLimitWithSourceToDrizzle(customerId, limitKey, maxValue, source, sourceId, resetAt, livemode) {
638
- return {
639
- customerId,
640
- limitKey,
641
- maxValue,
642
- currentValue: 0,
643
- resetAt,
644
- source,
645
- sourceId,
622
+ sourceId: input.sourceId ?? null,
646
623
  livemode
647
624
  };
648
625
  }
@@ -1134,6 +1111,15 @@ function mapCoreSubscriptionUpdateToDrizzle(input) {
1134
1111
  if (input.cancelAt !== void 0) {
1135
1112
  update.cancelAt = input.cancelAt;
1136
1113
  }
1114
+ if (input.currentPeriodStart !== void 0) {
1115
+ update.currentPeriodStart = input.currentPeriodStart;
1116
+ }
1117
+ if (input.currentPeriodEnd !== void 0) {
1118
+ update.currentPeriodEnd = input.currentPeriodEnd;
1119
+ }
1120
+ if (input.trialEnd !== void 0) {
1121
+ update.trialEnd = input.trialEnd;
1122
+ }
1137
1123
  return update;
1138
1124
  }
1139
1125
 
@@ -1490,7 +1476,8 @@ var billingCustomerEntitlements = pgCore.pgTable(
1490
1476
  customerIdIdx: pgCore.index("idx_customer_entitlements_customer_id").on(table.customerId),
1491
1477
  entitlementKeyIdx: pgCore.index("idx_customer_entitlements_key").on(table.entitlementKey),
1492
1478
  customerKeyIdx: pgCore.index("idx_customer_entitlements_customer_key").on(table.customerId, table.entitlementKey),
1493
- expiresAtIdx: pgCore.index("idx_customer_entitlements_expires_at").on(table.expiresAt)
1479
+ expiresAtIdx: pgCore.index("idx_customer_entitlements_expires_at").on(table.expiresAt),
1480
+ sourceIdx: pgCore.index("idx_customer_entitlements_source").on(table.source, table.sourceId)
1494
1481
  })
1495
1482
  );
1496
1483
  var billingCustomerEntitlementInsertSchema = drizzleZod.createInsertSchema(billingCustomerEntitlements);
@@ -1626,7 +1613,8 @@ var billingCustomerLimits = pgCore.pgTable(
1626
1613
  customerIdIdx: pgCore.index("idx_customer_limits_customer_id").on(table.customerId),
1627
1614
  limitKeyIdx: pgCore.index("idx_customer_limits_key").on(table.limitKey),
1628
1615
  customerKeyIdx: pgCore.index("idx_customer_limits_customer_key").on(table.customerId, table.limitKey),
1629
- resetAtIdx: pgCore.index("idx_customer_limits_reset_at").on(table.resetAt)
1616
+ resetAtIdx: pgCore.index("idx_customer_limits_reset_at").on(table.resetAt),
1617
+ sourceIdx: pgCore.index("idx_customer_limits_source").on(table.source, table.sourceId)
1630
1618
  })
1631
1619
  );
1632
1620
  var billingCustomerLimitInsertSchema = drizzleZod.createInsertSchema(billingCustomerLimits);
@@ -3501,10 +3489,7 @@ var QZPayLimitsRepository = class {
3501
3489
  * Delete a customer limit
3502
3490
  */
3503
3491
  async delete(customerId, limitKey) {
3504
- const result = await this.db.delete(billingCustomerLimits).where(drizzleOrm.and(drizzleOrm.eq(billingCustomerLimits.customerId, customerId), drizzleOrm.eq(billingCustomerLimits.limitKey, limitKey))).returning();
3505
- if (result.length === 0) {
3506
- throw new Error(`Customer limit not found for customer ${customerId} and key ${limitKey}`);
3507
- }
3492
+ await this.db.delete(billingCustomerLimits).where(drizzleOrm.and(drizzleOrm.eq(billingCustomerLimits.customerId, customerId), drizzleOrm.eq(billingCustomerLimits.limitKey, limitKey)));
3508
3493
  }
3509
3494
  /**
3510
3495
  * Delete all limits from a source
@@ -6045,6 +6030,9 @@ var QZPayDrizzleStorageAdapter = class {
6045
6030
  async revoke(customerId, entitlementKey) {
6046
6031
  await repo.revoke(customerId, entitlementKey);
6047
6032
  },
6033
+ async revokeBySource(source, sourceId) {
6034
+ return repo.revokeBySource(source, sourceId);
6035
+ },
6048
6036
  async findByCustomerId(customerId) {
6049
6037
  const result = await repo.findByCustomerId(customerId);
6050
6038
  return result.map(mapDrizzleCustomerEntitlementToCore);
@@ -6078,6 +6066,12 @@ var QZPayDrizzleStorageAdapter = class {
6078
6066
  const result = await repo.set(drizzleInput);
6079
6067
  return mapDrizzleCustomerLimitToCore(result);
6080
6068
  },
6069
+ async delete(customerId, limitKey) {
6070
+ await repo.delete(customerId, limitKey);
6071
+ },
6072
+ async deleteBySource(source, sourceId) {
6073
+ return repo.deleteBySource(source, sourceId);
6074
+ },
6081
6075
  async increment(input) {
6082
6076
  const result = await repo.increment(input.customerId, input.limitKey, input.incrementBy);
6083
6077
  return mapDrizzleCustomerLimitToCore(result);
@@ -6656,7 +6650,6 @@ exports.mapCoreCustomerCreateToDrizzle = mapCoreCustomerCreateToDrizzle;
6656
6650
  exports.mapCoreCustomerUpdateToDrizzle = mapCoreCustomerUpdateToDrizzle;
6657
6651
  exports.mapCoreEntitlementToDrizzle = mapCoreEntitlementToDrizzle;
6658
6652
  exports.mapCoreGrantEntitlementToDrizzle = mapCoreGrantEntitlementToDrizzle;
6659
- exports.mapCoreGrantEntitlementWithSourceToDrizzle = mapCoreGrantEntitlementWithSourceToDrizzle;
6660
6653
  exports.mapCoreInvoiceCreateToDrizzle = mapCoreInvoiceCreateToDrizzle;
6661
6654
  exports.mapCoreInvoiceLineCreateToDrizzle = mapCoreInvoiceLineCreateToDrizzle;
6662
6655
  exports.mapCoreInvoiceUpdateToDrizzle = mapCoreInvoiceUpdateToDrizzle;
@@ -6672,7 +6665,6 @@ exports.mapCorePriceUpdateToDrizzle = mapCorePriceUpdateToDrizzle;
6672
6665
  exports.mapCorePromoCodeCreateToDrizzle = mapCorePromoCodeCreateToDrizzle;
6673
6666
  exports.mapCorePromoCodeUpdateToDrizzle = mapCorePromoCodeUpdateToDrizzle;
6674
6667
  exports.mapCoreSetLimitToDrizzle = mapCoreSetLimitToDrizzle;
6675
- exports.mapCoreSetLimitWithSourceToDrizzle = mapCoreSetLimitWithSourceToDrizzle;
6676
6668
  exports.mapCoreSubscriptionAddonCreateToDrizzle = mapCoreSubscriptionAddonCreateToDrizzle;
6677
6669
  exports.mapCoreSubscriptionAddonUpdateToDrizzle = mapCoreSubscriptionAddonUpdateToDrizzle;
6678
6670
  exports.mapCoreSubscriptionCreateToDrizzle = mapCoreSubscriptionCreateToDrizzle;