@plitzi/sdk-shared 0.39.11 → 0.39.13
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 +14 -0
- package/dist/audiences/audiences.d.ts +78 -0
- package/dist/audiences/audiences.mjs +75 -0
- package/dist/audiences/index.d.ts +1 -0
- package/dist/audiences/index.mjs +1 -0
- package/dist/authoring/elementCallbacks.d.ts +22 -0
- package/dist/authoring/elementCallbacks.mjs +20 -5
- package/dist/authoring/index.mjs +4 -4
- package/dist/authoring/spaceCallbacks.mjs +46 -33
- package/dist/dataSource/globalSources.d.ts +8 -4
- package/dist/dataSource/globalSources.mjs +6 -0
- package/dist/experimentEvents/experimentEvents.d.ts +24 -0
- package/dist/experimentEvents/experimentEvents.mjs +28 -0
- package/dist/experimentEvents/index.d.ts +1 -0
- package/dist/experimentEvents/index.mjs +1 -0
- package/dist/experiments/experiments.d.ts +73 -0
- package/dist/experiments/experiments.mjs +74 -0
- package/dist/experiments/experimentsCookie.d.ts +26 -0
- package/dist/experiments/experimentsCookie.mjs +25 -0
- package/dist/experiments/forcedExperiments.d.ts +31 -0
- package/dist/experiments/forcedExperiments.mjs +41 -0
- package/dist/experiments/index.d.ts +3 -0
- package/dist/experiments/index.mjs +4 -0
- package/dist/flags/index.d.ts +1 -0
- package/dist/flags/index.mjs +6 -5
- package/dist/flags/react/index.d.ts +1 -0
- package/dist/flags/react/index.mjs +3 -1
- package/dist/flags/react/useFlagResolution.mjs +22 -19
- package/dist/flags/react/useRolloutBuckets.d.ts +9 -0
- package/dist/flags/react/useRolloutBuckets.mjs +19 -0
- package/dist/flags/resolveFlags.d.ts +10 -3
- package/dist/flags/resolveFlags.mjs +19 -9
- package/dist/flags/rollout.d.ts +41 -0
- package/dist/flags/rollout.mjs +53 -0
- package/dist/flags/schemaFlag.d.ts +3 -1
- package/dist/flags/schemaFlag.mjs +2 -2
- package/dist/helpers/index.mjs +31 -30
- package/dist/helpers/twigWrapper/Evaluator/Evaluator.mjs +28 -27
- package/dist/helpers/twigWrapper/filters/catalog/index.mjs +1 -1
- package/dist/helpers/twigWrapper/filters/dates.mjs +6 -6
- package/dist/helpers/twigWrapper/filters/filters.mjs +3 -3
- package/dist/helpers/twigWrapper/filters/index.mjs +4 -4
- package/dist/helpers/twigWrapper/filters/types.d.ts +16 -1
- package/dist/helpers/twigWrapper/filters/types.mjs +11 -2
- package/dist/helpers/twigWrapper/index.d.ts +2 -1
- package/dist/helpers/twigWrapper/index.mjs +4 -3
- package/dist/helpers/twigWrapper/templateRoots.mjs +19 -18
- package/dist/schema/serverElements.mjs +18 -18
- package/dist/schema/serverInput.mjs +6 -6
- package/dist/store/renderSettings.d.ts +1 -0
- package/dist/store/renderSettings.mjs +16 -12
- package/dist/store/storeHooks.d.ts +45 -45
- package/dist/style/styleStates.d.ts +7 -2
- package/dist/style/styleStates.mjs +2 -2
- package/dist/timeWindows/clock.d.ts +11 -0
- package/dist/timeWindows/clock.mjs +6 -0
- package/dist/timeWindows/countdown.d.ts +31 -0
- package/dist/timeWindows/countdown.mjs +57 -0
- package/dist/timeWindows/index.d.ts +3 -0
- package/dist/timeWindows/index.mjs +4 -0
- package/dist/timeWindows/timeWindows.d.ts +13 -0
- package/dist/timeWindows/timeWindows.mjs +10 -0
- package/dist/types/CommonTypes.d.ts +5 -0
- package/dist/types/DataSourceTypes.d.ts +1 -1
- package/dist/types/ElementTypes.d.ts +1 -1
- package/dist/types/PluginTypes.d.ts +5 -0
- package/dist/types/SchemaTypes.d.ts +11 -1
- package/dist/types/StoreTypes.d.ts +63 -0
- package/dist/variants/index.d.ts +1 -0
- package/dist/variants/index.mjs +1 -0
- package/dist/variants/variants.d.ts +23 -0
- package/dist/variants/variants.mjs +9 -0
- package/package.json +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isExperimentName as e, isExperimentVariant as t } from "./experiments.mjs";
|
|
2
|
+
import { cookieFromHeader as n } from "../helpers/cookies.mjs";
|
|
3
|
+
// src/experiments/experimentsCookie.ts
|
|
4
|
+
var r = (e) => {
|
|
5
|
+
let t = e?.split(":")[1];
|
|
6
|
+
return t ? `plitzi_ab_${t}` : "plitzi_ab";
|
|
7
|
+
}, i = 15552e3, a = (n) => {
|
|
8
|
+
let r = {};
|
|
9
|
+
for (let i of n?.split(",") ?? []) {
|
|
10
|
+
let [n = "", a] = i.split(":");
|
|
11
|
+
e(n) && t(a) && (r[n] = a);
|
|
12
|
+
}
|
|
13
|
+
return r;
|
|
14
|
+
}, o = (n) => Object.entries(n).filter(([n, r]) => e(n) && t(r)).sort(([e], [t]) => e.localeCompare(t)).map(([e, t]) => `${e}:${t}`).join(","), s = (e, t) => a(n(e, r(t))), c = (e, t, { secure: n }) => [
|
|
15
|
+
`${r(e)}=${encodeURIComponent(o(t))}`,
|
|
16
|
+
"Path=/",
|
|
17
|
+
`Max-Age=${i}`,
|
|
18
|
+
"SameSite=Lax",
|
|
19
|
+
...n ? ["Secure"] : []
|
|
20
|
+
].join("; "), l = (e) => {
|
|
21
|
+
try {
|
|
22
|
+
document.cookie = c(window.location.host, e, { secure: window.location.protocol === "https:" });
|
|
23
|
+
} catch {}
|
|
24
|
+
};
|
|
25
|
+
export { i as EXPERIMENTS_COOKIE_MAX_AGE_S, c as experimentsCookie, r as experimentsCookieName, s as keptExperiments, a as parseExperimentList, o as serializeExperimentList, l as writeExperiments };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { DeclaredExperiment, ExperimentAssignments, ExperimentVariant } from './experiments';
|
|
2
|
+
/**
|
|
3
|
+
* The cookie a tester forces variants with — what the dev tools' Experiments tab and an address's `?ab=` write.
|
|
4
|
+
*
|
|
5
|
+
* Apart from the visitor's own (`plitzi_ab`): forcing shows a variant without touching the one the visitor keeps, so
|
|
6
|
+
* a tester's visit is never measured as a side it was not drawn. A session cookie, as the flags a tester forces are,
|
|
7
|
+
* and only honoured where debugging is authorized — the server reads it only then, as the dev tools appear only then.
|
|
8
|
+
*/
|
|
9
|
+
export declare const forcedExperimentsCookieName: (host: string | undefined) => string;
|
|
10
|
+
/** The address parameter a tester forces variants with: `?ab=heroTest:b,pricing:c`. */
|
|
11
|
+
export declare const FORCED_EXPERIMENTS_PARAM = "ab";
|
|
12
|
+
/** The variants a tester forced, from a `Cookie` header or `document.cookie`. */
|
|
13
|
+
export declare const forcedExperimentsFromCookies: (cookies: string | undefined, host: string | undefined) => ExperimentAssignments;
|
|
14
|
+
/** The variants an address forces (`?ab=`), over the ones the cookie forced before it. */
|
|
15
|
+
export declare const forcedExperimentsOf: (cookies: string | undefined, host: string | undefined, param: unknown) => ExperimentAssignments;
|
|
16
|
+
/** What is forced once one experiment is forced to `variant` — or, with `undefined`, once it is no longer forced. */
|
|
17
|
+
export declare const withForcedExperiment: (forced: ExperimentAssignments, name: string, variant: ExperimentVariant | undefined) => ExperimentAssignments;
|
|
18
|
+
export type ForcedExperiments = {
|
|
19
|
+
/** The forced variants this space can show: an experiment it runs, a variant its test has. */
|
|
20
|
+
applied: ExperimentAssignments;
|
|
21
|
+
/** What was forced and cannot be shown, each with why — said to the tester, never applied. */
|
|
22
|
+
ignored: {
|
|
23
|
+
name: string;
|
|
24
|
+
variant: ExperimentVariant;
|
|
25
|
+
reason: 'undeclared' | 'no-such-variant';
|
|
26
|
+
}[];
|
|
27
|
+
};
|
|
28
|
+
/** What a tester forced, held to the experiments the space runs and the variants each has. */
|
|
29
|
+
export declare const forcedExperimentsFor: (declared: Record<string, DeclaredExperiment>, forced: ExperimentAssignments) => ForcedExperiments;
|
|
30
|
+
/** Keeps what a tester forced for the next page this browser asks for; nothing forced removes the cookie. */
|
|
31
|
+
export declare const writeForcedExperiments: (forced: ExperimentAssignments) => void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { indexOfVariant as e } from "./experiments.mjs";
|
|
2
|
+
import { parseExperimentList as t, serializeExperimentList as n } from "./experimentsCookie.mjs";
|
|
3
|
+
import { cookieFromHeader as r } from "../helpers/cookies.mjs";
|
|
4
|
+
// src/experiments/forcedExperiments.ts
|
|
5
|
+
var i = (e) => {
|
|
6
|
+
let t = e?.split(":")[1];
|
|
7
|
+
return t ? `plitzi_ab_qa_${t}` : "plitzi_ab_qa";
|
|
8
|
+
}, a = "ab", o = (e, n) => t(r(e, i(n))), s = (e, n, r) => ({
|
|
9
|
+
...o(e, n),
|
|
10
|
+
...typeof r == "string" ? t(r) : {}
|
|
11
|
+
}), c = (e, t, n) => {
|
|
12
|
+
let { [t]: r, ...i } = e;
|
|
13
|
+
return n === void 0 ? i : {
|
|
14
|
+
...i,
|
|
15
|
+
[t]: n
|
|
16
|
+
};
|
|
17
|
+
}, l = (t, n) => {
|
|
18
|
+
let r = {}, i = [];
|
|
19
|
+
for (let [a, o] of Object.entries(n)) {
|
|
20
|
+
let n = Object.hasOwn(t, a) ? t[a] : void 0;
|
|
21
|
+
n ? e(o) >= n.weights.length ? i.push({
|
|
22
|
+
name: a,
|
|
23
|
+
variant: o,
|
|
24
|
+
reason: "no-such-variant"
|
|
25
|
+
}) : r[a] = o : i.push({
|
|
26
|
+
name: a,
|
|
27
|
+
variant: o,
|
|
28
|
+
reason: "undeclared"
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
applied: r,
|
|
33
|
+
ignored: i
|
|
34
|
+
};
|
|
35
|
+
}, u = (e) => {
|
|
36
|
+
let t = i(window.location.host), r = n(e);
|
|
37
|
+
try {
|
|
38
|
+
document.cookie = r ? `${t}=${encodeURIComponent(r)};path=/;SameSite=Lax` : `${t}=;path=/;max-age=0;SameSite=Lax`;
|
|
39
|
+
} catch {}
|
|
40
|
+
};
|
|
41
|
+
export { a as FORCED_EXPERIMENTS_PARAM, i as forcedExperimentsCookieName, l as forcedExperimentsFor, o as forcedExperimentsFromCookies, s as forcedExperimentsOf, c as withForcedExperiment, u as writeForcedExperiments };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { DEFAULT_VARIANT_WEIGHT as e, EXPERIMENT_VARIANTS as t, assignExperiments as n, builderExperiments as r, declaredExperiments as i, experimentNameOf as a, experimentOf as o, indexOfVariant as s, isExperimentName as c, isExperimentVariant as l, isExperimentWeight as u, sharesToHundred as d, variantAt as f, weightOf as p } from "./experiments.mjs";
|
|
2
|
+
import { EXPERIMENTS_COOKIE_MAX_AGE_S as m, experimentsCookie as h, experimentsCookieName as g, keptExperiments as _, parseExperimentList as v, serializeExperimentList as y, writeExperiments as b } from "./experimentsCookie.mjs";
|
|
3
|
+
import { FORCED_EXPERIMENTS_PARAM as x, forcedExperimentsCookieName as S, forcedExperimentsFor as C, forcedExperimentsFromCookies as w, forcedExperimentsOf as T, withForcedExperiment as E, writeForcedExperiments as D } from "./forcedExperiments.mjs";
|
|
4
|
+
export { e as DEFAULT_VARIANT_WEIGHT, m as EXPERIMENTS_COOKIE_MAX_AGE_S, t as EXPERIMENT_VARIANTS, x as FORCED_EXPERIMENTS_PARAM, n as assignExperiments, r as builderExperiments, i as declaredExperiments, a as experimentNameOf, o as experimentOf, h as experimentsCookie, g as experimentsCookieName, S as forcedExperimentsCookieName, C as forcedExperimentsFor, w as forcedExperimentsFromCookies, T as forcedExperimentsOf, s as indexOfVariant, c as isExperimentName, l as isExperimentVariant, u as isExperimentWeight, _ as keptExperiments, v as parseExperimentList, y as serializeExperimentList, d as sharesToHundred, f as variantAt, p as weightOf, E as withForcedExperiment, b as writeExperiments, D as writeForcedExperiments };
|
package/dist/flags/index.d.ts
CHANGED
package/dist/flags/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { FLAG_GATE_PATTERN as e, FLAG_NAME_PATTERN as t, isFlagName as n,
|
|
2
|
-
import { FLAG_LAYERS as
|
|
3
|
-
import { flagsCookieName as
|
|
4
|
-
import { forcedFlagsFor as
|
|
5
|
-
|
|
1
|
+
import { FLAG_GATE_PATTERN as e, FLAG_NAME_PATTERN as t, isFlagName as n, isFlagRollout as r, isSchemaFlag as i } from "./schemaFlag.mjs";
|
|
2
|
+
import { FLAG_LAYERS as a, flagUserFrom as o, flagUserFromSSR as s, flagValues as c, hasConditions as l, passesFlagGate as u, resolveFlags as d, undeclaredFlagOverrides as f } from "./resolveFlags.mjs";
|
|
3
|
+
import { flagsCookieName as p, forcedFlagsFromCookies as m, parseFlagList as h, serializeFlagList as g, withForcedFlag as _, writeForcedFlags as v } from "./flagsCookie.mjs";
|
|
4
|
+
import { forcedFlagsFor as y, requestFlagOverrides as b, serverFlagsFor as x } from "./overrides.mjs";
|
|
5
|
+
import { assignRollout as S, browserRollout as C, keptRollout as w, parseRolloutList as T, rolledOutFlags as E, rolloutCookie as D, rolloutCookieName as O, serializeRolloutList as k, writeRollout as A } from "./rollout.mjs";
|
|
6
|
+
export { e as FLAG_GATE_PATTERN, a as FLAG_LAYERS, t as FLAG_NAME_PATTERN, S as assignRollout, C as browserRollout, o as flagUserFrom, s as flagUserFromSSR, c as flagValues, p as flagsCookieName, y as forcedFlagsFor, m as forcedFlagsFromCookies, l as hasConditions, n as isFlagName, r as isFlagRollout, i as isSchemaFlag, w as keptRollout, h as parseFlagList, T as parseRolloutList, u as passesFlagGate, b as requestFlagOverrides, d as resolveFlags, E as rolledOutFlags, D as rolloutCookie, O as rolloutCookieName, g as serializeFlagList, k as serializeRolloutList, x as serverFlagsFor, f as undeclaredFlagOverrides, _ as withForcedFlag, v as writeForcedFlags, A as writeRollout };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
/** flags's React bindings — apart from `@plitzi/sdk-shared/flags`, which a server imports without React's hooks and contexts. */
|
|
2
2
|
export { default as useFlagResolution } from './useFlagResolution';
|
|
3
3
|
export * from './useFlagResolution';
|
|
4
|
+
export { default as useRolloutBuckets } from './useRolloutBuckets';
|
|
@@ -2,33 +2,36 @@ import e from "../../hooks/useStableValue.mjs";
|
|
|
2
2
|
import { flagUserFrom as t, resolveFlags as n } from "../resolveFlags.mjs";
|
|
3
3
|
import { useCommonStore as r } from "../../store/storeHooks.mjs";
|
|
4
4
|
import i from "../../store/renderSettings.mjs";
|
|
5
|
-
import
|
|
5
|
+
import a from "./useRolloutBuckets.mjs";
|
|
6
|
+
import { useMemo as o } from "react";
|
|
6
7
|
// src/flags/react/useFlagResolution.ts
|
|
7
|
-
var
|
|
8
|
-
let { environment:
|
|
8
|
+
var s = (s) => {
|
|
9
|
+
let { environment: c } = i(), [[l, u, d, f, p]] = r([
|
|
9
10
|
"schema.flags",
|
|
10
11
|
"navigation.routeParams",
|
|
11
12
|
"navigation.queryParams",
|
|
12
13
|
"navigation.hostname",
|
|
13
14
|
"flags.overrides"
|
|
14
|
-
]), { authenticated:
|
|
15
|
-
authenticated:
|
|
16
|
-
user: m
|
|
17
|
-
}), [p, m]);
|
|
18
|
-
return e(a(() => n(c, {
|
|
19
|
-
environment: s,
|
|
20
|
-
hostname: d,
|
|
21
|
-
routeParams: l,
|
|
22
|
-
queryParams: u,
|
|
15
|
+
]), { authenticated: m, user: h } = s, g = o(() => t({
|
|
16
|
+
authenticated: m,
|
|
23
17
|
user: h
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
}), [m, h]), _ = a();
|
|
19
|
+
return e(o(() => n(l, {
|
|
20
|
+
environment: c,
|
|
21
|
+
hostname: f,
|
|
22
|
+
routeParams: u,
|
|
23
|
+
queryParams: d,
|
|
24
|
+
user: g,
|
|
25
|
+
rollout: _
|
|
26
|
+
}, p), [
|
|
28
27
|
l,
|
|
28
|
+
c,
|
|
29
|
+
f,
|
|
29
30
|
u,
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
d,
|
|
32
|
+
g,
|
|
33
|
+
_,
|
|
34
|
+
p
|
|
32
35
|
]));
|
|
33
36
|
};
|
|
34
|
-
export {
|
|
37
|
+
export { s as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RolloutBuckets } from '../rollout';
|
|
2
|
+
/**
|
|
3
|
+
* Where this visitor stands in the space's gradual rollouts, for whoever resolves the flags in the browser — the
|
|
4
|
+
* `flags` source and the router alike: the places the server answered the page with, the ones the visitor kept, and one
|
|
5
|
+
* drawn once per page for a flag none of those has, kept in the cookie from then on. In the builder there is no
|
|
6
|
+
* visitor: no place, and a rollout's flag answers its own value (forced from the Feature Flags panel to see the other).
|
|
7
|
+
*/
|
|
8
|
+
declare const useRolloutBuckets: () => RolloutBuckets;
|
|
9
|
+
export default useRolloutBuckets;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { browserRollout as e, writeRollout as t } from "../rollout.mjs";
|
|
2
|
+
import { useCommonStore as n } from "../../store/storeHooks.mjs";
|
|
3
|
+
import r from "../../store/renderSettings.mjs";
|
|
4
|
+
import { useEffect as i, useMemo as a } from "react";
|
|
5
|
+
// src/flags/react/useRolloutBuckets.ts
|
|
6
|
+
var o = {}, s = () => {
|
|
7
|
+
let { builder: s } = r(), [[c, l]] = n(["schema.flags", "flags.rollout"]), { buckets: u, drawn: d } = a(() => s ? {
|
|
8
|
+
buckets: o,
|
|
9
|
+
drawn: []
|
|
10
|
+
} : e(c, l), [
|
|
11
|
+
s,
|
|
12
|
+
c,
|
|
13
|
+
l
|
|
14
|
+
]);
|
|
15
|
+
return i(() => {
|
|
16
|
+
d.length > 0 && t(u);
|
|
17
|
+
}, [u, d]), u;
|
|
18
|
+
};
|
|
19
|
+
export { s as default };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RuleGroup } from '../conditions';
|
|
2
|
+
import { RolloutBuckets } from './rollout';
|
|
2
3
|
import { VariableScope } from '../dataSource/variables';
|
|
3
4
|
import { AuthContextValue, Schema, SSRUser } from '../types';
|
|
4
5
|
/**
|
|
@@ -21,18 +22,24 @@ export type FlagUser = {
|
|
|
21
22
|
export declare const flagUserFrom: ({ authenticated, user }: Partial<Pick<AuthContextValue, "authenticated" | "user">>) => FlagUser;
|
|
22
23
|
/** The visitor a server resolved, as a flag's rule sees them — the same fields the browser's rules see. */
|
|
23
24
|
export declare const flagUserFromSSR: (user: Pick<SSRUser, "email" | "username" | "roles"> | undefined) => FlagUser;
|
|
24
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* What a flag's rules are matched against: everything a variable's are, and who is visiting — with where the visitor
|
|
27
|
+
* stands in the space's gradual rollouts (`rollout`, their place 0–99 per flag; none, a rollout gives its flag's value).
|
|
28
|
+
*/
|
|
25
29
|
export type FlagScope = VariableScope & {
|
|
26
30
|
user?: FlagUser;
|
|
31
|
+
rollout?: RolloutBuckets;
|
|
27
32
|
};
|
|
28
33
|
/**
|
|
29
34
|
* One flag's answer, and where it came from: the layer that decided, and — when the space did — the index of the
|
|
30
|
-
* rule that matched,
|
|
35
|
+
* rule that matched, or `rollout` when its gradual rollout took the visitor in or left them out; neither when it was
|
|
36
|
+
* the flag's own default. What the dev tools show beside the value.
|
|
31
37
|
*/
|
|
32
38
|
export type FlagResolution = {
|
|
33
39
|
value: boolean;
|
|
34
40
|
layer: FlagLayer;
|
|
35
41
|
rule?: number;
|
|
42
|
+
rollout?: true;
|
|
36
43
|
};
|
|
37
44
|
/**
|
|
38
45
|
* Whether a rule says anything at all. A rule just added in the builder has an empty group, and the evaluator reads
|
|
@@ -43,7 +50,7 @@ export declare const hasConditions: (when: unknown) => when is RuleGroup;
|
|
|
43
50
|
/**
|
|
44
51
|
* Every flag the space declares, resolved for this render: `{ newCheckout: { value: true, layer: 'space', rule: 0 } }`.
|
|
45
52
|
*
|
|
46
|
-
* The space answers first — the first of a flag's rules that matches, or its default — and each layer above it may
|
|
53
|
+
* The space answers first — the first of a flag's rules that matches, its rollout, or its default — and each layer above it may
|
|
47
54
|
* replace that answer, in order. An override for a flag the space does not declare is not an answer to anything and
|
|
48
55
|
* is dropped here; {@link undeclaredFlagOverrides} names those so whoever set one can be told.
|
|
49
56
|
*/
|
|
@@ -22,15 +22,25 @@ var t = [
|
|
|
22
22
|
"server",
|
|
23
23
|
"sdk",
|
|
24
24
|
"qa"
|
|
25
|
-
], a = (e) => typeof e == "object" && !!e && "rules" in e && Array.isArray(e.rules) && e.rules.some((e) => typeof e == "object" && !!e && !("enabled" in e && e.enabled === !1)), o = (t, n) => Array.isArray(t.rules) ? t.rules.findIndex((t) => a(t.when) && e(t.when, n)) : -1, s = (e, t) => {
|
|
26
|
-
let
|
|
27
|
-
|
|
28
|
-
value:
|
|
29
|
-
layer: "space"
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
], a = (e) => typeof e == "object" && !!e && "rules" in e && Array.isArray(e.rules) && e.rules.some((e) => typeof e == "object" && !!e && !("enabled" in e && e.enabled === !1)), o = (t, n) => Array.isArray(t.rules) ? t.rules.findIndex((t) => a(t.when) && e(t.when, n)) : -1, s = (e, t, n) => {
|
|
26
|
+
let r = o(t, n);
|
|
27
|
+
if (r !== -1) return {
|
|
28
|
+
value: t.rules[r].value,
|
|
29
|
+
layer: "space",
|
|
30
|
+
rule: r
|
|
31
|
+
};
|
|
32
|
+
let i = n.rollout && Object.hasOwn(n.rollout, e) ? n.rollout[e] : void 0;
|
|
33
|
+
return t.rollout && i !== void 0 ? {
|
|
34
|
+
value: i < t.rollout.percent ? t.rollout.value : t.value,
|
|
32
35
|
layer: "space",
|
|
33
|
-
|
|
36
|
+
rollout: !0
|
|
37
|
+
} : t.rollout?.percent === 100 ? {
|
|
38
|
+
value: t.rollout.value,
|
|
39
|
+
layer: "space",
|
|
40
|
+
rollout: !0
|
|
41
|
+
} : {
|
|
42
|
+
value: t.value,
|
|
43
|
+
layer: "space"
|
|
34
44
|
};
|
|
35
45
|
}, c = (e, t = {}, n = {}) => Object.fromEntries(Object.entries(e ?? {}).map(([e, r]) => [e, i.reduce((t, r) => {
|
|
36
46
|
let i = n[r]?.[e];
|
|
@@ -38,7 +48,7 @@ var t = [
|
|
|
38
48
|
value: i,
|
|
39
49
|
layer: r
|
|
40
50
|
} : t;
|
|
41
|
-
}, s(r, t))])), l = (e) => Object.fromEntries(Object.entries(e).map(([e, { value: t }]) => [e, t])), u = (e, t) => i.flatMap((n) => Object.keys(t[n] ?? {}).filter((t) => !Object.hasOwn(e ?? {}, t)).map((e) => ({
|
|
51
|
+
}, s(e, r, t))])), l = (e) => Object.fromEntries(Object.entries(e).map(([e, { value: t }]) => [e, t])), u = (e, t) => i.flatMap((n) => Object.keys(t[n] ?? {}).filter((t) => !Object.hasOwn(e ?? {}, t)).map((e) => ({
|
|
42
52
|
layer: n,
|
|
43
53
|
name: e
|
|
44
54
|
}))), d = (e, t) => !e || (t[e.name] ?? !1) === e.is;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Schema } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Where each visitor stands in the space's gradual rollouts: a number from 0 to 99 per flag, drawn once. A rollout at
|
|
4
|
+
* `percent` takes in the visitors below it, so raising the percent keeps everyone who was in — and lowering it lets go
|
|
5
|
+
* of the last taken in first.
|
|
6
|
+
*/
|
|
7
|
+
export type RolloutBuckets = Record<string, number>;
|
|
8
|
+
/**
|
|
9
|
+
* The cookie a visitor's places are kept in, so a reload — or the next visit — keeps them in the same rollouts.
|
|
10
|
+
*
|
|
11
|
+
* A cookie for the reason the variants of an A/B test are kept in one: the server answers the flags before the page
|
|
12
|
+
* exists. Named with the port, as theirs is, because a cookie's scope has none.
|
|
13
|
+
*/
|
|
14
|
+
export declare const rolloutCookieName: (host: string | undefined) => string;
|
|
15
|
+
/** `newCheckout:37,beta:5` — a flag's name and the visitor's place; nothing else survives the parse. */
|
|
16
|
+
export declare const parseRolloutList: (value: string | undefined) => RolloutBuckets;
|
|
17
|
+
export declare const serializeRolloutList: (buckets: RolloutBuckets) => string;
|
|
18
|
+
/** The places a visitor kept, from a `Cookie` header or `document.cookie`. */
|
|
19
|
+
export declare const keptRollout: (cookies: string | undefined, host: string | undefined) => RolloutBuckets;
|
|
20
|
+
/** The cookie's whole text, as a `Set-Cookie` header and `document.cookie` take it: one writer for both. */
|
|
21
|
+
export declare const rolloutCookie: (host: string | undefined, buckets: RolloutBuckets, { secure }: {
|
|
22
|
+
secure: boolean;
|
|
23
|
+
}) => string;
|
|
24
|
+
/** The flags a space rolls out to part of its visitors: a rollout neither at 0 nor at 100, which need no place. */
|
|
25
|
+
export declare const rolledOutFlags: (declared: Schema["flags"]) => string[];
|
|
26
|
+
export type RolloutAssignment = {
|
|
27
|
+
/** The visitor's place in every flag rolled out to part of the visitors. */
|
|
28
|
+
buckets: RolloutBuckets;
|
|
29
|
+
/** The flags a place was drawn in just now — a page answered with any is the visitor's alone, and they keep it. */
|
|
30
|
+
drawn: string[];
|
|
31
|
+
};
|
|
32
|
+
/** A visitor's place in each flag rolled out: the one they kept, or one drawn now. */
|
|
33
|
+
export declare const assignRollout: (declared: Schema["flags"], kept: RolloutBuckets, random?: () => number) => RolloutAssignment;
|
|
34
|
+
/**
|
|
35
|
+
* A visitor's places in the browser: the server's (it answered the page with them), then what the cookie kept, then a
|
|
36
|
+
* place drawn here — once per page, whoever asks — for a flag none of those has: a space rendered with no server in
|
|
37
|
+
* front. `drawn` names what has to be kept in the cookie.
|
|
38
|
+
*/
|
|
39
|
+
export declare const browserRollout: (declared: Schema["flags"], server: RolloutBuckets | undefined) => RolloutAssignment;
|
|
40
|
+
/** Keeps a visitor's places in the browser, over what the cookie holds already. */
|
|
41
|
+
export declare const writeRollout: (buckets: RolloutBuckets) => void;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { isFlagName as e } from "./schemaFlag.mjs";
|
|
2
|
+
import { cookieFromHeader as t } from "../helpers/cookies.mjs";
|
|
3
|
+
// src/flags/rollout.ts
|
|
4
|
+
var n = 100, r = (e) => Number.isInteger(e) && e >= 0 && e < n, i = (e) => {
|
|
5
|
+
let t = e?.split(":")[1];
|
|
6
|
+
return t ? `plitzi_rollout_${t}` : "plitzi_rollout";
|
|
7
|
+
}, a = 15552e3, o = (t) => {
|
|
8
|
+
let n = {};
|
|
9
|
+
for (let i of t?.split(",") ?? []) {
|
|
10
|
+
let [t = "", a = ""] = i.split(":"), o = Number(a);
|
|
11
|
+
e(t) && a !== "" && r(o) && (n[t] = o);
|
|
12
|
+
}
|
|
13
|
+
return n;
|
|
14
|
+
}, s = (t) => Object.entries(t).filter(([t, n]) => e(t) && r(n)).sort(([e], [t]) => e.localeCompare(t)).map(([e, t]) => `${e}:${String(t)}`).join(","), c = (e, n) => o(t(e, i(n))), l = (e, t, { secure: n }) => [
|
|
15
|
+
`${i(e)}=${encodeURIComponent(s(t))}`,
|
|
16
|
+
"Path=/",
|
|
17
|
+
`Max-Age=${String(a)}`,
|
|
18
|
+
"SameSite=Lax",
|
|
19
|
+
...n ? ["Secure"] : []
|
|
20
|
+
].join("; "), u = (e) => Object.entries(e ?? {}).filter(([, e]) => e.rollout !== void 0 && e.rollout.percent > 0 && e.rollout.percent < 100).map(([e]) => e), d = (e, t, r = Math.random) => {
|
|
21
|
+
let i = {}, a = [];
|
|
22
|
+
for (let o of u(e)) {
|
|
23
|
+
let e = Object.hasOwn(t, o) ? t[o] : void 0;
|
|
24
|
+
e === void 0 ? (i[o] = Math.min(n - 1, Math.floor(r() * n)), a.push(o)) : i[o] = e;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
buckets: i,
|
|
28
|
+
drawn: a
|
|
29
|
+
};
|
|
30
|
+
}, f = {}, p = (e, t) => {
|
|
31
|
+
let n = typeof window > "u" ? void 0 : window.location.host, r;
|
|
32
|
+
try {
|
|
33
|
+
r = typeof document > "u" ? void 0 : document.cookie;
|
|
34
|
+
} catch {
|
|
35
|
+
r = void 0;
|
|
36
|
+
}
|
|
37
|
+
let i = d(e, {
|
|
38
|
+
...c(r, n),
|
|
39
|
+
...f,
|
|
40
|
+
...t
|
|
41
|
+
});
|
|
42
|
+
for (let e of i.drawn) f[e] = i.buckets[e];
|
|
43
|
+
return i;
|
|
44
|
+
}, m = (e) => {
|
|
45
|
+
try {
|
|
46
|
+
let t = window.location.host;
|
|
47
|
+
document.cookie = l(t, {
|
|
48
|
+
...c(document.cookie, t),
|
|
49
|
+
...e
|
|
50
|
+
}, { secure: window.location.protocol === "https:" });
|
|
51
|
+
} catch {}
|
|
52
|
+
};
|
|
53
|
+
export { d as assignRollout, p as browserRollout, c as keptRollout, o as parseRolloutList, u as rolledOutFlags, l as rolloutCookie, i as rolloutCookieName, s as serializeRolloutList, m as writeRollout };
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { SchemaFlag } from '../types';
|
|
1
|
+
import { SchemaFlag, SchemaFlagRollout } from '../types';
|
|
2
2
|
/** A flag name: what `{{ flags.<name> }}` reads, so it has to be a valid key in a template path. */
|
|
3
3
|
export declare const FLAG_NAME_PATTERN: RegExp;
|
|
4
4
|
/** A gate as authoring and MCP write it: `name` while the flag is on, `!name` while it is off. */
|
|
5
5
|
export declare const FLAG_GATE_PATTERN: RegExp;
|
|
6
6
|
export declare const isFlagName: (name: string) => boolean;
|
|
7
|
+
/** A rollout as the resolver reads one: a whole share from 0 to 100, and the answer it gives. */
|
|
8
|
+
export declare const isFlagRollout: (value: unknown) => value is SchemaFlagRollout;
|
|
7
9
|
/**
|
|
8
10
|
* Whether a value is a flag as the resolver reads it — what every writer checks before storing one: a mutation, the
|
|
9
11
|
* live channel, the linter. A rule's `when` has to be a group; whether it says anything is the linter's to warn about.
|
|
@@ -4,5 +4,5 @@ var t = "[A-Za-z_][A-Za-z0-9_]*", n = RegExp(`^${t}$`), r = RegExp(`^!?${t}$`),
|
|
|
4
4
|
"__proto__",
|
|
5
5
|
"constructor",
|
|
6
6
|
"prototype"
|
|
7
|
-
]), a = (e) => n.test(e) && !i.has(e), o = (t) => e(t) && typeof t.value == "boolean" && (t.description === void 0 || typeof t.description == "string") && Array.isArray(t.rules) && t.rules.every((t) => e(t) && typeof t.value == "boolean" && e(t.when));
|
|
8
|
-
export { r as FLAG_GATE_PATTERN, n as FLAG_NAME_PATTERN, a as isFlagName, o as isSchemaFlag };
|
|
7
|
+
]), a = (e) => n.test(e) && !i.has(e), o = (t) => e(t) && typeof t.percent == "number" && Number.isInteger(t.percent) && t.percent >= 0 && t.percent <= 100 && typeof t.value == "boolean", s = (t) => e(t) && typeof t.value == "boolean" && (t.description === void 0 || typeof t.description == "string") && Array.isArray(t.rules) && t.rules.every((t) => e(t) && typeof t.value == "boolean" && e(t.when)) && (t.rollout === void 0 || o(t.rollout));
|
|
8
|
+
export { r as FLAG_GATE_PATTERN, n as FLAG_NAME_PATTERN, a as isFlagName, o as isFlagRollout, s as isSchemaFlag };
|
package/dist/helpers/index.mjs
CHANGED
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
import e from "./fetchManifest.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { cookieFromHeader as
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
|
|
2
|
+
import { get as t } from "./lodash/get.mjs";
|
|
3
|
+
import { set as n } from "./lodash/set.mjs";
|
|
4
|
+
import { has as r } from "./lodash/has.mjs";
|
|
5
|
+
import { omit as i } from "./lodash/omit.mjs";
|
|
6
|
+
import { capitalize as a } from "./lodash/capitalize.mjs";
|
|
7
|
+
import { camelCase as o } from "./lodash/camelCase.mjs";
|
|
8
|
+
import s from "./syntaxHighlight.mjs";
|
|
9
|
+
import { TIME_GRAIN_MS as c, TIME_NOW as l } from "./twigWrapper/filters/types.mjs";
|
|
10
|
+
import { filters as u } from "./twigWrapper/filters/filters.mjs";
|
|
11
|
+
import { processTwig as d, processTwigParam as f, processTwigValue as p } from "./twigWrapper/processTwig/processTwig.mjs";
|
|
12
|
+
import { hasTemplateSyntax as m } from "./twigWrapper/tokens/hasTemplateSyntax.mjs";
|
|
13
|
+
import { hasValidToken as h } from "./twigWrapper/tokens/hasValidToken.mjs";
|
|
14
|
+
import { MAX_PARAM_PASSES as g, resolveStepParam as _ } from "./twigWrapper/processTwig/resolveStepParam.mjs";
|
|
15
|
+
import { inspectTemplate as v } from "./twigWrapper/inspectTemplate.mjs";
|
|
16
|
+
import { templatePaths as y, templateRootNames as b } from "./twigWrapper/templateRoots.mjs";
|
|
17
|
+
import { cookieFromHeader as x, documentCookies as S } from "./cookies.mjs";
|
|
18
|
+
import { deepEqual as C } from "./deepEqual/deepEqual.mjs";
|
|
19
|
+
import { elementOf as w, isElementTarget as T, isNodeTarget as E, nodeOf as D } from "./eventTarget.mjs";
|
|
20
|
+
import { INTERVAL_TRIGGER as O, MIN_INTERVAL_MS as k, intervalOf as A } from "./interval.mjs";
|
|
21
|
+
import { isRecord as j } from "./isRecord.mjs";
|
|
22
|
+
import { isUserEdit as M } from "./reducerOrigin.mjs";
|
|
23
|
+
import { ParamsFromURL as N, delay as P, emptyObject as F, getDisplayName as I, getKeyDecoded as L, getPathsFromObject as R, hexToRGB as z, isInViewport as B, makeId as V } from "./utils.mjs";
|
|
24
|
+
import { TRUSTED_TYPES_POLICIES as H, disableReactDevTools as U } from "./security.mjs";
|
|
25
|
+
import { canonicalJson as W } from "./canonicalJson.mjs";
|
|
26
|
+
import { SPACE_ROOT_CLASS as G, spaceRootOf as K } from "./spaceRoot.mjs";
|
|
27
|
+
import { IMAGE_PATH as q, IMAGE_WIDTHS as J, imageSrcSet as Y, imageUrl as X, isImageWidth as Z, isRemoteImage as Q, isResizableImage as $ } from "./images.mjs";
|
|
28
|
+
import { KEY_TRIGGER as ee, isFieldEditing as te, keyPressCombo as ne, parseKeys as re } from "./keys.mjs";
|
|
29
|
+
import { SCROLL_BEHAVIORS as ie, SCROLL_POSITIONS as ae, SCROLL_TRIGGER as oe, VIEW_TRIGGER as se, scrollDistance as ce, scrollPosition as le, scrollState as ue } from "./scroll.mjs";
|
|
30
|
+
import { NOT_COPIED_REASON as de, clipboardWriter as fe, copyText as pe } from "./clipboard.mjs";
|
|
31
|
+
import { MEMORY_STEPS as me, VCPU_STEPS as he, memoryWords as ge, mibOf as _e, millicoresOf as ve, quantityWords as ye, sizeWords as be, vcpuWords as xe } from "./resources.mjs";
|
|
32
|
+
export { q as IMAGE_PATH, J as IMAGE_WIDTHS, O as INTERVAL_TRIGGER, ee as KEY_TRIGGER, g as MAX_PARAM_PASSES, me as MEMORY_STEPS, k as MIN_INTERVAL_MS, de as NOT_COPIED_REASON, N as ParamsFromURL, ie as SCROLL_BEHAVIORS, ae as SCROLL_POSITIONS, oe as SCROLL_TRIGGER, G as SPACE_ROOT_CLASS, c as TIME_GRAIN_MS, l as TIME_NOW, H as TRUSTED_TYPES_POLICIES, he as VCPU_STEPS, se as VIEW_TRIGGER, o as camelCase, W as canonicalJson, a as capitalize, fe as clipboardWriter, x as cookieFromHeader, pe as copyText, C as deepEqual, P as delay, U as disableReactDevTools, S as documentCookies, w as elementOf, F as emptyObject, e as fetchManifest, u as filters, t as get, I as getDisplayName, L as getKeyDecoded, R as getPathsFromObject, r as has, m as hasTemplateSyntax, h as hasValidToken, z as hexToRGB, Y as imageSrcSet, X as imageUrl, v as inspectTemplate, A as intervalOf, T as isElementTarget, te as isFieldEditing, Z as isImageWidth, B as isInViewport, E as isNodeTarget, j as isRecord, Q as isRemoteImage, $ as isResizableImage, M as isUserEdit, ne as keyPressCombo, V as makeId, ge as memoryWords, _e as mibOf, ve as millicoresOf, D as nodeOf, i as omit, re as parseKeys, d as processTwig, f as processTwigParam, p as processTwigValue, ye as quantityWords, _ as resolveStepParam, ce as scrollDistance, le as scrollPosition, ue as scrollState, n as set, be as sizeWords, K as spaceRootOf, s as syntaxHighlight, y as templatePaths, b as templateRootNames, xe as vcpuWords };
|