mitra-interactions-sdk 1.0.60-beta.19 → 1.0.60-beta.20

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 CHANGED
@@ -6,7 +6,7 @@ SDK para interações com a plataforma Mitra via endpoints `/interactions/`.
6
6
 
7
7
  `userType` no token de login:
8
8
  - `dev` — chama tudo
9
- - `business` — chama apenas execução (SF, Data Loader), auth e integrações. Outras chamadas retornam **403**.
9
+ - `business` — chama apenas execução (SF), auth SSO e integrações. Outras chamadas retornam **403**.
10
10
 
11
11
  > Não confundir com o pacote `mitra-business-sdk` (SDK separado, usado pelo agente IA).
12
12
 
@@ -72,60 +72,34 @@ Login via popup ou redirect seguro hospedado no domínio Mitra. Credenciais nunc
72
72
  ### Login via Popup (padrão)
73
73
 
74
74
  ```typescript
75
- import { loginMitra } from 'mitra-interactions-sdk';
75
+ import { loginWithGoogleMitra, loginWithMicrosoftMitra } from 'mitra-interactions-sdk';
76
76
 
77
- // Métodos disponíveis: 'email', 'google', 'microsoft', 'mitra'
78
77
  // Primeira vez — sem configureSdkMitra: authUrl e projectId são obrigatórios
79
- const result = await loginMitra('email', {
80
- authUrl: 'https://coder.mitralab.io/sdk-auth/',
81
- projectId: 123
78
+ const result = await loginWithGoogleMitra({
79
+ authUrl: 'https://stg.mitralab.io/legacy',
80
+ projectId: 'uuid-do-projeto'
82
81
  });
83
82
 
84
83
  // Se já chamou configureSdkMitra({ authUrl, projectId }), basta:
85
- const result = await loginMitra('google');
86
- const result = await loginMitra('microsoft');
87
-
88
- // result: { token, baseURL, integrationURL? }
89
- ```
90
-
91
- ### Login Completo (method 'mitra')
84
+ const result = await loginWithGoogleMitra();
85
+ const result = await loginWithMicrosoftMitra();
92
86
 
93
- Abre uma tela com todas as opções (Google, Microsoft, Email) e toggle entre Login/Cadastro.
94
-
95
- ```typescript
96
- await loginMitra('mitra', {
97
- authUrl: 'https://coder.mitralab.io/sdk-auth/',
98
- projectId: 123,
99
- title: 'Meu App' // Opcional — título exibido na tela de login (default: "Mitra")
100
- });
87
+ // result: { token, baseURL, refreshToken }
101
88
  ```
102
89
 
103
- ### Login via Redirect
90
+ ### Login via Redirect (mobile)
104
91
 
105
- Navega o usuário para a página de auth. Após o login, redireciona de volta com token nos query params.
92
+ No celular o popup vira aba — use `mode: 'redirect'`: a página de auth navega de volta pro app com `#codeMitra`/`#stateMitra` no fragment, e o app conclui com `exchangeSsoCodeMitra`.
106
93
 
107
94
  ```typescript
108
- import { loginMitra } from 'mitra-interactions-sdk';
95
+ import { loginWithGoogleMitra, exchangeSsoCodeMitra } from 'mitra-interactions-sdk';
109
96
 
110
- // Iniciar login — o navegador navega para fora da página
111
- await loginMitra('google', {
112
- mode: 'redirect',
113
- returnTo: '/dashboard' // Opcional — URL de retorno após login (default: página atual). Só funciona com mode 'redirect'.
114
- });
115
- ```
97
+ // 1. Iniciar login — o navegador navega para fora da página
98
+ await loginWithGoogleMitra({ mode: 'redirect' });
116
99
 
117
- ### Fluxo de Criar Conta
118
-
119
- ```typescript
120
- // create funciona tanto em popup quanto redirect
121
- await loginMitra('email', { create: true });
122
-
123
- await loginMitra('mitra', {
124
- mode: 'redirect',
125
- create: true, // Abre direto no modo cadastro
126
- returnTo: '/onboarding',
127
- title: 'Meu App'
128
- });
100
+ // 2. No boot do app, se houver #codeMitra/#stateMitra no fragment:
101
+ const session = await exchangeSsoCodeMitra({ code, state });
102
+ // A SDK valida o nonce (anti-CSRF), troca o code no BFF e configura o SDK.
129
103
  ```
130
104
 
131
105
  ### Token Refresh Automático
@@ -147,39 +121,6 @@ configureSdkMitra({
147
121
  });
