diff --git a/apps/dashboard/lib/trpc/routers/api/create.ts b/apps/dashboard/lib/trpc/routers/api/create.ts index 434b618b85..e9ced2eba4 100644 --- a/apps/dashboard/lib/trpc/routers/api/create.ts +++ b/apps/dashboard/lib/trpc/routers/api/create.ts @@ -24,7 +24,7 @@ export const createApi = rateLimitedProcedure(ratelimit.create) .catch((_err) => { throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", - message: "We are unable to create an API. Please contact support using support@unkey.dev", + message: "We are unable to create an API. Please try again or contact support@unkey.dev", }); }); if (!ws) { @@ -44,52 +44,59 @@ export const createApi = rateLimitedProcedure(ratelimit.create) } catch (_err) { throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", - message: "We are unable to create an API. Please contact support using support@unkey.dev", + message: "We are unable to create an API. Please try again or contact support@unkey.dev", }); } 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 try again or contact 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 try again or contact support@unkey.dev", + }); }); - }); return { id: apiId, diff --git a/apps/dashboard/lib/trpc/routers/api/delete.ts b/apps/dashboard/lib/trpc/routers/api/delete.ts index 087e3531dc..fc445f23b4 100644 --- a/apps/dashboard/lib/trpc/routers/api/delete.ts +++ b/apps/dashboard/lib/trpc/routers/api/delete.ts @@ -24,13 +24,13 @@ export const deleteApi = rateLimitedProcedure(ratelimit.delete) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to delete this API. Please contact support using support@unkey.dev", + "We are unable to delete this API. Please try again or contact support@unkey.dev", }); }); if (!api || api.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ code: "NOT_FOUND", - message: "The API does not exist. Please contact support using support@unkey.dev", + message: "The API does not exist. Please try again or contact support@unkey.dev", }); } if (api.deleteProtection) { @@ -107,7 +107,7 @@ export const deleteApi = rateLimitedProcedure(ratelimit.delete) } catch (_err) { throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", - message: "We are unable to delete the API. Please contact support using support@unkey.dev", + message: "We are unable to delete the API. Please try again or contact support@unkey.dev", }); } }); diff --git a/apps/dashboard/lib/trpc/routers/api/setDefaultBytes.ts b/apps/dashboard/lib/trpc/routers/api/setDefaultBytes.ts index 4b5fb13b54..4e45f064b2 100644 --- a/apps/dashboard/lib/trpc/routers/api/setDefaultBytes.ts +++ b/apps/dashboard/lib/trpc/routers/api/setDefaultBytes.ts @@ -26,48 +26,56 @@ export const setDefaultApiBytes = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We were unable to find the KeyAuth. Please contact support using support@unkey.dev.", + "We were unable to find the KeyAuth. Please try again or contact support@unkey.dev.", }); }); if (!keyAuth || keyAuth.workspaceId !== input.workspaceId) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct keyAuth. Please contact support using support@unkey.dev", + "We are unable to find the correct keyAuth. Please try again or contact 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 try again or contact 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 try again or contact support@unkey.dev.", + }); }); - }); }); diff --git a/apps/dashboard/lib/trpc/routers/api/setDefaultPrefix.ts b/apps/dashboard/lib/trpc/routers/api/setDefaultPrefix.ts index 035af31609..1d3ec5681c 100644 --- a/apps/dashboard/lib/trpc/routers/api/setDefaultPrefix.ts +++ b/apps/dashboard/lib/trpc/routers/api/setDefaultPrefix.ts @@ -21,49 +21,56 @@ export const setDefaultApiPrefix = rateLimitedProcedure(ratelimit.update) .catch((_err) => { throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", - message: - "We were unable to find KeyAuth. Please contact support using support@unkey.dev.", + message: "We were unable to find KeyAuth. Please try again or contact support@unkey.dev.", }); }); if (!keyAuth || keyAuth.workspaceId !== input.workspaceId) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct keyAuth. Please contact support using support@unkey.dev", + "We are unable to find the correct keyAuth. Please try again or contact 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 try again or contact 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 try again or contact support@unkey.dev.", + }); }); - }); }); diff --git a/apps/dashboard/lib/trpc/routers/api/updateDeleteProtection.ts b/apps/dashboard/lib/trpc/routers/api/updateDeleteProtection.ts index 2306ca17b4..c6cdf3fca9 100644 --- a/apps/dashboard/lib/trpc/routers/api/updateDeleteProtection.ts +++ b/apps/dashboard/lib/trpc/routers/api/updateDeleteProtection.ts @@ -25,54 +25,62 @@ export const updateAPIDeleteProtection = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We were unable to update the API. Please contact support using support@unkey.dev", + "We were unable to update the API. Please try again or contact support@unkey.dev", }); }); if (!api || api.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct API. Please contact support using support@unkey.dev.", + "We are unable to find the correct API. Please try again or contact 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 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 try again or contact 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 try again or contact support@unkey.dev", + }); }); - }); }); diff --git a/apps/dashboard/lib/trpc/routers/api/updateIpWhitelist.ts b/apps/dashboard/lib/trpc/routers/api/updateIpWhitelist.ts index b7dc45041b..67954331c0 100644 --- a/apps/dashboard/lib/trpc/routers/api/updateIpWhitelist.ts +++ b/apps/dashboard/lib/trpc/routers/api/updateIpWhitelist.ts @@ -40,51 +40,59 @@ export const updateApiIpWhitelist = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to update the API whitelist. Please contact support using support@unkey.dev", + "We are unable to update the API whitelist. Please try again or contact support@unkey.dev", }); }); if (!api || api.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct API. Please contact support using support@unkey.dev.", + "We are unable to find the correct API. Please try again or contact support@unkey.dev.", }); } const newIpWhitelist = input.ipWhitelist === null ? null : input.ipWhitelist.join(","); - await db.transaction(async (tx) => { - await tx - .update(schema.apis) - .set({ - ipWhitelist: newIpWhitelist, - }) - .where(eq(schema.apis.id, input.apiId)) - .catch((_err) => { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: - "We are unable to update the API whitelist. Please contact support using support@unkey.dev", + await db + .transaction(async (tx) => { + await tx + .update(schema.apis) + .set({ + ipWhitelist: newIpWhitelist, + }) + .where(eq(schema.apis.id, input.apiId)) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to update the API whitelist. Please try again or contact support@unkey.dev", + }); }); - }); - await insertAuditLogs(tx, { - workspaceId: api.workspace.id, - actor: { - type: "user", - id: ctx.user.id, - }, - event: "api.update", - description: `Changed ${api.id} IP whitelist from ${api.ipWhitelist} to ${newIpWhitelist}`, - resources: [ - { - type: "api", - id: api.id, + await insertAuditLogs(tx, { + workspaceId: api.workspace.id, + actor: { + type: "user", + id: ctx.user.id, }, - ], - context: { - location: ctx.audit.location, - userAgent: ctx.audit.userAgent, - }, + event: "api.update", + description: `Changed ${api.id} IP whitelist from ${api.ipWhitelist} to ${newIpWhitelist}`, + resources: [ + { + type: "api", + id: api.id, + }, + ], + context: { + location: ctx.audit.location, + userAgent: ctx.audit.userAgent, + }, + }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to update the API whitelist. Please try again or contact support@unkey.dev", + }); }); - }); }); diff --git a/apps/dashboard/lib/trpc/routers/api/updateName.ts b/apps/dashboard/lib/trpc/routers/api/updateName.ts index a054eefd43..b11a28a47e 100644 --- a/apps/dashboard/lib/trpc/routers/api/updateName.ts +++ b/apps/dashboard/lib/trpc/routers/api/updateName.ts @@ -26,48 +26,56 @@ export const updateApiName = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We were unable to update the API name. Please contact support using support@unkey.dev.", + "We were unable to update the API name. Please try again or contact support@unkey.dev.", }); }); if (!api || api.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct API. Please contact support using support@unkey.dev.", + "We are unable to find the correct API. Please try again or contact support@unkey.dev.", }); } - await db.transaction(async (tx) => { - await tx - .update(schema.apis) - .set({ - name: input.name, - }) - .where(eq(schema.apis.id, input.apiId)) - .catch((_err) => { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: - "We were unable to update the API name. Please contact support using support@unkey.dev.", + await db + .transaction(async (tx) => { + await tx + .update(schema.apis) + .set({ + name: input.name, + }) + .where(eq(schema.apis.id, input.apiId)) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to update the API name. Please try again or contact support@unkey.dev.", + }); }); - }); - await insertAuditLogs(tx, { - workspaceId: api.workspace.id, - actor: { - type: "user", - id: ctx.user.id, - }, - event: "api.update", - description: `Changed ${api.id} name from ${api.name} to ${input.name}`, - resources: [ - { - type: "api", - id: api.id, + await insertAuditLogs(tx, { + workspaceId: api.workspace.id, + actor: { + type: "user", + id: ctx.user.id, }, - ], - context: { - location: ctx.audit.location, - userAgent: ctx.audit.userAgent, - }, + event: "api.update", + description: `Changed ${api.id} name from ${api.name} to ${input.name}`, + resources: [ + { + type: "api", + id: api.id, + }, + ], + 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 name. Please try again or contact support@unkey.dev.", + }); }); - }); }); diff --git a/apps/dashboard/lib/trpc/routers/key/create.ts b/apps/dashboard/lib/trpc/routers/key/create.ts index 0c7f9f5a2f..46f2b0e6fc 100644 --- a/apps/dashboard/lib/trpc/routers/key/create.ts +++ b/apps/dashboard/lib/trpc/routers/key/create.ts @@ -44,14 +44,14 @@ export const createKey = rateLimitedProcedure(ratelimit.create) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We were unable to create a key for this API. Please contact support using support@unkey.dev.", + "We were unable to create a key for this API. Please try again or contact support@unkey.dev.", }); }); if (!workspace) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct workspace. Please contact support using support@unkey.dev.", + "We are unable to find the correct workspace. Please try again or contact support@unkey.dev.", }); } @@ -66,14 +66,14 @@ export const createKey = rateLimitedProcedure(ratelimit.create) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We were unable to create a key for this API. Please contact support using support@unkey.dev.", + "We were unable to create a key for this API. Please try again or contact support@unkey.dev.", }); }); if (!keyAuth || keyAuth.workspaceId !== workspace.id) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct keyAuth. Please contact support using support@unkey.dev", + "We are unable to find the correct keyAuth. Please try again or contact support@unkey.dev", }); } diff --git a/apps/dashboard/lib/trpc/routers/key/createRootKey.ts b/apps/dashboard/lib/trpc/routers/key/createRootKey.ts index 6761ca577f..c78fafd35c 100644 --- a/apps/dashboard/lib/trpc/routers/key/createRootKey.ts +++ b/apps/dashboard/lib/trpc/routers/key/createRootKey.ts @@ -30,14 +30,14 @@ export const createRootKey = rateLimitedProcedure(ratelimit.create) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We were unable to create a root key for this workspace. Please contact support using support@unkey.dev.", + "We were unable to create a root key for this workspace. Please try again or contact support@unkey.dev.", }); }); if (!workspace) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct workspace. Please contact support using support@unkey.dev.", + "We are unable to find the correct workspace. Please try again or contact support@unkey.dev.", }); } @@ -52,7 +52,7 @@ export const createRootKey = rateLimitedProcedure(ratelimit.create) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We were unable to create a rootkey for this workspace. Please contact support using support@unkey.dev.", + "We were unable to create a rootkey for this workspace. Please try again or contact support@unkey.dev.", }); }); if (!unkeyApi) { @@ -193,7 +193,7 @@ export const createRootKey = rateLimitedProcedure(ratelimit.create) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to create the rootkey. Please contact support using support@unkey.dev", + "We are unable to create the rootkey. Please try again or contact support@unkey.dev", }); } diff --git a/apps/dashboard/lib/trpc/routers/key/delete.ts b/apps/dashboard/lib/trpc/routers/key/delete.ts index 9b207328f7..8624762c77 100644 --- a/apps/dashboard/lib/trpc/routers/key/delete.ts +++ b/apps/dashboard/lib/trpc/routers/key/delete.ts @@ -29,14 +29,14 @@ export const deleteKeys = rateLimitedProcedure(ratelimit.delete) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We were unable to delete this key. Please contact support using support@unkey.dev.", + "We were unable to delete this key. Please try again or contact support@unkey.dev.", }); }); if (!workspace) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct workspace. Please contact support using support@unkey.dev.", + "We are unable to find the correct workspace. Please try again or contact support@unkey.dev.", }); } @@ -77,8 +77,7 @@ export const deleteKeys = rateLimitedProcedure(ratelimit.delete) .catch((_err) => { throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", - message: - "We are unable to delete the key. Please contact support using support@unkey.dev", + message: "We are unable to delete the key. Please try again or contact support@unkey.dev", }); }); }); diff --git a/apps/dashboard/lib/trpc/routers/key/deleteRootKey.ts b/apps/dashboard/lib/trpc/routers/key/deleteRootKey.ts index 8e7d81a75d..980a46d80f 100644 --- a/apps/dashboard/lib/trpc/routers/key/deleteRootKey.ts +++ b/apps/dashboard/lib/trpc/routers/key/deleteRootKey.ts @@ -21,7 +21,7 @@ export const deleteRootKeys = rateLimitedProcedure(ratelimit.delete) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We were unable to delete this root key. Please contact support using support@unkey.dev.", + "We were unable to delete this root key. Please try again or contact support@unkey.dev.", }); }); @@ -29,7 +29,7 @@ export const deleteRootKeys = rateLimitedProcedure(ratelimit.delete) throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct workspace. Please contact support using support@unkey.dev.", + "We are unable to find the correct workspace. Please try again or contact support@unkey.dev.", }); } @@ -80,7 +80,7 @@ export const deleteRootKeys = rateLimitedProcedure(ratelimit.delete) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to delete the root key. Please contact support using support@unkey.dev", + "We are unable to delete the root key. Please try again or contact support@unkey.dev", }); }); }); diff --git a/apps/dashboard/lib/trpc/routers/key/updateEnabled.ts b/apps/dashboard/lib/trpc/routers/key/updateEnabled.ts index 92a5ced6a9..bc5e4d5322 100644 --- a/apps/dashboard/lib/trpc/routers/key/updateEnabled.ts +++ b/apps/dashboard/lib/trpc/routers/key/updateEnabled.ts @@ -24,49 +24,57 @@ export const updateKeyEnabled = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We were unable to update enabled on this key. Please contact support using support@unkey.dev", + "We were unable to update enabled on this key. Please try again or contact support@unkey.dev", }); }); if (!key || key.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the the correct key. Please contact support using support@unkey.dev.", + "We are unable to find the the correct key. Please try again or contact support@unkey.dev.", }); } - await db.transaction(async (tx) => { - await tx - .update(schema.keys) - .set({ - enabled: input.enabled, - }) - .where(eq(schema.keys.id, key.id)) - .catch((_err) => { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: - "We were unable to update enabled on this key. Please contact support using support@unkey.dev", + await db + .transaction(async (tx) => { + await tx + .update(schema.keys) + .set({ + enabled: input.enabled, + }) + .where(eq(schema.keys.id, key.id)) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to update enabled on this key. Please try again or contact support@unkey.dev", + }); }); - }); - await insertAuditLogs(tx, { - workspaceId: key.workspace.id, - actor: { - type: "user", - id: ctx.user.id, - }, - event: "key.update", - description: `${input.enabled ? "Enabled" : "Disabled"} ${key.id}`, - resources: [ - { - type: "key", - id: key.id, + await insertAuditLogs(tx, { + workspaceId: key.workspace.id, + actor: { + type: "user", + id: ctx.user.id, }, - ], - context: { - location: ctx.audit.location, - userAgent: ctx.audit.userAgent, - }, + event: "key.update", + description: `${input.enabled ? "Enabled" : "Disabled"} ${key.id}`, + resources: [ + { + type: "key", + id: key.id, + }, + ], + context: { + location: ctx.audit.location, + userAgent: ctx.audit.userAgent, + }, + }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to update enabled on this key. Please try again or contact support@unkey.dev", + }); }); - }); }); diff --git a/apps/dashboard/lib/trpc/routers/key/updateExpiration.ts b/apps/dashboard/lib/trpc/routers/key/updateExpiration.ts index c49f677fda..c40cd8d380 100644 --- a/apps/dashboard/lib/trpc/routers/key/updateExpiration.ts +++ b/apps/dashboard/lib/trpc/routers/key/updateExpiration.ts @@ -45,54 +45,62 @@ export const updateKeyExpiration = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We were unable to update expiration on this key. Please contact support using support@unkey.dev", + "We were unable to update expiration on this key. Please try again or contact support@unkey.dev", }); }); if (!key || key.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ message: - "We are unable to find the the correct key. Please contact support using support@unkey.dev.", + "We are unable to find the the correct key. Please try again or contact support@unkey.dev.", code: "NOT_FOUND", }); } - await db.transaction(async (tx) => { - await tx - .update(schema.keys) - .set({ - expires, - }) - .where(eq(schema.keys.id, key.id)) - .catch((_err) => { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: - "We were unable to update expiration on this key. Please contact support using support@unkey.dev", + await db + .transaction(async (tx) => { + await tx + .update(schema.keys) + .set({ + expires, + }) + .where(eq(schema.keys.id, key.id)) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to update expiration on this key. Please try again or contact support@unkey.dev", + }); }); - }); - await insertAuditLogs(tx, { - workspaceId: key.workspace.id, - actor: { - type: "user", - id: ctx.user.id, - }, - event: "key.update", - description: `${ - input.expiration - ? `Changed expiration of ${key.id} to ${input.expiration.toUTCString()}` - : `Disabled expiration for ${key.id}` - }`, - resources: [ - { - type: "key", - id: key.id, + await insertAuditLogs(tx, { + workspaceId: key.workspace.id, + actor: { + type: "user", + id: ctx.user.id, }, - ], - context: { - location: ctx.audit.location, - userAgent: ctx.audit.userAgent, - }, + event: "key.update", + description: `${ + input.expiration + ? `Changed expiration of ${key.id} to ${input.expiration.toUTCString()}` + : `Disabled expiration for ${key.id}` + }`, + resources: [ + { + type: "key", + id: key.id, + }, + ], + context: { + location: ctx.audit.location, + userAgent: ctx.audit.userAgent, + }, + }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to update expiration on this key. Please try again or contact support@unkey.dev", + }); }); - }); return true; }); diff --git a/apps/dashboard/lib/trpc/routers/key/updateMetadata.ts b/apps/dashboard/lib/trpc/routers/key/updateMetadata.ts index 949f02acde..28fe176d3e 100644 --- a/apps/dashboard/lib/trpc/routers/key/updateMetadata.ts +++ b/apps/dashboard/lib/trpc/routers/key/updateMetadata.ts @@ -38,50 +38,58 @@ export const updateKeyMetadata = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We were unable to update metadata on this key. Please contact support using support@unkey.dev", + "We were unable to update metadata on this key. Please try again or contact support@unkey.dev", }); }); if (!key || key.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ message: - "We are unable to find the correct key. Please contact support using support@unkey.dev.", + "We are unable to find the correct key. Please try again or contact support@unkey.dev.", code: "NOT_FOUND", }); } - await db.transaction(async (tx) => { - await tx - .update(schema.keys) - .set({ - meta: meta ? JSON.stringify(meta) : null, - }) - .where(eq(schema.keys.id, key.id)) - .catch((_err) => { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: - "We are unable to update metadata on this key. Please contact support using support@unkey.dev", + await db + .transaction(async (tx) => { + await tx + .update(schema.keys) + .set({ + meta: meta ? JSON.stringify(meta) : null, + }) + .where(eq(schema.keys.id, key.id)) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to update metadata on this key. Please try again or contact support@unkey.dev", + }); }); - }); - await insertAuditLogs(tx, { - workspaceId: key.workspace.id, - actor: { - type: "user", - id: ctx.user.id, - }, - event: "key.update", - description: `Updated metadata of ${key.id}`, - resources: [ - { - type: "key", - id: key.id, + await insertAuditLogs(tx, { + workspaceId: key.workspace.id, + actor: { + type: "user", + id: ctx.user.id, }, - ], - context: { - location: ctx.audit.location, - userAgent: ctx.audit.userAgent, - }, + event: "key.update", + description: `Updated metadata of ${key.id}`, + resources: [ + { + type: "key", + id: key.id, + }, + ], + context: { + location: ctx.audit.location, + userAgent: ctx.audit.userAgent, + }, + }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to update metadata on this key. Please try again or contact support@unkey.dev", + }); }); - }); return true; }); diff --git a/apps/dashboard/lib/trpc/routers/key/updateName.ts b/apps/dashboard/lib/trpc/routers/key/updateName.ts index 388acc4531..a072e5cdc5 100644 --- a/apps/dashboard/lib/trpc/routers/key/updateName.ts +++ b/apps/dashboard/lib/trpc/routers/key/updateName.ts @@ -26,50 +26,58 @@ export const updateKeyName = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We were unable to update the name on this key. Please contact support using support@unkey.dev", + "We were unable to update the name on this key. Please try again or contact support@unkey.dev", }); }); if (!key || key.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ message: - "We are unable to find the correct key. Please contact support using support@unkey.dev.", + "We are unable to find the correct key. Please try again or contact support@unkey.dev.", code: "NOT_FOUND", }); } - await db.transaction(async (tx) => { - await tx - .update(schema.keys) - .set({ - name: input.name ?? null, - }) - .where(eq(schema.keys.id, key.id)) - .catch((_err) => { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: - "We are unable to update name on this key. Please contact support using support@unkey.dev", + await db + .transaction(async (tx) => { + await tx + .update(schema.keys) + .set({ + name: input.name ?? null, + }) + .where(eq(schema.keys.id, key.id)) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to update name on this key. Please try again or contact support@unkey.dev", + }); }); - }); - await insertAuditLogs(tx, { - workspaceId: key.workspace.id, - actor: { - type: "user", - id: ctx.user.id, - }, - event: "key.update", - description: `Changed name of ${key.id} to ${input.name}`, - resources: [ - { - type: "key", - id: key.id, + await insertAuditLogs(tx, { + workspaceId: key.workspace.id, + actor: { + type: "user", + id: ctx.user.id, }, - ], - context: { - location: ctx.audit.location, - userAgent: ctx.audit.userAgent, - }, + event: "key.update", + description: `Changed name of ${key.id} to ${input.name}`, + resources: [ + { + type: "key", + id: key.id, + }, + ], + context: { + location: ctx.audit.location, + userAgent: ctx.audit.userAgent, + }, + }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to update name on this key. Please try again or contact support@unkey.dev", + }); }); - }); return true; }); diff --git a/apps/dashboard/lib/trpc/routers/key/updateOwnerId.ts b/apps/dashboard/lib/trpc/routers/key/updateOwnerId.ts index 9168941756..4b32a0a1d5 100644 --- a/apps/dashboard/lib/trpc/routers/key/updateOwnerId.ts +++ b/apps/dashboard/lib/trpc/routers/key/updateOwnerId.ts @@ -24,51 +24,59 @@ export const updateKeyOwnerId = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We were unable to update ownerId on this key. Please contact support using support@unkey.dev", + "We were unable to update ownerId on this key. Please try again or contact support@unkey.dev", }); }); if (!key || key.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ message: - "We are unable to find the correct key. Please contact support using support@unkey.dev.", + "We are unable to find the correct key. Please try again or contact support@unkey.dev.", code: "NOT_FOUND", }); } - await db.transaction(async (tx) => { - await tx - .update(schema.keys) - .set({ - ownerId: input.ownerId ?? null, - }) - .where(eq(schema.keys.id, key.id)) - .catch((_err) => { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: - "We were unable to update ownerId on this key. Please contact support using support@unkey.dev", + await db + .transaction(async (tx) => { + await tx + .update(schema.keys) + .set({ + ownerId: input.ownerId ?? null, + }) + .where(eq(schema.keys.id, key.id)) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to update ownerId on this key. Please try again or contact support@unkey.dev", + }); }); - }); - await insertAuditLogs(tx, { - workspaceId: key.workspace.id, - actor: { - type: "user", - id: ctx.user.id, - }, - event: "key.update", - description: `Changed ownerId of ${key.id} to ${input.ownerId}`, - resources: [ - { - type: "key", - id: key.id, + await insertAuditLogs(tx, { + workspaceId: key.workspace.id, + actor: { + type: "user", + id: ctx.user.id, }, - ], - context: { - location: ctx.audit.location, - userAgent: ctx.audit.userAgent, - }, + event: "key.update", + description: `Changed ownerId of ${key.id} to ${input.ownerId}`, + resources: [ + { + type: "key", + id: key.id, + }, + ], + context: { + location: ctx.audit.location, + userAgent: ctx.audit.userAgent, + }, + }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to update ownerId on this key. Please try again or contact support@unkey.dev", + }); }); - }); return true; }); diff --git a/apps/dashboard/lib/trpc/routers/key/updateRatelimit.ts b/apps/dashboard/lib/trpc/routers/key/updateRatelimit.ts index 24583f4edb..7d64654ea6 100644 --- a/apps/dashboard/lib/trpc/routers/key/updateRatelimit.ts +++ b/apps/dashboard/lib/trpc/routers/key/updateRatelimit.ts @@ -28,13 +28,13 @@ export const updateKeyRatelimit = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We were unable to update ratelimits on this key. Please contact support using support@unkey.dev", + "We were unable to update ratelimits on this key. Please try again or contact support@unkey.dev", }); }); if (!key || key.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ message: - "We are unable to find the correct key. Please contact support using support@unkey.dev.", + "We are unable to find the correct key. Please try again or contact support@unkey.dev.", code: "NOT_FOUND", }); } @@ -122,7 +122,7 @@ export const updateKeyRatelimit = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We were unable to update ratelimit on this key. Please contact support using support@unkey.dev", + "We were unable to update ratelimit on this key. Please try again or contact support@unkey.dev", }); }); } diff --git a/apps/dashboard/lib/trpc/routers/key/updateRemaining.ts b/apps/dashboard/lib/trpc/routers/key/updateRemaining.ts index fdfdd249fd..4e04452366 100644 --- a/apps/dashboard/lib/trpc/routers/key/updateRemaining.ts +++ b/apps/dashboard/lib/trpc/routers/key/updateRemaining.ts @@ -40,7 +40,7 @@ export const updateKeyRemaining = rateLimitedProcedure(ratelimit.update) if (!key || key.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ message: - "We are unable to find the correct key. Please contact support using support@unkey.dev.", + "We are unable to find the correct key. Please try again or contact support@unkey.dev.", code: "NOT_FOUND", }); } @@ -60,7 +60,7 @@ export const updateKeyRemaining = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We were unable to update remaining on this key. Please contact support using support@unkey.dev", + "We were unable to update remaining on this key. Please try again or contact support@unkey.dev", }); }); await insertAuditLogs(tx, { @@ -92,7 +92,7 @@ export const updateKeyRemaining = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We were unable to update remaining limits on this key. Please contact support using support@unkey.dev", + "We were unable to update remaining limits on this key. Please try again or contact support@unkey.dev", }); }); }); diff --git a/apps/dashboard/lib/trpc/routers/key/updateRootKeyName.ts b/apps/dashboard/lib/trpc/routers/key/updateRootKeyName.ts index dcb81e1c52..c78586f7c5 100644 --- a/apps/dashboard/lib/trpc/routers/key/updateRootKeyName.ts +++ b/apps/dashboard/lib/trpc/routers/key/updateRootKeyName.ts @@ -27,7 +27,7 @@ export const updateRootKeyName = t.procedure throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We were unable to update root key name. Please contact support using support@unkey.dev", + "We were unable to update root key name. Please try again or contact support@unkey.dev", }); }); @@ -35,50 +35,58 @@ export const updateRootKeyName = t.procedure throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct workspace. Please contact support using support@unkey.dev.", + "We are unable to find the correct workspace. Please try again or contact support@unkey.dev.", }); } if (!key || key.forWorkspaceId !== workspace.id) { throw new TRPCError({ message: - "We are unable to find the correct key. Please contact support using support@unkey.dev.", + "We are unable to find the correct key. Please try again or contact support@unkey.dev.", code: "NOT_FOUND", }); } - await db.transaction(async (tx) => { - await tx - .update(schema.keys) - .set({ - name: input.name ?? null, - }) - .where(eq(schema.keys.id, key.id)) - .catch((_err) => { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: - "We are unable to update root key name. Please contact support using support@unkey.dev", + await db + .transaction(async (tx) => { + await tx + .update(schema.keys) + .set({ + name: input.name ?? null, + }) + .where(eq(schema.keys.id, key.id)) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to update root key name. Please try again or contact support@unkey.dev", + }); }); - }); - await insertAuditLogs(tx, { - workspaceId: workspace.id, - actor: { - type: "user", - id: ctx.user.id, - }, - event: "key.update", - description: `Changed name of ${key.id} to ${input.name}`, - resources: [ - { - type: "key", - id: key.id, + await insertAuditLogs(tx, { + workspaceId: workspace.id, + actor: { + type: "user", + id: ctx.user.id, + }, + event: "key.update", + description: `Changed name of ${key.id} to ${input.name}`, + resources: [ + { + type: "key", + id: key.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 are unable to update root key name. Please try again or contact support@unkey.dev", + }); }); - }); }); diff --git a/apps/dashboard/lib/trpc/routers/llmGateway/create.ts b/apps/dashboard/lib/trpc/routers/llmGateway/create.ts index 01511d64e9..a50a08562c 100644 --- a/apps/dashboard/lib/trpc/routers/llmGateway/create.ts +++ b/apps/dashboard/lib/trpc/routers/llmGateway/create.ts @@ -22,14 +22,14 @@ export const createLlmGateway = rateLimitedProcedure(ratelimit.create) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We were unable to create LLM gateway. Please contact support using support@unkey.dev", + "We were unable to create LLM gateway. Please try again or contact support@unkey.dev", }); }); if (!ws) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct workspace. Please contact support using support@unkey.dev.", + "We are unable to find the correct workspace. Please try again or contact support@unkey.dev.", }); } diff --git a/apps/dashboard/lib/trpc/routers/llmGateway/delete.ts b/apps/dashboard/lib/trpc/routers/llmGateway/delete.ts index 6b9467eb0e..a031dbb4ff 100644 --- a/apps/dashboard/lib/trpc/routers/llmGateway/delete.ts +++ b/apps/dashboard/lib/trpc/routers/llmGateway/delete.ts @@ -24,48 +24,56 @@ export const deleteLlmGateway = rateLimitedProcedure(ratelimit.delete) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to delete LLM gateway. Please contact support using support@unkey.dev", + "We are unable to delete LLM gateway. Please try again or contact support@unkey.dev", }); }); if (!llmGateway || llmGateway.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ code: "NOT_FOUND", - message: "LLM gateway not found. please contact support using support@unkey.dev.", + message: "LLM gateway not found. Please try again or contact support@unkey.dev.", }); } - await db.transaction(async (tx) => { - await tx - .delete(schema.llmGateways) - .where(eq(schema.llmGateways.id, input.gatewayId)) - .catch((_err) => { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: - "We are unable to delete the LLM gateway. Please contact support using support@unkey.dev", + await db + .transaction(async (tx) => { + await tx + .delete(schema.llmGateways) + .where(eq(schema.llmGateways.id, input.gatewayId)) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to delete the LLM gateway. Please try again or contact support@unkey.dev", + }); }); - }); - await insertAuditLogs(tx, { - workspaceId: llmGateway.workspace.id, - actor: { - type: "user", - id: ctx.user.id, - }, - event: "llmGateway.delete", - description: `Deleted ${llmGateway.id}`, - resources: [ - { - type: "gateway", - id: llmGateway.id, + await insertAuditLogs(tx, { + workspaceId: llmGateway.workspace.id, + actor: { + type: "user", + id: ctx.user.id, }, - ], - context: { - location: ctx.audit.location, - userAgent: ctx.audit.userAgent, - }, + event: "llmGateway.delete", + description: `Deleted ${llmGateway.id}`, + resources: [ + { + type: "gateway", + id: llmGateway.id, + }, + ], + context: { + location: ctx.audit.location, + userAgent: ctx.audit.userAgent, + }, + }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to delete LLM gateway. Please try again or contact support@unkey.dev", + }); }); - }); return { id: llmGateway.id, diff --git a/apps/dashboard/lib/trpc/routers/ratelimit/createNamespace.ts b/apps/dashboard/lib/trpc/routers/ratelimit/createNamespace.ts index d626aba585..b8f03e5369 100644 --- a/apps/dashboard/lib/trpc/routers/ratelimit/createNamespace.ts +++ b/apps/dashboard/lib/trpc/routers/ratelimit/createNamespace.ts @@ -23,14 +23,14 @@ export const createNamespace = rateLimitedProcedure(ratelimit.create) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to create a new namespace. Please contact support using support@unkey.dev", + "We are unable to create a new namespace. Please try again or contact support@unkey.dev", }); }); if (!ws) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct workspace. Please contact support using support@unkey.dev.", + "We are unable to find the correct workspace. Please try again or contact support@unkey.dev.", }); } @@ -74,7 +74,7 @@ export const createNamespace = rateLimitedProcedure(ratelimit.create) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to create namspace. Please contact support using support@unkey.dev", + "We are unable to create namspace. Please try again or contact support@unkey.dev", }); }); diff --git a/apps/dashboard/lib/trpc/routers/ratelimit/createOverride.ts b/apps/dashboard/lib/trpc/routers/ratelimit/createOverride.ts index 021361c849..35332ad322 100644 --- a/apps/dashboard/lib/trpc/routers/ratelimit/createOverride.ts +++ b/apps/dashboard/lib/trpc/routers/ratelimit/createOverride.ts @@ -35,14 +35,14 @@ export const createOverride = rateLimitedProcedure(ratelimit.create) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to create an override for this namespace. Please contact support using support@unkey.dev", + "We are unable to create an override for this namespace. Please try again or contact support@unkey.dev", }); }); if (!namespace || namespace.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct namespace. Please contact support using support@unkey.dev.", + "We are unable to find the correct namespace. Please try again or contact support@unkey.dev.", }); } @@ -108,7 +108,7 @@ export const createOverride = rateLimitedProcedure(ratelimit.create) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to create the override. Please contact support using support@unkey.dev", + "We are unable to create the override. Please try again or contact support@unkey.dev", }); }); diff --git a/apps/dashboard/lib/trpc/routers/ratelimit/deleteNamespace.ts b/apps/dashboard/lib/trpc/routers/ratelimit/deleteNamespace.ts index 2a0d8e15d9..352dd4bd77 100644 --- a/apps/dashboard/lib/trpc/routers/ratelimit/deleteNamespace.ts +++ b/apps/dashboard/lib/trpc/routers/ratelimit/deleteNamespace.ts @@ -30,14 +30,14 @@ export const deleteNamespace = rateLimitedProcedure(ratelimit.delete) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to delete namespace. Please contact support using support@unkey.dev", + "We are unable to delete namespace. Please try again or contact support@unkey.dev", }); }); if (!namespace || namespace.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct namespace. Please contact support using support@unkey.dev.", + "We are unable to find the correct namespace. Please try again or contact support@unkey.dev.", }); } @@ -81,7 +81,7 @@ export const deleteNamespace = rateLimitedProcedure(ratelimit.delete) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to delete the namespaces. Please contact support using support@unkey.dev", + "We are unable to delete the namespaces. Please try again or contact support@unkey.dev", }); }); await insertAuditLogs( @@ -113,7 +113,7 @@ export const deleteNamespace = rateLimitedProcedure(ratelimit.delete) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to delete the namespaces. Please contact support using support@unkey.dev", + "We are unable to delete the namespaces. Please try again or contact support@unkey.dev", }); }); } diff --git a/apps/dashboard/lib/trpc/routers/ratelimit/deleteOverride.ts b/apps/dashboard/lib/trpc/routers/ratelimit/deleteOverride.ts index 795dac6a45..1cbd3bb713 100644 --- a/apps/dashboard/lib/trpc/routers/ratelimit/deleteOverride.ts +++ b/apps/dashboard/lib/trpc/routers/ratelimit/deleteOverride.ts @@ -35,14 +35,14 @@ export const deleteOverride = rateLimitedProcedure(ratelimit.create) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to delete override for this namespace. Please contact support using support@unkey.dev", + "We are unable to delete override for this namespace. Please try again or contact support@unkey.dev", }); }); if (!override || override.namespace.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ message: - "We are unable to find the correct override. Please contact support using support@unkey.dev.", + "We are unable to find the correct override. Please try again or contact support@unkey.dev.", code: "NOT_FOUND", }); } @@ -55,7 +55,7 @@ export const deleteOverride = rateLimitedProcedure(ratelimit.create) .catch((_err) => { throw new TRPCError({ message: - "We are unable to delete the override. Please contact support using support@unkey.dev", + "We are unable to delete the override. Please try again or contact support@unkey.dev", code: "INTERNAL_SERVER_ERROR", }); }); @@ -81,6 +81,12 @@ export const deleteOverride = rateLimitedProcedure(ratelimit.create) location: ctx.audit.location, userAgent: ctx.audit.userAgent, }, + }).catch((_err) => { + throw new TRPCError({ + message: + "We are unable to delete the override. Please try again or contact support@unkey.dev", + code: "INTERNAL_SERVER_ERROR", + }); }); }); }); diff --git a/apps/dashboard/lib/trpc/routers/ratelimit/updateNamespaceName.ts b/apps/dashboard/lib/trpc/routers/ratelimit/updateNamespaceName.ts index c0ebf77418..91ea8e5242 100644 --- a/apps/dashboard/lib/trpc/routers/ratelimit/updateNamespaceName.ts +++ b/apps/dashboard/lib/trpc/routers/ratelimit/updateNamespaceName.ts @@ -29,14 +29,14 @@ export const updateNamespaceName = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to update the name for this namespace. Please contact support using support@unkey.dev", + "We are unable to update the name for this namespace. Please try again or contact support@unkey.dev", }); }); if (!ws || ws.tenantId !== ctx.tenant.id) { throw new TRPCError({ message: - "We are unable to find the correct workspace. Please contact support using support@unkey.dev", + "We are unable to find the correct workspace. Please try again or contact support@unkey.dev", code: "NOT_FOUND", }); } @@ -44,7 +44,7 @@ export const updateNamespaceName = rateLimitedProcedure(ratelimit.update) if (!namespace) { throw new TRPCError({ message: - "We are unable to find the correct namespace. Please contact support using support@unkey.dev", + "We are unable to find the correct namespace. Please try again or contact support@unkey.dev", code: "NOT_FOUND", }); } @@ -59,7 +59,7 @@ export const updateNamespaceName = rateLimitedProcedure(ratelimit.update) .catch((_err) => { throw new TRPCError({ message: - "We are unable to update the namespace name. Please contact support using support@unkey.dev", + "We are unable to update the namespace name. Please try again or contact support@unkey.dev", code: "INTERNAL_SERVER_ERROR", }); }); @@ -84,7 +84,7 @@ export const updateNamespaceName = rateLimitedProcedure(ratelimit.update) }).catch((_err) => { throw new TRPCError({ message: - "We are unable to update the namespace name. Please contact support using support@unkey.dev", + "We are unable to update the namespace name. Please try again or contact support@unkey.dev", code: "INTERNAL_SERVER_ERROR", }); }); diff --git a/apps/dashboard/lib/trpc/routers/ratelimit/updateOverride.ts b/apps/dashboard/lib/trpc/routers/ratelimit/updateOverride.ts index a404348a03..6971ffdc3b 100644 --- a/apps/dashboard/lib/trpc/routers/ratelimit/updateOverride.ts +++ b/apps/dashboard/lib/trpc/routers/ratelimit/updateOverride.ts @@ -38,63 +38,71 @@ export const updateOverride = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to update this override for this namespae. Please contact support using support@unkey.dev", + "We are unable to update the override for this namespace. Please try again or contact support@unkey.dev", }); }); if (!override || override.namespace.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ message: - "We are unable to find the correct override. Please contact support using support@unkey.dev.", + "We are unable to find the correct override. Please try again or contact support@unkey.dev.", code: "NOT_FOUND", }); } - await db.transaction(async (tx) => { - await tx - .update(schema.ratelimitOverrides) - .set({ - limit: input.limit, - duration: input.duration, - updatedAt: new Date(), - async: input.async, - }) - .where(eq(schema.ratelimitOverrides.id, override.id)) - .catch((_err) => { + await db + .transaction(async (tx) => { + await tx + .update(schema.ratelimitOverrides) + .set({ + limit: input.limit, + duration: input.duration, + updatedAt: new Date(), + async: input.async, + }) + .where(eq(schema.ratelimitOverrides.id, override.id)) + .catch((_err) => { + throw new TRPCError({ + message: + "We are unable to update the override for this namespace. Please try again or contact support@unkey.dev.", + code: "INTERNAL_SERVER_ERROR", + }); + }); + await insertAuditLogs(tx, { + workspaceId: override.namespace.workspace.id, + actor: { + type: "user", + id: ctx.user.id, + }, + event: "ratelimitOverride.update", + description: `Changed ${override.id} limits from ${override.limit}/${override.duration} to ${input.limit}/${input.duration}`, + resources: [ + { + type: "ratelimitNamespace", + id: override.namespace.id, + }, + { + type: "ratelimitOverride", + id: override.id, + }, + ], + context: { + location: ctx.audit.location, + userAgent: ctx.audit.userAgent, + }, + }).catch((_err) => { throw new TRPCError({ - message: - "We are unable to update the override. Please contact support using support@unkey.dev.", code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to update the override. Please try again or contact support@unkey.dev", }); }); - await insertAuditLogs(tx, { - workspaceId: override.namespace.workspace.id, - actor: { - type: "user", - id: ctx.user.id, - }, - event: "ratelimitOverride.update", - description: `Changed ${override.id} limits from ${override.limit}/${override.duration} to ${input.limit}/${input.duration}`, - resources: [ - { - type: "ratelimitNamespace", - id: override.namespace.id, - }, - { - type: "ratelimitOverride", - id: override.id, - }, - ], - context: { - location: ctx.audit.location, - userAgent: ctx.audit.userAgent, - }, - }).catch((_err) => { + }) + .catch((_err) => { throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to update the override. Please contact support using support@unkey.dev", + "We are unable to update the override for this namespace. Please try again or contact support@unkey.dev", }); }); - }); }); diff --git a/apps/dashboard/lib/trpc/routers/rbac/addPermissionToRootKey.ts b/apps/dashboard/lib/trpc/routers/rbac/addPermissionToRootKey.ts index 3ed8fa5ed3..64749a0c94 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/addPermissionToRootKey.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/addPermissionToRootKey.ts @@ -31,14 +31,14 @@ export const addPermissionToRootKey = rateLimitedProcedure(ratelimit.create) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to add permission to the rootkey. Please contact support using support@unkey.dev", + "We are unable to add permission to the rootkey. Please try again or contact support@unkey.dev", }); }); if (!workspace) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct workspace. Please contact support using support@unkey.dev.", + "We are unable to find the correct workspace. Please try again or contact support@unkey.dev.", }); } @@ -57,7 +57,7 @@ export const addPermissionToRootKey = rateLimitedProcedure(ratelimit.create) throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct root key. Please contact support using support@unkey.dev.", + "We are unable to find the correct root key. Please try again or contact support@unkey.dev.", }); } @@ -65,44 +65,52 @@ export const addPermissionToRootKey = rateLimitedProcedure(ratelimit.create) permission.data, ]); const p = permissions[0]; - await db.transaction(async (tx) => { - await tx - .insert(schema.keysPermissions) - .values({ - keyId: rootKey.id, - permissionId: p.id, - workspaceId: p.workspaceId, - }) - .onDuplicateKeyUpdate({ set: { permissionId: p.id } }) - .catch((_err) => { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: - "We are unable to add permission to the root key. Please contact support using support@unkey.dev.", + await db + .transaction(async (tx) => { + await tx + .insert(schema.keysPermissions) + .values({ + keyId: rootKey.id, + permissionId: p.id, + workspaceId: p.workspaceId, + }) + .onDuplicateKeyUpdate({ set: { permissionId: p.id } }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to add permission to the root key. Please try again or contact support@unkey.dev.", + }); }); - }); - await insertAuditLogs(tx, [ - ...auditLogs, - { - workspaceId: workspace.id, - actor: { type: "user", id: ctx.user.id }, - event: "authorization.connect_permission_and_key", - description: `Attached ${p.id} to ${rootKey.id}`, - resources: [ - { - type: "key", - id: rootKey.id, - }, - { - type: "permission", - id: p.id, + await insertAuditLogs(tx, [ + ...auditLogs, + { + workspaceId: workspace.id, + actor: { type: "user", id: ctx.user.id }, + event: "authorization.connect_permission_and_key", + description: `Attached ${p.id} to ${rootKey.id}`, + resources: [ + { + type: "key", + id: rootKey.id, + }, + { + type: "permission", + id: p.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 are unable to add permission to the rootkey. Please try again or contact support@unkey.dev", + }); + }); }); diff --git a/apps/dashboard/lib/trpc/routers/rbac/connectPermissionToRole.ts b/apps/dashboard/lib/trpc/routers/rbac/connectPermissionToRole.ts index a291cb529f..10897edaa4 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/connectPermissionToRole.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/connectPermissionToRole.ts @@ -29,14 +29,14 @@ export const connectPermissionToRole = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to connect this permission to role. Please contact support using support@unkey.dev", + "We are unable to connect this permission to role. Please try again or contact support@unkey.dev", }); }); if (!workspace) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct workspace. Please contact support using support@unkey.dev.", + "We are unable to find the correct workspace. Please try again or contact support@unkey.dev.", }); } const role = workspace.roles.at(0); @@ -44,7 +44,7 @@ export const connectPermissionToRole = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct role. Please contact support using support@unkey.dev.", + "We are unable to find the correct role. Please try again or contact support@unkey.dev.", }); } const permission = workspace.permissions.at(0); @@ -52,7 +52,7 @@ export const connectPermissionToRole = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct permission. Please contact support using support@unkey.dev.", + "We are unable to find the correct permission. Please try again or contact support@unkey.dev.", }); } @@ -61,39 +61,47 @@ export const connectPermissionToRole = rateLimitedProcedure(ratelimit.update) permissionId: permission.id, roleId: role.id, }; - await db.transaction(async (tx) => { - await tx - .insert(schema.rolesPermissions) - .values({ ...tuple, createdAt: new Date() }) - .onDuplicateKeyUpdate({ - set: { ...tuple, updatedAt: new Date() }, - }) - .catch((_err) => { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: - "We are unable to connect the permission to the role. Please contact support using support@unkey.dev.", + await db + .transaction(async (tx) => { + await tx + .insert(schema.rolesPermissions) + .values({ ...tuple, createdAt: new Date() }) + .onDuplicateKeyUpdate({ + set: { ...tuple, updatedAt: new Date() }, + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to connect the permission to the role. Please try again or contact support@unkey.dev.", + }); }); - }); - await insertAuditLogs(tx, { - workspaceId: workspace.id, - actor: { type: "user", id: ctx.user.id }, - event: "authorization.connect_role_and_permission", - description: `Connect role ${role.id} to ${permission.id}`, - resources: [ - { - type: "role", - id: role.id, - }, - { - type: "permission", - id: permission.id, + await insertAuditLogs(tx, { + workspaceId: workspace.id, + actor: { type: "user", id: ctx.user.id }, + event: "authorization.connect_role_and_permission", + description: `Connect role ${role.id} to ${permission.id}`, + resources: [ + { + type: "role", + id: role.id, + }, + { + type: "permission", + id: permission.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 are unable to connect this permission to role. Please try again or contact support@unkey.dev", + }); }); - }); }); diff --git a/apps/dashboard/lib/trpc/routers/rbac/connectRoleToKey.ts b/apps/dashboard/lib/trpc/routers/rbac/connectRoleToKey.ts index 2809667048..96ae10d5c9 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/connectRoleToKey.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/connectRoleToKey.ts @@ -29,14 +29,14 @@ export const connectRoleToKey = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to connect the role to the key. Please contact support using support@unkey.dev", + "We are unable to connect the role to the key. Please try again or contact support@unkey.dev", }); }); if (!workspace) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct workspace. Please contact support using support@unkey.dev.", + "We are unable to find the correct workspace. Please try again or contact support@unkey.dev.", }); } const role = workspace.roles.at(0); @@ -44,7 +44,7 @@ export const connectRoleToKey = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct role. Please contact support using support@unkey.dev.", + "We are unable to find the correct role. Please try again or contact support@unkey.dev.", }); } const key = workspace.keys.at(0); @@ -52,7 +52,7 @@ export const connectRoleToKey = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct key. Please contact support using support@unkey.dev.", + "We are unable to find the correct key. Please try again or contact support@unkey.dev.", }); } @@ -61,39 +61,47 @@ export const connectRoleToKey = rateLimitedProcedure(ratelimit.update) keyId: key.id, roleId: role.id, }; - await db.transaction(async (tx) => { - await tx - .insert(schema.keysRoles) - .values({ ...tuple, createdAt: new Date() }) - .onDuplicateKeyUpdate({ - set: { ...tuple, updatedAt: new Date() }, - }) - .catch((_err) => { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: - "We are unable to connect the role and key. Please contact support using support@unkey.dev.", + await db + .transaction(async (tx) => { + await tx + .insert(schema.keysRoles) + .values({ ...tuple, createdAt: new Date() }) + .onDuplicateKeyUpdate({ + set: { ...tuple, updatedAt: new Date() }, + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to connect the role and key. Please try again or contact support@unkey.dev.", + }); }); - }); - await insertAuditLogs(tx, { - workspaceId: workspace.id, - actor: { type: "user", id: ctx.user.id }, - event: "authorization.connect_role_and_key", - description: `Connect role ${role.id} to ${key.id}`, - resources: [ - { - type: "role", - id: role.id, - }, - { - type: "key", - id: key.id, + await insertAuditLogs(tx, { + workspaceId: workspace.id, + actor: { type: "user", id: ctx.user.id }, + event: "authorization.connect_role_and_key", + description: `Connect role ${role.id} to ${key.id}`, + resources: [ + { + type: "role", + id: role.id, + }, + { + type: "key", + id: key.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 are unable to connect the role to the key. Please try again or contact support@unkey.dev", + }); }); - }); }); diff --git a/apps/dashboard/lib/trpc/routers/rbac/createPermission.ts b/apps/dashboard/lib/trpc/routers/rbac/createPermission.ts index af87eb79c3..86095b75f2 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/createPermission.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/createPermission.ts @@ -30,7 +30,7 @@ export const createPermission = rateLimitedProcedure(ratelimit.create) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to create permission. Please contact support using support@unkey.dev", + "We are unable to create permission. Please try again or contact support@unkey.dev", }); }); @@ -38,7 +38,7 @@ export const createPermission = rateLimitedProcedure(ratelimit.create) throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct workspace. Please contact support using support@unkey.dev.", + "We are unable to find the correct workspace. Please try again or contact support@unkey.dev.", }); } const permissionId = newId("permission"); @@ -75,7 +75,7 @@ export const createPermission = rateLimitedProcedure(ratelimit.create) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to create a permission. Please contact support using support@unkey.dev.", + "We are unable to create a permission. Please try again or contact support@unkey.dev.", }); }); diff --git a/apps/dashboard/lib/trpc/routers/rbac/createRole.ts b/apps/dashboard/lib/trpc/routers/rbac/createRole.ts index ba6a505438..1ece2a4562 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/createRole.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/createRole.ts @@ -30,7 +30,7 @@ export const createRole = rateLimitedProcedure(ratelimit.create) .catch((_err) => { throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", - message: "We are unable to create role. Please contact support using support@unkey.dev", + message: "We are unable to create role. Please try again or contact support@unkey.dev", }); }); @@ -38,80 +38,87 @@ export const createRole = rateLimitedProcedure(ratelimit.create) throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct workspace. Please contact support using support@unkey.dev.", + "We are unable to find the correct workspace. Please try again or contact support@unkey.dev.", }); } const roleId = newId("role"); - await db.transaction(async (tx) => { - await tx - .insert(schema.roles) - .values({ - id: roleId, - name: input.name, - description: input.description, - workspaceId: workspace.id, - }) - .catch((_err) => { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: - "We are unable to create a role. Please contact support using support@unkey.dev.", - }); - }); - await insertAuditLogs(tx, { - workspaceId: workspace.id, - event: "role.create", - actor: { - type: "user", - id: ctx.user.id, - }, - description: `Created ${roleId}`, - resources: [ - { - type: "role", + await db + .transaction(async (tx) => { + await tx + .insert(schema.roles) + .values({ id: roleId, + name: input.name, + description: input.description, + workspaceId: workspace.id, + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to create a role. Please try again or contact support@unkey.dev.", + }); + }); + await insertAuditLogs(tx, { + workspaceId: workspace.id, + event: "role.create", + actor: { + type: "user", + id: ctx.user.id, }, - ], + description: `Created ${roleId}`, + resources: [ + { + type: "role", + id: roleId, + }, + ], - context: { - userAgent: ctx.audit.userAgent, - location: ctx.audit.location, - }, - }); + context: { + userAgent: ctx.audit.userAgent, + location: ctx.audit.location, + }, + }); - if (input.permissionIds && input.permissionIds.length > 0) { - await tx.insert(schema.rolesPermissions).values( - input.permissionIds.map((permissionId) => ({ - permissionId, - roleId: roleId, - workspaceId: workspace.id, - })), - ); - await insertAuditLogs( - tx, - input.permissionIds.map((permissionId) => ({ - workspaceId: workspace.id, - event: "authorization.connect_role_and_permission", - actor: { - type: "user", - id: ctx.user.id, - }, - description: `Connected ${roleId} and ${permissionId}`, - resources: [ - { type: "role", id: roleId }, - { - type: "permission", - id: permissionId, + if (input.permissionIds && input.permissionIds.length > 0) { + await tx.insert(schema.rolesPermissions).values( + input.permissionIds.map((permissionId) => ({ + permissionId, + roleId: roleId, + workspaceId: workspace.id, + })), + ); + await insertAuditLogs( + tx, + input.permissionIds.map((permissionId) => ({ + workspaceId: workspace.id, + event: "authorization.connect_role_and_permission", + actor: { + type: "user", + id: ctx.user.id, }, - ], + description: `Connected ${roleId} and ${permissionId}`, + resources: [ + { type: "role", id: roleId }, + { + type: "permission", + id: permissionId, + }, + ], - context: { - userAgent: ctx.audit.userAgent, - location: ctx.audit.location, - }, - })), - ); - } - }); + context: { + userAgent: ctx.audit.userAgent, + location: ctx.audit.location, + }, + })), + ); + } + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: "We are unable to create role. Please try again or contact support@unkey.dev", + }); + }); return { roleId }; }); diff --git a/apps/dashboard/lib/trpc/routers/rbac/deletePermission.ts b/apps/dashboard/lib/trpc/routers/rbac/deletePermission.ts index a7fa53ebff..0558bac556 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/deletePermission.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/deletePermission.ts @@ -25,7 +25,7 @@ export const deletePermission = rateLimitedProcedure(ratelimit.delete) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to delete this permission. Please contact support using support@unkey.dev", + "We are unable to delete this permission. Please try again or contact support@unkey.dev", }); }); @@ -33,14 +33,14 @@ export const deletePermission = rateLimitedProcedure(ratelimit.delete) throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct workspace. Please contact support using support@unkey.dev.", + "We are unable to find the correct workspace. Please try again or contact support@unkey.dev.", }); } if (workspace.permissions.length === 0) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct permission. Please contact support using support@unkey.dev.", + "We are unable to find the correct permission. Please try again or contact support@unkey.dev.", }); } await db @@ -75,7 +75,7 @@ export const deletePermission = rateLimitedProcedure(ratelimit.delete) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to delete the permission. Please contact support using support@unkey.dev", + "We are unable to delete the permission. Please try again or contact support@unkey.dev", }); }); }); diff --git a/apps/dashboard/lib/trpc/routers/rbac/deleteRole.ts b/apps/dashboard/lib/trpc/routers/rbac/deleteRole.ts index 2d93b984eb..a0eb9d27c4 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/deleteRole.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/deleteRole.ts @@ -24,7 +24,7 @@ export const deleteRole = rateLimitedProcedure(ratelimit.delete) .catch((_err) => { throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", - message: "We are unable to delete role. Please contact support using support@unkey.dev", + message: "We are unable to delete role. Please try again or contact support@unkey.dev", }); }); @@ -32,14 +32,14 @@ export const deleteRole = rateLimitedProcedure(ratelimit.delete) throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct workspace. Please contact support using support@unkey.dev.", + "We are unable to find the correct workspace. Please try again or contact support@unkey.dev.", }); } if (workspace.roles.length === 0) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct role. Please contact support using support@unkey.dev.", + "We are unable to find the correct role. Please try again or contact support@unkey.dev.", }); } await db.transaction(async (tx) => { @@ -50,7 +50,7 @@ export const deleteRole = rateLimitedProcedure(ratelimit.delete) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to delete the role. Please contact support using support@unkey.dev", + "We are unable to delete the role. Please try again or contact support@unkey.dev", }); }); await insertAuditLogs(tx, { @@ -73,7 +73,7 @@ export const deleteRole = rateLimitedProcedure(ratelimit.delete) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to delete the role. Please contact support using support@unkey.dev.", + "We are unable to delete the role. Please try again or contact support@unkey.dev.", }); }); }); diff --git a/apps/dashboard/lib/trpc/routers/rbac/disconnectPermissionFromRole.ts b/apps/dashboard/lib/trpc/routers/rbac/disconnectPermissionFromRole.ts index 1b130b8e06..97fd27f57b 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/disconnectPermissionFromRole.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/disconnectPermissionFromRole.ts @@ -21,14 +21,14 @@ export const disconnectPermissionFromRole = rateLimitedProcedure(ratelimit.updat throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to remove permission from the role. Please contact support using support@unkey.dev", + "We are unable to remove permission from the role. Please try again or contact support@unkey.dev", }); }); if (!workspace) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct workspace. Please contact support using support@unkey.dev.", + "We are unable to find the correct workspace. Please try again or contact support@unkey.dev.", }); } await db @@ -68,7 +68,7 @@ export const disconnectPermissionFromRole = rateLimitedProcedure(ratelimit.updat throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to disconnect the permission from the role. Please contact support using support@unkey.dev", + "We are unable to disconnect the permission from the role. Please try again or contact support@unkey.dev", }); }); }); diff --git a/apps/dashboard/lib/trpc/routers/rbac/disconnectRoleFromKey.ts b/apps/dashboard/lib/trpc/routers/rbac/disconnectRoleFromKey.ts index 48caddfb40..bfa719b850 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/disconnectRoleFromKey.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/disconnectRoleFromKey.ts @@ -21,14 +21,14 @@ export const disconnectRoleFromKey = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to disconnect the role from the key. Please contact support using support@unkey.dev", + "We are unable to disconnect the role from the key. Please try again or contact support@unkey.dev", }); }); if (!workspace) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct workspace. Please contact support using support@unkey.dev.", + "We are unable to find the correct workspace. Please try again or contact support@unkey.dev.", }); } await db @@ -68,7 +68,7 @@ export const disconnectRoleFromKey = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to disconnect the role from the key. Please contact support using support@unkey.dev", + "We are unable to disconnect the role from the key. Please try again or contact support@unkey.dev", }); }); }); diff --git a/apps/dashboard/lib/trpc/routers/rbac/removePermissionFromRootKey.ts b/apps/dashboard/lib/trpc/routers/rbac/removePermissionFromRootKey.ts index 511717e1c3..51ac33d6ce 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/removePermissionFromRootKey.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/removePermissionFromRootKey.ts @@ -21,7 +21,7 @@ export const removePermissionFromRootKey = rateLimitedProcedure(ratelimit.update throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to remove permission from the root key. Please contact support using support@unkey.dev", + "We are unable to remove permission from the root key. Please try again or contact support@unkey.dev", }); }); @@ -29,7 +29,7 @@ export const removePermissionFromRootKey = rateLimitedProcedure(ratelimit.update throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct workspace. Please contact support using support@unkey.dev.", + "We are unable to find the correct workspace. Please try again or contact support@unkey.dev.", }); } @@ -103,7 +103,7 @@ export const removePermissionFromRootKey = rateLimitedProcedure(ratelimit.update throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to remove permission from the root key. Please contact support using support@unkey.dev", + "We are unable to remove permission from the root key. Please try again or contact support@unkey.dev", }); }); }); diff --git a/apps/dashboard/lib/trpc/routers/rbac/updatePermission.ts b/apps/dashboard/lib/trpc/routers/rbac/updatePermission.ts index a0b84d3150..833bdfc643 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/updatePermission.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/updatePermission.ts @@ -35,7 +35,7 @@ export const updatePermission = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to update permission. Please contact support using support@unkey.dev", + "We are unable to update permission. Please try again or contact support@unkey.dev", }); }); @@ -43,14 +43,14 @@ export const updatePermission = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct workspace. Please contact support using support@unkey.dev.", + "We are unable to find the correct workspace. Please try again or contact support@unkey.dev.", }); } if (workspace.permissions.length === 0) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct permission. Please contact support using support@unkey.dev.", + "We are unable to find the correct permission. Please try again or contact support@unkey.dev.", }); } @@ -87,7 +87,7 @@ export const updatePermission = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to update the permission. Please contact support using support@unkey.dev.", + "We are unable to update the permission. Please try again or contact support@unkey.dev.", }); }); }); diff --git a/apps/dashboard/lib/trpc/routers/rbac/updateRole.ts b/apps/dashboard/lib/trpc/routers/rbac/updateRole.ts index d09d9a3067..1f1af9b63b 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/updateRole.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/updateRole.ts @@ -36,7 +36,7 @@ export const updateRole = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to update the role. Please contact support using support@unkey.dev", + "We are unable to update the role. Please try again or contact support@unkey.dev", }); }); @@ -44,14 +44,14 @@ export const updateRole = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct workspace. Please contact support using support@unkey.dev.", + "We are unable to find the correct workspace. Please try again or contact support@unkey.dev.", }); } if (workspace.roles.length === 0) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct role. Please contact support using support@unkey.dev.", + "We are unable to find the correct role. Please try again or contact support@unkey.dev.", }); } await db @@ -79,7 +79,7 @@ export const updateRole = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to update the role. Please contact support using support@unkey.dev.", + "We are unable to update the role. Please try again or contact support@unkey.dev.", }); }); }); diff --git a/apps/dashboard/lib/trpc/routers/rbac/upsertPermission.ts b/apps/dashboard/lib/trpc/routers/rbac/upsertPermission.ts index b903ba1512..fdd06c02a5 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/upsertPermission.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/upsertPermission.ts @@ -19,7 +19,7 @@ export async function upsertPermission( throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to upsert the permission. Please contact support using support@unkey.dev", + "We are unable to upsert the permission. Please try again or contact support@unkey.dev", }); }); if (existingPermission) { @@ -42,7 +42,7 @@ export async function upsertPermission( throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to upsert the permission. Please contact support using support@unkey.dev.", + "We are unable to upsert the permission. Please try again or contact support@unkey.dev.", }); }); await insertAuditLogs(tx, { @@ -60,6 +60,12 @@ export async function upsertPermission( location: ctx.audit.location, userAgent: ctx.audit.userAgent, }, + }).catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to upsert the permission. Please try again or contact support@unkey.dev", + }); }); return permission; diff --git a/apps/dashboard/lib/trpc/routers/workspace/changeName.ts b/apps/dashboard/lib/trpc/routers/workspace/changeName.ts index d42972fa60..78cbc4bdb9 100644 --- a/apps/dashboard/lib/trpc/routers/workspace/changeName.ts +++ b/apps/dashboard/lib/trpc/routers/workspace/changeName.ts @@ -22,47 +22,55 @@ export const changeWorkspaceName = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to update the workspace name. Please contact support using support@unkey.dev", + "We are unable to update the workspace name. Please try again or contact support@unkey.dev", }); }); if (!ws || ws.tenantId !== ctx.tenant.id) { throw new Error("Workspace not found, Please sign back in and try again"); } - await db.transaction(async (tx) => { - await tx - .update(schema.workspaces) - .set({ - name: input.name, - }) - .where(eq(schema.workspaces.id, input.workspaceId)) - .catch((_err) => { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: - "We are unable to update the workspace name. Please contact support using support@unkey.dev", + await db + .transaction(async (tx) => { + await tx + .update(schema.workspaces) + .set({ + name: input.name, + }) + .where(eq(schema.workspaces.id, input.workspaceId)) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to update the workspace name. Please try again or contact support@unkey.dev", + }); }); - }); - await insertAuditLogs(tx, { - workspaceId: ws.id, - actor: { type: "user", id: ctx.user.id }, - event: "workspace.update", - description: `Changed name from ${ws.name} to ${input.name}`, - resources: [ - { - type: "workspace", - id: ws.id, + await insertAuditLogs(tx, { + workspaceId: ws.id, + actor: { type: "user", id: ctx.user.id }, + event: "workspace.update", + description: `Changed name from ${ws.name} to ${input.name}`, + resources: [ + { + type: "workspace", + id: ws.id, + }, + ], + context: { + location: ctx.audit.location, + userAgent: ctx.audit.userAgent, }, - ], - context: { - location: ctx.audit.location, - userAgent: ctx.audit.userAgent, - }, - }); + }); - if (ctx.tenant.id.startsWith("org_")) { - await clerkClient.organizations.updateOrganization(ctx.tenant.id, { - name: input.name, + if (ctx.tenant.id.startsWith("org_")) { + await clerkClient.organizations.updateOrganization(ctx.tenant.id, { + name: input.name, + }); + } + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to update the workspace name. Please try again or contact support@unkey.dev", }); - } - }); + }); }); diff --git a/apps/dashboard/lib/trpc/routers/workspace/changePlan.ts b/apps/dashboard/lib/trpc/routers/workspace/changePlan.ts index 56ec6ccfd2..253c7f4f18 100644 --- a/apps/dashboard/lib/trpc/routers/workspace/changePlan.ts +++ b/apps/dashboard/lib/trpc/routers/workspace/changePlan.ts @@ -34,14 +34,14 @@ export const changeWorkspacePlan = rateLimitedProcedure(ratelimit.update) .catch((_err) => { throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", - message: "We are unable to change plans. Please contact support using support@unkey.dev", + message: "We are unable to change plans. Please try again or contact support@unkey.dev", }); }); if (!workspace) { throw new TRPCError({ code: "NOT_FOUND", - message: "Workspace not found, please contact support using support@unkey.dev.", + message: "Workspace not found, Please try again or contact support@unkey.dev.", }); } if (workspace.tenantId !== ctx.tenant.id) { @@ -98,7 +98,7 @@ export const changeWorkspacePlan = rateLimitedProcedure(ratelimit.update) console.error(err); throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", - message: "Failed to change your plan. Please contact support using support@unkey.dev", + message: "Failed to change your plan. Please try again or contact support@unkey.dev", }); }); return { @@ -160,33 +160,41 @@ export const changeWorkspacePlan = rateLimitedProcedure(ratelimit.update) message: "You do not have a payment method. Please add one before upgrading.", }); } - await db.transaction(async (tx) => { - await tx - .update(schema.workspaces) - .set({ - plan: "pro", - planChanged: new Date(), - subscriptions: defaultProSubscriptions(), - planDowngradeRequest: null, - }) - .where(eq(schema.workspaces.id, input.workspaceId)); - await insertAuditLogs(tx, { - workspaceId: workspace.id, - actor: { type: "user", id: ctx.user.id }, - event: "workspace.update", - description: "Changed plan to 'pro'", - resources: [ - { - type: "workspace", - id: workspace.id, + await db + .transaction(async (tx) => { + await tx + .update(schema.workspaces) + .set({ + plan: "pro", + planChanged: new Date(), + subscriptions: defaultProSubscriptions(), + planDowngradeRequest: null, + }) + .where(eq(schema.workspaces.id, input.workspaceId)); + await insertAuditLogs(tx, { + workspaceId: workspace.id, + actor: { type: "user", id: ctx.user.id }, + event: "workspace.update", + description: "Changed plan to 'pro'", + resources: [ + { + type: "workspace", + id: workspace.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 are unable to change plans. Please try again or contact support@unkey.dev", + }); }); - }); return { title: "Your workspace has been upgraded" }; } } diff --git a/apps/dashboard/lib/trpc/routers/workspace/create.ts b/apps/dashboard/lib/trpc/routers/workspace/create.ts index 94b2fd495e..b8a3f6e1c5 100644 --- a/apps/dashboard/lib/trpc/routers/workspace/create.ts +++ b/apps/dashboard/lib/trpc/routers/workspace/create.ts @@ -99,7 +99,7 @@ export const createWorkspace = rateLimitedProcedure(ratelimit.create) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to create the workspace. Please contact support using support@unkey.dev", + "We are unable to create the workspace. Please try again or contact support@unkey.dev", }); }); diff --git a/apps/dashboard/lib/trpc/routers/workspace/optIntoBeta.ts b/apps/dashboard/lib/trpc/routers/workspace/optIntoBeta.ts index e0d93cb5e4..be49661d08 100644 --- a/apps/dashboard/lib/trpc/routers/workspace/optIntoBeta.ts +++ b/apps/dashboard/lib/trpc/routers/workspace/optIntoBeta.ts @@ -20,14 +20,14 @@ export const optWorkspaceIntoBeta = rateLimitedProcedure(ratelimit.update) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable opt you in to this beta feature. Please contact support using support@unkey.dev", + "We are unable opt you in to this beta feature. Please try again or contact support@unkey.dev", }); }); if (!workspace) { throw new TRPCError({ code: "NOT_FOUND", - message: "Workspace not found, please contact support using support@unkey.dev.", + message: "Workspace not found, Please try again or contact support@unkey.dev.", }); } @@ -74,7 +74,7 @@ export const optWorkspaceIntoBeta = rateLimitedProcedure(ratelimit.update) console.error(err); throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", - message: "Failed to update workspace, please contact support using support@unkey.dev.", + message: "Failed to update workspace, Please try again or contact support@unkey.dev.", }); }); });