@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.
Files changed (68) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +464 -0
  3. package/dist/access.d.ts +21 -0
  4. package/dist/access.d.ts.map +1 -0
  5. package/dist/access.js +20 -0
  6. package/dist/access.js.map +1 -0
  7. package/dist/audit.d.ts +10 -0
  8. package/dist/audit.d.ts.map +1 -0
  9. package/dist/audit.js +49 -0
  10. package/dist/audit.js.map +1 -0
  11. package/dist/events.d.ts +143 -0
  12. package/dist/events.d.ts.map +1 -0
  13. package/dist/events.js +20 -0
  14. package/dist/events.js.map +1 -0
  15. package/dist/index.d.ts +114 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +44 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/instrumentation.d.ts +74 -0
  20. package/dist/instrumentation.d.ts.map +1 -0
  21. package/dist/instrumentation.js +293 -0
  22. package/dist/instrumentation.js.map +1 -0
  23. package/dist/persistence.d.ts +30 -0
  24. package/dist/persistence.d.ts.map +1 -0
  25. package/dist/persistence.js +100 -0
  26. package/dist/persistence.js.map +1 -0
  27. package/dist/provider-instrumentation.d.ts +9 -0
  28. package/dist/provider-instrumentation.d.ts.map +1 -0
  29. package/dist/provider-instrumentation.js +25 -0
  30. package/dist/provider-instrumentation.js.map +1 -0
  31. package/dist/provider.d.ts +79 -0
  32. package/dist/provider.d.ts.map +1 -0
  33. package/dist/provider.js +293 -0
  34. package/dist/provider.js.map +1 -0
  35. package/dist/redaction.d.ts +5 -0
  36. package/dist/redaction.d.ts.map +1 -0
  37. package/dist/redaction.js +20 -0
  38. package/dist/redaction.js.map +1 -0
  39. package/dist/routes.d.ts +113 -0
  40. package/dist/routes.d.ts.map +1 -0
  41. package/dist/routes.js +247 -0
  42. package/dist/routes.js.map +1 -0
  43. package/dist/trace-context.d.ts +29 -0
  44. package/dist/trace-context.d.ts.map +1 -0
  45. package/dist/trace-context.js +74 -0
  46. package/dist/trace-context.js.map +1 -0
  47. package/dist/ui.d.ts +14 -0
  48. package/dist/ui.d.ts.map +1 -0
  49. package/dist/ui.js +795 -0
  50. package/dist/ui.js.map +1 -0
  51. package/dist/watchers.d.ts +22 -0
  52. package/dist/watchers.d.ts.map +1 -0
  53. package/dist/watchers.js +171 -0
  54. package/dist/watchers.js.map +1 -0
  55. package/package.json +66 -0
  56. package/src/access.ts +52 -0
  57. package/src/audit.ts +71 -0
  58. package/src/events.ts +193 -0
  59. package/src/index.ts +136 -0
  60. package/src/instrumentation.ts +451 -0
  61. package/src/persistence.ts +163 -0
  62. package/src/provider-instrumentation.ts +50 -0
  63. package/src/provider.ts +375 -0
  64. package/src/redaction.ts +26 -0
  65. package/src/routes.ts +317 -0
  66. package/src/trace-context.ts +115 -0
  67. package/src/ui.ts +807 -0
  68. package/src/watchers.ts +235 -0
