@sitecore-content-sdk/nextjs 0.1.0-beta.8 → 0.1.0-canary.0
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/README.md +5 -4
- package/client.d.ts +1 -0
- package/client.js +1 -0
- package/component-props-loader.d.ts +1 -0
- package/component-props-loader.js +3 -0
- package/dist/cjs/client/index.js +10 -0
- package/dist/cjs/client/sitecore-nextjs-client.js +117 -0
- package/dist/cjs/components/RichText.js +16 -4
- package/dist/cjs/config/define-cli-config.js +30 -0
- package/dist/cjs/config/index.js +3 -1
- package/dist/cjs/editing/editing-config-middleware.js +1 -3
- package/dist/cjs/editing/editing-render-middleware.js +13 -9
- package/dist/cjs/editing/index.js +2 -2
- package/dist/cjs/index.js +16 -18
- package/dist/cjs/middleware/index.js +3 -1
- package/dist/cjs/middleware/middleware.js +23 -12
- package/dist/cjs/middleware/multisite-middleware.js +19 -8
- package/dist/cjs/middleware/personalize-middleware.js +3 -3
- package/dist/cjs/middleware/redirects-middleware.js +28 -13
- package/dist/cjs/middleware/sitemap-middleware.js +47 -0
- package/dist/cjs/services/component-props-service.js +41 -50
- package/dist/cjs/tools/component-props.loader.js +101 -0
- package/dist/cjs/tools/index.js +9 -0
- package/dist/cjs/tools/templating/byoc-component.js +75 -0
- package/dist/cjs/tools/templating/constants.js +7 -0
- package/dist/cjs/tools/templating/default-component.js +54 -0
- package/dist/cjs/tools/templating/utils.js +18 -0
- package/dist/cjs/utils/index.js +2 -1
- package/dist/cjs/utils/utils.js +10 -1
- package/dist/esm/client/index.js +2 -0
- package/dist/esm/client/sitecore-nextjs-client.js +113 -0
- package/dist/esm/components/RichText.js +14 -2
- package/dist/esm/config/define-cli-config.js +26 -0
- package/dist/esm/config/index.js +1 -0
- package/dist/esm/editing/editing-config-middleware.js +1 -3
- package/dist/esm/editing/editing-render-middleware.js +11 -7
- package/dist/esm/editing/index.js +1 -1
- package/dist/esm/index.js +3 -5
- package/dist/esm/middleware/index.js +1 -0
- package/dist/esm/middleware/middleware.js +23 -12
- package/dist/esm/middleware/multisite-middleware.js +20 -9
- package/dist/esm/middleware/personalize-middleware.js +4 -4
- package/dist/esm/middleware/redirects-middleware.js +29 -14
- package/dist/esm/middleware/sitemap-middleware.js +43 -0
- package/dist/esm/services/component-props-service.js +41 -50
- package/dist/esm/tools/component-props.loader.js +65 -0
- package/dist/esm/tools/index.js +1 -0
- package/dist/esm/tools/templating/byoc-component.js +69 -0
- package/dist/esm/tools/templating/constants.js +4 -0
- package/dist/esm/tools/templating/default-component.js +48 -0
- package/dist/esm/tools/templating/utils.js +12 -0
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/utils/utils.js +8 -0
- package/package.json +16 -13
- package/tools.d.ts +1 -0
- package/tools.js +1 -0
- package/types/client/index.d.ts +2 -0
- package/types/client/sitecore-nextjs-client.d.ts +44 -0
- package/types/components/RichText.d.ts +7 -1
- package/types/config/define-cli-config.d.ts +8 -0
- package/types/config/index.d.ts +1 -0
- package/types/editing/editing-config-middleware.d.ts +4 -2
- package/types/editing/editing-render-middleware.d.ts +3 -31
- package/types/editing/index.d.ts +1 -1
- package/types/index.d.ts +6 -8
- package/types/middleware/index.d.ts +1 -0
- package/types/middleware/middleware.d.ts +13 -7
- package/types/middleware/sitemap-middleware.d.ts +12 -0
- package/types/services/component-props-service.d.ts +10 -26
- package/types/sharedTypes/component-props.d.ts +18 -0
- package/types/sharedTypes/sitecore-page-props.d.ts +5 -0
- package/types/tools/component-props.loader.d.ts +7 -0
- package/types/tools/index.d.ts +1 -0
- package/types/tools/templating/byoc-component.d.ts +2 -0
- package/types/tools/templating/constants.d.ts +4 -0
- package/types/tools/templating/default-component.d.ts +2 -0
- package/types/tools/templating/utils.d.ts +6 -0
- package/types/utils/index.d.ts +1 -1
- package/types/utils/utils.d.ts +2 -0
- package/dist/cjs/ComponentBuilder.js +0 -63
- package/dist/cjs/graphql/index.js +0 -7
- package/dist/cjs/services/base-graphql-sitemap-service.js +0 -206
- package/dist/cjs/services/graphql-sitemap-service.js +0 -64
- package/dist/cjs/services/mutisite-graphql-sitemap-service.js +0 -81
- package/dist/esm/ComponentBuilder.js +0 -59
- package/dist/esm/graphql/index.js +0 -1
- package/dist/esm/services/base-graphql-sitemap-service.js +0 -201
- package/dist/esm/services/graphql-sitemap-service.js +0 -59
- package/dist/esm/services/mutisite-graphql-sitemap-service.js +0 -77
- package/graphql.d.ts +0 -1
- package/graphql.js +0 -1
- package/types/ComponentBuilder.d.ts +0 -59
- package/types/graphql/index.d.ts +0 -1
- package/types/services/base-graphql-sitemap-service.d.ts +0 -148
- package/types/services/graphql-sitemap-service.d.ts +0 -51
- package/types/services/mutisite-graphql-sitemap-service.d.ts +0 -42
- package/types/sharedTypes/module-factory.d.ts +0 -32
- /package/dist/cjs/sharedTypes/{module-factory.js → sitecore-page-props.js} +0 -0
- /package/dist/esm/sharedTypes/{module-factory.js → sitecore-page-props.js} +0 -0
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Nextjs implementation of component builder class for building components based on the configuration.
|
|
3
|
-
*/
|
|
4
|
-
export class ComponentBuilder {
|
|
5
|
-
constructor(config) {
|
|
6
|
-
this.config = config;
|
|
7
|
-
/**
|
|
8
|
-
* SXA uses custom default export name
|
|
9
|
-
*/
|
|
10
|
-
this.DEFAULT_EXPORT_NAME = 'Default';
|
|
11
|
-
this.components = new Map([...config.components]);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Creates a new instance of module factory
|
|
15
|
-
* Module factory provides a module (file) including all exports.
|
|
16
|
-
* Module can be imported dynamically or statically.
|
|
17
|
-
* @returns {ModuleFactory} Module factory implementation
|
|
18
|
-
*/
|
|
19
|
-
getModuleFactory() {
|
|
20
|
-
return (componentName) => {
|
|
21
|
-
const component = this.components.get(componentName);
|
|
22
|
-
if (!component)
|
|
23
|
-
return null;
|
|
24
|
-
// check if module should be imported dynamically
|
|
25
|
-
if (component.module) {
|
|
26
|
-
return component.module();
|
|
27
|
-
}
|
|
28
|
-
return component;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Creates a new instance of component factory
|
|
33
|
-
* Component can be imported dynamically or statically.
|
|
34
|
-
* @param {object} [config] Component factory configuration
|
|
35
|
-
* @param {boolean} [config.isEditing] Indicates if component factory is used in editing mode
|
|
36
|
-
* @returns {ComponentFactory} Component factory implementation
|
|
37
|
-
*/
|
|
38
|
-
getComponentFactory({ isEditing } = {}) {
|
|
39
|
-
return (componentName, exportName) => {
|
|
40
|
-
const component = this.components.get(componentName);
|
|
41
|
-
if (!component)
|
|
42
|
-
return null;
|
|
43
|
-
// check if component should be imported dynamically
|
|
44
|
-
if (component.element) {
|
|
45
|
-
// Editing mode doesn't work well with dynamic components in nextjs: dynamic components are not displayed without refresh after a rendering is added.
|
|
46
|
-
// This happens beacuse Sitecore editors simply insert updated HTML generated on server side. This conflicts with nextjs dynamic logic as no HTML gets rendered for dynamic component
|
|
47
|
-
// So we use require() to obtain dynamic components in editing mode while preserving dynamic logic for non-editing scenarios
|
|
48
|
-
// As we need to be able to seamlessly work with dynamic components in both editing and normal modes, different componentFactory functions will be passed to app
|
|
49
|
-
return component.element(isEditing);
|
|
50
|
-
}
|
|
51
|
-
if (exportName && exportName !== this.DEFAULT_EXPORT_NAME) {
|
|
52
|
-
return component[exportName];
|
|
53
|
-
}
|
|
54
|
-
return (component.Default ||
|
|
55
|
-
component.default ||
|
|
56
|
-
component);
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { DefaultRetryStrategy, GraphQLRequestClient, getEdgeProxyContentUrl, } from '@sitecore-content-sdk/core/graphql';
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { debug } from '@sitecore-content-sdk/core';
|
|
11
|
-
import { getPersonalizedRewrite } from '@sitecore-content-sdk/core/personalize';
|
|
12
|
-
/** @private */
|
|
13
|
-
export const languageError = 'The list of languages cannot be empty';
|
|
14
|
-
export const siteError = 'The service needs a site name';
|
|
15
|
-
/**
|
|
16
|
-
* @param {string} siteName to inject into error text
|
|
17
|
-
* @private
|
|
18
|
-
*/
|
|
19
|
-
export function getSiteEmptyError(siteName) {
|
|
20
|
-
return `Site "${siteName}" does not exist or site item tree is missing`;
|
|
21
|
-
}
|
|
22
|
-
const languageEmptyError = 'The language must be a non-empty string';
|
|
23
|
-
/**
|
|
24
|
-
* GQL query made dynamic based whether personalization is enabled or not
|
|
25
|
-
* @param {boolean} usesPersonalize flag to detrmine which variation of a query to run
|
|
26
|
-
* @returns GraphQL query to fetch site paths with
|
|
27
|
-
*/
|
|
28
|
-
const defaultQuery = (usesPersonalize) => /* GraphQL */ `
|
|
29
|
-
query ${usesPersonalize ? 'PersonalizeSitemapQuery' : 'DefaultSitemapQuery'}(
|
|
30
|
-
$siteName: String!
|
|
31
|
-
$language: String!
|
|
32
|
-
$includedPaths: [String]
|
|
33
|
-
$excludedPaths: [String]
|
|
34
|
-
$pageSize: Int = 100
|
|
35
|
-
$after: String
|
|
36
|
-
) {
|
|
37
|
-
site {
|
|
38
|
-
siteInfo(site: $siteName) {
|
|
39
|
-
routes(
|
|
40
|
-
language: $language
|
|
41
|
-
includedPaths: $includedPaths
|
|
42
|
-
excludedPaths: $excludedPaths
|
|
43
|
-
first: $pageSize
|
|
44
|
-
after: $after
|
|
45
|
-
){
|
|
46
|
-
total
|
|
47
|
-
pageInfo {
|
|
48
|
-
endCursor
|
|
49
|
-
hasNext
|
|
50
|
-
}
|
|
51
|
-
results {
|
|
52
|
-
path: routePath
|
|
53
|
-
${usesPersonalize
|
|
54
|
-
? `
|
|
55
|
-
route {
|
|
56
|
-
personalization {
|
|
57
|
-
variantIds
|
|
58
|
-
}
|
|
59
|
-
}`
|
|
60
|
-
: ''}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
`;
|
|
67
|
-
/**
|
|
68
|
-
* Service that fetches the list of site pages using Sitecore's GraphQL API.
|
|
69
|
-
* Used to handle a single site
|
|
70
|
-
* This list is used for SSG and Export functionality.
|
|
71
|
-
* @mixes SearchQueryService<PageListQueryResult>
|
|
72
|
-
*/
|
|
73
|
-
export class BaseGraphQLSitemapService {
|
|
74
|
-
/**
|
|
75
|
-
* Creates an instance of graphQL sitemap service with the provided options
|
|
76
|
-
* @param {GraphQLSitemapServiceConfig} options instance
|
|
77
|
-
*/
|
|
78
|
-
constructor(options) {
|
|
79
|
-
this.options = options;
|
|
80
|
-
this._graphQLClient = this.getGraphQLClient();
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* GraphQL client accessible by descendant classes when needed
|
|
84
|
-
*/
|
|
85
|
-
get graphQLClient() {
|
|
86
|
-
return this._graphQLClient;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Gets the default query used for fetching the list of site pages
|
|
90
|
-
*/
|
|
91
|
-
get query() {
|
|
92
|
-
return defaultQuery(this.options.includePersonalizedRoutes);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Fetch sitemap which could be used for generation of static pages during `next export`.
|
|
96
|
-
* The `locale` parameter will be used in the item query, but since i18n is not supported,
|
|
97
|
-
* the output paths will not include a `language` property.
|
|
98
|
-
* @param {string} locale which application supports
|
|
99
|
-
* @returns an array of @see StaticPath objects
|
|
100
|
-
*/
|
|
101
|
-
fetchExportSitemap(locale) {
|
|
102
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
-
const formatPath = (path) => ({
|
|
104
|
-
params: {
|
|
105
|
-
path,
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
return this.fetchSitemap([locale], formatPath);
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Fetch sitemap which could be used for generation of static pages using SSG mode
|
|
113
|
-
* @param {string[]} locales locales which application supports
|
|
114
|
-
* @returns an array of @see StaticPath objects
|
|
115
|
-
*/
|
|
116
|
-
fetchSSGSitemap(locales) {
|
|
117
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
-
const formatPath = (path, locale) => ({
|
|
119
|
-
params: {
|
|
120
|
-
path,
|
|
121
|
-
},
|
|
122
|
-
locale,
|
|
123
|
-
});
|
|
124
|
-
return this.fetchSitemap(locales, formatPath);
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
getTranformedPaths(siteName, languages, formatStaticPath) {
|
|
128
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
-
const paths = new Array();
|
|
130
|
-
for (const language of languages) {
|
|
131
|
-
if (language === '') {
|
|
132
|
-
throw new RangeError(languageEmptyError);
|
|
133
|
-
}
|
|
134
|
-
debug.sitemap('fetching sitemap data for %s %s', language, siteName);
|
|
135
|
-
const results = yield this.fetchLanguageSitePaths(language, siteName);
|
|
136
|
-
const transformedPaths = yield this.transformLanguageSitePaths(results, formatStaticPath, language);
|
|
137
|
-
paths.push(...transformedPaths);
|
|
138
|
-
}
|
|
139
|
-
return paths;
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
transformLanguageSitePaths(sitePaths, formatStaticPath, language) {
|
|
143
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
-
const formatPath = (path) => formatStaticPath(path.replace(/^\/|\/$/g, '').split('/'), language);
|
|
145
|
-
const aggregatedPaths = [];
|
|
146
|
-
sitePaths.forEach((item) => {
|
|
147
|
-
var _a, _b, _c;
|
|
148
|
-
if (!item)
|
|
149
|
-
return;
|
|
150
|
-
aggregatedPaths.push(formatPath(item.path));
|
|
151
|
-
const variantIds = (_c = (_b = (_a = item.route) === null || _a === void 0 ? void 0 : _a.personalization) === null || _b === void 0 ? void 0 : _b.variantIds) === null || _c === void 0 ? void 0 : _c.filter((variantId) => !variantId.includes('_') // exclude component A/B test variants
|
|
152
|
-
);
|
|
153
|
-
if (variantIds === null || variantIds === void 0 ? void 0 : variantIds.length) {
|
|
154
|
-
aggregatedPaths.push(...variantIds.map((varId) => formatPath(getPersonalizedRewrite(item.path, [varId]))));
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
return aggregatedPaths;
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
fetchLanguageSitePaths(language, siteName) {
|
|
161
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
-
var _a, _b, _c, _d;
|
|
163
|
-
const args = {
|
|
164
|
-
siteName: siteName,
|
|
165
|
-
language: language,
|
|
166
|
-
pageSize: this.options.pageSize,
|
|
167
|
-
includedPaths: this.options.includedPaths,
|
|
168
|
-
excludedPaths: this.options.excludedPaths,
|
|
169
|
-
};
|
|
170
|
-
let results = [];
|
|
171
|
-
let hasNext = true;
|
|
172
|
-
let after = '';
|
|
173
|
-
while (hasNext) {
|
|
174
|
-
const fetchResponse = yield this.graphQLClient.request(this.query, Object.assign(Object.assign({}, args), { after }));
|
|
175
|
-
if (!((_a = fetchResponse === null || fetchResponse === void 0 ? void 0 : fetchResponse.site) === null || _a === void 0 ? void 0 : _a.siteInfo)) {
|
|
176
|
-
throw new RangeError(getSiteEmptyError(siteName));
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
results = results.concat((_b = fetchResponse.site.siteInfo.routes) === null || _b === void 0 ? void 0 : _b.results);
|
|
180
|
-
hasNext = (_c = fetchResponse.site.siteInfo.routes) === null || _c === void 0 ? void 0 : _c.pageInfo.hasNext;
|
|
181
|
-
after = (_d = fetchResponse.site.siteInfo.routes) === null || _d === void 0 ? void 0 : _d.pageInfo.endCursor;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return results;
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
|
|
189
|
-
* library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
|
|
190
|
-
* want to use something else.
|
|
191
|
-
* @returns {GraphQLClient} implementation
|
|
192
|
-
*/
|
|
193
|
-
getGraphQLClient() {
|
|
194
|
-
if (!this.options.clientFactory) {
|
|
195
|
-
throw new Error('clientFactory needs to be provided when initializing GraphQL client.');
|
|
196
|
-
}
|
|
197
|
-
return this.options.clientFactory({
|
|
198
|
-
debugger: debug.sitemap,
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { BaseGraphQLSitemapService, } from './base-graphql-sitemap-service';
|
|
11
|
-
/** @private */
|
|
12
|
-
export const languageError = 'The list of languages cannot be empty';
|
|
13
|
-
export const siteError = 'The service needs a site name';
|
|
14
|
-
/**
|
|
15
|
-
* @param {string} siteName to inject into error text
|
|
16
|
-
* @private
|
|
17
|
-
*/
|
|
18
|
-
export function getSiteEmptyError(siteName) {
|
|
19
|
-
return `Site "${siteName}" does not exist or site item tree is missing`;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Service that fetches the list of site pages using Sitecore's GraphQL API.
|
|
23
|
-
* Used to handle a single site
|
|
24
|
-
* This list is used for SSG and Export functionality.
|
|
25
|
-
* @mixes SearchQueryService<PageListQueryResult>
|
|
26
|
-
*/
|
|
27
|
-
export class GraphQLSitemapService extends BaseGraphQLSitemapService {
|
|
28
|
-
/**
|
|
29
|
-
* Creates an instance of graphQL sitemap service with the provided options
|
|
30
|
-
* @param {GraphQLSitemapServiceConfig} options instance
|
|
31
|
-
*/
|
|
32
|
-
constructor(options) {
|
|
33
|
-
super(options);
|
|
34
|
-
this.options = options;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Fetch a flat list of all pages that belong to the specificed site and have a
|
|
38
|
-
* version in the specified language(s).
|
|
39
|
-
* @param {string[]} languages Fetch pages that have versions in this language(s).
|
|
40
|
-
* @param {Function} formatStaticPath Function for transforming the raw search results into (@see StaticPath) types.
|
|
41
|
-
* @returns list of pages
|
|
42
|
-
* @throws {RangeError} if the list of languages is empty.
|
|
43
|
-
* @throws {RangeError} if the any of the languages is an empty string.
|
|
44
|
-
*/
|
|
45
|
-
fetchSitemap(languages, formatStaticPath) {
|
|
46
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
const paths = new Array();
|
|
48
|
-
if (!languages.length) {
|
|
49
|
-
throw new RangeError(languageError);
|
|
50
|
-
}
|
|
51
|
-
const siteName = this.options.siteName;
|
|
52
|
-
if (!siteName) {
|
|
53
|
-
throw new RangeError(siteError);
|
|
54
|
-
}
|
|
55
|
-
paths.push(...(yield this.getTranformedPaths(siteName, languages, formatStaticPath)));
|
|
56
|
-
return [].concat(...paths);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { getSiteRewrite } from '@sitecore-content-sdk/core/site';
|
|
11
|
-
import { BaseGraphQLSitemapService, languageError, } from './base-graphql-sitemap-service';
|
|
12
|
-
export const sitesError = 'The list of sites cannot be empty';
|
|
13
|
-
/**
|
|
14
|
-
* Service that fetches the list of site pages using Sitecore's GraphQL API.
|
|
15
|
-
* Used to handle multiple sites
|
|
16
|
-
* This list is used for SSG and Export functionality.
|
|
17
|
-
* @mixes SearchQueryService<PageListQueryResult>
|
|
18
|
-
*/
|
|
19
|
-
export class MultisiteGraphQLSitemapService extends BaseGraphQLSitemapService {
|
|
20
|
-
/**
|
|
21
|
-
* Creates an instance of graphQL sitemap service with the provided options
|
|
22
|
-
* @param {MultisiteGraphQLSitemapServiceConfig} options instance
|
|
23
|
-
*/
|
|
24
|
-
constructor(options) {
|
|
25
|
-
super(options);
|
|
26
|
-
this.options = options;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Fetch a flat list of all pages that belong to all the requested sites and have a
|
|
30
|
-
* version in the specified language(s).
|
|
31
|
-
* @param {string[]} languages Fetch pages that have versions in this language(s).
|
|
32
|
-
* @param {Function} formatStaticPath Function for transforming the raw search results into (@see StaticPath) types.
|
|
33
|
-
* @returns list of pages
|
|
34
|
-
* @throws {RangeError} if the list of languages is empty.
|
|
35
|
-
* @throws {RangeError} if the any of the languages is an empty string.
|
|
36
|
-
*/
|
|
37
|
-
fetchSitemap(languages, formatStaticPath) {
|
|
38
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
const paths = new Array();
|
|
40
|
-
if (!languages.length) {
|
|
41
|
-
throw new RangeError(languageError);
|
|
42
|
-
}
|
|
43
|
-
// Get all sites
|
|
44
|
-
const sites = this.options.sites;
|
|
45
|
-
if (!sites || !sites.length) {
|
|
46
|
-
throw new RangeError(sitesError);
|
|
47
|
-
}
|
|
48
|
-
// Fetch paths for each site
|
|
49
|
-
for (let i = 0; i < sites.length; i++) {
|
|
50
|
-
const siteName = sites[i];
|
|
51
|
-
// Fetch paths using all locales
|
|
52
|
-
paths.push(...(yield this.getTranformedPaths(siteName, languages, formatStaticPath)));
|
|
53
|
-
}
|
|
54
|
-
return [].concat(...paths);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Fetch and return site paths for multisite implementation, with prefixes included
|
|
59
|
-
* @param {string} language path language
|
|
60
|
-
* @param {string} siteName site name
|
|
61
|
-
* @returns modified paths
|
|
62
|
-
*/
|
|
63
|
-
fetchLanguageSitePaths(language, siteName) {
|
|
64
|
-
const _super = Object.create(null, {
|
|
65
|
-
fetchLanguageSitePaths: { get: () => super.fetchLanguageSitePaths }
|
|
66
|
-
});
|
|
67
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
const results = yield _super.fetchLanguageSitePaths.call(this, language, siteName);
|
|
69
|
-
results.forEach((item) => {
|
|
70
|
-
if (item) {
|
|
71
|
-
item.path = getSiteRewrite(item.path, { siteName: siteName });
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
return results;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}
|
package/graphql.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './types/graphql/index';
|
package/graphql.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('./dist/cjs/graphql/index');
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { ComponentFactory, JssComponentType } from '@sitecore-content-sdk/react';
|
|
2
|
-
import { Module, ModuleFactory } from './sharedTypes/module-factory';
|
|
3
|
-
/**
|
|
4
|
-
* Represents a component that can be imported dynamically
|
|
5
|
-
*/
|
|
6
|
-
export type LazyModule = {
|
|
7
|
-
module: () => Promise<Module>;
|
|
8
|
-
element: (isEditing?: boolean) => JssComponentType;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Component is a module or a lazy module
|
|
12
|
-
*/
|
|
13
|
-
type Component = Module | LazyModule | JssComponentType;
|
|
14
|
-
/**
|
|
15
|
-
* Configuration for ComponentBuilder
|
|
16
|
-
*/
|
|
17
|
-
export type ComponentBuilderConfig<Component> = {
|
|
18
|
-
/**
|
|
19
|
-
* List of components to be stored
|
|
20
|
-
*/
|
|
21
|
-
components: Map<string, Component>;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Configuration for ComponentFactory
|
|
25
|
-
*/
|
|
26
|
-
type ComponentFactoryConfig = {
|
|
27
|
-
isEditing?: boolean;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Nextjs implementation of component builder class for building components based on the configuration.
|
|
31
|
-
*/
|
|
32
|
-
export declare class ComponentBuilder {
|
|
33
|
-
protected config: ComponentBuilderConfig<Component>;
|
|
34
|
-
/**
|
|
35
|
-
* List of components to be stored
|
|
36
|
-
*/
|
|
37
|
-
protected components: Map<string, Component>;
|
|
38
|
-
/**
|
|
39
|
-
* SXA uses custom default export name
|
|
40
|
-
*/
|
|
41
|
-
protected DEFAULT_EXPORT_NAME: string;
|
|
42
|
-
constructor(config: ComponentBuilderConfig<Component>);
|
|
43
|
-
/**
|
|
44
|
-
* Creates a new instance of module factory
|
|
45
|
-
* Module factory provides a module (file) including all exports.
|
|
46
|
-
* Module can be imported dynamically or statically.
|
|
47
|
-
* @returns {ModuleFactory} Module factory implementation
|
|
48
|
-
*/
|
|
49
|
-
getModuleFactory(): ModuleFactory;
|
|
50
|
-
/**
|
|
51
|
-
* Creates a new instance of component factory
|
|
52
|
-
* Component can be imported dynamically or statically.
|
|
53
|
-
* @param {object} [config] Component factory configuration
|
|
54
|
-
* @param {boolean} [config.isEditing] Indicates if component factory is used in editing mode
|
|
55
|
-
* @returns {ComponentFactory} Component factory implementation
|
|
56
|
-
*/
|
|
57
|
-
getComponentFactory({ isEditing }?: ComponentFactoryConfig): ComponentFactory;
|
|
58
|
-
}
|
|
59
|
-
export {};
|
package/types/graphql/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { GraphQLClientError, RetryStrategy, DefaultRetryStrategy, GraphQLRequestClient, GraphQLRequestClientFactory, GraphQLRequestClientFactoryConfig, getEdgeProxyContentUrl, } from '@sitecore-content-sdk/core/graphql';
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { GraphQLClient, GraphQLRequestClientFactory, PageInfo } from '@sitecore-content-sdk/core/graphql';
|
|
2
|
-
/** @private */
|
|
3
|
-
export declare const languageError = "The list of languages cannot be empty";
|
|
4
|
-
export declare const siteError = "The service needs a site name";
|
|
5
|
-
/**
|
|
6
|
-
* @param {string} siteName to inject into error text
|
|
7
|
-
* @private
|
|
8
|
-
*/
|
|
9
|
-
export declare function getSiteEmptyError(siteName: string): string;
|
|
10
|
-
/**
|
|
11
|
-
* type for input variables for the site routes query
|
|
12
|
-
*/
|
|
13
|
-
interface SiteRouteQueryVariables {
|
|
14
|
-
/**
|
|
15
|
-
* Required. The name of the site being queried.
|
|
16
|
-
*/
|
|
17
|
-
siteName: string;
|
|
18
|
-
/**
|
|
19
|
-
* Required. The language to return routes/pages for.
|
|
20
|
-
*/
|
|
21
|
-
language: string;
|
|
22
|
-
/**
|
|
23
|
-
* Optional. Only paths starting with these provided prefixes will be returned.
|
|
24
|
-
*/
|
|
25
|
-
includedPaths?: string[];
|
|
26
|
-
/**
|
|
27
|
-
* Optional. Paths starting with these provided prefixes will be excluded from returned results.
|
|
28
|
-
*/
|
|
29
|
-
excludedPaths?: string[];
|
|
30
|
-
/**
|
|
31
|
-
* common variable for all GraphQL queries
|
|
32
|
-
* it will be used for every type of query to regulate result batch size
|
|
33
|
-
* Optional. How many result items to fetch in each GraphQL call. This is needed for pagination.
|
|
34
|
-
* @default 100
|
|
35
|
-
*/
|
|
36
|
-
pageSize?: number;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Schema of data returned in response to a "site" query request
|
|
40
|
-
* @template T The type of objects being requested.
|
|
41
|
-
*/
|
|
42
|
-
export interface SiteRouteQueryResult<T> {
|
|
43
|
-
site: {
|
|
44
|
-
siteInfo: {
|
|
45
|
-
routes: {
|
|
46
|
-
/**
|
|
47
|
-
* Data needed to paginate the site results
|
|
48
|
-
*/
|
|
49
|
-
pageInfo: PageInfo;
|
|
50
|
-
results: T[];
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* The schema of data returned in response to a routes list query request
|
|
57
|
-
*/
|
|
58
|
-
export type RouteListQueryResult = {
|
|
59
|
-
path: string;
|
|
60
|
-
route?: {
|
|
61
|
-
personalization?: {
|
|
62
|
-
variantIds: string[];
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* Configuration options for @see GraphQLSitemapService instances
|
|
68
|
-
*/
|
|
69
|
-
export interface BaseGraphQLSitemapServiceConfig extends Omit<SiteRouteQueryVariables, 'language' | 'siteName'> {
|
|
70
|
-
/**
|
|
71
|
-
* A flag for whether to include personalized routes in service output.
|
|
72
|
-
* Only works on XM Cloud for pages using Embedded Personalization (not Component A/B testing).
|
|
73
|
-
* Turned off by default.
|
|
74
|
-
*/
|
|
75
|
-
includePersonalizedRoutes?: boolean;
|
|
76
|
-
/**
|
|
77
|
-
* A GraphQL Request Client Factory is a function that accepts configuration and returns an instance of a GraphQLRequestClient.
|
|
78
|
-
* This factory function is used to create and configure GraphQL clients for making GraphQL API requests.
|
|
79
|
-
*/
|
|
80
|
-
clientFactory: GraphQLRequestClientFactory;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Object model of a site page item.
|
|
84
|
-
*/
|
|
85
|
-
export type StaticPath = {
|
|
86
|
-
params: {
|
|
87
|
-
path: string[];
|
|
88
|
-
};
|
|
89
|
-
locale?: string;
|
|
90
|
-
};
|
|
91
|
-
/**
|
|
92
|
-
* Service that fetches the list of site pages using Sitecore's GraphQL API.
|
|
93
|
-
* Used to handle a single site
|
|
94
|
-
* This list is used for SSG and Export functionality.
|
|
95
|
-
* @mixes SearchQueryService<PageListQueryResult>
|
|
96
|
-
*/
|
|
97
|
-
export declare abstract class BaseGraphQLSitemapService {
|
|
98
|
-
options: BaseGraphQLSitemapServiceConfig;
|
|
99
|
-
private _graphQLClient;
|
|
100
|
-
/**
|
|
101
|
-
* Creates an instance of graphQL sitemap service with the provided options
|
|
102
|
-
* @param {GraphQLSitemapServiceConfig} options instance
|
|
103
|
-
*/
|
|
104
|
-
constructor(options: BaseGraphQLSitemapServiceConfig);
|
|
105
|
-
/**
|
|
106
|
-
* GraphQL client accessible by descendant classes when needed
|
|
107
|
-
*/
|
|
108
|
-
protected get graphQLClient(): GraphQLClient;
|
|
109
|
-
/**
|
|
110
|
-
* Gets the default query used for fetching the list of site pages
|
|
111
|
-
*/
|
|
112
|
-
protected get query(): string;
|
|
113
|
-
/**
|
|
114
|
-
* Fetch sitemap which could be used for generation of static pages during `next export`.
|
|
115
|
-
* The `locale` parameter will be used in the item query, but since i18n is not supported,
|
|
116
|
-
* the output paths will not include a `language` property.
|
|
117
|
-
* @param {string} locale which application supports
|
|
118
|
-
* @returns an array of @see StaticPath objects
|
|
119
|
-
*/
|
|
120
|
-
fetchExportSitemap(locale: string): Promise<StaticPath[]>;
|
|
121
|
-
/**
|
|
122
|
-
* Fetch sitemap which could be used for generation of static pages using SSG mode
|
|
123
|
-
* @param {string[]} locales locales which application supports
|
|
124
|
-
* @returns an array of @see StaticPath objects
|
|
125
|
-
*/
|
|
126
|
-
fetchSSGSitemap(locales: string[]): Promise<StaticPath[]>;
|
|
127
|
-
protected getTranformedPaths(siteName: string, languages: string[], formatStaticPath: (path: string[], language: string) => StaticPath): Promise<StaticPath[]>;
|
|
128
|
-
protected transformLanguageSitePaths(sitePaths: RouteListQueryResult[], formatStaticPath: (path: string[], language: string) => StaticPath, language: string): Promise<StaticPath[]>;
|
|
129
|
-
protected fetchLanguageSitePaths(language: string, siteName: string): Promise<RouteListQueryResult[]>;
|
|
130
|
-
/**
|
|
131
|
-
* Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
|
|
132
|
-
* library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
|
|
133
|
-
* want to use something else.
|
|
134
|
-
* @returns {GraphQLClient} implementation
|
|
135
|
-
*/
|
|
136
|
-
protected getGraphQLClient(): GraphQLClient;
|
|
137
|
-
/**
|
|
138
|
-
* Fetch a flat list of all pages that belong to the specificed site and have a
|
|
139
|
-
* version in the specified language(s).
|
|
140
|
-
* @param {string[]} languages Fetch pages that have versions in this language(s).
|
|
141
|
-
* @param {Function} formatStaticPath Function for transforming the raw search results into (@see StaticPath) types.
|
|
142
|
-
* @returns list of pages
|
|
143
|
-
* @throws {RangeError} if the list of languages is empty.
|
|
144
|
-
* @throws {RangeError} if the any of the languages is an empty string.
|
|
145
|
-
*/
|
|
146
|
-
protected abstract fetchSitemap(languages: string[], formatStaticPath: (path: string[], language: string) => StaticPath): Promise<StaticPath[]>;
|
|
147
|
-
}
|
|
148
|
-
export {};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { BaseGraphQLSitemapService, BaseGraphQLSitemapServiceConfig } from './base-graphql-sitemap-service';
|
|
2
|
-
/** @private */
|
|
3
|
-
export declare const languageError = "The list of languages cannot be empty";
|
|
4
|
-
export declare const siteError = "The service needs a site name";
|
|
5
|
-
/**
|
|
6
|
-
* @param {string} siteName to inject into error text
|
|
7
|
-
* @private
|
|
8
|
-
*/
|
|
9
|
-
export declare function getSiteEmptyError(siteName: string): string;
|
|
10
|
-
/**
|
|
11
|
-
* Configuration options for @see GraphQLSitemapService instances
|
|
12
|
-
*/
|
|
13
|
-
export interface GraphQLSitemapServiceConfig extends BaseGraphQLSitemapServiceConfig {
|
|
14
|
-
/**
|
|
15
|
-
* Name of the site to retrieve site paths for
|
|
16
|
-
*/
|
|
17
|
-
siteName: string;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Object model of a site page item.
|
|
21
|
-
*/
|
|
22
|
-
export type StaticPath = {
|
|
23
|
-
params: {
|
|
24
|
-
path: string[];
|
|
25
|
-
};
|
|
26
|
-
locale?: string;
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Service that fetches the list of site pages using Sitecore's GraphQL API.
|
|
30
|
-
* Used to handle a single site
|
|
31
|
-
* This list is used for SSG and Export functionality.
|
|
32
|
-
* @mixes SearchQueryService<PageListQueryResult>
|
|
33
|
-
*/
|
|
34
|
-
export declare class GraphQLSitemapService extends BaseGraphQLSitemapService {
|
|
35
|
-
options: GraphQLSitemapServiceConfig;
|
|
36
|
-
/**
|
|
37
|
-
* Creates an instance of graphQL sitemap service with the provided options
|
|
38
|
-
* @param {GraphQLSitemapServiceConfig} options instance
|
|
39
|
-
*/
|
|
40
|
-
constructor(options: GraphQLSitemapServiceConfig);
|
|
41
|
-
/**
|
|
42
|
-
* Fetch a flat list of all pages that belong to the specificed site and have a
|
|
43
|
-
* version in the specified language(s).
|
|
44
|
-
* @param {string[]} languages Fetch pages that have versions in this language(s).
|
|
45
|
-
* @param {Function} formatStaticPath Function for transforming the raw search results into (@see StaticPath) types.
|
|
46
|
-
* @returns list of pages
|
|
47
|
-
* @throws {RangeError} if the list of languages is empty.
|
|
48
|
-
* @throws {RangeError} if the any of the languages is an empty string.
|
|
49
|
-
*/
|
|
50
|
-
protected fetchSitemap(languages: string[], formatStaticPath: (path: string[], language: string) => StaticPath): Promise<StaticPath[]>;
|
|
51
|
-
}
|