@contentstack/cli-utilities 1.8.2 → 1.8.4
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/auth-handler.d.ts +2 -0
- package/lib/auth-handler.js +25 -16
- package/lib/helpers.d.ts +1 -1
- package/lib/helpers.js +4 -1
- package/package.json +3 -3
package/lib/auth-handler.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Auth handler
|
|
4
4
|
*/
|
|
5
5
|
declare class AuthHandler {
|
|
6
|
+
private developerHubUrl;
|
|
6
7
|
private _host;
|
|
7
8
|
private codeVerifier;
|
|
8
9
|
private OAuthBaseURL;
|
|
@@ -27,6 +28,7 @@ declare class AuthHandler {
|
|
|
27
28
|
constructor();
|
|
28
29
|
initLog(): void;
|
|
29
30
|
setOAuthBaseURL(): Promise<void>;
|
|
31
|
+
setDeveloperHubURL(): void;
|
|
30
32
|
oauth(): Promise<object>;
|
|
31
33
|
createHTTPServer(): Promise<object>;
|
|
32
34
|
openOAuthURL(): Promise<object>;
|
package/lib/auth-handler.js
CHANGED
|
@@ -69,6 +69,17 @@ class AuthHandler {
|
|
|
69
69
|
throw new Error('Invalid ui-host URL while authenticating. Please set your region correctly using the command - csdx config:set:region');
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
+
setDeveloperHubURL() {
|
|
73
|
+
if (this.developerHubUrl) {
|
|
74
|
+
return; // Return if already set
|
|
75
|
+
}
|
|
76
|
+
if (config_handler_1.default.get('region')['developerHubUrl']) {
|
|
77
|
+
this.developerHubUrl = config_handler_1.default.get('region')['developerHubUrl'] || '';
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
throw new Error('Invalid developerHubUrl URL while authenticating. Please set your region correctly using the command - csdx config:set:region');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
72
83
|
/*
|
|
73
84
|
*
|
|
74
85
|
* Login into Contentstack
|
|
@@ -204,10 +215,10 @@ class AuthHandler {
|
|
|
204
215
|
redirect_uri: this.OAuthRedirectURL,
|
|
205
216
|
code: code,
|
|
206
217
|
};
|
|
207
|
-
this.
|
|
218
|
+
this.setDeveloperHubURL();
|
|
208
219
|
const httpClient = new http_client_1.default().headers(headers).asFormParams();
|
|
209
220
|
httpClient
|
|
210
|
-
.post(`${this.
|
|
221
|
+
.post(`${this.developerHubUrl}/apps/token`, payload)
|
|
211
222
|
.then(({ data }) => {
|
|
212
223
|
return this.getUserDetails(data);
|
|
213
224
|
})
|
|
@@ -311,10 +322,10 @@ class AuthHandler {
|
|
|
311
322
|
redirect_uri: this.OAuthRedirectURL,
|
|
312
323
|
refresh_token: configOauthRefreshToken,
|
|
313
324
|
};
|
|
314
|
-
this.
|
|
325
|
+
this.setDeveloperHubURL();
|
|
315
326
|
const httpClient = new http_client_1.default().headers(headers).asFormParams();
|
|
316
327
|
httpClient
|
|
317
|
-
.post(`${this.
|
|
328
|
+
.post(`${this.developerHubUrl}/apps/token`, payload)
|
|
318
329
|
.then(({ data }) => {
|
|
319
330
|
if (data.error || (data.statusCode != 200 && data.message)) {
|
|
320
331
|
let errorMessage = '';
|
|
@@ -379,7 +390,7 @@ class AuthHandler {
|
|
|
379
390
|
});
|
|
380
391
|
}
|
|
381
392
|
async oauthLogout() {
|
|
382
|
-
const authorization = await this.getOauthAppAuthorization() ||
|
|
393
|
+
const authorization = (await this.getOauthAppAuthorization()) || '';
|
|
383
394
|
const response = await this.revokeOauthAppAuthorization(authorization);
|
|
384
395
|
return response || {};
|
|
385
396
|
}
|
|
@@ -391,24 +402,22 @@ class AuthHandler {
|
|
|
391
402
|
const headers = {
|
|
392
403
|
authorization: `Bearer ${config_handler_1.default.get(this.oauthAccessTokenKeyName)}`,
|
|
393
404
|
organization_uid: config_handler_1.default.get(this.oauthOrgUidKeyName),
|
|
394
|
-
'Content-type': 'application/json'
|
|
405
|
+
'Content-type': 'application/json',
|
|
395
406
|
};
|
|
396
407
|
const httpClient = new http_client_1.default().headers(headers);
|
|
397
|
-
|
|
398
|
-
return httpClient
|
|
399
|
-
.get(`${this.OAuthBaseURL}/apps-api/manifests/${this.OAuthAppId}/authorizations`)
|
|
400
|
-
.then(({ data }) => {
|
|
408
|
+
this.setDeveloperHubURL();
|
|
409
|
+
return httpClient.get(`${this.developerHubUrl}/manifests/${this.OAuthAppId}/authorizations`).then(({ data }) => {
|
|
401
410
|
var _a, _b;
|
|
402
411
|
if (((_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
403
412
|
const userUid = config_handler_1.default.get(this.oauthUserUidKeyName);
|
|
404
|
-
const currentUserAuthorization = ((_b = data === null || data === void 0 ? void 0 : data.data) === null || _b === void 0 ? void 0 : _b.filter(element => element.user.uid === userUid)) || [];
|
|
413
|
+
const currentUserAuthorization = ((_b = data === null || data === void 0 ? void 0 : data.data) === null || _b === void 0 ? void 0 : _b.filter((element) => element.user.uid === userUid)) || [];
|
|
405
414
|
if (currentUserAuthorization.length === 0) {
|
|
406
|
-
throw new Error(message_handler_1.default.parse(
|
|
415
|
+
throw new Error(message_handler_1.default.parse('CLI_AUTH_LOGOUT_NO_AUTHORIZATIONS_USER'));
|
|
407
416
|
}
|
|
408
417
|
return currentUserAuthorization[0].authorization_uid; // filter authorizations by current logged in user
|
|
409
418
|
}
|
|
410
419
|
else {
|
|
411
|
-
throw new Error(message_handler_1.default.parse(
|
|
420
|
+
throw new Error(message_handler_1.default.parse('CLI_AUTH_LOGOUT_NO_AUTHORIZATIONS'));
|
|
412
421
|
}
|
|
413
422
|
});
|
|
414
423
|
}
|
|
@@ -417,12 +426,12 @@ class AuthHandler {
|
|
|
417
426
|
const headers = {
|
|
418
427
|
authorization: `Bearer ${config_handler_1.default.get(this.oauthAccessTokenKeyName)}`,
|
|
419
428
|
organization_uid: config_handler_1.default.get(this.oauthOrgUidKeyName),
|
|
420
|
-
'Content-type': 'application/json'
|
|
429
|
+
'Content-type': 'application/json',
|
|
421
430
|
};
|
|
422
431
|
const httpClient = new http_client_1.default().headers(headers);
|
|
423
|
-
|
|
432
|
+
this.setDeveloperHubURL();
|
|
424
433
|
return httpClient
|
|
425
|
-
.delete(`${this.
|
|
434
|
+
.delete(`${this.developerHubUrl}/manifests/${this.OAuthAppId}/authorizations/${authorizationId}`)
|
|
426
435
|
.then(({ data }) => {
|
|
427
436
|
return data;
|
|
428
437
|
});
|
package/lib/helpers.d.ts
CHANGED
|
@@ -16,5 +16,5 @@ export declare const escapeRegExp: (str: string) => string;
|
|
|
16
16
|
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
|
-
export declare const validateRegex: (str:
|
|
19
|
+
export declare const validateRegex: (str: unknown) => import("recheck").Diagnostics;
|
|
20
20
|
export declare const formatError: (error: any) => any;
|
package/lib/helpers.js
CHANGED
|
@@ -71,7 +71,10 @@ exports.validateUids = validateUids;
|
|
|
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) =>
|
|
74
|
+
const validateRegex = (str) => {
|
|
75
|
+
const stringValue = typeof str === 'string' ? str : str.toString();
|
|
76
|
+
return (0, recheck_1.checkSync)(stringValue, '');
|
|
77
|
+
};
|
|
75
78
|
exports.validateRegex = validateRegex;
|
|
76
79
|
const formatError = function (error) {
|
|
77
80
|
let parsedError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-utilities",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.4",
|
|
4
4
|
"description": "Utilities for contentstack projects",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@contentstack/management": "~1.18.4",
|
|
36
36
|
"@contentstack/marketplace-sdk": "^1.2.5",
|
|
37
37
|
"@oclif/core": "^3.27.0",
|
|
38
|
-
"axios": "^1.
|
|
38
|
+
"axios": "^1.8.2",
|
|
39
39
|
"chalk": "^4.1.2",
|
|
40
40
|
"cli-cursor": "^3.1.0",
|
|
41
41
|
"cli-table": "^0.3.11",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"mkdirp": "^1.0.4",
|
|
51
51
|
"open": "^8.4.2",
|
|
52
52
|
"ora": "^5.4.1",
|
|
53
|
-
"recheck": "
|
|
53
|
+
"recheck": "~4.4.5",
|
|
54
54
|
"rxjs": "^6.6.7",
|
|
55
55
|
"traverse": "^0.6.11",
|
|
56
56
|
"unique-string": "^2.0.0",
|