@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.
@@ -0,0 +1 @@
1
+ export declare function isReactNative(): boolean;
@@ -0,0 +1,38 @@
1
+ import type { SupabaseClient } from '@supabase/supabase-js';
2
+ type Auth = SupabaseClient<any, any, any>['auth'];
3
+ /** Auth options Bilt adds to supabase-js's. */
4
+ export type BiltAuthOptions = {
5
+ /**
6
+ * How long after the first attempt a session refresh that failed on the
7
+ * network keeps being retried, in milliseconds. `0` tries once. Defaults to
8
+ * 10 000; supabase-js's own is 30 000.
9
+ */
10
+ refreshRetryWindowMs?: number;
11
+ };
12
+ export declare const DEFAULT_REFRESH_RETRY_WINDOW_MS = 10000;
13
+ export declare function refreshRetryWindow(options: BiltAuthOptions | undefined): number;
14
+ /** Read by auth-js's refresh retry check, through patches/@supabase%2Fauth-js@*.patch. */
15
+ export declare function setRefreshRetryWindow(auth: Auth, windowMs: number): void;
16
+ type NetworkState = {
17
+ isConnected?: boolean;
18
+ isInternetReachable?: boolean;
19
+ };
20
+ /** The part of `expo-network` used here. */
21
+ export type Network = {
22
+ getNetworkStateAsync(): Promise<NetworkState>;
23
+ addNetworkStateListener(listener: (state: NetworkState) => void): {
24
+ remove(): void;
25
+ };
26
+ };
27
+ export declare function loadNetwork(): Promise<Network | undefined>;
28
+ type PauseOptions = {
29
+ autoRefreshToken?: boolean;
30
+ skipAutoInitialize?: boolean;
31
+ };
32
+ /**
33
+ * On React Native with `expo-network` installed, stops the auto-refresh ticker
34
+ * while the device is offline and starts it again when it comes back,
35
+ * refreshing at once if due, even within auth-js's cooldown after a failed refresh.
36
+ */
37
+ export declare function pauseRefreshWhileOffline(auth: Auth, options: PauseOptions | undefined, load?: () => Promise<Network | undefined>): Promise<void>;
38
+ export {};
@@ -0,0 +1,24 @@
1
+ import type { SupabaseClient } from '@supabase/supabase-js';
2
+ type Auth = SupabaseClient<any, any, any>['auth'];
3
+ /**
4
+ * Thrown in place of a request that would have gone out with the anon key
5
+ * while a signed-in session is stored but could not be refreshed, usually
6
+ * because the network is down. Callers see it as a failed fetch: postgrest-js
7
+ * reports `status: 0` and the message `SessionUnavailableError: …`.
8
+ */
9
+ export declare class SessionUnavailableError extends TypeError {
10
+ constructor();
11
+ }
12
+ /**
13
+ * Wraps the client's fetch so a data, storage or function request that carries
14
+ * the anon key while a session is stored fails like a network error instead.
15
+ *
16
+ * supabase-js sends the anon key whenever `getSession()` returns no session,
17
+ * and it returns none while a due refresh is failing or cooling down after a
18
+ * failure. auth-js removes the stored session when a refresh fails for good,
19
+ * so a stored one means the user is still signed in. Sent anyway, the request
20
+ * runs as `anon`: reads come back empty and writes fail RLS with `42501`,
21
+ * which an offline queue takes as permanent and drops.
22
+ */
23
+ export declare function holdRequestsWithoutSession(url: string, key: string, auth: () => Auth, base?: typeof fetch): typeof fetch;
24
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biltme/backend",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
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",
@@ -28,7 +28,7 @@
28
28
  "lint:fix": "oxlint --type-aware --type-check --fix src/",
29
29
  "format": "oxfmt --write src/",
30
30
  "format:check": "oxfmt --check src/",
31
- "build": "bun build src/index.ts --outdir dist --target node && tsc -p tsconfig.build.json"
31
+ "build": "bun build src/index.ts --outdir dist --target node --external expo-network && tsc -p tsconfig.build.json"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/bun": "latest",
@@ -39,12 +39,17 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@opentelemetry/api": "^1.9.0",
42
- "@supabase/supabase-js": "^2.0.0"
42
+ "@supabase/supabase-js": "2.110.7"
43
43
  },
44
44
  "peerDependencies": {
45
- "@react-native-async-storage/async-storage": "^2.0.0"
45
+ "@react-native-async-storage/async-storage": "^2.0.0",
46
+ "expo-network": "*"
46
47
  },
47
48
  "peerDependenciesMeta": {
48
- "@react-native-async-storage/async-storage": { "optional": true }
49
+ "@react-native-async-storage/async-storage": { "optional": true },
50
+ "expo-network": { "optional": true }
51
+ },
52
+ "patchedDependencies": {
53
+ "@supabase/auth-js@2.110.7": "patches/@supabase%2Fauth-js@2.110.7.patch"
49
54
  }
50
55
  }