@enonic/nextjs-adapter 3.0.0-B2 → 3.0.0-B4
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 +201 -0
- package/baseMappings.js.map +1 -1
- package/client.js.map +1 -1
- package/common/ComponentRegistry.js.map +1 -1
- package/common/UrlProcessor.js.map +1 -1
- package/common/constants.js.map +1 -1
- package/common/env.js +14 -13
- package/common/env.js.map +1 -1
- package/guillotine/applyProcessors.js.map +1 -1
- package/guillotine/buildComponentTree.js.map +1 -1
- package/guillotine/buildErrorResponse.js.map +1 -1
- package/guillotine/buildPage.js.map +1 -1
- package/guillotine/collectComponentDescriptors.js.map +1 -1
- package/guillotine/combineMultipleQueries.js.map +1 -1
- package/guillotine/createMetaData.js.map +1 -1
- package/guillotine/fetchContent.d.ts +2 -2
- package/guillotine/fetchContent.js +172 -170
- package/guillotine/fetchContent.js.map +1 -1
- package/guillotine/fetchContentData.js.map +1 -1
- package/guillotine/fetchContentPathsForAllLocales.js.map +1 -1
- package/guillotine/fetchContentPathsForLocale.js.map +1 -1
- package/guillotine/fetchFromApi.d.ts +1 -1
- package/guillotine/fetchFromApi.js +56 -54
- package/guillotine/fetchFromApi.js.map +1 -1
- package/guillotine/fetchGuillotine.d.ts +1 -1
- package/guillotine/fetchGuillotine.js +38 -36
- package/guillotine/fetchGuillotine.js.map +1 -1
- package/guillotine/fetchMetaData.js.map +1 -1
- package/guillotine/getCleanContentPathArrayOrThrow400.js.map +1 -1
- package/guillotine/getComponentConfig.js.map +1 -1
- package/guillotine/getContentAndComponentPaths.js.map +1 -1
- package/guillotine/getMetaData.js.map +1 -1
- package/guillotine/getParentRegion.js.map +1 -1
- package/guillotine/getQueryAndVariables.js.map +1 -1
- package/guillotine/metadata/configQuery.js.map +1 -1
- package/guillotine/metadata/richTextQuery.js.map +1 -1
- package/guillotine/parseComponentPath.js.map +1 -1
- package/guillotine/prefixLayoutPath.js.map +1 -1
- package/guillotine/processComponentConfig.js.map +1 -1
- package/guillotine/restrictComponentsToPath.js.map +1 -1
- package/guillotine/validateData.js.map +1 -1
- package/guillotine/validateNotFound.js.map +1 -1
- package/guillotine/validateShortcut.js.map +1 -1
- package/i18n/LocaleContext.jsx.map +1 -1
- package/i18n/i18n.js.map +1 -1
- package/index.d.ts +1 -5
- package/index.js +1 -5
- package/index.js.map +1 -1
- package/package.json +15 -16
- package/query/Shortcut.js.map +1 -1
- package/server.d.ts +5 -0
- package/server.js +6 -0
- package/server.js.map +1 -0
- package/src/baseMappings.ts +53 -0
- package/src/client.ts +2 -0
- package/src/common/ComponentRegistry.ts +162 -0
- package/src/common/UrlProcessor.ts +142 -0
- package/src/common/constants.ts +85 -0
- package/src/common/env.ts +39 -0
- package/src/guillotine/applyProcessors.ts +38 -0
- package/src/guillotine/buildComponentTree.ts +63 -0
- package/src/guillotine/buildErrorResponse.ts +39 -0
- package/src/guillotine/buildPage.ts +15 -0
- package/src/guillotine/collectComponentDescriptors.ts +63 -0
- package/src/guillotine/combineMultipleQueries.ts +75 -0
- package/src/guillotine/createMetaData.ts +73 -0
- package/src/guillotine/fetchContent.ts +250 -0
- package/src/guillotine/fetchContentData.ts +33 -0
- package/src/guillotine/fetchContentPathsForAllLocales.ts +21 -0
- package/src/guillotine/fetchContentPathsForLocale.ts +42 -0
- package/src/guillotine/fetchFromApi.ts +69 -0
- package/src/guillotine/fetchGuillotine.ts +61 -0
- package/src/guillotine/fetchMetaData.ts +32 -0
- package/src/guillotine/getCleanContentPathArrayOrThrow400.ts +22 -0
- package/src/guillotine/getComponentConfig.ts +7 -0
- package/src/guillotine/getContentAndComponentPaths.ts +11 -0
- package/src/guillotine/getMetaData.ts +73 -0
- package/src/guillotine/getParentRegion.ts +59 -0
- package/src/guillotine/getQueryAndVariables.ts +52 -0
- package/src/guillotine/metadata/configQuery.ts +46 -0
- package/src/guillotine/metadata/richTextQuery.ts +34 -0
- package/src/guillotine/parseComponentPath.ts +29 -0
- package/src/guillotine/prefixLayoutPath.ts +16 -0
- package/src/guillotine/processComponentConfig.ts +38 -0
- package/src/guillotine/restrictComponentsToPath.ts +45 -0
- package/src/guillotine/validateData.ts +11 -0
- package/src/guillotine/validateNotFound.ts +20 -0
- package/src/guillotine/validateShortcut.ts +37 -0
- package/src/i18n/LocaleContext.tsx +54 -0
- package/src/i18n/i18n.ts +54 -0
- package/src/index.ts +42 -0
- package/src/query/Shortcut.ts +14 -0
- package/src/server.ts +5 -0
- package/src/types/component.ts +147 -0
- package/src/types/componentProps.ts +142 -0
- package/src/types/guillotine.ts +426 -0
- package/src/types/i18n.ts +8 -0
- package/src/types/index.ts +58 -0
- package/src/types/next.ts +7 -0
- package/src/types/util.ts +5 -0
- package/src/utils/addLineNumbers.ts +3 -0
- package/src/utils/buildGuillotineRequestHeaders.ts +32 -0
- package/src/utils/commonChars.ts +16 -0
- package/src/utils/fixDoubleSlashes.ts +3 -0
- package/src/utils/getContentApiUrl.ts +20 -0
- package/src/utils/getProjectLocaleConfig.ts +24 -0
- package/src/utils/getProjectLocaleConfigById.ts +21 -0
- package/src/utils/getProjectLocaleConfigByLocale.ts +19 -0
- package/src/utils/getProjectLocaleConfigs.ts +36 -0
- package/src/utils/getProjectLocales.ts +6 -0
- package/src/utils/getRenderMode.ts +14 -0
- package/src/utils/getRequestLocaleInfo.ts +29 -0
- package/src/utils/getXpBaseUrl.ts +12 -0
- package/src/utils/indent.ts +4 -0
- package/src/utils/sanitizeGraphqlName.ts +11 -0
- package/src/views/BaseComponent.tsx +153 -0
- package/src/views/BaseContent.tsx +47 -0
- package/src/views/BaseLayout.tsx +33 -0
- package/src/views/BaseMacro.tsx +94 -0
- package/src/views/BasePage.tsx +42 -0
- package/src/views/BasePart.tsx +34 -0
- package/src/views/Empty.tsx +5 -0
- package/src/views/Fragment.tsx +41 -0
- package/src/views/MainView.tsx +22 -0
- package/src/views/PropsView.tsx +38 -0
- package/src/views/Region.tsx +76 -0
- package/src/views/RichTextView.tsx +75 -0
- package/src/views/SingleComponent.tsx +19 -0
- package/src/views/StaticContent.tsx +39 -0
- package/src/views/Text.tsx +19 -0
- package/src/views/getClientHydratedHtml.tsx +12 -0
- package/src/views/macros/DefaultMacro.tsx +9 -0
- package/src/views/macros/DisableMacro.tsx +8 -0
- package/types/component.js.map +1 -1
- package/types/componentProps.js.map +1 -1
- package/types/guillotine.js.map +1 -1
- package/types/i18n.js.map +1 -1
- package/types/index.js.map +1 -1
- package/types/next.js.map +1 -1
- package/types/util.js.map +1 -1
- package/utils/addLineNumbers.js.map +1 -1
- package/utils/buildGuillotineRequestHeaders.js.map +1 -1
- package/utils/commonChars.js.map +1 -1
- package/utils/fixDoubleSlashes.js.map +1 -1
- package/utils/getContentApiUrl.js.map +1 -1
- package/utils/getProjectLocaleConfig.js.map +1 -1
- package/utils/getProjectLocaleConfigById.js.map +1 -1
- package/utils/getProjectLocaleConfigByLocale.js.map +1 -1
- package/utils/getProjectLocaleConfigs.js.map +1 -1
- package/utils/getProjectLocales.js.map +1 -1
- package/utils/getRenderMode.js.map +1 -1
- package/utils/getRequestLocaleInfo.js.map +1 -1
- package/utils/getXpBaseUrl.js.map +1 -1
- package/utils/indent.js.map +1 -1
- package/utils/sanitizeGraphqlName.js.map +1 -1
- package/views/BaseComponent.jsx.map +1 -1
- package/views/BaseContent.jsx.map +1 -1
- package/views/BaseLayout.jsx.map +1 -1
- package/views/BaseMacro.jsx.map +1 -1
- package/views/BasePage.jsx.map +1 -1
- package/views/BasePart.jsx.map +1 -1
- package/views/Empty.jsx.map +1 -1
- package/views/Fragment.jsx.map +1 -1
- package/views/MainView.jsx.map +1 -1
- package/views/PropsView.jsx.map +1 -1
- package/views/Region.jsx.map +1 -1
- package/views/RichTextView.jsx.map +1 -1
- package/views/SingleComponent.jsx.map +1 -1
- package/views/StaticContent.jsx.map +1 -1
- package/views/Text.jsx.map +1 -1
- package/views/getClientHydratedHtml.jsx.map +1 -1
- package/views/macros/DefaultMacro.jsx.map +1 -1
- package/views/macros/DisableMacro.jsx.map +1 -1
|
@@ -38,185 +38,187 @@ import { createMetaData } from './createMetaData';
|
|
|
38
38
|
* @param context object from Next, contains .query info
|
|
39
39
|
* @returns FetchContentResult object: {data?: T, error?: {code, message}}
|
|
40
40
|
*/
|
|
41
|
-
export
|
|
41
|
+
export function fetchContent(context) {
|
|
42
42
|
var _a, _b;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
const outHeaders = buildGuillotineRequestHeaders({
|
|
57
|
-
context,
|
|
58
|
-
defaultLocale,
|
|
59
|
-
locale,
|
|
60
|
-
locales,
|
|
61
|
-
});
|
|
62
|
-
const xpBaseUrl = getXpBaseUrl(context);
|
|
63
|
-
const contentApiUrl = getContentApiUrl(context);
|
|
64
|
-
const projectConfig = getProjectLocaleConfig(context);
|
|
65
|
-
const renderMode = getRenderMode(context);
|
|
66
|
-
let requestType = XP_REQUEST_TYPE.TYPE;
|
|
67
|
-
const requestContentPath = getCleanContentPathArrayOrThrow400(context.contentPath);
|
|
68
|
-
const errorResponse = buildErrorResponse(requestType, renderMode, contentApiUrl, xpBaseUrl, locale, defaultLocale, requestContentPath);
|
|
69
|
-
UrlProcessor.setSiteKey(projectConfig.site);
|
|
70
|
-
try {
|
|
71
|
-
const [siteRelativeContentPath, componentPath] = getContentAndComponentPaths(requestContentPath);
|
|
72
|
-
if (componentPath) {
|
|
73
|
-
// set component request type because url contains component path
|
|
74
|
-
requestType = XP_REQUEST_TYPE.COMPONENT;
|
|
75
|
-
}
|
|
76
|
-
// ///////////// FIRST GUILLOTINE CALL FOR METADATA /////////////////
|
|
77
|
-
const metaResult = yield fetchMetaData(contentApiUrl, '${site}/' + siteRelativeContentPath, projectConfig, outHeaders);
|
|
78
|
-
// ///////////////////////////////////////////////////////////////////////
|
|
79
|
-
const { _path, type } = metaResult.meta || {};
|
|
80
|
-
const contentPath = _path || siteRelativeContentPath;
|
|
81
|
-
if (metaResult.error) {
|
|
82
|
-
console.error(metaResult.error);
|
|
83
|
-
return errorResponse(metaResult.error.code, metaResult.error.message);
|
|
84
|
-
}
|
|
85
|
-
if (!metaResult.meta) {
|
|
86
|
-
return errorResponse('404', 'No meta data found for content, most likely content does not exist');
|
|
87
|
-
}
|
|
88
|
-
else if (!type) {
|
|
89
|
-
return errorResponse('500', "Server responded with incomplete meta data: missing content 'type' attribute.");
|
|
90
|
-
}
|
|
91
|
-
else if (renderMode === RENDER_MODE.NEXT
|
|
92
|
-
&& !IS_DEV_MODE
|
|
93
|
-
&& (type === FRAGMENT_CONTENTTYPE_NAME ||
|
|
94
|
-
type === PAGE_TEMPLATE_CONTENTTYPE_NAME ||
|
|
95
|
-
type === PAGE_TEMPLATE_FOLDER)) {
|
|
96
|
-
return errorResponse('404', `Content type [${type}] is not accessible in ${renderMode} mode`);
|
|
97
|
-
}
|
|
98
|
-
const components = restrictComponentsToPath(type, metaResult.meta.components, componentPath);
|
|
99
|
-
if (componentPath && !components.length) {
|
|
100
|
-
// component was not found
|
|
101
|
-
return errorResponse('404', `Component ${componentPath} was not found`);
|
|
102
|
-
}
|
|
103
|
-
if (requestType !== XP_REQUEST_TYPE.COMPONENT && components.length > 0) {
|
|
104
|
-
requestType = XP_REQUEST_TYPE.PAGE;
|
|
105
|
-
}
|
|
106
|
-
// ////////////////////////////////////////////////// Content type established. Proceed to data call:
|
|
107
|
-
const allDescriptors = [];
|
|
108
|
-
// Add the content type query at all cases
|
|
109
|
-
const contentTypeDef = ComponentRegistry.getContentType(type);
|
|
110
|
-
const pageCmp = (components || []).find(cmp => cmp.type === XP_COMPONENT_TYPE.PAGE);
|
|
111
|
-
if (pageCmp) {
|
|
112
|
-
processComponentConfig(APP_NAME, APP_NAME_DASHED, pageCmp);
|
|
113
|
-
}
|
|
114
|
-
const contentQueryAndVars = getQueryAndVariables(type, contentPath, context, contentTypeDef === null || contentTypeDef === void 0 ? void 0 : contentTypeDef.query, (_a = pageCmp === null || pageCmp === void 0 ? void 0 : pageCmp.page) === null || _a === void 0 ? void 0 : _a.config);
|
|
115
|
-
if (contentQueryAndVars) {
|
|
116
|
-
allDescriptors.push({
|
|
117
|
-
type: contentTypeDef,
|
|
118
|
-
queryAndVariables: contentQueryAndVars,
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const { locale, locales, defaultLocale } = getRequestLocaleInfo(context);
|
|
45
|
+
// ideally we only want to set headers in draft mode,
|
|
46
|
+
// but draft mode token is not passed in non-static mode
|
|
47
|
+
// so try to add them whenever they are absent
|
|
48
|
+
if (!context.headers) {
|
|
49
|
+
// TODO does this break routing or dynamic server-side rendering?
|
|
50
|
+
// I guess hydration will fix it anyway?
|
|
51
|
+
const allHeaders = headers();
|
|
52
|
+
context.headers = new Headers();
|
|
53
|
+
allHeaders.forEach((value, key) => {
|
|
54
|
+
context.headers.set(key, value);
|
|
119
55
|
});
|
|
120
56
|
}
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
57
|
+
const outHeaders = buildGuillotineRequestHeaders({
|
|
58
|
+
context,
|
|
59
|
+
defaultLocale,
|
|
60
|
+
locale,
|
|
61
|
+
locales,
|
|
62
|
+
});
|
|
63
|
+
const xpBaseUrl = getXpBaseUrl(context);
|
|
64
|
+
const contentApiUrl = getContentApiUrl(context);
|
|
65
|
+
const projectConfig = getProjectLocaleConfig(context);
|
|
66
|
+
const renderMode = getRenderMode(context);
|
|
67
|
+
let requestType = XP_REQUEST_TYPE.TYPE;
|
|
68
|
+
const requestContentPath = getCleanContentPathArrayOrThrow400(context.contentPath);
|
|
69
|
+
const errorResponse = buildErrorResponse(requestType, renderMode, contentApiUrl, xpBaseUrl, locale, defaultLocale, requestContentPath);
|
|
70
|
+
UrlProcessor.setSiteKey(projectConfig.site);
|
|
71
|
+
try {
|
|
72
|
+
const [siteRelativeContentPath, componentPath] = getContentAndComponentPaths(requestContentPath);
|
|
73
|
+
if (componentPath) {
|
|
74
|
+
// set component request type because url contains component path
|
|
75
|
+
requestType = XP_REQUEST_TYPE.COMPONENT;
|
|
131
76
|
}
|
|
132
|
-
//
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
77
|
+
// ///////////// FIRST GUILLOTINE CALL FOR METADATA /////////////////
|
|
78
|
+
const metaResult = yield fetchMetaData(contentApiUrl, '${site}/' + siteRelativeContentPath, projectConfig, outHeaders);
|
|
79
|
+
// ///////////////////////////////////////////////////////////////////////
|
|
80
|
+
const { _path, type } = metaResult.meta || {};
|
|
81
|
+
const contentPath = _path || siteRelativeContentPath;
|
|
82
|
+
if (metaResult.error) {
|
|
83
|
+
console.error(metaResult.error);
|
|
84
|
+
return errorResponse(metaResult.error.code, metaResult.error.message);
|
|
140
85
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
86
|
+
if (!metaResult.meta) {
|
|
87
|
+
return errorResponse('404', 'No meta data found for content, most likely content does not exist');
|
|
88
|
+
}
|
|
89
|
+
else if (!type) {
|
|
90
|
+
return errorResponse('500', "Server responded with incomplete meta data: missing content 'type' attribute.");
|
|
91
|
+
}
|
|
92
|
+
else if (renderMode === RENDER_MODE.NEXT
|
|
93
|
+
&& !IS_DEV_MODE
|
|
94
|
+
&& (type === FRAGMENT_CONTENTTYPE_NAME ||
|
|
95
|
+
type === PAGE_TEMPLATE_CONTENTTYPE_NAME ||
|
|
96
|
+
type === PAGE_TEMPLATE_FOLDER)) {
|
|
97
|
+
return errorResponse('404', `Content type [${type}] is not accessible in ${renderMode} mode`);
|
|
98
|
+
}
|
|
99
|
+
const components = restrictComponentsToPath(type, metaResult.meta.components, componentPath);
|
|
100
|
+
if (componentPath && !components.length) {
|
|
101
|
+
// component was not found
|
|
102
|
+
return errorResponse('404', `Component ${componentPath} was not found`);
|
|
103
|
+
}
|
|
104
|
+
if (requestType !== XP_REQUEST_TYPE.COMPONENT && components.length > 0) {
|
|
105
|
+
requestType = XP_REQUEST_TYPE.PAGE;
|
|
106
|
+
}
|
|
107
|
+
// ////////////////////////////////////////////////// Content type established. Proceed to data call:
|
|
108
|
+
const allDescriptors = [];
|
|
109
|
+
// Add the content type query at all cases
|
|
110
|
+
const contentTypeDef = ComponentRegistry.getContentType(type);
|
|
111
|
+
const pageCmp = (components || []).find(cmp => cmp.type === XP_COMPONENT_TYPE.PAGE);
|
|
112
|
+
if (pageCmp) {
|
|
113
|
+
processComponentConfig(APP_NAME, APP_NAME_DASHED, pageCmp);
|
|
114
|
+
}
|
|
115
|
+
const contentQueryAndVars = getQueryAndVariables(type, contentPath, context, contentTypeDef === null || contentTypeDef === void 0 ? void 0 : contentTypeDef.query, (_a = pageCmp === null || pageCmp === void 0 ? void 0 : pageCmp.page) === null || _a === void 0 ? void 0 : _a.config);
|
|
116
|
+
if (contentQueryAndVars) {
|
|
117
|
+
allDescriptors.push({
|
|
118
|
+
type: contentTypeDef,
|
|
119
|
+
queryAndVariables: contentQueryAndVars,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
const commonQueryAndVars = getQueryAndVariables(type, contentPath, context, ComponentRegistry.getCommonQuery(), (_b = pageCmp === null || pageCmp === void 0 ? void 0 : pageCmp.page) === null || _b === void 0 ? void 0 : _b.config);
|
|
123
|
+
if (commonQueryAndVars) {
|
|
124
|
+
allDescriptors.push({
|
|
125
|
+
type: contentTypeDef,
|
|
126
|
+
queryAndVariables: commonQueryAndVars,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
if ((components === null || components === void 0 ? void 0 : components.length) && ComponentRegistry) {
|
|
130
|
+
for (const cmp of (components || [])) {
|
|
131
|
+
processComponentConfig(APP_NAME, APP_NAME_DASHED, cmp);
|
|
176
132
|
}
|
|
177
|
-
|
|
178
|
-
|
|
133
|
+
// Collect component queries if defined
|
|
134
|
+
const componentDescriptors = collectComponentDescriptors({
|
|
135
|
+
components,
|
|
136
|
+
xpContentPath: contentPath,
|
|
137
|
+
context,
|
|
138
|
+
});
|
|
139
|
+
if (componentDescriptors.length) {
|
|
140
|
+
allDescriptors.push(...componentDescriptors);
|
|
179
141
|
}
|
|
180
|
-
allDescriptors[i].component.error = reason;
|
|
181
142
|
}
|
|
182
|
-
|
|
183
|
-
|
|
143
|
+
const { query, variables } = combineMultipleQueries(allDescriptors);
|
|
144
|
+
if (!query.trim()) {
|
|
145
|
+
return errorResponse('400', `Missing or empty query override for content type ${type}`);
|
|
184
146
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
147
|
+
// /////////////// SECOND GUILLOTINE CALL FOR DATA //////////////////////
|
|
148
|
+
const contentResults = yield fetchContentData(contentApiUrl, contentPath, projectConfig, query, variables, outHeaders);
|
|
149
|
+
// ///////////////////////////////////////////////////////////////////////////
|
|
150
|
+
if (contentResults.error) {
|
|
151
|
+
console.error(contentResults.error);
|
|
152
|
+
return errorResponse(contentResults.error.code, contentResults.error.message);
|
|
153
|
+
}
|
|
154
|
+
// Apply processors to every component
|
|
155
|
+
const datas = yield applyProcessors(allDescriptors, contentResults, context);
|
|
156
|
+
// Unwind the data back to components
|
|
157
|
+
let contentData = null, common = null;
|
|
158
|
+
let startFrom = 0;
|
|
159
|
+
if (contentQueryAndVars) {
|
|
160
|
+
const item = datas[startFrom];
|
|
161
|
+
contentData = item.status === 'fulfilled' ? item.value : item.reason;
|
|
162
|
+
startFrom++;
|
|
163
|
+
}
|
|
164
|
+
if (commonQueryAndVars) {
|
|
165
|
+
const item = datas[startFrom];
|
|
166
|
+
common = item.status === 'fulfilled' ? item.value : item.reason;
|
|
167
|
+
startFrom++;
|
|
168
|
+
}
|
|
169
|
+
for (let i = startFrom; i < datas.length; i++) {
|
|
170
|
+
// component descriptors hold references to components
|
|
171
|
+
// that will later be used for creating page regions
|
|
172
|
+
const datum = datas[i];
|
|
173
|
+
if (datum.status === 'rejected') {
|
|
174
|
+
let reason = datum.reason;
|
|
175
|
+
if (reason instanceof Error) {
|
|
176
|
+
reason = reason.message;
|
|
177
|
+
}
|
|
178
|
+
else if (typeof reason !== 'string') {
|
|
179
|
+
reason = String(reason);
|
|
180
|
+
}
|
|
181
|
+
allDescriptors[i].component.error = reason;
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
allDescriptors[i].component.data = datum.value;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const page = buildPage(type, components);
|
|
188
|
+
const meta = createMetaData({
|
|
189
|
+
apiUrl: contentApiUrl,
|
|
190
|
+
baseUrl: xpBaseUrl,
|
|
191
|
+
components,
|
|
192
|
+
contentPath: siteRelativeContentPath,
|
|
193
|
+
contentType: type,
|
|
194
|
+
defaultLocale,
|
|
195
|
+
locale,
|
|
196
|
+
pageCmp: page,
|
|
197
|
+
renderMode,
|
|
198
|
+
requestedComponentPath: componentPath,
|
|
199
|
+
requestType,
|
|
200
|
+
});
|
|
201
|
+
return {
|
|
202
|
+
data: contentData,
|
|
203
|
+
common,
|
|
204
|
+
meta,
|
|
205
|
+
page,
|
|
217
206
|
};
|
|
218
207
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
208
|
+
catch (e) {
|
|
209
|
+
console.error(e);
|
|
210
|
+
let error;
|
|
211
|
+
try {
|
|
212
|
+
error = JSON.parse(e.message);
|
|
213
|
+
}
|
|
214
|
+
catch (e2) {
|
|
215
|
+
error = {
|
|
216
|
+
code: 'Local',
|
|
217
|
+
message: e.message,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
return errorResponse(error.code, error.message);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
222
224
|
//# sourceMappingURL=fetchContent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchContent.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"fetchContent.js","sourceRoot":"","sources":["../src/guillotine/fetchContent.ts"],"names":[],"mappings":";;;;;;;;;AAGA,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AACrC,OAAO,EAAC,iBAAiB,EAAC,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AACpD,OAAO,EACH,yBAAyB,EACzB,8BAA8B,EAC9B,oBAAoB,EACpB,WAAW,EACX,iBAAiB,EACjB,eAAe,GAClB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAC,QAAQ,EAAE,eAAe,EAAE,WAAW,EAAC,MAAM,eAAe,CAAC;AACrE,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BA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AAC,CAAC;YACzC,MAAM,IAAI,GAAG,cAAc,CAAC;gBACxB,MAAM,EAAE,aAAa;gBACrB,OAAO,EAAE,SAAS;gBAClB,UAAU;gBACV,WAAW,EAAE,uBAAuB;gBACpC,WAAW,EAAE,IAAI;gBACjB,aAAa;gBACb,MAAM;gBACN,OAAO,EAAE,IAAI;gBACb,UAAU;gBACV,sBAAsB,EAAE,aAAa;gBACrC,WAAW;aACd,CAAC,CAAC;YAEH,OAAO;gBACH,IAAI,EAAE,WAAW;gBACjB,MAAM;gBACN,IAAI;gBACJ,IAAI;aACP,CAAC;QACN,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YACd,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAEjB,IAAI,KAAK,CAAC;YACV,IAAI,CAAC;gBACD,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;YAClC,CAAC;YAAC,OAAO,EAAE,EAAE,CAAC;gBACV,KAAK,GAAG;oBACJ,IAAI,EAAE,OAAO;oBACb,OAAO,EAAE,CAAC,CAAC,OAAO;iBACrB,CAAC;YACN,CAAC;YACD,OAAO,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QACpD,CAAC;;CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchContentData.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"fetchContentData.js","sourceRoot":"","sources":["../src/guillotine/fetchContentData.ts"],"names":[],"mappings":";;;;;;;;;AAOA,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAGlD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC5B,aAAqB,EACrB,aAAqB,EACrB,aAAkC,EAClC,KAAa,EACb,SAAc,EACd,OAAY,EACU,EAAE;IACxB,MAAM,IAAI,GAAuB,EAAC,KAAK,EAAC,CAAC;IACzC,IAAI,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACjD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC;IACD,MAAM,cAAc,GAAG,MAAM,eAAe,CAAyB,aAAa,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;IAElH,IAAI,cAAc,CAAC,KAAK,EAAE,CAAC;QACvB,OAAO,cAAc,CAAC;IAC1B,CAAC;SAAM,CAAC;QACJ,OAAO;YACH,qCAAqC;YACrC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC;SAC1C,CAAC;IACN,CAAC;AACL,CAAC,CAAA,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchContentPathsForAllLocales.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"fetchContentPathsForAllLocales.js","sourceRoot":"","sources":["../src/guillotine/fetchContentPathsForAllLocales.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,EAAC,sBAAsB,EAAC,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAC,uBAAuB,EAAC,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAC,0BAA0B,EAAC,MAAM,8BAA8B,CAAC;AAGxE,MAAM,UAAgB,8BAA8B,CAChD,IAAY,EACZ,QAAgB,sBAAsB,EACtC,cAAc,GAAG,GAAG;;QAEpB,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,uBAAuB,EAAE,CAAC,CAAC,GAAG,CACzD,MAAM,CAAC,EAAE,CAAC,0BAA0B,CAChC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,CACtC,CACJ,CAAC;QACF,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;YACxC,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,WAAW,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,EAAE,CAAC,CAAC;QAC7E,CAAC,CAAC,CAAC;IACP,CAAC;CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchContentPathsForLocale.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"fetchContentPathsForLocale.js","sourceRoot":"","sources":["../src/guillotine/fetchContentPathsForLocale.ts"],"names":[],"mappings":";;;;;;;;;AAGA,OAAO,EAAC,sBAAsB,EAAC,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAGlD,MAAM,UAAgB,0BAA0B,CAC5C,IAAY,EACZ,MAA2B,EAC3B,QAAgB,sBAAsB,EACtC,KAAK,GAAG,GAAG;;QAEX,MAAM,aAAa,GAAG,gBAAgB,CAAC;YACnC,WAAW,EAAE,IAAI;YACjB,MAAM,EAAE,MAAM,CAAC,MAAM;SACxB,CAAC,CAAC;QACH,MAAM,IAAI,GAAuB;YAC7B,KAAK;YACL,SAAS,EAAE;gBACP,IAAI;gBACJ,KAAK;aACR;SACJ,CAAC;QACF,OAAO,eAAe,CAAoB,aAAa,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,CACxE,OAAyB,EAC3B,EAAE;YACA,OAAO,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,CACtC,IAAuB,EACvB,KAAU,EACZ,EAAE;;gBACA,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,KAAK,CAAA,MAAA,KAAK,CAAC,IAAI,0CAAE,KAAK,EAAC,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBACnF,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;gBACpD,IAAI,CAAC,IAAI,CAAC;oBACN,WAAW,EAAE,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC;oBACnC,MAAM,EAAE,MAAM,CAAC,MAAM;iBACxB,CAAC,CAAC;gBACH,OAAO,IAAI,CAAC;YAChB,CAAC,EAAE,EAAE,CAAC,CAAC;QACX,CAAC,CAAC,CAAC;IACP,CAAC;CAAA"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ContentApiBaseBody, GuillotineResponseJson, ProjectLocaleConfig } from '../types';
|
|
2
2
|
/** Generic fetch */
|
|
3
|
-
export declare
|
|
3
|
+
export declare function fetchFromApi<Data = Record<string, unknown>>(apiUrl: string, body: ContentApiBaseBody, projectConfig: ProjectLocaleConfig, headers?: {}, method?: string): Promise<GuillotineResponseJson<Data>>;
|
|
@@ -8,58 +8,60 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
/** Generic fetch */
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
11
|
+
export function fetchFromApi(apiUrl, body, projectConfig, headers, method = 'POST') {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
const options = {
|
|
14
|
+
method,
|
|
15
|
+
headers: {
|
|
16
|
+
'Accept': 'application/json',
|
|
17
|
+
'Content-Type': 'application/json',
|
|
18
|
+
'X-Guillotine-SiteKey': projectConfig.site,
|
|
19
|
+
},
|
|
20
|
+
body: JSON.stringify(body),
|
|
21
|
+
};
|
|
22
|
+
if (headers) {
|
|
23
|
+
Object.assign(options.headers, headers);
|
|
24
|
+
}
|
|
25
|
+
let res;
|
|
26
|
+
try {
|
|
27
|
+
res = yield fetch(apiUrl, options);
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
console.warn(apiUrl, e);
|
|
31
|
+
throw new Error(JSON.stringify({
|
|
32
|
+
code: 'API',
|
|
33
|
+
message: e.message,
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
if (!res.ok) {
|
|
37
|
+
throw new Error(JSON.stringify({
|
|
38
|
+
code: res.status,
|
|
39
|
+
message: `Data fetching failed (message: '${yield res.text()}')`,
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
let json;
|
|
43
|
+
try {
|
|
44
|
+
json = yield res.json();
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
throw new Error(JSON.stringify({
|
|
48
|
+
code: 500,
|
|
49
|
+
message: `API call completed but with non-JSON data: ${JSON.stringify(yield res.text())}`,
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
if (!json) {
|
|
53
|
+
throw new Error(JSON.stringify({
|
|
54
|
+
code: 500,
|
|
55
|
+
message: `API call completed but with unexpectedly empty data: ${JSON.stringify(yield res.text())}`,
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
if (Array.isArray(json)) {
|
|
59
|
+
throw new Error(JSON.stringify({
|
|
60
|
+
code: 500,
|
|
61
|
+
message: `API call completed but with unexpected array data: ${JSON.stringify(json)}`,
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
return json;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
65
67
|
//# sourceMappingURL=fetchFromApi.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchFromApi.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"fetchFromApi.js","sourceRoot":"","sources":["../src/guillotine/fetchFromApi.ts"],"names":[],"mappings":";;;;;;;;;AAGA,oBAAoB;AACpB,MAAM,UAAgB,YAAY,CAC9B,MAAc,EACd,IAAwB,EACxB,aAAkC,EAClC,OAAY,EACZ,MAAM,GAAG,MAAM;;QAEf,MAAM,OAAO,GAAG;YACZ,MAAM;YACN,OAAO,EAAE;gBACL,QAAQ,EAAE,kBAAkB;gBAC5B,cAAc,EAAE,kBAAkB;gBAClC,sBAAsB,EAAE,aAAa,CAAC,IAAI;aAC7C;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC7B,CAAC;QAEF,IAAI,OAAO,EAAE,CAAC;YACV,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC5C,CAAC;QAED,IAAI,GAA6B,CAAC;QAClC,IAAI,CAAC;YACD,GAAG,GAAG,MAAM,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACvC,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YACd,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;gBAC3B,IAAI,EAAE,KAAK;gBACX,OAAO,EAAE,CAAC,CAAC,OAAO;aACrB,CAAC,CAAC,CAAC;QACR,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;gBAC3B,IAAI,EAAE,GAAG,CAAC,MAAM;gBAChB,OAAO,EAAE,mCAAmC,MAAM,GAAG,CAAC,IAAI,EAAE,IAAI;aACnE,CAAC,CAAC,CAAC;QACR,CAAC;QAED,IAAI,IAAkC,CAAC;QACvC,IAAI,CAAC;YACD,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QAC5B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;gBAC3B,IAAI,EAAE,GAAG;gBACT,OAAO,EAAE,8CAA8C,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE;aAC5F,CAAC,CAAC,CAAC;QACR,CAAC;QAED,IAAI,CAAC,IAAI,EAAE,CAAC;YACR,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;gBAC3B,IAAI,EAAE,GAAG;gBACT,OAAO,EAAE,wDAAwD,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE;aACtG,CAAC,CAAC,CAAC;QACR,CAAC;QAED,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;gBAC3B,IAAI,EAAE,GAAG;gBACT,OAAO,EAAE,sDAAsD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;aACxF,CAAC,CAAC,CAAC;QACR,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;CAAA"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ContentApiBaseBody, GuillotineResult, ProjectLocaleConfig } from '../types';
|
|
2
2
|
/** Guillotine-specialized fetch, using the generic fetch above */
|
|
3
|
-
export declare
|
|
3
|
+
export declare function fetchGuillotine<Data = Record<string, unknown>>(contentApiUrl: string, body: ContentApiBaseBody, projectConfig: ProjectLocaleConfig, headers?: {}): Promise<GuillotineResult>;
|