@squiz/dx-common-lib 1.39.1-alpha.9 → 1.40.0
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/.npm/_logs/{2023-06-26T08_03_09_170Z-debug-0.log → 2023-07-06T01_50_58_148Z-debug-0.log} +15 -15
- package/lib/api-key-validation/ApiKeyValidationService.d.ts +8 -3
- package/lib/api-key-validation/CloudflareApiKeyService.d.ts +9 -4
- package/lib/api-key-validation/CloudflareApiKeyService.js +24 -12
- package/lib/api-key-validation/CloudflareApiKeyService.js.map +1 -1
- package/lib/api-key-validation/CloudflareApiKeyService.spec.js +26 -23
- package/lib/api-key-validation/CloudflareApiKeyService.spec.js.map +1 -1
- package/lib/api-key-validation/DevelopmentApiKeyService.d.ts +8 -3
- package/lib/api-key-validation/DevelopmentApiKeyService.js +14 -5
- package/lib/api-key-validation/DevelopmentApiKeyService.js.map +1 -1
- package/lib/api-key-validation/DevelopmentApiKeyService.spec.js +10 -6
- package/lib/api-key-validation/DevelopmentApiKeyService.spec.js.map +1 -1
- package/lib/assertions/assertIsArray.d.ts +1 -0
- package/lib/assertions/assertIsArray.js +15 -0
- package/lib/assertions/assertIsArray.js.map +1 -0
- package/lib/assertions/assertIsArray.spec.js +16 -0
- package/lib/assertions/assertIsArray.spec.js.map +1 -0
- package/lib/assertions/index.d.ts +1 -0
- package/lib/assertions/index.js +1 -0
- package/lib/assertions/index.js.map +1 -1
- package/lib/formatted-text/formattedTextToHtmlString.d.ts +7 -1
- package/lib/formatted-text/formattedTextToHtmlString.js +32 -1
- package/lib/formatted-text/formattedTextToHtmlString.js.map +1 -1
- package/lib/formatted-text/formattedTextToHtmlString.spec.js +30 -0
- package/lib/formatted-text/formattedTextToHtmlString.spec.js.map +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/package.json +5 -4
- package/src/api-key-validation/ApiKeyValidationService.ts +9 -3
- package/src/api-key-validation/CloudflareApiKeyService.spec.ts +38 -24
- package/src/api-key-validation/CloudflareApiKeyService.ts +27 -13
- package/src/api-key-validation/DevelopmentApiKeyService.spec.ts +12 -6
- package/src/api-key-validation/DevelopmentApiKeyService.ts +16 -5
- package/src/assertions/assertIsArray.spec.ts +16 -0
- package/src/assertions/assertIsArray.ts +11 -0
- package/src/assertions/index.ts +1 -0
- package/src/formatted-text/formattedTextToHtmlString.spec.ts +40 -0
- package/src/formatted-text/formattedTextToHtmlString.ts +31 -2
- package/src/index.ts +0 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/server-utils/apiKeyMiddleware.d.ts +0 -6
- package/lib/server-utils/apiKeyMiddleware.js +0 -23
- package/lib/server-utils/apiKeyMiddleware.js.map +0 -1
- package/lib/server-utils/apiKeyMiddleware.spec.js +0 -40
- package/lib/server-utils/apiKeyMiddleware.spec.js.map +0 -1
- package/src/server-utils/apiKeyMiddleware.spec.ts +0 -51
- package/src/server-utils/apiKeyMiddleware.ts +0 -26
- /package/lib/{server-utils/apiKeyMiddleware.spec.d.ts → assertions/assertIsArray.spec.d.ts} +0 -0
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"formattedTextToHtmlString.spec.js","sourceRoot":"","sources":["../../src/formatted-text/formattedTextToHtmlString.spec.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"formattedTextToHtmlString.spec.js","sourceRoot":"","sources":["../../src/formatted-text/formattedTextToHtmlString.spec.ts"],"names":[],"mappings":";;;;;AACA,2EAAwE;AACxE,kDAA0B;AAK1B,MAAM,cAAc,GAAG;IACrB,IAAI,EAAE,2BAA2B;CAClC,CAAC;AACF,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,eAAK,EAAE,KAAK,CAAC,CAAC;AAC7C,WAAW,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;AAE9C,QAAQ,CAAC,2BAA2B,EAAE,GAAG,EAAE;IACzC,EAAE,CAAC,mCAAmC,EAAE,KAAK,IAAI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ACF;iBACF;gBACD;oBACE,IAAI,EAAE,MAAM;oBACZ,KAAK,EAAE,iDAAiD;iBACzD;aACF;SACF,CAAC;QAEF,MAAM,MAAM,CAAC,IAAA,qDAAyB,EAAC,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,qBAAqB,CACpF,sLAAsL,CACvL,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+BAA+B,EAAE,KAAK,IAAI,EAAE;QAC7C,MAAM,cAAc,GAAmB;YACrC,IAAI,EAAE,WAAW;YACjB,YAAY,EAAE,MAAM;YACpB,UAAU,EAAE,+DAA+D;SAC5E,CAAC;QAEF,MAAM,MAAM,CAAC,IAAA,qDAAyB,EAAC,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,qBAAqB,CACpF,6BAA6B,CAC9B,CAAC;QACF,MAAM,CAAC,WAAW,CAAC,CAAC,cAAc,CAChC,kFAAkF,CACnF,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uDAAuD,EAAE,KAAK,IAAI,EAAE;QACrE,MAAM,cAAc,GAAmB;YACrC,IAAI,EAAE,WAAW;YACjB,YAAY,EAAE,MAAM;YACpB,OAAO,EAAE;gBACP,aAAa,EAAE,KAAK;aACrB;YACD,UAAU,EAAE,+DAA+D;SAC5E,CAAC;QAEF,MAAM,MAAM,CAAC,IAAA,qDAAyB,EAAC,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,qBAAqB,CACpF,6BAA6B,CAC9B,CAAC;QACF,MAAM,CAAC,WAAW,CAAC,CAAC,cAAc,CAChC,qGAAqG,CACtG,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/lib/index.d.ts
CHANGED
@@ -8,7 +8,6 @@ export * from './api-key-validation/ApiKeyValidationService';
|
|
8
8
|
export * from './api-key-validation/CloudflareApiKeyService';
|
9
9
|
export * from './api-key-validation/DevelopmentApiKeyService';
|
10
10
|
export * from './api-key-validation/getApiKeyService';
|
11
|
-
export * from './server-utils/apiKeyMiddleware';
|
12
11
|
export * from './cache';
|
13
12
|
export * from './formatted-text/formattedTextToHtmlString';
|
14
13
|
export * from './json-order';
|
package/lib/index.js
CHANGED
@@ -24,7 +24,6 @@ __exportStar(require("./api-key-validation/ApiKeyValidationService"), exports);
|
|
24
24
|
__exportStar(require("./api-key-validation/CloudflareApiKeyService"), exports);
|
25
25
|
__exportStar(require("./api-key-validation/DevelopmentApiKeyService"), exports);
|
26
26
|
__exportStar(require("./api-key-validation/getApiKeyService"), exports);
|
27
|
-
__exportStar(require("./server-utils/apiKeyMiddleware"), exports);
|
28
27
|
__exportStar(require("./cache"), exports);
|
29
28
|
__exportStar(require("./formatted-text/formattedTextToHtmlString"), exports);
|
30
29
|
__exportStar(require("./json-order"), exports);
|
package/lib/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,0CAAwB;AACxB,yCAAuB;AACvB,qDAAmC;AACnC,iEAA+C;AAC/C,+DAA6C;AAC7C,+EAA6D;AAC7D,+EAA6D;AAC7D,gFAA8D;AAC9D,wEAAsD;AACtD,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,0CAAwB;AACxB,yCAAuB;AACvB,qDAAmC;AACnC,iEAA+C;AAC/C,+DAA6C;AAC7C,+EAA6D;AAC7D,+EAA6D;AAC7D,gFAA8D;AAC9D,wEAAsD;AACtD,0CAAwB;AACxB,6EAA2D;AAC3D,+CAA6B"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@squiz/dx-common-lib",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.40.0",
|
4
4
|
"description": "",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"scripts": {
|
@@ -13,9 +13,10 @@
|
|
13
13
|
"license": "ISC",
|
14
14
|
"dependencies": {
|
15
15
|
"@aws-sdk/client-secrets-manager": "3.218.0",
|
16
|
-
"@squiz/dx-json-schema-lib": "1.
|
17
|
-
"@squiz/dx-logger-lib": "1.
|
16
|
+
"@squiz/dx-json-schema-lib": "1.40.0",
|
17
|
+
"@squiz/dx-logger-lib": "1.40.0",
|
18
18
|
"archiver": "5.3.1",
|
19
|
+
"axios": "1.3.2",
|
19
20
|
"escape-string-regexp": "4.0.0",
|
20
21
|
"fs-extra": "11.1.0",
|
21
22
|
"lodash.clonedeep": "4.5.0"
|
@@ -35,5 +36,5 @@
|
|
35
36
|
"ts-node": "10.9.1",
|
36
37
|
"typescript": "4.9.4"
|
37
38
|
},
|
38
|
-
"gitHead": "
|
39
|
+
"gitHead": "42d08bd61b20a1a8a4bb6ccb4a9c60ababcd8f39"
|
39
40
|
}
|
@@ -1,5 +1,11 @@
|
|
1
|
+
import { IncomingMessage } from 'http';
|
2
|
+
|
1
3
|
export interface ApiKeyValidationService {
|
2
|
-
|
3
|
-
|
4
|
-
|
4
|
+
interServiceKeyIsValid(key: string | undefined): boolean;
|
5
|
+
|
6
|
+
/**
|
7
|
+
* @deprecated Suggest moving towards using JWT authentication.
|
8
|
+
*/
|
9
|
+
matrixKeyIsValid(key: string | undefined, request: IncomingMessage): boolean;
|
10
|
+
getInterServiceKeys(): string[];
|
5
11
|
}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { GetSecretValueCommand, SecretsManagerClient } from '@aws-sdk/client-secrets-manager';
|
2
2
|
import { UnAuthenticatedRequestError } from '../error/UnAuthenticatedRequestError';
|
3
3
|
import { CloudflareApiKeyService } from './CloudflareApiKeyService';
|
4
|
+
import { IncomingMessage } from 'http';
|
4
5
|
|
5
6
|
const sendSpy = jest.spyOn(SecretsManagerClient.prototype, 'send');
|
6
7
|
|
@@ -21,7 +22,9 @@ describe('CloudflareApiKeyService', () => {
|
|
21
22
|
|
22
23
|
it('should make a request to the aws secrets manager when refreshing the keys', async () => {
|
23
24
|
sendSpy.mockClear();
|
24
|
-
sendSpy.mockImplementationOnce(() =>
|
25
|
+
sendSpy.mockImplementationOnce(() =>
|
26
|
+
Promise.resolve({ SecretString: '{"matrix-keys":[], "inter-service-keys":[]}' }),
|
27
|
+
);
|
25
28
|
await service.refreshApiKeys();
|
26
29
|
|
27
30
|
expect(sendSpy.mock.lastCall[0].input).toEqual({ SecretId: 'my-secret-name' });
|
@@ -30,7 +33,9 @@ describe('CloudflareApiKeyService', () => {
|
|
30
33
|
|
31
34
|
it('should start a refresh timer once called, but only once', (done) => {
|
32
35
|
sendSpy.mockClear();
|
33
|
-
sendSpy.mockImplementationOnce(() =>
|
36
|
+
sendSpy.mockImplementationOnce(() =>
|
37
|
+
Promise.resolve({ SecretString: '{"matrix-keys":[], "inter-service-keys":["my-new-key"]}' }),
|
38
|
+
);
|
34
39
|
const spy = jest.spyOn(service, 'refreshApiKeys');
|
35
40
|
|
36
41
|
expect(spy).not.toBeCalled();
|
@@ -41,21 +46,23 @@ describe('CloudflareApiKeyService', () => {
|
|
41
46
|
|
42
47
|
jest.useRealTimers();
|
43
48
|
setTimeout(() => {
|
44
|
-
expect(service.
|
49
|
+
expect(service.interServiceKeyIsValid('my-new-key')).toEqual(true);
|
45
50
|
done();
|
46
51
|
}, 5);
|
47
52
|
});
|
48
53
|
});
|
49
54
|
|
50
|
-
describe('
|
55
|
+
describe('matrixKeyIsValid', () => {
|
51
56
|
describe('when there are no api keys', () => {
|
52
57
|
beforeAll(async () => {
|
53
|
-
sendSpy.mockImplementation(() =>
|
58
|
+
sendSpy.mockImplementation(() =>
|
59
|
+
Promise.resolve({ SecretString: '{"matrix-keys":[], "inter-service-keys":[]}' }),
|
60
|
+
);
|
54
61
|
await service.refreshApiKeys();
|
55
62
|
});
|
56
63
|
|
57
64
|
it('should throw an unauthenticated request error when validating a key if there are no keys to validate against', () => {
|
58
|
-
expect(() => service.
|
65
|
+
expect(() => service.matrixKeyIsValid('anything', {} as IncomingMessage)).toThrowError(
|
59
66
|
new UnAuthenticatedRequestError('No api keys to check against'),
|
60
67
|
);
|
61
68
|
});
|
@@ -64,35 +71,39 @@ describe('CloudflareApiKeyService', () => {
|
|
64
71
|
describe('when there are api keys', () => {
|
65
72
|
beforeAll(async () => {
|
66
73
|
sendSpy.mockImplementation(() =>
|
67
|
-
Promise.resolve({
|
74
|
+
Promise.resolve({
|
75
|
+
SecretString: '{"matrix-keys":["my-matrix-key"], "inter-service-keys":["my-inter-service-key"]}',
|
76
|
+
}),
|
68
77
|
);
|
69
78
|
await service.refreshApiKeys();
|
70
79
|
});
|
71
|
-
|
72
|
-
|
73
|
-
expect(service.
|
80
|
+
|
81
|
+
it('should return true when there are keys loaded and the input key is in the list of valid matrix keys', () => {
|
82
|
+
expect(service.matrixKeyIsValid('my-matrix-key', {} as IncomingMessage)).toEqual(true);
|
74
83
|
});
|
75
84
|
|
76
|
-
it('should return false when there are keys loaded and the input key is not in the list of valid keys', async () => {
|
77
|
-
expect(service.
|
85
|
+
it('should return false when there are keys loaded and the input key is not in the list of valid matrix keys', async () => {
|
86
|
+
expect(service.matrixKeyIsValid('not-my-key', {} as IncomingMessage)).toEqual(false);
|
78
87
|
});
|
79
88
|
|
80
|
-
it('should return false
|
81
|
-
expect(service.
|
89
|
+
it('should return false when using non matrix keys', async () => {
|
90
|
+
expect(service.matrixKeyIsValid('my-inter-service-key', {} as IncomingMessage)).toEqual(false);
|
82
91
|
});
|
83
92
|
});
|
84
93
|
});
|
85
94
|
|
86
|
-
describe('
|
95
|
+
describe('interServiceKeyIsValid', () => {
|
87
96
|
describe('when there are no api keys', () => {
|
88
97
|
beforeAll(async () => {
|
89
|
-
sendSpy.mockImplementation(() =>
|
98
|
+
sendSpy.mockImplementation(() =>
|
99
|
+
Promise.resolve({ SecretString: '{"matrix-keys":[], "inter-service-keys":[]}' }),
|
100
|
+
);
|
90
101
|
await service.refreshApiKeys();
|
91
102
|
});
|
92
103
|
|
93
104
|
it('should throw an unauthenticated request error when validating a key if there are no keys to validate against', () => {
|
94
|
-
expect(() => service.
|
95
|
-
new UnAuthenticatedRequestError('No api keys to check against'),
|
105
|
+
expect(() => service.interServiceKeyIsValid('anything')).toThrowError(
|
106
|
+
new UnAuthenticatedRequestError('No inter service api keys to check against'),
|
96
107
|
);
|
97
108
|
});
|
98
109
|
});
|
@@ -100,22 +111,25 @@ describe('CloudflareApiKeyService', () => {
|
|
100
111
|
describe('when there are api keys', () => {
|
101
112
|
beforeAll(async () => {
|
102
113
|
sendSpy.mockImplementation(() =>
|
103
|
-
Promise.resolve({
|
114
|
+
Promise.resolve({
|
115
|
+
SecretString:
|
116
|
+
'{"keys":["my-key", "my-other-key"], "matrix-keys":["my-matrix-key"], "inter-service-keys":["my-inter-service-key"]}',
|
117
|
+
}),
|
104
118
|
);
|
105
119
|
await service.refreshApiKeys();
|
106
120
|
});
|
107
121
|
|
108
122
|
it('should return true when there are keys loaded and the input key is in the list of valid matrix keys', () => {
|
109
|
-
expect(service.
|
123
|
+
expect(service.interServiceKeyIsValid('my-inter-service-key')).toEqual(true);
|
110
124
|
});
|
111
125
|
|
112
126
|
it('should return false when there are keys loaded and the input key is not in the list of valid matrix keys', async () => {
|
113
|
-
expect(service.
|
127
|
+
expect(service.interServiceKeyIsValid('not-my-key')).toEqual(false);
|
114
128
|
});
|
115
129
|
|
116
|
-
it('should return false when using non
|
117
|
-
expect(service.
|
118
|
-
expect(service.
|
130
|
+
it('should return false when using non inter-service keys', async () => {
|
131
|
+
expect(service.interServiceKeyIsValid('my-key')).toEqual(false);
|
132
|
+
expect(service.interServiceKeyIsValid('my-matrix-key')).toEqual(false);
|
119
133
|
});
|
120
134
|
});
|
121
135
|
});
|
@@ -6,15 +6,16 @@ import {
|
|
6
6
|
import { UnAuthenticatedRequestError } from '../error/UnAuthenticatedRequestError';
|
7
7
|
import { ApiKeyValidationService } from './ApiKeyValidationService';
|
8
8
|
import { getLogger, Logger } from '@squiz/dx-logger-lib';
|
9
|
+
import { IncomingMessage } from 'http';
|
9
10
|
|
10
11
|
export interface CloudFlareKeys {
|
11
|
-
keys: string[];
|
12
12
|
'matrix-keys': string[];
|
13
|
+
'inter-service-keys': string[];
|
13
14
|
}
|
14
15
|
|
15
16
|
let validKeys: CloudFlareKeys = {
|
16
|
-
keys: [],
|
17
17
|
'matrix-keys': [],
|
18
|
+
'inter-service-keys': [],
|
18
19
|
};
|
19
20
|
|
20
21
|
let refreshInterval: ReturnType<typeof setInterval>;
|
@@ -38,20 +39,32 @@ export class CloudflareApiKeyService implements ApiKeyValidationService {
|
|
38
39
|
this.logger = logger;
|
39
40
|
}
|
40
41
|
|
41
|
-
|
42
|
-
|
42
|
+
/**
|
43
|
+
* @deprecated Suggest moving towards using JWT authentication.
|
44
|
+
*/
|
45
|
+
public matrixKeyIsValid(key: string, request: IncomingMessage): boolean {
|
46
|
+
if (validKeys['matrix-keys'].length == 0) {
|
43
47
|
throw new UnAuthenticatedRequestError('No api keys to check against');
|
44
48
|
}
|
45
49
|
|
46
|
-
|
50
|
+
if (validKeys['matrix-keys'].includes(key)) {
|
51
|
+
this.logger.info('Request authenticated using legacy Matrix API key', {
|
52
|
+
url: request.url,
|
53
|
+
userAgent: request.headers?.['user-agent'],
|
54
|
+
});
|
55
|
+
|
56
|
+
return true;
|
57
|
+
}
|
58
|
+
|
59
|
+
return false;
|
47
60
|
}
|
48
61
|
|
49
|
-
public
|
50
|
-
if (validKeys['
|
51
|
-
throw new UnAuthenticatedRequestError('No api keys to check against');
|
62
|
+
public interServiceKeyIsValid(key: string): boolean {
|
63
|
+
if (validKeys['inter-service-keys'].length == 0) {
|
64
|
+
throw new UnAuthenticatedRequestError('No inter service api keys to check against');
|
52
65
|
}
|
53
66
|
|
54
|
-
return validKeys['
|
67
|
+
return validKeys['inter-service-keys'].includes(key);
|
55
68
|
}
|
56
69
|
|
57
70
|
protected async getValidApiKeys(): Promise<CloudFlareKeys> {
|
@@ -74,7 +87,7 @@ export class CloudflareApiKeyService implements ApiKeyValidationService {
|
|
74
87
|
}
|
75
88
|
const secret = JSON.parse(secretValue.SecretString);
|
76
89
|
|
77
|
-
if (secret
|
90
|
+
if (secret['matrix-keys'] && secret['inter-service-keys']) {
|
78
91
|
return secret;
|
79
92
|
}
|
80
93
|
|
@@ -88,7 +101,8 @@ export class CloudflareApiKeyService implements ApiKeyValidationService {
|
|
88
101
|
this.logger.info('refreshing keys');
|
89
102
|
validKeys = await this.getValidApiKeys();
|
90
103
|
|
91
|
-
this.logger.info(`
|
104
|
+
this.logger.info(`found ${validKeys['matrix-keys'].length} valid matrix keys`);
|
105
|
+
this.logger.info(`found ${validKeys['inter-service-keys'].length} valid inter service keys`);
|
92
106
|
|
93
107
|
if (!refreshInterval) {
|
94
108
|
refreshInterval = setInterval(async () => {
|
@@ -98,7 +112,7 @@ export class CloudflareApiKeyService implements ApiKeyValidationService {
|
|
98
112
|
}
|
99
113
|
|
100
114
|
// temporary method, to be removed when DXP auth is properly implemented
|
101
|
-
|
102
|
-
return validKeys['
|
115
|
+
public getInterServiceKeys(): string[] {
|
116
|
+
return validKeys['inter-service-keys'];
|
103
117
|
}
|
104
118
|
}
|
@@ -1,17 +1,23 @@
|
|
1
1
|
import { DevelopmentApiKeyService } from './DevelopmentApiKeyService';
|
2
|
+
import { IncomingMessage } from 'http';
|
3
|
+
import { getLogger } from '@squiz/dx-logger-lib';
|
2
4
|
|
3
5
|
describe('DevelopmentApiKeyService', () => {
|
4
|
-
const service = new DevelopmentApiKeyService();
|
6
|
+
const service = new DevelopmentApiKeyService(getLogger({ name: 'test', silent: true }));
|
5
7
|
|
6
|
-
describe('
|
8
|
+
describe('matrixKeyIsValid', () => {
|
7
9
|
it('should always return true', () => {
|
8
|
-
expect(service.
|
10
|
+
expect(service.matrixKeyIsValid(undefined, {} as IncomingMessage)).toEqual(true);
|
9
11
|
});
|
10
12
|
});
|
11
13
|
|
12
|
-
describe('
|
13
|
-
it('should
|
14
|
-
expect(service.
|
14
|
+
describe('interServiceKeyIsValid', () => {
|
15
|
+
it('should return true if key is "inter-service-api-key"', () => {
|
16
|
+
expect(service.interServiceKeyIsValid('inter-service-api-key')).toEqual(true);
|
17
|
+
});
|
18
|
+
|
19
|
+
it('should return false if key is not "inter-service-api-key"', () => {
|
20
|
+
expect(service.interServiceKeyIsValid('invalid-api-key')).toEqual(false);
|
15
21
|
});
|
16
22
|
});
|
17
23
|
});
|
@@ -1,14 +1,25 @@
|
|
1
|
+
import { getLogger, Logger } from '@squiz/dx-logger-lib';
|
1
2
|
import { ApiKeyValidationService } from './ApiKeyValidationService';
|
3
|
+
import { IncomingMessage } from 'http';
|
2
4
|
|
3
5
|
export class DevelopmentApiKeyService implements ApiKeyValidationService {
|
4
|
-
|
5
|
-
|
6
|
+
private logger: Logger;
|
7
|
+
|
8
|
+
public constructor(logger?: Logger) {
|
9
|
+
this.logger = logger || getLogger({ name: 'DevelopmentApiKeyService' });
|
6
10
|
}
|
7
|
-
public matrixKeyIsValid(): boolean {
|
11
|
+
public matrixKeyIsValid(key: string | undefined, request: IncomingMessage): boolean {
|
12
|
+
this.logger.info('Request authenticated using legacy Matrix API key', {
|
13
|
+
url: request.url,
|
14
|
+
userAgent: request.headers?.['user-agent'],
|
15
|
+
});
|
8
16
|
return true;
|
9
17
|
}
|
18
|
+
public interServiceKeyIsValid(key: string | undefined): boolean {
|
19
|
+
return Boolean(key && this.getInterServiceKeys().includes(key));
|
20
|
+
}
|
10
21
|
// temporary method, to be removed when DXP auth is properly implemented
|
11
|
-
|
12
|
-
return ['
|
22
|
+
public getInterServiceKeys(): string[] {
|
23
|
+
return ['inter-service-api-key'];
|
13
24
|
}
|
14
25
|
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { assertIsArray } from './assertIsArray';
|
2
|
+
|
3
|
+
describe('assertIsArray', () => {
|
4
|
+
it('should throw an assertion error if input is undefined', () => {
|
5
|
+
expect(() => assertIsArray(undefined)).toThrowErrorMatchingInlineSnapshot(`"Expected undefined to be array"`);
|
6
|
+
});
|
7
|
+
|
8
|
+
it('should throw an assertion error if input is null', () => {
|
9
|
+
expect(() => assertIsArray(null)).toThrowErrorMatchingInlineSnapshot(`"Expected null to be array"`);
|
10
|
+
});
|
11
|
+
|
12
|
+
it('should return "void" or undefined if valid', () => {
|
13
|
+
expect(assertIsArray(['test'])).toBeUndefined();
|
14
|
+
expect(() => assertIsArray(['test'])).not.toThrowError();
|
15
|
+
});
|
16
|
+
});
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { AssertionError } from 'assert';
|
2
|
+
|
3
|
+
export function assertIsArray(val: any): asserts val is Array<any> {
|
4
|
+
if (!Array.isArray(val)) {
|
5
|
+
throw new AssertionError({
|
6
|
+
actual: val,
|
7
|
+
expected: 'array',
|
8
|
+
message: `Expected ${val} to be array`,
|
9
|
+
});
|
10
|
+
}
|
11
|
+
}
|
package/src/assertions/index.ts
CHANGED
@@ -6,6 +6,7 @@ export * from './assertIsObject';
|
|
6
6
|
export * from './assertIsNotAnEmptyString';
|
7
7
|
export * from './assertIsEnumValue';
|
8
8
|
export * from './assertIsBoolean';
|
9
|
+
export * from './assertIsArray';
|
9
10
|
|
10
11
|
// Assert assign
|
11
12
|
export * from './assertAssignWithDefaultUndefinedValue';
|
@@ -1,9 +1,16 @@
|
|
1
1
|
import { BaseResolvedNodes } from '@squiz/dx-json-schema-lib';
|
2
2
|
import { formattedTextToHtmlString } from './formattedTextToHtmlString';
|
3
|
+
import axios from 'axios';
|
3
4
|
|
4
5
|
type FormattedNodes = BaseResolvedNodes;
|
5
6
|
type FormattedTextTag = BaseResolvedNodes & { type: 'tag' };
|
6
7
|
|
8
|
+
const mockedResponse = {
|
9
|
+
data: `<div>component-html</div>`,
|
10
|
+
};
|
11
|
+
const axiosGetSpy = jest.spyOn(axios, 'get');
|
12
|
+
axiosGetSpy.mockResolvedValue(mockedResponse);
|
13
|
+
|
7
14
|
describe('formattedTextToHtmlString', () => {
|
8
15
|
it('should convert text nodes to HTML', async () => {
|
9
16
|
const textNode: FormattedNodes = {
|
@@ -236,4 +243,37 @@ describe('formattedTextToHtmlString', () => {
|
|
236
243
|
`"<div class="justify">Lorem ipsum dolor sit amet, consectetur adipiscing elit. <strong class="bold">Vestibulum dictum</strong> mi vel urna maximus, et luctus ipsum tincidunt</div>"`,
|
237
244
|
);
|
238
245
|
});
|
246
|
+
|
247
|
+
it('should handle component nodes', async () => {
|
248
|
+
const formattedNodes: FormattedNodes = {
|
249
|
+
type: 'component',
|
250
|
+
componentSet: 'test',
|
251
|
+
schemaName: 'https://some.render-runtime.url/d/page-demo/demo-button/1.0.0',
|
252
|
+
};
|
253
|
+
|
254
|
+
await expect(formattedTextToHtmlString(formattedNodes)).resolves.toMatchInlineSnapshot(
|
255
|
+
`"<div>component-html</div>"`,
|
256
|
+
);
|
257
|
+
expect(axiosGetSpy).toBeCalledWith(
|
258
|
+
'https://some.render-runtime.url/r/page-demo/demo-button/1.0.0?_componentSet=test',
|
259
|
+
);
|
260
|
+
});
|
261
|
+
|
262
|
+
it('should handle component nodes - with content provided', async () => {
|
263
|
+
const formattedNodes: FormattedNodes = {
|
264
|
+
type: 'component',
|
265
|
+
componentSet: 'test',
|
266
|
+
content: {
|
267
|
+
contentItemId: '123',
|
268
|
+
},
|
269
|
+
schemaName: 'https://some.render-runtime.url/d/page-demo/demo-button/1.0.0',
|
270
|
+
};
|
271
|
+
|
272
|
+
await expect(formattedTextToHtmlString(formattedNodes)).resolves.toMatchInlineSnapshot(
|
273
|
+
`"<div>component-html</div>"`,
|
274
|
+
);
|
275
|
+
expect(axiosGetSpy).toBeCalledWith(
|
276
|
+
'https://some.render-runtime.url/r/page-demo/demo-button/1.0.0?_componentSet=test&_contentItemId=123',
|
277
|
+
);
|
278
|
+
});
|
239
279
|
});
|
@@ -5,13 +5,18 @@ import {
|
|
5
5
|
FullyResolvedNodesMap,
|
6
6
|
resolveFormattedText,
|
7
7
|
} from '@squiz/dx-json-schema-lib';
|
8
|
+
import axios from 'axios';
|
8
9
|
|
9
10
|
type FormattedTextTag = FullyResolvedNodes & { type: 'tag' };
|
10
11
|
type FormattedNodeFontProperties = FORMATTED_TEXT_MODELS.v1.FormattedNodeFontProperties;
|
12
|
+
type ComponentNode = FORMATTED_TEXT_MODELS.v1.ComponentNode;
|
11
13
|
|
12
14
|
export const formattedTextToHtmlStringResolvers: FullyResolvedNodesMap = {
|
13
15
|
tag: async (node) => buildTagHTML(node),
|
14
16
|
text: async (node) => node.value,
|
17
|
+
component: async (node) => {
|
18
|
+
return await buildComponentHtml(node);
|
19
|
+
},
|
15
20
|
default: async (node) => {
|
16
21
|
return `<p class="invalid-node-type"> node of type "${node.type}" cannot be converted to html</p>`;
|
17
22
|
},
|
@@ -36,6 +41,12 @@ function buildTagHTML(formattedTextTag: FormattedTextTag): string {
|
|
36
41
|
return `<${formattedTextTag.tag}${attributesStr}>${formattedTextTag.children.join('')}</${formattedTextTag.tag}>`;
|
37
42
|
}
|
38
43
|
|
44
|
+
async function buildComponentHtml(node: ComponentNode): Promise<string> {
|
45
|
+
const renderUrl = buildComponentRenderUrl(node);
|
46
|
+
const componentHtml = await axios.get(renderUrl);
|
47
|
+
return componentHtml.data;
|
48
|
+
}
|
49
|
+
|
39
50
|
function getClassString(formattedTextTag: FormattedTextTag) {
|
40
51
|
const fontClasses = buildFontClasses(formattedTextTag.font);
|
41
52
|
|
@@ -52,7 +63,7 @@ function getClassString(formattedTextTag: FormattedTextTag) {
|
|
52
63
|
return string.trim();
|
53
64
|
}
|
54
65
|
|
55
|
-
function buildAttributesString(attributes: { [k: string]: string } | undefined): string {
|
66
|
+
export function buildAttributesString(attributes: { [k: string]: string } | undefined): string {
|
56
67
|
if (!attributes) {
|
57
68
|
return '';
|
58
69
|
}
|
@@ -67,7 +78,7 @@ function buildAttributesString(attributes: { [k: string]: string } | undefined):
|
|
67
78
|
return attributesString;
|
68
79
|
}
|
69
80
|
|
70
|
-
function buildFontClasses(font: FormattedNodeFontProperties | undefined): string[] {
|
81
|
+
export function buildFontClasses(font: FormattedNodeFontProperties | undefined): string[] {
|
71
82
|
if (!font) {
|
72
83
|
return [];
|
73
84
|
}
|
@@ -94,3 +105,21 @@ function buildFontClasses(font: FormattedNodeFontProperties | undefined): string
|
|
94
105
|
|
95
106
|
return classes;
|
96
107
|
}
|
108
|
+
|
109
|
+
function buildComponentRenderUrl(node: ComponentNode): string {
|
110
|
+
const [baseUrl, namespace, name, version] = getComponentDetails(node.schemaName);
|
111
|
+
let query = `_componentSet=${node.componentSet}`;
|
112
|
+
if (node.content?.contentItemId.length) {
|
113
|
+
query = query.concat(`&_contentItemId=${node.content.contentItemId}`);
|
114
|
+
}
|
115
|
+
const renderUrl = `${baseUrl}/r/${namespace}/${name}/${version}?${query}`;
|
116
|
+
return renderUrl;
|
117
|
+
}
|
118
|
+
|
119
|
+
function getComponentDetails(str: string): [string, string, string, string] {
|
120
|
+
const baseUrl = str.split('/d/')[0];
|
121
|
+
const sections = str.split('/');
|
122
|
+
const lastThreeSections = sections.slice(-3);
|
123
|
+
const [namespace, version, name] = lastThreeSections;
|
124
|
+
return [baseUrl, namespace, version, name];
|
125
|
+
}
|
package/src/index.ts
CHANGED
@@ -8,7 +8,6 @@ export * from './api-key-validation/ApiKeyValidationService';
|
|
8
8
|
export * from './api-key-validation/CloudflareApiKeyService';
|
9
9
|
export * from './api-key-validation/DevelopmentApiKeyService';
|
10
10
|
export * from './api-key-validation/getApiKeyService';
|
11
|
-
export * from './server-utils/apiKeyMiddleware';
|
12
11
|
export * from './cache';
|
13
12
|
export * from './formatted-text/formattedTextToHtmlString';
|
14
13
|
export * from './json-order';
|