@coursebuilder/adapter-drizzle 2.1.1 → 3.0.0-canary.0.0c9beb2ae
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-KIQLUFJX.js → chunk-2GW3BJE2.js} +2 -2
- package/dist/{chunk-M3WM5Q7W.js → chunk-33ZN7FN7.js} +2 -2
- package/dist/chunk-4VZJQAPV.js +74 -0
- package/dist/chunk-5FLS4ZBX.js +109 -0
- package/dist/chunk-5YR5M22S.js +147 -0
- package/dist/chunk-6XQ6C3IX.js +18 -0
- package/dist/chunk-AIDM2CH6.js +146 -0
- package/dist/chunk-ALTODDUX.js +173 -0
- package/dist/chunk-AZY2VRAE.js +63 -0
- package/dist/chunk-BS7T27VL.js +239 -0
- package/dist/chunk-CN3FCRLR.js +55 -0
- package/dist/chunk-EAXC4CQD.js +245 -0
- package/dist/chunk-EDDG2YFS.js +249 -0
- package/dist/chunk-EDKWCMA7.js +210 -0
- package/dist/{chunk-7FBSP3VD.js → chunk-EDM6DKA5.js} +2 -2
- package/dist/{chunk-EZEQQJNH.js → chunk-EIQBTF5J.js} +2 -2
- package/dist/chunk-FYT7RTVW.js +248 -0
- package/dist/{chunk-F56AI52P.js → chunk-INZTF6QV.js} +2 -2
- package/dist/{chunk-AP5HBIV4.js → chunk-JVHX4JHA.js} +2 -2
- package/dist/chunk-LWEKWDLC.js +300 -0
- package/dist/chunk-OJPEBGGE.js +139 -0
- package/dist/chunk-QKOSV34V.js +16268 -0
- package/dist/chunk-QO3QE3LE.js +330 -0
- package/dist/chunk-QQKNNFFB.js +399 -0
- package/dist/chunk-RBHCV3UW.js +20 -0
- package/dist/chunk-TNH2C27F.js +252 -0
- package/dist/chunk-TNWNW666.js +133 -0
- package/dist/chunk-VBEXYQ6L.js +156 -0
- package/dist/chunk-W3ILNMLD.js +265 -0
- package/dist/chunk-WJ2ZUXL3.js +71 -0
- package/dist/{chunk-PJORQUQP.js → chunk-WUMDFFN3.js} +2 -2
- package/dist/{chunk-2AW5KYAK.js → chunk-X7DRYXB7.js} +2 -2
- package/dist/{chunk-PNPTKVJ4.js → chunk-XUBZKYH6.js} +24 -15
- package/dist/{chunk-WWBSNLRC.js → chunk-ZY4AFKUQ.js} +2 -2
- package/dist/index.d.ts +5 -11
- package/dist/index.js +41 -18
- package/dist/lib/mysql/cms-resource-actions.cjs +15912 -4127
- package/dist/lib/mysql/cms-resource-actions.cjs.map +1 -1
- package/dist/lib/mysql/cms-resource-actions.d.cts +8 -38
- package/dist/lib/mysql/cms-resource-actions.d.ts +8 -38
- package/dist/lib/mysql/cms-resource-actions.js +2 -1
- package/dist/lib/mysql/context.cjs +3380 -0
- package/dist/lib/mysql/context.cjs.map +1 -0
- package/dist/lib/mysql/context.d.cts +15 -0
- package/dist/lib/mysql/context.d.ts +15 -0
- package/dist/lib/mysql/context.js +34 -0
- package/dist/lib/mysql/context.js.map +1 -0
- package/dist/lib/mysql/index.cjs +21875 -15261
- package/dist/lib/mysql/index.cjs.map +1 -1
- package/dist/lib/mysql/index.d.cts +24 -14300
- package/dist/lib/mysql/index.d.ts +24 -14300
- package/dist/lib/mysql/index.js +46 -22
- package/dist/lib/mysql/ports/auth-storage.cjs +84 -0
- package/dist/lib/mysql/ports/auth-storage.cjs.map +1 -0
- package/dist/lib/mysql/ports/auth-storage.d.cts +22 -0
- package/dist/lib/mysql/ports/auth-storage.d.ts +22 -0
- package/dist/lib/mysql/ports/auth-storage.js +8 -0
- package/dist/lib/mysql/ports/auth-storage.js.map +1 -0
- package/dist/lib/mysql/ports/catalog.cjs +16688 -0
- package/dist/lib/mysql/ports/catalog.cjs.map +1 -0
- package/dist/lib/mysql/ports/catalog.d.cts +24 -0
- package/dist/lib/mysql/ports/catalog.d.ts +24 -0
- package/dist/lib/mysql/ports/catalog.js +9 -0
- package/dist/lib/mysql/ports/catalog.js.map +1 -0
- package/dist/lib/mysql/ports/content-resource.cjs +321 -0
- package/dist/lib/mysql/ports/content-resource.cjs.map +1 -0
- package/dist/lib/mysql/ports/content-resource.d.cts +23 -0
- package/dist/lib/mysql/ports/content-resource.d.ts +23 -0
- package/dist/lib/mysql/ports/content-resource.js +8 -0
- package/dist/lib/mysql/ports/content-resource.js.map +1 -0
- package/dist/lib/mysql/ports/coupon.cjs +16524 -0
- package/dist/lib/mysql/ports/coupon.cjs.map +1 -0
- package/dist/lib/mysql/ports/coupon.d.cts +22 -0
- package/dist/lib/mysql/ports/coupon.d.ts +22 -0
- package/dist/lib/mysql/ports/coupon.js +9 -0
- package/dist/lib/mysql/ports/coupon.js.map +1 -0
- package/dist/lib/mysql/ports/entitlement.cjs +16350 -0
- package/dist/lib/mysql/ports/entitlement.cjs.map +1 -0
- package/dist/lib/mysql/ports/entitlement.d.cts +22 -0
- package/dist/lib/mysql/ports/entitlement.d.ts +22 -0
- package/dist/lib/mysql/ports/entitlement.js +9 -0
- package/dist/lib/mysql/ports/entitlement.js.map +1 -0
- package/dist/lib/mysql/ports/identity.cjs +154 -0
- package/dist/lib/mysql/ports/identity.cjs.map +1 -0
- package/dist/lib/mysql/ports/identity.d.cts +22 -0
- package/dist/lib/mysql/ports/identity.d.ts +22 -0
- package/dist/lib/mysql/ports/identity.js +8 -0
- package/dist/lib/mysql/ports/identity.js.map +1 -0
- package/dist/lib/mysql/ports/merchant.cjs +194 -0
- package/dist/lib/mysql/ports/merchant.cjs.map +1 -0
- package/dist/lib/mysql/ports/merchant.d.cts +22 -0
- package/dist/lib/mysql/ports/merchant.d.ts +22 -0
- package/dist/lib/mysql/ports/merchant.js +8 -0
- package/dist/lib/mysql/ports/merchant.js.map +1 -0
- package/dist/lib/mysql/ports/organization.cjs +16426 -0
- package/dist/lib/mysql/ports/organization.cjs.map +1 -0
- package/dist/lib/mysql/ports/organization.d.cts +22 -0
- package/dist/lib/mysql/ports/organization.d.ts +22 -0
- package/dist/lib/mysql/ports/organization.js +9 -0
- package/dist/lib/mysql/ports/organization.js.map +1 -0
- package/dist/lib/mysql/ports/progress.cjs +16544 -0
- package/dist/lib/mysql/ports/progress.cjs.map +1 -0
- package/dist/lib/mysql/ports/progress.d.cts +22 -0
- package/dist/lib/mysql/ports/progress.d.ts +22 -0
- package/dist/lib/mysql/ports/progress.js +9 -0
- package/dist/lib/mysql/ports/progress.js.map +1 -0
- package/dist/lib/mysql/ports/purchase.cjs +16609 -0
- package/dist/lib/mysql/ports/purchase.cjs.map +1 -0
- package/dist/lib/mysql/ports/purchase.d.cts +23 -0
- package/dist/lib/mysql/ports/purchase.d.ts +23 -0
- package/dist/lib/mysql/ports/purchase.js +9 -0
- package/dist/lib/mysql/ports/purchase.js.map +1 -0
- package/dist/lib/mysql/ports/subscription.cjs +76 -0
- package/dist/lib/mysql/ports/subscription.cjs.map +1 -0
- package/dist/lib/mysql/ports/subscription.d.cts +22 -0
- package/dist/lib/mysql/ports/subscription.d.ts +22 -0
- package/dist/lib/mysql/ports/subscription.js +8 -0
- package/dist/lib/mysql/ports/subscription.js.map +1 -0
- package/dist/lib/mysql/schema.cjs +3373 -0
- package/dist/lib/mysql/schema.cjs.map +1 -0
- package/dist/lib/mysql/schema.d.cts +14385 -0
- package/dist/lib/mysql/schema.d.ts +14385 -0
- package/dist/lib/mysql/schema.js +35 -0
- package/dist/lib/mysql/schema.js.map +1 -0
- package/dist/lib/mysql/schemas/auth/accounts.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/accounts.js +4 -4
- package/dist/lib/mysql/schemas/auth/device-access-token.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/device-access-token.js +5 -5
- package/dist/lib/mysql/schemas/auth/device-verification.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/device-verification.js +5 -5
- package/dist/lib/mysql/schemas/auth/personal-access-token.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/personal-access-token.js +5 -5
- package/dist/lib/mysql/schemas/auth/profiles.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/profiles.js +4 -4
- package/dist/lib/mysql/schemas/auth/role-permissions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/role-permissions.js +5 -5
- package/dist/lib/mysql/schemas/auth/roles.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/roles.js +4 -4
- package/dist/lib/mysql/schemas/auth/sessions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/sessions.js +5 -5
- package/dist/lib/mysql/schemas/auth/user-permissions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/user-permissions.js +4 -4
- package/dist/lib/mysql/schemas/auth/user-prefs.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/user-prefs.js +4 -4
- package/dist/lib/mysql/schemas/auth/user-roles.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/user-roles.js +4 -4
- package/dist/lib/mysql/schemas/auth/users.cjs +5 -1
- package/dist/lib/mysql/schemas/auth/users.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/users.js +4 -4
- package/dist/lib/mysql/schemas/commerce/coupon.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/coupon.js +4 -4
- package/dist/lib/mysql/schemas/commerce/merchant-charge.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-charge.js +4 -4
- package/dist/lib/mysql/schemas/commerce/merchant-subscription.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-subscription.js +4 -4
- package/dist/lib/mysql/schemas/commerce/price.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/price.js +4 -4
- package/dist/lib/mysql/schemas/commerce/product.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/product.js +4 -4
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.js +5 -5
- package/dist/lib/mysql/schemas/commerce/purchase.cjs +11 -2
- package/dist/lib/mysql/schemas/commerce/purchase.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/purchase.js +4 -4
- package/dist/lib/mysql/schemas/commerce/subscription.cjs +6 -1
- package/dist/lib/mysql/schemas/commerce/subscription.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/subscription.js +4 -4
- package/dist/lib/mysql/schemas/commerce/upgradable-products.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/upgradable-products.js +5 -5
- package/dist/lib/mysql/schemas/communication/comment.cjs +5 -1
- package/dist/lib/mysql/schemas/communication/comment.cjs.map +1 -1
- package/dist/lib/mysql/schemas/communication/comment.js +4 -4
- package/dist/lib/mysql/schemas/communication/communication-preferences.cjs +5 -1
- package/dist/lib/mysql/schemas/communication/communication-preferences.cjs.map +1 -1
- package/dist/lib/mysql/schemas/communication/communication-preferences.js +4 -4
- package/dist/lib/mysql/schemas/communication/question-response.cjs.map +1 -1
- package/dist/lib/mysql/schemas/communication/question-response.js +5 -5
- package/dist/lib/mysql/schemas/content/content-contributions.cjs +5 -1
- package/dist/lib/mysql/schemas/content/content-contributions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-contributions.js +4 -4
- package/dist/lib/mysql/schemas/content/content-resource-product.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-product.js +4 -4
- package/dist/lib/mysql/schemas/content/content-resource-resource.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-resource.js +4 -4
- package/dist/lib/mysql/schemas/content/content-resource-tag.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-tag.js +4 -4
- package/dist/lib/mysql/schemas/content/content-resource-version.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-version.js +4 -4
- package/dist/lib/mysql/schemas/content/content-resource.cjs +5 -1
- package/dist/lib/mysql/schemas/content/content-resource.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource.js +4 -4
- package/dist/lib/mysql/schemas/content/tag-tag.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/tag-tag.js +4 -4
- package/dist/lib/mysql/schemas/content/tag.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/tag.js +4 -4
- package/dist/lib/mysql/schemas/entitlements/entitlement.cjs +11 -2
- package/dist/lib/mysql/schemas/entitlements/entitlement.cjs.map +1 -1
- package/dist/lib/mysql/schemas/entitlements/entitlement.js +5 -5
- package/dist/lib/mysql/schemas/org/organization-membership-roles.cjs +11 -2
- package/dist/lib/mysql/schemas/org/organization-membership-roles.cjs.map +1 -1
- package/dist/lib/mysql/schemas/org/organization-membership-roles.js +4 -4
- package/dist/lib/mysql/schemas/org/organization-memberships.cjs +11 -2
- package/dist/lib/mysql/schemas/org/organization-memberships.cjs.map +1 -1
- package/dist/lib/mysql/schemas/org/organization-memberships.d.cts +16 -0
- package/dist/lib/mysql/schemas/org/organization-memberships.d.ts +16 -0
- package/dist/lib/mysql/schemas/org/organization-memberships.js +4 -4
- package/dist/lib/mysql/schemas/org/organizations.cjs +11 -2
- package/dist/lib/mysql/schemas/org/organizations.cjs.map +1 -1
- package/dist/lib/mysql/schemas/org/organizations.d.cts +16 -0
- package/dist/lib/mysql/schemas/org/organizations.d.ts +16 -0
- package/dist/lib/mysql/schemas/org/organizations.js +4 -4
- package/dist/lib/mysql/workflows/content-resource-workflow-utils.cjs +40 -0
- package/dist/lib/mysql/workflows/content-resource-workflow-utils.cjs.map +1 -0
- package/dist/lib/mysql/workflows/content-resource-workflow-utils.d.cts +4 -0
- package/dist/lib/mysql/workflows/content-resource-workflow-utils.d.ts +4 -0
- package/dist/lib/mysql/workflows/content-resource-workflow-utils.js +10 -0
- package/dist/lib/mysql/workflows/content-resource-workflow-utils.js.map +1 -0
- package/dist/lib/mysql/workflows/create-cohort.cjs +184 -0
- package/dist/lib/mysql/workflows/create-cohort.cjs.map +1 -0
- package/dist/lib/mysql/workflows/create-cohort.d.cts +24 -0
- package/dist/lib/mysql/workflows/create-cohort.d.ts +24 -0
- package/dist/lib/mysql/workflows/create-cohort.js +9 -0
- package/dist/lib/mysql/workflows/create-cohort.js.map +1 -0
- package/dist/lib/mysql/workflows/create-event-series.cjs +283 -0
- package/dist/lib/mysql/workflows/create-event-series.cjs.map +1 -0
- package/dist/lib/mysql/workflows/create-event-series.d.cts +24 -0
- package/dist/lib/mysql/workflows/create-event-series.d.ts +24 -0
- package/dist/lib/mysql/workflows/create-event-series.js +9 -0
- package/dist/lib/mysql/workflows/create-event-series.js.map +1 -0
- package/dist/lib/mysql/workflows/create-event.cjs +194 -0
- package/dist/lib/mysql/workflows/create-event.cjs.map +1 -0
- package/dist/lib/mysql/workflows/create-event.d.cts +24 -0
- package/dist/lib/mysql/workflows/create-event.d.ts +24 -0
- package/dist/lib/mysql/workflows/create-event.js +9 -0
- package/dist/lib/mysql/workflows/create-event.js.map +1 -0
- package/dist/lib/mysql/workflows/create-merchant-charge-and-purchase.cjs +231 -0
- package/dist/lib/mysql/workflows/create-merchant-charge-and-purchase.cjs.map +1 -0
- package/dist/lib/mysql/workflows/create-merchant-charge-and-purchase.d.cts +22 -0
- package/dist/lib/mysql/workflows/create-merchant-charge-and-purchase.d.ts +22 -0
- package/dist/lib/mysql/workflows/create-merchant-charge-and-purchase.js +8 -0
- package/dist/lib/mysql/workflows/create-merchant-charge-and-purchase.js.map +1 -0
- package/dist/lib/mysql/workflows/create-workshop.cjs +286 -0
- package/dist/lib/mysql/workflows/create-workshop.cjs.map +1 -0
- package/dist/lib/mysql/workflows/create-workshop.d.cts +24 -0
- package/dist/lib/mysql/workflows/create-workshop.d.ts +24 -0
- package/dist/lib/mysql/workflows/create-workshop.js +9 -0
- package/dist/lib/mysql/workflows/create-workshop.js.map +1 -0
- package/dist/lib/mysql/workflows/redeem-full-price-coupon.cjs +130 -0
- package/dist/lib/mysql/workflows/redeem-full-price-coupon.cjs.map +1 -0
- package/dist/lib/mysql/workflows/redeem-full-price-coupon.d.cts +24 -0
- package/dist/lib/mysql/workflows/redeem-full-price-coupon.d.ts +24 -0
- package/dist/lib/mysql/workflows/redeem-full-price-coupon.js +8 -0
- package/dist/lib/mysql/workflows/redeem-full-price-coupon.js.map +1 -0
- package/dist/lib/mysql/workflows/transfer-purchase-to-user.cjs +95 -0
- package/dist/lib/mysql/workflows/transfer-purchase-to-user.cjs.map +1 -0
- package/dist/lib/mysql/workflows/transfer-purchase-to-user.d.cts +30 -0
- package/dist/lib/mysql/workflows/transfer-purchase-to-user.d.ts +30 -0
- package/dist/lib/mysql/workflows/transfer-purchase-to-user.js +8 -0
- package/dist/lib/mysql/workflows/transfer-purchase-to-user.js.map +1 -0
- package/dist/lib/utils.d.cts +1 -10
- package/dist/lib/utils.d.ts +1 -10
- package/dist/types.d.ts +14 -0
- package/dist/types.js +1 -0
- package/package.json +9 -5
- package/src/index.ts +3 -2
- package/src/lib/mysql/context.ts +20 -0
- package/src/lib/mysql/index.ts +118 -4873
- package/src/lib/mysql/ports/auth-storage.ts +139 -0
- package/src/lib/mysql/ports/catalog.ts +610 -0
- package/src/lib/mysql/ports/content-resource.ts +442 -0
- package/src/lib/mysql/ports/coupon.ts +387 -0
- package/src/lib/mysql/ports/entitlement.ts +96 -0
- package/src/lib/mysql/ports/identity.ts +160 -0
- package/src/lib/mysql/ports/merchant.ts +274 -0
- package/src/lib/mysql/ports/organization.ts +216 -0
- package/src/lib/mysql/ports/progress.ts +366 -0
- package/src/lib/mysql/ports/purchase.ts +517 -0
- package/src/lib/mysql/ports/subscription.ts +93 -0
- package/src/lib/mysql/schema.ts +374 -0
- package/src/lib/mysql/schemas/org/organization-memberships.ts +7 -0
- package/src/lib/mysql/schemas/org/organizations.ts +8 -0
- package/src/lib/mysql/workflows/content-resource-workflow-utils.ts +22 -0
- package/src/lib/mysql/workflows/create-cohort.ts +239 -0
- package/src/lib/mysql/workflows/create-event-series.ts +384 -0
- package/src/lib/mysql/workflows/create-event.ts +232 -0
- package/src/lib/mysql/workflows/create-merchant-charge-and-purchase.ts +365 -0
- package/src/lib/mysql/workflows/create-workshop.ts +372 -0
- package/src/lib/mysql/workflows/redeem-full-price-coupon.ts +179 -0
- package/src/lib/mysql/workflows/transfer-purchase-to-user.ts +142 -0
- package/src/types.ts +33 -0
- package/dist/authjs.d.ts +0 -27
- package/dist/authjs.js +0 -1
- package/dist/chunk-62VSIVME.js +0 -4714
- package/dist/chunk-RVXF3JZ7.js +0 -8732
- package/dist/chunk-WEJL5OFI.js +0 -8732
- package/src/authjs.ts +0 -34
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-2X5XVNDN.js";
|
|
4
|
+
|
|
5
|
+
// src/lib/mysql/ports/merchant.ts
|
|
6
|
+
import { and, desc, eq } from "drizzle-orm";
|
|
7
|
+
import { v4 } from "uuid";
|
|
8
|
+
import { merchantChargeSchema, merchantEventsSchema, merchantPriceSchema, merchantProductSchema } from "@coursebuilder/core/schemas";
|
|
9
|
+
import { merchantAccountSchema } from "@coursebuilder/core/schemas/merchant-account-schema";
|
|
10
|
+
import { merchantCustomerSchema } from "@coursebuilder/core/schemas/merchant-customer-schema";
|
|
11
|
+
import { MerchantSessionSchema } from "@coursebuilder/core/schemas/merchant-session";
|
|
12
|
+
import { MerchantSubscriptionSchema } from "@coursebuilder/core/schemas/merchant-subscription";
|
|
13
|
+
import { logger as baseLogger } from "@coursebuilder/utils/logger";
|
|
14
|
+
var logger = baseLogger;
|
|
15
|
+
function createMerchantPort({ client, tables }) {
|
|
16
|
+
const { merchantAccount, merchantCharge, merchantCustomer, merchantEvents, merchantPrice, merchantProduct, merchantSession, merchantSubscription: merchantSubscriptionTable } = tables;
|
|
17
|
+
const merchantPort = {
|
|
18
|
+
createMerchantCustomer: async (options) => {
|
|
19
|
+
await client.insert(merchantCustomer).values({
|
|
20
|
+
id: `mc_${v4()}`,
|
|
21
|
+
identifier: options.identifier,
|
|
22
|
+
merchantAccountId: options.merchantAccountId,
|
|
23
|
+
userId: options.userId,
|
|
24
|
+
status: 1
|
|
25
|
+
});
|
|
26
|
+
return merchantCustomerSchema.parse(await client.query.merchantCustomer.findFirst({
|
|
27
|
+
where: eq(merchantCustomer.identifier, options.identifier)
|
|
28
|
+
}));
|
|
29
|
+
},
|
|
30
|
+
getMerchantAccount: async (options) => {
|
|
31
|
+
return merchantAccountSchema.parse(await client.query.merchantAccount.findFirst({
|
|
32
|
+
where: eq(merchantAccount.label, options.provider)
|
|
33
|
+
}));
|
|
34
|
+
},
|
|
35
|
+
getMerchantPriceForProductId: async (productId) => {
|
|
36
|
+
const merchantPriceData = await client.query.merchantPrice.findFirst({
|
|
37
|
+
where: and(eq(merchantPrice.merchantProductId, productId), eq(merchantPrice.status, 1))
|
|
38
|
+
});
|
|
39
|
+
const parsedMerchantPrice = merchantPriceSchema.safeParse(merchantPriceData);
|
|
40
|
+
if (!parsedMerchantPrice.success) {
|
|
41
|
+
logger.error(parsedMerchantPrice.error, {
|
|
42
|
+
event: "adapter.merchantPrice.parse_failed",
|
|
43
|
+
productId
|
|
44
|
+
});
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return parsedMerchantPrice.data;
|
|
48
|
+
},
|
|
49
|
+
getMerchantProductForProductId: async (productId) => {
|
|
50
|
+
const merchantProductData = await client.query.merchantProduct.findFirst({
|
|
51
|
+
where: eq(merchantProduct.productId, productId)
|
|
52
|
+
});
|
|
53
|
+
if (!merchantProductData)
|
|
54
|
+
return null;
|
|
55
|
+
return merchantProductSchema.parse(merchantProductData);
|
|
56
|
+
},
|
|
57
|
+
getMerchantCustomerForUserId: async (userId) => {
|
|
58
|
+
const merchantCustomerData = await client.query.merchantCustomer.findFirst({
|
|
59
|
+
where: eq(merchantCustomer.userId, userId)
|
|
60
|
+
});
|
|
61
|
+
if (!merchantCustomerData)
|
|
62
|
+
return null;
|
|
63
|
+
return merchantCustomerSchema.parse(merchantCustomerData);
|
|
64
|
+
},
|
|
65
|
+
async createMerchantSession(options) {
|
|
66
|
+
const id = `ms_${v4()}`;
|
|
67
|
+
await client.insert(merchantSession).values({
|
|
68
|
+
id,
|
|
69
|
+
identifier: options.identifier,
|
|
70
|
+
merchantAccountId: options.merchantAccountId,
|
|
71
|
+
...options.organizationId ? {
|
|
72
|
+
organizationId: options.organizationId
|
|
73
|
+
} : {}
|
|
74
|
+
});
|
|
75
|
+
return MerchantSessionSchema.parse(await client.query.merchantSession.findFirst({
|
|
76
|
+
where: eq(merchantSession.id, id)
|
|
77
|
+
}));
|
|
78
|
+
},
|
|
79
|
+
async findOrCreateMerchantCustomer(options) {
|
|
80
|
+
const merchantCustomer2 = merchantCustomerSchema.nullable().optional().parse(await client.query.merchantCustomer.findFirst({
|
|
81
|
+
where: (merchantCustomer3, { eq: eq2 }) => eq2(merchantCustomer3.identifier, options.identifier)
|
|
82
|
+
}));
|
|
83
|
+
if (merchantCustomer2) {
|
|
84
|
+
return merchantCustomer2;
|
|
85
|
+
}
|
|
86
|
+
return await merchantPort.createMerchantCustomer({
|
|
87
|
+
identifier: options.identifier,
|
|
88
|
+
merchantAccountId: options.merchantAccountId,
|
|
89
|
+
userId: options.user.id
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
async createMerchantEvent(options) {
|
|
93
|
+
const eventId = `me_${v4()}`;
|
|
94
|
+
await client.insert(merchantEvents).values({
|
|
95
|
+
id: eventId,
|
|
96
|
+
merchantAccountId: options.merchantAccountId,
|
|
97
|
+
identifier: options.identifier,
|
|
98
|
+
payload: options.payload
|
|
99
|
+
});
|
|
100
|
+
const createdEvent = await client.query.merchantEvents.findFirst({
|
|
101
|
+
where: eq(merchantEvents.id, eventId)
|
|
102
|
+
});
|
|
103
|
+
return merchantEventsSchema.parse(createdEvent);
|
|
104
|
+
},
|
|
105
|
+
async getMerchantEventByIdentifier(identifier) {
|
|
106
|
+
const event = await client.query.merchantEvents.findFirst({
|
|
107
|
+
where: eq(merchantEvents.identifier, identifier)
|
|
108
|
+
});
|
|
109
|
+
return event ? merchantEventsSchema.parse(event) : null;
|
|
110
|
+
},
|
|
111
|
+
async getMerchantEventsByAccount(merchantAccountId) {
|
|
112
|
+
const events = await client.query.merchantEvents.findMany({
|
|
113
|
+
where: eq(merchantEvents.merchantAccountId, merchantAccountId),
|
|
114
|
+
orderBy: [
|
|
115
|
+
desc(merchantEvents.createdAt)
|
|
116
|
+
]
|
|
117
|
+
});
|
|
118
|
+
return events.map((event) => merchantEventsSchema.parse(event));
|
|
119
|
+
},
|
|
120
|
+
async getMerchantCharge(merchantChargeId) {
|
|
121
|
+
const mCharge = await client.query.merchantCharge.findFirst({
|
|
122
|
+
where: eq(merchantCharge.id, merchantChargeId)
|
|
123
|
+
});
|
|
124
|
+
const parsed = merchantChargeSchema.safeParse(mCharge);
|
|
125
|
+
if (!parsed.success) {
|
|
126
|
+
logger.error(parsed.error, {
|
|
127
|
+
event: "adapter.merchantCharge.parse_failed",
|
|
128
|
+
merchantChargeId
|
|
129
|
+
});
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
return parsed.data;
|
|
133
|
+
},
|
|
134
|
+
async getMerchantProduct(stripeProductId) {
|
|
135
|
+
return merchantProductSchema.nullable().parse(await client.query.merchantProduct.findFirst({
|
|
136
|
+
where: eq(merchantProduct.identifier, stripeProductId)
|
|
137
|
+
}));
|
|
138
|
+
},
|
|
139
|
+
getMerchantSubscription: async (merchantSubscriptionId) => {
|
|
140
|
+
return MerchantSubscriptionSchema.parse(await client.query.merchantSubscription.findFirst({
|
|
141
|
+
where: eq(merchantSubscriptionTable.id, merchantSubscriptionId)
|
|
142
|
+
}));
|
|
143
|
+
},
|
|
144
|
+
createMerchantSubscription: async (options) => {
|
|
145
|
+
const id = crypto.randomUUID();
|
|
146
|
+
await client.insert(merchantSubscriptionTable).values({
|
|
147
|
+
...options,
|
|
148
|
+
id
|
|
149
|
+
});
|
|
150
|
+
return MerchantSubscriptionSchema.parse(await client.query.merchantSubscription.findFirst({
|
|
151
|
+
where: eq(merchantSubscriptionTable.id, id)
|
|
152
|
+
}));
|
|
153
|
+
},
|
|
154
|
+
updateMerchantSubscription: async (options) => {
|
|
155
|
+
await client.update(merchantSubscriptionTable).set({
|
|
156
|
+
status: Number(options.status)
|
|
157
|
+
}).where(eq(merchantSubscriptionTable.id, options.merchantSubscriptionId));
|
|
158
|
+
return MerchantSubscriptionSchema.parse(await client.query.merchantSubscription.findFirst({
|
|
159
|
+
where: eq(merchantSubscriptionTable.id, options.merchantSubscriptionId)
|
|
160
|
+
}));
|
|
161
|
+
},
|
|
162
|
+
deleteMerchantSubscription: async (merchantSubscriptionId) => {
|
|
163
|
+
await client.delete(merchantSubscriptionTable).where(eq(merchantSubscriptionTable.id, merchantSubscriptionId));
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
return merchantPort;
|
|
167
|
+
}
|
|
168
|
+
__name(createMerchantPort, "createMerchantPort");
|
|
169
|
+
|
|
170
|
+
export {
|
|
171
|
+
createMerchantPort
|
|
172
|
+
};
|
|
173
|
+
//# sourceMappingURL=chunk-ALTODDUX.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-2X5XVNDN.js";
|
|
4
|
+
|
|
5
|
+
// src/lib/mysql/ports/auth-storage.ts
|
|
6
|
+
import { addSeconds, isAfter } from "date-fns";
|
|
7
|
+
import { and, eq } from "drizzle-orm";
|
|
8
|
+
function createAuthStoragePort({ client, tables }) {
|
|
9
|
+
const { accounts, sessions, users, verificationTokens } = tables;
|
|
10
|
+
return {
|
|
11
|
+
createSession: async (data) => {
|
|
12
|
+
await client.insert(sessions).values(data);
|
|
13
|
+
return await client.select().from(sessions).where(eq(sessions.sessionToken, data.sessionToken)).then((res) => res[0]);
|
|
14
|
+
},
|
|
15
|
+
getSessionAndUser: async (data) => {
|
|
16
|
+
return await client.select({
|
|
17
|
+
session: sessions,
|
|
18
|
+
user: users
|
|
19
|
+
}).from(sessions).where(eq(sessions.sessionToken, data)).innerJoin(users, eq(users.id, sessions.userId)).then((res) => res[0]) ?? null;
|
|
20
|
+
},
|
|
21
|
+
updateSession: async (data) => {
|
|
22
|
+
await client.update(sessions).set(data).where(eq(sessions.sessionToken, data.sessionToken));
|
|
23
|
+
return await client.select().from(sessions).where(eq(sessions.sessionToken, data.sessionToken)).then((res) => res[0]);
|
|
24
|
+
},
|
|
25
|
+
deleteSession: async (sessionToken) => {
|
|
26
|
+
const session = await client.select().from(sessions).where(eq(sessions.sessionToken, sessionToken)).then((res) => res[0]) ?? null;
|
|
27
|
+
await client.delete(sessions).where(eq(sessions.sessionToken, sessionToken));
|
|
28
|
+
return session;
|
|
29
|
+
},
|
|
30
|
+
useVerificationToken: async (token) => {
|
|
31
|
+
try {
|
|
32
|
+
const deletedToken = await client.select().from(verificationTokens).where(and(eq(verificationTokens.identifier, token.identifier), eq(verificationTokens.token, token.token))).then((res) => res[0]) ?? null;
|
|
33
|
+
if (deletedToken?.createdAt) {
|
|
34
|
+
const TIMEOUT_IN_SECONDS = 90;
|
|
35
|
+
const expireMultipleClicks = addSeconds(deletedToken.createdAt, TIMEOUT_IN_SECONDS);
|
|
36
|
+
const now = /* @__PURE__ */ new Date();
|
|
37
|
+
if (isAfter(expireMultipleClicks, now)) {
|
|
38
|
+
const { id: _, ...verificationToken } = token;
|
|
39
|
+
return deletedToken;
|
|
40
|
+
}
|
|
41
|
+
await client.delete(verificationTokens).where(and(eq(verificationTokens.identifier, token.identifier), eq(verificationTokens.token, token.token)));
|
|
42
|
+
return deletedToken;
|
|
43
|
+
}
|
|
44
|
+
return deletedToken;
|
|
45
|
+
} catch (err) {
|
|
46
|
+
throw new Error("No verification token found.");
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
deleteUser: async (id) => {
|
|
50
|
+
const user = await client.select().from(users).where(eq(users.id, id)).then((res) => res[0] ?? null);
|
|
51
|
+
await client.delete(users).where(eq(users.id, id));
|
|
52
|
+
await client.delete(sessions).where(eq(sessions.userId, id));
|
|
53
|
+
await client.delete(accounts).where(eq(accounts.userId, id));
|
|
54
|
+
return user;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
__name(createAuthStoragePort, "createAuthStoragePort");
|
|
59
|
+
|
|
60
|
+
export {
|
|
61
|
+
createAuthStoragePort
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=chunk-AZY2VRAE.js.map
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import {
|
|
2
|
+
external_exports
|
|
3
|
+
} from "./chunk-QKOSV34V.js";
|
|
4
|
+
import {
|
|
5
|
+
__name
|
|
6
|
+
} from "./chunk-2X5XVNDN.js";
|
|
7
|
+
|
|
8
|
+
// src/lib/mysql/cms-resource-actions.ts
|
|
9
|
+
import { and, asc, desc, eq, inArray, isNull, notInArray, sql } from "drizzle-orm";
|
|
10
|
+
var jsonNumber = external_exports.preprocess((value) => value == null ? null : Number(value), external_exports.number().nullable().optional());
|
|
11
|
+
var CmsImageResourceRowSchema = external_exports.object({
|
|
12
|
+
id: external_exports.string(),
|
|
13
|
+
url: external_exports.string(),
|
|
14
|
+
alt: external_exports.string().optional().nullable(),
|
|
15
|
+
// Human filename (the uploaded file's name) — the media grid prefers it
|
|
16
|
+
// over `alt` for the tile label; absent on older rows.
|
|
17
|
+
name: external_exports.string().optional().nullable(),
|
|
18
|
+
// Row creation time — the media tab's unified grid sorts by it.
|
|
19
|
+
createdAt: external_exports.coerce.date().optional().nullable(),
|
|
20
|
+
// Cloudinary metadata — optional/nullable so pre-metadata rows keep
|
|
21
|
+
// working (JSON_EXTRACT returns NULL when the key is absent). Numeric
|
|
22
|
+
// coercion preserves null (plain z.coerce.number() would turn it into 0);
|
|
23
|
+
// MySQL JSON numerics can arrive as strings through some drivers.
|
|
24
|
+
width: jsonNumber,
|
|
25
|
+
height: jsonNumber,
|
|
26
|
+
bytes: jsonNumber,
|
|
27
|
+
format: external_exports.string().optional().nullable()
|
|
28
|
+
});
|
|
29
|
+
var ListResourcesForPickerInputSchema = external_exports.object({
|
|
30
|
+
types: external_exports.array(external_exports.string()).min(1),
|
|
31
|
+
search: external_exports.string().trim().max(200).optional(),
|
|
32
|
+
excludeIds: external_exports.array(external_exports.string()).default([]),
|
|
33
|
+
limit: external_exports.number().int().min(1).max(100).default(20)
|
|
34
|
+
});
|
|
35
|
+
function createCmsResourceActions(options) {
|
|
36
|
+
const { db, contentResource, contentResourceResource, contentResourceProduct, getAuthContext, getEditHref } = options;
|
|
37
|
+
const dbQuery = db.query;
|
|
38
|
+
async function assertCanUpdateContent() {
|
|
39
|
+
const { session, ability } = await getAuthContext();
|
|
40
|
+
if (!session?.user || !ability.can("update", "Content")) {
|
|
41
|
+
throw new Error("Unauthorized");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
__name(assertCanUpdateContent, "assertCanUpdateContent");
|
|
45
|
+
async function listResourcesForPicker(input) {
|
|
46
|
+
await assertCanUpdateContent();
|
|
47
|
+
const { types, search, excludeIds, limit } = ListResourcesForPickerInputSchema.parse(input);
|
|
48
|
+
const conditions = [
|
|
49
|
+
inArray(contentResource.type, types),
|
|
50
|
+
isNull(contentResource.deletedAt)
|
|
51
|
+
];
|
|
52
|
+
if (excludeIds.length > 0) {
|
|
53
|
+
conditions.push(notInArray(contentResource.id, excludeIds));
|
|
54
|
+
}
|
|
55
|
+
if (search) {
|
|
56
|
+
const escaped = search.replace(/[\\%_]/g, "\\$&");
|
|
57
|
+
conditions.push(sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.title')) LIKE ${`%${escaped}%`}`);
|
|
58
|
+
}
|
|
59
|
+
const rows = await db.select({
|
|
60
|
+
id: contentResource.id,
|
|
61
|
+
type: contentResource.type,
|
|
62
|
+
title: sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.title'))`,
|
|
63
|
+
// Generated (indexed) column — cheaper than a JSON_EXTRACT here.
|
|
64
|
+
slug: contentResource.slug,
|
|
65
|
+
state: sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.state'))`,
|
|
66
|
+
postType: sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.postType'))`,
|
|
67
|
+
updatedAt: contentResource.updatedAt
|
|
68
|
+
}).from(contentResource).where(and(...conditions)).orderBy(desc(contentResource.updatedAt)).limit(limit);
|
|
69
|
+
return rows.map((row) => ({
|
|
70
|
+
id: row.id,
|
|
71
|
+
type: row.type,
|
|
72
|
+
title: row.title ?? row.slug ?? row.id,
|
|
73
|
+
slug: row.slug ?? "",
|
|
74
|
+
state: row.state ?? "draft",
|
|
75
|
+
detail: row.postType ?? void 0,
|
|
76
|
+
updatedAt: row.updatedAt ?? void 0
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
__name(listResourcesForPicker, "listResourcesForPicker");
|
|
80
|
+
async function listVideoResourcesForPicker(input) {
|
|
81
|
+
await assertCanUpdateContent();
|
|
82
|
+
const excludeIds = input.excludeIds ?? [];
|
|
83
|
+
const limit = Math.min(Math.max(input.limit ?? 20, 1), 200);
|
|
84
|
+
const offset = Math.max(0, Math.floor(input.offset ?? 0));
|
|
85
|
+
const conditions = [
|
|
86
|
+
eq(contentResource.type, "videoResource"),
|
|
87
|
+
isNull(contentResource.deletedAt)
|
|
88
|
+
];
|
|
89
|
+
if (excludeIds.length > 0) {
|
|
90
|
+
conditions.push(notInArray(contentResource.id, excludeIds));
|
|
91
|
+
}
|
|
92
|
+
if (input.search) {
|
|
93
|
+
const escaped = input.search.replace(/[\\%_]/g, "\\$&");
|
|
94
|
+
conditions.push(sql`${contentResource.id} LIKE ${`%${escaped}%`}`);
|
|
95
|
+
}
|
|
96
|
+
const pageRows = await db.select({
|
|
97
|
+
id: contentResource.id,
|
|
98
|
+
createdAt: contentResource.createdAt
|
|
99
|
+
}).from(contentResource).where(and(...conditions)).orderBy(desc(contentResource.createdAt)).limit(offset + limit + 50);
|
|
100
|
+
if (pageRows.length === 0)
|
|
101
|
+
return [];
|
|
102
|
+
const detailRows = await db.select({
|
|
103
|
+
id: contentResource.id,
|
|
104
|
+
state: sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.state'))`,
|
|
105
|
+
muxPlaybackId: sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.muxPlaybackId'))`,
|
|
106
|
+
duration: sql`JSON_EXTRACT(${contentResource.fields}, '$.duration')`,
|
|
107
|
+
createdAt: contentResource.createdAt
|
|
108
|
+
}).from(contentResource).where(inArray(contentResource.id, pageRows.map((row) => row.id)));
|
|
109
|
+
const byId = new Map(detailRows.map((row) => [
|
|
110
|
+
row.id,
|
|
111
|
+
row
|
|
112
|
+
]));
|
|
113
|
+
const rows = pageRows.flatMap((page) => byId.get(page.id) ?? []).filter((row) => row.state !== "deleted" && row.state !== "errored").slice(offset, offset + limit);
|
|
114
|
+
return rows.map((row) => ({
|
|
115
|
+
id: row.id,
|
|
116
|
+
// videoResources have no title/slug — the filename-derived id is the
|
|
117
|
+
// human-readable handle.
|
|
118
|
+
title: row.id,
|
|
119
|
+
state: row.state ?? "processing",
|
|
120
|
+
thumbnailUrl: row.muxPlaybackId ? `https://image.mux.com/${row.muxPlaybackId}/thumbnail.png?width=96&height=54&fit_mode=smartcrop` : void 0,
|
|
121
|
+
duration: row.duration != null ? Number(row.duration) : null,
|
|
122
|
+
createdAt: row.createdAt
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
__name(listVideoResourcesForPicker, "listVideoResourcesForPicker");
|
|
126
|
+
async function listImageResources({ limit, offset = 0 }) {
|
|
127
|
+
const capped = Math.min(Math.max(1, Math.floor(limit)), 200);
|
|
128
|
+
const skip = Math.max(0, Math.floor(offset));
|
|
129
|
+
const rows = await db.select({
|
|
130
|
+
id: contentResource.id,
|
|
131
|
+
url: sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.url'))`,
|
|
132
|
+
alt: sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.alt'))`,
|
|
133
|
+
name: sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.name'))`,
|
|
134
|
+
createdAt: contentResource.createdAt,
|
|
135
|
+
// Cloudinary metadata — NULL on pre-metadata rows (backfillable).
|
|
136
|
+
width: sql`JSON_EXTRACT(${contentResource.fields}, '$.width')`,
|
|
137
|
+
height: sql`JSON_EXTRACT(${contentResource.fields}, '$.height')`,
|
|
138
|
+
bytes: sql`JSON_EXTRACT(${contentResource.fields}, '$.bytes')`,
|
|
139
|
+
format: sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.format'))`
|
|
140
|
+
}).from(contentResource).where(eq(contentResource.type, "imageResource")).orderBy(desc(contentResource.createdAt)).limit(capped).offset(skip);
|
|
141
|
+
const parsed = external_exports.array(CmsImageResourceRowSchema).safeParse(rows);
|
|
142
|
+
return parsed.success ? parsed.data : [];
|
|
143
|
+
}
|
|
144
|
+
__name(listImageResources, "listImageResources");
|
|
145
|
+
async function getPostListMemberships(postId) {
|
|
146
|
+
await assertCanUpdateContent();
|
|
147
|
+
const links = await dbQuery.contentResourceResource.findMany({
|
|
148
|
+
where: and(eq(contentResourceResource.resourceId, postId), isNull(contentResourceResource.deletedAt)),
|
|
149
|
+
with: {
|
|
150
|
+
resourceOf: true
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
return links.filter((link) => link.resourceOf?.type === "list" && !link.resourceOf.deletedAt).map((link) => {
|
|
154
|
+
const fields = link.resourceOf.fields ?? {};
|
|
155
|
+
return {
|
|
156
|
+
listId: link.resourceOf.id,
|
|
157
|
+
title: fields.title ?? fields.slug ?? link.resourceOf.id,
|
|
158
|
+
slug: fields.slug ?? void 0,
|
|
159
|
+
href: fields.slug ? getEditHref("list", fields.slug) : void 0,
|
|
160
|
+
position: link.position
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
__name(getPostListMemberships, "getPostListMemberships");
|
|
165
|
+
async function getResourceParents(resourceId) {
|
|
166
|
+
await assertCanUpdateContent();
|
|
167
|
+
const [containerLinks, productLinks] = await Promise.all([
|
|
168
|
+
dbQuery.contentResourceResource.findMany({
|
|
169
|
+
where: eq(contentResourceResource.resourceId, resourceId),
|
|
170
|
+
with: {
|
|
171
|
+
resourceOf: {
|
|
172
|
+
with: {
|
|
173
|
+
// Sibling JOIN rows only (no nested resource objects) —
|
|
174
|
+
// cheap, and enough to compute this resource's ordinal.
|
|
175
|
+
resources: {
|
|
176
|
+
orderBy: asc(contentResourceResource.position)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}),
|
|
182
|
+
dbQuery.contentResourceProduct.findMany({
|
|
183
|
+
where: and(eq(contentResourceProduct.resourceId, resourceId), isNull(contentResourceProduct.deletedAt)),
|
|
184
|
+
with: {
|
|
185
|
+
product: true
|
|
186
|
+
}
|
|
187
|
+
})
|
|
188
|
+
]);
|
|
189
|
+
const parents = [];
|
|
190
|
+
for (const link of containerLinks) {
|
|
191
|
+
const parent = link.resourceOf;
|
|
192
|
+
if (!parent || parent.deletedAt)
|
|
193
|
+
continue;
|
|
194
|
+
if (parent.type === "videoResource")
|
|
195
|
+
continue;
|
|
196
|
+
const slug = parent.fields?.slug ?? "";
|
|
197
|
+
const siblings = parent.resources ?? [];
|
|
198
|
+
const index = siblings.findIndex((sibling) => sibling.resourceId === resourceId);
|
|
199
|
+
parents.push({
|
|
200
|
+
id: parent.id,
|
|
201
|
+
type: parent.type,
|
|
202
|
+
title: parent.fields?.title ?? (slug || parent.id),
|
|
203
|
+
href: getEditHref(parent.type, slug || parent.id),
|
|
204
|
+
...index !== -1 && {
|
|
205
|
+
detail: `#${index + 1} of ${siblings.length}`
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
for (const link of productLinks) {
|
|
210
|
+
const product = link.product;
|
|
211
|
+
if (!product)
|
|
212
|
+
continue;
|
|
213
|
+
const slug = product.fields?.slug ?? "";
|
|
214
|
+
parents.push({
|
|
215
|
+
id: product.id,
|
|
216
|
+
type: "product",
|
|
217
|
+
title: product.name,
|
|
218
|
+
// Products aren't in the resource-paths registries; every app's
|
|
219
|
+
// product editor lives at /products/[slug]/edit.
|
|
220
|
+
href: `/products/${slug || product.id}/edit`
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
return parents;
|
|
224
|
+
}
|
|
225
|
+
__name(getResourceParents, "getResourceParents");
|
|
226
|
+
return {
|
|
227
|
+
listResourcesForPicker,
|
|
228
|
+
listVideoResourcesForPicker,
|
|
229
|
+
listImageResources,
|
|
230
|
+
getPostListMemberships,
|
|
231
|
+
getResourceParents
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
__name(createCmsResourceActions, "createCmsResourceActions");
|
|
235
|
+
|
|
236
|
+
export {
|
|
237
|
+
createCmsResourceActions
|
|
238
|
+
};
|
|
239
|
+
//# sourceMappingURL=chunk-BS7T27VL.js.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-2X5XVNDN.js";
|
|
4
|
+
|
|
5
|
+
// src/lib/mysql/ports/subscription.ts
|
|
6
|
+
import { eq } from "drizzle-orm";
|
|
7
|
+
import { MerchantSubscriptionSchema } from "@coursebuilder/core/schemas/merchant-subscription";
|
|
8
|
+
import { SubscriptionSchema } from "@coursebuilder/core/schemas/subscription";
|
|
9
|
+
function createSubscriptionPort({ client, tables }) {
|
|
10
|
+
const { merchantSubscription: merchantSubscriptionTable, subscription: subscriptionTable } = tables;
|
|
11
|
+
return {
|
|
12
|
+
createSubscription: async (options) => {
|
|
13
|
+
const id = `sub_${crypto.randomUUID()}`;
|
|
14
|
+
await client.insert(subscriptionTable).values({
|
|
15
|
+
...options,
|
|
16
|
+
id
|
|
17
|
+
});
|
|
18
|
+
return SubscriptionSchema.parse(await client.query.subscription.findFirst({
|
|
19
|
+
where: eq(subscriptionTable.id, id),
|
|
20
|
+
with: {
|
|
21
|
+
product: true
|
|
22
|
+
}
|
|
23
|
+
}));
|
|
24
|
+
},
|
|
25
|
+
getSubscriptionForStripeId: async (stripeSubscriptionId) => {
|
|
26
|
+
const merchantSubscriptionParsed = MerchantSubscriptionSchema.safeParse(await client.query.merchantSubscription.findFirst({
|
|
27
|
+
where: eq(merchantSubscriptionTable.identifier, stripeSubscriptionId)
|
|
28
|
+
}));
|
|
29
|
+
if (!merchantSubscriptionParsed.success) {
|
|
30
|
+
throw new Error(`No merchant subscription found for stripe id ${stripeSubscriptionId} ${merchantSubscriptionParsed.error}`);
|
|
31
|
+
}
|
|
32
|
+
const subscriptionParsed = SubscriptionSchema.safeParse(await client.query.subscription.findFirst({
|
|
33
|
+
where: eq(subscriptionTable.merchantSubscriptionId, merchantSubscriptionParsed.data.id),
|
|
34
|
+
with: {
|
|
35
|
+
product: true
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
if (!subscriptionParsed.success) {
|
|
39
|
+
throw new Error(`No subscription found for merchant subscription ${merchantSubscriptionParsed.data.id} ${subscriptionParsed.error}`);
|
|
40
|
+
}
|
|
41
|
+
return subscriptionParsed.data;
|
|
42
|
+
},
|
|
43
|
+
updateSubscriptionStatus: async (subscriptionId, status) => {
|
|
44
|
+
await client.update(subscriptionTable).set({
|
|
45
|
+
status
|
|
46
|
+
}).where(eq(subscriptionTable.id, subscriptionId));
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
__name(createSubscriptionPort, "createSubscriptionPort");
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
createSubscriptionPort
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=chunk-CN3FCRLR.js.map
|