@fedify/fedify 1.6.1-dev.849 → 1.6.1-dev.856

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 (79) hide show
  1. package/dist/_virtual/rolldown_runtime.js +26 -1
  2. package/dist/codegen/schema.js +5 -4
  3. package/dist/deno.js +15 -2
  4. package/dist/federation/context.d.ts +27 -0
  5. package/dist/federation/handler.test.js +24 -5
  6. package/dist/federation/middleware.js +34 -1
  7. package/dist/federation/middleware.test.js +90 -53
  8. package/dist/federation/send.test.js +8 -10
  9. package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/_common/constants.js +1 -7
  10. package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/_common/dirname.js +1 -1
  11. package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/_common/from_file_url.js +1 -1
  12. package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/dirname.js +1 -32
  13. package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/join.js +1 -32
  14. package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/mod.js +0 -2
  15. package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/posix/dirname.js +2 -2
  16. package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/posix/from_file_url.js +1 -1
  17. package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/posix/join.js +1 -1
  18. package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/windows/from_file_url.js +1 -1
  19. package/dist/node_modules/.pnpm/@jsr_std__url@1.0.0-rc.3/node_modules/@jsr/std__url/dirname.js +2 -2
  20. package/dist/node_modules/.pnpm/@jsr_std__url@1.0.0-rc.3/node_modules/@jsr/std__url/join.js +2 -2
  21. package/dist/node_modules/.pnpm/dequal@2.0.3/node_modules/dequal/dist/index.js +68 -0
  22. package/dist/node_modules/.pnpm/fetch-mock@12.5.2/node_modules/fetch-mock/dist/esm/CallHistory.js +94 -0
  23. package/dist/node_modules/.pnpm/fetch-mock@12.5.2/node_modules/fetch-mock/dist/esm/FetchMock.js +143 -0
  24. package/dist/node_modules/.pnpm/fetch-mock@12.5.2/node_modules/fetch-mock/dist/esm/IsSubsetOf.js +103 -0
  25. package/dist/node_modules/.pnpm/fetch-mock@12.5.2/node_modules/fetch-mock/dist/esm/Matchers.js +195 -0
  26. package/dist/node_modules/.pnpm/fetch-mock@12.5.2/node_modules/fetch-mock/dist/esm/RequestUtils.js +83 -0
  27. package/dist/node_modules/.pnpm/fetch-mock@12.5.2/node_modules/fetch-mock/dist/esm/Route.js +137 -0
  28. package/dist/node_modules/.pnpm/fetch-mock@12.5.2/node_modules/fetch-mock/dist/esm/Router.js +181 -0
  29. package/dist/node_modules/.pnpm/fetch-mock@12.5.2/node_modules/fetch-mock/dist/esm/StatusTextMap.js +73 -0
  30. package/dist/node_modules/.pnpm/fetch-mock@12.5.2/node_modules/fetch-mock/dist/esm/TypeDescriptor.js +97 -0
  31. package/dist/node_modules/.pnpm/fetch-mock@12.5.2/node_modules/fetch-mock/dist/esm/index.js +11 -0
  32. package/dist/node_modules/.pnpm/glob-to-regexp@0.4.1/node_modules/glob-to-regexp/index.js +87 -0
  33. package/dist/node_modules/.pnpm/regexparam@3.0.0/node_modules/regexparam/dist/index.js +37 -0
  34. package/dist/runtime/authdocloader.test.js +5 -5
  35. package/dist/runtime/docloader.js +1 -1
  36. package/dist/runtime/docloader.test.js +8 -0
  37. package/dist/sig/key.js +7 -2
  38. package/dist/testing/context.js +14 -2
  39. package/dist/testing/docloader.js +34 -15
  40. package/dist/testing/fixtures/example.com/{hong-gildong → hong-gildong.json} +1 -1
  41. package/dist/testing/fixtures/example.com/{object → object.json} +1 -1
  42. package/dist/testing/fixtures/example.com/person.js +29 -0
  43. package/dist/testing/fixtures/example.com/person2.js +48 -0
  44. package/dist/testing/fixtures/example.com/{test → test.json} +1 -1
  45. package/dist/testing/fixtures/w3id.org/security/data-integrity/{v1 → v1.json} +1 -1
  46. package/dist/testing/fixtures/w3id.org/security/{v1 → v1.json} +9 -9
  47. package/dist/testing/mod.d.ts +11 -0
  48. package/dist/testing/mod.js +44 -38
  49. package/dist/vocab/lookup.test.js +30 -35
  50. package/dist/vocab/vocab.js +176 -176
  51. package/dist/vocab/vocab.test.js +2 -2
  52. package/package.json +8 -3
  53. package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/windows/_util.js +0 -19
  54. package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/windows/dirname.js +0 -75
  55. package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/windows/join.js +0 -54
  56. package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/windows/normalize.js +0 -87
  57. /package/dist/testing/fixtures/activitypub.academy/users/{brauca_darradiul → brauca_darradiul.json} +0 -0
  58. /package/dist/testing/fixtures/example.com/{announce → announce.json} +0 -0
  59. /package/dist/testing/fixtures/example.com/{collection → collection.json} +0 -0
  60. /package/dist/testing/fixtures/example.com/{create → create.json} +0 -0
  61. /package/dist/testing/fixtures/example.com/{cross-origin-actor → cross-origin-actor.json} +0 -0
  62. /package/dist/testing/fixtures/example.com/{invite → invite.json} +0 -0
  63. /package/dist/testing/fixtures/example.com/{key → key.json} +0 -0
  64. /package/dist/testing/fixtures/example.com/{key2 → key2.json} +0 -0
  65. /package/dist/testing/fixtures/example.com/{orderedcollectionpage → orderedcollectionpage.json} +0 -0
  66. /package/dist/testing/fixtures/example.com/paged/{a → a.json} +0 -0
  67. /package/dist/testing/fixtures/example.com/paged/{b → b.json} +0 -0
  68. /package/dist/testing/fixtures/example.com/{paged-collection → paged-collection.json} +0 -0
  69. /package/dist/testing/fixtures/example.com/{person → person.json} +0 -0
  70. /package/dist/testing/fixtures/example.com/{person2 → person2.json} +0 -0
  71. /package/dist/testing/fixtures/example.com/users/{handle → handle.json} +0 -0
  72. /package/dist/testing/fixtures/example.com/{wrong-type → wrong-type.json} +0 -0
  73. /package/dist/testing/fixtures/remote.domain/users/{bob → bob.json} +0 -0
  74. /package/dist/testing/fixtures/server.example/users/{alice → alice.json} +0 -0
  75. /package/dist/testing/fixtures/w3id.org/identity/{v1 → v1.json} +0 -0
  76. /package/dist/testing/fixtures/w3id.org/security/multikey/{v1 → v1.json} +0 -0
  77. /package/dist/testing/fixtures/wizard.casa/users/{hongminhee → hongminhee.json} +0 -0
  78. /package/dist/testing/fixtures/www.w3.org/ns/{activitystreams → activitystreams.json} +0 -0
  79. /package/dist/testing/fixtures/www.w3.org/ns/did/{v1 → v1.json} +0 -0
