@traffic-twin/sdk 0.0.0-stage → 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 +202 -0
- package/README.md +171 -2
- package/dist/cjs/agent.d.ts +143 -0
- package/dist/cjs/agent.js +927 -0
- package/dist/cjs/capture/body.d.ts +11 -0
- package/dist/cjs/capture/body.js +73 -0
- package/dist/cjs/capture/common.d.ts +75 -0
- package/dist/cjs/capture/common.js +180 -0
- package/dist/cjs/capture/context.d.ts +28 -0
- package/dist/cjs/capture/context.js +92 -0
- package/dist/cjs/capture/inbound.d.ts +12 -0
- package/dist/cjs/capture/inbound.js +195 -0
- package/dist/cjs/capture/outbound-http.d.ts +4 -0
- package/dist/cjs/capture/outbound-http.js +200 -0
- package/dist/cjs/capture/outbound-undici.d.ts +2 -0
- package/dist/cjs/capture/outbound-undici.js +242 -0
- package/dist/cjs/capture/wire.d.ts +27 -0
- package/dist/cjs/capture/wire.js +68 -0
- package/dist/cjs/export/event.d.ts +46 -0
- package/dist/cjs/export/event.js +91 -0
- package/dist/cjs/export/exporter.d.ts +50 -0
- package/dist/cjs/export/exporter.js +192 -0
- package/dist/cjs/export/pipeline.d.ts +20 -0
- package/dist/cjs/export/pipeline.js +40 -0
- package/dist/cjs/fleet/asn1.d.ts +44 -0
- package/dist/cjs/fleet/asn1.js +150 -0
- package/dist/cjs/fleet/client.d.ts +84 -0
- package/dist/cjs/fleet/client.js +216 -0
- package/dist/cjs/fleet/http.d.ts +17 -0
- package/dist/cjs/fleet/http.js +80 -0
- package/dist/cjs/fleet/store.d.ts +18 -0
- package/dist/cjs/fleet/store.js +115 -0
- package/dist/cjs/index.d.ts +14 -0
- package/dist/cjs/index.js +69 -0
- package/dist/cjs/log.d.ts +4 -0
- package/dist/cjs/log.js +30 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/register.d.ts +1 -0
- package/dist/cjs/register.js +18 -0
- package/dist/cjs/sanitizer/bodies.d.ts +55 -0
- package/dist/cjs/sanitizer/bodies.js +710 -0
- package/dist/cjs/sanitizer/formats.d.ts +26 -0
- package/dist/cjs/sanitizer/formats.js +110 -0
- package/dist/cjs/sanitizer/graphql.d.ts +23 -0
- package/dist/cjs/sanitizer/graphql.js +478 -0
- package/dist/cjs/sanitizer/hostpat.d.ts +15 -0
- package/dist/cjs/sanitizer/hostpat.js +129 -0
- package/dist/cjs/sanitizer/json.d.ts +60 -0
- package/dist/cjs/sanitizer/json.js +460 -0
- package/dist/cjs/sanitizer/policy.d.ts +224 -0
- package/dist/cjs/sanitizer/policy.js +820 -0
- package/dist/cjs/sanitizer/sanitizer.d.ts +149 -0
- package/dist/cjs/sanitizer/sanitizer.js +1473 -0
- package/dist/cjs/sanitizer/utf8.d.ts +22 -0
- package/dist/cjs/sanitizer/utf8.js +180 -0
- package/dist/cjs/sanitizer/vectors.d.ts +22 -0
- package/dist/cjs/sanitizer/vectors.js +130 -0
- package/dist/cjs/version.d.ts +2 -0
- package/dist/cjs/version.js +5 -0
- package/dist/cjs/worker/dir.d.ts +1 -0
- package/dist/cjs/worker/dir.js +8 -0
- package/dist/cjs/worker/pool.d.ts +47 -0
- package/dist/cjs/worker/pool.js +179 -0
- package/dist/cjs/worker/protocol.d.ts +37 -0
- package/dist/cjs/worker/protocol.js +3 -0
- package/dist/cjs/worker/sanitizer-worker.d.ts +1 -0
- package/dist/cjs/worker/sanitizer-worker.js +53 -0
- package/dist/esm/agent.d.ts +143 -0
- package/dist/esm/agent.js +921 -0
- package/dist/esm/capture/body.d.ts +11 -0
- package/dist/esm/capture/body.js +69 -0
- package/dist/esm/capture/common.d.ts +75 -0
- package/dist/esm/capture/common.js +166 -0
- package/dist/esm/capture/context.d.ts +28 -0
- package/dist/esm/capture/context.js +84 -0
- package/dist/esm/capture/inbound.d.ts +12 -0
- package/dist/esm/capture/inbound.js +187 -0
- package/dist/esm/capture/outbound-http.d.ts +4 -0
- package/dist/esm/capture/outbound-http.js +193 -0
- package/dist/esm/capture/outbound-undici.d.ts +2 -0
- package/dist/esm/capture/outbound-undici.js +236 -0
- package/dist/esm/capture/wire.d.ts +27 -0
- package/dist/esm/capture/wire.js +65 -0
- package/dist/esm/export/event.d.ts +46 -0
- package/dist/esm/export/event.js +85 -0
- package/dist/esm/export/exporter.d.ts +50 -0
- package/dist/esm/export/exporter.js +188 -0
- package/dist/esm/export/pipeline.d.ts +20 -0
- package/dist/esm/export/pipeline.js +37 -0
- package/dist/esm/fleet/asn1.d.ts +44 -0
- package/dist/esm/fleet/asn1.js +128 -0
- package/dist/esm/fleet/client.d.ts +84 -0
- package/dist/esm/fleet/client.js +204 -0
- package/dist/esm/fleet/http.d.ts +17 -0
- package/dist/esm/fleet/http.js +73 -0
- package/dist/esm/fleet/store.d.ts +18 -0
- package/dist/esm/fleet/store.js +110 -0
- package/dist/esm/index.d.ts +14 -0
- package/dist/esm/index.js +48 -0
- package/dist/esm/log.d.ts +4 -0
- package/dist/esm/log.js +25 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/register.d.ts +1 -0
- package/dist/esm/register.js +16 -0
- package/dist/esm/sanitizer/bodies.d.ts +55 -0
- package/dist/esm/sanitizer/bodies.js +694 -0
- package/dist/esm/sanitizer/formats.d.ts +26 -0
- package/dist/esm/sanitizer/formats.js +101 -0
- package/dist/esm/sanitizer/graphql.d.ts +23 -0
- package/dist/esm/sanitizer/graphql.js +472 -0
- package/dist/esm/sanitizer/hostpat.d.ts +15 -0
- package/dist/esm/sanitizer/hostpat.js +122 -0
- package/dist/esm/sanitizer/json.d.ts +60 -0
- package/dist/esm/sanitizer/json.js +447 -0
- package/dist/esm/sanitizer/policy.d.ts +224 -0
- package/dist/esm/sanitizer/policy.js +800 -0
- package/dist/esm/sanitizer/sanitizer.d.ts +149 -0
- package/dist/esm/sanitizer/sanitizer.js +1459 -0
- package/dist/esm/sanitizer/utf8.d.ts +22 -0
- package/dist/esm/sanitizer/utf8.js +166 -0
- package/dist/esm/sanitizer/vectors.d.ts +22 -0
- package/dist/esm/sanitizer/vectors.js +125 -0
- package/dist/esm/version.d.ts +2 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/worker/dir.d.ts +1 -0
- package/dist/esm/worker/dir.js +5 -0
- package/dist/esm/worker/pool.d.ts +47 -0
- package/dist/esm/worker/pool.js +175 -0
- package/dist/esm/worker/protocol.d.ts +37 -0
- package/dist/esm/worker/protocol.js +2 -0
- package/dist/esm/worker/sanitizer-worker.d.ts +1 -0
- package/dist/esm/worker/sanitizer-worker.js +51 -0
- package/package.json +75 -4
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { type OMap } from './json.js';
|
|
2
|
+
import { type Action, type Policy, type TemplateSeg } from './policy.js';
|
|
3
|
+
export type NetError = 'timeout' | 'reset' | 'refused' | 'dns' | 'tls' | 'other';
|
|
4
|
+
export type SampledBy = 'baggage' | 'subject' | 'trace' | 'random' | 'inherited';
|
|
5
|
+
/** Normalized exchange (sanitizer.md 1). */
|
|
6
|
+
export interface Exchange {
|
|
7
|
+
dir: 'inbound' | 'outbound';
|
|
8
|
+
service_name?: string;
|
|
9
|
+
url_base?: string;
|
|
10
|
+
method: string;
|
|
11
|
+
raw_path: Buffer;
|
|
12
|
+
/** undefined/null = the URL had no "?". */
|
|
13
|
+
raw_query?: Buffer | null;
|
|
14
|
+
/** A-FRAMEWORK-ID: identifier of the 3.4 table; required with framework_route. */
|
|
15
|
+
framework?: string;
|
|
16
|
+
framework_route?: string;
|
|
17
|
+
trace_id?: string;
|
|
18
|
+
inherited?: boolean;
|
|
19
|
+
req_headers: Array<[string, Buffer]>;
|
|
20
|
+
req_body?: Buffer;
|
|
21
|
+
req_body_total?: number | 'unknown';
|
|
22
|
+
req_body_consumed?: boolean;
|
|
23
|
+
req_body_decoded?: boolean;
|
|
24
|
+
status?: number;
|
|
25
|
+
net_error?: NetError;
|
|
26
|
+
resp_headers?: Array<[string, Buffer]>;
|
|
27
|
+
resp_body?: Buffer;
|
|
28
|
+
resp_body_total?: number | 'unknown';
|
|
29
|
+
resp_body_consumed?: boolean;
|
|
30
|
+
resp_body_decoded?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface Decision {
|
|
33
|
+
sampled: boolean;
|
|
34
|
+
by: SampledBy;
|
|
35
|
+
}
|
|
36
|
+
export type Result = {
|
|
37
|
+
outcome: 'event';
|
|
38
|
+
out: OMap;
|
|
39
|
+
parts: Map<string, string>;
|
|
40
|
+
canonical: string;
|
|
41
|
+
sampledBy: SampledBy;
|
|
42
|
+
} | {
|
|
43
|
+
outcome: 'not_sampled';
|
|
44
|
+
sampledBy: SampledBy;
|
|
45
|
+
}
|
|
46
|
+
/** 10.3 step 4: no event; the source counts it in `sanitizer_errors`. */
|
|
47
|
+
| {
|
|
48
|
+
outcome: 'too_large';
|
|
49
|
+
sampledBy: SampledBy;
|
|
50
|
+
};
|
|
51
|
+
export declare const MAX_EVENT_BYTES = 524288;
|
|
52
|
+
interface HdrEntry {
|
|
53
|
+
out: string;
|
|
54
|
+
values: Buffer[];
|
|
55
|
+
origs: Set<string>;
|
|
56
|
+
}
|
|
57
|
+
interface Headers {
|
|
58
|
+
order: string[];
|
|
59
|
+
map: Map<string, HdrEntry>;
|
|
60
|
+
}
|
|
61
|
+
/** `token`: a ready output token (multipart file part, sanitizer.md 22.3); the value is then not read. */
|
|
62
|
+
interface NamedEntry {
|
|
63
|
+
orig: string | null;
|
|
64
|
+
out: string;
|
|
65
|
+
value: Buffer;
|
|
66
|
+
noEq: boolean;
|
|
67
|
+
token?: string;
|
|
68
|
+
}
|
|
69
|
+
export declare function normalizeHeaders(list: Array<[string, Buffer]> | undefined): Headers;
|
|
70
|
+
/** 8.1.5: `ct` from the normalized content-type value; undefined without the header. */
|
|
71
|
+
export declare function contentType(h: Headers): string | undefined;
|
|
72
|
+
interface Seg {
|
|
73
|
+
dec: string | null;
|
|
74
|
+
}
|
|
75
|
+
export declare function decomposePath(raw: Buffer): {
|
|
76
|
+
segs: Seg[];
|
|
77
|
+
truncated: boolean;
|
|
78
|
+
};
|
|
79
|
+
interface UrlBase {
|
|
80
|
+
invalid: boolean;
|
|
81
|
+
origin: string;
|
|
82
|
+
hostport: string;
|
|
83
|
+
/** Normalized host without port (an IPv6 literal keeps its lowercase text, without brackets). */
|
|
84
|
+
host: string;
|
|
85
|
+
/** Normalized port; null when absent or the scheme default. */
|
|
86
|
+
port: string | null;
|
|
87
|
+
/** The 16 bytes of a bracketed IPv6 literal (3.1 point 5, spec v1.5), else null. */
|
|
88
|
+
ip6: Uint8Array | null;
|
|
89
|
+
}
|
|
90
|
+
/** 3.1 normalization of `url_base`. */
|
|
91
|
+
export declare function normalizeUrlBase(u: string | undefined): UrlBase;
|
|
92
|
+
export declare const FRAMEWORKS: ReadonlySet<string>;
|
|
93
|
+
/**
|
|
94
|
+
* 3.4 with A-FRAMEWORK-ID (normative since 1.1.1): normalizes `route` with the table of
|
|
95
|
+
* `framework`. Every segment must be a parameter syntax of that framework or a literal of
|
|
96
|
+
* the operation-key grammar; anything else (every "not normalizable" case) fails.
|
|
97
|
+
*/
|
|
98
|
+
export declare function normalizeFrameworkRoute(route: string, framework: string): TemplateSeg[] | null;
|
|
99
|
+
export declare function bucketTime(s: string, unit: string): string | null;
|
|
100
|
+
export declare function bucketNum(lex: string, a: Action): string;
|
|
101
|
+
export interface KeyRef {
|
|
102
|
+
kid: string;
|
|
103
|
+
key: Buffer;
|
|
104
|
+
}
|
|
105
|
+
export declare class Sanitizer {
|
|
106
|
+
readonly policy: Policy;
|
|
107
|
+
readonly key: KeyRef;
|
|
108
|
+
readonly options: {
|
|
109
|
+
rand?: () => number;
|
|
110
|
+
rateOverrideBp?: number | null;
|
|
111
|
+
};
|
|
112
|
+
private readonly epochBuf;
|
|
113
|
+
constructor(policy: Policy, key: KeyRef, options?: {
|
|
114
|
+
rand?: () => number;
|
|
115
|
+
rateOverrideBp?: number | null;
|
|
116
|
+
});
|
|
117
|
+
mac(domain: string, value: Buffer): Buffer;
|
|
118
|
+
token(domain: string, value: Buffer): string;
|
|
119
|
+
rateBp(): number;
|
|
120
|
+
subjectValue(reqHeaders: Array<[string, Buffer]> | undefined): Buffer | null;
|
|
121
|
+
private hashSample;
|
|
122
|
+
private randomSample;
|
|
123
|
+
private readonly subjName;
|
|
124
|
+
/** Subject header value (as received) -> 1 sampled, 2 not sampled, 3 no usable subject. Per policy and key, bounded. */
|
|
125
|
+
private readonly subjCache;
|
|
126
|
+
/**
|
|
127
|
+
* Inbound decision straight from node's rawHeaders (flat latin1 strings) and the
|
|
128
|
+
* traceparent trace id, with no per-request allocation on the common paths. It returns the
|
|
129
|
+
* same decision as `decide()` on the same headers, or null when it cannot answer fast
|
|
130
|
+
* (baggage trusted, repeated subject header): the caller then uses `decide()`.
|
|
131
|
+
* The subject answer is remembered per header value: the HMAC and the parsing run once per
|
|
132
|
+
* distinct value (a user's cookie or token repeats on every request).
|
|
133
|
+
*/
|
|
134
|
+
decideRaw(service: string, raw: readonly string[], traceId: string | undefined): Decision | null;
|
|
135
|
+
/** Sampling decision for an exchange (needs only the request line and headers). */
|
|
136
|
+
decide(ex: Pick<Exchange, 'dir' | 'service_name' | 'req_headers' | 'trace_id' | 'inherited'>, subject?: Buffer | null): Decision;
|
|
137
|
+
run(ex: Exchange, now: number | undefined, decision?: Decision): Result;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* 9.0 decoding, one level, with an output cap (A-GZIP-STRICT): returns the decoded bytes,
|
|
141
|
+
* 'cap' when the output reaches `cap` bytes, or null on any error (truncated stream,
|
|
142
|
+
* bytes after the end of the stream, corrupt data).
|
|
143
|
+
*/
|
|
144
|
+
export declare function decodeBody(data: Buffer, zlibFormat: boolean, cap: number): Buffer | 'cap' | null;
|
|
145
|
+
/** tt-cjson object from already serialized members (keys sorted by bytes). */
|
|
146
|
+
export declare function composeCanonical(parts: Map<string, string>): string;
|
|
147
|
+
/** 8.3 / 9.1: query string or form body into named entries. */
|
|
148
|
+
export declare function parseUrlencoded(raw: Buffer): NamedEntry[];
|
|
149
|
+
export {};
|