mitra-interactions-sdk 1.0.60-beta.1 → 1.0.60-beta.2
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 +38 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -24
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -259,6 +259,10 @@ function buildEndpoint(authUrl, path) {
|
|
|
259
259
|
const base = authUrl.replace(/\/+$/, "");
|
|
260
260
|
return `${base}/iam/api/v1/auth${path}`;
|
|
261
261
|
}
|
|
262
|
+
function buildBffAuthEndpoint(gateway, path) {
|
|
263
|
+
const base = gateway.replace(/\/+$/, "");
|
|
264
|
+
return `${base}/auth${path}`;
|
|
265
|
+
}
|
|
262
266
|
function resolveLoginOptions2(options) {
|
|
263
267
|
var _a;
|
|
264
268
|
const config = isConfigured() ? getConfig() : null;
|
|
@@ -302,6 +306,26 @@ async function postNewAuth(url, body) {
|
|
|
302
306
|
}
|
|
303
307
|
return response.json();
|
|
304
308
|
}
|
|
309
|
+
async function postBffAuth(url, body) {
|
|
310
|
+
const fetchFn = getFetch();
|
|
311
|
+
const response = await fetchFn(url, {
|
|
312
|
+
method: "POST",
|
|
313
|
+
headers: { "Content-Type": "application/json" },
|
|
314
|
+
body: JSON.stringify(body)
|
|
315
|
+
});
|
|
316
|
+
if (!response.ok) {
|
|
317
|
+
const text2 = await response.text().catch(() => "");
|
|
318
|
+
let parsed = null;
|
|
319
|
+
try {
|
|
320
|
+
parsed = text2 ? JSON.parse(text2) : null;
|
|
321
|
+
} catch (e) {
|
|
322
|
+
}
|
|
323
|
+
const msg = (parsed == null ? void 0 : parsed.message) || (parsed == null ? void 0 : parsed.error) || `HTTP ${response.status}`;
|
|
324
|
+
throw { message: msg, status: response.status, details: parsed };
|
|
325
|
+
}
|
|
326
|
+
const text = await response.text().catch(() => "");
|
|
327
|
+
return text ? JSON.parse(text) : null;
|
|
328
|
+
}
|
|
305
329
|
function normalizeResponse(tokens, authUrl) {
|
|
306
330
|
return {
|
|
307
331
|
token: tokens.accessToken,
|
|
@@ -317,21 +341,9 @@ var OAUTH_RESULT_TYPE = "mitra-oauth-result";
|
|
|
317
341
|
var POPUP_W = 480;
|
|
318
342
|
var POPUP_H = 600;
|
|
319
343
|
var POPUP_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
method: "GET",
|
|
324
|
-
headers: { accept: "application/json" }
|
|
325
|
-
});
|
|
326
|
-
if (!response.ok) {
|
|
327
|
-
throw new Error(`SSO discovery falhou (HTTP ${response.status}).`);
|
|
328
|
-
}
|
|
329
|
-
const data = await response.json().catch(() => null);
|
|
330
|
-
const url = data && typeof data.authPageUrl === "string" ? data.authPageUrl : "";
|
|
331
|
-
if (!url) {
|
|
332
|
-
throw new Error("SSO discovery n\xE3o retornou authPageUrl.");
|
|
333
|
-
}
|
|
334
|
-
return url;
|
|
344
|
+
var SSO_AUTH_PAGE_URL = "https://d2by6yrxhbu2rl.cloudfront.net/sdk-auth.html";
|
|
345
|
+
async function fetchSsoAuthPageUrl(_baseURL) {
|
|
346
|
+
return SSO_AUTH_PAGE_URL;
|
|
335
347
|
}
|
|
336
348
|
function buildStartUrl(authPageUrl, provider, state, appId, apiUrl) {
|
|
337
349
|
const sep = authPageUrl.includes("?") ? "&" : "?";
|
|
@@ -456,25 +468,27 @@ async function loginMitra2(method, options) {
|
|
|
456
468
|
}
|
|
457
469
|
async function emailLoginMitra2(options) {
|
|
458
470
|
const { authUrl, projectId } = resolveLoginOptions2(options);
|
|
459
|
-
const
|
|
471
|
+
const data = await postBffAuth(buildBffAuthEndpoint(authUrl, "/email/login"), {
|
|
472
|
+
projectId: String(projectId),
|
|
460
473
|
email: options.email,
|
|
461
|
-
password: options.password
|
|
462
|
-
appId: String(projectId)
|
|
474
|
+
password: options.password
|
|
463
475
|
});
|
|
464
|
-
const response =
|
|
476
|
+
const response = {
|
|
477
|
+
token: data.token,
|
|
478
|
+
baseURL: data.baseURL || authUrl,
|
|
479
|
+
...data.integrationURL ? { integrationURL: data.integrationURL } : {}
|
|
480
|
+
};
|
|
465
481
|
autoConfigureFromLogin2(response, authUrl, projectId);
|
|
466
482
|
return response;
|
|
467
483
|
}
|
|
468
484
|
async function emailSignupMitra2(options) {
|
|
469
485
|
const { authUrl, projectId } = resolveLoginOptions2(options);
|
|
470
|
-
|
|
486
|
+
await postBffAuth(buildBffAuthEndpoint(authUrl, "/email/signup"), {
|
|
487
|
+
projectId: String(projectId),
|
|
471
488
|
name: options.name,
|
|
472
489
|
email: options.email,
|
|
473
|
-
password: options.password
|
|
474
|
-
appId: String(projectId)
|
|
490
|
+
password: options.password
|
|
475
491
|
});
|
|
476
|
-
const response = normalizeResponse(tokens, authUrl);
|
|
477
|
-
autoConfigureFromLogin2(response, authUrl, projectId);
|
|
478
492
|
}
|
|
479
493
|
async function emailVerifyCodeMitra2(_options) {
|
|
480
494
|
throw new Error(NOT_SUPPORTED_VERIFY);
|