@infuro/cms-core 1.0.33 → 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 (164) hide show
  1. package/README.md +22 -6
  2. package/dist/OrderTrackPage-W3J6WIG2.js +426 -0
  3. package/dist/OrderTrackPage-Z6FCJQYY.cjs +428 -0
  4. package/dist/admin.cjs +34072 -20487
  5. package/dist/admin.d.cts +191 -9
  6. package/dist/admin.d.ts +191 -9
  7. package/dist/admin.js +33913 -20423
  8. package/dist/api.cjs +123 -16508
  9. package/dist/api.d.cts +633 -3
  10. package/dist/api.d.ts +633 -3
  11. package/dist/api.js +14 -16519
  12. package/dist/auth.cjs +196 -955
  13. package/dist/auth.d.cts +201 -42
  14. package/dist/auth.d.ts +201 -42
  15. package/dist/auth.js +4 -888
  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 +142 -84
  59. package/dist/cli.js +101 -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 -21070
  77. package/dist/index.d.cts +2255 -749
  78. package/dist/index.d.ts +2255 -749
  79. package/dist/index.js +1925 -19891
  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/1778660000004-CreateCustomerAndCustomerContacts.ts +99 -0
  85. package/dist/migrations/1778660000005-AddCustomerIdToVendorCustomers.ts +39 -0
  86. package/dist/migrations/1778660000006-UpdateVendorCustomersContactNullable.ts +36 -0
  87. package/dist/migrations/1778660000007-VendorOwnerCustomerContactsPermission.ts +39 -0
  88. package/dist/migrations/1779300000000-VendorOwnerContactsPermission.ts +39 -0
  89. package/dist/migrations/1779400000000-AddCustomerContactIdToOrders.ts +33 -0
  90. package/dist/migrations/1779400000000-ConvertStatusToEnum.ts +142 -0
  91. package/dist/migrations/1779400000000-SeedDefaultCurrencies.ts +33 -0
  92. package/dist/migrations/1779500000000-VendorRolesAndPermissions.ts +102 -0
  93. package/dist/migrations/1779600000000-VendorRegistrationProfile.ts +52 -0
  94. package/dist/migrations/1779700000000-CollectionIsCatalog.ts +22 -0
  95. package/dist/migrations/1779710000000-CollectionPlatformCatalog.ts +60 -0
  96. package/dist/migrations/1779720000000-ProductCategoryPlatformCatalog.ts +157 -0
  97. package/dist/migrations/1779800000000-EventsAndEventProducts.ts +173 -0
  98. package/dist/migrations/1779810000000-BackfillVendorRoleEventsPermissions.ts +38 -0
  99. package/dist/migrations/1779820000000-FixProductsCategoryForeignKey.ts +70 -0
  100. package/dist/migrations/1779830000000-ProductTitleColumn.ts +32 -0
  101. package/dist/migrations/1779840000000-EventAboutAndVisibilityFields.ts +34 -0
  102. package/dist/migrations/1779850000000-EventCityCountrySplit.ts +43 -0
  103. package/dist/migrations/1779860000000-CreateCombos.ts +140 -0
  104. package/dist/migrations/1780100000000-OrderAttendeesEventId.ts +55 -0
  105. package/dist/migrations/1780110000000-EventContactFormId.ts +49 -0
  106. package/dist/migrations/1780130000000-ProductVariants.ts +54 -0
  107. package/dist/migrations/1780140000000-EventManagementEnhancements.ts +44 -0
  108. package/dist/migrations/1780160000000-EventRegistrationGstProductContactForm.ts +79 -0
  109. package/dist/migrations/1780170000000-ComboCurrencyPrices.ts +20 -0
  110. package/dist/migrations/1781110000000-VendorOwnerCombosPermission.ts +38 -0
  111. package/dist/migrations/1781120000000-RefundPoliciesAndRequests.ts +225 -0
  112. package/dist/migrations/1781130000000-CreateAttendees.ts +44 -0
  113. package/dist/migrations/1781140000000-EventOrderNotifications.ts +29 -0
  114. package/dist/migrations/1781150000000-EventNamedLists.ts +28 -0
  115. package/dist/migrations/1781160000000-RefundPolicyEventTiers.ts +27 -0
  116. package/dist/migrations/1781170000000-EventRefundPolicy.ts +42 -0
  117. package/dist/migrations/1781180000000-RemoveCartItemsUniqueConstraint.ts +15 -0
  118. package/dist/migrations/1781190000000-RenameProductTaxesToProductConfig.ts +84 -0
  119. package/dist/migrations/1781200000000-VendorOwnerProductConfigPermissions.ts +51 -0
  120. package/dist/migrations/1781210000000-VendorRoleProductConfigPermissions.ts +46 -0
  121. package/dist/migrations/helpers/vendor-role-seed.ts +243 -0
  122. package/dist/paid-order-erp-3USEG6WL.js +3 -0
  123. package/dist/paid-order-erp-FSQ3GSXE.cjs +12 -0
  124. package/dist/pg-boss-service-4XF2TQ2E.js +2 -0
  125. package/dist/pg-boss-service-L6MTF4EQ.cjs +15 -0
  126. package/dist/razorpay-KLO2KNCB.js +49 -0
  127. package/dist/razorpay-U23LGY72.cjs +56 -0
  128. package/dist/rbac-debug-db-D7ME7QUY.cjs +35 -0
  129. package/dist/rbac-debug-db-MTCTVNNM.js +33 -0
  130. package/dist/sms-defaults-2NL24H57.js +2 -0
  131. package/dist/sms-defaults-KCOPKQBA.cjs +19 -0
  132. package/dist/stripe-4FD27QVJ.js +51 -0
  133. package/dist/stripe-VU6OEG2D.cjs +57 -0
  134. package/dist/theme.cjs +31 -59
  135. package/dist/theme.d.cts +78 -3
  136. package/dist/theme.d.ts +78 -3
  137. package/dist/theme.js +23 -20
  138. package/dist/vendor-invite-status-77O7ZQ3U.cjs +19 -0
  139. package/dist/vendor-invite-status-PWJ3DE76.js +2 -0
  140. package/dist/whatsapp-queue-3DXA4MXU.js +2 -0
  141. package/dist/whatsapp-queue-KG65MXD5.cjs +15 -0
  142. package/package.json +147 -141
  143. package/dist/admin.cjs.map +0 -1
  144. package/dist/admin.js.map +0 -1
  145. package/dist/api.cjs.map +0 -1
  146. package/dist/api.js.map +0 -1
  147. package/dist/auth.cjs.map +0 -1
  148. package/dist/auth.js.map +0 -1
  149. package/dist/cli.cjs.map +0 -1
  150. package/dist/cli.js.map +0 -1
  151. package/dist/config-DJ5CmQvS.d.cts +0 -8
  152. package/dist/config-DJ5CmQvS.d.ts +0 -8
  153. package/dist/hooks.cjs.map +0 -1
  154. package/dist/hooks.js.map +0 -1
  155. package/dist/index-DWd5Gjc4.d.ts +0 -582
  156. package/dist/index-rZTnpK7y.d.cts +0 -582
  157. package/dist/index.cjs.map +0 -1
  158. package/dist/index.js.map +0 -1
  159. package/dist/theme.cjs.map +0 -1
  160. package/dist/theme.js.map +0 -1
  161. package/dist/types-DCVaXlPV.d.cts +0 -78
  162. package/dist/types-DCVaXlPV.d.ts +0 -78
  163. package/dist/vendor-scope-DTYhJk_I.d.cts +0 -129
  164. package/dist/vendor-scope-DTYhJk_I.d.ts +0 -129
