@coursebuilder/adapter-drizzle 0.4.0 → 0.5.1
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-57CX5SOI.js → chunk-2UU2F4DM.js} +5 -4
- package/dist/{chunk-V23SCQL7.js → chunk-3NUCFLQJ.js} +2 -2
- package/dist/{chunk-Y7QZGEPT.js → chunk-4ZWS76VQ.js} +2 -2
- package/dist/{chunk-PPBEA4EM.js → chunk-6ON2O6UD.js} +2 -2
- package/dist/{chunk-ULEUIL2Y.js → chunk-7ISZNMPU.js} +3 -3
- package/dist/{chunk-DL3UMWB4.js → chunk-7X7TMG4A.js} +3 -3
- package/dist/{chunk-IDINCRHK.js → chunk-DAP5KOAO.js} +3 -3
- package/dist/{chunk-J4LBG2TH.js → chunk-GINRTL6J.js} +2 -2
- package/dist/{chunk-GLPDG7UE.js → chunk-KDEWFXEP.js} +2 -2
- package/dist/chunk-KDOSK7KN.js +62 -0
- package/dist/{chunk-MBB4GIJI.js → chunk-LERR6HQ3.js} +2 -2
- package/dist/{chunk-VDVCCU7D.js → chunk-LZHZDFNZ.js} +2 -2
- package/dist/{chunk-BX5SO2JG.js → chunk-P4VXXTVA.js} +2 -2
- package/dist/{chunk-VXZRMVNY.js → chunk-QP6YMUQX.js} +2 -2
- package/dist/{chunk-XJHSXR42.js → chunk-QPXUGIXO.js} +4 -4
- package/dist/{chunk-ZD3R6UPJ.js → chunk-SRTIWWLG.js} +7 -7
- package/dist/{chunk-N7UDJAI3.js → chunk-UHH4OVKA.js} +464 -349
- package/dist/chunk-UK6EHYS5.js +54 -0
- package/dist/{chunk-A26D3TCA.js → chunk-VUS77FG3.js} +577 -185
- package/dist/{chunk-FNYW3XKR.js → chunk-XIGJFVUM.js} +8 -8
- package/dist/{chunk-JKOYOL7A.js → chunk-YGRYHMCG.js} +2 -2
- package/dist/chunk-YVVXDJHI.js +56 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +26 -23
- package/dist/lib/mysql/index.cjs +1424 -786
- package/dist/lib/mysql/index.cjs.map +1 -1
- package/dist/lib/mysql/index.d.cts +2056 -1162
- package/dist/lib/mysql/index.d.ts +2056 -1162
- package/dist/lib/mysql/index.js +24 -19
- package/dist/lib/mysql/schemas/auth/accounts.cjs +85 -77
- package/dist/lib/mysql/schemas/auth/accounts.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/accounts.d.cts +17 -17
- package/dist/lib/mysql/schemas/auth/accounts.d.ts +17 -17
- package/dist/lib/mysql/schemas/auth/accounts.js +12 -12
- package/dist/lib/mysql/schemas/auth/device-access-token.cjs +214 -0
- package/dist/lib/mysql/schemas/auth/device-access-token.cjs.map +1 -0
- package/dist/lib/mysql/schemas/auth/device-access-token.d.cts +52 -0
- package/dist/lib/mysql/schemas/auth/device-access-token.d.ts +52 -0
- package/dist/lib/mysql/schemas/auth/device-access-token.js +22 -0
- package/dist/lib/mysql/schemas/auth/device-access-token.js.map +1 -0
- package/dist/lib/mysql/schemas/auth/device-verification.cjs +222 -0
- package/dist/lib/mysql/schemas/auth/device-verification.cjs.map +1 -0
- package/dist/lib/mysql/schemas/auth/device-verification.d.cts +88 -0
- package/dist/lib/mysql/schemas/auth/device-verification.d.ts +88 -0
- package/dist/lib/mysql/schemas/auth/device-verification.js +22 -0
- package/dist/lib/mysql/schemas/auth/device-verification.js.map +1 -0
- package/dist/lib/mysql/schemas/auth/permissions.cjs +1 -1
- package/dist/lib/mysql/schemas/auth/permissions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/permissions.d.cts +9 -9
- package/dist/lib/mysql/schemas/auth/permissions.d.ts +9 -9
- package/dist/lib/mysql/schemas/auth/permissions.js +1 -1
- package/dist/lib/mysql/schemas/auth/role-permissions.cjs +74 -66
- package/dist/lib/mysql/schemas/auth/role-permissions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/role-permissions.d.cts +10 -10
- package/dist/lib/mysql/schemas/auth/role-permissions.d.ts +10 -10
- package/dist/lib/mysql/schemas/auth/role-permissions.js +13 -13
- package/dist/lib/mysql/schemas/auth/roles.cjs +72 -64
- package/dist/lib/mysql/schemas/auth/roles.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/roles.d.cts +10 -10
- package/dist/lib/mysql/schemas/auth/roles.d.ts +10 -10
- package/dist/lib/mysql/schemas/auth/roles.js +12 -12
- package/dist/lib/mysql/schemas/auth/sessions.cjs +75 -67
- package/dist/lib/mysql/schemas/auth/sessions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/sessions.d.cts +6 -6
- package/dist/lib/mysql/schemas/auth/sessions.d.ts +6 -6
- package/dist/lib/mysql/schemas/auth/sessions.js +13 -13
- package/dist/lib/mysql/schemas/auth/user-permissions.cjs +77 -69
- package/dist/lib/mysql/schemas/auth/user-permissions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/user-permissions.d.cts +10 -10
- package/dist/lib/mysql/schemas/auth/user-permissions.d.ts +10 -10
- package/dist/lib/mysql/schemas/auth/user-permissions.js +12 -12
- package/dist/lib/mysql/schemas/auth/user-prefs.cjs +222 -0
- package/dist/lib/mysql/schemas/auth/user-prefs.cjs.map +1 -0
- package/dist/lib/mysql/schemas/auth/user-prefs.d.cts +100 -0
- package/dist/lib/mysql/schemas/auth/user-prefs.d.ts +100 -0
- package/dist/lib/mysql/schemas/auth/user-prefs.js +21 -0
- package/dist/lib/mysql/schemas/auth/user-prefs.js.map +1 -0
- package/dist/lib/mysql/schemas/auth/user-roles.cjs +77 -69
- package/dist/lib/mysql/schemas/auth/user-roles.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/user-roles.d.cts +10 -10
- package/dist/lib/mysql/schemas/auth/user-roles.d.ts +10 -10
- package/dist/lib/mysql/schemas/auth/user-roles.js +12 -12
- package/dist/lib/mysql/schemas/auth/users.cjs +263 -180
- package/dist/lib/mysql/schemas/auth/users.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/users.d.cts +35 -21
- package/dist/lib/mysql/schemas/auth/users.d.ts +35 -21
- package/dist/lib/mysql/schemas/auth/users.js +12 -12
- package/dist/lib/mysql/schemas/auth/verification-tokens.cjs +1 -1
- package/dist/lib/mysql/schemas/auth/verification-tokens.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/verification-tokens.d.cts +5 -5
- package/dist/lib/mysql/schemas/auth/verification-tokens.d.ts +5 -5
- package/dist/lib/mysql/schemas/auth/verification-tokens.js +1 -1
- package/dist/lib/mysql/schemas/commerce/coupon.cjs +76 -77
- package/dist/lib/mysql/schemas/commerce/coupon.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/coupon.d.cts +18 -30
- package/dist/lib/mysql/schemas/commerce/coupon.d.ts +18 -30
- package/dist/lib/mysql/schemas/commerce/coupon.js +12 -12
- package/dist/lib/mysql/schemas/commerce/merchant-account.cjs +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-account.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-account.d.cts +6 -6
- package/dist/lib/mysql/schemas/commerce/merchant-account.d.ts +6 -6
- package/dist/lib/mysql/schemas/commerce/merchant-account.js +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-charge.cjs +6 -5
- package/dist/lib/mysql/schemas/commerce/merchant-charge.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-charge.d.cts +13 -13
- package/dist/lib/mysql/schemas/commerce/merchant-charge.d.ts +13 -13
- package/dist/lib/mysql/schemas/commerce/merchant-charge.js +4 -4
- package/dist/lib/mysql/schemas/commerce/merchant-coupon.cjs +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-coupon.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-coupon.d.cts +7 -7
- package/dist/lib/mysql/schemas/commerce/merchant-coupon.d.ts +7 -7
- package/dist/lib/mysql/schemas/commerce/merchant-coupon.js +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-customer.cjs +3 -2
- package/dist/lib/mysql/schemas/commerce/merchant-customer.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-customer.d.cts +7 -7
- package/dist/lib/mysql/schemas/commerce/merchant-customer.d.ts +7 -7
- package/dist/lib/mysql/schemas/commerce/merchant-customer.js +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-price.cjs +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-price.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-price.d.cts +8 -8
- package/dist/lib/mysql/schemas/commerce/merchant-price.d.ts +8 -8
- package/dist/lib/mysql/schemas/commerce/merchant-price.js +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-product.cjs +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-product.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-product.d.cts +7 -7
- package/dist/lib/mysql/schemas/commerce/merchant-product.d.ts +7 -7
- package/dist/lib/mysql/schemas/commerce/merchant-product.js +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-session.cjs +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-session.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-session.d.cts +4 -4
- package/dist/lib/mysql/schemas/commerce/merchant-session.d.ts +4 -4
- package/dist/lib/mysql/schemas/commerce/merchant-session.js +1 -1
- package/dist/lib/mysql/schemas/commerce/price.cjs +60 -52
- package/dist/lib/mysql/schemas/commerce/price.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/price.d.cts +11 -11
- package/dist/lib/mysql/schemas/commerce/price.d.ts +11 -11
- package/dist/lib/mysql/schemas/commerce/price.js +12 -12
- package/dist/lib/mysql/schemas/commerce/product.cjs +75 -67
- package/dist/lib/mysql/schemas/commerce/product.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/product.d.cts +13 -13
- package/dist/lib/mysql/schemas/commerce/product.d.ts +13 -13
- package/dist/lib/mysql/schemas/commerce/product.js +12 -12
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.cjs +105 -96
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.d.cts +15 -15
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.d.ts +15 -15
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.js +13 -13
- package/dist/lib/mysql/schemas/commerce/purchase.cjs +136 -131
- package/dist/lib/mysql/schemas/commerce/purchase.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/purchase.d.cts +25 -25
- package/dist/lib/mysql/schemas/commerce/purchase.d.ts +25 -25
- package/dist/lib/mysql/schemas/commerce/purchase.js +12 -12
- package/dist/lib/mysql/schemas/commerce/upgradable-products.cjs +66 -58
- package/dist/lib/mysql/schemas/commerce/upgradable-products.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/upgradable-products.d.cts +11 -11
- package/dist/lib/mysql/schemas/commerce/upgradable-products.d.ts +11 -11
- package/dist/lib/mysql/schemas/commerce/upgradable-products.js +13 -13
- package/dist/lib/mysql/schemas/communication/comment.cjs +220 -0
- package/dist/lib/mysql/schemas/communication/comment.cjs.map +1 -0
- package/dist/lib/mysql/schemas/communication/comment.d.cts +100 -0
- package/dist/lib/mysql/schemas/communication/comment.d.ts +100 -0
- package/dist/lib/mysql/schemas/communication/comment.js +21 -0
- package/dist/lib/mysql/schemas/communication/comment.js.map +1 -0
- package/dist/lib/mysql/schemas/communication/communication-channel.cjs +1 -1
- package/dist/lib/mysql/schemas/communication/communication-channel.cjs.map +1 -1
- package/dist/lib/mysql/schemas/communication/communication-channel.d.cts +8 -8
- package/dist/lib/mysql/schemas/communication/communication-channel.d.ts +8 -8
- package/dist/lib/mysql/schemas/communication/communication-channel.js +1 -1
- package/dist/lib/mysql/schemas/communication/communication-preference-types.cjs +1 -1
- package/dist/lib/mysql/schemas/communication/communication-preference-types.cjs.map +1 -1
- package/dist/lib/mysql/schemas/communication/communication-preference-types.d.cts +8 -8
- package/dist/lib/mysql/schemas/communication/communication-preference-types.d.ts +8 -8
- package/dist/lib/mysql/schemas/communication/communication-preference-types.js +1 -1
- package/dist/lib/mysql/schemas/communication/communication-preferences.cjs +99 -91
- package/dist/lib/mysql/schemas/communication/communication-preferences.cjs.map +1 -1
- package/dist/lib/mysql/schemas/communication/communication-preferences.d.cts +16 -16
- package/dist/lib/mysql/schemas/communication/communication-preferences.d.ts +16 -16
- package/dist/lib/mysql/schemas/communication/communication-preferences.js +12 -12
- package/dist/lib/mysql/schemas/content/content-contributions.cjs +67 -59
- package/dist/lib/mysql/schemas/content/content-contributions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-contributions.d.cts +13 -13
- package/dist/lib/mysql/schemas/content/content-contributions.d.ts +13 -13
- package/dist/lib/mysql/schemas/content/content-contributions.js +12 -12
- package/dist/lib/mysql/schemas/content/content-resource-product.cjs +61 -53
- package/dist/lib/mysql/schemas/content/content-resource-product.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-product.d.cts +11 -11
- package/dist/lib/mysql/schemas/content/content-resource-product.d.ts +11 -11
- package/dist/lib/mysql/schemas/content/content-resource-product.js +12 -12
- package/dist/lib/mysql/schemas/content/content-resource-resource.cjs +58 -50
- package/dist/lib/mysql/schemas/content/content-resource-resource.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-resource.d.cts +11 -11
- package/dist/lib/mysql/schemas/content/content-resource-resource.d.ts +11 -11
- package/dist/lib/mysql/schemas/content/content-resource-resource.js +12 -12
- package/dist/lib/mysql/schemas/content/content-resource.cjs +114 -66
- package/dist/lib/mysql/schemas/content/content-resource.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource.d.cts +14 -13
- package/dist/lib/mysql/schemas/content/content-resource.d.ts +14 -13
- package/dist/lib/mysql/schemas/content/content-resource.js +12 -12
- package/dist/lib/mysql/schemas/content/contribution-types.cjs +1 -1
- package/dist/lib/mysql/schemas/content/contribution-types.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/contribution-types.d.cts +10 -10
- package/dist/lib/mysql/schemas/content/contribution-types.d.ts +10 -10
- package/dist/lib/mysql/schemas/content/contribution-types.js +1 -1
- package/dist/lib/mysql/schemas/content/lesson-progress.cjs +77 -0
- package/dist/lib/mysql/schemas/content/lesson-progress.cjs.map +1 -0
- package/dist/lib/mysql/schemas/content/lesson-progress.d.cts +132 -0
- package/dist/lib/mysql/schemas/content/lesson-progress.d.ts +132 -0
- package/dist/lib/mysql/schemas/content/lesson-progress.js +8 -0
- package/dist/lib/mysql/schemas/content/lesson-progress.js.map +1 -0
- package/dist/lib/mysql/schemas/content/resource-progress.cjs +7 -7
- package/dist/lib/mysql/schemas/content/resource-progress.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/resource-progress.d.cts +9 -9
- package/dist/lib/mysql/schemas/content/resource-progress.d.ts +9 -9
- package/dist/lib/mysql/schemas/content/resource-progress.js +1 -1
- package/dist/lib/utils.d.cts +1 -0
- package/dist/lib/utils.d.ts +1 -0
- package/package.json +7 -5
- package/src/index.ts +14 -4
- package/src/lib/mysql/index.ts +675 -153
- package/src/lib/mysql/schemas/auth/accounts.ts +1 -1
- package/src/lib/mysql/schemas/auth/device-access-token.ts +40 -0
- package/src/lib/mysql/schemas/auth/device-verification.ts +48 -0
- package/src/lib/mysql/schemas/auth/permissions.ts +1 -1
- package/src/lib/mysql/schemas/auth/role-permissions.ts +1 -1
- package/src/lib/mysql/schemas/auth/roles.ts +1 -1
- package/src/lib/mysql/schemas/auth/sessions.ts +1 -1
- package/src/lib/mysql/schemas/auth/user-permissions.ts +1 -1
- package/src/lib/mysql/schemas/auth/user-prefs.ts +52 -0
- package/src/lib/mysql/schemas/auth/user-roles.ts +1 -1
- package/src/lib/mysql/schemas/auth/users.ts +14 -2
- package/src/lib/mysql/schemas/auth/verification-tokens.ts +1 -1
- package/src/lib/mysql/schemas/commerce/coupon.ts +4 -13
- package/src/lib/mysql/schemas/commerce/merchant-account.ts +1 -1
- package/src/lib/mysql/schemas/commerce/merchant-charge.ts +1 -1
- package/src/lib/mysql/schemas/commerce/merchant-coupon.ts +1 -1
- package/src/lib/mysql/schemas/commerce/merchant-customer.ts +3 -1
- package/src/lib/mysql/schemas/commerce/merchant-price.ts +1 -1
- package/src/lib/mysql/schemas/commerce/merchant-product.ts +1 -1
- package/src/lib/mysql/schemas/commerce/merchant-session.ts +1 -1
- package/src/lib/mysql/schemas/commerce/price.ts +1 -1
- package/src/lib/mysql/schemas/commerce/product.ts +1 -1
- package/src/lib/mysql/schemas/commerce/purchase-user-transfer.ts +1 -1
- package/src/lib/mysql/schemas/commerce/purchase.ts +5 -4
- package/src/lib/mysql/schemas/commerce/upgradable-products.ts +1 -1
- package/src/lib/mysql/schemas/communication/comment.ts +52 -0
- package/src/lib/mysql/schemas/communication/communication-channel.ts +1 -1
- package/src/lib/mysql/schemas/communication/communication-preference-types.ts +1 -1
- package/src/lib/mysql/schemas/communication/communication-preferences.ts +1 -1
- package/src/lib/mysql/schemas/content/content-contributions.ts +1 -1
- package/src/lib/mysql/schemas/content/content-resource-product.ts +1 -1
- package/src/lib/mysql/schemas/content/content-resource-resource.ts +1 -1
- package/src/lib/mysql/schemas/content/content-resource.ts +6 -2
- package/src/lib/mysql/schemas/content/contribution-types.ts +1 -1
- package/src/lib/mysql/schemas/content/lesson-progress.ts +39 -0
- package/src/lib/mysql/schemas/content/resource-progress.ts +6 -8
|
@@ -1,28 +1,41 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getLessonProgressSchema
|
|
3
|
+
} from "./chunk-YVVXDJHI.js";
|
|
1
4
|
import {
|
|
2
5
|
getResourceProgressSchema
|
|
3
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-XIGJFVUM.js";
|
|
7
|
+
import {
|
|
8
|
+
getPurchaseUserTransferRelationsSchema,
|
|
9
|
+
getPurchaseUserTransferSchema
|
|
10
|
+
} from "./chunk-DAP5KOAO.js";
|
|
4
11
|
import {
|
|
5
12
|
getUpgradableProductsRelationsSchema,
|
|
6
13
|
getUpgradableProductsSchema
|
|
7
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-7ISZNMPU.js";
|
|
8
15
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from "./chunk-
|
|
16
|
+
getRolePermissionsRelationsSchema,
|
|
17
|
+
getRolePermissionsSchema
|
|
18
|
+
} from "./chunk-QPXUGIXO.js";
|
|
12
19
|
import {
|
|
13
20
|
getSessionRelationsSchema,
|
|
14
21
|
getSessionsSchema
|
|
15
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-7X7TMG4A.js";
|
|
16
23
|
import {
|
|
17
24
|
getVerificationTokensSchema
|
|
18
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-LERR6HQ3.js";
|
|
19
26
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} from "./chunk-
|
|
27
|
+
getDeviceAccessTokenRelationsSchema,
|
|
28
|
+
getDeviceAccessTokenSchema
|
|
29
|
+
} from "./chunk-UK6EHYS5.js";
|
|
30
|
+
import {
|
|
31
|
+
getDeviceVerificationRelationsSchema,
|
|
32
|
+
getDeviceVerificationSchema
|
|
33
|
+
} from "./chunk-KDOSK7KN.js";
|
|
23
34
|
import {
|
|
24
35
|
getAccountsRelationsSchema,
|
|
25
36
|
getAccountsSchema,
|
|
37
|
+
getCommentRelationsSchema,
|
|
38
|
+
getCommentsSchema,
|
|
26
39
|
getCommunicationPreferencesRelationsSchema,
|
|
27
40
|
getCommunicationPreferencesSchema,
|
|
28
41
|
getContentContributionRelationsSchema,
|
|
@@ -44,55 +57,59 @@ import {
|
|
|
44
57
|
getRolesSchema,
|
|
45
58
|
getUserPermissionsRelationsSchema,
|
|
46
59
|
getUserPermissionsSchema,
|
|
60
|
+
getUserPrefsRelationsSchema,
|
|
61
|
+
getUserPrefsSchema,
|
|
47
62
|
getUserRolesRelationsSchema,
|
|
48
63
|
getUserRolesSchema,
|
|
49
64
|
getUsersRelationsSchema,
|
|
50
65
|
getUsersSchema
|
|
51
|
-
} from "./chunk-
|
|
66
|
+
} from "./chunk-UHH4OVKA.js";
|
|
52
67
|
import {
|
|
53
68
|
getContributionTypesRelationsSchema,
|
|
54
69
|
getContributionTypesSchema
|
|
55
|
-
} from "./chunk-
|
|
70
|
+
} from "./chunk-KDEWFXEP.js";
|
|
56
71
|
import {
|
|
57
72
|
getCommunicationChannelSchema
|
|
58
|
-
} from "./chunk-
|
|
73
|
+
} from "./chunk-GINRTL6J.js";
|
|
59
74
|
import {
|
|
60
75
|
getCommunicationPreferenceTypesSchema
|
|
61
|
-
} from "./chunk-
|
|
62
|
-
import {
|
|
63
|
-
getMerchantCouponSchema
|
|
64
|
-
} from "./chunk-JKOYOL7A.js";
|
|
65
|
-
import {
|
|
66
|
-
getMerchantPriceSchema
|
|
67
|
-
} from "./chunk-PPBEA4EM.js";
|
|
68
|
-
import {
|
|
69
|
-
getMerchantSessionSchema
|
|
70
|
-
} from "./chunk-V23SCQL7.js";
|
|
76
|
+
} from "./chunk-P4VXXTVA.js";
|
|
71
77
|
import {
|
|
72
78
|
getMerchantChargeRelationsSchema,
|
|
73
79
|
getMerchantChargeSchema
|
|
74
|
-
} from "./chunk-
|
|
80
|
+
} from "./chunk-SRTIWWLG.js";
|
|
81
|
+
import {
|
|
82
|
+
getMerchantAccountSchema
|
|
83
|
+
} from "./chunk-QP6YMUQX.js";
|
|
84
|
+
import {
|
|
85
|
+
getMerchantCouponSchema
|
|
86
|
+
} from "./chunk-YGRYHMCG.js";
|
|
75
87
|
import {
|
|
76
88
|
getMerchantCustomerSchema
|
|
77
|
-
} from "./chunk-
|
|
89
|
+
} from "./chunk-2UU2F4DM.js";
|
|
90
|
+
import {
|
|
91
|
+
getMerchantPriceSchema
|
|
92
|
+
} from "./chunk-6ON2O6UD.js";
|
|
78
93
|
import {
|
|
79
94
|
getMerchantProductSchema
|
|
80
|
-
} from "./chunk-
|
|
95
|
+
} from "./chunk-4ZWS76VQ.js";
|
|
81
96
|
import {
|
|
82
|
-
|
|
83
|
-
} from "./chunk-
|
|
97
|
+
getMerchantSessionSchema
|
|
98
|
+
} from "./chunk-3NUCFLQJ.js";
|
|
84
99
|
import {
|
|
85
100
|
getPermissionsRelationsSchema,
|
|
86
101
|
getPermissionsSchema
|
|
87
|
-
} from "./chunk-
|
|
102
|
+
} from "./chunk-LZHZDFNZ.js";
|
|
88
103
|
import {
|
|
89
104
|
__name
|
|
90
105
|
} from "./chunk-H736K5TN.js";
|
|
91
106
|
|
|
92
107
|
// src/lib/mysql/index.ts
|
|
108
|
+
import slugify from "@sindresorhus/slugify";
|
|
93
109
|
import { addSeconds, isAfter } from "date-fns";
|
|
94
|
-
import { and, asc, desc, eq, gte, inArray,
|
|
110
|
+
import { and, asc, desc, eq, gte, inArray, isNull, not, or, sql } from "drizzle-orm";
|
|
95
111
|
import { mysqlTable as defaultMySqlTableFn } from "drizzle-orm/mysql-core";
|
|
112
|
+
import { customAlphabet } from "nanoid";
|
|
96
113
|
import { v4 } from "uuid";
|
|
97
114
|
|
|
98
115
|
// ../../node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/index.mjs
|
|
@@ -8108,6 +8125,29 @@ var z2 = /* @__PURE__ */ Object.freeze({
|
|
|
8108
8125
|
ZodError: ZodError2
|
|
8109
8126
|
});
|
|
8110
8127
|
|
|
8128
|
+
// ../core/dist/chunk-CMH4QQ3R.js
|
|
8129
|
+
var VideoResourceSchema = z2.object({
|
|
8130
|
+
id: z2.string(),
|
|
8131
|
+
updatedAt: z2.coerce.date().optional(),
|
|
8132
|
+
createdAt: z2.coerce.date().optional(),
|
|
8133
|
+
title: z2.string().optional().nullable(),
|
|
8134
|
+
duration: z2.number().optional().nullable(),
|
|
8135
|
+
muxPlaybackId: z2.string().optional().nullable(),
|
|
8136
|
+
muxAssetId: z2.string().optional().nullable(),
|
|
8137
|
+
transcript: z2.string().optional().nullable(),
|
|
8138
|
+
transcriptWithScreenshots: z2.string().optional().nullable(),
|
|
8139
|
+
srt: z2.string().optional().nullable(),
|
|
8140
|
+
wordLevelSrt: z2.string().optional().nullable(),
|
|
8141
|
+
state: z2.enum([
|
|
8142
|
+
"new",
|
|
8143
|
+
"processing",
|
|
8144
|
+
"preparing",
|
|
8145
|
+
"ready",
|
|
8146
|
+
"errored",
|
|
8147
|
+
"deleted"
|
|
8148
|
+
])
|
|
8149
|
+
});
|
|
8150
|
+
|
|
8111
8151
|
// ../core/dist/chunk-CHYUPSYW.js
|
|
8112
8152
|
var userSchema = z2.object({
|
|
8113
8153
|
id: z2.string().max(255),
|
|
@@ -8142,15 +8182,15 @@ var priceSchema = z2.object({
|
|
|
8142
8182
|
fields: z2.record(z2.any()).default({})
|
|
8143
8183
|
});
|
|
8144
8184
|
|
|
8145
|
-
// ../core/dist/chunk-
|
|
8185
|
+
// ../core/dist/chunk-5BAEWUNU.js
|
|
8146
8186
|
var ContentResourceResourceSchema = z2.object({
|
|
8147
8187
|
resourceId: z2.string(),
|
|
8148
8188
|
resourceOfId: z2.string(),
|
|
8149
8189
|
position: z2.number().default(0),
|
|
8150
8190
|
metadata: z2.record(z2.string(), z2.any()).default({}).nullable(),
|
|
8151
|
-
createdAt: z2.date().nullable(),
|
|
8152
|
-
updatedAt: z2.date().nullable(),
|
|
8153
|
-
deletedAt: z2.date().nullable(),
|
|
8191
|
+
createdAt: z2.coerce.date().nullable(),
|
|
8192
|
+
updatedAt: z2.coerce.date().nullable(),
|
|
8193
|
+
deletedAt: z2.coerce.date().nullable(),
|
|
8154
8194
|
resource: z2.any()
|
|
8155
8195
|
});
|
|
8156
8196
|
var ContentResourceSchema = z2.object({
|
|
@@ -8158,9 +8198,9 @@ var ContentResourceSchema = z2.object({
|
|
|
8158
8198
|
type: z2.string(),
|
|
8159
8199
|
createdById: z2.string(),
|
|
8160
8200
|
fields: z2.record(z2.string(), z2.any()).default({}).nullable().optional(),
|
|
8161
|
-
createdAt: z2.date().nullable(),
|
|
8162
|
-
updatedAt: z2.date().nullable(),
|
|
8163
|
-
deletedAt: z2.date().nullable(),
|
|
8201
|
+
createdAt: z2.coerce.date().nullable(),
|
|
8202
|
+
updatedAt: z2.coerce.date().nullable(),
|
|
8203
|
+
deletedAt: z2.coerce.date().nullable(),
|
|
8164
8204
|
resources: z2.array(ContentResourceResourceSchema).default([]).nullable()
|
|
8165
8205
|
});
|
|
8166
8206
|
var ContentResourceProductSchema = z2.object({
|
|
@@ -8168,9 +8208,9 @@ var ContentResourceProductSchema = z2.object({
|
|
|
8168
8208
|
productId: z2.string(),
|
|
8169
8209
|
position: z2.number().default(0),
|
|
8170
8210
|
metadata: z2.record(z2.string(), z2.any()).default({}).nullable(),
|
|
8171
|
-
createdAt: z2.date().nullable(),
|
|
8172
|
-
updatedAt: z2.date().nullable(),
|
|
8173
|
-
deletedAt: z2.date().nullable(),
|
|
8211
|
+
createdAt: z2.coerce.date().nullable(),
|
|
8212
|
+
updatedAt: z2.coerce.date().nullable(),
|
|
8213
|
+
deletedAt: z2.coerce.date().nullable(),
|
|
8174
8214
|
resource: z2.any(),
|
|
8175
8215
|
product: z2.any()
|
|
8176
8216
|
});
|
|
@@ -8186,7 +8226,7 @@ var ResourceVisibilitySchema = z2.union([
|
|
|
8186
8226
|
z2.literal("unlisted")
|
|
8187
8227
|
]);
|
|
8188
8228
|
|
|
8189
|
-
// ../core/dist/chunk-
|
|
8229
|
+
// ../core/dist/chunk-SVQMPVCK.js
|
|
8190
8230
|
var productSchema = z2.object({
|
|
8191
8231
|
id: z2.string().max(191),
|
|
8192
8232
|
name: z2.string().max(191),
|
|
@@ -8197,10 +8237,10 @@ var productSchema = z2.object({
|
|
|
8197
8237
|
]).default("self-paced"),
|
|
8198
8238
|
fields: z2.object({
|
|
8199
8239
|
body: z2.string().nullable().optional(),
|
|
8200
|
-
description: z2.string().
|
|
8240
|
+
description: z2.string().nullish(),
|
|
8201
8241
|
slug: z2.string(),
|
|
8202
8242
|
image: z2.object({
|
|
8203
|
-
url: z2.string()
|
|
8243
|
+
url: z2.string(),
|
|
8204
8244
|
alt: z2.string().optional().nullable(),
|
|
8205
8245
|
width: z2.number().optional().nullable(),
|
|
8206
8246
|
height: z2.number().optional().nullable()
|
|
@@ -8218,14 +8258,19 @@ var productSchema = z2.object({
|
|
|
8218
8258
|
"unlisted"
|
|
8219
8259
|
]).default("unlisted")
|
|
8220
8260
|
}),
|
|
8221
|
-
createdAt: z2.date().nullable(),
|
|
8261
|
+
createdAt: z2.coerce.date().nullable(),
|
|
8222
8262
|
status: z2.number().int().default(0),
|
|
8223
8263
|
quantityAvailable: z2.number().int().default(-1),
|
|
8224
8264
|
price: priceSchema.nullable().optional(),
|
|
8225
8265
|
resources: z2.array(ContentResourceProductSchema).default([]).nullable()
|
|
8226
8266
|
});
|
|
8267
|
+
var NewProductSchema = z2.object({
|
|
8268
|
+
name: z2.string().min(2).max(90),
|
|
8269
|
+
quantityAvailable: z2.coerce.number().default(-1),
|
|
8270
|
+
price: z2.coerce.number().gte(0).default(0)
|
|
8271
|
+
});
|
|
8227
8272
|
|
|
8228
|
-
// ../core/dist/chunk-
|
|
8273
|
+
// ../core/dist/chunk-RCFZC3SN.js
|
|
8229
8274
|
var couponSchema = z2.object({
|
|
8230
8275
|
id: z2.string(),
|
|
8231
8276
|
code: z2.string().max(191).optional().nullable(),
|
|
@@ -8242,11 +8287,12 @@ var couponSchema = z2.object({
|
|
|
8242
8287
|
return decimalPlaces <= 2;
|
|
8243
8288
|
}),
|
|
8244
8289
|
restrictedToProductId: z2.string().max(191).optional().nullable(),
|
|
8245
|
-
|
|
8246
|
-
|
|
8290
|
+
bulkPurchases: z2.array(z2.any()).default([]),
|
|
8291
|
+
redeemedBulkCouponPurchases: z2.array(z2.any()).default([]),
|
|
8292
|
+
bulkPurchaseId: z2.string().max(191).optional().nullable()
|
|
8247
8293
|
});
|
|
8248
8294
|
|
|
8249
|
-
// ../core/dist/chunk-
|
|
8295
|
+
// ../core/dist/chunk-5OFQV6YX.js
|
|
8250
8296
|
var purchaseSchema = z2.object({
|
|
8251
8297
|
id: z2.string().max(191),
|
|
8252
8298
|
userId: z2.string().max(191).optional().nullable(),
|
|
@@ -8295,18 +8341,15 @@ var purchaseUserTransferSchema = z2.object({
|
|
|
8295
8341
|
completedAt: z2.date().nullable()
|
|
8296
8342
|
});
|
|
8297
8343
|
|
|
8298
|
-
// ../core/dist/chunk-
|
|
8344
|
+
// ../core/dist/chunk-CWQHSOPP.js
|
|
8299
8345
|
var resourceProgressSchema = z2.object({
|
|
8300
8346
|
userId: z2.string().max(191),
|
|
8301
|
-
|
|
8302
|
-
|
|
8303
|
-
completedAt: z2.date().nullable(),
|
|
8304
|
-
updatedAt: z2.date().nullable(),
|
|
8305
|
-
createdAt: z2.date().nullable()
|
|
8347
|
+
resourceId: z2.string().max(191).optional().nullable(),
|
|
8348
|
+
completedAt: z2.date().nullable()
|
|
8306
8349
|
});
|
|
8307
8350
|
var moduleProgressSchema = z2.object({
|
|
8308
8351
|
completedLessons: z2.array(resourceProgressSchema),
|
|
8309
|
-
nextResource: ContentResourceSchema.nullable(),
|
|
8352
|
+
nextResource: ContentResourceSchema.partial().nullable(),
|
|
8310
8353
|
percentCompleted: z2.number().default(0),
|
|
8311
8354
|
completedLessonsCount: z2.number().default(0),
|
|
8312
8355
|
totalLessonsCount: z2.number().default(0)
|
|
@@ -8323,28 +8366,6 @@ var upgradableProductSchema = z2.object({
|
|
|
8323
8366
|
deletedAt: z2.date().nullable()
|
|
8324
8367
|
});
|
|
8325
8368
|
|
|
8326
|
-
// ../core/dist/chunk-G22WGQ3G.js
|
|
8327
|
-
var VideoResourceSchema = z2.object({
|
|
8328
|
-
id: z2.string(),
|
|
8329
|
-
updatedAt: z2.string().optional(),
|
|
8330
|
-
createdAt: z2.string().optional(),
|
|
8331
|
-
title: z2.string().optional().nullable(),
|
|
8332
|
-
duration: z2.number().optional().nullable(),
|
|
8333
|
-
muxPlaybackId: z2.string().optional().nullable(),
|
|
8334
|
-
muxAssetId: z2.string().optional().nullable(),
|
|
8335
|
-
transcript: z2.string().optional().nullable(),
|
|
8336
|
-
transcriptWithScreenshots: z2.string().optional().nullable(),
|
|
8337
|
-
srt: z2.string().optional().nullable(),
|
|
8338
|
-
wordLevelSrt: z2.string().optional().nullable(),
|
|
8339
|
-
state: z2.enum([
|
|
8340
|
-
"new",
|
|
8341
|
-
"processing",
|
|
8342
|
-
"preparing",
|
|
8343
|
-
"ready",
|
|
8344
|
-
"errored"
|
|
8345
|
-
])
|
|
8346
|
-
});
|
|
8347
|
-
|
|
8348
8369
|
// ../core/dist/chunk-EDDT2FFU.js
|
|
8349
8370
|
var merchantCustomerSchema = z2.object({
|
|
8350
8371
|
id: z2.string().max(191),
|
|
@@ -8540,6 +8561,7 @@ var validateCoupon = /* @__PURE__ */ __name2((coupon, productIds = []) => {
|
|
|
8540
8561
|
}, "validateCoupon");
|
|
8541
8562
|
|
|
8542
8563
|
// src/lib/mysql/index.ts
|
|
8564
|
+
var guid = customAlphabet("1234567890abcdefghijklmnopqrstuvwxyz", 5);
|
|
8543
8565
|
function getCourseBuilderSchema(mysqlTable) {
|
|
8544
8566
|
return {
|
|
8545
8567
|
accounts: getAccountsSchema(mysqlTable),
|
|
@@ -8561,6 +8583,7 @@ function getCourseBuilderSchema(mysqlTable) {
|
|
|
8561
8583
|
verificationTokens: getVerificationTokensSchema(mysqlTable),
|
|
8562
8584
|
coupon: getCouponSchema(mysqlTable),
|
|
8563
8585
|
couponRelations: getCouponRelationsSchema(mysqlTable),
|
|
8586
|
+
lessonProgress: getLessonProgressSchema(mysqlTable),
|
|
8564
8587
|
merchantAccount: getMerchantAccountSchema(mysqlTable),
|
|
8565
8588
|
merchantCharge: getMerchantChargeSchema(mysqlTable),
|
|
8566
8589
|
merchantChargeRelations: getMerchantChargeRelationsSchema(mysqlTable),
|
|
@@ -8592,7 +8615,15 @@ function getCourseBuilderSchema(mysqlTable) {
|
|
|
8592
8615
|
upgradableProductsRelations: getUpgradableProductsRelationsSchema(mysqlTable),
|
|
8593
8616
|
contentResourceProduct: getContentResourceProductSchema(mysqlTable),
|
|
8594
8617
|
contentResourceProductRelations: getContentResourceProductRelationsSchema(mysqlTable),
|
|
8595
|
-
productRelations: getProductRelationsSchema(mysqlTable)
|
|
8618
|
+
productRelations: getProductRelationsSchema(mysqlTable),
|
|
8619
|
+
comments: getCommentsSchema(mysqlTable),
|
|
8620
|
+
commentsRelations: getCommentRelationsSchema(mysqlTable),
|
|
8621
|
+
deviceVerifications: getDeviceVerificationSchema(mysqlTable),
|
|
8622
|
+
deviceVerificationRelations: getDeviceVerificationRelationsSchema(mysqlTable),
|
|
8623
|
+
deviceAccessToken: getDeviceAccessTokenSchema(mysqlTable),
|
|
8624
|
+
deviceAccessTokenRelations: getDeviceAccessTokenRelationsSchema(mysqlTable),
|
|
8625
|
+
userPrefs: getUserPrefsSchema(mysqlTable),
|
|
8626
|
+
userPrefsRelations: getUserPrefsRelationsSchema(mysqlTable)
|
|
8596
8627
|
};
|
|
8597
8628
|
}
|
|
8598
8629
|
__name(getCourseBuilderSchema, "getCourseBuilderSchema");
|
|
@@ -8600,8 +8631,8 @@ function createTables(mySqlTable) {
|
|
|
8600
8631
|
return getCourseBuilderSchema(mySqlTable);
|
|
8601
8632
|
}
|
|
8602
8633
|
__name(createTables, "createTables");
|
|
8603
|
-
function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
8604
|
-
const { users, accounts, sessions, verificationTokens, contentResource, contentResourceResource, purchases: purchaseTable, purchaseUserTransfer, coupon, merchantCoupon, merchantCharge, merchantAccount, merchantPrice, merchantCustomer, merchantSession, merchantProduct, prices, products, upgradableProducts, resourceProgress } = createTables(tableFn);
|
|
8634
|
+
function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn, paymentProvider) {
|
|
8635
|
+
const { users, accounts, sessions, verificationTokens, contentResource, contentResourceResource, contentResourceProduct, purchases: purchaseTable, purchaseUserTransfer, coupon, merchantCoupon, merchantCharge, merchantAccount, merchantPrice, merchantCustomer, merchantSession, merchantProduct, prices, products, upgradableProducts, resourceProgress, comments } = createTables(tableFn);
|
|
8605
8636
|
const adapter = {
|
|
8606
8637
|
client,
|
|
8607
8638
|
async redeemFullPriceCoupon(options) {
|
|
@@ -8613,7 +8644,7 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8613
8644
|
throw new Error(`unable-to-find-any-product-id`);
|
|
8614
8645
|
const couponValidation = validateCoupon(coupon2, productIds);
|
|
8615
8646
|
if (coupon2 && couponValidation.isRedeemable) {
|
|
8616
|
-
const bulkCouponRedemption = Boolean(coupon2.
|
|
8647
|
+
const bulkCouponRedemption = Boolean(coupon2.maxUses > 1);
|
|
8617
8648
|
const { user } = await adapter.findOrCreateUser(email);
|
|
8618
8649
|
if (!user)
|
|
8619
8650
|
throw new Error(`unable-to-create-user-${email}`);
|
|
@@ -8623,8 +8654,18 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8623
8654
|
userId: user.id,
|
|
8624
8655
|
productId
|
|
8625
8656
|
});
|
|
8626
|
-
if (existingPurchases.length > 0)
|
|
8627
|
-
|
|
8657
|
+
if (existingPurchases.length > 0) {
|
|
8658
|
+
const errorMessage = `already-purchased-${email}`;
|
|
8659
|
+
console.error(errorMessage);
|
|
8660
|
+
return {
|
|
8661
|
+
error: {
|
|
8662
|
+
message: errorMessage
|
|
8663
|
+
},
|
|
8664
|
+
redeemingForCurrentUser,
|
|
8665
|
+
purchase: null
|
|
8666
|
+
};
|
|
8667
|
+
throw new Error(errorMessage);
|
|
8668
|
+
}
|
|
8628
8669
|
const purchaseId = `purchase-${v4()}`;
|
|
8629
8670
|
await adapter.createPurchase({
|
|
8630
8671
|
id: purchaseId,
|
|
@@ -8690,7 +8731,7 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8690
8731
|
},
|
|
8691
8732
|
getMerchantPriceForProductId: async (productId) => {
|
|
8692
8733
|
const merchantPriceData = await client.query.merchantPrice.findFirst({
|
|
8693
|
-
where: eq(merchantPrice.merchantProductId, productId)
|
|
8734
|
+
where: and(eq(merchantPrice.merchantProductId, productId), eq(merchantPrice.status, 1))
|
|
8694
8735
|
});
|
|
8695
8736
|
const parsedMerchantPrice = merchantPriceSchema.safeParse(merchantPriceData);
|
|
8696
8737
|
if (!parsedMerchantPrice.success) {
|
|
@@ -8724,7 +8765,7 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8724
8765
|
async availableUpgradesForProduct(purchases, productId) {
|
|
8725
8766
|
const previousPurchaseProductIds = purchases.map(({ productId: productId2 }) => productId2);
|
|
8726
8767
|
if (previousPurchaseProductIds.length > 0) {
|
|
8727
|
-
return
|
|
8768
|
+
return client.query.upgradableProducts.findMany({
|
|
8728
8769
|
where: and(eq(upgradableProducts.upgradableToId, productId), inArray(upgradableProducts.upgradableFromId, previousPurchaseProductIds))
|
|
8729
8770
|
});
|
|
8730
8771
|
}
|
|
@@ -8738,7 +8779,7 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8738
8779
|
throw new Error("No lessonId provided");
|
|
8739
8780
|
}
|
|
8740
8781
|
let lessonProgress = await client.query.resourceProgress.findFirst({
|
|
8741
|
-
where: and(eq(resourceProgress.userId, options.userId), eq(resourceProgress.
|
|
8782
|
+
where: and(eq(resourceProgress.userId, options.userId), eq(resourceProgress.resourceId, options.lessonId))
|
|
8742
8783
|
});
|
|
8743
8784
|
const now = /* @__PURE__ */ new Date();
|
|
8744
8785
|
if (lessonProgress) {
|
|
@@ -8746,18 +8787,18 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8746
8787
|
await client.update(resourceProgress).set({
|
|
8747
8788
|
completedAt: now,
|
|
8748
8789
|
updatedAt: now
|
|
8749
|
-
}).where(eq(resourceProgress.
|
|
8790
|
+
}).where(eq(resourceProgress.resourceId, options.lessonId));
|
|
8750
8791
|
}
|
|
8751
8792
|
} else {
|
|
8752
8793
|
await client.insert(resourceProgress).values({
|
|
8753
8794
|
userId: options.userId,
|
|
8754
|
-
|
|
8795
|
+
resourceId: options.lessonId,
|
|
8755
8796
|
completedAt: now,
|
|
8756
8797
|
updatedAt: now
|
|
8757
8798
|
});
|
|
8758
8799
|
}
|
|
8759
8800
|
lessonProgress = await client.query.resourceProgress.findFirst({
|
|
8760
|
-
where: and(eq(resourceProgress.userId, options.userId), eq(resourceProgress.
|
|
8801
|
+
where: and(eq(resourceProgress.userId, options.userId), eq(resourceProgress.resourceId, options.lessonId))
|
|
8761
8802
|
});
|
|
8762
8803
|
const parsedLessonProgress = resourceProgressSchema.safeParse(lessonProgress);
|
|
8763
8804
|
if (!parsedLessonProgress.success) {
|
|
@@ -8777,9 +8818,14 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8777
8818
|
});
|
|
8778
8819
|
if (!couponForIdOrCode)
|
|
8779
8820
|
return null;
|
|
8780
|
-
|
|
8821
|
+
const parsedCoupon = couponSchema.extend({
|
|
8781
8822
|
merchantCoupon: merchantCouponSchema
|
|
8782
|
-
}).
|
|
8823
|
+
}).safeParse(couponForIdOrCode);
|
|
8824
|
+
if (!parsedCoupon.success) {
|
|
8825
|
+
console.error("Error parsing coupon", JSON.stringify(parsedCoupon.error));
|
|
8826
|
+
return null;
|
|
8827
|
+
}
|
|
8828
|
+
return parsedCoupon.data;
|
|
8783
8829
|
},
|
|
8784
8830
|
async createMerchantChargeAndPurchase(options) {
|
|
8785
8831
|
const purchaseId = await client.transaction(async (trx) => {
|
|
@@ -8816,7 +8862,7 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8816
8862
|
]))
|
|
8817
8863
|
}) || null);
|
|
8818
8864
|
const existingBulkCoupon = couponSchema.nullable().parse(await client.select().from(coupon).leftJoin(purchaseTable, and(eq(coupon.id, purchaseTable.bulkCouponId), eq(purchaseTable.userId, userId))).where(and(eq(coupon.restrictedToProductId, productId), eq(purchaseTable.userId, userId))).then((res) => {
|
|
8819
|
-
return res[0]?.
|
|
8865
|
+
return res[0]?.Coupon ?? null;
|
|
8820
8866
|
}));
|
|
8821
8867
|
const isBulkPurchase = quantity > 1 || Boolean(existingBulkCoupon) || options.bulk || Boolean(existingPurchase?.status === "Valid");
|
|
8822
8868
|
let bulkCouponId = null;
|
|
@@ -8941,18 +8987,31 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8941
8987
|
couponId
|
|
8942
8988
|
});
|
|
8943
8989
|
let couponData;
|
|
8990
|
+
let bulkCouponPurchases;
|
|
8944
8991
|
try {
|
|
8945
8992
|
couponData = await client.query.coupon.findFirst({
|
|
8946
8993
|
where: eq(coupon.id, couponId),
|
|
8947
8994
|
with: {
|
|
8948
|
-
|
|
8949
|
-
|
|
8995
|
+
bulkPurchases: true,
|
|
8996
|
+
redeemedBulkCouponPurchases: true
|
|
8950
8997
|
}
|
|
8951
8998
|
}) || null;
|
|
8952
8999
|
} catch (e) {
|
|
8953
9000
|
console.log("getCouponWithBulkPurchases");
|
|
8954
9001
|
logger.error(e);
|
|
8955
9002
|
}
|
|
9003
|
+
try {
|
|
9004
|
+
bulkCouponPurchases = await client.query.purchases.findMany({
|
|
9005
|
+
where: eq(purchaseTable.redeemedBulkCouponId, couponId),
|
|
9006
|
+
with: {
|
|
9007
|
+
user: true
|
|
9008
|
+
}
|
|
9009
|
+
});
|
|
9010
|
+
console.log("purchases with redeemedBulkCouponId", bulkCouponPurchases);
|
|
9011
|
+
} catch (e) {
|
|
9012
|
+
console.log("getCouponWithBulkPurchases");
|
|
9013
|
+
logger.error(e);
|
|
9014
|
+
}
|
|
8956
9015
|
if (!couponData) {
|
|
8957
9016
|
logger.debug("getCouponWithBulkPurchases", {
|
|
8958
9017
|
couponId,
|
|
@@ -8960,12 +9019,15 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8960
9019
|
});
|
|
8961
9020
|
return null;
|
|
8962
9021
|
}
|
|
9022
|
+
const couponWithBulkPurchases = {
|
|
9023
|
+
...couponData,
|
|
9024
|
+
redeemedBulkCouponPurchases: bulkCouponPurchases || []
|
|
9025
|
+
};
|
|
8963
9026
|
const parsedCoupon = couponSchema.merge(z.object({
|
|
8964
|
-
|
|
8965
|
-
|
|
8966
|
-
})).nullable().safeParse(couponData);
|
|
9027
|
+
redeemedBulkCouponPurchases: z.array(purchaseSchema)
|
|
9028
|
+
})).nullable().safeParse(couponWithBulkPurchases);
|
|
8967
9029
|
if (!parsedCoupon.success) {
|
|
8968
|
-
console.error("Error parsing coupon", couponData);
|
|
9030
|
+
console.error("Error parsing coupon", JSON.stringify(parsedCoupon.error), couponData);
|
|
8969
9031
|
return null;
|
|
8970
9032
|
}
|
|
8971
9033
|
return parsedCoupon.data;
|
|
@@ -9007,95 +9069,98 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
9007
9069
|
return parsed.data;
|
|
9008
9070
|
},
|
|
9009
9071
|
async getModuleProgressForUser(userIdOrEmail, moduleIdOrSlug) {
|
|
9010
|
-
const module = await client.query.contentResource.findFirst({
|
|
9011
|
-
where: or(eq(contentResource.id, moduleIdOrSlug), eq(sql`JSON_EXTRACT (${contentResource.fields}, "$.slug")`, moduleIdOrSlug)),
|
|
9012
|
-
with: {
|
|
9013
|
-
resources: {
|
|
9014
|
-
orderBy: asc(contentResourceResource.position)
|
|
9015
|
-
}
|
|
9016
|
-
}
|
|
9017
|
-
});
|
|
9018
|
-
const parsedModule = ContentResourceSchema.parse(module);
|
|
9019
|
-
const moduleResources = await client.query.contentResourceResource.findMany({
|
|
9020
|
-
where: inArray(contentResourceResource.resourceOfId, parsedModule.resources?.map((r) => r.resourceId) ?? []),
|
|
9021
|
-
orderBy: asc(contentResourceResource.position)
|
|
9022
|
-
});
|
|
9023
|
-
const parsedModuleResources = z.array(ContentResourceResourceSchema).safeParse(moduleResources);
|
|
9024
|
-
if (!parsedModuleResources.success) {
|
|
9025
|
-
console.error("Error parsing module resources", parsedModuleResources.error);
|
|
9026
|
-
return {
|
|
9027
|
-
completedLessons: [],
|
|
9028
|
-
nextResource: null,
|
|
9029
|
-
percentCompleted: 0,
|
|
9030
|
-
completedLessonsCount: 0,
|
|
9031
|
-
totalLessonsCount: 0
|
|
9032
|
-
};
|
|
9033
|
-
}
|
|
9034
9072
|
const user = await client.query.users.findFirst({
|
|
9035
9073
|
where: or(eq(users.id, userIdOrEmail), eq(users.email, userIdOrEmail)),
|
|
9036
|
-
|
|
9037
|
-
|
|
9038
|
-
with: {
|
|
9039
|
-
role: true
|
|
9040
|
-
}
|
|
9041
|
-
}
|
|
9042
|
-
}
|
|
9043
|
-
}).then(async (res) => {
|
|
9044
|
-
if (res) {
|
|
9045
|
-
return {
|
|
9046
|
-
...res,
|
|
9047
|
-
roles: res.roles.map((r) => r.role)
|
|
9048
|
-
};
|
|
9074
|
+
columns: {
|
|
9075
|
+
id: true
|
|
9049
9076
|
}
|
|
9050
9077
|
});
|
|
9051
9078
|
if (!user) {
|
|
9052
|
-
|
|
9053
|
-
return {
|
|
9054
|
-
completedLessons: [],
|
|
9055
|
-
nextResource: null,
|
|
9056
|
-
percentCompleted: 0,
|
|
9057
|
-
completedLessonsCount: 0,
|
|
9058
|
-
totalLessonsCount: parsedModuleResources.data.length
|
|
9059
|
-
};
|
|
9079
|
+
return null;
|
|
9060
9080
|
}
|
|
9061
|
-
const
|
|
9062
|
-
|
|
9063
|
-
|
|
9081
|
+
const ResultRowSchema = z.object({
|
|
9082
|
+
resource_id: z.string(),
|
|
9083
|
+
resource_type: z.enum([
|
|
9084
|
+
"lesson",
|
|
9085
|
+
"exercise"
|
|
9086
|
+
]),
|
|
9087
|
+
resource_slug: z.string().nullable(),
|
|
9088
|
+
completed_at: z.string().nullable().transform((val) => val ? new Date(val) : null)
|
|
9089
|
+
});
|
|
9090
|
+
const results = await client.execute(sql`
|
|
9091
|
+
SELECT
|
|
9092
|
+
cr.id AS resource_id,
|
|
9093
|
+
cr.type AS resource_type,
|
|
9094
|
+
cr.fields->>'$.slug' AS resource_slug,
|
|
9095
|
+
rp.completedAt AS completed_at
|
|
9096
|
+
FROM
|
|
9097
|
+
(SELECT id, fields->>'$.slug' AS slug
|
|
9098
|
+
FROM ${contentResource}
|
|
9099
|
+
WHERE id = ${moduleIdOrSlug}
|
|
9100
|
+
OR fields->>'$.slug' = ${moduleIdOrSlug}) AS w
|
|
9101
|
+
LEFT JOIN
|
|
9102
|
+
(SELECT
|
|
9103
|
+
crr.resourceOfId AS workshop_id,
|
|
9104
|
+
crr.resourceId,
|
|
9105
|
+
crr.position
|
|
9106
|
+
FROM ${contentResourceResource} crr) AS tlr ON w.id = tlr.workshop_id
|
|
9107
|
+
LEFT JOIN ${contentResource} sections ON sections.id = tlr.resourceId AND sections.type = 'section'
|
|
9108
|
+
LEFT JOIN
|
|
9109
|
+
(SELECT
|
|
9110
|
+
crr.resourceOfId AS section_id,
|
|
9111
|
+
crr.resourceId AS resource_id,
|
|
9112
|
+
crr.position AS position_in_section,
|
|
9113
|
+
section_crr.position AS section_position
|
|
9114
|
+
FROM ${contentResourceResource} crr
|
|
9115
|
+
JOIN ${contentResourceResource} section_crr ON crr.resourceOfId = section_crr.resourceId) AS sr
|
|
9116
|
+
ON sr.section_id = sections.id
|
|
9117
|
+
JOIN ${contentResource} cr ON cr.id = COALESCE(sr.resource_id, tlr.resourceId)
|
|
9118
|
+
LEFT JOIN ${resourceProgress} rp ON rp.resourceId = cr.id
|
|
9119
|
+
AND rp.userId = ${user.id}
|
|
9120
|
+
WHERE
|
|
9121
|
+
cr.type IN ('lesson', 'exercise')
|
|
9122
|
+
|
|
9123
|
+
`);
|
|
9124
|
+
const completedLessons = [];
|
|
9125
|
+
let nextResource = null;
|
|
9126
|
+
let completedLessonsCount = 0;
|
|
9127
|
+
let totalLessonsCount = results.rows.length;
|
|
9128
|
+
const parsedRows = z.array(ResultRowSchema).safeParse(results.rows);
|
|
9129
|
+
if (!parsedRows.success) {
|
|
9130
|
+
console.error("Error parsing rows", parsedRows.error);
|
|
9064
9131
|
return {
|
|
9065
9132
|
completedLessons: [],
|
|
9066
9133
|
nextResource: null,
|
|
9067
9134
|
percentCompleted: 0,
|
|
9068
9135
|
completedLessonsCount: 0,
|
|
9069
|
-
totalLessonsCount
|
|
9136
|
+
totalLessonsCount
|
|
9070
9137
|
};
|
|
9071
9138
|
}
|
|
9072
|
-
const
|
|
9073
|
-
|
|
9074
|
-
|
|
9075
|
-
|
|
9076
|
-
|
|
9077
|
-
|
|
9078
|
-
|
|
9079
|
-
|
|
9080
|
-
|
|
9081
|
-
|
|
9082
|
-
|
|
9083
|
-
|
|
9084
|
-
|
|
9085
|
-
|
|
9086
|
-
|
|
9087
|
-
|
|
9088
|
-
|
|
9089
|
-
totalLessonsCount: parsedModuleResources.data.length
|
|
9090
|
-
};
|
|
9139
|
+
for (const row of parsedRows.data) {
|
|
9140
|
+
if (row.completed_at) {
|
|
9141
|
+
completedLessonsCount++;
|
|
9142
|
+
completedLessons.push({
|
|
9143
|
+
userId: user.id,
|
|
9144
|
+
resourceId: row.resource_id,
|
|
9145
|
+
completedAt: new Date(row.completed_at)
|
|
9146
|
+
});
|
|
9147
|
+
} else if (!nextResource) {
|
|
9148
|
+
nextResource = {
|
|
9149
|
+
id: row.resource_id,
|
|
9150
|
+
type: row.resource_type,
|
|
9151
|
+
fields: {
|
|
9152
|
+
slug: row.resource_slug
|
|
9153
|
+
}
|
|
9154
|
+
};
|
|
9155
|
+
}
|
|
9091
9156
|
}
|
|
9092
|
-
const percentCompleted = Math.
|
|
9157
|
+
const percentCompleted = totalLessonsCount > 0 ? Math.ceil(completedLessonsCount / totalLessonsCount * 100) : 0;
|
|
9093
9158
|
return {
|
|
9094
|
-
completedLessons
|
|
9095
|
-
nextResource
|
|
9159
|
+
completedLessons,
|
|
9160
|
+
nextResource,
|
|
9096
9161
|
percentCompleted,
|
|
9097
|
-
completedLessonsCount
|
|
9098
|
-
totalLessonsCount
|
|
9162
|
+
completedLessonsCount,
|
|
9163
|
+
totalLessonsCount
|
|
9099
9164
|
};
|
|
9100
9165
|
},
|
|
9101
9166
|
getLessonProgresses() {
|
|
@@ -9107,7 +9172,7 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
9107
9172
|
});
|
|
9108
9173
|
const parsed = merchantChargeSchema.safeParse(mCharge);
|
|
9109
9174
|
if (!parsed.success) {
|
|
9110
|
-
console.
|
|
9175
|
+
console.info("Error parsing merchantCharge", mCharge);
|
|
9111
9176
|
return null;
|
|
9112
9177
|
}
|
|
9113
9178
|
return parsed.data;
|
|
@@ -9150,10 +9215,257 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
9150
9215
|
where: eq(prices.productId, productId)
|
|
9151
9216
|
}));
|
|
9152
9217
|
},
|
|
9153
|
-
async
|
|
9154
|
-
|
|
9155
|
-
|
|
9218
|
+
async archiveProduct(productId) {
|
|
9219
|
+
if (!paymentProvider)
|
|
9220
|
+
throw new Error("Payment provider not found");
|
|
9221
|
+
const product = await adapter.getProduct(productId);
|
|
9222
|
+
if (!product) {
|
|
9223
|
+
throw new Error(`Product not found for id (${productId})`);
|
|
9224
|
+
}
|
|
9225
|
+
if (!product.price) {
|
|
9226
|
+
throw new Error(`Product has no price`);
|
|
9227
|
+
}
|
|
9228
|
+
await client.update(products).set({
|
|
9229
|
+
status: 0,
|
|
9230
|
+
name: `${product.name} (Archived)`
|
|
9231
|
+
}).where(eq(products.id, productId));
|
|
9232
|
+
await client.update(prices).set({
|
|
9233
|
+
status: 0,
|
|
9234
|
+
nickname: `${product.name} (Archived)`
|
|
9235
|
+
}).where(eq(prices.productId, productId));
|
|
9236
|
+
await client.update(merchantProduct).set({
|
|
9237
|
+
status: 0
|
|
9238
|
+
}).where(eq(merchantProduct.productId, productId));
|
|
9239
|
+
await client.update(merchantPrice).set({
|
|
9240
|
+
status: 0
|
|
9241
|
+
}).where(eq(merchantPrice.priceId, product.price.id));
|
|
9242
|
+
const currentMerchantProduct = merchantProductSchema.nullish().parse(await client.query.merchantProduct.findFirst({
|
|
9243
|
+
where: eq(merchantProduct.productId, productId)
|
|
9244
|
+
}));
|
|
9245
|
+
if (!currentMerchantProduct || !currentMerchantProduct.identifier) {
|
|
9246
|
+
throw new Error(`Merchant product not found for id (${productId})`);
|
|
9247
|
+
}
|
|
9248
|
+
await paymentProvider.updateProduct(currentMerchantProduct.identifier, {
|
|
9249
|
+
active: false
|
|
9250
|
+
});
|
|
9251
|
+
const currentMerchantPrice = merchantPriceSchema.nullish().parse(await client.query.merchantPrice.findFirst({
|
|
9252
|
+
where: and(eq(merchantPrice.priceId, product.price.id), eq(merchantPrice.status, 1))
|
|
9253
|
+
}));
|
|
9254
|
+
if (!currentMerchantPrice || !currentMerchantPrice.identifier) {
|
|
9255
|
+
throw new Error(`Merchant price not found for id (${productId})`);
|
|
9256
|
+
}
|
|
9257
|
+
await paymentProvider.updatePrice(currentMerchantPrice.identifier, {
|
|
9258
|
+
active: false
|
|
9259
|
+
});
|
|
9260
|
+
return adapter.getProduct(productId);
|
|
9261
|
+
},
|
|
9262
|
+
async updateProduct(input) {
|
|
9263
|
+
if (!paymentProvider)
|
|
9264
|
+
throw new Error("Payment provider not found");
|
|
9265
|
+
const currentProduct = await adapter.getProduct(input.id);
|
|
9266
|
+
if (!currentProduct) {
|
|
9267
|
+
throw new Error(`Product not found`);
|
|
9268
|
+
}
|
|
9269
|
+
if (!currentProduct.price) {
|
|
9270
|
+
throw new Error(`Product has no price`);
|
|
9271
|
+
}
|
|
9272
|
+
const merchantProduct2 = merchantProductSchema.nullish().parse(await client.query.merchantProduct.findFirst({
|
|
9273
|
+
where: (merchantProduct3, { eq: eq2 }) => eq2(merchantProduct3.productId, input.id)
|
|
9274
|
+
}));
|
|
9275
|
+
if (!merchantProduct2 || !merchantProduct2.identifier) {
|
|
9276
|
+
throw new Error(`Merchant product not found`);
|
|
9277
|
+
}
|
|
9278
|
+
const stripeProduct = await paymentProvider.getProduct(merchantProduct2.identifier);
|
|
9279
|
+
const priceChanged = currentProduct.price.unitAmount.toString() !== input.price?.unitAmount.toString();
|
|
9280
|
+
if (priceChanged) {
|
|
9281
|
+
const currentMerchantPrice = merchantPriceSchema.nullish().parse(await client.query.merchantPrice.findFirst({
|
|
9282
|
+
where: (merchantPrice2, { eq: eq2, and: and2 }) => and2(eq2(merchantPrice2.merchantProductId, merchantProduct2.id), eq2(merchantPrice2.status, 1))
|
|
9283
|
+
}));
|
|
9284
|
+
if (!currentMerchantPrice || !currentMerchantPrice.identifier) {
|
|
9285
|
+
throw new Error(`Merchant price not found`);
|
|
9286
|
+
}
|
|
9287
|
+
const currentStripePrice = await paymentProvider.getPrice(currentMerchantPrice.identifier);
|
|
9288
|
+
const newStripePrice = await paymentProvider.createPrice({
|
|
9289
|
+
product: stripeProduct.id,
|
|
9290
|
+
unit_amount: Math.floor(Number(input.price?.unitAmount || 0) * 100),
|
|
9291
|
+
currency: "usd",
|
|
9292
|
+
metadata: {
|
|
9293
|
+
slug: input.fields.slug
|
|
9294
|
+
},
|
|
9295
|
+
active: true
|
|
9296
|
+
});
|
|
9297
|
+
await paymentProvider.updateProduct(stripeProduct.id, {
|
|
9298
|
+
default_price: newStripePrice.id
|
|
9299
|
+
});
|
|
9300
|
+
const newMerchantPriceId = `mprice_${v4()}`;
|
|
9301
|
+
await client.insert(merchantPrice).values({
|
|
9302
|
+
id: newMerchantPriceId,
|
|
9303
|
+
merchantProductId: merchantProduct2.id,
|
|
9304
|
+
merchantAccountId: merchantProduct2.merchantAccountId,
|
|
9305
|
+
priceId: currentProduct.price.id,
|
|
9306
|
+
status: 1,
|
|
9307
|
+
identifier: newStripePrice.id
|
|
9308
|
+
});
|
|
9309
|
+
if (currentMerchantPrice) {
|
|
9310
|
+
await client.update(merchantPrice).set({
|
|
9311
|
+
status: 0
|
|
9312
|
+
}).where(eq(merchantPrice.id, currentMerchantPrice.id));
|
|
9313
|
+
}
|
|
9314
|
+
await client.update(prices).set({
|
|
9315
|
+
unitAmount: Math.floor(Number(input.price?.unitAmount || 0)).toString(),
|
|
9316
|
+
nickname: input.name
|
|
9317
|
+
}).where(eq(prices.id, currentProduct.price.id));
|
|
9318
|
+
if (currentStripePrice) {
|
|
9319
|
+
await paymentProvider.updatePrice(currentStripePrice.id, {
|
|
9320
|
+
active: false
|
|
9321
|
+
});
|
|
9322
|
+
}
|
|
9323
|
+
}
|
|
9324
|
+
await paymentProvider.updateProduct(stripeProduct.id, {
|
|
9325
|
+
name: input.name,
|
|
9326
|
+
active: true,
|
|
9327
|
+
images: input.fields.image?.url ? [
|
|
9328
|
+
input.fields.image.url
|
|
9329
|
+
] : void 0,
|
|
9330
|
+
description: input.fields.description || "",
|
|
9331
|
+
metadata: {
|
|
9332
|
+
slug: input.fields.slug
|
|
9333
|
+
}
|
|
9334
|
+
});
|
|
9335
|
+
const { image, ...fieldsNoImage } = input.fields;
|
|
9336
|
+
await client.update(products).set({
|
|
9337
|
+
name: input.name,
|
|
9338
|
+
quantityAvailable: input.quantityAvailable,
|
|
9339
|
+
status: 1,
|
|
9340
|
+
fields: {
|
|
9341
|
+
...fieldsNoImage,
|
|
9342
|
+
...image?.url && {
|
|
9343
|
+
image
|
|
9344
|
+
}
|
|
9345
|
+
}
|
|
9346
|
+
}).where(eq(products.id, currentProduct.id));
|
|
9347
|
+
return adapter.getProduct(currentProduct.id);
|
|
9348
|
+
},
|
|
9349
|
+
async createProduct(input) {
|
|
9350
|
+
if (!paymentProvider)
|
|
9351
|
+
throw new Error("Payment provider not found");
|
|
9352
|
+
const merchantAccount2 = merchantAccountSchema.nullish().parse(await client.query.merchantAccount.findFirst({
|
|
9353
|
+
where: (merchantAccount3, { eq: eq2 }) => eq2(merchantAccount3.label, "stripe")
|
|
9354
|
+
}));
|
|
9355
|
+
if (!merchantAccount2) {
|
|
9356
|
+
throw new Error("Merchant account not found");
|
|
9357
|
+
}
|
|
9358
|
+
const hash = guid();
|
|
9359
|
+
const newProductId = slugify(`product-${hash}`);
|
|
9360
|
+
const newProduct = {
|
|
9361
|
+
id: newProductId,
|
|
9362
|
+
name: input.name,
|
|
9363
|
+
status: 1,
|
|
9364
|
+
type: "self-paced",
|
|
9365
|
+
quantityAvailable: input.quantityAvailable,
|
|
9366
|
+
fields: {
|
|
9367
|
+
state: "draft",
|
|
9368
|
+
visibility: "unlisted",
|
|
9369
|
+
slug: slugify(`${input.name}-${hash}`)
|
|
9370
|
+
}
|
|
9371
|
+
};
|
|
9372
|
+
await client.insert(products).values(newProduct);
|
|
9373
|
+
const priceHash = guid();
|
|
9374
|
+
const newPriceId = `price-${priceHash}`;
|
|
9375
|
+
await client.insert(prices).values({
|
|
9376
|
+
id: newPriceId,
|
|
9377
|
+
productId: newProductId,
|
|
9378
|
+
unitAmount: input.price.toString(),
|
|
9379
|
+
status: 1
|
|
9380
|
+
});
|
|
9381
|
+
const product = await adapter.getProduct(newProductId);
|
|
9382
|
+
const stripeProduct = await paymentProvider.createProduct({
|
|
9383
|
+
name: input.name,
|
|
9384
|
+
metadata: {
|
|
9385
|
+
slug: product?.fields?.slug || null
|
|
9386
|
+
}
|
|
9387
|
+
});
|
|
9388
|
+
const stripePrice = await paymentProvider.createPrice({
|
|
9389
|
+
product: stripeProduct.id,
|
|
9390
|
+
unit_amount: Math.floor(Number(input.price) * 100),
|
|
9391
|
+
currency: "usd",
|
|
9392
|
+
nickname: input.name,
|
|
9393
|
+
metadata: {
|
|
9394
|
+
slug: product?.fields?.slug || null
|
|
9395
|
+
}
|
|
9396
|
+
});
|
|
9397
|
+
const newMerchantProductId = `mproduct_${v4()}`;
|
|
9398
|
+
await client.insert(merchantProduct).values({
|
|
9399
|
+
id: newMerchantProductId,
|
|
9400
|
+
merchantAccountId: merchantAccount2.id,
|
|
9401
|
+
productId: newProductId,
|
|
9402
|
+
identifier: stripeProduct.id,
|
|
9403
|
+
status: 1
|
|
9404
|
+
});
|
|
9405
|
+
const newMerchantPriceId = `mprice_${v4()}`;
|
|
9406
|
+
await client.insert(merchantPrice).values({
|
|
9407
|
+
id: newMerchantPriceId,
|
|
9408
|
+
merchantAccountId: merchantAccount2.id,
|
|
9409
|
+
merchantProductId: newMerchantProductId,
|
|
9410
|
+
priceId: newPriceId,
|
|
9411
|
+
identifier: stripePrice.id,
|
|
9412
|
+
status: 1
|
|
9413
|
+
});
|
|
9414
|
+
return product;
|
|
9415
|
+
},
|
|
9416
|
+
async getProduct(productSlugOrId, withResources = true) {
|
|
9417
|
+
if (!productSlugOrId) {
|
|
9418
|
+
return null;
|
|
9419
|
+
}
|
|
9420
|
+
try {
|
|
9421
|
+
const productData = await client.query.products.findFirst({
|
|
9422
|
+
where: and(or(eq(sql`JSON_EXTRACT (${products.fields}, "$.slug")`, `${productSlugOrId}`), eq(products.id, productSlugOrId))),
|
|
9423
|
+
with: {
|
|
9424
|
+
price: true,
|
|
9425
|
+
...withResources && {
|
|
9426
|
+
resources: {
|
|
9427
|
+
with: {
|
|
9428
|
+
resource: {
|
|
9429
|
+
with: {
|
|
9430
|
+
resources: true
|
|
9431
|
+
}
|
|
9432
|
+
}
|
|
9433
|
+
}
|
|
9434
|
+
}
|
|
9435
|
+
}
|
|
9436
|
+
}
|
|
9437
|
+
});
|
|
9438
|
+
const parsedProduct = productSchema.safeParse(productData);
|
|
9439
|
+
if (!parsedProduct.success) {
|
|
9440
|
+
console.error("Error parsing product", JSON.stringify(parsedProduct.error), JSON.stringify(productData));
|
|
9441
|
+
return null;
|
|
9442
|
+
}
|
|
9443
|
+
return parsedProduct.data;
|
|
9444
|
+
} catch (e) {
|
|
9445
|
+
console.log("getProduct error", e);
|
|
9446
|
+
return null;
|
|
9447
|
+
}
|
|
9448
|
+
},
|
|
9449
|
+
async getProductResources(productId) {
|
|
9450
|
+
const contentResourceProductsForProduct = z.array(ContentResourceProductSchema).nullable().parse(await client.query.contentResourceProduct.findMany({
|
|
9451
|
+
where: eq(contentResourceProduct.productId, productId)
|
|
9156
9452
|
}));
|
|
9453
|
+
if (!contentResourceProductsForProduct) {
|
|
9454
|
+
return null;
|
|
9455
|
+
} else {
|
|
9456
|
+
const contentResources = z.array(ContentResourceSchema).parse(await client.query.contentResource.findMany({
|
|
9457
|
+
where: inArray(contentResource.id, contentResourceProductsForProduct.map((crp) => crp.resourceId))
|
|
9458
|
+
}));
|
|
9459
|
+
return contentResources;
|
|
9460
|
+
}
|
|
9461
|
+
},
|
|
9462
|
+
async getPurchaseCountForProduct(productId) {
|
|
9463
|
+
return await client.query.purchases.findMany({
|
|
9464
|
+
where: and(eq(purchaseTable.productId, productId), inArray(purchaseTable.status, [
|
|
9465
|
+
"Valid",
|
|
9466
|
+
"Restricted"
|
|
9467
|
+
]))
|
|
9468
|
+
}).then((res) => res.length);
|
|
9157
9469
|
},
|
|
9158
9470
|
async getPurchase(purchaseId) {
|
|
9159
9471
|
const purchase = await client.query.purchases.findFirst({
|
|
@@ -9178,7 +9490,7 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
9178
9490
|
where: eq(merchantCharge.identifier, stripeChargeId)
|
|
9179
9491
|
}) || null);
|
|
9180
9492
|
if (!chargeForPurchase) {
|
|
9181
|
-
logger.error(new Error(
|
|
9493
|
+
logger.error(new Error(`No charge found for purchase: Stripe Charge ID: ${stripeChargeId}`));
|
|
9182
9494
|
return null;
|
|
9183
9495
|
}
|
|
9184
9496
|
const purchase = purchaseSchema.safeParse(await client.query.purchases.findFirst({
|
|
@@ -9313,6 +9625,33 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
9313
9625
|
purchase: parsedPurchase.data
|
|
9314
9626
|
};
|
|
9315
9627
|
},
|
|
9628
|
+
async getUserWithPurchasersByEmail(email) {
|
|
9629
|
+
const user = await client.query.users.findFirst({
|
|
9630
|
+
where: eq(users.email, email.trim().toLowerCase()),
|
|
9631
|
+
with: {
|
|
9632
|
+
// merchantCustomer: true,
|
|
9633
|
+
roles: {
|
|
9634
|
+
with: {
|
|
9635
|
+
role: true
|
|
9636
|
+
}
|
|
9637
|
+
},
|
|
9638
|
+
purchases: {
|
|
9639
|
+
with: {
|
|
9640
|
+
bulkCoupon: true,
|
|
9641
|
+
merchantCharge: true,
|
|
9642
|
+
product: {
|
|
9643
|
+
columns: {
|
|
9644
|
+
id: true,
|
|
9645
|
+
name: true,
|
|
9646
|
+
key: true
|
|
9647
|
+
}
|
|
9648
|
+
}
|
|
9649
|
+
}
|
|
9650
|
+
}
|
|
9651
|
+
}
|
|
9652
|
+
});
|
|
9653
|
+
return user;
|
|
9654
|
+
},
|
|
9316
9655
|
async getUserById(userId) {
|
|
9317
9656
|
const user = await client.query.users.findFirst({
|
|
9318
9657
|
where: eq(users.id, userId),
|
|
@@ -9360,24 +9699,24 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
9360
9699
|
throw new Error("No lessonId provided");
|
|
9361
9700
|
}
|
|
9362
9701
|
let lessonProgress = await client.query.resourceProgress.findFirst({
|
|
9363
|
-
where: and(eq(resourceProgress.userId, options.userId), eq(resourceProgress.
|
|
9702
|
+
where: and(eq(resourceProgress.userId, options.userId), eq(resourceProgress.resourceId, options.lessonId))
|
|
9364
9703
|
});
|
|
9365
9704
|
const now = /* @__PURE__ */ new Date();
|
|
9366
9705
|
if (lessonProgress) {
|
|
9367
9706
|
await client.update(resourceProgress).set({
|
|
9368
9707
|
completedAt: lessonProgress.completedAt ? null : now,
|
|
9369
9708
|
updatedAt: now
|
|
9370
|
-
}).where(eq(resourceProgress.
|
|
9709
|
+
}).where(eq(resourceProgress.resourceId, options.lessonId));
|
|
9371
9710
|
} else {
|
|
9372
9711
|
await client.insert(resourceProgress).values({
|
|
9373
9712
|
userId: options.userId,
|
|
9374
|
-
|
|
9713
|
+
resourceId: options.lessonId,
|
|
9375
9714
|
completedAt: now,
|
|
9376
9715
|
updatedAt: now
|
|
9377
9716
|
});
|
|
9378
9717
|
}
|
|
9379
9718
|
lessonProgress = await client.query.resourceProgress.findFirst({
|
|
9380
|
-
where: and(eq(resourceProgress.userId, options.userId), eq(resourceProgress.
|
|
9719
|
+
where: and(eq(resourceProgress.userId, options.userId), eq(resourceProgress.resourceId, options.lessonId))
|
|
9381
9720
|
});
|
|
9382
9721
|
const parsedLessonProgress = resourceProgressSchema.safeParse(lessonProgress);
|
|
9383
9722
|
if (!parsedLessonProgress.success) {
|
|
@@ -9389,8 +9728,40 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
9389
9728
|
transferPurchasesToNewUser(options) {
|
|
9390
9729
|
throw new Error("Method not implemented.");
|
|
9391
9730
|
},
|
|
9392
|
-
updatePurchaseStatusForCharge(chargeId, status) {
|
|
9393
|
-
|
|
9731
|
+
async updatePurchaseStatusForCharge(chargeId, status) {
|
|
9732
|
+
try {
|
|
9733
|
+
console.log("updatePurchaseStatusForCharge", {
|
|
9734
|
+
chargeId,
|
|
9735
|
+
status
|
|
9736
|
+
});
|
|
9737
|
+
const merchantChargeForPurchase = await client.query.merchantCharge.findFirst({
|
|
9738
|
+
where: or(eq(merchantCharge.identifier, chargeId), eq(merchantCharge.id, chargeId))
|
|
9739
|
+
});
|
|
9740
|
+
console.log("merchantChargeForPurchase", {
|
|
9741
|
+
merchantChargeForPurchase
|
|
9742
|
+
});
|
|
9743
|
+
const parsedMerchantChargeForPurchase = merchantChargeSchema.parse(merchantChargeForPurchase);
|
|
9744
|
+
if (!parsedMerchantChargeForPurchase)
|
|
9745
|
+
throw new Error(`no-charge-found-for-purchase ${chargeId}`);
|
|
9746
|
+
const purchase = await client.query.purchases.findFirst({
|
|
9747
|
+
where: eq(purchaseTable.merchantChargeId, parsedMerchantChargeForPurchase.id)
|
|
9748
|
+
});
|
|
9749
|
+
const parsedPurchase = purchaseSchema.nullable().parse(purchase);
|
|
9750
|
+
if (parsedPurchase) {
|
|
9751
|
+
await client.update(purchaseTable).set({
|
|
9752
|
+
status
|
|
9753
|
+
}).where(eq(purchaseTable.id, parsedPurchase.id));
|
|
9754
|
+
const newPurchase = await client.query.purchases.findFirst({
|
|
9755
|
+
where: eq(purchaseTable.id, parsedPurchase.id)
|
|
9756
|
+
});
|
|
9757
|
+
return purchaseSchema.optional().parse(newPurchase);
|
|
9758
|
+
} else {
|
|
9759
|
+
throw new Error(`no-purchase-found-for-charge ${chargeId}`);
|
|
9760
|
+
}
|
|
9761
|
+
} catch (e) {
|
|
9762
|
+
console.log("error updating purchase status", e);
|
|
9763
|
+
throw e;
|
|
9764
|
+
}
|
|
9394
9765
|
},
|
|
9395
9766
|
async updatePurchaseUserTransferTransferState(options) {
|
|
9396
9767
|
await client.update(purchaseUserTransfer).set({
|
|
@@ -9427,6 +9798,18 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
9427
9798
|
}
|
|
9428
9799
|
return parsedResourceJoin.data;
|
|
9429
9800
|
},
|
|
9801
|
+
async removeResourceFromResource(options) {
|
|
9802
|
+
const { childResourceId, parentResourceId } = options;
|
|
9803
|
+
const resourceJoin = await client.query.contentResourceResource.findFirst({
|
|
9804
|
+
where: and(eq(contentResourceResource.resourceOfId, parentResourceId), eq(contentResourceResource.resourceId, childResourceId))
|
|
9805
|
+
});
|
|
9806
|
+
const parsedResourceJoin = ContentResourceResourceSchema.safeParse(resourceJoin);
|
|
9807
|
+
if (!parsedResourceJoin.success) {
|
|
9808
|
+
return null;
|
|
9809
|
+
}
|
|
9810
|
+
await client.delete(contentResourceResource).where(and(eq(contentResourceResource.resourceOfId, parentResourceId), eq(contentResourceResource.resourceId, childResourceId)));
|
|
9811
|
+
return parsedResourceJoin.data.resource;
|
|
9812
|
+
},
|
|
9430
9813
|
async updateContentResourceFields(options) {
|
|
9431
9814
|
if (!options.id) {
|
|
9432
9815
|
throw new Error("No content resource id.");
|
|
@@ -9537,7 +9920,15 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
9537
9920
|
with: {
|
|
9538
9921
|
resources: {
|
|
9539
9922
|
with: {
|
|
9540
|
-
resource:
|
|
9923
|
+
resource: {
|
|
9924
|
+
with: {
|
|
9925
|
+
resources: {
|
|
9926
|
+
with: {
|
|
9927
|
+
resource: true
|
|
9928
|
+
}
|
|
9929
|
+
}
|
|
9930
|
+
}
|
|
9931
|
+
}
|
|
9541
9932
|
},
|
|
9542
9933
|
orderBy: asc(contentResourceResource.position)
|
|
9543
9934
|
}
|
|
@@ -9603,7 +9994,7 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
9603
9994
|
if (!dbAccount) {
|
|
9604
9995
|
return null;
|
|
9605
9996
|
}
|
|
9606
|
-
return dbAccount.
|
|
9997
|
+
return dbAccount.User;
|
|
9607
9998
|
},
|
|
9608
9999
|
async deleteSession(sessionToken) {
|
|
9609
10000
|
const session = await client.select().from(sessions).where(eq(sessions.sessionToken, sessionToken)).then((res) => res[0]) ?? null;
|
|
@@ -9651,8 +10042,9 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
9651
10042
|
__name(mySqlDrizzleAdapter, "mySqlDrizzleAdapter");
|
|
9652
10043
|
|
|
9653
10044
|
export {
|
|
10045
|
+
guid,
|
|
9654
10046
|
getCourseBuilderSchema,
|
|
9655
10047
|
createTables,
|
|
9656
10048
|
mySqlDrizzleAdapter
|
|
9657
10049
|
};
|
|
9658
|
-
//# sourceMappingURL=chunk-
|
|
10050
|
+
//# sourceMappingURL=chunk-VUS77FG3.js.map
|