Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const Feedback: React.FC<FeedbackProps> = ({ variant, FeedbackOpen }) =>
const schema = z.object({
severity: z.enum(["p0", "p1", "p2", "p3"]),
issueType: z.enum(["bug", "feature", "security", "payment", "question"]),
message: z.string().min(20, 'Feedback must contain at least 20 characters'),
message: z.string().min(20, "Feedback must contain at least 20 characters"),
});

const form = useForm<z.infer<typeof schema>>({
Expand Down
80 changes: 44 additions & 36 deletions apps/dashboard/lib/trpc/routers/api/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,46 +50,54 @@ export const createApi = rateLimitedProcedure(ratelimit.create)

const apiId = newId("api");

await db.transaction(async (tx) => {
await tx
.insert(schema.apis)
.values({
id: apiId,
name: input.name,
workspaceId: ws.id,
keyAuthId,
authType: "key",
ipWhitelist: null,
createdAt: new Date(),
})
.catch((_err) => {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message:
"We are unable to create the API. Please contact support using support@unkey.dev",
await db
.transaction(async (tx) => {
await tx
.insert(schema.apis)
.values({
id: apiId,
name: input.name,
workspaceId: ws.id,
keyAuthId,
authType: "key",
ipWhitelist: null,
createdAt: new Date(),
})
.catch((_err) => {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message:
"We are unable to create the API. Please contact support using support@unkey.dev",
});
});
});

await insertAuditLogs(tx, {
workspaceId: ws.id,
actor: {
type: "user",
id: ctx.user.id,
},
event: "api.create",
description: `Created ${apiId}`,
resources: [
{
type: "api",
id: apiId,
await insertAuditLogs(tx, {
workspaceId: ws.id,
actor: {
type: "user",
id: ctx.user.id,
},
event: "api.create",
description: `Created ${apiId}`,
resources: [
{
type: "api",
id: apiId,
},
],
context: {
location: ctx.audit.location,
userAgent: ctx.audit.userAgent,
},
],
context: {
location: ctx.audit.location,
userAgent: ctx.audit.userAgent,
},
});
})
.catch((_err) => {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message:
"We are unable to create the API. Please contact support using support@unkey.dev",
});
});
});

return {
id: apiId,
Expand Down
70 changes: 39 additions & 31 deletions apps/dashboard/lib/trpc/routers/api/setDefaultBytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,46 @@ export const setDefaultApiBytes = rateLimitedProcedure(ratelimit.update)
"We are unable to find the correct keyAuth. Please contact support using support@unkey.dev",
});
}
await db.transaction(async (tx) => {
await tx
.update(schema.keyAuth)
.set({
defaultBytes: input.defaultBytes,
})
.where(eq(schema.keyAuth.id, input.keyAuthId))
.catch((_err) => {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message:
"We were unable to update the API default bytes. Please contact support using support@unkey.dev.",
await db
.transaction(async (tx) => {
await tx
.update(schema.keyAuth)
.set({
defaultBytes: input.defaultBytes,
})
.where(eq(schema.keyAuth.id, input.keyAuthId))
.catch((_err) => {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message:
"We were unable to update the API default bytes. Please contact support using support@unkey.dev.",
});
});
});
await insertAuditLogs(tx, {
workspaceId: keyAuth.workspaceId,
actor: {
type: "user",
id: ctx.user.id,
},
event: "api.update",
description: `Changed ${keyAuth.workspaceId} default byte size for keys from ${keyAuth.defaultBytes} to ${input.defaultBytes}`,
resources: [
{
type: "keyAuth",
id: keyAuth.id,
await insertAuditLogs(tx, {
workspaceId: keyAuth.workspaceId,
actor: {
type: "user",
id: ctx.user.id,
},
event: "api.update",
description: `Changed ${keyAuth.workspaceId} default byte size for keys from ${keyAuth.defaultBytes} to ${input.defaultBytes}`,
resources: [
{
type: "keyAuth",
id: keyAuth.id,
},
],
context: {
location: ctx.audit.location,
userAgent: ctx.audit.userAgent,
},
],
context: {
location: ctx.audit.location,
userAgent: ctx.audit.userAgent,
},
});
})
.catch((_err) => {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message:
"We were unable to update the default bytes. Please contact support using support@unkey.dev.",
});
});
});
});
70 changes: 39 additions & 31 deletions apps/dashboard/lib/trpc/routers/api/setDefaultPrefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,46 @@ export const setDefaultApiPrefix = rateLimitedProcedure(ratelimit.update)
"We are unable to find the correct keyAuth. Please contact support using support@unkey.dev",
});
}
await db.transaction(async (tx) => {
await tx
.update(schema.keyAuth)
.set({
defaultPrefix: input.defaultPrefix,
})
.where(eq(schema.keyAuth.id, input.keyAuthId))
.catch((_err) => {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message:
"We were unable to update the API default prefix. Please contact support using support@unkey.dev.",
await db
.transaction(async (tx) => {
await tx
.update(schema.keyAuth)
.set({
defaultPrefix: input.defaultPrefix,
})
.where(eq(schema.keyAuth.id, input.keyAuthId))
.catch((_err) => {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message:
"We were unable to update the API default prefix. Please contact support using support@unkey.dev.",
});
});
});
await insertAuditLogs(tx, {
workspaceId: keyAuth.workspaceId,
actor: {
type: "user",
id: ctx.user.id,
},
event: "api.update",
description: `Changed ${keyAuth.workspaceId} default prefix from ${keyAuth.defaultPrefix} to ${input.defaultPrefix}`,
resources: [
{
type: "keyAuth",
id: keyAuth.id,
await insertAuditLogs(tx, {
workspaceId: keyAuth.workspaceId,
actor: {
type: "user",
id: ctx.user.id,
},
event: "api.update",
description: `Changed ${keyAuth.workspaceId} default prefix from ${keyAuth.defaultPrefix} to ${input.defaultPrefix}`,
resources: [
{
type: "keyAuth",
id: keyAuth.id,
},
],
context: {
location: ctx.audit.location,
userAgent: ctx.audit.userAgent,
},
],
context: {
location: ctx.audit.location,
userAgent: ctx.audit.userAgent,
},
});
})
.catch((_err) => {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message:
"We were unable to update the default prefix. Please contact support using support@unkey.dev.",
});
});
});
});
78 changes: 43 additions & 35 deletions apps/dashboard/lib/trpc/routers/api/updateDeleteProtection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,43 +36,51 @@ export const updateAPIDeleteProtection = rateLimitedProcedure(ratelimit.update)
});
}

