@contentstack/cli-utilities 2.0.0-beta.4 → 2.0.0-beta.6
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
CHANGED
|
@@ -23,7 +23,10 @@ declare class AuthHandler {
|
|
|
23
23
|
private allAuthConfigItems;
|
|
24
24
|
private oauthHandler;
|
|
25
25
|
private managementAPIClient;
|
|
26
|
+
/** True while an OAuth access-token refresh is running (for logging/diagnostics; correctness uses `oauthRefreshInFlight`). */
|
|
26
27
|
private isRefreshingToken;
|
|
28
|
+
/** Serialize OAuth refresh so concurrent API calls await the same refresh instead of proceeding with a stale token. */
|
|
29
|
+
private oauthRefreshInFlight;
|
|
27
30
|
private cmaHost;
|
|
28
31
|
set host(contentStackHost: any);
|
|
29
32
|
constructor();
|
|
@@ -45,8 +48,8 @@ declare class AuthHandler {
|
|
|
45
48
|
getAuthorisationType(): Promise<any>;
|
|
46
49
|
isAuthorisationTypeBasic(): Promise<boolean>;
|
|
47
50
|
isAuthorisationTypeOAuth(): Promise<boolean>;
|
|
48
|
-
checkExpiryAndRefresh: (force?: boolean) => Promise<void
|
|
49
|
-
compareOAuthExpiry(force?: boolean): Promise<void
|
|
51
|
+
checkExpiryAndRefresh: (force?: boolean) => Promise<void>;
|
|
52
|
+
compareOAuthExpiry(force?: boolean): Promise<void>;
|
|
50
53
|
restoreOAuthConfig(): void;
|
|
51
54
|
}
|
|
52
55
|
declare const _default: AuthHandler;
|
package/lib/auth-handler.js
CHANGED
|
@@ -22,7 +22,10 @@ class AuthHandler {
|
|
|
22
22
|
this.cmaHost = this.getCmaHost();
|
|
23
23
|
}
|
|
24
24
|
constructor() {
|
|
25
|
+
/** True while an OAuth access-token refresh is running (for logging/diagnostics; correctness uses `oauthRefreshInFlight`). */
|
|
25
26
|
this.isRefreshingToken = false; // Flag to track if a refresh operation is in progress
|
|
27
|
+
/** Serialize OAuth refresh so concurrent API calls await the same refresh instead of proceeding with a stale token. */
|
|
28
|
+
this.oauthRefreshInFlight = null;
|
|
26
29
|
this.checkExpiryAndRefresh = (force = false) => this.compareOAuthExpiry(force);
|
|
27
30
|
this.OAuthAppId = process.env.OAUTH_APP_ID || '6400aa06db64de001a31c8a9';
|
|
28
31
|
this.OAuthClientId = process.env.OAUTH_CLIENT_ID || 'Ie0FEfTzlfAHL4xM';
|
|
@@ -329,44 +332,41 @@ class AuthHandler {
|
|
|
329
332
|
return config_handler_1.default.get(this.authorisationTypeKeyName) === this.authorisationTypeOAUTHValue ? true : false;
|
|
330
333
|
}
|
|
331
334
|
async compareOAuthExpiry(force = false) {
|
|
332
|
-
// Avoid recursive refresh operations
|
|
333
|
-
if (this.isRefreshingToken) {
|
|
334
|
-
cli_ux_1.default.print('Refresh operation already in progress');
|
|
335
|
-
return Promise.resolve();
|
|
336
|
-
}
|
|
337
335
|
const oauthDateTime = config_handler_1.default.get(this.oauthDateTimeKeyName);
|
|
338
336
|
const authorisationType = config_handler_1.default.get(this.authorisationTypeKeyName);
|
|
339
337
|
if (oauthDateTime && authorisationType === this.authorisationTypeOAUTHValue) {
|
|
340
338
|
const now = new Date();
|
|
341
339
|
const oauthDate = new Date(oauthDateTime);
|
|
342
|
-
const oauthValidUpto = new Date();
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
return
|
|
340
|
+
const oauthValidUpto = new Date(oauthDate.getTime() + 59 * 60 * 1000);
|
|
341
|
+
const tokenExpired = oauthValidUpto <= now;
|
|
342
|
+
const shouldRefresh = force || tokenExpired;
|
|
343
|
+
if (!shouldRefresh) {
|
|
344
|
+
return Promise.resolve();
|
|
347
345
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
try {
|
|
357
|
-
await this.refreshToken();
|
|
358
|
-
}
|
|
359
|
-
catch (error) {
|
|
360
|
-
cli_ux_1.default.error('Error refreshing token');
|
|
361
|
-
throw error;
|
|
346
|
+
if (this.oauthRefreshInFlight) {
|
|
347
|
+
return this.oauthRefreshInFlight;
|
|
348
|
+
}
|
|
349
|
+
this.isRefreshingToken = true;
|
|
350
|
+
this.oauthRefreshInFlight = (async () => {
|
|
351
|
+
try {
|
|
352
|
+
if (force) {
|
|
353
|
+
cli_ux_1.default.print('Forcing token refresh...');
|
|
362
354
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
this.isRefreshingToken = false;
|
|
355
|
+
else {
|
|
356
|
+
cli_ux_1.default.print('Token expired, refreshing the token');
|
|
366
357
|
}
|
|
367
|
-
|
|
358
|
+
await this.refreshToken();
|
|
368
359
|
}
|
|
369
|
-
|
|
360
|
+
catch (error) {
|
|
361
|
+
cli_ux_1.default.error('Error refreshing token');
|
|
362
|
+
throw error;
|
|
363
|
+
}
|
|
364
|
+
finally {
|
|
365
|
+
this.isRefreshingToken = false;
|
|
366
|
+
this.oauthRefreshInFlight = null;
|
|
367
|
+
}
|
|
368
|
+
})();
|
|
369
|
+
return this.oauthRefreshInFlight;
|
|
370
370
|
}
|
|
371
371
|
else {
|
|
372
372
|
cli_ux_1.default.print('No OAuth configuration set.');
|
|
@@ -58,13 +58,9 @@ class CLIProgressManager {
|
|
|
58
58
|
* so output is pure timestamped log lines (per documentation).
|
|
59
59
|
*/
|
|
60
60
|
static printGlobalSummary() {
|
|
61
|
-
var _a;
|
|
62
61
|
if (!CLIProgressManager.globalSummary) {
|
|
63
62
|
return;
|
|
64
63
|
}
|
|
65
|
-
if ((_a = __1.configHandler.get('log')) === null || _a === void 0 ? void 0 : _a.showConsoleLogs) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
64
|
// Apply strategy-based corrections before printing
|
|
69
65
|
CLIProgressManager.applyStrategyCorrections();
|
|
70
66
|
// Print the final summary
|
|
@@ -468,7 +464,11 @@ class CLIProgressManager {
|
|
|
468
464
|
? (0, chalk_1.getChalk)().green(`✓ Complete (${this.successCount}/${totalProcessed})`)
|
|
469
465
|
: (0, chalk_1.getChalk)().yellow(`✓ Complete (${this.successCount}/${totalProcessed})`)
|
|
470
466
|
: (0, chalk_1.getChalk)().cyan(`${this.successCount}✓ ${this.failureCount}✗`);
|
|
471
|
-
const labelColor = totalProcessed >= this.total
|
|
467
|
+
const labelColor = totalProcessed >= this.total
|
|
468
|
+
? this.failureCount === 0
|
|
469
|
+
? (0, chalk_1.getChalk)().green
|
|
470
|
+
: (0, chalk_1.getChalk)().yellow
|
|
471
|
+
: (0, chalk_1.getChalk)().cyan;
|
|
472
472
|
const formattedName = this.formatModuleName(this.moduleName);
|
|
473
473
|
const displayName = formattedName.length > 20 ? formattedName.substring(0, 17) + '...' : formattedName;
|
|
474
474
|
this.progressBar.increment(1, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-utilities",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.6",
|
|
4
4
|
"description": "Utilities for contentstack projects",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"author": "contentstack",
|
|
34
34
|
"license": "MIT",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@contentstack/management": "~1.
|
|
36
|
+
"@contentstack/management": "~1.29.1",
|
|
37
37
|
"@contentstack/marketplace-sdk": "^1.5.0",
|
|
38
38
|
"@oclif/core": "^4.3.0",
|
|
39
39
|
"axios": "^1.13.5",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"inquirer-search-list": "^1.2.6",
|
|
50
50
|
"js-yaml": "^4.1.1",
|
|
51
51
|
"klona": "^2.0.6",
|
|
52
|
-
"lodash": "^4.
|
|
52
|
+
"lodash": "^4.18.1",
|
|
53
53
|
"mkdirp": "^1.0.4",
|
|
54
54
|
"open": "^8.4.2",
|
|
55
55
|
"ora": "^5.4.1",
|
|
@@ -82,4 +82,4 @@
|
|
|
82
82
|
"ts-node": "^10.9.2",
|
|
83
83
|
"typescript": "^5.0.0"
|
|
84
84
|
}
|
|
85
|
-
}
|
|
85
|
+
}
|