@builder.io/sdk-svelte 5.2.9 → 5.2.11

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 (45) hide show
  1. package/lib/browser/components/content/components/enable-editor.svelte +6 -0
  2. package/lib/browser/components/content/components/enable-editor.svelte.d.ts +1 -0
  3. package/lib/browser/components/content/content.svelte +2 -0
  4. package/lib/browser/components/content/content.svelte.d.ts +1 -0
  5. package/lib/browser/components/content-variants/content-variants.svelte +3 -0
  6. package/lib/browser/components/content-variants/content-variants.svelte.d.ts +1 -0
  7. package/lib/browser/components/content-variants/content-variants.types.d.ts +8 -0
  8. package/lib/browser/constants/sdk-version.d.ts +1 -1
  9. package/lib/browser/constants/sdk-version.js +1 -1
  10. package/lib/browser/functions/get-content/generate-content-url.js +13 -2
  11. package/lib/browser/functions/get-content/types.d.ts +27 -0
  12. package/lib/browser/scripts/init-editing.d.ts +2 -0
  13. package/lib/edge/components/content/components/enable-editor.svelte +6 -0
  14. package/lib/edge/components/content/components/enable-editor.svelte.d.ts +1 -0
  15. package/lib/edge/components/content/content.svelte +2 -0
  16. package/lib/edge/components/content/content.svelte.d.ts +1 -0
  17. package/lib/edge/components/content-variants/content-variants.svelte +3 -0
  18. package/lib/edge/components/content-variants/content-variants.svelte.d.ts +1 -0
  19. package/lib/edge/components/content-variants/content-variants.types.d.ts +8 -0
  20. package/lib/edge/constants/sdk-version.d.ts +1 -1
  21. package/lib/edge/constants/sdk-version.js +1 -1
  22. package/lib/edge/functions/get-content/generate-content-url.js +13 -2
  23. package/lib/edge/functions/get-content/types.d.ts +27 -0
  24. package/lib/edge/scripts/init-editing.d.ts +2 -0
  25. package/lib/node/components/content/components/enable-editor.svelte +6 -0
  26. package/lib/node/components/content/components/enable-editor.svelte.d.ts +1 -0
  27. package/lib/node/components/content/content.svelte +2 -0
  28. package/lib/node/components/content/content.svelte.d.ts +1 -0
  29. package/lib/node/components/content-variants/content-variants.svelte +3 -0
  30. package/lib/node/components/content-variants/content-variants.svelte.d.ts +1 -0
  31. package/lib/node/components/content-variants/content-variants.types.d.ts +8 -0
  32. package/lib/node/constants/sdk-version.d.ts +1 -1
  33. package/lib/node/constants/sdk-version.js +1 -1
  34. package/lib/node/functions/get-content/generate-content-url.js +13 -2
  35. package/lib/node/functions/get-content/types.d.ts +27 -0
  36. package/lib/node/scripts/init-editing.d.ts +2 -0
  37. package/package.json +1 -1
  38. package/src/components/content/components/enable-editor.svelte +6 -0
  39. package/src/components/content/content.svelte +2 -0
  40. package/src/components/content-variants/content-variants.svelte +3 -0
  41. package/src/components/content-variants/content-variants.types.ts +9 -0
  42. package/src/constants/sdk-version.ts +1 -1
  43. package/src/functions/get-content/generate-content-url.ts +12 -1
  44. package/src/functions/get-content/types.ts +29 -0
  45. package/src/scripts/init-editing.ts +4 -0
@@ -28,6 +28,7 @@ export let apiKey;
28
28
  export let apiHost = undefined;
29
29
  export let locale = undefined;
30
30
  export let enrich = undefined;
31
+ export let enrichOptions = undefined;
31
32
  export let trustedHosts = undefined;
32
33
  export let model;
33
34
  export let content;
@@ -215,6 +216,11 @@ function elementRef_onIniteditingbldr(event) {
215
216
  enrich: enrich,
216
217
  }
217
218
  : {}),
