@remkoj/optimizely-cms-react 2.0.0-pre3 → 2.0.0-pre4
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/dist/server/components/cms-content.d.ts +1 -1
- package/dist/server/components/cms-content.js +5 -5
- package/dist/server/components/cms-content.js.map +1 -1
- package/dist/server/components/types.d.ts +4 -0
- package/dist/server/components/visual-builder/Composition.d.ts +1 -1
- package/dist/server/components/visual-builder/Composition.js +56 -12
- package/dist/server/components/visual-builder/Composition.js.map +1 -1
- package/dist/server/components/visual-builder/types.d.ts +15 -10
- package/dist/types.d.ts +5 -0
- package/package.json +4 -4
|
@@ -8,5 +8,5 @@ export type { CmsContentProps } from './types.js';
|
|
|
8
8
|
* @param param0
|
|
9
9
|
* @returns
|
|
10
10
|
*/
|
|
11
|
-
export declare const CmsContent: <LocalesType = string>({ contentType, contentTypePrefix, contentLink: rawContentLink, children, fragmentData }: CmsContentProps<LocalesType>) => Promise<JSX.Element>;
|
|
11
|
+
export declare const CmsContent: <LocalesType = string>({ contentType, contentTypePrefix, contentLink: rawContentLink, children, fragmentData, layoutProps }: CmsContentProps<LocalesType>) => Promise<JSX.Element>;
|
|
12
12
|
export default CmsContent;
|
|
@@ -12,7 +12,7 @@ import * as Queries from './queries.js';
|
|
|
12
12
|
* @param param0
|
|
13
13
|
* @returns
|
|
14
14
|
*/
|
|
15
|
-
export const CmsContent = async ({ contentType, contentTypePrefix, contentLink: rawContentLink, children, fragmentData }) => {
|
|
15
|
+
export const CmsContent = async ({ contentType, contentTypePrefix, contentLink: rawContentLink, children, fragmentData, layoutProps }) => {
|
|
16
16
|
const context = getServerContext();
|
|
17
17
|
const contentLink = normalizeContentLink(rawContentLink);
|
|
18
18
|
if (!contentLink) {
|
|
@@ -80,7 +80,7 @@ export const CmsContent = async ({ contentType, contentTypePrefix, contentLink:
|
|
|
80
80
|
console.error("🔴 [CmsContent] Invalid fragment data received for ", Component.displayName ?? contentType?.join("/") ?? "[Undetermined component]");
|
|
81
81
|
return _jsx(_Fragment, {});
|
|
82
82
|
}
|
|
83
|
-
return _jsx(Component, { contentLink: contentLink, data: fragmentData || {}, inEditMode: context.inEditMode });
|
|
83
|
+
return _jsx(Component, { contentLink: contentLink, data: fragmentData || {}, inEditMode: context.inEditMode, layoutProps: layoutProps, children: children });
|
|
84
84
|
}
|
|
85
85
|
if (isInline) {
|
|
86
86
|
console.error(`🔴 [CmsContent] No data for content ${contentLinkToString(contentLink)}, data cannot be resolved for inline content`);
|
|
@@ -95,7 +95,7 @@ export const CmsContent = async ({ contentType, contentTypePrefix, contentLink:
|
|
|
95
95
|
const gqlResponse = await client.request(gqlQuery, gqlVariables);
|
|
96
96
|
if (context.isDebug)
|
|
97
97
|
console.log("⚪ [CmsContent] Component request the following data:", gqlResponse);
|
|
98
|
-
return _jsx(Component, { contentLink: contentLink, data: gqlResponse, inEditMode: context.inEditMode });
|
|
98
|
+
return _jsx(Component, { contentLink: contentLink, data: gqlResponse, inEditMode: context.inEditMode, layoutProps: layoutProps, children: children });
|
|
99
99
|
}
|
|
100
100
|
// Render using included fragment
|
|
101
101
|
if (Utils.isCmsComponentWithFragment(Component)) {
|
|
@@ -112,12 +112,12 @@ export const CmsContent = async ({ contentType, contentTypePrefix, contentLink:
|
|
|
112
112
|
throw new Error(`CmsContent expected to load exactly one content item of type ${name}, received ${totalItems} from Optimizely Graph. Content Item: ${JSON.stringify(fragmentVariables)}`);
|
|
113
113
|
if (totalItems > 1 && context.isDebug)
|
|
114
114
|
console.warn(`🟠 [CmsContent] Resolved ${totalItems} content items, expected only 1. Picked the first one`);
|
|
115
|
-
return _jsx(Component, { contentLink: contentLink, data: fragmentResponse.contentById.items[0], inEditMode: context.inEditMode });
|
|
115
|
+
return _jsx(Component, { contentLink: contentLink, data: fragmentResponse.contentById.items[0], inEditMode: context.inEditMode, layoutProps: layoutProps, children: children });
|
|
116
116
|
}
|
|
117
117
|
// Assume there's no server side prepared data needed for the component
|
|
118
118
|
if (context.isDebug)
|
|
119
119
|
console.log(`⚪ [CmsContent] Component of type "${contentType?.join('/') ?? Component.displayName ?? '?'}" did not request pre-loading of data`);
|
|
120
|
-
return _jsx(Component, { contentLink: contentLink, data: fragmentData || {}, inEditMode: context.inEditMode });
|
|
120
|
+
return _jsx(Component, { contentLink: contentLink, data: fragmentData || {}, inEditMode: context.inEditMode, layoutProps: layoutProps, children: children });
|
|
121
121
|
};
|
|
122
122
|
export default CmsContent;
|
|
123
123
|
//# sourceMappingURL=cms-content.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cms-content.js","sourceRoot":"","sources":["../../../src/server/components/cms-content.tsx"],"names":[],"mappings":";AAAA,OAAO,aAAa,CAAA;AAIpB,OAAO,cAAc,MAAM,uBAAuB,CAAA;AAClD,OAAO,gBAAgB,MAAM,eAAe,CAAA;AAC5C,OAAO,YAAY,EAAE,EAAE,QAAQ,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,mBAAmB,EAAoB,MAAM,iCAAiC,CAAA;AAC1J,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,KAAK,KAAK,MAAM,oBAAoB,CAAA;AAC3C,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AASvC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAAwB,EAAC,WAAW,EAAE,iBAAiB,EAAE,WAAW,EAAE,cAAc,EAAE,QAAQ,EAAE,YAAY,EAAgC,EAAyB,EAAE;
|
|
1
|
+
{"version":3,"file":"cms-content.js","sourceRoot":"","sources":["../../../src/server/components/cms-content.tsx"],"names":[],"mappings":";AAAA,OAAO,aAAa,CAAA;AAIpB,OAAO,cAAc,MAAM,uBAAuB,CAAA;AAClD,OAAO,gBAAgB,MAAM,eAAe,CAAA;AAC5C,OAAO,YAAY,EAAE,EAAE,QAAQ,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,mBAAmB,EAAoB,MAAM,iC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,CAAC,gEAAiE,IAAK,cAAe,UAAW,yCAA0C,IAAI,CAAC,SAAS,CAAE,iBAAiB,CAAE,EAAE,CAAC,CAAA;QACpM,IAAI,UAAU,GAAG,CAAC,IAAI,OAAO,CAAC,OAAO;YAAE,OAAO,CAAC,IAAI,CAAC,4BAA6B,UAAW,uDAAuD,CAAC,CAAA;QACpJ,OAAO,KAAC,SAAS,IAAC,WAAW,EAAG,WAA0B,EAAG,IAAI,EAAG,gBAAgB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,EAAG,UAAU,EAAG,OAAO,CAAC,UAAU,EAAG,WAAW,EAAG,WAAW,YAAK,QAAQ,GAAa,CAAA;IACrM,CAAC;IAED,uEAAuE;IACvE,IAAI,OAAO,CAAC,OAAO;QACf,OAAO,CAAC,GAAG,CAAC,qCAAsC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC,WAAW,IAAI,GAAG,uCAAuC,CAAC,CAAA;IACpJ,OAAO,KAAC,SAAS,IAAC,WAAW,EAAG,WAA0B,EAAG,IAAI,EAAG,YAAY,IAAI,EAAE,EAAG,UAAU,EAAG,OAAO,CAAC,UAAU,EAAG,WAAW,EAAG,WAAW,YAAK,QAAQ,GAAa,CAAA;AAClL,CAAC,CAAA;AAED,eAAe,UAAU,CAAA"}
|
|
@@ -59,6 +59,10 @@ export type CmsContentProps<LocalesType = string> = PropsWithChildren<{
|
|
|
59
59
|
* it will not be applied.
|
|
60
60
|
*/
|
|
61
61
|
contentTypePrefix?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Any layout properties inferred from the context
|
|
64
|
+
*/
|
|
65
|
+
layoutProps?: Record<string, any>;
|
|
62
66
|
}>;
|
|
63
67
|
export type ContentAreaItemDefinition = {
|
|
64
68
|
__typename?: string | null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import 'server-only';
|
|
3
3
|
import type { OptimizelyCompositionProps } from './types.js';
|
|
4
|
-
export declare function OptimizelyComposition({ node,
|
|
4
|
+
export declare function OptimizelyComposition({ node, leafPropsFactory, nodePropsFactory }: OptimizelyCompositionProps): Promise<JSX.Element>;
|
|
5
5
|
export default OptimizelyComposition;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
1
|
import 'server-only';
|
|
3
2
|
import { isElementNode } from './functions.js';
|
|
4
3
|
import { CmsContent } from '../cms-content.js';
|
|
5
|
-
import { getRandomKey } from '../../../utilities.js';
|
|
6
4
|
import { isContentLink, isInlineContentLink } from '@remkoj/optimizely-graph-client';
|
|
5
|
+
import getServerContext from '../../context.js';
|
|
7
6
|
function isContentType(toTest) {
|
|
8
7
|
return Array.isArray(toTest) && toTest.every(x => typeof (x) == 'string' && x.length > 0);
|
|
9
8
|
}
|
|
@@ -18,25 +17,70 @@ const defaultPropsFactory = (node) => {
|
|
|
18
17
|
};
|
|
19
18
|
if (!(isContentLink(contentLink) || isInlineContentLink(contentLink)))
|
|
20
19
|
throw new Error("Invalid content link: " + JSON.stringify(contentLink));
|
|
21
|
-
|
|
20
|
+
const layoutData = {
|
|
21
|
+
type: node.type,
|
|
22
|
+
layoutType: node.layoutType,
|
|
23
|
+
template: node.template,
|
|
24
|
+
settings: node.settings
|
|
25
|
+
};
|
|
26
|
+
return [contentLink, contentType, node.element, layoutData];
|
|
27
|
+
};
|
|
28
|
+
function ucFirst(input) {
|
|
29
|
+
return input[0].toUpperCase() + input.substring(1);
|
|
30
|
+
}
|
|
31
|
+
const defaultNodePropsFactory = (node) => {
|
|
32
|
+
const componentTypes = [
|
|
33
|
+
[node.template, node.type ? ucFirst(node.type) : null, ucFirst(node.layoutType), "Component", "Content"].filter(x => x),
|
|
34
|
+
(node.template && node.type) ? [node.type ? ucFirst(node.type) : null, ucFirst(node.layoutType), "Component", "Content"].filter(x => x) : null,
|
|
35
|
+
["Node", "Component", "Content"]
|
|
36
|
+
].filter(x => x);
|
|
37
|
+
const contentLink = { key: node.key ?? '' };
|
|
38
|
+
const componentData = {};
|
|
39
|
+
const layoutData = {
|
|
40
|
+
type: node.type,
|
|
41
|
+
layoutType: node.layoutType,
|
|
42
|
+
template: node.template,
|
|
43
|
+
settings: node.settings
|
|
44
|
+
};
|
|
45
|
+
if (!(isContentLink(contentLink) || isInlineContentLink(contentLink)))
|
|
46
|
+
throw new Error("Invalid content link: " + JSON.stringify(contentLink));
|
|
47
|
+
return [contentLink, componentTypes, componentData, layoutData];
|
|
22
48
|
};
|
|
23
|
-
export async function OptimizelyComposition({ node,
|
|
49
|
+
export async function OptimizelyComposition({ node, leafPropsFactory = defaultPropsFactory, nodePropsFactory = defaultNodePropsFactory }) {
|
|
24
50
|
if (isElementNode(node)) {
|
|
25
|
-
const [contentLink, contentType, fragmentData] =
|
|
26
|
-
return CmsContent({ contentLink, contentType, fragmentData });
|
|
51
|
+
const [contentLink, contentType, fragmentData, layoutProps] = leafPropsFactory(node);
|
|
52
|
+
return CmsContent({ contentLink, contentType, fragmentData, layoutProps });
|
|
27
53
|
}
|
|
54
|
+
const { factory, isDebug } = getServerContext();
|
|
55
|
+
if (!factory)
|
|
56
|
+
throw new Error("OptimizelyComposition requires the factory be defined within the serverContext");
|
|
28
57
|
const children = await Promise.all((node.nodes ?? []).map((child, idx) => {
|
|
29
|
-
const childKey = `vb::node::${child.key}::${
|
|
30
|
-
//console.log("Visual builder child: ", childKey)
|
|
58
|
+
const childKey = `vb::node::${child.key}::${child.name}`;
|
|
31
59
|
return OptimizelyComposition({
|
|
32
60
|
key: childKey,
|
|
33
61
|
node: child,
|
|
34
|
-
|
|
35
|
-
|
|
62
|
+
leafPropsFactory,
|
|
63
|
+
nodePropsFactory
|
|
36
64
|
});
|
|
37
65
|
}));
|
|
38
|
-
const
|
|
39
|
-
|
|
66
|
+
const [contentLink, contentTypes, fragmentData, layoutProps] = nodePropsFactory(node);
|
|
67
|
+
const firstExistingType = contentTypes.map(ct => {
|
|
68
|
+
const reversed = [...ct].reverse();
|
|
69
|
+
const hasType = factory.has(reversed);
|
|
70
|
+
if (!hasType && isDebug)
|
|
71
|
+
console.log(`🟡 [VisualBuilder] Content type ${reversed.join('/')} not found within factory`);
|
|
72
|
+
return hasType;
|
|
73
|
+
}).indexOf(true);
|
|
74
|
+
const contentType = contentTypes[firstExistingType];
|
|
75
|
+
if (!contentType)
|
|
76
|
+
throw new Error("OptimizelyComposition requires the factory have a definition for Component/Node");
|
|
77
|
+
return CmsContent({
|
|
78
|
+
contentType,
|
|
79
|
+
contentLink,
|
|
80
|
+
fragmentData,
|
|
81
|
+
children,
|
|
82
|
+
layoutProps
|
|
83
|
+
});
|
|
40
84
|
}
|
|
41
85
|
export default OptimizelyComposition;
|
|
42
86
|
//# sourceMappingURL=Composition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Composition.js","sourceRoot":"","sources":["../../../../src/server/components/visual-builder/Composition.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Composition.js","sourceRoot":"","sources":["../../../../src/server/components/visual-builder/Composition.tsx"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAG9C,OAAO,EAAE,aAAa,EAAyB,mBAAmB,EAAE,MAAM,iCAAiC,CAAA;AAE3G,OAAO,gBAAgB,MAAM,kBAAkB,CAAA;AAE/C,SAAS,aAAa,CAAC,MAAW;IAE9B,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAM,CAAC,CAAC,CAAC,IAAI,QAAQ,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;AAC5F,CAAC;AAED,MAAM,mBAAmB,GAAsB,CAA8C,IAAgC,EAAE,EAAE;IAC7H,MAAM,WAAW,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AC,GAAG,CAAC,mCAAoC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAE,2BAA2B,CAAC,CAAA;QACnG,OAAO,OAAO,CAAA;IAClB,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAChB,MAAM,WAAW,GAAG,YAAY,CAAC,iBAAiB,CAAC,CAAA;IACnD,IAAI,CAAC,WAAW;QACZ,MAAM,IAAI,KAAK,CAAC,iFAAiF,CAAC,CAAA;IAEtG,OAAO,UAAU,CAAC;QACd,WAAW;QACX,WAAW;QACX,YAAY;QACZ,QAAQ;QACR,WAAW;KACd,CAAC,CAAA;AACN,CAAC;AAED,eAAe,qBAAqB,CAAA"}
|
|
@@ -7,18 +7,23 @@ export declare enum StructureNodeTypes {
|
|
|
7
7
|
Row = "row",
|
|
8
8
|
Column = "column"
|
|
9
9
|
}
|
|
10
|
-
export type
|
|
10
|
+
export type CompositionNodeBase = {
|
|
11
11
|
name: string | null;
|
|
12
|
+
key: string | null;
|
|
13
|
+
type?: string | null;
|
|
14
|
+
template?: string | null;
|
|
15
|
+
settings?: Array<{
|
|
16
|
+
key: string;
|
|
17
|
+
value: string | number | boolean;
|
|
18
|
+
} | null> | null;
|
|
19
|
+
};
|
|
20
|
+
export type CompositionStructureNode = CompositionNodeBase & {
|
|
12
21
|
layoutType: "outline" | "grid" | "row" | "column";
|
|
13
22
|
nodes?: Array<CompositionNode>;
|
|
14
|
-
key: string | null;
|
|
15
|
-
type: string | null;
|
|
16
23
|
};
|
|
17
|
-
export type CompositionElementNode<E extends Record<string, any> = Record<string, any>> = {
|
|
18
|
-
name: string | null;
|
|
24
|
+
export type CompositionElementNode<E extends Record<string, any> = Record<string, any>> = CompositionNodeBase & {
|
|
19
25
|
layoutType: "element";
|
|
20
26
|
element: E;
|
|
21
|
-
key: string | null;
|
|
22
27
|
};
|
|
23
28
|
export type CompositionNode<E extends Record<string, any> = Record<string, any>> = CompositionStructureNode | CompositionElementNode<E>;
|
|
24
29
|
export type CompositionComponentType<NT extends CompositionNode> = ComponentType<NT extends CompositionElementNode<infer DT> ? {
|
|
@@ -27,11 +32,11 @@ export type CompositionComponentType<NT extends CompositionNode> = ComponentType
|
|
|
27
32
|
} : PropsWithChildren<{
|
|
28
33
|
node: Omit<NT, 'nodes'>;
|
|
29
34
|
}>>;
|
|
30
|
-
export type
|
|
31
|
-
export type
|
|
35
|
+
export type LeafPropsFactory = <ET extends Record<string, any>, LT = string>(node: CompositionElementNode<ET>) => [ContentLinkWithLocale<LT> | InlineContentLinkWithLocale<LT>, ContentType, ET] | [ContentLinkWithLocale<LT> | InlineContentLinkWithLocale<LT>, ContentType, ET, Record<string, any>];
|
|
36
|
+
export type NodePropsFactory = <ET extends Record<string, any>, LT = string>(node: CompositionStructureNode) => [ContentLinkWithLocale<LT> | InlineContentLinkWithLocale<LT>, Array<ContentType>, ET] | [ContentLinkWithLocale<LT> | InlineContentLinkWithLocale<LT>, Array<ContentType>, ET, Record<string, any>];
|
|
32
37
|
export type OptimizelyCompositionProps = {
|
|
33
38
|
node: CompositionNode<Record<string, any>>;
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
leafPropsFactory?: LeafPropsFactory;
|
|
40
|
+
nodePropsFactory?: NodePropsFactory;
|
|
36
41
|
key?: string;
|
|
37
42
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -18,6 +18,10 @@ export type CmsComponentProps<T> = PropsWithChildren<{
|
|
|
18
18
|
* Use the Server/Client context instead if you need this information
|
|
19
19
|
*/
|
|
20
20
|
inEditMode?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Contextual layout data, if any
|
|
23
|
+
*/
|
|
24
|
+
layoutProps?: Record<string, any>;
|
|
21
25
|
}>;
|
|
22
26
|
export type ContentQueryProps<LocaleType = string> = ContentLink & {
|
|
23
27
|
locale?: Array<LocaleType> | LocaleType | null;
|
|
@@ -62,6 +66,7 @@ export type CmsComponentWithOptionalQuery<T = DocumentNode> = BaseCmsComponent<T
|
|
|
62
66
|
export type CmsComponent<T = DocumentNode> = T extends TypedDocumentNode<infer R, any> ? CmsComponentWithQuery<R> : T extends DocumentNode ? CmsComponentWithQuery<{
|
|
63
67
|
[key: string]: any;
|
|
64
68
|
}> : T extends GraphQLFragmentBase ? CmsComponentWithFragment<T> : T extends GraphQLQueryBase ? CmsComponentWithQuery<T> : CmsComponentWithOptionalQuery<T>;
|
|
69
|
+
export type CmsLayoutComponent<T = never> = ReactComponentType<CmsComponentProps<T>>;
|
|
65
70
|
export type ComponentType = (ReactComponentType<any>) | (ReactExoticComponent<any>) | (keyof JSX.IntrinsicElements);
|
|
66
71
|
export type ComponentTypeHandle = string | string[];
|
|
67
72
|
export type ComponentTypeDictionary = {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remkoj/optimizely-cms-react",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "2.0.0-
|
|
4
|
+
"version": "2.0.0-pre4",
|
|
5
5
|
"packageManager": "yarn@4.1.1",
|
|
6
6
|
"repository": "https://github.com/remkoj/optimizely-dxp-clients.git",
|
|
7
7
|
"author": "Remko Jantzen <693172+remkoj@users.noreply.github.com>",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@remkoj/optimizely-graph-client": "2.0.0-
|
|
43
|
+
"@remkoj/optimizely-graph-client": "2.0.0-pre4",
|
|
44
44
|
"@types/crypto-js": "^4.2.2",
|
|
45
45
|
"@types/node": "^20.12.12",
|
|
46
|
-
"@types/react": "^18.3.
|
|
46
|
+
"@types/react": "^18.3.3",
|
|
47
47
|
"@types/react-dom": "18.3.0",
|
|
48
48
|
"graphql": "^16.8.1",
|
|
49
49
|
"graphql-request": "^6.1.0",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"crypto-js": "^4.2.0"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"@remkoj/optimizely-graph-client": "2.0.0-
|
|
61
|
+
"@remkoj/optimizely-graph-client": "2.0.0-pre4",
|
|
62
62
|
"graphql": "^16.8.1",
|
|
63
63
|
"graphql-request": "^6.1.0",
|
|
64
64
|
"react": "*",
|