@contentstack/cli-utilities 2.0.0 → 2.0.1
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.js +16 -3
- package/lib/authentication-handler.js +6 -2
- package/package.json +6 -6
package/lib/auth-handler.js
CHANGED
|
@@ -91,7 +91,9 @@ class AuthHandler {
|
|
|
91
91
|
async initSDK() {
|
|
92
92
|
// Ensure we have a valid host for the SDK initialization
|
|
93
93
|
const host = this._host || this.getCmaHost();
|
|
94
|
-
|
|
94
|
+
// skipTokenValidity: true avoids calling compareOAuthExpiry here, which would deadlock
|
|
95
|
+
// when initSDK is itself called from inside a compareOAuthExpiry refresh cycle.
|
|
96
|
+
this.managementAPIClient = await (0, contentstack_management_sdk_1.default)({ host, skipTokenValidity: true });
|
|
95
97
|
this.oauthHandler = this.managementAPIClient.oauth({
|
|
96
98
|
appId: this.OAuthAppId,
|
|
97
99
|
clientId: this.OAuthClientId,
|
|
@@ -347,7 +349,17 @@ class AuthHandler {
|
|
|
347
349
|
return this.oauthRefreshInFlight;
|
|
348
350
|
}
|
|
349
351
|
this.isRefreshingToken = true;
|
|
350
|
-
|
|
352
|
+
// Set the guard promise BEFORE starting the async work so re-entrant synchronous
|
|
353
|
+
// callers (e.g. compareOAuthExpiry invoked again via refreshToken → initSDK →
|
|
354
|
+
// managementSDKClient → createAPIClient) see a non-null oauthRefreshInFlight and
|
|
355
|
+
// return early instead of starting another recursive refresh cycle.
|
|
356
|
+
let _resolve;
|
|
357
|
+
let _reject;
|
|
358
|
+
this.oauthRefreshInFlight = new Promise((res, rej) => {
|
|
359
|
+
_resolve = res;
|
|
360
|
+
_reject = rej;
|
|
361
|
+
});
|
|
362
|
+
(async () => {
|
|
351
363
|
try {
|
|
352
364
|
if (force) {
|
|
353
365
|
cli_ux_1.default.print('Forcing token refresh...');
|
|
@@ -356,10 +368,11 @@ class AuthHandler {
|
|
|
356
368
|
cli_ux_1.default.print('Token expired, refreshing the token');
|
|
357
369
|
}
|
|
358
370
|
await this.refreshToken();
|
|
371
|
+
_resolve();
|
|
359
372
|
}
|
|
360
373
|
catch (error) {
|
|
361
374
|
cli_ux_1.default.error('Error refreshing token');
|
|
362
|
-
|
|
375
|
+
_reject(error);
|
|
363
376
|
}
|
|
364
377
|
finally {
|
|
365
378
|
this.isRefreshingToken = false;
|
|
@@ -53,6 +53,11 @@ class AuthenticationHandler {
|
|
|
53
53
|
if (error.response && error.response.status) {
|
|
54
54
|
switch (error.response.status) {
|
|
55
55
|
case 401:
|
|
56
|
+
if (maxRetryCount >= 2) {
|
|
57
|
+
const errorDetails = (0, index_1.formatError)(error);
|
|
58
|
+
index_1.cliux.print(`Authentication failed after token refresh: ${errorDetails}`, { color: 'red' });
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
56
61
|
// NOTE: Refresh the token if the type is OAuth.
|
|
57
62
|
const region = index_1.configHandler.get('region') || {};
|
|
58
63
|
if (region === null || region === void 0 ? void 0 : region.cma) {
|
|
@@ -65,11 +70,10 @@ class AuthenticationHandler {
|
|
|
65
70
|
hostName = hostName || region.cma;
|
|
66
71
|
const refreshed = await this.refreshToken(hostName);
|
|
67
72
|
if (refreshed) {
|
|
68
|
-
return this.refreshAccessToken(error, maxRetryCount);
|
|
73
|
+
return this.refreshAccessToken(error, maxRetryCount + 1);
|
|
69
74
|
}
|
|
70
75
|
const errorDetails = (0, index_1.formatError)(error);
|
|
71
76
|
index_1.cliux.print(`Authentication failed: ${errorDetails}`, { color: 'red' });
|
|
72
|
-
// For Basic Auth, exit immediately without retrying
|
|
73
77
|
return;
|
|
74
78
|
}
|
|
75
79
|
break;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-utilities",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Utilities for contentstack projects",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
"author": "contentstack",
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@contentstack/management": "~1.
|
|
32
|
-
"@contentstack/marketplace-sdk": "^1.5.
|
|
31
|
+
"@contentstack/management": "~1.31.1",
|
|
32
|
+
"@contentstack/marketplace-sdk": "^1.5.4",
|
|
33
33
|
"@contentstack/utils": "~1.9.1",
|
|
34
34
|
"@oclif/core": "^4.11.14",
|
|
35
|
-
"axios": "^1.
|
|
35
|
+
"axios": "^1.20.0",
|
|
36
36
|
"chalk": "^5.6.2",
|
|
37
37
|
"cli-cursor": "^3.1.0",
|
|
38
38
|
"cli-progress": "^3.12.0",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"inquirer": "12.11.1",
|
|
44
44
|
"inquirer-search-checkbox": "^1.0.0",
|
|
45
45
|
"inquirer-search-list": "^1.2.6",
|
|
46
|
-
"js-yaml": "^4.3.
|
|
46
|
+
"js-yaml": "^4.3.2",
|
|
47
47
|
"klona": "^2.0.6",
|
|
48
48
|
"lodash": "^4.18.1",
|
|
49
49
|
"mkdirp": "^1.0.4",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
},
|
|
63
63
|
"overrides": {
|
|
64
64
|
"@oclif/core": {
|
|
65
|
-
"picomatch": "^4.0.
|
|
65
|
+
"picomatch": "^4.0.7"
|
|
66
66
|
}
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|