@rebasepro/client 0.31.0 → 0.32.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.
- package/dist/index.d.ts +4 -0
- package/dist/index.es.js +74 -1
- package/dist/index.es.js.map +1 -1
- package/dist/{offline-D_wKJcO3.js → offline-ET6xI1ZO.js} +122 -3
- package/dist/offline-ET6xI1ZO.js.map +1 -0
- package/dist/offline-lease.d.ts +54 -0
- package/dist/offline.d.ts +6 -0
- package/dist/push.d.ts +50 -0
- package/package.json +4 -4
- package/dist/offline-D_wKJcO3.js.map +0 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A cross-tab mutex over `localStorage`, for the browsers that have no Web
|
|
3
|
+
* Locks: Safari before 15.4, pages served over plain http from anything but
|
|
4
|
+
* localhost (Web Locks is secure-context only), and embedded webviews.
|
|
5
|
+
*
|
|
6
|
+
* Without it two tabs on such a browser each replayed the whole offline queue,
|
|
7
|
+
* so every queued write reached the server twice. Creates survived that (the
|
|
8
|
+
* idempotency key dedups them) and deletes did too (a second delete's 404 is
|
|
9
|
+
* taken as done), but an update with `If-Match` came back `412` from its own
|
|
10
|
+
* twin and was reported as a conflict nobody caused.
|
|
11
|
+
*
|
|
12
|
+
* The lease is a `{ holder, until }` record under one key. A tab takes it by
|
|
13
|
+
* writing its own record when the key is empty, expired or already its own,
|
|
14
|
+
* then reading it back after `settleMs`: `localStorage` has no compare-and-set,
|
|
15
|
+
* but every tab reads and writes in one synchronous step, so two tabs can only
|
|
16
|
+
* both write within the time a write takes to reach the other process — far
|
|
17
|
+
* under `settleMs` — and the read-back sees whichever write landed last. Only
|
|
18
|
+
* that tab proceeds. The holder renews the record while it works and removes it
|
|
19
|
+
* when done; a tab that died holding it is outlived by `ttlMs`.
|
|
20
|
+
*
|
|
21
|
+
* It is a weaker guarantee than Web Locks, on purpose kept to what it can
|
|
22
|
+
* promise: a holder whose timers the browser throttles hard enough (a hidden
|
|
23
|
+
* tab can be held to one timer a minute) may see its lease expire mid-replay,
|
|
24
|
+
* and the next tab then replays what is still queued. That costs at most the
|
|
25
|
+
* one write in flight, not the whole queue.
|
|
26
|
+
*/
|
|
27
|
+
/** The part of `Storage` the lease uses — `localStorage`, or a test double. */
|
|
28
|
+
export interface LeaseStorage {
|
|
29
|
+
getItem(key: string): string | null;
|
|
30
|
+
setItem(key: string, value: string): void;
|
|
31
|
+
removeItem(key: string): void;
|
|
32
|
+
}
|
|
33
|
+
export interface StorageLeaseOptions {
|
|
34
|
+
/** How long a record stays valid without renewal. */
|
|
35
|
+
ttlMs?: number;
|
|
36
|
+
/** How long to wait before reading a fresh claim back. */
|
|
37
|
+
settleMs?: number;
|
|
38
|
+
/** How often a waiting tab looks again. */
|
|
39
|
+
pollMs?: number;
|
|
40
|
+
now?: () => number;
|
|
41
|
+
sleep?: (ms: number) => Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* `localStorage` when this page can use it, or `undefined` — a worker has none,
|
|
45
|
+
* and a browser with storage blocked throws on the mere access.
|
|
46
|
+
*/
|
|
47
|
+
export declare function browserLeaseStorage(): LeaseStorage | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Run `fn` while holding the lease named `key`, waiting for another holder to
|
|
50
|
+
* finish first. Storage that fails mid-protocol makes the lease unenforceable,
|
|
51
|
+
* and then `fn` runs anyway: a queue that never drains is worse than one that
|
|
52
|
+
* might drain twice.
|
|
53
|
+
*/
|
|
54
|
+
export declare function withStorageLease<T>(storage: LeaseStorage, key: string, holder: string, fn: () => Promise<T>, options?: StorageLeaseOptions): Promise<T>;
|
package/dist/offline.d.ts
CHANGED
|
@@ -696,6 +696,12 @@ export declare class OfflineManager {
|
|
|
696
696
|
/** Replay uses unwrapped clients: a failure must never re-enqueue itself. */
|
|
697
697
|
private innerFor;
|
|
698
698
|
private withLock;
|
|
699
|
+
/**
|
|
700
|
+
* Serialise replay across tabs without Web Locks — see `offline-lease.ts`.
|
|
701
|
+
* Where there is no `localStorage` either (a worker), there is no other
|
|
702
|
+
* tab sharing this queue through it to guard against.
|
|
703
|
+
*/
|
|
704
|
+
private withLeaseFallback;
|
|
699
705
|
private broadcast;
|
|
700
706
|
private onBroadcast;
|
|
701
707
|
/** Re-read one table from the store, replacing what is in memory. */
|
package/dist/push.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Transport } from "./transport.js";
|
|
2
|
+
/** Where the subscription is made: a service worker registration. */
|
|
3
|
+
export interface PushRegistrationOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The service worker registration to subscribe through. Default: the one
|
|
6
|
+
* controlling this page (`navigator.serviceWorker.getRegistration()`).
|
|
7
|
+
*/
|
|
8
|
+
registration?: ServiceWorkerRegistration;
|
|
9
|
+
}
|
|
10
|
+
export interface PushSubscribeOptions extends PushRegistrationOptions {
|
|
11
|
+
/**
|
|
12
|
+
* The language notifications to this browser should be written in, handed
|
|
13
|
+
* to the server's payload function as `subscription.lang`. Default
|
|
14
|
+
* `navigator.language`.
|
|
15
|
+
*/
|
|
16
|
+
lang?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Web Push from the browser, as `client.push`. Needs `push: true` on the
|
|
20
|
+
* backend, a service worker that shows the notifications, and a signed-in user.
|
|
21
|
+
*/
|
|
22
|
+
export interface PushClient {
|
|
23
|
+
/** Whether this browser can take push notifications at all (service workers, PushManager, Notification). */
|
|
24
|
+
isSupported(): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Ask permission when it has not been given, subscribe this browser with the
|
|
27
|
+
* server's VAPID key, and register the subscription for the signed-in user.
|
|
28
|
+
* Call it from a click: Safari only asks for permission inside a user gesture.
|
|
29
|
+
*
|
|
30
|
+
* Resolves with the subscription's id (the server's key for this browser)
|
|
31
|
+
* and the browser's `PushSubscription`. Calling it again is safe; it
|
|
32
|
+
* refreshes the same subscription.
|
|
33
|
+
*
|
|
34
|
+
* Throws `PUSH_UNSUPPORTED`, `PUSH_PERMISSION_DENIED` or `PUSH_NO_SERVICE_WORKER`
|
|
35
|
+
* from the browser side, and the server's `PUSH_NOT_CONFIGURED` when push is
|
|
36
|
+
* off there.
|
|
37
|
+
*/
|
|
38
|
+
subscribe(options?: PushSubscribeOptions): Promise<{
|
|
39
|
+
id: string;
|
|
40
|
+
subscription: PushSubscription;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* Stop notifications to this browser: removed on the server, then
|
|
44
|
+
* unsubscribed in the browser. `false` when it was not subscribed.
|
|
45
|
+
*/
|
|
46
|
+
unsubscribe(options?: PushRegistrationOptions): Promise<boolean>;
|
|
47
|
+
/** This browser's current subscription, or `null`. */
|
|
48
|
+
getSubscription(options?: PushRegistrationOptions): Promise<PushSubscription | null>;
|
|
49
|
+
}
|
|
50
|
+
export declare function createPushClient(transport: Transport, pushPath?: string): PushClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rebasepro/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.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.
|
|
45
|
-
"@rebasepro/utils": "0.
|
|
46
|
-
"@rebasepro/types": "0.
|
|
44
|
+
"@rebasepro/common": "0.32.0",
|
|
45
|
+
"@rebasepro/utils": "0.32.0",
|
|
46
|
+
"@rebasepro/types": "0.32.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@jest/globals": "^30.4.1",
|