@rulecms/widget-vue 0.7.0 → 0.8.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/dist/index.d.ts CHANGED
@@ -14,7 +14,28 @@ declare type __VLS_Props = {
14
14
  };
15
15
 
16
16
  declare type __VLS_Props_2 = {
17
- publishedKey: string;
17
+ /**
18
+ * Staging/production: published key (`{environmentId}---{widgetKey}`).
19
+ * Development (`dev.` token): the live widget key itself (`widget-...`).
20
+ * Omit when `rulesetPublishedKey` is set — the ruleset picks the widget.
21
+ */
22
+ publishedKey?: string;
23
+ /**
24
+ * Staging/production: ruleset published key (`{environmentId}---ruleset-…`).
25
+ * Development (`dev.` token): the `ruleset-…` key.
26
+ */
27
+ rulesetPublishedKey?: string;
28
+ /** Any JSON object sent to the resolve endpoint. The server flattens nested objects. */
29
+ params?: WidgetSelectionParams;
30
+ /**
31
+ * `false` skips minting an anonymous id. A string is used as `params.anonId`.
32
+ * Omit it in the browser and the widget stores one in `localStorage`.
33
+ */
34
+ anonymousId?: string | false;
35
+ /** Plain published-key GET used when the resolve request fails with a network error or 5xx. */
36
+ fallbackPublishedKey?: string;
37
+ /** Defaults to `text/plain` so the browser skips the CORS preflight. */
38
+ contentType?: WidgetResolveContentType;
18
39
  token?: string;
19
40
  endpoint?: string;
20
41
  mode?: 'client-fetch' | 'pre-fetched';
@@ -22,6 +43,13 @@ declare type __VLS_Props_2 = {
22
43
  libraries?: LibraryRegistrationMap;
23
44
  componentProps?: ComponentPropsMap;
24
45
  mounts?: MountsMap;
46
+ /**
47
+ * Values copied onto every Text as `placeholderValues`, unless that column's
48
+ * `componentProps` entry already sets the key (including `null` to opt out).
49
+ */
50
+ placeholderValues?: unknown;
51
+ /** Called when a ruleset resolve returns a selection. */
52
+ onSelection?: (selection: WidgetSelection) => void;
25
53
  };
26
54
 
27
55
  declare type __VLS_Props_3 = {
@@ -36,6 +64,7 @@ declare type __VLS_Props_3 = {
36
64
  plugins: RenderComponentPlugins;
37
65
  componentProps?: ComponentPropsMap;
38
66
  mounts?: MountsMap;
67
+ placeholderValues?: unknown;
39
68
  };
40
69
 
41
70
  declare type __VLS_Props_4 = {
@@ -51,6 +80,7 @@ declare type __VLS_Props_4 = {
51
80
  plugins: RenderComponentPlugins;
52
81
  componentProps?: ComponentPropsMap;
53
82
  mounts?: MountsMap;
83
+ placeholderValues?: unknown;
54
84
  ancestorColumnIds?: string[];
55
85
  };
56
86
 
@@ -67,6 +97,7 @@ declare type __VLS_Props_5 = {
67
97
  deviceDisplayType: keyof typeof DeviceDisplayTypes;
68
98
  componentProps?: ComponentPropsMap;
69
99
  mounts?: MountsMap;
100
+ placeholderValues?: unknown;
70
101
  ancestorColumnIds?: string[];
71
102
  };
72
103
 
@@ -78,6 +109,7 @@ declare type __VLS_Props_6 = {
78
109
  plugins: RenderComponentPlugins;
79
110
  componentProps?: ComponentPropsMap;
80
111
  mounts?: MountsMap;
112
+ placeholderValues?: unknown;
81
113
  scopeIdInput?: string;
82
114
  };
83
115
 
@@ -92,6 +124,8 @@ declare type __VLS_Props_7 = {
92
124
  [key: string]: any;
93
125
  };
94
126
  widgetInstanceProps?: WidgetInstanceProps;
127
+ pageViewType?: PageViewType;
128
+ columnPath?: string;
95
129
  mounts?: MountsMap;
96
130
  };
97
131
 
@@ -293,6 +327,19 @@ export declare interface BuildWidgetFetchUrlParams {
293
327
  endpoint?: string;
294
328
  }
295
329
 
330
+ /**
331
+ * Builds the ruleset resolve URL. The token, ruleset key and params travel in
332
+ * the POST body, so the URL carries no query string. Development tokens
333
+ * (`dev.…`) hit the draft resolve route; everything else uses the published one.
334
+ */
335
+ export declare function buildWidgetResolveUrl({ token, endpoint, }: BuildWidgetResolveUrlParams): string;
336
+
337
+ export declare interface BuildWidgetResolveUrlParams {
338
+ token: string;
339
+ /** Optional override. Defaults by token: rulecms.com (dev) or widget-cache (published). */
340
+ endpoint?: string;
341
+ }
342
+
296
343
  export declare interface ChildCollection {
297
344
  publishedKey: string;
298
345
  name: string;
@@ -304,6 +351,9 @@ export declare interface ChildCollection {
304
351
  lastPublishedAt: string;
305
352
  }
306
353
 
354
+ /** Drops the in-process published-widget cache. Tests call this between cases. */
355
+ export declare function clearPublishedWidgetFetchCache(): void;
356
+
307
357
  /**
308
358
  * A Cloudinary transformation component as an object, e.g.
309
359
  * `{ c: 'fill', g: 'auto' }` serializes to `c_fill,g_auto`.
@@ -503,6 +553,13 @@ export declare const DEFAULT_CLOUDINARY_CLOUD_NAME = "rulecms";
503
553
  */
504
554
  export declare const DEFAULT_LIBRARY_ID = "default";
505
555
 
556
+ /**
557
+ * How long a published-token GET stays in the in-process cache when the caller
558
+ * sets no cache policy. Vue has no Next.js `next.revalidate`; this is the
559
+ * same 60-second default `@rulecms/widget-react` applies on the server.
560
+ */
561
+ export declare const DEFAULT_PUBLISHED_WIDGET_CACHE_MS = 60000;
562
+
506
563
  export declare const DEFAULT_ROW_GAP = "var(--sl-spacing-x-small)";
507
564
 
508
565
  export declare type DefaultAttributeValue = {
@@ -533,6 +590,9 @@ export declare const DEV_CLIENT_TOKEN_PREFIX = "dev.";
533
590
  /** Live draft client API path — no cache; reads the widget table directly. */
534
591
  export declare const DEV_WIDGET_API_PATH = "/api/v1/c/dev/widget/get";
535
592
 
593
+ /** Live draft ruleset resolve path (POST) — compiles the draft ruleset in-process. */
594
+ export declare const DEV_WIDGET_RESOLVE_API_PATH = "/api/v1/c/dev/widget/resolve";
595
+
536
596
  export declare type DeviceDisplayType = 'phone' | 'tablet' | 'desktop';
537
597
 
538
598
  export declare const DeviceDisplayTypes: {
@@ -645,27 +705,56 @@ declare interface EditPlugin {
645
705
  */
646
706
  export declare const EMBEDDED_KEY_SEPARATOR = "___";
647
707
 
648
- /** Fetch widget JSON on the server (or at build time) and return render-ready data. */
708
+ /**
709
+ * Fetch widget JSON on the server (or at build time) and return render-ready
710
+ * data. Pass `publishedKey` for one widget, or `rulesetPublishedKey` + `params`
711
+ * to let a ruleset choose (the result then carries `selection`).
712
+ */
649
713
  export declare function fetchRuleCMSWidget(params: FetchRuleCMSWidgetParams): Promise<RuleCMSWidgetData>;
650
714
 
715
+ declare interface FetchRuleCMSWidgetBaseParams {
716
+ token: string;
717
+ /**
718
+ * Optional API origin override. Omit in apps — defaults to rulecms.com for
719
+ * `dev.` tokens and widget-cache for published tokens.
720
+ */
721
+ endpoint?: string;
722
+ /**
723
+ * Pass-through to `fetch`. Published-token GETs are cached in-process for
724
+ * 60 seconds unless `cache` is `no-store`, `reload`, or `no-cache`. `dev.`
725
+ * tokens always use `cache: 'no-store'` and are never cached here. A
726
+ * `rulesetPublishedKey` resolve is a POST and is never cached.
727
+ */
728
+ fetchOptions?: RequestInit;
729
+ }
730
+
651
731
  export declare class FetchRuleCMSWidgetError extends Error {
652
732
  readonly status?: number;
653
733
  constructor(message: string, status?: number);
654
734
  }
655
735
 
656
- export declare interface FetchRuleCMSWidgetParams {
736
+ export declare type FetchRuleCMSWidgetParams = FetchRuleCMSWidgetPublishedKeyParams | FetchRuleCMSWidgetRulesetParams;
737
+
738
+ /** Fetch one widget by key through the plain GET path. */
739
+ declare interface FetchRuleCMSWidgetPublishedKeyParams extends FetchRuleCMSWidgetBaseParams {
657
740
  /**
658
741
  * Published key for staging/production tokens, or the live widget key when
659
742
  * using a `dev.`-prefixed Development token.
660
743
  */
661
744
  publishedKey: string;
662
- token: string;
663
- /**
664
- * Optional API origin override. Omit in apps — defaults to rulecms.com for
665
- * `dev.` tokens and widget-cache for published tokens.
666
- */
667
- endpoint?: string;
668
- fetchOptions?: RequestInit;
745
+ rulesetPublishedKey?: never;
746
+ params?: never;
747
+ fallbackPublishedKey?: never;
748
+ contentType?: never;
749
+ }
750
+
751
+ /**
752
+ * Let a published ruleset pick the widget from `params` (POST resolve). The
753
+ * server never invents an anonymous id — pass `params.anonId` yourself when
754
+ * experiments should bucket a known visitor.
755
+ */
756
+ declare interface FetchRuleCMSWidgetRulesetParams extends FetchRuleCMSWidgetBaseParams, WidgetResolveRequestOptions {
757
+ publishedKey?: never;
669
758
  }
670
759
 
671
760
  /**
@@ -933,6 +1022,15 @@ export declare const getNameFromWidgetKey: (widgetKey: string) => {
933
1022
  errorMessage?: string;
934
1023
  };
935
1024
 
1025
+ /**
1026
+ * Returns the anonymous id used as `params.anonId` for experiments, minting
1027
+ * and persisting one in `localStorage` on first use. Browser-only: returns
1028
+ * `undefined` outside a window (SSR) so the server never invents an id, and
1029
+ * when storage is unavailable (private mode, blocked third-party context) a
1030
+ * per-page-load id is returned without persisting.
1031
+ */
1032
+ export declare function getOrCreateAnonymousId(): string | undefined;
1033
+
936
1034
  /**
937
1035
  * Where a layer sits above a base at `baseZIndex`: the first layer takes
938
1036
  * `baseZIndex + 1`, the second `baseZIndex + 2`, and so on.
@@ -1117,6 +1215,13 @@ export declare interface LibraryCardInputs {
1117
1215
  };
1118
1216
  className?: string;
1119
1217
  widgetInstanceProps?: WidgetInstanceProps;
1218
+ /**
1219
+ * This instance's column path — enclosing collection columns first, its own
1220
+ * column id last, joined with `/`. `r-button` emits it as
1221
+ * `data-rulecms-column-path`. Absent in the composer and from releases that
1222
+ * predate it.
1223
+ */
1224
+ columnPath?: string;
1120
1225
  /**
1121
1226
  * Host-supplied map of mount name → Vue component. Only `r-mount`
1122
1227
  * reads this. Absent in the composer, and absent whenever the host
@@ -1336,6 +1441,9 @@ export declare const PUBLISHED_KEY_SEPARATOR = "---";
1336
1441
  /** Published (cached) client API path. */
1337
1442
  export declare const PUBLISHED_WIDGET_API_PATH = "/api/v1/c/widget/get";
1338
1443
 
1444
+ /** Published ruleset resolve path (POST) — picks a widget by params, returns its payload. */
1445
+ export declare const PUBLISHED_WIDGET_RESOLVE_API_PATH = "/api/v1/c/widget/resolve";
1446
+
1339
1447
  export declare type PublishedWidgetCollectionForKey = {
1340
1448
  publishedKey: string;
1341
1449
  name: string;
@@ -1483,6 +1591,9 @@ export declare interface ResolveWidgetLibrariesParams {
1483
1591
  */
1484
1592
  export declare function rowBasedPropertiesAreAssigned(row: DisplayItemRow): boolean;
1485
1593
 
1594
+ /** First-party `localStorage` key holding the SDK-generated anonymous id. */
1595
+ export declare const RULECMS_ANONYMOUS_ID_STORAGE_KEY = "rulecms_anon_id";
1596
+
1486
1597
  /** Live draft API host — RulesCMS production (never relative / local). */
1487
1598
  export declare const RULECMS_API_ORIGIN = "https://rulecms.com";
1488
1599
 
@@ -1492,6 +1603,7 @@ export declare const RULECMS_WIDGET_CONTEXT_KEY: InjectionKey<RuleCMSWidgetConte
1492
1603
 
1493
1604
  export declare const RuleCMSWidget: DefineComponent<__VLS_Props_2, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props_2> & Readonly<{}>, {
1494
1605
  mode: "client-fetch" | "pre-fetched";
1606
+ anonymousId: string | false;
1495
1607
  }, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLSpanElement>;
1496
1608
 
1497
1609
  export declare interface RuleCMSWidgetContext {
@@ -1559,6 +1671,11 @@ export declare interface RuleCMSWidgetData {
1559
1671
  * `includePositionTry` on the raw GET is `false`.
1560
1672
  */
1561
1673
  positionTry?: ProjectCssPositionTryDefinitions;
1674
+ /**
1675
+ * Present when this payload came from a ruleset resolve. A plain published-key
1676
+ * GET never sets it.
1677
+ */
1678
+ selection?: WidgetSelection;
1562
1679
  }
1563
1680
 
1564
1681
  export declare const RuleCMSWidgetProvider: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
@@ -1662,6 +1779,14 @@ export declare type SpacingSideLiteralValue = {
1662
1779
 
1663
1780
  export declare type SpacingSideValue = (SpacingSideLiteralValue & CssVariableCarrier) | CssVariableValue;
1664
1781
 
1782
+ /**
1783
+ * `JSON.stringify` with object keys sorted at every depth, so two objects with
1784
+ * the same values serialize identically regardless of insertion order. Used as
1785
+ * the effect dependency for resolve `params`: a fresh `{ b, a }` on every render
1786
+ * must not trigger a refetch when `{ a, b }` was already sent.
1787
+ */
1788
+ export declare function stableJsonStringify(value: unknown): string | undefined;
1789
+
1665
1790
  export declare const tabletModeWidth = "820px";
1666
1791
 
1667
1792
  export declare const textAlignAllowlist: readonly ["left", "center", "right", "justify", "start", "end"];
@@ -1706,6 +1831,14 @@ export declare const WIDGET_ATTRIBUTES_IGNORED_IN_COMPOSE_MODE: readonly ["width
1706
1831
  /** Published (cached) API host. */
1707
1832
  export declare const WIDGET_CACHE_API_ORIGIN = "https://widget-cache.rulecms.com";
1708
1833
 
1834
+ /**
1835
+ * The one key copied from `rulecms-widget`'s `placeholderValues` onto a card.
1836
+ * Must stay the key `r-text` reads (`PLACEHOLDER_VALUES_PROP` in
1837
+ * `@rulecms/source-components-vue`). The renderer copies the value and does
1838
+ * not look inside it.
1839
+ */
1840
+ export declare const WIDGET_PLACEHOLDER_VALUES_KEY = "placeholderValues";
1841
+
1709
1842
  /**
1710
1843
  * True when the widget carries settings that need a real DOM element to land
1711
1844
  * on, so the vertical container has to be emitted even where it would
@@ -1781,6 +1914,82 @@ export declare type WidgetOverlayLayers = {
1781
1914
  layers: Items[];
1782
1915
  };
1783
1916
 
1917
+ /**
1918
+ * `Content-Type` sent on the resolve POST. `text/plain` is CORS-safelisted, so
1919
+ * the browser skips the preflight; it is the default everywhere.
1920
+ * `application/json` is for server-to-server calls only.
1921
+ */
1922
+ export declare type WidgetResolveContentType = 'application/json' | 'text/plain';
1923
+
1924
+ /** Options shared by every ruleset-driven entry point (hook, widget, server fetch). */
1925
+ export declare interface WidgetResolveRequestOptions {
1926
+ /**
1927
+ * Staging/production: ruleset published key (`{environmentId}---ruleset-…`).
1928
+ * Development (`dev.` token): the `ruleset-…` key; a published key is
1929
+ * accepted and stripped to its `ruleset-…` suffix.
1930
+ */
1931
+ rulesetPublishedKey: string;
1932
+ /** Any JSON object. Sent as-is; the server flattens nested objects. */
1933
+ params?: WidgetSelectionParams;
1934
+ /**
1935
+ * Widget to GET through the plain published path when the resolve request
1936
+ * fails at the network level or with a 5xx. Not used on 4xx (bad token,
1937
+ * unknown ruleset…), and not needed for "no rule matched" — the ruleset's
1938
+ * own default covers that on the server.
1939
+ */
1940
+ fallbackPublishedKey?: string;
1941
+ /**
1942
+ * Defaults to `text/plain` (no CORS preflight). Use `application/json` only
1943
+ * for server-to-server calls.
1944
+ */
1945
+ contentType?: WidgetResolveContentType;
1946
+ }
1947
+
1948
+ /** Which widget a ruleset picked and why. Returned alongside the widget payload. */
1949
+ export declare interface WidgetSelection {
1950
+ rulesetPublishedKey?: string;
1951
+ rulesetVersion?: string;
1952
+ schemaVersion?: number;
1953
+ outcome: WidgetSelectionOutcome;
1954
+ /** Matched rule id, or `null` for the default / fallback-default outcomes. */
1955
+ ruleId: string | null;
1956
+ /** Experiment variant id, or `null` when the rule was not an experiment. */
1957
+ variantId: string | null;
1958
+ widgetKey: string;
1959
+ widgetPublishedKey: string;
1960
+ }
1961
+
1962
+ export declare type WidgetSelectionOutcome = 'rule' | 'default' | 'fallback-default';
1963
+
1964
+ /**
1965
+ * Any JSON object. Sent to the resolve endpoint as-is — the server flattens
1966
+ * nested objects (`user.plan`) before evaluating rules. `undefined` values are
1967
+ * allowed for ergonomics (`{ plan: user?.plan }`) and dropped by JSON.
1968
+ */
1969
+ export declare interface WidgetSelectionParams {
1970
+ [name: string]: WidgetSelectionParamValue | undefined;
1971
+ }
1972
+
1973
+ /** A JSON leaf or nested value accepted in resolve `params`. */
1974
+ declare type WidgetSelectionParamValue = string | number | boolean | null | WidgetSelectionParamValue[] | WidgetSelectionParams;
1975
+
1976
+ /**
1977
+ * Widget-wide placeholder values for one component instance.
1978
+ *
1979
+ * When the host passed `placeholderValues` on `rulecms-widget`, every instance
1980
+ * receives that object unless its own `componentProps` entry already has the
1981
+ * key. An entry that sets the key wins even when the value is `null` or
1982
+ * otherwise unusable: that is how one Text opts out. Other keys on the entry,
1983
+ * such as `onClick`, stay. The host's entry is not mutated.
1984
+ *
1985
+ * `undefined` means the widget input was omitted, which is the common case and
1986
+ * must not invent a bag.
1987
+ */
1988
+ export declare function withWidgetPlaceholderValues({ widgetInstanceProps, placeholderValues, }: {
1989
+ widgetInstanceProps?: WidgetInstanceProps;
1990
+ placeholderValues?: unknown;
1991
+ }): WidgetInstanceProps | undefined;
1992
+
1784
1993
  /**
1785
1994
  * The base's own place in the stack. Read here rather than through
1786
1995
  * objectStyleAttributeRegistry on purpose: the registry is shared with rows and