@mitralab.io/platform-sdk 1.0.8 → 1.1.0-beta.0
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/CHANGELOG.md +49 -0
- package/LICENSE +21 -0
- package/README.md +251 -108
- package/dist/index.cjs +1835 -0
- package/dist/index.d.cts +966 -0
- package/dist/index.d.ts +409 -102
- package/dist/index.js +1238 -160
- package/package.json +29 -11
- package/dist/index.d.mts +0 -659
- package/dist/index.mjs +0 -706
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
## 1.1.0-beta.0
|
|
6
|
+
|
|
7
|
+
- Complete native Function sync, async, polling, cancellation, and anonymous public execution.
|
|
8
|
+
- Expose browser-safe Agent Tasks, restricted Agent Credentials, and model discovery through Core 0.2 contracts.
|
|
9
|
+
- Compose the Core-owned Agent task session manager with Platform WebSocket and HTTP/SSE adapters.
|
|
10
|
+
- Add native anonymous polling for executions created by the public async Function route.
|
|
11
|
+
- Keep business-Agent administration out of the browser adapter according to the app-role permission matrix.
|
|
12
|
+
- Expose app-scoped integration config listing and execution by alias from Core 0.2.
|
|
13
|
+
- Document the missing producer contract for native record selection by `jdbcConnectionConfigId` instead of inventing a browser-side translation.
|
|
14
|
+
- Document that entity `update` already implements the producer's partial PUT semantics, so no duplicate PATCH method is needed.
|
|
15
|
+
- Derive Function execution, integration proxy input, and custom query result types directly from Core without narrowing nullable or producer-returned fields.
|
|
16
|
+
- Preserve the complete Data Manager record envelope and execute Custom Queries with only
|
|
17
|
+
producer parameters, without a caller-selected Data Source or an `init()` precondition.
|
|
18
|
+
|
|
19
|
+
- Refresh app sessions proactively through IAM before authenticated native requests, with a 30-second JWT expiry heuristic and one shared refresh flight.
|
|
20
|
+
- Preserve sessions on transient refresh failures, clear them on definitive IAM client failures, and retain the one-time reactive `401` retry.
|
|
21
|
+
- Rotate both tokens without fetching the current user or notifying public auth-state listeners, while keeping the legacy bridge synchronized.
|
|
22
|
+
- Reject decodable access and refresh tokens whose app scope is missing or differs from the configured app while keeping opaque tokens server-authoritative.
|
|
23
|
+
- Fence refresh responses by session generation so late success or failure cannot undo sign-out or overwrite a newer login or bridged session.
|
|
24
|
+
- Bind reactive `401` handling to the token used by the rejected request so an old response cannot refresh or clear a replacement session.
|
|
25
|
+
- Redact values under sensitive credential field names from recursive API error details.
|
|
26
|
+
- Preserve the retained session when `auth.me()` reaches `401` after transient proactive and reactive refresh failures.
|
|
27
|
+
- Add native Google SSO through popup and redirect flows with direct IAM code exchange.
|
|
28
|
+
- Validate Google SSO origin, popup source, one-time state, cancellation, timeout, and token response shape.
|
|
29
|
+
- Require redirect errors to bind to the stored state before exposing or consuming them.
|
|
30
|
+
- Keep Google options limited to popup or redirect mode; account creation and locale remain producer concerns.
|
|
31
|
+
- Leave legacy-only `returnTo` and `title` on the deprecated aliases because the old runtime did not implement them as native Google controls.
|
|
32
|
+
- Preserve the email/password methods already public in Platform SDK 1.0.9 without presenting them as the new template flow.
|
|
33
|
+
- Route deprecated calls and legacy authentication through `${apiUrl}/legacy`.
|
|
34
|
+
- Apply the native auth page URL precedence to the deprecated SSO bridge.
|
|
35
|
+
- Propagate native sign-in, refresh, token changes, and sign-out to the legacy SDK session.
|
|
36
|
+
- Re-export the deprecated `mitra-interactions-sdk` surface from the package entrypoint.
|
|
37
|
+
- Mark every legacy type alias as deprecated in generated declarations.
|
|
38
|
+
- Share one session between this SDK and the legacy SDK in both directions.
|
|
39
|
+
- Make the SonarCloud job wait for the Quality Gate result.
|
|
40
|
+
- Align the public package metadata and ESM, CommonJS, and TypeScript artifacts.
|
|
41
|
+
- Add package shape checks and public tarball smoke coverage.
|
|
42
|
+
- Correct public imports and required configuration in documentation examples.
|
|
43
|
+
- Add the MIT license.
|
|
44
|
+
|
|
45
|
+
## 1.0.8
|
|
46
|
+
|
|
47
|
+
- Share environment-neutral API contracts through `@mitralab.io/sdk-core`.
|
|
48
|
+
- Preserve the Platform SDK 1.x browser authentication and entity facade.
|
|
49
|
+
- Validate redirects, API errors, sensitive-value redaction, and package consumers.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mitra Platform
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -3,197 +3,340 @@
|
|
|
3
3
|
[](https://sonarcloud.io/summary/new_code?id=mitra-platform-sdk)
|
|
4
4
|
[](https://sonarcloud.io/summary/new_code?id=mitra-platform-sdk)
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
JavaScript and TypeScript SDK for browser applications built on the Mitra Platform. Applications generated by Code Studio use this package to authenticate users, access Data Manager entities, execute Server Functions and custom queries, call integrations, and run live Agent tasks.
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
The browser transport uses standard Web APIs only, including `fetch`, `WebSocket`, `ReadableStream`, `AbortController`, browser storage, `URL`, `Proxy`, `crypto`, and `atob`. Shared contracts and API modules come from `@mitralab.io/sdk-core`, without bringing browser authentication into the Core package.
|
|
9
9
|
|
|
10
|
-
##
|
|
11
|
-
|
|
12
|
-
- Client único criado por `createClient`.
|
|
13
|
-
- Auth com login, cadastro, refresh token, logout e estado em `localStorage`.
|
|
14
|
-
- CRUD dinâmico em tabelas via `mitra.entities.<TableName>`.
|
|
15
|
-
- Execução de server functions publicadas.
|
|
16
|
-
- Execução de custom queries.
|
|
17
|
-
- Proxy de integrações e resources com credential injection no servidor.
|
|
18
|
-
- Tipos TypeScript exportados para os contratos principais.
|
|
19
|
-
|
|
20
|
-
## Instalação
|
|
10
|
+
## Installation
|
|
21
11
|
|
|
22
12
|
```bash
|
|
23
13
|
npm install @mitralab.io/platform-sdk
|
|
24
14
|
```
|
|
25
15
|
|
|
26
|
-
|
|
16
|
+
Node.js 18 or newer is required for development and server-side tooling. The runtime application must provide the browser Web APIs used by the SDK.
|
|
17
|
+
|
|
18
|
+
## Quick start
|
|
27
19
|
|
|
28
20
|
```typescript
|
|
29
|
-
import { createClient } from
|
|
21
|
+
import { createClient } from "@mitralab.io/platform-sdk"
|
|
30
22
|
|
|
31
23
|
export const mitra = createClient({
|
|
32
24
|
appId: import.meta.env.VITE_MITRA_APP_ID,
|
|
33
25
|
apiUrl: import.meta.env.VITE_MITRA_API_URL,
|
|
34
26
|
onError: (error) => console.error(error.status, error.code, error.message),
|
|
35
|
-
})
|
|
27
|
+
})
|
|
36
28
|
|
|
37
|
-
await mitra.init()
|
|
29
|
+
await mitra.init()
|
|
38
30
|
```
|
|
39
31
|
|
|
40
|
-
`init()`
|
|
32
|
+
`init()` resolves the application's public Code Studio configuration, including nullable
|
|
33
|
+
`dataSourceId` and `allowSignup`. The Data Source value remains part of the Platform 1.x
|
|
34
|
+
compatibility flow; native Entities and Custom Queries resolve the current app through the
|
|
35
|
+
authenticated request. Call `init()` during application startup before the compatibility sign-up
|
|
36
|
+
method needs `allowSignup`.
|
|
37
|
+
|
|
38
|
+
## Configuration
|
|
39
|
+
|
|
40
|
+
| Field | Required | Description |
|
|
41
|
+
|---|---|---|
|
|
42
|
+
| `appId` | yes | ID of the published Code Studio application. |
|
|
43
|
+
| `apiUrl` | yes | Base URL of the Mitra API gateway. |
|
|
44
|
+
| `authPageUrl` | no | Absolute URL of `sdk-auth.html`. Falls back to `window.__mitraEnv.authPageUrl`, then `/sdk-auth.html` on the `apiUrl` origin. |
|
|
45
|
+
| `onError` | no | Global callback for API errors. |
|
|
46
|
+
|
|
47
|
+
The client derives service endpoints from `apiUrl`: `/iam`, `/data-manager`, `/functions`, `/integration`, `/copilot`, and `/code-studio`.
|
|
41
48
|
|
|
42
|
-
##
|
|
49
|
+
## Boundary
|
|
43
50
|
|
|
44
|
-
|
|
45
|
-
| --------- | ----------- | ---------------------------------- |
|
|
46
|
-
| `appId` | sim | ID do app publicado no Code Studio |
|
|
47
|
-
| `apiUrl` | sim | URL base do Kong/API da plataforma |
|
|
48
|
-
| `onError` | não | callback global para erros de API |
|
|
51
|
+
The Platform SDK owns:
|
|
49
52
|
|
|
50
|
-
|
|
53
|
+
- browser Google SSO, logout, and session refresh
|
|
54
|
+
- trusted session adoption for the embedded app preview
|
|
55
|
+
- session persistence in `localStorage`
|
|
56
|
+
- auth-state listeners
|
|
57
|
+
- proactive token refresh before authenticated native requests
|
|
58
|
+
- one retry after reactive `401` recovery with the current session
|
|
59
|
+
- browser HTTP transport and public application initialization
|
|
60
|
+
- Agent WebSocket and HTTP/SSE live channels
|
|
51
61
|
|
|
52
|
-
|
|
62
|
+
`@mitralab.io/sdk-core` owns the shared entities, custom queries, Functions, integrations, Agent task lifecycle, `auth.me`, safe paths, and structural response validation. Server Function code should use `@mitralab.io/functions-sdk` instead of this browser SDK.
|
|
63
|
+
|
|
64
|
+
## Authentication
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
const user = await mitra.auth.signInWithGoogle({ mode: "popup" })
|
|
68
|
+
|
|
69
|
+
const unsubscribe = mitra.auth.onAuthStateChange((currentUser) => {
|
|
70
|
+
console.log(currentUser?.email)
|
|
71
|
+
})
|
|
53
72
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
├── client.ts # createClient, composição dos módulos e init
|
|
57
|
-
├── modules/ # auth de browser e fachadas compatíveis com a API 1.x
|
|
58
|
-
├── utils/http-client # fetch wrapper, auth header, retry 401 e MitraApiError
|
|
59
|
-
└── index.ts # exports públicos
|
|
73
|
+
mitra.auth.signOut("/login")
|
|
74
|
+
unsubscribe()
|
|
60
75
|
```
|
|
61
76
|
|
|
62
|
-
|
|
77
|
+
Authentication state is stored under `mitra_auth_{appId}`. Before each authenticated native request, the SDK checks a JWT's `exp` claim with a 30-second safety window and refreshes directly through IAM when needed. Opaque tokens, malformed JWTs, and JWTs without a numeric `exp` remain server-authoritative and proceed to the request. A `401` still triggers reactive recovery and at most one retry. If another login or bridged session replaced the token while the request was in flight, the retry uses that current token without refreshing its session. If sign-out cleared the token, the old `401` neither refreshes nor retries.
|
|
63
78
|
|
|
64
|
-
|
|
79
|
+
The generated-application authentication flow is Google SSO. The old native `signIn` and `signUp` names fail locally with `UNSUPPORTED_AUTH_METHOD` because IAM has no email/password endpoints. Deprecated login bindings remain available only through the legacy reexports.
|
|
65
80
|
|
|
66
|
-
|
|
67
|
-
| ------------- | --------------------------------------------------------------------------------------- |
|
|
68
|
-
| `auth` | `signIn`, `signUp`, `signOut`, `refreshSession`, `me`, `checkAuth`, `onAuthStateChange` |
|
|
69
|
-
| `entities` | CRUD dinâmico por tabela, filtro, paginação, bulk create e deleteMany |
|
|
70
|
-
| `functions` | disparo de server function por ID com a semântica assíncrona da API 1.x |
|
|
71
|
-
| `queries` | execução de custom query por ID com parâmetros |
|
|
72
|
-
| `integration` | execução de integration resource ou proxy direto por config |
|
|
81
|
+
An embedded preview can adopt the app-scoped session it receives from the platform without exchanging it:
|
|
73
82
|
|
|
74
|
-
|
|
83
|
+
```typescript
|
|
84
|
+
mitra.auth.setSession({ accessToken, refreshToken })
|
|
85
|
+
await mitra.auth.checkAuth()
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Proactive and reactive callers share one in-flight refresh. Successful refresh rotates and persists both tokens and updates the legacy session bridge without calling `auth.me()` or notifying public auth-state listeners. A refresh response that arrives after sign-out or after another login/session replacement is discarded and cannot restore or overwrite that newer state. Network failures, `408`, `429`, and `5xx` responses preserve the current session; the original HTTP request proceeds with the current token so a later `401` can use the reactive fallback. `auth.me()` also preserves that retained session when the fallback refresh is transient. Other IAM `4xx` responses are definitive and clear the session.
|
|
89
|
+
|
|
90
|
+
JWT decoding is not user authentication. It schedules refresh and prevents cross-app session adoption. Every decodable access and refresh token must contain `app_id` exactly equal to the client's configured `appId`; opaque tokens are kept for rollout compatibility and remain validated by the server.
|
|
91
|
+
|
|
92
|
+
Custom WebSocket or Server-Sent Events boundaries can refresh explicitly before connecting:
|
|
75
93
|
|
|
76
94
|
```typescript
|
|
77
|
-
const
|
|
78
|
-
email: 'user@example.com',
|
|
79
|
-
password: 'password123',
|
|
80
|
-
});
|
|
95
|
+
const fresh = await mitra.auth.ensureFreshSession(30_000)
|
|
81
96
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
97
|
+
if (!fresh) {
|
|
98
|
+
// A required refresh failed. The SDK may still retain the session after a
|
|
99
|
+
// transient failure, but this boundary can choose whether to connect.
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`ensureFreshSession()` returns `true` when the token does not need refresh or refresh succeeds. It returns `false` when a required refresh fails, including a transient failure that intentionally preserves the current session.
|
|
104
|
+
|
|
105
|
+
Google SSO uses a popup by default. The SDK opens `sdk-auth.html`, validates the popup source, origin, and one-time state, exchanges the returned code directly with IAM, stores both tokens, and fetches the current user:
|
|
85
106
|
|
|
86
|
-
|
|
87
|
-
|
|
107
|
+
```typescript
|
|
108
|
+
const user = await mitra.auth.signInWithGoogle({ mode: "popup" })
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
The public Google options contain only `mode`. Account creation and locale are producer concerns, so the SDK does not send `create` or `language` to IAM. During rollout, the popup also accepts the older auth page token response.
|
|
112
|
+
|
|
113
|
+
Deprecated `LoginOptions` still preserve `returnTo` and `title` for source compatibility. They are not copied into the new Google API: the legacy runtime never read `title`, did not pass caller `returnTo` into popup login, and hardcoded the current URL for redirect login.
|
|
114
|
+
|
|
115
|
+
Redirect mode stores the one-time state and options in `sessionStorage`. Complete it during application startup before rendering authenticated routes:
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
const redirectedUser = await mitra.auth.completeGoogleSignInRedirect()
|
|
119
|
+
|
|
120
|
+
if (!redirectedUser) {
|
|
121
|
+
await mitra.auth.signInWithGoogle({ mode: "redirect" })
|
|
122
|
+
}
|
|
88
123
|
```
|
|
89
124
|
|
|
90
|
-
|
|
125
|
+
Redirect errors are accepted only when `stateMitra` matches the stored one-time state. A missing or mismatched state leaves the fragment and redirect context untouched and does not expose `errorMitra`. The current alpha `sdk-auth.html` error redirect omits `stateMitra`, so those error redirects are intentionally rejected until that producer echoes the state; popup errors already carry state and are unaffected.
|
|
126
|
+
|
|
127
|
+
Configure the auth page explicitly when it is hosted outside the API gateway origin:
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
const mitra = createClient({
|
|
131
|
+
appId,
|
|
132
|
+
apiUrl,
|
|
133
|
+
authPageUrl: "https://app.example.com/sdk-auth.html",
|
|
134
|
+
})
|
|
135
|
+
```
|
|
91
136
|
|
|
92
137
|
## Entities
|
|
93
138
|
|
|
94
139
|
```typescript
|
|
95
140
|
type Task = {
|
|
96
|
-
id: string
|
|
97
|
-
title: string
|
|
98
|
-
status:
|
|
99
|
-
}
|
|
141
|
+
id: string
|
|
142
|
+
title: string
|
|
143
|
+
status: "pending" | "done"
|
|
144
|
+
}
|
|
100
145
|
|
|
101
|
-
const tasks = await mitra.entities.getTable<Task>(
|
|
102
|
-
sort:
|
|
146
|
+
const { data: tasks } = await mitra.entities.getTable<Task>("Task").list({
|
|
147
|
+
sort: "-created_at",
|
|
103
148
|
limit: 10,
|
|
104
|
-
fields: [
|
|
105
|
-
})
|
|
149
|
+
fields: ["id", "title", "status"],
|
|
150
|
+
})
|
|
106
151
|
|
|
107
|
-
const pending = await mitra.entities.Task.filter({ status:
|
|
108
|
-
const created = await mitra.entities.Task.create({ title:
|
|
109
|
-
await mitra.entities.Task.update(created.id, { status:
|
|
110
|
-
await mitra.entities.Task.delete(created.id)
|
|
152
|
+
const pending = await mitra.entities.Task.filter({ status: "pending" })
|
|
153
|
+
const created = await mitra.entities.Task.create({ title: "New task" })
|
|
154
|
+
await mitra.entities.Task.update(created.id, { status: "done" })
|
|
155
|
+
await mitra.entities.Task.delete(created.id)
|
|
111
156
|
```
|
|
112
157
|
|
|
113
|
-
Table names
|
|
158
|
+
Table names are case-sensitive and must match the Data Manager table name. Record operations use `/api/v1/tables/{table}/records`. Application and tenant scope come from the authenticated context, not from a data source in the path.
|
|
159
|
+
|
|
160
|
+
The native producer does not accept `jdbcConnectionConfigId` or `dataSourceId` on public record requests. The deprecated record helpers still expose their legacy arguments, but there is no native equivalent until Data Manager defines an app-safe backend contract. The SDK does not translate those arguments into query parameters or SQL.
|
|
114
161
|
|
|
115
|
-
|
|
162
|
+
`update(id, fields)` sends the Data Manager PUT contract, which applies the supplied fields as a partial record update and preserves omitted fields. A separate `patch` alias would duplicate that producer behavior, so the native surface keeps one method.
|
|
116
163
|
|
|
117
|
-
## Functions
|
|
164
|
+
## Server Functions
|
|
118
165
|
|
|
119
166
|
```typescript
|
|
120
|
-
const execution = await mitra.functions.execute(
|
|
121
|
-
orderId:
|
|
122
|
-
})
|
|
167
|
+
const execution = await mitra.functions.execute("function-id", {
|
|
168
|
+
orderId: "order-123",
|
|
169
|
+
})
|
|
123
170
|
|
|
124
|
-
console.log(execution.id, execution.status)
|
|
171
|
+
console.log(execution.id, execution.status)
|
|
125
172
|
```
|
|
126
173
|
|
|
127
|
-
|
|
174
|
+
`execute` sends `X-Invocation-Type: sync` and waits for the terminal result. `executeAsync` sends `async` and returns the initial execution for polling or cancellation.
|
|
128
175
|
|
|
129
|
-
|
|
176
|
+
The complete native lifecycle is also available. `getExecution` is kept because the Functions producer exposes execution polling and Agent consumers use it:
|
|
130
177
|
|
|
131
178
|
```typescript
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
179
|
+
const queued = await mitra.functions.executeAsync("function-id", { orderId: "order-123" })
|
|
180
|
+
const current = await mitra.functions.getExecution(queued.id)
|
|
181
|
+
await mitra.functions.cancelExecution(current.id)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Public Functions use a separate anonymous transport. It never adds `Authorization` or `X-App-Id`:
|
|
135
185
|
|
|
136
|
-
|
|
186
|
+
```typescript
|
|
187
|
+
const result = await mitra.publicFunctions.execute("public-function-id", { sku: "A-1" })
|
|
188
|
+
const queuedPublic = await mitra.publicFunctions.executeAsync("public-function-id", { sku: "A-1" })
|
|
137
189
|
```
|
|
138
190
|
|
|
139
|
-
|
|
191
|
+
Public async execution is fire-and-forget. The public API does not expose anonymous polling or
|
|
192
|
+
cancellation. Use synchronous `publicFunctions.execute` when the screen needs the result, or the
|
|
193
|
+
authenticated `functions.executeAsync` plus `functions.getExecution` flow after login.
|
|
140
194
|
|
|
141
|
-
|
|
195
|
+
## Agent tasks and credentials
|
|
196
|
+
|
|
197
|
+
The browser-safe Copilot modules call the native service directly. `agentTasks` provides list, read, create, rename, archive, HTTP input, history, and live sessions. These direct primitives match the Copilot producer and MCP contract. Core owns session state, queueing, recovery, and reconciliation; Platform supplies only authenticated browser WebSocket/SSE channels. `agentCredentials` provides safe credential status, model discovery, API key, OAuth, and device authorization flows. Raw credentials are write-only.
|
|
142
198
|
|
|
143
199
|
```typescript
|
|
144
|
-
const
|
|
145
|
-
|
|
200
|
+
const credentials = await mitra.agentCredentials.list()
|
|
201
|
+
const models = await mitra.agentCredentials.listModels()
|
|
202
|
+
const chats = await mitra.agentTasks.list({ archived: false, size: 20 })
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Create a live task lazily on the first message:
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
const session = mitra.agentTasks.session({
|
|
209
|
+
create: true,
|
|
210
|
+
agentType: models[0].agentType,
|
|
211
|
+
reasoningEffort: models[0].reasoningOptions[0],
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
const unsubscribe = session.on("delta", ({ delta, kind }) => {
|
|
215
|
+
console.log(kind, delta)
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
session.send("Analyze this application")
|
|
219
|
+
session.respondApproval(true)
|
|
220
|
+
await session.cancel()
|
|
221
|
+
unsubscribe()
|
|
222
|
+
session.close()
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Open an existing task with `session({ taskId })`. The default `auto` transport refreshes before connecting, opens `/copilot/ws/tasks/{taskId}`, and performs at most one safe recovery through persisted history plus the HTTP/SSE channel. Set `transport: "http"` when WebSockets are unavailable. Messages sent during a turn enter a FIFO queue with a maximum of 10 items; the session also exposes edit, remove, clear, approval, cancel, history, close, and typed events.
|
|
226
|
+
|
|
227
|
+
API keys and removal accept `ANTHROPIC` or `OPENAI`. OAuth accepts only `ANTHROPIC`; device authorization accepts only `OPENAI`. The facade enforces those producer-supported pairs in TypeScript and at runtime.
|
|
228
|
+
|
|
229
|
+
The browser token roles expose Agent tasks, credential status, and model discovery. Administrative business-Agent CRUD is intentionally not exposed by this adapter because the `USE` app role does not carry `AGENT_*` authority.
|
|
230
|
+
|
|
231
|
+
## Custom queries
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
const result = await mitra.queries.execute("query-id", {
|
|
235
|
+
status: "active",
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
console.log(result.rows, result.affectedRows)
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Custom Query execution sends only `parameters`. Data Manager resolves its Data Source from the
|
|
242
|
+
authenticated app, so Queries work without a caller-selected `dataSourceId` and do not depend on
|
|
243
|
+
`init()`.
|
|
244
|
+
|
|
245
|
+
## Integrations
|
|
246
|
+
|
|
247
|
+
List the current app's saved configs without exposing the Core admin module:
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
const configs = await mitra.integration.list({ page: 0, size: 20, sort: "alias,asc" })
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
The Integration producer derives the app from the authenticated token, so this list is app-scoped.
|
|
254
|
+
|
|
255
|
+
Execute a predefined resource:
|
|
256
|
+
|
|
257
|
+
```typescript
|
|
258
|
+
const result = await mitra.integration.executeResource("resource-id", {
|
|
259
|
+
description: "Notebook",
|
|
146
260
|
limit: 10,
|
|
147
|
-
})
|
|
261
|
+
})
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Or execute an integration config directly:
|
|
265
|
+
|
|
266
|
+
```typescript
|
|
267
|
+
const result = await mitra.integration.execute("config-id", {
|
|
268
|
+
method: "GET",
|
|
269
|
+
endpoint: "/users",
|
|
270
|
+
queryParams: { limit: "10" },
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
console.log(result.status, result.body)
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
An app can also address a saved config by its app-scoped alias:
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
const result = await mitra.integration.executeByAlias("billing", {
|
|
280
|
+
method: "POST",
|
|
281
|
+
endpoint: "/invoices",
|
|
282
|
+
body: { customerId: "customer-1" },
|
|
283
|
+
})
|
|
148
284
|
```
|
|
149
285
|
|
|
150
|
-
|
|
286
|
+
Integration credentials are injected by the Integration service. Do not pass provider credentials through browser input.
|
|
287
|
+
|
|
288
|
+
## Legacy surface
|
|
289
|
+
|
|
290
|
+
The public surface of `mitra-interactions-sdk` is re-exported from this package so an application can replace the legacy dependency without rewriting its call sites. Runtime re-exports are marked `@deprecated` and name their replacement, or state that no replacement exists yet. Every legacy type is an identity-preserving alias marked as a deprecated compatibility type.
|
|
151
291
|
|
|
152
292
|
```typescript
|
|
153
|
-
|
|
154
|
-
method: 'GET',
|
|
155
|
-
endpoint: '/users',
|
|
156
|
-
queryParams: { limit: '10' },
|
|
157
|
-
});
|
|
293
|
+
import { createClient, loginWithGoogleMitra } from "@mitralab.io/platform-sdk"
|
|
158
294
|
|
|
159
|
-
|
|
295
|
+
export const mitra = createClient({ appId, apiUrl })
|
|
296
|
+
|
|
297
|
+
await loginWithGoogleMitra()
|
|
298
|
+
console.log(mitra.auth.accessToken)
|
|
160
299
|
```
|
|
161
300
|
|
|
162
|
-
|
|
301
|
+
Google SSO is available through `mitra.auth.signInWithGoogle` and `mitra.auth.completeGoogleSignInRedirect`. Agent tasks, Agent credentials, public Functions, entities, custom queries, Function execution, and integrations now have native replacements. Microsoft SSO remains available only through the complete deprecated re-export surface.
|
|
302
|
+
|
|
303
|
+
`createClient` configures the legacy SDK with both `baseURL` and `authUrl` set to `${apiUrl}/legacy`, after removing trailing slashes, plus `projectId: appId`. This keeps deprecated calls and legacy login routed through the BFF while the new modules call their native APIs directly. Its `authPageUrl` uses the same precedence as native Google SSO: explicit client config, `window.__mitraEnv.authPageUrl`, then `/sdk-auth.html` on the `apiUrl` origin. Existing query parameters are preserved.
|
|
163
304
|
|
|
164
|
-
|
|
305
|
+
The bridge shares the session in both directions. A session persisted under `mitra_auth_{appId}` is handed to the legacy SDK at startup; native sign-in, Google SSO, proactive or reactive refresh, manual token changes, and sign-out update its active configuration. Sessions produced by legacy login or refresh are persisted back under the same new storage key. The bridge only propagates sessions the two SDKs produce: it never starts a login and never triggers a refresh of its own.
|
|
306
|
+
|
|
307
|
+
The legacy package exposes no sign-out API for deleting the refresh token stored in its private `mitra-session` entry. Native sign-out safely removes both credentials from the active legacy configuration, so deprecated calls cannot authenticate or refresh. A later direct call to `configureSdkMitra` can restore that private persisted refresh token; applications should keep configuration ownership in `createClient` during the migration.
|
|
308
|
+
|
|
309
|
+
The legacy SDK does not return a user, so `auth.currentUser` stays empty after a legacy login. Call `mitra.auth.me()` to populate it. Calling `configureSdkMitra` directly replaces the legacy configuration and its refresh hook until the next bridged session change, so it should not be mixed with a client-managed migration.
|
|
310
|
+
|
|
311
|
+
## Errors and request behavior
|
|
312
|
+
|
|
313
|
+
API failures throw `MitraApiError`:
|
|
165
314
|
|
|
166
315
|
```typescript
|
|
167
|
-
import { MitraApiError } from
|
|
316
|
+
import { MitraApiError } from "@mitralab.io/platform-sdk"
|
|
168
317
|
|
|
169
318
|
try {
|
|
170
|
-
await mitra.entities.Task.get(
|
|
319
|
+
await mitra.entities.Task.get("missing-id")
|
|
171
320
|
} catch (error) {
|
|
172
321
|
if (error instanceof MitraApiError) {
|
|
173
|
-
console.error(error.status, error.code, error.message)
|
|
322
|
+
console.error(error.status, error.code, error.message)
|
|
174
323
|
}
|
|
175
324
|
}
|
|
176
325
|
```
|
|
177
326
|
|
|
178
|
-
|
|
179
|
-
marcadas como redirecionadas falham sem replay. A única repetição automática é
|
|
180
|
-
a tentativa única após refresh bem-sucedido em resposta 401.
|
|
327
|
+
The transport refuses HTTP redirects. Statuses `307` and `308`, opaque redirects, and responses already marked as redirected fail without replay. The only automatic replay is the single request attempted after reactive `401` recovery with either a refreshed token or a session that changed while the original request was in flight.
|
|
181
328
|
|
|
182
|
-
|
|
183
|
-
qualquer credencial no formato `Bearer` de `message`, `code` e `details`,
|
|
184
|
-
percorrendo recursivamente valores, arrays e chaves de objetos.
|
|
329
|
+
Before constructing `MitraApiError`, the SDK recursively redacts the token used by the request and credentials in `Bearer` format from the error message, code, details, arrays, values, and object keys. Values under credential fields such as `accessToken`, `refreshToken`, `apiKey`, `password`, `authorization`, `secret`, and `clientSecret` are also replaced with `[REDACTED]`.
|
|
185
330
|
|
|
186
|
-
##
|
|
331
|
+
## Development
|
|
187
332
|
|
|
188
333
|
```bash
|
|
189
334
|
npm install
|
|
190
|
-
npm run
|
|
191
|
-
npm run lint
|
|
192
|
-
npm test
|
|
335
|
+
npm run check
|
|
193
336
|
```
|
|
194
337
|
|
|
195
|
-
`@mitralab.io/sdk-core@0.
|
|
196
|
-
|
|
197
|
-
`
|
|
338
|
+
Platform `1.1.0-beta.0` targets exactly `@mitralab.io/sdk-core@0.2.0-beta.0`. Until that Core prerelease is published, local validation uses its matching tarball through `MITRA_SDK_CORE_TARBALL`. The manifest and lock keep the registry spec and the tarball's verified integrity; root `npm ci` becomes available after Core is published. Do not commit a `file:` dependency.
|
|
339
|
+
|
|
340
|
+
The build produces ESM, CommonJS, `.d.ts`, and `.d.cts` artifacts. Package checks inspect the public tarball with Are The Types Wrong, install it into an isolated consumer, and validate ESM, CommonJS, and TypeScript resolution.
|
|
198
341
|
|
|
199
|
-
|
|
342
|
+
See [CHANGELOG.md](CHANGELOG.md) for release history and [LICENSE](LICENSE) for license terms.
|