@wordrhyme/db 0.1.0-alpha.14

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.
Files changed (98) hide show
  1. package/README.md +66 -0
  2. package/dist/acl-policy.d.ts +86 -0
  3. package/dist/acl-policy.d.ts.map +1 -0
  4. package/dist/chunk-3TTVLSF5.js +3390 -0
  5. package/dist/chunk-3TTVLSF5.js.map +1 -0
  6. package/dist/chunk-DCJM6GN5.js +264 -0
  7. package/dist/chunk-DCJM6GN5.js.map +1 -0
  8. package/dist/chunk-KWWJRUIK.js +54 -0
  9. package/dist/chunk-KWWJRUIK.js.map +1 -0
  10. package/dist/chunk-XAIEVBMU.js +212 -0
  11. package/dist/chunk-XAIEVBMU.js.map +1 -0
  12. package/dist/delete-policy.d.ts +11 -0
  13. package/dist/delete-policy.d.ts.map +1 -0
  14. package/dist/index.d.ts +31 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +545 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/plugin.d.ts +110 -0
  19. package/dist/plugin.d.ts.map +1 -0
  20. package/dist/plugin.js +21 -0
  21. package/dist/plugin.js.map +1 -0
  22. package/dist/relations/index.d.ts +105 -0
  23. package/dist/relations/index.d.ts.map +1 -0
  24. package/dist/relations/index.js +9 -0
  25. package/dist/relations/index.js.map +1 -0
  26. package/dist/schema/action-journal.d.ts +386 -0
  27. package/dist/schema/action-journal.d.ts.map +1 -0
  28. package/dist/schema/audit-archive.d.ts +934 -0
  29. package/dist/schema/audit-archive.d.ts.map +1 -0
  30. package/dist/schema/audit-events.d.ts +502 -0
  31. package/dist/schema/audit-events.d.ts.map +1 -0
  32. package/dist/schema/audit-logs.d.ts +418 -0
  33. package/dist/schema/audit-logs.d.ts.map +1 -0
  34. package/dist/schema/auth.d.ts +2727 -0
  35. package/dist/schema/auth.d.ts.map +1 -0
  36. package/dist/schema/billing.d.ts +3969 -0
  37. package/dist/schema/billing.d.ts.map +1 -0
  38. package/dist/schema/common.d.ts +87 -0
  39. package/dist/schema/common.d.ts.map +1 -0
  40. package/dist/schema/currency.d.ts +791 -0
  41. package/dist/schema/currency.d.ts.map +1 -0
  42. package/dist/schema/entity-extensions.d.ts +314 -0
  43. package/dist/schema/entity-extensions.d.ts.map +1 -0
  44. package/dist/schema/entity-ownerships.d.ts +862 -0
  45. package/dist/schema/entity-ownerships.d.ts.map +1 -0
  46. package/dist/schema/feature-flags.d.ts +770 -0
  47. package/dist/schema/feature-flags.d.ts.map +1 -0
  48. package/dist/schema/geo.d.ts +824 -0
  49. package/dist/schema/geo.d.ts.map +1 -0
  50. package/dist/schema/i18n.d.ts +1109 -0
  51. package/dist/schema/i18n.d.ts.map +1 -0
  52. package/dist/schema/index.d.ts +43 -0
  53. package/dist/schema/index.d.ts.map +1 -0
  54. package/dist/schema/index.js +507 -0
  55. package/dist/schema/index.js.map +1 -0
  56. package/dist/schema/media.d.ts +1147 -0
  57. package/dist/schema/media.d.ts.map +1 -0
  58. package/dist/schema/menus.d.ts +636 -0
  59. package/dist/schema/menus.d.ts.map +1 -0
  60. package/dist/schema/notification-channels.d.ts +288 -0
  61. package/dist/schema/notification-channels.d.ts.map +1 -0
  62. package/dist/schema/notification-preferences.d.ts +300 -0
  63. package/dist/schema/notification-preferences.d.ts.map +1 -0
  64. package/dist/schema/notification-templates.d.ts +476 -0
  65. package/dist/schema/notification-templates.d.ts.map +1 -0
  66. package/dist/schema/notifications.d.ts +1139 -0
  67. package/dist/schema/notifications.d.ts.map +1 -0
  68. package/dist/schema/permission-fields.d.ts +96 -0
  69. package/dist/schema/permission-fields.d.ts.map +1 -0
  70. package/dist/schema/permissions.d.ts +173 -0
  71. package/dist/schema/permissions.d.ts.map +1 -0
  72. package/dist/schema/plugin-migrations.d.ts +204 -0
  73. package/dist/schema/plugin-migrations.d.ts.map +1 -0
  74. package/dist/schema/plugins.d.ts +1977 -0
  75. package/dist/schema/plugins.d.ts.map +1 -0
  76. package/dist/schema/relationships.d.ts +221 -0
  77. package/dist/schema/relationships.d.ts.map +1 -0
  78. package/dist/schema/role-permissions.d.ts +305 -0
  79. package/dist/schema/role-permissions.d.ts.map +1 -0
  80. package/dist/schema/roles.d.ts +260 -0
  81. package/dist/schema/roles.d.ts.map +1 -0
  82. package/dist/schema/scheduled-tasks.d.ts +1334 -0
  83. package/dist/schema/scheduled-tasks.d.ts.map +1 -0
  84. package/dist/schema/settings.d.ts +819 -0
  85. package/dist/schema/settings.d.ts.map +1 -0
  86. package/dist/schema/site-presentation.d.ts +1587 -0
  87. package/dist/schema/site-presentation.d.ts.map +1 -0
  88. package/dist/schema/teams.d.ts +381 -0
  89. package/dist/schema/teams.d.ts.map +1 -0
  90. package/dist/schema/web-design.d.ts +1542 -0
  91. package/dist/schema/web-design.d.ts.map +1 -0
  92. package/dist/schema/webhooks.d.ts +1016 -0
  93. package/dist/schema/webhooks.d.ts.map +1 -0
  94. package/dist/zod/index.d.ts +2 -0
  95. package/dist/zod/index.d.ts.map +1 -0
  96. package/dist/zod/index.js +6 -0
  97. package/dist/zod/index.js.map +1 -0
  98. package/package.json +63 -0
