@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.
Files changed (73) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/audiences/audiences.d.ts +78 -0
  3. package/dist/audiences/audiences.mjs +75 -0
  4. package/dist/audiences/index.d.ts +1 -0
  5. package/dist/audiences/index.mjs +1 -0
  6. package/dist/authoring/elementCallbacks.d.ts +22 -0
  7. package/dist/authoring/elementCallbacks.mjs +20 -5
  8. package/dist/authoring/index.mjs +4 -4
  9. package/dist/authoring/spaceCallbacks.mjs +46 -33
  10. package/dist/dataSource/globalSources.d.ts +8 -4
  11. package/dist/dataSource/globalSources.mjs +6 -0
  12. package/dist/experimentEvents/experimentEvents.d.ts +24 -0
  13. package/dist/experimentEvents/experimentEvents.mjs +28 -0
  14. package/dist/experimentEvents/index.d.ts +1 -0
  15. package/dist/experimentEvents/index.mjs +1 -0
  16. package/dist/experiments/experiments.d.ts +73 -0
  17. package/dist/experiments/experiments.mjs +74 -0
  18. package/dist/experiments/experimentsCookie.d.ts +26 -0
  19. package/dist/experiments/experimentsCookie.mjs +25 -0
  20. package/dist/experiments/forcedExperiments.d.ts +31 -0
  21. package/dist/experiments/forcedExperiments.mjs +41 -0
  22. package/dist/experiments/index.d.ts +3 -0
  23. package/dist/experiments/index.mjs +4 -0
  24. package/dist/flags/index.d.ts +1 -0
  25. package/dist/flags/index.mjs +6 -5
  26. package/dist/flags/react/index.d.ts +1 -0
  27. package/dist/flags/react/index.mjs +3 -1
  28. package/dist/flags/react/useFlagResolution.mjs +22 -19
  29. package/dist/flags/react/useRolloutBuckets.d.ts +9 -0
  30. package/dist/flags/react/useRolloutBuckets.mjs +19 -0
  31. package/dist/flags/resolveFlags.d.ts +10 -3
  32. package/dist/flags/resolveFlags.mjs +19 -9
  33. package/dist/flags/rollout.d.ts +41 -0
  34. package/dist/flags/rollout.mjs +53 -0
  35. package/dist/flags/schemaFlag.d.ts +3 -1
  36. package/dist/flags/schemaFlag.mjs +2 -2
  37. package/dist/helpers/index.mjs +31 -30
  38. package/dist/helpers/twigWrapper/Evaluator/Evaluator.mjs +28 -27
  39. package/dist/helpers/twigWrapper/filters/catalog/index.mjs +1 -1
  40. package/dist/helpers/twigWrapper/filters/dates.mjs +6 -6
  41. package/dist/helpers/twigWrapper/filters/filters.mjs +3 -3
  42. package/dist/helpers/twigWrapper/filters/index.mjs +4 -4
  43. package/dist/helpers/twigWrapper/filters/types.d.ts +16 -1
  44. package/dist/helpers/twigWrapper/filters/types.mjs +11 -2
  45. package/dist/helpers/twigWrapper/index.d.ts +2 -1
  46. package/dist/helpers/twigWrapper/index.mjs +4 -3
  47. package/dist/helpers/twigWrapper/templateRoots.mjs +19 -18
  48. package/dist/schema/serverElements.mjs +18 -18
  49. package/dist/schema/serverInput.mjs +6 -6
  50. package/dist/store/renderSettings.d.ts +1 -0
  51. package/dist/store/renderSettings.mjs +16 -12
  52. package/dist/store/storeHooks.d.ts +45 -45
  53. package/dist/style/styleStates.d.ts +7 -2
  54. package/dist/style/styleStates.mjs +2 -2
  55. package/dist/timeWindows/clock.d.ts +11 -0
  56. package/dist/timeWindows/clock.mjs +6 -0
  57. package/dist/timeWindows/countdown.d.ts +31 -0
  58. package/dist/timeWindows/countdown.mjs +57 -0
  59. package/dist/timeWindows/index.d.ts +3 -0
  60. package/dist/timeWindows/index.mjs +4 -0
  61. package/dist/timeWindows/timeWindows.d.ts +13 -0
  62. package/dist/timeWindows/timeWindows.mjs +10 -0
  63. package/dist/types/CommonTypes.d.ts +5 -0
  64. package/dist/types/DataSourceTypes.d.ts +1 -1
  65. package/dist/types/ElementTypes.d.ts +1 -1
  66. package/dist/types/PluginTypes.d.ts +5 -0
  67. package/dist/types/SchemaTypes.d.ts +11 -1
  68. package/dist/types/StoreTypes.d.ts +63 -0
  69. package/dist/variants/index.d.ts +1 -0
  70. package/dist/variants/index.mjs +1 -0
  71. package/dist/variants/variants.d.ts +23 -0
  72. package/dist/variants/variants.mjs +9 -0
  73. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @plitzi/sdk-shared
2
2
 
3
+ ## 0.39.13
4
+
5
+ ### Patch Changes
6
+
7
+ - 919736b: Released with every `@plitzi` package at this version. What changed in each, and what to do when you upgrade, is in
8
+ `@plitzi/cli`'s `CHANGELOG.md`: one copy of the notes, not one per package.
9
+
10
+ ## 0.39.12
11
+
12
+ ### Patch Changes
13
+
14
+ - 2f5b44d: Released with every `@plitzi` package at this version. What changed in each, and what to do when you upgrade, is in
15
+ `@plitzi/cli`'s `CHANGELOG.md`: one copy of the notes, not one per package.
16
+
3
17
  ## 0.39.11