148
122
  ```
149
123
 
150
- ### Login por Email (iframe silencioso)
151
-
152
- Para quem precisa montar sua **própria tela de login** (sem popup/redirect), o SDK oferece funções que fazem a autenticação via iframe invisível. As credenciais são enviadas ao HTML de auth via `postMessage` — sem CORS, sem expor a API.
153
-
154
- #### emailSignupMitra
155
-
156
- Cria conta. No novo Mitra o signup é direto (sem código de verificação) — em seguida, chame `emailLoginMitra`.
157
-
158
- ```typescript
159
- import { emailSignupMitra } from 'mitra-interactions-sdk';
160
-
161
- await emailSignupMitra({
162
- name: 'João Silva',
163
- email: 'joao@email.com',
164
- password: 'minhasenha123'
165
- });
166
- // Não retorna token — em seguida, faça login com emailLoginMitra
167
- ```
168
-
169
- #### emailLoginMitra
170
-
171
- Login direto com email e senha. Retorna `LoginResponse` e auto-configura o SDK.
172
-
173
- ```typescript
174
- import { emailLoginMitra } from 'mitra-interactions-sdk';
175
-
176
- const session = await emailLoginMitra({
177
- email: 'joao@email.com',
178
- password: 'minhasenha123'
179
- });
180
- // session: { token, baseURL, integrationURL? }
181
- ```
182
-
183
124
  ## Métodos Disponíveis
184
125
 
185
126
  ### executeServerFunctionMitra
@@ -230,19 +171,24 @@ const result = await stopServerFunctionExecutionMitra({
230
171
  // result: { status, result: { executionId, executionStatus: "CANCELLED" | "ALREADY_FINISHED" } }
231
172
  ```
232
173
 
233
- ### executeDataLoaderMitra
174
+ ### Server Functions Públicas (sem autenticação)
234
175
 
235
- Executa um Data Loader cadastrado no projeto.
176
+ A SF deve ter `publicExecution = true` (via `togglePublicExecutionMitra` do mitra-sdk). Não exigem token.
236
177
 
237
178
  ```typescript
238
- import { executeDataLoaderMitra } from 'mitra-interactions-sdk';
179
+ import {
180
+ executePublicServerFunctionMitra,
181
+ executePublicServerFunctionAsyncMitra,
182
+ getPublicServerFunctionExecutionMitra
183
+ } from 'mitra-interactions-sdk';
239
184
 
240
- const result = await executeDataLoaderMitra({
241
- projectId: 123,
242
- dataLoaderId: 5,
243
- input: { mes: 1, ano: 2025 } // Opcional — parâmetros {{var}} da query
244
- });
245
- // result: { status, result: { dataLoaderId, executionLog: { timestamp, rowCount, query, status, fileSize?, duration? }, message } }
185
+ // Síncrona (timeout 5min)
186
+ const res = await executePublicServerFunctionMitra({ projectId, serverFunctionId, input: { x: 1 } });
187
+ // { executionId, status, output, logs, error, durationMs }
188
+
189
+ // Assíncrona + polling
190
+ const async1 = await executePublicServerFunctionAsyncMitra({ projectId, serverFunctionId });
191
+ const status = await getPublicServerFunctionExecutionMitra({ projectId, executionId: async1.executionId });
246
192
  ```
247
193
 
248
194
  ### Dynamic Schema CRUD
package/dist/index.d.mts CHANGED
@@ -233,6 +233,8 @@ interface MitraConfig {
233
233
  integrationURL?: string;
234
234
  /** URL da página de autenticação Mitra (ex: https://coder.mitralab.io/sdk-auth/) */
235
235
  authUrl?: string;
236
+ /** URL da página do popup de SSO (sdk-auth.html). Opcional se houver window.__mitraEnv.authPageUrl. */
237
+ authPageUrl?: string;
236
238
  /** ID do projeto (usado como fallback nos métodos de login e serviços) */
237
239
  projectId?: number | string;
238
240
  /** Callback chamado quando o token é renovado automaticamente (após 401/403). Recebe a nova sessão. */
package/dist/index.d.ts CHANGED
@@ -233,6 +233,8 @@ interface MitraConfig {
233
233
  integrationURL?: string;
234
234
  /** URL da página de autenticação Mitra (ex: https://coder.mitralab.io/sdk-auth/) */
235
235
  authUrl?: string;
236
+ /** URL da página do popup de SSO (sdk-auth.html). Opcional se houver window.__mitraEnv.authPageUrl. */
237
+ authPageUrl?: string;
236
238
  /** ID do projeto (usado como fallback nos métodos de login e serviços) */
237
239
  projectId?: number | string;
238
240
  /** Callback chamado quando o token é renovado automaticamente (após 401/403). Recebe a nova sessão. */
package/dist/index.js CHANGED
@@ -224,6 +224,8 @@ var POPUP_H = 600;
224
224
  var POPUP_TIMEOUT_MS = 5 * 60 * 1e3;
225
225
  var SSO_AUTH_PAGE_URL = "https://stg.mitralab.io/sdk-auth.html";
226
226
  async function fetchSsoAuthPageUrl(_baseURL) {
227
+ const config = isConfigured() ? getConfig() : null;
228
+ if (config == null ? void 0 : config.authPageUrl) return config.authPageUrl;
227
229
  return SSO_AUTH_PAGE_URL;
228
230
  }
229
231
  var SSO_ENABLED_PROVIDERS = ["google"];
@@ -785,6 +787,7 @@ function readInjectedEnv() {
785
787
  if (typeof env.apiBaseURL === "string" && env.apiBaseURL) out.baseURL = env.apiBaseURL;
786
788
  if (typeof env.integrationURL === "string" && env.integrationURL) out.integrationURL = env.integrationURL;
787
789
  if (typeof env.authUrl === "string" && env.authUrl) out.authUrl = env.authUrl;
790
+ if (typeof env.authPageUrl === "string" && env.authPageUrl) out.authPageUrl = env.authPageUrl;
788
791
  return out;
789
792
  }
790
793
  function configureSdkMitra(config = {}) {