@builder.io/sdk-svelte 2.0.24 → 2.0.26
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/lib/browser/components/content/components/enable-editor.svelte +5 -1
- package/lib/browser/components/content/components/enable-editor.svelte.d.ts +3 -1
- package/lib/browser/components/content/content.svelte +4 -1
- package/lib/browser/components/content/content.svelte.d.ts +2 -1
- package/lib/browser/components/content-variants/content-variants.svelte +3 -0
- package/lib/browser/components/content-variants/content-variants.svelte.d.ts +1 -0
- package/lib/browser/components/content-variants/content-variants.types.d.ts +4 -0
- package/lib/browser/constants/sdk-version.d.ts +1 -1
- package/lib/browser/constants/sdk-version.js +1 -1
- package/lib/browser/functions/get-content/generate-content-url.js +3 -2
- package/lib/browser/functions/get-content/index.js +9 -1
- package/lib/browser/functions/get-content/types.d.ts +4 -0
- package/lib/browser/functions/track/index.d.ts +3 -1
- package/lib/browser/functions/track/index.js +6 -3
- package/lib/browser/helpers/sdk-headers.d.ts +5 -0
- package/lib/browser/helpers/sdk-headers.js +7 -0
- package/lib/edge/components/content/components/enable-editor.svelte +5 -1
- package/lib/edge/components/content/components/enable-editor.svelte.d.ts +3 -1
- package/lib/edge/components/content/content.svelte +4 -1
- package/lib/edge/components/content/content.svelte.d.ts +2 -1
- package/lib/edge/components/content-variants/content-variants.svelte +3 -0
- package/lib/edge/components/content-variants/content-variants.svelte.d.ts +1 -0
- package/lib/edge/components/content-variants/content-variants.types.d.ts +4 -0
- package/lib/edge/constants/sdk-version.d.ts +1 -1
- package/lib/edge/constants/sdk-version.js +1 -1
- package/lib/edge/functions/get-content/generate-content-url.js +3 -2
- package/lib/edge/functions/get-content/index.js +9 -1
- package/lib/edge/functions/get-content/types.d.ts +4 -0
- package/lib/edge/functions/track/index.d.ts +3 -1
- package/lib/edge/functions/track/index.js +6 -3
- package/lib/edge/helpers/sdk-headers.d.ts +5 -0
- package/lib/edge/helpers/sdk-headers.js +7 -0
- package/lib/node/components/content/components/enable-editor.svelte +5 -1
- package/lib/node/components/content/components/enable-editor.svelte.d.ts +3 -1
- package/lib/node/components/content/content.svelte +4 -1
- package/lib/node/components/content/content.svelte.d.ts +2 -1
- package/lib/node/components/content-variants/content-variants.svelte +3 -0
- package/lib/node/components/content-variants/content-variants.svelte.d.ts +1 -0
- package/lib/node/components/content-variants/content-variants.types.d.ts +4 -0
- package/lib/node/constants/sdk-version.d.ts +1 -1
- package/lib/node/constants/sdk-version.js +1 -1
- package/lib/node/functions/get-content/generate-content-url.js +3 -2
- package/lib/node/functions/get-content/index.js +9 -1
- package/lib/node/functions/get-content/types.d.ts +4 -0
- package/lib/node/functions/track/index.d.ts +3 -1
- package/lib/node/functions/track/index.js +6 -3
- package/lib/node/helpers/sdk-headers.d.ts +5 -0
- package/lib/node/helpers/sdk-headers.js +7 -0
- package/package.json +1 -1
- package/src/components/content/components/enable-editor.svelte +5 -2
- package/src/components/content/content.svelte +4 -1
- package/src/components/content-variants/content-variants.svelte +3 -0
- package/src/components/content-variants/content-variants.types.ts +5 -0
- package/src/constants/sdk-version.ts +1 -1
- package/src/functions/get-content/generate-content-url.ts +4 -2
- package/src/functions/get-content/index.ts +9 -1
- package/src/functions/get-content/types.ts +5 -0
- package/src/functions/track/index.ts +11 -3
- package/src/helpers/sdk-headers.ts +7 -0
|
@@ -18,9 +18,11 @@ import { registerInsertMenu, setupBrowserForEditing, } from "../../../scripts/in
|
|
|
18
18
|
import { triggerAnimation } from "../../block/animator";
|
|
19
19
|
import "../../dynamic-div.svelte";
|
|
20
20
|
import { getWrapperClassName } from "./styles.helpers";
|
|
21
|
+
export let isNestedRender = undefined;
|
|
21
22
|
export let builderContextSignal;
|
|
22
23
|
export let canTrack = undefined;
|
|
23
24
|
export let apiKey;
|
|
25
|
+
export let apiHost = undefined;
|
|
24
26
|
export let locale = undefined;
|
|
25
27
|
export let enrich = undefined;
|
|
26
28
|
export let trustedHosts = undefined;
|
|
@@ -92,6 +94,7 @@ function onClick(event) {
|
|
|
92
94
|
const variationId = $builderContextSignal.content?.testVariationId;
|
|
93
95
|
const contentId = $builderContextSignal.content?.id;
|
|
94
96
|
_track({
|
|
97
|
+
apiHost: apiHost,
|
|
95
98
|
type: "click",
|
|
96
99
|
canTrack: getDefaultCanTrack(canTrack),
|
|
97
100
|
contentId,
|
|
@@ -223,7 +226,7 @@ runHttpRequests();
|
|
|
223
226
|
emitStateUpdate();
|
|
224
227
|
onMount(() => {
|
|
225
228
|
if (isBrowser()) {
|
|
226
|
-
if (isEditing()) {
|
|
229
|
+
if (isEditing() && !isNestedRender) {
|
|
227
230
|
if (elementRef) {
|
|
228
231
|
elementRef.dispatchEvent(new CustomEvent("initeditingbldr"));
|
|
229
232
|
}
|
|
@@ -234,6 +237,7 @@ onMount(() => {
|
|
|
234
237
|
const contentId = $builderContextSignal.content?.id;
|
|
235
238
|
const apiKeyProp = apiKey;
|
|
236
239
|
_track({
|
|
240
|
+
apiHost: apiHost,
|
|
237
241
|
type: "impression",
|
|
238
242
|
canTrack: true,
|
|
239
243
|
contentId,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
-
type BuilderEditorProps = Omit<ContentProps, "customComponents" | "apiVersion" | "isSsrAbTest" | "blocksWrapper" | "blocksWrapperProps" | "
|
|
2
|
+
type BuilderEditorProps = Omit<ContentProps, "customComponents" | "apiVersion" | "isSsrAbTest" | "blocksWrapper" | "blocksWrapperProps" | "linkComponent"> & {
|
|
3
3
|
builderContextSignal: Writable<BuilderContextInterface>;
|
|
4
4
|
setBuilderContextSignal?: (signal: any) => any;
|
|
5
5
|
children?: any;
|
|
@@ -9,9 +9,11 @@ import type { ContentProps } from "../content.types";
|
|
|
9
9
|
import type { Writable } from "svelte/store";
|
|
10
10
|
declare const __propDef: {
|
|
11
11
|
props: {
|
|
12
|
+
isNestedRender?: BuilderEditorProps["isNestedRender"];
|
|
12
13
|
builderContextSignal: BuilderEditorProps["builderContextSignal"];
|
|
13
14
|
canTrack?: BuilderEditorProps["canTrack"];
|
|
14
15
|
apiKey: BuilderEditorProps["apiKey"];
|
|
16
|
+
apiHost?: BuilderEditorProps["apiHost"];
|
|
15
17
|
locale?: BuilderEditorProps["locale"];
|
|
16
18
|
enrich?: BuilderEditorProps["enrich"];
|
|
17
19
|
trustedHosts?: BuilderEditorProps["trustedHosts"];
|
|
@@ -26,13 +26,14 @@ export let apiVersion = undefined;
|
|
|
26
26
|
export let blocksWrapper = undefined;
|
|
27
27
|
export let blocksWrapperProps = undefined;
|
|
28
28
|
export let nonce = undefined;
|
|
29
|
+
export let apiHost = undefined;
|
|
29
30
|
export let enrich = undefined;
|
|
30
31
|
export let showContent;
|
|
31
32
|
export let contentWrapper = undefined;
|
|
32
33
|
export let contentWrapperProps = undefined;
|
|
33
34
|
export let trustedHosts = undefined;
|
|
34
|
-
export let isSsrAbTest;
|
|
35
35
|
export let isNestedRender = undefined;
|
|
36
|
+
export let isSsrAbTest;
|
|
36
37
|
export let linkComponent = undefined;
|
|
37
38
|
function contentSetState(newRootState) {
|
|
38
39
|
$builderContextSignal.rootState = newRootState;
|
|
@@ -116,6 +117,7 @@ setContext(ComponentsContext.key, {
|
|
|
116
117
|
</script>
|
|
117
118
|
|
|
118
119
|
<EnableEditor
|
|
120
|
+
{apiHost}
|
|
119
121
|
{nonce}
|
|
120
122
|
{content}
|
|
121
123
|
{data}
|
|
@@ -130,6 +132,7 @@ setContext(ComponentsContext.key, {
|
|
|
130
132
|
{contentWrapper}
|
|
131
133
|
{contentWrapperProps}
|
|
132
134
|
{trustedHosts}
|
|
135
|
+
{isNestedRender}
|
|
133
136
|
{...{}}
|
|
134
137
|
>
|
|
135
138
|
{#if isSsrAbTest}
|
|
@@ -14,13 +14,14 @@ declare const __propDef: {
|
|
|
14
14
|
blocksWrapper?: ContentProps["blocksWrapper"];
|
|
15
15
|
blocksWrapperProps?: ContentProps["blocksWrapperProps"];
|
|
16
16
|
nonce?: ContentProps["nonce"];
|
|
17
|
+
apiHost?: ContentProps["apiHost"];
|
|
17
18
|
enrich?: ContentProps["enrich"];
|
|
18
19
|
showContent: ContentProps["showContent"];
|
|
19
20
|
contentWrapper?: ContentProps["contentWrapper"];
|
|
20
21
|
contentWrapperProps?: ContentProps["contentWrapperProps"];
|
|
21
22
|
trustedHosts?: ContentProps["trustedHosts"];
|
|
22
|
-
isSsrAbTest: ContentProps["isSsrAbTest"];
|
|
23
23
|
isNestedRender?: ContentProps["isNestedRender"];
|
|
24
|
+
isSsrAbTest: ContentProps["isSsrAbTest"];
|
|
24
25
|
linkComponent?: ContentProps["linkComponent"];
|
|
25
26
|
};
|
|
26
27
|
events: {
|
|
@@ -12,6 +12,7 @@ export let canTrack = undefined;
|
|
|
12
12
|
export let content = undefined;
|
|
13
13
|
export let isNestedRender = undefined;
|
|
14
14
|
export let nonce = undefined;
|
|
15
|
+
export let apiHost = undefined;
|
|
15
16
|
export let model = undefined;
|
|
16
17
|
export let data = undefined;
|
|
17
18
|
export let context = undefined;
|
|
@@ -82,6 +83,7 @@ onMount(() => {
|
|
|
82
83
|
|
|
83
84
|
{#each getVariants(content) as variant (variant.testVariationId)}
|
|
84
85
|
<ContentComponent
|
|
86
|
+
{apiHost}
|
|
85
87
|
{isNestedRender}
|
|
86
88
|
{nonce}
|
|
87
89
|
content={variant}
|
|
@@ -107,6 +109,7 @@ onMount(() => {
|
|
|
107
109
|
{/each}
|
|
108
110
|
{/if}
|
|
109
111
|
<ContentComponent
|
|
112
|
+
{apiHost}
|
|
110
113
|
{nonce}
|
|
111
114
|
{isNestedRender}
|
|
112
115
|
{...{}}
|
|
@@ -12,6 +12,7 @@ declare const __propDef: {
|
|
|
12
12
|
content?: VariantsProviderProps["content"];
|
|
13
13
|
isNestedRender?: VariantsProviderProps["isNestedRender"];
|
|
14
14
|
nonce?: VariantsProviderProps["nonce"];
|
|
15
|
+
apiHost?: VariantsProviderProps["apiHost"];
|
|
15
16
|
model?: VariantsProviderProps["model"];
|
|
16
17
|
data?: VariantsProviderProps["data"];
|
|
17
18
|
context?: VariantsProviderProps["context"];
|
|
@@ -26,6 +26,10 @@ export interface ContentVariantsPrps extends ExtraFrameworkProps {
|
|
|
26
26
|
* Your API Key: needed to enable visual editing, and to dynamically fetch symbols (required).
|
|
27
27
|
*/
|
|
28
28
|
apiKey: string;
|
|
29
|
+
/**
|
|
30
|
+
* Sets the host of Builder API calls. (Defaults to global `https://cdn.builder.io`)
|
|
31
|
+
*/
|
|
32
|
+
apiHost?: string;
|
|
29
33
|
apiVersion?: ApiVersion;
|
|
30
34
|
/**
|
|
31
35
|
* An array of custom components to register (optional).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "2.0.
|
|
1
|
+
export declare const SDK_VERSION = "2.0.26";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "2.0.
|
|
1
|
+
export const SDK_VERSION = "2.0.26";
|
|
@@ -4,7 +4,7 @@ import { DEFAULT_API_VERSION } from '../../types/api-version';
|
|
|
4
4
|
import { getBuilderSearchParamsFromWindow } from '../get-builder-search-params/index';
|
|
5
5
|
const isPositiveNumber = (thing) => typeof thing === 'number' && !isNaN(thing) && thing >= 0;
|
|
6
6
|
export const generateContentUrl = (options) => {
|
|
7
|
-
const { limit = 30, userAttributes, query, model, apiKey, enrich, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished } = options;
|
|
7
|
+
const { limit = 30, userAttributes, query, model, apiKey, enrich, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished, apiHost } = options;
|
|
8
8
|
if (!apiKey) {
|
|
9
9
|
throw new Error('Missing API key');
|
|
10
10
|
}
|
|
@@ -13,7 +13,8 @@ export const generateContentUrl = (options) => {
|
|
|
13
13
|
}
|
|
14
14
|
// if we are fetching an array of content, we disable noTraverse for perf reasons.
|
|
15
15
|
const noTraverse = limit !== 1;
|
|
16
|
-
const
|
|
16
|
+
const baseUrl = apiHost || 'https://cdn.builder.io';
|
|
17
|
+
const url = new URL(`${baseUrl}/api/${apiVersion}/content/${model}`);
|
|
17
18
|
url.searchParams.set('apiKey', apiKey);
|
|
18
19
|
url.searchParams.set('limit', String(limit));
|
|
19
20
|
url.searchParams.set('noTraverse', String(noTraverse));
|
|
@@ -3,6 +3,7 @@ import { handleABTesting } from '../../helpers/ab-tests';
|
|
|
3
3
|
import { getDefaultCanTrack } from '../../helpers/canTrack';
|
|
4
4
|
import { logger } from '../../helpers/logger';
|
|
5
5
|
import { getPreviewContent } from '../../helpers/preview-lru-cache/get';
|
|
6
|
+
import { getSdkHeaders } from '../../helpers/sdk-headers';
|
|
6
7
|
import { fetch } from '../get-fetch';
|
|
7
8
|
import { isBrowser } from '../is-browser';
|
|
8
9
|
import { generateContentUrl } from './generate-content-url';
|
|
@@ -23,7 +24,14 @@ export async function fetchOneEntry(options) {
|
|
|
23
24
|
const _fetchContent = async (options) => {
|
|
24
25
|
const url = generateContentUrl(options);
|
|
25
26
|
const _fetch = options.fetch ?? fetch;
|
|
26
|
-
const
|
|
27
|
+
const fetchOptions = {
|
|
28
|
+
...options.fetchOptions,
|
|
29
|
+
headers: {
|
|
30
|
+
...options.fetchOptions?.headers,
|
|
31
|
+
...getSdkHeaders()
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const res = await _fetch(url.href, fetchOptions);
|
|
27
35
|
const content = await res.json();
|
|
28
36
|
return content;
|
|
29
37
|
};
|
|
@@ -136,4 +136,8 @@ export interface GetContentOptions {
|
|
|
136
136
|
* Optional fetch options to be passed as the second argument to the `fetch` function.
|
|
137
137
|
*/
|
|
138
138
|
fetchOptions?: object;
|
|
139
|
+
/**
|
|
140
|
+
* Sets the host of Builder API calls. (Defaults to global `https://cdn.builder.io`)
|
|
141
|
+
*/
|
|
142
|
+
apiHost?: string;
|
|
139
143
|
}
|
|
@@ -46,6 +46,8 @@ type EventProperties = Pick<Event, 'type'> & Pick<Event['data'], 'contentId' | '
|
|
|
46
46
|
[index: string]: any;
|
|
47
47
|
};
|
|
48
48
|
export type EventProps = EventProperties & CanTrack;
|
|
49
|
-
export declare function _track(eventProps: EventProps
|
|
49
|
+
export declare function _track({ apiHost, ...eventProps }: EventProps & {
|
|
50
|
+
apiHost?: string;
|
|
51
|
+
}): Promise<void | Response>;
|
|
50
52
|
export declare const track: (args: EventProperties) => Promise<void | Response>;
|
|
51
53
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TARGET } from '../../constants/target';
|
|
2
2
|
import { logger } from '../../helpers/logger';
|
|
3
|
+
import { getSdkHeaders } from '../../helpers/sdk-headers';
|
|
3
4
|
import { getSessionId } from '../../helpers/sessionId';
|
|
4
5
|
import { getVisitorId } from '../../helpers/visitorId';
|
|
5
6
|
import { isBrowser } from '../is-browser';
|
|
@@ -38,7 +39,7 @@ const createEvent = async ({ type: eventType, canTrack, apiKey, metadata, ...pro
|
|
|
38
39
|
ownerId: apiKey
|
|
39
40
|
}
|
|
40
41
|
});
|
|
41
|
-
export async function _track(eventProps) {
|
|
42
|
+
export async function _track({ apiHost, ...eventProps }) {
|
|
42
43
|
if (!eventProps.apiKey) {
|
|
43
44
|
logger.error('Missing API key for track call. Please provide your API key.');
|
|
44
45
|
return;
|
|
@@ -52,13 +53,15 @@ export async function _track(eventProps) {
|
|
|
52
53
|
if (!(isBrowser() || TARGET === 'reactNative')) {
|
|
53
54
|
return;
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
+
const baseUrl = apiHost || 'https://cdn.builder.io';
|
|
57
|
+
return fetch(`${baseUrl}/api/v1/track`, {
|
|
56
58
|
method: 'POST',
|
|
57
59
|
body: JSON.stringify({
|
|
58
60
|
events: [await createEvent(eventProps)]
|
|
59
61
|
}),
|
|
60
62
|
headers: {
|
|
61
|
-
'content-type': 'application/json'
|
|
63
|
+
'content-type': 'application/json',
|
|
64
|
+
...getSdkHeaders()
|
|
62
65
|
},
|
|
63
66
|
mode: 'cors'
|
|
64
67
|
}).catch(err => {
|
|
@@ -18,9 +18,11 @@ import { registerInsertMenu, setupBrowserForEditing, } from "../../../scripts/in
|
|
|
18
18
|
import { triggerAnimation } from "../../block/animator";
|
|
19
19
|
import "../../dynamic-div.svelte";
|
|
20
20
|
import { getWrapperClassName } from "./styles.helpers";
|
|
21
|
+
export let isNestedRender = undefined;
|
|
21
22
|
export let builderContextSignal;
|
|
22
23
|
export let canTrack = undefined;
|
|
23
24
|
export let apiKey;
|
|
25
|
+
export let apiHost = undefined;
|
|
24
26
|
export let locale = undefined;
|
|
25
27
|
export let enrich = undefined;
|
|
26
28
|
export let trustedHosts = undefined;
|
|
@@ -92,6 +94,7 @@ function onClick(event) {
|
|
|
92
94
|
const variationId = $builderContextSignal.content?.testVariationId;
|
|
93
95
|
const contentId = $builderContextSignal.content?.id;
|
|
94
96
|
_track({
|
|
97
|
+
apiHost: apiHost,
|
|
95
98
|
type: "click",
|
|
96
99
|
canTrack: getDefaultCanTrack(canTrack),
|
|
97
100
|
contentId,
|
|
@@ -223,7 +226,7 @@ runHttpRequests();
|
|
|
223
226
|
emitStateUpdate();
|
|
224
227
|
onMount(() => {
|
|
225
228
|
if (isBrowser()) {
|
|
226
|
-
if (isEditing()) {
|
|
229
|
+
if (isEditing() && !isNestedRender) {
|
|
227
230
|
if (elementRef) {
|
|
228
231
|
elementRef.dispatchEvent(new CustomEvent("initeditingbldr"));
|
|
229
232
|
}
|
|
@@ -234,6 +237,7 @@ onMount(() => {
|
|
|
234
237
|
const contentId = $builderContextSignal.content?.id;
|
|
235
238
|
const apiKeyProp = apiKey;
|
|
236
239
|
_track({
|
|
240
|
+
apiHost: apiHost,
|
|
237
241
|
type: "impression",
|
|
238
242
|
canTrack: true,
|
|
239
243
|
contentId,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
-
type BuilderEditorProps = Omit<ContentProps, "customComponents" | "apiVersion" | "isSsrAbTest" | "blocksWrapper" | "blocksWrapperProps" | "
|
|
2
|
+
type BuilderEditorProps = Omit<ContentProps, "customComponents" | "apiVersion" | "isSsrAbTest" | "blocksWrapper" | "blocksWrapperProps" | "linkComponent"> & {
|
|
3
3
|
builderContextSignal: Writable<BuilderContextInterface>;
|
|
4
4
|
setBuilderContextSignal?: (signal: any) => any;
|
|
5
5
|
children?: any;
|
|
@@ -9,9 +9,11 @@ import type { ContentProps } from "../content.types";
|
|
|
9
9
|
import type { Writable } from "svelte/store";
|
|
10
10
|
declare const __propDef: {
|
|
11
11
|
props: {
|
|
12
|
+
isNestedRender?: BuilderEditorProps["isNestedRender"];
|
|
12
13
|
builderContextSignal: BuilderEditorProps["builderContextSignal"];
|
|
13
14
|
canTrack?: BuilderEditorProps["canTrack"];
|
|
14
15
|
apiKey: BuilderEditorProps["apiKey"];
|
|
16
|
+
apiHost?: BuilderEditorProps["apiHost"];
|
|
15
17
|
locale?: BuilderEditorProps["locale"];
|
|
16
18
|
enrich?: BuilderEditorProps["enrich"];
|
|
17
19
|
trustedHosts?: BuilderEditorProps["trustedHosts"];
|
|
@@ -26,13 +26,14 @@ export let apiVersion = undefined;
|
|
|
26
26
|
export let blocksWrapper = undefined;
|
|
27
27
|
export let blocksWrapperProps = undefined;
|
|
28
28
|
export let nonce = undefined;
|
|
29
|
+
export let apiHost = undefined;
|
|
29
30
|
export let enrich = undefined;
|
|
30
31
|
export let showContent;
|
|
31
32
|
export let contentWrapper = undefined;
|
|
32
33
|
export let contentWrapperProps = undefined;
|
|
33
34
|
export let trustedHosts = undefined;
|
|
34
|
-
export let isSsrAbTest;
|
|
35
35
|
export let isNestedRender = undefined;
|
|
36
|
+
export let isSsrAbTest;
|
|
36
37
|
export let linkComponent = undefined;
|
|
37
38
|
function contentSetState(newRootState) {
|
|
38
39
|
$builderContextSignal.rootState = newRootState;
|
|
@@ -116,6 +117,7 @@ setContext(ComponentsContext.key, {
|
|
|
116
117
|
</script>
|
|
117
118
|
|
|
118
119
|
<EnableEditor
|
|
120
|
+
{apiHost}
|
|
119
121
|
{nonce}
|
|
120
122
|
{content}
|
|
121
123
|
{data}
|
|
@@ -130,6 +132,7 @@ setContext(ComponentsContext.key, {
|
|
|
130
132
|
{contentWrapper}
|
|
131
133
|
{contentWrapperProps}
|
|
132
134
|
{trustedHosts}
|
|
135
|
+
{isNestedRender}
|
|
133
136
|
{...{}}
|
|
134
137
|
>
|
|
135
138
|
{#if isSsrAbTest}
|
|
@@ -14,13 +14,14 @@ declare const __propDef: {
|
|
|
14
14
|
blocksWrapper?: ContentProps["blocksWrapper"];
|
|
15
15
|
blocksWrapperProps?: ContentProps["blocksWrapperProps"];
|
|
16
16
|
nonce?: ContentProps["nonce"];
|
|
17
|
+
apiHost?: ContentProps["apiHost"];
|
|
17
18
|
enrich?: ContentProps["enrich"];
|
|
18
19
|
showContent: ContentProps["showContent"];
|
|
19
20
|
contentWrapper?: ContentProps["contentWrapper"];
|
|
20
21
|
contentWrapperProps?: ContentProps["contentWrapperProps"];
|
|
21
22
|
trustedHosts?: ContentProps["trustedHosts"];
|
|
22
|
-
isSsrAbTest: ContentProps["isSsrAbTest"];
|
|
23
23
|
isNestedRender?: ContentProps["isNestedRender"];
|
|
24
|
+
isSsrAbTest: ContentProps["isSsrAbTest"];
|
|
24
25
|
linkComponent?: ContentProps["linkComponent"];
|
|
25
26
|
};
|
|
26
27
|
events: {
|
|
@@ -12,6 +12,7 @@ export let canTrack = undefined;
|
|
|
12
12
|
export let content = undefined;
|
|
13
13
|
export let isNestedRender = undefined;
|
|
14
14
|
export let nonce = undefined;
|
|
15
|
+
export let apiHost = undefined;
|
|
15
16
|
export let model = undefined;
|
|
16
17
|
export let data = undefined;
|
|
17
18
|
export let context = undefined;
|
|
@@ -82,6 +83,7 @@ onMount(() => {
|
|
|
82
83
|
|
|
83
84
|
{#each getVariants(content) as variant (variant.testVariationId)}
|
|
84
85
|
<ContentComponent
|
|
86
|
+
{apiHost}
|
|
85
87
|
{isNestedRender}
|
|
86
88
|
{nonce}
|
|
87
89
|
content={variant}
|
|
@@ -107,6 +109,7 @@ onMount(() => {
|
|
|
107
109
|
{/each}
|
|
108
110
|
{/if}
|
|
109
111
|
<ContentComponent
|
|
112
|
+
{apiHost}
|
|
110
113
|
{nonce}
|
|
111
114
|
{isNestedRender}
|
|
112
115
|
{...{}}
|
|
@@ -12,6 +12,7 @@ declare const __propDef: {
|
|
|
12
12
|
content?: VariantsProviderProps["content"];
|
|
13
13
|
isNestedRender?: VariantsProviderProps["isNestedRender"];
|
|
14
14
|
nonce?: VariantsProviderProps["nonce"];
|
|
15
|
+
apiHost?: VariantsProviderProps["apiHost"];
|
|
15
16
|
model?: VariantsProviderProps["model"];
|
|
16
17
|
data?: VariantsProviderProps["data"];
|
|
17
18
|
context?: VariantsProviderProps["context"];
|
|
@@ -26,6 +26,10 @@ export interface ContentVariantsPrps extends ExtraFrameworkProps {
|
|
|
26
26
|
* Your API Key: needed to enable visual editing, and to dynamically fetch symbols (required).
|
|
27
27
|
*/
|
|
28
28
|
apiKey: string;
|
|
29
|
+
/**
|
|
30
|
+
* Sets the host of Builder API calls. (Defaults to global `https://cdn.builder.io`)
|
|
31
|
+
*/
|
|
32
|
+
apiHost?: string;
|
|
29
33
|
apiVersion?: ApiVersion;
|
|
30
34
|
/**
|
|
31
35
|
* An array of custom components to register (optional).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "2.0.
|
|
1
|
+
export declare const SDK_VERSION = "2.0.26";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "2.0.
|
|
1
|
+
export const SDK_VERSION = "2.0.26";
|
|
@@ -4,7 +4,7 @@ import { DEFAULT_API_VERSION } from '../../types/api-version';
|
|
|
4
4
|
import { getBuilderSearchParamsFromWindow } from '../get-builder-search-params/index';
|
|
5
5
|
const isPositiveNumber = (thing) => typeof thing === 'number' && !isNaN(thing) && thing >= 0;
|
|
6
6
|
export const generateContentUrl = (options) => {
|
|
7
|
-
const { limit = 30, userAttributes, query, model, apiKey, enrich, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished } = options;
|
|
7
|
+
const { limit = 30, userAttributes, query, model, apiKey, enrich, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished, apiHost } = options;
|
|
8
8
|
if (!apiKey) {
|
|
9
9
|
throw new Error('Missing API key');
|
|
10
10
|
}
|
|
@@ -13,7 +13,8 @@ export const generateContentUrl = (options) => {
|
|
|
13
13
|
}
|
|
14
14
|
// if we are fetching an array of content, we disable noTraverse for perf reasons.
|
|
15
15
|
const noTraverse = limit !== 1;
|
|
16
|
-
const
|
|
16
|
+
const baseUrl = apiHost || 'https://cdn.builder.io';
|
|
17
|
+
const url = new URL(`${baseUrl}/api/${apiVersion}/content/${model}`);
|
|
17
18
|
url.searchParams.set('apiKey', apiKey);
|
|
18
19
|
url.searchParams.set('limit', String(limit));
|
|
19
20
|
url.searchParams.set('noTraverse', String(noTraverse));
|
|
@@ -3,6 +3,7 @@ import { handleABTesting } from '../../helpers/ab-tests';
|
|
|
3
3
|
import { getDefaultCanTrack } from '../../helpers/canTrack';
|
|
4
4
|
import { logger } from '../../helpers/logger';
|
|
5
5
|
import { getPreviewContent } from '../../helpers/preview-lru-cache/get';
|
|
6
|
+
import { getSdkHeaders } from '../../helpers/sdk-headers';
|
|
6
7
|
import { fetch } from '../get-fetch';
|
|
7
8
|
import { isBrowser } from '../is-browser';
|
|
8
9
|
import { generateContentUrl } from './generate-content-url';
|
|
@@ -23,7 +24,14 @@ export async function fetchOneEntry(options) {
|
|
|
23
24
|
const _fetchContent = async (options) => {
|
|
24
25
|
const url = generateContentUrl(options);
|
|
25
26
|
const _fetch = options.fetch ?? fetch;
|
|
26
|
-
const
|
|
27
|
+
const fetchOptions = {
|
|
28
|
+
...options.fetchOptions,
|
|
29
|
+
headers: {
|
|
30
|
+
...options.fetchOptions?.headers,
|
|
31
|
+
...getSdkHeaders()
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const res = await _fetch(url.href, fetchOptions);
|
|
27
35
|
const content = await res.json();
|
|
28
36
|
return content;
|
|
29
37
|
};
|
|
@@ -136,4 +136,8 @@ export interface GetContentOptions {
|
|
|
136
136
|
* Optional fetch options to be passed as the second argument to the `fetch` function.
|
|
137
137
|
*/
|
|
138
138
|
fetchOptions?: object;
|
|
139
|
+
/**
|
|
140
|
+
* Sets the host of Builder API calls. (Defaults to global `https://cdn.builder.io`)
|
|
141
|
+
*/
|
|
142
|
+
apiHost?: string;
|
|
139
143
|
}
|
|
@@ -46,6 +46,8 @@ type EventProperties = Pick<Event, 'type'> & Pick<Event['data'], 'contentId' | '
|
|
|
46
46
|
[index: string]: any;
|
|
47
47
|
};
|
|
48
48
|
export type EventProps = EventProperties & CanTrack;
|
|
49
|
-
export declare function _track(eventProps: EventProps
|
|
49
|
+
export declare function _track({ apiHost, ...eventProps }: EventProps & {
|
|
50
|
+
apiHost?: string;
|
|
51
|
+
}): Promise<void | Response>;
|
|
50
52
|
export declare const track: (args: EventProperties) => Promise<void | Response>;
|
|
51
53
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TARGET } from '../../constants/target';
|
|
2
2
|
import { logger } from '../../helpers/logger';
|
|
3
|
+
import { getSdkHeaders } from '../../helpers/sdk-headers';
|
|
3
4
|
import { getSessionId } from '../../helpers/sessionId';
|
|
4
5
|
import { getVisitorId } from '../../helpers/visitorId';
|
|
5
6
|
import { isBrowser } from '../is-browser';
|
|
@@ -38,7 +39,7 @@ const createEvent = async ({ type: eventType, canTrack, apiKey, metadata, ...pro
|
|
|
38
39
|
ownerId: apiKey
|
|
39
40
|
}
|
|
40
41
|
});
|
|
41
|
-
export async function _track(eventProps) {
|
|
42
|
+
export async function _track({ apiHost, ...eventProps }) {
|
|
42
43
|
if (!eventProps.apiKey) {
|
|
43
44
|
logger.error('Missing API key for track call. Please provide your API key.');
|
|
44
45
|
return;
|
|
@@ -52,13 +53,15 @@ export async function _track(eventProps) {
|
|
|
52
53
|
if (!(isBrowser() || TARGET === 'reactNative')) {
|
|
53
54
|
return;
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
+
const baseUrl = apiHost || 'https://cdn.builder.io';
|
|
57
|
+
return fetch(`${baseUrl}/api/v1/track`, {
|
|
56
58
|
method: 'POST',
|
|
57
59
|
body: JSON.stringify({
|
|
58
60
|
events: [await createEvent(eventProps)]
|
|
59
61
|
}),
|
|
60
62
|
headers: {
|
|
61
|
-
'content-type': 'application/json'
|
|
63
|
+
'content-type': 'application/json',
|
|
64
|
+
...getSdkHeaders()
|
|
62
65
|
},
|
|
63
66
|
mode: 'cors'
|
|
64
67
|
}).catch(err => {
|
|
@@ -18,9 +18,11 @@ import { registerInsertMenu, setupBrowserForEditing, } from "../../../scripts/in
|
|
|
18
18
|
import { triggerAnimation } from "../../block/animator";
|
|
19
19
|
import "../../dynamic-div.svelte";
|
|
20
20
|
import { getWrapperClassName } from "./styles.helpers";
|
|
21
|
+
export let isNestedRender = undefined;
|
|
21
22
|
export let builderContextSignal;
|
|
22
23
|
export let canTrack = undefined;
|
|
23
24
|
export let apiKey;
|
|
25
|
+
export let apiHost = undefined;
|
|
24
26
|
export let locale = undefined;
|
|
25
27
|
export let enrich = undefined;
|
|
26
28
|
export let trustedHosts = undefined;
|
|
@@ -92,6 +94,7 @@ function onClick(event) {
|
|
|
92
94
|
const variationId = $builderContextSignal.content?.testVariationId;
|
|
93
95
|
const contentId = $builderContextSignal.content?.id;
|
|
94
96
|
_track({
|
|
97
|
+
apiHost: apiHost,
|
|
95
98
|
type: "click",
|
|
96
99
|
canTrack: getDefaultCanTrack(canTrack),
|
|
97
100
|
contentId,
|
|
@@ -223,7 +226,7 @@ runHttpRequests();
|
|
|
223
226
|
emitStateUpdate();
|
|
224
227
|
onMount(() => {
|
|
225
228
|
if (isBrowser()) {
|
|
226
|
-
if (isEditing()) {
|
|
229
|
+
if (isEditing() && !isNestedRender) {
|
|
227
230
|
if (elementRef) {
|
|
228
231
|
elementRef.dispatchEvent(new CustomEvent("initeditingbldr"));
|
|
229
232
|
}
|
|
@@ -234,6 +237,7 @@ onMount(() => {
|
|
|
234
237
|
const contentId = $builderContextSignal.content?.id;
|
|
235
238
|
const apiKeyProp = apiKey;
|
|
236
239
|
_track({
|
|
240
|
+
apiHost: apiHost,
|
|
237
241
|
type: "impression",
|
|
238
242
|
canTrack: true,
|
|
239
243
|
contentId,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
-
type BuilderEditorProps = Omit<ContentProps, "customComponents" | "apiVersion" | "isSsrAbTest" | "blocksWrapper" | "blocksWrapperProps" | "
|
|
2
|
+
type BuilderEditorProps = Omit<ContentProps, "customComponents" | "apiVersion" | "isSsrAbTest" | "blocksWrapper" | "blocksWrapperProps" | "linkComponent"> & {
|
|
3
3
|
builderContextSignal: Writable<BuilderContextInterface>;
|
|
4
4
|
setBuilderContextSignal?: (signal: any) => any;
|
|
5
5
|
children?: any;
|
|
@@ -9,9 +9,11 @@ import type { ContentProps } from "../content.types";
|
|
|
9
9
|
import type { Writable } from "svelte/store";
|
|
10
10
|
declare const __propDef: {
|
|
11
11
|
props: {
|
|
12
|
+
isNestedRender?: BuilderEditorProps["isNestedRender"];
|
|
12
13
|
builderContextSignal: BuilderEditorProps["builderContextSignal"];
|
|
13
14
|
canTrack?: BuilderEditorProps["canTrack"];
|
|
14
15
|
apiKey: BuilderEditorProps["apiKey"];
|
|
16
|
+
apiHost?: BuilderEditorProps["apiHost"];
|
|
15
17
|
locale?: BuilderEditorProps["locale"];
|
|
16
18
|
enrich?: BuilderEditorProps["enrich"];
|
|
17
19
|
trustedHosts?: BuilderEditorProps["trustedHosts"];
|
|
@@ -26,13 +26,14 @@ export let apiVersion = undefined;
|
|
|
26
26
|
export let blocksWrapper = undefined;
|
|
27
27
|
export let blocksWrapperProps = undefined;
|
|
28
28
|
export let nonce = undefined;
|
|
29
|
+
export let apiHost = undefined;
|
|
29
30
|
export let enrich = undefined;
|
|
30
31
|
export let showContent;
|
|
31
32
|
export let contentWrapper = undefined;
|
|
32
33
|
export let contentWrapperProps = undefined;
|
|
33
34
|
export let trustedHosts = undefined;
|
|
34
|
-
export let isSsrAbTest;
|
|
35
35
|
export let isNestedRender = undefined;
|
|
36
|
+
export let isSsrAbTest;
|
|
36
37
|
export let linkComponent = undefined;
|
|
37
38
|
function contentSetState(newRootState) {
|
|
38
39
|
$builderContextSignal.rootState = newRootState;
|
|
@@ -116,6 +117,7 @@ setContext(ComponentsContext.key, {
|
|
|
116
117
|
</script>
|
|
117
118
|
|
|
118
119
|
<EnableEditor
|
|
120
|
+
{apiHost}
|
|
119
121
|
{nonce}
|
|
120
122
|
{content}
|
|
121
123
|
{data}
|
|
@@ -130,6 +132,7 @@ setContext(ComponentsContext.key, {
|
|
|
130
132
|
{contentWrapper}
|
|
131
133
|
{contentWrapperProps}
|
|
132
134
|
{trustedHosts}
|
|
135
|
+
{isNestedRender}
|
|
133
136
|
{...{}}
|
|
134
137
|
>
|
|
135
138
|
{#if isSsrAbTest}
|
|
@@ -14,13 +14,14 @@ declare const __propDef: {
|
|
|
14
14
|
blocksWrapper?: ContentProps["blocksWrapper"];
|
|
15
15
|
blocksWrapperProps?: ContentProps["blocksWrapperProps"];
|
|
16
16
|
nonce?: ContentProps["nonce"];
|
|
17
|
+
apiHost?: ContentProps["apiHost"];
|
|
17
18
|
enrich?: ContentProps["enrich"];
|
|
18
19
|
showContent: ContentProps["showContent"];
|
|
19
20
|
contentWrapper?: ContentProps["contentWrapper"];
|
|
20
21
|
contentWrapperProps?: ContentProps["contentWrapperProps"];
|
|
21
22
|
trustedHosts?: ContentProps["trustedHosts"];
|
|
22
|
-
isSsrAbTest: ContentProps["isSsrAbTest"];
|
|
23
23
|
isNestedRender?: ContentProps["isNestedRender"];
|
|
24
|
+
isSsrAbTest: ContentProps["isSsrAbTest"];
|
|
24
25
|
linkComponent?: ContentProps["linkComponent"];
|
|
25
26
|
};
|
|
26
27
|
events: {
|
|
@@ -12,6 +12,7 @@ export let canTrack = undefined;
|
|
|
12
12
|
export let content = undefined;
|
|
13
13
|
export let isNestedRender = undefined;
|
|
14
14
|
export let nonce = undefined;
|
|
15
|
+
export let apiHost = undefined;
|
|
15
16
|
export let model = undefined;
|
|
16
17
|
export let data = undefined;
|
|
17
18
|
export let context = undefined;
|
|
@@ -82,6 +83,7 @@ onMount(() => {
|
|
|
82
83
|
|
|
83
84
|
{#each getVariants(content) as variant (variant.testVariationId)}
|
|
84
85
|
<ContentComponent
|
|
86
|
+
{apiHost}
|
|
85
87
|
{isNestedRender}
|
|
86
88
|
{nonce}
|
|
87
89
|
content={variant}
|
|
@@ -107,6 +109,7 @@ onMount(() => {
|
|
|
107
109
|
{/each}
|
|
108
110
|
{/if}
|
|
109
111
|
<ContentComponent
|
|
112
|
+
{apiHost}
|
|
110
113
|
{nonce}
|
|
111
114
|
{isNestedRender}
|
|
112
115
|
{...{}}
|
|
@@ -12,6 +12,7 @@ declare const __propDef: {
|
|
|
12
12
|
content?: VariantsProviderProps["content"];
|
|
13
13
|
isNestedRender?: VariantsProviderProps["isNestedRender"];
|
|
14
14
|
nonce?: VariantsProviderProps["nonce"];
|
|
15
|
+
apiHost?: VariantsProviderProps["apiHost"];
|
|
15
16
|
model?: VariantsProviderProps["model"];
|
|
16
17
|
data?: VariantsProviderProps["data"];
|
|
17
18
|
context?: VariantsProviderProps["context"];
|
|
@@ -26,6 +26,10 @@ export interface ContentVariantsPrps extends ExtraFrameworkProps {
|
|
|
26
26
|
* Your API Key: needed to enable visual editing, and to dynamically fetch symbols (required).
|
|
27
27
|
*/
|
|
28
28
|
apiKey: string;
|
|
29
|
+
/**
|
|
30
|
+
* Sets the host of Builder API calls. (Defaults to global `https://cdn.builder.io`)
|
|
31
|
+
*/
|
|
32
|
+
apiHost?: string;
|
|
29
33
|
apiVersion?: ApiVersion;
|
|
30
34
|
/**
|
|
31
35
|
* An array of custom components to register (optional).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "2.0.
|
|
1
|
+
export declare const SDK_VERSION = "2.0.26";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "2.0.
|
|
1
|
+
export const SDK_VERSION = "2.0.26";
|
|
@@ -4,7 +4,7 @@ import { DEFAULT_API_VERSION } from '../../types/api-version';
|
|
|
4
4
|
import { getBuilderSearchParamsFromWindow } from '../get-builder-search-params/index';
|
|
5
5
|
const isPositiveNumber = (thing) => typeof thing === 'number' && !isNaN(thing) && thing >= 0;
|
|
6
6
|
export const generateContentUrl = (options) => {
|
|
7
|
-
const { limit = 30, userAttributes, query, model, apiKey, enrich, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished } = options;
|
|
7
|
+
const { limit = 30, userAttributes, query, model, apiKey, enrich, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished, apiHost } = options;
|
|
8
8
|
if (!apiKey) {
|
|
9
9
|
throw new Error('Missing API key');
|
|
10
10
|
}
|
|
@@ -13,7 +13,8 @@ export const generateContentUrl = (options) => {
|
|
|
13
13
|
}
|
|
14
14
|
// if we are fetching an array of content, we disable noTraverse for perf reasons.
|
|
15
15
|
const noTraverse = limit !== 1;
|
|
16
|
-
const
|
|
16
|
+
const baseUrl = apiHost || 'https://cdn.builder.io';
|
|
17
|
+
const url = new URL(`${baseUrl}/api/${apiVersion}/content/${model}`);
|
|
17
18
|
url.searchParams.set('apiKey', apiKey);
|
|
18
19
|
url.searchParams.set('limit', String(limit));
|
|
19
20
|
url.searchParams.set('noTraverse', String(noTraverse));
|
|
@@ -3,6 +3,7 @@ import { handleABTesting } from '../../helpers/ab-tests';
|
|
|
3
3
|
import { getDefaultCanTrack } from '../../helpers/canTrack';
|
|
4
4
|
import { logger } from '../../helpers/logger';
|
|
5
5
|
import { getPreviewContent } from '../../helpers/preview-lru-cache/get';
|
|
6
|
+
import { getSdkHeaders } from '../../helpers/sdk-headers';
|
|
6
7
|
import { fetch } from '../get-fetch';
|
|
7
8
|
import { isBrowser } from '../is-browser';
|
|
8
9
|
import { generateContentUrl } from './generate-content-url';
|
|
@@ -23,7 +24,14 @@ export async function fetchOneEntry(options) {
|
|
|
23
24
|
const _fetchContent = async (options) => {
|
|
24
25
|
const url = generateContentUrl(options);
|
|
25
26
|
const _fetch = options.fetch ?? fetch;
|
|
26
|
-
const
|
|
27
|
+
const fetchOptions = {
|
|
28
|
+
...options.fetchOptions,
|
|
29
|
+
headers: {
|
|
30
|
+
...options.fetchOptions?.headers,
|
|
31
|
+
...getSdkHeaders()
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const res = await _fetch(url.href, fetchOptions);
|
|
27
35
|
const content = await res.json();
|
|
28
36
|
return content;
|
|
29
37
|
};
|
|
@@ -136,4 +136,8 @@ export interface GetContentOptions {
|
|
|
136
136
|
* Optional fetch options to be passed as the second argument to the `fetch` function.
|
|
137
137
|
*/
|
|
138
138
|
fetchOptions?: object;
|
|
139
|
+
/**
|
|
140
|
+
* Sets the host of Builder API calls. (Defaults to global `https://cdn.builder.io`)
|
|
141
|
+
*/
|
|
142
|
+
apiHost?: string;
|
|
139
143
|
}
|
|
@@ -46,6 +46,8 @@ type EventProperties = Pick<Event, 'type'> & Pick<Event['data'], 'contentId' | '
|
|
|
46
46
|
[index: string]: any;
|
|
47
47
|
};
|
|
48
48
|
export type EventProps = EventProperties & CanTrack;
|
|
49
|
-
export declare function _track(eventProps: EventProps
|
|
49
|
+
export declare function _track({ apiHost, ...eventProps }: EventProps & {
|
|
50
|
+
apiHost?: string;
|
|
51
|
+
}): Promise<void | Response>;
|
|
50
52
|
export declare const track: (args: EventProperties) => Promise<void | Response>;
|
|
51
53
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TARGET } from '../../constants/target';
|
|
2
2
|
import { logger } from '../../helpers/logger';
|
|
3
|
+
import { getSdkHeaders } from '../../helpers/sdk-headers';
|
|
3
4
|
import { getSessionId } from '../../helpers/sessionId';
|
|
4
5
|
import { getVisitorId } from '../../helpers/visitorId';
|
|
5
6
|
import { isBrowser } from '../is-browser';
|
|
@@ -38,7 +39,7 @@ const createEvent = async ({ type: eventType, canTrack, apiKey, metadata, ...pro
|
|
|
38
39
|
ownerId: apiKey
|
|
39
40
|
}
|
|
40
41
|
});
|
|
41
|
-
export async function _track(eventProps) {
|
|
42
|
+
export async function _track({ apiHost, ...eventProps }) {
|
|
42
43
|
if (!eventProps.apiKey) {
|
|
43
44
|
logger.error('Missing API key for track call. Please provide your API key.');
|
|
44
45
|
return;
|
|
@@ -52,13 +53,15 @@ export async function _track(eventProps) {
|
|
|
52
53
|
if (!(isBrowser() || TARGET === 'reactNative')) {
|
|
53
54
|
return;
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
+
const baseUrl = apiHost || 'https://cdn.builder.io';
|
|
57
|
+
return fetch(`${baseUrl}/api/v1/track`, {
|
|
56
58
|
method: 'POST',
|
|
57
59
|
body: JSON.stringify({
|
|
58
60
|
events: [await createEvent(eventProps)]
|
|
59
61
|
}),
|
|
60
62
|
headers: {
|
|
61
|
-
'content-type': 'application/json'
|
|
63
|
+
'content-type': 'application/json',
|
|
64
|
+
...getSdkHeaders()
|
|
62
65
|
},
|
|
63
66
|
mode: 'cors'
|
|
64
67
|
}).catch(err => {
|
package/package.json
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
| "isSsrAbTest"
|
|
7
7
|
| "blocksWrapper"
|
|
8
8
|
| "blocksWrapperProps"
|
|
9
|
-
| "isNestedRender"
|
|
10
9
|
| "linkComponent"
|
|
11
10
|
> & {
|
|
12
11
|
builderContextSignal: Writable<BuilderContextInterface>;
|
|
@@ -48,9 +47,11 @@
|
|
|
48
47
|
import { getWrapperClassName } from "./styles.helpers";
|
|
49
48
|
import type { Writable } from "svelte/store";
|
|
50
49
|
|
|
50
|
+
export let isNestedRender: BuilderEditorProps["isNestedRender"] = undefined;
|
|
51
51
|
export let builderContextSignal: BuilderEditorProps["builderContextSignal"];
|
|
52
52
|
export let canTrack: BuilderEditorProps["canTrack"] = undefined;
|
|
53
53
|
export let apiKey: BuilderEditorProps["apiKey"];
|
|
54
|
+
export let apiHost: BuilderEditorProps["apiHost"] = undefined;
|
|
54
55
|
export let locale: BuilderEditorProps["locale"] = undefined;
|
|
55
56
|
export let enrich: BuilderEditorProps["enrich"] = undefined;
|
|
56
57
|
export let trustedHosts: BuilderEditorProps["trustedHosts"] = undefined;
|
|
@@ -124,6 +125,7 @@
|
|
|
124
125
|
const variationId = $builderContextSignal.content?.testVariationId;
|
|
125
126
|
const contentId = $builderContextSignal.content?.id;
|
|
126
127
|
_track({
|
|
128
|
+
apiHost: apiHost,
|
|
127
129
|
type: "click",
|
|
128
130
|
canTrack: getDefaultCanTrack(canTrack),
|
|
129
131
|
contentId,
|
|
@@ -279,7 +281,7 @@
|
|
|
279
281
|
|
|
280
282
|
onMount(() => {
|
|
281
283
|
if (isBrowser()) {
|
|
282
|
-
if (isEditing()) {
|
|
284
|
+
if (isEditing() && !isNestedRender) {
|
|
283
285
|
if (elementRef) {
|
|
284
286
|
elementRef.dispatchEvent(new CustomEvent("initeditingbldr"));
|
|
285
287
|
}
|
|
@@ -291,6 +293,7 @@
|
|
|
291
293
|
const contentId = $builderContextSignal.content?.id;
|
|
292
294
|
const apiKeyProp = apiKey;
|
|
293
295
|
_track({
|
|
296
|
+
apiHost: apiHost,
|
|
294
297
|
type: "impression",
|
|
295
298
|
canTrack: true,
|
|
296
299
|
contentId,
|
|
@@ -40,14 +40,15 @@
|
|
|
40
40
|
export let blocksWrapper: ContentProps["blocksWrapper"] = undefined;
|
|
41
41
|
export let blocksWrapperProps: ContentProps["blocksWrapperProps"] = undefined;
|
|
42
42
|
export let nonce: ContentProps["nonce"] = undefined;
|
|
43
|
+
export let apiHost: ContentProps["apiHost"] = undefined;
|
|
43
44
|
export let enrich: ContentProps["enrich"] = undefined;
|
|
44
45
|
export let showContent: ContentProps["showContent"];
|
|
45
46
|
export let contentWrapper: ContentProps["contentWrapper"] = undefined;
|
|
46
47
|
export let contentWrapperProps: ContentProps["contentWrapperProps"] =
|
|
47
48
|
undefined;
|
|
48
49
|
export let trustedHosts: ContentProps["trustedHosts"] = undefined;
|
|
49
|
-
export let isSsrAbTest: ContentProps["isSsrAbTest"];
|
|
50
50
|
export let isNestedRender: ContentProps["isNestedRender"] = undefined;
|
|
51
|
+
export let isSsrAbTest: ContentProps["isSsrAbTest"];
|
|
51
52
|
export let linkComponent: ContentProps["linkComponent"] = undefined;
|
|
52
53
|
|
|
53
54
|
function contentSetState(newRootState: BuilderRenderState) {
|
|
@@ -139,6 +140,7 @@
|
|
|
139
140
|
</script>
|
|
140
141
|
|
|
141
142
|
<EnableEditor
|
|
143
|
+
{apiHost}
|
|
142
144
|
{nonce}
|
|
143
145
|
{content}
|
|
144
146
|
{data}
|
|
@@ -153,6 +155,7 @@
|
|
|
153
155
|
{contentWrapper}
|
|
154
156
|
{contentWrapperProps}
|
|
155
157
|
{trustedHosts}
|
|
158
|
+
{isNestedRender}
|
|
156
159
|
{...{}}
|
|
157
160
|
>
|
|
158
161
|
{#if isSsrAbTest}
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
export let isNestedRender: VariantsProviderProps["isNestedRender"] =
|
|
30
30
|
undefined;
|
|
31
31
|
export let nonce: VariantsProviderProps["nonce"] = undefined;
|
|
32
|
+
export let apiHost: VariantsProviderProps["apiHost"] = undefined;
|
|
32
33
|
export let model: VariantsProviderProps["model"] = undefined;
|
|
33
34
|
export let data: VariantsProviderProps["data"] = undefined;
|
|
34
35
|
export let context: VariantsProviderProps["context"] = undefined;
|
|
@@ -109,6 +110,7 @@
|
|
|
109
110
|
|
|
110
111
|
{#each getVariants(content) as variant (variant.testVariationId)}
|
|
111
112
|
<ContentComponent
|
|
113
|
+
{apiHost}
|
|
112
114
|
{isNestedRender}
|
|
113
115
|
{nonce}
|
|
114
116
|
content={variant}
|
|
@@ -134,6 +136,7 @@
|
|
|
134
136
|
{/each}
|
|
135
137
|
{/if}
|
|
136
138
|
<ContentComponent
|
|
139
|
+
{apiHost}
|
|
137
140
|
{nonce}
|
|
138
141
|
{isNestedRender}
|
|
139
142
|
{...{}}
|
|
@@ -30,6 +30,11 @@ export interface ContentVariantsPrps extends ExtraFrameworkProps {
|
|
|
30
30
|
* Your API Key: needed to enable visual editing, and to dynamically fetch symbols (required).
|
|
31
31
|
*/
|
|
32
32
|
apiKey: string;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Sets the host of Builder API calls. (Defaults to global `https://cdn.builder.io`)
|
|
36
|
+
*/
|
|
37
|
+
apiHost?: string;
|
|
33
38
|
apiVersion?: ApiVersion;
|
|
34
39
|
|
|
35
40
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "2.0.
|
|
1
|
+
export const SDK_VERSION = "2.0.26"
|
|
@@ -20,7 +20,8 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
|
|
|
20
20
|
cacheSeconds,
|
|
21
21
|
staleCacheSeconds,
|
|
22
22
|
sort,
|
|
23
|
-
includeUnpublished
|
|
23
|
+
includeUnpublished,
|
|
24
|
+
apiHost
|
|
24
25
|
} = options;
|
|
25
26
|
if (!apiKey) {
|
|
26
27
|
throw new Error('Missing API key');
|
|
@@ -31,7 +32,8 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
|
|
|
31
32
|
|
|
32
33
|
// if we are fetching an array of content, we disable noTraverse for perf reasons.
|
|
33
34
|
const noTraverse = limit !== 1;
|
|
34
|
-
const
|
|
35
|
+
const baseUrl = apiHost || 'https://cdn.builder.io';
|
|
36
|
+
const url = new URL(`${baseUrl}/api/${apiVersion}/content/${model}`);
|
|
35
37
|
url.searchParams.set('apiKey', apiKey);
|
|
36
38
|
url.searchParams.set('limit', String(limit));
|
|
37
39
|
url.searchParams.set('noTraverse', String(noTraverse));
|
|
@@ -3,6 +3,7 @@ import { handleABTesting } from '../../helpers/ab-tests';
|
|
|
3
3
|
import { getDefaultCanTrack } from '../../helpers/canTrack';
|
|
4
4
|
import { logger } from '../../helpers/logger';
|
|
5
5
|
import { getPreviewContent } from '../../helpers/preview-lru-cache/get';
|
|
6
|
+
import { getSdkHeaders } from '../../helpers/sdk-headers';
|
|
6
7
|
import type { BuilderContent } from '../../types/builder-content';
|
|
7
8
|
import { fetch } from '../get-fetch';
|
|
8
9
|
import { isBrowser } from '../is-browser';
|
|
@@ -33,7 +34,14 @@ type ContentResponse = ContentResults | {
|
|
|
33
34
|
const _fetchContent = async (options: GetContentOptions) => {
|
|
34
35
|
const url = generateContentUrl(options);
|
|
35
36
|
const _fetch = options.fetch ?? fetch;
|
|
36
|
-
const
|
|
37
|
+
const fetchOptions = {
|
|
38
|
+
...options.fetchOptions,
|
|
39
|
+
headers: {
|
|
40
|
+
...(options.fetchOptions as any)?.headers,
|
|
41
|
+
...getSdkHeaders()
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const res = await _fetch(url.href, fetchOptions);
|
|
37
45
|
const content = await (res.json() as Promise<ContentResponse>);
|
|
38
46
|
return content;
|
|
39
47
|
};
|
|
@@ -154,4 +154,9 @@ export interface GetContentOptions {
|
|
|
154
154
|
* Optional fetch options to be passed as the second argument to the `fetch` function.
|
|
155
155
|
*/
|
|
156
156
|
fetchOptions?: object;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Sets the host of Builder API calls. (Defaults to global `https://cdn.builder.io`)
|
|
160
|
+
*/
|
|
161
|
+
apiHost?: string;
|
|
157
162
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TARGET } from '../../constants/target';
|
|
2
2
|
import { logger } from '../../helpers/logger';
|
|
3
|
+
import { getSdkHeaders } from '../../helpers/sdk-headers';
|
|
3
4
|
import { getSessionId } from '../../helpers/sessionId';
|
|
4
5
|
import { getVisitorId } from '../../helpers/visitorId';
|
|
5
6
|
import type { CanTrack } from '../../types/can-track';
|
|
@@ -98,7 +99,12 @@ const createEvent = async ({
|
|
|
98
99
|
ownerId: apiKey
|
|
99
100
|
}
|
|
100
101
|
});
|
|
101
|
-
export async function _track(
|
|
102
|
+
export async function _track({
|
|
103
|
+
apiHost,
|
|
104
|
+
...eventProps
|
|
105
|
+
}: EventProps & {
|
|
106
|
+
apiHost?: string;
|
|
107
|
+
}) {
|
|
102
108
|
if (!eventProps.apiKey) {
|
|
103
109
|
logger.error('Missing API key for track call. Please provide your API key.');
|
|
104
110
|
return;
|
|
@@ -112,13 +118,15 @@ export async function _track(eventProps: EventProps) {
|
|
|
112
118
|
if (!(isBrowser() || TARGET === 'reactNative')) {
|
|
113
119
|
return;
|
|
114
120
|
}
|
|
115
|
-
|
|
121
|
+
const baseUrl = apiHost || 'https://cdn.builder.io';
|
|
122
|
+
return fetch(`${baseUrl}/api/v1/track`, {
|
|
116
123
|
method: 'POST',
|
|
117
124
|
body: JSON.stringify({
|
|
118
125
|
events: [await createEvent(eventProps)]
|
|
119
126
|
}),
|
|
120
127
|
headers: {
|
|
121
|
-
'content-type': 'application/json'
|
|
128
|
+
'content-type': 'application/json',
|
|
129
|
+
...getSdkHeaders()
|
|
122
130
|
},
|
|
123
131
|
mode: 'cors'
|
|
124
132
|
}).catch(err => {
|