@biltme/backend 0.7.0 → 0.7.1

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
@@ -163,6 +163,12 @@ Bucket admin (`createBucket`, `updateBucket`, `deleteBucket`, `emptyBucket`,
163
163
  policies on `storage.objects` — author them with the `bilt_storage_apply`
164
164
  agent tool or the SQL editor.
165
165
 
166
+ On React Native, a `Blob` passed to `upload`, `update` or `uploadToSignedUrl`
167
+ is sent as bytes labelled with `contentType`, so `fetch(uri).blob()` from a
168
+ picked file passes a bucket's MIME allowlist. Pass `contentType` for such
169
+ files: a React Native Blob has no type of its own, and without one the upload
170
+ is labelled `application/octet-stream`.
171
+
166
172
  ## Web
167
173
 
168
174
  ```ts
@@ -188,6 +194,8 @@ const bilt = createClient(url, key, {
188
194
  - `createClient` *is* supabase-js's `createClient`, re-typed so that a call with no type
189
195
  arguments defaults its schema to the augmentable `Database` interface above instead of `any`.
190
196
  - `Database`, the empty interface a project augments to type its schema.
197
+ - On React Native, storage uploads send a `Blob` as bytes so `contentType` reaches the bucket (see Storage).
198
+ - Realtime is not available: `bilt.channel()` throws `REALTIME_NOT_SUPPORTED`. Refetch with `bilt.from(...)` on an interval or on screen focus instead.
191
199
  - `asyncStorage(impl)` factory wrapping `@react-native-async-storage/async-storage` to the supabase-js storage shape.
192
200
  - `webStorage()` and `memoryStorage()` for completeness.
193
201
  - `FunctionsHttpError`, `FunctionsRelayError`, `FunctionsFetchError`, `FunctionRegion` re-exports for clean `catch` and option typing.
@@ -196,6 +204,6 @@ const bilt = createClient(url, key, {
196
204
 
197
205
  ## Docs
198
206
 
199
- For everything else (auth flows, RLS, OAuth, realtime, functions reference),
207
+ For everything else (auth flows, RLS, OAuth, functions reference),
200
208
  use [Supabase's docs](https://supabase.com/docs/reference/javascript/introduction).
201
209
  The bilt backend speaks the same wire protocol.
package/dist/index.d.ts CHANGED
@@ -82,9 +82,12 @@ export type TablesUpdate<Name extends keyof PublicTables> = PublicTables[Name] e
82
82
  Update: infer U;
83
83
  } ? U : never;
84
84
  /**
85
- * Creates a Bilt client. supabase-js's `createClient` with two changes: called
85
+ * Creates a Bilt client. supabase-js's `createClient` with four changes: called
86
86
  * with no type arguments, the schema is {@link BiltDatabase} instead of `any`,
87
- * and a missing or malformed URL or key names Bilt Cloud rather than Supabase.
87
+ * a missing or malformed URL or key names Bilt Cloud rather than Supabase, on
88
+ * React Native a Blob upload is sent as bytes so `contentType` reaches the
89
+ * bucket's MIME allowlist (see {@link sendNativeBlobsAsBytes}), and opening a
90
+ * realtime channel throws because Bilt Cloud has no realtime (see {@link blockRealtime}).
88
91
  *
89
92
  * The second member of the intersection is supabase-js's own signature. An
90
93
  * intersection of function types is an overload set, so a bare call takes the
@@ -93,6 +96,7 @@ export type TablesUpdate<Name extends keyof PublicTables> = PublicTables[Name] e
93
96
  * supabase-js's defaults by hand across a caret range.
94
97
  */
95
98
  export declare const createClient: typeof createSupabaseClient<BiltDatabase> & typeof createSupabaseClient;
99
+ export { REALTIME_NOT_SUPPORTED } from './realtime';
96
100
  export { webStorage, memoryStorage, asyncStorage } from './storage';
97
101
  export type { StorageAdapter } from './storage';
98
102
  export { FunctionsHttpError, FunctionsRelayError, FunctionsFetchError, FunctionRegion } from '@supabase/supabase-js';
package/dist/index.js CHANGED
@@ -11796,6 +11796,51 @@ function shouldShowDeprecationWarning() {
11796
11796
  if (shouldShowDeprecationWarning())
11797
11797
  console.warn("⚠️ Node.js 20 and below are deprecated and will no longer be supported in future versions of @supabase/supabase-js. Please upgrade to Node.js 22 or later. For more information, visit: https://github.com/orgs/supabase/discussions/45715");
11798
11798
 
11799
+ // src/realtime.ts
11800
+ var REALTIME_NOT_SUPPORTED = "Realtime is not supported by Bilt Cloud yet. Refetch with bilt.from(...) on an interval or when the screen regains focus instead.";
11801
+ function notSupported() {
11802
+ throw new Error(REALTIME_NOT_SUPPORTED);
11803
+ }
11804
+ function blockRealtime(client) {
11805
+ client.channel = notSupported;
11806
+ client.realtime.channel = notSupported;
11807
+ client.realtime.connect = notSupported;
11808
+ }
11809
+
11810
+ // src/uploads.ts
11811
+ function isReactNative() {
11812
+ return typeof navigator !== "undefined" && navigator.product === "ReactNative";
11813
+ }
11814
+ function readBytes(blob) {
11815
+ if (typeof FileReader === "undefined")
11816
+ return blob.arrayBuffer();
11817
+ return new Promise((resolve, reject) => {
11818
+ const reader = new FileReader;
11819
+ reader.onload = () => resolve(reader.result);
11820
+ reader.onerror = () => reject(reader.error);
11821
+ reader.readAsArrayBuffer(blob);
11822
+ });
11823
+ }
11824
+ async function asBytes(body, options) {
11825
+ if (!isReactNative() || typeof Blob === "undefined" || !(body instanceof Blob))
11826
+ return [body, options];
11827
+ const contentType = options?.contentType ?? (body.type || "application/octet-stream");
11828
+ return [await readBytes(body), { ...options, contentType }];
11829
+ }
11830
+ function sendNativeBlobsAsBytes(client) {
11831
+ const storage = client.storage;
11832
+ const from = storage.from.bind(storage);
11833
+ storage.from = (id) => {
11834
+ const api = from(id);
11835
+ const upload = api.upload.bind(api);
11836
+ const update = api.update.bind(api);
11837
+ const uploadToSignedUrl = api.uploadToSignedUrl.bind(api);
11838
+ api.upload = async (path, body, options) => upload(path, ...await asBytes(body, options));
11839
+ api.update = async (path, body, options) => update(path, ...await asBytes(body, options));
11840
+ api.uploadToSignedUrl = async (path, token, body, options) => uploadToSignedUrl(path, token, ...await asBytes(body, options));
11841
+ return api;
11842
+ };
11843
+ }
11799
11844
  // src/storage/memory.ts
11800
11845
  function memoryStorage() {
11801
11846
  const store = new Map;
@@ -11879,7 +11924,10 @@ function assertCredentials(url, key) {
11879
11924
  }
11880
11925
  var createClient2 = (url, key, options) => {
11881
11926
  assertCredentials(url, key);
11882
- return createClient(url, key, options);
11927
+ const client = createClient(url, key, options);
11928
+ sendNativeBlobsAsBytes(client);
11929
+ blockRealtime(client);
11930
+ return client;
11883
11931
  };
11884
11932
  var export_FunctionsRelayError = import_functions_js.FunctionsRelayError;
11885
11933
  var export_FunctionsHttpError = import_functions_js.FunctionsHttpError;
@@ -11892,6 +11940,7 @@ export {
11892
11940
  createClient2 as createClient,
11893
11941
  asyncStorage,
11894
11942
  StorageApiError,
11943
+ REALTIME_NOT_SUPPORTED,
11895
11944
  export_FunctionsRelayError as FunctionsRelayError,
11896
11945
  export_FunctionsHttpError as FunctionsHttpError,
11897
11946
  export_FunctionsFetchError as FunctionsFetchError,
@@ -0,0 +1,11 @@
1
+ import type { SupabaseClient } from '@supabase/supabase-js';
2
+ export declare const REALTIME_NOT_SUPPORTED = "Realtime is not supported by Bilt Cloud yet. Refetch with bilt.from(...) on an interval or when the screen regains focus instead.";
3
+ /**
4
+ * Makes every way of opening a realtime socket throw {@link REALTIME_NOT_SUPPORTED}.
5
+ *
6
+ * bilt-cloud has no realtime endpoint, so a channel would retry its socket against
7
+ * a 404 for as long as the app runs. `setAuth`, `getChannels`, `removeChannel` and
8
+ * `removeAllChannels` keep working: supabase-js calls `setAuth` on every auth
9
+ * change, and cleanup code must not throw.
10
+ */
11
+ export declare function blockRealtime(client: SupabaseClient<any, any, any>): void;
@@ -0,0 +1,3 @@
1
+ import type { SupabaseClient } from '@supabase/supabase-js';
2
+ /** Makes `upload`, `update` and `uploadToSignedUrl` send React Native Blobs as bytes typed by `contentType`. */
3
+ export declare function sendNativeBlobsAsBytes(client: SupabaseClient<any, any, any>): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biltme/backend",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Bilt backend SDK — thin shim over @supabase/supabase-js for bilt-cloud projects",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",