@qazuor/qzpay-drizzle 1.1.0 → 1.3.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
 
@@ -1276,6 +1262,7 @@ var billingPromoCodes = pgCore.pgTable(
1276
1262
  maxUses: pgCore.integer("max_uses"),
1277
1263
  usedCount: pgCore.integer("used_count").default(0),
1278
1264
  maxPerCustomer: pgCore.integer("max_per_customer").default(1),
1265
+ maxUsesPerUser: pgCore.integer("max_uses_per_user").notNull().default(1),
1279
1266
  validPlans: pgCore.text("valid_plans").array(),
1280
1267
  newCustomersOnly: pgCore.boolean("new_customers_only").default(false),
1281
1268
  existingCustomersOnly: pgCore.boolean("existing_customers_only").default(false),
@@ -1305,7 +1292,8 @@ var billingPromoCodeUsage = pgCore.pgTable(
1305
1292
  },
1306
1293
  (table) => ({
1307
1294
  codeIdx: pgCore.index("idx_promo_usage_code").on(table.promoCodeId),
1308
- customerIdx: pgCore.index("idx_promo_usage_customer").on(table.customerId)
1295
+ customerIdx: pgCore.index("idx_promo_usage_customer").on(table.customerId),
1296
+ customerPromoUnique: pgCore.uniqueIndex("promo_code_usage_customer_promo_unique").on(table.customerId, table.promoCodeId)
1309
1297
  })
1310
1298
  );
1311
1299
  var billingPromoCodeInsertSchema = drizzleZod.createInsertSchema(billingPromoCodes);
@@ -1490,7 +1478,8 @@ var billingCustomerEntitlements = pgCore.pgTable(
1490
1478
  customerIdIdx: pgCore.index("idx_customer_entitlements_customer_id").on(table.customerId),
1491
1479
  entitlementKeyIdx: pgCore.index("idx_customer_entitlements_key").on(table.entitlementKey),
1492
1480
  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)
1481
+ expiresAtIdx: pgCore.index("idx_customer_entitlements_expires_at").on(table.expiresAt),
1482
+ sourceIdx: pgCore.index("idx_customer_entitlements_source").on(table.source, table.sourceId)
1494
1483
  })
1495
1484
  );
1496
1485
  var billingCustomerEntitlementInsertSchema = drizzleZod.createInsertSchema(billingCustomerEntitlements);
@@ -1626,7 +1615,8 @@ var billingCustomerLimits = pgCore.pgTable(
1626
1615
  customerIdIdx: pgCore.index("idx_customer_limits_customer_id").on(table.customerId),
1627
1616
  limitKeyIdx: pgCore.index("idx_customer_limits_key").on(table.limitKey),
1628
1617
  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)
1618
+ resetAtIdx: pgCore.index("idx_customer_limits_reset_at").on(table.resetAt),
1619
+ sourceIdx: pgCore.index("idx_customer_limits_source").on(table.source, table.sourceId)
1630
1620
  })
1631
1621
  );
1632
1622
  var billingCustomerLimitInsertSchema = drizzleZod.createInsertSchema(billingCustomerLimits);
@@ -3501,10 +3491,7 @@ var QZPayLimitsRepository = class {
3501
3491
  * Delete a customer limit
3502
3492
  */
3503
3493
  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
- }
3494
+ await this.db.delete(billingCustomerLimits).where(drizzleOrm.and(drizzleOrm.eq(billingCustomerLimits.customerId, customerId), drizzleOrm.eq(billingCustomerLimits.limitKey, limitKey)));
3508
3495
  }
3509
3496
  /**
3510
3497
  * Delete all limits from a source
@@ -6045,6 +6032,9 @@ var QZPayDrizzleStorageAdapter = class {
6045
6032
  async revoke(customerId, entitlementKey) {
6046
6033
  await repo.revoke(customerId, entitlementKey);
6047
6034
  },
6035
+ async revokeBySource(source, sourceId) {
6036
+ return repo.revokeBySource(source, sourceId);
6037
+ },
6048
6038
  async findByCustomerId(customerId) {
6049
6039
  const result = await repo.findByCustomerId(customerId);
6050
6040
  return result.map(mapDrizzleCustomerEntitlementToCore);
@@ -6078,6 +6068,12 @@ var QZPayDrizzleStorageAdapter = class {
6078
6068
  const result = await repo.set(drizzleInput);
6079
6069
  return mapDrizzleCustomerLimitToCore(result);
6080
6070
  },
6071
+ async delete(customerId, limitKey) {
6072
+ await repo.delete(customerId, limitKey);
6073
+ },
6074
+ async deleteBySource(source, sourceId) {
6075
+ return repo.deleteBySource(source, sourceId);
6076
+ },
6081
6077
  async increment(input) {
6082
6078
  const result = await repo.increment(input.customerId, input.limitKey, input.incrementBy);
6083
6079
  return mapDrizzleCustomerLimitToCore(result);
@@ -6656,7 +6652,6 @@ exports.mapCoreCustomerCreateToDrizzle = mapCoreCustomerCreateToDrizzle;
6656
6652
  exports.mapCoreCustomerUpdateToDrizzle = mapCoreCustomerUpdateToDrizzle;
6657
6653
  exports.mapCoreEntitlementToDrizzle = mapCoreEntitlementToDrizzle;
6658
6654
  exports.mapCoreGrantEntitlementToDrizzle = mapCoreGrantEntitlementToDrizzle;
6659
- exports.mapCoreGrantEntitlementWithSourceToDrizzle = mapCoreGrantEntitlementWithSourceToDrizzle;
6660
6655
  exports.mapCoreInvoiceCreateToDrizzle = mapCoreInvoiceCreateToDrizzle;
6661
6656
  exports.mapCoreInvoiceLineCreateToDrizzle = mapCoreInvoiceLineCreateToDrizzle;
6662
6657
  exports.mapCoreInvoiceUpdateToDrizzle = mapCoreInvoiceUpdateToDrizzle;
@@ -6672,7 +6667,6 @@ exports.mapCorePriceUpdateToDrizzle = mapCorePriceUpdateToDrizzle;
6672
6667
  exports.mapCorePromoCodeCreateToDrizzle = mapCorePromoCodeCreateToDrizzle;
6673
6668
  exports.mapCorePromoCodeUpdateToDrizzle = mapCorePromoCodeUpdateToDrizzle;
6674
6669
  exports.mapCoreSetLimitToDrizzle = mapCoreSetLimitToDrizzle;
6675
- exports.mapCoreSetLimitWithSourceToDrizzle = mapCoreSetLimitWithSourceToDrizzle;
6676
6670
  exports.mapCoreSubscriptionAddonCreateToDrizzle = mapCoreSubscriptionAddonCreateToDrizzle;
6677
6671
  exports.mapCoreSubscriptionAddonUpdateToDrizzle = mapCoreSubscriptionAddonUpdateToDrizzle;
6678
6672
  exports.mapCoreSubscriptionCreateToDrizzle = mapCoreSubscriptionCreateToDrizzle;