4
18
 
5
19
  ### Patch Changes
@@ -0,0 +1,78 @@
1
+ import { FlagScope } from '../flags/resolveFlags';
2
+ import { Schema } from '../types';
3
+ export type VisitorDevice = 'mobile' | 'tablet' | 'desktop';
4
+ /**
5
+ * What an audience's rules know of the visitor beyond what a flag's do, read as `visitor.<fact>`: whether they came
6
+ * before, the language their browser asks for first (its primary subtag: `es`, `en`), the kind of device, and the
7
+ * country they are in (ISO 3166-1 alpha-2: `ES`, `MX`) — empty where nothing in front of the server says it.
8
+ */
9
+ export type VisitorFacts = {
10
+ returning: boolean;
11
+ language: string;
12
+ device: VisitorDevice;
13
+ country: string;
14
+ };
15
+ export declare const VISITOR_FACTS: readonly ["returning", "language", "device", "country"];
16
+ export type VisitorFact = (typeof VISITOR_FACTS)[number];
17
+ /** What an audience's rules are matched against: what a flag's are, and the visitor's facts. */
18
+ export type AudienceScope = FlagScope & {
19
+ visitor?: VisitorFacts;
20
+ };
21
+ /**
22
+ * The kind of device a user agent says, with the client hint `Sec-CH-UA-Mobile` (`?1`) first where the browser sends
23
+ * one. A tablet says so in its agent (`iPad`, `Tablet`) or is an Android one without `Mobile`.
24
+ */
25
+ export declare const deviceFromUserAgent: (userAgent: string | undefined, mobileHint?: string) => VisitorDevice;
26
+ /** The language a browser asks for first, by its primary subtag — `es` for `es-AR,es;q=0.9,en;q=0.8` — or none. */
27
+ export declare const languageFrom: (preferred: string | undefined) => string;
28
+ /**
29
+ * The headers a CDN in front of the server says the visitor's country in, the first one present winning: Cloudflare's,
30
+ * CloudFront's, Vercel's. A server with none in front gets none — and any visitor could send one, so a country is for
31
+ * what a page shows, never for who may see it.
32
+ */
33
+ export declare const COUNTRY_HEADERS: readonly ["cf-ipcountry", "cloudfront-viewer-country", "x-vercel-ip-country"];
34
+ /**
35
+ * A country as an edge says it, as rules compare it: two letters, upper case — `ES` for `es` — or none for what is no
36
+ * country (`XX`, unknown, and `T1`, Tor, as Cloudflare says them).
37
+ */
38
+ export declare const countryFrom: (value: string | undefined) => string;
39
+ /**
40
+ * The cookie that says when a visitor was first seen, in seconds since the epoch (UTC): what makes them returning. Named
41
+ * with the port, as the others a page keeps for its visitor are.
42
+ */
43
+ export declare const seenCookieName: (host: string | undefined) => string;
44
+ /** How long a visit lasts, at most: a visitor first seen longer ago than this is returning. */
45
+ export declare const VISIT_LENGTH_S: number;
46
+ /** When a visitor was first seen, from a `Cookie` header or `document.cookie` — none for a first visit. */
47
+ export declare const firstSeenOf: (cookies: string | undefined, host: string | undefined) => number | undefined;
48
+ /** Whether a visitor first seen then is returning now (`now` in ms). */
49
+ export declare const isReturning: (firstSeen: number | undefined, now: number) => boolean;
50
+ /** The cookie's whole text, for `document.cookie`: first seen now. */
51
+ export declare const seenCookie: (host: string | undefined, now: number, { secure }: {
52
+ secure: boolean;
53
+ }) => string;
54
+ /** A visitor's facts, as a request says them: its cookies, its agent, its languages and the country its edge said. */
55
+ export declare const visitorFactsOf: ({ cookies, host, userAgent, mobileHint, acceptLanguage, country, now }: {
56
+ cookies: string | undefined;
57
+ host: string | undefined;
58
+ userAgent: string | undefined;
59
+ mobileHint?: string;
60
+ acceptLanguage: string | undefined;
61
+ country?: string;
62
+ now: number;
63
+ }) => VisitorFacts;
64
+ /**
65
+ * The visitor facts a space's variants chosen by rules decide on, in order: what a page of it is drawn by besides the address and the
66
+ * session — so what its pages are kept apart by. Empty for a space with no audience, or none reading a fact.
67
+ */
68
+ export declare const audienceFactsUsed: (schema: Pick<Schema, "flat"> & Partial<Pick<Schema, "components">>) => VisitorFact[];
69
+ /** The facts a page is kept apart by, written as one part of a cache key: `device=mobile;language=es`. */
70
+ export declare const audienceKeyOf: (facts: VisitorFacts, used: readonly VisitorFact[]) => string;
71
+ /**
72
+ * Which of an audience's variants a visitor is shown: the first whose rule they match — one with no conditions matches
73
+ * everybody, the "everyone else" an audience ends with — or none (`-1`).
74
+ */
75
+ export declare const chooseAudienceVariant: (rules: readonly unknown[], scope: AudienceScope) => number;
76
+ export declare const browserVisitorFacts: () => VisitorFacts;
77
+ /** Says, for the visitor's next visits, when they were first seen — once: the cookie is never moved forward. */
78
+ export declare const keepFirstSeen: () => void;
@@ -0,0 +1,75 @@
1
+ import { hasConditions as e } from "../flags/resolveFlags.mjs";
2
+ import { evaluateRuleGroup as t } from "../conditions/evaluateRuleGroup.mjs";
3
+ import { cookieFromHeader as n } from "../helpers/cookies.mjs";
4
+ import { isRecord as r } from "../helpers/isRecord.mjs";
5
+ import { chooseByOf as i, variantItemsOf as a, variantsElementsOf as o } from "../variants/variants.mjs";
6
+ // src/audiences/audiences.ts
7
+ var s = [
8
+ "returning",
9
+ "language",
10
+ "device",
11
+ "country"
12
+ ], c = (e, t) => {
13
+ if (t === "?1") return "mobile";
14
+ let n = e ?? "";
15
+ return /iPad|Tablet|PlayBook|Silk|Android(?!.*Mobile)/i.test(n) ? "tablet" : /Mobi|iPhone|iPod|Android|Windows Phone/i.test(n) ? "mobile" : "desktop";
16
+ }, l = (e) => (e ?? "").split(",")[0]?.split(";")[0]?.split("-")[0]?.trim().toLowerCase() ?? "", u = [
17
+ "cf-ipcountry",
18
+ "cloudfront-viewer-country",
19
+ "x-vercel-ip-country"
20
+ ], d = (e) => {
21
+ let t = (e ?? "").trim().toUpperCase();
22
+ return /^[A-Z]{2}$/.test(t) && t !== "XX" ? t : "";
23
+ }, f = (e) => {
24
+ let t = e?.split(":")[1];
25
+ return t ? `plitzi_seen_${t}` : "plitzi_seen";
26
+ }, p = 1800, m = 31536e3, h = (e, t) => {
27
+ let r = Number(n(e, f(t)));
28
+ return Number.isInteger(r) && r > 0 ? r : void 0;
29
+ }, g = (e, t) => e !== void 0 && t / 1e3 - e > 1800, _ = (e, t, { secure: n }) => [
30
+ `${f(e)}=${String(Math.floor(t / 1e3))}`,
31
+ "Path=/",
32
+ `Max-Age=${String(m)}`,
33
+ "SameSite=Lax",
34
+ ...n ? ["Secure"] : []
35
+ ].join("; "), v = ({ cookies: e, host: t, userAgent: n, mobileHint: r, acceptLanguage: i, country: a, now: o }) => ({
36
+ returning: g(h(e, t), o),
37
+ language: l(i),
38
+ device: c(n, r),
39
+ country: d(a)
40
+ }), y = (e, t) => {
41
+ if (!r(e)) return;
42
+ let { field: n, rules: i } = e;
43
+ if (typeof n == "string" && n.startsWith("visitor.")) {
44
+ let e = s.find((e) => `visitor.${e}` === n);
45
+ e && t.add(e);
46
+ }
47
+ Array.isArray(i) && i.forEach((e) => y(e, t));
48
+ }, b = (e) => o(e).filter(({ element: e }) => i(e.attributes) === "rules").flatMap(({ element: e, flat: t }) => a(e, t)), x = (e) => {
49
+ let t = /* @__PURE__ */ new Set();
50
+ for (let n of b(e)) y(n.attributes.when, t);
51
+ return s.filter((e) => t.has(e));
52
+ }, S = (e, t) => t.map((t) => `${t}=${String(e[t])}`).join(";"), C = (n, r) => n.findIndex((n) => !e(n) || t(n, r)), w, T = () => {
53
+ if (!w) {
54
+ let e;
55
+ try {
56
+ e = document.cookie;
57
+ } catch {
58
+ e = void 0;
59
+ }
60
+ w = v({
61
+ cookies: e,
62
+ host: window.location.host,
63
+ userAgent: navigator.userAgent,
64
+ acceptLanguage: navigator.languages.join(",") || navigator.language,
65
+ now: Date.now()
66
+ });
67
+ }
68
+ return w;
69
+ }, E = () => {
70
+ try {
71
+ let e = window.location.host;
72
+ h(document.cookie, e) === void 0 && (document.cookie = _(e, Date.now(), { secure: window.location.protocol === "https:" }));
73
+ } catch {}
74
+ };
75
+ export { u as COUNTRY_HEADERS, s as VISITOR_FACTS, p as VISIT_LENGTH_S, x as audienceFactsUsed, S as audienceKeyOf, T as browserVisitorFacts, C as chooseAudienceVariant, d as countryFrom, c as deviceFromUserAgent, h as firstSeenOf, g as isReturning, E as keepFirstSeen, l as languageFrom, _ as seenCookie, f as seenCookieName, v as visitorFactsOf };
@@ -0,0 +1 @@
1
+ export * from './audiences';
@@ -0,0 +1 @@
1
+ export { COUNTRY_HEADERS, VISITOR_FACTS, VISIT_LENGTH_S, audienceFactsUsed, audienceKeyOf, browserVisitorFacts, chooseAudienceVariant, countryFrom, deviceFromUserAgent, firstSeenOf, isReturning, keepFirstSeen, languageFrom, seenCookie, seenCookieName, visitorFactsOf } from "./audiences.mjs";
@@ -77,6 +77,28 @@ export declare const FOCUS_CALLBACKS: {
77
77
  params: {};
78
78
  };