await db.transaction(async (tx) => {
await tx
.update(schema.apis)
.set({
deleteProtection: input.enabled,
})
.where(eq(schema.apis.id, input.apiId))
.catch((_err) => {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message:
"We were unable to update the API. Please contact support using support@unkey.dev.",
await db
.transaction(async (tx) => {
await tx
.update(schema.apis)
.set({
deleteProtection: input.enabled,
})
.where(eq(schema.apis.id, input.apiId))
.catch((_err) => {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message:
"We were unable to update the API. Please contact support using support@unkey.dev.",
});
});
});
await insertAuditLogs(tx, {
workspaceId: api.workspace.id,
actor: {
type: "user",
id: ctx.user.id,
},
event: "api.update",
description: `API ${api.name} delete protection is now ${
input.enabled ? "enabled" : "disabled"
}.}`,
resources: [
{
type: "api",
id: api.id,
meta: {
deleteProtection: input.enabled,
await insertAuditLogs(tx, {
workspaceId: api.workspace.id,
actor: {
type: "user",
id: ctx.user.id,
},
event: "api.update",
description: `API ${api.name} delete protection is now ${
input.enabled ? "enabled" : "disabled"
}.}`,
resources: [
{
type: "api",
id: api.id,
meta: {
deleteProtection: input.enabled,
},
},
],
context: {
location: ctx.audit.location,
userAgent: ctx.audit.userAgent,
},
],
context: {
location: ctx.audit.location,
userAgent: ctx.audit.userAgent,
},
});
})
.catch((_err) => {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message:
"We were unable to update the API. Please contact support using support@unkey.dev",
});
});
});
});
Loading