@fedify/fedify 2.5.0-dev.2687 → 2.5.0-dev.2710

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 (244) hide show
  1. package/dist/federation/mod.cjs +1 -1
  2. package/dist/federation/mod.js +1 -1
  3. package/dist/{federation-pFFwPyoZ.cjs → federation-JvzYDx0P.cjs} +3 -3
  4. package/dist/{http-CXX-QPzs.cjs → http-BG5cDmTS.cjs} +1 -1
  5. package/dist/{http-T7h9GBAN.js → http-MUf125Jc.js} +1 -1
  6. package/dist/{kv-cache-C6XX_fwz.cjs → kv-cache-A2po7h0_.cjs} +1 -1
  7. package/dist/{kv-cache-EFcb1kkU.js → kv-cache-CbWc1BZA.js} +1 -1
  8. package/dist/{middleware-Bj91r7r2.js → middleware-DzzdJ7Wz.js} +3 -3
  9. package/dist/mod.cjs +4 -4
  10. package/dist/mod.js +4 -4
  11. package/dist/{portable-collection-Do5QA2oy.js → portable-collection-CAer9RWN.js} +1 -1
  12. package/dist/{portable-collection-BOl9oKrt.cjs → portable-collection-d8w7TCn9.cjs} +1 -1
  13. package/dist/sig/mod.cjs +2 -2
  14. package/dist/sig/mod.js +2 -2
  15. package/dist/utils/mod.cjs +1 -1
  16. package/dist/utils/mod.js +1 -1
  17. package/package.json +22 -9
  18. package/skills/fedify/SKILL.md +10 -0
  19. package/dist/accept-CPVqki78.mjs +0 -145
  20. package/dist/activity-listener-CELFAodc.mjs +0 -44
  21. package/dist/assert-D1Eafmd_.mjs +0 -23
  22. package/dist/assert_equals-Z6IcEbWU.mjs +0 -987
  23. package/dist/assert_exists-cffSpJ7X.mjs +0 -28
  24. package/dist/assert_false-CPdRnc3E.mjs +0 -23
  25. package/dist/assert_greater_or_equal-BlafOF4-.mjs +0 -31
  26. package/dist/assert_instance_of-mrXWWNY-.mjs +0 -37
  27. package/dist/assert_not_equals-CpPK2t89.mjs +0 -30
  28. package/dist/assert_rejects-CTptdYck.mjs +0 -39
  29. package/dist/assert_strict_equals-CYvBmkpC.mjs +0 -42
  30. package/dist/assert_throws-BYITOvPO.mjs +0 -74
  31. package/dist/assertion_error-B-cx0fFA.mjs +0 -31
  32. package/dist/audience-CHQ-FlLD.mjs +0 -95
  33. package/dist/builder-D1FP_5nQ.mjs +0 -911
  34. package/dist/circuit-breaker-XJ53md4S.mjs +0 -544
  35. package/dist/circuit-breaker-test-utils-DW6YC_Pe.mjs +0 -14
  36. package/dist/client-5SIFzW3q.mjs +0 -441
  37. package/dist/codec-C6rTrpIp.mjs +0 -147
  38. package/dist/collection-CnnP1UAv.mjs +0 -44
  39. package/dist/compat/outgoing-jsonld.test.d.mts +0 -2
  40. package/dist/compat/outgoing-jsonld.test.mjs +0 -257
  41. package/dist/compat/public-audience.test.d.mts +0 -2
  42. package/dist/compat/public-audience.test.mjs +0 -187
  43. package/dist/compat/secured-document.test.d.mts +0 -2
  44. package/dist/compat/secured-document.test.mjs +0 -58
  45. package/dist/compat/transformers.test.d.mts +0 -2
  46. package/dist/compat/transformers.test.mjs +0 -62
  47. package/dist/compound-proof-DSHhnOEW.mjs +0 -1019
  48. package/dist/context-LgGFFSz7.mjs +0 -146
  49. package/dist/deno-C50ikGBU.mjs +0 -8
  50. package/dist/dist-_geWsuaI.mjs +0 -189
  51. package/dist/docloader-BY-SEID0.mjs +0 -136
  52. package/dist/esm-BHXXx4Wx.mjs +0 -1233
  53. package/dist/exporter-DVG68ozH.mjs +0 -263
  54. package/dist/federation/audience.test.d.mts +0 -2
  55. package/dist/federation/audience.test.mjs +0 -130
  56. package/dist/federation/builder.test.d.mts +0 -2
  57. package/dist/federation/builder.test.mjs +0 -396
  58. package/dist/federation/circuit-breaker.test.d.mts +0 -2
  59. package/dist/federation/circuit-breaker.test.mjs +0 -1277
  60. package/dist/federation/collection.test.d.mts +0 -2
  61. package/dist/federation/collection.test.mjs +0 -21
  62. package/dist/federation/compound-fanout.test.d.mts +0 -2
  63. package/dist/federation/compound-fanout.test.mjs +0 -231
  64. package/dist/federation/handler-compound-proof.test.d.mts +0 -2
  65. package/dist/federation/handler-compound-proof.test.mjs +0 -384
  66. package/dist/federation/handler.test.d.mts +0 -2
  67. package/dist/federation/handler.test.mjs +0 -5445
  68. package/dist/federation/hashlink-media.test.d.mts +0 -2
  69. package/dist/federation/hashlink-media.test.mjs +0 -422
  70. package/dist/federation/idempotency.test.d.mts +0 -2
  71. package/dist/federation/idempotency.test.mjs +0 -207
  72. package/dist/federation/inbox-actorless.test.d.mts +0 -2
  73. package/dist/federation/inbox-actorless.test.mjs +0 -522
  74. package/dist/federation/inbox-authentication.test.d.mts +0 -2
  75. package/dist/federation/inbox-authentication.test.mjs +0 -220
  76. package/dist/federation/inbox-report.test.d.mts +0 -2
  77. package/dist/federation/inbox-report.test.mjs +0 -719
  78. package/dist/federation/inbox-view.test.d.mts +0 -2
  79. package/dist/federation/inbox-view.test.mjs +0 -369
  80. package/dist/federation/inbox.test.d.mts +0 -2
  81. package/dist/federation/inbox.test.mjs +0 -139
  82. package/dist/federation/keycache.test.d.mts +0 -2
  83. package/dist/federation/keycache.test.mjs +0 -337
  84. package/dist/federation/kv.test.d.mts +0 -2
  85. package/dist/federation/kv.test.mjs +0 -88
  86. package/dist/federation/metrics.test.d.mts +0 -2
  87. package/dist/federation/metrics.test.mjs +0 -634
  88. package/dist/federation/middleware.test.d.mts +0 -2
  89. package/dist/federation/middleware.test.mjs +0 -9314
  90. package/dist/federation/mq.test.d.mts +0 -2
  91. package/dist/federation/mq.test.mjs +0 -591
  92. package/dist/federation/negotiation.test.d.mts +0 -2
  93. package/dist/federation/negotiation.test.mjs +0 -18
  94. package/dist/federation/outbound-body.test.d.mts +0 -2
  95. package/dist/federation/outbound-body.test.mjs +0 -149
  96. package/dist/federation/outbound-capture.test.d.mts +0 -2
  97. package/dist/federation/outbound-capture.test.mjs +0 -394
  98. package/dist/federation/outbound-dispatch.test.d.mts +0 -2
  99. package/dist/federation/outbound-dispatch.test.mjs +0 -368
  100. package/dist/federation/outbound-document.test.d.mts +0 -2
  101. package/dist/federation/outbound-document.test.mjs +0 -171
  102. package/dist/federation/outbound-provenance.test.d.mts +0 -2
  103. package/dist/federation/outbound-provenance.test.mjs +0 -543
  104. package/dist/federation/outbound-report.test.d.mts +0 -2
  105. package/dist/federation/outbound-report.test.mjs +0 -5475
  106. package/dist/federation/outbound-workers.test.d.mts +0 -2
  107. package/dist/federation/outbound-workers.test.mjs +0 -64
  108. package/dist/federation/outbound-workflow.test.d.mts +0 -2
  109. package/dist/federation/outbound-workflow.test.mjs +0 -154
  110. package/dist/federation/outgoing-proof.test.d.mts +0 -2
  111. package/dist/federation/outgoing-proof.test.mjs +0 -933
  112. package/dist/federation/portable-actor.test.d.mts +0 -2
  113. package/dist/federation/portable-actor.test.mjs +0 -496
  114. package/dist/federation/portable-chain.test.d.mts +0 -2
  115. package/dist/federation/portable-chain.test.mjs +0 -370
  116. package/dist/federation/portable-collection.test.d.mts +0 -2
  117. package/dist/federation/portable-collection.test.mjs +0 -832
  118. package/dist/federation/portable-delivery.test.d.mts +0 -2
  119. package/dist/federation/portable-delivery.test.mjs +0 -845
  120. package/dist/federation/portable-gateway-keys.test.d.mts +0 -2
  121. package/dist/federation/portable-gateway-keys.test.mjs +0 -692
  122. package/dist/federation/portable-inbox.test.d.mts +0 -2
  123. package/dist/federation/portable-inbox.test.mjs +0 -1960
  124. package/dist/federation/portable-parse-uri.test.d.mts +0 -2
  125. package/dist/federation/portable-parse-uri.test.mjs +0 -348
  126. package/dist/federation/portable-route-activity.test.d.mts +0 -2
  127. package/dist/federation/portable-route-activity.test.mjs +0 -259
  128. package/dist/federation/portable.test.d.mts +0 -2
  129. package/dist/federation/portable.test.mjs +0 -1072
  130. package/dist/federation/retry.test.d.mts +0 -2
  131. package/dist/federation/retry.test.mjs +0 -42
  132. package/dist/federation/router.test.d.mts +0 -2
  133. package/dist/federation/router.test.mjs +0 -123
  134. package/dist/federation/send.test.d.mts +0 -2
  135. package/dist/federation/send.test.mjs +0 -1421
  136. package/dist/federation/tasks/codec.test.d.mts +0 -2
  137. package/dist/federation/tasks/codec.test.mjs +0 -302
  138. package/dist/federation/tasks/enqueue.test.d.mts +0 -2
  139. package/dist/federation/tasks/enqueue.test.mjs +0 -1095
  140. package/dist/federation/tasks/tasks.test.d.mts +0 -2
  141. package/dist/federation/tasks/tasks.test.mjs +0 -1229
  142. package/dist/federation/temporal.test.d.mts +0 -2
  143. package/dist/federation/temporal.test.mjs +0 -71
  144. package/dist/federation/webfinger.test.d.mts +0 -2
  145. package/dist/federation/webfinger.test.mjs +0 -944
  146. package/dist/http-BXbQQZDM.mjs +0 -1449
  147. package/dist/inbox-authentication-CgonVRkg.mjs +0 -198
  148. package/dist/inbox-cS97XzOD.mjs +0 -399
  149. package/dist/inbox-view-D-d0Ar6o.mjs +0 -385
  150. package/dist/key-owner-evidence-APB6NpSk.mjs +0 -108
  151. package/dist/keycache-N2opu4-3.mjs +0 -221
  152. package/dist/keys-DIJNHW-Y.mjs +0 -120
  153. package/dist/kv-DBRWVx3Q.mjs +0 -104
  154. package/dist/kv-DCHkaJ9-.mjs +0 -92
  155. package/dist/kv-cache-fgbLHGVL.mjs +0 -121
  156. package/dist/ld-BpkhkDGj.mjs +0 -1752
  157. package/dist/map-local-context-conflict-DOYEEJ3u.mjs +0 -204
  158. package/dist/map-local-create-note-B0SeXJms.mjs +0 -214
  159. package/dist/metrics-Uqf8GomB.mjs +0 -818
  160. package/dist/middleware-DcXzz-YK.mjs +0 -9971
  161. package/dist/middleware-DgwZkvJR.mjs +0 -5
  162. package/dist/mq-eF96QxUT.mjs +0 -288
  163. package/dist/negotiation-BAKO9nih.mjs +0 -96
  164. package/dist/nodeinfo/client.test.d.mts +0 -2
  165. package/dist/nodeinfo/client.test.mjs +0 -1364
  166. package/dist/nodeinfo/handler.test.d.mts +0 -2
  167. package/dist/nodeinfo/handler.test.mjs +0 -94
  168. package/dist/nodeinfo/types.test.d.mts +0 -2
  169. package/dist/nodeinfo/types.test.mjs +0 -192
  170. package/dist/otel/exporter.test.d.mts +0 -2
  171. package/dist/otel/exporter.test.mjs +0 -887
  172. package/dist/outbound-body-CckPA5gc.mjs +0 -83
  173. package/dist/outbound-capture-DVgnRzlf.mjs +0 -184
  174. package/dist/outbound-document-BMgwLXTY.mjs +0 -179
  175. package/dist/outgoing-jsonld-4IJqPYos.mjs +0 -205
  176. package/dist/owner-BVenIFg1.mjs +0 -267
  177. package/dist/portable-collection-DIk9gpjL.mjs +0 -418
  178. package/dist/portable-key-C7pVaHNR.mjs +0 -549
  179. package/dist/portable-key-id-Ca30-hOa.mjs +0 -248
  180. package/dist/proof-BlfZ95--.mjs +0 -1420
  181. package/dist/public-audience--klBIOk1.mjs +0 -197
  182. package/dist/retry-zX5xw5e0.mjs +0 -34
  183. package/dist/router-u5O5KCQr.mjs +0 -156
  184. package/dist/secured-document-CxzZZ9nL.mjs +0 -35
  185. package/dist/send-DEGHPGFk.mjs +0 -710
  186. package/dist/sig/accept.test.d.mts +0 -2
  187. package/dist/sig/accept.test.mjs +0 -416
  188. package/dist/sig/compound-proof-discovery.test.d.mts +0 -2
  189. package/dist/sig/compound-proof-discovery.test.mjs +0 -331
  190. package/dist/sig/compound-proof-producer.test.d.mts +0 -2
  191. package/dist/sig/compound-proof-producer.test.mjs +0 -107
  192. package/dist/sig/compound-proof-verification.test.d.mts +0 -2
  193. package/dist/sig/compound-proof-verification.test.mjs +0 -1017
  194. package/dist/sig/compound-proof.test.d.mts +0 -2
  195. package/dist/sig/compound-proof.test.mjs +0 -411
  196. package/dist/sig/http.test.d.mts +0 -2
  197. package/dist/sig/http.test.mjs +0 -3328
  198. package/dist/sig/key-owner-evidence.test.d.mts +0 -2
  199. package/dist/sig/key-owner-evidence.test.mjs +0 -100
  200. package/dist/sig/key.test.d.mts +0 -2
  201. package/dist/sig/key.test.mjs +0 -1250
  202. package/dist/sig/ld.test.d.mts +0 -2
  203. package/dist/sig/ld.test.mjs +0 -1044
  204. package/dist/sig/mitra-receive-interop.test.d.mts +0 -2
  205. package/dist/sig/mitra-receive-interop.test.mjs +0 -260
  206. package/dist/sig/mitra-send-interop.test.d.mts +0 -2
  207. package/dist/sig/mitra-send-interop.test.mjs +0 -461
  208. package/dist/sig/owner.test.d.mts +0 -2
  209. package/dist/sig/owner.test.mjs +0 -202
  210. package/dist/sig/portable-collection.test.d.mts +0 -2
  211. package/dist/sig/portable-collection.test.mjs +0 -697
  212. package/dist/sig/portable-interop.test.d.mts +0 -2
  213. package/dist/sig/portable-interop.test.mjs +0 -156
  214. package/dist/sig/portable-key-id.test.d.mts +0 -2
  215. package/dist/sig/portable-key-id.test.mjs +0 -67
  216. package/dist/sig/portable-key.test.d.mts +0 -2
  217. package/dist/sig/portable-key.test.mjs +0 -1438
  218. package/dist/sig/proof.test.d.mts +0 -2
  219. package/dist/sig/proof.test.mjs +0 -2638
  220. package/dist/sig/tootik-request-interop.test.d.mts +0 -2
  221. package/dist/sig/tootik-request-interop.test.mjs +0 -190
  222. package/dist/sig/tootik-send-interop.test.d.mts +0 -2
  223. package/dist/sig/tootik-send-interop.test.mjs +0 -331
  224. package/dist/sig/verification.test.d.mts +0 -2
  225. package/dist/sig/verification.test.mjs +0 -310
  226. package/dist/std__assert-DvMDRPes.mjs +0 -8
  227. package/dist/tasks-BCUmQbbz.mjs +0 -77
  228. package/dist/temporal-B4oQ8HpW.mjs +0 -95
  229. package/dist/testing/context.test.d.mts +0 -2
  230. package/dist/testing/context.test.mjs +0 -19
  231. package/dist/testing/kv.test.d.mts +0 -2
  232. package/dist/testing/kv.test.mjs +0 -101
  233. package/dist/testing/mod.d.mts +0 -6099
  234. package/dist/testing/mod.mjs +0 -9
  235. package/dist/testing-vrnD5Uaa.mjs +0 -8
  236. package/dist/types-DE_LV1JB.mjs +0 -46
  237. package/dist/utils/docloader.test.d.mts +0 -2
  238. package/dist/utils/docloader.test.mjs +0 -1076
  239. package/dist/utils/kv-cache.test.d.mts +0 -2
  240. package/dist/utils/kv-cache.test.mjs +0 -261
  241. package/dist/verification-C3954hQh.mjs +0 -5
  242. package/dist/verification-Dpfcw8ml.mjs +0 -105
  243. package/dist/vocab/cjs.test.d.mts +0 -2
  244. package/dist/vocab/cjs.test.mjs +0 -27
