From a2f16f093fe3314d20fcc6fc0516d4256229add9 Mon Sep 17 00:00:00 2001 From: Andreas Thomas Date: Tue, 21 Jan 2025 17:54:55 +0100 Subject: [PATCH 1/2] feat: add all options to verifyKey (#2827) * feat: add all options to verifyKey * fix: allow string as requirement * [autofix.ci] apply automated fixes * revert: lock file * chore: remove empty line --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .changeset/unlucky-bottles-punch.md | 5 + packages/api/src/openapi.d.ts | 198 ++++++++++++++++++++-------- packages/api/src/verify.ts | 11 +- 3 files changed, 155 insertions(+), 59 deletions(-) create mode 100644 .changeset/unlucky-bottles-punch.md diff --git a/.changeset/unlucky-bottles-punch.md b/.changeset/unlucky-bottles-punch.md new file mode 100644 index 0000000000..be0c686188 --- /dev/null +++ b/.changeset/unlucky-bottles-punch.md @@ -0,0 +1,5 @@ +--- +"@unkey/api": minor +--- + +Add all options to verifyKey diff --git a/packages/api/src/openapi.d.ts b/packages/api/src/openapi.d.ts index 9db6d29640..7deedc11e3 100644 --- a/packages/api/src/openapi.d.ts +++ b/packages/api/src/openapi.d.ts @@ -38,7 +38,7 @@ export interface paths { post: operations["updateRemaining"]; }; "/v1/keys.getVerifications": { - get: operations["getVerifications"]; + get: operations["keys.getVerifications"]; }; "/v1/keys.addPermissions": { post: operations["addPermissions"]; @@ -1607,72 +1607,44 @@ export interface operations { }; }; }; - getVerifications: { + "keys.getVerifications": { parameters: { - query: { - apiId: string; - externalId?: string; - keyId?: string | string[]; - tag?: string | string[]; + query?: { + keyId?: string; + ownerId?: string; start?: number | null; end?: number | null; - groupBy?: - | ("key" | "identity" | "tags" | "tag" | "month" | "day" | "hour") - | ("key" | "identity" | "tags" | "tag" | "month" | "day" | "hour")[]; - limit?: number; - orderBy?: - | "time" - | "valid" - | "notFound" - | "forbidden" - | "usageExceeded" - | "rateLimited" - | "unauthorized" - | "disabled" - | "insufficientPermissions" - | "expired" - | "total"; - order?: "asc" | "desc"; + granularity?: "day"; }; }; responses: { - /** @description Retrieve all required data to build end-user facing dashboards and drive your usage-based billing. */ + /** @description Usage numbers over time */ 200: { content: { "application/json": { - /** @description Unix timestamp in milliseconds of the start of the current time slice. */ - time?: number; - valid?: number; - notFound?: number; - forbidden?: number; - usageExceeded?: number; - rateLimited?: number; - unauthorized?: number; - disabled?: number; - insufficientPermissions?: number; - expired?: number; - /** @description Total number of verifications in the current time slice, regardless of outcome. */ - total: number; - /** @description Only available when grouping by tag. */ - tag?: string; - /** @description Filter by one or multiple tags. If multiple tags are provided */ - tags?: string[]; - /** - * @description - * Only available when specifying groupBy=key in the query. - * In this case there would be one datapoint per time and groupBy target. - */ - keyId?: string; - /** - * @description - * Only available when specifying groupBy=identity in the query. - * In this case there would be one datapoint per time and groupBy target. - */ - identity?: { - id: string; - externalId: string; - }; - }[]; + verifications: { + /** + * @description The timestamp of the usage data + * @example 1620000000000 + */ + time: number; + /** + * @description The number of successful requests + * @example 100 + */ + success: number; + /** + * @description The number of requests that were rate limited + * @example 10 + */ + rateLimited: number; + /** + * @description The number of requests that exceeded the usage limit + * @example 0 + */ + usageExceeded: number; + }[]; + }; }; }; /** @description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). */ @@ -4523,6 +4495,116 @@ export interface operations { }; }; }; + getVerifications: { + parameters: { + query: { + apiId: string; + externalId?: string; + keyId?: string | string[]; + tag?: string | string[]; + start?: number | null; + end?: number | null; + groupBy?: + | ("key" | "identity" | "tags" | "tag" | "month" | "day" | "hour") + | ("key" | "identity" | "tags" | "tag" | "month" | "day" | "hour")[]; + limit?: number; + orderBy?: + | "time" + | "valid" + | "notFound" + | "forbidden" + | "usageExceeded" + | "rateLimited" + | "unauthorized" + | "disabled" + | "insufficientPermissions" + | "expired" + | "total"; + order?: "asc" | "desc"; + }; + }; + responses: { + /** @description Retrieve all required data to build end-user facing dashboards and drive your usage-based billing. */ + 200: { + content: { + "application/json": { + /** @description Unix timestamp in milliseconds of the start of the current time slice. */ + time?: number; + valid?: number; + notFound?: number; + forbidden?: number; + usageExceeded?: number; + rateLimited?: number; + unauthorized?: number; + disabled?: number; + insufficientPermissions?: number; + expired?: number; + /** @description Total number of verifications in the current time slice, regardless of outcome. */ + total: number; + /** @description Only available when grouping by tag. */ + tag?: string; + /** @description Filter by one or multiple tags. If multiple tags are provided */ + tags?: string[]; + /** + * @description Only available when specifying groupBy=key in the query. + * In this case there would be one datapoint per time and groupBy target. + */ + keyId?: string; + /** + * @description Only available when specifying groupBy=identity in the query. + * In this case there would be one datapoint per time and groupBy target. + */ + identity?: { + id: string; + externalId: string; + }; + }[]; + }; + }; + /** @description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). */ + 400: { + content: { + "application/json": components["schemas"]["ErrBadRequest"]; + }; + }; + /** @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. */ + 401: { + content: { + "application/json": components["schemas"]["ErrUnauthorized"]; + }; + }; + /** @description The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server. */ + 403: { + content: { + "application/json": components["schemas"]["ErrForbidden"]; + }; + }; + /** @description The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web. */ + 404: { + content: { + "application/json": components["schemas"]["ErrNotFound"]; + }; + }; + /** @description This response is sent when a request conflicts with the current state of the server. */ + 409: { + content: { + "application/json": components["schemas"]["ErrConflict"]; + }; + }; + /** @description The user has sent too many requests in a given amount of time ("rate limiting") */ + 429: { + content: { + "application/json": components["schemas"]["ErrTooManyRequests"]; + }; + }; + /** @description The server has encountered a situation it does not know how to handle. */ + 500: { + content: { + "application/json": components["schemas"]["ErrInternalServerError"]; + }; + }; + }; + }; "deprecated.createKey": { requestBody: { content: { diff --git a/packages/api/src/verify.ts b/packages/api/src/verify.ts index cdecdcb81d..11ea8aa627 100644 --- a/packages/api/src/verify.ts +++ b/packages/api/src/verify.ts @@ -1,4 +1,6 @@ +import type { PermissionQuery } from "@unkey/rbac"; import { Unkey } from "./client"; +import type { paths } from "./openapi"; /** * Verify a key @@ -21,7 +23,14 @@ import { Unkey } from "./client"; * console.log(result) * ``` */ -export function verifyKey(req: string | { key: string; apiId: string }) { +export function verifyKey( + req: + | string + | (Omit< + paths["/v1/keys.verifyKey"]["post"]["requestBody"]["content"]["application/json"], + "authorization" + > & { authorization?: { permissions: PermissionQuery } }), +) { // yes this is empty to make typescript happy but we don't need a token for verifying keys // it's not the cleanest but it works for now :) const unkey = new Unkey({ rootKey: "public" }); From ab3798622091dca99a22d0b7a21a3787bcc6fb34 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 21 Jan 2025 17:07:47 +0000 Subject: [PATCH 2/2] chore(release): version packages (#2828) Co-authored-by: github-actions[bot] --- .changeset/unlucky-bottles-punch.md | 5 ----- apps/dashboard/CHANGELOG.md | 6 ++++++ apps/dashboard/package.json | 2 +- packages/api/CHANGELOG.md | 6 ++++++ packages/api/package.json | 13 ++++++++++--- packages/hono/CHANGELOG.md | 7 +++++++ packages/hono/package.json | 13 ++++++++++--- packages/nextjs/CHANGELOG.md | 7 +++++++ packages/nextjs/package.json | 13 ++++++++++--- packages/ratelimit/CHANGELOG.md | 7 +++++++ packages/ratelimit/package.json | 14 +++++++++++--- 11 files changed, 75 insertions(+), 18 deletions(-) delete mode 100644 .changeset/unlucky-bottles-punch.md diff --git a/.changeset/unlucky-bottles-punch.md b/.changeset/unlucky-bottles-punch.md deleted file mode 100644 index be0c686188..0000000000 --- a/.changeset/unlucky-bottles-punch.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@unkey/api": minor ---- - -Add all options to verifyKey diff --git a/apps/dashboard/CHANGELOG.md b/apps/dashboard/CHANGELOG.md index d7b0e165bc..3a9deee3c1 100644 --- a/apps/dashboard/CHANGELOG.md +++ b/apps/dashboard/CHANGELOG.md @@ -1,5 +1,11 @@ # @unkey/web +## 0.1.42 + +### Patch Changes + +- @unkey/ratelimit@0.5.3 + ## 0.1.41 ### Patch Changes diff --git a/apps/dashboard/package.json b/apps/dashboard/package.json index 88fb99b45b..fe44561bd9 100644 --- a/apps/dashboard/package.json +++ b/apps/dashboard/package.json @@ -1,6 +1,6 @@ { "name": "@unkey/dashboard", - "version": "0.1.41", + "version": "0.1.42", "private": true, "scripts": { "dev": "next dev", diff --git a/packages/api/CHANGELOG.md b/packages/api/CHANGELOG.md index cc5be5359a..66e20c2b5d 100644 --- a/packages/api/CHANGELOG.md +++ b/packages/api/CHANGELOG.md @@ -1,5 +1,11 @@ # @unkey/api +## 0.32.0 + +### Minor Changes + +- a2f16f0: Add all options to verifyKey + ## 0.31.0 ### Minor Changes diff --git a/packages/api/package.json b/packages/api/package.json index c6fef3285c..daf3b014f8 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -1,6 +1,6 @@ { "name": "@unkey/api", - "version": "0.31.0", + "version": "0.32.0", "main": "./dist/index.js", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", @@ -9,12 +9,19 @@ "publishConfig": { "access": "public" }, - "keywords": ["unkey", "client", "api"], + "keywords": [ + "unkey", + "client", + "api" + ], "bugs": { "url": "https://github.com/unkeyed/unkey/issues" }, "homepage": "https://github.com/unkeyed/unkey#readme", - "files": ["./dist/**", "README.md"], + "files": [ + "./dist/**", + "README.md" + ], "author": "Andreas Thomas ", "scripts": { "generate": "openapi-typescript https://api.unkey.dev/openapi.json -o ./src/openapi.d.ts", diff --git a/packages/hono/CHANGELOG.md b/packages/hono/CHANGELOG.md index 09829a24ad..52e2b2b3d7 100644 --- a/packages/hono/CHANGELOG.md +++ b/packages/hono/CHANGELOG.md @@ -1,5 +1,12 @@ # @unkey/hono +## 1.4.13 + +### Patch Changes + +- Updated dependencies [a2f16f0] + - @unkey/api@0.32.0 + ## 1.4.12 ### Patch Changes diff --git a/packages/hono/package.json b/packages/hono/package.json index eaba9a4e89..e6b30ebb50 100644 --- a/packages/hono/package.json +++ b/packages/hono/package.json @@ -1,6 +1,6 @@ { "name": "@unkey/hono", - "version": "1.4.12", + "version": "1.4.13", "main": "./dist/index.js", "types": "./dist/index.d.ts", "license": "MIT", @@ -8,12 +8,19 @@ "publishConfig": { "access": "public" }, - "keywords": ["unkey", "client", "api", "hono"], + "keywords": [ + "unkey", + "client", + "api", + "hono" + ], "bugs": { "url": "https://github.com/unkeyed/unkey/issues" }, "homepage": "https://github.com/unkeyed/unkey#readme", - "files": ["./dist/**"], + "files": [ + "./dist/**" + ], "author": "Andreas Thomas ", "scripts": { "build": "tsup", diff --git a/packages/nextjs/CHANGELOG.md b/packages/nextjs/CHANGELOG.md index bc0b146713..0900b69445 100644 --- a/packages/nextjs/CHANGELOG.md +++ b/packages/nextjs/CHANGELOG.md @@ -1,5 +1,12 @@ # @unkey/nextjs +## 0.18.6 + +### Patch Changes + +- Updated dependencies [a2f16f0] + - @unkey/api@0.32.0 + ## 0.18.5 ### Patch Changes diff --git a/packages/nextjs/package.json b/packages/nextjs/package.json index 4786b6ec4d..2fbf99dbde 100644 --- a/packages/nextjs/package.json +++ b/packages/nextjs/package.json @@ -1,6 +1,6 @@ { "name": "@unkey/nextjs", - "version": "0.18.5", + "version": "0.18.6", "main": "./dist/index.js", "types": "./dist/index.d.ts", "license": "MIT", @@ -8,12 +8,19 @@ "publishConfig": { "access": "public" }, - "keywords": ["unkey", "client", "api"], + "keywords": [ + "unkey", + "client", + "api" + ], "bugs": { "url": "https://github.com/unkeyed/unkey/issues" }, "homepage": "https://github.com/unkeyed/unkey#readme", - "files": ["./dist/**", "README.md"], + "files": [ + "./dist/**", + "README.md" + ], "author": "Andreas Thomas ", "scripts": { "build": "tsup" diff --git a/packages/ratelimit/CHANGELOG.md b/packages/ratelimit/CHANGELOG.md index ca7f3b0586..cf04f5e3a0 100644 --- a/packages/ratelimit/CHANGELOG.md +++ b/packages/ratelimit/CHANGELOG.md @@ -1,5 +1,12 @@ # @unkey/ratelimit +## 0.5.3 + +### Patch Changes + +- Updated dependencies [a2f16f0] + - @unkey/api@0.32.0 + ## 0.5.2 ### Patch Changes diff --git a/packages/ratelimit/package.json b/packages/ratelimit/package.json index dbedb47d42..2374dc904d 100644 --- a/packages/ratelimit/package.json +++ b/packages/ratelimit/package.json @@ -1,6 +1,6 @@ { "name": "@unkey/ratelimit", - "version": "0.5.2", + "version": "0.5.3", "main": "./dist/index.js", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", @@ -9,12 +9,20 @@ "publishConfig": { "access": "public" }, - "keywords": ["unkey", "ratelimit", "global", "serverless"], + "keywords": [ + "unkey", + "ratelimit", + "global", + "serverless" + ], "bugs": { "url": "https://github.com/unkeyed/unkey/issues" }, "homepage": "https://github.com/unkeyed/unkey#readme", - "files": ["./dist/**", "README.md"], + "files": [ + "./dist/**", + "README.md" + ], "author": "Andreas Thomas ", "scripts": { "build": "tsup"