@sitecore-content-sdk/content 1.5.0-canary.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +202 -0
- package/README.md +7 -0
- package/client.d.ts +1 -0
- package/codegen.d.ts +1 -0
- package/config-cli.d.ts +1 -0
- package/config.d.ts +1 -0
- package/dist/cjs/client/edge-proxy.js +24 -0
- package/dist/cjs/client/index.js +14 -0
- package/dist/cjs/client/models.js +2 -0
- package/dist/cjs/client/sitecore-client.js +420 -0
- package/dist/cjs/client/utils.js +53 -0
- package/dist/cjs/config/define-config.js +195 -0
- package/dist/cjs/config/index.js +7 -0
- package/dist/cjs/config/models.js +12 -0
- package/dist/cjs/config-cli/define-cli-config.js +23 -0
- package/dist/cjs/config-cli/index.js +7 -0
- package/dist/cjs/config-cli/models.js +8 -0
- package/dist/cjs/constants.js +12 -0
- package/dist/cjs/debug.js +21 -0
- package/dist/cjs/editing/codegen/index.js +14 -0
- package/dist/cjs/editing/codegen/preview.js +277 -0
- package/dist/cjs/editing/component-layout-service.js +62 -0
- package/dist/cjs/editing/design-library.js +184 -0
- package/dist/cjs/editing/editing-service.js +81 -0
- package/dist/cjs/editing/index.js +33 -0
- package/dist/cjs/editing/models.js +44 -0
- package/dist/cjs/editing/utils.js +105 -0
- package/dist/cjs/form/form.js +81 -0
- package/dist/cjs/form/index.js +7 -0
- package/dist/cjs/i18n/dictionary-service.js +144 -0
- package/dist/cjs/i18n/index.js +7 -0
- package/dist/cjs/i18n/utils.js +16 -0
- package/dist/cjs/index.js +47 -0
- package/dist/cjs/layout/content-styles.js +73 -0
- package/dist/cjs/layout/index.js +24 -0
- package/dist/cjs/layout/layout-service.js +68 -0
- package/dist/cjs/layout/models.js +39 -0
- package/dist/cjs/layout/themes.js +77 -0
- package/dist/cjs/layout/utils.js +117 -0
- package/dist/cjs/media/index.js +38 -0
- package/dist/cjs/media/media-api.js +100 -0
- package/dist/cjs/models.js +2 -0
- package/dist/cjs/personalize/index.js +15 -0
- package/dist/cjs/personalize/layout-personalizer.js +98 -0
- package/dist/cjs/personalize/personalize-service.js +109 -0
- package/dist/cjs/personalize/utils.js +143 -0
- package/dist/cjs/site/error-pages-service.js +82 -0
- package/dist/cjs/site/index.js +26 -0
- package/dist/cjs/site/models.js +2 -0
- package/dist/cjs/site/redirects-service.js +109 -0
- package/dist/cjs/site/robots-service.js +74 -0
- package/dist/cjs/site/site-resolver.js +73 -0
- package/dist/cjs/site/siteinfo-service.js +94 -0
- package/dist/cjs/site/sitemap-xml-service.js +92 -0
- package/dist/cjs/site/sitepath-service.js +201 -0
- package/dist/cjs/site/utils.js +55 -0
- package/dist/cjs/sitecore-service-base.js +33 -0
- package/dist/cjs/tools/codegen/component-generation.js +49 -0
- package/dist/cjs/tools/codegen/extract-files.js +105 -0
- package/dist/cjs/tools/codegen/import-map.js +411 -0
- package/dist/cjs/tools/codegen/utils.js +418 -0
- package/dist/cjs/tools/generate-map.js +2 -0
- package/dist/cjs/tools/generateSites.js +59 -0
- package/dist/cjs/tools/index.js +30 -0
- package/dist/cjs/tools/scaffold.js +62 -0
- package/dist/cjs/tools/templating/components.js +96 -0
- package/dist/cjs/tools/templating/index.js +6 -0
- package/dist/esm/client/edge-proxy.js +19 -0
- package/dist/esm/client/index.js +4 -0
- package/dist/esm/client/models.js +1 -0
- package/dist/esm/client/sitecore-client.js +416 -0
- package/dist/esm/client/utils.js +49 -0
- package/dist/esm/config/define-config.js +189 -0
- package/dist/esm/config/index.js +2 -0
- package/dist/esm/config/models.js +9 -0
- package/dist/esm/config-cli/define-cli-config.js +19 -0
- package/dist/esm/config-cli/index.js +2 -0
- package/dist/esm/config-cli/models.js +5 -0
- package/dist/esm/constants.js +9 -0
- package/dist/esm/debug.js +19 -0
- package/dist/esm/editing/codegen/index.js +1 -0
- package/dist/esm/editing/codegen/preview.js +263 -0
- package/dist/esm/editing/component-layout-service.js +55 -0
- package/dist/esm/editing/design-library.js +172 -0
- package/dist/esm/editing/editing-service.js +74 -0
- package/dist/esm/editing/index.js +6 -0
- package/dist/esm/editing/models.js +41 -0
- package/dist/esm/editing/utils.js +98 -0
- package/dist/esm/form/form.js +72 -0
- package/dist/esm/form/index.js +1 -0
- package/dist/esm/i18n/dictionary-service.js +137 -0
- package/dist/esm/i18n/index.js +2 -0
- package/dist/esm/i18n/utils.js +13 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/layout/content-styles.js +65 -0
- package/dist/esm/layout/index.js +6 -0
- package/dist/esm/layout/layout-service.js +61 -0
- package/dist/esm/layout/models.js +36 -0
- package/dist/esm/layout/themes.js +72 -0
- package/dist/esm/layout/utils.js +109 -0
- package/dist/esm/media/index.js +2 -0
- package/dist/esm/media/media-api.js +90 -0
- package/dist/esm/models.js +1 -0
- package/dist/esm/personalize/index.js +3 -0
- package/dist/esm/personalize/layout-personalizer.js +93 -0
- package/dist/esm/personalize/personalize-service.js +102 -0
- package/dist/esm/personalize/utils.js +135 -0
- package/dist/esm/site/error-pages-service.js +75 -0
- package/dist/esm/site/index.js +8 -0
- package/dist/esm/site/models.js +1 -0
- package/dist/esm/site/redirects-service.js +102 -0
- package/dist/esm/site/robots-service.js +67 -0
- package/dist/esm/site/site-resolver.js +69 -0
- package/dist/esm/site/siteinfo-service.js +87 -0
- package/dist/esm/site/sitemap-xml-service.js +85 -0
- package/dist/esm/site/sitepath-service.js +193 -0
- package/dist/esm/site/utils.js +49 -0
- package/dist/esm/sitecore-service-base.js +29 -0
- package/dist/esm/tools/codegen/component-generation.js +44 -0
- package/dist/esm/tools/codegen/extract-files.js +99 -0
- package/dist/esm/tools/codegen/import-map.js +368 -0
- package/dist/esm/tools/codegen/utils.js +373 -0
- package/dist/esm/tools/generate-map.js +1 -0
- package/dist/esm/tools/generateSites.js +52 -0
- package/dist/esm/tools/index.js +6 -0
- package/dist/esm/tools/scaffold.js +54 -0
- package/dist/esm/tools/templating/components.js +59 -0
- package/dist/esm/tools/templating/index.js +1 -0
- package/editing.d.ts +1 -0
- package/i18n.d.ts +1 -0
- package/layout.d.ts +1 -0
- package/media.d.ts +1 -0
- package/package.json +157 -0
- package/personalize.d.ts +1 -0
- package/site.d.ts +1 -0
- package/tools.d.ts +1 -0
- package/types/client/edge-proxy.d.ts +17 -0
- package/types/client/edge-proxy.d.ts.map +1 -0
- package/types/client/index.d.ts +7 -0
- package/types/client/index.d.ts.map +1 -0
- package/types/client/models.d.ts +21 -0
- package/types/client/models.d.ts.map +1 -0
- package/types/client/sitecore-client.d.ts +338 -0
- package/types/client/sitecore-client.d.ts.map +1 -0
- package/types/client/utils.d.ts +15 -0
- package/types/client/utils.d.ts.map +1 -0
- package/types/config/define-config.d.ts +20 -0
- package/types/config/define-config.d.ts.map +1 -0
- package/types/config/index.d.ts +3 -0
- package/types/config/index.d.ts.map +1 -0
- package/types/config/models.d.ts +287 -0
- package/types/config/models.d.ts.map +1 -0
- package/types/config-cli/define-cli-config.d.ts +9 -0
- package/types/config-cli/define-cli-config.d.ts.map +1 -0
- package/types/config-cli/index.d.ts +3 -0
- package/types/config-cli/index.d.ts.map +1 -0
- package/types/config-cli/models.d.ts +6 -0
- package/types/config-cli/models.d.ts.map +1 -0
- package/types/constants.d.ts +10 -0
- package/types/constants.d.ts.map +1 -0
- package/types/debug.d.ts +19 -0
- package/types/debug.d.ts.map +1 -0
- package/types/editing/codegen/index.d.ts +2 -0
- package/types/editing/codegen/index.d.ts.map +1 -0
- package/types/editing/codegen/preview.d.ts +256 -0
- package/types/editing/codegen/preview.d.ts.map +1 -0
- package/types/editing/component-layout-service.d.ts +84 -0
- package/types/editing/component-layout-service.d.ts.map +1 -0
- package/types/editing/design-library.d.ts +111 -0
- package/types/editing/design-library.d.ts.map +1 -0
- package/types/editing/editing-service.d.ts +71 -0
- package/types/editing/editing-service.d.ts.map +1 -0
- package/types/editing/index.d.ts +7 -0
- package/types/editing/index.d.ts.map +1 -0
- package/types/editing/models.d.ts +103 -0
- package/types/editing/models.d.ts.map +1 -0
- package/types/editing/utils.d.ts +82 -0
- package/types/editing/utils.d.ts.map +1 -0
- package/types/form/form.d.ts +25 -0
- package/types/form/form.d.ts.map +1 -0
- package/types/form/index.d.ts +2 -0
- package/types/form/index.d.ts.map +1 -0
- package/types/i18n/dictionary-service.d.ts +133 -0
- package/types/i18n/dictionary-service.d.ts.map +1 -0
- package/types/i18n/index.d.ts +3 -0
- package/types/i18n/index.d.ts.map +1 -0
- package/types/i18n/utils.d.ts +9 -0
- package/types/i18n/utils.d.ts.map +1 -0
- package/types/index.d.ts +7 -0
- package/types/index.d.ts.map +1 -0
- package/types/layout/content-styles.d.ts +20 -0
- package/types/layout/content-styles.d.ts.map +1 -0
- package/types/layout/index.d.ts +6 -0
- package/types/layout/index.d.ts.map +1 -0
- package/types/layout/layout-service.d.ts +45 -0
- package/types/layout/layout-service.d.ts.map +1 -0
- package/types/layout/models.d.ts +174 -0
- package/types/layout/models.d.ts.map +1 -0
- package/types/layout/themes.d.ts +13 -0
- package/types/layout/themes.d.ts.map +1 -0
- package/types/layout/utils.d.ts +56 -0
- package/types/layout/utils.d.ts.map +1 -0
- package/types/media/index.d.ts +3 -0
- package/types/media/index.d.ts.map +1 -0
- package/types/media/media-api.d.ts +60 -0
- package/types/media/media-api.d.ts.map +1 -0
- package/types/models.d.ts +32 -0
- package/types/models.d.ts.map +1 -0
- package/types/personalize/index.d.ts +4 -0
- package/types/personalize/index.d.ts.map +1 -0
- package/types/personalize/layout-personalizer.d.ts +29 -0
- package/types/personalize/layout-personalizer.d.ts.map +1 -0
- package/types/personalize/personalize-service.d.ts +89 -0
- package/types/personalize/personalize-service.d.ts.map +1 -0
- package/types/personalize/utils.d.ts +78 -0
- package/types/personalize/utils.d.ts.map +1 -0
- package/types/site/error-pages-service.d.ts +64 -0
- package/types/site/error-pages-service.d.ts.map +1 -0
- package/types/site/index.d.ts +10 -0
- package/types/site/index.d.ts.map +1 -0
- package/types/site/models.d.ts +23 -0
- package/types/site/models.d.ts.map +1 -0
- package/types/site/redirects-service.d.ts +91 -0
- package/types/site/redirects-service.d.ts.map +1 -0
- package/types/site/robots-service.d.ts +57 -0
- package/types/site/robots-service.d.ts.map +1 -0
- package/types/site/site-resolver.d.ts +28 -0
- package/types/site/site-resolver.d.ts.map +1 -0
- package/types/site/siteinfo-service.d.ts +64 -0
- package/types/site/siteinfo-service.d.ts.map +1 -0
- package/types/site/sitemap-xml-service.d.ts +63 -0
- package/types/site/sitemap-xml-service.d.ts.map +1 -0
- package/types/site/sitepath-service.d.ts +137 -0
- package/types/site/sitepath-service.d.ts.map +1 -0
- package/types/site/utils.d.ts +41 -0
- package/types/site/utils.d.ts.map +1 -0
- package/types/sitecore-service-base.d.ts +31 -0
- package/types/sitecore-service-base.d.ts.map +1 -0
- package/types/tools/codegen/component-generation.d.ts +50 -0
- package/types/tools/codegen/component-generation.d.ts.map +1 -0
- package/types/tools/codegen/extract-files.d.ts +24 -0
- package/types/tools/codegen/extract-files.d.ts.map +1 -0
- package/types/tools/codegen/import-map.d.ts +103 -0
- package/types/tools/codegen/import-map.d.ts.map +1 -0
- package/types/tools/codegen/utils.d.ts +76 -0
- package/types/tools/codegen/utils.d.ts.map +1 -0
- package/types/tools/generate-map.d.ts +36 -0
- package/types/tools/generate-map.d.ts.map +1 -0
- package/types/tools/generateSites.d.ts +25 -0
- package/types/tools/generateSites.d.ts.map +1 -0
- package/types/tools/index.d.ts +8 -0
- package/types/tools/index.d.ts.map +1 -0
- package/types/tools/scaffold.d.ts +27 -0
- package/types/tools/scaffold.d.ts.map +1 -0
- package/types/tools/templating/components.d.ts +104 -0
- package/types/tools/templating/components.d.ts.map +1 -0
- package/types/tools/templating/index.d.ts +2 -0
- package/types/tools/templating/index.d.ts.map +1 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SiteInfoService = void 0;
|
|
7
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
8
|
+
const debug_1 = __importDefault(require("../debug"));
|
|
9
|
+
const siteQuery = /* GraphQL */ `
|
|
10
|
+
query {
|
|
11
|
+
site {
|
|
12
|
+
siteInfoCollection {
|
|
13
|
+
name
|
|
14
|
+
hostName: hostname
|
|
15
|
+
language
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
/**
|
|
21
|
+
* Service to fetch site information
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
class SiteInfoService {
|
|
25
|
+
/**
|
|
26
|
+
* Creates an instance of graphQL service to retrieve site configuration list from Sitecore
|
|
27
|
+
* @param {SiteInfoServiceConfig} config instance
|
|
28
|
+
*/
|
|
29
|
+
constructor(config) {
|
|
30
|
+
this.config = config;
|
|
31
|
+
this.graphQLClient = this.getGraphQLClient();
|
|
32
|
+
this.cache = this.getCacheClient();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* site query is available on XM Cloud and XP 10.4+
|
|
36
|
+
*/
|
|
37
|
+
get siteQuery() {
|
|
38
|
+
return siteQuery;
|
|
39
|
+
}
|
|
40
|
+
async fetchSiteInfo(fetchOptions) {
|
|
41
|
+
var _a, _b;
|
|
42
|
+
const cachedResult = this.cache.getCacheValue(this.getCacheKey());
|
|
43
|
+
if (cachedResult) {
|
|
44
|
+
return cachedResult;
|
|
45
|
+
}
|
|
46
|
+
if (process.env.SITECORE) {
|
|
47
|
+
debug_1.default.multisite('Skipping site information fetch (building on XM Cloud)');
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
const response = await this.graphQLClient.request(this.siteQuery, {}, fetchOptions);
|
|
51
|
+
const results = (_b = (_a = response === null || response === void 0 ? void 0 : response.site) === null || _a === void 0 ? void 0 : _a.siteInfoCollection) === null || _b === void 0 ? void 0 : _b.reduce((result, current) => {
|
|
52
|
+
// filter out built in website
|
|
53
|
+
current.name !== 'website' &&
|
|
54
|
+
result.push({
|
|
55
|
+
name: current.name,
|
|
56
|
+
hostName: current.hostName,
|
|
57
|
+
language: current.language,
|
|
58
|
+
});
|
|
59
|
+
return result;
|
|
60
|
+
}, []);
|
|
61
|
+
this.cache.setCacheValue(this.getCacheKey(), results);
|
|
62
|
+
return results;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Gets cache client implementation
|
|
66
|
+
* Override this method if custom cache needs to be used
|
|
67
|
+
* @returns CacheClient instance
|
|
68
|
+
*/
|
|
69
|
+
getCacheClient() {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
return new core_1.MemoryCacheClient({
|
|
72
|
+
cacheEnabled: (_a = this.config.cacheEnabled) !== null && _a !== void 0 ? _a : true,
|
|
73
|
+
cacheTimeout: (_b = this.config.cacheTimeout) !== null && _b !== void 0 ? _b : 10,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
|
|
78
|
+
* library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
|
|
79
|
+
* want to use something else.
|
|
80
|
+
* @returns {GraphQLClient} implementation
|
|
81
|
+
*/
|
|
82
|
+
getGraphQLClient() {
|
|
83
|
+
if (!this.config.clientFactory) {
|
|
84
|
+
throw new Error('clientFactory needs to be provided when initializing GraphQL client.');
|
|
85
|
+
}
|
|
86
|
+
return this.config.clientFactory({
|
|
87
|
+
debugger: debug_1.default.multisite,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
getCacheKey() {
|
|
91
|
+
return 'siteinfo-service-cache';
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.SiteInfoService = SiteInfoService;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SitemapXmlService = void 0;
|
|
7
|
+
const debug_1 = __importDefault(require("../debug"));
|
|
8
|
+
const constants_1 = require("../constants");
|
|
9
|
+
const PREFIX_NAME_SITEMAP = 'sitemap';
|
|
10
|
+
// The default query for request sitemaps
|
|
11
|
+
const defaultQuery = /* GraphQL */ `
|
|
12
|
+
query SitemapQuery($siteName: String!) {
|
|
13
|
+
site {
|
|
14
|
+
siteInfo(site: $siteName) {
|
|
15
|
+
sitemap
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
/**
|
|
21
|
+
* Service that fetch the sitemaps data using Sitecore's GraphQL API.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
class SitemapXmlService {
|
|
25
|
+
/**
|
|
26
|
+
* Creates an instance of graphQL sitemaps service with the provided options
|
|
27
|
+
* @param {SitemapXmlServiceConfig} options instance
|
|
28
|
+
*/
|
|
29
|
+
constructor(options) {
|
|
30
|
+
this.options = options;
|
|
31
|
+
this.graphQLClient = this.getGraphQLClient();
|
|
32
|
+
}
|
|
33
|
+
get query() {
|
|
34
|
+
return defaultQuery;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Fetch list of sitemaps for the site
|
|
38
|
+
* @returns {string[]} list of sitemap paths
|
|
39
|
+
* @param {FetchOptions} [fetchOptions] Options to override graphQL client details like retries and fetch implementation
|
|
40
|
+
* @throws {Error} if the siteName is empty.
|
|
41
|
+
*/
|
|
42
|
+
async fetchSitemaps(fetchOptions) {
|
|
43
|
+
const siteName = this.options.siteName;
|
|
44
|
+
if (!siteName) {
|
|
45
|
+
throw new Error(constants_1.siteNameError);
|
|
46
|
+
}
|
|
47
|
+
const sitemapResult = this.graphQLClient.request(this.query, {
|
|
48
|
+
siteName,
|
|
49
|
+
}, fetchOptions);
|
|
50
|
+
try {
|
|
51
|
+
return sitemapResult.then((result) => result.site.siteInfo.sitemap);
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
return Promise.reject(e);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get sitemap file path for sitemap id
|
|
59
|
+
* @param {string} id the sitemap id (can be empty for default 'sitemap.xml' file)
|
|
60
|
+
* @returns {string | undefined} the sitemap file path or undefined if one doesn't exist
|
|
61
|
+
*/
|
|
62
|
+
async getSitemap(id) {
|
|
63
|
+
let searchSitemap;
|
|
64
|
+
if (id === undefined) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
else if (id === '') {
|
|
68
|
+
searchSitemap = `${PREFIX_NAME_SITEMAP}.xml`;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const normalizedId = id.startsWith('-') ? id.slice(1) : id;
|
|
72
|
+
searchSitemap = `${PREFIX_NAME_SITEMAP}-${normalizedId}.xml`;
|
|
73
|
+
}
|
|
74
|
+
const sitemaps = await this.fetchSitemaps();
|
|
75
|
+
return sitemaps.find((sitemap) => sitemap.includes(searchSitemap));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
|
|
79
|
+
* library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
|
|
80
|
+
* want to use something else.
|
|
81
|
+
* @returns {GraphQLClient} implementation
|
|
82
|
+
*/
|
|
83
|
+
getGraphQLClient() {
|
|
84
|
+
if (!this.options.clientFactory) {
|
|
85
|
+
throw new Error('clientFactory needs to be provided when initializing GraphQL client.');
|
|
86
|
+
}
|
|
87
|
+
return this.options.clientFactory({
|
|
88
|
+
debugger: debug_1.default.sitemap,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.SitemapXmlService = SitemapXmlService;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SitePathService = exports.sitesError = exports.siteError = exports.languageError = void 0;
|
|
7
|
+
exports.getSiteEmptyError = getSiteEmptyError;
|
|
8
|
+
const personalize_1 = require("../personalize");
|
|
9
|
+
const site_1 = require("../site");
|
|
10
|
+
const debug_1 = __importDefault(require("../debug"));
|
|
11
|
+
/** @private */
|
|
12
|
+
exports.languageError = 'The list of languages cannot be empty';
|
|
13
|
+
exports.siteError = 'The service needs a site name';
|
|
14
|
+
exports.sitesError = 'The list of sites cannot be empty';
|
|
15
|
+
/**
|
|
16
|
+
* @param {string} siteName to inject into error text
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
function getSiteEmptyError(siteName) {
|
|
20
|
+
return `Site "${siteName}" does not exist or site item tree is missing`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* GQL query made dynamic based whether personalization is enabled or not
|
|
24
|
+
* @param {boolean} usesPersonalize flag to detrmine which variation of a query to run
|
|
25
|
+
* @returns GraphQL query to fetch site paths with
|
|
26
|
+
*/
|
|
27
|
+
const defaultQuery = (usesPersonalize) => /* GraphQL */ `
|
|
28
|
+
query ${usesPersonalize ? 'PersonalizeSitemapQuery' : 'DefaultSitemapQuery'}(
|
|
29
|
+
$siteName: String!
|
|
30
|
+
$language: String!
|
|
31
|
+
$includedPaths: [String]
|
|
32
|
+
$excludedPaths: [String]
|
|
33
|
+
$pageSize: Int = 100
|
|
34
|
+
$after: String
|
|
35
|
+
) {
|
|
36
|
+
site {
|
|
37
|
+
siteInfo(site: $siteName) {
|
|
38
|
+
routes(
|
|
39
|
+
language: $language
|
|
40
|
+
includedPaths: $includedPaths
|
|
41
|
+
excludedPaths: $excludedPaths
|
|
42
|
+
first: $pageSize
|
|
43
|
+
after: $after
|
|
44
|
+
){
|
|
45
|
+
total
|
|
46
|
+
pageInfo {
|
|
47
|
+
endCursor
|
|
48
|
+
hasNext
|
|
49
|
+
}
|
|
50
|
+
results {
|
|
51
|
+
path: routePath
|
|
52
|
+
${usesPersonalize
|
|
53
|
+
? `
|
|
54
|
+
route {
|
|
55
|
+
personalization {
|
|
56
|
+
variantIds
|
|
57
|
+
}
|
|
58
|
+
}`
|
|
59
|
+
: ''}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
`;
|
|
66
|
+
/**
|
|
67
|
+
* Service that fetches the list of site pages using Sitecore's GraphQL API.
|
|
68
|
+
* Used to handle a single site
|
|
69
|
+
* This list is used for SSG and Export functionality.
|
|
70
|
+
* @mixes SearchQueryService<PageListQueryResult>
|
|
71
|
+
* @public
|
|
72
|
+
*/
|
|
73
|
+
class SitePathService {
|
|
74
|
+
/**
|
|
75
|
+
* Creates an instance of graphQL sitemap service with the provided options
|
|
76
|
+
* @param {SitePathServiceConfig} 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 a flat list of all pages that belong to all the requested sites and have a
|
|
96
|
+
* version in the specified language(s).
|
|
97
|
+
* @param {string[]} sites Fetch pages for these sites.
|
|
98
|
+
* @param {string[]} languages Fetch pages that have versions in this language(s).
|
|
99
|
+
* @param {FetchOptions} fetchOptions Options to override graphQL client details like retries and fetch implementation
|
|
100
|
+
* @returns list of pages
|
|
101
|
+
* @throws {RangeError} if the list of languages is empty.
|
|
102
|
+
* @throws {RangeError} if the any of the languages is an empty string.
|
|
103
|
+
*/
|
|
104
|
+
async fetchSiteRoutes(sites, languages, fetchOptions) {
|
|
105
|
+
const formatPath = (path, locale) => ({
|
|
106
|
+
params: {
|
|
107
|
+
path,
|
|
108
|
+
},
|
|
109
|
+
locale,
|
|
110
|
+
});
|
|
111
|
+
const paths = new Array();
|
|
112
|
+
if (!languages.length) {
|
|
113
|
+
throw new RangeError(exports.languageError);
|
|
114
|
+
}
|
|
115
|
+
// Get all sites
|
|
116
|
+
if (!sites || !sites.length) {
|
|
117
|
+
throw new RangeError(exports.sitesError);
|
|
118
|
+
}
|
|
119
|
+
// Fetch paths for each site
|
|
120
|
+
for (let i = 0; i < sites.length; i++) {
|
|
121
|
+
for (const language of languages) {
|
|
122
|
+
// Fetch paths using all locales
|
|
123
|
+
const sitePaths = await this.fetchLanguageSitePaths(language, sites[i], fetchOptions);
|
|
124
|
+
const transformedPaths = await this.transformLanguageSitePaths(sitePaths, formatPath, language);
|
|
125
|
+
paths.push(...transformedPaths);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return [].concat(...paths);
|
|
129
|
+
}
|
|
130
|
+
async transformLanguageSitePaths(sitePaths, formatStaticPath, language) {
|
|
131
|
+
const toSegments = (p) => decodeURI(p)
|
|
132
|
+
.replace(/^\/|\/$/g, '')
|
|
133
|
+
.split('/');
|
|
134
|
+
const aggregatedPaths = [];
|
|
135
|
+
sitePaths.forEach((item) => {
|
|
136
|
+
var _a, _b, _c;
|
|
137
|
+
if (!item)
|
|
138
|
+
return;
|
|
139
|
+
aggregatedPaths.push(formatStaticPath(toSegments(item.path), language));
|
|
140
|
+
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
|
|
141
|
+
);
|
|
142
|
+
if (variantIds === null || variantIds === void 0 ? void 0 : variantIds.length) {
|
|
143
|
+
aggregatedPaths.push(...variantIds.map((varId) => formatStaticPath(toSegments((0, personalize_1.getPersonalizedRewrite)(item.path, [varId])), language)));
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
return aggregatedPaths;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
|
|
150
|
+
* library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
|
|
151
|
+
* want to use something else.
|
|
152
|
+
* @returns {GraphQLClient} implementation
|
|
153
|
+
*/
|
|
154
|
+
getGraphQLClient() {
|
|
155
|
+
if (!this.options.clientFactory) {
|
|
156
|
+
throw new Error('clientFactory needs to be provided when initializing GraphQL client.');
|
|
157
|
+
}
|
|
158
|
+
return this.options.clientFactory({
|
|
159
|
+
debugger: debug_1.default.sitemap,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Fetch and return site paths for multisite implementation, with prefixes included
|
|
164
|
+
* @param {string} language path language
|
|
165
|
+
* @param {string} siteName site name
|
|
166
|
+
* @param {FetchOptions} fetchOptions Options to override graphQL client details like retries and fetch implementation
|
|
167
|
+
* @returns modified paths
|
|
168
|
+
*/
|
|
169
|
+
async fetchLanguageSitePaths(language, siteName, fetchOptions) {
|
|
170
|
+
var _a, _b, _c, _d;
|
|
171
|
+
const args = {
|
|
172
|
+
siteName: siteName,
|
|
173
|
+
language: language,
|
|
174
|
+
pageSize: this.options.pageSize,
|
|
175
|
+
includedPaths: this.options.includedPaths,
|
|
176
|
+
excludedPaths: this.options.excludedPaths,
|
|
177
|
+
};
|
|
178
|
+
let results = [];
|
|
179
|
+
let hasNext = true;
|
|
180
|
+
let after = '';
|
|
181
|
+
debug_1.default.sitemap('fetching sitemap data for %s %s', language, siteName);
|
|
182
|
+
while (hasNext) {
|
|
183
|
+
const fetchResponse = await this.graphQLClient.request(this.query, Object.assign(Object.assign({}, args), { after }), fetchOptions);
|
|
184
|
+
if (!((_a = fetchResponse === null || fetchResponse === void 0 ? void 0 : fetchResponse.site) === null || _a === void 0 ? void 0 : _a.siteInfo)) {
|
|
185
|
+
throw new RangeError(getSiteEmptyError(siteName));
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
results = results.concat((_b = fetchResponse.site.siteInfo.routes) === null || _b === void 0 ? void 0 : _b.results);
|
|
189
|
+
hasNext = (_c = fetchResponse.site.siteInfo.routes) === null || _c === void 0 ? void 0 : _c.pageInfo.hasNext;
|
|
190
|
+
after = (_d = fetchResponse.site.siteInfo.routes) === null || _d === void 0 ? void 0 : _d.pageInfo.endCursor;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
results.forEach((item) => {
|
|
194
|
+
if (item) {
|
|
195
|
+
item.path = (0, site_1.getSiteRewrite)(item.path, { siteName: siteName });
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
return results;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
exports.SitePathService = SitePathService;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SITE_KEY = exports.SITE_PREFIX = void 0;
|
|
4
|
+
exports.getSiteRewrite = getSiteRewrite;
|
|
5
|
+
exports.getSiteRewriteData = getSiteRewriteData;
|
|
6
|
+
exports.normalizeSiteRewrite = normalizeSiteRewrite;
|
|
7
|
+
/**
|
|
8
|
+
* Site prefix for rewrite path
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
exports.SITE_PREFIX = '_site_';
|
|
12
|
+
/**
|
|
13
|
+
* Site key for cookie and query string parameter access
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
exports.SITE_KEY = 'sc_site';
|
|
17
|
+
/**
|
|
18
|
+
* Get a site rewrite path for given pathname
|
|
19
|
+
* @param {string} pathname the pathname
|
|
20
|
+
* @param {SiteRewriteData} data the site data to include in the rewrite
|
|
21
|
+
* @returns {string} the rewrite path
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
function getSiteRewrite(pathname, data) {
|
|
25
|
+
const path = pathname.startsWith('/') ? pathname : '/' + pathname;
|
|
26
|
+
return `/${exports.SITE_PREFIX}${data.siteName}${path}`;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get site data from the rewrite path
|
|
30
|
+
* @param {string} pathname the pathname
|
|
31
|
+
* @param {string} defaultSiteName the default site name
|
|
32
|
+
* @returns {SiteRewriteData} the site data from the rewrite
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
function getSiteRewriteData(pathname, defaultSiteName) {
|
|
36
|
+
const data = {
|
|
37
|
+
siteName: defaultSiteName,
|
|
38
|
+
};
|
|
39
|
+
const path = pathname.endsWith('/') ? pathname : pathname + '/';
|
|
40
|
+
const result = path.match(`${exports.SITE_PREFIX}(.*?)\\/`);
|
|
41
|
+
if (result && result[1] !== '') {
|
|
42
|
+
data.siteName = result[1];
|
|
43
|
+
}
|
|
44
|
+
return data;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Normalize a site rewrite path (remove site data)
|
|
48
|
+
* @param {string} pathname the pathname
|
|
49
|
+
* @returns {string} the pathname with site data removed
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
function normalizeSiteRewrite(pathname) {
|
|
53
|
+
const result = pathname.match(`${exports.SITE_PREFIX}.*?(?:\\/|$)`);
|
|
54
|
+
return result === null ? pathname : pathname.replace(result[0], '');
|
|
55
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SitecoreServiceBase = void 0;
|
|
4
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
5
|
+
/**
|
|
6
|
+
* Base abstraction to implement custom layout service
|
|
7
|
+
*/
|
|
8
|
+
class SitecoreServiceBase {
|
|
9
|
+
/**
|
|
10
|
+
* Fetch layout data using the Sitecore GraphQL endpoint.
|
|
11
|
+
* @param {GraphQLServiceConfig} serviceConfig configuration
|
|
12
|
+
*/
|
|
13
|
+
constructor(serviceConfig) {
|
|
14
|
+
this.serviceConfig = serviceConfig;
|
|
15
|
+
this.graphQLClient = this.getGraphQLClient();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Gets a GraphQL client that can make requests to the API.
|
|
19
|
+
* @returns {GraphQLClient} implementation
|
|
20
|
+
*/
|
|
21
|
+
getGraphQLClient() {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
if (!this.serviceConfig.clientFactory) {
|
|
24
|
+
throw new Error('clientFactory needs to be provided when initializing GraphQL client.');
|
|
25
|
+
}
|
|
26
|
+
return this.serviceConfig.clientFactory({
|
|
27
|
+
debugger: this.serviceConfig.debugger || core_1.debug.http,
|
|
28
|
+
retries: (_a = this.serviceConfig.retries) === null || _a === void 0 ? void 0 : _a.count,
|
|
29
|
+
retryStrategy: (_b = this.serviceConfig.retries) === null || _b === void 0 ? void 0 : _b.retryStrategy,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.SitecoreServiceBase = SitecoreServiceBase;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getComponentSpec = exports.getComponentSpecUrl = void 0;
|
|
4
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
5
|
+
const { SITECORE_EDGE_URL_DEFAULT } = core_1.constants;
|
|
6
|
+
/**
|
|
7
|
+
* Gets the component spec url.
|
|
8
|
+
* @param {GetComponentSpecParams} params - The parameters for getting the component spec url.
|
|
9
|
+
* @returns {string} The component spec url.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
const getComponentSpecUrl = ({ componentId, edgeUrl = SITECORE_EDGE_URL_DEFAULT, targetPath, token, }) => {
|
|
13
|
+
let url = `${edgeUrl}/authoring/api/v1/components/generated/${componentId}?token=${token}`;
|
|
14
|
+
if (targetPath) {
|
|
15
|
+
url += `&targetPath=${encodeURIComponent(targetPath)}`;
|
|
16
|
+
}
|
|
17
|
+
return url;
|
|
18
|
+
};
|
|
19
|
+
exports.getComponentSpecUrl = getComponentSpecUrl;
|
|
20
|
+
/**
|
|
21
|
+
* Fetches the component spec.
|
|
22
|
+
* @param {GetComponentSpecParams} params - The parameters for fetching the component spec.
|
|
23
|
+
* @returns {Promise<ComponentSpec>} The component spec.
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
const getComponentSpec = async ({ componentId, edgeUrl = SITECORE_EDGE_URL_DEFAULT, targetPath, token, }) => {
|
|
27
|
+
const url = (0, exports.getComponentSpecUrl)({ componentId, edgeUrl, targetPath, token });
|
|
28
|
+
core_1.debug.common('Fetching component spec for %s: %s', componentId, url);
|
|
29
|
+
try {
|
|
30
|
+
const response = await fetch(url);
|
|
31
|
+
if (response.status === 404) {
|
|
32
|
+
throw new Error(`Component '${componentId}' was not found. Please verify the component ID is correct and exists.`);
|
|
33
|
+
}
|
|
34
|
+
if (response.status === 401) {
|
|
35
|
+
throw new Error('The token is incorrect or expired or the component ID is incorrect.');
|
|
36
|
+
}
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
throw new Error(`Failed to fetch component ${componentId}`);
|
|
39
|
+
}
|
|
40
|
+
const spec = await response.json();
|
|
41
|
+
core_1.debug.common('Component spec fetched successfully for %s: %o', componentId, spec);
|
|
42
|
+
return spec;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
core_1.debug.common('Failed to fetch component spec: %s', String(error));
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
exports.getComponentSpec = getComponentSpec;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.unitMocks = exports.extractFiles = void 0;
|
|
7
|
+
/* eslint-disable jsdoc/require-jsdoc */
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
const tools_1 = require("@sitecore-content-sdk/core/tools");
|
|
11
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
12
|
+
const path_1 = __importDefault(require("path"));
|
|
13
|
+
const fs_1 = __importDefault(require("fs"));
|
|
14
|
+
/**
|
|
15
|
+
* Extracts components from the app folder and sends them to XMCloud.
|
|
16
|
+
* @param {ExtractFilesConfig} args - Config for components extraction
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
exports.extractFiles = _extractFiles;
|
|
20
|
+
// mock setup for unit tests to make sinon happy and mock-able with esbuild/tsx
|
|
21
|
+
// https://sinonjs.org/how-to/typescript-swc/
|
|
22
|
+
// This, plus the `_` names make the exports writable for sinon
|
|
23
|
+
exports.unitMocks = {
|
|
24
|
+
set extractFiles(mockImplementation) {
|
|
25
|
+
exports.extractFiles = mockImplementation;
|
|
26
|
+
},
|
|
27
|
+
get extractFiles() {
|
|
28
|
+
return _extractFiles;
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
function _extractFiles(args = {}) {
|
|
32
|
+
const authParams = {
|
|
33
|
+
clientId: process.env.SITECORE_AUTH_CLIENT_ID || '',
|
|
34
|
+
clientSecret: process.env.SITECORE_AUTH_CLIENT_SECRET || '',
|
|
35
|
+
authority: process.env.SITECORE_AUTH_AUTHORITY,
|
|
36
|
+
audience: process.env.SITECORE_AUTH_AUDIENCE,
|
|
37
|
+
};
|
|
38
|
+
const renderingHost = process.env.SITECORE_RENDERINGHOST_NAME;
|
|
39
|
+
return async ({ scConfig } = {}) => {
|
|
40
|
+
var _a;
|
|
41
|
+
const config = (_a = args.scConfig) !== null && _a !== void 0 ? _a : scConfig;
|
|
42
|
+
if (!config) {
|
|
43
|
+
throw new Error('Sitecore configuration is required to be provided');
|
|
44
|
+
}
|
|
45
|
+
if ((args.customValidateDeployContext && !args.customValidateDeployContext()) ||
|
|
46
|
+
!(0, utils_1.validateDeployContext)()) {
|
|
47
|
+
core_1.debug.common('Skipping code extraction, not in deploy context');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (config.disableCodeGeneration) {
|
|
51
|
+
core_1.debug.common('Skipping code extraction, code generation has been disabled');
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
console.log(chalk_1.default.green('Code extraction started'));
|
|
55
|
+
const basePath = process.cwd();
|
|
56
|
+
try {
|
|
57
|
+
// Use Edge Platform mesh endpoint - staging is ready, prod QA in progress
|
|
58
|
+
const targetUrl = config.api.edge.edgeUrl;
|
|
59
|
+
const { accessToken } = await tools_1.auth.clientCredentialsFlow(authParams);
|
|
60
|
+
if (!accessToken) {
|
|
61
|
+
console.error(chalk_1.default.red('Failed to get access token, aborting code extraction'));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
// Resolve files from component-map
|
|
65
|
+
const resolvedImports = await (0, utils_1.resolveComponentImportFiles)(basePath, args.componentMapPath);
|
|
66
|
+
const clientComponentMapPath = args.clientComponentMapPath || '.sitecore/component-map.client.ts';
|
|
67
|
+
const absClientMapPath = path_1.default.isAbsolute(clientComponentMapPath)
|
|
68
|
+
? clientComponentMapPath
|
|
69
|
+
: path_1.default.resolve(basePath, clientComponentMapPath);
|
|
70
|
+
const exists = fs_1.default.existsSync(absClientMapPath);
|
|
71
|
+
if (exists) {
|
|
72
|
+
resolvedImports.push(...(await (0, utils_1.resolveComponentImportFiles)(basePath, absClientMapPath)));
|
|
73
|
+
}
|
|
74
|
+
const fileDispatches = [];
|
|
75
|
+
for (const { componentKey, filePath, fileType } of resolvedImports) {
|
|
76
|
+
let extraLabels;
|
|
77
|
+
// return an array of export names (e.g., ['Default','Cooler'])
|
|
78
|
+
const variantNames = (0, utils_1.readNamedExports)(filePath);
|
|
79
|
+
extraLabels = Object.assign(Object.assign({}, (variantNames.length ? { variantNames } : {})), (renderingHost ? { renderingHost } : {}));
|
|
80
|
+
fileDispatches.push((0, utils_1.sendCode)({
|
|
81
|
+
file: {
|
|
82
|
+
labels: extraLabels,
|
|
83
|
+
name: componentKey,
|
|
84
|
+
path: filePath,
|
|
85
|
+
type: fileType,
|
|
86
|
+
},
|
|
87
|
+
targetUrl,
|
|
88
|
+
token: accessToken,
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
fileDispatches.push((0, utils_1.sendCode)({
|
|
92
|
+
file: Object.assign(Object.assign({}, (renderingHost ? { labels: { renderingHost } } : {})), { name: 'package.json', path: path_1.default.resolve(basePath, './package.json'), type: utils_1.ExtractedFileType.PackageJson }),
|
|
93
|
+
targetUrl,
|
|
94
|
+
token: accessToken,
|
|
95
|
+
}));
|
|
96
|
+
const files = await Promise.all(fileDispatches);
|
|
97
|
+
console.log(chalk_1.default.green(`Code extraction completed successfully, files extracted:\r\n${files
|
|
98
|
+
.filter((file) => file !== null)
|
|
99
|
+
.join('\r\n')}`));
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
console.warn(chalk_1.default.yellow('Error during code extraction:', error, error.stack));
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|