@aouda/client 0.1.10 → 0.1.11

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.
@@ -421,7 +421,7 @@ var import_node_url = require("url");
421
421
  // package.json
422
422
  var package_default = {
423
423
  name: "@aouda/client",
424
- version: "0.1.10",
424
+ version: "0.1.11",
425
425
  description: "Official TypeScript/JavaScript client library for Aouda",
426
426
  type: "module",
427
427
  main: "./dist/index.cjs",
@@ -659,6 +659,7 @@ var AuthHandler = class {
659
659
  this._tokenExpiry = null;
660
660
  this._authenticated = false;
661
661
  this._refreshPromise = null;
662
+ this._onAccessTokenRefreshed = null;
662
663
  this._serverUrl = serverUrl.replace(/\/+$/, "");
663
664
  this._timeout = timeout;
664
665
  this._authBasePath = config.basePath;
@@ -908,10 +909,16 @@ var AuthHandler = class {
908
909
  const thresholdSeconds = this._refreshThresholdMs / 1e3;
909
910
  return this._tokenExpiry <= nowSeconds + thresholdSeconds;
910
911
  }
912
+ setOnAccessTokenRefreshed(handler) {
913
+ this._onAccessTokenRefreshed = handler;
914
+ }
911
915
  async _doRefresh() {
912
916
  try {
913
917
  const result = await this.callRefreshEndpoint();
914
918
  this.handleSignInResult(result);
919
+ if (result.accessToken) {
920
+ this._onAccessTokenRefreshed?.(result.accessToken);
921
+ }
915
922
  return true;
916
923
  } catch {
917
924
  return false;
@@ -2414,6 +2421,7 @@ var TableSubscription = class {
2414
2421
  this._startPromise = null;
2415
2422
  this._lastVersion = 0;
2416
2423
  this._pendingSnapshotRows = [];
2424
+ this._forceFreshSubscribe = false;
2417
2425
  this.id = createStreamingId("sub");
2418
2426
  this._transport = transport;
2419
2427
  this._tableName = tableName;
@@ -2421,6 +2429,7 @@ var TableSubscription = class {
2421
2429
  this._onSnapshot = options.onSnapshot;
2422
2430
  this._onChange = options.onChange;
2423
2431
  this._onError = options.onError;
2432
+ this._conflate = options.conflate;
2424
2433
  this._reconnectHandlerKey = `${this.id}::reconnect`;
2425
2434
  }
2426
2435
  get lastVersion() {
@@ -2471,7 +2480,8 @@ var TableSubscription = class {
2471
2480
  }
2472
2481
  try {
2473
2482
  this._pendingSnapshotRows = [];
2474
- const resumeFrom = this._lastVersion > 0 ? this._lastVersion : void 0;
2483
+ const resumeFrom = this._forceFreshSubscribe || this._lastVersion <= 0 ? void 0 : this._lastVersion;
2484
+ this._forceFreshSubscribe = false;
2475
2485
  await this._sendSubscribe(resumeFrom);
2476
2486
  } catch (error) {
2477
2487
  const wrapped = error instanceof Error ? error : new AoudaConnectionError("Subscription reconnect failed");
@@ -2491,6 +2501,9 @@ var TableSubscription = class {
2491
2501
  if (resumeFrom !== void 0) {
2492
2502
  message.resume_from = resumeFrom;
2493
2503
  }
2504
+ if (this._conflate !== void 0) {
2505
+ message.conflate = this._conflate;
2506
+ }
2494
2507
  await this._transport.send(message);
2495
2508
  }
2496
2509
  _handleMessage(message) {
@@ -2551,10 +2564,19 @@ var TableSubscription = class {
2551
2564
  key: message.key,
2552
2565
  version: message.version
2553
2566
  };
2567
+ if (message.values_skipped !== void 0) {
2568
+ event.values_skipped = message.values_skipped;
2569
+ }
2554
2570
  this._onChange?.(event);
2555
2571
  this._queue.push(event);
2556
2572
  }
2557
2573
  _handleServerError(message) {
2574
+ if (message.code === "SLOW_CONSUMER") {
2575
+ this._pendingSnapshotRows = [];
2576
+ this._lastVersion = 0;
2577
+ this._forceFreshSubscribe = true;
2578
+ return;
2579
+ }
2558
2580
  this._pendingSnapshotRows = [];
2559
2581
  const error = new AoudaConnectionError(
2560
2582
  `Subscription error (${message.code}): ${message.message}`
@@ -3268,7 +3290,8 @@ var TableQuery = class _TableQuery {
3268
3290
  {
3269
3291
  onSnapshot: options.onSnapshot,
3270
3292
  onChange: options.onChange,
3271
- onError: options.onError
3293
+ onError: options.onError,
3294
+ conflate: options.conflate
3272
3295
  },
3273
3296
  mergedFilter
3274
3297
  );
@@ -5128,6 +5151,7 @@ var WebSocketTransport = class {
5128
5151
  // Resolved/rejected when the auth handshake completes.
5129
5152
  this._authResolve = null;
5130
5153
  this._authReject = null;
5154
+ this._handshakeComplete = false;
5131
5155
  this._serverUrl = serverUrl;
5132
5156
  this._database = database;
5133
5157
  this._authHandler = options.authHandler;
@@ -5137,6 +5161,11 @@ var WebSocketTransport = class {
5137
5161
  this._maxMissedHeartbeats = options.maxMissedHeartbeats ?? DEFAULT_MAX_MISSED_HEARTBEATS;
5138
5162
  this._enableCompression = options.enableCompression ?? true;
5139
5163
  this._wireMode = options.wireMode ?? "json";
5164
+ this._authHandler?.setOnAccessTokenRefreshed((token) => {
5165
+ if (this._handshakeComplete && this._ws?.readyState === WS_READY_STATE_OPEN) {
5166
+ void this.send({ type: "re_auth", token });
5167
+ }
5168
+ });
5140
5169
  }
5141
5170
  // ─── Public API ────────────────────────────────────────────────────────────
5142
5171
  /** Latest version number from the most recent server `heartbeat` message. */
@@ -5309,6 +5338,7 @@ var WebSocketTransport = class {
5309
5338
  const resolve4 = this._authResolve;
5310
5339
  this._authResolve = null;
5311
5340
  this._authReject = null;
5341
+ this._handshakeComplete = true;
5312
5342
  if (resolve4) resolve4();
5313
5343
  break;
5314
5344
  }
@@ -5335,10 +5365,15 @@ var WebSocketTransport = class {
5335
5365
  break;
5336
5366
  }
5337
5367
  const id = "id" in msg ? msg.id : void 0;
5338
- if (id !== void 0 && id !== null) {
5368
+ if (id !== void 0 && id !== null && id !== "") {
5339
5369
  this._handlers.get(id)?.(msg);
5340
5370
  } else {
5341
5371
  this._handlers.get("__global__")?.(msg);
5372
+ for (const [key, handler] of this._handlers) {
5373
+ if (key !== "__global__") {
5374
+ handler(msg);
5375
+ }
5376
+ }
5342
5377
  }
5343
5378
  }
5344
5379
  // ─── Internal: reconnect ──────────────────────────────────────────────────