@builder.io/sdk-solid 0.1.15 → 0.2.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.
- package/CHANGELOG.md +13 -0
- package/package.json +1 -1
- package/src/blocks/button/button.jsx +10 -3
- package/src/blocks/image/image.jsx +1 -3
- package/src/components/render-block/render-block.jsx +1 -0
- package/src/components/render-content/render-content.jsx +1 -1
- package/src/functions/get-content/generate-content-url.js +2 -1
- package/src/functions/get-content/generate-content-url.test.js +9 -0
- package/src/functions/get-content/index.js +16 -4
- package/src/types/api-version.js +4 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
### 0.2.0
|
|
2
|
+
- Sets the default `apiVersion` to `v3`.
|
|
3
|
+
|
|
4
|
+
In case you feel the need to use our older API Version `v2`, reach out to us at support@builder.io first. But you can override the default by setting `apiVersion` explicitly to `v2` as follows:
|
|
5
|
+
|
|
6
|
+
```jsx
|
|
7
|
+
<RenderContent apiVersion="v2" />
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```js
|
|
11
|
+
getContent({ apiVersion: "v2" })
|
|
12
|
+
```
|
|
13
|
+
More details on the Builder API Versions visit [this link](https://www.builder.io/c/docs/content-api-versions).
|
package/package.json
CHANGED
|
@@ -7,9 +7,16 @@ function Button(props) {
|
|
|
7
7
|
<Show
|
|
8
8
|
fallback={
|
|
9
9
|
<button
|
|
10
|
-
class={
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
class={
|
|
11
|
+
/**
|
|
12
|
+
* We have to explicitly provide `class` so that Mitosis knows to merge it with `css`.
|
|
13
|
+
*/
|
|
14
|
+
props.attributes.class +
|
|
15
|
+
" " +
|
|
16
|
+
css({
|
|
17
|
+
all: "unset",
|
|
18
|
+
})
|
|
19
|
+
}
|
|
13
20
|
{...props.attributes}
|
|
14
21
|
>
|
|
15
22
|
{props.text}
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
getBuilderSearchParamsFromWindow,
|
|
20
20
|
normalizeSearchParams
|
|
21
21
|
} from "../get-builder-search-params/index.js";
|
|
22
|
+
import { DEFAULT_API_VERSION } from "../../types/api-version";
|
|
22
23
|
const generateContentUrl = (options) => {
|
|
23
24
|
const {
|
|
24
25
|
limit = 30,
|
|
@@ -29,7 +30,7 @@ const generateContentUrl = (options) => {
|
|
|
29
30
|
apiKey,
|
|
30
31
|
includeRefs = true,
|
|
31
32
|
locale,
|
|
32
|
-
apiVersion =
|
|
33
|
+
apiVersion = DEFAULT_API_VERSION
|
|
33
34
|
} = options;
|
|
34
35
|
if (!apiKey) {
|
|
35
36
|
throw new Error("Missing API key");
|
|
@@ -28,6 +28,15 @@ describe("Generate Content URL", () => {
|
|
|
28
28
|
});
|
|
29
29
|
expect(output).toMatchSnapshot();
|
|
30
30
|
});
|
|
31
|
+
test("generate content url with apiVersion as default", () => {
|
|
32
|
+
const output = generateContentUrl({
|
|
33
|
+
apiKey: testKey,
|
|
34
|
+
model: testModel,
|
|
35
|
+
query: { id: testId },
|
|
36
|
+
options
|
|
37
|
+
});
|
|
38
|
+
expect(output).toMatchSnapshot();
|
|
39
|
+
});
|
|
31
40
|
test("generate content url with apiVersion as v2", () => {
|
|
32
41
|
const output = generateContentUrl({
|
|
33
42
|
apiKey: testKey,
|
|
@@ -42,7 +42,11 @@ import { handleABTesting } from "./ab-testing.js";
|
|
|
42
42
|
import { generateContentUrl } from "./generate-content-url.js";
|
|
43
43
|
function getContent(options) {
|
|
44
44
|
return __async(this, null, function* () {
|
|
45
|
-
|
|
45
|
+
const allContent = yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }));
|
|
46
|
+
if ("results" in allContent) {
|
|
47
|
+
return (allContent == null ? void 0 : allContent.results[0]) || null;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
46
50
|
});
|
|
47
51
|
}
|
|
48
52
|
function getAllContent(options) {
|
|
@@ -50,11 +54,19 @@ function getAllContent(options) {
|
|
|
50
54
|
const url = generateContentUrl(options);
|
|
51
55
|
const res = yield fetch(url.href);
|
|
52
56
|
const content = yield res.json();
|
|
57
|
+
if ("status" in content && !("results" in content)) {
|
|
58
|
+
console.error("[Builder.io]: Error fetching data. ", content, options);
|
|
59
|
+
return content;
|
|
60
|
+
}
|
|
53
61
|
const canTrack = options.canTrack !== false;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
try {
|
|
63
|
+
if (canTrack && Array.isArray(content.results)) {
|
|
64
|
+
for (const item of content.results) {
|
|
65
|
+
yield handleABTesting({ item, canTrack });
|
|
66
|
+
}
|
|
57
67
|
}
|
|
68
|
+
} catch (e) {
|
|
69
|
+
console.error("[Builder.io]: Could not setup A/B testing. ", e);
|
|
58
70
|
}
|
|
59
71
|
return content;
|
|
60
72
|
});
|
package/src/types/api-version.js
CHANGED