@fedify/fedify 1.7.15 → 1.7.16

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 (129) hide show
  1. package/dist/actor-BzWaWDTY.js +146 -0
  2. package/dist/actor.js +34648 -5
  3. package/dist/{assert.js → assert-C-mZuSQl.js} +1 -1
  4. package/dist/{assert_instance_of.js → assert_instance_of-lS0Jr2iu.js} +1 -1
  5. package/dist/{assert_is_error.js → assert_is_error-CIYFACrT.js} +1 -1
  6. package/dist/{assert_not_equals.js → assert_not_equals-C1azCAB0.js} +1 -1
  7. package/dist/{assert_rejects.js → assert_rejects-Bkh5lA1a.js} +2 -2
  8. package/dist/{assert_throws.js → assert_throws-CmpfkWEM.js} +2 -2
  9. package/dist/authdocloader-1vrHbYJF.js +51 -0
  10. package/dist/authdocloader.js +2 -4
  11. package/dist/{builder.js → builder-8YjpOSrf.js} +5 -5
  12. package/dist/{client.js → client-CJ3nfMyp.js} +2 -2
  13. package/dist/compat/transformers.test.js +30 -30
  14. package/dist/{context.js → context-OXYKUfFL.js} +4 -4
  15. package/dist/docloader-I3SkMpZK.js +4421 -0
  16. package/dist/docloader.js +61 -4
  17. package/dist/{esm.js → esm-BRXvTSrx.js} +1 -1
  18. package/dist/federation/builder.test.js +17 -17
  19. package/dist/federation/collection.test.js +8 -8
  20. package/dist/federation/handler.test.js +36 -36
  21. package/dist/federation/inbox.test.js +11 -11
  22. package/dist/federation/keycache.test.js +12 -12
  23. package/dist/federation/kv.test.js +8 -8
  24. package/dist/federation/middleware.test.js +39 -39
  25. package/dist/federation/mq.test.js +10 -10
  26. package/dist/federation/retry.test.js +5 -5
  27. package/dist/federation/router.test.js +9 -9
  28. package/dist/federation/send.test.js +23 -23
  29. package/dist/http-CiQH4CF3.js +789 -0
  30. package/dist/http.js +4 -5
  31. package/dist/{inbox.js → inbox-BqBPO0vG.js} +3 -3
  32. package/dist/key-Ba-IjS2c.js +259 -0
  33. package/dist/key-CdNa4Um6.js +16 -0
  34. package/dist/key.js +1 -7
  35. package/dist/key2.js +2 -4
  36. package/dist/{keycache.js → keycache-BdgRTisV.js} +1 -1
  37. package/dist/{keys.js → keys-CLFIvF3E.js} +1 -1
  38. package/dist/{ld.js → ld-Dm1tdWDX.js} +4 -4
  39. package/dist/{lookup2.js → lookup-BumKjgCt.js} +4 -4
  40. package/dist/lookup-CoCshjhM.js +129 -0
  41. package/dist/lookup.js +1 -3
  42. package/dist/middleware-Dvd4BUlF.js +2661 -0
  43. package/dist/middleware-pC0Ld2I6.js +32 -0
  44. package/dist/middleware.js +1222 -364
  45. package/dist/middleware2.js +6 -21
  46. package/dist/nodeinfo/client.test.js +12 -12
  47. package/dist/nodeinfo/handler.test.js +34 -34
  48. package/dist/nodeinfo/semver.test.js +8 -8
  49. package/dist/nodeinfo/types.test.js +9 -9
  50. package/dist/{owner.js → owner-BO3ZhyYg.js} +3 -3
  51. package/dist/proof-Btlfk6hr.js +255 -0
  52. package/dist/proof.js +330 -8
  53. package/dist/runtime/authdocloader.test.js +20 -20
  54. package/dist/runtime/docloader.test.js +13 -13
  55. package/dist/runtime/key.test.js +15 -15
  56. package/dist/runtime/langstr.test.js +8 -8
  57. package/dist/runtime/multibase/multibase.test.js +8 -8
  58. package/dist/runtime/url.test.js +7 -7
  59. package/dist/{send.js → send-Dj-482tr.js} +2 -2
  60. package/dist/sig/http.test.js +20 -20
  61. package/dist/sig/key.test.js +17 -17
  62. package/dist/sig/ld.test.js +18 -18
  63. package/dist/sig/owner.test.js +20 -20
  64. package/dist/sig/proof.test.js +19 -19
  65. package/dist/{std__assert.js → std__assert-BdP_WkD-.js} +1 -1
  66. package/dist/testing/docloader.test.js +8 -8
  67. package/dist/testing/mod.js +2 -2
  68. package/dist/{testing.js → testing-qaAD4B0t.js} +1 -1
  69. package/dist/types-CB_2uuCA.js +51 -0
  70. package/dist/types.js +397 -3
  71. package/dist/vocab/actor.test.js +16 -16
  72. package/dist/vocab/lookup.test.js +17 -17
  73. package/dist/vocab/type.test.js +9 -9
  74. package/dist/vocab/vocab.test.js +17 -17
  75. package/dist/vocab-B8zleLsO.js +34386 -0
  76. package/dist/vocab.js +133 -34351
  77. package/dist/webfinger/handler.test.js +34 -34
  78. package/dist/webfinger/lookup.test.js +11 -11
  79. package/dist/x/cfworkers.test.js +7 -7
  80. package/package.json +1 -1
  81. /package/dist/{assert_equals.js → assert_equals-Dy0MG_Zw.js} +0 -0
  82. /package/dist/{chunk.js → chunk-DvTpRkcT.js} +0 -0
  83. /package/dist/{collection.js → collection-XNLQhehO.js} +0 -0
  84. /package/dist/compat/{transformers.test.d.ts → transformers.test-DnJbd34u.d.ts} +0 -0
  85. /package/dist/{denokv.js → denokv-NcJeZ6rP.js} +0 -0
  86. /package/dist/{docloader2.js → docloader-BDSHZfTJ.js} +0 -0
  87. /package/dist/federation/{builder.test.d.ts → builder.test-Bpt6NOZ6.d.ts} +0 -0
  88. /package/dist/federation/{collection.test.d.ts → collection.test-DKJ6JOZz.d.ts} +0 -0
  89. /package/dist/federation/{handler.test.d.ts → handler.test-BMT7uLC0.d.ts} +0 -0
  90. /package/dist/federation/{inbox.test.d.ts → inbox.test-Do6i02Qp.d.ts} +0 -0
  91. /package/dist/federation/{keycache.test.d.ts → keycache.test-BT83IPZY.d.ts} +0 -0
  92. /package/dist/federation/{kv.test.d.ts → kv.test-kFzzF2VN.d.ts} +0 -0
  93. /package/dist/federation/{middleware.test.d.ts → middleware.test-B1R4_e3-.d.ts} +0 -0
  94. /package/dist/federation/{mq.test.d.ts → mq.test-l79EQQOe.d.ts} +0 -0
  95. /package/dist/federation/{retry.test.d.ts → retry.test-BqS50VCX.d.ts} +0 -0
  96. /package/dist/federation/{router.test.d.ts → router.test-CYQl4po-.d.ts} +0 -0
  97. /package/dist/federation/{send.test.d.ts → send.test-COUnNUzv.d.ts} +0 -0
  98. /package/dist/{kv.js → kv-QeuZ51go.js} +0 -0
  99. /package/dist/{langstr.js → langstr-pFHBDU4y.js} +0 -0
  100. /package/dist/{multibase.js → multibase-DBcKTV2a.js} +0 -0
  101. /package/dist/nodeinfo/{client.test.d.ts → client.test-CZLe79hL.d.ts} +0 -0
  102. /package/dist/nodeinfo/{handler.test.d.ts → handler.test-B-EDZ_hK.d.ts} +0 -0
  103. /package/dist/nodeinfo/{semver.test.d.ts → semver.test-BEuuQSEM.d.ts} +0 -0
  104. /package/dist/nodeinfo/{types.test.d.ts → types.test-B5AT89WV.d.ts} +0 -0
  105. /package/dist/{retry.js → retry-BQet39_l.js} +0 -0
  106. /package/dist/{router.js → router-BuDkN4RQ.js} +0 -0
  107. /package/dist/runtime/{authdocloader.test.d.ts → authdocloader.test-hCRKzn9v.d.ts} +0 -0
  108. /package/dist/runtime/{docloader.test.d.ts → docloader.test-CVd7i_5h.d.ts} +0 -0
  109. /package/dist/runtime/{key.test.d.ts → key.test-DBsILYSD.d.ts} +0 -0
  110. /package/dist/runtime/{langstr.test.d.ts → langstr.test-CiKxuuRY.d.ts} +0 -0
  111. /package/dist/runtime/multibase/{multibase.test.d.ts → multibase.test-Brh6gPBP.d.ts} +0 -0
  112. /package/dist/runtime/{url.test.d.ts → url.test-DlRqkU2j.d.ts} +0 -0
  113. /package/dist/{semver.js → semver-D9d-VO-_.js} +0 -0
  114. /package/dist/sig/{http.test.d.ts → http.test-BpXNAWNI.d.ts} +0 -0
  115. /package/dist/sig/{key.test.d.ts → key.test-B2iLIugy.d.ts} +0 -0
  116. /package/dist/sig/{ld.test.d.ts → ld.test-D-cI70Gw.d.ts} +0 -0
  117. /package/dist/sig/{owner.test.d.ts → owner.test-B_YRjMPj.d.ts} +0 -0
  118. /package/dist/sig/{proof.test.d.ts → proof.test-BagEM_-4.d.ts} +0 -0
  119. /package/dist/testing/{docloader.test.d.ts → docloader.test-lrzf6sDZ.d.ts} +0 -0
  120. /package/dist/testing/{mod.d.ts → mod-3uM8ZvS7.d.ts} +0 -0
  121. /package/dist/{type.js → type-DFsmi-p1.js} +0 -0
  122. /package/dist/{url.js → url-BdNvnK9P.js} +0 -0
  123. /package/dist/vocab/{actor.test.d.ts → actor.test-ClC-iVWk.d.ts} +0 -0
  124. /package/dist/vocab/{lookup.test.d.ts → lookup.test-Cq1I-27w.d.ts} +0 -0
  125. /package/dist/vocab/{type.test.d.ts → type.test-bfFiYGcs.d.ts} +0 -0
  126. /package/dist/vocab/{vocab.test.d.ts → vocab.test-h-ZTisfu.d.ts} +0 -0
  127. /package/dist/webfinger/{handler.test.d.ts → handler.test-DiUeEDDD.d.ts} +0 -0
  128. /package/dist/webfinger/{lookup.test.d.ts → lookup.test-D9onm3U3.d.ts} +0 -0
  129. /package/dist/x/{cfworkers.test.d.ts → cfworkers.test-KXHlJ29z.d.ts} +0 -0
