@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.
Files changed (90) hide show
  1. package/README.md +379 -284
  2. package/package.json +1 -1
  3. package/dist/admin.d.ts +0 -81
  4. package/dist/admin.d.ts.map +0 -1
  5. package/dist/admin.js +0 -85
  6. package/dist/admin.js.map +0 -1
  7. package/dist/auth.d.ts +0 -362
  8. package/dist/auth.d.ts.map +0 -1
  9. package/dist/auth.js +0 -721
  10. package/dist/auth.js.map +0 -1
  11. package/dist/channel.d.ts +0 -122
  12. package/dist/channel.d.ts.map +0 -1
  13. package/dist/channel.js +0 -213
  14. package/dist/channel.js.map +0 -1
  15. package/dist/compat.d.ts +0 -40
  16. package/dist/compat.d.ts.map +0 -1
  17. package/dist/compat.js +0 -98
  18. package/dist/compat.js.map +0 -1
  19. package/dist/cookie.d.ts +0 -68
  20. package/dist/cookie.d.ts.map +0 -1
  21. package/dist/cookie.js +0 -152
  22. package/dist/cookie.js.map +0 -1
  23. package/dist/database.d.ts +0 -188
  24. package/dist/database.d.ts.map +0 -1
  25. package/dist/database.js +0 -2
  26. package/dist/database.js.map +0 -1
  27. package/dist/devices.d.ts +0 -13
  28. package/dist/devices.d.ts.map +0 -1
  29. package/dist/devices.js +0 -13
  30. package/dist/devices.js.map +0 -1
  31. package/dist/edge.d.ts +0 -7
  32. package/dist/edge.d.ts.map +0 -1
  33. package/dist/edge.js +0 -13
  34. package/dist/edge.js.map +0 -1
  35. package/dist/functions.d.ts +0 -60
  36. package/dist/functions.d.ts.map +0 -1
  37. package/dist/functions.js +0 -75
  38. package/dist/functions.js.map +0 -1
  39. package/dist/http.d.ts +0 -123
  40. package/dist/http.d.ts.map +0 -1
  41. package/dist/http.js +0 -205
  42. package/dist/http.js.map +0 -1
  43. package/dist/index.d.ts +0 -185
  44. package/dist/index.d.ts.map +0 -1
  45. package/dist/index.js +0 -331
  46. package/dist/index.js.map +0 -1
  47. package/dist/mfa.d.ts +0 -109
  48. package/dist/mfa.d.ts.map +0 -1
  49. package/dist/mfa.js +0 -134
  50. package/dist/mfa.js.map +0 -1
  51. package/dist/postgrest.d.ts +0 -326
  52. package/dist/postgrest.d.ts.map +0 -1
  53. package/dist/postgrest.js +0 -629
  54. package/dist/postgrest.js.map +0 -1
  55. package/dist/profile.d.ts +0 -16
  56. package/dist/profile.d.ts.map +0 -1
  57. package/dist/profile.js +0 -26
  58. package/dist/profile.js.map +0 -1
  59. package/dist/query.d.ts +0 -97
  60. package/dist/query.d.ts.map +0 -1
  61. package/dist/query.js +0 -94
  62. package/dist/query.js.map +0 -1
  63. package/dist/realtime.d.ts +0 -114
  64. package/dist/realtime.d.ts.map +0 -1
  65. package/dist/realtime.js +0 -372
  66. package/dist/realtime.js.map +0 -1
  67. package/dist/rest.d.ts +0 -50
  68. package/dist/rest.d.ts.map +0 -1
  69. package/dist/rest.js +0 -75
  70. package/dist/rest.js.map +0 -1
  71. package/dist/session.d.ts +0 -47
  72. package/dist/session.d.ts.map +0 -1
  73. package/dist/session.js +0 -136
  74. package/dist/session.js.map +0 -1
  75. package/dist/storage.d.ts +0 -239
  76. package/dist/storage.d.ts.map +0 -1
  77. package/dist/storage.js +0 -391
  78. package/dist/storage.js.map +0 -1
  79. package/dist/testing.d.ts +0 -38
  80. package/dist/testing.d.ts.map +0 -1
  81. package/dist/testing.js +0 -50
  82. package/dist/testing.js.map +0 -1
  83. package/dist/types.d.ts +0 -343
  84. package/dist/types.d.ts.map +0 -1
  85. package/dist/types.js +0 -2
  86. package/dist/types.js.map +0 -1
  87. package/dist/warn.d.ts +0 -4
  88. package/dist/warn.d.ts.map +0 -1
  89. package/dist/warn.js +0 -27
  90. package/dist/warn.js.map +0 -1
