@decocms/blocks 8.1.0-next.0 → 8.1.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -92
- package/src/index.ts +2 -12
- package/src/protocol/storage/memory.ts +1 -1
- package/src/v8/background.ts +3 -3
- package/src/v8/builtins/legacy.ts +1 -1
- package/src/v8/cli/index.ts +1 -1
- package/src/v8/fetch.ts +8 -27
- package/src/v8/remoteLoader.ts +1 -1
- package/src/v8/telemetry.ts +1 -1
- package/src/cms/applySectionConventions.ts +0 -148
- package/src/cms/blockSource.ts +0 -228
- package/src/cms/client.ts +0 -85
- package/src/cms/deferredTrigger.ts +0 -58
- package/src/cms/draftSource.ts +0 -476
- package/src/cms/index.ts +0 -180
- package/src/cms/loadDecofileDirectory.ts +0 -89
- package/src/cms/loader.ts +0 -563
- package/src/cms/registry.ts +0 -264
- package/src/cms/renderJson.ts +0 -179
- package/src/cms/resolve.ts +0 -2583
- package/src/cms/schema.ts +0 -1219
- package/src/cms/sectionLoaderContext.ts +0 -113
- package/src/cms/sectionLoaders.ts +0 -686
- package/src/cms/sectionMixins.ts +0 -153
- package/src/flags/audience.ts +0 -56
- package/src/flags/everyone.ts +0 -29
- package/src/flags/flag.ts +0 -15
- package/src/flags/multivariate/image.ts +0 -11
- package/src/flags/multivariate/message.ts +0 -11
- package/src/flags/multivariate/page.ts +0 -16
- package/src/flags/multivariate/section.ts +0 -16
- package/src/flags/multivariate.ts +0 -1
- package/src/flags/types.ts +0 -59
- package/src/flags/utils/multivariate.ts +0 -20
- package/src/hooks/Image.tsx +0 -314
- package/src/hooks/JsonLd.tsx +0 -353
- package/src/hooks/LazySection.tsx +0 -121
- package/src/hooks/LiveControls.tsx +0 -144
- package/src/hooks/Picture.tsx +0 -127
- package/src/hooks/RenderSection.tsx +0 -91
- package/src/hooks/SectionErrorFallback.tsx +0 -97
- package/src/hooks/Stats.tsx +0 -134
- package/src/hooks/index.ts +0 -35
- package/src/hooks/useLoadMore.ts +0 -100
- package/src/matchers/builtins.ts +0 -459
- package/src/matchers/countryNames.ts +0 -104
- package/src/matchers/override.ts +0 -136
- package/src/matchers/posthog.ts +0 -154
- package/src/middleware/decoState.ts +0 -55
- package/src/middleware/healthMetrics.ts +0 -133
- package/src/middleware/hydrationContext.ts +0 -79
- package/src/middleware/index.ts +0 -88
- package/src/middleware/liveness.ts +0 -21
- package/src/middleware/observability.ts +0 -800
- package/src/middleware/validateSection.ts +0 -100
- package/src/preview/DraftPreviewBadge.tsx +0 -306
- package/src/preview/decoMark.ts +0 -11
- package/src/preview/index.ts +0 -8
- package/src/sdk/abTesting.ts +0 -556
- package/src/sdk/analytics.ts +0 -147
- package/src/sdk/cacheHeaders.ts +0 -633
- package/src/sdk/cacheStorage.ts +0 -287
- package/src/sdk/cachedLoader.ts +0 -556
- package/src/sdk/clx.ts +0 -5
- package/src/sdk/cn.ts +0 -28
- package/src/sdk/composite.ts +0 -114
- package/src/sdk/cookie.ts +0 -129
- package/src/sdk/crypto.ts +0 -199
- package/src/sdk/csp.ts +0 -59
- package/src/sdk/deepOmit.ts +0 -52
- package/src/sdk/detectDevice.ts +0 -45
- package/src/sdk/djb2.ts +0 -20
- package/src/sdk/encoding.ts +0 -44
- package/src/sdk/env.ts +0 -54
- package/src/sdk/experiments.ts +0 -314
- package/src/sdk/fetchCache.ts +0 -269
- package/src/sdk/fetchTimeout.ts +0 -58
- package/src/sdk/flags.ts +0 -138
- package/src/sdk/http.ts +0 -124
- package/src/sdk/index.ts +0 -97
- package/src/sdk/inflightTimeout.ts +0 -53
- package/src/sdk/instrumentedFetch.ts +0 -362
- package/src/sdk/invoke.ts +0 -298
- package/src/sdk/logger.ts +0 -304
- package/src/sdk/mergeCacheControl.ts +0 -150
- package/src/sdk/nonce.ts +0 -46
- package/src/sdk/normalizeUrls.ts +0 -91
- package/src/sdk/observability.ts +0 -116
- package/src/sdk/otel.ts +0 -1118
- package/src/sdk/otelAdapters/clickhouseCollector.ts +0 -65
- package/src/sdk/otelAdapters.ts +0 -144
- package/src/sdk/otelHttpLog.ts +0 -419
- package/src/sdk/otelHttpMeter.ts +0 -532
- package/src/sdk/otelHttpTracer.ts +0 -543
- package/src/sdk/redirects.ts +0 -336
- package/src/sdk/requestContext.ts +0 -281
- package/src/sdk/requestContextStorage.browser.ts +0 -43
- package/src/sdk/requestContextStorage.ts +0 -35
- package/src/sdk/responseCache.ts +0 -82
- package/src/sdk/retry.ts +0 -45
- package/src/sdk/serverTimings.ts +0 -68
- package/src/sdk/signal.ts +0 -42
- package/src/sdk/sitemap.ts +0 -160
- package/src/sdk/urlRedaction.ts +0 -82
- package/src/sdk/urlUtils.ts +0 -183
- package/src/sdk/useDevice.ts +0 -89
- package/src/sdk/useDeviceContext.tsx +0 -108
- package/src/sdk/useId.ts +0 -7
- package/src/sdk/useScript.ts +0 -210
- package/src/sdk/useSuggestions.ts +0 -188
- package/src/sdk/wrapCaughtErrors.ts +0 -107
- package/src/setup.ts +0 -120
- package/src/types/index.ts +0 -53
- package/src/types/widgets.ts +0 -14
package/src/cms/sectionMixins.ts
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Section Loader Mixins
|
|
3
|
-
*
|
|
4
|
-
* Reusable section loader factories for common patterns like device detection,
|
|
5
|
-
* mobile flag injection, and search param extraction. Eliminates repetitive
|
|
6
|
-
* `(props, req) => ({ ...props, device: detectDevice(...) })` boilerplate.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* import { withDevice, withMobile, compose } from "@decocms/start/cms";
|
|
11
|
-
*
|
|
12
|
-
* registerSectionLoaders({
|
|
13
|
-
* "site/sections/Product/ProductShelf.tsx": withDevice(),
|
|
14
|
-
* "site/sections/Images/Carousel.tsx": withMobile(),
|
|
15
|
-
* "site/sections/Header/Header.tsx": compose(withDevice(), withSearchParam()),
|
|
16
|
-
* });
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
import { detectDevice } from "../sdk/detectDevice";
|
|
20
|
-
import type { SectionLoaderFn } from "./sectionLoaders";
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Mixins that derive props from the incoming request (UA, search params,
|
|
24
|
-
* cookies, geo, segment) carry this flag so the framework can warn when a
|
|
25
|
-
* site accidentally combines them with a layout-cached section — the layout
|
|
26
|
-
* cache is keyed only by component path, so the first visitor's variant
|
|
27
|
-
* would be served to all viewers for the cache TTL. See #206.
|
|
28
|
-
*/
|
|
29
|
-
type TaggedSectionLoaderFn = SectionLoaderFn & { __requestDependent?: boolean };
|
|
30
|
-
|
|
31
|
-
function tagRequestDependent(fn: SectionLoaderFn): SectionLoaderFn {
|
|
32
|
-
(fn as TaggedSectionLoaderFn).__requestDependent = true;
|
|
33
|
-
return fn;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Injects `device: "mobile" | "desktop" | "tablet"` from the request User-Agent.
|
|
38
|
-
*/
|
|
39
|
-
export function withDevice(): SectionLoaderFn {
|
|
40
|
-
return tagRequestDependent((props, req) => ({
|
|
41
|
-
...props,
|
|
42
|
-
device: detectDevice(req.headers.get("user-agent") ?? ""),
|
|
43
|
-
}));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Injects `isMobile: boolean` (true for mobile and tablet) from the request User-Agent.
|
|
48
|
-
*/
|
|
49
|
-
export function withMobile(): SectionLoaderFn {
|
|
50
|
-
return tagRequestDependent((props, req) => {
|
|
51
|
-
const d = detectDevice(req.headers.get("user-agent") ?? "");
|
|
52
|
-
return { ...props, isMobile: d === "mobile" || d === "tablet" };
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const REGEX_QUERY_VALUE = /[?&]q=([^&]*)/;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Injects `currentSearchParam: string | undefined` extracted from the `?q=` URL parameter.
|
|
60
|
-
*/
|
|
61
|
-
export function withSearchParam(): SectionLoaderFn {
|
|
62
|
-
return tagRequestDependent((props, req) => {
|
|
63
|
-
const match = req.url.match(REGEX_QUERY_VALUE);
|
|
64
|
-
return {
|
|
65
|
-
...props,
|
|
66
|
-
currentSearchParam: match ? decodeURIComponent(match[1]) : undefined,
|
|
67
|
-
};
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Composes multiple section loader mixins into a single loader.
|
|
73
|
-
* Each mixin's result is merged left-to-right (later mixins override earlier ones).
|
|
74
|
-
*
|
|
75
|
-
* Propagates the `__requestDependent` flag from any input mixin so the
|
|
76
|
-
* layout-cache contamination warning (#206) fires even when a request-
|
|
77
|
-
* dependent mixin is hidden inside a compose() chain.
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```ts
|
|
81
|
-
* compose(withDevice(), withSearchParam())
|
|
82
|
-
* // Equivalent to: (props, req) => ({ ...props, device: ..., currentSearchParam: ... })
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
export function compose(...mixins: SectionLoaderFn[]): SectionLoaderFn {
|
|
86
|
-
const composed: SectionLoaderFn = async (props, req, ctx) => {
|
|
87
|
-
let result = { ...props };
|
|
88
|
-
for (const mixin of mixins) {
|
|
89
|
-
const partial = await mixin(result, req, ctx);
|
|
90
|
-
result = { ...result, ...partial };
|
|
91
|
-
}
|
|
92
|
-
return result;
|
|
93
|
-
};
|
|
94
|
-
if (mixins.some((m) => (m as TaggedSectionLoaderFn).__requestDependent)) {
|
|
95
|
-
(composed as TaggedSectionLoaderFn).__requestDependent = true;
|
|
96
|
-
}
|
|
97
|
-
return composed;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Wraps a section module's exported `loader` so it can be composed alongside
|
|
102
|
-
* mixins like {@link withDevice}, {@link withMobile}, {@link withSearchParam}.
|
|
103
|
-
*
|
|
104
|
-
* The `modImport` argument is a lazy factory (typically `() => import("~/sections/...")`)
|
|
105
|
-
* — the module is loaded on first call. If the module does not export a
|
|
106
|
-
* `loader`, the original `props` are returned unchanged (no-op).
|
|
107
|
-
*
|
|
108
|
-
* Why this exists: the migrator and many sites lifted from Fresh declare a
|
|
109
|
-
* `loader` export on the section file (often re-exported from the inner
|
|
110
|
-
* component). That loader sets things like `url: req.url`, runs platform
|
|
111
|
-
* invocations, or calls the section's domain logic. If the section is wired
|
|
112
|
-
* in `registerSectionLoaders` with mixin-only (e.g. `withSearchParam()`),
|
|
113
|
-
* the section's own loader is silently *replaced* — its work never runs and
|
|
114
|
-
* its returned props are dropped.
|
|
115
|
-
*
|
|
116
|
-
* Compose this helper FIRST in the chain so mixin-injected props
|
|
117
|
-
* (`device`, `currentSearchParam`, …) are available to the section's loader,
|
|
118
|
-
* then the section's loader has the final word over what is returned.
|
|
119
|
-
*
|
|
120
|
-
* @example
|
|
121
|
-
* ```ts
|
|
122
|
-
* import {
|
|
123
|
-
* compose,
|
|
124
|
-
* withMobile,
|
|
125
|
-
* withSearchParam,
|
|
126
|
-
* withSectionLoader,
|
|
127
|
-
* } from "@decocms/start/cms";
|
|
128
|
-
*
|
|
129
|
-
* registerSectionLoaders({
|
|
130
|
-
* "site/sections/Product/SearchContainerV2.tsx": compose(
|
|
131
|
-
* withMobile(),
|
|
132
|
-
* withSearchParam(),
|
|
133
|
-
* withSectionLoader(() => import("~/sections/Product/SearchContainerV2")),
|
|
134
|
-
* ),
|
|
135
|
-
* });
|
|
136
|
-
* ```
|
|
137
|
-
*/
|
|
138
|
-
export function withSectionLoader(modImport: () => Promise<unknown>): SectionLoaderFn {
|
|
139
|
-
return async (props, req, ctx) => {
|
|
140
|
-
const mod = (await modImport()) as { loader?: unknown } | undefined;
|
|
141
|
-
const loader = mod?.loader;
|
|
142
|
-
if (typeof loader !== "function") return props;
|
|
143
|
-
try {
|
|
144
|
-
// Forward the compat `ctx` (issue #305) so migrated Fresh loaders that
|
|
145
|
-
// read `ctx.device`/`ctx.invoke`/`ctx.<app>` get the real 3rd argument.
|
|
146
|
-
const result = await (loader as SectionLoaderFn)(props, req, ctx);
|
|
147
|
-
return result ?? props;
|
|
148
|
-
} catch (error) {
|
|
149
|
-
console.error("[withSectionLoader] section loader threw:", error);
|
|
150
|
-
return props;
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
}
|
package/src/flags/audience.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { FlagObj, Matcher } from "./types";
|
|
2
|
-
import Flag from "./flag";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @title Site Route
|
|
6
|
-
* @titleBy pathTemplate
|
|
7
|
-
*/
|
|
8
|
-
export interface Route {
|
|
9
|
-
pathTemplate: string;
|
|
10
|
-
/**
|
|
11
|
-
* @description if true so the path will be checked against the coming from request instead of using urlpattern.
|
|
12
|
-
*/
|
|
13
|
-
isHref?: boolean;
|
|
14
|
-
handler: {
|
|
15
|
-
value: unknown;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* @title Priority
|
|
19
|
-
* @description higher priority means that this route will be used in favor of other routes with less or none priority
|
|
20
|
-
*/
|
|
21
|
-
highPriority?: boolean;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @title Routes
|
|
26
|
-
* @description Used to configure your site routes
|
|
27
|
-
*/
|
|
28
|
-
export type Routes = Route[];
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @titleBy name
|
|
32
|
-
*/
|
|
33
|
-
export interface Audience {
|
|
34
|
-
matcher: Matcher;
|
|
35
|
-
/**
|
|
36
|
-
* @title The audience name (will be used on cookies).
|
|
37
|
-
* @description Add a meaningful short word for the audience name.
|
|
38
|
-
* @minLength 3
|
|
39
|
-
* @pattern ^[A-Za-z0-9_-]+$
|
|
40
|
-
*/
|
|
41
|
-
name: string;
|
|
42
|
-
routes?: Routes;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @title Audience
|
|
47
|
-
* @description Select routes based on the matched audience.
|
|
48
|
-
*/
|
|
49
|
-
export default function Audience({ matcher, routes, name }: Audience): FlagObj<Route[]> {
|
|
50
|
-
return Flag<Route[]>({
|
|
51
|
-
matcher,
|
|
52
|
-
true: routes ?? [],
|
|
53
|
-
false: [],
|
|
54
|
-
name,
|
|
55
|
-
});
|
|
56
|
-
}
|
package/src/flags/everyone.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { FlagObj, Matcher } from "./types";
|
|
2
|
-
import Audience, { type Route, type Routes } from "./audience";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Ported from apps-start's `website/matchers/always.ts`. That file existed
|
|
6
|
-
* as its own block file only because deco-cx's old manifest system
|
|
7
|
-
* discovered matchers by scanning files; this codebase's matcher/flag
|
|
8
|
-
* mechanisms aren't file-scanned, so it's inlined here as its sole
|
|
9
|
-
* consumer. (Its `cacheable = true` export was manifest-generation
|
|
10
|
-
* metadata for that old system with no runtime consumer — dropped, same
|
|
11
|
-
* as the rest of the `date`/matcher ports in `../matchers/builtins.ts`.)
|
|
12
|
-
*/
|
|
13
|
-
const MatchAlways: Matcher = () => true;
|
|
14
|
-
|
|
15
|
-
export interface EveryoneConfig {
|
|
16
|
-
routes?: Routes;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @title Audience Everyone
|
|
21
|
-
* @description Always match regardless of the current user
|
|
22
|
-
*/
|
|
23
|
-
export default function Everyone({ routes }: EveryoneConfig): FlagObj<Route[]> {
|
|
24
|
-
return Audience({
|
|
25
|
-
matcher: MatchAlways,
|
|
26
|
-
routes: routes ?? [],
|
|
27
|
-
name: "Everyone",
|
|
28
|
-
});
|
|
29
|
-
}
|
package/src/flags/flag.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { FlagObj } from "./types";
|
|
2
|
-
|
|
3
|
-
export type Props<T> = FlagObj<T>;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @title Flag
|
|
7
|
-
*/
|
|
8
|
-
export default function Flag<T>({ matcher, name, true: T, false: F }: Props<T>): FlagObj<T> {
|
|
9
|
-
return {
|
|
10
|
-
matcher,
|
|
11
|
-
true: T,
|
|
12
|
-
false: F,
|
|
13
|
-
name,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { ImageWidget, MultivariateFlag } from "../types";
|
|
2
|
-
import multivariate, { type MultivariateProps } from "../utils/multivariate";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @title Image Variants
|
|
6
|
-
*/
|
|
7
|
-
export default function Image(
|
|
8
|
-
props: MultivariateProps<ImageWidget>,
|
|
9
|
-
): MultivariateFlag<ImageWidget> {
|
|
10
|
-
return multivariate(props);
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { MultivariateFlag } from "../types";
|
|
2
|
-
import multivariate, { type MultivariateProps } from "../utils/multivariate";
|
|
3
|
-
|
|
4
|
-
export type Message = string;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @title Message Variants
|
|
8
|
-
*/
|
|
9
|
-
export default function Message(props: MultivariateProps<Message>): MultivariateFlag<Message> {
|
|
10
|
-
return multivariate(props);
|
|
11
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { MultivariateFlag } from "../types";
|
|
2
|
-
import multivariate, { type MultivariateProps } from "../utils/multivariate";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Section type placeholder — the actual Section type is defined by the framework.
|
|
6
|
-
*/
|
|
7
|
-
type Section = unknown;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @title Page Variants
|
|
11
|
-
*/
|
|
12
|
-
export default function PageVariants(
|
|
13
|
-
props: MultivariateProps<Section[]>,
|
|
14
|
-
): MultivariateFlag<Section[]> {
|
|
15
|
-
return multivariate(props);
|
|
16
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { MultivariateFlag } from "../types";
|
|
2
|
-
import multivariate, { type MultivariateProps } from "../utils/multivariate";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Section type placeholder — the actual Section type is defined by the framework.
|
|
6
|
-
*/
|
|
7
|
-
type Section = unknown;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @title Section Variants
|
|
11
|
-
*/
|
|
12
|
-
export default function SectionVariants(
|
|
13
|
-
props: MultivariateProps<Section>,
|
|
14
|
-
): MultivariateFlag<Section> {
|
|
15
|
-
return multivariate(props);
|
|
16
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "./multivariate/page";
|
package/src/flags/types.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Types for the feature-flag primitives in this subpath.
|
|
3
|
-
*
|
|
4
|
-
* Ported from apps-start's `website/types.ts` (the flag/matcher slice only).
|
|
5
|
-
* These are intentionally self-contained: `Matcher`/`MatchContext` here are
|
|
6
|
-
* a *function-composition* matcher — a plain `(ctx) => boolean` imported and
|
|
7
|
-
* invoked directly by TS code — which is a different mechanism from
|
|
8
|
-
* `@decocms/blocks/matchers`'s CMS rule engine (`registerMatcher`/
|
|
9
|
-
* `evaluateMatcher` dispatch by name over a `Record<string, unknown>` rule
|
|
10
|
-
* against `MatcherContext` from `cms/resolve.ts`). The two don't share a
|
|
11
|
-
* context shape (this `MatchContext` has `device`/`siteId`; the CMS one
|
|
12
|
-
* doesn't), so they are not merged.
|
|
13
|
-
*/
|
|
14
|
-
import type { ImageWidget } from "../types/widgets";
|
|
15
|
-
|
|
16
|
-
export type { ImageWidget };
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Context passed to matchers at request time.
|
|
20
|
-
* The framework populates this from the incoming request.
|
|
21
|
-
*/
|
|
22
|
-
export interface MatchContext {
|
|
23
|
-
request: Request;
|
|
24
|
-
device: "mobile" | "tablet" | "desktop";
|
|
25
|
-
siteId: number;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* A matcher is a function that evaluates request context and returns a boolean.
|
|
30
|
-
*/
|
|
31
|
-
export type Matcher = (ctx: MatchContext) => boolean;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* A feature flag with a matcher and two branches.
|
|
35
|
-
* The framework evaluates the matcher at request time and selects the
|
|
36
|
-
* appropriate branch value.
|
|
37
|
-
*/
|
|
38
|
-
export interface FlagObj<T> {
|
|
39
|
-
matcher: Matcher;
|
|
40
|
-
true: T;
|
|
41
|
-
false: T;
|
|
42
|
-
name: string;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* A single variant in a multivariate flag.
|
|
47
|
-
*/
|
|
48
|
-
export interface Variant<T> {
|
|
49
|
-
matcher?: Matcher;
|
|
50
|
-
value: T;
|
|
51
|
-
weight?: number;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* A multivariate flag with multiple variants, each with its own matcher.
|
|
56
|
-
*/
|
|
57
|
-
export interface MultivariateFlag<T> {
|
|
58
|
-
variants: Variant<T>[];
|
|
59
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { MultivariateFlag, Variant } from "../types";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @title Multivariate
|
|
5
|
-
*/
|
|
6
|
-
export interface MultivariateProps<T> {
|
|
7
|
-
/**
|
|
8
|
-
* @minItems 1
|
|
9
|
-
* @addBehavior 1
|
|
10
|
-
*/
|
|
11
|
-
variants: Variant<T>[];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @title Variant
|
|
16
|
-
* @label hidden
|
|
17
|
-
*/
|
|
18
|
-
export default function multivariate<T>(props: MultivariateProps<T>): MultivariateFlag<T> {
|
|
19
|
-
return props;
|
|
20
|
-
}
|