79
79
  };
80
+ /** How a `fullscreen` step moves: in or out as it is (`toggle`), or one way. */
81
+ export declare const FULLSCREEN_MODES: readonly ["toggle", "enter", "exit"];
82
+ export type FullscreenMode = (typeof FULLSCREEN_MODES)[number];
83
+ /**
84
+ * An element shown on the whole screen — a map, a board, a gallery, a video — and back. Its node names the element; a
85
+ * browser that cannot (an iPhone shows only a video so) fails the step, and the flow's `onFailure` says so.
86
+ */
87
+ export declare const FULLSCREEN_CALLBACKS: {
88
+ fullscreen: {
89
+ title: string;
90
+ type: "callback";
91
+ strictParams: true;
92
+ params: {
93
+ mode: {
94
+ type: "select";
95
+ description: string;
96
+ default: string;
97
+ options: ("enter" | "toggle" | "exit")[];
98
+ };
99
+ };
100
+ };
101
+ };
80
102
  /** The callbacks every element answers — `setState`, `scrollTo`, `scrollIntoView`, `focus`… — each with its params, as a flow's step calls them. */
81
103
  export declare const BUILTIN_ELEMENT_CALLBACKS: Record<string, BuiltinElementCallback>;
82
104
  /** The built-in element callback for an action, or undefined when the action is not a known built-in (an
@@ -68,7 +68,21 @@ var r = {
68
68
  type: "callback",
69
69
  strictParams: !0,
70
70
  params: {}
71
- } }, o = {
71
+ } }, o = [
72
+ "toggle",
73
+ "enter",
74
+ "exit"
75
+ ], s = { fullscreen: {
76
+ title: "Fullscreen",
77
+ type: "callback",
78
+ strictParams: !0,
79
+ params: { mode: {
80
+ type: "select",
81
+ description: "\"toggle\" shows it on the whole screen or, when it is already, back; \"enter\" and \"exit\" one way.",
82
+ default: "toggle",
83
+ options: [...o]
84
+ } }
85
+ } }, c = {
72
86
  setState: {
73
87
  title: "Update Element (set attribute / state)",
74
88
  type: "callback",
@@ -126,9 +140,10 @@ var r = {
126
140
  }
127
141
  },
128
142
  ...i,
129
- ...a
130
- }, s = (e) => Object.hasOwn(o, e) ? o[e] : void 0, c = (t, n) => {
131
- let r = s(t);
143
+ ...a,
144
+ ...s
145
+ }, l = (e) => Object.hasOwn(c, e) ? c[e] : void 0, u = (t, n) => {
146
+ let r = l(t);
132
147
  return r ? {
133
148
  known: !0,
134
149
  params: e(n, r.params, r.strictParams)
@@ -137,4 +152,4 @@ var r = {
137
152
  params: n
138
153
  };
139
154
  };
140
- export { o as BUILTIN_ELEMENT_CALLBACKS, a as FOCUS_CALLBACKS, i as SCROLL_CALLBACKS, c as applyElementCallback, s as getElementCallback };
155
+ export { c as BUILTIN_ELEMENT_CALLBACKS, a as FOCUS_CALLBACKS, s as FULLSCREEN_CALLBACKS, o as FULLSCREEN_MODES, i as SCROLL_CALLBACKS, u as applyElementCallback, l as getElementCallback };
@@ -1,6 +1,6 @@
1
1
  import { toBuilderParams as e, toInteractionCallback as t, toInteractionCallbacks as n } from "./builder.mjs";
2
2
  import { definePlugin as r, elementDeclaration as i, valuesOf as a } from "./declare.mjs";
3
- import { BUILTIN_ELEMENT_CALLBACKS as o, FOCUS_CALLBACKS as s, SCROLL_CALLBACKS as c, applyElementCallback as l, getElementCallback as u } from "./elementCallbacks.mjs";
4
- import { BUILTIN_PARAM_TYPES as d, hiddenParams as f, invalidParams as p, missingRequiredParams as m, reconcileParams as h } from "./paramSpec.mjs";
5
- import { NOTIFICATION_APPEARANCES as g, NOTIFICATION_DEFAULTS as _, NOTIFICATION_PLACEMENTS as v, readNotificationOptions as y, spaceCallbacks as b } from "./spaceCallbacks.mjs";
6
- export { o as BUILTIN_ELEMENT_CALLBACKS, d as BUILTIN_PARAM_TYPES, s as FOCUS_CALLBACKS, g as NOTIFICATION_APPEARANCES, _ as NOTIFICATION_DEFAULTS, v as NOTIFICATION_PLACEMENTS, c as SCROLL_CALLBACKS, l as applyElementCallback, r as definePlugin, i as elementDeclaration, u as getElementCallback, f as hiddenParams, p as invalidParams, m as missingRequiredParams, y as readNotificationOptions, h as reconcileParams, b as spaceCallbacks, e as toBuilderParams, t as toInteractionCallback, n as toInteractionCallbacks, a as valuesOf };
3
+ import { BUILTIN_ELEMENT_CALLBACKS as o, FOCUS_CALLBACKS as s, FULLSCREEN_CALLBACKS as c, FULLSCREEN_MODES as l, SCROLL_CALLBACKS as u, applyElementCallback as d, getElementCallback as f } from "./elementCallbacks.mjs";
4
+ import { BUILTIN_PARAM_TYPES as p, hiddenParams as m, invalidParams as h, missingRequiredParams as g, reconcileParams as _ } from "./paramSpec.mjs";
5
+ import { NOTIFICATION_APPEARANCES as v, NOTIFICATION_DEFAULTS as y, NOTIFICATION_PLACEMENTS as b, readNotificationOptions as x, spaceCallbacks as S } from "./spaceCallbacks.mjs";
6
+ export { o as BUILTIN_ELEMENT_CALLBACKS, p as BUILTIN_PARAM_TYPES, s as FOCUS_CALLBACKS, c as FULLSCREEN_CALLBACKS, l as FULLSCREEN_MODES, v as NOTIFICATION_APPEARANCES, y as NOTIFICATION_DEFAULTS, b as NOTIFICATION_PLACEMENTS, u as SCROLL_CALLBACKS, d as applyElementCallback, r as definePlugin, i as elementDeclaration, f as getElementCallback, m as hiddenParams, h as invalidParams, g as missingRequiredParams, x as readNotificationOptions, _ as reconcileParams, S as spaceCallbacks, e as toBuilderParams, t as toInteractionCallback, n as toInteractionCallbacks, a as valuesOf };
@@ -32,40 +32,53 @@ var e = [
32
32
  appearance: "success",
33
33
  autoDismiss: !0,
34
34
  autoDismissTimeout: 5e3
35
- }, i = { addNotification: {
36
- source: "space",
37
- title: "Add Notification",
38
- strictParams: !0,
39
- params: {
40
- content: {
41
- type: "textarea",
42
- description: "The notification text shown to the user — this is the message body. There is no separate title/message/type param.",
43
- default: "Content"
44
- },
45
- placement: {
46
- type: "select",
47
- description: "Where the toast appears on screen.",
48
- default: r.placement,
49
- options: [...e]
50
- },
51
- appearance: {
52
- type: "select",
53
- description: "Visual style of the notification: success, danger, warning or info.",
54
- default: r.appearance,
55
- options: [...t]
56
- },
57
- autoDismiss: {
58
- type: "boolean",
59
- description: "Whether the notification dismisses itself after a timeout.",
60
- default: r.autoDismiss,
35
+ }, i = {
36
+ reachGoal: {
37
+ source: "space",
38
+ title: "Reach Goal",
39
+ strictParams: !0,
40
+ params: { goal: {
41
+ type: "text",
42
+ description: "The goal reached — `signup`, `checkout`: counted in the space’s analytics as a conversion of each A/B variant the visitor is shown. Letters, digits, - and _.",
43
+ default: "signup",
61
44
  canBind: !1
62
- },
63
- autoDismissTimeout: {
64
- type: "number",
65
- description: "Milliseconds before auto-dismiss. Only applies when autoDismiss is true.",
66
- default: r.autoDismissTimeout,
67
- when: (e) => e.autoDismiss === !0
45
+ } }
46
+ },
47
+ addNotification: {
48
+ source: "space",
49
+ title: "Add Notification",
50
+ strictParams: !0,
51
+ params: {
52
+ content: {
53
+ type: "textarea",
54
+ description: "The notification text shown to the user — this is the message body. There is no separate title/message/type param.",
55
+ default: "Content"
56
+ },
57
+ placement: {
58
+ type: "select",
59
+ description: "Where the toast appears on screen.",
60
+ default: r.placement,
61
+ options: [...e]
62
+ },
63
+ appearance: {
64
+ type: "select",
65
+ description: "Visual style of the notification: success, danger, warning or info.",
66
+ default: r.appearance,
67
+ options: [...t]
68
+ },
69
+ autoDismiss: {
70
+ type: "boolean",
71
+ description: "Whether the notification dismisses itself after a timeout.",
72
+ default: r.autoDismiss,
73
+ canBind: !1
74
+ },
75
+ autoDismissTimeout: {
76
+ type: "number",
77
+ description: "Milliseconds before auto-dismiss. Only applies when autoDismiss is true.",
78
+ default: r.autoDismissTimeout,
79
+ when: (e) => e.autoDismiss === !0
80
+ }
68
81
  }
69
82
  }
70
- } };
83
+ };
71
84
  export { t as NOTIFICATION_APPEARANCES, r as NOTIFICATION_DEFAULTS, e as NOTIFICATION_PLACEMENTS, n as readNotificationOptions, i as spaceCallbacks };
@@ -6,19 +6,19 @@
6
6
  * refusing a binding to a name nothing answers to, an element that may not take one of these names as its id — so a
7
7
  * new global is a global everywhere at once.
8
8
  */
