mitra-interactions-sdk 1.0.29 → 1.0.31
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 +124 -20
- package/dist/index.d.mts +33 -25
- package/dist/index.d.ts +33 -25
- package/dist/index.js +231 -189
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +230 -190
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,45 +21,129 @@ Antes de usar qualquer função, configure o SDK com seu token da plataforma Mit
|
|
|
21
21
|
```typescript
|
|
22
22
|
import { configureSdkMitra } from 'mitra-interactions-sdk';
|
|
23
23
|
|
|
24
|
-
configureSdkMitra({
|
|
24
|
+
const instance = configureSdkMitra({
|
|
25
25
|
baseURL: process.env.MITRA_BASE_URL || 'https://api.mitra.com',
|
|
26
|
-
token: process.env.MITRA_TOKEN
|
|
26
|
+
token: process.env.MITRA_TOKEN!,
|
|
27
|
+
authUrl: 'https://coder.mitralab.io/sdk-auth/', // Opcional — necessário para login e token refresh
|
|
28
|
+
projectId: 123, // Opcional — se informado, torna projectId opcional em TODOS os métodos
|
|
29
|
+
integrationURL: 'https://api0.mitraecp.com:1003', // Opcional — necessário para integrações
|
|
30
|
+
onTokenRefresh: (session) => { // Opcional — chamado quando o token é renovado automaticamente
|
|
31
|
+
localStorage.setItem('mitra_session', JSON.stringify(session));
|
|
32
|
+
}
|
|
27
33
|
});
|
|
28
34
|
```
|
|
29
35
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
> **`projectId` global:** Se você passar `projectId` no `configureSdkMitra`, ele será usado como fallback em **todos** os métodos do SDK. Assim, não é necessário passar `projectId` em cada chamada individual — basta configurar uma vez.
|
|
37
|
+
|
|
38
|
+
`configureSdkMitra` retorna uma `MitraInstance` que também pode ser usada diretamente:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
await instance.executeDbAction({ dbActionId: 456 }); // projectId já vem do configureSdkMitra
|
|
34
42
|
```
|
|
35
43
|
|
|
36
44
|
## Autenticação (Login)
|
|
37
45
|
|
|
38
|
-
Login via popup seguro hospedado no domínio Mitra. Credenciais nunca passam pelo código do desenvolvedor. O SDK é **auto-configurado** após o login.
|
|
46
|
+
Login via popup ou redirect seguro hospedado no domínio Mitra. Credenciais nunca passam pelo código do desenvolvedor. O SDK é **auto-configurado** após o login.
|
|
47
|
+
|
|
48
|
+
> **Nota:** `authUrl` e `projectId` são **obrigatórios** para login. Porém, se já foram passados no `configureSdkMitra()`, não é necessário repeti-los — o SDK usa os valores configurados como fallback.
|
|
49
|
+
|
|
50
|
+
### Login via Popup (padrão)
|
|
39
51
|
|
|
40
52
|
```typescript
|
|
41
53
|
import { loginMitra } from 'mitra-interactions-sdk';
|
|
42
54
|
|
|
43
|
-
//
|
|
55
|
+
// Primeira vez — sem configureSdkMitra: authUrl e projectId são obrigatórios
|
|
44
56
|
const result = await loginMitra('email', {
|
|
45
|
-
authUrl: 'https://
|
|
57
|
+
authUrl: 'https://coder.mitralab.io/sdk-auth/',
|
|
46
58
|
projectId: 123
|
|
47
59
|
});
|
|
48
60
|
|
|
49
|
-
//
|
|
50
|
-
const result = await loginMitra('google'
|
|
51
|
-
|
|
52
|
-
|
|
61
|
+
// Se já chamou configureSdkMitra({ authUrl, projectId }), basta:
|
|
62
|
+
const result = await loginMitra('google');
|
|
63
|
+
const result = await loginMitra('microsoft');
|
|
64
|
+
|
|
65
|
+
// result: { token, baseURL, integrationURL? }
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Login via Redirect
|
|
69
|
+
|
|
70
|
+
Navega o usuário para a página de auth. Após o login, redireciona de volta com token nos query params.
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { loginMitra, handleAuthRedirect } from 'mitra-interactions-sdk';
|
|
74
|
+
|
|
75
|
+
// Iniciar login — o navegador navega para fora da página
|
|
76
|
+
await loginMitra('google', {
|
|
77
|
+
mode: 'redirect',
|
|
78
|
+
returnTo: '/dashboard' // Opcional — URL de retorno após login (default: página atual). Só funciona com mode 'redirect'.
|
|
53
79
|
});
|
|
80
|
+
```
|
|
54
81
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
82
|
+
### Fluxo de Criar Conta
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
// create funciona tanto em popup quanto redirect
|
|
86
|
+
await loginMitra('email', { create: true });
|
|
87
|
+
|
|
88
|
+
await loginMitra('email', {
|
|
89
|
+
mode: 'redirect',
|
|
90
|
+
create: true,
|
|
91
|
+
returnTo: '/onboarding'
|
|
59
92
|
});
|
|
93
|
+
```
|
|
60
94
|
|
|
61
|
-
|
|
62
|
-
|
|
95
|
+
### Processar Retorno do Redirect
|
|
96
|
+
|
|
97
|
+
Após o redirect, a página de destino deve chamar `handleAuthRedirect()` para capturar o token:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { handleAuthRedirect, configureSdkMitra } from 'mitra-interactions-sdk';
|
|
101
|
+
|
|
102
|
+
// No mounted/onLoad da página de retorno
|
|
103
|
+
const session = handleAuthRedirect();
|
|
104
|
+
if (session) {
|
|
105
|
+
// Login OK — session: { token, baseURL, integrationURL? }
|
|
106
|
+
configureSdkMitra({
|
|
107
|
+
baseURL: session.baseURL,
|
|
108
|
+
token: session.token,
|
|
109
|
+
integrationURL: session.integrationURL
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Token Refresh Automático
|
|
115
|
+
|
|
116
|
+
Quando qualquer requisição retorna **403**, o SDK tenta renovar o token automaticamente via iframe invisível (usa o cookie de sessão do provider). Se o refresh funcionar, a requisição é retentada com o novo token — transparente para o desenvolvedor.
|
|
117
|
+
|
|
118
|
+
O callback `onTokenRefresh` é chamado após renovação bem-sucedida:
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
configureSdkMitra({
|
|
122
|
+
baseURL: '...',
|
|
123
|
+
token: '...',
|
|
124
|
+
authUrl: 'https://coder.mitralab.io/sdk-auth/',
|
|
125
|
+
projectId: 123,
|
|
126
|
+
onTokenRefresh: (session) => {
|
|
127
|
+
// Atualiza o token salvo (ex: localStorage, store, etc.)
|
|
128
|
+
localStorage.setItem('mitra_token', session.token);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Funções de Login Individuais
|
|
134
|
+
|
|
135
|
+
Também disponíveis como funções separadas:
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import {
|
|
139
|
+
loginWithEmailMitra,
|
|
140
|
+
loginWithGoogleMitra,
|
|
141
|
+
loginWithMicrosoftMitra
|
|
142
|
+
} from 'mitra-interactions-sdk';
|
|
143
|
+
|
|
144
|
+
await loginWithEmailMitra({ mode: 'redirect', create: true });
|
|
145
|
+
await loginWithGoogleMitra();
|
|
146
|
+
await loginWithMicrosoftMitra({ mode: 'popup' });
|
|
63
147
|
```
|
|
64
148
|
|
|
65
149
|
## Métodos Disponíveis
|
|
@@ -142,7 +226,25 @@ Lista as integrações configuradas no projeto.
|
|
|
142
226
|
import { listIntegrationsMitra } from 'mitra-interactions-sdk';
|
|
143
227
|
|
|
144
228
|
const integrations = await listIntegrationsMitra({ projectId: 123 });
|
|
145
|
-
// result: IntegrationResponse[] — [{ id
|
|
229
|
+
// result: IntegrationResponse[] — [{ id, projectId, name, slug, blueprintId, blueprintType, authType, credentials, status, lastCheckedAt, createdAt, updatedAt }]
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
#### callIntegrationMitra
|
|
233
|
+
|
|
234
|
+
Chama uma integração configurada, delegando a requisição ao serviço externo.
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
import { callIntegrationMitra } from 'mitra-interactions-sdk';
|
|
238
|
+
|
|
239
|
+
const result = await callIntegrationMitra({
|
|
240
|
+
projectId: 123,
|
|
241
|
+
connection: 'meu-erp', // Slug da integração
|
|
242
|
+
method: 'GET', // GET, POST, PUT, DELETE
|
|
243
|
+
endpoint: '/api/v1/pedidos', // Path no serviço externo (opcional)
|
|
244
|
+
params: { status: 'ativo' }, // Query params (opcional)
|
|
245
|
+
body: { nome: 'Teste' } // Body para POST/PUT (opcional)
|
|
246
|
+
});
|
|
247
|
+
// result: { statusCode: number, body: any }
|
|
146
248
|
```
|
|
147
249
|
|
|
148
250
|
### setFileStatusMitra
|
|
@@ -280,6 +382,7 @@ import type {
|
|
|
280
382
|
ExecuteServerFunctionOptions,
|
|
281
383
|
ExecuteServerFunctionAsyncOptions,
|
|
282
384
|
ListIntegrationsOptions,
|
|
385
|
+
CallIntegrationOptions,
|
|
283
386
|
StopServerFunctionExecutionOptions,
|
|
284
387
|
SetFileStatusOptions,
|
|
285
388
|
SetVariableOptions,
|
|
@@ -303,6 +406,7 @@ import type {
|
|
|
303
406
|
ExecuteServerFunctionResponse,
|
|
304
407
|
ExecuteServerFunctionAsyncResponse,
|
|
305
408
|
IntegrationResponse,
|
|
409
|
+
CallIntegrationResponse,
|
|
306
410
|
StopServerFunctionExecutionResponse,
|
|
307
411
|
ListRecordsResponse
|
|
308
412
|
} from 'mitra-interactions-sdk';
|
package/dist/index.d.mts
CHANGED
|
@@ -2,10 +2,16 @@
|
|
|
2
2
|
* Mitra Interactions SDK - Types
|
|
3
3
|
*/
|
|
4
4
|
interface LoginOptions {
|
|
5
|
-
/** URL da página de autenticação Mitra (ex: https://
|
|
5
|
+
/** URL da página de autenticação Mitra (ex: https://coder.mitralab.io/sdk-auth/). Opcional se já configurado via configureSdkMitra. */
|
|
6
6
|
authUrl?: string;
|
|
7
7
|
/** ID do projeto. Opcional se já configurado via configureSdkMitra. */
|
|
8
8
|
projectId?: number;
|
|
9
|
+
/** Modo de login: 'popup' (default) abre popup, 'redirect' navega para a página de auth. */
|
|
10
|
+
mode?: 'popup' | 'redirect';
|
|
11
|
+
/** URL de retorno após login com mode 'redirect'. A página de auth redirecionará de volta para esta URL com token nos query params. */
|
|
12
|
+
returnTo?: string;
|
|
13
|
+
/** Se true, abre o fluxo de criar conta em vez de login. */
|
|
14
|
+
create?: boolean;
|
|
9
15
|
}
|
|
10
16
|
interface LoginResponse {
|
|
11
17
|
/** Token JWT (já com prefixo Bearer) */
|
|
@@ -264,10 +270,6 @@ interface StopServerFunctionExecutionResponse {
|
|
|
264
270
|
|
|
265
271
|
interface MitraInstance {
|
|
266
272
|
readonly config: MitraConfig;
|
|
267
|
-
login(method: 'email' | 'google' | 'microsoft', options?: LoginOptions): Promise<MitraInstance>;
|
|
268
|
-
loginWithEmail(options?: LoginOptions): Promise<MitraInstance>;
|
|
269
|
-
loginWithGoogle(options?: LoginOptions): Promise<MitraInstance>;
|
|
270
|
-
loginWithMicrosoft(options?: LoginOptions): Promise<MitraInstance>;
|
|
271
273
|
runQuery(options: RunQueryOptions): Promise<RunQueryResponse>;
|
|
272
274
|
executeDbAction(options: ExecuteDbActionOptions): Promise<ExecuteDbActionResponse>;
|
|
273
275
|
setFileStatus(options: SetFileStatusOptions): Promise<SetFileStatusResponse>;
|
|
@@ -290,10 +292,6 @@ interface MitraInstance {
|
|
|
290
292
|
}
|
|
291
293
|
declare function createMitraInstance(initialConfig: Partial<MitraConfig>): MitraInstance;
|
|
292
294
|
|
|
293
|
-
/**
|
|
294
|
-
* Mitra Interactions SDK - Configuração
|
|
295
|
-
*/
|
|
296
|
-
|
|
297
295
|
interface MitraConfig {
|
|
298
296
|
/** URL base da API (ex: https://api.mitra.com) */
|
|
299
297
|
baseURL: string;
|
|
@@ -301,10 +299,12 @@ interface MitraConfig {
|
|
|
301
299
|
token: string;
|
|
302
300
|
/** URL base do serviço de integrações (ex: https://api0.mitraecp.com:1003) */
|
|
303
301
|
integrationURL?: string;
|
|
304
|
-
/** URL da página de autenticação Mitra (ex: https://coder.mitralab.io/auth/) */
|
|
302
|
+
/** URL da página de autenticação Mitra (ex: https://coder.mitralab.io/sdk-auth/) */
|
|
305
303
|
authUrl?: string;
|
|
306
304
|
/** ID do projeto (usado como fallback nos métodos de login e serviços) */
|
|
307
305
|
projectId?: number;
|
|
306
|
+
/** Callback chamado quando o token é renovado automaticamente (após 401/403). Recebe a nova sessão. */
|
|
307
|
+
onTokenRefresh?: (session: LoginResponse) => void;
|
|
308
308
|
}
|
|
309
309
|
/**
|
|
310
310
|
* Configura o SDK globalmente e retorna uma instância configurada.
|
|
@@ -327,31 +327,39 @@ declare function resolveProjectId(projectId?: number): number;
|
|
|
327
327
|
*/
|
|
328
328
|
|
|
329
329
|
/**
|
|
330
|
-
* Login com email e senha via popup seguro Mitra.
|
|
331
|
-
*
|
|
332
|
-
* authUrl e projectId são opcionais se já configurados via configureSdkMitra().
|
|
333
|
-
* Se passados, sobrescrevem os valores salvos.
|
|
330
|
+
* Login com email e senha via popup/redirect seguro Mitra.
|
|
334
331
|
*/
|
|
335
332
|
declare function loginWithEmailMitra(options?: LoginOptions): Promise<LoginResponse>;
|
|
336
333
|
/**
|
|
337
|
-
* Login com Google via popup seguro Mitra.
|
|
338
|
-
*
|
|
339
|
-
* authUrl e projectId são opcionais se já configurados via configureSdkMitra().
|
|
340
|
-
* Se passados, sobrescrevem os valores salvos.
|
|
334
|
+
* Login com Google via popup/redirect seguro Mitra.
|
|
341
335
|
*/
|
|
342
336
|
declare function loginWithGoogleMitra(options?: LoginOptions): Promise<LoginResponse>;
|
|
343
337
|
/**
|
|
344
|
-
* Login com Microsoft via popup seguro Mitra.
|
|
345
|
-
*
|
|
346
|
-
* authUrl e projectId são opcionais se já configurados via configureSdkMitra().
|
|
347
|
-
* Se passados, sobrescrevem os valores salvos.
|
|
338
|
+
* Login com Microsoft via popup/redirect seguro Mitra.
|
|
348
339
|
*/
|
|
349
340
|
declare function loginWithMicrosoftMitra(options?: LoginOptions): Promise<LoginResponse>;
|
|
350
341
|
/**
|
|
351
|
-
* Login genérico via popup seguro Mitra.
|
|
352
|
-
* Recebe o método de login como string e delega para a função correspondente.
|
|
342
|
+
* Login genérico via popup/redirect seguro Mitra.
|
|
353
343
|
*/
|
|
354
344
|
declare function loginMitra(method: 'email' | 'google' | 'microsoft', options?: LoginOptions): Promise<LoginResponse>;
|
|
345
|
+
/**
|
|
346
|
+
* Processa o retorno de um login com mode 'redirect'.
|
|
347
|
+
*
|
|
348
|
+
* Após o redirect, a página de auth redireciona de volta com query params:
|
|
349
|
+
* ?tokenMitra={token}&backURLMitra={baseURL}&integrationURLMitra={integrationURL}
|
|
350
|
+
*
|
|
351
|
+
* Esta função:
|
|
352
|
+
* - Lê os query params da URL atual
|
|
353
|
+
* - Se `tokenMitra=error`, lança erro
|
|
354
|
+
* - Se encontrou tokens, limpa a URL e retorna LoginResponse
|
|
355
|
+
* - Se não encontrou nada, retorna null
|
|
356
|
+
*/
|
|
357
|
+
declare function handleAuthRedirect(): LoginResponse | null;
|
|
358
|
+
/**
|
|
359
|
+
* Renova o token silenciosamente via iframe invisível.
|
|
360
|
+
* Se já houver um refresh em andamento, reaproveita a mesma promise.
|
|
361
|
+
*/
|
|
362
|
+
declare function refreshTokenSilently(authUrl: string, projectId: number): Promise<LoginResponse>;
|
|
355
363
|
|
|
356
364
|
/**
|
|
357
365
|
* Mitra Interactions SDK - Services
|
|
@@ -426,4 +434,4 @@ declare function patchRecordMitra(options: PatchRecordOptions): Promise<Record<s
|
|
|
426
434
|
declare function deleteRecordMitra(options: DeleteRecordOptions): Promise<void>;
|
|
427
435
|
declare function createRecordsBatchMitra(options: CreateRecordsBatchOptions): Promise<Record<string, any>[]>;
|
|
428
436
|
|
|
429
|
-
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, callIntegrationMitra, configureSdkMitra, createMitraInstance, createRecordMitra, createRecordsBatchMitra, deleteRecordMitra, executeDbActionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getConfig, getRecordMitra, getVariableMitra, listIntegrationsMitra, listRecordsMitra, listVariablesMitra, loginMitra, loginWithEmailMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, patchRecordMitra, resolveProjectId, runActionMitra, runQueryMitra, setFileStatusMitra, setVariableMitra, stopServerFunctionExecutionMitra, updateRecordMitra };
|
|
437
|
+
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, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,10 +2,16 @@
|
|
|
2
2
|
* Mitra Interactions SDK - Types
|
|
3
3
|
*/
|
|
4
4
|
interface LoginOptions {
|
|
5
|
-
/** URL da página de autenticação Mitra (ex: https://
|
|
5
|
+
/** URL da página de autenticação Mitra (ex: https://coder.mitralab.io/sdk-auth/). Opcional se já configurado via configureSdkMitra. */
|
|
6
6
|
authUrl?: string;
|
|
7
7
|
/** ID do projeto. Opcional se já configurado via configureSdkMitra. */
|
|
8
8
|
projectId?: number;
|
|
9
|
+
/** Modo de login: 'popup' (default) abre popup, 'redirect' navega para a página de auth. */
|
|
10
|
+
mode?: 'popup' | 'redirect';
|
|
11
|
+
/** URL de retorno após login com mode 'redirect'. A página de auth redirecionará de volta para esta URL com token nos query params. */
|
|
12
|
+
returnTo?: string;
|
|
13
|
+
/** Se true, abre o fluxo de criar conta em vez de login. */
|
|
14
|
+
create?: boolean;
|
|
9
15
|
}
|
|
10
16
|
interface LoginResponse {
|
|
11
17
|
/** Token JWT (já com prefixo Bearer) */
|
|
@@ -264,10 +270,6 @@ interface StopServerFunctionExecutionResponse {
|
|
|
264
270
|
|
|
265
271
|
interface MitraInstance {
|
|
266
272
|
readonly config: MitraConfig;
|
|
267
|
-
login(method: 'email' | 'google' | 'microsoft', options?: LoginOptions): Promise<MitraInstance>;
|
|
268
|
-
loginWithEmail(options?: LoginOptions): Promise<MitraInstance>;
|
|
269
|
-
loginWithGoogle(options?: LoginOptions): Promise<MitraInstance>;
|
|
270
|
-
loginWithMicrosoft(options?: LoginOptions): Promise<MitraInstance>;
|
|
271
273
|
runQuery(options: RunQueryOptions): Promise<RunQueryResponse>;
|
|
272
274
|
executeDbAction(options: ExecuteDbActionOptions): Promise<ExecuteDbActionResponse>;
|
|
273
275
|
setFileStatus(options: SetFileStatusOptions): Promise<SetFileStatusResponse>;
|
|
@@ -290,10 +292,6 @@ interface MitraInstance {
|
|
|
290
292
|
}
|
|
291
293
|
declare function createMitraInstance(initialConfig: Partial<MitraConfig>): MitraInstance;
|
|
292
294
|
|
|
293
|
-
/**
|
|
294
|
-
* Mitra Interactions SDK - Configuração
|
|
295
|
-
*/
|
|
296
|
-
|
|
297
295
|
interface MitraConfig {
|
|
298
296
|
/** URL base da API (ex: https://api.mitra.com) */
|
|
299
297
|
baseURL: string;
|
|
@@ -301,10 +299,12 @@ interface MitraConfig {
|
|
|
301
299
|
token: string;
|
|
302
300
|
/** URL base do serviço de integrações (ex: https://api0.mitraecp.com:1003) */
|
|
303
301
|
integrationURL?: string;
|
|
304
|
-
/** URL da página de autenticação Mitra (ex: https://coder.mitralab.io/auth/) */
|
|
302
|
+
/** URL da página de autenticação Mitra (ex: https://coder.mitralab.io/sdk-auth/) */
|
|
305
303
|
authUrl?: string;
|
|
306
304
|
/** ID do projeto (usado como fallback nos métodos de login e serviços) */
|
|
307
305
|
projectId?: number;
|
|
306
|
+
/** Callback chamado quando o token é renovado automaticamente (após 401/403). Recebe a nova sessão. */
|
|
307
|
+
onTokenRefresh?: (session: LoginResponse) => void;
|
|
308
308
|
}
|
|
309
309
|
/**
|
|
310
310
|
* Configura o SDK globalmente e retorna uma instância configurada.
|
|
@@ -327,31 +327,39 @@ declare function resolveProjectId(projectId?: number): number;
|
|
|
327
327
|
*/
|
|
328
328
|
|
|
329
329
|
/**
|
|
330
|
-
* Login com email e senha via popup seguro Mitra.
|
|
331
|
-
*
|
|
332
|
-
* authUrl e projectId são opcionais se já configurados via configureSdkMitra().
|
|
333
|
-
* Se passados, sobrescrevem os valores salvos.
|
|
330
|
+
* Login com email e senha via popup/redirect seguro Mitra.
|
|
334
331
|
*/
|
|
335
332
|
declare function loginWithEmailMitra(options?: LoginOptions): Promise<LoginResponse>;
|
|
336
333
|
/**
|
|
337
|
-
* Login com Google via popup seguro Mitra.
|
|
338
|
-
*
|
|
339
|
-
* authUrl e projectId são opcionais se já configurados via configureSdkMitra().
|
|
340
|
-
* Se passados, sobrescrevem os valores salvos.
|
|
334
|
+
* Login com Google via popup/redirect seguro Mitra.
|
|
341
335
|
*/
|
|
342
336
|
declare function loginWithGoogleMitra(options?: LoginOptions): Promise<LoginResponse>;
|
|
343
337
|
/**
|
|
344
|
-
* Login com Microsoft via popup seguro Mitra.
|
|
345
|
-
*
|
|
346
|
-
* authUrl e projectId são opcionais se já configurados via configureSdkMitra().
|
|
347
|
-
* Se passados, sobrescrevem os valores salvos.
|
|
338
|
+
* Login com Microsoft via popup/redirect seguro Mitra.
|
|
348
339
|
*/
|
|
349
340
|
declare function loginWithMicrosoftMitra(options?: LoginOptions): Promise<LoginResponse>;
|
|
350
341
|
/**
|
|
351
|
-
* Login genérico via popup seguro Mitra.
|
|
352
|
-
* Recebe o método de login como string e delega para a função correspondente.
|
|
342
|
+
* Login genérico via popup/redirect seguro Mitra.
|
|
353
343
|
*/
|
|
354
344
|
declare function loginMitra(method: 'email' | 'google' | 'microsoft', options?: LoginOptions): Promise<LoginResponse>;
|
|
345
|
+
/**
|
|
346
|
+
* Processa o retorno de um login com mode 'redirect'.
|
|
347
|
+
*
|
|
348
|
+
* Após o redirect, a página de auth redireciona de volta com query params:
|
|
349
|
+
* ?tokenMitra={token}&backURLMitra={baseURL}&integrationURLMitra={integrationURL}
|
|
350
|
+
*
|
|
351
|
+
* Esta função:
|
|
352
|
+
* - Lê os query params da URL atual
|
|
353
|
+
* - Se `tokenMitra=error`, lança erro
|
|
354
|
+
* - Se encontrou tokens, limpa a URL e retorna LoginResponse
|
|
355
|
+
* - Se não encontrou nada, retorna null
|
|
356
|
+
*/
|
|
357
|
+
declare function handleAuthRedirect(): LoginResponse | null;
|
|
358
|
+
/**
|
|
359
|
+
* Renova o token silenciosamente via iframe invisível.
|
|
360
|
+
* Se já houver um refresh em andamento, reaproveita a mesma promise.
|
|
361
|
+
*/
|
|
362
|
+
declare function refreshTokenSilently(authUrl: string, projectId: number): Promise<LoginResponse>;
|
|
355
363
|
|
|
356
364
|
/**
|
|
357
365
|
* Mitra Interactions SDK - Services
|
|
@@ -426,4 +434,4 @@ declare function patchRecordMitra(options: PatchRecordOptions): Promise<Record<s
|
|
|
426
434
|
declare function deleteRecordMitra(options: DeleteRecordOptions): Promise<void>;
|
|
427
435
|
declare function createRecordsBatchMitra(options: CreateRecordsBatchOptions): Promise<Record<string, any>[]>;
|
|
428
436
|
|
|
429
|
-
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, callIntegrationMitra, configureSdkMitra, createMitraInstance, createRecordMitra, createRecordsBatchMitra, deleteRecordMitra, executeDbActionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getConfig, getRecordMitra, getVariableMitra, listIntegrationsMitra, listRecordsMitra, listVariablesMitra, loginMitra, loginWithEmailMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, patchRecordMitra, resolveProjectId, runActionMitra, runQueryMitra, setFileStatusMitra, setVariableMitra, stopServerFunctionExecutionMitra, updateRecordMitra };
|
|
437
|
+
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, 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 };
|