@atproto/lex-client 0.3.7 → 0.4.2

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 (135) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +4 -3
  3. package/dist/client.d.ts +4 -11
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/client.js +6 -12
  6. package/dist/client.js.map +1 -1
  7. package/dist/index.d.ts +2 -5
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +2 -5
  10. package/dist/index.js.map +1 -1
  11. package/dist/lexicons/com/atproto/repo/applyWrites.d.ts +2 -2
  12. package/dist/lexicons/com/atproto/repo/applyWrites.d.ts.map +1 -1
  13. package/dist/lexicons/com/atproto/repo/applyWrites.defs.d.ts +23 -23
  14. package/dist/lexicons/com/atproto/repo/applyWrites.defs.d.ts.map +1 -1
  15. package/dist/lexicons/com/atproto/repo/applyWrites.defs.js +13 -64
  16. package/dist/lexicons/com/atproto/repo/applyWrites.defs.js.map +1 -1
  17. package/dist/lexicons/com/atproto/repo/applyWrites.js +2 -2
  18. package/dist/lexicons/com/atproto/repo/applyWrites.js.map +1 -1
  19. package/dist/lexicons/com/atproto/repo/createRecord.d.ts +2 -2
  20. package/dist/lexicons/com/atproto/repo/createRecord.d.ts.map +1 -1
  21. package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts +2 -2
  22. package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts.map +1 -1
  23. package/dist/lexicons/com/atproto/repo/createRecord.defs.js +6 -24
  24. package/dist/lexicons/com/atproto/repo/createRecord.defs.js.map +1 -1
  25. package/dist/lexicons/com/atproto/repo/createRecord.js +2 -2
  26. package/dist/lexicons/com/atproto/repo/createRecord.js.map +1 -1
  27. package/dist/lexicons/com/atproto/repo/defs.d.ts +1 -1
  28. package/dist/lexicons/com/atproto/repo/defs.d.ts.map +1 -1
  29. package/dist/lexicons/com/atproto/repo/defs.defs.d.ts +4 -4
  30. package/dist/lexicons/com/atproto/repo/defs.defs.d.ts.map +1 -1
  31. package/dist/lexicons/com/atproto/repo/defs.defs.js +3 -7
  32. package/dist/lexicons/com/atproto/repo/defs.defs.js.map +1 -1
  33. package/dist/lexicons/com/atproto/repo/defs.js +1 -1
  34. package/dist/lexicons/com/atproto/repo/defs.js.map +1 -1
  35. package/dist/lexicons/com/atproto/repo/deleteRecord.d.ts +2 -2
  36. package/dist/lexicons/com/atproto/repo/deleteRecord.d.ts.map +1 -1
  37. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts +2 -2
  38. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts.map +1 -1
  39. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js +6 -19
  40. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js.map +1 -1
  41. package/dist/lexicons/com/atproto/repo/deleteRecord.js +2 -2
  42. package/dist/lexicons/com/atproto/repo/deleteRecord.js.map +1 -1
  43. package/dist/lexicons/com/atproto/repo/getRecord.d.ts +2 -2
  44. package/dist/lexicons/com/atproto/repo/getRecord.d.ts.map +1 -1
  45. package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts +1 -1
  46. package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts.map +1 -1
  47. package/dist/lexicons/com/atproto/repo/getRecord.defs.js +5 -14
  48. package/dist/lexicons/com/atproto/repo/getRecord.defs.js.map +1 -1
  49. package/dist/lexicons/com/atproto/repo/getRecord.js +2 -2
  50. package/dist/lexicons/com/atproto/repo/getRecord.js.map +1 -1
  51. package/dist/lexicons/com/atproto/repo/listRecords.d.ts +2 -2
  52. package/dist/lexicons/com/atproto/repo/listRecords.d.ts.map +1 -1
  53. package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts +5 -5
  54. package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts.map +1 -1
  55. package/dist/lexicons/com/atproto/repo/listRecords.defs.js +5 -22
  56. package/dist/lexicons/com/atproto/repo/listRecords.defs.js.map +1 -1
  57. package/dist/lexicons/com/atproto/repo/listRecords.js +2 -2
  58. package/dist/lexicons/com/atproto/repo/listRecords.js.map +1 -1
  59. package/dist/lexicons/com/atproto/repo/putRecord.d.ts +2 -2
  60. package/dist/lexicons/com/atproto/repo/putRecord.d.ts.map +1 -1
  61. package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts +2 -2
  62. package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts.map +1 -1
  63. package/dist/lexicons/com/atproto/repo/putRecord.defs.js +6 -25
  64. package/dist/lexicons/com/atproto/repo/putRecord.defs.js.map +1 -1
  65. package/dist/lexicons/com/atproto/repo/putRecord.js +2 -2
  66. package/dist/lexicons/com/atproto/repo/putRecord.js.map +1 -1
  67. package/dist/lexicons/com/atproto/repo/uploadBlob.d.ts +2 -2
  68. package/dist/lexicons/com/atproto/repo/uploadBlob.d.ts.map +1 -1
  69. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts +1 -1
  70. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts.map +1 -1
  71. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js +4 -6
  72. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js.map +1 -1
  73. package/dist/lexicons/com/atproto/repo/uploadBlob.js +2 -2
  74. package/dist/lexicons/com/atproto/repo/uploadBlob.js.map +1 -1
  75. package/dist/lexicons/com/atproto/repo.d.ts +8 -8
  76. package/dist/lexicons/com/atproto/repo.d.ts.map +1 -1
  77. package/dist/lexicons/com/atproto/repo.js +8 -8
  78. package/dist/lexicons/com/atproto/repo.js.map +1 -1
  79. package/dist/lexicons/com/atproto/sync/getBlob.d.ts +2 -2
  80. package/dist/lexicons/com/atproto/sync/getBlob.d.ts.map +1 -1
  81. package/dist/lexicons/com/atproto/sync/getBlob.defs.d.ts +1 -1
  82. package/dist/lexicons/com/atproto/sync/getBlob.defs.d.ts.map +1 -1
  83. package/dist/lexicons/com/atproto/sync/getBlob.defs.js +5 -14
  84. package/dist/lexicons/com/atproto/sync/getBlob.defs.js.map +1 -1
  85. package/dist/lexicons/com/atproto/sync/getBlob.js +2 -2
  86. package/dist/lexicons/com/atproto/sync/getBlob.js.map +1 -1
  87. package/dist/lexicons/com/atproto/sync.d.ts +1 -1
  88. package/dist/lexicons/com/atproto/sync.d.ts.map +1 -1
  89. package/dist/lexicons/com/atproto/sync.js +1 -1
  90. package/dist/lexicons/com/atproto/sync.js.map +1 -1
  91. package/dist/lexicons/com/atproto.d.ts +2 -2
  92. package/dist/lexicons/com/atproto.d.ts.map +1 -1
  93. package/dist/lexicons/com/atproto.js +2 -2
  94. package/dist/lexicons/com/atproto.js.map +1 -1
  95. package/dist/lexicons/com.d.ts +1 -1
  96. package/dist/lexicons/com.d.ts.map +1 -1
  97. package/dist/lexicons/com.js +1 -1
  98. package/dist/lexicons/com.js.map +1 -1
  99. package/dist/lexicons/index.d.ts +1 -1
  100. package/dist/lexicons/index.d.ts.map +1 -1
  101. package/dist/lexicons/index.js +1 -1
  102. package/dist/lexicons/index.js.map +1 -1
  103. package/dist/write-operation-builder.d.ts +1 -1
  104. package/dist/write-operation-builder.d.ts.map +1 -1
  105. package/dist/write-operation-builder.js +4 -4
  106. package/dist/write-operation-builder.js.map +1 -1
  107. package/package.json +16 -9
  108. package/dist/agent.d.ts +0 -127
  109. package/dist/agent.d.ts.map +0 -1
  110. package/dist/agent.js +0 -41
  111. package/dist/agent.js.map +0 -1
  112. package/dist/errors.d.ts +0 -277
  113. package/dist/errors.d.ts.map +0 -1
  114. package/dist/errors.js +0 -388
  115. package/dist/errors.js.map +0 -1
  116. package/dist/response.d.ts +0 -124
  117. package/dist/response.d.ts.map +0 -1
  118. package/dist/response.js +0 -178
  119. package/dist/response.js.map +0 -1
  120. package/dist/types.d.ts +0 -54
  121. package/dist/types.d.ts.map +0 -1
  122. package/dist/types.js +0 -16
  123. package/dist/types.js.map +0 -1
  124. package/dist/util.d.ts +0 -90
  125. package/dist/util.d.ts.map +0 -1
  126. package/dist/util.js +0 -210
  127. package/dist/util.js.map +0 -1
  128. package/dist/www-authenticate.d.ts +0 -35
  129. package/dist/www-authenticate.d.ts.map +0 -1
  130. package/dist/www-authenticate.js +0 -54
  131. package/dist/www-authenticate.js.map +0 -1
  132. package/dist/xrpc.d.ts +0 -194
  133. package/dist/xrpc.d.ts.map +0 -1
  134. package/dist/xrpc.js +0 -235
  135. package/dist/xrpc.js.map +0 -1
