@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,274 @@
|
|
|
1
|
+
import { and, desc, eq } from 'drizzle-orm'
|
|
2
|
+
import { v4 } from 'uuid'
|
|
3
|
+
|
|
4
|
+
import type { MerchantPort } from '@coursebuilder/core/ports'
|
|
5
|
+
import {
|
|
6
|
+
merchantChargeSchema,
|
|
7
|
+
merchantEventsSchema,
|
|
8
|
+
merchantPriceSchema,
|
|
9
|
+
merchantProductSchema,
|
|
10
|
+
type MerchantCharge,
|
|
11
|
+
type MerchantEvents,
|
|
12
|
+
type MerchantProduct,
|
|
13
|
+
type User,
|
|
14
|
+
} from '@coursebuilder/core/schemas'
|
|
15
|
+
import { merchantAccountSchema } from '@coursebuilder/core/schemas/merchant-account-schema'
|
|
16
|
+
import { merchantCustomerSchema } from '@coursebuilder/core/schemas/merchant-customer-schema'
|
|
17
|
+
import type { MerchantCustomer } from '@coursebuilder/core/schemas/merchant-customer-schema'
|
|
18
|
+
import {
|
|
19
|
+
MerchantSessionSchema,
|
|
20
|
+
type MerchantSession,
|
|
21
|
+
} from '@coursebuilder/core/schemas/merchant-session'
|
|
22
|
+
import { MerchantSubscriptionSchema } from '@coursebuilder/core/schemas/merchant-subscription'
|
|
23
|
+
import { logger as baseLogger } from '@coursebuilder/utils/logger'
|
|
24
|
+
|
|
25
|
+
import type { MySqlContext } from '../context.js'
|
|
26
|
+
|
|
27
|
+
const logger = baseLogger as unknown as {
|
|
28
|
+
error: (error: Error, attrs?: Record<string, unknown>) => void
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Creates the MySQL implementation of payment-processor mirror operations.
|
|
33
|
+
*
|
|
34
|
+
* @param context - The shared MySQL client and table set.
|
|
35
|
+
* @returns All sixteen MerchantPort operations.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const merchantPort = createMerchantPort(context)
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export function createMerchantPort({
|
|
43
|
+
client,
|
|
44
|
+
tables,
|
|
45
|
+
}: MySqlContext): MerchantPort {
|
|
46
|
+
const {
|
|
47
|
+
merchantAccount,
|
|
48
|
+
merchantCharge,
|
|
49
|
+
merchantCustomer,
|
|
50
|
+
merchantEvents,
|
|
51
|
+
merchantPrice,
|
|
52
|
+
merchantProduct,
|
|
53
|
+
merchantSession,
|
|
54
|
+
merchantSubscription: merchantSubscriptionTable,
|
|
55
|
+
} = tables
|
|
56
|
+
|
|
57
|
+
const merchantPort: MerchantPort = {
|
|
58
|
+
createMerchantCustomer: async (options) => {
|
|
59
|
+
await client.insert(merchantCustomer).values({
|
|
60
|
+
id: `mc_${v4()}`,
|
|
61
|
+
identifier: options.identifier,
|
|
62
|
+
merchantAccountId: options.merchantAccountId,
|
|
63
|
+
userId: options.userId,
|
|
64
|
+
status: 1,
|
|
65
|
+
})
|
|
66
|
+
return merchantCustomerSchema.parse(
|
|
67
|
+
await client.query.merchantCustomer.findFirst({
|
|
68
|
+
where: eq(merchantCustomer.identifier, options.identifier),
|
|
69
|
+
}),
|
|
70
|
+
)
|
|
71
|
+
},
|
|
72
|
+
getMerchantAccount: async (options) => {
|
|
73
|
+
return merchantAccountSchema.parse(
|
|
74
|
+
await client.query.merchantAccount.findFirst({
|
|
75
|
+
where: eq(merchantAccount.label, options.provider),
|
|
76
|
+
}),
|
|
77
|
+
)
|
|
78
|
+
},
|
|
79
|
+
getMerchantPriceForProductId: async (productId) => {
|
|
80
|
+
const merchantPriceData = await client.query.merchantPrice.findFirst({
|
|
81
|
+
where: and(
|
|
82
|
+
eq(merchantPrice.merchantProductId, productId),
|
|
83
|
+
eq(merchantPrice.status, 1),
|
|
84
|
+
),
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
const parsedMerchantPrice =
|
|
88
|
+
merchantPriceSchema.safeParse(merchantPriceData)
|
|
89
|
+
|
|
90
|
+
if (!parsedMerchantPrice.success) {
|
|
91
|
+
logger.error(parsedMerchantPrice.error, {
|
|
92
|
+
event: 'adapter.merchantPrice.parse_failed',
|
|
93
|
+
productId,
|
|
94
|
+
})
|
|
95
|
+
return null
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return parsedMerchantPrice.data
|
|
99
|
+
},
|
|
100
|
+
getMerchantProductForProductId: async (productId) => {
|
|
101
|
+
const merchantProductData = await client.query.merchantProduct.findFirst({
|
|
102
|
+
where: eq(merchantProduct.productId, productId),
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
if (!merchantProductData) return null
|
|
106
|
+
return merchantProductSchema.parse(merchantProductData)
|
|
107
|
+
},
|
|
108
|
+
getMerchantCustomerForUserId: async (userId) => {
|
|
109
|
+
const merchantCustomerData =
|
|
110
|
+
await client.query.merchantCustomer.findFirst({
|
|
111
|
+
where: eq(merchantCustomer.userId, userId),
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
if (!merchantCustomerData) return null
|
|
115
|
+
return merchantCustomerSchema.parse(merchantCustomerData)
|
|
116
|
+
},
|
|
117
|
+
async createMerchantSession(options): Promise<MerchantSession> {
|
|
118
|
+
const id = `ms_${v4()}`
|
|
119
|
+
await client.insert(merchantSession).values({
|
|
120
|
+
id,
|
|
121
|
+
identifier: options.identifier,
|
|
122
|
+
merchantAccountId: options.merchantAccountId,
|
|
123
|
+
...(options.organizationId
|
|
124
|
+
? { organizationId: options.organizationId }
|
|
125
|
+
: {}),
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
return MerchantSessionSchema.parse(
|
|
129
|
+
await client.query.merchantSession.findFirst({
|
|
130
|
+
where: eq(merchantSession.id, id),
|
|
131
|
+
}),
|
|
132
|
+
)
|
|
133
|
+
},
|
|
134
|
+
async findOrCreateMerchantCustomer(options: {
|
|
135
|
+
user: User
|
|
136
|
+
identifier: string
|
|
137
|
+
merchantAccountId: string
|
|
138
|
+
}): Promise<MerchantCustomer | null> {
|
|
139
|
+
const merchantCustomer = merchantCustomerSchema
|
|
140
|
+
.nullable()
|
|
141
|
+
.optional()
|
|
142
|
+
.parse(
|
|
143
|
+
await client.query.merchantCustomer.findFirst({
|
|
144
|
+
where: (merchantCustomer, { eq }) =>
|
|
145
|
+
eq(merchantCustomer.identifier, options.identifier),
|
|
146
|
+
}),
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
if (merchantCustomer) {
|
|
150
|
+
return merchantCustomer
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return await merchantPort.createMerchantCustomer({
|
|
154
|
+
identifier: options.identifier,
|
|
155
|
+
merchantAccountId: options.merchantAccountId,
|
|
156
|
+
userId: options.user.id,
|
|
157
|
+
})
|
|
158
|
+
},
|
|
159
|
+
async createMerchantEvent(options: {
|
|
160
|
+
merchantAccountId: string
|
|
161
|
+
identifier: string
|
|
162
|
+
payload: Record<string, any>
|
|
163
|
+
}): Promise<MerchantEvents> {
|
|
164
|
+
const eventId = `me_${v4()}`
|
|
165
|
+
|
|
166
|
+
await client.insert(merchantEvents).values({
|
|
167
|
+
id: eventId,
|
|
168
|
+
merchantAccountId: options.merchantAccountId,
|
|
169
|
+
identifier: options.identifier,
|
|
170
|
+
payload: options.payload,
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
const createdEvent = await client.query.merchantEvents.findFirst({
|
|
174
|
+
where: eq(merchantEvents.id, eventId),
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
return merchantEventsSchema.parse(createdEvent)
|
|
178
|
+
},
|
|
179
|
+
async getMerchantEventByIdentifier(
|
|
180
|
+
identifier: string,
|
|
181
|
+
): Promise<MerchantEvents | null> {
|
|
182
|
+
const event = await client.query.merchantEvents.findFirst({
|
|
183
|
+
where: eq(merchantEvents.identifier, identifier),
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
return event ? merchantEventsSchema.parse(event) : null
|
|
187
|
+
},
|
|
188
|
+
async getMerchantEventsByAccount(
|
|
189
|
+
merchantAccountId: string,
|
|
190
|
+
): Promise<MerchantEvents[]> {
|
|
191
|
+
const events = await client.query.merchantEvents.findMany({
|
|
192
|
+
where: eq(merchantEvents.merchantAccountId, merchantAccountId),
|
|
193
|
+
orderBy: [desc(merchantEvents.createdAt)],
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
return events.map((event) => merchantEventsSchema.parse(event))
|
|
197
|
+
},
|
|
198
|
+
async getMerchantCharge(
|
|
199
|
+
merchantChargeId: string,
|
|
200
|
+
): Promise<MerchantCharge | null> {
|
|
201
|
+
const mCharge = await client.query.merchantCharge.findFirst({
|
|
202
|
+
where: eq(merchantCharge.id, merchantChargeId),
|
|
203
|
+
})
|
|
204
|
+
const parsed = merchantChargeSchema.safeParse(mCharge)
|
|
205
|
+
if (!parsed.success) {
|
|
206
|
+
logger.error(parsed.error, {
|
|
207
|
+
event: 'adapter.merchantCharge.parse_failed',
|
|
208
|
+
merchantChargeId,
|
|
209
|
+
})
|
|
210
|
+
return null
|
|
211
|
+
}
|
|
212
|
+
return parsed.data
|
|
213
|
+
},
|
|
214
|
+
async getMerchantProduct(
|
|
215
|
+
stripeProductId: string,
|
|
216
|
+
): Promise<MerchantProduct | null> {
|
|
217
|
+
return merchantProductSchema.nullable().parse(
|
|
218
|
+
await client.query.merchantProduct.findFirst({
|
|
219
|
+
where: eq(merchantProduct.identifier, stripeProductId),
|
|
220
|
+
}),
|
|
221
|
+
)
|
|
222
|
+
},
|
|
223
|
+
getMerchantSubscription: async (merchantSubscriptionId: string) => {
|
|
224
|
+
return MerchantSubscriptionSchema.parse(
|
|
225
|
+
await client.query.merchantSubscription.findFirst({
|
|
226
|
+
where: eq(merchantSubscriptionTable.id, merchantSubscriptionId),
|
|
227
|
+
}),
|
|
228
|
+
)
|
|
229
|
+
},
|
|
230
|
+
createMerchantSubscription: async (options: {
|
|
231
|
+
merchantAccountId: string
|
|
232
|
+
merchantCustomerId: string
|
|
233
|
+
merchantProductId: string
|
|
234
|
+
identifier: string
|
|
235
|
+
}) => {
|
|
236
|
+
const id = crypto.randomUUID()
|
|
237
|
+
await client.insert(merchantSubscriptionTable).values({
|
|
238
|
+
...options,
|
|
239
|
+
id,
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
return MerchantSubscriptionSchema.parse(
|
|
243
|
+
await client.query.merchantSubscription.findFirst({
|
|
244
|
+
where: eq(merchantSubscriptionTable.id, id),
|
|
245
|
+
}),
|
|
246
|
+
)
|
|
247
|
+
},
|
|
248
|
+
updateMerchantSubscription: async (options: {
|
|
249
|
+
merchantSubscriptionId: string
|
|
250
|
+
status: string
|
|
251
|
+
}) => {
|
|
252
|
+
await client
|
|
253
|
+
.update(merchantSubscriptionTable)
|
|
254
|
+
.set({ status: Number(options.status) })
|
|
255
|
+
.where(eq(merchantSubscriptionTable.id, options.merchantSubscriptionId))
|
|
256
|
+
|
|
257
|
+
return MerchantSubscriptionSchema.parse(
|
|
258
|
+
await client.query.merchantSubscription.findFirst({
|
|
259
|
+
where: eq(
|
|
260
|
+
merchantSubscriptionTable.id,
|
|
261
|
+
options.merchantSubscriptionId,
|
|
262
|
+
),
|
|
263
|
+
}),
|
|
264
|
+
)
|
|
265
|
+
},
|
|
266
|
+
deleteMerchantSubscription: async (merchantSubscriptionId: string) => {
|
|
267
|
+
await client
|
|
268
|
+
.delete(merchantSubscriptionTable)
|
|
269
|
+
.where(eq(merchantSubscriptionTable.id, merchantSubscriptionId))
|
|
270
|
+
},
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return merchantPort
|
|
274
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { and, eq } from 'drizzle-orm'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
|
|
4
|
+
import type { OrganizationPort } from '@coursebuilder/core/ports'
|
|
5
|
+
import { OrganizationMemberSchema } from '@coursebuilder/core/schemas/organization-member'
|
|
6
|
+
import { OrganizationSchema } from '@coursebuilder/core/schemas/organization-schema'
|
|
7
|
+
|
|
8
|
+
import type { MySqlContext } from '../context.js'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Creates the MySQL implementation of the organization capability port.
|
|
12
|
+
*
|
|
13
|
+
* @param context - The shared MySQL client and table set.
|
|
14
|
+
* @returns All eight organization, membership, and member-role operations.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const organizationPort = createOrganizationPort(context)
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function createOrganizationPort({
|
|
22
|
+
client,
|
|
23
|
+
tables,
|
|
24
|
+
}: MySqlContext): OrganizationPort {
|
|
25
|
+
const {
|
|
26
|
+
organization: organizationTable,
|
|
27
|
+
organizationMemberships: organizationMembershipTable,
|
|
28
|
+
organizationMembershipRoles: organizationMembershipRoleTable,
|
|
29
|
+
roles: roleTable,
|
|
30
|
+
} = tables
|
|
31
|
+
|
|
32
|
+
const getOrganization: OrganizationPort['getOrganization'] = async (
|
|
33
|
+
organizationId,
|
|
34
|
+
) => {
|
|
35
|
+
return OrganizationSchema.parse(
|
|
36
|
+
await client.query.organization.findFirst({
|
|
37
|
+
where: eq(organizationTable.id, organizationId),
|
|
38
|
+
}),
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const getPersonalOrganization: OrganizationPort['getPersonalOrganization'] =
|
|
43
|
+
async (userId) => {
|
|
44
|
+
return OrganizationSchema.nullable().parse(
|
|
45
|
+
(await client.query.organization.findFirst({
|
|
46
|
+
where: eq(organizationTable.personalOrganizationUserId, userId),
|
|
47
|
+
})) ?? null,
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
createOrganization: async (options) => {
|
|
53
|
+
const organizationId = crypto.randomUUID()
|
|
54
|
+
await client.insert(organizationTable).values({
|
|
55
|
+
...options,
|
|
56
|
+
id: organizationId,
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
return getOrganization(organizationId)
|
|
60
|
+
},
|
|
61
|
+
getOrganization,
|
|
62
|
+
getPersonalOrganization,
|
|
63
|
+
createPersonalOrganization: async ({ userId, name }) => {
|
|
64
|
+
await client
|
|
65
|
+
.insert(organizationTable)
|
|
66
|
+
.values({
|
|
67
|
+
id: crypto.randomUUID(),
|
|
68
|
+
name,
|
|
69
|
+
personalOrganizationUserId: userId,
|
|
70
|
+
})
|
|
71
|
+
.onDuplicateKeyUpdate({
|
|
72
|
+
set: { personalOrganizationUserId: userId },
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
const organization = await getPersonalOrganization(userId)
|
|
76
|
+
if (!organization) {
|
|
77
|
+
throw new Error('Failed to create durable personal organization')
|
|
78
|
+
}
|
|
79
|
+
return organization
|
|
80
|
+
},
|
|
81
|
+
addMemberToOrganization: async (options) => {
|
|
82
|
+
const membershipWhere = options.personalOrganizationUserId
|
|
83
|
+
? eq(
|
|
84
|
+
organizationMembershipTable.personalOrganizationUserId,
|
|
85
|
+
options.personalOrganizationUserId,
|
|
86
|
+
)
|
|
87
|
+
: and(
|
|
88
|
+
eq(
|
|
89
|
+
organizationMembershipTable.organizationId,
|
|
90
|
+
options.organizationId,
|
|
91
|
+
),
|
|
92
|
+
eq(organizationMembershipTable.userId, options.userId),
|
|
93
|
+
)
|
|
94
|
+
const currentMembership =
|
|
95
|
+
await client.query.organizationMemberships.findFirst({
|
|
96
|
+
where: membershipWhere,
|
|
97
|
+
with: { organization: true, user: true },
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
if (!currentMembership) {
|
|
101
|
+
const insert = client.insert(organizationMembershipTable).values({
|
|
102
|
+
...options,
|
|
103
|
+
id: crypto.randomUUID(),
|
|
104
|
+
})
|
|
105
|
+
if (options.personalOrganizationUserId) {
|
|
106
|
+
await insert.onDuplicateKeyUpdate({
|
|
107
|
+
set: { userId: options.userId },
|
|
108
|
+
})
|
|
109
|
+
} else {
|
|
110
|
+
await insert
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return OrganizationMemberSchema.parse(
|
|
115
|
+
await client.query.organizationMemberships.findFirst({
|
|
116
|
+
where: membershipWhere,
|
|
117
|
+
with: { organization: true, user: true },
|
|
118
|
+
}),
|
|
119
|
+
)
|
|
120
|
+
},
|
|
121
|
+
removeMemberFromOrganization: async (options) => {
|
|
122
|
+
await client
|
|
123
|
+
.delete(organizationMembershipTable)
|
|
124
|
+
.where(
|
|
125
|
+
and(
|
|
126
|
+
eq(
|
|
127
|
+
organizationMembershipTable.organizationId,
|
|
128
|
+
options.organizationId,
|
|
129
|
+
),
|
|
130
|
+
eq(organizationMembershipTable.userId, options.userId),
|
|
131
|
+
),
|
|
132
|
+
)
|
|
133
|
+
},
|
|
134
|
+
addRoleForMember: async (options) => {
|
|
135
|
+
await client
|
|
136
|
+
.insert(roleTable)
|
|
137
|
+
.values({
|
|
138
|
+
name: options.role,
|
|
139
|
+
organizationId: options.organizationId,
|
|
140
|
+
id: crypto.randomUUID(),
|
|
141
|
+
})
|
|
142
|
+
.onDuplicateKeyUpdate({ set: { name: options.role } })
|
|
143
|
+
|
|
144
|
+
const role = z.object({ id: z.string() }).parse(
|
|
145
|
+
await client.query.roles.findFirst({
|
|
146
|
+
where: and(
|
|
147
|
+
eq(roleTable.organizationId, options.organizationId),
|
|
148
|
+
eq(roleTable.name, options.role),
|
|
149
|
+
),
|
|
150
|
+
}),
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
await client
|
|
154
|
+
.insert(organizationMembershipRoleTable)
|
|
155
|
+
.values({
|
|
156
|
+
organizationId: options.organizationId,
|
|
157
|
+
organizationMembershipId: options.memberId,
|
|
158
|
+
roleId: role.id,
|
|
159
|
+
})
|
|
160
|
+
.onDuplicateKeyUpdate({ set: { roleId: role.id } })
|
|
161
|
+
},
|
|
162
|
+
removeRoleForMember: async (options) => {
|
|
163
|
+
const existingRole = z
|
|
164
|
+
.object({
|
|
165
|
+
id: z.string(),
|
|
166
|
+
})
|
|
167
|
+
.nullable()
|
|
168
|
+
.parse(
|
|
169
|
+
await client.query.roles.findFirst({
|
|
170
|
+
where: and(
|
|
171
|
+
eq(roleTable.organizationId, options.organizationId),
|
|
172
|
+
eq(roleTable.name, options.role),
|
|
173
|
+
),
|
|
174
|
+
}),
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
const roleId = existingRole?.id
|
|
178
|
+
|
|
179
|
+
if (roleId) {
|
|
180
|
+
await client
|
|
181
|
+
.delete(organizationMembershipRoleTable)
|
|
182
|
+
.where(
|
|
183
|
+
and(
|
|
184
|
+
eq(organizationMembershipRoleTable.roleId, roleId),
|
|
185
|
+
eq(
|
|
186
|
+
organizationMembershipRoleTable.organizationMembershipId,
|
|
187
|
+
options.memberId,
|
|
188
|
+
),
|
|
189
|
+
),
|
|
190
|
+
)
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
getMembershipsForUser: async (userId) => {
|
|
194
|
+
return OrganizationMemberSchema.array().parse(
|
|
195
|
+
(await client.query.organizationMemberships.findMany({
|
|
196
|
+
where: eq(organizationMembershipTable.userId, userId),
|
|
197
|
+
with: {
|
|
198
|
+
organization: true,
|
|
199
|
+
user: true,
|
|
200
|
+
},
|
|
201
|
+
})) || [],
|
|
202
|
+
)
|
|
203
|
+
},
|
|
204
|
+
getOrganizationMembers: async (organizationId) => {
|
|
205
|
+
return OrganizationMemberSchema.array().parse(
|
|
206
|
+
(await client.query.organizationMemberships.findMany({
|
|
207
|
+
where: eq(organizationMembershipTable.organizationId, organizationId),
|
|
208
|
+
with: {
|
|
209
|
+
organization: true,
|
|
210
|
+
user: true,
|
|
211
|
+
},
|
|
212
|
+
})) || [],
|
|
213
|
+
)
|
|
214
|
+
},
|
|
215
|
+
}
|
|
216
|
+
}
|