mitra-interactions-sdk 1.0.60-beta.4 → 1.0.60-beta.6
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 +10 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -255,10 +255,6 @@ function getFetch() {
|
|
|
255
255
|
if (typeof globalThis.fetch === "function") return globalThis.fetch;
|
|
256
256
|
throw new Error("fetch n\xE3o dispon\xEDvel. Use Node.js 18+ ou instale node-fetch.");
|
|
257
257
|
}
|
|
258
|
-
function buildEndpoint(authUrl, path) {
|
|
259
|
-
const base = authUrl.replace(/\/+$/, "");
|
|
260
|
-
return `${base}/iam/api/v1/auth${path}`;
|
|
261
|
-
}
|
|
262
258
|
function buildBffAuthEndpoint(gateway, path) {
|
|
263
259
|
const base = gateway.replace(/\/+$/, "");
|
|
264
260
|
return `${base}/auth${path}`;
|
|
@@ -287,25 +283,6 @@ function autoConfigureFromLogin2(response, authUrl, projectId) {
|
|
|
287
283
|
...response.integrationURL ? { integrationURL: response.integrationURL } : {}
|
|
288
284
|
});
|
|
289
285
|
}
|
|
290
|
-
async function postNewAuth(url, body) {
|
|
291
|
-
const fetchFn = getFetch();
|
|
292
|
-
const response = await fetchFn(url, {
|
|
293
|
-
method: "POST",
|
|
294
|
-
headers: { "Content-Type": "application/json" },
|
|
295
|
-
body: JSON.stringify(body)
|
|
296
|
-
});
|
|
297
|
-
if (!response.ok) {
|
|
298
|
-
const text = await response.text().catch(() => "");
|
|
299
|
-
let parsed = null;
|
|
300
|
-
try {
|
|
301
|
-
parsed = text ? JSON.parse(text) : null;
|
|
302
|
-
} catch (e) {
|
|
303
|
-
}
|
|
304
|
-
const msg = (parsed == null ? void 0 : parsed.message) || (parsed == null ? void 0 : parsed.error) || `HTTP ${response.status}`;
|
|
305
|
-
throw { message: msg, status: response.status, details: parsed };
|
|
306
|
-
}
|
|
307
|
-
return response.json();
|
|
308
|
-
}
|
|
309
286
|
async function postBffAuth(url, body) {
|
|
310
287
|
const fetchFn = getFetch();
|
|
311
288
|
const response = await fetchFn(url, {
|
|
@@ -473,6 +450,8 @@ async function emailLoginMitra2(options) {
|
|
|
473
450
|
const response = {
|
|
474
451
|
token: data.token,
|
|
475
452
|
baseURL: data.baseURL || authUrl,
|
|
453
|
+
// Guarda o refreshToken do login — é ele que vai no body do refresh depois.
|
|
454
|
+
...data.refreshToken ? { refreshToken: data.refreshToken } : {},
|
|
476
455
|
...data.integrationURL ? { integrationURL: data.integrationURL } : {}
|
|
477
456
|
};
|
|
478
457
|
autoConfigureFromLogin2(response, authUrl, projectId);
|
|
@@ -501,10 +480,15 @@ async function refreshTokenSilently2(authUrl, _projectId) {
|
|
|
501
480
|
const config = isConfigured() ? getConfig() : null;
|
|
502
481
|
const refreshToken = config == null ? void 0 : config.refreshToken;
|
|
503
482
|
if (!refreshToken) {
|
|
504
|
-
throw new Error("refreshToken n\xE3o dispon\xEDvel para renova\xE7\xE3o
|
|
483
|
+
throw new Error("refreshToken n\xE3o dispon\xEDvel para renova\xE7\xE3o. Fa\xE7a login novamente.");
|
|
505
484
|
}
|
|
506
|
-
const
|
|
507
|
-
return
|
|
485
|
+
const data = await postBffAuth(buildBffAuthEndpoint(authUrl, "/refresh-token"), { refreshToken });
|
|
486
|
+
return {
|
|
487
|
+
token: data.token,
|
|
488
|
+
baseURL: data.baseURL || authUrl,
|
|
489
|
+
...data.refreshToken ? { refreshToken: data.refreshToken } : {},
|
|
490
|
+
...data.integrationURL ? { integrationURL: data.integrationURL } : {}
|
|
491
|
+
};
|
|
508
492
|
} finally {
|
|
509
493
|
_refreshPromise2 = null;
|
|
510
494
|
}
|