mitra-interactions-sdk 1.0.60-beta.46 → 1.0.60-beta.47

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
@@ -64,13 +64,31 @@ var POPUP_W = 480;
64
64
  var POPUP_H = 600;
65
65
  var POPUP_TIMEOUT_MS = 5 * 60 * 1e3;
66
66
  var SSO_AUTH_PAGE_URL = "https://beta.infusion.cloud/sdk-auth.html";
67
- async function fetchSsoAuthPageUrl(_baseURL) {
67
+ async function fetchSsoAuthPageUrl(baseURL, projectId) {
68
68
  const config = isConfigured() ? getConfig() : null;
69
69
  if (config == null ? void 0 : config.authPageUrl) return config.authPageUrl;
70
+ const discovered = await discoverSsoAuthPageUrl(baseURL, projectId);
71
+ if (discovered) return discovered;
70
72
  const injected = readInjectedEnv().authPageUrl;
71
73
  if (injected) return injected;
72
74
  return SSO_AUTH_PAGE_URL;
73
75
  }
76
+ async function discoverSsoAuthPageUrl(baseURL, projectId) {
77
+ if (!baseURL || !projectId) return null;
78
+ try {
79
+ const path = `/sso/config?projectId=${encodeURIComponent(projectId)}`;
80
+ const response = await getFetch()(buildBffAuthEndpoint(baseURL, path), {
81
+ method: "GET",
82
+ headers: { accept: "application/json" }
83
+ });
84
+ if (!response.ok) return null;
85
+ const data = await response.json().catch(() => null);
86
+ const url = data && typeof data.authPageUrl === "string" ? data.authPageUrl : "";
87
+ return url || null;
88
+ } catch (e) {
89
+ return null;
90
+ }
91
+ }
74
92
  var SSO_ENABLED_PROVIDERS = ["google", "microsoft"];
75
93
  function providerLabel(provider) {
76
94
  return provider === "microsoft" ? "Microsoft" : provider === "google" ? "Google" : provider;
@@ -226,7 +244,7 @@ async function loginWithProvider(provider, options) {
226
244
  const { authUrl, projectId } = resolveLoginOptions(options);
227
245
  const state = generateState();
228
246
  const appId = String(projectId);
229
- const authPageUrl = await fetchSsoAuthPageUrl(authUrl);
247
+ const authPageUrl = await fetchSsoAuthPageUrl(authUrl, appId);
230
248
  const pageOrigin = getOriginFromUrl(authPageUrl);
231
249
  const redirectUri = stripToOriginPath(authPageUrl);
232
250
  const startUrl = buildStartUrl(authPageUrl, provider, state, appId, authUrl);
@@ -250,7 +268,7 @@ async function startSsoRedirect(provider, options) {
250
268
  const { authUrl, projectId } = resolveLoginOptions(options);
251
269
  const state = generateState();
252
270
  const appId = String(projectId);
253
- const authPageUrl = await fetchSsoAuthPageUrl();
271
+ const authPageUrl = await fetchSsoAuthPageUrl(authUrl, appId);
254
272
  const redirectUri = stripToOriginPath(authPageUrl);
255
273
  persistRedirectContext({
256
274
  state,