@infuro/cms-core 1.0.34 → 1.0.35

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 (158) hide show
  1. package/README.md +13 -0
  2. package/dist/OrderTrackPage-W3J6WIG2.js +426 -0
  3. package/dist/OrderTrackPage-Z6FCJQYY.cjs +428 -0
  4. package/dist/admin.cjs +34329 -20923
  5. package/dist/admin.d.cts +186 -9
  6. package/dist/admin.d.ts +186 -9
  7. package/dist/admin.js +34140 -20829
  8. package/dist/api.cjs +120 -17515
  9. package/dist/api.d.cts +633 -3
  10. package/dist/api.d.ts +633 -3
  11. package/dist/api.js +14 -17528
  12. package/dist/auth.cjs +192 -1034
  13. package/dist/auth.d.cts +194 -51
  14. package/dist/auth.d.ts +194 -51
  15. package/dist/auth.js +4 -966
  16. package/dist/chunk-2XE4X74C.js +29602 -0
  17. package/dist/chunk-3DZRIZOD.cjs +52 -0
  18. package/dist/chunk-3KPNTQBV.cjs +620 -0
  19. package/dist/chunk-46GKADYE.cjs +84 -0
  20. package/dist/chunk-4TRPKBKO.js +589 -0
  21. package/dist/chunk-5ELSW2UP.js +150 -0
  22. package/dist/chunk-6KPQWRFW.js +171 -0
  23. package/dist/chunk-7NMT3GBR.cjs +29 -0
  24. package/dist/chunk-7YIBMQDR.cjs +86 -0
  25. package/dist/chunk-BGJAV67S.cjs +29710 -0
  26. package/dist/chunk-CNTSLED2.cjs +559 -0
  27. package/dist/chunk-CRFV5WJK.js +16 -0
  28. package/dist/chunk-D5FBNKQM.cjs +104 -0
  29. package/dist/chunk-EF2JBPDM.js +114 -0
  30. package/dist/chunk-EQPITOP6.js +543 -0
  31. package/dist/chunk-GO7PPYNU.js +76 -0
  32. package/dist/chunk-HF3L2GIT.cjs +194 -0
  33. package/dist/chunk-J7XHLOLO.js +830 -0
  34. package/dist/chunk-JBRR5UYL.js +87 -0
  35. package/dist/chunk-JC6DLWTE.js +21 -0
  36. package/dist/chunk-JHF4YYRC.cjs +188 -0
  37. package/dist/chunk-JXF23MPG.js +25 -0
  38. package/dist/chunk-MQBT33IV.js +48 -0
  39. package/dist/chunk-N44BJZ4C.cjs +123 -0
  40. package/dist/chunk-OOTLNH63.cjs +18 -0
  41. package/dist/chunk-PAMVINEX.cjs +577 -0
  42. package/dist/chunk-PNOKNSG2.cjs +222 -0
  43. package/dist/chunk-QM733NUK.js +186 -0
  44. package/dist/chunk-R73BKDRO.cjs +90 -0
  45. package/dist/chunk-SHUYVCID.js +4 -0
  46. package/dist/chunk-SYBOCAWB.js +97 -0
  47. package/dist/chunk-TDV6EJHV.js +192 -0
  48. package/dist/chunk-TFUOHI37.cjs +839 -0
  49. package/dist/chunk-TIAEXJLI.cjs +182 -0
  50. package/dist/chunk-UPLVMVRX.cjs +23 -0
  51. package/dist/chunk-USNT2KNT.cjs +6 -0
  52. package/dist/chunk-WEMDMVHQ.js +216 -0
  53. package/dist/chunk-XDSNZUW7.js +564 -0
  54. package/dist/chunk-XQ3QUHWR.cjs +83 -0
  55. package/dist/chunk-XW5ATPRW.cjs +155 -0
  56. package/dist/chunk-ZQ4X6OAU.js +82 -0
  57. package/dist/chunk-ZSVCP6N3.js +83 -0
  58. package/dist/cli.cjs +103 -84
  59. package/dist/cli.js +62 -27
  60. package/dist/email-FKR4FXFI.js +5 -0
  61. package/dist/email-KVKVPNCL.cjs +58 -0
  62. package/dist/email-queue-CGZBVVAS.js +2 -0
  63. package/dist/email-queue-TPZWLTIV.cjs +23 -0
  64. package/dist/erp-config-enabled-CUMQ6N2V.cjs +11 -0
  65. package/dist/erp-config-enabled-T37X7T34.js +2 -0
  66. package/dist/erp-order-invoice-3YISSOWW.js +3 -0
  67. package/dist/erp-order-invoice-ZR5F2KTA.cjs +12 -0
  68. package/dist/event-order-defaults-6E543227.js +2 -0
  69. package/dist/event-order-defaults-DUGDVGJI.cjs +39 -0
  70. package/dist/event-order-notifications-5GSAOYVS.cjs +27 -0
  71. package/dist/event-order-notifications-IIIF23D5.js +10 -0
  72. package/dist/hooks.cjs +259 -132
  73. package/dist/hooks.d.cts +42 -1
  74. package/dist/hooks.d.ts +42 -1
  75. package/dist/hooks.js +234 -91
  76. package/dist/index.cjs +3884 -22307
  77. package/dist/index.d.cts +2203 -772
  78. package/dist/index.d.ts +2203 -772
  79. package/dist/index.js +2871 -22064
  80. package/dist/interpolate-WAKPN56R.cjs +11 -0
  81. package/dist/interpolate-WDUWDF3I.js +2 -0
  82. package/dist/layout-36UFTHC5.cjs +11 -0
  83. package/dist/layout-AOBN26XG.js +2 -0
  84. package/dist/migrations/1779400000000-ConvertStatusToEnum.ts +142 -0
  85. package/dist/migrations/1779400000000-SeedDefaultCurrencies.ts +33 -0
  86. package/dist/migrations/1779500000000-VendorRolesAndPermissions.ts +102 -0
  87. package/dist/migrations/1779600000000-VendorRegistrationProfile.ts +52 -0
  88. package/dist/migrations/1779700000000-CollectionIsCatalog.ts +22 -0
  89. package/dist/migrations/1779710000000-CollectionPlatformCatalog.ts +60 -0
  90. package/dist/migrations/1779720000000-ProductCategoryPlatformCatalog.ts +157 -0
  91. package/dist/migrations/1779800000000-EventsAndEventProducts.ts +173 -0
  92. package/dist/migrations/1779810000000-BackfillVendorRoleEventsPermissions.ts +38 -0
  93. package/dist/migrations/1779820000000-FixProductsCategoryForeignKey.ts +70 -0
  94. package/dist/migrations/1779830000000-ProductTitleColumn.ts +32 -0
  95. package/dist/migrations/1779840000000-EventAboutAndVisibilityFields.ts +34 -0
  96. package/dist/migrations/1779850000000-EventCityCountrySplit.ts +43 -0
  97. package/dist/migrations/1779860000000-CreateCombos.ts +140 -0
  98. package/dist/migrations/1780100000000-OrderAttendeesEventId.ts +55 -0
  99. package/dist/migrations/1780110000000-EventContactFormId.ts +49 -0
  100. package/dist/migrations/1780130000000-ProductVariants.ts +54 -0
  101. package/dist/migrations/1780140000000-EventManagementEnhancements.ts +44 -0
  102. package/dist/migrations/1780160000000-EventRegistrationGstProductContactForm.ts +79 -0
  103. package/dist/migrations/1780170000000-ComboCurrencyPrices.ts +20 -0
  104. package/dist/migrations/1781110000000-VendorOwnerCombosPermission.ts +38 -0
  105. package/dist/migrations/1781120000000-RefundPoliciesAndRequests.ts +225 -0
  106. package/dist/migrations/1781130000000-CreateAttendees.ts +44 -0
  107. package/dist/migrations/1781140000000-EventOrderNotifications.ts +29 -0
  108. package/dist/migrations/1781150000000-EventNamedLists.ts +28 -0
  109. package/dist/migrations/1781160000000-RefundPolicyEventTiers.ts +27 -0
  110. package/dist/migrations/1781170000000-EventRefundPolicy.ts +42 -0
  111. package/dist/migrations/1781180000000-RemoveCartItemsUniqueConstraint.ts +15 -0
  112. package/dist/migrations/1781190000000-RenameProductTaxesToProductConfig.ts +84 -0
  113. package/dist/migrations/1781200000000-VendorOwnerProductConfigPermissions.ts +51 -0
  114. package/dist/migrations/1781210000000-VendorRoleProductConfigPermissions.ts +46 -0
  115. package/dist/migrations/helpers/vendor-role-seed.ts +243 -0
  116. package/dist/paid-order-erp-3USEG6WL.js +3 -0
  117. package/dist/paid-order-erp-FSQ3GSXE.cjs +12 -0
  118. package/dist/pg-boss-service-4XF2TQ2E.js +2 -0
  119. package/dist/pg-boss-service-L6MTF4EQ.cjs +15 -0
  120. package/dist/razorpay-KLO2KNCB.js +49 -0
  121. package/dist/razorpay-U23LGY72.cjs +56 -0
  122. package/dist/rbac-debug-db-D7ME7QUY.cjs +35 -0
  123. package/dist/rbac-debug-db-MTCTVNNM.js +33 -0
  124. package/dist/sms-defaults-2NL24H57.js +2 -0
  125. package/dist/sms-defaults-KCOPKQBA.cjs +19 -0
  126. package/dist/stripe-4FD27QVJ.js +51 -0
  127. package/dist/stripe-VU6OEG2D.cjs +57 -0
  128. package/dist/theme.cjs +31 -59
  129. package/dist/theme.d.cts +78 -3
  130. package/dist/theme.d.ts +78 -3
  131. package/dist/theme.js +23 -20
  132. package/dist/vendor-invite-status-77O7ZQ3U.cjs +19 -0
  133. package/dist/vendor-invite-status-PWJ3DE76.js +2 -0
  134. package/dist/whatsapp-queue-3DXA4MXU.js +2 -0
  135. package/dist/whatsapp-queue-KG65MXD5.cjs +15 -0
  136. package/package.json +147 -142
  137. package/dist/admin.cjs.map +0 -1
  138. package/dist/admin.js.map +0 -1
  139. package/dist/api.cjs.map +0 -1
  140. package/dist/api.js.map +0 -1
  141. package/dist/auth.cjs.map +0 -1
  142. package/dist/auth.js.map +0 -1
  143. package/dist/cli.cjs.map +0 -1
  144. package/dist/cli.js.map +0 -1
  145. package/dist/config-DJ5CmQvS.d.cts +0 -8
  146. package/dist/config-DJ5CmQvS.d.ts +0 -8
  147. package/dist/hooks.cjs.map +0 -1
  148. package/dist/hooks.js.map +0 -1
  149. package/dist/index-Bf5GO8fu.d.cts +0 -583
  150. package/dist/index-DOiJuMQA.d.ts +0 -583
  151. package/dist/index.cjs.map +0 -1
  152. package/dist/index.js.map +0 -1
  153. package/dist/theme.cjs.map +0 -1
  154. package/dist/theme.js.map +0 -1
  155. package/dist/types-DCVaXlPV.d.cts +0 -78
  156. package/dist/types-DCVaXlPV.d.ts +0 -78
  157. package/dist/vendor-scope-DTYhJk_I.d.cts +0 -129
  158. package/dist/vendor-scope-DTYhJk_I.d.ts +0 -129
package/dist/index.d.ts CHANGED
@@ -1,18 +1,10 @@
1
- import { e as CompanyDetails, T as TemplateContext, h as EmailTemplateResult, g as EmailTemplateName, O as OrderPlacedLineItem, o as StorageService, i as EntityMap$2 } from './index-DOiJuMQA.js';
2
- export { A as AnalyticsHandlerConfig, a as AuthHandlersConfig, B as BlogBySlugConfig, C as ChangePasswordConfig, b as ChatPublicConfig, c as CmsApiHandlerConfig, d as CmsGetter, f as CrudHandlerOptions, D as DashboardStatsConfig, E as EcommerceAnalyticsConfig, F as ForgotPasswordConfig, j as FormBySlugConfig, G as GetPublicSettingsGroupConfig, k as GetPublicSettingsGroupDataSource, I as InviteAcceptConfig, J as JobScheduleApiConfig, L as LlmAgentKnowledgeApiConfig, l as LlmAgentValidationRulesJson, P as ParsedLlmAgentValidation, S as SetPasswordConfig, m as SettingsApiConfig, n as SocialLinkItem, p as StorefrontApiConfig, q as StorefrontOtpFlags, U as UploadHandlerConfig, r as UserAuthApiConfig, s as UserAvatarConfig, t as UserProfileConfig, u as UsersApiConfig, V as VendorOnboardHandlersConfig, v as VendorOwnerActivation, w as createAnalyticsHandlers, x as createBlogBySlugHandler, y as createChangePasswordHandler, z as createCmsApiHandler, H as createCrudByIdHandler, K as createCrudHandler, M as createDashboardStatsHandler, N as createEcommerceAnalyticsHandler, Q as createForgotPasswordHandler, R as createFormBySlugHandler, W as createInviteAcceptHandler, X as createJobScheduleHandlers, Y as createLlmAgentKnowledgeHandlers, Z as createMediaZipExtractHandler, _ as createSetPasswordHandler, $ as createSettingsApiHandlers, a0 as createStorefrontApiHandler, a1 as createUploadHandler, a2 as createUserAuthApiRouter, a3 as createUserAvatarHandler, a4 as createUserProfileHandler, a5 as createUsersApiHandlers, a6 as createVendorOnboardHandlers, a7 as getCompanyDetailsFromSettings, a8 as getPublicSettingsGroup, a9 as mergeEmailLayoutCompanyDetails, aa as mergeGuardrailsIntoSystemPrompt, ab as parseLlmAgentValidationRules, ac as simpleDecrypt, ad as simpleEncrypt, ae as validateUserMessageAgainstAgentRules, af as validateUserMessageAgainstStructuredRules } from './index-DOiJuMQA.js';
3
1
  import PgBoss from 'pg-boss';
4
2
  import * as typeorm from 'typeorm';
5
- import { DataSource, EntityTarget, ObjectLiteral, SelectQueryBuilder } from 'typeorm';
3
+ import { DataSource, EntityTarget, ObjectLiteral, EntityManager, SelectQueryBuilder } from 'typeorm';
6
4
  import { ClassValue } from 'clsx';
7
5
  import { Metadata } from 'next';
8
- import { NextAuthUser } from './auth.js';
9
- export { AuthorizeOtpInput, CmsMiddlewareConfig, CmsMiddlewareRequest, NextAuthOptionsConfig, SUPER_ADMIN_GROUP_ID, VENDOR_ADMIN_GROUP_ID, createCmsMiddleware, defaultPublicApiMethods, explainSessionEntityAccess, getNextAuthOptions, getStorefrontNextAuthOptions, isAuthDebugClientEnabled, isAuthDebugEnabled, isRbacDebugEnabled, isSuperAdmin, isVendorAdmin, logAuth, logAuthClient, logEntityAccessDecision, logRbac, nextAuthCookieDebugInfo, seedAdministratorPermissions, summarizeEntityPerms, summarizeSessionUserForLog } from './auth.js';
10
- import { E as EntityCrudAction, S as SessionUser, e as VendorScope } from './vendor-scope-DTYhJk_I.js';
11
- export { A as ADMIN_GROUP_NAME, a as AuthHelpers, b as EntityPermissionFlags, G as GetSession, O as OPEN_ENDPOINTS, P as PERMISSION_REQUIRED_ENDPOINTS, R as RBAC_ADMIN_ONLY_ENTITIES, V as VENDOR_OWNER_GROUP_NAME, c as VENDOR_SCOPED_STORE_ENTITIES, d as VENDOR_STORE_RBAC_ENTITIES, f as canManageRoles, g as canManageVendorRoles, h as canManageVendorTeam, i as canOnboardVendors, j as createAuthHelpers, k as createCmsAuthBundle, l as getPermissionableEntityKeys, m as getRequiredPermission, n as hasEntityPermission, o as isOpenEndpoint, p as isPlatformAdministrator, q as isPublicMethod, r as isSuperAdminGroupName, s as isVendorGroupName, t as isVendorOwner, u as isVendorPortalUser, v as isVendorStaff, w as permissionRowsToRecord, x as resolveVendorScopeFromSessionUser, y as sessionHasEntityAccess, z as vendorPortalFlagsFromUser } from './vendor-scope-DTYhJk_I.js';
12
- import { a as NavbarConfig, F as FooterConfig } from './types-DCVaXlPV.js';
13
- export { A as AdminNavItem, D as DEFAULT_ADMIN_NAV } from './config-DJ5CmQvS.js';
14
- import 'next-auth/jwt';
15
- import 'next-auth';
6
+ import { NextAuthOptions } from 'next-auth';
7
+ import { getToken } from 'next-auth/jwt';
16
8
 
17
9
  interface PluginContext {
18
10
  dataSource: unknown;
@@ -126,7 +118,7 @@ declare class ERPSubmissionService {
126
118
  }[]): ContactFormData | null;
127
119
  }
128
120
 
