@fedify/fedify 1.7.14 → 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 (163) hide show
  1. package/dist/{actor-Dx5YX74F.d.ts → actor.d.ts} +2 -2
  2. package/dist/{actor-y7shp0CR.js → actor.js} +4 -4
  3. package/dist/{assert-C-mZuSQl.js → assert.js} +1 -1
  4. package/dist/{assert_instance_of-lS0Jr2iu.js → assert_instance_of.js} +1 -1
  5. package/dist/{assert_is_error-CIYFACrT.js → assert_is_error.js} +1 -1
  6. package/dist/{assert_not_equals-C1azCAB0.js → assert_not_equals.js} +1 -1
  7. package/dist/{assert_rejects-Bkh5lA1a.js → assert_rejects.js} +2 -2
  8. package/dist/{assert_throws-CmpfkWEM.js → assert_throws.js} +2 -2
  9. package/dist/{authdocloader-C0JcfxUs.js → authdocloader.js} +4 -4
  10. package/dist/{builder-DaECqbbT.js → builder.js} +5 -5
  11. package/dist/{client-wKLuY12i.d.ts → client.d.ts} +1 -1
  12. package/dist/{client-dfu57WLy.js → client.js} +2 -2
  13. package/dist/compat/{mod-Bwqav33K.d.ts → mod.d.ts} +2 -2
  14. package/dist/compat/mod.js +1 -1
  15. package/dist/compat/transformers.test.js +30 -30
  16. package/dist/{context-CW_8R4BH.d.ts → context.d.ts} +10 -10
  17. package/dist/{context-nxDPfAiA.js → context.js} +4 -4
  18. package/dist/{docloader-D_MGP37Q.d.ts → docloader.d.ts} +1 -1
  19. package/dist/{docloader-sGz4vcrK.js → docloader.js} +2 -2
  20. package/dist/{esm-BRXvTSrx.js → esm.js} +1 -1
  21. package/dist/federation/builder.test.js +17 -17
  22. package/dist/federation/collection.test.js +8 -8
  23. package/dist/federation/handler.test.js +36 -36
  24. package/dist/federation/inbox.test.js +11 -11
  25. package/dist/federation/keycache.test.js +12 -12
  26. package/dist/federation/kv.test.js +8 -8
  27. package/dist/federation/middleware.test.js +39 -39
  28. package/dist/federation/{mod-DvlLc8Ru.d.ts → mod.d.ts} +3 -3
  29. package/dist/federation/mod.js +11 -11
  30. package/dist/federation/mq.test.js +10 -10
  31. package/dist/federation/retry.test.js +5 -5
  32. package/dist/federation/router.test.js +9 -9
  33. package/dist/federation/send.test.js +23 -23
  34. package/dist/{http-DFZRNfDP.d.ts → http.d.ts} +2 -2
  35. package/dist/{http-BhES0Sg9.js → http.js} +3 -3
  36. package/dist/{inbox-Z_QlSGYN.js → inbox.js} +3 -3
  37. package/dist/key.js +16 -0
  38. package/dist/{key-bMrDyA2T.js → key2.js} +3 -3
  39. package/dist/{keycache-B5Rr8Lbc.js → keycache.js} +1 -1
  40. package/dist/{keys-DK4k1R8e.js → keys.js} +1 -1
  41. package/dist/{ld--auFISy7.js → ld.js} +4 -4
  42. package/dist/{lookup-CqI9jhXo.d.ts → lookup.d.ts} +1 -1
  43. package/dist/{lookup-Bq8vhIG4.js → lookup.js} +2 -2
  44. package/dist/{lookup-cHV4n1IB.js → lookup2.js} +4 -4
  45. package/dist/{middleware-B7p-onxQ.js → middleware.js} +20 -20
  46. package/dist/middleware2.js +32 -0
  47. package/dist/{mod-DMn4Bxyg.d.ts → mod.d.ts} +17 -17
  48. package/dist/mod.js +11 -11
  49. package/dist/{mod-DjGYGrBd.d.ts → mod2.d.ts} +2 -2
  50. package/dist/{mod-BEZy4WHZ.d.ts → mod3.d.ts} +3 -3
  51. package/dist/nodeinfo/client.test.js +12 -12
  52. package/dist/nodeinfo/handler.test.js +34 -34
  53. package/dist/nodeinfo/{mod--upgPcaX.d.ts → mod.d.ts} +1 -1
  54. package/dist/nodeinfo/mod.js +2 -2
  55. package/dist/nodeinfo/semver.test.js +8 -8
  56. package/dist/nodeinfo/types.test.js +9 -9
  57. package/dist/{owner-CewLNqWO.d.ts → owner.d.ts} +3 -3
  58. package/dist/{owner-DkTRLQAV.js → owner.js} +3 -3
  59. package/dist/{proof-DT_xxRPF.js → proof.js} +4 -4
  60. package/dist/runtime/authdocloader.test.js +20 -20
  61. package/dist/runtime/docloader.test.js +13 -13
  62. package/dist/runtime/key.test.js +15 -15
  63. package/dist/runtime/langstr.test.js +8 -8
  64. package/dist/runtime/{mod-BaH1vtHp.d.ts → mod.d.ts} +3 -3
  65. package/dist/runtime/mod.js +6 -6
  66. package/dist/runtime/multibase/multibase.test.js +8 -8
  67. package/dist/runtime/url.test.js +7 -7
  68. package/dist/{send-axIyQX2p.js → send.js} +2 -2
  69. package/dist/sig/http.test.js +20 -20
  70. package/dist/sig/key.test.js +17 -17
  71. package/dist/sig/ld.test.js +18 -18
  72. package/dist/sig/{mod-BmJQTnPT.d.ts → mod.d.ts} +3 -3
  73. package/dist/sig/mod.js +6 -6
  74. package/dist/sig/owner.test.js +20 -20
  75. package/dist/sig/proof.test.js +19 -19
  76. package/dist/{std__assert-BdP_WkD-.js → std__assert.js} +1 -1
  77. package/dist/testing/docloader.test.js +8 -8
  78. package/dist/testing/mod.js +2 -2
  79. package/dist/{testing-qaAD4B0t.js → testing.js} +1 -1
  80. package/dist/{types-CB_2uuCA.js → types.js} +1 -1
  81. package/dist/vocab/actor.test.js +16 -16
  82. package/dist/vocab/lookup.test.js +17 -17
  83. package/dist/vocab/{mod-BkXGAYkx.d.ts → mod.d.ts} +3 -3
  84. package/dist/vocab/mod.js +4 -4
  85. package/dist/vocab/type.test.js +9 -9
  86. package/dist/vocab/vocab.test.js +17 -17
  87. package/dist/{vocab-DoBcp8ow.d.ts → vocab.d.ts} +1 -1
  88. package/dist/{vocab-DCHRuBGF.js → vocab.js} +181 -181
  89. package/dist/webfinger/handler.test.js +34 -34
  90. package/dist/webfinger/lookup.test.js +11 -11
  91. package/dist/webfinger/{mod-B1UhCvlL.d.ts → mod.d.ts} +1 -1
  92. package/dist/webfinger/mod.js +2 -2
  93. package/dist/x/{cfworkers-BIcR64Sf.d.ts → cfworkers.d.ts} +2 -2
  94. package/dist/x/cfworkers.test.js +7 -7
  95. package/dist/x/{hono-DmQmp8wi.d.ts → hono.d.ts} +1 -1
  96. package/dist/x/{sveltekit-Cvh0XnN4.d.ts → sveltekit.d.ts} +1 -1
  97. package/package.json +1 -1
  98. package/dist/actor-OYVgkiZG.js +0 -34789
  99. package/dist/authdocloader-C2krvRo1.js +0 -49
  100. package/dist/docloader-BU25UQLB.js +0 -4478
  101. package/dist/http-DRePVWfE.js +0 -788
  102. package/dist/key-CJuc1GE1.js +0 -10
  103. package/dist/key-D2HZrCxh.js +0 -257
  104. package/dist/key-eP5Yk7hl.js +0 -16
  105. package/dist/lookup-4uc2jh52.js +0 -127
  106. package/dist/middleware-72Tuh6Iw.js +0 -17
  107. package/dist/middleware-DB3BUysJ.js +0 -32
  108. package/dist/middleware-QJjRfjjc.js +0 -3519
  109. package/dist/proof-D4HXHDPz.js +0 -577
  110. package/dist/types-Bk4b1bGc.js +0 -445
  111. package/dist/vocab-sMuiKIWm.js +0 -168
  112. /package/dist/{assert_equals-Dy0MG_Zw.js → assert_equals.js} +0 -0
  113. /package/dist/{chunk-DvTpRkcT.js → chunk.js} +0 -0
  114. /package/dist/{collection-XNLQhehO.js → collection.js} +0 -0
  115. /package/dist/compat/{transformers.test-DnJbd34u.d.ts → transformers.test.d.ts} +0 -0
  116. /package/dist/{denokv-NcJeZ6rP.js → denokv.js} +0 -0
  117. /package/dist/{docloader-BDSHZfTJ.js → docloader2.js} +0 -0
  118. /package/dist/federation/{builder.test-Bpt6NOZ6.d.ts → builder.test.d.ts} +0 -0
  119. /package/dist/federation/{collection.test-DKJ6JOZz.d.ts → collection.test.d.ts} +0 -0
  120. /package/dist/federation/{handler.test-BMT7uLC0.d.ts → handler.test.d.ts} +0 -0
  121. /package/dist/federation/{inbox.test-Do6i02Qp.d.ts → inbox.test.d.ts} +0 -0
  122. /package/dist/federation/{keycache.test-BT83IPZY.d.ts → keycache.test.d.ts} +0 -0
  123. /package/dist/federation/{kv.test-kFzzF2VN.d.ts → kv.test.d.ts} +0 -0
  124. /package/dist/federation/{middleware.test-B1R4_e3-.d.ts → middleware.test.d.ts} +0 -0
  125. /package/dist/federation/{mq.test-l79EQQOe.d.ts → mq.test.d.ts} +0 -0
  126. /package/dist/federation/{retry.test-BqS50VCX.d.ts → retry.test.d.ts} +0 -0
  127. /package/dist/federation/{router.test-CYQl4po-.d.ts → router.test.d.ts} +0 -0
  128. /package/dist/federation/{send.test-COUnNUzv.d.ts → send.test.d.ts} +0 -0
  129. /package/dist/{kv-CKqSUxHd.d.ts → kv.d.ts} +0 -0
  130. /package/dist/{kv-QeuZ51go.js → kv.js} +0 -0
  131. /package/dist/{langstr-pFHBDU4y.js → langstr.js} +0 -0
  132. /package/dist/{mq-Cgfbl44M.d.ts → mq.d.ts} +0 -0
  133. /package/dist/{multibase-DBcKTV2a.js → multibase.js} +0 -0
  134. /package/dist/nodeinfo/{client.test-CZLe79hL.d.ts → client.test.d.ts} +0 -0
  135. /package/dist/nodeinfo/{handler.test-B-EDZ_hK.d.ts → handler.test.d.ts} +0 -0
  136. /package/dist/nodeinfo/{semver.test-BEuuQSEM.d.ts → semver.test.d.ts} +0 -0
  137. /package/dist/nodeinfo/{types.test-B5AT89WV.d.ts → types.test.d.ts} +0 -0
  138. /package/dist/{retry-BQet39_l.js → retry.js} +0 -0
  139. /package/dist/{router-BuDkN4RQ.js → router.js} +0 -0
  140. /package/dist/runtime/{authdocloader.test-hCRKzn9v.d.ts → authdocloader.test.d.ts} +0 -0
  141. /package/dist/runtime/{docloader.test-CVd7i_5h.d.ts → docloader.test.d.ts} +0 -0
  142. /package/dist/runtime/{key.test-DBsILYSD.d.ts → key.test.d.ts} +0 -0
  143. /package/dist/runtime/{langstr.test-CiKxuuRY.d.ts → langstr.test.d.ts} +0 -0
  144. /package/dist/runtime/multibase/{multibase.test-Brh6gPBP.d.ts → multibase.test.d.ts} +0 -0
  145. /package/dist/runtime/{url.test-DlRqkU2j.d.ts → url.test.d.ts} +0 -0
  146. /package/dist/{semver-D9d-VO-_.js → semver.js} +0 -0
  147. /package/dist/sig/{http.test-BpXNAWNI.d.ts → http.test.d.ts} +0 -0
  148. /package/dist/sig/{key.test-B2iLIugy.d.ts → key.test.d.ts} +0 -0
  149. /package/dist/sig/{ld.test-D-cI70Gw.d.ts → ld.test.d.ts} +0 -0
  150. /package/dist/sig/{owner.test-B_YRjMPj.d.ts → owner.test.d.ts} +0 -0
  151. /package/dist/sig/{proof.test-BagEM_-4.d.ts → proof.test.d.ts} +0 -0
  152. /package/dist/testing/{docloader.test-lrzf6sDZ.d.ts → docloader.test.d.ts} +0 -0
  153. /package/dist/testing/{mod-3uM8ZvS7.d.ts → mod.d.ts} +0 -0
  154. /package/dist/{transformers-CFSWUhNi.js → transformers.js} +0 -0
  155. /package/dist/{type-DFsmi-p1.js → type.js} +0 -0
  156. /package/dist/{url-BdNvnK9P.js → url.js} +0 -0
  157. /package/dist/vocab/{actor.test-ClC-iVWk.d.ts → actor.test.d.ts} +0 -0
  158. /package/dist/vocab/{lookup.test-Cq1I-27w.d.ts → lookup.test.d.ts} +0 -0
  159. /package/dist/vocab/{type.test-bfFiYGcs.d.ts → type.test.d.ts} +0 -0
  160. /package/dist/vocab/{vocab.test-h-ZTisfu.d.ts → vocab.test.d.ts} +0 -0
  161. /package/dist/webfinger/{handler.test-DiUeEDDD.d.ts → handler.test.d.ts} +0 -0
  162. /package/dist/webfinger/{lookup.test-D9onm3U3.d.ts → lookup.test.d.ts} +0 -0
  163. /package/dist/x/{cfworkers.test-KXHlJ29z.d.ts → cfworkers.test.d.ts} +0 -0
