@builder.io/sdk-svelte 0.0.9-1 → 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.
@@ -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-0",
4
+ "version": "0.0.9-2",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "package",
@@ -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.replace(BUILDER_SEARCHPARAMS_PREFIX, '');
19
+ const trimmedKey = key
20
+ .replace(BUILDER_SEARCHPARAMS_PREFIX, '')
21
+ .replace(BUILDER_OPTIONS_PREFIX, '');
19
22
  newOptions[trimmedKey] = options[key];
20
23
  }
21
24
  });
@@ -3,14 +3,14 @@ import { getBuilderSearchParamsFromWindow, normalizeSearchParams, } from '../get
3
3
  import { getFetch } from '../get-fetch.js';
4
4
  import { handleABTesting } from './ab-testing.js';
5
5
  export async function getContent(options) {
6
- return (await getAllContent({ ...options, single: true })) || null;
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, } = 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
  }
13
- const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}`);
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
14
  const queryOptions = {
15
15
  ...getBuilderSearchParamsFromWindow(),
16
16
  ...normalizeSearchParams(options.options || {}),
@@ -32,10 +32,6 @@ export interface GetContentOptions {
32
32
  * Include references in the response. Defaults to `true`.
33
33
  */
34
34
  includeRefs?: boolean;
35
- /**
36
- * Returns a single content match
37
- */
38
- single?: boolean;
39
35
  /**
40
36
  * If passed , the API will aut-resolve localized objects to the value of this locale key
41
37
  */
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.9-1",
4
+ "version": "0.0.9-3",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "package",
@@ -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.replace(BUILDER_SEARCHPARAMS_PREFIX, '');
28
+ const trimmedKey = key
29
+ .replace(BUILDER_SEARCHPARAMS_PREFIX, '')
30
+ .replace(BUILDER_OPTIONS_PREFIX, '');
29
31
  newOptions[trimmedKey] = options[key];
30
32
  }
31
33
  });
@@ -12,7 +12,7 @@ export type GetContentOptions = import('./types.js').GetContentOptions;
12
12
  export async function getContent(
13
13
  options: GetContentOptions
14
14
  ): Promise<BuilderContent | null> {
15
- return (await getAllContent({ ...options, single: true })) || null;
15
+ return (await getAllContent({ ...options, limit: 1 })).results[0] || null;
16
16
  }
17
17
 
18
18
  export const generateContentUrl = (options: GetContentOptions): URL => {
@@ -24,6 +24,7 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
24
24
  model,
25
25
  apiKey,
26
26
  includeRefs = true,
27
+ locale,
27
28
  } = options;
28
29
 
29
30
  if (!apiKey) {
@@ -31,7 +32,9 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
31
32
  }
32
33
 
33
34
  const url = new URL(
34
- `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
+ }`
35
38
  );
36
39
 
37
40
  const queryOptions = {
@@ -39,11 +39,6 @@ export interface GetContentOptions {
39
39
  */
40
40
  includeRefs?: boolean;
41
41
 
42
- /**
43
- * Returns a single content match
44
- */
45
- single?: boolean;
46
-
47
42
  /**
48
43
  * If passed , the API will aut-resolve localized objects to the value of this locale key
49
44
  */