9
- export declare const GLOBAL_SOURCES: readonly ["variables", "navigation", "auth", "state", "host", "theme", "flags", "computed"];
9
+ export declare const GLOBAL_SOURCES: readonly ["variables", "navigation", "auth", "state", "host", "theme", "flags", "experiments", "time", "computed"];
10
10
  export type GlobalSource = (typeof GLOBAL_SOURCES)[number];
11
11
  /**
12
12
  * What a computed value is evaluated over: every global but `state`, which a flow hands it live, and `computed`, which
13
13
  * is what is being evaluated.
14
14
  */
15
- export declare const COMPUTED_GLOBALS: ("auth" | "host" | "navigation" | "flags" | "variables" | "theme")[];
15
+ export declare const COMPUTED_GLOBALS: ("auth" | "time" | "host" | "navigation" | "flags" | "variables" | "theme" | "experiments")[];
16
16
  /**
17
17
  * The fields of the globals whose shape the platform decides, as `GlobalSources` publishes them: a read of any other
18
18
  * — `auth.authenticated` for `auth.isAuthenticated` — resolves to nothing, and the authoring linter says so. An `open`
19
19
  * field holds whatever the page puts in it (the route's params, the signed-in account's details), so nothing below it
20
- * is a mistake. The rest of the globals are the space's own (`variables`, `flags`, `computed`, held to what it
21
- * declares) or anybody's (`state`, `host`).
20
+ * is a mistake. The rest of the globals are the space's own (`variables`, `flags`, `experiments`, `computed`, held to
21
+ * what it declares) or anybody's (`state`, `host`).
22
22
  */