@@ -1,445 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
-
5
- import { o as getUserAgent } from "./docloader-BU25UQLB.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 version, followed optionally by a pre-release version and build metadata.
37
- */
38
- const FULL_VERSION = `v?${VERSION_CORE}${PRERELEASE}?${`(?:\\+(?<buildmetadata>${BUILD_IDENTIFIER}(?:\\.${BUILD_IDENTIFIER})*))`}?`;
39
- const FULL_REGEXP = /* @__PURE__ */ new RegExp(`^${FULL_VERSION}$`);
40
- /**
41
- * Attempt to parse a string as a semantic version, returning a SemVer object.
42
- *
43
- * @example Usage
44
- * ```ts
45
- * import { parseSemVer } from "@fedify/fedify/nodeinfo";
46
- * import { assertEquals } from "@std/assert";
47
- *
48
- * const version = parseSemVer("1.2.3");
49
- * assertEquals(version, {
50
- * major: 1,
51
- * minor: 2,
52
- * patch: 3,
53
- * prerelease: [],
54
- * build: [],
55
- * });
56
- * ```
57
- *
58
- * @throws {TypeError} If the input string is invalid.
59
- * @param value The version string to parse
60
- * @returns A valid SemVer
61
- * @since 1.2.0
62
- */
63
- function parseSemVer(value) {
64
- if (typeof value !== "string") throw new TypeError(`Cannot parse version as version must be a string: received ${typeof value}`);
65
- 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}`);
66
- value = value.trim();
67
- const groups = value.match(FULL_REGEXP)?.groups;
68
- if (!groups) throw new TypeError(`Cannot parse version: ${value}`);
69
- return {
70
- major: parseNumber(groups.major, `Cannot parse version ${value}: invalid major version`),
71
- minor: parseNumber(groups.minor, `Cannot parse version ${value}: invalid minor version`),
72
- patch: parseNumber(groups.patch, `Cannot parse version ${value}: invalid patch version`),
73
- prerelease: groups.prerelease ? parsePrerelease(groups.prerelease) : [],
74
- build: groups.buildmetadata ? parseBuild(groups.buildmetadata) : []
75
- };
76
- }
77
- /**
78
- * Returns true if the value is a valid SemVer number.
79
- *
80
- * Must be a number. Must not be NaN. Can be positive or negative infinity.
81
- * Can be between 0 and MAX_SAFE_INTEGER.
82
- * @param value The value to check
83
- * @returns True if its a valid semver number
84
- */
85
- function isValidNumber(value) {
86
- return typeof value === "number" && !Number.isNaN(value) && (!Number.isFinite(value) || 0 <= value && value <= Number.MAX_SAFE_INTEGER);
87
- }
88
- const NUMERIC_IDENTIFIER_REGEXP = /* @__PURE__ */ new RegExp(`^${NUMERIC_IDENTIFIER}$`);
89
- function parsePrerelease(prerelease) {
90
- return prerelease.split(".").filter(Boolean).map((id) => {
91
- if (NUMERIC_IDENTIFIER_REGEXP.test(id)) {
92
- const number = Number(id);
93
- if (isValidNumber(number)) return number;
94
- }
95
- return id;
96
- });
97
- }
98
- function parseBuild(buildmetadata) {
99
- return buildmetadata.split(".").filter(Boolean);
100
- }
101
- function parseNumber(input, errorMessage) {
102
- const number = Number(input);
103
- if (!isValidNumber(number)) throw new TypeError(errorMessage);
104
- return number;
105
- }
106
- function formatNumber(value) {
107
- return value.toFixed(0);
108
- }
109
- /**
110
- * Format a SemVer object into a string.
111
- *
112
- * @example Usage
113
- * ```ts
114
- * import { formatSemVer } from "@fedify/fedify/nodeinfo";
115
- * import { assertEquals } from "@std/assert";
116
- *
117
- * const semver = {
118
- * major: 1,
119
- * minor: 2,
120
- * patch: 3,
121
- * };
122
- * assertEquals(formatSemVer(semver), "1.2.3");
123
- * ```
124
- *
125
- * @param version The SemVer to format
126
- * @returns The string representation of a semantic version.
127
- * @since 1.2.0
128
- */
129
- function formatSemVer(version) {
130
- const major = formatNumber(version.major);
131
- const minor = formatNumber(version.minor);
132
- const patch = formatNumber(version.patch);
133
- const pre = version.prerelease?.join(".") ?? "";
134
- const build = version.build?.join(".") ?? "";
135
- return [[`${major}.${minor}.${patch}`, pre].filter((v) => v).join("-"), build].filter((v) => v).join("+");
136
- }
137
-
138
- //#endregion
139
- //#region nodeinfo/client.ts
140
- const logger = getLogger([
141
- "fedify",
142
- "nodeinfo",
143
- "client"
144
- ]);
145
- async function getNodeInfo(url, options = {}) {
146
- try {
147
- let nodeInfoUrl = url;
148
- if (!options.direct) {
149
- const wellKnownUrl = new URL("/.well-known/nodeinfo", url);
150
- const wellKnownResponse = await fetch(wellKnownUrl, { headers: {
151
- Accept: "application/json",
152
- "User-Agent": typeof options.userAgent === "string" ? options.userAgent : getUserAgent(options.userAgent)
153
- } });
154
- if (!wellKnownResponse.ok) {
155
- logger.error("Failed to fetch {url}: {status} {statusText}", {
156
- url: wellKnownUrl.href,
157
- status: wellKnownResponse.status,
158
- statusText: wellKnownResponse.statusText
159
- });
160
- return;
161
- }
162
- const wellKnownRd = await wellKnownResponse.json();
163
- 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);
164
- if (link == null) {
165
- logger.error("Failed to find a NodeInfo document link from {url}: {resourceDescriptor}", {
166
- url: wellKnownUrl.href,
167
- resourceDescriptor: wellKnownRd
168
- });
169
- return;
170
- }
171
- nodeInfoUrl = link.href;
172
- }
173
- const response = await fetch(nodeInfoUrl, { headers: {
174
- Accept: "application/json",
175
- "User-Agent": typeof options.userAgent === "string" ? options.userAgent : getUserAgent(options.userAgent)
176
- } });
177
- if (!response.ok) {
178
- logger.error("Failed to fetch NodeInfo document from {url}: {status} {statusText}", {
179
- url: nodeInfoUrl.toString(),
180
- status: response.status,
181
- statusText: response.statusText
182
- });
183
- return;
184
- }
185
- const data = await response.json();
186
- if (options.parse === "none") return data;
187
- return parseNodeInfo(data, { tryBestEffort: options.parse === "best-effort" }) ?? void 0;
188
- } catch (error) {
189
- logger.error("Failed to fetch NodeInfo document from {url}: {error}", {
190
- url: url.toString(),
191
- error
192
- });
193
- return;
194
- }
195
- }
196
- /**
197
- * Parses a NodeInfo document.
198
- * @param data A JSON value that complies with the NodeInfo schema.
199
- * @param options Options for parsing the NodeInfo document.
200
- * @returns The parsed NodeInfo document if it is valid. Otherwise, `null`
201
- * is returned.
202
- * @since 1.2.0
203
- */
204
- function parseNodeInfo(data, options = {}) {
205
- if (typeof data !== "object" || data == null || !("software" in data)) return null;
206
- const software = parseSoftware(data.software, options);
207
- if (software == null) return null;
208
- let protocols = [];
209
- if ("protocols" in data && Array.isArray(data.protocols)) {
210
- const ps = data.protocols.map(parseProtocol);
211
- protocols = ps.filter((p) => p != null);
212
- if (ps.length != protocols.length && !options.tryBestEffort) return null;
213
- } else if (!options.tryBestEffort) return null;
214
- let services;
215
- if ("services" in data) {
216
- if (typeof data.services === "object" && data.services != null) {
217
- const ss = parseServices(data.services, options);
218
- if (ss == null) {
219
- if (!options.tryBestEffort) return null;
220
- } else services = ss;
221
- } else if (!options.tryBestEffort) return null;
222
- }
223
- let openRegistrations;
224
- if ("openRegistrations" in data) {
225
- if (typeof data.openRegistrations === "boolean") openRegistrations = data.openRegistrations;
226
- else if (!options.tryBestEffort) return null;
227
- }
228
- let usage = {
229
- users: {},
230
- localPosts: 0,
231
- localComments: 0
232
- };
233
- if ("usage" in data) {
234
- const u = parseUsage(data.usage, options);
235
- if (u == null) {
236
- if (!options.tryBestEffort) return null;
237
- } else usage = u;
238
- }
239
- let metadata;
240
- if ("metadata" in data) {
241
- if (typeof data.metadata === "object" && data.metadata != null) metadata = Object.fromEntries(Object.entries(data.metadata));
242
- else if (!options.tryBestEffort) return null;
243
- }
244
- const result = {
245
- software,
246
- protocols,
247
- usage
248
- };
249
- if (services != null) result.services = services;
250
- if (openRegistrations != null) result.openRegistrations = openRegistrations;
251
- if (metadata != null) result.metadata = metadata;
252
- return result;
253
- }
254
- function parseSoftware(data, options = {}) {
255
- if (typeof data !== "object" || data == null) {
256
- if (!options.tryBestEffort) data = {};
257
- return null;
258
- }
259
- let name;
260
- if ("name" in data && typeof data.name === "string" && data.name.match(/^\s*[A-Za-z0-9-]+\s*$/)) {
261
- if (!data.name.match(/^[a-z0-9-]+$/) && !options.tryBestEffort) return null;
262
- name = data.name.trim().toLowerCase();
263
- } else return null;
264
- let version;
265
- if ("version" in data && typeof data.version === "string") try {
266
- version = parseSemVer(data.version);
267
- } catch {
268
- if (!options.tryBestEffort) return null;
269
- version = {
270
- major: 0,
271
- minor: 0,
272
- patch: 0,
273
- build: [],
274
- prerelease: []
275
- };
276
- }
277
- else {
278
- if (!options.tryBestEffort) return null;
279
- version = {
280
- major: 0,
281
- minor: 0,
282
- patch: 0,
283
- build: [],
284
- prerelease: []
285
- };
286
- }
287
- let repository;
288
- if ("repository" in data) {
289
- if (typeof data.repository === "string") try {
290
- repository = new URL(data.repository);
291
- } catch {
292
- if (!options.tryBestEffort) return null;
293
- }
294
- else if (!options.tryBestEffort) return null;
295
- }
296
- let homepage;
297
- if ("homepage" in data) {
298
- if (typeof data.homepage === "string") try {
299
- homepage = new URL(data.homepage);
300
- } catch {
301
- if (!options.tryBestEffort) return null;
302
- }
303
- else if (!options.tryBestEffort) return null;
304
- }
305
- const result = {
306
- name,
307
- version
308
- };
309
- if (repository != null) result.repository = repository;
310
- if (homepage != null) result.homepage = homepage;
311
- return result;
312
- }
313
- function parseProtocol(data) {
314
- if (data === "activitypub" || data === "buddycloud" || data === "dfrn" || data === "diaspora" || data === "libertree" || data === "ostatus" || data === "pumpio" || data === "tent" || data === "xmpp" || data === "zot") return data;
315
- return null;
316
- }
317
- function parseServices(data, options = {}) {
318
- if (!(typeof data === "object") || data == null) {
319
- if (options.tryBestEffort) return {};
320
- return null;
321
- }
322
- let inbound;
323
- if ("inbound" in data && Array.isArray(data.inbound)) {
324
- const is = data.inbound.map(parseInboundService);
325
- inbound = is.filter((i) => i != null);
326
- if (is.length > inbound.length && !options.tryBestEffort) return null;
327
- }
328
- let outbound;
329
- if ("outbound" in data && Array.isArray(data.outbound)) {
330
- const os = data.outbound.map(parseOutboundService);
331
- outbound = os.filter((o) => o != null);
332
- if (os.length > outbound.length && !options.tryBestEffort) return null;
333
- }
334
- const result = {};
335
- if (inbound != null) result.inbound = inbound;
336
- if (outbound != null) result.outbound = outbound;
337
- return result;
338
- }
339
- function parseInboundService(data) {
340
- if (data === "atom1.0" || data === "gnusocial" || data === "imap" || data === "pnut" || data === "pop3" || data === "pumpio" || data === "rss2.0" || data === "twitter") return data;
341
- return null;
342
- }
343
- function parseOutboundService(data) {
344
- 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;
345
- return null;
346
- }
347
- function parseUsage(data, options = {}) {
348
- if (typeof data !== "object" || data == null) return null;
349
- const users = {};
350
- if ("users" in data && typeof data.users === "object" && data.users != null) {
351
- if ("total" in data.users) if (typeof data.users.total === "number") users.total = data.users.total;
352
- else {
353
- if (!options.tryBestEffort) return null;
354
- if (typeof data.users.total === "string") {
355
- const n = parseInt(data.users.total);
356
- if (!isNaN(n)) users.total = n;
357
- }
358
- }
359
- if ("activeHalfyear" in data.users) if (typeof data.users.activeHalfyear === "number") users.activeHalfyear = data.users.activeHalfyear;
360
- else {
361
- if (!options.tryBestEffort) return null;
362
- if (typeof data.users.activeHalfyear === "string") {
363
- const n = parseInt(data.users.activeHalfyear);
364
- if (!isNaN(n)) users.activeHalfyear = n;
365
- }
366
- }
367
- if ("activeMonth" in data.users) if (typeof data.users.activeMonth === "number") users.activeMonth = data.users.activeMonth;
368
- else {
369
- if (!options.tryBestEffort) return null;
370
- if (typeof data.users.activeMonth === "string") {
371
- const n = parseInt(data.users.activeMonth);
372
- if (!isNaN(n)) users.activeMonth = n;
373
- }
374
- }
375
- } else if (!options.tryBestEffort) return null;
376
- let localPosts = 0;
377
- if ("localPosts" in data) if (typeof data.localPosts === "number") localPosts = data.localPosts;
378
- else {
379
- if (!options.tryBestEffort) return null;
380
- if (typeof data.localPosts === "string") {
381
- const n = parseInt(data.localPosts);
382
- if (!isNaN(n)) localPosts = n;
383
- }
384
- }
385
- let localComments = 0;
386
- if ("localComments" in data) if (typeof data.localComments === "number") localComments = data.localComments;
387
- else {
388
- if (!options.tryBestEffort) return null;
389
- if (typeof data.localComments === "string") {
390
- const n = parseInt(data.localComments);
391
- if (!isNaN(n)) localComments = n;
392
- }
393
- }
394
- return {
395
- users,
396
- localPosts,
397
- localComments
398
- };
399
- }
400
-
401
- //#endregion
402
- //#region nodeinfo/types.ts
403
- /**
404
- * Converts a {@link NodeInfo} object to a JSON value.
405
- * @param nodeInfo The {@link NodeInfo} object to convert.
406
- * @returns The JSON value that complies with the NodeInfo schema.
407
- * @throws {TypeError} If the {@link NodeInfo} object is invalid.
408
- */
409
- function nodeInfoToJson(nodeInfo) {
410
- if (!nodeInfo.software.name.match(/^[a-z0-9-]+$/)) throw new TypeError("Invalid software name.");
411
- if (nodeInfo.protocols.length < 1) throw new TypeError("At least one protocol must be supported.");
412
- if (nodeInfo.usage.users.total != null && (nodeInfo.usage.users.total < 0 || !Number.isInteger(nodeInfo.usage.users.total))) throw new TypeError("Invalid total users.");
413
- if (nodeInfo.usage.users.activeHalfyear != null && (nodeInfo.usage.users.activeHalfyear < 0 || !Number.isInteger(nodeInfo.usage.users.activeHalfyear))) throw new TypeError("Invalid active halfyear users.");
414
- if (nodeInfo.usage.users.activeMonth != null && (nodeInfo.usage.users.activeMonth < 0 || !Number.isInteger(nodeInfo.usage.users.activeMonth))) throw new TypeError("Invalid active month users.");
415
- if (nodeInfo.usage.localPosts < 0 || !Number.isInteger(nodeInfo.usage.localPosts)) throw new TypeError("Invalid local posts.");
416
- if (nodeInfo.usage.localComments < 0 || !Number.isInteger(nodeInfo.usage.localComments)) throw new TypeError("Invalid local comments.");
417
- return {
418
- "$schema": "http://nodeinfo.diaspora.software/ns/schema/2.1#",
419
- version: "2.1",
420
- software: {
421
- name: nodeInfo.software.name,
422
- version: formatSemVer(nodeInfo.software.version),
423
- repository: nodeInfo.software.repository?.href,
424
- homepage: nodeInfo.software.homepage?.href
425
- },
426
- protocols: nodeInfo.protocols,
427
- services: nodeInfo.services == null ? {
428
- inbound: [],
429
- outbound: []
430
- } : {
431
- inbound: nodeInfo.services.inbound ?? [],
432
- outbound: nodeInfo.services.outbound ?? []
433
- },
434
- openRegistrations: nodeInfo.openRegistrations ?? false,
435
- usage: {
436
- users: nodeInfo.usage.users,
437
- localPosts: nodeInfo.usage.localPosts,
438
- localComments: nodeInfo.usage.localComments
439
- },
440
- metadata: nodeInfo.metadata ?? {}
441
- };
442
- }
443
-
444
- //#endregion
445
- export { parseSemVer as a, formatSemVer as i, getNodeInfo as n, parseNodeInfo as r, nodeInfoToJson as t };
@@ -1,168 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
-
5
- import { d as name, f as version, i as getDocumentLoader } from "./docloader-BU25UQLB.js";
6
- import { Tt as getTypeId, q as Object$1 } from "./actor-OYVgkiZG.js";
7
- import { t as lookupWebFinger } from "./lookup-4uc2jh52.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(name, 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 { lookupObject as n, traverseCollection as r, PUBLIC_COLLECTION as t };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes