@contentstack/cli-utilities 1.5.6 → 1.5.8
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/add-locale.d.ts +1 -0
- package/lib/add-locale.js +19 -0
- package/lib/date-time.d.ts +2 -0
- package/lib/date-time.js +19 -0
- package/lib/helpers.d.ts +7 -0
- package/lib/helpers.js +22 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const addLocale: (apiKey: any, managementToken: any, host: any) => Promise<void>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addLocale = void 0;
|
|
4
|
+
const http_client_1 = require("./http-client");
|
|
5
|
+
const addLocale = async (apiKey, managementToken, host) => {
|
|
6
|
+
const httpClient = new http_client_1.HttpClient({
|
|
7
|
+
headers: { api_key: apiKey, authorization: managementToken },
|
|
8
|
+
});
|
|
9
|
+
const { data } = await httpClient.post(`https://${host}/v3/locales`, {
|
|
10
|
+
locale: {
|
|
11
|
+
name: 'English',
|
|
12
|
+
code: 'en-us',
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
if ([161, 105].includes(data.error_code)) {
|
|
16
|
+
throw new Error(data.error_code === 105 ? 'Sorry but you don\'t have access to this stack' : data.error_message);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
exports.addLocale = addLocale;
|
package/lib/date-time.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatTime = exports.formatDate = void 0;
|
|
4
|
+
const formatDate = (date) => {
|
|
5
|
+
return [
|
|
6
|
+
date.getFullYear(),
|
|
7
|
+
(date.getMonth() + 1).toString().padStart(2, '0'),
|
|
8
|
+
date.getDate().toString().padStart(2, '0'),
|
|
9
|
+
].join('');
|
|
10
|
+
};
|
|
11
|
+
exports.formatDate = formatDate;
|
|
12
|
+
const formatTime = (date) => {
|
|
13
|
+
return [
|
|
14
|
+
date.getHours().toString().padStart(2, '0'),
|
|
15
|
+
date.getMinutes().toString().padStart(2, '0'),
|
|
16
|
+
date.getSeconds().toString().padStart(2, '0'),
|
|
17
|
+
].join('');
|
|
18
|
+
};
|
|
19
|
+
exports.formatTime = formatTime;
|
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/lib/index.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export { default as NodeCrypto } from './encrypter';
|
|
|
13
13
|
export { Args as args, Flags as flags, Command } from './cli-ux';
|
|
14
14
|
export * from './helpers';
|
|
15
15
|
export * from './interfaces';
|
|
16
|
+
export * from './date-time';
|
|
17
|
+
export * from './add-locale';
|
|
16
18
|
export { Args, CommandHelp, Config, Errors, Flags, loadHelpClass, Help, HelpBase, HelpSection, HelpSectionRenderer, HelpSectionKeyValueTable, Hook, Interfaces, Parser, Plugin, run, toCached, tsPath, toStandardizedId, toConfiguredId, settings, Settings, flush, ux, execute, stderr, stdout, } from '@oclif/core';
|
|
17
19
|
export { FlagInput, ArgInput } from '@oclif/core/lib/interfaces/parser';
|
|
18
20
|
export { default as TablePrompt } from './inquirer-table-prompt';
|
package/lib/index.js
CHANGED
|
@@ -31,6 +31,8 @@ Object.defineProperty(exports, "flags", { enumerable: true, get: function () { r
|
|
|
31
31
|
Object.defineProperty(exports, "Command", { enumerable: true, get: function () { return cli_ux_2.Command; } });
|
|
32
32
|
tslib_1.__exportStar(require("./helpers"), exports);
|
|
33
33
|
tslib_1.__exportStar(require("./interfaces"), exports);
|
|
34
|
+
tslib_1.__exportStar(require("./date-time"), exports);
|
|
35
|
+
tslib_1.__exportStar(require("./add-locale"), exports);
|
|
34
36
|
// NOTE Exporting all @oclif/core modules: So that all the module can be acessed through cli-utility
|
|
35
37
|
var core_1 = require("@oclif/core");
|
|
36
38
|
Object.defineProperty(exports, "Args", { enumerable: true, get: function () { return core_1.Args; } });
|