@beignet/core 0.0.13 → 0.0.15
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 +28 -0
- package/README.md +198 -2
- package/dist/entitlements/index.d.ts +234 -0
- package/dist/entitlements/index.d.ts.map +1 -0
- package/dist/entitlements/index.js +172 -0
- package/dist/entitlements/index.js.map +1 -0
- package/dist/error-reporting/index.d.ts +131 -0
- package/dist/error-reporting/index.d.ts.map +1 -0
- package/dist/error-reporting/index.js +112 -0
- package/dist/error-reporting/index.js.map +1 -0
- package/dist/flags/index.d.ts +293 -0
- package/dist/flags/index.d.ts.map +1 -0
- package/dist/flags/index.js +204 -0
- package/dist/flags/index.js.map +1 -0
- package/dist/locks/index.d.ts +155 -0
- package/dist/locks/index.d.ts.map +1 -0
- package/dist/locks/index.js +248 -0
- package/dist/locks/index.js.map +1 -0
- package/dist/payments/index.d.ts +430 -0
- package/dist/payments/index.d.ts.map +1 -0
- package/dist/payments/index.js +230 -0
- package/dist/payments/index.js.map +1 -0
- package/dist/ports/index.d.ts +74 -1
- package/dist/ports/index.d.ts.map +1 -1
- package/dist/ports/index.js +38 -0
- package/dist/ports/index.js.map +1 -1
- package/dist/ports/policy.d.ts +104 -0
- package/dist/ports/policy.d.ts.map +1 -1
- package/dist/ports/policy.js +102 -7
- package/dist/ports/policy.js.map +1 -1
- package/dist/search/index.d.ts +175 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +344 -0
- package/dist/search/index.js.map +1 -0
- package/dist/server/hooks/error-reporting.d.ts +79 -0
- package/dist/server/hooks/error-reporting.d.ts.map +1 -0
- package/dist/server/hooks/error-reporting.js +147 -0
- package/dist/server/hooks/error-reporting.js.map +1 -0
- package/dist/server/hooks/index.d.ts +1 -0
- package/dist/server/hooks/index.d.ts.map +1 -1
- package/dist/server/hooks/index.js +1 -0
- package/dist/server/hooks/index.js.map +1 -1
- package/dist/server/server.d.ts +5 -0
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +9 -1
- package/dist/server/server.js.map +1 -1
- package/dist/server/use-case-route.d.ts +2 -2
- package/dist/testing/index.d.ts +46 -1
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +33 -1
- package/dist/testing/index.js.map +1 -1
- package/dist/webhooks/index.d.ts +195 -0
- package/dist/webhooks/index.d.ts.map +1 -0
- package/dist/webhooks/index.js +313 -0
- package/dist/webhooks/index.js.map +1 -0
- package/package.json +29 -1
- package/src/entitlements/index.ts +479 -0
- package/src/error-reporting/index.ts +273 -0
- package/src/flags/index.ts +608 -0
- package/src/locks/index.ts +440 -0
- package/src/payments/index.ts +699 -0
- package/src/ports/index.ts +231 -0
- package/src/ports/policy.ts +272 -7
- package/src/search/index.ts +632 -0
- package/src/server/hooks/error-reporting.ts +249 -0
- package/src/server/hooks/index.ts +8 -0
- package/src/server/server.ts +20 -0
- package/src/server/use-case-route.ts +2 -2
- package/src/testing/index.ts +83 -1
- package/src/webhooks/index.ts +555 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @beignet/core/error-reporting
|
|
3
|
+
*
|
|
4
|
+
* Provider-neutral error reporting primitives for Beignet applications.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* JSON-compatible value accepted by error reporting context, tags, and extras.
|
|
11
|
+
*/
|
|
12
|
+
export type ErrorReportJsonValue =
|
|
13
|
+
| null
|
|
14
|
+
| boolean
|
|
15
|
+
| number
|
|
16
|
+
| string
|
|
17
|
+
| readonly ErrorReportJsonValue[]
|
|
18
|
+
| { readonly [key: string]: ErrorReportJsonValue };
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Error severity level shared by common reporting providers.
|
|
22
|
+
*/
|
|
23
|
+
export type ErrorReportLevel = "fatal" | "error" | "warning" | "info" | "debug";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* User or actor attached to a reported error.
|
|
27
|
+
*/
|
|
28
|
+
export type ErrorReportUser = {
|
|
29
|
+
id?: string;
|
|
30
|
+
email?: string;
|
|
31
|
+
username?: string;
|
|
32
|
+
ipAddress?: string;
|
|
33
|
+
} & Record<string, ErrorReportJsonValue | undefined>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Provider-neutral structured context attached to a reported error.
|
|
37
|
+
*/
|
|
38
|
+
export type ErrorReportContext = Record<
|
|
39
|
+
string,
|
|
40
|
+
ErrorReportJsonValue | undefined
|
|
41
|
+
>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Tags used for searching, grouping, and alert routing.
|
|
45
|
+
*/
|
|
46
|
+
export type ErrorReportTags = Record<
|
|
47
|
+
string,
|
|
48
|
+
string | number | boolean | null | undefined
|
|
49
|
+
>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Options accepted by exception and message capture calls.
|
|
53
|
+
*/
|
|
54
|
+
export type ErrorReportOptions = {
|
|
55
|
+
level?: ErrorReportLevel;
|
|
56
|
+
user?: ErrorReportUser | null;
|
|
57
|
+
tags?: ErrorReportTags;
|
|
58
|
+
contexts?: Record<string, ErrorReportContext | undefined>;
|
|
59
|
+
extra?: Record<string, ErrorReportJsonValue | undefined>;
|
|
60
|
+
fingerprint?: readonly string[];
|
|
61
|
+
mechanism?: string;
|
|
62
|
+
handled?: boolean;
|
|
63
|
+
requestId?: string;
|
|
64
|
+
traceId?: string;
|
|
65
|
+
spanId?: string;
|
|
66
|
+
parentSpanId?: string;
|
|
67
|
+
traceparent?: string;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Result returned by a reporting provider after capture.
|
|
72
|
+
*/
|
|
73
|
+
export type ErrorReportResult = {
|
|
74
|
+
id?: string;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Flush options accepted by providers that buffer events.
|
|
79
|
+
*/
|
|
80
|
+
export type ErrorReporterFlushOptions = {
|
|
81
|
+
timeoutMs?: number;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* App-facing error reporting port.
|
|
86
|
+
*/
|
|
87
|
+
export type ErrorReporterPort = {
|
|
88
|
+
captureException(
|
|
89
|
+
error: unknown,
|
|
90
|
+
options?: ErrorReportOptions,
|
|
91
|
+
): Promise<ErrorReportResult>;
|
|
92
|
+
captureMessage(
|
|
93
|
+
message: string,
|
|
94
|
+
options?: ErrorReportOptions,
|
|
95
|
+
): Promise<ErrorReportResult>;
|
|
96
|
+
setUser(user: ErrorReportUser | null): MaybePromise<void>;
|
|
97
|
+
setTags(tags: ErrorReportTags): MaybePromise<void>;
|
|
98
|
+
setContext(
|
|
99
|
+
name: string,
|
|
100
|
+
context: ErrorReportContext | null,
|
|
101
|
+
): MaybePromise<void>;
|
|
102
|
+
flush(options?: ErrorReporterFlushOptions): Promise<boolean>;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Captured exception stored by `createMemoryErrorReporter(...)`.
|
|
107
|
+
*/
|
|
108
|
+
export type MemoryReportedException = {
|
|
109
|
+
type: "exception";
|
|
110
|
+
error: unknown;
|
|
111
|
+
options?: ErrorReportOptions;
|
|
112
|
+
id: string;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Captured message stored by `createMemoryErrorReporter(...)`.
|
|
117
|
+
*/
|
|
118
|
+
export type MemoryReportedMessage = {
|
|
119
|
+
type: "message";
|
|
120
|
+
message: string;
|
|
121
|
+
options?: ErrorReportOptions;
|
|
122
|
+
id: string;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Captured report stored by `createMemoryErrorReporter(...)`.
|
|
127
|
+
*/
|
|
128
|
+
export type MemoryErrorReport = MemoryReportedException | MemoryReportedMessage;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* In-memory reporter state exposed for tests.
|
|
132
|
+
*/
|
|
133
|
+
export type MemoryErrorReporterPort = ErrorReporterPort & {
|
|
134
|
+
reports: MemoryErrorReport[];
|
|
135
|
+
user: ErrorReportUser | null;
|
|
136
|
+
tags: ErrorReportTags;
|
|
137
|
+
contexts: Map<string, ErrorReportContext>;
|
|
138
|
+
reset(): void;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Options accepted by `createMemoryErrorReporter(...)`.
|
|
143
|
+
*/
|
|
144
|
+
export type CreateMemoryErrorReporterOptions = {
|
|
145
|
+
onCapture?: (report: MemoryErrorReport) => MaybePromise<void>;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Create a no-op reporter for apps that want to bind the port without sending
|
|
150
|
+
* events.
|
|
151
|
+
*/
|
|
152
|
+
export function createNoopErrorReporter(): ErrorReporterPort {
|
|
153
|
+
return {
|
|
154
|
+
async captureException() {
|
|
155
|
+
return {};
|
|
156
|
+
},
|
|
157
|
+
async captureMessage() {
|
|
158
|
+
return {};
|
|
159
|
+
},
|
|
160
|
+
setUser() {},
|
|
161
|
+
setTags() {},
|
|
162
|
+
setContext() {},
|
|
163
|
+
async flush() {
|
|
164
|
+
return true;
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Create an in-memory reporter for tests and local assertions.
|
|
171
|
+
*/
|
|
172
|
+
export function createMemoryErrorReporter(
|
|
173
|
+
options: CreateMemoryErrorReporterOptions = {},
|
|
174
|
+
): MemoryErrorReporterPort {
|
|
175
|
+
let nextId = 1;
|
|
176
|
+
const reports: MemoryErrorReport[] = [];
|
|
177
|
+
const contexts = new Map<string, ErrorReportContext>();
|
|
178
|
+
const port: MemoryErrorReporterPort = {
|
|
179
|
+
reports,
|
|
180
|
+
user: null,
|
|
181
|
+
tags: {},
|
|
182
|
+
contexts,
|
|
183
|
+
async captureException(error, reportOptions) {
|
|
184
|
+
const report: MemoryReportedException = {
|
|
185
|
+
type: "exception",
|
|
186
|
+
error,
|
|
187
|
+
options: withAmbientState(port, reportOptions),
|
|
188
|
+
id: String(nextId++),
|
|
189
|
+
};
|
|
190
|
+
reports.push(report);
|
|
191
|
+
await options.onCapture?.(report);
|
|
192
|
+
return { id: report.id };
|
|
193
|
+
},
|
|
194
|
+
async captureMessage(message, reportOptions) {
|
|
195
|
+
const report: MemoryReportedMessage = {
|
|
196
|
+
type: "message",
|
|
197
|
+
message,
|
|
198
|
+
options: withAmbientState(port, reportOptions),
|
|
199
|
+
id: String(nextId++),
|
|
200
|
+
};
|
|
201
|
+
reports.push(report);
|
|
202
|
+
await options.onCapture?.(report);
|
|
203
|
+
return { id: report.id };
|
|
204
|
+
},
|
|
205
|
+
setUser(user) {
|
|
206
|
+
port.user = user;
|
|
207
|
+
},
|
|
208
|
+
setTags(tags) {
|
|
209
|
+
port.tags = { ...port.tags, ...tags };
|
|
210
|
+
},
|
|
211
|
+
setContext(name, context) {
|
|
212
|
+
if (context === null) {
|
|
213
|
+
contexts.delete(name);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
contexts.set(name, context);
|
|
217
|
+
},
|
|
218
|
+
async flush() {
|
|
219
|
+
return true;
|
|
220
|
+
},
|
|
221
|
+
reset() {
|
|
222
|
+
reports.length = 0;
|
|
223
|
+
contexts.clear();
|
|
224
|
+
port.user = null;
|
|
225
|
+
port.tags = {};
|
|
226
|
+
nextId = 1;
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
return port;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Report an exception through any `ErrorReporterPort`.
|
|
235
|
+
*/
|
|
236
|
+
export function reportException(
|
|
237
|
+
reporter: ErrorReporterPort,
|
|
238
|
+
error: unknown,
|
|
239
|
+
options?: ErrorReportOptions,
|
|
240
|
+
): Promise<ErrorReportResult> {
|
|
241
|
+
return reporter.captureException(error, options);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Report a message through any `ErrorReporterPort`.
|
|
246
|
+
*/
|
|
247
|
+
export function reportMessage(
|
|
248
|
+
reporter: ErrorReporterPort,
|
|
249
|
+
message: string,
|
|
250
|
+
options?: ErrorReportOptions,
|
|
251
|
+
): Promise<ErrorReportResult> {
|
|
252
|
+
return reporter.captureMessage(message, options);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function withAmbientState(
|
|
256
|
+
port: MemoryErrorReporterPort,
|
|
257
|
+
options: ErrorReportOptions | undefined,
|
|
258
|
+
): ErrorReportOptions | undefined {
|
|
259
|
+
const contexts =
|
|
260
|
+
port.contexts.size > 0 ? Object.fromEntries(port.contexts) : undefined;
|
|
261
|
+
const hasTags = Object.keys(port.tags).length > 0;
|
|
262
|
+
if (!port.user && !hasTags && !contexts) return options;
|
|
263
|
+
|
|
264
|
+
return {
|
|
265
|
+
...options,
|
|
266
|
+
user: options?.user ?? port.user ?? undefined,
|
|
267
|
+
tags: hasTags ? { ...port.tags, ...options?.tags } : options?.tags,
|
|
268
|
+
contexts:
|
|
269
|
+
contexts || options?.contexts
|
|
270
|
+
? { ...contexts, ...options?.contexts }
|
|
271
|
+
: undefined,
|
|
272
|
+
};
|
|
273
|
+
}
|