@sitecore-content-sdk/content 1.5.0-canary.5
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/LICENSE.txt +202 -0
- package/README.md +7 -0
- package/client.d.ts +1 -0
- package/codegen.d.ts +1 -0
- package/config-cli.d.ts +1 -0
- package/config.d.ts +1 -0
- package/dist/cjs/client/edge-proxy.js +24 -0
- package/dist/cjs/client/index.js +14 -0
- package/dist/cjs/client/models.js +2 -0
- package/dist/cjs/client/sitecore-client.js +420 -0
- package/dist/cjs/client/utils.js +53 -0
- package/dist/cjs/config/define-config.js +195 -0
- package/dist/cjs/config/index.js +7 -0
- package/dist/cjs/config/models.js +12 -0
- package/dist/cjs/config-cli/define-cli-config.js +23 -0
- package/dist/cjs/config-cli/index.js +7 -0
- package/dist/cjs/config-cli/models.js +8 -0
- package/dist/cjs/constants.js +12 -0
- package/dist/cjs/debug.js +21 -0
- package/dist/cjs/editing/codegen/index.js +14 -0
- package/dist/cjs/editing/codegen/preview.js +277 -0
- package/dist/cjs/editing/component-layout-service.js +62 -0
- package/dist/cjs/editing/design-library.js +184 -0
- package/dist/cjs/editing/editing-service.js +81 -0
- package/dist/cjs/editing/index.js +33 -0
- package/dist/cjs/editing/models.js +44 -0
- package/dist/cjs/editing/utils.js +105 -0
- package/dist/cjs/form/form.js +81 -0
- package/dist/cjs/form/index.js +7 -0
- package/dist/cjs/i18n/dictionary-service.js +144 -0
- package/dist/cjs/i18n/index.js +7 -0
- package/dist/cjs/i18n/utils.js +16 -0
- package/dist/cjs/index.js +47 -0
- package/dist/cjs/layout/content-styles.js +73 -0
- package/dist/cjs/layout/index.js +24 -0
- package/dist/cjs/layout/layout-service.js +68 -0
- package/dist/cjs/layout/models.js +39 -0
- package/dist/cjs/layout/themes.js +77 -0
- package/dist/cjs/layout/utils.js +117 -0
- package/dist/cjs/media/index.js +38 -0
- package/dist/cjs/media/media-api.js +100 -0
- package/dist/cjs/models.js +2 -0
- package/dist/cjs/personalize/index.js +15 -0
- package/dist/cjs/personalize/layout-personalizer.js +98 -0
- package/dist/cjs/personalize/personalize-service.js +109 -0
- package/dist/cjs/personalize/utils.js +143 -0
- package/dist/cjs/site/error-pages-service.js +82 -0
- package/dist/cjs/site/index.js +26 -0
- package/dist/cjs/site/models.js +2 -0
- package/dist/cjs/site/redirects-service.js +109 -0
- package/dist/cjs/site/robots-service.js +74 -0
- package/dist/cjs/site/site-resolver.js +73 -0
- package/dist/cjs/site/siteinfo-service.js +94 -0
- package/dist/cjs/site/sitemap-xml-service.js +92 -0
- package/dist/cjs/site/sitepath-service.js +201 -0
- package/dist/cjs/site/utils.js +55 -0
- package/dist/cjs/sitecore-service-base.js +33 -0
- package/dist/cjs/tools/codegen/component-generation.js +49 -0
- package/dist/cjs/tools/codegen/extract-files.js +105 -0
- package/dist/cjs/tools/codegen/import-map.js +411 -0
- package/dist/cjs/tools/codegen/utils.js +418 -0
- package/dist/cjs/tools/generate-map.js +2 -0
- package/dist/cjs/tools/generateSites.js +59 -0
- package/dist/cjs/tools/index.js +30 -0
- package/dist/cjs/tools/scaffold.js +62 -0
- package/dist/cjs/tools/templating/components.js +96 -0
- package/dist/cjs/tools/templating/index.js +6 -0
- package/dist/esm/client/edge-proxy.js +19 -0
- package/dist/esm/client/index.js +4 -0
- package/dist/esm/client/models.js +1 -0
- package/dist/esm/client/sitecore-client.js +416 -0
- package/dist/esm/client/utils.js +49 -0
- package/dist/esm/config/define-config.js +189 -0
- package/dist/esm/config/index.js +2 -0
- package/dist/esm/config/models.js +9 -0
- package/dist/esm/config-cli/define-cli-config.js +19 -0
- package/dist/esm/config-cli/index.js +2 -0
- package/dist/esm/config-cli/models.js +5 -0
- package/dist/esm/constants.js +9 -0
- package/dist/esm/debug.js +19 -0
- package/dist/esm/editing/codegen/index.js +1 -0
- package/dist/esm/editing/codegen/preview.js +263 -0
- package/dist/esm/editing/component-layout-service.js +55 -0
- package/dist/esm/editing/design-library.js +172 -0
- package/dist/esm/editing/editing-service.js +74 -0
- package/dist/esm/editing/index.js +6 -0
- package/dist/esm/editing/models.js +41 -0
- package/dist/esm/editing/utils.js +98 -0
- package/dist/esm/form/form.js +72 -0
- package/dist/esm/form/index.js +1 -0
- package/dist/esm/i18n/dictionary-service.js +137 -0
- package/dist/esm/i18n/index.js +2 -0
- package/dist/esm/i18n/utils.js +13 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/layout/content-styles.js +65 -0
- package/dist/esm/layout/index.js +6 -0
- package/dist/esm/layout/layout-service.js +61 -0
- package/dist/esm/layout/models.js +36 -0
- package/dist/esm/layout/themes.js +72 -0
- package/dist/esm/layout/utils.js +109 -0
- package/dist/esm/media/index.js +2 -0
- package/dist/esm/media/media-api.js +90 -0
- package/dist/esm/models.js +1 -0
- package/dist/esm/personalize/index.js +3 -0
- package/dist/esm/personalize/layout-personalizer.js +93 -0
- package/dist/esm/personalize/personalize-service.js +102 -0
- package/dist/esm/personalize/utils.js +135 -0
- package/dist/esm/site/error-pages-service.js +75 -0
- package/dist/esm/site/index.js +8 -0
- package/dist/esm/site/models.js +1 -0
- package/dist/esm/site/redirects-service.js +102 -0
- package/dist/esm/site/robots-service.js +67 -0
- package/dist/esm/site/site-resolver.js +69 -0
- package/dist/esm/site/siteinfo-service.js +87 -0
- package/dist/esm/site/sitemap-xml-service.js +85 -0
- package/dist/esm/site/sitepath-service.js +193 -0
- package/dist/esm/site/utils.js +49 -0
- package/dist/esm/sitecore-service-base.js +29 -0
- package/dist/esm/tools/codegen/component-generation.js +44 -0
- package/dist/esm/tools/codegen/extract-files.js +99 -0
- package/dist/esm/tools/codegen/import-map.js +368 -0
- package/dist/esm/tools/codegen/utils.js +373 -0
- package/dist/esm/tools/generate-map.js +1 -0
- package/dist/esm/tools/generateSites.js +52 -0
- package/dist/esm/tools/index.js +6 -0
- package/dist/esm/tools/scaffold.js +54 -0
- package/dist/esm/tools/templating/components.js +59 -0
- package/dist/esm/tools/templating/index.js +1 -0
- package/editing.d.ts +1 -0
- package/i18n.d.ts +1 -0
- package/layout.d.ts +1 -0
- package/media.d.ts +1 -0
- package/package.json +157 -0
- package/personalize.d.ts +1 -0
- package/site.d.ts +1 -0
- package/tools.d.ts +1 -0
- package/types/client/edge-proxy.d.ts +17 -0
- package/types/client/edge-proxy.d.ts.map +1 -0
- package/types/client/index.d.ts +7 -0
- package/types/client/index.d.ts.map +1 -0
- package/types/client/models.d.ts +21 -0
- package/types/client/models.d.ts.map +1 -0
- package/types/client/sitecore-client.d.ts +338 -0
- package/types/client/sitecore-client.d.ts.map +1 -0
- package/types/client/utils.d.ts +15 -0
- package/types/client/utils.d.ts.map +1 -0
- package/types/config/define-config.d.ts +20 -0
- package/types/config/define-config.d.ts.map +1 -0
- package/types/config/index.d.ts +3 -0
- package/types/config/index.d.ts.map +1 -0
- package/types/config/models.d.ts +287 -0
- package/types/config/models.d.ts.map +1 -0
- package/types/config-cli/define-cli-config.d.ts +9 -0
- package/types/config-cli/define-cli-config.d.ts.map +1 -0
- package/types/config-cli/index.d.ts +3 -0
- package/types/config-cli/index.d.ts.map +1 -0
- package/types/config-cli/models.d.ts +6 -0
- package/types/config-cli/models.d.ts.map +1 -0
- package/types/constants.d.ts +10 -0
- package/types/constants.d.ts.map +1 -0
- package/types/debug.d.ts +19 -0
- package/types/debug.d.ts.map +1 -0
- package/types/editing/codegen/index.d.ts +2 -0
- package/types/editing/codegen/index.d.ts.map +1 -0
- package/types/editing/codegen/preview.d.ts +256 -0
- package/types/editing/codegen/preview.d.ts.map +1 -0
- package/types/editing/component-layout-service.d.ts +84 -0
- package/types/editing/component-layout-service.d.ts.map +1 -0
- package/types/editing/design-library.d.ts +111 -0
- package/types/editing/design-library.d.ts.map +1 -0
- package/types/editing/editing-service.d.ts +71 -0
- package/types/editing/editing-service.d.ts.map +1 -0
- package/types/editing/index.d.ts +7 -0
- package/types/editing/index.d.ts.map +1 -0
- package/types/editing/models.d.ts +103 -0
- package/types/editing/models.d.ts.map +1 -0
- package/types/editing/utils.d.ts +82 -0
- package/types/editing/utils.d.ts.map +1 -0
- package/types/form/form.d.ts +25 -0
- package/types/form/form.d.ts.map +1 -0
- package/types/form/index.d.ts +2 -0
- package/types/form/index.d.ts.map +1 -0
- package/types/i18n/dictionary-service.d.ts +133 -0
- package/types/i18n/dictionary-service.d.ts.map +1 -0
- package/types/i18n/index.d.ts +3 -0
- package/types/i18n/index.d.ts.map +1 -0
- package/types/i18n/utils.d.ts +9 -0
- package/types/i18n/utils.d.ts.map +1 -0
- package/types/index.d.ts +7 -0
- package/types/index.d.ts.map +1 -0
- package/types/layout/content-styles.d.ts +20 -0
- package/types/layout/content-styles.d.ts.map +1 -0
- package/types/layout/index.d.ts +6 -0
- package/types/layout/index.d.ts.map +1 -0
- package/types/layout/layout-service.d.ts +45 -0
- package/types/layout/layout-service.d.ts.map +1 -0
- package/types/layout/models.d.ts +174 -0
- package/types/layout/models.d.ts.map +1 -0
- package/types/layout/themes.d.ts +13 -0
- package/types/layout/themes.d.ts.map +1 -0
- package/types/layout/utils.d.ts +56 -0
- package/types/layout/utils.d.ts.map +1 -0
- package/types/media/index.d.ts +3 -0
- package/types/media/index.d.ts.map +1 -0
- package/types/media/media-api.d.ts +60 -0
- package/types/media/media-api.d.ts.map +1 -0
- package/types/models.d.ts +32 -0
- package/types/models.d.ts.map +1 -0
- package/types/personalize/index.d.ts +4 -0
- package/types/personalize/index.d.ts.map +1 -0
- package/types/personalize/layout-personalizer.d.ts +29 -0
- package/types/personalize/layout-personalizer.d.ts.map +1 -0
- package/types/personalize/personalize-service.d.ts +89 -0
- package/types/personalize/personalize-service.d.ts.map +1 -0
- package/types/personalize/utils.d.ts +78 -0
- package/types/personalize/utils.d.ts.map +1 -0
- package/types/site/error-pages-service.d.ts +64 -0
- package/types/site/error-pages-service.d.ts.map +1 -0
- package/types/site/index.d.ts +10 -0
- package/types/site/index.d.ts.map +1 -0
- package/types/site/models.d.ts +23 -0
- package/types/site/models.d.ts.map +1 -0
- package/types/site/redirects-service.d.ts +91 -0
- package/types/site/redirects-service.d.ts.map +1 -0
- package/types/site/robots-service.d.ts +57 -0
- package/types/site/robots-service.d.ts.map +1 -0
- package/types/site/site-resolver.d.ts +28 -0
- package/types/site/site-resolver.d.ts.map +1 -0
- package/types/site/siteinfo-service.d.ts +64 -0
- package/types/site/siteinfo-service.d.ts.map +1 -0
- package/types/site/sitemap-xml-service.d.ts +63 -0
- package/types/site/sitemap-xml-service.d.ts.map +1 -0
- package/types/site/sitepath-service.d.ts +137 -0
- package/types/site/sitepath-service.d.ts.map +1 -0
- package/types/site/utils.d.ts +41 -0
- package/types/site/utils.d.ts.map +1 -0
- package/types/sitecore-service-base.d.ts +31 -0
- package/types/sitecore-service-base.d.ts.map +1 -0
- package/types/tools/codegen/component-generation.d.ts +50 -0
- package/types/tools/codegen/component-generation.d.ts.map +1 -0
- package/types/tools/codegen/extract-files.d.ts +24 -0
- package/types/tools/codegen/extract-files.d.ts.map +1 -0
- package/types/tools/codegen/import-map.d.ts +103 -0
- package/types/tools/codegen/import-map.d.ts.map +1 -0
- package/types/tools/codegen/utils.d.ts +76 -0
- package/types/tools/codegen/utils.d.ts.map +1 -0
- package/types/tools/generate-map.d.ts +36 -0
- package/types/tools/generate-map.d.ts.map +1 -0
- package/types/tools/generateSites.d.ts +25 -0
- package/types/tools/generateSites.d.ts.map +1 -0
- package/types/tools/index.d.ts +8 -0
- package/types/tools/index.d.ts.map +1 -0
- package/types/tools/scaffold.d.ts +27 -0
- package/types/tools/scaffold.d.ts.map +1 -0
- package/types/tools/templating/components.d.ts +104 -0
- package/types/tools/templating/components.d.ts.map +1 -0
- package/types/tools/templating/index.d.ts +2 -0
- package/types/tools/templating/index.d.ts.map +1 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { constants } from '@sitecore-content-sdk/core';
|
|
2
|
+
import { normalizeUrl } from '@sitecore-content-sdk/core/tools';
|
|
3
|
+
import { DesignLibraryMode } from './models';
|
|
4
|
+
const { SITECORE_EDGE_URL_DEFAULT } = constants;
|
|
5
|
+
/**
|
|
6
|
+
* Event to be sent when report status to design library
|
|
7
|
+
*/
|
|
8
|
+
const DESIGN_LIBRARY_STATUS_EVENT_NAME = 'component:status';
|
|
9
|
+
/**
|
|
10
|
+
* Prefix for component update cache keys
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export const COMPONENT_UPDATE_CACHE_KEY_PREFIX = 'component-update-';
|
|
14
|
+
/**
|
|
15
|
+
* Enumeration of statuses for the design library.
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export var DesignLibraryStatus;
|
|
19
|
+
(function (DesignLibraryStatus) {
|
|
20
|
+
DesignLibraryStatus["READY"] = "ready";
|
|
21
|
+
DesignLibraryStatus["RENDERED"] = "rendered";
|
|
22
|
+
})(DesignLibraryStatus || (DesignLibraryStatus = {}));
|
|
23
|
+
/**
|
|
24
|
+
* Adds the browser-side event handler for 'component:update' message used in Design Library
|
|
25
|
+
* The event should update a component on page by uid, with fields and params from event args
|
|
26
|
+
* @param {ComponentRendering} rootComponent root component displayed for Design Library page
|
|
27
|
+
* @param {Function} successCallback callback to be called after successful component update
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export const addComponentUpdateHandler = (rootComponent, successCallback) => {
|
|
31
|
+
if (!window)
|
|
32
|
+
return;
|
|
33
|
+
const handler = (e) => updateComponentHandler(e, rootComponent, successCallback);
|
|
34
|
+
window.addEventListener('message', handler);
|
|
35
|
+
// the power to remove handler outside of this function, if needed
|
|
36
|
+
const unsubscribe = () => {
|
|
37
|
+
window.removeEventListener('message', handler);
|
|
38
|
+
};
|
|
39
|
+
return unsubscribe;
|
|
40
|
+
};
|
|
41
|
+
export const validateOrigin = (event) => {
|
|
42
|
+
// TODO: use `EDITING_ALLOWED_ORIGINS.concat(getAllowedOriginsFromEnv())` later
|
|
43
|
+
// nextjs's JSS_ALLOWED_ORIGINS is not available on the client, need to use NEXT_PUBLIC_ variable, but it's a breaking change for Deploy
|
|
44
|
+
const allowedOrigins = ['*'];
|
|
45
|
+
return allowedOrigins.some((origin) => origin === event.origin ||
|
|
46
|
+
new RegExp('^' + origin.replace('.', '\\.').replace(/\*/g, '.*') + '$').test(event.origin));
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Validates that a MessageEvent has the expected event name and required data.
|
|
50
|
+
* Logs debug information when validation fails due to invalid origin.
|
|
51
|
+
* @param {MessageEvent} e - The message event to validate.
|
|
52
|
+
* @param {string} eventName - The expected event name to match against e.data.name.
|
|
53
|
+
* @returns {boolean} True if the event has a valid origin, data object, and matching event name; otherwise false.
|
|
54
|
+
*/
|
|
55
|
+
export const validateEvent = (e, eventName) => {
|
|
56
|
+
if (!e.origin || !e.data || e.data.name !== eventName) {
|
|
57
|
+
// avoid extra noise in logs
|
|
58
|
+
if (!validateOrigin(e)) {
|
|
59
|
+
console.debug('Component Library: event skipped - invalid origin: message %s from origin %s', e.data.name, e.origin);
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
};
|
|
65
|
+
export const updateComponentHandler = (e, rootComponent, successCallback) => {
|
|
66
|
+
var _a;
|
|
67
|
+
const eventArgs = e.data;
|
|
68
|
+
if (!e.origin || !eventArgs || eventArgs.name !== 'component:update') {
|
|
69
|
+
// avoid extra noise in logs
|
|
70
|
+
if (!validateOrigin(e)) {
|
|
71
|
+
console.debug('Component Library: event skipped: message %s from origin %s', eventArgs.name, e.origin);
|
|
72
|
+
}
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (!((_a = eventArgs.details) === null || _a === void 0 ? void 0 : _a.uid)) {
|
|
76
|
+
console.debug('Received component:update event without uid, aborting event handler...');
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const findComponent = (root) => {
|
|
80
|
+
var _a, _b;
|
|
81
|
+
if (((_a = root.uid) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === ((_b = eventArgs.details) === null || _b === void 0 ? void 0 : _b.uid.toLowerCase()))
|
|
82
|
+
return root;
|
|
83
|
+
if (root.placeholders) {
|
|
84
|
+
for (const plhName of Object.keys(root.placeholders)) {
|
|
85
|
+
for (const rendering of root.placeholders[plhName]) {
|
|
86
|
+
const result = findComponent(rendering);
|
|
87
|
+
if (result)
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
};
|
|
94
|
+
const componentToUpdate = findComponent(rootComponent);
|
|
95
|
+
if (componentToUpdate) {
|
|
96
|
+
console.debug('Found component with uid %s to update. Update fields: %o. Update params: %o.', eventArgs.details.uid, eventArgs.details.fields, eventArgs.details.params);
|
|
97
|
+
updateComponent(componentToUpdate, eventArgs.details.fields, eventArgs.details.params);
|
|
98
|
+
if (successCallback)
|
|
99
|
+
successCallback(rootComponent);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
console.debug('Rendering with uid %s not found', eventArgs.details.uid);
|
|
103
|
+
}
|
|
104
|
+
// strictly for testing
|
|
105
|
+
return rootComponent;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Updates a component's fields and params with the provided values.
|
|
109
|
+
* @param {ComponentRendering<ComponentFields>} component - The component to update.
|
|
110
|
+
* @param {ComponentFields | undefined} fields - The fields to merge into the component.
|
|
111
|
+
* @param {ComponentParams | undefined} params - The params to merge into the component.
|
|
112
|
+
* @internal
|
|
113
|
+
*/
|
|
114
|
+
export const updateComponent = (component, fields, params) => {
|
|
115
|
+
if (fields) {
|
|
116
|
+
component.fields = Object.assign(Object.assign({}, component.fields), fields);
|
|
117
|
+
}
|
|
118
|
+
if (params) {
|
|
119
|
+
component.params = Object.assign(Object.assign({}, component.params), params);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Generates a DesignLibraryStatusEvent with the given status and uid.
|
|
124
|
+
* @param {DesignLibraryStatus} status - The status of rendering.
|
|
125
|
+
* @param {string} uid - The unique identifier for the event.
|
|
126
|
+
* @returns An object representing the DesignLibraryStatusEvent.
|
|
127
|
+
* @internal
|
|
128
|
+
*/
|
|
129
|
+
export function getDesignLibraryStatusEvent(status, uid) {
|
|
130
|
+
return {
|
|
131
|
+
name: DESIGN_LIBRARY_STATUS_EVENT_NAME,
|
|
132
|
+
message: {
|
|
133
|
+
status,
|
|
134
|
+
uid,
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Generates the URL for the design library script link.
|
|
140
|
+
* @param {string} [sitecoreEdgeUrl] Sitecore Edge Platform URL. Default is https://edge-platform.sitecorecloud.io
|
|
141
|
+
* @returns The full URL to the design library script.
|
|
142
|
+
* @internal
|
|
143
|
+
*/
|
|
144
|
+
export function getDesignLibraryScriptLink(sitecoreEdgeUrl = SITECORE_EDGE_URL_DEFAULT) {
|
|
145
|
+
return `${normalizeUrl(sitecoreEdgeUrl)}/v1/files/designlibrary/lib/rh-lib-script.js`;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Checks if the given mode is a Design Library mode.
|
|
149
|
+
* @param {unknown} mode - The mode to check.
|
|
150
|
+
* @returns {boolean} True if the mode is a Design Library mode, false otherwise.
|
|
151
|
+
* @internal
|
|
152
|
+
*/
|
|
153
|
+
export function isDesignLibraryMode(mode) {
|
|
154
|
+
return mode === DesignLibraryMode.Normal || mode === DesignLibraryMode.Metadata;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Sends an event to the Design Library
|
|
158
|
+
* @param {DesignLibraryEvent} evt - The event object to send.
|
|
159
|
+
* @internal
|
|
160
|
+
*/
|
|
161
|
+
export const postToDesignLibrary = (evt) => {
|
|
162
|
+
if (typeof window === 'undefined')
|
|
163
|
+
return;
|
|
164
|
+
const target = window.parent && window.parent !== window ? window.parent : window;
|
|
165
|
+
try {
|
|
166
|
+
console.log('Component Library: sending event', evt.name, evt);
|
|
167
|
+
target.postMessage(evt, '*');
|
|
168
|
+
}
|
|
169
|
+
catch (err) {
|
|
170
|
+
console.error('Component Library: postMessage failed', err, evt);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import debug from '../debug';
|
|
2
|
+
import { LayoutKind } from './models';
|
|
3
|
+
/**
|
|
4
|
+
* GraphQL query for fetching editing data.
|
|
5
|
+
*/
|
|
6
|
+
export const query = /* GraphQL */ `
|
|
7
|
+
query EditingQuery($itemId: String!, $language: String!, $version: String) {
|
|
8
|
+
item(path: $itemId, language: $language, version: $version) {
|
|
9
|
+
rendered
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
`;
|
|
13
|
+
/**
|
|
14
|
+
* Service for fetching editing data from Sitecore using the Sitecore's GraphQL API.
|
|
15
|
+
* Expected to be used in XMCloud Pages preview (editing) Metadata Edit Mode.
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export class EditingService {
|
|
19
|
+
/**
|
|
20
|
+
* Fetch layout data using the Sitecore GraphQL endpoint.
|
|
21
|
+
* @param {EditingServiceConfig} serviceConfig configuration
|
|
22
|
+
*/
|
|
23
|
+
constructor(serviceConfig) {
|
|
24
|
+
this.serviceConfig = serviceConfig;
|
|
25
|
+
this.graphQLClient = this.getGraphQLClient();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Fetches editing data. Provides the layout data and dictionary phrases
|
|
29
|
+
* @param {object} variables - The parameters for fetching editing data.
|
|
30
|
+
* @param {string} variables.itemId - The item id (path) to fetch layout data for.
|
|
31
|
+
* @param {string} variables.language - The language to fetch layout data for.
|
|
32
|
+
* @param {string} variables.mode - The editing mode to fetch layout data for.
|
|
33
|
+
* @param {string} [variables.version] - The version of the item (optional).
|
|
34
|
+
* @param {LayoutKind} [variables.layoutKind] - The final or shared layout variant.
|
|
35
|
+
* @param {FetchOptions} [fetchOptions] Options to override graphQL client details like retries and fetch implementation
|
|
36
|
+
* @returns {Promise} The layout data and dictionary phrases.
|
|
37
|
+
*/
|
|
38
|
+
async fetchEditingData({ itemId, language, version, layoutKind = LayoutKind.Final, mode }, fetchOptions) {
|
|
39
|
+
var _a;
|
|
40
|
+
debug.editing('fetching editing data for %s %s %s %s', itemId, language, version, layoutKind);
|
|
41
|
+
if (!language) {
|
|
42
|
+
throw new RangeError('The language must be a non-empty string');
|
|
43
|
+
}
|
|
44
|
+
const editModeHeader = mode === 'edit' ? 'true' : 'false';
|
|
45
|
+
const editingData = await this.graphQLClient.request(query, {
|
|
46
|
+
itemId,
|
|
47
|
+
version,
|
|
48
|
+
language,
|
|
49
|
+
}, Object.assign(Object.assign({}, fetchOptions), { headers: {
|
|
50
|
+
sc_layoutKind: layoutKind,
|
|
51
|
+
sc_editMode: editModeHeader,
|
|
52
|
+
} }));
|
|
53
|
+
return {
|
|
54
|
+
layoutData: ((_a = editingData === null || editingData === void 0 ? void 0 : editingData.item) === null || _a === void 0 ? void 0 : _a.rendered) || {
|
|
55
|
+
sitecore: {
|
|
56
|
+
context: { pageEditing: true, language },
|
|
57
|
+
route: null,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Gets a GraphQL client that can make requests to the API.
|
|
64
|
+
* @returns {GraphQLClient} implementation
|
|
65
|
+
*/
|
|
66
|
+
getGraphQLClient() {
|
|
67
|
+
if (!this.serviceConfig.clientFactory) {
|
|
68
|
+
throw new Error('clientFactory needs to be provided when initializing GraphQL client.');
|
|
69
|
+
}
|
|
70
|
+
return this.serviceConfig.clientFactory({
|
|
71
|
+
debugger: debug.editing,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { EditingService } from './editing-service';
|
|
2
|
+
export { DEFAULT_PLACEHOLDER_UID, PagesEditor, isEditorActive, resetEditorChromes, getContentSdkPagesClientData, EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET, INVALID_SECRET_HTML_MESSAGE, PAGES_EDITING_MARKER, PREVIEW_KEY, } from './utils';
|
|
3
|
+
export { ComponentLayoutService, } from './component-layout-service';
|
|
4
|
+
export { DesignLibraryVariantGeneration, } from './models';
|
|
5
|
+
export { LayoutKind, MetadataKind, DesignLibraryMode, } from './models';
|
|
6
|
+
export { addComponentUpdateHandler, DesignLibraryStatus, getDesignLibraryStatusEvent, getDesignLibraryScriptLink, isDesignLibraryMode, postToDesignLibrary, COMPONENT_UPDATE_CACHE_KEY_PREFIX, updateComponent, } from './design-library';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the Editing Layout variant.
|
|
3
|
+
* - shared - shared layout
|
|
4
|
+
* - final - final layout
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export var LayoutKind;
|
|
8
|
+
(function (LayoutKind) {
|
|
9
|
+
LayoutKind["Final"] = "final";
|
|
10
|
+
LayoutKind["Shared"] = "shared";
|
|
11
|
+
})(LayoutKind || (LayoutKind = {}));
|
|
12
|
+
/**
|
|
13
|
+
* Represents the kind of metadata element.
|
|
14
|
+
* - open - starting chrome element
|
|
15
|
+
* - close - closing chrome element
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export var MetadataKind;
|
|
19
|
+
(function (MetadataKind) {
|
|
20
|
+
MetadataKind["Open"] = "open";
|
|
21
|
+
MetadataKind["Close"] = "close";
|
|
22
|
+
})(MetadataKind || (MetadataKind = {}));
|
|
23
|
+
/**
|
|
24
|
+
* Represents the mode of the Design Library
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export var DesignLibraryMode;
|
|
28
|
+
(function (DesignLibraryMode) {
|
|
29
|
+
/** Normal mode */
|
|
30
|
+
DesignLibraryMode["Normal"] = "library";
|
|
31
|
+
/** Metadata mode */
|
|
32
|
+
DesignLibraryMode["Metadata"] = "library-metadata";
|
|
33
|
+
})(DesignLibraryMode || (DesignLibraryMode = {}));
|
|
34
|
+
/**
|
|
35
|
+
* Variant generation mode for Design Library
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export var DesignLibraryVariantGeneration;
|
|
39
|
+
(function (DesignLibraryVariantGeneration) {
|
|
40
|
+
DesignLibraryVariantGeneration["Variant"] = "variant";
|
|
41
|
+
})(DesignLibraryVariantGeneration || (DesignLibraryVariantGeneration = {}));
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { isServer } from '@sitecore-content-sdk/core/tools';
|
|
2
|
+
/**
|
|
3
|
+
* Default value of uid for root placeholder when uid is not present.
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export const DEFAULT_PLACEHOLDER_UID = '00000000-0000-0000-0000-000000000000';
|
|
7
|
+
/**
|
|
8
|
+
* Query parameter for editing secret
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export const QUERY_PARAM_EDITING_SECRET = 'secret';
|
|
12
|
+
/**
|
|
13
|
+
* HTML returned for invalid or missing secret
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export const INVALID_SECRET_HTML_MESSAGE = '<html><body>Missing or invalid secret</body></html>';
|
|
17
|
+
/**
|
|
18
|
+
* Key to identify whether the app is running in Sitecore Preview mode
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export const PREVIEW_KEY = 'sc_preview';
|
|
22
|
+
/**
|
|
23
|
+
* ID to be used as a marker for a script rendered in XMC Pages
|
|
24
|
+
* Should identify app is in XM Cloud Pages editing mode
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export const PAGES_EDITING_MARKER = 'jss-hrz-editing';
|
|
28
|
+
/**
|
|
29
|
+
* Default allowed origins for editing requests. This is used to enforce CORS, CSP headers.
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export const EDITING_ALLOWED_ORIGINS = [
|
|
33
|
+
'https://pages.sitecorecloud.io',
|
|
34
|
+
'https://xmapps.sitecorecloud.io',
|
|
35
|
+
'https://designlibrary.sitecorecloud.io',
|
|
36
|
+
];
|
|
37
|
+
/**
|
|
38
|
+
* Copy of chrome rediscovery contract from Horizon (chrome-rediscovery.contract.ts)
|
|
39
|
+
*/
|
|
40
|
+
export const ChromeRediscoveryGlobalFunctionName = {
|
|
41
|
+
name: 'Sitecore.Horizon.ResetChromes',
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Static utility class for Sitecore Pages Editor
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export class PagesEditor {
|
|
48
|
+
/**
|
|
49
|
+
* Determines whether the current execution context is within a Pages Editor.
|
|
50
|
+
* Pages Editor environment can be identified only in the browser
|
|
51
|
+
* @returns true if executing within a Pages Editor
|
|
52
|
+
*/
|
|
53
|
+
static isActive() {
|
|
54
|
+
if (isServer()) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
// Check for Chromes mode
|
|
58
|
+
const chromesCheck = window.location.search.indexOf('sc_headless_mode=edit') > -1;
|
|
59
|
+
// Content SDK will render a content-sdk-exclusive script element in Metadata mode to indicate edit mode in Pages
|
|
60
|
+
return chromesCheck || !!window.document.getElementById(PAGES_EDITING_MARKER);
|
|
61
|
+
}
|
|
62
|
+
static resetChromes() {
|
|
63
|
+
if (isServer()) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
// Reset chromes in Pages
|
|
67
|
+
window[ChromeRediscoveryGlobalFunctionName.name] &&
|
|
68
|
+
window[ChromeRediscoveryGlobalFunctionName.name]();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Determines whether the current execution context is within a Sitecore editor.
|
|
73
|
+
* Sitecore Editor environment can be identified only in the browser
|
|
74
|
+
* @returns true if executing within a Sitecore editor
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
export const isEditorActive = () => {
|
|
78
|
+
return PagesEditor.isActive();
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Resets Sitecore editor "chromes"
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
export const resetEditorChromes = () => {
|
|
85
|
+
if (PagesEditor.isActive()) {
|
|
86
|
+
PagesEditor.resetChromes();
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Gets extra Content SDK clientData scripts to render in XMC Pages in addition to clientData from Pages itself
|
|
91
|
+
* @returns {Record} collection of clientData
|
|
92
|
+
* @internal
|
|
93
|
+
*/
|
|
94
|
+
export const getContentSdkPagesClientData = () => {
|
|
95
|
+
const clientData = {};
|
|
96
|
+
clientData[PAGES_EDITING_MARKER] = {};
|
|
97
|
+
return clientData;
|
|
98
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { form } from '@sitecore-cloudsdk/events/browser';
|
|
2
|
+
import { getEdgeProxyFormsUrl } from '../client';
|
|
3
|
+
import debug from '../debug';
|
|
4
|
+
/**
|
|
5
|
+
* Fetches the form markup from the Sitecore Edge service and renders it in the component's template.
|
|
6
|
+
* @param {string} contextId - The unique identifier of the current context
|
|
7
|
+
* @param {string} formId - The unique identifier of the form
|
|
8
|
+
* @param {string} [edgeUrl] - The URL of the Sitecore Edge Platform
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export const loadForm = async (contextId, formId, edgeUrl) => {
|
|
12
|
+
if (!contextId) {
|
|
13
|
+
debug.form('Form was not able to render since context id was not provided');
|
|
14
|
+
return '';
|
|
15
|
+
}
|
|
16
|
+
const url = getEdgeProxyFormsUrl(contextId, formId, edgeUrl);
|
|
17
|
+
try {
|
|
18
|
+
debug.form(`Fetching form data from ${url}`);
|
|
19
|
+
const rsp = await fetch(url, {
|
|
20
|
+
method: 'GET',
|
|
21
|
+
cache: 'no-cache',
|
|
22
|
+
});
|
|
23
|
+
if (rsp.status !== 200) {
|
|
24
|
+
throw new Error('Failed to fetch form data');
|
|
25
|
+
}
|
|
26
|
+
const content = await rsp.text();
|
|
27
|
+
debug.form(`Form data fetch response: ${content}`);
|
|
28
|
+
return content;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
debug.form(`Form '${formId}' was not able to render`, error);
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* When you set the innerHTML property of an element, the browser does not execute any <script> tags included in the HTML string
|
|
37
|
+
* This method ensures that any <script> elements within the loaded HTML are executed.
|
|
38
|
+
* It re-creates the script elements and appends the to the component's template, then removes old script elements to avoid duplication.
|
|
39
|
+
* @param {HTMLElement} rootElement - The root element to execute script elements within
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
export const executeScriptElements = (rootElement) => {
|
|
43
|
+
const scriptElements = rootElement.querySelectorAll('script');
|
|
44
|
+
if (!scriptElements) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
Array.from(scriptElements).forEach((scriptElement) => {
|
|
48
|
+
var _a;
|
|
49
|
+
const clonedElement = document.createElement('script');
|
|
50
|
+
Array.from(scriptElement.attributes).forEach((attribute) => {
|
|
51
|
+
clonedElement.setAttribute(attribute.name, attribute.value);
|
|
52
|
+
});
|
|
53
|
+
clonedElement.text = scriptElement.text;
|
|
54
|
+
(_a = scriptElement === null || scriptElement === void 0 ? void 0 : scriptElement.parentNode) === null || _a === void 0 ? void 0 : _a.replaceChild(clonedElement, scriptElement);
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Subscribes to the Form event
|
|
59
|
+
* This listener captures interactions such as form views or submissions
|
|
60
|
+
* @param {HTMLElement} formElement - The form element to subscribe to events on
|
|
61
|
+
* @param {string} [componentId] - The unique identifier of the component
|
|
62
|
+
* @internal
|
|
63
|
+
*/
|
|
64
|
+
export const subscribeToFormSubmitEvent = (formElement, componentId) => {
|
|
65
|
+
formElement.addEventListener('form:engage', ((e) => {
|
|
66
|
+
const { formId, name } = e.detail;
|
|
67
|
+
if (formId && name) {
|
|
68
|
+
debug.form('Sending form event', formId, name);
|
|
69
|
+
form(formId, name, (componentId === null || componentId === void 0 ? void 0 : componentId.replace(/-/g, '')) || '');
|
|
70
|
+
}
|
|
71
|
+
}));
|
|
72
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { executeScriptElements, loadForm, subscribeToFormSubmitEvent } from './form';
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { MemoryCacheClient, } from '@sitecore-content-sdk/core';
|
|
2
|
+
import { siteNameError, languageError } from '../constants';
|
|
3
|
+
import debug from '../debug';
|
|
4
|
+
/** @private */
|
|
5
|
+
export const queryError = 'Valid value for rootItemId not provided and failed to auto-resolve app root item.';
|
|
6
|
+
/** @default */
|
|
7
|
+
const siteQuery = /* GraphQL */ `
|
|
8
|
+
query DictionarySiteQuery(
|
|
9
|
+
$siteName: String!
|
|
10
|
+
$language: String!
|
|
11
|
+
$pageSize: Int = 500
|
|
12
|
+
$after: String
|
|
13
|
+
) {
|
|
14
|
+
site {
|
|
15
|
+
siteInfo(site: $siteName) {
|
|
16
|
+
dictionary(language: $language, first: $pageSize, after: $after) {
|
|
17
|
+
pageInfo {
|
|
18
|
+
endCursor
|
|
19
|
+
hasNext
|
|
20
|
+
}
|
|
21
|
+
results {
|
|
22
|
+
key
|
|
23
|
+
value
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
/**
|
|
31
|
+
* Service that fetch dictionary data using Sitecore's GraphQL API.
|
|
32
|
+
* @augments DictionaryServiceBase
|
|
33
|
+
* @mixes SearchQueryService<DictionaryQueryResult>
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export class DictionaryService {
|
|
37
|
+
/**
|
|
38
|
+
* Creates an instance of graphQL dictionary service with the provided options
|
|
39
|
+
* @param {DictionaryService} options instance
|
|
40
|
+
*/
|
|
41
|
+
constructor(options) {
|
|
42
|
+
this.options = options;
|
|
43
|
+
this.cache = this.getCacheClient();
|
|
44
|
+
this.graphQLClient = this.getGraphQLClient();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Fetches dictionary data for internalization. Uses search query by default
|
|
48
|
+
* @param {string} language the language to fetch
|
|
49
|
+
* @param {string} site site name to fetch data for.
|
|
50
|
+
* @param {FetchOptions} [fetchOptions] Options to override graphQL client details like retries and fetch implementation
|
|
51
|
+
* @returns {Promise<DictionaryPhrases>} dictionary phrases
|
|
52
|
+
* @throws {Error} if the app root was not found for the specified site and language.
|
|
53
|
+
*/
|
|
54
|
+
async fetchDictionaryData(language, site, fetchOptions) {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
const cacheKey = site + language;
|
|
57
|
+
const cachedValue = this.getCacheValue(cacheKey);
|
|
58
|
+
if (cachedValue) {
|
|
59
|
+
debug.dictionary('using cached dictionary data for %s %s', language, site);
|
|
60
|
+
return cachedValue;
|
|
61
|
+
}
|
|
62
|
+
const phrases = {};
|
|
63
|
+
debug.dictionary('fetching dictionary data for %s %s', language, site);
|
|
64
|
+
let results = [];
|
|
65
|
+
let hasNext = true;
|
|
66
|
+
let after = '';
|
|
67
|
+
if (!site) {
|
|
68
|
+
throw new RangeError(siteNameError);
|
|
69
|
+
}
|
|
70
|
+
if (!language) {
|
|
71
|
+
throw new RangeError(languageError);
|
|
72
|
+
}
|
|
73
|
+
while (hasNext) {
|
|
74
|
+
const fetchResponse = await this.graphQLClient.request(siteQuery, {
|
|
75
|
+
siteName: site,
|
|
76
|
+
language,
|
|
77
|
+
pageSize: this.options.pageSize,
|
|
78
|
+
after,
|
|
79
|
+
}, fetchOptions);
|
|
80
|
+
if ((_b = (_a = fetchResponse === null || fetchResponse === void 0 ? void 0 : fetchResponse.site) === null || _a === void 0 ? void 0 : _a.siteInfo) === null || _b === void 0 ? void 0 : _b.dictionary) {
|
|
81
|
+
results = results.concat(fetchResponse.site.siteInfo.dictionary.results);
|
|
82
|
+
after = fetchResponse.site.siteInfo.dictionary.pageInfo.endCursor;
|
|
83
|
+
hasNext = fetchResponse.site.siteInfo.dictionary.pageInfo.hasNext;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
hasNext = false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
results.forEach((item) => (phrases[item.key] = item.value));
|
|
90
|
+
this.setCacheValue(cacheKey, phrases);
|
|
91
|
+
return phrases;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Caches a @see DictionaryPhrases value for the specified cache key.
|
|
95
|
+
* @param {string} key The cache key.
|
|
96
|
+
* @param {DictionaryPhrases} value The value to cache.
|
|
97
|
+
* @returns The value added to the cache.
|
|
98
|
+
* @mixes CacheClient<DictionaryPhrases>
|
|
99
|
+
*/
|
|
100
|
+
setCacheValue(key, value) {
|
|
101
|
+
return this.cache.setCacheValue(key, value);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Retrieves a @see DictionaryPhrases value from the cache.
|
|
105
|
+
* @param {string} key The cache key.
|
|
106
|
+
* @returns The @see DictionaryPhrases value, or null if the specified key is not found in the cache.
|
|
107
|
+
*/
|
|
108
|
+
getCacheValue(key) {
|
|
109
|
+
return this.cache.getCacheValue(key);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Gets a cache client that can cache data. Uses memory-cache as the default
|
|
113
|
+
* library for caching (@see MemoryCacheClient). Override this method if you
|
|
114
|
+
* want to use something else.
|
|
115
|
+
* @returns {CacheClient} implementation
|
|
116
|
+
*/
|
|
117
|
+
getCacheClient() {
|
|
118
|
+
return new MemoryCacheClient(this.options);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
|
|
122
|
+
* library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
|
|
123
|
+
* want to use something else.
|
|
124
|
+
* @returns {GraphQLClient} implementation
|
|
125
|
+
*/
|
|
126
|
+
getGraphQLClient() {
|
|
127
|
+
var _a, _b;
|
|
128
|
+
if (!this.options.clientFactory) {
|
|
129
|
+
throw new Error('clientFactory needs to be provided when initializing GraphQL client.');
|
|
130
|
+
}
|
|
131
|
+
return this.options.clientFactory({
|
|
132
|
+
debugger: debug.dictionary,
|
|
133
|
+
retries: (_a = this.options.retries) === null || _a === void 0 ? void 0 : _a.count,
|
|
134
|
+
retryStrategy: (_b = this.options.retries) === null || _b === void 0 ? void 0 : _b.retryStrategy,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get a locale rewrite path for given pathname
|
|
3
|
+
* @param {string} pathname the pathname
|
|
4
|
+
* @param {string} locale the site data to include in the rewrite
|
|
5
|
+
* @returns {string} the rewrite path
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export function getLocaleRewrite(pathname, locale) {
|
|
9
|
+
if (pathname === '/')
|
|
10
|
+
return `/${locale}`;
|
|
11
|
+
const path = pathname.startsWith('/') ? pathname : '/' + pathname;
|
|
12
|
+
return `/${locale}${path}`;
|
|
13
|
+
}
|