@rebasepro/client 0.26.0 → 0.28.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.
@@ -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.28.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/common": "0.28.0",
45
+ "@rebasepro/utils": "0.28.0",
46
+ "@rebasepro/types": "0.28.0"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@jest/globals": "^30.4.1",