129
- interface CmsAppLike$3 {
121
+ interface CmsAppLike$4 {
130
122
  getPlugin(name: string): unknown;
131
123
  }
132
124
  type ErpJobPayload = {
@@ -145,8 +137,8 @@ type ErpJobPayload = {
145
137
  kind: 'productUpsert';
146
138
  product: Record<string, unknown>;
147
139
  };
148
- declare function queueErp(cms: CmsAppLike$3, payload: ErpJobPayload): Promise<void>;
149
- declare function registerErpQueueProcessor(cms: CmsAppLike$3): void;
140
+ declare function queueErp(cms: CmsAppLike$4, payload: ErpJobPayload): Promise<void>;
141
+ declare function registerErpQueueProcessor(cms: CmsAppLike$4): void;
150
142
 
151
143
  /**
152
144
  * Duck-typed DataSource so host apps (e.g. Next) can pass their own TypeORM instance
@@ -167,7 +159,7 @@ type ErpPaidOrderEntityMap = Record<string, unknown>;
167
159
  * Enqueues ERP `order.created` only when the order has at least one **completed** payment.
168
160
  * Include `payments` in the payload.
169
161
  */
170
- declare function queueErpPaidOrderForOrderId(cms: CmsAppLike$3, dataSource: ErpPaidOrderDataSource, entityMap: ErpPaidOrderEntityMap, orderId: number): Promise<void>;
162
+ declare function queueErpPaidOrderForOrderId(cms: CmsAppLike$4, dataSource: ErpPaidOrderDataSource, entityMap: ErpPaidOrderEntityMap, orderId: number): Promise<void>;
171
163
 
172
164
  interface ErpContactSyncInput {
173
165
  name: string;
@@ -183,7 +175,7 @@ interface ErpContactSyncInput {
183
175
  * When ERP is enabled and plugin loaded, enqueue `create-contact` (non-fatal on failure).
184
176
  * Used for admin CRUD and storefront contact paths — not form submissions (those use lead/opportunity).
185
177
  */
186
- declare function queueErpCreateContactIfEnabled(cms: CmsAppLike$3, dataSource: ErpPaidOrderDataSource, entityMap: ErpPaidOrderEntityMap, input: ErpContactSyncInput): Promise<void>;
178
+ declare function queueErpCreateContactIfEnabled(cms: CmsAppLike$4, dataSource: ErpPaidOrderDataSource, entityMap: ErpPaidOrderEntityMap, input: ErpContactSyncInput): Promise<void>;
187
179
 
188
180
  interface ERPPluginConfig {
189
181
  webhookUrl: string;
@@ -195,6 +187,47 @@ interface ERPPluginInstance {
195
187
  }
196
188
  declare function erpPlugin(config: ERPPluginConfig): CmsPlugin<ERPPluginInstance>;
197
189
 
190
+ /** Social entry: use `iconUrl` for an image, or `icon` (emoji/text) as fallback when no image. */
191
+ interface SocialLinkItem {
192
+ url: string;
193
+ iconUrl?: string;
194
+ icon?: string;
195
+ }
196
+ interface CompanyDetails {
197
+ logoUrl?: string;
198
+ companyName?: string;
199
+ supportEmail?: string;
200
+ supportPhone?: string;
201
+ socialLinks?: SocialLinkItem[];
202
+ /** Shown below footer rows; from email plugin settings */
203
+ footerDisclaimer?: string;
204
+ /** Heading above social icons (default "Follow Us") */
205
+ followUsTitle?: string;
206
+ }
207
+ /** One row in order-placed transactional emails */
208
+ interface OrderPlacedLineItem {
209
+ productName: string;
210
+ quantity: number;
211
+ unitPrice: number | string;
212
+ lineTotal: number | string;
213
+ sku?: string | null;
214
+ tax?: number | string | null;
215
+ hsn?: string | null;
216
+ }
217
+ /** Merge branding + email plugin settings for layout (email overrides when set). */
218
+ declare function mergeEmailLayoutCompanyDetails(branding: Record<string, string>, emailSettings: Record<string, string>): CompanyDetails;
219
+ interface EmailTemplateResult {
220
+ subject: string;
221
+ bodyHtml: string;
222
+ text?: string;
223
+ }
224
+ type TemplateContext<T = unknown> = T & {
225
+ companyDetails: CompanyDetails;
226
+ };
227
+ declare const EMAIL_TEMPLATE_NAMES: readonly ["signup", "passwordReset", "passwordChange", "orderPlaced", "returnInitiated", "shippingUpdate", "invite", "formSubmission", "otp", "chatLead", "vendorOnboarded"];
228
+ type EmailTemplateName = (typeof EMAIL_TEMPLATE_NAMES)[number];
229
+ declare function getCompanyDetailsFromSettings(settingsGroup: Record<string, string>): CompanyDetails;
230
+
198
231
  interface RenderEmailOptions {
199
232
  renderLayout?: (opts: {
200
233
  bodyHtml: string;
@@ -288,7 +321,7 @@ declare function renderLayout(options: {
288
321
  companyDetails: CompanyDetails;
289
322
  }): string;
290
323
 
291
- interface CmsAppLike$2 {
324
+ interface CmsAppLike$3 {
292
325
  getPlugin(name: string): unknown;
293
326
  }
294
327
  /** Context for template rendering: at least companyDetails; template-specific fields (formName, etc.) are allowed. */
@@ -302,8 +335,8 @@ interface EmailJobPayload {
302
335
  html?: string;
303
336
  text?: string;
304
337
  }
305
- declare function registerEmailQueueProcessor(cms: CmsAppLike$2): void;
306
- declare function queueEmail(cms: CmsAppLike$2, payload: EmailJobPayload): Promise<void>;
338
+ declare function registerEmailQueueProcessor(cms: CmsAppLike$3): void;
339
+ declare function queueEmail(cms: CmsAppLike$3, payload: EmailJobPayload): Promise<void>;
307
340
  interface OrderPlacedEmailPayload {
308
341
  orderNumber: string;
309
342
  total?: string | number;
@@ -321,7 +354,7 @@ interface OrderPlacedEmailPayload {
321
354
  shippingAddress?: Record<string, string>;
322
355
  }
323
356
  /** Queues one `orderPlaced` email per recipient (customer + each unique sales address; skips sales if same as customer). */
324
- declare function queueOrderPlacedEmails(cms: CmsAppLike$2, payload: OrderPlacedEmailPayload): Promise<void>;
357
+ declare function queueOrderPlacedEmails(cms: CmsAppLike$3, payload: OrderPlacedEmailPayload): Promise<void>;
325
358
  interface VendorOnboardEmailPayload {
326
359
  vendorName: string;
327
360
  vendorSlug?: string;
@@ -336,7 +369,7 @@ interface VendorOnboardEmailPayload {
336
369
  sendToOwner?: boolean;
337
370
  }
338
371
  /** Queues `vendorOnboarded` email to owner and each unique notify address (sales team settings). */
339
- declare function queueVendorOnboardEmails(cms: CmsAppLike$2, payload: VendorOnboardEmailPayload): Promise<void>;
372
+ declare function queueVendorOnboardEmails(cms: CmsAppLike$3, payload: VendorOnboardEmailPayload): Promise<void>;
340
373
 
341
374
  interface EmailPluginConfig {
342
375
  type: 'AWS' | 'SMTP' | 'GMAIL' | 'SENDGRID';
@@ -404,7 +437,7 @@ interface AnalyticsPluginConfig {
404
437
  }
405
438
  declare function analyticsPlugin(config?: AnalyticsPluginConfig): CmsPlugin<AnalyticsService>;
406
439
 
407
- type MessageTemplateRowLoader = (channel: string, templateKey: string) => Promise<{
440
+ type MessageTemplateRowLoader$1 = (channel: string, templateKey: string) => Promise<{
408
441
  body: string;
409
442
  externalTemplateRef: string | null;
410
443
  providerMeta: Record<string, unknown> | null;
@@ -444,7 +477,7 @@ interface SmsServiceConfig {
444
477
  webhookSecret?: string;
445
478
  }
446
479
 
447
- interface CmsAppLike$1 {
480
+ interface CmsAppLike$2 {
448
481
  getPlugin(name: string): unknown;
449
482
  }
450
483
  interface SmsJobPayload {
@@ -455,14 +488,14 @@ interface SmsJobPayload {
455
488
  variables?: Record<string, string>;
456
489
  otpCode?: string;
457
490
  }
458
- declare function registerSmsQueueProcessor(cms: CmsAppLike$1): void;
459
- declare function queueSms(cms: CmsAppLike$1, payload: SmsJobPayload): Promise<void>;
491
+ declare function registerSmsQueueProcessor(cms: CmsAppLike$2): void;
492
+ declare function queueSms(cms: CmsAppLike$2, payload: SmsJobPayload): Promise<void>;
460
493
 
461
494
  interface SmsPluginConfig extends Partial<SmsServiceConfig> {
462
495
  /** Load admin settings group `sms` (enabled, smsProvider). Secrets typically stay in env. */
463
496
  getSmsSettings?: () => Promise<Record<string, string>>;
464
497
  /** Resolve `message_templates` rows for SMS (required for `templateKey` sends). */
465
- getMessageTemplateRow?: MessageTemplateRowLoader;
498
+ getMessageTemplateRow?: MessageTemplateRowLoader$1;
466
499
  }
467
500
  interface SmsServiceInterface {
468
501
  send(opts: {
@@ -475,6 +508,47 @@ interface SmsServiceInterface {
475
508
  }
476
509
  declare function smsPlugin(config?: SmsPluginConfig): CmsPlugin<SmsServiceInterface | null>;
477
510
 
511
+ type MessageTemplateRowLoader = (channel: string, templateKey: string) => Promise<{
512
+ body: string;
513
+ externalTemplateRef: string | null;
514
+ enabled: boolean;
515
+ } | null>;
516
+ interface WhatsAppServiceConfig {
517
+ accessToken?: string;
518
+ phoneNumberId?: string;
519
+ apiVersion?: string;
520
+ }
521
+
522
+ interface CmsAppLike$1 {
523
+ getPlugin(name: string): unknown;
524
+ }
525
+ interface WhatsAppJobPayload {
526
+ to: string;
527
+ body?: string;
528
+ templateKey?: string;
529
+ externalTemplateRef?: string;
530
+ variables?: Record<string, string>;
531
+ templateParamOrder?: readonly string[];
532
+ }
533
+ declare function registerWhatsAppQueueProcessor(cms: CmsAppLike$1): void;
534
+ declare function queueWhatsApp(cms: CmsAppLike$1, payload: WhatsAppJobPayload): Promise<boolean>;
535
+
536
+ interface WhatsAppPluginConfig extends Partial<WhatsAppServiceConfig> {
537
+ getWhatsAppSettings?: () => Promise<Record<string, string>>;
538
+ getMessageTemplateRow?: MessageTemplateRowLoader;
539
+ }
540
+ interface WhatsAppServiceInterface {
541
+ send(opts: {
542
+ to: string;
543
+ body?: string;
544
+ templateKey?: string;
545
+ externalTemplateRef?: string;
546
+ variables?: Record<string, string>;
547
+ templateParamOrder?: readonly string[];
548
+ }): Promise<boolean>;
549
+ }
550
+ declare function whatsappPlugin(config?: WhatsAppPluginConfig): CmsPlugin<WhatsAppServiceInterface | null>;
551
+
478
552
  interface PaymentIntent {
479
553
  id: string;
480
554
  clientSecret: string;
@@ -501,6 +575,13 @@ interface RazorpayConfig {
501
575
  type PaymentPluginConfig = StripeConfig | RazorpayConfig;
502
576
  declare function paymentPlugin(config: PaymentPluginConfig): CmsPlugin<PaymentServiceInterface | undefined>;
503
577
 
578
+ /**
579
+ * Storage plugin contract: upload a file and return its public URL.
580
+ */
581
+ interface StorageService {
582
+ upload(buffer: Buffer, key: string, contentType: string): Promise<string>;
583
+ }
584
+
504
585
  interface S3StoragePluginConfig {
505
586
  region: string;
506
587
  accessKeyId: string;
@@ -636,6 +717,173 @@ declare class LlmService implements LlmServiceInterface {
636
717
  streamChat(messages: LlmMessage[], options?: LlmChatOptions): AsyncIterable<string>;
637
718
  }
638
719
 
720
+ /** Canonical name for new installs / migrations */
721
+ declare const ADMIN_GROUP_NAME = "Administrator";
722
+ /** System administrator group (roles UI + users / user_groups / permissions bypass). */
723
+ declare function isSuperAdminGroupName(name: string | null | undefined): boolean;
724
+ type EntityCrudAction = 'create' | 'read' | 'update' | 'delete';
725
+ type EntityPermissionFlags = {
726
+ c: boolean;
727
+ r: boolean;
728
+ u: boolean;
729
+ d: boolean;
730
+ };
731
+ declare function getPermissionableEntityKeys(entityMap: Record<string, unknown>): string[];
732
+ declare function permissionRowsToRecord(rows: Array<{
733
+ entity: string;
734
+ canCreate: boolean;
735
+ canRead: boolean;
736
+ canUpdate: boolean;
737
+ canDelete: boolean;
738
+ }> | undefined): Record<string, EntityPermissionFlags>;
739
+ declare function hasEntityPermission(record: Record<string, EntityPermissionFlags> | undefined, entity: string, action: EntityCrudAction): boolean;
740
+
741
+ /**
742
+ * @deprecated Administrator bypass is now full entity access via `isRBACAdmin` in `sessionHasEntityAccess`.
743
+ * Kept for backwards-compatible imports.
744
+ */
745
+ declare const RBAC_ADMIN_ONLY_ENTITIES: Set<string>;
746
+ interface SessionUser {
747
+ id?: string;
748
+ email?: string | null;
749
+ name?: string | null;
750
+ groupId?: number;
751
+ /** User group display name (from login). */
752
+ groupName?: string | null;
753
+ /** @deprecated use entityPerms / isRBACAdmin */
754
+ permissions?: string[];
755
+ /** Administrator group: bypasses entity-level RBAC on all resources */
756
+ isRBACAdmin?: boolean;
757
+ entityPerms?: Record<string, EntityPermissionFlags>;
758
+ /** When false and not isRBACAdmin, admin API/UI is denied. */
759
+ adminAccess?: boolean;
760
+ /** Vendor stores this user can access (from vendor_users). */
761
+ vendorIds?: number[];
762
+ /** Active vendor for scoped CRUD (vendor staff). */
763
+ activeVendorId?: number | null;
764
+ /** Role for the active vendor link (`vendor_users.role`). */
765
+ vendorRole?: 'owner' | 'staff' | null;
766
+ /** Active vendor-scoped role id (`vendor_users.vendorRoleId`). */
767
+ vendorRoleId?: number | null;
768
+ vendorRoleName?: string | null;
769
+ /** True when active vendor role has `isOwnerRole`. */
770
+ isVendorRoleOwner?: boolean;
771
+ /** Permissions from active vendor role (`vendor_role_permissions`). */
772
+ vendorEntityPerms?: Record<string, EntityPermissionFlags>;
773
+ /** Set at login: vendor store portal (not platform admin). */
774
+ isVendorPortal?: boolean;
775
+ /** Set at login: vendor store owner (team + permissions). */
776
+ isVendorOwner?: boolean;
777
+ }
778
+ declare function sessionHasEntityAccess(user: SessionUser | null | undefined, entity: string, action: EntityCrudAction): boolean;
779
+ declare function canManageRoles(user: SessionUser | null | undefined): boolean;
780
+ type GetSession = () => Promise<{
781
+ user?: SessionUser;
782
+ } | null>;
783
+ declare const OPEN_ENDPOINTS: Array<Record<string, string[]>>;
784
+ declare const PERMISSION_REQUIRED_ENDPOINTS: Record<string, string[]>;
785
+ declare function isOpenEndpoint(pathname: string): boolean;
786
+ declare function getRequiredPermission(pathname: string): string[] | null;
787
+ declare function isPublicMethod(pathname: string, method: string): boolean;
788
+ interface AuthHelpers {
789
+ requireAuth(req: Request): Promise<Response | null>;
790
+ requirePermission(req: Request, permission: string): Promise<Response | null>;
791
+ requireEntityPermission(req: Request, entity: string, action: EntityCrudAction): Promise<Response | null>;
792
+ requireAdminAccess(req: Request): Promise<Response | null>;
793
+ getAuthenticatedUser(): Promise<SessionUser | null>;
794
+ }
795
+ declare function createAuthHelpers(getSession: GetSession, NextResponse: {
796
+ json: (body: unknown, init?: {
797
+ status?: number;
798
+ }) => Response;
799
+ }): AuthHelpers;
800
+ /** Pass return value into `createCmsApiHandler` (includes `getSessionUser` for vendor store APIs). */
801
+ declare function createCmsAuthBundle(getSession: GetSession, NextResponse: {
802
+ json: (body: unknown, init?: {
803
+ status?: number;
804
+ }) => Response;
805
+ }): {
806
+ requireAuth: (req: Request) => Promise<Response | null>;
807
+ requireAdminAccess: (req: Request) => Promise<Response | null>;
808
+ requireEntityPermission: (req: Request, entity: string, action: EntityCrudAction) => Promise<Response | null>;
809
+ getSessionUser: () => Promise<SessionUser | null>;
810
+ getAuthenticatedUser: () => Promise<SessionUser | null>;
811
+ };
812
+
813
+ /** Entities with a `vendorId` column (store data). */
814
+ declare const VENDOR_SCOPED_STORE_ENTITIES: Set<string>;
815
+ /**
816
+ * Store admin RBAC for vendor portal users (read/create/update/delete fallbacks in rbac-debug).
817
+ * Includes entities without `vendorId` that are still part of the store admin UI.
818
+ */
819
+ declare const VENDOR_STORE_RBAC_ENTITIES: Set<string>;
820
+ type VendorScope = {
821
+ type: 'all';
822
+ } | {
823
+ type: 'vendor';
824
+ vendorId: number;
825
+ vendorIds: number[];
826
+ } | {
827
+ type: 'deny';
828
+ };
829
+ declare const VENDOR_OWNER_GROUP_NAME = "Vendor Owner";
830
+ /** User groups treated as vendor store staff (sidebar + scoped admin). */
831
+ declare function isVendorGroupName(name: string | null | undefined): boolean;
832
+ declare function isPlatformAdministrator(user: SessionUser | null | undefined): boolean;
833
+ /** Vendor portal UI (store + store admin), not platform admin. */
834
+ declare function isVendorPortalUser(user: SessionUser | null | undefined): boolean;
835
+ declare function isVendorStaff(user: SessionUser | null | undefined): boolean;
836
+ /** Vendor store owner (manages team + role permissions for their store). */
837
+ declare function isVendorOwner(user: SessionUser | null | undefined): boolean;
838
+ declare function canManageVendorTeam(user: SessionUser | null | undefined): boolean;
839
+ declare function canManageVendorRoles(user: SessionUser | null | undefined): boolean;
840
+ /** Platform admins (Administrator group) can onboard vendors. */
841
+ declare function canOnboardVendors(user: SessionUser | null | undefined): boolean;
842
+ declare function resolveVendorScopeFromSessionUser(user: SessionUser | null | undefined): VendorScope;
843
+ /** Compute portal flags at login (persist on JWT). */
844
+ declare function vendorPortalFlagsFromUser(input: {
845
+ email: string;
846
+ isRBACAdmin: boolean;
847
+ groupName?: string | null;
848
+ vendorIds?: number[];
849
+ vendorRole?: 'owner' | 'staff' | null;
850
+ isVendorRoleOwner?: boolean;
851
+ }): {
852
+ isVendorPortal: boolean;
853
+ isVendorOwner: boolean;
854
+ };
855
+
856
+ type EntityMap$2 = Record<string, typeorm.EntityTarget<typeorm.ObjectLiteral>>;
857
+ interface CrudHandlerOptions {
858
+ requireAuth: (req: Request) => Promise<Response | null>;
859
+ json: (body: unknown, init?: {
860
+ status?: number;
861
+ }) => Response;
862
+ requireEntityPermission?: (req: Request, entity: string, action: EntityCrudAction) => Promise<Response | null>;
863
+ /** When set, contact create/update enqueues ERP `create-contact` (non-fatal). */
864
+ getCms?: () => Promise<{
865
+ getPlugin: (name: string) => unknown;
866
+ }>;
867
+ /** When set, soft-delete sets `deletedBy` from the current admin user. */
868
+ getDeletedByUserId?: (req: Request) => Promise<number | null>;
869
+ /** When set, store rows are filtered by session vendor (platform admin bypasses). */
870
+ getVendorScope?: () => Promise<VendorScope>;
871
+ /** Hydrated session (group + vendor context) for vendorId resolution on create. */
872
+ getHydratedSessionUser?: () => Promise<SessionUser | null>;
873
+ }
874
+ declare function createCrudHandler(dataSource: DataSource, entityMap: EntityMap$2, options: CrudHandlerOptions): {
875
+ GET(req: Request, resource: string): Promise<Response>;
876
+ POST(req: Request, resource: string): Promise<Response>;
877
+ GET_METADATA(req: Request, resource: string): Promise<Response>;
878
+ BULK_POST(req: Request, resource: string): Promise<Response>;
879
+ GET_EXPORT(req: Request, resource: string): Promise<Response>;
880
+ };
881
+ declare function createCrudByIdHandler(dataSource: DataSource, entityMap: EntityMap$2, options: CrudHandlerOptions): {
882
+ GET(req: Request, resource: string, id: string): Promise<Response>;
883
+ PUT(req: Request, resource: string, id: string): Promise<Response>;
884
+ DELETE(req: Request, resource: string, id: string): Promise<Response>;
885
+ };
886
+
639
887
  declare class LlmAgent {
640
888
  id: number;
641
889
  name: string;
@@ -797,523 +1045,477 @@ declare function pgBossScheduleNameForId(scheduleId: string): string;
797
1045
  declare function buildCronFromSchedule(schedule: Pick<JobSchedule, 'scheduleMode' | 'intervalMinutes' | 'runAtTime' | 'runOnDays' | 'cronExpression'>): string;
798
1046
  declare function validateScheduleInput(schedule: Pick<JobSchedule, 'scheduleMode' | 'intervalMinutes' | 'runAtTime' | 'cronExpression'>): string | null;
799
1047
 
800
- type CaptchaProviderId = 'turnstile' | 'recaptcha_v3';
801
- interface CaptchaPublicConfig {
802
- enabled: boolean;
803
- activeProvider: CaptchaProviderId | null;
804
- siteKey: string | null;
805
- availableProviders: Array<{
806
- id: CaptchaProviderId;
807
- siteKey: string;
808
- }>;
809
- multipleProviders: boolean;
810
- }
811
- type CaptchaVerifyResult = {
812
- ok: true;
813
- } | {
814
- ok: false;
815
- status: number;
816
- message: string;
817
- };
818
- declare function buildCaptchaPublicConfig(config: Record<string, string>): CaptchaPublicConfig;
819
- declare class CaptchaService {
820
- private readonly env;
821
- constructor(env: Record<string, string>);
822
- isEnforced(): boolean;
823
- getPublicConfig(): CaptchaPublicConfig;
824
- verify(body: Record<string, unknown>, req: Request): Promise<CaptchaVerifyResult>;
825
- }
826
-
827
- declare function captchaPlugin(): CmsPlugin<CaptchaService | void>;
828
-
829
- type JsonResponse = (body: unknown, init?: {
830
- status?: number;
831
- headers?: HeadersInit;
832
- }) => Response;
833
- declare function assertCaptchaOk(getCms: (() => Promise<{
834
- getPlugin: (name: string) => unknown;
835
- }>) | undefined, body: Record<string, unknown>, req: Request, json: JsonResponse): Promise<Response | null>;
1048
+ /**
1049
+ * Auth API handler factories. Inject dataSource + entityMap, sendEmail, hash/compare; optional hooks to customize.
1050
+ */
836
1051
 
837
- interface LatestArticleFromFeed {
838
- title?: string;
839
- link?: string;
840
- /** Short excerpt */
841
- summary?: string;
842
- /** Full content if available */
843
- content?: string;
844
- date: Date;
845
- creator?: string;
846
- categories?: string[];
1052
+ interface AuthHandlersConfig {
1053
+ json: (body: unknown, init?: {
1054
+ status?: number;
1055
+ }) => Response;
1056
+ baseUrl: string;
1057
+ hashPassword: (plain: string) => Promise<string>;
1058
+ comparePassword: (plain: string, hash: string) => Promise<boolean>;
847
1059
  }
848
- type RssItem = {
849
- title?: string;
850
- link?: string;
851
- pubDate?: string;
852
- isoDate?: string;
853
- contentSnippet?: string;
854
- summary?: string;
855
- description?: string;
856
- content?: string;
857
- creator?: string;
858
- 'dc:creator'?: string;
859
- 'content:encoded'?: string;
860
- categories?: string[];
861
- guid?: string | {
862
- _: string;
863
- };
864
- };
865
- declare function getRssArticleSummaryFromItem(item: RssItem): {
866
- summary: string;
867
- fullContent: string;
868
- };
869
- type BlogGeneratorDraftParseMode = 'json' | 'plaintext';
870
- interface BlogGeneratorSeoDraft {
871
- title: string | null;
872
- description: string | null;
873
- keywords: string | null;
874
- ogTitle: string | null;
875
- ogDescription: string | null;
1060
+ interface ForgotPasswordConfig extends AuthHandlersConfig {
1061
+ dataSource: DataSource;
1062
+ entityMap: EntityMap$2;
1063
+ sendEmail?: (opts: {
1064
+ to: string;
1065
+ subject: string;
1066
+ html: string;
1067
+ text?: string;
1068
+ /** Plain reset URL for templated emails (preferred over parsing html). */
1069
+ resetLink?: string;
1070
+ }) => Promise<void>;
1071
+ resetExpiryHours?: number;
1072
+ afterCreateToken?: (email: string, resetLink: string) => Promise<void>;
1073
+ }
1074
+ declare function createForgotPasswordHandler(config: ForgotPasswordConfig): (request: Request) => Promise<Response>;
1075
+ interface SetPasswordConfig extends AuthHandlersConfig {
1076
+ dataSource: DataSource;
1077
+ entityMap: EntityMap$2;
1078
+ minPasswordLength?: number;
1079
+ beforeUpdate?: (email: string, userId: number) => Promise<void>;
876
1080
  }
877
- interface BlogGeneratorBlogDraft {
878
- title: string;
879
- slug?: string;
880
- markdown: string;
881
- /** Short plain-text copy for social (e.g. LinkedIn); optional until social LLM step runs. */
882
- socialMediaContent?: string | null;
883
- categoryName: string | null;
884
- seo: BlogGeneratorSeoDraft;
885
- /** Suggested tag labels (may not exist in CMS yet). */
886
- tags: string[];
887
- parseMode: BlogGeneratorDraftParseMode;
1081
+ declare function createSetPasswordHandler(config: SetPasswordConfig): (request: Request) => Promise<Response>;
1082
+ interface InviteAcceptConfig extends AuthHandlersConfig {
1083
+ dataSource: DataSource;
1084
+ entityMap: EntityMap$2;
1085
+ beforeActivate?: (email: string, userId: number) => Promise<void>;
1086
+ }
1087
+ /** Decode invite token (base64 email) and set password + unblock user */
1088
+ declare function createInviteAcceptHandler(config: InviteAcceptConfig): (request: Request) => Promise<Response>;
1089
+ interface ChangePasswordConfig extends AuthHandlersConfig {
1090
+ dataSource: DataSource;
1091
+ entityMap: EntityMap$2;
1092
+ getSession: () => Promise<{
1093
+ user?: {
1094
+ email?: string | null;
1095
+ };
1096
+ } | null>;
1097
+ minPasswordLength?: number;
1098
+ beforeUpdate?: (email: string) => Promise<void>;
1099
+ }
1100
+ declare function createChangePasswordHandler(config: ChangePasswordConfig): (request: Request) => Promise<Response>;
1101
+ interface UserAuthApiConfig extends ForgotPasswordConfig, Omit<SetPasswordConfig, 'dataSource' | 'entityMap' | 'json' | 'baseUrl' | 'hashPassword' | 'comparePassword'>, Omit<InviteAcceptConfig, 'dataSource' | 'entityMap' | 'json' | 'baseUrl' | 'hashPassword' | 'comparePassword'>, Omit<ChangePasswordConfig, 'dataSource' | 'entityMap' | 'json' | 'baseUrl' | 'hashPassword' | 'comparePassword' | 'beforeUpdate' | 'getSession'> {
1102
+ getSession?: () => Promise<{
1103
+ user?: {
1104
+ email?: string | null;
1105
+ };
1106
+ } | null>;
1107
+ beforeChangePasswordUpdate?: (email: string) => Promise<void>;
888
1108
  }
889
1109
  /**
890
- * Parses the LLM reply: prefers a single JSON object with blogTitle, blogHtml/blogMarkdown/content, categoryName, seo, …
891
- * Falls back to treating the entire string as HTML (or legacy markdown) if JSON parsing fails.
1110
+ * Single router for all user-auth APIs. Mount in the app once.
1111
+ * Use when you have no users/[id] route (else Next.js gives [id] precedence and "forgot-password" would match as id).
1112
+ * Path is the segment after the mount (e.g. "forgot-password"). Returns 404 for unknown paths.
892
1113
  */
893
- declare function parseBlogGeneratorAgentContent(raw: string): BlogGeneratorBlogDraft;
894
- declare function resolveBlogCategoryIdByName(needle: string | null | undefined, rows: readonly {
895
- id: number;
896
- name: string;
897
- }[]): {
898
- categoryId: number | null;
899
- matched: boolean;
1114
+ declare function createUserAuthApiRouter(config: UserAuthApiConfig): {
1115
+ POST(req: Request, pathname: string): Promise<Response>;
900
1116
  };
1117
+
901
1118
  /**
902
- * Minimal user payload: latest item per feed only (system prompt carries writing rules).
1119
+ * CMS API handlers: dashboard, analytics, upload, blog/form by slug, users (list/create/get/update/delete/regenerate-invite/avatar/profile).
1120
+ * All accept injectable deps; upload supports S3 or local.
903
1121
  */
904
- declare function buildRssUserPromptFromFeeds(feeds: ReadonlyArray<{
905
- rssUrl: string;
906
- article: LatestArticleFromFeed;
907
- }>): string;
1122
+
1123
+ type RequireEntityPermissionFn = (req: Request, entity: string, action: EntityCrudAction) => Promise<Response | null>;
908
1124
  /**
909
- * User message for the metadata-only LLM step (one blog at a time).
1125
+ * Optional JSON in `LlmAgent.validationRules`. Used for programmatic checks before the LLM call.
1126
+ * For natural-language output rules, use `guardrails` / `outputRules` / `outputInstructions` (merged into system prompt).
910
1127
  */
911
- declare function buildBlogMetadataUserPrompt(opts: {
912
- title: string;
913
- markdown: string;
914
- categoryNames: readonly string[];
915
- tagNames: readonly string[];
916
- }): string;
917
- /** Parses JSON from the metadata-enrichment LLM (category, slug, seo, tags). */
918
- declare function parseBlogMetadataEnrichmentJson(raw: string): {
919
- categoryName: string | null;
920
- blogSlug: string | null;
921
- seo: BlogGeneratorSeoDraft;
922
- tags: string[];
1128
+ type LlmAgentValidationRulesJson = {
1129
+ maxUserChars?: number;
1130
+ maxMessageLength?: number;
1131
+ minUserChars?: number;
1132
+ minMessageLength?: number;
1133
+ blockedSubstrings?: string[];
1134
+ /** Shown to the model as output guardrails (first non-empty of guardrails | outputRules | outputInstructions wins). */
1135
+ guardrails?: string;
1136
+ outputRules?: string;
1137
+ outputInstructions?: string;
1138
+ };
1139
+ type ParsedLlmAgentValidation = {
1140
+ /** Subset used for length / substring checks only. */
1141
+ structured: Pick<LlmAgentValidationRulesJson, 'maxUserChars' | 'maxMessageLength' | 'minUserChars' | 'minMessageLength' | 'blockedSubstrings'>;
1142
+ /** Appended to system prompt so the model follows output guardrails. */
1143
+ guardrailsForPrompt: string | null;
923
1144
  };
924
1145
  /**
925
- * Parses LLM output: prefers HTML + {@link BLOG_GENERATOR_MARKDOWN_ARTICLE_SEPARATOR} for multiple articles.
926
- * If the model still returns legacy JSON with `blogHtml` / `blogMarkdown`, returns a single draft from that object.
1146
+ * - Valid JSON object: structural keys validation; `guardrails` / `outputRules` / `outputInstructions` → prompt suffix.
1147
+ * - Not JSON: entire string is treated as prose guardrails for the prompt (no programmatic rules unless you use JSON).
927
1148
  */
928
- declare function parseBlogGeneratorModelOutput(raw: string): BlogGeneratorBlogDraft[];
929
- declare class BlogGeneratorService {
930
- readonly version: "1.0.0";
931
- getLatestArticleFromFeed(rssUrl: string): Promise<LatestArticleFromFeed | null>;
932
- /** Defaults for the Blog Generator Agent (admin can override per request). */
933
- getAgentDefaults(): {
934
- agentName: string;
935
- systemInstruction: string;
936
- validationRules: string;
937
- };
938
- /**
939
- * Second LLM call: one draft at a time — category, URL slug, SEO fields, tags (JSON).
940
- */
941
- private enrichBlogDraftWithLlmMetadata;
942
- /**
943
- * Third LLM call: one draft at a time short social copy (JSON `{ socialMediaContent }`).
944
- */
945
- private enrichBlogDraftWithLlmSocial;
946
- /**
947
- * Fetches the latest item for each RSS URL, then calls {@link LlmServiceInterface.chatAgent}.
948
- * `userPrompt` is only per-feed source material; rules live in the system prompt.
949
- * Expects HTML article fragment(s), optionally separated by {@link BLOG_GENERATOR_MARKDOWN_ARTICLE_SEPARATOR}.
950
- */
951
- generateBlogMarkdownFromRss(params: {
952
- llm: LlmServiceInterface;
953
- /** Single feed (legacy). */
954
- rssUrl?: string;
955
- /** One or more feeds; latest item per URL is sent together. Prefer this when multiple URLs. */
956
- rssUrls?: readonly string[];
957
- systemInstruction?: string;
958
- validationRules?: string;
959
- /** Reserved for future structured output; writer does not inject categories into the user prompt. */
960
- categoryNamesHint?: readonly string[];
961
- /** Names of non-deleted tags in CMS (hint for reuse). */
962
- tagNamesHint?: readonly string[];
963
- /** From optional `llm_agents` row (slug `blog-generator`): model / sampling for the writer step. */
964
- llmAgentChatOptions?: Pick<LlmAgentOptions, 'model' | 'temperature' | 'max_tokens'>;
965
- /** Optional overrides for the metadata step; defaults live in `blog-generator-metadata-defaults.ts`. */
966
- metadataSystemInstruction?: string;
967
- metadataValidationRules?: string;
968
- /** From optional `llm_agents` row (slug `blog-generator-metadata`): model / sampling for metadata only. */
969
- metadataLlmAgentChatOptions?: Pick<LlmAgentOptions, 'model' | 'temperature' | 'max_tokens'>;
970
- /** Optional overrides for the social-summary step; defaults in `blog-generator-social-defaults.ts`. */
971
- socialSystemInstruction?: string;
972
- socialValidationRules?: string;
973
- /** From optional `llm_agents` row (slug `blog-generator-social`): model / sampling for social copy only. */
974
- socialLlmAgentChatOptions?: Pick<LlmAgentOptions, 'model' | 'temperature' | 'max_tokens'>;
975
- }): Promise<{
976
- agentName: string;
977
- feedArticles: Array<{
978
- rssUrl: string;
979
- article: LatestArticleFromFeed;
980
- }>;
981
- /** First feed's article (backward compatibility). */
982
- article: LatestArticleFromFeed;
983
- /** Raw model reply (HTML body per defaults; legacy markdown or JSON still parsed when present). */
984
- blogMarkdown: string;
985
- blogDrafts: BlogGeneratorBlogDraft[];
986
- /** Same as first draft; backward compatibility. */
987
- blogDraft: BlogGeneratorBlogDraft;
988
- }>;
1149
+ declare function parseLlmAgentValidationRules(validationRulesText: string | null | undefined): ParsedLlmAgentValidation;
1150
+ declare function validateUserMessageAgainstStructuredRules(message: string, structured: ParsedLlmAgentValidation['structured']): {
1151
+ ok: true;
1152
+ } | {
1153
+ ok: false;
1154
+ error: string;
1155
+ };
1156
+ /** Parses `validationRules` then runs programmatic checks only. */
1157
+ declare function validateUserMessageAgainstAgentRules(message: string, validationRulesText: string | null | undefined): {
1158
+ ok: true;
1159
+ } | {
1160
+ ok: false;
1161
+ error: string;
1162
+ };
1163
+ /** Merges guardrails prose into the system instruction sent to the model. */
1164
+ declare function mergeGuardrailsIntoSystemPrompt(baseSystem: string | undefined, guardrailsForPrompt: string | null): string;
1165
+ interface CmsHandlersBase {
1166
+ json: (body: unknown, init?: {
1167
+ status?: number;
1168
+ }) => Response;
1169
+ requireAuth: (req: Request) => Promise<Response | null>;
1170
+ requireEntityPermission?: RequireEntityPermissionFn;
1171
+ }
1172
+ interface DashboardStatsConfig extends CmsHandlersBase {
1173
+ dataSource: DataSource;
1174
+ entityMap: EntityMap$2;
1175
+ requirePermission?: (req: Request, permission: string) => Promise<Response | null>;
1176
+ }
1177
+ declare function createDashboardStatsHandler(config: DashboardStatsConfig): (req: Request) => Promise<Response>;
1178
+ interface EcommerceAnalyticsConfig extends CmsHandlersBase {
1179
+ dataSource: DataSource;
1180
+ entityMap: EntityMap$2;
1181
+ }
1182
+ declare function createEcommerceAnalyticsHandler(config: EcommerceAnalyticsConfig): (req: Request) => Promise<Response>;
1183
+ interface VendorDashboardConfig extends CmsHandlersBase {
1184
+ dataSource: DataSource;
1185
+ entityMap: EntityMap$2;
1186
+ getSessionUser: () => Promise<SessionUser | null>;
1187
+ }
1188
+ declare function createVendorDashboardHandler(config: VendorDashboardConfig): (req: Request) => Promise<Response>;
1189
+ interface AnalyticsHandlerConfig extends CmsHandlersBase {
1190
+ getAnalyticsData?: (days: number) => Promise<unknown>;
1191
+ getPropertyId?: () => ({
1192
+ currentViewId?: string;
1193
+ [k: string]: unknown;
1194
+ });
1195
+ getPermissions?: () => ({
1196
+ serviceAccountEmail?: string;
1197
+ currentViewId?: string;
1198
+ [k: string]: unknown;
1199
+ });
989
1200
  }
1201
+ declare function createAnalyticsHandlers(config: AnalyticsHandlerConfig): {
1202
+ GET(req: Request): Promise<Response>;
1203
+ propertyId: () => Promise<Response>;
1204
+ permissions: () => Promise<Response>;
1205
+ };
990
1206
 
991
- /** Stable display name; not persisted as DB agent row in v1. */
992
- declare const BLOG_GENERATOR_AGENT_NAME = "Blog Generator Agent";
1207
+ interface UploadHandlerConfig extends CmsHandlersBase {
1208
+ /** Storage plugin instance or getter (e.g. () => getCms().then(c => c.getPlugin('storage'))). If not set, uses local fallback. */
1209
+ storage?: StorageService | (() => StorageService | undefined) | (() => Promise<StorageService | undefined>);
1210
+ /** Fallback when storage not set: dir relative to cwd (e.g. "public/uploads") */
1211
+ localUploadDir?: string;
1212
+ allowedTypes?: string[];
1213
+ maxSizeBytes?: number;
1214
+ /** Resolve folder chain for `parentId` (merged from createCmsApiHandler when omitted). */
1215
+ dataSource?: DataSource;
1216
+ entityMap?: EntityMap$2;
1217
+ }
1218
+ declare function createUploadHandler(config: UploadHandlerConfig): (req: Request) => Promise<Response>;
1219
+ /** POST /api/media/extract/:id — expand a zip media row into folders/files under the zip’s parent folder. */
1220
+ declare function createMediaZipExtractHandler(config: UploadHandlerConfig): (_req: Request, zipMediaId: string) => Promise<Response>;
1221
+ interface BlogBySlugConfig extends CmsHandlersBase {
1222
+ dataSource: DataSource;
1223
+ entityMap: EntityMap$2;
1224
+ }
1225
+ declare function createBlogBySlugHandler(config: BlogBySlugConfig): (_req: Request, slug: string) => Promise<Response>;
1226
+ interface FormBySlugConfig extends CmsHandlersBase {
1227
+ dataSource: DataSource;
1228
+ entityMap: EntityMap$2;
1229
+ }
1230
+ declare function createFormBySlugHandler(config: FormBySlugConfig): (_req: Request, slug: string) => Promise<Response>;
1231
+ interface FormSaveHandlersConfig extends CmsHandlersBase {
1232
+ dataSource: DataSource;
1233
+ entityMap: EntityMap$2;
1234
+ }
1235
+ interface FormSubmissionHandlerConfig {
1236
+ dataSource: DataSource;
1237
+ entityMap: EntityMap$2;
1238
+ json: (body: unknown, init?: {
1239
+ status?: number;
1240
+ }) => Response;
1241
+ /** When set, form submission notification email is queued (CRM recipient). */
1242
+ getCms?: () => Promise<{
1243
+ getPlugin: (name: string) => unknown;
1244
+ }>;
1245
+ getCompanyDetails?: () => Promise<CompanyDetails>;
1246
+ getRecipientForChannel?: (channel: 'crm' | 'sales' | 'fulfilment') => Promise<string | null>;
1247
+ }
1248
+ interface FormSubmissionGetByIdConfig extends CmsHandlersBase {
1249
+ dataSource: DataSource;
1250
+ entityMap: EntityMap$2;
1251
+ json: (body: unknown, init?: {
1252
+ status?: number;
1253
+ }) => Response;
1254
+ }
1255
+ interface UsersApiConfig extends CmsHandlersBase {
1256
+ dataSource: DataSource;
1257
+ entityMap: EntityMap$2;
1258
+ baseUrl: string;
1259
+ /** When set with email queue/plugin, invite emails are sent on user create and regenerate-invite. */
1260
+ getCms?: () => Promise<{
1261
+ getPlugin: (name: string) => unknown;
1262
+ }>;
1263
+ getCompanyDetails?: () => Promise<CompanyDetails>;
1264
+ /** When set, soft-delete sets `deletedBy` on the user row. */
1265
+ getSessionUser?: () => Promise<SessionUser | null>;
1266
+ }
1267
+ declare function createUsersApiHandlers(config: UsersApiConfig): {
1268
+ list(req: Request): Promise<Response>;
1269
+ create(req: Request): Promise<Response>;
1270
+ getById(_req: Request, id: string): Promise<Response>;
1271
+ update(req: Request, id: string): Promise<Response>;
1272
+ delete(_req: Request, id: string): Promise<Response>;
1273
+ regenerateInvite(_req: Request, id: string): Promise<Response>;
1274
+ };
1275
+ interface UserAvatarConfig extends CmsHandlersBase {
1276
+ getSession: () => Promise<{
1277
+ user?: {
1278
+ email?: string | null;
1279
+ };
1280
+ } | null>;
1281
+ /** Save avatar (buffer, fileName) => publicUrl. Default: local public/uploads/avatars */
1282
+ saveAvatar?: (buffer: Buffer, fileName: string) => Promise<string>;
1283
+ }
1284
+ declare function createUserAvatarHandler(config: UserAvatarConfig): (req: Request) => Promise<Response>;
1285
+ interface UserProfileConfig extends CmsHandlersBase {
1286
+ dataSource: DataSource;
1287
+ entityMap: EntityMap$2;
1288
+ getSession: () => Promise<{
1289
+ user?: {
1290
+ id?: string;
1291
+ email?: string | null;
1292
+ name?: string | null;
1293
+ };
1294
+ } | null>;
1295
+ /** Optional hook after a successful profile PUT (e.g. audit logging). */
1296
+ onProfileUpdated?: (req: Request, user: {
1297
+ id: number;
1298
+ name: string;
1299
+ email: string;
1300
+ phone: string | null;
1301
+ }) => Promise<void>;
1302
+ }
993
1303
  /**
994
- * Optional `llm_agents` row: when present and enabled, model / temperature / max_tokens
995
- * are applied to {@link LlmServiceInterface.chatAgent} (system + user content still come from blog generator defaults / UI).
1304
+ * GET / PUT handlers for `/api/users/profile` (current session user).
1305
+ * GET merges DB fields with the session; PUT updates the user row and callers should refresh the client session (e.g. `useSession().update()`).
996
1306
  */
997
- declare const BLOG_GENERATOR_LLM_AGENT_SLUG = "blog-generator";
998
- /** Line that separates multiple articles in the model reply (HTML or legacy markdown; must match parser and prompts). */
999
- declare const BLOG_GENERATOR_MARKDOWN_ARTICLE_SEPARATOR = "---BLOG_GENERATOR_NEXT---";
1000
- declare const BLOG_GENERATOR_DEFAULT_SYSTEM_INSTRUCTION = "You are a professional financial and business content writer.\n\nYour task is to generate completely original, high-quality blog article(s) from the latest RSS-derived source material in the user message (one block per feed). The user message is factual input only.\n\nIMPORTANT RULES:\n\n1. NEVER copy the RSS article directly.\n2. Rewrite the information into a fresh, human-like article.\n3. Expand the topic with professional insights and explanations.\n4. Maintain a natural editorial tone.\n5. Make the article SEO-friendly.\n6. Use engaging headings and subheadings.\n7. Avoid robotic AI phrasing.\n8. Do not mention that the content came from RSS or feeds.\n9. Preserve factual accuracy from the source material.\n10. The output should feel like a professionally written industry blog.\n\nMULTIPLE FEEDS:\n- If several feeds are provided, compare them: if they largely cover the same story or overlap heavily, produce ONE cohesive article.\n- If they cover clearly different topics or distinct stories, produce MULTIPLE articles (one per distinct story).\n- You may also produce one synthesis plus a short separate angle when that best serves the reader\u2014use your judgment.\n\nWRITING STYLE:\n- Professional\n- Clear\n- Informative\n- Business-focused\n- Human sounding\n- Modern editorial style\n\nARTICLE STRUCTURE (each article \u2014 express in HTML):\n1. Engaging introduction\n2. Industry context\n3. Main developments\n4. Key implications\n5. Expert/business analysis\n6. Conclusion\n\nHTML STRUCTURE (STRICT \u2014 each article must be valid, semantic HTML only):\n- Output HTML only. Do not use Markdown (no # headings, no **bold**, no `code fences`).\n- Wrap each complete article in a single root: <article class=\"blog-post\"> ... </article>\n- Inside <article>, use this outline:\n - <header><h1 class=\"blog-post-title\">\u2026main title\u2026</h1></header> (exactly one h1 per article)\n - <section class=\"blog-post-body\"> for all following content\n - Use <h2> and <h3> for section and subsection titles (never skip levels: h1 \u2192 h2 \u2192 h3).\n - Use <p> for paragraphs; keep paragraphs focused (avoid huge unbroken text).\n - Use <ul>/<ol> with <li> for lists where appropriate.\n - Use <strong> and <em> for emphasis sparingly; use <blockquote> only when quoting or callouts fit.\n- Do not include <html>, <head>, <body>, or document-level wrappers \u2014 only the fragment(s) described above.\n- Do not use <script>, <style>, <iframe>, or inline event handlers. Avoid inline style=\"\" except when essential for accessibility (prefer none).\n- Escape angle brackets in body text if you must mention markup; keep output safe for embedding in a CMS.\n\nCONTENT REQUIREMENTS:\n- Minimum 800 words per article unless source material is very small.\n- Add context around industry trends where appropriate.\n- Explain why the topic matters.\n- Include practical implications for businesses/professionals.\n\nIF RSS CONTENT IS LIMITED:\n- Expand intelligently using general industry knowledge.\n- Keep the article relevant to the original topic.\n- Do not invent fake facts or statistics.\n\nOUTPUT FORMAT (STRICT \u2014 HTML only):\n- Return ONLY the article HTML fragment(s). No JSON, no preamble or postscript (\"Here is your article\u2026\"), no markdown.\n- If you output more than one article, output multiple <article class=\"blog-post\">\u2026</article> blocks in sequence, and between articles put a single line containing exactly this (and nothing else on that line):\n---BLOG_GENERATOR_NEXT---\n- If you output a single article, use one <article> only and do not use that separator line.";
1307
+ declare function createUserProfileHandler(config: UserProfileConfig): {
1308
+ GET(_req: Request): Promise<Response>;
1309
+ PUT(req: Request): Promise<Response>;
1310
+ };
1311
+ interface SettingsApiConfig extends CmsHandlersBase {
1312
+ dataSource: DataSource;
1313
+ entityMap: EntityMap$2;
1314
+ encryptionKey?: string;
1315
+ /** Groups in this list are readable without auth (GET returns all keys for the group). */
1316
+ publicGetGroups?: string[];
1317
+ }
1318
+ declare function simpleEncrypt(text: string, key: string): string;
1319
+ declare function simpleDecrypt(encoded: string, key: string): string;
1001
1320
  /**
1002
- * JSON so {@link parseLlmAgentValidationRules} can attach guardrails and allow long source payloads.
1003
- * Edit in the admin UI if needed; defaults match product intent.
1321
+ * Structural types so apps with their own `typeorm` install (e.g. npm link) typecheck without duplicate-package errors.
1004
1322
  */
1005
- declare const BLOG_GENERATOR_DEFAULT_VALIDATION_RULES: string;
1323
+ type GetPublicSettingsGroupDataSource = {
1324
+ getRepository(entity: unknown): {
1325
+ find(options: object): Promise<unknown[]>;
1326
+ };
1327
+ };
1328
+ interface GetPublicSettingsGroupConfig {
1329
+ dataSource: GetPublicSettingsGroupDataSource;
1330
+ entityMap: Record<string, unknown>;
1331
+ encryptionKey?: string;
1332
+ }
1333
+ /** Same rows as unauthenticated GET /api/settings/:group when the group is in publicGetGroups. */
1334
+ declare function getPublicSettingsGroup(config: GetPublicSettingsGroupConfig, group: string): Promise<Record<string, string>>;
1335
+ declare function createSettingsApiHandlers(config: SettingsApiConfig): {
1336
+ GET(req: Request, group: string): Promise<Response>;
1337
+ PUT(req: Request, group: string): Promise<Response>;
1338
+ };
1339
+ interface ChatApiConfig extends CmsHandlersBase {
1340
+ dataSource: DataSource;
1341
+ entityMap: EntityMap$2;
1342
+ getCms: () => Promise<{
1343
+ getPlugin: (name: string) => unknown;
1344
+ }>;
1345
+ }
1346
+ /** Safe subset of `llm` settings for the storefront chat widget (`GET /api/chat/config`). */
1347
+ interface ChatPublicConfig {
1348
+ enabled: boolean;
1349
+ chatMode: 'whatsapp' | 'external' | 'llm';
1350
+ /** When `chatMode === 'llm'`, slug of the chatbot-scoped agent (`llm_agents.scope = chatbot`). */
1351
+ agentSlug: string;
1352
+ botName: string;
1353
+ icon: string;
1354
+ iconImageUrl: string;
1355
+ iconBackgroundColor: string;
1356
+ headerColor: string;
1357
+ whatsappPhone: string;
1358
+ }
1006
1359
 
1007
1360
  /**
1008
- * Second-step LLM: classifies one finished HTML blog body into CMS fields (category, SEO, tags).
1009
- *
1010
- * Optional `llm_agents` row: slug {@link BLOG_METADATA_ENRICHER_LLM_AGENT_SLUG} — when present and enabled,
1011
- * model / temperature / max_tokens apply to this call only (writer step uses `blog-generator`).
1361
+ * Admin API: attach knowledge base documents to an LLM agent, ingest text into chunks + embeddings.
1362
+ * Routes: GET/POST /api/llm_agents/:slug/knowledge, DELETE /api/llm_agents/:slug/knowledge/:documentId
1012
1363
  *
1013
- * To change how metadata is produced, edit the constants in this file (system instruction + validation JSON).
1014
- * No admin UI override is wired yet; add request body fields in `cms-api-handler` if you need runtime overrides later.
1364
+ * Pipeline logs (grep `[llm-agent-knowledge] pipeline`):
1365
+ * - 01_request incoming POST, content-type preview
1366
+ * - 02_agent_loaded — agent id for slug
1367
+ * - 03_body_parsed — JSON vs multipart, sizes / documentId
1368
+ * - 04_* — file decode or PDF extract (multipart)
1369
+ * - 05_branch — link_existing_document | new_upload_ingest
1370
+ * - 06_* — KB row + junction (link create / exists)
1371
+ * - 06b_chunks_existing_count — link path: existing chunk rows
1372
+ * - 06_knowledge_document_saved — new ingest: document row id
1373
+ * - 07_chunk_split — split stats
1374
+ * - 07b_chunks_persisted — chunk rows saved
1375
+ * - 07_query_chunks_missing_embedding — link path: rows with NULL embedding
1376
+ * - 08_* — resolve LLM plugin, embed availability or skip
1377
+ * - 09_embedding_workers_start / 10_embedding_workers_finished — concurrent embed+DB update
1378
+ * - 11_response — final outcome summary
1379
+ * - 99_pipeline_error — uncaught exception
1015
1380
  */
1016
- declare const BLOG_METADATA_ENRICHER_AGENT_NAME = "Blog Generator Metadata";
1017
- /** `llm_agents.slug` for routing model/temperature for the metadata-only chat step. */
1018
- declare const BLOG_METADATA_ENRICHER_LLM_AGENT_SLUG = "blog-generator-metadata";
1019
- declare const BLOG_METADATA_ENRICHER_DEFAULT_SYSTEM_INSTRUCTION = "You are a careful CMS metadata assistant for a publishing system.\n\nYou receive ONE complete blog post as HTML (title is usually in <h1 class=\"blog-post-title\"> or the first <h1>). Your job is to propose structured fields so an editor can save the post: category, URL slug, SEO block, and topical tags.\n\nRULES:\n1. Read the whole article and infer the primary topic and audience.\n2. categoryName must be EXACTLY one string from AVAILABLE_BLOG_CATEGORIES in the user message, or \"\" if none fit.\n3. blogSlug: lowercase kebab-case, ASCII letters/digits/hyphens only, no leading/trailing hyphens, max ~80 chars. Derive from the main topic or title.\n4. seo.title: concise meta title (~50\u201360 characters when reasonable).\n5. seo.description: meta description (~150\u2013160 characters when reasonable), plain text.\n6. seo.keywords: comma-separated phrases, no stuffing.\n7. seo.ogTitle / seo.ogDescription: may mirror title/description or be slightly adapted for social.\n8. tags: 4\u201310 short labels (1\u20133 words each). Prefer exact matches from EXISTING_TAG_NAMES when they truly apply; otherwise invent precise new labels (they may be created in the CMS later).\n9. Do not invent statistics, quotes, or URLs not implied by the article.\n10. Output JSON only \u2014 no markdown outside the JSON, no commentary.\n\nOUTPUT FORMAT (STRICT):\nReturn a single JSON object only. Do not wrap it in a markdown code fence.\n\n{\n \"categoryName\": \"string \u2014 exact match from list or empty string\",\n \"blogSlug\": \"string \u2014 url-safe kebab-case\",\n \"seo\": {\n \"title\": \"string or empty\",\n \"description\": \"string or empty\",\n \"keywords\": \"string or empty\",\n \"ogTitle\": \"string or empty\",\n \"ogDescription\": \"string or empty\"\n },\n \"tags\": [\"tag-one\", \"tag-two\"]\n}";
1020
- declare const BLOG_METADATA_ENRICHER_DEFAULT_VALIDATION_RULES: string;
1021
1381
 
1022
- interface BlogGeneratorPluginConfig {
1023
- /** Set to false to skip registering the plugin. */
1024
- enabled?: boolean;
1382
+ interface LlmAgentKnowledgeApiConfig {
1383
+ dataSource: DataSource;
1384
+ entityMap: EntityMap$2;
1385
+ getCms: () => Promise<{
1386
+ getPlugin: (name: string) => unknown;
1387
+ }>;
1388
+ json: (body: unknown, init?: {
1389
+ status?: number;
1390
+ }) => Response;
1391
+ requireAuth: (req: Request) => Promise<Response | null>;
1392
+ requireEntityPermission?: RequireEntityPermissionFn;
1025
1393
  }
1026
- declare function blogGeneratorPlugin(config?: BlogGeneratorPluginConfig): CmsPlugin<BlogGeneratorService | undefined>;
1394
+ declare function createLlmAgentKnowledgeHandlers(config: LlmAgentKnowledgeApiConfig): {
1395
+ list(req: Request, slug: string): Promise<Response>;
1396
+ post(req: Request, slug: string): Promise<Response>;
1397
+ unlink(req: Request, slug: string, documentIdStr: string): Promise<Response>;
1398
+ } | null;
1027
1399
 
1028
- interface SocialMediaApiConfig {
1400
+ /**
1401
+ * Single CMS API handler: dashboard, analytics, upload, media zip extract, blog/form by slug, users API, user auth, CRUD. Mount once (e.g. app/api/[[...path]]/route.ts).
1402
+ */
1403
+
1404
+ /** CMS instance with getPlugin; when provided, analytics and userAuth.sendEmail can be resolved from plugins when not passed. */
1405
+ type CmsGetter = () => Promise<{
1406
+ getPlugin: (name: string) => unknown;
1407
+ }>;
1408
+ interface CmsApiHandlerConfig {
1029
1409
  dataSource: DataSource;
1030
1410
  entityMap: EntityMap$2;
1411
+ requireAuth: (req: Request) => Promise<Response | null>;
1031
1412
  json: (body: unknown, init?: {
1032
1413
  status?: number;
1033
1414
  }) => Response;
1034
- requireAuth: (req: Request) => Promise<Response | null>;
1035
- requireEntityPermission: (req: Request, entity: string, action: EntityCrudAction) => Promise<Response | null>;
1036
- encryptionKey?: string;
1037
- /** Used to resolve relative cover image URLs (e.g. https://mysite.com). */
1038
- publicSiteUrl?: string;
1415
+ pathToModel?: (segment: string) => string;
1416
+ crudResources?: string[];
1417
+ /** When set, analytics and userAuth.sendEmail can be derived from getPlugin('analytics') and getPlugin('email') when not provided. */
1418
+ getCms?: CmsGetter;
1419
+ /** Optional: used when deriving userAuth.sendEmail to pass company details into email templates (e.g. from settings). */
1420
+ getCompanyDetails?: () => Promise<CompanyDetails>;
1421
+ /** Optional: used for form submission and other channel-based email recipients (from settings group "email"). */
1422
+ getRecipientForChannel?: (channel: 'crm' | 'sales' | 'fulfilment') => Promise<string | null>;
1423
+ userAuth?: UserAuthApiConfig;
1424
+ /** GET /api/dashboard/stats */
1425
+ dashboard?: DashboardStatsConfig;
1426
+ /** GET /api/dashboard/ecommerce */
1427
+ ecommerceAnalytics?: EcommerceAnalyticsConfig;
1428
+ /** GET /api/analytics. If omitted and getCms is set, uses getCms().getPlugin('analytics'). */
1429
+ analytics?: AnalyticsHandlerConfig;
1430
+ /** POST /api/upload (S3 or local) */
1431
+ upload?: UploadHandlerConfig;
1432
+ /** GET /api/blogs/slug/:slug (public) */
1433
+ blogBySlug?: BlogBySlugConfig;
1434
+ /** GET /api/forms/slug/:slug (public) */
1435
+ formBySlug?: FormBySlugConfig;
1436
+ /** POST/PUT /api/forms (save form + fields; when set, overrides CRUD for forms) */
1437
+ formSave?: FormSaveHandlersConfig;
1438
+ /** POST /api/form-submissions (public, no auth) */
1439
+ formSubmission?: FormSubmissionHandlerConfig;
1440
+ /** GET /api/form-submissions/:id (auth) with form + contact relations */
1441
+ formSubmissionGetById?: FormSubmissionGetByIdConfig;
1442
+ /** GET/POST /api/users, GET/PUT/DELETE /api/users/:id, POST /api/users/:id/regenerate-invite */
1443
+ usersApi?: UsersApiConfig;
1444
+ /** POST /api/users/avatar */
1445
+ userAvatar?: UserAvatarConfig;
1446
+ /** GET/PUT /api/users/profile (current session user) */
1447
+ userProfile?: UserProfileConfig;
1448
+ /** GET/PUT /api/settings/:group */
1449
+ settings?: SettingsApiConfig;
1450
+ /** GET /api/chat/config (public); POST /api/chat/identify; GET /api/chat/conversations/:id/messages; POST /api/chat/messages */
1451
+ chat?: ChatApiConfig;
1039
1452
  /**
1040
- * When true (default), `console.info` / `console.warn` lines are emitted for LinkedIn blog publish
1041
- * (text vs image path, sizes, errors). Set false or `CMS_LINKEDIN_PUBLISH_LOG=0` to silence.
1453
+ * GET/POST /api/llm_agents/:slug/knowledge; DELETE …/knowledge/:documentId agent KB ingest + links.
1454
+ * When omitted but `chat` is set, the same dataSource / entityMap / getCms / json / requireAuth are reused automatically.
1042
1455
  */
1043
- linkedInPublishLogging?: boolean;
1044
- }
1045
- declare function createSocialMediaHandlers(config: SocialMediaApiConfig): {
1046
- getLinkedInStatus(req: Request): Promise<Response>;
1047
- fetchLinkedInOrganizations(req: Request): Promise<Response>;
1048
- syncLinkedInProfile(req: Request): Promise<Response>;
1049
- publishBlogToLinkedIn(req: Request, blogId: number): Promise<Response>;
1050
- getFacebookStatus(req: Request): Promise<Response>;
1051
- publishBlogToFacebook(req: Request, blogId: number): Promise<Response>;
1456
+ llmAgentKnowledge?: LlmAgentKnowledgeApiConfig;
1052
1457
  /**
1053
- * POST JSON `{ appId, appSecret, userAccessToken }`. Calls Graph `GET /me/accounts` with the user token.
1054
- * App ID and secret are validated but not used yet (reserved for future token flows).
1055
- * Persist credentials via Plugins → Save: `meta_app_id` (public), `meta_app_secret` and `meta_user_access_token` (encrypted).
1458
+ * Entity-level RBAC (session `entityPerms` / Administrator). When omitted, admin routes that need it respond with 403
1459
+ * (`entity_rbac_required`) so CRUD cannot run as auth-only. Pass `createAuthHelpers(...).requireEntityPermission` from the app.
1056
1460
  */
1057
- fetchFacebookManagedPages(req: Request): Promise<Response>;
1461
+ requireEntityPermission?: (req: Request, entity: string, action: EntityCrudAction) => Promise<Response | null>;
1462
+ /** Required for vendor store RBAC + scoping. Alias: `getAuthenticatedUser`. */
1463
+ getSessionUser?: () => Promise<SessionUser | null>;
1464
+ /** Same as `getSessionUser` (from `createAuthHelpers().getAuthenticatedUser`). */
1465
+ getAuthenticatedUser?: () => Promise<SessionUser | null>;
1466
+ }
1467
+ declare function createCmsApiHandler(config: CmsApiHandlerConfig): {
1468
+ handle(method: string, pathInput: string[], req: Request): Promise<Response>;
1058
1469
  };
1059
1470
 
1060
- /**
1061
- * Meta (Facebook) Graph API helpers (server-side). Uses fetch — no SDK.
1062
- * @see https://developers.facebook.com/docs/graph-api/reference/user/accounts
1063
- */
1064
- type FacebookPageAccount = {
1065
- access_token?: string;
1066
- category?: string;
1067
- name?: string;
1068
- id?: string;
1069
- /** Graph may return additional fields */
1070
- [key: string]: unknown;
1071
- };
1072
- type FacebookMeAccountsResponse = {
1073
- data?: FacebookPageAccount[];
1074
- paging?: Record<string, unknown>;
1075
- error?: {
1076
- message?: string;
1077
- type?: string;
1078
- code?: number;
1079
- fbtrace_id?: string;
1080
- };
1081
- };
1082
- /**
1083
- * Lists Facebook Pages the user manages (page access tokens + metadata).
1084
- * Requires a User access token with `pages_show_list` or equivalent page permissions.
1085
- */
1086
- declare function metaFetchUserManagedPages(userAccessToken: string): Promise<FacebookMeAccountsResponse>;
1087
- type MetaGraphMutationResponse = {
1088
- id?: string;
1089
- post_id?: string;
1090
- error?: {
1091
- message?: string;
1092
- type?: string;
1093
- code?: number;
1094
- fbtrace_id?: string;
1095
- };
1471
+ interface JobScheduleApiConfig {
1472
+ dataSource: DataSource;
1473
+ entityMap: EntityMap$2;
1474
+ json: (body: unknown, init?: ResponseInit) => Response;
1475
+ requireAuth: (req: Request) => Promise<Response | null>;
1476
+ requireEntityPermission?: (req: Request, entity: string, action: 'read' | 'create' | 'update' | 'delete') => Promise<Response | null>;
1477
+ getCms?: CmsGetter;
1478
+ config?: Record<string, string>;
1479
+ }
1480
+ declare function createJobScheduleHandlers(apiConfig: JobScheduleApiConfig): {
1481
+ list(req: Request): Promise<Response>;
1482
+ getById(req: Request, id: string): Promise<Response>;
1483
+ create(req: Request): Promise<Response>;
1484
+ update(req: Request, id: string): Promise<Response>;
1485
+ remove(req: Request, id: string): Promise<Response>;
1486
+ runNow(req: Request, id: string): Promise<Response>;
1487
+ listRuns(req: Request, id: string): Promise<Response>;
1096
1488
  };
1097
- /** Resolves the long-lived page access token for a Page ID from `/me/accounts` data. */
1098
- declare function metaResolvePageAccessToken(accounts: FacebookMeAccountsResponse, pageId: string): string | null;
1099
- /**
1100
- * Upload a photo to a Page timeline (multipart).
1101
- * @see https://developers.facebook.com/docs/graph-api/reference/page/photos#Creating
1102
- */
1103
- declare function metaPostPagePhoto(opts: {
1104
- pageId: string;
1105
- pageAccessToken: string;
1106
- imageBuffer: Buffer;
1107
- contentType: string;
1108
- caption: string;
1109
- }): Promise<MetaGraphMutationResponse>;
1110
- /**
1111
- * Publish a text-only post to the Page feed (when no JPEG/PNG image is available).
1112
- * @see https://developers.facebook.com/docs/graph-api/reference/page/feed#Creating
1113
- */
1114
- declare function metaPostPageFeed(opts: {
1115
- pageId: string;
1116
- pageAccessToken: string;
1117
- message: string;
1118
- }): Promise<MetaGraphMutationResponse>;
1119
1489
 
1120
- interface SocialMediaPluginConfig {
1121
- /** Set to false to skip registering the plugin instance (API routes still work if wired in the app handler). */
1122
- enabled?: boolean;
1490
+ interface EventNotificationHandlersConfig {
1491
+ dataSource: DataSource;
1492
+ entityMap: EntityMap$2;
1493
+ json: (body: unknown, init?: {
1494
+ status?: number;
1495
+ }) => Response;
1496
+ requireAuth: (req: Request) => Promise<Response | null>;
1497
+ requireEntityPermission?: RequireEntityPermissionFn;
1498
+ getCms?: () => Promise<CmsAppLike$3>;
1123
1499
  }
1124
- /**
1125
- * Optional CMS plugin instance for `getPlugin('social_media')`.
1126
- * LinkedIn publishing is implemented in {@link createSocialMediaHandlers} and mounted from the CMS API handler.
1127
- */
1128
- declare function socialMediaPlugin(config?: SocialMediaPluginConfig): CmsPlugin<{
1129
- name: string;
1130
- } | undefined>;
1500
+ declare function createEventNotificationHandlers(config: EventNotificationHandlersConfig): {
1501
+ getSettings(req: Request, id: string): Promise<Response>;
1502
+ updateSettings(req: Request, id: string): Promise<Response>;
1503
+ sendTest(req: Request, id: string): Promise<Response>;
1504
+ };
1131
1505
 
1132
- declare function cn(...inputs: ClassValue[]): string;
1133
- declare function generateSlug(title: string): string;
1134
- declare function validateSlug(slug: string): boolean;
1135
- declare function formatDate(date: Date | string): string;
1136
- declare function formatDateTime(date: Date | string): string;
1137
- declare function formatDateOnly(date: Date | string): string;
1138
- declare function truncateText(text: string, maxLength: number): string;
1139
-
1140
- /** Minimal SEO row shape (DB or API). */
1141
- type SeoLike = {
1142
- title?: string | null;
1143
- description?: string | null;
1144
- keywords?: string | null;
1145
- ogTitle?: string | null;
1146
- ogDescription?: string | null;
1147
- ogImage?: string | null;
1148
- };
1149
- type SeoMetadataOverrides = {
1150
- title?: string;
1151
- description?: string;
1152
- keywords?: string;
1153
- ogTitle?: string;
1154
- ogDescription?: string;
1155
- ogImage?: string;
1156
- };
1157
- /** Per-field: join row wins over slug row. */
1158
- declare function mergeSeoBySlug(join: SeoLike | null | undefined, bySlug: SeoLike | null): SeoLike | null;
1159
- declare function fetchSeoBySlug(dataSource: DataSource, entityMap: EntityMap$2, slug: string): Promise<SeoLike | null>;
1160
- /**
1161
- * Build Next.js Metadata from merged SEO + optional layers.
1162
- * `overrides` win over SEO; `fallbacks` apply when SEO (and overrides) omit a field.
1163
- * Returns a partial object; omit fields so the root layout defaults apply.
1164
- */
1165
- declare function resolvePublicMetadata(args: {
1166
- dataSource: DataSource;
1167
- entityMap: EntityMap$2;
1168
- slug: string;
1169
- seoFromJoin?: SeoLike | null;
1170
- overrides?: SeoMetadataOverrides;
1171
- fallbacks?: SeoMetadataOverrides;
1172
- canonicalPath?: string;
1173
- metadataBase?: URL;
1174
- }): Promise<Metadata>;
1175
-
1176
- /** Links an unclaimed contact (same email, no userId) to the new user after signup or invite. */
1177
- declare function linkUnclaimedContactToUser(dataSource: DataSource, contactsEntity: EntityTarget<ObjectLiteral>, userId: number, email: string): Promise<void>;
1178
-
1179
- /** Parse stored config value into a list of emails (JSON array, or comma/semicolon-separated string). */
1180
- declare function parseEmailRecipientsFromConfig(raw: string | undefined | null): string[];
1181
- /** Serialize email list for config storage (JSON array in DB). */
1182
- declare function serializeEmailRecipients(emails: string[]): string;
1183
- /** Join for SMTP `to` header (multiple recipients). */
1184
- declare function joinRecipientsForSend(emails: string[]): string | null;
1185
-
1186
- type OtpPurpose = 'login' | 'verify_email' | 'verify_phone';
1187
- type OtpChannel = 'email' | 'sms';
1188
- declare function hashOtpCode(code: string, purpose: string, identifier: string, pepper?: string): string;
1189
- declare function verifyOtpCodeHash(code: string, storedHash: string, purpose: string, identifier: string, pepper?: string): boolean;
1190
- declare function generateNumericOtp(length?: number): string;
1191
- /** Normalize to E.164-like +digits */
1192
- declare function normalizePhoneE164(raw: string, defaultCountryCode?: string): string | null;
1193
- type EntityMap$1 = Record<string, EntityTarget<ObjectLiteral>>;
1194
- declare function countRecentOtpSends(dataSource: DataSource, entityMap: EntityMap$1, purpose: OtpPurpose, identifier: string, since: Date): Promise<number>;
1195
- declare function createOtpChallenge(dataSource: DataSource, entityMap: EntityMap$1, input: {
1196
- purpose: OtpPurpose;
1197
- channel: OtpChannel;
1198
- identifier: string;
1199
- code: string;
1200
- pepper?: string;
1201
- }): Promise<{
1202
- ok: true;
1203
- } | {
1204
- ok: false;
1205
- error: string;
1206
- status: number;
1207
- }>;
1208
- declare function verifyAndConsumeOtpChallenge(dataSource: DataSource, entityMap: EntityMap$1, input: {
1209
- purpose: OtpPurpose;
1210
- identifier: string;
1211
- code: string;
1212
- pepper?: string;
1213
- }): Promise<{
1214
- ok: true;
1215
- } | {
1216
- ok: false;
1217
- error: string;
1218
- status: number;
1219
- }>;
1220
-
1221
- /** Returns true if request is allowed; false if rate limited. */
1222
- declare function allowRateLimit(key: string): Promise<boolean>;
1223
- type ExtraPublicWriteRule = (method: string, segments: string[]) => boolean;
1224
- /** Segments are path parts after `/api/` (e.g. `['form-submissions']`). */
1225
- declare function shouldRateLimitPublicWrite(method: string, segments: string[], extraRule?: ExtraPublicWriteRule): boolean;
1226
- declare function rateLimitKeyForApiRequest(req: Request, segments: string[]): string;
1227
- declare function rateLimitPublicApiIfNeeded(req: Request, method: string, segments: string[], options?: {
1228
- extraRule?: ExtraPublicWriteRule;
1229
- }): Promise<Response | null>;
1230
- declare function rateLimitCheckoutPost(req: Request): Promise<Response | null>;
1231
-
1232
- interface EntityMapLike$1 {
1233
- configs: unknown;
1234
- orders: unknown;
1235
- order_items: unknown;
1236
- }
1237
- interface SendOrderPlacedEmailDeps {
1238
- getDataSource: () => Promise<DataSource>;
1239
- entityMap: EntityMapLike$1;
1240
- getCms: () => Promise<CmsApp>;
1241
- }
1242
- /** After payment confirmation: email customer + each sales team address from plugin settings. */
1243
- declare function sendOrderPlacedEmailsAfterConfirmation(orderId: number, deps: SendOrderPlacedEmailDeps): Promise<void>;
1244
-
1245
- type VendorOnboardedActivation = 'invite' | 'password';
1246
- type VendorOnboardedKind = 'vendor_onboard' | 'team_invite';
1247
-
1248
- interface EntityMapLike {
1249
- configs: unknown;
1250
- }
1251
- interface SendVendorOnboardEmailInput {
1252
- vendorName: string;
1253
- vendorSlug?: string;
1254
- ownerName: string;
1255
- ownerEmail: string;
1256
- activation: VendorOnboardedActivation;
1257
- inviteLink?: string;
1258
- signInLink: string;
1259
- kind?: VendorOnboardedKind;
1260
- /** When false, skips owner email but still notifies internal recipients. Default true. */
1261
- sendToOwner?: boolean;
1262
- }
1263
- interface SendVendorOnboardEmailDeps {
1264
- getDataSource: () => Promise<DataSource>;
1265
- entityMap: EntityMapLike;
1266
- getCms: () => Promise<CmsAppLike$2>;
1267
- }
1268
- /** After vendor onboard / team invite: email owner + platform team from plugin settings. */
1269
- declare function sendVendorOnboardEmails(input: SendVendorOnboardEmailInput, deps: SendVendorOnboardEmailDeps): Promise<{
1270
- ownerEmailSent: boolean;
1271
- }>;
1272
-
1273
- interface DataSourceManager {
1274
- getDataSource: () => DataSource;
1275
- getDataSourceInitialized: () => Promise<DataSource>;
1276
- resetDataSource: () => void;
1277
- registerOnReset: (cb: () => void) => void;
1278
- isConnectionError: (e: unknown) => boolean;
1279
- }
1280
- declare function createDataSourceManager(entityMap: Record<string, unknown>, options?: {
1281
- databaseUrl?: string;
1282
- idleTimeoutMillis?: number;
1283
- }): DataSourceManager;
1284
-
1285
- interface SeedEntityMap {
1286
- users: unknown;
1287
- user_groups: unknown;
1288
- }
1289
- declare function seedDefaultAdmin(ds: DataSource, entityMap: SeedEntityMap, opts?: {
1290
- email?: string;
1291
- password?: string;
1292
- }): Promise<void>;
1293
-
1294
- type VendorInviteStatus = 'none' | 'pending' | 'expired' | 'accepted';
1295
- declare class Vendor {
1296
- id: number;
1297
- name: string;
1298
- slug: string;
1299
- email: string | null;
1300
- phone: string | null;
1301
- logo: string | null;
1302
- description: string | null;
1303
- metadata: Record<string, unknown> | null;
1304
- active: boolean;
1305
- /** Primary owner user for this vendor (set on onboard). */
1306
- userId: number | null;
1307
- inviteStatus: VendorInviteStatus;
1308
- createdAt: Date;
1309
- updatedAt: Date;
1310
- deletedAt: Date | null;
1311
- deleted: boolean;
1312
- createdBy: number | null;
1313
- updatedBy: number | null;
1314
- deletedBy: number | null;
1315
- vendorUsers: VendorUser[];
1316
- }
1506
+ interface EventOrderMessageTemplateHandlersConfig {
1507
+ dataSource: DataSource;
1508
+ entityMap: EntityMap$2;
1509
+ json: (body: unknown, init?: {
1510
+ status?: number;
1511
+ }) => Response;
1512
+ requireAuth: (req: Request) => Promise<Response | null>;
1513
+ requireEntityPermission?: RequireEntityPermissionFn;
1514
+ }
1515
+ declare function createEventOrderMessageTemplateHandlers(config: EventOrderMessageTemplateHandlersConfig): {
1516
+ GET(req: Request): Promise<Response>;
1517
+ PUT(req: Request): Promise<Response>;
1518
+ };
1317
1519
 
1318
1520
  declare class Permission {
1319
1521
  id: number;
@@ -1369,117 +1571,138 @@ declare class User {
1369
1571
  group: UserGroup | null;
1370
1572
  }
1371
1573
 
1574
+ declare class VendorRolePermission {
1575
+ id: number;
1576
+ vendorRoleId: number;
1577
+ entity: string;
1578
+ canCreate: boolean;
1579
+ canRead: boolean;
1580
+ canUpdate: boolean;
1581
+ canDelete: boolean;
1582
+ createdAt: Date;
1583
+ updatedAt: Date;
1584
+ role: VendorRole;
1585
+ }
1586
+
1587
+ declare class VendorRole {
1588
+ id: number;
1589
+ vendorId: number;
1590
+ name: string;
1591
+ description: string | null;
1592
+ isSystem: boolean;
1593
+ isOwnerRole: boolean;
1594
+ createdAt: Date;
1595
+ updatedAt: Date;
1596
+ deletedAt: Date | null;
1597
+ deleted: boolean;
1598
+ vendor: Vendor;
1599
+ permissions: VendorRolePermission[];
1600
+ }
1601
+
1372
1602
  /** Links a staff user to a vendor store. */
1373
1603
  type VendorUserRole = 'owner' | 'staff';
1374
1604
  declare class VendorUser {
1375
1605
  id: number;
1376
1606
  vendorId: number;
1377
1607
  userId: number;
1608
+ /** @deprecated use vendorRoleId — kept for migration compatibility */
1378
1609
  role: VendorUserRole;
1610
+ vendorRoleId: number | null;
1379
1611
  createdAt: Date;
1380
1612
  updatedAt: Date;
1381
1613
  vendor: Vendor;
1382
1614
  user: User;
1615
+ vendorRole: VendorRole | null;
1383
1616
  }
1384
1617
 
1385
- /** Load vendor membership for session (call from app `getUserByEmail`).
1386
- *
1387
- * Uses a raw SQL query so it works even when the consuming app's DataSource
1388
- * does not explicitly register the VendorUser entity.
1389
- */
1390
- declare function loadUserVendorContext(dataSource: DataSource, userId: number, preferredVendorId?: number | null): Promise<{
1391
- vendorIds: number[];
1392
- activeVendorId: number | null;
1393
- vendorRole: VendorUserRole | null;
1394
- }>;
1395
-
1396
- /** Attach vendorIds / activeVendorId / vendorRole for NextAuth (use in app getUserByEmail). */
1397
- declare function enrichUserWithVendorContext(dataSource: DataSource, user: NextAuthUser | null): Promise<NextAuthUser | null>;
1398
-
1399
- /** Merge DB group + vendor_users into session (JWT often missing these). Server/API only. */
1400
- declare function hydrateVendorSessionUser(dataSource: DataSource, user: SessionUser | null | undefined): Promise<SessionUser | null | undefined>;
1401
-
1402
- interface PublicThemeSettingsPayload {
1403
- activeThemeId: string;
1404
- primaryColor: string;
1405
- secondaryColor: string;
1406
- navbarConfig: NavbarConfig;
1407
- footerOverrides: Partial<FooterConfig>;
1618
+ type VendorInviteStatus = 'none' | 'pending' | 'expired' | 'accepted';
1619
+ type VendorRegistrationStatus = 'pending' | 'approved' | 'rejected' | 'suspended';
1620
+ declare class Vendor {
1621
+ id: number;
1622
+ name: string;
1623
+ slug: string;
1624
+ email: string | null;
1625
+ phone: string | null;
1626
+ legalName: string | null;
1627
+ businessType: string | null;
1628
+ website: string | null;
1629
+ addressLine1: string | null;
1630
+ addressLine2: string | null;
1631
+ city: string | null;
1632
+ state: string | null;
1633
+ country: string | null;
1634
+ postalCode: string | null;
1635
+ gstin: string | null;
1636
+ pan: string | null;
1637
+ logo: string | null;
1638
+ description: string | null;
1639
+ metadata: Record<string, unknown> | null;
1640
+ active: boolean;
1641
+ /** Primary owner user for this vendor (set on onboard). */
1642
+ userId: number | null;
1643
+ inviteStatus: VendorInviteStatus;
1644
+ registrationStatus: VendorRegistrationStatus;
1645
+ createdAt: Date;
1646
+ updatedAt: Date;
1647
+ deletedAt: Date | null;
1648
+ deleted: boolean;
1649
+ createdBy: number | null;
1650
+ updatedBy: number | null;
1651
+ deletedBy: number | null;
1652
+ vendorUsers: VendorUser[];
1408
1653
  }
1409
- declare function loadPublicThemeSettings(config: {
1410
- dataSource: DataSource;
1411
- entityMap: EntityMap$2;
1412
- encryptionKey?: string;
1413
- defaultActiveThemeId?: string;
1414
- defaultPrimaryColor?: string;
1415
- defaultSecondaryColor?: string;
1416
- }): Promise<PublicThemeSettingsPayload>;
1417
1654
 
1418
- /** Normalize a logical media folder path: no leading/trailing slashes, no ".." segments, max length. */
1419
- declare function sanitizeMediaFolderPath(input: unknown): string;
1420
- /** Single path segment for storage (folder name or legacy path segment). */
1421
- declare function sanitizeStorageSegment(name: string): string;
1422
-
1423
- type EntityMap = Record<string, EntityTarget<ObjectLiteral>>;
1424
- /** Build `a/b/c` path under `uploads/` from the chain of folder rows up to root. */
1425
- declare function relativePathFromMediaParentId(dataSource: DataSource, entityMap: EntityMap, parentId: number | null): Promise<string>;
1426
-
1427
- declare const ZIP_MIME_TYPES: Set<string>;
1428
- declare function isZipMedia(mime: string | null | undefined, filename: string): boolean;
1429
-
1430
- /**
1431
- * Executes `fn` inside a transaction where the PostgreSQL GUC
1432
- * `app.vendor_id` is set for the duration of that transaction.
1433
- *
1434
- * This activates the `vendor_isolation` RLS policy added by the
1435
- * `VendorRls1775940000000` migration.
1436
- *
1437
- * vendorId = 0 → admin / all-access (policy allows everything)
1438
- * vendorId > 0 → only rows whose `vendorId` column matches
1439
- *
1440
- * Example:
1441
- * const orders = await withVendorRlsContext(dataSource, 4, (ds) =>
1442
- * ds.getRepository(Order).find({ where: { deleted: false } })
1443
- * );
1444
- */
1445
- declare function withVendorRlsContext<T>(dataSource: DataSource, vendorId: number, fn: (dataSource: DataSource) => Promise<T>): Promise<T>;
1446
- /**
1447
- * Convenience wrapper: sets admin mode (vendor_id = '0') so all rows are
1448
- * visible regardless of their vendorId. Use for platform-admin queries.
1449
- */
1450
- declare function withAdminRlsContext<T>(dataSource: DataSource, fn: (dataSource: DataSource) => Promise<T>): Promise<T>;
1451
-
1452
- declare function isCustomerTypeContact(type: unknown): boolean;
1453
- /** Restrict contact list to rows linked in `vendor_customers` with type customer. */
1454
- declare function applyVendorCustomersContactFilter(qb: SelectQueryBuilder<typeorm.ObjectLiteral>, contactAlias: string, scope: VendorScope, vendorIdFilter: number | null): void;
1455
- declare function contactIsVendorCustomer(dataSource: DataSource, entityMap: EntityMap$2, vendorId: number, contactId: number): Promise<boolean>;
1456
- /** Returns an error message when the contact is not a vendor-linked customer; otherwise null. */
1457
- declare function assertContactAllowedForVendorOrder(dataSource: DataSource, entityMap: EntityMap$2, vendorId: number, contactId: number): Promise<string | null>;
1458
- declare function resolveVendorIdForContactCheck(scope: VendorScope, bodyOrRow: Record<string, unknown>): number | null;
1459
-
1460
- declare class OtpChallenge {
1655
+ declare class FormField {
1461
1656
  id: number;
1462
- purpose: string;
1463
- channel: string;
1464
- identifier: string;
1465
- codeHash: string;
1466
- expiresAt: Date;
1467
- attempts: number;
1468
- consumedAt: Date | null;
1657
+ formId: number;
1658
+ label: string;
1659
+ type: string;
1660
+ placeholder: string | null;
1661
+ options: string | null;
1662
+ required: boolean;
1663
+ validation: string | null;
1664
+ order: number;
1665
+ groupId: number;
1666
+ columnWidth: number;
1469
1667
  createdAt: Date;
1668
+ updatedAt: Date;
1669
+ deletedAt: Date | null;
1670
+ deleted: boolean;
1671
+ createdBy: number | null;
1672
+ updatedBy: number | null;
1673
+ deletedBy: number | null;
1674
+ form: Form;
1470
1675
  }
1471
1676
 
1472
- declare class PasswordResetToken {
1677
+ declare class Address {
1473
1678
  id: number;
1474
- email: string;
1475
- token: string;
1476
- expiresAt: Date;
1679
+ contactId: number;
1680
+ tag: string | null;
1681
+ line1: string | null;
1682
+ line2: string | null;
1683
+ city: string | null;
1684
+ state: string | null;
1685
+ postalCode: string | null;
1686
+ country: string | null;
1477
1687
  createdAt: Date;
1688
+ updatedAt: Date;
1689
+ contact: Contact;
1478
1690
  }
1479
1691
 
1480
- declare class Category {
1692
+ declare class ProductCategory {
1481
1693
  id: number;
1694
+ /** Null for platform catalog categories (`isCatalog`). */
1695
+ vendorId: number | null;
1696
+ /** Platform-wide catalog type — all vendors add collections/products under these categories. */
1697
+ isCatalog: boolean;
1482
1698
  name: string;
1699
+ slug: string;
1700
+ parentId: number | null;
1701
+ image: string | null;
1702
+ description: string | null;
1703
+ metadata: Record<string, unknown> | null;
1704
+ active: boolean;
1705
+ sortOrder: number;
1483
1706
  createdAt: Date;
1484
1707
  updatedAt: Date;
1485
1708
  deletedAt: Date | null;
@@ -1487,18 +1710,16 @@ declare class Category {
1487
1710
  createdBy: number | null;
1488
1711
  updatedBy: number | null;
1489
1712
  deletedBy: number | null;
1490
- blogs: Blog[];
1713
+ vendor: Vendor | null;
1714
+ parent: ProductCategory | null;
1715
+ children: ProductCategory[];
1716
+ products: Product[];
1717
+ collections: Collection[];
1491
1718
  }
1492
1719
 
1493
- declare class Seo {
1720
+ declare class Category {
1494
1721
  id: number;
1495
- title: string | null;
1496
- description: string | null;
1497
- keywords: string | null;
1498
- ogTitle: string | null;
1499
- ogDescription: string | null;
1500
- ogImage: string | null;
1501
- slug: string;
1722
+ name: string;
1502
1723
  createdAt: Date;
1503
1724
  updatedAt: Date;
1504
1725
  deletedAt: Date | null;
@@ -1564,85 +1785,15 @@ declare class Blog {
1564
1785
  tags: Tag[];
1565
1786
  }
1566
1787
 
1567
- declare class FormField {
1568
- id: number;
1569
- formId: number;
1570
- label: string;
1571
- type: string;
1572
- placeholder: string | null;
1573
- options: string | null;
1574
- required: boolean;
1575
- validation: string | null;
1576
- order: number;
1577
- groupId: number;
1578
- columnWidth: number;
1579
- createdAt: Date;
1580
- updatedAt: Date;
1581
- deletedAt: Date | null;
1582
- deleted: boolean;
1583
- createdBy: number | null;
1584
- updatedBy: number | null;
1585
- deletedBy: number | null;
1586
- form: Form;
1587
- }
1588
-
1589
- declare class Form {
1788
+ declare class Seo {
1590
1789
  id: number;
1591
- name: string;
1790
+ title: string | null;
1592
1791
  description: string | null;
1593
- campaign: string | null;
1594
- slug: string;
1595
- published: boolean;
1596
- createdAt: Date;
1597
- updatedAt: Date;
1598
- deletedAt: Date | null;
1599
- deleted: boolean;
1600
- createdBy: number | null;
1601
- updatedBy: number | null;
1602
- deletedBy: number | null;
1603
- fields: FormField[];
1604
- submissions: FormSubmission[];
1605
- }
1606
-
1607
- declare class FormSubmission {
1608
- id: number;
1609
- formId: number;
1610
- contactId: number | null;
1611
- data: Record<string, unknown>;
1612
- ipAddress: string | null;
1613
- userAgent: string | null;
1614
- createdAt: Date;
1615
- updatedAt: Date;
1616
- form: Form;
1617
- contact: Contact | null;
1618
- }
1619
-
1620
- declare class Address {
1621
- id: number;
1622
- contactId: number;
1623
- tag: string | null;
1624
- line1: string | null;
1625
- line2: string | null;
1626
- city: string | null;
1627
- state: string | null;
1628
- postalCode: string | null;
1629
- country: string | null;
1630
- createdAt: Date;
1631
- updatedAt: Date;
1632
- contact: Contact;
1633
- }
1634
-
1635
- declare class ProductCategory {
1636
- id: number;
1637
- vendorId: number;
1638
- name: string;
1792
+ keywords: string | null;
1793
+ ogTitle: string | null;
1794
+ ogDescription: string | null;
1795
+ ogImage: string | null;
1639
1796
  slug: string;
1640
- parentId: number | null;
1641
- image: string | null;
1642
- description: string | null;
1643
- metadata: Record<string, unknown> | null;
1644
- active: boolean;
1645
- sortOrder: number;
1646
1797
  createdAt: Date;
1647
1798
  updatedAt: Date;
1648
1799
  deletedAt: Date | null;
@@ -1650,11 +1801,7 @@ declare class ProductCategory {
1650
1801
  createdBy: number | null;
1651
1802
  updatedBy: number | null;
1652
1803
  deletedBy: number | null;
1653
- vendor: Vendor;
1654
- parent: ProductCategory | null;
1655
- children: ProductCategory[];
1656
- products: Product[];
1657
- collections: Collection[];
1804
+ blogs: Blog[];
1658
1805
  }
1659
1806
 
1660
1807
  declare class Brand {
@@ -1683,7 +1830,8 @@ declare class Brand {
1683
1830
 
1684
1831
  declare class Collection {
1685
1832
  id: number;
1686
- vendorId: number;
1833
+ /** Null for platform catalog collections (`isCatalog`). */
1834
+ vendorId: number | null;
1687
1835
  categoryId: number | null;
1688
1836
  brandId: number | null;
1689
1837
  name: string;
@@ -1694,6 +1842,8 @@ declare class Collection {
1694
1842
  metadata: Record<string, unknown> | null;
1695
1843
  variants: Array<Record<string, unknown>> | null;
1696
1844
  active: boolean;
1845
+ /** Platform-wide catalog type — all vendors add products under these collections. */
1846
+ isCatalog: boolean;
1697
1847
  sortOrder: number;
1698
1848
  createdAt: Date;
1699
1849
  updatedAt: Date;
@@ -1703,7 +1853,7 @@ declare class Collection {
1703
1853
  updatedBy: number | null;
1704
1854
  deletedBy: number | null;
1705
1855
  seoId: number | null;
1706
- vendor: Vendor;
1856
+ vendor: Vendor | null;
1707
1857
  seo: Seo | null;
1708
1858
  category: ProductCategory | null;
1709
1859
  brand: Brand | null;
@@ -1762,15 +1912,64 @@ declare class Tax {
1762
1912
  vendor: Vendor;
1763
1913
  }
1764
1914
 
1765
- declare class ProductTax {
1915
+ declare enum RefundPolicyStatus {
1916
+ ACTIVE = "active",
1917
+ INACTIVE = "inactive"
1918
+ }
1919
+ declare enum RefundPolicyType$1 {
1920
+ PERCENTAGE = "percentage",
1921
+ EVENT_TIERS = "event_tiers"
1922
+ }
1923
+ type RefundPolicyTierRow = {
1924
+ fromDaysBefore: number;
1925
+ toDaysBefore: number | null;
1926
+ percentage: number;
1927
+ };
1928
+ declare class RefundPolicy {
1929
+ id: number;
1930
+ name: string;
1931
+ desc?: string;
1932
+ vendorId: number;
1933
+ vendor: Vendor;
1934
+ refundWindowDays: number;
1935
+ status: RefundPolicyStatus;
1936
+ type: RefundPolicyType$1;
1937
+ value: number;
1938
+ /** Day bands before event start → refund % (when type is event_tiers). */
1939
+ tiers?: RefundPolicyTierRow[] | null;
1940
+ productConfigs: ProductConfig[];
1941
+ }
1942
+
1943
+ declare class ProductConfig {
1766
1944
  id: number;
1767
1945
  productId: number;
1768
1946
  taxId: number;
1947
+ refundPolicyId: number | null;
1769
1948
  rate: number | null;
1770
1949
  createdAt: Date;
1771
1950
  updatedAt: Date;
1772
1951
  product: Product;
1773
1952
  tax: Tax;
1953
+ refundPolicy: RefundPolicy | null;
1954
+ }
1955
+
1956
+ type ProductVariantStatus = 'draft' | 'available' | 'reserved' | 'sold';
1957
+ /** Option dimensions (Color, Size, …) plus optional `image_url` for PDP image switching. */
1958
+ type ProductVariantAttributes = Record<string, string>;
1959
+ declare class ProductVariant {
1960
+ id: number;
1961
+ productId: number;
1962
+ sku: string | null;
1963
+ price: number | null;
1964
+ compareAtPrice: number | null;
1965
+ currencyPrices: Record<string, number> | null;
1966
+ inventory: number;
1967
+ status: ProductVariantStatus;
1968
+ attributes: ProductVariantAttributes | null;
1969
+ imageUrls: string[] | null;
1970
+ createdAt: Date;
1971
+ updatedAt: Date;
1972
+ product: Product;
1774
1973
  }
1775
1974
 
1776
1975
  declare class Product {
@@ -1786,8 +1985,11 @@ declare class Product {
1786
1985
  type: 'product' | 'service';
1787
1986
  slug: string | null;
1788
1987
  name: string | null;
1988
+ /** Optional display title (kept in sync with `name` by the products API). */
1989
+ title: string | null;
1789
1990
  price: number;
1790
1991
  compareAtPrice: number | null;
1992
+ currencyPrices: Record<string, number> | null;
1791
1993
  quantity: number;
1792
1994
  status: 'draft' | 'available' | 'reserved' | 'sold';
1793
1995
  featured: boolean;
@@ -1800,13 +2002,17 @@ declare class Product {
1800
2002
  updatedBy: number | null;
1801
2003
  deletedBy: number | null;
1802
2004
  seoId: number | null;
2005
+ /** CMS form used for product checkout / attendee capture. */
2006
+ contactFormId: number | null;
1803
2007
  vendor: Vendor;
1804
2008
  seo: Seo | null;
2009
+ contactForm: Form | null;
1805
2010
  collection: Collection | null;
1806
2011
  brand: Brand | null;
1807
2012
  category: ProductCategory | null;
1808
2013
  attributes: ProductAttribute[];
1809
- taxes: ProductTax[];
2014
+ taxes: ProductConfig[];
2015
+ variants: ProductVariant[];
1810
2016
  }
1811
2017
 
1812
2018
  declare class OrderItem {
@@ -1814,6 +2020,8 @@ declare class OrderItem {
1814
2020
  orderId: number;
1815
2021
  productId: number;
1816
2022
  discountIds: number[];
2023
+ vendorId: number | null;
2024
+ vendor: Vendor | null;
1817
2025
  quantity: number;
1818
2026
  unitPrice: number;
1819
2027
  subTotal: number;
@@ -1835,6 +2043,13 @@ declare class OrderItem {
1835
2043
  product: Product;
1836
2044
  }
1837
2045
 
2046
+ declare enum PaymentStatus {
2047
+ Unpaid = "unpaid",
2048
+ Paid = "paid",
2049
+ Pending = "pending",
2050
+ Failed = "failed",
2051
+ Refunded = "refunded"
2052
+ }
1838
2053
  declare class Payment {
1839
2054
  id: number;
1840
2055
  vendorId: number;
@@ -1842,7 +2057,7 @@ declare class Payment {
1842
2057
  contactId: number | null;
1843
2058
  amount: number;
1844
2059
  currency: string;
1845
- status: 'pending' | 'processing' | 'completed' | 'failed' | 'refunded';
2060
+ status: PaymentStatus;
1846
2061
  method: string | null;
1847
2062
  externalReference: string | null;
1848
2063
  metadata: Record<string, unknown> | null;
@@ -1880,112 +2095,1087 @@ declare class OrderAddresses {
1880
2095
  shippingOrders: Order[];
1881
2096
  }
1882
2097
 
1883
- declare class Customer {
2098
+ declare class Customer {
2099
+ id: number;
2100
+ userId: number;
2101
+ user: User | null;
2102
+ name: string;
2103
+ email: string;
2104
+ phone: string;
2105
+ createdAt: Date;
2106
+ updatedAt: Date;
2107
+ deletedAt: Date | null;
2108
+ deleted: boolean;
2109
+ createdBy: number | null;
2110
+ updatedBy: number | null;
2111
+ deletedBy: number | null;
2112
+ }
2113
+
2114
+ declare class Customer_Contacts {
2115
+ id: number;
2116
+ customerId: number;
2117
+ customer: Customer;
2118
+ contactId: number;
2119
+ contact: Contact;
2120
+ }
2121
+
2122
+ type OrderKind = 'sale' | 'return' | 'replacement';
2123
+ declare enum OrderStatus {
2124
+ Pending = "pending",
2125
+ Confirmed = "confirmed",
2126
+ Processing = "processing",
2127
+ Completed = "completed",
2128
+ Cancelled = "cancelled"
2129
+ }
2130
+ declare class Order {
2131
+ id: number;
2132
+ vendorId: number;
2133
+ orderNumber: string;
2134
+ qrToken: string | null;
2135
+ orderKind: OrderKind;
2136
+ parentOrderId: number | null;
2137
+ contactId: number;
2138
+ /** Junction row linking the account customer to the checkout contact (storefront checkout). */
2139
+ customerContactId: number | null;
2140
+ billingAddressId: number | null;
2141
+ shippingAddressId: number | null;
2142
+ status: OrderStatus;
2143
+ subtotal: number;
2144
+ tax: number;
2145
+ discount: number;
2146
+ total: number;
2147
+ currency: string;
2148
+ metadata: Record<string, unknown> | null;
2149
+ createdAt: Date;
2150
+ updatedAt: Date;
2151
+ deletedAt: Date | null;
2152
+ deleted: boolean;
2153
+ createdBy: number | null;
2154
+ updatedBy: number | null;
2155
+ deletedBy: number | null;
2156
+ vendor: Vendor;
2157
+ parentOrder: Order | null;
2158
+ children: Order[];
2159
+ contact: Contact;
2160
+ customerContact: Customer_Contacts | null;
2161
+ billingAddress: OrderAddresses | null;
2162
+ shippingAddress: OrderAddresses | null;
2163
+ items: OrderItem[];
2164
+ payments: Payment[];
2165
+ }
2166
+
2167
+ declare class ChatMessage {
2168
+ id: number;
2169
+ conversationId: number;
2170
+ role: 'user' | 'assistant' | 'system';
2171
+ content: string;
2172
+ createdAt: Date;
2173
+ conversation: ChatConversation;
2174
+ }
2175
+
2176
+ declare class ChatConversation {
2177
+ id: number;
2178
+ contactId: number;
2179
+ createdAt: Date;
2180
+ updatedAt: Date;
2181
+ /** Set when a chat lead email was sent for this conversation (intent tool). */
2182
+ leadEmailSentAt: Date | null;
2183
+ contact: Contact;
2184
+ messages: ChatMessage[];
2185
+ }
2186
+
2187
+ declare class Contact {
2188
+ id: number;
2189
+ name: string;
2190
+ email: string;
2191
+ phone: string | null;
2192
+ type: string | null;
2193
+ company: string | null;
2194
+ taxId: string | null;
2195
+ notes: string | null;
2196
+ createdAt: Date;
2197
+ updatedAt: Date;
2198
+ deletedAt: Date | null;
2199
+ deleted: boolean;
2200
+ createdBy: number | null;
2201
+ updatedBy: number | null;
2202
+ deletedBy: number | null;
2203
+ userId: number | null;
2204
+ user: User | null;
2205
+ form_submissions: FormSubmission[];
2206
+ addresses: Address[];
2207
+ orders: Order[];
2208
+ payments: Payment[];
2209
+ chatConversations: ChatConversation[];
2210
+ orderAddresses: OrderAddresses[];
2211
+ }
2212
+
2213
+ declare class FormSubmission {
2214
+ id: number;
2215
+ formId: number;
2216
+ contactId: number | null;
2217
+ data: Record<string, unknown>;
2218
+ ipAddress: string | null;
2219
+ userAgent: string | null;
2220
+ createdAt: Date;
2221
+ updatedAt: Date;
2222
+ form: Form;
2223
+ contact: Contact | null;
2224
+ }
2225
+
2226
+ declare class Form {
2227
+ id: number;
2228
+ name: string;
2229
+ description: string | null;
2230
+ campaign: string | null;
2231
+ slug: string;
2232
+ published: boolean;
2233
+ createdAt: Date;
2234
+ updatedAt: Date;
2235
+ deletedAt: Date | null;
2236
+ deleted: boolean;
2237
+ createdBy: number | null;
2238
+ updatedBy: number | null;
2239
+ deletedBy: number | null;
2240
+ fields: FormField[];
2241
+ submissions: FormSubmission[];
2242
+ }
2243
+
2244
+ declare class EventProduct {
2245
+ id: number;
2246
+ eventId: number;
2247
+ productId: number;
2248
+ displayOrder: number;
2249
+ isActive: boolean;
2250
+ createdAt: Date;
2251
+ updatedAt: Date;
2252
+ event: Event;
2253
+ product: Product;
2254
+ }
2255
+
2256
+ type EventSocialMediaLinks = {
2257
+ facebook?: string;
2258
+ instagram?: string;
2259
+ linkedin?: string;
2260
+ youtube?: string;
2261
+ twitter?: string;
2262
+ tiktok?: string;
2263
+ whatsapp?: string;
2264
+ };
2265
+ type EventPricingType = 'free' | 'paid';
2266
+ type EventEntityMode = 'inperson' | 'online' | 'hybrid';
2267
+ type EventVisibility = 'public' | 'private';
2268
+ type EventOrderNotificationChannel$1 = 'email' | 'whatsapp';
2269
+ type EventOrderTemplateOverride$1 = {
2270
+ subject?: string;
2271
+ body?: string;
2272
+ externalTemplateRef?: string;
2273
+ };
2274
+ type EventOrderNotificationTemplates = Partial<Record<EventOrderNotificationChannel$1, EventOrderTemplateOverride$1>>;
2275
+ declare class Event {
2276
+ id: number;
2277
+ vendorId: number | null;
2278
+ name: string;
2279
+ slug: string;
2280
+ description: string | null;
2281
+ expectedSpeakers: number | null;
2282
+ expectedParticipants: number | null;
2283
+ isActive: boolean;
2284
+ comingSoon: boolean;
2285
+ bannerImageUrl: string | null;
2286
+ logoUrl: string | null;
2287
+ venue: string | null;
2288
+ additionalVenueDetails: string | null;
2289
+ visibility: EventVisibility;
2290
+ startDate: Date | null;
2291
+ endDate: Date | null;
2292
+ registrationOpensAt: Date | null;
2293
+ registrationClosesAt: Date | null;
2294
+ pricingType: EventPricingType | null;
2295
+ entityTypes: string[] | null;
2296
+ entityMode: EventEntityMode | null;
2297
+ city: string | null;
2298
+ country: string | null;
2299
+ cityCountry: string | null;
2300
+ defaultCurrency: string | null;
2301
+ supportedCurrencies: string[] | null;
2302
+ timezone: string | null;
2303
+ socialMediaLinks: EventSocialMediaLinks | null;
2304
+ officialWebsiteUrl: string | null;
2305
+ supportContact: string | null;
2306
+ allowGroupOrders: boolean;
2307
+ sendIndividualTicketPDFToAttendees: boolean;
2308
+ /** Send email/WhatsApp when an order containing this event's products is created. */
2309
+ orderNotificationsEnabled: boolean;
2310
+ /** Enabled channels, e.g. ["email","whatsapp"]. */
2311
+ orderNotificationChannels: EventOrderNotificationChannel$1[] | null;
2312
+ /** Per-event template overrides keyed by channel. */
2313
+ orderNotificationTemplates: EventOrderNotificationTemplates | null;
2314
+ /** CMS contact/attendee form used for this event's registration checkout. */
2315
+ contactFormId: number | null;
2316
+ /** GST / tax applied to event ticket sales. */
2317
+ taxId: number | null;
2318
+ /** Optional return/refund policy applied when cancelling orders for this event. */
2319
+ refundPolicyId: number | null;
2320
+ taxRate: number | null;
2321
+ maxGroupPurchaseQuantity: number | null;
2322
+ sponsors: Record<string, unknown> | unknown[] | null;
2323
+ agenda: Record<string, unknown> | unknown[] | null;
2324
+ workshops: Record<string, unknown> | unknown[] | null;
2325
+ exhibitors: Record<string, unknown> | unknown[] | null;
2326
+ partners: Record<string, unknown> | unknown[] | null;
2327
+ speakers: Record<string, unknown> | unknown[] | null;
2328
+ sortOrder: number;
2329
+ createdAt: Date;
2330
+ updatedAt: Date;
2331
+ deletedAt: Date | null;
2332
+ deleted: boolean;
2333
+ createdBy: number | null;
2334
+ updatedBy: number | null;
2335
+ deletedBy: number | null;
2336
+ vendor: Vendor | null;
2337
+ contactForm: Form | null;
2338
+ tax: Tax | null;
2339
+ refundPolicy: RefundPolicy | null;
2340
+ eventProducts: EventProduct[];
2341
+ }
2342
+
2343
+ type OrderLineForTemplate = {
2344
+ name: string;
2345
+ quantity: number;
2346
+ total: number | string;
2347
+ currency: string;
2348
+ };
2349
+ declare function buildEventOrderTemplateVariables(input: {
2350
+ event: Event;
2351
+ order: {
2352
+ orderNumber: string;
2353
+ total: number | string;
2354
+ currency: string;
2355
+ qrToken?: string | null;
2356
+ };
2357
+ contact: {
2358
+ name?: string | null;
2359
+ email?: string | null;
2360
+ phone?: string | null;
2361
+ };
2362
+ productNames: string;
2363
+ orderLines?: OrderLineForTemplate[];
2364
+ siteUrl?: string;
2365
+ }): Record<string, string>;
2366
+
2367
+ declare const EVENT_ORDER_TEMPLATE_KEY = "eventOrderPlaced";
2368
+ type EventOrderNotificationChannel = 'email' | 'whatsapp';
2369
+ type EventOrderTemplateOverride = {
2370
+ subject?: string;
2371
+ body?: string;
2372
+ externalTemplateRef?: string;
2373
+ };
2374
+ type EventOrderMessageTemplateDefault = {
2375
+ channel: EventOrderNotificationChannel;
2376
+ templateKey: string;
2377
+ name: string;
2378
+ subject?: string;
2379
+ body: string;
2380
+ externalTemplateRef?: string;
2381
+ };
2382
+ /** Variables available in email HTML and WhatsApp text templates. */
2383
+ declare const EVENT_ORDER_TEMPLATE_VARIABLES: readonly ["eventName", "eventSlug", "venue", "startDate", "orderNumber", "orderTotal", "currency", "customerName", "customerEmail", "customerPhone", "productNames", "trackUrl", "qrImageUrl", "orderDetails", "orderDetailsHtml"];
2384
+ declare const EVENT_ORDER_MESSAGE_TEMPLATE_DEFAULTS: EventOrderMessageTemplateDefault[];
2385
+ type ResolvedEventOrderTemplate = {
2386
+ subject?: string;
2387
+ body: string;
2388
+ externalTemplateRef?: string;
2389
+ enabled: boolean;
2390
+ };
2391
+ declare function resolveEventOrderTemplate(channel: EventOrderNotificationChannel, getRow: (channel: string, key: string) => Promise<{
2392
+ subject: string | null;
2393
+ body: string;
2394
+ externalTemplateRef: string | null;
2395
+ enabled: boolean;
2396
+ } | null>, eventOverride?: EventOrderTemplateOverride | null): Promise<ResolvedEventOrderTemplate | null>;
2397
+
2398
+ interface DispatchEventOrderNotificationsDeps {
2399
+ dataSource: DataSource;
2400
+ entityMap: Record<string, unknown>;
2401
+ getCms: () => Promise<CmsAppLike$3>;
2402
+ }
2403
+
2404
+ declare function dispatchEventOrderNotifications(orderId: number, deps: DispatchEventOrderNotificationsDeps): Promise<void>;
2405
+
2406
+ type CaptchaProviderId = 'turnstile' | 'recaptcha_v3';
2407
+ interface CaptchaPublicConfig {
2408
+ enabled: boolean;
2409
+ activeProvider: CaptchaProviderId | null;
2410
+ siteKey: string | null;
2411
+ availableProviders: Array<{
2412
+ id: CaptchaProviderId;
2413
+ siteKey: string;
2414
+ }>;
2415
+ multipleProviders: boolean;
2416
+ }
2417
+ type CaptchaVerifyResult = {
2418
+ ok: true;
2419
+ } | {
2420
+ ok: false;
2421
+ status: number;
2422
+ message: string;
2423
+ };
2424
+ declare function buildCaptchaPublicConfig(config: Record<string, string>): CaptchaPublicConfig;
2425
+ declare class CaptchaService {
2426
+ private readonly env;
2427
+ constructor(env: Record<string, string>);
2428
+ isEnforced(): boolean;
2429
+ getPublicConfig(): CaptchaPublicConfig;
2430
+ verify(body: Record<string, unknown>, req: Request): Promise<CaptchaVerifyResult>;
2431
+ }
2432
+
2433
+ declare function captchaPlugin(): CmsPlugin<CaptchaService | void>;
2434
+
2435
+ type JsonResponse = (body: unknown, init?: {
2436
+ status?: number;
2437
+ headers?: HeadersInit;
2438
+ }) => Response;
2439
+ declare function assertCaptchaOk(getCms: (() => Promise<{
2440
+ getPlugin: (name: string) => unknown;
2441
+ }>) | undefined, body: Record<string, unknown>, req: Request, json: JsonResponse): Promise<Response | null>;
2442
+
2443
+ interface LatestArticleFromFeed {
2444
+ title?: string;
2445
+ link?: string;
2446
+ /** Short excerpt */
2447
+ summary?: string;
2448
+ /** Full content if available */
2449
+ content?: string;
2450
+ date: Date;
2451
+ creator?: string;
2452
+ categories?: string[];
2453
+ }
2454
+ type RssItem = {
2455
+ title?: string;
2456
+ link?: string;
2457
+ pubDate?: string;
2458
+ isoDate?: string;
2459
+ contentSnippet?: string;
2460
+ summary?: string;
2461
+ description?: string;
2462
+ content?: string;
2463
+ creator?: string;
2464
+ 'dc:creator'?: string;
2465
+ 'content:encoded'?: string;
2466
+ categories?: string[];
2467
+ guid?: string | {
2468
+ _: string;
2469
+ };
2470
+ };
2471
+ declare function getRssArticleSummaryFromItem(item: RssItem): {
2472
+ summary: string;
2473
+ fullContent: string;
2474
+ };
2475
+ type BlogGeneratorDraftParseMode = 'json' | 'plaintext';
2476
+ interface BlogGeneratorSeoDraft {
2477
+ title: string | null;
2478
+ description: string | null;
2479
+ keywords: string | null;
2480
+ ogTitle: string | null;
2481
+ ogDescription: string | null;
2482
+ }
2483
+ interface BlogGeneratorBlogDraft {
2484
+ title: string;
2485
+ slug?: string;
2486
+ markdown: string;
2487
+ /** Short plain-text copy for social (e.g. LinkedIn); optional until social LLM step runs. */
2488
+ socialMediaContent?: string | null;
2489
+ categoryName: string | null;
2490
+ seo: BlogGeneratorSeoDraft;
2491
+ /** Suggested tag labels (may not exist in CMS yet). */
2492
+ tags: string[];
2493
+ parseMode: BlogGeneratorDraftParseMode;
2494
+ }
2495
+ /**
2496
+ * Parses the LLM reply: prefers a single JSON object with blogTitle, blogHtml/blogMarkdown/content, categoryName, seo, …
2497
+ * Falls back to treating the entire string as HTML (or legacy markdown) if JSON parsing fails.
2498
+ */
2499
+ declare function parseBlogGeneratorAgentContent(raw: string): BlogGeneratorBlogDraft;
2500
+ declare function resolveBlogCategoryIdByName(needle: string | null | undefined, rows: readonly {
2501
+ id: number;
2502
+ name: string;
2503
+ }[]): {
2504
+ categoryId: number | null;
2505
+ matched: boolean;
2506
+ };
2507
+ /**
2508
+ * Minimal user payload: latest item per feed only (system prompt carries writing rules).
2509
+ */
2510
+ declare function buildRssUserPromptFromFeeds(feeds: ReadonlyArray<{
2511
+ rssUrl: string;
2512
+ article: LatestArticleFromFeed;
2513
+ }>): string;
2514
+ /**
2515
+ * User message for the metadata-only LLM step (one blog at a time).
2516
+ */
2517
+ declare function buildBlogMetadataUserPrompt(opts: {
2518
+ title: string;
2519
+ markdown: string;
2520
+ categoryNames: readonly string[];
2521
+ tagNames: readonly string[];
2522
+ }): string;
2523
+ /** Parses JSON from the metadata-enrichment LLM (category, slug, seo, tags). */
2524
+ declare function parseBlogMetadataEnrichmentJson(raw: string): {
2525
+ categoryName: string | null;
2526
+ blogSlug: string | null;
2527
+ seo: BlogGeneratorSeoDraft;
2528
+ tags: string[];
2529
+ };
2530
+ /**
2531
+ * Parses LLM output: prefers HTML + {@link BLOG_GENERATOR_MARKDOWN_ARTICLE_SEPARATOR} for multiple articles.
2532
+ * If the model still returns legacy JSON with `blogHtml` / `blogMarkdown`, returns a single draft from that object.
2533
+ */
2534
+ declare function parseBlogGeneratorModelOutput(raw: string): BlogGeneratorBlogDraft[];
2535
+ declare class BlogGeneratorService {
2536
+ readonly version: "1.0.0";
2537
+ getLatestArticleFromFeed(rssUrl: string): Promise<LatestArticleFromFeed | null>;
2538
+ /** Defaults for the Blog Generator Agent (admin can override per request). */
2539
+ getAgentDefaults(): {
2540
+ agentName: string;
2541
+ systemInstruction: string;
2542
+ validationRules: string;
2543
+ };
2544
+ /**
2545
+ * Second LLM call: one draft at a time — category, URL slug, SEO fields, tags (JSON).
2546
+ */
2547
+ private enrichBlogDraftWithLlmMetadata;
2548
+ /**
2549
+ * Third LLM call: one draft at a time — short social copy (JSON `{ socialMediaContent }`).
2550
+ */
2551
+ private enrichBlogDraftWithLlmSocial;
2552
+ /**
2553
+ * Fetches the latest item for each RSS URL, then calls {@link LlmServiceInterface.chatAgent}.
2554
+ * `userPrompt` is only per-feed source material; rules live in the system prompt.
2555
+ * Expects HTML article fragment(s), optionally separated by {@link BLOG_GENERATOR_MARKDOWN_ARTICLE_SEPARATOR}.
2556
+ */
2557
+ generateBlogMarkdownFromRss(params: {
2558
+ llm: LlmServiceInterface;
2559
+ /** Single feed (legacy). */
2560
+ rssUrl?: string;
2561
+ /** One or more feeds; latest item per URL is sent together. Prefer this when multiple URLs. */
2562
+ rssUrls?: readonly string[];
2563
+ systemInstruction?: string;
2564
+ validationRules?: string;
2565
+ /** Reserved for future structured output; writer does not inject categories into the user prompt. */
2566
+ categoryNamesHint?: readonly string[];
2567
+ /** Names of non-deleted tags in CMS (hint for reuse). */
2568
+ tagNamesHint?: readonly string[];
2569
+ /** From optional `llm_agents` row (slug `blog-generator`): model / sampling for the writer step. */
2570
+ llmAgentChatOptions?: Pick<LlmAgentOptions, 'model' | 'temperature' | 'max_tokens'>;
2571
+ /** Optional overrides for the metadata step; defaults live in `blog-generator-metadata-defaults.ts`. */
2572
+ metadataSystemInstruction?: string;
2573
+ metadataValidationRules?: string;
2574
+ /** From optional `llm_agents` row (slug `blog-generator-metadata`): model / sampling for metadata only. */
2575
+ metadataLlmAgentChatOptions?: Pick<LlmAgentOptions, 'model' | 'temperature' | 'max_tokens'>;
2576
+ /** Optional overrides for the social-summary step; defaults in `blog-generator-social-defaults.ts`. */
2577
+ socialSystemInstruction?: string;
2578
+ socialValidationRules?: string;
2579
+ /** From optional `llm_agents` row (slug `blog-generator-social`): model / sampling for social copy only. */
2580
+ socialLlmAgentChatOptions?: Pick<LlmAgentOptions, 'model' | 'temperature' | 'max_tokens'>;
2581
+ }): Promise<{
2582
+ agentName: string;
2583
+ feedArticles: Array<{
2584
+ rssUrl: string;
2585
+ article: LatestArticleFromFeed;
2586
+ }>;
2587
+ /** First feed's article (backward compatibility). */
2588
+ article: LatestArticleFromFeed;
2589
+ /** Raw model reply (HTML body per defaults; legacy markdown or JSON still parsed when present). */
2590
+ blogMarkdown: string;
2591
+ blogDrafts: BlogGeneratorBlogDraft[];
2592
+ /** Same as first draft; backward compatibility. */
2593
+ blogDraft: BlogGeneratorBlogDraft;
2594
+ }>;
2595
+ }
2596
+
2597
+ /** Stable display name; not persisted as DB agent row in v1. */
2598
+ declare const BLOG_GENERATOR_AGENT_NAME = "Blog Generator Agent";
2599
+ /**
2600
+ * Optional `llm_agents` row: when present and enabled, model / temperature / max_tokens
2601
+ * are applied to {@link LlmServiceInterface.chatAgent} (system + user content still come from blog generator defaults / UI).
2602
+ */
2603
+ declare const BLOG_GENERATOR_LLM_AGENT_SLUG = "blog-generator";
2604
+ /** Line that separates multiple articles in the model reply (HTML or legacy markdown; must match parser and prompts). */
2605
+ declare const BLOG_GENERATOR_MARKDOWN_ARTICLE_SEPARATOR = "---BLOG_GENERATOR_NEXT---";
2606
+ declare const BLOG_GENERATOR_DEFAULT_SYSTEM_INSTRUCTION = "You are a professional financial and business content writer.\n\nYour task is to generate completely original, high-quality blog article(s) from the latest RSS-derived source material in the user message (one block per feed). The user message is factual input only.\n\nIMPORTANT RULES:\n\n1. NEVER copy the RSS article directly.\n2. Rewrite the information into a fresh, human-like article.\n3. Expand the topic with professional insights and explanations.\n4. Maintain a natural editorial tone.\n5. Make the article SEO-friendly.\n6. Use engaging headings and subheadings.\n7. Avoid robotic AI phrasing.\n8. Do not mention that the content came from RSS or feeds.\n9. Preserve factual accuracy from the source material.\n10. The output should feel like a professionally written industry blog.\n\nMULTIPLE FEEDS:\n- If several feeds are provided, compare them: if they largely cover the same story or overlap heavily, produce ONE cohesive article.\n- If they cover clearly different topics or distinct stories, produce MULTIPLE articles (one per distinct story).\n- You may also produce one synthesis plus a short separate angle when that best serves the reader\u2014use your judgment.\n\nWRITING STYLE:\n- Professional\n- Clear\n- Informative\n- Business-focused\n- Human sounding\n- Modern editorial style\n\nARTICLE STRUCTURE (each article \u2014 express in HTML):\n1. Engaging introduction\n2. Industry context\n3. Main developments\n4. Key implications\n5. Expert/business analysis\n6. Conclusion\n\nHTML STRUCTURE (STRICT \u2014 each article must be valid, semantic HTML only):\n- Output HTML only. Do not use Markdown (no # headings, no **bold**, no `code fences`).\n- Wrap each complete article in a single root: <article class=\"blog-post\"> ... </article>\n- Inside <article>, use this outline:\n - <header><h1 class=\"blog-post-title\">\u2026main title\u2026</h1></header> (exactly one h1 per article)\n - <section class=\"blog-post-body\"> for all following content\n - Use <h2> and <h3> for section and subsection titles (never skip levels: h1 \u2192 h2 \u2192 h3).\n - Use <p> for paragraphs; keep paragraphs focused (avoid huge unbroken text).\n - Use <ul>/<ol> with <li> for lists where appropriate.\n - Use <strong> and <em> for emphasis sparingly; use <blockquote> only when quoting or callouts fit.\n- Do not include <html>, <head>, <body>, or document-level wrappers \u2014 only the fragment(s) described above.\n- Do not use <script>, <style>, <iframe>, or inline event handlers. Avoid inline style=\"\" except when essential for accessibility (prefer none).\n- Escape angle brackets in body text if you must mention markup; keep output safe for embedding in a CMS.\n\nCONTENT REQUIREMENTS:\n- Minimum 800 words per article unless source material is very small.\n- Add context around industry trends where appropriate.\n- Explain why the topic matters.\n- Include practical implications for businesses/professionals.\n\nIF RSS CONTENT IS LIMITED:\n- Expand intelligently using general industry knowledge.\n- Keep the article relevant to the original topic.\n- Do not invent fake facts or statistics.\n\nOUTPUT FORMAT (STRICT \u2014 HTML only):\n- Return ONLY the article HTML fragment(s). No JSON, no preamble or postscript (\"Here is your article\u2026\"), no markdown.\n- If you output more than one article, output multiple <article class=\"blog-post\">\u2026</article> blocks in sequence, and between articles put a single line containing exactly this (and nothing else on that line):\n---BLOG_GENERATOR_NEXT---\n- If you output a single article, use one <article> only and do not use that separator line.";
2607
+ /**
2608
+ * JSON so {@link parseLlmAgentValidationRules} can attach guardrails and allow long source payloads.
2609
+ * Edit in the admin UI if needed; defaults match product intent.
2610
+ */
2611
+ declare const BLOG_GENERATOR_DEFAULT_VALIDATION_RULES: string;
2612
+
2613
+ /**
2614
+ * Second-step LLM: classifies one finished HTML blog body into CMS fields (category, SEO, tags).
2615
+ *
2616
+ * Optional `llm_agents` row: slug {@link BLOG_METADATA_ENRICHER_LLM_AGENT_SLUG} — when present and enabled,
2617
+ * model / temperature / max_tokens apply to this call only (writer step uses `blog-generator`).
2618
+ *
2619
+ * To change how metadata is produced, edit the constants in this file (system instruction + validation JSON).
2620
+ * No admin UI override is wired yet; add request body fields in `cms-api-handler` if you need runtime overrides later.
2621
+ */
2622
+ declare const BLOG_METADATA_ENRICHER_AGENT_NAME = "Blog Generator Metadata";
2623
+ /** `llm_agents.slug` for routing model/temperature for the metadata-only chat step. */
2624
+ declare const BLOG_METADATA_ENRICHER_LLM_AGENT_SLUG = "blog-generator-metadata";
2625
+ declare const BLOG_METADATA_ENRICHER_DEFAULT_SYSTEM_INSTRUCTION = "You are a careful CMS metadata assistant for a publishing system.\n\nYou receive ONE complete blog post as HTML (title is usually in <h1 class=\"blog-post-title\"> or the first <h1>). Your job is to propose structured fields so an editor can save the post: category, URL slug, SEO block, and topical tags.\n\nRULES:\n1. Read the whole article and infer the primary topic and audience.\n2. categoryName must be EXACTLY one string from AVAILABLE_BLOG_CATEGORIES in the user message, or \"\" if none fit.\n3. blogSlug: lowercase kebab-case, ASCII letters/digits/hyphens only, no leading/trailing hyphens, max ~80 chars. Derive from the main topic or title.\n4. seo.title: concise meta title (~50\u201360 characters when reasonable).\n5. seo.description: meta description (~150\u2013160 characters when reasonable), plain text.\n6. seo.keywords: comma-separated phrases, no stuffing.\n7. seo.ogTitle / seo.ogDescription: may mirror title/description or be slightly adapted for social.\n8. tags: 4\u201310 short labels (1\u20133 words each). Prefer exact matches from EXISTING_TAG_NAMES when they truly apply; otherwise invent precise new labels (they may be created in the CMS later).\n9. Do not invent statistics, quotes, or URLs not implied by the article.\n10. Output JSON only \u2014 no markdown outside the JSON, no commentary.\n\nOUTPUT FORMAT (STRICT):\nReturn a single JSON object only. Do not wrap it in a markdown code fence.\n\n{\n \"categoryName\": \"string \u2014 exact match from list or empty string\",\n \"blogSlug\": \"string \u2014 url-safe kebab-case\",\n \"seo\": {\n \"title\": \"string or empty\",\n \"description\": \"string or empty\",\n \"keywords\": \"string or empty\",\n \"ogTitle\": \"string or empty\",\n \"ogDescription\": \"string or empty\"\n },\n \"tags\": [\"tag-one\", \"tag-two\"]\n}";
2626
+ declare const BLOG_METADATA_ENRICHER_DEFAULT_VALIDATION_RULES: string;
2627
+
2628
+ interface BlogGeneratorPluginConfig {
2629
+ /** Set to false to skip registering the plugin. */
2630
+ enabled?: boolean;
2631
+ }
2632
+ declare function blogGeneratorPlugin(config?: BlogGeneratorPluginConfig): CmsPlugin<BlogGeneratorService | undefined>;
2633
+
2634
+ interface SocialMediaApiConfig {
2635
+ dataSource: DataSource;
2636
+ entityMap: EntityMap$2;
2637
+ json: (body: unknown, init?: {
2638
+ status?: number;
2639
+ }) => Response;
2640
+ requireAuth: (req: Request) => Promise<Response | null>;
2641
+ requireEntityPermission: (req: Request, entity: string, action: EntityCrudAction) => Promise<Response | null>;
2642
+ encryptionKey?: string;
2643
+ /** Used to resolve relative cover image URLs (e.g. https://mysite.com). */
2644
+ publicSiteUrl?: string;
2645
+ /**
2646
+ * When true (default), `console.info` / `console.warn` lines are emitted for LinkedIn blog publish
2647
+ * (text vs image path, sizes, errors). Set false or `CMS_LINKEDIN_PUBLISH_LOG=0` to silence.
2648
+ */
2649
+ linkedInPublishLogging?: boolean;
2650
+ }
2651
+ declare function createSocialMediaHandlers(config: SocialMediaApiConfig): {
2652
+ getLinkedInStatus(req: Request): Promise<Response>;
2653
+ fetchLinkedInOrganizations(req: Request): Promise<Response>;
2654
+ syncLinkedInProfile(req: Request): Promise<Response>;
2655
+ publishBlogToLinkedIn(req: Request, blogId: number): Promise<Response>;
2656
+ getFacebookStatus(req: Request): Promise<Response>;
2657
+ publishBlogToFacebook(req: Request, blogId: number): Promise<Response>;
2658
+ /**
2659
+ * POST JSON `{ appId, appSecret, userAccessToken }`. Calls Graph `GET /me/accounts` with the user token.
2660
+ * App ID and secret are validated but not used yet (reserved for future token flows).
2661
+ * Persist credentials via Plugins → Save: `meta_app_id` (public), `meta_app_secret` and `meta_user_access_token` (encrypted).
2662
+ */
2663
+ fetchFacebookManagedPages(req: Request): Promise<Response>;
2664
+ };
2665
+
2666
+ /**
2667
+ * Meta (Facebook) Graph API helpers (server-side). Uses fetch — no SDK.
2668
+ * @see https://developers.facebook.com/docs/graph-api/reference/user/accounts
2669
+ */
2670
+ type FacebookPageAccount = {
2671
+ access_token?: string;
2672
+ category?: string;
2673
+ name?: string;
2674
+ id?: string;
2675
+ /** Graph may return additional fields */
2676
+ [key: string]: unknown;
2677
+ };
2678
+ type FacebookMeAccountsResponse = {
2679
+ data?: FacebookPageAccount[];
2680
+ paging?: Record<string, unknown>;
2681
+ error?: {
2682
+ message?: string;
2683
+ type?: string;
2684
+ code?: number;
2685
+ fbtrace_id?: string;
2686
+ };
2687
+ };
2688
+ /**
2689
+ * Lists Facebook Pages the user manages (page access tokens + metadata).
2690
+ * Requires a User access token with `pages_show_list` or equivalent page permissions.
2691
+ */
2692
+ declare function metaFetchUserManagedPages(userAccessToken: string): Promise<FacebookMeAccountsResponse>;
2693
+ type MetaGraphMutationResponse = {
2694
+ id?: string;
2695
+ post_id?: string;
2696
+ error?: {
2697
+ message?: string;
2698
+ type?: string;
2699
+ code?: number;
2700
+ fbtrace_id?: string;
2701
+ };
2702
+ };
2703
+ /** Resolves the long-lived page access token for a Page ID from `/me/accounts` data. */
2704
+ declare function metaResolvePageAccessToken(accounts: FacebookMeAccountsResponse, pageId: string): string | null;
2705
+ /**
2706
+ * Upload a photo to a Page timeline (multipart).
2707
+ * @see https://developers.facebook.com/docs/graph-api/reference/page/photos#Creating
2708
+ */
2709
+ declare function metaPostPagePhoto(opts: {
2710
+ pageId: string;
2711
+ pageAccessToken: string;
2712
+ imageBuffer: Buffer;
2713
+ contentType: string;
2714
+ caption: string;
2715
+ }): Promise<MetaGraphMutationResponse>;
2716
+ /**
2717
+ * Publish a text-only post to the Page feed (when no JPEG/PNG image is available).
2718
+ * @see https://developers.facebook.com/docs/graph-api/reference/page/feed#Creating
2719
+ */
2720
+ declare function metaPostPageFeed(opts: {
2721
+ pageId: string;
2722
+ pageAccessToken: string;
2723
+ message: string;
2724
+ }): Promise<MetaGraphMutationResponse>;
2725
+
2726
+ interface SocialMediaPluginConfig {
2727
+ /** Set to false to skip registering the plugin instance (API routes still work if wired in the app handler). */
2728
+ enabled?: boolean;
2729
+ }
2730
+ /**
2731
+ * Optional CMS plugin instance for `getPlugin('social_media')`.
2732
+ * LinkedIn publishing is implemented in {@link createSocialMediaHandlers} and mounted from the CMS API handler.
2733
+ */
2734
+ declare function socialMediaPlugin(config?: SocialMediaPluginConfig): CmsPlugin<{
2735
+ name: string;
2736
+ } | undefined>;
2737
+
2738
+ declare function cn(...inputs: ClassValue[]): string;
2739
+ declare function generateSlug(title: string): string;
2740
+ declare function validateSlug(slug: string): boolean;
2741
+ declare function formatDate(date: Date | string): string;
2742
+ declare function formatDateTime(date: Date | string): string;
2743
+ declare function formatDateOnly(date: Date | string): string;
2744
+ declare function truncateText(text: string, maxLength: number): string;
2745
+
2746
+ /** Minimal SEO row shape (DB or API). */
2747
+ type SeoLike = {
2748
+ title?: string | null;
2749
+ description?: string | null;
2750
+ keywords?: string | null;
2751
+ ogTitle?: string | null;
2752
+ ogDescription?: string | null;
2753
+ ogImage?: string | null;
2754
+ };
2755
+ type SeoMetadataOverrides = {
2756
+ title?: string;
2757
+ description?: string;
2758
+ keywords?: string;
2759
+ ogTitle?: string;
2760
+ ogDescription?: string;
2761
+ ogImage?: string;
2762
+ };
2763
+ /** Per-field: join row wins over slug row. */
2764
+ declare function mergeSeoBySlug(join: SeoLike | null | undefined, bySlug: SeoLike | null): SeoLike | null;
2765
+ declare function fetchSeoBySlug(dataSource: DataSource, entityMap: EntityMap$2, slug: string): Promise<SeoLike | null>;
2766
+ /**
2767
+ * Build Next.js Metadata from merged SEO + optional layers.
2768
+ * `overrides` win over SEO; `fallbacks` apply when SEO (and overrides) omit a field.
2769
+ * Returns a partial object; omit fields so the root layout defaults apply.
2770
+ */
2771
+ declare function resolvePublicMetadata(args: {
2772
+ dataSource: DataSource;
2773
+ entityMap: EntityMap$2;
2774
+ slug: string;
2775
+ seoFromJoin?: SeoLike | null;
2776
+ overrides?: SeoMetadataOverrides;
2777
+ fallbacks?: SeoMetadataOverrides;
2778
+ canonicalPath?: string;
2779
+ metadataBase?: URL;
2780
+ }): Promise<Metadata>;
2781
+
2782
+ /** Links an unclaimed contact (same email, no userId) to the new user after signup or invite. */
2783
+ declare function linkUnclaimedContactToUser(dataSource: DataSource, contactsEntity: EntityTarget<ObjectLiteral>, userId: number, email: string): Promise<void>;
2784
+
2785
+ type EnsureCustomerUserInput = {
2786
+ id: number;
2787
+ name: string;
2788
+ email: string;
2789
+ phone?: string | null;
2790
+ };
2791
+ /** Stable unique placeholder when no phone is available (customer.phone is NOT NULL + UNIQUE). */
2792
+ declare function customerPhoneForUser(userId: number, phone?: string | null): string;
2793
+ /**
2794
+ * Ensures a `customer` row exists for the given user (idempotent by userId / email).
2795
+ * Returns null when customer entity is missing or email belongs to another user.
2796
+ */
2797
+ declare function ensureCustomerForUser(dsOrEm: DataSource | EntityManager, customerEntity: EntityTarget<ObjectLiteral>, user: EnsureCustomerUserInput, overrides?: {
2798
+ phone?: string | null;
2799
+ }): Promise<{
2800
+ id: number;
2801
+ } | null>;
2802
+
2803
+ /** Parse stored config value into a list of emails (JSON array, or comma/semicolon-separated string). */
2804
+ declare function parseEmailRecipientsFromConfig(raw: string | undefined | null): string[];
2805
+ /** Serialize email list for config storage (JSON array in DB). */
2806
+ declare function serializeEmailRecipients(emails: string[]): string;
2807
+ /** Join for SMTP `to` header (multiple recipients). */
2808
+ declare function joinRecipientsForSend(emails: string[]): string | null;
2809
+
2810
+ type OtpPurpose = 'login' | 'verify_email' | 'verify_phone';
2811
+ type OtpChannel = 'email' | 'sms';
2812
+ declare function hashOtpCode(code: string, purpose: string, identifier: string, pepper?: string): string;
2813
+ declare function verifyOtpCodeHash(code: string, storedHash: string, purpose: string, identifier: string, pepper?: string): boolean;
2814
+ declare function generateNumericOtp(length?: number): string;
2815
+ /** Normalize to E.164-like +digits */
2816
+ declare function normalizePhoneE164(raw: string, defaultCountryCode?: string): string | null;
2817
+ type EntityMap$1 = Record<string, EntityTarget<ObjectLiteral>>;
2818
+ declare function countRecentOtpSends(dataSource: DataSource, entityMap: EntityMap$1, purpose: OtpPurpose, identifier: string, since: Date): Promise<number>;
2819
+ declare function createOtpChallenge(dataSource: DataSource, entityMap: EntityMap$1, input: {
2820
+ purpose: OtpPurpose;
2821
+ channel: OtpChannel;
2822
+ identifier: string;
2823
+ code: string;
2824
+ pepper?: string;
2825
+ }): Promise<{
2826
+ ok: true;
2827
+ } | {
2828
+ ok: false;
2829
+ error: string;
2830
+ status: number;
2831
+ }>;
2832
+ declare function verifyAndConsumeOtpChallenge(dataSource: DataSource, entityMap: EntityMap$1, input: {
2833
+ purpose: OtpPurpose;
2834
+ identifier: string;
2835
+ code: string;
2836
+ pepper?: string;
2837
+ }): Promise<{
2838
+ ok: true;
2839
+ } | {
2840
+ ok: false;
2841
+ error: string;
2842
+ status: number;
2843
+ }>;
2844
+
2845
+ /** Returns true if request is allowed; false if rate limited. */
2846
+ declare function allowRateLimit(key: string): Promise<boolean>;
2847
+ type ExtraPublicWriteRule = (method: string, segments: string[]) => boolean;
2848
+ /** Segments are path parts after `/api/` (e.g. `['form-submissions']`). */
2849
+ declare function shouldRateLimitPublicWrite(method: string, segments: string[], extraRule?: ExtraPublicWriteRule): boolean;
2850
+ declare function rateLimitKeyForApiRequest(req: Request, segments: string[]): string;
2851
+ declare function rateLimitPublicApiIfNeeded(req: Request, method: string, segments: string[], options?: {
2852
+ extraRule?: ExtraPublicWriteRule;
2853
+ }): Promise<Response | null>;
2854
+ declare function rateLimitCheckoutPost(req: Request): Promise<Response | null>;
2855
+
2856
+ interface EntityMapLike$1 {
2857
+ configs: unknown;
2858
+ orders: unknown;
2859
+ order_items: unknown;
2860
+ }
2861
+ interface SendOrderPlacedEmailDeps {
2862
+ getDataSource: () => Promise<DataSource>;
2863
+ entityMap: EntityMapLike$1;
2864
+ getCms: () => Promise<CmsApp>;
2865
+ }
2866
+ /** After payment confirmation: email customer + each sales team address from plugin settings. */
2867
+ declare function sendOrderPlacedEmailsAfterConfirmation(orderId: number, deps: SendOrderPlacedEmailDeps): Promise<void>;
2868
+
2869
+ type VendorOnboardedActivation = 'invite' | 'password';
2870
+ type VendorOnboardedKind = 'vendor_onboard' | 'team_invite';
2871
+
2872
+ interface EntityMapLike {
2873
+ configs: unknown;
2874
+ }
2875
+ interface SendVendorOnboardEmailInput {
2876
+ vendorName: string;
2877
+ vendorSlug?: string;
2878
+ ownerName: string;
2879
+ ownerEmail: string;
2880
+ activation: VendorOnboardedActivation;
2881
+ inviteLink?: string;
2882
+ signInLink: string;
2883
+ kind?: VendorOnboardedKind;
2884
+ /** When false, skips owner email but still notifies internal recipients. Default true. */
2885
+ sendToOwner?: boolean;
2886
+ }
2887
+ interface SendVendorOnboardEmailDeps {
2888
+ getDataSource: () => Promise<DataSource>;
2889
+ entityMap: EntityMapLike;
2890
+ getCms: () => Promise<CmsAppLike$3>;
2891
+ }
2892
+ /** After vendor onboard / team invite: email owner + platform team from plugin settings. */
2893
+ declare function sendVendorOnboardEmails(input: SendVendorOnboardEmailInput, deps: SendVendorOnboardEmailDeps): Promise<{
2894
+ ownerEmailSent: boolean;
2895
+ }>;
2896
+
2897
+ interface DataSourceManager {
2898
+ getDataSource: () => DataSource;
2899
+ getDataSourceInitialized: () => Promise<DataSource>;
2900
+ resetDataSource: () => void;
2901
+ registerOnReset: (cb: () => void) => void;
2902
+ isConnectionError: (e: unknown) => boolean;
2903
+ }
2904
+ declare function createDataSourceManager(entityMap: Record<string, unknown>, options?: {
2905
+ databaseUrl?: string;
2906
+ idleTimeoutMillis?: number;
2907
+ }): DataSourceManager;
2908
+
2909
+ interface SeedEntityMap {
2910
+ users: unknown;
2911
+ user_groups: unknown;
2912
+ }
2913
+ declare function seedDefaultAdmin(ds: DataSource, entityMap: SeedEntityMap, opts?: {
2914
+ email?: string;
2915
+ password?: string;
2916
+ }): Promise<void>;
2917
+
2918
+ type UserVendorContext = {
2919
+ vendorIds: number[];
2920
+ activeVendorId: number | null;
2921
+ /** @deprecated legacy vendor_users.role */
2922
+ vendorRole: VendorUserRole | null;
2923
+ vendorRoleId: number | null;
2924
+ vendorRoleName: string | null;
2925
+ isVendorRoleOwner: boolean;
2926
+ vendorEntityPerms: Record<string, EntityPermissionFlags>;
2927
+ };
2928
+ /** Load vendor membership + active vendor role permissions for session. */
2929
+ declare function loadUserVendorContext(dataSource: DataSource, userId: number, preferredVendorId?: number | null): Promise<UserVendorContext>;
2930
+
2931
+ /**
2932
+ * Build NextAuth options for credentials auth. App can extend/override via extend().
2933
+ */
2934
+
2935
+ interface NextAuthUser {
1884
2936
  id: number;
1885
- userId: number;
1886
- user: User | null;
1887
- name: string;
1888
2937
  email: string;
1889
- phone: string;
1890
- createdAt: Date;
1891
- updatedAt: Date;
1892
- deletedAt: Date | null;
1893
- deleted: boolean;
1894
- createdBy: number | null;
1895
- updatedBy: number | null;
1896
- deletedBy: number | null;
2938
+ name: string | null;
2939
+ password: string | null;
2940
+ blocked?: boolean;
2941
+ deleted?: boolean;
2942
+ groupId?: number | null;
2943
+ adminAccess?: boolean;
2944
+ group?: {
2945
+ name?: string;
2946
+ permissions?: Array<{
2947
+ entity: string;
2948
+ canCreate: boolean;
2949
+ canRead: boolean;
2950
+ canUpdate: boolean;
2951
+ canDelete: boolean;
2952
+ }>;
2953
+ };
2954
+ vendorIds?: number[];
2955
+ activeVendorId?: number | null;
2956
+ vendorRole?: 'owner' | 'staff' | null;
2957
+ vendorRoleId?: number | null;
2958
+ vendorRoleName?: string | null;
2959
+ isVendorRoleOwner?: boolean;
2960
+ vendorEntityPerms?: Record<string, {
2961
+ c: boolean;
2962
+ r: boolean;
2963
+ u: boolean;
2964
+ d: boolean;
2965
+ }>;
2966
+ }
2967
+ interface AuthorizeOtpInput {
2968
+ identifier: string;
2969
+ channel: 'email' | 'sms';
2970
+ code: string;
2971
+ }
2972
+ interface NextAuthOptionsConfig {
2973
+ /** Resolve user by email (e.g. from TypeORM). Return null if not found. */
2974
+ getUserByEmail: (email: string) => Promise<NextAuthUser | null>;
2975
+ comparePassword: (plain: string, hash: string) => Promise<boolean>;
2976
+ signInPage?: string;
2977
+ secret?: string;
2978
+ extend?: (options: NextAuthOptions) => NextAuthOptions;
2979
+ /** When false, password CredentialsProvider is omitted. Default true. */
2980
+ enablePasswordLogin?: boolean;
2981
+ /** When true, registers CredentialsProvider id `otp`. Requires authorizeOtp. Default false. */
2982
+ enableOtpLogin?: boolean;
2983
+ /** Validate OTP and return user (same shape as password flow) or null. */
2984
+ authorizeOtp?: (input: AuthorizeOtpInput) => Promise<NextAuthUser | null>;
2985
+ /**
2986
+ * Customer group sign-in policy for credentials/OTP on a shared `/api/auth` route:
2987
+ * - `true` — always allow (dedicated storefront auth)
2988
+ * - `false` — always block
2989
+ * - omitted — auto: allow unless `callbackUrl` targets `/admin` (storefront `/signin` works unchanged)
2990
+ */
2991
+ allowCustomerLogin?: boolean;
1897
2992
  }
2993
+ declare function getNextAuthOptions(config: NextAuthOptionsConfig): NextAuthOptions;
2994
+ /** Storefront sign-in: allows Customer group; use with signInPage `/signin`. */
2995
+ declare function getStorefrontNextAuthOptions(config: Omit<NextAuthOptionsConfig, 'allowCustomerLogin'>): NextAuthOptions;
1898
2996
 
1899
- declare class Customer_Contacts {
1900
- id: number;
1901
- customerId: number;
1902
- customer: Customer;
1903
- contactId: number;
1904
- contact: Contact;
2997
+ /** Attach vendor membership + role permissions for NextAuth (use in app getUserByEmail). */
2998
+ declare function enrichUserWithVendorContext(dataSource: DataSource, user: NextAuthUser | null): Promise<NextAuthUser | null>;
2999
+
3000
+ /** Merge DB group + vendor_users into session (JWT often missing these). Server/API only. */
3001
+ declare function hydrateVendorSessionUser(dataSource: DataSource, user: SessionUser | null | undefined): Promise<SessionUser | null | undefined>;
3002
+
3003
+ interface NavItem {
3004
+ id: string;
3005
+ label: string;
3006
+ url: string;
3007
+ openInNewTab?: boolean;
3008
+ /** When set, url is derived from the linked page slug. */
3009
+ pageId?: number;
3010
+ children?: NavItem[];
3011
+ }
3012
+ interface NavbarConfig {
3013
+ logo: string;
3014
+ items: NavItem[];
3015
+ ctaLabel?: string;
3016
+ ctaUrl?: string;
3017
+ /** Optional variant for theme-specific layout (e.g. "page2"). */
3018
+ variant?: string;
3019
+ }
3020
+ interface FooterConfig {
3021
+ copyright: string;
3022
+ columns: {
3023
+ title: string;
3024
+ links: {
3025
+ label: string;
3026
+ url: string;
3027
+ }[];
3028
+ }[];
3029
+ socialLinks: {
3030
+ icon: string;
3031
+ url: string;
3032
+ }[];
3033
+ /** When set, footer shows this logo (e.g. same as navbar). */
3034
+ logo?: string;
1905
3035
  }
1906
3036
 
1907
- type OrderKind = 'sale' | 'return' | 'replacement';
1908
- declare class Order {
1909
- id: number;
1910
- vendorId: number;
1911
- orderNumber: string;
1912
- qrToken: string | null;
1913
- orderKind: OrderKind;
1914
- parentOrderId: number | null;
1915
- contactId: number;
1916
- /** Junction row linking the account customer to the checkout contact (storefront checkout). */
1917
- customerContactId: number | null;
1918
- billingAddressId: number | null;
1919
- shippingAddressId: number | null;
1920
- status: 'pending' | 'confirmed' | 'processing' | 'completed' | 'cancelled';
1921
- subtotal: number;
1922
- tax: number;
1923
- discount: number;
1924
- total: number;
1925
- currency: string;
1926
- metadata: Record<string, unknown> | null;
1927
- createdAt: Date;
1928
- updatedAt: Date;
1929
- deletedAt: Date | null;
1930
- deleted: boolean;
1931
- createdBy: number | null;
1932
- updatedBy: number | null;
1933
- deletedBy: number | null;
1934
- vendor: Vendor;
1935
- parentOrder: Order | null;
1936
- children: Order[];
1937
- contact: Contact;
1938
- customerContact: Customer_Contacts | null;
1939
- billingAddress: OrderAddresses | null;
1940
- shippingAddress: OrderAddresses | null;
1941
- items: OrderItem[];
1942
- payments: Payment[];
3037
+ interface PublicThemeSettingsPayload {
3038
+ activeThemeId: string;
3039
+ primaryColor: string;
3040
+ secondaryColor: string;
3041
+ navbarConfig: NavbarConfig;
3042
+ footerOverrides: Partial<FooterConfig>;
1943
3043
  }
3044
+ declare function loadPublicThemeSettings(config: {
3045
+ dataSource: DataSource;
3046
+ entityMap: EntityMap$2;
3047
+ encryptionKey?: string;
3048
+ defaultActiveThemeId?: string;
3049
+ defaultPrimaryColor?: string;
3050
+ defaultSecondaryColor?: string;
3051
+ }): Promise<PublicThemeSettingsPayload>;
1944
3052
 
1945
- declare class ChatMessage {
3053
+ /** Normalize a logical media folder path: no leading/trailing slashes, no ".." segments, max length. */
3054
+ declare function sanitizeMediaFolderPath(input: unknown): string;
3055
+ /** Single path segment for storage (folder name or legacy path segment). */
3056
+ declare function sanitizeStorageSegment(name: string): string;
3057
+
3058
+ type EntityMap = Record<string, EntityTarget<ObjectLiteral>>;
3059
+ /** Build `a/b/c` path under `uploads/` from the chain of folder rows up to root. */
3060
+ declare function relativePathFromMediaParentId(dataSource: DataSource, entityMap: EntityMap, parentId: number | null): Promise<string>;
3061
+
3062
+ declare const ZIP_MIME_TYPES: Set<string>;
3063
+ declare function isZipMedia(mime: string | null | undefined, filename: string): boolean;
3064
+
3065
+ /**
3066
+ * Executes `fn` inside a transaction where the PostgreSQL GUC
3067
+ * `app.vendor_id` is set for the duration of that transaction.
3068
+ *
3069
+ * This activates the `vendor_isolation` RLS policy added by the
3070
+ * `VendorRls1775940000000` migration.
3071
+ *
3072
+ * vendorId = 0 → admin / all-access (policy allows everything)
3073
+ * vendorId > 0 → only rows whose `vendorId` column matches
3074
+ *
3075
+ * Example:
3076
+ * const orders = await withVendorRlsContext(dataSource, 4, (ds) =>
3077
+ * ds.getRepository(Order).find({ where: { deleted: false } })
3078
+ * );
3079
+ */
3080
+ declare function withVendorRlsContext<T>(dataSource: DataSource, vendorId: number, fn: (dataSource: DataSource) => Promise<T>): Promise<T>;
3081
+ /**
3082
+ * Convenience wrapper: sets admin mode (vendor_id = '0') so all rows are
3083
+ * visible regardless of their vendorId. Use for platform-admin queries.
3084
+ */
3085
+ declare function withAdminRlsContext<T>(dataSource: DataSource, fn: (dataSource: DataSource) => Promise<T>): Promise<T>;
3086
+
3087
+ type EnsureVendorCustomerDetails = {
3088
+ name: string;
3089
+ email: string;
3090
+ phone?: string | null;
3091
+ };
3092
+ declare function isCustomerTypeContact(type: unknown): boolean;
3093
+ /** Restrict contact list to rows linked in `vendor_customers` with type customer. */
3094
+ declare function applyVendorCustomersContactFilter(qb: SelectQueryBuilder<typeorm.ObjectLiteral>, contactAlias: string, scope: VendorScope, vendorIdFilter: number | null): void;
3095
+ declare function contactIsVendorCustomer(dataSource: DataSource, entityMap: EntityMap$2, vendorId: number, contactId: number): Promise<boolean>;
3096
+ /** Returns an error message when the contact is not a vendor-linked customer; otherwise null. */
3097
+ declare function assertContactAllowedForVendorOrder(dataSource: DataSource, entityMap: EntityMap$2, vendorId: number, contactId: number): Promise<string | null>;
3098
+ declare function resolveVendorIdForContactCheck(scope: VendorScope, bodyOrRow: Record<string, unknown>): number | null;
3099
+ /**
3100
+ * When an order is placed for a manually entered customer, ensure they appear in
3101
+ * vendor customers: customer row, vendor_customers link, and contact type.
3102
+ */
3103
+ declare function ensureVendorCustomerForOrderContact(dataSource: DataSource, entityMap: EntityMap$2, vendorId: number, contactId: number, details: EnsureVendorCustomerDetails): Promise<void>;
3104
+
3105
+ /** One band: refund % when cancellation falls N days before event start. */
3106
+ type RefundPolicyTier = {
3107
+ /** Inclusive lower bound (days before event start; 0 = event day). */
3108
+ fromDaysBefore: number;
3109
+ /** Exclusive upper bound, or null for open-ended (e.g. 20+ days). */
3110
+ toDaysBefore: number | null;
3111
+ percentage: number;
3112
+ };
3113
+ type RefundPolicyType = 'percentage' | 'event_tiers';
3114
+ type RefundPolicyLike = {
3115
+ id?: number;
3116
+ type: RefundPolicyType;
3117
+ value: number;
3118
+ refundWindowDays: number;
3119
+ tiers?: RefundPolicyTier[] | null;
3120
+ };
3121
+ type RefundCalculationResult = {
3122
+ amount: number;
3123
+ percentage: number;
3124
+ daysBeforeEvent: number | null;
3125
+ daysSincePurchase: number | null;
3126
+ policyId: number | null;
3127
+ summary: string;
3128
+ /** Order cancelled without policy-based refund (no policy on event). */
3129
+ directCancellation?: boolean;
3130
+ eventId?: number | null;
3131
+ eventName?: string | null;
3132
+ };
3133
+ declare function normalizeRefundTiers(raw: unknown): RefundPolicyTier[];
3134
+ declare function validateRefundTiers(tiers: RefundPolicyTier[]): string | null;
3135
+ declare function daysBeforeEventStart(eventStart: Date, asOf?: Date): number;
3136
+ declare function formatTierRange(tier: RefundPolicyTier): string;
3137
+ declare function describeEventTierPolicy(tiers: RefundPolicyTier[]): string;
3138
+ declare function calculateRefundFromPolicy(policy: RefundPolicyLike | null | undefined, orderTotal: number, options?: {
3139
+ orderCreatedAt?: Date | null;
3140
+ eventStartDate?: Date | null;
3141
+ asOf?: Date;
3142
+ }): RefundCalculationResult;
3143
+
3144
+ type PolicyRow = RefundPolicyLike & {
1946
3145
  id: number;
1947
- conversationId: number;
1948
- role: 'user' | 'assistant' | 'system';
1949
- content: string;
1950
- createdAt: Date;
1951
- conversation: ChatConversation;
1952
- }
3146
+ };
3147
+ declare function calculateOrderRefundPreview(dataSource: DataSource, entityMap: EntityMap$2, order: {
3148
+ id: number;
3149
+ vendorId?: number | null;
3150
+ total?: number | null;
3151
+ createdAt?: Date | string | null;
3152
+ }, asOf?: Date): Promise<RefundCalculationResult & {
3153
+ eventStartDate: string | null;
3154
+ directCancellation: boolean;
3155
+ eventId: number | null;
3156
+ eventName: string | null;
3157
+ }>;
3158
+ /** @deprecated Use event-attached policy via calculateOrderRefundPreview. */
3159
+ declare function findActiveRefundPolicyForVendor(dataSource: DataSource, entityMap: EntityMap$2, vendorId: number | null | undefined): Promise<PolicyRow | null>;
1953
3160
 
1954
- declare class ChatConversation {
3161
+ declare class OtpChallenge {
1955
3162
  id: number;
1956
- contactId: number;
3163
+ purpose: string;
3164
+ channel: string;
3165
+ identifier: string;
3166
+ codeHash: string;
3167
+ expiresAt: Date;
3168
+ attempts: number;
3169
+ consumedAt: Date | null;
1957
3170
  createdAt: Date;
1958
- updatedAt: Date;
1959
- /** Set when a chat lead email was sent for this conversation (intent tool). */
1960
- leadEmailSentAt: Date | null;
1961
- contact: Contact;
1962
- messages: ChatMessage[];
1963
3171
  }
1964
3172
 
1965
- declare class Contact {
3173
+ declare class PasswordResetToken {
1966
3174
  id: number;
1967
- name: string;
1968
3175
  email: string;
1969
- phone: string | null;
1970
- type: string | null;
1971
- company: string | null;
1972
- taxId: string | null;
1973
- notes: string | null;
3176
+ token: string;
3177
+ expiresAt: Date;
1974
3178
  createdAt: Date;
1975
- updatedAt: Date;
1976
- deletedAt: Date | null;
1977
- deleted: boolean;
1978
- createdBy: number | null;
1979
- updatedBy: number | null;
1980
- deletedBy: number | null;
1981
- userId: number | null;
1982
- user: User | null;
1983
- form_submissions: FormSubmission[];
1984
- addresses: Address[];
1985
- orders: Order[];
1986
- payments: Payment[];
1987
- chatConversations: ChatConversation[];
1988
- orderAddresses: OrderAddresses[];
1989
3179
  }
1990
3180
 
1991
3181
  declare class Config {
@@ -2297,7 +3487,248 @@ declare class VendorCustomer {
2297
3487
  customer: Customer;
2298
3488
  }
2299
3489
 
3490
+ declare enum ComboItemType {
3491
+ FIXED = "fixed",
3492
+ ADDONS = "addons"
3493
+ }
3494
+ declare class ComboItem {
3495
+ id: number;
3496
+ comboId: number;
3497
+ combo: Combo;
3498
+ productId: number;
3499
+ product: Product;
3500
+ type: ComboItemType;
3501
+ }
3502
+
3503
+ declare enum ComboStatus {
3504
+ ACTIVE = "active",
3505
+ INACTIVE = "inactive",
3506
+ DRAFT = "draft"
3507
+ }
3508
+ declare class Combo {
3509
+ id: number;
3510
+ name: string;
3511
+ desc?: string;
3512
+ eventId: number;
3513
+ event: Event;
3514
+ price: number;
3515
+ currencyPrices: Record<string, number> | null;
3516
+ minSelectableItems: number;
3517
+ maxSelectableItems: number;
3518
+ status: ComboStatus;
3519
+ startsAt?: Date;
3520
+ endsAt?: Date;
3521
+ metadata?: Record<string, any>;
3522
+ items: ComboItem[];
3523
+ createdAt: Date;
3524
+ updatedAt: Date;
3525
+ deletedAt?: Date;
3526
+ deleted: boolean;
3527
+ createdBy?: number;
3528
+ updatedBy?: number;
3529
+ deletedBy?: number;
3530
+ }
3531
+
3532
+ declare enum RefundMethod {
3533
+ CARD = "card",
3534
+ UPI = "upi",
3535
+ NET_BANKING = "net_banking"
3536
+ }
3537
+ declare enum RefundRequestStatus {
3538
+ REQUESTED = "requested",
3539
+ APPROVED = "approved",
3540
+ REJECTED = "rejected",
3541
+ REFUNDED = "refunded"
3542
+ }
3543
+ declare class RefundRequest {
3544
+ id: number;
3545
+ refundPolicyId: number;
3546
+ refundPolicy: RefundPolicy;
3547
+ orderId: number;
3548
+ order: Order;
3549
+ customerId: number;
3550
+ customer: Customer;
3551
+ reason?: string;
3552
+ refundMethod: RefundMethod;
3553
+ status: RefundRequestStatus;
3554
+ expectedRefundAmount: number;
3555
+ approvedRefundAmount?: number;
3556
+ }
3557
+
3558
+ declare class Attendee {
3559
+ id: number;
3560
+ displayName: string;
3561
+ email: string;
3562
+ contactId: number | null;
3563
+ contact: Contact | null;
3564
+ }
3565
+
2300
3566
  /** Map API resource segment (e.g. "blogs", "form_submissions") to entity. Used by CRUD handler. */
2301
3567
  declare const CMS_ENTITY_MAP: Record<string, EntityTarget<typeorm.ObjectLiteral>>;
2302
3568
 
2303
- export { Address, type AnalyticsPluginConfig, Attribute, BLOG_GENERATOR_AGENT_NAME, BLOG_GENERATOR_DEFAULT_SYSTEM_INSTRUCTION, BLOG_GENERATOR_DEFAULT_VALIDATION_RULES, BLOG_GENERATOR_LLM_AGENT_SLUG, BLOG_GENERATOR_MARKDOWN_ARTICLE_SEPARATOR, BLOG_METADATA_ENRICHER_AGENT_NAME, BLOG_METADATA_ENRICHER_DEFAULT_SYSTEM_INSTRUCTION, BLOG_METADATA_ENRICHER_DEFAULT_VALIDATION_RULES, BLOG_METADATA_ENRICHER_LLM_AGENT_SLUG, Blog, type BlogGeneratorBlogDraft, type BlogGeneratorDraftParseMode, type BlogGeneratorPluginConfig, type BlogGeneratorSeoDraft, BlogGeneratorService, Brand, CMS_ENTITY_MAP, type CachePluginConfig, type CacheService, type CaptchaProviderId, type CaptchaPublicConfig, CaptchaService, type CaptchaVerifyResult, Cart, CartItem, Category, ChatConversation, ChatMessage, type CmsApp, type CmsPlugin, Collection, Comment, CompanyDetails, Config, Contact, type CreateCmsAppOptions, Currency, CurrencyExchange, Customer, Customer_Contacts, type DataSourceManager, Discount, DiscountRules, type ERPPluginConfig, type ERPPluginInstance, ERPSubmissionService, type EmailData, type EmailJobPayload, type EmailPluginConfig, EmailService, type EmailServiceInterface, EmailTemplateName, EmailTemplateResult, EntityCrudAction, EntityMap$2 as EntityMap, type ErpContactSyncInput, type ErpCreateContactPayload, type ErpJobPayload, type ErpPaidOrderDataSource, type ErpPaidOrderEntityMap, type ExtraPublicWriteRule, type FacebookMeAccountsResponse, type FacebookPageAccount, Form, FormField, FormSubmission, JOB_RUNNER_QUEUE, type CmsAppLike as JobRunnerCmsAppLike, type JobRunnerDeps, type JobRunnerPayload, JobSchedule, JobScheduleRun, KnowledgeBaseChunk, KnowledgeBaseDocument, type LatestArticleFromFeed, LlmAgent, type LlmAgentOptions, type LlmChatOptions, type LlmEmbeddingProvider, type LlmMessage, type LlmPluginConfig, LlmService, type LlmServiceEmbedOptions, type LlmServiceInterface, type LocalStoragePluginConfig, type Logger, Media, MessageTemplate, type MetaGraphMutationResponse, NextAuthUser, Order, OrderAddresses, OrderDiscounts, OrderItem, type OrderPlacedEmailPayload, OrderPlacedLineItem, OtpChallenge, type OtpChannel, type OtpPurpose, Page, PasswordResetToken, Payment, type PaymentIntent, type PaymentPluginConfig, type PaymentServiceInterface, Permission, type PgBossPluginConfig, PgBossService, type PipelineNames, type PluginContext, Product, ProductAttribute, ProductCategory, ProductTax, type PublicThemeSettingsPayload, type QueuePluginConfig, type QueueService, type RenderEmailOptions, type RenderedEmail, RssArticle, RssFeed, type S3StoragePluginConfig, type SendVendorOnboardEmailInput, Seo, type SeoLike, type SeoMetadataOverrides, SessionUser, type SmsJobPayload, type SmsPluginConfig, type SmsProviderChoice, type SmsProviderId, type SmsServiceConfig, type SmsServiceInterface, type SocialMediaPluginConfig, StorageService, Tag, Tax, TemplateContext, User, UserGroup, Vendor, VendorCustomer, VendorUser, Wishlist, WishlistItem, ZIP_MIME_TYPES, allowRateLimit, analyticsPlugin, applyVendorCustomersContactFilter, assertCaptchaOk, assertContactAllowedForVendorOrder, blogGeneratorPlugin, buildBlogMetadataUserPrompt, buildCaptchaPublicConfig, buildCronFromSchedule, buildRssUserPromptFromFeeds, cachePlugin, captchaPlugin, cn, contactIsVendorCustomer, countRecentOtpSends, createCmsApp, createDataSourceManager, createOtpChallenge, createSocialMediaHandlers, emailPlugin, emailTemplates, enrichUserWithVendorContext, ensureScheduleQueueWorker, erpPlugin, fetchSeoBySlug, formatDate, formatDateOnly, formatDateTime, generateNumericOtp, generateSlug, getRssArticleSummaryFromItem, hashOtpCode, hydrateVendorSessionUser, isCustomerTypeContact, isZipMedia, joinRecipientsForSend, linkUnclaimedContactToUser, llmAgentToChatAgentOptions, llmPlugin, loadPublicThemeSettings, loadUserVendorContext, localStoragePlugin, mergeSeoBySlug, metaFetchUserManagedPages, metaPostPageFeed, metaPostPagePhoto, metaResolvePageAccessToken, normalizePhoneE164, parseBlogGeneratorAgentContent, parseBlogGeneratorModelOutput, parseBlogMetadataEnrichmentJson, parseEmailRecipientsFromConfig, parseHfInferenceEmbeddingBody, paymentPlugin, pgBossPlugin, pgBossScheduleNameForId, queueEmail, queueErp, queueErpCreateContactIfEnabled, queueErpPaidOrderForOrderId, queueJobScheduleNow, queueOrderPlacedEmails, queuePlugin, queueSms, queueVendorOnboardEmails, rateLimitCheckoutPost, rateLimitKeyForApiRequest, rateLimitPublicApiIfNeeded, registerEmailQueueProcessor, registerErpQueueProcessor, registerJobRunnerWorker, registerSmsQueueProcessor, relativePathFromMediaParentId, renderEmail, renderLayout, resolveBlogCategoryIdByName, resolvePublicMetadata, resolveVendorIdForContactCheck, s3StoragePlugin, sanitizeMediaFolderPath, sanitizeStorageSegment, seedDefaultAdmin, sendOrderPlacedEmailsAfterConfirmation, sendVendorOnboardEmails, serializeEmailRecipients, shouldRateLimitPublicWrite, smsPlugin, socialMediaPlugin, syncJobScheduleToPgBoss, truncateText, validateScheduleInput, validateSlug, verifyAndConsumeOtpChallenge, verifyOtpCodeHash, withAdminRlsContext, withVendorRlsContext };
3569
+ /** Minimal DB handle for RBAC debug (avoids importing `typeorm` in the auth bundle). */
3570
+ type RbacDebugDataSource = {
3571
+ query: (sql: string, parameters?: unknown[]) => Promise<unknown>;
3572
+ };
3573
+ /** Set `CMS_RBAC_DEBUG=true` in `.env` to log permission decisions (server console). */
3574
+ declare function isRbacDebugEnabled(): boolean;
3575
+ declare function logRbac(message: string, data?: Record<string, unknown>): void;
3576
+ declare function summarizeEntityPerms(entityPerms: Record<string, EntityPermissionFlags> | undefined): Record<string, {
3577
+ c: boolean;
3578
+ r: boolean;
3579
+ u: boolean;
3580
+ d: boolean;
3581
+ }>;
3582
+ interface EntityAccessExplanation {
3583
+ allowed: boolean;
3584
+ reason: string;
3585
+ userSnapshot: Record<string, unknown>;
3586
+ }
3587
+ /** Same rules as `sessionHasEntityAccess`, but returns why access was granted or denied. */
3588
+ declare function explainSessionEntityAccess(user: SessionUser | null | undefined, entity: string, action: EntityCrudAction): EntityAccessExplanation;
3589
+ declare function logEntityAccessDecision(dataSource: RbacDebugDataSource | undefined, context: string, user: SessionUser | null | undefined, entity: string, action: EntityCrudAction, extra?: Record<string, unknown>): Promise<void>;
3590
+
3591
+ /** Platform super admin (`user_groups.id = 1` or Administrator group). */
3592
+ declare const SUPER_ADMIN_GROUP_ID = 1;
3593
+ /** Vendor store admin (`user_groups.id = 5` or vendor-linked portal users). */
3594
+ declare const VENDOR_ADMIN_GROUP_ID = 5;
3595
+ declare function isSuperAdmin(user: SessionUser | null | undefined): boolean;
3596
+ declare function isVendorAdmin(user: SessionUser | null | undefined): boolean;
3597
+
3598
+ /**
3599
+ * Ensures the Administrator group has full CRUD on every permissionable entity
3600
+ * for the given entity map. Idempotent: upserts per entity.
3601
+ */
3602
+ declare function seedAdministratorPermissions(dataSource: DataSource, entityMap: Record<string, unknown>): Promise<void>;
3603
+
3604
+ interface CmsMiddlewareRequest {
3605
+ nextUrl: {
3606
+ pathname: string;
3607
+ };
3608
+ url: string;
3609
+ method: string;
3610
+ cookies: {
3611
+ get: (name: string) => {
3612
+ value?: string;
3613
+ } | undefined;
3614
+ };
3615
+ /**
3616
+ * Full Next.js request (e.g. `NextRequest`). When provided, session is resolved via
3617
+ * `getToken()` so chunked `next-auth.session-token.N` cookies work.
3618
+ */
3619
+ req?: Parameters<typeof getToken>[0]['req'];
3620
+ }
3621
+ interface CmsMiddlewareConfig {
3622
+ publicAdminPaths?: string[];
3623
+ publicApiPaths?: string[];
3624
+ /** path -> allowed methods */
3625
+ publicApiMethods?: Record<string, string[]>;
3626
+ signInPath?: string;
3627
+ /** @deprecated Prefer passing `req` on the request; used only when `req` is omitted. */
3628
+ getSessionToken?: (request: CmsMiddlewareRequest) => string | undefined;
3629
+ secret?: string;
3630
+ }
3631
+ /** Default public API paths (no auth). Sites should extend this with their own routes. */
3632
+ declare const defaultPublicApiMethods: Record<string, string[]>;
3633
+ /**
3634
+ * Returns middleware logic. Use from Next.js middleware:
3635
+ * import { createCmsMiddleware } from '@infuro/cms-core';
3636
+ * export async function middleware(request: NextRequest) {
3637
+ * const result = await cmsMiddleware({ ...request fields, req: request });
3638
+ * ...
3639
+ * }
3640
+ * export const config = { matcher: ['/admin/:path*', '/api/:path*'] };
3641
+ */
3642
+ declare function createCmsMiddleware(config?: CmsMiddlewareConfig): (request: CmsMiddlewareRequest) => Promise<{
3643
+ type: "next";
3644
+ } | {
3645
+ type: "redirect";
3646
+ url: string;
3647
+ } | {
3648
+ type: "json";
3649
+ status: number;
3650
+ body: unknown;
3651
+ }>;
3652
+
3653
+ /** Set `CMS_AUTH_DEBUG=false` to silence server auth logs in development. */
3654
+ declare function isAuthDebugEnabled(): boolean;
3655
+ /** Browser console logs; set `NEXT_PUBLIC_CMS_AUTH_DEBUG=false` to silence. */
3656
+ declare function isAuthDebugClientEnabled(): boolean;
3657
+ declare function logAuth(message: string, data?: Record<string, unknown>): void;
3658
+ declare function logAuthClient(message: string, data?: Record<string, unknown>): void;
3659
+ declare function summarizeSessionUserForLog(user: unknown): Record<string, unknown>;
3660
+ declare function nextAuthCookieDebugInfo(): Record<string, unknown>;
3661
+
3662
+ type VendorOwnerActivation = 'invite' | 'password';
3663
+ interface VendorOnboardHandlersConfig {
3664
+ dataSource: DataSource;
3665
+ entityMap: EntityMap$2;
3666
+ json: (body: unknown, init?: {
3667
+ status?: number;
3668
+ }) => Response;
3669
+ getSessionUser: () => Promise<SessionUser | null>;
3670
+ baseUrl: string;
3671
+ getCms?: () => Promise<{
3672
+ getPlugin: (name: string) => unknown;
3673
+ }>;
3674
+ hashPassword?: (plain: string) => Promise<string>;
3675
+ minPasswordLength?: number;
3676
+ }
3677
+ declare function createVendorOnboardHandlers(config: VendorOnboardHandlersConfig): {
3678
+ /** POST /api/admin/vendors/onboard — create vendor + owner user + vendor_users + invite */
3679
+ onboard(req: Request): Promise<Response>;
3680
+ /** POST /api/admin/vendor/switch — set active vendor in session (JWT update via client) */
3681
+ switchVendor(req: Request): Promise<Response>;
3682
+ /** GET /api/admin/vendor/team */
3683
+ listTeam(): Promise<Response>;
3684
+ /** POST /api/admin/vendor/team — add staff to vendor */
3685
+ addTeamMember(req: Request): Promise<Response>;
3686
+ /** PATCH /api/admin/vendor/team/:userId — change member store role */
3687
+ updateTeamMemberRole(req: Request, userIdStr: string): Promise<Response>;
3688
+ /** DELETE /api/admin/vendor/team/:userId */
3689
+ removeTeamMember(_req: Request, userIdStr: string): Promise<Response>;
3690
+ };
3691
+
3692
+ interface StorefrontOtpFlags {
3693
+ login?: boolean;
3694
+ verifyEmail?: boolean;
3695
+ verifyPhone?: boolean;
3696
+ }
3697
+ interface StorefrontApiConfig {
3698
+ dataSource: DataSource;
3699
+ entityMap: EntityMap$2;
3700
+ json: (body: unknown, init?: {
3701
+ status?: number;
3702
+ headers?: HeadersInit;
3703
+ }) => Response;
3704
+ getSessionUser: () => Promise<SessionUser | null>;
3705
+ guestCookieName?: string;
3706
+ /** Required for POST storefront/register */
3707
+ hashPassword?: (plain: string) => Promise<string>;
3708
+ /** When set, new registrations are blocked until email is verified and a signup email is sent. */
3709
+ getCms?: () => Promise<{
3710
+ getPlugin: (name: string) => unknown;
3711
+ }>;
3712
+ getCompanyDetails?: () => Promise<CompanyDetails>;
3713
+ /** Origin for verify links (e.g. process.env.NEXTAUTH_URL). Required with getCms for verification URLs. */
3714
+ publicSiteUrl?: string;
3715
+ /** When a flag is true, the corresponding OTP storefront route is enabled. */
3716
+ otpFlags?: StorefrontOtpFlags;
3717
+ /** Defaults to OTP_PEPPER or NEXTAUTH_SECRET. */
3718
+ otpPepper?: string;
3719
+ defaultPhoneCountryCode?: string;
3720
+ /** When false, login OTP send accepts email only (no phone). Default true. */
3721
+ otpAllowPhoneLogin?: boolean;
3722
+ }
3723
+ declare function createStorefrontApiHandler(config: StorefrontApiConfig): {
3724
+ handle(method: string, path: string[], req: Request): Promise<Response>;
3725
+ };
3726
+
3727
+ interface AdminNavItem {
3728
+ href: string;
3729
+ label: string;
3730
+ icon?: string;
3731
+ }
3732
+ declare const DEFAULT_ADMIN_NAV: AdminNavItem[];
3733
+
3734
+ export { ADMIN_GROUP_NAME, Address, type AdminNavItem, type AnalyticsHandlerConfig, type AnalyticsPluginConfig, Attendee, Attribute, type AuthHandlersConfig, type AuthHelpers, type AuthorizeOtpInput, BLOG_GENERATOR_AGENT_NAME, BLOG_GENERATOR_DEFAULT_SYSTEM_INSTRUCTION, BLOG_GENERATOR_DEFAULT_VALIDATION_RULES, BLOG_GENERATOR_LLM_AGENT_SLUG, BLOG_GENERATOR_MARKDOWN_ARTICLE_SEPARATOR, BLOG_METADATA_ENRICHER_AGENT_NAME, BLOG_METADATA_ENRICHER_DEFAULT_SYSTEM_INSTRUCTION, BLOG_METADATA_ENRICHER_DEFAULT_VALIDATION_RULES, BLOG_METADATA_ENRICHER_LLM_AGENT_SLUG, Blog, type BlogBySlugConfig, type BlogGeneratorBlogDraft, type BlogGeneratorDraftParseMode, type BlogGeneratorPluginConfig, type BlogGeneratorSeoDraft, BlogGeneratorService, Brand, CMS_ENTITY_MAP, type CachePluginConfig, type CacheService, type CaptchaProviderId, type CaptchaPublicConfig, CaptchaService, type CaptchaVerifyResult, Cart, CartItem, Category, type ChangePasswordConfig, ChatConversation, ChatMessage, type ChatPublicConfig, type CmsApiHandlerConfig, type CmsApp, type CmsGetter, type CmsMiddlewareConfig, type CmsMiddlewareRequest, type CmsPlugin, Collection, Combo, ComboItem, Comment, type CompanyDetails, Config, Contact, type CreateCmsAppOptions, type CrudHandlerOptions, Currency, CurrencyExchange, Customer, Customer_Contacts, DEFAULT_ADMIN_NAV, type DashboardStatsConfig, type DataSourceManager, Discount, DiscountRules, type ERPPluginConfig, type ERPPluginInstance, ERPSubmissionService, EVENT_ORDER_MESSAGE_TEMPLATE_DEFAULTS, EVENT_ORDER_TEMPLATE_KEY, EVENT_ORDER_TEMPLATE_VARIABLES, type EcommerceAnalyticsConfig, type EmailData, type EmailJobPayload, type EmailPluginConfig, EmailService, type EmailServiceInterface, type EmailTemplateName, type EmailTemplateResult, type EnsureCustomerUserInput, type EnsureVendorCustomerDetails, type EntityCrudAction, type EntityMap$2 as EntityMap, type EntityPermissionFlags, type ErpContactSyncInput, type ErpCreateContactPayload, type ErpJobPayload, type ErpPaidOrderDataSource, type ErpPaidOrderEntityMap, Event, type EventNotificationHandlersConfig, type EventOrderMessageTemplateHandlersConfig, type EventOrderNotificationChannel$1 as EventOrderNotificationChannel, type EventOrderNotificationTemplates, type EventOrderTemplateOverride$1 as EventOrderTemplateOverride, EventProduct, type ExtraPublicWriteRule, type FacebookMeAccountsResponse, type FacebookPageAccount, type ForgotPasswordConfig, Form, type FormBySlugConfig, FormField, FormSubmission, type GetPublicSettingsGroupConfig, type GetPublicSettingsGroupDataSource, type GetSession, type InviteAcceptConfig, JOB_RUNNER_QUEUE, type CmsAppLike as JobRunnerCmsAppLike, type JobRunnerDeps, type JobRunnerPayload, JobSchedule, type JobScheduleApiConfig, JobScheduleRun, KnowledgeBaseChunk, KnowledgeBaseDocument, type LatestArticleFromFeed, LlmAgent, type LlmAgentKnowledgeApiConfig, type LlmAgentOptions, type LlmAgentValidationRulesJson, type LlmChatOptions, type LlmEmbeddingProvider, type LlmMessage, type LlmPluginConfig, LlmService, type LlmServiceEmbedOptions, type LlmServiceInterface, type LocalStoragePluginConfig, type Logger, Media, MessageTemplate, type MetaGraphMutationResponse, type NextAuthOptionsConfig, type NextAuthUser, OPEN_ENDPOINTS, Order, OrderAddresses, OrderDiscounts, OrderItem, type OrderPlacedEmailPayload, type OrderPlacedLineItem, OtpChallenge, type OtpChannel, type OtpPurpose, PERMISSION_REQUIRED_ENDPOINTS, Page, type ParsedLlmAgentValidation, PasswordResetToken, Payment, type PaymentIntent, type PaymentPluginConfig, type PaymentServiceInterface, Permission, type PgBossPluginConfig, PgBossService, type PipelineNames, type PluginContext, Product, ProductAttribute, ProductCategory, ProductConfig, ProductVariant, type PublicThemeSettingsPayload, type QueuePluginConfig, type QueueService, RBAC_ADMIN_ONLY_ENTITIES, type RefundCalculationResult, RefundPolicy, type RefundPolicyLike, type RefundPolicyTier, RefundRequest, type RenderEmailOptions, type RenderedEmail, RssArticle, RssFeed, type S3StoragePluginConfig, SUPER_ADMIN_GROUP_ID, type SendVendorOnboardEmailInput, Seo, type SeoLike, type SeoMetadataOverrides, type SessionUser, type SetPasswordConfig, type SettingsApiConfig, type SmsJobPayload, type SmsPluginConfig, type SmsProviderChoice, type SmsProviderId, type SmsServiceConfig, type SmsServiceInterface, type SocialLinkItem, type SocialMediaPluginConfig, type StorageService, type StorefrontApiConfig, type StorefrontOtpFlags, Tag, Tax, type TemplateContext, type UploadHandlerConfig, User, type UserAuthApiConfig, type UserAvatarConfig, UserGroup, type UserProfileConfig, type UsersApiConfig, VENDOR_ADMIN_GROUP_ID, VENDOR_OWNER_GROUP_NAME, VENDOR_SCOPED_STORE_ENTITIES, VENDOR_STORE_RBAC_ENTITIES, Vendor, VendorCustomer, type VendorDashboardConfig, type VendorOnboardHandlersConfig, type VendorOwnerActivation, VendorRole, VendorRolePermission, VendorUser, type WhatsAppJobPayload, type WhatsAppPluginConfig, type WhatsAppServiceConfig, type WhatsAppServiceInterface, Wishlist, WishlistItem, ZIP_MIME_TYPES, allowRateLimit, analyticsPlugin, applyVendorCustomersContactFilter, assertCaptchaOk, assertContactAllowedForVendorOrder, blogGeneratorPlugin, buildBlogMetadataUserPrompt, buildCaptchaPublicConfig, buildCronFromSchedule, buildEventOrderTemplateVariables, buildRssUserPromptFromFeeds, cachePlugin, calculateOrderRefundPreview, calculateRefundFromPolicy, canManageRoles, canManageVendorRoles, canManageVendorTeam, canOnboardVendors, captchaPlugin, cn, contactIsVendorCustomer, countRecentOtpSends, createAnalyticsHandlers, createAuthHelpers, createBlogBySlugHandler, createChangePasswordHandler, createCmsApiHandler, createCmsApp, createCmsAuthBundle, createCmsMiddleware, createCrudByIdHandler, createCrudHandler, createDashboardStatsHandler, createDataSourceManager, createEcommerceAnalyticsHandler, createEventNotificationHandlers, createEventOrderMessageTemplateHandlers, createForgotPasswordHandler, createFormBySlugHandler, createInviteAcceptHandler, createJobScheduleHandlers, createLlmAgentKnowledgeHandlers, createMediaZipExtractHandler, createOtpChallenge, createSetPasswordHandler, createSettingsApiHandlers, createSocialMediaHandlers, createStorefrontApiHandler, createUploadHandler, createUserAuthApiRouter, createUserAvatarHandler, createUserProfileHandler, createUsersApiHandlers, createVendorDashboardHandler, createVendorOnboardHandlers, customerPhoneForUser, daysBeforeEventStart, defaultPublicApiMethods, describeEventTierPolicy, dispatchEventOrderNotifications, emailPlugin, emailTemplates, enrichUserWithVendorContext, ensureCustomerForUser, ensureScheduleQueueWorker, ensureVendorCustomerForOrderContact, erpPlugin, explainSessionEntityAccess, fetchSeoBySlug, findActiveRefundPolicyForVendor, formatDate, formatDateOnly, formatDateTime, formatTierRange, generateNumericOtp, generateSlug, getCompanyDetailsFromSettings, getNextAuthOptions, getPermissionableEntityKeys, getPublicSettingsGroup, getRequiredPermission, getRssArticleSummaryFromItem, getStorefrontNextAuthOptions, hasEntityPermission, hashOtpCode, hydrateVendorSessionUser, isAuthDebugClientEnabled, isAuthDebugEnabled, isCustomerTypeContact, isOpenEndpoint, isPlatformAdministrator, isPublicMethod, isRbacDebugEnabled, isSuperAdmin, isSuperAdminGroupName, isVendorAdmin, isVendorGroupName, isVendorOwner, isVendorPortalUser, isVendorStaff, isZipMedia, joinRecipientsForSend, linkUnclaimedContactToUser, llmAgentToChatAgentOptions, llmPlugin, loadPublicThemeSettings, loadUserVendorContext, localStoragePlugin, logAuth, logAuthClient, logEntityAccessDecision, logRbac, mergeEmailLayoutCompanyDetails, mergeGuardrailsIntoSystemPrompt, mergeSeoBySlug, metaFetchUserManagedPages, metaPostPageFeed, metaPostPagePhoto, metaResolvePageAccessToken, nextAuthCookieDebugInfo, normalizePhoneE164, normalizeRefundTiers, parseBlogGeneratorAgentContent, parseBlogGeneratorModelOutput, parseBlogMetadataEnrichmentJson, parseEmailRecipientsFromConfig, parseHfInferenceEmbeddingBody, parseLlmAgentValidationRules, paymentPlugin, permissionRowsToRecord, pgBossPlugin, pgBossScheduleNameForId, queueEmail, queueErp, queueErpCreateContactIfEnabled, queueErpPaidOrderForOrderId, queueJobScheduleNow, queueOrderPlacedEmails, queuePlugin, queueSms, queueVendorOnboardEmails, queueWhatsApp, rateLimitCheckoutPost, rateLimitKeyForApiRequest, rateLimitPublicApiIfNeeded, registerEmailQueueProcessor, registerErpQueueProcessor, registerJobRunnerWorker, registerSmsQueueProcessor, registerWhatsAppQueueProcessor, relativePathFromMediaParentId, renderEmail, renderLayout, resolveBlogCategoryIdByName, resolveEventOrderTemplate, resolvePublicMetadata, resolveVendorIdForContactCheck, resolveVendorScopeFromSessionUser, s3StoragePlugin, sanitizeMediaFolderPath, sanitizeStorageSegment, seedAdministratorPermissions, seedDefaultAdmin, sendOrderPlacedEmailsAfterConfirmation, sendVendorOnboardEmails, serializeEmailRecipients, sessionHasEntityAccess, shouldRateLimitPublicWrite, simpleDecrypt, simpleEncrypt, smsPlugin, socialMediaPlugin, summarizeEntityPerms, summarizeSessionUserForLog, syncJobScheduleToPgBoss, truncateText, validateRefundTiers, validateScheduleInput, validateSlug, validateUserMessageAgainstAgentRules, validateUserMessageAgainstStructuredRules, vendorPortalFlagsFromUser, verifyAndConsumeOtpChallenge, verifyOtpCodeHash, whatsappPlugin, withAdminRlsContext, withVendorRlsContext };