@builder.io/sdk-react-nextjs 0.17.6 → 0.17.7

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 (63) hide show
  1. package/lib/browser/blocks-exports.cjs +1 -1
  2. package/lib/browser/blocks-exports.mjs +14 -12
  3. package/lib/browser/components/blocks/blocks-wrapper.cjs +2 -2
  4. package/lib/browser/components/blocks/blocks-wrapper.mjs +13 -13
  5. package/lib/browser/constants/sdk-version.cjs +1 -1
  6. package/lib/browser/constants/sdk-version.mjs +1 -1
  7. package/lib/browser/helpers/canTrack.cjs +1 -1
  8. package/lib/browser/helpers/canTrack.mjs +7 -3
  9. package/lib/browser/helpers/user-attributes.cjs +1 -0
  10. package/lib/browser/helpers/user-attributes.mjs +45 -0
  11. package/lib/browser/index.cjs +1 -1
  12. package/lib/browser/index.mjs +32 -30
  13. package/lib/browser/scripts/init-editing.cjs +1 -1
  14. package/lib/browser/scripts/init-editing.mjs +12 -11
  15. package/lib/edge/blocks-exports.cjs +1 -1
  16. package/lib/edge/blocks-exports.mjs +14 -12
  17. package/lib/edge/components/blocks/blocks-wrapper.cjs +2 -2
  18. package/lib/edge/components/blocks/blocks-wrapper.mjs +13 -13
  19. package/lib/edge/constants/sdk-version.cjs +1 -1
  20. package/lib/edge/constants/sdk-version.mjs +1 -1
  21. package/lib/edge/helpers/canTrack.cjs +1 -1
  22. package/lib/edge/helpers/canTrack.mjs +7 -3
  23. package/lib/edge/helpers/user-attributes.cjs +1 -0
  24. package/lib/edge/helpers/user-attributes.mjs +45 -0
  25. package/lib/edge/index.cjs +1 -1
  26. package/lib/edge/index.mjs +32 -30
  27. package/lib/edge/scripts/init-editing.cjs +1 -1
  28. package/lib/edge/scripts/init-editing.mjs +12 -11
  29. package/lib/node/blocks-exports.cjs +1 -1
  30. package/lib/node/blocks-exports.mjs +14 -12
  31. package/lib/node/components/blocks/blocks-wrapper.cjs +2 -2
  32. package/lib/node/components/blocks/blocks-wrapper.mjs +13 -13
  33. package/lib/node/constants/sdk-version.cjs +1 -1
  34. package/lib/node/constants/sdk-version.mjs +1 -1
  35. package/lib/node/helpers/canTrack.cjs +1 -1
  36. package/lib/node/helpers/canTrack.mjs +7 -3
  37. package/lib/node/helpers/user-attributes.cjs +1 -0
  38. package/lib/node/helpers/user-attributes.mjs +45 -0
  39. package/lib/node/index.cjs +1 -1
  40. package/lib/node/index.mjs +32 -30
  41. package/lib/node/scripts/init-editing.cjs +1 -1
  42. package/lib/node/scripts/init-editing.mjs +12 -11
  43. package/package.json +1 -1
  44. package/types/cjs/blocks/personalization-container/component-info.d.ts +2 -0
  45. package/types/cjs/blocks/personalization-container/helpers/inlined-fns.d.ts +8 -0
  46. package/types/cjs/blocks/personalization-container/helpers.d.ts +27 -0
  47. package/types/cjs/blocks/personalization-container/index.d.ts +1 -0
  48. package/types/cjs/blocks/personalization-container/personalization-container.d.ts +4 -0
  49. package/types/cjs/blocks/personalization-container/personalization-container.types.d.ts +14 -0
  50. package/types/cjs/constants/sdk-version.d.ts +1 -1
  51. package/types/cjs/helpers/user-attributes.d.ts +17 -0
  52. package/types/cjs/index-helpers/blocks-exports.d.ts +1 -0
  53. package/types/cjs/types/input.d.ts +1 -0
  54. package/types/esm/blocks/personalization-container/component-info.d.ts +2 -0
  55. package/types/esm/blocks/personalization-container/helpers/inlined-fns.d.ts +8 -0
  56. package/types/esm/blocks/personalization-container/helpers.d.ts +27 -0
  57. package/types/esm/blocks/personalization-container/index.d.ts +1 -0
  58. package/types/esm/blocks/personalization-container/personalization-container.d.ts +4 -0
  59. package/types/esm/blocks/personalization-container/personalization-container.types.d.ts +14 -0
  60. package/types/esm/constants/sdk-version.d.ts +1 -1
  61. package/types/esm/helpers/user-attributes.d.ts +17 -0
  62. package/types/esm/index-helpers/blocks-exports.d.ts +1 -0
  63. package/types/esm/types/input.d.ts +1 -0
