mitra-interactions-sdk 1.0.30 → 1.0.32
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 +131 -19
- package/dist/index.d.mts +62 -25
- package/dist/index.d.ts +62 -25
- package/dist/index.js +278 -189
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +275 -190
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,45 +21,113 @@ 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
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
|
+
});
|
|
63
131
|
```
|
|
64
132
|
|
|
65
133
|
## Métodos Disponíveis
|
|
@@ -142,7 +210,47 @@ Lista as integrações configuradas no projeto.
|
|
|
142
210
|
import { listIntegrationsMitra } from 'mitra-interactions-sdk';
|
|
143
211
|
|
|
144
212
|
const integrations = await listIntegrationsMitra({ projectId: 123 });
|
|
145
|
-
// result: IntegrationResponse[] — [{ id
|
|
213
|
+
// result: IntegrationResponse[] — [{ id, projectId, name, slug, blueprintId, blueprintType, authType, credentials, status, lastCheckedAt, createdAt, updatedAt }]
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
#### callIntegrationMitra
|
|
217
|
+
|
|
218
|
+
Chama uma integração configurada, delegando a requisição ao serviço externo.
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
import { callIntegrationMitra } from 'mitra-interactions-sdk';
|
|
222
|
+
|
|
223
|
+
const result = await callIntegrationMitra({
|
|
224
|
+
projectId: 123,
|
|
225
|
+
connection: 'meu-erp', // Slug da integração
|
|
226
|
+
method: 'GET', // GET, POST, PUT, DELETE
|
|
227
|
+
endpoint: '/api/v1/pedidos', // Path no serviço externo (opcional)
|
|
228
|
+
params: { status: 'ativo' }, // Query params (opcional)
|
|
229
|
+
body: { nome: 'Teste' } // Body para POST/PUT (opcional)
|
|
230
|
+
});
|
|
231
|
+
// result: { statusCode: number, body: any }
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### uploadFilePublicMitra / uploadFileLoadableMitra
|
|
235
|
+
|
|
236
|
+
Faz upload de um arquivo diretamente para a pasta PUBLIC ou LOADABLE do projeto. Usa `multipart/form-data`.
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
import { uploadFilePublicMitra, uploadFileLoadableMitra } from 'mitra-interactions-sdk';
|
|
240
|
+
|
|
241
|
+
// Upload para PUBLIC (arquivo fica acessível publicamente via URL)
|
|
242
|
+
const result = await uploadFilePublicMitra({
|
|
243
|
+
projectId: 123,
|
|
244
|
+
file: fileInput.files[0] // File ou Blob
|
|
245
|
+
});
|
|
246
|
+
// result: { status, result: { fileName, currentPath, publicUrl, message } }
|
|
247
|
+
|
|
248
|
+
// Upload para LOADABLE (arquivo disponível para carga via Spark/ETL)
|
|
249
|
+
const result2 = await uploadFileLoadableMitra({
|
|
250
|
+
projectId: 123,
|
|
251
|
+
file: myBlob
|
|
252
|
+
});
|
|
253
|
+
// result2: { status, result: { fileName, currentPath, publicUrl: null, message } }
|
|
146
254
|
```
|
|
147
255
|
|
|
148
256
|
### setFileStatusMitra
|
|
@@ -280,6 +388,8 @@ import type {
|
|
|
280
388
|
ExecuteServerFunctionOptions,
|
|
281
389
|
ExecuteServerFunctionAsyncOptions,
|
|
282
390
|
ListIntegrationsOptions,
|
|
391
|
+
CallIntegrationOptions,
|
|
392
|
+
UploadFileOptions,
|
|
283
393
|
StopServerFunctionExecutionOptions,
|
|
284
394
|
SetFileStatusOptions,
|
|
285
395
|
SetVariableOptions,
|
|
@@ -303,6 +413,8 @@ import type {
|
|
|
303
413
|
ExecuteServerFunctionResponse,
|
|
304
414
|
ExecuteServerFunctionAsyncResponse,
|
|
305
415
|
IntegrationResponse,
|
|
416
|
+
CallIntegrationResponse,
|
|
417
|
+
UploadFileResponse,
|
|
306
418
|
StopServerFunctionExecutionResponse,
|
|
307
419
|
ListRecordsResponse
|
|
308
420
|
} 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) */
|
|
@@ -163,6 +169,23 @@ interface CreateRecordsBatchOptions {
|
|
|
163
169
|
records: Record<string, unknown>[];
|
|
164
170
|
jdbcConnectionConfigId?: number;
|
|
165
171
|
}
|
|
172
|
+
interface UploadFileOptions {
|
|
173
|
+
/** ID do projeto (opcional se já configurado via configureSdkMitra) */
|
|
174
|
+
projectId?: number;
|
|
175
|
+
/** Arquivo a ser enviado (File ou Blob) */
|
|
176
|
+
file: File | Blob;
|
|
177
|
+
/** Habilitar debug (opcional) */
|
|
178
|
+
debug?: boolean;
|
|
179
|
+
}
|
|
180
|
+
interface UploadFileResponse {
|
|
181
|
+
status: string;
|
|
182
|
+
result: {
|
|
183
|
+
fileName: string;
|
|
184
|
+
currentPath: string;
|
|
185
|
+
publicUrl: string | null;
|
|
186
|
+
message: string;
|
|
187
|
+
};
|
|
188
|
+
}
|
|
166
189
|
interface ListVariablesOptions {
|
|
167
190
|
/** ID do projeto (opcional se já configurado via configureSdkMitra) */
|
|
168
191
|
projectId?: number;
|
|
@@ -264,10 +287,6 @@ interface StopServerFunctionExecutionResponse {
|
|
|
264
287
|
|
|
265
288
|
interface MitraInstance {
|
|
266
289
|
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
290
|
runQuery(options: RunQueryOptions): Promise<RunQueryResponse>;
|
|
272
291
|
executeDbAction(options: ExecuteDbActionOptions): Promise<ExecuteDbActionResponse>;
|
|
273
292
|
setFileStatus(options: SetFileStatusOptions): Promise<SetFileStatusResponse>;
|
|
@@ -278,6 +297,8 @@ interface MitraInstance {
|
|
|
278
297
|
executeServerFunction(options: ExecuteServerFunctionOptions): Promise<ExecuteServerFunctionResponse>;
|
|
279
298
|
executeServerFunctionAsync(options: ExecuteServerFunctionAsyncOptions): Promise<ExecuteServerFunctionAsyncResponse>;
|
|
280
299
|
stopServerFunctionExecution(options: StopServerFunctionExecutionOptions): Promise<StopServerFunctionExecutionResponse>;
|
|
300
|
+
uploadFilePublic(options: UploadFileOptions): Promise<UploadFileResponse>;
|
|
301
|
+
uploadFileLoadable(options: UploadFileOptions): Promise<UploadFileResponse>;
|
|
281
302
|
listIntegrations(options?: ListIntegrationsOptions): Promise<IntegrationResponse[]>;
|
|
282
303
|
callIntegration(options: CallIntegrationOptions): Promise<CallIntegrationResponse>;
|
|
283
304
|
listRecords(options: ListRecordsOptions): Promise<ListRecordsResponse>;
|
|
@@ -290,10 +311,6 @@ interface MitraInstance {
|
|
|
290
311
|
}
|
|
291
312
|
declare function createMitraInstance(initialConfig: Partial<MitraConfig>): MitraInstance;
|
|
292
313
|
|
|
293
|
-
/**
|
|
294
|
-
* Mitra Interactions SDK - Configuração
|
|
295
|
-
*/
|
|
296
|
-
|
|
297
314
|
interface MitraConfig {
|
|
298
315
|
/** URL base da API (ex: https://api.mitra.com) */
|
|
299
316
|
baseURL: string;
|
|
@@ -301,10 +318,12 @@ interface MitraConfig {
|
|
|
301
318
|
token: string;
|
|
302
319
|
/** URL base do serviço de integrações (ex: https://api0.mitraecp.com:1003) */
|
|
303
320
|
integrationURL?: string;
|
|
304
|
-
/** URL da página de autenticação Mitra (ex: https://coder.mitralab.io/auth/) */
|
|
321
|
+
/** URL da página de autenticação Mitra (ex: https://coder.mitralab.io/sdk-auth/) */
|
|
305
322
|
authUrl?: string;
|
|
306
323
|
/** ID do projeto (usado como fallback nos métodos de login e serviços) */
|
|
307
324
|
projectId?: number;
|
|
325
|
+
/** Callback chamado quando o token é renovado automaticamente (após 401/403). Recebe a nova sessão. */
|
|
326
|
+
onTokenRefresh?: (session: LoginResponse) => void;
|
|
308
327
|
}
|
|
309
328
|
/**
|
|
310
329
|
* Configura o SDK globalmente e retorna uma instância configurada.
|
|
@@ -327,31 +346,39 @@ declare function resolveProjectId(projectId?: number): number;
|
|
|
327
346
|
*/
|
|
328
347
|
|
|
329
348
|
/**
|
|
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.
|
|
349
|
+
* Login com email e senha via popup/redirect seguro Mitra.
|
|
334
350
|
*/
|
|
335
351
|
declare function loginWithEmailMitra(options?: LoginOptions): Promise<LoginResponse>;
|
|
336
352
|
/**
|
|
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.
|
|
353
|
+
* Login com Google via popup/redirect seguro Mitra.
|
|
341
354
|
*/
|
|
342
355
|
declare function loginWithGoogleMitra(options?: LoginOptions): Promise<LoginResponse>;
|
|
343
356
|
/**
|
|
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.
|
|
357
|
+
* Login com Microsoft via popup/redirect seguro Mitra.
|
|
348
358
|
*/
|
|
349
359
|
declare function loginWithMicrosoftMitra(options?: LoginOptions): Promise<LoginResponse>;
|
|
350
360
|
/**
|
|
351
|
-
* Login genérico via popup seguro Mitra.
|
|
352
|
-
* Recebe o método de login como string e delega para a função correspondente.
|
|
361
|
+
* Login genérico via popup/redirect seguro Mitra.
|
|
353
362
|
*/
|
|
354
363
|
declare function loginMitra(method: 'email' | 'google' | 'microsoft', options?: LoginOptions): Promise<LoginResponse>;
|
|
364
|
+
/**
|
|
365
|
+
* Processa o retorno de um login com mode 'redirect'.
|
|
366
|
+
*
|
|
367
|
+
* Após o redirect, a página de auth redireciona de volta com query params:
|
|
368
|
+
* ?tokenMitra={token}&backURLMitra={baseURL}&integrationURLMitra={integrationURL}
|
|
369
|
+
*
|
|
370
|
+
* Esta função:
|
|
371
|
+
* - Lê os query params da URL atual
|
|
372
|
+
* - Se `tokenMitra=error`, lança erro
|
|
373
|
+
* - Se encontrou tokens, limpa a URL e retorna LoginResponse
|
|
374
|
+
* - Se não encontrou nada, retorna null
|
|
375
|
+
*/
|
|
376
|
+
declare function handleAuthRedirect(): LoginResponse | null;
|
|
377
|
+
/**
|
|
378
|
+
* Renova o token silenciosamente via iframe invisível.
|
|
379
|
+
* Se já houver um refresh em andamento, reaproveita a mesma promise.
|
|
380
|
+
*/
|
|
381
|
+
declare function refreshTokenSilently(authUrl: string, projectId: number): Promise<LoginResponse>;
|
|
355
382
|
|
|
356
383
|
/**
|
|
357
384
|
* Mitra Interactions SDK - Services
|
|
@@ -418,6 +445,16 @@ declare function callIntegrationMitra(options: CallIntegrationOptions): Promise<
|
|
|
418
445
|
* Para a execução de uma Server Function em andamento
|
|
419
446
|
*/
|
|
420
447
|
declare function stopServerFunctionExecutionMitra(options: StopServerFunctionExecutionOptions): Promise<StopServerFunctionExecutionResponse>;
|
|
448
|
+
/**
|
|
449
|
+
* POST /agentAiShortcut/uploadFilePublic (multipart/form-data)
|
|
450
|
+
* Faz upload de um arquivo para a pasta PUBLIC do projeto.
|
|
451
|
+
*/
|
|
452
|
+
declare function uploadFilePublicMitra(options: UploadFileOptions): Promise<UploadFileResponse>;
|
|
453
|
+
/**
|
|
454
|
+
* POST /agentAiShortcut/uploadFileLoadable (multipart/form-data)
|
|
455
|
+
* Faz upload de um arquivo para a pasta LOADABLE do projeto.
|
|
456
|
+
*/
|
|
457
|
+
declare function uploadFileLoadableMitra(options: UploadFileOptions): Promise<UploadFileResponse>;
|
|
421
458
|
declare function listRecordsMitra(options: ListRecordsOptions): Promise<ListRecordsResponse>;
|
|
422
459
|
declare function getRecordMitra(options: GetRecordOptions): Promise<Record<string, any>>;
|
|
423
460
|
declare function createRecordMitra(options: CreateRecordOptions): Promise<Record<string, any>>;
|
|
@@ -426,4 +463,4 @@ declare function patchRecordMitra(options: PatchRecordOptions): Promise<Record<s
|
|
|
426
463
|
declare function deleteRecordMitra(options: DeleteRecordOptions): Promise<void>;
|
|
427
464
|
declare function createRecordsBatchMitra(options: CreateRecordsBatchOptions): Promise<Record<string, any>[]>;
|
|
428
465
|
|
|
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 };
|
|
466
|
+
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 };
|
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) */
|
|
@@ -163,6 +169,23 @@ interface CreateRecordsBatchOptions {
|
|
|
163
169
|
records: Record<string, unknown>[];
|
|
164
170
|
jdbcConnectionConfigId?: number;
|
|
165
171
|
}
|
|
172
|
+
interface UploadFileOptions {
|
|
173
|
+
/** ID do projeto (opcional se já configurado via configureSdkMitra) */
|
|
174
|
+
projectId?: number;
|
|
175
|
+
/** Arquivo a ser enviado (File ou Blob) */
|
|
176
|
+
file: File | Blob;
|
|
177
|
+
/** Habilitar debug (opcional) */
|
|
178
|
+
debug?: boolean;
|
|
179
|
+
}
|
|
180
|
+
interface UploadFileResponse {
|
|
181
|
+
status: string;
|
|
182
|
+
result: {
|
|
183
|
+
fileName: string;
|
|
184
|
+
currentPath: string;
|
|
185
|
+
publicUrl: string | null;
|
|
186
|
+
message: string;
|
|
187
|
+
};
|
|
188
|
+
}
|
|
166
189
|
interface ListVariablesOptions {
|
|
167
190
|
/** ID do projeto (opcional se já configurado via configureSdkMitra) */
|
|
168
191
|
projectId?: number;
|
|
@@ -264,10 +287,6 @@ interface StopServerFunctionExecutionResponse {
|
|
|
264
287
|
|
|
265
288
|
interface MitraInstance {
|
|
266
289
|
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
290
|
runQuery(options: RunQueryOptions): Promise<RunQueryResponse>;
|
|
272
291
|
executeDbAction(options: ExecuteDbActionOptions): Promise<ExecuteDbActionResponse>;
|
|
273
292
|
setFileStatus(options: SetFileStatusOptions): Promise<SetFileStatusResponse>;
|
|
@@ -278,6 +297,8 @@ interface MitraInstance {
|
|
|
278
297
|
executeServerFunction(options: ExecuteServerFunctionOptions): Promise<ExecuteServerFunctionResponse>;
|
|
279
298
|
executeServerFunctionAsync(options: ExecuteServerFunctionAsyncOptions): Promise<ExecuteServerFunctionAsyncResponse>;
|
|
280
299
|
stopServerFunctionExecution(options: StopServerFunctionExecutionOptions): Promise<StopServerFunctionExecutionResponse>;
|
|
300
|
+
uploadFilePublic(options: UploadFileOptions): Promise<UploadFileResponse>;
|
|
301
|
+
uploadFileLoadable(options: UploadFileOptions): Promise<UploadFileResponse>;
|
|
281
302
|
listIntegrations(options?: ListIntegrationsOptions): Promise<IntegrationResponse[]>;
|
|
282
303
|
callIntegration(options: CallIntegrationOptions): Promise<CallIntegrationResponse>;
|
|
283
304
|
listRecords(options: ListRecordsOptions): Promise<ListRecordsResponse>;
|
|
@@ -290,10 +311,6 @@ interface MitraInstance {
|
|
|
290
311
|
}
|
|
291
312
|
declare function createMitraInstance(initialConfig: Partial<MitraConfig>): MitraInstance;
|
|
292
313
|
|
|
293
|
-
/**
|
|
294
|
-
* Mitra Interactions SDK - Configuração
|
|
295
|
-
*/
|
|
296
|
-
|
|
297
314
|
interface MitraConfig {
|
|
298
315
|
/** URL base da API (ex: https://api.mitra.com) */
|
|
299
316
|
baseURL: string;
|
|
@@ -301,10 +318,12 @@ interface MitraConfig {
|
|
|
301
318
|
token: string;
|
|
302
319
|
/** URL base do serviço de integrações (ex: https://api0.mitraecp.com:1003) */
|
|
303
320
|
integrationURL?: string;
|
|
304
|
-
/** URL da página de autenticação Mitra (ex: https://coder.mitralab.io/auth/) */
|
|
321
|
+
/** URL da página de autenticação Mitra (ex: https://coder.mitralab.io/sdk-auth/) */
|
|
305
322
|
authUrl?: string;
|
|
306
323
|
/** ID do projeto (usado como fallback nos métodos de login e serviços) */
|
|
307
324
|
projectId?: number;
|
|
325
|
+
/** Callback chamado quando o token é renovado automaticamente (após 401/403). Recebe a nova sessão. */
|
|
326
|
+
onTokenRefresh?: (session: LoginResponse) => void;
|
|
308
327
|
}
|
|
309
328
|
/**
|
|
310
329
|
* Configura o SDK globalmente e retorna uma instância configurada.
|
|
@@ -327,31 +346,39 @@ declare function resolveProjectId(projectId?: number): number;
|
|
|
327
346
|
*/
|
|
328
347
|
|
|
329
348
|
/**
|
|
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.
|
|
349
|
+
* Login com email e senha via popup/redirect seguro Mitra.
|
|
334
350
|
*/
|
|
335
351
|
declare function loginWithEmailMitra(options?: LoginOptions): Promise<LoginResponse>;
|
|
336
352
|
/**
|
|
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.
|
|
353
|
+
* Login com Google via popup/redirect seguro Mitra.
|
|
341
354
|
*/
|
|
342
355
|
declare function loginWithGoogleMitra(options?: LoginOptions): Promise<LoginResponse>;
|
|
343
356
|
/**
|
|
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.
|
|
357
|
+
* Login com Microsoft via popup/redirect seguro Mitra.
|
|
348
358
|
*/
|
|
349
359
|
declare function loginWithMicrosoftMitra(options?: LoginOptions): Promise<LoginResponse>;
|
|
350
360
|
/**
|
|
351
|
-
* Login genérico via popup seguro Mitra.
|
|
352
|
-
* Recebe o método de login como string e delega para a função correspondente.
|
|
361
|
+
* Login genérico via popup/redirect seguro Mitra.
|
|
353
362
|
*/
|
|
354
363
|
declare function loginMitra(method: 'email' | 'google' | 'microsoft', options?: LoginOptions): Promise<LoginResponse>;
|
|
364
|
+
/**
|
|
365
|
+
* Processa o retorno de um login com mode 'redirect'.
|
|
366
|
+
*
|
|
367
|
+
* Após o redirect, a página de auth redireciona de volta com query params:
|
|
368
|
+
* ?tokenMitra={token}&backURLMitra={baseURL}&integrationURLMitra={integrationURL}
|
|
369
|
+
*
|
|
370
|
+
* Esta função:
|
|
371
|
+
* - Lê os query params da URL atual
|
|
372
|
+
* - Se `tokenMitra=error`, lança erro
|
|
373
|
+
* - Se encontrou tokens, limpa a URL e retorna LoginResponse
|
|
374
|
+
* - Se não encontrou nada, retorna null
|
|
375
|
+
*/
|
|
376
|
+
declare function handleAuthRedirect(): LoginResponse | null;
|
|
377
|
+
/**
|
|
378
|
+
* Renova o token silenciosamente via iframe invisível.
|
|
379
|
+
* Se já houver um refresh em andamento, reaproveita a mesma promise.
|
|
380
|
+
*/
|
|
381
|
+
declare function refreshTokenSilently(authUrl: string, projectId: number): Promise<LoginResponse>;
|
|
355
382
|
|
|
356
383
|
/**
|
|
357
384
|
* Mitra Interactions SDK - Services
|
|
@@ -418,6 +445,16 @@ declare function callIntegrationMitra(options: CallIntegrationOptions): Promise<
|
|
|
418
445
|
* Para a execução de uma Server Function em andamento
|
|
419
446
|
*/
|
|
420
447
|
declare function stopServerFunctionExecutionMitra(options: StopServerFunctionExecutionOptions): Promise<StopServerFunctionExecutionResponse>;
|
|
448
|
+
/**
|
|
449
|
+
* POST /agentAiShortcut/uploadFilePublic (multipart/form-data)
|
|
450
|
+
* Faz upload de um arquivo para a pasta PUBLIC do projeto.
|
|
451
|
+
*/
|
|
452
|
+
declare function uploadFilePublicMitra(options: UploadFileOptions): Promise<UploadFileResponse>;
|
|
453
|
+
/**
|
|
454
|
+
* POST /agentAiShortcut/uploadFileLoadable (multipart/form-data)
|
|
455
|
+
* Faz upload de um arquivo para a pasta LOADABLE do projeto.
|
|
456
|
+
*/
|
|
457
|
+
declare function uploadFileLoadableMitra(options: UploadFileOptions): Promise<UploadFileResponse>;
|
|
421
458
|
declare function listRecordsMitra(options: ListRecordsOptions): Promise<ListRecordsResponse>;
|
|
422
459
|
declare function getRecordMitra(options: GetRecordOptions): Promise<Record<string, any>>;
|
|
423
460
|
declare function createRecordMitra(options: CreateRecordOptions): Promise<Record<string, any>>;
|
|
@@ -426,4 +463,4 @@ declare function patchRecordMitra(options: PatchRecordOptions): Promise<Record<s
|
|
|
426
463
|
declare function deleteRecordMitra(options: DeleteRecordOptions): Promise<void>;
|
|
427
464
|
declare function createRecordsBatchMitra(options: CreateRecordsBatchOptions): Promise<Record<string, any>[]>;
|
|
428
465
|
|
|
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 };
|
|
466
|
+
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 };
|