@fedify/fedify 2.0.0-dev.7 → 2.0.0-dev.85

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 (108) hide show
  1. package/dist/{actor-BLBfgCFC.cjs → actor-Bpgsv6Ii.cjs} +185 -185
  2. package/dist/{actor-CT1vyB17.js → actor-D3v8T9kQ.js} +185 -185
  3. package/dist/{actor-B5o1xrFI.js → actor-DrvDW-tK.js} +1 -1
  4. package/dist/{builder-CiifhBKW.js → builder-D2trc6p7.js} +3 -3
  5. package/dist/compat/mod.d.cts +3 -3
  6. package/dist/compat/mod.d.ts +3 -3
  7. package/dist/compat/transformers.test.js +16 -16
  8. package/dist/{context-PxGADCsD.d.cts → context-DBQ7nMCw.d.cts} +1 -1
  9. package/dist/{context-V-XS2_6O.d.ts → context-mM0Nu5yo.d.ts} +1 -1
  10. package/dist/{docloader-DUfba_vD.js → docloader-DlSrn4Io.js} +2 -2
  11. package/dist/{esm-p1rx_7cC.js → esm-DQKBkSAc.js} +1 -1
  12. package/dist/federation/builder.test.js +5 -5
  13. package/dist/federation/collection.test.js +2 -2
  14. package/dist/federation/handler.test.js +18 -18
  15. package/dist/federation/idempotency.test.js +17 -17
  16. package/dist/federation/inbox.test.js +3 -3
  17. package/dist/federation/keycache.test.js +4 -4
  18. package/dist/federation/kv.test.js +57 -3
  19. package/dist/federation/middleware.test.js +18 -18
  20. package/dist/federation/mod.cjs +8 -8
  21. package/dist/federation/mod.d.cts +3 -3
  22. package/dist/federation/mod.d.ts +3 -3
  23. package/dist/federation/mod.js +8 -8
  24. package/dist/federation/mq.test.js +2 -2
  25. package/dist/federation/negotiation.test.js +2 -2
  26. package/dist/federation/retry.test.js +2 -2
  27. package/dist/federation/router.test.js +2 -2
  28. package/dist/federation/send.test.js +10 -10
  29. package/dist/{federation-CRpdnOMS.cjs → federation-CoW-KDKv.cjs} +22 -0
  30. package/dist/{federation-jcR8-ZxP.js → federation-D0hkM4T7.js} +22 -0
  31. package/dist/{http-pgzDkXD0.js → http-BNxhNjYm.js} +2 -2
  32. package/dist/{http-C78SwacJ.js → http-Bz4YpW-D.js} +2 -2
  33. package/dist/{http-ClCl_dis.cjs → http-Dr7V4DY7.cjs} +2 -2
  34. package/dist/{inbox-BDF2VbZ8.js → inbox-CXOoDyEH.js} +1 -1
  35. package/dist/{key-jo5CucF6.js → key-C_b1t1Na.js} +2 -2
  36. package/dist/{keycache-C5k5PTyM.js → keycache-zfG6F1PW.js} +1 -1
  37. package/dist/{keys-BSzUEVJu.js → keys-C01rMN22.js} +1 -1
  38. package/dist/{kv-BKNZ-Tb-.d.ts → kv-BpJND1Hr.d.ts} +30 -1
  39. package/dist/{kv-CRZrzyXm.js → kv-QzKcOQgP.js} +22 -0
  40. package/dist/{kv-Bxr0Q87_.d.cts → kv-cD_d4hg-.d.cts} +30 -1
  41. package/dist/{kv-cache-ONwNlGJb.js → kv-cache-4I_O-pli.js} +1 -1
  42. package/dist/{kv-cache-DVMGXeBd.cjs → kv-cache-CpjdzlKh.cjs} +1 -1
  43. package/dist/{kv-cache-DN9pfMBe.js → kv-cache-D7LFlByV.js} +13 -0
  44. package/dist/{ld-CWuhgMM4.js → ld-Ba0jIf7k.js} +2 -2
  45. package/dist/{lookup-BvK_-Lja.js → lookup-BUqdDUac.js} +6 -6
  46. package/dist/{lookup-DdOtSFct.cjs → lookup-UA4SKewV.cjs} +6 -6
  47. package/dist/{lookup-Dvhilldd.js → lookup-kl47RWf3.js} +190 -190
  48. package/dist/middleware-B64_UxVQ.js +26 -0
  49. package/dist/middleware-BK7fptEJ.cjs +15 -0
  50. package/dist/{middleware-8uNpzeWq.cjs → middleware-BYqpBCFp.cjs} +7 -7
  51. package/dist/{middleware-C7m5m72k.js → middleware-CwpDL0KB.js} +12 -12
  52. package/dist/{middleware-DMZO9M2Z.js → middleware-Cx0KwuzQ.js} +7 -7
  53. package/dist/middleware-_DVIaAFk.js +15 -0
  54. package/dist/{mod-aAE2wOWV.d.ts → mod-CAdoBu0x.d.ts} +1 -1
  55. package/dist/{mod-BoRKfJPE.d.cts → mod-Dy2fJtmN.d.cts} +1 -1
  56. package/dist/{mod-Cdo6SYlJ.d.ts → mod-GetHzY6F.d.ts} +1 -1
  57. package/dist/{mod-DMpuiKXi.d.cts → mod-fxr25Gv7.d.cts} +1 -1
  58. package/dist/mod.cjs +8 -8
  59. package/dist/mod.d.cts +5 -5
  60. package/dist/mod.d.ts +5 -5
  61. package/dist/mod.js +8 -8
  62. package/dist/nodeinfo/client.test.js +3 -3
  63. package/dist/nodeinfo/handler.test.js +16 -16
  64. package/dist/nodeinfo/types.test.js +2 -2
  65. package/dist/otel/exporter.test.d.ts +3 -0
  66. package/dist/otel/exporter.test.js +900 -0
  67. package/dist/otel/mod.cjs +262 -0
  68. package/dist/otel/mod.d.cts +230 -0
  69. package/dist/otel/mod.d.ts +232 -0
  70. package/dist/otel/mod.js +261 -0
  71. package/dist/{otel-1BmGPuZc.js → otel-Bfe_BgOV.js} +1 -2
  72. package/dist/{owner-_G6LyiEi.js → owner-CgznkTZ6.js} +2 -2
  73. package/dist/{proof-CZ_Wlbae.cjs → proof-AEFUz3SS.cjs} +3 -3
  74. package/dist/{proof-BqpNTnd4.js → proof-BrsOl9bB.js} +3 -3
  75. package/dist/{proof-BkMSGqJy.js → proof-rFeNfcVE.js} +2 -2
  76. package/dist/{send-BCzFH66x.js → send-w_IyjZ0S.js} +2 -2
  77. package/dist/sig/http.test.js +7 -7
  78. package/dist/sig/key.test.js +5 -5
  79. package/dist/sig/ld.test.js +6 -6
  80. package/dist/sig/mod.cjs +4 -4
  81. package/dist/sig/mod.js +4 -4
  82. package/dist/sig/owner.test.js +7 -7
  83. package/dist/sig/proof.test.js +6 -6
  84. package/dist/testing/docloader.test.js +2 -2
  85. package/dist/testing/mod.js +2 -2
  86. package/dist/{testing-cwlO8Sns.js → testing-fIO3Z258.js} +1 -1
  87. package/dist/utils/docloader.test.js +8 -8
  88. package/dist/utils/kv-cache.test.js +6 -3
  89. package/dist/utils/mod.cjs +4 -4
  90. package/dist/utils/mod.d.cts +2 -2
  91. package/dist/utils/mod.d.ts +2 -2
  92. package/dist/utils/mod.js +4 -4
  93. package/dist/vocab/actor.test.js +4 -4
  94. package/dist/vocab/lookup.test.js +4 -4
  95. package/dist/vocab/mod.cjs +3 -3
  96. package/dist/vocab/mod.js +3 -3
  97. package/dist/vocab/type.test.js +2 -2
  98. package/dist/vocab/vocab.test.js +157 -157
  99. package/dist/{vocab-BXz9NayY.js → vocab-BtqMcZvq.js} +2 -2
  100. package/dist/{vocab-_gvYdHDB.cjs → vocab-COVHviQ5.cjs} +2 -2
  101. package/dist/webfinger/handler.test.js +16 -16
  102. package/dist/webfinger/lookup.test.js +3 -3
  103. package/dist/webfinger/mod.cjs +1 -1
  104. package/dist/webfinger/mod.js +1 -1
  105. package/package.json +19 -11
  106. package/dist/middleware-BCFCgNNb.js +0 -26
  107. package/dist/middleware-BDTi2tq7.cjs +0 -15
  108. package/dist/middleware-NNEe-eQ5.js +0 -15