@@ -0,0 +1,3390 @@
1
+ import {
2
+ TagPrefix,
3
+ __export,
4
+ createLbacIndexes,
5
+ lbacFields,
6
+ ownerFields,
7
+ permissionFields,
8
+ scopeFields
9
+ } from "./chunk-KWWJRUIK.js";
10
+
11
+ // src/schema/index.ts
12
+ var schema_exports = {};
13
+ __export(schema_exports, {
14
+ ACTION_JOURNAL_ACTIVE_STATUSES: () => ACTION_JOURNAL_ACTIVE_STATUSES,
15
+ ACTION_JOURNAL_STATUSES: () => ACTION_JOURNAL_STATUSES,
16
+ AccessLevel: () => AccessLevel,
17
+ CREDENTIAL_ACCOUNT_ISSUER: () => CREDENTIAL_ACCOUNT_ISSUER,
18
+ ENTITY_EXTENSION_PROJECTION_STATUSES: () => ENTITY_EXTENSION_PROJECTION_STATUSES,
19
+ ENTITY_EXTENSION_VALUE_TYPES: () => ENTITY_EXTENSION_VALUE_TYPES,
20
+ I18N_MESSAGE_FORMATS: () => I18N_MESSAGE_FORMATS,
21
+ MARKET_REGIONS: () => MARKET_REGIONS,
22
+ NotificationTypeEnum: () => NotificationTypeEnum,
23
+ PLUGIN_INSTALL_JOB_STATUSES: () => PLUGIN_INSTALL_JOB_STATUSES,
24
+ PLUGIN_INSTALL_OPERATIONS: () => PLUGIN_INSTALL_OPERATIONS,
25
+ PLUGIN_INSTALL_SOURCES: () => PLUGIN_INSTALL_SOURCES,
26
+ PLUGIN_MARKETPLACE_STATES: () => PLUGIN_MARKETPLACE_STATES,
27
+ PLUGIN_TRUST_LEVELS: () => PLUGIN_TRUST_LEVELS,
28
+ ROLE_PERMISSIONS: () => ROLE_PERMISSIONS,
29
+ SYS_INBOX_CODE: () => SYS_INBOX_CODE,
30
+ ScopeType: () => ScopeType,
31
+ TagPrefix: () => TagPrefix,
32
+ WEB_DOMAIN_CERTIFICATE_STATUSES: () => WEB_DOMAIN_CERTIFICATE_STATUSES,
33
+ WEB_DOMAIN_STATUSES: () => WEB_DOMAIN_STATUSES,
34
+ WEB_PAGE_RESERVED_PATHS: () => WEB_PAGE_RESERVED_PATHS,
35
+ WEB_PAGE_RESERVED_PREFIXES: () => WEB_PAGE_RESERVED_PREFIXES,
36
+ WEB_PAGE_STATUSES: () => WEB_PAGE_STATUSES,
37
+ WEB_THEME_REVISION_STATUSES: () => WEB_THEME_REVISION_STATUSES,
38
+ WEB_THEME_SELECTION_STATUSES: () => WEB_THEME_SELECTION_STATUSES,
39
+ account: () => account,
40
+ accountSchema: () => accountSchema,
41
+ actionExecutionJournal: () => actionExecutionJournal,
42
+ actionExecutionOutbox: () => actionExecutionOutbox,
43
+ activateWebThemeMutation: () => activateWebThemeMutation,
44
+ activateWebThemeRevisionMutation: () => activateWebThemeRevisionMutation,
45
+ apikey: () => apikey,
46
+ apikeySchema: () => apikeySchema,
47
+ appendPluginUploadMutation: () => appendPluginUploadMutation,
48
+ auditEventSchema: () => auditEventSchema,
49
+ auditEvents: () => auditEvents,
50
+ auditEventsArchive: () => auditEventsArchive,
51
+ auditEventsArchiveSchema: () => auditEventsArchiveSchema,
52
+ auditLogSchema: () => auditLogSchema,
53
+ auditLogs: () => auditLogs,
54
+ auditLogsArchive: () => auditLogsArchive,
55
+ auditLogsArchiveSchema: () => auditLogsArchiveSchema,
56
+ batchUpdateMessagesMutation: () => batchUpdateMessagesMutation,
57
+ billingEventOutbox: () => billingEventOutbox,
58
+ billingEventOutboxSchema: () => billingEventOutboxSchema,
59
+ capabilities: () => capabilities,
60
+ capabilitySchema: () => capabilitySchema,
61
+ checkFeatureFlagQuery: () => checkFeatureFlagQuery,
62
+ completePluginUploadMutation: () => completePluginUploadMutation,
63
+ countryCode2Schema: () => countryCode2Schema,
64
+ countryCode3Schema: () => countryCode3Schema,
65
+ createLbacIndexes: () => createLbacIndexes,
66
+ createMenuSchema: () => createMenuSchema,
67
+ createPluginUploadMutation: () => createPluginUploadMutation,
68
+ createWebDomainMutation: () => createWebDomainMutation,
69
+ createWebPageMutation: () => createWebPageMutation,
70
+ currencies: () => currencies,
71
+ currencySchema: () => currencySchema,
72
+ deleteFeatureFlagMutation: () => deleteFeatureFlagMutation,
73
+ deleteMenuMutation: () => deleteMenuMutation,
74
+ deleteSettingMutation: () => deleteSettingMutation,
75
+ deleteWebDomainMutation: () => deleteWebDomainMutation,
76
+ disableWebDomainMutation: () => disableWebDomainMutation,
77
+ entityOwnershipSchema: () => entityOwnershipSchema,
78
+ entityOwnerships: () => entityOwnerships,
79
+ exchangeRateSchema: () => exchangeRateSchema,
80
+ exchangeRates: () => exchangeRates,
81
+ extProjection: () => extProjection,
82
+ featureFlagOverrideSchema: () => featureFlagOverrideSchema,
83
+ featureFlagOverrides: () => featureFlagOverrides,
84
+ featureFlagSchema: () => featureFlagSchema,
85
+ featureFlags: () => featureFlags,
86
+ flagConditionSchema: () => flagConditionSchema,
87
+ geoCountries: () => geoCountries,
88
+ geoCountrySchema: () => geoCountrySchema,
89
+ geoNameSchema: () => geoNameSchema,
90
+ geoSubdivisionSchema: () => geoSubdivisionSchema,
91
+ geoSubdivisions: () => geoSubdivisions,
92
+ getFeatureFlagQuery: () => getFeatureFlagQuery,
93
+ getGeoCountryQuery: () => getGeoCountryQuery,
94
+ getGeoSubdivisionQuery: () => getGeoSubdivisionQuery,
95
+ getI18nBundlesQuery: () => getI18nBundlesQuery,
96
+ getI18nBundlesResultSchema: () => getI18nBundlesResultSchema,
97
+ getI18nMessagesQuery: () => getI18nMessagesQuery,
98
+ getMenuQuery: () => getMenuQuery,
99
+ getPluginInstallJobQuery: () => getPluginInstallJobQuery,
100
+ getSettingQuery: () => getSettingQuery,
101
+ getWebDomainQuery: () => getWebDomainQuery,
102
+ getWebPageDocumentQuery: () => getWebPageDocumentQuery,
103
+ getWebThemeQuery: () => getWebThemeQuery,
104
+ getWebThemeRevisionQuery: () => getWebThemeRevisionQuery,
105
+ i18nBundleSchema: () => i18nBundleSchema,
106
+ i18nBundleVersions: () => i18nBundleVersions,
107
+ i18nDirectionSchema: () => i18nDirectionSchema,
108
+ i18nLanguageSchema: () => i18nLanguageSchema,
109
+ i18nLanguages: () => i18nLanguages,
110
+ i18nMessageFormatSchema: () => i18nMessageFormatSchema,
111
+ i18nMessageSchema: () => i18nMessageSchema,
112
+ i18nMessageSourceSchema: () => i18nMessageSourceSchema,
113
+ i18nMessageTypeSchema: () => i18nMessageTypeSchema,
114
+ i18nMessages: () => i18nMessages,
115
+ importMediaFromUrlMutation: () => importMediaFromUrlMutation,
116
+ installPluginFromRegistryMutation: () => installPluginFromRegistryMutation,
117
+ invitation: () => invitation,
118
+ invitationSchema: () => invitationSchema,
119
+ issueWebThemePreviewMutation: () => issueWebThemePreviewMutation,
120
+ lbacFields: () => lbacFields,
121
+ listAllMenusQuery: () => listAllMenusQuery,
122
+ listFeatureFlagsQuery: () => listFeatureFlagsQuery,
123
+ listFlagOverridesQuery: () => listFlagOverridesQuery,
124
+ listGeoCountriesQuery: () => listGeoCountriesQuery,
125
+ listGeoSubdivisionsQuery: () => listGeoSubdivisionsQuery,
126
+ listI18nLanguagesQuery: () => listI18nLanguagesQuery,
127
+ listI18nMessagesQuery: () => listI18nMessagesQuery,
128
+ listMarketRegionsQuery: () => listMarketRegionsQuery,
129
+ listMenusQuery: () => listMenusQuery,
130
+ listPluginCatalogQuery: () => listPluginCatalogQuery,
131
+ listSettingsQuery: () => listSettingsQuery,
132
+ listWebThemeRevisionsQuery: () => listWebThemeRevisionsQuery,
133
+ localeSchema: () => localeSchema,
134
+ media: () => media,
135
+ mediaInsertSchema: () => mediaInsertSchema,
136
+ mediaSelectSchema: () => mediaSelectSchema,
137
+ member: () => member,
138
+ memberSchema: () => memberSchema,
139
+ menuSchema: () => menuSchema,
140
+ menus: () => menus,
141
+ notificationChannelSchema: () => notificationChannelSchema,
142
+ notificationChannels: () => notificationChannels,
143
+ notificationPreferenceSchema: () => notificationPreferenceSchema,
144
+ notificationPreferences: () => notificationPreferences,
145
+ notificationSchema: () => notificationSchema,
146
+ notificationTemplateSchema: () => notificationTemplateSchema,
147
+ notificationTemplates: () => notificationTemplates,
148
+ notifications: () => notifications,
149
+ organization: () => organization,
150
+ organizationSchema: () => organizationSchema,
151
+ ownerFields: () => ownerFields,
152
+ ownershipAuditLog: () => ownershipAuditLog,
153
+ ownershipAuditLogSchema: () => ownershipAuditLogSchema,
154
+ permissionFields: () => permissionFields,
155
+ permissionSchema: () => permissionSchema,
156
+ permissions: () => permissions,
157
+ planItemSchema: () => planItemSchema,
158
+ planItems: () => planItems,
159
+ planSchema: () => planSchema,
160
+ planSubscriptionSchema: () => planSubscriptionSchema,
161
+ planSubscriptions: () => planSubscriptions,
162
+ plans: () => plans,
163
+ pluginCatalogReleaseSchema: () => pluginCatalogReleaseSchema,
164
+ pluginCatalogReleases: () => pluginCatalogReleases,
165
+ pluginConfigSchema: () => pluginConfigSchema,
166
+ pluginConfigs: () => pluginConfigs,
167
+ pluginInstallJobSchema: () => pluginInstallJobSchema,
168
+ pluginInstallJobs: () => pluginInstallJobs,
169
+ pluginInstanceSchema: () => pluginInstanceSchema,
170
+ pluginInstances: () => pluginInstances,
171
+ pluginMigrationSchema: () => pluginMigrationSchema,
172
+ pluginMigrations: () => pluginMigrations,
173
+ pluginRegistrySyncState: () => pluginRegistrySyncState,
174
+ pluginSchema: () => pluginSchema,
175
+ plugins: () => plugins,
176
+ publishWebPageMutation: () => publishWebPageMutation,
177
+ publishWebThemeDraftMutation: () => publishWebThemeDraftMutation,
178
+ recoverWebThemeMutation: () => recoverWebThemeMutation,
179
+ relationship: () => relationship,
180
+ relationshipSchema: () => relationshipSchema,
181
+ removeFlagOverrideMutation: () => removeFlagOverrideMutation,
182
+ requestWebDomainCertificateMutation: () => requestWebDomainCertificateMutation,
183
+ rolePermissionSchema: () => rolePermissionSchema,
184
+ rolePermissions: () => rolePermissions,
185
+ roleSchema: () => roleSchema,
186
+ roles: () => roles,
187
+ rollbackPluginInstallMutation: () => rollbackPluginInstallMutation,
188
+ rollbackWebThemeRevisionMutation: () => rollbackWebThemeRevisionMutation,
189
+ saveWebPageDocumentMutation: () => saveWebPageDocumentMutation,
190
+ saveWebThemeDraftMutation: () => saveWebThemeDraftMutation,
191
+ scheduledTaskSchema: () => scheduledTaskSchema,
192
+ scheduledTasks: () => scheduledTasks,
193
+ schedulerProviderSchema: () => schedulerProviderSchema,
194
+ schedulerProviders: () => schedulerProviders,
195
+ scopeFields: () => scopeFields,
196
+ session: () => session,
197
+ sessionSchema: () => sessionSchema,
198
+ setDefaultLanguageMutation: () => setDefaultLanguageMutation,
199
+ setFlagOverrideMutation: () => setFlagOverrideMutation,
200
+ setPrimaryWebDomainMutation: () => setPrimaryWebDomainMutation,
201
+ setSettingMutation: () => setSettingMutation,
202
+ setWebThemeEnabledMutation: () => setWebThemeEnabledMutation,
203
+ settingSchema: () => settingSchema,
204
+ settingSchemaSchema: () => settingSchemaSchema,
205
+ settingSchemas: () => settingSchemas,
206
+ settingScopeSchema: () => settingScopeSchema,
207
+ settingValueTypeSchema: () => settingValueTypeSchema,
208
+ settings: () => settings,
209
+ subdivisionFullCodeSchema: () => subdivisionFullCodeSchema,
210
+ taskExecutionSchema: () => taskExecutionSchema,
211
+ taskExecutions: () => taskExecutions,
212
+ team: () => team,
213
+ teamMember: () => teamMember,
214
+ teamMemberSchema: () => teamMemberSchema,
215
+ teamSchema: () => teamSchema,
216
+ tenantQuotaSchema: () => tenantQuotaSchema,
217
+ tenantQuotas: () => tenantQuotas,
218
+ toggleMenuVisibilityMutation: () => toggleMenuVisibilityMutation,
219
+ transactionSchema: () => transactionSchema,
220
+ transactions: () => transactions,
221
+ translationsObjectSchema: () => translationsObjectSchema,
222
+ uninstallPluginFromInstanceMutation: () => uninstallPluginFromInstanceMutation,
223
+ updateFeatureFlagMutation: () => updateFeatureFlagMutation,
224
+ updateMenuMutation: () => updateMenuMutation,
225
+ updateMenuSchema: () => updateMenuSchema,
226
+ updateProfileMutation: () => updateProfileMutation,
227
+ updateWebDomainCertificateStatusMutation: () => updateWebDomainCertificateStatusMutation,
228
+ updateWebPageMutation: () => updateWebPageMutation,
229
+ usageRecordSchema: () => usageRecordSchema,
230
+ usageRecords: () => usageRecords,
231
+ user: () => user,
232
+ userQuotaSchema: () => userQuotaSchema,
233
+ userQuotas: () => userQuotas,
234
+ userSchema: () => userSchema,
235
+ verification: () => verification,
236
+ verificationSchema: () => verificationSchema,
237
+ verifyWebDomainMutation: () => verifyWebDomainMutation,
238
+ walletSchema: () => walletSchema,
239
+ wallets: () => wallets,
240
+ webDesignDocumentSchema: () => webDesignDocumentSchema,
241
+ webDomainHostnameSchema: () => webDomainHostnameSchema,
242
+ webDomainSchema: () => webDomainSchema,
243
+ webDomainSelectSchema: () => webDomainSelectSchema,
244
+ webDomains: () => webDomains,
245
+ webPagePathSchema: () => webPagePathSchema,
246
+ webPageSchema: () => webPageSchema,
247
+ webPageSelectSchema: () => webPageSelectSchema,
248
+ webPages: () => webPages,
249
+ webThemeAdapterConfigSchema: () => webThemeAdapterConfigSchema,
250
+ webThemeAdapterSelectionSchema: () => webThemeAdapterSelectionSchema,
251
+ webThemeHomeTargetSchema: () => webThemeHomeTargetSchema,
252
+ webThemeRevisionSchema: () => webThemeRevisionSchema,
253
+ webThemeRevisionSelectSchema: () => webThemeRevisionSelectSchema,
254
+ webThemeRevisions: () => webThemeRevisions,
255
+ webThemeSelectionSchema: () => webThemeSelectionSchema,
256
+ webThemeSelectionSelectSchema: () => webThemeSelectionSelectSchema,
257
+ webThemeSelections: () => webThemeSelections,
258
+ webhookDeliveries: () => webhookDeliveries,
259
+ webhookDeliverySchema: () => webhookDeliverySchema,
260
+ webhookEndpointSchema: () => webhookEndpointSchema,
261
+ webhookEndpoints: () => webhookEndpoints,
262
+ webhookOutbox: () => webhookOutbox,
263
+ webhookOutboxSchema: () => webhookOutboxSchema
264
+ });
265
+
266
+ // src/schema/auth.ts
267
+ import {
268
+ pgTable,
269
+ text,
270
+ integer,
271
+ timestamp,
272
+ boolean,
273
+ index,
274
+ uniqueIndex
275
+ } from "drizzle-orm/pg-core";
276
+ import { createInsertSchema } from "drizzle-orm/zod";
277
+ import { z } from "zod";
278
+ var user = pgTable("user", {
279
+ id: text("id").primaryKey(),
280
+ name: text("name").notNull(),
281
+ email: text("email").notNull().unique(),
282
+ emailVerified: boolean("email_verified").default(false).notNull(),
283
+ image: text("image"),
284
+ phoneNumber: text("phone_number").unique(),
285
+ phoneNumberVerified: boolean("phone_number_verified").default(false).notNull(),
286
+ whatsappAccount: text("whatsapp_account"),
287
+ createdAt: timestamp("created_at").defaultNow().notNull(),
288
+ updatedAt: timestamp("updated_at").defaultNow().$onUpdate(() => /* @__PURE__ */ new Date()).notNull(),
289
+ // Admin plugin fields
290
+ role: text("role").default("user"),
291
+ banned: boolean("banned").default(false),
292
+ banReason: text("ban_reason"),
293
+ banExpires: timestamp("ban_expires")
294
+ });
295
+ var session = pgTable(
296
+ "session",
297
+ {
298
+ id: text("id").primaryKey(),
299
+ expiresAt: timestamp("expires_at").notNull(),
300
+ token: text("token").notNull().unique(),
301
+ createdAt: timestamp("created_at").defaultNow().notNull(),
302
+ updatedAt: timestamp("updated_at").defaultNow().$onUpdate(() => /* @__PURE__ */ new Date()).notNull(),
303
+ ipAddress: text("ip_address"),
304
+ userAgent: text("user_agent"),
305
+ // FK to user table
306
+ userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
307
+ activeOrganizationId: text("active_organization_id"),
308
+ // Admin plugin field for impersonation
309
+ impersonatedBy: text("impersonated_by")
310
+ },
311
+ (table) => [index("session_userId_idx").on(table.userId)]
312
+ );
313
+ var CREDENTIAL_ACCOUNT_ISSUER = "local:credential";
314
+ var account = pgTable(
315
+ "account",
316
+ {
317
+ id: text("id").primaryKey(),
318
+ accountId: text("account_id").notNull(),
319
+ providerId: text("provider_id").notNull(),
320
+ issuer: text("issuer").notNull(),
321
+ // FK to user table
322
+ userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
323
+ accessToken: text("access_token"),
324
+ refreshToken: text("refresh_token"),
325
+ idToken: text("id_token"),
326
+ accessTokenExpiresAt: timestamp("access_token_expires_at"),
327
+ refreshTokenExpiresAt: timestamp("refresh_token_expires_at"),
328
+ scope: text("scope"),
329
+ password: text("password"),
330
+ createdAt: timestamp("created_at").defaultNow().notNull(),
331
+ updatedAt: timestamp("updated_at").defaultNow().$onUpdate(() => /* @__PURE__ */ new Date()).notNull()
332
+ },
333
+ (table) => [
334
+ index("account_userId_idx").on(table.userId),
335
+ uniqueIndex("account_issuer_accountId_uidx").on(table.issuer, table.accountId)
336
+ ]
337
+ );
338
+ var verification = pgTable(
339
+ "verification",
340
+ {
341
+ id: text("id").primaryKey(),
342
+ identifier: text("identifier").notNull(),
343
+ value: text("value").notNull(),
344
+ expiresAt: timestamp("expires_at").notNull(),
345
+ createdAt: timestamp("created_at").defaultNow().notNull(),
346
+ updatedAt: timestamp("updated_at").defaultNow().$onUpdate(() => /* @__PURE__ */ new Date()).notNull()
347
+ },
348
+ (table) => [index("verification_identifier_idx").on(table.identifier)]
349
+ );
350
+ var organization = pgTable(
351
+ "organization",
352
+ {
353
+ id: text("id").primaryKey(),
354
+ name: text("name").notNull(),
355
+ slug: text("slug").notNull().unique(),
356
+ logo: text("logo"),
357
+ createdAt: timestamp("created_at").defaultNow().notNull(),
358
+ metadata: text("metadata")
359
+ },
360
+ (table) => [uniqueIndex("organization_slug_uidx").on(table.slug)]
361
+ );
362
+ var member = pgTable(
363
+ "member",
364
+ {
365
+ id: text("id").primaryKey(),
366
+ // FK to organization table
367
+ organizationId: text("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
368
+ // FK to user table
369
+ userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
370
+ role: text("role").default("member").notNull(),
371
+ createdAt: timestamp("created_at").defaultNow().notNull(),
372
+ // Tenant-level ban fields
373
+ status: text("status").default("active").notNull(),
374
+ banReason: text("ban_reason"),
375
+ banExpires: timestamp("ban_expires")
376
+ },
377
+ (table) => [
378
+ index("member_organizationId_idx").on(table.organizationId),
379
+ index("member_userId_idx").on(table.userId)
380
+ ]
381
+ );
382
+ var invitation = pgTable(
383
+ "invitation",
384
+ {
385
+ id: text("id").primaryKey(),
386
+ // FK to organization table
387
+ organizationId: text("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
388
+ email: text("email").notNull(),
389
+ role: text("role"),
390
+ status: text("status").default("pending").notNull(),
391
+ expiresAt: timestamp("expires_at").notNull(),
392
+ createdAt: timestamp("created_at").defaultNow().notNull(),
393
+ // FK to user table
394
+ inviterId: text("inviter_id").notNull().references(() => user.id, { onDelete: "cascade" })
395
+ },
396
+ (table) => [
397
+ index("invitation_organizationId_idx").on(table.organizationId),
398
+ index("invitation_email_idx").on(table.email)
399
+ ]
400
+ );
401
+ var apikey = pgTable(
402
+ "apikey",
403
+ {
404
+ id: text("id").primaryKey(),
405
+ configId: text("config_id").default("default").notNull(),
406
+ name: text("name"),
407
+ start: text("start"),
408
+ prefix: text("prefix"),
409
+ key: text("key").notNull(),
410
+ // FK to user table
411
+ referenceId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
412
+ refillInterval: integer("refill_interval"),
413
+ refillAmount: integer("refill_amount"),
414
+ lastRefillAt: timestamp("last_refill_at"),
415
+ enabled: boolean("enabled").default(true),
416
+ rateLimitEnabled: boolean("rate_limit_enabled").default(true),
417
+ rateLimitTimeWindow: integer("rate_limit_time_window"),
418
+ rateLimitMax: integer("rate_limit_max"),
419
+ requestCount: integer("request_count").default(0),
420
+ remaining: integer("remaining"),
421
+ lastRequest: timestamp("last_request"),
422
+ expiresAt: timestamp("expires_at"),
423
+ createdAt: timestamp("created_at").defaultNow().notNull(),
424
+ updatedAt: timestamp("updated_at").defaultNow().$onUpdate(() => /* @__PURE__ */ new Date()).notNull(),
425
+ permissions: text("permissions"),
426
+ metadata: text("metadata")
427
+ },
428
+ (table) => [
429
+ index("apikey_configId_idx").on(table.configId),
430
+ index("apikey_userId_idx").on(table.referenceId)
431
+ ]
432
+ );
433
+ var userSchema = createInsertSchema(user);
434
+ var sessionSchema = createInsertSchema(session);
435
+ var accountSchema = createInsertSchema(account);
436
+ var verificationSchema = createInsertSchema(verification);
437
+ var organizationSchema = createInsertSchema(organization);
438
+ var memberSchema = createInsertSchema(member);
439
+ var invitationSchema = createInsertSchema(invitation);
440
+ var apikeySchema = createInsertSchema(apikey);
441
+ var updateProfileMutation = z.object({
442
+ name: z.preprocess(
443
+ (value) => typeof value === "string" ? value.trim() : value,
444
+ z.string().min(1, "\u59D3\u540D\u4E0D\u80FD\u4E3A\u7A7A").max(80, "\u59D3\u540D\u4E0D\u80FD\u8D85\u8FC7 80 \u4E2A\u5B57\u7B26").optional()
445
+ ),
446
+ whatsappAccount: z.preprocess(
447
+ (value) => typeof value === "string" ? value.trim() : value,
448
+ z.string().max(64).nullable().optional()
449
+ ).transform((value) => value === "" ? null : value)
450
+ });
451
+
452
+ // src/schema/teams.ts
453
+ import {
454
+ pgTable as pgTable2,
455
+ text as text2,
456
+ timestamp as timestamp2,
457
+ integer as integer2,
458
+ index as index2,
459
+ uniqueIndex as uniqueIndex2
460
+ } from "drizzle-orm/pg-core";
461
+ import { createInsertSchema as createInsertSchema2 } from "drizzle-orm/zod";
462
+ var team = pgTable2(
463
+ "team",
464
+ {
465
+ id: text2("id").primaryKey(),
466
+ name: text2("name").notNull(),
467
+ // FK to organization table
468
+ organizationId: text2("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
469
+ createdAt: timestamp2("created_at").defaultNow().notNull(),
470
+ updatedAt: timestamp2("updated_at").defaultNow().$onUpdate(() => /* @__PURE__ */ new Date()).notNull(),
471
+ // Hierarchical structure
472
+ parentId: text2("parent_id"),
473
+ path: text2("path"),
474
+ // Materialized path for efficient tree queries
475
+ level: integer2("level").default(0).notNull()
476
+ },
477
+ (table) => [
478
+ index2("team_organizationId_idx").on(table.organizationId),
479
+ index2("team_parent_idx").on(table.parentId),
480
+ index2("team_org_path_idx").on(table.organizationId, table.path)
481
+ ]
482
+ );
483
+ var teamMember = pgTable2(
484
+ "team_member",
485
+ {
486
+ id: text2("id").primaryKey(),
487
+ // FK to team table
488
+ teamId: text2("team_id").notNull().references(() => team.id, { onDelete: "cascade" }),
489
+ // FK to user table
490
+ userId: text2("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
491
+ createdAt: timestamp2("created_at").defaultNow().notNull()
492
+ },
493
+ (table) => [
494
+ uniqueIndex2("teamMember_team_user_uidx").on(table.teamId, table.userId),
495
+ index2("teamMember_teamId_idx").on(table.teamId),
496
+ index2("teamMember_userId_idx").on(table.userId)
497
+ ]
498
+ );
499
+ var teamSchema = createInsertSchema2(team);
500
+ var teamMemberSchema = createInsertSchema2(teamMember);
501
+
502
+ // src/schema/relationships.ts
503
+ import {
504
+ pgTable as pgTable3,
505
+ text as text3,
506
+ timestamp as timestamp3,
507
+ jsonb,
508
+ index as index3,
509
+ uniqueIndex as uniqueIndex3
510
+ } from "drizzle-orm/pg-core";
511
+ import { createInsertSchema as createInsertSchema3 } from "drizzle-orm/zod";
512
+ var relationship = pgTable3(
513
+ "relationship",
514
+ {
515
+ id: text3("id").primaryKey(),
516
+ // Relationship type (e.g., 'follows', 'contains', 'manages')
517
+ type: text3("type").notNull(),
518
+ // Source entity ID
519
+ sourceId: text3("source_id").notNull(),
520
+ // Target entity ID
521
+ targetId: text3("target_id").notNull(),
522
+ // FK to organization table
523
+ organizationId: text3("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
524
+ // Additional metadata for the relationship
525
+ metadata: jsonb("metadata"),
526
+ createdAt: timestamp3("created_at").defaultNow().notNull()
527
+ },
528
+ (table) => [
529
+ index3("relationship_org_idx").on(table.organizationId),
530
+ index3("relationship_source_idx").on(table.type, table.sourceId),
531
+ index3("relationship_target_idx").on(table.type, table.targetId),
532
+ uniqueIndex3("relationship_unique_idx").on(
533
+ table.type,
534
+ table.sourceId,
535
+ table.targetId
536
+ )
537
+ ]
538
+ );
539
+ var relationshipSchema = createInsertSchema3(relationship);
540
+
541
+ // src/schema/i18n.ts
542
+ import {
543
+ pgTable as pgTable4,
544
+ text as text4,
545
+ timestamp as timestamp4,
546
+ boolean as boolean2,
547
+ integer as integer3,
548
+ jsonb as jsonb2,
549
+ varchar,
550
+ index as index4,
551
+ uniqueIndex as uniqueIndex4
552
+ } from "drizzle-orm/pg-core";
553
+ import { createInsertSchema as createInsertSchema4 } from "drizzle-orm/zod";
554
+ import { z as z3 } from "zod/v4";
555
+
556
+ // src/schema/common.ts
557
+ import { z as z2 } from "zod/v4";
558
+ var paginationSchema = z2.object({
559
+ limit: z2.number().int().min(1).max(100).default(20),
560
+ offset: z2.number().int().min(0).default(0)
561
+ });
562
+ var cursorPaginationSchema = z2.object({
563
+ cursor: z2.string().optional(),
564
+ limit: z2.number().int().min(1).max(100).default(20)
565
+ });
566
+ var sortSchema = z2.object({
567
+ sortBy: z2.string().optional(),
568
+ sortOrder: z2.enum(["asc", "desc"]).default("asc")
569
+ });
570
+ var searchSchema = z2.object({
571
+ q: z2.string().min(1).optional()
572
+ });
573
+ var listQueryBase = paginationSchema.merge(sortSchema);
574
+ var searchListQueryBase = listQueryBase.merge(searchSchema);
575
+ var idSchema = z2.object({
576
+ id: z2.string()
577
+ });
578
+ var uuidSchema = z2.object({
579
+ id: z2.string().uuid()
580
+ });
581
+ var batchIdsSchema = z2.object({
582
+ ids: z2.array(z2.string()).min(1)
583
+ });
584
+ var dateRangeSchema = z2.object({
585
+ startDate: z2.string().datetime().optional(),
586
+ endDate: z2.string().datetime().optional()
587
+ });
588
+
589
+ // src/schema/i18n.ts
590
+ var I18N_MESSAGE_FORMATS = [
591
+ "legacy-mixed",
592
+ "i18next-v4",
593
+ "legacy-projection"
594
+ ];
595
+ var i18nLanguages = pgTable4(
596
+ "i18n_languages",
597
+ {
598
+ id: text4("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
599
+ // FK to organization table
600
+ organizationId: text4("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
601
+ // Language identification (BCP 47)
602
+ locale: text4("locale").notNull(),
603
+ // e.g., 'en-US', 'zh-CN', 'ar-SA'
604
+ name: text4("name").notNull(),
605
+ // e.g., 'English', '简体中文', 'العربية'
606
+ nativeName: text4("native_name"),
607
+ // e.g., 'English', '中文', 'العربية'
608
+ // Status
609
+ isDefault: boolean2("is_default").notNull().default(false),
610
+ isEnabled: boolean2("is_enabled").notNull().default(true),
611
+ // Display order
612
+ sortOrder: integer3("sort_order").notNull().default(0),
613
+ // RTL support
614
+ direction: text4("direction").notNull().default("ltr").$type(),
615
+ // Audit fields
616
+ createdAt: timestamp4("created_at").notNull().defaultNow(),
617
+ updatedAt: timestamp4("updated_at").notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
618
+ },
619
+ (table) => [
620
+ // Each locale is unique per organization
621
+ uniqueIndex4("i18n_languages_org_locale_uidx").on(
622
+ table.organizationId,
623
+ table.locale
624
+ ),
625
+ // Fast lookup by organization
626
+ index4("i18n_languages_org_idx").on(table.organizationId),
627
+ // Fast lookup for enabled languages
628
+ index4("i18n_languages_enabled_idx").on(table.organizationId, table.isEnabled)
629
+ ]
630
+ );
631
+ var i18nMessages = pgTable4(
632
+ "i18n_messages",
633
+ {
634
+ id: text4("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
635
+ // FK to organization table
636
+ organizationId: text4("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
637
+ // Message identification
638
+ key: text4("key").notNull(),
639
+ // e.g., 'order.submit', 'common.save'
640
+ namespace: text4("namespace").notNull(),
641
+ // e.g., 'core', 'admin', 'plugin:dsneo.orders'
642
+ // Message type
643
+ type: text4("type").notNull().default("page").$type(),
644
+ // Translations (JSONB)
645
+ translations: jsonb2("translations").notNull().default({}).$type(),
646
+ // Description for translators
647
+ description: text4("description"),
648
+ // Source tracking
649
+ source: text4("source").notNull().default("user").$type(),
650
+ sourceId: text4("source_id"),
651
+ // Plugin ID if source is 'plugin'
652
+ // User modification tracking (for plugin upgrade protection)
653
+ // Deprecated rollback-only mirror. New runtime code must not read or write it.
654
+ userModified: boolean2("user_modified").notNull().default(false),
655
+ modifiedLocales: jsonb2("modified_locales").notNull().default([]).$type(),
656
+ archivedLocales: jsonb2("archived_locales").notNull().default([]).$type(),
657
+ messageFormat: varchar("message_format", {
658
+ length: 32,
659
+ enum: I18N_MESSAGE_FORMATS
660
+ }).notNull().default("i18next-v4").$type(),
661
+ // Status
662
+ isEnabled: boolean2("is_enabled").notNull().default(true),
663
+ // Version for optimistic locking
664
+ version: integer3("version").notNull().default(1),
665
+ // Audit fields
666
+ createdAt: timestamp4("created_at").notNull().defaultNow(),
667
+ updatedAt: timestamp4("updated_at").notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
668
+ },
669
+ (table) => [
670
+ // Each key is unique per organization + namespace
671
+ uniqueIndex4("i18n_messages_org_ns_key_uidx").on(
672
+ table.organizationId,
673
+ table.namespace,
674
+ table.key
675
+ ),
676
+ // Fast lookup by organization
677
+ index4("i18n_messages_org_idx").on(table.organizationId),
678
+ // Fast lookup by namespace (for loading translations)
679
+ index4("i18n_messages_org_ns_idx").on(table.organizationId, table.namespace),
680
+ // Fast lookup by source (for plugin lifecycle)
681
+ index4("i18n_messages_source_idx").on(table.source, table.sourceId)
682
+ ]
683
+ );
684
+ var i18nBundleVersions = pgTable4(
685
+ "i18n_bundle_versions",
686
+ {
687
+ id: text4("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
688
+ organizationId: text4("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
689
+ namespace: text4("namespace").notNull(),
690
+ generation: integer3("generation").notNull().default(1),
691
+ cacheDirty: boolean2("cache_dirty").notNull().default(false),
692
+ createdAt: timestamp4("created_at").notNull().defaultNow(),
693
+ updatedAt: timestamp4("updated_at").notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
694
+ },
695
+ (table) => [
696
+ uniqueIndex4("i18n_bundle_versions_org_ns_uidx").on(
697
+ table.organizationId,
698
+ table.namespace
699
+ ),
700
+ index4("i18n_bundle_versions_dirty_idx").on(
701
+ table.cacheDirty,
702
+ table.organizationId
703
+ )
704
+ ]
705
+ );
706
+ function canonicalizeLocale(value) {
707
+ if (typeof value !== "string") return void 0;
708
+ const locale = value.trim();
709
+ if (!locale || locale === "*") return void 0;
710
+ try {
711
+ return Intl.getCanonicalLocales(locale)[0];
712
+ } catch {
713
+ return void 0;
714
+ }
715
+ }
716
+ var localeSchema = z3.string().min(1).refine((value) => canonicalizeLocale(value) !== void 0, "Invalid BCP 47 locale").transform((value) => canonicalizeLocale(value));
717
+ var translationsObjectSchema = z3.record(z3.string(), z3.string());
718
+ var i18nDirectionSchema = z3.enum(["ltr", "rtl"]);
719
+ var i18nMessageTypeSchema = z3.enum(["page", "api"]);
720
+ var i18nMessageSourceSchema = z3.enum(["core", "plugin", "user"]);
721
+ var i18nMessageFormatSchema = z3.enum(I18N_MESSAGE_FORMATS);
722
+ var i18nLanguageSchema = createInsertSchema4(i18nLanguages, {
723
+ locale: () => localeSchema,
724
+ name: (schema) => schema.min(1).max(50),
725
+ nativeName: (schema) => schema.max(50)
726
+ });
727
+ var i18nMessageSchema = createInsertSchema4(i18nMessages, {
728
+ key: (schema) => schema.min(1).max(200),
729
+ namespace: (schema) => schema.min(1).max(100)
730
+ });
731
+ var getI18nMessagesQuery = z3.object({
732
+ locale: localeSchema,
733
+ namespaces: z3.array(z3.string()).optional(),
734
+ version: z3.string().optional()
735
+ });
736
+ var getI18nBundlesQuery = z3.object({
737
+ locale: localeSchema,
738
+ namespaces: z3.array(z3.string().min(1).max(160)).min(1).max(32),
739
+ versions: z3.record(z3.string(), z3.string()).optional()
740
+ });
741
+ var i18nBundleSchema = z3.object({
742
+ version: z3.string(),
743
+ notModified: z3.boolean(),
744
+ messages: translationsObjectSchema.optional()
745
+ });
746
+ var getI18nBundlesResultSchema = z3.object({
747
+ bundles: z3.record(z3.string(), i18nBundleSchema)
748
+ });
749
+ var listI18nLanguagesQuery = paginationSchema.partial();
750
+ var listI18nMessagesQuery = z3.object({
751
+ namespace: z3.string().optional(),
752
+ key: z3.string().optional()
753
+ }).merge(paginationSchema.partial());
754
+ var setDefaultLanguageMutation = z3.object({
755
+ locale: localeSchema
756
+ });
757
+ var batchUpdateMessagesMutation = z3.object({
758
+ messages: z3.array(z3.object({
759
+ key: z3.string(),
760
+ namespace: z3.string(),
761
+ translations: translationsObjectSchema
762
+ }))
763
+ });
764
+
765
+ // src/schema/roles.ts
766
+ import {
767
+ pgTable as pgTable5,
768
+ text as text5,
769
+ timestamp as timestamp5,
770
+ boolean as boolean3,
771
+ uniqueIndex as uniqueIndex5,
772
+ index as index5
773
+ } from "drizzle-orm/pg-core";
774
+ import { createInsertSchema as createInsertSchema5 } from "drizzle-orm/zod";
775
+ var roles = pgTable5(
776
+ "roles",
777
+ {
778
+ id: text5("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
779
+ // FK to organization table
780
+ organizationId: text5("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
781
+ name: text5("name").notNull(),
782
+ slug: text5("slug").notNull(),
783
+ description: text5("description"),
784
+ isSystem: boolean3("is_system").notNull().default(false),
785
+ createdAt: timestamp5("created_at").notNull().defaultNow(),
786
+ updatedAt: timestamp5("updated_at").notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
787
+ },
788
+ (table) => [
789
+ uniqueIndex5("roles_org_slug_uidx").on(table.organizationId, table.slug),
790
+ index5("roles_organization_id_idx").on(table.organizationId)
791
+ ]
792
+ );
793
+ var roleSchema = createInsertSchema5(roles);
794
+
795
+ // src/schema/role-permissions.ts
796
+ import {
797
+ pgTable as pgTable6,
798
+ text as text6,
799
+ timestamp as timestamp6,
800
+ boolean as boolean4,
801
+ jsonb as jsonb3,
802
+ uniqueIndex as uniqueIndex6,
803
+ index as index6
804
+ } from "drizzle-orm/pg-core";
805
+ import { createInsertSchema as createInsertSchema6 } from "drizzle-orm/zod";
806
+ var rolePermissions = pgTable6(
807
+ "role_permissions",
808
+ {
809
+ id: text6("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
810
+ // FK to roles table
811
+ roleId: text6("role_id").notNull().references(() => roles.id, { onDelete: "cascade" }),
812
+ // CASL rule fields
813
+ action: text6("action").notNull(),
814
+ subject: text6("subject").notNull(),
815
+ fields: jsonb3("fields").$type(),
816
+ conditions: jsonb3("conditions").$type(),
817
+ inverted: boolean4("inverted").notNull().default(false),
818
+ // Plugin tracking
819
+ source: text6("source"),
820
+ // Plugin ID if from a plugin, null for core permissions
821
+ createdAt: timestamp6("created_at").notNull().defaultNow()
822
+ },
823
+ (table) => [
824
+ // Unique constraint on role + action + subject combination
825
+ uniqueIndex6("role_permissions_role_action_subject_uidx").on(
826
+ table.roleId,
827
+ table.action,
828
+ table.subject
829
+ ),
830
+ index6("role_permissions_role_id_idx").on(table.roleId),
831
+ index6("role_permissions_source_idx").on(table.source)
832
+ ]
833
+ );
834
+ var rolePermissionSchema = createInsertSchema6(rolePermissions);
835
+
836
+ // src/schema/permissions.ts
837
+ import { pgTable as pgTable7, text as text7, timestamp as timestamp7 } from "drizzle-orm/pg-core";
838
+ import { createInsertSchema as createInsertSchema7 } from "drizzle-orm/zod";
839
+ var permissions = pgTable7("permissions", {
840
+ id: text7("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
841
+ capability: text7("capability").notNull().unique(),
842
+ source: text7("source").notNull(),
843
+ // 'core' | pluginId
844
+ description: text7("description"),
845
+ createdAt: timestamp7("created_at").notNull().defaultNow()
846
+ });
847
+ var permissionSchema = createInsertSchema7(permissions);
848
+ var ROLE_PERMISSIONS = {
849
+ owner: ["*:*:*"],
850
+ admin: ["organization:*:*", "plugin:*:*", "user:manage:*", "content:*:*"],
851
+ editor: ["content:create:space", "content:update:own", "content:read:*"],
852
+ member: ["content:read:space", "content:comment:*"],
853
+ viewer: ["content:read:public"]
854
+ };
855
+
856
+ // src/schema/menus.ts
857
+ import {
858
+ pgTable as pgTable8,
859
+ text as text8,
860
+ integer as integer4,
861
+ timestamp as timestamp8,
862
+ jsonb as jsonb4,
863
+ index as index7,
864
+ uniqueIndex as uniqueIndex7,
865
+ boolean as boolean5
866
+ } from "drizzle-orm/pg-core";
867
+ import { createInsertSchema as createInsertSchema8 } from "drizzle-orm/zod";
868
+ import { z as z4 } from "zod/v4";
869
+ var menus = pgTable8(
870
+ "menus",
871
+ {
872
+ // Primary key (UUID for database)
873
+ id: text8("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
874
+ // Logical identifier (stable across tenants)
875
+ // Format: 'core:dashboard', 'plugin:blog:posts', 'custom:my-menu'
876
+ code: text8("code").notNull(),
877
+ // Menu Type
878
+ type: text8("type").notNull().$type(),
879
+ // system = core/plugin, custom = tenant-created
880
+ // Source (for system menus: 'core' | pluginId)
881
+ source: text8("source").notNull(),
882
+ // 'core' | pluginId | 'custom'
883
+ // FK to organization table (nullable: NULL = global template, value = organization-specific)
884
+ organizationId: text8("organization_id").references(() => organization.id, { onDelete: "cascade" }),
885
+ // Menu Display
886
+ label: text8("label").notNull(),
887
+ icon: text8("icon"),
888
+ path: text8("path"),
889
+ // NULL for directory menus
890
+ openMode: text8("open_mode").notNull().default("route").$type(),
891
+ // Hierarchy (using code for logical reference)
892
+ parentCode: text8("parent_code"),
893
+ // NULL = root level, 'SYS_INBOX' = orphaned
894
+ order: integer4("order").notNull().default(0),
895
+ // Visibility Control
896
+ visible: boolean5("visible").notNull().default(true),
897
+ // Tenant can hide menus
898
+ // Permission Control
899
+ requiredPermission: text8("required_permission"),
900
+ // Target Application
901
+ target: text8("target").notNull().$type(),
902
+ // Extensibility
903
+ metadata: jsonb4("metadata"),
904
+ // Timestamps
905
+ createdAt: timestamp8("created_at").notNull().defaultNow(),
906
+ updatedAt: timestamp8("updated_at").notNull().defaultNow()
907
+ },
908
+ (table) => [
909
+ // Unique constraint: code + organizationId (allows same code in different organizations)
910
+ uniqueIndex7("menus_code_org_idx").on(table.code, table.organizationId),
911
+ // Query optimization indexes
912
+ index7("menus_org_idx").on(table.organizationId),
913
+ index7("menus_source_org_idx").on(table.source, table.organizationId),
914
+ index7("menus_target_idx").on(table.target),
915
+ index7("menus_parent_code_idx").on(table.parentCode),
916
+ index7("menus_type_idx").on(table.type)
917
+ ]
918
+ );
919
+ var SYS_INBOX_CODE = "SYS_INBOX";
920
+ var menuSchema = createInsertSchema8(menus);
921
+ var getMenuQuery = z4.object({
922
+ code: z4.string()
923
+ });
924
+ var listMenusQuery = z4.object({
925
+ target: z4.enum(["admin", "web"])
926
+ });
927
+ var listAllMenusQuery = z4.object({
928
+ target: z4.enum(["admin", "web"]).optional()
929
+ }).merge(paginationSchema.partial());
930
+ var deleteMenuMutation = z4.object({
931
+ code: z4.string()
932
+ });
933
+ var toggleMenuVisibilityMutation = z4.object({
934
+ code: z4.string(),
935
+ visible: z4.boolean()
936
+ });
937
+ var createMenuSchema = menuSchema.pick({
938
+ code: true,
939
+ label: true,
940
+ path: true,
941
+ icon: true,
942
+ openMode: true,
943
+ parentCode: true,
944
+ order: true,
945
+ target: true,
946
+ metadata: true
947
+ }).extend({
948
+ openMode: z4.enum(["route", "external"]).optional(),
949
+ target: z4.enum(["admin", "web"])
950
+ });
951
+ var updateMenuSchema = menuSchema.pick({
952
+ label: true,
953
+ icon: true,
954
+ path: true,
955
+ openMode: true,
956
+ parentCode: true,
957
+ order: true,
958
+ visible: true,
959
+ metadata: true
960
+ }).partial().extend({
961
+ openMode: z4.enum(["route", "external"]).optional()
962
+ });
963
+ var updateMenuMutation = menuSchema.omit({
964
+ id: true,
965
+ createdAt: true,
966
+ updatedAt: true
967
+ }).partial().extend({
968
+ code: z4.string()
969
+ // Required for identification
970
+ });
971
+
972
+ // src/schema/plugins.ts
973
+ import {
974
+ index as index8,
975
+ pgTable as pgTable9,
976
+ text as text9,
977
+ timestamp as timestamp9,
978
+ jsonb as jsonb5,
979
+ uniqueIndex as uniqueIndex8,
980
+ varchar as varchar2
981
+ } from "drizzle-orm/pg-core";
982
+ import { sql } from "drizzle-orm";
983
+ import { createInsertSchema as createInsertSchema9 } from "drizzle-orm/zod";
984
+ import { z as z5 } from "zod";
985
+ var PLUGIN_MARKETPLACE_STATES = [
986
+ "draft",
987
+ "published",
988
+ "archived",
989
+ "suspended",
990
+ "removed"
991
+ ];
992
+ var PLUGIN_TRUST_LEVELS = ["first_party", "third_party"];
993
+ var PLUGIN_INSTALL_OPERATIONS = ["install", "update", "uninstall", "rollback"];
994
+ var PLUGIN_INSTALL_SOURCES = ["registry", "upload", "system"];
995
+ var PLUGIN_INSTALL_JOB_STATUSES = [
996
+ "queued",
997
+ "validating",
998
+ "staging",
999
+ "awaiting_reload",
1000
+ "succeeded",
1001
+ "failed",
1002
+ "rolled_back"
1003
+ ];
1004
+ var plugins = pgTable9(
1005
+ "plugins",
1006
+ {
1007
+ id: text9("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
1008
+ pluginId: text9("plugin_id").notNull(),
1009
+ // FK to organization table
1010
+ organizationId: text9("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
1011
+ version: text9("version").notNull(),
1012
+ installationStatus: text9("installation_status").notNull().$type().default("installed"),
1013
+ activationStatus: text9("activation_status").notNull().$type().default("enabled"),
1014
+ status: text9("status").notNull().$type(),
1015
+ manifest: jsonb5("manifest").notNull().$type(),
1016
+ installedAt: timestamp9("installed_at").notNull().defaultNow(),
1017
+ updatedAt: timestamp9("updated_at").notNull().defaultNow(),
1018
+ scheduledDeletionAt: timestamp9("scheduled_deletion_at")
1019
+ },
1020
+ (table) => [
1021
+ uniqueIndex8("unique_plugin_per_org").on(table.organizationId, table.pluginId),
1022
+ index8("plugins_plugin_installation_idx").on(
1023
+ table.pluginId,
1024
+ table.installationStatus,
1025
+ table.organizationId
1026
+ )
1027
+ ]
1028
+ );
1029
+ var pluginInstances = pgTable9(
1030
+ "plugin_instances",
1031
+ {
1032
+ id: text9("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
1033
+ pluginId: text9("plugin_id").notNull(),
1034
+ version: text9("version").notNull(),
1035
+ status: text9("status").notNull().$type(),
1036
+ manifest: jsonb5("manifest").notNull().$type(),
1037
+ installedAt: timestamp9("installed_at").notNull().defaultNow(),
1038
+ updatedAt: timestamp9("updated_at").notNull().defaultNow()
1039
+ },
1040
+ (table) => [
1041
+ uniqueIndex8("unique_plugin_per_instance").on(table.pluginId)
1042
+ ]
1043
+ );
1044
+ var pluginCatalogReleases = pgTable9(
1045
+ "plugin_catalog_releases",
1046
+ {
1047
+ id: text9("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
1048
+ sourceId: text9("source_id").notNull(),
1049
+ pluginId: varchar2("plugin_id", { length: 160 }).notNull(),
1050
+ version: varchar2("version", { length: 80 }).notNull(),
1051
+ state: varchar2("state", { length: 20, enum: PLUGIN_MARKETPLACE_STATES }).notNull().$type(),
1052
+ trustLevel: varchar2("trust_level", { length: 20, enum: PLUGIN_TRUST_LEVELS }).notNull().$type(),
1053
+ manifest: jsonb5("manifest").notNull().$type(),
1054
+ release: jsonb5("release").notNull().$type(),
1055
+ artifactUrl: text9("artifact_url").notNull(),
1056
+ artifactSha256: varchar2("artifact_sha256", { length: 64 }).notNull(),
1057
+ publisherId: varchar2("publisher_id", { length: 160 }),
1058
+ releaseSha256: varchar2("release_sha256", { length: 64 }),
1059
+ publisherSignature: jsonb5("publisher_signature").$type(),
1060
+ registrySignature: jsonb5("registry_signature").$type(),
1061
+ /** @deprecated Legacy alias for publisherSignature. */
1062
+ signature: jsonb5("signature").$type(),
1063
+ publishedAt: timestamp9("published_at").notNull(),
1064
+ fetchedAt: timestamp9("fetched_at").notNull().defaultNow()
1065
+ },
1066
+ (table) => [
1067
+ uniqueIndex8("plugin_catalog_release_unique").on(table.sourceId, table.pluginId, table.version),
1068
+ index8("plugin_catalog_release_lookup_idx").on(table.pluginId, table.state, table.publishedAt)
1069
+ ]
1070
+ );
1071
+ var pluginRegistrySyncState = pgTable9("plugin_registry_sync_state", {
1072
+ sourceId: text9("source_id").primaryKey(),
1073
+ snapshotId: varchar2("snapshot_id", { length: 160 }).notNull(),
1074
+ generatedAt: timestamp9("generated_at").notNull(),
1075
+ fetchedAt: timestamp9("fetched_at").notNull().defaultNow()
1076
+ });
1077
+ var pluginInstallJobs = pgTable9(
1078
+ "plugin_install_jobs",
1079
+ {
1080
+ id: text9("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
1081
+ pluginId: varchar2("plugin_id", { length: 160 }).notNull(),
1082
+ operation: varchar2("operation", { length: 20, enum: PLUGIN_INSTALL_OPERATIONS }).notNull().$type(),
1083
+ source: varchar2("source", { length: 20, enum: PLUGIN_INSTALL_SOURCES }).notNull().$type(),
1084
+ sourceId: text9("source_id"),
1085
+ releaseId: text9("release_id").references(() => pluginCatalogReleases.id, { onDelete: "set null" }),
1086
+ previousVersion: varchar2("previous_version", { length: 80 }),
1087
+ targetVersion: varchar2("target_version", { length: 80 }),
1088
+ status: varchar2("status", { length: 24, enum: PLUGIN_INSTALL_JOB_STATUSES }).notNull().$type().default("queued"),
1089
+ artifactSha256: varchar2("artifact_sha256", { length: 64 }),
1090
+ requestedBy: text9("requested_by").notNull(),
1091
+ errorCode: varchar2("error_code", { length: 80 }),
1092
+ errorMessage: text9("error_message"),
1093
+ metadata: jsonb5("metadata").notNull().$type().default({}),
1094
+ createdAt: timestamp9("created_at").notNull().defaultNow(),
1095
+ updatedAt: timestamp9("updated_at").notNull().defaultNow(),
1096
+ completedAt: timestamp9("completed_at")
1097
+ },
1098
+ (table) => [
1099
+ uniqueIndex8("plugin_install_jobs_active_plugin_uidx").on(table.pluginId).where(sql`${table.status} IN ('queued', 'validating', 'staging', 'awaiting_reload')`),
1100
+ index8("plugin_install_jobs_plugin_idx").on(table.pluginId, table.createdAt),
1101
+ index8("plugin_install_jobs_status_idx").on(table.status, table.createdAt)
1102
+ ]
1103
+ );
1104
+ var pluginConfigs = pgTable9(
1105
+ "plugin_configs",
1106
+ {
1107
+ id: text9("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
1108
+ pluginId: text9("plugin_id").notNull(),
1109
+ // FK to organization table
1110
+ organizationId: text9("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
1111
+ key: text9("key").notNull(),
1112
+ value: jsonb5("value").notNull(),
1113
+ updatedAt: timestamp9("updated_at").notNull().defaultNow()
1114
+ },
1115
+ (table) => [
1116
+ uniqueIndex8("unique_config_key").on(
1117
+ table.organizationId,
1118
+ table.pluginId,
1119
+ table.key
1120
+ )
1121
+ ]
1122
+ );
1123
+ var pluginSchema = createInsertSchema9(plugins);
1124
+ var pluginInstanceSchema = createInsertSchema9(pluginInstances);
1125
+ var pluginCatalogReleaseSchema = createInsertSchema9(pluginCatalogReleases, {
1126
+ artifactUrl: () => z5.url(),
1127
+ artifactSha256: () => z5.string().regex(/^[a-f0-9]{64}$/)
1128
+ });
1129
+ var pluginInstallJobSchema = createInsertSchema9(pluginInstallJobs);
1130
+ var pluginConfigSchema = createInsertSchema9(pluginConfigs);
1131
+ var listPluginCatalogQuery = z5.object({
1132
+ query: z5.string().trim().min(1).max(120).optional(),
1133
+ limit: z5.number().int().min(1).max(100).default(20),
1134
+ offset: z5.number().int().nonnegative().default(0)
1135
+ });
1136
+ var installPluginFromRegistryMutation = z5.object({
1137
+ pluginId: z5.string().regex(/^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)+$/),
1138
+ version: z5.string().min(1).max(80)
1139
+ });
1140
+ var createPluginUploadMutation = z5.object({
1141
+ pluginId: z5.string().regex(/^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)+$/),
1142
+ version: z5.string().min(1).max(80),
1143
+ totalSize: z5.number().int().positive().max(100 * 1024 * 1024),
1144
+ sha256: z5.string().regex(/^[a-f0-9]{64}$/)
1145
+ });
1146
+ var appendPluginUploadMutation = z5.object({
1147
+ uploadId: z5.string().uuid(),
1148
+ offset: z5.number().int().nonnegative(),
1149
+ chunkBase64: z5.base64().min(1).max(1024 * 1024)
1150
+ });
1151
+ var completePluginUploadMutation = z5.object({
1152
+ uploadId: z5.string().uuid()
1153
+ });
1154
+ var getPluginInstallJobQuery = pluginInstallJobSchema.pick({ id: true }).required();
1155
+ var uninstallPluginFromInstanceMutation = z5.object({
1156
+ pluginId: z5.string().regex(/^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)+$/),
1157
+ retentionChoice: z5.enum(["retain", "archive", "delete"]).optional(),
1158
+ confirmed: z5.boolean().optional()
1159
+ });
1160
+ var rollbackPluginInstallMutation = getPluginInstallJobQuery;
1161
+
1162
+ // src/schema/plugin-migrations.ts
1163
+ import { pgTable as pgTable10, text as text10, timestamp as timestamp10, uniqueIndex as uniqueIndex9 } from "drizzle-orm/pg-core";
1164
+ import { createInsertSchema as createInsertSchema10 } from "drizzle-orm/zod";
1165
+ var pluginMigrations = pgTable10(
1166
+ "plugin_migrations",
1167
+ {
1168
+ id: text10("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
1169
+ pluginId: text10("plugin_id").notNull(),
1170
+ // FK to organization table
1171
+ organizationId: text10("organization_id").notNull(),
1172
+ migrationFile: text10("migration_file").notNull(),
1173
+ appliedAt: timestamp10("applied_at").notNull().defaultNow(),
1174
+ checksum: text10("checksum").notNull()
1175
+ // SHA256 of file content
1176
+ },
1177
+ (table) => [
1178
+ uniqueIndex9("unique_plugin_migration").on(
1179
+ table.organizationId,
1180
+ table.pluginId,
1181
+ table.migrationFile
1182
+ )
1183
+ ]
1184
+ );
1185
+ var pluginMigrationSchema = createInsertSchema10(pluginMigrations);
1186
+
1187
+ // src/schema/entity-extensions.ts
1188
+ import {
1189
+ boolean as boolean7,
1190
+ index as index9,
1191
+ jsonb as jsonb6,
1192
+ numeric,
1193
+ pgTable as pgTable11,
1194
+ text as text11,
1195
+ timestamp as timestamp11,
1196
+ uniqueIndex as uniqueIndex10,
1197
+ varchar as varchar3
1198
+ } from "drizzle-orm/pg-core";
1199
+ var ENTITY_EXTENSION_VALUE_TYPES = [
1200
+ "text",
1201
+ "number",
1202
+ "boolean",
1203
+ "date",
1204
+ "datetime",
1205
+ "select",
1206
+ "ref",
1207
+ "json"
1208
+ ];
1209
+ var ENTITY_EXTENSION_PROJECTION_STATUSES = [
1210
+ "active",
1211
+ "stale",
1212
+ "deleted"
1213
+ ];
1214
+ var extProjection = pgTable11(
1215
+ "ext_projection",
1216
+ {
1217
+ id: text11("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
1218
+ organizationId: text11("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
1219
+ pluginId: text11("plugin_id").notNull(),
1220
+ entity: varchar3("entity", { length: 160 }).notNull(),
1221
+ entityId: text11("entity_id").notNull(),
1222
+ field: varchar3("field", { length: 80 }).notNull(),
1223
+ type: varchar3("type", { length: 30 }).notNull().$type(),
1224
+ valueText: text11("value_text"),
1225
+ valueNumber: numeric("value_number"),
1226
+ valueBoolean: boolean7("value_boolean"),
1227
+ valueDate: timestamp11("value_date", { withTimezone: true }),
1228
+ valueJson: jsonb6("value_json").$type(),
1229
+ refEntity: varchar3("ref_entity", { length: 160 }),
1230
+ refId: text11("ref_id"),
1231
+ display: text11("display"),
1232
+ search: text11("search"),
1233
+ status: varchar3("status", { length: 20 }).notNull().$type().default("active"),
1234
+ syncedAt: timestamp11("synced_at", { withTimezone: true }).notNull().defaultNow(),
1235
+ createdAt: timestamp11("created_at", { withTimezone: true }).notNull().defaultNow(),
1236
+ updatedAt: timestamp11("updated_at", { withTimezone: true }).notNull().defaultNow()
1237
+ },
1238
+ (table) => [
1239
+ uniqueIndex10("ext_projection_unique_field").on(
1240
+ table.organizationId,
1241
+ table.pluginId,
1242
+ table.entity,
1243
+ table.entityId,
1244
+ table.field
1245
+ ),
1246
+ index9("ext_projection_entity_idx").on(
1247
+ table.organizationId,
1248
+ table.entity,
1249
+ table.entityId
1250
+ ),
1251
+ index9("ext_projection_field_idx").on(
1252
+ table.organizationId,
1253
+ table.entity,
1254
+ table.field,
1255
+ table.status
1256
+ ),
1257
+ index9("ext_projection_ref_idx").on(
1258
+ table.organizationId,
1259
+ table.refEntity,
1260
+ table.refId
1261
+ )
1262
+ ]
1263
+ );
1264
+
1265
+ // src/schema/action-journal.ts
1266
+ import { index as index10, integer as integer5, pgTable as pgTable12, text as text12, timestamp as timestamp12, uniqueIndex as uniqueIndex11, varchar as varchar4 } from "drizzle-orm/pg-core";
1267
+ import { sql as sql2 } from "drizzle-orm";
1268
+ var ACTION_JOURNAL_STATUSES = [
1269
+ "prepared",
1270
+ "approval_pending",
1271
+ "authorized",
1272
+ "dispatched",
1273
+ "succeeded",
1274
+ "failed",
1275
+ "unknown",
1276
+ "reconciled",
1277
+ "denied",
1278
+ "expired"
1279
+ ];
1280
+ var ACTION_JOURNAL_ACTIVE_STATUSES = [
1281
+ "prepared",
1282
+ "approval_pending",
1283
+ "authorized",
1284
+ "dispatched"
1285
+ ];
1286
+ var actionExecutionJournal = pgTable12(
1287
+ "action_execution_journal",
1288
+ {
1289
+ id: text12("id").primaryKey().default(sql2`gen_random_uuid()`),
1290
+ organizationId: text12("organization_id").notNull(),
1291
+ /** Authorizing subject. The only permission source (plan §4.3 B2). */
1292
+ principalUserId: text12("principal_user_id").notNull(),
1293
+ /** Who initiated, e.g. `agent:<pluginId>`. Audit chain only, never authorization. */
1294
+ invoker: text12("invoker").notNull(),
1295
+ /** Stable Action Contract id, decoupled from the procedure path. */
1296
+ actionId: text12("action_id").notNull(),
1297
+ revision: integer5("revision").notNull(),
1298
+ /** Canonicalized argument hash; binds the approval token to these arguments. */
1299
+ argsHash: text12("args_hash").notNull(),
1300
+ /** Approval token nonce, or an `auto-` prefixed value for ungated executions. */
1301
+ nonce: text12("nonce").notNull(),
1302
+ status: varchar4("status", { length: 24, enum: ACTION_JOURNAL_STATUSES }).notNull().$type().default("prepared"),
1303
+ attempt: integer5("attempt").notNull().default(0),
1304
+ /** Target-system identifier used to reconcile `unknown` executions. */
1305
+ externalRef: text12("external_ref"),
1306
+ errorCode: text12("error_code"),
1307
+ /** Resolved verdict recorded by reconciliation. */
1308
+ outcome: text12("outcome"),
1309
+ createdAt: timestamp12("created_at", { withTimezone: true }).notNull().defaultNow(),
1310
+ updatedAt: timestamp12("updated_at", { withTimezone: true }).notNull().defaultNow(),
1311
+ dispatchedAt: timestamp12("dispatched_at", { withTimezone: true }),
1312
+ terminalAt: timestamp12("terminal_at", { withTimezone: true })
1313
+ },
1314
+ (table) => [
1315
+ uniqueIndex11("action_execution_journal_nonce_uidx").on(table.nonce),
1316
+ uniqueIndex11("action_execution_journal_active_uidx").on(table.organizationId, table.actionId, table.argsHash).where(sql2`${table.status} IN ('prepared','approval_pending','authorized','dispatched')`),
1317
+ index10("action_execution_journal_status_idx").on(table.status, table.updatedAt),
1318
+ index10("action_execution_journal_org_idx").on(table.organizationId, table.createdAt)
1319
+ ]
1320
+ );
1321
+ var actionExecutionOutbox = pgTable12(
1322
+ "action_execution_outbox",
1323
+ {
1324
+ id: text12("id").primaryKey().default(sql2`gen_random_uuid()`),
1325
+ journalId: text12("journal_id").notNull().references(() => actionExecutionJournal.id, { onDelete: "cascade" }),
1326
+ kind: text12("kind").notNull(),
1327
+ availableAt: timestamp12("available_at", { withTimezone: true }).notNull().defaultNow(),
1328
+ attempts: integer5("attempts").notNull().default(0),
1329
+ lockedAt: timestamp12("locked_at", { withTimezone: true }),
1330
+ lockToken: text12("lock_token")
1331
+ },
1332
+ (table) => [index10("action_execution_outbox_available_idx").on(table.availableAt)]
1333
+ );
1334
+
1335
+ // src/schema/settings.ts
1336
+ import {
1337
+ pgTable as pgTable13,
1338
+ text as text13,
1339
+ timestamp as timestamp13,
1340
+ jsonb as jsonb7,
1341
+ index as index11,
1342
+ boolean as boolean8,
1343
+ integer as integer6,
1344
+ uniqueIndex as uniqueIndex12
1345
+ } from "drizzle-orm/pg-core";
1346
+ import { sql as sql3 } from "drizzle-orm";
1347
+ import { createInsertSchema as createInsertSchema11 } from "drizzle-orm/zod";
1348
+ import { z as z6 } from "zod/v4";
1349
+ var settings = pgTable13(
1350
+ "settings",
1351
+ {
1352
+ id: text13("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
1353
+ // Scope identification
1354
+ scope: text13("scope").notNull().$type(),
1355
+ scopeId: text13("scope_id"),
1356
+ // pluginId (only for plugin_* scopes)
1357
+ // FK to organization table (nullable - only for tenant and plugin_tenant scopes)
1358
+ organizationId: text13("organization_id").references(() => organization.id, { onDelete: "cascade" }),
1359
+ // Setting data
1360
+ key: text13("key").notNull(),
1361
+ // Setting key (e.g., "email.smtp.host")
1362
+ value: jsonb7("value"),
1363
+ // Setting value (or EncryptedValue if encrypted)
1364
+ valueType: text13("value_type").$type().default("string"),
1365
+ // Encryption
1366
+ encrypted: boolean8("encrypted").notNull().default(false),
1367
+ // Schema version for migration support
1368
+ schemaVersion: integer6("schema_version").notNull().default(1),
1369
+ // Metadata
1370
+ description: text13("description"),
1371
+ // Audit fields
1372
+ createdBy: text13("created_by"),
1373
+ updatedBy: text13("updated_by"),
1374
+ createdAt: timestamp13("created_at").notNull().defaultNow(),
1375
+ updatedAt: timestamp13("updated_at").notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
1376
+ },
1377
+ (table) => [
1378
+ // Unique constraint with COALESCE to handle NULL values
1379
+ uniqueIndex12("idx_settings_unique").on(
1380
+ table.scope,
1381
+ sql3`COALESCE(${table.scopeId}, '')`,
1382
+ sql3`COALESCE(${table.organizationId}, '')`,
1383
+ table.key
1384
+ ),
1385
+ // Index for scope + key queries
1386
+ index11("idx_settings_scope_key").on(table.scope, table.key),
1387
+ // Index for tenant queries (partial)
1388
+ index11("idx_settings_tenant").on(table.organizationId),
1389
+ // Index for plugin queries (partial)
1390
+ index11("idx_settings_plugin").on(table.scopeId)
1391
+ ]
1392
+ );
1393
+ var settingSchemas = pgTable13(
1394
+ "setting_schemas",
1395
+ {
1396
+ id: text13("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
1397
+ // Pattern matching (supports wildcards, e.g., "email.*" or "plugin:*:api_key")
1398
+ keyPattern: text13("key_pattern").notNull(),
1399
+ // JSON Schema definition
1400
+ schema: jsonb7("schema").notNull().$type(),
1401
+ // Version for schema evolution
1402
+ version: integer6("version").notNull().default(1),
1403
+ // Default value if setting doesn't exist
1404
+ defaultValue: jsonb7("default_value"),
1405
+ // Metadata
1406
+ description: text13("description"),
1407
+ deprecated: boolean8("deprecated").notNull().default(false),
1408
+ createdAt: timestamp13("created_at").notNull().defaultNow()
1409
+ },
1410
+ (table) => [
1411
+ // Unique constraint on pattern + version
1412
+ uniqueIndex12("idx_setting_schemas_pattern_version").on(
1413
+ table.keyPattern,
1414
+ table.version
1415
+ )
1416
+ ]
1417
+ );
1418
+ var settingScopeSchema = z6.enum(["global", "tenant", "plugin_global", "plugin_tenant"]);
1419
+ var settingValueTypeSchema = z6.enum(["string", "number", "boolean", "json"]);
1420
+ var settingSchema = createInsertSchema11(settings);
1421
+ var settingSchemaSchema = createInsertSchema11(settingSchemas);
1422
+ var getSettingQuery = settingSchema.pick({
1423
+ scope: true,
1424
+ key: true,
1425
+ organizationId: true,
1426
+ scopeId: true
1427
+ }).extend({
1428
+ defaultValue: z6.unknown().optional()
1429
+ });
1430
+ var listSettingsQuery = settingSchema.pick({
1431
+ scope: true,
1432
+ organizationId: true,
1433
+ scopeId: true
1434
+ }).merge(paginationSchema).extend({
1435
+ keyPrefix: z6.string().optional()
1436
+ });
1437
+ var setSettingMutation = settingSchema.pick({
1438
+ scope: true,
1439
+ key: true,
1440
+ value: true,
1441
+ organizationId: true,
1442
+ scopeId: true,
1443
+ encrypted: true,
1444
+ description: true,
1445
+ valueType: true
1446
+ });
1447
+ var deleteSettingMutation = settingSchema.pick({
1448
+ scope: true,
1449
+ key: true,
1450
+ organizationId: true,
1451
+ scopeId: true
1452
+ });
1453
+
1454
+ // src/schema/feature-flags.ts
1455
+ import {
1456
+ pgTable as pgTable14,
1457
+ text as text14,
1458
+ timestamp as timestamp14,
1459
+ jsonb as jsonb8,
1460
+ index as index12,
1461
+ boolean as boolean9,
1462
+ integer as integer7,
1463
+ uniqueIndex as uniqueIndex13
1464
+ } from "drizzle-orm/pg-core";
1465
+ import { createInsertSchema as createInsertSchema12 } from "drizzle-orm/zod";
1466
+ import { z as z7 } from "zod/v4";
1467
+ var featureFlags = pgTable14(
1468
+ "feature_flags",
1469
+ {
1470
+ id: text14("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
1471
+ // Identification
1472
+ key: text14("key").notNull().unique(),
1473
+ // Unique flag key (e.g., "dark_mode", "ai_features")
1474
+ name: text14("name").notNull(),
1475
+ // Display name
1476
+ // Configuration
1477
+ description: text14("description"),
1478
+ enabled: boolean9("enabled").notNull().default(false),
1479
+ // Rollout configuration
1480
+ rolloutPercentage: integer7("rollout_percentage").notNull().default(100),
1481
+ // 0-100
1482
+ // Condition rules (evaluated in order, all must pass)
1483
+ conditions: jsonb8("conditions").notNull().default([]).$type(),
1484
+ // Audit fields
1485
+ createdBy: text14("created_by"),
1486
+ createdAt: timestamp14("created_at").notNull().defaultNow(),
1487
+ updatedAt: timestamp14("updated_at").notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
1488
+ },
1489
+ (table) => [index12("idx_feature_flags_key").on(table.key)]
1490
+ );
1491
+ var featureFlagOverrides = pgTable14(
1492
+ "feature_flag_overrides",
1493
+ {
1494
+ id: text14("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
1495
+ // References
1496
+ flagId: text14("flag_id").notNull().references(() => featureFlags.id, { onDelete: "cascade" }),
1497
+ // FK to organization table
1498
+ organizationId: text14("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
1499
+ // Override configuration
1500
+ enabled: boolean9("enabled").notNull(),
1501
+ rolloutPercentage: integer7("rollout_percentage"),
1502
+ // NULL means use global value
1503
+ conditions: jsonb8("conditions").$type(),
1504
+ // NULL means use global conditions
1505
+ // Audit fields
1506
+ createdBy: text14("created_by"),
1507
+ createdAt: timestamp14("created_at").notNull().defaultNow()
1508
+ },
1509
+ (table) => [
1510
+ // Unique constraint: one override per flag per tenant
1511
+ uniqueIndex13("idx_ff_overrides_flag_tenant").on(table.flagId, table.organizationId),
1512
+ // Index for tenant lookups
1513
+ index12("idx_ff_overrides_tenant").on(table.organizationId)
1514
+ ]
1515
+ );
1516
+ var flagConditionSchema = z7.object({
1517
+ type: z7.enum(["user_role", "tenant_plan", "user_id", "percentage"]),
1518
+ operator: z7.enum(["eq", "neq", "in", "nin", "gt", "lt", "gte", "lte"]),
1519
+ value: z7.unknown()
1520
+ });
1521
+ var featureFlagSchema = createInsertSchema12(featureFlags);
1522
+ var featureFlagOverrideSchema = createInsertSchema12(featureFlagOverrides);
1523
+ var organizationInputSchema = z7.object({
1524
+ organizationId: z7.string().min(1).optional(),
1525
+ tenantId: z7.string().min(1).optional()
1526
+ }).refine((data) => !!(data.organizationId ?? data.tenantId), {
1527
+ message: "organizationId is required",
1528
+ path: ["organizationId"]
1529
+ }).transform((data) => ({
1530
+ organizationId: data.organizationId ?? data.tenantId
1531
+ }));
1532
+ var checkFeatureFlagQuery = z7.object({
1533
+ key: z7.string(),
1534
+ organizationId: z7.string().optional(),
1535
+ tenantId: z7.string().optional(),
1536
+ userId: z7.string().optional(),
1537
+ userRole: z7.string().optional(),
1538
+ tenantPlan: z7.string().optional()
1539
+ }).transform((data) => ({
1540
+ ...data,
1541
+ organizationId: data.organizationId ?? data.tenantId
1542
+ }));
1543
+ var getFeatureFlagQuery = z7.object({
1544
+ key: z7.string().min(1)
1545
+ });
1546
+ var listFeatureFlagsQuery = paginationSchema.partial();
1547
+ var listFlagOverridesQuery = z7.object({
1548
+ organizationId: z7.string().min(1).optional(),
1549
+ tenantId: z7.string().min(1).optional()
1550
+ }).refine((data) => !!(data.organizationId ?? data.tenantId), {
1551
+ message: "organizationId is required",
1552
+ path: ["organizationId"]
1553
+ }).transform((data) => ({
1554
+ organizationId: data.organizationId ?? data.tenantId
1555
+ }));
1556
+ var updateFeatureFlagMutation = featureFlagSchema.omit({
1557
+ id: true,
1558
+ createdAt: true,
1559
+ updatedAt: true
1560
+ }).partial().extend({
1561
+ id: z7.string()
1562
+ // Required for identification
1563
+ });
1564
+ var deleteFeatureFlagMutation = z7.object({
1565
+ id: z7.string().uuid()
1566
+ });
1567
+ var setFlagOverrideMutation = z7.object({
1568
+ flagKey: z7.string(),
1569
+ organizationId: z7.string().optional(),
1570
+ tenantId: z7.string().optional(),
1571
+ enabled: z7.boolean(),
1572
+ rolloutPercentage: z7.number().min(0).max(100).optional(),
1573
+ conditions: z7.array(flagConditionSchema).optional()
1574
+ }).and(organizationInputSchema).transform((data) => ({
1575
+ flagKey: data.flagKey,
1576
+ organizationId: data.organizationId,
1577
+ enabled: data.enabled,
1578
+ rolloutPercentage: data.rolloutPercentage,
1579
+ conditions: data.conditions
1580
+ }));
1581
+ var removeFlagOverrideMutation = z7.object({
1582
+ flagKey: z7.string(),
1583
+ organizationId: z7.string().optional(),
1584
+ tenantId: z7.string().optional()
1585
+ }).and(organizationInputSchema).transform((data) => ({
1586
+ flagKey: data.flagKey,
1587
+ organizationId: data.organizationId
1588
+ }));
1589
+
1590
+ // src/schema/media.ts
1591
+ import {
1592
+ pgTable as pgTable15,
1593
+ text as text15,
1594
+ timestamp as timestamp15,
1595
+ boolean as boolean10,
1596
+ bigint,
1597
+ integer as integer8,
1598
+ jsonb as jsonb9,
1599
+ index as index13,
1600
+ uniqueIndex as uniqueIndex14,
1601
+ check
1602
+ } from "drizzle-orm/pg-core";
1603
+ import { sql as sql4 } from "drizzle-orm";
1604
+ import { createInsertSchema as createInsertSchema13, createSelectSchema } from "drizzle-orm/zod";
1605
+ import { z as z8 } from "zod";
1606
+ var media = pgTable15(
1607
+ "media",
1608
+ {
1609
+ id: text15("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
1610
+ organizationId: text15("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
1611
+ // Self-reference: variants point to their original media
1612
+ parentId: text15("parent_id").references(() => media.id, { onDelete: "cascade" }),
1613
+ variantName: text15("variant_name"),
1614
+ // File information
1615
+ filename: text15("filename").notNull(),
1616
+ mimeType: text15("mime_type").notNull(),
1617
+ size: bigint("size", { mode: "number" }).notNull().default(0),
1618
+ // Storage information
1619
+ storageProvider: text15("storage_provider").notNull().$type(),
1620
+ storageKey: text15("storage_key").notNull(),
1621
+ storageBucket: text15("storage_bucket"),
1622
+ // Public access
1623
+ publicUrl: text15("public_url"),
1624
+ isPublic: boolean10("is_public").notNull().default(false),
1625
+ // Integrity
1626
+ checksum: text15("checksum"),
1627
+ // Image-specific (null for non-image media)
1628
+ width: integer8("width"),
1629
+ height: integer8("height"),
1630
+ format: text15("format"),
1631
+ // CMS semantics
1632
+ alt: text15("alt"),
1633
+ title: text15("title"),
1634
+ tags: text15("tags").array().default([]),
1635
+ folderPath: text15("folder_path"),
1636
+ // Extensible metadata
1637
+ metadata: jsonb9("metadata").$type().default({}),
1638
+ // Audit
1639
+ createdBy: text15("created_by").notNull(),
1640
+ createdAt: timestamp15("created_at").notNull().defaultNow(),
1641
+ updatedAt: timestamp15("updated_at").notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date()),
1642
+ deletedAt: timestamp15("deleted_at")
1643
+ },
1644
+ (table) => [
1645
+ // Storage key uniqueness per tenant
1646
+ uniqueIndex14("media_storage_unique").on(
1647
+ table.organizationId,
1648
+ table.storageProvider,
1649
+ table.storageKey
1650
+ ),
1651
+ // Variant name uniqueness per parent
1652
+ uniqueIndex14("media_parent_variant_unique").on(table.parentId, table.variantName).where(sql4`${table.parentId} IS NOT NULL`),
1653
+ // Prevent self-referencing
1654
+ check("media_no_self_ref", sql4`${table.parentId} IS DISTINCT FROM ${table.id}`),
1655
+ // Query indexes
1656
+ index13("idx_media_org_folder").on(table.organizationId, table.folderPath).where(sql4`${table.deletedAt} IS NULL`),
1657
+ index13("idx_media_org_mime").on(table.organizationId, table.mimeType).where(sql4`${table.deletedAt} IS NULL`),
1658
+ index13("idx_media_parent").on(table.parentId).where(sql4`${table.parentId} IS NOT NULL`),
1659
+ index13("idx_media_tags").using("gin", table.tags).where(sql4`${table.deletedAt} IS NULL`),
1660
+ index13("idx_media_org_created").on(table.organizationId, table.createdAt).where(sql4`${table.deletedAt} IS NULL`),
1661
+ index13("idx_media_deleted").on(table.deletedAt).where(sql4`${table.deletedAt} IS NOT NULL`)
1662
+ ]
1663
+ );
1664
+ var mediaInsertSchema = createInsertSchema13(media);
1665
+ var mediaSelectSchema = createSelectSchema(media);
1666
+ var importMediaFromUrlMutation = z8.object({
1667
+ url: z8.string().trim().url().max(2048),
1668
+ providerId: z8.string().trim().min(1).max(100).optional()
1669
+ });
1670
+
1671
+ // src/schema/web-design.ts
1672
+ import {
1673
+ boolean as boolean11,
1674
+ index as index14,
1675
+ jsonb as jsonb10,
1676
+ pgTable as pgTable16,
1677
+ text as text16,
1678
+ timestamp as timestamp16,
1679
+ uniqueIndex as uniqueIndex15,
1680
+ varchar as varchar5
1681
+ } from "drizzle-orm/pg-core";
1682
+ import { createInsertSchema as createInsertSchema14, createSelectSchema as createSelectSchema2 } from "drizzle-orm/zod";
1683
+ import { z as z9 } from "zod";
1684
+ var WEB_PAGE_STATUSES = ["draft", "published", "archived"];
1685
+ var WEB_DOMAIN_STATUSES = ["pending", "verified", "active", "disabled"];
1686
+ var WEB_DOMAIN_CERTIFICATE_STATUSES = [
1687
+ "not_requested",
1688
+ "requested",
1689
+ "provisioning",
1690
+ "active",
1691
+ "failed"
1692
+ ];
1693
+ var WEB_PAGE_RESERVED_PATHS = [
1694
+ "/favicon.ico",
1695
+ "/robots.txt",
1696
+ "/sitemap.xml",
1697
+ "/manifest.json"
1698
+ ];
1699
+ var WEB_PAGE_RESERVED_PREFIXES = [
1700
+ "/_next",
1701
+ "/api",
1702
+ "/assets",
1703
+ "/plugins",
1704
+ "/static",
1705
+ "/trpc"
1706
+ ];
1707
+ function normalizeWebPagePath(value) {
1708
+ const normalized = value.trim().replace(/^\/?/, "/").replace(/\/+/g, "/").replace(/\/$/, "").toLowerCase();
1709
+ return normalized || "/";
1710
+ }
1711
+ var webPages = pgTable16(
1712
+ "web_pages",
1713
+ {
1714
+ id: text16("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
1715
+ organizationId: text16("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
1716
+ title: text16("title").notNull(),
1717
+ path: text16("path").notNull(),
1718
+ status: varchar5("status", { length: 24, enum: WEB_PAGE_STATUSES }).notNull().default("draft"),
1719
+ routeId: text16("route_id"),
1720
+ templateId: text16("template_id"),
1721
+ seoTitle: text16("seo_title"),
1722
+ seoDescription: text16("seo_description"),
1723
+ document: jsonb10("document").notNull().default({}).$type(),
1724
+ publishedDocument: jsonb10("published_document").$type(),
1725
+ publishedAt: timestamp16("published_at"),
1726
+ createdBy: text16("created_by"),
1727
+ updatedBy: text16("updated_by"),
1728
+ createdAt: timestamp16("created_at").notNull().defaultNow(),
1729
+ updatedAt: timestamp16("updated_at").notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
1730
+ },
1731
+ (table) => [
1732
+ uniqueIndex15("web_pages_org_path_uidx").on(table.organizationId, table.path),
1733
+ index14("web_pages_org_status_idx").on(table.organizationId, table.status),
1734
+ index14("web_pages_route_idx").on(table.routeId)
1735
+ ]
1736
+ );
1737
+ var webDomains = pgTable16(
1738
+ "web_domains",
1739
+ {
1740
+ id: text16("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
1741
+ organizationId: text16("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
1742
+ hostname: text16("hostname").notNull(),
1743
+ status: varchar5("status", { length: 24, enum: WEB_DOMAIN_STATUSES }).notNull().default("pending"),
1744
+ isPrimary: boolean11("is_primary").notNull().default(false),
1745
+ verificationToken: text16("verification_token"),
1746
+ certificateStatus: varchar5("certificate_status", { length: 24, enum: WEB_DOMAIN_CERTIFICATE_STATUSES }).notNull().default("not_requested"),
1747
+ certificateRequestedAt: timestamp16("certificate_requested_at"),
1748
+ certificateIssuedAt: timestamp16("certificate_issued_at"),
1749
+ certificateError: text16("certificate_error"),
1750
+ verificationDetails: jsonb10("verification_details").$type(),
1751
+ lastCheckedAt: timestamp16("last_checked_at"),
1752
+ verifiedAt: timestamp16("verified_at"),
1753
+ createdAt: timestamp16("created_at").notNull().defaultNow(),
1754
+ updatedAt: timestamp16("updated_at").notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
1755
+ },
1756
+ (table) => [
1757
+ uniqueIndex15("web_domains_hostname_uidx").on(table.hostname),
1758
+ index14("web_domains_org_idx").on(table.organizationId),
1759
+ index14("web_domains_status_idx").on(table.status)
1760
+ ]
1761
+ );
1762
+ var webPageSchema = createInsertSchema14(webPages);
1763
+ var webPageSelectSchema = createSelectSchema2(webPages);
1764
+ var webDomainSchema = createInsertSchema14(webDomains);
1765
+ var webDomainSelectSchema = createSelectSchema2(webDomains);
1766
+ function normalizeWebDomainHostname(value) {
1767
+ return value.trim().toLowerCase().replace(/\.$/, "");
1768
+ }
1769
+ function isValidWebDomainHostname(value) {
1770
+ if (value.length > 253) return false;
1771
+ if (value.includes("/") || value.includes("\\") || value.includes(":")) return false;
1772
+ if (value === "localhost" || value.endsWith(".localhost")) return false;
1773
+ if (/^\d{1,3}(\.\d{1,3}){3}$/.test(value)) return false;
1774
+ const labels = value.split(".");
1775
+ if (labels.length < 2) return false;
1776
+ return labels.every((label) => label.length > 0 && label.length <= 63 && /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(label));
1777
+ }
1778
+ var webDomainHostnameSchema = z9.string().trim().min(1, "Hostname is required").max(253, "Hostname must be 253 characters or less").transform(normalizeWebDomainHostname).refine((hostname) => !/^[a-z][a-z\d+\-.]*:\/\//i.test(hostname), {
1779
+ message: "Hostname must not include a protocol"
1780
+ }).refine(isValidWebDomainHostname, {
1781
+ message: "Hostname must be a valid public domain name"
1782
+ });
1783
+ var webPagePathSchema = z9.string().trim().min(1, "Path is required").max(200, "Path must be 200 characters or less").transform(normalizeWebPagePath).refine((path) => !WEB_PAGE_RESERVED_PATHS.includes(path), {
1784
+ message: "Path is reserved by the web host"
1785
+ }).refine((path) => !WEB_PAGE_RESERVED_PREFIXES.some((prefix) => path === prefix || path.startsWith(`${prefix}/`)), {
1786
+ message: "Path uses a reserved system prefix"
1787
+ }).refine((path) => path === "/" || /^\/[a-z0-9][a-z0-9/_-]*$/.test(path), {
1788
+ message: "Path must use lowercase letters, numbers, dashes, underscores, and slashes"
1789
+ }).refine((path) => !path.split("/").some((segment) => segment === "." || segment === ".."), {
1790
+ message: "Path cannot contain dot segments"
1791
+ });
1792
+ var webDesignDocumentSchema = z9.record(z9.string(), z9.unknown());
1793
+ var createWebPageMutation = webPageSchema.pick({
1794
+ title: true,
1795
+ path: true,
1796
+ status: true,
1797
+ routeId: true,
1798
+ templateId: true,
1799
+ seoTitle: true,
1800
+ seoDescription: true
1801
+ }).extend({
1802
+ path: webPagePathSchema
1803
+ });
1804
+ var updateWebPageMutation = createWebPageMutation.partial();
1805
+ var getWebPageDocumentQuery = webPageSelectSchema.pick({
1806
+ id: true
1807
+ });
1808
+ var saveWebPageDocumentMutation = getWebPageDocumentQuery.extend({
1809
+ document: webDesignDocumentSchema
1810
+ });
1811
+ var publishWebPageMutation = getWebPageDocumentQuery;
1812
+ var createWebDomainMutation = webDomainSchema.pick({
1813
+ hostname: true
1814
+ }).extend({
1815
+ hostname: webDomainHostnameSchema
1816
+ });
1817
+ var getWebDomainQuery = webDomainSelectSchema.pick({
1818
+ id: true
1819
+ });
1820
+ var verifyWebDomainMutation = getWebDomainQuery;
1821
+ var requestWebDomainCertificateMutation = getWebDomainQuery;
1822
+ var updateWebDomainCertificateStatusMutation = getWebDomainQuery.extend({
1823
+ status: z9.enum(WEB_DOMAIN_CERTIFICATE_STATUSES),
1824
+ error: z9.string().trim().max(1e3).optional()
1825
+ });
1826
+ var setPrimaryWebDomainMutation = getWebDomainQuery;
1827
+ var disableWebDomainMutation = getWebDomainQuery;
1828
+ var deleteWebDomainMutation = getWebDomainQuery;
1829
+
1830
+ // src/schema/site-presentation.ts
1831
+ import { sql as sql5 } from "drizzle-orm";
1832
+ import {
1833
+ check as check2,
1834
+ foreignKey,
1835
+ index as index15,
1836
+ integer as integer9,
1837
+ jsonb as jsonb11,
1838
+ pgTable as pgTable17,
1839
+ text as text17,
1840
+ timestamp as timestamp17,
1841
+ uniqueIndex as uniqueIndex16,
1842
+ varchar as varchar6
1843
+ } from "drizzle-orm/pg-core";
1844
+ import { createInsertSchema as createInsertSchema15, createSelectSchema as createSelectSchema3 } from "drizzle-orm/zod";
1845
+ import { z as z10 } from "zod";
1846
+ var WEB_THEME_REVISION_STATUSES = [
1847
+ "draft",
1848
+ "published",
1849
+ "archived",
1850
+ "invalid"
1851
+ ];
1852
+ var WEB_THEME_SELECTION_STATUSES = ["active", "safe_mode"];
1853
+ var webThemeRevisions = pgTable17(
1854
+ "web_theme_revisions",
1855
+ {
1856
+ id: text17("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
1857
+ organizationId: text17("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
1858
+ pluginId: varchar6("plugin_id", { length: 160 }).notNull(),
1859
+ pluginVersion: varchar6("plugin_version", { length: 80 }).notNull(),
1860
+ revision: integer9("revision").notNull(),
1861
+ status: varchar6("status", { length: 24, enum: WEB_THEME_REVISION_STATUSES }).notNull().$type().default("draft"),
1862
+ version: integer9("version").notNull().default(1),
1863
+ homeTarget: jsonb11("home_target").notNull().$type().default({ type: "default" }),
1864
+ settings: jsonb11("settings").notNull().$type().default({}),
1865
+ tokenOverrides: jsonb11("token_overrides").notNull().$type().default({}),
1866
+ adapterConfig: jsonb11("adapter_config").notNull().$type().default({}),
1867
+ embedConfig: jsonb11("embed_config").notNull().$type().default({}),
1868
+ schemaVersions: jsonb11("schema_versions").notNull().$type().default({}),
1869
+ compatibilitySnapshot: jsonb11("compatibility_snapshot").$type(),
1870
+ createdBy: text17("created_by").notNull(),
1871
+ updatedBy: text17("updated_by").notNull(),
1872
+ publishedBy: text17("published_by"),
1873
+ createdAt: timestamp17("created_at").notNull().defaultNow(),
1874
+ updatedAt: timestamp17("updated_at").notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date()),
1875
+ publishedAt: timestamp17("published_at")
1876
+ },
1877
+ (table) => [
1878
+ uniqueIndex16("web_theme_revisions_org_plugin_revision_uidx").on(
1879
+ table.organizationId,
1880
+ table.pluginId,
1881
+ table.revision
1882
+ ),
1883
+ uniqueIndex16("web_theme_revisions_org_id_uidx").on(table.organizationId, table.id),
1884
+ uniqueIndex16("web_theme_revisions_one_draft_uidx").on(table.organizationId, table.pluginId).where(sql5`${table.status} = 'draft'`),
1885
+ index15("web_theme_revisions_org_plugin_history_idx").on(
1886
+ table.organizationId,
1887
+ table.pluginId,
1888
+ table.createdAt
1889
+ ),
1890
+ index15("web_theme_revisions_org_status_idx").on(table.organizationId, table.status)
1891
+ ]
1892
+ );
1893
+ var webThemeSelections = pgTable17(
1894
+ "web_theme_selections",
1895
+ {
1896
+ organizationId: text17("organization_id").primaryKey().references(() => organization.id, { onDelete: "cascade" }),
1897
+ activeRevisionId: text17("active_revision_id"),
1898
+ previousRevisionId: text17("previous_revision_id"),
1899
+ lastKnownCompatibleRevisionId: text17("last_known_compatible_revision_id"),
1900
+ status: varchar6("status", { length: 24, enum: WEB_THEME_SELECTION_STATUSES }).notNull().$type().default("active"),
1901
+ version: integer9("version").notNull().default(1),
1902
+ diagnostics: jsonb11("diagnostics").notNull().$type().default([]),
1903
+ safeModeReason: text17("safe_mode_reason"),
1904
+ safeModeEnteredAt: timestamp17("safe_mode_entered_at"),
1905
+ updatedBy: text17("updated_by").notNull(),
1906
+ createdAt: timestamp17("created_at").notNull().defaultNow(),
1907
+ updatedAt: timestamp17("updated_at").notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
1908
+ },
1909
+ (table) => [
1910
+ foreignKey({
1911
+ name: "web_theme_selections_active_revision_fk",
1912
+ columns: [table.organizationId, table.activeRevisionId],
1913
+ foreignColumns: [webThemeRevisions.organizationId, webThemeRevisions.id]
1914
+ }).onDelete("restrict"),
1915
+ foreignKey({
1916
+ name: "web_theme_selections_previous_revision_fk",
1917
+ columns: [table.organizationId, table.previousRevisionId],
1918
+ foreignColumns: [webThemeRevisions.organizationId, webThemeRevisions.id]
1919
+ }).onDelete("restrict"),
1920
+ foreignKey({
1921
+ name: "web_theme_selections_last_compatible_revision_fk",
1922
+ columns: [table.organizationId, table.lastKnownCompatibleRevisionId],
1923
+ foreignColumns: [webThemeRevisions.organizationId, webThemeRevisions.id]
1924
+ }).onDelete("restrict"),
1925
+ check2(
1926
+ "web_theme_selections_active_previous_distinct_chk",
1927
+ sql5`${table.activeRevisionId} IS NULL OR ${table.previousRevisionId} IS NULL OR ${table.activeRevisionId} <> ${table.previousRevisionId}`
1928
+ ),
1929
+ index15("web_theme_selections_active_revision_idx").on(table.activeRevisionId),
1930
+ index15("web_theme_selections_status_idx").on(table.status)
1931
+ ]
1932
+ );
1933
+ var webThemePluginIdSchema = z10.string().min(3).max(160).regex(/^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)+$/);
1934
+ var webThemeHomeTargetSchema = z10.discriminatedUnion("type", [
1935
+ z10.object({ type: z10.literal("theme-route"), routeId: z10.string().min(1).max(160) }),
1936
+ z10.object({
1937
+ type: z10.literal("plugin-route"),
1938
+ pluginId: webThemePluginIdSchema,
1939
+ routeId: z10.string().min(1).max(160)
1940
+ }),
1941
+ z10.object({ type: z10.literal("designer-page"), pageId: z10.string().min(1).max(160) }),
1942
+ z10.object({ type: z10.literal("default") })
1943
+ ]);
1944
+ var webThemeJsonObjectSchema = z10.record(z10.string(), z10.json());
1945
+ var webThemeAdapterSelectionSchema = z10.object({
1946
+ ownerPluginId: webThemePluginIdSchema,
1947
+ surfaceId: z10.string().min(1).max(160).regex(/^[a-z0-9][a-z0-9._-]*$/),
1948
+ source: z10.enum(["theme", "plugin", "owner"]),
1949
+ providerPluginId: webThemePluginIdSchema.optional()
1950
+ }).superRefine((selection, ctx) => {
1951
+ if (selection.source === "plugin" && !selection.providerPluginId) {
1952
+ ctx.addIssue({
1953
+ code: "custom",
1954
+ path: ["providerPluginId"],
1955
+ message: "plugin adapter selections require providerPluginId"
1956
+ });
1957
+ }
1958
+ if (selection.source !== "plugin" && selection.providerPluginId) {
1959
+ ctx.addIssue({
1960
+ code: "custom",
1961
+ path: ["providerPluginId"],
1962
+ message: "providerPluginId is only allowed for plugin adapter selections"
1963
+ });
1964
+ }
1965
+ });
1966
+ var webThemeAdapterConfigSchema = z10.object({
1967
+ selections: z10.array(webThemeAdapterSelectionSchema).optional(),
1968
+ providers: z10.record(webThemePluginIdSchema, webThemeJsonObjectSchema).optional()
1969
+ }).superRefine((config, ctx) => {
1970
+ const targets = /* @__PURE__ */ new Set();
1971
+ for (const [index28, selection] of (config.selections ?? []).entries()) {
1972
+ const key = `${selection.ownerPluginId}:${selection.surfaceId}`;
1973
+ if (targets.has(key)) {
1974
+ ctx.addIssue({
1975
+ code: "custom",
1976
+ path: ["selections", index28, "surfaceId"],
1977
+ message: `duplicate adapter selection target: ${key}`
1978
+ });
1979
+ }
1980
+ targets.add(key);
1981
+ }
1982
+ });
1983
+ var webThemeRevisionSchema = createInsertSchema15(webThemeRevisions, {
1984
+ homeTarget: () => webThemeHomeTargetSchema,
1985
+ settings: () => webThemeJsonObjectSchema,
1986
+ tokenOverrides: () => webThemeJsonObjectSchema,
1987
+ adapterConfig: () => webThemeAdapterConfigSchema,
1988
+ embedConfig: () => webThemeJsonObjectSchema,
1989
+ schemaVersions: () => z10.record(z10.string(), z10.number().int().nonnegative())
1990
+ });
1991
+ var webThemeRevisionSelectSchema = createSelectSchema3(webThemeRevisions);
1992
+ var webThemeSelectionSchema = createInsertSchema15(webThemeSelections);
1993
+ var webThemeSelectionSelectSchema = createSelectSchema3(webThemeSelections);
1994
+ var getWebThemeQuery = z10.object({ pluginId: webThemePluginIdSchema });
1995
+ var setWebThemeEnabledMutation = getWebThemeQuery.extend({ enabled: z10.boolean() });
1996
+ var getWebThemeRevisionQuery = webThemeRevisionSelectSchema.pick({ id: true });
1997
+ var listWebThemeRevisionsQuery = getWebThemeQuery.merge(paginationSchema);
1998
+ var saveWebThemeDraftMutation = getWebThemeQuery.extend({
1999
+ expectedVersion: z10.number().int().positive().optional(),
2000
+ homeTarget: webThemeHomeTargetSchema.optional(),
2001
+ settings: webThemeJsonObjectSchema.optional(),
2002
+ tokenOverrides: webThemeJsonObjectSchema.optional(),
2003
+ adapterConfig: webThemeAdapterConfigSchema.optional(),
2004
+ embedConfig: webThemeJsonObjectSchema.optional()
2005
+ });
2006
+ var activateWebThemeMutation = getWebThemeQuery.extend({
2007
+ expectedSelectionVersion: z10.number().int().positive().optional()
2008
+ });
2009
+ var activateWebThemeRevisionMutation = getWebThemeRevisionQuery.extend({
2010
+ expectedSelectionVersion: z10.number().int().positive().optional()
2011
+ });
2012
+ var publishWebThemeDraftMutation = getWebThemeRevisionQuery.extend({
2013
+ expectedDraftVersion: z10.number().int().positive(),
2014
+ expectedSelectionVersion: z10.number().int().positive().optional()
2015
+ });
2016
+ var rollbackWebThemeRevisionMutation = getWebThemeRevisionQuery.extend({
2017
+ expectedSelectionVersion: z10.number().int().positive()
2018
+ });
2019
+ var issueWebThemePreviewMutation = getWebThemeRevisionQuery.extend({
2020
+ host: z10.string().trim().min(1).max(253),
2021
+ pageId: z10.string().min(1).max(160).optional(),
2022
+ expiresInSeconds: z10.number().int().min(30).max(900).optional()
2023
+ });
2024
+ var recoverWebThemeMutation = z10.object({
2025
+ expectedSelectionVersion: z10.number().int().positive(),
2026
+ revisionId: z10.string().min(1).optional()
2027
+ });
2028
+
2029
+ // src/schema/notifications.ts
2030
+ import {
2031
+ pgTable as pgTable18,
2032
+ text as text18,
2033
+ timestamp as timestamp18,
2034
+ jsonb as jsonb12,
2035
+ boolean as boolean12,
2036
+ integer as integer10,
2037
+ index as index16
2038
+ } from "drizzle-orm/pg-core";
2039
+ import { createInsertSchema as createInsertSchema16 } from "drizzle-orm/zod";
2040
+ var NotificationTypeEnum = {
2041
+ // System / SaaS
2042
+ SYSTEM_ALERT: "system_alert",
2043
+ SYSTEM_WARNING: "system_warning",
2044
+ TASK_ASSIGNED: "task_assigned",
2045
+ TASK_COMPLETED: "task_completed",
2046
+ EXPORT_READY: "export_ready",
2047
+ // Collaboration
2048
+ COMMENT_ADDED: "comment_added",
2049
+ COMMENT_REPLIED: "comment_replied",
2050
+ MENTIONED: "mentioned",
2051
+ // Social (reserved for future)
2052
+ POST_LIKED: "post_liked",
2053
+ POST_COMMENTED: "post_commented",
2054
+ USER_FOLLOWED: "user_followed"
2055
+ };
2056
+ var notifications = pgTable18(
2057
+ "notifications",
2058
+ {
2059
+ id: text18("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
2060
+ // FK to user table
2061
+ userId: text18("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
2062
+ // FK to organization table
2063
+ organizationId: text18("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
2064
+ // Actor/Entity for better UI rendering
2065
+ actorId: text18("actor_id"),
2066
+ entityId: text18("entity_id"),
2067
+ entityType: text18("entity_type"),
2068
+ // Template reference
2069
+ templateKey: text18("template_key"),
2070
+ templateVariables: jsonb12("template_variables").$type(),
2071
+ // Content (rendered)
2072
+ type: text18("type").notNull().$type(),
2073
+ title: text18("title").notNull(),
2074
+ message: text18("message").notNull(),
2075
+ link: text18("link"),
2076
+ // Status
2077
+ read: boolean12("read").notNull().default(false),
2078
+ archived: boolean12("archived").notNull().default(false),
2079
+ // Channel tracking
2080
+ channelsSent: jsonb12("channels_sent").$type(),
2081
+ channelsFailed: jsonb12("channels_failed").$type(),
2082
+ emailSent: boolean12("email_sent").notNull().default(false),
2083
+ emailSentAt: timestamp18("email_sent_at"),
2084
+ // Grouping/Bundling support
2085
+ groupKey: text18("group_key"),
2086
+ groupCount: integer10("group_count").notNull().default(1),
2087
+ // Idempotency
2088
+ idempotencyKey: text18("idempotency_key").unique(),
2089
+ // Source tracking
2090
+ sourcePluginId: text18("source_plugin_id"),
2091
+ // Priority
2092
+ priority: text18("priority").notNull().default("normal").$type(),
2093
+ // Source - who triggered the notification (system/plugin/user)
2094
+ source: text18("source").notNull().default("system").$type(),
2095
+ // Category - determines retention policy and view strategy
2096
+ category: text18("category").notNull().default("system").$type(),
2097
+ // Latest Actors - for aggregation display ("Alice and 4 others...")
2098
+ latestActors: jsonb12("latest_actors").$type().default([]),
2099
+ // Pinned - for system alerts that need to stay at top
2100
+ pinned: boolean12("pinned").notNull().default(false),
2101
+ // Visual Priority - for UI styling
2102
+ visualPriority: text18("visual_priority").notNull().default("medium").$type(),
2103
+ // Actor info - structured actor data for rendering
2104
+ actor: jsonb12("actor").$type(),
2105
+ // Target info - what the notification is about
2106
+ target: jsonb12("target").$type(),
2107
+ // Aggregation Strategy - how to group notifications
2108
+ aggregationStrategy: text18("aggregation_strategy").notNull().default("none").$type(),
2109
+ // Metadata includes decisionTrace for debugging
2110
+ metadata: jsonb12("metadata").$type(),
2111
+ // Timestamps
2112
+ createdAt: timestamp18("created_at").notNull().defaultNow(),
2113
+ expiresAt: timestamp18("expires_at")
2114
+ },
2115
+ (table) => [
2116
+ index16("idx_notifications_user_read").on(table.userId, table.read),
2117
+ index16("idx_notifications_template").on(table.templateKey),
2118
+ index16("idx_notifications_group").on(table.groupKey),
2119
+ index16("idx_notifications_expires").on(table.expiresAt),
2120
+ index16("idx_notifications_tenant_user").on(table.organizationId, table.userId),
2121
+ index16("idx_notifications_category").on(table.category),
2122
+ index16("idx_notifications_source").on(table.source),
2123
+ index16("idx_notifications_pinned").on(table.pinned),
2124
+ index16("idx_notifications_cleanup").on(table.category, table.read, table.createdAt)
2125
+ ]
2126
+ );
2127
+ var notificationSchema = createInsertSchema16(notifications);
2128
+
2129
+ // src/schema/notification-templates.ts
2130
+ import {
2131
+ pgTable as pgTable19,
2132
+ text as text19,
2133
+ timestamp as timestamp19,
2134
+ jsonb as jsonb13,
2135
+ boolean as boolean13,
2136
+ integer as integer11,
2137
+ index as index17
2138
+ } from "drizzle-orm/pg-core";
2139
+ import { createInsertSchema as createInsertSchema17 } from "drizzle-orm/zod";
2140
+ var notificationTemplates = pgTable19(
2141
+ "notification_templates",
2142
+ {
2143
+ id: text19("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
2144
+ // Unique key (e.g., 'comment.new', 'order.shipped')
2145
+ key: text19("key").notNull().unique(),
2146
+ // Display name
2147
+ name: text19("name").notNull(),
2148
+ description: text19("description"),
2149
+ // Category
2150
+ category: text19("category").notNull().$type(),
2151
+ // i18n content
2152
+ title: jsonb13("title").notNull().$type(),
2153
+ message: jsonb13("message").notNull().$type(),
2154
+ // Variables that can be interpolated
2155
+ variables: jsonb13("variables").$type(),
2156
+ // Default channels for this template
2157
+ defaultChannels: jsonb13("default_channels").notNull().default(["in-app"]).$type(),
2158
+ // Priority
2159
+ priority: text19("priority").notNull().default("normal").$type(),
2160
+ // Plugin reference (if registered by plugin)
2161
+ pluginId: text19("plugin_id"),
2162
+ // Template evolution
2163
+ deprecated: boolean13("deprecated").notNull().default(false),
2164
+ version: integer11("version").notNull().default(1),
2165
+ // Timestamps
2166
+ createdAt: timestamp19("created_at").notNull().defaultNow(),
2167
+ updatedAt: timestamp19("updated_at").notNull().defaultNow()
2168
+ },
2169
+ (table) => [
2170
+ index17("idx_templates_plugin").on(table.pluginId),
2171
+ index17("idx_templates_category").on(table.category)
2172
+ ]
2173
+ );
2174
+ var notificationTemplateSchema = createInsertSchema17(notificationTemplates);
2175
+
2176
+ // src/schema/notification-channels.ts
2177
+ import {
2178
+ pgTable as pgTable20,
2179
+ text as text20,
2180
+ timestamp as timestamp20,
2181
+ jsonb as jsonb14,
2182
+ boolean as boolean14,
2183
+ index as index18
2184
+ } from "drizzle-orm/pg-core";
2185
+ import { createInsertSchema as createInsertSchema18 } from "drizzle-orm/zod";
2186
+ var notificationChannels = pgTable20(
2187
+ "notification_channels",
2188
+ {
2189
+ id: text20("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
2190
+ // Unique key (namespaced)
2191
+ // Format: 'in-app' (Core) or 'plugin:{pluginId}:{channel}'
2192
+ key: text20("key").notNull().unique(),
2193
+ // Display name (i18n)
2194
+ name: jsonb14("name").notNull().$type(),
2195
+ // Description (i18n)
2196
+ description: jsonb14("description").$type(),
2197
+ // Icon name
2198
+ icon: text20("icon"),
2199
+ // Plugin reference
2200
+ pluginId: text20("plugin_id").notNull(),
2201
+ // Is this channel currently enabled
2202
+ enabled: boolean14("enabled").notNull().default(true),
2203
+ // User configuration schema (Zod schema as JSON)
2204
+ configSchema: jsonb14("config_schema"),
2205
+ // Timestamps
2206
+ createdAt: timestamp20("created_at").notNull().defaultNow()
2207
+ },
2208
+ (table) => [
2209
+ index18("idx_channels_plugin").on(table.pluginId),
2210
+ index18("idx_channels_enabled").on(table.enabled)
2211
+ ]
2212
+ );
2213
+ var notificationChannelSchema = createInsertSchema18(notificationChannels);
2214
+
2215
+ // src/schema/notification-preferences.ts
2216
+ import {
2217
+ pgTable as pgTable21,
2218
+ text as text21,
2219
+ timestamp as timestamp21,
2220
+ jsonb as jsonb15,
2221
+ uniqueIndex as uniqueIndex17
2222
+ } from "drizzle-orm/pg-core";
2223
+ import { createInsertSchema as createInsertSchema19 } from "drizzle-orm/zod";
2224
+ var notificationPreferences = pgTable21(
2225
+ "notification_preferences",
2226
+ {
2227
+ id: text21("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
2228
+ // FK to user table
2229
+ userId: text21("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
2230
+ // FK to organization table
2231
+ organizationId: text21("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
2232
+ // Enabled channels (global)
2233
+ enabledChannels: jsonb15("enabled_channels").notNull().default(["in-app"]).$type(),
2234
+ // Per-template channel overrides
2235
+ // e.g., { 'order.urgent': ['in-app', 'email', 'sms'] }
2236
+ templateOverrides: jsonb15("template_overrides").$type(),
2237
+ // Quiet hours (do not disturb)
2238
+ quietHours: jsonb15("quiet_hours").$type(),
2239
+ // Email digest frequency
2240
+ emailFrequency: text21("email_frequency").notNull().default("instant").$type(),
2241
+ // Timestamps
2242
+ createdAt: timestamp21("created_at").notNull().defaultNow(),
2243
+ updatedAt: timestamp21("updated_at").notNull().defaultNow()
2244
+ },
2245
+ (table) => [
2246
+ uniqueIndex17("idx_preferences_user_tenant").on(
2247
+ table.userId,
2248
+ table.organizationId
2249
+ )
2250
+ ]
2251
+ );
2252
+ var notificationPreferenceSchema = createInsertSchema19(notificationPreferences);
2253
+
2254
+ // src/schema/audit-logs.ts
2255
+ import { pgTable as pgTable22, text as text22, timestamp as timestamp22, jsonb as jsonb16, index as index19 } from "drizzle-orm/pg-core";
2256
+ import { createInsertSchema as createInsertSchema20 } from "drizzle-orm/zod";
2257
+ var auditLogs = pgTable22(
2258
+ "audit_logs",
2259
+ {
2260
+ id: text22("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
2261
+ // Actor
2262
+ actorType: text22("actor_type").notNull().$type(),
2263
+ actorId: text22("actor_id").notNull(),
2264
+ // FK to organization table
2265
+ organizationId: text22("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
2266
+ // Action
2267
+ action: text22("action").notNull(),
2268
+ resource: text22("resource"),
2269
+ // Result
2270
+ result: text22("result").notNull().$type(),
2271
+ reason: text22("reason"),
2272
+ // Metadata
2273
+ metadata: jsonb16("metadata"),
2274
+ // Audit enhancement fields
2275
+ actorIp: text22("actor_ip"),
2276
+ userAgent: text22("user_agent"),
2277
+ traceId: text22("trace_id"),
2278
+ createdAt: timestamp22("created_at").notNull().defaultNow()
2279
+ },
2280
+ (table) => [
2281
+ index19("audit_logs_organization_idx").on(table.organizationId),
2282
+ index19("audit_logs_actor_idx").on(table.actorType, table.actorId),
2283
+ index19("audit_logs_action_idx").on(table.action),
2284
+ index19("audit_logs_created_at_idx").on(table.createdAt),
2285
+ index19("audit_logs_trace_idx").on(table.traceId)
2286
+ ]
2287
+ );
2288
+ var auditLogSchema = createInsertSchema20(auditLogs);
2289
+
2290
+ // src/schema/audit-events.ts
2291
+ import { pgTable as pgTable23, text as text23, timestamp as timestamp23, jsonb as jsonb17, index as index20 } from "drizzle-orm/pg-core";
2292
+ import { createInsertSchema as createInsertSchema21 } from "drizzle-orm/zod";
2293
+ var auditEvents = pgTable23(
2294
+ "audit_events",
2295
+ {
2296
+ id: text23("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
2297
+ // Entity identification
2298
+ entityType: text23("entity_type").notNull(),
2299
+ // 'setting', 'user', 'role', 'feature_flag', etc.
2300
+ entityId: text23("entity_id"),
2301
+ // Entity ID (can be NULL for batch operations)
2302
+ // FK to organization table (nullable for global operations)
2303
+ organizationId: text23("organization_id").references(() => organization.id, { onDelete: "cascade" }),
2304
+ // Action
2305
+ action: text23("action").notNull(),
2306
+ // 'create', 'update', 'delete', 'login', 'logout', etc.
2307
+ // Changes (flexible structure)
2308
+ changes: jsonb17("changes").$type(),
2309
+ // { old: {...}, new: {...} } or custom structure
2310
+ metadata: jsonb17("metadata").$type(),
2311
+ // Extra context
2312
+ // Actor
2313
+ actorId: text23("actor_id").notNull(),
2314
+ actorType: text23("actor_type").notNull().$type().default("user"),
2315
+ actorIp: text23("actor_ip"),
2316
+ userAgent: text23("user_agent"),
2317
+ // Correlation & Tracing
2318
+ requestId: text23("request_id"),
2319
+ // Request tracking ID
2320
+ sessionId: text23("session_id"),
2321
+ traceId: text23("trace_id"),
2322
+ // Distributed trace ID
2323
+ // Timestamp
2324
+ createdAt: timestamp23("created_at").notNull().defaultNow()
2325
+ },
2326
+ (table) => [
2327
+ // Index for entity queries
2328
+ index20("audit_events_entity_idx").on(table.entityType, table.entityId),
2329
+ // Index for tenant queries
2330
+ index20("audit_events_organization_idx").on(table.organizationId),
2331
+ // Index for actor queries
2332
+ index20("audit_events_actor_idx").on(table.actorId),
2333
+ // Index for time-based queries
2334
+ index20("audit_events_time_idx").on(table.createdAt),
2335
+ // Index for action queries
2336
+ index20("audit_events_action_idx").on(table.entityType, table.action),
2337
+ // Index for trace queries
2338
+ index20("audit_events_trace_idx").on(table.traceId)
2339
+ ]
2340
+ );
2341
+ var auditEventSchema = createInsertSchema21(auditEvents);
2342
+
2343
+ // src/schema/audit-archive.ts
2344
+ import { pgTable as pgTable24, text as text24, timestamp as timestamp24, jsonb as jsonb18, index as index21 } from "drizzle-orm/pg-core";
2345
+ import { createInsertSchema as createInsertSchema22 } from "drizzle-orm/zod";
2346
+ var auditEventsArchive = pgTable24(
2347
+ "audit_events_archive",
2348
+ {
2349
+ id: text24("id").primaryKey(),
2350
+ // Entity identification
2351
+ entityType: text24("entity_type").notNull(),
2352
+ entityId: text24("entity_id"),
2353
+ // FK to organization table (nullable for global operations)
2354
+ organizationId: text24("organization_id").references(() => organization.id, { onDelete: "set null" }),
2355
+ // Action
2356
+ action: text24("action").notNull(),
2357
+ // Changes
2358
+ changes: jsonb18("changes").$type(),
2359
+ metadata: jsonb18("metadata").$type(),
2360
+ // Actor
2361
+ actorId: text24("actor_id").notNull(),
2362
+ actorType: text24("actor_type").notNull().$type().default("user"),
2363
+ actorIp: text24("actor_ip"),
2364
+ userAgent: text24("user_agent"),
2365
+ // Correlation & Tracing
2366
+ requestId: text24("request_id"),
2367
+ sessionId: text24("session_id"),
2368
+ traceId: text24("trace_id"),
2369
+ // Timestamps
2370
+ createdAt: timestamp24("created_at").notNull(),
2371
+ archivedAt: timestamp24("archived_at").notNull().defaultNow()
2372
+ },
2373
+ (table) => [
2374
+ index21("audit_events_archive_entity_idx").on(table.entityType, table.entityId),
2375
+ index21("audit_events_archive_organization_idx").on(table.organizationId),
2376
+ index21("audit_events_archive_time_idx").on(table.createdAt)
2377
+ ]
2378
+ );
2379
+ var auditLogsArchive = pgTable24(
2380
+ "audit_logs_archive",
2381
+ {
2382
+ id: text24("id").primaryKey(),
2383
+ // Actor
2384
+ actorType: text24("actor_type").notNull().$type(),
2385
+ actorId: text24("actor_id").notNull(),
2386
+ // FK to organization table
2387
+ organizationId: text24("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
2388
+ // Action
2389
+ action: text24("action").notNull(),
2390
+ resource: text24("resource"),
2391
+ // Result
2392
+ result: text24("result").notNull().$type(),
2393
+ reason: text24("reason"),
2394
+ // Metadata
2395
+ metadata: jsonb18("metadata"),
2396
+ // Audit enhancement fields
2397
+ actorIp: text24("actor_ip"),
2398
+ userAgent: text24("user_agent"),
2399
+ traceId: text24("trace_id"),
2400
+ // Timestamps
2401
+ createdAt: timestamp24("created_at").notNull(),
2402
+ archivedAt: timestamp24("archived_at").notNull().defaultNow()
2403
+ },
2404
+ (table) => [
2405
+ index21("audit_logs_archive_organization_idx").on(table.organizationId),
2406
+ index21("audit_logs_archive_actor_idx").on(table.actorType, table.actorId),
2407
+ index21("audit_logs_archive_time_idx").on(table.createdAt)
2408
+ ]
2409
+ );
2410
+ var auditEventsArchiveSchema = createInsertSchema22(auditEventsArchive);
2411
+ var auditLogsArchiveSchema = createInsertSchema22(auditLogsArchive);
2412
+
2413
+ // src/schema/entity-ownerships.ts
2414
+ import {
2415
+ pgTable as pgTable25,
2416
+ text as text25,
2417
+ timestamp as timestamp25,
2418
+ index as index22,
2419
+ uniqueIndex as uniqueIndex18,
2420
+ jsonb as jsonb19
2421
+ } from "drizzle-orm/pg-core";
2422
+ import { createInsertSchema as createInsertSchema23 } from "drizzle-orm/zod";
2423
+ var ScopeType = {
2424
+ USER: "user",
2425
+ TEAM: "team",
2426
+ ROLE: "role",
2427
+ SPACE: "space",
2428
+ ORG: "org"
2429
+ };
2430
+ var AccessLevel = {
2431
+ READ: "read",
2432
+ WRITE: "write"
2433
+ };
2434
+ var entityOwnerships = pgTable25(
2435
+ "entity_ownerships",
2436
+ {
2437
+ id: text25("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
2438
+ // Target Entity
2439
+ entityType: text25("entity_type").notNull(),
2440
+ // 'article', 'document', etc.
2441
+ entityId: text25("entity_id").notNull(),
2442
+ // Scope (who has access)
2443
+ scopeType: text25("scope_type").notNull(),
2444
+ // 'user' | 'team' | 'role' | 'space' | 'org'
2445
+ scopeId: text25("scope_id").notNull(),
2446
+ // Access Level
2447
+ level: text25("level").notNull().default("read"),
2448
+ // 'read' | 'write'
2449
+ // Inheritance Tracking (for rebuild)
2450
+ inheritedFromType: text25("inherited_from_type"),
2451
+ // 'team' | 'space' | null
2452
+ inheritedFromId: text25("inherited_from_id"),
2453
+ // Source scope ID
2454
+ // FK to organization table
2455
+ organizationId: text25("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
2456
+ // Expiration (optional, for time-limited access)
2457
+ expireAt: timestamp25("expire_at"),
2458
+ // Metadata
2459
+ createdAt: timestamp25("created_at").defaultNow().notNull(),
2460
+ updatedAt: timestamp25("updated_at").defaultNow().notNull(),
2461
+ createdBy: text25("created_by")
2462
+ // Actor who granted this
2463
+ },
2464
+ (table) => [
2465
+ // Unique constraint: one grant per entity-scope combination
2466
+ uniqueIndex18("ownership_unique_idx").on(
2467
+ table.entityType,
2468
+ table.entityId,
2469
+ table.scopeType,
2470
+ table.scopeId
2471
+ ),
2472
+ // Query by entity
2473
+ index22("ownership_entity_idx").on(table.entityType, table.entityId),
2474
+ // Query by scope (who has access to what)
2475
+ index22("ownership_scope_idx").on(table.scopeType, table.scopeId),
2476
+ // Query inherited ownerships (for rebuild on membership change)
2477
+ index22("ownership_inherited_idx").on(table.inheritedFromType, table.inheritedFromId),
2478
+ // Tenant isolation
2479
+ index22("ownership_org_idx").on(table.organizationId),
2480
+ // Expiration cleanup
2481
+ index22("ownership_expire_idx").on(table.expireAt)
2482
+ ]
2483
+ );
2484
+ var ownershipAuditLog = pgTable25(
2485
+ "ownership_audit_log",
2486
+ {
2487
+ id: text25("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
2488
+ // Reference to ownership (may be deleted)
2489
+ ownershipId: text25("ownership_id").notNull(),
2490
+ entityType: text25("entity_type").notNull(),
2491
+ entityId: text25("entity_id").notNull(),
2492
+ scopeType: text25("scope_type").notNull(),
2493
+ scopeId: text25("scope_id").notNull(),
2494
+ // Action
2495
+ action: text25("action").notNull(),
2496
+ // 'grant' | 'revoke' | 'inherit_expand' | 'inherit_collapse' | 'expire'
2497
+ // State snapshot
2498
+ beforeState: jsonb19("before_state"),
2499
+ afterState: jsonb19("after_state"),
2500
+ // Actor
2501
+ actorId: text25("actor_id").notNull(),
2502
+ actorType: text25("actor_type").notNull(),
2503
+ // 'user' | 'system' | 'plugin'
2504
+ reason: text25("reason"),
2505
+ // FK to organization table
2506
+ organizationId: text25("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
2507
+ // Timestamp
2508
+ timestamp: timestamp25("timestamp").defaultNow().notNull()
2509
+ },
2510
+ (table) => [
2511
+ index22("audit_ownership_idx").on(table.ownershipId),
2512
+ index22("audit_entity_idx").on(table.entityType, table.entityId),
2513
+ index22("audit_actor_idx").on(table.actorId),
2514
+ index22("audit_org_idx").on(table.organizationId),
2515
+ index22("audit_timestamp_idx").on(table.timestamp)
2516
+ ]
2517
+ );
2518
+ var entityOwnershipSchema = createInsertSchema23(entityOwnerships);
2519
+ var ownershipAuditLogSchema = createInsertSchema23(ownershipAuditLog);
2520
+
2521
+ // src/schema/billing.ts
2522
+ import {
2523
+ pgTable as pgTable26,
2524
+ text as text26,
2525
+ timestamp as timestamp26,
2526
+ jsonb as jsonb20,
2527
+ uuid,
2528
+ integer as integer12,
2529
+ index as index23,
2530
+ uniqueIndex as uniqueIndex19
2531
+ } from "drizzle-orm/pg-core";
2532
+ import { sql as sql6 } from "drizzle-orm";
2533
+ import { createInsertSchema as createInsertSchema24 } from "drizzle-orm/zod";
2534
+ var capabilities = pgTable26(
2535
+ "capabilities",
2536
+ {
2537
+ subject: text26("subject").primaryKey(),
2538
+ type: text26("type").notNull().$type(),
2539
+ unit: text26("unit"),
2540
+ description: text26("description"),
2541
+ source: text26("source").notNull().$type(),
2542
+ pluginId: text26("plugin_id"),
2543
+ status: text26("status").notNull().$type().default("pending"),
2544
+ createdAt: timestamp26("created_at").notNull().defaultNow()
2545
+ },
2546
+ (table) => [
2547
+ index23("idx_capabilities_source_status").on(table.source, table.status),
2548
+ index23("idx_capabilities_plugin_id").on(table.pluginId)
2549
+ ]
2550
+ );
2551
+ var plans = pgTable26("plans", {
2552
+ id: text26("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
2553
+ name: text26("name").notNull(),
2554
+ description: text26("description"),
2555
+ interval: text26("interval").notNull().$type(),
2556
+ intervalCount: integer12("interval_count").notNull().default(1),
2557
+ currency: text26("currency").notNull().default("usd"),
2558
+ priceCents: integer12("price_cents").notNull(),
2559
+ isActive: integer12("is_active").notNull().default(1),
2560
+ metadata: jsonb20("metadata").$type(),
2561
+ createdAt: timestamp26("created_at").notNull().defaultNow(),
2562
+ updatedAt: timestamp26("updated_at").notNull().defaultNow()
2563
+ });
2564
+ var planItems = pgTable26(
2565
+ "plan_items",
2566
+ {
2567
+ id: uuid("id").primaryKey().defaultRandom(),
2568
+ planId: text26("plan_id").notNull().references(() => plans.id, { onDelete: "cascade" }),
2569
+ subject: text26("subject").notNull(),
2570
+ procedurePath: text26("procedure_path"),
2571
+ groupKey: text26("group_key"),
2572
+ type: text26("type").notNull().$type(),
2573
+ amount: integer12("amount"),
2574
+ resetMode: text26("reset_mode").notNull().$type(),
2575
+ priority: integer12("priority").notNull().default(0),
2576
+ overagePolicy: text26("overage_policy").$type().default("deny"),
2577
+ overagePriceCents: integer12("overage_price_cents"),
2578
+ resetStrategy: text26("reset_strategy").$type().default("hard"),
2579
+ resetCap: integer12("reset_cap"),
2580
+ quotaScope: text26("quota_scope").$type().notNull().default("tenant"),
2581
+ metadata: jsonb20("metadata").$type(),
2582
+ createdAt: timestamp26("created_at").notNull().defaultNow(),
2583
+ updatedAt: timestamp26("updated_at").notNull().defaultNow()
2584
+ },
2585
+ (table) => [
2586
+ index23("idx_plan_items_plan_id").on(table.planId),
2587
+ index23("idx_plan_items_subject").on(table.subject),
2588
+ index23("idx_plan_items_procedure_path").on(table.procedurePath),
2589
+ uniqueIndex19("uq_plan_items_plan_procedure_path").on(table.planId, table.procedurePath).where(sql6`${table.procedurePath} IS NOT NULL`)
2590
+ ]
2591
+ );
2592
+ var userQuotas = pgTable26(
2593
+ "user_quotas",
2594
+ {
2595
+ id: uuid("id").primaryKey().defaultRandom(),
2596
+ userId: text26("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
2597
+ organizationId: text26("organization_id").references(() => organization.id, { onDelete: "cascade" }),
2598
+ subject: text26("subject").notNull(),
2599
+ balance: integer12("balance").notNull(),
2600
+ priority: integer12("priority").notNull().default(0),
2601
+ expiresAt: timestamp26("expires_at"),
2602
+ sourceType: text26("source_type").notNull().$type(),
2603
+ sourceId: text26("source_id").notNull(),
2604
+ metadata: jsonb20("metadata").$type(),
2605
+ createdAt: timestamp26("created_at").notNull().defaultNow(),
2606
+ updatedAt: timestamp26("updated_at").notNull().defaultNow()
2607
+ },
2608
+ (table) => [
2609
+ index23("idx_user_quotas_user_feature").on(table.userId, table.subject),
2610
+ index23("idx_user_quotas_waterfall").on(
2611
+ table.userId,
2612
+ table.subject,
2613
+ table.balance,
2614
+ table.priority,
2615
+ table.expiresAt
2616
+ ),
2617
+ uniqueIndex19("uq_user_quotas_source").on(
2618
+ table.organizationId,
2619
+ table.userId,
2620
+ table.subject,
2621
+ table.sourceType,
2622
+ table.sourceId
2623
+ ),
2624
+ uniqueIndex19("uq_user_quotas_legacy_source").on(table.userId, table.subject, table.sourceType, table.sourceId).where(sql6`${table.organizationId} IS NULL`)
2625
+ ]
2626
+ );
2627
+ var wallets = pgTable26("wallets", {
2628
+ userId: text26("user_id").primaryKey().references(() => user.id, { onDelete: "cascade" }),
2629
+ balanceCents: integer12("balance_cents").notNull().default(0),
2630
+ currency: text26("currency").notNull().default("usd"),
2631
+ updatedAt: timestamp26("updated_at").notNull().defaultNow()
2632
+ });
2633
+ var transactions = pgTable26(
2634
+ "transactions",
2635
+ {
2636
+ id: uuid("id").primaryKey().defaultRandom(),
2637
+ userId: text26("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
2638
+ amountCents: integer12("amount_cents").notNull(),
2639
+ currency: text26("currency").notNull(),
2640
+ sourceType: text26("source_type").notNull().$type(),
2641
+ sourceId: text26("source_id").notNull(),
2642
+ status: text26("status").notNull().$type().default("PENDING"),
2643
+ gateway: text26("gateway"),
2644
+ externalId: text26("external_id"),
2645
+ baseCurrency: text26("base_currency"),
2646
+ baseAmountCents: integer12("base_amount_cents"),
2647
+ settlementCurrency: text26("settlement_currency"),
2648
+ settlementAmountCents: integer12("settlement_amount_cents"),
2649
+ exchangeRate: text26("exchange_rate"),
2650
+ exchangeRateAt: timestamp26("exchange_rate_at"),
2651
+ metadata: jsonb20("metadata").$type(),
2652
+ paidAt: timestamp26("paid_at"),
2653
+ createdAt: timestamp26("created_at").notNull().defaultNow(),
2654
+ updatedAt: timestamp26("updated_at").notNull().defaultNow()
2655
+ },
2656
+ (table) => [
2657
+ index23("idx_transactions_user_source").on(table.userId, table.sourceType, table.sourceId),
2658
+ uniqueIndex19("uq_transactions_external_id").on(table.externalId),
2659
+ index23("idx_transactions_status").on(table.status)
2660
+ ]
2661
+ );
2662
+ var billingEventOutbox = pgTable26(
2663
+ "billing_event_outbox",
2664
+ {
2665
+ id: uuid("id").primaryKey().defaultRandom(),
2666
+ dedupeKey: text26("dedupe_key").notNull(),
2667
+ transactionId: uuid("transaction_id").notNull().references(() => transactions.id, { onDelete: "cascade" }),
2668
+ eventName: text26("event_name").notNull(),
2669
+ payload: jsonb20("payload").notNull().$type(),
2670
+ status: text26("status").notNull().$type().default("pending"),
2671
+ attempts: integer12("attempts").notNull().default(0),
2672
+ availableAt: timestamp26("available_at", { withTimezone: true }).notNull().defaultNow(),
2673
+ claimId: uuid("claim_id"),
2674
+ leaseExpiresAt: timestamp26("lease_expires_at", { withTimezone: true }),
2675
+ lastError: text26("last_error"),
2676
+ completedAt: timestamp26("completed_at", { withTimezone: true }),
2677
+ createdAt: timestamp26("created_at", { withTimezone: true }).notNull().defaultNow(),
2678
+ updatedAt: timestamp26("updated_at", { withTimezone: true }).notNull().defaultNow()
2679
+ },
2680
+ (table) => [
2681
+ uniqueIndex19("billing_event_outbox_dedupe_uidx").on(table.dedupeKey),
2682
+ index23("billing_event_outbox_available_idx").on(table.status, table.availableAt),
2683
+ index23("billing_event_outbox_transaction_idx").on(table.transactionId)
2684
+ ]
2685
+ );
2686
+ var usageRecords = pgTable26(
2687
+ "usage_records",
2688
+ {
2689
+ id: uuid("id").primaryKey().defaultRandom(),
2690
+ userId: text26("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
2691
+ subject: text26("subject").notNull(),
2692
+ amount: integer12("amount").notNull(),
2693
+ quotaIds: jsonb20("quota_ids").$type(),
2694
+ overageChargedCents: integer12("overage_charged_cents"),
2695
+ occurredAt: timestamp26("occurred_at").notNull().defaultNow(),
2696
+ metadata: jsonb20("metadata").$type()
2697
+ },
2698
+ (table) => [
2699
+ index23("idx_usage_records_user_feature").on(table.userId, table.subject),
2700
+ index23("idx_usage_records_occurred_at").on(table.occurredAt)
2701
+ ]
2702
+ );
2703
+ var planSubscriptions = pgTable26(
2704
+ "plan_subscriptions",
2705
+ {
2706
+ id: uuid("id").primaryKey().defaultRandom(),
2707
+ organizationId: text26("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
2708
+ planId: text26("plan_id").notNull().references(() => plans.id, { onDelete: "restrict" }),
2709
+ status: text26("status").notNull().$type(),
2710
+ version: integer12("version").notNull().default(1),
2711
+ currentPeriodStart: timestamp26("current_period_start").notNull(),
2712
+ currentPeriodEnd: timestamp26("current_period_end").notNull(),
2713
+ billingCycleAnchor: integer12("billing_cycle_anchor"),
2714
+ trialStart: timestamp26("trial_start"),
2715
+ trialEnd: timestamp26("trial_end"),
2716
+ renewalCount: integer12("renewal_count").notNull().default(0),
2717
+ lastRenewalAt: timestamp26("last_renewal_at"),
2718
+ gateway: text26("gateway"),
2719
+ externalSubscriptionId: text26("external_subscription_id"),
2720
+ initialTransactionId: uuid("initial_transaction_id").references(() => transactions.id, { onDelete: "set null" }),
2721
+ latestTransactionId: uuid("latest_transaction_id").references(() => transactions.id, { onDelete: "set null" }),
2722
+ canceledAt: timestamp26("canceled_at"),
2723
+ cancelReason: text26("cancel_reason"),
2724
+ cancelAtPeriodEnd: integer12("cancel_at_period_end").default(0),
2725
+ scheduledPlanId: text26("scheduled_plan_id").references(() => plans.id, { onDelete: "set null" }),
2726
+ scheduledChangeAt: timestamp26("scheduled_change_at"),
2727
+ metadata: jsonb20("metadata").$type(),
2728
+ createdAt: timestamp26("created_at").notNull().defaultNow(),
2729
+ updatedAt: timestamp26("updated_at").notNull().defaultNow()
2730
+ },
2731
+ (table) => [
2732
+ index23("idx_subscriptions_tenant").on(table.organizationId),
2733
+ index23("idx_subscriptions_status").on(table.status),
2734
+ index23("idx_subscriptions_period_end").on(table.currentPeriodEnd),
2735
+ uniqueIndex19("uq_subscriptions_external_id").on(table.externalSubscriptionId),
2736
+ uniqueIndex19("uq_subscriptions_tenant_plan_active").on(table.organizationId, table.planId).where(sql6`status IN ('active', 'trialing', 'past_due')`)
2737
+ ]
2738
+ );
2739
+ var tenantQuotas = pgTable26(
2740
+ "tenant_quotas",
2741
+ {
2742
+ id: uuid("id").primaryKey().defaultRandom(),
2743
+ organizationId: text26("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
2744
+ subject: text26("subject").notNull(),
2745
+ balance: integer12("balance").notNull(),
2746
+ priority: integer12("priority").notNull().default(100),
2747
+ expiresAt: timestamp26("expires_at"),
2748
+ sourceType: text26("source_type").notNull().$type(),
2749
+ sourceId: text26("source_id").notNull(),
2750
+ metadata: jsonb20("metadata").$type(),
2751
+ createdAt: timestamp26("created_at").notNull().defaultNow(),
2752
+ updatedAt: timestamp26("updated_at").notNull().defaultNow()
2753
+ },
2754
+ (table) => [
2755
+ index23("idx_tenant_quotas_tenant_feature").on(table.organizationId, table.subject),
2756
+ index23("idx_tenant_quotas_waterfall").on(
2757
+ table.organizationId,
2758
+ table.subject,
2759
+ table.balance,
2760
+ table.priority,
2761
+ table.expiresAt
2762
+ ),
2763
+ uniqueIndex19("uq_tenant_quotas_source").on(
2764
+ table.organizationId,
2765
+ table.subject,
2766
+ table.sourceType,
2767
+ table.sourceId
2768
+ )
2769
+ ]
2770
+ );
2771
+ var capabilitySchema = createInsertSchema24(capabilities);
2772
+ var planSchema = createInsertSchema24(plans);
2773
+ var planItemSchema = createInsertSchema24(planItems);
2774
+ var userQuotaSchema = createInsertSchema24(userQuotas);
2775
+ var walletSchema = createInsertSchema24(wallets);
2776
+ var transactionSchema = createInsertSchema24(transactions);
2777
+ var billingEventOutboxSchema = createInsertSchema24(billingEventOutbox);
2778
+ var usageRecordSchema = createInsertSchema24(usageRecords);
2779
+ var planSubscriptionSchema = createInsertSchema24(planSubscriptions);
2780
+ var tenantQuotaSchema = createInsertSchema24(tenantQuotas);
2781
+
2782
+ // src/schema/currency.ts
2783
+ import {
2784
+ pgTable as pgTable27,
2785
+ text as text27,
2786
+ timestamp as timestamp27,
2787
+ jsonb as jsonb21,
2788
+ uuid as uuid2,
2789
+ integer as integer13,
2790
+ index as index24,
2791
+ uniqueIndex as uniqueIndex20,
2792
+ numeric as numeric2
2793
+ } from "drizzle-orm/pg-core";
2794
+ import { sql as sql7 } from "drizzle-orm";
2795
+ import { createInsertSchema as createInsertSchema25 } from "drizzle-orm/zod";
2796
+ var currencies = pgTable27(
2797
+ "currencies",
2798
+ {
2799
+ id: uuid2("id").primaryKey().defaultRandom(),
2800
+ // FK to organization table
2801
+ organizationId: text27("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
2802
+ code: text27("code").notNull(),
2803
+ // ISO 4217 uppercase (USD, CNY, EUR)
2804
+ nameI18n: jsonb21("name_i18n").notNull().$type(),
2805
+ symbol: text27("symbol").notNull(),
2806
+ // '$', '¥', '€'
2807
+ decimalDigits: integer13("decimal_digits").notNull().default(2),
2808
+ isEnabled: integer13("is_enabled").notNull().default(1),
2809
+ isBase: integer13("is_base").notNull().default(0),
2810
+ currentRate: numeric2("current_rate", { precision: 18, scale: 8 }),
2811
+ createdBy: text27("created_by"),
2812
+ updatedBy: text27("updated_by"),
2813
+ createdAt: timestamp27("created_at").notNull().defaultNow(),
2814
+ updatedAt: timestamp27("updated_at").notNull().defaultNow()
2815
+ },
2816
+ (table) => [
2817
+ uniqueIndex20("uq_currencies_org_code").on(table.organizationId, table.code),
2818
+ uniqueIndex20("uq_currencies_org_base").on(table.organizationId).where(sql7`is_base = 1`),
2819
+ index24("idx_currencies_org").on(table.organizationId)
2820
+ ]
2821
+ );
2822
+ var exchangeRates = pgTable27(
2823
+ "exchange_rates",
2824
+ {
2825
+ id: uuid2("id").primaryKey().defaultRandom(),
2826
+ // FK to organization table
2827
+ organizationId: text27("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
2828
+ baseCurrency: text27("base_currency").notNull(),
2829
+ targetCurrency: text27("target_currency").notNull(),
2830
+ rate: numeric2("rate", { precision: 18, scale: 8 }).notNull(),
2831
+ source: text27("source").notNull().$type(),
2832
+ effectiveAt: timestamp27("effective_at").notNull(),
2833
+ expiresAt: timestamp27("expires_at"),
2834
+ createdBy: text27("created_by"),
2835
+ updatedBy: text27("updated_by"),
2836
+ createdAt: timestamp27("created_at").notNull().defaultNow(),
2837
+ updatedAt: timestamp27("updated_at").notNull().defaultNow()
2838
+ },
2839
+ (table) => [
2840
+ uniqueIndex20("uq_exchange_rates_org_pair_time").on(
2841
+ table.organizationId,
2842
+ table.baseCurrency,
2843
+ table.targetCurrency,
2844
+ table.effectiveAt
2845
+ ),
2846
+ index24("idx_exchange_rates_org").on(table.organizationId),
2847
+ index24("idx_exchange_rates_current").on(
2848
+ table.organizationId,
2849
+ table.baseCurrency,
2850
+ table.targetCurrency
2851
+ ).where(sql7`expires_at IS NULL`)
2852
+ ]
2853
+ );
2854
+ var currencySchema = createInsertSchema25(currencies);
2855
+ var exchangeRateSchema = createInsertSchema25(exchangeRates);
2856
+
2857
+ // src/schema/geo.ts
2858
+ import {
2859
+ pgTable as pgTable28,
2860
+ text as text28,
2861
+ timestamp as timestamp28,
2862
+ boolean as boolean15,
2863
+ integer as integer14,
2864
+ jsonb as jsonb22,
2865
+ index as index25,
2866
+ uniqueIndex as uniqueIndex21
2867
+ } from "drizzle-orm/pg-core";
2868
+ import { createInsertSchema as createInsertSchema26 } from "drizzle-orm/zod";
2869
+ import { z as z11 } from "zod/v4";
2870
+ var MARKET_REGIONS = [
2871
+ { code: "north_america", name: { "zh-CN": "\u5317\u7F8E", "en-US": "North America" }, sortOrder: 10 },
2872
+ { code: "europe", name: { "zh-CN": "\u6B27\u6D32", "en-US": "Europe" }, sortOrder: 20 },
2873
+ { code: "asia_pacific", name: { "zh-CN": "\u4E9A\u592A", "en-US": "Asia Pacific" }, sortOrder: 30 },
2874
+ { code: "latin_america", name: { "zh-CN": "\u62C9\u7F8E", "en-US": "Latin America" }, sortOrder: 40 },
2875
+ { code: "middle_east", name: { "zh-CN": "\u4E2D\u4E1C", "en-US": "Middle East" }, sortOrder: 50 },
2876
+ { code: "africa", name: { "zh-CN": "\u975E\u6D32", "en-US": "Africa" }, sortOrder: 60 },
2877
+ { code: "global", name: { "zh-CN": "\u5168\u7403", "en-US": "Global" }, sortOrder: 70 }
2878
+ ];
2879
+ var geoNameSchema = z11.record(z11.string(), z11.string()).refine((value) => Object.keys(value).length > 0, {
2880
+ message: "At least one localized name is required"
2881
+ });
2882
+ var countryCode2Schema = z11.string().length(2).regex(/^[A-Za-z]{2}$/, "Country code must be ISO 3166-1 alpha-2").transform((value) => value.toUpperCase());
2883
+ var countryCode3Schema = z11.string().length(3).regex(/^[A-Za-z]{3}$/, "Country code must be ISO 3166-1 alpha-3").transform((value) => value.toUpperCase());
2884
+ var subdivisionFullCodeSchema = z11.string().min(4).regex(/^[A-Za-z]{2}-[A-Za-z0-9]+$/, "Subdivision code must look like ISO 3166-2").transform((value) => value.toUpperCase());
2885
+ var geoCountries = pgTable28(
2886
+ "geo_countries",
2887
+ {
2888
+ id: text28("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
2889
+ code2: text28("code2").notNull(),
2890
+ code3: text28("code3"),
2891
+ numericCode: text28("numeric_code"),
2892
+ name: jsonb22("name").notNull().$type(),
2893
+ officialName: jsonb22("official_name").$type(),
2894
+ flags: jsonb22("flags").$type(),
2895
+ currencyCode: text28("currency_code"),
2896
+ languageCode: text28("language_code"),
2897
+ locale: text28("locale"),
2898
+ phoneCode: text28("phone_code"),
2899
+ isSupported: boolean15("is_supported").notNull().default(true),
2900
+ sortOrder: integer14("sort_order").notNull().default(0),
2901
+ createdAt: timestamp28("created_at").notNull().defaultNow(),
2902
+ updatedAt: timestamp28("updated_at").notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
2903
+ },
2904
+ (table) => [
2905
+ uniqueIndex21("geo_countries_code2_uidx").on(table.code2),
2906
+ uniqueIndex21("geo_countries_code3_uidx").on(table.code3),
2907
+ index25("geo_countries_supported_sort_idx").on(table.isSupported, table.sortOrder)
2908
+ ]
2909
+ );
2910
+ var geoSubdivisions = pgTable28(
2911
+ "geo_subdivisions",
2912
+ {
2913
+ id: text28("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
2914
+ countryCode2: text28("country_code2").notNull().references(() => geoCountries.code2, { onDelete: "cascade" }),
2915
+ code: text28("code").notNull(),
2916
+ fullCode: text28("full_code").notNull(),
2917
+ name: jsonb22("name").notNull().$type(),
2918
+ type: text28("type"),
2919
+ isSupported: boolean15("is_supported").notNull().default(true),
2920
+ sortOrder: integer14("sort_order").notNull().default(0),
2921
+ createdAt: timestamp28("created_at").notNull().defaultNow(),
2922
+ updatedAt: timestamp28("updated_at").notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
2923
+ },
2924
+ (table) => [
2925
+ uniqueIndex21("geo_subdivisions_full_code_uidx").on(table.fullCode),
2926
+ uniqueIndex21("geo_subdivisions_country_code_uidx").on(table.countryCode2, table.code),
2927
+ index25("geo_subdivisions_country_sort_idx").on(table.countryCode2, table.sortOrder),
2928
+ index25("geo_subdivisions_country_supported_idx").on(table.countryCode2, table.isSupported)
2929
+ ]
2930
+ );
2931
+ var geoCountrySchema = createInsertSchema26(geoCountries, {
2932
+ code2: () => countryCode2Schema,
2933
+ code3: () => countryCode3Schema.optional(),
2934
+ name: () => geoNameSchema,
2935
+ officialName: () => geoNameSchema.nullish()
2936
+ });
2937
+ var geoSubdivisionSchema = createInsertSchema26(geoSubdivisions, {
2938
+ countryCode2: () => countryCode2Schema,
2939
+ fullCode: () => subdivisionFullCodeSchema,
2940
+ name: () => geoNameSchema
2941
+ });
2942
+ var getGeoCountryQuery = z11.object({
2943
+ code2: countryCode2Schema,
2944
+ locale: localeSchema.optional()
2945
+ });
2946
+ var listGeoCountriesQuery = paginationSchema.partial().extend({
2947
+ limit: z11.number().int().min(1).max(300).default(300),
2948
+ offset: z11.number().int().min(0).default(0),
2949
+ locale: localeSchema.optional(),
2950
+ supportedOnly: z11.boolean().default(true)
2951
+ });
2952
+ var getGeoSubdivisionQuery = z11.object({
2953
+ fullCode: subdivisionFullCodeSchema,
2954
+ locale: localeSchema.optional()
2955
+ });
2956
+ var listGeoSubdivisionsQuery = paginationSchema.partial().extend({
2957
+ limit: z11.number().int().min(1).max(500).default(500),
2958
+ offset: z11.number().int().min(0).default(0),
2959
+ countryCode2: countryCode2Schema,
2960
+ locale: localeSchema.optional(),
2961
+ supportedOnly: z11.boolean().default(true)
2962
+ });
2963
+ var listMarketRegionsQuery = paginationSchema.partial().extend({
2964
+ limit: z11.number().int().min(1).max(100).default(100),
2965
+ offset: z11.number().int().min(0).default(0),
2966
+ locale: localeSchema.optional()
2967
+ });
2968
+
2969
+ // src/schema/webhooks.ts
2970
+ import {
2971
+ pgTable as pgTable29,
2972
+ text as text29,
2973
+ timestamp as timestamp29,
2974
+ boolean as boolean16,
2975
+ jsonb as jsonb23,
2976
+ integer as integer15,
2977
+ index as index26,
2978
+ uniqueIndex as uniqueIndex22
2979
+ } from "drizzle-orm/pg-core";
2980
+ import { createInsertSchema as createInsertSchema27 } from "drizzle-orm/zod";
2981
+ var webhookEndpoints = pgTable29(
2982
+ "webhook_endpoints",
2983
+ {
2984
+ id: text29("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
2985
+ // FK to organization table
2986
+ organizationId: text29("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
2987
+ url: text29("url").notNull(),
2988
+ secret: text29("secret").notNull(),
2989
+ events: text29("events").array().notNull().$defaultFn(() => []),
2990
+ enabled: boolean16("enabled").notNull().default(true),
2991
+ retryPolicy: jsonb23("retry_policy").notNull().$type().default({ attempts: 5, backoffMs: 1e3 }),
2992
+ createdAt: timestamp29("created_at", { withTimezone: true }).notNull().defaultNow(),
2993
+ updatedAt: timestamp29("updated_at", { withTimezone: true }).notNull().defaultNow()
2994
+ },
2995
+ (table) => [
2996
+ index26("idx_webhook_endpoints_tenant").on(table.organizationId),
2997
+ index26("idx_webhook_endpoints_enabled").on(table.organizationId, table.enabled),
2998
+ uniqueIndex22("uq_webhook_endpoints_tenant_url").on(table.organizationId, table.url)
2999
+ ]
3000
+ );
3001
+ var webhookDeliveries = pgTable29(
3002
+ "webhook_deliveries",
3003
+ {
3004
+ id: text29("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
3005
+ // FK to organization table
3006
+ organizationId: text29("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
3007
+ // FK to webhookEndpoints table
3008
+ endpointId: text29("endpoint_id").notNull().references(() => webhookEndpoints.id, { onDelete: "cascade" }),
3009
+ eventType: text29("event_type").notNull(),
3010
+ payload: jsonb23("payload").notNull().$type(),
3011
+ status: text29("status").notNull().$type().default("pending"),
3012
+ attempts: integer15("attempts").notNull().default(0),
3013
+ lastAttemptAt: timestamp29("last_attempt_at", { withTimezone: true }),
3014
+ responseCode: integer15("response_code"),
3015
+ error: text29("error"),
3016
+ dedupeKey: text29("dedupe_key").notNull(),
3017
+ createdAt: timestamp29("created_at", { withTimezone: true }).notNull().defaultNow(),
3018
+ updatedAt: timestamp29("updated_at", { withTimezone: true }).notNull().defaultNow()
3019
+ },
3020
+ (table) => [
3021
+ index26("idx_webhook_deliveries_endpoint").on(table.endpointId),
3022
+ index26("idx_webhook_deliveries_tenant_status").on(table.organizationId, table.status),
3023
+ uniqueIndex22("idx_webhook_deliveries_dedupe").on(table.dedupeKey),
3024
+ index26("idx_webhook_deliveries_created").on(table.createdAt)
3025
+ ]
3026
+ );
3027
+ var webhookOutbox = pgTable29(
3028
+ "webhook_outbox",
3029
+ {
3030
+ id: text29("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
3031
+ // FK to organization table
3032
+ organizationId: text29("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
3033
+ // FK to webhookEndpoints table
3034
+ endpointId: text29("endpoint_id").notNull().references(() => webhookEndpoints.id, { onDelete: "cascade" }),
3035
+ eventType: text29("event_type").notNull(),
3036
+ payload: jsonb23("payload").notNull().$type(),
3037
+ dedupeKey: text29("dedupe_key").notNull(),
3038
+ availableAt: timestamp29("available_at", { withTimezone: true }).notNull().defaultNow(),
3039
+ lockedAt: timestamp29("locked_at", { withTimezone: true }),
3040
+ lockToken: text29("lock_token"),
3041
+ createdAt: timestamp29("created_at", { withTimezone: true }).notNull().defaultNow()
3042
+ },
3043
+ (table) => [
3044
+ index26("idx_webhook_outbox_available").on(table.availableAt),
3045
+ uniqueIndex22("idx_webhook_outbox_dedupe").on(table.dedupeKey),
3046
+ index26("idx_webhook_outbox_tenant").on(table.organizationId)
3047
+ ]
3048
+ );
3049
+ var webhookEndpointSchema = createInsertSchema27(webhookEndpoints);
3050
+ var webhookDeliverySchema = createInsertSchema27(webhookDeliveries);
3051
+ var webhookOutboxSchema = createInsertSchema27(webhookOutbox);
3052
+
3053
+ // src/schema/scheduled-tasks.ts
3054
+ import {
3055
+ pgTable as pgTable30,
3056
+ text as text30,
3057
+ timestamp as timestamp30,
3058
+ jsonb as jsonb24,
3059
+ boolean as boolean17,
3060
+ integer as integer16,
3061
+ real,
3062
+ index as index27
3063
+ } from "drizzle-orm/pg-core";
3064
+ import { createInsertSchema as createInsertSchema28 } from "drizzle-orm/zod";
3065
+ var scheduledTasks = pgTable30(
3066
+ "scheduled_tasks",
3067
+ {
3068
+ id: text30("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
3069
+ // FK to organization table
3070
+ organizationId: text30("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
3071
+ name: text30("name").notNull(),
3072
+ description: text30("description"),
3073
+ cronExpression: text30("cron_expression").notNull(),
3074
+ timezone: text30("timezone").notNull().default("UTC"),
3075
+ handlerType: text30("handler_type").$type().notNull(),
3076
+ handlerConfig: jsonb24("handler_config").notNull().$type(),
3077
+ payload: jsonb24("payload"),
3078
+ enabled: boolean17("enabled").notNull().default(true),
3079
+ lastRunAt: timestamp30("last_run_at", { withTimezone: true }),
3080
+ lastStatus: text30("last_status").$type(),
3081
+ nextRunAt: timestamp30("next_run_at", { withTimezone: true }).notNull(),
3082
+ consecutiveFailures: integer16("consecutive_failures").notNull().default(0),
3083
+ maxRetries: integer16("max_retries").notNull().default(3),
3084
+ retryBackoffMultiplier: real("retry_backoff_multiplier").notNull().default(2),
3085
+ providerId: text30("provider_id").notNull().default("builtin"),
3086
+ providerMetadata: jsonb24("provider_metadata"),
3087
+ createdBy: text30("created_by").notNull(),
3088
+ createdByType: text30("created_by_type").$type().notNull(),
3089
+ createdAt: timestamp30("created_at", { withTimezone: true }).notNull().defaultNow(),
3090
+ updatedAt: timestamp30("updated_at", { withTimezone: true }).notNull().defaultNow()
3091
+ },
3092
+ (table) => [
3093
+ index27("scheduled_tasks_organization_idx").on(table.organizationId),
3094
+ index27("scheduled_tasks_next_run_idx").on(table.nextRunAt, table.enabled),
3095
+ index27("scheduled_tasks_provider_idx").on(table.providerId)
3096
+ ]
3097
+ );
3098
+ var taskExecutions = pgTable30(
3099
+ "task_executions",
3100
+ {
3101
+ id: text30("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
3102
+ // FK to scheduledTasks table
3103
+ taskId: text30("task_id").notNull().references(() => scheduledTasks.id, { onDelete: "cascade" }),
3104
+ // FK to organization table
3105
+ organizationId: text30("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
3106
+ scheduledAt: timestamp30("scheduled_at", { withTimezone: true }).notNull(),
3107
+ startedAt: timestamp30("started_at", { withTimezone: true }).notNull(),
3108
+ completedAt: timestamp30("completed_at", { withTimezone: true }),
3109
+ status: text30("status").$type().notNull(),
3110
+ attempt: integer16("attempt").notNull().default(1),
3111
+ result: jsonb24("result"),
3112
+ error: jsonb24("error").$type(),
3113
+ lockKey: text30("lock_key").notNull(),
3114
+ workerId: text30("worker_id").notNull()
3115
+ },
3116
+ (table) => [
3117
+ index27("task_executions_task_idx").on(table.taskId, table.startedAt),
3118
+ index27("task_executions_organization_idx").on(table.organizationId),
3119
+ index27("task_executions_status_idx").on(table.status)
3120
+ ]
3121
+ );
3122
+ var schedulerProviders = pgTable30(
3123
+ "scheduler_providers",
3124
+ {
3125
+ id: text30("id").primaryKey(),
3126
+ name: text30("name").notNull(),
3127
+ version: text30("version").notNull(),
3128
+ pluginId: text30("plugin_id"),
3129
+ capabilities: jsonb24("capabilities").notNull().$type(),
3130
+ status: text30("status").$type().notNull(),
3131
+ registeredAt: timestamp30("registered_at", { withTimezone: true }).notNull().defaultNow(),
3132
+ unregisteredAt: timestamp30("unregistered_at", { withTimezone: true })
3133
+ },
3134
+ (table) => [
3135
+ index27("scheduler_providers_plugin_idx").on(table.pluginId),
3136
+ index27("scheduler_providers_status_idx").on(table.status)
3137
+ ]
3138
+ );
3139
+ var scheduledTaskSchema = createInsertSchema28(scheduledTasks);
3140
+ var taskExecutionSchema = createInsertSchema28(taskExecutions);
3141
+ var schedulerProviderSchema = createInsertSchema28(schedulerProviders);
3142
+
3143
+ export {
3144
+ user,
3145
+ session,
3146
+ CREDENTIAL_ACCOUNT_ISSUER,
3147
+ account,
3148
+ verification,
3149
+ organization,
3150
+ member,
3151
+ invitation,
3152
+ apikey,
3153
+ userSchema,
3154
+ sessionSchema,
3155
+ accountSchema,
3156
+ verificationSchema,
3157
+ organizationSchema,
3158
+ memberSchema,
3159
+ invitationSchema,
3160
+ apikeySchema,
3161
+ updateProfileMutation,
3162
+ team,
3163
+ teamMember,
3164
+ teamSchema,
3165
+ teamMemberSchema,
3166
+ relationship,
3167
+ relationshipSchema,
3168
+ I18N_MESSAGE_FORMATS,
3169
+ i18nLanguages,
3170
+ i18nMessages,
3171
+ i18nBundleVersions,
3172
+ localeSchema,
3173
+ translationsObjectSchema,
3174
+ i18nDirectionSchema,
3175
+ i18nMessageTypeSchema,
3176
+ i18nMessageSourceSchema,
3177
+ i18nMessageFormatSchema,
3178
+ i18nLanguageSchema,
3179
+ i18nMessageSchema,
3180
+ getI18nMessagesQuery,
3181
+ getI18nBundlesQuery,
3182
+ i18nBundleSchema,
3183
+ getI18nBundlesResultSchema,
3184
+ listI18nLanguagesQuery,
3185
+ listI18nMessagesQuery,
3186
+ setDefaultLanguageMutation,
3187
+ batchUpdateMessagesMutation,
3188
+ roles,
3189
+ roleSchema,
3190
+ rolePermissions,
3191
+ rolePermissionSchema,
3192
+ permissions,
3193
+ permissionSchema,
3194
+ ROLE_PERMISSIONS,
3195
+ menus,
3196
+ SYS_INBOX_CODE,
3197
+ menuSchema,
3198
+ getMenuQuery,
3199
+ listMenusQuery,
3200
+ listAllMenusQuery,
3201
+ deleteMenuMutation,
3202
+ toggleMenuVisibilityMutation,
3203
+ createMenuSchema,
3204
+ updateMenuSchema,
3205
+ updateMenuMutation,
3206
+ PLUGIN_MARKETPLACE_STATES,
3207
+ PLUGIN_TRUST_LEVELS,
3208
+ PLUGIN_INSTALL_OPERATIONS,
3209
+ PLUGIN_INSTALL_SOURCES,
3210
+ PLUGIN_INSTALL_JOB_STATUSES,
3211
+ plugins,
3212
+ pluginInstances,
3213
+ pluginCatalogReleases,
3214
+ pluginRegistrySyncState,
3215
+ pluginInstallJobs,
3216
+ pluginConfigs,
3217
+ pluginSchema,
3218
+ pluginInstanceSchema,
3219
+ pluginCatalogReleaseSchema,
3220
+ pluginInstallJobSchema,
3221
+ pluginConfigSchema,
3222
+ listPluginCatalogQuery,
3223
+ installPluginFromRegistryMutation,
3224
+ createPluginUploadMutation,
3225
+ appendPluginUploadMutation,
3226
+ completePluginUploadMutation,
3227
+ getPluginInstallJobQuery,
3228
+ uninstallPluginFromInstanceMutation,
3229
+ rollbackPluginInstallMutation,
3230
+ pluginMigrations,
3231
+ pluginMigrationSchema,
3232
+ ENTITY_EXTENSION_VALUE_TYPES,
3233
+ ENTITY_EXTENSION_PROJECTION_STATUSES,
3234
+ extProjection,
3235
+ ACTION_JOURNAL_STATUSES,
3236
+ ACTION_JOURNAL_ACTIVE_STATUSES,
3237
+ actionExecutionJournal,
3238
+ actionExecutionOutbox,
3239
+ settings,
3240
+ settingSchemas,
3241
+ settingScopeSchema,
3242
+ settingValueTypeSchema,
3243
+ settingSchema,
3244
+ settingSchemaSchema,
3245
+ getSettingQuery,
3246
+ listSettingsQuery,
3247
+ setSettingMutation,
3248
+ deleteSettingMutation,
3249
+ featureFlags,
3250
+ featureFlagOverrides,
3251
+ flagConditionSchema,
3252
+ featureFlagSchema,
3253
+ featureFlagOverrideSchema,
3254
+ checkFeatureFlagQuery,
3255
+ getFeatureFlagQuery,
3256
+ listFeatureFlagsQuery,
3257
+ listFlagOverridesQuery,
3258
+ updateFeatureFlagMutation,
3259
+ deleteFeatureFlagMutation,
3260
+ setFlagOverrideMutation,
3261
+ removeFlagOverrideMutation,
3262
+ media,
3263
+ mediaInsertSchema,
3264
+ mediaSelectSchema,
3265
+ importMediaFromUrlMutation,
3266
+ WEB_PAGE_STATUSES,
3267
+ WEB_DOMAIN_STATUSES,
3268
+ WEB_DOMAIN_CERTIFICATE_STATUSES,
3269
+ WEB_PAGE_RESERVED_PATHS,
3270
+ WEB_PAGE_RESERVED_PREFIXES,
3271
+ webPages,
3272
+ webDomains,
3273
+ webPageSchema,
3274
+ webPageSelectSchema,
3275
+ webDomainSchema,
3276
+ webDomainSelectSchema,
3277
+ webDomainHostnameSchema,
3278
+ webPagePathSchema,
3279
+ webDesignDocumentSchema,
3280
+ createWebPageMutation,
3281
+ updateWebPageMutation,
3282
+ getWebPageDocumentQuery,
3283
+ saveWebPageDocumentMutation,
3284
+ publishWebPageMutation,
3285
+ createWebDomainMutation,
3286
+ getWebDomainQuery,
3287
+ verifyWebDomainMutation,
3288
+ requestWebDomainCertificateMutation,
3289
+ updateWebDomainCertificateStatusMutation,
3290
+ setPrimaryWebDomainMutation,
3291
+ disableWebDomainMutation,
3292
+ deleteWebDomainMutation,
3293
+ WEB_THEME_REVISION_STATUSES,
3294
+ WEB_THEME_SELECTION_STATUSES,
3295
+ webThemeRevisions,
3296
+ webThemeSelections,
3297
+ webThemeHomeTargetSchema,
3298
+ webThemeAdapterSelectionSchema,
3299
+ webThemeAdapterConfigSchema,
3300
+ webThemeRevisionSchema,
3301
+ webThemeRevisionSelectSchema,
3302
+ webThemeSelectionSchema,
3303
+ webThemeSelectionSelectSchema,
3304
+ getWebThemeQuery,
3305
+ setWebThemeEnabledMutation,
3306
+ getWebThemeRevisionQuery,
3307
+ listWebThemeRevisionsQuery,
3308
+ saveWebThemeDraftMutation,
3309
+ activateWebThemeMutation,
3310
+ activateWebThemeRevisionMutation,
3311
+ publishWebThemeDraftMutation,
3312
+ rollbackWebThemeRevisionMutation,
3313
+ issueWebThemePreviewMutation,
3314
+ recoverWebThemeMutation,
3315
+ NotificationTypeEnum,
3316
+ notifications,
3317
+ notificationSchema,
3318
+ notificationTemplates,
3319
+ notificationTemplateSchema,
3320
+ notificationChannels,
3321
+ notificationChannelSchema,
3322
+ notificationPreferences,
3323
+ notificationPreferenceSchema,
3324
+ auditLogs,
3325
+ auditLogSchema,
3326
+ auditEvents,
3327
+ auditEventSchema,
3328
+ auditEventsArchive,
3329
+ auditLogsArchive,
3330
+ auditEventsArchiveSchema,
3331
+ auditLogsArchiveSchema,
3332
+ ScopeType,
3333
+ AccessLevel,
3334
+ entityOwnerships,
3335
+ ownershipAuditLog,
3336
+ entityOwnershipSchema,
3337
+ ownershipAuditLogSchema,
3338
+ capabilities,
3339
+ plans,
3340
+ planItems,
3341
+ userQuotas,
3342
+ wallets,
3343
+ transactions,
3344
+ billingEventOutbox,
3345
+ usageRecords,
3346
+ planSubscriptions,
3347
+ tenantQuotas,
3348
+ capabilitySchema,
3349
+ planSchema,
3350
+ planItemSchema,
3351
+ userQuotaSchema,
3352
+ walletSchema,
3353
+ transactionSchema,
3354
+ billingEventOutboxSchema,
3355
+ usageRecordSchema,
3356
+ planSubscriptionSchema,
3357
+ tenantQuotaSchema,
3358
+ currencies,
3359
+ exchangeRates,
3360
+ currencySchema,
3361
+ exchangeRateSchema,
3362
+ MARKET_REGIONS,
3363
+ geoNameSchema,
3364
+ countryCode2Schema,
3365
+ countryCode3Schema,
3366
+ subdivisionFullCodeSchema,
3367
+ geoCountries,
3368
+ geoSubdivisions,
3369
+ geoCountrySchema,
3370
+ geoSubdivisionSchema,
3371
+ getGeoCountryQuery,
3372
+ listGeoCountriesQuery,
3373
+ getGeoSubdivisionQuery,
3374
+ listGeoSubdivisionsQuery,
3375
+ listMarketRegionsQuery,
3376
+ webhookEndpoints,
3377
+ webhookDeliveries,
3378
+ webhookOutbox,
3379
+ webhookEndpointSchema,
3380
+ webhookDeliverySchema,
3381
+ webhookOutboxSchema,
3382
+ scheduledTasks,
3383
+ taskExecutions,
3384
+ schedulerProviders,
3385
+ scheduledTaskSchema,
3386
+ taskExecutionSchema,
3387
+ schedulerProviderSchema,
3388
+ schema_exports
3389
+ };
3390
+ //# sourceMappingURL=chunk-3TTVLSF5.js.map