From 2aada7d78c5162e292d536ac255b3d8680e6c251 Mon Sep 17 00:00:00 2001 From: Baylee Schmeisser <119542904+mxbaylee@users.noreply.github.com> Date: Tue, 27 Aug 2024 16:36:20 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=8C=90=20Enable=20correct=20handli?= =?UTF-8?q?ng=20of=20undefined=20in=20api=20package=20fetch.=20(#2036)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ๐ŸŽ’ Mark rbac as external, allowing tests to pass locally. * ๐Ÿงช Install `vitest` for apis client package. * ๐ŸŒ Enable correct handling of undefined in api package fetch. * ๐Ÿ’ฑ Add changeset. * Revert "๐ŸŽ’ Mark rbac as external, allowing tests to pass locally." This reverts commit a20368b7577ad80e3b2ab8b410083d14052c3e2c. * ๐Ÿงน lintin'. * ๐Ÿ”‘ Update lock file. * ๐Ÿงน lint. * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .changeset/tall-needles-rhyme.md | 5 ++ packages/api/package.json | 6 +- packages/api/src/client.test.ts | 14 +++ packages/api/src/client.ts | 2 +- pnpm-lock.yaml | 144 ++++++++++++++++++------------- 5 files changed, 109 insertions(+), 62 deletions(-) create mode 100644 .changeset/tall-needles-rhyme.md create mode 100644 packages/api/src/client.test.ts diff --git a/.changeset/tall-needles-rhyme.md b/.changeset/tall-needles-rhyme.md new file mode 100644 index 0000000000..2093797a8d --- /dev/null +++ b/.changeset/tall-needles-rhyme.md @@ -0,0 +1,5 @@ +--- +"@unkey/api": patch +--- + +fix: ๐ŸŒ Correctly handle `undefined` values in API package fetch. diff --git a/packages/api/package.json b/packages/api/package.json index cb0c0ba522..d176c00278 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -18,14 +18,16 @@ "author": "Andreas Thomas ", "scripts": { "generate": "openapi-typescript https://api.unkey.dev/openapi.json -o ./src/openapi.d.ts", - "build": "pnpm generate && tsup" + "build": "pnpm generate && tsup", + "test": "vitest run" }, "devDependencies": { "@types/node": "^20.14.9", "@unkey/tsconfig": "workspace:^", "openapi-typescript": "^6.7.5", "tsup": "^8.0.2", - "typescript": "^5.5.3" + "typescript": "^5.5.3", + "vitest": "^1.6.0" }, "dependencies": { "@unkey/rbac": "workspace:^" diff --git a/packages/api/src/client.test.ts b/packages/api/src/client.test.ts new file mode 100644 index 0000000000..2d682f5cda --- /dev/null +++ b/packages/api/src/client.test.ts @@ -0,0 +1,14 @@ +import { describe, expect, test } from "vitest"; +import { Unkey } from "./client"; + +describe("client", () => { + test("fetch can encode the params without throwing", async () => { + const unkey = new Unkey({ token: "rawr" }); + expect(() => { + unkey.apis.listKeys({ + apiId: "meow", + cursor: undefined, + }); + }).not.toThrow(); + }); +}); diff --git a/packages/api/src/client.ts b/packages/api/src/client.ts index d53fd44157..75d05cffbe 100644 --- a/packages/api/src/client.ts +++ b/packages/api/src/client.ts @@ -157,7 +157,7 @@ export class Unkey { const url = new URL(`${this.baseUrl}/${req.path.join("/")}`); if (req.query) { for (const [k, v] of Object.entries(req.query)) { - if (v === null) { + if (typeof v === "undefined" || v === null) { continue; } url.searchParams.set(k, v.toString()); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4f6368ff22..3c60070e64 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1223,7 +1223,7 @@ importers: devDependencies: checkly: specifier: latest - version: 4.7.0(@types/node@20.14.9)(typescript@5.5.3) + version: 4.8.1(@types/node@20.14.9)(typescript@5.5.3) ts-node: specifier: 10.9.1 version: 10.9.1(@types/node@20.14.9)(typescript@5.5.3) @@ -1508,6 +1508,9 @@ importers: typescript: specifier: ^5.5.3 version: 5.5.3 + vitest: + specifier: ^1.6.0 + version: 1.6.0(@types/node@20.14.9)(@vitest/ui@1.6.0) packages/cache: dependencies: @@ -6077,35 +6080,24 @@ packages: - typescript dev: true - /@oclif/core@3.27.0: - resolution: {integrity: sha512-Fg93aNFvXzBq5L7ztVHFP2nYwWU1oTCq48G0TjF/qC1UN36KWa2H5Hsm72kERd5x/sjy2M2Tn4kDEorUlpXOlw==} + /@oclif/core@4.0.19: + resolution: {integrity: sha512-VXnsYNVfmucXp5BdOA/OcWi8F/h2h8ofW1GxQDdspodnmnUgALEpqrxXBl5NFuA+iEihtAJeXzX260ICHYDaBg==} engines: {node: '>=18.0.0'} dependencies: - '@types/cli-progress': 3.11.6 ansi-escapes: 4.3.2 - ansi-styles: 4.3.0 - cardinal: 2.1.1 - chalk: 4.1.2 + ansis: 3.3.2 clean-stack: 3.0.1 - cli-progress: 3.12.0 - color: 4.2.3 + cli-spinners: 2.9.2 debug: 4.3.6(supports-color@8.1.1) ejs: 3.1.10 get-package-type: 0.1.0 globby: 11.1.0 - hyperlinker: 1.0.0 indent-string: 4.0.0 is-wsl: 2.2.0 - js-yaml: 3.14.1 + lilconfig: 3.1.2 minimatch: 9.0.5 - natural-orderby: 2.0.3 - object-treeify: 1.1.33 - password-prompt: 1.1.3 - slice-ansi: 4.0.0 string-width: 4.2.3 - strip-ansi: 6.0.1 supports-color: 8.1.1 - supports-hyperlinks: 2.3.0 widest-line: 3.1.0 wordwrap: 1.0.0 wrap-ansi: 7.0.0 @@ -6137,18 +6129,20 @@ packages: - typescript dev: true - /@oclif/plugin-plugins@4.1.12: - resolution: {integrity: sha512-lYNoqoQJz+p4AOMZ9N5k7OkLk/HZJSdaybJ4rWfDZ76pQ7AcrLEPtREi2wLfcwcrzKoBMsrwBoMTf3PnmpW7ZQ==} + /@oclif/plugin-plugins@5.4.4: + resolution: {integrity: sha512-p30fo3JPtbOqTJOX9A/8qKV/14XWt8xFgG/goVfIkuKBAO+cdY78ag8pYatlpzsYzJhO27X1MFn0WkkPWo36Ww==} engines: {node: '>=18.0.0'} dependencies: - '@oclif/core': 3.27.0 - chalk: 5.3.0 + '@oclif/core': 4.0.19 + ansis: 3.3.2 debug: 4.3.6(supports-color@8.1.1) - npm: 10.2.3 - npm-run-path: 4.0.1 + npm: 10.8.2 + npm-package-arg: 11.0.3 + npm-run-path: 5.3.0 + object-treeify: 4.0.1 semver: 7.6.3 - shelljs: 0.8.5 validate-npm-package-name: 5.0.1 + which: 4.0.0 yarn: 1.22.22 transitivePeerDependencies: - supports-color @@ -6998,7 +6992,7 @@ packages: resolution: {integrity: sha512-coUfuoMeIB7B8/NMekxaDzLhaYmp0HZNPEjYRm9goRou8UZIC3z21s0sL9AWoCw4EG876QyO3kYrc61WNF9B/w==} engines: {node: '>=8.0.0'} dependencies: - tslib: 2.4.1 + tslib: 2.7.0 dev: false /@peculiar/webcrypto@1.4.1: @@ -7008,7 +7002,7 @@ packages: '@peculiar/asn1-schema': 2.3.13 '@peculiar/json-schema': 1.1.12 pvtsutils: 1.3.5 - tslib: 2.4.1 + tslib: 2.7.0 webcrypto-core: 1.8.0 dev: false @@ -12354,6 +12348,11 @@ packages: resolution: {integrity: sha512-QXu7BPrP29VllRxH8GwB7x5iX5qWKAAMLqKQGWTeLWVlNHNOpVMJ91dsxQAIWXpjuW5wqvxu3Jd/nRjrJ+0pqg==} dev: true + /ansis@3.3.2: + resolution: {integrity: sha512-cFthbBlt+Oi0i9Pv/j6YdVWJh54CtjGACaMPCIrEV4Ha7HWsIjXDwseYV79TIL0B4+KfSwD5S70PeQDkPUd1rA==} + engines: {node: '>=15'} + dev: true + /any-promise@1.3.0: resolution: {integrity: sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A==} @@ -12486,11 +12485,6 @@ packages: tslib: 2.7.0 dev: true - /astral-regex@2.0.0: - resolution: {integrity: sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==} - engines: {node: '>=8'} - dev: true - /astring@1.8.6: resolution: {integrity: sha512-ISvCdHdlTDlH5IpxQJIex7BWBywFWgjJSVdwst+/iQCoEYnyOaQ95+X1JGshuBjGp6nxKUy1jMgE3zPqN7fQdg==} hasBin: true @@ -12563,8 +12557,8 @@ packages: resolution: {integrity: sha512-+H+kuK34PfMaI9PNU/NSjBKL5hh/KDM9J72kwYeYEm0A8B1AC4fuCy3qsjnA7lxklgyXsB68yn8Z2xoZEjgwCQ==} engines: {node: '>= 6.0.0'} - /axios@1.6.2: - resolution: {integrity: sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==} + /axios@1.7.4: + resolution: {integrity: sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==} dependencies: follow-redirects: 1.15.6 form-data: 4.0.0 @@ -12954,21 +12948,21 @@ packages: get-func-name: 2.0.2 dev: true - /checkly@4.7.0(@types/node@20.14.9)(typescript@5.5.3): - resolution: {integrity: sha512-OVEn7iUrtTs/YrxmNcWo7jQkH+e5LS0/KhF+MmIi8DbrCc8sCBppO1JyEnjoKcslCkV/Rilad66LShI6V/cqvQ==} + /checkly@4.8.1(@types/node@20.14.9)(typescript@5.5.3): + resolution: {integrity: sha512-LyVxHVOqjZ6k/QXGZQhZgnG7stL5mYfzu+Vl5hkdh2ZKDm/MLk4Q+gRKAyMLOjMN66jrJN1ZM1K3zlLt2/EJcg==} engines: {node: '>=16.0.0'} hasBin: true dependencies: '@oclif/core': 2.8.11(@types/node@20.14.9)(typescript@5.5.3) '@oclif/plugin-help': 5.1.20 '@oclif/plugin-not-found': 2.3.23(@types/node@20.14.9)(typescript@5.5.3) - '@oclif/plugin-plugins': 4.1.12 + '@oclif/plugin-plugins': 5.4.4 '@oclif/plugin-warn-if-update-available': 2.0.24(@types/node@20.14.9)(typescript@5.5.3) '@typescript-eslint/typescript-estree': 6.19.0(typescript@5.5.3) acorn: 8.8.1 acorn-walk: 8.2.0 async-mqtt: 2.6.3 - axios: 1.6.2 + axios: 1.7.4 chalk: 4.1.2 ci-info: 3.8.0 conf: 10.2.0 @@ -14254,7 +14248,7 @@ packages: resolution: {integrity: sha512-Kv5nKlh6yRrdrGvxeJ2e5y2eRUpkUosIW4A2AS38zwSz27zu7ufDwQPi5Jhs3XAlGNetl3bmnGhQsMtkKJnj3w==} dependencies: no-case: 3.0.4 - tslib: 2.4.1 + tslib: 2.7.0 dev: false /dot-prop@6.0.1: @@ -15457,7 +15451,7 @@ packages: engines: {node: '>= 10.17.0'} hasBin: true dependencies: - debug: 4.3.4 + debug: 4.3.6(supports-color@8.1.1) get-stream: 5.2.0 yauzl: 2.10.0 optionalDependencies: @@ -16696,6 +16690,13 @@ packages: resolution: {integrity: sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==} dev: true + /hosted-git-info@7.0.2: + resolution: {integrity: sha512-puUZAUKT5m8Zzvs72XWy3HtvVbTWljRE66cP60bxJzAqf2DgICo7lYTY2IHUmLnNpjYvw5bvmoHvPc0QO2a62w==} + engines: {node: ^16.14.0 || >=18.0.0} + dependencies: + lru-cache: 10.4.3 + dev: true + /html-escaper@2.0.2: resolution: {integrity: sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==} dev: false @@ -16957,6 +16958,7 @@ packages: /interpret@1.4.0: resolution: {integrity: sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==} engines: {node: '>= 0.10'} + dev: false /invariant@2.2.4: resolution: {integrity: sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==} @@ -17348,6 +17350,11 @@ packages: /isexe@2.0.0: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} + /isexe@3.1.1: + resolution: {integrity: sha512-LpB/54B+/2J5hqQ7imZHfdU31OlgQqx7ZicVlkm9kzg9/w8GKLEcFfJl/t7DCEDueOyBAD6zCCwTO6Fzs0NoEQ==} + engines: {node: '>=16'} + dev: true + /isomorphic-fetch@3.0.0: resolution: {integrity: sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==} dependencies: @@ -17910,7 +17917,7 @@ packages: /lower-case@2.0.2: resolution: {integrity: sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg==} dependencies: - tslib: 2.4.1 + tslib: 2.7.0 dev: false /lowercase-keys@3.0.0: @@ -19306,6 +19313,7 @@ packages: /minipass@6.0.2: resolution: {integrity: sha512-MzWSV5nYVT7mVyWCwn2o7JH13w2TBRmmSqSRCKzTw+lmft9X4z+3wjvs06Tzijo5z4W/kahUCDpRXTF+ZrmF/w==} engines: {node: '>=16 || 14 >=14.17'} + dev: true /minipass@7.1.2: resolution: {integrity: sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==} @@ -19807,7 +19815,7 @@ packages: resolution: {integrity: sha512-fgAN3jGAh+RoxUGZHTSOLJIqUc2wmoBwGR4tbpNAKmmovFoWq0OdRkb0VkldReO2a2iBT/OEulG9XSUc10r3zg==} dependencies: lower-case: 2.0.2 - tslib: 2.4.1 + tslib: 2.7.0 dev: false /node-addon-api@7.1.1: @@ -19910,6 +19918,16 @@ packages: engines: {node: '>=14.16'} dev: true + /npm-package-arg@11.0.3: + resolution: {integrity: sha512-sHGJy8sOC1YraBywpzQlIKBE4pBbGbiF95U6Auspzyem956E0+FtDtsx1ZxlOJkQCZ1AFXAY/yuvtFYrOxF+Bw==} + engines: {node: ^16.14.0 || >=18.0.0} + dependencies: + hosted-git-info: 7.0.2 + proc-log: 4.2.0 + semver: 7.6.3 + validate-npm-package-name: 5.0.1 + dev: true + /npm-run-path@4.0.1: resolution: {integrity: sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==} engines: {node: '>=8'} @@ -19928,8 +19946,8 @@ packages: engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dev: false - /npm@10.2.3: - resolution: {integrity: sha512-GbUui/rHTl0mW8HhJSn4A0Xg89yCR3I9otgJT1i0z1QBPOVlgbh6rlcUTpHT8Gut9O1SJjWRUU0nEcAymhG2tQ==} + /npm@10.8.2: + resolution: {integrity: sha512-x/AIjFIKRllrhcb48dqUNAAZl0ig9+qMuN91RpZo3Cb2+zuibfh+KISl6+kVVyktDz230JKc208UkQwwMqyB+w==} engines: {node: ^18.17.0 || >=20.5.0} hasBin: true dev: true @@ -19941,6 +19959,7 @@ packages: - '@npmcli/map-workspaces' - '@npmcli/package-json' - '@npmcli/promise-spawn' + - '@npmcli/redact' - '@npmcli/run-script' - '@sigstore/tuf' - abbrev @@ -19949,8 +19968,6 @@ packages: - chalk - ci-info - cli-columns - - cli-table3 - - columnify - fastest-levenshtein - fs-minipass - glob @@ -19986,7 +20003,6 @@ packages: - npm-profile - npm-registry-fetch - npm-user-validate - - npmlog - p-map - pacote - parse-conflict-json @@ -19996,7 +20012,6 @@ packages: - semver - spdx-expression-parse - ssri - - strip-ansi - supports-color - tar - text-table @@ -20072,6 +20087,11 @@ packages: engines: {node: '>= 10'} dev: true + /object-treeify@4.0.1: + resolution: {integrity: sha512-Y6tg5rHfsefSkfKujv2SwHulInROy/rCL5F4w0QOWxut8AnxYxf0YmNhTh95Zfyxpsudo66uqkux0ACFnyMSgQ==} + engines: {node: '>= 16'} + dev: true + /object-values@1.0.0: resolution: {integrity: sha512-+8hwcz/JnQ9EpLIXzN0Rs7DLsBpJNT/xYehtB/jU93tHYr5BFEO8E+JGQNOSqE7opVzz5cGksKFHt7uUJVLSjQ==} engines: {node: '>=0.10.0'} @@ -20486,7 +20506,7 @@ packages: engines: {node: '>=16 || 14 >=14.18'} dependencies: lru-cache: 10.4.3 - minipass: 6.0.2 + minipass: 7.1.2 /path-to-regexp@0.1.7: resolution: {integrity: sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==} @@ -20696,7 +20716,7 @@ packages: dependencies: nanoid: 3.3.7 picocolors: 1.0.1 - source-map-js: 1.0.2 + source-map-js: 1.2.0 dev: false /postcss@8.4.38: @@ -20823,6 +20843,11 @@ packages: '@probe.gl/stats': 3.6.0 dev: false + /proc-log@4.2.0: + resolution: {integrity: sha512-g8+OnU/L2v+wyiVK+D5fA34J7EH8jZ8DDlvwhRCMxmMj7UCBvxiO1mGeN+36JXIKF4zevU4kRBd8lVgG9vLelA==} + engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} + dev: true + /process-nextick-args@2.0.1: resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==} dev: true @@ -21539,6 +21564,7 @@ packages: engines: {node: '>= 0.10'} dependencies: resolve: 1.22.8 + dev: false /redent@3.0.0: resolution: {integrity: sha512-6tDA8g98We0zd0GvVeMT9arEOnTw9qM03L9cJXaCjrip1OO764RDBLBfrB4cwzNGDj5OA5ioymC9GkizgWJDUg==} @@ -22391,6 +22417,7 @@ packages: glob: 7.2.3 interpret: 1.4.0 rechoir: 0.6.2 + dev: false /shiki@0.14.7: resolution: {integrity: sha512-dNPAPrxSc87ua2sKJ3H5dQ/6ZaY8RNnaAqK+t0eG7p0Soi2ydiqbGOTaZCqaYvA/uZYfS1LJnemt3Q+mSfcPCg==} @@ -22477,15 +22504,6 @@ packages: engines: {node: '>=8'} dev: true - /slice-ansi@4.0.0: - resolution: {integrity: sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ==} - engines: {node: '>=10'} - dependencies: - ansi-styles: 4.3.0 - astral-regex: 2.0.0 - is-fullwidth-code-point: 3.0.0 - dev: true - /slice-ansi@5.0.0: resolution: {integrity: sha512-FC+lgizVPfie0kkhqUScwRu1O/lF6NOgJmlCgK+/LYxDCTk8sGelYaHDhFcDN+Sn3Cv+3VSa4Byeo+IMCzpMgQ==} engines: {node: '>=12'} @@ -22527,7 +22545,7 @@ packages: resolution: {integrity: sha512-LAOh4z89bGQvl9pFfNF8V146i7o7/CqFPbqzYgP+yYzDIDeS9HaNFtXABamRW+AQzEVODcvE79ljJ+8a9YSdMg==} dependencies: dot-case: 3.0.4 - tslib: 2.4.1 + tslib: 2.7.0 dev: false /snakecase-keys@3.2.1: @@ -24870,6 +24888,14 @@ packages: dependencies: isexe: 2.0.0 + /which@4.0.0: + resolution: {integrity: sha512-GlaYyEb07DPxYCKhKzplCWBJtvxZcZMrL+4UkrTSJHHPyZU4mYYTv3qaOe77H7EODLSSopAUFAc6W8U4yqvscg==} + engines: {node: ^16.13.0 || >=18.0.0} + hasBin: true + dependencies: + isexe: 3.1.1 + dev: true + /why-is-node-running@2.3.0: resolution: {integrity: sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==} engines: {node: '>=8'}