@spidy092/auth-client 3.1.6 → 3.2.0

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.
package/dist/index.js CHANGED
@@ -963,6 +963,29 @@ api.interceptors.request.use((config2) => {
963
963
  return config2;
964
964
  });
965
965
  var refreshPromise2 = null;
966
+ var SINGLE_ORG_DENIED_EVENT = "auth:single-org-denied";
967
+ function responseErrorCode(response) {
968
+ var _a;
969
+ const data = response == null ? void 0 : response.data;
970
+ return ((_a = data == null ? void 0 : data.errors) == null ? void 0 : _a.code) || (data == null ? void 0 : data.code) || null;
971
+ }
972
+ function isTenantAccessDenied(response) {
973
+ return (response == null ? void 0 : response.status) === 403 && responseErrorCode(response) === "TENANT_ACCESS_DENIED";
974
+ }
975
+ function isSingleOrganizationMode(response) {
976
+ return (response == null ? void 0 : response.status) === 409 && responseErrorCode(response) === "SINGLE_ORGANIZATION_MODE";
977
+ }
978
+ function dispatchSingleOrgDenied(response) {
979
+ var _a, _b;
980
+ if (typeof window === "undefined" || typeof window.dispatchEvent !== "function") return;
981
+ window.dispatchEvent(new CustomEvent(SINGLE_ORG_DENIED_EVENT, {
982
+ detail: {
983
+ code: responseErrorCode(response),
984
+ status: (response == null ? void 0 : response.status) || null,
985
+ currentOrgId: ((_b = (_a = response == null ? void 0 : response.data) == null ? void 0 : _a.errors) == null ? void 0 : _b.current_org_id) || null
986
+ }
987
+ }));
988
+ }
966
989
  api.interceptors.response.use(
967
990
  (response) => response,
968
991
  async (error) => {
@@ -970,6 +993,10 @@ api.interceptors.response.use(
970
993
  if (!response || !config2) {
971
994
  return Promise.reject(error);
972
995
  }
996
+ if (isTenantAccessDenied(response) || isSingleOrganizationMode(response)) {
997
+ dispatchSingleOrgDenied(response);
998
+ return Promise.reject(error);
999
+ }
973
1000
  if (response.status !== 401 || config2._retry) {
974
1001
  return Promise.reject(error);
975
1002
  }
@@ -1651,6 +1678,10 @@ var auth = {
1651
1678
  // 🌐 Authenticated API client
1652
1679
  api: api_default,
1653
1680
  preferences,
1681
+ // 🏢 Single-organization mode helpers
1682
+ SINGLE_ORG_DENIED_EVENT,
1683
+ isTenantAccessDenied,
1684
+ isSingleOrganizationMode,
1654
1685
  // 🔎 Safe authentication diagnostics
1655
1686
  getDiagnosticContext,
1656
1687
  emitAuthDiagnostic,
@@ -1702,12 +1733,15 @@ export {
1702
1733
  AuthProvider,
1703
1734
  PREFERENCE_DEFAULTS,
1704
1735
  PreferencesProvider,
1736
+ SINGLE_ORG_DENIED_EVENT,
1705
1737
  applyPreferences,
1706
1738
  auth,
1707
1739
  formatUserDate,
1708
1740
  formatUserNumber,
1709
1741
  formatUserRelativeTime,
1710
1742
  getPreferences,
1743
+ isSingleOrganizationMode,
1744
+ isTenantAccessDenied,
1711
1745
  normalizePreferences,
1712
1746
  resolveTheme,
1713
1747
  startPreferenceSync,