@numbunch/node 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/dist/client.d.ts +122 -0
- package/dist/client.js +395 -0
- package/dist/client.js.map +1 -0
- package/dist/context.d.ts +60 -0
- package/dist/context.js +109 -0
- package/dist/context.js.map +1 -0
- package/dist/evaluate.d.ts +75 -0
- package/dist/evaluate.js +107 -0
- package/dist/evaluate.js.map +1 -0
- package/dist/exceptions.d.ts +25 -0
- package/dist/exceptions.js +79 -0
- package/dist/exceptions.js.map +1 -0
- package/dist/express.d.ts +16 -0
- package/dist/express.js +26 -0
- package/dist/express.js.map +1 -0
- package/dist/fastify.d.ts +22 -0
- package/dist/fastify.js +28 -0
- package/dist/fastify.js.map +1 -0
- package/dist/hash.d.ts +18 -0
- package/dist/hash.js +79 -0
- package/dist/hash.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/matching.d.ts +21 -0
- package/dist/matching.js +196 -0
- package/dist/matching.js.map +1 -0
- package/dist/uuid.d.ts +2 -0
- package/dist/uuid.js +15 -0
- package/dist/uuid.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/package.json +60 -3
- package/README.md +0 -3
package/dist/context.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Request context and OpenTelemetry integration.
|
|
2
|
+
//
|
|
3
|
+
// - The Numbunch browser SDK sends the W3C `baggage` header with `session.id` and `user.id` on calls to its own
|
|
4
|
+
// origins. `requestContext` reads them; `withRequestContext` makes them the default `$session_id` (and distinct ID)
|
|
5
|
+
// of events captured while handling the request, and, when `@opentelemetry/api` is installed, puts them on the
|
|
6
|
+
// active span and in the active context's baggage so downstream spans and logs carry the user and session.
|
|
7
|
+
// - Captured events get `$trace_id` and `$span_id` from the active span.
|
|
8
|
+
//
|
|
9
|
+
// `@opentelemetry/api` is an optional peer dependency, loaded once and lazily; everything works without it.
|
|
10
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
11
|
+
let otel;
|
|
12
|
+
let otelLoading;
|
|
13
|
+
/** Loads `@opentelemetry/api` once if it is installed. Resolves to undefined otherwise. */
|
|
14
|
+
export function loadOtel() {
|
|
15
|
+
otelLoading ??= import('@opentelemetry/api')
|
|
16
|
+
.then((api) => {
|
|
17
|
+
const resolved = (api.trace ? api : api.default);
|
|
18
|
+
otel ??= resolved;
|
|
19
|
+
return otel;
|
|
20
|
+
})
|
|
21
|
+
.catch(() => undefined);
|
|
22
|
+
return otelLoading;
|
|
23
|
+
}
|
|
24
|
+
/** Uses an explicitly passed `@opentelemetry/api` instead of the lazily imported one. */
|
|
25
|
+
export function useOtel(api) {
|
|
26
|
+
otel = api;
|
|
27
|
+
}
|
|
28
|
+
const INVALID_TRACE = '00000000000000000000000000000000';
|
|
29
|
+
const INVALID_SPAN = '0000000000000000';
|
|
30
|
+
/** `$trace_id` and `$span_id` of the active span, if OpenTelemetry is loaded and a valid span is active. */
|
|
31
|
+
export function activeTrace() {
|
|
32
|
+
const span = otel?.trace.getActiveSpan();
|
|
33
|
+
if (!span)
|
|
34
|
+
return undefined;
|
|
35
|
+
const { traceId, spanId } = span.spanContext();
|
|
36
|
+
if (!/^[0-9a-f]{32}$/.test(traceId) || traceId === INVALID_TRACE || spanId === INVALID_SPAN)
|
|
37
|
+
return undefined;
|
|
38
|
+
return { traceId, spanId };
|
|
39
|
+
}
|
|
40
|
+
function header(headers, name) {
|
|
41
|
+
if (typeof headers.get === 'function') {
|
|
42
|
+
return headers.get(name) ?? undefined;
|
|
43
|
+
}
|
|
44
|
+
const record = headers;
|
|
45
|
+
const value = record[name] ?? record[Object.keys(record).find((k) => k.toLowerCase() === name) ?? ''];
|
|
46
|
+
return Array.isArray(value) ? value.join(',') : value;
|
|
47
|
+
}
|
|
48
|
+
/** Parses a W3C `baggage` header into its entries (values percent-decoded, properties dropped). */
|
|
49
|
+
export function parseBaggage(value) {
|
|
50
|
+
const out = {};
|
|
51
|
+
for (const member of (value ?? '').split(',')) {
|
|
52
|
+
const [pair] = member.split(';');
|
|
53
|
+
const eq = pair?.indexOf('=') ?? -1;
|
|
54
|
+
if (!pair || eq <= 0)
|
|
55
|
+
continue;
|
|
56
|
+
const key = pair.slice(0, eq).trim();
|
|
57
|
+
if (!key)
|
|
58
|
+
continue;
|
|
59
|
+
try {
|
|
60
|
+
out[key] = decodeURIComponent(pair.slice(eq + 1).trim());
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
out[key] = pair.slice(eq + 1).trim();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
/** The session and distinct ID the browser SDK put in the request's `baggage` header. */
|
|
69
|
+
export function requestContext(headers) {
|
|
70
|
+
const baggage = parseBaggage(header(headers, 'baggage'));
|
|
71
|
+
const out = {};
|
|
72
|
+
if (baggage['session.id'])
|
|
73
|
+
out.sessionId = baggage['session.id'];
|
|
74
|
+
if (baggage['user.id'])
|
|
75
|
+
out.distinctId = baggage['user.id'];
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
const storage = new AsyncLocalStorage();
|
|
79
|
+
/** The request context of the current async context, if inside `withRequestContext`. */
|
|
80
|
+
export function currentRequestContext() {
|
|
81
|
+
return storage.getStore();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Runs `fn` with the request's session and distinct ID as the defaults for captured events. With OpenTelemetry, also
|
|
85
|
+
* sets `session.id`/`user.id` on the active span and in the baggage of the context `fn` runs in.
|
|
86
|
+
*/
|
|
87
|
+
export function withRequestContext(headers, fn) {
|
|
88
|
+
const ctx = isRequestContext(headers) ? headers : requestContext(headers);
|
|
89
|
+
const run = () => storage.run(ctx, fn);
|
|
90
|
+
if (!otel || (!ctx.sessionId && !ctx.distinctId))
|
|
91
|
+
return run();
|
|
92
|
+
const span = otel.trace.getActiveSpan();
|
|
93
|
+
const active = otel.context.active();
|
|
94
|
+
let baggage = otel.propagation.getBaggage(active) ?? otel.propagation.createBaggage();
|
|
95
|
+
if (ctx.sessionId) {
|
|
96
|
+
span?.setAttribute('session.id', ctx.sessionId);
|
|
97
|
+
baggage = baggage.setEntry('session.id', { value: ctx.sessionId });
|
|
98
|
+
}
|
|
99
|
+
if (ctx.distinctId) {
|
|
100
|
+
span?.setAttribute('user.id', ctx.distinctId);
|
|
101
|
+
baggage = baggage.setEntry('user.id', { value: ctx.distinctId });
|
|
102
|
+
}
|
|
103
|
+
return otel.context.with(otel.propagation.setBaggage(active, baggage), run);
|
|
104
|
+
}
|
|
105
|
+
function isRequestContext(value) {
|
|
106
|
+
const keys = Object.keys(value);
|
|
107
|
+
return typeof value.get !== 'function' && keys.every((k) => k === 'sessionId' || k === 'distinctId');
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,EAAE;AACF,gHAAgH;AAChH,sHAAsH;AACtH,iHAAiH;AACjH,6GAA6G;AAC7G,yEAAyE;AACzE,EAAE;AACF,4GAA4G;AAE5G,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AA2BpD,IAAI,IAAyB,CAAA;AAC7B,IAAI,WAAqD,CAAA;AAEzD,2FAA2F;AAC3F,MAAM,UAAU,QAAQ;IACtB,WAAW,KAAK,MAAM,CAAC,oBAA8B,CAAC;SACnD,IAAI,CAAC,CAAC,GAA6C,EAAE,EAAE;QACtD,MAAM,QAAQ,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAwB,CAAA;QACvE,IAAI,KAAK,QAAQ,CAAA;QACjB,OAAO,IAAI,CAA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,CAAC,SAAS,EAAE,GAAG,CAAC,UAAU,CAAC,CAAA;QAC7C,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,UAAU,EAAE,CAAC,CAAA;IAClE,CAAC;IACD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,CAAA;AAC7E,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAmC;IAC3D,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC/B,OAAO,OAAQ,KAA2B,CAAC,GAAG,KAAK,UAAU,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,WAAW,IAAI,CAAC,KAAK,YAAY,CAAC,CAAA;AAC7H,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { type Bucketing } from './hash.js';
|
|
2
|
+
import { type Properties, type PropertyFilter } from './matching.js';
|
|
3
|
+
export interface ConditionSet {
|
|
4
|
+
properties?: PropertyFilter[];
|
|
5
|
+
/** 0–100; null means 100. */
|
|
6
|
+
rollout_percentage?: number | null;
|
|
7
|
+
/** Pins matching users to this variant. */
|
|
8
|
+
variant?: string | null;
|
|
9
|
+
}
|
|
10
|
+
export interface Variant {
|
|
11
|
+
key: string;
|
|
12
|
+
name?: string;
|
|
13
|
+
rollout_percentage: number;
|
|
14
|
+
}
|
|
15
|
+
export interface FlagFilters {
|
|
16
|
+
aggregation_group_type_index?: number | null;
|
|
17
|
+
groups?: ConditionSet[];
|
|
18
|
+
multivariate?: {
|
|
19
|
+
variants: Variant[];
|
|
20
|
+
} | null;
|
|
21
|
+
payloads?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
/** One flag of `GET /v1/flags/definitions`. */
|
|
24
|
+
export interface FlagDefinition {
|
|
25
|
+
id?: number;
|
|
26
|
+
key: string;
|
|
27
|
+
version?: number;
|
|
28
|
+
active: boolean;
|
|
29
|
+
bucketing: Bucketing;
|
|
30
|
+
filters: FlagFilters;
|
|
31
|
+
holdout?: {
|
|
32
|
+
id: number;
|
|
33
|
+
percentage: number;
|
|
34
|
+
} | null;
|
|
35
|
+
ensure_continuity?: boolean;
|
|
36
|
+
client_evaluable?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** The body of `GET /v1/flags/definitions`. */
|
|
39
|
+
export interface Definitions {
|
|
40
|
+
flags: FlagDefinition[];
|
|
41
|
+
group_type_mapping?: Record<string, string>;
|
|
42
|
+
}
|
|
43
|
+
export type FlagValue = string | boolean;
|
|
44
|
+
/** Evaluates `flag` for `bucketingId` against supplied properties. Throws `InconclusiveMatchError`. */
|
|
45
|
+
export declare function evaluateFlag(flag: FlagDefinition, bucketingId: string, properties: Properties, now?: Date): FlagValue;
|
|
46
|
+
/** The group a group flag is evaluated for, as on the server (`group_subject`). */
|
|
47
|
+
export type GroupSubject = {
|
|
48
|
+
kind: 'group';
|
|
49
|
+
key: string;
|
|
50
|
+
properties: Properties;
|
|
51
|
+
}
|
|
52
|
+
/** The flag's group type is unknown: only the server can decide. */
|
|
53
|
+
| {
|
|
54
|
+
kind: 'unknown_type';
|
|
55
|
+
}
|
|
56
|
+
/** The call names no group of the flag's type: the flag is off. */
|
|
57
|
+
| {
|
|
58
|
+
kind: 'no_group';
|
|
59
|
+
};
|
|
60
|
+
export declare function groupSubject(flag: FlagDefinition, groupTypeMapping: Record<string, string>, groups: Record<string, string | number> | undefined, groupProperties: Record<string, Properties> | undefined): GroupSubject;
|
|
61
|
+
export interface LocalInput {
|
|
62
|
+
distinctId: string;
|
|
63
|
+
personProperties?: Properties;
|
|
64
|
+
groups?: Record<string, string | number>;
|
|
65
|
+
groupProperties?: Record<string, Properties>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Evaluates a flag locally the way the server would. Throws `InconclusiveMatchError` when only the server can decide:
|
|
69
|
+
* missing properties, an unknown group type, or experience continuity (which needs stored hash-key overrides).
|
|
70
|
+
*/
|
|
71
|
+
export declare function evaluateLocally(flag: FlagDefinition, groupTypeMapping: Record<string, string>, input: LocalInput, now?: Date): FlagValue;
|
|
72
|
+
/** The payload for a value (`"true"` for boolean flags, else the variant key), JSON-decoded when it is a string. */
|
|
73
|
+
export declare function payloadFor(flag: FlagDefinition, value: FlagValue): unknown;
|
|
74
|
+
/** Payloads travel as JSON-encoded strings; plain strings that are not JSON are returned as they are. */
|
|
75
|
+
export declare function decodePayload(payload: unknown): unknown;
|
package/dist/evaluate.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// Local flag evaluation, identical to crates/nb-flags/src/evaluate.rs: condition sets (pinned variants first) and
|
|
2
|
+
// rollout, then for a matching user the holdout and the variant, for both `sha1_v1` and `murmur3_v1`.
|
|
3
|
+
//
|
|
4
|
+
// Ported from posthog-node 4.11.2 `src/feature-flags.ts` (`matchFeatureFlagProperties`, `isConditionMatch`,
|
|
5
|
+
// `getMatchingVariant`), MIT, Copyright (c) PostHog Inc.
|
|
6
|
+
import { bucket, holdoutValue, pickVariant, within } from './hash.js';
|
|
7
|
+
import { InconclusiveMatchError, matchProperty } from './matching.js';
|
|
8
|
+
/** Evaluates `flag` for `bucketingId` against supplied properties. Throws `InconclusiveMatchError`. */
|
|
9
|
+
export function evaluateFlag(flag, bucketingId, properties, now = new Date()) {
|
|
10
|
+
if (!flag.active)
|
|
11
|
+
return false;
|
|
12
|
+
const scheme = flag.bucketing;
|
|
13
|
+
const groups = flag.filters.groups ?? [];
|
|
14
|
+
// Condition sets with a pinned variant first (a stable sort keeps the rest in order).
|
|
15
|
+
const ordered = [...groups].sort((a, b) => Number(a.variant == null) - Number(b.variant == null));
|
|
16
|
+
let inconclusive = false;
|
|
17
|
+
for (const condition of ordered) {
|
|
18
|
+
let matched;
|
|
19
|
+
try {
|
|
20
|
+
matched = conditionMatches(flag, condition, bucketingId, properties, now);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
if (error instanceof InconclusiveMatchError) {
|
|
24
|
+
inconclusive = true;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
if (matched) {
|
|
30
|
+
// The holdout applies only to users the flag targets.
|
|
31
|
+
if (flag.holdout && within(scheme, holdoutValue(scheme, flag.holdout.id, bucketingId), flag.holdout.percentage)) {
|
|
32
|
+
return `holdout-${flag.holdout.id}`;
|
|
33
|
+
}
|
|
34
|
+
return variantFor(flag, condition, bucketingId) ?? true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (inconclusive)
|
|
38
|
+
throw new InconclusiveMatchError(`flag ${flag.key}: properties not supplied`);
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
function conditionMatches(flag, condition, bucketingId, properties, now) {
|
|
42
|
+
for (const filter of condition.properties ?? []) {
|
|
43
|
+
if (!matchProperty(filter, properties, now))
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const rollout = condition.rollout_percentage;
|
|
47
|
+
if (rollout == null)
|
|
48
|
+
return true;
|
|
49
|
+
return within(flag.bucketing, bucket(flag.bucketing, flag.key, bucketingId, ''), rollout);
|
|
50
|
+
}
|
|
51
|
+
function variantFor(flag, condition, bucketingId) {
|
|
52
|
+
const variants = flag.filters.multivariate?.variants ?? [];
|
|
53
|
+
if (condition.variant != null && variants.some((v) => v.key === condition.variant))
|
|
54
|
+
return condition.variant;
|
|
55
|
+
if (variants.length === 0)
|
|
56
|
+
return undefined;
|
|
57
|
+
return pickVariant(bucket(flag.bucketing, flag.key, bucketingId, 'variant'), variants);
|
|
58
|
+
}
|
|
59
|
+
export function groupSubject(flag, groupTypeMapping, groups, groupProperties) {
|
|
60
|
+
const index = flag.filters.aggregation_group_type_index;
|
|
61
|
+
const name = index == null ? undefined : groupTypeMapping[String(index)];
|
|
62
|
+
if (name === undefined)
|
|
63
|
+
return { kind: 'unknown_type' };
|
|
64
|
+
const raw = groups?.[name];
|
|
65
|
+
const key = typeof raw === 'number' ? String(raw) : typeof raw === 'string' ? raw : undefined;
|
|
66
|
+
if (key === undefined)
|
|
67
|
+
return { kind: 'no_group' };
|
|
68
|
+
return { kind: 'group', key, properties: { $group_key: key, ...(groupProperties?.[name] ?? {}) } };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Evaluates a flag locally the way the server would. Throws `InconclusiveMatchError` when only the server can decide:
|
|
72
|
+
* missing properties, an unknown group type, or experience continuity (which needs stored hash-key overrides).
|
|
73
|
+
*/
|
|
74
|
+
export function evaluateLocally(flag, groupTypeMapping, input, now = new Date()) {
|
|
75
|
+
if (flag.filters.aggregation_group_type_index != null) {
|
|
76
|
+
const subject = groupSubject(flag, groupTypeMapping, input.groups, input.groupProperties);
|
|
77
|
+
if (subject.kind === 'unknown_type')
|
|
78
|
+
throw new InconclusiveMatchError(`flag ${flag.key}: unknown group type`);
|
|
79
|
+
if (subject.kind === 'no_group')
|
|
80
|
+
return false;
|
|
81
|
+
return evaluateFlag(flag, subject.key, subject.properties, now);
|
|
82
|
+
}
|
|
83
|
+
if (flag.ensure_continuity && flag.active) {
|
|
84
|
+
throw new InconclusiveMatchError(`flag ${flag.key}: experience continuity is evaluated by the server`);
|
|
85
|
+
}
|
|
86
|
+
const properties = { distinct_id: input.distinctId, ...(input.personProperties ?? {}) };
|
|
87
|
+
return evaluateFlag(flag, input.distinctId, properties, now);
|
|
88
|
+
}
|
|
89
|
+
/** The payload for a value (`"true"` for boolean flags, else the variant key), JSON-decoded when it is a string. */
|
|
90
|
+
export function payloadFor(flag, value) {
|
|
91
|
+
if (value === false)
|
|
92
|
+
return undefined;
|
|
93
|
+
const stored = flag.filters.payloads?.[value === true ? 'true' : value];
|
|
94
|
+
return stored === undefined ? undefined : decodePayload(stored);
|
|
95
|
+
}
|
|
96
|
+
/** Payloads travel as JSON-encoded strings; plain strings that are not JSON are returned as they are. */
|
|
97
|
+
export function decodePayload(payload) {
|
|
98
|
+
if (typeof payload !== 'string')
|
|
99
|
+
return payload;
|
|
100
|
+
try {
|
|
101
|
+
return JSON.parse(payload);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return payload;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=evaluate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../src/evaluate.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,sGAAsG;AACtG,EAAE;AACF,4GAA4G;AAC5G,yDAAyD;AAEzD,OAAO,EAAkB,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AACrF,OAAO,EAAE,sBAAsB,EAAE,aAAa,EAAwC,MAAM,eAAe,CAAA;AA4C3G,uGAAuG;AACvG,MAAM,UAAU,YAAY,CAAC,IAAoB,EAAE,WAAmB,EAAE,UAAsB,EAAE,MAAY,IAAI,IAAI,EAAE;IACpH,IAAI,CAAC,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAA;IAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAA;IAC7B,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAA;IACxC,sFAAsF;IACtF,MAAM,OAAO,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,IAAI,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC,CAAA;IACjG,IAAI,YAAY,GAAG,KAAK,CAAA;IACxB,KAAK,MAAM,SAAS,IAAI,OAAO,EAAE,CAAC;QAChC,IAAI,OAAgB,CAAA;QACpB,I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AK,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,CAAC,CAAA;AAC9D,CAAC;AAED,oHAAoH;AACpH,MAAM,UAAU,UAAU,CAAC,IAAoB,EAAE,KAAgB;IAC/D,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,SAAS,CAAA;IACrC,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;IACvE,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;AACjE,CAAC;AAED,yGAAyG;AACzG,MAAM,UAAU,aAAa,CAAC,OAAgB;IAC5C,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,OAAO,CAAA;IAC/C,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAC5B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,OAAO,CAAA;IAChB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface StackFrame {
|
|
2
|
+
filename: string;
|
|
3
|
+
function: string;
|
|
4
|
+
lineno?: number;
|
|
5
|
+
colno?: number;
|
|
6
|
+
in_app: boolean;
|
|
7
|
+
platform: 'node:javascript';
|
|
8
|
+
}
|
|
9
|
+
export interface ExceptionEntry {
|
|
10
|
+
type: string;
|
|
11
|
+
value: string;
|
|
12
|
+
mechanism: {
|
|
13
|
+
type: 'generic';
|
|
14
|
+
handled: boolean;
|
|
15
|
+
synthetic?: boolean;
|
|
16
|
+
};
|
|
17
|
+
stacktrace?: {
|
|
18
|
+
type: 'raw';
|
|
19
|
+
frames: StackFrame[];
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** The `$exception_list` of an error (and its `cause` chain). */
|
|
23
|
+
export declare function exceptionList(error: unknown, handled?: boolean): ExceptionEntry[];
|
|
24
|
+
/** Parses a V8 stack trace. Returns frames with the crash site last. */
|
|
25
|
+
export declare function parseStack(stack: string): StackFrame[];
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// `$exception_list` in PostHog's format (the server's error tracking parses it, docs/architecture.md "Error
|
|
2
|
+
// tracking"): outermost exception first, then its causes; frames with the crash site last.
|
|
3
|
+
const MAX_CAUSES = 10;
|
|
4
|
+
/** The `$exception_list` of an error (and its `cause` chain). */
|
|
5
|
+
export function exceptionList(error, handled = true) {
|
|
6
|
+
const out = [];
|
|
7
|
+
let current = error;
|
|
8
|
+
const seen = new Set();
|
|
9
|
+
while (current !== undefined && current !== null && out.length < MAX_CAUSES && !seen.has(current)) {
|
|
10
|
+
seen.add(current);
|
|
11
|
+
out.push(entry(current, handled));
|
|
12
|
+
current = current instanceof Error ? current.cause : undefined;
|
|
13
|
+
}
|
|
14
|
+
return out;
|
|
15
|
+
}
|
|
16
|
+
function entry(error, handled) {
|
|
17
|
+
if (error instanceof Error) {
|
|
18
|
+
const frames = parseStack(error.stack ?? '');
|
|
19
|
+
const out = {
|
|
20
|
+
type: error.name || error.constructor?.name || 'Error',
|
|
21
|
+
value: error.message,
|
|
22
|
+
mechanism: { type: 'generic', handled },
|
|
23
|
+
};
|
|
24
|
+
if (frames.length > 0)
|
|
25
|
+
out.stacktrace = { type: 'raw', frames };
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
const value = typeof error === 'string' ? error : safeJson(error);
|
|
29
|
+
return { type: 'Error', value, mechanism: { type: 'generic', handled, synthetic: true } };
|
|
30
|
+
}
|
|
31
|
+
function safeJson(value) {
|
|
32
|
+
try {
|
|
33
|
+
return JSON.stringify(value) ?? String(value);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return String(value);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const WITH_FUNCTION = /^\s*at (?:async )?(.*?) \((.*?)(?::(\d+))?(?::(\d+))?\)$/;
|
|
40
|
+
const WITHOUT_FUNCTION = /^\s*at (?:async )?(.*?)(?::(\d+))?(?::(\d+))?$/;
|
|
41
|
+
/** Parses a V8 stack trace. Returns frames with the crash site last. */
|
|
42
|
+
export function parseStack(stack) {
|
|
43
|
+
const frames = [];
|
|
44
|
+
for (const line of stack.split('\n')) {
|
|
45
|
+
if (!/^\s*at /.test(line))
|
|
46
|
+
continue;
|
|
47
|
+
let fn = '?';
|
|
48
|
+
let location;
|
|
49
|
+
let lineno;
|
|
50
|
+
let colno;
|
|
51
|
+
const named = WITH_FUNCTION.exec(line);
|
|
52
|
+
if (named) {
|
|
53
|
+
fn = named[1] || '?';
|
|
54
|
+
[, , location = '', lineno, colno] = named;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
const bare = WITHOUT_FUNCTION.exec(line);
|
|
58
|
+
if (!bare)
|
|
59
|
+
continue;
|
|
60
|
+
[, location = '', lineno, colno] = bare;
|
|
61
|
+
}
|
|
62
|
+
const filename = location.replace(/^file:\/\//, '');
|
|
63
|
+
const frame = { filename, function: fn, in_app: inApp(filename), platform: 'node:javascript' };
|
|
64
|
+
if (lineno)
|
|
65
|
+
frame.lineno = Number(lineno);
|
|
66
|
+
if (colno)
|
|
67
|
+
frame.colno = Number(colno);
|
|
68
|
+
frames.push(frame);
|
|
69
|
+
}
|
|
70
|
+
return frames.reverse();
|
|
71
|
+
}
|
|
72
|
+
function inApp(filename) {
|
|
73
|
+
return !(filename.includes('/node_modules/') ||
|
|
74
|
+
filename.startsWith('node:') ||
|
|
75
|
+
filename.startsWith('internal/') ||
|
|
76
|
+
filename === 'native' ||
|
|
77
|
+
filename === '<anonymous>');
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=exceptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.js","sourceRoot":"","sources":["../src/exceptions.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,2FAA2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CAAC,IAAI,CAAC,CAAA;YACxC,IAAI,CAAC,IAAI;gBAAE,SACV;YAAA,CAAC,EAAE,QAAQ,GAAG,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,IAAI,CAAA;QAC1C,CAAC;QACD,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAA;QACnD,MAAM,KAAK,GAAe,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,iBAAiB,EAAE,CAAA;QAC1G,IAAI,MAAM;YAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;QACzC,IAAI,KAAK;YAAE,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;QACtC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACpB,CAAC;IACD,OAAO,MAAM,CAAC,OAAO,EAAE,CAAA;AACzB,CAAC;AAED,SAAS,KAAK,CAAC,QAAgB;IAC7B,OAAO,CAAC,CACN,QAAQ,CAAC,QAAQ,CAAC,gBAAgB,CAAC;QACnC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC;QAC5B,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC;QAChC,QAAQ,KAAK,QAAQ;QACrB,QAAQ,KAAK,aAAa,CAC3B,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Numbunch } from './client.js';
|
|
2
|
+
export interface ExpressLikeRequest {
|
|
3
|
+
method?: string;
|
|
4
|
+
originalUrl?: string;
|
|
5
|
+
url?: string;
|
|
6
|
+
headers: Record<string, string | string[] | undefined>;
|
|
7
|
+
}
|
|
8
|
+
export interface ErrorHandlerOptions<Req> {
|
|
9
|
+
/** The distinct ID for the request (default: the browser SDK's `user.id` baggage). */
|
|
10
|
+
distinctId?: (req: Req) => string | undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* `app.use(numbunchErrorHandler(client))` after your routes: captures the error as `$exception` (unhandled) and passes
|
|
14
|
+
* it on to the next error handler unchanged.
|
|
15
|
+
*/
|
|
16
|
+
export declare function numbunchErrorHandler<Req extends ExpressLikeRequest>(client: Numbunch, options?: ErrorHandlerOptions<Req>): (error: unknown, req: Req, _res: unknown, next: (error?: unknown) => void) => void;
|
package/dist/express.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Express error middleware that reports to Numbunch error tracking. No Express dependency: structural types only.
|
|
2
|
+
import { requestContext } from './context.js';
|
|
3
|
+
/**
|
|
4
|
+
* `app.use(numbunchErrorHandler(client))` after your routes: captures the error as `$exception` (unhandled) and passes
|
|
5
|
+
* it on to the next error handler unchanged.
|
|
6
|
+
*/
|
|
7
|
+
export function numbunchErrorHandler(client, options = {}) {
|
|
8
|
+
return (error, req, _res, next) => {
|
|
9
|
+
try {
|
|
10
|
+
const context = requestContext(req.headers);
|
|
11
|
+
const properties = { $exception_source: 'express' };
|
|
12
|
+
if (req.method)
|
|
13
|
+
properties.$request_method = req.method;
|
|
14
|
+
const path = req.originalUrl ?? req.url;
|
|
15
|
+
if (path)
|
|
16
|
+
properties.$request_path = path;
|
|
17
|
+
if (context.sessionId)
|
|
18
|
+
properties.$session_id = context.sessionId;
|
|
19
|
+
client.captureException(error, options.distinctId?.(req) ?? context.distinctId, properties, false);
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
next(error);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=express.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAGlH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAc7C;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAiC,MAAgB,EAAE,UAAoC,EAAE;IAC3H,OAAO,CAAC,KAAc,EAAE,GAAQ,EAAE,IAAa,EAAE,IAA+B,EAAQ,EAAE;QACxF,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;YAC3C,MAAM,UAAU,GAA4B,EAAE,iBAAiB,EAAE,SAAS,EAAE,CAAA;YAC5E,IAAI,GAAG,CAAC,MAAM;gBAAE,UAAU,CAAC,eAAe,GAAG,GAAG,CAAC,MAAM,CAAA;YACvD,MAAM,IAAI,GAAG,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,GAAG,CAAA;YACvC,IAAI,IAAI;gBAAE,UAAU,CAAC,aAAa,GAAG,IAAI,CAAA;YACzC,IAAI,OAAO,CAAC,SAAS;gBAAE,UAAU,CAAC,WAAW,GAAG,OAAO,CAAC,SAAS,CAAA;YACjE,MAAM,CAAC,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,CAAC,CAAA;QACpG,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,KAAK,CAAC,CAAA;QACb,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Numbunch } from './client.js';
|
|
2
|
+
export interface FastifyLikeRequest {
|
|
3
|
+
method?: string;
|
|
4
|
+
url?: string;
|
|
5
|
+
headers: Record<string, string | string[] | undefined>;
|
|
6
|
+
}
|
|
7
|
+
export interface FastifyLikeInstance<Req> {
|
|
8
|
+
addHook(name: 'onError', hook: (request: Req, reply: unknown, error: unknown) => Promise<void>): unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface FastifyOptions<Req> {
|
|
11
|
+
/** The distinct ID for the request (default: the browser SDK's `user.id` baggage). */
|
|
12
|
+
distinctId?: (request: Req) => string | undefined;
|
|
13
|
+
}
|
|
14
|
+
/** The `onError` hook on its own: `fastify.addHook('onError', numbunchOnError(client))`. */
|
|
15
|
+
export declare function numbunchOnError<Req extends FastifyLikeRequest>(client: Numbunch, options?: FastifyOptions<Req>): (request: Req, _reply: unknown, error: unknown) => Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* `fastify.register(numbunchFastify(client))`: registers the `onError` hook for the whole instance (the plugin skips
|
|
18
|
+
* Fastify's encapsulation, as `fastify-plugin` would).
|
|
19
|
+
*/
|
|
20
|
+
export declare function numbunchFastify<Req extends FastifyLikeRequest>(client: Numbunch, options?: FastifyOptions<Req>): ((fastify: FastifyLikeInstance<Req>, _opts: unknown, done: () => void) => void) & {
|
|
21
|
+
[x: symbol]: string | boolean;
|
|
22
|
+
};
|
package/dist/fastify.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Fastify plugin that reports request errors to Numbunch error tracking. No Fastify dependency: structural types only.
|
|
2
|
+
import { requestContext } from './context.js';
|
|
3
|
+
/** The `onError` hook on its own: `fastify.addHook('onError', numbunchOnError(client))`. */
|
|
4
|
+
export function numbunchOnError(client, options = {}) {
|
|
5
|
+
return async (request, _reply, error) => {
|
|
6
|
+
const context = requestContext(request.headers);
|
|
7
|
+
const properties = { $exception_source: 'fastify' };
|
|
8
|
+
if (request.method)
|
|
9
|
+
properties.$request_method = request.method;
|
|
10
|
+
if (request.url)
|
|
11
|
+
properties.$request_path = request.url;
|
|
12
|
+
if (context.sessionId)
|
|
13
|
+
properties.$session_id = context.sessionId;
|
|
14
|
+
client.captureException(error, options.distinctId?.(request) ?? context.distinctId, properties, false);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* `fastify.register(numbunchFastify(client))`: registers the `onError` hook for the whole instance (the plugin skips
|
|
19
|
+
* Fastify's encapsulation, as `fastify-plugin` would).
|
|
20
|
+
*/
|
|
21
|
+
export function numbunchFastify(client, options = {}) {
|
|
22
|
+
const plugin = (fastify, _opts, done) => {
|
|
23
|
+
fastify.addHook('onError', numbunchOnError(client, options));
|
|
24
|
+
done();
|
|
25
|
+
};
|
|
26
|
+
return Object.assign(plugin, { [Symbol.for('skip-override')]: true, [Symbol.for('fastify.display-name')]: 'numbunch' });
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=fastify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fastify.js","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAAA,uHAAuH;AAGvH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAiB7C,4FAA4F;AAC5F,MAAM,UAAU,eAAe,CAAiC,MAAgB,EAAE,UAA+B,EAAE;IACjH,OAAO,KAAK,EAAE,OAAY,EAAE,MAAe,EAAE,KAAc,EAAiB,EAAE;QAC5E,MAAM,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC/C,MAAM,UAAU,GAA4B,EAAE,iBAAiB,EAAE,SAAS,EAAE,CAAA;QAC5E,IAAI,OAAO,CAAC,MAAM;YAAE,UAAU,CAAC,eAAe,GAAG,OAAO,CAAC,MAAM,CAAA;QAC/D,IAAI,OAAO,CAAC,GAAG;YAAE,UAAU,CAAC,aAAa,GAAG,OAAO,CAAC,GAAG,CAAA;QACvD,IAAI,OAAO,CAAC,SAAS;YAAE,UAAU,CAAC,WAAW,GAAG,OAAO,CAAC,SAAS,CAAA;QACjE,MAAM,CAAC,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,CAAC,CAAA;IACxG,CAAC,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAiC,MAAgB,EAAE,UAA+B,EAAE;IACjH,MAAM,MAAM,GAAG,CAAC,OAAiC,EAAE,KAAc,EAAE,IAAgB,EAAQ,EAAE;QAC3F,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;QAC5D,IAAI,EAAE,CAAA;IACR,CAAC,CAAA;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAA;AACzH,CAAC"}
|
package/dist/hash.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type Bucketing = 'sha1_v1' | 'murmur3_v1';
|
|
2
|
+
/** MurmurHash3, x86 32-bit variant (Austin Appleby, public domain), over the UTF-8 bytes of `input`. */
|
|
3
|
+
export declare function murmur3_x86_32(input: string | Uint8Array, seed?: number): number;
|
|
4
|
+
/** `murmur3_x86_32(utf8("{flagKey}.{id}{salt}"), 0) / 2^32`, in [0, 1). */
|
|
5
|
+
export declare function murmur3V1(flagKey: string, id: string, salt?: string): number;
|
|
6
|
+
/** `int(hex(SHA1("{flagKey}.{id}{salt}"))[0..15], 16) / 0xfffffffffffffff`, in [0, 1]. */
|
|
7
|
+
export declare function sha1V1(flagKey: string, id: string, salt?: string): number;
|
|
8
|
+
/** The rollout or variant value of `flagKey` for `id`. */
|
|
9
|
+
export declare function bucket(scheme: Bucketing, flagKey: string, id: string, salt?: string): number;
|
|
10
|
+
/** The holdout value: the hash of `"holdout-{holdoutId}.{id}"` (no flag key, so a holdout spans its flags). */
|
|
11
|
+
export declare function holdoutValue(scheme: Bucketing, holdoutId: number, id: string): number;
|
|
12
|
+
/** Whether `value` falls inside `percentage` (0–100): `sha1_v1` includes the bound, `murmur3_v1` excludes it. */
|
|
13
|
+
export declare function within(scheme: Bucketing, value: number, percentage: number): boolean;
|
|
14
|
+
/** The first variant whose cumulative share exceeds `value`. */
|
|
15
|
+
export declare function pickVariant(value: number, variants: readonly {
|
|
16
|
+
key: string;
|
|
17
|
+
rollout_percentage: number;
|
|
18
|
+
}[]): string | undefined;
|
package/dist/hash.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Bucketing (ADR 0007), identical to crates/nb-flags/src/hash.rs.
|
|
2
|
+
//
|
|
3
|
+
// `sha1_v1` follows posthog-node 4.11.2 `src/feature-flags.ts` (`_hash`), MIT, Copyright (c) PostHog Inc.
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
/** `0xfffffffffffffff`: the largest 15-hex-digit number. */
|
|
6
|
+
// Rounds to 2^60, exactly as `0xfffffffffffffff as f64` in Rust and the literal in posthog-node.
|
|
7
|
+
const LONG_SCALE = Number(0xfffffffffffffffn);
|
|
8
|
+
const TWO_32 = 4294967296;
|
|
9
|
+
const encoder = new TextEncoder();
|
|
10
|
+
/** MurmurHash3, x86 32-bit variant (Austin Appleby, public domain), over the UTF-8 bytes of `input`. */
|
|
11
|
+
export function murmur3_x86_32(input, seed = 0) {
|
|
12
|
+
const data = typeof input === 'string' ? encoder.encode(input) : input;
|
|
13
|
+
const c1 = 0xcc9e2d51;
|
|
14
|
+
const c2 = 0x1b873593;
|
|
15
|
+
let h = seed >>> 0;
|
|
16
|
+
const blocks = data.length & ~3;
|
|
17
|
+
for (let i = 0; i < blocks; i += 4) {
|
|
18
|
+
let k = (data[i] | (data[i + 1] << 8) | (data[i + 2] << 16) | (data[i + 3] << 24)) >>> 0;
|
|
19
|
+
k = Math.imul(k, c1);
|
|
20
|
+
k = (k << 15) | (k >>> 17);
|
|
21
|
+
k = Math.imul(k, c2);
|
|
22
|
+
h ^= k;
|
|
23
|
+
h = (h << 13) | (h >>> 19);
|
|
24
|
+
h = (Math.imul(h, 5) + 0xe6546b64) | 0;
|
|
25
|
+
}
|
|
26
|
+
const tail = data.length & 3;
|
|
27
|
+
if (tail > 0) {
|
|
28
|
+
let k = 0;
|
|
29
|
+
for (let i = tail - 1; i >= 0; i--)
|
|
30
|
+
k = (k << 8) | data[blocks + i];
|
|
31
|
+
k = Math.imul(k, c1);
|
|
32
|
+
k = (k << 15) | (k >>> 17);
|
|
33
|
+
k = Math.imul(k, c2);
|
|
34
|
+
h ^= k;
|
|
35
|
+
}
|
|
36
|
+
h ^= data.length;
|
|
37
|
+
h ^= h >>> 16;
|
|
38
|
+
h = Math.imul(h, 0x85ebca6b);
|
|
39
|
+
h ^= h >>> 13;
|
|
40
|
+
h = Math.imul(h, 0xc2b2ae35);
|
|
41
|
+
h ^= h >>> 16;
|
|
42
|
+
return h >>> 0;
|
|
43
|
+
}
|
|
44
|
+
/** `murmur3_x86_32(utf8("{flagKey}.{id}{salt}"), 0) / 2^32`, in [0, 1). */
|
|
45
|
+
export function murmur3V1(flagKey, id, salt = '') {
|
|
46
|
+
return murmur3_x86_32(`${flagKey}.${id}${salt}`) / TWO_32;
|
|
47
|
+
}
|
|
48
|
+
/** `int(hex(SHA1("{flagKey}.{id}{salt}"))[0..15], 16) / 0xfffffffffffffff`, in [0, 1]. */
|
|
49
|
+
export function sha1V1(flagKey, id, salt = '') {
|
|
50
|
+
return sha1Scaled(`${flagKey}.${id}${salt}`);
|
|
51
|
+
}
|
|
52
|
+
function sha1Scaled(input) {
|
|
53
|
+
const hex = createHash('sha1').update(input, 'utf8').digest('hex').slice(0, 15);
|
|
54
|
+
// BigInt keeps all 60 bits, then rounds once to the nearest double, as Rust's `u64 as f64` does.
|
|
55
|
+
return Number(BigInt(`0x${hex}`)) / LONG_SCALE;
|
|
56
|
+
}
|
|
57
|
+
/** The rollout or variant value of `flagKey` for `id`. */
|
|
58
|
+
export function bucket(scheme, flagKey, id, salt = '') {
|
|
59
|
+
return scheme === 'murmur3_v1' ? murmur3V1(flagKey, id, salt) : sha1V1(flagKey, id, salt);
|
|
60
|
+
}
|
|
61
|
+
/** The holdout value: the hash of `"holdout-{holdoutId}.{id}"` (no flag key, so a holdout spans its flags). */
|
|
62
|
+
export function holdoutValue(scheme, holdoutId, id) {
|
|
63
|
+
return scheme === 'murmur3_v1' ? murmur3V1(`holdout-${holdoutId}`, id) : sha1Scaled(`holdout-${holdoutId}.${id}`);
|
|
64
|
+
}
|
|
65
|
+
/** Whether `value` falls inside `percentage` (0–100): `sha1_v1` includes the bound, `murmur3_v1` excludes it. */
|
|
66
|
+
export function within(scheme, value, percentage) {
|
|
67
|
+
return scheme === 'murmur3_v1' ? value < percentage / 100 : value <= percentage / 100;
|
|
68
|
+
}
|
|
69
|
+
/** The first variant whose cumulative share exceeds `value`. */
|
|
70
|
+
export function pickVariant(value, variants) {
|
|
71
|
+
let cumulative = 0;
|
|
72
|
+
for (const variant of variants) {
|
|
73
|
+
cumulative += variant.rollout_percentage / 100;
|
|
74
|
+
if (value < cumulative)
|
|
75
|
+
return variant.key;
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=hash.js.map
|
package/dist/hash.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,EAAE;AACF,0GAA0G;AAE1G,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAIxC,4DAA4D;AAC5D,iGAAiG;AACjG,MAAM,UAAU,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAA;AAC7C,MAAM,MAAM,GAAG,UAAU,CAAA;AACzB,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAA;AAEjC,wGAAwG;AACxG,MAAM,UAAU,cAAc,CAAC,KAA0B,EAAE,IAAI,GAAG,CAAC;IACjE,MAAM,IAAI,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;IACtE,MAAM,EAAE,GAAG,UAAU,CAAA;IACrB,MAAM,EAAE,GAAG,UAAU,CAAA;IACrB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