@infuro/cms-core 1.0.34 → 1.0.36

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 (152) 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 +35254 -21613
  5. package/dist/admin.d.cts +192 -9
  6. package/dist/admin.d.ts +192 -9
  7. package/dist/admin.js +34301 -20755
  8. package/dist/api.cjs +137 -17531
  9. package/dist/api.d.cts +633 -3
  10. package/dist/api.d.ts +633 -3
  11. package/dist/api.js +15 -17528
  12. package/dist/auth.cjs +192 -1034
  13. package/dist/auth.d.cts +197 -54
  14. package/dist/auth.d.ts +197 -54
  15. package/dist/auth.js +4 -966
  16. package/dist/chunk-2AEVFOQP.cjs +30436 -0
  17. package/dist/chunk-3DZRIZOD.cjs +52 -0
  18. package/dist/chunk-5ELSW2UP.js +150 -0
  19. package/dist/chunk-7NMT3GBR.cjs +29 -0
  20. package/dist/chunk-COBORIJH.cjs +2373 -0
  21. package/dist/chunk-CRFV5WJK.js +16 -0
  22. package/dist/chunk-D5FBNKQM.cjs +104 -0
  23. package/dist/chunk-FG6I64HP.js +604 -0
  24. package/dist/chunk-GO7PPYNU.js +76 -0
  25. package/dist/chunk-HCIRL37O.js +21 -0
  26. package/dist/chunk-HF3L2GIT.cjs +194 -0
  27. package/dist/chunk-HT5DI3XW.cjs +82 -0
  28. package/dist/chunk-JC6DLWTE.js +21 -0
  29. package/dist/chunk-JS2W7XZ4.js +30312 -0
  30. package/dist/chunk-JXF23MPG.js +25 -0
  31. package/dist/chunk-KFFB6EMZ.js +123 -0
  32. package/dist/chunk-KPKFNLQQ.cjs +648 -0
  33. package/dist/chunk-LI2IXVAY.js +171 -0
  34. package/dist/chunk-MQBT33IV.js +48 -0
  35. package/dist/chunk-OOTLNH63.cjs +18 -0
  36. package/dist/chunk-PNOKNSG2.cjs +222 -0
  37. package/dist/chunk-SHUYVCID.js +4 -0
  38. package/dist/chunk-SPQFNIYJ.cjs +132 -0
  39. package/dist/chunk-SYBOCAWB.js +97 -0
  40. package/dist/chunk-TDV6EJHV.js +192 -0
  41. package/dist/chunk-UCKN4BBY.cjs +24 -0
  42. package/dist/chunk-UF3BYUXY.js +616 -0
  43. package/dist/chunk-UPLVMVRX.cjs +23 -0
  44. package/dist/chunk-USNT2KNT.cjs +6 -0
  45. package/dist/chunk-VMY2S32H.js +2342 -0
  46. package/dist/chunk-WEMDMVHQ.js +216 -0
  47. package/dist/chunk-WO2DW4AU.cjs +182 -0
  48. package/dist/chunk-X47PBV4I.js +79 -0
  49. package/dist/chunk-X6H5VBQ2.cjs +620 -0
  50. package/dist/chunk-XQ3QUHWR.cjs +83 -0
  51. package/dist/chunk-XW5ATPRW.cjs +155 -0
  52. package/dist/cli.cjs +107 -86
  53. package/dist/cli.js +66 -29
  54. package/dist/email-queue-CGZBVVAS.js +2 -0
  55. package/dist/email-queue-TPZWLTIV.cjs +23 -0
  56. package/dist/emit-order-notification-trigger-D2N3KFHL.cjs +16 -0
  57. package/dist/emit-order-notification-trigger-IVLWKKJL.js +3 -0
  58. package/dist/erp-config-enabled-CUMQ6N2V.cjs +11 -0
  59. package/dist/erp-config-enabled-T37X7T34.js +2 -0
  60. package/dist/erp-order-invoice-3YISSOWW.js +3 -0
  61. package/dist/erp-order-invoice-ZR5F2KTA.cjs +12 -0
  62. package/dist/event-order-defaults-EMWBIGL3.cjs +39 -0
  63. package/dist/event-order-defaults-SDRNAZHC.js +2 -0
  64. package/dist/hooks.cjs +259 -132
  65. package/dist/hooks.d.cts +42 -1
  66. package/dist/hooks.d.ts +42 -1
  67. package/dist/hooks.js +234 -91
  68. package/dist/index.cjs +3679 -22356
  69. package/dist/index.d.cts +2173 -643
  70. package/dist/index.d.ts +2173 -643
  71. package/dist/index.js +2587 -22119
  72. package/dist/interpolate-WAKPN56R.cjs +11 -0
  73. package/dist/interpolate-WDUWDF3I.js +2 -0
  74. package/dist/migrations/1779400000000-ConvertStatusToEnum.ts +142 -0
  75. package/dist/migrations/1779400000000-SeedDefaultCurrencies.ts +33 -0
  76. package/dist/migrations/1779500000000-VendorRolesAndPermissions.ts +102 -0
  77. package/dist/migrations/1779600000000-VendorRegistrationProfile.ts +52 -0
  78. package/dist/migrations/1779700000000-CollectionIsCatalog.ts +22 -0
  79. package/dist/migrations/1779710000000-CollectionPlatformCatalog.ts +60 -0
  80. package/dist/migrations/1779720000000-ProductCategoryPlatformCatalog.ts +157 -0
  81. package/dist/migrations/1779800000000-EventsAndEventProducts.ts +173 -0
  82. package/dist/migrations/1779810000000-BackfillVendorRoleEventsPermissions.ts +38 -0
  83. package/dist/migrations/1779820000000-FixProductsCategoryForeignKey.ts +70 -0
  84. package/dist/migrations/1779830000000-ProductTitleColumn.ts +32 -0
  85. package/dist/migrations/1779840000000-EventAboutAndVisibilityFields.ts +34 -0
  86. package/dist/migrations/1779850000000-EventCityCountrySplit.ts +43 -0
  87. package/dist/migrations/1779860000000-CreateCombos.ts +140 -0
  88. package/dist/migrations/1780100000000-OrderAttendeesEventId.ts +55 -0
  89. package/dist/migrations/1780110000000-EventContactFormId.ts +49 -0
  90. package/dist/migrations/1780130000000-ProductVariants.ts +54 -0
  91. package/dist/migrations/1780140000000-EventManagementEnhancements.ts +44 -0
  92. package/dist/migrations/1780160000000-EventRegistrationGstProductContactForm.ts +79 -0
  93. package/dist/migrations/1780170000000-ComboCurrencyPrices.ts +20 -0
  94. package/dist/migrations/1781110000000-VendorOwnerCombosPermission.ts +38 -0
  95. package/dist/migrations/1781120000000-RefundPoliciesAndRequests.ts +225 -0
  96. package/dist/migrations/1781130000000-CreateAttendees.ts +44 -0
  97. package/dist/migrations/1781140000000-EventOrderNotifications.ts +29 -0
  98. package/dist/migrations/1781150000000-EventNamedLists.ts +28 -0
  99. package/dist/migrations/1781160000000-RefundPolicyEventTiers.ts +27 -0
  100. package/dist/migrations/1781170000000-EventRefundPolicy.ts +42 -0
  101. package/dist/migrations/1781180000000-RemoveCartItemsUniqueConstraint.ts +15 -0
  102. package/dist/migrations/1781190000000-RenameProductTaxesToProductConfig.ts +84 -0
  103. package/dist/migrations/1781200000000-VendorOwnerProductConfigPermissions.ts +51 -0
  104. package/dist/migrations/1781210000000-VendorRoleProductConfigPermissions.ts +46 -0
  105. package/dist/migrations/1781220000000-AddWhatsappTriggerBindings.ts +23 -0
  106. package/dist/migrations/1781230000000-AddOrderNotificationTriggers.ts +46 -0
  107. package/dist/migrations/1781240000000-DropEventOrderNotificationColumns.ts +29 -0
  108. package/dist/migrations/1781250000000-RemoveOrderRefundedTrigger.ts +36 -0
  109. package/dist/migrations/helpers/vendor-role-seed.ts +243 -0
  110. package/dist/paid-order-erp-3USEG6WL.js +3 -0
  111. package/dist/paid-order-erp-FSQ3GSXE.cjs +12 -0
  112. package/dist/pg-boss-service-4XF2TQ2E.js +2 -0
  113. package/dist/pg-boss-service-L6MTF4EQ.cjs +15 -0
  114. package/dist/razorpay-KLO2KNCB.js +49 -0
  115. package/dist/razorpay-U23LGY72.cjs +56 -0
  116. package/dist/rbac-debug-db-HWP65A4O.cjs +35 -0
  117. package/dist/rbac-debug-db-QJH3AD34.js +33 -0
  118. package/dist/sms-defaults-2NL24H57.js +2 -0
  119. package/dist/sms-defaults-KCOPKQBA.cjs +19 -0
  120. package/dist/stripe-4FD27QVJ.js +51 -0
  121. package/dist/stripe-VU6OEG2D.cjs +57 -0
  122. package/dist/theme.cjs +31 -59
  123. package/dist/theme.d.cts +78 -3
  124. package/dist/theme.d.ts +78 -3
  125. package/dist/theme.js +23 -20
  126. package/dist/vendor-invite-status-77O7ZQ3U.cjs +19 -0
  127. package/dist/vendor-invite-status-PWJ3DE76.js +2 -0
  128. package/dist/whatsapp-trigger-dispatcher-ONHXI7UY.cjs +19 -0
  129. package/dist/whatsapp-trigger-dispatcher-PWFI4FKP.js +6 -0
  130. package/package.json +147 -142
  131. package/dist/admin.cjs.map +0 -1
  132. package/dist/admin.js.map +0 -1
  133. package/dist/api.cjs.map +0 -1
  134. package/dist/api.js.map +0 -1
  135. package/dist/auth.cjs.map +0 -1
  136. package/dist/auth.js.map +0 -1
  137. package/dist/cli.cjs.map +0 -1
  138. package/dist/cli.js.map +0 -1
  139. package/dist/config-DJ5CmQvS.d.cts +0 -8
  140. package/dist/config-DJ5CmQvS.d.ts +0 -8
  141. package/dist/hooks.cjs.map +0 -1
  142. package/dist/hooks.js.map +0 -1
  143. package/dist/index-Bf5GO8fu.d.cts +0 -583
  144. package/dist/index-DOiJuMQA.d.ts +0 -583
  145. package/dist/index.cjs.map +0 -1
  146. package/dist/index.js.map +0 -1
  147. package/dist/theme.cjs.map +0 -1
  148. package/dist/theme.js.map +0 -1
  149. package/dist/types-DCVaXlPV.d.cts +0 -78
  150. package/dist/types-DCVaXlPV.d.ts +0 -78
  151. package/dist/vendor-scope-DTYhJk_I.d.cts +0 -129
  152. package/dist/vendor-scope-DTYhJk_I.d.ts +0 -129
