@mitway/sdk 0.5.0 → 0.7.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/README.md +51 -53
- package/dist/index.cjs +5 -2092
- package/dist/index.d.cts +209 -13
- package/dist/index.d.ts +209 -13
- package/dist/index.js +5 -2054
- package/package.json +1 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,29 +1,22 @@
|
|
|
1
1
|
# @mitway/sdk
|
|
2
2
|
|
|
3
3
|
TypeScript/JavaScript client for the **MITWAY-BaaS** backend. Lets end-user
|
|
4
|
-
apps sign up, sign in, refresh tokens,
|
|
5
|
-
per-
|
|
4
|
+
apps sign up, sign in, refresh tokens, run PostgREST queries, subscribe to
|
|
5
|
+
realtime events, and manage storage against a per-tenant MITWAY-BaaS deployment.
|
|
6
6
|
|
|
7
7
|
## Status
|
|
8
8
|
|
|
9
|
-
**v0.
|
|
9
|
+
**v0.5.0**
|
|
10
10
|
|
|
11
11
|
| Module | Status | Notes |
|
|
12
12
|
|---|---|---|
|
|
13
|
-
| `auth` |
|
|
14
|
-
| `database` |
|
|
15
|
-
| `
|
|
16
|
-
| `
|
|
17
|
-
| `
|
|
18
|
-
| `
|
|
19
|
-
| `
|
|
20
|
-
|
|
21
|
-
When the backend grows the missing routes, port the corresponding modules
|
|
22
|
-
from upstream
|
|
23
|
-
[`InsForge/InsForge-sdk-js`](https://github.com/InsForge/InsForge-sdk-js)
|
|
24
|
-
(`src/modules/{storage,functions,email,ai,realtime}.ts`). The SDK was
|
|
25
|
-
structured intentionally to match upstream so future ports are mechanical
|
|
26
|
-
rebrands.
|
|
13
|
+
| `auth` | Working | `signUp`, `signInWithPassword`, `signOut`, `refreshSession`, `getSession`, `getUser`, `getCurrentUser`, `getProfile`, `setProfile` |
|
|
14
|
+
| `database` | Working | PostgREST query builder via `@supabase/postgrest-js` |
|
|
15
|
+
| `realtime` | Working | Socket.IO transport with channels (postgres_changes, broadcast, presence) |
|
|
16
|
+
| `storage` | Working | Bucket admin + object operations (upload, download, signed URLs, public URLs) |
|
|
17
|
+
| `functions` | MCP only | Backend routes + MCP tools working. No SDK module |
|
|
18
|
+
| `email` | Not yet | Backend has no `/api/email/*` routes |
|
|
19
|
+
| `ai` | Not yet | Backend has no `/api/ai/*` routes |
|
|
27
20
|
|
|
28
21
|
## Install
|
|
29
22
|
|
|
@@ -37,8 +30,8 @@ pnpm add @mitway/sdk
|
|
|
37
30
|
import { createClient } from '@mitway/sdk';
|
|
38
31
|
|
|
39
32
|
const client = createClient({
|
|
40
|
-
baseUrl: 'https://acme.api.dev.nttmitway.com',
|
|
41
|
-
anonKey: 'eyJhbGciOiJIUzI1NiIs...',
|
|
33
|
+
baseUrl: 'https://acme.api.dev.nttmitway.com',
|
|
34
|
+
anonKey: 'eyJhbGciOiJIUzI1NiIs...',
|
|
42
35
|
});
|
|
43
36
|
|
|
44
37
|
// Sign up
|
|
@@ -89,6 +82,14 @@ const { data: pub } = client.storage
|
|
|
89
82
|
.from('avatars')
|
|
90
83
|
.getPublicUrl('user-123/avatar.png');
|
|
91
84
|
|
|
85
|
+
// Realtime subscription
|
|
86
|
+
const channel = client.realtime
|
|
87
|
+
.channel('posts-feed')
|
|
88
|
+
.on('postgres_changes', { event: 'INSERT', schema: 'public', table: 'posts' }, (payload) => {
|
|
89
|
+
console.log('New post:', payload);
|
|
90
|
+
})
|
|
91
|
+
.subscribe();
|
|
92
|
+
|
|
92
93
|
// Sign out
|
|
93
94
|
await client.auth.signOut();
|
|
94
95
|
```
|
|
@@ -109,14 +110,32 @@ interface MitwayBaasConfig {
|
|
|
109
110
|
}
|
|
110
111
|
```
|
|
111
112
|
|
|
112
|
-
`baseUrl` is the **only** URL consumers need. Auth, database, and
|
|
113
|
-
|
|
114
|
-
is an internal ClusterIP Pod per cliente and is never publicly exposed —
|
|
115
|
-
the backend proxies database requests to it over the cluster network.
|
|
113
|
+
`baseUrl` is the **only** URL consumers need. Auth, database, storage, and realtime
|
|
114
|
+
all route through the same backend.
|
|
116
115
|
|
|
117
|
-
##
|
|
116
|
+
## Releasing a new version
|
|
117
|
+
|
|
118
|
+
Releases are automated via GitHub Actions with OIDC provenance.
|
|
119
|
+
|
|
120
|
+
**Steps:**
|
|
121
|
+
|
|
122
|
+
1. Bump the version in `package.json`:
|
|
118
123
|
|
|
119
|
-
|
|
124
|
+
```bash
|
|
125
|
+
pnpm version patch # or minor / major
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
2. Push the commit and tag:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
git push --follow-tags
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
3. Create a **Release** on GitHub pointing to the new tag (e.g. `v0.5.1`).
|
|
135
|
+
|
|
136
|
+
The workflow (`.github/workflows/publish.yml`) triggers on the release event, runs `typecheck`, `test`, `build`, and publishes to npm with provenance attestation. Requires an `NPM_TOKEN` secret configured in the repository.
|
|
137
|
+
|
|
138
|
+
## Auth flow
|
|
120
139
|
|
|
121
140
|
| Method | Backend route |
|
|
122
141
|
|---|---|
|
|
@@ -125,43 +144,22 @@ The SDK targets the routes the MITWAY-BaaS backend currently exposes:
|
|
|
125
144
|
| `signOut()` | `POST /api/auth/logout` |
|
|
126
145
|
| `refreshSession()` (also automatic on 401) | `POST /api/auth/refresh` |
|
|
127
146
|
|
|
128
|
-
The InsForge SDK uses different paths (`/api/auth/users`, `/api/auth/sessions`,
|
|
129
|
-
etc.); those are not implemented in MITWAY-BaaS.
|
|
130
|
-
|
|
131
147
|
The `HttpClient` automatically calls `refreshSession()` and retries the
|
|
132
|
-
original request when it receives a `401 INVALID_TOKEN` response
|
|
133
|
-
don't need to manage refresh manually.
|
|
148
|
+
original request when it receives a `401 INVALID_TOKEN` response.
|
|
134
149
|
|
|
135
150
|
## Database flow
|
|
136
151
|
|
|
137
152
|
The `database` module is a thin wrapper around
|
|
138
|
-
[`@supabase/postgrest-js`](https://github.com/supabase/postgrest-js)
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
- `http://dummy/{table}?…` → `{baseUrl}/api/database/records/{table}?…`
|
|
142
|
-
- `http://dummy/rpc/{fn}?…` → `{baseUrl}/api/database/rpc/{fn}?…`
|
|
143
|
-
|
|
144
|
-
These paths hit the MITWAY-BaaS backend, which then proxies the request
|
|
145
|
-
internally to the per-cliente PostgREST Pod (`mitway-baas-{client}-postgrest:3000`)
|
|
146
|
-
over the cluster network. PostgREST verifies the JWT with the shared
|
|
147
|
-
tenant `JWT_SECRET` and enforces RLS based on the role claim.
|
|
148
|
-
|
|
149
|
-
The full
|
|
150
|
-
[PostgREST query builder API](https://supabase.com/docs/reference/javascript/select)
|
|
151
|
-
is available: `select`, `insert`, `update`, `upsert`, `delete`, `rpc`,
|
|
152
|
-
filters (`.eq`, `.neq`, `.gt`, `.like`, `.in`, …), modifiers (`.order`,
|
|
153
|
-
`.limit`, `.range`, `.single`, …), foreign-key joins
|
|
154
|
-
(`select('*, author:users(*)')`).
|
|
153
|
+
[`@supabase/postgrest-js`](https://github.com/supabase/postgrest-js).
|
|
154
|
+
The full PostgREST query builder API is available: `select`, `insert`, `update`,
|
|
155
|
+
`upsert`, `delete`, `rpc`, filters, modifiers, and foreign-key joins.
|
|
155
156
|
|
|
156
|
-
Authorization is read from the `TokenManager` on every request, so a
|
|
157
|
-
|
|
157
|
+
Authorization is read from the `TokenManager` on every request, so a sign-in/sign-out
|
|
158
|
+
is picked up automatically.
|
|
158
159
|
|
|
159
160
|
## Origin
|
|
160
161
|
|
|
161
162
|
Forked structurally from
|
|
162
163
|
[`InsForge/InsForge-sdk-js`](https://github.com/InsForge/InsForge-sdk-js).
|
|
163
164
|
Kept the `lib/` infrastructure (http-client, token-manager, logger)
|
|
164
|
-
|
|
165
|
-
routes and `database` to use the same fetch-rewriting pattern as
|
|
166
|
-
upstream — both hit a backend proxy that forwards to the internal
|
|
167
|
-
PostgREST, collapsing the per-cliente public surface into a single URL.
|
|
165
|
+
with rebranding. Rewrote `auth` and `database` for the MITWAY-BaaS routes.
|