@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 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, and run PostgREST queries against a
5
- per-cliente MITWAY-BaaS deployment through a single public URL.
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.2.0 — backend proxy.** Currently ships:
9
+ **v0.5.0**
10
10
 
11
11
  | Module | Status | Notes |
12
12
  |---|---|---|
13
- | `auth` | Working | `signUp`, `signInWithPassword`, `signOut`, `refreshSession`, `getSession`, `getUser`, `getCurrentUser`, `getProfile`, `setProfile` |
14
- | `database` | Working | PostgREST query builder via `@supabase/postgrest-js`, routed through the backend proxy at `/api/database/records/*` and `/api/database/rpc/*` |
15
- | `storage` | Not yet | Backend has no `/api/storage/*` routes |
16
- | `functions` | MCP only | Backend routes + MCP tools working. No SDK module — functions are managed by the agent, not by end-user apps |
17
- | `email` | Not yet | Backend has no `/api/email/*` routes |
18
- | `ai` | Not yet | Backend has no `/api/ai/*` routes |
19
- | `realtime` | Not yet | No realtime subsystem |
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', // single backend URL
41
- anonKey: 'eyJhbGciOiJIUzI1NiIs...', // optional; signed JWT with role=anon
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 (in the
113
- future) storage/functions all route through the same backend. PostgREST
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
- ## Auth flow
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
- The SDK targets the routes the MITWAY-BaaS backend currently exposes:
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, so you
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
- configured with a custom fetch that rewrites every outgoing URL:
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
- sign-in/sign-out is picked up automatically — no need to recreate the client.
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
- almost verbatim with rebranding. Rewrote `auth` for the MITWAY-BaaS
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.