@builder.io/sdk-svelte 0.0.10-0 → 0.0.11-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.
Files changed (29) hide show
  1. package/README.md +4 -0
  2. package/package/--package.json +3 -5
  3. package/package/README.md +4 -0
  4. package/package/blocks/symbol/symbol.svelte +17 -4
  5. package/package/blocks/symbol/symbol.svelte.d.ts +2 -1
  6. package/package/components/render-block/render-block.svelte +4 -1
  7. package/package/components/render-content/render-content.svelte +2 -3
  8. package/package/functions/get-content/generate-content-url.d.ts +2 -0
  9. package/package/functions/get-content/generate-content-url.js +27 -0
  10. package/package/functions/get-content/{fn.test.d.ts → generate-content-url.test.d.ts} +0 -0
  11. package/package/functions/get-content/{fn.test.js → generate-content-url.test.js} +1 -1
  12. package/package/functions/get-content/index.d.ts +1 -2
  13. package/package/functions/get-content/index.js +4 -30
  14. package/package/functions/get-fetch.d.ts +1 -1
  15. package/package/functions/get-fetch.js +7 -5
  16. package/package/functions/get-global-this.d.ts +2 -1
  17. package/package/functions/get-global-this.js +1 -1
  18. package/package/functions/get-react-native-block-styles.d.ts +2 -1
  19. package/package/functions/get-react-native-block-styles.js +2 -1
  20. package/package.json +1 -4
  21. package/src/blocks/symbol/symbol.svelte +17 -4
  22. package/src/components/render-block/render-block.svelte +4 -1
  23. package/src/components/render-content/render-content.svelte +2 -3
  24. package/src/functions/get-content/{fn.test.ts → generate-content-url.test.ts} +1 -1
  25. package/src/functions/get-content/generate-content-url.ts +51 -0
  26. package/src/functions/get-content/index.ts +5 -57
  27. package/src/functions/get-fetch.ts +11 -7
  28. package/src/functions/get-global-this.ts +2 -2
  29. package/src/functions/get-react-native-block-styles.ts +3 -0
package/README.md CHANGED
@@ -17,3 +17,7 @@ npm install @builder.io/sdk-svelte@dev
17
17
  ```
18
18
 
19
19
  Take a look at [our example repo](/examples/svelte/sveltekit) for how to use this SDK.
20
+
21
+ ## Fetch
22
+
23
+ This Package uses fetch. See [these docs](https://github.com/BuilderIO/this-package-uses-fetch/blob/main/README.md) for more information.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-svelte",
3
3
  "description": "Builder.io SDK for Svelte",
4
- "version": "0.0.9",
4
+ "version": "0.0.10",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "package",
@@ -95,7 +95,8 @@
95
95
  "./functions/get-builder-search-params/fn.test": "./functions/get-builder-search-params/fn.test.js",
96
96
  "./functions/get-builder-search-params": "./functions/get-builder-search-params/index.js",
97
97
  "./functions/get-content/ab-testing": "./functions/get-content/ab-testing.js",
98
- "./functions/get-content/fn.test": "./functions/get-content/fn.test.js",
98
+ "./functions/get-content/generate-content-url.test": "./functions/get-content/generate-content-url.test.js",
99
+ "./functions/get-content/generate-content-url": "./functions/get-content/generate-content-url.js",
99
100
  "./functions/get-content": "./functions/get-content/index.js",
100
101
  "./functions/get-content/types": "./functions/get-content/types.js",
101
102
  "./functions/get-fetch": "./functions/get-fetch.js",
@@ -154,8 +155,5 @@
154
155
  "tslib": "^2.3.1",
155
156
  "typescript": "^4",
156
157
  "vite": "^3.0.4"
157
- },
158
- "dependencies": {
159
- "node-fetch": "^2.6.1"
160
158
  }
161
159
  }
package/package/README.md CHANGED
@@ -17,3 +17,7 @@ npm install @builder.io/sdk-svelte@dev
17
17
  ```
18
18
 
19
19
  Take a look at [our example repo](/examples/svelte/sveltekit) for how to use this SDK.
