@qazuor/qzpay-drizzle 1.4.0 → 1.6.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 +297 -72
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +92 -6
- package/dist/index.d.ts +92 -6
- package/dist/index.js +292 -74
- package/dist/index.js.map +1 -1
- package/dist/schema/index.cjs +91 -55
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +1758 -445
- package/dist/schema/index.d.ts +1758 -445
- package/dist/schema/index.js +89 -56
- package/dist/schema/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -130,13 +130,13 @@ function firstOrThrow(results, entityType, id) {
|
|
|
130
130
|
}
|
|
131
131
|
async function updateWithVersionHelper(db, table, id, expectedVersion, updateData, options) {
|
|
132
132
|
const { entityType, entityId, includeSoftDeleted = false, transform } = options;
|
|
133
|
-
const { and:
|
|
133
|
+
const { and: and19, eq: eq18, isNull: isNull13 } = await import('drizzle-orm');
|
|
134
134
|
const { generateVersion: generateVersion2 } = await Promise.resolve().then(() => (init_optimistic_locking(), optimistic_locking_exports));
|
|
135
|
-
const conditions = [
|
|
135
|
+
const conditions = [eq18(table.id, id), eq18(table.version, expectedVersion)];
|
|
136
136
|
if (!includeSoftDeleted && "deletedAt" in table) {
|
|
137
137
|
conditions.push(isNull13(table.deletedAt));
|
|
138
138
|
}
|
|
139
|
-
const whereClause =
|
|
139
|
+
const whereClause = and19(...conditions);
|
|
140
140
|
if (!whereClause) {
|
|
141
141
|
throw new Error("Failed to build WHERE clause for version update");
|
|
142
142
|
}
|
|
@@ -150,7 +150,7 @@ async function updateWithVersionHelper(db, table, id, expectedVersion, updateDat
|
|
|
150
150
|
result = await db.update(table).set(dataWithVersion).where(whereClause).returning();
|
|
151
151
|
} catch (_error) {
|
|
152
152
|
try {
|
|
153
|
-
const existsQuery = await db.select().from(table).where(includeSoftDeleted ?
|
|
153
|
+
const existsQuery = await db.select().from(table).where(includeSoftDeleted ? eq18(table.id, id) : and19(eq18(table.id, id), isNull13(table.deletedAt))).limit(1);
|
|
154
154
|
if (existsQuery.length > 0) {
|
|
155
155
|
throw new exports.QZPayOptimisticLockError(entityType, entityId);
|
|
156
156
|
}
|
|
@@ -159,7 +159,7 @@ async function updateWithVersionHelper(db, table, id, expectedVersion, updateDat
|
|
|
159
159
|
throw new exports.QZPayEntityNotFoundError(entityType, entityId);
|
|
160
160
|
}
|
|
161
161
|
if (result.length === 0) {
|
|
162
|
-
const existsQuery = await db.select().from(table).where(includeSoftDeleted ?
|
|
162
|
+
const existsQuery = await db.select().from(table).where(includeSoftDeleted ? eq18(table.id, id) : and19(eq18(table.id, id), isNull13(table.deletedAt))).limit(1);
|
|
163
163
|
if (existsQuery.length > 0) {
|
|
164
164
|
throw new exports.QZPayOptimisticLockError(entityType, entityId);
|
|
165
165
|
}
|
|
@@ -319,6 +319,69 @@ function mapCoreSubscriptionAddonUpdateToDrizzle(update) {
|
|
|
319
319
|
return result;
|
|
320
320
|
}
|
|
321
321
|
|
|
322
|
+
// src/mappers/checkout.mapper.ts
|
|
323
|
+
function mapDrizzleCheckoutToCore(drizzle3) {
|
|
324
|
+
return {
|
|
325
|
+
id: drizzle3.id,
|
|
326
|
+
customerId: drizzle3.customerId ?? null,
|
|
327
|
+
customerEmail: drizzle3.customerEmail ?? null,
|
|
328
|
+
mode: drizzle3.mode,
|
|
329
|
+
status: drizzle3.status,
|
|
330
|
+
currency: drizzle3.currency,
|
|
331
|
+
lineItems: drizzle3.lineItems ?? [],
|
|
332
|
+
successUrl: drizzle3.successUrl,
|
|
333
|
+
cancelUrl: drizzle3.cancelUrl,
|
|
334
|
+
expiresAt: drizzle3.expiresAt,
|
|
335
|
+
paymentId: drizzle3.paymentId ?? null,
|
|
336
|
+
subscriptionId: drizzle3.subscriptionId ?? null,
|
|
337
|
+
providerSessionIds: drizzle3.providerSessionIds ?? {},
|
|
338
|
+
metadata: drizzle3.metadata ?? {},
|
|
339
|
+
livemode: drizzle3.livemode,
|
|
340
|
+
createdAt: drizzle3.createdAt,
|
|
341
|
+
completedAt: drizzle3.completedAt ?? null
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
function mapCoreCheckoutToDrizzle(session) {
|
|
345
|
+
return {
|
|
346
|
+
id: session.id,
|
|
347
|
+
customerId: session.customerId ?? null,
|
|
348
|
+
customerEmail: session.customerEmail ?? null,
|
|
349
|
+
mode: session.mode,
|
|
350
|
+
status: session.status,
|
|
351
|
+
currency: session.currency,
|
|
352
|
+
lineItems: session.lineItems,
|
|
353
|
+
successUrl: session.successUrl,
|
|
354
|
+
cancelUrl: session.cancelUrl,
|
|
355
|
+
expiresAt: session.expiresAt,
|
|
356
|
+
paymentId: session.paymentId ?? null,
|
|
357
|
+
subscriptionId: session.subscriptionId ?? null,
|
|
358
|
+
providerSessionIds: session.providerSessionIds,
|
|
359
|
+
metadata: session.metadata,
|
|
360
|
+
livemode: session.livemode,
|
|
361
|
+
createdAt: session.createdAt,
|
|
362
|
+
completedAt: session.completedAt ?? null
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
function mapCoreCheckoutUpdateToDrizzle(input) {
|
|
366
|
+
const update = {};
|
|
367
|
+
if (input.customerId !== void 0) update.customerId = input.customerId;
|
|
368
|
+
if (input.customerEmail !== void 0) update.customerEmail = input.customerEmail;
|
|
369
|
+
if (input.mode !== void 0) update.mode = input.mode;
|
|
370
|
+
if (input.status !== void 0) update.status = input.status;
|
|
371
|
+
if (input.currency !== void 0) update.currency = input.currency;
|
|
372
|
+
if (input.lineItems !== void 0) update.lineItems = input.lineItems;
|
|
373
|
+
if (input.successUrl !== void 0) update.successUrl = input.successUrl;
|
|
374
|
+
if (input.cancelUrl !== void 0) update.cancelUrl = input.cancelUrl;
|
|
375
|
+
if (input.expiresAt !== void 0) update.expiresAt = input.expiresAt;
|
|
376
|
+
if (input.paymentId !== void 0) update.paymentId = input.paymentId;
|
|
377
|
+
if (input.subscriptionId !== void 0) update.subscriptionId = input.subscriptionId;
|
|
378
|
+
if (input.providerSessionIds !== void 0) update.providerSessionIds = input.providerSessionIds;
|
|
379
|
+
if (input.metadata !== void 0) update.metadata = input.metadata;
|
|
380
|
+
if (input.livemode !== void 0) update.livemode = input.livemode;
|
|
381
|
+
if (input.completedAt !== void 0) update.completedAt = input.completedAt;
|
|
382
|
+
return update;
|
|
383
|
+
}
|
|
384
|
+
|
|
322
385
|
// src/mappers/customer.mapper.ts
|
|
323
386
|
function mapDrizzleCustomerToCore(drizzle3) {
|
|
324
387
|
const providerCustomerIds = {};
|
|
@@ -1078,7 +1141,7 @@ function mapDrizzleSubscriptionToCore(drizzle3) {
|
|
|
1078
1141
|
};
|
|
1079
1142
|
}
|
|
1080
1143
|
function mapCoreSubscriptionCreateToDrizzle(input, defaults) {
|
|
1081
|
-
|
|
1144
|
+
const insert = {
|
|
1082
1145
|
id: input.id,
|
|
1083
1146
|
customerId: input.customerId,
|
|
1084
1147
|
planId: input.planId,
|
|
@@ -1093,6 +1156,17 @@ function mapCoreSubscriptionCreateToDrizzle(input, defaults) {
|
|
|
1093
1156
|
metadata: input.metadata ?? {},
|
|
1094
1157
|
livemode: defaults.livemode
|
|
1095
1158
|
};
|
|
1159
|
+
if (input.providerSubscriptionIds) {
|
|
1160
|
+
const stripeId = input.providerSubscriptionIds["stripe"];
|
|
1161
|
+
const mpId = input.providerSubscriptionIds["mercadopago"];
|
|
1162
|
+
if (stripeId !== void 0) {
|
|
1163
|
+
insert.stripeSubscriptionId = stripeId;
|
|
1164
|
+
}
|
|
1165
|
+
if (mpId !== void 0) {
|
|
1166
|
+
insert.mpSubscriptionId = mpId;
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
return insert;
|
|
1096
1170
|
}
|
|
1097
1171
|
function mapCoreSubscriptionUpdateToDrizzle(input) {
|
|
1098
1172
|
const update = {};
|
|
@@ -1120,6 +1194,16 @@ function mapCoreSubscriptionUpdateToDrizzle(input) {
|
|
|
1120
1194
|
if (input.trialEnd !== void 0) {
|
|
1121
1195
|
update.trialEnd = input.trialEnd;
|
|
1122
1196
|
}
|
|
1197
|
+
if (input.providerSubscriptionIds) {
|
|
1198
|
+
const stripeId = input.providerSubscriptionIds["stripe"];
|
|
1199
|
+
const mpId = input.providerSubscriptionIds["mercadopago"];
|
|
1200
|
+
if (stripeId !== void 0) {
|
|
1201
|
+
update.stripeSubscriptionId = stripeId;
|
|
1202
|
+
}
|
|
1203
|
+
if (mpId !== void 0) {
|
|
1204
|
+
update.mpSubscriptionId = mpId;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1123
1207
|
return update;
|
|
1124
1208
|
}
|
|
1125
1209
|
|
|
@@ -1445,6 +1529,93 @@ var billingAuditLogs = pgCore.pgTable(
|
|
|
1445
1529
|
);
|
|
1446
1530
|
var billingAuditLogInsertSchema = drizzleZod.createInsertSchema(billingAuditLogs);
|
|
1447
1531
|
var billingAuditLogSelectSchema = drizzleZod.createSelectSchema(billingAuditLogs);
|
|
1532
|
+
var billingPayments = pgCore.pgTable(
|
|
1533
|
+
"billing_payments",
|
|
1534
|
+
{
|
|
1535
|
+
id: pgCore.uuid("id").primaryKey().defaultRandom(),
|
|
1536
|
+
customerId: pgCore.uuid("customer_id").notNull().references(() => billingCustomers.id, { onDelete: "restrict" }),
|
|
1537
|
+
subscriptionId: pgCore.uuid("subscription_id").references(() => billingSubscriptions.id),
|
|
1538
|
+
invoiceId: pgCore.uuid("invoice_id"),
|
|
1539
|
+
amount: pgCore.integer("amount").notNull(),
|
|
1540
|
+
currency: pgCore.varchar("currency", { length: 3 }).notNull(),
|
|
1541
|
+
baseAmount: pgCore.integer("base_amount"),
|
|
1542
|
+
baseCurrency: pgCore.varchar("base_currency", { length: 3 }),
|
|
1543
|
+
exchangeRate: pgCore.numeric("exchange_rate", { precision: 18, scale: 8 }),
|
|
1544
|
+
status: pgCore.varchar("status", { length: 50 }).notNull(),
|
|
1545
|
+
provider: pgCore.varchar("provider", { length: 50 }).notNull(),
|
|
1546
|
+
providerPaymentIds: pgCore.jsonb("provider_payment_ids").default({}),
|
|
1547
|
+
paymentMethodId: pgCore.uuid("payment_method_id"),
|
|
1548
|
+
refundedAmount: pgCore.integer("refunded_amount").default(0),
|
|
1549
|
+
failureCode: pgCore.varchar("failure_code", { length: 100 }),
|
|
1550
|
+
failureMessage: pgCore.text("failure_message"),
|
|
1551
|
+
idempotencyKey: pgCore.varchar("idempotency_key", { length: 255 }),
|
|
1552
|
+
livemode: pgCore.boolean("livemode").notNull().default(true),
|
|
1553
|
+
metadata: pgCore.jsonb("metadata").default({}),
|
|
1554
|
+
version: pgCore.uuid("version").notNull().defaultRandom(),
|
|
1555
|
+
createdAt: pgCore.timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1556
|
+
updatedAt: pgCore.timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1557
|
+
deletedAt: pgCore.timestamp("deleted_at", { withTimezone: true })
|
|
1558
|
+
},
|
|
1559
|
+
(table) => ({
|
|
1560
|
+
customerIdx: pgCore.index("idx_payments_customer").on(table.customerId),
|
|
1561
|
+
subscriptionIdx: pgCore.index("idx_payments_subscription").on(table.subscriptionId),
|
|
1562
|
+
statusIdx: pgCore.index("idx_payments_status").on(table.status),
|
|
1563
|
+
idempotencyIdx: pgCore.index("idx_payments_idempotency").on(table.idempotencyKey)
|
|
1564
|
+
})
|
|
1565
|
+
);
|
|
1566
|
+
var billingRefunds = pgCore.pgTable(
|
|
1567
|
+
"billing_refunds",
|
|
1568
|
+
{
|
|
1569
|
+
id: pgCore.uuid("id").primaryKey().defaultRandom(),
|
|
1570
|
+
paymentId: pgCore.uuid("payment_id").notNull().references(() => billingPayments.id, { onDelete: "restrict" }),
|
|
1571
|
+
amount: pgCore.integer("amount").notNull(),
|
|
1572
|
+
currency: pgCore.varchar("currency", { length: 3 }).notNull(),
|
|
1573
|
+
status: pgCore.varchar("status", { length: 50 }).notNull(),
|
|
1574
|
+
reason: pgCore.varchar("reason", { length: 100 }),
|
|
1575
|
+
providerRefundId: pgCore.varchar("provider_refund_id", { length: 255 }),
|
|
1576
|
+
livemode: pgCore.boolean("livemode").notNull().default(true),
|
|
1577
|
+
metadata: pgCore.jsonb("metadata").default({}),
|
|
1578
|
+
createdAt: pgCore.timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
1579
|
+
},
|
|
1580
|
+
(table) => ({
|
|
1581
|
+
paymentIdx: pgCore.index("idx_refunds_payment").on(table.paymentId),
|
|
1582
|
+
providerIdIdx: pgCore.index("idx_refunds_provider_id").on(table.providerRefundId)
|
|
1583
|
+
})
|
|
1584
|
+
);
|
|
1585
|
+
var billingPaymentInsertSchema = drizzleZod.createInsertSchema(billingPayments);
|
|
1586
|
+
var billingPaymentSelectSchema = drizzleZod.createSelectSchema(billingPayments);
|
|
1587
|
+
|
|
1588
|
+
// src/schema/checkouts.schema.ts
|
|
1589
|
+
var billingCheckouts = pgCore.pgTable(
|
|
1590
|
+
"billing_checkouts",
|
|
1591
|
+
{
|
|
1592
|
+
id: pgCore.uuid("id").primaryKey().defaultRandom(),
|
|
1593
|
+
customerId: pgCore.uuid("customer_id").references(() => billingCustomers.id, { onDelete: "set null" }),
|
|
1594
|
+
customerEmail: pgCore.varchar("customer_email", { length: 255 }),
|
|
1595
|
+
mode: pgCore.varchar("mode", { length: 50 }).notNull(),
|
|
1596
|
+
status: pgCore.varchar("status", { length: 50 }).notNull(),
|
|
1597
|
+
currency: pgCore.varchar("currency", { length: 10 }).notNull(),
|
|
1598
|
+
lineItems: pgCore.jsonb("line_items").notNull().default([]),
|
|
1599
|
+
successUrl: pgCore.text("success_url").notNull(),
|
|
1600
|
+
cancelUrl: pgCore.text("cancel_url").notNull(),
|
|
1601
|
+
expiresAt: pgCore.timestamp("expires_at", { withTimezone: true }).notNull(),
|
|
1602
|
+
paymentId: pgCore.uuid("payment_id").references(() => billingPayments.id),
|
|
1603
|
+
subscriptionId: pgCore.uuid("subscription_id").references(() => billingSubscriptions.id),
|
|
1604
|
+
providerSessionIds: pgCore.jsonb("provider_session_ids").notNull().default({}),
|
|
1605
|
+
metadata: pgCore.jsonb("metadata").default({}),
|
|
1606
|
+
livemode: pgCore.boolean("livemode").notNull().default(true),
|
|
1607
|
+
createdAt: pgCore.timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1608
|
+
completedAt: pgCore.timestamp("completed_at", { withTimezone: true })
|
|
1609
|
+
},
|
|
1610
|
+
(table) => ({
|
|
1611
|
+
customerIdx: pgCore.index("idx_checkouts_customer").on(table.customerId),
|
|
1612
|
+
statusIdx: pgCore.index("idx_checkouts_status").on(table.status),
|
|
1613
|
+
customerStatusIdx: pgCore.index("idx_checkouts_customer_status").on(table.customerId, table.status),
|
|
1614
|
+
expirationIdx: pgCore.index("idx_checkouts_expiration").on(table.expiresAt)
|
|
1615
|
+
})
|
|
1616
|
+
);
|
|
1617
|
+
var billingCheckoutInsertSchema = drizzleZod.createInsertSchema(billingCheckouts);
|
|
1618
|
+
var billingCheckoutSelectSchema = drizzleZod.createSelectSchema(billingCheckouts);
|
|
1448
1619
|
var billingEntitlements = pgCore.pgTable(
|
|
1449
1620
|
"billing_entitlements",
|
|
1450
1621
|
{
|
|
@@ -1648,61 +1819,6 @@ var billingPaymentMethods = pgCore.pgTable(
|
|
|
1648
1819
|
);
|
|
1649
1820
|
var billingPaymentMethodInsertSchema = drizzleZod.createInsertSchema(billingPaymentMethods);
|
|
1650
1821
|
var billingPaymentMethodSelectSchema = drizzleZod.createSelectSchema(billingPaymentMethods);
|
|
1651
|
-
var billingPayments = pgCore.pgTable(
|
|
1652
|
-
"billing_payments",
|
|
1653
|
-
{
|
|
1654
|
-
id: pgCore.uuid("id").primaryKey().defaultRandom(),
|
|
1655
|
-
customerId: pgCore.uuid("customer_id").notNull().references(() => billingCustomers.id, { onDelete: "restrict" }),
|
|
1656
|
-
subscriptionId: pgCore.uuid("subscription_id").references(() => billingSubscriptions.id),
|
|
1657
|
-
invoiceId: pgCore.uuid("invoice_id"),
|
|
1658
|
-
amount: pgCore.integer("amount").notNull(),
|
|
1659
|
-
currency: pgCore.varchar("currency", { length: 3 }).notNull(),
|
|
1660
|
-
baseAmount: pgCore.integer("base_amount"),
|
|
1661
|
-
baseCurrency: pgCore.varchar("base_currency", { length: 3 }),
|
|
1662
|
-
exchangeRate: pgCore.numeric("exchange_rate", { precision: 18, scale: 8 }),
|
|
1663
|
-
status: pgCore.varchar("status", { length: 50 }).notNull(),
|
|
1664
|
-
provider: pgCore.varchar("provider", { length: 50 }).notNull(),
|
|
1665
|
-
providerPaymentIds: pgCore.jsonb("provider_payment_ids").default({}),
|
|
1666
|
-
paymentMethodId: pgCore.uuid("payment_method_id"),
|
|
1667
|
-
refundedAmount: pgCore.integer("refunded_amount").default(0),
|
|
1668
|
-
failureCode: pgCore.varchar("failure_code", { length: 100 }),
|
|
1669
|
-
failureMessage: pgCore.text("failure_message"),
|
|
1670
|
-
idempotencyKey: pgCore.varchar("idempotency_key", { length: 255 }),
|
|
1671
|
-
livemode: pgCore.boolean("livemode").notNull().default(true),
|
|
1672
|
-
metadata: pgCore.jsonb("metadata").default({}),
|
|
1673
|
-
version: pgCore.uuid("version").notNull().defaultRandom(),
|
|
1674
|
-
createdAt: pgCore.timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1675
|
-
updatedAt: pgCore.timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1676
|
-
deletedAt: pgCore.timestamp("deleted_at", { withTimezone: true })
|
|
1677
|
-
},
|
|
1678
|
-
(table) => ({
|
|
1679
|
-
customerIdx: pgCore.index("idx_payments_customer").on(table.customerId),
|
|
1680
|
-
subscriptionIdx: pgCore.index("idx_payments_subscription").on(table.subscriptionId),
|
|
1681
|
-
statusIdx: pgCore.index("idx_payments_status").on(table.status),
|
|
1682
|
-
idempotencyIdx: pgCore.index("idx_payments_idempotency").on(table.idempotencyKey)
|
|
1683
|
-
})
|
|
1684
|
-
);
|
|
1685
|
-
var billingRefunds = pgCore.pgTable(
|
|
1686
|
-
"billing_refunds",
|
|
1687
|
-
{
|
|
1688
|
-
id: pgCore.uuid("id").primaryKey().defaultRandom(),
|
|
1689
|
-
paymentId: pgCore.uuid("payment_id").notNull().references(() => billingPayments.id, { onDelete: "restrict" }),
|
|
1690
|
-
amount: pgCore.integer("amount").notNull(),
|
|
1691
|
-
currency: pgCore.varchar("currency", { length: 3 }).notNull(),
|
|
1692
|
-
status: pgCore.varchar("status", { length: 50 }).notNull(),
|
|
1693
|
-
reason: pgCore.varchar("reason", { length: 100 }),
|
|
1694
|
-
providerRefundId: pgCore.varchar("provider_refund_id", { length: 255 }),
|
|
1695
|
-
livemode: pgCore.boolean("livemode").notNull().default(true),
|
|
1696
|
-
metadata: pgCore.jsonb("metadata").default({}),
|
|
1697
|
-
createdAt: pgCore.timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
1698
|
-
},
|
|
1699
|
-
(table) => ({
|
|
1700
|
-
paymentIdx: pgCore.index("idx_refunds_payment").on(table.paymentId),
|
|
1701
|
-
providerIdIdx: pgCore.index("idx_refunds_provider_id").on(table.providerRefundId)
|
|
1702
|
-
})
|
|
1703
|
-
);
|
|
1704
|
-
var billingPaymentInsertSchema = drizzleZod.createInsertSchema(billingPayments);
|
|
1705
|
-
var billingPaymentSelectSchema = drizzleZod.createSelectSchema(billingPayments);
|
|
1706
1822
|
var billingPlans = pgCore.pgTable(
|
|
1707
1823
|
"billing_plans",
|
|
1708
1824
|
{
|
|
@@ -2029,6 +2145,7 @@ var qzpaySchema = {
|
|
|
2029
2145
|
billingAddons,
|
|
2030
2146
|
billingSubscriptionAddons,
|
|
2031
2147
|
billingAuditLogs,
|
|
2148
|
+
billingCheckouts,
|
|
2032
2149
|
billingCustomers,
|
|
2033
2150
|
billingCustomerEntitlements,
|
|
2034
2151
|
billingEntitlements,
|
|
@@ -2527,6 +2644,72 @@ var QZPayAuditLogsRepository = class {
|
|
|
2527
2644
|
// src/repositories/index.ts
|
|
2528
2645
|
init_base_repository();
|
|
2529
2646
|
init_base_repository();
|
|
2647
|
+
var QZPayCheckoutsRepository = class {
|
|
2648
|
+
constructor(db) {
|
|
2649
|
+
this.db = db;
|
|
2650
|
+
}
|
|
2651
|
+
/**
|
|
2652
|
+
* Find a checkout by ID.
|
|
2653
|
+
*/
|
|
2654
|
+
async findById(id) {
|
|
2655
|
+
const result = await this.db.select().from(billingCheckouts).where(drizzleOrm.eq(billingCheckouts.id, id)).limit(1);
|
|
2656
|
+
return firstOrNull(result);
|
|
2657
|
+
}
|
|
2658
|
+
/**
|
|
2659
|
+
* Insert a new checkout.
|
|
2660
|
+
*/
|
|
2661
|
+
async create(input) {
|
|
2662
|
+
const result = await this.db.insert(billingCheckouts).values(input).returning();
|
|
2663
|
+
return firstOrThrow(result, "Checkout", "new");
|
|
2664
|
+
}
|
|
2665
|
+
/**
|
|
2666
|
+
* Partial update.
|
|
2667
|
+
*/
|
|
2668
|
+
async update(id, input) {
|
|
2669
|
+
const result = await this.db.update(billingCheckouts).set(input).where(drizzleOrm.eq(billingCheckouts.id, id)).returning();
|
|
2670
|
+
return firstOrThrow(result, "Checkout", id);
|
|
2671
|
+
}
|
|
2672
|
+
/**
|
|
2673
|
+
* List all checkouts for a customer, newest first.
|
|
2674
|
+
*/
|
|
2675
|
+
async findByCustomerId(customerId, options = {}) {
|
|
2676
|
+
const { limit = 100, offset = 0, status } = options;
|
|
2677
|
+
const conditions = [drizzleOrm.eq(billingCheckouts.customerId, customerId)];
|
|
2678
|
+
if (status && status.length > 0) {
|
|
2679
|
+
conditions.push(drizzleOrm.inArray(billingCheckouts.status, status));
|
|
2680
|
+
}
|
|
2681
|
+
const countResult = await this.db.select({ count: drizzleOrm.count() }).from(billingCheckouts).where(drizzleOrm.and(...conditions));
|
|
2682
|
+
const total = countResult[0]?.count ?? 0;
|
|
2683
|
+
const data = await this.db.select().from(billingCheckouts).where(drizzleOrm.and(...conditions)).orderBy(drizzleOrm.sql`${billingCheckouts.createdAt} DESC`).limit(limit).offset(offset);
|
|
2684
|
+
return { data, total };
|
|
2685
|
+
}
|
|
2686
|
+
/**
|
|
2687
|
+
* Paginated search across all checkouts.
|
|
2688
|
+
*/
|
|
2689
|
+
async search(options) {
|
|
2690
|
+
const { customerId, status, livemode, limit = 100, offset = 0 } = options;
|
|
2691
|
+
const conditions = [];
|
|
2692
|
+
if (customerId) {
|
|
2693
|
+
conditions.push(drizzleOrm.eq(billingCheckouts.customerId, customerId));
|
|
2694
|
+
}
|
|
2695
|
+
if (status) {
|
|
2696
|
+
if (Array.isArray(status)) {
|
|
2697
|
+
conditions.push(drizzleOrm.inArray(billingCheckouts.status, status));
|
|
2698
|
+
} else {
|
|
2699
|
+
conditions.push(drizzleOrm.eq(billingCheckouts.status, status));
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
if (livemode !== void 0) {
|
|
2703
|
+
conditions.push(drizzleOrm.eq(billingCheckouts.livemode, livemode));
|
|
2704
|
+
}
|
|
2705
|
+
const where = conditions.length > 0 ? drizzleOrm.and(...conditions) : void 0;
|
|
2706
|
+
const countResult = await this.db.select({ count: drizzleOrm.count() }).from(billingCheckouts).where(where);
|
|
2707
|
+
const total = countResult[0]?.count ?? 0;
|
|
2708
|
+
const data = await this.db.select().from(billingCheckouts).where(where).orderBy(drizzleOrm.sql`${billingCheckouts.createdAt} DESC`).limit(limit).offset(offset);
|
|
2709
|
+
return { data, total };
|
|
2710
|
+
}
|
|
2711
|
+
};
|
|
2712
|
+
init_base_repository();
|
|
2530
2713
|
var QZPayCustomersRepository = class {
|
|
2531
2714
|
constructor(db) {
|
|
2532
2715
|
this.db = db;
|
|
@@ -5556,6 +5739,7 @@ var QZPayDrizzleStorageAdapter = class {
|
|
|
5556
5739
|
livemode;
|
|
5557
5740
|
// Repositories
|
|
5558
5741
|
addonsRepo;
|
|
5742
|
+
checkoutsRepo;
|
|
5559
5743
|
customersRepo;
|
|
5560
5744
|
subscriptionsRepo;
|
|
5561
5745
|
paymentsRepo;
|
|
@@ -5570,6 +5754,7 @@ var QZPayDrizzleStorageAdapter = class {
|
|
|
5570
5754
|
usageRecordsRepo;
|
|
5571
5755
|
// Storage implementations
|
|
5572
5756
|
addons;
|
|
5757
|
+
checkouts;
|
|
5573
5758
|
customers;
|
|
5574
5759
|
subscriptions;
|
|
5575
5760
|
payments;
|
|
@@ -5586,6 +5771,7 @@ var QZPayDrizzleStorageAdapter = class {
|
|
|
5586
5771
|
this.livemode = config.livemode ?? true;
|
|
5587
5772
|
const typedDb = this.db;
|
|
5588
5773
|
this.addonsRepo = new QZPayAddonsRepository(this.db);
|
|
5774
|
+
this.checkoutsRepo = new QZPayCheckoutsRepository(this.db);
|
|
5589
5775
|
this.customersRepo = new QZPayCustomersRepository(typedDb);
|
|
5590
5776
|
this.subscriptionsRepo = new QZPaySubscriptionsRepository(typedDb);
|
|
5591
5777
|
this.paymentsRepo = new QZPayPaymentsRepository(this.db);
|
|
@@ -5599,6 +5785,7 @@ var QZPayDrizzleStorageAdapter = class {
|
|
|
5599
5785
|
this.limitsRepo = new QZPayLimitsRepository(this.db);
|
|
5600
5786
|
this.usageRecordsRepo = new QZPayUsageRecordsRepository(this.db);
|
|
5601
5787
|
this.addons = this.createAddOnStorage();
|
|
5788
|
+
this.checkouts = this.createCheckoutStorage();
|
|
5602
5789
|
this.customers = this.createCustomerStorage();
|
|
5603
5790
|
this.subscriptions = this.createSubscriptionStorage();
|
|
5604
5791
|
this.payments = this.createPaymentStorage();
|
|
@@ -5659,6 +5846,37 @@ var QZPayDrizzleStorageAdapter = class {
|
|
|
5659
5846
|
}
|
|
5660
5847
|
};
|
|
5661
5848
|
}
|
|
5849
|
+
// ==================== Checkout Storage ====================
|
|
5850
|
+
createCheckoutStorage() {
|
|
5851
|
+
const repo = this.checkoutsRepo;
|
|
5852
|
+
const livemode = this.livemode;
|
|
5853
|
+
return {
|
|
5854
|
+
async create(session) {
|
|
5855
|
+
const drizzleInput = mapCoreCheckoutToDrizzle(session);
|
|
5856
|
+
const result = await repo.create(drizzleInput);
|
|
5857
|
+
return mapDrizzleCheckoutToCore(result);
|
|
5858
|
+
},
|
|
5859
|
+
async update(id, input) {
|
|
5860
|
+
const drizzleInput = mapCoreCheckoutUpdateToDrizzle(input);
|
|
5861
|
+
const result = await repo.update(id, drizzleInput);
|
|
5862
|
+
return mapDrizzleCheckoutToCore(result);
|
|
5863
|
+
},
|
|
5864
|
+
async findById(id) {
|
|
5865
|
+
const result = await repo.findById(id);
|
|
5866
|
+
return result ? mapDrizzleCheckoutToCore(result) : null;
|
|
5867
|
+
},
|
|
5868
|
+
async findByCustomerId(customerId) {
|
|
5869
|
+
const result = await repo.findByCustomerId(customerId);
|
|
5870
|
+
return result.data.map(mapDrizzleCheckoutToCore);
|
|
5871
|
+
},
|
|
5872
|
+
async list(options) {
|
|
5873
|
+
const limit = options?.limit ?? 20;
|
|
5874
|
+
const offset = options?.offset ?? 0;
|
|
5875
|
+
const result = await repo.search({ livemode, limit, offset });
|
|
5876
|
+
return toPaginatedResult(result, mapDrizzleCheckoutToCore, limit, offset);
|
|
5877
|
+
}
|
|
5878
|
+
};
|
|
5879
|
+
}
|
|
5662
5880
|
// ==================== Subscription Storage ====================
|
|
5663
5881
|
createSubscriptionStorage() {
|
|
5664
5882
|
const repo = this.subscriptionsRepo;
|
|
@@ -6260,9 +6478,9 @@ async function runMigrations(config) {
|
|
|
6260
6478
|
if (verbose) {
|
|
6261
6479
|
console.log("[QZPay] Starting database migrations...");
|
|
6262
6480
|
}
|
|
6263
|
-
const
|
|
6481
|
+
const sql19 = postgres2__default.default(connectionUrl, { max: 1 });
|
|
6264
6482
|
try {
|
|
6265
|
-
const db = postgresJs.drizzle(
|
|
6483
|
+
const db = postgresJs.drizzle(sql19);
|
|
6266
6484
|
await migrator.migrate(db, {
|
|
6267
6485
|
migrationsFolder
|
|
6268
6486
|
});
|
|
@@ -6273,14 +6491,14 @@ async function runMigrations(config) {
|
|
|
6273
6491
|
console.error("[QZPay] Migration failed:", error);
|
|
6274
6492
|
throw error;
|
|
6275
6493
|
} finally {
|
|
6276
|
-
await
|
|
6494
|
+
await sql19.end();
|
|
6277
6495
|
}
|
|
6278
6496
|
}
|
|
6279
6497
|
async function hasPendingMigrations(connectionUrl) {
|
|
6280
|
-
const
|
|
6498
|
+
const sql19 = postgres2__default.default(connectionUrl, { max: 1 });
|
|
6281
6499
|
try {
|
|
6282
|
-
postgresJs.drizzle(
|
|
6283
|
-
const result = await
|
|
6500
|
+
postgresJs.drizzle(sql19);
|
|
6501
|
+
const result = await sql19`
|
|
6284
6502
|
SELECT EXISTS (
|
|
6285
6503
|
SELECT FROM information_schema.tables
|
|
6286
6504
|
WHERE table_name = 'drizzle_migrations'
|
|
@@ -6291,24 +6509,24 @@ async function hasPendingMigrations(connectionUrl) {
|
|
|
6291
6509
|
}
|
|
6292
6510
|
return false;
|
|
6293
6511
|
} finally {
|
|
6294
|
-
await
|
|
6512
|
+
await sql19.end();
|
|
6295
6513
|
}
|
|
6296
6514
|
}
|
|
6297
6515
|
async function ensureDatabase(config) {
|
|
6298
6516
|
const { connectionUrl, databaseName } = config;
|
|
6299
|
-
const
|
|
6517
|
+
const sql19 = postgres2__default.default(connectionUrl, { max: 1 });
|
|
6300
6518
|
try {
|
|
6301
|
-
const result = await
|
|
6519
|
+
const result = await sql19`
|
|
6302
6520
|
SELECT 1 FROM pg_database WHERE datname = ${databaseName}
|
|
6303
6521
|
`;
|
|
6304
6522
|
if (result.length === 0) {
|
|
6305
|
-
await
|
|
6523
|
+
await sql19.unsafe(`CREATE DATABASE "${databaseName}"`);
|
|
6306
6524
|
console.log(`[QZPay] Created database: ${databaseName}`);
|
|
6307
6525
|
return true;
|
|
6308
6526
|
}
|
|
6309
6527
|
return false;
|
|
6310
6528
|
} finally {
|
|
6311
|
-
await
|
|
6529
|
+
await sql19.end();
|
|
6312
6530
|
}
|
|
6313
6531
|
}
|
|
6314
6532
|
|
|
@@ -6547,6 +6765,7 @@ exports.QZPAY_DRIZZLE_SCHEMA_VERSION = QZPAY_DRIZZLE_SCHEMA_VERSION;
|
|
|
6547
6765
|
exports.QZPAY_PAGINATION_DEFAULTS = QZPAY_PAGINATION_DEFAULTS;
|
|
6548
6766
|
exports.QZPayAddonsRepository = QZPayAddonsRepository;
|
|
6549
6767
|
exports.QZPayAuditLogsRepository = QZPayAuditLogsRepository;
|
|
6768
|
+
exports.QZPayCheckoutsRepository = QZPayCheckoutsRepository;
|
|
6550
6769
|
exports.QZPayCustomersRepository = QZPayCustomersRepository;
|
|
6551
6770
|
exports.QZPayDrizzleStorageAdapter = QZPayDrizzleStorageAdapter;
|
|
6552
6771
|
exports.QZPayEntitlementsRepository = QZPayEntitlementsRepository;
|
|
@@ -6571,6 +6790,9 @@ exports.billingAddonsRelations = billingAddonsRelations;
|
|
|
6571
6790
|
exports.billingAuditLogInsertSchema = billingAuditLogInsertSchema;
|
|
6572
6791
|
exports.billingAuditLogSelectSchema = billingAuditLogSelectSchema;
|
|
6573
6792
|
exports.billingAuditLogs = billingAuditLogs;
|
|
6793
|
+
exports.billingCheckoutInsertSchema = billingCheckoutInsertSchema;
|
|
6794
|
+
exports.billingCheckoutSelectSchema = billingCheckoutSelectSchema;
|
|
6795
|
+
exports.billingCheckouts = billingCheckouts;
|
|
6574
6796
|
exports.billingCustomerEntitlementInsertSchema = billingCustomerEntitlementInsertSchema;
|
|
6575
6797
|
exports.billingCustomerEntitlementSelectSchema = billingCustomerEntitlementSelectSchema;
|
|
6576
6798
|
exports.billingCustomerEntitlements = billingCustomerEntitlements;
|
|
@@ -6674,6 +6896,8 @@ exports.isSoftDeleted = isSoftDeleted;
|
|
|
6674
6896
|
exports.isTransaction = isTransaction;
|
|
6675
6897
|
exports.mapCoreAddonCreateToDrizzle = mapCoreAddonCreateToDrizzle;
|
|
6676
6898
|
exports.mapCoreAddonUpdateToDrizzle = mapCoreAddonUpdateToDrizzle;
|
|
6899
|
+
exports.mapCoreCheckoutToDrizzle = mapCoreCheckoutToDrizzle;
|
|
6900
|
+
exports.mapCoreCheckoutUpdateToDrizzle = mapCoreCheckoutUpdateToDrizzle;
|
|
6677
6901
|
exports.mapCoreCustomerCreateToDrizzle = mapCoreCustomerCreateToDrizzle;
|
|
6678
6902
|
exports.mapCoreCustomerUpdateToDrizzle = mapCoreCustomerUpdateToDrizzle;
|
|
6679
6903
|
exports.mapCoreEntitlementToDrizzle = mapCoreEntitlementToDrizzle;
|
|
@@ -6702,6 +6926,7 @@ exports.mapCoreVendorCreateToDrizzle = mapCoreVendorCreateToDrizzle;
|
|
|
6702
6926
|
exports.mapCoreVendorPayoutToDrizzle = mapCoreVendorPayoutToDrizzle;
|
|
6703
6927
|
exports.mapCoreVendorUpdateToDrizzle = mapCoreVendorUpdateToDrizzle;
|
|
6704
6928
|
exports.mapDrizzleAddonToCore = mapDrizzleAddonToCore;
|
|
6929
|
+
exports.mapDrizzleCheckoutToCore = mapDrizzleCheckoutToCore;
|
|
6705
6930
|
exports.mapDrizzleCustomerEntitlementToCore = mapDrizzleCustomerEntitlementToCore;
|
|
6706
6931
|
exports.mapDrizzleCustomerLimitToCore = mapDrizzleCustomerLimitToCore;
|
|
6707
6932
|
exports.mapDrizzleCustomerToCore = mapDrizzleCustomerToCore;
|