@atproto/lex-client 0.0.11 → 0.0.13

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 (71) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/agent.d.ts +67 -0
  3. package/dist/agent.d.ts.map +1 -1
  4. package/dist/agent.js +31 -0
  5. package/dist/agent.js.map +1 -1
  6. package/dist/client.d.ts +443 -45
  7. package/dist/client.d.ts.map +1 -1
  8. package/dist/client.js +145 -1
  9. package/dist/client.js.map +1 -1
  10. package/dist/errors.d.ts +162 -9
  11. package/dist/errors.d.ts.map +1 -1
  12. package/dist/errors.js +132 -8
  13. package/dist/errors.js.map +1 -1
  14. package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts +29 -25
  15. package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts.map +1 -1
  16. package/dist/lexicons/com/atproto/repo/createRecord.defs.js +3 -2
  17. package/dist/lexicons/com/atproto/repo/createRecord.defs.js.map +1 -1
  18. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts +17 -17
  19. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts.map +1 -1
  20. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js.map +1 -1
  21. package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts +9 -9
  22. package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts.map +1 -1
  23. package/dist/lexicons/com/atproto/repo/getRecord.defs.js +1 -1
  24. package/dist/lexicons/com/atproto/repo/getRecord.defs.js.map +1 -1
  25. package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts +8 -8
  26. package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts.map +1 -1
  27. package/dist/lexicons/com/atproto/repo/listRecords.defs.js +1 -1
  28. package/dist/lexicons/com/atproto/repo/listRecords.defs.js.map +1 -1
  29. package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts +31 -27
  30. package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts.map +1 -1
  31. package/dist/lexicons/com/atproto/repo/putRecord.defs.js +3 -2
  32. package/dist/lexicons/com/atproto/repo/putRecord.defs.js.map +1 -1
  33. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts +7 -7
  34. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts.map +1 -1
  35. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js.map +1 -1
  36. package/dist/lexicons/com/atproto/sync/getBlob.defs.d.ts +3 -3
  37. package/dist/lexicons/com/atproto/sync/getBlob.defs.d.ts.map +1 -1
  38. package/dist/lexicons/com/atproto/sync/getBlob.defs.js.map +1 -1
  39. package/dist/response.d.ts +14 -4
  40. package/dist/response.d.ts.map +1 -1
  41. package/dist/response.js +19 -9
  42. package/dist/response.js.map +1 -1
  43. package/dist/types.d.ts +51 -0
  44. package/dist/types.d.ts.map +1 -1
  45. package/dist/types.js.map +1 -1
  46. package/dist/util.d.ts +40 -5
  47. package/dist/util.d.ts.map +1 -1
  48. package/dist/util.js +22 -0
  49. package/dist/util.js.map +1 -1
  50. package/dist/www-authenticate.d.ts +23 -0
  51. package/dist/www-authenticate.d.ts.map +1 -1
  52. package/dist/www-authenticate.js.map +1 -1
  53. package/dist/xrpc.d.ts +81 -1
  54. package/dist/xrpc.d.ts.map +1 -1
  55. package/dist/xrpc.js.map +1 -1
  56. package/package.json +7 -7
  57. package/src/agent.ts +67 -0
  58. package/src/client.ts +424 -11
  59. package/src/errors.ts +165 -12
  60. package/src/lexicons/com/atproto/repo/createRecord.defs.ts +15 -7
  61. package/src/lexicons/com/atproto/repo/deleteRecord.defs.ts +11 -5
  62. package/src/lexicons/com/atproto/repo/getRecord.defs.ts +7 -4
  63. package/src/lexicons/com/atproto/repo/listRecords.defs.ts +8 -5
  64. package/src/lexicons/com/atproto/repo/putRecord.defs.ts +15 -7
  65. package/src/lexicons/com/atproto/repo/uploadBlob.defs.ts +11 -5
  66. package/src/lexicons/com/atproto/sync/getBlob.defs.ts +6 -3
  67. package/src/response.ts +22 -19
  68. package/src/types.ts +52 -0
  69. package/src/util.ts +50 -5
  70. package/src/www-authenticate.ts +24 -0
  71. package/src/xrpc.ts +83 -4
