mitra-interactions-sdk 1.0.60-beta.12 → 1.0.60-beta.14
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.d.mts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +103 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +103 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -881,6 +881,16 @@ declare function emailLoginMitra(options: EmailLoginOptions): Promise<LoginRespo
|
|
|
881
881
|
declare function emailVerifyCodeMitra(options: EmailVerifyCodeOptions): Promise<LoginResponse>;
|
|
882
882
|
declare function emailResendCodeMitra(options: EmailResendCodeOptions): Promise<void>;
|
|
883
883
|
declare function refreshTokenSilently(authUrl: string, projectId: number | string): Promise<LoginResponse>;
|
|
884
|
+
/**
|
|
885
|
+
* Gera o JWT a partir do code do SSO (novo Mitra). O app lê codeMitra/stateMitra
|
|
886
|
+
* do fragment (lógica de template) e chama aqui pra validar o nonce e trocar o
|
|
887
|
+
* code por token no BFF. Exclusivo do novo mundo — no legacy o token já vem
|
|
888
|
+
* pronto no fragment (tokenMitra).
|
|
889
|
+
*/
|
|
890
|
+
declare function exchangeSsoCodeMitra(options: {
|
|
891
|
+
code: string;
|
|
892
|
+
state: string;
|
|
893
|
+
}): Promise<LoginResponse>;
|
|
884
894
|
|
|
885
895
|
/**
|
|
886
896
|
* Mitra Interactions SDK - Password Reset (legacy backend)
|
|
@@ -1127,4 +1137,4 @@ declare function setProfileScreensMitra(options: SetProfileScreensOptions): Prom
|
|
|
1127
1137
|
*/
|
|
1128
1138
|
declare function setProfileServerFunctionsMitra(options: SetProfileServerFunctionsOptions): Promise<SetProfilePermissionResponse>;
|
|
1129
1139
|
|
|
1130
|
-
export { type AgentApiKeyTarget, type AgentAttachment, type AgentAttachmentType, type AgentAuthMeta, type AgentChat, type AgentDeltaEvent, type AgentErrorEvent, type AgentMessage, type AgentModelGroup, type AgentModelOption, type AgentProviderListItem, type AgentQueueChangeEvent, type AgentStatusChangeEvent, type AgentSubscriptionAccount, type AgentSubscriptionTarget, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type AuthAgentCredentialOptions, type AuthAgentCredentialResult, type AuthClaudeResult, type AuthCodexResult, type AuthMethod, type CallIntegrationOptions, type CallIntegrationResponse, type ChatManageAction, type ConnectAgentCredentialOptions, type ConnectAgentSubscriptionResult, type ConnectableSubscriptionTarget, type CreateProfileOptions, type CreateProfileResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAccessType, type CredentialAction, type CredentialTarget, type DeleteAgentChatResult, type DeleteProfileOptions, type DeleteProfileResponse, type DeleteRecordOptions, type EmailLoginOptions, type EmailResendCodeOptions, type EmailSignupOptions, type EmailVerifyCodeOptions, type ExecuteDataLoaderOptions, type ExecuteDataLoaderResponse, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetProfileDetailsOptions, type GetProfileDetailsResponse, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type IntegrationResponse, type ListAgentModelsResult, type ListAgentProvidersResult, type ListIntegrationsOptions, type ListProfilesOptions, type ListProfilesResponse, type ListRecordsOptions, type ListRecordsResponse, type LoginOptions, type LoginResponse, type ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type ManageAgentCredentialResult, type MitraConfig, type MitraInstance, type PatchRecordOptions, type ProfileTableRef, type QueuedItem, type RenameAgentChatResult, type ResetPasswordOptions, type SendOptions, type SendPasswordResetCodeOptions, type SetFileStatusOptions, type SetFileStatusResponse, type SetProfileActionsOptions, type SetProfileDmlTablesOptions, type SetProfilePermissionResponse, type SetProfileScreensOptions, type SetProfileSelectTablesOptions, type SetProfileServerFunctionsOptions, type SetProfileUsersOptions, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateProfileOptions, type UpdateProfileResponse, type UpdateRecordOptions, type UploadFileOptions, type UploadFileResponse, type ValidatePasswordResetCodeOptions, callIntegrationMitra, configureSdkMitra, createMitraInstance, createProfileMitra, createRecordMitra, createRecordsBatchMitra, deleteProfileMitra, deleteRecordMitra, emailLoginMitra, emailResendCodeMitra, emailSignupMitra, emailVerifyCodeMitra, executeDataLoaderMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getAgentTaskMitra, getConfig, getProfileDetailsMitra, getPublicServerFunctionExecutionMitra, getRecordMitra, listIntegrationsMitra, listProfilesMitra, listRecordsMitra, loginMitra, loginWithEmailMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, manageAgentChatMitra, manageAgentCredentialMitra, patchRecordMitra, refreshTokenSilently, resetPasswordMitra, resolveProjectId, sendPasswordResetCodeMitra, setFileStatusMitra, setProfileActionsMitra, setProfileDmlTablesMitra, setProfileScreensMitra, setProfileSelectTablesMitra, setProfileServerFunctionsMitra, setProfileUsersMitra, stopServerFunctionExecutionMitra, updateProfileMitra, updateRecordMitra, uploadFileLoadableMitra, uploadFilePublicMitra, validatePasswordResetCodeMitra };
|
|
1140
|
+
export { type AgentApiKeyTarget, type AgentAttachment, type AgentAttachmentType, type AgentAuthMeta, type AgentChat, type AgentDeltaEvent, type AgentErrorEvent, type AgentMessage, type AgentModelGroup, type AgentModelOption, type AgentProviderListItem, type AgentQueueChangeEvent, type AgentStatusChangeEvent, type AgentSubscriptionAccount, type AgentSubscriptionTarget, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type AuthAgentCredentialOptions, type AuthAgentCredentialResult, type AuthClaudeResult, type AuthCodexResult, type AuthMethod, type CallIntegrationOptions, type CallIntegrationResponse, type ChatManageAction, type ConnectAgentCredentialOptions, type ConnectAgentSubscriptionResult, type ConnectableSubscriptionTarget, type CreateProfileOptions, type CreateProfileResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAccessType, type CredentialAction, type CredentialTarget, type DeleteAgentChatResult, type DeleteProfileOptions, type DeleteProfileResponse, type DeleteRecordOptions, type EmailLoginOptions, type EmailResendCodeOptions, type EmailSignupOptions, type EmailVerifyCodeOptions, type ExecuteDataLoaderOptions, type ExecuteDataLoaderResponse, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetProfileDetailsOptions, type GetProfileDetailsResponse, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type IntegrationResponse, type ListAgentModelsResult, type ListAgentProvidersResult, type ListIntegrationsOptions, type ListProfilesOptions, type ListProfilesResponse, type ListRecordsOptions, type ListRecordsResponse, type LoginOptions, type LoginResponse, type ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type ManageAgentCredentialResult, type MitraConfig, type MitraInstance, type PatchRecordOptions, type ProfileTableRef, type QueuedItem, type RenameAgentChatResult, type ResetPasswordOptions, type SendOptions, type SendPasswordResetCodeOptions, type SetFileStatusOptions, type SetFileStatusResponse, type SetProfileActionsOptions, type SetProfileDmlTablesOptions, type SetProfilePermissionResponse, type SetProfileScreensOptions, type SetProfileSelectTablesOptions, type SetProfileServerFunctionsOptions, type SetProfileUsersOptions, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateProfileOptions, type UpdateProfileResponse, type UpdateRecordOptions, type UploadFileOptions, type UploadFileResponse, type ValidatePasswordResetCodeOptions, callIntegrationMitra, configureSdkMitra, createMitraInstance, createProfileMitra, createRecordMitra, createRecordsBatchMitra, deleteProfileMitra, deleteRecordMitra, emailLoginMitra, emailResendCodeMitra, emailSignupMitra, emailVerifyCodeMitra, exchangeSsoCodeMitra, executeDataLoaderMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getAgentTaskMitra, getConfig, getProfileDetailsMitra, getPublicServerFunctionExecutionMitra, getRecordMitra, listIntegrationsMitra, listProfilesMitra, listRecordsMitra, loginMitra, loginWithEmailMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, manageAgentChatMitra, manageAgentCredentialMitra, patchRecordMitra, refreshTokenSilently, resetPasswordMitra, resolveProjectId, sendPasswordResetCodeMitra, setFileStatusMitra, setProfileActionsMitra, setProfileDmlTablesMitra, setProfileScreensMitra, setProfileSelectTablesMitra, setProfileServerFunctionsMitra, setProfileUsersMitra, stopServerFunctionExecutionMitra, updateProfileMitra, updateRecordMitra, uploadFileLoadableMitra, uploadFilePublicMitra, validatePasswordResetCodeMitra };
|
package/dist/index.d.ts
CHANGED
|
@@ -881,6 +881,16 @@ declare function emailLoginMitra(options: EmailLoginOptions): Promise<LoginRespo
|
|
|
881
881
|
declare function emailVerifyCodeMitra(options: EmailVerifyCodeOptions): Promise<LoginResponse>;
|
|
882
882
|
declare function emailResendCodeMitra(options: EmailResendCodeOptions): Promise<void>;
|
|
883
883
|
declare function refreshTokenSilently(authUrl: string, projectId: number | string): Promise<LoginResponse>;
|
|
884
|
+
/**
|
|
885
|
+
* Gera o JWT a partir do code do SSO (novo Mitra). O app lê codeMitra/stateMitra
|
|
886
|
+
* do fragment (lógica de template) e chama aqui pra validar o nonce e trocar o
|
|
887
|
+
* code por token no BFF. Exclusivo do novo mundo — no legacy o token já vem
|
|
888
|
+
* pronto no fragment (tokenMitra).
|
|
889
|
+
*/
|
|
890
|
+
declare function exchangeSsoCodeMitra(options: {
|
|
891
|
+
code: string;
|
|
892
|
+
state: string;
|
|
893
|
+
}): Promise<LoginResponse>;
|
|
884
894
|
|
|
885
895
|
/**
|
|
886
896
|
* Mitra Interactions SDK - Password Reset (legacy backend)
|
|
@@ -1127,4 +1137,4 @@ declare function setProfileScreensMitra(options: SetProfileScreensOptions): Prom
|
|
|
1127
1137
|
*/
|
|
1128
1138
|
declare function setProfileServerFunctionsMitra(options: SetProfileServerFunctionsOptions): Promise<SetProfilePermissionResponse>;
|
|
1129
1139
|
|
|
1130
|
-
export { type AgentApiKeyTarget, type AgentAttachment, type AgentAttachmentType, type AgentAuthMeta, type AgentChat, type AgentDeltaEvent, type AgentErrorEvent, type AgentMessage, type AgentModelGroup, type AgentModelOption, type AgentProviderListItem, type AgentQueueChangeEvent, type AgentStatusChangeEvent, type AgentSubscriptionAccount, type AgentSubscriptionTarget, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type AuthAgentCredentialOptions, type AuthAgentCredentialResult, type AuthClaudeResult, type AuthCodexResult, type AuthMethod, type CallIntegrationOptions, type CallIntegrationResponse, type ChatManageAction, type ConnectAgentCredentialOptions, type ConnectAgentSubscriptionResult, type ConnectableSubscriptionTarget, type CreateProfileOptions, type CreateProfileResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAccessType, type CredentialAction, type CredentialTarget, type DeleteAgentChatResult, type DeleteProfileOptions, type DeleteProfileResponse, type DeleteRecordOptions, type EmailLoginOptions, type EmailResendCodeOptions, type EmailSignupOptions, type EmailVerifyCodeOptions, type ExecuteDataLoaderOptions, type ExecuteDataLoaderResponse, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetProfileDetailsOptions, type GetProfileDetailsResponse, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type IntegrationResponse, type ListAgentModelsResult, type ListAgentProvidersResult, type ListIntegrationsOptions, type ListProfilesOptions, type ListProfilesResponse, type ListRecordsOptions, type ListRecordsResponse, type LoginOptions, type LoginResponse, type ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type ManageAgentCredentialResult, type MitraConfig, type MitraInstance, type PatchRecordOptions, type ProfileTableRef, type QueuedItem, type RenameAgentChatResult, type ResetPasswordOptions, type SendOptions, type SendPasswordResetCodeOptions, type SetFileStatusOptions, type SetFileStatusResponse, type SetProfileActionsOptions, type SetProfileDmlTablesOptions, type SetProfilePermissionResponse, type SetProfileScreensOptions, type SetProfileSelectTablesOptions, type SetProfileServerFunctionsOptions, type SetProfileUsersOptions, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateProfileOptions, type UpdateProfileResponse, type UpdateRecordOptions, type UploadFileOptions, type UploadFileResponse, type ValidatePasswordResetCodeOptions, callIntegrationMitra, configureSdkMitra, createMitraInstance, createProfileMitra, createRecordMitra, createRecordsBatchMitra, deleteProfileMitra, deleteRecordMitra, emailLoginMitra, emailResendCodeMitra, emailSignupMitra, emailVerifyCodeMitra, executeDataLoaderMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getAgentTaskMitra, getConfig, getProfileDetailsMitra, getPublicServerFunctionExecutionMitra, getRecordMitra, listIntegrationsMitra, listProfilesMitra, listRecordsMitra, loginMitra, loginWithEmailMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, manageAgentChatMitra, manageAgentCredentialMitra, patchRecordMitra, refreshTokenSilently, resetPasswordMitra, resolveProjectId, sendPasswordResetCodeMitra, setFileStatusMitra, setProfileActionsMitra, setProfileDmlTablesMitra, setProfileScreensMitra, setProfileSelectTablesMitra, setProfileServerFunctionsMitra, setProfileUsersMitra, stopServerFunctionExecutionMitra, updateProfileMitra, updateRecordMitra, uploadFileLoadableMitra, uploadFilePublicMitra, validatePasswordResetCodeMitra };
|
|
1140
|
+
export { type AgentApiKeyTarget, type AgentAttachment, type AgentAttachmentType, type AgentAuthMeta, type AgentChat, type AgentDeltaEvent, type AgentErrorEvent, type AgentMessage, type AgentModelGroup, type AgentModelOption, type AgentProviderListItem, type AgentQueueChangeEvent, type AgentStatusChangeEvent, type AgentSubscriptionAccount, type AgentSubscriptionTarget, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type AuthAgentCredentialOptions, type AuthAgentCredentialResult, type AuthClaudeResult, type AuthCodexResult, type AuthMethod, type CallIntegrationOptions, type CallIntegrationResponse, type ChatManageAction, type ConnectAgentCredentialOptions, type ConnectAgentSubscriptionResult, type ConnectableSubscriptionTarget, type CreateProfileOptions, type CreateProfileResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAccessType, type CredentialAction, type CredentialTarget, type DeleteAgentChatResult, type DeleteProfileOptions, type DeleteProfileResponse, type DeleteRecordOptions, type EmailLoginOptions, type EmailResendCodeOptions, type EmailSignupOptions, type EmailVerifyCodeOptions, type ExecuteDataLoaderOptions, type ExecuteDataLoaderResponse, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetProfileDetailsOptions, type GetProfileDetailsResponse, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type IntegrationResponse, type ListAgentModelsResult, type ListAgentProvidersResult, type ListIntegrationsOptions, type ListProfilesOptions, type ListProfilesResponse, type ListRecordsOptions, type ListRecordsResponse, type LoginOptions, type LoginResponse, type ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type ManageAgentCredentialResult, type MitraConfig, type MitraInstance, type PatchRecordOptions, type ProfileTableRef, type QueuedItem, type RenameAgentChatResult, type ResetPasswordOptions, type SendOptions, type SendPasswordResetCodeOptions, type SetFileStatusOptions, type SetFileStatusResponse, type SetProfileActionsOptions, type SetProfileDmlTablesOptions, type SetProfilePermissionResponse, type SetProfileScreensOptions, type SetProfileSelectTablesOptions, type SetProfileServerFunctionsOptions, type SetProfileUsersOptions, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateProfileOptions, type UpdateProfileResponse, type UpdateRecordOptions, type UploadFileOptions, type UploadFileResponse, type ValidatePasswordResetCodeOptions, callIntegrationMitra, configureSdkMitra, createMitraInstance, createProfileMitra, createRecordMitra, createRecordsBatchMitra, deleteProfileMitra, deleteRecordMitra, emailLoginMitra, emailResendCodeMitra, emailSignupMitra, emailVerifyCodeMitra, exchangeSsoCodeMitra, executeDataLoaderMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getAgentTaskMitra, getConfig, getProfileDetailsMitra, getPublicServerFunctionExecutionMitra, getRecordMitra, listIntegrationsMitra, listProfilesMitra, listRecordsMitra, loginMitra, loginWithEmailMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, manageAgentChatMitra, manageAgentCredentialMitra, patchRecordMitra, refreshTokenSilently, resetPasswordMitra, resolveProjectId, sendPasswordResetCodeMitra, setFileStatusMitra, setProfileActionsMitra, setProfileDmlTablesMitra, setProfileScreensMitra, setProfileSelectTablesMitra, setProfileServerFunctionsMitra, setProfileUsersMitra, stopServerFunctionExecutionMitra, updateProfileMitra, updateRecordMitra, uploadFileLoadableMitra, uploadFilePublicMitra, validatePasswordResetCodeMitra };
|
package/dist/index.js
CHANGED
|
@@ -309,18 +309,82 @@ function normalizeResponse(tokens, authUrl) {
|
|
|
309
309
|
var NOT_SUPPORTED_POPUP = 'Login via popup (loginWithEmailMitra/loginMitra com method "email" ou "mitra") ainda n\xE3o suportado no novo Mitra. Use emailLoginMitra({ email, password }).';
|
|
310
310
|
var NOT_SUPPORTED_VERIFY = "emailVerifyCodeMitra n\xE3o existe no novo Mitra (signup \xE9 direto, sem c\xF3digo de verifica\xE7\xE3o).";
|
|
311
311
|
var NOT_SUPPORTED_RESEND = "emailResendCodeMitra n\xE3o existe no novo Mitra.";
|
|
312
|
-
var NOT_SUPPORTED_REDIRECT = 'mode "redirect" ainda n\xE3o suportado no novo Mitra para SSO. Use mode "popup" (default).';
|
|
313
312
|
var OAUTH_RESULT_TYPE = "mitra-oauth-result";
|
|
314
313
|
var POPUP_W = 480;
|
|
315
314
|
var POPUP_H = 600;
|
|
316
315
|
var POPUP_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
317
|
-
var SSO_AUTH_PAGE_URL = "https://
|
|
316
|
+
var SSO_AUTH_PAGE_URL = "https://stg.mitralab.io/sdk-auth.html";
|
|
318
317
|
async function fetchSsoAuthPageUrl(_baseURL) {
|
|
319
318
|
return SSO_AUTH_PAGE_URL;
|
|
320
319
|
}
|
|
321
|
-
|
|
320
|
+
var SSO_ENABLED_PROVIDERS = ["google"];
|
|
321
|
+
function providerLabel(provider) {
|
|
322
|
+
return provider === "microsoft" ? "Microsoft" : provider === "google" ? "Google" : provider;
|
|
323
|
+
}
|
|
324
|
+
function assertProviderAvailable(provider) {
|
|
325
|
+
if (!SSO_ENABLED_PROVIDERS.includes(provider)) {
|
|
326
|
+
throw new Error(`Login com ${providerLabel(provider)} ainda n\xE3o dispon\xEDvel no novo Mitra.`);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function stripToOriginPath(url) {
|
|
330
|
+
try {
|
|
331
|
+
const u = new URL(url);
|
|
332
|
+
return u.origin + u.pathname;
|
|
333
|
+
} catch (e) {
|
|
334
|
+
return url.split("?")[0].split("#")[0];
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
async function exchangeSsoCode(authUrl, provider, code, redirectUri, projectId) {
|
|
338
|
+
const data = await postBffAuth(buildBffAuthEndpoint(authUrl, `/${provider}`), {
|
|
339
|
+
appId: String(projectId),
|
|
340
|
+
code,
|
|
341
|
+
redirectUri
|
|
342
|
+
});
|
|
343
|
+
const response = {
|
|
344
|
+
token: data.token,
|
|
345
|
+
// baseURL = authUrl (gateway); o BFF não devolve URLs de bootstrap.
|
|
346
|
+
baseURL: authUrl,
|
|
347
|
+
...data.refreshToken ? { refreshToken: data.refreshToken } : {}
|
|
348
|
+
};
|
|
349
|
+
autoConfigureFromLogin2(response, authUrl, projectId);
|
|
350
|
+
return response;
|
|
351
|
+
}
|
|
352
|
+
var SSO_REDIRECT_STORE_KEY = "mitra_sso_redirect";
|
|
353
|
+
function persistRedirectContext(ctx) {
|
|
354
|
+
try {
|
|
355
|
+
sessionStorage.setItem(SSO_REDIRECT_STORE_KEY, JSON.stringify(ctx));
|
|
356
|
+
} catch (e) {
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
function readRedirectContext() {
|
|
360
|
+
try {
|
|
361
|
+
const raw = sessionStorage.getItem(SSO_REDIRECT_STORE_KEY);
|
|
362
|
+
return raw ? JSON.parse(raw) : null;
|
|
363
|
+
} catch (e) {
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
function clearRedirectContext() {
|
|
368
|
+
try {
|
|
369
|
+
sessionStorage.removeItem(SSO_REDIRECT_STORE_KEY);
|
|
370
|
+
} catch (e) {
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
function buildStartUrl(authPageUrl, provider, state, appId, apiUrl, returnTo) {
|
|
322
374
|
const sep = authPageUrl.includes("?") ? "&" : "?";
|
|
323
|
-
|
|
375
|
+
const query = {
|
|
376
|
+
provider,
|
|
377
|
+
state,
|
|
378
|
+
appId,
|
|
379
|
+
apiUrl,
|
|
380
|
+
// origin = origin desta SDK; a página trava o postMessage do result nela.
|
|
381
|
+
origin: window.location.origin,
|
|
382
|
+
// Contrato novo: a página NÃO troca mais o code — devolve o code cru (popup
|
|
383
|
+
// via postMessage, redirect via #codeMitra). A SDK troca no BFF /auth/{provider}.
|
|
384
|
+
responseType: "code"
|
|
385
|
+
};
|
|
386
|
+
if (returnTo) query.returnTo = returnTo;
|
|
387
|
+
return authPageUrl + sep + new URLSearchParams(query).toString();
|
|
324
388
|
}
|
|
325
389
|
function getOriginFromUrl2(url) {
|
|
326
390
|
try {
|
|
@@ -377,11 +441,11 @@ function openOAuthPopup(providerUrl, expectedOrigin, expectedState) {
|
|
|
377
441
|
reject(new Error(data.error || "Erro na autentica\xE7\xE3o OAuth."));
|
|
378
442
|
return;
|
|
379
443
|
}
|
|
380
|
-
if (!data.token) {
|
|
381
|
-
reject(new Error("Resposta OAuth sem token."));
|
|
444
|
+
if (!data.code && !data.token) {
|
|
445
|
+
reject(new Error("Resposta OAuth sem code nem token."));
|
|
382
446
|
return;
|
|
383
447
|
}
|
|
384
|
-
resolve({ token: data.token });
|
|
448
|
+
resolve({ code: data.code, token: data.token });
|
|
385
449
|
}
|
|
386
450
|
function cleanup() {
|
|
387
451
|
clearTimeout(timer);
|
|
@@ -394,13 +458,14 @@ function openOAuthPopup(providerUrl, expectedOrigin, expectedState) {
|
|
|
394
458
|
}
|
|
395
459
|
var _oauthInFlight = null;
|
|
396
460
|
async function loginWithProvider(provider, options) {
|
|
397
|
-
|
|
461
|
+
assertProviderAvailable(provider);
|
|
398
462
|
if (typeof window === "undefined") {
|
|
399
463
|
throw new Error("SSO s\xF3 funciona em ambiente browser.");
|
|
400
464
|
}
|
|
401
465
|
if ((options == null ? void 0 : options.mode) === "redirect") {
|
|
402
|
-
|
|
466
|
+
return startSsoRedirect(provider, options);
|
|
403
467
|
}
|
|
468
|
+
if (_oauthInFlight) return _oauthInFlight;
|
|
404
469
|
_oauthInFlight = (async () => {
|
|
405
470
|
try {
|
|
406
471
|
const { authUrl, projectId } = resolveLoginOptions2(options);
|
|
@@ -408,8 +473,12 @@ async function loginWithProvider(provider, options) {
|
|
|
408
473
|
const appId = String(projectId);
|
|
409
474
|
const authPageUrl = await fetchSsoAuthPageUrl(authUrl);
|
|
410
475
|
const pageOrigin = getOriginFromUrl2(authPageUrl);
|
|
476
|
+
const redirectUri = stripToOriginPath(authPageUrl);
|
|
411
477
|
const startUrl = buildStartUrl(authPageUrl, provider, state, appId, authUrl);
|
|
412
|
-
const { token } = await openOAuthPopup(startUrl, pageOrigin, state);
|
|
478
|
+
const { code, token } = await openOAuthPopup(startUrl, pageOrigin, state);
|
|
479
|
+
if (code) {
|
|
480
|
+
return await exchangeSsoCode(authUrl, provider, code, redirectUri, projectId);
|
|
481
|
+
}
|
|
413
482
|
const response = normalizeResponse(token, authUrl);
|
|
414
483
|
autoConfigureFromLogin2(response, authUrl, projectId);
|
|
415
484
|
return response;
|
|
@@ -419,6 +488,26 @@ async function loginWithProvider(provider, options) {
|
|
|
419
488
|
})();
|
|
420
489
|
return _oauthInFlight;
|
|
421
490
|
}
|
|
491
|
+
async function startSsoRedirect(provider, options) {
|
|
492
|
+
const { authUrl, projectId } = resolveLoginOptions2(options);
|
|
493
|
+
const state = generateState();
|
|
494
|
+
const appId = String(projectId);
|
|
495
|
+
const authPageUrl = await fetchSsoAuthPageUrl();
|
|
496
|
+
const redirectUri = stripToOriginPath(authPageUrl);
|
|
497
|
+
persistRedirectContext({ state, provider, authUrl, projectId: appId, redirectUri });
|
|
498
|
+
const startUrl = buildStartUrl(authPageUrl, provider, state, appId, authUrl, window.location.href);
|
|
499
|
+
window.location.assign(startUrl);
|
|
500
|
+
return new Promise(() => {
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
async function exchangeSsoCodeMitra(options) {
|
|
504
|
+
const ctx = readRedirectContext();
|
|
505
|
+
clearRedirectContext();
|
|
506
|
+
if (!ctx || ctx.state !== options.state) {
|
|
507
|
+
throw new Error("State inv\xE1lido no retorno do SSO (poss\xEDvel CSRF).");
|
|
508
|
+
}
|
|
509
|
+
return exchangeSsoCode(ctx.authUrl, ctx.provider, options.code, ctx.redirectUri, ctx.projectId);
|
|
510
|
+
}
|
|
422
511
|
async function loginWithEmailMitra2(_options) {
|
|
423
512
|
throw new Error(NOT_SUPPORTED_POPUP);
|
|
424
513
|
}
|
|
@@ -548,6 +637,9 @@ async function emailResendCodeMitra3(options) {
|
|
|
548
637
|
async function refreshTokenSilently3(authUrl, projectId) {
|
|
549
638
|
return isLegacyAuthUrl(authUrl) ? refreshTokenSilently(authUrl, projectId) : refreshTokenSilently2(authUrl);
|
|
550
639
|
}
|
|
640
|
+
async function exchangeSsoCodeMitra2(options) {
|
|
641
|
+
return exchangeSsoCodeMitra(options);
|
|
642
|
+
}
|
|
551
643
|
|
|
552
644
|
// src/password-reset.ts
|
|
553
645
|
var AUTH_API_BY_AUTH_URL = {
|
|
@@ -2366,6 +2458,7 @@ exports.emailLoginMitra = emailLoginMitra3;
|
|
|
2366
2458
|
exports.emailResendCodeMitra = emailResendCodeMitra3;
|
|
2367
2459
|
exports.emailSignupMitra = emailSignupMitra3;
|
|
2368
2460
|
exports.emailVerifyCodeMitra = emailVerifyCodeMitra3;
|
|
2461
|
+
exports.exchangeSsoCodeMitra = exchangeSsoCodeMitra2;
|
|
2369
2462
|
exports.executeDataLoaderMitra = executeDataLoaderMitra;
|
|
2370
2463
|
exports.executePublicServerFunctionAsyncMitra = executePublicServerFunctionAsyncMitra;
|
|
2371
2464
|
exports.executePublicServerFunctionMitra = executePublicServerFunctionMitra;
|