package/dist/util.js DELETED
@@ -1,210 +0,0 @@
1
- export function applyDefaults(options, ...defaults) {
2
- const combined = { ...options };
3
- // @NOTE We make sure that options with an explicit `undefined` value get the
4
- // default, since spreading doesn't override with `undefined`. When multiple
5
- // defaults define the same key, the first defined value wins.
6
- for (const def of defaults) {
7
- for (const key of Object.keys(def)) {
8
- if (combined[key] === undefined) {
9
- combined[key] = def[key];
10
- }
11
- }
12
- }
13
- return combined;
14
- }
15
- /**
16
- * Type guard to check if a value is {@link Blob}-like.
17
- *
18
- * Handles both native Blobs and polyfilled Blob implementations
19
- * (e.g., fetch-blob from node-fetch).
20
- *
21
- * @param value - The value to check
22
- * @returns `true` if the value is a Blob or Blob-like object
23
- */
24
- export function isBlobLike(value) {
25
- if (value == null)
26
- return false;
27
- if (typeof value !== 'object')
28
- return false;
29
- if (typeof Blob === 'function' && value instanceof Blob)
30
- return true;
31
- // Support for Blobs provided by libraries that don't use the native Blob
32
- // (e.g. fetch-blob from node-fetch).
33
- // https://github.com/node-fetch/fetch-blob/blob/a1a182e5978811407bef4ea1632b517567dda01f/index.js#L233-L244
34
- const tag = value[Symbol.toStringTag];
35
- if (tag === 'Blob' || tag === 'File') {
36
- return 'stream' in value && typeof value.stream === 'function';
37
- }
38
- return false;
39
- }
40
- export function isAsyncIterable(value) {
41
- return (value != null && typeof value[Symbol.asyncIterator] === 'function');
42
- }
43
- export function asUint8ArrayArrayBuffer(bytes) {
44
- // If the Uint8Array is already backed by a non-shared ArrayBuffer, we can use
45
- // it directly.
46
- if (bytes.buffer instanceof ArrayBuffer) {
47
- return bytes;
48
- }
49
- // Otherwise, we need to create a new ArrayBuffer and copy the data.
50
- return new Uint8Array(bytes);
51
- }
52
- /**
53
- * Builds HTTP headers for AT Protocol requests.
54
- *
55
- * Adds or removes the following headers based on the provided options:
56
- * - `atproto-proxy`: Service routing header (if service is specified)
57
- * - `atproto-accept-labelers`: Comma-separated list of labeler DIDs
58
- *
59
- * @see {@link XrpcRequestHeadersOptions}
60
- * @returns A new Headers object with AT Protocol headers added
61
- */
62
- export function buildXrpcRequestHeaders({ service, labelers, appLabelers, headers: headersInit, }) {
63
- const headers = new Headers(headersInit);
64
- // If provided, the "service" option overrides any existing "atproto-proxy"
65
- // header. If `null`, the header is removed entirely.
66
- if (service !== undefined) {
67
- if (service === null) {
68
- headers.delete('atproto-proxy');
69
- }
70
- else {
71
- headers.set('atproto-proxy', service);
72
- }
73
- }
74
- // Labelers are combined from the "appLabelers" and "labelers" options, as
75
- // well as any existing "atproto-accept-labelers" header. The "appLabelers"
76
- // are always added with the ";redact" suffix, while the "labelers" are added
77
- // as-is. Existing labelers headers are not preserved if the "labelers" option
78
- // is explicitly set to null.
79
- const combinedLabelers = new Set();
80
- if (appLabelers) {
81
- for (const labeler of appLabelers) {
82
- combinedLabelers.add(`${labeler};redact`);
83
- }
84
- }
85
- if (labelers) {
86
- for (const labeler of labelers) {
87
- combinedLabelers.add(labeler);
88
- }
89
- }
90
- if (labelers !== null) {
91
- const headersLabelers = headers.get('atproto-accept-labelers');
92
- if (headersLabelers) {
93
- for (const labeler of headersLabelers
94
- .split(',')
95
- .map(trim)
96
- .filter(Boolean)) {
97
- if (labeler)
98
- combinedLabelers.add(labeler);
99
- }
100
- }
101
- }
102
- if (combinedLabelers.size > 0) {
103
- headers.set('atproto-accept-labelers', Array.from(combinedLabelers).join(', '));
104
- }
105
- else {
106
- headers.delete('atproto-accept-labelers');
107
- }
108
- return headers;
109
- }
110
- export function toReadableStream(data) {
111
- // Use the native ReadableStream.from() if available.
112
- /* v8 ignore next -- @preserve */
113
- if ('from' in ReadableStream && typeof ReadableStream.from === 'function') {
114
- return ReadableStream.from(data);
115
- }
116
- /* v8 ignore next -- @preserve */
117
- return toReadableStreamPonyfill(data);
118
- }
119
- export function toReadableStreamPonyfill(data) {
120
- let iterator;
121
- return new ReadableStream({
122
- async pull(controller) {
123
- try {
124
- iterator ??= data[Symbol.asyncIterator]();
125
- const result = await iterator.next();
126
- if (result.done)
127
- controller.close();
128
- else
129
- controller.enqueue(result.value);
130
- }
131
- catch (err) {
132
- controller.error(err);
133
- iterator = undefined;
134
- }
135
- },
136
- async cancel() {
137
- await iterator?.return?.();
138
- iterator = undefined;
139
- },
140
- });
141
- }
142
- export function getDefaultRecordKey(schema) {
143
- // Let the server generate the TID
144
- if (schema.key === 'tid')
145
- return undefined;
146
- if (schema.key === 'any')
147
- return undefined;
148
- return getLiteralRecordKey(schema);
149
- }
150
- export function getLiteralRecordKey(schema) {
151
- if (schema.key.startsWith('literal:')) {
152
- return schema.key.slice(8);
153
- }
154
- throw new TypeError(`An "rkey" must be provided for record key type "${schema.key}" (${schema.$type})`);
155
- }
156
- export function mergeHeaders(defaultHeaders, requestHeaders) {
157
- // We don't want to alter the original Headers objects, so we create a new one
158
- const result = new Headers(defaultHeaders);
159
- const overrides = requestHeaders instanceof Headers
160
- ? requestHeaders
161
- : new Headers(requestHeaders);
162
- for (const [key, value] of overrides.entries()) {
163
- result.set(key, value);
164
- }
165
- return result;
166
- }
167
- function getAbortReason(signal) {
168
- if ('reason' in signal)
169
- return signal.reason;
170
- return typeof DOMException !== 'undefined'
171
- ? new DOMException('Aborted', 'AbortError')
172
- : new Error('Aborted');
173
- }
174
- /**
175
- * Uses the native `AbortSignal.throwIfAborted()` when available, falling back
176
- * for older implementations such as React Native's `abort-controller`.
177
- */
178
- export function throwIfAborted(signal) {
179
- if (!signal)
180
- return;
181
- if (typeof signal.throwIfAborted === 'function') {
182
- signal.throwIfAborted();
183
- return;
184
- }
185
- if (signal.aborted)
186
- throw getAbortReason(signal);
187
- }
188
- export function wait(ms, { signal } = {}) {
189
- return new Promise((resolve, reject) => {
190
- throwIfAborted(signal);
191
- const cleanup = () => {
192
- clearTimeout(timeout);
193
- signal?.removeEventListener('abort', onAbort);
194
- };
195
- const timeout = setTimeout(() => {
196
- cleanup();
197
- resolve();
198
- }, ms);
199
- const onAbort = () => {
200
- cleanup();
201
- // @NOTE the signal exists because this listener came from it.
202
- reject(getAbortReason(signal));
203
- };
204
- signal?.addEventListener('abort', onAbort);
205
- });
206
- }
207
- export function trim(value) {
208
- return value.trim();
209
- }
210
- //# sourceMappingURL=util.js.map
package/dist/util.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAgBA,MAAM,UAAU,aAAa,CAI3B,OAAiB,EACjB,GAAG,QAAmB;IAEtB,MAAM,QAAQ,GAA4B,EAAE,GAAG,OAAO,EAAE,CAAA;IAExD,6EAA6E;IAC7E,4EAA4E;IAC5E,8DAA8D;IAC9D,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAyB,EAAE,CAAC;YAC3D,IAAI,QAAQ,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE,CAAC;gBAChC,QAAQ,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;YAC1B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,QAA6C,CAAA;AACtD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,KAAK,CAAA;IAC/B,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC3C,IAAI,OAAO,IAAI,KAAK,UAAU,IAAI,KAAK,YAAY,IAAI;QAAE,OAAO,IAAI,CAAA;IAEpE,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E,EAAE;QAC3C,cAAc,CAAC,MAAM,CAAC,CAAA;QAEtB,MAAM,OAAO,GAAG,GAAG,EAAE;YACnB,YAAY,CAAC,OAAO,CAAC,CAAA;YACrB,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAC/C,CAAC,CAAA;QAED,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YAC9B,OAAO,EAAE,CAAA;YACT,OAAO,EAAE,CAAA;QACX,CAAC,EAAE,EAAE,CAAC,CAAA;QAEN,MAAM,OAAO,GAAG,GAAG,EAAE;YACnB,OAAO,EAAE,CAAA;YACT,8DAA8D;YAC9D,MAAM,CAAC,cAAc,CAAC,MAAO,CAAC,CAAC,CAAA;QACjC,CAAC,CAAA;QAED,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAC5C,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,KAAa;IAChC,OAAO,KAAK,CAAC,IAAI,EAAE,CAAA;AACrB,CAAC","sourcesContent":["import type {\n InferRecordKey,\n LexiconRecordKey,\n RecordSchema,\n} from '@atproto/lex-schema'\nimport type { DidString, Service } from './types.ts'\n\ntype NonReadonly<T> = { -readonly [K in keyof T]: T[K] }\n\nexport type WithDefaults<\n TOptions extends Record<string, unknown>,\n TDefaults extends Record<string, unknown>[],\n> = TDefaults extends [infer First, ...infer Rest extends any[]]\n ? TOptions & WithDefaults<NonReadonly<First>, Rest>\n : TOptions\n\nexport function applyDefaults<\n TOptions extends Readonly<Record<string, unknown>>,\n TDefaults extends Readonly<Record<string, unknown>>[],\n>(\n options: TOptions,\n ...defaults: TDefaults\n): WithDefaults<TOptions, TDefaults> {\n const combined: Record<string, unknown> = { ...options }\n\n // @NOTE We make sure that options with an explicit `undefined` value get the\n // default, since spreading doesn't override with `undefined`. When multiple\n // defaults define the same key, the first defined value wins.\n for (const def of defaults) {\n for (const key of Object.keys(def) as (keyof typeof def)[]) {\n if (combined[key] === undefined) {\n combined[key] = def[key]\n }\n }\n }\n\n return combined as WithDefaults<TOptions, TDefaults>\n}\n\n/**\n * Type guard to check if a value is {@link Blob}-like.\n *\n * Handles both native Blobs and polyfilled Blob implementations\n * (e.g., fetch-blob from node-fetch).\n *\n * @param value - The value to check\n * @returns `true` if the value is a Blob or Blob-like object\n */\nexport function isBlobLike(value: unknown): value is Blob {\n if (value == null) return false\n if (typeof value !== 'object') return false\n if (typeof Blob === 'function' && value instanceof Blob) return true\n\n // Support for Blobs provided by libraries that don't use the native Blob\n // (e.g. fetch-blob from node-fetch).\n // https://github.com/node-fetch/fetch-blob/blob/a1a182e5978811407bef4ea1632b517567dda01f/index.js#L233-L244\n\n const tag = (value as any)[Symbol.toStringTag]\n if (tag === 'Blob' || tag === 'File') {\n return 'stream' in value && typeof value.stream === 'function'\n }\n\n return false\n}\n\nexport function isAsyncIterable<T>(\n value: T,\n): value is unknown extends T\n ? T & AsyncIterable<unknown>\n : Extract<T, AsyncIterable<any>> {\n return (\n value != null && typeof (value as any)[Symbol.asyncIterator] === 'function'\n )\n}\n\nexport function asUint8ArrayArrayBuffer(\n bytes: Uint8Array,\n): Uint8Array<ArrayBuffer> {\n // If the Uint8Array is already backed by a non-shared ArrayBuffer, we can use\n // it directly.\n if (bytes.buffer instanceof ArrayBuffer) {\n return bytes as Uint8Array<ArrayBuffer>\n }\n\n // Otherwise, we need to create a new ArrayBuffer and copy the data.\n return new Uint8Array(bytes)\n}\n\nexport type XrpcRequestHeadersOptions = {\n /**\n * Additional custom HTTP headers to include in the request.\n *\n * @note \"atproto-proxy\" and \"atproto-accept-labelers\" headers might change\n * depending on the `service` and `labelers` options, respectively, if they\n * are provided (which is always the case when using {@link Client.xrpc}).\n */\n headers?: HeadersInit\n\n /**\n * Labeler DIDs to request labels from for content moderation.\n *\n * When `undefined`, will default to the client instance's default. When\n * `null`, it will cause any existing `atproto-accept-labelers` header\n * (including one provided through the\n * {@link XrpcRequestHeadersOptions.headers} option) to be removed.\n */\n labelers?: null | Iterable<DidString>\n\n /**\n * Labeler DIDs to request labels from for content moderation. Values here\n * will always be applied with the \";redact\" suffix, which indicates that the\n * client is requesting that the labeler redact content that is deemed\n * inappropriate.\n */\n appLabelers?: null | Iterable<DidString>\n\n /**\n * Service proxy identifier for routing requests through a specific service.\n *\n * When `undefined`, will default to the client instance's default. When not\n * used against a client instance (e.g., when using the {@link xrpc} helper\n * function), the default is to not alter the `atproto-proxy` header (e.g. if\n * one is provided in the {@link XrpcRequestHeadersOptions.headers}).\n *\n * When defined (as either `null` or a string), it will override any\n * `atproto-proxy` header provided in the\n * {@link XrpcRequestHeadersOptions.headers} option.\n */\n service?: null | Service\n}\n\n/**\n * Builds HTTP headers for AT Protocol requests.\n *\n * Adds or removes the following headers based on the provided options:\n * - `atproto-proxy`: Service routing header (if service is specified)\n * - `atproto-accept-labelers`: Comma-separated list of labeler DIDs\n *\n * @see {@link XrpcRequestHeadersOptions}\n * @returns A new Headers object with AT Protocol headers added\n */\nexport function buildXrpcRequestHeaders({\n service,\n labelers,\n appLabelers,\n headers: headersInit,\n}: XrpcRequestHeadersOptions): Headers {\n const headers = new Headers(headersInit)\n\n // If provided, the \"service\" option overrides any existing \"atproto-proxy\"\n // header. If `null`, the header is removed entirely.\n if (service !== undefined) {\n if (service === null) {\n headers.delete('atproto-proxy')\n } else {\n headers.set('atproto-proxy', service)\n }\n }\n\n // Labelers are combined from the \"appLabelers\" and \"labelers\" options, as\n // well as any existing \"atproto-accept-labelers\" header. The \"appLabelers\"\n // are always added with the \";redact\" suffix, while the \"labelers\" are added\n // as-is. Existing labelers headers are not preserved if the \"labelers\" option\n // is explicitly set to null.\n const combinedLabelers = new Set<string>()\n\n if (appLabelers) {\n for (const labeler of appLabelers) {\n combinedLabelers.add(`${labeler};redact`)\n }\n }\n\n if (labelers) {\n for (const labeler of labelers) {\n combinedLabelers.add(labeler)\n }\n }\n\n if (labelers !== null) {\n const headersLabelers = headers.get('atproto-accept-labelers')\n if (headersLabelers) {\n for (const labeler of headersLabelers\n .split(',')\n .map(trim)\n .filter(Boolean)) {\n if (labeler) combinedLabelers.add(labeler)\n }\n }\n }\n\n if (combinedLabelers.size > 0) {\n headers.set(\n 'atproto-accept-labelers',\n Array.from(combinedLabelers).join(', '),\n )\n } else {\n headers.delete('atproto-accept-labelers')\n }\n\n return headers\n}\n\nexport function toReadableStream(\n data: AsyncIterable<Uint8Array>,\n): ReadableStream<Uint8Array> {\n // Use the native ReadableStream.from() if available.\n\n /* v8 ignore next -- @preserve */\n if ('from' in ReadableStream && typeof ReadableStream.from === 'function') {\n return ReadableStream.from(data)\n }\n\n /* v8 ignore next -- @preserve */\n return toReadableStreamPonyfill(data)\n}\n\nexport function toReadableStreamPonyfill(\n data: AsyncIterable<Uint8Array>,\n): ReadableStream<Uint8Array> {\n let iterator: AsyncIterator<Uint8Array> | undefined\n return new ReadableStream<Uint8Array>({\n async pull(controller) {\n try {\n iterator ??= data[Symbol.asyncIterator]()\n const result = await iterator!.next()\n if (result.done) controller.close()\n else controller.enqueue(result.value)\n } catch (err) {\n controller.error(err)\n iterator = undefined\n }\n },\n async cancel() {\n await iterator?.return?.()\n iterator = undefined\n },\n })\n}\n\nexport type RecordKeyOptions<\n T extends RecordSchema,\n AlsoOptionalWhenRecordKeyIs extends LexiconRecordKey = never,\n> = T['key'] extends `literal:${string}` | AlsoOptionalWhenRecordKeyIs\n ? { rkey?: InferRecordKey<T> }\n : { rkey: InferRecordKey<T> }\n\nexport function getDefaultRecordKey<const T extends RecordSchema>(\n schema: T,\n): undefined | InferRecordKey<T> {\n // Let the server generate the TID\n if (schema.key === 'tid') return undefined\n if (schema.key === 'any') return undefined\n\n return getLiteralRecordKey(schema)\n}\n\nexport function getLiteralRecordKey<const T extends RecordSchema>(\n schema: T,\n): InferRecordKey<T> {\n if (schema.key.startsWith('literal:')) {\n return schema.key.slice(8) as InferRecordKey<T>\n }\n\n throw new TypeError(\n `An \"rkey\" must be provided for record key type \"${schema.key}\" (${schema.$type})`,\n )\n}\n\nexport function mergeHeaders(\n defaultHeaders: HeadersInit,\n requestHeaders: HeadersInit,\n): Headers {\n // We don't want to alter the original Headers objects, so we create a new one\n const result = new Headers(defaultHeaders)\n\n const overrides =\n requestHeaders instanceof Headers\n ? requestHeaders\n : new Headers(requestHeaders)\n\n for (const [key, value] of overrides.entries()) {\n result.set(key, value)\n }\n\n return result\n}\n\nfunction getAbortReason(signal: AbortSignal): unknown {\n if ('reason' in signal) return signal.reason\n return typeof DOMException !== 'undefined'\n ? new DOMException('Aborted', 'AbortError')\n : new Error('Aborted')\n}\n\n/**\n * Uses the native `AbortSignal.throwIfAborted()` when available, falling back\n * for older implementations such as React Native's `abort-controller`.\n */\nexport function throwIfAborted(signal?: AbortSignal): void {\n if (!signal) return\n if (typeof signal.throwIfAborted === 'function') {\n signal.throwIfAborted()\n return\n }\n if (signal.aborted) throw getAbortReason(signal)\n}\n\nexport function wait(\n ms: number,\n { signal }: { signal?: AbortSignal } = {},\n): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n throwIfAborted(signal)\n\n const cleanup = () => {\n clearTimeout(timeout)\n signal?.removeEventListener('abort', onAbort)\n }\n\n const timeout = setTimeout(() => {\n cleanup()\n resolve()\n }, ms)\n\n const onAbort = () => {\n cleanup()\n // @NOTE the signal exists because this listener came from it.\n reject(getAbortReason(signal!))\n }\n\n signal?.addEventListener('abort', onAbort)\n })\n}\n\nexport function trim(value: string): string {\n return value.trim()\n}\n"]}
@@ -1,35 +0,0 @@
1
- type WWWAuthenticateParams = {
2
- [authParam in string]: string;
3
- };
4
- /**
5
- * Parsed representation of a WWW-Authenticate HTTP header.
6
- *
7
- * Maps authentication scheme names to either:
8
- * - A token68 string (compact authentication data)
9
- * - A params object with key-value pairs
10
- *
11
- * @example Bearer with realm
12
- * ```typescript
13
- * // WWW-Authenticate: Bearer realm="example"
14
- * const parsed: WWWAuthenticate = {
15
- * Bearer: { realm: 'example' }
16
- * }
17
- * ```
18
- *
19
- * @example DPoP with error
20
- * ```typescript
21
- * // WWW-Authenticate: DPoP error="use_dpop_nonce", error_description="..."
22
- * const parsed: WWWAuthenticate = {
23
- * DPoP: { error: 'use_dpop_nonce', error_description: '...' }
24
- * }
25
- * ```
26
- */
27
- export type WWWAuthenticate = {
28
- [authScheme in string]: string | WWWAuthenticateParams;
29
- };
30
- /**
31
- * Returns `undefined` if the header is malformed.
32
- */
33
- export declare function parseWWWAuthenticateHeader(header?: unknown): undefined | WWWAuthenticate;
34
- export {};
35
- //# sourceMappingURL=www-authenticate.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"www-authenticate.d.ts","sourceRoot":"","sources":["../src/www-authenticate.ts"],"names":[],"mappings":"AAAA,KAAK,qBAAqB,GAAG;KAAG,SAAS,IAAI,MAAM,GAAG,MAAM;CAAE,CAAA;AAE9D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,eAAe,GAAG;KAC3B,UAAU,IAAI,MAAM,GACjB,MAAM,GACN,qBAAqB;CAC1B,CAAA;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,MAAM,CAAC,EAAE,OAAO,GACf,SAAS,GAAG,eAAe,CAgE7B"}
@@ -1,54 +0,0 @@
1
- /**
2
- * Returns `undefined` if the header is malformed.
3
- */
4
- export function parseWWWAuthenticateHeader(header) {
5
- if (typeof header !== 'string')
6
- return undefined;
7
- const wwwAuthenticate = {};
8
- // Split over commas, not within quoted strings
9
- const trimmedHeader = header.trim();
10
- if (!trimmedHeader)
11
- return wwwAuthenticate;
12
- const parts = trimmedHeader.split(/,(?=(?:[^"]*"[^"]*")*[^"]*$)/);
13
- let currentParams = null;
14
- for (let part of parts) {
15
- // Check if the part starts with an auth scheme
16
- const schemeMatch = part.trim().match(/^([^"=\s]+)(\s+.*)?$/);
17
- if (schemeMatch) {
18
- const scheme = schemeMatch[1];
19
- // Duplicate scheme
20
- if (Object.hasOwn(wwwAuthenticate, scheme))
21
- return undefined;
22
- const rest = schemeMatch[2]?.trim();
23
- if (!rest) {
24
- // Scheme only (no params or token68)
25
- currentParams = null;
26
- wwwAuthenticate[scheme] = Object.create(null);
27
- continue;
28
- }
29
- if (!rest.includes('=')) {
30
- // Scheme with token68
31
- currentParams = null;
32
- wwwAuthenticate[scheme] = rest;
33
- continue;
34
- }
35
- // Scheme with params
36
- currentParams = Object.create(null);
37
- wwwAuthenticate[scheme] = currentParams;
38
- // Fall through to parse params
39
- part = rest;
40
- }
41
- // Invalid header
42
- if (!currentParams)
43
- return undefined;
44
- const param = part.match(/^\s*([^"\s=]+)=(?:("[^"\\]*(?:\\.[^"\\]*)*")|([^\s,"]*))\s*$/);
45
- // invalid param
46
- if (!param)
47
- return undefined;
48
- const paramName = param[1];
49
- const paramValue = param[3] ?? param[2].slice(1, -1).replaceAll(/\\(.)/g, '$1');
50
- currentParams[paramName] = paramValue;
51
- }
52
- return wwwAuthenticate;
53
- }
54
- //# sourceMappingURL=www-authenticate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"www-authenticate.js","sourceRoot":"","sources":["../src/www-authenticate.ts"],"names":[],"mappings":"AA+BA;;GAEG;AACH,MAAM,UAAU,0BAA0B,CACxC,MAAgB;IAEhB,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAA;IAEhD,MAAM,eAAe,GAAoB,EAAE,CAAA;IAE3C,+CAA+C;IAC/C,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,EAAE,CAAA;IACnC,IAAI,CAAC,aAAa;QAAE,OAAO,eAAe,CAAA;IAE1C,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAA;IAEjE,IAAI,aAAa,GAAiC,IAAI,CAAA;IAEtD,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,+CAA+C;QAC/C,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAA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CAAC,CAAA;QAE/D,aAAa,CAAC,SAAS,CAAC,GAAG,UAAU,CAAA;IACvC,CAAC;IAED,OAAO,eAAe,CAAA;AACxB,CAAC","sourcesContent":["type WWWAuthenticateParams = { [authParam in string]: string }\n\n/**\n * Parsed representation of a WWW-Authenticate HTTP header.\n *\n * Maps authentication scheme names to either:\n * - A token68 string (compact authentication data)\n * - A params object with key-value pairs\n *\n * @example Bearer with realm\n * ```typescript\n * // WWW-Authenticate: Bearer realm=\"example\"\n * const parsed: WWWAuthenticate = {\n * Bearer: { realm: 'example' }\n * }\n * ```\n *\n * @example DPoP with error\n * ```typescript\n * // WWW-Authenticate: DPoP error=\"use_dpop_nonce\", error_description=\"...\"\n * const parsed: WWWAuthenticate = {\n * DPoP: { error: 'use_dpop_nonce', error_description: '...' }\n * }\n * ```\n */\nexport type WWWAuthenticate = {\n [authScheme in string]:\n | string // token68\n | WWWAuthenticateParams\n}\n\n/**\n * Returns `undefined` if the header is malformed.\n */\nexport function parseWWWAuthenticateHeader(\n header?: unknown,\n): undefined | WWWAuthenticate {\n if (typeof header !== 'string') return undefined\n\n const wwwAuthenticate: WWWAuthenticate = {}\n\n // Split over commas, not within quoted strings\n const trimmedHeader = header.trim()\n if (!trimmedHeader) return wwwAuthenticate\n\n const parts = trimmedHeader.split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/)\n\n let currentParams: WWWAuthenticateParams | null = null\n\n for (let part of parts) {\n // Check if the part starts with an auth scheme\n const schemeMatch = part.trim().match(/^([^\"=\\s]+)(\\s+.*)?$/)\n if (schemeMatch) {\n const scheme = schemeMatch[1]\n\n // Duplicate scheme\n if (Object.hasOwn(wwwAuthenticate, scheme)) return undefined\n\n const rest = schemeMatch[2]?.trim()\n if (!rest) {\n // Scheme only (no params or token68)\n currentParams = null\n wwwAuthenticate[scheme] = Object.create(null)\n continue\n }\n\n if (!rest.includes('=')) {\n // Scheme with token68\n currentParams = null\n wwwAuthenticate[scheme] = rest\n continue\n }\n\n // Scheme with params\n\n currentParams = Object.create(null) as WWWAuthenticateParams\n wwwAuthenticate[scheme] = currentParams\n\n // Fall through to parse params\n part = rest\n }\n\n // Invalid header\n if (!currentParams) return undefined\n\n const param = part.match(\n /^\\s*([^\"\\s=]+)=(?:(\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\")|([^\\s,\"]*))\\s*$/,\n )\n\n // invalid param\n if (!param) return undefined\n\n const paramName = param[1]\n const paramValue =\n param[3] ?? param[2]!.slice(1, -1).replaceAll(/\\\\(.)/g, '$1')\n\n currentParams[paramName] = paramValue\n }\n\n return wwwAuthenticate\n}\n"]}
package/dist/xrpc.d.ts DELETED
@@ -1,194 +0,0 @@
1
- import { type InferInput, type InferPayload, type Main, type Params, type Procedure, type Query, type Restricted, type Subscription } from '@atproto/lex-schema';
2
- import type { Agent, AgentOptions } from './agent.js';
3
- import type { XrpcFailure } from './errors.js';
4
- import type { XrpcResponseOptions } from './response.js';
5
- import { XrpcResponse } from './response.js';
6
- import type { BinaryBodyInit } from './types.js';
7
- import type { XrpcRequestHeadersOptions } from './util.js';
8
- /**
9
- * The query/path parameters type for an XRPC method, inferred from its schema.
10
- *
11
- * @typeParam M - The XRPC method type (Procedure, Query, or Subscription)
12
- */
13
- export type XrpcRequestParams<M extends Procedure | Query | Subscription> = InferInput<M['parameters']>;
14
- type XrpcRequestParamsOptions<P extends Params> = NonNullable<unknown> extends P ? {
15
- params?: P;
16
- } : {
17
- params: P;
18
- };
19
- type XrpcRequestPayload<M extends Procedure | Query> = M extends Procedure ? InferPayload<M['input'], BinaryBodyInit> : undefined;
20
- type XrpcRequestPayloadOptions<TPayload> = TPayload extends {
21
- body: infer B;
22
- encoding: infer E;
23
- } ? {
24
- body: B;
25
- /**
26
- * mime type hint for binary bodies
27
- *
28
- * Only needed for endpoints that accept binary input (e.g. file uploads)
29
- * when the body is a Blob-like object without a type (e.g. fetch-blob's
30
- * Blob). If the body is a Blob-like object with a type, that type will be
31
- * used as the content-type header instead of this option.
32
- *
33
- * @default "application/octet-stream"
34
- */
35
- encoding?: E;
36
- } : {
37
- body?: undefined;
38
- encoding?: undefined;
39
- };
40
- /**
41
- * Options for making an XRPC request, based on the method schema.
42
- *
43
- * Combines {@link XrpcRequestOptions} and {@link XrpcResponseOptions} with
44
- * method-specific params and body requirements. The type system ensures
45
- * required params/body are provided based on the method schema.
46
- *
47
- * @typeParam M - The XRPC method type (Procedure or Query)
48
- *
49
- * @example Query with params
50
- * ```typescript
51
- * const options: XrpcOptions<typeof app.bsky.feed.getTimeline.main> = {
52
- * params: { limit: 50 }
53
- * }
54
- * ```
55
- *
56
- * @example Procedure with body
57
- * ```typescript
58
- * const options: XrpcOptions<typeof com.atproto.repo.createRecord.main> = {
59
- * body: { repo: did, collection: 'app.bsky.feed.post', record: { ... } }
60
- * }
61
- * ```
62
- */
63
- export type XrpcOptions<M extends Procedure | Query = Procedure | Query> = XrpcRequestOptions<M> & XrpcResponseOptions & RetryOptions;
64
- export type XrpcRequestOptions<M extends Procedure | Query = Procedure | Query> = XrpcRequestProcessingOptions & XrpcRequestHeadersOptions & XrpcRequestPayloadOptions<XrpcRequestPayload<M>> & XrpcRequestParamsOptions<XrpcRequestParams<M>>;
65
- export type XrpcRequestProcessingOptions = {
66
- /**
67
- * AbortSignal to cancel the request.
68
- */
69
- signal?: AbortSignal;
70
- /**
71
- * Whether to validate the request against the method's input schema. Enabling
72
- * this can help catch errors early but may have a performance cost. This
73
- * would typically only be set to `true` in development or debugging
74
- * scenarios.
75
- *
76
- * @default false
77
- */
78
- validateRequest?: boolean;
79
- };
80
- /**
81
- * Makes an XRPC request and throws on failure.
82
- *
83
- * This is the low-level function for making XRPC calls.
84
- *
85
- * @param agent - The {@link Agent} to use for making the request
86
- * @param ns - The lexicon method definition
87
- * @param options - Request {@link XrpcOptions options} (params, body, headers, etc.)
88
- * @returns The successful {@link XrpcResponse}
89
- * @throws {XrpcFailure} When the request fails
90
- *
91
- * @example
92
- * ```typescript
93
- * const response = await xrpc('https://bsky.network', com.atproto.identity.resolveHandle, {
94
- * params: { handle: "atproto.com" }
95
- * })
96
- * ```
97
- *
98
- * @example
99
- * ```typescript
100
- * const response = await xrpc(agent, app.bsky.feed.getTimeline.main, {
101
- * params: { limit: 50 }
102
- * })
103
- * ```
104
- */
105
- export declare function xrpc<const M extends Query | Procedure>(agentOpts: Agent | AgentOptions, ns: NonNullable<unknown> extends XrpcOptions<M> ? Main<M> : Restricted<'This XRPC method requires an "options" argument'>): Promise<XrpcResponse<M>>;
106
- export declare function xrpc<const M extends Query | Procedure>(agentOpts: Agent | AgentOptions, ns: Main<M>, options: XrpcOptions<M>): Promise<XrpcResponse<M>>;
107
- /**
108
- * Union type representing either a successful response or a failure.
109
- *
110
- * Both {@link XrpcResponse} and {@link XrpcFailure} have a `success` property
111
- * that can be used to discriminate between them.
112
- *
113
- * @typeParam M - The XRPC method type
114
- */
115
- export type XrpcResult<M extends Procedure | Query> = XrpcResponse<M> | XrpcFailure<M>;
116
- /**
117
- * Makes an XRPC request without throwing on failure.
118
- *
119
- * Returns a discriminated union that can be checked via the `success` property.
120
- * This is useful for handling errors without try/catch blocks. This also allows
121
- * failure results to be typed with the method schema, which can provide better
122
- * type safety when handling errors (e.g. checking for specific error codes).
123
- *
124
- * @param agent - The {@link Agent} to use for making the request
125
- * @param ns - The lexicon method definition
126
- * @param options - Request {@link XrpcOptions options} (params, body, headers, etc.)
127
- * @returns Either a successful {@link XrpcResponse} or an {@link XrpcFailure}
128
- *
129
- * @example
130
- * ```typescript
131
- * const result = await xrpcSafe('https://example.com', app.bsky.actor.getProfile, {
132
- * params: { actor: 'alice.bsky.social' }
133
- * })
134
- *
135
- * if (result.success) {
136
- * console.log(result.body.displayName)
137
- * } else {
138
- * console.error('Request failed:', result.error)
139
- * }
140
- * ```
141
- */
142
- export declare function xrpcSafe<const M extends Query | Procedure>(agentOpts: Agent | AgentOptions, ns: NonNullable<unknown> extends XrpcOptions<M> ? Main<M> : Restricted<'This XRPC method requires an "options" argument'>): Promise<XrpcResult<M>>;
143
- export declare function xrpcSafe<const M extends Query | Procedure>(agentOpts: Agent | AgentOptions, ns: Main<M>, options: XrpcOptions<M>): Promise<XrpcResult<M>>;
144
- /**
145
- * Extracts the root cause from an error, unwrapping common fetch-related errors
146
- * such as those from undici (Node's internal fetch implementation).
147
- *
148
- * @param err - The error to extract the root cause from
149
- * @returns The root cause error, or the original error if no specific pattern is matched
150
- * @remarks This is useful for getting more specific error information from fetch-related failures, especially in Node environments using undici.
151
- */
152
- export declare function extractFetchErrorCause(err: unknown): unknown;
153
- export type RetryOptions = {
154
- /**
155
- * Function to determine whether a request should be retried after a failure.
156
- *
157
- * @default `(failure) => failure.shouldRetry()`
158
- */
159
- retry?: (failure: XrpcFailure, context: {
160
- counter: number;
161
- }) => boolean;
162
- /**
163
- * Maximum number of retries to allow.
164
- *
165
- * @default 0 (no retries)
166
- */
167
- maxRetries?: number;
168
- /**
169
- * Max number of milliseconds allow between retries
170
- *
171
- * @default 30000
172
- */
173
- maxRetryTimeout?: number;
174
- /**
175
- * Initial number of milliseconds to wait before retrying for the first time.
176
- *
177
- * @default 500
178
- */
179
- minRetryTimeout?: number;
180
- /**
181
- * Factor to multiply the timeout factor between retries.
182
- *
183
- * @default 2
184
- */
185
- retryTimeoutFactor?: number;
186
- /**
187
- * Automatically infer timeout between retries based on header values (`Retry-After`, `RateLimit-Reset`).
188
- *
189
- * @default true
190
- */
191
- retryHeaders?: boolean;
192
- };
193
- export {};
194
- //# sourceMappingURL=xrpc.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"xrpc.d.ts","sourceRoot":"","sources":["../src/xrpc.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,IAAI,EAET,KAAK,MAAM,EAEX,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,YAAY,EAElB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EA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