@@ -2,14 +2,39 @@
2
2
  import { Temporal } from "@js-temporal/polyfill";
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
 
5
+ import { createRequire } from "node:module";
6
+
5
7
  //#region rolldown:runtime
8
+ var __create = Object.create;
6
9
  var __defProp = Object.defineProperty;
10
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
+ var __getOwnPropNames = Object.getOwnPropertyNames;
12
+ var __getProtoOf = Object.getPrototypeOf;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __commonJS = (cb, mod) => function() {
15
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
+ };
7
17
  var __export = (target, all) => {
8
18
  for (var name in all) __defProp(target, name, {
9
19
  get: all[name],
10
20
  enumerable: true
11
21
  });
12
22
  };
23
+ var __copyProps = (to, from, except, desc) => {
24
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
25
+ key = keys[i];
26
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
27
+ get: ((k) => from[k]).bind(null, key),
28
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
29
+ });
30
+ }
31
+ return to;
32
+ };
33
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
34
+ value: mod,
35
+ enumerable: true
36
+ }) : target, mod));
37
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
13
38
 
14
39
  //#endregion
15
- export { __export };
40
+ export { __commonJS, __export, __require, __toESM };
@@ -3,12 +3,12 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
 
5
5
  import { fromFileUrl } from "../node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/from_file_url.js";
6
- import { dirname$1 as dirname } from "../node_modules/.pnpm/@jsr_std__url@1.0.0-rc.3/node_modules/@jsr/std__url/dirname.js";
7
- import { join$1 as join } from "../node_modules/.pnpm/@jsr_std__url@1.0.0-rc.3/node_modules/@jsr/std__url/join.js";
6
+ import { dirname } from "../node_modules/.pnpm/@jsr_std__url@1.0.0-rc.3/node_modules/@jsr/std__url/dirname.js";
7
+ import { join } from "../node_modules/.pnpm/@jsr_std__url@1.0.0-rc.3/node_modules/@jsr/std__url/join.js";
8
8
  import { parse } from "../node_modules/.pnpm/@jsr_std__yaml@1.0.6/node_modules/@jsr/std__yaml/parse.js";
9
9
  import { readDirRecursive } from "./fs.js";
10
- import { readFile } from "node:fs/promises";
11
10
  import { Validator } from "@cfworker/json-schema";
11
+ import { readFile } from "node:fs/promises";
12
12
  import { join as join$1 } from "node:path";
13
13
 
14
14
  //#region codegen/schema.ts
@@ -41,10 +41,11 @@ async function loadSchemaValidator() {
41
41
  const schemaObject = parse(content);
42
42
  return new Validator(schemaObject);
43
43
  }