@@ -0,0 +1,14 @@
1
+ import type { BuilderBlock } from '../../types/builder-block.js';
2
+ import type { BuilderDataProps } from '../../types/builder-props.js';
3
+ import type { Query } from './helpers.js';
4
+ export type PersonalizationContainerProps = {
5
+ children?: any;
6
+ attributes?: any;
7
+ previewingIndex?: number | null;
8
+ variants?: Array<{
9
+ blocks: BuilderBlock[];
10
+ query: Query[];
11
+ startDate?: string;
12
+ endDate?: string;
13
+ }>;
14
+ } & BuilderDataProps;
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.17.6";
1
+ export declare const SDK_VERSION = "0.17.7";
@@ -0,0 +1,17 @@
1
+ export interface UserAttributes {
2
+ [key: string]: any;
3
+ }
4
+ export declare const USER_ATTRIBUTES_COOKIE_NAME = "builder.userAttributes";
5
+ export declare function createUserAttributesService(): {
6
+ setUserAttributes(newAttrs: UserAttributes): void;
7
+ getUserAttributes(): any;
8
+ subscribeOnUserAttributesChange(callback: (attrs: UserAttributes) => void): () => void;
9
+ setCanTrack(value: boolean): void;
10
+ };
11
+ export declare const userAttributesService: {
12
+ setUserAttributes(newAttrs: UserAttributes): void;
13
+ getUserAttributes(): any;
14
+ subscribeOnUserAttributesChange(callback: (attrs: UserAttributes) => void): () => void;
15
+ setCanTrack(value: boolean): void;
16
+ };
17
+ export declare const setClientUserAttributes: (attributes: UserAttributes) => void;
@@ -12,3 +12,4 @@ export { default as Content } from '../components/content-variants/index.js';
12
12
  * Builder Context
13
13
  */
14
14
  export { BuilderContext } from '../context/index.js';
