@motherbase/client 1.4.0 → 1.5.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 +379 -284
- package/package.json +1 -1
- package/dist/admin.d.ts +0 -81
- package/dist/admin.d.ts.map +0 -1
- package/dist/admin.js +0 -85
- package/dist/admin.js.map +0 -1
- package/dist/auth.d.ts +0 -362
- package/dist/auth.d.ts.map +0 -1
- package/dist/auth.js +0 -721
- package/dist/auth.js.map +0 -1
- package/dist/channel.d.ts +0 -122
- package/dist/channel.d.ts.map +0 -1
- package/dist/channel.js +0 -213
- package/dist/channel.js.map +0 -1
- package/dist/compat.d.ts +0 -40
- package/dist/compat.d.ts.map +0 -1
- package/dist/compat.js +0 -98
- package/dist/compat.js.map +0 -1
- package/dist/cookie.d.ts +0 -68
- package/dist/cookie.d.ts.map +0 -1
- package/dist/cookie.js +0 -152
- package/dist/cookie.js.map +0 -1
- package/dist/database.d.ts +0 -188
- package/dist/database.d.ts.map +0 -1
- package/dist/database.js +0 -2
- package/dist/database.js.map +0 -1
- package/dist/devices.d.ts +0 -13
- package/dist/devices.d.ts.map +0 -1
- package/dist/devices.js +0 -13
- package/dist/devices.js.map +0 -1
- package/dist/edge.d.ts +0 -7
- package/dist/edge.d.ts.map +0 -1
- package/dist/edge.js +0 -13
- package/dist/edge.js.map +0 -1
- package/dist/functions.d.ts +0 -60
- package/dist/functions.d.ts.map +0 -1
- package/dist/functions.js +0 -75
- package/dist/functions.js.map +0 -1
- package/dist/http.d.ts +0 -123
- package/dist/http.d.ts.map +0 -1
- package/dist/http.js +0 -205
- package/dist/http.js.map +0 -1
- package/dist/index.d.ts +0 -185
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -331
- package/dist/index.js.map +0 -1
- package/dist/mfa.d.ts +0 -109
- package/dist/mfa.d.ts.map +0 -1
- package/dist/mfa.js +0 -134
- package/dist/mfa.js.map +0 -1
- package/dist/postgrest.d.ts +0 -326
- package/dist/postgrest.d.ts.map +0 -1
- package/dist/postgrest.js +0 -629
- package/dist/postgrest.js.map +0 -1
- package/dist/profile.d.ts +0 -16
- package/dist/profile.d.ts.map +0 -1
- package/dist/profile.js +0 -26
- package/dist/profile.js.map +0 -1
- package/dist/query.d.ts +0 -97
- package/dist/query.d.ts.map +0 -1
- package/dist/query.js +0 -94
- package/dist/query.js.map +0 -1
- package/dist/realtime.d.ts +0 -114
- package/dist/realtime.d.ts.map +0 -1
- package/dist/realtime.js +0 -372
- package/dist/realtime.js.map +0 -1
- package/dist/rest.d.ts +0 -50
- package/dist/rest.d.ts.map +0 -1
- package/dist/rest.js +0 -75
- package/dist/rest.js.map +0 -1
- package/dist/session.d.ts +0 -47
- package/dist/session.d.ts.map +0 -1
- package/dist/session.js +0 -136
- package/dist/session.js.map +0 -1
- package/dist/storage.d.ts +0 -239
- package/dist/storage.d.ts.map +0 -1
- package/dist/storage.js +0 -391
- package/dist/storage.js.map +0 -1
- package/dist/testing.d.ts +0 -38
- package/dist/testing.d.ts.map +0 -1
- package/dist/testing.js +0 -50
- package/dist/testing.js.map +0 -1
- package/dist/types.d.ts +0 -343
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/warn.d.ts +0 -4
- package/dist/warn.d.ts.map +0 -1
- package/dist/warn.js +0 -27
- package/dist/warn.js.map +0 -1
package/dist/http.d.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import type { SessionStore } from './session.js';
|
|
2
|
-
export declare class BackendError extends Error {
|
|
3
|
-
/** HTTP status code (0 if the request never completed). */
|
|
4
|
-
readonly httpStatus: number;
|
|
5
|
-
/** The API envelope's `status` field when present. */
|
|
6
|
-
readonly apiStatus?: number;
|
|
7
|
-
/** Backend error code, when present. */
|
|
8
|
-
readonly code?: string;
|
|
9
|
-
/**
|
|
10
|
-
* Correlation id for the failed request, from the `x-request-id` response
|
|
11
|
-
* header (the backend also puts it in the error body). Quote it in a bug
|
|
12
|
-
* report or log it next to your own error: it is what matches this call to
|
|
13
|
-
* the server-side stack trace in the project's logs.
|
|
14
|
-
*/
|
|
15
|
-
readonly requestId?: string;
|
|
16
|
-
constructor(message: string, httpStatus: number, apiStatus?: number, code?: string, requestId?: string);
|
|
17
|
-
}
|
|
18
|
-
export interface RequestOptions {
|
|
19
|
-
method?: string;
|
|
20
|
-
/** Headers scoped to this request. Override client-level headers. */
|
|
21
|
-
headers?: Record<string, string>;
|
|
22
|
-
/** JSON body. Mutually exclusive with `form`. */
|
|
23
|
-
body?: unknown;
|
|
24
|
-
/** Multipart body. Mutually exclusive with `body`. */
|
|
25
|
-
form?: FormData;
|
|
26
|
-
/** Skip attaching the Authorization header (used by auth endpoints). */
|
|
27
|
-
anonymous?: boolean;
|
|
28
|
-
/** Abort the request when this signal fires (`.abortSignal(signal)`). */
|
|
29
|
-
signal?: AbortSignal;
|
|
30
|
-
/**
|
|
31
|
-
* Parse the response body as-is instead of unwrapping the app's
|
|
32
|
-
* `{ status, data }` envelope. Better Auth's native /api/auth/* endpoints
|
|
33
|
-
* return plain JSON, so the auth client sets this.
|
|
34
|
-
*/
|
|
35
|
-
raw?: boolean;
|
|
36
|
-
/**
|
|
37
|
-
* Cookie mode for this request. Defaults to fetch's own `same-origin`.
|
|
38
|
-
* OAuth start endpoints need `'include'`: better-auth sets a signed state
|
|
39
|
-
* cookie on that response and verifies it on the provider callback, and a
|
|
40
|
-
* cross-origin response's cookie is discarded without it (the callback then
|
|
41
|
-
* fails with `state_mismatch`).
|
|
42
|
-
*/
|
|
43
|
-
credentials?: RequestCredentials;
|
|
44
|
-
/** Internal: prevents infinite refresh recursion. */
|
|
45
|
-
_retry?: boolean;
|
|
46
|
-
}
|
|
47
|
-
/** What every request reports to `client.on('request', ...)`. */
|
|
48
|
-
export interface RequestEvent {
|
|
49
|
-
method: string;
|
|
50
|
-
/** Path with query string, as sent. */
|
|
51
|
-
path: string;
|
|
52
|
-
/** HTTP status, or 0 when the request never completed (network, abort). */
|
|
53
|
-
status: number;
|
|
54
|
-
/** Wall time from send to response headers, in milliseconds. */
|
|
55
|
-
durationMs: number;
|
|
56
|
-
/** `x-request-id`, the id to quote when reporting a server-side failure. */
|
|
57
|
-
requestId?: string;
|
|
58
|
-
/** Set when the request failed outright rather than answering. */
|
|
59
|
-
error?: unknown;
|
|
60
|
-
}
|
|
61
|
-
export type RequestObserver = (event: RequestEvent) => void;
|
|
62
|
-
/**
|
|
63
|
-
* fetch wrapper that injects the bearer token, unwraps the API envelope, maps
|
|
64
|
-
* failures to BackendError, and performs single-flight token refresh on 401.
|
|
65
|
-
*/
|
|
66
|
-
export declare class HttpClient {
|
|
67
|
-
private readonly baseUrl;
|
|
68
|
-
private readonly store;
|
|
69
|
-
private readonly opts;
|
|
70
|
-
/** Performs the refresh; returns true on success. Injected to avoid a cycle. */
|
|
71
|
-
private readonly doRefresh;
|
|
72
|
-
private refreshPromise;
|
|
73
|
-
constructor(baseUrl: string, store: SessionStore, opts: {
|
|
74
|
-
autoRefresh: boolean;
|
|
75
|
-
fetch: typeof fetch;
|
|
76
|
-
headers?: Record<string, string>;
|
|
77
|
-
/** Called once per HTTP round trip, including the retry after a refresh. */
|
|
78
|
-
onRequest?: RequestObserver;
|
|
79
|
-
},
|
|
80
|
-
/** Performs the refresh; returns true on success. Injected to avoid a cycle. */
|
|
81
|
-
doRefresh: () => Promise<boolean>);
|
|
82
|
-
/**
|
|
83
|
-
* Install (or clear) the request observer.
|
|
84
|
-
*
|
|
85
|
-
* Set rather than constructed, so `client.on('request', ...)` can be called
|
|
86
|
-
* after the client exists, and cleared again when the last listener goes: the
|
|
87
|
-
* timing path is skipped entirely while nobody is watching.
|
|
88
|
-
*/
|
|
89
|
-
setRequestObserver(observer: RequestObserver | undefined): void;
|
|
90
|
-
request<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
91
|
-
/**
|
|
92
|
-
* Like `request`, but keeps the response headers. PostgREST puts the row count
|
|
93
|
-
* in `Content-Range`, which is unreachable from the parsed body alone.
|
|
94
|
-
*/
|
|
95
|
-
requestWithHeaders<T>(path: string, options?: RequestOptions): Promise<{
|
|
96
|
-
data: T;
|
|
97
|
-
headers: Headers;
|
|
98
|
-
status: number;
|
|
99
|
-
}>;
|
|
100
|
-
/** Like `request`, but returns the raw Response (for binary downloads). */
|
|
101
|
-
requestRaw(path: string, options?: RequestOptions): Promise<Response>;
|
|
102
|
-
private sendWithRefresh;
|
|
103
|
-
/** Shared single-flight refresh: concurrent callers await the same promise. */
|
|
104
|
-
private refreshOnce;
|
|
105
|
-
private send;
|
|
106
|
-
/** An observer that throws must not fail the request it was watching. */
|
|
107
|
-
private emit;
|
|
108
|
-
private parse;
|
|
109
|
-
/** Parse a plain-JSON (non-envelope) response, mapping failures to BackendError. */
|
|
110
|
-
private parseRaw;
|
|
111
|
-
private errorMessage;
|
|
112
|
-
/** Absolute URL for a path. Public so callers can navigate to an endpoint
|
|
113
|
-
* rather than fetch it (see AuthClient.signInWithOAuth). */
|
|
114
|
-
url(path: string): string;
|
|
115
|
-
}
|
|
116
|
-
/** Convert a thrown BackendError (or any error) into a Supabase-shaped error object. */
|
|
117
|
-
export declare function toError(err: unknown): {
|
|
118
|
-
message: string;
|
|
119
|
-
status?: number;
|
|
120
|
-
code?: string;
|
|
121
|
-
requestId?: string;
|
|
122
|
-
};
|
|
123
|
-
//# sourceMappingURL=http.d.ts.map
|
package/dist/http.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAYjD,qBAAa,YAAa,SAAQ,KAAK;IACrC,2DAA2D;IAC3D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,sDAAsD;IACtD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,wCAAwC;IACxC,QAAQ,CAAC,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AE,OAAO,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAW7G"}
|
package/dist/http.js
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error thrown internally for any non-successful API response. Callers of the
|
|
3
|
-
* public SDK never see this: module boundaries catch it and return a
|
|
4
|
-
* `{ data, error }` result instead. Reserved for programmer misuse leaks only.
|
|
5
|
-
*/
|
|
6
|
-
/** The backend sets `x-request-id` on every response; older ones may not. */
|
|
7
|
-
function requestIdOf(res) {
|
|
8
|
-
return res.headers?.get('x-request-id') ?? undefined;
|
|
9
|
-
}
|
|
10
|
-
export class BackendError extends Error {
|
|
11
|
-
constructor(message, httpStatus, apiStatus, code, requestId) {
|
|
12
|
-
super(message);
|
|
13
|
-
this.name = 'BackendError';
|
|
14
|
-
this.httpStatus = httpStatus;
|
|
15
|
-
this.apiStatus = apiStatus;
|
|
16
|
-
this.code = code;
|
|
17
|
-
this.requestId = requestId;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* fetch wrapper that injects the bearer token, unwraps the API envelope, maps
|
|
22
|
-
* failures to BackendError, and performs single-flight token refresh on 401.
|
|
23
|
-
*/
|
|
24
|
-
export class HttpClient {
|
|
25
|
-
constructor(baseUrl, store, opts,
|
|
26
|
-
/** Performs the refresh; returns true on success. Injected to avoid a cycle. */
|
|
27
|
-
doRefresh) {
|
|
28
|
-
this.baseUrl = baseUrl;
|
|
29
|
-
this.store = store;
|
|
30
|
-
this.opts = opts;
|
|
31
|
-
this.doRefresh = doRefresh;
|
|
32
|
-
this.refreshPromise = null;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Install (or clear) the request observer.
|
|
36
|
-
*
|
|
37
|
-
* Set rather than constructed, so `client.on('request', ...)` can be called
|
|
38
|
-
* after the client exists, and cleared again when the last listener goes: the
|
|
39
|
-
* timing path is skipped entirely while nobody is watching.
|
|
40
|
-
*/
|
|
41
|
-
setRequestObserver(observer) {
|
|
42
|
-
this.opts.onRequest = observer;
|
|
43
|
-
}
|
|
44
|
-
async request(path, options = {}) {
|
|
45
|
-
return (await this.requestWithHeaders(path, options)).data;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Like `request`, but keeps the response headers. PostgREST puts the row count
|
|
49
|
-
* in `Content-Range`, which is unreachable from the parsed body alone.
|
|
50
|
-
*/
|
|
51
|
-
async requestWithHeaders(path, options = {}) {
|
|
52
|
-
const res = await this.sendWithRefresh(path, options);
|
|
53
|
-
const data = options.raw ? await this.parseRaw(res) : await this.parse(res);
|
|
54
|
-
return { data, headers: res.headers, status: res.status };
|
|
55
|
-
}
|
|
56
|
-
/** Like `request`, but returns the raw Response (for binary downloads). */
|
|
57
|
-
async requestRaw(path, options = {}) {
|
|
58
|
-
const res = await this.sendWithRefresh(path, options);
|
|
59
|
-
if (!res.ok) {
|
|
60
|
-
const message = await this.errorMessage(res);
|
|
61
|
-
throw new BackendError(message, res.status, undefined, undefined, requestIdOf(res));
|
|
62
|
-
}
|
|
63
|
-
return res;
|
|
64
|
-
}
|
|
65
|
-
async sendWithRefresh(path, options) {
|
|
66
|
-
const res = await this.send(path, options);
|
|
67
|
-
if (res.status === 401 && this.opts.autoRefresh && !options.anonymous && !options._retry) {
|
|
68
|
-
const refreshed = await this.refreshOnce();
|
|
69
|
-
if (refreshed) {
|
|
70
|
-
return this.send(path, { ...options, _retry: true });
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return res;
|
|
74
|
-
}
|
|
75
|
-
/** Shared single-flight refresh: concurrent callers await the same promise. */
|
|
76
|
-
refreshOnce() {
|
|
77
|
-
if (!this.refreshPromise) {
|
|
78
|
-
this.refreshPromise = this.doRefresh().finally(() => {
|
|
79
|
-
this.refreshPromise = null;
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
return this.refreshPromise;
|
|
83
|
-
}
|
|
84
|
-
async send(path, options) {
|
|
85
|
-
await this.store.hydrate();
|
|
86
|
-
const headers = { ...this.opts.headers, ...options.headers };
|
|
87
|
-
const session = this.store.get();
|
|
88
|
-
if (!options.anonymous && session?.accessToken) {
|
|
89
|
-
headers['Authorization'] = `Bearer ${session.accessToken}`;
|
|
90
|
-
}
|
|
91
|
-
let body;
|
|
92
|
-
if (options.form) {
|
|
93
|
-
body = options.form; // browser/runtime sets the multipart boundary
|
|
94
|
-
}
|
|
95
|
-
else if (options.body !== undefined) {
|
|
96
|
-
headers['Content-Type'] = 'application/json';
|
|
97
|
-
body = JSON.stringify(options.body);
|
|
98
|
-
}
|
|
99
|
-
const method = options.method ?? 'GET';
|
|
100
|
-
if (!this.opts.onRequest) {
|
|
101
|
-
return this.opts.fetch(this.url(path), {
|
|
102
|
-
method,
|
|
103
|
-
headers,
|
|
104
|
-
body,
|
|
105
|
-
signal: options.signal,
|
|
106
|
-
...(options.credentials ? { credentials: options.credentials } : {}),
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
// Timed only when someone is listening: reading the clock twice per request
|
|
110
|
-
// for an observer nobody registered is a cost every app pays for a feature
|
|
111
|
-
// most do not use.
|
|
112
|
-
const startedAt = Date.now();
|
|
113
|
-
try {
|
|
114
|
-
const res = await this.opts.fetch(this.url(path), {
|
|
115
|
-
method,
|
|
116
|
-
headers,
|
|
117
|
-
body,
|
|
118
|
-
signal: options.signal,
|
|
119
|
-
...(options.credentials ? { credentials: options.credentials } : {}),
|
|
120
|
-
});
|
|
121
|
-
this.emit({
|
|
122
|
-
method,
|
|
123
|
-
path,
|
|
124
|
-
status: res.status,
|
|
125
|
-
durationMs: Date.now() - startedAt,
|
|
126
|
-
requestId: requestIdOf(res),
|
|
127
|
-
});
|
|
128
|
-
return res;
|
|
129
|
-
}
|
|
130
|
-
catch (error) {
|
|
131
|
-
this.emit({ method, path, status: 0, durationMs: Date.now() - startedAt, error });
|
|
132
|
-
throw error;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
/** An observer that throws must not fail the request it was watching. */
|
|
136
|
-
emit(event) {
|
|
137
|
-
try {
|
|
138
|
-
this.opts.onRequest?.(event);
|
|
139
|
-
}
|
|
140
|
-
catch {
|
|
141
|
-
// an observer is a spectator
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
async parse(res) {
|
|
145
|
-
let envelope;
|
|
146
|
-
try {
|
|
147
|
-
envelope = (await res.json());
|
|
148
|
-
}
|
|
149
|
-
catch {
|
|
150
|
-
// non-JSON response
|
|
151
|
-
}
|
|
152
|
-
if (!res.ok || (envelope && envelope.status === 0)) {
|
|
153
|
-
const message = envelope?.message ?? `Request failed with status ${res.status}`;
|
|
154
|
-
throw new BackendError(message, res.status, envelope?.status, undefined, requestIdOf(res));
|
|
155
|
-
}
|
|
156
|
-
return (envelope?.data ?? envelope);
|
|
157
|
-
}
|
|
158
|
-
/** Parse a plain-JSON (non-envelope) response, mapping failures to BackendError. */
|
|
159
|
-
async parseRaw(res) {
|
|
160
|
-
let body;
|
|
161
|
-
try {
|
|
162
|
-
body = await res.json();
|
|
163
|
-
}
|
|
164
|
-
catch {
|
|
165
|
-
body = undefined;
|
|
166
|
-
}
|
|
167
|
-
if (!res.ok) {
|
|
168
|
-
const failure = (body ?? {});
|
|
169
|
-
const message = failure.message ?? `Request failed with status ${res.status}`;
|
|
170
|
-
throw new BackendError(message, res.status, undefined, failure.code, requestIdOf(res));
|
|
171
|
-
}
|
|
172
|
-
return body;
|
|
173
|
-
}
|
|
174
|
-
async errorMessage(res) {
|
|
175
|
-
try {
|
|
176
|
-
const body = (await res.json());
|
|
177
|
-
if (body?.message)
|
|
178
|
-
return body.message;
|
|
179
|
-
}
|
|
180
|
-
catch {
|
|
181
|
-
// ignore
|
|
182
|
-
}
|
|
183
|
-
return `Request failed with status ${res.status}`;
|
|
184
|
-
}
|
|
185
|
-
/** Absolute URL for a path. Public so callers can navigate to an endpoint
|
|
186
|
-
* rather than fetch it (see AuthClient.signInWithOAuth). */
|
|
187
|
-
url(path) {
|
|
188
|
-
return `${this.baseUrl.replace(/\/$/, '')}${path}`;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
/** Convert a thrown BackendError (or any error) into a Supabase-shaped error object. */
|
|
192
|
-
export function toError(err) {
|
|
193
|
-
if (err instanceof BackendError) {
|
|
194
|
-
return {
|
|
195
|
-
message: err.message,
|
|
196
|
-
status: err.httpStatus || undefined,
|
|
197
|
-
code: err.code,
|
|
198
|
-
requestId: err.requestId,
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
if (err instanceof Error)
|
|
202
|
-
return { message: err.message };
|
|
203
|
-
return { message: String(err) };
|
|
204
|
-
}
|
|
205
|
-
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,6EAA6E;AAC7E,SAAS,WAAW,CAAC,GAAa;IAChC,OAAO,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,cAAc,CAAC,IAAI,SAAS,CAAC;AACvD,CAAC;AAED,MAAM,OAAO,YAAa,SAAQ,KAAK;IAerC,YAAY,OAAe,EAAE,UAAkB,EAAE,SAAkB,EAAE,IAAa,EAAE,SAAkB;QACpG,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF;AAiDD;;;GAGG;AACH,MAAM,OAAO,UAAU;IAGrB,YACmB,OAAe,EACf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CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC;IACrD,CAAC;CACF;AAED,wFAAwF;AACxF,MAAM,UAAU,OAAO,CAAC,GAAY;IAClC,IAAI,GAAG,YAAY,YAAY,EAAE,CAAC;QAChC,OAAO;YACL,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,MAAM,EAAE,GAAG,CAAC,UAAU,IAAI,SAAS;YACnC,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,SAAS,EAAE,GAAG,CAAC,SAAS;SACzB,CAAC;IACJ,CAAC;IACD,IAAI,GAAG,YAAY,KAAK;QAAE,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;IAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;AAClC,CAAC"}
|
package/dist/index.d.ts
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import type { RequestObserver } from './http.js';
|
|
2
|
-
import { memoryStorage, localStorageStorage, keyValueStorage } from './session.js';
|
|
3
|
-
import { AuthClient } from './auth.js';
|
|
4
|
-
import { StorageClient } from './storage.js';
|
|
5
|
-
import { FunctionsClient } from './functions.js';
|
|
6
|
-
import { RealtimeModule } from './realtime.js';
|
|
7
|
-
import { RealtimeChannel, type RealtimeChannelOptions } from './channel.js';
|
|
8
|
-
import type { PostgrestCount, PostgrestResponse } from './postgrest.js';
|
|
9
|
-
import type { ClientOptions } from './types.js';
|
|
10
|
-
/**
|
|
11
|
-
* What the `client.transaction()` callback is handed.
|
|
12
|
-
*
|
|
13
|
-
* Typed loosely on purpose: the relation names come from the generated
|
|
14
|
-
* `Database` on `client.from()`, and reproducing that overload pair here for a
|
|
15
|
-
* callback that returns nothing buys inference no one reads at the cost of a
|
|
16
|
-
* signature nobody can follow.
|
|
17
|
-
*/
|
|
18
|
-
export interface TransactionContext {
|
|
19
|
-
from<Row extends object = Record<string, unknown>>(table: string): TypedQuery<Row, Partial<Row>, Partial<Row>>;
|
|
20
|
-
}
|
|
21
|
-
/** Options for `client.rpc(fn, args, options)`, mirroring supabase-js. */
|
|
22
|
-
export interface RpcOptions {
|
|
23
|
-
/** Send the request as HEAD: no rows, only the count. */
|
|
24
|
-
head?: boolean;
|
|
25
|
-
/** Use the read-only GET form, with the arguments as query parameters. */
|
|
26
|
-
get?: boolean;
|
|
27
|
-
count?: PostgrestCount;
|
|
28
|
-
}
|
|
29
|
-
import type { DefaultSchemaName, FunctionArgs, FunctionName, FunctionReturns, GenericDatabase, GenericSchema, InsertOf, RelationName, RowOf, SchemaOf, TypedQuery, UpdateOf } from './database.js';
|
|
30
|
-
/**
|
|
31
|
-
* Supabase-js-compatible client for a Motherbase backend.
|
|
32
|
-
*
|
|
33
|
-
* Drop-in shaped: `client.from(table).select()…`, `client.auth.signInWithPassword()`,
|
|
34
|
-
* `client.storage.from(bucket)`, `client.channel(name)`, `client.functions.invoke()`.
|
|
35
|
-
*
|
|
36
|
-
* Pass the type generated by `motherbase gen types typescript` to get real
|
|
37
|
-
* inference: `createClient<Database>(url, key)` then types every row, rejects
|
|
38
|
-
* unknown columns in `.select()`, checks `.insert()` payloads against the
|
|
39
|
-
* Insert shape and types `.rpc()` from `Functions`. Without it the client
|
|
40
|
-
* behaves exactly as it did before generics existed.
|
|
41
|
-
*/
|
|
42
|
-
export declare class MotherbaseClient<Database = GenericDatabase, SchemaName = DefaultSchemaName<Database>, Schema extends GenericSchema = SchemaOf<Database, SchemaName>> {
|
|
43
|
-
private readonly url;
|
|
44
|
-
/** Accepted for supabase-js signature parity; sent as an `apikey` header when set. */
|
|
45
|
-
readonly key?: string | undefined;
|
|
46
|
-
readonly auth: AuthClient;
|
|
47
|
-
readonly storage: StorageClient;
|
|
48
|
-
readonly functions: FunctionsClient;
|
|
49
|
-
/** Low-level realtime transport. Prefer `channel()` for the Supabase surface. */
|
|
50
|
-
readonly realtime: RealtimeModule;
|
|
51
|
-
private readonly http;
|
|
52
|
-
private readonly store;
|
|
53
|
-
private readonly channels;
|
|
54
|
-
private static warnedAboutStorage;
|
|
55
|
-
/** `options.compat === 'supabase'`, read by every query builder this client makes. */
|
|
56
|
-
private readonly compat;
|
|
57
|
-
private readonly requestObservers;
|
|
58
|
-
constructor(url: string,
|
|
59
|
-
/** Accepted for supabase-js signature parity; sent as an `apikey` header when set. */
|
|
60
|
-
key?: string | undefined, options?: ClientOptions);
|
|
61
|
-
/**
|
|
62
|
-
* Start a PostgREST-style query against a table or view.
|
|
63
|
-
*
|
|
64
|
-
* The first overload is the typed path: with a generated `Database` the
|
|
65
|
-
* relation name is checked and the row/insert/update types come from it.
|
|
66
|
-
* The second keeps the pre-generics form (`from<MyRow>('t')`) working; its
|
|
67
|
-
* `never` default makes the parameter unusable unless `Row` is passed
|
|
68
|
-
* explicitly, so a bare `from('typo')` still has to satisfy the first
|
|
69
|
-
* overload rather than silently falling through to an unchecked one.
|
|
70
|
-
*/
|
|
71
|
-
from<Name extends RelationName<Schema>>(table: Name): TypedQuery<RowOf<Schema, Name>, InsertOf<Schema, Name>, UpdateOf<Schema, Name>>;
|
|
72
|
-
from<Row extends object = never>(table: [Row] extends [never] ? never : string): TypedQuery<Row, Partial<Row>, Partial<Row>>;
|
|
73
|
-
/**
|
|
74
|
-
* Call a database function, typed from the generated `Functions` map.
|
|
75
|
-
*
|
|
76
|
-
* The transport is `POST /rest/v1/rpc/<fn>`, which the REST layer gains in
|
|
77
|
-
* Phase 2.8. The typing is independent of that work: it reads only the
|
|
78
|
-
* generated `Database`, so it is correct the moment the route exists.
|
|
79
|
-
*
|
|
80
|
-
* `get` and `head` switch to the read-only forms, which carry their arguments
|
|
81
|
-
* as query parameters rather than as a body, exactly as supabase-js does.
|
|
82
|
-
*/
|
|
83
|
-
rpc<Name extends FunctionName<Schema>>(fn: Name, args?: FunctionArgs<Schema, Name>, options?: RpcOptions): Promise<PostgrestResponse<FunctionReturns<Schema, Name>>>;
|
|
84
|
-
/**
|
|
85
|
-
* Watch every HTTP request this client makes.
|
|
86
|
-
*
|
|
87
|
-
* One event per round trip, with method, path, status, duration and the
|
|
88
|
-
* `x-request-id` the server logged it under. That id is the whole point: it
|
|
89
|
-
* is what turns "a query was slow for a user yesterday" into a line in the
|
|
90
|
-
* project's logs.
|
|
91
|
-
*
|
|
92
|
-
* ```ts
|
|
93
|
-
* client.on('request', e => console.log(e.method, e.path, e.status, e.durationMs))
|
|
94
|
-
* ```
|
|
95
|
-
*
|
|
96
|
-
* Returns the unsubscribe function. An observer that throws is ignored: it is
|
|
97
|
-
* a spectator, and a broken logger must not fail the request it was logging.
|
|
98
|
-
*/
|
|
99
|
-
on(event: 'request', listener: RequestObserver): () => void;
|
|
100
|
-
private syncRequestObserver;
|
|
101
|
-
/**
|
|
102
|
-
* Several writes, applied in one database transaction, all or nothing.
|
|
103
|
-
*
|
|
104
|
-
* supabase-js has no equivalent. What people write instead is a sequence of
|
|
105
|
-
* awaited writes inside a `try`, which is not a rollback: whatever already
|
|
106
|
-
* committed stays committed, and the catch block is left holding half a
|
|
107
|
-
* change it cannot undo.
|
|
108
|
-
*
|
|
109
|
-
* The callback does not await anything. It DESCRIBES the writes; they are
|
|
110
|
-
* sent together and applied together:
|
|
111
|
-
*
|
|
112
|
-
* ```ts
|
|
113
|
-
* const { data, error } = await client.transaction(tx => {
|
|
114
|
-
* tx.from('orders').insert({ id, total })
|
|
115
|
-
* tx.from('stock').update({ count: 4 }).eq('sku', sku)
|
|
116
|
-
* })
|
|
117
|
-
* ```
|
|
118
|
-
*
|
|
119
|
-
* `data` is one result array per operation, in the order they were declared.
|
|
120
|
-
* Reads are refused: a batch exists to make writes atomic, and a read in the
|
|
121
|
-
* middle of one invites expectations about ordering that nothing guarantees.
|
|
122
|
-
*/
|
|
123
|
-
transaction(build: (tx: TransactionContext) => void): Promise<PostgrestResponse<unknown[][]>>;
|
|
124
|
-
/** Create (or reuse) a realtime channel. */
|
|
125
|
-
channel(name: string, opts?: RealtimeChannelOptions): RealtimeChannel;
|
|
126
|
-
/** Every channel this client created, as supabase-js reports them. */
|
|
127
|
-
getChannels(): RealtimeChannel[];
|
|
128
|
-
/**
|
|
129
|
-
* supabase-js's schema switcher.
|
|
130
|
-
*
|
|
131
|
-
* The Motherbase REST layer serves `public` and nothing else, so this returns
|
|
132
|
-
* the client for `'public'` and throws for anything else rather than issuing
|
|
133
|
-
* a request that would silently read the wrong tables.
|
|
134
|
-
*/
|
|
135
|
-
schema(name: string): this;
|
|
136
|
-
/** Unsubscribe and drop a channel. */
|
|
137
|
-
removeChannel(channel: RealtimeChannel): Promise<'ok'>;
|
|
138
|
-
/** Unsubscribe and drop every channel. */
|
|
139
|
-
removeAllChannels(): Promise<'ok'>;
|
|
140
|
-
/** Load any persisted session before first use. Optional but recommended. */
|
|
141
|
-
hydrate(): Promise<unknown>;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Create a Supabase-compatible Motherbase client.
|
|
145
|
-
*
|
|
146
|
-
* In a Next.js app, prefer `createBrowserClient` / `createServerClient` from
|
|
147
|
-
* `@motherbase/ssr`: they persist the session to a cookie both halves can read.
|
|
148
|
-
* `createClient()` on its own keeps the session in memory, which the server
|
|
149
|
-
* cannot see, so every server-rendered `getUser()` returns null.
|
|
150
|
-
*
|
|
151
|
-
* @param url Backend API base URL.
|
|
152
|
-
* @param key Anon/publishable key (optional). Sent as an `apikey` header.
|
|
153
|
-
* @param options Session storage, fetch override, extra headers.
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* ```ts
|
|
157
|
-
* import type { Database } from './database.types'
|
|
158
|
-
* const client = createClient<Database>(url, anonKey)
|
|
159
|
-
* ```
|
|
160
|
-
*/
|
|
161
|
-
export declare function createClient<Database = GenericDatabase, SchemaName = DefaultSchemaName<Database>, Schema extends GenericSchema = SchemaOf<Database, SchemaName>>(url: string, key?: string, options?: ClientOptions): MotherbaseClient<Database, SchemaName, Schema>;
|
|
162
|
-
export { BackendError } from './http.js';
|
|
163
|
-
export { memoryStorage, localStorageStorage, keyValueStorage };
|
|
164
|
-
export { normalizeSession, normalizeUser } from './compat.js';
|
|
165
|
-
export { cookieStorage, serverCookieStorage, SESSION_COOKIE_KEY } from './cookie.js';
|
|
166
|
-
export { PostgrestQueryBuilder } from './postgrest.js';
|
|
167
|
-
export type { RequestEvent, RequestObserver } from './http.js';
|
|
168
|
-
export type { PostgrestSingleBuilder, PostgrestTextBuilder, PostgrestExplainBuilder, PostgrestResponse, PostgrestPrimitive, PostgrestArrayOperand, PostgrestFilterOperator, PostgrestIsValue, PostgrestCount, TextSearchType, ReferencedTableOption, OrderOptions, SelectOptions, InsertOptions, UpsertOptions, MutateOptions, ExplainOptions, } from './postgrest.js';
|
|
169
|
-
export type { GenericDatabase, GenericSchema, GenericTable, GenericView, GenericFunction, DefaultSchemaName, SchemaOf, Relations, RelationName, RowOf, InsertOf, UpdateOf, FunctionName, FunctionArgs, FunctionReturns, TypedQuery, TypedSingleQuery, SelectResult, ValidateSelect, UnknownSelectColumns, EmbeddedSelectSeam, ColumnName, FilterValue, } from './database.js';
|
|
170
|
-
export { AuthClient } from './auth.js';
|
|
171
|
-
export { MfaClient } from './mfa.js';
|
|
172
|
-
export { AuthAdminClient } from './admin.js';
|
|
173
|
-
export type { AdminListUsersParams, AdminUserList, AdminCreateUserParams, AdminCreatedUser, AdminUpdateUserParams, } from './admin.js';
|
|
174
|
-
export type { MfaFactor, MfaEnrollResponse, MfaChallengeResponse } from './mfa.js';
|
|
175
|
-
export type { SignUpCredentials, SignInWithPasswordCredentials, SignInWithOtpCredentials, VerifyOtpParams, SignInWithOAuthCredentials, UpdateUserAttributes, DeleteUserAttributes, Subscription, } from './auth.js';
|
|
176
|
-
export { StorageClient, StorageBucket } from './storage.js';
|
|
177
|
-
export type { UploadOptions, UploadResult, ObjectInfo, ListOptions, BucketInfo } from './storage.js';
|
|
178
|
-
export { FunctionsClient, FunctionsError, FunctionsHttpError, FunctionsRelayError, FunctionsFetchError } from './functions.js';
|
|
179
|
-
export type { FunctionInvokeAuth, FunctionInvokeOptions } from './functions.js';
|
|
180
|
-
export { RealtimeChannel } from './channel.js';
|
|
181
|
-
export type { PostgresChangeEvent, PostgresChangeFilter, PostgresChangePayload, ChannelStatus, BroadcastFilter, PresenceFilter, BroadcastMessage, BroadcastReceived, RealtimeChannelOptions, PresenceEntry, PresenceState, PresenceJoinPayload, PresenceLeavePayload, } from './channel.js';
|
|
182
|
-
export type { CookieMethods, CookieToSet, CookieOptions } from './cookie.js';
|
|
183
|
-
export type { ApiEnvelope, User, UserIdentity, UserMetadata, BetterAuthUserFields, MotherbaseUserFields, SupabaseUserAliases, Timestamp, Tokens, Session, FileObject, StoredFile, FileStatus, FileVisibility, StorageUploadResponse, StorageRemoveResponse, UploadInput, SessionStorageAdapter, ClientOptions, SupabaseStyleOptions, KeyValueStorageAdapter, MotherbaseResponse, MotherbaseError, AuthChangeEvent, AuthChangeListener, } from './types.js';
|
|
184
|
-
export type { RealtimeConnectOptions, RealtimeStatus, RealtimeStatusListener, RealtimeWatchEvent, RealtimeWatchOptions, IoFactory, SocketLike, } from './realtime.js';
|
|
185
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAgB,eAAe,EAAE,MAAM,WAAW,CAAC;AAE/D,OAAO,EAAgB,aAAa,EAAE,mBAAmB,EAAE,eAAe,EAAqB,MAAM,cAAc,CAAC;AACpH,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,KAAK,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAE5E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