Skip to content

Commit

Permalink
Merge branch 'main' into feat/logs-v2-data-fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
ogzhanolguncu authored Jan 22, 2025
2 parents b048018 + ab37986 commit 041c786
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 72 deletions.
6 changes: 6 additions & 0 deletions apps/dashboard/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @unkey/web

## 0.1.42

### Patch Changes

- @unkey/ratelimit@0.5.3

## 0.1.41

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@unkey/dashboard",
"version": "0.1.41",
"version": "0.1.42",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
6 changes: 6 additions & 0 deletions packages/api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @unkey/api

## 0.32.0

### Minor Changes

- a2f16f0: Add all options to verifyKey

## 0.31.0

### Minor Changes
Expand Down
13 changes: 10 additions & 3 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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 <[email protected]>",
"scripts": {
"generate": "openapi-typescript https://api.unkey.dev/openapi.json -o ./src/openapi.d.ts",
Expand Down
198 changes: 140 additions & 58 deletions packages/api/src/openapi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down Expand Up @@ -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). */
Expand Down Expand Up @@ -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: {
Expand Down
11 changes: 10 additions & 1 deletion packages/api/src/verify.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { PermissionQuery } from "@unkey/rbac";
import { Unkey } from "./client";
import type { paths } from "./openapi";

/**
* Verify a key
Expand All @@ -21,7 +23,14 @@ import { Unkey } from "./client";
* console.log(result)
* ```
*/
export function verifyKey(req: string | { key: string; apiId: string }) {
export function verifyKey<TPermission extends string = string>(
req:
| string
| (Omit<
paths["/v1/keys.verifyKey"]["post"]["requestBody"]["content"]["application/json"],
"authorization"
> & { authorization?: { permissions: PermissionQuery<TPermission> } }),
) {
// 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" });
Expand Down
7 changes: 7 additions & 0 deletions packages/hono/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @unkey/hono

## 1.4.13

### Patch Changes

- Updated dependencies [a2f16f0]
- @unkey/api@0.32.0

## 1.4.12

### Patch Changes
Expand Down
13 changes: 10 additions & 3 deletions packages/hono/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
{
"name": "@unkey/hono",
"version": "1.4.12",
"version": "1.4.13",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"license": "MIT",
"private": false,
"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 <[email protected]>",
"scripts": {
"build": "tsup",
Expand Down
7 changes: 7 additions & 0 deletions packages/nextjs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @unkey/nextjs

## 0.18.6

### Patch Changes

- Updated dependencies [a2f16f0]
- @unkey/api@0.32.0

## 0.18.5

### Patch Changes
Expand Down
13 changes: 10 additions & 3 deletions packages/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
{
"name": "@unkey/nextjs",
"version": "0.18.5",
"version": "0.18.6",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"license": "MIT",
"private": false,
"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 <[email protected]>",
"scripts": {
"build": "tsup"
Expand Down
Loading

0 comments on commit 041c786

Please sign in to comment.