@qazuor/qzpay-drizzle 1.5.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 +275 -71
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +80 -4
- package/dist/index.d.ts +80 -4
- package/dist/index.js +270 -73
- 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 = {};
|
|
@@ -1466,6 +1529,93 @@ var billingAuditLogs = pgCore.pgTable(
|
|
|
1466
1529
|
);
|
|
1467
1530
|
var billingAuditLogInsertSchema = drizzleZod.createInsertSchema(billingAuditLogs);
|
|
1468
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);
|
|
1469
1619
|
var billingEntitlements = pgCore.pgTable(
|
|
1470
1620
|
"billing_entitlements",
|
|
1471
1621
|
{
|
|
@@ -1669,61 +1819,6 @@ var billingPaymentMethods = pgCore.pgTable(
|
|
|
1669
1819
|
);
|
|
1670
1820
|
var billingPaymentMethodInsertSchema = drizzleZod.createInsertSchema(billingPaymentMethods);
|
|
1671
1821
|
var billingPaymentMethodSelectSchema = drizzleZod.createSelectSchema(billingPaymentMethods);
|
|
1672
|
-
var billingPayments = pgCore.pgTable(
|
|
1673
|
-
"billing_payments",
|
|
1674
|
-
{
|
|
1675
|
-
id: pgCore.uuid("id").primaryKey().defaultRandom(),
|
|
1676
|
-
customerId: pgCore.uuid("customer_id").notNull().references(() => billingCustomers.id, { onDelete: "restrict" }),
|
|
1677
|
-
subscriptionId: pgCore.uuid("subscription_id").references(() => billingSubscriptions.id),
|
|
1678
|
-
invoiceId: pgCore.uuid("invoice_id"),
|
|
1679
|
-
amount: pgCore.integer("amount").notNull(),
|
|
1680
|
-
currency: pgCore.varchar("currency", { length: 3 }).notNull(),
|
|
1681
|
-
baseAmount: pgCore.integer("base_amount"),
|
|
1682
|
-
baseCurrency: pgCore.varchar("base_currency", { length: 3 }),
|
|
1683
|
-
exchangeRate: pgCore.numeric("exchange_rate", { precision: 18, scale: 8 }),
|
|
1684
|
-
status: pgCore.varchar("status", { length: 50 }).notNull(),
|
|
1685
|
-
provider: pgCore.varchar("provider", { length: 50 }).notNull(),
|
|
1686
|
-
providerPaymentIds: pgCore.jsonb("provider_payment_ids").default({}),
|
|
1687
|
-
paymentMethodId: pgCore.uuid("payment_method_id"),
|
|
1688
|
-
refundedAmount: pgCore.integer("refunded_amount").default(0),
|
|
1689
|
-
failureCode: pgCore.varchar("failure_code", { length: 100 }),
|
|
1690
|
-
failureMessage: pgCore.text("failure_message"),
|
|
1691
|
-
idempotencyKey: pgCore.varchar("idempotency_key", { length: 255 }),
|
|
1692
|
-
livemode: pgCore.boolean("livemode").notNull().default(true),
|
|
1693
|
-
metadata: pgCore.jsonb("metadata").default({}),
|
|
1694
|
-
version: pgCore.uuid("version").notNull().defaultRandom(),
|
|
1695
|
-
createdAt: pgCore.timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1696
|
-
updatedAt: pgCore.timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1697
|
-
deletedAt: pgCore.timestamp("deleted_at", { withTimezone: true })
|
|
1698
|
-
},
|
|
1699
|
-
(table) => ({
|
|
1700
|
-
customerIdx: pgCore.index("idx_payments_customer").on(table.customerId),
|
|
1701
|
-
subscriptionIdx: pgCore.index("idx_payments_subscription").on(table.subscriptionId),
|
|
1702
|
-
statusIdx: pgCore.index("idx_payments_status").on(table.status),
|
|
1703
|
-
idempotencyIdx: pgCore.index("idx_payments_idempotency").on(table.idempotencyKey)
|
|
1704
|
-
})
|
|
1705
|
-
);
|
|
1706
|
-
var billingRefunds = pgCore.pgTable(
|
|
1707
|
-
"billing_refunds",
|
|
1708
|
-
{
|
|
1709
|
-
id: pgCore.uuid("id").primaryKey().defaultRandom(),
|
|
1710
|
-
paymentId: pgCore.uuid("payment_id").notNull().references(() => billingPayments.id, { onDelete: "restrict" }),
|
|
1711
|
-
amount: pgCore.integer("amount").notNull(),
|
|
1712
|
-
currency: pgCore.varchar("currency", { length: 3 }).notNull(),
|
|
1713
|
-
status: pgCore.varchar("status", { length: 50 }).notNull(),
|
|
1714
|
-
reason: pgCore.varchar("reason", { length: 100 }),
|
|
1715
|
-
providerRefundId: pgCore.varchar("provider_refund_id", { length: 255 }),
|
|
1716
|
-
livemode: pgCore.boolean("livemode").notNull().default(true),
|
|
1717
|
-
metadata: pgCore.jsonb("metadata").default({}),
|
|
1718
|
-
createdAt: pgCore.timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
1719
|
-
},
|
|
1720
|
-
(table) => ({
|
|
1721
|
-
paymentIdx: pgCore.index("idx_refunds_payment").on(table.paymentId),
|
|
1722
|
-
providerIdIdx: pgCore.index("idx_refunds_provider_id").on(table.providerRefundId)
|
|
1723
|
-
})
|
|
1724
|
-
);
|
|
1725
|
-
var billingPaymentInsertSchema = drizzleZod.createInsertSchema(billingPayments);
|
|
1726
|
-
var billingPaymentSelectSchema = drizzleZod.createSelectSchema(billingPayments);
|
|
1727
1822
|
var billingPlans = pgCore.pgTable(
|
|
1728
1823
|
"billing_plans",
|
|
1729
1824
|
{
|
|
@@ -2050,6 +2145,7 @@ var qzpaySchema = {
|
|
|
2050
2145
|
billingAddons,
|
|
2051
2146
|
billingSubscriptionAddons,
|
|
2052
2147
|
billingAuditLogs,
|
|
2148
|
+
billingCheckouts,
|
|
2053
2149
|
billingCustomers,
|
|
2054
2150
|
billingCustomerEntitlements,
|
|
2055
2151
|
billingEntitlements,
|
|
@@ -2548,6 +2644,72 @@ var QZPayAuditLogsRepository = class {
|
|
|
2548
2644
|
// src/repositories/index.ts
|
|
2549
2645
|
init_base_repository();
|
|
2550
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();
|
|
2551
2713
|
var QZPayCustomersRepository = class {
|
|
2552
2714
|
constructor(db) {
|
|
2553
2715
|
this.db = db;
|
|
@@ -5577,6 +5739,7 @@ var QZPayDrizzleStorageAdapter = class {
|
|
|
5577
5739
|
livemode;
|
|
5578
5740
|
// Repositories
|
|
5579
5741
|
addonsRepo;
|
|
5742
|
+
checkoutsRepo;
|
|
5580
5743
|
customersRepo;
|
|
5581
5744
|
subscriptionsRepo;
|
|
5582
5745
|
paymentsRepo;
|
|
@@ -5591,6 +5754,7 @@ var QZPayDrizzleStorageAdapter = class {
|
|
|
5591
5754
|
usageRecordsRepo;
|
|
5592
5755
|
// Storage implementations
|
|
5593
5756
|
addons;
|
|
5757
|
+
checkouts;
|
|
5594
5758
|
customers;
|
|
5595
5759
|
subscriptions;
|
|
5596
5760
|
payments;
|
|
@@ -5607,6 +5771,7 @@ var QZPayDrizzleStorageAdapter = class {
|
|
|
5607
5771
|
this.livemode = config.livemode ?? true;
|
|
5608
5772
|
const typedDb = this.db;
|
|
5609
5773
|
this.addonsRepo = new QZPayAddonsRepository(this.db);
|
|
5774
|
+
this.checkoutsRepo = new QZPayCheckoutsRepository(this.db);
|
|
5610
5775
|
this.customersRepo = new QZPayCustomersRepository(typedDb);
|
|
5611
5776
|
this.subscriptionsRepo = new QZPaySubscriptionsRepository(typedDb);
|
|
5612
5777
|
this.paymentsRepo = new QZPayPaymentsRepository(this.db);
|
|
@@ -5620,6 +5785,7 @@ var QZPayDrizzleStorageAdapter = class {
|
|
|
5620
5785
|
this.limitsRepo = new QZPayLimitsRepository(this.db);
|
|
5621
5786
|
this.usageRecordsRepo = new QZPayUsageRecordsRepository(this.db);
|
|
5622
5787
|
this.addons = this.createAddOnStorage();
|
|
5788
|
+
this.checkouts = this.createCheckoutStorage();
|
|
5623
5789
|
this.customers = this.createCustomerStorage();
|
|
5624
5790
|
this.subscriptions = this.createSubscriptionStorage();
|
|
5625
5791
|
this.payments = this.createPaymentStorage();
|
|
@@ -5680,6 +5846,37 @@ var QZPayDrizzleStorageAdapter = class {
|
|
|
5680
5846
|
}
|
|
5681
5847
|
};
|
|
5682
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
|
+
}
|
|
5683
5880
|
// ==================== Subscription Storage ====================
|
|
5684
5881
|
createSubscriptionStorage() {
|
|
5685
5882
|
const repo = this.subscriptionsRepo;
|
|
@@ -6281,9 +6478,9 @@ async function runMigrations(config) {
|
|
|
6281
6478
|
if (verbose) {
|
|
6282
6479
|
console.log("[QZPay] Starting database migrations...");
|
|
6283
6480
|
}
|
|
6284
|
-
const
|
|
6481
|
+
const sql19 = postgres2__default.default(connectionUrl, { max: 1 });
|
|
6285
6482
|
try {
|
|
6286
|
-
const db = postgresJs.drizzle(
|
|
6483
|
+
const db = postgresJs.drizzle(sql19);
|
|
6287
6484
|
await migrator.migrate(db, {
|
|
6288
6485
|
migrationsFolder
|
|
6289
6486
|
});
|
|
@@ -6294,14 +6491,14 @@ async function runMigrations(config) {
|
|
|
6294
6491
|
console.error("[QZPay] Migration failed:", error);
|
|
6295
6492
|
throw error;
|
|
6296
6493
|
} finally {
|
|
6297
|
-
await
|
|
6494
|
+
await sql19.end();
|
|
6298
6495
|
}
|
|
6299
6496
|
}
|
|
6300
6497
|
async function hasPendingMigrations(connectionUrl) {
|
|
6301
|
-
const
|
|
6498
|
+
const sql19 = postgres2__default.default(connectionUrl, { max: 1 });
|
|
6302
6499
|
try {
|
|
6303
|
-
postgresJs.drizzle(
|
|
6304
|
-
const result = await
|
|
6500
|
+
postgresJs.drizzle(sql19);
|
|
6501
|
+
const result = await sql19`
|
|
6305
6502
|
SELECT EXISTS (
|
|
6306
6503
|
SELECT FROM information_schema.tables
|
|
6307
6504
|
WHERE table_name = 'drizzle_migrations'
|
|
@@ -6312,24 +6509,24 @@ async function hasPendingMigrations(connectionUrl) {
|
|
|
6312
6509
|
}
|
|
6313
6510
|
return false;
|
|
6314
6511
|
} finally {
|
|
6315
|
-
await
|
|
6512
|
+
await sql19.end();
|
|
6316
6513
|
}
|
|
6317
6514
|
}
|
|
6318
6515
|
async function ensureDatabase(config) {
|
|
6319
6516
|
const { connectionUrl, databaseName } = config;
|
|
6320
|
-
const
|
|
6517
|
+
const sql19 = postgres2__default.default(connectionUrl, { max: 1 });
|
|
6321
6518
|
try {
|
|
6322
|
-
const result = await
|
|
6519
|
+
const result = await sql19`
|
|
6323
6520
|
SELECT 1 FROM pg_database WHERE datname = ${databaseName}
|
|
6324
6521
|
`;
|
|
6325
6522
|
if (result.length === 0) {
|
|
6326
|
-
await
|
|
6523
|
+
await sql19.unsafe(`CREATE DATABASE "${databaseName}"`);
|
|
6327
6524
|
console.log(`[QZPay] Created database: ${databaseName}`);
|
|
6328
6525
|
return true;
|
|
6329
6526
|
}
|
|
6330
6527
|
return false;
|
|
6331
6528
|
} finally {
|
|
6332
|
-
await
|
|
6529
|
+
await sql19.end();
|
|
6333
6530
|
}
|
|
6334
6531
|
}
|
|
6335
6532
|
|
|
@@ -6568,6 +6765,7 @@ exports.QZPAY_DRIZZLE_SCHEMA_VERSION = QZPAY_DRIZZLE_SCHEMA_VERSION;
|
|
|
6568
6765
|
exports.QZPAY_PAGINATION_DEFAULTS = QZPAY_PAGINATION_DEFAULTS;
|
|
6569
6766
|
exports.QZPayAddonsRepository = QZPayAddonsRepository;
|
|
6570
6767
|
exports.QZPayAuditLogsRepository = QZPayAuditLogsRepository;
|
|
6768
|
+
exports.QZPayCheckoutsRepository = QZPayCheckoutsRepository;
|
|
6571
6769
|
exports.QZPayCustomersRepository = QZPayCustomersRepository;
|
|
6572
6770
|
exports.QZPayDrizzleStorageAdapter = QZPayDrizzleStorageAdapter;
|
|
6573
6771
|
exports.QZPayEntitlementsRepository = QZPayEntitlementsRepository;
|
|
@@ -6592,6 +6790,9 @@ exports.billingAddonsRelations = billingAddonsRelations;
|
|
|
6592
6790
|
exports.billingAuditLogInsertSchema = billingAuditLogInsertSchema;
|
|
6593
6791
|
exports.billingAuditLogSelectSchema = billingAuditLogSelectSchema;
|
|
6594
6792
|
exports.billingAuditLogs = billingAuditLogs;
|
|
6793
|
+
exports.billingCheckoutInsertSchema = billingCheckoutInsertSchema;
|
|
6794
|
+
exports.billingCheckoutSelectSchema = billingCheckoutSelectSchema;
|
|
6795
|
+
exports.billingCheckouts = billingCheckouts;
|
|
6595
6796
|
exports.billingCustomerEntitlementInsertSchema = billingCustomerEntitlementInsertSchema;
|
|
6596
6797
|
exports.billingCustomerEntitlementSelectSchema = billingCustomerEntitlementSelectSchema;
|
|
6597
6798
|
exports.billingCustomerEntitlements = billingCustomerEntitlements;
|
|
@@ -6695,6 +6896,8 @@ exports.isSoftDeleted = isSoftDeleted;
|
|
|
6695
6896
|
exports.isTransaction = isTransaction;
|
|
6696
6897
|
exports.mapCoreAddonCreateToDrizzle = mapCoreAddonCreateToDrizzle;
|
|
6697
6898
|
exports.mapCoreAddonUpdateToDrizzle = mapCoreAddonUpdateToDrizzle;
|
|
6899
|
+
exports.mapCoreCheckoutToDrizzle = mapCoreCheckoutToDrizzle;
|
|
6900
|
+
exports.mapCoreCheckoutUpdateToDrizzle = mapCoreCheckoutUpdateToDrizzle;
|
|
6698
6901
|
exports.mapCoreCustomerCreateToDrizzle = mapCoreCustomerCreateToDrizzle;
|
|
6699
6902
|
exports.mapCoreCustomerUpdateToDrizzle = mapCoreCustomerUpdateToDrizzle;
|
|
6700
6903
|
exports.mapCoreEntitlementToDrizzle = mapCoreEntitlementToDrizzle;
|
|
@@ -6723,6 +6926,7 @@ exports.mapCoreVendorCreateToDrizzle = mapCoreVendorCreateToDrizzle;
|
|
|
6723
6926
|
exports.mapCoreVendorPayoutToDrizzle = mapCoreVendorPayoutToDrizzle;
|
|
6724
6927
|
exports.mapCoreVendorUpdateToDrizzle = mapCoreVendorUpdateToDrizzle;
|
|
6725
6928
|
exports.mapDrizzleAddonToCore = mapDrizzleAddonToCore;
|
|
6929
|
+
exports.mapDrizzleCheckoutToCore = mapDrizzleCheckoutToCore;
|
|
6726
6930
|
exports.mapDrizzleCustomerEntitlementToCore = mapDrizzleCustomerEntitlementToCore;
|
|
6727
6931
|
exports.mapDrizzleCustomerLimitToCore = mapDrizzleCustomerLimitToCore;
|
|
6728
6932
|
exports.mapDrizzleCustomerToCore = mapDrizzleCustomerToCore;
|