15
+ export { setClientUserAttributes } from '../helpers/user-attributes.js';
@@ -124,6 +124,7 @@ export interface Input {
124
124
  * Use optionally with inputs of type `reference`. Restricts the content entry picker to a specific model by name.
125
125
  */
126
126
  model?: string;
127
+ behavior?: string;
127
128
  valueType?: {
128
129
  type?: string;
129
130
  };
@@ -0,0 +1,2 @@
1
+ import type { ComponentInfo } from '../../types/components.js';
2
+ export declare const componentInfo: ComponentInfo;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * WARNING: This file contains functions that get stringified and inlined into the HTML at build-time.
3
+ * They cannot import anything.
4
+ */
5
+ import type { Query, UserAttributes } from '../helpers.js';
6
+ export declare function filterWithCustomTargeting(userAttributes: UserAttributes, query: Query[], startDate?: string, endDate?: string): boolean;
7
+ export declare const PERSONALIZATION_SCRIPT = "function getPersonalizedVariant(variants, blockId, locale) {\n if (!navigator.cookieEnabled) {\n return;\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) == ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n function removeVariants() {\n variants?.forEach(function (_, index) {\n document.querySelector('template[data-variant-id=\"' + blockId + '-' + index + '\"]')?.remove();\n });\n document.querySelector('script[data-id=\"variants-script-' + blockId + '\"]')?.remove();\n document.querySelector('style[data-id=\"variants-styles-' + blockId + '\"]')?.remove();\n }\n const attributes = JSON.parse(getCookie('builder.userAttributes') || '{}');\n if (locale) {\n attributes.locale = locale;\n }\n const winningVariantIndex = variants?.findIndex(function (variant) {\n return filterWithCustomTargeting(attributes, variant.query, variant.startDate, variant.endDate);\n });\n const isDebug = location.href.includes('builder.debug=true');\n if (isDebug) {\n console.debug('PersonalizationContainer', {\n attributes,\n variants,\n winningVariantIndex\n });\n }\n if (winningVariantIndex !== -1) {\n const winningVariant = document.querySelector('template[data-variant-id=\"' + blockId + '-' + winningVariantIndex + '\"]');\n if (winningVariant) {\n const parentNode = winningVariant.parentNode;\n if (parentNode) {\n const newParent = parentNode.cloneNode(false);\n newParent.appendChild(winningVariant.content.firstChild);\n newParent.appendChild(winningVariant.content.lastChild);\n parentNode.parentNode?.replaceChild(newParent, parentNode);\n }\n if (isDebug) {\n console.debug('PersonalizationContainer', 'Winning variant Replaced:', winningVariant);\n }\n }\n } else if (variants && variants.length > 0) {\n removeVariants();\n }\n}";
8
+ export declare const FILTER_WITH_CUSTOM_TARGETING_SCRIPT = "function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {\n function isString(val) {\n return typeof val === 'string';\n }\n function isNumber(val) {\n return typeof val === 'number';\n }\n function objectMatchesQuery(userattr, query) {\n const result = (() => {\n const property = query.property;\n const operator = query.operator;\n let testValue = query.value;\n if (query && query.property === 'urlPath' && query.value && typeof query.value === 'string' && query.value !== '/' && query.value.endsWith('/')) {\n testValue = query.value.slice(0, -1);\n }\n if (!(property && operator)) {\n return true;\n }\n if (Array.isArray(testValue)) {\n if (operator === 'isNot') {\n return testValue.every(val => objectMatchesQuery(userattr, {\n property,\n operator,\n value: val\n }));\n }\n return !!testValue.find(val => objectMatchesQuery(userattr, {\n property,\n operator,\n value: val\n }));\n }\n const value = userattr[property];\n if (Array.isArray(value)) {\n return value.includes(testValue);\n }\n switch (operator) {\n case 'is':\n return value === testValue;\n case 'isNot':\n return value !== testValue;\n case 'contains':\n return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));\n case 'startsWith':\n return isString(value) && value.startsWith(String(testValue));\n case 'endsWith':\n return isString(value) && value.endsWith(String(testValue));\n case 'greaterThan':\n return isNumber(value) && isNumber(testValue) && value > testValue;\n case 'lessThan':\n return isNumber(value) && isNumber(testValue) && value < testValue;\n case 'greaterThanOrEqualTo':\n return isNumber(value) && isNumber(testValue) && value >= testValue;\n case 'lessThanOrEqualTo':\n return isNumber(value) && isNumber(testValue) && value <= testValue;\n default:\n return false;\n }\n })();\n return result;\n }\n const item = {\n query,\n startDate,\n endDate\n };\n const now = userAttributes.date && new Date(userAttributes.date) || new Date();\n if (item.startDate && new Date(item.startDate) > now) {\n return false;\n } else if (item.endDate && new Date(item.endDate) < now) {\n return false;\n }\n if (!item.query || !item.query.length) {\n return true;\n }\n return item.query.every(filter => {\n return objectMatchesQuery(userAttributes, filter);\n });\n}";
@@ -0,0 +1,27 @@
1
+ import type { BuilderBlock } from '../../types/builder-block.js';
2
+ import type { PersonalizationContainerProps } from './personalization-container.types.js';
3
+ export type UserAttributes = {
4
+ date?: string | Date;
5
+ urlPath?: string;
6
+ [key: string]: any;
7
+ };
8
+ type QueryOperator = 'is' | 'isNot' | 'contains' | 'startsWith' | 'endsWith' | 'greaterThan' | 'lessThan' | 'greaterThanOrEqualTo' | 'lessThanOrEqualTo';
9
+ type QueryValue = string | number | boolean | Array<string | number | boolean>;
10
+ export type Query = {
11
+ property: string;
12
+ operator: QueryOperator;
13
+ value: QueryValue;
14
+ };
15
+ export declare function checkShouldRenderVariants(variants: PersonalizationContainerProps['variants'], canTrack: boolean): boolean;
16
+ export declare function getBlocksToRender({ variants, previewingIndex, isHydrated, filteredVariants, fallbackBlocks }: {
17
+ variants: PersonalizationContainerProps['variants'];
18
+ previewingIndex?: number | null;
19
+ isHydrated: boolean;
20
+ filteredVariants: PersonalizationContainerProps['variants'];
21
+ fallbackBlocks?: BuilderBlock[];
22
+ }): {
23
+ blocks: BuilderBlock[];
24
+ path: string | undefined;
25
+ };
26
+ export declare const getPersonalizationScript: (variants: PersonalizationContainerProps['variants'], blockId: string, locale?: string) => string;
27
+ export { filterWithCustomTargeting } from './helpers/inlined-fns.js';
@@ -0,0 +1 @@
1
+ export { default } from './personalization-container.js';
@@ -0,0 +1,4 @@
1
+ import * as React from "react";
2
+ import type { PersonalizationContainerProps } from "./personalization-container.types.js";
3
+ declare function PersonalizationContainer(props: PersonalizationContainerProps): React.JSX.Element;
4
+ export default PersonalizationContainer;
@@ -0,0 +1,14 @@
1
+ import type { BuilderBlock } from '../../types/builder-block.js';
2
+ import type { BuilderDataProps } from '../../types/builder-props.js';
3
+ import type { Query } from './helpers.js';
4
+ export type PersonalizationContainerProps = {
5
+ children?: any;
6
+ attributes?: any;
7
+ previewingIndex?: number | null;
8
+ variants?: Array<{
9
+ blocks: BuilderBlock[];
10
+ query: Query[];
11
+ startDate?: string;
12
+ endDate?: string;
13
+ }>;
14
+ } & BuilderDataProps;
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.17.6";
1
+ export declare const SDK_VERSION = "0.17.7";
@@ -0,0 +1,17 @@
1
+ export interface UserAttributes {
2
+ [key: string]: any;
3
+ }
4
+ export declare const USER_ATTRIBUTES_COOKIE_NAME = "builder.userAttributes";
5
+ export declare function createUserAttributesService(): {
6
+ setUserAttributes(newAttrs: UserAttributes): void;
7
+ getUserAttributes(): any;
8
+ subscribeOnUserAttributesChange(callback: (attrs: UserAttributes) => void): () => void;
9
+ setCanTrack(value: boolean): void;
10
+ };
11
+ export declare const userAttributesService: {
12
+ setUserAttributes(newAttrs: UserAttributes): void;
13
+ getUserAttributes(): any;
14
+ subscribeOnUserAttributesChange(callback: (attrs: UserAttributes) => void): () => void;
15
+ setCanTrack(value: boolean): void;
16
+ };
17
+ export declare const setClientUserAttributes: (attributes: UserAttributes) => void;
@@ -12,3 +12,4 @@ export { default as Content } from '../components/content-variants/index.js';
12
12
  * Builder Context
13
13
  */
14
14
  export { BuilderContext } from '../context/index.js';
15
+ export { setClientUserAttributes } from '../helpers/user-attributes.js';
@@ -124,6 +124,7 @@ export interface Input {
124
124
  * Use optionally with inputs of type `reference`. Restricts the content entry picker to a specific model by name.
125
125
  */
126
126
  model?: string;
127
+ behavior?: string;
127
128
  valueType?: {
128
129
  type?: string;
129
130
  };