@@ -1,263 +0,0 @@
1
- import "temporal-polyfill";
2
- import "urlpattern-polyfill";
3
- globalThis.addEventListener = () => {};
4
- import { getLogger } from "@logtape/logtape";
5
- import { ExportResultCode } from "@opentelemetry/core";
6
- //#region src/otel/exporter.ts
7
- /**
8
- * A SpanExporter that persists ActivityPub activity traces to a
9
- * {@link KvStore}. This enables distributed tracing across multiple
10
- * nodes in a Fedify deployment.
11
- *
12
- * The exporter captures activity data from OpenTelemetry span events
13
- * (`activitypub.activity.received` and `activitypub.activity.sent`)
14
- * and stores them in the KvStore with trace context preserved.
15
- *
16
- * @example Basic usage with MemoryKvStore
17
- * ```typescript ignore
18
- * import { MemoryKvStore } from "@fedify/fedify";
19
- * import { FedifySpanExporter } from "@fedify/fedify/otel";
20
- * import {
21
- * BasicTracerProvider,
22
- * SimpleSpanProcessor,
23
- * } from "@opentelemetry/sdk-trace-base";
24
- *
25
- * const kv = new MemoryKvStore();
26
- * const exporter = new FedifySpanExporter(kv, {
27
- * ttl: Temporal.Duration.from({ hours: 1 }),
28
- * });
29
- *
30
- * const provider = new BasicTracerProvider({
31
- * spanProcessors: [new SimpleSpanProcessor(exporter)],
32
- * });
33
- * ```
34
- *
35
- * @example Querying stored traces
36
- * ```typescript ignore
37
- * import { MemoryKvStore } from "@fedify/fedify";
38
- * import { FedifySpanExporter } from "@fedify/fedify/otel";
39
- *
40
- * const kv = new MemoryKvStore();
41
- * const exporter = new FedifySpanExporter(kv);
42
- * const traceId = "abc123";
43
- *
44
- * // Get all activities for a specific trace
45
- * const activities = await exporter.getActivitiesByTraceId(traceId);
46
- *
47
- * // Get recent traces
48
- * const recentTraces = await exporter.getRecentTraces({ limit: 100 });
49
- * ```
50
- *
51
- * @since 1.10.0
52
- */
53
- var FedifySpanExporter = class {
54
- #kv;
55
- #ttl;
56
- #keyPrefix;
57
- /**
58
- * Creates a new FedifySpanExporter.
59
- *
60
- * @param kv The KvStore to persist trace data to.
61
- * @param options Configuration options.
62
- */
63
- constructor(kv, options) {
64
- this.#kv = kv;
65
- this.#ttl = options?.ttl;
66
- this.#keyPrefix = options?.keyPrefix ?? ["fedify", "traces"];
67
- }
68
- /**
69
- * Exports spans to the KvStore.
70
- *
71
- * @param spans The spans to export.
72
- * @param resultCallback Callback to invoke with the export result.
73
- */
74
- export(spans, resultCallback) {
75
- this.#exportAsync(spans).then(() => resultCallback({ code: ExportResultCode.SUCCESS })).catch((error) => {
76
- getLogger([
77
- "fedify",
78
- "otel",
79
- "exporter"
80
- ]).error("Failed to export spans to KvStore: {error}", { error });
81
- resultCallback({ code: ExportResultCode.FAILED });
82
- });
83
- }
84
- async #exportAsync(spans) {
85
- const storeOperations = [];
86
- for (const span of spans) {
87
- const records = this.#extractRecords(span);
88
- for (const record of records) storeOperations.push(this.#storeRecord(record));
89
- }
90
- const rejected = (await Promise.allSettled(storeOperations)).filter((r) => r.status === "rejected");
91
- if (rejected.length > 0) throw new AggregateError(rejected.map((r) => r.reason), "Failed to store one or more trace activity records.");
92
- }
93
- #extractRecords(span) {
94
- const records = [];
95
- const spanContext = span.spanContext();
96
- const traceId = spanContext.traceId;
97
- const spanId = spanContext.spanId;
98
- const parentSpanId = span.parentSpanContext?.spanId;
99
- for (const event of span.events) if (event.name === "activitypub.activity.received") {
100
- const record = this.#extractInboundRecord(event, traceId, spanId, parentSpanId);
101
- if (record != null) records.push(record);
102
- } else if (event.name === "activitypub.activity.sent") {
103
- const record = this.#extractOutboundRecord(event, traceId, spanId, parentSpanId);
104
- if (record != null) records.push(record);
105
- }
106
- return records;
107
- }
108
- #extractInboundRecord(event, traceId, spanId, parentSpanId) {
109
- const attrs = event.attributes;
110
- if (attrs == null) return null;
111
- const activityJson = attrs["activitypub.activity.json"];
112
- if (typeof activityJson !== "string") return null;
113
- let activityType = "Unknown";
114
- let activityId;
115
- let actorId;
116
- try {
117
- const activity = JSON.parse(activityJson);
118
- activityType = activity.type ?? "Unknown";
119
- activityId = activity.id;
120
- if (typeof activity.actor === "string") actorId = activity.actor;
121
- else if (activity.actor != null && typeof activity.actor.id === "string") actorId = activity.actor.id;
122
- } catch {}
123
- const verified = attrs["activitypub.activity.verified"];
124
- const httpSigVerified = attrs["http_signatures.verified"];
125
- const httpSigKeyId = attrs["http_signatures.key_id"];
126
- const httpSigFailureReason = attrs["http_signatures.failure_reason"];
127
- const httpSigKeyFetchStatus = attrs["http_signatures.key_fetch_status"];
128
- const httpSigKeyFetchError = attrs["http_signatures.key_fetch_error"];
129
- const ldSigVerified = attrs["ld_signatures.verified"];
130
- let signatureDetails;
131
- if (typeof httpSigVerified === "boolean" || typeof ldSigVerified === "boolean" || typeof httpSigFailureReason === "string") signatureDetails = {
132
- httpSignaturesVerified: httpSigVerified === true,
133
- httpSignaturesKeyId: typeof httpSigKeyId === "string" && httpSigKeyId !== "" ? httpSigKeyId : void 0,
134
- httpSignaturesFailureReason: typeof httpSigFailureReason === "string" && httpSigFailureReason !== "" ? httpSigFailureReason : void 0,
135
- httpSignaturesKeyFetchStatus: typeof httpSigKeyFetchStatus === "number" ? httpSigKeyFetchStatus : void 0,
136
- httpSignaturesKeyFetchError: typeof httpSigKeyFetchError === "string" && httpSigKeyFetchError !== "" ? httpSigKeyFetchError : void 0,
137
- ldSignaturesVerified: ldSigVerified === true
138
- };
139
- return {
140
- traceId,
141
- spanId,
142
- parentSpanId,
143
- direction: "inbound",
144
- activityType,
145
- activityId,
146
- actorId,
147
- activityJson,
148
- verified: typeof verified === "boolean" ? verified : void 0,
149
- signatureDetails,
150
- timestamp: (/* @__PURE__ */ new Date(event.time[0] * 1e3 + event.time[1] / 1e6)).toISOString()
151
- };
152
- }
153
- #extractOutboundRecord(event, traceId, spanId, parentSpanId) {
154
- const attrs = event.attributes;
155
- if (attrs == null) return null;
156
- const activityJson = attrs["activitypub.activity.json"];
157
- let activityType = "Unknown";
158
- let activityId;
159
- let actorId;
160
- if (typeof activityJson === "string") try {
161
- const activity = JSON.parse(activityJson);
162
- activityType = activity.type ?? "Unknown";
163
- activityId = activity.id;
164
- if (typeof activity.actor === "string") actorId = activity.actor;
165
- else if (activity.actor != null && typeof activity.actor.id === "string") actorId = activity.actor.id;
166
- } catch {}
167
- const inboxUrl = attrs["activitypub.inbox.url"];
168
- const explicitActivityId = attrs["activitypub.activity.id"];
169
- const explicitActivityType = attrs["activitypub.activity.type"];
170
- const explicitActorId = attrs["activitypub.actor.id"];
171
- return {
172
- traceId,
173
- spanId,
174
- parentSpanId,
175
- direction: "outbound",
176
- activityType: typeof explicitActivityType === "string" && explicitActivityType !== "" ? explicitActivityType : activityType,
177
- activityId: activityId ?? (typeof explicitActivityId === "string" && explicitActivityId !== "" ? explicitActivityId : void 0),
178
- actorId: typeof explicitActorId === "string" && explicitActorId !== "" ? explicitActorId : actorId,
179
- ...typeof activityJson === "string" ? { activityJson } : {},
180
- timestamp: (/* @__PURE__ */ new Date(event.time[0] * 1e3 + event.time[1] / 1e6)).toISOString(),
181
- inboxUrl: typeof inboxUrl === "string" ? inboxUrl : void 0
182
- };
183
- }
184
- async #storeRecord(record) {
185
- const options = this.#ttl != null ? { ttl: this.#ttl } : void 0;
186
- const key = [
187
- ...this.#keyPrefix,
188
- record.traceId,
189
- record.spanId
190
- ];
191
- await this.#kv.set(key, record, options);
192
- }
193
- /**
194
- * Gets all activity records for a specific trace ID.
195
- *
196
- * @param traceId The trace ID to query.
197
- * @returns An array of activity records belonging to the trace.
198
- */
199
- async getActivitiesByTraceId(traceId) {
200
- const prefix = [...this.#keyPrefix, traceId];
201
- const records = [];
202
- for await (const entry of this.#kv.list(prefix)) records.push(entry.value);
203
- return records;
204
- }
205
- /**
206
- * Gets recent traces with summary information.
207
- *
208
- * Each summary is computed directly from the activity records currently
209
- * stored for each trace, rather than from a separately maintained
210
- * counter. This guarantees that a trace is discoverable, and its
211
- * `activityCount` accurate, as soon as its records are stored, even if
212
- * an earlier attempt at summarizing it (in a previous version of this
213
- * exporter) never completed, and that the count always reflects
214
- * records that have not expired. It costs a full scan of every stored
215
- * record on every call, including full inbound activity JSON. The
216
- * `limit` option only truncates the returned summaries and does not
217
- * reduce the scan. Callers that poll this method frequently should
218
- * account for the total retained data when choosing a TTL and polling
219
- * interval.
220
- *
221
- * @param options Options for the query.
222
- * @returns An array of trace summaries.
223
- */
224
- async getRecentTraces(options) {
225
- const aggregates = /* @__PURE__ */ new Map();
226
- const traceIdIndex = this.#keyPrefix.length;
227
- for await (const entry of this.#kv.list(this.#keyPrefix)) {
228
- const traceId = entry.key[traceIdIndex];
229
- if (traceId == null || traceId === "_summaries") continue;
230
- const record = entry.value;
231
- if (record == null || typeof record.timestamp !== "string") continue;
232
- const aggregate = aggregates.get(traceId);
233
- if (aggregate == null) aggregates.set(traceId, {
234
- timestamp: record.timestamp,
235
- activityCount: 1,
236
- activityTypes: [record.activityType]
237
- });
238
- else {
239
- aggregate.activityCount++;
240
- if (record.timestamp < aggregate.timestamp) aggregate.timestamp = record.timestamp;
241
- if (!aggregate.activityTypes.includes(record.activityType)) aggregate.activityTypes.push(record.activityType);
242
- }
243
- }
244
- const summaries = [...aggregates].map(([traceId, aggregate]) => ({
245
- traceId,
246
- ...aggregate
247
- }));
248
- summaries.sort((a, b) => b.timestamp.localeCompare(a.timestamp));
249
- if (options?.limit != null) return summaries.slice(0, options.limit);
250
- return summaries;
251
- }
252
- /**
253
- * Forces the exporter to flush any buffered data.
254
- * This is a no-op because we write directly to the KvStore without buffering.
255
- */
256
- async forceFlush() {}
257
- /**
258
- * Shuts down the exporter.
259
- */
260
- async shutdown() {}
261
- };
262
- //#endregion
263
- export { FedifySpanExporter as t };
@@ -1,2 +0,0 @@
1
- import { Temporal } from "temporal-polyfill";
2
- import { URLPattern } from "urlpattern-polyfill";
@@ -1,130 +0,0 @@
1
- import "temporal-polyfill";
2
- import "urlpattern-polyfill";
3
- globalThis.addEventListener = () => {};
4
- import { n as isPubliclyAddressedNode, t as isInAudience } from "../audience-CHQ-FlLD.mjs";
5
- import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
6
- import "../std__assert-DvMDRPes.mjs";
7
- import { Note, PUBLIC_COLLECTION, Person } from "@fedify/vocab";
8
- import { parseIri, toCompatibleEf61Id } from "@fedify/vocab-runtime";
9
- import { mockDocumentLoader, test } from "@fedify/fixture";
10
- import jsonld from "@fedify/vocab-runtime/jsonld";
11
- //#region src/federation/audience.test.ts
12
- const did = "did:key:z6MkrJVnaZkeFzdQyMZu1cgjg7k1pZZ6pvBQ7XJPt4swbTQ2";
13
- async function expand(document) {
14
- const [node] = await jsonld.expand({
15
- "@context": "https://www.w3.org/ns/activitystreams",
16
- id: "https://example.com/notes/1",
17
- type: "Note",
18
- ...document
19
- }, { documentLoader: mockDocumentLoader });
20
- return node;
21
- }
22
- test("isPubliclyAddressedNode()", async (t) => {
23
- for (const property of [
24
- "to",
25
- "cc",
26
- "bto",
27
- "bcc",
28
- "audience"
29
- ]) for (const value of [
30
- PUBLIC_COLLECTION.href,
31
- "as:Public",
32
- "Public",
33
- ["https://example.com/person", "as:Public"]
34
- ]) await t.step(`${JSON.stringify(value)} in ${property}`, async () => {
35
- assertEquals(isPubliclyAddressedNode(await expand({ [property]: value })), true);
36
- });
37
- await t.step("not addressed", async () => {
38
- assertEquals(isPubliclyAddressedNode(await expand({})), false);
39
- });
40
- await t.step("addressed to other recipients", async () => {
41
- assertEquals(isPubliclyAddressedNode(await expand({
42
- to: "https://example.com/person",
43
- cc: "https://example.com/person/followers"
44
- })), false);
45
- });
46
- await t.step("Public in other properties", async () => {
47
- assertEquals(isPubliclyAddressedNode(await expand({ tag: PUBLIC_COLLECTION.href })), false);
48
- });
49
- await t.step("a Public literal rather than an ID", async () => {
50
- assertEquals(isPubliclyAddressedNode(await expand({ to: { "@value": PUBLIC_COLLECTION.href } })), false);
51
- });
52
- await t.step("Public that the context maps elsewhere", async () => {
53
- for (const [context, to] of [[{ as: "https://example.com/ns#" }, "as:Public"], [{ "@base": "https://example.com/" }, "Public"]]) {
54
- const [node] = await jsonld.expand({
55
- "@context": ["https://www.w3.org/ns/activitystreams", context],
56
- id: "https://example.com/notes/1",
57
- type: "Note",
58
- to
59
- }, { documentLoader: mockDocumentLoader });
60
- assertEquals(isPubliclyAddressedNode(node), false, JSON.stringify(context));
61
- }
62
- });
63
- await t.step("only the node itself is checked", async () => {
64
- assertEquals(isPubliclyAddressedNode(await expand({
65
- type: "Create",
66
- actor: "https://example.com/person",
67
- object: {
68
- type: "Note",
69
- id: "https://example.com/notes/2",
70
- to: PUBLIC_COLLECTION.href
71
- }
72
- })), false);
73
- });
74
- });
75
- test("isInAudience()", async (t) => {
76
- const person = new Person({ id: new URL("https://example.com/person") });
77
- const portableId = parseIri(`ap+ef61://${did}/actor`);
78
- const portable = new Person({ id: toCompatibleEf61Id(portableId, "https://other.example") });
79
- const followers = new URL("https://example.com/person2/followers");
80
- await t.step("publicly addressed", async () => {
81
- for (const actor of [null, person]) assertEquals(await isInAudience(new Note({ cc: PUBLIC_COLLECTION }), actor), true);
82
- });
83
- await t.step("no actor", async () => {
84
- assertEquals(await isInAudience(new Note({ to: person.id }), null), false);
85
- assertEquals(await isInAudience(new Note({}), null), false);
86
- });
87
- await t.step("directly addressed", async () => {
88
- for (const property of [
89
- "to",
90
- "cc",
91
- "bto",
92
- "bcc",
93
- "audience"
94
- ]) assertEquals(await isInAudience(new Note({ [property]: person.id }), person), true, property);
95
- });
96
- await t.step("not addressed", async () => {
97
- assertEquals(await isInAudience(new Note({ to: new URL("https://example.com/other") }), person), false);
98
- assertEquals(await isInAudience(new Note({ to: person.id }), new Person({})), false);
99
- });
100
- await t.step("portable IDs are compared canonically", async () => {
101
- for (const addressee of [
102
- portableId,
103
- parseIri(`ap://${did}/actor`),
104
- parseIri(`ap+ef61://${did.replaceAll(":", "%3A")}/actor`),
105
- toCompatibleEf61Id(portableId, "https://example.com")
106
- ]) assertEquals(await isInAudience(new Note({ to: addressee }), portable), true, addressee.href);
107
- assertEquals(await isInAudience(new Note({ to: parseIri(`ap+ef61://${did}/other`) }), portable), false);
108
- assertEquals(await isInAudience(new Note({ to: new URL(`https://other.example/${did}/actor`) }), portable), false);
109
- });
110
- await t.step("isMember()", async () => {
111
- const calls = [];
112
- const isMember = (addressee, actor) => {
113
- calls.push(`${addressee.href} ${actor.id?.href}`);
114
- return addressee.href === followers.href;
115
- };
116
- const note = new Note({
117
- to: new URL("https://example.com/other"),
118
- cc: followers
119
- });
120
- assertEquals(await isInAudience(note, person, { isMember }), true);
121
- assertEquals(calls, [`https://example.com/other ${person.id?.href}`, `${followers.href} ${person.id?.href}`]);
122
- calls.length = 0;
123
- assertEquals(await isInAudience(new Note({ to: person.id }), person, { isMember }), true);
124
- assertEquals(await isInAudience(note, null, { isMember }), false);
125
- assertEquals(calls, []);
126
- assertEquals(await isInAudience(note, person, { isMember: () => false }), false);
127
- });
128
- });
129
- //#endregion
130
- export {};
@@ -1,2 +0,0 @@
1
- import { Temporal } from "temporal-polyfill";
2
- import { URLPattern } from "urlpattern-polyfill";