mitra-interactions-sdk 1.0.60-beta.6 → 1.0.60-beta.8
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 +45 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -449,7 +449,10 @@ async function emailLoginMitra2(options) {
|
|
|
449
449
|
});
|
|
450
450
|
const response = {
|
|
451
451
|
token: data.token,
|
|
452
|
-
baseURL
|
|
452
|
+
// baseURL = authUrl usado (o gateway). NÃO usar data.baseURL da resposta:
|
|
453
|
+
// no novo Mitra o BFF pode devolver outro backURL e isso reescreveria a base
|
|
454
|
+
// (quebra no F5 quando o app persiste). authUrl e baseURL são o mesmo gateway.
|
|
455
|
+
baseURL: authUrl,
|
|
453
456
|
// Guarda o refreshToken do login — é ele que vai no body do refresh depois.
|
|
454
457
|
...data.refreshToken ? { refreshToken: data.refreshToken } : {},
|
|
455
458
|
...data.integrationURL ? { integrationURL: data.integrationURL } : {}
|
|
@@ -485,7 +488,9 @@ async function refreshTokenSilently2(authUrl, _projectId) {
|
|
|
485
488
|
const data = await postBffAuth(buildBffAuthEndpoint(authUrl, "/refresh-token"), { refreshToken });
|
|
486
489
|
return {
|
|
487
490
|
token: data.token,
|
|
488
|
-
|
|
491
|
+
// Refresh NÃO muda a base — devolve o authUrl usado (gateway), nunca o
|
|
492
|
+
// data.baseURL da resposta (que reescreveria a base e quebra no F5).
|
|
493
|
+
baseURL: authUrl,
|
|
489
494
|
...data.refreshToken ? { refreshToken: data.refreshToken } : {},
|
|
490
495
|
...data.integrationURL ? { integrationURL: data.integrationURL } : {}
|
|
491
496
|
};
|
|
@@ -2355,6 +2360,37 @@ function stripBearer(token) {
|
|
|
2355
2360
|
}
|
|
2356
2361
|
return t;
|
|
2357
2362
|
}
|
|
2363
|
+
var SESSION_STORE_KEY = "mitra-session";
|
|
2364
|
+
function safeLocalStorage() {
|
|
2365
|
+
try {
|
|
2366
|
+
return typeof localStorage !== "undefined" ? localStorage : null;
|
|
2367
|
+
} catch (e) {
|
|
2368
|
+
return null;
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
function persistRefreshToken(refreshToken) {
|
|
2372
|
+
const ls = safeLocalStorage();
|
|
2373
|
+
if (!ls) return;
|
|
2374
|
+
try {
|
|
2375
|
+
const raw = ls.getItem(SESSION_STORE_KEY);
|
|
2376
|
+
const obj = raw ? JSON.parse(raw) : {};
|
|
2377
|
+
obj.refreshToken = refreshToken;
|
|
2378
|
+
ls.setItem(SESSION_STORE_KEY, JSON.stringify(obj));
|
|
2379
|
+
} catch (e) {
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
function readPersistedRefreshToken() {
|
|
2383
|
+
const ls = safeLocalStorage();
|
|
2384
|
+
if (!ls) return void 0;
|
|
2385
|
+
try {
|
|
2386
|
+
const raw = ls.getItem(SESSION_STORE_KEY);
|
|
2387
|
+
if (!raw) return void 0;
|
|
2388
|
+
const obj = JSON.parse(raw);
|
|
2389
|
+
return typeof (obj == null ? void 0 : obj.refreshToken) === "string" && obj.refreshToken ? obj.refreshToken : void 0;
|
|
2390
|
+
} catch (e) {
|
|
2391
|
+
return void 0;
|
|
2392
|
+
}
|
|
2393
|
+
}
|
|
2358
2394
|
function readInjectedEnv() {
|
|
2359
2395
|
if (typeof window === "undefined") return {};
|
|
2360
2396
|
const env = window.__mitraEnv;
|
|
@@ -2372,6 +2408,12 @@ function configureSdkMitra(config = {}) {
|
|
|
2372
2408
|
throw new Error("baseURL \xE9 obrigat\xF3rio. Passe em configureSdkMitra({ baseURL }), fa\xE7a login para receber via sdk-auth, ou rode em uma app publicada pelo Mitra (window.__mitraEnv).");
|
|
2373
2409
|
}
|
|
2374
2410
|
if (merged.token != null) merged.token = stripBearer(merged.token);
|
|
2411
|
+
if (!merged.refreshToken) {
|
|
2412
|
+
const persisted = readPersistedRefreshToken();
|
|
2413
|
+
if (persisted) merged.refreshToken = persisted;
|
|
2414
|
+
} else {
|
|
2415
|
+
persistRefreshToken(merged.refreshToken);
|
|
2416
|
+
}
|
|
2375
2417
|
globalConfig = {
|
|
2376
2418
|
...merged,
|
|
2377
2419
|
baseURL: merged.baseURL.replace(/\/+$/, "")
|
|
@@ -2398,6 +2440,7 @@ function updateGlobalToken(token, refreshToken) {
|
|
|
2398
2440
|
token: stripBearer(token),
|
|
2399
2441
|
...refreshToken !== void 0 ? { refreshToken } : {}
|
|
2400
2442
|
};
|
|
2443
|
+
if (refreshToken) persistRefreshToken(refreshToken);
|
|
2401
2444
|
}
|
|
2402
2445
|
}
|
|
2403
2446
|
function resolveProjectId2(projectId) {
|