@synonymdev/pubky 0.13.0 → 0.15.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/README.md +27 -0
- package/index.cjs +446 -145
- package/index.js +447 -146
- package/package.json +4 -2
- package/pubky.d.ts +130 -5
- package/pubky_bg.wasm +0 -0
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@synonymdev/pubky",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "Decentralized identity, auth flows, and user-owned storage",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.15.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"test-browser:ci": "npm run build:test && browserify dist/tests/setup.js dist/tests/*.js -p esmify | tape-run --browser electron --electron-arg=--no-sandbox --electron-arg=--disable-gpu",
|
|
18
18
|
"build": "cargo run --bin bundle_npm",
|
|
19
19
|
"docs": "typedoc",
|
|
20
|
-
"prepublishOnly": "npm run build"
|
|
20
|
+
"prepublishOnly": "npm run build",
|
|
21
|
+
"test-browser:tabs": "npm run build:test && browserify dist/tests/browser/session-tabs.js -p esmify -o dist/session-tabs.bundle.js && electron scripts/session-tabs.cjs"
|
|
21
22
|
},
|
|
22
23
|
"files": [
|
|
23
24
|
"index.cjs",
|
|
@@ -40,6 +41,7 @@
|
|
|
40
41
|
"@types/tape": "^5.6.4",
|
|
41
42
|
"browser-resolve": "^2.0.0",
|
|
42
43
|
"browserify": "^17.0.1",
|
|
44
|
+
"electron": "41.0.2",
|
|
43
45
|
"esmify": "^2.1.1",
|
|
44
46
|
"tape": "^5.8.1",
|
|
45
47
|
"tape-run": "^11.0.0",
|
package/pubky.d.ts
CHANGED
|
@@ -74,8 +74,8 @@ export interface PkarrConfig {
|
|
|
74
74
|
*/
|
|
75
75
|
relays?: string[];
|
|
76
76
|
/**
|
|
77
|
-
* The timeout for
|
|
78
|
-
* Default is
|
|
77
|
+
* The timeout for relay HTTP requests in milliseconds.
|
|
78
|
+
* Default is 5000ms.
|
|
79
79
|
*/
|
|
80
80
|
requestTimeout?: number;
|
|
81
81
|
}
|
|
@@ -459,7 +459,7 @@ export class BrowserSessionStore {
|
|
|
459
459
|
* This removes all stored session records and all browser-held delegated
|
|
460
460
|
* grant keys, including keys for pending delegated grant flows. Saved
|
|
461
461
|
* delegated flow state becomes unrestorable. This does not revoke remote
|
|
462
|
-
* grants
|
|
462
|
+
* grants. Browser-managed handles stop working when their saved record is removed.
|
|
463
463
|
*/
|
|
464
464
|
clearAll(): Promise<void>;
|
|
465
465
|
/**
|
|
@@ -470,7 +470,7 @@ export class BrowserSessionStore {
|
|
|
470
470
|
*/
|
|
471
471
|
clear(): Promise<void>;
|
|
472
472
|
/**
|
|
473
|
-
* Whether IndexedDB
|
|
473
|
+
* Whether IndexedDB and Web Locks are available.
|
|
474
474
|
*/
|
|
475
475
|
isAvailable(): Promise<boolean>;
|
|
476
476
|
/**
|
|
@@ -483,6 +483,9 @@ export class BrowserSessionStore {
|
|
|
483
483
|
remove(id: string): Promise<void>;
|
|
484
484
|
/**
|
|
485
485
|
* Restore a specific stored session by id.
|
|
486
|
+
*
|
|
487
|
+
* Shares one bearer with other tabs on this origin. Requires IndexedDB and
|
|
488
|
+
* Web Locks in a secure browser context.
|
|
486
489
|
*/
|
|
487
490
|
restore(id: string): Promise<Session>;
|
|
488
491
|
/**
|
|
@@ -1778,12 +1781,23 @@ export class SessionInfo {
|
|
|
1778
1781
|
* Only {@link SessionStorage.exists} and {@link SessionStorage.stats} treat
|
|
1779
1782
|
* HTTP 404/410 as missing. Other HTTP failures, including 401/403 and 5xx, reject.
|
|
1780
1783
|
* Writes require write permission and can fail on directory targets (400),
|
|
1781
|
-
* file/directory path conflicts (409),
|
|
1784
|
+
* file/directory path conflicts (409), a path someone holds a
|
|
1785
|
+
* {@link StorageLock} on (423), or exceeded quotas (507).
|
|
1782
1786
|
*/
|
|
1783
1787
|
export class SessionStorage {
|
|
1784
1788
|
private constructor();
|
|
1785
1789
|
free(): void;
|
|
1786
1790
|
[Symbol.dispose](): void;
|
|
1791
|
+
/**
|
|
1792
|
+
* `DELETE` the path of a lock this client holds. The lock stays in place.
|
|
1793
|
+
*
|
|
1794
|
+
* @param {StorageLock} lock A lock this client holds.
|
|
1795
|
+
* @returns {Promise<void>}
|
|
1796
|
+
* @throws {PubkyError} A lock that has expired or was unlocked rejects with
|
|
1797
|
+
* `RequestError` and status `412`; take a new one.
|
|
1798
|
+
* Otherwise as {@link SessionStorage.delete}.
|
|
1799
|
+
*/
|
|
1800
|
+
deleteLocked(lock: StorageLock): Promise<void>;
|
|
1787
1801
|
/**
|
|
1788
1802
|
* Delete a file. Directory targets are unsupported.
|
|
1789
1803
|
*
|
|
@@ -1850,6 +1864,35 @@ export class SessionStorage {
|
|
|
1850
1864
|
* entries, or shared errors (see {@link SessionStorage}).
|
|
1851
1865
|
*/
|
|
1852
1866
|
list(path: Path, cursor?: string | null, reverse?: boolean | null, limit?: number | null, shallow?: boolean | null): Promise<string[]>;
|
|
1867
|
+
/**
|
|
1868
|
+
* Take an exclusive write lock on a file at an **absolute session path**.
|
|
1869
|
+
*
|
|
1870
|
+
* The file need not exist; locking a free path reserves it. `timeoutSeconds` is
|
|
1871
|
+
* the lifetime asked for; the homeserver caps it, and
|
|
1872
|
+
* {@link StorageLock.timeoutSeconds} tells what was granted. A write made under
|
|
1873
|
+
* the lock keeps it alive until the write ends, so it need not cover the upload itself.
|
|
1874
|
+
*
|
|
1875
|
+
* @param {Path} path File path; must not end with `/`.
|
|
1876
|
+
* @param {number} timeoutSeconds Lifetime to ask for, in seconds; rounded down to
|
|
1877
|
+
* whole seconds, and at least 1.
|
|
1878
|
+
* @returns {Promise<StorageLock>} The granted lock.
|
|
1879
|
+
* @throws {PubkyError} `InvalidInput` for a negative, NaN or out-of-range timeout;
|
|
1880
|
+
* a path that is already locked rejects with `RequestError` and status `423`;
|
|
1881
|
+
* directory targets with `400`; a homeserver without lock support with `405`.
|
|
1882
|
+
* See {@link SessionStorage} for shared errors.
|
|
1883
|
+
*/
|
|
1884
|
+
lock(path: Path, timeout_seconds: number): Promise<StorageLock>;
|
|
1885
|
+
/**
|
|
1886
|
+
* `PUT` binary data to the path of a lock this client holds.
|
|
1887
|
+
*
|
|
1888
|
+
* @param {StorageLock} lock A lock this client holds.
|
|
1889
|
+
* @param {Uint8Array} body
|
|
1890
|
+
* @returns {Promise<void>}
|
|
1891
|
+
* @throws {PubkyError} A lock that has expired or was unlocked rejects with
|
|
1892
|
+
* `RequestError` and status `412`; take a new one and read the file again.
|
|
1893
|
+
* Otherwise as {@link SessionStorage.putBytes}.
|
|
1894
|
+
*/
|
|
1895
|
+
putBytesLocked(lock: StorageLock, body: Uint8Array): Promise<void>;
|
|
1853
1896
|
/**
|
|
1854
1897
|
* Create or replace a file with binary data at an absolute session path.
|
|
1855
1898
|
*
|
|
@@ -1869,6 +1912,17 @@ export class SessionStorage {
|
|
|
1869
1912
|
* otherwise serialization, upload, or shared write/request errors (see {@link SessionStorage}).
|
|
1870
1913
|
*/
|
|
1871
1914
|
putJson(path: Path, body: any): Promise<void>;
|
|
1915
|
+
/**
|
|
1916
|
+
* `PUT` text to the path of a lock this client holds.
|
|
1917
|
+
*
|
|
1918
|
+
* @param {StorageLock} lock A lock this client holds.
|
|
1919
|
+
* @param {string} body
|
|
1920
|
+
* @returns {Promise<void>}
|
|
1921
|
+
* @throws {PubkyError} A lock that has expired or was unlocked rejects with
|
|
1922
|
+
* `RequestError` and status `412`; take a new one and read the file again.
|
|
1923
|
+
* Otherwise as {@link SessionStorage.putText}.
|
|
1924
|
+
*/
|
|
1925
|
+
putTextLocked(lock: StorageLock, body: string): Promise<void>;
|
|
1872
1926
|
/**
|
|
1873
1927
|
* Create or replace a file with text at an absolute session path.
|
|
1874
1928
|
*
|
|
@@ -1878,6 +1932,22 @@ export class SessionStorage {
|
|
|
1878
1932
|
* @throws {PubkyError} Upload or shared write/request errors (see {@link SessionStorage}).
|
|
1879
1933
|
*/
|
|
1880
1934
|
putText(path: Path, body: string): Promise<void>;
|
|
1935
|
+
/**
|
|
1936
|
+
* Restart the lifetime of a lock this client holds.
|
|
1937
|
+
*
|
|
1938
|
+
* On success the lock carries the newly granted
|
|
1939
|
+
* {@link StorageLock.timeoutSeconds}.
|
|
1940
|
+
*
|
|
1941
|
+
* @param {StorageLock} lock A lock this client holds.
|
|
1942
|
+
* @param {number} timeoutSeconds Lifetime to ask for, in seconds; rounded down to
|
|
1943
|
+
* whole seconds, and at least 1.
|
|
1944
|
+
* @returns {Promise<void>}
|
|
1945
|
+
* @throws {PubkyError} A lock that has expired or was unlocked rejects with
|
|
1946
|
+
* `RequestError` and status `412`; take a new one and read the file again.
|
|
1947
|
+
* `InvalidInput` for a negative, NaN or out-of-range timeout.
|
|
1948
|
+
* See {@link SessionStorage} for shared errors.
|
|
1949
|
+
*/
|
|
1950
|
+
refreshLock(lock: StorageLock, timeout_seconds: number): Promise<void>;
|
|
1881
1951
|
/**
|
|
1882
1952
|
* Get metadata for an absolute, session-scoped path (e.g. `"/pub/app/file.json"`).
|
|
1883
1953
|
*
|
|
@@ -1888,6 +1958,15 @@ export class SessionStorage {
|
|
|
1888
1958
|
* @throws {PubkyError} All other failures (see {@link SessionStorage}).
|
|
1889
1959
|
*/
|
|
1890
1960
|
stats(path: Path): Promise<ResourceStats | undefined>;
|
|
1961
|
+
/**
|
|
1962
|
+
* Release a lock this client holds.
|
|
1963
|
+
*
|
|
1964
|
+
* @param {StorageLock} lock A lock this client holds.
|
|
1965
|
+
* @returns {Promise<void>}
|
|
1966
|
+
* @throws {PubkyError} A lock that no longer exists rejects with `RequestError`
|
|
1967
|
+
* and status `409`. See {@link SessionStorage} for shared errors.
|
|
1968
|
+
*/
|
|
1969
|
+
unlock(lock: StorageLock): Promise<void>;
|
|
1891
1970
|
}
|
|
1892
1971
|
|
|
1893
1972
|
/**
|
|
@@ -2158,6 +2237,52 @@ export class SignupGrantDeepLink {
|
|
|
2158
2237
|
readonly xCallback: XCallbackParams;
|
|
2159
2238
|
}
|
|
2160
2239
|
|
|
2240
|
+
/**
|
|
2241
|
+
* An exclusive write lock on one file path, granted by the homeserver.
|
|
2242
|
+
*
|
|
2243
|
+
* While the lock lives, only writes that present it are accepted on the path;
|
|
2244
|
+
* every other write, and every other {@link SessionStorage.lock}, rejects with
|
|
2245
|
+
* `423 Locked`. The lock ends when it is {@link SessionStorage.unlock | unlocked}
|
|
2246
|
+
* or when its {@link StorageLock.timeoutSeconds} runs out without a
|
|
2247
|
+
* {@link SessionStorage.refreshLock | refresh}, so a client that disappears never
|
|
2248
|
+
* blocks a path for long.
|
|
2249
|
+
*
|
|
2250
|
+
* The lock is a bearer token: whoever holds this value, and may write the path,
|
|
2251
|
+
* can use and release the lock.
|
|
2252
|
+
*
|
|
2253
|
+
* Calls that take the lock may overlap: a {@link SessionStorage.refreshLock | refresh}
|
|
2254
|
+
* can run while a locked write is in flight.
|
|
2255
|
+
*
|
|
2256
|
+
* @example
|
|
2257
|
+
* const lock = await session.storage.lock("/pub/my.app/state.json", 30);
|
|
2258
|
+
* const state = await session.storage.getText(lock.path);
|
|
2259
|
+
* await session.storage.putTextLocked(lock, state);
|
|
2260
|
+
* await session.storage.unlock(lock);
|
|
2261
|
+
*/
|
|
2262
|
+
export class StorageLock {
|
|
2263
|
+
private constructor();
|
|
2264
|
+
free(): void;
|
|
2265
|
+
[Symbol.dispose](): void;
|
|
2266
|
+
/**
|
|
2267
|
+
* Value of the `If` header that presents this lock on a write.
|
|
2268
|
+
*/
|
|
2269
|
+
ifHeader(): string;
|
|
2270
|
+
/**
|
|
2271
|
+
* The locked path.
|
|
2272
|
+
*/
|
|
2273
|
+
readonly path: Path;
|
|
2274
|
+
/**
|
|
2275
|
+
* Lifetime the homeserver granted at the last `lock` or `refreshLock`, in seconds,
|
|
2276
|
+
* counted from when that call resolved. It may be shorter than what was asked for.
|
|
2277
|
+
* It is not the time remaining: note when the call resolved to know when to refresh.
|
|
2278
|
+
*/
|
|
2279
|
+
readonly timeoutSeconds: number;
|
|
2280
|
+
/**
|
|
2281
|
+
* The lock token URL, `opaquelocktoken:<uuid>`.
|
|
2282
|
+
*/
|
|
2283
|
+
readonly token: string;
|
|
2284
|
+
}
|
|
2285
|
+
|
|
2161
2286
|
/**
|
|
2162
2287
|
* Metadata for a session saved in the browser session store.
|
|
2163
2288
|
*/
|
package/pubky_bg.wasm
CHANGED
|
Binary file
|