@coursebuilder/adapter-drizzle 1.0.1 → 1.0.3
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/chunk-253RMSB3.js +99 -0
- package/dist/{chunk-MOV5TUON.js → chunk-5QEGBX2O.js} +52 -21
- package/dist/chunk-ORRM7KVW.js +25 -0
- package/dist/index.js +3 -1
- package/dist/lib/mysql/index.cjs +301 -175
- package/dist/lib/mysql/index.cjs.map +1 -1
- package/dist/lib/mysql/index.d.cts +518 -0
- package/dist/lib/mysql/index.d.ts +518 -0
- package/dist/lib/mysql/index.js +3 -1
- package/dist/lib/mysql/schemas/entitlements/entitlement-type.cjs +46 -0
- package/dist/lib/mysql/schemas/entitlements/entitlement-type.cjs.map +1 -0
- package/dist/lib/mysql/schemas/entitlements/entitlement-type.d.cts +60 -0
- package/dist/lib/mysql/schemas/entitlements/entitlement-type.d.ts +60 -0
- package/dist/lib/mysql/schemas/entitlements/entitlement-type.js +8 -0
- package/dist/lib/mysql/schemas/entitlements/entitlement-type.js.map +1 -0
- package/dist/lib/mysql/schemas/entitlements/entitlement.cjs +351 -0
- package/dist/lib/mysql/schemas/entitlements/entitlement.cjs.map +1 -0
- package/dist/lib/mysql/schemas/entitlements/entitlement.d.cts +210 -0
- package/dist/lib/mysql/schemas/entitlements/entitlement.d.ts +210 -0
- package/dist/lib/mysql/schemas/entitlements/entitlement.js +21 -0
- package/dist/lib/mysql/schemas/entitlements/entitlement.js.map +1 -0
- package/dist/lib/utils.d.cts +1 -1
- package/dist/lib/utils.d.ts +1 -1
- package/package.json +2 -2
- package/src/lib/mysql/index.ts +43 -14
- package/src/lib/mysql/schemas/entitlements/entitlement-type.ts +21 -0
- package/src/lib/mysql/schemas/entitlements/entitlement.ts +66 -0
package/dist/lib/mysql/index.cjs
CHANGED
|
@@ -39,8 +39,8 @@ __export(mysql_exports, {
|
|
|
39
39
|
module.exports = __toCommonJS(mysql_exports);
|
|
40
40
|
var import_slugify = __toESM(require("@sindresorhus/slugify"), 1);
|
|
41
41
|
var import_date_fns2 = require("date-fns");
|
|
42
|
-
var
|
|
43
|
-
var
|
|
42
|
+
var import_drizzle_orm43 = require("drizzle-orm");
|
|
43
|
+
var import_mysql_core49 = require("drizzle-orm/mysql-core");
|
|
44
44
|
var import_nanoid = require("nanoid");
|
|
45
45
|
var import_uuid = require("uuid");
|
|
46
46
|
|
|
@@ -198,8 +198,8 @@ var ZodIssueCode = util.arrayToEnum([
|
|
|
198
198
|
"not_finite"
|
|
199
199
|
]);
|
|
200
200
|
var quotelessJson = /* @__PURE__ */ __name((obj) => {
|
|
201
|
-
const
|
|
202
|
-
return
|
|
201
|
+
const json21 = JSON.stringify(obj, null, 2);
|
|
202
|
+
return json21.replace(/"([^"]+)":/g, "$1:");
|
|
203
203
|
}, "quotelessJson");
|
|
204
204
|
var _ZodError = class _ZodError extends Error {
|
|
205
205
|
constructor(issues) {
|
|
@@ -2318,10 +2318,10 @@ var _ZodObject = class _ZodObject extends ZodType {
|
|
|
2318
2318
|
// }) as any;
|
|
2319
2319
|
// return merged;
|
|
2320
2320
|
// }
|
|
2321
|
-
catchall(
|
|
2321
|
+
catchall(index45) {
|
|
2322
2322
|
return new _ZodObject({
|
|
2323
2323
|
...this._def,
|
|
2324
|
-
catchall:
|
|
2324
|
+
catchall: index45
|
|
2325
2325
|
});
|
|
2326
2326
|
}
|
|
2327
2327
|
pick(mask) {
|
|
@@ -2636,9 +2636,9 @@ function mergeValues(a, b) {
|
|
|
2636
2636
|
return { valid: false };
|
|
2637
2637
|
}
|
|
2638
2638
|
const newArray = [];
|
|
2639
|
-
for (let
|
|
2640
|
-
const itemA = a[
|
|
2641
|
-
const itemB = b[
|
|
2639
|
+
for (let index45 = 0; index45 < a.length; index45++) {
|
|
2640
|
+
const itemA = a[index45];
|
|
2641
|
+
const itemB = b[index45];
|
|
2642
2642
|
const sharedValue = mergeValues(itemA, itemB);
|
|
2643
2643
|
if (!sharedValue.valid) {
|
|
2644
2644
|
return { valid: false };
|
|
@@ -2850,10 +2850,10 @@ var _ZodMap = class _ZodMap extends ZodType {
|
|
|
2850
2850
|
}
|
|
2851
2851
|
const keyType = this._def.keyType;
|
|
2852
2852
|
const valueType = this._def.valueType;
|
|
2853
|
-
const pairs = [...ctx.data.entries()].map(([key, value],
|
|
2853
|
+
const pairs = [...ctx.data.entries()].map(([key, value], index45) => {
|
|
2854
2854
|
return {
|
|
2855
|
-
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [
|
|
2856
|
-
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [
|
|
2855
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index45, "key"])),
|
|
2856
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index45, "value"]))
|
|
2857
2857
|
};
|
|
2858
2858
|
});
|
|
2859
2859
|
if (ctx.common.async) {
|
|
@@ -4046,8 +4046,8 @@ var ZodIssueCode2 = util2.arrayToEnum([
|
|
|
4046
4046
|
"not_finite"
|
|
4047
4047
|
]);
|
|
4048
4048
|
var quotelessJson2 = /* @__PURE__ */ __name2((obj) => {
|
|
4049
|
-
const
|
|
4050
|
-
return
|
|
4049
|
+
const json21 = JSON.stringify(obj, null, 2);
|
|
4050
|
+
return json21.replace(/"([^"]+)":/g, "$1:");
|
|
4051
4051
|
}, "quotelessJson");
|
|
4052
4052
|
var _a;
|
|
4053
4053
|
var _ZodError2 = (_a = class extends Error {
|
|
@@ -6351,10 +6351,10 @@ var _ZodObject2 = (_a18 = class extends ZodType2 {
|
|
|
6351
6351
|
// }) as any;
|
|
6352
6352
|
// return merged;
|
|
6353
6353
|
// }
|
|
6354
|
-
catchall(
|
|
6354
|
+
catchall(index45) {
|
|
6355
6355
|
return new _a18({
|
|
6356
6356
|
...this._def,
|
|
6357
|
-
catchall:
|
|
6357
|
+
catchall: index45
|
|
6358
6358
|
});
|
|
6359
6359
|
}
|
|
6360
6360
|
pick(mask) {
|
|
@@ -6696,9 +6696,9 @@ function mergeValues2(a, b) {
|
|
|
6696
6696
|
};
|
|
6697
6697
|
}
|
|
6698
6698
|
const newArray = [];
|
|
6699
|
-
for (let
|
|
6700
|
-
const itemA = a[
|
|
6701
|
-
const itemB = b[
|
|
6699
|
+
for (let index45 = 0; index45 < a.length; index45++) {
|
|
6700
|
+
const itemA = a[index45];
|
|
6701
|
+
const itemB = b[index45];
|
|
6702
6702
|
const sharedValue = mergeValues2(itemA, itemB);
|
|
6703
6703
|
if (!sharedValue.valid) {
|
|
6704
6704
|
return {
|
|
@@ -6932,14 +6932,14 @@ var _ZodMap2 = (_a24 = class extends ZodType2 {
|
|
|
6932
6932
|
const valueType = this._def.valueType;
|
|
6933
6933
|
const pairs = [
|
|
6934
6934
|
...ctx.data.entries()
|
|
6935
|
-
].map(([key, value],
|
|
6935
|
+
].map(([key, value], index45) => {
|
|
6936
6936
|
return {
|
|
6937
6937
|
key: keyType._parse(new ParseInputLazyPath2(ctx, key, ctx.path, [
|
|
6938
|
-
|
|
6938
|
+
index45,
|
|
6939
6939
|
"key"
|
|
6940
6940
|
])),
|
|
6941
6941
|
value: valueType._parse(new ParseInputLazyPath2(ctx, value, ctx.path, [
|
|
6942
|
-
|
|
6942
|
+
index45,
|
|
6943
6943
|
"value"
|
|
6944
6944
|
]))
|
|
6945
6945
|
};
|
|
@@ -8226,7 +8226,7 @@ var priceSchema = z2.object({
|
|
|
8226
8226
|
fields: z2.record(z2.any()).default({})
|
|
8227
8227
|
});
|
|
8228
8228
|
|
|
8229
|
-
// ../core/dist/chunk-
|
|
8229
|
+
// ../core/dist/chunk-FMAXYBP4.js
|
|
8230
8230
|
var productSchema = z2.object({
|
|
8231
8231
|
id: z2.string().max(191),
|
|
8232
8232
|
organizationId: z2.string().max(191).optional().nullable(),
|
|
@@ -8235,7 +8235,8 @@ var productSchema = z2.object({
|
|
|
8235
8235
|
type: z2.enum([
|
|
8236
8236
|
"live",
|
|
8237
8237
|
"self-paced",
|
|
8238
|
-
"membership"
|
|
8238
|
+
"membership",
|
|
8239
|
+
"cohort"
|
|
8239
8240
|
]).default("self-paced"),
|
|
8240
8241
|
fields: z2.object({
|
|
8241
8242
|
body: z2.string().nullable().optional(),
|
|
@@ -8295,7 +8296,7 @@ var couponSchema = z2.object({
|
|
|
8295
8296
|
organizationId: z2.string().max(191).optional().nullable()
|
|
8296
8297
|
});
|
|
8297
8298
|
|
|
8298
|
-
// ../core/dist/chunk-
|
|
8299
|
+
// ../core/dist/chunk-MDUGHSSW.js
|
|
8299
8300
|
var purchaseSchema = z2.object({
|
|
8300
8301
|
id: z2.string().max(191),
|
|
8301
8302
|
userId: z2.string().max(191).optional().nullable(),
|
|
@@ -11464,6 +11465,108 @@ function getResourceProgressSchema(mysqlTable) {
|
|
|
11464
11465
|
}
|
|
11465
11466
|
__name(getResourceProgressSchema, "getResourceProgressSchema");
|
|
11466
11467
|
|
|
11468
|
+
// src/lib/mysql/schemas/entitlements/entitlement-type.ts
|
|
11469
|
+
var import_mysql_core47 = require("drizzle-orm/mysql-core");
|
|
11470
|
+
function getEntitlementTypesSchema(mysqlTable) {
|
|
11471
|
+
return mysqlTable("EntitlementType", {
|
|
11472
|
+
id: (0, import_mysql_core47.varchar)("id", {
|
|
11473
|
+
length: 191
|
|
11474
|
+
}).notNull().primaryKey(),
|
|
11475
|
+
name: (0, import_mysql_core47.varchar)("name", {
|
|
11476
|
+
length: 255
|
|
11477
|
+
}).notNull(),
|
|
11478
|
+
description: (0, import_mysql_core47.text)("description")
|
|
11479
|
+
}, (table) => ({
|
|
11480
|
+
uniqueName: (0, import_mysql_core47.uniqueIndex)("unique_name_idx").on(table.name)
|
|
11481
|
+
}));
|
|
11482
|
+
}
|
|
11483
|
+
__name(getEntitlementTypesSchema, "getEntitlementTypesSchema");
|
|
11484
|
+
|
|
11485
|
+
// src/lib/mysql/schemas/entitlements/entitlement.ts
|
|
11486
|
+
var import_drizzle_orm42 = require("drizzle-orm");
|
|
11487
|
+
var import_mysql_core48 = require("drizzle-orm/mysql-core");
|
|
11488
|
+
function getEntitlementsSchema(mysqlTable) {
|
|
11489
|
+
return mysqlTable("Entitlement", {
|
|
11490
|
+
id: (0, import_mysql_core48.varchar)("id", {
|
|
11491
|
+
length: 191
|
|
11492
|
+
}).notNull().primaryKey(),
|
|
11493
|
+
entitlementType: (0, import_mysql_core48.varchar)("entitlementType", {
|
|
11494
|
+
length: 255
|
|
11495
|
+
}).notNull(),
|
|
11496
|
+
userId: (0, import_mysql_core48.varchar)("userId", {
|
|
11497
|
+
length: 191
|
|
11498
|
+
}),
|
|
11499
|
+
organizationId: (0, import_mysql_core48.varchar)("organizationId", {
|
|
11500
|
+
length: 191
|
|
11501
|
+
}),
|
|
11502
|
+
organizationMembershipId: (0, import_mysql_core48.varchar)("organizationMembershipId", {
|
|
11503
|
+
length: 191
|
|
11504
|
+
}),
|
|
11505
|
+
sourceType: (0, import_mysql_core48.varchar)("sourceType", {
|
|
11506
|
+
length: 255
|
|
11507
|
+
}).notNull(),
|
|
11508
|
+
sourceId: (0, import_mysql_core48.varchar)("sourceId", {
|
|
11509
|
+
length: 191
|
|
11510
|
+
}).notNull(),
|
|
11511
|
+
metadata: (0, import_mysql_core48.json)("metadata").$type().default({}),
|
|
11512
|
+
expiresAt: (0, import_mysql_core48.timestamp)("expiresAt", {
|
|
11513
|
+
mode: "date",
|
|
11514
|
+
fsp: 3
|
|
11515
|
+
}),
|
|
11516
|
+
createdAt: (0, import_mysql_core48.timestamp)("createdAt", {
|
|
11517
|
+
mode: "date",
|
|
11518
|
+
fsp: 3
|
|
11519
|
+
}).default(import_drizzle_orm42.sql`CURRENT_TIMESTAMP(3)`).notNull(),
|
|
11520
|
+
updatedAt: (0, import_mysql_core48.timestamp)("updatedAt", {
|
|
11521
|
+
mode: "date",
|
|
11522
|
+
fsp: 3
|
|
11523
|
+
}).default(import_drizzle_orm42.sql`CURRENT_TIMESTAMP(3)`).notNull(),
|
|
11524
|
+
deletedAt: (0, import_mysql_core48.timestamp)("deletedAt", {
|
|
11525
|
+
mode: "date",
|
|
11526
|
+
fsp: 3
|
|
11527
|
+
})
|
|
11528
|
+
}, (table) => ({
|
|
11529
|
+
userIdIdx: (0, import_mysql_core48.index)("userId_idx").on(table.userId),
|
|
11530
|
+
orgIdIdx: (0, import_mysql_core48.index)("orgId_idx").on(table.organizationId),
|
|
11531
|
+
sourceIdx: (0, import_mysql_core48.index)("source_idx").on(table.sourceType, table.sourceId),
|
|
11532
|
+
typeIdx: (0, import_mysql_core48.index)("type_idx").on(table.entitlementType)
|
|
11533
|
+
}));
|
|
11534
|
+
}
|
|
11535
|
+
__name(getEntitlementsSchema, "getEntitlementsSchema");
|
|
11536
|
+
function getEntitlementRelationsSchema(mysqlTable) {
|
|
11537
|
+
const entitlements = getEntitlementsSchema(mysqlTable);
|
|
11538
|
+
const users = getUsersSchema(mysqlTable);
|
|
11539
|
+
const orgs = getOrganizationsSchema(mysqlTable);
|
|
11540
|
+
const memberships = getOrganizationMembershipsSchema(mysqlTable);
|
|
11541
|
+
return (0, import_drizzle_orm42.relations)(entitlements, ({ one }) => ({
|
|
11542
|
+
user: one(users, {
|
|
11543
|
+
fields: [
|
|
11544
|
+
entitlements.userId
|
|
11545
|
+
],
|
|
11546
|
+
references: [
|
|
11547
|
+
users.id
|
|
11548
|
+
]
|
|
11549
|
+
}),
|
|
11550
|
+
organization: one(orgs, {
|
|
11551
|
+
fields: [
|
|
11552
|
+
entitlements.organizationId
|
|
11553
|
+
],
|
|
11554
|
+
references: [
|
|
11555
|
+
orgs.id
|
|
11556
|
+
]
|
|
11557
|
+
}),
|
|
11558
|
+
membership: one(memberships, {
|
|
11559
|
+
fields: [
|
|
11560
|
+
entitlements.organizationMembershipId
|
|
11561
|
+
],
|
|
11562
|
+
references: [
|
|
11563
|
+
memberships.id
|
|
11564
|
+
]
|
|
11565
|
+
})
|
|
11566
|
+
}));
|
|
11567
|
+
}
|
|
11568
|
+
__name(getEntitlementRelationsSchema, "getEntitlementRelationsSchema");
|
|
11569
|
+
|
|
11467
11570
|
// src/lib/mysql/index.ts
|
|
11468
11571
|
var guid = (0, import_nanoid.customAlphabet)("1234567890abcdefghijklmnopqrstuvwxyz", 5);
|
|
11469
11572
|
function getCourseBuilderSchema(mysqlTable) {
|
|
@@ -11547,7 +11650,10 @@ function getCourseBuilderSchema(mysqlTable) {
|
|
|
11547
11650
|
subscription: getSubscriptionSchema(mysqlTable),
|
|
11548
11651
|
subscriptionRelations: getSubscriptionRelationsSchema(mysqlTable),
|
|
11549
11652
|
profiles: getProfilesSchema(mysqlTable),
|
|
11550
|
-
profilesRelations: getProfilesRelationsSchema(mysqlTable)
|
|
11653
|
+
profilesRelations: getProfilesRelationsSchema(mysqlTable),
|
|
11654
|
+
entitlementTypes: getEntitlementTypesSchema(mysqlTable),
|
|
11655
|
+
entitlements: getEntitlementsSchema(mysqlTable),
|
|
11656
|
+
entitlementsRelations: getEntitlementRelationsSchema(mysqlTable)
|
|
11551
11657
|
};
|
|
11552
11658
|
}
|
|
11553
11659
|
__name(getCourseBuilderSchema, "getCourseBuilderSchema");
|
|
@@ -11555,7 +11661,7 @@ function createTables(mySqlTable) {
|
|
|
11555
11661
|
return getCourseBuilderSchema(mySqlTable);
|
|
11556
11662
|
}
|
|
11557
11663
|
__name(createTables, "createTables");
|
|
11558
|
-
function mySqlDrizzleAdapter(client, tableFn =
|
|
11664
|
+
function mySqlDrizzleAdapter(client, tableFn = import_mysql_core49.mysqlTable, paymentProvider) {
|
|
11559
11665
|
const { users, accounts, sessions, verificationTokens, contentResource, contentResourceResource, contentResourceProduct, purchases: purchaseTable, purchaseUserTransfer, coupon, merchantCoupon, merchantCharge, merchantAccount, merchantPrice, merchantCustomer, merchantSession, merchantProduct, prices, products, upgradableProducts, resourceProgress, comments, organization: organizationTable, organizationMemberships: organizationMembershipTable, organizationMembershipRoles: organizationMembershipRoleTable, roles: roleTable, merchantSubscription: merchantSubscriptionTable, subscription: subscriptionTable } = createTables(tableFn);
|
|
11560
11666
|
const adapter = {
|
|
11561
11667
|
client,
|
|
@@ -11627,12 +11733,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
11627
11733
|
},
|
|
11628
11734
|
incrementCouponUsedCount: async (couponId) => {
|
|
11629
11735
|
await client.update(coupon).set({
|
|
11630
|
-
usedCount:
|
|
11631
|
-
}).where((0,
|
|
11736
|
+
usedCount: import_drizzle_orm43.sql`${coupon.usedCount} + 1`
|
|
11737
|
+
}).where((0, import_drizzle_orm43.eq)(coupon.id, couponId));
|
|
11632
11738
|
},
|
|
11633
11739
|
getExistingNonBulkValidPurchasesOfProduct: async ({ userId, productId }) => {
|
|
11634
11740
|
const existingPurchases = await client.query.purchases.findMany({
|
|
11635
|
-
where: (0,
|
|
11741
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(purchaseTable.userId, userId), productId ? (0, import_drizzle_orm43.eq)(purchaseTable.productId, productId) : void 0, (0, import_drizzle_orm43.eq)(purchaseTable.status, "Valid"), (0, import_drizzle_orm43.isNull)(purchaseTable.bulkCouponId))
|
|
11636
11742
|
});
|
|
11637
11743
|
return z.array(purchaseSchema).parse(existingPurchases);
|
|
11638
11744
|
},
|
|
@@ -11645,17 +11751,17 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
11645
11751
|
status: 1
|
|
11646
11752
|
});
|
|
11647
11753
|
return merchantCustomerSchema.parse(await client.query.merchantCustomer.findFirst({
|
|
11648
|
-
where: (0,
|
|
11754
|
+
where: (0, import_drizzle_orm43.eq)(merchantCustomer.identifier, options.identifier)
|
|
11649
11755
|
}));
|
|
11650
11756
|
},
|
|
11651
11757
|
getMerchantAccount: async (options) => {
|
|
11652
11758
|
return merchantAccountSchema.parse(await client.query.merchantAccount.findFirst({
|
|
11653
|
-
where: (0,
|
|
11759
|
+
where: (0, import_drizzle_orm43.eq)(merchantAccount.label, options.provider)
|
|
11654
11760
|
}));
|
|
11655
11761
|
},
|
|
11656
11762
|
getMerchantPriceForProductId: async (productId) => {
|
|
11657
11763
|
const merchantPriceData = await client.query.merchantPrice.findFirst({
|
|
11658
|
-
where: (0,
|
|
11764
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(merchantPrice.merchantProductId, productId), (0, import_drizzle_orm43.eq)(merchantPrice.status, 1))
|
|
11659
11765
|
});
|
|
11660
11766
|
const parsedMerchantPrice = merchantPriceSchema.safeParse(merchantPriceData);
|
|
11661
11767
|
if (!parsedMerchantPrice.success) {
|
|
@@ -11666,7 +11772,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
11666
11772
|
},
|
|
11667
11773
|
getMerchantProductForProductId: async (productId) => {
|
|
11668
11774
|
const merchantProductData = await client.query.merchantProduct.findFirst({
|
|
11669
|
-
where: (0,
|
|
11775
|
+
where: (0, import_drizzle_orm43.eq)(merchantProduct.productId, productId)
|
|
11670
11776
|
});
|
|
11671
11777
|
if (!merchantProductData)
|
|
11672
11778
|
return null;
|
|
@@ -11674,7 +11780,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
11674
11780
|
},
|
|
11675
11781
|
getMerchantCustomerForUserId: async (userId) => {
|
|
11676
11782
|
const merchantCustomerData = await client.query.merchantCustomer.findFirst({
|
|
11677
|
-
where: (0,
|
|
11783
|
+
where: (0, import_drizzle_orm43.eq)(merchantCustomer.userId, userId)
|
|
11678
11784
|
});
|
|
11679
11785
|
if (!merchantCustomerData)
|
|
11680
11786
|
return null;
|
|
@@ -11683,14 +11789,14 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
11683
11789
|
getUpgradableProducts: async (options) => {
|
|
11684
11790
|
const { upgradableFromId, upgradableToId } = options;
|
|
11685
11791
|
return z.array(upgradableProductSchema).parse(await client.query.upgradableProducts.findMany({
|
|
11686
|
-
where: (0,
|
|
11792
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(upgradableProducts.upgradableFromId, upgradableFromId), (0, import_drizzle_orm43.eq)(upgradableProducts.upgradableToId, upgradableToId))
|
|
11687
11793
|
}));
|
|
11688
11794
|
},
|
|
11689
11795
|
async availableUpgradesForProduct(purchases, productId) {
|
|
11690
11796
|
const previousPurchaseProductIds = purchases.map(({ productId: productId2 }) => productId2);
|
|
11691
11797
|
if (previousPurchaseProductIds.length > 0) {
|
|
11692
11798
|
return client.query.upgradableProducts.findMany({
|
|
11693
|
-
where: (0,
|
|
11799
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(upgradableProducts.upgradableToId, productId), (0, import_drizzle_orm43.inArray)(upgradableProducts.upgradableFromId, previousPurchaseProductIds))
|
|
11694
11800
|
});
|
|
11695
11801
|
}
|
|
11696
11802
|
return [];
|
|
@@ -11703,7 +11809,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
11703
11809
|
throw new Error("No lessonId provided");
|
|
11704
11810
|
}
|
|
11705
11811
|
let lessonProgress = await client.query.resourceProgress.findFirst({
|
|
11706
|
-
where: (0,
|
|
11812
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm43.eq)(resourceProgress.resourceId, options.lessonId))
|
|
11707
11813
|
});
|
|
11708
11814
|
const now = /* @__PURE__ */ new Date();
|
|
11709
11815
|
if (lessonProgress) {
|
|
@@ -11711,7 +11817,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
11711
11817
|
await client.update(resourceProgress).set({
|
|
11712
11818
|
completedAt: now,
|
|
11713
11819
|
updatedAt: now
|
|
11714
|
-
}).where((0,
|
|
11820
|
+
}).where((0, import_drizzle_orm43.eq)(resourceProgress.resourceId, options.lessonId));
|
|
11715
11821
|
}
|
|
11716
11822
|
} else {
|
|
11717
11823
|
await client.insert(resourceProgress).values({
|
|
@@ -11722,7 +11828,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
11722
11828
|
});
|
|
11723
11829
|
}
|
|
11724
11830
|
lessonProgress = await client.query.resourceProgress.findFirst({
|
|
11725
|
-
where: (0,
|
|
11831
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm43.eq)(resourceProgress.resourceId, options.lessonId))
|
|
11726
11832
|
});
|
|
11727
11833
|
const parsedLessonProgress = resourceProgressSchema.safeParse(lessonProgress);
|
|
11728
11834
|
if (!parsedLessonProgress.success) {
|
|
@@ -11735,7 +11841,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
11735
11841
|
if (!options.couponId && !options.code)
|
|
11736
11842
|
return null;
|
|
11737
11843
|
const couponForIdOrCode = await client.query.coupon.findFirst({
|
|
11738
|
-
where: (0,
|
|
11844
|
+
where: (0, import_drizzle_orm43.or)((0, import_drizzle_orm43.and)((0, import_drizzle_orm43.or)(options.code ? (0, import_drizzle_orm43.eq)(coupon.code, options.code) : void 0, options.couponId ? (0, import_drizzle_orm43.eq)(coupon.id, options.couponId) : void 0), (0, import_drizzle_orm43.gte)(coupon.expires, /* @__PURE__ */ new Date())), (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.or)(options.code ? (0, import_drizzle_orm43.eq)(coupon.code, options.code) : void 0, options.couponId ? (0, import_drizzle_orm43.eq)(coupon.id, options.couponId) : void 0), (0, import_drizzle_orm43.isNull)(coupon.expires))),
|
|
11739
11845
|
with: {
|
|
11740
11846
|
merchantCoupon: true
|
|
11741
11847
|
}
|
|
@@ -11762,18 +11868,18 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
11762
11868
|
} : {}
|
|
11763
11869
|
});
|
|
11764
11870
|
return MerchantSessionSchema.parse(await client.query.merchantSession.findFirst({
|
|
11765
|
-
where: (0,
|
|
11871
|
+
where: (0, import_drizzle_orm43.eq)(merchantSession.id, id)
|
|
11766
11872
|
}));
|
|
11767
11873
|
},
|
|
11768
11874
|
async createMerchantChargeAndPurchase(options) {
|
|
11769
11875
|
const purchaseId = await client.transaction(async (trx) => {
|
|
11770
11876
|
try {
|
|
11771
|
-
const { userId, stripeChargeId, stripeCouponId, merchantAccountId, merchantProductId, merchantCustomerId, productId, stripeChargeAmount, quantity = 1, checkoutSessionId, appliedPPPStripeCouponId, upgradedFromPurchaseId, country, usedCouponId } = options;
|
|
11877
|
+
const { userId, stripeChargeId, stripeCouponId, merchantAccountId, merchantProductId, merchantCustomerId, productId, stripeChargeAmount, quantity = 1, checkoutSessionId, appliedPPPStripeCouponId, upgradedFromPurchaseId, country, usedCouponId, organizationId } = options;
|
|
11772
11878
|
const existingMerchantCharge = merchantChargeSchema.nullable().parse(await client.query.merchantCharge.findFirst({
|
|
11773
|
-
where: (0,
|
|
11879
|
+
where: (0, import_drizzle_orm43.eq)(merchantCharge.identifier, stripeChargeId)
|
|
11774
11880
|
}) || null);
|
|
11775
11881
|
const existingPurchaseForCharge = existingMerchantCharge ? await client.query.purchases.findFirst({
|
|
11776
|
-
where: (0,
|
|
11882
|
+
where: (0, import_drizzle_orm43.eq)(purchaseTable.merchantChargeId, existingMerchantCharge.id),
|
|
11777
11883
|
with: {
|
|
11778
11884
|
user: true,
|
|
11779
11885
|
product: true,
|
|
@@ -11794,12 +11900,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
11794
11900
|
merchantCustomerId
|
|
11795
11901
|
});
|
|
11796
11902
|
const existingPurchase = purchaseSchema.nullable().parse(await client.query.purchases.findFirst({
|
|
11797
|
-
where: (0,
|
|
11903
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(purchaseTable.productId, productId), (0, import_drizzle_orm43.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm43.inArray)(purchaseTable.status, [
|
|
11798
11904
|
"Valid",
|
|
11799
11905
|
"Restricted"
|
|
11800
11906
|
]))
|
|
11801
11907
|
}) || null);
|
|
11802
|
-
const existingBulkCoupon = couponSchema.nullable().parse(await client.select().from(coupon).leftJoin(purchaseTable, (0,
|
|
11908
|
+
const existingBulkCoupon = couponSchema.nullable().parse(await client.select().from(coupon).leftJoin(purchaseTable, (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(coupon.id, purchaseTable.bulkCouponId), (0, import_drizzle_orm43.eq)(purchaseTable.userId, userId))).where((0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(coupon.restrictedToProductId, productId), (0, import_drizzle_orm43.eq)(purchaseTable.userId, userId))).then((res) => {
|
|
11803
11909
|
return res[0]?.Coupon ?? null;
|
|
11804
11910
|
}));
|
|
11805
11911
|
const isBulkPurchase = quantity > 1 || Boolean(existingBulkCoupon) || options.bulk || Boolean(existingPurchase?.status === "Valid");
|
|
@@ -11809,11 +11915,14 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
11809
11915
|
bulkCouponId = existingBulkCoupon !== null ? existingBulkCoupon.id : (0, import_uuid.v4)();
|
|
11810
11916
|
if (existingBulkCoupon !== null) {
|
|
11811
11917
|
couponToUpdate = await client.update(coupon).set({
|
|
11812
|
-
maxUses: (existingBulkCoupon?.maxUses || 0) + quantity
|
|
11813
|
-
|
|
11918
|
+
maxUses: (existingBulkCoupon?.maxUses || 0) + quantity,
|
|
11919
|
+
...organizationId ? {
|
|
11920
|
+
organizationId
|
|
11921
|
+
} : {}
|
|
11922
|
+
}).where((0, import_drizzle_orm43.eq)(coupon.id, bulkCouponId));
|
|
11814
11923
|
} else {
|
|
11815
11924
|
const merchantCouponToUse = stripeCouponId ? merchantCouponSchema.nullable().parse(await client.query.merchantCoupon.findFirst({
|
|
11816
|
-
where: (0,
|
|
11925
|
+
where: (0, import_drizzle_orm43.eq)(merchantCoupon.identifier, stripeCouponId)
|
|
11817
11926
|
})) : null;
|
|
11818
11927
|
couponToUpdate = await client.insert(coupon).values({
|
|
11819
11928
|
id: bulkCouponId,
|
|
@@ -11821,6 +11930,9 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
11821
11930
|
restrictedToProductId: productId,
|
|
11822
11931
|
maxUses: quantity,
|
|
11823
11932
|
status: 1,
|
|
11933
|
+
...organizationId ? {
|
|
11934
|
+
organizationId
|
|
11935
|
+
} : {},
|
|
11824
11936
|
...merchantCouponToUse ? {
|
|
11825
11937
|
merchantCouponId: merchantCouponToUse.id
|
|
11826
11938
|
} : {}
|
|
@@ -11834,10 +11946,10 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
11834
11946
|
merchantAccountId
|
|
11835
11947
|
});
|
|
11836
11948
|
const merchantCouponUsed = stripeCouponId ? await client.query.merchantCoupon.findFirst({
|
|
11837
|
-
where: (0,
|
|
11949
|
+
where: (0, import_drizzle_orm43.eq)(merchantCoupon.identifier, stripeCouponId)
|
|
11838
11950
|
}) : null;
|
|
11839
11951
|
const pppMerchantCoupon = appliedPPPStripeCouponId ? await client.query.merchantCoupon.findFirst({
|
|
11840
|
-
where: (0,
|
|
11952
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(merchantCoupon.identifier, appliedPPPStripeCouponId), (0, import_drizzle_orm43.eq)(merchantCoupon.type, "ppp"))
|
|
11841
11953
|
}) : null;
|
|
11842
11954
|
const newPurchaseStatus = merchantCouponUsed?.type === "ppp" || pppMerchantCoupon ? "Restricted" : "Valid";
|
|
11843
11955
|
await client.insert(purchaseTable).values({
|
|
@@ -11851,14 +11963,20 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
11851
11963
|
merchantSessionId,
|
|
11852
11964
|
country,
|
|
11853
11965
|
upgradedFromId: upgradedFromPurchaseId || null,
|
|
11854
|
-
couponId: usedCouponId || null
|
|
11966
|
+
couponId: usedCouponId || null,
|
|
11967
|
+
...organizationId ? {
|
|
11968
|
+
organizationId
|
|
11969
|
+
} : {}
|
|
11855
11970
|
});
|
|
11856
11971
|
const oneWeekInMilliseconds = 1e3 * 60 * 60 * 24 * 7;
|
|
11857
11972
|
await client.insert(purchaseUserTransfer).values({
|
|
11858
11973
|
id: `put_${(0, import_uuid.v4)()}`,
|
|
11859
11974
|
purchaseId: purchaseId2,
|
|
11860
11975
|
expiresAt: existingPurchase ? /* @__PURE__ */ new Date() : new Date(Date.now() + oneWeekInMilliseconds),
|
|
11861
|
-
sourceUserId: userId
|
|
11976
|
+
sourceUserId: userId,
|
|
11977
|
+
...organizationId ? {
|
|
11978
|
+
organizationId
|
|
11979
|
+
} : {}
|
|
11862
11980
|
});
|
|
11863
11981
|
return purchaseId2;
|
|
11864
11982
|
} catch (error) {
|
|
@@ -11868,7 +11986,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
11868
11986
|
}
|
|
11869
11987
|
});
|
|
11870
11988
|
const parsedPurchase = purchaseSchema.safeParse(await client.query.purchases.findFirst({
|
|
11871
|
-
where: (0,
|
|
11989
|
+
where: (0, import_drizzle_orm43.eq)(purchaseTable.id, purchaseId)
|
|
11872
11990
|
}));
|
|
11873
11991
|
if (!parsedPurchase.success) {
|
|
11874
11992
|
console.error("Error parsing purchase", parsedPurchase, JSON.stringify(parsedPurchase, null, 2));
|
|
@@ -11913,7 +12031,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
11913
12031
|
},
|
|
11914
12032
|
async getCoupon(couponIdOrCode) {
|
|
11915
12033
|
const loadedCoupon = await client.query.coupon.findFirst({
|
|
11916
|
-
where: (0,
|
|
12034
|
+
where: (0, import_drizzle_orm43.or)((0, import_drizzle_orm43.eq)(coupon.id, couponIdOrCode), (0, import_drizzle_orm43.eq)(coupon.code, couponIdOrCode))
|
|
11917
12035
|
}) || null;
|
|
11918
12036
|
logger.debug("loadedCoupon", {
|
|
11919
12037
|
loadedCoupon
|
|
@@ -11928,7 +12046,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
11928
12046
|
let bulkCouponPurchases;
|
|
11929
12047
|
try {
|
|
11930
12048
|
couponData = await client.query.coupon.findFirst({
|
|
11931
|
-
where: (0,
|
|
12049
|
+
where: (0, import_drizzle_orm43.eq)(coupon.id, couponId),
|
|
11932
12050
|
with: {
|
|
11933
12051
|
bulkPurchases: true,
|
|
11934
12052
|
redeemedBulkCouponPurchases: true
|
|
@@ -11940,7 +12058,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
11940
12058
|
}
|
|
11941
12059
|
try {
|
|
11942
12060
|
bulkCouponPurchases = await client.query.purchases.findMany({
|
|
11943
|
-
where: (0,
|
|
12061
|
+
where: (0, import_drizzle_orm43.eq)(purchaseTable.redeemedBulkCouponId, couponId),
|
|
11944
12062
|
with: {
|
|
11945
12063
|
user: true
|
|
11946
12064
|
}
|
|
@@ -11972,8 +12090,8 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
11972
12090
|
},
|
|
11973
12091
|
async getDefaultCoupon(productIds) {
|
|
11974
12092
|
const activeSaleCoupon = await client.query.coupon.findFirst({
|
|
11975
|
-
where: (0,
|
|
11976
|
-
orderBy: (0,
|
|
12093
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(coupon.status, 1), (0, import_drizzle_orm43.eq)(coupon.default, true), (0, import_drizzle_orm43.gte)(coupon.expires, /* @__PURE__ */ new Date()), (0, import_drizzle_orm43.or)(productIds ? (0, import_drizzle_orm43.inArray)(coupon.restrictedToProductId, productIds) : void 0, (0, import_drizzle_orm43.isNull)(coupon.restrictedToProductId))),
|
|
12094
|
+
orderBy: (0, import_drizzle_orm43.desc)(coupon.percentageDiscount),
|
|
11977
12095
|
with: {
|
|
11978
12096
|
merchantCoupon: true,
|
|
11979
12097
|
product: true
|
|
@@ -11997,7 +12115,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
11997
12115
|
},
|
|
11998
12116
|
async getLessonProgressForUser(userId) {
|
|
11999
12117
|
const userProgress = await client.query.resourceProgress.findMany({
|
|
12000
|
-
where: (0,
|
|
12118
|
+
where: (0, import_drizzle_orm43.eq)(resourceProgress.userId, userId)
|
|
12001
12119
|
});
|
|
12002
12120
|
const parsed = z.array(resourceProgressSchema).safeParse(userProgress);
|
|
12003
12121
|
if (!parsed.success) {
|
|
@@ -12008,7 +12126,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12008
12126
|
},
|
|
12009
12127
|
async getModuleProgressForUser(userIdOrEmail, moduleIdOrSlug) {
|
|
12010
12128
|
const user = await client.query.users.findFirst({
|
|
12011
|
-
where: (0,
|
|
12129
|
+
where: (0, import_drizzle_orm43.or)((0, import_drizzle_orm43.eq)(users.id, userIdOrEmail), (0, import_drizzle_orm43.eq)(users.email, userIdOrEmail)),
|
|
12012
12130
|
columns: {
|
|
12013
12131
|
id: true
|
|
12014
12132
|
}
|
|
@@ -12026,7 +12144,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12026
12144
|
resource_slug: z.string().nullable(),
|
|
12027
12145
|
completed_at: z.string().nullable().transform((val) => val ? new Date(val) : null)
|
|
12028
12146
|
});
|
|
12029
|
-
const results = await client.execute(
|
|
12147
|
+
const results = await client.execute(import_drizzle_orm43.sql`
|
|
12030
12148
|
SELECT
|
|
12031
12149
|
cr.id AS resource_id,
|
|
12032
12150
|
cr.type AS resource_type,
|
|
@@ -12107,7 +12225,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12107
12225
|
},
|
|
12108
12226
|
async getMerchantCharge(merchantChargeId) {
|
|
12109
12227
|
const mCharge = await client.query.merchantCharge.findFirst({
|
|
12110
|
-
where: (0,
|
|
12228
|
+
where: (0, import_drizzle_orm43.eq)(merchantCharge.id, merchantChargeId)
|
|
12111
12229
|
});
|
|
12112
12230
|
const parsed = merchantChargeSchema.safeParse(mCharge);
|
|
12113
12231
|
if (!parsed.success) {
|
|
@@ -12118,12 +12236,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12118
12236
|
},
|
|
12119
12237
|
async getMerchantCouponsForTypeAndPercent(params) {
|
|
12120
12238
|
return z.array(merchantCouponSchema).parse(await client.query.merchantCoupon.findMany({
|
|
12121
|
-
where: (0,
|
|
12239
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(merchantCoupon.type, params.type), (0, import_drizzle_orm43.eq)(merchantCoupon.percentageDiscount, params.percentageDiscount.toString()))
|
|
12122
12240
|
}));
|
|
12123
12241
|
},
|
|
12124
12242
|
async getMerchantCouponForTypeAndPercent(params) {
|
|
12125
12243
|
const foundMerchantCoupon = await client.query.merchantCoupon.findFirst({
|
|
12126
|
-
where: (0,
|
|
12244
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(merchantCoupon.type, params.type), (0, import_drizzle_orm43.eq)(merchantCoupon.percentageDiscount, params.percentageDiscount.toString()))
|
|
12127
12245
|
});
|
|
12128
12246
|
const parsed = merchantCouponSchema.nullable().safeParse(foundMerchantCoupon);
|
|
12129
12247
|
if (parsed.success) {
|
|
@@ -12133,7 +12251,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12133
12251
|
},
|
|
12134
12252
|
async getMerchantCoupon(merchantCouponId) {
|
|
12135
12253
|
const foundMerchantCoupon = await client.query.merchantCoupon.findFirst({
|
|
12136
|
-
where: (0,
|
|
12254
|
+
where: (0, import_drizzle_orm43.eq)(merchantCoupon.id, merchantCouponId)
|
|
12137
12255
|
});
|
|
12138
12256
|
const parsed = merchantCouponSchema.nullable().safeParse(foundMerchantCoupon);
|
|
12139
12257
|
if (parsed.success) {
|
|
@@ -12143,7 +12261,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12143
12261
|
},
|
|
12144
12262
|
async getMerchantProduct(stripeProductId) {
|
|
12145
12263
|
return merchantProductSchema.nullable().parse(await client.query.merchantProduct.findFirst({
|
|
12146
|
-
where: (0,
|
|
12264
|
+
where: (0, import_drizzle_orm43.eq)(merchantProduct.identifier, stripeProductId)
|
|
12147
12265
|
}));
|
|
12148
12266
|
},
|
|
12149
12267
|
getPrice(productId) {
|
|
@@ -12151,7 +12269,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12151
12269
|
},
|
|
12152
12270
|
async getPriceForProduct(productId) {
|
|
12153
12271
|
return priceSchema.nullable().parse(await client.query.prices.findFirst({
|
|
12154
|
-
where: (0,
|
|
12272
|
+
where: (0, import_drizzle_orm43.eq)(prices.productId, productId)
|
|
12155
12273
|
}));
|
|
12156
12274
|
},
|
|
12157
12275
|
async archiveProduct(productId) {
|
|
@@ -12167,19 +12285,19 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12167
12285
|
await client.update(products).set({
|
|
12168
12286
|
status: 0,
|
|
12169
12287
|
name: `${product.name} (Archived)`
|
|
12170
|
-
}).where((0,
|
|
12288
|
+
}).where((0, import_drizzle_orm43.eq)(products.id, productId));
|
|
12171
12289
|
await client.update(prices).set({
|
|
12172
12290
|
status: 0,
|
|
12173
12291
|
nickname: `${product.name} (Archived)`
|
|
12174
|
-
}).where((0,
|
|
12292
|
+
}).where((0, import_drizzle_orm43.eq)(prices.productId, productId));
|
|
12175
12293
|
await client.update(merchantProduct).set({
|
|
12176
12294
|
status: 0
|
|
12177
|
-
}).where((0,
|
|
12295
|
+
}).where((0, import_drizzle_orm43.eq)(merchantProduct.productId, productId));
|
|
12178
12296
|
await client.update(merchantPrice).set({
|
|
12179
12297
|
status: 0
|
|
12180
|
-
}).where((0,
|
|
12298
|
+
}).where((0, import_drizzle_orm43.eq)(merchantPrice.priceId, product.price.id));
|
|
12181
12299
|
const currentMerchantProduct = merchantProductSchema.nullish().parse(await client.query.merchantProduct.findFirst({
|
|
12182
|
-
where: (0,
|
|
12300
|
+
where: (0, import_drizzle_orm43.eq)(merchantProduct.productId, productId)
|
|
12183
12301
|
}));
|
|
12184
12302
|
if (!currentMerchantProduct || !currentMerchantProduct.identifier) {
|
|
12185
12303
|
throw new Error(`Merchant product not found for id (${productId})`);
|
|
@@ -12188,7 +12306,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12188
12306
|
active: false
|
|
12189
12307
|
});
|
|
12190
12308
|
const currentMerchantPrice = merchantPriceSchema.nullish().parse(await client.query.merchantPrice.findFirst({
|
|
12191
|
-
where: (0,
|
|
12309
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(merchantPrice.priceId, product.price.id), (0, import_drizzle_orm43.eq)(merchantPrice.status, 1))
|
|
12192
12310
|
}));
|
|
12193
12311
|
if (!currentMerchantPrice || !currentMerchantPrice.identifier) {
|
|
12194
12312
|
throw new Error(`Merchant price not found for id (${productId})`);
|
|
@@ -12248,12 +12366,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12248
12366
|
if (currentMerchantPrice) {
|
|
12249
12367
|
await client.update(merchantPrice).set({
|
|
12250
12368
|
status: 0
|
|
12251
|
-
}).where((0,
|
|
12369
|
+
}).where((0, import_drizzle_orm43.eq)(merchantPrice.id, currentMerchantPrice.id));
|
|
12252
12370
|
}
|
|
12253
12371
|
await client.update(prices).set({
|
|
12254
12372
|
unitAmount: Math.floor(Number(input.price?.unitAmount || 0)).toString(),
|
|
12255
12373
|
nickname: input.name
|
|
12256
|
-
}).where((0,
|
|
12374
|
+
}).where((0, import_drizzle_orm43.eq)(prices.id, currentProduct.price.id));
|
|
12257
12375
|
if (currentStripePrice) {
|
|
12258
12376
|
await paymentProvider.updatePrice(currentStripePrice.id, {
|
|
12259
12377
|
active: false
|
|
@@ -12281,8 +12399,9 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12281
12399
|
...image?.url && {
|
|
12282
12400
|
image
|
|
12283
12401
|
}
|
|
12284
|
-
}
|
|
12285
|
-
|
|
12402
|
+
},
|
|
12403
|
+
type: input.type
|
|
12404
|
+
}).where((0, import_drizzle_orm43.eq)(products.id, currentProduct.id));
|
|
12286
12405
|
return adapter.getProduct(currentProduct.id);
|
|
12287
12406
|
},
|
|
12288
12407
|
async createProduct(input) {
|
|
@@ -12358,7 +12477,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12358
12477
|
}
|
|
12359
12478
|
try {
|
|
12360
12479
|
const productData = await client.query.products.findFirst({
|
|
12361
|
-
where: (0,
|
|
12480
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.or)((0, import_drizzle_orm43.eq)(import_drizzle_orm43.sql`JSON_EXTRACT (${products.fields}, "$.slug")`, `${productSlugOrId}`), (0, import_drizzle_orm43.eq)(products.id, productSlugOrId))),
|
|
12362
12481
|
with: {
|
|
12363
12482
|
price: true,
|
|
12364
12483
|
...withResources && {
|
|
@@ -12387,20 +12506,20 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12387
12506
|
},
|
|
12388
12507
|
async getProductResources(productId) {
|
|
12389
12508
|
const contentResourceProductsForProduct = z.array(ContentResourceProductSchema).nullable().parse(await client.query.contentResourceProduct.findMany({
|
|
12390
|
-
where: (0,
|
|
12509
|
+
where: (0, import_drizzle_orm43.eq)(contentResourceProduct.productId, productId)
|
|
12391
12510
|
}));
|
|
12392
12511
|
if (!contentResourceProductsForProduct) {
|
|
12393
12512
|
return null;
|
|
12394
12513
|
} else {
|
|
12395
12514
|
const contentResources = z.array(ContentResourceSchema).parse(await client.query.contentResource.findMany({
|
|
12396
|
-
where: (0,
|
|
12515
|
+
where: (0, import_drizzle_orm43.inArray)(contentResource.id, contentResourceProductsForProduct.map((crp) => crp.resourceId))
|
|
12397
12516
|
}));
|
|
12398
12517
|
return contentResources;
|
|
12399
12518
|
}
|
|
12400
12519
|
},
|
|
12401
12520
|
async getPurchaseCountForProduct(productId) {
|
|
12402
12521
|
return await client.query.purchases.findMany({
|
|
12403
|
-
where: (0,
|
|
12522
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(purchaseTable.productId, productId), (0, import_drizzle_orm43.inArray)(purchaseTable.status, [
|
|
12404
12523
|
"Valid",
|
|
12405
12524
|
"Restricted"
|
|
12406
12525
|
]))
|
|
@@ -12408,7 +12527,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12408
12527
|
},
|
|
12409
12528
|
async getPurchase(purchaseId) {
|
|
12410
12529
|
const purchase = await client.query.purchases.findFirst({
|
|
12411
|
-
where: (0,
|
|
12530
|
+
where: (0, import_drizzle_orm43.eq)(purchaseTable.id, purchaseId)
|
|
12412
12531
|
});
|
|
12413
12532
|
return purchase ? purchaseSchema.parse(purchase) : null;
|
|
12414
12533
|
},
|
|
@@ -12426,14 +12545,14 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12426
12545
|
stripeChargeId
|
|
12427
12546
|
});
|
|
12428
12547
|
const chargeForPurchase = merchantChargeSchema.nullable().parse(await client.query.merchantCharge.findFirst({
|
|
12429
|
-
where: (0,
|
|
12548
|
+
where: (0, import_drizzle_orm43.eq)(merchantCharge.identifier, stripeChargeId)
|
|
12430
12549
|
}) || null);
|
|
12431
12550
|
if (!chargeForPurchase) {
|
|
12432
12551
|
logger.error(new Error(`No charge found for purchase: Stripe Charge ID: ${stripeChargeId}`));
|
|
12433
12552
|
return null;
|
|
12434
12553
|
}
|
|
12435
12554
|
const purchase = purchaseSchema.safeParse(await client.query.purchases.findFirst({
|
|
12436
|
-
where: (0,
|
|
12555
|
+
where: (0, import_drizzle_orm43.eq)(purchaseTable.merchantChargeId, chargeForPurchase.id),
|
|
12437
12556
|
with: {
|
|
12438
12557
|
user: true,
|
|
12439
12558
|
product: true,
|
|
@@ -12447,7 +12566,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12447
12566
|
},
|
|
12448
12567
|
async getPurchaseUserTransferById(options) {
|
|
12449
12568
|
const purchaseTransferData = await client.query.purchaseUserTransfer.findFirst({
|
|
12450
|
-
where: (0,
|
|
12569
|
+
where: (0, import_drizzle_orm43.eq)(purchaseUserTransfer.id, options.id),
|
|
12451
12570
|
with: {
|
|
12452
12571
|
sourceUser: true,
|
|
12453
12572
|
targetUser: true,
|
|
@@ -12462,7 +12581,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12462
12581
|
},
|
|
12463
12582
|
async getPurchaseWithUser(purchaseId) {
|
|
12464
12583
|
const purchaseData = await client.query.purchases.findFirst({
|
|
12465
|
-
where: (0,
|
|
12584
|
+
where: (0, import_drizzle_orm43.eq)(purchaseTable.id, purchaseId),
|
|
12466
12585
|
with: {
|
|
12467
12586
|
user: true
|
|
12468
12587
|
}
|
|
@@ -12486,13 +12605,13 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12486
12605
|
"Restricted"
|
|
12487
12606
|
];
|
|
12488
12607
|
const userPurchases = await client.query.purchases.findMany({
|
|
12489
|
-
where: (0,
|
|
12608
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm43.inArray)(purchaseTable.status, visiblePurchaseStates)),
|
|
12490
12609
|
with: {
|
|
12491
12610
|
user: true,
|
|
12492
12611
|
product: true,
|
|
12493
12612
|
bulkCoupon: true
|
|
12494
12613
|
},
|
|
12495
|
-
orderBy: (0,
|
|
12614
|
+
orderBy: (0, import_drizzle_orm43.asc)(purchaseTable.createdAt)
|
|
12496
12615
|
});
|
|
12497
12616
|
const parsedPurchases = z.array(purchaseSchema).safeParse(userPurchases);
|
|
12498
12617
|
if (!parsedPurchases.success) {
|
|
@@ -12508,18 +12627,18 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12508
12627
|
"Restricted"
|
|
12509
12628
|
];
|
|
12510
12629
|
const userPurchases = await client.query.purchases.findMany({
|
|
12511
|
-
where: (0,
|
|
12630
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm43.inArray)(purchaseTable.status, visiblePurchaseStates)),
|
|
12512
12631
|
with: {
|
|
12513
12632
|
user: true,
|
|
12514
12633
|
product: true,
|
|
12515
12634
|
bulkCoupon: true
|
|
12516
12635
|
},
|
|
12517
|
-
orderBy: (0,
|
|
12636
|
+
orderBy: (0, import_drizzle_orm43.asc)(purchaseTable.createdAt)
|
|
12518
12637
|
});
|
|
12519
12638
|
const parsedPurchases = z.array(purchaseSchema).safeParse(userPurchases);
|
|
12520
12639
|
const allPurchases = parsedPurchases.success ? parsedPurchases.data : [];
|
|
12521
12640
|
const thePurchase = await client.query.purchases.findFirst({
|
|
12522
|
-
where: (0,
|
|
12641
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(purchaseTable.id, purchaseId), (0, import_drizzle_orm43.eq)(purchaseTable.userId, userId)),
|
|
12523
12642
|
with: {
|
|
12524
12643
|
user: true,
|
|
12525
12644
|
product: true,
|
|
@@ -12540,7 +12659,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12540
12659
|
let availableUpgrades = [];
|
|
12541
12660
|
if (purchaseCanUpgrade) {
|
|
12542
12661
|
availableUpgrades = await client.query.upgradableProducts.findMany({
|
|
12543
|
-
where: (0,
|
|
12662
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(upgradableProducts.upgradableFromId, parsedPurchase.data.product?.id), (0, import_drizzle_orm43.not)((0, import_drizzle_orm43.inArray)(upgradableProducts.upgradableToId, allPurchases.map((p) => p.product?.id)))),
|
|
12544
12663
|
with: {
|
|
12545
12664
|
upgradableTo: true,
|
|
12546
12665
|
upgradableFrom: true
|
|
@@ -12548,10 +12667,10 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12548
12667
|
});
|
|
12549
12668
|
}
|
|
12550
12669
|
const existingPurchase = purchaseSchema.optional().nullable().parse(await client.query.purchases.findFirst({
|
|
12551
|
-
where: (0,
|
|
12670
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm43.eq)(purchaseTable.productId, parsedPurchase.data.productId), (0, import_drizzle_orm43.inArray)(purchaseTable.status, [
|
|
12552
12671
|
"Valid",
|
|
12553
12672
|
"Restricted"
|
|
12554
|
-
]), (0,
|
|
12673
|
+
]), (0, import_drizzle_orm43.isNull)(purchaseTable.bulkCouponId), (0, import_drizzle_orm43.not)((0, import_drizzle_orm43.eq)(purchaseTable.id, parsedPurchase.data.id))),
|
|
12555
12674
|
with: {
|
|
12556
12675
|
user: true,
|
|
12557
12676
|
product: true,
|
|
@@ -12566,7 +12685,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12566
12685
|
},
|
|
12567
12686
|
async getUserWithPurchasersByEmail(email) {
|
|
12568
12687
|
const user = await client.query.users.findFirst({
|
|
12569
|
-
where: (0,
|
|
12688
|
+
where: (0, import_drizzle_orm43.eq)(users.email, email.trim().toLowerCase()),
|
|
12570
12689
|
with: {
|
|
12571
12690
|
// merchantCustomer: true,
|
|
12572
12691
|
roles: {
|
|
@@ -12593,7 +12712,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12593
12712
|
},
|
|
12594
12713
|
async getUserById(userId) {
|
|
12595
12714
|
const user = await client.query.users.findFirst({
|
|
12596
|
-
where: (0,
|
|
12715
|
+
where: (0, import_drizzle_orm43.eq)(users.id, userId),
|
|
12597
12716
|
with: {
|
|
12598
12717
|
roles: {
|
|
12599
12718
|
with: {
|
|
@@ -12615,13 +12734,13 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12615
12734
|
if (userId === void 0)
|
|
12616
12735
|
return [];
|
|
12617
12736
|
const canUpgradeProducts = await client.query.upgradableProducts.findMany({
|
|
12618
|
-
where: (0,
|
|
12737
|
+
where: (0, import_drizzle_orm43.eq)(upgradableProducts.upgradableToId, bundleId)
|
|
12619
12738
|
});
|
|
12620
12739
|
const upgradableFrom = z.array(z.string()).parse(canUpgradeProducts.map((product) => {
|
|
12621
12740
|
return product.upgradableFromId;
|
|
12622
12741
|
}));
|
|
12623
12742
|
const purchases = await client.query.purchases.findMany({
|
|
12624
|
-
where: (0,
|
|
12743
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm43.inArray)(purchaseTable.productId, upgradableFrom))
|
|
12625
12744
|
});
|
|
12626
12745
|
const productsPurchased = z.array(z.string()).parse(purchases.map((purchase) => {
|
|
12627
12746
|
return purchase.productId;
|
|
@@ -12629,7 +12748,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12629
12748
|
if (productsPurchased.length === 0)
|
|
12630
12749
|
return [];
|
|
12631
12750
|
const foundPrices = await client.query.prices.findMany({
|
|
12632
|
-
where: (0,
|
|
12751
|
+
where: (0, import_drizzle_orm43.inArray)(prices.productId, productsPurchased)
|
|
12633
12752
|
});
|
|
12634
12753
|
return z.array(priceSchema).parse(foundPrices);
|
|
12635
12754
|
},
|
|
@@ -12638,14 +12757,14 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12638
12757
|
throw new Error("No lessonId provided");
|
|
12639
12758
|
}
|
|
12640
12759
|
let lessonProgress = await client.query.resourceProgress.findFirst({
|
|
12641
|
-
where: (0,
|
|
12760
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm43.eq)(resourceProgress.resourceId, options.lessonId))
|
|
12642
12761
|
});
|
|
12643
12762
|
const now = /* @__PURE__ */ new Date();
|
|
12644
12763
|
if (lessonProgress) {
|
|
12645
12764
|
await client.update(resourceProgress).set({
|
|
12646
12765
|
completedAt: lessonProgress.completedAt ? null : now,
|
|
12647
12766
|
updatedAt: now
|
|
12648
|
-
}).where((0,
|
|
12767
|
+
}).where((0, import_drizzle_orm43.eq)(resourceProgress.resourceId, options.lessonId));
|
|
12649
12768
|
} else {
|
|
12650
12769
|
await client.insert(resourceProgress).values({
|
|
12651
12770
|
userId: options.userId,
|
|
@@ -12655,7 +12774,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12655
12774
|
});
|
|
12656
12775
|
}
|
|
12657
12776
|
lessonProgress = await client.query.resourceProgress.findFirst({
|
|
12658
|
-
where: (0,
|
|
12777
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm43.eq)(resourceProgress.resourceId, options.lessonId))
|
|
12659
12778
|
});
|
|
12660
12779
|
const parsedLessonProgress = resourceProgressSchema.safeParse(lessonProgress);
|
|
12661
12780
|
if (!parsedLessonProgress.success) {
|
|
@@ -12677,7 +12796,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12677
12796
|
throw new Error("No purchase found");
|
|
12678
12797
|
await trx.update(purchaseTable).set({
|
|
12679
12798
|
userId: targetUserId
|
|
12680
|
-
}).where((0,
|
|
12799
|
+
}).where((0, import_drizzle_orm43.eq)(purchaseTable.id, purchase.id));
|
|
12681
12800
|
await trx.insert(purchaseUserTransfer).values({
|
|
12682
12801
|
id: transferId,
|
|
12683
12802
|
purchaseId: purchase.id,
|
|
@@ -12692,21 +12811,21 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12692
12811
|
if (paymentProvider && purchase.merchantChargeId) {
|
|
12693
12812
|
await trx.update(merchantCharge).set({
|
|
12694
12813
|
userId: targetUserId
|
|
12695
|
-
}).where((0,
|
|
12814
|
+
}).where((0, import_drizzle_orm43.eq)(merchantCharge.id, purchase.merchantChargeId));
|
|
12696
12815
|
const updatedMerchantCharge = await adapter.getMerchantCharge(purchase.merchantChargeId);
|
|
12697
12816
|
if (!updatedMerchantCharge)
|
|
12698
12817
|
throw new Error("No merchant charge found");
|
|
12699
12818
|
await trx.update(merchantCustomer).set({
|
|
12700
12819
|
userId: targetUserId
|
|
12701
|
-
}).where((0,
|
|
12820
|
+
}).where((0, import_drizzle_orm43.eq)(merchantCustomer.id, updatedMerchantCharge.merchantCustomerId));
|
|
12702
12821
|
const updatedMerchantCustomer = merchantCustomerSchema.parse(await client.query.merchantCustomer.findFirst({
|
|
12703
|
-
where: (0,
|
|
12822
|
+
where: (0, import_drizzle_orm43.eq)(merchantCustomer.id, updatedMerchantCharge.merchantCustomerId)
|
|
12704
12823
|
}));
|
|
12705
12824
|
const targetUser = userSchema.parse(await client.query.users.findFirst({
|
|
12706
|
-
where: (0,
|
|
12825
|
+
where: (0, import_drizzle_orm43.eq)(users.id, targetUserId)
|
|
12707
12826
|
}));
|
|
12708
12827
|
const sourceUser = userSchema.parse(await client.query.users.findFirst({
|
|
12709
|
-
where: (0,
|
|
12828
|
+
where: (0, import_drizzle_orm43.eq)(users.id, sourceUserId)
|
|
12710
12829
|
}));
|
|
12711
12830
|
await paymentProvider.updateCustomer(updatedMerchantCustomer.identifier, {
|
|
12712
12831
|
email: targetUser.email,
|
|
@@ -12733,7 +12852,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12733
12852
|
status
|
|
12734
12853
|
});
|
|
12735
12854
|
const merchantChargeForPurchase = await client.query.merchantCharge.findFirst({
|
|
12736
|
-
where: (0,
|
|
12855
|
+
where: (0, import_drizzle_orm43.or)((0, import_drizzle_orm43.eq)(merchantCharge.identifier, chargeId), (0, import_drizzle_orm43.eq)(merchantCharge.id, chargeId))
|
|
12737
12856
|
});
|
|
12738
12857
|
console.log("merchantChargeForPurchase", {
|
|
12739
12858
|
merchantChargeForPurchase
|
|
@@ -12742,15 +12861,15 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12742
12861
|
if (!parsedMerchantChargeForPurchase)
|
|
12743
12862
|
throw new Error(`no-charge-found-for-purchase ${chargeId}`);
|
|
12744
12863
|
const purchase = await client.query.purchases.findFirst({
|
|
12745
|
-
where: (0,
|
|
12864
|
+
where: (0, import_drizzle_orm43.eq)(purchaseTable.merchantChargeId, parsedMerchantChargeForPurchase.id)
|
|
12746
12865
|
});
|
|
12747
12866
|
const parsedPurchase = purchaseSchema.nullable().parse(purchase);
|
|
12748
12867
|
if (parsedPurchase) {
|
|
12749
12868
|
await client.update(purchaseTable).set({
|
|
12750
12869
|
status
|
|
12751
|
-
}).where((0,
|
|
12870
|
+
}).where((0, import_drizzle_orm43.eq)(purchaseTable.id, parsedPurchase.id));
|
|
12752
12871
|
const newPurchase = await client.query.purchases.findFirst({
|
|
12753
|
-
where: (0,
|
|
12872
|
+
where: (0, import_drizzle_orm43.eq)(purchaseTable.id, parsedPurchase.id)
|
|
12754
12873
|
});
|
|
12755
12874
|
return purchaseSchema.optional().parse(newPurchase);
|
|
12756
12875
|
} else {
|
|
@@ -12764,16 +12883,16 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12764
12883
|
async updatePurchaseUserTransferTransferState(options) {
|
|
12765
12884
|
await client.update(purchaseUserTransfer).set({
|
|
12766
12885
|
transferState: options.transferState
|
|
12767
|
-
}).where((0,
|
|
12886
|
+
}).where((0, import_drizzle_orm43.eq)(purchaseUserTransfer.id, options.id));
|
|
12768
12887
|
const purchaseUserTransferData = await client.query.purchaseUserTransfer.findFirst({
|
|
12769
|
-
where: (0,
|
|
12888
|
+
where: (0, import_drizzle_orm43.eq)(purchaseUserTransfer.id, options.id)
|
|
12770
12889
|
}) || null;
|
|
12771
12890
|
return purchaseUserTransferSchema.nullable().parse(purchaseUserTransferData);
|
|
12772
12891
|
},
|
|
12773
12892
|
addResourceToResource: async function(options) {
|
|
12774
12893
|
const { parentResourceId, childResourceId } = options;
|
|
12775
12894
|
const parentResourceData = await client.query.contentResource.findFirst({
|
|
12776
|
-
where: (0,
|
|
12895
|
+
where: (0, import_drizzle_orm43.or)((0, import_drizzle_orm43.eq)(import_drizzle_orm43.sql`JSON_EXTRACT (${contentResource.fields}, "$.slug")`, parentResourceId), (0, import_drizzle_orm43.eq)(contentResource.id, parentResourceId)),
|
|
12777
12896
|
with: {
|
|
12778
12897
|
resources: true
|
|
12779
12898
|
}
|
|
@@ -12785,7 +12904,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12785
12904
|
position: parentResource.resources?.length || 0
|
|
12786
12905
|
});
|
|
12787
12906
|
const resourceJoin = client.query.contentResourceResource.findFirst({
|
|
12788
|
-
where: (0,
|
|
12907
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(contentResourceResource.resourceOfId, parentResourceId), (0, import_drizzle_orm43.eq)(contentResourceResource.resourceId, childResourceId)),
|
|
12789
12908
|
with: {
|
|
12790
12909
|
resource: true
|
|
12791
12910
|
}
|
|
@@ -12799,28 +12918,28 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12799
12918
|
async removeResourceFromResource(options) {
|
|
12800
12919
|
const { childResourceId, parentResourceId } = options;
|
|
12801
12920
|
const resourceJoin = await client.query.contentResourceResource.findFirst({
|
|
12802
|
-
where: (0,
|
|
12921
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(contentResourceResource.resourceOfId, parentResourceId), (0, import_drizzle_orm43.eq)(contentResourceResource.resourceId, childResourceId))
|
|
12803
12922
|
});
|
|
12804
12923
|
const parsedResourceJoin = ContentResourceResourceSchema.safeParse(resourceJoin);
|
|
12805
12924
|
if (!parsedResourceJoin.success) {
|
|
12806
12925
|
return null;
|
|
12807
12926
|
}
|
|
12808
|
-
await client.delete(contentResourceResource).where((0,
|
|
12927
|
+
await client.delete(contentResourceResource).where((0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(contentResourceResource.resourceOfId, parentResourceId), (0, import_drizzle_orm43.eq)(contentResourceResource.resourceId, childResourceId)));
|
|
12809
12928
|
return parsedResourceJoin.data.resource;
|
|
12810
12929
|
},
|
|
12811
12930
|
async updateContentResourceFields(options) {
|
|
12812
12931
|
if (!options.id) {
|
|
12813
12932
|
throw new Error("No content resource id.");
|
|
12814
12933
|
}
|
|
12815
|
-
const currentResource = await client.select().from(contentResource).where((0,
|
|
12934
|
+
const currentResource = await client.select().from(contentResource).where((0, import_drizzle_orm43.eq)(contentResource.id, options.id)).then((res) => res[0]);
|
|
12816
12935
|
await client.update(contentResource).set({
|
|
12817
12936
|
fields: {
|
|
12818
12937
|
...currentResource.fields,
|
|
12819
12938
|
...options.fields
|
|
12820
12939
|
}
|
|
12821
|
-
}).where((0,
|
|
12940
|
+
}).where((0, import_drizzle_orm43.eq)(contentResource.id, options.id));
|
|
12822
12941
|
const resource = await client.query.contentResource.findFirst({
|
|
12823
|
-
where: (0,
|
|
12942
|
+
where: (0, import_drizzle_orm43.eq)(contentResource.id, options.id),
|
|
12824
12943
|
with: {
|
|
12825
12944
|
resources: {
|
|
12826
12945
|
with: {
|
|
@@ -12830,12 +12949,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12830
12949
|
with: {
|
|
12831
12950
|
resource: true
|
|
12832
12951
|
},
|
|
12833
|
-
orderBy: (0,
|
|
12952
|
+
orderBy: (0, import_drizzle_orm43.asc)(contentResourceResource.position)
|
|
12834
12953
|
}
|
|
12835
12954
|
}
|
|
12836
12955
|
}
|
|
12837
12956
|
},
|
|
12838
|
-
orderBy: (0,
|
|
12957
|
+
orderBy: (0, import_drizzle_orm43.asc)(contentResourceResource.position)
|
|
12839
12958
|
}
|
|
12840
12959
|
}
|
|
12841
12960
|
});
|
|
@@ -12850,7 +12969,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12850
12969
|
if (!id) {
|
|
12851
12970
|
return null;
|
|
12852
12971
|
}
|
|
12853
|
-
const query =
|
|
12972
|
+
const query = import_drizzle_orm43.sql`
|
|
12854
12973
|
SELECT
|
|
12855
12974
|
id as id,
|
|
12856
12975
|
CAST(updatedAt AS DATETIME) as updatedAt,
|
|
@@ -12882,7 +13001,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12882
13001
|
id
|
|
12883
13002
|
});
|
|
12884
13003
|
const resource = await client.query.contentResource.findFirst({
|
|
12885
|
-
where: (0,
|
|
13004
|
+
where: (0, import_drizzle_orm43.eq)(contentResource.id, id),
|
|
12886
13005
|
with: {
|
|
12887
13006
|
resources: {
|
|
12888
13007
|
with: {
|
|
@@ -12892,12 +13011,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12892
13011
|
with: {
|
|
12893
13012
|
resource: true
|
|
12894
13013
|
},
|
|
12895
|
-
orderBy: (0,
|
|
13014
|
+
orderBy: (0, import_drizzle_orm43.asc)(contentResourceResource.position)
|
|
12896
13015
|
}
|
|
12897
13016
|
}
|
|
12898
13017
|
}
|
|
12899
13018
|
},
|
|
12900
|
-
orderBy: (0,
|
|
13019
|
+
orderBy: (0, import_drizzle_orm43.asc)(contentResourceResource.position)
|
|
12901
13020
|
}
|
|
12902
13021
|
}
|
|
12903
13022
|
});
|
|
@@ -12910,7 +13029,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12910
13029
|
},
|
|
12911
13030
|
async getContentResource(data) {
|
|
12912
13031
|
const resource = await client.query.contentResource.findFirst({
|
|
12913
|
-
where: (0,
|
|
13032
|
+
where: (0, import_drizzle_orm43.or)((0, import_drizzle_orm43.eq)(contentResource.id, data), (0, import_drizzle_orm43.eq)(import_drizzle_orm43.sql`JSON_EXTRACT (${contentResource.fields}, "$.slug")`, `${data}`)),
|
|
12914
13033
|
with: {
|
|
12915
13034
|
resources: {
|
|
12916
13035
|
with: {
|
|
@@ -12928,12 +13047,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12928
13047
|
}
|
|
12929
13048
|
}
|
|
12930
13049
|
},
|
|
12931
|
-
orderBy: (0,
|
|
13050
|
+
orderBy: (0, import_drizzle_orm43.asc)(contentResourceResource.position)
|
|
12932
13051
|
}
|
|
12933
13052
|
}
|
|
12934
13053
|
}
|
|
12935
13054
|
},
|
|
12936
|
-
orderBy: (0,
|
|
13055
|
+
orderBy: (0, import_drizzle_orm43.asc)(contentResourceResource.position)
|
|
12937
13056
|
}
|
|
12938
13057
|
}
|
|
12939
13058
|
});
|
|
@@ -12981,54 +13100,54 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
12981
13100
|
}
|
|
12982
13101
|
},
|
|
12983
13102
|
async getUser(data) {
|
|
12984
|
-
return await client.select().from(users).where((0,
|
|
13103
|
+
return await client.select().from(users).where((0, import_drizzle_orm43.eq)(users.id, data)).then((res) => res[0]) ?? null;
|
|
12985
13104
|
},
|
|
12986
13105
|
async getUserByEmail(data) {
|
|
12987
|
-
return await client.select().from(users).where((0,
|
|
13106
|
+
return await client.select().from(users).where((0, import_drizzle_orm43.eq)(users.email, data)).then((res) => res[0]) ?? null;
|
|
12988
13107
|
},
|
|
12989
13108
|
async createSession(data) {
|
|
12990
13109
|
await client.insert(sessions).values(data);
|
|
12991
|
-
return await client.select().from(sessions).where((0,
|
|
13110
|
+
return await client.select().from(sessions).where((0, import_drizzle_orm43.eq)(sessions.sessionToken, data.sessionToken)).then((res) => res[0]);
|
|
12992
13111
|
},
|
|
12993
13112
|
async getSessionAndUser(data) {
|
|
12994
13113
|
return await client.select({
|
|
12995
13114
|
session: sessions,
|
|
12996
13115
|
user: users
|
|
12997
|
-
}).from(sessions).where((0,
|
|
13116
|
+
}).from(sessions).where((0, import_drizzle_orm43.eq)(sessions.sessionToken, data)).innerJoin(users, (0, import_drizzle_orm43.eq)(users.id, sessions.userId)).then((res) => res[0]) ?? null;
|
|
12998
13117
|
},
|
|
12999
13118
|
async updateUser(data) {
|
|
13000
13119
|
if (!data.id) {
|
|
13001
13120
|
throw new Error("No user id.");
|
|
13002
13121
|
}
|
|
13003
|
-
await client.update(users).set(data).where((0,
|
|
13004
|
-
return await client.select().from(users).where((0,
|
|
13122
|
+
await client.update(users).set(data).where((0, import_drizzle_orm43.eq)(users.id, data.id));
|
|
13123
|
+
return await client.select().from(users).where((0, import_drizzle_orm43.eq)(users.id, data.id)).then((res) => res[0]);
|
|
13005
13124
|
},
|
|
13006
13125
|
async updateSession(data) {
|
|
13007
|
-
await client.update(sessions).set(data).where((0,
|
|
13008
|
-
return await client.select().from(sessions).where((0,
|
|
13126
|
+
await client.update(sessions).set(data).where((0, import_drizzle_orm43.eq)(sessions.sessionToken, data.sessionToken));
|
|
13127
|
+
return await client.select().from(sessions).where((0, import_drizzle_orm43.eq)(sessions.sessionToken, data.sessionToken)).then((res) => res[0]);
|
|
13009
13128
|
},
|
|
13010
13129
|
async linkAccount(rawAccount) {
|
|
13011
13130
|
await client.insert(accounts).values(rawAccount);
|
|
13012
13131
|
},
|
|
13013
13132
|
async getUserByAccount(account) {
|
|
13014
|
-
const dbAccount = await client.select().from(accounts).where((0,
|
|
13133
|
+
const dbAccount = await client.select().from(accounts).where((0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(accounts.providerAccountId, account.providerAccountId), (0, import_drizzle_orm43.eq)(accounts.provider, account.provider))).leftJoin(users, (0, import_drizzle_orm43.eq)(accounts.userId, users.id)).then((res) => res[0]) ?? null;
|
|
13015
13134
|
if (!dbAccount) {
|
|
13016
13135
|
return null;
|
|
13017
13136
|
}
|
|
13018
13137
|
return dbAccount.User;
|
|
13019
13138
|
},
|
|
13020
13139
|
async deleteSession(sessionToken) {
|
|
13021
|
-
const session = await client.select().from(sessions).where((0,
|
|
13022
|
-
await client.delete(sessions).where((0,
|
|
13140
|
+
const session = await client.select().from(sessions).where((0, import_drizzle_orm43.eq)(sessions.sessionToken, sessionToken)).then((res) => res[0]) ?? null;
|
|
13141
|
+
await client.delete(sessions).where((0, import_drizzle_orm43.eq)(sessions.sessionToken, sessionToken));
|
|
13023
13142
|
return session;
|
|
13024
13143
|
},
|
|
13025
13144
|
async createVerificationToken(token) {
|
|
13026
13145
|
await client.insert(verificationTokens).values(token);
|
|
13027
|
-
return await client.select().from(verificationTokens).where((0,
|
|
13146
|
+
return await client.select().from(verificationTokens).where((0, import_drizzle_orm43.eq)(verificationTokens.identifier, token.identifier)).then((res) => res[0]);
|
|
13028
13147
|
},
|
|
13029
13148
|
async useVerificationToken(token) {
|
|
13030
13149
|
try {
|
|
13031
|
-
const deletedToken = await client.select().from(verificationTokens).where((0,
|
|
13150
|
+
const deletedToken = await client.select().from(verificationTokens).where((0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(verificationTokens.identifier, token.identifier), (0, import_drizzle_orm43.eq)(verificationTokens.token, token.token))).then((res) => res[0]) ?? null;
|
|
13032
13151
|
if (deletedToken?.createdAt) {
|
|
13033
13152
|
const TIMEOUT_IN_SECONDS = 90;
|
|
13034
13153
|
const expireMultipleClicks = (0, import_date_fns2.addSeconds)(deletedToken.createdAt, TIMEOUT_IN_SECONDS);
|
|
@@ -13037,7 +13156,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
13037
13156
|
const { id: _, ...verificationToken } = token;
|
|
13038
13157
|
return deletedToken;
|
|
13039
13158
|
} else {
|
|
13040
|
-
await client.delete(verificationTokens).where((0,
|
|
13159
|
+
await client.delete(verificationTokens).where((0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(verificationTokens.identifier, token.identifier), (0, import_drizzle_orm43.eq)(verificationTokens.token, token.token)));
|
|
13041
13160
|
return deletedToken;
|
|
13042
13161
|
}
|
|
13043
13162
|
}
|
|
@@ -13047,14 +13166,14 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
13047
13166
|
}
|
|
13048
13167
|
},
|
|
13049
13168
|
async deleteUser(id) {
|
|
13050
|
-
const user = await client.select().from(users).where((0,
|
|
13051
|
-
await client.delete(users).where((0,
|
|
13052
|
-
await client.delete(sessions).where((0,
|
|
13053
|
-
await client.delete(accounts).where((0,
|
|
13169
|
+
const user = await client.select().from(users).where((0, import_drizzle_orm43.eq)(users.id, id)).then((res) => res[0] ?? null);
|
|
13170
|
+
await client.delete(users).where((0, import_drizzle_orm43.eq)(users.id, id));
|
|
13171
|
+
await client.delete(sessions).where((0, import_drizzle_orm43.eq)(sessions.userId, id));
|
|
13172
|
+
await client.delete(accounts).where((0, import_drizzle_orm43.eq)(accounts.userId, id));
|
|
13054
13173
|
return user;
|
|
13055
13174
|
},
|
|
13056
13175
|
async unlinkAccount(account) {
|
|
13057
|
-
await client.delete(accounts).where((0,
|
|
13176
|
+
await client.delete(accounts).where((0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(accounts.providerAccountId, account.providerAccountId), (0, import_drizzle_orm43.eq)(accounts.provider, account.provider)));
|
|
13058
13177
|
return void 0;
|
|
13059
13178
|
},
|
|
13060
13179
|
createOrganization: async (options) => {
|
|
@@ -13067,31 +13186,38 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
13067
13186
|
},
|
|
13068
13187
|
getOrganization: async (organizationId) => {
|
|
13069
13188
|
return OrganizationSchema.parse(await client.query.organization.findFirst({
|
|
13070
|
-
where: (0,
|
|
13189
|
+
where: (0, import_drizzle_orm43.eq)(organizationTable.id, organizationId)
|
|
13071
13190
|
}));
|
|
13072
13191
|
},
|
|
13073
13192
|
addMemberToOrganization: async (options) => {
|
|
13074
|
-
const
|
|
13075
|
-
|
|
13076
|
-
...options,
|
|
13077
|
-
id
|
|
13193
|
+
const currentMembership = await client.query.organizationMemberships.findFirst({
|
|
13194
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(organizationMembershipTable.organizationId, options.organizationId), (0, import_drizzle_orm43.eq)(organizationMembershipTable.userId, options.userId))
|
|
13078
13195
|
});
|
|
13079
|
-
|
|
13080
|
-
|
|
13081
|
-
|
|
13082
|
-
|
|
13083
|
-
|
|
13084
|
-
|
|
13085
|
-
|
|
13196
|
+
if (currentMembership) {
|
|
13197
|
+
return OrganizationMemberSchema.parse(currentMembership);
|
|
13198
|
+
} else {
|
|
13199
|
+
const id = crypto.randomUUID();
|
|
13200
|
+
await client.insert(organizationMembershipTable).values({
|
|
13201
|
+
...options,
|
|
13202
|
+
id
|
|
13203
|
+
});
|
|
13204
|
+
return OrganizationMemberSchema.parse(await client.query.organizationMemberships.findFirst({
|
|
13205
|
+
where: (0, import_drizzle_orm43.eq)(organizationMembershipTable.id, id),
|
|
13206
|
+
with: {
|
|
13207
|
+
organization: true,
|
|
13208
|
+
user: true
|
|
13209
|
+
}
|
|
13210
|
+
}));
|
|
13211
|
+
}
|
|
13086
13212
|
},
|
|
13087
13213
|
removeMemberFromOrganization: async (options) => {
|
|
13088
|
-
await client.delete(organizationMembershipTable).where((0,
|
|
13214
|
+
await client.delete(organizationMembershipTable).where((0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(organizationMembershipTable.organizationId, options.organizationId), (0, import_drizzle_orm43.eq)(organizationMembershipTable.userId, options.userId)));
|
|
13089
13215
|
},
|
|
13090
13216
|
addRoleForMember: async (options) => {
|
|
13091
13217
|
const existingRole = z.object({
|
|
13092
13218
|
id: z.string()
|
|
13093
13219
|
}).nullish().parse(await client.query.roles.findFirst({
|
|
13094
|
-
where: (0,
|
|
13220
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(roleTable.organizationId, options.organizationId), (0, import_drizzle_orm43.eq)(roleTable.name, options.role))
|
|
13095
13221
|
}));
|
|
13096
13222
|
const roleId = existingRole?.id || crypto.randomUUID();
|
|
13097
13223
|
if (!existingRole) {
|
|
@@ -13102,7 +13228,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
13102
13228
|
});
|
|
13103
13229
|
}
|
|
13104
13230
|
const currentOrgMembershipRole = await client.query.organizationMembershipRoles.findFirst({
|
|
13105
|
-
where: (0,
|
|
13231
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(organizationMembershipRoleTable.organizationMembershipId, options.memberId), (0, import_drizzle_orm43.eq)(organizationMembershipRoleTable.roleId, roleId))
|
|
13106
13232
|
});
|
|
13107
13233
|
if (!currentOrgMembershipRole) {
|
|
13108
13234
|
await client.insert(organizationMembershipRoleTable).values({
|
|
@@ -13116,16 +13242,16 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
13116
13242
|
const existingRole = z.object({
|
|
13117
13243
|
id: z.string()
|
|
13118
13244
|
}).nullable().parse(await client.query.roles.findFirst({
|
|
13119
|
-
where: (0,
|
|
13245
|
+
where: (0, import_drizzle_orm43.and)((0, import_drizzle_orm43.eq)(roleTable.organizationId, options.organizationId), (0, import_drizzle_orm43.eq)(roleTable.name, options.role))
|
|
13120
13246
|
}));
|
|
13121
13247
|
const roleId = existingRole?.id;
|
|
13122
13248
|
if (roleId) {
|
|
13123
|
-
await client.delete(organizationMembershipRoleTable).where((0,
|
|
13249
|
+
await client.delete(organizationMembershipRoleTable).where((0, import_drizzle_orm43.eq)(organizationMembershipRoleTable.roleId, roleId));
|
|
13124
13250
|
}
|
|
13125
13251
|
},
|
|
13126
13252
|
getMembershipsForUser: async (userId) => {
|
|
13127
13253
|
return OrganizationMemberSchema.array().parse(await client.query.organizationMemberships.findMany({
|
|
13128
|
-
where: (0,
|
|
13254
|
+
where: (0, import_drizzle_orm43.eq)(organizationMembershipTable.userId, userId),
|
|
13129
13255
|
with: {
|
|
13130
13256
|
organization: true,
|
|
13131
13257
|
user: true
|
|
@@ -13134,7 +13260,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
13134
13260
|
},
|
|
13135
13261
|
getOrganizationMembers: async (organizationId) => {
|
|
13136
13262
|
return OrganizationMemberSchema.array().parse(await client.query.organizationMemberships.findMany({
|
|
13137
|
-
where: (0,
|
|
13263
|
+
where: (0, import_drizzle_orm43.eq)(organizationMembershipTable.organizationId, organizationId)
|
|
13138
13264
|
}) || []);
|
|
13139
13265
|
},
|
|
13140
13266
|
createSubscription: async (options) => {
|
|
@@ -13144,7 +13270,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
13144
13270
|
id
|
|
13145
13271
|
});
|
|
13146
13272
|
return SubscriptionSchema.parse(await client.query.subscription.findFirst({
|
|
13147
|
-
where: (0,
|
|
13273
|
+
where: (0, import_drizzle_orm43.eq)(subscriptionTable.id, id),
|
|
13148
13274
|
with: {
|
|
13149
13275
|
product: true
|
|
13150
13276
|
}
|
|
@@ -13152,7 +13278,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
13152
13278
|
},
|
|
13153
13279
|
getMerchantSubscription: async (merchantSubscriptionId) => {
|
|
13154
13280
|
return MerchantSubscriptionSchema.parse(await client.query.merchantSubscription.findFirst({
|
|
13155
|
-
where: (0,
|
|
13281
|
+
where: (0, import_drizzle_orm43.eq)(merchantSubscriptionTable.id, merchantSubscriptionId)
|
|
13156
13282
|
}));
|
|
13157
13283
|
},
|
|
13158
13284
|
createMerchantSubscription: async (options) => {
|
|
@@ -13162,7 +13288,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
13162
13288
|
id
|
|
13163
13289
|
});
|
|
13164
13290
|
return MerchantSubscriptionSchema.parse(await client.query.merchantSubscription.findFirst({
|
|
13165
|
-
where: (0,
|
|
13291
|
+
where: (0, import_drizzle_orm43.eq)(merchantSubscriptionTable.id, id)
|
|
13166
13292
|
}));
|
|
13167
13293
|
},
|
|
13168
13294
|
updateMerchantSubscription: async (options) => {
|
|
@@ -13173,13 +13299,13 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core47.mysqlTable, p
|
|
|
13173
13299
|
},
|
|
13174
13300
|
getSubscriptionForStripeId: async (stripeSubscriptionId) => {
|
|
13175
13301
|
const merchantSubscriptionParsed = MerchantSubscriptionSchema.safeParse(await client.query.merchantSubscription.findFirst({
|
|
13176
|
-
where: (0,
|
|
13302
|
+
where: (0, import_drizzle_orm43.eq)(merchantSubscriptionTable.identifier, stripeSubscriptionId)
|
|
13177
13303
|
}));
|
|
13178
13304
|
if (!merchantSubscriptionParsed.success) {
|
|
13179
13305
|
throw new Error(`No merchant subscription found for stripe id ${stripeSubscriptionId} ${merchantSubscriptionParsed.error}`);
|
|
13180
13306
|
}
|
|
13181
13307
|
const subscriptionParsed = SubscriptionSchema.safeParse(await client.query.subscription.findFirst({
|
|
13182
|
-
where: (0,
|
|
13308
|
+
where: (0, import_drizzle_orm43.eq)(subscriptionTable.merchantSubscriptionId, merchantSubscriptionParsed.data.id),
|
|
13183
13309
|
with: {
|
|
13184
13310
|
product: true
|
|
13185
13311
|
}
|