@fedify/fedify 1.7.13 → 1.7.15

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 (138) hide show
  1. package/dist/{actor-CPpvuBKU.d.ts → actor.d.ts} +3 -3
  2. package/dist/{actor-BVilnhZ3.js → actor.js} +6 -6
  3. package/dist/{assert-LOEeCUK5.js → assert.js} +2 -2
  4. package/dist/{assert_equals-B44MxcIj.js → assert_equals.js} +16 -16
  5. package/dist/{assert_instance_of-XtuFevV_.js → assert_instance_of.js} +2 -2
  6. package/dist/{assert_is_error-BTlryvT0.js → assert_is_error.js} +2 -2
  7. package/dist/{assert_not_equals-C685gKx6.js → assert_not_equals.js} +3 -6
  8. package/dist/{assert_rejects-DWQ4jaf9.js → assert_rejects.js} +3 -3
  9. package/dist/{assert_throws-YetpVSc-.js → assert_throws.js} +3 -3
  10. package/dist/{authdocloader-DqCINL6u.js → authdocloader.js} +8 -8
  11. package/dist/{builder-CKUAOfcL.js → builder.js} +7 -7
  12. package/dist/{chunk-Cx8LTkjm.js → chunk.js} +22 -15
  13. package/dist/{client-DvtwXO7t.d.ts → client.d.ts} +2 -2
  14. package/dist/{client-C5xUY491.js → client.js} +3 -3
  15. package/dist/{collection-Dfb0TPno.js → collection.js} +2 -3
  16. package/dist/compat/mod.d.ts +79 -12
  17. package/dist/compat/mod.js +1 -2
  18. package/dist/compat/transformers.test.js +34 -38
  19. package/dist/{context-OBWjptjU.d.ts → context.d.ts} +11 -11
  20. package/dist/{context-aglzx1Ww.js → context.js} +5 -5
  21. package/dist/{docloader-Q42SMRIB.d.ts → docloader.d.ts} +2 -2
  22. package/dist/{docloader-Qfs9nPiy.js → docloader.js} +32 -152
  23. package/dist/{docloader-09nVWLAZ.js → docloader2.js} +1 -1
  24. package/dist/{esm-DO9PrujO.js → esm.js} +36 -22
  25. package/dist/federation/builder.test.js +20 -26
  26. package/dist/federation/collection.test.js +11 -16
  27. package/dist/federation/handler.test.js +41 -48
  28. package/dist/federation/inbox.test.js +11 -11
  29. package/dist/federation/keycache.test.js +12 -11
  30. package/dist/federation/kv.test.js +8 -10
  31. package/dist/federation/middleware.test.js +105 -134
  32. package/dist/federation/mod.d.ts +4 -13
  33. package/dist/federation/mod.js +206 -12
  34. package/dist/federation/mq.test.js +12 -17
  35. package/dist/federation/retry.test.js +5 -4
  36. package/dist/federation/router.test.js +9 -10
  37. package/dist/federation/send.test.js +23 -24
  38. package/dist/{http-DMTrO3Ye.d.ts → http.d.ts} +3 -3
  39. package/dist/{http-CjDwMreH.js → http.js} +25 -31
  40. package/dist/{inbox-ApPO50Ma.js → inbox.js} +5 -5
  41. package/dist/key.js +16 -0
  42. package/dist/{key-BPUM0v_S.js → key2.js} +5 -5
  43. package/dist/{keycache-B7Urghlu.js → keycache.js} +2 -2
  44. package/dist/{keys-DGJec4-R.js → keys.js} +2 -2
  45. package/dist/{kv-DRaeSXco.d.ts → kv.d.ts} +1 -1
  46. package/dist/{kv-BMY6Qf_A.js → kv.js} +1 -1
  47. package/dist/{langstr-DbWheeIS.js → langstr.js} +1 -1
  48. package/dist/{ld-DJTavNY3.js → ld.js} +9 -12
  49. package/dist/{lookup-Bf-K85bV.d.ts → lookup.d.ts} +2 -2
  50. package/dist/{lookup-CkOdKyYR.js → lookup.js} +4 -4
  51. package/dist/{lookup-CnkkF4Rf.js → lookup2.js} +6 -6
  52. package/dist/{middleware-BxHcZC4p.js → middleware.js} +35 -39
  53. package/dist/middleware2.js +32 -0
  54. package/dist/mod.d.ts +17 -17
  55. package/dist/mod.js +17 -17
  56. package/dist/{mod-CDzlVCUF.d.ts → mod2.d.ts} +3 -3
  57. package/dist/{mod-CCL2cvnI.d.ts → mod3.d.ts} +4 -4
  58. package/dist/{mq-DYKDDJmp.d.ts → mq.d.ts} +1 -1
  59. package/dist/{multibase-CnLHszip.js → multibase.js} +1 -1
  60. package/dist/nodeinfo/client.test.js +19 -28
  61. package/dist/nodeinfo/handler.test.js +37 -44
  62. package/dist/nodeinfo/mod.d.ts +2 -5
  63. package/dist/nodeinfo/mod.js +2 -3
  64. package/dist/nodeinfo/semver.test.js +13 -21
  65. package/dist/nodeinfo/types.test.js +9 -11
  66. package/dist/{owner-D0cOz8R5.d.ts → owner.d.ts} +4 -4
  67. package/dist/{owner-qKULzrkx.js → owner.js} +4 -4
  68. package/dist/{proof-d5P09-xk.js → proof.js} +11 -13
  69. package/dist/{retry-BiIhZWgD.js → retry.js} +1 -1
  70. package/dist/{router-D_aVZZUc.js → router.js} +1 -1
  71. package/dist/runtime/authdocloader.test.js +22 -26
  72. package/dist/runtime/docloader.test.js +56 -56
  73. package/dist/runtime/key.test.js +31 -53
  74. package/dist/runtime/langstr.test.js +8 -10
  75. package/dist/runtime/mod.d.ts +103 -6
  76. package/dist/runtime/mod.js +6 -7
  77. package/dist/runtime/multibase/multibase.test.js +12 -18
  78. package/dist/runtime/url.test.js +7 -6
  79. package/dist/{semver-BNrOOAs9.js → semver.js} +7 -17
  80. package/dist/{send-BnMY3Qxa.js → send.js} +4 -4
  81. package/dist/sig/http.test.js +104 -168
  82. package/dist/sig/key.test.js +17 -20
  83. package/dist/sig/ld.test.js +28 -35
  84. package/dist/sig/mod.d.ts +3 -7
  85. package/dist/sig/mod.js +6 -7
  86. package/dist/sig/owner.test.js +24 -30
  87. package/dist/sig/proof.test.js +24 -29
  88. package/dist/{std__assert-o_r9vqm1.js → std__assert.js} +7 -13
  89. package/dist/testing/docloader.test.js +9 -12
  90. package/dist/testing/mod.js +2 -1
  91. package/dist/{testing-DLyvtiiW.js → testing.js} +2 -2
  92. package/dist/{transformers-ghwJuzGY.js → transformers.js} +1 -1
  93. package/dist/{type-CFuiGLz9.js → type.js} +1 -1
  94. package/dist/{types-CJHS5pXl.js → types.js} +2 -2
  95. package/dist/{url-C2xuoQD1.js → url.js} +1 -1
  96. package/dist/vocab/actor.test.js +76 -128
  97. package/dist/vocab/lookup.test.js +19 -23
  98. package/dist/vocab/mod.d.ts +3 -5
  99. package/dist/vocab/mod.js +4 -4
  100. package/dist/vocab/type.test.js +10 -10
  101. package/dist/vocab/vocab.test.js +90 -109
  102. package/dist/{vocab-CzEfWQk2.d.ts → vocab.d.ts} +2 -2
  103. package/dist/{vocab-S7fEn6XO.js → vocab.js} +318 -454
  104. package/dist/webfinger/handler.test.js +40 -48
  105. package/dist/webfinger/lookup.test.js +12 -15
  106. package/dist/webfinger/mod.d.ts +1 -4
  107. package/dist/webfinger/mod.js +2 -3
  108. package/dist/x/cfworkers.d.ts +2 -2
  109. package/dist/x/cfworkers.test.js +7 -9
  110. package/dist/x/hono.d.ts +2 -11
  111. package/dist/x/sveltekit.d.ts +2 -11
  112. package/package.json +1 -1
  113. package/dist/actor-CsmPeeHG.js +0 -34925
  114. package/dist/authdocloader-9g6RkEcR.js +0 -53
  115. package/dist/compat-Bb5myD13.js +0 -4
  116. package/dist/docloader-CchlnLWb.js +0 -4598
  117. package/dist/federation-B0aljx0V.js +0 -203
  118. package/dist/http-CP3h1SLi.js +0 -796
  119. package/dist/key--l6NVKdl.js +0 -257
  120. package/dist/key-1Fv7reaM.js +0 -16
  121. package/dist/key-DD37RpoD.js +0 -10
  122. package/dist/lookup-CN-LpF5e.js +0 -127
  123. package/dist/middleware-BQHe0X6Y.js +0 -17
  124. package/dist/middleware-C3TZ3P-v.js +0 -33
  125. package/dist/middleware-CEpilAEY.js +0 -3524
  126. package/dist/mod-1pDWKvUL.d.ts +0 -2
  127. package/dist/mod-DFncUgcE.d.ts +0 -82
  128. package/dist/mod-GIh5OYxW.d.ts +0 -2
  129. package/dist/mod-g0xFzAP9.d.ts +0 -2
  130. package/dist/mod-qFMzZ3iF.d.ts +0 -104
  131. package/dist/nodeinfo-CyEbLjHs.js +0 -4
  132. package/dist/proof-BfeWBNrY.js +0 -582
  133. package/dist/runtime-BSkOVUWM.js +0 -4
  134. package/dist/sig-BXJO--F9.js +0 -4
  135. package/dist/types-BZUzjGS0.js +0 -455
  136. package/dist/vocab-C_pE4SvE.js +0 -168
  137. package/dist/webfinger-C3GIyXIg.js +0 -4
  138. /package/dist/{denokv-CvROlGYX.js → denokv.js} +0 -0
