@contentstack/cli-utilities 1.8.1 → 1.8.3

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.
@@ -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>;
@@ -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.setOAuthBaseURL();
218
+ this.setDeveloperHubURL();
208
219
  const httpClient = new http_client_1.default().headers(headers).asFormParams();
209
220
  httpClient
210
- .post(`${this.OAuthBaseURL}/apps-api/apps/token`, payload)
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.setOAuthBaseURL();
325
+ this.setDeveloperHubURL();
315
326
  const httpClient = new http_client_1.default().headers(headers).asFormParams();
316
327
  httpClient
317
- .post(`${this.OAuthBaseURL}/apps-api/apps/token`, payload)
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
- await this.setOAuthBaseURL();
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("CLI_AUTH_LOGOUT_NO_AUTHORIZATIONS_USER"));
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("CLI_AUTH_LOGOUT_NO_AUTHORIZATIONS"));
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
- await this.setOAuthBaseURL();
432
+ this.setDeveloperHubURL();
424
433
  return httpClient
425
- .delete(`${this.OAuthBaseURL}/apps-api/manifests/${this.OAuthAppId}/authorizations/${authorizationId}`)
434
+ .delete(`${this.developerHubUrl}/manifests/${this.OAuthAppId}/authorizations/${authorizationId}`)
426
435
  .then(({ data }) => {
427
436
  return data;
428
437
  });
@@ -14,8 +14,8 @@ class ManagementSDKInitiator {
14
14
  async createAPIClient(config) {
15
15
  const option = {
16
16
  host: config.host,
17
- maxContentLength: 100000000,
18
- maxBodyLength: 1000000000,
17
+ maxContentLength: config.maxContentLength || 100000000,
18
+ maxBodyLength: config.maxBodyLength || 1000000000,
19
19
  maxRequests: 10,
20
20
  retryLimit: 3,
21
21
  timeout: 60000,
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: any) => import("recheck").Diagnostics;
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) => (0, recheck_1.checkSync)(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.1",
3
+ "version": "1.8.3",
4
4
  "description": "Utilities for contentstack projects",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -50,7 +50,7 @@
50
50
  "mkdirp": "^1.0.4",
51
51
  "open": "^8.4.2",
52
52
  "ora": "^5.4.1",
53
- "recheck": "^4.4.5",
53
+ "recheck": "~4.4.5",
54
54
  "rxjs": "^6.6.7",
55
55
  "traverse": "^0.6.11",
56
56
  "unique-string": "^2.0.0",