Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash-1511 authored Oct 23, 2024
2 parents 469d548 + b456ac0 commit 5ceaba6
Show file tree
Hide file tree
Showing 45 changed files with 131 additions and 122 deletions.
4 changes: 2 additions & 2 deletions apps/dashboard/lib/trpc/ratelimitProcedure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const ratelimit = env().UNKEY_ROOT_KEY
create: new Ratelimit({
rootKey: env().UNKEY_ROOT_KEY ?? "",
namespace: "trpc_create",
limit: 5,
limit: 25,
duration: "3s",
}),

Expand All @@ -22,7 +22,7 @@ export const ratelimit = env().UNKEY_ROOT_KEY
delete: new Ratelimit({
rootKey: env().UNKEY_ROOT_KEY ?? "",
namespace: "trpc_delete",
limit: 5,
limit: 25,
duration: "5s",
}),
}
Expand Down
5 changes: 3 additions & 2 deletions apps/dashboard/lib/trpc/routers/api/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { z } from "zod";

import { insertAuditLogs } from "@/lib/audit";
import { db, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";
import { newId } from "@unkey/id";
import { auth, t } from "../../trpc";

export const createApi = rateLimitedProcedure(ratelimit.create)
export const createApi = t.procedure
.use(auth)
.input(
z.object({
name: z
Expand Down
6 changes: 3 additions & 3 deletions apps/dashboard/lib/trpc/routers/api/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { z } from "zod";

import { insertAuditLogs } from "@/lib/audit";
import { db, eq, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";

export const deleteApi = rateLimitedProcedure(ratelimit.delete)
import { auth, t } from "../../trpc";
export const deleteApi = t.procedure
.use(auth)
.input(
z.object({
apiId: z.string(),
Expand Down
5 changes: 3 additions & 2 deletions apps/dashboard/lib/trpc/routers/api/setDefaultBytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { z } from "zod";

import { insertAuditLogs } from "@/lib/audit";
import { db, eq, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";
import { auth, t } from "../../trpc";

export const setDefaultApiBytes = rateLimitedProcedure(ratelimit.update)
export const setDefaultApiBytes = t.procedure
.use(auth)
.input(
z.object({
defaultBytes: z
Expand Down
5 changes: 3 additions & 2 deletions apps/dashboard/lib/trpc/routers/api/setDefaultPrefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { z } from "zod";

import { insertAuditLogs } from "@/lib/audit";
import { db, eq, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";
import { auth, t } from "../../trpc";

export const setDefaultApiPrefix = rateLimitedProcedure(ratelimit.update)
export const setDefaultApiPrefix = t.procedure
.use(auth)
.input(
z.object({
defaultPrefix: z.string().max(8, "Prefix can be a maximum of 8 characters"),
Expand Down
6 changes: 4 additions & 2 deletions apps/dashboard/lib/trpc/routers/api/updateDeleteProtection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { z } from "zod";

import { insertAuditLogs } from "@/lib/audit";
import { db, eq, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";

export const updateAPIDeleteProtection = rateLimitedProcedure(ratelimit.update)
import { auth, t } from "../../trpc";

export const updateAPIDeleteProtection = t.procedure
.use(auth)
.input(
z.object({
apiId: z.string(),
Expand Down
6 changes: 4 additions & 2 deletions apps/dashboard/lib/trpc/routers/api/updateIpWhitelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { z } from "zod";

import { insertAuditLogs } from "@/lib/audit";
import { db, eq, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";

export const updateApiIpWhitelist = rateLimitedProcedure(ratelimit.update)
import { auth, t } from "../../trpc";

export const updateApiIpWhitelist = t.procedure
.use(auth)
.input(
z.object({
ipWhitelist: z
Expand Down
6 changes: 4 additions & 2 deletions apps/dashboard/lib/trpc/routers/api/updateName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { z } from "zod";

import { insertAuditLogs } from "@/lib/audit";
import { db, eq, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";

export const updateApiName = rateLimitedProcedure(ratelimit.update)
import { auth, t } from "../../trpc";

export const updateApiName = t.procedure
.use(auth)
.input(
z.object({
name: z.string().min(3, "API names must contain at least 3 characters"),
Expand Down
5 changes: 3 additions & 2 deletions apps/dashboard/lib/trpc/routers/key/create.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { insertAuditLogs } from "@/lib/audit";
import { db, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";
import { TRPCError } from "@trpc/server";
import { newId } from "@unkey/id";
import { newKey } from "@unkey/keys";
import { z } from "zod";
import { auth, t } from "../../trpc";

export const createKey = rateLimitedProcedure(ratelimit.create)
export const createKey = t.procedure
.use(auth)
.input(
z.object({
prefix: z.string().optional(),
Expand Down
5 changes: 3 additions & 2 deletions apps/dashboard/lib/trpc/routers/key/createRootKey.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { db, eq, schema } from "@/lib/db";
import { env } from "@/lib/env";
import type { UnkeyAuditLog } from "@/lib/tinybird";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";
import { TRPCError } from "@trpc/server";
import { newId } from "@unkey/id";
import { newKey } from "@unkey/keys";
import { unkeyPermissionValidation } from "@unkey/rbac";
import { z } from "zod";
import { auth, t } from "../../trpc";

import { insertAuditLogs } from "@/lib/audit";
import { upsertPermissions } from "../rbac";

export const createRootKey = rateLimitedProcedure(ratelimit.create)
export const createRootKey = t.procedure
.use(auth)
.input(
z.object({
name: z.string().optional(),
Expand Down
5 changes: 3 additions & 2 deletions apps/dashboard/lib/trpc/routers/key/delete.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { insertAuditLogs } from "@/lib/audit";
import { and, db, eq, inArray, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";
import { TRPCError } from "@trpc/server";
import { z } from "zod";
import { auth, t } from "../../trpc";

export const deleteKeys = rateLimitedProcedure(ratelimit.delete)
export const deleteKeys = t.procedure
.use(auth)
.input(
z.object({
keyIds: z.array(z.string()),
Expand Down
6 changes: 3 additions & 3 deletions apps/dashboard/lib/trpc/routers/key/deleteRootKey.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { insertAuditLogs } from "@/lib/audit";
import { db, inArray, schema } from "@/lib/db";
import { env } from "@/lib/env";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";
import { TRPCError } from "@trpc/server";
import { z } from "zod";

export const deleteRootKeys = rateLimitedProcedure(ratelimit.delete)
import { auth, t } from "../../trpc";
export const deleteRootKeys = t.procedure
.use(auth)
.input(
z.object({
keyIds: z.array(z.string()),
Expand Down
6 changes: 3 additions & 3 deletions apps/dashboard/lib/trpc/routers/key/updateEnabled.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { insertAuditLogs } from "@/lib/audit";
import { db, eq, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";
import { TRPCError } from "@trpc/server";
import { z } from "zod";

export const updateKeyEnabled = rateLimitedProcedure(ratelimit.update)
import { auth, t } from "../../trpc";
export const updateKeyEnabled = t.procedure
.use(auth)
.input(
z.object({
keyId: z.string(),
Expand Down
6 changes: 3 additions & 3 deletions apps/dashboard/lib/trpc/routers/key/updateExpiration.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { insertAuditLogs } from "@/lib/audit";
import { db, eq, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";
import { TRPCError } from "@trpc/server";
import { z } from "zod";

export const updateKeyExpiration = rateLimitedProcedure(ratelimit.update)
import { auth, t } from "../../trpc";
export const updateKeyExpiration = t.procedure
.use(auth)
.input(
z.object({
keyId: z.string(),
Expand Down
6 changes: 3 additions & 3 deletions apps/dashboard/lib/trpc/routers/key/updateMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { insertAuditLogs } from "@/lib/audit";
import { db, eq, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";
import { TRPCError } from "@trpc/server";
import { z } from "zod";

export const updateKeyMetadata = rateLimitedProcedure(ratelimit.update)
import { auth, t } from "../../trpc";
export const updateKeyMetadata = t.procedure
.use(auth)
.input(
z.object({
keyId: z.string(),
Expand Down
6 changes: 2 additions & 4 deletions apps/dashboard/lib/trpc/routers/key/updateName.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { insertAuditLogs } from "@/lib/audit";
import { db, eq, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";
import { TRPCError } from "@trpc/server";
import { z } from "zod";
import { auth } from "../../trpc";

export const updateKeyName = rateLimitedProcedure(ratelimit.update)
import { auth, t } from "../../trpc";
export const updateKeyName = t.procedure
.use(auth)
.input(
z.object({
Expand Down
6 changes: 3 additions & 3 deletions apps/dashboard/lib/trpc/routers/key/updateOwnerId.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { insertAuditLogs } from "@/lib/audit";
import { db, eq, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";
import { TRPCError } from "@trpc/server";
import { z } from "zod";

export const updateKeyOwnerId = rateLimitedProcedure(ratelimit.update)
import { auth, t } from "../../trpc";
export const updateKeyOwnerId = t.procedure
.use(auth)
.input(
z.object({
keyId: z.string(),
Expand Down
6 changes: 3 additions & 3 deletions apps/dashboard/lib/trpc/routers/key/updateRatelimit.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { insertAuditLogs } from "@/lib/audit";
import { db, eq, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";
import { TRPCError } from "@trpc/server";
import { z } from "zod";

export const updateKeyRatelimit = rateLimitedProcedure(ratelimit.update)
import { auth, t } from "../../trpc";
export const updateKeyRatelimit = t.procedure
.use(auth)
.input(
z.object({
keyId: z.string(),
Expand Down
6 changes: 3 additions & 3 deletions apps/dashboard/lib/trpc/routers/key/updateRemaining.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { insertAuditLogs } from "@/lib/audit";
import { db, eq, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";
import { TRPCError } from "@trpc/server";
import { z } from "zod";

export const updateKeyRemaining = rateLimitedProcedure(ratelimit.update)
import { auth, t } from "../../trpc";
export const updateKeyRemaining = t.procedure
.use(auth)
.input(
z.object({
keyId: z.string(),
Expand Down
1 change: 0 additions & 1 deletion apps/dashboard/lib/trpc/routers/key/updateRootKeyName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { db, eq, schema } from "@/lib/db";
import { TRPCError } from "@trpc/server";
import { z } from "zod";
import { auth, t } from "../../trpc";

export const updateRootKeyName = t.procedure
.use(auth)
.input(
Expand Down
6 changes: 3 additions & 3 deletions apps/dashboard/lib/trpc/routers/llmGateway/create.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { insertAuditLogs } from "@/lib/audit";
import { db, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";
import { DatabaseError } from "@planetscale/database";
import { TRPCError } from "@trpc/server";
import { newId } from "@unkey/id";
import { z } from "zod";

export const createLlmGateway = rateLimitedProcedure(ratelimit.create)
import { auth, t } from "../../trpc";
export const createLlmGateway = t.procedure
.use(auth)
.input(
z.object({
subdomain: z.string().min(1).max(50),
Expand Down
6 changes: 3 additions & 3 deletions apps/dashboard/lib/trpc/routers/llmGateway/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { z } from "zod";

import { insertAuditLogs } from "@/lib/audit";
import { db, eq, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";

export const deleteLlmGateway = rateLimitedProcedure(ratelimit.delete)
import { auth, t } from "../../trpc";
export const deleteLlmGateway = t.procedure
.use(auth)
.input(z.object({ gatewayId: z.string() }))
.mutation(async ({ ctx, input }) => {
const llmGateway = await db.query.llmGateways
Expand Down
6 changes: 3 additions & 3 deletions apps/dashboard/lib/trpc/routers/ratelimit/createNamespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { z } from "zod";

import { insertAuditLogs } from "@/lib/audit";
import { db, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";
import { DatabaseError } from "@planetscale/database";
import { newId } from "@unkey/id";

export const createNamespace = rateLimitedProcedure(ratelimit.create)
import { auth, t } from "../../trpc";
export const createNamespace = t.procedure
.use(auth)
.input(
z.object({
name: z.string().min(1).max(50),
Expand Down
6 changes: 3 additions & 3 deletions apps/dashboard/lib/trpc/routers/ratelimit/createOverride.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { z } from "zod";

import { insertAuditLogs } from "@/lib/audit";
import { and, db, eq, isNull, schema, sql } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";
import { newId } from "@unkey/id";

export const createOverride = rateLimitedProcedure(ratelimit.create)
import { auth, t } from "../../trpc";
export const createOverride = t.procedure
.use(auth)
.input(
z.object({
namespaceId: z.string(),
Expand Down
6 changes: 3 additions & 3 deletions apps/dashboard/lib/trpc/routers/ratelimit/deleteNamespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { z } from "zod";

import { insertAuditLogs } from "@/lib/audit";
import { db, eq, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";

export const deleteNamespace = rateLimitedProcedure(ratelimit.delete)
import { auth, t } from "../../trpc";
export const deleteNamespace = t.procedure
.use(auth)
.input(
z.object({
namespaceId: z.string(),
Expand Down
6 changes: 3 additions & 3 deletions apps/dashboard/lib/trpc/routers/ratelimit/deleteOverride.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { z } from "zod";

import { insertAuditLogs } from "@/lib/audit";
import { db, eq, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";

export const deleteOverride = rateLimitedProcedure(ratelimit.create)
import { auth, t } from "../../trpc";
export const deleteOverride = t.procedure
.use(auth)
.input(
z.object({
id: z.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { z } from "zod";

import { insertAuditLogs } from "@/lib/audit";
import { db, eq, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";

export const updateNamespaceName = rateLimitedProcedure(ratelimit.update)
import { auth, t } from "../../trpc";
export const updateNamespaceName = t.procedure
.use(auth)
.input(
z.object({
name: z.string().min(3, "namespace names must contain at least 3 characters"),
Expand Down
6 changes: 3 additions & 3 deletions apps/dashboard/lib/trpc/routers/ratelimit/updateOverride.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { z } from "zod";

import { insertAuditLogs } from "@/lib/audit";
import { db, eq, schema } from "@/lib/db";
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure";

export const updateOverride = rateLimitedProcedure(ratelimit.update)
import { auth, t } from "../../trpc";
export const updateOverride = t.procedure
.use(auth)
.input(
z.object({
id: z.string(),
Expand Down
Loading

0 comments on commit 5ceaba6

Please sign in to comment.