@@ -0,0 +1,648 @@
1
+ 'use strict';
2
+
3
+ var chunkUSNT2KNT_cjs = require('./chunk-USNT2KNT.cjs');
4
+
5
+ // src/auth/permission-entities.ts
6
+ var PERMISSION_ENTITY_INTERNAL_EXCLUDE = /* @__PURE__ */ new Set([
7
+ "users",
8
+ "password_reset_tokens",
9
+ "user_groups",
10
+ "permissions",
11
+ "comments",
12
+ "form_fields",
13
+ "configs",
14
+ "knowledge_base_chunks",
15
+ "carts",
16
+ "cart_items",
17
+ "wishlists",
18
+ "wishlist_items",
19
+ "message_templates",
20
+ "order_notification_triggers",
21
+ "whatsapp_trigger_bindings",
22
+ "vendor_users",
23
+ "vendor_roles",
24
+ "vendor_role_permissions"
25
+ ]);
26
+ var PERMISSION_LOGICAL_ENTITIES = [
27
+ "users",
28
+ "forms",
29
+ "form_submissions",
30
+ "dashboard",
31
+ "upload",
32
+ "settings",
33
+ "analytics",
34
+ "chat"
35
+ ];
36
+ var ADMIN_GROUP_NAME = "Administrator";
37
+ function isSuperAdminGroupName(name) {
38
+ return name === ADMIN_GROUP_NAME;
39
+ }
40
+ chunkUSNT2KNT_cjs.__name(isSuperAdminGroupName, "isSuperAdminGroupName");
41
+ function getPermissionableEntityKeys(entityMap) {
42
+ const fromMap = Object.keys(entityMap).filter((k) => !PERMISSION_ENTITY_INTERNAL_EXCLUDE.has(k));
43
+ const logical = PERMISSION_LOGICAL_ENTITIES.filter((k) => !fromMap.includes(k));
44
+ return [
45
+ ...fromMap.sort(),
46
+ ...logical
47
+ ].filter((k, i, a) => a.indexOf(k) === i);
48
+ }
49
+ chunkUSNT2KNT_cjs.__name(getPermissionableEntityKeys, "getPermissionableEntityKeys");
50
+ function permissionRowsToRecord(rows) {
51
+ const out = {};
52
+ if (!rows?.length) return out;
53
+ for (const p of rows) {
54
+ out[p.entity] = {
55
+ c: !!p.canCreate,
56
+ r: !!p.canRead,
57
+ u: !!p.canUpdate,
58
+ d: !!p.canDelete
59
+ };
60
+ }
61
+ return out;
62
+ }
63
+ chunkUSNT2KNT_cjs.__name(permissionRowsToRecord, "permissionRowsToRecord");
64
+ function hasEntityPermission(record, entity, action) {
65
+ const p = record?.[entity];
66
+ if (!p) return false;
67
+ if (action === "create") return p.c;
68
+ if (action === "read") return p.r;
69
+ if (action === "update") return p.u;
70
+ return p.d;
71
+ }
72
+ chunkUSNT2KNT_cjs.__name(hasEntityPermission, "hasEntityPermission");
73
+
74
+ // src/auth/role-helpers.ts
75
+ var SUPER_ADMIN_GROUP_ID = 1;
76
+ var VENDOR_ADMIN_GROUP_ID = 5;
77
+ function isSuperAdmin(user) {
78
+ if (!user) return false;
79
+ if (user.groupId === SUPER_ADMIN_GROUP_ID) return true;
80
+ if (user.isRBACAdmin === true) return true;
81
+ return isSuperAdminGroupName(user.groupName);
82
+ }
83
+ chunkUSNT2KNT_cjs.__name(isSuperAdmin, "isSuperAdmin");
84
+ function isVendorAdmin(user) {
85
+ if (!user?.email || isSuperAdmin(user)) return false;
86
+ if (user.groupId === VENDOR_ADMIN_GROUP_ID) return true;
87
+ if ((user.vendorIds?.length ?? 0) > 0) return true;
88
+ return isVendorGroupName(user.groupName);
89
+ }
90
+ chunkUSNT2KNT_cjs.__name(isVendorAdmin, "isVendorAdmin");
91
+
92
+ // src/auth/vendor-scope.ts
93
+ var DEFAULT_VENDOR_SLUG = "default";
94
+ async function resolveDefaultVendorId(dataSource) {
95
+ try {
96
+ const rows = await dataSource.query(`SELECT id FROM vendors WHERE slug = $1 AND deleted = false LIMIT 1`, [
97
+ DEFAULT_VENDOR_SLUG
98
+ ]);
99
+ const id = rows[0]?.id;
100
+ return typeof id === "number" ? id : null;
101
+ } catch {
102
+ return null;
103
+ }
104
+ }
105
+ chunkUSNT2KNT_cjs.__name(resolveDefaultVendorId, "resolveDefaultVendorId");
106
+ async function resolveDisabledMultiVendorScope(dataSource) {
107
+ const defaultVendorId = await resolveDefaultVendorId(dataSource);
108
+ if (defaultVendorId == null) return {
109
+ type: "deny"
110
+ };
111
+ return {
112
+ type: "vendor",
113
+ vendorId: defaultVendorId,
114
+ vendorIds: [
115
+ defaultVendorId
116
+ ]
117
+ };
118
+ }
119
+ chunkUSNT2KNT_cjs.__name(resolveDisabledMultiVendorScope, "resolveDisabledMultiVendorScope");
120
+ var VENDOR_SCOPED_STORE_ENTITIES = /* @__PURE__ */ new Set([
121
+ "products",
122
+ "collections",
123
+ "brands",
124
+ "product_categories",
125
+ "orders",
126
+ "payments",
127
+ "taxes",
128
+ "attributes",
129
+ "vendor_customers",
130
+ "discounts",
131
+ "events",
132
+ "refund_policies"
133
+ ]);
134
+ var VENDOR_STORE_RBAC_ENTITIES = /* @__PURE__ */ new Set([
135
+ ...VENDOR_SCOPED_STORE_ENTITIES,
136
+ "order_discounts",
137
+ "order_addresses",
138
+ "event_products"
139
+ ]);
140
+ var VENDOR_OWNER_GROUP_NAME = "Vendor Owner";
141
+ function isVendorGroupName(name) {
142
+ if (!name?.trim()) return false;
143
+ const n = name.trim().toLowerCase();
144
+ return n === VENDOR_OWNER_GROUP_NAME.toLowerCase() || n.includes("vendor");
145
+ }
146
+ chunkUSNT2KNT_cjs.__name(isVendorGroupName, "isVendorGroupName");
147
+ function isPlatformAdministrator(user) {
148
+ if (!user?.email) return false;
149
+ return isSuperAdmin(user);
150
+ }
151
+ chunkUSNT2KNT_cjs.__name(isPlatformAdministrator, "isPlatformAdministrator");
152
+ function isVendorPortalUser(user) {
153
+ if (user?.isVendorPortal === true) return true;
154
+ if (!user?.email || isPlatformAdministrator(user)) return false;
155
+ if (isVendorAdmin(user)) return true;
156
+ return isVendorGroupName(user.groupName);
157
+ }
158
+ chunkUSNT2KNT_cjs.__name(isVendorPortalUser, "isVendorPortalUser");
159
+ function isVendorStaff(user) {
160
+ return isVendorPortalUser(user);
161
+ }
162
+ chunkUSNT2KNT_cjs.__name(isVendorStaff, "isVendorStaff");
163
+ function isVendorOwner(user) {
164
+ if (user?.isVendorOwner === true) return true;
165
+ if (!user?.email || isPlatformAdministrator(user)) return false;
166
+ if (user.isVendorRoleOwner === true) return true;
167
+ if (user.vendorRole === "staff") return false;
168
+ if (user.vendorRole === "owner") return true;
169
+ if (!isVendorPortalUser(user)) return false;
170
+ return user.groupName?.trim().toLowerCase() === VENDOR_OWNER_GROUP_NAME.toLowerCase();
171
+ }
172
+ chunkUSNT2KNT_cjs.__name(isVendorOwner, "isVendorOwner");
173
+ function canManageVendorTeam(user) {
174
+ return isPlatformAdministrator(user) || isVendorOwner(user);
175
+ }
176
+ chunkUSNT2KNT_cjs.__name(canManageVendorTeam, "canManageVendorTeam");
177
+ function canManageVendorRoles(user) {
178
+ return isPlatformAdministrator(user) || isVendorOwner(user);
179
+ }
180
+ chunkUSNT2KNT_cjs.__name(canManageVendorRoles, "canManageVendorRoles");
181
+ function canOnboardVendors(user) {
182
+ return isPlatformAdministrator(user);
183
+ }
184
+ chunkUSNT2KNT_cjs.__name(canOnboardVendors, "canOnboardVendors");
185
+ function resolveVendorScopeFromSessionUser(user) {
186
+ if (!user?.email) return {
187
+ type: "deny"
188
+ };
189
+ if (isPlatformAdministrator(user)) return {
190
+ type: "all"
191
+ };
192
+ const vendorIds = user.vendorIds ?? [];
193
+ if (vendorIds.length === 0) return {
194
+ type: "deny"
195
+ };
196
+ const preferred = user.activeVendorId ?? vendorIds[0];
197
+ const vendorId = vendorIds.includes(preferred) ? preferred : vendorIds[0];
198
+ return {
199
+ type: "vendor",
200
+ vendorId,
201
+ vendorIds
202
+ };
203
+ }
204
+ chunkUSNT2KNT_cjs.__name(resolveVendorScopeFromSessionUser, "resolveVendorScopeFromSessionUser");
205
+ function vendorPortalFlagsFromUser(input) {
206
+ const vendorIds = input.vendorIds ?? [];
207
+ const isVendorPortal = !input.isRBACAdmin && (vendorIds.length > 0 || isVendorGroupName(input.groupName));
208
+ const isVendorOwner2 = isVendorPortal && (input.isVendorRoleOwner === true || input.vendorRole !== "staff" && (input.vendorRole === "owner" || input.groupName?.trim().toLowerCase() === VENDOR_OWNER_GROUP_NAME.toLowerCase()));
209
+ return {
210
+ isVendorPortal,
211
+ isVendorOwner: isVendorOwner2
212
+ };
213
+ }
214
+ chunkUSNT2KNT_cjs.__name(vendorPortalFlagsFromUser, "vendorPortalFlagsFromUser");
215
+
216
+ // src/lib/vendor-role-defaults.ts
217
+ var VENDOR_RBAC_ENTITIES = [
218
+ ...VENDOR_STORE_RBAC_ENTITIES,
219
+ "dashboard",
220
+ "settings",
221
+ "team",
222
+ "roles"
223
+ ];
224
+ var STORE_ENTITIES = [
225
+ ...VENDOR_STORE_RBAC_ENTITIES
226
+ ];
227
+ function full() {
228
+ return {
229
+ canCreate: true,
230
+ canRead: true,
231
+ canUpdate: true,
232
+ canDelete: true
233
+ };
234
+ }
235
+ chunkUSNT2KNT_cjs.__name(full, "full");
236
+ function read() {
237
+ return {
238
+ canCreate: false,
239
+ canRead: true,
240
+ canUpdate: false,
241
+ canDelete: false
242
+ };
243
+ }
244
+ chunkUSNT2KNT_cjs.__name(read, "read");
245
+ function none() {
246
+ return {
247
+ canCreate: false,
248
+ canRead: false,
249
+ canUpdate: false,
250
+ canDelete: false
251
+ };
252
+ }
253
+ chunkUSNT2KNT_cjs.__name(none, "none");
254
+ function readUpdate() {
255
+ return {
256
+ canCreate: false,
257
+ canRead: true,
258
+ canUpdate: true,
259
+ canDelete: false
260
+ };
261
+ }
262
+ chunkUSNT2KNT_cjs.__name(readUpdate, "readUpdate");
263
+ function storePerms(spec) {
264
+ const resolve = /* @__PURE__ */ chunkUSNT2KNT_cjs.__name((v) => {
265
+ if (v === "full") return full();
266
+ if (v === "read") return read();
267
+ if (v === "none") return none();
268
+ return v;
269
+ }, "resolve");
270
+ const out = {};
271
+ for (const entity of STORE_ENTITIES) {
272
+ out[entity] = resolve(spec[entity] ?? "none");
273
+ }
274
+ return out;
275
+ }
276
+ chunkUSNT2KNT_cjs.__name(storePerms, "storePerms");
277
+ var DEFAULT_VENDOR_ROLE_DEFS = [
278
+ {
279
+ name: "Owner",
280
+ description: "Full store access and team/role management",
281
+ isSystem: true,
282
+ isOwnerRole: true,
283
+ permissions: {
284
+ ...storePerms(Object.fromEntries(STORE_ENTITIES.map((e) => [
285
+ e,
286
+ "full"
287
+ ]))),
288
+ dashboard: read(),
289
+ settings: readUpdate(),
290
+ team: full(),
291
+ roles: full()
292
+ }
293
+ },
294
+ {
295
+ name: "Manager",
296
+ description: "Day-to-day store operations",
297
+ isSystem: true,
298
+ isOwnerRole: false,
299
+ permissions: {
300
+ ...storePerms({
301
+ products: "full",
302
+ collections: "full",
303
+ brands: "full",
304
+ product_categories: "full",
305
+ orders: "full",
306
+ vendor_customers: "full",
307
+ discounts: "full",
308
+ order_discounts: "full",
309
+ order_addresses: "full",
310
+ payments: "read",
311
+ taxes: "read",
312
+ attributes: "read"
313
+ }),
314
+ dashboard: read(),
315
+ settings: read(),
316
+ team: none(),
317
+ roles: none()
318
+ }
319
+ },
320
+ {
321
+ name: "Catalog Staff",
322
+ description: "Manage products and catalog content",
323
+ isSystem: true,
324
+ isOwnerRole: false,
325
+ permissions: {
326
+ ...storePerms({
327
+ products: "full",
328
+ collections: "full",
329
+ brands: "full",
330
+ product_categories: "full",
331
+ attributes: "full",
332
+ orders: "read",
333
+ vendor_customers: "read"
334
+ }),
335
+ dashboard: read(),
336
+ settings: none(),
337
+ team: none(),
338
+ roles: none()
339
+ }
340
+ },
341
+ {
342
+ name: "Fulfillment",
343
+ description: "Orders and fulfillment",
344
+ isSystem: true,
345
+ isOwnerRole: false,
346
+ permissions: {
347
+ ...storePerms({
348
+ products: "read",
349
+ orders: "full",
350
+ order_addresses: "full",
351
+ order_discounts: "read",
352
+ vendor_customers: "read"
353
+ }),
354
+ dashboard: read(),
355
+ settings: none(),
356
+ team: none(),
357
+ roles: none()
358
+ }
359
+ },
360
+ {
361
+ name: "Viewer",
362
+ description: "Read-only access to store data",
363
+ isSystem: true,
364
+ isOwnerRole: false,
365
+ permissions: {
366
+ ...storePerms(Object.fromEntries(STORE_ENTITIES.map((e) => [
367
+ e,
368
+ "read"
369
+ ]))),
370
+ dashboard: read(),
371
+ settings: none(),
372
+ team: none(),
373
+ roles: none()
374
+ }
375
+ }
376
+ ];
377
+ var VENDOR_VIEWER_ROLE_NAME = "Viewer";
378
+
379
+ // src/auth/rbac-debug.ts
380
+ var LOG_PREFIX = "[cms-rbac]";
381
+ function isRbacDebugEnabled() {
382
+ const v = process.env.CMS_RBAC_DEBUG?.trim().toLowerCase();
383
+ return v === "1" || v === "true" || v === "yes";
384
+ }
385
+ chunkUSNT2KNT_cjs.__name(isRbacDebugEnabled, "isRbacDebugEnabled");
386
+ function logRbac(message, data) {
387
+ if (!isRbacDebugEnabled()) return;
388
+ if (data) console.info(LOG_PREFIX, message, data);
389
+ else console.info(LOG_PREFIX, message);
390
+ }
391
+ chunkUSNT2KNT_cjs.__name(logRbac, "logRbac");
392
+ function summarizeEntityPerms(entityPerms) {
393
+ const out = {};
394
+ if (!entityPerms) return out;
395
+ for (const [entity, p] of Object.entries(entityPerms)) {
396
+ out[entity] = {
397
+ c: p.c,
398
+ r: p.r,
399
+ u: p.u,
400
+ d: p.d
401
+ };
402
+ }
403
+ return out;
404
+ }
405
+ chunkUSNT2KNT_cjs.__name(summarizeEntityPerms, "summarizeEntityPerms");
406
+ function vendorPortalFallbackReason(user, entity, action) {
407
+ if (!isVendorPortalUser(user)) return null;
408
+ if (entity === "dashboard" && action === "read") return "vendor_portal_dashboard_fallback";
409
+ if (entity === "analytics" && action === "read") return "vendor_portal_analytics_fallback";
410
+ if (entity === "settings" && action === "read") return "vendor_portal_settings_read_fallback";
411
+ if (VENDOR_STORE_RBAC_ENTITIES.has(entity) && action === "read") return "vendor_portal_store_read_fallback";
412
+ return null;
413
+ }
414
+ chunkUSNT2KNT_cjs.__name(vendorPortalFallbackReason, "vendorPortalFallbackReason");
415
+ function explainSessionEntityAccess(user, entity, action) {
416
+ const userSnapshot = {
417
+ email: user?.email ?? null,
418
+ id: user?.id ?? null,
419
+ groupId: user?.groupId ?? null,
420
+ groupName: user?.groupName ?? null,
421
+ isRBACAdmin: user?.isRBACAdmin ?? false,
422
+ adminAccess: user?.adminAccess ?? null,
423
+ vendorIds: user?.vendorIds ?? [],
424
+ activeVendorId: user?.activeVendorId ?? null,
425
+ vendorRole: user?.vendorRole ?? null,
426
+ vendorRoleId: user?.vendorRoleId ?? null,
427
+ vendorRoleName: user?.vendorRoleName ?? null,
428
+ isVendorRoleOwner: user?.isVendorRoleOwner ?? false,
429
+ vendorEntityPerms: summarizeEntityPerms(user?.vendorEntityPerms),
430
+ isVendorPortal: user?.isVendorPortal ?? false,
431
+ isVendorOwner: user?.isVendorOwner ?? false,
432
+ isVendorPortalComputed: isVendorPortalUser(user),
433
+ isVendorOwnerComputed: isVendorOwner(user),
434
+ jwtEntityPerms: summarizeEntityPerms(user?.entityPerms),
435
+ jwtEntityPermForTarget: user?.entityPerms?.[entity] ?? null
436
+ };
437
+ if (!user?.email) {
438
+ return {
439
+ allowed: false,
440
+ reason: "no_session_email",
441
+ userSnapshot
442
+ };
443
+ }
444
+ if (user.isRBACAdmin) {
445
+ return {
446
+ allowed: true,
447
+ reason: "platform_administrator",
448
+ userSnapshot
449
+ };
450
+ }
451
+ const vendorIds = user.vendorIds ?? [];
452
+ const isStaff = user.vendorRole === "staff";
453
+ const vendorPerms = user.vendorEntityPerms;
454
+ const hasVendorRolePerms = vendorPerms != null && Object.keys(vendorPerms).length > 0;
455
+ if (vendorIds.length > 0 && hasVendorRolePerms) {
456
+ const vendorRbacSet = new Set(VENDOR_RBAC_ENTITIES);
457
+ if (vendorRbacSet.has(entity) || entity === "analytics") {
458
+ if (entity === "analytics" && action === "read") {
459
+ const allowed3 = hasEntityPermission(vendorPerms, "dashboard", "read");
460
+ return {
461
+ allowed: allowed3,
462
+ reason: allowed3 ? "vendor_role_analytics_via_dashboard" : "vendor_role_analytics_denied",
463
+ userSnapshot
464
+ };
465
+ }
466
+ if (user.isVendorRoleOwner === true) {
467
+ return {
468
+ allowed: true,
469
+ reason: "vendor_owner_role_full",
470
+ userSnapshot
471
+ };
472
+ }
473
+ const allowed2 = hasEntityPermission(vendorPerms, entity, action);
474
+ return {
475
+ allowed: allowed2,
476
+ reason: allowed2 ? "vendor_role_permissions_allow" : "vendor_role_permissions_deny",
477
+ userSnapshot
478
+ };
479
+ }
480
+ }
481
+ if (vendorIds.length > 0) {
482
+ if (entity === "dashboard" && action === "read") {
483
+ return {
484
+ allowed: true,
485
+ reason: "vendor_link_dashboard_read",
486
+ userSnapshot
487
+ };
488
+ }
489
+ if (entity === "analytics" && action === "read") {
490
+ return {
491
+ allowed: true,
492
+ reason: "vendor_link_analytics_read",
493
+ userSnapshot
494
+ };
495
+ }
496
+ if (entity === "settings") {
497
+ if (action === "read") {
498
+ return {
499
+ allowed: true,
500
+ reason: "vendor_link_settings_read",
501
+ userSnapshot
502
+ };
503
+ }
504
+ if (action === "update" && !isStaff) {
505
+ return {
506
+ allowed: true,
507
+ reason: "vendor_link_settings_update",
508
+ userSnapshot
509
+ };
510
+ }
511
+ }
512
+ if (VENDOR_STORE_RBAC_ENTITIES.has(entity)) {
513
+ if (isStaff && action === "read") {
514
+ return {
515
+ allowed: true,
516
+ reason: "vendor_staff_store_read",
517
+ userSnapshot
518
+ };
519
+ }
520
+ if (!isStaff) {
521
+ return {
522
+ allowed: true,
523
+ reason: "vendor_link_store_full",
524
+ userSnapshot
525
+ };
526
+ }
527
+ return {
528
+ allowed: false,
529
+ reason: "vendor_staff_store_write_denied",
530
+ userSnapshot
531
+ };
532
+ }
533
+ }
534
+ if (isVendorPortalUser(user) && isVendorOwner(user)) {
535
+ if (entity === "dashboard" && action === "read") {
536
+ return {
537
+ allowed: true,
538
+ reason: "vendor_owner_group_dashboard",
539
+ userSnapshot
540
+ };
541
+ }
542
+ if (entity === "analytics" && action === "read") {
543
+ return {
544
+ allowed: true,
545
+ reason: "vendor_owner_group_analytics",
546
+ userSnapshot
547
+ };
548
+ }
549
+ if (entity === "settings" && (action === "read" || action === "update")) {
550
+ return {
551
+ allowed: true,
552
+ reason: "vendor_owner_group_settings",
553
+ userSnapshot
554
+ };
555
+ }
556
+ if (VENDOR_STORE_RBAC_ENTITIES.has(entity)) {
557
+ return {
558
+ allowed: true,
559
+ reason: "vendor_owner_group_store",
560
+ userSnapshot
561
+ };
562
+ }
563
+ }
564
+ const vendorPortalReason = vendorPortalFallbackReason(user, entity, action);
565
+ if (vendorPortalReason) {
566
+ return {
567
+ allowed: true,
568
+ reason: vendorPortalReason,
569
+ userSnapshot
570
+ };
571
+ }
572
+ const explicit = user.entityPerms?.[entity];
573
+ if (explicit !== void 0) {
574
+ const allowed2 = hasEntityPermission(user.entityPerms, entity, action);
575
+ return {
576
+ allowed: allowed2,
577
+ reason: allowed2 ? "jwt_entity_perms_allow" : "jwt_entity_perms_deny",
578
+ userSnapshot
579
+ };
580
+ }
581
+ const allowed = hasEntityPermission(user.entityPerms, entity, action);
582
+ return {
583
+ allowed,
584
+ reason: allowed ? "entity_perms_fallback_allow" : "no_matching_rule",
585
+ userSnapshot
586
+ };
587
+ }
588
+ chunkUSNT2KNT_cjs.__name(explainSessionEntityAccess, "explainSessionEntityAccess");
589
+ async function logEntityAccessDecision(dataSource, context, user, entity, action, extra) {
590
+ if (!isRbacDebugEnabled()) return;
591
+ const explanation = explainSessionEntityAccess(user, entity, action);
592
+ let dbPermissions;
593
+ if (dataSource && user?.id) {
594
+ const id = Number(user.id);
595
+ if (Number.isFinite(id)) {
596
+ try {
597
+ const { loadDbPermissionsForUser } = await import('./rbac-debug-db-HWP65A4O.cjs');
598
+ dbPermissions = await loadDbPermissionsForUser(dataSource, id);
599
+ } catch (e) {
600
+ dbPermissions = {
601
+ error: e instanceof Error ? e.message : String(e)
602
+ };
603
+ }
604
+ }
605
+ }
606
+ logRbac(context, {
607
+ entity,
608
+ action,
609
+ allowed: explanation.allowed,
610
+ reason: explanation.reason,
611
+ ...explanation.userSnapshot,
612
+ dbPermissions,
613
+ ...extra
614
+ });
615
+ }
616
+ chunkUSNT2KNT_cjs.__name(logEntityAccessDecision, "logEntityAccessDecision");
617
+
618
+ exports.ADMIN_GROUP_NAME = ADMIN_GROUP_NAME;
619
+ exports.DEFAULT_VENDOR_ROLE_DEFS = DEFAULT_VENDOR_ROLE_DEFS;
620
+ exports.SUPER_ADMIN_GROUP_ID = SUPER_ADMIN_GROUP_ID;
621
+ exports.VENDOR_ADMIN_GROUP_ID = VENDOR_ADMIN_GROUP_ID;
622
+ exports.VENDOR_OWNER_GROUP_NAME = VENDOR_OWNER_GROUP_NAME;
623
+ exports.VENDOR_RBAC_ENTITIES = VENDOR_RBAC_ENTITIES;
624
+ exports.VENDOR_SCOPED_STORE_ENTITIES = VENDOR_SCOPED_STORE_ENTITIES;
625
+ exports.VENDOR_STORE_RBAC_ENTITIES = VENDOR_STORE_RBAC_ENTITIES;
626
+ exports.VENDOR_VIEWER_ROLE_NAME = VENDOR_VIEWER_ROLE_NAME;
627
+ exports.canManageVendorRoles = canManageVendorRoles;
628
+ exports.canManageVendorTeam = canManageVendorTeam;
629
+ exports.canOnboardVendors = canOnboardVendors;
630
+ exports.explainSessionEntityAccess = explainSessionEntityAccess;
631
+ exports.getPermissionableEntityKeys = getPermissionableEntityKeys;
632
+ exports.hasEntityPermission = hasEntityPermission;
633
+ exports.isPlatformAdministrator = isPlatformAdministrator;
634
+ exports.isRbacDebugEnabled = isRbacDebugEnabled;
635
+ exports.isSuperAdmin = isSuperAdmin;
636
+ exports.isSuperAdminGroupName = isSuperAdminGroupName;
637
+ exports.isVendorAdmin = isVendorAdmin;
638
+ exports.isVendorGroupName = isVendorGroupName;
639
+ exports.isVendorOwner = isVendorOwner;
640
+ exports.isVendorPortalUser = isVendorPortalUser;
641
+ exports.isVendorStaff = isVendorStaff;
642
+ exports.logEntityAccessDecision = logEntityAccessDecision;
643
+ exports.logRbac = logRbac;
644
+ exports.permissionRowsToRecord = permissionRowsToRecord;
645
+ exports.resolveDisabledMultiVendorScope = resolveDisabledMultiVendorScope;
646
+ exports.resolveVendorScopeFromSessionUser = resolveVendorScopeFromSessionUser;
647
+ exports.summarizeEntityPerms = summarizeEntityPerms;
648
+ exports.vendorPortalFlagsFromUser = vendorPortalFlagsFromUser;