@contentstack/cli-utilities 1.13.2 → 1.14.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/helpers.d.ts +2 -0
- package/lib/helpers.js +17 -1
- package/package.json +1 -1
package/lib/helpers.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { ContentstackClient } from '.';
|
|
1
2
|
export declare const isAuthenticated: () => boolean;
|
|
2
3
|
export declare const doesBranchExist: (stack: any, branchName: any) => Promise<any>;
|
|
4
|
+
export declare const getBranchFromAlias: (stack: ReturnType<ContentstackClient['stack']>, branchAlias: string) => Promise<string>;
|
|
3
5
|
export declare const isManagementTokenValid: (stackAPIKey: any, managementToken: any) => Promise<{
|
|
4
6
|
valid: boolean;
|
|
5
7
|
message?: undefined;
|
package/lib/helpers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.redactObject = exports.formatError = exports.validateRegex = exports.validateFileName = exports.validateUids = exports.sanitizePath = exports.escapeRegExp = exports.validatePath = exports.createDeveloperHubUrl = exports.isManagementTokenValid = exports.doesBranchExist = exports.isAuthenticated = void 0;
|
|
3
|
+
exports.redactObject = exports.formatError = exports.validateRegex = exports.validateFileName = exports.validateUids = exports.sanitizePath = exports.escapeRegExp = exports.validatePath = exports.createDeveloperHubUrl = exports.isManagementTokenValid = exports.getBranchFromAlias = exports.doesBranchExist = exports.isAuthenticated = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const recheck_1 = require("recheck");
|
|
6
6
|
const traverse_1 = tslib_1.__importDefault(require("traverse"));
|
|
@@ -17,6 +17,22 @@ const doesBranchExist = async (stack, branchName) => {
|
|
|
17
17
|
});
|
|
18
18
|
};
|
|
19
19
|
exports.doesBranchExist = doesBranchExist;
|
|
20
|
+
const getBranchFromAlias = async (stack, branchAlias) => {
|
|
21
|
+
if (!stack || !branchAlias || typeof branchAlias !== 'string') {
|
|
22
|
+
throw new Error('Invalid input. Both stack and branch alias are required.');
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const response = await stack.branchAlias(branchAlias).fetch();
|
|
26
|
+
if (!(response === null || response === void 0 ? void 0 : response.uid)) {
|
|
27
|
+
throw new Error(`Invalid Branch Alias. No Branch found for the branch alias: ${branchAlias}`);
|
|
28
|
+
}
|
|
29
|
+
return response.uid;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
exports.getBranchFromAlias = getBranchFromAlias;
|
|
20
36
|
const isManagementTokenValid = async (stackAPIKey, managementToken) => {
|
|
21
37
|
var _a;
|
|
22
38
|
const httpClient = new _1.HttpClient({ headers: { api_key: stackAPIKey, authorization: managementToken } });
|