@sitecore-jss/sitecore-jss
Advanced tools
Comparing version 21.8.0-canary.10 to 21.8.0-canary.14
@@ -31,3 +31,3 @@ "use strict"; | ||
function fetchData(url, fetcher, params = {}) { | ||
return fetcher(utils_1.resolveUrl(url, params)) | ||
return fetcher((0, utils_1.resolveUrl)(url, params)) | ||
.then(checkStatus) | ||
@@ -34,0 +34,0 @@ .then((response) => { |
@@ -14,3 +14,3 @@ "use strict"; | ||
// with a `DEBUG_MULTILINE` environment variable. | ||
if (is_server_1.default() && | ||
if ((0, is_server_1.default)() && | ||
((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.DEBUG_MULTILINE) === 'true' && | ||
@@ -32,13 +32,13 @@ debug_1.default.formatters.o && | ||
exports.default = { | ||
common: debug_1.default(`${rootNamespace}:common`), | ||
http: debug_1.default(`${rootNamespace}:http`), | ||
layout: debug_1.default(`${rootNamespace}:layout`), | ||
dictionary: debug_1.default(`${rootNamespace}:dictionary`), | ||
editing: debug_1.default(`${rootNamespace}:editing`), | ||
sitemap: debug_1.default(`${rootNamespace}:sitemap`), | ||
multisite: debug_1.default(`${rootNamespace}:multisite`), | ||
robots: debug_1.default(`${rootNamespace}:robots`), | ||
redirects: debug_1.default(`${rootNamespace}:redirects`), | ||
personalize: debug_1.default(`${rootNamespace}:personalize`), | ||
errorpages: debug_1.default(`${rootNamespace}:errorpages`), | ||
common: (0, debug_1.default)(`${rootNamespace}:common`), | ||
http: (0, debug_1.default)(`${rootNamespace}:http`), | ||
layout: (0, debug_1.default)(`${rootNamespace}:layout`), | ||
dictionary: (0, debug_1.default)(`${rootNamespace}:dictionary`), | ||
editing: (0, debug_1.default)(`${rootNamespace}:editing`), | ||
sitemap: (0, debug_1.default)(`${rootNamespace}:sitemap`), | ||
multisite: (0, debug_1.default)(`${rootNamespace}:multisite`), | ||
robots: (0, debug_1.default)(`${rootNamespace}:robots`), | ||
redirects: (0, debug_1.default)(`${rootNamespace}:redirects`), | ||
personalize: (0, debug_1.default)(`${rootNamespace}:personalize`), | ||
errorpages: (0, debug_1.default)(`${rootNamespace}:errorpages`), | ||
}; |
@@ -76,3 +76,3 @@ "use strict"; | ||
} | ||
if (!endpoint || !url_parse_1.default(endpoint).hostname) { | ||
if (!endpoint || !(0, url_parse_1.default)(endpoint).hostname) { | ||
throw new Error(`Invalid GraphQL endpoint '${endpoint}'. Verify that 'layoutServiceHost' property in 'scjssconfig.json' file or appropriate environment variable is set`); | ||
@@ -79,0 +79,0 @@ } |
@@ -16,2 +16,3 @@ "use strict"; | ||
exports.GraphQLDictionaryService = exports.queryError = void 0; | ||
const graphql_request_client_1 = require("../graphql-request-client"); | ||
const constants_1 = require("../constants"); | ||
@@ -92,3 +93,3 @@ const dictionary_service_1 = require("./dictionary-service"); | ||
const rootItemId = this.options.rootItemId || | ||
(yield graphql_1.getAppRootId(this.graphQLClient, this.options.siteName, language, this.options.jssAppTemplateId)); | ||
(yield (0, graphql_1.getAppRootId)(this.graphQLClient, this.options.siteName, language, this.options.jssAppTemplateId)); | ||
if (!rootItemId) { | ||
@@ -120,6 +121,14 @@ throw new Error(exports.queryError); | ||
getGraphQLClient() { | ||
if (!this.options.clientFactory) { | ||
throw new Error('clientFactory needs to be provided when initializing GraphQL client.'); | ||
if (!this.options.endpoint) { | ||
if (!this.options.clientFactory) { | ||
throw new Error('You should provide either an endpoint and apiKey, or a clientFactory.'); | ||
} | ||
return this.options.clientFactory({ | ||
debugger: debug_1.default.dictionary, | ||
retries: this.options.retries, | ||
retryStrategy: this.options.retryStrategy, | ||
}); | ||
} | ||
return this.options.clientFactory({ | ||
return new graphql_request_client_1.GraphQLRequestClient(this.options.endpoint, { | ||
apiKey: this.options.apiKey, | ||
debugger: debug_1.default.dictionary, | ||
@@ -126,0 +135,0 @@ retries: this.options.retries, |
@@ -56,3 +56,3 @@ "use strict"; | ||
const fetcher = this.options.dataFetcher || this.defaultFetcher; | ||
const response = yield data_fetcher_1.fetchData(endpoint, fetcher, { | ||
const response = yield (0, data_fetcher_1.fetchData)(endpoint, fetcher, { | ||
sc_apikey: this.options.apiKey, | ||
@@ -59,0 +59,0 @@ }); |
@@ -6,3 +6,7 @@ "use strict"; | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -9,0 +13,0 @@ if (k2 === undefined) k2 = k; |
@@ -20,7 +20,7 @@ "use strict"; | ||
const config = { loadStyles: false }; | ||
exports.traverseComponent(layoutData.sitecore.route, config); | ||
(0, exports.traverseComponent)(layoutData.sitecore.route, config); | ||
if (!config.loadStyles) | ||
return null; | ||
return { | ||
href: exports.getContentStylesheetUrl(sitecoreEdgeContextId, sitecoreEdgeUrl), | ||
href: (0, exports.getContentStylesheetUrl)(sitecoreEdgeContextId, sitecoreEdgeUrl), | ||
rel: 'stylesheet', | ||
@@ -36,3 +36,3 @@ }; | ||
components.forEach((component) => { | ||
exports.traverseComponent(component, config); | ||
(0, exports.traverseComponent)(component, config); | ||
}); | ||
@@ -52,3 +52,3 @@ }; | ||
Object.values(field.fields).forEach((field) => { | ||
exports.traverseField(field, config); | ||
(0, exports.traverseField)(field, config); | ||
}); | ||
@@ -58,3 +58,3 @@ } | ||
field.forEach((field) => { | ||
exports.traverseField(field, config); | ||
(0, exports.traverseField)(field, config); | ||
}); | ||
@@ -69,3 +69,3 @@ } | ||
Object.values(component.fields).forEach((field) => { | ||
exports.traverseField(field, config); | ||
(0, exports.traverseField)(field, config); | ||
}); | ||
@@ -75,5 +75,5 @@ } | ||
Object.keys(placeholders).forEach((placeholder) => { | ||
exports.traversePlaceholder(placeholders[placeholder], config); | ||
(0, exports.traversePlaceholder)(placeholders[placeholder], config); | ||
}); | ||
}; | ||
exports.traverseComponent = traverseComponent; |
@@ -17,2 +17,3 @@ "use strict"; | ||
const layout_service_1 = require("./layout-service"); | ||
const graphql_request_client_1 = require("../graphql-request-client"); | ||
const debug_1 = __importDefault(require("../debug")); | ||
@@ -59,6 +60,14 @@ /** | ||
getGraphQLClient() { | ||
if (!this.serviceConfig.clientFactory) { | ||
throw new Error('clientFactory needs to be provided when initializing GraphQL client.'); | ||
if (!this.serviceConfig.endpoint) { | ||
if (!this.serviceConfig.clientFactory) { | ||
throw new Error('You should provide either an endpoint and apiKey, or a clientFactory.'); | ||
} | ||
return this.serviceConfig.clientFactory({ | ||
debugger: debug_1.default.layout, | ||
retries: this.serviceConfig.retries, | ||
retryStrategy: this.serviceConfig.retryStrategy, | ||
}); | ||
} | ||
return this.serviceConfig.clientFactory({ | ||
return new graphql_request_client_1.GraphQLRequestClient(this.serviceConfig.endpoint, { | ||
apiKey: this.serviceConfig.apiKey, | ||
debugger: debug_1.default.layout, | ||
@@ -65,0 +74,0 @@ retries: this.serviceConfig.retries, |
@@ -72,3 +72,3 @@ "use strict"; | ||
const fetchUrl = this.resolveLayoutServiceUrl('render'); | ||
return data_fetcher_1.fetchData(fetchUrl, fetcher, Object.assign({ item: itemPath }, querystringParams)).catch((error) => { | ||
return (0, data_fetcher_1.fetchData)(fetchUrl, fetcher, Object.assign({ item: itemPath }, querystringParams)).catch((error) => { | ||
var _a; | ||
@@ -111,3 +111,3 @@ if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) { | ||
const fetchUrl = this.resolveLayoutServiceUrl('placeholder'); | ||
return data_fetcher_1.fetchData(fetchUrl, fetcher, Object.assign({ placeholderName, item: itemPath }, querystringParams)); | ||
return (0, data_fetcher_1.fetchData)(fetchUrl, fetcher, Object.assign({ placeholderName, item: itemPath }, querystringParams)); | ||
} | ||
@@ -114,0 +114,0 @@ /** |
@@ -24,3 +24,3 @@ "use strict"; | ||
return [...ids].map((id) => ({ | ||
href: exports.getStylesheetUrl(id, sitecoreEdgeContextId, sitecoreEdgeUrl), | ||
href: (0, exports.getStylesheetUrl)(id, sitecoreEdgeContextId, sitecoreEdgeUrl), | ||
rel: 'stylesheet', | ||
@@ -64,5 +64,5 @@ })); | ||
libraryId = | ||
((_e = _1.getFieldValue(component.fields, 'CSSStyles', '').match(STYLES_LIBRARY_ID_REGEX)) === null || _e === void 0 ? void 0 : _e[1]) || | ||
((_f = _1.getFieldValue(component.fields, 'Styles', '').match(STYLES_LIBRARY_ID_REGEX)) === null || _f === void 0 ? void 0 : _f[1]) || | ||
_1.getFieldValue(component.fields, 'LibraryId', '') || | ||
((_e = (0, _1.getFieldValue)(component.fields, 'CSSStyles', '').match(STYLES_LIBRARY_ID_REGEX)) === null || _e === void 0 ? void 0 : _e[1]) || | ||
((_f = (0, _1.getFieldValue)(component.fields, 'Styles', '').match(STYLES_LIBRARY_ID_REGEX)) === null || _f === void 0 ? void 0 : _f[1]) || | ||
(0, _1.getFieldValue)(component.fields, 'LibraryId', '') || | ||
undefined; | ||
@@ -69,0 +69,0 @@ } |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -30,3 +30,3 @@ "use strict"; | ||
while (match !== null) { | ||
attrs[match[1]] = lodash_unescape_1.default(match[3]); | ||
attrs[match[1]] = (0, lodash_unescape_1.default)(match[3]); | ||
match = htmlAttrsRegex.exec(tagMatch[1]); | ||
@@ -58,3 +58,3 @@ } | ||
const replaceMediaUrlPrefix = (url, mediaUrlPrefix = mediaUrlPrefixRegex) => { | ||
const parsed = url_parse_1.default(url, {}, true); | ||
const parsed = (0, url_parse_1.default)(url, {}, true); | ||
const match = mediaUrlPrefix.exec(parsed.pathname); | ||
@@ -88,4 +88,4 @@ if (match && match.length > 1) { | ||
} | ||
const parsed = url_parse_1.default(exports.replaceMediaUrlPrefix(url, mediaUrlPrefix), {}, true); | ||
const requiredParams = exports.getRequiredParams(parsed.query); | ||
const parsed = (0, url_parse_1.default)((0, exports.replaceMediaUrlPrefix)(url, mediaUrlPrefix), {}, true); | ||
const requiredParams = (0, exports.getRequiredParams)(parsed.query); | ||
const query = Object.assign({}, params); | ||
@@ -126,3 +126,3 @@ Object.entries(requiredParams).forEach(([key, param]) => { | ||
} | ||
return `${exports.updateImageUrl(url, newParams, mediaUrlPrefix)} ${imageWidth}w`; | ||
return `${(0, exports.updateImageUrl)(url, newParams, mediaUrlPrefix)} ${imageWidth}w`; | ||
}) | ||
@@ -129,0 +129,0 @@ .filter((value) => value) |
@@ -16,2 +16,3 @@ "use strict"; | ||
exports.GraphQLPersonalizeService = void 0; | ||
const graphql_request_client_1 = require("../graphql-request-client"); | ||
const debug_1 = __importDefault(require("../debug")); | ||
@@ -70,3 +71,3 @@ const utils_1 = require("../utils"); | ||
catch (error) { | ||
if (utils_1.isTimeoutError(error)) { | ||
if ((0, utils_1.isTimeoutError)(error)) { | ||
return undefined; | ||
@@ -108,6 +109,14 @@ } | ||
getGraphQLClient() { | ||
if (!this.config.clientFactory) { | ||
throw new Error('clientFactory needs to be provided when initializing GraphQL client.'); | ||
if (!this.config.endpoint) { | ||
if (!this.config.clientFactory) { | ||
throw new Error('You should provide either an endpoint and apiKey, or a clientFactory.'); | ||
} | ||
return this.config.clientFactory({ | ||
debugger: debug_1.default.personalize, | ||
fetch: this.config.fetch, | ||
timeout: this.config.timeout, | ||
}); | ||
} | ||
return this.config.clientFactory({ | ||
return new graphql_request_client_1.GraphQLRequestClient(this.config.endpoint, { | ||
apiKey: this.config.apiKey, | ||
debugger: debug_1.default.personalize, | ||
@@ -114,0 +123,0 @@ fetch: this.config.fetch, |
@@ -16,2 +16,3 @@ "use strict"; | ||
exports.GraphQLErrorPagesService = void 0; | ||
const graphql_1 = require("../graphql"); | ||
const constants_1 = require("../constants"); | ||
@@ -80,6 +81,14 @@ const debug_1 = __importDefault(require("../debug")); | ||
getGraphQLClient() { | ||
if (!this.options.clientFactory) { | ||
throw new Error('clientFactory needs to be provided when initializing GraphQL client.'); | ||
if (!this.options.endpoint) { | ||
if (!this.options.clientFactory) { | ||
throw new Error('You should provide either an endpoint and apiKey, or a clientFactory.'); | ||
} | ||
return this.options.clientFactory({ | ||
debugger: debug_1.default.errorpages, | ||
retries: this.options.retries, | ||
retryStrategy: this.options.retryStrategy, | ||
}); | ||
} | ||
return this.options.clientFactory({ | ||
return new graphql_1.GraphQLRequestClient(this.options.endpoint, { | ||
apiKey: this.options.apiKey, | ||
debugger: debug_1.default.errorpages, | ||
@@ -86,0 +95,0 @@ retries: this.options.retries, |
@@ -16,2 +16,3 @@ "use strict"; | ||
exports.GraphQLRedirectsService = exports.REDIRECT_TYPE_SERVER_TRANSFER = exports.REDIRECT_TYPE_302 = exports.REDIRECT_TYPE_301 = void 0; | ||
const graphql_1 = require("../graphql"); | ||
const constants_1 = require("../constants"); | ||
@@ -85,6 +86,13 @@ const debug_1 = __importDefault(require("../debug")); | ||
getGraphQLClient() { | ||
if (!this.options.clientFactory) { | ||
throw new Error('clientFactory needs to be provided when initializing GraphQL client.'); | ||
if (!this.options.endpoint) { | ||
if (!this.options.clientFactory) { | ||
throw new Error('You should provide either an endpoint and apiKey, or a clientFactory.'); | ||
} | ||
return this.options.clientFactory({ | ||
debugger: debug_1.default.redirects, | ||
fetch: this.options.fetch, | ||
}); | ||
} | ||
return this.options.clientFactory({ | ||
return new graphql_1.GraphQLRequestClient(this.options.endpoint, { | ||
apiKey: this.options.apiKey, | ||
debugger: debug_1.default.redirects, | ||
@@ -91,0 +99,0 @@ fetch: this.options.fetch, |
@@ -16,2 +16,3 @@ "use strict"; | ||
exports.GraphQLRobotsService = void 0; | ||
const graphql_1 = require("../graphql"); | ||
const constants_1 = require("../constants"); | ||
@@ -76,6 +77,12 @@ const debug_1 = __importDefault(require("../debug")); | ||
getGraphQLClient() { | ||
if (!this.options.clientFactory) { | ||
throw new Error('clientFactory needs to be provided when initializing GraphQL client.'); | ||
if (!this.options.endpoint) { | ||
if (!this.options.clientFactory) { | ||
throw new Error('You should provide either an endpoint and apiKey, or a clientFactory.'); | ||
} | ||
return this.options.clientFactory({ | ||
debugger: debug_1.default.robots, | ||
}); | ||
} | ||
return this.options.clientFactory({ | ||
return new graphql_1.GraphQLRequestClient(this.options.endpoint, { | ||
apiKey: this.options.apiKey, | ||
debugger: debug_1.default.robots, | ||
@@ -82,0 +89,0 @@ }); |
@@ -16,4 +16,39 @@ "use strict"; | ||
exports.GraphQLSiteInfoService = void 0; | ||
const graphql_1 = require("../graphql"); | ||
const debug_1 = __importDefault(require("../debug")); | ||
const cache_client_1 = require("../cache-client"); | ||
const headlessSiteGroupingTemplate = 'E46F3AF2-39FA-4866-A157-7017C4B2A40C'; | ||
const sitecoreContentRootItem = '0DE95AE4-41AB-4D01-9EB0-67441B7C2450'; | ||
const defaultQuery = /* GraphQL */ ` | ||
query($pageSize: Int = 10, $after: String) { | ||
search( | ||
where: { | ||
AND: [ | ||
{ name: "_templates", value: "${headlessSiteGroupingTemplate}", operator: CONTAINS } | ||
{ name: "_path", value: "${sitecoreContentRootItem}", operator: CONTAINS } | ||
] | ||
} | ||
first: $pageSize | ||
after: $after | ||
) { | ||
pageInfo { | ||
endCursor | ||
hasNext | ||
} | ||
results { | ||
... on Item { | ||
name: field(name: "SiteName") { | ||
value | ||
} | ||
hostName: field(name: "Hostname") { | ||
value | ||
} | ||
language: field(name: "Language") { | ||
value | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
const siteQuery = /* GraphQL */ ` | ||
@@ -40,2 +75,5 @@ query { | ||
} | ||
get query() { | ||
return defaultQuery; | ||
} | ||
/** | ||
@@ -57,3 +95,5 @@ * site query is available on XM Cloud and XP 10.4+ | ||
} | ||
const results = yield this.fetchWithSiteQuery(); | ||
const results = this.config.useSiteQuery | ||
? yield this.fetchWithSiteQuery() | ||
: yield this.fetchWithDefaultQuery(); | ||
this.cache.setCacheValue(this.getCacheKey(), results); | ||
@@ -63,2 +103,28 @@ return results; | ||
} | ||
fetchWithDefaultQuery() { | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const results = []; | ||
let hasNext = true; | ||
let after = ''; | ||
while (hasNext) { | ||
const response = yield this.graphQLClient.request(this.query, { | ||
pageSize: this.config.pageSize, | ||
after, | ||
}); | ||
const result = (_b = (_a = response === null || response === void 0 ? void 0 : response.search) === null || _a === void 0 ? void 0 : _a.results) === null || _b === void 0 ? void 0 : _b.reduce((result, current) => { | ||
result.push({ | ||
name: current.name.value, | ||
hostName: current.hostName.value, | ||
language: current.language.value, | ||
}); | ||
return result; | ||
}, []); | ||
results.push(...result); | ||
hasNext = response.search.pageInfo.hasNext; | ||
after = response.search.pageInfo.endCursor; | ||
} | ||
return results; | ||
}); | ||
} | ||
fetchWithSiteQuery() { | ||
@@ -100,6 +166,12 @@ var _a, _b; | ||
getGraphQLClient() { | ||
if (!this.config.clientFactory) { | ||
throw new Error('clientFactory needs to be provided when initializing GraphQL client.'); | ||
if (!this.config.endpoint) { | ||
if (!this.config.clientFactory) { | ||
throw new Error('You should provide either an endpoint and apiKey, or a clientFactory.'); | ||
} | ||
return this.config.clientFactory({ | ||
debugger: debug_1.default.multisite, | ||
}); | ||
} | ||
return this.config.clientFactory({ | ||
return new graphql_1.GraphQLRequestClient(this.config.endpoint, { | ||
apiKey: this.config.apiKey, | ||
debugger: debug_1.default.multisite, | ||
@@ -106,0 +178,0 @@ }); |
@@ -16,2 +16,3 @@ "use strict"; | ||
exports.GraphQLSitemapXmlService = void 0; | ||
const graphql_1 = require("../graphql"); | ||
const constants_1 = require("../constants"); | ||
@@ -86,6 +87,12 @@ const debug_1 = __importDefault(require("../debug")); | ||
getGraphQLClient() { | ||
if (!this.options.clientFactory) { | ||
throw new Error('clientFactory needs to be provided when initializing GraphQL client.'); | ||
if (!this.options.endpoint) { | ||
if (!this.options.clientFactory) { | ||
throw new Error('You should provide either an endpoint and apiKey, or a clientFactory.'); | ||
} | ||
return this.options.clientFactory({ | ||
debugger: debug_1.default.sitemap, | ||
}); | ||
} | ||
return this.options.clientFactory({ | ||
return new graphql_1.GraphQLRequestClient(this.options.endpoint, { | ||
apiKey: this.options.apiKey, | ||
debugger: debug_1.default.sitemap, | ||
@@ -92,0 +99,0 @@ }); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -33,3 +33,3 @@ "use strict"; | ||
function fetchData(url, data, fetcher, params = {}) { | ||
return fetcher(utils_1.resolveUrl(url, params), data) | ||
return fetcher((0, utils_1.resolveUrl)(url, params), data) | ||
.then(checkStatus) | ||
@@ -58,3 +58,3 @@ .then((response) => { | ||
const { querystringParams } = options; | ||
if (!options.test && utils_1.isServer()) { | ||
if (!options.test && (0, utils_1.isServer)()) { | ||
// do nothing for SSR, only track events when a browser requests it | ||
@@ -61,0 +61,0 @@ return Promise.resolve(); |
@@ -18,3 +18,3 @@ "use strict"; | ||
static isActive() { | ||
if (is_server_1.default()) { | ||
if ((0, is_server_1.default)()) { | ||
return false; | ||
@@ -27,3 +27,3 @@ } | ||
static resetChromes() { | ||
if (is_server_1.default()) { | ||
if ((0, is_server_1.default)()) { | ||
return; | ||
@@ -51,3 +51,3 @@ } | ||
static isActive() { | ||
if (is_server_1.default()) { | ||
if ((0, is_server_1.default)()) { | ||
return false; | ||
@@ -59,3 +59,3 @@ } | ||
static resetChromes() { | ||
if (is_server_1.default()) { | ||
if ((0, is_server_1.default)()) { | ||
return; | ||
@@ -62,0 +62,0 @@ } |
@@ -36,3 +36,3 @@ "use strict"; | ||
// TODO: Verify our browser support requirements. | ||
if (is_server_1.default()) { | ||
if ((0, is_server_1.default)()) { | ||
const url = new URL(urlBase); | ||
@@ -39,0 +39,0 @@ for (const key in params) { |
@@ -10,2 +10,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { GraphQLRequestClient, } from '../graphql-request-client'; | ||
import { SitecoreTemplateId } from '../constants'; | ||
@@ -113,6 +114,14 @@ import { DictionaryServiceBase } from './dictionary-service'; | ||
getGraphQLClient() { | ||
if (!this.options.clientFactory) { | ||
throw new Error('clientFactory needs to be provided when initializing GraphQL client.'); | ||
if (!this.options.endpoint) { | ||
if (!this.options.clientFactory) { | ||
throw new Error('You should provide either an endpoint and apiKey, or a clientFactory.'); | ||
} | ||
return this.options.clientFactory({ | ||
debugger: debug.dictionary, | ||
retries: this.options.retries, | ||
retryStrategy: this.options.retryStrategy, | ||
}); | ||
} | ||
return this.options.clientFactory({ | ||
return new GraphQLRequestClient(this.options.endpoint, { | ||
apiKey: this.options.apiKey, | ||
debugger: debug.dictionary, | ||
@@ -119,0 +128,0 @@ retries: this.options.retries, |
@@ -11,2 +11,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { LayoutServiceBase } from './layout-service'; | ||
import { GraphQLRequestClient, } from '../graphql-request-client'; | ||
import debug from '../debug'; | ||
@@ -53,6 +54,14 @@ /** | ||
getGraphQLClient() { | ||
if (!this.serviceConfig.clientFactory) { | ||
throw new Error('clientFactory needs to be provided when initializing GraphQL client.'); | ||
if (!this.serviceConfig.endpoint) { | ||
if (!this.serviceConfig.clientFactory) { | ||
throw new Error('You should provide either an endpoint and apiKey, or a clientFactory.'); | ||
} | ||
return this.serviceConfig.clientFactory({ | ||
debugger: debug.layout, | ||
retries: this.serviceConfig.retries, | ||
retryStrategy: this.serviceConfig.retryStrategy, | ||
}); | ||
} | ||
return this.serviceConfig.clientFactory({ | ||
return new GraphQLRequestClient(this.serviceConfig.endpoint, { | ||
apiKey: this.serviceConfig.apiKey, | ||
debugger: debug.layout, | ||
@@ -59,0 +68,0 @@ retries: this.serviceConfig.retries, |
@@ -10,2 +10,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { GraphQLRequestClient, } from '../graphql-request-client'; | ||
import debug from '../debug'; | ||
@@ -101,6 +102,14 @@ import { isTimeoutError } from '../utils'; | ||
getGraphQLClient() { | ||
if (!this.config.clientFactory) { | ||
throw new Error('clientFactory needs to be provided when initializing GraphQL client.'); | ||
if (!this.config.endpoint) { | ||
if (!this.config.clientFactory) { | ||
throw new Error('You should provide either an endpoint and apiKey, or a clientFactory.'); | ||
} | ||
return this.config.clientFactory({ | ||
debugger: debug.personalize, | ||
fetch: this.config.fetch, | ||
timeout: this.config.timeout, | ||
}); | ||
} | ||
return this.config.clientFactory({ | ||
return new GraphQLRequestClient(this.config.endpoint, { | ||
apiKey: this.config.apiKey, | ||
debugger: debug.personalize, | ||
@@ -107,0 +116,0 @@ fetch: this.config.fetch, |
@@ -10,2 +10,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { GraphQLRequestClient } from '../graphql'; | ||
import { siteNameError } from '../constants'; | ||
@@ -74,6 +75,14 @@ import debug from '../debug'; | ||
getGraphQLClient() { | ||
if (!this.options.clientFactory) { | ||
throw new Error('clientFactory needs to be provided when initializing GraphQL client.'); | ||
if (!this.options.endpoint) { | ||
if (!this.options.clientFactory) { | ||
throw new Error('You should provide either an endpoint and apiKey, or a clientFactory.'); | ||
} | ||
return this.options.clientFactory({ | ||
debugger: debug.errorpages, | ||
retries: this.options.retries, | ||
retryStrategy: this.options.retryStrategy, | ||
}); | ||
} | ||
return this.options.clientFactory({ | ||
return new GraphQLRequestClient(this.options.endpoint, { | ||
apiKey: this.options.apiKey, | ||
debugger: debug.errorpages, | ||
@@ -80,0 +89,0 @@ retries: this.options.retries, |
@@ -10,2 +10,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { GraphQLRequestClient } from '../graphql'; | ||
import { siteNameError } from '../constants'; | ||
@@ -79,6 +80,13 @@ import debug from '../debug'; | ||
getGraphQLClient() { | ||
if (!this.options.clientFactory) { | ||
throw new Error('clientFactory needs to be provided when initializing GraphQL client.'); | ||
if (!this.options.endpoint) { | ||
if (!this.options.clientFactory) { | ||
throw new Error('You should provide either an endpoint and apiKey, or a clientFactory.'); | ||
} | ||
return this.options.clientFactory({ | ||
debugger: debug.redirects, | ||
fetch: this.options.fetch, | ||
}); | ||
} | ||
return this.options.clientFactory({ | ||
return new GraphQLRequestClient(this.options.endpoint, { | ||
apiKey: this.options.apiKey, | ||
debugger: debug.redirects, | ||
@@ -85,0 +93,0 @@ fetch: this.options.fetch, |
@@ -10,2 +10,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { GraphQLRequestClient } from '../graphql'; | ||
import { siteNameError } from '../constants'; | ||
@@ -70,6 +71,12 @@ import debug from '../debug'; | ||
getGraphQLClient() { | ||
if (!this.options.clientFactory) { | ||
throw new Error('clientFactory needs to be provided when initializing GraphQL client.'); | ||
if (!this.options.endpoint) { | ||
if (!this.options.clientFactory) { | ||
throw new Error('You should provide either an endpoint and apiKey, or a clientFactory.'); | ||
} | ||
return this.options.clientFactory({ | ||
debugger: debug.robots, | ||
}); | ||
} | ||
return this.options.clientFactory({ | ||
return new GraphQLRequestClient(this.options.endpoint, { | ||
apiKey: this.options.apiKey, | ||
debugger: debug.robots, | ||
@@ -76,0 +83,0 @@ }); |
@@ -10,4 +10,39 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { GraphQLRequestClient } from '../graphql'; | ||
import debug from '../debug'; | ||
import { MemoryCacheClient } from '../cache-client'; | ||
const headlessSiteGroupingTemplate = 'E46F3AF2-39FA-4866-A157-7017C4B2A40C'; | ||
const sitecoreContentRootItem = '0DE95AE4-41AB-4D01-9EB0-67441B7C2450'; | ||
const defaultQuery = /* GraphQL */ ` | ||
query($pageSize: Int = 10, $after: String) { | ||
search( | ||
where: { | ||
AND: [ | ||
{ name: "_templates", value: "${headlessSiteGroupingTemplate}", operator: CONTAINS } | ||
{ name: "_path", value: "${sitecoreContentRootItem}", operator: CONTAINS } | ||
] | ||
} | ||
first: $pageSize | ||
after: $after | ||
) { | ||
pageInfo { | ||
endCursor | ||
hasNext | ||
} | ||
results { | ||
... on Item { | ||
name: field(name: "SiteName") { | ||
value | ||
} | ||
hostName: field(name: "Hostname") { | ||
value | ||
} | ||
language: field(name: "Language") { | ||
value | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
const siteQuery = /* GraphQL */ ` | ||
@@ -34,2 +69,5 @@ query { | ||
} | ||
get query() { | ||
return defaultQuery; | ||
} | ||
/** | ||
@@ -51,3 +89,5 @@ * site query is available on XM Cloud and XP 10.4+ | ||
} | ||
const results = yield this.fetchWithSiteQuery(); | ||
const results = this.config.useSiteQuery | ||
? yield this.fetchWithSiteQuery() | ||
: yield this.fetchWithDefaultQuery(); | ||
this.cache.setCacheValue(this.getCacheKey(), results); | ||
@@ -57,2 +97,28 @@ return results; | ||
} | ||
fetchWithDefaultQuery() { | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const results = []; | ||
let hasNext = true; | ||
let after = ''; | ||
while (hasNext) { | ||
const response = yield this.graphQLClient.request(this.query, { | ||
pageSize: this.config.pageSize, | ||
after, | ||
}); | ||
const result = (_b = (_a = response === null || response === void 0 ? void 0 : response.search) === null || _a === void 0 ? void 0 : _a.results) === null || _b === void 0 ? void 0 : _b.reduce((result, current) => { | ||
result.push({ | ||
name: current.name.value, | ||
hostName: current.hostName.value, | ||
language: current.language.value, | ||
}); | ||
return result; | ||
}, []); | ||
results.push(...result); | ||
hasNext = response.search.pageInfo.hasNext; | ||
after = response.search.pageInfo.endCursor; | ||
} | ||
return results; | ||
}); | ||
} | ||
fetchWithSiteQuery() { | ||
@@ -94,6 +160,12 @@ var _a, _b; | ||
getGraphQLClient() { | ||
if (!this.config.clientFactory) { | ||
throw new Error('clientFactory needs to be provided when initializing GraphQL client.'); | ||
if (!this.config.endpoint) { | ||
if (!this.config.clientFactory) { | ||
throw new Error('You should provide either an endpoint and apiKey, or a clientFactory.'); | ||
} | ||
return this.config.clientFactory({ | ||
debugger: debug.multisite, | ||
}); | ||
} | ||
return this.config.clientFactory({ | ||
return new GraphQLRequestClient(this.config.endpoint, { | ||
apiKey: this.config.apiKey, | ||
debugger: debug.multisite, | ||
@@ -100,0 +172,0 @@ }); |
@@ -10,2 +10,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { GraphQLRequestClient } from '../graphql'; | ||
import { siteNameError } from '../constants'; | ||
@@ -80,6 +81,12 @@ import debug from '../debug'; | ||
getGraphQLClient() { | ||
if (!this.options.clientFactory) { | ||
throw new Error('clientFactory needs to be provided when initializing GraphQL client.'); | ||
if (!this.options.endpoint) { | ||
if (!this.options.clientFactory) { | ||
throw new Error('You should provide either an endpoint and apiKey, or a clientFactory.'); | ||
} | ||
return this.options.clientFactory({ | ||
debugger: debug.sitemap, | ||
}); | ||
} | ||
return this.options.clientFactory({ | ||
return new GraphQLRequestClient(this.options.endpoint, { | ||
apiKey: this.options.apiKey, | ||
debugger: debug.sitemap, | ||
@@ -86,0 +93,0 @@ }); |
{ | ||
"name": "@sitecore-jss/sitecore-jss", | ||
"version": "21.8.0-canary.10", | ||
"version": "21.8.0-canary.14", | ||
"main": "dist/cjs/index.js", | ||
@@ -54,3 +54,3 @@ "module": "dist/esm/index.js", | ||
"tslib": "^1.10.0", | ||
"typescript": "~4.3.5" | ||
"typescript": "~4.6.3" | ||
}, | ||
@@ -69,3 +69,3 @@ "dependencies": { | ||
"types": "types/index.d.ts", | ||
"gitHead": "53fd28227f4691ab5505903d2d3843f47e208c8b", | ||
"gitHead": "80887889578baec2c700477218a3e05951653d52", | ||
"files": [ | ||
@@ -72,0 +72,0 @@ "dist", |
@@ -5,6 +5,3 @@ # Sitecore JavaScript Rendering SDK | ||
<!--- | ||
@TODO: Update to next version docs before release | ||
--> | ||
[Documentation (Experience Platform)](https://doc.sitecore.com/xp/en/developers/hd/22/sitecore-headless-development/sitecore-javascript-rendering-sdks--jss-.html) | ||
[Documentation (Experience Platform)](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-headless-development/sitecore-javascript-rendering-sdks--jss-.html) | ||
@@ -11,0 +8,0 @@ [Documentation (XM Cloud)](https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-javascript-rendering-sdks--jss-.html) |
@@ -18,2 +18,22 @@ import { ClientError } from 'graphql-request'; | ||
/** | ||
* Defines the strategy for retrying GraphQL requests based on errors and attempts. | ||
*/ | ||
export interface RetryStrategy { | ||
/** | ||
* Determines whether a request should be retried based on the given error and attempt count. | ||
* @param error - The error received from the GraphQL request. | ||
* @param attempt - The current attempt number. | ||
* @param retries - The number of retries configured. | ||
* @returns A boolean indicating whether to retry the request. | ||
*/ | ||
shouldRetry(error: ClientError, attempt: number, retries: number): boolean; | ||
/** | ||
* Calculates the delay (in milliseconds) before the next retry based on the given error and attempt count. | ||
* @param error - The error received from the GraphQL request. | ||
* @param attempt - The current attempt number. | ||
* @returns The delay in milliseconds before the next retry. | ||
*/ | ||
getDelay(error: ClientError, attempt: number): number; | ||
} | ||
/** | ||
* This type represents errors that can occur in a GraphQL client. | ||
@@ -20,0 +40,0 @@ * In cases where an error status was sent back from the server (`!response.ok`), the `response` will be populated with details. In cases where a response was never received, the `code` can be populated with the error code (e.g. Node's 'ECONNRESET', 'ETIMEDOUT', etc). |
@@ -12,6 +12,16 @@ import { GraphQLClient, GraphQLRequestClientConfig, GraphQLRequestClientFactory } from '../graphql-request-client'; | ||
/** | ||
* The URL of the graphQL endpoint. | ||
* @deprecated use @param clientFactory property instead | ||
*/ | ||
endpoint?: string; | ||
/** | ||
* The API key to use for authentication. | ||
* @deprecated use @param clientFactory property instead | ||
*/ | ||
apiKey?: string; | ||
/** | ||
* A GraphQL Request Client Factory is a function that accepts configuration and returns an instance of a GraphQLRequestClient. | ||
* This factory function is used to create and configure GraphQL clients for making GraphQL API requests. | ||
*/ | ||
clientFactory: GraphQLRequestClientFactory; | ||
clientFactory?: GraphQLRequestClientFactory; | ||
/** | ||
@@ -18,0 +28,0 @@ * Optional. The template ID to use when searching for dictionary entries. |
@@ -6,2 +6,7 @@ import { LayoutServiceBase } from './layout-service'; | ||
/** | ||
* Your Graphql endpoint | ||
* @deprecated use @param clientFactory property instead | ||
*/ | ||
endpoint?: string; | ||
/** | ||
* The JSS application name | ||
@@ -11,6 +16,11 @@ */ | ||
/** | ||
* The API key to use for authentication | ||
* @deprecated use @param clientFactory property instead | ||
*/ | ||
apiKey?: string; | ||
/** | ||
* A GraphQL Request Client Factory is a function that accepts configuration and returns an instance of a GraphQLRequestClient. | ||
* This factory function is used to create and configure GraphQL clients for making GraphQL API requests. | ||
*/ | ||
clientFactory: GraphQLRequestClientFactory; | ||
clientFactory?: GraphQLRequestClientFactory; | ||
/** | ||
@@ -17,0 +27,0 @@ * Override default layout query |
@@ -5,2 +5,12 @@ import { GraphQLClient, GraphQLRequestClientFactory } from '../graphql-request-client'; | ||
/** | ||
* Your Graphql endpoint | ||
* @deprecated use @param clientFactory property instead | ||
*/ | ||
endpoint?: string; | ||
/** | ||
* The API key to use for authentication | ||
* @deprecated use @param clientFactory property instead | ||
*/ | ||
apiKey?: string; | ||
/** | ||
* Timeout (ms) for the Personalize request. Default is 400. | ||
@@ -21,3 +31,3 @@ */ | ||
*/ | ||
clientFactory: GraphQLRequestClientFactory; | ||
clientFactory?: GraphQLRequestClientFactory; | ||
}; | ||
@@ -24,0 +34,0 @@ /** |
@@ -6,2 +6,12 @@ import { GraphQLClient, GraphQLRequestClientConfig } from '../graphql'; | ||
/** | ||
* Your Graphql endpoint | ||
* @deprecated use @param clientFactory property instead | ||
*/ | ||
endpoint?: string; | ||
/** | ||
* The API key to use for authentication | ||
* @deprecated use @param clientFactory property instead | ||
*/ | ||
apiKey?: string; | ||
/** | ||
* The JSS application name | ||
@@ -18,3 +28,3 @@ */ | ||
*/ | ||
clientFactory: GraphQLRequestClientFactory; | ||
clientFactory?: GraphQLRequestClientFactory; | ||
} | ||
@@ -21,0 +31,0 @@ /** |
@@ -16,2 +16,12 @@ import { GraphQLClient } from '../graphql'; | ||
/** | ||
* Your Graphql endpoint | ||
* @deprecated use @param clientFactory property instead | ||
*/ | ||
endpoint?: string; | ||
/** | ||
* The API key to use for authentication | ||
* @deprecated use @param clientFactory property instead | ||
*/ | ||
apiKey?: string; | ||
/** | ||
* Override fetch method. Uses 'GraphQLRequestClient' default otherwise. | ||
@@ -24,3 +34,3 @@ */ | ||
*/ | ||
clientFactory: GraphQLRequestClientFactory; | ||
clientFactory?: GraphQLRequestClientFactory; | ||
}; | ||
@@ -27,0 +37,0 @@ /** |
@@ -5,2 +5,12 @@ import { GraphQLClient } from '../graphql'; | ||
/** | ||
* Your Graphql endpoint | ||
* @deprecated use @param clientFactory property instead | ||
*/ | ||
endpoint?: string; | ||
/** | ||
* The API key to use for authentication | ||
* @deprecated use @param clientFactory property instead | ||
*/ | ||
apiKey?: string; | ||
/** | ||
* The JSS application name | ||
@@ -13,3 +23,3 @@ */ | ||
*/ | ||
clientFactory: GraphQLRequestClientFactory; | ||
clientFactory?: GraphQLRequestClientFactory; | ||
}; | ||
@@ -16,0 +26,0 @@ /** |
@@ -23,2 +23,12 @@ import { GraphQLClient } from '../graphql'; | ||
export declare type GraphQLSiteInfoServiceConfig = CacheOptions & { | ||
/** | ||
* Your Graphql endpoint | ||
* @deprecated use @param clientFactory property instead | ||
*/ | ||
endpoint?: string; | ||
/** | ||
* The API key to use for authentication | ||
* @deprecated use @param clientFactory property instead | ||
*/ | ||
apiKey?: string; | ||
/** common variable for all GraphQL queries | ||
@@ -34,5 +44,20 @@ * it will be used for every type of query to regulate result batch size | ||
*/ | ||
clientFactory: GraphQLRequestClientFactory; | ||
clientFactory?: GraphQLRequestClientFactory; | ||
/** | ||
* Boolean indicating if service will use site GQL query instead of search | ||
*/ | ||
useSiteQuery?: boolean; | ||
}; | ||
export declare type GraphQLSiteInfoResult = { | ||
name: { | ||
value: string; | ||
}; | ||
hostName: { | ||
value: string; | ||
}; | ||
language: { | ||
value: string; | ||
}; | ||
}; | ||
export declare type GraphQLXmCloudSiteInfoResult = { | ||
name: string; | ||
@@ -46,2 +71,3 @@ hostName: string; | ||
private cache; | ||
protected get query(): string; | ||
/** | ||
@@ -57,2 +83,3 @@ * site query is available on XM Cloud and XP 10.4+ | ||
fetchSiteInfo(): Promise<SiteInfo[]>; | ||
protected fetchWithDefaultQuery(): Promise<SiteInfo[]>; | ||
protected fetchWithSiteQuery(): Promise<SiteInfo[]>; | ||
@@ -59,0 +86,0 @@ /** |
@@ -5,2 +5,12 @@ import { GraphQLClient } from '../graphql'; | ||
/** | ||
* Your Graphql endpoint | ||
* @deprecated use @param clientFactory property instead | ||
*/ | ||
endpoint?: string; | ||
/** | ||
* The API key to use for authentication | ||
* @deprecated use @param clientFactory property instead | ||
*/ | ||
apiKey?: string; | ||
/** | ||
* The JSS application name | ||
@@ -13,3 +23,3 @@ */ | ||
*/ | ||
clientFactory: GraphQLRequestClientFactory; | ||
clientFactory?: GraphQLRequestClientFactory; | ||
}; | ||
@@ -16,0 +26,0 @@ /** |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
373496
177
8383
10