@contentstack/cli-utilities 1.6.2 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/contentstack-management-sdk.js +1 -1
- package/lib/helpers.d.ts +1 -0
- package/lib/helpers.js +54 -5
- package/package.json +6 -6
|
@@ -30,7 +30,7 @@ class ManagementSDKInitiator {
|
|
|
30
30
|
retryDelay: Math.floor(Math.random() * (8000 - 3000 + 1) + 3000),
|
|
31
31
|
logHandler: (level, data) => { },
|
|
32
32
|
retryCondition: (error) => {
|
|
33
|
-
// LINK
|
|
33
|
+
// LINK ***REMOVED***vascript/blob/72fee8ad75ba7d1d5bab8489ebbbbbbaefb1c880/src/core/stack.js#L49
|
|
34
34
|
if (error.response && error.response.status) {
|
|
35
35
|
switch (error.response.status) {
|
|
36
36
|
case 401:
|
package/lib/helpers.d.ts
CHANGED
|
@@ -17,3 +17,4 @@ export declare const sanitizePath: (str: string) => string;
|
|
|
17
17
|
export declare const validateUids: (uid: any) => boolean;
|
|
18
18
|
export declare const validateFileName: (fileName: any) => boolean;
|
|
19
19
|
export declare const validateRegex: (str: any) => import("recheck").Diagnostics;
|
|
20
|
+
export declare const formatError: (error: any) => any;
|
package/lib/helpers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateRegex = exports.validateFileName = exports.validateUids = exports.sanitizePath = exports.escapeRegExp = exports.validatePath = exports.createDeveloperHubUrl = exports.isManagementTokenValid = exports.doesBranchExist = exports.isAuthenticated = void 0;
|
|
3
|
+
exports.formatError = exports.validateRegex = exports.validateFileName = exports.validateUids = exports.sanitizePath = exports.escapeRegExp = exports.validatePath = exports.createDeveloperHubUrl = exports.isManagementTokenValid = exports.doesBranchExist = exports.isAuthenticated = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const recheck_1 = require("recheck");
|
|
6
6
|
const auth_handler_1 = tslib_1.__importDefault(require("./auth-handler"));
|
|
@@ -28,7 +28,7 @@ const isManagementTokenValid = async (stackAPIKey, managementToken) => {
|
|
|
28
28
|
return { valid: false, message: response.error_message };
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
|
-
throw typeof response ===
|
|
31
|
+
throw typeof response === 'string' ? response : '';
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
catch (error) {
|
|
@@ -61,15 +61,64 @@ exports.validatePath = validatePath;
|
|
|
61
61
|
// To escape special characters in a string
|
|
62
62
|
const escapeRegExp = (str) => str === null || str === void 0 ? void 0 : str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
63
63
|
exports.escapeRegExp = escapeRegExp;
|
|
64
|
-
// To remove the relative path
|
|
64
|
+
// To remove the relative path
|
|
65
65
|
const sanitizePath = (str) => str === null || str === void 0 ? void 0 : str.replace(/^(\.\.(\/|\\|$))+/, '');
|
|
66
66
|
exports.sanitizePath = sanitizePath;
|
|
67
|
-
// To validate the UIDs of assets
|
|
67
|
+
// To validate the UIDs of assets
|
|
68
68
|
const validateUids = (uid) => /^[a-zA-Z0-9]+$/.test(uid);
|
|
69
69
|
exports.validateUids = validateUids;
|
|
70
70
|
// Validate File name
|
|
71
71
|
const validateFileName = (fileName) => /^[a-zA-Z0-9-_\.]+$/.test(fileName);
|
|
72
72
|
exports.validateFileName = validateFileName;
|
|
73
73
|
// Validate Regex for ReDDos
|
|
74
|
-
const validateRegex = (str) => (0, recheck_1.checkSync)(str,
|
|
74
|
+
const validateRegex = (str) => (0, recheck_1.checkSync)(str, '');
|
|
75
75
|
exports.validateRegex = validateRegex;
|
|
76
|
+
const formatError = function (error) {
|
|
77
|
+
let parsedError;
|
|
78
|
+
// Parse the error
|
|
79
|
+
try {
|
|
80
|
+
if (typeof error === 'string') {
|
|
81
|
+
parsedError = JSON.parse(error);
|
|
82
|
+
}
|
|
83
|
+
else if (typeof (error === null || error === void 0 ? void 0 : error.message) === 'string') {
|
|
84
|
+
parsedError = JSON.parse(error.message);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
parsedError = error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
parsedError = error;
|
|
92
|
+
}
|
|
93
|
+
// Determine the error message
|
|
94
|
+
let message = parsedError.errorMessage || parsedError.error_message || parsedError.message || parsedError;
|
|
95
|
+
if (typeof message === 'object') {
|
|
96
|
+
message = JSON.stringify(message);
|
|
97
|
+
}
|
|
98
|
+
// If message is in JSON format, parse it to extract the actual message string
|
|
99
|
+
try {
|
|
100
|
+
const parsedMessage = JSON.parse(message);
|
|
101
|
+
if (typeof parsedMessage === 'object') {
|
|
102
|
+
message = (parsedMessage === null || parsedMessage === void 0 ? void 0 : parsedMessage.message) || message;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
// message is not in JSON format, no need to parse
|
|
107
|
+
}
|
|
108
|
+
// Append detailed error information if available
|
|
109
|
+
if (parsedError.errors && Object.keys(parsedError.errors).length > 0) {
|
|
110
|
+
const entityNames = {
|
|
111
|
+
authorization: 'Authentication',
|
|
112
|
+
api_key: 'Stack API key',
|
|
113
|
+
uid: 'Content Type',
|
|
114
|
+
access_token: 'Delivery Token',
|
|
115
|
+
};
|
|
116
|
+
message +=
|
|
117
|
+
' ' +
|
|
118
|
+
Object.entries(parsedError.errors)
|
|
119
|
+
.map(([key, value]) => `${entityNames[key] || key} ${value}`)
|
|
120
|
+
.join(' ');
|
|
121
|
+
}
|
|
122
|
+
return message;
|
|
123
|
+
};
|
|
124
|
+
exports.formatError = formatError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-utilities",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Utilities for contentstack projects",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@contentstack/management": "~1.15.3",
|
|
36
|
-
"@contentstack/marketplace-sdk": "^1.
|
|
36
|
+
"@contentstack/marketplace-sdk": "^1.2.1",
|
|
37
37
|
"@oclif/core": "^3.26.5",
|
|
38
38
|
"axios": "^1.6.4",
|
|
39
39
|
"chalk": "^4.0.0",
|
|
@@ -50,13 +50,13 @@
|
|
|
50
50
|
"mkdirp": "^1.0.4",
|
|
51
51
|
"open": "^8.4.2",
|
|
52
52
|
"ora": "^5.4.0",
|
|
53
|
+
"recheck": "^4.4.5",
|
|
53
54
|
"rxjs": "^6.6.7",
|
|
54
55
|
"traverse": "^0.6.7",
|
|
55
56
|
"unique-string": "^2.0.0",
|
|
56
|
-
"uuid": "^9.0.
|
|
57
|
+
"uuid": "^9.0.1",
|
|
57
58
|
"winston": "^3.7.2",
|
|
58
|
-
"xdg-basedir": "^4.0.0"
|
|
59
|
-
"recheck": "^4.4.5"
|
|
59
|
+
"xdg-basedir": "^4.0.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@contentstack/cli-dev-dependencies": "^1.2.4",
|
|
@@ -84,4 +84,4 @@
|
|
|
84
84
|
"tslib": "^1.13.0",
|
|
85
85
|
"typescript": "^4.9.3"
|
|
86
86
|
}
|
|
87
|
-
}
|
|
87
|
+
}
|