@builder.io/sdk-qwik 0.17.1 → 0.17.2
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/blocks/text/text.qwik.cjs +6 -19
- package/lib/browser/blocks/text/text.qwik.mjs +7 -20
- package/lib/browser/components/block/block.qwik.cjs +2 -3
- package/lib/browser/components/block/block.qwik.mjs +2 -3
- package/lib/browser/components/content/components/enable-editor.qwik.cjs +9 -3
- package/lib/browser/components/content/components/enable-editor.qwik.mjs +9 -3
- package/lib/browser/constants/sdk-version.qwik.cjs +1 -1
- package/lib/browser/constants/sdk-version.qwik.mjs +1 -1
- package/lib/browser/functions/get-block-component-options.qwik.cjs +18 -2
- package/lib/browser/functions/get-block-component-options.qwik.mjs +18 -2
- package/lib/browser/functions/get-content/generate-content-url.qwik.cjs +26 -2
- package/lib/browser/functions/get-content/generate-content-url.qwik.mjs +27 -3
- package/lib/browser/functions/get-processed-block.qwik.cjs +8 -11
- package/lib/browser/functions/get-processed-block.qwik.mjs +8 -11
- package/lib/browser/helpers/flatten.qwik.cjs +18 -0
- package/lib/browser/helpers/flatten.qwik.mjs +19 -1
- package/lib/edge/blocks/text/text.qwik.cjs +6 -19
- package/lib/edge/blocks/text/text.qwik.mjs +7 -20
- package/lib/edge/components/block/block.qwik.cjs +2 -3
- package/lib/edge/components/block/block.qwik.mjs +2 -3
- package/lib/edge/components/content/components/enable-editor.qwik.cjs +9 -3
- package/lib/edge/components/content/components/enable-editor.qwik.mjs +9 -3
- package/lib/edge/constants/sdk-version.qwik.cjs +1 -1
- package/lib/edge/constants/sdk-version.qwik.mjs +1 -1
- package/lib/edge/functions/evaluate/edge-runtime/edge-runtime.qwik.cjs +1 -4
- package/lib/edge/functions/evaluate/edge-runtime/edge-runtime.qwik.mjs +1 -4
- package/lib/edge/functions/get-block-component-options.qwik.cjs +18 -2
- package/lib/edge/functions/get-block-component-options.qwik.mjs +18 -2
- package/lib/edge/functions/get-content/generate-content-url.qwik.cjs +26 -2
- package/lib/edge/functions/get-content/generate-content-url.qwik.mjs +27 -3
- package/lib/edge/functions/get-processed-block.qwik.cjs +8 -11
- package/lib/edge/functions/get-processed-block.qwik.mjs +8 -11
- package/lib/edge/helpers/flatten.qwik.cjs +18 -0
- package/lib/edge/helpers/flatten.qwik.mjs +19 -1
- package/lib/node/blocks/text/text.qwik.cjs +6 -19
- package/lib/node/blocks/text/text.qwik.mjs +7 -20
- package/lib/node/components/block/block.qwik.cjs +2 -3
- package/lib/node/components/block/block.qwik.mjs +2 -3
- package/lib/node/components/content/components/enable-editor.qwik.cjs +9 -3
- package/lib/node/components/content/components/enable-editor.qwik.mjs +9 -3
- package/lib/node/constants/sdk-version.qwik.cjs +1 -1
- package/lib/node/constants/sdk-version.qwik.mjs +1 -1
- package/lib/node/functions/get-block-component-options.qwik.cjs +18 -2
- package/lib/node/functions/get-block-component-options.qwik.mjs +18 -2
- package/lib/node/functions/get-content/generate-content-url.qwik.cjs +26 -2
- package/lib/node/functions/get-content/generate-content-url.qwik.mjs +27 -3
- package/lib/node/functions/get-processed-block.qwik.cjs +8 -11
- package/lib/node/functions/get-processed-block.qwik.mjs +8 -11
- package/lib/node/helpers/flatten.qwik.cjs +18 -0
- package/lib/node/helpers/flatten.qwik.mjs +19 -1
- package/package.json +1 -1
- package/types/src/constants/sdk-version.d.ts +1 -1
- package/types/src/functions/get-block-component-options.d.ts +2 -1
- package/types/src/functions/get-processed-block.d.ts +1 -6
- package/types/src/helpers/flatten.d.ts +6 -0
- package/types/src/server-index.d.ts +1 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { flatten, flattenMongoQuery } from "../../helpers/flatten.qwik.mjs";
|
|
1
|
+
import { flatten, flattenMongoQuery, unflatten } from "../../helpers/flatten.qwik.mjs";
|
|
2
2
|
import { normalizeSearchParams } from "../../helpers/search/search.qwik.mjs";
|
|
3
3
|
import { DEFAULT_API_VERSION } from "../../types/api-version.qwik.mjs";
|
|
4
4
|
import { getBuilderSearchParamsFromWindow } from "../get-builder-search-params/index.qwik.mjs";
|
|
5
|
+
import { isBrowser } from "../is-browser.qwik.mjs";
|
|
5
6
|
const isPositiveNumber = (thing) => typeof thing === "number" && !isNaN(thing) && thing >= 0;
|
|
6
7
|
const generateContentUrl = (options) => {
|
|
7
8
|
const { limit = 30, userAttributes, query, model, apiKey, enrich, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished, apiHost } = options;
|
|
@@ -19,7 +20,7 @@ const generateContentUrl = (options) => {
|
|
|
19
20
|
url.searchParams.set("noTraverse", String(noTraverse));
|
|
20
21
|
url.searchParams.set("includeRefs", String(true));
|
|
21
22
|
const finalLocale = locale || (userAttributes == null ? void 0 : userAttributes.locale);
|
|
22
|
-
let finalUserAttributes = userAttributes;
|
|
23
|
+
let finalUserAttributes = userAttributes || {};
|
|
23
24
|
if (finalLocale) {
|
|
24
25
|
url.searchParams.set("locale", finalLocale);
|
|
25
26
|
finalUserAttributes = {
|
|
@@ -51,10 +52,14 @@ const generateContentUrl = (options) => {
|
|
|
51
52
|
...getBuilderSearchParamsFromWindow(),
|
|
52
53
|
...normalizeSearchParams(options.options || {})
|
|
53
54
|
};
|
|
55
|
+
finalUserAttributes = {
|
|
56
|
+
...finalUserAttributes,
|
|
57
|
+
...getUserAttributesAsJSON(queryOptions)
|
|
58
|
+
};
|
|
54
59
|
const flattened = flatten(queryOptions);
|
|
55
60
|
for (const key in flattened)
|
|
56
61
|
url.searchParams.set(key, String(flattened[key]));
|
|
57
|
-
if (finalUserAttributes)
|
|
62
|
+
if (Object.keys(finalUserAttributes).length > 0)
|
|
58
63
|
url.searchParams.set("userAttributes", JSON.stringify(finalUserAttributes));
|
|
59
64
|
if (query) {
|
|
60
65
|
const flattened2 = flattenMongoQuery({
|
|
@@ -65,6 +70,25 @@ const generateContentUrl = (options) => {
|
|
|
65
70
|
}
|
|
66
71
|
return url;
|
|
67
72
|
};
|
|
73
|
+
const getUserAttributesFromQueryOptions = (queryOptions) => {
|
|
74
|
+
const newUserAttributes = {};
|
|
75
|
+
for (const key in queryOptions)
|
|
76
|
+
if (key.startsWith("userAttributes.")) {
|
|
77
|
+
newUserAttributes[key] = queryOptions[key];
|
|
78
|
+
delete queryOptions[key];
|
|
79
|
+
}
|
|
80
|
+
return newUserAttributes;
|
|
81
|
+
};
|
|
82
|
+
const getUserAttributesAsJSON = (queryOptions) => {
|
|
83
|
+
if (isBrowser() && queryOptions["preview"] === "BUILDER_STUDIO") {
|
|
84
|
+
queryOptions["userAttributes.urlPath"] = window.location.pathname;
|
|
85
|
+
queryOptions["userAttributes.host"] = window.location.host;
|
|
86
|
+
const queryOptionsForUserAttributes = getUserAttributesFromQueryOptions(queryOptions);
|
|
87
|
+
const { userAttributes } = unflatten(queryOptionsForUserAttributes);
|
|
88
|
+
return userAttributes;
|
|
89
|
+
}
|
|
90
|
+
return {};
|
|
91
|
+
};
|
|
68
92
|
export {
|
|
69
93
|
generateContentUrl
|
|
70
94
|
};
|
|
@@ -72,19 +72,16 @@ const evaluateBindings = ({ block, context, localState, rootState, rootSetState
|
|
|
72
72
|
}
|
|
73
73
|
return copied;
|
|
74
74
|
};
|
|
75
|
-
function getProcessedBlock({ block, context,
|
|
75
|
+
function getProcessedBlock({ block, context, localState, rootState, rootSetState }) {
|
|
76
76
|
let transformedBlock = extractLocalizedValues.resolveLocalizedValues(block, rootState.locale);
|
|
77
77
|
transformedBlock = transformBlock.transformBlock(transformedBlock);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
});
|
|
86
|
-
else
|
|
87
|
-
return transformedBlock;
|
|
78
|
+
return evaluateBindings({
|
|
79
|
+
block: transformedBlock,
|
|
80
|
+
localState,
|
|
81
|
+
rootState,
|
|
82
|
+
rootSetState,
|
|
83
|
+
context
|
|
84
|
+
});
|
|
88
85
|
}
|
|
89
86
|
exports.deepCloneWithConditions = deepCloneWithConditions;
|
|
90
87
|
exports.getProcessedBlock = getProcessedBlock;
|
|
@@ -70,19 +70,16 @@ const evaluateBindings = ({ block, context, localState, rootState, rootSetState
|
|
|
70
70
|
}
|
|
71
71
|
return copied;
|
|
72
72
|
};
|
|
73
|
-
function getProcessedBlock({ block, context,
|
|
73
|
+
function getProcessedBlock({ block, context, localState, rootState, rootSetState }) {
|
|
74
74
|
let transformedBlock = resolveLocalizedValues(block, rootState.locale);
|
|
75
75
|
transformedBlock = transformBlock(transformedBlock);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
});
|
|
84
|
-
else
|
|
85
|
-
return transformedBlock;
|
|
76
|
+
return evaluateBindings({
|
|
77
|
+
block: transformedBlock,
|
|
78
|
+
localState,
|
|
79
|
+
rootState,
|
|
80
|
+
rootSetState,
|
|
81
|
+
context
|
|
82
|
+
});
|
|
86
83
|
}
|
|
87
84
|
export {
|
|
88
85
|
deepCloneWithConditions,
|
|
@@ -32,5 +32,23 @@ function flattenMongoQuery(obj, _current, _res = {}) {
|
|
|
32
32
|
}
|
|
33
33
|
return _res;
|
|
34
34
|
}
|
|
35
|
+
function unflatten(obj) {
|
|
36
|
+
const result = {};
|
|
37
|
+
for (const key in obj) {
|
|
38
|
+
const parts = key.split(".");
|
|
39
|
+
let current = result;
|
|
40
|
+
for (let i = 0; i < parts.length; i++) {
|
|
41
|
+
const part = parts[i];
|
|
42
|
+
if (i === parts.length - 1)
|
|
43
|
+
current[part] = obj[key];
|
|
44
|
+
else {
|
|
45
|
+
current[part] = current[part] || {};
|
|
46
|
+
current = current[part];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
35
52
|
exports.flatten = flatten;
|
|
36
53
|
exports.flattenMongoQuery = flattenMongoQuery;
|
|
54
|
+
exports.unflatten = unflatten;
|
|
@@ -30,7 +30,25 @@ function flattenMongoQuery(obj, _current, _res = {}) {
|
|
|
30
30
|
}
|
|
31
31
|
return _res;
|
|
32
32
|
}
|
|
33
|
+
function unflatten(obj) {
|
|
34
|
+
const result = {};
|
|
35
|
+
for (const key in obj) {
|
|
36
|
+
const parts = key.split(".");
|
|
37
|
+
let current = result;
|
|
38
|
+
for (let i = 0; i < parts.length; i++) {
|
|
39
|
+
const part = parts[i];
|
|
40
|
+
if (i === parts.length - 1)
|
|
41
|
+
current[part] = obj[key];
|
|
42
|
+
else {
|
|
43
|
+
current[part] = current[part] || {};
|
|
44
|
+
current = current[part];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
33
50
|
export {
|
|
34
51
|
flatten,
|
|
35
|
-
flattenMongoQuery
|
|
52
|
+
flattenMongoQuery,
|
|
53
|
+
unflatten
|
|
36
54
|
};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.17.
|
|
1
|
+
export declare const SDK_VERSION = "0.17.2";
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import type { BuilderContextInterface } from '../context/types';
|
|
1
2
|
import type { BuilderBlock } from '../types/builder-block';
|
|
2
|
-
export declare function getBlockComponentOptions(block: BuilderBlock): any;
|
|
3
|
+
export declare function getBlockComponentOptions(block: BuilderBlock, context: Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): any;
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import type { BuilderContextInterface } from '../context/types';
|
|
2
2
|
import type { BuilderBlock } from '../types/builder-block';
|
|
3
3
|
export declare function deepCloneWithConditions<T = any>(obj: T): T;
|
|
4
|
-
export declare function getProcessedBlock({ block, context,
|
|
4
|
+
export declare function getProcessedBlock({ block, context, localState, rootState, rootSetState }: {
|
|
5
5
|
block: BuilderBlock;
|
|
6
|
-
/**
|
|
7
|
-
* In some cases, we want to avoid evaluating bindings and only want framework-specific block transformation. It is
|
|
8
|
-
* also sometimes too early to consider bindings, e.g. when we might be looking at a repeated block.
|
|
9
|
-
*/
|
|
10
|
-
shouldEvaluateBindings: boolean;
|
|
11
6
|
} & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): BuilderBlock;
|
|
@@ -14,3 +14,9 @@ export declare function flatten<T extends Record<string, any>>(object: T, path?:
|
|
|
14
14
|
export declare function flattenMongoQuery(obj: any, _current?: any, _res?: any): {
|
|
15
15
|
[key: string]: string;
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Unflatten a flat object with dot-separated keys back into a nested object.
|
|
19
|
+
*
|
|
20
|
+
* { 'foo.bar': 'baz' } -> { foo: { bar: 'baz' }}
|
|
21
|
+
*/
|
|
22
|
+
export declare function unflatten(obj: any): any;
|
|
@@ -15,7 +15,7 @@ export type { ContentVariantsPrps as ContentProps } from './components/content-v
|
|
|
15
15
|
/**
|
|
16
16
|
* General Builder types
|
|
17
17
|
*/
|
|
18
|
-
export type { RegisteredComponent } from './context/types';
|
|
18
|
+
export type { BuilderContextInterface, RegisteredComponent, RegisteredComponents } from './context/types';
|
|
19
19
|
export type { BuilderBlock } from './types/builder-block';
|
|
20
20
|
export type { BuilderContent } from './types/builder-content';
|
|
21
21
|
export type { ComponentInfo } from './types/components';
|