@synonymdev/pubky 0.16.2 → 0.17.1
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 +26 -2
- package/index.cjs +122 -59
- package/index.js +123 -60
- package/package.json +1 -1
- package/pubky.d.ts +70 -21
- package/pubky_bg.wasm +0 -0
package/package.json
CHANGED
package/pubky.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export interface VerifiedGrantClaims {
|
|
|
45
45
|
* Provides a simplified, actionable set of error categories for developers
|
|
46
46
|
* to handle in their code.
|
|
47
47
|
*/
|
|
48
|
-
export type PubkyErrorName = "RequestError" | "InvalidInput" | "AuthenticationError" | "PkarrError" | "ClientStateError" | "InternalError";
|
|
48
|
+
export type PubkyErrorName = "RequestError" | "CredentialRefreshError" | "InvalidInput" | "AuthenticationError" | "PkarrError" | "ClientStateError" | "InternalError";
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Optional x-callback-url metadata carried by a Pubky deep link.
|
|
@@ -152,7 +152,7 @@ export type GrantApprovalFormat = "bareGrant" | "signedApprovalV1";
|
|
|
152
152
|
*
|
|
153
153
|
* @property name - A machine-readable error code from {@link PubkyErrorName}. Use this for programmatic error handling.
|
|
154
154
|
* @property message - A human-readable, descriptive error message suitable for logging.
|
|
155
|
-
* @property data -
|
|
155
|
+
* @property data - Optional structured context. For a `RequestError` it is a {@link RequestErrorData}, e.g. `{ reason: "Http", statusCode: 404 }`.
|
|
156
156
|
*
|
|
157
157
|
* @example
|
|
158
158
|
* ```typescript
|
|
@@ -160,14 +160,11 @@ export type GrantApprovalFormat = "bareGrant" | "signedApprovalV1";
|
|
|
160
160
|
* await client.signup(...);
|
|
161
161
|
* } catch (e) {
|
|
162
162
|
* const error = e as PubkyError;
|
|
163
|
-
* if (
|
|
164
|
-
* error.
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* (error.data as { statusCode?: number }).statusCode === 404
|
|
169
|
-
* ) {
|
|
170
|
-
* // Handle not found...
|
|
163
|
+
* if (error.name === "RequestError") {
|
|
164
|
+
* const data = error.data as RequestErrorData;
|
|
165
|
+
* if (data.statusCode === 404) {
|
|
166
|
+
* // Handle not found...
|
|
167
|
+
* }
|
|
171
168
|
* }
|
|
172
169
|
* }
|
|
173
170
|
* ```
|
|
@@ -178,13 +175,34 @@ export interface PubkyError extends Error {
|
|
|
178
175
|
data?: unknown;
|
|
179
176
|
}
|
|
180
177
|
|
|
178
|
+
/** The classified cause of a `RequestError`, carried in `PubkyError.data.reason`. */
|
|
179
|
+
export type RequestErrorReason =
|
|
180
|
+
| "Http"
|
|
181
|
+
| "Timeout"
|
|
182
|
+
| "Connection"
|
|
183
|
+
| "Body"
|
|
184
|
+
| "Decode"
|
|
185
|
+
| "InvalidRequest"
|
|
186
|
+
| "Other";
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* `PubkyError.data` for a `RequestError`.
|
|
190
|
+
*
|
|
191
|
+
* `statusCode` is present when `reason` is `"Http"`. A reason describes the
|
|
192
|
+
* failure, not whether retrying is safe.
|
|
193
|
+
*/
|
|
194
|
+
export interface RequestErrorData {
|
|
195
|
+
reason: RequestErrorReason;
|
|
196
|
+
statusCode?: number;
|
|
197
|
+
}
|
|
198
|
+
|
|
181
199
|
/**
|
|
182
200
|
* Represents the standard error structure for all exceptions thrown by the Pubky
|
|
183
201
|
* WASM client.
|
|
184
202
|
*
|
|
185
203
|
* @property name - A machine-readable error code from {@link PubkyErrorName}. Use this for programmatic error handling.
|
|
186
204
|
* @property message - A human-readable, descriptive error message suitable for logging.
|
|
187
|
-
* @property data -
|
|
205
|
+
* @property data - Optional structured context. For a `RequestError` it is a {@link RequestErrorData}, e.g. `{ reason: "Http", statusCode: 404 }`.
|
|
188
206
|
*
|
|
189
207
|
* @example
|
|
190
208
|
* ```typescript
|
|
@@ -192,14 +210,11 @@ export interface PubkyError extends Error {
|
|
|
192
210
|
* await client.signup(...);
|
|
193
211
|
* } catch (e) {
|
|
194
212
|
* const error = e as PubkyError;
|
|
195
|
-
* if (
|
|
196
|
-
* error.
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
* (error.data as { statusCode?: number }).statusCode === 404
|
|
201
|
-
* ) {
|
|
202
|
-
* // Handle not found...
|
|
213
|
+
* if (error.name === 'RequestError') {
|
|
214
|
+
* const data = error.data as RequestErrorData;
|
|
215
|
+
* if (data.statusCode === 404) {
|
|
216
|
+
* // Handle not found...
|
|
217
|
+
* }
|
|
203
218
|
* }
|
|
204
219
|
* }
|
|
205
220
|
* ```
|
|
@@ -1937,8 +1952,10 @@ export class SessionInfo {
|
|
|
1937
1952
|
*
|
|
1938
1953
|
* Failures reject with a {@link PubkyError}. Path validation, transport, and HTTP
|
|
1939
1954
|
* failures use `RequestError`; only HTTP errors include `data.statusCode`.
|
|
1940
|
-
*
|
|
1941
|
-
*
|
|
1955
|
+
* Automatic grant refresh failures use `CredentialRefreshError`, with the
|
|
1956
|
+
* refresh HTTP status in `data.statusCode` when available. URL parsing failures
|
|
1957
|
+
* use `InvalidInput`. Other credential preparation and reading response bodies
|
|
1958
|
+
* can also fail.
|
|
1942
1959
|
*
|
|
1943
1960
|
* Only {@link SessionStorage.exists} and {@link SessionStorage.stats} treat
|
|
1944
1961
|
* HTTP 404/410 as missing. Other HTTP failures, including 401/403 and 5xx, reject.
|
|
@@ -2044,6 +2061,38 @@ export class SessionStorage {
|
|
|
2044
2061
|
* See {@link SessionStorage} for shared errors.
|
|
2045
2062
|
*/
|
|
2046
2063
|
lock(path: Path, timeout_seconds: number): Promise<StorageLock>;
|
|
2064
|
+
/**
|
|
2065
|
+
* Upload a Blob or File to a locked path without copying its contents into
|
|
2066
|
+
* WASM memory.
|
|
2067
|
+
*
|
|
2068
|
+
* @param {StorageLock} lock A lock you hold. The upload uses the lock's path.
|
|
2069
|
+
* @param {Blob} body A Blob or File to upload.
|
|
2070
|
+
* @returns {Promise<void>}
|
|
2071
|
+
* @throws {PubkyError} An expired or released lock rejects with status `412`.
|
|
2072
|
+
* A file that changed since the write was prepared rejects with status `409`.
|
|
2073
|
+
* See {@link SessionStorage.putBytesLocked} for recovery and
|
|
2074
|
+
* {@link SessionStorage.putBlob} for input validation and shared errors.
|
|
2075
|
+
* @example
|
|
2076
|
+
* const lock = await session.storage.lock("/pub/example.com/file.bin", 30);
|
|
2077
|
+
* try {
|
|
2078
|
+
* await session.storage.putBlobLocked(lock, file);
|
|
2079
|
+
* } finally {
|
|
2080
|
+
* await session.storage.unlock(lock);
|
|
2081
|
+
* }
|
|
2082
|
+
*/
|
|
2083
|
+
putBlobLocked(lock: StorageLock, body: Blob): Promise<void>;
|
|
2084
|
+
/**
|
|
2085
|
+
* Upload a Blob or File without copying its contents into WASM memory.
|
|
2086
|
+
*
|
|
2087
|
+
* @param {Path} path File path; must not end with `/`.
|
|
2088
|
+
* @param {Blob} body A Blob or File to upload.
|
|
2089
|
+
* @returns {Promise<void>}
|
|
2090
|
+
* @throws {PubkyError} `InvalidInput` if body is not a Blob or File;
|
|
2091
|
+
* otherwise upload or shared write/request errors (see {@link SessionStorage}).
|
|
2092
|
+
* @example
|
|
2093
|
+
* await session.storage.putBlob("/pub/example.com/file.bin", file);
|
|
2094
|
+
*/
|
|
2095
|
+
putBlob(path: Path, body: Blob): Promise<void>;
|
|
2047
2096
|
/**
|
|
2048
2097
|
* `PUT` binary data to the path of a lock this client holds.
|
|
2049
2098
|
*
|
package/pubky_bg.wasm
CHANGED
|
Binary file
|