@synonymdev/pubky 0.11.0 → 0.13.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/pubky.d.ts CHANGED
@@ -4,14 +4,14 @@
4
4
  * An enum representing the available verbosity levels of the logger.
5
5
  */
6
6
 
7
- type Level = "error" | "warn" | "info" | "debug" | "trace";
7
+ export type Level = "error" | "warn" | "info" | "debug" | "trace";
8
8
  /**
9
9
  * The `ReadableStreamType` enum.
10
10
  *
11
11
  * *This API requires the following crate features to be activated: `ReadableStreamType`*
12
12
  */
13
13
 
14
- type ReadableStreamType = "bytes";
14
+ export type ReadableStreamType = "bytes";
15
15
  /**
16
16
  * A union type of all possible machine-readable codes for the `name` property
17
17
  * of a {@link PubkyError}.
@@ -51,11 +51,11 @@ export interface XCallbackParams {
51
51
  */
52
52
  export interface GrantAuthFlowOptions {
53
53
  /**
54
- * App identifier shown in the user\'s grant/session list, typically a domain.
54
+ * App identifier shown in the user's grant/session list, typically a domain.
55
55
  */
56
56
  clientId: string;
57
57
  /**
58
- * Optional HTTP relay base, e.g. `\"https://demo.httprelay.io/inbox/\"`.
58
+ * Optional HTTP relay base, e.g. `"https://demo.httprelay.io/inbox/"`.
59
59
  * Defaults to the default Synonym-hosted relay when omitted.
60
60
  */
61
61
  relay?: string | null;
@@ -88,6 +88,12 @@ export interface PubkyClientConfig {
88
88
  * Configuration on how to access pkarr packets on the mainline DHT.
89
89
  */
90
90
  pkarr?: PkarrConfig;
91
+ /**
92
+ * Maximum raw HTTP error-body bytes to capture. Defaults to 4096; zero skips the body.
93
+ * UTF-8 decoding can produce up to three times as many bytes of text, plus the
94
+ * truncation marker. This does not cap final message size or total memory use.
95
+ */
96
+ maxErrorBodyBytes?: number;
91
97
  }
92
98
 
93
99
  /**
@@ -137,10 +143,10 @@ export interface PubkyError extends Error {
137
143
  * } catch (e) {
138
144
  * const error = e as PubkyError;
139
145
  * if (
140
- * error.name === \'RequestError\' &&
141
- * typeof error.data === \'object\' &&
146
+ * error.name === 'RequestError' &&
147
+ * typeof error.data === 'object' &&
142
148
  * error.data !== null &&
143
- * \'statusCode\' in error.data &&
149
+ * 'statusCode' in error.data &&
144
150
  * (error.data as { statusCode?: number }).statusCode === 404
145
151
  * ) {
146
152
  * // Handle not found...
@@ -162,7 +168,7 @@ export interface PubkyError {
162
168
  *
163
169
  * @typedef {Object} ResourceStats
164
170
  * @property {number=} contentLength Size in bytes.
165
- * @property {string=} contentType Media type (e.g. \"application/json; charset=utf-8\").
171
+ * @property {string=} contentType Media type (e.g. "application/json; charset=utf-8").
166
172
  * @property {number=} lastModifiedMs Unix epoch milliseconds.
167
173
  * @property {string=} etag Opaque server ETag for the current version.
168
174
  *
@@ -183,7 +189,7 @@ export interface ResourceStats {
183
189
  */
184
190
  contentLength?: number;
185
191
  /**
186
- * Media type of the stored object (e.g., `\"application/json\"`).
192
+ * Media type of the stored object (e.g., `"application/json"`).
187
193
  */
188
194
  contentType?: string;
189
195
  /**
@@ -256,6 +262,8 @@ export class AuthFlow {
256
262
  * @returns {AuthFlow} A flow reconnected to the original relay channel.
257
263
  * @throws {PubkyError}
258
264
  * - `{ name: "AuthenticationError" }` if the URL is invalid or not a signin/signup link
265
+ *
266
+ * @deprecated Use `GrantAuthFlow.resume(...)` instead.
259
267
  */
260
268
  static resume(authorization_url: string): AuthFlow;
261
269
  /**
@@ -445,13 +453,6 @@ export class BrowserSessionStore {
445
453
  private constructor();
446
454
  free(): void;
447
455
  [Symbol.dispose](): void;
448
- /**
449
- * Clear all local stored session records for this origin.
450
- *
451
- * Delegated keys referenced by those stored session records are removed.
452
- * Delegated keys that only belong to pending grant flows are preserved.
453
- */
454
- clear(): Promise<void>;
455
456
  /**
456
457
  * Clear all browser auth persistence owned by this SDK origin.
457
458
  *
@@ -461,6 +462,13 @@ export class BrowserSessionStore {
461
462
  * grants or immediately invalidate already-live in-memory sessions.
462
463
  */
463
464
  clearAll(): Promise<void>;
465
+ /**
466
+ * Clear all local stored session records for this origin.
467
+ *
468
+ * Delegated keys referenced by those stored session records are removed.
469
+ * Delegated keys that only belong to pending grant flows are preserved.
470
+ */
471
+ clear(): Promise<void>;
464
472
  /**
465
473
  * Whether IndexedDB is available for durable session persistence.
466
474
  */
@@ -501,26 +509,27 @@ export class Client {
501
509
  *
502
510
  * @example
503
511
  * const client = pubky.client;
504
- * const res = await client.fetch(`https://_pubky.${user}/pub/app/file.txt`, { method: "PUT", body: "hi", credentials: "include" });
512
+ * const res = await client.fetch(`https://_pubky.${user}/storage/${user}/pub/app/file.txt`, { method: "PUT", body: "hi", credentials: "include" });
505
513
  */
506
514
  fetch(url: string, init?: RequestInit | null): Promise<Response>;
507
515
  /**
508
516
  * Create a Pubky HTTP client.
509
517
  *
510
518
  * @param {PubkyClientConfig} [config]
511
- * Optional transport overrides:
512
- * `{ pkarr?: { relays?: string[], request_timeout?: number } }`.
519
+ * Optional error-body limit and PKARR overrides:
520
+ * `{ maxErrorBodyBytes?: number, pkarr?: { relays?: string[], requestTimeout?: number } }`.
513
521
  *
514
522
  * @returns {Client}
515
523
  * A configured low-level client. Prefer `new Pubky().client` unless you
516
- * need custom relays/timeouts.
524
+ * need custom relays, timeouts or error-body limits.
517
525
  *
518
526
  * @throws {InvalidInput}
519
- * If any PKARR relay URL is invalid.
527
+ * If a relay URL is invalid or the error-body limit is not an integer in 0..=4294967295.
520
528
  *
521
529
  * @example
522
530
  * const client = new Client({
523
- * pkarr: { relays: ["https://relay1/","https://relay2/"], request_timeout: 8000 }
531
+ * maxErrorBodyBytes: 1024,
532
+ * pkarr: { relays: ["https://relay1/","https://relay2/"], requestTimeout: 8000 }
524
533
  * });
525
534
  * const pubky = Pubky.withClient(client);
526
535
  */
@@ -549,22 +558,14 @@ export class Client {
549
558
  /**
550
559
  * Cookie-only view over a cookie-backed `Session`.
551
560
  *
552
- * Grant-backed sessions do not expose this view; use `session.cookie` and
553
- * check for `undefined` before calling cookie-specific methods.
561
+ * New applications should use `session.grant` and `GrantSession`.
562
+ *
563
+ * @deprecated Use `GrantSession` instead.
554
564
  */
555
565
  export class CookieSession {
556
566
  private constructor();
557
567
  free(): void;
558
568
  [Symbol.dispose](): void;
559
- /**
560
- * Export session metadata for legacy cookie restore.
561
- *
562
- * The returned string contains no secrets; the browser cookie jar must
563
- * still hold the HTTP-only cookie.
564
- *
565
- * @returns {string}
566
- */
567
- export(): string;
568
569
  /**
569
570
  * Export the cookie secret needed to restore this cookie session.
570
571
  *
@@ -572,8 +573,19 @@ export class CookieSession {
572
573
  * Node.js. Browser sessions cannot read HTTP-only Set-Cookie values.
573
574
  *
574
575
  * @returns {Promise<string>}
576
+ * @deprecated Use `GrantSession.exportLocalSecret()` instead.
575
577
  */
576
578
  exportSecret(): Promise<string>;
579
+ /**
580
+ * Export session metadata for legacy cookie restore.
581
+ *
582
+ * The returned string contains no secrets; the browser cookie jar must
583
+ * still hold the HTTP-only cookie.
584
+ *
585
+ * @returns {string}
586
+ * @deprecated Use `GrantSession.exportLocalSecret()` instead.
587
+ */
588
+ export(): string;
577
589
  }
578
590
 
579
591
  /**
@@ -649,6 +661,7 @@ export class Event {
649
661
  * Builder for creating an event stream subscription.
650
662
  *
651
663
  * Construct via `Pubky.eventStreamForUser()` or `Pubky.eventStreamFor()`.
664
+ * Configuration methods consume this builder unless documented otherwise.
652
665
  *
653
666
  * @example
654
667
  * ```typescript
@@ -681,6 +694,8 @@ export class EventStreamBuilder {
681
694
  *
682
695
  * Each user can have an independent cursor position. If a user already exists,
683
696
  * their cursor value is overwritten.
697
+ * Updates this builder and returns a copy for chaining. Rejected input
698
+ * leaves this builder unchanged.
684
699
  *
685
700
  * @param {Array<[string, string | null]>} users - Array of [z32PublicKey, cursor] tuples
686
701
  * @returns {EventStreamBuilder} - Builder for chaining
@@ -739,6 +754,20 @@ export class EventStreamBuilder {
739
754
  * @returns {EventStreamBuilder} - Builder for chaining
740
755
  */
741
756
  live(): EventStreamBuilder;
757
+ /**
758
+ * Set a client-side byte limit for SSE payloads. Unbounded by default.
759
+ * Limits accumulated data (including newlines joining data fields), each
760
+ * event name, and each ID separately in historical and live streams.
761
+ * Comments, unknown fields and framing bytes are excluded.
762
+ * There is no total block or stream byte limit.
763
+ * Overflow cancels the response and errors the ReadableStream.
764
+ * Updates this builder and returns a copy for chaining. Rejected input
765
+ * leaves this builder unchanged.
766
+ *
767
+ * @param {number} limit - Integer in 1..=4294967295.
768
+ * @throws {InvalidInput} If the limit is not a positive 32-bit integer.
769
+ */
770
+ maxEventBytes(limit: number): EventStreamBuilder;
742
771
  /**
743
772
  * Filter events by path. Call once per path to receive the
744
773
  * union of several scopes (e.g. `/pub/` plus a private `/priv/app/`).
@@ -822,6 +851,15 @@ export class GrantAuthFlow {
822
851
  * Block until the user approves on their signer device; returns a grant-backed `Session`.
823
852
  */
824
853
  awaitApproval(): Promise<Session>;
854
+ /**
855
+ * Resume a previously saved pending delegated grant auth flow.
856
+ *
857
+ * Runtime: delegated grant keys require a secure browser context with
858
+ * WebCrypto `crypto.subtle` and IndexedDB. The saved `keyId` must still
859
+ * exist in IndexedDB for the same origin. Unsupported runtimes reject with
860
+ * `ClientStateError`.
861
+ */
862
+ static resumeDelegated(saved_state: string): Promise<GrantAuthFlow>;
825
863
  /**
826
864
  * Resume a previously saved pending grant auth flow (standalone).
827
865
  * Prefer `pubky.resumeGrantAuthFlow()` to reuse a facade client.
@@ -833,15 +871,6 @@ export class GrantAuthFlow {
833
871
  * @returns {GrantAuthFlow} A flow reconnected to the original relay channel.
834
872
  */
835
873
  static resume(saved_state: string): GrantAuthFlow;
836
- /**
837
- * Resume a previously saved pending delegated grant auth flow.
838
- *
839
- * Runtime: delegated grant keys require a secure browser context with
840
- * WebCrypto `crypto.subtle` and IndexedDB. The saved `keyId` must still
841
- * exist in IndexedDB for the same origin. Unsupported runtimes reject with
842
- * `ClientStateError`.
843
- */
844
- static resumeDelegated(saved_state: string): Promise<GrantAuthFlow>;
845
874
  /**
846
875
  * Save sensitive state required to resume this delegated pending grant flow.
847
876
  *
@@ -857,6 +886,17 @@ export class GrantAuthFlow {
857
886
  * `pubky.resumeGrantAuthFlow()`.
858
887
  */
859
888
  saveLocal(): string;
889
+ /**
890
+ * Start a browser delegated grant-backed flow.
891
+ *
892
+ * The SDK creates a fresh non-extractable WebCrypto Ed25519 key in
893
+ * IndexedDB and uses that key for grant Proof-of-Possession signing.
894
+ *
895
+ * Runtime: delegated grant keys require a secure browser context with
896
+ * WebCrypto `crypto.subtle` and IndexedDB. Unsupported runtimes reject
897
+ * with `ClientStateError`.
898
+ */
899
+ static startDelegated(capabilities: Capabilities, kind: AuthFlowKind, options: GrantAuthFlowOptions): Promise<GrantAuthFlow>;
860
900
  /**
861
901
  * Start a grant-backed flow with a new DHT client.
862
902
  * Prefer `pubky.startGrantAuthFlow()` to reuse a facade DHT client.
@@ -876,17 +916,6 @@ export class GrantAuthFlow {
876
916
  * then `awaitApproval()` to receive a grant-backed `Session`.
877
917
  */
878
918
  static start(capabilities: Capabilities, kind: AuthFlowKind, options: GrantAuthFlowOptions): GrantAuthFlow;
879
- /**
880
- * Start a browser delegated grant-backed flow.
881
- *
882
- * The SDK creates a fresh non-extractable WebCrypto Ed25519 key in
883
- * IndexedDB and uses that key for grant Proof-of-Possession signing.
884
- *
885
- * Runtime: delegated grant keys require a secure browser context with
886
- * WebCrypto `crypto.subtle` and IndexedDB. Unsupported runtimes reject
887
- * with `ClientStateError`.
888
- */
889
- static startDelegated(capabilities: Capabilities, kind: AuthFlowKind, options: GrantAuthFlowOptions): Promise<GrantAuthFlow>;
890
919
  /**
891
920
  * Non-blocking single poll step (advanced UIs).
892
921
  *
@@ -1055,6 +1084,18 @@ export class IntoUnderlyingByteSource {
1055
1084
  readonly type: ReadableStreamType;
1056
1085
  }
1057
1086
 
1087
+ declare class IntoUnderlyingByteSource2 {
1088
+ private constructor();
1089
+ free(): void;
1090
+ [Symbol.dispose](): void;
1091
+ cancel(): void;
1092
+ pull(controller: ReadableByteStreamController): Promise<any>;
1093
+ start(controller: ReadableByteStreamController): void;
1094
+ readonly autoAllocateChunkSize: number;
1095
+ readonly type: ReadableStreamType;
1096
+ }
1097
+ export type { IntoUnderlyingByteSource2 };
1098
+
1058
1099
  export class IntoUnderlyingSink {
1059
1100
  private constructor();
1060
1101
  free(): void;
@@ -1064,6 +1105,16 @@ export class IntoUnderlyingSink {
1064
1105
  write(chunk: any): Promise<any>;
1065
1106
  }
1066
1107
 
1108
+ declare class IntoUnderlyingSink2 {
1109
+ private constructor();
1110
+ free(): void;
1111
+ [Symbol.dispose](): void;
1112
+ abort(reason: any): Promise<any>;
1113
+ close(): Promise<any>;
1114
+ write(chunk: any): Promise<any>;
1115
+ }
1116
+ export type { IntoUnderlyingSink2 };
1117
+
1067
1118
  export class IntoUnderlyingSource {
1068
1119
  private constructor();
1069
1120
  free(): void;
@@ -1072,6 +1123,15 @@ export class IntoUnderlyingSource {
1072
1123
  pull(controller: ReadableStreamDefaultController): Promise<any>;
1073
1124
  }
1074
1125
 
1126
+ declare class IntoUnderlyingSource2 {
1127
+ private constructor();
1128
+ free(): void;
1129
+ [Symbol.dispose](): void;
1130
+ cancel(): void;
1131
+ pull(controller: ReadableStreamDefaultController): Promise<any>;
1132
+ }
1133
+ export type { IntoUnderlyingSource2 };
1134
+
1075
1135
  export class Keypair {
1076
1136
  private constructor();
1077
1137
  free(): void;
@@ -1119,14 +1179,6 @@ export class Pkdns {
1119
1179
  * PKDNS actor with publishing enabled (requires a keypair).
1120
1180
  */
1121
1181
  static fromKeypair(keypair: Keypair): Pkdns;
1122
- /**
1123
- * Resolve the homeserver for **this** user (requires keypair).
1124
- *
1125
- * @returns {Promise<PublicKey|undefined>} Homeserver public key or `undefined` if not found.
1126
- * @throws When no keypair is attached, Pkarr resolution fails, or a resolved `_pubky` target
1127
- * is malformed.
1128
- */
1129
- getHomeserver(): Promise<PublicKey | undefined>;
1130
1182
  /**
1131
1183
  * Resolve the homeserver for a given public key (read-only).
1132
1184
  *
@@ -1136,6 +1188,14 @@ export class Pkdns {
1136
1188
  * @throws When Pkarr resolution fails or a resolved `_pubky` target is malformed.
1137
1189
  */
1138
1190
  getHomeserverOf(pubky: PublicKey): Promise<PublicKey | undefined>;
1191
+ /**
1192
+ * Resolve the homeserver for **this** user (requires keypair).
1193
+ *
1194
+ * @returns {Promise<PublicKey|undefined>} Homeserver public key or `undefined` if not found.
1195
+ * @throws When no keypair is attached, Pkarr resolution fails, or a resolved `_pubky` target
1196
+ * is malformed.
1197
+ */
1198
+ getHomeserver(): Promise<PublicKey | undefined>;
1139
1199
  /**
1140
1200
  * Read-only PKDNS actor (no keypair; resolve only).
1141
1201
  */
@@ -1167,19 +1227,19 @@ export class Pubky {
1167
1227
  free(): void;
1168
1228
  [Symbol.dispose](): void;
1169
1229
  /**
1170
- * Create an event stream builder for a specific homeserver.
1230
+ * Create an event stream builder for a single user.
1171
1231
  *
1172
- * Use this when you already know the homeserver pubkey. This avoids
1173
- * Pkarr resolution overhead. Obtain a homeserver pubkey via `getHomeserverOf()`.
1232
+ * This is the simplest way to subscribe to events for one user. The homeserver
1233
+ * is automatically resolved from the user's Pkarr record.
1174
1234
  *
1175
- * @param {PublicKey} homeserver - The homeserver public key
1235
+ * @param {PublicKey} user - The user's public key
1236
+ * @param {string | null} cursor - Optional cursor position to start from
1176
1237
  * @returns {EventStreamBuilder} - Builder for configuring and subscribing to the stream
1177
1238
  *
1178
1239
  * @example
1179
1240
  * ```typescript
1180
- * const homeserver = await pubky.getHomeserverOf(user1);
1181
- * const stream = await pubky.eventStreamFor(homeserver)
1182
- * .addUsers([[user1.z32(), null], [user2.z32(), null]])
1241
+ * const user = PublicKey.from("o1gg96ewuojmopcjbz8895478wdtxtzzuxnfjjz8o8e77csa1ngo");
1242
+ * const stream = await pubky.eventStreamForUser(user, null)
1183
1243
  * .live()
1184
1244
  * .subscribe();
1185
1245
  *
@@ -1188,21 +1248,21 @@ export class Pubky {
1188
1248
  * }
1189
1249
  * ```
1190
1250
  */
1191
- eventStreamFor(homeserver: PublicKey): EventStreamBuilder;
1251
+ eventStreamForUser(user: PublicKey, cursor?: string | null): EventStreamBuilder;
1192
1252
  /**
1193
- * Create an event stream builder for a single user.
1253
+ * Create an event stream builder for a specific homeserver.
1194
1254
  *
1195
- * This is the simplest way to subscribe to events for one user. The homeserver
1196
- * is automatically resolved from the user's Pkarr record.
1255
+ * Use this when you already know the homeserver pubkey. This avoids
1256
+ * Pkarr resolution overhead. Obtain a homeserver pubkey via `getHomeserverOf()`.
1197
1257
  *
1198
- * @param {PublicKey} user - The user's public key
1199
- * @param {string | null} cursor - Optional cursor position to start from
1258
+ * @param {PublicKey} homeserver - The homeserver public key
1200
1259
  * @returns {EventStreamBuilder} - Builder for configuring and subscribing to the stream
1201
1260
  *
1202
1261
  * @example
1203
1262
  * ```typescript
1204
- * const user = PublicKey.from("o1gg96ewuojmopcjbz8895478wdtxtzzuxnfjjz8o8e77csa1ngo");
1205
- * const stream = await pubky.eventStreamForUser(user, null)
1263
+ * const homeserver = await pubky.getHomeserverOf(user1);
1264
+ * const stream = await pubky.eventStreamFor(homeserver)
1265
+ * .addUsers([[user1.z32(), null], [user2.z32(), null]])
1206
1266
  * .live()
1207
1267
  * .subscribe();
1208
1268
  *
@@ -1211,7 +1271,7 @@ export class Pubky {
1211
1271
  * }
1212
1272
  * ```
1213
1273
  */
1214
- eventStreamForUser(user: PublicKey, cursor?: string | null): EventStreamBuilder;
1274
+ eventStreamFor(homeserver: PublicKey): EventStreamBuilder;
1215
1275
  /**
1216
1276
  * Resolve the homeserver for a given public key (read-only).
1217
1277
  *
@@ -1291,6 +1351,8 @@ export class Pubky {
1291
1351
  * sessionStorage.removeItem("pubky-auth-url");
1292
1352
  * }
1293
1353
  * }
1354
+ *
1355
+ * @deprecated Use `resumeGrantAuthFlow(...)` instead.
1294
1356
  */
1295
1357
  resumeCookieAuthFlow(authorization_url: string): AuthFlow;
1296
1358
  /**
@@ -1356,6 +1418,8 @@ export class Pubky {
1356
1418
  * const flow = pubky.startCookieAuthFlow("/pub/my-cool-app/:rw");
1357
1419
  * renderQr(flow.authorizationUrl);
1358
1420
  * const session = await flow.awaitApproval();
1421
+ *
1422
+ * @deprecated Use `startGrantAuthFlow(...)` instead.
1359
1423
  */
1360
1424
  startCookieAuthFlow(capabilities: Capabilities, kind: AuthFlowKind, relay?: string | null, x_callback?: XCallbackParams | null): AuthFlow;
1361
1425
  /**
@@ -1521,13 +1585,6 @@ export class PublicStorage {
1521
1585
  * @returns {Promise<boolean>}
1522
1586
  */
1523
1587
  exists(address: Address): Promise<boolean>;
1524
- /**
1525
- * Perform a streaming `GET` and expose the raw `Response` object.
1526
- *
1527
- * @param {Address} address
1528
- * @returns {Promise<Response>}
1529
- */
1530
- get(address: Address): Promise<Response>;
1531
1588
  /**
1532
1589
  * Fetch bytes from an addressed path.
1533
1590
  *
@@ -1549,6 +1606,13 @@ export class PublicStorage {
1549
1606
  * @returns {Promise<string>}
1550
1607
  */
1551
1608
  getText(address: Address): Promise<string>;
1609
+ /**
1610
+ * Perform a streaming `GET` and expose the raw `Response` object.
1611
+ *
1612
+ * @param {Address} address
1613
+ * @returns {Promise<Response>}
1614
+ */
1615
+ get(address: Address): Promise<Response>;
1552
1616
  /**
1553
1617
  * List a directory. Results are `pubky://…` identifier URLs.
1554
1618
  *
@@ -1596,18 +1660,6 @@ export class Session {
1596
1660
  private constructor();
1597
1661
  free(): void;
1598
1662
  [Symbol.dispose](): void;
1599
- /**
1600
- * Export the session metadata so it can be restored after a tab refresh.
1601
- *
1602
- * The export string contains **no secrets**; it only serializes the public `SessionInfo`.
1603
- * Browsers remain responsible for persisting the HTTP-only session cookie.
1604
- *
1605
- * @returns {string}
1606
- * A base64 string to store (e.g. in `localStorage`).
1607
- *
1608
- * @deprecated Prefer `exportLocalSecret()` for grant sessions.
1609
- */
1610
- export(): string;
1611
1663
  /**
1612
1664
  * Export the local secret material needed to restore this session.
1613
1665
  *
@@ -1623,6 +1675,18 @@ export class Session {
1623
1675
  * A secret token that can be passed to `pubky.restoreSession()`.
1624
1676
  */
1625
1677
  exportLocalSecret(): Promise<string>;
1678
+ /**
1679
+ * Export the session metadata so it can be restored after a tab refresh.
1680
+ *
1681
+ * The export string contains **no secrets**; it only serializes the public `SessionInfo`.
1682
+ * Browsers remain responsible for persisting the HTTP-only session cookie.
1683
+ *
1684
+ * @returns {string}
1685
+ * A base64 string to store (e.g. in `localStorage`).
1686
+ *
1687
+ * @deprecated Use `GrantSession.exportLocalSecret()` instead.
1688
+ */
1689
+ export(): string;
1626
1690
  /**
1627
1691
  * Restore a session from an `export()` string.
1628
1692
  *
@@ -1635,7 +1699,7 @@ export class Session {
1635
1699
  * Optional client to reuse transport configuration.
1636
1700
  * @returns {Promise<Session>}
1637
1701
  *
1638
- * @deprecated Prefer `Pubky.restoreSession(...)`.
1702
+ * @deprecated Use `Pubky.restoreSession(...)` with a grant secret.
1639
1703
  */
1640
1704
  static restore(exported: string, client?: Client | null): Promise<Session>;
1641
1705
  /**
@@ -1651,6 +1715,7 @@ export class Session {
1651
1715
  * Grant-backed sessions return `undefined`.
1652
1716
  *
1653
1717
  * @returns {CookieSession|undefined}
1718
+ * @deprecated Use `session.grant` and `GrantSession` instead.
1654
1719
  */
1655
1720
  readonly cookie: CookieSession | undefined;
1656
1721
  /**
@@ -1704,94 +1769,123 @@ export class SessionInfo {
1704
1769
 
1705
1770
  /**
1706
1771
  * Read/write storage scoped to **your** session (absolute paths: `/pub/...` or `/priv/...`).
1772
+ *
1773
+ * Failures reject with a {@link PubkyError}. Path validation, transport, and HTTP
1774
+ * failures use `RequestError`; only HTTP errors include `data.statusCode`.
1775
+ * URL parsing failures use `InvalidInput`. Credential preparation, refresh,
1776
+ * and reading response bodies can also fail.
1777
+ *
1778
+ * Only {@link SessionStorage.exists} and {@link SessionStorage.stats} treat
1779
+ * HTTP 404/410 as missing. Other HTTP failures, including 401/403 and 5xx, reject.
1780
+ * Writes require write permission and can fail on directory targets (400),
1781
+ * file/directory path conflicts (409), or exceeded quotas (507).
1707
1782
  */
1708
1783
  export class SessionStorage {
1709
1784
  private constructor();
1710
1785
  free(): void;
1711
1786
  [Symbol.dispose](): void;
1712
1787
  /**
1713
- * Delete a path (file or empty directory).
1788
+ * Delete a file. Directory targets are unsupported.
1714
1789
  *
1715
- * @param {Path} path
1790
+ * @param {Path} path File path; must not end with `/`.
1716
1791
  * @returns {Promise<void>}
1792
+ * @throws {PubkyError} Missing file (404), directory target (400), or shared errors
1793
+ * (see {@link SessionStorage}).
1717
1794
  */
1718
1795
  delete(path: Path): Promise<void>;
1719
1796
  /**
1720
- * Check existence.
1797
+ * Check existence with a HEAD request.
1721
1798
  *
1722
1799
  * @param {Path} path
1723
- * @returns {Promise<boolean>}
1800
+ * @returns {Promise<boolean>} `true` on success; `false` for HTTP 404/410.
1801
+ * @throws {PubkyError} All other failures (see {@link SessionStorage}).
1724
1802
  */
1725
1803
  exists(path: Path): Promise<boolean>;
1726
- /**
1727
- * GET a streaming response for an absolute session path.
1728
- *
1729
- * @param {Path} path
1730
- * @returns {Promise<Response>}
1731
- */
1732
- get(path: Path): Promise<Response>;
1733
1804
  /**
1734
1805
  * GET bytes from an absolute session path.
1735
1806
  *
1736
1807
  * @param {Path} path
1737
- * @returns {Promise<Uint8Array>}
1808
+ * @returns {Promise<Uint8Array>} The complete response body.
1809
+ * @throws {PubkyError} Missing resource (404/410) or shared errors (see {@link SessionStorage}).
1738
1810
  */
1739
1811
  getBytes(path: Path): Promise<Uint8Array>;
1740
1812
  /**
1741
1813
  * GET JSON from an absolute session path.
1742
1814
  *
1743
1815
  * @param {Path} path
1744
- * @returns {Promise<any>}
1816
+ * @returns {Promise<any>} The parsed JSON value.
1817
+ * @throws {PubkyError} Missing resource (404/410), JSON parsing/conversion failures,
1818
+ * or shared errors (see {@link SessionStorage}).
1745
1819
  */
1746
1820
  getJson(path: Path): Promise<any>;
1747
1821
  /**
1748
1822
  * GET text from an absolute session path.
1749
1823
  *
1750
1824
  * @param {Path} path
1751
- * @returns {Promise<string>}
1825
+ * @returns {Promise<string>} The complete response body decoded as text.
1826
+ * @throws {PubkyError} Missing resource (404/410) or shared errors (see {@link SessionStorage}).
1752
1827
  */
1753
1828
  getText(path: Path): Promise<string>;
1754
1829
  /**
1755
- * List a directory (absolute session path). Returns `pubky://…` URLs.
1830
+ * GET a streaming response for an absolute session path.
1831
+ *
1832
+ * Reading the returned response body can still fail after this resolves.
1833
+ *
1834
+ * @param {Path} path
1835
+ * @returns {Promise<Response>} A successful response with an unread body.
1836
+ * @throws {PubkyError} Missing resource (404/410) or other request/response errors.
1837
+ * See {@link SessionStorage} for shared errors.
1838
+ */
1839
+ get(path: Path): Promise<Response>;
1840
+ /**
1841
+ * List a directory (absolute session path).
1756
1842
  *
1757
1843
  * @param {Path} path Must end with `/`.
1758
- * @param {string|null=} cursor Optional suffix or full URL to start **after**.
1844
+ * @param {string|null=} cursor Optional last entry URL to start **after**.
1759
1845
  * @param {boolean=} reverse Default `false`.
1760
1846
  * @param {number=} limit Optional result limit.
1761
1847
  * @param {boolean=} shallow Default `false`.
1762
- * @returns {Promise<string[]>}
1848
+ * @returns {Promise<string[]>} `pubky://…` entry URLs, or an empty array for an empty page.
1849
+ * @throws {PubkyError} Missing directory (404), invalid cursor (400), invalid response
1850
+ * entries, or shared errors (see {@link SessionStorage}).
1763
1851
  */
1764
1852
  list(path: Path, cursor?: string | null, reverse?: boolean | null, limit?: number | null, shallow?: boolean | null): Promise<string[]>;
1765
1853
  /**
1766
- * PUT binary at an absolute session path.
1854
+ * Create or replace a file with binary data at an absolute session path.
1767
1855
  *
1768
- * @param {Path} path
1769
- * @param {Uint8Array} bytes
1856
+ * @param {Path} path File path; must not end with `/`.
1857
+ * @param {Uint8Array} body
1770
1858
  * @returns {Promise<void>}
1859
+ * @throws {PubkyError} Upload or shared write/request errors (see {@link SessionStorage}).
1771
1860
  */
1772
1861
  putBytes(path: Path, body: Uint8Array): Promise<void>;
1773
1862
  /**
1774
- * PUT JSON at an absolute session path.
1863
+ * Create or replace a file with JSON at an absolute session path.
1775
1864
  *
1776
- * @param {Path} path Absolute path (e.g. `"/pub/app/data.json"`).
1777
- * @param {any} value JSON-serializable value.
1865
+ * @param {Path} path File path (e.g. `"/pub/app/data.json"`); must not end with `/`.
1866
+ * @param {any} body JSON-serializable value.
1778
1867
  * @returns {Promise<void>}
1868
+ * @throws {PubkyError} `InvalidInput` if `body` cannot be converted to JSON;
1869
+ * otherwise serialization, upload, or shared write/request errors (see {@link SessionStorage}).
1779
1870
  */
1780
1871
  putJson(path: Path, body: any): Promise<void>;
1781
1872
  /**
1782
- * PUT text at an absolute session path.
1873
+ * Create or replace a file with text at an absolute session path.
1783
1874
  *
1784
- * @param {Path} path
1785
- * @param {string} text
1875
+ * @param {Path} path File path; must not end with `/`.
1876
+ * @param {string} body
1786
1877
  * @returns {Promise<void>}
1878
+ * @throws {PubkyError} Upload or shared write/request errors (see {@link SessionStorage}).
1787
1879
  */
1788
1880
  putText(path: Path, body: string): Promise<void>;
1789
1881
  /**
1790
1882
  * Get metadata for an absolute, session-scoped path (e.g. `"/pub/app/file.json"`).
1791
1883
  *
1884
+ * On success, missing or unparseable metadata headers leave their properties absent.
1885
+ *
1792
1886
  * @param {Path} path Absolute path under your user (starts with `/`).
1793
- * @returns {Promise<ResourceStats|undefined>} `undefined` if the resource does not exist.
1794
- * @throws {PubkyError} On invalid input or transport/server errors.
1887
+ * @returns {Promise<ResourceStats|undefined>} Metadata on success; `undefined` for HTTP 404/410.
1888
+ * @throws {PubkyError} All other failures (see {@link SessionStorage}).
1795
1889
  */
1796
1890
  stats(path: Path): Promise<ResourceStats | undefined>;
1797
1891
  }
@@ -1826,39 +1920,45 @@ export class Signer {
1826
1920
  */
1827
1921
  handleDeepLink(pubkyauth_url: string): Promise<void>;
1828
1922
  /**
1829
- * Fast sign-in for a returning user. Publishes PKDNS in the background.
1923
+ * Blocking sign-in. Waits for PKDNS publish to complete (slower; safer).
1830
1924
  *
1831
1925
  * Creates a valid grant-backed homeserver Session with root capabilities.
1832
1926
  * `clientId` is shown in the user's grant/session list.
1833
1927
  * @param {string} clientId App identifier, typically a domain.
1834
1928
  *
1835
1929
  * @returns {Promise<Session>}
1930
+ */
1931
+ signinBlocking(client_id: string): Promise<Session>;
1932
+ /**
1933
+ * Legacy cookie blocking signin. Prefer `signinBlocking(clientId)`.
1836
1934
  *
1837
- * @throws {PubkyError}
1935
+ * @deprecated Prefer `signinBlocking(clientId)`.
1838
1936
  */
1839
- signin(client_id: string): Promise<Session>;
1937
+ signinCookieBlocking(): Promise<Session>;
1840
1938
  /**
1841
- * Blocking sign-in. Waits for PKDNS publish to complete (slower; safer).
1939
+ * Legacy cookie signin. Prefer `signin(clientId)`.
1940
+ *
1941
+ * @deprecated Prefer `signin(clientId)`.
1942
+ */
1943
+ signinCookie(): Promise<Session>;
1944
+ /**
1945
+ * Fast sign-in for a returning user. Publishes PKDNS in the background.
1842
1946
  *
1843
1947
  * Creates a valid grant-backed homeserver Session with root capabilities.
1844
1948
  * `clientId` is shown in the user's grant/session list.
1845
1949
  * @param {string} clientId App identifier, typically a domain.
1846
1950
  *
1847
1951
  * @returns {Promise<Session>}
1848
- */
1849
- signinBlocking(client_id: string): Promise<Session>;
1850
- /**
1851
- * Legacy cookie signin. Prefer `signin(clientId)`.
1852
1952
  *
1853
- * @deprecated Prefer `signin(clientId)`.
1953
+ * @throws {PubkyError}
1854
1954
  */
1855
- signinCookie(): Promise<Session>;
1955
+ signin(client_id: string): Promise<Session>;
1856
1956
  /**
1857
- * Legacy cookie blocking signin. Prefer `signinBlocking(clientId)`.
1957
+ * Legacy cookie signup. Prefer `signup()` plus `signin(clientId)`.
1858
1958
  *
1859
- * @deprecated Prefer `signinBlocking(clientId)`.
1959
+ * @deprecated Prefer `signup()` followed by `signin(clientId)`.
1860
1960
  */
1861
- signinCookieBlocking(): Promise<Session>;
1961
+ signupCookie(homeserver: PublicKey, signup_token?: string | null): Promise<Session>;
1862
1962
  /**
1863
1963
  * Sign up at a homeserver.
1864
1964
  *
@@ -1873,12 +1973,6 @@ export class Signer {
1873
1973
  * - `RequestError` (network/server)
1874
1974
  */
1875
1975
  signup(homeserver: PublicKey, signup_token?: string | null): Promise<void>;
1876
- /**
1877
- * Legacy cookie signup. Prefer `signup()` plus `signin(clientId)`.
1878
- *
1879
- * @deprecated Prefer `signup()` followed by `signin(clientId)`.
1880
- */
1881
- signupCookie(homeserver: PublicKey, signup_token?: string | null): Promise<Session>;
1882
1976
  /**
1883
1977
  * Get a PKDNS actor bound to this signer's client & keypair (publishing enabled).
1884
1978
  *
@@ -2113,7 +2207,7 @@ export class StoredSessionInfo {
2113
2207
  * Resolve a `pubky://` or `pubky<pk>/…` identifier into the homeserver transport URL.
2114
2208
  *
2115
2209
  * @param {string} identifier Either `pubky<pk>/...` (preferred) or `pubky://<pk>/...`.
2116
- * @returns {string} HTTPS URL in the form `https://_pubky.<pk>/...`.
2210
+ * @returns {string} HTTPS URL in the form `https://_pubky.<pk>/storage/<pk>/...`.
2117
2211
  */
2118
2212
  export function resolvePubky(identifier: string): string;
2119
2213