@camera.ui/transport 0.0.23 → 0.0.24

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.
@@ -5,11 +5,13 @@ export type RefreshReason = 'proactive' | 'auth-error';
5
5
  export interface TokenLifecycleOptions {
6
6
  readonly kernel: Kernel;
7
7
  readonly transports: readonly Transport[];
8
- readonly refresh: (target: ConnectionTarget, reason: RefreshReason) => Promise<Tokens>;
9
8
  readonly graceMs?: number;
10
- readonly isTransientError?: (err: unknown) => boolean;
11
9
  readonly maxTransientRetries?: number;
12
10
  readonly transientRetryDelayMs?: number;
11
+ readonly maxServerErrorRetries?: number;
12
+ readonly refresh: (target: ConnectionTarget, reason: RefreshReason) => Promise<Tokens>;
13
+ readonly isTransientError?: (err: unknown) => boolean;
14
+ readonly isServerError?: (err: unknown) => boolean;
13
15
  readonly now?: () => number;
14
16
  readonly setTimer?: (cb: () => void, ms: number) => unknown;
15
17
  readonly clearTimer?: (handle: unknown) => void;
@@ -20,6 +22,7 @@ export interface TokenLifecycleOptions {
20
22
  readonly onRefreshSkipped?: (reason: RefreshReason, tokens: Tokens) => void;
21
23
  readonly onRefreshError?: (reason: RefreshReason, error: unknown, info: {
22
24
  transient: boolean;
25
+ serverError: boolean;
23
26
  retriesLeft: number;
24
27
  willRetry: boolean;
25
28
  }) => void;
package/dist/index.js CHANGED
@@ -836,9 +836,11 @@ var DEFAULT_TRANSIENT_RETRY_DELAY_MS = 2e3;
836
836
  var MAX_TIMER_DELAY_MS = 2 ** 31 - 1;
837
837
  function attachTokenLifecycle(options) {
838
838
  const graceMs = options.graceMs ?? DEFAULT_GRACE_MS;
839
- const isTransient = options.isTransientError ?? (() => false);
840
839
  const maxTransientRetries = options.maxTransientRetries ?? DEFAULT_MAX_TRANSIENT_RETRIES;
840
+ const maxServerErrorRetries = options.maxServerErrorRetries ?? maxTransientRetries;
841
841
  const transientRetryDelayMs = options.transientRetryDelayMs ?? DEFAULT_TRANSIENT_RETRY_DELAY_MS;
842
+ const isTransient = options.isTransientError ?? (() => false);
843
+ const isServerError = options.isServerError ?? (() => false);
842
844
  const now = options.now ?? (() => Date.now());
843
845
  const setTimer = options.setTimer ?? ((cb, ms) => setTimeout(cb, ms));
844
846
  const clearTimer = options.clearTimer ?? ((h) => clearTimeout(h));
@@ -926,11 +928,14 @@ function attachTokenLifecycle(options) {
926
928
  } catch (err) {
927
929
  if (detached) return;
928
930
  const transient = isTransient(err);
929
- if (transient && transientRetries < maxTransientRetries) {
931
+ const serverError = transient && isServerError(err);
932
+ const budget = serverError ? maxServerErrorRetries : maxTransientRetries;
933
+ if (transient && transientRetries < budget) {
930
934
  transientRetries++;
931
- const retriesLeft = maxTransientRetries - transientRetries;
935
+ const retriesLeft = budget - transientRetries;
932
936
  options.onRefreshError?.(reason, err, {
933
937
  transient: true,
938
+ serverError,
934
939
  retriesLeft,
935
940
  willRetry: true
936
941
  });
@@ -943,6 +948,7 @@ function attachTokenLifecycle(options) {
943
948
  transientRetries = 0;
944
949
  options.onRefreshError?.(reason, err, {
945
950
  transient,
951
+ serverError,
946
952
  retriesLeft: 0,
947
953
  willRetry: false
948
954
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camera.ui/transport",
3
- "version": "0.0.23",
3
+ "version": "0.0.24",
4
4
  "description": "camera.ui transport layer — framework-agnostic connection kernel, reducer state, pluggable transports (HTTP/WS/Socket.IO/NATS), lifecycle effects and worker bridge",
5
5
  "author": "seydx (https://github.com/cameraui/clients)",
6
6
  "type": "module",