@coursebuilder/adapter-drizzle 0.1.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-3RJVKNXB.js → chunk-4PJWD6YK.js} +421 -392
- package/dist/{chunk-WQ7UXKZC.js → chunk-J63FMGT7.js} +538 -200
- package/dist/{chunk-2CI3IGR2.js → chunk-MCARHGE5.js} +2 -2
- package/dist/{chunk-Q5WENQT6.js → chunk-PIQXK2CY.js} +2 -2
- package/dist/{chunk-5HT43CVZ.js → chunk-QMDE6HUA.js} +43 -3
- package/dist/{chunk-53266VWH.js → chunk-QY4TPO7D.js} +2 -2
- package/dist/chunk-ZD3R6UPJ.js +96 -0
- package/dist/index.js +11 -11
- package/dist/lib/mysql/index.cjs +1110 -671
- package/dist/lib/mysql/index.cjs.map +1 -1
- package/dist/lib/mysql/index.d.cts +26 -0
- package/dist/lib/mysql/index.d.ts +26 -0
- package/dist/lib/mysql/index.js +11 -11
- package/dist/lib/mysql/schemas/auth/accounts.cjs +83 -72
- package/dist/lib/mysql/schemas/auth/accounts.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/accounts.js +6 -3
- package/dist/lib/mysql/schemas/auth/role-permissions.cjs +73 -62
- package/dist/lib/mysql/schemas/auth/role-permissions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/role-permissions.js +7 -4
- package/dist/lib/mysql/schemas/auth/roles.cjs +73 -62
- package/dist/lib/mysql/schemas/auth/roles.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/roles.js +6 -3
- package/dist/lib/mysql/schemas/auth/sessions.cjs +73 -62
- package/dist/lib/mysql/schemas/auth/sessions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/sessions.js +7 -4
- package/dist/lib/mysql/schemas/auth/user-permissions.cjs +74 -63
- package/dist/lib/mysql/schemas/auth/user-permissions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/user-permissions.js +6 -3
- package/dist/lib/mysql/schemas/auth/user-roles.cjs +74 -63
- package/dist/lib/mysql/schemas/auth/user-roles.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/user-roles.js +6 -3
- package/dist/lib/mysql/schemas/auth/users.cjs +158 -147
- package/dist/lib/mysql/schemas/auth/users.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/users.js +6 -3
- package/dist/lib/mysql/schemas/commerce/coupon.cjs +209 -103
- package/dist/lib/mysql/schemas/commerce/coupon.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/coupon.d.cts +3 -0
- package/dist/lib/mysql/schemas/commerce/coupon.d.ts +3 -0
- package/dist/lib/mysql/schemas/commerce/coupon.js +6 -3
- package/dist/lib/mysql/schemas/commerce/merchant-charge.cjs +154 -10
- package/dist/lib/mysql/schemas/commerce/merchant-charge.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-charge.d.cts +7 -1
- package/dist/lib/mysql/schemas/commerce/merchant-charge.d.ts +7 -1
- package/dist/lib/mysql/schemas/commerce/merchant-charge.js +6 -1
- package/dist/lib/mysql/schemas/commerce/price.cjs +68 -57
- package/dist/lib/mysql/schemas/commerce/price.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/price.js +6 -3
- package/dist/lib/mysql/schemas/commerce/product.cjs +115 -104
- package/dist/lib/mysql/schemas/commerce/product.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/product.js +6 -3
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.cjs +251 -13
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.d.cts +7 -1
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.d.ts +7 -1
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.js +15 -1
- package/dist/lib/mysql/schemas/commerce/purchase.cjs +71 -56
- package/dist/lib/mysql/schemas/commerce/purchase.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/purchase.js +6 -3
- package/dist/lib/mysql/schemas/commerce/upgradable-products.cjs +75 -64
- package/dist/lib/mysql/schemas/commerce/upgradable-products.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/upgradable-products.js +7 -4
- package/dist/lib/mysql/schemas/communication/communication-preferences.cjs +96 -85
- package/dist/lib/mysql/schemas/communication/communication-preferences.cjs.map +1 -1
- package/dist/lib/mysql/schemas/communication/communication-preferences.js +6 -3
- package/dist/lib/mysql/schemas/content/content-contributions.cjs +100 -89
- package/dist/lib/mysql/schemas/content/content-contributions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-contributions.js +6 -3
- package/dist/lib/mysql/schemas/content/content-resource-product.cjs +66 -55
- package/dist/lib/mysql/schemas/content/content-resource-product.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-product.js +6 -3
- package/dist/lib/mysql/schemas/content/content-resource-resource.cjs +79 -68
- package/dist/lib/mysql/schemas/content/content-resource-resource.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-resource.js +6 -3
- package/dist/lib/mysql/schemas/content/content-resource.cjs +103 -92
- package/dist/lib/mysql/schemas/content/content-resource.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource.js +6 -3
- package/package.json +2 -2
- package/src/lib/mysql/index.ts +456 -95
- package/src/lib/mysql/schemas/commerce/coupon.ts +18 -1
- package/src/lib/mysql/schemas/commerce/merchant-charge.ts +29 -1
- package/src/lib/mysql/schemas/commerce/purchase-user-transfer.ts +29 -1
- package/dist/chunk-PJHGIRZM.js +0 -50
|
@@ -4,30 +4,22 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
getUpgradableProductsRelationsSchema,
|
|
6
6
|
getUpgradableProductsSchema
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import {
|
|
9
|
-
getMerchantCouponSchema
|
|
10
|
-
} from "./chunk-JKOYOL7A.js";
|
|
11
|
-
import {
|
|
12
|
-
getMerchantCustomerSchema
|
|
13
|
-
} from "./chunk-57CX5SOI.js";
|
|
7
|
+
} from "./chunk-QY4TPO7D.js";
|
|
14
8
|
import {
|
|
9
|
+
getPurchaseUserTransferRelationsSchema,
|
|
15
10
|
getPurchaseUserTransferSchema
|
|
16
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-QMDE6HUA.js";
|
|
17
12
|
import {
|
|
18
13
|
getSessionRelationsSchema,
|
|
19
14
|
getSessionsSchema
|
|
20
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-PIQXK2CY.js";
|
|
21
16
|
import {
|
|
22
17
|
getVerificationTokensSchema
|
|
23
18
|
} from "./chunk-MBB4GIJI.js";
|
|
24
|
-
import {
|
|
25
|
-
getMerchantAccountSchema
|
|
26
|
-
} from "./chunk-VXZRMVNY.js";
|
|
27
19
|
import {
|
|
28
20
|
getRolePermissionsRelationsSchema,
|
|
29
21
|
getRolePermissionsSchema
|
|
30
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-MCARHGE5.js";
|
|
31
23
|
import {
|
|
32
24
|
getAccountsRelationsSchema,
|
|
33
25
|
getAccountsSchema,
|
|
@@ -56,7 +48,7 @@ import {
|
|
|
56
48
|
getUserRolesSchema,
|
|
57
49
|
getUsersRelationsSchema,
|
|
58
50
|
getUsersSchema
|
|
59
|
-
} from "./chunk-
|
|
51
|
+
} from "./chunk-4PJWD6YK.js";
|
|
60
52
|
import {
|
|
61
53
|
getContributionTypesRelationsSchema,
|
|
62
54
|
getContributionTypesSchema
|
|
@@ -67,18 +59,28 @@ import {
|
|
|
67
59
|
import {
|
|
68
60
|
getCommunicationPreferenceTypesSchema
|
|
69
61
|
} from "./chunk-BX5SO2JG.js";
|
|
62
|
+
import {
|
|
63
|
+
getMerchantCouponSchema
|
|
64
|
+
} from "./chunk-JKOYOL7A.js";
|
|
70
65
|
import {
|
|
71
66
|
getMerchantPriceSchema
|
|
72
67
|
} from "./chunk-PPBEA4EM.js";
|
|
73
|
-
import {
|
|
74
|
-
getMerchantProductSchema
|
|
75
|
-
} from "./chunk-Y7QZGEPT.js";
|
|
76
68
|
import {
|
|
77
69
|
getMerchantSessionSchema
|
|
78
70
|
} from "./chunk-V23SCQL7.js";
|
|
79
71
|
import {
|
|
72
|
+
getMerchantChargeRelationsSchema,
|
|
80
73
|
getMerchantChargeSchema
|
|
81
|
-
} from "./chunk-
|
|
74
|
+
} from "./chunk-ZD3R6UPJ.js";
|
|
75
|
+
import {
|
|
76
|
+
getMerchantCustomerSchema
|
|
77
|
+
} from "./chunk-57CX5SOI.js";
|
|
78
|
+
import {
|
|
79
|
+
getMerchantProductSchema
|
|
80
|
+
} from "./chunk-Y7QZGEPT.js";
|
|
81
|
+
import {
|
|
82
|
+
getMerchantAccountSchema
|
|
83
|
+
} from "./chunk-VXZRMVNY.js";
|
|
82
84
|
import {
|
|
83
85
|
getPermissionsRelationsSchema,
|
|
84
86
|
getPermissionsSchema
|
|
@@ -89,7 +91,7 @@ import {
|
|
|
89
91
|
|
|
90
92
|
// src/lib/mysql/index.ts
|
|
91
93
|
import { addSeconds, isAfter } from "date-fns";
|
|
92
|
-
import { and, asc, eq, inArray, isNull, not, or, sql } from "drizzle-orm";
|
|
94
|
+
import { and, asc, desc, eq, gte, inArray, isNotNull, isNull, not, or, sql } from "drizzle-orm";
|
|
93
95
|
import { mysqlTable as defaultMySqlTableFn } from "drizzle-orm/mysql-core";
|
|
94
96
|
import { v4 } from "uuid";
|
|
95
97
|
|
|
@@ -686,11 +688,11 @@ var _ZodType = class _ZodType {
|
|
|
686
688
|
throw result.error;
|
|
687
689
|
}
|
|
688
690
|
safeParse(data, params) {
|
|
689
|
-
var
|
|
691
|
+
var _a46;
|
|
690
692
|
const ctx = {
|
|
691
693
|
common: {
|
|
692
694
|
issues: [],
|
|
693
|
-
async: (
|
|
695
|
+
async: (_a46 = params === null || params === void 0 ? void 0 : params.async) !== null && _a46 !== void 0 ? _a46 : false,
|
|
694
696
|
contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap
|
|
695
697
|
},
|
|
696
698
|
path: (params === null || params === void 0 ? void 0 : params.path) || [],
|
|
@@ -1035,7 +1037,7 @@ var _ZodString = class _ZodString extends ZodType {
|
|
|
1035
1037
|
} else if (check.kind === "url") {
|
|
1036
1038
|
try {
|
|
1037
1039
|
new URL(input.data);
|
|
1038
|
-
} catch (
|
|
1040
|
+
} catch (_a46) {
|
|
1039
1041
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
1040
1042
|
addIssueToContext(ctx, {
|
|
1041
1043
|
validation: "url",
|
|
@@ -1157,7 +1159,7 @@ var _ZodString = class _ZodString extends ZodType {
|
|
|
1157
1159
|
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
1158
1160
|
}
|
|
1159
1161
|
datetime(options) {
|
|
1160
|
-
var
|
|
1162
|
+
var _a46;
|
|
1161
1163
|
if (typeof options === "string") {
|
|
1162
1164
|
return this._addCheck({
|
|
1163
1165
|
kind: "datetime",
|
|
@@ -1169,7 +1171,7 @@ var _ZodString = class _ZodString extends ZodType {
|
|
|
1169
1171
|
return this._addCheck({
|
|
1170
1172
|
kind: "datetime",
|
|
1171
1173
|
precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
|
|
1172
|
-
offset: (
|
|
1174
|
+
offset: (_a46 = options === null || options === void 0 ? void 0 : options.offset) !== null && _a46 !== void 0 ? _a46 : false,
|
|
1173
1175
|
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
|
|
1174
1176
|
});
|
|
1175
1177
|
}
|
|
@@ -1299,11 +1301,11 @@ var _ZodString = class _ZodString extends ZodType {
|
|
|
1299
1301
|
__name(_ZodString, "ZodString");
|
|
1300
1302
|
var ZodString = _ZodString;
|
|
1301
1303
|
ZodString.create = (params) => {
|
|
1302
|
-
var
|
|
1304
|
+
var _a46;
|
|
1303
1305
|
return new ZodString({
|
|
1304
1306
|
checks: [],
|
|
1305
1307
|
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
1306
|
-
coerce: (
|
|
1308
|
+
coerce: (_a46 = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a46 !== void 0 ? _a46 : false,
|
|
1307
1309
|
...processCreateParams(params)
|
|
1308
1310
|
});
|
|
1309
1311
|
};
|
|
@@ -1709,11 +1711,11 @@ var _ZodBigInt = class _ZodBigInt extends ZodType {
|
|
|
1709
1711
|
__name(_ZodBigInt, "ZodBigInt");
|
|
1710
1712
|
var ZodBigInt = _ZodBigInt;
|
|
1711
1713
|
ZodBigInt.create = (params) => {
|
|
1712
|
-
var
|
|
1714
|
+
var _a46;
|
|
1713
1715
|
return new ZodBigInt({
|
|
1714
1716
|
checks: [],
|
|
1715
1717
|
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
1716
|
-
coerce: (
|
|
1718
|
+
coerce: (_a46 = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a46 !== void 0 ? _a46 : false,
|
|
1717
1719
|
...processCreateParams(params)
|
|
1718
1720
|
});
|
|
1719
1721
|
};
|
|
@@ -2240,8 +2242,8 @@ var _ZodObject = class _ZodObject extends ZodType {
|
|
|
2240
2242
|
unknownKeys: "strict",
|
|
2241
2243
|
...message !== void 0 ? {
|
|
2242
2244
|
errorMap: (issue, ctx) => {
|
|
2243
|
-
var
|
|
2244
|
-
const defaultError = (_c = (_b = (
|
|
2245
|
+
var _a46, _b, _c, _d;
|
|
2246
|
+
const defaultError = (_c = (_b = (_a46 = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a46, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
|
|
2245
2247
|
if (issue.code === "unrecognized_keys")
|
|
2246
2248
|
return {
|
|
2247
2249
|
message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError
|
|
@@ -3703,10 +3705,10 @@ ZodReadonly.create = (type, params) => {
|
|
|
3703
3705
|
var custom = /* @__PURE__ */ __name((check, params = {}, fatal) => {
|
|
3704
3706
|
if (check)
|
|
3705
3707
|
return ZodAny.create().superRefine((data, ctx) => {
|
|
3706
|
-
var
|
|
3708
|
+
var _a46, _b;
|
|
3707
3709
|
if (!check(data)) {
|
|
3708
3710
|
const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
|
|
3709
|
-
const _fatal = (_b = (
|
|
3711
|
+
const _fatal = (_b = (_a46 = p.fatal) !== null && _a46 !== void 0 ? _a46 : fatal) !== null && _b !== void 0 ? _b : true;
|
|
3710
3712
|
const p2 = typeof p === "string" ? { message: p } : p;
|
|
3711
3713
|
ctx.addIssue({ code: "custom", ...p2, fatal: _fatal });
|
|
3712
3714
|
}
|
|
@@ -3924,12 +3926,22 @@ var z = /* @__PURE__ */ Object.freeze({
|
|
|
3924
3926
|
|
|
3925
3927
|
// ../core/dist/chunk-VLQXSCFN.js
|
|
3926
3928
|
var __defProp = Object.defineProperty;
|
|
3929
|
+
var __defNormalProp = /* @__PURE__ */ __name((obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
3930
|
+
enumerable: true,
|
|
3931
|
+
configurable: true,
|
|
3932
|
+
writable: true,
|
|
3933
|
+
value
|
|
3934
|
+
}) : obj[key] = value, "__defNormalProp");
|
|
3927
3935
|
var __name2 = /* @__PURE__ */ __name((target, value) => __defProp(target, "name", {
|
|
3928
3936
|
value,
|
|
3929
3937
|
configurable: true
|
|
3930
3938
|
}), "__name");
|
|
3939
|
+
var __publicField = /* @__PURE__ */ __name((obj, key, value) => {
|
|
3940
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3941
|
+
return value;
|
|
3942
|
+
}, "__publicField");
|
|
3931
3943
|
|
|
3932
|
-
// ../core/dist/chunk-
|
|
3944
|
+
// ../core/dist/chunk-GH4VK5VM.js
|
|
3933
3945
|
var util2;
|
|
3934
3946
|
(function(util22) {
|
|
3935
3947
|
util22.assertEqual = (val) => val;
|
|
@@ -4583,11 +4595,11 @@ var _ZodType2 = (_a4 = class {
|
|
|
4583
4595
|
throw result.error;
|
|
4584
4596
|
}
|
|
4585
4597
|
safeParse(data, params) {
|
|
4586
|
-
var
|
|
4598
|
+
var _a46;
|
|
4587
4599
|
const ctx = {
|
|
4588
4600
|
common: {
|
|
4589
4601
|
issues: [],
|
|
4590
|
-
async: (
|
|
4602
|
+
async: (_a46 = params === null || params === void 0 ? void 0 : params.async) !== null && _a46 !== void 0 ? _a46 : false,
|
|
4591
4603
|
contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap
|
|
4592
4604
|
},
|
|
4593
4605
|
path: (params === null || params === void 0 ? void 0 : params.path) || [],
|
|
@@ -4949,7 +4961,7 @@ var _ZodString2 = (_a5 = class extends ZodType2 {
|
|
|
4949
4961
|
} else if (check.kind === "url") {
|
|
4950
4962
|
try {
|
|
4951
4963
|
new URL(input.data);
|
|
4952
|
-
} catch (
|
|
4964
|
+
} catch (_a46) {
|
|
4953
4965
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
4954
4966
|
addIssueToContext2(ctx, {
|
|
4955
4967
|
validation: "url",
|
|
@@ -5108,7 +5120,7 @@ var _ZodString2 = (_a5 = class extends ZodType2 {
|
|
|
5108
5120
|
});
|
|
5109
5121
|
}
|
|
5110
5122
|
datetime(options) {
|
|
5111
|
-
var
|
|
5123
|
+
var _a46;
|
|
5112
5124
|
if (typeof options === "string") {
|
|
5113
5125
|
return this._addCheck({
|
|
5114
5126
|
kind: "datetime",
|
|
@@ -5120,7 +5132,7 @@ var _ZodString2 = (_a5 = class extends ZodType2 {
|
|
|
5120
5132
|
return this._addCheck({
|
|
5121
5133
|
kind: "datetime",
|
|
5122
5134
|
precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
|
|
5123
|
-
offset: (
|
|
5135
|
+
offset: (_a46 = options === null || options === void 0 ? void 0 : options.offset) !== null && _a46 !== void 0 ? _a46 : false,
|
|
5124
5136
|
...errorUtil2.errToObj(options === null || options === void 0 ? void 0 : options.message)
|
|
5125
5137
|
});
|
|
5126
5138
|
}
|
|
@@ -5265,11 +5277,11 @@ var _ZodString2 = (_a5 = class extends ZodType2 {
|
|
|
5265
5277
|
__name2(_ZodString2, "ZodString");
|
|
5266
5278
|
var ZodString2 = _ZodString2;
|
|
5267
5279
|
ZodString2.create = (params) => {
|
|
5268
|
-
var
|
|
5280
|
+
var _a46;
|
|
5269
5281
|
return new ZodString2({
|
|
5270
5282
|
checks: [],
|
|
5271
5283
|
typeName: ZodFirstPartyTypeKind2.ZodString,
|
|
5272
|
-
coerce: (
|
|
5284
|
+
coerce: (_a46 = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a46 !== void 0 ? _a46 : false,
|
|
5273
5285
|
...processCreateParams2(params)
|
|
5274
5286
|
});
|
|
5275
5287
|
};
|
|
@@ -5690,11 +5702,11 @@ var _ZodBigInt2 = (_a7 = class extends ZodType2 {
|
|
|
5690
5702
|
__name2(_ZodBigInt2, "ZodBigInt");
|
|
5691
5703
|
var ZodBigInt2 = _ZodBigInt2;
|
|
5692
5704
|
ZodBigInt2.create = (params) => {
|
|
5693
|
-
var
|
|
5705
|
+
var _a46;
|
|
5694
5706
|
return new ZodBigInt2({
|
|
5695
5707
|
checks: [],
|
|
5696
5708
|
typeName: ZodFirstPartyTypeKind2.ZodBigInt,
|
|
5697
|
-
coerce: (
|
|
5709
|
+
coerce: (_a46 = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a46 !== void 0 ? _a46 : false,
|
|
5698
5710
|
...processCreateParams2(params)
|
|
5699
5711
|
});
|
|
5700
5712
|
};
|
|
@@ -6261,8 +6273,8 @@ var _ZodObject2 = (_a18 = class extends ZodType2 {
|
|
|
6261
6273
|
unknownKeys: "strict",
|
|
6262
6274
|
...message !== void 0 ? {
|
|
6263
6275
|
errorMap: (issue, ctx) => {
|
|
6264
|
-
var
|
|
6265
|
-
const defaultError = (_c = (_b = (
|
|
6276
|
+
var _a46, _b, _c, _d;
|
|
6277
|
+
const defaultError = (_c = (_b = (_a46 = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a46, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
|
|
6266
6278
|
if (issue.code === "unrecognized_keys")
|
|
6267
6279
|
return {
|
|
6268
6280
|
message: (_d = errorUtil2.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError
|
|
@@ -7857,12 +7869,12 @@ ZodReadonly2.create = (type, params) => {
|
|
|
7857
7869
|
var custom2 = /* @__PURE__ */ __name2((check, params = {}, fatal) => {
|
|
7858
7870
|
if (check)
|
|
7859
7871
|
return ZodAny2.create().superRefine((data, ctx) => {
|
|
7860
|
-
var
|
|
7872
|
+
var _a46, _b;
|
|
7861
7873
|
if (!check(data)) {
|
|
7862
7874
|
const p = typeof params === "function" ? params(data) : typeof params === "string" ? {
|
|
7863
7875
|
message: params
|
|
7864
7876
|
} : params;
|
|
7865
|
-
const _fatal = (_b = (
|
|
7877
|
+
const _fatal = (_b = (_a46 = p.fatal) !== null && _a46 !== void 0 ? _a46 : fatal) !== null && _b !== void 0 ? _b : true;
|
|
7866
7878
|
const p2 = typeof p === "string" ? {
|
|
7867
7879
|
message: p
|
|
7868
7880
|
} : p;
|
|
@@ -8096,7 +8108,7 @@ var z2 = /* @__PURE__ */ Object.freeze({
|
|
|
8096
8108
|
ZodError: ZodError2
|
|
8097
8109
|
});
|
|
8098
8110
|
|
|
8099
|
-
// ../core/dist/chunk-
|
|
8111
|
+
// ../core/dist/chunk-LMH5A7OR.js
|
|
8100
8112
|
var purchaseUserTransferSchema = z2.object({
|
|
8101
8113
|
id: z2.string().max(191),
|
|
8102
8114
|
transferState: z2.enum([
|
|
@@ -8118,7 +8130,51 @@ var purchaseUserTransferSchema = z2.object({
|
|
|
8118
8130
|
completedAt: z2.date().nullable()
|
|
8119
8131
|
});
|
|
8120
8132
|
|
|
8121
|
-
// ../core/dist/chunk-
|
|
8133
|
+
// ../core/dist/chunk-YYIPQN6H.js
|
|
8134
|
+
var ContentResourceResourceSchema = z2.object({
|
|
8135
|
+
resourceId: z2.string(),
|
|
8136
|
+
resourceOfId: z2.string(),
|
|
8137
|
+
position: z2.number().default(0),
|
|
8138
|
+
metadata: z2.record(z2.string(), z2.any()).default({}).nullable(),
|
|
8139
|
+
createdAt: z2.date().nullable(),
|
|
8140
|
+
updatedAt: z2.date().nullable(),
|
|
8141
|
+
deletedAt: z2.date().nullable(),
|
|
8142
|
+
resource: z2.any()
|
|
8143
|
+
});
|
|
8144
|
+
var ContentResourceSchema = z2.object({
|
|
8145
|
+
id: z2.string(),
|
|
8146
|
+
type: z2.string(),
|
|
8147
|
+
createdById: z2.string(),
|
|
8148
|
+
fields: z2.record(z2.string(), z2.any()).default({}).nullable().optional(),
|
|
8149
|
+
createdAt: z2.date().nullable(),
|
|
8150
|
+
updatedAt: z2.date().nullable(),
|
|
8151
|
+
deletedAt: z2.date().nullable(),
|
|
8152
|
+
resources: z2.array(ContentResourceResourceSchema).default([]).nullable()
|
|
8153
|
+
});
|
|
8154
|
+
var ContentResourceProductSchema = z2.object({
|
|
8155
|
+
resourceId: z2.string(),
|
|
8156
|
+
productId: z2.string(),
|
|
8157
|
+
position: z2.number().default(0),
|
|
8158
|
+
metadata: z2.record(z2.string(), z2.any()).default({}).nullable(),
|
|
8159
|
+
createdAt: z2.date().nullable(),
|
|
8160
|
+
updatedAt: z2.date().nullable(),
|
|
8161
|
+
deletedAt: z2.date().nullable(),
|
|
8162
|
+
resource: z2.any(),
|
|
8163
|
+
product: z2.any()
|
|
8164
|
+
});
|
|
8165
|
+
var ResourceStateSchema = z2.union([
|
|
8166
|
+
z2.literal("draft"),
|
|
8167
|
+
z2.literal("published"),
|
|
8168
|
+
z2.literal("archived"),
|
|
8169
|
+
z2.literal("deleted")
|
|
8170
|
+
]);
|
|
8171
|
+
var ResourceVisibilitySchema = z2.union([
|
|
8172
|
+
z2.literal("public"),
|
|
8173
|
+
z2.literal("private"),
|
|
8174
|
+
z2.literal("unlisted")
|
|
8175
|
+
]);
|
|
8176
|
+
|
|
8177
|
+
// ../core/dist/chunk-GCYJ74DO.js
|
|
8122
8178
|
var resourceProgressSchema = z2.object({
|
|
8123
8179
|
userId: z2.string().max(191),
|
|
8124
8180
|
contentResourceId: z2.string().max(191).optional().nullable(),
|
|
@@ -8127,8 +8183,15 @@ var resourceProgressSchema = z2.object({
|
|
|
8127
8183
|
updatedAt: z2.date().nullable(),
|
|
8128
8184
|
createdAt: z2.date().nullable()
|
|
8129
8185
|
});
|
|
8186
|
+
var moduleProgressSchema = z2.object({
|
|
8187
|
+
completedLessons: z2.array(resourceProgressSchema),
|
|
8188
|
+
nextResource: ContentResourceSchema.nullable(),
|
|
8189
|
+
percentCompleted: z2.number().default(0),
|
|
8190
|
+
completedLessonsCount: z2.number().default(0),
|
|
8191
|
+
totalLessonsCount: z2.number().default(0)
|
|
8192
|
+
});
|
|
8130
8193
|
|
|
8131
|
-
// ../core/dist/chunk-
|
|
8194
|
+
// ../core/dist/chunk-DLQA3JMA.js
|
|
8132
8195
|
var upgradableProductSchema = z2.object({
|
|
8133
8196
|
upgradableToId: z2.string().max(255),
|
|
8134
8197
|
upgradableFromId: z2.string().max(255),
|
|
@@ -8139,7 +8202,7 @@ var upgradableProductSchema = z2.object({
|
|
|
8139
8202
|
deletedAt: z2.date().nullable()
|
|
8140
8203
|
});
|
|
8141
8204
|
|
|
8142
|
-
// ../core/dist/chunk-
|
|
8205
|
+
// ../core/dist/chunk-G22WGQ3G.js
|
|
8143
8206
|
var VideoResourceSchema = z2.object({
|
|
8144
8207
|
id: z2.string(),
|
|
8145
8208
|
updatedAt: z2.string().optional(),
|
|
@@ -8161,7 +8224,7 @@ var VideoResourceSchema = z2.object({
|
|
|
8161
8224
|
])
|
|
8162
8225
|
});
|
|
8163
8226
|
|
|
8164
|
-
// ../core/dist/chunk-
|
|
8227
|
+
// ../core/dist/chunk-PS6USEN7.js
|
|
8165
8228
|
var merchantPriceSchema = z2.object({
|
|
8166
8229
|
id: z2.string().max(191),
|
|
8167
8230
|
merchantAccountId: z2.string().max(191),
|
|
@@ -8172,7 +8235,7 @@ var merchantPriceSchema = z2.object({
|
|
|
8172
8235
|
priceId: z2.string().max(191).optional().nullable()
|
|
8173
8236
|
});
|
|
8174
8237
|
|
|
8175
|
-
// ../core/dist/chunk-
|
|
8238
|
+
// ../core/dist/chunk-DAG4HKGL.js
|
|
8176
8239
|
var merchantProductSchema = z2.object({
|
|
8177
8240
|
id: z2.string().max(191),
|
|
8178
8241
|
merchantAccountId: z2.string().max(191),
|
|
@@ -8182,7 +8245,7 @@ var merchantProductSchema = z2.object({
|
|
|
8182
8245
|
createdAt: z2.date().nullable()
|
|
8183
8246
|
});
|
|
8184
8247
|
|
|
8185
|
-
// ../core/dist/chunk-
|
|
8248
|
+
// ../core/dist/chunk-CHYUPSYW.js
|
|
8186
8249
|
var userSchema = z2.object({
|
|
8187
8250
|
id: z2.string().max(255),
|
|
8188
8251
|
name: z2.string().max(255).optional().nullable(),
|
|
@@ -8191,12 +8254,18 @@ var userSchema = z2.object({
|
|
|
8191
8254
|
"admin"
|
|
8192
8255
|
]).default("user"),
|
|
8193
8256
|
email: z2.string().max(255).email(),
|
|
8194
|
-
emailVerified: z2.date().nullable(),
|
|
8257
|
+
emailVerified: z2.coerce.date().nullable(),
|
|
8195
8258
|
image: z2.string().max(255).optional().nullable(),
|
|
8196
|
-
createdAt: z2.date().nullable()
|
|
8259
|
+
createdAt: z2.coerce.date().nullable(),
|
|
8260
|
+
roles: z2.array(z2.object({
|
|
8261
|
+
id: z2.string(),
|
|
8262
|
+
name: z2.string(),
|
|
8263
|
+
description: z2.string().nullable(),
|
|
8264
|
+
active: z2.boolean()
|
|
8265
|
+
})).optional().default([])
|
|
8197
8266
|
});
|
|
8198
8267
|
|
|
8199
|
-
// ../core/dist/chunk-
|
|
8268
|
+
// ../core/dist/chunk-47RWEDJ6.js
|
|
8200
8269
|
var priceSchema = z2.object({
|
|
8201
8270
|
id: z2.string().max(191),
|
|
8202
8271
|
productId: z2.string().max(191).optional().nullable(),
|
|
@@ -8210,51 +8279,7 @@ var priceSchema = z2.object({
|
|
|
8210
8279
|
fields: z2.record(z2.any()).default({})
|
|
8211
8280
|
});
|
|
8212
8281
|
|
|
8213
|
-
// ../core/dist/chunk-
|
|
8214
|
-
var ContentResourceResourceSchema = z2.object({
|
|
8215
|
-
resourceId: z2.string(),
|
|
8216
|
-
resourceOfId: z2.string(),
|
|
8217
|
-
position: z2.number().default(0),
|
|
8218
|
-
metadata: z2.record(z2.string(), z2.any()).default({}).nullable(),
|
|
8219
|
-
createdAt: z2.date().nullable(),
|
|
8220
|
-
updatedAt: z2.date().nullable(),
|
|
8221
|
-
deletedAt: z2.date().nullable(),
|
|
8222
|
-
resource: z2.any()
|
|
8223
|
-
});
|
|
8224
|
-
var ContentResourceSchema = z2.object({
|
|
8225
|
-
id: z2.string(),
|
|
8226
|
-
type: z2.string(),
|
|
8227
|
-
createdById: z2.string(),
|
|
8228
|
-
fields: z2.record(z2.string(), z2.any()).default({}).nullable().optional(),
|
|
8229
|
-
createdAt: z2.date().nullable(),
|
|
8230
|
-
updatedAt: z2.date().nullable(),
|
|
8231
|
-
deletedAt: z2.date().nullable(),
|
|
8232
|
-
resources: z2.array(ContentResourceResourceSchema).default([]).nullable()
|
|
8233
|
-
});
|
|
8234
|
-
var ContentResourceProductSchema = z2.object({
|
|
8235
|
-
resourceId: z2.string(),
|
|
8236
|
-
productId: z2.string(),
|
|
8237
|
-
position: z2.number().default(0),
|
|
8238
|
-
metadata: z2.record(z2.string(), z2.any()).default({}).nullable(),
|
|
8239
|
-
createdAt: z2.date().nullable(),
|
|
8240
|
-
updatedAt: z2.date().nullable(),
|
|
8241
|
-
deletedAt: z2.date().nullable(),
|
|
8242
|
-
resource: z2.any(),
|
|
8243
|
-
product: z2.any()
|
|
8244
|
-
});
|
|
8245
|
-
var ResourceStateSchema = z2.union([
|
|
8246
|
-
z2.literal("draft"),
|
|
8247
|
-
z2.literal("published"),
|
|
8248
|
-
z2.literal("archived"),
|
|
8249
|
-
z2.literal("deleted")
|
|
8250
|
-
]);
|
|
8251
|
-
var ResourceVisibilitySchema = z2.union([
|
|
8252
|
-
z2.literal("public"),
|
|
8253
|
-
z2.literal("private"),
|
|
8254
|
-
z2.literal("unlisted")
|
|
8255
|
-
]);
|
|
8256
|
-
|
|
8257
|
-
// ../core/dist/chunk-EHEPZVSG.js
|
|
8282
|
+
// ../core/dist/chunk-DGMGNBW7.js
|
|
8258
8283
|
var productSchema = z2.object({
|
|
8259
8284
|
id: z2.string().max(191),
|
|
8260
8285
|
name: z2.string().max(191),
|
|
@@ -8270,8 +8295,8 @@ var productSchema = z2.object({
|
|
|
8270
8295
|
image: z2.object({
|
|
8271
8296
|
url: z2.string().url(),
|
|
8272
8297
|
alt: z2.string().optional().nullable(),
|
|
8273
|
-
width: z2.number(),
|
|
8274
|
-
height: z2.number()
|
|
8298
|
+
width: z2.number().optional().nullable(),
|
|
8299
|
+
height: z2.number().optional().nullable()
|
|
8275
8300
|
}).optional().nullable(),
|
|
8276
8301
|
action: z2.string().optional().nullable().default("Buy Now"),
|
|
8277
8302
|
state: z2.enum([
|
|
@@ -8293,7 +8318,7 @@ var productSchema = z2.object({
|
|
|
8293
8318
|
resources: z2.array(ContentResourceProductSchema).default([]).nullable()
|
|
8294
8319
|
});
|
|
8295
8320
|
|
|
8296
|
-
// ../core/dist/chunk-
|
|
8321
|
+
// ../core/dist/chunk-VDB4YSMY.js
|
|
8297
8322
|
var couponSchema = z2.object({
|
|
8298
8323
|
id: z2.string(),
|
|
8299
8324
|
code: z2.string().max(191).optional().nullable(),
|
|
@@ -8314,7 +8339,7 @@ var couponSchema = z2.object({
|
|
|
8314
8339
|
bulkCouponPurchases: z2.any().optional().nullable()
|
|
8315
8340
|
});
|
|
8316
8341
|
|
|
8317
|
-
// ../core/dist/chunk-
|
|
8342
|
+
// ../core/dist/chunk-OUYYSWMK.js
|
|
8318
8343
|
var purchaseSchema = z2.object({
|
|
8319
8344
|
id: z2.string().max(191),
|
|
8320
8345
|
userId: z2.string().max(191).optional().nullable(),
|
|
@@ -8341,7 +8366,7 @@ var purchaseSchema = z2.object({
|
|
|
8341
8366
|
product: productSchema.optional().nullable()
|
|
8342
8367
|
});
|
|
8343
8368
|
|
|
8344
|
-
// ../core/dist/chunk-
|
|
8369
|
+
// ../core/dist/chunk-SGE7BCRS.js
|
|
8345
8370
|
var merchantChargeSchema = z2.object({
|
|
8346
8371
|
id: z2.string().max(191),
|
|
8347
8372
|
status: z2.number().int().default(0),
|
|
@@ -8353,7 +8378,17 @@ var merchantChargeSchema = z2.object({
|
|
|
8353
8378
|
merchantCustomerId: z2.string().max(191)
|
|
8354
8379
|
});
|
|
8355
8380
|
|
|
8356
|
-
// ../core/dist/chunk-
|
|
8381
|
+
// ../core/dist/chunk-EDDT2FFU.js
|
|
8382
|
+
var merchantCustomerSchema = z2.object({
|
|
8383
|
+
id: z2.string().max(191),
|
|
8384
|
+
userId: z2.string().max(191),
|
|
8385
|
+
merchantAccountId: z2.string().max(191),
|
|
8386
|
+
identifier: z2.string().max(191),
|
|
8387
|
+
createdAt: z2.date().nullable(),
|
|
8388
|
+
status: z2.number().int().default(0)
|
|
8389
|
+
});
|
|
8390
|
+
|
|
8391
|
+
// ../core/dist/chunk-256SROW3.js
|
|
8357
8392
|
var merchantCouponSchema = z2.object({
|
|
8358
8393
|
id: z2.string().max(191),
|
|
8359
8394
|
identifier: z2.string().max(191).optional().nullable(),
|
|
@@ -8363,17 +8398,7 @@ var merchantCouponSchema = z2.object({
|
|
|
8363
8398
|
const decimalPlaces = value.toString().split(".")[1]?.length || 0;
|
|
8364
8399
|
return decimalPlaces <= 2;
|
|
8365
8400
|
}),
|
|
8366
|
-
type: z2.string().max(191)
|
|
8367
|
-
});
|
|
8368
|
-
|
|
8369
|
-
// ../core/dist/chunk-LQYMTPOB.js
|
|
8370
|
-
var merchantCustomerSchema = z2.object({
|
|
8371
|
-
id: z2.string().max(191),
|
|
8372
|
-
userId: z2.string().max(191),
|
|
8373
|
-
merchantAccountId: z2.string().max(191),
|
|
8374
|
-
identifier: z2.string().max(191),
|
|
8375
|
-
createdAt: z2.date().nullable(),
|
|
8376
|
-
status: z2.number().int().default(0)
|
|
8401
|
+
type: z2.string().max(191)
|
|
8377
8402
|
});
|
|
8378
8403
|
|
|
8379
8404
|
// ../core/dist/schemas/merchant-account-schema.js
|
|
@@ -8385,6 +8410,107 @@ var merchantAccountSchema = z2.object({
|
|
|
8385
8410
|
status: z2.number().int().default(0)
|
|
8386
8411
|
});
|
|
8387
8412
|
|
|
8413
|
+
// ../core/dist/chunk-F32UWPXN.js
|
|
8414
|
+
var _a41;
|
|
8415
|
+
var _CourseBuilderError = (_a41 = class extends Error {
|
|
8416
|
+
constructor(message, errorOptions) {
|
|
8417
|
+
var __super = /* @__PURE__ */ __name((...args) => {
|
|
8418
|
+
super(...args);
|
|
8419
|
+
__publicField(this, "type");
|
|
8420
|
+
__publicField(this, "kind");
|
|
8421
|
+
__publicField(this, "cause");
|
|
8422
|
+
return this;
|
|
8423
|
+
}, "__super");
|
|
8424
|
+
if (message instanceof Error) {
|
|
8425
|
+
__super(void 0, {
|
|
8426
|
+
cause: {
|
|
8427
|
+
err: message,
|
|
8428
|
+
...message.cause,
|
|
8429
|
+
...errorOptions
|
|
8430
|
+
}
|
|
8431
|
+
});
|
|
8432
|
+
} else if (typeof message === "string") {
|
|
8433
|
+
if (errorOptions instanceof Error) {
|
|
8434
|
+
errorOptions = {
|
|
8435
|
+
err: errorOptions,
|
|
8436
|
+
...errorOptions.cause
|
|
8437
|
+
};
|
|
8438
|
+
}
|
|
8439
|
+
__super(message, errorOptions);
|
|
8440
|
+
} else {
|
|
8441
|
+
__super(void 0, message);
|
|
8442
|
+
}
|
|
8443
|
+
this.name = this.constructor.name;
|
|
8444
|
+
this.type = this.constructor.type ?? "CourseBuilderError";
|
|
8445
|
+
this.kind = this.constructor.kind ?? "error";
|
|
8446
|
+
Error.captureStackTrace?.(this, this.constructor);
|
|
8447
|
+
const url = `https://errors.authjs.dev#${this.type.toLowerCase()}`;
|
|
8448
|
+
this.message += `${this.message ? ". " : ""}Read more at ${url}`;
|
|
8449
|
+
}
|
|
8450
|
+
}, __name(_a41, "_CourseBuilderError"), _a41);
|
|
8451
|
+
__name2(_CourseBuilderError, "CourseBuilderError");
|
|
8452
|
+
var CourseBuilderError = _CourseBuilderError;
|
|
8453
|
+
var _a42;
|
|
8454
|
+
var _AdapterError = (_a42 = class extends CourseBuilderError {
|
|
8455
|
+
}, __name(_a42, "_AdapterError"), _a42);
|
|
8456
|
+
__name2(_AdapterError, "AdapterError");
|
|
8457
|
+
__publicField(_AdapterError, "type", "AdapterError");
|
|
8458
|
+
var _a43;
|
|
8459
|
+
var _UnsupportedStrategy = (_a43 = class extends CourseBuilderError {
|
|
8460
|
+
}, __name(_a43, "_UnsupportedStrategy"), _a43);
|
|
8461
|
+
__name2(_UnsupportedStrategy, "UnsupportedStrategy");
|
|
8462
|
+
__publicField(_UnsupportedStrategy, "type", "UnsupportedStrategy");
|
|
8463
|
+
var _a44;
|
|
8464
|
+
var _MissingAdapter = (_a44 = class extends CourseBuilderError {
|
|
8465
|
+
}, __name(_a44, "_MissingAdapter"), _a44);
|
|
8466
|
+
__name2(_MissingAdapter, "MissingAdapter");
|
|
8467
|
+
__publicField(_MissingAdapter, "type", "MissingAdapter");
|
|
8468
|
+
var _a45;
|
|
8469
|
+
var _MissingAdapterMethods = (_a45 = class extends CourseBuilderError {
|
|
8470
|
+
}, __name(_a45, "_MissingAdapterMethods"), _a45);
|
|
8471
|
+
__name2(_MissingAdapterMethods, "MissingAdapterMethods");
|
|
8472
|
+
__publicField(_MissingAdapterMethods, "type", "MissingAdapterMethods");
|
|
8473
|
+
|
|
8474
|
+
// ../core/dist/chunk-B73XG2UO.js
|
|
8475
|
+
var red = "\x1B[31m";
|
|
8476
|
+
var yellow = "\x1B[33m";
|
|
8477
|
+
var grey = "\x1B[38;5;246m";
|
|
8478
|
+
var reset = "\x1B[0m";
|
|
8479
|
+
var logger = {
|
|
8480
|
+
error(error) {
|
|
8481
|
+
const name = error instanceof CourseBuilderError ? error.type : error.name;
|
|
8482
|
+
console.error(`${red}[coursebuilder][error]${reset} ${name}: ${error.message}`);
|
|
8483
|
+
if (error.cause && typeof error.cause === "object" && "err" in error.cause && error.cause.err instanceof Error) {
|
|
8484
|
+
const { err, ...data } = error.cause;
|
|
8485
|
+
console.error(`${red}[coursebuilder][cause]${reset}:`, err.stack);
|
|
8486
|
+
if (data)
|
|
8487
|
+
console.error(`${red}[coursebuilder][details]${reset}:`, JSON.stringify(data, null, 2));
|
|
8488
|
+
} else if (error.stack) {
|
|
8489
|
+
console.error(error.stack.replace(/.*/, "").substring(1));
|
|
8490
|
+
}
|
|
8491
|
+
},
|
|
8492
|
+
warn(code) {
|
|
8493
|
+
const url = `https://warnings.coursebuilder.dev#${code}`;
|
|
8494
|
+
console.warn(`${yellow}[coursebuilder][warn][${code}]${reset}`, `Read more: ${url}`);
|
|
8495
|
+
},
|
|
8496
|
+
debug(message, metadata) {
|
|
8497
|
+
console.log(`${grey}[coursebuilder][debug]:${reset} ${message}`, JSON.stringify(metadata, null, 2));
|
|
8498
|
+
}
|
|
8499
|
+
};
|
|
8500
|
+
function setLogger(newLogger = {}, debug) {
|
|
8501
|
+
if (!debug)
|
|
8502
|
+
logger.debug = () => {
|
|
8503
|
+
};
|
|
8504
|
+
if (newLogger.error)
|
|
8505
|
+
logger.error = newLogger.error;
|
|
8506
|
+
if (newLogger.warn)
|
|
8507
|
+
logger.warn = newLogger.warn;
|
|
8508
|
+
if (newLogger.debug)
|
|
8509
|
+
logger.debug = newLogger.debug;
|
|
8510
|
+
}
|
|
8511
|
+
__name(setLogger, "setLogger");
|
|
8512
|
+
__name2(setLogger, "setLogger");
|
|
8513
|
+
|
|
8388
8514
|
// ../core/dist/lib/utils/validate-coupon.js
|
|
8389
8515
|
import { isBefore } from "date-fns";
|
|
8390
8516
|
var validateCoupon = /* @__PURE__ */ __name2((coupon, productIds = []) => {
|
|
@@ -8437,6 +8563,7 @@ function getCourseBuilderSchema(mysqlTable) {
|
|
|
8437
8563
|
couponRelations: getCouponRelationsSchema(mysqlTable),
|
|
8438
8564
|
merchantAccount: getMerchantAccountSchema(mysqlTable),
|
|
8439
8565
|
merchantCharge: getMerchantChargeSchema(mysqlTable),
|
|
8566
|
+
merchantChargeRelations: getMerchantChargeRelationsSchema(mysqlTable),
|
|
8440
8567
|
merchantCoupon: getMerchantCouponSchema(mysqlTable),
|
|
8441
8568
|
merchantCustomer: getMerchantCustomerSchema(mysqlTable),
|
|
8442
8569
|
merchantPrice: getMerchantPriceSchema(mysqlTable),
|
|
@@ -8447,6 +8574,7 @@ function getCourseBuilderSchema(mysqlTable) {
|
|
|
8447
8574
|
purchases: getPurchaseSchema(mysqlTable),
|
|
8448
8575
|
purchaseRelations: getPurchaseRelationsSchema(mysqlTable),
|
|
8449
8576
|
purchaseUserTransfer: getPurchaseUserTransferSchema(mysqlTable),
|
|
8577
|
+
purchaseUserTransferRelations: getPurchaseUserTransferRelationsSchema(mysqlTable),
|
|
8450
8578
|
communicationChannel: getCommunicationChannelSchema(mysqlTable),
|
|
8451
8579
|
communicationPreferenceTypes: getCommunicationPreferenceTypesSchema(mysqlTable),
|
|
8452
8580
|
communicationPreferences: getCommunicationPreferencesSchema(mysqlTable),
|
|
@@ -8474,31 +8602,31 @@ function createTables(mySqlTable) {
|
|
|
8474
8602
|
__name(createTables, "createTables");
|
|
8475
8603
|
function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
8476
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);
|
|
8477
|
-
|
|
8605
|
+
const adapter = {
|
|
8478
8606
|
client,
|
|
8479
8607
|
async redeemFullPriceCoupon(options) {
|
|
8480
8608
|
const { email: baseEmail, couponId, productIds, currentUserId, redeemingProductId } = options;
|
|
8481
8609
|
const email = String(baseEmail).replace(" ", "+");
|
|
8482
|
-
const coupon2 = await
|
|
8610
|
+
const coupon2 = await adapter.getCouponWithBulkPurchases(couponId);
|
|
8483
8611
|
const productId = coupon2 && coupon2.restrictedToProductId || redeemingProductId;
|
|
8484
8612
|
if (!productId)
|
|
8485
8613
|
throw new Error(`unable-to-find-any-product-id`);
|
|
8486
8614
|
const couponValidation = validateCoupon(coupon2, productIds);
|
|
8487
8615
|
if (coupon2 && couponValidation.isRedeemable) {
|
|
8488
|
-
const bulkCouponRedemption = Boolean(coupon2.
|
|
8489
|
-
const { user } = await
|
|
8616
|
+
const bulkCouponRedemption = Boolean(coupon2.bulkPurchase?.bulkCouponId);
|
|
8617
|
+
const { user } = await adapter.findOrCreateUser(email);
|
|
8490
8618
|
if (!user)
|
|
8491
8619
|
throw new Error(`unable-to-create-user-${email}`);
|
|
8492
|
-
const currentUser = currentUserId ? await
|
|
8620
|
+
const currentUser = currentUserId ? await adapter.getUserById(currentUserId) : null;
|
|
8493
8621
|
const redeemingForCurrentUser = currentUser?.id === user.id;
|
|
8494
|
-
const existingPurchases = await
|
|
8622
|
+
const existingPurchases = await adapter.getExistingNonBulkValidPurchasesOfProduct({
|
|
8495
8623
|
userId: user.id,
|
|
8496
8624
|
productId
|
|
8497
8625
|
});
|
|
8498
8626
|
if (existingPurchases.length > 0)
|
|
8499
8627
|
throw new Error(`already-purchased-${email}`);
|
|
8500
8628
|
const purchaseId = `purchase-${v4()}`;
|
|
8501
|
-
await
|
|
8629
|
+
await adapter.createPurchase({
|
|
8502
8630
|
id: purchaseId,
|
|
8503
8631
|
userId: user.id,
|
|
8504
8632
|
couponId: bulkCouponRedemption ? null : coupon2.id,
|
|
@@ -8509,9 +8637,9 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8509
8637
|
couponUsedId: bulkCouponRedemption ? null : coupon2.id
|
|
8510
8638
|
}
|
|
8511
8639
|
});
|
|
8512
|
-
const newPurchase = await
|
|
8513
|
-
await
|
|
8514
|
-
await
|
|
8640
|
+
const newPurchase = await adapter.getPurchase(purchaseId);
|
|
8641
|
+
await adapter.incrementCouponUsedCount(coupon2.id);
|
|
8642
|
+
await adapter.createPurchaseTransfer({
|
|
8515
8643
|
sourceUserId: user.id,
|
|
8516
8644
|
purchaseId,
|
|
8517
8645
|
expiresAt: new Date(Date.now() + 1e3 * 60 * 60 * 24 * 7)
|
|
@@ -8593,14 +8721,17 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8593
8721
|
where: and(eq(upgradableProducts.upgradableFromId, upgradableFromId), eq(upgradableProducts.upgradableToId, upgradableToId))
|
|
8594
8722
|
}));
|
|
8595
8723
|
},
|
|
8596
|
-
availableUpgradesForProduct(purchases, productId) {
|
|
8724
|
+
async availableUpgradesForProduct(purchases, productId) {
|
|
8597
8725
|
const previousPurchaseProductIds = purchases.map(({ productId: productId2 }) => productId2);
|
|
8598
|
-
|
|
8599
|
-
|
|
8600
|
-
|
|
8726
|
+
if (previousPurchaseProductIds.length > 0) {
|
|
8727
|
+
return await client.query.upgradableProducts.findMany({
|
|
8728
|
+
where: and(eq(upgradableProducts.upgradableToId, productId), inArray(upgradableProducts.upgradableFromId, previousPurchaseProductIds))
|
|
8729
|
+
});
|
|
8730
|
+
}
|
|
8731
|
+
return [];
|
|
8601
8732
|
},
|
|
8602
8733
|
clearLessonProgressForUser(options) {
|
|
8603
|
-
throw new Error("Method not implemented.");
|
|
8734
|
+
throw new Error("clearLessonProgressForUser Method not implemented.");
|
|
8604
8735
|
},
|
|
8605
8736
|
async completeLessonProgressForUser(options) {
|
|
8606
8737
|
if (!options.lessonId) {
|
|
@@ -8635,8 +8766,20 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8635
8766
|
}
|
|
8636
8767
|
return parsedLessonProgress.data;
|
|
8637
8768
|
},
|
|
8638
|
-
couponForIdOrCode(options) {
|
|
8639
|
-
|
|
8769
|
+
async couponForIdOrCode(options) {
|
|
8770
|
+
if (!options.couponId && !options.code)
|
|
8771
|
+
return null;
|
|
8772
|
+
const couponForIdOrCode = await client.query.coupon.findFirst({
|
|
8773
|
+
where: or(and(or(options.code ? eq(coupon.code, options.code) : void 0, options.couponId ? eq(coupon.id, options.couponId) : void 0), gte(coupon.expires, /* @__PURE__ */ new Date())), and(or(options.code ? eq(coupon.code, options.code) : void 0, options.couponId ? eq(coupon.id, options.couponId) : void 0), isNull(coupon.expires))),
|
|
8774
|
+
with: {
|
|
8775
|
+
merchantCoupon: true
|
|
8776
|
+
}
|
|
8777
|
+
});
|
|
8778
|
+
if (!couponForIdOrCode)
|
|
8779
|
+
return null;
|
|
8780
|
+
return couponSchema.extend({
|
|
8781
|
+
merchantCoupon: merchantCouponSchema
|
|
8782
|
+
}).parse(couponForIdOrCode);
|
|
8640
8783
|
},
|
|
8641
8784
|
async createMerchantChargeAndPurchase(options) {
|
|
8642
8785
|
const purchaseId = await client.transaction(async (trx) => {
|
|
@@ -8673,14 +8816,8 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8673
8816
|
]))
|
|
8674
8817
|
}) || null);
|
|
8675
8818
|
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) => {
|
|
8676
|
-
console.log({
|
|
8677
|
-
res
|
|
8678
|
-
});
|
|
8679
8819
|
return res[0]?.coupons ?? null;
|
|
8680
8820
|
}));
|
|
8681
|
-
console.log({
|
|
8682
|
-
existingBulkCoupon
|
|
8683
|
-
});
|
|
8684
8821
|
const isBulkPurchase = quantity > 1 || Boolean(existingBulkCoupon) || options.bulk || Boolean(existingPurchase?.status === "Valid");
|
|
8685
8822
|
let bulkCouponId = null;
|
|
8686
8823
|
let couponToUpdate = null;
|
|
@@ -8712,21 +8849,12 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8712
8849
|
identifier: checkoutSessionId,
|
|
8713
8850
|
merchantAccountId
|
|
8714
8851
|
});
|
|
8715
|
-
console.log({
|
|
8716
|
-
newMerchantSession
|
|
8717
|
-
});
|
|
8718
8852
|
const merchantCouponUsed = stripeCouponId ? await client.query.merchantCoupon.findFirst({
|
|
8719
8853
|
where: eq(merchantCoupon.identifier, stripeCouponId)
|
|
8720
8854
|
}) : null;
|
|
8721
|
-
console.log({
|
|
8722
|
-
merchantCouponUsed
|
|
8723
|
-
});
|
|
8724
8855
|
const pppMerchantCoupon = appliedPPPStripeCouponId ? await client.query.merchantCoupon.findFirst({
|
|
8725
8856
|
where: and(eq(merchantCoupon.identifier, appliedPPPStripeCouponId), eq(merchantCoupon.type, "ppp"))
|
|
8726
8857
|
}) : null;
|
|
8727
|
-
console.log({
|
|
8728
|
-
pppMerchantCoupon
|
|
8729
|
-
});
|
|
8730
8858
|
const newPurchaseStatus = merchantCouponUsed?.type === "ppp" || pppMerchantCoupon ? "Restricted" : "Valid";
|
|
8731
8859
|
const newPurchase = await client.insert(purchaseTable).values({
|
|
8732
8860
|
id: purchaseId2,
|
|
@@ -8741,9 +8869,6 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8741
8869
|
upgradedFromId: upgradedFromPurchaseId || null,
|
|
8742
8870
|
couponId: usedCouponId || null
|
|
8743
8871
|
});
|
|
8744
|
-
console.log({
|
|
8745
|
-
newPurchase
|
|
8746
|
-
});
|
|
8747
8872
|
const oneWeekInMilliseconds = 1e3 * 60 * 60 * 24 * 7;
|
|
8748
8873
|
const newPurchaseUserTransfer = await client.insert(purchaseUserTransfer).values({
|
|
8749
8874
|
id: `put_${v4()}`,
|
|
@@ -8751,12 +8876,6 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8751
8876
|
expiresAt: existingPurchase ? /* @__PURE__ */ new Date() : new Date(Date.now() + oneWeekInMilliseconds),
|
|
8752
8877
|
sourceUserId: userId
|
|
8753
8878
|
});
|
|
8754
|
-
console.log({
|
|
8755
|
-
newPurchaseUserTransfer
|
|
8756
|
-
});
|
|
8757
|
-
console.log("inside", {
|
|
8758
|
-
purchaseId: purchaseId2
|
|
8759
|
-
});
|
|
8760
8879
|
return purchaseId2;
|
|
8761
8880
|
} catch (error) {
|
|
8762
8881
|
console.error(error);
|
|
@@ -8764,9 +8883,6 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8764
8883
|
throw error;
|
|
8765
8884
|
}
|
|
8766
8885
|
});
|
|
8767
|
-
console.log("putside", {
|
|
8768
|
-
purchaseId
|
|
8769
|
-
});
|
|
8770
8886
|
const parsedPurchase = purchaseSchema.safeParse(await client.query.purchases.findFirst({
|
|
8771
8887
|
where: eq(purchaseTable.id, purchaseId)
|
|
8772
8888
|
}));
|
|
@@ -8783,16 +8899,16 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8783
8899
|
if (merchantCustomer2) {
|
|
8784
8900
|
return merchantCustomer2;
|
|
8785
8901
|
}
|
|
8786
|
-
return await
|
|
8902
|
+
return await adapter.createMerchantCustomer({
|
|
8787
8903
|
identifier: options.identifier,
|
|
8788
8904
|
merchantAccountId: options.merchantAccountId,
|
|
8789
8905
|
userId: options.user.id
|
|
8790
8906
|
});
|
|
8791
8907
|
},
|
|
8792
8908
|
async findOrCreateUser(email, name) {
|
|
8793
|
-
const user = await
|
|
8909
|
+
const user = await adapter.getUserByEmail?.(email);
|
|
8794
8910
|
if (!user) {
|
|
8795
|
-
const newUser = await
|
|
8911
|
+
const newUser = await adapter.createUser?.({
|
|
8796
8912
|
id: `u_${v4()}`,
|
|
8797
8913
|
email,
|
|
8798
8914
|
name,
|
|
@@ -8814,26 +8930,154 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8814
8930
|
async getCoupon(couponIdOrCode) {
|
|
8815
8931
|
return couponSchema.nullable().parse(await client.select().from(coupon).where(or(eq(coupon.id, couponIdOrCode), eq(coupon.code, couponIdOrCode))).then((res) => res[0] ?? null));
|
|
8816
8932
|
},
|
|
8817
|
-
getCouponWithBulkPurchases(couponId) {
|
|
8818
|
-
|
|
8933
|
+
async getCouponWithBulkPurchases(couponId) {
|
|
8934
|
+
logger.debug("getCouponWithBulkPurchases", {
|
|
8935
|
+
couponId
|
|
8936
|
+
});
|
|
8937
|
+
let couponData;
|
|
8938
|
+
try {
|
|
8939
|
+
couponData = await client.query.coupon.findFirst({
|
|
8940
|
+
where: eq(coupon.id, couponId),
|
|
8941
|
+
with: {
|
|
8942
|
+
bulkPurchase: true,
|
|
8943
|
+
bulkCouponPurchases: true
|
|
8944
|
+
}
|
|
8945
|
+
}) || null;
|
|
8946
|
+
} catch (e) {
|
|
8947
|
+
console.log("getCouponWithBulkPurchases");
|
|
8948
|
+
logger.error(e);
|
|
8949
|
+
}
|
|
8950
|
+
if (!couponData) {
|
|
8951
|
+
logger.debug("getCouponWithBulkPurchases", {
|
|
8952
|
+
couponId,
|
|
8953
|
+
error: "no coupon found"
|
|
8954
|
+
});
|
|
8955
|
+
return null;
|
|
8956
|
+
}
|
|
8957
|
+
const parsedCoupon = couponSchema.merge(z.object({
|
|
8958
|
+
bulkCouponPurchases: z.array(purchaseSchema),
|
|
8959
|
+
bulkPurchase: purchaseSchema.nullable().optional()
|
|
8960
|
+
})).nullable().safeParse(couponData);
|
|
8961
|
+
if (!parsedCoupon.success) {
|
|
8962
|
+
console.error("Error parsing coupon", couponData);
|
|
8963
|
+
return null;
|
|
8964
|
+
}
|
|
8965
|
+
return parsedCoupon.data;
|
|
8819
8966
|
},
|
|
8820
|
-
getDefaultCoupon(productIds) {
|
|
8821
|
-
|
|
8967
|
+
async getDefaultCoupon(productIds) {
|
|
8968
|
+
const activeSaleCoupon = await client.query.coupon.findFirst({
|
|
8969
|
+
where: and(eq(coupon.status, 1), eq(coupon.default, true), gte(coupon.expires, /* @__PURE__ */ new Date()), or(productIds ? inArray(coupon.restrictedToProductId, productIds) : void 0, isNull(coupon.restrictedToProductId))),
|
|
8970
|
+
orderBy: desc(coupon.percentageDiscount),
|
|
8971
|
+
with: {
|
|
8972
|
+
merchantCoupon: true,
|
|
8973
|
+
product: true
|
|
8974
|
+
}
|
|
8975
|
+
});
|
|
8976
|
+
if (activeSaleCoupon) {
|
|
8977
|
+
const { restrictedToProductId } = activeSaleCoupon;
|
|
8978
|
+
const validForProdcutId = restrictedToProductId ? productIds?.includes(restrictedToProductId) : true;
|
|
8979
|
+
const { merchantCoupon: defaultMerchantCoupon, ...defaultCoupon } = activeSaleCoupon;
|
|
8980
|
+
if (validForProdcutId) {
|
|
8981
|
+
return {
|
|
8982
|
+
defaultMerchantCoupon: merchantCouponSchema.parse(defaultMerchantCoupon),
|
|
8983
|
+
defaultCoupon: couponSchema.parse(defaultCoupon)
|
|
8984
|
+
};
|
|
8985
|
+
}
|
|
8986
|
+
}
|
|
8987
|
+
return null;
|
|
8822
8988
|
},
|
|
8823
8989
|
getLessonProgressCountsByDate() {
|
|
8824
|
-
throw new Error("Method not implemented.");
|
|
8990
|
+
throw new Error("getLessonProgressCountsByDate Method not implemented.");
|
|
8825
8991
|
},
|
|
8826
|
-
getLessonProgressForUser(userId) {
|
|
8827
|
-
|
|
8992
|
+
async getLessonProgressForUser(userId) {
|
|
8993
|
+
const userProgress = await client.query.resourceProgress.findMany({
|
|
8994
|
+
where: eq(resourceProgress.userId, userId)
|
|
8995
|
+
});
|
|
8996
|
+
const parsed = z.array(resourceProgressSchema).safeParse(userProgress);
|
|
8997
|
+
if (!parsed.success) {
|
|
8998
|
+
console.error("Error parsing user progress", userProgress);
|
|
8999
|
+
return [];
|
|
9000
|
+
}
|
|
9001
|
+
return parsed.data;
|
|
9002
|
+
},
|
|
9003
|
+
async getModuleProgressForUser(userIdOrEmail, moduleIdOrSlug) {
|
|
9004
|
+
const module = await client.query.contentResource.findFirst({
|
|
9005
|
+
where: or(eq(contentResource.id, moduleIdOrSlug), eq(sql`JSON_EXTRACT (${contentResource.fields}, "$.slug")`, moduleIdOrSlug)),
|
|
9006
|
+
with: {
|
|
9007
|
+
resources: {
|
|
9008
|
+
orderBy: asc(contentResourceResource.position)
|
|
9009
|
+
}
|
|
9010
|
+
}
|
|
9011
|
+
});
|
|
9012
|
+
const parsedModule = ContentResourceSchema.parse(module);
|
|
9013
|
+
const moduleResources = await client.query.contentResourceResource.findMany({
|
|
9014
|
+
where: inArray(contentResourceResource.resourceOfId, parsedModule.resources?.map((r) => r.resourceId) ?? []),
|
|
9015
|
+
orderBy: asc(contentResourceResource.position)
|
|
9016
|
+
});
|
|
9017
|
+
const parsedModuleResources = z.array(ContentResourceResourceSchema).safeParse(moduleResources);
|
|
9018
|
+
if (!parsedModuleResources.success) {
|
|
9019
|
+
console.error("Error parsing module resources", parsedModuleResources.error);
|
|
9020
|
+
return {
|
|
9021
|
+
completedLessons: [],
|
|
9022
|
+
nextResource: null,
|
|
9023
|
+
percentCompleted: 0,
|
|
9024
|
+
completedLessonsCount: 0,
|
|
9025
|
+
totalLessonsCount: 0
|
|
9026
|
+
};
|
|
9027
|
+
}
|
|
9028
|
+
const user = await client.query.users.findFirst({
|
|
9029
|
+
where: or(eq(users.id, userIdOrEmail), eq(users.email, userIdOrEmail)),
|
|
9030
|
+
with: {
|
|
9031
|
+
roles: true
|
|
9032
|
+
}
|
|
9033
|
+
});
|
|
9034
|
+
if (!user) {
|
|
9035
|
+
console.error("User not found", userIdOrEmail);
|
|
9036
|
+
return {
|
|
9037
|
+
completedLessons: [],
|
|
9038
|
+
nextResource: null,
|
|
9039
|
+
percentCompleted: 0,
|
|
9040
|
+
completedLessonsCount: 0,
|
|
9041
|
+
totalLessonsCount: parsedModuleResources.data.length
|
|
9042
|
+
};
|
|
9043
|
+
}
|
|
9044
|
+
const parsedUser = userSchema.parse(user);
|
|
9045
|
+
const userProgress = await client.query.resourceProgress.findMany({
|
|
9046
|
+
where: and(eq(resourceProgress.userId, parsedUser.id), isNotNull(resourceProgress.completedAt), inArray(resourceProgress.contentResourceId, parsedModuleResources.data.map((r) => r.resourceId))),
|
|
9047
|
+
orderBy: asc(resourceProgress.completedAt)
|
|
9048
|
+
});
|
|
9049
|
+
const nextResourceId = moduleResources.find((r) => !userProgress.find((p) => p.contentResourceId === r.resourceId))?.resourceId;
|
|
9050
|
+
const nextResource = await client.query.contentResource.findFirst({
|
|
9051
|
+
where: eq(contentResource.id, nextResourceId)
|
|
9052
|
+
});
|
|
9053
|
+
const parsedNextResource = ContentResourceSchema.nullable().optional().default(null).parse(nextResource);
|
|
9054
|
+
const parsedProgress = z.array(resourceProgressSchema).safeParse(userProgress);
|
|
9055
|
+
if (!parsedProgress.success) {
|
|
9056
|
+
console.error("Error parsing user progress", parsedProgress.error);
|
|
9057
|
+
return {
|
|
9058
|
+
completedLessons: [],
|
|
9059
|
+
nextResource: null,
|
|
9060
|
+
percentCompleted: 0,
|
|
9061
|
+
completedLessonsCount: 0,
|
|
9062
|
+
totalLessonsCount: parsedModuleResources.data.length
|
|
9063
|
+
};
|
|
9064
|
+
}
|
|
9065
|
+
const percentCompleted = Math.round(parsedProgress.data.length / parsedModuleResources.data.length * 100);
|
|
9066
|
+
return {
|
|
9067
|
+
completedLessons: parsedProgress.data,
|
|
9068
|
+
nextResource: parsedNextResource,
|
|
9069
|
+
percentCompleted,
|
|
9070
|
+
completedLessonsCount: parsedProgress.data.length,
|
|
9071
|
+
totalLessonsCount: parsedModuleResources.data.length
|
|
9072
|
+
};
|
|
8828
9073
|
},
|
|
8829
9074
|
getLessonProgresses() {
|
|
8830
|
-
throw new Error("Method not implemented.");
|
|
9075
|
+
throw new Error("getLessonProgresses Method not implemented.");
|
|
8831
9076
|
},
|
|
8832
9077
|
async getMerchantCharge(merchantChargeId) {
|
|
8833
9078
|
const mCharge = await client.query.merchantCharge.findFirst({
|
|
8834
9079
|
where: eq(merchantCharge.id, merchantChargeId)
|
|
8835
9080
|
});
|
|
8836
|
-
console.log("mCharge", mCharge);
|
|
8837
9081
|
const parsed = merchantChargeSchema.safeParse(mCharge);
|
|
8838
9082
|
if (!parsed.success) {
|
|
8839
9083
|
console.error("Error parsing merchantCharge", mCharge);
|
|
@@ -8872,7 +9116,7 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8872
9116
|
}));
|
|
8873
9117
|
},
|
|
8874
9118
|
getPrice(productId) {
|
|
8875
|
-
throw new Error("
|
|
9119
|
+
throw new Error("getPrice not implemented.");
|
|
8876
9120
|
},
|
|
8877
9121
|
async getPriceForProduct(productId) {
|
|
8878
9122
|
return priceSchema.nullable().parse(await client.query.prices.findFirst({
|
|
@@ -8896,23 +9140,63 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8896
9140
|
...options,
|
|
8897
9141
|
id: newPurchaseId
|
|
8898
9142
|
});
|
|
8899
|
-
const newPurchase = await
|
|
9143
|
+
const newPurchase = await adapter.getPurchase(newPurchaseId);
|
|
8900
9144
|
return purchaseSchema.parse(newPurchase);
|
|
8901
9145
|
},
|
|
8902
9146
|
async getPurchaseForStripeCharge(stripeChargeId) {
|
|
8903
|
-
|
|
8904
|
-
|
|
9147
|
+
logger.debug("getPurchaseForStripeCharge", {
|
|
9148
|
+
stripeChargeId
|
|
9149
|
+
});
|
|
9150
|
+
const chargeForPurchase = merchantChargeSchema.nullable().parse(await client.query.merchantCharge.findFirst({
|
|
9151
|
+
where: eq(merchantCharge.identifier, stripeChargeId)
|
|
9152
|
+
}) || null);
|
|
9153
|
+
if (!chargeForPurchase) {
|
|
9154
|
+
logger.error(new Error("No charge found for purchase"));
|
|
9155
|
+
return null;
|
|
9156
|
+
}
|
|
9157
|
+
const purchase = purchaseSchema.safeParse(await client.query.purchases.findFirst({
|
|
9158
|
+
where: eq(purchaseTable.merchantChargeId, chargeForPurchase.id),
|
|
9159
|
+
with: {
|
|
9160
|
+
user: true,
|
|
9161
|
+
product: true,
|
|
9162
|
+
bulkCoupon: true
|
|
9163
|
+
}
|
|
8905
9164
|
}));
|
|
8906
9165
|
if (!purchase.success) {
|
|
8907
9166
|
return null;
|
|
8908
9167
|
}
|
|
8909
9168
|
return purchase.data;
|
|
8910
9169
|
},
|
|
8911
|
-
getPurchaseUserTransferById(options) {
|
|
8912
|
-
|
|
9170
|
+
async getPurchaseUserTransferById(options) {
|
|
9171
|
+
const purchaseTransferData = await client.query.purchaseUserTransfer.findFirst({
|
|
9172
|
+
where: eq(purchaseUserTransfer.id, options.id),
|
|
9173
|
+
with: {
|
|
9174
|
+
sourceUser: true,
|
|
9175
|
+
targetUser: true,
|
|
9176
|
+
purchase: true
|
|
9177
|
+
}
|
|
9178
|
+
});
|
|
9179
|
+
return purchaseUserTransferSchema.merge(z.object({
|
|
9180
|
+
sourceUser: userSchema,
|
|
9181
|
+
targetUser: userSchema.nullable(),
|
|
9182
|
+
purchase: purchaseSchema
|
|
9183
|
+
})).nullable().parse(purchaseTransferData);
|
|
8913
9184
|
},
|
|
8914
|
-
getPurchaseWithUser(purchaseId) {
|
|
8915
|
-
|
|
9185
|
+
async getPurchaseWithUser(purchaseId) {
|
|
9186
|
+
const purchaseData = await client.query.purchases.findFirst({
|
|
9187
|
+
where: eq(purchaseTable.id, purchaseId),
|
|
9188
|
+
with: {
|
|
9189
|
+
user: true
|
|
9190
|
+
}
|
|
9191
|
+
}) || null;
|
|
9192
|
+
const parsedPurchase = purchaseSchema.merge(z.object({
|
|
9193
|
+
user: userSchema
|
|
9194
|
+
})).nullable().safeParse(purchaseData);
|
|
9195
|
+
if (!parsedPurchase.success) {
|
|
9196
|
+
console.error("Error parsing purchase", parsedPurchase.error);
|
|
9197
|
+
return null;
|
|
9198
|
+
}
|
|
9199
|
+
return parsedPurchase.data;
|
|
8916
9200
|
},
|
|
8917
9201
|
async getPurchasesForUser(userId) {
|
|
8918
9202
|
if (!userId) {
|
|
@@ -8956,9 +9240,6 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8956
9240
|
});
|
|
8957
9241
|
const parsedPurchases = z.array(purchaseSchema).safeParse(userPurchases);
|
|
8958
9242
|
const allPurchases = parsedPurchases.success ? parsedPurchases.data : [];
|
|
8959
|
-
console.log("\u{1F9A6}", {
|
|
8960
|
-
allPurchases
|
|
8961
|
-
});
|
|
8962
9243
|
const thePurchase = await client.query.purchases.findFirst({
|
|
8963
9244
|
where: and(eq(purchaseTable.id, purchaseId), eq(purchaseTable.userId, userId)),
|
|
8964
9245
|
with: {
|
|
@@ -8974,9 +9255,6 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8974
9255
|
availableUpgrades: []
|
|
8975
9256
|
};
|
|
8976
9257
|
}
|
|
8977
|
-
console.log("\u{1F9A6}", {
|
|
8978
|
-
parsedPurchase: parsedPurchase.data
|
|
8979
|
-
});
|
|
8980
9258
|
const purchaseCanUpgrade = [
|
|
8981
9259
|
"Valid",
|
|
8982
9260
|
"Restricted"
|
|
@@ -8991,17 +9269,42 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
8991
9269
|
}
|
|
8992
9270
|
});
|
|
8993
9271
|
}
|
|
8994
|
-
const existingPurchase =
|
|
8995
|
-
|
|
9272
|
+
const existingPurchase = purchaseSchema.optional().nullable().parse(await client.query.purchases.findFirst({
|
|
9273
|
+
where: and(eq(purchaseTable.userId, userId), eq(purchaseTable.productId, parsedPurchase.data.productId), inArray(purchaseTable.status, [
|
|
9274
|
+
"Valid",
|
|
9275
|
+
"Restricted"
|
|
9276
|
+
]), isNull(purchaseTable.bulkCouponId), not(eq(purchaseTable.id, parsedPurchase.data.id))),
|
|
9277
|
+
with: {
|
|
9278
|
+
user: true,
|
|
9279
|
+
product: true,
|
|
9280
|
+
bulkCoupon: true
|
|
9281
|
+
}
|
|
9282
|
+
}) || null);
|
|
9283
|
+
return {
|
|
8996
9284
|
availableUpgrades: z.array(upgradableProductSchema).parse(availableUpgrades),
|
|
8997
9285
|
existingPurchase,
|
|
8998
9286
|
purchase: parsedPurchase.data
|
|
8999
|
-
}
|
|
9287
|
+
};
|
|
9000
9288
|
},
|
|
9001
9289
|
async getUserById(userId) {
|
|
9002
|
-
|
|
9003
|
-
where: eq(users.id, userId)
|
|
9004
|
-
|
|
9290
|
+
const user = await client.query.users.findFirst({
|
|
9291
|
+
where: eq(users.id, userId),
|
|
9292
|
+
with: {
|
|
9293
|
+
roles: {
|
|
9294
|
+
with: {
|
|
9295
|
+
role: true
|
|
9296
|
+
}
|
|
9297
|
+
}
|
|
9298
|
+
}
|
|
9299
|
+
}).then(async (res) => {
|
|
9300
|
+
if (res) {
|
|
9301
|
+
return {
|
|
9302
|
+
...res,
|
|
9303
|
+
roles: res.roles.map((r) => r.role)
|
|
9304
|
+
};
|
|
9305
|
+
}
|
|
9306
|
+
});
|
|
9307
|
+
return userSchema.nullable().parse(user ?? null);
|
|
9005
9308
|
},
|
|
9006
9309
|
async pricesOfPurchasesTowardOneBundle({ userId, bundleId }) {
|
|
9007
9310
|
if (userId === void 0)
|
|
@@ -9025,17 +9328,51 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
9025
9328
|
});
|
|
9026
9329
|
return z.array(priceSchema).parse(foundPrices);
|
|
9027
9330
|
},
|
|
9028
|
-
toggleLessonProgressForUser(options) {
|
|
9029
|
-
|
|
9331
|
+
async toggleLessonProgressForUser(options) {
|
|
9332
|
+
if (!options.lessonId) {
|
|
9333
|
+
throw new Error("No lessonId provided");
|
|
9334
|
+
}
|
|
9335
|
+
let lessonProgress = await client.query.resourceProgress.findFirst({
|
|
9336
|
+
where: and(eq(resourceProgress.userId, options.userId), eq(resourceProgress.contentResourceId, options.lessonId))
|
|
9337
|
+
});
|
|
9338
|
+
const now = /* @__PURE__ */ new Date();
|
|
9339
|
+
if (lessonProgress) {
|
|
9340
|
+
await client.update(resourceProgress).set({
|
|
9341
|
+
completedAt: lessonProgress.completedAt ? null : now,
|
|
9342
|
+
updatedAt: now
|
|
9343
|
+
}).where(eq(resourceProgress.contentResourceId, options.lessonId));
|
|
9344
|
+
} else {
|
|
9345
|
+
await client.insert(resourceProgress).values({
|
|
9346
|
+
userId: options.userId,
|
|
9347
|
+
contentResourceId: options.lessonId,
|
|
9348
|
+
completedAt: now,
|
|
9349
|
+
updatedAt: now
|
|
9350
|
+
});
|
|
9351
|
+
}
|
|
9352
|
+
lessonProgress = await client.query.resourceProgress.findFirst({
|
|
9353
|
+
where: and(eq(resourceProgress.userId, options.userId), eq(resourceProgress.contentResourceId, options.lessonId))
|
|
9354
|
+
});
|
|
9355
|
+
const parsedLessonProgress = resourceProgressSchema.safeParse(lessonProgress);
|
|
9356
|
+
if (!parsedLessonProgress.success) {
|
|
9357
|
+
console.error("Error parsing lesson progress", lessonProgress);
|
|
9358
|
+
return null;
|
|
9359
|
+
}
|
|
9360
|
+
return parsedLessonProgress.data;
|
|
9030
9361
|
},
|
|
9031
9362
|
transferPurchasesToNewUser(options) {
|
|
9032
9363
|
throw new Error("Method not implemented.");
|
|
9033
9364
|
},
|
|
9034
9365
|
updatePurchaseStatusForCharge(chargeId, status) {
|
|
9035
|
-
throw new Error("Method not implemented.");
|
|
9366
|
+
throw new Error("updatePurchaseStatusForCharge Method not implemented.");
|
|
9036
9367
|
},
|
|
9037
|
-
updatePurchaseUserTransferTransferState(options) {
|
|
9038
|
-
|
|
9368
|
+
async updatePurchaseUserTransferTransferState(options) {
|
|
9369
|
+
await client.update(purchaseUserTransfer).set({
|
|
9370
|
+
transferState: options.transferState
|
|
9371
|
+
}).where(eq(purchaseUserTransfer.id, options.id));
|
|
9372
|
+
const purchaseUserTransferData = await client.query.purchaseUserTransfer.findFirst({
|
|
9373
|
+
where: eq(purchaseUserTransfer.id, options.id)
|
|
9374
|
+
}) || null;
|
|
9375
|
+
return purchaseUserTransferSchema.nullable().parse(purchaseUserTransferData);
|
|
9039
9376
|
},
|
|
9040
9377
|
addResourceToResource: async function(options) {
|
|
9041
9378
|
const { parentResourceId, childResourceId } = options;
|
|
@@ -9282,6 +9619,7 @@ function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
|
9282
9619
|
return void 0;
|
|
9283
9620
|
}
|
|
9284
9621
|
};
|
|
9622
|
+
return adapter;
|
|
9285
9623
|
}
|
|
9286
9624
|
__name(mySqlDrizzleAdapter, "mySqlDrizzleAdapter");
|
|
9287
9625
|
|
|
@@ -9290,4 +9628,4 @@ export {
|
|
|
9290
9628
|
createTables,
|
|
9291
9629
|
mySqlDrizzleAdapter
|
|
9292
9630
|
};
|
|
9293
|
-
//# sourceMappingURL=chunk-
|
|
9631
|
+
//# sourceMappingURL=chunk-J63FMGT7.js.map
|