mitra-interactions-sdk 1.0.60-beta.18 → 1.0.60-beta.19
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 +50 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -269,6 +269,16 @@ declare function loginMitra(method: 'email' | 'google' | 'microsoft' | 'mitra',
|
|
|
269
269
|
declare function loginWithGoogleMitra(options?: LoginOptions): Promise<LoginResponse>;
|
|
270
270
|
declare function loginWithMicrosoftMitra(options?: LoginOptions): Promise<LoginResponse>;
|
|
271
271
|
declare function refreshTokenSilently(authUrl: string, projectId: number | string): Promise<LoginResponse>;
|
|
272
|
+
/**
|
|
273
|
+
* Gera o JWT a partir do code do SSO (novo Mitra). O app lê codeMitra/stateMitra
|
|
274
|
+
* do fragment (lógica de template) e chama aqui pra validar o nonce e trocar o
|
|
275
|
+
* code por token no BFF. Exclusivo do novo mundo — no legacy o token já vem
|
|
276
|
+
* pronto no fragment (tokenMitra).
|
|
277
|
+
*/
|
|
278
|
+
declare function exchangeSsoCodeMitra(options: {
|
|
279
|
+
code: string;
|
|
280
|
+
state: string;
|
|
281
|
+
}): Promise<LoginResponse>;
|
|
272
282
|
|
|
273
283
|
/**
|
|
274
284
|
* Mitra Interactions SDK - Services
|
|
@@ -325,4 +335,4 @@ declare function patchRecordMitra(options: PatchRecordOptions): Promise<Record<s
|
|
|
325
335
|
declare function deleteRecordMitra(options: DeleteRecordOptions): Promise<void>;
|
|
326
336
|
declare function createRecordsBatchMitra(options: CreateRecordsBatchOptions): Promise<Record<string, any>[]>;
|
|
327
337
|
|
|
328
|
-
export { type CallIntegrationOptions, type CallIntegrationResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type DeleteRecordOptions, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type IntegrationResponse, type ListIntegrationsOptions, type ListRecordsOptions, type ListRecordsResponse, type LoginOptions, type LoginResponse, type MitraConfig, type MitraInstance, type PatchRecordOptions, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, callIntegrationMitra, configureSdkMitra, createMitraInstance, createRecordMitra, createRecordsBatchMitra, deleteRecordMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getConfig, getPublicServerFunctionExecutionMitra, getRecordMitra, listIntegrationsMitra, listRecordsMitra, loginMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, patchRecordMitra, refreshTokenSilently, resolveProjectId, stopServerFunctionExecutionMitra, updateRecordMitra };
|
|
338
|
+
export { type CallIntegrationOptions, type CallIntegrationResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type DeleteRecordOptions, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type IntegrationResponse, type ListIntegrationsOptions, type ListRecordsOptions, type ListRecordsResponse, type LoginOptions, type LoginResponse, type MitraConfig, type MitraInstance, type PatchRecordOptions, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, callIntegrationMitra, configureSdkMitra, createMitraInstance, createRecordMitra, createRecordsBatchMitra, deleteRecordMitra, exchangeSsoCodeMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getConfig, getPublicServerFunctionExecutionMitra, getRecordMitra, listIntegrationsMitra, listRecordsMitra, loginMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, patchRecordMitra, refreshTokenSilently, resolveProjectId, stopServerFunctionExecutionMitra, updateRecordMitra };
|
package/dist/index.d.ts
CHANGED
|
@@ -269,6 +269,16 @@ declare function loginMitra(method: 'email' | 'google' | 'microsoft' | 'mitra',
|
|
|
269
269
|
declare function loginWithGoogleMitra(options?: LoginOptions): Promise<LoginResponse>;
|
|
270
270
|
declare function loginWithMicrosoftMitra(options?: LoginOptions): Promise<LoginResponse>;
|
|
271
271
|
declare function refreshTokenSilently(authUrl: string, projectId: number | string): Promise<LoginResponse>;
|
|
272
|
+
/**
|
|
273
|
+
* Gera o JWT a partir do code do SSO (novo Mitra). O app lê codeMitra/stateMitra
|
|
274
|
+
* do fragment (lógica de template) e chama aqui pra validar o nonce e trocar o
|
|
275
|
+
* code por token no BFF. Exclusivo do novo mundo — no legacy o token já vem
|
|
276
|
+
* pronto no fragment (tokenMitra).
|
|
277
|
+
*/
|
|
278
|
+
declare function exchangeSsoCodeMitra(options: {
|
|
279
|
+
code: string;
|
|
280
|
+
state: string;
|
|
281
|
+
}): Promise<LoginResponse>;
|
|
272
282
|
|
|
273
283
|
/**
|
|
274
284
|
* Mitra Interactions SDK - Services
|
|
@@ -325,4 +335,4 @@ declare function patchRecordMitra(options: PatchRecordOptions): Promise<Record<s
|
|
|
325
335
|
declare function deleteRecordMitra(options: DeleteRecordOptions): Promise<void>;
|
|
326
336
|
declare function createRecordsBatchMitra(options: CreateRecordsBatchOptions): Promise<Record<string, any>[]>;
|
|
327
337
|
|
|
328
|
-
export { type CallIntegrationOptions, type CallIntegrationResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type DeleteRecordOptions, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type IntegrationResponse, type ListIntegrationsOptions, type ListRecordsOptions, type ListRecordsResponse, type LoginOptions, type LoginResponse, type MitraConfig, type MitraInstance, type PatchRecordOptions, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, callIntegrationMitra, configureSdkMitra, createMitraInstance, createRecordMitra, createRecordsBatchMitra, deleteRecordMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getConfig, getPublicServerFunctionExecutionMitra, getRecordMitra, listIntegrationsMitra, listRecordsMitra, loginMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, patchRecordMitra, refreshTokenSilently, resolveProjectId, stopServerFunctionExecutionMitra, updateRecordMitra };
|
|
338
|
+
export { type CallIntegrationOptions, type CallIntegrationResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type DeleteRecordOptions, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type IntegrationResponse, type ListIntegrationsOptions, type ListRecordsOptions, type ListRecordsResponse, type LoginOptions, type LoginResponse, type MitraConfig, type MitraInstance, type PatchRecordOptions, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, callIntegrationMitra, configureSdkMitra, createMitraInstance, createRecordMitra, createRecordsBatchMitra, deleteRecordMitra, exchangeSsoCodeMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getConfig, getPublicServerFunctionExecutionMitra, getRecordMitra, listIntegrationsMitra, listRecordsMitra, loginMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, patchRecordMitra, refreshTokenSilently, resolveProjectId, stopServerFunctionExecutionMitra, updateRecordMitra };
|
package/dist/index.js
CHANGED
|
@@ -218,7 +218,6 @@ function normalizeResponse(tokens, authUrl) {
|
|
|
218
218
|
};
|
|
219
219
|
}
|
|
220
220
|
var NOT_SUPPORTED_POPUP = 'loginMitra com method "email" ou "mitra" n\xE3o \xE9 suportado no novo Mitra. Use SSO (loginWithGoogleMitra).';
|
|
221
|
-
var NOT_SUPPORTED_REDIRECT = 'mode "redirect" n\xE3o \xE9 suportado no novo Mitra para SSO. Use mode "popup" (default).';
|
|
222
221
|
var OAUTH_RESULT_TYPE = "mitra-oauth-result";
|
|
223
222
|
var POPUP_W = 480;
|
|
224
223
|
var POPUP_H = 600;
|
|
@@ -259,7 +258,28 @@ async function exchangeSsoCode(authUrl, provider, code, redirectUri, projectId)
|
|
|
259
258
|
autoConfigureFromLogin2(response, authUrl, projectId);
|
|
260
259
|
return response;
|
|
261
260
|
}
|
|
262
|
-
|
|
261
|
+
var SSO_REDIRECT_STORE_KEY = "mitra_sso_redirect";
|
|
262
|
+
function persistRedirectContext(ctx) {
|
|
263
|
+
try {
|
|
264
|
+
sessionStorage.setItem(SSO_REDIRECT_STORE_KEY, JSON.stringify(ctx));
|
|
265
|
+
} catch (e) {
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
function readRedirectContext() {
|
|
269
|
+
try {
|
|
270
|
+
const raw = sessionStorage.getItem(SSO_REDIRECT_STORE_KEY);
|
|
271
|
+
return raw ? JSON.parse(raw) : null;
|
|
272
|
+
} catch (e) {
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function clearRedirectContext() {
|
|
277
|
+
try {
|
|
278
|
+
sessionStorage.removeItem(SSO_REDIRECT_STORE_KEY);
|
|
279
|
+
} catch (e) {
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function buildStartUrl(authPageUrl, provider, state, appId, apiUrl, returnTo) {
|
|
263
283
|
const sep = authPageUrl.includes("?") ? "&" : "?";
|
|
264
284
|
const query = {
|
|
265
285
|
provider,
|
|
@@ -268,10 +288,11 @@ function buildStartUrl(authPageUrl, provider, state, appId, apiUrl) {
|
|
|
268
288
|
apiUrl,
|
|
269
289
|
// origin = origin desta SDK; a página trava o postMessage do result nela.
|
|
270
290
|
origin: window.location.origin,
|
|
271
|
-
// Contrato novo: a página NÃO troca mais o code — devolve o code cru
|
|
272
|
-
// postMessage. A SDK troca no BFF /auth/{provider}.
|
|
291
|
+
// Contrato novo: a página NÃO troca mais o code — devolve o code cru (popup
|
|
292
|
+
// via postMessage, redirect via #codeMitra). A SDK troca no BFF /auth/{provider}.
|
|
273
293
|
responseType: "code"
|
|
274
294
|
};
|
|
295
|
+
if (returnTo) query.returnTo = returnTo;
|
|
275
296
|
return authPageUrl + sep + new URLSearchParams(query).toString();
|
|
276
297
|
}
|
|
277
298
|
function getOriginFromUrl2(url) {
|
|
@@ -351,7 +372,7 @@ async function loginWithProvider(provider, options) {
|
|
|
351
372
|
throw new Error("SSO s\xF3 funciona em ambiente browser.");
|
|
352
373
|
}
|
|
353
374
|
if ((options == null ? void 0 : options.mode) === "redirect") {
|
|
354
|
-
|
|
375
|
+
return startSsoRedirect(provider, options);
|
|
355
376
|
}
|
|
356
377
|
if (_oauthInFlight) return _oauthInFlight;
|
|
357
378
|
_oauthInFlight = (async () => {
|
|
@@ -376,6 +397,26 @@ async function loginWithProvider(provider, options) {
|
|
|
376
397
|
})();
|
|
377
398
|
return _oauthInFlight;
|
|
378
399
|
}
|
|
400
|
+
async function startSsoRedirect(provider, options) {
|
|
401
|
+
const { authUrl, projectId } = resolveLoginOptions2(options);
|
|
402
|
+
const state = generateState();
|
|
403
|
+
const appId = String(projectId);
|
|
404
|
+
const authPageUrl = await fetchSsoAuthPageUrl();
|
|
405
|
+
const redirectUri = stripToOriginPath(authPageUrl);
|
|
406
|
+
persistRedirectContext({ state, provider, authUrl, projectId: appId, redirectUri });
|
|
407
|
+
const startUrl = buildStartUrl(authPageUrl, provider, state, appId, authUrl, window.location.href);
|
|
408
|
+
window.location.assign(startUrl);
|
|
409
|
+
return new Promise(() => {
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
async function exchangeSsoCodeMitra(options) {
|
|
413
|
+
const ctx = readRedirectContext();
|
|
414
|
+
clearRedirectContext();
|
|
415
|
+
if (!ctx || ctx.state !== options.state) {
|
|
416
|
+
throw new Error("State inv\xE1lido no retorno do SSO (poss\xEDvel CSRF).");
|
|
417
|
+
}
|
|
418
|
+
return exchangeSsoCode(ctx.authUrl, ctx.provider, options.code, ctx.redirectUri, ctx.projectId);
|
|
419
|
+
}
|
|
379
420
|
async function loginWithGoogleMitra2(options) {
|
|
380
421
|
return loginWithProvider("google", options);
|
|
381
422
|
}
|
|
@@ -449,6 +490,9 @@ async function loginWithMicrosoftMitra3(options) {
|
|
|
449
490
|
async function refreshTokenSilently3(authUrl, projectId) {
|
|
450
491
|
return isLegacyAuthUrl(authUrl) ? refreshTokenSilently(authUrl, projectId) : refreshTokenSilently2(authUrl);
|
|
451
492
|
}
|
|
493
|
+
async function exchangeSsoCodeMitra2(options) {
|
|
494
|
+
return exchangeSsoCodeMitra(options);
|
|
495
|
+
}
|
|
452
496
|
|
|
453
497
|
// src/instance.ts
|
|
454
498
|
function formatToken(token) {
|
|
@@ -1097,6 +1141,7 @@ exports.createMitraInstance = createMitraInstance;
|
|
|
1097
1141
|
exports.createRecordMitra = createRecordMitra;
|
|
1098
1142
|
exports.createRecordsBatchMitra = createRecordsBatchMitra;
|
|
1099
1143
|
exports.deleteRecordMitra = deleteRecordMitra;
|
|
1144
|
+
exports.exchangeSsoCodeMitra = exchangeSsoCodeMitra2;
|
|
1100
1145
|
exports.executePublicServerFunctionAsyncMitra = executePublicServerFunctionAsyncMitra;
|
|
1101
1146
|
exports.executePublicServerFunctionMitra = executePublicServerFunctionMitra;
|
|
1102
1147
|
exports.executeServerFunctionAsyncMitra = executeServerFunctionAsyncMitra;
|