@beignet/devtools 0.0.1
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/CHANGELOG.md +5 -0
- package/README.md +464 -0
- package/dist/access.d.ts +21 -0
- package/dist/access.d.ts.map +1 -0
- package/dist/access.js +20 -0
- package/dist/access.js.map +1 -0
- package/dist/audit.d.ts +10 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/audit.js +49 -0
- package/dist/audit.js.map +1 -0
- package/dist/events.d.ts +143 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +20 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +114 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/instrumentation.d.ts +74 -0
- package/dist/instrumentation.d.ts.map +1 -0
- package/dist/instrumentation.js +293 -0
- package/dist/instrumentation.js.map +1 -0
- package/dist/persistence.d.ts +30 -0
- package/dist/persistence.d.ts.map +1 -0
- package/dist/persistence.js +100 -0
- package/dist/persistence.js.map +1 -0
- package/dist/provider-instrumentation.d.ts +9 -0
- package/dist/provider-instrumentation.d.ts.map +1 -0
- package/dist/provider-instrumentation.js +25 -0
- package/dist/provider-instrumentation.js.map +1 -0
- package/dist/provider.d.ts +79 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +293 -0
- package/dist/provider.js.map +1 -0
- package/dist/redaction.d.ts +5 -0
- package/dist/redaction.d.ts.map +1 -0
- package/dist/redaction.js +20 -0
- package/dist/redaction.js.map +1 -0
- package/dist/routes.d.ts +113 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +247 -0
- package/dist/routes.js.map +1 -0
- package/dist/trace-context.d.ts +29 -0
- package/dist/trace-context.d.ts.map +1 -0
- package/dist/trace-context.js +74 -0
- package/dist/trace-context.js.map +1 -0
- package/dist/ui.d.ts +14 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +795 -0
- package/dist/ui.js.map +1 -0
- package/dist/watchers.d.ts +22 -0
- package/dist/watchers.d.ts.map +1 -0
- package/dist/watchers.js +171 -0
- package/dist/watchers.js.map +1 -0
- package/package.json +66 -0
- package/src/access.ts +52 -0
- package/src/audit.ts +71 -0
- package/src/events.ts +193 -0
- package/src/index.ts +136 -0
- package/src/instrumentation.ts +451 -0
- package/src/persistence.ts +163 -0
- package/src/provider-instrumentation.ts +50 -0
- package/src/provider.ts +375 -0
- package/src/redaction.ts +26 -0
- package/src/routes.ts +317 -0
- package/src/trace-context.ts +115 -0
- package/src/ui.ts +807 -0
- package/src/watchers.ts +235 -0
package/src/watchers.ts
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import type { DevtoolsEvent } from "./events";
|
|
2
|
+
|
|
3
|
+
export const BUILT_IN_DEVTOOLS_WATCHER_NAMES = [
|
|
4
|
+
"requests",
|
|
5
|
+
"errors",
|
|
6
|
+
"useCases",
|
|
7
|
+
"eventBus",
|
|
8
|
+
"jobs",
|
|
9
|
+
"schedules",
|
|
10
|
+
"providers",
|
|
11
|
+
"db",
|
|
12
|
+
"cache",
|
|
13
|
+
"storage",
|
|
14
|
+
"mail",
|
|
15
|
+
"auth",
|
|
16
|
+
"audit",
|
|
17
|
+
"rateLimit",
|
|
18
|
+
"custom",
|
|
19
|
+
] as const;
|
|
20
|
+
|
|
21
|
+
export type BuiltInDevtoolsWatcherName =
|
|
22
|
+
(typeof BUILT_IN_DEVTOOLS_WATCHER_NAMES)[number];
|
|
23
|
+
|
|
24
|
+
export type DevtoolsWatcherName = BuiltInDevtoolsWatcherName | (string & {});
|
|
25
|
+
|
|
26
|
+
export interface DevtoolsWatcher {
|
|
27
|
+
name: DevtoolsWatcherName;
|
|
28
|
+
label: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
eventTypes: readonly DevtoolsEvent["type"][];
|
|
31
|
+
enabled: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type DevtoolsWatcherOptions =
|
|
35
|
+
| boolean
|
|
36
|
+
| {
|
|
37
|
+
enabled?: boolean;
|
|
38
|
+
label?: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
eventTypes?: readonly DevtoolsEvent["type"][];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type DevtoolsWatchersOptions = Partial<
|
|
44
|
+
Record<BuiltInDevtoolsWatcherName, DevtoolsWatcherOptions>
|
|
45
|
+
> &
|
|
46
|
+
Record<string, DevtoolsWatcherOptions | undefined>;
|
|
47
|
+
|
|
48
|
+
const BUILT_IN_DEVTOOLS_WATCHERS = {
|
|
49
|
+
requests: {
|
|
50
|
+
name: "requests",
|
|
51
|
+
label: "Requests",
|
|
52
|
+
description: "HTTP request timing and contract route activity.",
|
|
53
|
+
eventTypes: ["request"],
|
|
54
|
+
enabled: true,
|
|
55
|
+
},
|
|
56
|
+
errors: {
|
|
57
|
+
name: "errors",
|
|
58
|
+
label: "Errors",
|
|
59
|
+
description: "Unhandled errors, use case failures, and devtools failures.",
|
|
60
|
+
eventTypes: ["error"],
|
|
61
|
+
enabled: true,
|
|
62
|
+
},
|
|
63
|
+
useCases: {
|
|
64
|
+
name: "useCases",
|
|
65
|
+
label: "Use cases",
|
|
66
|
+
description: "Application command and query execution.",
|
|
67
|
+
eventTypes: ["usecase"],
|
|
68
|
+
enabled: true,
|
|
69
|
+
},
|
|
70
|
+
eventBus: {
|
|
71
|
+
name: "eventBus",
|
|
72
|
+
label: "Event bus",
|
|
73
|
+
description: "Domain event publishing.",
|
|
74
|
+
eventTypes: ["eventBus"],
|
|
75
|
+
enabled: true,
|
|
76
|
+
},
|
|
77
|
+
jobs: {
|
|
78
|
+
name: "jobs",
|
|
79
|
+
label: "Jobs",
|
|
80
|
+
description: "Background job scheduling and execution.",
|
|
81
|
+
eventTypes: ["job"],
|
|
82
|
+
enabled: true,
|
|
83
|
+
},
|
|
84
|
+
schedules: {
|
|
85
|
+
name: "schedules",
|
|
86
|
+
label: "Schedules",
|
|
87
|
+
description: "Scheduled task execution.",
|
|
88
|
+
eventTypes: ["schedule"],
|
|
89
|
+
enabled: true,
|
|
90
|
+
},
|
|
91
|
+
providers: {
|
|
92
|
+
name: "providers",
|
|
93
|
+
label: "Providers",
|
|
94
|
+
description: "Provider setup, start, and stop lifecycle activity.",
|
|
95
|
+
eventTypes: ["provider"],
|
|
96
|
+
enabled: true,
|
|
97
|
+
},
|
|
98
|
+
db: {
|
|
99
|
+
name: "db",
|
|
100
|
+
label: "Database",
|
|
101
|
+
description: "Database queries and mutations from first-party providers.",
|
|
102
|
+
eventTypes: ["custom"],
|
|
103
|
+
enabled: true,
|
|
104
|
+
},
|
|
105
|
+
cache: {
|
|
106
|
+
name: "cache",
|
|
107
|
+
label: "Cache",
|
|
108
|
+
description: "Cache reads, writes, and deletes from first-party providers.",
|
|
109
|
+
eventTypes: ["custom"],
|
|
110
|
+
enabled: true,
|
|
111
|
+
},
|
|
112
|
+
storage: {
|
|
113
|
+
name: "storage",
|
|
114
|
+
label: "Storage",
|
|
115
|
+
description:
|
|
116
|
+
"Object storage reads, writes, and deletes from first-party providers.",
|
|
117
|
+
eventTypes: ["custom"],
|
|
118
|
+
enabled: true,
|
|
119
|
+
},
|
|
120
|
+
mail: {
|
|
121
|
+
name: "mail",
|
|
122
|
+
label: "Mail",
|
|
123
|
+
description: "Mail delivery attempts from first-party providers.",
|
|
124
|
+
eventTypes: ["custom"],
|
|
125
|
+
enabled: true,
|
|
126
|
+
},
|
|
127
|
+
auth: {
|
|
128
|
+
name: "auth",
|
|
129
|
+
label: "Auth",
|
|
130
|
+
description:
|
|
131
|
+
"Authentication and session activity from first-party providers.",
|
|
132
|
+
eventTypes: ["custom"],
|
|
133
|
+
enabled: true,
|
|
134
|
+
},
|
|
135
|
+
audit: {
|
|
136
|
+
name: "audit",
|
|
137
|
+
label: "Audit",
|
|
138
|
+
description: "Durable audit and activity records emitted by the app.",
|
|
139
|
+
eventTypes: ["custom"],
|
|
140
|
+
enabled: true,
|
|
141
|
+
},
|
|
142
|
+
rateLimit: {
|
|
143
|
+
name: "rateLimit",
|
|
144
|
+
label: "Rate limits",
|
|
145
|
+
description: "Rate limit checks from first-party providers.",
|
|
146
|
+
eventTypes: ["custom"],
|
|
147
|
+
enabled: true,
|
|
148
|
+
},
|
|
149
|
+
custom: {
|
|
150
|
+
name: "custom",
|
|
151
|
+
label: "Custom",
|
|
152
|
+
description: "Application and integration-specific diagnostic events.",
|
|
153
|
+
eventTypes: ["custom"],
|
|
154
|
+
enabled: true,
|
|
155
|
+
},
|
|
156
|
+
} as const satisfies Record<BuiltInDevtoolsWatcherName, DevtoolsWatcher>;
|
|
157
|
+
|
|
158
|
+
function normalizeWatcherOptions(
|
|
159
|
+
name: string,
|
|
160
|
+
defaultWatcher: DevtoolsWatcher | undefined,
|
|
161
|
+
options: DevtoolsWatcherOptions | undefined,
|
|
162
|
+
): DevtoolsWatcher {
|
|
163
|
+
const base = defaultWatcher ?? {
|
|
164
|
+
name,
|
|
165
|
+
label: name,
|
|
166
|
+
eventTypes: [],
|
|
167
|
+
enabled: true,
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
if (typeof options === "boolean") {
|
|
171
|
+
return {
|
|
172
|
+
...base,
|
|
173
|
+
enabled: options,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
...base,
|
|
179
|
+
...options,
|
|
180
|
+
name,
|
|
181
|
+
label: options?.label ?? base.label,
|
|
182
|
+
eventTypes: options?.eventTypes ?? base.eventTypes,
|
|
183
|
+
enabled: options?.enabled ?? base.enabled,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function resolveDevtoolsWatchers(
|
|
188
|
+
options: DevtoolsWatchersOptions = {},
|
|
189
|
+
): DevtoolsWatcher[] {
|
|
190
|
+
const watchers = BUILT_IN_DEVTOOLS_WATCHER_NAMES.map((name) =>
|
|
191
|
+
normalizeWatcherOptions(
|
|
192
|
+
name,
|
|
193
|
+
BUILT_IN_DEVTOOLS_WATCHERS[name],
|
|
194
|
+
options[name],
|
|
195
|
+
),
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
for (const [name, option] of Object.entries(options)) {
|
|
199
|
+
if (
|
|
200
|
+
BUILT_IN_DEVTOOLS_WATCHER_NAMES.includes(
|
|
201
|
+
name as BuiltInDevtoolsWatcherName,
|
|
202
|
+
) ||
|
|
203
|
+
option === undefined
|
|
204
|
+
) {
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
watchers.push(normalizeWatcherOptions(name, undefined, option));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return watchers;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function isDevtoolsWatcherEnabled(
|
|
215
|
+
watchers: readonly DevtoolsWatcher[],
|
|
216
|
+
name: DevtoolsWatcherName,
|
|
217
|
+
): boolean {
|
|
218
|
+
return watchers.find((watcher) => watcher.name === name)?.enabled ?? true;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export function isDevtoolsEventEnabled(
|
|
222
|
+
watchers: readonly DevtoolsWatcher[],
|
|
223
|
+
event: DevtoolsEvent,
|
|
224
|
+
): boolean {
|
|
225
|
+
if (event.watcher) {
|
|
226
|
+
return isDevtoolsWatcherEnabled(watchers, event.watcher);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (event.type === "custom") {
|
|
230
|
+
return isDevtoolsWatcherEnabled(watchers, "custom");
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const watcher = watchers.find((item) => item.eventTypes.includes(event.type));
|
|
234
|
+
return watcher?.enabled ?? true;
|
|
235
|
+
}
|