@hyperframes/inspector 0.9.64 → 0.9.66
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/dist/live.js +1 -1
- package/dist/service.js +245 -84
- package/dist/types/core/src/canary.d.ts +153 -0
- package/dist/types/core/src/compiler/compositionScoping.d.ts +2 -0
- package/dist/types/core/src/compiler/htmlBundler.d.ts +5 -1
- package/dist/types/core/src/compiler/inlineSubCompositions.d.ts +7 -0
- package/dist/types/core/src/compiler/selectorIdTokens.d.ts +2 -0
- package/dist/types/core/src/compiler/svgIdNamespacing.d.ts +4 -2
- package/package.json +3 -3
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canary rollouts — ship a change to a stable slice of installs instead of
|
|
3
|
+
* all-or-nothing.
|
|
4
|
+
*
|
|
5
|
+
* The problem this solves: the repo has ~49 `HF_*` / `PRODUCER_*` boolean
|
|
6
|
+
* toggles, and every one of them is binary. A change is either off (and
|
|
7
|
+
* therefore untested on real traffic) or on for everyone (and therefore a
|
|
8
|
+
* fleet-wide bet). The parallel-drawElement router spent weeks in that gap:
|
|
9
|
+
* default-off collected almost no signal, and flipping it default-on exposed
|
|
10
|
+
* 100% of eligible installs at once. A percentage slice is the missing rung.
|
|
11
|
+
*
|
|
12
|
+
* Design notes worth knowing before you add one:
|
|
13
|
+
*
|
|
14
|
+
* - **Pure and universal.** No fs, no network, no `process` — the caller
|
|
15
|
+
* supplies the unit id and the overrides. That keeps this importable from
|
|
16
|
+
* the CLI, the producer, the engine, studio-server, the browser-side studio
|
|
17
|
+
* bundle, and the embeddable player alike.
|
|
18
|
+
*
|
|
19
|
+
* - **Independent slices.** The bucket is a hash of `feature:unitId`, NOT of
|
|
20
|
+
* `unitId` alone. If every canary bucketed on the id by itself, they would
|
|
21
|
+
* all select the SAME installs — one unlucky cohort would receive every
|
|
22
|
+
* experiment simultaneously, and no two rollouts could be read
|
|
23
|
+
* independently.
|
|
24
|
+
*
|
|
25
|
+
* - **Ramping is inclusive.** `bucket < percentage` means widening 10 → 25
|
|
26
|
+
* keeps every install that was already at 10. Cohorts never reshuffle, so
|
|
27
|
+
* before/after comparisons stay valid across a ramp.
|
|
28
|
+
*
|
|
29
|
+
* - **Stable per install, for the life of the install.** The same id and
|
|
30
|
+
* feature always resolve the same way, with no persisted state to keep in
|
|
31
|
+
* sync and nothing to look up at runtime.
|
|
32
|
+
*/
|
|
33
|
+
/** Why a canary resolved the way it did. Attach to telemetry — a rollout you
|
|
34
|
+
* can't segment by enrolment reason is a rollout you can't debug. */
|
|
35
|
+
export type CanaryReason = "forced_on" | "forced_off" | "in_cohort" | "out_of_cohort" | "no_unit_id" | "excluded" | "telemetry_opt_out";
|
|
36
|
+
export interface CanaryDecision {
|
|
37
|
+
enabled: boolean;
|
|
38
|
+
reason: CanaryReason;
|
|
39
|
+
/** 0-99 slot this unit landed in for this feature; undefined when not computed. */
|
|
40
|
+
bucket?: number;
|
|
41
|
+
}
|
|
42
|
+
export interface CanaryInput {
|
|
43
|
+
/** Registry key, e.g. "de-parallel-router". Part of the hash, so each feature gets its own slice. */
|
|
44
|
+
feature: string;
|
|
45
|
+
/** Stable per-install id — the CLI's telemetry `anonymousId`. Missing/blank fails closed. */
|
|
46
|
+
unitId: string | undefined;
|
|
47
|
+
/** 0 = off for everyone, 100 = on for everyone. Values outside 0-100 are clamped. */
|
|
48
|
+
percentage: number;
|
|
49
|
+
/**
|
|
50
|
+
* Explicit override, both directions — support escalations, dogfooding, a
|
|
51
|
+
* bisect, or a panic-off. Always wins over the percentage.
|
|
52
|
+
*/
|
|
53
|
+
override?: boolean | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Exclude this unit from percentage-based enrolment (an explicit override
|
|
56
|
+
* still applies). Callers pass `isCI` here: CI installs regenerate their
|
|
57
|
+
* config constantly, so their ids are ephemeral — they would hop cohorts
|
|
58
|
+
* between runs, adding noise to the rollout signal while telling you
|
|
59
|
+
* nothing about real users.
|
|
60
|
+
*/
|
|
61
|
+
exclude?: boolean | undefined;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* FNV-1a (32-bit). Chosen over `node:crypto` deliberately: this module has to
|
|
65
|
+
* run in the browser-side studio bundle and the embeddable player too, and a
|
|
66
|
+
* six-line hash beats shipping a polyfill or maintaining two code paths.
|
|
67
|
+
* Distribution is uniform enough for bucketing (pinned by a test).
|
|
68
|
+
*
|
|
69
|
+
* ASCII-only by contract. `charCodeAt` yields UTF-16 code units — two
|
|
70
|
+
* surrogate halves for an astral character — whereas reference FNV-1a is
|
|
71
|
+
* byte-oriented, so the two agree only on ASCII. Both inputs are constrained
|
|
72
|
+
* to satisfy that: canary names by the registry's kebab-case assertion in
|
|
73
|
+
* `canary.test.ts`, unit ids by being UUIDs. Widening either means switching
|
|
74
|
+
* to a UTF-8 encoding here first, which is not free in the browser bundle
|
|
75
|
+
* (`TextEncoder` is fine; `Buffer` is not).
|
|
76
|
+
*/
|
|
77
|
+
export declare function fnv1a32(input: string): number;
|
|
78
|
+
/** The 0-99 slot a unit occupies for a given feature. Exported for tests and diagnostics. */
|
|
79
|
+
export declare function canaryBucket(feature: string, unitId: string): number;
|
|
80
|
+
/**
|
|
81
|
+
* Resolve whether a feature is on for this unit.
|
|
82
|
+
*
|
|
83
|
+
* Fails closed on a missing id: the canary exists to bound blast radius, so
|
|
84
|
+
* "we don't know who this is" must mean "not enrolled", never "enrol
|
|
85
|
+
* everyone".
|
|
86
|
+
*/
|
|
87
|
+
export declare function evaluateCanary(input: CanaryInput): CanaryDecision;
|
|
88
|
+
/**
|
|
89
|
+
* Parse a canary override from an env-var value.
|
|
90
|
+
*
|
|
91
|
+
* Accepts the spellings people actually type. Returns undefined for
|
|
92
|
+
* unset/empty so the percentage decides — matching how the existing HF_*
|
|
93
|
+
* knobs treat a set-but-empty var, and avoiding the failure mode where an
|
|
94
|
+
* exported-but-empty variable silently forces a feature on.
|
|
95
|
+
*/
|
|
96
|
+
export declare function parseCanaryOverride(raw: string | undefined): boolean | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Property-name prefix for canary assignments on telemetry events.
|
|
99
|
+
*
|
|
100
|
+
* PostHog treats `$feature/<key>` as a first-class flag property: breakdowns,
|
|
101
|
+
* funnels split by cohort and the experiment surfaces all key on it. Emitting
|
|
102
|
+
* assignments in that shape means the analysis tooling works on a canary with
|
|
103
|
+
* nothing configured server-side — the decision still happens locally and
|
|
104
|
+
* offline, which the render path requires (no render-time network calls, and
|
|
105
|
+
* behaviour must not depend on analytics being reachable).
|
|
106
|
+
*
|
|
107
|
+
* The `canary-` infix is deliberate. A real PostHog flag namespace already
|
|
108
|
+
* exists in this project, owned by the web app (e.g. `enable-chat-tab`, set by
|
|
109
|
+
* posthog-js). Namespacing guarantees a canary key can never alias a real flag
|
|
110
|
+
* key and have the two fight over the same property.
|
|
111
|
+
*/
|
|
112
|
+
export declare const CANARY_FEATURE_PREFIX = "$feature/canary-";
|
|
113
|
+
/** `de-parallel-router` → `$feature/canary-de-parallel-router`. */
|
|
114
|
+
export declare function canaryFeatureKey(name: string): string;
|
|
115
|
+
/**
|
|
116
|
+
* Companion key carrying WHY a canary resolved as it did.
|
|
117
|
+
*
|
|
118
|
+
* Deliberately outside the `$feature/` namespace: PostHog treats those as flag
|
|
119
|
+
* values and a non-boolean there would corrupt the flag's own breakdowns. This
|
|
120
|
+
* is an ordinary property that sits alongside.
|
|
121
|
+
*
|
|
122
|
+
* `de-parallel-router` → `canary_reason_de_parallel_router`.
|
|
123
|
+
*/
|
|
124
|
+
export declare function canaryReasonKey(name: string): string;
|
|
125
|
+
/**
|
|
126
|
+
* Build the telemetry properties for a set of resolved canaries.
|
|
127
|
+
*
|
|
128
|
+
* Emits EVERY registered canary, not just the enrolled ones, because absent
|
|
129
|
+
* and `"false"` mean different things: absent is "this build predates the
|
|
130
|
+
* canary", `"false"` is "this build has it and this install is not enrolled".
|
|
131
|
+
* Collapsing those makes a ramp unreadable — you cannot tell a control group
|
|
132
|
+
* from an old version.
|
|
133
|
+
*
|
|
134
|
+
* Values are the strings `"true"` / `"false"` to match how PostHog records
|
|
135
|
+
* boolean flag values, so the property is directly comparable to a real flag.
|
|
136
|
+
*
|
|
137
|
+
* **The reason rides alongside when supplied**, under `canary_reason_<name>`.
|
|
138
|
+
* Without it the assignment alone is ambiguous in the one case that matters:
|
|
139
|
+
* an install reporting both `"true"` and `"false"` for a canary whose
|
|
140
|
+
* percentage never moved is indistinguishable from a developer toggling
|
|
141
|
+
* `HF_CANARY_*`. The first calibration read hit exactly that wall — 304
|
|
142
|
+
* installs reported both values and the genuinely anomalous ones could not be
|
|
143
|
+
* separated from deliberate overrides. The registry doc deferred this until
|
|
144
|
+
* the stability check came back dirty; it did.
|
|
145
|
+
*
|
|
146
|
+
* `reason` is optional so existing callers keep working; a caller that has the
|
|
147
|
+
* full decision should pass it.
|
|
148
|
+
*/
|
|
149
|
+
export declare function canaryFeatureProperties(entries: ReadonlyArray<{
|
|
150
|
+
name: string;
|
|
151
|
+
enabled: boolean;
|
|
152
|
+
reason?: CanaryReason;
|
|
153
|
+
}>): Record<string, string>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
type ScopeOptions = {
|
|
2
2
|
compoundAuthoredRoot?: boolean;
|
|
3
3
|
scopeRootSelectors?: boolean;
|
|
4
|
+
/** Told the sheet's size, an upper bound for each rule before it is scoped, then the correction. */
|
|
5
|
+
charge?: (bytes: number) => void;
|
|
4
6
|
};
|
|
5
7
|
export declare function scopeCssToComposition(css: string, compositionId: string, scopeSelectorOverride?: string, authoredRootId?: string | null, options?: ScopeOptions): string;
|
|
6
8
|
/** `scopeCssToComposition` for sheets mounted many times: each sheet is scoped once around a
|
|
@@ -80,4 +80,8 @@ export declare function bundleToSingleHtml(projectDir: string, options?: BundleO
|
|
|
80
80
|
* through the shared module rather than this bundler.
|
|
81
81
|
* Returns whether a style element was appended.
|
|
82
82
|
*/
|
|
83
|
-
export declare function emitRootCompositionVariableStyles(document: Document, variablesByComp?: Record<string, Record<string, unknown>>, overrides?: Record<string, unknown
|
|
83
|
+
export declare function emitRootCompositionVariableStyles(document: Document, variablesByComp?: Record<string, Record<string, unknown>>, overrides?: Record<string, unknown>, options?: {
|
|
84
|
+
chargeBytes?: (bytes: number) => void;
|
|
85
|
+
}): boolean;
|
|
86
|
+
/** The most CSS the compile-time composition-variable rules may add up to when the caller sets no budget of its own. */
|
|
87
|
+
export declare const MAX_COMPOSITION_VARIABLE_STYLE_BYTES: number;
|
|
@@ -20,6 +20,8 @@ export interface InlineSubCompositionsOptions {
|
|
|
20
20
|
* Return `null` when the file cannot be found.
|
|
21
21
|
*/
|
|
22
22
|
resolveHtml: (srcPath: string) => string | null;
|
|
23
|
+
/** The project-relative file `resolveHtml` read for a src; asset paths rebase from its folder. */
|
|
24
|
+
resolveFilePath?: (srcPath: string) => string | null;
|
|
23
25
|
/**
|
|
24
26
|
* Parse an HTML string into a Document. The returned object must expose
|
|
25
27
|
* standard DOM APIs (querySelector, querySelectorAll, body, head, etc.).
|
|
@@ -100,6 +102,11 @@ export interface InlineSubCompositionsOptions {
|
|
|
100
102
|
/** Tag each top-level host with `data-hf-scene` and report every part's scene, for preview swaps. */
|
|
101
103
|
tagScenes?: boolean;
|
|
102
104
|
readProjectScript?: (path: string) => string | null;
|
|
105
|
+
/**
|
|
106
|
+
* Told the size of each script and stylesheet generated for a mount: each wrapped script once
|
|
107
|
+
* built, and each scoped sheet rule by rule as `scopeCssToComposition` reports it. May throw.
|
|
108
|
+
*/
|
|
109
|
+
chargeEmitted?: (srcPath: string, bytes: number) => void;
|
|
103
110
|
}
|
|
104
111
|
export interface ExternalLink {
|
|
105
112
|
href: string;
|
|
@@ -48,6 +48,8 @@ export declare function escapeCssIdentifier(value: string): string;
|
|
|
48
48
|
* full replacement text (including its own leading `#`, if any) to splice
|
|
49
49
|
* in.
|
|
50
50
|
*/
|
|
51
|
+
/** The `#id` values a selector names, read as `replaceSelectorIdTokens` reads them. */
|
|
52
|
+
export declare function selectorIdTokens(selector: string): string[];
|
|
51
53
|
export declare function replaceSelectorIdTokens(selector: string, candidateIds: readonly string[], resolveReplacement: (matchedId: string) => string): string;
|
|
52
54
|
export declare function escapeCssAttributeValue(value: string): string;
|
|
53
55
|
type AttributeNamespace = {
|
|
@@ -45,6 +45,8 @@ export interface SvgIdScope {
|
|
|
45
45
|
*/
|
|
46
46
|
cssTexts?: readonly string[];
|
|
47
47
|
}
|
|
48
|
+
/** What reads a scope's renames: a plain `Map`, or a `ScopedIdMap`. */
|
|
49
|
+
export type SvgIdMap = Pick<ReadonlyMap<string, string>, "get" | "has" | "size">;
|
|
48
50
|
/** The outermost timed clips holding an `<svg>` outside every composition host. Each is its own id scope, as an
|
|
49
51
|
* inlined composition is, so two scenes drawn with the same ids each resolve their own `url(#id)` and `href`. */
|
|
50
52
|
export declare function sceneClipRoots(document: SvgIdQueryable, hosts: readonly Element[]): Element[];
|
|
@@ -65,7 +67,7 @@ export declare function sceneClipRoots(document: SvgIdQueryable, hosts: readonly
|
|
|
65
67
|
* document declares itself, since those collide with an inlined instance's
|
|
66
68
|
* ids just as two instances collide with each other.
|
|
67
69
|
*/
|
|
68
|
-
export declare function namespaceCollidingSvgIds(document: SvgIdQueryable, scopes: readonly SvgIdScope[], finalizedIds?: Set<Element
|
|
70
|
+
export declare function namespaceCollidingSvgIds(document: SvgIdQueryable, scopes: readonly SvgIdScope[], finalizedIds?: Set<Element>, charge?: (scopeIndex: number, bytes: number) => void): SvgIdMap[];
|
|
69
71
|
/**
|
|
70
72
|
* Apply the same id substitution `namespaceCollidingSvgIds` computed to a
|
|
71
73
|
* composition's `<style>` text.
|
|
@@ -79,5 +81,5 @@ export declare function namespaceCollidingSvgIds(document: SvgIdQueryable, scope
|
|
|
79
81
|
* same-composition stylesheet rule silently stops matching the element whose
|
|
80
82
|
* id this module just changed.
|
|
81
83
|
*/
|
|
82
|
-
export declare function rewriteSvgIdReferencesInCss(css: string, idMap:
|
|
84
|
+
export declare function rewriteSvgIdReferencesInCss(css: string, idMap: SvgIdMap, references?: readonly SvgReferenceAlias[]): string;
|
|
83
85
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/inspector",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.66",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/heygen-com/hyperframes",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"htmlparser2": "^10.1.0",
|
|
44
44
|
"postcss": "^8.5.8",
|
|
45
45
|
"puppeteer-core": "^25.8.0",
|
|
46
|
-
"@hyperframes/core": "0.9.
|
|
47
|
-
"@hyperframes/parsers": "0.9.
|
|
46
|
+
"@hyperframes/core": "0.9.66",
|
|
47
|
+
"@hyperframes/parsers": "0.9.66"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/node": "^25.0.10",
|