@rebasepro/client 0.26.0 → 0.27.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.
@@ -217,6 +217,19 @@ export declare class RebaseRealtimeChannel {
217
217
  */
218
218
  private send;
219
219
  join(): Promise<void>;
220
+ /** Consecutive re-joins asked for by refusals, for the backoff; reset after a quiet minute. */
221
+ private rejoinAttempts;
222
+ private rejoinTimer?;
223
+ private lastRejoinAt;
224
+ /**
225
+ * Re-join after the server refused this channel for a reason a retry can
226
+ * change: it could not check permissions at that moment, or it has no record
227
+ * of the join (a join that was itself refused, so every broadcast after it
228
+ * came back "not a member"). The join was fire-and-forget and `joined` was
229
+ * already set, so nothing else would ever send it again. Backs off 1, 2, 4…
230
+ * up to 30 seconds, one re-join at a time.
231
+ */
232
+ private scheduleRejoin;
220
233
  private rejoin;
221
234
  /**
222
235
  * Ask the server for everything after {@link lastSeq}.
@@ -344,3 +357,10 @@ export declare class RebaseRealtimeChannel {
344
357
  private deliver;
345
358
  private emitPresence;
346
359
  }
360
+ /**
361
+ * Whether a channel refusal is one a re-join can recover from: the server's
362
+ * auth store could not answer (`ROLE_LOOKUP_FAILED`, `DATABASE_UNAVAILABLE`), or
363
+ * it no longer counts this client a member. A channel the client may not use
364
+ * (any other `CHANNEL_FORBIDDEN`) is not retried.
365
+ */
366
+ export declare function rejoinsAfter(code: string | undefined, message: string): boolean;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Compile-time assertions about `client.storage.putObject`.
3
+ *
4
+ * A plain module under `src`, imported by nothing, for the reason
5
+ * `query-contract.types.ts` gives: `pnpm typecheck` reads `src`, and a type
6
+ * assertion in a jest test is checked by nothing.
7
+ *
8
+ * The SDK's upload takes any `Blob` and an optional key — with none, the server
9
+ * names the object after the file — and the SDK docs say so. Its parameter was
10
+ * the server controllers' `UploadFileProps`, whose `key` is required and whose
11
+ * `file` is a `File`, so both documented calls were compile errors.
12
+ */
13
+ import type { StorageSource } from "./index.js";
14
+ export declare const keyless: () => unknown;
15
+ export declare const named: () => unknown;
16
+ export declare const asSource: StorageSource;
package/dist/storage.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { StorageSource } from "@rebasepro/types";
1
+ import { ClientStorageSource } from "@rebasepro/types";
2
2
  import { Transport } from "./transport.js";
3
3
  /**
4
4
  * Create a StorageSource that talks to the Rebase backend REST API.
@@ -27,4 +27,4 @@ import { Transport } from "./transport.js";
27
27
  * characters and a trailing `%`.
28
28
  */
29
29
  export declare function encodeStorageKey(key: string): string;
30
- export declare function createStorage(transport: Transport, storageId?: string): StorageSource;
30
+ export declare function createStorage(transport: Transport, storageId?: string): ClientStorageSource;
@@ -1,6 +1,21 @@
1
1
  import { AggregateParams, FindParams as TypesFindParams, FindResponse as TypesFindResponse, type IncludeSpec } from "@rebasepro/types";
2
2
  export { RebaseApiError } from "@rebasepro/types";
3
3
  export type { RebaseErrorInit } from "@rebasepro/types";
4
+ /** Options for the realtime socket: `createRebaseClient({ realtime: { ... } })`. */
5
+ export interface RealtimeClientOptions {
6
+ /**
7
+ * The group this client's socket belongs to, such as a room code.
8
+ *
9
+ * Named on the socket's address as `?affinity=`, so a platform that routes
10
+ * on it can send a group's sockets to the same instance and keep their
11
+ * messages off the channel bus. Elsewhere it does nothing. It decides where
12
+ * a socket lands, not what it may join, and an address ends up in access
13
+ * logs: use a code, not a secret or anything personal.
14
+ *
15
+ * When it is only known later, use `client.realtime.setAffinity()`.
16
+ */
17
+ affinity?: string;
18
+ }
4
19
  export interface RebaseClientConfig {
5
20
  /**
6
21
  * Origin of the Rebase server — scheme, host and port **only**.
@@ -59,8 +74,10 @@ export interface RebaseClientConfig {
59
74
  *
60
75
  * Long-lived processes that do want realtime can instead call
61
76
  * `client.close()` when shutting down.
77
+ *
78
+ * An object leaves realtime on and configures it.
62
79
  */
63
- realtime?: boolean;
80
+ realtime?: boolean | RealtimeClientOptions;
64
81
  /**
65
82
  * "Yes, I meant to be anonymous."
66
83
  *
@@ -2,6 +2,8 @@ import { DeleteProps, CollectionConfig, FetchCollectionProps, ListenCollectionPr
2
2
  import type { SqlScriptResult } from "@rebasepro/types";
3
3
  export interface RebaseWebSocketConfig {
4
4
  websocketUrl: string;
5
+ /** The group this socket belongs to — see `RealtimeClientOptions.affinity`. */
6
+ affinity?: string;
5
7
  /**
6
8
  * Where the token the socket authenticates with comes from, asked each
7
9
  * time it authenticates. A falsy answer leaves it anonymous.
@@ -22,8 +24,11 @@ export interface RebaseWebSocketConfig {
22
24
  */
23
25
  debug?: boolean;
24
26
  }
27
+ /** The code of a channel `ERROR` frame, if it is one and carries a code. */
28
+ export declare function channelErrorCode(message: ChannelMessage): string | undefined;
25
29
  export declare class RebaseWebSocketClient {
26
30
  private websocketUrl;
31
+ private affinity?;
27
32
  private ws;
28
33
  /**
29
34
  * Where the socket's token comes from. A client built by
@@ -168,6 +173,11 @@ export declare class RebaseWebSocketClient {
168
173
  */
169
174
  private connectionDebug;
170
175
  constructor(config: RebaseWebSocketConfig);
176
+ /**
177
+ * Name the group this socket belongs to, or clear it with `null`. Read at
178
+ * each dial, so a socket already open stays where it is until it redials.
179
+ */
180
+ setAffinity(key: string | null): void;
171
181
  /**
172
182
  * Open the socket if it is not open (or opening) already.
173
183
  *
@@ -210,6 +220,24 @@ export declare class RebaseWebSocketClient {
210
220
  /**
211
221
  * Authenticate the WebSocket connection
212
222
  */
223
+ /**
224
+ * {@link authenticate}, asked again a few times when the server could not
225
+ * answer (its auth store busy, `ROLE_LOOKUP_FAILED`, a timeout) — not when
226
+ * it refused the session or the socket ceiling, which a retry cannot
227
+ * change. Stops as soon as `socket` is no longer this client's.
228
+ */
229
+ private authenticateRetrying;
230
+ /** A sign-in again after a channel was refused for not being signed in, in flight. */
231
+ private channelAuthRecovery;
232
+ /**
233
+ * A channel frame refused `UNAUTHORIZED` while this client holds a way to
234
+ * get a token: the socket is open but not signed in (an authentication that
235
+ * failed on a reconnect, a token that expired). Nothing else signs it in —
236
+ * channel frames expect no answer, so the refusal reaches only the channel —
237
+ * and every later frame is refused the same way. Sign in again, once for
238
+ * all the channels that noticed, and have them re-join.
239
+ */
240
+ private recoverChannelAuth;
213
241
  authenticate(token: string): Promise<void>;
214
242
  /**
215
243
  * Replace where this socket's token comes from, and authenticate an open,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rebasepro/client",
3
- "version": "0.26.0",
3
+ "version": "0.27.0",
4
4
  "description": "HTTP SDK client for the Rebase custom backend",
5
5
  "keywords": [
6
6
  "rebase",
@@ -41,9 +41,9 @@
41
41
  "./package.json": "./package.json"
42
42
  },
43
43
  "dependencies": {
44
- "@rebasepro/common": "0.26.0",
45
- "@rebasepro/utils": "0.26.0",
46
- "@rebasepro/types": "0.26.0"
44
+ "@rebasepro/types": "0.27.0",
45
+ "@rebasepro/utils": "0.27.0",
46
+ "@rebasepro/common": "0.27.0"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@jest/globals": "^30.4.1",