@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
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getOrganizationMembershipsSchema,
|
|
3
|
+
getOrganizationsSchema,
|
|
4
|
+
getUsersSchema
|
|
5
|
+
} from "./chunk-LPJ2P2KJ.js";
|
|
6
|
+
import {
|
|
7
|
+
__name
|
|
8
|
+
} from "./chunk-H736K5TN.js";
|
|
9
|
+
|
|
10
|
+
// src/lib/mysql/schemas/entitlements/entitlement.ts
|
|
11
|
+
import { relations, sql } from "drizzle-orm";
|
|
12
|
+
import { index, json, timestamp, varchar } from "drizzle-orm/mysql-core";
|
|
13
|
+
function getEntitlementsSchema(mysqlTable) {
|
|
14
|
+
return mysqlTable("Entitlement", {
|
|
15
|
+
id: varchar("id", {
|
|
16
|
+
length: 191
|
|
17
|
+
}).notNull().primaryKey(),
|
|
18
|
+
entitlementType: varchar("entitlementType", {
|
|
19
|
+
length: 255
|
|
20
|
+
}).notNull(),
|
|
21
|
+
userId: varchar("userId", {
|
|
22
|
+
length: 191
|
|
23
|
+
}),
|
|
24
|
+
organizationId: varchar("organizationId", {
|
|
25
|
+
length: 191
|
|
26
|
+
}),
|
|
27
|
+
organizationMembershipId: varchar("organizationMembershipId", {
|
|
28
|
+
length: 191
|
|
29
|
+
}),
|
|
30
|
+
sourceType: varchar("sourceType", {
|
|
31
|
+
length: 255
|
|
32
|
+
}).notNull(),
|
|
33
|
+
sourceId: varchar("sourceId", {
|
|
34
|
+
length: 191
|
|
35
|
+
}).notNull(),
|
|
36
|
+
metadata: json("metadata").$type().default({}),
|
|
37
|
+
expiresAt: timestamp("expiresAt", {
|
|
38
|
+
mode: "date",
|
|
39
|
+
fsp: 3
|
|
40
|
+
}),
|
|
41
|
+
createdAt: timestamp("createdAt", {
|
|
42
|
+
mode: "date",
|
|
43
|
+
fsp: 3
|
|
44
|
+
}).default(sql`CURRENT_TIMESTAMP(3)`).notNull(),
|
|
45
|
+
updatedAt: timestamp("updatedAt", {
|
|
46
|
+
mode: "date",
|
|
47
|
+
fsp: 3
|
|
48
|
+
}).default(sql`CURRENT_TIMESTAMP(3)`).notNull(),
|
|
49
|
+
deletedAt: timestamp("deletedAt", {
|
|
50
|
+
mode: "date",
|
|
51
|
+
fsp: 3
|
|
52
|
+
})
|
|
53
|
+
}, (table) => ({
|
|
54
|
+
userIdIdx: index("userId_idx").on(table.userId),
|
|
55
|
+
orgIdIdx: index("orgId_idx").on(table.organizationId),
|
|
56
|
+
sourceIdx: index("source_idx").on(table.sourceType, table.sourceId),
|
|
57
|
+
typeIdx: index("type_idx").on(table.entitlementType)
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
__name(getEntitlementsSchema, "getEntitlementsSchema");
|
|
61
|
+
function getEntitlementRelationsSchema(mysqlTable) {
|
|
62
|
+
const entitlements = getEntitlementsSchema(mysqlTable);
|
|
63
|
+
const users = getUsersSchema(mysqlTable);
|
|
64
|
+
const orgs = getOrganizationsSchema(mysqlTable);
|
|
65
|
+
const memberships = getOrganizationMembershipsSchema(mysqlTable);
|
|
66
|
+
return relations(entitlements, ({ one }) => ({
|
|
67
|
+
user: one(users, {
|
|
68
|
+
fields: [
|
|
69
|
+
entitlements.userId
|
|
70
|
+
],
|
|
71
|
+
references: [
|
|
72
|
+
users.id
|
|
73
|
+
]
|
|
74
|
+
}),
|
|
75
|
+
organization: one(orgs, {
|
|
76
|
+
fields: [
|
|
77
|
+
entitlements.organizationId
|
|
78
|
+
],
|
|
79
|
+
references: [
|
|
80
|
+
orgs.id
|
|
81
|
+
]
|
|
82
|
+
}),
|
|
83
|
+
membership: one(memberships, {
|
|
84
|
+
fields: [
|
|
85
|
+
entitlements.organizationMembershipId
|
|
86
|
+
],
|
|
87
|
+
references: [
|
|
88
|
+
memberships.id
|
|
89
|
+
]
|
|
90
|
+
})
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
__name(getEntitlementRelationsSchema, "getEntitlementRelationsSchema");
|
|
94
|
+
|
|
95
|
+
export {
|
|
96
|
+
getEntitlementsSchema,
|
|
97
|
+
getEntitlementRelationsSchema
|
|
98
|
+
};
|
|
99
|
+
//# sourceMappingURL=chunk-253RMSB3.js.map
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getEntitlementRelationsSchema,
|
|
3
|
+
getEntitlementsSchema
|
|
4
|
+
} from "./chunk-253RMSB3.js";
|
|
1
5
|
import {
|
|
2
6
|
getLessonProgressSchema
|
|
3
7
|
} from "./chunk-ET3QAIY7.js";
|
|
4
8
|
import {
|
|
5
9
|
getResourceProgressSchema
|
|
6
10
|
} from "./chunk-6YPHJWS2.js";
|
|
11
|
+
import {
|
|
12
|
+
getEntitlementTypesSchema
|
|
13
|
+
} from "./chunk-ORRM7KVW.js";
|
|
7
14
|
import {
|
|
8
15
|
getPurchaseUserTransferRelationsSchema,
|
|
9
16
|
getPurchaseUserTransferSchema
|
|
@@ -8312,7 +8319,7 @@ var priceSchema = z2.object({
|
|
|
8312
8319
|
fields: z2.record(z2.any()).default({})
|
|
8313
8320
|
});
|
|
8314
8321
|
|
|
8315
|
-
// ../core/dist/chunk-
|
|
8322
|
+
// ../core/dist/chunk-FMAXYBP4.js
|
|
8316
8323
|
var productSchema = z2.object({
|
|
8317
8324
|
id: z2.string().max(191),
|
|
8318
8325
|
organizationId: z2.string().max(191).optional().nullable(),
|
|
@@ -8321,7 +8328,8 @@ var productSchema = z2.object({
|
|
|
8321
8328
|
type: z2.enum([
|
|
8322
8329
|
"live",
|
|
8323
8330
|
"self-paced",
|
|
8324
|
-
"membership"
|
|
8331
|
+
"membership",
|
|
8332
|
+
"cohort"
|
|
8325
8333
|
]).default("self-paced"),
|
|
8326
8334
|
fields: z2.object({
|
|
8327
8335
|
body: z2.string().nullable().optional(),
|
|
@@ -8381,7 +8389,7 @@ var couponSchema = z2.object({
|
|
|
8381
8389
|
organizationId: z2.string().max(191).optional().nullable()
|
|
8382
8390
|
});
|
|
8383
8391
|
|
|
8384
|
-
// ../core/dist/chunk-
|
|
8392
|
+
// ../core/dist/chunk-MDUGHSSW.js
|
|
8385
8393
|
var purchaseSchema = z2.object({
|
|
8386
8394
|
id: z2.string().max(191),
|
|
8387
8395
|
userId: z2.string().max(191).optional().nullable(),
|
|
@@ -8752,7 +8760,10 @@ function getCourseBuilderSchema(mysqlTable) {
|
|
|
8752
8760
|
subscription: getSubscriptionSchema(mysqlTable),
|
|
8753
8761
|
subscriptionRelations: getSubscriptionRelationsSchema(mysqlTable),
|
|
8754
8762
|
profiles: getProfilesSchema(mysqlTable),
|
|
8755
|
-
profilesRelations: getProfilesRelationsSchema(mysqlTable)
|
|
8763
|
+
profilesRelations: getProfilesRelationsSchema(mysqlTable),
|
|
8764
|
+
entitlementTypes: getEntitlementTypesSchema(mysqlTable),
|
|
8765
|
+
entitlements: getEntitlementsSchema(mysqlTable),
|
|
8766
|
+
entitlementsRelations: getEntitlementRelationsSchema(mysqlTable)
|
|
8756
8767
|
};
|
|
8757
8768
|
}
|
|
8758
8769
|
__name(getCourseBuilderSchema, "getCourseBuilderSchema");
|
|
@@ -8973,7 +8984,7 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn, paymentProvi
|
|
|
8973
8984
|
async createMerchantChargeAndPurchase(options) {
|
|
8974
8985
|
const purchaseId = await client.transaction(async (trx) => {
|
|
8975
8986
|
try {
|
|
8976
|
-
const { userId, stripeChargeId, stripeCouponId, merchantAccountId, merchantProductId, merchantCustomerId, productId, stripeChargeAmount, quantity = 1, checkoutSessionId, appliedPPPStripeCouponId, upgradedFromPurchaseId, country, usedCouponId } = options;
|
|
8987
|
+
const { userId, stripeChargeId, stripeCouponId, merchantAccountId, merchantProductId, merchantCustomerId, productId, stripeChargeAmount, quantity = 1, checkoutSessionId, appliedPPPStripeCouponId, upgradedFromPurchaseId, country, usedCouponId, organizationId } = options;
|
|
8977
8988
|
const existingMerchantCharge = merchantChargeSchema.nullable().parse(await client.query.merchantCharge.findFirst({
|
|
8978
8989
|
where: eq(merchantCharge.identifier, stripeChargeId)
|
|
8979
8990
|
}) || null);
|
|
@@ -9014,7 +9025,10 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn, paymentProvi
|
|
|
9014
9025
|
bulkCouponId = existingBulkCoupon !== null ? existingBulkCoupon.id : v4();
|
|
9015
9026
|
if (existingBulkCoupon !== null) {
|
|
9016
9027
|
couponToUpdate = await client.update(coupon).set({
|
|
9017
|
-
maxUses: (existingBulkCoupon?.maxUses || 0) + quantity
|
|
9028
|
+
maxUses: (existingBulkCoupon?.maxUses || 0) + quantity,
|
|
9029
|
+
...organizationId ? {
|
|
9030
|
+
organizationId
|
|
9031
|
+
} : {}
|
|
9018
9032
|
}).where(eq(coupon.id, bulkCouponId));
|
|
9019
9033
|
} else {
|
|
9020
9034
|
const merchantCouponToUse = stripeCouponId ? merchantCouponSchema.nullable().parse(await client.query.merchantCoupon.findFirst({
|
|
@@ -9026,6 +9040,9 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn, paymentProvi
|
|
|
9026
9040
|
restrictedToProductId: productId,
|
|
9027
9041
|
maxUses: quantity,
|
|
9028
9042
|
status: 1,
|
|
9043
|
+
...organizationId ? {
|
|
9044
|
+
organizationId
|
|
9045
|
+
} : {},
|
|
9029
9046
|
...merchantCouponToUse ? {
|
|
9030
9047
|
merchantCouponId: merchantCouponToUse.id
|
|
9031
9048
|
} : {}
|
|
@@ -9056,14 +9073,20 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn, paymentProvi
|
|
|
9056
9073
|
merchantSessionId,
|
|
9057
9074
|
country,
|
|
9058
9075
|
upgradedFromId: upgradedFromPurchaseId || null,
|
|
9059
|
-
couponId: usedCouponId || null
|
|
9076
|
+
couponId: usedCouponId || null,
|
|
9077
|
+
...organizationId ? {
|
|
9078
|
+
organizationId
|
|
9079
|
+
} : {}
|
|
9060
9080
|
});
|
|
9061
9081
|
const oneWeekInMilliseconds = 1e3 * 60 * 60 * 24 * 7;
|
|
9062
9082
|
await client.insert(purchaseUserTransfer).values({
|
|
9063
9083
|
id: `put_${v4()}`,
|
|
9064
9084
|
purchaseId: purchaseId2,
|
|
9065
9085
|
expiresAt: existingPurchase ? /* @__PURE__ */ new Date() : new Date(Date.now() + oneWeekInMilliseconds),
|
|
9066
|
-
sourceUserId: userId
|
|
9086
|
+
sourceUserId: userId,
|
|
9087
|
+
...organizationId ? {
|
|
9088
|
+
organizationId
|
|
9089
|
+
} : {}
|
|
9067
9090
|
});
|
|
9068
9091
|
return purchaseId2;
|
|
9069
9092
|
} catch (error) {
|
|
@@ -9486,7 +9509,8 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn, paymentProvi
|
|
|
9486
9509
|
...image?.url && {
|
|
9487
9510
|
image
|
|
9488
9511
|
}
|
|
9489
|
-
}
|
|
9512
|
+
},
|
|
9513
|
+
type: input.type
|
|
9490
9514
|
}).where(eq(products.id, currentProduct.id));
|
|
9491
9515
|
return adapter.getProduct(currentProduct.id);
|
|
9492
9516
|
},
|
|
@@ -10276,18 +10300,25 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn, paymentProvi
|
|
|
10276
10300
|
}));
|
|
10277
10301
|
},
|
|
10278
10302
|
addMemberToOrganization: async (options) => {
|
|
10279
|
-
const
|
|
10280
|
-
|
|
10281
|
-
...options,
|
|
10282
|
-
id
|
|
10303
|
+
const currentMembership = await client.query.organizationMemberships.findFirst({
|
|
10304
|
+
where: and(eq(organizationMembershipTable.organizationId, options.organizationId), eq(organizationMembershipTable.userId, options.userId))
|
|
10283
10305
|
});
|
|
10284
|
-
|
|
10285
|
-
|
|
10286
|
-
|
|
10287
|
-
|
|
10288
|
-
|
|
10289
|
-
|
|
10290
|
-
|
|
10306
|
+
if (currentMembership) {
|
|
10307
|
+
return OrganizationMemberSchema.parse(currentMembership);
|
|
10308
|
+
} else {
|
|
10309
|
+
const id = crypto.randomUUID();
|
|
10310
|
+
await client.insert(organizationMembershipTable).values({
|
|
10311
|
+
...options,
|
|
10312
|
+
id
|
|
10313
|
+
});
|
|
10314
|
+
return OrganizationMemberSchema.parse(await client.query.organizationMemberships.findFirst({
|
|
10315
|
+
where: eq(organizationMembershipTable.id, id),
|
|
10316
|
+
with: {
|
|
10317
|
+
organization: true,
|
|
10318
|
+
user: true
|
|
10319
|
+
}
|
|
10320
|
+
}));
|
|
10321
|
+
}
|
|
10291
10322
|
},
|
|
10292
10323
|
removeMemberFromOrganization: async (options) => {
|
|
10293
10324
|
await client.delete(organizationMembershipTable).where(and(eq(organizationMembershipTable.organizationId, options.organizationId), eq(organizationMembershipTable.userId, options.userId)));
|
|
@@ -10405,4 +10436,4 @@ export {
|
|
|
10405
10436
|
createTables,
|
|
10406
10437
|
mySqlDrizzleAdapter
|
|
10407
10438
|
};
|
|
10408
|
-
//# sourceMappingURL=chunk-
|
|
10439
|
+
//# sourceMappingURL=chunk-5QEGBX2O.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-H736K5TN.js";
|
|
4
|
+
|
|
5
|
+
// src/lib/mysql/schemas/entitlements/entitlement-type.ts
|
|
6
|
+
import { text, uniqueIndex, varchar } from "drizzle-orm/mysql-core";
|
|
7
|
+
function getEntitlementTypesSchema(mysqlTable) {
|
|
8
|
+
return mysqlTable("EntitlementType", {
|
|
9
|
+
id: varchar("id", {
|
|
10
|
+
length: 191
|
|
11
|
+
}).notNull().primaryKey(),
|
|
12
|
+
name: varchar("name", {
|
|
13
|
+
length: 255
|
|
14
|
+
}).notNull(),
|
|
15
|
+
description: text("description")
|
|
16
|
+
}, (table) => ({
|
|
17
|
+
uniqueName: uniqueIndex("unique_name_idx").on(table.name)
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
__name(getEntitlementTypesSchema, "getEntitlementTypesSchema");
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
getEntitlementTypesSchema
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=chunk-ORRM7KVW.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createTables,
|
|
3
3
|
mySqlDrizzleAdapter
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-5QEGBX2O.js";
|
|
5
|
+
import "./chunk-253RMSB3.js";
|
|
5
6
|
import "./chunk-ET3QAIY7.js";
|
|
6
7
|
import "./chunk-6YPHJWS2.js";
|
|
8
|
+
import "./chunk-ORRM7KVW.js";
|
|
7
9
|
import "./chunk-HWIQUI7O.js";
|
|
8
10
|
import "./chunk-FPAQINSA.js";
|
|
9
11
|
import "./chunk-LERR6HQ3.js";
|