techne-sdk 0.3.8 → 0.5.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.
Files changed (56) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/README.md +3 -1
  3. package/dist/auth/account.d.ts +67 -0
  4. package/dist/auth/account.js +136 -0
  5. package/dist/auth/hosts.d.ts +4 -0
  6. package/dist/auth/hosts.js +4 -0
  7. package/dist/auth/index.d.ts +30 -5
  8. package/dist/auth/index.js +80 -12
  9. package/dist/catalog/catalog.gen.js +1332 -205
  10. package/dist/generated/index.d.ts +9 -0
  11. package/dist/generated/index.js +27 -0
  12. package/dist/generated/lexicons.d.ts +1797 -227
  13. package/dist/generated/lexicons.js +1147 -224
  14. package/dist/generated/nsid.d.ts +16 -0
  15. package/dist/generated/nsid.js +16 -0
  16. package/dist/generated/nsid.json +16 -0
  17. package/dist/generated/types/pub/techne/draft/commons/moveAccountHandle.d.ts +3 -0
  18. package/dist/generated/types/pub/techne/draft/commons/moveAccountHandle.js +7 -0
  19. package/dist/generated/types/pub/techne/draft/identity/attest.d.ts +5 -0
  20. package/dist/generated/types/pub/techne/draft/identity/attest.js +7 -0
  21. package/dist/generated/types/pub/techne/draft/identity/beginAddMethod.d.ts +3 -0
  22. package/dist/generated/types/pub/techne/draft/identity/beginAddMethod.js +7 -0
  23. package/dist/generated/types/pub/techne/draft/identity/cancelPendingChange.d.ts +29 -0
  24. package/dist/generated/types/pub/techne/draft/identity/cancelPendingChange.js +27 -0
  25. package/dist/generated/types/pub/techne/draft/identity/defs.d.ts +41 -7
  26. package/dist/generated/types/pub/techne/draft/identity/defs.js +14 -0
  27. package/dist/generated/types/pub/techne/draft/identity/finishAddMethod.d.ts +9 -0
  28. package/dist/generated/types/pub/techne/draft/identity/finishAddMethod.js +14 -0
  29. package/dist/generated/types/pub/techne/draft/identity/fold.d.ts +3 -0
  30. package/dist/generated/types/pub/techne/draft/identity/fold.js +7 -0
  31. package/dist/generated/types/pub/techne/draft/identity/holdForPhone.d.ts +1 -1
  32. package/dist/generated/types/pub/techne/draft/identity/link.d.ts +3 -0
  33. package/dist/generated/types/pub/techne/draft/identity/link.js +7 -0
  34. package/dist/generated/types/pub/techne/draft/identity/listMethods.d.ts +7 -1
  35. package/dist/generated/types/pub/techne/draft/identity/manageMethods.d.ts +267 -0
  36. package/dist/generated/types/pub/techne/draft/identity/manageMethods.js +265 -0
  37. package/dist/generated/types/pub/techne/draft/identity/openAccountPage.d.ts +40 -0
  38. package/dist/generated/types/pub/techne/draft/identity/openAccountPage.js +55 -0
  39. package/dist/generated/types/pub/techne/draft/identity/resolve.d.ts +4 -0
  40. package/dist/generated/types/pub/techne/draft/identity/unlinkMethod.d.ts +6 -0
  41. package/dist/generated/types/pub/techne/draft/identity/unlinkMethod.js +7 -0
  42. package/dist/generated/types/pub/techne/draft/permissioned/putRecords.d.ts +2 -2
  43. package/dist/generated/types/pub/techne/draft/query/getRecords.d.ts +11 -0
  44. package/dist/generated/types/pub/techne/draft/query/getRecords.js +7 -0
  45. package/dist/generated/types/pub/techne/draft/registry/blockIndex.d.ts +7 -1
  46. package/dist/generated/types/pub/techne/draft/registry/blockIndex.js +17 -3
  47. package/dist/generated/types/pub/techne/draft/registry/purgeType.d.ts +7 -1
  48. package/dist/generated/types/pub/techne/draft/registry/purgeType.js +17 -3
  49. package/dist/query/compose.d.ts +1 -1
  50. package/dist/query/compose.js +1 -1
  51. package/dist/query/index.d.ts +7 -0
  52. package/dist/query/index.js +28 -1
  53. package/dist/versions/react.js +19 -6
  54. package/dist/wasm/techne-wasm.gen.js +1 -1
  55. package/dist/wasm/techne-wasm2js.gen.js +8361 -8359
  56. package/package.json +2 -1
