@plitzi/sdk-shared 0.39.10 → 0.39.12
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 +64 -0
- package/dist/audiences/audiences.mjs +66 -0
- package/dist/audiences/index.d.ts +1 -0
- package/dist/audiences/index.mjs +1 -0
- package/dist/authoring/spaceCallbacks.mjs +46 -33
- package/dist/dataSource/globalSources.d.ts +4 -4
- package/dist/dataSource/globalSources.mjs +1 -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 +17 -17
- 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/timeWindows/index.d.ts +1 -0
- package/dist/timeWindows/index.mjs +1 -0
- package/dist/timeWindows/timeWindows.d.ts +16 -0
- package/dist/timeWindows/timeWindows.mjs +10 -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 +59 -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 @@
|
|
|
1
|
+
export * from './timeWindows';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TIME_WINDOW_TYPE, hasTimeWindows, instantOf, isWindowBound, isWindowOpen, nextWindowChange } from "./timeWindows.mjs";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Schema } from '../types';
|
|
2
|
+
/** The element that shows what it holds only between two instants. */
|
|
3
|
+
export declare const TIME_WINDOW_TYPE = "timeWindow";
|
|
4
|
+
/**
|
|
5
|
+
* The instant a window's bound names, in ms since the epoch — or `undefined` for one left empty or written without its
|
|
6
|
+
* offset: a time with no zone is a different instant for every visitor, so it is never read as one.
|
|
7
|
+
*/
|
|
8
|
+
export declare const instantOf: (value: unknown) => number | undefined;
|
|
9
|
+
/** Whether a bound is written as an instant the window can read: empty (no bound) or ISO 8601 with its offset. */
|
|
10
|
+
export declare const isWindowBound: (value: unknown) => boolean;
|
|
11
|
+
/** Whether a window is open at `now`: from its start (none, always started) up to its end (none, never ended). */
|
|
12
|
+
export declare const isWindowOpen: (now: number, from: unknown, until: unknown) => boolean;
|
|
13
|
+
/** The next instant after `now` a window opens or closes at — what a page waits for to show or hide it — or none. */
|
|
14
|
+
export declare const nextWindowChange: (now: number, from: unknown, until: unknown) => number | undefined;
|
|
15
|
+
/** Whether a space has a time window, on its pages or in its components: its pages are drawn at an instant. */
|
|
16
|
+
export declare const hasTimeWindows: (schema: Pick<Schema, "flat"> & Partial<Pick<Schema, "components">>) => boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/timeWindows/timeWindows.ts
|
|
2
|
+
var e = "timeWindow", t = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/, n = (e) => {
|
|
3
|
+
if (typeof e != "string" || !t.test(e)) return;
|
|
4
|
+
let n = Date.parse(e);
|
|
5
|
+
return Number.isNaN(n) ? void 0 : n;
|
|
6
|
+
}, r = (e) => e === void 0 || e === "" || n(e) !== void 0, i = (e, t, r) => {
|
|
7
|
+
let i = n(t), a = n(r);
|
|
8
|
+
return (i === void 0 || e >= i) && (a === void 0 || e < a);
|
|
9
|
+
}, a = (e, t, r) => [n(t), n(r)].filter((t) => t !== void 0 && t > e).sort((e, t) => e - t)[0], o = (t) => [t.flat, ...Object.values(t.components ?? {}).map((e) => e.flat)].some((t) => Object.values(t).some((t) => t.definition.type === e));
|
|
10
|
+
export { e as TIME_WINDOW_TYPE, o as hasTimeWindows, n as instantOf, r as isWindowBound, i as isWindowOpen, a as nextWindowChange };
|
|
@@ -22,7 +22,7 @@ export type InternalPropsSTG1<T extends InternalPropsExtension = InternalPropsEx
|
|
|
22
22
|
plitziElementLayout?: ElementLayout;
|
|
23
23
|
attributes?: Element['attributes'];
|
|
24
24
|
};
|
|
25
|
-
export type ComponentDefinition = Pick<PluginSchema, 'attributes' | 'builder' | 'definition' | 'defaultStyle' | 'initialItems' | 'contentAttributes'> & {
|
|
25
|
+
export type ComponentDefinition = Pick<PluginSchema, 'attributes' | 'builder' | 'definition' | 'defaultStyle' | 'initialItems' | 'contentAttributes' | 'ancestorType'> & {
|
|
26
26
|
assets: Asset[];
|
|
27
27
|
assetsSettings: Omit<Asset, 'isMain'>[];
|
|
28
28
|
manifest: PluginManifest;
|
|
@@ -8,6 +8,11 @@ export type PluginSchema = {
|
|
|
8
8
|
definition: Element['definition'];
|
|
9
9
|
/** The attributes a role that edits the content and not the design may change; none, it may change none. */
|
|
10
10
|
contentAttributes?: string[];
|
|
11
|
+
/**
|
|
12
|
+
* The element this one only works somewhere inside — a carousel's track, an A/B test's variant: the builder's
|
|
13
|
+
* catalogue lists it after that one, as a part of it.
|
|
14
|
+
*/
|
|
15
|
+
ancestorType?: string;
|
|
11
16
|
defaultStyle: {
|
|
12
17
|
name: string;
|
|
13
18
|
displayMode: DisplayMode;
|
|
@@ -176,9 +176,19 @@ export type SchemaFlagRule = {
|
|
|
176
176
|
*/
|
|
177
177
|
export type SchemaFlag = {
|
|
178
178
|
description?: string;
|
|
179
|
-
/** The answer when no rule matches. */
|
|
179
|
+
/** The answer when no rule matches — and no rollout takes the visitor in. */
|
|
180
180
|
value: boolean;
|
|
181
181
|
rules: SchemaFlagRule[];
|
|
182
|
+
/**
|
|
183
|
+
* A gradual rollout, read when no rule matches: `percent` of the visitors (0–100) get `value`, the rest the flag's own
|
|
184
|
+
* `value`. Each visitor is kept in their place by a cookie, so raising the percent keeps everyone who was in.
|
|
185
|
+
*/
|
|
186
|
+
rollout?: SchemaFlagRollout;
|
|
187
|
+
};
|
|
188
|
+
/** A share of the visitors a flag answers `value` for, when none of its rules matched. */
|
|
189
|
+
export type SchemaFlagRollout = {
|
|
190
|
+
percent: number;
|
|
191
|
+
value: boolean;
|
|
182
192
|
};
|
|
183
193
|
export type PageFolder = {
|
|
184
194
|
id: string;
|
|
@@ -9,7 +9,10 @@ import { SpaceConnector } from './SpaceTypes';
|
|
|
9
9
|
import { DisplayMode, Style, StylePseudo, StyleState } from './StyleTypes';
|
|
10
10
|
import { SignedInTestAccount } from './TestTypes';
|
|
11
11
|
import { ColorScheme, Theme } from './ThemeTypes';
|
|
12
|
+
import { VisitorFacts } from '../audiences/audiences';
|
|
13
|
+
import { ExperimentAssignments } from '../experiments/experiments';
|
|
12
14
|
import { FlagOverrides, FlagResolution } from '../flags/resolveFlags';
|
|
15
|
+
import { RolloutBuckets } from '../flags/rollout';
|
|
13
16
|
/** Where a site's badge leads: who made it, and where to report one that abuses its address — the deployment's own. */
|
|
14
17
|
export type BadgeLinks = {
|
|
15
18
|
madeWith: string;
|
|
@@ -29,6 +32,7 @@ export type RuntimeSourceValues = {
|
|
|
29
32
|
resolved: ColorScheme;
|
|
30
33
|
};
|
|
31
34
|
flags?: Record<string, boolean>;
|
|
35
|
+
experiments?: ExperimentAssignments;
|
|
32
36
|
};
|
|
33
37
|
/**
|
|
34
38
|
* The feature flags of this render: what each layer above the space says, and how every flag resolved.
|
|
@@ -46,10 +50,32 @@ export type NavigateHow = {
|
|
|
46
50
|
};
|
|
47
51
|
export type FlagsState = {
|
|
48
52
|
overrides?: FlagOverrides;
|
|
53
|
+
/** Where the visitor stands in the space's gradual rollouts, as the server that drew the page answered them. */
|
|
54
|
+
rollout?: RolloutBuckets;
|
|
49
55
|
/** Each declared flag's answer and the layer that gave it — what the dev tools show. The values alone are the
|
|
50
56
|
* `flags` source. */
|
|
51
57
|
resolved?: Record<string, FlagResolution>;
|
|
52
58
|
};
|
|
59
|
+
/**
|
|
60
|
+
* The A/B tests of this render. Top-level for the reason `flags` is: the server's answer is written at the root by
|
|
61
|
+
* whoever mounts the SDK, and an element scope owning `runtime` would keep a write from any depth to itself.
|
|
62
|
+
*/
|
|
63
|
+
export type ExperimentsState = {
|
|
64
|
+
/** The variants the server drew the page with — the browser hydrates with these, never a draw of its own. */
|
|
65
|
+
server?: ExperimentAssignments;
|
|
66
|
+
/**
|
|
67
|
+
* The variants a tester forced (the dev tools' Experiments tab, an address's `?ab=`), only where debugging is
|
|
68
|
+
* authorized: shown over the visitor's, never kept as theirs.
|
|
69
|
+
*/
|
|
70
|
+
qa?: ExperimentAssignments;
|
|
71
|
+
/** Every experiment's variant on this page: the forced ones, the server's, the visitor's kept and any drawn here. */
|
|
72
|
+
assigned?: ExperimentAssignments;
|
|
73
|
+
/**
|
|
74
|
+
* The experiments drawn for this visitor on this page — by the server that drew it, or here: each reported once to
|
|
75
|
+
* the space's analytics as one visitor of the variant drawn.
|
|
76
|
+
*/
|
|
77
|
+
drawn?: string[];
|
|
78
|
+
};
|
|
53
79
|
export type CommonState = {
|
|
54
80
|
schema: Schema;
|
|
55
81
|
pageDefinitions: Record<string, Element>;
|
|
@@ -76,6 +102,20 @@ export type CommonState = {
|
|
|
76
102
|
sources?: Record<string, Source>;
|
|
77
103
|
rsc?: RscState;
|
|
78
104
|
flags?: FlagsState;
|
|
105
|
+
experiments?: ExperimentsState;
|
|
106
|
+
/**
|
|
107
|
+
* What the space's audiences know of the visitor — returning, language, device — as the server that drew the page read
|
|
108
|
+
* them from the request. Absent where no server drew it: the browser reads them itself (`browserVisitorFacts`).
|
|
109
|
+
*/
|
|
110
|
+
visitor?: VisitorFacts;
|
|
111
|
+
/**
|
|
112
|
+
* The instant this page is drawn at, for what shows by the time (`timeWindow`): the server's, when it drew the page —
|
|
113
|
+
* the page hydrates at it, then follows its own clock — or the one the builder simulates (`simulated`), which it keeps.
|
|
114
|
+
*/
|
|
115
|
+
clock?: {
|
|
116
|
+
at: number;
|
|
117
|
+
simulated?: boolean;
|
|
118
|
+
};
|
|
79
119
|
actions?: ActionsState;
|
|
80
120
|
/** Where this origin's realtime channels answer — absent in a render with no server, where no channel opens. */
|
|
81
121
|
realtime?: {
|
|
@@ -140,6 +180,11 @@ export type CommonState = {
|
|
|
140
180
|
export type RenderSettings = {
|
|
141
181
|
previewMode?: boolean;
|
|
142
182
|
debugMode?: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* The space is drawn in the builder's canvas: what a visitor is assigned there is the author's to choose instead —
|
|
185
|
+
* an A/B test shows the variant its settings name (`builderVariant`), and nothing is drawn or kept for a visitor.
|
|
186
|
+
*/
|
|
187
|
+
builder?: boolean;
|
|
143
188
|
renderMode?: RenderMode;
|
|
144
189
|
environment?: Environment;
|
|
145
190
|
isHydrating?: boolean;
|
|
@@ -313,6 +358,20 @@ export type BuilderState = CommonState & {
|
|
|
313
358
|
* Editor-only and never published; a journey on the canvas decides its own visitor.
|
|
314
359
|
*/
|
|
315
360
|
canvasGuest?: boolean;
|
|
361
|
+
/**
|
|
362
|
+
* What the canvas's visitor is, for the space's audiences, as chosen in the State Manager's Visitor tab — over what
|
|
363
|
+
* the builder says by itself: the device the canvas is sized as, the editor's language, a first visit. Editor-only and
|
|
364
|
+
* never published; the canvas's preview shows the variants this visitor matches.
|
|
365
|
+
*/
|
|
366
|
+
visitorSimulation?: Partial<VisitorFacts>;
|
|
367
|
+
/** The instant the canvas's preview is shown at, chosen in the Visitor tab — the editor's clock until then. */
|
|
368
|
+
simulatedAt?: number;
|
|
369
|
+
/**
|
|
370
|
+
* The A/B tests whose variant the canvas's preview shows was picked by hand, its shares set aside. Every other is drawn
|
|
371
|
+
* by them, as a visitor's page draws it — the variant laid in `experiments.qa` — kept across a reload as a visitor's
|
|
372
|
+
* cookie keeps it, drawn again for a new visitor. Editor-only and never published.
|
|
373
|
+
*/
|
|
374
|
+
previewPicked?: string[];
|
|
316
375
|
displayMode: DisplayMode;
|
|
317
376
|
selector?: string;
|
|
318
377
|
styleSelector?: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './variants';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CHOOSE_BY, VARIANTS_TYPE, VARIANT_ITEM_TYPE, builderVariantOf, chooseByOf, isChooseBy, variantItemsOf, variantsElementsOf } from "./variants.mjs";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Element, Schema } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* The element that shows each visitor one of its variants — chosen by chance (an A/B test: each variant a share of the
|
|
4
|
+
* visitors, a visitor kept on theirs) or by rules (who the visitor is: the first variant whose rule they match).
|
|
5
|
+
*/
|
|
6
|
+
export declare const VARIANTS_TYPE = "variants";
|
|
7
|
+
/** Its parts, in order: each with its share (`weight`) for the chance and its rule (`when`) for the rules. */
|
|
8
|
+
export declare const VARIANT_ITEM_TYPE = "variantItem";
|
|
9
|
+
/** How a `variants` element chooses: at random by the variants' shares, or by the visitor's facts. */
|
|
10
|
+
export declare const CHOOSE_BY: readonly ["chance", "rules"];
|
|
11
|
+
export type ChooseBy = (typeof CHOOSE_BY)[number];
|
|
12
|
+
export declare const isChooseBy: (value: unknown) => value is ChooseBy;
|
|
13
|
+
/** What a `variants` element chooses by: chance, unless it says rules. */
|
|
14
|
+
export declare const chooseByOf: (attributes: Element["attributes"]) => ChooseBy;
|
|
15
|
+
/** A `variants` element's variants, in order: its items of the variant type. */
|
|
16
|
+
export declare const variantItemsOf: (element: Element, flat: Schema["flat"]) => Element[];
|
|
17
|
+
/** The place (from 0) of the variant the builder's canvas shows while editing: one it has, the first otherwise. */
|
|
18
|
+
export declare const builderVariantOf: (attributes: Element["attributes"], count: number) => number;
|
|
19
|
+
/** Every `variants` element of a space — its pages' tree and each component's — with the tree it is in. */
|
|
20
|
+
export declare const variantsElementsOf: (schema: Pick<Schema, "flat"> & Partial<Pick<Schema, "components">>) => {
|
|
21
|
+
element: Element;
|
|
22
|
+
flat: Schema["flat"];
|
|
23
|
+
}[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// src/variants/variants.ts
|
|
2
|
+
var e = "variants", t = "variantItem", n = ["chance", "rules"], r = (e) => n.some((t) => t === e), i = (e) => r(e.chooseBy) ? e.chooseBy : "chance", a = (e, t) => (e.definition.items ?? []).filter((e) => Object.hasOwn(t, e) && t[e].definition.type === "variantItem").map((e) => t[e]), o = (e, t) => {
|
|
3
|
+
let { builderVariant: n } = e;
|
|
4
|
+
return typeof n == "number" && Number.isInteger(n) && n >= 0 && n < t ? n : 0;
|
|
5
|
+
}, s = (t) => [t.flat, ...Object.values(t.components ?? {}).map((e) => e.flat)].flatMap((t) => Object.values(t).filter((t) => t.definition.type === e).map((e) => ({
|
|
6
|
+
element: e,
|
|
7
|
+
flat: t
|
|
8
|
+
})));
|
|
9
|
+
export { n as CHOOSE_BY, e as VARIANTS_TYPE, t as VARIANT_ITEM_TYPE, o as builderVariantOf, i as chooseByOf, r as isChooseBy, a as variantItemsOf, s as variantsElementsOf };
|