@sitecore-content-sdk/nextjs 0.2.0-beta.13 → 0.2.0-beta.15
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/dist/cjs/tools/codegen/extract-files.js +17 -12
- package/dist/cjs/tools/codegen/utils.js +7 -6
- package/dist/esm/tools/codegen/extract-files.js +18 -13
- package/dist/esm/tools/codegen/utils.js +7 -6
- package/package.json +4 -4
- package/types/tools/codegen/extract-files.d.ts +1 -0
- package/types/tools/codegen/utils.d.ts +1 -1
|
@@ -15,8 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.extractFiles = void 0;
|
|
16
16
|
const chalk_1 = __importDefault(require("chalk"));
|
|
17
17
|
const utils_1 = require("./utils");
|
|
18
|
-
const core_1 = require("@sitecore-content-sdk/core");
|
|
19
18
|
const tools_1 = require("@sitecore-content-sdk/core/tools");
|
|
19
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
20
20
|
const path_1 = __importDefault(require("path"));
|
|
21
21
|
/**
|
|
22
22
|
* Extracts components from the app folder and sends them to XMCloud.
|
|
@@ -26,25 +26,27 @@ const extractFiles = (args) => {
|
|
|
26
26
|
const authParams = {
|
|
27
27
|
clientId: process.env.SITECORE_AUTH_CLIENT_ID || '',
|
|
28
28
|
clientSecret: process.env.SITECORE_AUTH_CLIENT_SECRET || '',
|
|
29
|
-
|
|
30
|
-
audience: process.env.SITECORE_AUTH_AUDIENCE
|
|
29
|
+
authority: process.env.SITECORE_AUTH_AUTHORITY,
|
|
30
|
+
audience: process.env.SITECORE_AUTH_AUDIENCE,
|
|
31
31
|
};
|
|
32
32
|
return () => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
-
if (
|
|
34
|
-
|
|
33
|
+
if ((args.customValidateDeployContext && !args.customValidateDeployContext()) ||
|
|
34
|
+
!(0, utils_1.validateDeployContext)()) {
|
|
35
|
+
core_1.debug.common('Skipping code extraction, not in deploy context');
|
|
35
36
|
return;
|
|
36
37
|
}
|
|
37
38
|
if (!(0, utils_1.validateConsent)()) {
|
|
38
39
|
console.log(chalk_1.default.yellow('Skipping code extraction, consent not given'));
|
|
39
40
|
return;
|
|
40
41
|
}
|
|
42
|
+
console.log(chalk_1.default.green('Code extraction started'));
|
|
41
43
|
const basePath = process.cwd();
|
|
42
44
|
try {
|
|
43
45
|
// MESH_URL is temporary option to use until mesh is onboarded into Edge Proxy
|
|
44
46
|
const targetUrl = process.env.SITECORE_MESH_URL || args.scConfig.api.edge.edgeUrl;
|
|
45
|
-
const
|
|
46
|
-
if (!
|
|
47
|
-
console.error(chalk_1.default.red('Failed to get
|
|
47
|
+
const { accessToken } = yield tools_1.auth.clientCredentialsFlow(authParams);
|
|
48
|
+
if (!accessToken) {
|
|
49
|
+
console.error(chalk_1.default.red('Failed to get access token, aborting code extraction'));
|
|
48
50
|
return;
|
|
49
51
|
}
|
|
50
52
|
const componentPaths = yield (0, utils_1.resolveComponentImportFiles)(basePath, args.componentMapPath);
|
|
@@ -54,7 +56,7 @@ const extractFiles = (args) => {
|
|
|
54
56
|
path: mapEntry[1],
|
|
55
57
|
type: utils_1.ExtractedFileType.Component,
|
|
56
58
|
},
|
|
57
|
-
token:
|
|
59
|
+
token: accessToken,
|
|
58
60
|
targetUrl,
|
|
59
61
|
}));
|
|
60
62
|
fileDispatches.push((0, utils_1.sendCode)({
|
|
@@ -63,13 +65,16 @@ const extractFiles = (args) => {
|
|
|
63
65
|
path: path_1.default.resolve(basePath, './package.json'),
|
|
64
66
|
type: utils_1.ExtractedFileType.PackageJson,
|
|
65
67
|
},
|
|
66
|
-
token:
|
|
68
|
+
token: accessToken,
|
|
67
69
|
targetUrl,
|
|
68
70
|
}));
|
|
69
|
-
yield Promise.all(fileDispatches);
|
|
71
|
+
const files = yield Promise.all(fileDispatches);
|
|
72
|
+
console.log(chalk_1.default.green(`Code extraction completed successfully, files extracted:\r\n${files
|
|
73
|
+
.filter((file) => file !== null)
|
|
74
|
+
.join('\r\n')}`));
|
|
70
75
|
}
|
|
71
76
|
catch (error) {
|
|
72
|
-
console.error(chalk_1.default.red('Error during
|
|
77
|
+
console.error(chalk_1.default.red('Error during code extraction:', error));
|
|
73
78
|
}
|
|
74
79
|
});
|
|
75
80
|
};
|
|
@@ -65,8 +65,8 @@ var ExtractedFileType;
|
|
|
65
65
|
* @returns {boolean} - true if consent is given, false otherwise
|
|
66
66
|
*/
|
|
67
67
|
const validateConsent = () => {
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
var _a;
|
|
69
|
+
if (((_a = process.env.EXTRACT_CONSENT) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== 'true') {
|
|
70
70
|
return false;
|
|
71
71
|
}
|
|
72
72
|
return true;
|
|
@@ -85,7 +85,7 @@ const validateDeployContext = () => {
|
|
|
85
85
|
if (process.env.VERCEL && !process.env.VERCEL_REGION) {
|
|
86
86
|
return true;
|
|
87
87
|
}
|
|
88
|
-
if (process.env.SITECORE && process.env.
|
|
88
|
+
if (process.env.SITECORE && process.env.SITECORE_BUILD) {
|
|
89
89
|
return true;
|
|
90
90
|
}
|
|
91
91
|
return false;
|
|
@@ -228,7 +228,7 @@ const sendCode = (_a) => __awaiter(void 0, [_a], void 0, function* ({ file, toke
|
|
|
228
228
|
const apiEndpoint = `${targetUrl}/api/v1/contentsdk/code/extracted`;
|
|
229
229
|
if (!fs_1.default.existsSync(file.path)) {
|
|
230
230
|
console.error(chalk_1.default.red(`File not found: ${file.path}`));
|
|
231
|
-
return;
|
|
231
|
+
return null;
|
|
232
232
|
}
|
|
233
233
|
const code = fs_1.default.readFileSync(file.path);
|
|
234
234
|
try {
|
|
@@ -256,12 +256,13 @@ const sendCode = (_a) => __awaiter(void 0, [_a], void 0, function* ({ file, toke
|
|
|
256
256
|
url: response.url,
|
|
257
257
|
headers: response.headers,
|
|
258
258
|
});
|
|
259
|
+
return null;
|
|
259
260
|
}
|
|
260
261
|
}
|
|
261
262
|
catch (error) {
|
|
262
263
|
console.error(chalk_1.default.red(`Fetch request to send extracted code from ${file.path} failed: ${JSON.stringify(error)}`));
|
|
263
|
-
return;
|
|
264
|
+
return null;
|
|
264
265
|
}
|
|
265
|
-
|
|
266
|
+
return file.path;
|
|
266
267
|
});
|
|
267
268
|
exports.sendCode = sendCode;
|
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import chalk from 'chalk';
|
|
11
11
|
import { ExtractedFileType, resolveComponentImportFiles, sendCode, validateConsent, validateDeployContext, } from './utils';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
12
|
+
import { auth } from '@sitecore-content-sdk/core/tools';
|
|
13
|
+
import { debug } from '@sitecore-content-sdk/core';
|
|
14
14
|
import path from 'path';
|
|
15
15
|
/**
|
|
16
16
|
* Extracts components from the app folder and sends them to XMCloud.
|
|
@@ -20,25 +20,27 @@ export const extractFiles = (args) => {
|
|
|
20
20
|
const authParams = {
|
|
21
21
|
clientId: process.env.SITECORE_AUTH_CLIENT_ID || '',
|
|
22
22
|
clientSecret: process.env.SITECORE_AUTH_CLIENT_SECRET || '',
|
|
23
|
-
|
|
24
|
-
audience: process.env.SITECORE_AUTH_AUDIENCE
|
|
23
|
+
authority: process.env.SITECORE_AUTH_AUTHORITY,
|
|
24
|
+
audience: process.env.SITECORE_AUTH_AUDIENCE,
|
|
25
25
|
};
|
|
26
26
|
return () => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
-
if (!
|
|
28
|
-
|
|
27
|
+
if ((args.customValidateDeployContext && !args.customValidateDeployContext()) ||
|
|
28
|
+
!validateDeployContext()) {
|
|
29
|
+
debug.common('Skipping code extraction, not in deploy context');
|
|
29
30
|
return;
|
|
30
31
|
}
|
|
31
32
|
if (!validateConsent()) {
|
|
32
33
|
console.log(chalk.yellow('Skipping code extraction, consent not given'));
|
|
33
34
|
return;
|
|
34
35
|
}
|
|
36
|
+
console.log(chalk.green('Code extraction started'));
|
|
35
37
|
const basePath = process.cwd();
|
|
36
38
|
try {
|
|
37
39
|
// MESH_URL is temporary option to use until mesh is onboarded into Edge Proxy
|
|
38
40
|
const targetUrl = process.env.SITECORE_MESH_URL || args.scConfig.api.edge.edgeUrl;
|
|
39
|
-
const
|
|
40
|
-
if (!
|
|
41
|
-
console.error(chalk.red('Failed to get
|
|
41
|
+
const { accessToken } = yield auth.clientCredentialsFlow(authParams);
|
|
42
|
+
if (!accessToken) {
|
|
43
|
+
console.error(chalk.red('Failed to get access token, aborting code extraction'));
|
|
42
44
|
return;
|
|
43
45
|
}
|
|
44
46
|
const componentPaths = yield resolveComponentImportFiles(basePath, args.componentMapPath);
|
|
@@ -48,7 +50,7 @@ export const extractFiles = (args) => {
|
|
|
48
50
|
path: mapEntry[1],
|
|
49
51
|
type: ExtractedFileType.Component,
|
|
50
52
|
},
|
|
51
|
-
token:
|
|
53
|
+
token: accessToken,
|
|
52
54
|
targetUrl,
|
|
53
55
|
}));
|
|
54
56
|
fileDispatches.push(sendCode({
|
|
@@ -57,13 +59,16 @@ export const extractFiles = (args) => {
|
|
|
57
59
|
path: path.resolve(basePath, './package.json'),
|
|
58
60
|
type: ExtractedFileType.PackageJson,
|
|
59
61
|
},
|
|
60
|
-
token:
|
|
62
|
+
token: accessToken,
|
|
61
63
|
targetUrl,
|
|
62
64
|
}));
|
|
63
|
-
yield Promise.all(fileDispatches);
|
|
65
|
+
const files = yield Promise.all(fileDispatches);
|
|
66
|
+
console.log(chalk.green(`Code extraction completed successfully, files extracted:\r\n${files
|
|
67
|
+
.filter((file) => file !== null)
|
|
68
|
+
.join('\r\n')}`));
|
|
64
69
|
}
|
|
65
70
|
catch (error) {
|
|
66
|
-
console.error(chalk.red('Error during
|
|
71
|
+
console.error(chalk.red('Error during code extraction:', error));
|
|
67
72
|
}
|
|
68
73
|
});
|
|
69
74
|
};
|
|
@@ -26,8 +26,8 @@ export var ExtractedFileType;
|
|
|
26
26
|
* @returns {boolean} - true if consent is given, false otherwise
|
|
27
27
|
*/
|
|
28
28
|
export const validateConsent = () => {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
var _a;
|
|
30
|
+
if (((_a = process.env.EXTRACT_CONSENT) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== 'true') {
|
|
31
31
|
return false;
|
|
32
32
|
}
|
|
33
33
|
return true;
|
|
@@ -45,7 +45,7 @@ export const validateDeployContext = () => {
|
|
|
45
45
|
if (process.env.VERCEL && !process.env.VERCEL_REGION) {
|
|
46
46
|
return true;
|
|
47
47
|
}
|
|
48
|
-
if (process.env.SITECORE && process.env.
|
|
48
|
+
if (process.env.SITECORE && process.env.SITECORE_BUILD) {
|
|
49
49
|
return true;
|
|
50
50
|
}
|
|
51
51
|
return false;
|
|
@@ -186,7 +186,7 @@ export const sendCode = (_a) => __awaiter(void 0, [_a], void 0, function* ({ fil
|
|
|
186
186
|
const apiEndpoint = `${targetUrl}/api/v1/contentsdk/code/extracted`;
|
|
187
187
|
if (!fs.existsSync(file.path)) {
|
|
188
188
|
console.error(chalk.red(`File not found: ${file.path}`));
|
|
189
|
-
return;
|
|
189
|
+
return null;
|
|
190
190
|
}
|
|
191
191
|
const code = fs.readFileSync(file.path);
|
|
192
192
|
try {
|
|
@@ -214,11 +214,12 @@ export const sendCode = (_a) => __awaiter(void 0, [_a], void 0, function* ({ fil
|
|
|
214
214
|
url: response.url,
|
|
215
215
|
headers: response.headers,
|
|
216
216
|
});
|
|
217
|
+
return null;
|
|
217
218
|
}
|
|
218
219
|
}
|
|
219
220
|
catch (error) {
|
|
220
221
|
console.error(chalk.red(`Fetch request to send extracted code from ${file.path} failed: ${JSON.stringify(error)}`));
|
|
221
|
-
return;
|
|
222
|
+
return null;
|
|
222
223
|
}
|
|
223
|
-
|
|
224
|
+
return file.path;
|
|
224
225
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-content-sdk/nextjs",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.15",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -79,15 +79,15 @@
|
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
81
|
"@babel/parser": "^7.27.2",
|
|
82
|
-
"@sitecore-content-sdk/core": "0.2.0-beta.
|
|
83
|
-
"@sitecore-content-sdk/react": "0.2.0-beta.
|
|
82
|
+
"@sitecore-content-sdk/core": "0.2.0-beta.15",
|
|
83
|
+
"@sitecore-content-sdk/react": "0.2.0-beta.15",
|
|
84
84
|
"recast": "^0.23.11",
|
|
85
85
|
"regex-parser": "^2.3.1",
|
|
86
86
|
"sync-disk-cache": "^2.1.0"
|
|
87
87
|
},
|
|
88
88
|
"description": "",
|
|
89
89
|
"types": "types/index.d.ts",
|
|
90
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "bd5745567f36adecc31440fa4bb53062a8ac0f2d",
|
|
91
91
|
"files": [
|
|
92
92
|
"dist",
|
|
93
93
|
"types",
|
|
@@ -2,6 +2,7 @@ import { SitecoreConfig } from '@sitecore-content-sdk/core/config';
|
|
|
2
2
|
export type ExtractFilesConfig = {
|
|
3
3
|
scConfig: SitecoreConfig;
|
|
4
4
|
componentMapPath?: string;
|
|
5
|
+
customValidateDeployContext?: () => boolean;
|
|
5
6
|
};
|
|
6
7
|
/**
|
|
7
8
|
* Extracts components from the app folder and sends them to XMCloud.
|