@spidy092/auth-client 3.1.6 → 3.2.1

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
@@ -516,6 +516,13 @@ async function logout(options = {}) {
516
516
  clientKey
517
517
  });
518
518
  }
519
+ if (scope === "sso" && authBaseUrl && clientKey) {
520
+ const frontChannelLogoutUrl = new URL(
521
+ `${authBaseUrl.replace(/\/+$/, "")}/logout/${encodeURIComponent(clientKey)}`
522
+ );
523
+ window.location.replace(frontChannelLogoutUrl.toString());
524
+ return;
525
+ }
519
526
  const fallbackUrl = isRouterMode() ? new URL("/login", window.location.origin) : new URL("/login", accountUiUrl);
520
527
  fallbackUrl.searchParams.set("logged_out", "true");
521
528
  fallbackUrl.searchParams.set("client", clientKey);
@@ -963,6 +970,29 @@ api.interceptors.request.use((config2) => {
963
970
  return config2;
964
971
  });
965
972
  var refreshPromise2 = null;
973
+ var SINGLE_ORG_DENIED_EVENT = "auth:single-org-denied";
974
+ function responseErrorCode(response) {
975
+ var _a;
976
+ const data = response == null ? void 0 : response.data;
977
+ return ((_a = data == null ? void 0 : data.errors) == null ? void 0 : _a.code) || (data == null ? void 0 : data.code) || null;
978
+ }
979
+ function isTenantAccessDenied(response) {
980
+ return (response == null ? void 0 : response.status) === 403 && responseErrorCode(response) === "TENANT_ACCESS_DENIED";
981
+ }
982
+ function isSingleOrganizationMode(response) {
983
+ return (response == null ? void 0 : response.status) === 409 && responseErrorCode(response) === "SINGLE_ORGANIZATION_MODE";
984
+ }
985
+ function dispatchSingleOrgDenied(response) {
986
+ var _a, _b;
987
+ if (typeof window === "undefined" || typeof window.dispatchEvent !== "function") return;
988
+ window.dispatchEvent(new CustomEvent(SINGLE_ORG_DENIED_EVENT, {
989
+ detail: {
990
+ code: responseErrorCode(response),
991
+ status: (response == null ? void 0 : response.status) || null,
992
+ currentOrgId: ((_b = (_a = response == null ? void 0 : response.data) == null ? void 0 : _a.errors) == null ? void 0 : _b.current_org_id) || null
993
+ }
994
+ }));
995
+ }
966
996
  api.interceptors.response.use(
967
997
  (response) => response,
968
998
  async (error) => {
@@ -970,6 +1000,10 @@ api.interceptors.response.use(
970
1000
  if (!response || !config2) {
971
1001
  return Promise.reject(error);
972
1002
  }
1003
+ if (isTenantAccessDenied(response) || isSingleOrganizationMode(response)) {
1004
+ dispatchSingleOrgDenied(response);
1005
+ return Promise.reject(error);
1006
+ }
973
1007
  if (response.status !== 401 || config2._retry) {
974
1008
  return Promise.reject(error);
975
1009
  }
@@ -1651,6 +1685,10 @@ var auth = {
1651
1685
  // 🌐 Authenticated API client
1652
1686
  api: api_default,
1653
1687
  preferences,
1688
+ // 🏢 Single-organization mode helpers
1689
+ SINGLE_ORG_DENIED_EVENT,
1690
+ isTenantAccessDenied,
1691
+ isSingleOrganizationMode,
1654
1692
  // 🔎 Safe authentication diagnostics
1655
1693
  getDiagnosticContext,
1656
1694
  emitAuthDiagnostic,
@@ -1702,12 +1740,15 @@ export {
1702
1740
  AuthProvider,
1703
1741
  PREFERENCE_DEFAULTS,
1704
1742
  PreferencesProvider,
1743
+ SINGLE_ORG_DENIED_EVENT,
1705
1744
  applyPreferences,
1706
1745
  auth,
1707
1746
  formatUserDate,
1708
1747
  formatUserNumber,
1709
1748
  formatUserRelativeTime,
1710
1749
  getPreferences,
1750
+ isSingleOrganizationMode,
1751
+ isTenantAccessDenied,
1711
1752
  normalizePreferences,
1712
1753
  resolveTheme,
1713
1754
  startPreferenceSync,