@birtalanrobert/context 0.1.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 +661 -0
- package/NOTICE +45 -0
- package/README.md +3 -0
- package/dist/context.d.ts +67 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +166 -0
- package/dist/context.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +48 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +39 -0
- package/src/context.ts +179 -0
- package/src/index.ts +22 -0
- package/src/types.ts +49 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ambient facts about the work currently in flight.
|
|
3
|
+
*
|
|
4
|
+
* Carried through AsyncLocalStorage rather than threaded through every
|
|
5
|
+
* function signature, because these values are needed by logging, auditing,
|
|
6
|
+
* tenant scoping and error reporting — layers that should not force every
|
|
7
|
+
* intermediate function to know about them.
|
|
8
|
+
*/
|
|
9
|
+
export interface RequestContext {
|
|
10
|
+
/** Unique per inbound request or job execution. */
|
|
11
|
+
readonly requestId: string;
|
|
12
|
+
/**
|
|
13
|
+
* Correlates work across service boundaries and background jobs. Inherited
|
|
14
|
+
* from an incoming header where present, otherwise equal to requestId.
|
|
15
|
+
*/
|
|
16
|
+
readonly correlationId: string;
|
|
17
|
+
/** The tenant this work belongs to, once resolved. */
|
|
18
|
+
tenantId?: string;
|
|
19
|
+
/** The authenticated principal, once resolved. */
|
|
20
|
+
actor?: Actor;
|
|
21
|
+
/** Resolved locale, e.g. 'ro-RO'. */
|
|
22
|
+
locale?: string;
|
|
23
|
+
/** Client address, for audit and rate limiting. */
|
|
24
|
+
ip?: string;
|
|
25
|
+
/** Client user agent, for audit. */
|
|
26
|
+
userAgent?: string;
|
|
27
|
+
/** Where this unit of work came from. */
|
|
28
|
+
readonly source: ContextSource;
|
|
29
|
+
/** When the unit of work started, for duration measurement. */
|
|
30
|
+
readonly startedAt: number;
|
|
31
|
+
/** Free-form values attached by application code. */
|
|
32
|
+
readonly attributes: Map<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type ContextSource = 'http' | 'job' | 'cli' | 'test' | 'internal';
|
|
36
|
+
|
|
37
|
+
export interface Actor {
|
|
38
|
+
readonly id: string;
|
|
39
|
+
/**
|
|
40
|
+
* `user` is a human with an account; `client` is a link-authenticated party
|
|
41
|
+
* with no account (a guest, a candidate, a tenant of a landlord); `system`
|
|
42
|
+
* is scheduled or internal work; `service` is a machine credential.
|
|
43
|
+
*/
|
|
44
|
+
readonly type: 'user' | 'client' | 'system' | 'service';
|
|
45
|
+
readonly displayName?: string;
|
|
46
|
+
readonly roles?: readonly string[];
|
|
47
|
+
/** Set when an operator is impersonating; the audit trail records both. */
|
|
48
|
+
readonly impersonatedBy?: string;
|
|
49
|
+
}
|