@builder.io/sdk-svelte 0.0.9-2 → 0.0.9-3
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/package/--package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { isBrowser } from '../is-browser.js';
|
|
2
2
|
const BUILDER_SEARCHPARAMS_PREFIX = 'builder.';
|
|
3
|
+
const BUILDER_OPTIONS_PREFIX = 'options.';
|
|
3
4
|
export const convertSearchParamsToQueryObject = (searchParams) => {
|
|
4
5
|
const options = {};
|
|
5
6
|
searchParams.forEach((value, key) => {
|
|
6
|
-
options[key] = value;
|
|
7
|
+
options[key.replace('options.', '')] = value;
|
|
7
8
|
});
|
|
8
9
|
return options;
|
|
9
10
|
};
|
|
@@ -15,7 +16,9 @@ export const getBuilderSearchParams = (_options) => {
|
|
|
15
16
|
const newOptions = {};
|
|
16
17
|
Object.keys(options).forEach((key) => {
|
|
17
18
|
if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
|
|
18
|
-
const trimmedKey = key
|
|
19
|
+
const trimmedKey = key
|
|
20
|
+
.replace(BUILDER_SEARCHPARAMS_PREFIX, '')
|
|
21
|
+
.replace(BUILDER_OPTIONS_PREFIX, '');
|
|
19
22
|
newOptions[trimmedKey] = options[key];
|
|
20
23
|
}
|
|
21
24
|
});
|
|
@@ -6,7 +6,7 @@ export async function getContent(options) {
|
|
|
6
6
|
return (await getAllContent({ ...options, limit: 1 })).results[0] || null;
|
|
7
7
|
}
|
|
8
8
|
export const generateContentUrl = (options) => {
|
|
9
|
-
const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, locale } = options;
|
|
9
|
+
const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, locale, } = options;
|
|
10
10
|
if (!apiKey) {
|
|
11
11
|
throw new Error('Missing API key');
|
|
12
12
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isBrowser } from '../is-browser.js';
|
|
2
2
|
|
|
3
3
|
const BUILDER_SEARCHPARAMS_PREFIX = 'builder.';
|
|
4
|
-
|
|
4
|
+
const BUILDER_OPTIONS_PREFIX = 'options.';
|
|
5
5
|
type QueryObject = Record<string, string | string[]>;
|
|
6
6
|
|
|
7
7
|
export const convertSearchParamsToQueryObject = (
|
|
@@ -9,7 +9,7 @@ export const convertSearchParamsToQueryObject = (
|
|
|
9
9
|
): QueryObject => {
|
|
10
10
|
const options: Record<string, string> = {};
|
|
11
11
|
searchParams.forEach((value, key) => {
|
|
12
|
-
options[key] = value;
|
|
12
|
+
options[key.replace('options.', '')] = value;
|
|
13
13
|
});
|
|
14
14
|
return options;
|
|
15
15
|
};
|
|
@@ -25,7 +25,9 @@ export const getBuilderSearchParams = (
|
|
|
25
25
|
const newOptions: QueryObject = {};
|
|
26
26
|
Object.keys(options).forEach((key) => {
|
|
27
27
|
if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
|
|
28
|
-
const trimmedKey = key
|
|
28
|
+
const trimmedKey = key
|
|
29
|
+
.replace(BUILDER_SEARCHPARAMS_PREFIX, '')
|
|
30
|
+
.replace(BUILDER_OPTIONS_PREFIX, '');
|
|
29
31
|
newOptions[trimmedKey] = options[key];
|
|
30
32
|
}
|
|
31
33
|
});
|
|
@@ -24,7 +24,7 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
|
|
|
24
24
|
model,
|
|
25
25
|
apiKey,
|
|
26
26
|
includeRefs = true,
|
|
27
|
-
locale
|
|
27
|
+
locale,
|
|
28
28
|
} = options;
|
|
29
29
|
|
|
30
30
|
if (!apiKey) {
|
|
@@ -32,7 +32,9 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const url = new URL(
|
|
35
|
-
`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${
|
|
35
|
+
`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${
|
|
36
|
+
locale ? `&locale=${locale}` : ''
|
|
37
|
+
}`
|
|
36
38
|
);
|
|
37
39
|
|
|
38
40
|
const queryOptions = {
|