Skip to content

Commit

Permalink
fix: 🌐 Enable correct handling of undefined in api package fetch. (#2036
Browse files Browse the repository at this point in the history
)

* πŸŽ’ 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 a20368b.

* 🧹 lintin'.

* πŸ”‘ Update lock file.

* 🧹 lint.

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
mxbaylee and autofix-ci[bot] authored Aug 27, 2024
1 parent abe2224 commit 2aada7d
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 62 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-needles-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@unkey/api": patch
---

fix: 🌐 Correctly handle `undefined` values in API package fetch.
6 changes: 4 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
"author": "Andreas Thomas <andreas@chronark.com>",
"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:^"
Expand Down
14 changes: 14 additions & 0 deletions packages/api/src/client.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
2 changes: 1 addition & 1 deletion packages/api/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Loading

1 comment on commit 2aada7d

@vercel
Copy link

@vercel vercel bot commented on 2aada7d Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

planetfall – ./apps/planetfall

planetfall-unkey.vercel.app
planetfall.unkey.dev
planetfall-git-main-unkey.vercel.app
planetfall-two.vercel.app

Please sign in to comment.