@fedify/debugger 2.0.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/dist/mod.cjs +969 -0
- package/dist/mod.d.cts +188 -0
- package/dist/mod.d.ts +189 -0
- package/dist/mod.js +945 -0
- package/package.json +54 -0
package/dist/mod.d.cts
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { Federation, KvStore } from "@fedify/fedify/federation";
|
|
2
|
+
import { FedifySpanExporter } from "@fedify/fedify/otel";
|
|
3
|
+
import { Sink } from "@logtape/logtape";
|
|
4
|
+
|
|
5
|
+
//#region src/auth.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Authentication configuration for the debug dashboard.
|
|
9
|
+
*
|
|
10
|
+
* The debug dashboard can be protected using one of three authentication modes:
|
|
11
|
+
*
|
|
12
|
+
* - `"password"` — Shows a password-only login form.
|
|
13
|
+
* - `"usernamePassword"` — Shows a username + password login form.
|
|
14
|
+
* - `"request"` — Authenticates based on the incoming request (e.g., IP
|
|
15
|
+
* address). No login form is shown; unauthenticated requests receive a
|
|
16
|
+
* 403 response.
|
|
17
|
+
*
|
|
18
|
+
* Each mode supports either a static credential check or a callback function.
|
|
19
|
+
*/
|
|
20
|
+
type FederationDebuggerAuth = {
|
|
21
|
+
readonly type: "password";
|
|
22
|
+
authenticate(password: string): boolean | Promise<boolean>;
|
|
23
|
+
} | {
|
|
24
|
+
readonly type: "password";
|
|
25
|
+
readonly password: string;
|
|
26
|
+
} | {
|
|
27
|
+
readonly type: "usernamePassword";
|
|
28
|
+
authenticate(username: string, password: string): boolean | Promise<boolean>;
|
|
29
|
+
} | {
|
|
30
|
+
readonly type: "usernamePassword";
|
|
31
|
+
readonly username: string;
|
|
32
|
+
readonly password: string;
|
|
33
|
+
} | {
|
|
34
|
+
readonly type: "request";
|
|
35
|
+
authenticate(request: Request): boolean | Promise<boolean>;
|
|
36
|
+
};
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/log-store.d.ts
|
|
39
|
+
/**
|
|
40
|
+
* A serialized log record for the debug dashboard.
|
|
41
|
+
*/
|
|
42
|
+
interface SerializedLogRecord {
|
|
43
|
+
/**
|
|
44
|
+
* The logger category.
|
|
45
|
+
*/
|
|
46
|
+
readonly category: readonly string[];
|
|
47
|
+
/**
|
|
48
|
+
* The log level.
|
|
49
|
+
*/
|
|
50
|
+
readonly level: string;
|
|
51
|
+
/**
|
|
52
|
+
* The rendered log message.
|
|
53
|
+
*/
|
|
54
|
+
readonly message: string;
|
|
55
|
+
/**
|
|
56
|
+
* The timestamp in milliseconds since the Unix epoch.
|
|
57
|
+
*/
|
|
58
|
+
readonly timestamp: number;
|
|
59
|
+
/**
|
|
60
|
+
* The extra properties of the log record (excluding traceId and spanId).
|
|
61
|
+
*/
|
|
62
|
+
readonly properties: Record<string, unknown>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Persistent storage for log records grouped by trace ID, backed by a
|
|
66
|
+
* {@link KvStore}. When the same `KvStore` is shared across web and worker
|
|
67
|
+
* processes the dashboard can display logs produced by background tasks.
|
|
68
|
+
*/
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/mod.d.ts
|
|
71
|
+
/**
|
|
72
|
+
* Resets the internal auto-setup state. This is intended **only for tests**
|
|
73
|
+
* that need to exercise the auto-setup code path more than once within the
|
|
74
|
+
* same process.
|
|
75
|
+
*
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
declare function resetAutoSetup(): void;
|
|
79
|
+
/**
|
|
80
|
+
* Options for {@link createFederationDebugger} with an explicit exporter.
|
|
81
|
+
*
|
|
82
|
+
* When `exporter` is provided, the caller is responsible for setting up
|
|
83
|
+
* the OpenTelemetry tracer provider and passing it to `createFederation()`.
|
|
84
|
+
*/
|
|
85
|
+
interface FederationDebuggerOptions {
|
|
86
|
+
/**
|
|
87
|
+
* The path prefix for the debug dashboard. Defaults to `"/__debug__"`.
|
|
88
|
+
*/
|
|
89
|
+
path?: string;
|
|
90
|
+
/**
|
|
91
|
+
* The {@link FedifySpanExporter} to query trace data from.
|
|
92
|
+
*/
|
|
93
|
+
exporter: FedifySpanExporter;
|
|
94
|
+
/**
|
|
95
|
+
* The {@link KvStore} to persist log records to. This should typically be
|
|
96
|
+
* the same `KvStore` instance that was passed to the `FedifySpanExporter`
|
|
97
|
+
* so that logs and traces are co-located and accessible from all processes
|
|
98
|
+
* (e.g., both web and worker nodes).
|
|
99
|
+
*/
|
|
100
|
+
kv: KvStore;
|
|
101
|
+
/**
|
|
102
|
+
* Authentication configuration for the debug dashboard. When omitted,
|
|
103
|
+
* the dashboard is accessible without authentication.
|
|
104
|
+
*/
|
|
105
|
+
auth?: FederationDebuggerAuth;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Options for {@link createFederationDebugger} without an explicit exporter.
|
|
109
|
+
*
|
|
110
|
+
* When `exporter` is omitted, the debugger automatically creates a
|
|
111
|
+
* {@link MemoryKvStore}, {@link FedifySpanExporter},
|
|
112
|
+
* {@link BasicTracerProvider}, and registers it as the global tracer provider
|
|
113
|
+
* so that `createFederation()` picks it up automatically.
|
|
114
|
+
*/
|
|
115
|
+
interface FederationDebuggerSimpleOptions {
|
|
116
|
+
/**
|
|
117
|
+
* The path prefix for the debug dashboard. Defaults to `"/__debug__"`.
|
|
118
|
+
*/
|
|
119
|
+
path?: string;
|
|
120
|
+
/**
|
|
121
|
+
* Authentication configuration for the debug dashboard. When omitted,
|
|
122
|
+
* the dashboard is accessible without authentication.
|
|
123
|
+
*/
|
|
124
|
+
auth?: FederationDebuggerAuth;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Wraps a {@link Federation} object with a debug dashboard.
|
|
128
|
+
*
|
|
129
|
+
* When called without an `exporter`, the debugger automatically sets up
|
|
130
|
+
* OpenTelemetry tracing: it creates a {@link MemoryKvStore},
|
|
131
|
+
* {@link FedifySpanExporter}, and {@link BasicTracerProvider}, then registers
|
|
132
|
+
* it as the global tracer provider. It also auto-configures LogTape to
|
|
133
|
+
* collect logs per trace.
|
|
134
|
+
*
|
|
135
|
+
* @example Simple usage (recommended)
|
|
136
|
+
* ```typescript ignore
|
|
137
|
+
* const innerFederation = createFederation({ kv: new MemoryKvStore() });
|
|
138
|
+
* const federation = createFederationDebugger(innerFederation);
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* @template TContextData The context data type of the federation.
|
|
142
|
+
* @param federation The federation object to wrap.
|
|
143
|
+
* @param options Optional path configuration.
|
|
144
|
+
* @returns A new {@link Federation} object with the debug dashboard attached
|
|
145
|
+
* and a `sink` property for LogTape integration.
|
|
146
|
+
*/
|
|
147
|
+
declare function createFederationDebugger<TContextData>(federation: Federation<TContextData>, options?: FederationDebuggerSimpleOptions): Federation<TContextData> & {
|
|
148
|
+
sink: Sink;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Wraps a {@link Federation} object with a debug dashboard.
|
|
152
|
+
*
|
|
153
|
+
* When called with an `exporter`, the caller is responsible for setting up
|
|
154
|
+
* the OpenTelemetry tracer provider and passing it to `createFederation()`.
|
|
155
|
+
* The returned object includes a `sink` property that should be added to
|
|
156
|
+
* the LogTape configuration to collect logs per trace.
|
|
157
|
+
*
|
|
158
|
+
* @example Advanced usage with explicit exporter
|
|
159
|
+
* ```typescript ignore
|
|
160
|
+
* const kv = new MemoryKvStore();
|
|
161
|
+
* const exporter = new FedifySpanExporter(kv);
|
|
162
|
+
* const tracerProvider = new BasicTracerProvider({
|
|
163
|
+
* spanProcessors: [new SimpleSpanProcessor(exporter)],
|
|
164
|
+
* });
|
|
165
|
+
* const innerFederation = createFederation({ kv, tracerProvider });
|
|
166
|
+
* const federation = createFederationDebugger(innerFederation, {
|
|
167
|
+
* exporter,
|
|
168
|
+
* kv,
|
|
169
|
+
* });
|
|
170
|
+
* await configure({
|
|
171
|
+
* sinks: { debugger: federation.sink },
|
|
172
|
+
* loggers: [
|
|
173
|
+
* { category: "fedify", sinks: ["debugger"] },
|
|
174
|
+
* ],
|
|
175
|
+
* });
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* @template TContextData The context data type of the federation.
|
|
179
|
+
* @param federation The federation object to wrap.
|
|
180
|
+
* @param options Options including the exporter.
|
|
181
|
+
* @returns A new {@link Federation} object with the debug dashboard attached
|
|
182
|
+
* and a `sink` property for LogTape integration.
|
|
183
|
+
*/
|
|
184
|
+
declare function createFederationDebugger<TContextData>(federation: Federation<TContextData>, options: FederationDebuggerOptions): Federation<TContextData> & {
|
|
185
|
+
sink: Sink;
|
|
186
|
+
};
|
|
187
|
+
//#endregion
|
|
188
|
+
export { FederationDebuggerAuth, FederationDebuggerOptions, FederationDebuggerSimpleOptions, SerializedLogRecord, createFederationDebugger, resetAutoSetup };
|
package/dist/mod.d.ts
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
+
import { Federation, KvStore } from "@fedify/fedify/federation";
|
|
3
|
+
import { FedifySpanExporter } from "@fedify/fedify/otel";
|
|
4
|
+
import { Sink } from "@logtape/logtape";
|
|
5
|
+
|
|
6
|
+
//#region src/auth.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Authentication configuration for the debug dashboard.
|
|
10
|
+
*
|
|
11
|
+
* The debug dashboard can be protected using one of three authentication modes:
|
|
12
|
+
*
|
|
13
|
+
* - `"password"` — Shows a password-only login form.
|
|
14
|
+
* - `"usernamePassword"` — Shows a username + password login form.
|
|
15
|
+
* - `"request"` — Authenticates based on the incoming request (e.g., IP
|
|
16
|
+
* address). No login form is shown; unauthenticated requests receive a
|
|
17
|
+
* 403 response.
|
|
18
|
+
*
|
|
19
|
+
* Each mode supports either a static credential check or a callback function.
|
|
20
|
+
*/
|
|
21
|
+
type FederationDebuggerAuth = {
|
|
22
|
+
readonly type: "password";
|
|
23
|
+
authenticate(password: string): boolean | Promise<boolean>;
|
|
24
|
+
} | {
|
|
25
|
+
readonly type: "password";
|
|
26
|
+
readonly password: string;
|
|
27
|
+
} | {
|
|
28
|
+
readonly type: "usernamePassword";
|
|
29
|
+
authenticate(username: string, password: string): boolean | Promise<boolean>;
|
|
30
|
+
} | {
|
|
31
|
+
readonly type: "usernamePassword";
|
|
32
|
+
readonly username: string;
|
|
33
|
+
readonly password: string;
|
|
34
|
+
} | {
|
|
35
|
+
readonly type: "request";
|
|
36
|
+
authenticate(request: Request): boolean | Promise<boolean>;
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/log-store.d.ts
|
|
40
|
+
/**
|
|
41
|
+
* A serialized log record for the debug dashboard.
|
|
42
|
+
*/
|
|
43
|
+
interface SerializedLogRecord {
|
|
44
|
+
/**
|
|
45
|
+
* The logger category.
|
|
46
|
+
*/
|
|
47
|
+
readonly category: readonly string[];
|
|
48
|
+
/**
|
|
49
|
+
* The log level.
|
|
50
|
+
*/
|
|
51
|
+
readonly level: string;
|
|
52
|
+
/**
|
|
53
|
+
* The rendered log message.
|
|
54
|
+
*/
|
|
55
|
+
readonly message: string;
|
|
56
|
+
/**
|
|
57
|
+
* The timestamp in milliseconds since the Unix epoch.
|
|
58
|
+
*/
|
|
59
|
+
readonly timestamp: number;
|
|
60
|
+
/**
|
|
61
|
+
* The extra properties of the log record (excluding traceId and spanId).
|
|
62
|
+
*/
|
|
63
|
+
readonly properties: Record<string, unknown>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Persistent storage for log records grouped by trace ID, backed by a
|
|
67
|
+
* {@link KvStore}. When the same `KvStore` is shared across web and worker
|
|
68
|
+
* processes the dashboard can display logs produced by background tasks.
|
|
69
|
+
*/
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/mod.d.ts
|
|
72
|
+
/**
|
|
73
|
+
* Resets the internal auto-setup state. This is intended **only for tests**
|
|
74
|
+
* that need to exercise the auto-setup code path more than once within the
|
|
75
|
+
* same process.
|
|
76
|
+
*
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
79
|
+
declare function resetAutoSetup(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Options for {@link createFederationDebugger} with an explicit exporter.
|
|
82
|
+
*
|
|
83
|
+
* When `exporter` is provided, the caller is responsible for setting up
|
|
84
|
+
* the OpenTelemetry tracer provider and passing it to `createFederation()`.
|
|
85
|
+
*/
|
|
86
|
+
interface FederationDebuggerOptions {
|
|
87
|
+
/**
|
|
88
|
+
* The path prefix for the debug dashboard. Defaults to `"/__debug__"`.
|
|
89
|
+
*/
|
|
90
|
+
path?: string;
|
|
91
|
+
/**
|
|
92
|
+
* The {@link FedifySpanExporter} to query trace data from.
|
|
93
|
+
*/
|
|
94
|
+
exporter: FedifySpanExporter;
|
|
95
|
+
/**
|
|
96
|
+
* The {@link KvStore} to persist log records to. This should typically be
|
|
97
|
+
* the same `KvStore` instance that was passed to the `FedifySpanExporter`
|
|
98
|
+
* so that logs and traces are co-located and accessible from all processes
|
|
99
|
+
* (e.g., both web and worker nodes).
|
|
100
|
+
*/
|
|
101
|
+
kv: KvStore;
|
|
102
|
+
/**
|
|
103
|
+
* Authentication configuration for the debug dashboard. When omitted,
|
|
104
|
+
* the dashboard is accessible without authentication.
|
|
105
|
+
*/
|
|
106
|
+
auth?: FederationDebuggerAuth;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Options for {@link createFederationDebugger} without an explicit exporter.
|
|
110
|
+
*
|
|
111
|
+
* When `exporter` is omitted, the debugger automatically creates a
|
|
112
|
+
* {@link MemoryKvStore}, {@link FedifySpanExporter},
|
|
113
|
+
* {@link BasicTracerProvider}, and registers it as the global tracer provider
|
|
114
|
+
* so that `createFederation()` picks it up automatically.
|
|
115
|
+
*/
|
|
116
|
+
interface FederationDebuggerSimpleOptions {
|
|
117
|
+
/**
|
|
118
|
+
* The path prefix for the debug dashboard. Defaults to `"/__debug__"`.
|
|
119
|
+
*/
|
|
120
|
+
path?: string;
|
|
121
|
+
/**
|
|
122
|
+
* Authentication configuration for the debug dashboard. When omitted,
|
|
123
|
+
* the dashboard is accessible without authentication.
|
|
124
|
+
*/
|
|
125
|
+
auth?: FederationDebuggerAuth;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Wraps a {@link Federation} object with a debug dashboard.
|
|
129
|
+
*
|
|
130
|
+
* When called without an `exporter`, the debugger automatically sets up
|
|
131
|
+
* OpenTelemetry tracing: it creates a {@link MemoryKvStore},
|
|
132
|
+
* {@link FedifySpanExporter}, and {@link BasicTracerProvider}, then registers
|
|
133
|
+
* it as the global tracer provider. It also auto-configures LogTape to
|
|
134
|
+
* collect logs per trace.
|
|
135
|
+
*
|
|
136
|
+
* @example Simple usage (recommended)
|
|
137
|
+
* ```typescript ignore
|
|
138
|
+
* const innerFederation = createFederation({ kv: new MemoryKvStore() });
|
|
139
|
+
* const federation = createFederationDebugger(innerFederation);
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @template TContextData The context data type of the federation.
|
|
143
|
+
* @param federation The federation object to wrap.
|
|
144
|
+
* @param options Optional path configuration.
|
|
145
|
+
* @returns A new {@link Federation} object with the debug dashboard attached
|
|
146
|
+
* and a `sink` property for LogTape integration.
|
|
147
|
+
*/
|
|
148
|
+
declare function createFederationDebugger<TContextData>(federation: Federation<TContextData>, options?: FederationDebuggerSimpleOptions): Federation<TContextData> & {
|
|
149
|
+
sink: Sink;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Wraps a {@link Federation} object with a debug dashboard.
|
|
153
|
+
*
|
|
154
|
+
* When called with an `exporter`, the caller is responsible for setting up
|
|
155
|
+
* the OpenTelemetry tracer provider and passing it to `createFederation()`.
|
|
156
|
+
* The returned object includes a `sink` property that should be added to
|
|
157
|
+
* the LogTape configuration to collect logs per trace.
|
|
158
|
+
*
|
|
159
|
+
* @example Advanced usage with explicit exporter
|
|
160
|
+
* ```typescript ignore
|
|
161
|
+
* const kv = new MemoryKvStore();
|
|
162
|
+
* const exporter = new FedifySpanExporter(kv);
|
|
163
|
+
* const tracerProvider = new BasicTracerProvider({
|
|
164
|
+
* spanProcessors: [new SimpleSpanProcessor(exporter)],
|
|
165
|
+
* });
|
|
166
|
+
* const innerFederation = createFederation({ kv, tracerProvider });
|
|
167
|
+
* const federation = createFederationDebugger(innerFederation, {
|
|
168
|
+
* exporter,
|
|
169
|
+
* kv,
|
|
170
|
+
* });
|
|
171
|
+
* await configure({
|
|
172
|
+
* sinks: { debugger: federation.sink },
|
|
173
|
+
* loggers: [
|
|
174
|
+
* { category: "fedify", sinks: ["debugger"] },
|
|
175
|
+
* ],
|
|
176
|
+
* });
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* @template TContextData The context data type of the federation.
|
|
180
|
+
* @param federation The federation object to wrap.
|
|
181
|
+
* @param options Options including the exporter.
|
|
182
|
+
* @returns A new {@link Federation} object with the debug dashboard attached
|
|
183
|
+
* and a `sink` property for LogTape integration.
|
|
184
|
+
*/
|
|
185
|
+
declare function createFederationDebugger<TContextData>(federation: Federation<TContextData>, options: FederationDebuggerOptions): Federation<TContextData> & {
|
|
186
|
+
sink: Sink;
|
|
187
|
+
};
|
|
188
|
+
//#endregion
|
|
189
|
+
export { FederationDebuggerAuth, FederationDebuggerOptions, FederationDebuggerSimpleOptions, SerializedLogRecord, createFederationDebugger, resetAutoSetup };
|