@builder.io/sdk-qwik 0.0.24 → 0.0.25

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 (34) hide show
  1. package/lib/index.qwik.cjs +176 -122
  2. package/lib/index.qwik.mjs +177 -123
  3. package/package.json +1 -1
  4. package/types/blocks/columns/columns.d.ts +2 -3
  5. package/types/blocks/image/image.d.ts +1 -1
  6. package/types/blocks/symbol/symbol.d.ts +2 -2
  7. package/types/components/render-block/block-styles.d.ts +2 -2
  8. package/types/components/render-block/render-block.d.ts +3 -3
  9. package/types/components/render-block/render-component.d.ts +2 -2
  10. package/types/components/render-block/types.d.ts +2 -2
  11. package/types/components/render-blocks.d.ts +1 -1
  12. package/types/components/render-content/render-content.d.ts +2 -2
  13. package/types/context/types.d.ts +3 -3
  14. package/types/functions/get-block-actions-handler.d.ts +1 -1
  15. package/types/functions/get-block-actions.d.ts +1 -1
  16. package/types/functions/get-block-component-options.d.ts +1 -1
  17. package/types/functions/get-block-properties.d.ts +1 -1
  18. package/types/functions/get-block-styles.d.ts +1 -1
  19. package/types/functions/get-block-tag.d.ts +1 -1
  20. package/types/functions/get-content/ab-testing.d.ts +5 -3
  21. package/types/functions/get-content/index.d.ts +1 -1
  22. package/types/functions/get-content/types.d.ts +7 -2
  23. package/types/functions/get-processed-block.d.ts +1 -1
  24. package/types/functions/register-component.d.ts +1 -1
  25. package/types/functions/register.d.ts +2 -2
  26. package/types/functions/track.d.ts +1 -1
  27. package/types/functions/transform-block.d.ts +1 -1
  28. package/types/helpers/ab-tests.d.ts +8 -0
  29. package/types/helpers/cookie.d.ts +9 -3
  30. package/types/helpers/localStorage.d.ts +3 -4
  31. package/types/helpers/sessionId.d.ts +3 -4
  32. package/types/helpers/visitorId.d.ts +3 -5
  33. package/types/types/builder-content.d.ts +1 -1
  34. package/types/types/typescript.d.ts +1 -0
@@ -527,15 +527,27 @@ const RenderBlock = (props) => {
527
527
  };
528
528
  state.tagName = tagName2(props);