package/src/agent.ts CHANGED
@@ -1,5 +1,17 @@
1
1
  import { DidString } from '@atproto/lex-schema'
2
2
 
3
+ /**
4
+ * A function that performs HTTP requests towards a service endpoint.
5
+ *
6
+ * The handler is responsible for adding the origin (protocol, hostname, and
7
+ * port) to the provided path, typically based on authentication or service
8
+ * configuration. The handler are also responsible for adding any necessary
9
+ * headers, such as authorization tokens.
10
+ *
11
+ * @param path - The URL path (pathname + query parameters) without the origin
12
+ * @param init - Standard fetch RequestInit options
13
+ * @returns A Promise resolving to the HTTP Response
14
+ */
3
15
  export type FetchHandler = (
4
16
  /**
5
17
  * The URL (pathname + query parameters) to make the request to, without the
@@ -10,8 +22,27 @@ export type FetchHandler = (
10
22
  init: RequestInit,
11
23
  ) => Promise<Response>
12
24
 
25
+ /**
26
+ * Core interface for making XRPC requests.
27
+ *
28
+ * An Agent encapsulates an identity and request handling for AT Protocol
29
+ * operations. It can represent an authenticated user session or an
30
+ * unauthenticated service client.
31
+ *
32
+ * @see {@link buildAgent} for creating (simple) Agent instances.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const agent: Agent = {
37
+ * did: 'did:plc:example123',
38
+ * fetchHandler: (path, init) => fetch(new URL(path, 'https://bsky.social'), init)
39
+ * }
40
+ * ```
41
+ */
13
42
  export interface Agent {
43
+ /** The DID of the authenticated user, or `undefined` if unauthenticated. */
14
44
  readonly did?: DidString
45
+ /** The fetch handler used to make HTTP requests. */
15
46
  fetchHandler: FetchHandler
16
47
  }
17
48
 
@@ -43,8 +74,44 @@ export type AgentConfig = {
43
74
  fetch?: typeof globalThis.fetch
44
75
  }
45
76
 
77
+ /**
78
+ * Options for creating an Agent.
79
+ *
80
+ * Can be a full {@link AgentConfig} object, or a simple service URL string/{@link URL}.
81
+ */
46
82
  export type AgentOptions = AgentConfig | string | URL
47
83
 
84
+ /**
85
+ * Creates an {@link Agent} from various input types.
86
+ *
87
+ * This factory function accepts an existing Agent (returned as-is), a service URL,
88
+ * or a full configuration object. It handles the common case of creating an
89
+ * unauthenticated agent from just a service URL.
90
+ *
91
+ * @param options - Agent instance, configuration object, or service URL
92
+ * @returns A configured Agent ready for making requests
93
+ * @throws {TypeError} If fetch() is not available in the environment
94
+ *
95
+ * @example From URL string
96
+ * ```typescript
97
+ * const agent = buildAgent('https://public.api.bsky.app')
98
+ * ```
99
+ *
100
+ * @example From configuration
101
+ * ```typescript
102
+ * const agent = buildAgent({
103
+ * did: 'did:plc:example',
104
+ * service: 'https://bsky.social',
105
+ * headers: { 'Authorization': 'Bearer ...' }
106
+ * })
107
+ * ```
108
+ *
109
+ * @example Pass-through existing agent
110
+ * ```typescript
111
+ * const existing: Agent = { ... }
112
+ * const agent = buildAgent(existing) // Returns existing unchanged
113
+ * ```
114
+ */
48
115
  export function buildAgent(options: Agent | AgentOptions): Agent {
49
116
  if (typeof options === 'object' && 'fetchHandler' in options) {
50
117
  return options