@squiz/dx-common-lib 1.39.1-alpha.8 → 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.
Files changed (49) hide show
  1. package/.npm/_logs/{2023-06-26T04_04_44_628Z-debug-0.log → 2023-07-06T01_50_58_148Z-debug-0.log} +20 -20
  2. package/lib/api-key-validation/ApiKeyValidationService.d.ts +8 -3
  3. package/lib/api-key-validation/CloudflareApiKeyService.d.ts +9 -4
  4. package/lib/api-key-validation/CloudflareApiKeyService.js +24 -12
  5. package/lib/api-key-validation/CloudflareApiKeyService.js.map +1 -1
  6. package/lib/api-key-validation/CloudflareApiKeyService.spec.js +26 -23
  7. package/lib/api-key-validation/CloudflareApiKeyService.spec.js.map +1 -1
  8. package/lib/api-key-validation/DevelopmentApiKeyService.d.ts +8 -3
  9. package/lib/api-key-validation/DevelopmentApiKeyService.js +14 -5
  10. package/lib/api-key-validation/DevelopmentApiKeyService.js.map +1 -1
  11. package/lib/api-key-validation/DevelopmentApiKeyService.spec.js +10 -6
  12. package/lib/api-key-validation/DevelopmentApiKeyService.spec.js.map +1 -1
  13. package/lib/assertions/assertIsArray.d.ts +1 -0
  14. package/lib/assertions/assertIsArray.js +15 -0
  15. package/lib/assertions/assertIsArray.js.map +1 -0
  16. package/lib/assertions/assertIsArray.spec.js +16 -0
  17. package/lib/assertions/assertIsArray.spec.js.map +1 -0
  18. package/lib/assertions/index.d.ts +1 -0
  19. package/lib/assertions/index.js +1 -0
  20. package/lib/assertions/index.js.map +1 -1
  21. package/lib/formatted-text/formattedTextToHtmlString.d.ts +7 -1
  22. package/lib/formatted-text/formattedTextToHtmlString.js +32 -1
  23. package/lib/formatted-text/formattedTextToHtmlString.js.map +1 -1
  24. package/lib/formatted-text/formattedTextToHtmlString.spec.js +30 -0
  25. package/lib/formatted-text/formattedTextToHtmlString.spec.js.map +1 -1
  26. package/lib/index.d.ts +0 -1
  27. package/lib/index.js +0 -1
  28. package/lib/index.js.map +1 -1
  29. package/package.json +5 -4
  30. package/src/api-key-validation/ApiKeyValidationService.ts +9 -3
  31. package/src/api-key-validation/CloudflareApiKeyService.spec.ts +38 -24
  32. package/src/api-key-validation/CloudflareApiKeyService.ts +27 -13
  33. package/src/api-key-validation/DevelopmentApiKeyService.spec.ts +12 -6
  34. package/src/api-key-validation/DevelopmentApiKeyService.ts +16 -5
  35. package/src/assertions/assertIsArray.spec.ts +16 -0
  36. package/src/assertions/assertIsArray.ts +11 -0
  37. package/src/assertions/index.ts +1 -0
  38. package/src/formatted-text/formattedTextToHtmlString.spec.ts +40 -0
  39. package/src/formatted-text/formattedTextToHtmlString.ts +31 -2
  40. package/src/index.ts +0 -1
  41. package/tsconfig.tsbuildinfo +1 -1
  42. package/lib/server-utils/apiKeyMiddleware.d.ts +0 -6
  43. package/lib/server-utils/apiKeyMiddleware.js +0 -23
  44. package/lib/server-utils/apiKeyMiddleware.js.map +0 -1
  45. package/lib/server-utils/apiKeyMiddleware.spec.js +0 -40
  46. package/lib/server-utils/apiKeyMiddleware.spec.js.map +0 -1
  47. package/src/server-utils/apiKeyMiddleware.spec.ts +0 -51
  48. package/src/server-utils/apiKeyMiddleware.ts +0 -26
  49. /package/lib/{server-utils/apiKeyMiddleware.spec.d.ts → assertions/assertIsArray.spec.d.ts} +0 -0
@@ -1,51 +0,0 @@
1
- import { UnAuthenticatedRequestError } from '../error/UnAuthenticatedRequestError';
2
- import { apiKeyMiddleware } from './apiKeyMiddleware';
3
-
4
- const keyIsValid = jest.fn().mockImplementation(() => true);
5
- const matrixKeyIsValid = jest.fn().mockImplementation(() => true);
6
- const getMatrixKeys = jest.fn(() => []);
7
-
8
- describe('apiKeyMiddleware', () => {
9
- const middleware = apiKeyMiddleware({ keyIsValid, matrixKeyIsValid, getMatrixKeys });
10
-
11
- it('should return an express middleware which', () => {
12
- expect(middleware).toBeInstanceOf(Function);
13
- });
14
-
15
- describe('middleware', () => {
16
- it('should call next is key is invalid but matrix ke is valid', () => {
17
- const nextFunc = jest.fn().mockImplementation(() => {
18
- /* no op */
19
- });
20
- keyIsValid.mockImplementation(() => false);
21
- keyIsValid.mockImplementation(() => true);
22
-
23
- middleware({ header: () => 'some-key' } as any, {} as any, nextFunc);
24
-
25
- expect(nextFunc).toHaveBeenCalled();
26
- });
27
-
28
- it('should call next if api key is valid', () => {
29
- const nextFunc = jest.fn().mockImplementation(() => {
30
- /* no op */
31
- });
32
-
33
- middleware({ header: () => 'some-key' } as any, {} as any, nextFunc);
34
-
35
- expect(nextFunc).toHaveBeenCalled();
36
- });
37
-
38
- it('should throw an UnAuthenticatedRequestError if key is invalid', () => {
39
- const nextFunc = jest.fn().mockImplementation(() => {
40
- /* no op */
41
- });
42
-
43
- keyIsValid.mockImplementation(() => false);
44
- matrixKeyIsValid.mockImplementation(() => false);
45
-
46
- expect(() => middleware({ header: () => 'some-key' } as any, {} as any, nextFunc)).toThrowError(
47
- new UnAuthenticatedRequestError(`API KEY IS INVALID`),
48
- );
49
- });
50
- });
51
- });
@@ -1,26 +0,0 @@
1
- import type { Request, Response } from 'express';
2
- import { ApiKeyValidationService } from '../api-key-validation/ApiKeyValidationService';
3
- import { UnAuthenticatedRequestError } from '../error/UnAuthenticatedRequestError';
4
-
5
- /**
6
- * @deprecated Use JWT authentication.
7
- */
8
- export function apiKeyMiddleware(
9
- apiKeyService: ApiKeyValidationService,
10
- ): (req: Request, res: Response, next: any) => void {
11
- return function (req: Request, res: Response, next: any) {
12
- const key = req.header('x-api-key');
13
-
14
- if (req.path == '/health') {
15
- next();
16
- return;
17
- }
18
-
19
- if (apiKeyService.keyIsValid(key) || apiKeyService.matrixKeyIsValid(key)) {
20
- next();
21
- return;
22
- }
23
-
24
- throw new UnAuthenticatedRequestError(`API KEY IS INVALID`);
25
- };
26
- }