219
+ ...(enrichOptions
220
+ ? {
221
+ enrichOptions: enrichOptions,
222
+ }
223
+ : {}),
218
224
  ...(trustedHosts
219
225
  ? {
220
226
  trustedHosts: trustedHosts,
@@ -16,6 +16,7 @@ declare const __propDef: {
16
16
  apiHost?: BuilderEditorProps["apiHost"];
17
17
  locale?: BuilderEditorProps["locale"];
18
18
  enrich?: BuilderEditorProps["enrich"];
19
+ enrichOptions?: BuilderEditorProps["enrichOptions"];
19
20
  trustedHosts?: BuilderEditorProps["trustedHosts"];
20
21
  model: BuilderEditorProps["model"];
21
22
  content: BuilderEditorProps["content"];
@@ -28,6 +28,7 @@ export let nonce = undefined;
28
28
  export let model;
29
29
  export let apiHost = undefined;
30
30
  export let enrich = undefined;
31
+ export let enrichOptions = undefined;
31
32
  export let showContent;
32
33
  export let contentWrapper = undefined;
33
34
  export let contentWrapperProps = undefined;
@@ -140,6 +141,7 @@ setContext(ComponentsContext.key, {
140
141
  {canTrack}
141
142
  {locale}
142
143
  {enrich}
144
+ {enrichOptions}
143
145
  {showContent}
144
146
  {builderContextSignal}
145
147
  {contentWrapper}
@@ -16,6 +16,7 @@ declare const __propDef: {
16
16
  model: ContentProps["model"];
17
17
  apiHost?: ContentProps["apiHost"];
18
18
  enrich?: ContentProps["enrich"];
19
+ enrichOptions?: ContentProps["enrichOptions"];
19
20
  showContent: ContentProps["showContent"];
20
21
  contentWrapper?: ContentProps["contentWrapper"];
21
22
  contentWrapperProps?: ContentProps["contentWrapperProps"];
@@ -23,6 +23,7 @@ export let customComponents = undefined;
23
23
  export let linkComponent = undefined;
24
24
  export let locale = undefined;
25
25
  export let enrich = undefined;
26
+ export let enrichOptions = undefined;
26
27
  export let blocksWrapper = undefined;
27
28
  export let blocksWrapperProps = undefined;
28
29
  export let contentWrapper = undefined;
@@ -107,6 +108,7 @@ onMount(() => {
107
108
  {canTrack}
108
109
  {locale}
109
110
  {enrich}
111
+ {enrichOptions}
110
112
  isSsrAbTest={shouldRenderVariants}
111
113
  {blocksWrapper}
112
114
  {blocksWrapperProps}
@@ -134,6 +136,7 @@ onMount(() => {
134
136
  {canTrack}
135
137
  {locale}
136
138
  {enrich}
139
+ {enrichOptions}
137
140
  isSsrAbTest={shouldRenderVariants}
138
141
  {blocksWrapper}
139
142
  {blocksWrapperProps}
@@ -22,6 +22,7 @@ declare const __propDef: {
22
22
  linkComponent?: VariantsProviderProps["linkComponent"];
23
23
  locale?: VariantsProviderProps["locale"];
24
24
  enrich?: VariantsProviderProps["enrich"];
25
+ enrichOptions?: VariantsProviderProps["enrichOptions"];
25
26
  blocksWrapper?: VariantsProviderProps["blocksWrapper"];
26
27
  blocksWrapperProps?: VariantsProviderProps["blocksWrapperProps"];
27
28
  contentWrapper?: VariantsProviderProps["contentWrapper"];
@@ -1,4 +1,5 @@
1
1
  import type { BuilderRenderContext, RegisteredComponent } from '../../context/types';
2
+ import type { EnrichOptions } from '../../functions/get-content/types';
2
3
  import type { ApiVersion } from '../../types/api-version';
3
4
  import type { BuilderContent } from '../../types/builder-content';
4
5
  import type { Nullable } from '../../types/typescript';
@@ -53,6 +54,13 @@ export interface ContentVariantsPrps extends ExtraFrameworkProps {
53
54
  * Enriching will Include multilevel references in the response. Defaults to `false`.
54
55
  */
55
56
  enrich?: boolean;
57
+ /**
58
+ * The `enrichOptions` used to fetch this content (optional).
59
+ *
60
+ * Passing the same value you passed to `fetchOneEntry` lets the Visual Editor
61
+ * resolve references in its preview the way your site fetches them.
62
+ */
63
+ enrichOptions?: EnrichOptions;
56
64
  /**
57
65
  * The element that wraps your content. Defaults to `<div>` ('ScrollView' in React Native).
58
66
  */
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "5.2.9";
1
+ export declare const SDK_VERSION = "5.2.11";
@@ -1 +1 @@
1
- export const SDK_VERSION = "5.2.9";
1
+ export const SDK_VERSION = "5.2.11";
@@ -5,7 +5,7 @@ import { getBuilderSearchParamsFromWindow } from '../get-builder-search-params/i
5
5
  import { isBrowser } from '../is-browser';
6
6
  const isPositiveNumber = (thing) => typeof thing === 'number' && !isNaN(thing) && thing >= 0;
7
7
  export const generateContentUrl = (options) => {
8
- const { limit = 30, userAttributes, query, model, apiKey, enrich, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished, apiHost } = options;
8
+ const { limit = 30, userAttributes, query, model, apiKey, enrich, enrichOptions, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished, apiHost } = options;
9
9
  if (!apiKey) {
10
10
  throw new Error('Missing API key');
11
11
  }
@@ -26,6 +26,10 @@ export const generateContentUrl = (options) => {
26
26
  let finalUserAttributes = userAttributes || {};
27
27
  if (enrich)
28
28
  url.searchParams.set('enrich', String(enrich));
29
+ // Only honored alongside `enrich=true` by the content API.
30
+ if (enrich && enrichOptions) {
31
+ url.searchParams.set('enrichOptions', JSON.stringify(enrichOptions));
32
+ }
29
33
  url.searchParams.set('omit', omit ?? 'meta.componentsUsed');
30
34
  if (fields) {
31
35
  url.searchParams.set('fields', fields);
@@ -76,11 +80,18 @@ export const generateContentUrl = (options) => {
76
80
  }
77
81
  return url;
78
82
  };
83
+ const parseStudioUserAttribute = (value) => {
84
+ if (value === 'true')
85
+ return true;
86
+ if (value === 'false')
87
+ return false;
88
+ return value;
89
+ };
79
90
  const getUserAttributesFromQueryOptions = (queryOptions) => {
80
91
  const newUserAttributes = {};
81
92
  for (const key in queryOptions) {
82
93
  if (key.startsWith('userAttributes.')) {
83
- newUserAttributes[key] = queryOptions[key];
94
+ newUserAttributes[key] = parseStudioUserAttribute(queryOptions[key]);
84
95
  delete queryOptions[key];
85
96
  }
86
97
  }
@@ -1,3 +1,26 @@
1
+ /**
2
+ * Options to configure how `enrich` resolves references.
3
+ *
4
+ * @see {@link https://www.builder.io/c/docs/content-api#code-enrich-options-code}
5
+ */
6
+ export interface EnrichOptions {
7
+ /**
8
+ * How many levels of nested references to resolve. Higher levels multiply
9
+ * response size, so prefer the lowest level your content needs.
10
+ */
11
+ enrichLevel?: number;
12
+ /**
13
+ * Per-model field filters applied to resolved references.
14
+ */
15
+ model?: {
16
+ [modelName: string]: {
17
+ /** Comma-separated list of fields to include */
18
+ fields?: string;
19
+ /** Comma-separated list of fields to omit */
20
+ omit?: string;
21
+ };
22
+ };
23
+ }
1
24
  export interface GetContentOptions {
2
25
  /** The model to get content for (required) */
3
26
  model: string;
@@ -58,6 +81,10 @@ export interface GetContentOptions {
58
81
  * Include multilevel references in the response.
59
82
  */
60
83
  enrich?: boolean;
84
+ /**
85
+ * Constrains how `enrich` resolves references. Only honored when `enrich` is `true`.
86
+ */
87
+ enrichOptions?: EnrichOptions;
61
88
  /**
62
89
  * If provided, the API will auto-resolve localized objects to the value of this `locale` key.
63
90
  */
@@ -1,7 +1,9 @@
1
+ import type { EnrichOptions } from '../functions/get-content/types';
1
2
  export declare const setupBrowserForEditing: (options: {
2
3
  modelName: string;
3
4
  apiKey: string;
4
5
  enrich?: boolean;
6
+ enrichOptions?: EnrichOptions;
5
7
  includeRefs?: boolean;
6
8
  locale?: string;
7
9
  trustedHosts?: string[];
@@ -28,6 +28,7 @@ export let apiKey;
28
28
  export let apiHost = undefined;
29
29
  export let locale = undefined;
30
30
  export let enrich = undefined;
31
+ export let enrichOptions = undefined;
31
32
  export let trustedHosts = undefined;
32
33
  export let model;
33
34
  export let content;
@@ -215,6 +216,11 @@ function elementRef_onIniteditingbldr(event) {
215
216
  enrich: enrich,
216
217
  }
217
218
  : {}),
219
+ ...(enrichOptions
220
+ ? {
221
+ enrichOptions: enrichOptions,
222
+ }
223
+ : {}),
218
224
  ...(trustedHosts
219
225
  ? {
220
226
  trustedHosts: trustedHosts,
@@ -16,6 +16,7 @@ declare const __propDef: {
16
16
  apiHost?: BuilderEditorProps["apiHost"];
17
17
  locale?: BuilderEditorProps["locale"];
18
18
  enrich?: BuilderEditorProps["enrich"];
19
+ enrichOptions?: BuilderEditorProps["enrichOptions"];
19
20
  trustedHosts?: BuilderEditorProps["trustedHosts"];
20
21
  model: BuilderEditorProps["model"];
21
22
  content: BuilderEditorProps["content"];
@@ -28,6 +28,7 @@ export let nonce = undefined;
28
28
  export let model;
29
29
  export let apiHost = undefined;
30
30
  export let enrich = undefined;
31
+ export let enrichOptions = undefined;
31
32
  export let showContent;
32
33
  export let contentWrapper = undefined;
33
34
  export let contentWrapperProps = undefined;
@@ -140,6 +141,7 @@ setContext(ComponentsContext.key, {
140
141
  {canTrack}
141
142
  {locale}
142
143
  {enrich}
144
+ {enrichOptions}
143
145
  {showContent}
144
146
  {builderContextSignal}
145
147
  {contentWrapper}
@@ -16,6 +16,7 @@ declare const __propDef: {
16
16
  model: ContentProps["model"];
17
17
  apiHost?: ContentProps["apiHost"];
18
18
  enrich?: ContentProps["enrich"];
19
+ enrichOptions?: ContentProps["enrichOptions"];
19
20
  showContent: ContentProps["showContent"];
20
21
  contentWrapper?: ContentProps["contentWrapper"];
21
22
  contentWrapperProps?: ContentProps["contentWrapperProps"];
@@ -23,6 +23,7 @@ export let customComponents = undefined;
23
23
  export let linkComponent = undefined;
24
24
  export let locale = undefined;
25
25
  export let enrich = undefined;
26
+ export let enrichOptions = undefined;
26
27
  export let blocksWrapper = undefined;
27
28
  export let blocksWrapperProps = undefined;
28
29
  export let contentWrapper = undefined;
@@ -107,6 +108,7 @@ onMount(() => {
107
108
  {canTrack}
108
109
  {locale}
109
110
  {enrich}
111
+ {enrichOptions}
110
112
  isSsrAbTest={shouldRenderVariants}
111
113
  {blocksWrapper}
112
114
  {blocksWrapperProps}
@@ -134,6 +136,7 @@ onMount(() => {
134
136
  {canTrack}
135
137
  {locale}
136
138
  {enrich}
139
+ {enrichOptions}
137
140
  isSsrAbTest={shouldRenderVariants}
138
141
  {blocksWrapper}
139
142
  {blocksWrapperProps}
@@ -22,6 +22,7 @@ declare const __propDef: {
22
22
  linkComponent?: VariantsProviderProps["linkComponent"];
23
23
  locale?: VariantsProviderProps["locale"];
24
24
  enrich?: VariantsProviderProps["enrich"];
25
+ enrichOptions?: VariantsProviderProps["enrichOptions"];
25
26
  blocksWrapper?: VariantsProviderProps["blocksWrapper"];
26
27
  blocksWrapperProps?: VariantsProviderProps["blocksWrapperProps"];
27
28
  contentWrapper?: VariantsProviderProps["contentWrapper"];
@@ -1,4 +1,5 @@
1
1
  import type { BuilderRenderContext, RegisteredComponent } from '../../context/types';
2
+ import type { EnrichOptions } from '../../functions/get-content/types';
2
3
  import type { ApiVersion } from '../../types/api-version';
3
4
  import type { BuilderContent } from '../../types/builder-content';
4
5
  import type { Nullable } from '../../types/typescript';
@@ -53,6 +54,13 @@ export interface ContentVariantsPrps extends ExtraFrameworkProps {
53
54
  * Enriching will Include multilevel references in the response. Defaults to `false`.
54
55
  */
55
56
  enrich?: boolean;
57
+ /**
58
+ * The `enrichOptions` used to fetch this content (optional).
59
+ *
60
+ * Passing the same value you passed to `fetchOneEntry` lets the Visual Editor
61
+ * resolve references in its preview the way your site fetches them.
62
+ */
63
+ enrichOptions?: EnrichOptions;
56
64
  /**
57
65
  * The element that wraps your content. Defaults to `<div>` ('ScrollView' in React Native).
58
66
  */
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "5.2.9";
1
+ export declare const SDK_VERSION = "5.2.11";
@@ -1 +1 @@
1
- export const SDK_VERSION = "5.2.9";
1
+ export const SDK_VERSION = "5.2.11";
@@ -5,7 +5,7 @@ import { getBuilderSearchParamsFromWindow } from '../get-builder-search-params/i
5
5
  import { isBrowser } from '../is-browser';
6
6
  const isPositiveNumber = (thing) => typeof thing === 'number' && !isNaN(thing) && thing >= 0;
7
7
  export const generateContentUrl = (options) => {
8
- const { limit = 30, userAttributes, query, model, apiKey, enrich, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished, apiHost } = options;
8
+ const { limit = 30, userAttributes, query, model, apiKey, enrich, enrichOptions, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished, apiHost } = options;
9
9
  if (!apiKey) {
10
10
  throw new Error('Missing API key');
11
11
  }
@@ -26,6 +26,10 @@ export const generateContentUrl = (options) => {
26
26
  let finalUserAttributes = userAttributes || {};
27
27
  if (enrich)
28
28
  url.searchParams.set('enrich', String(enrich));
29
+ // Only honored alongside `enrich=true` by the content API.
30
+ if (enrich && enrichOptions) {
31
+ url.searchParams.set('enrichOptions', JSON.stringify(enrichOptions));
32
+ }
29
33
  url.searchParams.set('omit', omit ?? 'meta.componentsUsed');
30
34
  if (fields) {
31
35
  url.searchParams.set('fields', fields);
@@ -76,11 +80,18 @@ export const generateContentUrl = (options) => {
76
80
  }
77
81
  return url;
78
82
  };
83
+ const parseStudioUserAttribute = (value) => {
84
+ if (value === 'true')
85
+ return true;
86
+ if (value === 'false')
87
+ return false;
88
+ return value;
89
+ };
79
90
  const getUserAttributesFromQueryOptions = (queryOptions) => {
80
91
  const newUserAttributes = {};
81
92
  for (const key in queryOptions) {
82
93
  if (key.startsWith('userAttributes.')) {
83
- newUserAttributes[key] = queryOptions[key];
94
+ newUserAttributes[key] = parseStudioUserAttribute(queryOptions[key]);
84
95
  delete queryOptions[key];
85
96
  }
86
97
  }
@@ -1,3 +1,26 @@
1
+ /**
2
+ * Options to configure how `enrich` resolves references.
3
+ *
4
+ * @see {@link https://www.builder.io/c/docs/content-api#code-enrich-options-code}
5
+ */
6
+ export interface EnrichOptions {
7
+ /**
8
+ * How many levels of nested references to resolve. Higher levels multiply
9
+ * response size, so prefer the lowest level your content needs.
10
+ */
11
+ enrichLevel?: number;
12
+ /**
13
+ * Per-model field filters applied to resolved references.
14
+ */
15
+ model?: {
16
+ [modelName: string]: {
17
+ /** Comma-separated list of fields to include */
18
+ fields?: string;
19
+ /** Comma-separated list of fields to omit */
20
+ omit?: string;
21
+ };
22
+ };
23
+ }
1
24
  export interface GetContentOptions {
2
25
  /** The model to get content for (required) */
3
26
  model: string;
@@ -58,6 +81,10 @@ export interface GetContentOptions {
58
81
  * Include multilevel references in the response.
59
82
  */
60
83
  enrich?: boolean;
84
+ /**
85
+ * Constrains how `enrich` resolves references. Only honored when `enrich` is `true`.
86
+ */
87
+ enrichOptions?: EnrichOptions;
61
88
  /**
62
89
  * If provided, the API will auto-resolve localized objects to the value of this `locale` key.
63
90
  */
@@ -1,7 +1,9 @@
1
+ import type { EnrichOptions } from '../functions/get-content/types';
1
2
  export declare const setupBrowserForEditing: (options: {
2
3
  modelName: string;
3
4
  apiKey: string;
4
5
  enrich?: boolean;
6
+ enrichOptions?: EnrichOptions;
5
7
  includeRefs?: boolean;
6
8
  locale?: string;
7
9
  trustedHosts?: string[];
@@ -28,6 +28,7 @@ export let apiKey;
28
28
  export let apiHost = undefined;
29
29
  export let locale = undefined;
30
30
  export let enrich = undefined;
31
+ export let enrichOptions = undefined;
31
32
  export let trustedHosts = undefined;
32
33
  export let model;
33
34
  export let content;
@@ -215,6 +216,11 @@ function elementRef_onIniteditingbldr(event) {
215
216
  enrich: enrich,
216
217
  }
217
218
  : {}),
219
+ ...(enrichOptions
220
+ ? {
221
+ enrichOptions: enrichOptions,
222
+ }
223
+ : {}),
218
224
  ...(trustedHosts
219
225
  ? {
220
226
  trustedHosts: trustedHosts,
@@ -16,6 +16,7 @@ declare const __propDef: {
16
16
  apiHost?: BuilderEditorProps["apiHost"];
17
17
  locale?: BuilderEditorProps["locale"];
18
18
  enrich?: BuilderEditorProps["enrich"];
19
+ enrichOptions?: BuilderEditorProps["enrichOptions"];
19
20
  trustedHosts?: BuilderEditorProps["trustedHosts"];
20
21
  model: BuilderEditorProps["model"];
21
22
  content: BuilderEditorProps["content"];
@@ -28,6 +28,7 @@ export let nonce = undefined;
28
28
  export let model;
29
29
  export let apiHost = undefined;
30
30
  export let enrich = undefined;
31
+ export let enrichOptions = undefined;
31
32
  export let showContent;
32
33
  export let contentWrapper = undefined;
33
34
  export let contentWrapperProps = undefined;
@@ -140,6 +141,7 @@ setContext(ComponentsContext.key, {
140
141
  {canTrack}
141
142
  {locale}
142
143
  {enrich}
144
+ {enrichOptions}
143
145
  {showContent}
144
146
  {builderContextSignal}
145
147
  {contentWrapper}
@@ -16,6 +16,7 @@ declare const __propDef: {
16
16
  model: ContentProps["model"];
17
17
  apiHost?: ContentProps["apiHost"];
18
18
  enrich?: ContentProps["enrich"];
19
+ enrichOptions?: ContentProps["enrichOptions"];
19
20
  showContent: ContentProps["showContent"];
20
21
  contentWrapper?: ContentProps["contentWrapper"];
21
22
  contentWrapperProps?: ContentProps["contentWrapperProps"];
@@ -23,6 +23,7 @@ export let customComponents = undefined;
23
23
  export let linkComponent = undefined;
24
24
  export let locale = undefined;
25
25
  export let enrich = undefined;
26
+ export let enrichOptions = undefined;
26
27
  export let blocksWrapper = undefined;
27
28
  export let blocksWrapperProps = undefined;
28
29
  export let contentWrapper = undefined;
@@ -107,6 +108,7 @@ onMount(() => {
107
108
  {canTrack}
108
109
  {locale}
109
110
  {enrich}
111
+ {enrichOptions}
110
112
  isSsrAbTest={shouldRenderVariants}
111
113
  {blocksWrapper}
112
114
  {blocksWrapperProps}
@@ -134,6 +136,7 @@ onMount(() => {
134
136
  {canTrack}
135
137
  {locale}
136
138
  {enrich}
139
+ {enrichOptions}
137
140
  isSsrAbTest={shouldRenderVariants}
138
141
  {blocksWrapper}
139
142
  {blocksWrapperProps}
@@ -22,6 +22,7 @@ declare const __propDef: {
22
22
  linkComponent?: VariantsProviderProps["linkComponent"];
23
23
  locale?: VariantsProviderProps["locale"];
24
24
  enrich?: VariantsProviderProps["enrich"];
25
+ enrichOptions?: VariantsProviderProps["enrichOptions"];
25
26
  blocksWrapper?: VariantsProviderProps["blocksWrapper"];
26
27
  blocksWrapperProps?: VariantsProviderProps["blocksWrapperProps"];
27
28
  contentWrapper?: VariantsProviderProps["contentWrapper"];
@@ -1,4 +1,5 @@
1
1
  import type { BuilderRenderContext, RegisteredComponent } from '../../context/types';
2
+ import type { EnrichOptions } from '../../functions/get-content/types';
2
3
  import type { ApiVersion } from '../../types/api-version';
3
4
  import type { BuilderContent } from '../../types/builder-content';
4
5
  import type { Nullable } from '../../types/typescript';
@@ -53,6 +54,13 @@ export interface ContentVariantsPrps extends ExtraFrameworkProps {
53
54
  * Enriching will Include multilevel references in the response. Defaults to `false`.
54
55
  */
55
56
  enrich?: boolean;
57
+ /**
58
+ * The `enrichOptions` used to fetch this content (optional).
59
+ *
60
+ * Passing the same value you passed to `fetchOneEntry` lets the Visual Editor
61
+ * resolve references in its preview the way your site fetches them.
62
+ */
63
+ enrichOptions?: EnrichOptions;
56
64
  /**
57
65
  * The element that wraps your content. Defaults to `<div>` ('ScrollView' in React Native).
58
66
  */
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "5.2.9";
1
+ export declare const SDK_VERSION = "5.2.11";
@@ -1 +1 @@
1
- export const SDK_VERSION = "5.2.9";
1
+ export const SDK_VERSION = "5.2.11";
@@ -5,7 +5,7 @@ import { getBuilderSearchParamsFromWindow } from '../get-builder-search-params/i
5
5
  import { isBrowser } from '../is-browser';
6
6
  const isPositiveNumber = (thing) => typeof thing === 'number' && !isNaN(thing) && thing >= 0;
7
7
  export const generateContentUrl = (options) => {
8
- const { limit = 30, userAttributes, query, model, apiKey, enrich, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished, apiHost } = options;
8
+ const { limit = 30, userAttributes, query, model, apiKey, enrich, enrichOptions, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished, apiHost } = options;
9
9
  if (!apiKey) {
10
10
  throw new Error('Missing API key');
11
11
  }
@@ -26,6 +26,10 @@ export const generateContentUrl = (options) => {
26
26
  let finalUserAttributes = userAttributes || {};
27
27
  if (enrich)
28
28
  url.searchParams.set('enrich', String(enrich));
29
+ // Only honored alongside `enrich=true` by the content API.
30
+ if (enrich && enrichOptions) {
31
+ url.searchParams.set('enrichOptions', JSON.stringify(enrichOptions));
32
+ }
29
33
  url.searchParams.set('omit', omit ?? 'meta.componentsUsed');
30
34
  if (fields) {
31
35
  url.searchParams.set('fields', fields);
@@ -76,11 +80,18 @@ export const generateContentUrl = (options) => {
76
80
  }
77
81
  return url;
78
82
  };
83
+ const parseStudioUserAttribute = (value) => {
84
+ if (value === 'true')
85
+ return true;
86
+ if (value === 'false')
87
+ return false;
88
+ return value;
89
+ };
79
90
  const getUserAttributesFromQueryOptions = (queryOptions) => {
80
91
  const newUserAttributes = {};
81
92
  for (const key in queryOptions) {
82
93
  if (key.startsWith('userAttributes.')) {
83
- newUserAttributes[key] = queryOptions[key];
94
+ newUserAttributes[key] = parseStudioUserAttribute(queryOptions[key]);
84
95
  delete queryOptions[key];
85
96
  }
86
97
  }
@@ -1,3 +1,26 @@
1
+ /**
2
+ * Options to configure how `enrich` resolves references.
3
+ *
4
+ * @see {@link https://www.builder.io/c/docs/content-api#code-enrich-options-code}
5
+ */
6
+ export interface EnrichOptions {
7
+ /**
8
+ * How many levels of nested references to resolve. Higher levels multiply
9
+ * response size, so prefer the lowest level your content needs.
10
+ */
11
+ enrichLevel?: number;
12
+ /**
13
+ * Per-model field filters applied to resolved references.
14
+ */
15
+ model?: {
16
+ [modelName: string]: {
17
+ /** Comma-separated list of fields to include */
18
+ fields?: string;
19
+ /** Comma-separated list of fields to omit */
20
+ omit?: string;
21
+ };
22
+ };
23
+ }
1
24
  export interface GetContentOptions {
2
25
  /** The model to get content for (required) */
3
26
  model: string;
@@ -58,6 +81,10 @@ export interface GetContentOptions {
58
81
  * Include multilevel references in the response.
59
82
  */
60
83
  enrich?: boolean;
84
+ /**
85
+ * Constrains how `enrich` resolves references. Only honored when `enrich` is `true`.
86
+ */
87
+ enrichOptions?: EnrichOptions;
61
88
  /**
62
89
  * If provided, the API will auto-resolve localized objects to the value of this `locale` key.
63
90
  */
@@ -1,7 +1,9 @@
1
+ import type { EnrichOptions } from '../functions/get-content/types';
1
2
  export declare const setupBrowserForEditing: (options: {
2
3
  modelName: string;
3
4
  apiKey: string;
4
5
  enrich?: boolean;
6
+ enrichOptions?: EnrichOptions;
5
7
  includeRefs?: boolean;
6
8
  locale?: string;
7
9
  trustedHosts?: string[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-svelte",
3
3
  "description": "Builder.io SDK for Svelte",
4
- "version": "5.2.9",
4
+ "version": "5.2.11",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "lib",
@@ -78,6 +78,7 @@
78
78
  export let apiHost: BuilderEditorProps["apiHost"] = undefined;
79
79
  export let locale: BuilderEditorProps["locale"] = undefined;
80
80
  export let enrich: BuilderEditorProps["enrich"] = undefined;
81
+ export let enrichOptions: BuilderEditorProps["enrichOptions"] = undefined;
81
82
  export let trustedHosts: BuilderEditorProps["trustedHosts"] = undefined;
82
83
  export let model: BuilderEditorProps["model"];
83
84
  export let content: BuilderEditorProps["content"];
@@ -286,6 +287,11 @@
286
287
  enrich: enrich,
287
288
  }
288
289
  : {}),
290
+ ...(enrichOptions
291
+ ? {
292
+ enrichOptions: enrichOptions,
293
+ }
294
+ : {}),
289
295
  ...(trustedHosts
290
296
  ? {
291
297
  trustedHosts: trustedHosts,
@@ -42,6 +42,7 @@
42
42
  export let model: ContentProps["model"];
43
43
  export let apiHost: ContentProps["apiHost"] = undefined;
44
44
  export let enrich: ContentProps["enrich"] = undefined;
45
+ export let enrichOptions: ContentProps["enrichOptions"] = undefined;
45
46
  export let showContent: ContentProps["showContent"];
46
47
  export let contentWrapper: ContentProps["contentWrapper"] = undefined;
47
48
  export let contentWrapperProps: ContentProps["contentWrapperProps"] =
@@ -170,6 +171,7 @@
170
171
  {canTrack}
171
172
  {locale}
172
173
  {enrich}
174
+ {enrichOptions}
173
175
  {showContent}
174
176
  {builderContextSignal}
175
177
  {contentWrapper}
@@ -45,6 +45,7 @@
45
45
  export let linkComponent: VariantsProviderProps["linkComponent"] = undefined;
46
46
  export let locale: VariantsProviderProps["locale"] = undefined;
47
47
  export let enrich: VariantsProviderProps["enrich"] = undefined;
48
+ export let enrichOptions: VariantsProviderProps["enrichOptions"] = undefined;
48
49
  export let blocksWrapper: VariantsProviderProps["blocksWrapper"] = undefined;
49
50
  export let blocksWrapperProps: VariantsProviderProps["blocksWrapperProps"] =
50
51
  undefined;
@@ -139,6 +140,7 @@
139
140
  {canTrack}
140
141
  {locale}
141
142
  {enrich}
143
+ {enrichOptions}
142
144
  isSsrAbTest={shouldRenderVariants}
143
145
  {blocksWrapper}
144
146
  {blocksWrapperProps}
@@ -166,6 +168,7 @@
166
168
  {canTrack}
167
169
  {locale}
168
170
  {enrich}
171
+ {enrichOptions}
169
172
  isSsrAbTest={shouldRenderVariants}
170
173
  {blocksWrapper}
171
174
  {blocksWrapperProps}
@@ -1,4 +1,5 @@
1
1
  import type { BuilderRenderContext, RegisteredComponent } from '../../context/types';
2
+ import type { EnrichOptions } from '../../functions/get-content/types';
2
3
  import type { ApiVersion } from '../../types/api-version';
3
4
  import type { BuilderContent } from '../../types/builder-content';
4
5
  import type { Nullable } from '../../types/typescript';
@@ -63,6 +64,14 @@ export interface ContentVariantsPrps extends ExtraFrameworkProps {
63
64
  */
64
65
  enrich?: boolean;
65
66
 
67
+ /**
68
+ * The `enrichOptions` used to fetch this content (optional).
69
+ *
70
+ * Passing the same value you passed to `fetchOneEntry` lets the Visual Editor
71
+ * resolve references in its preview the way your site fetches them.
72
+ */
73
+ enrichOptions?: EnrichOptions;
74
+
66
75
  /**
67
76
  * The element that wraps your content. Defaults to `<div>` ('ScrollView' in React Native).
68
77
  */
@@ -1 +1 @@
1
- export const SDK_VERSION = "5.2.9"
1
+ export const SDK_VERSION = "5.2.11"
@@ -13,6 +13,7 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
13
13
  model,
14
14
  apiKey,
15
15
  enrich,
16
+ enrichOptions,
16
17
  locale,
17
18
  apiVersion = DEFAULT_API_VERSION,
18
19
  fields,
@@ -44,6 +45,11 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
44
45
  }
45
46
  let finalUserAttributes: Record<string, any> = userAttributes || {};
46
47
  if (enrich) url.searchParams.set('enrich', String(enrich));
48
+
49
+ // Only honored alongside `enrich=true` by the content API.
50
+ if (enrich && enrichOptions) {
51
+ url.searchParams.set('enrichOptions', JSON.stringify(enrichOptions));
52
+ }
47
53
  url.searchParams.set('omit', omit ?? 'meta.componentsUsed');
48
54
  if (fields) {
49
55
  url.searchParams.set('fields', fields);
@@ -96,11 +102,16 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
96
102
  }
97
103
  return url;
98
104
  };
105
+ const parseStudioUserAttribute = (value: unknown) => {
106
+ if (value === 'true') return true;
107
+ if (value === 'false') return false;
108
+ return value;
109
+ };
99
110
  const getUserAttributesFromQueryOptions = (queryOptions: any) => {
100
111
  const newUserAttributes: any = {};
101
112
  for (const key in queryOptions) {
102
113
  if (key.startsWith('userAttributes.')) {
103
- newUserAttributes[key] = queryOptions[key];
114
+ newUserAttributes[key] = parseStudioUserAttribute(queryOptions[key]);
104
115
  delete queryOptions[key];
105
116
  }
106
117
  }
@@ -1,3 +1,27 @@
1
+ /**
2
+ * Options to configure how `enrich` resolves references.
3
+ *
4
+ * @see {@link https://www.builder.io/c/docs/content-api#code-enrich-options-code}
5
+ */
6
+ export interface EnrichOptions {
7
+ /**
8
+ * How many levels of nested references to resolve. Higher levels multiply
9
+ * response size, so prefer the lowest level your content needs.
10
+ */
11
+ enrichLevel?: number;
12
+
13
+ /**
14
+ * Per-model field filters applied to resolved references.
15
+ */
16
+ model?: {
17
+ [modelName: string]: {
18
+ /** Comma-separated list of fields to include */
19
+ fields?: string;
20
+ /** Comma-separated list of fields to omit */
21
+ omit?: string;
22
+ };
23
+ };
24
+ }
1
25
  export interface GetContentOptions {
2
26
  /** The model to get content for (required) */
3
27
  model: string;
@@ -67,6 +91,11 @@ export interface GetContentOptions {
67
91
  */
68
92
  enrich?: boolean;
69
93
 
94
+ /**
95
+ * Constrains how `enrich` resolves references. Only honored when `enrich` is `true`.
96
+ */
97
+ enrichOptions?: EnrichOptions;
98
+
70
99
  /**
71
100
  * If provided, the API will auto-resolve localized objects to the value of this `locale` key.
72
101
  */
@@ -1,5 +1,6 @@
1
1
  import { SDK_VERSION } from '../constants/sdk-version';
2
2
  import { TARGET } from '../constants/target';
3
+ import type { EnrichOptions } from '../functions/get-content/types';
3
4
  import { isBrowser } from '../functions/is-browser';
4
5
  import { isFromTrustedHost } from '../functions/is-from-trusted-host';
5
6
  let isSetupForEditing = false;
@@ -7,6 +8,9 @@ export const setupBrowserForEditing = (options: {
7
8
  modelName: string;
8
9
  apiKey: string;
9
10
  enrich?: boolean;
11
+ // Forwarded to the editor as part of `builder.updateContent` below, so its
12
+ // preview can resolve references with the same constraints as this site's fetch.
13
+ enrichOptions?: EnrichOptions;
10
14
  includeRefs?: boolean;
11
15
  locale?: string;
12
16
  trustedHosts?: string[];