mitra-interactions-sdk 1.0.34 → 1.0.35
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/README.md +78 -0
- package/dist/index.d.mts +66 -1
- package/dist/index.d.ts +66 -1
- package/dist/index.js +139 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +136 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -144,6 +144,79 @@ configureSdkMitra({
|
|
|
144
144
|
});
|
|
145
145
|
```
|
|
146
146
|
|
|
147
|
+
### Login por Email (iframe silencioso)
|
|
148
|
+
|
|
149
|
+
Para quem precisa montar sua **própria tela de login** (sem popup/redirect), o SDK oferece funções que fazem a autenticação via iframe invisível. As credenciais são enviadas ao HTML de auth via `postMessage` — sem CORS, sem expor a API.
|
|
150
|
+
|
|
151
|
+
#### emailSignupMitra
|
|
152
|
+
|
|
153
|
+
Cria conta. Após sucesso, o usuário recebe um código de verificação por email.
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { emailSignupMitra } from 'mitra-interactions-sdk';
|
|
157
|
+
|
|
158
|
+
await emailSignupMitra({
|
|
159
|
+
name: 'João Silva',
|
|
160
|
+
email: 'joao@email.com',
|
|
161
|
+
password: 'minhasenha123'
|
|
162
|
+
});
|
|
163
|
+
// Não retorna token — o próximo passo é verificar o código
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
#### emailVerifyCodeMitra
|
|
167
|
+
|
|
168
|
+
Verifica o código de 6 dígitos e faz login automático. Retorna `LoginResponse` e auto-configura o SDK.
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
import { emailVerifyCodeMitra } from 'mitra-interactions-sdk';
|
|
172
|
+
|
|
173
|
+
const session = await emailVerifyCodeMitra({
|
|
174
|
+
email: 'joao@email.com',
|
|
175
|
+
code: '123456',
|
|
176
|
+
password: 'minhasenha123' // Necessário para login automático após verificação
|
|
177
|
+
});
|
|
178
|
+
// session: { token, baseURL, integrationURL? }
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
#### emailResendCodeMitra
|
|
182
|
+
|
|
183
|
+
Reenvia o código de verificação para o email.
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
import { emailResendCodeMitra } from 'mitra-interactions-sdk';
|
|
187
|
+
|
|
188
|
+
await emailResendCodeMitra({ email: 'joao@email.com' });
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
#### emailLoginMitra
|
|
192
|
+
|
|
193
|
+
Login direto com email e senha. Retorna `LoginResponse` e auto-configura o SDK.
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
import { emailLoginMitra } from 'mitra-interactions-sdk';
|
|
197
|
+
|
|
198
|
+
const session = await emailLoginMitra({
|
|
199
|
+
email: 'joao@email.com',
|
|
200
|
+
password: 'minhasenha123'
|
|
201
|
+
});
|
|
202
|
+
// session: { token, baseURL, integrationURL? }
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
#### Fluxo completo de signup com email
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
// 1. Criar conta
|
|
209
|
+
await emailSignupMitra({ name: 'João', email, password });
|
|
210
|
+
|
|
211
|
+
// 2. Usuário recebe código por email e digita na tela
|
|
212
|
+
const session = await emailVerifyCodeMitra({ email, code: '123456', password });
|
|
213
|
+
|
|
214
|
+
// 3. SDK já está configurado — pode chamar qualquer método
|
|
215
|
+
await executeDbActionMitra({ dbActionId: 1 });
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
> **Nota:** `authUrl` e `projectId` são opcionais em todas as funções de email se já foram configurados via `configureSdkMitra()`.
|
|
219
|
+
|
|
147
220
|
## Métodos Disponíveis
|
|
148
221
|
|
|
149
222
|
### executeDbActionMitra
|
|
@@ -397,6 +470,11 @@ import type {
|
|
|
397
470
|
// Login
|
|
398
471
|
LoginOptions,
|
|
399
472
|
LoginResponse,
|
|
473
|
+
// Email Auth
|
|
474
|
+
EmailSignupOptions,
|
|
475
|
+
EmailLoginOptions,
|
|
476
|
+
EmailVerifyCodeOptions,
|
|
477
|
+
EmailResendCodeOptions,
|
|
400
478
|
// Options
|
|
401
479
|
ExecuteDbActionOptions,
|
|
402
480
|
ExecuteServerFunctionOptions,
|
package/dist/index.d.mts
CHANGED
|
@@ -23,6 +23,48 @@ interface LoginResponse {
|
|
|
23
23
|
/** URL do serviço de integrações (opcional) */
|
|
24
24
|
integrationURL?: string;
|
|
25
25
|
}
|
|
26
|
+
interface EmailSignupOptions {
|
|
27
|
+
/** URL da página de auth (ex: https://validacao.mitralab.io/sdk-auth/). Opcional se já configurado via configureSdkMitra. */
|
|
28
|
+
authUrl?: string;
|
|
29
|
+
/** ID do projeto. Opcional se já configurado via configureSdkMitra. */
|
|
30
|
+
projectId?: number;
|
|
31
|
+
/** Nome completo do usuário */
|
|
32
|
+
name: string;
|
|
33
|
+
/** Email do usuário */
|
|
34
|
+
email: string;
|
|
35
|
+
/** Senha */
|
|
36
|
+
password: string;
|
|
37
|
+
}
|
|
38
|
+
interface EmailLoginOptions {
|
|
39
|
+
/** URL da página de auth (ex: https://validacao.mitralab.io/sdk-auth/). Opcional se já configurado via configureSdkMitra. */
|
|
40
|
+
authUrl?: string;
|
|
41
|
+
/** ID do projeto. Opcional se já configurado via configureSdkMitra. */
|
|
42
|
+
projectId?: number;
|
|
43
|
+
/** Email do usuário */
|
|
44
|
+
email: string;
|
|
45
|
+
/** Senha */
|
|
46
|
+
password: string;
|
|
47
|
+
}
|
|
48
|
+
interface EmailVerifyCodeOptions {
|
|
49
|
+
/** URL da página de auth. Opcional se já configurado via configureSdkMitra. */
|
|
50
|
+
authUrl?: string;
|
|
51
|
+
/** ID do projeto. Opcional se já configurado via configureSdkMitra. */
|
|
52
|
+
projectId?: number;
|
|
53
|
+
/** Email do usuário */
|
|
54
|
+
email: string;
|
|
55
|
+
/** Código de verificação de 6 dígitos */
|
|
56
|
+
code: string;
|
|
57
|
+
/** Senha do usuário (necessário para login automático após verificação) */
|
|
58
|
+
password: string;
|
|
59
|
+
}
|
|
60
|
+
interface EmailResendCodeOptions {
|
|
61
|
+
/** URL da página de auth. Opcional se já configurado via configureSdkMitra. */
|
|
62
|
+
authUrl?: string;
|
|
63
|
+
/** ID do projeto. Opcional se já configurado via configureSdkMitra. */
|
|
64
|
+
projectId?: number;
|
|
65
|
+
/** Email do usuário */
|
|
66
|
+
email: string;
|
|
67
|
+
}
|
|
26
68
|
interface RunQueryOptions {
|
|
27
69
|
/** ID do projeto (opcional se já configurado via configureSdkMitra) */
|
|
28
70
|
projectId?: number;
|
|
@@ -381,6 +423,29 @@ declare function handleAuthRedirect(): LoginResponse | null;
|
|
|
381
423
|
* Se já houver um refresh em andamento, reaproveita a mesma promise.
|
|
382
424
|
*/
|
|
383
425
|
declare function refreshTokenSilently(authUrl: string, projectId: number): Promise<LoginResponse>;
|
|
426
|
+
/**
|
|
427
|
+
* Cria conta via email usando iframe silencioso.
|
|
428
|
+
* Após sucesso, o usuário recebe um código de verificação por email.
|
|
429
|
+
* Fluxo: emailSignupMitra → emailVerifyCodeMitra → emailLoginMitra
|
|
430
|
+
*/
|
|
431
|
+
declare function emailSignupMitra(options: EmailSignupOptions): Promise<void>;
|
|
432
|
+
/**
|
|
433
|
+
* Verifica o código de 6 dígitos enviado por email após signup.
|
|
434
|
+
* Após verificação, faz login automático e retorna LoginResponse.
|
|
435
|
+
* Auto-configura o SDK após sucesso.
|
|
436
|
+
*/
|
|
437
|
+
declare function emailVerifyCodeMitra(options: EmailVerifyCodeOptions): Promise<LoginResponse>;
|
|
438
|
+
/**
|
|
439
|
+
* Reenvia o código de verificação para o email.
|
|
440
|
+
*/
|
|
441
|
+
declare function emailResendCodeMitra(options: EmailResendCodeOptions): Promise<void>;
|
|
442
|
+
/**
|
|
443
|
+
* Login via email e senha usando iframe silencioso.
|
|
444
|
+
* O HTML de auth faz a chamada à API e resolve as credenciais do projeto.
|
|
445
|
+
* Retorna LoginResponse com token, baseURL e integrationURL.
|
|
446
|
+
* Auto-configura o SDK após sucesso.
|
|
447
|
+
*/
|
|
448
|
+
declare function emailLoginMitra(options: EmailLoginOptions): Promise<LoginResponse>;
|
|
384
449
|
|
|
385
450
|
/**
|
|
386
451
|
* Mitra Interactions SDK - Services
|
|
@@ -465,4 +530,4 @@ declare function patchRecordMitra(options: PatchRecordOptions): Promise<Record<s
|
|
|
465
530
|
declare function deleteRecordMitra(options: DeleteRecordOptions): Promise<void>;
|
|
466
531
|
declare function createRecordsBatchMitra(options: CreateRecordsBatchOptions): Promise<Record<string, any>[]>;
|
|
467
532
|
|
|
468
|
-
export { type CallIntegrationOptions, type CallIntegrationResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type DeleteRecordOptions, type ExecuteDbActionOptions, type ExecuteDbActionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetRecordOptions, type GetVariableOptions, type GetVariableResponse, type IntegrationResponse, type ListIntegrationsOptions, type ListRecordsOptions, type ListRecordsResponse, type ListVariablesOptions, type ListVariablesResponse, type LoginOptions, type LoginResponse, type MitraConfig, type MitraInstance, type PatchRecordOptions, type RunActionOptions, type RunActionResponse, type RunQueryOptions, type RunQueryResponse, type SetFileStatusOptions, type SetFileStatusResponse, type SetVariableOptions, type SetVariableResponse, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, type UploadFileOptions, type UploadFileResponse, callIntegrationMitra, configureSdkMitra, createMitraInstance, createRecordMitra, createRecordsBatchMitra, deleteRecordMitra, executeDbActionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getConfig, getRecordMitra, getVariableMitra, handleAuthRedirect, listIntegrationsMitra, listRecordsMitra, listVariablesMitra, loginMitra, loginWithEmailMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, patchRecordMitra, refreshTokenSilently, resolveProjectId, runActionMitra, runQueryMitra, setFileStatusMitra, setVariableMitra, stopServerFunctionExecutionMitra, updateRecordMitra, uploadFileLoadableMitra, uploadFilePublicMitra };
|
|
533
|
+
export { type CallIntegrationOptions, type CallIntegrationResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type DeleteRecordOptions, type EmailLoginOptions, type EmailResendCodeOptions, type EmailSignupOptions, type EmailVerifyCodeOptions, type ExecuteDbActionOptions, type ExecuteDbActionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetRecordOptions, type GetVariableOptions, type GetVariableResponse, type IntegrationResponse, type ListIntegrationsOptions, type ListRecordsOptions, type ListRecordsResponse, type ListVariablesOptions, type ListVariablesResponse, type LoginOptions, type LoginResponse, type MitraConfig, type MitraInstance, type PatchRecordOptions, type RunActionOptions, type RunActionResponse, type RunQueryOptions, type RunQueryResponse, type SetFileStatusOptions, type SetFileStatusResponse, type SetVariableOptions, type SetVariableResponse, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, type UploadFileOptions, type UploadFileResponse, callIntegrationMitra, configureSdkMitra, createMitraInstance, createRecordMitra, createRecordsBatchMitra, deleteRecordMitra, emailLoginMitra, emailResendCodeMitra, emailSignupMitra, emailVerifyCodeMitra, executeDbActionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getConfig, getRecordMitra, getVariableMitra, handleAuthRedirect, listIntegrationsMitra, listRecordsMitra, listVariablesMitra, loginMitra, loginWithEmailMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, patchRecordMitra, refreshTokenSilently, resolveProjectId, runActionMitra, runQueryMitra, setFileStatusMitra, setVariableMitra, stopServerFunctionExecutionMitra, updateRecordMitra, uploadFileLoadableMitra, uploadFilePublicMitra };
|
package/dist/index.d.ts
CHANGED
|
@@ -23,6 +23,48 @@ interface LoginResponse {
|
|
|
23
23
|
/** URL do serviço de integrações (opcional) */
|
|
24
24
|
integrationURL?: string;
|
|
25
25
|
}
|
|
26
|
+
interface EmailSignupOptions {
|
|
27
|
+
/** URL da página de auth (ex: https://validacao.mitralab.io/sdk-auth/). Opcional se já configurado via configureSdkMitra. */
|
|
28
|
+
authUrl?: string;
|
|
29
|
+
/** ID do projeto. Opcional se já configurado via configureSdkMitra. */
|
|
30
|
+
projectId?: number;
|
|
31
|
+
/** Nome completo do usuário */
|
|
32
|
+
name: string;
|
|
33
|
+
/** Email do usuário */
|
|
34
|
+
email: string;
|
|
35
|
+
/** Senha */
|
|
36
|
+
password: string;
|
|
37
|
+
}
|
|
38
|
+
interface EmailLoginOptions {
|
|
39
|
+
/** URL da página de auth (ex: https://validacao.mitralab.io/sdk-auth/). Opcional se já configurado via configureSdkMitra. */
|
|
40
|
+
authUrl?: string;
|
|
41
|
+
/** ID do projeto. Opcional se já configurado via configureSdkMitra. */
|
|
42
|
+
projectId?: number;
|
|
43
|
+
/** Email do usuário */
|
|
44
|
+
email: string;
|
|
45
|
+
/** Senha */
|
|
46
|
+
password: string;
|
|
47
|
+
}
|
|
48
|
+
interface EmailVerifyCodeOptions {
|
|
49
|
+
/** URL da página de auth. Opcional se já configurado via configureSdkMitra. */
|
|
50
|
+
authUrl?: string;
|
|
51
|
+
/** ID do projeto. Opcional se já configurado via configureSdkMitra. */
|
|
52
|
+
projectId?: number;
|
|
53
|
+
/** Email do usuário */
|
|
54
|
+
email: string;
|
|
55
|
+
/** Código de verificação de 6 dígitos */
|
|
56
|
+
code: string;
|
|
57
|
+
/** Senha do usuário (necessário para login automático após verificação) */
|
|
58
|
+
password: string;
|
|
59
|
+
}
|
|
60
|
+
interface EmailResendCodeOptions {
|
|
61
|
+
/** URL da página de auth. Opcional se já configurado via configureSdkMitra. */
|
|
62
|
+
authUrl?: string;
|
|
63
|
+
/** ID do projeto. Opcional se já configurado via configureSdkMitra. */
|
|
64
|
+
projectId?: number;
|
|
65
|
+
/** Email do usuário */
|
|
66
|
+
email: string;
|
|
67
|
+
}
|
|
26
68
|
interface RunQueryOptions {
|
|
27
69
|
/** ID do projeto (opcional se já configurado via configureSdkMitra) */
|
|
28
70
|
projectId?: number;
|
|
@@ -381,6 +423,29 @@ declare function handleAuthRedirect(): LoginResponse | null;
|
|
|
381
423
|
* Se já houver um refresh em andamento, reaproveita a mesma promise.
|
|
382
424
|
*/
|
|
383
425
|
declare function refreshTokenSilently(authUrl: string, projectId: number): Promise<LoginResponse>;
|
|
426
|
+
/**
|
|
427
|
+
* Cria conta via email usando iframe silencioso.
|
|
428
|
+
* Após sucesso, o usuário recebe um código de verificação por email.
|
|
429
|
+
* Fluxo: emailSignupMitra → emailVerifyCodeMitra → emailLoginMitra
|
|
430
|
+
*/
|
|
431
|
+
declare function emailSignupMitra(options: EmailSignupOptions): Promise<void>;
|
|
432
|
+
/**
|
|
433
|
+
* Verifica o código de 6 dígitos enviado por email após signup.
|
|
434
|
+
* Após verificação, faz login automático e retorna LoginResponse.
|
|
435
|
+
* Auto-configura o SDK após sucesso.
|
|
436
|
+
*/
|
|
437
|
+
declare function emailVerifyCodeMitra(options: EmailVerifyCodeOptions): Promise<LoginResponse>;
|
|
438
|
+
/**
|
|
439
|
+
* Reenvia o código de verificação para o email.
|
|
440
|
+
*/
|
|
441
|
+
declare function emailResendCodeMitra(options: EmailResendCodeOptions): Promise<void>;
|
|
442
|
+
/**
|
|
443
|
+
* Login via email e senha usando iframe silencioso.
|
|
444
|
+
* O HTML de auth faz a chamada à API e resolve as credenciais do projeto.
|
|
445
|
+
* Retorna LoginResponse com token, baseURL e integrationURL.
|
|
446
|
+
* Auto-configura o SDK após sucesso.
|
|
447
|
+
*/
|
|
448
|
+
declare function emailLoginMitra(options: EmailLoginOptions): Promise<LoginResponse>;
|
|
384
449
|
|
|
385
450
|
/**
|
|
386
451
|
* Mitra Interactions SDK - Services
|
|
@@ -465,4 +530,4 @@ declare function patchRecordMitra(options: PatchRecordOptions): Promise<Record<s
|
|
|
465
530
|
declare function deleteRecordMitra(options: DeleteRecordOptions): Promise<void>;
|
|
466
531
|
declare function createRecordsBatchMitra(options: CreateRecordsBatchOptions): Promise<Record<string, any>[]>;
|
|
467
532
|
|
|
468
|
-
export { type CallIntegrationOptions, type CallIntegrationResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type DeleteRecordOptions, type ExecuteDbActionOptions, type ExecuteDbActionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetRecordOptions, type GetVariableOptions, type GetVariableResponse, type IntegrationResponse, type ListIntegrationsOptions, type ListRecordsOptions, type ListRecordsResponse, type ListVariablesOptions, type ListVariablesResponse, type LoginOptions, type LoginResponse, type MitraConfig, type MitraInstance, type PatchRecordOptions, type RunActionOptions, type RunActionResponse, type RunQueryOptions, type RunQueryResponse, type SetFileStatusOptions, type SetFileStatusResponse, type SetVariableOptions, type SetVariableResponse, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, type UploadFileOptions, type UploadFileResponse, callIntegrationMitra, configureSdkMitra, createMitraInstance, createRecordMitra, createRecordsBatchMitra, deleteRecordMitra, executeDbActionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getConfig, getRecordMitra, getVariableMitra, handleAuthRedirect, listIntegrationsMitra, listRecordsMitra, listVariablesMitra, loginMitra, loginWithEmailMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, patchRecordMitra, refreshTokenSilently, resolveProjectId, runActionMitra, runQueryMitra, setFileStatusMitra, setVariableMitra, stopServerFunctionExecutionMitra, updateRecordMitra, uploadFileLoadableMitra, uploadFilePublicMitra };
|
|
533
|
+
export { type CallIntegrationOptions, type CallIntegrationResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type DeleteRecordOptions, type EmailLoginOptions, type EmailResendCodeOptions, type EmailSignupOptions, type EmailVerifyCodeOptions, type ExecuteDbActionOptions, type ExecuteDbActionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetRecordOptions, type GetVariableOptions, type GetVariableResponse, type IntegrationResponse, type ListIntegrationsOptions, type ListRecordsOptions, type ListRecordsResponse, type ListVariablesOptions, type ListVariablesResponse, type LoginOptions, type LoginResponse, type MitraConfig, type MitraInstance, type PatchRecordOptions, type RunActionOptions, type RunActionResponse, type RunQueryOptions, type RunQueryResponse, type SetFileStatusOptions, type SetFileStatusResponse, type SetVariableOptions, type SetVariableResponse, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, type UploadFileOptions, type UploadFileResponse, callIntegrationMitra, configureSdkMitra, createMitraInstance, createRecordMitra, createRecordsBatchMitra, deleteRecordMitra, emailLoginMitra, emailResendCodeMitra, emailSignupMitra, emailVerifyCodeMitra, executeDbActionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getConfig, getRecordMitra, getVariableMitra, handleAuthRedirect, listIntegrationsMitra, listRecordsMitra, listVariablesMitra, loginMitra, loginWithEmailMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, patchRecordMitra, refreshTokenSilently, resolveProjectId, runActionMitra, runQueryMitra, setFileStatusMitra, setVariableMitra, stopServerFunctionExecutionMitra, updateRecordMitra, uploadFileLoadableMitra, uploadFilePublicMitra };
|
package/dist/index.js
CHANGED
|
@@ -189,6 +189,91 @@ async function refreshTokenSilently(authUrl, projectId) {
|
|
|
189
189
|
})();
|
|
190
190
|
return _refreshPromise;
|
|
191
191
|
}
|
|
192
|
+
var SILENT_TIMEOUT_MS = 2e4;
|
|
193
|
+
var AUTH_READY_TYPE = "mitra-auth-ready";
|
|
194
|
+
var AUTH_CREDENTIALS_TYPE = "mitra-auth-credentials";
|
|
195
|
+
function openSilentAuthIframe(authUrl, projectId, credentials) {
|
|
196
|
+
return new Promise((resolve, reject) => {
|
|
197
|
+
const origin = getOriginFromUrl(authUrl);
|
|
198
|
+
const base = authUrl.endsWith("/") ? authUrl : authUrl + "/";
|
|
199
|
+
let url = `${base}?mode=silent&projectId=${encodeURIComponent(projectId)}`;
|
|
200
|
+
if (typeof window !== "undefined") {
|
|
201
|
+
url += `&originUrl=${encodeURIComponent(window.location.href)}`;
|
|
202
|
+
}
|
|
203
|
+
const iframe = document.createElement("iframe");
|
|
204
|
+
iframe.style.display = "none";
|
|
205
|
+
const timer = setTimeout(() => {
|
|
206
|
+
cleanup();
|
|
207
|
+
reject(new Error("Timeout na autentica\xE7\xE3o silenciosa"));
|
|
208
|
+
}, SILENT_TIMEOUT_MS);
|
|
209
|
+
function onMessage(event) {
|
|
210
|
+
var _a, _b, _c;
|
|
211
|
+
if (event.origin !== origin) return;
|
|
212
|
+
if (((_a = event.data) == null ? void 0 : _a.type) === AUTH_READY_TYPE) {
|
|
213
|
+
(_b = iframe.contentWindow) == null ? void 0 : _b.postMessage({
|
|
214
|
+
type: AUTH_CREDENTIALS_TYPE,
|
|
215
|
+
...credentials
|
|
216
|
+
}, origin);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (((_c = event.data) == null ? void 0 : _c.type) !== AUTH_MESSAGE_TYPE) return;
|
|
220
|
+
cleanup();
|
|
221
|
+
if (event.data.success) {
|
|
222
|
+
resolve(event.data.data);
|
|
223
|
+
} else {
|
|
224
|
+
reject(new Error(event.data.error || "Erro na autentica\xE7\xE3o"));
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
function cleanup() {
|
|
228
|
+
window.removeEventListener("message", onMessage);
|
|
229
|
+
clearTimeout(timer);
|
|
230
|
+
if (iframe.parentNode) iframe.parentNode.removeChild(iframe);
|
|
231
|
+
}
|
|
232
|
+
window.addEventListener("message", onMessage);
|
|
233
|
+
iframe.src = url;
|
|
234
|
+
document.body.appendChild(iframe);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
async function emailSignupMitra(options) {
|
|
238
|
+
const { authUrl, projectId } = resolveLoginOptions(options);
|
|
239
|
+
const result = await openSilentAuthIframe(authUrl, projectId, {
|
|
240
|
+
action: "signup",
|
|
241
|
+
name: options.name,
|
|
242
|
+
email: options.email,
|
|
243
|
+
password: options.password
|
|
244
|
+
});
|
|
245
|
+
if (!result.needsVerification) {
|
|
246
|
+
throw new Error("Resposta inesperada do signup");
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
async function emailVerifyCodeMitra(options) {
|
|
250
|
+
const { authUrl, projectId } = resolveLoginOptions(options);
|
|
251
|
+
const response = await openSilentAuthIframe(authUrl, projectId, {
|
|
252
|
+
action: "verifyCode",
|
|
253
|
+
email: options.email,
|
|
254
|
+
code: options.code,
|
|
255
|
+
password: options.password
|
|
256
|
+
});
|
|
257
|
+
autoConfigureFromLogin(response, authUrl, projectId);
|
|
258
|
+
return response;
|
|
259
|
+
}
|
|
260
|
+
async function emailResendCodeMitra(options) {
|
|
261
|
+
const { authUrl, projectId } = resolveLoginOptions(options);
|
|
262
|
+
await openSilentAuthIframe(authUrl, projectId, {
|
|
263
|
+
action: "resendCode",
|
|
264
|
+
email: options.email
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
async function emailLoginMitra(options) {
|
|
268
|
+
const { authUrl, projectId } = resolveLoginOptions(options);
|
|
269
|
+
const response = await openSilentAuthIframe(authUrl, projectId, {
|
|
270
|
+
action: "login",
|
|
271
|
+
email: options.email,
|
|
272
|
+
password: options.password
|
|
273
|
+
});
|
|
274
|
+
autoConfigureFromLogin(response, authUrl, projectId);
|
|
275
|
+
return response;
|
|
276
|
+
}
|
|
192
277
|
|
|
193
278
|
// src/instance.ts
|
|
194
279
|
function formatToken(token) {
|
|
@@ -232,8 +317,31 @@ function createMitraInstance(initialConfig) {
|
|
|
232
317
|
return data;
|
|
233
318
|
}
|
|
234
319
|
async function tryRefreshToken2() {
|
|
235
|
-
|
|
236
|
-
if (
|
|
320
|
+
var _a2, _b;
|
|
321
|
+
if (_config.projectId == null) return false;
|
|
322
|
+
try {
|
|
323
|
+
const baseURL = _config.baseURL.replace(/\/+$/, "");
|
|
324
|
+
const resp = await getFetch()(`${baseURL}/mitraspace/project/refreshedToken/${_config.projectId}`, {
|
|
325
|
+
method: "GET",
|
|
326
|
+
headers: { "Authorization": formatToken(_config.token) }
|
|
327
|
+
});
|
|
328
|
+
if (resp.ok) {
|
|
329
|
+
const data = await resp.json();
|
|
330
|
+
if (data.token) {
|
|
331
|
+
const newToken = data.token.startsWith("Bearer ") ? data.token : `Bearer ${data.token}`;
|
|
332
|
+
const session = {
|
|
333
|
+
token: newToken,
|
|
334
|
+
baseURL: ((_a2 = data.merge) == null ? void 0 : _a2.backURL) || _config.baseURL,
|
|
335
|
+
...((_b = data.merge) == null ? void 0 : _b.integrationURL) ? { integrationURL: data.merge.integrationURL } : {}
|
|
336
|
+
};
|
|
337
|
+
_config = { ..._config, token: session.token };
|
|
338
|
+
if (_config.onTokenRefresh) _config.onTokenRefresh(session);
|
|
339
|
+
return true;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
} catch (e) {
|
|
343
|
+
}
|
|
344
|
+
if (!_config.authUrl || typeof window === "undefined") return false;
|
|
237
345
|
try {
|
|
238
346
|
const session = await refreshTokenSilently(_config.authUrl, _config.projectId);
|
|
239
347
|
_config = { ..._config, token: session.token };
|
|
@@ -498,9 +606,32 @@ function buildUrl(endpoint, params) {
|
|
|
498
606
|
return url;
|
|
499
607
|
}
|
|
500
608
|
async function tryRefreshToken() {
|
|
609
|
+
var _a, _b;
|
|
501
610
|
const config = getConfig();
|
|
502
|
-
if (
|
|
503
|
-
|
|
611
|
+
if (config.projectId == null) return false;
|
|
612
|
+
try {
|
|
613
|
+
const baseURL = config.baseURL.replace(/\/+$/, "");
|
|
614
|
+
const resp = await getFetch2()(`${baseURL}/mitraspace/project/refreshedToken/${config.projectId}`, {
|
|
615
|
+
method: "GET",
|
|
616
|
+
headers: { "Authorization": formatToken2(config.token) }
|
|
617
|
+
});
|
|
618
|
+
if (resp.ok) {
|
|
619
|
+
const data = await resp.json();
|
|
620
|
+
if (data.token) {
|
|
621
|
+
const newToken = data.token.startsWith("Bearer ") ? data.token : `Bearer ${data.token}`;
|
|
622
|
+
const session = {
|
|
623
|
+
token: newToken,
|
|
624
|
+
baseURL: ((_a = data.merge) == null ? void 0 : _a.backURL) || config.baseURL,
|
|
625
|
+
...((_b = data.merge) == null ? void 0 : _b.integrationURL) ? { integrationURL: data.merge.integrationURL } : {}
|
|
626
|
+
};
|
|
627
|
+
updateGlobalToken(session.token);
|
|
628
|
+
if (config.onTokenRefresh) config.onTokenRefresh(session);
|
|
629
|
+
return true;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
} catch (e) {
|
|
633
|
+
}
|
|
634
|
+
if (!config.authUrl || typeof window === "undefined") return false;
|
|
504
635
|
try {
|
|
505
636
|
const session = await refreshTokenSilently(config.authUrl, config.projectId);
|
|
506
637
|
updateGlobalToken(session.token);
|
|
@@ -792,6 +923,10 @@ exports.createMitraInstance = createMitraInstance;
|
|
|
792
923
|
exports.createRecordMitra = createRecordMitra;
|
|
793
924
|
exports.createRecordsBatchMitra = createRecordsBatchMitra;
|
|
794
925
|
exports.deleteRecordMitra = deleteRecordMitra;
|
|
926
|
+
exports.emailLoginMitra = emailLoginMitra;
|
|
927
|
+
exports.emailResendCodeMitra = emailResendCodeMitra;
|
|
928
|
+
exports.emailSignupMitra = emailSignupMitra;
|
|
929
|
+
exports.emailVerifyCodeMitra = emailVerifyCodeMitra;
|
|
795
930
|
exports.executeDbActionMitra = executeDbActionMitra;
|
|
796
931
|
exports.executeServerFunctionAsyncMitra = executeServerFunctionAsyncMitra;
|
|
797
932
|
exports.executeServerFunctionMitra = executeServerFunctionMitra;
|