-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0a24ea
commit 8c54751
Showing
43 changed files
with
128 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,8 @@ import { z } from "zod"; | |
|
||
import { insertAuditLogs } from "@/lib/audit"; | ||
import { db, schema } from "@/lib/db"; | ||
import { auth, t } from "../../trpc"; | ||
import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure"; | ||
import { newId } from "@unkey/id"; | ||
import { auth, t } from "../../trpc"; | ||
|
||
export const createApi = t.procedure | ||
.use(auth) | ||
|
@@ -15,7 +14,7 @@ export const createApi = t.procedure | |
.string() | ||
.min(3, "workspace names must contain at least 3 characters") | ||
.max(50, "workspace names must contain at most 50 characters"), | ||
}) | ||
}), | ||
) | ||
.mutation(async ({ input, ctx }) => { | ||
const ws = await db.query.workspaces | ||
|
@@ -26,8 +25,7 @@ export const createApi = t.procedure | |
.catch((_err) => { | ||
throw new TRPCError({ | ||
code: "INTERNAL_SERVER_ERROR", | ||
message: | ||
"We are unable to create an API. Please try again or contact [email protected]", | ||
message: "We are unable to create an API. Please try again or contact [email protected]", | ||
}); | ||
}); | ||
if (!ws) { | ||
|
@@ -47,8 +45,7 @@ export const createApi = t.procedure | |
} catch (_err) { | ||
throw new TRPCError({ | ||
code: "INTERNAL_SERVER_ERROR", | ||
message: | ||
"We are unable to create an API. Please try again or contact [email protected]", | ||
message: "We are unable to create an API. Please try again or contact [email protected]", | ||
}); | ||
} | ||
|
||
|
@@ -98,8 +95,7 @@ export const createApi = t.procedure | |
.catch((_err) => { | ||
throw new TRPCError({ | ||
code: "INTERNAL_SERVER_ERROR", | ||
message: | ||
"We are unable to create the API. Please try again or contact [email protected]", | ||
message: "We are unable to create the API. Please try again or contact [email protected]", | ||
}); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,13 @@ import { z } from "zod"; | |
|
||
import { insertAuditLogs } from "@/lib/audit"; | ||
import { db, eq, schema } from "@/lib/db"; | ||
import { t, auth } from "../../trpc"; | ||
import { auth, t } from "../../trpc"; | ||
export const deleteApi = t.procedure | ||
.use(auth) | ||
.input( | ||
z.object({ | ||
apiId: z.string(), | ||
}) | ||
}), | ||
) | ||
.mutation(async ({ ctx, input }) => { | ||
const api = await db.query.apis | ||
|
@@ -30,8 +30,7 @@ export const deleteApi = t.procedure | |
if (!api || api.workspace.tenantId !== ctx.tenant.id) { | ||
throw new TRPCError({ | ||
code: "NOT_FOUND", | ||
message: | ||
"The API does not exist. Please try again or contact [email protected]", | ||
message: "The API does not exist. Please try again or contact [email protected]", | ||
}); | ||
} | ||
if (api.deleteProtection) { | ||
|
@@ -101,15 +100,14 @@ export const deleteApi = t.procedure | |
location: ctx.audit.location, | ||
userAgent: ctx.audit.userAgent, | ||
}, | ||
})) | ||
})), | ||
); | ||
} | ||
}); | ||
} catch (_err) { | ||
throw new TRPCError({ | ||
code: "INTERNAL_SERVER_ERROR", | ||
message: | ||
"We are unable to delete the API. Please try again or contact [email protected]", | ||
message: "We are unable to delete the API. Please try again or contact [email protected]", | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,18 +3,16 @@ import { z } from "zod"; | |
|
||
import { insertAuditLogs } from "@/lib/audit"; | ||
import { db, eq, schema } from "@/lib/db"; | ||
import { t, auth } from "../../trpc"; | ||
import { auth, t } from "../../trpc"; | ||
|
||
export const setDefaultApiPrefix = t.procedure | ||
.use(auth) | ||
.input( | ||
z.object({ | ||
defaultPrefix: z | ||
.string() | ||
.max(8, "Prefix can be a maximum of 8 characters"), | ||
defaultPrefix: z.string().max(8, "Prefix can be a maximum of 8 characters"), | ||
keyAuthId: z.string(), | ||
workspaceId: z.string(), | ||
}) | ||
}), | ||
) | ||
.mutation(async ({ ctx, input }) => { | ||
const keyAuth = await db.query.keyAuth | ||
|
@@ -24,8 +22,7 @@ export const setDefaultApiPrefix = t.procedure | |
.catch((_err) => { | ||
throw new TRPCError({ | ||
code: "INTERNAL_SERVER_ERROR", | ||
message: | ||
"We were unable to find KeyAuth. Please try again or contact [email protected].", | ||
message: "We were unable to find KeyAuth. Please try again or contact [email protected].", | ||
}); | ||
}); | ||
if (!keyAuth || keyAuth.workspaceId !== input.workspaceId) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
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"; | ||
|
@@ -10,7 +9,7 @@ export const deleteKeys = t.procedure | |
.input( | ||
z.object({ | ||
keyIds: z.array(z.string()), | ||
}) | ||
}), | ||
) | ||
.mutation(async ({ ctx, input }) => { | ||
const workspace = await db.query.workspaces | ||
|
@@ -52,9 +51,9 @@ export const deleteKeys = t.procedure | |
eq(schema.keys.workspaceId, workspace.id), | ||
inArray( | ||
schema.keys.id, | ||
workspace.keys.map((k) => k.id) | ||
) | ||
) | ||
workspace.keys.map((k) => k.id), | ||
), | ||
), | ||
); | ||
insertAuditLogs( | ||
tx, | ||
|
@@ -73,14 +72,13 @@ export const deleteKeys = t.procedure | |
location: ctx.audit.location, | ||
userAgent: ctx.audit.userAgent, | ||
}, | ||
})) | ||
})), | ||
); | ||
}) | ||
.catch((_err) => { | ||
throw new TRPCError({ | ||
code: "INTERNAL_SERVER_ERROR", | ||
message: | ||
"We are unable to delete the key. Please try again or contact [email protected]", | ||
message: "We are unable to delete the key. Please try again or contact [email protected]", | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.