@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
@@ -0,0 +1,84 @@
1
+ 'use strict';
2
+
3
+ var chunkUSNT2KNT_cjs = require('./chunk-USNT2KNT.cjs');
4
+
5
+ // src/plugins/email/templates/layout.ts
6
+ function escapeHtml(s) {
7
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
8
+ }
9
+ chunkUSNT2KNT_cjs.__name(escapeHtml, "escapeHtml");
10
+ function socialLinkInnerHtml(s) {
11
+ if (s.iconUrl?.trim()) {
12
+ return `<img src="${escapeHtml(s.iconUrl.trim())}" alt="" width="20" height="20" style="display:inline-block;vertical-align:middle;border:0;" />`;
13
+ }
14
+ const label = s.icon && s.icon.trim() || "\u{1F517}";
15
+ return escapeHtml(label);
16
+ }
17
+ chunkUSNT2KNT_cjs.__name(socialLinkInnerHtml, "socialLinkInnerHtml");
18
+ function supportLinesHtml(supportEmail, supportPhone, opts) {
19
+ const parts = [];
20
+ const top = opts?.tightTop ? "margin-top:0;" : "margin-top:4px;";
21
+ if (supportEmail) {
22
+ parts.push(`<div style="font-size:13px;color:#444;${top}">&#128231; ${escapeHtml(supportEmail)}</div>`);
23
+ }
24
+ if (supportPhone) {
25
+ parts.push(`<div style="font-size:13px;color:#444;margin-top:2px;">&#128222; ${escapeHtml(supportPhone)}</div>`);
26
+ }
27
+ return parts.join("");
28
+ }
29
+ chunkUSNT2KNT_cjs.__name(supportLinesHtml, "supportLinesHtml");
30
+ function renderLayout(options) {
31
+ const { bodyHtml, companyDetails } = options;
32
+ const { logoUrl, companyName, supportEmail, supportPhone, socialLinks, footerDisclaimer, followUsTitle = "Follow Us" } = companyDetails;
33
+ const supportFooterHtml = supportLinesHtml(supportEmail, supportPhone, {
34
+ tightTop: true
35
+ });
36
+ const hasSocial = Boolean(socialLinks?.length);
37
+ const brandFooterInner = [];
38
+ if (logoUrl) {
39
+ brandFooterInner.push(`<img src="${escapeHtml(logoUrl)}" alt="" style="max-height:28px;max-width:160px;height:auto;width:auto;display:inline-block;vertical-align:middle;margin-right:10px;border:0;" />`);
40
+ }
41
+ if (companyName) {
42
+ brandFooterInner.push(`<span style="font-size:14px;font-weight:600;color:#111;vertical-align:middle;">${escapeHtml(companyName)}</span>`);
43
+ }
44
+ const brandFooterHtml = brandFooterInner.length ? `<div style="line-height:1.4;">${brandFooterInner.join("")}</div>` : "";
45
+ const followTitleHtml = hasSocial && followUsTitle ? `<div class="footer-follow-title" style="font-size:13px;font-weight:600;color:#555;margin:0;">${escapeHtml(followUsTitle)}</div>` : "";
46
+ const socialRowHtml = hasSocial && socialLinks ? `<div class="footer-social-icons" style="margin-top:6px;text-align:left;font-size:0;line-height:0;">${socialLinks.map((s) => `<a href="${escapeHtml(s.url)}" style="display:inline-block;margin-right:12px;text-decoration:none;color:#333;font-size:18px;line-height:1;vertical-align:middle;">${socialLinkInnerHtml(s)}</a>`).join("")}</div>` : "";
47
+ const rowSupport = supportFooterHtml ? `<tr><td class="footer-support-cell" colspan="2" valign="top" style="padding:0 0 10px 0;">${supportFooterHtml}</td></tr>` : "";
48
+ let footerBlock = "";
49
+ if (brandFooterHtml || followTitleHtml || socialRowHtml || footerDisclaimer || rowSupport) {
50
+ const rowBrand = brandFooterHtml ? `<tr><td class="footer-brand-cell" colspan="2" valign="top" style="padding:0 0 10px 0;">${brandFooterHtml}</td></tr>` : "";
51
+ const rowFollowTitle = followTitleHtml ? `<tr><td class="footer-follow-cell" colspan="2" valign="top" style="padding:14px 0 0 0;text-align:left;">${followTitleHtml}</td></tr>` : "";
52
+ const rowSocial = socialRowHtml ? `<tr><td class="footer-social-cell" colspan="2" style="padding:0;text-align:left;">${socialRowHtml}</td></tr>` : "";
53
+ footerBlock = `<table role="presentation" class="footer-main" width="100%" cellpadding="0" cellspacing="0" style="margin-top:28px;padding-top:16px;">${rowBrand}${rowSupport}${rowFollowTitle}${rowSocial}</table>`;
54
+ }
55
+ const disclaimerBlock = footerDisclaimer ? `<div style="margin-top:20px;padding-top:12px;font-size:11px;line-height:1.5;color:#888;">${escapeHtml(footerDisclaimer).replace(/\n/g, "<br/>")}</div>` : "";
56
+ const responsiveCss = `
57
+ @media only screen and (max-width: 600px) {
58
+ .email-wrap { padding-left: 12px !important; padding-right: 12px !important; }
59
+ .footer-follow-cell { padding-top: 12px !important; }
60
+ }
61
+ `;
62
+ return `<!DOCTYPE html>
63
+ <html>
64
+ <head>
65
+ <meta charset="utf-8">
66
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
67
+ <style type="text/css">${responsiveCss}</style>
68
+ </head>
69
+ <body style="margin:0;padding:0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;font-size:14px;line-height:1.5;color:#333;background:#fff;">
70
+ <table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#fff;">
71
+ <tr><td class="email-wrap" style="padding:16px;">
72
+ <div>
73
+ ${bodyHtml}
74
+ </div>
75
+ ${footerBlock}
76
+ ${disclaimerBlock}
77
+ </td></tr>
78
+ </table>
79
+ </body>
80
+ </html>`;
81
+ }
82
+ chunkUSNT2KNT_cjs.__name(renderLayout, "renderLayout");
83
+
84
+ exports.renderLayout = renderLayout;
@@ -0,0 +1,589 @@
1
+ import { __name } from './chunk-SHUYVCID.js';
2
+
3
+ // src/auth/permission-entities.ts
4
+ var PERMISSION_ENTITY_INTERNAL_EXCLUDE = /* @__PURE__ */ new Set([
5
+ "users",
6
+ "password_reset_tokens",
7
+ "user_groups",
8
+ "permissions",
9
+ "comments",
10
+ "form_fields",
11
+ "configs",
12
+ "knowledge_base_chunks",
13
+ "carts",
14
+ "cart_items",
15
+ "wishlists",
16
+ "wishlist_items",
17
+ "message_templates",
18
+ "vendor_users",
19
+ "vendor_roles",
20
+ "vendor_role_permissions"
21
+ ]);
22
+ var PERMISSION_LOGICAL_ENTITIES = [
23
+ "users",
24
+ "forms",
25
+ "form_submissions",
26
+ "dashboard",
27
+ "upload",
28
+ "settings",
29
+ "analytics",
30
+ "chat"
31
+ ];
32
+ var ADMIN_GROUP_NAME = "Administrator";
33
+ function isSuperAdminGroupName(name) {
34
+ return name === ADMIN_GROUP_NAME;
35
+ }
36
+ __name(isSuperAdminGroupName, "isSuperAdminGroupName");
37
+ function getPermissionableEntityKeys(entityMap) {
38
+ const fromMap = Object.keys(entityMap).filter((k) => !PERMISSION_ENTITY_INTERNAL_EXCLUDE.has(k));
39
+ const logical = PERMISSION_LOGICAL_ENTITIES.filter((k) => !fromMap.includes(k));
40
+ return [
41
+ ...fromMap.sort(),
42
+ ...logical
43
+ ].filter((k, i, a) => a.indexOf(k) === i);
44
+ }
45
+ __name(getPermissionableEntityKeys, "getPermissionableEntityKeys");
46
+ function permissionRowsToRecord(rows) {
47
+ const out = {};
48
+ if (!rows?.length) return out;
49
+ for (const p of rows) {
50
+ out[p.entity] = {
51
+ c: !!p.canCreate,
52
+ r: !!p.canRead,
53
+ u: !!p.canUpdate,
54
+ d: !!p.canDelete
55
+ };
56
+ }
57
+ return out;
58
+ }
59
+ __name(permissionRowsToRecord, "permissionRowsToRecord");
60
+ function hasEntityPermission(record, entity, action) {
61
+ const p = record?.[entity];
62
+ if (!p) return false;
63
+ if (action === "create") return p.c;
64
+ if (action === "read") return p.r;
65
+ if (action === "update") return p.u;
66
+ return p.d;
67
+ }
68
+ __name(hasEntityPermission, "hasEntityPermission");
69
+
70
+ // src/auth/vendor-scope.ts
71
+ var VENDOR_SCOPED_STORE_ENTITIES = /* @__PURE__ */ new Set([
72
+ "products",
73
+ "collections",
74
+ "brands",
75
+ "product_categories",
76
+ "orders",
77
+ "payments",
78
+ "taxes",
79
+ "attributes",
80
+ "vendor_customers",
81
+ "discounts",
82
+ "events",
83
+ "refund_policies"
84
+ ]);
85
+ var VENDOR_STORE_RBAC_ENTITIES = /* @__PURE__ */ new Set([
86
+ ...VENDOR_SCOPED_STORE_ENTITIES,
87
+ "order_discounts",
88
+ "order_addresses",
89
+ "event_products"
90
+ ]);
91
+ var VENDOR_OWNER_GROUP_NAME = "Vendor Owner";
92
+ function isVendorGroupName(name) {
93
+ if (!name?.trim()) return false;
94
+ const n = name.trim().toLowerCase();
95
+ return n === VENDOR_OWNER_GROUP_NAME.toLowerCase() || n.includes("vendor");
96
+ }
97
+ __name(isVendorGroupName, "isVendorGroupName");
98
+ function isPlatformAdministrator(user) {
99
+ if (!user?.email) return false;
100
+ return isSuperAdmin(user);
101
+ }
102
+ __name(isPlatformAdministrator, "isPlatformAdministrator");
103
+ function isVendorPortalUser(user) {
104
+ if (user?.isVendorPortal === true) return true;
105
+ if (!user?.email || isPlatformAdministrator(user)) return false;
106
+ if (isVendorAdmin(user)) return true;
107
+ return isVendorGroupName(user.groupName);
108
+ }
109
+ __name(isVendorPortalUser, "isVendorPortalUser");
110
+ function isVendorStaff(user) {
111
+ return isVendorPortalUser(user);
112
+ }
113
+ __name(isVendorStaff, "isVendorStaff");
114
+ function isVendorOwner(user) {
115
+ if (user?.isVendorOwner === true) return true;
116
+ if (!user?.email || isPlatformAdministrator(user)) return false;
117
+ if (user.isVendorRoleOwner === true) return true;
118
+ if (user.vendorRole === "staff") return false;
119
+ if (user.vendorRole === "owner") return true;
120
+ if (!isVendorPortalUser(user)) return false;
121
+ return user.groupName?.trim().toLowerCase() === VENDOR_OWNER_GROUP_NAME.toLowerCase();
122
+ }
123
+ __name(isVendorOwner, "isVendorOwner");
124
+ function canManageVendorTeam(user) {
125
+ return isPlatformAdministrator(user) || isVendorOwner(user);
126
+ }
127
+ __name(canManageVendorTeam, "canManageVendorTeam");
128
+ function canManageVendorRoles(user) {
129
+ return isPlatformAdministrator(user) || isVendorOwner(user);
130
+ }
131
+ __name(canManageVendorRoles, "canManageVendorRoles");
132
+ function canOnboardVendors(user) {
133
+ return isPlatformAdministrator(user);
134
+ }
135
+ __name(canOnboardVendors, "canOnboardVendors");
136
+ function resolveVendorScopeFromSessionUser(user) {
137
+ if (!user?.email) return {
138
+ type: "deny"
139
+ };
140
+ if (isPlatformAdministrator(user)) return {
141
+ type: "all"
142
+ };
143
+ const vendorIds = user.vendorIds ?? [];
144
+ if (vendorIds.length === 0) return {
145
+ type: "deny"
146
+ };
147
+ const preferred = user.activeVendorId ?? vendorIds[0];
148
+ const vendorId = vendorIds.includes(preferred) ? preferred : vendorIds[0];
149
+ return {
150
+ type: "vendor",
151
+ vendorId,
152
+ vendorIds
153
+ };
154
+ }
155
+ __name(resolveVendorScopeFromSessionUser, "resolveVendorScopeFromSessionUser");
156
+ function vendorPortalFlagsFromUser(input) {
157
+ const vendorIds = input.vendorIds ?? [];
158
+ const isVendorPortal = !input.isRBACAdmin && (vendorIds.length > 0 || isVendorGroupName(input.groupName));
159
+ const isVendorOwner2 = isVendorPortal && (input.isVendorRoleOwner === true || input.vendorRole !== "staff" && (input.vendorRole === "owner" || input.groupName?.trim().toLowerCase() === VENDOR_OWNER_GROUP_NAME.toLowerCase()));
160
+ return {
161
+ isVendorPortal,
162
+ isVendorOwner: isVendorOwner2
163
+ };
164
+ }
165
+ __name(vendorPortalFlagsFromUser, "vendorPortalFlagsFromUser");
166
+
167
+ // src/auth/role-helpers.ts
168
+ var SUPER_ADMIN_GROUP_ID = 1;
169
+ var VENDOR_ADMIN_GROUP_ID = 5;
170
+ function isSuperAdmin(user) {
171
+ if (!user) return false;
172
+ if (user.groupId === SUPER_ADMIN_GROUP_ID) return true;
173
+ if (user.isRBACAdmin === true) return true;
174
+ return isSuperAdminGroupName(user.groupName);
175
+ }
176
+ __name(isSuperAdmin, "isSuperAdmin");
177
+ function isVendorAdmin(user) {
178
+ if (!user?.email || isSuperAdmin(user)) return false;
179
+ if (user.groupId === VENDOR_ADMIN_GROUP_ID) return true;
180
+ if ((user.vendorIds?.length ?? 0) > 0) return true;
181
+ return isVendorGroupName(user.groupName);
182
+ }
183
+ __name(isVendorAdmin, "isVendorAdmin");
184
+
185
+ // src/lib/vendor-role-defaults.ts
186
+ var VENDOR_RBAC_ENTITIES = [
187
+ ...VENDOR_STORE_RBAC_ENTITIES,
188
+ "dashboard",
189
+ "settings",
190
+ "team",
191
+ "roles"
192
+ ];
193
+ var STORE_ENTITIES = [
194
+ ...VENDOR_STORE_RBAC_ENTITIES
195
+ ];
196
+ function full() {
197
+ return {
198
+ canCreate: true,
199
+ canRead: true,
200
+ canUpdate: true,
201
+ canDelete: true
202
+ };
203
+ }
204
+ __name(full, "full");
205
+ function read() {
206
+ return {
207
+ canCreate: false,
208
+ canRead: true,
209
+ canUpdate: false,
210
+ canDelete: false
211
+ };
212
+ }
213
+ __name(read, "read");
214
+ function none() {
215
+ return {
216
+ canCreate: false,
217
+ canRead: false,
218
+ canUpdate: false,
219
+ canDelete: false
220
+ };
221
+ }
222
+ __name(none, "none");
223
+ function readUpdate() {
224
+ return {
225
+ canCreate: false,
226
+ canRead: true,
227
+ canUpdate: true,
228
+ canDelete: false
229
+ };
230
+ }
231
+ __name(readUpdate, "readUpdate");
232
+ function storePerms(spec) {
233
+ const resolve = /* @__PURE__ */ __name((v) => {
234
+ if (v === "full") return full();
235
+ if (v === "read") return read();
236
+ if (v === "none") return none();
237
+ return v;
238
+ }, "resolve");
239
+ const out = {};
240
+ for (const entity of STORE_ENTITIES) {
241
+ out[entity] = resolve(spec[entity] ?? "none");
242
+ }
243
+ return out;
244
+ }
245
+ __name(storePerms, "storePerms");
246
+ var DEFAULT_VENDOR_ROLE_DEFS = [
247
+ {
248
+ name: "Owner",
249
+ description: "Full store access and team/role management",
250
+ isSystem: true,
251
+ isOwnerRole: true,
252
+ permissions: {
253
+ ...storePerms(Object.fromEntries(STORE_ENTITIES.map((e) => [
254
+ e,
255
+ "full"
256
+ ]))),
257
+ dashboard: read(),
258
+ settings: readUpdate(),
259
+ team: full(),
260
+ roles: full()
261
+ }
262
+ },
263
+ {
264
+ name: "Manager",
265
+ description: "Day-to-day store operations",
266
+ isSystem: true,
267
+ isOwnerRole: false,
268
+ permissions: {
269
+ ...storePerms({
270
+ products: "full",
271
+ collections: "full",
272
+ brands: "full",
273
+ product_categories: "full",
274
+ orders: "full",
275
+ vendor_customers: "full",
276
+ discounts: "full",
277
+ order_discounts: "full",
278
+ order_addresses: "full",
279
+ payments: "read",
280
+ taxes: "read",
281
+ attributes: "read"
282
+ }),
283
+ dashboard: read(),
284
+ settings: read(),
285
+ team: none(),
286
+ roles: none()
287
+ }
288
+ },
289
+ {
290
+ name: "Catalog Staff",
291
+ description: "Manage products and catalog content",
292
+ isSystem: true,
293
+ isOwnerRole: false,
294
+ permissions: {
295
+ ...storePerms({
296
+ products: "full",
297
+ collections: "full",
298
+ brands: "full",
299
+ product_categories: "full",
300
+ attributes: "full",
301
+ orders: "read",
302
+ vendor_customers: "read"
303
+ }),
304
+ dashboard: read(),
305
+ settings: none(),
306
+ team: none(),
307
+ roles: none()
308
+ }
309
+ },
310
+ {
311
+ name: "Fulfillment",
312
+ description: "Orders and fulfillment",
313
+ isSystem: true,
314
+ isOwnerRole: false,
315
+ permissions: {
316
+ ...storePerms({
317
+ products: "read",
318
+ orders: "full",
319
+ order_addresses: "full",
320
+ order_discounts: "read",
321
+ vendor_customers: "read"
322
+ }),
323
+ dashboard: read(),
324
+ settings: none(),
325
+ team: none(),
326
+ roles: none()
327
+ }
328
+ },
329
+ {
330
+ name: "Viewer",
331
+ description: "Read-only access to store data",
332
+ isSystem: true,
333
+ isOwnerRole: false,
334
+ permissions: {
335
+ ...storePerms(Object.fromEntries(STORE_ENTITIES.map((e) => [
336
+ e,
337
+ "read"
338
+ ]))),
339
+ dashboard: read(),
340
+ settings: none(),
341
+ team: none(),
342
+ roles: none()
343
+ }
344
+ }
345
+ ];
346
+ var VENDOR_VIEWER_ROLE_NAME = "Viewer";
347
+
348
+ // src/auth/rbac-debug.ts
349
+ var LOG_PREFIX = "[cms-rbac]";
350
+ function isRbacDebugEnabled() {
351
+ const v = process.env.CMS_RBAC_DEBUG?.trim().toLowerCase();
352
+ if (v === "1" || v === "true" || v === "yes") return true;
353
+ if (v === "0" || v === "false" || v === "no") return false;
354
+ return process.env.NODE_ENV === "development";
355
+ }
356
+ __name(isRbacDebugEnabled, "isRbacDebugEnabled");
357
+ function logRbac(message, data) {
358
+ if (!isRbacDebugEnabled()) return;
359
+ if (data) console.info(LOG_PREFIX, message, data);
360
+ else console.info(LOG_PREFIX, message);
361
+ }
362
+ __name(logRbac, "logRbac");
363
+ function summarizeEntityPerms(entityPerms) {
364
+ const out = {};
365
+ if (!entityPerms) return out;
366
+ for (const [entity, p] of Object.entries(entityPerms)) {
367
+ out[entity] = {
368
+ c: p.c,
369
+ r: p.r,
370
+ u: p.u,
371
+ d: p.d
372
+ };
373
+ }
374
+ return out;
375
+ }
376
+ __name(summarizeEntityPerms, "summarizeEntityPerms");
377
+ function vendorPortalFallbackReason(user, entity, action) {
378
+ if (!isVendorPortalUser(user)) return null;
379
+ if (entity === "dashboard" && action === "read") return "vendor_portal_dashboard_fallback";
380
+ if (entity === "analytics" && action === "read") return "vendor_portal_analytics_fallback";
381
+ if (entity === "settings" && action === "read") return "vendor_portal_settings_read_fallback";
382
+ if (VENDOR_STORE_RBAC_ENTITIES.has(entity) && action === "read") return "vendor_portal_store_read_fallback";
383
+ return null;
384
+ }
385
+ __name(vendorPortalFallbackReason, "vendorPortalFallbackReason");
386
+ function explainSessionEntityAccess(user, entity, action) {
387
+ const userSnapshot = {
388
+ email: user?.email ?? null,
389
+ id: user?.id ?? null,
390
+ groupId: user?.groupId ?? null,
391
+ groupName: user?.groupName ?? null,
392
+ isRBACAdmin: user?.isRBACAdmin ?? false,
393
+ adminAccess: user?.adminAccess ?? null,
394
+ vendorIds: user?.vendorIds ?? [],
395
+ activeVendorId: user?.activeVendorId ?? null,
396
+ vendorRole: user?.vendorRole ?? null,
397
+ vendorRoleId: user?.vendorRoleId ?? null,
398
+ vendorRoleName: user?.vendorRoleName ?? null,
399
+ isVendorRoleOwner: user?.isVendorRoleOwner ?? false,
400
+ vendorEntityPerms: summarizeEntityPerms(user?.vendorEntityPerms),
401
+ isVendorPortal: user?.isVendorPortal ?? false,
402
+ isVendorOwner: user?.isVendorOwner ?? false,
403
+ isVendorPortalComputed: isVendorPortalUser(user),
404
+ isVendorOwnerComputed: isVendorOwner(user),
405
+ jwtEntityPerms: summarizeEntityPerms(user?.entityPerms),
406
+ jwtEntityPermForTarget: user?.entityPerms?.[entity] ?? null
407
+ };
408
+ if (!user?.email) {
409
+ return {
410
+ allowed: false,
411
+ reason: "no_session_email",
412
+ userSnapshot
413
+ };
414
+ }
415
+ if (user.isRBACAdmin) {
416
+ return {
417
+ allowed: true,
418
+ reason: "platform_administrator",
419
+ userSnapshot
420
+ };
421
+ }
422
+ const vendorIds = user.vendorIds ?? [];
423
+ const isStaff = user.vendorRole === "staff";
424
+ const vendorPerms = user.vendorEntityPerms;
425
+ const hasVendorRolePerms = vendorPerms != null && Object.keys(vendorPerms).length > 0;
426
+ if (vendorIds.length > 0 && hasVendorRolePerms) {
427
+ const vendorRbacSet = new Set(VENDOR_RBAC_ENTITIES);
428
+ if (vendorRbacSet.has(entity) || entity === "analytics") {
429
+ if (entity === "analytics" && action === "read") {
430
+ const allowed3 = hasEntityPermission(vendorPerms, "dashboard", "read");
431
+ return {
432
+ allowed: allowed3,
433
+ reason: allowed3 ? "vendor_role_analytics_via_dashboard" : "vendor_role_analytics_denied",
434
+ userSnapshot
435
+ };
436
+ }
437
+ if (user.isVendorRoleOwner === true) {
438
+ return {
439
+ allowed: true,
440
+ reason: "vendor_owner_role_full",
441
+ userSnapshot
442
+ };
443
+ }
444
+ const allowed2 = hasEntityPermission(vendorPerms, entity, action);
445
+ return {
446
+ allowed: allowed2,
447
+ reason: allowed2 ? "vendor_role_permissions_allow" : "vendor_role_permissions_deny",
448
+ userSnapshot
449
+ };
450
+ }
451
+ }
452
+ if (vendorIds.length > 0) {
453
+ if (entity === "dashboard" && action === "read") {
454
+ return {
455
+ allowed: true,
456
+ reason: "vendor_link_dashboard_read",
457
+ userSnapshot
458
+ };
459
+ }
460
+ if (entity === "analytics" && action === "read") {
461
+ return {
462
+ allowed: true,
463
+ reason: "vendor_link_analytics_read",
464
+ userSnapshot
465
+ };
466
+ }
467
+ if (entity === "settings") {
468
+ if (action === "read") {
469
+ return {
470
+ allowed: true,
471
+ reason: "vendor_link_settings_read",
472
+ userSnapshot
473
+ };
474
+ }
475
+ if (action === "update" && !isStaff) {
476
+ return {
477
+ allowed: true,
478
+ reason: "vendor_link_settings_update",
479
+ userSnapshot
480
+ };
481
+ }
482
+ }
483
+ if (VENDOR_STORE_RBAC_ENTITIES.has(entity)) {
484
+ if (isStaff && action === "read") {
485
+ return {
486
+ allowed: true,
487
+ reason: "vendor_staff_store_read",
488
+ userSnapshot
489
+ };
490
+ }
491
+ if (!isStaff) {
492
+ return {
493
+ allowed: true,
494
+ reason: "vendor_link_store_full",
495
+ userSnapshot
496
+ };
497
+ }
498
+ return {
499
+ allowed: false,
500
+ reason: "vendor_staff_store_write_denied",
501
+ userSnapshot
502
+ };
503
+ }
504
+ }
505
+ if (isVendorPortalUser(user) && isVendorOwner(user)) {
506
+ if (entity === "dashboard" && action === "read") {
507
+ return {
508
+ allowed: true,
509
+ reason: "vendor_owner_group_dashboard",
510
+ userSnapshot
511
+ };
512
+ }
513
+ if (entity === "analytics" && action === "read") {
514
+ return {
515
+ allowed: true,
516
+ reason: "vendor_owner_group_analytics",
517
+ userSnapshot
518
+ };
519
+ }
520
+ if (entity === "settings" && (action === "read" || action === "update")) {
521
+ return {
522
+ allowed: true,
523
+ reason: "vendor_owner_group_settings",
524
+ userSnapshot
525
+ };
526
+ }
527
+ if (VENDOR_STORE_RBAC_ENTITIES.has(entity)) {
528
+ return {
529
+ allowed: true,
530
+ reason: "vendor_owner_group_store",
531
+ userSnapshot
532
+ };
533
+ }
534
+ }
535
+ const vendorPortalReason = vendorPortalFallbackReason(user, entity, action);
536
+ if (vendorPortalReason) {
537
+ return {
538
+ allowed: true,
539
+ reason: vendorPortalReason,
540
+ userSnapshot
541
+ };
542
+ }
543
+ const explicit = user.entityPerms?.[entity];
544
+ if (explicit !== void 0) {
545
+ const allowed2 = hasEntityPermission(user.entityPerms, entity, action);
546
+ return {
547
+ allowed: allowed2,
548
+ reason: allowed2 ? "jwt_entity_perms_allow" : "jwt_entity_perms_deny",
549
+ userSnapshot
550
+ };
551
+ }
552
+ const allowed = hasEntityPermission(user.entityPerms, entity, action);
553
+ return {
554
+ allowed,
555
+ reason: allowed ? "entity_perms_fallback_allow" : "no_matching_rule",
556
+ userSnapshot
557
+ };
558
+ }
559
+ __name(explainSessionEntityAccess, "explainSessionEntityAccess");
560
+ async function logEntityAccessDecision(dataSource, context, user, entity, action, extra) {
561
+ if (!isRbacDebugEnabled()) return;
562
+ const explanation = explainSessionEntityAccess(user, entity, action);
563
+ let dbPermissions;
564
+ if (dataSource && user?.id) {
565
+ const id = Number(user.id);
566
+ if (Number.isFinite(id)) {
567
+ try {
568
+ const { loadDbPermissionsForUser } = await import('./rbac-debug-db-MTCTVNNM.js');
569
+ dbPermissions = await loadDbPermissionsForUser(dataSource, id);
570
+ } catch (e) {
571
+ dbPermissions = {
572
+ error: e instanceof Error ? e.message : String(e)
573
+ };
574
+ }
575
+ }
576
+ }
577
+ logRbac(context, {
578
+ entity,
579
+ action,
580
+ allowed: explanation.allowed,
581
+ reason: explanation.reason,
582
+ ...explanation.userSnapshot,
583
+ dbPermissions,
584
+ ...extra
585
+ });
586
+ }
587
+ __name(logEntityAccessDecision, "logEntityAccessDecision");
588
+
589
+ export { ADMIN_GROUP_NAME, DEFAULT_VENDOR_ROLE_DEFS, SUPER_ADMIN_GROUP_ID, VENDOR_ADMIN_GROUP_ID, VENDOR_OWNER_GROUP_NAME, VENDOR_RBAC_ENTITIES, VENDOR_SCOPED_STORE_ENTITIES, VENDOR_STORE_RBAC_ENTITIES, VENDOR_VIEWER_ROLE_NAME, canManageVendorRoles, canManageVendorTeam, canOnboardVendors, explainSessionEntityAccess, getPermissionableEntityKeys, hasEntityPermission, isPlatformAdministrator, isRbacDebugEnabled, isSuperAdmin, isSuperAdminGroupName, isVendorAdmin, isVendorGroupName, isVendorOwner, isVendorPortalUser, isVendorStaff, logEntityAccessDecision, logRbac, permissionRowsToRecord, resolveVendorScopeFromSessionUser, summarizeEntityPerms, vendorPortalFlagsFromUser };