@@ -21,6 +21,11 @@ export class LastMethodError extends XRPCError {
21
21
  super(src.status, src.error, src.message, src.headers, { cause: src });
22
22
  }
23
23
  }
24
+ export class RecoveryProtectedError extends XRPCError {
25
+ constructor(src) {
26
+ super(src.status, src.error, src.message, src.headers, { cause: src });
27
+ }
28
+ }
24
29
  export function toKnownErr(e) {
25
30
  if (e instanceof XRPCError) {
26
31
  if (e.error === 'AuthenticationRequired')
@@ -29,6 +34,8 @@ export function toKnownErr(e) {
29
34
  return new NotFoundError(e);
30
35
  if (e.error === 'LastMethod')
31
36
  return new LastMethodError(e);
37
+ if (e.error === 'RecoveryProtected')
38
+ return new RecoveryProtectedError(e);
32
39
  }
33
40
  return e;
34
41
  }
@@ -79,8 +79,8 @@ export declare function validateWriteResult<V>(v: V): ValidationResult<WriteResu
79
79
  /** A write refused, and nothing of it written: the error putRecord would have answered. */
80
80
  export interface WriteError {
81
81
  $type?: 'pub.techne.draft.permissioned.putRecords#writeError';
82
- /** InvalidRequest (malformed, a body that fails its collection's published lexicon, or a record over 2 MiB, more than a putRecord body may be), InvalidSwap (swapCid did not match the current version), Conflict (the same key holds a public record in the caller's repo, or a concurrent write replaced this version before it was recorded), IdentityConflict (the write would change a contact's identity, which writing again never fixes; see putRecord), DuplicatePhone (a contact write introduces a number another of the caller's active contacts carries; see putRecord) or Forbidden (the call's `space:` scopes do not cover the write, or it replaces a record already written for an app's space and the caller is neither the app its key names nor holds `space:` scopes covering it; see putRecord). */
83
- error: 'InvalidRequest' | 'InvalidSwap' | 'Conflict' | 'IdentityConflict' | 'DuplicatePhone' | (string & {});
82
+ /** InvalidRequest (malformed, a body that fails its collection's published lexicon, or a record over 2 MiB, more than a putRecord body may be), InvalidSwap (swapCid did not match the current version), Conflict (the same key holds a public record in the caller's repo, or a concurrent write replaced this version before it was recorded), IdentityConflict (the write would change a contact's identity, which writing again never fixes; see putRecord), DuplicatePhone (a contact write introduces a number another of the caller's active contacts carries; see putRecord), RateLimitExceeded (a contact write that binds a number to an account found the caller's phone lookups spent; retry it in a minute) or Forbidden (the call's `space:` scopes do not cover the write, or it replaces a record already written for an app's space and the caller is neither the app its key names nor holds `space:` scopes covering it; see putRecord). */
83
+ error: 'InvalidRequest' | 'InvalidSwap' | 'Conflict' | 'IdentityConflict' | 'DuplicatePhone' | 'RateLimitExceeded' | 'Forbidden' | (string & {});
84
84
  message: string;
85
85
  }
86
86
  export declare function isWriteError<V>(v: V): v is import("../../../../../util.js").$TypedObject<V, "pub.techne.draft.permissioned.putRecords", "writeError">;
@@ -48,9 +48,20 @@ export interface Handle {
48
48
  $type?: 'pub.techne.draft.query.getRecords#handle';
49
49
  did: string;
50
50
  handle: string;
51
+ /** The other accounts linked to this one now (the same person; links are public, alsoKnownAs on both DIDs). Absent when none, and while a sign-in method of any account of the person is frozen (a freeze pauses the link). A linked account that is not active or is suspended is left out. */
52
+ linked?: LinkedHandle[];
51
53
  }
52
54
  export declare function isHandle<V>(v: V): v is import("../../../../../util.js").$TypedObject<V, "pub.techne.draft.query.getRecords", "handle">;
53
55
  export declare function validateHandle<V>(v: V): ValidationResult<Handle & V>;
56
+ export interface LinkedHandle {
57
+ $type?: 'pub.techne.draft.query.getRecords#linkedHandle';
58
+ did: string;
59
+ handle?: string;
60
+ /** The linked account's public profile name, when it has one. */
61
+ displayName?: string;
62
+ }
63
+ export declare function isLinkedHandle<V>(v: V): v is import("../../../../../util.js").$TypedObject<V, "pub.techne.draft.query.getRecords", "linkedHandle">;
64
+ export declare function validateLinkedHandle<V>(v: V): ValidationResult<LinkedHandle & V>;
54
65
  export interface Resolved {
55
66
  $type?: 'pub.techne.draft.query.getRecords#resolved';
56
67
  /** The URI asked. */
@@ -25,6 +25,13 @@ export function isHandle(v) {
25
25
  export function validateHandle(v) {
26
26
  return validate(v, id, hashHandle);
27
27
  }
28
+ const hashLinkedHandle = 'linkedHandle';
29
+ export function isLinkedHandle(v) {
30
+ return is$typed(v, id, hashLinkedHandle);
31
+ }
32
+ export function validateLinkedHandle(v) {
33
+ return validate(v, id, hashLinkedHandle);
34
+ }
28
35
  const hashResolved = 'resolved';
29
36
  export function isResolved(v) {
30
37
  return is$typed(v, id, hashResolved);
@@ -33,10 +33,16 @@ export interface Response {
33
33
  export declare class AuthenticationRequiredError extends XRPCError {
34
34
  constructor(src: XRPCError);
35
35
  }
36
- export declare class ForbiddenError extends XRPCError {
36
+ export declare class NotAuthorizedError extends XRPCError {
37
+ constructor(src: XRPCError);
38
+ }
39
+ export declare class ProgramRefusedError extends XRPCError {
37
40
  constructor(src: XRPCError);
38
41
  }
39
42
  export declare class UnknownTypeError extends XRPCError {
40
43
  constructor(src: XRPCError);
41
44
  }
45
+ export declare class InvalidRequestError extends XRPCError {
46
+ constructor(src: XRPCError);
47
+ }
42
48
  export declare function toKnownErr(e: any): any;
@@ -11,7 +11,12 @@ export class AuthenticationRequiredError extends XRPCError {
11
11
  super(src.status, src.error, src.message, src.headers, { cause: src });
12
12
  }
13
13
  }
14
- export class ForbiddenError extends XRPCError {
14
+ export class NotAuthorizedError extends XRPCError {
15
+ constructor(src) {
16
+ super(src.status, src.error, src.message, src.headers, { cause: src });
17
+ }
18
+ }
19
+ export class ProgramRefusedError extends XRPCError {
15
20
  constructor(src) {
16
21
  super(src.status, src.error, src.message, src.headers, { cause: src });
17
22
  }
@@ -21,14 +26,23 @@ export class UnknownTypeError extends XRPCError {
21
26
  super(src.status, src.error, src.message, src.headers, { cause: src });
22
27
  }
23
28
  }
29
+ export class InvalidRequestError extends XRPCError {
30
+ constructor(src) {
31
+ super(src.status, src.error, src.message, src.headers, { cause: src });
32
+ }
33
+ }
24
34
  export function toKnownErr(e) {
25
35
  if (e instanceof XRPCError) {
26
36
  if (e.error === 'AuthenticationRequired')
27
37
  return new AuthenticationRequiredError(e);
28
- if (e.error === 'Forbidden')
29
- return new ForbiddenError(e);
38
+ if (e.error === 'NotAuthorized')
39
+ return new NotAuthorizedError(e);
40
+ if (e.error === 'ProgramRefused')
41
+ return new ProgramRefusedError(e);
30
42
  if (e.error === 'UnknownType')
31
43
  return new UnknownTypeError(e);
44
+ if (e.error === 'InvalidRequest')
45
+ return new InvalidRequestError(e);
32
46
  }
33
47
  return e;
34
48
  }
@@ -30,10 +30,16 @@ export interface Response {
30
30
  export declare class AuthenticationRequiredError extends XRPCError {
31
31
  constructor(src: XRPCError);
32
32
  }
33
- export declare class ForbiddenError extends XRPCError {
33
+ export declare class NotAuthorizedError extends XRPCError {
34
+ constructor(src: XRPCError);
35
+ }
36
+ export declare class ProgramRefusedError extends XRPCError {
34
37
  constructor(src: XRPCError);
35
38
  }
36
39
  export declare class UnknownTypeError extends XRPCError {
37
40
  constructor(src: XRPCError);
38
41
  }
42
+ export declare class InvalidRequestError extends XRPCError {
43
+ constructor(src: XRPCError);
44
+ }
39
45
  export declare function toKnownErr(e: any): any;
@@ -11,7 +11,12 @@ export class AuthenticationRequiredError extends XRPCError {
11
11
  super(src.status, src.error, src.message, src.headers, { cause: src });
12
12
  }
13
13
  }
14
- export class ForbiddenError extends XRPCError {
14
+ export class NotAuthorizedError extends XRPCError {
15
+ constructor(src) {
16
+ super(src.status, src.error, src.message, src.headers, { cause: src });
17
+ }
18
+ }
19
+ export class ProgramRefusedError extends XRPCError {
15
20
  constructor(src) {
16
21
  super(src.status, src.error, src.message, src.headers, { cause: src });
17
22
  }
@@ -21,14 +26,23 @@ export class UnknownTypeError extends XRPCError {
21
26
  super(src.status, src.error, src.message, src.headers, { cause: src });
22
27
  }
23
28
  }
29
+ export class InvalidRequestError extends XRPCError {
30
+ constructor(src) {
31
+ super(src.status, src.error, src.message, src.headers, { cause: src });
32
+ }
33
+ }
24
34
  export function toKnownErr(e) {
25
35
  if (e instanceof XRPCError) {
26
36
  if (e.error === 'AuthenticationRequired')
27
37
  return new AuthenticationRequiredError(e);
28
- if (e.error === 'Forbidden')
29
- return new ForbiddenError(e);
38
+ if (e.error === 'NotAuthorized')
39
+ return new NotAuthorizedError(e);
40
+ if (e.error === 'ProgramRefused')
41
+ return new ProgramRefusedError(e);
30
42
  if (e.error === 'UnknownType')
31
43
  return new UnknownTypeError(e);
44
+ if (e.error === 'InvalidRequest')
45
+ return new InvalidRequestError(e);
32
46
  }
33
47
  return e;
34
48
  }
@@ -224,7 +224,7 @@ export declare class Composed {
224
224
  * than the platform reads in one step, and this throws (`<who>: step <name> matched more than …`) rather than
225
225
  * answer part of the list. */
226
226
  whole<V = Record<string, unknown>, E extends EnvelopeField = EnvelopeField, U extends boolean = true>(step: StepRef<'list', true, E, U>, who: string): StepRecord<V, E, U>[];
227
- /** A get step's answer as `getRecordsAnswer` gives it: records by URI, withheld, handles, curation, defaults.
227
+ /** A get step's answer as `getRecordsAnswer` gives it: records by URI, withheld, handles, linked, curation, defaults.
228
228
  * Only a step that keeps its records' `uri`. */
229
229
  answer<V = Record<string, unknown>, E extends EnvelopeField = EnvelopeField>(step: StepRef<'get', true, E, true>): StepAnswer<V, E>;
230
230
  /** A step's records in the order answered, list or get: the read for a step asked `uri: false`, whose records
@@ -316,7 +316,7 @@ export class Composed {
316
316
  throw new Error(`${who}: step ${step.name} matched more than ${MAX_STEP_LIMIT} records`);
317
317
  return page.records;
318
318
  }
319
- /** A get step's answer as `getRecordsAnswer` gives it: records by URI, withheld, handles, curation, defaults.
319
+ /** A get step's answer as `getRecordsAnswer` gives it: records by URI, withheld, handles, linked, curation, defaults.
320
320
  * Only a step that keeps its records' `uri`. */
321
321
  answer(step) {
322
322
  const s = this.#raw(step.name);
@@ -189,6 +189,10 @@ export declare function curationOf(c: unknown): Curation | undefined;
189
189
  /** A handle fit to show, trimmed: `undefined` when there is none, or when it is `handle.invalid` (any case),
190
190
  * what atproto reports for an account whose handle does not verify, which names no one. */
191
191
  export declare function shownHandle(handle: string | null | undefined): string | undefined;
192
+ /** Another account of the same person as a handle entry's (Linking v2: accounts linked on the identity PDS are
193
+ * one person on the platform): its DID, and its public handle (never `handle.invalid`, see {@link shownHandle})
194
+ * and profile name when it has them. The generated `getRecords#linkedHandle`. */
195
+ export type LinkedAccount = Omit<GetRecords.LinkedHandle, '$type'>;
192
196
  /** {@link getRecords}'s records, and the asked URIs moderation withheld from this caller. */
193
197
  export interface RecordsAnswer<V = Record<string, unknown>> {
194
198
  records: Map<string, QueryRecord<V>>;
@@ -196,6 +200,9 @@ export interface RecordsAnswer<V = Record<string, unknown>> {
196
200
  /** Asked with `{ handles: true }`: each named repo's public handle, by DID (empty otherwise; never
197
201
  * `handle.invalid`, see {@link shownHandle}). */
198
202
  handles: Map<string, string>;
203
+ /** Asked with `{ handles: true }`: the other accounts of each named repo's person, by DID, from each handle
204
+ * entry's `linked` (only DIDs that have some; empty otherwise, and from a platform that does not send it). */
205
+ linked: Map<string, LinkedAccount[]>;
199
206
  /** Asked with `{ curation: true }`, signed in: the curation status of each asked URI that is the
200
207
  * caller's own, by URI (empty otherwise, and for anyone else's record or a private one). */
201
208
  curation: Map<string, Curation>;
@@ -150,6 +150,26 @@ export function shownHandle(handle) {
150
150
  const h = handle?.trim();
151
151
  return h && h.toLowerCase() !== 'handle.invalid' ? h : undefined;
152
152
  }
153
+ /** A `getRecords#handle` entry's `linked` list as {@link LinkedAccount}s: malformed entries, the entry's own DID
154
+ * and repeats left out. */
155
+ function linkedAccountsOf(list, self) {
156
+ if (!Array.isArray(list))
157
+ return [];
158
+ const seen = new Set([self]);
159
+ const out = [];
160
+ for (const v of list) {
161
+ if (!v || typeof v !== 'object')
162
+ continue;
163
+ const { did, handle, displayName } = v;
164
+ if (typeof did !== 'string' || !did || seen.has(did))
165
+ continue;
166
+ seen.add(did);
167
+ const shown = typeof handle === 'string' ? shownHandle(handle) : undefined;
168
+ const name = typeof displayName === 'string' ? displayName.trim() : '';
169
+ out.push({ did, ...(shown ? { handle: shown } : {}), ...(name ? { displayName: name } : {}) });
170
+ }
171
+ return out;
172
+ }
153
173
  /** The records at `uris` the viewer may read, by URI, and which of the asked URIs were withheld. With
154
174
  * `handles`, also the public handle of each repo the URIs name; with `curation`, the curation status
155
175
  * of each asked URI that is the signed-in caller's own (no extra read: the same call answers it).
@@ -168,15 +188,22 @@ export async function getRecordsAnswer(read, uris, opts = {}) {
168
188
  /** One or more `getRecords` pages (or a composed get step's answer) as a {@link RecordsAnswer}. */
169
189
  export function answerOf(pages) {
170
190
  const handles = new Map();
191
+ const linked = new Map();
171
192
  for (const h of pages.flatMap((p) => (Array.isArray(p.handles) ? p.handles : []))) {
172
- const handle = typeof h?.did === 'string' && typeof h.handle === 'string' ? shownHandle(h.handle) : undefined;
193
+ if (typeof h?.did !== 'string')
194
+ continue;
195
+ const handle = typeof h.handle === 'string' ? shownHandle(h.handle) : undefined;
173
196
  if (handle)
174
197
  handles.set(h.did, handle);
198
+ const others = linkedAccountsOf(h.linked, h.did);
199
+ if (others.length)
200
+ linked.set(h.did, others);
175
201
  }
176
202
  return {
177
203
  records: new Map(pages.flatMap((p) => p.records).map((r) => [r.uri, r])),
178
204
  withheld: new Set(pages.flatMap((p) => (Array.isArray(p.withheld) ? p.withheld : []))),
179
205
  handles,
206
+ linked,
180
207
  curation: new Map(pages
181
208
  .flatMap((p) => (Array.isArray(p.curation) ? p.curation : []))
182
209
  .map(curationOf)
@@ -40,20 +40,33 @@ export function useEvent(uri, options = {}) {
40
40
  useEffect(() => {
41
41
  loadRef.current = load;
42
42
  });
43
+ // Reads are numbered; an answer lands only when it is newer than the last one shown (`shown`), so the
44
+ // newest answer wins. `reload()` does not drop a read still in flight: a caller that reloads faster than
45
+ // the network answers would otherwise never see one. A uri (or data mode) change raises the floor to the
46
+ // last read sent, so nothing read for the previous uri ever lands. That effect is declared before the
47
+ // read's, so on a uri change the floor is raised before the new uri's read is numbered.
48
+ const sent = useRef(0);
49
+ const shown = useRef(0);
50
+ useEffect(() => {
51
+ shown.current = sent.current;
52
+ }, [uri, dataMode]);
43
53
  useEffect(() => {
44
54
  const read = loadRef.current;
45
55
  if (!uri || !read || dataMode)
46
56
  return;
47
- let live = true;
57
+ const seq = ++sent.current;
58
+ const landed = () => {
59
+ if (seq <= shown.current)
60
+ return false;
61
+ shown.current = seq;
62
+ return true;
63
+ };
48
64
  read(uri).then((out) => {
49
- if (!live)
65
+ if (!landed())
50
66
  return;
51
67
  setLoaded({ uri, out });
52
68
  setFailed(null);
53
- }, (e) => live && setFailed({ uri, error: e }));
54
- return () => {
55
- live = false;
56
- };
69
+ }, (e) => landed() && setFailed({ uri, error: e }));
57
70
  }, [uri, dataMode, reads]);
58
71
  const data = dataMode ? given ?? null : loaded && loaded.uri === uri ? loaded.out : null;
59
72
  const error = !dataMode && failed && failed.uri === uri ? failed.error : null;