@fedify/vocab-runtime 2.0.7 → 2.0.9
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.
- package/deno.json +1 -1
- package/dist/{chunk-CUT6urMc.cjs → chunk-CKQMccvm.cjs} +7 -9
- package/dist/jsonld.cjs +4 -5
- package/dist/jsonld.d.cts +3 -4
- package/dist/jsonld.d.ts +2 -2
- package/dist/jsonld.js +1 -3
- package/dist/mod.cjs +83 -131
- package/dist/mod.d.cts +1 -5
- package/dist/mod.d.ts +1 -5
- package/dist/mod.js +59 -110
- package/dist/tests/{chunk-DWy1uDak.cjs → chunk-Do9eywBl.cjs} +13 -17
- package/dist/tests/docloader.test.cjs +137 -114
- package/dist/tests/{docloader.test.js → docloader.test.mjs} +132 -115
- package/dist/tests/internal/multicodec.test.cjs +5 -7
- package/dist/tests/internal/{multicodec.test.js → multicodec.test.mjs} +3 -4
- package/dist/tests/key.test.cjs +39 -70
- package/dist/tests/{key.test.js → key.test.mjs} +32 -62
- package/dist/tests/langstr.test.cjs +6 -8
- package/dist/tests/{langstr.test.js → langstr.test.mjs} +2 -4
- package/dist/tests/{link-CdFPEo9O.cjs → link-B6ZWBZhf.cjs} +6 -8
- package/dist/tests/{link-Ck2yj4dH.js → link-B8JGXSS2.mjs} +1 -2
- package/dist/tests/link.test.cjs +5 -7
- package/dist/tests/{link.test.js → link.test.mjs} +3 -4
- package/dist/tests/multibase/multibase.test.cjs +10 -17
- package/dist/tests/multibase/{multibase.test.js → multibase.test.mjs} +10 -18
- package/dist/tests/{multibase-B2D6B0V4.cjs → multibase-CgYqpk4Z.cjs} +43 -49
- package/dist/tests/{multibase-BdHCGO4H.js → multibase-jcKrOpuU.mjs} +5 -12
- package/dist/tests/{multicodec-mHcRzSGY.cjs → multicodec-DeYop8xg.cjs} +16 -18
- package/dist/tests/{multicodec-DvC5xnX2.js → multicodec-aqbZnrNi.mjs} +1 -2
- package/dist/tests/{request-BZixuWv5.js → request-AitXfW_2.mjs} +4 -45
- package/dist/tests/{request-78UEYyIx.cjs → request-C6iSYeYi.cjs} +38 -72
- package/dist/tests/request.test.cjs +23 -24
- package/dist/tests/request.test.mjs +42 -0
- package/dist/tests/{url-C5Vs9nYh.cjs → url-Cr2K-wzd.cjs} +31 -35
- package/dist/tests/{url-fW_DHbih.js → url-Djghaq0m.mjs} +3 -7
- package/dist/tests/url.test.cjs +5 -7
- package/dist/tests/{url.test.js → url.test.mjs} +3 -4
- package/package.json +3 -3
- package/src/docloader.test.ts +67 -0
- package/src/docloader.ts +43 -11
- package/dist/tests/request.test.js +0 -43
- /package/dist/tests/{docloader.test.d.ts → docloader.test.d.mts} +0 -0
- /package/dist/tests/internal/{multicodec.test.d.ts → multicodec.test.d.mts} +0 -0
- /package/dist/tests/{key.test.d.ts → key.test.d.mts} +0 -0
- /package/dist/tests/{langstr.test.d.ts → langstr.test.d.mts} +0 -0
- /package/dist/tests/{link.test.d.ts → link.test.d.mts} +0 -0
- /package/dist/tests/multibase/{multibase.test.d.ts → multibase.test.d.mts} +0 -0
- /package/dist/tests/{request.test.d.ts → request.test.d.mts} +0 -0
- /package/dist/tests/{url.test.d.ts → url.test.d.mts} +0 -0
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
const require_chunk = require(
|
|
2
|
-
const require_request = require(
|
|
3
|
-
const require_link = require(
|
|
4
|
-
const require_url = require(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
const require_chunk = require("./chunk-Do9eywBl.cjs");
|
|
2
|
+
const require_request = require("./request-C6iSYeYi.cjs");
|
|
3
|
+
const require_link = require("./link-B6ZWBZhf.cjs");
|
|
4
|
+
const require_url = require("./url-Cr2K-wzd.cjs");
|
|
5
|
+
let node_assert = require("node:assert");
|
|
6
|
+
let node_test = require("node:test");
|
|
7
|
+
let _logtape_logtape = require("@logtape/logtape");
|
|
8
|
+
let _opentelemetry_api = require("@opentelemetry/api");
|
|
10
9
|
//#region ../../node_modules/.pnpm/glob-to-regexp@0.4.1/node_modules/glob-to-regexp/index.js
|
|
11
|
-
var require_glob_to_regexp =
|
|
12
|
-
module.exports = function(glob
|
|
13
|
-
if (typeof glob
|
|
14
|
-
var str = String(glob
|
|
10
|
+
var require_glob_to_regexp = /* @__PURE__ */ require_chunk.__commonJSMin(((exports, module) => {
|
|
11
|
+
module.exports = function(glob, opts) {
|
|
12
|
+
if (typeof glob !== "string") throw new TypeError("Expected a string");
|
|
13
|
+
var str = String(glob);
|
|
15
14
|
var reStr = "";
|
|
16
15
|
var extended = opts ? !!opts.extended : false;
|
|
17
16
|
var globstar = opts ? !!opts.globstar : false;
|
|
@@ -68,13 +67,10 @@ var require_glob_to_regexp = require_chunk.__commonJS({ "../../node_modules/.pnp
|
|
|
68
67
|
}
|
|
69
68
|
var nextChar = str[i + 1];
|
|
70
69
|
if (!globstar) reStr += ".*";
|
|
71
|
-
else {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
i++;
|
|
76
|
-
} else reStr += "([^/]*)";
|
|
77
|
-
}
|
|
70
|
+
else if (starCount > 1 && (prevChar === "/" || prevChar === void 0) && (nextChar === "/" || nextChar === void 0)) {
|
|
71
|
+
reStr += "((?:[^/]*(?:/|$))*)";
|
|
72
|
+
i++;
|
|
73
|
+
} else reStr += "([^/]*)";
|
|
78
74
|
break;
|
|
79
75
|
default: reStr += c;
|
|
80
76
|
}
|
|
@@ -82,10 +78,10 @@ var require_glob_to_regexp = require_chunk.__commonJS({ "../../node_modules/.pnp
|
|
|
82
78
|
if (!flags || !~flags.indexOf("g")) reStr = "^" + reStr + "$";
|
|
83
79
|
return new RegExp(reStr, flags);
|
|
84
80
|
};
|
|
85
|
-
}
|
|
86
|
-
|
|
81
|
+
}));
|
|
87
82
|
//#endregion
|
|
88
83
|
//#region ../../node_modules/.pnpm/regexparam@3.0.0/node_modules/regexparam/dist/index.mjs
|
|
84
|
+
var import_glob_to_regexp = /* @__PURE__ */ require_chunk.__toESM(require_glob_to_regexp(), 1);
|
|
89
85
|
/**
|
|
90
86
|
* @param {string|RegExp} input The route pattern
|
|
91
87
|
* @param {boolean} [loose] Allow open-ended matching. Ignored with `RegExp` input.
|
|
@@ -115,7 +111,6 @@ function parse(input, loose) {
|
|
|
115
111
|
pattern: new RegExp("^" + pattern + (loose ? "(?=$|/)" : "/?$"), "i")
|
|
116
112
|
};
|
|
117
113
|
}
|
|
118
|
-
|
|
119
114
|
//#endregion
|
|
120
115
|
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/TypeDescriptor.js
|
|
121
116
|
const valueTypes = new Set([
|
|
@@ -207,7 +202,6 @@ var TypeDescriptor = class TypeDescriptor {
|
|
|
207
202
|
return TypeDescriptor.of(value) === "undefined";
|
|
208
203
|
}
|
|
209
204
|
};
|
|
210
|
-
|
|
211
205
|
//#endregion
|
|
212
206
|
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/IsSubsetOf.js
|
|
213
207
|
const allowedTypes = new Set([
|
|
@@ -234,7 +228,7 @@ const isSubsetOf = function(subset, superset, visited = []) {
|
|
|
234
228
|
switch (subsetItemType) {
|
|
235
229
|
case "array":
|
|
236
230
|
case "object":
|
|
237
|
-
case "function":
|
|
231
|
+
case "function":
|
|
238
232
|
if (visited.includes(subsetItem)) continue;
|
|
239
233
|
visited.push(subsetItem);
|
|
240
234
|
isItemInSuperset = superset.some((supersetItem) => {
|
|
@@ -245,7 +239,6 @@ const isSubsetOf = function(subset, superset, visited = []) {
|
|
|
245
239
|
}
|
|
246
240
|
});
|
|
247
241
|
break;
|
|
248
|
-
}
|
|
249
242
|
default: isItemInSuperset = superset.includes(subsetItem);
|
|
250
243
|
}
|
|
251
244
|
if (!isItemInSuperset) return false;
|
|
@@ -257,21 +250,18 @@ const isSubsetOf = function(subset, superset, visited = []) {
|
|
|
257
250
|
if (Object.keys(subset).length > Object.keys(superset).length) return false;
|
|
258
251
|
for (const [subsetKey, subsetValue] of Object.entries(subset)) {
|
|
259
252
|
const supersetValue = superset[subsetKey];
|
|
260
|
-
|
|
261
|
-
switch (subsetValueType) {
|
|
253
|
+
switch (TypeDescriptor.of(subsetValue)) {
|
|
262
254
|
case "array":
|
|
263
255
|
case "object":
|
|
264
|
-
case "function":
|
|
256
|
+
case "function":
|
|
265
257
|
if (visited.includes(subsetValue)) continue;
|
|
266
258
|
visited.push(subsetValue);
|
|
267
259
|
try {
|
|
268
|
-
|
|
269
|
-
if (!isInSuperset) return false;
|
|
260
|
+
if (!isSubsetOf(subsetValue, supersetValue, visited)) return false;
|
|
270
261
|
} catch {
|
|
271
262
|
return false;
|
|
272
263
|
}
|
|
273
264
|
break;
|
|
274
|
-
}
|
|
275
265
|
default: if (subsetValue !== supersetValue) return false;
|
|
276
266
|
}
|
|
277
267
|
}
|
|
@@ -294,8 +284,7 @@ isSubsetOf.structural = function(subset, superset, visited = []) {
|
|
|
294
284
|
if (visited.includes(subsetValue)) continue;
|
|
295
285
|
visited.push(subsetValue);
|
|
296
286
|
try {
|
|
297
|
-
|
|
298
|
-
if (!isInSuperset) return false;
|
|
287
|
+
if (!isSubsetOf.structural(subsetValue, supersetValue, visited)) return false;
|
|
299
288
|
} catch {
|
|
300
289
|
return false;
|
|
301
290
|
}
|
|
@@ -303,7 +292,6 @@ isSubsetOf.structural = function(subset, superset, visited = []) {
|
|
|
303
292
|
}
|
|
304
293
|
return true;
|
|
305
294
|
};
|
|
306
|
-
|
|
307
295
|
//#endregion
|
|
308
296
|
//#region ../../node_modules/.pnpm/dequal@2.0.3/node_modules/dequal/dist/index.mjs
|
|
309
297
|
var has = Object.prototype.hasOwnProperty;
|
|
@@ -366,11 +354,10 @@ function dequal(foo, bar) {
|
|
|
366
354
|
}
|
|
367
355
|
return foo !== foo && bar !== bar;
|
|
368
356
|
}
|
|
369
|
-
|
|
370
357
|
//#endregion
|
|
371
358
|
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/RequestUtils.js
|
|
372
|
-
const absoluteUrlRX = new RegExp("^[a-z]+://|^data:", "i");
|
|
373
|
-
const protocolRelativeUrlRX = new RegExp("^//", "i");
|
|
359
|
+
const absoluteUrlRX = /* @__PURE__ */ new RegExp("^[a-z]+://|^data:", "i");
|
|
360
|
+
const protocolRelativeUrlRX = /* @__PURE__ */ new RegExp("^//", "i");
|
|
374
361
|
function hasCredentialsInUrl(url) {
|
|
375
362
|
const urlObject = new URL(url, !absoluteUrlRX.test(url) ? "http://dummy" : void 0);
|
|
376
363
|
return Boolean(urlObject.username || urlObject.password);
|
|
@@ -418,7 +405,7 @@ async function createCallLogFromRequest(request, options) {
|
|
|
418
405
|
} catch {}
|
|
419
406
|
if (request.headers) derivedOptions.headers = normalizeHeaders(request.headers);
|
|
420
407
|
const url = normalizeUrl(request.url, true);
|
|
421
|
-
|
|
408
|
+
return {
|
|
422
409
|
args: [request, options],
|
|
423
410
|
url,
|
|
424
411
|
queryParams: new URLSearchParams(getQuery(url)),
|
|
@@ -427,11 +414,9 @@ async function createCallLogFromRequest(request, options) {
|
|
|
427
414
|
signal: options && options.signal || request.signal,
|
|
428
415
|
pendingPromises
|
|
429
416
|
};
|
|
430
|
-
return callLog;
|
|
431
417
|
}
|
|
432
418
|
function getPath(url) {
|
|
433
|
-
|
|
434
|
-
return u.pathname;
|
|
419
|
+
return (absoluteUrlRX.test(url) ? new URL(url) : new URL(url, "http://dummy")).pathname;
|
|
435
420
|
}
|
|
436
421
|
function getHost(url) {
|
|
437
422
|
if (absoluteUrlRX.test(url)) return new URL(url).host;
|
|
@@ -449,10 +434,8 @@ function normalizeHeaders(headers) {
|
|
|
449
434
|
else entries = Object.entries(headers);
|
|
450
435
|
return Object.fromEntries(entries.map(([key, val]) => [key.toLowerCase(), String(val).valueOf()]));
|
|
451
436
|
}
|
|
452
|
-
|
|
453
437
|
//#endregion
|
|
454
438
|
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/Matchers.js
|
|
455
|
-
var import_glob_to_regexp = require_chunk.__toESM(require_glob_to_regexp(), 1);
|
|
456
439
|
const isUrlMatcher = (matcher) => matcher instanceof RegExp || typeof matcher === "string" || typeof matcher === "object" && "href" in matcher;
|
|
457
440
|
const isFunctionMatcher = (matcher) => typeof matcher === "function";
|
|
458
441
|
const stringMatchers = {
|
|
@@ -506,8 +489,7 @@ const getMissingHeaderMatcher = ({ missingHeaders: expectedMissingHeaders }) =>
|
|
|
506
489
|
const getMethodMatcher = ({ method: expectedMethod }) => {
|
|
507
490
|
if (!expectedMethod) return;
|
|
508
491
|
return ({ options: { method } = {} }) => {
|
|
509
|
-
|
|
510
|
-
return expectedMethod === actualMethod;
|
|
492
|
+
return expectedMethod === (method ? method.toLowerCase() : "get");
|
|
511
493
|
};
|
|
512
494
|
};
|
|
513
495
|
const getQueryParamsMatcher = ({ query: passedQuery }) => {
|
|
@@ -586,7 +568,7 @@ const getUrlMatcher = (route) => {
|
|
|
586
568
|
}
|
|
587
569
|
if (typeof matcherUrl === "string") {
|
|
588
570
|
for (const shorthand in stringMatchers) if (matcherUrl.indexOf(`${shorthand}:`) === 0) {
|
|
589
|
-
const urlFragment = matcherUrl.replace(
|
|
571
|
+
const urlFragment = matcherUrl.replace(new RegExp(`^${shorthand}:`), "");
|
|
590
572
|
return stringMatchers[shorthand](urlFragment);
|
|
591
573
|
}
|
|
592
574
|
return getFullUrlMatcher(route, matcherUrl, query);
|
|
@@ -597,7 +579,7 @@ const getUrlMatcher = (route) => {
|
|
|
597
579
|
else if (key in stringMatchers) return stringMatchers[key](pattern);
|
|
598
580
|
else throw new Error(`unrecognised url matching pattern: ${key}`);
|
|
599
581
|
});
|
|
600
|
-
return (route
|
|
582
|
+
return (route) => matchers.every((matcher) => matcher(route));
|
|
601
583
|
}
|
|
602
584
|
};
|
|
603
585
|
const builtInMatchers = [
|
|
@@ -635,7 +617,6 @@ const builtInMatchers = [
|
|
|
635
617
|
matcher: getFunctionMatcher
|
|
636
618
|
}
|
|
637
619
|
];
|
|
638
|
-
|
|
639
620
|
//#endregion
|
|
640
621
|
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/StatusTextMap.js
|
|
641
622
|
const statusTextMap = {
|
|
@@ -702,17 +683,15 @@ const statusTextMap = {
|
|
|
702
683
|
510: "Not Extended",
|
|
703
684
|
511: "Network Authentication Required"
|
|
704
685
|
};
|
|
705
|
-
var StatusTextMap_default = statusTextMap;
|
|
706
|
-
|
|
707
686
|
//#endregion
|
|
708
687
|
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/Route.js
|
|
709
|
-
var __classPrivateFieldSet =
|
|
688
|
+
var __classPrivateFieldSet = function(receiver, state, value, kind, f) {
|
|
710
689
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
711
690
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
712
691
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
713
692
|
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
714
693
|
};
|
|
715
|
-
var __classPrivateFieldGet =
|
|
694
|
+
var __classPrivateFieldGet = function(receiver, state, kind, f) {
|
|
716
695
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
717
696
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
718
697
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
@@ -773,14 +752,13 @@ var Route = class {
|
|
|
773
752
|
constructResponseOptions(responseInput) {
|
|
774
753
|
const options = responseInput.options || {};
|
|
775
754
|
options.status = sanitizeStatus(responseInput.status);
|
|
776
|
-
options.statusText =
|
|
755
|
+
options.statusText = statusTextMap[options.status];
|
|
777
756
|
options.headers = new this.config.Headers(responseInput.headers);
|
|
778
757
|
return options;
|
|
779
758
|
}
|
|
780
759
|
constructResponseBody(responseInput, responseOptions) {
|
|
781
760
|
let body = responseInput.body;
|
|
782
|
-
|
|
783
|
-
if (!bodyIsBodyInit) if (typeof body === "undefined") body = null;
|
|
761
|
+
if (!isBodyInit(body)) if (typeof body === "undefined") body = null;
|
|
784
762
|
else if (typeof body === "object") {
|
|
785
763
|
body = JSON.stringify(body);
|
|
786
764
|
if (!responseOptions.headers.has("Content-Type")) responseOptions.headers.set("Content-Type", "application/json");
|
|
@@ -799,26 +777,25 @@ var Route = class {
|
|
|
799
777
|
_a.registeredMatchers.push(matcher);
|
|
800
778
|
}
|
|
801
779
|
};
|
|
802
|
-
_a = Route, _Route_responseSubscriptions = /* @__PURE__ */ new WeakMap(), _Route_instances = /* @__PURE__ */ new WeakSet(), _Route_validate = function _Route_validate
|
|
780
|
+
_a = Route, _Route_responseSubscriptions = /* @__PURE__ */ new WeakMap(), _Route_instances = /* @__PURE__ */ new WeakSet(), _Route_validate = function _Route_validate() {
|
|
803
781
|
if (["matched", "unmatched"].includes(this.config.name)) throw new Error(`fetch-mock: Routes cannot use the reserved name \`${this.config.name}\``);
|
|
804
782
|
if (!("response" in this.config)) throw new Error("fetch-mock: Each route must define a response");
|
|
805
783
|
if (!_a.registeredMatchers.some(({ name }) => name in this.config)) throw new Error("fetch-mock: Each route must specify some criteria for matching calls to fetch. To match all calls use '*'");
|
|
806
|
-
}, _Route_sanitize = function _Route_sanitize
|
|
784
|
+
}, _Route_sanitize = function _Route_sanitize() {
|
|
807
785
|
if (this.config.method) this.config.method = this.config.method.toLowerCase();
|
|
808
|
-
}, _Route_generateMatcher = function _Route_generateMatcher
|
|
786
|
+
}, _Route_generateMatcher = function _Route_generateMatcher() {
|
|
809
787
|
const activeMatchers = _a.registeredMatchers.filter(({ name }) => name in this.config).map(({ matcher, usesBody }) => ({
|
|
810
788
|
matcher: matcher(this.config),
|
|
811
789
|
usesBody
|
|
812
790
|
}));
|
|
813
791
|
this.config.usesBody = activeMatchers.some(({ usesBody }) => usesBody);
|
|
814
792
|
this.matcher = (normalizedRequest) => activeMatchers.every(({ matcher }) => matcher(normalizedRequest));
|
|
815
|
-
}, _Route_limit = function _Route_limit
|
|
793
|
+
}, _Route_limit = function _Route_limit() {
|
|
816
794
|
if (!this.config.repeat) return;
|
|
817
795
|
const originalMatcher = this.matcher;
|
|
818
796
|
let timesLeft = this.config.repeat;
|
|
819
797
|
this.matcher = (callLog) => {
|
|
820
|
-
|
|
821
|
-
if (match) {
|
|
798
|
+
if (timesLeft && originalMatcher(callLog)) {
|
|
822
799
|
timesLeft--;
|
|
823
800
|
return true;
|
|
824
801
|
}
|
|
@@ -826,7 +803,7 @@ _a = Route, _Route_responseSubscriptions = /* @__PURE__ */ new WeakMap(), _Route
|
|
|
826
803
|
this.reset = () => {
|
|
827
804
|
timesLeft = this.config.repeat;
|
|
828
805
|
};
|
|
829
|
-
}, _Route_delayResponse = function _Route_delayResponse
|
|
806
|
+
}, _Route_delayResponse = function _Route_delayResponse() {
|
|
830
807
|
if (this.config.delay) {
|
|
831
808
|
const { response } = this.config;
|
|
832
809
|
this.config.response = () => {
|
|
@@ -836,8 +813,6 @@ _a = Route, _Route_responseSubscriptions = /* @__PURE__ */ new WeakMap(), _Route
|
|
|
836
813
|
};
|
|
837
814
|
Route.registeredMatchers = [];
|
|
838
815
|
builtInMatchers.forEach(Route.defineMatcher);
|
|
839
|
-
var Route_default = Route;
|
|
840
|
-
|
|
841
816
|
//#endregion
|
|
842
817
|
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/Router.js
|
|
843
818
|
const responseConfigProps = [
|
|
@@ -910,8 +885,7 @@ var Router = class {
|
|
|
910
885
|
});
|
|
911
886
|
}
|
|
912
887
|
if (this.needsToReadBody(request)) options.body = await options.body;
|
|
913
|
-
const
|
|
914
|
-
const route = routesToTry.find((route$1) => route$1.matcher(callLog));
|
|
888
|
+
const route = (this.fallbackRoute ? [...this.routes, this.fallbackRoute] : this.routes).find((route) => route.matcher(callLog));
|
|
915
889
|
if (route) try {
|
|
916
890
|
callLog.route = route;
|
|
917
891
|
const { response, responseOptions, responseInput } = await this.generateResponse(callLog);
|
|
@@ -966,7 +940,7 @@ var Router = class {
|
|
|
966
940
|
else Object.assign(config, matcher);
|
|
967
941
|
if (typeof response !== "undefined") config.response = response;
|
|
968
942
|
if (nameOrOptions) Object.assign(config, typeof nameOrOptions === "string" ? nameToOptions(nameOrOptions) : nameOrOptions);
|
|
969
|
-
const route = new
|
|
943
|
+
const route = new Route({
|
|
970
944
|
...this.config,
|
|
971
945
|
...config
|
|
972
946
|
});
|
|
@@ -985,7 +959,7 @@ var Router = class {
|
|
|
985
959
|
}
|
|
986
960
|
setFallback(response) {
|
|
987
961
|
if (this.fallbackRoute) console.warn("calling fetchMock.catch() twice - are you sure you want to overwrite the previous fallback response");
|
|
988
|
-
this.fallbackRoute = new
|
|
962
|
+
this.fallbackRoute = new Route({
|
|
989
963
|
matcherFunction: () => true,
|
|
990
964
|
response: response || "ok",
|
|
991
965
|
...this.config
|
|
@@ -1017,7 +991,6 @@ var Router = class {
|
|
|
1017
991
|
route.init(newConfig);
|
|
1018
992
|
}
|
|
1019
993
|
};
|
|
1020
|
-
|
|
1021
994
|
//#endregion
|
|
1022
995
|
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/CallHistory.js
|
|
1023
996
|
const isName = (filter) => typeof filter === "string" && /^[\da-zA-Z-]+$/.test(filter) && !["matched", "unmatched"].includes(filter);
|
|
@@ -1063,12 +1036,12 @@ var CallHistory = class {
|
|
|
1063
1036
|
...filter,
|
|
1064
1037
|
...options || {}
|
|
1065
1038
|
};
|
|
1066
|
-
const { matcher } = new
|
|
1039
|
+
const { matcher } = new Route({
|
|
1067
1040
|
response: "ok",
|
|
1068
1041
|
...options
|
|
1069
1042
|
});
|
|
1070
|
-
calls = calls.filter(({ url, options
|
|
1071
|
-
return matcher(createCallLogFromUrlAndOptions(url, options
|
|
1043
|
+
calls = calls.filter(({ url, options }) => {
|
|
1044
|
+
return matcher(createCallLogFromUrlAndOptions(url, options));
|
|
1072
1045
|
});
|
|
1073
1046
|
return calls;
|
|
1074
1047
|
}
|
|
@@ -1101,8 +1074,6 @@ var CallHistory = class {
|
|
|
1101
1074
|
}).every((isDone) => isDone);
|
|
1102
1075
|
}
|
|
1103
1076
|
};
|
|
1104
|
-
var CallHistory_default = CallHistory;
|
|
1105
|
-
|
|
1106
1077
|
//#endregion
|
|
1107
1078
|
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/FetchMock.js
|
|
1108
1079
|
const defaultFetchMockConfig = {
|
|
@@ -1124,7 +1095,9 @@ const defineGreedyShorthand = (shorthandOptions) => {
|
|
|
1124
1095
|
return this.route("*", response, Object.assign(options || {}, shorthandOptions));
|
|
1125
1096
|
};
|
|
1126
1097
|
};
|
|
1127
|
-
|
|
1098
|
+
//#endregion
|
|
1099
|
+
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/index.js
|
|
1100
|
+
var esm_default = new class FetchMock {
|
|
1128
1101
|
constructor(config, router) {
|
|
1129
1102
|
this.sticky = defineShorthand({ sticky: true });
|
|
1130
1103
|
this.once = defineShorthand({ repeat: 1 });
|
|
@@ -1165,7 +1138,7 @@ var FetchMock = class FetchMock {
|
|
|
1165
1138
|
routes: router ? [...router.routes] : [],
|
|
1166
1139
|
fallbackRoute: router ? router.fallbackRoute : null
|
|
1167
1140
|
});
|
|
1168
|
-
this.callHistory = new
|
|
1141
|
+
this.callHistory = new CallHistory(this.config, this.router);
|
|
1169
1142
|
this.fetchHandler = this.fetchHandler.bind(this);
|
|
1170
1143
|
Object.assign(this.fetchHandler, { fetchMock: this });
|
|
1171
1144
|
}
|
|
@@ -1190,7 +1163,7 @@ var FetchMock = class FetchMock {
|
|
|
1190
1163
|
return this;
|
|
1191
1164
|
}
|
|
1192
1165
|
defineMatcher(matcher) {
|
|
1193
|
-
|
|
1166
|
+
Route.defineMatcher(matcher);
|
|
1194
1167
|
}
|
|
1195
1168
|
removeRoutes(options) {
|
|
1196
1169
|
this.router.removeRoutes(options);
|
|
@@ -1232,14 +1205,7 @@ var FetchMock = class FetchMock {
|
|
|
1232
1205
|
this.mockGlobal();
|
|
1233
1206
|
return this.spy();
|
|
1234
1207
|
}
|
|
1235
|
-
};
|
|
1236
|
-
const fetchMock = new FetchMock({ ...defaultFetchMockConfig });
|
|
1237
|
-
var FetchMock_default = fetchMock;
|
|
1238
|
-
|
|
1239
|
-
//#endregion
|
|
1240
|
-
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/index.js
|
|
1241
|
-
var esm_default = FetchMock_default;
|
|
1242
|
-
|
|
1208
|
+
}({ ...defaultFetchMockConfig });
|
|
1243
1209
|
//#endregion
|
|
1244
1210
|
//#region src/contexts.ts
|
|
1245
1211
|
const preloadedContexts = {
|
|
@@ -5488,15 +5454,14 @@ const preloadedContexts = {
|
|
|
5488
5454
|
}
|
|
5489
5455
|
} }
|
|
5490
5456
|
};
|
|
5491
|
-
var contexts_default = preloadedContexts;
|
|
5492
|
-
|
|
5493
5457
|
//#endregion
|
|
5494
5458
|
//#region src/docloader.ts
|
|
5495
|
-
const logger = (0,
|
|
5459
|
+
const logger = (0, _logtape_logtape.getLogger)([
|
|
5496
5460
|
"fedify",
|
|
5497
5461
|
"runtime",
|
|
5498
5462
|
"docloader"
|
|
5499
5463
|
]);
|
|
5464
|
+
const DEFAULT_MAX_REDIRECTION = 20;
|
|
5500
5465
|
/**
|
|
5501
5466
|
* Gets a {@link RemoteDocument} from the given response.
|
|
5502
5467
|
* @param url The URL of the document to load.
|
|
@@ -5506,7 +5471,7 @@ const logger = (0, __logtape_logtape.getLogger)([
|
|
|
5506
5471
|
* @throws {FetchError} If the response is not OK.
|
|
5507
5472
|
* @internal
|
|
5508
5473
|
*/
|
|
5509
|
-
async function getRemoteDocument(url, response, fetch
|
|
5474
|
+
async function getRemoteDocument(url, response, fetch) {
|
|
5510
5475
|
const documentUrl = response.url === "" ? url : response.url;
|
|
5511
5476
|
const docUrl = new URL(documentUrl);
|
|
5512
5477
|
if (!response.ok) {
|
|
@@ -5544,7 +5509,7 @@ async function getRemoteDocument(url, response, fetch$1) {
|
|
|
5544
5509
|
alternateUrl: altUri.href,
|
|
5545
5510
|
url: documentUrl
|
|
5546
5511
|
});
|
|
5547
|
-
return await fetch
|
|
5512
|
+
return await fetch(altUri.href);
|
|
5548
5513
|
}
|
|
5549
5514
|
}
|
|
5550
5515
|
}
|
|
@@ -5570,15 +5535,14 @@ async function getRemoteDocument(url, response, fetch$1) {
|
|
|
5570
5535
|
attrPattern.lastIndex = 0;
|
|
5571
5536
|
while ((attrMatch = attrPattern.exec(tagContent)) !== null) {
|
|
5572
5537
|
const key = attrMatch[1].toLowerCase();
|
|
5573
|
-
|
|
5574
|
-
attribs[key] = value;
|
|
5538
|
+
attribs[key] = attrMatch[2] ?? attrMatch[3] ?? attrMatch[4] ?? "";
|
|
5575
5539
|
}
|
|
5576
5540
|
if (attribs.rel === "alternate" && "type" in attribs && (attribs.type === "application/activity+json" || attribs.type === "application/ld+json" || attribs.type.startsWith("application/ld+json;")) && "href" in attribs && new URL(attribs.href, docUrl).href !== docUrl.href) {
|
|
5577
5541
|
logger.debug("Found alternate document: {alternateUrl} from {url}", {
|
|
5578
5542
|
alternateUrl: attribs.href,
|
|
5579
5543
|
url: documentUrl
|
|
5580
5544
|
});
|
|
5581
|
-
return await fetch
|
|
5545
|
+
return await fetch(new URL(attribs.href, docUrl).href);
|
|
5582
5546
|
}
|
|
5583
5547
|
}
|
|
5584
5548
|
document = JSON.parse(html);
|
|
@@ -5613,33 +5577,34 @@ async function getRemoteDocument(url, response, fetch$1) {
|
|
|
5613
5577
|
* @since 1.3.0
|
|
5614
5578
|
*/
|
|
5615
5579
|
function getDocumentLoader({ allowPrivateAddress, skipPreloadedContexts, userAgent } = {}) {
|
|
5616
|
-
const
|
|
5617
|
-
|
|
5618
|
-
async function load(url, options) {
|
|
5580
|
+
const tracer = _opentelemetry_api.trace.getTracerProvider().getTracer(require_request.name, require_request.version);
|
|
5581
|
+
async function load(url, options, redirected = 0, visited = /* @__PURE__ */ new Set()) {
|
|
5619
5582
|
options?.signal?.throwIfAborted();
|
|
5620
|
-
|
|
5621
|
-
|
|
5583
|
+
const currentUrl = new URL(url).href;
|
|
5584
|
+
if (!skipPreloadedContexts && currentUrl in preloadedContexts) {
|
|
5585
|
+
logger.debug("Using preloaded context: {url}.", { url: currentUrl });
|
|
5622
5586
|
return {
|
|
5623
5587
|
contextUrl: null,
|
|
5624
|
-
document:
|
|
5625
|
-
documentUrl:
|
|
5588
|
+
document: preloadedContexts[currentUrl],
|
|
5589
|
+
documentUrl: currentUrl
|
|
5626
5590
|
};
|
|
5627
5591
|
}
|
|
5628
5592
|
if (!allowPrivateAddress) try {
|
|
5629
|
-
await require_url.validatePublicUrl(
|
|
5593
|
+
await require_url.validatePublicUrl(currentUrl);
|
|
5630
5594
|
} catch (error) {
|
|
5631
5595
|
if (error instanceof require_url.UrlError) logger.error("Disallowed private URL: {url}", {
|
|
5632
|
-
url,
|
|
5596
|
+
url: currentUrl,
|
|
5633
5597
|
error
|
|
5634
5598
|
});
|
|
5635
5599
|
throw error;
|
|
5636
5600
|
}
|
|
5601
|
+
visited.add(currentUrl);
|
|
5637
5602
|
return await tracer.startActiveSpan("activitypub.fetch_document", {
|
|
5638
|
-
kind:
|
|
5639
|
-
attributes: { "url.full":
|
|
5603
|
+
kind: _opentelemetry_api.SpanKind.CLIENT,
|
|
5604
|
+
attributes: { "url.full": currentUrl }
|
|
5640
5605
|
}, async (span) => {
|
|
5641
5606
|
try {
|
|
5642
|
-
const request = require_request.createActivityPubRequest(
|
|
5607
|
+
const request = require_request.createActivityPubRequest(currentUrl, { userAgent });
|
|
5643
5608
|
require_request.logRequest(logger, request);
|
|
5644
5609
|
const response = await fetch(request, {
|
|
5645
5610
|
redirect: "manual",
|
|
@@ -5647,18 +5612,32 @@ function getDocumentLoader({ allowPrivateAddress, skipPreloadedContexts, userAge
|
|
|
5647
5612
|
});
|
|
5648
5613
|
span.setAttribute("http.response.status_code", response.status);
|
|
5649
5614
|
if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
|
|
5650
|
-
|
|
5615
|
+
if (redirected >= DEFAULT_MAX_REDIRECTION) {
|
|
5616
|
+
logger.error("Too many redirections ({redirections}) while fetching document.", {
|
|
5617
|
+
redirections: redirected + 1,
|
|
5618
|
+
url: currentUrl
|
|
5619
|
+
});
|
|
5620
|
+
throw new require_request.FetchError(currentUrl, `Too many redirections (${redirected + 1})`);
|
|
5621
|
+
}
|
|
5622
|
+
const redirectUrl = new URL(response.headers.get("Location"), response.url === "" ? currentUrl : response.url).href;
|
|
5651
5623
|
span.setAttribute("http.redirect.url", redirectUrl);
|
|
5652
|
-
|
|
5624
|
+
if (visited.has(redirectUrl)) {
|
|
5625
|
+
logger.error("Detected a redirect loop while fetching document: {url} -> {redirectUrl}", {
|
|
5626
|
+
url: currentUrl,
|
|
5627
|
+
redirectUrl
|
|
5628
|
+
});
|
|
5629
|
+
throw new require_request.FetchError(currentUrl, `Redirect loop detected: ${redirectUrl}`);
|
|
5630
|
+
}
|
|
5631
|
+
return await load(redirectUrl, options, redirected + 1, visited);
|
|
5653
5632
|
}
|
|
5654
|
-
const result = await getRemoteDocument(
|
|
5633
|
+
const result = await getRemoteDocument(currentUrl, response, load);
|
|
5655
5634
|
span.setAttribute("docloader.document_url", result.documentUrl);
|
|
5656
5635
|
if (result.contextUrl != null) span.setAttribute("docloader.context_url", result.contextUrl);
|
|
5657
5636
|
return result;
|
|
5658
5637
|
} catch (error) {
|
|
5659
5638
|
span.recordException(error);
|
|
5660
5639
|
span.setStatus({
|
|
5661
|
-
code:
|
|
5640
|
+
code: _opentelemetry_api.SpanStatusCode.ERROR,
|
|
5662
5641
|
message: String(error)
|
|
5663
5642
|
});
|
|
5664
5643
|
throw error;
|
|
@@ -5669,7 +5648,6 @@ function getDocumentLoader({ allowPrivateAddress, skipPreloadedContexts, userAge
|
|
|
5669
5648
|
}
|
|
5670
5649
|
return load;
|
|
5671
5650
|
}
|
|
5672
|
-
|
|
5673
5651
|
//#endregion
|
|
5674
5652
|
//#region src/docloader.test.ts
|
|
5675
5653
|
(0, node_test.test)("new FetchError()", () => {
|
|
@@ -5887,7 +5865,7 @@ function getDocumentLoader({ allowPrivateAddress, skipPreloadedContexts, userAge
|
|
|
5887
5865
|
await (0, node_assert.rejects)(() => fetchDocumentLoader("https://example.com/404"), require_request.FetchError, "HTTP 404: https://example.com/404");
|
|
5888
5866
|
});
|
|
5889
5867
|
await t.test("preloaded contexts", async () => {
|
|
5890
|
-
for (const [url, document] of Object.entries(
|
|
5868
|
+
for (const [url, document] of Object.entries(preloadedContexts)) (0, node_assert.deepStrictEqual)(await fetchDocumentLoader(url), {
|
|
5891
5869
|
contextUrl: null,
|
|
5892
5870
|
documentUrl: url,
|
|
5893
5871
|
document
|
|
@@ -5939,6 +5917,52 @@ function getDocumentLoader({ allowPrivateAddress, skipPreloadedContexts, userAge
|
|
|
5939
5917
|
(0, node_assert.deepStrictEqual)(await fetchDocumentLoader2("https://example.com/localhost-redirect"), expected);
|
|
5940
5918
|
(0, node_assert.deepStrictEqual)(await fetchDocumentLoader2("https://example.com/localhost-link"), expected);
|
|
5941
5919
|
});
|
|
5920
|
+
let redirectAttempts = 0;
|
|
5921
|
+
esm_default.get("begin:https://example.com/too-many-redirects/", (cl) => {
|
|
5922
|
+
redirectAttempts++;
|
|
5923
|
+
return {
|
|
5924
|
+
status: 302,
|
|
5925
|
+
headers: { Location: `https://example.com/too-many-redirects/${Number(cl.url.split("/").at(-1)) + 1}` }
|
|
5926
|
+
};
|
|
5927
|
+
});
|
|
5928
|
+
await t.test("too many redirects", async () => {
|
|
5929
|
+
redirectAttempts = 0;
|
|
5930
|
+
await (0, node_assert.rejects)(() => fetchDocumentLoader("https://example.com/too-many-redirects/0"), require_request.FetchError, "Too many redirections");
|
|
5931
|
+
(0, node_assert.deepStrictEqual)(redirectAttempts, 21);
|
|
5932
|
+
});
|
|
5933
|
+
let loopAttempts = 0;
|
|
5934
|
+
esm_default.get("https://example.com/redirect-loop-a", () => {
|
|
5935
|
+
loopAttempts++;
|
|
5936
|
+
return {
|
|
5937
|
+
status: 302,
|
|
5938
|
+
headers: { Location: "https://example.com/redirect-loop-b" }
|
|
5939
|
+
};
|
|
5940
|
+
});
|
|
5941
|
+
esm_default.get("https://example.com/redirect-loop-b", () => {
|
|
5942
|
+
loopAttempts++;
|
|
5943
|
+
return {
|
|
5944
|
+
status: 302,
|
|
5945
|
+
headers: { Location: "https://example.com/redirect-loop-a" }
|
|
5946
|
+
};
|
|
5947
|
+
});
|
|
5948
|
+
await t.test("redirect loop", async () => {
|
|
5949
|
+
loopAttempts = 0;
|
|
5950
|
+
await (0, node_assert.rejects)(() => fetchDocumentLoader("https://example.com/redirect-loop-a"), require_request.FetchError, "Redirect loop detected");
|
|
5951
|
+
(0, node_assert.deepStrictEqual)(loopAttempts, 2);
|
|
5952
|
+
});
|
|
5953
|
+
let relativeLoopAttempts = 0;
|
|
5954
|
+
esm_default.get("https://example.com/redirect-loop-relative", () => {
|
|
5955
|
+
relativeLoopAttempts++;
|
|
5956
|
+
return {
|
|
5957
|
+
status: 302,
|
|
5958
|
+
headers: { Location: "/redirect-loop-relative" }
|
|
5959
|
+
};
|
|
5960
|
+
});
|
|
5961
|
+
await t.test("redirect loop with relative location", async () => {
|
|
5962
|
+
relativeLoopAttempts = 0;
|
|
5963
|
+
await (0, node_assert.rejects)(() => fetchDocumentLoader("https://example.com/redirect-loop-relative"), require_request.FetchError, "Redirect loop detected");
|
|
5964
|
+
(0, node_assert.deepStrictEqual)(relativeLoopAttempts, 1);
|
|
5965
|
+
});
|
|
5942
5966
|
const maliciousPayload = "<a" + " a=\"b\"".repeat(30) + " ";
|
|
5943
5967
|
esm_default.get("https://example.com/redos", {
|
|
5944
5968
|
body: maliciousPayload,
|
|
@@ -5952,5 +5976,4 @@ function getDocumentLoader({ allowPrivateAddress, skipPreloadedContexts, userAge
|
|
|
5952
5976
|
});
|
|
5953
5977
|
esm_default.hardReset();
|
|
5954
5978
|
});
|
|
5955
|
-
|
|
5956
|
-
//#endregion
|
|
5979
|
+
//#endregion
|