@builder.io/sdk-svelte 2.0.30 → 3.0.0

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.
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "2.0.30";
1
+ export declare const SDK_VERSION = "3.0.0";
@@ -1 +1 @@
1
- export const SDK_VERSION = "2.0.30";
1
+ export const SDK_VERSION = "3.0.0";
@@ -19,8 +19,15 @@ export const generateContentUrl = (options) => {
19
19
  url.searchParams.set('limit', String(limit));
20
20
  url.searchParams.set('noTraverse', String(noTraverse));
21
21
  url.searchParams.set('includeRefs', String(true));
22
- if (locale)
23
- url.searchParams.set('locale', locale);
22
+ const finalLocale = locale || userAttributes?.locale;
23
+ let finalUserAttributes = userAttributes;
24
+ if (finalLocale) {
25
+ url.searchParams.set('locale', finalLocale);
26
+ finalUserAttributes = {
27
+ locale: finalLocale,
28
+ ...finalUserAttributes
29
+ };
30
+ }
24
31
  if (enrich)
25
32
  url.searchParams.set('enrich', String(enrich));
26
33
  url.searchParams.set('omit', omit || 'meta.componentsUsed');
@@ -56,8 +63,8 @@ export const generateContentUrl = (options) => {
56
63
  for (const key in flattened) {
57
64
  url.searchParams.set(key, String(flattened[key]));
58
65
  }
59
- if (userAttributes) {
60
- url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
66
+ if (finalUserAttributes) {
67
+ url.searchParams.set('userAttributes', JSON.stringify(finalUserAttributes));
61
68
  }
62
69
  if (query) {
63
70
  const flattened = flattenMongoQuery({
@@ -14,5 +14,5 @@ export declare const _processContentResult: (options: GetContentOptions, content
14
14
  /**
15
15
  * Returns a paginated array of entries that match the given options.
16
16
  */
17
- export declare function fetchEntries(options: GetContentOptions): Promise<BuilderContent[] | null>;
17
+ export declare function fetchEntries(options: GetContentOptions): Promise<BuilderContent[]>;
18
18
  export {};
@@ -78,21 +78,15 @@ export const _processContentResult = async (options, content, url = generateCont
78
78
  * Returns a paginated array of entries that match the given options.
79
79
  */
80
80
  export async function fetchEntries(options) {
81
- try {
82
- const url = generateContentUrl(options);
83
- const content = await _fetchContent(options);
84
- if (!checkContentHasResults(content)) {
85
- logger.error('Error fetching data. ', {
86
- url,
87
- content,
88
- options
89
- });
90
- return null;
91
- }
92
- return _processContentResult(options, content);
93
- }
94
- catch (error) {
95
- logger.error('Error fetching data. ', error);
96
- return null;
81
+ const url = generateContentUrl(options);
82
+ const content = await _fetchContent(options);
83
+ if (!checkContentHasResults(content)) {
84
+ logger.error('Error fetching data. ', {
85
+ url,
86
+ content,
87
+ options
88
+ });
89
+ throw content;
97
90
  }
91
+ return _processContentResult(options, content);
98
92
  }
@@ -9,7 +9,9 @@ const serializeFn = (fnValue) => {
9
9
  // 1. `function name(args) => {code}`
10
10
  // 2. `name(args) => {code}`
11
11
  // 3. `(args) => {}`
12
- const appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(');
12
+ // 4. `args => {}`
13
+ const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
14
+ const appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(') && !isArrowWithoutParens;
13
15
  return `return (${appendFunction ? 'function ' : ''}${fnStr}).apply(this, arguments)`;
14
16
  };
15
17
  export function serializeIncludingFunctions(info) {
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "2.0.30";
1
+ export declare const SDK_VERSION = "3.0.0";
@@ -1 +1 @@
1
- export const SDK_VERSION = "2.0.30";
1
+ export const SDK_VERSION = "3.0.0";
@@ -19,8 +19,15 @@ export const generateContentUrl = (options) => {
19
19
  url.searchParams.set('limit', String(limit));
20
20
  url.searchParams.set('noTraverse', String(noTraverse));
21
21
  url.searchParams.set('includeRefs', String(true));
22
- if (locale)
23
- url.searchParams.set('locale', locale);
22
+ const finalLocale = locale || userAttributes?.locale;
23
+ let finalUserAttributes = userAttributes;
24
+ if (finalLocale) {
25
+ url.searchParams.set('locale', finalLocale);
26
+ finalUserAttributes = {
27
+ locale: finalLocale,
28
+ ...finalUserAttributes
29
+ };
30
+ }
24
31
  if (enrich)
25
32
  url.searchParams.set('enrich', String(enrich));
26
33
  url.searchParams.set('omit', omit || 'meta.componentsUsed');
@@ -56,8 +63,8 @@ export const generateContentUrl = (options) => {
56
63
  for (const key in flattened) {
57
64
  url.searchParams.set(key, String(flattened[key]));
58
65
  }
59
- if (userAttributes) {
60
- url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
66
+ if (finalUserAttributes) {
67
+ url.searchParams.set('userAttributes', JSON.stringify(finalUserAttributes));
61
68
  }
62
69
  if (query) {
63
70
  const flattened = flattenMongoQuery({
@@ -14,5 +14,5 @@ export declare const _processContentResult: (options: GetContentOptions, content
14
14
  /**
15
15
  * Returns a paginated array of entries that match the given options.
16
16
  */
17
- export declare function fetchEntries(options: GetContentOptions): Promise<BuilderContent[] | null>;
17
+ export declare function fetchEntries(options: GetContentOptions): Promise<BuilderContent[]>;
18
18
  export {};
@@ -78,21 +78,15 @@ export const _processContentResult = async (options, content, url = generateCont
78
78
  * Returns a paginated array of entries that match the given options.
79
79
  */
80
80
  export async function fetchEntries(options) {
81
- try {
82
- const url = generateContentUrl(options);
83
- const content = await _fetchContent(options);
84
- if (!checkContentHasResults(content)) {
85
- logger.error('Error fetching data. ', {
86
- url,
87
- content,
88
- options
89
- });
90
- return null;
91
- }
92
- return _processContentResult(options, content);
93
- }
94
- catch (error) {
95
- logger.error('Error fetching data. ', error);
96
- return null;
81
+ const url = generateContentUrl(options);
82
+ const content = await _fetchContent(options);
83
+ if (!checkContentHasResults(content)) {
84
+ logger.error('Error fetching data. ', {
85
+ url,
86
+ content,
87
+ options
88
+ });
89
+ throw content;
97
90
  }
91
+ return _processContentResult(options, content);
98
92
  }
@@ -9,7 +9,9 @@ const serializeFn = (fnValue) => {
9
9
  // 1. `function name(args) => {code}`
10
10
  // 2. `name(args) => {code}`
11
11
  // 3. `(args) => {}`
12
- const appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(');
12
+ // 4. `args => {}`
13
+ const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
14
+ const appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(') && !isArrowWithoutParens;
13
15
  return `return (${appendFunction ? 'function ' : ''}${fnStr}).apply(this, arguments)`;
14
16
  };
15
17
  export function serializeIncludingFunctions(info) {
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "2.0.30";
1
+ export declare const SDK_VERSION = "3.0.0";
@@ -1 +1 @@
1
- export const SDK_VERSION = "2.0.30";
1
+ export const SDK_VERSION = "3.0.0";
@@ -19,8 +19,15 @@ export const generateContentUrl = (options) => {
19
19
  url.searchParams.set('limit', String(limit));
20
20
  url.searchParams.set('noTraverse', String(noTraverse));
21
21
  url.searchParams.set('includeRefs', String(true));
22
- if (locale)
23
- url.searchParams.set('locale', locale);
22
+ const finalLocale = locale || userAttributes?.locale;
23
+ let finalUserAttributes = userAttributes;
24
+ if (finalLocale) {
25
+ url.searchParams.set('locale', finalLocale);
26
+ finalUserAttributes = {
27
+ locale: finalLocale,
28
+ ...finalUserAttributes
29
+ };
30
+ }
24
31
  if (enrich)
25
32
  url.searchParams.set('enrich', String(enrich));
26
33
  url.searchParams.set('omit', omit || 'meta.componentsUsed');
@@ -56,8 +63,8 @@ export const generateContentUrl = (options) => {
56
63
  for (const key in flattened) {
57
64
  url.searchParams.set(key, String(flattened[key]));
58
65
  }
59
- if (userAttributes) {
60
- url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
66
+ if (finalUserAttributes) {
67
+ url.searchParams.set('userAttributes', JSON.stringify(finalUserAttributes));
61
68
  }
62
69
  if (query) {
63
70
  const flattened = flattenMongoQuery({
@@ -14,5 +14,5 @@ export declare const _processContentResult: (options: GetContentOptions, content
14
14
  /**
15
15
  * Returns a paginated array of entries that match the given options.
16
16
  */
17
- export declare function fetchEntries(options: GetContentOptions): Promise<BuilderContent[] | null>;
17
+ export declare function fetchEntries(options: GetContentOptions): Promise<BuilderContent[]>;
18
18
  export {};
@@ -78,21 +78,15 @@ export const _processContentResult = async (options, content, url = generateCont
78
78
  * Returns a paginated array of entries that match the given options.
79
79
  */
80
80
  export async function fetchEntries(options) {
81
- try {
82
- const url = generateContentUrl(options);
83
- const content = await _fetchContent(options);
84
- if (!checkContentHasResults(content)) {
85
- logger.error('Error fetching data. ', {
86
- url,
87
- content,
88
- options
89
- });
90
- return null;
91
- }
92
- return _processContentResult(options, content);
93
- }
94
- catch (error) {
95
- logger.error('Error fetching data. ', error);
96
- return null;
81
+ const url = generateContentUrl(options);
82
+ const content = await _fetchContent(options);
83
+ if (!checkContentHasResults(content)) {
84
+ logger.error('Error fetching data. ', {
85
+ url,
86
+ content,
87
+ options
88
+ });
89
+ throw content;
97
90
  }
91
+ return _processContentResult(options, content);
98
92
  }
@@ -9,7 +9,9 @@ const serializeFn = (fnValue) => {
9
9
  // 1. `function name(args) => {code}`
10
10
  // 2. `name(args) => {code}`
11
11
  // 3. `(args) => {}`
12
- const appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(');
12
+ // 4. `args => {}`
13
+ const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
14
+ const appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(') && !isArrowWithoutParens;
13
15
  return `return (${appendFunction ? 'function ' : ''}${fnStr}).apply(this, arguments)`;
14
16
  };
15
17
  export function serializeIncludingFunctions(info) {
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": "2.0.30",
4
+ "version": "3.0.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "lib",
@@ -1 +1 @@
1
- export const SDK_VERSION = "2.0.30"
1
+ export const SDK_VERSION = "3.0.0"
@@ -38,7 +38,15 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
38
38
  url.searchParams.set('limit', String(limit));
39
39
  url.searchParams.set('noTraverse', String(noTraverse));
40
40
  url.searchParams.set('includeRefs', String(true));
41
- if (locale) url.searchParams.set('locale', locale);
41
+ const finalLocale = locale || userAttributes?.locale;
42
+ let finalUserAttributes = userAttributes;
43
+ if (finalLocale) {
44
+ url.searchParams.set('locale', finalLocale);
45
+ finalUserAttributes = {
46
+ locale: finalLocale,
47
+ ...finalUserAttributes
48
+ };
49
+ }
42
50
  if (enrich) url.searchParams.set('enrich', String(enrich));
43
51
  url.searchParams.set('omit', omit || 'meta.componentsUsed');
44
52
  if (fields) {
@@ -75,8 +83,8 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
75
83
  for (const key in flattened) {
76
84
  url.searchParams.set(key, String(flattened[key]));
77
85
  }
78
- if (userAttributes) {
79
- url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
86
+ if (finalUserAttributes) {
87
+ url.searchParams.set('userAttributes', JSON.stringify(finalUserAttributes));
80
88
  }
81
89
  if (query) {
82
90
  const flattened = flattenMongoQuery({
@@ -88,20 +88,15 @@ export const _processContentResult = async (options: GetContentOptions, content:
88
88
  * Returns a paginated array of entries that match the given options.
89
89
  */
90
90
  export async function fetchEntries(options: GetContentOptions) {
91
- try {
92
- const url = generateContentUrl(options);
93
- const content = await _fetchContent(options);
94
- if (!checkContentHasResults(content)) {
95
- logger.error('Error fetching data. ', {
96
- url,
97
- content,
98
- options
99
- });
100
- return null;
101
- }
102
- return _processContentResult(options, content);
103
- } catch (error) {
104
- logger.error('Error fetching data. ', error);
105
- return null;
91
+ const url = generateContentUrl(options);
92
+ const content = await _fetchContent(options);
93
+ if (!checkContentHasResults(content)) {
94
+ logger.error('Error fetching data. ', {
95
+ url,
96
+ content,
97
+ options
98
+ });
99
+ throw content;
106
100
  }
101
+ return _processContentResult(options, content);
107
102
  }
@@ -12,7 +12,9 @@ const serializeFn = (fnValue: Function) => {
12
12
  // 1. `function name(args) => {code}`
13
13
  // 2. `name(args) => {code}`
14
14
  // 3. `(args) => {}`
15
- const appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(');
15
+ // 4. `args => {}`
16
+ const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
17
+ const appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(') && !isArrowWithoutParens;
16
18
  return `return (${appendFunction ? 'function ' : ''}${fnStr}).apply(this, arguments)`;
17
19
  };
18
20
  export function serializeIncludingFunctions(info: ComponentInfo) {