package/dist/storage.js DELETED
@@ -1,391 +0,0 @@
1
- import { toError } from './http.js';
2
- import { HTTP_ROUTES, contractPath } from '@motherbase/contracts';
3
- /** Bucket administration lives one level up from an object route. */
4
- const BUCKET_ROUTE = `${HTTP_ROUTES.files}/bucket`;
5
- /**
6
- * Supabase-compatible storage bucket handle over the authenticated
7
- * `/api/files` endpoints.
8
- *
9
- * Objects are addressed by path: `upload('123/pic.png')` then
10
- * `download('123/pic.png')`. The server-issued file id still works everywhere a
11
- * path does, because that is what every caller written before path addressing
12
- * has stored.
13
- */
14
- const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
15
- export class StorageBucket {
16
- constructor(http, baseUrl, bucket,
17
- /** Used only by `uploadToSignedUrl`, which PUTs straight to object storage. */
18
- fetchImpl) {
19
- this.http = http;
20
- this.baseUrl = baseUrl;
21
- this.bucket = bucket;
22
- this.fetchImpl = fetchImpl;
23
- }
24
- /**
25
- * Route for one object. A bare uuid is treated as a file id (the pre-path
26
- * addressing form, which existing callers have stored); anything else is a
27
- * key inside this bucket.
28
- */
29
- objectPath(pathOrId, kind) {
30
- if (UUID.test(pathOrId)) {
31
- if (kind === 'object-info') {
32
- throw new Error('info() addresses objects by path. Pass the key you uploaded under, not a file id.');
33
- }
34
- return contractPath.file(pathOrId, kind === 'object-url' ? 'url' : 'raw');
35
- }
36
- const key = pathOrId.split('/').map(encodeURIComponent).join('/');
37
- return `${HTTP_ROUTES.files}/${kind}/${encodeURIComponent(this.bucket)}/${key}`;
38
- }
39
- async upload(path, file, options = {}) {
40
- try {
41
- const form = new FormData();
42
- if (typeof Blob !== 'undefined' && file instanceof Blob) {
43
- // `contentType` used to be documented as a hint and then dropped on the
44
- // floor: the server reads the mime type off the multipart part, so the
45
- // only way to honour it is to retype the blob. `slice()` with a type is
46
- // the retyping that does not copy the bytes, which matters at upload
47
- // sizes.
48
- const body = options.contentType ? file.slice(0, file.size, options.contentType) : file;
49
- form.append('file', body, path);
50
- }
51
- else {
52
- form.append('file', file);
53
- }
54
- if (options.visibility)
55
- form.append('visibility', options.visibility);
56
- form.append('bucket', this.bucket);
57
- form.append('path', path);
58
- if (options.upsert)
59
- form.append('upsert', 'true');
60
- const created = await this.http.request(`${HTTP_ROUTES.files}/`, { method: 'POST', form });
61
- return {
62
- data: {
63
- path,
64
- id: created.file.id,
65
- fullPath: `${this.bucket}/${path}`,
66
- },
67
- error: null,
68
- };
69
- }
70
- catch (err) {
71
- return { data: null, error: toError(err) };
72
- }
73
- }
74
- /**
75
- * Upload several objects, a few at a time, reporting progress per file.
76
- *
77
- * Uploading a folder is the common case and `Promise.all` is the common
78
- * mistake: a hundred parallel multipart posts saturate the connection, and
79
- * the server rate limiter answers 429 to the tail of them. Four at a time
80
- * finishes sooner in practice and fails less.
81
- *
82
- * One failing file does not cancel the rest. The result reports every entry
83
- * in the order it was given, each with its own error or `null`, so the caller
84
- * can retry exactly what failed.
85
- *
86
- * ponytail: progress is per file, not per byte. Byte-level progress needs
87
- * XMLHttpRequest, which does not exist outside a browser; if a progress bar
88
- * has to move within one large file, that is the upgrade path.
89
- */
90
- async uploadMany(files, options = {}) {
91
- const total = files.length;
92
- const concurrency = Math.max(1, Math.min(options.concurrency ?? 4, total || 1));
93
- const results = new Array(total);
94
- let next = 0;
95
- let completed = 0;
96
- // A shared cursor rather than fixed slices: one slow file would otherwise
97
- // hold up its whole slice while other workers sit idle.
98
- const worker = async () => {
99
- for (;;) {
100
- const index = next++;
101
- if (index >= total)
102
- return;
103
- const entry = files[index];
104
- const { data, error } = await this.upload(entry.path, entry.file, entry.options);
105
- results[index] = { path: entry.path, data: data ?? null, error: error?.message ?? null };
106
- completed += 1;
107
- options.onProgress?.({ completed, total, path: entry.path, error: error?.message ?? null });
108
- }
109
- };
110
- await Promise.all(Array.from({ length: concurrency }, worker));
111
- return { data: results, error: null };
112
- }
113
- async download(path) {
114
- try {
115
- const res = await this.http.requestRaw(this.objectPath(path, 'object'));
116
- return { data: await res.blob(), error: null };
117
- }
118
- catch (err) {
119
- return { data: null, error: toError(err) };
120
- }
121
- }
122
- async remove(paths) {
123
- try {
124
- const removed = await Promise.all(paths.map(p => this.http.request(UUID.test(p)
125
- ? contractPath.file(p)
126
- : `${HTTP_ROUTES.files}/object/${encodeURIComponent(this.bucket)}/${p
127
- .split('/')
128
- .map(encodeURIComponent)
129
- .join('/')}`, { method: 'DELETE' })));
130
- return { data: removed, error: null };
131
- }
132
- catch (err) {
133
- return { data: null, error: toError(err) };
134
- }
135
- }
136
- /** Objects under a prefix, in the Supabase response shape. */
137
- async list(prefix = '', options = {}) {
138
- try {
139
- const query = new URLSearchParams();
140
- if (prefix)
141
- query.set('prefix', prefix);
142
- if (options.limit !== undefined)
143
- query.set('limit', String(options.limit));
144
- if (options.offset !== undefined)
145
- query.set('offset', String(options.offset));
146
- if (options.search)
147
- query.set('search', options.search);
148
- if (options.sortBy?.column)
149
- query.set('sortColumn', options.sortBy.column);
150
- if (options.sortBy?.order)
151
- query.set('sortOrder', options.sortBy.order);
152
- const suffix = query.toString() ? `?${query}` : '';
153
- const res = await this.http.request(`${HTTP_ROUTES.files}/list/${encodeURIComponent(this.bucket)}${suffix}`);
154
- return { data: res.objects, error: null };
155
- }
156
- catch (err) {
157
- return { data: null, error: toError(err) };
158
- }
159
- }
160
- /** Synchronous public URL (Supabase parity). Serves through the public bucket endpoint. */
161
- getPublicUrl(path) {
162
- const base = this.baseUrl.replace(/\/$/, '');
163
- return {
164
- data: {
165
- publicUrl: `${base}/api/storage/${encodeURIComponent(this.bucket)}/files/${encodeURIComponent(path)}`,
166
- },
167
- };
168
- }
169
- /**
170
- * A download URL for the object, valid for `expiresIn` seconds (default 3600,
171
- * maximum 7 days: the AWS SigV4 ceiling; anything outside that is a `400`).
172
- *
173
- * `expiresAt` reports when the URL actually stops working, and is `null` when
174
- * nothing expires: a public object's URL is permanent, and a private object on
175
- * the `local` storage driver resolves to the authenticated streaming endpoint,
176
- * which is bound to the session rather than to a clock and so cannot be handed
177
- * to a third party at all. Check it rather than assuming `expiresIn` applied,
178
- * that assumption is exactly what this used to get wrong, silently.
179
- */
180
- async createSignedUrl(path, expiresIn) {
181
- try {
182
- const query = expiresIn === undefined ? '' : `?expiresIn=${encodeURIComponent(expiresIn)}`;
183
- const res = await this.http.request(`${this.objectPath(path, 'object-url')}${query}`);
184
- return { data: { signedUrl: res.url, expiresAt: res.expiresAt ?? null }, error: null };
185
- }
186
- catch (err) {
187
- return { data: null, error: toError(err) };
188
- }
189
- }
190
- /**
191
- * Sign several objects in one call.
192
- *
193
- * There is no batch endpoint behind this: it signs each key and reports per
194
- * entry, exactly as supabase-js does, so one missing object yields one entry
195
- * with an `error` rather than failing the whole batch.
196
- */
197
- async createSignedUrls(paths, expiresIn) {
198
- const results = await Promise.all(paths.map(async (path) => {
199
- const { data, error } = await this.createSignedUrl(path, expiresIn);
200
- return { path, signedUrl: data?.signedUrl ?? null, error: error?.message ?? null };
201
- }));
202
- return { data: results, error: null };
203
- }
204
- /**
205
- * Replace the object at `path`. In supabase-js `update` is `upload` with
206
- * upsert forced on, and the same is true here.
207
- */
208
- async update(path, file, options = {}) {
209
- return this.upload(path, file, { ...options, upsert: true });
210
- }
211
- /** Copy an object to another key in this bucket. */
212
- async copy(from, to, options = {}) {
213
- return this.transfer('copy', from, to, options);
214
- }
215
- /** Move an object to another key in this bucket (copy, then delete the source). */
216
- async move(from, to, options = {}) {
217
- return this.transfer('move', from, to, options);
218
- }
219
- async transfer(action, from, to, options) {
220
- try {
221
- const res = await this.http.request(`${HTTP_ROUTES.files}/${action}`, { method: 'POST', body: { bucket: this.bucket, from, to, upsert: options.upsert === true } });
222
- return { data: { path: res.fullPath ?? `${this.bucket}/${to}` }, error: null };
223
- }
224
- catch (err) {
225
- return { data: null, error: toError(err) };
226
- }
227
- }
228
- /** One object's metadata, without downloading it. */
229
- async info(path) {
230
- try {
231
- const res = await this.http.request(this.objectPath(path, 'object-info'));
232
- return { data: res, error: null };
233
- }
234
- catch (err) {
235
- return { data: null, error: toError(err) };
236
- }
237
- }
238
- /**
239
- * Whether an object exists and this caller can read it.
240
- *
241
- * A 404 is the answer `false`, not a failure. Anything else (a 403, a network
242
- * error) is reported as an error rather than as "no": treating an
243
- * authorization failure as absence is how a UI ends up offering to create
244
- * something that is already there.
245
- */
246
- async exists(path) {
247
- const { data, error } = await this.info(path);
248
- if (data)
249
- return { data: true, error: null };
250
- if (error?.status === 404)
251
- return { data: false, error: null };
252
- return { data: null, error: error ?? { message: 'Unknown storage error' } };
253
- }
254
- /**
255
- * Mint a URL the browser can PUT the bytes to directly, skipping this server.
256
- *
257
- * Unlike supabase-js this needs the file's `size` and content type up front:
258
- * the upload is reserved against the bucket quota and the signature is bound
259
- * to that exact length, which is what stops a signed URL from becoming an
260
- * unbounded write. Pair it with `uploadToSignedUrl`.
261
- *
262
- * Requires the S3 driver; the local driver has no presigned uploads.
263
- */
264
- async createSignedUploadUrl(path, options) {
265
- try {
266
- const res = await this.http.request(`${HTTP_ROUTES.files}/presign`, {
267
- method: 'POST',
268
- body: {
269
- bucket: this.bucket,
270
- path,
271
- size: options.size,
272
- mime: options.contentType,
273
- visibility: options.visibility,
274
- },
275
- });
276
- // supabase-js's `token` is opaque to the caller and is handed straight
277
- // back to uploadToSignedUrl, so it carries what finalisation needs.
278
- const token = JSON.stringify({ url: res.uploadUrl, id: res.file.id });
279
- return { data: { signedUrl: res.uploadUrl, token, path }, error: null };
280
- }
281
- catch (err) {
282
- return { data: null, error: toError(err) };
283
- }
284
- }
285
- /**
286
- * Upload to a URL from `createSignedUploadUrl`: PUT the bytes to storage,
287
- * then tell the server the object landed. The finalise step is what makes the
288
- * row readable, so a PUT that succeeds and a finalise that fails leaves the
289
- * reservation to expire rather than a half-visible object.
290
- */
291
- async uploadToSignedUrl(path, token, file, options = {}) {
292
- let parsed;
293
- try {
294
- parsed = JSON.parse(token);
295
- }
296
- catch {
297
- return { data: null, error: { message: 'Invalid upload token. Use the token from createSignedUploadUrl().' } };
298
- }
299
- if (!parsed.url || !parsed.id) {
300
- return { data: null, error: { message: 'Invalid upload token. Use the token from createSignedUploadUrl().' } };
301
- }
302
- try {
303
- const put = await this.fetchImpl(parsed.url, {
304
- method: 'PUT',
305
- body: file,
306
- headers: { 'Content-Type': options.contentType ?? file.type ?? 'application/octet-stream' },
307
- });
308
- if (!put.ok) {
309
- return { data: null, error: { message: `Upload failed with status ${put.status}`, status: put.status } };
310
- }
311
- await this.http.request(`${contractPath.file(parsed.id)}/finalize`, { method: 'POST' });
312
- return { data: { path, id: parsed.id, fullPath: `${this.bucket}/${path}` }, error: null };
313
- }
314
- catch (err) {
315
- return { data: null, error: toError(err) };
316
- }
317
- }
318
- }
319
- /** Supabase-compatible storage client: `client.storage.from(bucket)`. */
320
- export class StorageClient {
321
- constructor(http, baseUrl, fetchImpl) {
322
- this.http = http;
323
- this.baseUrl = baseUrl;
324
- this.fetchImpl = fetchImpl;
325
- }
326
- from(bucket) {
327
- return new StorageBucket(this.http, this.baseUrl, bucket, this.fetchImpl);
328
- }
329
- /**
330
- * Bucket administration, supabase-js shaped.
331
- *
332
- * Every method here needs a SECRET project API key, which is the same rule
333
- * Supabase applies (bucket administration is a service-role operation). With
334
- * a publishable key they resolve with a 401 error, so keep them in server
335
- * code and setup scripts, never in a browser bundle.
336
- */
337
- async listBuckets() {
338
- try {
339
- const res = await this.http.request(BUCKET_ROUTE);
340
- return { data: res.buckets, error: null };
341
- }
342
- catch (err) {
343
- return { data: null, error: toError(err) };
344
- }
345
- }
346
- async getBucket(id) {
347
- return this.bucketCall(`${BUCKET_ROUTE}/${encodeURIComponent(id)}`);
348
- }
349
- async createBucket(id, options = {}) {
350
- return this.bucketCall(BUCKET_ROUTE, 'POST', { id, name: options.name, public: options.public === true });
351
- }
352
- async updateBucket(id, options) {
353
- return this.bucketCall(`${BUCKET_ROUTE}/${encodeURIComponent(id)}`, 'PUT', options);
354
- }
355
- /** Delete every object in the bucket, keeping the bucket itself. */
356
- async emptyBucket(id) {
357
- try {
358
- const res = await this.http.request(`${BUCKET_ROUTE}/${encodeURIComponent(id)}/empty`, { method: 'POST' });
359
- return { data: res, error: null };
360
- }
361
- catch (err) {
362
- return { data: null, error: toError(err) };
363
- }
364
- }
365
- /**
366
- * Delete the bucket. A bucket that still holds objects is a `409` unless
367
- * `force` is set, which queues a background deletion of its contents: an
368
- * accidental `deleteBucket` must not be able to destroy a project's files in
369
- * one unqualified call.
370
- */
371
- async deleteBucket(id, options = {}) {
372
- try {
373
- const query = options.force ? '?force=true' : '';
374
- const res = await this.http.request(`${BUCKET_ROUTE}/${encodeURIComponent(id)}${query}`, { method: 'DELETE' });
375
- return { data: res, error: null };
376
- }
377
- catch (err) {
378
- return { data: null, error: toError(err) };
379
- }
380
- }
381
- async bucketCall(path, method = 'GET', body) {
382
- try {
383
- const res = await this.http.request(path, { method, body });
384
- return { data: res, error: null };
385
- }
386
- catch (err) {
387
- return { data: null, error: toError(err) };
388
- }
389
- }
390
- }
391
- //# sourceMappingURL=storage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAsClE,qEAAqE;AACrE,MAAM,YAAY,GAAG,GAAG,WAAW,CAAC,KAAK,SAAS,CAAC;AAwBnD;;;;;;;;GAQG;AACH,MAAM,IAAI,GAAG,iEAAiE,CAAC;AAE/E,MAAM,OAAO,aAAa;IACxB,YACmB,IAAgB,EAChB,OAAe,EACf,MAAc;IAC/B,+EAA+E;IAC9D,SAAuB;QAJvB,SAAI,GAAJ,IAAI,CAAY;QAChB,YAAO,GAAP,OAAO,CAAQ;QACf,WAAM,GAAN,MAAM,CAAQ;QAEd,cAAS,GAAT,SAAS,CAAc;IACvC,CAAC;IAEJ;;;;OAIG;IACK,UAAU,CAAC,QAAgB,EAAE,IAA6C;QAChF,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YACxB,IAAI,IAAI,KAAK,aAAa,EAAE,CAAC;gBAC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CAAC;CACF"}
package/dist/testing.d.ts DELETED
@@ -1,38 +0,0 @@
1
- /**
2
- * Test-only client: run a query as a specific user, or as nobody.
3
- *
4
- * A row level security policy is a claim about who can see what, and the only
5
- * honest way to check it is to issue the same query as several callers and
6
- * compare the results. Without this, doing that in a test means creating users
7
- * and signing in as each of them through the real auth flow, which is slow
8
- * enough that most policies end up untested and wrong.
9
- *
10
- * ```ts
11
- * const asAlice = createTestClient(url, secretKey, { as: alice.id })
12
- * const asBob = createTestClient(url, secretKey, { as: bob.id })
13
- * const asAnon = createTestClient(url, secretKey, { as: 'anon' })
14
- *
15
- * expect((await asAlice.from('notes').select('*')).data).toHaveLength(1)
16
- * expect((await asBob.from('notes').select('*')).data).toHaveLength(0)
17
- * ```
18
- *
19
- * This is a server-side tool. It needs the project's SECRET key, which bypasses
20
- * RLS and must never reach a browser, so importing this module from application
21
- * code is a mistake even though nothing here can stop you. The server refuses
22
- * the impersonation header outright when the key is anything else, so the worst
23
- * case is a failed request rather than a privilege escalation.
24
- */
25
- import { MotherbaseClient } from './index.js';
26
- import type { ClientOptions } from './types.js';
27
- import type { GenericDatabase, GenericSchema, DefaultSchemaName, SchemaOf } from './database.js';
28
- /** The header the server reads. Exported so a raw fetch can do the same thing. */
29
- export declare const IMPERSONATE_HEADER = "x-motherbase-impersonate";
30
- export interface TestClientOptions extends ClientOptions {
31
- /**
32
- * Who to run as: a user id, `'anon'` for a signed-out visitor, or
33
- * `'service_role'` to keep the secret key's own bypass-everything identity.
34
- */
35
- as: string;
36
- }
37
- export declare function createTestClient<Database = GenericDatabase, SchemaName = DefaultSchemaName<Database>, Schema extends GenericSchema = SchemaOf<Database, SchemaName>>(url: string, secretKey: string, options: TestClientOptions): MotherbaseClient<Database, SchemaName, Schema>;
38
- //# sourceMappingURL=testing.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAgB,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEjG,kFAAkF;AAClF,eAAO,MAAM,kBAAkB,6BAA6B,CAAC;AAE7D,MAAM,WAAW,iBAAkB,SAAQ,aAAa;IACtD;;;OAGG;IACH,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,wBAAgB,gBAAgB,CAC9B,QAAQ,GAAG,eAAe,EAC1B,UAAU,GAAG,iBAAiB,CAAC,QAAQ,CAAC,EACxC,MAAM,SAAS,aAAa,GAAG,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC,EAE7D,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,iBAAiB,GACzB,gBAAgB,CAAC,QAAQ,EAAE,UAAU,EAAE,MAAM,CAAC,CAuBhD"}
package/dist/testing.js DELETED
@@ -1,50 +0,0 @@
1
- /**
2
- * Test-only client: run a query as a specific user, or as nobody.
3
- *
4
- * A row level security policy is a claim about who can see what, and the only
5
- * honest way to check it is to issue the same query as several callers and
6
- * compare the results. Without this, doing that in a test means creating users
7
- * and signing in as each of them through the real auth flow, which is slow
8
- * enough that most policies end up untested and wrong.
9
- *
10
- * ```ts
11
- * const asAlice = createTestClient(url, secretKey, { as: alice.id })
12
- * const asBob = createTestClient(url, secretKey, { as: bob.id })
13
- * const asAnon = createTestClient(url, secretKey, { as: 'anon' })
14
- *
15
- * expect((await asAlice.from('notes').select('*')).data).toHaveLength(1)
16
- * expect((await asBob.from('notes').select('*')).data).toHaveLength(0)
17
- * ```
18
- *
19
- * This is a server-side tool. It needs the project's SECRET key, which bypasses
20
- * RLS and must never reach a browser, so importing this module from application
21
- * code is a mistake even though nothing here can stop you. The server refuses
22
- * the impersonation header outright when the key is anything else, so the worst
23
- * case is a failed request rather than a privilege escalation.
24
- */
25
- import { createClient } from './index.js';
26
- import { memoryStorage } from './session.js';
27
- /** The header the server reads. Exported so a raw fetch can do the same thing. */
28
- export const IMPERSONATE_HEADER = 'x-motherbase-impersonate';
29
- export function createTestClient(url, secretKey, options) {
30
- if (!secretKey?.startsWith('mb_secret_')) {
31
- // Fail here rather than at the first query: a test that ran as the wrong
32
- // caller and passed is the failure this whole module exists to prevent.
33
- throw new Error('createTestClient needs the project secret key (mb_secret_…). A publishable key cannot impersonate, '
34
- + 'and the server refuses the header with a 403.');
35
- }
36
- const { as, ...rest } = options;
37
- return createClient(url, secretKey, {
38
- // A fresh in-memory session per client, so two clients in one test file
39
- // cannot share (or clobber) each other's stored session.
40
- storage: memoryStorage(),
41
- ...rest,
42
- headers: {
43
- ...rest.headers,
44
- // `service_role` is the absence of impersonation: the secret key already
45
- // is service_role, so sending a header would only add a lookup.
46
- ...(as === 'service_role' ? {} : { [IMPERSONATE_HEADER]: as }),
47
- },
48
- });
49
- }
50
- //# sourceMappingURL=testing.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,YAAY,EAAoB,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI7C,kFAAkF;AAClF,MAAM,CAAC,MAAM,kBAAkB,GAAG,0BAA0B,CAAC;AAU7D,MAAM,UAAU,gBAAgB,CAK9B,GAAW,EACX,SAAiB,EACjB,OAA0B;IAE1B,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QACzC,yEAAyE;QACzE,wEAAwE;QACxE,MAAM,IAAI,KAAK,CACb,qGAAqG;cACjG,+CAA+C,CACpD,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IAChC,OAAO,YAAY,CAA+B,GAAG,EAAE,SAAS,EAAE;QAChE,wEAAwE;QACxE,yDAAyD;QACzD,OAAO,EAAE,aAAa,EAAE;QACxB,GAAG,IAAI;QACP,OAAO,EAAE;YACP,GAAG,IAAI,CAAC,OAAO;YACf,yEAAyE;YACzE,gEAAgE;YAChE,GAAG,CAAC,EAAE,KAAK,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,kBAAkB,CAAC,EAAE,EAAE,EAAE,CAAC;SAC/D;KACF,CAAC,CAAC;AACL,CAAC"}