@contentstack/cli-utilities 1.5.5 → 1.5.7
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/helpers.d.ts +7 -0
- package/lib/helpers.js +22 -1
- package/package.json +2 -2
package/lib/helpers.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
export declare const isAuthenticated: () => boolean;
|
|
2
2
|
export declare const doesBranchExist: (stack: any, branchName: any) => Promise<any>;
|
|
3
|
+
export declare const isManagementTokenValid: (stackAPIKey: any, managementToken: any) => Promise<{
|
|
4
|
+
valid: boolean;
|
|
5
|
+
message: any;
|
|
6
|
+
} | {
|
|
7
|
+
message: string;
|
|
8
|
+
valid?: undefined;
|
|
9
|
+
}>;
|
package/lib/helpers.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.doesBranchExist = exports.isAuthenticated = void 0;
|
|
3
|
+
exports.isManagementTokenValid = exports.doesBranchExist = exports.isAuthenticated = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const auth_handler_1 = tslib_1.__importDefault(require("./auth-handler"));
|
|
6
|
+
const _1 = require(".");
|
|
6
7
|
const isAuthenticated = () => auth_handler_1.default.isAuthenticated();
|
|
7
8
|
exports.isAuthenticated = isAuthenticated;
|
|
8
9
|
const doesBranchExist = async (stack, branchName) => {
|
|
@@ -14,3 +15,23 @@ const doesBranchExist = async (stack, branchName) => {
|
|
|
14
15
|
});
|
|
15
16
|
};
|
|
16
17
|
exports.doesBranchExist = doesBranchExist;
|
|
18
|
+
const isManagementTokenValid = async (stackAPIKey, managementToken) => {
|
|
19
|
+
var _a;
|
|
20
|
+
const httpClient = new _1.HttpClient({ headers: { api_key: stackAPIKey, authorization: managementToken } });
|
|
21
|
+
try {
|
|
22
|
+
const response = (_a = (await httpClient.get(`${_1.configHandler.get('region').cma}/v3/environments?limit=1`))) === null || _a === void 0 ? void 0 : _a.data;
|
|
23
|
+
if (response === null || response === void 0 ? void 0 : response.environments) {
|
|
24
|
+
return { valid: true, message: `valid token and stack api key` };
|
|
25
|
+
}
|
|
26
|
+
else if (response === null || response === void 0 ? void 0 : response.error_code) {
|
|
27
|
+
return { valid: false, message: response.error_message };
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
throw typeof response === "string" ? response : "";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
return { message: `Failed to check the validity of the Management token. ${error}` };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
exports.isManagementTokenValid = isManagementTokenValid;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-utilities",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.7",
|
|
4
4
|
"description": "Utilities for contentstack projects",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"author": "contentstack",
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@contentstack/management": "~1.
|
|
35
|
+
"@contentstack/management": "~1.12.0",
|
|
36
36
|
"@oclif/core": "^2.9.3",
|
|
37
37
|
"axios": "^1.6.0",
|
|
38
38
|
"chalk": "^4.0.0",
|