20
+
21
+ ## Fetch
22
+
23
+ This Package uses fetch. See [these docs](https://github.com/BuilderIO/this-package-uses-fetch/blob/main/README.md) for more information.
@@ -4,6 +4,7 @@
4
4
  import RenderContent from "../../components/render-content/render-content.svelte";
5
5
  import BuilderContext from "../../context/builder.context.js";
6
6
  import { getContent } from "../../functions/get-content/index.js";
7
+ import { TARGET } from "../../constants/target";
7
8
  const isEvent = (attr) => attr.startsWith("on:");
8
9
  const isNonEvent = (attr) => !attr.startsWith("on:");
9
10
  const filterAttrs = (attrs, filter) => {
@@ -31,13 +32,25 @@ const setAttrs = (node, attrs) => {
31
32
  },
32
33
  };
33
34
  };
34
- export let symbol;
35
35
  export let attributes;
36
+ export let symbol;
37
+ export let dynamic;
36
38
  let builderContext = getContext(BuilderContext.key);
39
+ $: className = () => {
40
+ return [
41
+ ...(TARGET === "vue2" || TARGET === "vue3"
42
+ ? Object.keys(attributes.class)
43
+ : [attributes.class]),
44
+ "builder-symbol",
45
+ symbol?.inline ? "builder-inline-symbol" : undefined,
46
+ symbol?.dynamic || dynamic ? "builder-dynamic-symbol" : undefined,
47
+ ]
48
+ .filter(Boolean)
49
+ .join(" ");
50
+ };
37
51
  $: contentToUse = () => {
38
52
  return symbol?.content || fetchedContent;
39
53
  };
40
- let className = "builder-symbol";
41
54
  let fetchedContent = null;
42
55
  function onUpdateFn_0() {
43
56
  const symbolToUse = symbol;
@@ -71,9 +84,9 @@ $: onUpdateFn_0(...[symbol, fetchedContent]);
71
84
  <div
72
85
  {...filterAttrs(attributes, isNonEvent)}
73
86
  dataSet={{
74
- class: className,
87
+ class: className(),
75
88
  }}
76
- class={className}
89
+ class={className()}
77
90
  use:setAttrs={filterAttrs(attributes, isEvent)}
78
91
  >
79
92
  <RenderContent
@@ -19,8 +19,9 @@ export interface SymbolProps {
19
19
  }
20
20
  declare const __propDef: {
21
21
  props: {
22
- symbol: SymbolProps["symbol"];
23
22
  attributes: SymbolProps["attributes"];
23
+ symbol: SymbolProps["symbol"];
24
+ dynamic: SymbolProps["dynamic"];
24
25
  };
25
26
  events: {
26
27
  [evt: string]: CustomEvent<any>;
@@ -75,13 +75,15 @@ $: actions = () => {
75
75
  });
76
76
  };
77
77
  $: attributes = () => {
78
+ const blockProperties = getBlockProperties(useBlock());
78
79
  return {
79
- ...getBlockProperties(useBlock()),
80
+ ...blockProperties,
80
81
  ...(TARGET === "reactNative"
81
82
  ? {
82
83
  style: getReactNativeBlockStyles({
83
84
  block: useBlock(),
84
85
  context: context,
86
+ blockStyles: blockProperties.style,
85
87
  }),
86
88
  }
87
89
  : {}),
@@ -171,6 +173,7 @@ $: inheritedTextStyles = () => {
171
173
  const styles = getReactNativeBlockStyles({
172
174
  block: useBlock(),
173
175
  context: context,
176
+ blockStyles: attributes().style,
174
177
  });
175
178
  return extractTextStyles(styles);
176
179
  };
@@ -5,7 +5,7 @@ import { getDefaultRegisteredComponents } from "../../constants/builder-register
5
5
  import { TARGET } from "../../constants/target.js";
6
6
  import { evaluate } from "../../functions/evaluate.js";
7
7
  import { getContent } from "../../functions/get-content/index.js";
8
- import { getFetch } from "../../functions/get-fetch.js";
8
+ import { fetch } from "../../functions/get-fetch.js";
9
9
  import { isBrowser } from "../../functions/is-browser.js";
10
10
  import { isEditing } from "../../functions/is-editing.js";
11
11
  import { isPreviewing } from "../../functions/is-previewing.js";
@@ -107,8 +107,7 @@ function evalExpression(expression) {
107
107
  }));
108
108
  }
