@motherbase/client 1.0.2 → 1.1.3

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
@@ -25,8 +25,8 @@ import { createClient, localStorageStorage } from '@motherbase/client';
25
25
 
26
26
  const client = createClient(
27
27
  'http://localhost:5001',
28
- 'your-anon-key', // optional; sent as an `apikey` header
29
- { storage: localStorageStorage() }, // omit for in-memory (SSR-safe) sessions
28
+ 'your-anon-key', // optional; sent as an `apikey` header
29
+ { storage: localStorageStorage() } // omit for in-memory (SSR-safe) sessions
30
30
  );
31
31
 
32
32
  await client.hydrate(); // restore a persisted session (optional)
@@ -51,14 +51,19 @@ const { data: uploaded } = await client.storage.from('avatars').upload('me.png',
51
51
  visibility: 'public',
52
52
  });
53
53
 
54
- // Realtime
55
- const channel = client
56
- .channel('room-products')
57
- .on('postgres_changes', { event: '*', schema: 'public', table: 'products' }, (payload) => {
58
- console.log(payload.eventType, payload.new, payload.old);
54
+ // Realtime — postgres_changes, broadcast, presence over one channel (Supabase-shaped)
55
+ const room = client
56
+ .channel('room-1', { config: { broadcast: { self: true }, presence: { key: userId } } })
57
+ .on('postgres_changes', { event: '*', schema: 'public', table: 'messages', filter: 'room_id=eq.42' }, p => {
58
+ console.log(p.eventType, p.new, p.old);
59
59
  })
60
+ .on('broadcast', { event: 'cursor' }, ({ payload }) => console.log(payload))
61
+ .on('presence', { event: 'sync' }, () => console.log(room.presenceState()))
60
62
  .subscribe();
61
63
 
64
+ await room.send({ type: 'broadcast', event: 'cursor', payload: { x: 1, y: 2 } });
65
+ await room.track({ online_at: Date.now() });
66
+
62
67
  // Edge functions
63
68
  const { data: result } = await client.functions.invoke('hello', { body: { name: 'Ada' } });
64
69
  ```
@@ -96,7 +101,13 @@ client.storage.from(bucket).createSignedUrl(path, expiresIn)
96
101
  client.storage.from(bucket).getPublicUrl(path) // sync
97
102
 
98
103
  // Realtime
99
- client.channel(name).on('postgres_changes', { event, schema, table }, cb).subscribe()
104
+ client.channel(name, { config: { broadcast: { self, ack }, presence: { key } } })
105
+ .on('postgres_changes', { event, schema, table, filter }, cb)
106
+ .on('broadcast', { event }, cb)
107
+ .on('presence', { event: 'sync' | 'join' | 'leave' }, cb)
108
+ .subscribe(status => {}) // SUBSCRIBED | TIMED_OUT | CLOSED | CHANNEL_ERROR
109
+ channel.send({ type: 'broadcast', event, payload })
110
+ channel.track(state); channel.untrack(); channel.presenceState()
100
111
  client.removeChannel(channel)
101
112
 
102
113
  // Edge functions → { data, error }
@@ -105,11 +116,11 @@ client.functions.invoke(name, { body })
105
116
 
106
117
  ## Storage adapters
107
118
 
108
- | Runtime | Adapter |
109
- | -------- | ------- |
110
- | Browser | `localStorageStorage()` or `cookieStorage()` |
119
+ | Runtime | Adapter |
120
+ | -------- | ------------------------------------------------------------- |
121
+ | Browser | `localStorageStorage()` or `cookieStorage()` |
111
122
  | SSR/Node | `memoryStorage()` (default) or `serverCookieStorage(adapter)` |
112
- | Expo/RN | custom `{ get, set }` backed by `AsyncStorage` |
123
+ | Expo/RN | custom `{ get, set }` backed by `AsyncStorage` |
113
124
 
114
125
  ```ts
115
126
  import AsyncStorage from '@react-native-async-storage/async-storage';
@@ -131,24 +142,25 @@ const client = createClient(API_URL, ANON_KEY, {
131
142
 
132
143
  ## Compatibility matrix
133
144
 
134
- | Area | Status | Notes |
135
- | --- | --- | --- |
136
- | `createClient(url, key, options)` | Supported | `key` sent as `apikey` header. |
137
- | `from().select/insert/update/delete` | Supported | Awaitable `{ data, error }`. |
138
- | filters `eq/neq/gt/gte/lt/lte/like/ilike/in/is` | Supported | Mapped to the `/rest/v1` PostgREST dialect. |
139
- | `order/limit/range/single/maybeSingle` | Supported | `range` → limit/offset. |
140
- | `upsert()` | Partial | Emulated as `insert` (no `onConflict`). |
141
- | relational embedding (`select('*, author(*)')`) | Not supported | Backend blocks joins. |
142
- | `.rpc()` | Not supported | No exposed Postgres functions — use `functions.invoke`. |
143
- | `.or/.not/.filter/.textSearch/.contains` | Not supported | Not in the backend dialect. |
144
- | `auth.signUp/signInWithPassword/signOut` | Supported | |
145
- | `auth.getUser/getSession/refreshSession/onAuthStateChange` | Supported | Events: `SIGNED_IN`, `SIGNED_OUT`, `TOKEN_REFRESHED`. |
146
- | OAuth / magic link / OTP | Not supported | Email + password only. |
147
- | `storage upload/download/remove/createSignedUrl/getPublicUrl` | Partial | `path` == server file id returned by `upload`. |
148
- | `storage.list()` | Stub | Returns an unsupported error instead of throwing. |
149
- | `channel().on('postgres_changes').subscribe()` | Supported | INSERT/UPDATE/DELETE/`*`. |
150
- | broadcast / presence channels | Not supported | Only `postgres_changes`. |
151
- | `functions.invoke(name, { body })` | Supported | Maps to `/api/edge/:name`. |
145
+ | Area | Status | Notes |
146
+ | ------------------------------------------------------------- | ------------- | ------------------------------------------------------- |
147
+ | `createClient(url, key, options)` | Supported | `key` sent as `apikey` header. |
148
+ | `from().select/insert/update/delete` | Supported | Awaitable `{ data, error }`. |
149
+ | filters `eq/neq/gt/gte/lt/lte/like/ilike/in/is` | Supported | Mapped to the `/rest/v1` PostgREST dialect. |
150
+ | `order/limit/range/single/maybeSingle` | Supported | `range` → limit/offset. |
151
+ | `upsert()` | Partial | Emulated as `insert` (no `onConflict`). |
152
+ | relational embedding (`select('*, author(*)')`) | Not supported | Backend blocks joins. |
153
+ | `.rpc()` | Not supported | No exposed Postgres functions — use `functions.invoke`. |
154
+ | `.or/.not/.filter/.textSearch/.contains` | Not supported | Not in the backend dialect. |
155
+ | `auth.signUp/signInWithPassword/signOut` | Supported | |
156
+ | `auth.getUser/getSession/refreshSession/onAuthStateChange` | Supported | Events: `SIGNED_IN`, `SIGNED_OUT`, `TOKEN_REFRESHED`. |
157
+ | OAuth / magic link / OTP | Not supported | Email + password only. |
158
+ | `storage upload/download/remove/createSignedUrl/getPublicUrl` | Partial | `path` == server file id returned by `upload`. |
159
+ | `storage.list()` | Stub | Returns an unsupported error instead of throwing. |
160
+ | `channel().on('postgres_changes').subscribe()` | Supported | INSERT/UPDATE/DELETE/`*`, RLS-filtered, column `filter`. |
161
+ | `channel().on('broadcast')` + `.send()` | Supported | `config.broadcast.self` / `.ack`. |
162
+ | `channel().on('presence')` + `.track/.untrack/.presenceState` | Supported | `sync`/`join`/`leave`, keyed by `config.presence.key`. |
163
+ | `functions.invoke(name, { body })` | Supported | Maps to `/api/edge/:name`. |
152
164
 
153
165
  More examples live in [`docs/sdk.md`](../../docs/sdk.md). Project Studio also
154
166
  exposes a project-specific Connect page with the exact API URL, WebSocket URL and
package/dist/auth.d.ts CHANGED
@@ -11,6 +11,43 @@ export interface SignInWithPasswordCredentials {
11
11
  email: string;
12
12
  password: string;
13
13
  }
14
+ export interface SignInWithOtpCredentials {
15
+ email: string;
16
+ }
17
+ export interface VerifyOtpParams {
18
+ email: string;
19
+ /** The OTP code sent to the email. Named `token` for supabase-js parity. */
20
+ token: string;
21
+ /** Accepted for supabase-js signature parity; only the email sign-in OTP flow is supported. */
22
+ type?: 'email';
23
+ }
24
+ export interface SignInWithOAuthCredentials {
25
+ /** Social provider id, e.g. 'google' or 'apple'. Must be enabled on the backend. */
26
+ provider: string;
27
+ options?: {
28
+ /** Where the provider should send the user back to after auth. */
29
+ redirectTo?: string;
30
+ /** Space-separated OAuth scopes. */
31
+ scopes?: string;
32
+ /** Skip the automatic `window.location` redirect and just return the URL. */
33
+ skipBrowserRedirect?: boolean;
34
+ };
35
+ }
36
+ export interface DeleteUserAttributes {
37
+ /** Required unless the session is already "fresh" (i.e. just re-authenticated). */
38
+ password?: string;
39
+ /** Deletion-confirmation token, when the backend's delete flow requires an email confirmation step. */
40
+ token?: string;
41
+ callbackURL?: string;
42
+ }
43
+ export interface UpdateUserAttributes {
44
+ /** New password. Requires `currentPassword` — the backend does not allow a
45
+ * blind password change from an authenticated session. */
46
+ password?: string;
47
+ currentPassword?: string;
48
+ /** Arbitrary profile fields (name, image, or any custom additional field). */
49
+ data?: Record<string, unknown>;
50
+ }
14
51
  export interface Subscription {
15
52
  unsubscribe(): void;
16
53
  }
@@ -31,6 +68,77 @@ export declare class AuthClient {
31
68
  user: User | null;
32
69
  session: Session | null;
33
70
  }>>;
71
+ /**
72
+ * Request a password-reset OTP by email. Always resolves successfully
73
+ * (whether or not the email is registered) to avoid leaking account
74
+ * existence; check `error` only for transport/server failures.
75
+ */
76
+ resetPasswordForEmail(email: string): Promise<{
77
+ error: MotherbaseResponse<null>['error'];
78
+ }>;
79
+ /** Complete a password reset using the OTP sent to the user's email. */
80
+ resetPassword(args: {
81
+ email: string;
82
+ otp: string;
83
+ password: string;
84
+ }): Promise<{
85
+ error: MotherbaseResponse<null>['error'];
86
+ }>;
87
+ /** Send a one-time sign-in code by email. Pair with `verifyOtp` to complete sign-in. */
88
+ signInWithOtp(credentials: SignInWithOtpCredentials): Promise<{
89
+ data: Record<string, never>;
90
+ error: MotherbaseResponse<null>['error'];
91
+ }>;
92
+ /** Complete a `signInWithOtp` sign-in using the code sent to the user's email. */
93
+ verifyOtp(params: VerifyOtpParams): Promise<MotherbaseResponse<{
94
+ user: User | null;
95
+ session: Session | null;
96
+ }>>;
97
+ /** Create a fresh anonymous session. Requires the `anonymous` sign-in method to be enabled. */
98
+ signInAnonymously(): Promise<MotherbaseResponse<{
99
+ user: User | null;
100
+ session: Session | null;
101
+ }>>;
102
+ /**
103
+ * Start an OAuth sign-in with a configured social provider. Resolves with the
104
+ * provider's authorize URL and, in a browser, redirects to it immediately
105
+ * unless `options.skipBrowserRedirect` is set.
106
+ */
107
+ signInWithOAuth(credentials: SignInWithOAuthCredentials): Promise<MotherbaseResponse<{
108
+ provider: string;
109
+ url: string | null;
110
+ }>>;
111
+ /**
112
+ * Update the signed-in user's profile fields and/or password. Password
113
+ * changes require `currentPassword` (a Better Auth requirement — there is no
114
+ * blind password overwrite from an authenticated session).
115
+ */
116
+ updateUser(attributes: UpdateUserAttributes): Promise<MotherbaseResponse<{
117
+ user: User | null;
118
+ }>>;
119
+ /**
120
+ * Permanently delete the signed-in user's account. Not part of the
121
+ * supabase-js client surface (there it's admin-only) — kept here because
122
+ * self-service account deletion is a real product need. Requires the
123
+ * backend's `delete-user` flow to be enabled; clears the local session on
124
+ * success.
125
+ */
126
+ deleteUser(attributes?: DeleteUserAttributes): Promise<{
127
+ error: MotherbaseResponse<null>['error'];
128
+ }>;
129
+ /**
130
+ * Adopt an externally-obtained access token as the current session (e.g. one
131
+ * captured from an OAuth redirect). Validates it against the server before
132
+ * persisting. `refresh_token` is accepted for supabase-js signature parity
133
+ * and unused — Better Auth bearer sessions have none.
134
+ */
135
+ setSession(currentSession: {
136
+ access_token: string;
137
+ refresh_token?: string;
138
+ }): Promise<MotherbaseResponse<{
139
+ user: User | null;
140
+ session: Session | null;
141
+ }>>;
34
142
  signOut(): Promise<{
35
143
  error: MotherbaseResponse<null>['error'];
36
144
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAEV,kBAAkB,EAElB,kBAAkB,EAClB,OAAO,EACP,IAAI,EACL,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,6BAA6B;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAyBD,MAAM,WAAW,YAAY;IAC3B,WAAW,IAAI,IAAI,CAAC;CACrB;AAED;;;;GAIG;AACH,qBAAa,UAAU;IACT,OAAO,CAAC,QAAQ,CAAC,IAAI;IAAc,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAxC,IAAI,EAAE,UA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;KAAE,CAAC,CAAC;IASnE,0DAA0D;IACpD,UAAU,IAAI,OAAO,CAAC,kBAAkB,CAAC;QAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;IAI5E;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,kBAAkB,CAAC;QAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;QAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;IAoBnG,iBAAiB,CAAC,QAAQ,EAAE,kBAAkB,GAAG;QAAE,IAAI,EAAE;YAAE,YAAY,EAAE,YAAY,CAAA;SAAE,CAAA;KAAE;IAOzF;;;OAGG;IACG,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;YAKpB,OAAO;CAKtB"}
package/dist/auth.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { toError } from './http.js';
2
+ import { HTTP_ROUTES } from '@motherbase/contracts';
2
3
  /** Build a clean Session from the Better Auth auth payload. */
3
4
  function toSession(payload) {
4
5
  return { accessToken: payload.token, user: payload.user };
@@ -20,7 +21,7 @@ export class AuthClient {
20
21
  }
21
22
  async signUp(credentials) {
22
23
  try {
23
- const payload = await this.http.request('/api/auth/sign-up/email', {
24
+ const payload = await this.http.request(HTTP_ROUTES.authSignUp, {
24
25
  method: 'POST',
25
26
  body: { email: credentials.email, password: credentials.password, name: credentials.username ?? credentials.email },
26
27
  anonymous: true,
@@ -35,7 +36,7 @@ export class AuthClient {
35
36
  }
36
37
  async signInWithPassword(credentials) {
37
38
  try {
38
- const payload = await this.http.request('/api/auth/sign-in/email', {
39
+ const payload = await this.http.request(HTTP_ROUTES.authSignIn, {
39
40
  method: 'POST',
40
41
  body: { email: credentials.email, password: credentials.password },
41
42
  anonymous: true,
@@ -48,9 +49,187 @@ export class AuthClient {
48
49
  return { data: { user: null, session: null }, error: toError(err) };
49
50
  }
50
51
  }
52
+ /**
53
+ * Request a password-reset OTP by email. Always resolves successfully
54
+ * (whether or not the email is registered) to avoid leaking account
55
+ * existence; check `error` only for transport/server failures.
56
+ */
57
+ async resetPasswordForEmail(email) {
58
+ try {
59
+ await this.http.request(HTTP_ROUTES.authRequestPasswordReset, {
60
+ method: 'POST',
61
+ body: { email },
62
+ anonymous: true,
63
+ raw: true,
64
+ });
65
+ return { error: null };
66
+ }
67
+ catch (err) {
68
+ return { error: toError(err) };
69
+ }
70
+ }
71
+ /** Complete a password reset using the OTP sent to the user's email. */
72
+ async resetPassword(args) {
73
+ try {
74
+ await this.http.request(HTTP_ROUTES.authResetPassword, {
75
+ method: 'POST',
76
+ body: { email: args.email, otp: args.otp, password: args.password },
77
+ anonymous: true,
78
+ raw: true,
79
+ });
80
+ return { error: null };
81
+ }
82
+ catch (err) {
83
+ return { error: toError(err) };
84
+ }
85
+ }
86
+ /** Send a one-time sign-in code by email. Pair with `verifyOtp` to complete sign-in. */
87
+ async signInWithOtp(credentials) {
88
+ try {
89
+ await this.http.request(HTTP_ROUTES.authSendOtp, {
90
+ method: 'POST',
91
+ body: { email: credentials.email, type: 'sign-in' },
92
+ anonymous: true,
93
+ raw: true,
94
+ });
95
+ return { data: {}, error: null };
96
+ }
97
+ catch (err) {
98
+ return { data: {}, error: toError(err) };
99
+ }
100
+ }
101
+ /** Complete a `signInWithOtp` sign-in using the code sent to the user's email. */
102
+ async verifyOtp(params) {
103
+ try {
104
+ const payload = await this.http.request(HTTP_ROUTES.authSignInEmailOtp, {
105
+ method: 'POST',
106
+ body: { email: params.email, otp: params.token },
107
+ anonymous: true,
108
+ raw: true,
109
+ });
110
+ const session = await this.persist(payload);
111
+ return { data: { user: session.user, session }, error: null };
112
+ }
113
+ catch (err) {
114
+ return { data: { user: null, session: null }, error: toError(err) };
115
+ }
116
+ }
117
+ /** Create a fresh anonymous session. Requires the `anonymous` sign-in method to be enabled. */
118
+ async signInAnonymously() {
119
+ try {
120
+ const payload = await this.http.request(HTTP_ROUTES.authSignInAnonymous, {
121
+ method: 'POST',
122
+ anonymous: true,
123
+ raw: true,
124
+ });
125
+ const session = await this.persist(payload);
126
+ return { data: { user: session.user, session }, error: null };
127
+ }
128
+ catch (err) {
129
+ return { data: { user: null, session: null }, error: toError(err) };
130
+ }
131
+ }
132
+ /**
133
+ * Start an OAuth sign-in with a configured social provider. Resolves with the
134
+ * provider's authorize URL and, in a browser, redirects to it immediately
135
+ * unless `options.skipBrowserRedirect` is set.
136
+ */
137
+ async signInWithOAuth(credentials) {
138
+ try {
139
+ const payload = await this.http.request(HTTP_ROUTES.authSignInSocial, {
140
+ method: 'POST',
141
+ body: {
142
+ provider: credentials.provider,
143
+ callbackURL: credentials.options?.redirectTo,
144
+ scopes: credentials.options?.scopes ? credentials.options.scopes.split(' ') : undefined,
145
+ disableRedirect: true,
146
+ },
147
+ anonymous: true,
148
+ raw: true,
149
+ });
150
+ const url = payload?.url ?? null;
151
+ if (url && !credentials.options?.skipBrowserRedirect && typeof window !== 'undefined') {
152
+ window.location.href = url;
153
+ }
154
+ return { data: { provider: credentials.provider, url }, error: null };
155
+ }
156
+ catch (err) {
157
+ return { data: { provider: credentials.provider, url: null }, error: toError(err) };
158
+ }
159
+ }
160
+ /**
161
+ * Update the signed-in user's profile fields and/or password. Password
162
+ * changes require `currentPassword` (a Better Auth requirement — there is no
163
+ * blind password overwrite from an authenticated session).
164
+ */
165
+ async updateUser(attributes) {
166
+ try {
167
+ if (attributes.data && Object.keys(attributes.data).length > 0) {
168
+ await this.http.request(HTTP_ROUTES.authUpdateUser, { method: 'POST', body: attributes.data, raw: true });
169
+ }
170
+ if (attributes.password) {
171
+ if (!attributes.currentPassword) {
172
+ return { data: { user: null }, error: { message: '`currentPassword` is required to change the password.' } };
173
+ }
174
+ await this.http.request(HTTP_ROUTES.authChangePassword, {
175
+ method: 'POST',
176
+ body: { newPassword: attributes.password, currentPassword: attributes.currentPassword },
177
+ raw: true,
178
+ });
179
+ }
180
+ return await this.getUser();
181
+ }
182
+ catch (err) {
183
+ return { data: { user: null }, error: toError(err) };
184
+ }
185
+ }
186
+ /**
187
+ * Permanently delete the signed-in user's account. Not part of the
188
+ * supabase-js client surface (there it's admin-only) — kept here because
189
+ * self-service account deletion is a real product need. Requires the
190
+ * backend's `delete-user` flow to be enabled; clears the local session on
191
+ * success.
192
+ */
193
+ async deleteUser(attributes = {}) {
194
+ try {
195
+ await this.http.request(HTTP_ROUTES.authDeleteUser, {
196
+ method: 'POST',
197
+ body: attributes,
198
+ raw: true,
199
+ });
200
+ await this.store.set(null, 'signOut');
201
+ return { error: null };
202
+ }
203
+ catch (err) {
204
+ return { error: toError(err) };
205
+ }
206
+ }
207
+ /**
208
+ * Adopt an externally-obtained access token as the current session (e.g. one
209
+ * captured from an OAuth redirect). Validates it against the server before
210
+ * persisting. `refresh_token` is accepted for supabase-js signature parity
211
+ * and unused — Better Auth bearer sessions have none.
212
+ */
213
+ async setSession(currentSession) {
214
+ await this.store.set({ accessToken: currentSession.access_token, user: { id: '', email: '' } }, 'signIn');
215
+ try {
216
+ const payload = await this.http.request(HTTP_ROUTES.authSession, { raw: true });
217
+ if (!payload?.user) {
218
+ await this.store.set(null, 'signOut');
219
+ return { data: { user: null, session: null }, error: { message: 'Invalid session' } };
220
+ }
221
+ const session = { accessToken: currentSession.access_token, user: payload.user };
222
+ await this.store.set(session, 'signIn');
223
+ return { data: { user: session.user, session }, error: null };
224
+ }
225
+ catch (err) {
226
+ await this.store.set(null, 'signOut');
227
+ return { data: { user: null, session: null }, error: toError(err) };
228
+ }
229
+ }
51
230
  async signOut() {
52
231
  try {
53
- await this.http.request('/api/auth/sign-out', { method: 'POST', raw: true });
232
+ await this.http.request(HTTP_ROUTES.authSignOut, { method: 'POST', raw: true });
54
233
  }
55
234
  catch {
56
235
  // best-effort; clear locally regardless
@@ -61,7 +240,7 @@ export class AuthClient {
61
240
  /** Fetch the current user from Better Auth (requires a valid session). */
62
241
  async getUser() {
63
242
  try {
64
- const payload = await this.http.request('/api/auth/get-session', { raw: true });
243
+ const payload = await this.http.request(HTTP_ROUTES.authSession, { raw: true });
65
244
  return { data: { user: payload?.user ?? null }, error: null };
66
245
  }
67
246
  catch (err) {
@@ -83,7 +262,7 @@ export class AuthClient {
83
262
  return { data: { user: null, session: null }, error: { message: 'Auth session missing!' } };
84
263
  }
85
264
  try {
86
- const payload = await this.http.request('/api/auth/get-session', { raw: true });
265
+ const payload = await this.http.request(HTTP_ROUTES.authSession, { raw: true });
87
266
  if (!payload?.user) {
88
267
  await this.store.set(null, 'signOut');
89
268
  return { data: { user: null, session: null }, error: { message: 'Session expired' } };
package/dist/auth.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAoCpC,+DAA+D;AAC/D,SAAS,SAAS,CAAC,OAAoB;IACrC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;AAC5D,CAAC;AAED,MAAM,SAAS,GAAuC;IACpD,MAAM,EAAE,WAAW;IACnB,OAAO,EAAE,YAAY;IACrB,cAAc,EAAE,iBAAiB;CAClC,CAAC;AAMF;;;;GAIG;AACH,MAAM,OAAO,UAAU;IACrB,YAA6B,IAAgB,EAAmB,KAAmB;QAAtD,SAAI,GAAJ,IAAI,CAAY;QAAmB,UAAK,GAAL,KAAK,CAAc;IAAG,CAAC;IAEvF,KAAK,CAAC,MAAM,CACV,WAA8B;QAE9B,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAc,yBAAyB,EAAE;gBAC9E,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE,EAAE,KAAK,EAAE,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,WAAW,CAAC,QAAQ,EAAE,IAAI,EAAE,WAAW,CAAC,QAAQ,IAAI,WAAW,CAAC,KAAK,EAAE;gBACn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IAAI,CAAC;IAC/B,CAAC;IAEO,KAAK,CAAC,OAAO,CAAC,OAAoB;QACxC,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;QACnC,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACxC,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
package/dist/channel.d.ts CHANGED
@@ -1,9 +1,12 @@
1
1
  import type { RealtimeModule } from './realtime.js';
2
+ import type { RealtimeTopicEnvelope } from '@motherbase/contracts';
2
3
  export type PostgresChangeEvent = 'INSERT' | 'UPDATE' | 'DELETE' | '*';
3
4
  export interface PostgresChangeFilter {
4
5
  event: PostgresChangeEvent;
5
6
  schema?: string;
6
7
  table: string;
8
+ /** PostgREST-style column filter, e.g. `room_id=eq.42`. Applied server-side in sub-project #4. */
9
+ filter?: string;
7
10
  }
8
11
  export interface PostgresChangePayload<T = Record<string, unknown>> {
9
12
  schema: string;
@@ -13,28 +16,89 @@ export interface PostgresChangePayload<T = Record<string, unknown>> {
13
16
  old: T | Record<string, never>;
14
17
  commit_timestamp: string;
15
18
  }
16
- export type ChannelStatus = 'SUBSCRIBED' | 'CLOSED' | 'CHANNEL_ERROR';
19
+ export interface BroadcastFilter {
20
+ event: string;
21
+ }
22
+ export interface PresenceFilter {
23
+ event: 'sync' | 'join' | 'leave';
24
+ }
25
+ export interface BroadcastMessage {
26
+ type: 'broadcast';
27
+ event: string;
28
+ payload?: Record<string, unknown>;
29
+ }
30
+ export interface BroadcastReceived {
31
+ type: 'broadcast';
32
+ event: string;
33
+ payload: unknown;
34
+ }
35
+ export interface PresenceEntry {
36
+ presence_ref: string;
37
+ [key: string]: unknown;
38
+ }
39
+ export type PresenceState<T extends Record<string, unknown> = Record<string, unknown>> = Record<string, Array<T & {
40
+ presence_ref: string;
41
+ }>>;
42
+ export interface PresenceJoinPayload {
43
+ key: string;
44
+ newPresences: PresenceEntry[];
45
+ currentPresences: PresenceEntry[];
46
+ }
47
+ export interface PresenceLeavePayload {
48
+ key: string;
49
+ leftPresences: PresenceEntry[];
50
+ currentPresences: PresenceEntry[];
51
+ }
52
+ export type ChannelStatus = 'SUBSCRIBED' | 'TIMED_OUT' | 'CLOSED' | 'CHANNEL_ERROR';
53
+ export interface RealtimeChannelOptions {
54
+ config?: {
55
+ broadcast?: {
56
+ self?: boolean;
57
+ ack?: boolean;
58
+ };
59
+ presence?: {
60
+ key?: string;
61
+ };
62
+ };
63
+ }
17
64
  /**
18
- * Supabase-compatible realtime channel. Maps `postgres_changes` subscriptions
19
- * onto the backend's socket.io table watch, translating the watch event shape
20
- * into Supabase's `{ eventType, new, old, table, schema }` payload.
65
+ * Supabase-compatible realtime channel. Multiplexes broadcast, presence, and
66
+ * postgres_changes over a single topic. `postgres_changes` is delivered through
67
+ * the RealtimeModule.watchTable bridge in this release; broadcast/presence are
68
+ * routed by topic via rt:msg envelopes.
21
69
  */
22
70
  export declare class RealtimeChannel {
23
71
  readonly topic: string;
24
72
  private readonly realtime;
25
- private readonly bindings;
26
- private readonly unsubscribers;
27
- private subscribed;
28
- constructor(topic: string, realtime: RealtimeModule);
29
- /** Register a `postgres_changes` listener. Chainable, like supabase-js. */
73
+ private readonly options;
74
+ private readonly pgBindings;
75
+ private readonly broadcastBindings;
76
+ private readonly presenceBindings;
77
+ private status;
78
+ private presence;
79
+ constructor(topic: string, realtime: RealtimeModule, options?: RealtimeChannelOptions);
80
+ on(type: 'broadcast', filter: BroadcastFilter, callback: (payload: BroadcastReceived) => void): this;
81
+ on(type: 'presence', filter: PresenceFilter, callback: (payload: unknown) => void): this;
30
82
  on(type: 'postgres_changes', filter: PostgresChangeFilter, callback: (payload: PostgresChangePayload) => void): this;
83
+ subscribe(onStatus?: (status: ChannelStatus, err?: Error) => void, timeoutMs?: number): this;
84
+ unsubscribe(): Promise<'ok'>;
31
85
  /**
32
- * Connect (if needed) and start delivering events. Optionally reports status.
33
- * Returns the channel for chaining, matching supabase-js.
86
+ * Broadcast a message to the topic. Other clients on the topic with a matching
87
+ * `on('broadcast', { event })` binding receive it; the sender receives its own
88
+ * message only when the channel was created with `config.broadcast.self`.
89
+ * With `config.broadcast.ack`, resolves on the server ack.
34
90
  */
35
- subscribe(onStatus?: (status: ChannelStatus, err?: Error) => void): this;
36
- /** Tear down all watchers for this channel. */
37
- unsubscribe(): Promise<'ok'>;
38
- private attach;
91
+ send(message: BroadcastMessage): Promise<'ok' | 'timed out' | 'error'>;
92
+ /** Announce this client's presence on the topic with the given state. */
93
+ track(state: Record<string, unknown>): Promise<'ok' | 'timed out' | 'error'>;
94
+ /** Remove this client's presence from the topic. */
95
+ untrack(): Promise<'ok' | 'timed out' | 'error'>;
96
+ /** Current presence state, keyed by presence key. */
97
+ presenceState<T extends Record<string, unknown> = Record<string, unknown>>(): PresenceState<T>;
98
+ /** Internal: receive a topic envelope routed by RealtimeModule. */
99
+ _receive(envelope: RealtimeTopicEnvelope): void;
100
+ private applyPresenceState;
101
+ private emitPresence;
102
+ private buildConfig;
39
103
  }
40
104
  //# sourceMappingURL=channel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAsB,MAAM,eAAe,CAAC;AAExE,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,GAAG,CAAC;AAEvE,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,mBAAmB,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,qBAAqB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAChE,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC1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