@squiz/dxp-cli-next 5.5.1 → 5.6.0-develop.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/ApiService.js +10 -6
- package/lib/ApiService.spec.js +15 -0
- package/package.json +2 -2
package/lib/ApiService.js
CHANGED
|
@@ -36,16 +36,20 @@ exports.ApiService = ApiService;
|
|
|
36
36
|
* will seamlessly have the authorization required.
|
|
37
37
|
*/
|
|
38
38
|
function requestInterceptor(request) {
|
|
39
|
+
var _a;
|
|
39
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const additionalHeaders = {};
|
|
40
42
|
const maybeSessionCookie = yield (0, ApplicationStore_1.getApplicationFile)(ApplicationStore_1.STORE_FILES.sessionCookie);
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
+
if (maybeSessionCookie) {
|
|
44
|
+
additionalHeaders.cookie =
|
|
45
|
+
(_a = tough_cookie_1.Cookie.fromJSON(maybeSessionCookie)) === null || _a === void 0 ? void 0 : _a.cookieString();
|
|
46
|
+
}
|
|
47
|
+
if (process.env.DXP_JWT) {
|
|
48
|
+
additionalHeaders.authorization = `Bearer ${process.env.DXP_JWT}`;
|
|
43
49
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return request;
|
|
50
|
+
if (Object.keys(additionalHeaders).length > 0) {
|
|
51
|
+
request.headers = Object.assign(Object.assign({}, (request.headers || {})), additionalHeaders);
|
|
47
52
|
}
|
|
48
|
-
request.headers = Object.assign(Object.assign({}, (request.headers || {})), { cookie: sessionCookie === null || sessionCookie === void 0 ? void 0 : sessionCookie.cookieString() });
|
|
49
53
|
return request;
|
|
50
54
|
});
|
|
51
55
|
}
|
package/lib/ApiService.spec.js
CHANGED
|
@@ -19,6 +19,7 @@ const VALID_COOKIE = new tough_cookie_1.Cookie({
|
|
|
19
19
|
describe('ApiService', () => {
|
|
20
20
|
describe('requestInterceptor', () => {
|
|
21
21
|
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
delete process.env.DXP_JWT;
|
|
22
23
|
yield (0, ApplicationStore_1.deleteApplicationFile)(ApplicationStore_1.STORE_FILES.sessionCookie);
|
|
23
24
|
}));
|
|
24
25
|
it('loads stored session cookie into request config', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -32,6 +33,20 @@ describe('ApiService', () => {
|
|
|
32
33
|
const requestConfig = yield (0, ApiService_1.requestInterceptor)({});
|
|
33
34
|
expect(requestConfig).toEqual({});
|
|
34
35
|
}));
|
|
36
|
+
it('attaches DXP JWT as authorization header if environment variable defined', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
process.env.DXP_JWT = 'xxx.yyy.zzz';
|
|
38
|
+
const requestConfig = yield (0, ApiService_1.requestInterceptor)({
|
|
39
|
+
headers: {
|
|
40
|
+
'x-custom-header': 'header value',
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
expect(requestConfig).toEqual({
|
|
44
|
+
headers: {
|
|
45
|
+
authorization: 'Bearer xxx.yyy.zzz',
|
|
46
|
+
'x-custom-header': 'header value',
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}));
|
|
35
50
|
});
|
|
36
51
|
describe('responseInterceptor', () => {
|
|
37
52
|
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squiz/dxp-cli-next",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.0-develop.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"url": "https://gitlab.squiz.net/developer-experience/dxp-cli-next"
|
|
6
6
|
},
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"codecov"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@squiz/component-cli-lib": "1.
|
|
42
|
+
"@squiz/component-cli-lib": "1.32.1-alpha.17",
|
|
43
43
|
"axios": "1.1.3",
|
|
44
44
|
"cli-color": "2.0.3",
|
|
45
45
|
"commander": "9.4.0",
|