23
23
  export declare const GLOBAL_SOURCE_FIELDS: {
24
24
  readonly navigation: {
@@ -40,6 +40,10 @@ export declare const GLOBAL_SOURCE_FIELDS: {
40
40
  readonly mode: "value";
41
41
  readonly resolved: "value";
42
42
  };
43
+ readonly time: {
44
+ readonly now: "value";
45
+ readonly today: "value";
46
+ };
43
47
  };
44
48
  export type ShapedGlobalSource = keyof typeof GLOBAL_SOURCE_FIELDS;
45
49
  /** What one of those globals publishes: its declared fields and no others, each one a page may leave out. */
@@ -7,6 +7,8 @@ var e = [
7
7
  "host",
8
8
  "theme",
9
9
  "flags",
10
+ "experiments",
11
+ "time",
10
12
  "computed"
11
13
  ], t = e.filter((e) => e !== "state" && e !== "computed"), n = {
12
14
  navigation: {
@@ -27,6 +29,10 @@ var e = [
27
29
  theme: {
28
30
  mode: "value",
29
31
  resolved: "value"
32
+ },
33
+ time: {
34
+ now: "value",
35
+ today: "value"
30
36
  }
31
37
  };
32
38
  export { t as COMPUTED_GLOBALS, e as GLOBAL_SOURCES, n as GLOBAL_SOURCE_FIELDS };
@@ -0,0 +1,24 @@
1
+ import { ExperimentAssignments, ExperimentVariant } from '../experiments/experiments';
2
+ /**
3
+ * The analytics event a visitor's variant is reported with, once — when it is drawn for them: one visitor of that
4
+ * variant. Reserved (`$`): a space's own `plitzi.track` names never start with it.
5
+ */
6
+ export declare const EXPERIMENT_EXPOSURE_EVENT = "$experiment";
7
+ /** The analytics event a goal is reached with (the `reachGoal` step), carrying the visitor's variants. */
8
+ export declare const GOAL_EVENT = "$goal";
9
+ /** A goal's name as a step writes it and the console shows it: what a conversion is counted under. */
10
+ export declare const isGoalName: (name: unknown) => name is string;
11
+ export declare const exposureProps: (experiment: string, variant: ExperimentVariant) => Record<string, string>;
12
+ export declare const goalProps: (goal: string, assignments: ExperimentAssignments) => Record<string, string>;
13
+ type EventProps = Readonly<Record<string, string | number | boolean>> | undefined;
14
+ /** What an exposure event says — the experiment and the variant shown — or nothing it can read. */
15
+ export declare const exposureOf: (props: EventProps) => {
16
+ experiment: string;
17
+ variant: ExperimentVariant;
18
+ } | undefined;
19
+ /** What a goal event says: the goal, and the visitor's variant of each experiment they were in when they reached it. */
20
+ export declare const goalOf: (props: EventProps) => {
21
+ goal: string;
22
+ assignments: ExperimentAssignments;
23
+ } | undefined;
24
+ export {};
@@ -0,0 +1,28 @@
1
+ import { isExperimentName as e, isExperimentVariant as t } from "../experiments/experiments.mjs";
2
+ // src/experimentEvents/experimentEvents.ts
3
+ var n = "$experiment", r = "$goal", i = "ab.", a = (e) => typeof e == "string" && /^[A-Za-z0-9_-]{1,64}$/.test(e), o = (e, t) => ({
4
+ experiment: e,
5
+ variant: t
6
+ }), s = (e, t) => ({
7
+ goal: e,
8
+ ...Object.fromEntries(Object.entries(t).map(([e, t]) => [`${i}${e}`, t]))
9
+ }), c = (n) => {
10
+ let r = n?.experiment, i = n?.variant;
11
+ return typeof r == "string" && e(r) && t(i) ? {
12
+ experiment: r,
13
+ variant: i
14
+ } : void 0;
15
+ }, l = (n) => {
16
+ let r = n?.goal;
17
+ if (!a(r)) return;
18
+ let o = {};
19
+ for (let [r, a] of Object.entries(n ?? {})) {
20
+ let n = r.slice(i.length);
21
+ r.startsWith(i) && e(n) && t(a) && (o[n] = a);
22
+ }
23
+ return {
24
+ goal: r,
25
+ assignments: o
26
+ };
27
+ };
28
+ export { n as EXPERIMENT_EXPOSURE_EVENT, r as GOAL_EVENT, c as exposureOf, o as exposureProps, l as goalOf, s as goalProps, a as isGoalName };
@@ -0,0 +1 @@
1
+ export * from './experimentEvents';
@@ -0,0 +1 @@
1
+ export { EXPERIMENT_EXPOSURE_EVENT, GOAL_EVENT, exposureOf, exposureProps, goalOf, goalProps, isGoalName } from "./experimentEvents.mjs";
@@ -0,0 +1,73 @@
1
+ import { Element, Schema } from '../types';
2
+ /** Every variant an experiment may have, by its place among the variants: A first. */
3
+ export declare const EXPERIMENT_VARIANTS: readonly ["a", "b", "c", "d", "e"];
4
+ export type ExperimentVariant = (typeof EXPERIMENT_VARIANTS)[number];
5
+ /** The variant each experiment showed this visitor, by the experiment's name — what `{{ experiments.<name> }}` reads. */
6
+ export type ExperimentAssignments = Record<string, ExperimentVariant>;
7
+ /**
8
+ * An experiment as the space declares it: each variant's weight, in order — its share of the visitors, against the
9
+ * others' — and the variant the builder's canvas shows in its place.
10
+ */
11
+ export type DeclaredExperiment = {
12
+ weights: number[];
13
+ builderVariant: ExperimentVariant;
14
+ };
15
+ /**
16
+ * An experiment's name: what `{{ experiments.<name> }}` reads, so — like a flag's — a valid key in a template path, and
17
+ * what the visitor's cookie keeps their variant under.
18
+ */
19
+ export declare const isExperimentName: (name: string) => boolean;
20
+ export declare const isExperimentVariant: (value: unknown) => value is ExperimentVariant;
21
+ /** A variant's weight as an element may hold one: a whole number from 0 to 100. 0 shows it to nobody. */
22
+ export declare const isExperimentWeight: (value: unknown) => value is number;
23
+ /** A variant's weight when it says none: every variant left as it was gets the same share. */
24
+ export declare const DEFAULT_VARIANT_WEIGHT = 50;
25
+ /** The variant at a place among the variants: A at 0. */
26
+ export declare const variantAt: (index: number) => ExperimentVariant | undefined;
27
+ /** A variant's place among the variants: 0 for A. */
28
+ export declare const indexOfVariant: (variant: ExperimentVariant) => number;
29
+ /** A variant's weight as it is read: its own, or the default share. */
30
+ export declare const weightOf: (variant: Element) => number;
31
+ /**
32
+ * Shares made whole percents that add up to 100, each in proportion to what it was: `[1, 1, 1]` is `[34, 33, 33]`,
33
+ * `[60, 30, 30]` is `[50, 25, 25]` — the points left after rounding down going to the largest remainders, the first
34
+ * first. All at 0 stay so: nothing is said of shares that give nobody anything.
35
+ */
36
+ export declare const sharesToHundred: (weights: readonly number[]) => number[];
37
+ /**
38
+ * The experiment a `variants` element chosen by chance runs: the name it is given — or, until it is given one, the
39
+ * element's own, made a name (`pricing-test` runs `pricing_test`), so a test runs as soon as it is placed. None for a
40
+ * name it was given that is not one (the linter says so).
41
+ */
42
+ export declare const experimentNameOf: (element: Pick<Element, "id" | "attributes">) => string | undefined;
43
+ /** What a `variants` element chosen by chance runs: its experiment's name and its variants' weights, A first. */
44
+ export declare const experimentOf: (element: Element, flat: Schema["flat"]) => ({
45
+ name: string;
46
+ } & DeclaredExperiment) | undefined;
47
+ /**
48
+ * Every experiment a space runs, by name — on its pages and in its components. Two elements naming the same experiment
49
+ * share it, so a visitor sees the same variant of both; the first one met gives the weights (the linter warns when
50
+ * they disagree). One answer for the server assigning variants before it draws and the browser assigning those it was
51
+ * not handed.
52
+ */
53
+ export declare const declaredExperiments: (schema: Pick<Schema, "flat"> & Partial<Pick<Schema, "components">>) => Record<string, DeclaredExperiment>;
54
+ export type ExperimentAssignment = {
55
+ /** Every declared experiment's variant for this visitor. */
56
+ assignments: ExperimentAssignments;
57
+ /**
58
+ * What the visitor keeps from now on: the variants drawn at random, the ones kept before among them. Nothing of an
59
+ * experiment decided for everybody — one variant left with a weight — which needs nothing kept.
60
+ */
61
+ kept: ExperimentAssignments;
62
+ /** The experiments drawn for this visitor just now — a page drawn with any is theirs alone, and they keep them. */
63
+ drawn: string[];
64
+ };
65
+ /**
66
+ * The variant of each experiment for one visitor. The one they kept, while it still has a weight — what they were
67
+ * shown is what their visit is measured on, so a change of weights does not move them; a new one drawn in proportion to
68
+ * the weights when they have none, or theirs was taken out (weight 0). An experiment with one variant left with a
69
+ * weight is ended: everybody sees that one (A when none has any).
70
+ */
71
+ export declare const assignExperiments: (declared: Record<string, DeclaredExperiment>, kept: ExperimentAssignments, random?: () => number) => ExperimentAssignment;
72
+ /** What the builder's canvas shows of each experiment: the variant its settings name, never a visitor's. */
73
+ export declare const builderExperiments: (declared: Record<string, DeclaredExperiment>) => ExperimentAssignments;
@@ -0,0 +1,74 @@
1
+ import { isFlagName as e } from "../flags/schemaFlag.mjs";
2
+ import { builderVariantOf as t, chooseByOf as n, variantItemsOf as r, variantsElementsOf as i } from "../variants/variants.mjs";
3
+ // src/experiments/experiments.ts
4
+ var a = [
5
+ "a",
6
+ "b",
7
+ "c",
8
+ "d",
9
+ "e"
10
+ ], o = (t) => e(t), s = (e) => a.some((t) => t === e), c = (e) => typeof e == "number" && Number.isInteger(e) && e >= 0 && e <= 100, l = 50, u = (e) => a[e], d = (e) => a.indexOf(e), f = (e) => c(e.attributes.weight) ? e.attributes.weight : 50, p = (e) => {
11
+ let t = e.reduce((e, t) => e + Math.max(0, t), 0);
12
+ if (t === 0) return e.map(() => 0);
13
+ let n = e.map((e) => Math.max(0, e) / t * 100), r = n.map(Math.floor), i = 100 - r.reduce((e, t) => e + t, 0), a = n.map((e, t) => ({
14
+ index: t,
15
+ remainder: e - Math.floor(e)
16
+ })).sort((e, t) => t.remainder - e.remainder || e.index - t.index);
17
+ for (let { index: e } of a.slice(0, i)) r[e] += 1;
18
+ return r;
19
+ }, m = (e) => {
20
+ let { experiment: t } = e.attributes;
21
+ if (t !== void 0 && t !== "") return typeof t == "string" && o(t) ? t : void 0;
22
+ let n = e.id.replace(/[^A-Za-z0-9_]/g, "_"), r = /^[0-9]/.test(n) ? `_${n}` : n;
23
+ return o(r) ? r : void 0;
24
+ }, h = (e, i) => {
25
+ if (e.definition.type !== "variants" || n(e.attributes) !== "chance") return;
26
+ let o = m(e);
27
+ if (o === void 0) return;
28
+ let s = r(e, i).slice(0, a.length).map(f);
29
+ return {
30
+ name: o,
31
+ weights: s,
32
+ builderVariant: u(t(e.attributes, s.length)) ?? "a"
33
+ };
34
+ }, g = (e) => {
35
+ let t = {};
36
+ for (let { element: n, flat: r } of i(e)) {
37
+ let e = h(n, r);
38
+ e && !(e.name in t) && (t[e.name] = {
39
+ weights: e.weights,
40
+ builderVariant: e.builderVariant
41
+ });
42
+ }
43
+ return t;
44
+ }, _ = (e) => e.flatMap((e, t) => {
45
+ let n = u(t);
46
+ return n && e > 0 ? [{
47
+ variant: n,
48
+ weight: e
49
+ }] : [];
50
+ }), v = (e, t) => {
51
+ let n = e.reduce((e, { weight: t }) => e + t, 0), r = t() * n;
52
+ for (let { variant: t, weight: n } of e) {
53
+ if (r < n) return t;
54
+ r -= n;
55
+ }
56
+ return e[e.length - 1]?.variant ?? "a";
57
+ }, y = (e, t, n = Math.random) => {
58
+ let r = {}, i = {}, a = [];
59
+ for (let [o, { weights: s }] of Object.entries(e)) {
60
+ let e = _(s);
61
+ if (e.length <= 1) {
62
+ r[o] = e[0]?.variant ?? "a";
63
+ continue;
64
+ }
65
+ let c = Object.hasOwn(t, o) ? t[o] : void 0, l = e.some(({ variant: e }) => e === c) ? c : void 0, u = l ?? v(e, n);
66
+ l === void 0 && a.push(o), r[o] = u, i[o] = u;
67
+ }
68
+ return {
69
+ assignments: r,
70
+ kept: i,
71
+ drawn: a
72
+ };
73
+ }, b = (e) => Object.fromEntries(Object.entries(e).map(([e, { builderVariant: t }]) => [e, t]));
74
+ export { l as DEFAULT_VARIANT_WEIGHT, a as EXPERIMENT_VARIANTS, y as assignExperiments, b as builderExperiments, g as declaredExperiments, m as experimentNameOf, h as experimentOf, d as indexOfVariant, o as isExperimentName, s as isExperimentVariant, c as isExperimentWeight, p as sharesToHundred, u as variantAt, f as weightOf };
@@ -0,0 +1,26 @@
1
+ import { ExperimentAssignments } from './experiments';
2
+ /**
3
+ * The cookie a visitor's variants are kept in, so a reload — or the next visit — shows them the same variant of every
4
+ * experiment.
5
+ *
6
+ * A cookie and not web storage for the reason the theme is one: the server draws the variant, so it has to know it
7
+ * before the page exists. Named with the port, like the flags a tester forces, because a cookie's scope has none.
8
+ */
9
+ export declare const experimentsCookieName: (host: string | undefined) => string;
10
+ /** How long a visitor keeps their variants: long enough to outlast an experiment, as a measurement needs. */
11
+ export declare const EXPERIMENTS_COOKIE_MAX_AGE_S: number;
12
+ /** `heroTest:b,pricing:a` — an experiment's name and its variant; nothing else survives the parse. */
13
+ export declare const parseExperimentList: (value: string | undefined) => ExperimentAssignments;
14
+ export declare const serializeExperimentList: (assignments: ExperimentAssignments) => string;
15
+ /** The variants a visitor kept, from a `Cookie` header or `document.cookie`. */
16
+ export declare const keptExperiments: (cookies: string | undefined, host: string | undefined) => ExperimentAssignments;
17
+ /**
18
+ * The cookie's whole text, as a `Set-Cookie` header and `document.cookie` take it: one writer for the server and the
19
+ * browser, so the two never keep it under different terms. Readable by the page (no `HttpOnly`) — the browser assigns
20
+ * what a page reached without the server never drew.
21
+ */
22
+ export declare const experimentsCookie: (host: string | undefined, assignments: ExperimentAssignments, { secure }: {
23
+ secure: boolean;
24
+ }) => string;
25
+ /** Keeps a visitor's variants in the browser — what a page assigned that the server did not draw. */
26
+ export declare const writeExperiments: (assignments: ExperimentAssignments) => void;