@mitralab.io/platform-sdk 1.0.7 → 1.0.9

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 ADDED
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ ## Unreleased
6
+
7
+ - Make the SonarCloud job wait for the Quality Gate result.
8
+ - Align the public package metadata and ESM, CommonJS, and TypeScript artifacts.
9
+ - Add package shape checks and public tarball smoke coverage.
10
+ - Correct public imports and required configuration in documentation examples.
11
+ - Add the MIT license.
12
+
13
+ ## 1.0.8
14
+
15
+ - Share environment-neutral API contracts through `@mitralab.io/sdk-core`.
16
+ - Preserve the Platform SDK 1.x browser authentication and entity facade.
17
+ - 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,148 +3,173 @@
3
3
  [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=mitra-platform-sdk&metric=alert_status&token=28d7be14b66d6f88d706347e2418af5ea39ab3e9)](https://sonarcloud.io/summary/new_code?id=mitra-platform-sdk)
4
4
  [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=mitra-platform-sdk&metric=coverage&token=28d7be14b66d6f88d706347e2418af5ea39ab3e9)](https://sonarcloud.io/summary/new_code?id=mitra-platform-sdk)
5
5
 
6
- The Mitra Platform SDK provides a JavaScript/TypeScript interface for building apps on the Mitra Platform. When Mitra generates your app, the generated code uses this SDK to authenticate users, manage your app's data, execute serverless functions, and more. You can use the same SDK to modify and extend your app.
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, and call integrations.
7
7
 
8
- **Zero runtime dependencies.** Uses only standard Web APIs (`fetch`, `localStorage`, `URL`, `Proxy`).
9
-
10
- ## Modules
11
-
12
- - **`auth`**: User authentication, registration, and session handling.
13
- - **`entities`**: Database CRUD operations.
14
- - **`functions`**: Serverless function execution.
15
- - **`integration`**: Proxy HTTP requests to external APIs with automatic credential injection.
16
- - **`queries`**: Execute reusable named queries.
8
+ The browser transport uses standard Web APIs only: `fetch`, `localStorage`, `URL`, and `Proxy`. Shared contracts and API modules come from `@mitralab.io/sdk-core`, without bringing browser authentication into the Core package.
17
9
 
18
10
  ## Installation
19
11
 
20
12
  ```bash
21
- npm install mitra-platform-sdk
13
+ npm install @mitralab.io/platform-sdk
22
14
  ```
23
15
 
24
- ## Quick Start
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
25
19
 
26
20
  ```typescript
27
- import { createClient } from 'mitra-platform-sdk';
21
+ import { createClient } from "@mitralab.io/platform-sdk"
28
22
 
29
- const mitra = createClient({
30
- appId: 'your-app-id',
31
- apiUrl: 'https://api.mitra.io',
32
- });
23
+ export const mitra = createClient({
24
+ appId: import.meta.env.VITE_MITRA_APP_ID,
25
+ apiUrl: import.meta.env.VITE_MITRA_API_URL,
26
+ onError: (error) => console.error(error.status, error.code, error.message),
27
+ })
33
28
 
34
- await mitra.init();
29
+ await mitra.init()
35
30
  ```
36
31
 
37
- | Parameter | Type | Required | Description |
38
- |-----------|------|----------|-------------|
39
- | `appId` | `string` | Yes | Your app's unique identifier |
40
- | `apiUrl` | `string` | Yes | Base URL of the Mitra API |
41
- | `onError` | `(error) => void` | No | Global error handler for all API requests |
32
+ `init()` resolves the application's public Code Studio configuration, including `dataSourceId` and `allowSignup`. Call it during application startup before using entities, custom queries, or sign-up.
33
+
34
+ ## Configuration
35
+
36
+ | Field | Required | Description |
37
+ |---|---|---|
38
+ | `appId` | yes | ID of the published Code Studio application. |
39
+ | `apiUrl` | yes | Base URL of the Mitra API gateway. |
40
+ | `onError` | no | Global callback for API errors. |
41
+
42
+ The client derives service endpoints from `apiUrl`: `/iam`, `/data-manager`, `/functions`, `/integration`, and `/code-studio`.
43
+
44
+ ## Boundary
42
45
 
43
- `init()` must be called before using the client. Safe to call multiple times.
46
+ The Platform SDK owns:
44
47
 
45
- ## Usage
48
+ - browser login, sign-up, logout, and session refresh
49
+ - session persistence in `localStorage`
50
+ - auth-state listeners
51
+ - one retry after a successful token refresh on a `401` response
52
+ - browser HTTP transport and public application initialization
46
53
 
47
- All modules and methods are fully typed explore the full API through your editor's autocomplete or read the JSDoc in the source code.
54
+ `@mitralab.io/sdk-core` owns the shared entities, custom queries, Functions, integrations, `auth.me`, safe paths, and structural response validation. Server Function code should use `@mitralab.io/functions-sdk` instead of this browser SDK.
48
55
 
49
- ### Authentication
56
+ ## Authentication
50
57
 
51
58
  ```typescript
52
- // Sign up (auto-signs in after registration)
53
- const user = await mitra.auth.signUp({
54
- email: 'user@example.com',
55
- password: 'password123',
56
- name: 'Jane Doe',
57
- });
58
-
59
- // Sign in
60
- await mitra.auth.signIn({ email: 'user@example.com', password: 'password123' });
61
-
62
- // Check state
63
- console.log(mitra.auth.isAuthenticated, mitra.auth.currentUser);
64
-
65
- // Listen for auth changes (fires immediately with current state)
66
- const unsubscribe = mitra.auth.onAuthStateChange((user) => {
67
- console.log(user ? 'Logged in' : 'Logged out');
68
- });
69
-
70
- // Sign out
71
- mitra.auth.signOut();
59
+ const user = await mitra.auth.signIn({
60
+ email: "user@example.com",
61
+ password: "password123",
62
+ })
63
+
64
+ const unsubscribe = mitra.auth.onAuthStateChange((currentUser) => {
65
+ console.log(currentUser?.email)
66
+ })
67
+
68
+ mitra.auth.signOut("/login")
69
+ unsubscribe()
72
70
  ```
73
71
 
74
- ### Entities
72
+ Authentication state is stored under `mitra_auth_{appId}`. When an API request returns `401`, the SDK attempts `refreshSession()` once and repeats the request only when refresh succeeds.
73
+
74
+ ## Entities
75
75
 
76
76
  ```typescript
77
- const tasks = await mitra.entities.Task.list('-created_at', 10);
77
+ type Task = {
78
+ id: string
79
+ title: string
80
+ status: "pending" | "done"
81
+ }
82
+
83
+ const tasks = await mitra.entities.getTable<Task>("Task").list({
84
+ sort: "-created_at",
85
+ limit: 10,
86
+ fields: ["id", "title", "status"],
87
+ })
88
+
89
+ const pending = await mitra.entities.Task.filter({ status: "pending" })
90
+ const created = await mitra.entities.Task.create({ title: "New task" })
91
+ await mitra.entities.Task.update(created.id, { status: "done" })
92
+ await mitra.entities.Task.delete(created.id)
93
+ ```
94
+
95
+ 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.
78
96
 
79
- const task = await mitra.entities.Task.create({
80
- title: 'New task',
81
- status: 'pending',
82
- });
97
+ ## Server Functions
83
98
 
84
- await mitra.entities.Task.update(task.id, { status: 'done' });
99
+ ```typescript
100
+ const execution = await mitra.functions.execute("function-id", {
101
+ orderId: "order-123",
102
+ })
85
103
 
86
- await mitra.entities.Task.delete(task.id);
104
+ console.log(execution.id, execution.status)
87
105
  ```
88
106
 
89
- ### Functions
107
+ The Platform SDK 1.x `execute` method keeps the existing asynchronous API behavior. It does not send `X-Invocation-Type`, so the Functions service applies its default and returns the created execution, normally with `PENDING` status.
108
+
109
+ ## Custom queries
90
110
 
91
111
  ```typescript
92
- const execution = await mitra.functions.execute('function-id', {
93
- to: 'user@example.com',
94
- subject: 'Welcome',
95
- });
112
+ const result = await mitra.queries.execute("query-id", {
113
+ status: "active",
114
+ })
96
115
 
97
- console.log(execution.status, execution.output);
116
+ console.log(result.rows, result.affectedRows)
98
117
  ```
99
118
 
100
- ### Queries
119
+ ## Integrations
120
+
121
+ Execute a predefined resource:
101
122
 
102
123
  ```typescript
103
- const result = await mitra.queries.execute('query-id', { status: 'active' });
104
- console.log(result.rows);
124
+ const result = await mitra.integration.executeResource("resource-id", {
125
+ description: "Notebook",
126
+ limit: 10,
127
+ })
105
128
  ```
106
129
 
107
- ### Integration
130
+ Or execute an integration config directly:
108
131
 
109
132
  ```typescript
110
- const result = await mitra.integration.execute('config-id', {
111
- method: 'GET',
112
- endpoint: '/users',
113
- });
114
- console.log(result.status, result.body);
133
+ const result = await mitra.integration.execute("config-id", {
134
+ method: "GET",
135
+ endpoint: "/users",
136
+ queryParams: { limit: "10" },
137
+ })
138
+
139
+ console.log(result.status, result.body)
115
140
  ```
116
141
 
117
- ## Error Handling
142
+ Integration credentials are injected by the Integration service. Do not pass provider credentials through browser input.
143
+
144
+ ## Errors and request behavior
118
145
 
119
- All API errors throw `MitraApiError`:
146
+ API failures throw `MitraApiError`:
120
147
 
121
148
  ```typescript
122
- import { MitraApiError } from 'mitra-platform-sdk';
149
+ import { MitraApiError } from "@mitralab.io/platform-sdk"
123
150
 
124
151
  try {
125
- await mitra.entities.Task.get('non-existent-id');
152
+ await mitra.entities.Task.get("missing-id")
126
153
  } catch (error) {
127
154
  if (error instanceof MitraApiError) {
128
- console.error(error.status, error.code, error.message);
155
+ console.error(error.status, error.code, error.message)
129
156
  }
130
157
  }
131
158
  ```
132
159
 
133
- ## Development
160
+ 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 a successful session refresh on `401`.
161
+
162
+ 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.
134
163
 
135
- ### Build the SDK
164
+ ## Development
136
165
 
137
166
  ```bash
138
167
  npm install
139
- npm run build
168
+ npm run check
140
169
  ```
141
170
 
142
- ### Run tests
143
-
144
- ```bash
145
- npm test
146
- ```
171
+ `@mitralab.io/sdk-core@0.1.0` is resolved from the public npm registry and locked by integrity in `package-lock.json`. Do not replace it with a `file:` dependency or a local tarball.
147
172
 
148
- ## License
173
+ 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.
149
174
 
150
- MIT
175
+ See [CHANGELOG.md](CHANGELOG.md) for release history and [LICENSE](LICENSE) for license terms.