@@ -0,0 +1,146 @@
1
+
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+ globalThis.addEventListener = () => {};
5
+
6
+ import { d as version, u as name } from "./docloader-I3SkMpZK.js";
7
+ import { S as Person, T as Service, r as Application, u as Group, x as Organization } from "./vocab-B8zleLsO.js";
8
+ import { t as lookupWebFinger } from "./lookup-CoCshjhM.js";
9
+ import { t as getTypeId } from "./type-DFsmi-p1.js";
10
+ import { SpanStatusCode, trace } from "@opentelemetry/api";
11
+ import { domainToASCII, domainToUnicode } from "node:url";
12
+
13
+ //#region vocab/actor.ts
14
+ /**
15
+ * Checks if the given object is an {@link Actor}.
16
+ * @param object The object to check.
17
+ * @returns `true` if the given object is an {@link Actor}.
18
+ */
19
+ function isActor(object) {
20
+ return object instanceof Application || object instanceof Group || object instanceof Organization || object instanceof Person || object instanceof Service;
21
+ }
22
+ /**
23
+ * Gets the type name of the given actor.
24
+ * @param actor The actor to get the type name of.
25
+ * @returns The type name of the given actor.
26
+ */
27
+ function getActorTypeName(actor) {
28
+ if (actor instanceof Application) return "Application";
29
+ else if (actor instanceof Group) return "Group";
30
+ else if (actor instanceof Organization) return "Organization";
31
+ else if (actor instanceof Person) return "Person";
32
+ else if (actor instanceof Service) return "Service";
33
+ throw new Error("Unknown actor type.");
34
+ }
35
+ /**
36
+ * Gets the actor class by the given type name.
37
+ * @param typeName The type name to get the actor class by.
38
+ * @returns The actor class by the given type name.
39
+ */
40
+ function getActorClassByTypeName(typeName) {
41
+ switch (typeName) {
42
+ case "Application": return Application;
43
+ case "Group": return Group;
44
+ case "Organization": return Organization;
45
+ case "Person": return Person;
46
+ case "Service": return Service;
47
+ }
48
+ throw new Error("Unknown actor type name.");
49
+ }
50
+ /**
51
+ * Gets the actor handle, of the form `@username@domain`, from the given actor
52
+ * or an actor URI.
53
+ *
54
+ * @example
55
+ * ``` typescript
56
+ * // Get the handle of an actor object:
57
+ * await getActorHandle(
58
+ * new Person({ id: new URL("https://fosstodon.org/users/hongminhee") })
59
+ * );
60
+ *
61
+ * // Get the handle of an actor URI:
62
+ * await getActorHandle(new URL("https://fosstodon.org/users/hongminhee"));
63
+ * ```
64
+ *
65
+ * @param actor The actor or actor URI to get the handle from.
66
+ * @param options The extra options for getting the actor handle.
67
+ * @returns The actor handle. It starts with `@` and is followed by the
68
+ * username and domain, separated by `@` by default (it can be
69
+ * customized with the options).
70
+ * @throws {TypeError} If the actor does not have enough information to get the
71
+ * handle.
72
+ * @since 0.4.0
73
+ */
74
+ async function getActorHandle(actor, options = {}) {
75
+ return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).startActiveSpan("activitypub.get_actor_handle", async (span) => {
76
+ if (isActor(actor)) {
77
+ if (actor.id != null) span.setAttribute("activitypub.actor.id", actor.id.href);
78
+ span.setAttribute("activitypub.actor.type", getTypeId(actor).href);
79
+ }
80
+ try {
81
+ return await getActorHandleInternal(actor, options);
82
+ } catch (error) {
83
+ span.setStatus({
84
+ code: SpanStatusCode.ERROR,
85
+ message: String(error)
86
+ });
87
+ throw error;
88
+ } finally {
89
+ span.end();
90
+ }
91
+ });
92
+ }
93
+ async function getActorHandleInternal(actor, options = {}) {
94
+ const actorId = actor instanceof URL ? actor : actor.id;
95
+ if (actorId != null) {
96
+ const result = await lookupWebFinger(actorId, {
97
+ userAgent: options.userAgent,
98
+ tracerProvider: options.tracerProvider
99
+ });
100
+ if (result != null) {
101
+ const aliases = [...result.aliases ?? []];
102
+ if (result.subject != null) aliases.unshift(result.subject);
103
+ for (const alias of aliases) {
104
+ const match = alias.match(/^acct:([^@]+)@([^@]+)$/);
105
+ if (match != null) {
106
+ if (new URL(`https://${match[2]}/`).hostname !== actorId.hostname && !await verifyCrossOriginActorHandle(actorId.href, alias, options.userAgent, options.tracerProvider)) continue;
107
+ return normalizeActorHandle(`@${match[1]}@${match[2]}`, options);
108
+ }
109
+ }
110
+ }
111
+ }
112
+ if (!(actor instanceof URL) && actor.preferredUsername != null && actor.id != null) return normalizeActorHandle(`@${actor.preferredUsername}@${actor.id.host}`, options);
113
+ throw new TypeError("Actor does not have enough information to get the handle.");
114
+ }
115
+ async function verifyCrossOriginActorHandle(actorId, alias, userAgent, tracerProvider) {
116
+ const response = await lookupWebFinger(alias, {
117
+ userAgent,
118
+ tracerProvider
119
+ });
120
+ if (response == null) return false;
121
+ for (const alias$1 of response.aliases ?? []) if (new URL(alias$1).href === actorId) return true;
122
+ return false;
123
+ }
124
+ /**
125
+ * Normalizes the given actor handle.
126
+ * @param handle The full handle of the actor to normalize.
127
+ * @param options The options for normalizing the actor handle.
128
+ * @returns The normalized actor handle.
129
+ * @throws {TypeError} If the actor handle is invalid.
130
+ * @since 0.9.0
131
+ */
132
+ function normalizeActorHandle(handle, options = {}) {
133
+ handle = handle.replace(/^@/, "");
134
+ const atPos = handle.indexOf("@");
135
+ if (atPos < 1) throw new TypeError("Invalid actor handle.");
136
+ let domain = handle.substring(atPos + 1);
137
+ if (domain.length < 1 || domain.includes("@")) throw new TypeError("Invalid actor handle.");
138
+ domain = domain.toLowerCase();
139
+ domain = options.punycode ? domainToASCII(domain) : domainToUnicode(domain);
140
+ domain = domain.toLowerCase();
141
+ const user = handle.substring(0, atPos);
142
+ return options.trimLeadingAt ? `${user}@${domain}` : `@${user}@${domain}`;
143
+ }
144
+
145
+ //#endregion
146
+ export { normalizeActorHandle as a, isActor as i, getActorHandle as n, getActorTypeName as r, getActorClassByTypeName as t };