package/dist/auth.d.cts CHANGED
@@ -1,56 +1,99 @@
1
- import { S as SessionUser, E as EntityCrudAction, b as EntityPermissionFlags } from './vendor-scope-DTYhJk_I.cjs';
2
- export { A as ADMIN_GROUP_NAME, a as AuthHelpers, 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.cjs';
3
1
  import { DataSource } from 'typeorm';
4
2
  import { getToken } from 'next-auth/jwt';
5
3
  import { NextAuthOptions } from 'next-auth';
6
4
 
5
+ /** Canonical name for new installs / migrations */
6
+ declare const ADMIN_GROUP_NAME = "Administrator";
7
+ /** System administrator group (roles UI + users / user_groups / permissions bypass). */
8
+ declare function isSuperAdminGroupName(name: string | null | undefined): boolean;
9
+ type EntityCrudAction = 'create' | 'read' | 'update' | 'delete';
10
+ type EntityPermissionFlags = {
11
+ c: boolean;
12
+ r: boolean;
13
+ u: boolean;
14
+ d: boolean;
15
+ };
16
+ declare function getPermissionableEntityKeys(entityMap: Record<string, unknown>): string[];
17
+ declare function permissionRowsToRecord(rows: Array<{
18
+ entity: string;
19
+ canCreate: boolean;
20
+ canRead: boolean;
21
+ canUpdate: boolean;
22
+ canDelete: boolean;
23
+ }> | undefined): Record<string, EntityPermissionFlags>;
24
+ declare function hasEntityPermission(record: Record<string, EntityPermissionFlags> | undefined, entity: string, action: EntityCrudAction): boolean;
25
+
7
26
  /**
8
- * Build NextAuth options for credentials auth. App can extend/override via extend().
27
+ * @deprecated Administrator bypass is now full entity access via `isRBACAdmin` in `sessionHasEntityAccess`.
28
+ * Kept for backwards-compatible imports.
9
29
  */
10
-
11
- interface NextAuthUser {
12
- id: number;
13
- email: string;
14
- name: string | null;
15
- password: string | null;
16
- blocked?: boolean;
17
- deleted?: boolean;
18
- groupId?: number | null;
30
+ declare const RBAC_ADMIN_ONLY_ENTITIES: Set<string>;
31
+ interface SessionUser {
32
+ id?: string;
33
+ email?: string | null;
34
+ name?: string | null;
35
+ groupId?: number;
36
+ /** User group display name (from login). */
37
+ groupName?: string | null;
38
+ /** @deprecated use entityPerms / isRBACAdmin */
39
+ permissions?: string[];
40
+ /** Administrator group: bypasses entity-level RBAC on all resources */
41
+ isRBACAdmin?: boolean;
42
+ entityPerms?: Record<string, EntityPermissionFlags>;
43
+ /** When false and not isRBACAdmin, admin API/UI is denied. */
19
44
  adminAccess?: boolean;
20
- group?: {
21
- name?: string;
22
- permissions?: Array<{
23
- entity: string;
24
- canCreate: boolean;
25
- canRead: boolean;
26
- canUpdate: boolean;
27
- canDelete: boolean;
28
- }>;
29
- };
45
+ /** Vendor stores this user can access (from vendor_users). */
30
46
  vendorIds?: number[];
47
+ /** Active vendor for scoped CRUD (vendor staff). */
31
48
  activeVendorId?: number | null;
49
+ /** Role for the active vendor link (`vendor_users.role`). */
32
50
  vendorRole?: 'owner' | 'staff' | null;
51
+ /** Active vendor-scoped role id (`vendor_users.vendorRoleId`). */
52
+ vendorRoleId?: number | null;
53
+ vendorRoleName?: string | null;
54
+ /** True when active vendor role has `isOwnerRole`. */
55
+ isVendorRoleOwner?: boolean;
56
+ /** Permissions from active vendor role (`vendor_role_permissions`). */
57
+ vendorEntityPerms?: Record<string, EntityPermissionFlags>;
58
+ /** Set at login: vendor store portal (not platform admin). */
59
+ isVendorPortal?: boolean;
60
+ /** Set at login: vendor store owner (team + permissions). */
61
+ isVendorOwner?: boolean;
33
62
  }
34
- interface AuthorizeOtpInput {
35
- identifier: string;
36
- channel: 'email' | 'sms';
37
- code: string;
38
- }
39
- interface NextAuthOptionsConfig {
40
- /** Resolve user by email (e.g. from TypeORM). Return null if not found. */
41
- getUserByEmail: (email: string) => Promise<NextAuthUser | null>;
42
- comparePassword: (plain: string, hash: string) => Promise<boolean>;
43
- signInPage?: string;
44
- secret?: string;
45
- extend?: (options: NextAuthOptions) => NextAuthOptions;
46
- /** When false, password CredentialsProvider is omitted. Default true. */
47
- enablePasswordLogin?: boolean;
48
- /** When true, registers CredentialsProvider id `otp`. Requires authorizeOtp. Default false. */
49
- enableOtpLogin?: boolean;
50
- /** Validate OTP and return user (same shape as password flow) or null. */
51
- authorizeOtp?: (input: AuthorizeOtpInput) => Promise<NextAuthUser | null>;
63
+ declare function sessionHasEntityAccess(user: SessionUser | null | undefined, entity: string, action: EntityCrudAction): boolean;
64
+ declare function canManageRoles(user: SessionUser | null | undefined): boolean;
65
+ type GetSession = () => Promise<{
66
+ user?: SessionUser;
67
+ } | null>;
68
+ declare const OPEN_ENDPOINTS: Array<Record<string, string[]>>;
69
+ declare const PERMISSION_REQUIRED_ENDPOINTS: Record<string, string[]>;
70
+ declare function isOpenEndpoint(pathname: string): boolean;
71
+ declare function getRequiredPermission(pathname: string): string[] | null;
72
+ declare function isPublicMethod(pathname: string, method: string): boolean;
73
+ interface AuthHelpers {
74
+ requireAuth(req: Request): Promise<Response | null>;
75
+ requirePermission(req: Request, permission: string): Promise<Response | null>;
76
+ requireEntityPermission(req: Request, entity: string, action: EntityCrudAction): Promise<Response | null>;
77
+ requireAdminAccess(req: Request): Promise<Response | null>;
78
+ getAuthenticatedUser(): Promise<SessionUser | null>;
52
79
  }
53
- declare function getNextAuthOptions(config: NextAuthOptionsConfig): NextAuthOptions;
80
+ declare function createAuthHelpers(getSession: GetSession, NextResponse: {
81
+ json: (body: unknown, init?: {
82
+ status?: number;
83
+ }) => Response;
84
+ }): AuthHelpers;
85
+ /** Pass return value into `createCmsApiHandler` (includes `getSessionUser` for vendor store APIs). */
86
+ declare function createCmsAuthBundle(getSession: GetSession, NextResponse: {
87
+ json: (body: unknown, init?: {
88
+ status?: number;
89
+ }) => Response;
90
+ }): {
91
+ requireAuth: (req: Request) => Promise<Response | null>;
92
+ requireAdminAccess: (req: Request) => Promise<Response | null>;
93
+ requireEntityPermission: (req: Request, entity: string, action: EntityCrudAction) => Promise<Response | null>;
94
+ getSessionUser: () => Promise<SessionUser | null>;
95
+ getAuthenticatedUser: () => Promise<SessionUser | null>;
96
+ };
54
97
 
55
98
  /** Minimal DB handle for RBAC debug (avoids importing `typeorm` in the auth bundle). */
56
99
  type RbacDebugDataSource = {
@@ -74,6 +117,56 @@ interface EntityAccessExplanation {
74
117
  declare function explainSessionEntityAccess(user: SessionUser | null | undefined, entity: string, action: EntityCrudAction): EntityAccessExplanation;
75
118
  declare function logEntityAccessDecision(dataSource: RbacDebugDataSource | undefined, context: string, user: SessionUser | null | undefined, entity: string, action: EntityCrudAction, extra?: Record<string, unknown>): Promise<void>;
76
119
 
120
+ /** Platform super admin (`user_groups.id = 1` or Administrator group). */
121
+ declare const SUPER_ADMIN_GROUP_ID = 1;
122
+ /** Vendor store admin (`user_groups.id = 5` or vendor-linked portal users). */
123
+ declare const VENDOR_ADMIN_GROUP_ID = 5;
124
+ declare function isSuperAdmin(user: SessionUser | null | undefined): boolean;
125
+ declare function isVendorAdmin(user: SessionUser | null | undefined): boolean;
126
+
127
+ /** Entities with a `vendorId` column (store data). */
128
+ declare const VENDOR_SCOPED_STORE_ENTITIES: Set<string>;
129
+ /**
130
+ * Store admin RBAC for vendor portal users (read/create/update/delete fallbacks in rbac-debug).
131
+ * Includes entities without `vendorId` that are still part of the store admin UI.
132
+ */
133
+ declare const VENDOR_STORE_RBAC_ENTITIES: Set<string>;
134
+ type VendorScope = {
135
+ type: 'all';
136
+ } | {
137
+ type: 'vendor';
138
+ vendorId: number;
139
+ vendorIds: number[];
140
+ } | {
141
+ type: 'deny';
142
+ };
143
+ declare const VENDOR_OWNER_GROUP_NAME = "Vendor Owner";
144
+ /** User groups treated as vendor store staff (sidebar + scoped admin). */
145
+ declare function isVendorGroupName(name: string | null | undefined): boolean;
146
+ declare function isPlatformAdministrator(user: SessionUser | null | undefined): boolean;
147
+ /** Vendor portal UI (store + store admin), not platform admin. */
148
+ declare function isVendorPortalUser(user: SessionUser | null | undefined): boolean;
149
+ declare function isVendorStaff(user: SessionUser | null | undefined): boolean;
150
+ /** Vendor store owner (manages team + role permissions for their store). */
151
+ declare function isVendorOwner(user: SessionUser | null | undefined): boolean;
152
+ declare function canManageVendorTeam(user: SessionUser | null | undefined): boolean;
153
+ declare function canManageVendorRoles(user: SessionUser | null | undefined): boolean;
154
+ /** Platform admins (Administrator group) can onboard vendors. */
155
+ declare function canOnboardVendors(user: SessionUser | null | undefined): boolean;
156
+ declare function resolveVendorScopeFromSessionUser(user: SessionUser | null | undefined): VendorScope;
157
+ /** Compute portal flags at login (persist on JWT). */
158
+ declare function vendorPortalFlagsFromUser(input: {
159
+ email: string;
160
+ isRBACAdmin: boolean;
161
+ groupName?: string | null;
162
+ vendorIds?: number[];
163
+ vendorRole?: 'owner' | 'staff' | null;
164
+ isVendorRoleOwner?: boolean;
165
+ }): {
166
+ isVendorPortal: boolean;
167
+ isVendorOwner: boolean;
168
+ };
169
+
77
170
  /**
78
171
  * Ensures the Administrator group has full CRUD on every permissionable entity
79
172
  * for the given entity map. Idempotent: upserts per entity.
@@ -138,4 +231,70 @@ declare function logAuthClient(message: string, data?: Record<string, unknown>):
138
231
  declare function summarizeSessionUserForLog(user: unknown): Record<string, unknown>;
139
232
  declare function nextAuthCookieDebugInfo(): Record<string, unknown>;
140
233
 
141
- export { type AuthorizeOtpInput, type CmsMiddlewareConfig, type CmsMiddlewareRequest, EntityCrudAction, EntityPermissionFlags, type NextAuthOptionsConfig, type NextAuthUser, SessionUser, createCmsMiddleware, defaultPublicApiMethods, explainSessionEntityAccess, getNextAuthOptions, isAuthDebugClientEnabled, isAuthDebugEnabled, isRbacDebugEnabled, logAuth, logAuthClient, logEntityAccessDecision, logRbac, nextAuthCookieDebugInfo, seedAdministratorPermissions, summarizeEntityPerms, summarizeSessionUserForLog };
234
+ /**
235
+ * Build NextAuth options for credentials auth. App can extend/override via extend().
236
+ */
237
+
238
+ interface NextAuthUser {
239
+ id: number;
240
+ email: string;
241
+ name: string | null;
242
+ password: string | null;
243
+ blocked?: boolean;
244
+ deleted?: boolean;
245
+ groupId?: number | null;
246
+ adminAccess?: boolean;
247
+ group?: {
248
+ name?: string;
249
+ permissions?: Array<{
250
+ entity: string;
251
+ canCreate: boolean;
252
+ canRead: boolean;
253
+ canUpdate: boolean;
254
+ canDelete: boolean;
255
+ }>;
256
+ };
257
+ vendorIds?: number[];
258
+ activeVendorId?: number | null;
259
+ vendorRole?: 'owner' | 'staff' | null;
260
+ vendorRoleId?: number | null;
261
+ vendorRoleName?: string | null;
262
+ isVendorRoleOwner?: boolean;
263
+ vendorEntityPerms?: Record<string, {
264
+ c: boolean;
265
+ r: boolean;
266
+ u: boolean;
267
+ d: boolean;
268
+ }>;
269
+ }
270
+ interface AuthorizeOtpInput {
271
+ identifier: string;
272
+ channel: 'email' | 'sms';
273
+ code: string;
274
+ }
275
+ interface NextAuthOptionsConfig {
276
+ /** Resolve user by email (e.g. from TypeORM). Return null if not found. */
277
+ getUserByEmail: (email: string) => Promise<NextAuthUser | null>;
278
+ comparePassword: (plain: string, hash: string) => Promise<boolean>;
279
+ signInPage?: string;
280
+ secret?: string;
281
+ extend?: (options: NextAuthOptions) => NextAuthOptions;
282
+ /** When false, password CredentialsProvider is omitted. Default true. */
283
+ enablePasswordLogin?: boolean;
284
+ /** When true, registers CredentialsProvider id `otp`. Requires authorizeOtp. Default false. */
285
+ enableOtpLogin?: boolean;
286
+ /** Validate OTP and return user (same shape as password flow) or null. */
287
+ authorizeOtp?: (input: AuthorizeOtpInput) => Promise<NextAuthUser | null>;
288
+ /**
289
+ * Customer group sign-in policy for credentials/OTP on a shared `/api/auth` route:
290
+ * - `true` — always allow (dedicated storefront auth)
291
+ * - `false` — always block
292
+ * - omitted — auto: allow unless `callbackUrl` targets `/admin` (storefront `/signin` works unchanged)
293
+ */
294
+ allowCustomerLogin?: boolean;
295
+ }
296
+ declare function getNextAuthOptions(config: NextAuthOptionsConfig): NextAuthOptions;
297
+ /** Storefront sign-in: allows Customer group; use with signInPage `/signin`. */
298
+ declare function getStorefrontNextAuthOptions(config: Omit<NextAuthOptionsConfig, 'allowCustomerLogin'>): NextAuthOptions;
299
+
300
+ export { ADMIN_GROUP_NAME, type AuthHelpers, type AuthorizeOtpInput, type CmsMiddlewareConfig, type CmsMiddlewareRequest, type EntityCrudAction, type EntityPermissionFlags, type GetSession, type NextAuthOptionsConfig, type NextAuthUser, OPEN_ENDPOINTS, PERMISSION_REQUIRED_ENDPOINTS, RBAC_ADMIN_ONLY_ENTITIES, SUPER_ADMIN_GROUP_ID, type SessionUser, VENDOR_ADMIN_GROUP_ID, VENDOR_OWNER_GROUP_NAME, VENDOR_SCOPED_STORE_ENTITIES, VENDOR_STORE_RBAC_ENTITIES, canManageRoles, canManageVendorRoles, canManageVendorTeam, canOnboardVendors, createAuthHelpers, createCmsAuthBundle, createCmsMiddleware, defaultPublicApiMethods, explainSessionEntityAccess, getNextAuthOptions, getPermissionableEntityKeys, getRequiredPermission, getStorefrontNextAuthOptions, hasEntityPermission, isAuthDebugClientEnabled, isAuthDebugEnabled, isOpenEndpoint, isPlatformAdministrator, isPublicMethod, isRbacDebugEnabled, isSuperAdmin, isSuperAdminGroupName, isVendorAdmin, isVendorGroupName, isVendorOwner, isVendorPortalUser, isVendorStaff, logAuth, logAuthClient, logEntityAccessDecision, logRbac, nextAuthCookieDebugInfo, permissionRowsToRecord, resolveVendorScopeFromSessionUser, seedAdministratorPermissions, sessionHasEntityAccess, summarizeEntityPerms, summarizeSessionUserForLog, vendorPortalFlagsFromUser };
package/dist/auth.d.ts CHANGED
@@ -1,56 +1,99 @@
1
- import { S as SessionUser, E as EntityCrudAction, b as EntityPermissionFlags } from './vendor-scope-DTYhJk_I.js';
2
- export { A as ADMIN_GROUP_NAME, a as AuthHelpers, 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';
3
1
  import { DataSource } from 'typeorm';
4
2
  import { getToken } from 'next-auth/jwt';
5
3
  import { NextAuthOptions } from 'next-auth';
6
4
 
5
+ /** Canonical name for new installs / migrations */
6
+ declare const ADMIN_GROUP_NAME = "Administrator";
7
+ /** System administrator group (roles UI + users / user_groups / permissions bypass). */
8
+ declare function isSuperAdminGroupName(name: string | null | undefined): boolean;
9
+ type EntityCrudAction = 'create' | 'read' | 'update' | 'delete';
10
+ type EntityPermissionFlags = {
11
+ c: boolean;
12
+ r: boolean;
13
+ u: boolean;
14
+ d: boolean;
15
+ };
16
+ declare function getPermissionableEntityKeys(entityMap: Record<string, unknown>): string[];
17
+ declare function permissionRowsToRecord(rows: Array<{
18
+ entity: string;
19
+ canCreate: boolean;
20
+ canRead: boolean;
21
+ canUpdate: boolean;
22
+ canDelete: boolean;
23
+ }> | undefined): Record<string, EntityPermissionFlags>;
24
+ declare function hasEntityPermission(record: Record<string, EntityPermissionFlags> | undefined, entity: string, action: EntityCrudAction): boolean;
25
+
7
26
  /**
8
- * Build NextAuth options for credentials auth. App can extend/override via extend().
27
+ * @deprecated Administrator bypass is now full entity access via `isRBACAdmin` in `sessionHasEntityAccess`.
28
+ * Kept for backwards-compatible imports.
9
29
  */
10
-
11
- interface NextAuthUser {
12
- id: number;
13
- email: string;
14
- name: string | null;
15
- password: string | null;
16
- blocked?: boolean;
17
- deleted?: boolean;
18
- groupId?: number | null;
30
+ declare const RBAC_ADMIN_ONLY_ENTITIES: Set<string>;
31
+ interface SessionUser {
32
+ id?: string;
33
+ email?: string | null;
34
+ name?: string | null;
35
+ groupId?: number;
36
+ /** User group display name (from login). */
37
+ groupName?: string | null;
38
+ /** @deprecated use entityPerms / isRBACAdmin */
39
+ permissions?: string[];
40
+ /** Administrator group: bypasses entity-level RBAC on all resources */
41
+ isRBACAdmin?: boolean;
42
+ entityPerms?: Record<string, EntityPermissionFlags>;
43
+ /** When false and not isRBACAdmin, admin API/UI is denied. */
19
44
  adminAccess?: boolean;
20
- group?: {
21
- name?: string;
22
- permissions?: Array<{
23
- entity: string;
24
- canCreate: boolean;
25
- canRead: boolean;
26
- canUpdate: boolean;
27
- canDelete: boolean;
28
- }>;
29
- };
45
+ /** Vendor stores this user can access (from vendor_users). */
30
46
  vendorIds?: number[];
47
+ /** Active vendor for scoped CRUD (vendor staff). */
31
48
  activeVendorId?: number | null;
49
+ /** Role for the active vendor link (`vendor_users.role`). */
32
50
  vendorRole?: 'owner' | 'staff' | null;
51
+ /** Active vendor-scoped role id (`vendor_users.vendorRoleId`). */
52
+ vendorRoleId?: number | null;
53
+ vendorRoleName?: string | null;
54
+ /** True when active vendor role has `isOwnerRole`. */
55
+ isVendorRoleOwner?: boolean;
56
+ /** Permissions from active vendor role (`vendor_role_permissions`). */
57
+ vendorEntityPerms?: Record<string, EntityPermissionFlags>;
58
+ /** Set at login: vendor store portal (not platform admin). */
59
+ isVendorPortal?: boolean;
60
+ /** Set at login: vendor store owner (team + permissions). */
61
+ isVendorOwner?: boolean;
33
62
  }
34
- interface AuthorizeOtpInput {
35
- identifier: string;
36
- channel: 'email' | 'sms';
37
- code: string;
38
- }
39
- interface NextAuthOptionsConfig {
40
- /** Resolve user by email (e.g. from TypeORM). Return null if not found. */
41
- getUserByEmail: (email: string) => Promise<NextAuthUser | null>;
42
- comparePassword: (plain: string, hash: string) => Promise<boolean>;
43
- signInPage?: string;
44
- secret?: string;
45
- extend?: (options: NextAuthOptions) => NextAuthOptions;
46
- /** When false, password CredentialsProvider is omitted. Default true. */
47
- enablePasswordLogin?: boolean;
48
- /** When true, registers CredentialsProvider id `otp`. Requires authorizeOtp. Default false. */
49
- enableOtpLogin?: boolean;
50
- /** Validate OTP and return user (same shape as password flow) or null. */
51
- authorizeOtp?: (input: AuthorizeOtpInput) => Promise<NextAuthUser | null>;
63
+ declare function sessionHasEntityAccess(user: SessionUser | null | undefined, entity: string, action: EntityCrudAction): boolean;
64
+ declare function canManageRoles(user: SessionUser | null | undefined): boolean;
65
+ type GetSession = () => Promise<{
66
+ user?: SessionUser;
67
+ } | null>;
68
+ declare const OPEN_ENDPOINTS: Array<Record<string, string[]>>;
69
+ declare const PERMISSION_REQUIRED_ENDPOINTS: Record<string, string[]>;
70
+ declare function isOpenEndpoint(pathname: string): boolean;
71
+ declare function getRequiredPermission(pathname: string): string[] | null;
72
+ declare function isPublicMethod(pathname: string, method: string): boolean;
73
+ interface AuthHelpers {
74
+ requireAuth(req: Request): Promise<Response | null>;
75
+ requirePermission(req: Request, permission: string): Promise<Response | null>;
76
+ requireEntityPermission(req: Request, entity: string, action: EntityCrudAction): Promise<Response | null>;
77
+ requireAdminAccess(req: Request): Promise<Response | null>;
78
+ getAuthenticatedUser(): Promise<SessionUser | null>;
52
79
  }
53
- declare function getNextAuthOptions(config: NextAuthOptionsConfig): NextAuthOptions;
80
+ declare function createAuthHelpers(getSession: GetSession, NextResponse: {
81
+ json: (body: unknown, init?: {
82
+ status?: number;
83
+ }) => Response;
84
+ }): AuthHelpers;
85
+ /** Pass return value into `createCmsApiHandler` (includes `getSessionUser` for vendor store APIs). */
86
+ declare function createCmsAuthBundle(getSession: GetSession, NextResponse: {
87
+ json: (body: unknown, init?: {
88
+ status?: number;
89
+ }) => Response;
90
+ }): {
91
+ requireAuth: (req: Request) => Promise<Response | null>;
92
+ requireAdminAccess: (req: Request) => Promise<Response | null>;
93
+ requireEntityPermission: (req: Request, entity: string, action: EntityCrudAction) => Promise<Response | null>;
94
+ getSessionUser: () => Promise<SessionUser | null>;
95
+ getAuthenticatedUser: () => Promise<SessionUser | null>;
96
+ };
54
97
 
55
98
  /** Minimal DB handle for RBAC debug (avoids importing `typeorm` in the auth bundle). */
56
99
  type RbacDebugDataSource = {
@@ -74,6 +117,56 @@ interface EntityAccessExplanation {
74
117
  declare function explainSessionEntityAccess(user: SessionUser | null | undefined, entity: string, action: EntityCrudAction): EntityAccessExplanation;
75
118
  declare function logEntityAccessDecision(dataSource: RbacDebugDataSource | undefined, context: string, user: SessionUser | null | undefined, entity: string, action: EntityCrudAction, extra?: Record<string, unknown>): Promise<void>;
76
119
 
120
+ /** Platform super admin (`user_groups.id = 1` or Administrator group). */
121
+ declare const SUPER_ADMIN_GROUP_ID = 1;
122
+ /** Vendor store admin (`user_groups.id = 5` or vendor-linked portal users). */
123
+ declare const VENDOR_ADMIN_GROUP_ID = 5;
124
+ declare function isSuperAdmin(user: SessionUser | null | undefined): boolean;
125
+ declare function isVendorAdmin(user: SessionUser | null | undefined): boolean;
126
+
127
+ /** Entities with a `vendorId` column (store data). */
128
+ declare const VENDOR_SCOPED_STORE_ENTITIES: Set<string>;
129
+ /**
130
+ * Store admin RBAC for vendor portal users (read/create/update/delete fallbacks in rbac-debug).
131
+ * Includes entities without `vendorId` that are still part of the store admin UI.
132
+ */
133
+ declare const VENDOR_STORE_RBAC_ENTITIES: Set<string>;
134
+ type VendorScope = {
135
+ type: 'all';
136
+ } | {
137
+ type: 'vendor';
138
+ vendorId: number;
139
+ vendorIds: number[];
140
+ } | {
141
+ type: 'deny';
142
+ };
143
+ declare const VENDOR_OWNER_GROUP_NAME = "Vendor Owner";
144
+ /** User groups treated as vendor store staff (sidebar + scoped admin). */
145
+ declare function isVendorGroupName(name: string | null | undefined): boolean;
146
+ declare function isPlatformAdministrator(user: SessionUser | null | undefined): boolean;
147
+ /** Vendor portal UI (store + store admin), not platform admin. */
148
+ declare function isVendorPortalUser(user: SessionUser | null | undefined): boolean;
149
+ declare function isVendorStaff(user: SessionUser | null | undefined): boolean;
150
+ /** Vendor store owner (manages team + role permissions for their store). */
151
+ declare function isVendorOwner(user: SessionUser | null | undefined): boolean;
152
+ declare function canManageVendorTeam(user: SessionUser | null | undefined): boolean;
153
+ declare function canManageVendorRoles(user: SessionUser | null | undefined): boolean;
154
+ /** Platform admins (Administrator group) can onboard vendors. */
155
+ declare function canOnboardVendors(user: SessionUser | null | undefined): boolean;
156
+ declare function resolveVendorScopeFromSessionUser(user: SessionUser | null | undefined): VendorScope;
157
+ /** Compute portal flags at login (persist on JWT). */
158
+ declare function vendorPortalFlagsFromUser(input: {
159
+ email: string;
160
+ isRBACAdmin: boolean;
161
+ groupName?: string | null;
162
+ vendorIds?: number[];
163
+ vendorRole?: 'owner' | 'staff' | null;
164
+ isVendorRoleOwner?: boolean;
165
+ }): {
166
+ isVendorPortal: boolean;
167
+ isVendorOwner: boolean;
168
+ };
169
+
77
170
  /**
78
171
  * Ensures the Administrator group has full CRUD on every permissionable entity
79
172
  * for the given entity map. Idempotent: upserts per entity.
@@ -138,4 +231,70 @@ declare function logAuthClient(message: string, data?: Record<string, unknown>):
138
231
  declare function summarizeSessionUserForLog(user: unknown): Record<string, unknown>;
139
232
  declare function nextAuthCookieDebugInfo(): Record<string, unknown>;
140
233
 
141
- export { type AuthorizeOtpInput, type CmsMiddlewareConfig, type CmsMiddlewareRequest, EntityCrudAction, EntityPermissionFlags, type NextAuthOptionsConfig, type NextAuthUser, SessionUser, createCmsMiddleware, defaultPublicApiMethods, explainSessionEntityAccess, getNextAuthOptions, isAuthDebugClientEnabled, isAuthDebugEnabled, isRbacDebugEnabled, logAuth, logAuthClient, logEntityAccessDecision, logRbac, nextAuthCookieDebugInfo, seedAdministratorPermissions, summarizeEntityPerms, summarizeSessionUserForLog };
234
+ /**
235
+ * Build NextAuth options for credentials auth. App can extend/override via extend().
236
+ */
237
+
238
+ interface NextAuthUser {
239
+ id: number;
240
+ email: string;
241
+ name: string | null;
242
+ password: string | null;
243
+ blocked?: boolean;
244
+ deleted?: boolean;
245
+ groupId?: number | null;
246
+ adminAccess?: boolean;
247
+ group?: {
248
+ name?: string;
249
+ permissions?: Array<{
250
+ entity: string;
251
+ canCreate: boolean;
252
+ canRead: boolean;
253
+ canUpdate: boolean;
254
+ canDelete: boolean;
255
+ }>;
256
+ };
257
+ vendorIds?: number[];
258
+ activeVendorId?: number | null;
259
+ vendorRole?: 'owner' | 'staff' | null;
260
+ vendorRoleId?: number | null;
261
+ vendorRoleName?: string | null;
262
+ isVendorRoleOwner?: boolean;
263
+ vendorEntityPerms?: Record<string, {
264
+ c: boolean;
265
+ r: boolean;
266
+ u: boolean;
267
+ d: boolean;
268
+ }>;
269
+ }
270
+ interface AuthorizeOtpInput {
271
+ identifier: string;
272
+ channel: 'email' | 'sms';
273
+ code: string;
274
+ }
275
+ interface NextAuthOptionsConfig {
276
+ /** Resolve user by email (e.g. from TypeORM). Return null if not found. */
277
+ getUserByEmail: (email: string) => Promise<NextAuthUser | null>;
278
+ comparePassword: (plain: string, hash: string) => Promise<boolean>;
279
+ signInPage?: string;
280
+ secret?: string;
281
+ extend?: (options: NextAuthOptions) => NextAuthOptions;
282
+ /** When false, password CredentialsProvider is omitted. Default true. */
283
+ enablePasswordLogin?: boolean;
284
+ /** When true, registers CredentialsProvider id `otp`. Requires authorizeOtp. Default false. */
285
+ enableOtpLogin?: boolean;
286
+ /** Validate OTP and return user (same shape as password flow) or null. */
287
+ authorizeOtp?: (input: AuthorizeOtpInput) => Promise<NextAuthUser | null>;
288
+ /**
289
+ * Customer group sign-in policy for credentials/OTP on a shared `/api/auth` route:
290
+ * - `true` — always allow (dedicated storefront auth)
291
+ * - `false` — always block
292
+ * - omitted — auto: allow unless `callbackUrl` targets `/admin` (storefront `/signin` works unchanged)
293
+ */
294
+ allowCustomerLogin?: boolean;
295
+ }
296
+ declare function getNextAuthOptions(config: NextAuthOptionsConfig): NextAuthOptions;
297
+ /** Storefront sign-in: allows Customer group; use with signInPage `/signin`. */
298
+ declare function getStorefrontNextAuthOptions(config: Omit<NextAuthOptionsConfig, 'allowCustomerLogin'>): NextAuthOptions;
299
+
300
+ export { ADMIN_GROUP_NAME, type AuthHelpers, type AuthorizeOtpInput, type CmsMiddlewareConfig, type CmsMiddlewareRequest, type EntityCrudAction, type EntityPermissionFlags, type GetSession, type NextAuthOptionsConfig, type NextAuthUser, OPEN_ENDPOINTS, PERMISSION_REQUIRED_ENDPOINTS, RBAC_ADMIN_ONLY_ENTITIES, SUPER_ADMIN_GROUP_ID, type SessionUser, VENDOR_ADMIN_GROUP_ID, VENDOR_OWNER_GROUP_NAME, VENDOR_SCOPED_STORE_ENTITIES, VENDOR_STORE_RBAC_ENTITIES, canManageRoles, canManageVendorRoles, canManageVendorTeam, canOnboardVendors, createAuthHelpers, createCmsAuthBundle, createCmsMiddleware, defaultPublicApiMethods, explainSessionEntityAccess, getNextAuthOptions, getPermissionableEntityKeys, getRequiredPermission, getStorefrontNextAuthOptions, hasEntityPermission, isAuthDebugClientEnabled, isAuthDebugEnabled, isOpenEndpoint, isPlatformAdministrator, isPublicMethod, isRbacDebugEnabled, isSuperAdmin, isSuperAdminGroupName, isVendorAdmin, isVendorGroupName, isVendorOwner, isVendorPortalUser, isVendorStaff, logAuth, logAuthClient, logEntityAccessDecision, logRbac, nextAuthCookieDebugInfo, permissionRowsToRecord, resolveVendorScopeFromSessionUser, seedAdministratorPermissions, sessionHasEntityAccess, summarizeEntityPerms, summarizeSessionUserForLog, vendorPortalFlagsFromUser };