@builder.io/sdk-solid 0.0.23 → 0.1.1

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.
package/README.md CHANGED
@@ -5,3 +5,7 @@ More info coming soon.
5
5
  ## Mitosis
6
6
 
7
7
  This SDK is generated by [Mitosis](https://github.com/BuilderIO/mitosis). To see the Mitosis source-code, go [here](../../).
8
+
9
+ ## Fetch
10
+
11
+ This Package uses fetch. See [these docs](https://github.com/BuilderIO/this-package-uses-fetch/blob/main/README.md) for more information.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-solid",
3
- "version": "0.0.23",
3
+ "version": "0.1.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./solid-index.jsx",
@@ -10,11 +10,11 @@
10
10
  },
11
11
  "scripts": {
12
12
  "build": "echo 'no need to build solid SDK'",
13
- "release:patch": "npm version patch --no-git-tag-version && npm publish --access public",
14
- "release:dev": "npm version prerelease --no-git-tag-version && npm publish --tag dev --access public"
13
+ "release:patch": "yarn run build && npm version patch && npm publish",
14
+ "release:minor": "yarn run build && npm version minor && npm publish",
15
+ "release:dev": "yarn run build && npm version prerelease && npm publish --tag dev"
15
16
  },
16
17
  "dependencies": {
17
- "node-fetch": "^2.6.7",
18
18
  "solid-styled-components": "^0.27.6"
19
19
  },
20
20
  "peerDependencies": {
@@ -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";
@@ -129,7 +129,7 @@ function RenderContent(props) {
129
129
  url,
130
130
  key
131
131
  }) {
132
- getFetch().then(fetch => fetch(url)).then(response => response.json()).then(json => {
132
+ fetch(url).then(response => response.json()).then(json => {
133
133
  const newOverrideState = {
134
134
  ...overrideState(),
135
135
  [key]: json
@@ -0,0 +1,55 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ import { flatten } from "../../helpers/flatten.js";
18
+ import {
19
+ getBuilderSearchParamsFromWindow,
20
+ normalizeSearchParams
21
+ } from "../get-builder-search-params/index.js";
22
+ const generateContentUrl = (options) => {
23
+ const {
24
+ limit = 30,
25
+ userAttributes,
26
+ query,
27
+ noTraverse = false,
28
+ model,
29
+ apiKey,
30
+ includeRefs = true,
31
+ locale
32
+ } = options;
33
+ if (!apiKey) {
34
+ throw new Error("Missing API key");
35
+ }
36
+ const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}`);
37
+ const queryOptions = __spreadValues(__spreadValues({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
38
+ const flattened = flatten(queryOptions);
39
+ for (const key in flattened) {
40
+ url.searchParams.set(key, String(flattened[key]));
41
+ }
42
+ if (userAttributes) {
43
+ url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
44
+ }
45
+ if (query) {
46
+ const flattened2 = flatten({ query });
47
+ for (const key in flattened2) {
48
+ url.searchParams.set(key, JSON.stringify(flattened2[key]));
49
+ }
50
+ }
51
+ return url;
52
+ };
53
+ export {
54
+ generateContentUrl
55
+ };
@@ -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";
@@ -37,54 +37,19 @@ var __async = (__this, __arguments, generator) => {
37
37
  step((generator = generator.apply(__this, __arguments)).next());
38
38
  });
39
39
  };
40
- import { flatten } from "../../helpers/flatten.js";
41
- import {
42
- getBuilderSearchParamsFromWindow,
43
- normalizeSearchParams
44
- } from "../get-builder-search-params/index.js";
45
- import { getFetch } from "../get-fetch.js";
40
+ import { fetch } from "../get-fetch.js";
46
41
  import { handleABTesting } from "./ab-testing.js";
42
+ import { generateContentUrl } from "./generate-content-url.js";
47
43
  function getContent(options) {
48
44
  return __async(this, null, function* () {
49
45
  return (yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }))).results[0] || null;
50
46
  });
51
47
  }
52
- const generateContentUrl = (options) => {
53
- const {
54
- limit = 30,
55
- userAttributes,
56
- query,
57
- noTraverse = false,
58
- model,
59
- apiKey,
60
- includeRefs = true,
61
- locale
62
- } = options;
63
- if (!apiKey) {
64
- throw new Error("Missing API key");
65
- }
66
- const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}`);
67
- const queryOptions = __spreadValues(__spreadValues({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
68
- const flattened = flatten(queryOptions);
69
- for (const key in flattened) {
70
- url.searchParams.set(key, String(flattened[key]));
71
- }
72
- if (userAttributes) {
73
- url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
74
- }
75
- if (query) {
76
- const flattened2 = flatten({ query });
77
- for (const key in flattened2) {
78
- url.searchParams.set(key, JSON.stringify(flattened2[key]));
79
- }
80
- }
81
- return url;
82
- };
83
48
  function getAllContent(options) {
84
49
  return __async(this, null, function* () {
85
50
  const url = generateContentUrl(options);
86
- const fetch = yield getFetch();
87
- const content = yield fetch(url.href).then((res) => res.json());
51
+ const res = yield fetch(url.href);
52
+ const content = yield res.json();
88
53
  const canTrack = options.canTrack !== false;
89
54
  if (canTrack && Array.isArray(content.results)) {
90
55
  for (const item of content.results) {
@@ -95,7 +60,6 @@ function getAllContent(options) {
95
60
  });
96
61
  }
97
62
  export {
98
- generateContentUrl,
99
63
  getAllContent,
100
64
  getContent
101
65
  };
@@ -1,34 +1,14 @@
1
- var __async = (__this, __arguments, generator) => {
2
- return new Promise((resolve, reject) => {
3
- var fulfilled = (value) => {
4
- try {
5
- step(generator.next(value));
6
- } catch (e) {
7
- reject(e);
8
- }
9
- };
10
- var rejected = (value) => {
11
- try {
12
- step(generator.throw(value));
13
- } catch (e) {
14
- reject(e);
15
- }
16
- };
17
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
- step((generator = generator.apply(__this, __arguments)).next());
19
- });
20
- };
21
1
  import { getGlobalThis } from "./get-global-this.js";
22
2
  function getFetch() {
23
- return __async(this, null, function* () {
24
- const globalFetch = getGlobalThis().fetch;
25
- if (typeof globalFetch === "undefined" && typeof global !== "undefined") {
26
- const nodeFetch = import("node-fetch").then((d) => d.default);
27
- return nodeFetch.default || nodeFetch;
28
- }
29
- return globalFetch.default || globalFetch;
30
- });
3
+ const globalFetch = getGlobalThis().fetch;
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");
8
+ }
9
+ return globalFetch;
31
10
  }
11
+ const fetch = getFetch();
32
12
  export {
33
- getFetch
13
+ fetch
34
14
  };
@@ -11,7 +11,7 @@ function getGlobalThis() {
11
11
  if (typeof self !== "undefined") {
12
12
  return self;
13
13
  }
14
- return null;
14
+ return globalThis;
15
15
  }
16
16
  export {
17
17
  getGlobalThis