@biltme/backend 0.10.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,6 +11,8 @@ re-exports the functions error classes for clean `catch` blocks.
11
11
  bun add @biltme/backend
12
12
  # Expo only — also install AsyncStorage as the session store
13
13
  bun add @react-native-async-storage/async-storage
14
+ # Expo only, optional — pauses session auto-refresh while the device is offline
15
+ npx expo install expo-network
14
16
  ```
15
17
 
16
18
  ## Quick start (Expo)
@@ -32,6 +34,23 @@ export const bilt = createClient(url, key, {
32
34
  })
33
35
  ```
34
36
 
37
+ A session refresh that fails on the network is retried for 10 seconds after
38
+ the first attempt, then gives up and keeps the session. Requests waiting on the
39
+ refresh wait that long. Set `auth.refreshRetryWindowMs` to change it; `0` tries
40
+ once. supabase-js on its own retries for 30 seconds.
41
+
42
+ While a signed-in user's expired session can't be refreshed, data, storage and
43
+ function requests fail as if the network were down, with `status: 0` and the
44
+ message `SessionUnavailableError: …`. supabase-js on its own sends them with
45
+ the anon key instead, so reads come back empty and writes fail row-level
46
+ security with `42501`. An app that queues writes offline should retry these,
47
+ like any network error.
48
+
49
+ On iOS and Android with `expo-network` installed, auto-refresh stops while the
50
+ device is offline and starts again when it comes back, refreshing at once if
51
+ the token is due, even if a refresh failed in the last minute. Without
52
+ `expo-network`, or with `autoRefreshToken: false`, nothing changes.
53
+
35
54
  Every supabase-js method works:
36
55
 
37
56
  ```ts
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { createClient as createSupabaseClient } from '@supabase/supabase-js';
2
2
  import { type Notifications } from './notifications';
3
+ import { type BiltAuthOptions } from './refresh';
3
4
  /**
4
5
  * Schema of the project's database, in postgrest-js's `Database` shape.
5
6
  *
@@ -83,20 +84,27 @@ export type TablesUpdate<Name extends keyof PublicTables> = PublicTables[Name] e
83
84
  Update: infer U;
84
85
  } ? U : never;
85
86
  /**
86
- * Creates a Bilt client. supabase-js's `createClient` with five changes: called
87
+ * Creates a Bilt client. supabase-js's `createClient` with these changes: called
87
88
  * with no type arguments, the schema is {@link BiltDatabase} instead of `any`,
88
89
  * a missing or malformed URL or key names Bilt Cloud rather than Supabase, on
89
90
  * React Native a Blob upload is sent as bytes so `contentType` reaches the
90
91
  * bucket's MIME allowlist (see {@link sendNativeBlobsAsBytes}), opening a
91
92
  * realtime channel throws because Bilt Cloud has no realtime (see {@link blockRealtime}),
92
- * and the client has `notifications` (see {@link Notifications}).
93
+ * the client has `notifications` (see {@link Notifications}), a session refresh
94
+ * that fails on the network stops retrying after `auth.refreshRetryWindowMs`
95
+ * (see {@link BiltAuthOptions}), a request that would fall back to the anon key
96
+ * while the user's session cannot be refreshed fails like a network error
97
+ * instead (see {@link holdRequestsWithoutSession}), and on React Native with
98
+ * `expo-network` installed, auto-refresh pauses while the device is offline and
99
+ * retries at once when it comes back (see {@link pauseRefreshWhileOffline}).
93
100
  *
94
101
  * The second member of the intersection is supabase-js's own signature. An
95
102
  * intersection of function types is an overload set, so a bare call takes the
96
103
  * first member and any call with explicit type arguments falls through to the
97
104
  * second. Restating the parameter list here instead would have to track
98
- * supabase-js's defaults by hand across a caret range. For the same reason only
99
- * the bare call's type carries `notifications`; it is there at runtime either way.
105
+ * supabase-js's defaults by hand across versions. For the same reason only
106
+ * the bare call's types carry `notifications` and {@link BiltAuthOptions};
107
+ * both work at runtime either way.
100
108
  */
101
109
  export declare const createClient: BareCreateClient & typeof createSupabaseClient;
102
110
  type BareCall = typeof createSupabaseClient<BiltDatabase>;
@@ -104,8 +112,14 @@ type BareCall = typeof createSupabaseClient<BiltDatabase>;
104
112
  export type BiltClient = ReturnType<BareCall> & {
105
113
  notifications: Notifications;
106
114
  };
107
- type BareCreateClient = (...args: Parameters<BareCall>) => BiltClient;
115
+ /** supabase-js's client options, plus {@link BiltAuthOptions} under `auth`. */
116
+ export type BiltClientOptions = NonNullable<Parameters<BareCall>[2]> & {
117
+ auth?: BiltAuthOptions;
118
+ };
119
+ type BareCreateClient = (url: Parameters<BareCall>[0], key: Parameters<BareCall>[1], options?: BiltClientOptions) => BiltClient;
108
120
  export { REALTIME_NOT_SUPPORTED } from './realtime';
121
+ export { SessionUnavailableError } from './session';
122
+ export type { BiltAuthOptions } from './refresh';
109
123
  export { NotificationsError } from './notifications';
110
124
  export type { Notifications, NotificationMessage, NotificationOutcome, NotificationSendResult, NotificationCounts, NotificationSendAllResult, } from './notifications';
111
125
  export { webStorage, memoryStorage, asyncStorage } from './storage';