@rulecms/widget-svelte 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
@@ -180,6 +180,19 @@ export declare interface BuildWidgetFetchUrlParams {
180
180
  endpoint?: string;
181
181
  }
182
182
 
183
+ /**
184
+ * Builds the ruleset resolve URL. The token, ruleset key and params travel in
185
+ * the POST body, so the URL carries no query string. Development tokens
186
+ * (`dev.…`) hit the draft resolve route; everything else uses the published one.
187
+ */
188
+ export declare function buildWidgetResolveUrl({ token, endpoint, }: BuildWidgetResolveUrlParams): string;
189
+
190
+ export declare interface BuildWidgetResolveUrlParams {
191
+ token: string;
192
+ /** Optional override. Defaults by token: rulecms.com (dev) or widget-cache (published). */
193
+ endpoint?: string;
194
+ }
195
+
183
196
  export declare interface ChildCollection {
184
197
  publishedKey: string;
185
198
  name: string;
@@ -191,6 +204,9 @@ export declare interface ChildCollection {
191
204
  lastPublishedAt: string;
192
205
  }
193
206
 
207
+ /** Drops the in-process published-widget cache. Tests call this between cases. */
208
+ export declare function clearPublishedWidgetFetchCache(): void;
209
+
194
210
  /**
195
211
  * A Cloudinary transformation component as an object, e.g.
196
212
  * `{ c: 'fill', g: 'auto' }` serializes to `c_fill,g_auto`.
@@ -390,6 +406,13 @@ export declare const DEFAULT_CLOUDINARY_CLOUD_NAME = "rulecms";
390
406
  */
391
407
  export declare const DEFAULT_LIBRARY_ID = "default";
392
408
 
409
+ /**
410
+ * How long a published-token GET stays in the in-process cache when the caller
411
+ * sets no cache policy. Svelte has no Next.js `next.revalidate`; this is the
412
+ * same 60-second default `@rulecms/widget-react` applies on the server.
413
+ */
414
+ export declare const DEFAULT_PUBLISHED_WIDGET_CACHE_MS = 60000;
415
+
393
416
  export declare const DEFAULT_ROW_GAP = "var(--sl-spacing-x-small)";
394
417
 
395
418
  export declare type DefaultAttributeValue = {
@@ -420,6 +443,9 @@ export declare const DEV_CLIENT_TOKEN_PREFIX = "dev.";
420
443
  /** Live draft client API path — no cache; reads the widget table directly. */
421
444
  export declare const DEV_WIDGET_API_PATH = "/api/v1/c/dev/widget/get";
422
445
 
446
+ /** Live draft ruleset resolve path (POST) — compiles the draft ruleset in-process. */
447
+ export declare const DEV_WIDGET_RESOLVE_API_PATH = "/api/v1/c/dev/widget/resolve";
448
+
423
449
  export declare type DeviceDisplayType = 'phone' | 'tablet' | 'desktop';
424
450
 
425
451
  export declare const DeviceDisplayTypes: {
@@ -530,27 +556,56 @@ declare interface EditPlugin {
530
556
  */
531
557
  export declare const EMBEDDED_KEY_SEPARATOR = "___";
532
558
 
533
- /** Fetch widget JSON on the server (or at build time) and return render-ready data. */
559
+ /**
560
+ * Fetch widget JSON on the server (or at build time) and return render-ready
561
+ * data. Pass `publishedKey` for one widget, or `rulesetPublishedKey` + `params`
562
+ * to let a ruleset choose (the result then carries `selection`).
563
+ */
534
564
  export declare function fetchRuleCMSWidget(params: FetchRuleCMSWidgetParams): Promise<RuleCMSWidgetData>;
535
565
 
566
+ declare interface FetchRuleCMSWidgetBaseParams {
567
+ token: string;
568
+ /**
569
+ * Optional API origin override. Omit in apps — defaults to rulecms.com for
570
+ * `dev.` tokens and widget-cache for published tokens.
571
+ */
572
+ endpoint?: string;
573
+ /**
574
+ * Pass-through to `fetch`. Published-token GETs are cached in-process for
575
+ * 60 seconds unless `cache` is `no-store`, `reload`, or `no-cache`. `dev.`
576
+ * tokens always use `cache: 'no-store'` and are never cached here. A
577
+ * `rulesetPublishedKey` resolve is a POST and is never cached.
578
+ */
579
+ fetchOptions?: RequestInit;
580
+ }
581
+
536
582
  export declare class FetchRuleCMSWidgetError extends Error {
537
583
  readonly status?: number;
538
584
  constructor(message: string, status?: number);
539
585
  }
540
586
 
541
- export declare interface FetchRuleCMSWidgetParams {
587
+ export declare type FetchRuleCMSWidgetParams = FetchRuleCMSWidgetPublishedKeyParams | FetchRuleCMSWidgetRulesetParams;
588
+
589
+ /** Fetch one widget by key through the plain GET path. */
590
+ declare interface FetchRuleCMSWidgetPublishedKeyParams extends FetchRuleCMSWidgetBaseParams {
542
591
  /**
543
592
  * Published key for staging/production tokens, or the live widget key when
544
593
  * using a `dev.`-prefixed Development token.
545
594
  */
546
595
  publishedKey: string;
547
- token: string;
548
- /**
549
- * Optional API origin override. Omit in apps — defaults to rulecms.com for
550
- * `dev.` tokens and widget-cache for published tokens.
551
- */
552
- endpoint?: string;
553
- fetchOptions?: RequestInit;
596
+ rulesetPublishedKey?: never;
597
+ params?: never;
598
+ fallbackPublishedKey?: never;
599
+ contentType?: never;
600
+ }
601
+
602
+ /**
603
+ * Let a published ruleset pick the widget from `params` (POST resolve). The
604
+ * server never invents an anonymous id — pass `params.anonId` yourself when
605
+ * experiments should bucket a known visitor.
606
+ */
607
+ declare interface FetchRuleCMSWidgetRulesetParams extends FetchRuleCMSWidgetBaseParams, WidgetResolveRequestOptions {
608
+ publishedKey?: never;
554
609
  }
555
610
 
556
611
  /**
@@ -818,6 +873,15 @@ export declare const getNameFromWidgetKey: (widgetKey: string) => {
818
873
  errorMessage?: string;
819
874
  };
820
875
 
876
+ /**
877
+ * Returns the anonymous id used as `params.anonId` for experiments, minting
878
+ * and persisting one in `localStorage` on first use. Browser-only: returns
879
+ * `undefined` outside a window (SSR) so the server never invents an id, and
880
+ * when storage is unavailable (private mode, blocked third-party context) a
881
+ * per-page-load id is returned without persisting.
882
+ */
883
+ export declare function getOrCreateAnonymousId(): string | undefined;
884
+
821
885
  /**
822
886
  * Where a layer sits above a base at `baseZIndex`: the first layer takes
823
887
  * `baseZIndex + 1`, the second `baseZIndex + 2`, and so on.
@@ -1002,6 +1066,13 @@ export declare interface LibraryCardInputs {
1002
1066
  };
1003
1067
  className?: string;
1004
1068
  widgetInstanceProps?: WidgetInstanceProps;
1069
+ /**
1070
+ * This instance's column path — enclosing collection columns first, its own
1071
+ * column id last, joined with `/`. `r-button` emits it as
1072
+ * `data-rulecms-column-path`. Absent in the composer and from releases that
1073
+ * predate it.
1074
+ */
1075
+ columnPath?: string;
1005
1076
  /**
1006
1077
  * Host-supplied map of mount name → Svelte component. Only `r-mount`
1007
1078
  * reads this. Absent in the composer, and absent whenever the host
@@ -1221,6 +1292,9 @@ export declare const PUBLISHED_KEY_SEPARATOR = "---";
1221
1292
  /** Published (cached) client API path. */
1222
1293
  export declare const PUBLISHED_WIDGET_API_PATH = "/api/v1/c/widget/get";
1223
1294
 
1295
+ /** Published ruleset resolve path (POST) — picks a widget by params, returns its payload. */
1296
+ export declare const PUBLISHED_WIDGET_RESOLVE_API_PATH = "/api/v1/c/widget/resolve";
1297
+
1224
1298
  export declare type PublishedWidgetCollectionForKey = {
1225
1299
  publishedKey: string;
1226
1300
  name: string;
@@ -1358,6 +1432,9 @@ export declare interface ResolveWidgetLibrariesParams {
1358
1432
  */
1359
1433
  export declare function rowBasedPropertiesAreAssigned(row: DisplayItemRow): boolean;
1360
1434
 
1435
+ /** First-party `localStorage` key holding the SDK-generated anonymous id. */
1436
+ export declare const RULECMS_ANONYMOUS_ID_STORAGE_KEY = "rulecms_anon_id";
1437
+
1361
1438
  /** Live draft API host — RulesCMS production (never relative / local). */
1362
1439
  export declare const RULECMS_API_ORIGIN = "https://rulecms.com";
1363
1440
 
@@ -1430,6 +1507,11 @@ export declare interface RuleCMSWidgetData {
1430
1507
  * `includePositionTry` on the raw GET is `false`.
1431
1508
  */
1432
1509
  positionTry?: ProjectCssPositionTryDefinitions;
1510
+ /**
1511
+ * Present when this payload came from a ruleset resolve. A plain published-key
1512
+ * GET never sets it.
1513
+ */
1514
+ selection?: WidgetSelection;
1433
1515
  }
1434
1516
 
1435
1517
  export declare interface RuleCMSWidgetRawData {
@@ -1531,6 +1613,14 @@ export declare type SpacingSideLiteralValue = {
1531
1613
 
1532
1614
  export declare type SpacingSideValue = (SpacingSideLiteralValue & CssVariableCarrier) | CssVariableValue;
1533
1615
 
1616
+ /**
1617
+ * `JSON.stringify` with object keys sorted at every depth, so two objects with
1618
+ * the same values serialize identically regardless of insertion order. Used as
1619
+ * the effect dependency for resolve `params`: a fresh `{ b, a }` on every render
1620
+ * must not trigger a refetch when `{ a, b }` was already sent.
1621
+ */
1622
+ export declare function stableJsonStringify(value: unknown): string | undefined;
1623
+
1534
1624
  export { SvelteComponent as BreakpointVariantRender }
1535
1625
  export { SvelteComponent as DisplayComponent }
1536
1626
  export { SvelteComponent as RenderComponents }
@@ -1586,6 +1676,14 @@ export declare const WIDGET_ATTRIBUTES_IGNORED_IN_COMPOSE_MODE: readonly ["width
1586
1676
  /** Published (cached) API host. */
1587
1677
  export declare const WIDGET_CACHE_API_ORIGIN = "https://widget-cache.rulecms.com";
1588
1678
 
1679
+ /**
1680
+ * The one key copied from `rulecms-widget`'s `placeholderValues` onto a card.
1681
+ * Must stay the key `r-text` reads (`PLACEHOLDER_VALUES_PROP` in
1682
+ * `@rulecms/source-components-svelte`). The renderer copies the value and does
1683
+ * not look inside it.
1684
+ */
1685
+ export declare const WIDGET_PLACEHOLDER_VALUES_KEY = "placeholderValues";
1686
+
1589
1687
  /**
1590
1688
  * True when the widget carries settings that need a real DOM element to land
1591
1689
  * on, so the vertical container has to be emitted even where it would
@@ -1661,6 +1759,82 @@ export declare type WidgetOverlayLayers = {
1661
1759
  layers: Items[];
1662
1760
  };
1663
1761
 
1762
+ /**
1763
+ * `Content-Type` sent on the resolve POST. `text/plain` is CORS-safelisted, so
1764
+ * the browser skips the preflight; it is the default everywhere.
1765
+ * `application/json` is for server-to-server calls only.
1766
+ */
1767
+ export declare type WidgetResolveContentType = 'application/json' | 'text/plain';
1768
+
1769
+ /** Options shared by every ruleset-driven entry point (hook, widget, server fetch). */
1770
+ export declare interface WidgetResolveRequestOptions {
1771
+ /**
1772
+ * Staging/production: ruleset published key (`{environmentId}---ruleset-…`).
1773
+ * Development (`dev.` token): the `ruleset-…` key; a published key is
1774
+ * accepted and stripped to its `ruleset-…` suffix.
1775
+ */
1776
+ rulesetPublishedKey: string;
1777
+ /** Any JSON object. Sent as-is; the server flattens nested objects. */
1778
+ params?: WidgetSelectionParams;
1779
+ /**
1780
+ * Widget to GET through the plain published path when the resolve request
1781
+ * fails at the network level or with a 5xx. Not used on 4xx (bad token,
1782
+ * unknown ruleset…), and not needed for "no rule matched" — the ruleset's
1783
+ * own default covers that on the server.
1784
+ */
1785
+ fallbackPublishedKey?: string;
1786
+ /**
1787
+ * Defaults to `text/plain` (no CORS preflight). Use `application/json` only
1788
+ * for server-to-server calls.
1789
+ */
1790
+ contentType?: WidgetResolveContentType;
1791
+ }
1792
+
1793
+ /** Which widget a ruleset picked and why. Returned alongside the widget payload. */
1794
+ export declare interface WidgetSelection {
1795
+ rulesetPublishedKey?: string;
1796
+ rulesetVersion?: string;
1797
+ schemaVersion?: number;
1798
+ outcome: WidgetSelectionOutcome;
1799
+ /** Matched rule id, or `null` for the default / fallback-default outcomes. */
1800
+ ruleId: string | null;
1801
+ /** Experiment variant id, or `null` when the rule was not an experiment. */
1802
+ variantId: string | null;
1803
+ widgetKey: string;
1804
+ widgetPublishedKey: string;
1805
+ }
1806
+
1807
+ export declare type WidgetSelectionOutcome = 'rule' | 'default' | 'fallback-default';
1808
+
1809
+ /**
1810
+ * Any JSON object. Sent to the resolve endpoint as-is — the server flattens
1811
+ * nested objects (`user.plan`) before evaluating rules. `undefined` values are
1812
+ * allowed for ergonomics (`{ plan: user?.plan }`) and dropped by JSON.
1813
+ */
1814
+ export declare interface WidgetSelectionParams {
1815
+ [name: string]: WidgetSelectionParamValue | undefined;
1816
+ }
1817
+
1818
+ /** A JSON leaf or nested value accepted in resolve `params`. */
1819
+ declare type WidgetSelectionParamValue = string | number | boolean | null | WidgetSelectionParamValue[] | WidgetSelectionParams;
1820
+
1821
+ /**
1822
+ * Widget-wide placeholder values for one component instance.
1823
+ *
1824
+ * When the host passed `placeholderValues` on `rulecms-widget`, every instance
1825
+ * receives that object unless its own `componentProps` entry already has the
1826
+ * key. An entry that sets the key wins even when the value is `null` or
1827
+ * otherwise unusable: that is how one Text opts out. Other keys on the entry,
1828
+ * such as `onClick`, stay. The host's entry is not mutated.
1829
+ *
1830
+ * `undefined` means the widget input was omitted, which is the common case and
1831
+ * must not invent a bag.
1832
+ */
1833
+ export declare function withWidgetPlaceholderValues({ widgetInstanceProps, placeholderValues, }: {
1834
+ widgetInstanceProps?: WidgetInstanceProps;
1835
+ placeholderValues?: unknown;
1836
+ }): WidgetInstanceProps | undefined;
1837
+
1664
1838
  /**
1665
1839
  * The base's own place in the stack. Read here rather than through
1666
1840
  * objectStyleAttributeRegistry on purpose: the registry is shared with rows and