529
529
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {
530
- children: shouldWrap(props) ? !isEmptyHtmlElement(tagName2(props)) ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
530
+ children: shouldWrap(props) ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
531
531
  children: [
532
- repeatItemData(props) ? (repeatItemData(props) || []).map(function(data, index) {
532
+ isEmptyHtmlElement(tagName2(props)) ? /* @__PURE__ */ jsxRuntime.jsx(state.tagName, {
533
+ ...attributes(props)
534
+ }) : null,
535
+ !isEmptyHtmlElement(tagName2(props)) && TARGET === "vue2" && repeatItemData(props) ? /* @__PURE__ */ jsxRuntime.jsx("div", {
536
+ class: "vue2-root-element-workaround",
537
+ children: (repeatItemData(props) || []).map(function(data, index) {
538
+ return /* @__PURE__ */ jsxRuntime.jsx(RenderRepeatedBlock$1, {
539
+ repeatContext: data.context,
540
+ block: data.block
541
+ }, index);
542
+ })
543
+ }) : null,
544
+ !isEmptyHtmlElement(tagName2(props)) && TARGET !== "vue2" && repeatItemData(props) ? (repeatItemData(props) || []).map(function(data, index) {
533
545
  return /* @__PURE__ */ jsxRuntime.jsx(RenderRepeatedBlock$1, {
534
546
  repeatContext: data.context,
535
547
  block: data.block
536
548
  }, index);
537
549
  }) : null,
538
- !repeatItemData(props) ? /* @__PURE__ */ jsxRuntime.jsxs(state.tagName, {
550
+ !isEmptyHtmlElement(tagName2(props)) && !repeatItemData(props) ? /* @__PURE__ */ jsxRuntime.jsxs(state.tagName, {
539
551
  ...attributes(props),
540
552
  children: [
541
553
  /* @__PURE__ */ jsxRuntime.jsx(RenderComponent$1, {
@@ -556,8 +568,6 @@ const RenderBlock = (props) => {
556
568
  ]
557
569
  }) : null
558
570
  ]
559
- }) : /* @__PURE__ */ jsxRuntime.jsx(state.tagName, {
560
- ...attributes(props)
561
571
  }) : /* @__PURE__ */ jsxRuntime.jsx(RenderComponent$1, {
562
572
  ...renderComponentProps(props),
563
573
  context: props.context
@@ -601,7 +611,7 @@ const RenderBlocks = /* @__PURE__ */ qwik.componentQrl(qwik.inlinedQrl((props) =
601
611
  style: props.style,
602
612
  onClick$: qwik.inlinedQrl((event) => {
603
613
  const [builderContext2, props2, state2] = qwik.useLexicalScope();
604
- return (event2) => onClick$1(props2);
614
+ return onClick$1(props2);
605
615
  }, "RenderBlocks_component_div_onClick_RzhhZa265Yg", [
606
616
  builderContext,
607
617
  props,
@@ -609,7 +619,7 @@ const RenderBlocks = /* @__PURE__ */ qwik.componentQrl(qwik.inlinedQrl((props) =
609
619
  ]),
610
620
  onMouseEnter$: qwik.inlinedQrl((event) => {
611
621
  const [builderContext2, props2, state2] = qwik.useLexicalScope();
612
- return (event2) => onMouseEnter(props2);
622
+ return onMouseEnter(props2);
613
623
  }, "RenderBlocks_component_div_onMouseEnter_nG7I7RYG3JQ", [
614
624
  builderContext,
615
625
  props,
@@ -1908,117 +1918,13 @@ async function getFetch() {
1908
1918
  throw new Error("`fetch()` not found, ensure you have it as part of your polyfills.");
1909
1919
  return globalFetch.default || globalFetch;
1910
1920
  }
1911
- const handleABTesting = (item, testGroups) => {
1912
- if (item.variations && Object.keys(item.variations).length) {
1913
- const testGroup = item.id ? testGroups[item.id] : void 0;
1914
- const variationValue = testGroup ? item.variations[testGroup] : void 0;
1915
- if (testGroup && variationValue) {
1916
- item.data = variationValue.data;
1917
- item.testVariationId = variationValue.id;
1918
- item.testVariationName = variationValue.name;
1919
- } else {
1920
- let n = 0;
1921
- const random = Math.random();
1922
- let set2 = false;
1923
- for (const id in item.variations) {
1924
- const variation = item.variations[id];
1925
- const testRatio = variation.testRatio;
1926
- n += testRatio;
1927
- if (random < n) {
1928
- const variationName = variation.name || (variation.id === item.id ? "Default variation" : "");
1929
- set2 = true;
1930
- Object.assign(item, {
1931
- data: variation.data,
1932
- testVariationId: variation.id,
1933
- testVariationName: variationName
1934
- });
1935
- }
1936
- }
1937
- if (!set2)
1938
- Object.assign(item, {
1939
- testVariationId: item.id,
1940
- testVariationName: "Default"
1941
- });
1942
- }
1943
- }
1944
- };
1945
- async function getContent(options) {
1946
- return (await getAllContent({
1947
- ...options,
1948
- limit: 1
1949
- })).results[0] || null;
1950
- }
1951
- const generateContentUrl = (options) => {
1952
- const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey } = options;
1953
- const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}`);
1954
- const queryOptions = {
1955
- ...getBuilderSearchParamsFromWindow(),
1956
- ...normalizeSearchParams(options.options || {})
1957
- };
1958
- const flattened = flatten(queryOptions);
1959
- for (const key in flattened)
1960
- url.searchParams.set(key, String(flattened[key]));
1961
- if (userAttributes)
1962
- url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
1963
- if (query) {
1964
- const flattened1 = flatten({
1965
- query
1966
- });
1967
- for (const key1 in flattened1)
1968
- url.searchParams.set(key1, JSON.stringify(flattened1[key1]));
1969
- }
1970
- return url;
1971
- };
1972
- async function getAllContent(options) {
1973
- const url = generateContentUrl(options);
1974
- const fetch2 = await getFetch();
1975
- const content = await fetch2(url.href).then((res) => res.json());
1976
- if (options.testGroups)
1977
- for (const item of content.results)
1978
- handleABTesting(item, options.testGroups);
1979
- return content;
1980
- }
1981
- function isPreviewing() {
1982
- if (!isBrowser())
1983
- return false;
1984
- if (isEditing())
1985
- return false;
1986
- return Boolean(location.search.indexOf("builder.preview=") !== -1);
1987
- }
1988
- const components = [];
1989
- function registerComponent(component3, info) {
1990
- components.push({
1991
- component: component3,
1992
- ...info
1993
- });
1994
- console.warn("registerComponent is deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.");
1995
- return component3;
1996
- }
1997
- const createRegisterComponentMessage = ({ component: _, ...info }) => ({
1998
- type: "builder.registerComponent",
1999
- data: prepareComponentInfoToSend(info)
2000
- });
2001
- const fastClone = (obj) => JSON.parse(JSON.stringify(obj));
2002
- const serializeValue = (value) => typeof value === "function" ? serializeFn(value) : fastClone(value);
2003
- const serializeFn = (fnValue) => {
2004
- const fnStr = fnValue.toString().trim();
2005
- const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(");
2006
- return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
2007
- };
2008
- const prepareComponentInfoToSend = ({ inputs, ...info }) => ({
2009
- ...fastClone(info),
2010
- inputs: inputs?.map((input) => Object.entries(input).reduce((acc, [key, value]) => ({
2011
- ...acc,
2012
- [key]: serializeValue(value)
2013
- }), {}))
2014
- });
2015
1921
  const getTopLevelDomain = (host) => {
2016
1922
  const parts = host.split(".");
2017
1923
  if (parts.length > 2)
2018
1924
  return parts.slice(1).join(".");
2019
1925
  return host;
2020
1926
  };
2021
- const getCookie = ({ name, canTrack }) => {
1927
+ const getCookie = async ({ name, canTrack }) => {
2022
1928
  try {
2023
1929
  if (!canTrack)
2024
1930
  return void 0;
@@ -2070,7 +1976,7 @@ const createCookieString = ({ name, value, expires }) => {
2070
1976
  const cookie = stringifyCookie(cookieValue);
2071
1977
  return cookie;
2072
1978
  };
2073
- const setCookie = ({ name, value, expires, canTrack }) => {
1979
+ const setCookie = async ({ name, value, expires, canTrack }) => {
2074
1980
  try {
2075
1981
  if (!canTrack)
2076
1982
  return void 0;
@@ -2084,7 +1990,156 @@ const setCookie = ({ name, value, expires, canTrack }) => {
2084
1990
  console.warn("[COOKIE] SET error: ", err);
2085
1991
  }
2086
1992
  };
1993
+ const BUILDER_STORE_PREFIX = "builderio.variations";
1994
+ const getContentTestKey = (id) => `${BUILDER_STORE_PREFIX}.${id}`;
1995
+ const getContentVariationCookie = ({ contentId, canTrack }) => getCookie({
1996
+ name: getContentTestKey(contentId),
1997
+ canTrack
1998
+ });
1999
+ const setContentVariationCookie = ({ contentId, canTrack, value }) => setCookie({
2000
+ name: getContentTestKey(contentId),
2001
+ value,
2002
+ canTrack
2003
+ });
2087
2004
  const checkIsDefined = (maybeT) => maybeT !== null && maybeT !== void 0;
2005
+ const checkIsBuilderContentWithVariations = (item) => checkIsDefined(item.id) && checkIsDefined(item.variations) && Object.keys(item.variations).length > 0;
2006
+ const getRandomVariationId = ({ id, variations }) => {
2007
+ let n = 0;
2008
+ const random = Math.random();
2009
+ for (const id1 in variations) {
2010
+ const testRatio = variations[id1]?.testRatio;
2011
+ n += testRatio;
2012
+ if (random < n)
2013
+ return id1;
2014
+ }
2015
+ return id;
2016
+ };
2017
+ const getTestFields = ({ item, testGroupId }) => {
2018
+ const variationValue = item.variations[testGroupId];
2019
+ if (testGroupId === item.id || !variationValue)
2020
+ return {
2021
+ testVariationId: item.id,
2022
+ testVariationName: "Default"
2023
+ };
2024
+ else
2025
+ return {
2026
+ data: variationValue.data,
2027
+ testVariationId: variationValue.id,
2028
+ testVariationName: variationValue.name || (variationValue.id === item.id ? "Default" : "")
2029
+ };
2030
+ };
2031
+ const getContentVariation = async ({ item, canTrack }) => {
2032
+ const testGroupId = await getContentVariationCookie({
2033
+ canTrack,
2034
+ contentId: item.id
2035
+ });
2036
+ const testFields = testGroupId ? getTestFields({
2037
+ item,
2038
+ testGroupId
2039
+ }) : void 0;
2040
+ if (testFields)
2041
+ return testFields;
2042
+ else {
2043
+ const randomVariationId = getRandomVariationId({
2044
+ variations: item.variations,
2045
+ id: item.id
2046
+ });
2047
+ setContentVariationCookie({
2048
+ contentId: item.id,
2049
+ value: randomVariationId,
2050
+ canTrack
2051
+ }).catch((err) => {
2052
+ console.error("could not store A/B test variation: ", err);
2053
+ });
2054
+ return getTestFields({
2055
+ item,
2056
+ testGroupId: randomVariationId
2057
+ });
2058
+ }
2059
+ };
2060
+ const handleABTesting = async ({ item, canTrack }) => {
2061
+ if (!checkIsBuilderContentWithVariations(item))
2062
+ return;
2063
+ const variationValue = await getContentVariation({
2064
+ item,
2065
+ canTrack
2066
+ });
2067
+ Object.assign(item, variationValue);
2068
+ };
2069
+ async function getContent(options) {
2070
+ return (await getAllContent({
2071
+ ...options,
2072
+ limit: 1
2073
+ })).results[0] || null;
2074
+ }
2075
+ const generateContentUrl = (options) => {
2076
+ const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey } = options;
2077
+ const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}`);
2078
+ const queryOptions = {
2079
+ ...getBuilderSearchParamsFromWindow(),
2080
+ ...normalizeSearchParams(options.options || {})
2081
+ };
2082
+ const flattened = flatten(queryOptions);
2083
+ for (const key in flattened)
2084
+ url.searchParams.set(key, String(flattened[key]));
2085
+ if (userAttributes)
2086
+ url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
2087
+ if (query) {
2088
+ const flattened1 = flatten({
2089
+ query
2090
+ });
2091
+ for (const key1 in flattened1)
2092
+ url.searchParams.set(key1, JSON.stringify(flattened1[key1]));
2093
+ }
2094
+ return url;
2095
+ };
2096
+ async function getAllContent(options) {
2097
+ const url = generateContentUrl(options);
2098
+ const fetch2 = await getFetch();
2099
+ const content = await fetch2(url.href).then((res) => res.json());
2100
+ const canTrack = options.canTrack !== false;
2101
+ if (canTrack)
2102
+ for (const item of content.results)
2103
+ await handleABTesting({
2104
+ item,
2105
+ canTrack
2106
+ });
2107
+ return content;
2108
+ }
2109
+ function isPreviewing() {
2110
+ if (!isBrowser())
2111
+ return false;
2112
+ if (isEditing())
2113
+ return false;
2114
+ return Boolean(location.search.indexOf("builder.preview=") !== -1);
2115
+ }
2116
+ const components = [];
2117
+ function registerComponent(component3, info) {
2118
+ components.push({
2119
+ component: component3,
2120
+ ...info
2121
+ });
2122
+ console.warn("registerComponent is deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.");
2123
+ return component3;
2124
+ }
2125
+ const createRegisterComponentMessage = ({ component: _, ...info }) => ({
2126
+ type: "builder.registerComponent",
2127
+ data: prepareComponentInfoToSend(info)
2128
+ });
2129
+ const fastClone = (obj) => JSON.parse(JSON.stringify(obj));
2130
+ const serializeValue = (value) => typeof value === "function" ? serializeFn(value) : fastClone(value);
2131
+ const serializeFn = (fnValue) => {
2132
+ const fnStr = fnValue.toString().trim();
2133
+ const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(");
2134
+ return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
2135
+ };
2136
+ const prepareComponentInfoToSend = ({ inputs, ...info }) => ({
2137
+ ...fastClone(info),
2138
+ inputs: inputs?.map((input) => Object.entries(input).reduce((acc, [key, value]) => ({
2139
+ ...acc,
2140
+ [key]: serializeValue(value)
2141
+ }), {}))
2142
+ });
2088
2143
  function uuidv4() {
2089
2144
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
2090
2145
  const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
@@ -2095,10 +2150,10 @@ function uuid() {
2095
2150
  return uuidv4().replace(/-/g, "");
2096
2151
  }
2097
2152
  const SESSION_LOCAL_STORAGE_KEY = "builderSessionId";
2098
- const getSessionId = ({ canTrack }) => {
2153
+ const getSessionId = async ({ canTrack }) => {
2099
2154
  if (!canTrack)
2100
2155
  return void 0;
2101
- const sessionId = getCookie({
2156
+ const sessionId = await getCookie({
2102
2157
  name: SESSION_LOCAL_STORAGE_KEY,
2103
2158
  canTrack
2104
2159
  });
@@ -2160,13 +2215,13 @@ const setVisitorId = ({ id, canTrack }) => setLocalStorageItem({
2160
2215
  value: id,
2161
2216
  canTrack
2162
2217
  });
2163
- const getTrackingEventData = ({ canTrack }) => {
2218
+ const getTrackingEventData = async ({ canTrack }) => {
2164
2219
  if (!canTrack)
2165
2220
  return {
2166
2221
  visitorId: void 0,
2167
2222
  sessionId: void 0
2168
2223
  };
2169
- const sessionId = getSessionId({
2224
+ const sessionId = await getSessionId({
2170
2225
  canTrack
2171
2226
  });
2172
2227
  const visitorId = getVisitorId({
@@ -2177,11 +2232,11 @@ const getTrackingEventData = ({ canTrack }) => {
2177
2232
  visitorId
2178
2233
  };
2179
2234
  };
2180
- const createEvent = ({ type: eventType, canTrack, orgId, contentId, ...properties }) => ({
2235
+ const createEvent = async ({ type: eventType, canTrack, orgId, contentId, ...properties }) => ({
2181
2236
  type: eventType,
2182
2237
  data: {
2183
2238
  ...properties,
2184
- ...getTrackingEventData({
2239
+ ...await getTrackingEventData({
2185
2240
  canTrack
2186
2241
  }),
2187
2242
  ownerId: orgId,
@@ -2199,7 +2254,7 @@ async function track(eventProps) {
2199
2254
  method: "POST",
2200
2255
  body: JSON.stringify({
2201
2256
  events: [
2202
- createEvent(eventProps)
2257
+ await createEvent(eventProps)
2203
2258
  ]
2204
2259
  }),
2205
2260
  headers: {
@@ -2411,7 +2466,6 @@ const RenderContent = /* @__PURE__ */ qwik.componentQrl(qwik.inlinedQrl((props)
2411
2466
  if (isBrowser()) {
2412
2467
  if (isEditing()) {
2413
2468
  state2.forceReRenderCount = state2.forceReRenderCount + 1;
2414
- elementRef2.current && qwik._useMutableProps(elementRef2.current, true);
2415
2469
  registerInsertMenu();
2416
2470
  setupBrowserForEditing();
2417
2471
  Object.values(allRegisteredComponents(props2)).forEach((registeredComponent) => {
@@ -2494,7 +2548,7 @@ const RenderContent = /* @__PURE__ */ qwik.componentQrl(qwik.inlinedQrl((props)
2494
2548
  ref: elementRef,
2495
2549
  onClick$: qwik.inlinedQrl((event) => {
2496
2550
  const [elementRef2, props2, state2] = qwik.useLexicalScope();
2497
- return (event2) => onClick2(props2, state2);
2551
+ return onClick2(props2, state2);
2498
2552
  }, "RenderContent_component__Fragment_div_onClick_wLg5o3ZkpC0", [
2499
2553
  elementRef,
2500
2554
  props,
@@ -1,4 +1,4 @@
1
- import { createContext, inlinedQrl, useLexicalScope, mutable, componentQrl, useContextProvider, useStore, useStylesScopedQrl, useContext, Slot, useRef, useWatchQrl, useClientEffectQrl, _useMutableProps, useCleanupQrl } from "@builder.io/qwik";
1
+ import { createContext, inlinedQrl, useLexicalScope, mutable, componentQrl, useContextProvider, useStore, useStylesScopedQrl, useContext, Slot, useRef, useWatchQrl, useClientEffectQrl, useCleanupQrl } from "@builder.io/qwik";
2
2
  import { jsx, Fragment as Fragment$1, jsxs } from "@builder.io/qwik/jsx-runtime";
3
3
  const TARGET = "qwik";
4
4
  function isBrowser() {
@@ -525,15 +525,27 @@ const RenderBlock = (props) => {
525
525
  };
526
526
  state.tagName = tagName2(props);
527
527
  return /* @__PURE__ */ jsx(Fragment$1, {
528
- children: shouldWrap(props) ? !isEmptyHtmlElement(tagName2(props)) ? /* @__PURE__ */ jsxs(Fragment$1, {
528
+ children: shouldWrap(props) ? /* @__PURE__ */ jsxs(Fragment$1, {
529
529
  children: [
530
- repeatItemData(props) ? (repeatItemData(props) || []).map(function(data, index) {
530
+ isEmptyHtmlElement(tagName2(props)) ? /* @__PURE__ */ jsx(state.tagName, {
531
+ ...attributes(props)
532
+ }) : null,
533
+ !isEmptyHtmlElement(tagName2(props)) && TARGET === "vue2" && repeatItemData(props) ? /* @__PURE__ */ jsx("div", {
534
+ class: "vue2-root-element-workaround",
535
+ children: (repeatItemData(props) || []).map(function(data, index) {
536
+ return /* @__PURE__ */ jsx(RenderRepeatedBlock$1, {
537
+ repeatContext: data.context,
538
+ block: data.block
539
+ }, index);
540
+ })
541
+ }) : null,
542
+ !isEmptyHtmlElement(tagName2(props)) && TARGET !== "vue2" && repeatItemData(props) ? (repeatItemData(props) || []).map(function(data, index) {
531
543
  return /* @__PURE__ */ jsx(RenderRepeatedBlock$1, {
532
544
  repeatContext: data.context,
533
545
  block: data.block
534
546
  }, index);
535
547
  }) : null,
536
- !repeatItemData(props) ? /* @__PURE__ */ jsxs(state.tagName, {
548
+ !isEmptyHtmlElement(tagName2(props)) && !repeatItemData(props) ? /* @__PURE__ */ jsxs(state.tagName, {
537
549
  ...attributes(props),
538
550
  children: [
539
551
  /* @__PURE__ */ jsx(RenderComponent$1, {
@@ -554,8 +566,6 @@ const RenderBlock = (props) => {
554
566
  ]
555
567
  }) : null
556
568
  ]
557
- }) : /* @__PURE__ */ jsx(state.tagName, {
558
- ...attributes(props)
559
569
  }) : /* @__PURE__ */ jsx(RenderComponent$1, {
560
570
  ...renderComponentProps(props),
561
571
  context: props.context
@@ -599,7 +609,7 @@ const RenderBlocks = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
599
609
  style: props.style,
600
610
  onClick$: inlinedQrl((event) => {
601
611
  const [builderContext2, props2, state2] = useLexicalScope();
602
- return (event2) => onClick$1(props2);
612
+ return onClick$1(props2);
603
613
  }, "RenderBlocks_component_div_onClick_RzhhZa265Yg", [
604
614
  builderContext,
605
615
  props,
@@ -607,7 +617,7 @@ const RenderBlocks = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
607
617
  ]),
608
618
  onMouseEnter$: inlinedQrl((event) => {
609
619
  const [builderContext2, props2, state2] = useLexicalScope();
610
- return (event2) => onMouseEnter(props2);
620
+ return onMouseEnter(props2);
611
621
  }, "RenderBlocks_component_div_onMouseEnter_nG7I7RYG3JQ", [
612
622
  builderContext,
613
623
  props,
@@ -1906,117 +1916,13 @@ async function getFetch() {
1906
1916
  throw new Error("`fetch()` not found, ensure you have it as part of your polyfills.");
1907
1917
  return globalFetch.default || globalFetch;
1908
1918
  }
1909
- const handleABTesting = (item, testGroups) => {
1910
- if (item.variations && Object.keys(item.variations).length) {
1911
- const testGroup = item.id ? testGroups[item.id] : void 0;
1912
- const variationValue = testGroup ? item.variations[testGroup] : void 0;
1913
- if (testGroup && variationValue) {
1914
- item.data = variationValue.data;
1915
- item.testVariationId = variationValue.id;
1916
- item.testVariationName = variationValue.name;
1917
- } else {
1918
- let n = 0;
1919
- const random = Math.random();
1920
- let set2 = false;
1921
- for (const id in item.variations) {
1922
- const variation = item.variations[id];
1923
- const testRatio = variation.testRatio;
1924
- n += testRatio;
1925
- if (random < n) {
1926
- const variationName = variation.name || (variation.id === item.id ? "Default variation" : "");
1927
- set2 = true;
1928
- Object.assign(item, {
1929
- data: variation.data,
1930
- testVariationId: variation.id,
1931
- testVariationName: variationName
1932
- });
1933
- }
1934
- }
1935
- if (!set2)
1936
- Object.assign(item, {
1937
- testVariationId: item.id,
1938
- testVariationName: "Default"
1939
- });
1940
- }
1941
- }
1942
- };
1943
- async function getContent(options) {
1944
- return (await getAllContent({
1945
- ...options,
1946
- limit: 1
1947
- })).results[0] || null;
1948
- }
1949
- const generateContentUrl = (options) => {
1950
- const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey } = options;
1951
- const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}`);
1952
- const queryOptions = {
1953
- ...getBuilderSearchParamsFromWindow(),
1954
- ...normalizeSearchParams(options.options || {})
1955
- };
1956
- const flattened = flatten(queryOptions);
1957
- for (const key in flattened)
1958
- url.searchParams.set(key, String(flattened[key]));
1959
- if (userAttributes)
1960
- url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
1961
- if (query) {
1962
- const flattened1 = flatten({
1963
- query
1964
- });
1965
- for (const key1 in flattened1)
1966
- url.searchParams.set(key1, JSON.stringify(flattened1[key1]));
1967
- }
1968
- return url;
1969
- };
1970
- async function getAllContent(options) {
1971
- const url = generateContentUrl(options);
1972
- const fetch2 = await getFetch();
1973
- const content = await fetch2(url.href).then((res) => res.json());
1974
- if (options.testGroups)
1975
- for (const item of content.results)
1976
- handleABTesting(item, options.testGroups);
1977
- return content;
1978
- }
1979
- function isPreviewing() {
1980
- if (!isBrowser())
1981
- return false;
1982
- if (isEditing())
1983
- return false;
1984
- return Boolean(location.search.indexOf("builder.preview=") !== -1);
1985
- }
1986
- const components = [];
1987
- function registerComponent(component3, info) {
1988
- components.push({
1989
- component: component3,
1990
- ...info
1991
- });
1992
- console.warn("registerComponent is deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.");
1993
- return component3;
1994
- }
1995
- const createRegisterComponentMessage = ({ component: _, ...info }) => ({
1996
- type: "builder.registerComponent",
1997
- data: prepareComponentInfoToSend(info)
1998
- });
1999
- const fastClone = (obj) => JSON.parse(JSON.stringify(obj));
2000
- const serializeValue = (value) => typeof value === "function" ? serializeFn(value) : fastClone(value);
2001
- const serializeFn = (fnValue) => {
2002
- const fnStr = fnValue.toString().trim();
2003
- const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(");
2004
- return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
2005
- };
2006
- const prepareComponentInfoToSend = ({ inputs, ...info }) => ({
2007
- ...fastClone(info),
2008
- inputs: inputs?.map((input) => Object.entries(input).reduce((acc, [key, value]) => ({
2009
- ...acc,
2010
- [key]: serializeValue(value)
2011
- }), {}))
2012
- });
2013
1919
  const getTopLevelDomain = (host) => {
2014
1920
  const parts = host.split(".");
2015
1921
  if (parts.length > 2)
2016
1922
  return parts.slice(1).join(".");
2017
1923
  return host;
2018
1924
  };
2019
- const getCookie = ({ name, canTrack }) => {
1925
+ const getCookie = async ({ name, canTrack }) => {
2020
1926
  try {
2021
1927
  if (!canTrack)
2022
1928
  return void 0;
@@ -2068,7 +1974,7 @@ const createCookieString = ({ name, value, expires }) => {
2068
1974
  const cookie = stringifyCookie(cookieValue);
2069
1975
  return cookie;
2070
1976
  };
2071
- const setCookie = ({ name, value, expires, canTrack }) => {
1977
+ const setCookie = async ({ name, value, expires, canTrack }) => {
2072
1978
  try {
2073
1979
  if (!canTrack)
2074
1980
  return void 0;
@@ -2082,7 +1988,156 @@ const setCookie = ({ name, value, expires, canTrack }) => {
2082
1988
  console.warn("[COOKIE] SET error: ", err);
2083
1989
  }
2084
1990
  };
1991
+ const BUILDER_STORE_PREFIX = "builderio.variations";
1992
+ const getContentTestKey = (id) => `${BUILDER_STORE_PREFIX}.${id}`;
1993
+ const getContentVariationCookie = ({ contentId, canTrack }) => getCookie({
1994
+ name: getContentTestKey(contentId),
1995
+ canTrack
1996
+ });
1997
+ const setContentVariationCookie = ({ contentId, canTrack, value }) => setCookie({
1998
+ name: getContentTestKey(contentId),
1999
+ value,
2000
+ canTrack
2001
+ });
2085
2002
  const checkIsDefined = (maybeT) => maybeT !== null && maybeT !== void 0;
2003
+ const checkIsBuilderContentWithVariations = (item) => checkIsDefined(item.id) && checkIsDefined(item.variations) && Object.keys(item.variations).length > 0;
2004
+ const getRandomVariationId = ({ id, variations }) => {
2005
+ let n = 0;
2006
+ const random = Math.random();
2007
+ for (const id1 in variations) {
2008
+ const testRatio = variations[id1]?.testRatio;
2009
+ n += testRatio;
2010
+ if (random < n)
2011
+ return id1;
2012
+ }
2013
+ return id;
2014
+ };
2015
+ const getTestFields = ({ item, testGroupId }) => {
2016
+ const variationValue = item.variations[testGroupId];
2017
+ if (testGroupId === item.id || !variationValue)
2018
+ return {
2019
+ testVariationId: item.id,
2020
+ testVariationName: "Default"
2021
+ };
2022
+ else
2023
+ return {
2024
+ data: variationValue.data,
2025
+ testVariationId: variationValue.id,
2026
+ testVariationName: variationValue.name || (variationValue.id === item.id ? "Default" : "")
2027
+ };
2028
+ };
2029
+ const getContentVariation = async ({ item, canTrack }) => {
2030
+ const testGroupId = await getContentVariationCookie({
2031
+ canTrack,
2032
+ contentId: item.id
2033
+ });
2034
+ const testFields = testGroupId ? getTestFields({
2035
+ item,
2036
+ testGroupId
2037
+ }) : void 0;
2038
+ if (testFields)
2039
+ return testFields;
2040
+ else {
2041
+ const randomVariationId = getRandomVariationId({
2042
+ variations: item.variations,
2043
+ id: item.id
2044
+ });
2045
+ setContentVariationCookie({
2046
+ contentId: item.id,
2047
+ value: randomVariationId,
2048
+ canTrack
2049
+ }).catch((err) => {
2050
+ console.error("could not store A/B test variation: ", err);
2051
+ });
2052
+ return getTestFields({
2053
+ item,
2054
+ testGroupId: randomVariationId
2055
+ });
2056
+ }
2057
+ };
2058
+ const handleABTesting = async ({ item, canTrack }) => {
2059
+ if (!checkIsBuilderContentWithVariations(item))
2060
+ return;
2061
+ const variationValue = await getContentVariation({
2062
+ item,
2063
+ canTrack
2064
+ });
2065
+ Object.assign(item, variationValue);
2066
+ };
2067
+ async function getContent(options) {
2068
+ return (await getAllContent({
2069
+ ...options,
2070
+ limit: 1
2071
+ })).results[0] || null;
2072
+ }
2073
+ const generateContentUrl = (options) => {
2074
+ const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey } = options;
2075
+ const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}`);
2076
+ const queryOptions = {
2077
+ ...getBuilderSearchParamsFromWindow(),
2078
+ ...normalizeSearchParams(options.options || {})
2079
+ };
2080
+ const flattened = flatten(queryOptions);
2081
+ for (const key in flattened)
2082
+ url.searchParams.set(key, String(flattened[key]));
2083
+ if (userAttributes)
2084
+ url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
2085
+ if (query) {
2086
+ const flattened1 = flatten({
2087
+ query
2088
+ });
2089
+ for (const key1 in flattened1)
2090
+ url.searchParams.set(key1, JSON.stringify(flattened1[key1]));
2091
+ }
2092
+ return url;
2093
+ };
2094
+ async function getAllContent(options) {
2095
+ const url = generateContentUrl(options);
2096
+ const fetch2 = await getFetch();
2097
+ const content = await fetch2(url.href).then((res) => res.json());
2098
+ const canTrack = options.canTrack !== false;
2099
+ if (canTrack)
2100
+ for (const item of content.results)
2101
+ await handleABTesting({
2102
+ item,
2103
+ canTrack
2104
+ });
2105
+ return content;
2106
+ }
2107
+ function isPreviewing() {
2108
+ if (!isBrowser())
2109
+ return false;
2110
+ if (isEditing())
2111
+ return false;
2112
+ return Boolean(location.search.indexOf("builder.preview=") !== -1);
2113
+ }
2114
+ const components = [];
2115
+ function registerComponent(component3, info) {
2116
+ components.push({
2117
+ component: component3,
2118
+ ...info
2119
+ });
2120
+ console.warn("registerComponent is deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.");
2121
+ return component3;
2122
+ }
2123
+ const createRegisterComponentMessage = ({ component: _, ...info }) => ({
2124
+ type: "builder.registerComponent",
2125
+ data: prepareComponentInfoToSend(info)
2126
+ });
2127
+ const fastClone = (obj) => JSON.parse(JSON.stringify(obj));
2128
+ const serializeValue = (value) => typeof value === "function" ? serializeFn(value) : fastClone(value);
2129
+ const serializeFn = (fnValue) => {
2130
+ const fnStr = fnValue.toString().trim();
2131
+ const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(");
2132
+ return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
2133
+ };
2134
+ const prepareComponentInfoToSend = ({ inputs, ...info }) => ({
2135
+ ...fastClone(info),
2136
+ inputs: inputs?.map((input) => Object.entries(input).reduce((acc, [key, value]) => ({
2137
+ ...acc,
2138
+ [key]: serializeValue(value)
2139
+ }), {}))
2140
+ });
2086
2141
  function uuidv4() {
2087
2142
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
2088
2143
  const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
@@ -2093,10 +2148,10 @@ function uuid() {
2093
2148
  return uuidv4().replace(/-/g, "");
2094
2149
  }
2095
2150
  const SESSION_LOCAL_STORAGE_KEY = "builderSessionId";
2096
- const getSessionId = ({ canTrack }) => {
2151
+ const getSessionId = async ({ canTrack }) => {
2097
2152
  if (!canTrack)
2098
2153
  return void 0;
2099
- const sessionId = getCookie({
2154
+ const sessionId = await getCookie({
2100
2155
  name: SESSION_LOCAL_STORAGE_KEY,
2101
2156
  canTrack
2102
2157
  });
@@ -2158,13 +2213,13 @@ const setVisitorId = ({ id, canTrack }) => setLocalStorageItem({
2158
2213
  value: id,
2159
2214
  canTrack
2160
2215
  });
2161
- const getTrackingEventData = ({ canTrack }) => {
2216
+ const getTrackingEventData = async ({ canTrack }) => {
2162
2217
  if (!canTrack)
2163
2218
  return {
2164
2219
  visitorId: void 0,
2165
2220
  sessionId: void 0
2166
2221
  };
2167
- const sessionId = getSessionId({
2222
+ const sessionId = await getSessionId({
2168
2223
  canTrack
2169
2224
  });
2170
2225
  const visitorId = getVisitorId({
@@ -2175,11 +2230,11 @@ const getTrackingEventData = ({ canTrack }) => {
2175
2230
  visitorId
2176
2231
  };
2177
2232
  };
2178
- const createEvent = ({ type: eventType, canTrack, orgId, contentId, ...properties }) => ({
2233
+ const createEvent = async ({ type: eventType, canTrack, orgId, contentId, ...properties }) => ({
2179
2234
  type: eventType,
2180
2235
  data: {
2181
2236
  ...properties,
2182
- ...getTrackingEventData({
2237
+ ...await getTrackingEventData({
2183
2238
  canTrack
2184
2239
  }),
2185
2240
  ownerId: orgId,
@@ -2197,7 +2252,7 @@ async function track(eventProps) {
2197
2252
  method: "POST",
2198
2253
  body: JSON.stringify({
2199
2254
  events: [
2200
- createEvent(eventProps)
2255
+ await createEvent(eventProps)
2201
2256
  ]
2202
2257
  }),
2203
2258
  headers: {
@@ -2409,7 +2464,6 @@ const RenderContent = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
2409
2464
  if (isBrowser()) {
2410
2465
  if (isEditing()) {
2411
2466
  state2.forceReRenderCount = state2.forceReRenderCount + 1;
2412
- elementRef2.current && _useMutableProps(elementRef2.current, true);
2413
2467
  registerInsertMenu();
2414
2468
  setupBrowserForEditing();
2415
2469
  Object.values(allRegisteredComponents(props2)).forEach((registeredComponent) => {
@@ -2492,7 +2546,7 @@ const RenderContent = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
2492
2546
  ref: elementRef,
2493
2547
  onClick$: inlinedQrl((event) => {
2494
2548
  const [elementRef2, props2, state2] = useLexicalScope();
2495
- return (event2) => onClick2(props2, state2);
2549
+ return onClick2(props2, state2);
2496
2550
  }, "RenderContent_component__Fragment_div_onClick_wLg5o3ZkpC0", [
2497
2551
  elementRef,
2498
2552
  props,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-qwik",
3
- "version": "0.0.24",
3
+ "version": "0.0.25",
4
4
  "description": "Builder.io Qwik SDK",
5
5
  "type": "module",
6
6
  "main": "./lib/index.qwik.cjs",
@@ -1,5 +1,4 @@
1
- import { BuilderBlock } from "../../types/builder-block";
2
- import { JSX } from "@builder.io/mitosis/jsx-runtime";
1
+ import type { BuilderBlock } from "../../types/builder-block";
3
2
  declare type Column = {
4
3
  blocks: any;
5
4
  width?: number;
@@ -16,7 +15,7 @@ export declare const getGutterSize: (props: any, state: any) => any;
16
15
  export declare const getColumns: (props: any, state: any) => any;
17
16
  export declare const getWidth: (props: any, state: any, index: number) => any;
18
17
  export declare const getColumnCssWidth: (props: any, state: any, index: number) => string;
19
- export declare const maybeApplyForTablet: (props: any, state: any, prop: JSX.CSS["flexDirection"]) => string | undefined;
18
+ export declare const maybeApplyForTablet: (props: any, state: any, prop: string | undefined) => string | undefined;
20
19
  export declare const columnsCssVars: (props: any, state: any) => {
21
20
  "--flex-dir": string;
22
21
  "--flex-dir-tablet": string | undefined;
@@ -1,4 +1,4 @@
1
- import { JSX } from "@builder.io/mitosis/jsx-runtime";
1
+ /// <reference types="react" />
2
2
  import type { BuilderBlock } from "../../types/builder-block.js";
3
3
  export interface ImageProps {
4
4
  className?: string;
@@ -1,5 +1,5 @@
1
- import { BuilderBlock } from "../../types/builder-block.js";
2
- import { BuilderContent } from "../../types/builder-content.js";
1
+ import type { BuilderContent } from "../../types/builder-content.js";
2
+ import type { BuilderBlock } from "../../types/builder-block.js";
3
3
  export interface SymbolInfo {
4
4
  model?: string;
5
5
  entry?: string;
@@ -1,5 +1,5 @@
1
- import { BuilderContextInterface } from "../../context/types.js";
2
- import { BuilderBlock } from "../../types/builder-block.js";
1
+ import type { BuilderContextInterface } from "../../context/types.js";
2
+ import type { BuilderBlock } from "../../types/builder-block.js";
3
3
  export declare type BlockStylesProps = {
4
4
  block: BuilderBlock;
5
5
  context: BuilderContextInterface;
@@ -1,6 +1,6 @@
1
- import { BuilderContextInterface } from "../../context/types.js";
2
- import { BuilderBlock } from "../../types/builder-block.js";
3
- import { RepeatData } from "./types.js";
1
+ import type { BuilderContextInterface } from "../../context/types.js";
2
+ import type { BuilderBlock } from "../../types/builder-block.js";
3
+ import type { RepeatData } from "./types.js";
4
4
  export declare type RenderBlockProps = {
5
5
  block: BuilderBlock;
6
6
  context: BuilderContextInterface;
@@ -1,5 +1,5 @@
1
- import { BuilderContextInterface } from "../../context/types.js";
2
- import { BuilderBlock } from "../../types/builder-block.js";
1
+ import type { BuilderBlock } from "../../types/builder-block.js";
2
+ import type { BuilderContextInterface } from "../../context/types.js";
3
3
  export interface RenderComponentProps {
4
4
  componentRef: any;
5
5
  componentOptions: any;
@@ -1,5 +1,5 @@
1
- import { BuilderContextInterface } from '../../context/types.js';
2
- import { BuilderBlock } from '../../types/builder-block.js';
1
+ import type { BuilderContextInterface } from '../../context/types.js';
2
+ import type { BuilderBlock } from '../../types/builder-block.js';
3
3
  export interface RepeatData {
4
4
  block: BuilderBlock;
5
5
  context: BuilderContextInterface;
@@ -1,4 +1,4 @@
1
- import { BuilderBlock } from "../types/builder-block.js";
1
+ import type { BuilderBlock } from "../types/builder-block.js";
2
2
  export declare type RenderBlockProps = {
3
3
  blocks?: BuilderBlock[];
4
4
  parent?: string;
@@ -1,5 +1,5 @@
1
- import { BuilderRenderContext, RegisteredComponent } from "../../context/types.js";
2
- import { BuilderContent } from "../../types/builder-content.js";
1
+ import type { BuilderRenderContext, RegisteredComponent } from "../../context/types.js";
2
+ import type { BuilderContent } from "../../types/builder-content.js";
3
3
  import type { Nullable } from "../../types/typescript.js";
4
4
  export declare type RenderContentProps = {
5
5
  content?: Nullable<BuilderContent>;
@@ -1,6 +1,6 @@
1
- import { BuilderContent } from '../types/builder-content.js';
2
- import { ComponentInfo } from '../types/components.js';
3
- import { Dictionary, Nullable } from '../types/typescript.js';
1
+ import type { BuilderContent } from '../types/builder-content.js';
2
+ import type { ComponentInfo } from '../types/components.js';
3
+ import type { Dictionary, Nullable } from '../types/typescript.js';
4
4
  export declare type RegisteredComponent = ComponentInfo & {
5
5
  component: any;
6
6
  };
@@ -1,5 +1,5 @@
1
1
  import type { BuilderContextInterface } from '../context/types.js';
2
- import { BuilderBlock } from '../types/builder-block.js';
2
+ import type { BuilderBlock } from '../types/builder-block.js';
3
3
  export declare function crateEventHandler(value: string, options: {
4
4
  block: BuilderBlock;
5
5
  } & Pick<BuilderContextInterface, 'state' | 'context'>): (event: Event) => any;
@@ -1,5 +1,5 @@
1
1
  import type { BuilderContextInterface } from '../context/types.js';
2
- import { BuilderBlock } from '../types/builder-block.js';
2
+ import type { BuilderBlock } from '../types/builder-block.js';
3
3
  declare type Actions = {
4
4
  [index: string]: (event: Event) => any;
5
5
  };
@@ -1,2 +1,2 @@
1
- import { BuilderBlock } from '../types/builder-block.js';
1
+ import type { BuilderBlock } from '../types/builder-block.js';
2
2
  export declare function getBlockComponentOptions(block: BuilderBlock): any;
@@ -1,4 +1,4 @@
1
- import { BuilderBlock } from '../types/builder-block.js';
1
+ import type { BuilderBlock } from '../types/builder-block.js';
2
2
  export declare function getBlockProperties(block: BuilderBlock): {
3
3
  'builder-id': string | undefined;
4
4
  class: string;
@@ -1,2 +1,2 @@
1
- import { BuilderBlock } from '../types/builder-block.js';
1
+ import type { BuilderBlock } from '../types/builder-block.js';
2
2
  export declare function getBlockStyles(block: BuilderBlock): Partial<CSSStyleDeclaration>;
@@ -1,3 +1,3 @@
1
- import { BuilderBlock } from '../types/builder-block.js';
1
+ import type { BuilderBlock } from '../types/builder-block.js';
2
2
  export declare type TagName = string;
3
3
  export declare function getBlockTag(block: BuilderBlock): TagName;
@@ -1,3 +1,5 @@
1
- import { GetContentOptions } from './types.js';
2
- import { BuilderContent } from '../../types/builder-content.js';
3
- export declare const handleABTesting: (item: BuilderContent, testGroups: NonNullable<GetContentOptions['testGroups']>) => void;
1
+ import type { BuilderContent } from '../../types/builder-content.js';
2
+ import type { CanTrack } from '../../types/can-track.js';
3
+ export declare const handleABTesting: ({ item, canTrack, }: {
4
+ item: BuilderContent;
5
+ } & CanTrack) => Promise<void>;
@@ -1,4 +1,4 @@
1
- import { BuilderContent } from '../../types/builder-content.js';
1
+ import type { BuilderContent } from '../../types/builder-content.js';
2
2
  export declare type GetContentOptions = import('./types.js').GetContentOptions;
3
3
  export declare function getContent(options: GetContentOptions): Promise<BuilderContent | null>;
4
4
  export declare const generateContentUrl: (options: GetContentOptions) => URL;
@@ -3,8 +3,6 @@ export interface GetContentOptions {
3
3
  model: string;
4
4
  /** Your public API key */
5
5
  apiKey: string;
6
- /** A/B test groups the current visitor is in. Key is the content ID, value is the variation ID */
7
- testGroups?: Record<string, string> | null;
8
6
  /** Number of items to fetch. Default is 1 */
9
7
  limit?: number;
10
8
  /** User attributes to target on, such as { urlPath: '/foo', device: 'mobile', ...etc } */
@@ -23,4 +21,11 @@ export interface GetContentOptions {
23
21
  * If set to `false`, it will render the entire content tree eagerly.
24
22
  */
25
23
  noTraverse?: boolean;
24
+ /**
25
+ * If set to `false`, it will not use cookies to target content. Therefore, A/B Testing will be disabled and
26
+ * only the default variation will be returned to every user.
27
+ *
28
+ * Defaults to `true`.
29
+ */
30
+ canTrack?: boolean;
26
31
  }
@@ -1,5 +1,5 @@
1
1
  import type { BuilderContextInterface } from '../context/types.js';
2
- import { BuilderBlock } from '../types/builder-block.js';
2
+ import type { BuilderBlock } from '../types/builder-block.js';
3
3
  export declare function getProcessedBlock({ block, context, shouldEvaluateBindings, state, }: {
4
4
  block: BuilderBlock;
5
5
  /**
@@ -1,4 +1,4 @@
1
- import { RegisteredComponent } from '../context/types.js';
1
+ import type { RegisteredComponent } from '../context/types.js';
2
2
  import type { ComponentInfo } from '../types/components.js';
3
3
  /**
4
4
  * @deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.
@@ -1,5 +1,5 @@
1
- import { BuilderBlock } from '../types/builder-block.js';
2
- import { DeepPartial } from '../types/deep-partial.js';
1
+ import type { BuilderBlock } from '../types/builder-block.js';
2
+ import type { DeepPartial } from '../types/deep-partial.js';
3
3
  export interface InsertMenuItem {
4
4
  name: string;
5
5
  icon?: string;
@@ -1,4 +1,4 @@
1
- import { CanTrack } from '../types/can-track.js';
1
+ import type { CanTrack } from '../types/can-track.js';
2
2
  interface Event {
3
3
  type: 'click' | 'impression';
4
4
  data: {
@@ -1,2 +1,2 @@
1
- import { BuilderBlock } from '../types/builder-block.js';
1
+ import type { BuilderBlock } from '../types/builder-block.js';
2
2
  export declare function transformBlock(block: BuilderBlock): BuilderBlock;
@@ -0,0 +1,8 @@
1
+ import type { CanTrack } from '../types/can-track.js';
2
+ export declare const getContentVariationCookie: ({ contentId, canTrack, }: {
3
+ contentId: string;
4
+ } & CanTrack) => Promise<string | undefined>;
5
+ export declare const setContentVariationCookie: ({ contentId, canTrack, value, }: {
6
+ contentId: string;
7
+ value: string;
8
+ } & CanTrack) => Promise<undefined>;
@@ -1,9 +1,15 @@
1
- import { CanTrack } from '../types/can-track.js';
1
+ import type { CanTrack } from '../types/can-track.js';
2
+ /**
3
+ * NOTE: This function is `async` because its react-native override is async. Do not remove the `async` keyword!
4
+ */
2
5
  export declare const getCookie: ({ name, canTrack, }: {
3
6
  name: string;
4
- } & CanTrack) => string | undefined;
7
+ } & CanTrack) => Promise<string | undefined>;
8
+ /**
9
+ * NOTE: This function is `async` because its react-native override is async. Do not remove the `async` keyword!
10
+ */
5
11
  export declare const setCookie: ({ name, value, expires, canTrack, }: {
6
12
  name: string;
7
13
  value: string;
8
14
  expires?: Date | undefined;
9
- } & CanTrack) => undefined;
15
+ } & CanTrack) => Promise<undefined>;
@@ -1,9 +1,8 @@
1
+ import type { CanTrack } from '../types/can-track.js';
1
2
  export declare const getLocalStorageItem: ({ key, canTrack, }: {
2
3
  key: string;
3
- canTrack: boolean;
4
- }) => string | null | undefined;
4
+ } & CanTrack) => string | null | undefined;
5
5
  export declare const setLocalStorageItem: ({ key, canTrack, value, }: {
6
6
  key: string;
7
7
  value: string;
8
- canTrack: boolean;
9
- }) => void;
8
+ } & CanTrack) => void;
@@ -1,7 +1,6 @@
1
- import { CanTrack } from '../types/can-track.js';
2
- export declare const getSessionId: ({ canTrack }: CanTrack) => string | undefined;
1
+ import type { CanTrack } from '../types/can-track.js';
2
+ export declare const getSessionId: ({ canTrack }: CanTrack) => Promise<string | undefined>;
3
3
  export declare const createSessionId: () => string;
4
4
  export declare const setSessionId: ({ id, canTrack, }: {
5
5
  id: string;
6
- canTrack: boolean;
7
- }) => undefined;
6
+ } & CanTrack) => Promise<undefined>;
@@ -1,8 +1,6 @@
1
- export declare const getVisitorId: ({ canTrack }: {
2
- canTrack: boolean;
3
- }) => string | undefined;
1
+ import type { CanTrack } from '../types/can-track.js';
2
+ export declare const getVisitorId: ({ canTrack }: CanTrack) => string | undefined;
4
3
  export declare const createVisitorId: () => string;
5
4
  export declare const setVisitorId: ({ id, canTrack, }: {
6
5
  id: string;
7
- canTrack: boolean;
8
- }) => void;
6
+ } & CanTrack) => void;
@@ -1,4 +1,4 @@
1
- import { BuilderBlock } from './builder-block.js';
1
+ import type { BuilderBlock } from './builder-block.js';
2
2
  declare type Input = any;
3
3
  export interface BuilderContentVariation {
4
4
  data?: {
@@ -2,3 +2,4 @@ export declare type Nullable<T> = T | null | undefined;
2
2
  export declare type Dictionary<T> = {
3
3
  [key: string]: T;
4
4
  };
5
+ export declare type Overwrite<T, U> = keyof U extends keyof T ? Pick<T, Exclude<keyof T, keyof U>> & U : never;