@drakkar.software/starfish-client 3.0.0-alpha.23 → 3.0.0-alpha.26

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.
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { CapCert } from "@drakkar.software/starfish-protocol";
1
+ import type { CapCert, PullResult } from "@drakkar.software/starfish-protocol";
2
2
  /** Push conflict error (HTTP 409). */
3
3
  export declare class ConflictError extends Error {
4
4
  constructor();
@@ -109,6 +109,38 @@ export interface StarfishClientOptions {
109
109
  * for an offline-first app where any last-synced data beats none.
110
110
  */
111
111
  cacheMaxAgeMs?: number;
112
+ /**
113
+ * HTTP status codes for which a structured `pull()` falls back to the
114
+ * last-synced cached snapshot rather than throwing `StarfishHttpError` —
115
+ * a **stale-while-revalidate** strategy for transient server failures.
116
+ *
117
+ * When a pull returns one of these statuses AND a {@link cache} is configured
118
+ * AND a cached snapshot exists for the document, `pull()` returns the cached
119
+ * result immediately (tagged stale via `pullWasFromCache`) and spawns a
120
+ * background revalidation loop that retries until it gets a live response.
121
+ * On success the fresh snapshot is written through and {@link onRevalidated}
122
+ * fires. When no cached snapshot exists the error propagates as usual.
123
+ *
124
+ * Applies only to structured (non-append) pulls. Do NOT include `403` or `404`
125
+ * — they are genuine server answers (access denied / no document yet).
126
+ *
127
+ * Default `undefined` — every non-2xx status throws as before.
128
+ *
129
+ * Recommended set for offline-first apps: `[429, 500, 502, 503, 504]`.
130
+ */
131
+ cacheFallbackStatuses?: number[];
132
+ /**
133
+ * Called after a background revalidation succeeds following a
134
+ * {@link cacheFallbackStatuses} hit: the server returned a live response and
135
+ * the fresh snapshot has been written through to the cache.
136
+ *
137
+ * Use this to signal to the host app that the server is reachable again (e.g.
138
+ * call `reportReachability(true)`) so any stale views can re-pull and recover.
139
+ *
140
+ * `path` is the namespaced document path sent to the server (namespace prefix
141
+ * + path + query string, matching the key under which the snapshot was cached).
142
+ */
143
+ onRevalidated?: (path: string, result: PullResult) => void;
112
144
  /**
113
145
  * Optional list of client-side plugins. The list is stored on the client
114
146
  * instance but does not fire any hooks yet — the contract is plumbed so
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drakkar.software/starfish-client",
3
- "version": "3.0.0-alpha.23",
3
+ "version": "3.0.0-alpha.26",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/Drakkar-Software/starfish.git",
@@ -60,7 +60,7 @@
60
60
  }
61
61
  },
62
62
  "dependencies": {
63
- "@drakkar.software/starfish-protocol": "3.0.0-alpha.23"
63
+ "@drakkar.software/starfish-protocol": "3.0.0-alpha.26"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@legendapp/state": "^2.0.0",