44
- const schemaValidator = await loadSchemaValidator();
44
+ let schemaValidator = void 0;
45
45
  async function loadSchema(path) {
46
46
  const content = await readFile(path, { encoding: "utf-8" });
47
47
  const schema = parse(content);
48
+ if (schemaValidator == null) schemaValidator = await loadSchemaValidator();
48
49
  const result = schemaValidator.validate(schema);
49
50
  const errors = [];
50
51
  if (result.valid) return schema;
package/dist/deno.js CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  //#region deno.json
6
6
  var name = "@fedify/fedify";
7
- var version = "1.6.1-dev.849+87f95fcc";
7
+ var version = "1.6.1-dev.856+77c62d3e";
8
8
  var license = "MIT";
9
9
  var exports = {
10
10
  ".": "./mod.ts",
@@ -36,6 +36,7 @@ var imports = {
36
36
  "asn1js": "npm:asn1js@^3.0.5",
37
37
  "byte-encodings": "npm:byte-encodings@^1.0.11",
38
38
  "fast-check": "npm:fast-check@^3.22.0",
39
+ "fetch-mock": "npm:fetch-mock@^12.5.2",
39
40
  "json-canon": "npm:json-canon@^1.0.1",
40
41
  "jsonld": "npm:jsonld@^8.3.2",
41
42
  "multicodec": "npm:multicodec@^3.2.1",
@@ -48,6 +49,13 @@ var imports = {
48
49
  var include = ["vocab/vocab.ts"];
49
50
  var exclude = [
50
51
  "apidoc/",
52
+ "cfworkers/dist/",
53
+ "cfworkers/fixtures/",
54
+ "cfworkers/imports.ts",
55
+ "cfworkers/README.md",
56
+ "cfworkers/server.ts",
57
+ "cfworkers/server.js",
58
+ "cfworkers/server.js.map",
51
59
  "codegen/schema.yaml",
52
60
  "dist/",
53
61
  "node_modules/",
@@ -102,11 +110,16 @@ var tasks = {
102
110
  "command": "cd dist/ && bun test --timeout 60000",
103
111
  "dependencies": ["pnpm:build"]
104
112
  },
113
+ "test:cfworkers": {
114
+ "command": "pnpm exec wrangler deploy --dry-run --outdir cfworkers && node --import=tsx cfworkers/client.ts",
115
+ "dependencies": ["pnpm:build"]
116
+ },
105
117
  "test-all": { "dependencies": [
106
118
  "check",
107
119
  "test",
108
120
  "test:node",
109
- "test:bun"
121
+ "test:bun",
122
+ "test:cfworkers"
110
123
  ] }
111
124
  };
112
125
  var deno_default = {
@@ -71,6 +71,15 @@ interface Context<TContextData> {
71
71
  * @since 1.6.0
72
72
  */
73
73
  readonly federation: Federation<TContextData>;
74
+ /**
75
+ * Creates a new context with the same properties as this one,
76
+ * but with the given data.
77
+ * @param data The new data to associate with the context.
78
+ * @returns A new context with the same properties as this one,
79
+ * but with the given data.
80
+ * @since 1.6.0
81
+ */
82
+ clone(data: TContextData): Context<TContextData>;
74
83
  /**
75
84
  * Builds the URI of the NodeInfo document.
76
85
  * @returns The NodeInfo URI.
@@ -373,6 +382,15 @@ interface RequestContext<TContextData> extends Context<TContextData> {
373
382
  * The URL of the request.
374
383
  */
375
384
  readonly url: URL;
385
+ /**
386
+ * Creates a new context with the same properties as this one,
387
+ * but with the given data.
388
+ * @param data The new data to associate with the context.
389
+ * @returns A new context with the same properties as this one,
390
+ * but with the given data.
391
+ * @since 1.6.0
392
+ */
393
+ clone(data: TContextData): RequestContext<TContextData>;
376
394
  /**
377
395
  * Gets an {@link Actor} object for the given identifier.
378
396
  * @param identifier The actor's identifier.
@@ -472,6 +490,15 @@ interface InboxContext<TContextData> extends Context<TContextData> {
472
490
  * @since 1.2.0
473
491
  */
474
492
  recipient: string | null;
493
+ /**
494
+ * Creates a new context with the same properties as this one,
495
+ * but with the given data.
496
+ * @param data The new data to associate with the context.
497
+ * @returns A new context with the same properties as this one,
498
+ * but with the given data.
499
+ * @since 1.6.0
500
+ */
501
+ clone(data: TContextData): InboxContext<TContextData>;
475
502
  /**
476
503
  * Forwards a received activity to the recipients' inboxes. The forwarded
477
504
  * activity will be signed in HTTP Signatures by the forwarder, but its
@@ -984,7 +984,10 @@ test("handleInbox()", async () => {
984
984
  recipient: null,
985
985
  context: unsignedContext,
986
986
  inboxContextFactory(_activity) {
987
- return createInboxContext(unsignedContext);
987
+ return createInboxContext({
988
+ ...unsignedContext,
989
+ clone: void 0
990
+ });
988
991
  },
989
992
  ...inboxOptions,
990
993
  actorDispatcher: void 0
@@ -998,6 +1001,7 @@ test("handleInbox()", async () => {
998
1001
  inboxContextFactory(_activity) {
999
1002
  return createInboxContext({
1000
1003
  ...unsignedContext,
1004
+ clone: void 0,
1001
1005
  recipient: "nobody"
1002
1006
  });
1003
1007
  },
@@ -1010,7 +1014,10 @@ test("handleInbox()", async () => {
1010
1014
  recipient: null,
1011
1015
  context: unsignedContext,
1012
1016
  inboxContextFactory(_activity) {
1013
- return createInboxContext(unsignedContext);
1017
+ return createInboxContext({
1018
+ ...unsignedContext,
1019
+ clone: void 0
1020
+ });
1014
1021
  },
1015
1022
  ...inboxOptions
1016
1023
  });
@@ -1022,6 +1029,7 @@ test("handleInbox()", async () => {
1022
1029
  inboxContextFactory(_activity) {
1023
1030
  return createInboxContext({
1024
1031
  ...unsignedContext,
1032
+ clone: void 0,
1025
1033
  recipient: "someone"
1026
1034
  });
1027
1035
  },
@@ -1042,7 +1050,10 @@ test("handleInbox()", async () => {
1042
1050
  recipient: null,
1043
1051
  context: signedContext,
1044
1052
  inboxContextFactory(_activity) {
1045
- return createInboxContext(unsignedContext);
1053
+ return createInboxContext({
1054
+ ...unsignedContext,
1055
+ clone: void 0
1056
+ });
1046
1057
  },
1047
1058
  ...inboxOptions
1048
1059
  });
@@ -1054,6 +1065,7 @@ test("handleInbox()", async () => {
1054
1065
  inboxContextFactory(_activity) {
1055
1066
  return createInboxContext({
1056
1067
  ...unsignedContext,
1068
+ clone: void 0,
1057
1069
  recipient: "someone"
1058
1070
  });
1059
1071
  },
@@ -1065,7 +1077,10 @@ test("handleInbox()", async () => {
1065
1077
  recipient: null,
1066
1078
  context: unsignedContext,
1067
1079
  inboxContextFactory(_activity) {
1068
- return createInboxContext(unsignedContext);
1080
+ return createInboxContext({
1081
+ ...unsignedContext,
1082
+ clone: void 0
1083
+ });
1069
1084
  },
1070
1085
  ...inboxOptions,
1071
1086
  skipSignatureVerification: true
@@ -1078,6 +1093,7 @@ test("handleInbox()", async () => {
1078
1093
  inboxContextFactory(_activity) {
1079
1094
  return createInboxContext({
1080
1095
  ...unsignedContext,
1096
+ clone: void 0,
1081
1097
  recipient: "someone"
1082
1098
  });
1083
1099
  },
@@ -1114,7 +1130,10 @@ test("handleInbox()", async () => {
1114
1130
  recipient: null,
1115
1131
  context: signedContext,
1116
1132
  inboxContextFactory(_activity) {
1117
- return createInboxContext(signedInvalidContext);
1133
+ return createInboxContext({
1134
+ ...signedInvalidContext,
1135
+ clone: void 0
1136
+ });
1118
1137
  },
1119
1138
  ...inboxOptions
1120
1139
  });
@@ -882,6 +882,16 @@ var ContextImpl = class ContextImpl {
882
882
  this.contextLoader = contextLoader;
883
883
  this.invokedFromActorKeyPairsDispatcher = invokedFromActorKeyPairsDispatcher;
884
884
  }
885
+ clone(data) {
886
+ return new ContextImpl({
887
+ url: this.url,
888
+ federation: this.federation,
889
+ data,
890
+ documentLoader: this.documentLoader,
891
+ contextLoader: this.contextLoader,
892
+ invokedFromActorKeyPairsDispatcher: this.invokedFromActorKeyPairsDispatcher
893
+ });
894
+ }
885
895
  toInboxContext(recipient, activity, activityId, activityType) {
886
896
  return new InboxContextImpl(recipient, activity, activityId, activityType, {
887
897
  url: this.url,
@@ -1498,6 +1508,19 @@ var RequestContextImpl = class RequestContextImpl extends ContextImpl {
1498
1508
  this.request = options.request;
1499
1509
  this.url = options.url;
1500
1510
  }
1511
+ clone(data) {
1512
+ return new RequestContextImpl({
1513
+ url: this.url,
1514
+ federation: this.federation,
1515
+ data,
1516
+ documentLoader: this.documentLoader,
1517
+ contextLoader: this.contextLoader,
1518
+ invokedFromActorKeyPairsDispatcher: this.invokedFromActorKeyPairsDispatcher,
1519
+ invokedFromActorDispatcher: this.#invokedFromActorDispatcher,
1520
+ invokedFromObjectDispatcher: this.#invokedFromObjectDispatcher,
1521
+ request: this.request
1522
+ });
1523
+ }
1501
1524
  async getActor(identifier) {
1502
1525
  if (this.federation.actorCallbacks == null || this.federation.actorCallbacks.dispatcher == null) throw new Error("No actor dispatcher registered.");
1503
1526
  if (this.#invokedFromActorDispatcher != null) getLogger([
@@ -1554,7 +1577,7 @@ var RequestContextImpl = class RequestContextImpl extends ContextImpl {
1554
1577
  });
1555
1578
  }
1556
1579
  };
1557
- var InboxContextImpl = class extends ContextImpl {
1580
+ var InboxContextImpl = class InboxContextImpl extends ContextImpl {
1558
1581
  recipient;
1559
1582
  activity;
1560
1583
  activityId;
@@ -1566,6 +1589,16 @@ var InboxContextImpl = class extends ContextImpl {
1566
1589
  this.activityId = activityId;
1567
1590
  this.activityType = activityType;
1568
1591
  }
1592
+ clone(data) {
1593
+ return new InboxContextImpl(this.recipient, this.activity, this.activityId, this.activityType, {
1594
+ url: this.url,
1595
+ federation: this.federation,
1596
+ data,
1597
+ documentLoader: this.documentLoader,
1598
+ contextLoader: this.contextLoader,
1599
+ invokedFromActorKeyPairsDispatcher: this.invokedFromActorKeyPairsDispatcher
1600
+ });
1601
+ }
1569
1602
  forwardActivity(forwarder, recipients, options) {
1570
1603
  const tracer = this.tracerProvider.getTracer(deno_default.name, deno_default.version);
1571
1604
  return tracer.startActiveSpan("activitypub.outbox", {
@@ -23,12 +23,11 @@ import { assertNotEquals } from "../node_modules/.pnpm/@jsr_std__assert@0.226.0/
23
23
  import { assertRejects } from "../node_modules/.pnpm/@jsr_std__assert@0.226.0/node_modules/@jsr/std__assert/assert_rejects.js";
24
24
  import { assertStrictEquals } from "../node_modules/.pnpm/@jsr_std__assert@0.226.0/node_modules/@jsr/std__assert/assert_strict_equals.js";
25
25
  import { assertThrows } from "../node_modules/.pnpm/@jsr_std__assert@0.226.0/node_modules/@jsr/std__assert/assert_throws.js";
26
- import { dirname } from "../node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/dirname.js";
27
- import { join } from "../node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/join.js";
28
26
  import { mockDocumentLoader } from "../testing/docloader.js";
29
27
  import { ed25519Multikey, ed25519PrivateKey, ed25519PublicKey, rsaPrivateKey2, rsaPrivateKey3, rsaPublicKey2, rsaPublicKey3 } from "../testing/keys.js";
30
- import { install, mock, uninstall } from "../node_modules/.pnpm/@jsr_hongminhee__deno-mock-fetch@0.3.2/node_modules/@jsr/hongminhee__deno-mock-fetch/mod.js";
31
- import { readFile } from "node:fs/promises";
28
+ import { esm_default } from "../node_modules/.pnpm/fetch-mock@12.5.2/node_modules/fetch-mock/dist/esm/index.js";
29
+ import { person_default } from "../testing/fixtures/example.com/person.js";
30
+ import { person2_default } from "../testing/fixtures/example.com/person2.js";
32
31
 
33
32
  //#region federation/middleware.test.ts
34
33
  test("createFederation()", async (t) => {
@@ -148,9 +147,9 @@ test("Federation.createContext()", async (t) => {
148
147
  const documentLoader = (url) => {
149
148
  throw new FetchError(new URL(url), "Not found");
150
149
  };
151
- install();
152
- mock("GET@/object", async (req) => {
153
- const v = await verifyRequest(req, {
150
+ esm_default.spyGlobal();
151
+ esm_default.get("https://example.com/object", async (cl) => {
152
+ const v = await verifyRequest(cl.request, {
154
153
  contextLoader: mockDocumentLoader,
155
154
  documentLoader: mockDocumentLoader,
156
155
  currentTime: Temporal.Now.instant()
@@ -536,17 +535,30 @@ test("Federation.createContext()", async (t) => {
536
535
  identifier: "handle"
537
536
  });
538
537
  });
539
- mock("GET@/.well-known/nodeinfo", (req) => {
540
- assertEquals(new URL(req.url).host, "example.com");
541
- assertEquals(req.headers.get("User-Agent"), "CustomUserAgent/1.2.3");
538
+ await t.step("Context.clone()", () => {
539
+ const federation = createFederation({ kv });
540
+ const ctx = federation.createContext(new URL("https://example.com/"), 123);
541
+ const clone = ctx.clone(456);
542
+ assertStrictEquals(clone.canonicalOrigin, ctx.canonicalOrigin);
543
+ assertStrictEquals(clone.origin, ctx.origin);
544
+ assertEquals(clone.data, 456);
545
+ assertEquals(clone.host, ctx.host);
546
+ assertEquals(clone.hostname, ctx.hostname);
547
+ assertStrictEquals(clone.documentLoader, ctx.documentLoader);
548
+ assertStrictEquals(clone.contextLoader, ctx.contextLoader);
549
+ assertStrictEquals(clone.federation, ctx.federation);
550
+ });
551
+ esm_default.get("https://example.com/.well-known/nodeinfo", (cl) => {
552
+ const headers = cl.options.headers ?? {};
553
+ assertEquals(new Headers(headers).get("User-Agent"), "CustomUserAgent/1.2.3");
542
554
  return new Response(JSON.stringify({ links: [{
543
555
  rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
544
556
  href: "https://example.com/nodeinfo/2.1"
545
557
  }] }));
546
558
  });
547
- mock("GET@/nodeinfo/2.1", (req) => {
548
- assertEquals(new URL(req.url).host, "example.com");
549
- assertEquals(req.headers.get("User-Agent"), "CustomUserAgent/1.2.3");
559
+ esm_default.get("https://example.com/nodeinfo/2.1", (cl) => {
560
+ const headers = cl.options.headers ?? {};
561
+ assertEquals(new Headers(headers).get("User-Agent"), "CustomUserAgent/1.2.3");
550
562
  return new Response(JSON.stringify({
551
563
  software: {
552
564
  name: "foo",
@@ -662,19 +674,37 @@ test("Federation.createContext()", async (t) => {
662
674
  id: "123"
663
675
  }), new Note({ summary: "Note 123 by john" }));
664
676
  });
665
- uninstall();
677
+ await t.step("RequestContext.clone()", () => {
678
+ const federation = createFederation({ kv });
679
+ const req = new Request("https://example.com/");
680
+ const ctx = federation.createContext(req, 123);
681
+ const clone = ctx.clone(456);
682
+ assertStrictEquals(clone.request, ctx.request);
683
+ assertEquals(clone.url, ctx.url);
684
+ assertEquals(clone.data, 456);
685
+ assertEquals(clone.origin, ctx.origin);
686
+ assertEquals(clone.host, ctx.host);
687
+ assertEquals(clone.hostname, ctx.hostname);
688
+ assertStrictEquals(clone.documentLoader, ctx.documentLoader);
689
+ assertStrictEquals(clone.contextLoader, ctx.contextLoader);
690
+ assertStrictEquals(clone.federation, ctx.federation);
691
+ });
692
+ esm_default.hardReset();
666
693
  });
667
694
  test("Federation.setInboxListeners()", async (t) => {
668
695
  const kv = new MemoryKvStore();
669
- install();
670
- mock("GET@/key2", async () => {
671
- return new Response(JSON.stringify(await rsaPublicKey2.toJsonLd({ contextLoader: mockDocumentLoader })), { headers: { "Content-Type": "application/activity+json" } });
696
+ esm_default.spyGlobal();
697
+ esm_default.get("https://example.com/key2", {
698
+ headers: { "Content-Type": "application/activity+json" },
699
+ body: await rsaPublicKey2.toJsonLd({ contextLoader: mockDocumentLoader })
672
700
  });
673
- mock("GET@/person", async () => {
674
- return new Response(await readFile(join(dirname(import.meta.dirname), "testing", "fixtures", "example.com", "person")), { headers: { "Content-Type": "application/activity+json" } });
701
+ esm_default.get("begin:https://example.com/person2", {
702
+ headers: { "Content-Type": "application/activity+json" },
703
+ body: person2_default
675
704
  });
676
- mock("GET@/person2", async () => {
677
- return new Response(await readFile(join(dirname(import.meta.dirname), "testing", "fixtures", "example.com", "person2")), { headers: { "Content-Type": "application/activity+json" } });
705
+ esm_default.get("begin:https://example.com/person", {
706
+ headers: { "Content-Type": "application/activity+json" },
707
+ body: person_default
678
708
  });
679
709
  await t.step("path match", () => {
680
710
  const federation = createFederation({
@@ -841,7 +871,7 @@ test("Federation.setInboxListeners()", async (t) => {
841
871
  assertEquals(errors[0], error);
842
872
  assertEquals(response.status, 500);
843
873
  });
844
- uninstall();
874
+ esm_default.hardReset();
845
875
  });
846
876
  test("Federation.setInboxDispatcher()", async (t) => {
847
877
  const kv = new MemoryKvStore();
@@ -872,17 +902,17 @@ test("Federation.setInboxDispatcher()", async (t) => {
872
902
  });
873
903
  });
874
904
  test("FederationImpl.sendActivity()", async (t) => {
875
- install();
905
+ esm_default.spyGlobal();
876
906
  let verified = null;
877
907
  let request = null;
878
- mock("POST@/inbox", async (req) => {
908
+ esm_default.post("https://example.com/inbox", async (cl) => {
879
909
  verified = [];
880
- request = req.clone();
910
+ request = cl.request.clone();
881
911
  const options = {
882
912
  documentLoader: mockDocumentLoader,
883
913
  contextLoader: mockDocumentLoader
884
914
  };
885
- let json = await req.json();
915
+ let json = await cl.request.json();
886
916
  if (await verifyJsonLd(json, options)) verified.push("ld");
887
917
  json = detachSignature(json);
888
918
  let activity = await verifyObject(Activity, json, options);
@@ -955,24 +985,30 @@ test("FederationImpl.sendActivity()", async (t) => {
955
985
  assertEquals(request?.url, "https://example.com/inbox");
956
986
  assertEquals(request?.headers.get("Content-Type"), "application/activity+json");
957
987
  });
958
- uninstall();
988
+ esm_default.hardReset();
959
989
  });
960
990
  test("ContextImpl.lookupObject()", async (t) => {
961
- install();
962
- mock("GET@/.well-known/webfinger", () => new Response(JSON.stringify({
963
- subject: "acct:test@localhost",
964
- links: [{
965
- rel: "self",
966
- type: "application/activity+json",
967
- href: "https://localhost/actor"
968
- }]
969
- }), { headers: { "Content-Type": "application/jrd+json" } }));
970
- mock("GET@/actor", () => new Response(JSON.stringify({
971
- "@context": "https://www.w3.org/ns/activitystreams",
972
- "type": "Person",
973
- "id": "https://localhost/actor",
974
- "preferredUsername": "test"
975
- }), { headers: { "Content-Type": "application/activity+json" } }));
991
+ esm_default.spyGlobal();
992
+ esm_default.get("begin:https://localhost/.well-known/webfinger", {
993
+ headers: { "Content-Type": "application/jrd+json" },
994
+ body: {
995
+ subject: "acct:test@localhost",
996
+ links: [{
997
+ rel: "self",
998
+ type: "application/activity+json",
999
+ href: "https://localhost/actor"
1000
+ }]
1001
+ }
1002
+ });
1003
+ esm_default.get("https://localhost/actor", {
1004
+ headers: { "Content-Type": "application/activity+json" },
1005
+ body: {
1006
+ "@context": "https://www.w3.org/ns/activitystreams",
1007
+ "type": "Person",
1008
+ "id": "https://localhost/actor",
1009
+ "preferredUsername": "test"
1010
+ }
1011
+ });
976
1012
  await t.step("allowPrivateAddress: true", async () => {
977
1013
  const federation = createFederation({
978
1014
  kv: new MemoryKvStore(),
@@ -993,17 +1029,17 @@ test("ContextImpl.lookupObject()", async (t) => {
993
1029
  const result = await ctx.lookupObject("@test@localhost");
994
1030
  assertEquals(result, null);
995
1031
  });
996
- uninstall();
1032
+ esm_default.hardReset();
997
1033
  });
998
1034
  test("ContextImpl.sendActivity()", async (t) => {
999
- install();
1035
+ esm_default.spyGlobal();
1000
1036
  let verified = null;
1001
1037
  let request = null;
1002
1038
  let collectionSyncHeader = null;
1003
- mock("POST@/inbox", async (req) => {
1039
+ esm_default.post("https://example.com/inbox", async (cl) => {
1004
1040
  verified = [];
1005
- request = req.clone();
1006
- collectionSyncHeader = req.headers.get("Collection-Synchronization");
1041
+ request = cl.request.clone();
1042
+ collectionSyncHeader = cl.request.headers.get("Collection-Synchronization");
1007
1043
  const options = {
1008
1044
  async documentLoader(url) {
1009
1045
  const response = await federation.fetch(new Request(url), { contextData: void 0 });
@@ -1026,7 +1062,7 @@ test("ContextImpl.sendActivity()", async (t) => {
1026
1062
  async set(_keyId, _key) {}
1027
1063
  }
1028
1064
  };
1029
- let json = await req.json();
1065
+ let json = await cl.request.json();
1030
1066
  if (await verifyJsonLd(json, options)) verified.push("ld");
1031
1067
  json = detachSignature(json);
1032
1068
  let activity = await verifyObject(Activity, json, options);
@@ -1300,6 +1336,7 @@ test("ContextImpl.sendActivity()", async (t) => {
1300
1336
  });
1301
1337
  assertNotEquals(collectionSyncHeader, null);
1302
1338
  });
1339
+ esm_default.hardReset();
1303
1340
  });
1304
1341
  test("ContextImpl.routeActivity()", async () => {
1305
1342
  const federation = new FederationImpl({ kv: new MemoryKvStore() });
@@ -1367,17 +1404,17 @@ test("ContextImpl.routeActivity()", async () => {
1367
1404
  ]);
1368
1405
  });
1369
1406
  test("InboxContextImpl.forwardActivity()", async (t) => {
1370
- install();
1407
+ esm_default.spyGlobal();
1371
1408
  let verified = null;
1372
1409
  let request = null;
1373
- mock("POST@/inbox", async (req) => {
1410
+ esm_default.post("https://example.com/inbox", async (cl) => {
1374
1411
  verified = [];
1375
- request = req.clone();
1412
+ request = cl.request.clone();
1376
1413
  const options = {
1377
1414
  documentLoader: mockDocumentLoader,
1378
1415
  contextLoader: mockDocumentLoader
1379
1416
  };
1380
- let json = await req.json();
1417
+ let json = await cl.request.json();
1381
1418
  if (await verifyJsonLd(json, options)) verified.push("ld");
1382
1419
  json = detachSignature(json);
1383
1420
  let activity = await verifyObject(Activity, json, options);
@@ -1486,7 +1523,7 @@ test("InboxContextImpl.forwardActivity()", async (t) => {
1486
1523
  }, { skipIfUnsigned: true });
1487
1524
  assertEquals(verified, ["ld"]);
1488
1525
  });
1489
- uninstall();
1526
+ esm_default.hardReset();
1490
1527
  });
1491
1528
 
1492
1529
  //#endregion
@@ -14,7 +14,7 @@ import { assertNotEquals } from "../node_modules/.pnpm/@jsr_std__assert@0.226.0/
14
14
  import { assertRejects } from "../node_modules/.pnpm/@jsr_std__assert@0.226.0/node_modules/@jsr/std__assert/assert_rejects.js";
15
15
  import { mockDocumentLoader } from "../testing/docloader.js";
16
16
  import { ed25519Multikey, ed25519PrivateKey, rsaPrivateKey2, rsaPublicKey2 } from "../testing/keys.js";
17
- import { install, mock, uninstall } from "../node_modules/.pnpm/@jsr_hongminhee__deno-mock-fetch@0.3.2/node_modules/@jsr/hongminhee__deno-mock-fetch/mod.js";
17
+ import { esm_default } from "../node_modules/.pnpm/fetch-mock@12.5.2/node_modules/fetch-mock/dist/esm/index.js";
18
18
 
19
19
  //#region federation/send.test.ts
20
20
  test("extractInboxes()", () => {
@@ -129,12 +129,12 @@ test("extractInboxes()", () => {
129
129
  });
130
130
  });
131
131
  test("sendActivity()", async (t) => {
132
- install();
132
+ esm_default.spyGlobal();
133
133
  let httpSigVerified = null;
134
134
  let request = null;
135
- mock("POST@/inbox", async (req) => {
135
+ esm_default.post("https://example.com/inbox", async (cl) => {
136
136
  httpSigVerified = false;
137
- request = req.clone();
137
+ request = cl.request.clone();
138
138
  const options = {
139
139
  documentLoader: mockDocumentLoader,
140
140
  contextLoader: mockDocumentLoader
@@ -185,11 +185,9 @@ test("sendActivity()", async (t) => {
185
185
  assertEquals(request?.url, "https://example.com/inbox");
186
186
  assertEquals(request?.headers.get("Content-Type"), "application/activity+json");
187
187
  });
188
- mock("POST@/inbox2", (_req) => {
189
- return new Response("something went wrong", {
190
- status: 500,
191
- statusText: "Internal Server Error"
192
- });
188
+ esm_default.post("https://example.com/inbox2", {
189
+ status: 500,
190
+ body: "something went wrong"
193
191
  });
194
192
  await t.step("failure", async () => {
195
193
  const activity = {
@@ -208,7 +206,7 @@ test("sendActivity()", async (t) => {
208
206
  inbox: new URL("https://example.com/inbox2")
209
207
  }), Error, "Failed to send activity https://example.com/activity to https://example.com/inbox2 (500 Internal Server Error):\nsomething went wrong");
210
208
  });
211
- uninstall();
209
+ esm_default.hardReset();
212
210
  });
213
211
 
214
212
  //#endregion
@@ -3,14 +3,8 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
 
5
5
  //#region node_modules/.pnpm/@jsr+std__path@1.0.9/node_modules/@jsr/std__path/_common/constants.js
6
- const CHAR_UPPERCASE_A = 65;
7
- const CHAR_LOWERCASE_A = 97;
8
- const CHAR_UPPERCASE_Z = 90;
9
- const CHAR_LOWERCASE_Z = 122;
10
6
  const CHAR_DOT = 46;
11
7
  const CHAR_FORWARD_SLASH = 47;
12
- const CHAR_BACKWARD_SLASH = 92;
13
- const CHAR_COLON = 58;
14
8
 
15
9
  //#endregion
16
- export { CHAR_BACKWARD_SLASH, CHAR_COLON, CHAR_DOT, CHAR_FORWARD_SLASH, CHAR_LOWERCASE_A, CHAR_LOWERCASE_Z, CHAR_UPPERCASE_A, CHAR_UPPERCASE_Z };
10
+ export { CHAR_DOT, CHAR_FORWARD_SLASH };
@@ -11,4 +11,4 @@ function assertArg(path) {
11
11
  }
12
12
 
13
13
  //#endregion
14
- export { assertArg };
14
+ export { assertArg as assertArg$2 };
@@ -10,4 +10,4 @@ function assertArg(url) {
10
10
  }
11
11
 
12
12
  //#endregion
13
- export { assertArg as assertArg$2 };
13
+ export { assertArg };