From d8bec82d7ff0617619b1ed3ab9350edbb92dc249 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 28 Jul 2024 00:08:33 -0700 Subject: [PATCH 1/3] chore(deps): bump minimatch from 9.0.5 to 10.0.1 (#1040) Bumps [minimatch](https://github.com/isaacs/minimatch) from 9.0.5 to 10.0.1.
Changelog

Sourced from minimatch's changelog.

change log

10.0

9.0

8.0

7.4

7.3

7.2

7.1

7.0

6.2

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=minimatch&package-manager=npm_and_yarn&previous-version=9.0.5&new-version=10.0.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package-lock.json | 205 +++++++++++++++++++++++- packages/cloudflare-worker/package.json | 2 +- 2 files changed, 201 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1b51cc15f..22d5d6adb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2580,6 +2580,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": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", @@ -2790,6 +2805,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", @@ -3312,6 +3342,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", @@ -3534,6 +3579,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", @@ -3675,6 +3735,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", @@ -5734,6 +5809,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/cacache/node_modules/minipass": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", @@ -8831,6 +8921,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", @@ -14328,14 +14433,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" @@ -14991,6 +15096,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/minipass": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", @@ -15470,6 +15590,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", @@ -16489,6 +16624,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/minipass": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", @@ -17455,6 +17605,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/minipass": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", @@ -18590,6 +18755,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": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", @@ -19959,6 +20139,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": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", @@ -21817,7 +22012,7 @@ "version": "1.2.2", "license": "ISC", "dependencies": { - "minimatch": "^9.0.1" + "minimatch": "^10.0.1" }, "devDependencies": { "@readme/eslint-config": "^14.0.0", 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" From 97a4172189f126af5a398fa735b7ce44228d4a96 Mon Sep 17 00:00:00 2001 From: Gabe Ratcliff Date: Sun, 28 Jul 2024 00:40:52 -0700 Subject: [PATCH 2/3] chore(uuid): deprecate `uuid` package in favor of `node:crypto` (#1043) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit | 🚥 Resolves ISSUE_ID | | :------------------- | ## 🧰 Changes Removing `uuid` dep. We should be able to use `node:crypto` for any UUID generation going forward. ## 🧬 QA & Testing Provide as much information as you can on how to test what you've done. --- package-lock.json | 11 ++--------- packages/node/package.json | 4 +--- packages/node/src/lib/construct-payload.ts | 4 ++-- packages/node/src/lib/log.ts | 5 ++--- packages/node/src/lib/metrics-log.ts | 2 +- 5 files changed, 8 insertions(+), 18 deletions(-) diff --git a/package-lock.json b/package-lock.json index 22d5d6adb..e86116340 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3206,12 +3206,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/@typescript-eslint/eslint-plugin": { "version": "7.13.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.13.0.tgz", @@ -20926,6 +20920,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" } @@ -22046,8 +22041,7 @@ "oas": "^20.10.2", "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", @@ -22061,7 +22055,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": "^0.34.2", "caseless": "^0.12.0", "eslint": "^8.34.0", diff --git a/packages/node/package.json b/packages/node/package.json index 4b749dc86..9362bb8f8 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -37,8 +37,7 @@ "oas": "^20.10.2", "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", @@ -52,7 +51,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": "^0.34.2", "caseless": "^0.12.0", "eslint": "^8.34.0", 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 3db7e7c81..569d4adb9 100644 --- a/packages/node/src/lib/metrics-log.ts +++ b/packages/node/src/lib/metrics-log.ts @@ -1,7 +1,7 @@ import type { Options } from './log'; -import type { UUID } from 'crypto'; import type { Har } from 'har-format'; import type { Response } from 'node-fetch'; +import type { UUID } from 'node:crypto'; import fetch from 'node-fetch'; import timeoutSignal from 'timeout-signal'; From be9a8e2c64e63f863362996424883e327502cd4d Mon Sep 17 00:00:00 2001 From: Kanad Gupta <8854718+kanadgupta@users.noreply.github.com> Date: Mon, 29 Jul 2024 11:18:35 -0500 Subject: [PATCH 3/3] fix: type errors in tests (#1056) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 🧰 Changes Noticed a bunch of type errors when running `npx tsc -p test/` from the `packages/node` directory. Not sure if we should do this typechecking in CI? ## 🧬 QA & Testing Do you notice any errors when running `npx tsc -p test/` from the `packages/node` directory? --- packages/node/src/lib/ReadMe.ts | 4 ++-- packages/node/test/index.test.ts | 4 ++-- .../node/test/lib/construct-payload.test.ts | 6 ++--- packages/node/test/lib/get-group-id.test.ts | 22 +++++++++++-------- .../node/test/lib/process-request.test.ts | 1 + packages/node/test/lib/verify-webhook.test.ts | 1 + packages/node/test/tsconfig.json | 3 ++- 7 files changed, 23 insertions(+), 18 deletions(-) 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/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 0a8d46951..19d2bfa8e 100644 --- a/packages/node/test/lib/get-group-id.test.ts +++ b/packages/node/test/lib/get-group-id.test.ts @@ -35,6 +35,7 @@ describe('getGroupId', () => { }); it('returns undefined when no user is passed', () => { + // @ts-expect-error deliberately passing in bad data const groupId = getGroupIdByOperation(undefined, operation as Operation); expect(groupId).toBeUndefined(); }); @@ -174,6 +175,7 @@ describe('getGroupId', () => { }); it('does not error if the keys array is null', () => { + // @ts-expect-error deliberately passing in bad data const user = mockUser(null); const groupId = getGroupIdByOperation(user, operation as Operation); @@ -184,6 +186,7 @@ describe('getGroupId', () => { describe('byApiKey', () => { it('returns undefined when no user is passed', () => { + // @ts-expect-error deliberately passing in bad data const groupId = getGroupByApiKey(undefined, 'requestApiKey'); expect(groupId).toBeUndefined(); }); @@ -194,6 +197,7 @@ describe('getGroupId', () => { }); 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(); }); @@ -220,14 +224,14 @@ describe('getGroupId', () => { ]); 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', () => { @@ -240,35 +244,35 @@ describe('getGroupId', () => { ]); 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'); }); }); @@ -283,7 +287,7 @@ describe('getGroupId', () => { ]); const groupId = getGroupByApiKey(user, 'requestApiKey'); - expect(groupId.id).toBe('key-1-id'); + expect(groupId?.id).toBe('key-1-id'); }); }); @@ -298,7 +302,7 @@ describe('getGroupId', () => { ]); 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"] }