@@ -1,455 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
-
5
- import { getUserAgent } from "./docloader-CchlnLWb.js";
6
- import { getLogger } from "@logtape/logtape";
7
-
8
- //#region nodeinfo/semver.ts
9
- const MAX_LENGTH = 256;
10
- /**
11
- * A single `0`, or a non-zero digit followed by zero or more digits.
12
- */
13
- const NUMERIC_IDENTIFIER = "0|[1-9]\\d*";
14
- /**
15
- * Zero or more digits, followed by a letter or hyphen, and then zero or more letters, digits, or hyphens.
16
- */
17
- const NON_NUMERIC_IDENTIFIER = "\\d*[a-zA-Z-][a-zA-Z0-9-]*";
18
- /**
19
- * Three dot-separated numeric identifiers.
20
- */
21
- const VERSION_CORE = `(?<major>${NUMERIC_IDENTIFIER})\\.(?<minor>${NUMERIC_IDENTIFIER})\\.(?<patch>${NUMERIC_IDENTIFIER})`;
22
- /**
23
- * A numeric identifier, or a non-numeric identifier.
24
- */
25
- const PRERELEASE_IDENTIFIER = `(?:${NUMERIC_IDENTIFIER}|${NON_NUMERIC_IDENTIFIER})`;
26
- /**
27
- * A hyphen, followed by one or more dot-separated pre-release version identifiers.
28
- * @example "-pre.release"
29
- */
30
- const PRERELEASE = `(?:-(?<prerelease>${PRERELEASE_IDENTIFIER}(?:\\.${PRERELEASE_IDENTIFIER})*))`;
31
- /**
32
- * Any combination of digits, letters, or hyphens.
33
- */
34
- const BUILD_IDENTIFIER = "[0-9A-Za-z-]+";
35
- /**
36
- * A plus sign, followed by one or more period-separated build metadata identifiers.
37
- * @example "+build.meta"
38
- */
39
- const BUILD = `(?:\\+(?<buildmetadata>${BUILD_IDENTIFIER}(?:\\.${BUILD_IDENTIFIER})*))`;
40
- /**
41
- * A version, followed optionally by a pre-release version and build metadata.
42
- */
43
- const FULL_VERSION = `v?${VERSION_CORE}${PRERELEASE}?${BUILD}?`;
44
- const FULL_REGEXP = /* @__PURE__ */ new RegExp(`^${FULL_VERSION}$`);
45
- /**
46
- * Attempt to parse a string as a semantic version, returning a SemVer object.
47
- *
48
- * @example Usage
49
- * ```ts
50
- * import { parseSemVer } from "@fedify/fedify/nodeinfo";
51
- * import { assertEquals } from "@std/assert";
52
- *
53
- * const version = parseSemVer("1.2.3");
54
- * assertEquals(version, {
55
- * major: 1,
56
- * minor: 2,
57
- * patch: 3,
58
- * prerelease: [],
59
- * build: [],
60
- * });
61
- * ```
62
- *
63
- * @throws {TypeError} If the input string is invalid.
64
- * @param value The version string to parse
65
- * @returns A valid SemVer
66
- * @since 1.2.0
67
- */
68
- function parseSemVer(value) {
69
- if (typeof value !== "string") throw new TypeError(`Cannot parse version as version must be a string: received ${typeof value}`);
70
- if (value.length > MAX_LENGTH) throw new TypeError(`Cannot parse version as version length is too long: length is ${value.length}, max length is ${MAX_LENGTH}`);
71
- value = value.trim();
72
- const groups = value.match(FULL_REGEXP)?.groups;
73
- if (!groups) throw new TypeError(`Cannot parse version: ${value}`);
74
- const major = parseNumber(groups.major, `Cannot parse version ${value}: invalid major version`);
75
- const minor = parseNumber(groups.minor, `Cannot parse version ${value}: invalid minor version`);
76
- const patch = parseNumber(groups.patch, `Cannot parse version ${value}: invalid patch version`);
77
- const prerelease = groups.prerelease ? parsePrerelease(groups.prerelease) : [];
78
- const build = groups.buildmetadata ? parseBuild(groups.buildmetadata) : [];
79
- return {
80
- major,
81
- minor,
82
- patch,
83
- prerelease,
84
- build
85
- };
86
- }
87
- /**
88
- * Returns true if the value is a valid SemVer number.
89
- *
90
- * Must be a number. Must not be NaN. Can be positive or negative infinity.
91
- * Can be between 0 and MAX_SAFE_INTEGER.
92
- * @param value The value to check
93
- * @returns True if its a valid semver number
94
- */
95
- function isValidNumber(value) {
96
- return typeof value === "number" && !Number.isNaN(value) && (!Number.isFinite(value) || 0 <= value && value <= Number.MAX_SAFE_INTEGER);
97
- }
98
- const NUMERIC_IDENTIFIER_REGEXP = /* @__PURE__ */ new RegExp(`^${NUMERIC_IDENTIFIER}$`);
99
- function parsePrerelease(prerelease) {
100
- return prerelease.split(".").filter(Boolean).map((id) => {
101
- if (NUMERIC_IDENTIFIER_REGEXP.test(id)) {
102
- const number = Number(id);
103
- if (isValidNumber(number)) return number;
104
- }
105
- return id;
106
- });
107
- }
108
- function parseBuild(buildmetadata) {
109
- return buildmetadata.split(".").filter(Boolean);
110
- }
111
- function parseNumber(input, errorMessage) {
112
- const number = Number(input);
113
- if (!isValidNumber(number)) throw new TypeError(errorMessage);
114
- return number;
115
- }
116
- function formatNumber(value) {
117
- return value.toFixed(0);
118
- }
119
- /**
120
- * Format a SemVer object into a string.
121
- *
122
- * @example Usage
123
- * ```ts
124
- * import { formatSemVer } from "@fedify/fedify/nodeinfo";
125
- * import { assertEquals } from "@std/assert";
126
- *
127
- * const semver = {
128
- * major: 1,
129
- * minor: 2,
130
- * patch: 3,
131
- * };
132
- * assertEquals(formatSemVer(semver), "1.2.3");
133
- * ```
134
- *
135
- * @param version The SemVer to format
136
- * @returns The string representation of a semantic version.
137
- * @since 1.2.0
138
- */
139
- function formatSemVer(version) {
140
- const major = formatNumber(version.major);
141
- const minor = formatNumber(version.minor);
142
- const patch = formatNumber(version.patch);
143
- const pre = version.prerelease?.join(".") ?? "";
144
- const build = version.build?.join(".") ?? "";
145
- return [[`${major}.${minor}.${patch}`, pre].filter((v) => v).join("-"), build].filter((v) => v).join("+");
146
- }
147
-
148
- //#endregion
149
- //#region nodeinfo/client.ts
150
- const logger = getLogger([
151
- "fedify",
152
- "nodeinfo",
153
- "client"
154
- ]);
155
- async function getNodeInfo(url, options = {}) {
156
- try {
157
- let nodeInfoUrl = url;
158
- if (!options.direct) {
159
- const wellKnownUrl = new URL("/.well-known/nodeinfo", url);
160
- const wellKnownResponse = await fetch(wellKnownUrl, { headers: {
161
- Accept: "application/json",
162
- "User-Agent": typeof options.userAgent === "string" ? options.userAgent : getUserAgent(options.userAgent)
163
- } });
164
- if (!wellKnownResponse.ok) {
165
- logger.error("Failed to fetch {url}: {status} {statusText}", {
166
- url: wellKnownUrl.href,
167
- status: wellKnownResponse.status,
168
- statusText: wellKnownResponse.statusText
169
- });
170
- return;
171
- }
172
- const wellKnownRd = await wellKnownResponse.json();
173
- const link = wellKnownRd?.links?.find((link$1) => link$1 != null && "rel" in link$1 && (link$1.rel === "http://nodeinfo.diaspora.software/ns/schema/2.0" || link$1.rel === "http://nodeinfo.diaspora.software/ns/schema/2.1") && "href" in link$1 && link$1.href != null);
174
- if (link == null) {
175
- logger.error("Failed to find a NodeInfo document link from {url}: {resourceDescriptor}", {
176
- url: wellKnownUrl.href,
177
- resourceDescriptor: wellKnownRd
178
- });
179
- return;
180
- }
181
- nodeInfoUrl = link.href;
182
- }
183
- const response = await fetch(nodeInfoUrl, { headers: {
184
- Accept: "application/json",
185
- "User-Agent": typeof options.userAgent === "string" ? options.userAgent : getUserAgent(options.userAgent)
186
- } });
187
- if (!response.ok) {
188
- logger.error("Failed to fetch NodeInfo document from {url}: {status} {statusText}", {
189
- url: nodeInfoUrl.toString(),
190
- status: response.status,
191
- statusText: response.statusText
192
- });
193
- return;
194
- }
195
- const data = await response.json();
196
- if (options.parse === "none") return data;
197
- return parseNodeInfo(data, { tryBestEffort: options.parse === "best-effort" }) ?? void 0;
198
- } catch (error) {
199
- logger.error("Failed to fetch NodeInfo document from {url}: {error}", {
200
- url: url.toString(),
201
- error
202
- });
203
- return;
204
- }
205
- }
206
- /**
207
- * Parses a NodeInfo document.
208
- * @param data A JSON value that complies with the NodeInfo schema.
209
- * @param options Options for parsing the NodeInfo document.
210
- * @returns The parsed NodeInfo document if it is valid. Otherwise, `null`
211
- * is returned.
212
- * @since 1.2.0
213
- */
214
- function parseNodeInfo(data, options = {}) {
215
- if (typeof data !== "object" || data == null || !("software" in data)) return null;
216
- const software = parseSoftware(data.software, options);
217
- if (software == null) return null;
218
- let protocols = [];
219
- if ("protocols" in data && Array.isArray(data.protocols)) {
220
- const ps = data.protocols.map(parseProtocol);
221
- protocols = ps.filter((p) => p != null);
222
- if (ps.length != protocols.length && !options.tryBestEffort) return null;
223
- } else if (!options.tryBestEffort) return null;
224
- let services;
225
- if ("services" in data) {
226
- if (typeof data.services === "object" && data.services != null) {
227
- const ss = parseServices(data.services, options);
228
- if (ss == null) {
229
- if (!options.tryBestEffort) return null;
230
- } else services = ss;
231
- } else if (!options.tryBestEffort) return null;
232
- }
233
- let openRegistrations;
234
- if ("openRegistrations" in data) {
235
- if (typeof data.openRegistrations === "boolean") openRegistrations = data.openRegistrations;
236
- else if (!options.tryBestEffort) return null;
237
- }
238
- let usage = {
239
- users: {},
240
- localPosts: 0,
241
- localComments: 0
242
- };
243
- if ("usage" in data) {
244
- const u = parseUsage(data.usage, options);
245
- if (u == null) {
246
- if (!options.tryBestEffort) return null;
247
- } else usage = u;
248
- }
249
- let metadata;
250
- if ("metadata" in data) {
251
- if (typeof data.metadata === "object" && data.metadata != null) metadata = Object.fromEntries(Object.entries(data.metadata));
252
- else if (!options.tryBestEffort) return null;
253
- }
254
- const result = {
255
- software,
256
- protocols,
257
- usage
258
- };
259
- if (services != null) result.services = services;
260
- if (openRegistrations != null) result.openRegistrations = openRegistrations;
261
- if (metadata != null) result.metadata = metadata;
262
- return result;
263
- }
264
- function parseSoftware(data, options = {}) {
265
- if (typeof data !== "object" || data == null) {
266
- if (!options.tryBestEffort) data = {};
267
- return null;
268
- }
269
- let name;
270
- if ("name" in data && typeof data.name === "string" && data.name.match(/^\s*[A-Za-z0-9-]+\s*$/)) {
271
- if (!data.name.match(/^[a-z0-9-]+$/) && !options.tryBestEffort) return null;
272
- name = data.name.trim().toLowerCase();
273
- } else return null;
274
- let version;
275
- if ("version" in data && typeof data.version === "string") try {
276
- version = parseSemVer(data.version);
277
- } catch {
278
- if (!options.tryBestEffort) return null;
279
- version = {
280
- major: 0,
281
- minor: 0,
282
- patch: 0,
283
- build: [],
284
- prerelease: []
285
- };
286
- }
287
- else {
288
- if (!options.tryBestEffort) return null;
289
- version = {
290
- major: 0,
291
- minor: 0,
292
- patch: 0,
293
- build: [],
294
- prerelease: []
295
- };
296
- }
297
- let repository;
298
- if ("repository" in data) {
299
- if (typeof data.repository === "string") try {
300
- repository = new URL(data.repository);
301
- } catch {
302
- if (!options.tryBestEffort) return null;
303
- }
304
- else if (!options.tryBestEffort) return null;
305
- }
306
- let homepage;
307
- if ("homepage" in data) {
308
- if (typeof data.homepage === "string") try {
309
- homepage = new URL(data.homepage);
310
- } catch {
311
- if (!options.tryBestEffort) return null;
312
- }
313
- else if (!options.tryBestEffort) return null;
314
- }
315
- const result = {
316
- name,
317
- version
318
- };
319
- if (repository != null) result.repository = repository;
320
- if (homepage != null) result.homepage = homepage;
321
- return result;
322
- }
323
- function parseProtocol(data) {
324
- if (data === "activitypub" || data === "buddycloud" || data === "dfrn" || data === "diaspora" || data === "libertree" || data === "ostatus" || data === "pumpio" || data === "tent" || data === "xmpp" || data === "zot") return data;
325
- return null;
326
- }
327
- function parseServices(data, options = {}) {
328
- if (!(typeof data === "object") || data == null) {
329
- if (options.tryBestEffort) return {};
330
- return null;
331
- }
332
- let inbound;
333
- if ("inbound" in data && Array.isArray(data.inbound)) {
334
- const is = data.inbound.map(parseInboundService);
335
- inbound = is.filter((i) => i != null);
336
- if (is.length > inbound.length && !options.tryBestEffort) return null;
337
- }
338
- let outbound;
339
- if ("outbound" in data && Array.isArray(data.outbound)) {
340
- const os = data.outbound.map(parseOutboundService);
341
- outbound = os.filter((o) => o != null);
342
- if (os.length > outbound.length && !options.tryBestEffort) return null;
343
- }
344
- const result = {};
345
- if (inbound != null) result.inbound = inbound;
346
- if (outbound != null) result.outbound = outbound;
347
- return result;
348
- }
349
- function parseInboundService(data) {
350
- if (data === "atom1.0" || data === "gnusocial" || data === "imap" || data === "pnut" || data === "pop3" || data === "pumpio" || data === "rss2.0" || data === "twitter") return data;
351
- return null;
352
- }
353
- function parseOutboundService(data) {
354
- if (data === "atom1.0" || data === "blogger" || data === "buddycloud" || data === "diaspora" || data === "dreamwidth" || data === "drupal" || data === "facebook" || data === "friendica" || data === "gnusocial" || data === "google" || data === "insanejournal" || data === "libertree" || data === "linkedin" || data === "livejournal" || data === "mediagoblin" || data === "myspace" || data === "pinterest" || data === "pnut" || data === "posterous" || data === "pumpio" || data === "redmatrix" || data === "rss2.0" || data === "smtp" || data === "tent" || data === "tumblr" || data === "twitter" || data === "wordpress" || data === "xmpp") return data;
355
- return null;
356
- }
357
- function parseUsage(data, options = {}) {
358
- if (typeof data !== "object" || data == null) return null;
359
- const users = {};
360
- if ("users" in data && typeof data.users === "object" && data.users != null) {
361
- if ("total" in data.users) if (typeof data.users.total === "number") users.total = data.users.total;
362
- else {
363
- if (!options.tryBestEffort) return null;
364
- if (typeof data.users.total === "string") {
365
- const n = parseInt(data.users.total);
366
- if (!isNaN(n)) users.total = n;
367
- }
368
- }
369
- if ("activeHalfyear" in data.users) if (typeof data.users.activeHalfyear === "number") users.activeHalfyear = data.users.activeHalfyear;
370
- else {
371
- if (!options.tryBestEffort) return null;
372
- if (typeof data.users.activeHalfyear === "string") {
373
- const n = parseInt(data.users.activeHalfyear);
374
- if (!isNaN(n)) users.activeHalfyear = n;
375
- }
376
- }
377
- if ("activeMonth" in data.users) if (typeof data.users.activeMonth === "number") users.activeMonth = data.users.activeMonth;
378
- else {
379
- if (!options.tryBestEffort) return null;
380
- if (typeof data.users.activeMonth === "string") {
381
- const n = parseInt(data.users.activeMonth);
382
- if (!isNaN(n)) users.activeMonth = n;
383
- }
384
- }
385
- } else if (!options.tryBestEffort) return null;
386
- let localPosts = 0;
387
- if ("localPosts" in data) if (typeof data.localPosts === "number") localPosts = data.localPosts;
388
- else {
389
- if (!options.tryBestEffort) return null;
390
- if (typeof data.localPosts === "string") {
391
- const n = parseInt(data.localPosts);
392
- if (!isNaN(n)) localPosts = n;
393
- }
394
- }
395
- let localComments = 0;
396
- if ("localComments" in data) if (typeof data.localComments === "number") localComments = data.localComments;
397
- else {
398
- if (!options.tryBestEffort) return null;
399
- if (typeof data.localComments === "string") {
400
- const n = parseInt(data.localComments);
401
- if (!isNaN(n)) localComments = n;
402
- }
403
- }
404
- return {
405
- users,
406
- localPosts,
407
- localComments
408
- };
409
- }
410
-
411
- //#endregion
412
- //#region nodeinfo/types.ts
413
- /**
414
- * Converts a {@link NodeInfo} object to a JSON value.
415
- * @param nodeInfo The {@link NodeInfo} object to convert.
416
- * @returns The JSON value that complies with the NodeInfo schema.
417
- * @throws {TypeError} If the {@link NodeInfo} object is invalid.
418
- */
419
- function nodeInfoToJson(nodeInfo) {
420
- if (!nodeInfo.software.name.match(/^[a-z0-9-]+$/)) throw new TypeError("Invalid software name.");
421
- if (nodeInfo.protocols.length < 1) throw new TypeError("At least one protocol must be supported.");
422
- if (nodeInfo.usage.users.total != null && (nodeInfo.usage.users.total < 0 || !Number.isInteger(nodeInfo.usage.users.total))) throw new TypeError("Invalid total users.");
423
- if (nodeInfo.usage.users.activeHalfyear != null && (nodeInfo.usage.users.activeHalfyear < 0 || !Number.isInteger(nodeInfo.usage.users.activeHalfyear))) throw new TypeError("Invalid active halfyear users.");
424
- if (nodeInfo.usage.users.activeMonth != null && (nodeInfo.usage.users.activeMonth < 0 || !Number.isInteger(nodeInfo.usage.users.activeMonth))) throw new TypeError("Invalid active month users.");
425
- if (nodeInfo.usage.localPosts < 0 || !Number.isInteger(nodeInfo.usage.localPosts)) throw new TypeError("Invalid local posts.");
426
- if (nodeInfo.usage.localComments < 0 || !Number.isInteger(nodeInfo.usage.localComments)) throw new TypeError("Invalid local comments.");
427
- return {
428
- "$schema": "http://nodeinfo.diaspora.software/ns/schema/2.1#",
429
- version: "2.1",
430
- software: {
431
- name: nodeInfo.software.name,
432
- version: formatSemVer(nodeInfo.software.version),
433
- repository: nodeInfo.software.repository?.href,
434
- homepage: nodeInfo.software.homepage?.href
435
- },
436
- protocols: nodeInfo.protocols,
437
- services: nodeInfo.services == null ? {
438
- inbound: [],
439
- outbound: []
440
- } : {
441
- inbound: nodeInfo.services.inbound ?? [],
442
- outbound: nodeInfo.services.outbound ?? []
443
- },
444
- openRegistrations: nodeInfo.openRegistrations ?? false,
445
- usage: {
446
- users: nodeInfo.usage.users,
447
- localPosts: nodeInfo.usage.localPosts,
448
- localComments: nodeInfo.usage.localComments
449
- },
450
- metadata: nodeInfo.metadata ?? {}
451
- };
452
- }
453
-
454
- //#endregion
455
- export { formatSemVer, getNodeInfo, nodeInfoToJson, parseNodeInfo, parseSemVer };
@@ -1,168 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
-
5
- import { deno_default, getDocumentLoader } from "./docloader-CchlnLWb.js";
6
- import { Object as Object$1, getTypeId } from "./actor-CsmPeeHG.js";
7
- import { lookupWebFinger } from "./lookup-CN-LpF5e.js";
8
- import { getLogger } from "@logtape/logtape";
9
- import { SpanStatusCode, trace } from "@opentelemetry/api";
10
- import { delay } from "@es-toolkit/es-toolkit";
11
-
12
- //#region vocab/lookup.ts
13
- const logger = getLogger([
14
- "fedify",
15
- "vocab",
16
- "lookup"
17
- ]);
18
- const handleRegexp = /^@?((?:[-A-Za-z0-9._~!$&'()*+,;=]|%[A-Fa-f0-9]{2})+)@([^@]+)$/;
19
- /**
20
- * Looks up an ActivityStreams object by its URI (including `acct:` URIs)
21
- * or a fediverse handle (e.g., `@user@server` or `user@server`).
22
- *
23
- * @example
24
- * ``` typescript
25
- * // Look up an actor by its fediverse handle:
26
- * await lookupObject("@hongminhee@fosstodon.org");
27
- * // returning a `Person` object.
28
- *
29
- * // A fediverse handle can omit the leading '@':
30
- * await lookupObject("hongminhee@fosstodon.org");
31
- * // returning a `Person` object.
32
- *
33
- * // A `acct:` URI can be used as well:
34
- * await lookupObject("acct:hongminhee@fosstodon.org");
35
- * // returning a `Person` object.
36
- *
37
- * // Look up an object by its URI:
38
- * await lookupObject("https://todon.eu/@hongminhee/112060633798771581");
39
- * // returning a `Note` object.
40
- *
41
- * // It can be a `URL` object as well:
42
- * await lookupObject(new URL("https://todon.eu/@hongminhee/112060633798771581"));
43
- * // returning a `Note` object.
44
- * ```
45
- *
46
- * @param identifier The URI or fediverse handle to look up.
47
- * @param options Lookup options.
48
- * @returns The object, or `null` if not found.
49
- * @since 0.2.0
50
- */
51
- async function lookupObject(identifier, options = {}) {
52
- return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(deno_default.name, deno_default.version).startActiveSpan("activitypub.lookup_object", async (span) => {
53
- try {
54
- const result = await lookupObjectInternal(identifier, options);
55
- if (result == null) span.setStatus({ code: SpanStatusCode.ERROR });
56
- else {
57
- if (result.id != null) span.setAttribute("activitypub.object.id", result.id.href);
58
- span.setAttribute("activitypub.object.type", getTypeId(result).href);
59
- if (result.replyTargetIds.length > 0) span.setAttribute("activitypub.object.in_reply_to", result.replyTargetIds.map((id) => id.href));
60
- }
61
- return result;
62
- } catch (error) {
63
- span.setStatus({
64
- code: SpanStatusCode.ERROR,
65
- message: String(error)
66
- });
67
- throw error;
68
- } finally {
69
- span.end();
70
- }
71
- });
72
- }
73
- async function lookupObjectInternal(identifier, options = {}) {
74
- const documentLoader = options.documentLoader ?? getDocumentLoader({ userAgent: options.userAgent });
75
- if (typeof identifier === "string") {
76
- const match = handleRegexp.exec(identifier);
77
- if (match) identifier = `acct:${match[1]}@${match[2]}`;
78
- identifier = new URL(identifier);
79
- }
80
- let document = null;
81
- if (identifier.protocol === "http:" || identifier.protocol === "https:") try {
82
- document = (await documentLoader(identifier.href)).document;
83
- } catch (error) {
84
- logger.debug("Failed to fetch remote document:\n{error}", { error });
85
- }
86
- if (document == null) {
87
- const jrd = await lookupWebFinger(identifier, {
88
- userAgent: options.userAgent,
89
- tracerProvider: options.tracerProvider,
90
- allowPrivateAddress: "allowPrivateAddress" in options && options.allowPrivateAddress === true
91
- });
92
- if (jrd?.links == null) return null;
93
- for (const l of jrd.links) {
94
- if (l.type !== "application/activity+json" && !l.type?.match(/application\/ld\+json;\s*profile="https:\/\/www.w3.org\/ns\/activitystreams"/) || l.rel !== "self") continue;
95
- try {
96
- document = (await documentLoader(l.href)).document;
97
- break;
98
- } catch (error) {
99
- logger.debug("Failed to fetch remote document:\n{error}", { error });
100
- continue;
101
- }
102
- }
103
- }
104
- if (document == null) return null;
105
- try {
106
- return await Object$1.fromJsonLd(document, {
107
- documentLoader,
108
- contextLoader: options.contextLoader,
109
- tracerProvider: options.tracerProvider
110
- });
111
- } catch (error) {
112
- if (error instanceof TypeError) {
113
- logger.debug("Failed to parse JSON-LD document: {error}\n{document}", {
114
- error,
115
- document
116
- });
117
- return null;
118
- }
119
- throw error;
120
- }
121
- }
122
- /**
123
- * Traverses a collection, yielding each item in the collection.
124
- * If the collection is paginated, it will fetch the next page
125
- * automatically.
126
- *
127
- * @example
128
- * ``` typescript
129
- * const collection = await lookupObject(collectionUrl);
130
- * if (collection instanceof Collection) {
131
- * for await (const item of traverseCollection(collection)) {
132
- * console.log(item.id?.href);
133
- * }
134
- * }
135
- * ```
136
- *
137
- * @param collection The collection to traverse.
138
- * @param options Options for traversing the collection.
139
- * @returns An async iterable of each item in the collection.
140
- * @since 1.1.0
141
- */
142
- async function* traverseCollection(collection, options = {}) {
143
- if (collection.firstId == null) for await (const item of collection.getItems(options)) yield item;
144
- else {
145
- const interval = Temporal.Duration.from(options.interval ?? { seconds: 0 }).total("millisecond");
146
- let page = await collection.getFirst(options);
147
- while (page != null) {
148
- for await (const item of page.getItems(options)) yield item;
149
- if (interval > 0) await delay(interval);
150
- page = await page.getNext(options);
151
- }
152
- }
153
- }
154
-
155
- //#endregion
156
- //#region vocab/constants.ts
157
- /**
158
- * The special public collection for [public addressing]. *Do not mutate this
159
- * object.*
160
- *
161
- * [public addressing]: https://www.w3.org/TR/activitypub/#public-addressing
162
- *
163
- * @since 0.7.0
164
- */
165
- const PUBLIC_COLLECTION = new URL("https://www.w3.org/ns/activitystreams#Public");
166
-
167
- //#endregion
168
- export { PUBLIC_COLLECTION, lookupObject, traverseCollection };
@@ -1,4 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
-
File without changes