Skip to content

Commit

Permalink
[autofix.ci] apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored Oct 22, 2024
1 parent c0a24ea commit 8c54751
Show file tree
Hide file tree
Showing 43 changed files with 128 additions and 238 deletions.
14 changes: 5 additions & 9 deletions apps/dashboard/lib/trpc/routers/api/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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]",
});
}

Expand Down Expand Up @@ -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]",
});
});

Expand Down
12 changes: 5 additions & 7 deletions apps/dashboard/lib/trpc/routers/api/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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]",
});
}
});
4 changes: 2 additions & 2 deletions apps/dashboard/lib/trpc/routers/api/setDefaultBytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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 setDefaultApiBytes = t.procedure
.use(auth)
Expand All @@ -16,7 +16,7 @@ export const setDefaultApiBytes = t.procedure
.optional(),
keyAuthId: z.string(),
workspaceId: z.string(),
})
}),
)
.mutation(async ({ ctx, input }) => {
const keyAuth = await db.query.keyAuth
Expand Down
11 changes: 4 additions & 7 deletions apps/dashboard/lib/trpc/routers/api/setDefaultPrefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
5 changes: 2 additions & 3 deletions apps/dashboard/lib/trpc/routers/api/updateDeleteProtection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ import { z } from "zod";

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

import { t, auth } from "../../trpc";
import { auth, t } from "../../trpc";

export const updateAPIDeleteProtection = t.procedure
.use(auth)
.input(
z.object({
apiId: z.string(),
enabled: z.boolean(),
})
}),
)
.mutation(async ({ ctx, input }) => {
const api = await db.query.apis
Expand Down
8 changes: 3 additions & 5 deletions apps/dashboard/lib/trpc/routers/api/updateIpWhitelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import { z } from "zod";

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

import { t, auth } from "../../trpc";
import { auth, t } from "../../trpc";

export const updateApiIpWhitelist = t.procedure
.use(auth)
Expand All @@ -28,7 +27,7 @@ export const updateApiIpWhitelist = t.procedure
.nullable(),
apiId: z.string(),
workspaceId: z.string(),
})
}),
)
.mutation(async ({ input, ctx }) => {
const api = await db.query.apis
Expand Down Expand Up @@ -67,8 +66,7 @@ export const updateApiIpWhitelist = t.procedure
});
}

const newIpWhitelist =
input.ipWhitelist === null ? null : input.ipWhitelist.join(",");
const newIpWhitelist = input.ipWhitelist === null ? null : input.ipWhitelist.join(",");

await db
.transaction(async (tx) => {
Expand Down
5 changes: 2 additions & 3 deletions apps/dashboard/lib/trpc/routers/api/updateName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import { z } from "zod";

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

import { t, auth } from "../../trpc";
import { auth, t } from "../../trpc";

export const updateApiName = t.procedure
.use(auth)
Expand All @@ -14,7 +13,7 @@ export const updateApiName = t.procedure
name: z.string().min(3, "API names must contain at least 3 characters"),
apiId: z.string(),
workspaceId: z.string(),
})
}),
)
.mutation(async ({ ctx, input }) => {
const api = await db.query.apis
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/lib/trpc/routers/key/create.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { insertAuditLogs } from "@/lib/audit";
import { db, schema } from "@/lib/db";
import { auth, t } from "../../trpc";
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 = t.procedure
.use(auth)
Expand Down Expand Up @@ -33,7 +33,7 @@ export const createKey = t.procedure
.optional(),
enabled: z.boolean().default(true),
environment: z.string().optional(),
})
}),
)
.mutation(async ({ input, ctx }) => {
const workspace = await db.query.workspaces
Expand Down
24 changes: 10 additions & 14 deletions apps/dashboard/lib/trpc/routers/key/createRootKey.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { db, eq, schema } from "@/lib/db";
import { env } from "@/lib/env";
import type { UnkeyAuditLog } from "@/lib/tinybird";
import { auth, t } from "../../trpc";
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";
Expand All @@ -19,7 +19,7 @@ export const createRootKey = t.procedure
permissions: z.array(unkeyPermissionValidation).min(1, {
message: "You need to add at least one permissions.",
}),
})
}),
)
.mutation(async ({ ctx, input }) => {
const workspace = await db.query.workspaces
Expand Down Expand Up @@ -149,17 +149,13 @@ export const createRootKey = t.procedure
},
});
}
await tx
.update(schema.keys)
.set({ identityId })
.where(eq(schema.keys.id, keyId));
await tx.update(schema.keys).set({ identityId }).where(eq(schema.keys.id, keyId));

const { permissions, auditLogs: createPermissionLogs } =
await upsertPermissions(
ctx,
env().UNKEY_WORKSPACE_ID,
input.permissions
);
const { permissions, auditLogs: createPermissionLogs } = await upsertPermissions(
ctx,
env().UNKEY_WORKSPACE_ID,
input.permissions,
);
auditLogs.push(...createPermissionLogs);

auditLogs.push(
Expand All @@ -182,15 +178,15 @@ export const createRootKey = t.procedure
location: ctx.audit.location,
userAgent: ctx.audit.userAgent,
},
}))
})),
);

await tx.insert(schema.keysPermissions).values(
permissions.map((p) => ({
keyId,
permissionId: p.id,
workspaceId: env().UNKEY_WORKSPACE_ID,
}))
})),
);
await insertAuditLogs(tx, auditLogs);
});
Expand Down
14 changes: 6 additions & 8 deletions apps/dashboard/lib/trpc/routers/key/delete.ts
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";
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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]",
});
});
});
11 changes: 5 additions & 6 deletions apps/dashboard/lib/trpc/routers/key/deleteRootKey.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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";
import { auth, t } from "../../trpc";
Expand All @@ -10,7 +9,7 @@ export const deleteRootKeys = t.procedure
.input(
z.object({
keyIds: z.array(z.string()),
})
}),
)
.mutation(async ({ ctx, input }) => {
const workspace = await db.query.workspaces
Expand Down Expand Up @@ -40,7 +39,7 @@ export const deleteRootKeys = t.procedure
eq(table.workspaceId, env().UNKEY_WORKSPACE_ID),
eq(table.forWorkspaceId, workspace.id),
inArray(table.id, input.keyIds),
isNull(table.deletedAt)
isNull(table.deletedAt),
),
columns: {
id: true,
Expand All @@ -54,8 +53,8 @@ export const deleteRootKeys = t.procedure
.where(
inArray(
schema.keys.id,
rootKeys.map((k) => k.id)
)
rootKeys.map((k) => k.id),
),
);
await insertAuditLogs(
tx,
Expand All @@ -74,7 +73,7 @@ export const deleteRootKeys = t.procedure
location: ctx.audit.location,
userAgent: ctx.audit.userAgent,
},
}))
})),
);
})
.catch((_err) => {
Expand Down
Loading

0 comments on commit 8c54751

Please sign in to comment.