@@ -0,0 +1,232 @@
1
+ import { Temporal } from "@js-temporal/polyfill";
2
+ import { URLPattern } from "urlpattern-polyfill";
3
+ import { KvKey, KvStore } from "../kv-BpJND1Hr.js";
4
+ import { ExportResultCode } from "@opentelemetry/core";
5
+ import { ReadableSpan, SpanExporter } from "@opentelemetry/sdk-trace-base";
6
+
7
+ //#region src/otel/exporter.d.ts
8
+ /**
9
+ * The direction of an activity in the trace.
10
+ *
11
+ * @since 1.10.0
12
+ */
13
+ type ActivityDirection = "inbound" | "outbound";
14
+ /**
15
+ * Signature verification details for an inbound activity.
16
+ *
17
+ * @since 1.10.0
18
+ */
19
+ interface SignatureVerificationDetails {
20
+ /**
21
+ * Whether HTTP Signatures were verified.
22
+ */
23
+ httpSignaturesVerified: boolean;
24
+ /**
25
+ * The key ID used for HTTP signature verification, if available.
26
+ */
27
+ httpSignaturesKeyId?: string;
28
+ /**
29
+ * Whether Linked Data Signatures were verified.
30
+ */
31
+ ldSignaturesVerified: boolean;
32
+ }
33
+ /**
34
+ * A record of an activity captured from a trace span.
35
+ * This interface stores the activity data along with trace context
36
+ * for distributed tracing support.
37
+ *
38
+ * @since 1.10.0
39
+ */
40
+ interface TraceActivityRecord {
41
+ /**
42
+ * The trace ID from OpenTelemetry.
43
+ */
44
+ traceId: string;
45
+ /**
46
+ * The span ID from OpenTelemetry.
47
+ */
48
+ spanId: string;
49
+ /**
50
+ * The parent span ID, if any.
51
+ */
52
+ parentSpanId?: string;
53
+ /**
54
+ * Whether this is an inbound or outbound activity.
55
+ */
56
+ direction: ActivityDirection;
57
+ /**
58
+ * The ActivityPub activity type (e.g., "Create", "Follow", "Like").
59
+ */
60
+ activityType: string;
61
+ /**
62
+ * The activity's ID URL, if present.
63
+ */
64
+ activityId?: string;
65
+ /**
66
+ * The actor ID URL (sender of the activity).
67
+ */
68
+ actorId?: string;
69
+ /**
70
+ * The full JSON representation of the activity.
71
+ */
72
+ activityJson: string;
73
+ /**
74
+ * Whether the activity was verified (for inbound activities).
75
+ */
76
+ verified?: boolean;
77
+ /**
78
+ * Detailed signature verification information (for inbound activities).
79
+ */
80
+ signatureDetails?: SignatureVerificationDetails;
81
+ /**
82
+ * The timestamp when this record was created (ISO 8601 format).
83
+ */
84
+ timestamp: string;
85
+ /**
86
+ * The target inbox URL (for outbound activities).
87
+ */
88
+ inboxUrl?: string;
89
+ }
90
+ /**
91
+ * Summary information about a trace.
92
+ *
93
+ * @since 1.10.0
94
+ */
95
+ interface TraceSummary {
96
+ /**
97
+ * The trace ID.
98
+ */
99
+ traceId: string;
100
+ /**
101
+ * The timestamp of the first activity in the trace.
102
+ */
103
+ timestamp: string;
104
+ /**
105
+ * The number of activities in the trace.
106
+ */
107
+ activityCount: number;
108
+ /**
109
+ * Activity types present in this trace.
110
+ */
111
+ activityTypes: string[];
112
+ }
113
+ /**
114
+ * Options for configuring the {@link FedifySpanExporter}.
115
+ *
116
+ * @since 1.10.0
117
+ */
118
+ interface FedifySpanExporterOptions {
119
+ /**
120
+ * The time-to-live for stored trace data.
121
+ * If not specified, data will be stored indefinitely
122
+ * (or until manually deleted).
123
+ */
124
+ ttl?: Temporal.Duration;
125
+ /**
126
+ * The key prefix for storing trace data in the KvStore.
127
+ * Defaults to `["fedify", "traces"]`.
128
+ */
129
+ keyPrefix?: KvKey;
130
+ }
131
+ /**
132
+ * Options for the {@link FedifySpanExporter.getRecentTraces} method.
133
+ *
134
+ * @since 1.10.0
135
+ */
136
+ interface GetRecentTracesOptions {
137
+ /**
138
+ * Maximum number of traces to return.
139
+ * If not specified, returns all available traces.
140
+ */
141
+ limit?: number;
142
+ }
143
+ /**
144
+ * A SpanExporter that persists ActivityPub activity traces to a
145
+ * {@link KvStore}. This enables distributed tracing across multiple
146
+ * nodes in a Fedify deployment.
147
+ *
148
+ * The exporter captures activity data from OpenTelemetry span events
149
+ * (`activitypub.activity.received` and `activitypub.activity.sent`)
150
+ * and stores them in the KvStore with trace context preserved.
151
+ *
152
+ * @example Basic usage with MemoryKvStore
153
+ * ```typescript ignore
154
+ * import { MemoryKvStore } from "@fedify/fedify";
155
+ * import { FedifySpanExporter } from "@fedify/fedify/otel";
156
+ * import {
157
+ * BasicTracerProvider,
158
+ * SimpleSpanProcessor,
159
+ * } from "@opentelemetry/sdk-trace-base";
160
+ *
161
+ * const kv = new MemoryKvStore();
162
+ * const exporter = new FedifySpanExporter(kv, {
163
+ * ttl: Temporal.Duration.from({ hours: 1 }),
164
+ * });
165
+ *
166
+ * const provider = new BasicTracerProvider({
167
+ * spanProcessors: [new SimpleSpanProcessor(exporter)],
168
+ * });
169
+ * ```
170
+ *
171
+ * @example Querying stored traces
172
+ * ```typescript ignore
173
+ * import { MemoryKvStore } from "@fedify/fedify";
174
+ * import { FedifySpanExporter } from "@fedify/fedify/otel";
175
+ *
176
+ * const kv = new MemoryKvStore();
177
+ * const exporter = new FedifySpanExporter(kv);
178
+ * const traceId = "abc123";
179
+ *
180
+ * // Get all activities for a specific trace
181
+ * const activities = await exporter.getActivitiesByTraceId(traceId);
182
+ *
183
+ * // Get recent traces
184
+ * const recentTraces = await exporter.getRecentTraces({ limit: 100 });
185
+ * ```
186
+ *
187
+ * @since 1.10.0
188
+ */
189
+ declare class FedifySpanExporter implements SpanExporter {
190
+ #private;
191
+ /**
192
+ * Creates a new FedifySpanExporter.
193
+ *
194
+ * @param kv The KvStore to persist trace data to.
195
+ * @param options Configuration options.
196
+ */
197
+ constructor(kv: KvStore, options?: FedifySpanExporterOptions);
198
+ /**
199
+ * Exports spans to the KvStore.
200
+ *
201
+ * @param spans The spans to export.
202
+ * @param resultCallback Callback to invoke with the export result.
203
+ */
204
+ export(spans: ReadableSpan[], resultCallback: (result: {
205
+ code: ExportResultCode;
206
+ }) => void): void;
207
+ /**
208
+ * Gets all activity records for a specific trace ID.
209
+ *
210
+ * @param traceId The trace ID to query.
211
+ * @returns An array of activity records belonging to the trace.
212
+ */
213
+ getActivitiesByTraceId(traceId: string): Promise<TraceActivityRecord[]>;
214
+ /**
215
+ * Gets recent traces with summary information.
216
+ *
217
+ * @param options Options for the query.
218
+ * @returns An array of trace summaries.
219
+ */
220
+ getRecentTraces(options?: GetRecentTracesOptions): Promise<TraceSummary[]>;
221
+ /**
222
+ * Forces the exporter to flush any buffered data.
223
+ * This is a no-op because we write directly to the KvStore without buffering.
224
+ */
225
+ forceFlush(): Promise<void>;
226
+ /**
227
+ * Shuts down the exporter.
228
+ */
229
+ shutdown(): Promise<void>;
230
+ }
231
+ //#endregion
232
+ export { ActivityDirection, FedifySpanExporter, FedifySpanExporterOptions, GetRecentTracesOptions, SignatureVerificationDetails, TraceActivityRecord, TraceSummary };
@@ -0,0 +1,261 @@
1
+
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+
5
+ import { getLogger } from "@logtape/logtape";
6
+ import { ExportResultCode } from "@opentelemetry/core";
7
+
8
+ //#region src/otel/exporter.ts
9
+ /**
10
+ * A SpanExporter that persists ActivityPub activity traces to a
11
+ * {@link KvStore}. This enables distributed tracing across multiple
12
+ * nodes in a Fedify deployment.
13
+ *
14
+ * The exporter captures activity data from OpenTelemetry span events
15
+ * (`activitypub.activity.received` and `activitypub.activity.sent`)
16
+ * and stores them in the KvStore with trace context preserved.
17
+ *
18
+ * @example Basic usage with MemoryKvStore
19
+ * ```typescript ignore
20
+ * import { MemoryKvStore } from "@fedify/fedify";
21
+ * import { FedifySpanExporter } from "@fedify/fedify/otel";
22
+ * import {
23
+ * BasicTracerProvider,
24
+ * SimpleSpanProcessor,
25
+ * } from "@opentelemetry/sdk-trace-base";
26
+ *
27
+ * const kv = new MemoryKvStore();
28
+ * const exporter = new FedifySpanExporter(kv, {
29
+ * ttl: Temporal.Duration.from({ hours: 1 }),
30
+ * });
31
+ *
32
+ * const provider = new BasicTracerProvider({
33
+ * spanProcessors: [new SimpleSpanProcessor(exporter)],
34
+ * });
35
+ * ```
36
+ *
37
+ * @example Querying stored traces
38
+ * ```typescript ignore
39
+ * import { MemoryKvStore } from "@fedify/fedify";
40
+ * import { FedifySpanExporter } from "@fedify/fedify/otel";
41
+ *
42
+ * const kv = new MemoryKvStore();
43
+ * const exporter = new FedifySpanExporter(kv);
44
+ * const traceId = "abc123";
45
+ *
46
+ * // Get all activities for a specific trace
47
+ * const activities = await exporter.getActivitiesByTraceId(traceId);
48
+ *
49
+ * // Get recent traces
50
+ * const recentTraces = await exporter.getRecentTraces({ limit: 100 });
51
+ * ```
52
+ *
53
+ * @since 1.10.0
54
+ */
55
+ var FedifySpanExporter = class {
56
+ #kv;
57
+ #ttl;
58
+ #keyPrefix;
59
+ /**
60
+ * Creates a new FedifySpanExporter.
61
+ *
62
+ * @param kv The KvStore to persist trace data to.
63
+ * @param options Configuration options.
64
+ */
65
+ constructor(kv, options) {
66
+ this.#kv = kv;
67
+ this.#ttl = options?.ttl;
68
+ this.#keyPrefix = options?.keyPrefix ?? ["fedify", "traces"];
69
+ }
70
+ /**
71
+ * Exports spans to the KvStore.
72
+ *
73
+ * @param spans The spans to export.
74
+ * @param resultCallback Callback to invoke with the export result.
75
+ */
76
+ export(spans, resultCallback) {
77
+ this.#exportAsync(spans).then(() => resultCallback({ code: ExportResultCode.SUCCESS })).catch((error) => {
78
+ getLogger([
79
+ "fedify",
80
+ "otel",
81
+ "exporter"
82
+ ]).error("Failed to export spans to KvStore: {error}", { error });
83
+ resultCallback({ code: ExportResultCode.FAILED });
84
+ });
85
+ }
86
+ async #exportAsync(spans) {
87
+ const storeOperations = [];
88
+ for (const span of spans) {
89
+ const records = this.#extractRecords(span);
90
+ for (const record of records) storeOperations.push(this.#storeRecord(record));
91
+ }
92
+ const results = await Promise.allSettled(storeOperations);
93
+ const rejected = results.filter((r) => r.status === "rejected");
94
+ if (rejected.length > 0) throw new AggregateError(rejected.map((r) => r.reason), "Failed to store one or more trace activity records.");
95
+ }
96
+ #extractRecords(span) {
97
+ const records = [];
98
+ const spanContext = span.spanContext();
99
+ const traceId = spanContext.traceId;
100
+ const spanId = spanContext.spanId;
101
+ const parentSpanId = span.parentSpanContext?.spanId;
102
+ for (const event of span.events) if (event.name === "activitypub.activity.received") {
103
+ const record = this.#extractInboundRecord(event, traceId, spanId, parentSpanId);
104
+ if (record != null) records.push(record);
105
+ } else if (event.name === "activitypub.activity.sent") {
106
+ const record = this.#extractOutboundRecord(event, traceId, spanId, parentSpanId);
107
+ if (record != null) records.push(record);
108
+ }
109
+ return records;
110
+ }
111
+ #extractInboundRecord(event, traceId, spanId, parentSpanId) {
112
+ const attrs = event.attributes;
113
+ if (attrs == null) return null;
114
+ const activityJson = attrs["activitypub.activity.json"];
115
+ if (typeof activityJson !== "string") return null;
116
+ let activityType = "Unknown";
117
+ let activityId;
118
+ let actorId;
119
+ try {
120
+ const activity = JSON.parse(activityJson);
121
+ activityType = activity.type ?? "Unknown";
122
+ activityId = activity.id;
123
+ if (typeof activity.actor === "string") actorId = activity.actor;
124
+ else if (activity.actor != null && typeof activity.actor.id === "string") actorId = activity.actor.id;
125
+ } catch {}
126
+ const verified = attrs["activitypub.activity.verified"];
127
+ const httpSigVerified = attrs["http_signatures.verified"];
128
+ const httpSigKeyId = attrs["http_signatures.key_id"];
129
+ const ldSigVerified = attrs["ld_signatures.verified"];
130
+ let signatureDetails;
131
+ if (typeof httpSigVerified === "boolean" || typeof ldSigVerified === "boolean") signatureDetails = {
132
+ httpSignaturesVerified: httpSigVerified === true,
133
+ httpSignaturesKeyId: typeof httpSigKeyId === "string" && httpSigKeyId !== "" ? httpSigKeyId : void 0,
134
+ ldSignaturesVerified: ldSigVerified === true
135
+ };
136
+ return {
137
+ traceId,
138
+ spanId,
139
+ parentSpanId,
140
+ direction: "inbound",
141
+ activityType,
142
+ activityId,
143
+ actorId,
144
+ activityJson,
145
+ verified: typeof verified === "boolean" ? verified : void 0,
146
+ signatureDetails,
147
+ timestamp: (/* @__PURE__ */ new Date(event.time[0] * 1e3 + event.time[1] / 1e6)).toISOString()
148
+ };
149
+ }
150
+ #extractOutboundRecord(event, traceId, spanId, parentSpanId) {
151
+ const attrs = event.attributes;
152
+ if (attrs == null) return null;
153
+ const activityJson = attrs["activitypub.activity.json"];
154
+ if (typeof activityJson !== "string") return null;
155
+ let activityType = "Unknown";
156
+ let activityId;
157
+ let actorId;
158
+ try {
159
+ const activity = JSON.parse(activityJson);
160
+ activityType = activity.type ?? "Unknown";
161
+ activityId = activity.id;
162
+ if (typeof activity.actor === "string") actorId = activity.actor;
163
+ else if (activity.actor != null && typeof activity.actor.id === "string") actorId = activity.actor.id;
164
+ } catch {}
165
+ const inboxUrl = attrs["activitypub.inbox.url"];
166
+ const explicitActivityId = attrs["activitypub.activity.id"];
167
+ return {
168
+ traceId,
169
+ spanId,
170
+ parentSpanId,
171
+ direction: "outbound",
172
+ activityType,
173
+ activityId: activityId ?? (typeof explicitActivityId === "string" && explicitActivityId !== "" ? explicitActivityId : void 0),
174
+ actorId,
175
+ activityJson,
176
+ timestamp: (/* @__PURE__ */ new Date(event.time[0] * 1e3 + event.time[1] / 1e6)).toISOString(),
177
+ inboxUrl: typeof inboxUrl === "string" ? inboxUrl : void 0
178
+ };
179
+ }
180
+ async #storeRecord(record) {
181
+ const options = this.#ttl != null ? { ttl: this.#ttl } : void 0;
182
+ const key = [
183
+ ...this.#keyPrefix,
184
+ record.traceId,
185
+ record.spanId
186
+ ];
187
+ await this.#kv.set(key, record, options);
188
+ await this.#updateTraceSummary(record, options);
189
+ }
190
+ async #setWithCasRetry(key, transform, options) {
191
+ if (this.#kv.cas != null) for (let attempt = 0; attempt < 3; attempt++) {
192
+ const existing$1 = await this.#kv.get(key);
193
+ const newValue$1 = transform(existing$1);
194
+ if (await this.#kv.cas(key, existing$1, newValue$1, options)) return;
195
+ }
196
+ const existing = await this.#kv.get(key);
197
+ const newValue = transform(existing);
198
+ await this.#kv.set(key, newValue, options);
199
+ }
200
+ async #updateTraceSummary(record, options) {
201
+ const summaryKey = [
202
+ ...this.#keyPrefix,
203
+ "_summaries",
204
+ record.traceId
205
+ ];
206
+ await this.#setWithCasRetry(summaryKey, (existing) => {
207
+ const summary = existing != null ? {
208
+ traceId: existing.traceId,
209
+ timestamp: existing.timestamp,
210
+ activityCount: existing.activityCount,
211
+ activityTypes: [...existing.activityTypes]
212
+ } : {
213
+ traceId: record.traceId,
214
+ timestamp: record.timestamp,
215
+ activityCount: 0,
216
+ activityTypes: []
217
+ };
218
+ summary.activityCount += 1;
219
+ if (!summary.activityTypes.includes(record.activityType)) summary.activityTypes.push(record.activityType);
220
+ return summary;
221
+ }, options);
222
+ }
223
+ /**
224
+ * Gets all activity records for a specific trace ID.
225
+ *
226
+ * @param traceId The trace ID to query.
227
+ * @returns An array of activity records belonging to the trace.
228
+ */
229
+ async getActivitiesByTraceId(traceId) {
230
+ const prefix = [...this.#keyPrefix, traceId];
231
+ const records = [];
232
+ for await (const entry of this.#kv.list(prefix)) records.push(entry.value);
233
+ return records;
234
+ }
235
+ /**
236
+ * Gets recent traces with summary information.
237
+ *
238
+ * @param options Options for the query.
239
+ * @returns An array of trace summaries.
240
+ */
241
+ async getRecentTraces(options) {
242
+ const summaryPrefix = [...this.#keyPrefix, "_summaries"];
243
+ const summaries = [];
244
+ for await (const entry of this.#kv.list(summaryPrefix)) summaries.push(entry.value);
245
+ summaries.sort((a, b) => b.timestamp.localeCompare(a.timestamp));
246
+ if (options?.limit != null) return summaries.slice(0, options.limit);
247
+ return summaries;
248
+ }
249
+ /**
250
+ * Forces the exporter to flush any buffered data.
251
+ * This is a no-op because we write directly to the KvStore without buffering.
252
+ */
253
+ async forceFlush() {}
254
+ /**
255
+ * Shuts down the exporter.
256
+ */
257
+ async shutdown() {}
258
+ };
259
+
260
+ //#endregion
261
+ export { FedifySpanExporter };
@@ -55,8 +55,7 @@ var TestSpanExporter = class {
55
55
  */
56
56
  function createTestTracerProvider() {
57
57
  const exporter = new TestSpanExporter();
58
- const provider = new BasicTracerProvider();
59
- provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
58
+ const provider = new BasicTracerProvider({ spanProcessors: [new SimpleSpanProcessor(exporter)] });
60
59
  return [provider, exporter];
61
60
  }
62
61
 
@@ -3,8 +3,8 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { CryptographicKey, Object as Object$1, deno_default } from "./lookup-Dvhilldd.js";
7
- import { isActor } from "./actor-B5o1xrFI.js";
6
+ import { CryptographicKey, Object as Object$1, deno_default } from "./lookup-kl47RWf3.js";
7
+ import { isActor } from "./actor-DrvDW-tK.js";
8
8
  import { getDocumentLoader } from "@fedify/vocab-runtime";
9
9
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
10
10
 
@@ -3,9 +3,9 @@
3
3
  const { URLPattern } = require("urlpattern-polyfill");
4
4
 
5
5
  const require_chunk = require('./chunk-DqRYRqnO.cjs');
6
- const require_lookup = require('./lookup-DdOtSFct.cjs');
7
- const require_actor = require('./actor-BLBfgCFC.cjs');
8
- const require_http = require('./http-ClCl_dis.cjs');
6
+ const require_lookup = require('./lookup-UA4SKewV.cjs');
7
+ const require_actor = require('./actor-Bpgsv6Ii.cjs');
8
+ const require_http = require('./http-Dr7V4DY7.cjs');
9
9
  const __logtape_logtape = require_chunk.__toESM(require("@logtape/logtape"));
10
10
  const __opentelemetry_api = require_chunk.__toESM(require("@opentelemetry/api"));
11
11
  const jsonld = require_chunk.__toESM(require("jsonld"));
@@ -2,9 +2,9 @@
2
2
  import { Temporal } from "@js-temporal/polyfill";
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
 
5
- import { deno_default } from "./lookup-BvK_-Lja.js";
6
- import { Activity, CryptographicKey, DataIntegrityProof, Multikey, Object as Object$1, getTypeId, isActor } from "./actor-CT1vyB17.js";
7
- import { fetchKey, validateCryptoKey } from "./http-C78SwacJ.js";
5
+ import { deno_default } from "./lookup-BUqdDUac.js";
6
+ import { Activity, CryptographicKey, DataIntegrityProof, Multikey, Object as Object$1, getTypeId, isActor } from "./actor-D3v8T9kQ.js";
7
+ import { fetchKey, validateCryptoKey } from "./http-Bz4YpW-D.js";
8
8
  import { getLogger } from "@logtape/logtape";
9
9
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
10
10
  import jsonld from "jsonld";
@@ -3,8 +3,8 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { Activity, DataIntegrityProof, Multikey, deno_default, getTypeId } from "./lookup-Dvhilldd.js";
7
- import { fetchKey, validateCryptoKey } from "./key-jo5CucF6.js";
6
+ import { Activity, DataIntegrityProof, Multikey, deno_default, getTypeId } from "./lookup-kl47RWf3.js";
7
+ import { fetchKey, validateCryptoKey } from "./key-C_b1t1Na.js";
8
8
  import { getLogger } from "@logtape/logtape";
9
9
  import { SpanStatusCode, trace } from "@opentelemetry/api";
10
10
  import { encodeHex } from "byte-encodings/hex";
@@ -3,8 +3,8 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { deno_default } from "./lookup-Dvhilldd.js";
7
- import { doubleKnock } from "./http-pgzDkXD0.js";
6
+ import { deno_default } from "./lookup-kl47RWf3.js";
7
+ import { doubleKnock } from "./http-BNxhNjYm.js";
8
8
  import { getLogger } from "@logtape/logtape";
9
9
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
10
10
 
@@ -3,20 +3,20 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import "../lookup-Dvhilldd.js";
6
+ import "../lookup-kl47RWf3.js";
7
7
  import { assertEquals } from "../assert_equals-DSbWqCm3.js";
8
8
  import { assert } from "../assert-MZs1qjMx.js";
9
9
  import "../assert_instance_of-DHz7EHNU.js";
10
- import "../actor-B5o1xrFI.js";
11
- import { exportJwk } from "../key-jo5CucF6.js";
12
- import { createRfc9421SignatureBase, doubleKnock, formatRfc9421Signature, formatRfc9421SignatureParameters, parseRfc9421Signature, parseRfc9421SignatureInput, signRequest, timingSafeEqual, verifyRequest } from "../http-pgzDkXD0.js";
13
- import { mockDocumentLoader, test } from "../testing-cwlO8Sns.js";
10
+ import "../actor-DrvDW-tK.js";
11
+ import { exportJwk } from "../key-C_b1t1Na.js";
12
+ import { createRfc9421SignatureBase, doubleKnock, formatRfc9421Signature, formatRfc9421SignatureParameters, parseRfc9421Signature, parseRfc9421SignatureInput, signRequest, timingSafeEqual, verifyRequest } from "../http-BNxhNjYm.js";
13
+ import { mockDocumentLoader, test } from "../testing-fIO3Z258.js";
14
14
  import { assertExists, assertStringIncludes } from "../std__assert-DWivtrGR.js";
15
15
  import { assertFalse, assertRejects } from "../assert_rejects-Ce45JcFg.js";
16
16
  import { assertThrows } from "../assert_throws-BNXdRGWP.js";
17
17
  import "../assert_not_equals-C80BG-_5.js";
18
- import { rsaPrivateKey2, rsaPublicKey1, rsaPublicKey2, rsaPublicKey5 } from "../keys-BSzUEVJu.js";
19
- import { esm_default } from "../esm-p1rx_7cC.js";
18
+ import { rsaPrivateKey2, rsaPublicKey1, rsaPublicKey2, rsaPublicKey5 } from "../keys-C01rMN22.js";
19
+ import { esm_default } from "../esm-DQKBkSAc.js";
20
20
  import { exportSpki } from "@fedify/vocab-runtime";
21
21
  import { encodeBase64 } from "byte-encodings/base64";
22
22
 
@@ -3,18 +3,18 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { CryptographicKey, Multikey } from "../lookup-Dvhilldd.js";
6
+ import { CryptographicKey, Multikey } from "../lookup-kl47RWf3.js";
7
7
  import { assertEquals } from "../assert_equals-DSbWqCm3.js";
8
8
  import "../assert-MZs1qjMx.js";
9
9
  import "../assert_instance_of-DHz7EHNU.js";
10
- import "../actor-B5o1xrFI.js";
11
- import { exportJwk, fetchKey, generateCryptoKeyPair, importJwk, validateCryptoKey } from "../key-jo5CucF6.js";
12
- import { mockDocumentLoader, test } from "../testing-cwlO8Sns.js";
10
+ import "../actor-DrvDW-tK.js";
11
+ import { exportJwk, fetchKey, generateCryptoKeyPair, importJwk, validateCryptoKey } from "../key-C_b1t1Na.js";
12
+ import { mockDocumentLoader, test } from "../testing-fIO3Z258.js";
13
13
  import "../std__assert-DWivtrGR.js";
14
14
  import { assertRejects } from "../assert_rejects-Ce45JcFg.js";
15
15
  import { assertThrows } from "../assert_throws-BNXdRGWP.js";
16
16
  import "../assert_not_equals-C80BG-_5.js";
17
- import { ed25519Multikey, rsaPrivateKey2, rsaPublicKey1, rsaPublicKey2, rsaPublicKey3 } from "../keys-BSzUEVJu.js";
17
+ import { ed25519Multikey, rsaPrivateKey2, rsaPublicKey1, rsaPublicKey2, rsaPublicKey3 } from "../keys-C01rMN22.js";
18
18
 
19
19
  //#region src/sig/key.test.ts
20
20
  test("validateCryptoKey()", async () => {
@@ -3,16 +3,16 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { CryptographicKey } from "../lookup-Dvhilldd.js";
6
+ import { CryptographicKey } from "../lookup-kl47RWf3.js";
7
7
  import { assertEquals } from "../assert_equals-DSbWqCm3.js";
8
8
  import { assert } from "../assert-MZs1qjMx.js";
9
- import "../actor-B5o1xrFI.js";
10
- import { generateCryptoKeyPair } from "../key-jo5CucF6.js";
11
- import { attachSignature, createSignature, detachSignature, signJsonLd, verifyJsonLd, verifySignature } from "../ld-CWuhgMM4.js";
12
- import { mockDocumentLoader, test } from "../testing-cwlO8Sns.js";
9
+ import "../actor-DrvDW-tK.js";
10
+ import { generateCryptoKeyPair } from "../key-C_b1t1Na.js";
11
+ import { attachSignature, createSignature, detachSignature, signJsonLd, verifyJsonLd, verifySignature } from "../ld-Ba0jIf7k.js";
12
+ import { mockDocumentLoader, test } from "../testing-fIO3Z258.js";
13
13
  import { assertFalse, assertRejects } from "../assert_rejects-Ce45JcFg.js";
14
14
  import { assertThrows } from "../assert_throws-BNXdRGWP.js";
15
- import { ed25519Multikey, ed25519PrivateKey, rsaPrivateKey2, rsaPrivateKey3, rsaPublicKey2, rsaPublicKey3 } from "../keys-BSzUEVJu.js";
15
+ import { ed25519Multikey, ed25519PrivateKey, rsaPrivateKey2, rsaPrivateKey3, rsaPublicKey2, rsaPublicKey3 } from "../keys-C01rMN22.js";
16
16
  import { encodeBase64 } from "byte-encodings/base64";
17
17
 
18
18
  //#region src/sig/ld.test.ts
package/dist/sig/mod.cjs CHANGED
@@ -2,10 +2,10 @@
2
2
  const { Temporal } = require("@js-temporal/polyfill");
3
3
  const { URLPattern } = require("urlpattern-polyfill");
4
4
 
5
- require('../lookup-DdOtSFct.cjs');
6
- require('../actor-BLBfgCFC.cjs');
7
- const require_http = require('../http-ClCl_dis.cjs');
8
- const require_proof = require('../proof-CZ_Wlbae.cjs');
5
+ require('../lookup-UA4SKewV.cjs');
6
+ require('../actor-Bpgsv6Ii.cjs');
7
+ const require_http = require('../http-Dr7V4DY7.cjs');
8
+ const require_proof = require('../proof-AEFUz3SS.cjs');
9
9
  require('../sig-YYj5tCnr.cjs');
10
10
 
11
11
  exports.attachSignature = require_proof.attachSignature;
package/dist/sig/mod.js CHANGED
@@ -2,10 +2,10 @@
2
2
  import { Temporal } from "@js-temporal/polyfill";
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
 
5
- import "../lookup-BvK_-Lja.js";
6
- import "../actor-CT1vyB17.js";
7
- import { exportJwk, fetchKey, generateCryptoKeyPair, importJwk, signRequest, verifyRequest } from "../http-C78SwacJ.js";
8
- import { attachSignature, createProof, createSignature, detachSignature, doesActorOwnKey, getKeyOwner, signJsonLd, signObject, verifyJsonLd, verifyObject, verifyProof, verifySignature } from "../proof-BqpNTnd4.js";
5
+ import "../lookup-BUqdDUac.js";
6
+ import "../actor-D3v8T9kQ.js";
7
+ import { exportJwk, fetchKey, generateCryptoKeyPair, importJwk, signRequest, verifyRequest } from "../http-Bz4YpW-D.js";
8
+ import { attachSignature, createProof, createSignature, detachSignature, doesActorOwnKey, getKeyOwner, signJsonLd, signObject, verifyJsonLd, verifyObject, verifyProof, verifySignature } from "../proof-BrsOl9bB.js";
9
9
  import "../sig-C34-oHBl.js";
10
10
 
11
11
  export { attachSignature, createProof, createSignature, detachSignature, doesActorOwnKey, exportJwk, fetchKey, generateCryptoKeyPair, getKeyOwner, importJwk, signJsonLd, signObject, signRequest, verifyJsonLd, verifyObject, verifyProof, verifyRequest, verifySignature };