mitra-interactions-sdk 1.0.35 → 1.0.37
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 +13 -160
- package/dist/index.d.mts +22 -35
- package/dist/index.d.ts +22 -35
- package/dist/index.js +63 -134
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -134
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Mitra Interactions SDK
|
|
2
2
|
|
|
3
|
-
SDK para interações com a plataforma Mitra via endpoints `/
|
|
3
|
+
SDK para interações com a plataforma Mitra via endpoints `/interactions/`.
|
|
4
4
|
|
|
5
5
|
## Instalação
|
|
6
6
|
|
|
@@ -14,16 +14,17 @@ pnpm add mitra-interactions-sdk
|
|
|
14
14
|
|
|
15
15
|
## Configuração
|
|
16
16
|
|
|
17
|
-
Antes de usar qualquer função, configure o SDK
|
|
17
|
+
Antes de usar qualquer função, configure o SDK. O `token` é **opcional** — Server Functions públicas podem ser chamadas sem autenticação.
|
|
18
18
|
|
|
19
|
-
> **Importante:**
|
|
19
|
+
> **Importante:** Quando usado, o token é um JWT de autenticação da plataforma Mitra. **Nunca deixe o token estático no código.** Utilize variáveis de ambiente para armazená-lo de forma segura.
|
|
20
20
|
|
|
21
21
|
```typescript
|
|
22
22
|
import { configureSdkMitra } from 'mitra-interactions-sdk';
|
|
23
23
|
|
|
24
|
+
// Configuração completa (com autenticação)
|
|
24
25
|
const instance = configureSdkMitra({
|
|
25
26
|
baseURL: process.env.MITRA_BASE_URL || 'https://api.mitra.com',
|
|
26
|
-
token: process.env.MITRA_TOKEN!,
|
|
27
|
+
token: process.env.MITRA_TOKEN!, // Opcional — necessário apenas para endpoints autenticados
|
|
27
28
|
authUrl: 'https://coder.mitralab.io/sdk-auth/', // Opcional — necessário para login e token refresh
|
|
28
29
|
projectId: 123, // Opcional — se informado, torna projectId opcional em TODOS os métodos
|
|
29
30
|
integrationURL: 'https://api0.mitraecp.com:1003', // Opcional — necessário para integrações
|
|
@@ -31,6 +32,13 @@ const instance = configureSdkMitra({
|
|
|
31
32
|
localStorage.setItem('mitra_session', JSON.stringify(session));
|
|
32
33
|
}
|
|
33
34
|
});
|
|
35
|
+
|
|
36
|
+
// Configuração mínima (sem token — apenas para Server Functions públicas)
|
|
37
|
+
const instance = configureSdkMitra({
|
|
38
|
+
baseURL: 'https://api.mitra.com',
|
|
39
|
+
projectId: 123
|
|
40
|
+
});
|
|
41
|
+
await instance.executeServerFunction({ serverFunctionId: 42 }); // OK — sem token
|
|
34
42
|
```
|
|
35
43
|
|
|
36
44
|
> **`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.
|
|
@@ -83,7 +91,7 @@ await loginMitra('mitra', {
|
|
|
83
91
|
Navega o usuário para a página de auth. Após o login, redireciona de volta com token nos query params.
|
|
84
92
|
|
|
85
93
|
```typescript
|
|
86
|
-
import { loginMitra
|
|
94
|
+
import { loginMitra } from 'mitra-interactions-sdk';
|
|
87
95
|
|
|
88
96
|
// Iniciar login — o navegador navega para fora da página
|
|
89
97
|
await loginMitra('google', {
|
|
@@ -106,25 +114,6 @@ await loginMitra('mitra', {
|
|
|
106
114
|
});
|
|
107
115
|
```
|
|
108
116
|
|
|
109
|
-
### Processar Retorno do Redirect
|
|
110
|
-
|
|
111
|
-
Após o redirect, a página de destino deve chamar `handleAuthRedirect()` para capturar o token:
|
|
112
|
-
|
|
113
|
-
```typescript
|
|
114
|
-
import { handleAuthRedirect, configureSdkMitra } from 'mitra-interactions-sdk';
|
|
115
|
-
|
|
116
|
-
// No mounted/onLoad da página de retorno
|
|
117
|
-
const session = handleAuthRedirect();
|
|
118
|
-
if (session) {
|
|
119
|
-
// Login OK — session: { token, baseURL, integrationURL? }
|
|
120
|
-
configureSdkMitra({
|
|
121
|
-
baseURL: session.baseURL,
|
|
122
|
-
token: session.token,
|
|
123
|
-
integrationURL: session.integrationURL
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
```
|
|
127
|
-
|
|
128
117
|
### Token Refresh Automático
|
|
129
118
|
|
|
130
119
|
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.
|
|
@@ -219,24 +208,6 @@ await executeDbActionMitra({ dbActionId: 1 });
|
|
|
219
208
|
|
|
220
209
|
## Métodos Disponíveis
|
|
221
210
|
|
|
222
|
-
### executeDbActionMitra
|
|
223
|
-
|
|
224
|
-
Executa uma DBAction (DML) cadastrada.
|
|
225
|
-
|
|
226
|
-
```typescript
|
|
227
|
-
import { executeDbActionMitra } from 'mitra-interactions-sdk';
|
|
228
|
-
|
|
229
|
-
const result = await executeDbActionMitra({
|
|
230
|
-
projectId: 123,
|
|
231
|
-
dbActionId: 456,
|
|
232
|
-
params: { // Opcional
|
|
233
|
-
campo1: 'valor1',
|
|
234
|
-
campo2: 'valor2'
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
// result: { status, result: { rowsAffected: number } }
|
|
238
|
-
```
|
|
239
|
-
|
|
240
211
|
### executeServerFunctionMitra
|
|
241
212
|
|
|
242
213
|
Executa uma Server Function de forma **síncrona** (timeout de 60s no backend). Retorna o resultado diretamente.
|
|
@@ -285,39 +256,6 @@ const result = await stopServerFunctionExecutionMitra({
|
|
|
285
256
|
// result: { status, result: { executionId, executionStatus: "CANCELLED" | "ALREADY_FINISHED" } }
|
|
286
257
|
```
|
|
287
258
|
|
|
288
|
-
### Integrações
|
|
289
|
-
|
|
290
|
-
> **Requisito:** A `integrationURL` deve ser configurada via `configureSdkMitra({ ..., integrationURL: 'https://api0.mitraecp.com:1003' })`.
|
|
291
|
-
|
|
292
|
-
#### listIntegrationsMitra
|
|
293
|
-
|
|
294
|
-
Lista as integrações configuradas no projeto.
|
|
295
|
-
|
|
296
|
-
```typescript
|
|
297
|
-
import { listIntegrationsMitra } from 'mitra-interactions-sdk';
|
|
298
|
-
|
|
299
|
-
const integrations = await listIntegrationsMitra({ projectId: 123 });
|
|
300
|
-
// result: IntegrationResponse[] — [{ id, projectId, name, slug, blueprintId, blueprintType, authType, credentials, status, lastCheckedAt, createdAt, updatedAt }]
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
#### callIntegrationMitra
|
|
304
|
-
|
|
305
|
-
Chama uma integração configurada, delegando a requisição ao serviço externo.
|
|
306
|
-
|
|
307
|
-
```typescript
|
|
308
|
-
import { callIntegrationMitra } from 'mitra-interactions-sdk';
|
|
309
|
-
|
|
310
|
-
const result = await callIntegrationMitra({
|
|
311
|
-
projectId: 123,
|
|
312
|
-
connection: 'meu-erp', // Slug da integração
|
|
313
|
-
method: 'GET', // GET, POST, PUT, DELETE
|
|
314
|
-
endpoint: '/api/v1/pedidos', // Path no serviço externo (opcional)
|
|
315
|
-
params: { status: 'ativo' }, // Query params (opcional)
|
|
316
|
-
body: { nome: 'Teste' } // Body para POST/PUT (opcional)
|
|
317
|
-
});
|
|
318
|
-
// result: { statusCode: number, body: any }
|
|
319
|
-
```
|
|
320
|
-
|
|
321
259
|
### uploadFilePublicMitra / uploadFileLoadableMitra
|
|
322
260
|
|
|
323
261
|
Faz upload de um arquivo diretamente para a pasta PUBLIC ou LOADABLE do projeto. Usa `multipart/form-data`.
|
|
@@ -340,75 +278,6 @@ const result2 = await uploadFileLoadableMitra({
|
|
|
340
278
|
// result2: { status, result: { fileName, currentPath, publicUrl: null, message } }
|
|
341
279
|
```
|
|
342
280
|
|
|
343
|
-
### setFileStatusMitra
|
|
344
|
-
|
|
345
|
-
Move arquivo do chat para PUBLIC ou LOADABLE.
|
|
346
|
-
|
|
347
|
-
```typescript
|
|
348
|
-
import { setFileStatusMitra } from 'mitra-interactions-sdk';
|
|
349
|
-
|
|
350
|
-
const result = await setFileStatusMitra({
|
|
351
|
-
projectId: 123,
|
|
352
|
-
fileName: 'arquivo.jpg',
|
|
353
|
-
targetPath: 'PUBLIC' // 'PUBLIC' ou 'LOADABLE'
|
|
354
|
-
});
|
|
355
|
-
// result: { status, result: { fileName, currentPath, publicUrl, message } }
|
|
356
|
-
```
|
|
357
|
-
|
|
358
|
-
### setVariableMitra
|
|
359
|
-
|
|
360
|
-
Cria ou atualiza uma variável customizada.
|
|
361
|
-
|
|
362
|
-
```typescript
|
|
363
|
-
import { setVariableMitra } from 'mitra-interactions-sdk';
|
|
364
|
-
|
|
365
|
-
const result = await setVariableMitra({
|
|
366
|
-
projectId: 123,
|
|
367
|
-
key: 'minhaVariavel',
|
|
368
|
-
value: 'meuValor' // Opcional
|
|
369
|
-
});
|
|
370
|
-
// result: { status, result: { key, value } }
|
|
371
|
-
```
|
|
372
|
-
|
|
373
|
-
### listVariablesMitra
|
|
374
|
-
|
|
375
|
-
Lista variáveis de um projeto.
|
|
376
|
-
|
|
377
|
-
```typescript
|
|
378
|
-
import { listVariablesMitra } from 'mitra-interactions-sdk';
|
|
379
|
-
|
|
380
|
-
const result = await listVariablesMitra({ projectId: 123 });
|
|
381
|
-
// result: { status, projectId, result: [{ key, value }] }
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
### getVariableMitra
|
|
385
|
-
|
|
386
|
-
Busca o valor de uma variável específica.
|
|
387
|
-
|
|
388
|
-
```typescript
|
|
389
|
-
import { getVariableMitra } from 'mitra-interactions-sdk';
|
|
390
|
-
|
|
391
|
-
const result = await getVariableMitra({ projectId: 123, key: 'minhaVariavel' });
|
|
392
|
-
// result: { status, result: { key, value } }
|
|
393
|
-
```
|
|
394
|
-
|
|
395
|
-
### runActionMitra
|
|
396
|
-
|
|
397
|
-
Executa uma Action (fluxo de ação Low-Code) cadastrada.
|
|
398
|
-
|
|
399
|
-
```typescript
|
|
400
|
-
import { runActionMitra } from 'mitra-interactions-sdk';
|
|
401
|
-
|
|
402
|
-
const result = await runActionMitra({
|
|
403
|
-
projectId: 123,
|
|
404
|
-
actionId: 456,
|
|
405
|
-
params: { // Opcional
|
|
406
|
-
campo1: 'valor1'
|
|
407
|
-
}
|
|
408
|
-
});
|
|
409
|
-
// result: { status, executionTime, result: { stepsExecuted, message } }
|
|
410
|
-
```
|
|
411
|
-
|
|
412
281
|
### Dynamic Schema CRUD
|
|
413
282
|
|
|
414
283
|
CRUD completo em tabelas do projeto via Dynamic Schema (usa header `X-TenantID`).
|
|
@@ -476,18 +345,10 @@ import type {
|
|
|
476
345
|
EmailVerifyCodeOptions,
|
|
477
346
|
EmailResendCodeOptions,
|
|
478
347
|
// Options
|
|
479
|
-
ExecuteDbActionOptions,
|
|
480
348
|
ExecuteServerFunctionOptions,
|
|
481
349
|
ExecuteServerFunctionAsyncOptions,
|
|
482
|
-
ListIntegrationsOptions,
|
|
483
|
-
CallIntegrationOptions,
|
|
484
350
|
UploadFileOptions,
|
|
485
351
|
StopServerFunctionExecutionOptions,
|
|
486
|
-
SetFileStatusOptions,
|
|
487
|
-
SetVariableOptions,
|
|
488
|
-
ListVariablesOptions,
|
|
489
|
-
GetVariableOptions,
|
|
490
|
-
RunActionOptions,
|
|
491
352
|
ListRecordsOptions,
|
|
492
353
|
GetRecordOptions,
|
|
493
354
|
CreateRecordOptions,
|
|
@@ -496,16 +357,8 @@ import type {
|
|
|
496
357
|
DeleteRecordOptions,
|
|
497
358
|
CreateRecordsBatchOptions,
|
|
498
359
|
// Responses
|
|
499
|
-
ExecuteDbActionResponse,
|
|
500
|
-
SetFileStatusResponse,
|
|
501
|
-
SetVariableResponse,
|
|
502
|
-
ListVariablesResponse,
|
|
503
|
-
GetVariableResponse,
|
|
504
|
-
RunActionResponse,
|
|
505
360
|
ExecuteServerFunctionResponse,
|
|
506
361
|
ExecuteServerFunctionAsyncResponse,
|
|
507
|
-
IntegrationResponse,
|
|
508
|
-
CallIntegrationResponse,
|
|
509
362
|
UploadFileResponse,
|
|
510
363
|
StopServerFunctionExecutionResponse,
|
|
511
364
|
ListRecordsResponse
|
package/dist/index.d.mts
CHANGED
|
@@ -85,8 +85,8 @@ interface ExecuteDbActionOptions {
|
|
|
85
85
|
projectId?: number;
|
|
86
86
|
/** ID da DBAction cadastrada */
|
|
87
87
|
dbActionId: number;
|
|
88
|
-
/**
|
|
89
|
-
|
|
88
|
+
/** Parâmetros de entrada (opcional) — substituição de variáveis no SQL (ex: { "nome": "João" } substitui :nome) */
|
|
89
|
+
input?: Record<string, unknown>;
|
|
90
90
|
}
|
|
91
91
|
interface ExecuteDbActionResponse {
|
|
92
92
|
status: string;
|
|
@@ -260,8 +260,8 @@ interface RunActionOptions {
|
|
|
260
260
|
projectId?: number;
|
|
261
261
|
/** ID da Action a executar */
|
|
262
262
|
actionId: number;
|
|
263
|
-
/**
|
|
264
|
-
|
|
263
|
+
/** Parâmetros de entrada para a action (opcional) */
|
|
264
|
+
input?: Record<string, unknown>;
|
|
265
265
|
}
|
|
266
266
|
interface RunActionResponse {
|
|
267
267
|
status: string;
|
|
@@ -358,8 +358,8 @@ declare function createMitraInstance(initialConfig: Partial<MitraConfig>): Mitra
|
|
|
358
358
|
interface MitraConfig {
|
|
359
359
|
/** URL base da API (ex: https://api.mitra.com) */
|
|
360
360
|
baseURL: string;
|
|
361
|
-
/** Token JWT para autenticação */
|
|
362
|
-
token
|
|
361
|
+
/** Token JWT para autenticação (opcional para Server Functions públicas) */
|
|
362
|
+
token?: string;
|
|
363
363
|
/** URL base do serviço de integrações (ex: https://api0.mitraecp.com:1003) */
|
|
364
364
|
integrationURL?: string;
|
|
365
365
|
/** URL da página de autenticação Mitra (ex: https://coder.mitralab.io/sdk-auth/) */
|
|
@@ -405,19 +405,6 @@ declare function loginWithMicrosoftMitra(options?: LoginOptions): Promise<LoginR
|
|
|
405
405
|
* Login genérico via popup/redirect seguro Mitra.
|
|
406
406
|
*/
|
|
407
407
|
declare function loginMitra(method: 'email' | 'google' | 'microsoft' | 'mitra', options?: LoginOptions): Promise<LoginResponse>;
|
|
408
|
-
/**
|
|
409
|
-
* Processa o retorno de um login com mode 'redirect'.
|
|
410
|
-
*
|
|
411
|
-
* Após o redirect, a página de auth redireciona de volta com query params:
|
|
412
|
-
* ?tokenMitra={token}&backURLMitra={baseURL}&integrationURLMitra={integrationURL}
|
|
413
|
-
*
|
|
414
|
-
* Esta função:
|
|
415
|
-
* - Lê os query params da URL atual
|
|
416
|
-
* - Se `tokenMitra=error`, lança erro
|
|
417
|
-
* - Se encontrou tokens, limpa a URL e retorna LoginResponse
|
|
418
|
-
* - Se não encontrou nada, retorna null
|
|
419
|
-
*/
|
|
420
|
-
declare function handleAuthRedirect(): LoginResponse | null;
|
|
421
408
|
/**
|
|
422
409
|
* Renova o token silenciosamente via iframe invisível.
|
|
423
410
|
* Se já houver um refresh em andamento, reaproveita a mesma promise.
|
|
@@ -452,73 +439,73 @@ declare function emailLoginMitra(options: EmailLoginOptions): Promise<LoginRespo
|
|
|
452
439
|
*/
|
|
453
440
|
|
|
454
441
|
/**
|
|
455
|
-
* POST /
|
|
442
|
+
* POST /interactions/runQuery
|
|
456
443
|
* Executa query SELECT em um projeto
|
|
457
444
|
*/
|
|
458
445
|
declare function runQueryMitra(options: RunQueryOptions): Promise<RunQueryResponse>;
|
|
459
446
|
/**
|
|
460
|
-
* POST /
|
|
447
|
+
* POST /interactions/executeDbAction
|
|
461
448
|
* Executa uma DBAction (DML) cadastrada
|
|
462
449
|
*/
|
|
463
450
|
declare function executeDbActionMitra(options: ExecuteDbActionOptions): Promise<ExecuteDbActionResponse>;
|
|
464
451
|
/**
|
|
465
|
-
* POST /
|
|
452
|
+
* POST /interactions/setFileStatus
|
|
466
453
|
* Move arquivo do chat para PUBLIC ou LOADABLE
|
|
467
454
|
*/
|
|
468
455
|
declare function setFileStatusMitra(options: SetFileStatusOptions): Promise<SetFileStatusResponse>;
|
|
469
456
|
/**
|
|
470
|
-
* POST /
|
|
457
|
+
* POST /interactions/setVariable
|
|
471
458
|
* Cria ou atualiza uma variável customizada
|
|
472
459
|
*/
|
|
473
460
|
declare function setVariableMitra(options: SetVariableOptions): Promise<SetVariableResponse>;
|
|
474
461
|
/**
|
|
475
|
-
* GET /
|
|
462
|
+
* GET /interactions/listVariables?projectId={id}
|
|
476
463
|
* Lista variáveis de um projeto
|
|
477
464
|
*/
|
|
478
465
|
declare function listVariablesMitra(options?: ListVariablesOptions): Promise<ListVariablesResponse>;
|
|
479
466
|
/**
|
|
480
|
-
* GET /
|
|
467
|
+
* GET /interactions/getVariable?projectId={id}&key={key}
|
|
481
468
|
* Busca o valor de uma variável específica
|
|
482
469
|
*/
|
|
483
470
|
declare function getVariableMitra(options: GetVariableOptions): Promise<GetVariableResponse>;
|
|
484
471
|
/**
|
|
485
|
-
* POST /
|
|
472
|
+
* POST /interactions/runAction
|
|
486
473
|
* Executa uma Action (fluxo de ação) cadastrada
|
|
487
474
|
*/
|
|
488
475
|
declare function runActionMitra(options: RunActionOptions): Promise<RunActionResponse>;
|
|
489
476
|
/**
|
|
490
|
-
* POST /
|
|
477
|
+
* POST /interactions/executeServerFunction
|
|
491
478
|
* Executa uma Server Function de forma SÍNCRONA (timeout 60s no backend)
|
|
492
479
|
*/
|
|
493
480
|
declare function executeServerFunctionMitra(options: ExecuteServerFunctionOptions): Promise<ExecuteServerFunctionResponse>;
|
|
494
481
|
/**
|
|
495
|
-
* POST /
|
|
482
|
+
* POST /interactions/executeServerFunctionAsync
|
|
496
483
|
* Executa uma Server Function de forma ASSÍNCRONA (retorna executionId imediatamente)
|
|
497
484
|
*/
|
|
498
485
|
declare function executeServerFunctionAsyncMitra(options: ExecuteServerFunctionAsyncOptions): Promise<ExecuteServerFunctionAsyncResponse>;
|
|
499
486
|
/**
|
|
500
|
-
* GET /
|
|
487
|
+
* GET /interactions/integrations?projectId=X
|
|
501
488
|
* Lista integrações configuradas no projeto
|
|
502
489
|
*/
|
|
503
490
|
declare function listIntegrationsMitra(options?: ListIntegrationsOptions): Promise<IntegrationResponse[]>;
|
|
504
491
|
/**
|
|
505
|
-
* POST /
|
|
506
|
-
* Chama uma API externa via serviço de integrações
|
|
492
|
+
* POST /interactions/integrations/call
|
|
493
|
+
* Chama uma API externa via serviço de integrações
|
|
507
494
|
* Mapeia connection → integrationSlug no body
|
|
508
495
|
*/
|
|
509
496
|
declare function callIntegrationMitra(options: CallIntegrationOptions): Promise<CallIntegrationResponse>;
|
|
510
497
|
/**
|
|
511
|
-
* POST /
|
|
498
|
+
* POST /interactions/stopServerFunctionExecution
|
|
512
499
|
* Para a execução de uma Server Function em andamento
|
|
513
500
|
*/
|
|
514
501
|
declare function stopServerFunctionExecutionMitra(options: StopServerFunctionExecutionOptions): Promise<StopServerFunctionExecutionResponse>;
|
|
515
502
|
/**
|
|
516
|
-
* POST /
|
|
503
|
+
* POST /interactions/uploadFilePublic (multipart/form-data)
|
|
517
504
|
* Faz upload de um arquivo para a pasta PUBLIC do projeto.
|
|
518
505
|
*/
|
|
519
506
|
declare function uploadFilePublicMitra(options: UploadFileOptions): Promise<UploadFileResponse>;
|
|
520
507
|
/**
|
|
521
|
-
* POST /
|
|
508
|
+
* POST /interactions/uploadFileLoadable (multipart/form-data)
|
|
522
509
|
* Faz upload de um arquivo para a pasta LOADABLE do projeto.
|
|
523
510
|
*/
|
|
524
511
|
declare function uploadFileLoadableMitra(options: UploadFileOptions): Promise<UploadFileResponse>;
|
|
@@ -530,4 +517,4 @@ declare function patchRecordMitra(options: PatchRecordOptions): Promise<Record<s
|
|
|
530
517
|
declare function deleteRecordMitra(options: DeleteRecordOptions): Promise<void>;
|
|
531
518
|
declare function createRecordsBatchMitra(options: CreateRecordsBatchOptions): Promise<Record<string, any>[]>;
|
|
532
519
|
|
|
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,
|
|
520
|
+
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, listIntegrationsMitra, listRecordsMitra, listVariablesMitra, loginMitra, loginWithEmailMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, patchRecordMitra, refreshTokenSilently, resolveProjectId, runActionMitra, runQueryMitra, setFileStatusMitra, setVariableMitra, stopServerFunctionExecutionMitra, updateRecordMitra, uploadFileLoadableMitra, uploadFilePublicMitra };
|
package/dist/index.d.ts
CHANGED
|
@@ -85,8 +85,8 @@ interface ExecuteDbActionOptions {
|
|
|
85
85
|
projectId?: number;
|
|
86
86
|
/** ID da DBAction cadastrada */
|
|
87
87
|
dbActionId: number;
|
|
88
|
-
/**
|
|
89
|
-
|
|
88
|
+
/** Parâmetros de entrada (opcional) — substituição de variáveis no SQL (ex: { "nome": "João" } substitui :nome) */
|
|
89
|
+
input?: Record<string, unknown>;
|
|
90
90
|
}
|
|
91
91
|
interface ExecuteDbActionResponse {
|
|
92
92
|
status: string;
|
|
@@ -260,8 +260,8 @@ interface RunActionOptions {
|
|
|
260
260
|
projectId?: number;
|
|
261
261
|
/** ID da Action a executar */
|
|
262
262
|
actionId: number;
|
|
263
|
-
/**
|
|
264
|
-
|
|
263
|
+
/** Parâmetros de entrada para a action (opcional) */
|
|
264
|
+
input?: Record<string, unknown>;
|
|
265
265
|
}
|
|
266
266
|
interface RunActionResponse {
|
|
267
267
|
status: string;
|
|
@@ -358,8 +358,8 @@ declare function createMitraInstance(initialConfig: Partial<MitraConfig>): Mitra
|
|
|
358
358
|
interface MitraConfig {
|
|
359
359
|
/** URL base da API (ex: https://api.mitra.com) */
|
|
360
360
|
baseURL: string;
|
|
361
|
-
/** Token JWT para autenticação */
|
|
362
|
-
token
|
|
361
|
+
/** Token JWT para autenticação (opcional para Server Functions públicas) */
|
|
362
|
+
token?: string;
|
|
363
363
|
/** URL base do serviço de integrações (ex: https://api0.mitraecp.com:1003) */
|
|
364
364
|
integrationURL?: string;
|
|
365
365
|
/** URL da página de autenticação Mitra (ex: https://coder.mitralab.io/sdk-auth/) */
|
|
@@ -405,19 +405,6 @@ declare function loginWithMicrosoftMitra(options?: LoginOptions): Promise<LoginR
|
|
|
405
405
|
* Login genérico via popup/redirect seguro Mitra.
|
|
406
406
|
*/
|
|
407
407
|
declare function loginMitra(method: 'email' | 'google' | 'microsoft' | 'mitra', options?: LoginOptions): Promise<LoginResponse>;
|
|
408
|
-
/**
|
|
409
|
-
* Processa o retorno de um login com mode 'redirect'.
|
|
410
|
-
*
|
|
411
|
-
* Após o redirect, a página de auth redireciona de volta com query params:
|
|
412
|
-
* ?tokenMitra={token}&backURLMitra={baseURL}&integrationURLMitra={integrationURL}
|
|
413
|
-
*
|
|
414
|
-
* Esta função:
|
|
415
|
-
* - Lê os query params da URL atual
|
|
416
|
-
* - Se `tokenMitra=error`, lança erro
|
|
417
|
-
* - Se encontrou tokens, limpa a URL e retorna LoginResponse
|
|
418
|
-
* - Se não encontrou nada, retorna null
|
|
419
|
-
*/
|
|
420
|
-
declare function handleAuthRedirect(): LoginResponse | null;
|
|
421
408
|
/**
|
|
422
409
|
* Renova o token silenciosamente via iframe invisível.
|
|
423
410
|
* Se já houver um refresh em andamento, reaproveita a mesma promise.
|
|
@@ -452,73 +439,73 @@ declare function emailLoginMitra(options: EmailLoginOptions): Promise<LoginRespo
|
|
|
452
439
|
*/
|
|
453
440
|
|
|
454
441
|
/**
|
|
455
|
-
* POST /
|
|
442
|
+
* POST /interactions/runQuery
|
|
456
443
|
* Executa query SELECT em um projeto
|
|
457
444
|
*/
|
|
458
445
|
declare function runQueryMitra(options: RunQueryOptions): Promise<RunQueryResponse>;
|
|
459
446
|
/**
|
|
460
|
-
* POST /
|
|
447
|
+
* POST /interactions/executeDbAction
|
|
461
448
|
* Executa uma DBAction (DML) cadastrada
|
|
462
449
|
*/
|
|
463
450
|
declare function executeDbActionMitra(options: ExecuteDbActionOptions): Promise<ExecuteDbActionResponse>;
|
|
464
451
|
/**
|
|
465
|
-
* POST /
|
|
452
|
+
* POST /interactions/setFileStatus
|
|
466
453
|
* Move arquivo do chat para PUBLIC ou LOADABLE
|
|
467
454
|
*/
|
|
468
455
|
declare function setFileStatusMitra(options: SetFileStatusOptions): Promise<SetFileStatusResponse>;
|
|
469
456
|
/**
|
|
470
|
-
* POST /
|
|
457
|
+
* POST /interactions/setVariable
|
|
471
458
|
* Cria ou atualiza uma variável customizada
|
|
472
459
|
*/
|
|
473
460
|
declare function setVariableMitra(options: SetVariableOptions): Promise<SetVariableResponse>;
|
|
474
461
|
/**
|
|
475
|
-
* GET /
|
|
462
|
+
* GET /interactions/listVariables?projectId={id}
|
|
476
463
|
* Lista variáveis de um projeto
|
|
477
464
|
*/
|
|
478
465
|
declare function listVariablesMitra(options?: ListVariablesOptions): Promise<ListVariablesResponse>;
|
|
479
466
|
/**
|
|
480
|
-
* GET /
|
|
467
|
+
* GET /interactions/getVariable?projectId={id}&key={key}
|
|
481
468
|
* Busca o valor de uma variável específica
|
|
482
469
|
*/
|
|
483
470
|
declare function getVariableMitra(options: GetVariableOptions): Promise<GetVariableResponse>;
|
|
484
471
|
/**
|
|
485
|
-
* POST /
|
|
472
|
+
* POST /interactions/runAction
|
|
486
473
|
* Executa uma Action (fluxo de ação) cadastrada
|
|
487
474
|
*/
|
|
488
475
|
declare function runActionMitra(options: RunActionOptions): Promise<RunActionResponse>;
|
|
489
476
|
/**
|
|
490
|
-
* POST /
|
|
477
|
+
* POST /interactions/executeServerFunction
|
|
491
478
|
* Executa uma Server Function de forma SÍNCRONA (timeout 60s no backend)
|
|
492
479
|
*/
|
|
493
480
|
declare function executeServerFunctionMitra(options: ExecuteServerFunctionOptions): Promise<ExecuteServerFunctionResponse>;
|
|
494
481
|
/**
|
|
495
|
-
* POST /
|
|
482
|
+
* POST /interactions/executeServerFunctionAsync
|
|
496
483
|
* Executa uma Server Function de forma ASSÍNCRONA (retorna executionId imediatamente)
|
|
497
484
|
*/
|
|
498
485
|
declare function executeServerFunctionAsyncMitra(options: ExecuteServerFunctionAsyncOptions): Promise<ExecuteServerFunctionAsyncResponse>;
|
|
499
486
|
/**
|
|
500
|
-
* GET /
|
|
487
|
+
* GET /interactions/integrations?projectId=X
|
|
501
488
|
* Lista integrações configuradas no projeto
|
|
502
489
|
*/
|
|
503
490
|
declare function listIntegrationsMitra(options?: ListIntegrationsOptions): Promise<IntegrationResponse[]>;
|
|
504
491
|
/**
|
|
505
|
-
* POST /
|
|
506
|
-
* Chama uma API externa via serviço de integrações
|
|
492
|
+
* POST /interactions/integrations/call
|
|
493
|
+
* Chama uma API externa via serviço de integrações
|
|
507
494
|
* Mapeia connection → integrationSlug no body
|
|
508
495
|
*/
|
|
509
496
|
declare function callIntegrationMitra(options: CallIntegrationOptions): Promise<CallIntegrationResponse>;
|
|
510
497
|
/**
|
|
511
|
-
* POST /
|
|
498
|
+
* POST /interactions/stopServerFunctionExecution
|
|
512
499
|
* Para a execução de uma Server Function em andamento
|
|
513
500
|
*/
|
|
514
501
|
declare function stopServerFunctionExecutionMitra(options: StopServerFunctionExecutionOptions): Promise<StopServerFunctionExecutionResponse>;
|
|
515
502
|
/**
|
|
516
|
-
* POST /
|
|
503
|
+
* POST /interactions/uploadFilePublic (multipart/form-data)
|
|
517
504
|
* Faz upload de um arquivo para a pasta PUBLIC do projeto.
|
|
518
505
|
*/
|
|
519
506
|
declare function uploadFilePublicMitra(options: UploadFileOptions): Promise<UploadFileResponse>;
|
|
520
507
|
/**
|
|
521
|
-
* POST /
|
|
508
|
+
* POST /interactions/uploadFileLoadable (multipart/form-data)
|
|
522
509
|
* Faz upload de um arquivo para a pasta LOADABLE do projeto.
|
|
523
510
|
*/
|
|
524
511
|
declare function uploadFileLoadableMitra(options: UploadFileOptions): Promise<UploadFileResponse>;
|
|
@@ -530,4 +517,4 @@ declare function patchRecordMitra(options: PatchRecordOptions): Promise<Record<s
|
|
|
530
517
|
declare function deleteRecordMitra(options: DeleteRecordOptions): Promise<void>;
|
|
531
518
|
declare function createRecordsBatchMitra(options: CreateRecordsBatchOptions): Promise<Record<string, any>[]>;
|
|
532
519
|
|
|
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,
|
|
520
|
+
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, listIntegrationsMitra, listRecordsMitra, listVariablesMitra, loginMitra, loginWithEmailMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, patchRecordMitra, refreshTokenSilently, resolveProjectId, runActionMitra, runQueryMitra, setFileStatusMitra, setVariableMitra, stopServerFunctionExecutionMitra, updateRecordMitra, uploadFileLoadableMitra, uploadFilePublicMitra };
|