109
109
  function handleRequest({ url, key }) {
110
- getFetch()
111
- .then((fetch) => fetch(url))
110
+ fetch(url)
112
111
  .then((response) => response.json())
113
112
  .then((json) => {
114
113
  const newOverrideState = {
@@ -0,0 +1,2 @@
1
+ import type { GetContentOptions } from './types.js';
2
+ export declare const generateContentUrl: (options: GetContentOptions) => URL;
@@ -0,0 +1,27 @@
1
+ import { flatten } from '../../helpers/flatten.js';
2
+ import { getBuilderSearchParamsFromWindow, normalizeSearchParams, } from '../get-builder-search-params/index.js';
3
+ export const generateContentUrl = (options) => {
4
+ const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, locale, } = options;
5
+ if (!apiKey) {
6
+ throw new Error('Missing API key');
7
+ }
8
+ const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ''}`);
9
+ const queryOptions = {
10
+ ...getBuilderSearchParamsFromWindow(),
11
+ ...normalizeSearchParams(options.options || {}),
12
+ };
13
+ const flattened = flatten(queryOptions);
14
+ for (const key in flattened) {
15
+ url.searchParams.set(key, String(flattened[key]));
16
+ }
17
+ if (userAttributes) {
18
+ url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
19
+ }
20
+ if (query) {
21
+ const flattened = flatten({ query });
22
+ for (const key in flattened) {
23
+ url.searchParams.set(key, JSON.stringify(flattened[key]));
24
+ }
25
+ }
26
+ return url;
27
+ };
@@ -1,4 +1,4 @@
1
- import { generateContentUrl } from '.';
1
+ import { generateContentUrl } from './generate-content-url';
2
2
  const testKey = 'YJIGb4i01jvw0SRdL5Bt';
3
3
  const testModel = 'page';
4
4
  const testId = 'c1b81bab59704599b997574eb0736def';
@@ -1,7 +1,6 @@
1
1
  import type { BuilderContent } from '../../types/builder-content.js';
2
- export declare type GetContentOptions = import('./types.js').GetContentOptions;
2
+ import type { GetContentOptions } from './types.js';
3
3
  export declare function getContent(options: GetContentOptions): Promise<BuilderContent | null>;
4
- export declare const generateContentUrl: (options: GetContentOptions) => URL;
5
4
  /**
6
5
  * TO-DO: Handle error responses.
7
6
  */
@@ -1,39 +1,13 @@
1
- import { flatten } from '../../helpers/flatten.js';
2
- import { getBuilderSearchParamsFromWindow, normalizeSearchParams, } from '../get-builder-search-params/index.js';
3
- import { getFetch } from '../get-fetch.js';
1
+ import { fetch } from '../get-fetch.js';
4
2
  import { handleABTesting } from './ab-testing.js';
3
+ import { generateContentUrl } from './generate-content-url.js';
5
4
  export async function getContent(options) {
6
5
  return (await getAllContent({ ...options, limit: 1 })).results[0] || null;
7
6
  }
8
- export const generateContentUrl = (options) => {
9
- const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, locale, } = options;
10
- if (!apiKey) {
11
- throw new Error('Missing API key');
12
- }
13
- const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ''}`);
14
- const queryOptions = {
15
- ...getBuilderSearchParamsFromWindow(),
16
- ...normalizeSearchParams(options.options || {}),
17
- };
18
- const flattened = flatten(queryOptions);
19
- for (const key in flattened) {
20
- url.searchParams.set(key, String(flattened[key]));
21
- }
22
- if (userAttributes) {
23
- url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
24
- }
25
- if (query) {
26
- const flattened = flatten({ query });
27
- for (const key in flattened) {
28
- url.searchParams.set(key, JSON.stringify(flattened[key]));
29
- }
30
- }
31
- return url;
32
- };
33
7
  export async function getAllContent(options) {
34
8
  const url = generateContentUrl(options);
35
- const fetch = await getFetch();
36
- const content = await fetch(url.href).then((res) => res.json());
9
+ const res = await fetch(url.href);
10
+ const content = await res.json();
37
11
  const canTrack = options.canTrack !== false;
38
12
  if (canTrack &&
39
13
  // This makes sure we have a non-error response with the results array.
@@ -1 +1 @@
1
- export declare function getFetch(): Promise<typeof global.fetch>;
1
+ export declare const fetch: typeof globalThis.fetch;
@@ -1,9 +1,11 @@
1
1
  import { getGlobalThis } from './get-global-this.js';
2
- export async function getFetch() {
2
+ function getFetch() {
3
3
  const globalFetch = getGlobalThis().fetch;
4
- if (typeof globalFetch === 'undefined' && typeof global !== 'undefined') {
5
- const nodeFetch = import('node-fetch').then((d) => d.default);
6
- return nodeFetch.default || nodeFetch;
4
+ if (typeof globalFetch === 'undefined') {
5
+ console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
6
+ For more information, read https://github.com/BuilderIO/this-package-uses-fetch`);
7
+ throw new Error('Builder SDK could not find a global `fetch` function');
7
8
  }
8
- return globalFetch.default || globalFetch;
9
+ return globalFetch;
9
10
  }
11
+ export const fetch = getFetch();
@@ -1 +1,2 @@
1
- export declare function getGlobalThis(): any;
1
+ /// <reference types="@types/node" />
2
+ export declare function getGlobalThis(): typeof global;
@@ -11,5 +11,5 @@ export function getGlobalThis() {
11
11
  if (typeof self !== 'undefined') {
12
12
  return self;
13
13
  }
14
- return null;
14
+ return globalThis;
15
15
  }
@@ -1,6 +1,7 @@
1
1
  import type { BuilderContextInterface } from '../context/types.js';
2
2
  import type { BuilderBlock } from '../types/builder-block.js';
3
- export declare function getReactNativeBlockStyles({ block, context, }: {
3
+ export declare function getReactNativeBlockStyles({ block, context, blockStyles, }: {
4
4
  block: BuilderBlock;
5
5
  context: BuilderContextInterface;
6
+ blockStyles: any;
6
7
  }): CSSStyleDeclaration | Record<string, string | undefined>;
@@ -1,5 +1,5 @@
1
1
  import { sanitizeReactNativeBlockStyles } from './sanitize-react-native-block-styles.js';
2
- export function getReactNativeBlockStyles({ block, context, }) {
2
+ export function getReactNativeBlockStyles({ block, context, blockStyles, }) {
3
3
  const responsiveStyles = block.responsiveStyles;
4
4
  if (!responsiveStyles) {
5
5
  return {};
@@ -10,6 +10,7 @@ export function getReactNativeBlockStyles({ block, context, }) {
10
10
  ...(responsiveStyles.large || {}),
11
11
  ...(responsiveStyles.medium || {}),
12
12
  ...(responsiveStyles.small || {}),
13
+ ...blockStyles,
13
14
  };
14
15
  const newStyles = sanitizeReactNativeBlockStyles(styles);
15
16
  return newStyles;
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": "0.0.10-0",
4
+ "version": "0.0.11-0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "package",
@@ -46,8 +46,5 @@
46
46
  "tslib": "^2.3.1",
47
47
  "typescript": "^4",
48
48
  "vite": "^3.0.4"
49
- },
50
- "dependencies": {
51
- "node-fetch": "^2.6.1"
52
49
  }
53
50
  }
@@ -30,6 +30,7 @@
30
30
  import RenderContent from "../../components/render-content/render-content.svelte";
31
31
  import BuilderContext from "../../context/builder.context.js";
32
32
  import { getContent } from "../../functions/get-content/index.js";
33
+ import { TARGET } from "../../constants/target";
33
34
 
34
35
  const isEvent = (attr) => attr.startsWith("on:");
35
36
  const isNonEvent = (attr) => !attr.startsWith("on:");
@@ -65,16 +66,28 @@
65
66
  };
66
67
  };
67
68
 
68
- export let symbol: SymbolProps["symbol"];
69
69
  export let attributes: SymbolProps["attributes"];
70
+ export let symbol: SymbolProps["symbol"];
71
+ export let dynamic: SymbolProps["dynamic"];
70
72
 
71
73
  let builderContext = getContext(BuilderContext.key);
72
74
 
75
+ $: className = () => {
76
+ return [
77
+ ...(TARGET === "vue2" || TARGET === "vue3"
78
+ ? Object.keys(attributes.class)
79
+ : [attributes.class]),
80
+ "builder-symbol",
81
+ symbol?.inline ? "builder-inline-symbol" : undefined,
82
+ symbol?.dynamic || dynamic ? "builder-dynamic-symbol" : undefined,
83
+ ]
84
+ .filter(Boolean)
85
+ .join(" ");
86
+ };
73
87
  $: contentToUse = () => {
74
88
  return symbol?.content || fetchedContent;
75
89
  };
76
90
 
77
- let className = "builder-symbol";
78
91
  let fetchedContent = null;
79
92
 
80
93
  function onUpdateFn_0() {
@@ -112,9 +125,9 @@
112
125
  <div
113
126
  {...filterAttrs(attributes, isNonEvent)}
114
127
  dataSet={{
115
- class: className,
128
+ class: className(),
116
129
  }}
117
- class={className}
130
+ class={className()}
118
131
  use:setAttrs={filterAttrs(attributes, isEvent)}
119
132
  >
120
133
  <RenderContent
@@ -100,13 +100,15 @@
100
100
  });
101
101
  };
102
102
  $: attributes = () => {
103
+ const blockProperties = getBlockProperties(useBlock());
103
104
  return {
104
- ...getBlockProperties(useBlock()),
105
+ ...blockProperties,
105
106
  ...(TARGET === "reactNative"
106
107
  ? {
107
108
  style: getReactNativeBlockStyles({
108
109
  block: useBlock(),
109
110
  context: context,
111
+ blockStyles: blockProperties.style,
110
112
  }),
111
113
  }
112
114
  : {}),
@@ -198,6 +200,7 @@
198
200
  const styles = getReactNativeBlockStyles({
199
201
  block: useBlock(),
200
202
  context: context,
203
+ blockStyles: attributes().style,
201
204
  });
202
205
  return extractTextStyles(styles);
203
206
  };
@@ -53,7 +53,7 @@
53
53
  import { TARGET } from "../../constants/target.js";
54
54
  import { evaluate } from "../../functions/evaluate.js";
55
55
  import { getContent } from "../../functions/get-content/index.js";
56
- import { getFetch } from "../../functions/get-fetch.js";
56
+ import { fetch } from "../../functions/get-fetch.js";
57
57
  import { isBrowser } from "../../functions/is-browser.js";
58
58
  import { isEditing } from "../../functions/is-editing.js";
59
59
  import { isPreviewing } from "../../functions/is-previewing.js";
@@ -168,8 +168,7 @@
168
168
  );
169
169
  }
170
170
  function handleRequest({ url, key }) {
171
- getFetch()
172
- .then((fetch) => fetch(url))
171
+ fetch(url)
173
172
  .then((response) => response.json())
174
173
  .then((json) => {
175
174
  const newOverrideState = {
@@ -1,4 +1,4 @@
1
- import { generateContentUrl } from '.';
1
+ import { generateContentUrl } from './generate-content-url';
2
2
 
3
3
  const testKey = 'YJIGb4i01jvw0SRdL5Bt';
4
4
  const testModel = 'page';
@@ -0,0 +1,51 @@
1
+ import { flatten } from '../../helpers/flatten.js';
2
+ import {
3
+ getBuilderSearchParamsFromWindow,
4
+ normalizeSearchParams,
5
+ } from '../get-builder-search-params/index.js';
6
+ import type { GetContentOptions } from './types.js';
7
+
8
+ export const generateContentUrl = (options: GetContentOptions): URL => {
9
+ const {
10
+ limit = 30,
11
+ userAttributes,
12
+ query,
13
+ noTraverse = false,
14
+ model,
15
+ apiKey,
16
+ includeRefs = true,
17
+ locale,
18
+ } = options;
19
+
20
+ if (!apiKey) {
21
+ throw new Error('Missing API key');
22
+ }
23
+
24
+ const url = new URL(
25
+ `https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${
26
+ locale ? `&locale=${locale}` : ''
27
+ }`
28
+ );
29
+
30
+ const queryOptions = {
31
+ ...getBuilderSearchParamsFromWindow(),
32
+ ...normalizeSearchParams(options.options || {}),
33
+ };
34
+
35
+ const flattened = flatten(queryOptions);
36
+ for (const key in flattened) {
37
+ url.searchParams.set(key, String(flattened[key]));
38
+ }
39
+
40
+ if (userAttributes) {
41
+ url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
42
+ }
43
+ if (query) {
44
+ const flattened = flatten({ query });
45
+ for (const key in flattened) {
46
+ url.searchParams.set(key, JSON.stringify((flattened as any)[key]));
47
+ }
48
+ }
49
+
50
+ return url;
51
+ };
@@ -1,13 +1,8 @@
1
- import { flatten } from '../../helpers/flatten.js';
2
1
  import type { BuilderContent } from '../../types/builder-content.js';
3
- import {
4
- getBuilderSearchParamsFromWindow,
5
- normalizeSearchParams,
6
- } from '../get-builder-search-params/index.js';
7
- import { getFetch } from '../get-fetch.js';
2
+ import { fetch } from '../get-fetch.js';
8
3
  import { handleABTesting } from './ab-testing.js';
9
-
10
- export type GetContentOptions = import('./types.js').GetContentOptions;
4
+ import { generateContentUrl } from './generate-content-url.js';
5
+ import type { GetContentOptions } from './types.js';
11
6
 
12
7
  export async function getContent(
13
8
  options: GetContentOptions
@@ -15,51 +10,6 @@ export async function getContent(
15
10
  return (await getAllContent({ ...options, limit: 1 })).results[0] || null;
16
11
  }
17
12
 
18
- export const generateContentUrl = (options: GetContentOptions): URL => {
19
- const {
20
- limit = 30,
21
- userAttributes,
22
- query,
23
- noTraverse = false,
24
- model,
25
- apiKey,
26
- includeRefs = true,
27
- locale,
28
- } = options;
29
-
30
- if (!apiKey) {
31
- throw new Error('Missing API key');
32
- }
33
-
34
- const url = new URL(
35
- `https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${
36
- locale ? `&locale=${locale}` : ''
37
- }`
38
- );
39
-
40
- const queryOptions = {
41
- ...getBuilderSearchParamsFromWindow(),
42
- ...normalizeSearchParams(options.options || {}),
43
- };
44
-
45
- const flattened = flatten(queryOptions);
46
- for (const key in flattened) {
47
- url.searchParams.set(key, String(flattened[key]));
48
- }
49
-
50
- if (userAttributes) {
51
- url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
52
- }
53
- if (query) {
54
- const flattened = flatten({ query });
55
- for (const key in flattened) {
56
- url.searchParams.set(key, JSON.stringify((flattened as any)[key]));
57
- }
58
- }
59
-
60
- return url;
61
- };
62
-
63
13
  /**
64
14
  * TO-DO: Handle error responses.
65
15
  */
@@ -72,10 +22,8 @@ export async function getAllContent(
72
22
  ): Promise<ContentResponse> {
73
23
  const url = generateContentUrl(options);
74
24
 
75
- const fetch = await getFetch();
76
- const content: ContentResponse = await fetch(url.href).then((res) =>
77
- res.json()
78
- );
25
+ const res = await fetch(url.href);
26
+ const content = await (res.json() as Promise<ContentResponse>);
79
27
 
80
28
  const canTrack = options.canTrack !== false;
81
29
  if (
@@ -1,14 +1,18 @@
1
1
  import { getGlobalThis } from './get-global-this.js';
2
2
 
3
- export async function getFetch(): Promise<typeof global.fetch> {
3
+ function getFetch(): typeof global.fetch {
4
4
  const globalFetch: typeof global.fetch = getGlobalThis().fetch;
5
5
 
6
- if (typeof globalFetch === 'undefined' && typeof global !== 'undefined') {
7
- const nodeFetch = import('node-fetch').then((d) => d.default) as Promise<
8
- typeof global.fetch
9
- >;
10
- return (nodeFetch as any).default || nodeFetch;
6
+ if (typeof globalFetch === 'undefined') {
7
+ console.warn(
8
+ `Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
9
+ For more information, read https://github.com/BuilderIO/this-package-uses-fetch`
10
+ );
11
+
12
+ throw new Error('Builder SDK could not find a global `fetch` function');
11
13
  }
12
14
 
13
- return (globalFetch as any).default || globalFetch;
15
+ return globalFetch;
14
16
  }
17
+
18
+ export const fetch = getFetch();
@@ -1,4 +1,4 @@
1
- export function getGlobalThis(): any {
1
+ export function getGlobalThis(): typeof global {
2
2
  if (typeof globalThis !== 'undefined') {
3
3
  return globalThis;
4
4
  }
@@ -11,5 +11,5 @@ export function getGlobalThis(): any {
11
11
  if (typeof self !== 'undefined') {
12
12
  return self;
13
13
  }
14
- return null;
14
+ return globalThis;
15
15
  }
@@ -5,9 +5,11 @@ import { sanitizeReactNativeBlockStyles } from './sanitize-react-native-block-st
5
5
  export function getReactNativeBlockStyles({
6
6
  block,
7
7
  context,
8
+ blockStyles,
8
9
  }: {
9
10
  block: BuilderBlock;
10
11
  context: BuilderContextInterface;
12
+ blockStyles: any;
11
13
  }): CSSStyleDeclaration | Record<string, string | undefined> {
12
14
  const responsiveStyles = block.responsiveStyles;
13
15
  if (!responsiveStyles) {
@@ -20,6 +22,7 @@ export function getReactNativeBlockStyles({
20
22
  ...(responsiveStyles.large || {}),
21
23
  ...(responsiveStyles.medium || {}),
22
24
  ...(responsiveStyles.small || {}),
25
+ ...blockStyles,
23
26
  } as Record<string, string | number>;
24
27
 
25
28
  const newStyles = sanitizeReactNativeBlockStyles(