diff --git a/package-lock.json b/package-lock.json index f430b27f9..d2c60be54 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2826,6 +2826,21 @@ "node": ">=8" } }, + "node_modules/@sigstore/sign/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/@sigstore/sign/node_modules/minipass-collect": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/minipass-collect/-/minipass-collect-1.0.2.tgz", @@ -3000,6 +3015,21 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, + "node_modules/@tufjs/models/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/@types/acorn": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/@types/acorn/-/acorn-4.0.6.tgz", @@ -3390,18 +3420,6 @@ "integrity": "sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==", "dev": true }, - "node_modules/@types/uuid": { - "version": "9.0.2", - "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.2.tgz", - "integrity": "sha512-kNnC1GFBLuhImSnV7w4njQkUiJi0ZXUycu1rUaouPqiKlXkh77JKgdRnTAp1x5eBwcIwbtI+3otwzuIDEuDoxQ==", - "dev": true - }, - "node_modules/@types/wrap-ansi": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@types/wrap-ansi/-/wrap-ansi-3.0.0.tgz", - "integrity": "sha512-ltIpx+kM7g/MLRZfkbL7EsCEjfzCcScLpkg37eXEtx5kmrAKBkTJwd1GIAjDSL8wTpM6Hzn5YO4pSb91BEwu1g==", - "dev": true - }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "7.13.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.13.0.tgz", @@ -3532,6 +3550,21 @@ "url": "https://opencollective.com/typescript-eslint" } }, + "node_modules/@typescript-eslint/eslint-plugin/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/@typescript-eslint/experimental-utils": { "version": "5.62.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-5.62.0.tgz", @@ -3754,6 +3787,21 @@ "url": "https://opencollective.com/typescript-eslint" } }, + "node_modules/@typescript-eslint/parser/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/@typescript-eslint/scope-manager": { "version": "5.60.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.60.1.tgz", @@ -3895,6 +3943,21 @@ "url": "https://opencollective.com/typescript-eslint" } }, + "node_modules/@typescript-eslint/type-utils/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/@typescript-eslint/types": { "version": "5.60.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.60.1.tgz", @@ -5848,6 +5911,21 @@ "node": "14 || >=16.14" } }, + "node_modules/cacache/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/cacheable-lookup": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-7.0.0.tgz", @@ -8785,6 +8863,21 @@ "url": "https://opencollective.com/typescript-eslint" } }, + "node_modules/eslint-plugin-vitest/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/eslint-plugin-you-dont-need-lodash-underscore": { "version": "6.12.0", "resolved": "https://registry.npmjs.org/eslint-plugin-you-dont-need-lodash-underscore/-/eslint-plugin-you-dont-need-lodash-underscore-6.12.0.tgz", @@ -14098,14 +14191,14 @@ } }, "node_modules/minimatch": { - "version": "9.0.5", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", - "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.0.1.tgz", + "integrity": "sha512-ethXTt3SGGR+95gudmqJ1eNhRO7eGEGIgYA9vnPatK4/etz2MEVDno5GMCibdMTuBMyElzIlgxMna3K94XDIDQ==", "dependencies": { "brace-expansion": "^2.0.1" }, "engines": { - "node": ">=16 || 14 >=14.17" + "node": "20 || >=22" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -14694,6 +14787,21 @@ "node": ">=16" } }, + "node_modules/node-gyp/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/node-gyp/node_modules/nopt": { "version": "7.2.1", "resolved": "https://registry.npmjs.org/nopt/-/nopt-7.2.1.tgz", @@ -15147,6 +15255,21 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, + "node_modules/npm-registry-fetch/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/npm-registry-fetch/node_modules/minipass": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz", @@ -16032,6 +16155,21 @@ "node": "14 || >=16.14" } }, + "node_modules/pacote/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/pacote/node_modules/normalize-package-data": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-6.0.1.tgz", @@ -16963,6 +17101,21 @@ "node": ">=12" } }, + "node_modules/read-package-json/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/read-package-json/node_modules/normalize-package-data": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-5.0.0.tgz", @@ -18016,6 +18169,21 @@ "node": ">=8" } }, + "node_modules/sigstore/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/sigstore/node_modules/minipass-collect": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/minipass-collect/-/minipass-collect-1.0.2.tgz", @@ -19344,6 +19512,21 @@ "node": ">=8" } }, + "node_modules/tuf-js/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/tuf-js/node_modules/minipass-collect": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/minipass-collect/-/minipass-collect-1.0.2.tgz", @@ -20107,6 +20290,7 @@ "version": "9.0.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz", "integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==", + "dev": true, "bin": { "uuid": "dist/bin/uuid" } @@ -21162,7 +21346,7 @@ "version": "1.2.2", "license": "ISC", "dependencies": { - "minimatch": "^9.0.1" + "minimatch": "^10.0.1" }, "devDependencies": { "@readme/eslint-config": "^14.0.0", @@ -21190,8 +21374,7 @@ "lodash": "^4.17.15", "ssri": "^10.0.1", "timeout-signal": "^1.1.0", - "type-is": "^1.6.18", - "uuid": "^9.0.0" + "type-is": "^1.6.18" }, "devDependencies": { "@readme/eslint-config": "^14.0.0", @@ -21206,7 +21389,6 @@ "@types/ssri": "^7.1.1", "@types/supertest": "^2.0.12", "@types/type-is": "^1.6.3", - "@types/uuid": "^9.0.2", "@vitest/coverage-v8": "^2.0.4", "eslint": "^8.34.0", "express": "^4.18.2", diff --git a/packages/cloudflare-worker/package.json b/packages/cloudflare-worker/package.json index d66eabfd6..a86dce3aa 100644 --- a/packages/cloudflare-worker/package.json +++ b/packages/cloudflare-worker/package.json @@ -3,7 +3,7 @@ "description": "Cloudflare worker to get your API log data into ReadMe", "version": "1.2.2", "dependencies": { - "minimatch": "^9.0.1" + "minimatch": "^10.0.1" }, "engines": { "node": ">=18" diff --git a/packages/node/package.json b/packages/node/package.json index a458cd568..668a91513 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -31,8 +31,7 @@ "lodash": "^4.17.15", "ssri": "^10.0.1", "timeout-signal": "^1.1.0", - "type-is": "^1.6.18", - "uuid": "^9.0.0" + "type-is": "^1.6.18" }, "devDependencies": { "@readme/eslint-config": "^14.0.0", @@ -47,7 +46,6 @@ "@types/ssri": "^7.1.1", "@types/supertest": "^2.0.12", "@types/type-is": "^1.6.3", - "@types/uuid": "^9.0.2", "@vitest/coverage-v8": "^2.0.4", "eslint": "^8.34.0", "express": "^4.18.2", diff --git a/packages/node/src/lib/ReadMe.ts b/packages/node/src/lib/ReadMe.ts index fb54eda9f..3089aa573 100644 --- a/packages/node/src/lib/ReadMe.ts +++ b/packages/node/src/lib/ReadMe.ts @@ -41,8 +41,8 @@ export interface GroupingObject { // Typing the return as unknown to make it easier to format the user to our format in the middleware // This way these functions can just return from their database interface GetUserParams { - byAPIKey: (apiKey: string) => Promise; - byEmail: (email: string) => Promise; + byAPIKey: (apiKey: string) => Promise | undefined; + byEmail: (email: string) => Promise | undefined; manualAPIKey?: string; } diff --git a/packages/node/src/lib/construct-payload.ts b/packages/node/src/lib/construct-payload.ts index 67927674f..0c1b1a707 100644 --- a/packages/node/src/lib/construct-payload.ts +++ b/packages/node/src/lib/construct-payload.ts @@ -3,11 +3,11 @@ import type { UUID } from 'node:crypto'; import type { IncomingMessage, ServerResponse } from 'node:http'; import type { TLSSocket } from 'tls'; +import { randomUUID } from 'node:crypto'; import os from 'os'; import { URL } from 'url'; import ssri from 'ssri'; -import { v4 as uuidv4 } from 'uuid'; import { version } from '../../package.json'; @@ -142,7 +142,7 @@ export function constructPayload( const serverTime = payloadData.responseEndDateTime.getTime() - payloadData.startedDateTime.getTime(); return { - _id: payloadData.logId || (uuidv4() as UUID), + _id: payloadData.logId || randomUUID(), _version: 3, group: { id: mask(payloadData.apiKey), diff --git a/packages/node/src/lib/log.ts b/packages/node/src/lib/log.ts index 6b9deb5f1..ad4a5a324 100644 --- a/packages/node/src/lib/log.ts +++ b/packages/node/src/lib/log.ts @@ -1,12 +1,11 @@ import type { LogOptions } from './construct-payload'; import type { GroupingObject, OutgoingLogBody } from './metrics-log'; -import type { UUID } from 'node:crypto'; import type { IncomingMessage, ServerResponse } from 'node:http'; +import { randomUUID } from 'node:crypto'; import * as url from 'url'; import clamp from 'lodash/clamp'; -import { v4 as uuidv4 } from 'uuid'; import config from '../config'; @@ -108,7 +107,7 @@ export function log( const bufferLength = clamp(options.bufferLength || config.bufferLength, 1, 30); const startedDateTime = new Date(); - const logId = uuidv4() as UUID; + const logId = randomUUID(); // baseLogUrl can be provided, but if it isn't then we // attempt to fetch it from the ReadMe API diff --git a/packages/node/src/lib/metrics-log.ts b/packages/node/src/lib/metrics-log.ts index d48730319..1701d1665 100644 --- a/packages/node/src/lib/metrics-log.ts +++ b/packages/node/src/lib/metrics-log.ts @@ -1,6 +1,6 @@ import type { Options } from './log'; -import type { UUID } from 'crypto'; import type { Har } from 'har-format'; +import type { UUID } from 'node:crypto'; import timeoutSignal from 'timeout-signal'; diff --git a/packages/node/test/index.test.ts b/packages/node/test/index.test.ts index f7c844e85..023156db8 100644 --- a/packages/node/test/index.test.ts +++ b/packages/node/test/index.test.ts @@ -48,7 +48,7 @@ const server = setupServer( function doMetricsHeadersMatch(headers: Headers) { const auth = headers.get('authorization'); - const decodedAuth = Buffer.from(auth.replace(/^Basic /, ''), 'base64').toString('ascii'); + const decodedAuth = Buffer.from((auth || '').replace(/^Basic /, ''), 'base64').toString('ascii'); const contentType = headers.get('content-type'); const userAgent = headers.get('user-agent'); return ( @@ -625,7 +625,7 @@ describe('#metrics', function () { http.post(`${config.host}/v1/request`, async ({ request: req }) => { const body = (await req.json()) as OutgoingLogBody[]; if (doMetricsHeadersMatch(req.headers)) { - expect(body[0].request.log.entries[0].request.postData[checkLocation]).toStrictEqual(requestBody); + expect(body[0].request.log.entries[0].request.postData?.[checkLocation]).toStrictEqual(requestBody); return new HttpResponse(null, { status: 200 }); } diff --git a/packages/node/test/lib/construct-payload.test.ts b/packages/node/test/lib/construct-payload.test.ts index 5b1987e9c..96cabeab2 100644 --- a/packages/node/test/lib/construct-payload.test.ts +++ b/packages/node/test/lib/construct-payload.test.ts @@ -7,7 +7,7 @@ import * as qs from 'querystring'; import { isValidUUIDV4 } from 'is-valid-uuid-v4'; import request from 'supertest'; -import { describe, expect, expectTypeOf, it } from 'vitest'; +import { describe, expect, it } from 'vitest'; import pkg from '../../package.json'; import { constructPayload, mask } from '../../src/lib/construct-payload'; @@ -33,6 +33,7 @@ function createApp(options?: LogOptions, payloadData?: PayloadData) { parsedBody = qs.parse(body); } + // @ts-expect-error deliberately passing in potentially bad data res.end(JSON.stringify(constructPayload(req, res, { ...payloadData, requestBody: parsedBody }, options))); }); }; @@ -81,8 +82,6 @@ describe('constructPayload()', function () { .send({ password: '123456' }) .expect(({ body }) => { expect(isValidUUIDV4(body._id)).toBe(true); - expectTypeOf(body.request.log.entries[0].request).toBeObject(); - expectTypeOf(body.request.log.entries[0].response).toBeObject(); expect(body.request.log.entries[0].request.postData).toStrictEqual({ mimeType: 'application/json', text: '{"password":"[REDACTED 6]"}', @@ -140,7 +139,6 @@ describe('constructPayload()', function () { return request(createApp(undefined, group)) .post('/') .expect(({ body }) => { - expectTypeOf(body.request.log.entries[0].time).toBeNumber(); expect(body.request.log.entries[0].time).toBe(20000); }); }); diff --git a/packages/node/test/lib/get-group-id.test.ts b/packages/node/test/lib/get-group-id.test.ts index 8d691db5e..f0fa06753 100644 --- a/packages/node/test/lib/get-group-id.test.ts +++ b/packages/node/test/lib/get-group-id.test.ts @@ -22,6 +22,7 @@ const mockUser = (keys: Record[] = [], user = {}) => { describe('#getGroupByApiKey', () => { it('returns undefined when no user is passed', () => { + // @ts-expect-error deliberately passing in bad data const groupId = getGroupByApiKey(undefined, 'requestApiKey'); expect(groupId).toBeUndefined(); }); @@ -32,6 +33,7 @@ describe('#getGroupByApiKey', () => { }); it('returns undefined for a user with a null keys array', () => { + // @ts-expect-error deliberately passing in bad data const groupId = getGroupByApiKey(mockUser(null), 'requestApiKey'); expect(groupId).toBeUndefined(); }); @@ -58,14 +60,14 @@ describe('#getGroupByApiKey', () => { ]); const groupId = getGroupByApiKey(user, 'requestApiKey'); - expect(groupId.id).toBe('key-2-id'); + expect(groupId?.id).toBe('key-2-id'); }); it('returns the id of the key as first priority', () => { const user = mockUser([{ id: 'key-1-id', name: 'key-1-name', otherField: 'requestApiKey' }]); const groupId = getGroupByApiKey(user, 'requestApiKey'); - expect(groupId.id).toBe('key-1-id'); + expect(groupId?.id).toBe('key-1-id'); }); it('returns the apiKey of the key as second priority', () => { @@ -78,35 +80,35 @@ describe('#getGroupByApiKey', () => { ]); const groupId = getGroupByApiKey(user, 'requestApiKey'); - expect(groupId.id).toBe('key-1-apiKey'); + expect(groupId?.id).toBe('key-1-apiKey'); }); it('returns the value of the matching apiKey as the third priority', () => { const user = mockUser([{ otherField: 'requestApiKey' }]); const groupId = getGroupByApiKey(user, 'requestApiKey'); - expect(groupId.id).toBe('requestApiKey'); + expect(groupId?.id).toBe('requestApiKey'); }); it('returns the basic user as the fourth priority', () => { const user = mockUser([{ user: 'basic-user', pass: 'basic-pass' }]); const groupId = getGroupByApiKey(user, 'requestApiKey'); - expect(groupId.id).toBe('basic-user'); + expect(groupId?.id).toBe('basic-user'); }); it('returns the name of the key as fifth priority', () => { const user = mockUser([{ name: 'key-1-name' }]); const groupId = getGroupByApiKey(user, 'requestApiKey'); - expect(groupId.id).toBe('key-1-name'); + expect(groupId?.id).toBe('key-1-name'); }); it('supports having nested basic auth', () => { const user = mockUser([{ notRelevant: 'foo' }, { basic: { user: 'basic-user', pass: 'basic-pass' } }]); const groupId = getGroupByApiKey(user, 'basic-user'); - expect(groupId.id).toBe('basic-user'); + expect(groupId?.id).toBe('basic-user'); }); }); @@ -121,7 +123,7 @@ describe('#getGroupByApiKey', () => { ]); const groupId = getGroupByApiKey(user, 'requestApiKey'); - expect(groupId.id).toBe('key-1-id'); + expect(groupId?.id).toBe('key-1-id'); }); }); @@ -136,7 +138,7 @@ describe('#getGroupByApiKey', () => { ]); const groupId = getGroupByApiKey(user, 'requestApiKey'); - expect(groupId.label).toBe('key-1-name'); + expect(groupId?.label).toBe('key-1-name'); }); }); }); diff --git a/packages/node/test/lib/process-request.test.ts b/packages/node/test/lib/process-request.test.ts index 2445529df..e052a1e6e 100644 --- a/packages/node/test/lib/process-request.test.ts +++ b/packages/node/test/lib/process-request.test.ts @@ -526,6 +526,7 @@ describe('process-request', function () { }); it('should not error with no body', function () { + // @ts-expect-error deliberately passing in bad data return request(createApp({}, false, null)) .post('/') .set('content-type', 'application/x-www-form-urlencoded') diff --git a/packages/node/test/lib/verify-webhook.test.ts b/packages/node/test/lib/verify-webhook.test.ts index ff6ce54f1..c6fa24020 100644 --- a/packages/node/test/lib/verify-webhook.test.ts +++ b/packages/node/test/lib/verify-webhook.test.ts @@ -59,6 +59,7 @@ describe('verifyWebhook', function () { const secret = 'docs4dayz'; expect(() => { + // @ts-expect-error deliberately passing in bad data verifyWebhook(body, undefined, secret); }).toThrow(/Missing Signature/); }); diff --git a/packages/node/test/tsconfig.json b/packages/node/test/tsconfig.json index 25b837d8a..8a8e2ca92 100644 --- a/packages/node/test/tsconfig.json +++ b/packages/node/test/tsconfig.json @@ -3,7 +3,8 @@ "compilerOptions": { "downlevelIteration": true, "noImplicitAny": true, - "strict": false + "noEmit": true, + "strict": true }, "include": ["./index.test.ts", "./lib/*.ts", "./global.d.ts"] }