@coursebuilder/adapter-drizzle 0.5.2 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-QQA7STVO.js → chunk-3GONHHMY.js} +2 -2
- package/dist/{chunk-2UU2F4DM.js → chunk-6MRFUIH5.js} +6 -2
- package/dist/{chunk-XIGJFVUM.js → chunk-6YPHJWS2.js} +9 -2
- package/dist/{chunk-3NUCFLQJ.js → chunk-BLDW3QUS.js} +7 -3
- package/dist/{chunk-QP6YMUQX.js → chunk-DKJO4Y3K.js} +7 -3
- package/dist/{chunk-P4VXXTVA.js → chunk-EHRARBRS.js} +4 -1
- package/dist/{chunk-YVVXDJHI.js → chunk-ET3QAIY7.js} +9 -2
- package/dist/{chunk-27UC2HEP.js → chunk-FPAQINSA.js} +7 -3
- package/dist/{chunk-XJXCDN7B.js → chunk-HWIQUI7O.js} +8 -4
- package/dist/{chunk-4ZWS76VQ.js → chunk-KPBVZ44W.js} +7 -3
- package/dist/chunk-LPJ2P2KJ.js +2122 -0
- package/dist/{chunk-6ON2O6UD.js → chunk-MGZMGDQ5.js} +7 -3
- package/dist/{chunk-ZYQYJNLK.js → chunk-MOV5TUON.js} +409 -127
- package/dist/{chunk-KDEWFXEP.js → chunk-MP4CUWYC.js} +6 -2
- package/dist/{chunk-YMFPIZMO.js → chunk-OBUGOZKM.js} +2 -2
- package/dist/{chunk-EFVZ7IN4.js → chunk-PBTEHA7F.js} +2 -2
- package/dist/{chunk-GINRTL6J.js → chunk-WJWJ6E5Y.js} +6 -2
- package/dist/{chunk-YGRYHMCG.js → chunk-WPJZAYX7.js} +7 -3
- package/dist/{chunk-6SLQW6OM.js → chunk-YQNIXCD3.js} +5 -2
- package/dist/index.js +19 -20
- package/dist/lib/mysql/index.cjs +1889 -994
- package/dist/lib/mysql/index.cjs.map +1 -1
- package/dist/lib/mysql/index.d.cts +4641 -1889
- package/dist/lib/mysql/index.d.ts +4641 -1889
- package/dist/lib/mysql/index.js +19 -20
- package/dist/lib/mysql/schemas/auth/accounts.cjs +121 -97
- package/dist/lib/mysql/schemas/auth/accounts.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/accounts.js +10 -11
- package/dist/lib/mysql/schemas/auth/device-access-token.cjs +116 -89
- package/dist/lib/mysql/schemas/auth/device-access-token.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/device-access-token.d.cts +16 -0
- package/dist/lib/mysql/schemas/auth/device-access-token.d.ts +16 -0
- package/dist/lib/mysql/schemas/auth/device-access-token.js +11 -12
- package/dist/lib/mysql/schemas/auth/device-verification.cjs +115 -91
- package/dist/lib/mysql/schemas/auth/device-verification.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/device-verification.js +11 -12
- package/dist/lib/mysql/schemas/auth/profiles.cjs +254 -0
- package/dist/lib/mysql/schemas/auth/profiles.cjs.map +1 -0
- package/dist/lib/mysql/schemas/auth/profiles.d.cts +112 -0
- package/dist/lib/mysql/schemas/auth/profiles.d.ts +112 -0
- package/dist/lib/mysql/schemas/auth/profiles.js +20 -0
- package/dist/lib/mysql/schemas/auth/profiles.js.map +1 -0
- package/dist/lib/mysql/schemas/auth/role-permissions.cjs +112 -83
- package/dist/lib/mysql/schemas/auth/role-permissions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/role-permissions.js +11 -12
- package/dist/lib/mysql/schemas/auth/roles.cjs +116 -83
- package/dist/lib/mysql/schemas/auth/roles.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/roles.d.cts +16 -0
- package/dist/lib/mysql/schemas/auth/roles.d.ts +16 -0
- package/dist/lib/mysql/schemas/auth/roles.js +10 -11
- package/dist/lib/mysql/schemas/auth/sessions.cjs +111 -87
- package/dist/lib/mysql/schemas/auth/sessions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/sessions.js +11 -12
- package/dist/lib/mysql/schemas/auth/user-permissions.cjs +116 -88
- package/dist/lib/mysql/schemas/auth/user-permissions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/user-permissions.d.cts +16 -0
- package/dist/lib/mysql/schemas/auth/user-permissions.d.ts +16 -0
- package/dist/lib/mysql/schemas/auth/user-permissions.js +10 -11
- package/dist/lib/mysql/schemas/auth/user-prefs.cjs +120 -92
- package/dist/lib/mysql/schemas/auth/user-prefs.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/user-prefs.d.cts +16 -0
- package/dist/lib/mysql/schemas/auth/user-prefs.d.ts +16 -0
- package/dist/lib/mysql/schemas/auth/user-prefs.js +10 -11
- package/dist/lib/mysql/schemas/auth/user-roles.cjs +119 -86
- package/dist/lib/mysql/schemas/auth/user-roles.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/user-roles.d.cts +16 -0
- package/dist/lib/mysql/schemas/auth/user-roles.d.ts +16 -0
- package/dist/lib/mysql/schemas/auth/user-roles.js +10 -11
- package/dist/lib/mysql/schemas/auth/users.cjs +355 -223
- package/dist/lib/mysql/schemas/auth/users.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/users.d.cts +2 -0
- package/dist/lib/mysql/schemas/auth/users.d.ts +2 -0
- package/dist/lib/mysql/schemas/auth/users.js +10 -11
- package/dist/lib/mysql/schemas/commerce/coupon.cjs +155 -111
- package/dist/lib/mysql/schemas/commerce/coupon.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/coupon.d.cts +16 -0
- package/dist/lib/mysql/schemas/commerce/coupon.d.ts +16 -0
- package/dist/lib/mysql/schemas/commerce/coupon.js +10 -11
- package/dist/lib/mysql/schemas/commerce/merchant-account.cjs +5 -1
- package/dist/lib/mysql/schemas/commerce/merchant-account.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-account.d.cts +16 -0
- package/dist/lib/mysql/schemas/commerce/merchant-account.d.ts +16 -0
- package/dist/lib/mysql/schemas/commerce/merchant-account.js +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-charge.cjs +218 -17
- package/dist/lib/mysql/schemas/commerce/merchant-charge.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-charge.d.cts +33 -0
- package/dist/lib/mysql/schemas/commerce/merchant-charge.d.ts +33 -0
- package/dist/lib/mysql/schemas/commerce/merchant-charge.js +11 -4
- package/dist/lib/mysql/schemas/commerce/merchant-coupon.cjs +5 -1
- package/dist/lib/mysql/schemas/commerce/merchant-coupon.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-coupon.d.cts +16 -0
- package/dist/lib/mysql/schemas/commerce/merchant-coupon.d.ts +16 -0
- package/dist/lib/mysql/schemas/commerce/merchant-coupon.js +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-customer.cjs +5 -1
- package/dist/lib/mysql/schemas/commerce/merchant-customer.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-customer.d.cts +16 -0
- package/dist/lib/mysql/schemas/commerce/merchant-customer.d.ts +16 -0
- package/dist/lib/mysql/schemas/commerce/merchant-customer.js +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-price.cjs +5 -1
- package/dist/lib/mysql/schemas/commerce/merchant-price.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-price.d.cts +16 -0
- package/dist/lib/mysql/schemas/commerce/merchant-price.d.ts +16 -0
- package/dist/lib/mysql/schemas/commerce/merchant-price.js +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-product.cjs +5 -1
- package/dist/lib/mysql/schemas/commerce/merchant-product.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-product.d.cts +16 -0
- package/dist/lib/mysql/schemas/commerce/merchant-product.d.ts +16 -0
- package/dist/lib/mysql/schemas/commerce/merchant-product.js +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-session.cjs +5 -1
- package/dist/lib/mysql/schemas/commerce/merchant-session.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-session.d.cts +16 -0
- package/dist/lib/mysql/schemas/commerce/merchant-session.d.ts +16 -0
- package/dist/lib/mysql/schemas/commerce/merchant-session.js +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-subscription.cjs +323 -0
- package/dist/lib/mysql/schemas/commerce/merchant-subscription.cjs.map +1 -0
- package/dist/lib/mysql/schemas/commerce/merchant-subscription.d.cts +161 -0
- package/dist/lib/mysql/schemas/commerce/merchant-subscription.d.ts +161 -0
- package/dist/lib/mysql/schemas/commerce/merchant-subscription.js +20 -0
- package/dist/lib/mysql/schemas/commerce/merchant-subscription.js.map +1 -0
- package/dist/lib/mysql/schemas/commerce/price.cjs +115 -79
- package/dist/lib/mysql/schemas/commerce/price.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/price.d.cts +16 -0
- package/dist/lib/mysql/schemas/commerce/price.d.ts +16 -0
- package/dist/lib/mysql/schemas/commerce/price.js +10 -11
- package/dist/lib/mysql/schemas/commerce/product.cjs +134 -94
- package/dist/lib/mysql/schemas/commerce/product.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/product.d.cts +16 -0
- package/dist/lib/mysql/schemas/commerce/product.d.ts +16 -0
- package/dist/lib/mysql/schemas/commerce/product.js +10 -11
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.cjs +153 -117
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.d.cts +16 -0
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.d.ts +16 -0
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.js +11 -12
- package/dist/lib/mysql/schemas/commerce/purchase.cjs +307 -181
- package/dist/lib/mysql/schemas/commerce/purchase.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/purchase.d.cts +34 -0
- package/dist/lib/mysql/schemas/commerce/purchase.d.ts +34 -0
- package/dist/lib/mysql/schemas/commerce/purchase.js +10 -11
- package/dist/lib/mysql/schemas/commerce/subscription.cjs +351 -0
- package/dist/lib/mysql/schemas/commerce/subscription.cjs.map +1 -0
- package/dist/lib/mysql/schemas/commerce/subscription.d.cts +130 -0
- package/dist/lib/mysql/schemas/commerce/subscription.d.ts +130 -0
- package/dist/lib/mysql/schemas/commerce/subscription.js +20 -0
- package/dist/lib/mysql/schemas/commerce/subscription.js.map +1 -0
- package/dist/lib/mysql/schemas/commerce/upgradable-products.cjs +116 -84
- package/dist/lib/mysql/schemas/commerce/upgradable-products.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/upgradable-products.d.cts +16 -0
- package/dist/lib/mysql/schemas/commerce/upgradable-products.d.ts +16 -0
- package/dist/lib/mysql/schemas/commerce/upgradable-products.js +11 -12
- package/dist/lib/mysql/schemas/communication/comment.cjs +161 -92
- package/dist/lib/mysql/schemas/communication/comment.cjs.map +1 -1
- package/dist/lib/mysql/schemas/communication/comment.d.cts +17 -0
- package/dist/lib/mysql/schemas/communication/comment.d.ts +17 -0
- package/dist/lib/mysql/schemas/communication/comment.js +10 -11
- package/dist/lib/mysql/schemas/communication/communication-channel.cjs +5 -1
- package/dist/lib/mysql/schemas/communication/communication-channel.cjs.map +1 -1
- package/dist/lib/mysql/schemas/communication/communication-channel.d.cts +16 -0
- package/dist/lib/mysql/schemas/communication/communication-channel.d.ts +16 -0
- package/dist/lib/mysql/schemas/communication/communication-channel.js +1 -1
- package/dist/lib/mysql/schemas/communication/communication-preference-types.cjs +3 -0
- package/dist/lib/mysql/schemas/communication/communication-preference-types.cjs.map +1 -1
- package/dist/lib/mysql/schemas/communication/communication-preference-types.d.cts +16 -0
- package/dist/lib/mysql/schemas/communication/communication-preference-types.d.ts +16 -0
- package/dist/lib/mysql/schemas/communication/communication-preference-types.js +1 -1
- package/dist/lib/mysql/schemas/communication/communication-preferences.cjs +189 -110
- package/dist/lib/mysql/schemas/communication/communication-preferences.cjs.map +1 -1
- package/dist/lib/mysql/schemas/communication/communication-preferences.d.cts +33 -0
- package/dist/lib/mysql/schemas/communication/communication-preferences.d.ts +33 -0
- package/dist/lib/mysql/schemas/communication/communication-preferences.js +10 -11
- package/dist/lib/mysql/schemas/content/content-contributions.cjs +199 -116
- package/dist/lib/mysql/schemas/content/content-contributions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-contributions.d.cts +33 -0
- package/dist/lib/mysql/schemas/content/content-contributions.d.ts +33 -0
- package/dist/lib/mysql/schemas/content/content-contributions.js +10 -11
- package/dist/lib/mysql/schemas/content/content-resource-product.cjs +118 -79
- package/dist/lib/mysql/schemas/content/content-resource-product.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-product.d.cts +16 -0
- package/dist/lib/mysql/schemas/content/content-resource-product.d.ts +16 -0
- package/dist/lib/mysql/schemas/content/content-resource-product.js +10 -11
- package/dist/lib/mysql/schemas/content/content-resource-resource.cjs +128 -93
- package/dist/lib/mysql/schemas/content/content-resource-resource.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-resource.d.cts +16 -0
- package/dist/lib/mysql/schemas/content/content-resource-resource.d.ts +16 -0
- package/dist/lib/mysql/schemas/content/content-resource-resource.js +10 -11
- package/dist/lib/mysql/schemas/content/content-resource-tag.cjs +140 -101
- package/dist/lib/mysql/schemas/content/content-resource-tag.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-tag.d.cts +16 -0
- package/dist/lib/mysql/schemas/content/content-resource-tag.d.ts +16 -0
- package/dist/lib/mysql/schemas/content/content-resource-tag.js +10 -11
- package/dist/lib/mysql/schemas/content/content-resource-version.cjs +142 -107
- package/dist/lib/mysql/schemas/content/content-resource-version.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-version.d.cts +16 -0
- package/dist/lib/mysql/schemas/content/content-resource-version.d.ts +16 -0
- package/dist/lib/mysql/schemas/content/content-resource-version.js +10 -11
- package/dist/lib/mysql/schemas/content/content-resource.cjs +260 -161
- package/dist/lib/mysql/schemas/content/content-resource.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource.d.cts +33 -0
- package/dist/lib/mysql/schemas/content/content-resource.d.ts +33 -0
- package/dist/lib/mysql/schemas/content/content-resource.js +10 -11
- package/dist/lib/mysql/schemas/content/contribution-types.cjs +5 -1
- package/dist/lib/mysql/schemas/content/contribution-types.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/contribution-types.d.cts +16 -0
- package/dist/lib/mysql/schemas/content/contribution-types.d.ts +16 -0
- package/dist/lib/mysql/schemas/content/contribution-types.js +1 -1
- package/dist/lib/mysql/schemas/content/lesson-progress.cjs +8 -1
- package/dist/lib/mysql/schemas/content/lesson-progress.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/lesson-progress.d.cts +32 -0
- package/dist/lib/mysql/schemas/content/lesson-progress.d.ts +32 -0
- package/dist/lib/mysql/schemas/content/lesson-progress.js +1 -1
- package/dist/lib/mysql/schemas/content/resource-progress.cjs +8 -1
- package/dist/lib/mysql/schemas/content/resource-progress.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/resource-progress.d.cts +32 -0
- package/dist/lib/mysql/schemas/content/resource-progress.d.ts +32 -0
- package/dist/lib/mysql/schemas/content/resource-progress.js +1 -1
- package/dist/lib/mysql/schemas/content/tag-tag.cjs +121 -89
- package/dist/lib/mysql/schemas/content/tag-tag.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/tag-tag.d.cts +16 -0
- package/dist/lib/mysql/schemas/content/tag-tag.d.ts +16 -0
- package/dist/lib/mysql/schemas/content/tag-tag.js +10 -11
- package/dist/lib/mysql/schemas/content/tag.cjs +136 -100
- package/dist/lib/mysql/schemas/content/tag.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/tag.d.cts +16 -0
- package/dist/lib/mysql/schemas/content/tag.d.ts +16 -0
- package/dist/lib/mysql/schemas/content/tag.js +10 -11
- package/dist/lib/mysql/schemas/org/organization-membership-roles.cjs +339 -0
- package/dist/lib/mysql/schemas/org/organization-membership-roles.cjs.map +1 -0
- package/dist/lib/mysql/schemas/org/organization-membership-roles.d.cts +130 -0
- package/dist/lib/mysql/schemas/org/organization-membership-roles.d.ts +130 -0
- package/dist/lib/mysql/schemas/org/organization-membership-roles.js +20 -0
- package/dist/lib/mysql/schemas/org/organization-membership-roles.js.map +1 -0
- package/dist/lib/mysql/schemas/org/organization-memberships.cjs +420 -0
- package/dist/lib/mysql/schemas/org/organization-memberships.cjs.map +1 -0
- package/dist/lib/mysql/schemas/org/organization-memberships.d.cts +132 -0
- package/dist/lib/mysql/schemas/org/organization-memberships.d.ts +132 -0
- package/dist/lib/mysql/schemas/org/organization-memberships.js +20 -0
- package/dist/lib/mysql/schemas/org/organization-memberships.js.map +1 -0
- package/dist/lib/mysql/schemas/org/organizations.cjs +359 -0
- package/dist/lib/mysql/schemas/org/organizations.cjs.map +1 -0
- package/dist/lib/mysql/schemas/org/organizations.d.cts +98 -0
- package/dist/lib/mysql/schemas/org/organizations.d.ts +98 -0
- package/dist/lib/mysql/schemas/org/organizations.js +20 -0
- package/dist/lib/mysql/schemas/org/organizations.js.map +1 -0
- package/package.json +4 -3
- package/src/lib/mysql/index.ts +354 -26
- package/src/lib/mysql/schemas/auth/device-access-token.ts +3 -0
- package/src/lib/mysql/schemas/auth/profiles.ts +50 -0
- package/src/lib/mysql/schemas/auth/roles.ts +9 -1
- package/src/lib/mysql/schemas/auth/user-permissions.ts +2 -0
- package/src/lib/mysql/schemas/auth/user-prefs.ts +2 -0
- package/src/lib/mysql/schemas/auth/user-roles.ts +2 -0
- package/src/lib/mysql/schemas/auth/users.ts +11 -1
- package/src/lib/mysql/schemas/commerce/coupon.ts +2 -0
- package/src/lib/mysql/schemas/commerce/merchant-account.ts +3 -0
- package/src/lib/mysql/schemas/commerce/merchant-charge.ts +16 -0
- package/src/lib/mysql/schemas/commerce/merchant-coupon.ts +3 -0
- package/src/lib/mysql/schemas/commerce/merchant-customer.ts +2 -0
- package/src/lib/mysql/schemas/commerce/merchant-price.ts +3 -0
- package/src/lib/mysql/schemas/commerce/merchant-product.ts +3 -0
- package/src/lib/mysql/schemas/commerce/merchant-session.ts +8 -1
- package/src/lib/mysql/schemas/commerce/merchant-subscription.ts +64 -0
- package/src/lib/mysql/schemas/commerce/price.ts +3 -0
- package/src/lib/mysql/schemas/commerce/product.ts +3 -0
- package/src/lib/mysql/schemas/commerce/purchase-user-transfer.ts +3 -0
- package/src/lib/mysql/schemas/commerce/purchase.ts +22 -0
- package/src/lib/mysql/schemas/commerce/subscription.ts +69 -0
- package/src/lib/mysql/schemas/commerce/upgradable-products.ts +2 -0
- package/src/lib/mysql/schemas/communication/comment.ts +13 -0
- package/src/lib/mysql/schemas/communication/communication-channel.ts +2 -0
- package/src/lib/mysql/schemas/communication/communication-preference-types.ts +1 -0
- package/src/lib/mysql/schemas/communication/communication-preferences.ts +14 -0
- package/src/lib/mysql/schemas/content/content-contributions.ts +14 -0
- package/src/lib/mysql/schemas/content/content-resource-product.ts +2 -0
- package/src/lib/mysql/schemas/content/content-resource-resource.ts +2 -0
- package/src/lib/mysql/schemas/content/content-resource-tag.ts +2 -0
- package/src/lib/mysql/schemas/content/content-resource-version.ts +2 -0
- package/src/lib/mysql/schemas/content/content-resource.ts +17 -0
- package/src/lib/mysql/schemas/content/contribution-types.ts +2 -0
- package/src/lib/mysql/schemas/content/lesson-progress.ts +7 -0
- package/src/lib/mysql/schemas/content/resource-progress.ts +7 -0
- package/src/lib/mysql/schemas/content/tag-tag.ts +2 -0
- package/src/lib/mysql/schemas/content/tag.ts +2 -0
- package/src/lib/mysql/schemas/org/organization-membership-roles.ts +75 -0
- package/src/lib/mysql/schemas/org/organization-memberships.ts +75 -0
- package/src/lib/mysql/schemas/org/organizations.ts +50 -0
- package/dist/chunk-JW2PFVLO.js +0 -1468
- package/dist/chunk-SRTIWWLG.js +0 -96
package/src/lib/mysql/index.ts
CHANGED
|
@@ -61,7 +61,15 @@ import {
|
|
|
61
61
|
} from '@coursebuilder/core/schemas/content-resource-schema'
|
|
62
62
|
import { merchantAccountSchema } from '@coursebuilder/core/schemas/merchant-account-schema'
|
|
63
63
|
import { merchantCustomerSchema } from '@coursebuilder/core/schemas/merchant-customer-schema'
|
|
64
|
+
import {
|
|
65
|
+
MerchantSession,
|
|
66
|
+
MerchantSessionSchema,
|
|
67
|
+
} from '@coursebuilder/core/schemas/merchant-session'
|
|
68
|
+
import { MerchantSubscriptionSchema } from '@coursebuilder/core/schemas/merchant-subscription'
|
|
69
|
+
import { OrganizationMemberSchema } from '@coursebuilder/core/schemas/organization-member'
|
|
70
|
+
import { OrganizationSchema } from '@coursebuilder/core/schemas/organization-schema'
|
|
64
71
|
import { type ModuleProgress } from '@coursebuilder/core/schemas/resource-progress-schema'
|
|
72
|
+
import { SubscriptionSchema } from '@coursebuilder/core/schemas/subscription'
|
|
65
73
|
import { VideoResourceSchema } from '@coursebuilder/core/schemas/video-resource'
|
|
66
74
|
import { PaymentsProviderConfig } from '@coursebuilder/core/types'
|
|
67
75
|
import { logger } from '@coursebuilder/core/utils/logger'
|
|
@@ -83,6 +91,10 @@ import {
|
|
|
83
91
|
getPermissionsRelationsSchema,
|
|
84
92
|
getPermissionsSchema,
|
|
85
93
|
} from './schemas/auth/permissions.js'
|
|
94
|
+
import {
|
|
95
|
+
getProfilesRelationsSchema,
|
|
96
|
+
getProfilesSchema,
|
|
97
|
+
} from './schemas/auth/profiles.js'
|
|
86
98
|
import {
|
|
87
99
|
getRolePermissionsRelationsSchema,
|
|
88
100
|
getRolePermissionsSchema,
|
|
@@ -126,6 +138,10 @@ import { getMerchantCustomerSchema } from './schemas/commerce/merchant-customer.
|
|
|
126
138
|
import { getMerchantPriceSchema } from './schemas/commerce/merchant-price.js'
|
|
127
139
|
import { getMerchantProductSchema } from './schemas/commerce/merchant-product.js'
|
|
128
140
|
import { getMerchantSessionSchema } from './schemas/commerce/merchant-session.js'
|
|
141
|
+
import {
|
|
142
|
+
getMerchantSubscriptionRelationsSchema,
|
|
143
|
+
getMerchantSubscriptionSchema,
|
|
144
|
+
} from './schemas/commerce/merchant-subscription.js'
|
|
129
145
|
import { getPriceSchema } from './schemas/commerce/price.js'
|
|
130
146
|
import {
|
|
131
147
|
getProductRelationsSchema,
|
|
@@ -139,6 +155,10 @@ import {
|
|
|
139
155
|
getPurchaseRelationsSchema,
|
|
140
156
|
getPurchaseSchema,
|
|
141
157
|
} from './schemas/commerce/purchase.js'
|
|
158
|
+
import {
|
|
159
|
+
getSubscriptionRelationsSchema,
|
|
160
|
+
getSubscriptionSchema,
|
|
161
|
+
} from './schemas/commerce/subscription.js'
|
|
142
162
|
import {
|
|
143
163
|
getUpgradableProductsRelationsSchema,
|
|
144
164
|
getUpgradableProductsSchema,
|
|
@@ -188,6 +208,18 @@ import {
|
|
|
188
208
|
getTagTagSchema,
|
|
189
209
|
} from './schemas/content/tag-tag.js'
|
|
190
210
|
import { getTagRelationsSchema, getTagSchema } from './schemas/content/tag.js'
|
|
211
|
+
import {
|
|
212
|
+
getOrganizationMembershipRolesRelationsSchema,
|
|
213
|
+
getOrganizationMembershipRolesSchema,
|
|
214
|
+
} from './schemas/org/organization-membership-roles.js'
|
|
215
|
+
import {
|
|
216
|
+
getOrganizationMembershipsRelationsSchema,
|
|
217
|
+
getOrganizationMembershipsSchema,
|
|
218
|
+
} from './schemas/org/organization-memberships.js'
|
|
219
|
+
import {
|
|
220
|
+
getOrganizationsRelationsSchema,
|
|
221
|
+
getOrganizationsSchema,
|
|
222
|
+
} from './schemas/org/organizations.js'
|
|
191
223
|
|
|
192
224
|
export const guid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz', 5)
|
|
193
225
|
|
|
@@ -271,6 +303,22 @@ export function getCourseBuilderSchema(mysqlTable: MySqlTableFn) {
|
|
|
271
303
|
tagTagRelations: getTagTagRelationsSchema(mysqlTable),
|
|
272
304
|
userPrefs: getUserPrefsSchema(mysqlTable),
|
|
273
305
|
userPrefsRelations: getUserPrefsRelationsSchema(mysqlTable),
|
|
306
|
+
organization: getOrganizationsSchema(mysqlTable),
|
|
307
|
+
organizationRelations: getOrganizationsRelationsSchema(mysqlTable),
|
|
308
|
+
organizationMemberships: getOrganizationMembershipsSchema(mysqlTable),
|
|
309
|
+
organizationMembershipRelations:
|
|
310
|
+
getOrganizationMembershipsRelationsSchema(mysqlTable),
|
|
311
|
+
organizationMembershipRoles:
|
|
312
|
+
getOrganizationMembershipRolesSchema(mysqlTable),
|
|
313
|
+
organizationMembershipRolesRelations:
|
|
314
|
+
getOrganizationMembershipRolesRelationsSchema(mysqlTable),
|
|
315
|
+
merchantSubscription: getMerchantSubscriptionSchema(mysqlTable),
|
|
316
|
+
merchantSubscriptionRelations:
|
|
317
|
+
getMerchantSubscriptionRelationsSchema(mysqlTable),
|
|
318
|
+
subscription: getSubscriptionSchema(mysqlTable),
|
|
319
|
+
subscriptionRelations: getSubscriptionRelationsSchema(mysqlTable),
|
|
320
|
+
profiles: getProfilesSchema(mysqlTable),
|
|
321
|
+
profilesRelations: getProfilesRelationsSchema(mysqlTable),
|
|
274
322
|
} as const
|
|
275
323
|
}
|
|
276
324
|
|
|
@@ -308,6 +356,12 @@ export function mySqlDrizzleAdapter(
|
|
|
308
356
|
upgradableProducts,
|
|
309
357
|
resourceProgress,
|
|
310
358
|
comments,
|
|
359
|
+
organization: organizationTable,
|
|
360
|
+
organizationMemberships: organizationMembershipTable,
|
|
361
|
+
organizationMembershipRoles: organizationMembershipRoleTable,
|
|
362
|
+
roles: roleTable,
|
|
363
|
+
merchantSubscription: merchantSubscriptionTable,
|
|
364
|
+
subscription: subscriptionTable,
|
|
311
365
|
} = createTables(tableFn)
|
|
312
366
|
|
|
313
367
|
const adapter: CourseBuilderAdapter = {
|
|
@@ -621,6 +675,23 @@ export function mySqlDrizzleAdapter(
|
|
|
621
675
|
|
|
622
676
|
return parsedCoupon.data
|
|
623
677
|
},
|
|
678
|
+
async createMerchantSession(options): Promise<MerchantSession> {
|
|
679
|
+
const id = `ms_${v4()}`
|
|
680
|
+
await client.insert(merchantSession).values({
|
|
681
|
+
id,
|
|
682
|
+
identifier: options.identifier,
|
|
683
|
+
merchantAccountId: options.merchantAccountId,
|
|
684
|
+
...(options.organizationId
|
|
685
|
+
? { organizationId: options.organizationId }
|
|
686
|
+
: {}),
|
|
687
|
+
})
|
|
688
|
+
|
|
689
|
+
return MerchantSessionSchema.parse(
|
|
690
|
+
await client.query.merchantSession.findFirst({
|
|
691
|
+
where: eq(merchantSession.id, id),
|
|
692
|
+
}),
|
|
693
|
+
)
|
|
694
|
+
},
|
|
624
695
|
async createMerchantChargeAndPurchase(options): Promise<Purchase> {
|
|
625
696
|
const purchaseId = await client.transaction(async (trx) => {
|
|
626
697
|
try {
|
|
@@ -753,15 +824,14 @@ export function mySqlDrizzleAdapter(
|
|
|
753
824
|
}
|
|
754
825
|
}
|
|
755
826
|
|
|
827
|
+
// create a new merchant session
|
|
756
828
|
const merchantSessionId = `ms_${v4()}`
|
|
757
829
|
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
merchantAccountId,
|
|
764
|
-
})
|
|
830
|
+
await client.insert(merchantSession).values({
|
|
831
|
+
id: merchantSessionId,
|
|
832
|
+
identifier: checkoutSessionId,
|
|
833
|
+
merchantAccountId,
|
|
834
|
+
})
|
|
765
835
|
|
|
766
836
|
const merchantCouponUsed = stripeCouponId
|
|
767
837
|
? await client.query.merchantCoupon.findFirst({
|
|
@@ -783,7 +853,7 @@ export function mySqlDrizzleAdapter(
|
|
|
783
853
|
? 'Restricted'
|
|
784
854
|
: 'Valid'
|
|
785
855
|
|
|
786
|
-
|
|
856
|
+
await client.insert(purchaseTable).values({
|
|
787
857
|
id: purchaseId,
|
|
788
858
|
status: newPurchaseStatus,
|
|
789
859
|
userId,
|
|
@@ -799,16 +869,14 @@ export function mySqlDrizzleAdapter(
|
|
|
799
869
|
|
|
800
870
|
const oneWeekInMilliseconds = 1000 * 60 * 60 * 24 * 7
|
|
801
871
|
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
sourceUserId: userId,
|
|
811
|
-
})
|
|
872
|
+
await client.insert(purchaseUserTransfer).values({
|
|
873
|
+
id: `put_${v4()}`,
|
|
874
|
+
purchaseId: purchaseId as string,
|
|
875
|
+
expiresAt: existingPurchase
|
|
876
|
+
? new Date()
|
|
877
|
+
: new Date(Date.now() + oneWeekInMilliseconds),
|
|
878
|
+
sourceUserId: userId,
|
|
879
|
+
})
|
|
812
880
|
|
|
813
881
|
// const result = await Promise.all([
|
|
814
882
|
// newMerchantCharge,
|
|
@@ -1064,7 +1132,7 @@ export function mySqlDrizzleAdapter(
|
|
|
1064
1132
|
|
|
1065
1133
|
const ResultRowSchema = z.object({
|
|
1066
1134
|
resource_id: z.string(),
|
|
1067
|
-
resource_type: z.enum(['lesson', 'exercise']),
|
|
1135
|
+
resource_type: z.enum(['lesson', 'exercise', 'post']),
|
|
1068
1136
|
resource_slug: z.string().nullable(),
|
|
1069
1137
|
completed_at: z
|
|
1070
1138
|
.string()
|
|
@@ -1104,10 +1172,9 @@ export function mySqlDrizzleAdapter(
|
|
|
1104
1172
|
LEFT JOIN ${resourceProgress} rp ON rp.resourceId = cr.id
|
|
1105
1173
|
AND rp.userId = ${user.id}
|
|
1106
1174
|
WHERE
|
|
1107
|
-
cr.type IN ('lesson', 'exercise')
|
|
1175
|
+
cr.type IN ('lesson', 'exercise', 'post')
|
|
1108
1176
|
|
|
1109
1177
|
`)
|
|
1110
|
-
|
|
1111
1178
|
// Process the results
|
|
1112
1179
|
const completedLessons: ResourceProgress[] = []
|
|
1113
1180
|
let nextResource: Partial<ContentResource> | null = null
|
|
@@ -2407,11 +2474,39 @@ export function mySqlDrizzleAdapter(
|
|
|
2407
2474
|
|
|
2408
2475
|
await client.insert(users).values({ ...data, id })
|
|
2409
2476
|
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2477
|
+
// creating a personal organization for the user
|
|
2478
|
+
// every user gets an organization of their very own
|
|
2479
|
+
const personalOrganization = await adapter.createOrganization({
|
|
2480
|
+
name: `Personal (${data.email})`,
|
|
2481
|
+
})
|
|
2482
|
+
|
|
2483
|
+
if (!personalOrganization) {
|
|
2484
|
+
throw new Error('Failed to create personal organization')
|
|
2485
|
+
}
|
|
2486
|
+
|
|
2487
|
+
const membership = await adapter.addMemberToOrganization({
|
|
2488
|
+
organizationId: personalOrganization.id,
|
|
2489
|
+
userId: id,
|
|
2490
|
+
invitedById: id,
|
|
2491
|
+
})
|
|
2492
|
+
|
|
2493
|
+
if (!membership) {
|
|
2494
|
+
throw new Error('Failed to add user to personal organization')
|
|
2495
|
+
}
|
|
2496
|
+
|
|
2497
|
+
await adapter.addRoleForMember({
|
|
2498
|
+
organizationId: personalOrganization.id,
|
|
2499
|
+
memberId: membership.id,
|
|
2500
|
+
role: 'owner',
|
|
2501
|
+
})
|
|
2502
|
+
|
|
2503
|
+
const user = await adapter.getUser?.(id)
|
|
2504
|
+
|
|
2505
|
+
if (!user) {
|
|
2506
|
+
throw new Error('Failed to get user')
|
|
2507
|
+
}
|
|
2508
|
+
|
|
2509
|
+
return user
|
|
2415
2510
|
} catch (error) {
|
|
2416
2511
|
console.error(error)
|
|
2417
2512
|
throw error
|
|
@@ -2597,6 +2692,239 @@ export function mySqlDrizzleAdapter(
|
|
|
2597
2692
|
|
|
2598
2693
|
return undefined
|
|
2599
2694
|
},
|
|
2695
|
+
createOrganization: async (options: { name: string }) => {
|
|
2696
|
+
const organizationId = crypto.randomUUID()
|
|
2697
|
+
await client.insert(organizationTable).values({
|
|
2698
|
+
...options,
|
|
2699
|
+
id: organizationId,
|
|
2700
|
+
})
|
|
2701
|
+
|
|
2702
|
+
return adapter.getOrganization(organizationId)
|
|
2703
|
+
},
|
|
2704
|
+
getOrganization: async (organizationId: string) => {
|
|
2705
|
+
return OrganizationSchema.parse(
|
|
2706
|
+
await client.query.organization.findFirst({
|
|
2707
|
+
where: eq(organizationTable.id, organizationId),
|
|
2708
|
+
}),
|
|
2709
|
+
)
|
|
2710
|
+
},
|
|
2711
|
+
addMemberToOrganization: async (options: {
|
|
2712
|
+
organizationId: string
|
|
2713
|
+
userId: string
|
|
2714
|
+
invitedById: string
|
|
2715
|
+
}) => {
|
|
2716
|
+
const id = crypto.randomUUID()
|
|
2717
|
+
await client.insert(organizationMembershipTable).values({
|
|
2718
|
+
...options,
|
|
2719
|
+
id,
|
|
2720
|
+
})
|
|
2721
|
+
|
|
2722
|
+
return OrganizationMemberSchema.parse(
|
|
2723
|
+
await client.query.organizationMemberships.findFirst({
|
|
2724
|
+
where: eq(organizationMembershipTable.id, id),
|
|
2725
|
+
with: {
|
|
2726
|
+
organization: true,
|
|
2727
|
+
user: true,
|
|
2728
|
+
},
|
|
2729
|
+
}),
|
|
2730
|
+
)
|
|
2731
|
+
},
|
|
2732
|
+
removeMemberFromOrganization: async (options: {
|
|
2733
|
+
organizationId: string
|
|
2734
|
+
userId: string
|
|
2735
|
+
}) => {
|
|
2736
|
+
await client
|
|
2737
|
+
.delete(organizationMembershipTable)
|
|
2738
|
+
.where(
|
|
2739
|
+
and(
|
|
2740
|
+
eq(
|
|
2741
|
+
organizationMembershipTable.organizationId,
|
|
2742
|
+
options.organizationId,
|
|
2743
|
+
),
|
|
2744
|
+
eq(organizationMembershipTable.userId, options.userId),
|
|
2745
|
+
),
|
|
2746
|
+
)
|
|
2747
|
+
},
|
|
2748
|
+
addRoleForMember: async (options: {
|
|
2749
|
+
organizationId: string
|
|
2750
|
+
memberId: string
|
|
2751
|
+
role: string
|
|
2752
|
+
}) => {
|
|
2753
|
+
const existingRole = z
|
|
2754
|
+
.object({
|
|
2755
|
+
id: z.string(),
|
|
2756
|
+
})
|
|
2757
|
+
.nullish()
|
|
2758
|
+
.parse(
|
|
2759
|
+
await client.query.roles.findFirst({
|
|
2760
|
+
where: and(
|
|
2761
|
+
eq(roleTable.organizationId, options.organizationId),
|
|
2762
|
+
eq(roleTable.name, options.role),
|
|
2763
|
+
),
|
|
2764
|
+
}),
|
|
2765
|
+
)
|
|
2766
|
+
|
|
2767
|
+
const roleId = existingRole?.id || crypto.randomUUID()
|
|
2768
|
+
|
|
2769
|
+
if (!existingRole) {
|
|
2770
|
+
await client.insert(roleTable).values({
|
|
2771
|
+
name: options.role,
|
|
2772
|
+
organizationId: options.organizationId,
|
|
2773
|
+
id: roleId,
|
|
2774
|
+
})
|
|
2775
|
+
}
|
|
2776
|
+
|
|
2777
|
+
const currentOrgMembershipRole =
|
|
2778
|
+
await client.query.organizationMembershipRoles.findFirst({
|
|
2779
|
+
where: and(
|
|
2780
|
+
eq(
|
|
2781
|
+
organizationMembershipRoleTable.organizationMembershipId,
|
|
2782
|
+
options.memberId,
|
|
2783
|
+
),
|
|
2784
|
+
eq(organizationMembershipRoleTable.roleId, roleId),
|
|
2785
|
+
),
|
|
2786
|
+
})
|
|
2787
|
+
|
|
2788
|
+
if (!currentOrgMembershipRole) {
|
|
2789
|
+
await client.insert(organizationMembershipRoleTable).values({
|
|
2790
|
+
organizationId: options.organizationId,
|
|
2791
|
+
organizationMembershipId: options.memberId,
|
|
2792
|
+
roleId,
|
|
2793
|
+
})
|
|
2794
|
+
}
|
|
2795
|
+
},
|
|
2796
|
+
removeRoleForMember: async (options: {
|
|
2797
|
+
organizationId: string
|
|
2798
|
+
memberId: string
|
|
2799
|
+
role: string
|
|
2800
|
+
}) => {
|
|
2801
|
+
const existingRole = z
|
|
2802
|
+
.object({
|
|
2803
|
+
id: z.string(),
|
|
2804
|
+
})
|
|
2805
|
+
.nullable()
|
|
2806
|
+
.parse(
|
|
2807
|
+
await client.query.roles.findFirst({
|
|
2808
|
+
where: and(
|
|
2809
|
+
eq(roleTable.organizationId, options.organizationId),
|
|
2810
|
+
eq(roleTable.name, options.role),
|
|
2811
|
+
),
|
|
2812
|
+
}),
|
|
2813
|
+
)
|
|
2814
|
+
|
|
2815
|
+
const roleId = existingRole?.id
|
|
2816
|
+
|
|
2817
|
+
if (roleId) {
|
|
2818
|
+
await client
|
|
2819
|
+
.delete(organizationMembershipRoleTable)
|
|
2820
|
+
.where(eq(organizationMembershipRoleTable.roleId, roleId))
|
|
2821
|
+
}
|
|
2822
|
+
},
|
|
2823
|
+
getMembershipsForUser: async (userId: string) => {
|
|
2824
|
+
return OrganizationMemberSchema.array().parse(
|
|
2825
|
+
(await client.query.organizationMemberships.findMany({
|
|
2826
|
+
where: eq(organizationMembershipTable.userId, userId),
|
|
2827
|
+
with: {
|
|
2828
|
+
organization: true,
|
|
2829
|
+
user: true,
|
|
2830
|
+
},
|
|
2831
|
+
})) || [],
|
|
2832
|
+
)
|
|
2833
|
+
},
|
|
2834
|
+
getOrganizationMembers: async (organizationId: string) => {
|
|
2835
|
+
return OrganizationMemberSchema.array().parse(
|
|
2836
|
+
(await client.query.organizationMemberships.findMany({
|
|
2837
|
+
where: eq(organizationMembershipTable.organizationId, organizationId),
|
|
2838
|
+
})) || [],
|
|
2839
|
+
)
|
|
2840
|
+
},
|
|
2841
|
+
createSubscription: async (options: {
|
|
2842
|
+
organizationId: string
|
|
2843
|
+
merchantSubscriptionId: string
|
|
2844
|
+
productId: string
|
|
2845
|
+
}) => {
|
|
2846
|
+
const id = `sub_${crypto.randomUUID()}`
|
|
2847
|
+
await client.insert(subscriptionTable).values({
|
|
2848
|
+
...options,
|
|
2849
|
+
id,
|
|
2850
|
+
})
|
|
2851
|
+
|
|
2852
|
+
return SubscriptionSchema.parse(
|
|
2853
|
+
await client.query.subscription.findFirst({
|
|
2854
|
+
where: eq(subscriptionTable.id, id),
|
|
2855
|
+
with: {
|
|
2856
|
+
product: true,
|
|
2857
|
+
},
|
|
2858
|
+
}),
|
|
2859
|
+
)
|
|
2860
|
+
},
|
|
2861
|
+
getMerchantSubscription: async (merchantSubscriptionId: string) => {
|
|
2862
|
+
return MerchantSubscriptionSchema.parse(
|
|
2863
|
+
await client.query.merchantSubscription.findFirst({
|
|
2864
|
+
where: eq(merchantSubscriptionTable.id, merchantSubscriptionId),
|
|
2865
|
+
}),
|
|
2866
|
+
)
|
|
2867
|
+
},
|
|
2868
|
+
createMerchantSubscription: async (options: {
|
|
2869
|
+
merchantAccountId: string
|
|
2870
|
+
merchantCustomerId: string
|
|
2871
|
+
merchantProductId: string
|
|
2872
|
+
identifier: string
|
|
2873
|
+
}) => {
|
|
2874
|
+
const id = crypto.randomUUID()
|
|
2875
|
+
await client.insert(merchantSubscriptionTable).values({
|
|
2876
|
+
...options,
|
|
2877
|
+
id,
|
|
2878
|
+
})
|
|
2879
|
+
|
|
2880
|
+
return MerchantSubscriptionSchema.parse(
|
|
2881
|
+
await client.query.merchantSubscription.findFirst({
|
|
2882
|
+
where: eq(merchantSubscriptionTable.id, id),
|
|
2883
|
+
}),
|
|
2884
|
+
)
|
|
2885
|
+
},
|
|
2886
|
+
updateMerchantSubscription: async (options: {
|
|
2887
|
+
merchantSubscriptionId: string
|
|
2888
|
+
status: string
|
|
2889
|
+
}) => {
|
|
2890
|
+
throw new Error('Not implemented')
|
|
2891
|
+
},
|
|
2892
|
+
deleteMerchantSubscription: async (merchantSubscriptionId: string) => {
|
|
2893
|
+
throw new Error('Not implemented')
|
|
2894
|
+
},
|
|
2895
|
+
getSubscriptionForStripeId: async (stripeSubscriptionId: string) => {
|
|
2896
|
+
const merchantSubscriptionParsed = MerchantSubscriptionSchema.safeParse(
|
|
2897
|
+
await client.query.merchantSubscription.findFirst({
|
|
2898
|
+
where: eq(merchantSubscriptionTable.identifier, stripeSubscriptionId),
|
|
2899
|
+
}),
|
|
2900
|
+
)
|
|
2901
|
+
|
|
2902
|
+
if (!merchantSubscriptionParsed.success) {
|
|
2903
|
+
throw new Error(
|
|
2904
|
+
`No merchant subscription found for stripe id ${stripeSubscriptionId} ${merchantSubscriptionParsed.error}`,
|
|
2905
|
+
)
|
|
2906
|
+
}
|
|
2907
|
+
|
|
2908
|
+
const subscriptionParsed = SubscriptionSchema.safeParse(
|
|
2909
|
+
await client.query.subscription.findFirst({
|
|
2910
|
+
where: eq(
|
|
2911
|
+
subscriptionTable.merchantSubscriptionId,
|
|
2912
|
+
merchantSubscriptionParsed.data.id,
|
|
2913
|
+
),
|
|
2914
|
+
with: {
|
|
2915
|
+
product: true,
|
|
2916
|
+
},
|
|
2917
|
+
}),
|
|
2918
|
+
)
|
|
2919
|
+
|
|
2920
|
+
if (!subscriptionParsed.success) {
|
|
2921
|
+
throw new Error(
|
|
2922
|
+
`No subscription found for merchant subscription ${merchantSubscriptionParsed.data.id} ${subscriptionParsed.error}`,
|
|
2923
|
+
)
|
|
2924
|
+
}
|
|
2925
|
+
|
|
2926
|
+
return subscriptionParsed.data
|
|
2927
|
+
},
|
|
2600
2928
|
}
|
|
2601
2929
|
|
|
2602
2930
|
return adapter
|
|
@@ -15,6 +15,9 @@ export function getDeviceAccessTokenSchema(mysqlTable: MySqlTableFn) {
|
|
|
15
15
|
{
|
|
16
16
|
token: varchar('token', { length: 191 }).notNull(),
|
|
17
17
|
userId: varchar('userId', { length: 191 }).notNull(),
|
|
18
|
+
organizationMembershipId: varchar('organizationMembershipId', {
|
|
19
|
+
length: 191,
|
|
20
|
+
}),
|
|
18
21
|
createdAt: timestamp('createdAt', {
|
|
19
22
|
mode: 'date',
|
|
20
23
|
fsp: 3,
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { relations, sql } from 'drizzle-orm'
|
|
2
|
+
import {
|
|
3
|
+
index,
|
|
4
|
+
json,
|
|
5
|
+
MySqlTableFn,
|
|
6
|
+
timestamp,
|
|
7
|
+
uniqueIndex,
|
|
8
|
+
varchar,
|
|
9
|
+
} from 'drizzle-orm/mysql-core'
|
|
10
|
+
|
|
11
|
+
import { getUsersSchema } from './users.js'
|
|
12
|
+
|
|
13
|
+
export function getProfilesSchema(mysqlTable: MySqlTableFn) {
|
|
14
|
+
return mysqlTable(
|
|
15
|
+
'Profile',
|
|
16
|
+
{
|
|
17
|
+
id: varchar('id', { length: 255 }).notNull().primaryKey(),
|
|
18
|
+
userId: varchar('userId', { length: 255 }).notNull(),
|
|
19
|
+
type: varchar('type', { length: 255 }).notNull(),
|
|
20
|
+
fields: json('fields').$type<Record<string, any>>().default({}),
|
|
21
|
+
createdAt: timestamp('createdAt', {
|
|
22
|
+
mode: 'date',
|
|
23
|
+
fsp: 3,
|
|
24
|
+
}).default(sql`CURRENT_TIMESTAMP(3)`),
|
|
25
|
+
updatedAt: timestamp('updatedAt', {
|
|
26
|
+
mode: 'date',
|
|
27
|
+
fsp: 3,
|
|
28
|
+
}).default(sql`CURRENT_TIMESTAMP(3)`),
|
|
29
|
+
},
|
|
30
|
+
(profile) => ({
|
|
31
|
+
userIdIdx: index('userId_idx').on(profile.userId),
|
|
32
|
+
uniqueUserType: uniqueIndex('unique_user_type_idx').on(
|
|
33
|
+
profile.userId,
|
|
34
|
+
profile.type,
|
|
35
|
+
),
|
|
36
|
+
}),
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function getProfilesRelationsSchema(mysqlTable: MySqlTableFn) {
|
|
41
|
+
const profiles = getProfilesSchema(mysqlTable)
|
|
42
|
+
const users = getUsersSchema(mysqlTable)
|
|
43
|
+
return relations(profiles, ({ one }) => ({
|
|
44
|
+
user: one(users, {
|
|
45
|
+
fields: [profiles.userId],
|
|
46
|
+
references: [users.id],
|
|
47
|
+
relationName: 'profiles',
|
|
48
|
+
}),
|
|
49
|
+
}))
|
|
50
|
+
}
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
MySqlTableFn,
|
|
6
6
|
text,
|
|
7
7
|
timestamp,
|
|
8
|
+
uniqueIndex,
|
|
8
9
|
varchar,
|
|
9
10
|
} from 'drizzle-orm/mysql-core'
|
|
10
11
|
|
|
@@ -15,7 +16,8 @@ export function getRolesSchema(mysqlTable: MySqlTableFn) {
|
|
|
15
16
|
'Role',
|
|
16
17
|
{
|
|
17
18
|
id: varchar('id', { length: 255 }).notNull().primaryKey(),
|
|
18
|
-
|
|
19
|
+
organizationId: varchar('organizationId', { length: 191 }),
|
|
20
|
+
name: varchar('name', { length: 255 }).notNull(),
|
|
19
21
|
description: text('description'),
|
|
20
22
|
active: boolean('active').notNull().default(true),
|
|
21
23
|
createdAt: timestamp('createdAt', {
|
|
@@ -33,6 +35,11 @@ export function getRolesSchema(mysqlTable: MySqlTableFn) {
|
|
|
33
35
|
},
|
|
34
36
|
(role) => ({
|
|
35
37
|
nameIdx: index('name_idx').on(role.name),
|
|
38
|
+
organizationIdIdx: index('organizationId_idx').on(role.organizationId),
|
|
39
|
+
uniqueNamePerOrg: uniqueIndex('unique_name_per_org').on(
|
|
40
|
+
role.organizationId,
|
|
41
|
+
role.name,
|
|
42
|
+
),
|
|
36
43
|
}),
|
|
37
44
|
)
|
|
38
45
|
}
|
|
@@ -40,6 +47,7 @@ export function getRolesSchema(mysqlTable: MySqlTableFn) {
|
|
|
40
47
|
export function getRolesRelationsSchema(mysqlTable: MySqlTableFn) {
|
|
41
48
|
const roles = getRolesSchema(mysqlTable)
|
|
42
49
|
const userRoles = getUserRolesSchema(mysqlTable)
|
|
50
|
+
|
|
43
51
|
return relations(roles, ({ many }) => ({
|
|
44
52
|
userRoles: many(userRoles, { relationName: 'role' }),
|
|
45
53
|
}))
|
|
@@ -16,6 +16,7 @@ export function getUserPermissionsSchema(mysqlTable: MySqlTableFn) {
|
|
|
16
16
|
'UserPermission',
|
|
17
17
|
{
|
|
18
18
|
userId: varchar('userId', { length: 255 }).notNull(),
|
|
19
|
+
organizationId: varchar('organizationId', { length: 191 }),
|
|
19
20
|
permissionId: varchar('permissionId', { length: 255 }).notNull(),
|
|
20
21
|
active: boolean('active').notNull().default(true),
|
|
21
22
|
createdAt: timestamp('createdAt', {
|
|
@@ -35,6 +36,7 @@ export function getUserPermissionsSchema(mysqlTable: MySqlTableFn) {
|
|
|
35
36
|
pk: primaryKey({ columns: [up.userId, up.permissionId] }),
|
|
36
37
|
userIdIdx: index('userId_idx').on(up.userId),
|
|
37
38
|
permissionIdIdx: index('permissionId_idx').on(up.permissionId),
|
|
39
|
+
organizationIdIdx: index('organizationId_idx').on(up.organizationId),
|
|
38
40
|
}),
|
|
39
41
|
)
|
|
40
42
|
}
|
|
@@ -16,6 +16,7 @@ export function getUserPrefsSchema(mysqlTable: MySqlTableFn) {
|
|
|
16
16
|
'UserPrefs',
|
|
17
17
|
{
|
|
18
18
|
id: varchar('id', { length: 191 }).notNull(),
|
|
19
|
+
organizationId: varchar('organizationId', { length: 191 }),
|
|
19
20
|
type: varchar('type', { length: 191 }).default('Global').notNull(),
|
|
20
21
|
userId: varchar('userId', { length: 255 }).notNull(),
|
|
21
22
|
fields: json('fields').$type<Record<string, any>>().default({}),
|
|
@@ -35,6 +36,7 @@ export function getUserPrefsSchema(mysqlTable: MySqlTableFn) {
|
|
|
35
36
|
(crr) => ({
|
|
36
37
|
pk: primaryKey({ columns: [crr.id] }),
|
|
37
38
|
crrUserIdIdKey: index('crr_userIdId_idx').on(crr.userId),
|
|
39
|
+
organizationIdIdx: index('organizationId_idx').on(crr.organizationId),
|
|
38
40
|
}),
|
|
39
41
|
)
|
|
40
42
|
}
|
|
@@ -18,6 +18,7 @@ export function getUserRolesSchema(mysqlTable: MySqlTableFn) {
|
|
|
18
18
|
userId: varchar('userId', { length: 255 }).notNull(),
|
|
19
19
|
roleId: varchar('roleId', { length: 255 }).notNull(),
|
|
20
20
|
active: boolean('active').notNull().default(true),
|
|
21
|
+
organizationId: varchar('organizationId', { length: 191 }),
|
|
21
22
|
createdAt: timestamp('createdAt', {
|
|
22
23
|
mode: 'date',
|
|
23
24
|
fsp: 3,
|
|
@@ -35,6 +36,7 @@ export function getUserRolesSchema(mysqlTable: MySqlTableFn) {
|
|
|
35
36
|
pk: primaryKey({ columns: [ur.userId, ur.roleId] }),
|
|
36
37
|
userIdIdx: index('userId_idx').on(ur.userId),
|
|
37
38
|
roleIdIdx: index('roleId_idx').on(ur.roleId),
|
|
39
|
+
organizationIdIdx: index('organizationId_idx').on(ur.organizationId),
|
|
38
40
|
}),
|
|
39
41
|
)
|
|
40
42
|
}
|
|
@@ -13,7 +13,9 @@ import { getCommentsSchema } from '../communication/comment.js'
|
|
|
13
13
|
import { getCommunicationPreferencesSchema } from '../communication/communication-preferences.js'
|
|
14
14
|
import { getContentContributionsSchema } from '../content/content-contributions.js'
|
|
15
15
|
import { getContentResourceSchema } from '../content/content-resource.js'
|
|
16
|
+
import { getOrganizationMembershipsSchema } from '../org/organization-memberships.js'
|
|
16
17
|
import { getAccountsSchema } from './accounts.js'
|
|
18
|
+
import { getProfilesSchema } from './profiles.js'
|
|
17
19
|
import { getUserPermissionsSchema } from './user-permissions.js'
|
|
18
20
|
import { getUserPrefsSchema } from './user-prefs.js'
|
|
19
21
|
import { getUserRolesSchema } from './user-roles.js'
|
|
@@ -47,6 +49,7 @@ export function getUsersSchema(mysqlTable: MySqlTableFn) {
|
|
|
47
49
|
|
|
48
50
|
export function getUsersRelationsSchema(mysqlTable: MySqlTableFn) {
|
|
49
51
|
const users = getUsersSchema(mysqlTable)
|
|
52
|
+
const profiles = getProfilesSchema(mysqlTable)
|
|
50
53
|
const accounts = getAccountsSchema(mysqlTable)
|
|
51
54
|
const communicationPreferences = getCommunicationPreferencesSchema(mysqlTable)
|
|
52
55
|
const userRoles = getUserRolesSchema(mysqlTable)
|
|
@@ -56,7 +59,11 @@ export function getUsersRelationsSchema(mysqlTable: MySqlTableFn) {
|
|
|
56
59
|
const purchases = getPurchaseSchema(mysqlTable)
|
|
57
60
|
const comments = getCommentsSchema(mysqlTable)
|
|
58
61
|
const userPrefs = getUserPrefsSchema(mysqlTable)
|
|
59
|
-
|
|
62
|
+
const organizationMemberships = getOrganizationMembershipsSchema(mysqlTable)
|
|
63
|
+
return relations(users, ({ many, one }) => ({
|
|
64
|
+
profiles: many(profiles, {
|
|
65
|
+
relationName: 'profiles',
|
|
66
|
+
}),
|
|
60
67
|
accounts: many(accounts, {
|
|
61
68
|
relationName: 'user',
|
|
62
69
|
}),
|
|
@@ -84,5 +91,8 @@ export function getUsersRelationsSchema(mysqlTable: MySqlTableFn) {
|
|
|
84
91
|
prefs: many(userPrefs, {
|
|
85
92
|
relationName: 'user',
|
|
86
93
|
}),
|
|
94
|
+
organizationMemberships: many(organizationMemberships, {
|
|
95
|
+
relationName: 'user',
|
|
96
|
+
}),
|
|
87
97
|
}))
|
|
88
98
|
}
|
|
@@ -21,6 +21,7 @@ export function getCouponSchema(mysqlTable: MySqlTableFn) {
|
|
|
21
21
|
'Coupon',
|
|
22
22
|
{
|
|
23
23
|
id: varchar('id', { length: 191 }).notNull(),
|
|
24
|
+
organizationId: varchar('organizationId', { length: 191 }),
|
|
24
25
|
code: varchar('code', { length: 191 }),
|
|
25
26
|
createdAt: timestamp('createdAt', { mode: 'date', fsp: 3 })
|
|
26
27
|
.default(sql`CURRENT_TIMESTAMP(3)`)
|
|
@@ -46,6 +47,7 @@ export function getCouponSchema(mysqlTable: MySqlTableFn) {
|
|
|
46
47
|
),
|
|
47
48
|
couponId: primaryKey({ columns: [table.id], name: 'Coupon_id' }),
|
|
48
49
|
couponCodeKey: unique('Coupon_code_key').on(table.code),
|
|
50
|
+
organizationIdIdx: index('organizationId_idx').on(table.organizationId),
|
|
49
51
|
}
|
|
50
52
|
},
|
|
51
53
|
)
|