package/dist/ui.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui.js","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,UAAU,CAAC;AAElB;;;;GAIG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CACrC,QAAgB,EAChB,UAAsC,EAAE;IAExC,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,CAAC;QACrC,OAAO,wBAAwB,EAAE,CAAC;IACpC,CAAC;IAED,MAAM,IAAI,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IAE1C,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE;QACxB,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,EAAE,cAAc,EAAE,0BAA0B,EAAE;KACxD,CAAC,CAAC;AACL,CAAC;AAED,SAAS,kBAAkB,CAAC,QAAgB;IAC1C,MAAM,iBAAiB,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAEvD,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBA6KO,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAmlBzB,CAAC;AACT,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { DevtoolsEvent } from "./events";
2
+ export declare const BUILT_IN_DEVTOOLS_WATCHER_NAMES: readonly ["requests", "errors", "useCases", "eventBus", "jobs", "schedules", "providers", "db", "cache", "storage", "mail", "auth", "audit", "rateLimit", "custom"];
3
+ export type BuiltInDevtoolsWatcherName = (typeof BUILT_IN_DEVTOOLS_WATCHER_NAMES)[number];
4
+ export type DevtoolsWatcherName = BuiltInDevtoolsWatcherName | (string & {});
5
+ export interface DevtoolsWatcher {
6
+ name: DevtoolsWatcherName;
7
+ label: string;
8
+ description?: string;
9
+ eventTypes: readonly DevtoolsEvent["type"][];
10
+ enabled: boolean;
11
+ }
12
+ export type DevtoolsWatcherOptions = boolean | {
13
+ enabled?: boolean;
14
+ label?: string;
15
+ description?: string;
16
+ eventTypes?: readonly DevtoolsEvent["type"][];
17
+ };
18
+ export type DevtoolsWatchersOptions = Partial<Record<BuiltInDevtoolsWatcherName, DevtoolsWatcherOptions>> & Record<string, DevtoolsWatcherOptions | undefined>;
19
+ export declare function resolveDevtoolsWatchers(options?: DevtoolsWatchersOptions): DevtoolsWatcher[];
20
+ export declare function isDevtoolsWatcherEnabled(watchers: readonly DevtoolsWatcher[], name: DevtoolsWatcherName): boolean;
21
+ export declare function isDevtoolsEventEnabled(watchers: readonly DevtoolsWatcher[], event: DevtoolsEvent): boolean;
22
+ //# sourceMappingURL=watchers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watchers.d.ts","sourceRoot":"","sources":["../src/watchers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,eAAO,MAAM,+BAA+B,qKAgBlC,CAAC;AAEX,MAAM,MAAM,0BAA0B,GACpC,CAAC,OAAO,+BAA+B,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnD,MAAM,MAAM,mBAAmB,GAAG,0BAA0B,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAE7E,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,mBAAmB,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,SAAS,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;IAC7C,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,MAAM,sBAAsB,GAC9B,OAAO,GACP;IACE,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,SAAS,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;CAC/C,CAAC;AAEN,MAAM,MAAM,uBAAuB,GAAG,OAAO,CAC3C,MAAM,CAAC,0BAA0B,EAAE,sBAAsB,CAAC,CAC3D,GACC,MAAM,CAAC,MAAM,EAAE,sBAAsB,GAAG,SAAS,CAAC,CAAC;AA6IrD,wBAAgB,uBAAuB,CACrC,OAAO,GAAE,uBAA4B,GACpC,eAAe,EAAE,CAuBnB;AAED,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,SAAS,eAAe,EAAE,EACpC,IAAI,EAAE,mBAAmB,GACxB,OAAO,CAET;AAED,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,SAAS,eAAe,EAAE,EACpC,KAAK,EAAE,aAAa,GACnB,OAAO,CAWT"}
@@ -0,0 +1,171 @@
1
+ export const BUILT_IN_DEVTOOLS_WATCHER_NAMES = [
2
+ "requests",
3
+ "errors",
4
+ "useCases",
5
+ "eventBus",
6
+ "jobs",
7
+ "schedules",
8
+ "providers",
9
+ "db",
10
+ "cache",
11
+ "storage",
12
+ "mail",
13
+ "auth",
14
+ "audit",
15
+ "rateLimit",
16
+ "custom",
17
+ ];
18
+ const BUILT_IN_DEVTOOLS_WATCHERS = {
19
+ requests: {
20
+ name: "requests",
21
+ label: "Requests",
22
+ description: "HTTP request timing and contract route activity.",
23
+ eventTypes: ["request"],
24
+ enabled: true,
25
+ },
26
+ errors: {
27
+ name: "errors",
28
+ label: "Errors",
29
+ description: "Unhandled errors, use case failures, and devtools failures.",
30
+ eventTypes: ["error"],
31
+ enabled: true,
32
+ },
33
+ useCases: {
34
+ name: "useCases",
35
+ label: "Use cases",
36
+ description: "Application command and query execution.",
37
+ eventTypes: ["usecase"],
38
+ enabled: true,
39
+ },
40
+ eventBus: {
41
+ name: "eventBus",
42
+ label: "Event bus",
43
+ description: "Domain event publishing.",
44
+ eventTypes: ["eventBus"],
45
+ enabled: true,
46
+ },
47
+ jobs: {
48
+ name: "jobs",
49
+ label: "Jobs",
50
+ description: "Background job scheduling and execution.",
51
+ eventTypes: ["job"],
52
+ enabled: true,
53
+ },
54
+ schedules: {
55
+ name: "schedules",
56
+ label: "Schedules",
57
+ description: "Scheduled task execution.",
58
+ eventTypes: ["schedule"],
59
+ enabled: true,
60
+ },
61
+ providers: {
62
+ name: "providers",
63
+ label: "Providers",
64
+ description: "Provider setup, start, and stop lifecycle activity.",
65
+ eventTypes: ["provider"],
66
+ enabled: true,
67
+ },
68
+ db: {
69
+ name: "db",
70
+ label: "Database",
71
+ description: "Database queries and mutations from first-party providers.",
72
+ eventTypes: ["custom"],
73
+ enabled: true,
74
+ },
75
+ cache: {
76
+ name: "cache",
77
+ label: "Cache",
78
+ description: "Cache reads, writes, and deletes from first-party providers.",
79
+ eventTypes: ["custom"],
80
+ enabled: true,
81
+ },
82
+ storage: {
83
+ name: "storage",
84
+ label: "Storage",
85
+ description: "Object storage reads, writes, and deletes from first-party providers.",
86
+ eventTypes: ["custom"],
87
+ enabled: true,
88
+ },
89
+ mail: {
90
+ name: "mail",
91
+ label: "Mail",
92
+ description: "Mail delivery attempts from first-party providers.",
93
+ eventTypes: ["custom"],
94
+ enabled: true,
95
+ },
96
+ auth: {
97
+ name: "auth",
98
+ label: "Auth",
99
+ description: "Authentication and session activity from first-party providers.",
100
+ eventTypes: ["custom"],
101
+ enabled: true,
102
+ },
103
+ audit: {
104
+ name: "audit",
105
+ label: "Audit",
106
+ description: "Durable audit and activity records emitted by the app.",
107
+ eventTypes: ["custom"],
108
+ enabled: true,
109
+ },
110
+ rateLimit: {
111
+ name: "rateLimit",
112
+ label: "Rate limits",
113
+ description: "Rate limit checks from first-party providers.",
114
+ eventTypes: ["custom"],
115
+ enabled: true,
116
+ },
117
+ custom: {
118
+ name: "custom",
119
+ label: "Custom",
120
+ description: "Application and integration-specific diagnostic events.",
121
+ eventTypes: ["custom"],
122
+ enabled: true,
123
+ },
124
+ };
125
+ function normalizeWatcherOptions(name, defaultWatcher, options) {
126
+ const base = defaultWatcher ?? {
127
+ name,
128
+ label: name,
129
+ eventTypes: [],
130
+ enabled: true,
131
+ };
132
+ if (typeof options === "boolean") {
133
+ return {
134
+ ...base,
135
+ enabled: options,
136
+ };
137
+ }
138
+ return {
139
+ ...base,
140
+ ...options,
141
+ name,
142
+ label: options?.label ?? base.label,
143
+ eventTypes: options?.eventTypes ?? base.eventTypes,
144
+ enabled: options?.enabled ?? base.enabled,
145
+ };
146
+ }
147
+ export function resolveDevtoolsWatchers(options = {}) {
148
+ const watchers = BUILT_IN_DEVTOOLS_WATCHER_NAMES.map((name) => normalizeWatcherOptions(name, BUILT_IN_DEVTOOLS_WATCHERS[name], options[name]));
149
+ for (const [name, option] of Object.entries(options)) {
150
+ if (BUILT_IN_DEVTOOLS_WATCHER_NAMES.includes(name) ||
151
+ option === undefined) {
152
+ continue;
153
+ }
154
+ watchers.push(normalizeWatcherOptions(name, undefined, option));
155
+ }
156
+ return watchers;
157
+ }
158
+ export function isDevtoolsWatcherEnabled(watchers, name) {
159
+ return watchers.find((watcher) => watcher.name === name)?.enabled ?? true;
160
+ }
161
+ export function isDevtoolsEventEnabled(watchers, event) {
162
+ if (event.watcher) {
163
+ return isDevtoolsWatcherEnabled(watchers, event.watcher);
164
+ }
165
+ if (event.type === "custom") {
166
+ return isDevtoolsWatcherEnabled(watchers, "custom");
167
+ }
168
+ const watcher = watchers.find((item) => item.eventTypes.includes(event.type));
169
+ return watcher?.enabled ?? true;
170
+ }
171
+ //# sourceMappingURL=watchers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watchers.js","sourceRoot":"","sources":["../src/watchers.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,+BAA+B,GAAG;IAC7C,UAAU;IAC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;AAED,MAAM,UAAU,wBAAwB,CACtC,QAAoC,EACpC,IAAyB;IAEzB,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,OAAO,IAAI,IAAI,CAAC;AAC5E,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,QAAoC,EACpC,KAAoB;IAEpB,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QAClB,OAAO,wBAAwB,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3D,CAAC;IAED,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,wBAAwB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACtD,CAAC;IAED,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9E,OAAO,OAAO,EAAE,OAAO,IAAI,IAAI,CAAC;AAClC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@beignet/devtools",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "description": "Development-time devtools for Beignet - mini Telescope for the server runtime",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "src",
17
+ "!src/**/*.test.ts",
18
+ "!src/**/*.test.tsx",
19
+ "!src/**/*.test-d.ts",
20
+ "README.md",
21
+ "CHANGELOG.md"
22
+ ],
23
+ "scripts": {
24
+ "build": "tsc",
25
+ "dev": "tsc --watch",
26
+ "clean": "rm -rf dist coverage .turbo",
27
+ "test": "bun test",
28
+ "test:coverage": "bun test --coverage",
29
+ "lint": "biome check ."
30
+ },
31
+ "keywords": [
32
+ "beignet",
33
+ "devtools",
34
+ "development",
35
+ "debugging",
36
+ "server",
37
+ "ports"
38
+ ],
39
+ "license": "MIT",
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/taylorbryant/beignet.git",
43
+ "directory": "packages/devtools"
44
+ },
45
+ "author": "Taylor Bryant",
46
+ "homepage": "https://github.com/taylorbryant/beignet#readme",
47
+ "bugs": "https://github.com/taylorbryant/beignet/issues",
48
+ "sideEffects": false,
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "engines": {
53
+ "node": ">=18.0.0"
54
+ },
55
+ "peerDependencies": {
56
+ "@beignet/core": "*"
57
+ },
58
+ "dependencies": {
59
+ "zod": "^4.0.0"
60
+ },
61
+ "devDependencies": {
62
+ "@types/bun": "^1.3.13",
63
+ "@types/node": "^20.10.0",
64
+ "typescript": "^5.3.0"
65
+ }
66
+ }
package/src/access.ts ADDED
@@ -0,0 +1,52 @@
1
+ export type DevtoolsAuthorizeResult = boolean | Response;
2
+
3
+ export type DevtoolsAuthorize = (
4
+ req: Request,
5
+ ) => DevtoolsAuthorizeResult | Promise<DevtoolsAuthorizeResult>;
6
+
7
+ export interface DevtoolsRouteAccessOptions {
8
+ /**
9
+ * Whether the devtools route should be exposed.
10
+ *
11
+ * @default process.env.NODE_ENV !== "production"
12
+ */
13
+ enabled?: boolean;
14
+
15
+ /**
16
+ * Optional app-owned authorization check for exposed devtools routes.
17
+ *
18
+ * Returning `false` hides devtools with a 404. Returning a `Response` lets
19
+ * the app provide a custom denial response.
20
+ */
21
+ authorize?: DevtoolsAuthorize;
22
+ }
23
+
24
+ export function isDevtoolsRouteEnabled(
25
+ options: DevtoolsRouteAccessOptions = {},
26
+ ): boolean {
27
+ return options.enabled ?? process.env.NODE_ENV !== "production";
28
+ }
29
+
30
+ export function devtoolsNotFoundResponse(): Response {
31
+ return new Response("Not Found", { status: 404 });
32
+ }
33
+
34
+ export async function authorizeDevtoolsRequest(
35
+ req: Request,
36
+ options: DevtoolsRouteAccessOptions = {},
37
+ ): Promise<Response | undefined> {
38
+ if (!isDevtoolsRouteEnabled(options)) {
39
+ return devtoolsNotFoundResponse();
40
+ }
41
+
42
+ if (!options.authorize) {
43
+ return undefined;
44
+ }
45
+
46
+ const result = await options.authorize(req);
47
+ if (result instanceof Response) {
48
+ return result;
49
+ }
50
+
51
+ return result ? undefined : devtoolsNotFoundResponse();
52
+ }
package/src/audit.ts ADDED
@@ -0,0 +1,71 @@
1
+ import {
2
+ type AuditLogEntry,
3
+ type AuditLogEntryInput,
4
+ type AuditLogPort,
5
+ normalizeAuditLogEntry,
6
+ redactAuditLogEntry,
7
+ } from "@beignet/core/ports";
8
+ import type { DevtoolsPort } from "./index";
9
+
10
+ export interface DevtoolsAuditLogOptions {
11
+ audit: AuditLogPort;
12
+ devtools?: DevtoolsPort;
13
+ emit?: boolean;
14
+ redact?: (entry: AuditLogEntry) => AuditLogEntry;
15
+ }
16
+
17
+ function prepareEntry(
18
+ input: AuditLogEntryInput,
19
+ redact?: (entry: AuditLogEntry) => AuditLogEntry,
20
+ ): AuditLogEntry {
21
+ const redacted = redactAuditLogEntry(normalizeAuditLogEntry(input));
22
+ return redact ? redact(redacted) : redacted;
23
+ }
24
+
25
+ function auditSummary(entry: AuditLogEntry): string {
26
+ const resource = entry.resource?.id
27
+ ? `${entry.resource.type}:${entry.resource.id}`
28
+ : entry.resource?.type;
29
+ const outcome = entry.outcome === "failure" ? "failed" : "succeeded";
30
+ return resource
31
+ ? `${entry.action} ${outcome} for ${resource}`
32
+ : `${entry.action} ${outcome}`;
33
+ }
34
+
35
+ export function createDevtoolsAuditLog(
36
+ options: DevtoolsAuditLogOptions,
37
+ ): AuditLogPort {
38
+ return {
39
+ async record(input) {
40
+ const entry = prepareEntry(input, options.redact);
41
+
42
+ await options.audit.record(entry);
43
+
44
+ if (options.emit === false || !options.devtools) return;
45
+
46
+ try {
47
+ options.devtools.record({
48
+ type: "custom",
49
+ watcher: "audit",
50
+ name: entry.action,
51
+ label: "Audit",
52
+ summary: auditSummary(entry),
53
+ requestId: entry.requestId,
54
+ traceId: entry.traceId,
55
+ details: {
56
+ action: entry.action,
57
+ actor: entry.actor,
58
+ tenant: entry.tenant,
59
+ resource: entry.resource,
60
+ outcome: entry.outcome,
61
+ message: entry.message,
62
+ metadata: entry.metadata,
63
+ occurredAt: entry.occurredAt.toISOString(),
64
+ },
65
+ });
66
+ } catch {
67
+ // Devtools is an observer; durable audit writes must not depend on it.
68
+ }
69
+ },
70
+ };
71
+ }
package/src/events.ts ADDED
@@ -0,0 +1,193 @@
1
+ /**
2
+ * Event types for Beignet devtools
3
+ *
4
+ * These events represent activity within the Beignet server and can be
5
+ * logged during development to aid in debugging and observability.
6
+ */
7
+
8
+ /**
9
+ * Base interface for all devtools events.
10
+ * All events share these common fields for correlation and debugging.
11
+ */
12
+ export interface BaseDevtoolsEvent {
13
+ /**
14
+ * Unique identifier for this event (UUID or timestamp-based).
15
+ */
16
+ id: string;
17
+
18
+ /**
19
+ * ISO timestamp when the event occurred.
20
+ */
21
+ timestamp: string;
22
+
23
+ /**
24
+ * Optional correlation ID to link events from the same request/operation.
25
+ */
26
+ requestId?: string;
27
+
28
+ /**
29
+ * W3C trace ID for cross-service correlation.
30
+ */
31
+ traceId?: string;
32
+
33
+ /**
34
+ * Span ID for the operation represented by this event.
35
+ */
36
+ spanId?: string;
37
+
38
+ /**
39
+ * Parent span ID when this event belongs to a nested operation.
40
+ */
41
+ parentSpanId?: string;
42
+
43
+ /**
44
+ * W3C traceparent header value associated with this event.
45
+ */
46
+ traceparent?: string;
47
+
48
+ /**
49
+ * Optional watcher name that owns this event. Built-in events can infer their
50
+ * watcher from `type`; custom integrations can set this to use their own
51
+ * watcher configuration.
52
+ */
53
+ watcher?: string;
54
+
55
+ /**
56
+ * Optional structured detail payload. Devtools applies default redaction to
57
+ * this field before events are stored.
58
+ */
59
+ details?: unknown;
60
+ }
61
+
62
+ /**
63
+ * Logged when the server handles a request mapped from a contract.
64
+ */
65
+ export interface RequestEvent extends BaseDevtoolsEvent {
66
+ type: "request";
67
+ method: string;
68
+ path: string;
69
+ contractName?: string;
70
+ status?: number;
71
+ durationMs?: number;
72
+ summary?: string;
73
+ }
74
+
75
+ /**
76
+ * Logged when an error occurs (unhandled or explicit).
77
+ */
78
+ export interface ErrorEvent extends BaseDevtoolsEvent {
79
+ type: "error";
80
+ message: string;
81
+ stack?: string;
82
+ contractName?: string;
83
+ useCaseName?: string;
84
+ }
85
+
86
+ /**
87
+ * Logged when a use case runs.
88
+ */
89
+ export interface UseCaseEvent extends BaseDevtoolsEvent {
90
+ type: "usecase";
91
+ name: string;
92
+ kind?: "command" | "query";
93
+ phase: "start" | "end" | "error";
94
+ durationMs?: number;
95
+ error?: string;
96
+ }
97
+
98
+ /**
99
+ * Logged when the event bus publishes an event.
100
+ */
101
+ export interface EventBusEvent extends BaseDevtoolsEvent {
102
+ type: "eventBus";
103
+ eventName: string;
104
+ }
105
+
106
+ /**
107
+ * Logged when a job is scheduled / starts / completes / fails.
108
+ * Jobs may be backed by Inngest or other providers.
109
+ */
110
+ export interface JobEvent extends BaseDevtoolsEvent {
111
+ type: "job";
112
+ jobName: string;
113
+ status: "scheduled" | "started" | "completed" | "failed";
114
+ }
115
+
116
+ /**
117
+ * Logged when a scheduled task starts, completes, or fails.
118
+ */
119
+ export interface ScheduleEvent extends BaseDevtoolsEvent {
120
+ type: "schedule";
121
+ scheduleName: string;
122
+ status: "started" | "completed" | "failed";
123
+ cron?: string;
124
+ timezone?: string;
125
+ }
126
+
127
+ /**
128
+ * Logged when a provider is set up, started, or stopped.
129
+ */
130
+ export interface ProviderEvent extends BaseDevtoolsEvent {
131
+ type: "provider";
132
+ providerName: string;
133
+ action: "setup" | "start" | "stop";
134
+ }
135
+
136
+ /**
137
+ * Logged by application or integration code for app-specific diagnostics.
138
+ */
139
+ export interface CustomDevtoolsEvent extends BaseDevtoolsEvent {
140
+ type: "custom";
141
+ name: string;
142
+ label?: string;
143
+ summary?: string;
144
+ }
145
+
146
+ /**
147
+ * Union type of all devtools events.
148
+ */
149
+ export type DevtoolsEvent =
150
+ | RequestEvent
151
+ | ErrorEvent
152
+ | UseCaseEvent
153
+ | EventBusEvent
154
+ | JobEvent
155
+ | ScheduleEvent
156
+ | ProviderEvent
157
+ | CustomDevtoolsEvent;
158
+
159
+ export type DevtoolsEventInput = DevtoolsEvent extends infer Event
160
+ ? Event extends DevtoolsEvent
161
+ ? Omit<Event, "id" | "timestamp"> & Partial<Pick<Event, "id" | "timestamp">>
162
+ : never
163
+ : never;
164
+
165
+ export type DevtoolsRedactor = (event: DevtoolsEvent) => DevtoolsEvent;
166
+
167
+ export type DevtoolsSubscriptionEvent =
168
+ | {
169
+ type: "record";
170
+ event: DevtoolsEvent;
171
+ }
172
+ | {
173
+ type: "clear";
174
+ };
175
+
176
+ export type DevtoolsListener = (event: DevtoolsSubscriptionEvent) => void;
177
+
178
+ export const DEVTOOLS_EVENT_TYPES = [
179
+ "request",
180
+ "error",
181
+ "usecase",
182
+ "eventBus",
183
+ "job",
184
+ "schedule",
185
+ "provider",
186
+ "custom",
187
+ ] as const satisfies readonly DevtoolsEvent["type"][];
188
+
189
+ export function isDevtoolsEventType(
190
+ value: string,
191
+ ): value is DevtoolsEvent["type"] {
192
+ return DEVTOOLS_EVENT_TYPES.includes(value as DevtoolsEvent["type"]);
193
+ }