featL completed v1 routes for projects

This commit is contained in:
=
2025-09-16 00:08:40 +05:30
parent 2509890bab
commit cd2a39b374
40 changed files with 2147 additions and 743 deletions
@@ -12,7 +12,7 @@ import { SanitizedRoleSchema } from "@app/server/routes/sanitizedSchemas";
import { AuthMode } from "@app/services/auth/auth-type"; import { AuthMode } from "@app/services/auth/auth-type";
import { ProjectRoleServiceIdentifierType } from "@app/services/project-role/project-role-types"; import { ProjectRoleServiceIdentifierType } from "@app/services/project-role/project-role-types";
export const registerProjectRoleRouter = async (server: FastifyZodProvider) => { export const registerDepreciatedProjectRoleRouter = async (server: FastifyZodProvider) => {
server.route({ server.route({
method: "POST", method: "POST",
url: "/:projectId/roles", url: "/:projectId/roles",
+3 -3
View File
@@ -9,13 +9,13 @@ import {
import { registerGatewayV2Router } from "./gateway-router"; import { registerGatewayV2Router } from "./gateway-router";
import { registerIdentityProjectAdditionalPrivilegeRouter } from "./identity-project-additional-privilege-router"; import { registerIdentityProjectAdditionalPrivilegeRouter } from "./identity-project-additional-privilege-router";
import { registerProjectRoleRouter } from "./project-role-router"; import { registerDepreciatedProjectRoleRouter } from "./depreciated-project-role-router";
export const registerV2EERoutes = async (server: FastifyZodProvider) => { export const registerV2EERoutes = async (server: FastifyZodProvider) => {
// org role starts with organization
await server.register( await server.register(
async (projectRouter) => { async (projectRouter) => {
await projectRouter.register(registerProjectRoleRouter); // this has been depreciated and moved to /api/v1/projects
await projectRouter.register(registerDepreciatedProjectRoleRouter);
}, },
{ prefix: "/workspace" } { prefix: "/workspace" }
); );
+13 -13
View File
@@ -711,13 +711,13 @@ export const PROJECTS = {
template: "The name of the project template, if specified, to apply to this project." template: "The name of the project template, if specified, to apply to this project."
}, },
DELETE: { DELETE: {
workspaceId: "The ID of the project to delete." projectId: "The ID of the project to delete."
}, },
GET: { GET: {
workspaceId: "The ID of the project." projectId: "The ID of the project."
}, },
UPDATE: { UPDATE: {
workspaceId: "The ID of the project to update.", projectId: "The ID of the project to update.",
name: "The new name of the project.", name: "The new name of the project.",
projectDescription: "An optional description label for the project.", projectDescription: "An optional description label for the project.",
autoCapitalization: "Disable or enable auto-capitalization for the project.", autoCapitalization: "Disable or enable auto-capitalization for the project.",
@@ -729,7 +729,7 @@ export const PROJECTS = {
secretDetectionIgnoreValues: "The list of secret values to ignore for secret detection." secretDetectionIgnoreValues: "The list of secret values to ignore for secret detection."
}, },
GET_KEY: { GET_KEY: {
workspaceId: "The ID of the project to get the key from." projectId: "The ID of the project to get the key from."
}, },
GET_SNAPSHOTS: { GET_SNAPSHOTS: {
projectId: "The ID of the project to get snapshots from.", projectId: "The ID of the project to get snapshots from.",
@@ -759,10 +759,10 @@ export const PROJECTS = {
projectId: "The ID of the project to list groups for." projectId: "The ID of the project to list groups for."
}, },
LIST_INTEGRATION: { LIST_INTEGRATION: {
workspaceId: "The ID of the project to list integrations for." projectId: "The ID of the project to list integrations for."
}, },
LIST_INTEGRATION_AUTHORIZATION: { LIST_INTEGRATION_AUTHORIZATION: {
workspaceId: "The ID of the project to list integration auths for." projectId: "The ID of the project to list integration auths for."
}, },
LIST_SSH_CAS: { LIST_SSH_CAS: {
projectId: "The ID of the project to list SSH CAs for." projectId: "The ID of the project to list SSH CAs for."
@@ -815,15 +815,15 @@ export const PROJECT_USERS = {
usernames: "A list of usernames to remove from the project." usernames: "A list of usernames to remove from the project."
}, },
GET_USER_MEMBERSHIPS: { GET_USER_MEMBERSHIPS: {
workspaceId: "The ID of the project to get memberships from." projectId: "The ID of the project to get memberships from."
}, },
GET_USER_MEMBERSHIP: { GET_USER_MEMBERSHIP: {
workspaceId: "The ID of the project to get memberships from.", projectId: "The ID of the project to get memberships from.",
membershipId: "The ID of the user's project membership.", membershipId: "The ID of the user's project membership.",
username: "The username to get project membership of. Email is the default username." username: "The username to get project membership of. Email is the default username."
}, },
UPDATE_USER_MEMBERSHIP: { UPDATE_USER_MEMBERSHIP: {
workspaceId: "The ID of the project to update the membership for.", projectId: "The ID of the project to update the membership for.",
membershipId: "The ID of the membership to update.", membershipId: "The ID of the membership to update.",
roles: "A list of roles to update the membership to." roles: "A list of roles to update the membership to."
} }
@@ -877,24 +877,24 @@ export const PROJECT_IDENTITIES = {
export const ENVIRONMENTS = { export const ENVIRONMENTS = {
CREATE: { CREATE: {
workspaceId: "The ID of the project to create the environment in.", projectId: "The ID of the project to create the environment in.",
name: "The name of the environment to create.", name: "The name of the environment to create.",
slug: "The slug of the environment to create.", slug: "The slug of the environment to create.",
position: "The position of the environment. The lowest number will be displayed as the first environment." position: "The position of the environment. The lowest number will be displayed as the first environment."
}, },
UPDATE: { UPDATE: {
workspaceId: "The ID of the project to update the environment in.", projectId: "The ID of the project to update the environment in.",
id: "The ID of the environment to update.", id: "The ID of the environment to update.",
name: "The new name of the environment.", name: "The new name of the environment.",
slug: "The new slug of the environment.", slug: "The new slug of the environment.",
position: "The new position of the environment. The lowest number will be displayed as the first environment." position: "The new position of the environment. The lowest number will be displayed as the first environment."
}, },
DELETE: { DELETE: {
workspaceId: "The ID of the project to delete the environment from.", projectId: "The ID of the project to delete the environment from.",
id: "The ID of the environment to delete." id: "The ID of the environment to delete."
}, },
GET: { GET: {
workspaceId: "The ID of the project the environment belongs to.", projectId: "The ID of the project the environment belongs to.",
id: "The ID of the environment to fetch." id: "The ID of the environment to fetch."
} }
} as const; } as const;
@@ -0,0 +1,298 @@
import { z } from "zod";
import { ProjectEnvironmentsSchema } from "@app/db/schemas";
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
import { ApiDocsTags, ENVIRONMENTS } from "@app/lib/api-docs";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { slugSchema } from "@app/server/lib/schemas";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AuthMode } from "@app/services/auth/auth-type";
export const registerDepreciatedProjectEnvRouter = async (server: FastifyZodProvider) => {
server.route({
method: "GET",
url: "/:workspaceId/environments/:envId",
config: {
rateLimit: readLimit
},
schema: {
hide: false,
tags: [ApiDocsTags.Environments],
description: "Get Environment",
security: [
{
bearerAuth: []
}
],
params: z.object({
// NOTE(daniel): workspaceId isn't used, but we need to keep it for backwards compatibility. The endpoint defined below, uses no project ID, and is takes a pure environment ID.
workspaceId: z.string().trim().describe(ENVIRONMENTS.GET.projectId),
envId: z.string().trim().describe(ENVIRONMENTS.GET.id)
}),
response: {
200: z.object({
environment: ProjectEnvironmentsSchema
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const environment = await server.services.projectEnv.getEnvironmentById({
actorId: req.permission.id,
actor: req.permission.type,
actorOrgId: req.permission.orgId,
actorAuthMethod: req.permission.authMethod,
id: req.params.envId
});
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
projectId: environment.projectId,
event: {
type: EventType.GET_ENVIRONMENT,
metadata: {
id: environment.id
}
}
});
return { environment };
}
});
server.route({
method: "GET",
url: "/environments/:envId",
config: {
rateLimit: readLimit
},
schema: {
hide: false,
tags: [ApiDocsTags.Environments],
description: "Get Environment by ID",
security: [
{
bearerAuth: []
}
],
params: z.object({
envId: z.string().trim().describe(ENVIRONMENTS.GET.id)
}),
response: {
200: z.object({
environment: ProjectEnvironmentsSchema
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const environment = await server.services.projectEnv.getEnvironmentById({
actorId: req.permission.id,
actor: req.permission.type,
actorOrgId: req.permission.orgId,
actorAuthMethod: req.permission.authMethod,
id: req.params.envId
});
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
projectId: environment.projectId,
event: {
type: EventType.GET_ENVIRONMENT,
metadata: {
id: environment.id
}
}
});
return { environment };
}
});
server.route({
method: "POST",
url: "/:workspaceId/environments",
config: {
rateLimit: writeLimit
},
schema: {
hide: false,
tags: [ApiDocsTags.Environments],
description: "Create environment",
security: [
{
bearerAuth: []
}
],
params: z.object({
workspaceId: z.string().trim().describe(ENVIRONMENTS.CREATE.projectId)
}),
body: z.object({
name: z.string().trim().describe(ENVIRONMENTS.CREATE.name),
position: z.number().min(1).optional().describe(ENVIRONMENTS.CREATE.position),
slug: slugSchema({ max: 64 }).describe(ENVIRONMENTS.CREATE.slug)
}),
response: {
200: z.object({
message: z.string(),
workspace: z.string(),
environment: ProjectEnvironmentsSchema
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const environment = await server.services.projectEnv.createEnvironment({
actorId: req.permission.id,
actor: req.permission.type,
actorOrgId: req.permission.orgId,
actorAuthMethod: req.permission.authMethod,
projectId: req.params.workspaceId,
...req.body
});
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
projectId: environment.projectId,
event: {
type: EventType.CREATE_ENVIRONMENT,
metadata: {
name: environment.name,
slug: environment.slug
}
}
});
return {
message: "Successfully created new environment",
workspace: req.params.workspaceId,
environment
};
}
});
server.route({
method: "PATCH",
url: "/:workspaceId/environments/:id",
config: {
rateLimit: writeLimit
},
schema: {
hide: false,
tags: [ApiDocsTags.Environments],
description: "Update environment",
security: [
{
bearerAuth: []
}
],
params: z.object({
workspaceId: z.string().trim().describe(ENVIRONMENTS.UPDATE.projectId),
id: z.string().trim().describe(ENVIRONMENTS.UPDATE.id)
}),
body: z.object({
slug: slugSchema({ max: 64 }).optional().describe(ENVIRONMENTS.UPDATE.slug),
name: z.string().trim().optional().describe(ENVIRONMENTS.UPDATE.name),
position: z.number().optional().describe(ENVIRONMENTS.UPDATE.position)
}),
response: {
200: z.object({
message: z.string(),
workspace: z.string(),
environment: ProjectEnvironmentsSchema
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const { environment, old } = await server.services.projectEnv.updateEnvironment({
actorId: req.permission.id,
actor: req.permission.type,
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId,
id: req.params.id,
...req.body
});
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
projectId: environment.projectId,
event: {
type: EventType.UPDATE_ENVIRONMENT,
metadata: {
oldName: old.name,
oldSlug: old.slug,
oldPos: old.position,
newName: environment.name,
newSlug: environment.slug,
newPos: environment.position
}
}
});
return {
message: "Successfully updated environment",
workspace: req.params.workspaceId,
environment
};
}
});
server.route({
method: "DELETE",
url: "/:workspaceId/environments/:id",
config: {
rateLimit: writeLimit
},
schema: {
hide: false,
tags: [ApiDocsTags.Environments],
description: "Delete environment",
security: [
{
bearerAuth: []
}
],
params: z.object({
workspaceId: z.string().trim().describe(ENVIRONMENTS.DELETE.projectId),
id: z.string().trim().describe(ENVIRONMENTS.DELETE.id)
}),
response: {
200: z.object({
message: z.string(),
workspace: z.string(),
environment: ProjectEnvironmentsSchema
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const environment = await server.services.projectEnv.deleteEnvironment({
actorId: req.permission.id,
actor: req.permission.type,
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId,
id: req.params.id
});
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
projectId: environment.projectId,
event: {
type: EventType.DELETE_ENVIRONMENT,
metadata: {
slug: environment.slug,
name: environment.name
}
}
});
return {
message: "Successfully deleted environment",
workspace: req.params.workspaceId,
environment
};
}
});
};
@@ -0,0 +1,378 @@
import { z } from "zod";
import {
OrgMembershipsSchema,
ProjectMembershipsSchema,
ProjectUserMembershipRolesSchema,
UserEncryptionKeysSchema,
UsersSchema
} from "@app/db/schemas";
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
import { ApiDocsTags, PROJECT_USERS } from "@app/lib/api-docs";
import { ms } from "@app/lib/ms";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AuthMode } from "@app/services/auth/auth-type";
import { ProjectUserMembershipTemporaryMode } from "@app/services/project-membership/project-membership-types";
export const registerDepreciatedProjectMembershipRouter = async (server: FastifyZodProvider) => {
server.route({
method: "GET",
url: "/:workspaceId/memberships",
config: {
rateLimit: readLimit
},
schema: {
hide: false,
tags: [ApiDocsTags.ProjectUsers],
description: "Return project user memberships",
security: [
{
bearerAuth: []
}
],
params: z.object({
workspaceId: z.string().trim().describe(PROJECT_USERS.GET_USER_MEMBERSHIPS.projectId)
}),
response: {
200: z.object({
memberships: ProjectMembershipsSchema.extend({
user: UsersSchema.pick({
email: true,
firstName: true,
lastName: true,
id: true,
username: true
}).merge(UserEncryptionKeysSchema.pick({ publicKey: true })),
roles: z.array(
z.object({
id: z.string(),
role: z.string(),
customRoleId: z.string().optional().nullable(),
customRoleName: z.string().optional().nullable(),
customRoleSlug: z.string().optional().nullable(),
isTemporary: z.boolean(),
temporaryMode: z.string().optional().nullable(),
temporaryRange: z.string().nullable().optional(),
temporaryAccessStartTime: z.date().nullable().optional(),
temporaryAccessEndTime: z.date().nullable().optional()
})
)
})
.omit({ updatedAt: true })
.array()
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const memberships = await server.services.projectMembership.getProjectMemberships({
actorId: req.permission.id,
actor: req.permission.type,
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId
});
return { memberships };
}
});
server.route({
method: "GET",
url: "/:workspaceId/memberships/:membershipId",
config: {
rateLimit: readLimit
},
schema: {
description: "Return project user membership",
security: [
{
bearerAuth: []
}
],
params: z.object({
workspaceId: z.string().min(1).trim().describe(PROJECT_USERS.GET_USER_MEMBERSHIP.projectId),
membershipId: z.string().min(1).trim().describe(PROJECT_USERS.GET_USER_MEMBERSHIP.membershipId)
}),
response: {
200: z.object({
membership: ProjectMembershipsSchema.extend({
user: UsersSchema.pick({
email: true,
firstName: true,
lastName: true,
id: true,
username: true
}).merge(UserEncryptionKeysSchema.pick({ publicKey: true })),
roles: z.array(
z.object({
id: z.string(),
role: z.string(),
customRoleId: z.string().optional().nullable(),
customRoleName: z.string().optional().nullable(),
customRoleSlug: z.string().optional().nullable(),
isTemporary: z.boolean(),
temporaryMode: z.string().optional().nullable(),
temporaryRange: z.string().nullable().optional(),
temporaryAccessStartTime: z.date().nullable().optional(),
temporaryAccessEndTime: z.date().nullable().optional()
})
)
}).omit({ updatedAt: true })
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const membership = await server.services.projectMembership.getProjectMembershipById({
actorId: req.permission.id,
actor: req.permission.type,
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId,
id: req.params.membershipId
});
return { membership };
}
});
server.route({
method: "POST",
url: "/:workspaceId/memberships/details",
config: {
rateLimit: readLimit
},
schema: {
hide: false,
tags: [ApiDocsTags.ProjectUsers],
description: "Return project user memberships",
security: [
{
bearerAuth: []
}
],
params: z.object({
workspaceId: z.string().min(1).trim().describe(PROJECT_USERS.GET_USER_MEMBERSHIP.projectId)
}),
body: z.object({
username: z.string().min(1).trim().describe(PROJECT_USERS.GET_USER_MEMBERSHIP.username)
}),
response: {
200: z.object({
membership: ProjectMembershipsSchema.extend({
user: UsersSchema.pick({
email: true,
firstName: true,
lastName: true,
id: true
}).merge(UserEncryptionKeysSchema.pick({ publicKey: true })),
roles: z.array(
z.object({
id: z.string(),
role: z.string(),
customRoleId: z.string().optional().nullable(),
customRoleName: z.string().optional().nullable(),
customRoleSlug: z.string().optional().nullable(),
isTemporary: z.boolean(),
temporaryMode: z.string().optional().nullable(),
temporaryRange: z.string().nullable().optional(),
temporaryAccessStartTime: z.date().nullable().optional(),
temporaryAccessEndTime: z.date().nullable().optional()
})
)
}).omit({ createdAt: true, updatedAt: true })
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const membership = await server.services.projectMembership.getProjectMembershipByUsername({
actorId: req.permission.id,
actor: req.permission.type,
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId,
username: req.body.username
});
return { membership };
}
});
server.route({
method: "POST",
url: "/:workspaceId/memberships",
config: {
rateLimit: writeLimit
},
schema: {
params: z.object({
workspaceId: z.string().trim()
}),
body: z.object({
members: z
.object({
orgMembershipId: z.string().trim(),
workspaceEncryptedKey: z.string().trim(),
workspaceEncryptedNonce: z.string().trim()
})
.array()
.min(1)
}),
response: {
200: z.object({
success: z.boolean(),
data: OrgMembershipsSchema.array()
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const data = await server.services.projectMembership.addUsersToProject({
actorId: req.permission.id,
actor: req.permission.type,
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId,
members: req.body.members
});
await server.services.auditLog.createAuditLog({
projectId: req.params.workspaceId,
...req.auditLogInfo,
event: {
type: EventType.ADD_BATCH_WORKSPACE_MEMBER,
metadata: data.map(({ userId }) => ({
userId: userId || "",
email: ""
}))
}
});
return { data, success: true };
}
});
server.route({
method: "PATCH",
url: "/:workspaceId/memberships/:membershipId",
config: {
rateLimit: writeLimit
},
schema: {
hide: false,
tags: [ApiDocsTags.ProjectUsers],
description: "Update project user membership",
security: [
{
bearerAuth: []
}
],
params: z.object({
workspaceId: z.string().trim().describe(PROJECT_USERS.UPDATE_USER_MEMBERSHIP.projectId),
membershipId: z.string().trim().describe(PROJECT_USERS.UPDATE_USER_MEMBERSHIP.membershipId)
}),
body: z.object({
roles: z
.array(
z.union([
z.object({
role: z.string(),
isTemporary: z.literal(false).default(false)
}),
z.object({
role: z.string(),
isTemporary: z.literal(true),
temporaryMode: z.nativeEnum(ProjectUserMembershipTemporaryMode),
temporaryRange: z.string().refine((val) => ms(val) > 0, "Temporary range must be a positive number"),
temporaryAccessStartTime: z.string().datetime()
})
])
)
.min(1)
.refine((data) => data.some(({ isTemporary }) => !isTemporary), "At least one long lived role is required")
.describe(PROJECT_USERS.UPDATE_USER_MEMBERSHIP.roles)
}),
response: {
200: z.object({
roles: ProjectUserMembershipRolesSchema.array()
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const roles = await server.services.projectMembership.updateProjectMembership({
actorId: req.permission.id,
actor: req.permission.type,
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId,
membershipId: req.params.membershipId,
roles: req.body.roles
});
// await server.services.auditLog.createAuditLog({
// ...req.auditLogInfo,
// projectId: req.params.workspaceId,
// event: {
// type: EventType.UPDATE_USER_WORKSPACE_ROLE,
// metadata: {
// userId: membership.userId,
// newRole: req.body.role,
// oldRole: membership.role,
// email: ""
// }
// }
// });
return { roles };
}
});
server.route({
method: "DELETE",
url: "/:workspaceId/memberships/:membershipId",
config: {
rateLimit: writeLimit
},
schema: {
description: "Delete project user membership",
security: [
{
bearerAuth: []
}
],
params: z.object({
workspaceId: z.string().trim(),
membershipId: z.string().trim()
}),
response: {
200: z.object({
membership: ProjectMembershipsSchema
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const membership = await server.services.projectMembership.deleteProjectMembership({
actorId: req.permission.id,
actor: req.permission.type,
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId,
membershipId: req.params.membershipId
});
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
projectId: req.params.workspaceId,
event: {
type: EventType.REMOVE_WORKSPACE_MEMBER,
metadata: {
userId: membership.userId,
email: ""
}
}
});
return { membership };
}
});
};
@@ -0,0 +1,724 @@
import { z } from "zod";
import {
IntegrationsSchema,
ProjectRolesSchema,
ProjectSlackConfigsSchema,
ProjectSshConfigsSchema,
ProjectType,
SortDirection
} from "@app/db/schemas";
import { ProjectMicrosoftTeamsConfigsSchema } from "@app/db/schemas/project-microsoft-teams-configs";
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
import { ApiDocsTags, PROJECTS } from "@app/lib/api-docs";
import { CharacterType, characterValidator } from "@app/lib/validator/validate-string";
import { re2Validator } from "@app/lib/zod";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AuthMode } from "@app/services/auth/auth-type";
import { validateMicrosoftTeamsChannelsSchema } from "@app/services/microsoft-teams/microsoft-teams-fns";
import { ProjectFilterType, SearchProjectSortBy } from "@app/services/project/project-types";
import { validateSlackChannelsField } from "@app/services/slack/slack-auth-validators";
import { WorkflowIntegration } from "@app/services/workflow-integration/workflow-integration-types";
import { integrationAuthPubSchema, SanitizedProjectSchema } from "../sanitizedSchemas";
const projectWithEnv = SanitizedProjectSchema.merge(
z.object({
_id: z.string(),
environments: z.object({ name: z.string(), slug: z.string(), id: z.string() }).array()
})
);
export const registerDepreciatedProjectRouter = async (server: FastifyZodProvider) => {
server.route({
method: "GET",
url: "/",
config: {
rateLimit: readLimit
},
schema: {
querystring: z.object({
includeRoles: z
.enum(["true", "false"])
.default("false")
.transform((value) => value === "true"),
type: z.nativeEnum(ProjectType).optional()
}),
response: {
200: z.object({
workspaces: projectWithEnv
.extend({
roles: ProjectRolesSchema.array().optional()
})
.array()
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const workspaces = await server.services.project.getProjects({
includeRoles: req.query.includeRoles,
actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod,
actor: req.permission.type,
actorOrgId: req.permission.orgId,
type: req.query.type
});
return { workspaces };
}
});
server.route({
method: "GET",
url: "/:workspaceId",
config: {
rateLimit: readLimit
},
schema: {
hide: false,
tags: [ApiDocsTags.Projects],
description: "Get project",
security: [
{
bearerAuth: []
}
],
params: z.object({
workspaceId: z.string().trim().describe(PROJECTS.GET.workspaceId)
}),
response: {
200: z.object({
workspace: projectWithEnv.optional()
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.SERVICE_TOKEN, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const workspace = await server.services.project.getAProject({
filter: {
type: ProjectFilterType.ID,
projectId: req.params.workspaceId
},
actorAuthMethod: req.permission.authMethod,
actorId: req.permission.id,
actor: req.permission.type,
actorOrgId: req.permission.orgId
});
return { workspace };
}
});
server.route({
method: "DELETE",
url: "/:workspaceId",
config: {
rateLimit: writeLimit
},
schema: {
hide: false,
tags: [ApiDocsTags.Projects],
description: "Delete project",
security: [
{
bearerAuth: []
}
],
params: z.object({
workspaceId: z.string().trim().describe(PROJECTS.DELETE.projectId)
}),
response: {
200: z.object({
workspace: SanitizedProjectSchema.optional()
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const workspace = await server.services.project.deleteProject({
filter: {
type: ProjectFilterType.ID,
projectId: req.params.workspaceId
},
actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod,
actor: req.permission.type,
actorOrgId: req.permission.orgId
});
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
orgId: req.permission.orgId,
projectId: req.params.workspaceId,
event: {
type: EventType.DELETE_PROJECT,
metadata: workspace
}
});
return { workspace };
}
});
server.route({
method: "PATCH",
url: "/:workspaceId",
config: {
rateLimit: writeLimit
},
schema: {
hide: false,
tags: [ApiDocsTags.Projects],
description: "Update project",
security: [
{
bearerAuth: []
}
],
params: z.object({
workspaceId: z.string().trim().describe(PROJECTS.UPDATE.workspaceId)
}),
body: z.object({
name: z
.string()
.trim()
.max(64, { message: "Name must be 64 or fewer characters" })
.optional()
.describe(PROJECTS.UPDATE.name),
description: z
.string()
.trim()
.max(256, { message: "Description must be 256 or fewer characters" })
.optional()
.describe(PROJECTS.UPDATE.projectDescription),
autoCapitalization: z.boolean().optional().describe(PROJECTS.UPDATE.autoCapitalization),
hasDeleteProtection: z.boolean().optional().describe(PROJECTS.UPDATE.hasDeleteProtection),
slug: z
.string()
.trim()
.max(64, { message: "Slug must be 64 characters or fewer" })
.refine(re2Validator(/^[a-z0-9]+(?:[_-][a-z0-9]+)*$/), {
message:
"Project slug can only contain lowercase letters and numbers, with optional single hyphens (-) or underscores (_) between words. Cannot start or end with a hyphen or underscore."
})
.optional()
.describe(PROJECTS.UPDATE.slug),
secretSharing: z.boolean().optional().describe(PROJECTS.UPDATE.secretSharing),
showSnapshotsLegacy: z.boolean().optional().describe(PROJECTS.UPDATE.showSnapshotsLegacy),
defaultProduct: z.nativeEnum(ProjectType).optional().describe(PROJECTS.UPDATE.defaultProduct),
secretDetectionIgnoreValues: z
.array(z.string())
.optional()
.describe(PROJECTS.UPDATE.secretDetectionIgnoreValues)
}),
response: {
200: z.object({
workspace: SanitizedProjectSchema
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const workspace = await server.services.project.updateProject({
filter: {
type: ProjectFilterType.ID,
projectId: req.params.workspaceId
},
update: {
name: req.body.name,
description: req.body.description,
autoCapitalization: req.body.autoCapitalization,
defaultProduct: req.body.defaultProduct,
hasDeleteProtection: req.body.hasDeleteProtection,
slug: req.body.slug,
secretSharing: req.body.secretSharing,
showSnapshotsLegacy: req.body.showSnapshotsLegacy,
secretDetectionIgnoreValues: req.body.secretDetectionIgnoreValues
},
actorAuthMethod: req.permission.authMethod,
actorId: req.permission.id,
actor: req.permission.type,
actorOrgId: req.permission.orgId
});
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
orgId: req.permission.orgId,
projectId: req.params.workspaceId,
event: {
type: EventType.UPDATE_PROJECT,
metadata: req.body
}
});
return {
workspace
};
}
});
server.route({
method: "PUT",
url: "/:workspaceSlug/audit-logs-retention",
config: {
rateLimit: writeLimit
},
schema: {
params: z.object({
workspaceSlug: z.string().trim()
}),
body: z.object({
auditLogsRetentionDays: z.number().min(0)
}),
response: {
200: z.object({
message: z.string(),
workspace: SanitizedProjectSchema
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const workspace = await server.services.project.updateAuditLogsRetention({
actorId: req.permission.id,
actor: req.permission.type,
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId,
workspaceSlug: req.params.workspaceSlug,
auditLogsRetentionDays: req.body.auditLogsRetentionDays
});
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
orgId: req.permission.orgId,
projectId: workspace.id,
event: {
type: EventType.UPDATE_PROJECT,
metadata: req.body
}
});
return {
message: "Successfully updated project's audit logs retention period",
workspace
};
}
});
server.route({
method: "GET",
url: "/:workspaceId/integrations",
config: {
rateLimit: readLimit
},
schema: {
hide: false,
tags: [ApiDocsTags.Integrations],
description: "List integrations for a project.",
security: [
{
bearerAuth: []
}
],
params: z.object({
workspaceId: z.string().trim().describe(PROJECTS.LIST_INTEGRATION.workspaceId)
}),
response: {
200: z.object({
integrations: IntegrationsSchema.merge(
z.object({
environment: z.object({
id: z.string(),
name: z.string(),
slug: z.string()
})
})
).array()
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const integrations = await server.services.integration.listIntegrationByProject({
actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod,
actor: req.permission.type,
actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId
});
return { integrations };
}
});
server.route({
method: "GET",
url: "/:workspaceId/authorizations",
config: {
rateLimit: readLimit
},
schema: {
hide: false,
tags: [ApiDocsTags.Integrations],
description: "List integration auth objects for a workspace.",
security: [
{
bearerAuth: []
}
],
params: z.object({
workspaceId: z.string().trim().describe(PROJECTS.LIST_INTEGRATION_AUTHORIZATION.workspaceId)
}),
response: {
200: z.object({
authorizations: integrationAuthPubSchema.array()
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const authorizations = await server.services.integrationAuth.listIntegrationAuthByProjectId({
actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod,
actor: req.permission.type,
actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId
});
return { authorizations };
}
});
server.route({
method: "GET",
url: "/:workspaceId/ssh-config",
config: {
rateLimit: readLimit
},
schema: {
params: z.object({
workspaceId: z.string().trim()
}),
response: {
200: ProjectSshConfigsSchema.pick({
id: true,
createdAt: true,
updatedAt: true,
projectId: true,
defaultUserSshCaId: true,
defaultHostSshCaId: true
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const sshConfig = await server.services.project.getProjectSshConfig({
actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod,
actor: req.permission.type,
actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId
});
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
projectId: sshConfig.projectId,
event: {
type: EventType.GET_PROJECT_SSH_CONFIG,
metadata: {
id: sshConfig.id,
projectId: sshConfig.projectId
}
}
});
return sshConfig;
}
});
server.route({
method: "PATCH",
url: "/:workspaceId/ssh-config",
config: {
rateLimit: writeLimit
},
schema: {
params: z.object({
workspaceId: z.string().trim()
}),
body: z.object({
defaultUserSshCaId: z.string().optional(),
defaultHostSshCaId: z.string().optional()
}),
response: {
200: ProjectSshConfigsSchema.pick({
id: true,
createdAt: true,
updatedAt: true,
projectId: true,
defaultUserSshCaId: true,
defaultHostSshCaId: true
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const sshConfig = await server.services.project.updateProjectSshConfig({
actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod,
actor: req.permission.type,
actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId,
...req.body
});
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
projectId: sshConfig.projectId,
event: {
type: EventType.UPDATE_PROJECT_SSH_CONFIG,
metadata: {
id: sshConfig.id,
projectId: sshConfig.projectId,
defaultUserSshCaId: sshConfig.defaultUserSshCaId,
defaultHostSshCaId: sshConfig.defaultHostSshCaId
}
}
});
return sshConfig;
}
});
server.route({
method: "GET",
url: "/:workspaceId/workflow-integration-config/:integration",
config: {
rateLimit: readLimit
},
schema: {
params: z.object({
workspaceId: z.string().trim(),
integration: z.nativeEnum(WorkflowIntegration)
}),
response: {
200: z.discriminatedUnion("integration", [
ProjectSlackConfigsSchema.pick({
id: true,
isAccessRequestNotificationEnabled: true,
accessRequestChannels: true,
isSecretRequestNotificationEnabled: true,
secretRequestChannels: true
}).merge(
z.object({
integration: z.literal(WorkflowIntegration.SLACK),
integrationId: z.string()
})
),
ProjectMicrosoftTeamsConfigsSchema.pick({
id: true,
isAccessRequestNotificationEnabled: true,
accessRequestChannels: true,
isSecretRequestNotificationEnabled: true,
secretRequestChannels: true
}).merge(
z.object({
integration: z.literal(WorkflowIntegration.MICROSOFT_TEAMS),
integrationId: z.string()
})
)
])
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const config = await server.services.project.getProjectWorkflowIntegrationConfig({
actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod,
actor: req.permission.type,
actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId,
integration: req.params.integration
});
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
projectId: req.params.workspaceId,
event: {
type: EventType.GET_PROJECT_WORKFLOW_INTEGRATION_CONFIG,
metadata: {
id: config.id,
integration: config.integration
}
}
});
return config;
}
});
server.route({
method: "DELETE",
url: "/:projectId/workflow-integration/:integration/:integrationId",
config: {
rateLimit: writeLimit
},
schema: {
params: z.object({
projectId: z.string().trim(),
integration: z.nativeEnum(WorkflowIntegration),
integrationId: z.string()
}),
response: {
200: z.object({
integrationConfig: z.object({
id: z.string()
})
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const deletedIntegration = await server.services.project.deleteProjectWorkflowIntegration({
actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod,
actor: req.permission.type,
actorOrgId: req.permission.orgId,
projectId: req.params.projectId,
integration: req.params.integration,
integrationId: req.params.integrationId
});
return {
integrationConfig: deletedIntegration
};
}
});
server.route({
method: "PUT",
url: "/:workspaceId/workflow-integration",
config: {
rateLimit: readLimit
},
schema: {
params: z.object({
workspaceId: z.string().trim()
}),
body: z.discriminatedUnion("integration", [
z.object({
integration: z.literal(WorkflowIntegration.SLACK),
integrationId: z.string(),
accessRequestChannels: validateSlackChannelsField,
secretRequestChannels: validateSlackChannelsField,
isAccessRequestNotificationEnabled: z.boolean(),
isSecretRequestNotificationEnabled: z.boolean()
}),
z.object({
integration: z.literal(WorkflowIntegration.MICROSOFT_TEAMS),
integrationId: z.string(),
accessRequestChannels: validateMicrosoftTeamsChannelsSchema,
secretRequestChannels: validateMicrosoftTeamsChannelsSchema,
isAccessRequestNotificationEnabled: z.boolean(),
isSecretRequestNotificationEnabled: z.boolean()
})
]),
response: {
200: z.discriminatedUnion("integration", [
ProjectSlackConfigsSchema.pick({
id: true,
isAccessRequestNotificationEnabled: true,
accessRequestChannels: true,
isSecretRequestNotificationEnabled: true,
secretRequestChannels: true
}).merge(
z.object({
integration: z.literal(WorkflowIntegration.SLACK),
integrationId: z.string()
})
),
ProjectMicrosoftTeamsConfigsSchema.pick({
id: true,
isAccessRequestNotificationEnabled: true,
isSecretRequestNotificationEnabled: true
}).merge(
z.object({
integration: z.literal(WorkflowIntegration.MICROSOFT_TEAMS),
integrationId: z.string(),
accessRequestChannels: validateMicrosoftTeamsChannelsSchema,
secretRequestChannels: validateMicrosoftTeamsChannelsSchema
})
)
])
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const workflowIntegrationConfig = await server.services.project.updateProjectWorkflowIntegration({
actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod,
actor: req.permission.type,
actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId,
...req.body
});
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
projectId: req.params.workspaceId,
event: {
type: EventType.UPDATE_PROJECT_WORKFLOW_INTEGRATION_CONFIG,
metadata: {
id: workflowIntegrationConfig.id,
integrationId: workflowIntegrationConfig.integrationId,
integration: workflowIntegrationConfig.integration,
isAccessRequestNotificationEnabled: workflowIntegrationConfig.isAccessRequestNotificationEnabled,
accessRequestChannels: workflowIntegrationConfig.accessRequestChannels,
isSecretRequestNotificationEnabled: workflowIntegrationConfig.isSecretRequestNotificationEnabled,
secretRequestChannels: workflowIntegrationConfig.secretRequestChannels
}
}
});
return workflowIntegrationConfig;
}
});
server.route({
method: "POST",
url: "/search",
config: {
rateLimit: readLimit
},
schema: {
body: z.object({
limit: z.number().default(100),
offset: z.number().default(0),
type: z.nativeEnum(ProjectType).optional(),
orderBy: z.nativeEnum(SearchProjectSortBy).optional().default(SearchProjectSortBy.NAME),
orderDirection: z.nativeEnum(SortDirection).optional().default(SortDirection.ASC),
name: z
.string()
.trim()
.refine((val) => characterValidator([CharacterType.AlphaNumeric, CharacterType.Hyphen])(val), {
message: "Invalid pattern: only alphanumeric characters, - are allowed."
})
.optional()
}),
response: {
200: z.object({
projects: SanitizedProjectSchema.extend({ isMember: z.boolean() }).array(),
totalCount: z.number()
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const { docs: projects, totalCount } = await server.services.project.searchProjects({
permission: req.permission,
...req.body
});
return { projects, totalCount };
}
});
};
@@ -0,0 +1,213 @@
import { z } from "zod";
import { SecretTagsSchema } from "@app/db/schemas";
import { ApiDocsTags, SECRET_TAGS } from "@app/lib/api-docs";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { slugSchema } from "@app/server/lib/schemas";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AuthMode } from "@app/services/auth/auth-type";
export const registerDepreciatedSecretTagRouter = async (server: FastifyZodProvider) => {
server.route({
method: "GET",
url: "/:projectId/tags",
config: {
rateLimit: readLimit
},
schema: {
hide: false,
tags: [ApiDocsTags.Folders],
params: z.object({
projectId: z.string().trim().describe(SECRET_TAGS.LIST.projectId)
}),
response: {
200: z.object({
workspaceTags: SecretTagsSchema.array()
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const workspaceTags = await server.services.secretTag.getProjectTags({
actor: req.permission.type,
actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId,
projectId: req.params.projectId
});
return { workspaceTags };
}
});
server.route({
method: "GET",
url: "/:projectId/tags/:tagId",
config: {
rateLimit: readLimit
},
schema: {
hide: false,
tags: [ApiDocsTags.Folders],
params: z.object({
projectId: z.string().trim().describe(SECRET_TAGS.GET_TAG_BY_ID.projectId),
tagId: z.string().trim().describe(SECRET_TAGS.GET_TAG_BY_ID.tagId)
}),
response: {
200: z.object({
// akhilmhdh: for terraform backward compatiability
workspaceTag: SecretTagsSchema.extend({ name: z.string() })
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const workspaceTag = await server.services.secretTag.getTagById({
actor: req.permission.type,
actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId,
id: req.params.tagId
});
return { workspaceTag };
}
});
server.route({
method: "GET",
url: "/:projectId/tags/slug/:tagSlug",
config: {
rateLimit: readLimit
},
schema: {
hide: false,
tags: [ApiDocsTags.Folders],
params: z.object({
projectId: z.string().trim().describe(SECRET_TAGS.GET_TAG_BY_SLUG.projectId),
tagSlug: z.string().trim().describe(SECRET_TAGS.GET_TAG_BY_SLUG.tagSlug)
}),
response: {
200: z.object({
// akhilmhdh: for terraform backward compatiability
workspaceTag: SecretTagsSchema.extend({ name: z.string() })
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const workspaceTag = await server.services.secretTag.getTagBySlug({
actor: req.permission.type,
actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId,
slug: req.params.tagSlug,
projectId: req.params.projectId
});
return { workspaceTag };
}
});
server.route({
method: "POST",
url: "/:projectId/tags",
config: {
rateLimit: writeLimit
},
schema: {
hide: false,
tags: [ApiDocsTags.Folders],
params: z.object({
projectId: z.string().trim().describe(SECRET_TAGS.CREATE.projectId)
}),
body: z.object({
slug: slugSchema({ max: 64 }).describe(SECRET_TAGS.CREATE.slug),
color: z.string().trim().describe(SECRET_TAGS.CREATE.color)
}),
response: {
200: z.object({
workspaceTag: SecretTagsSchema
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const workspaceTag = await server.services.secretTag.createTag({
actor: req.permission.type,
actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId,
projectId: req.params.projectId,
...req.body
});
return { workspaceTag };
}
});
server.route({
method: "PATCH",
url: "/:projectId/tags/:tagId",
config: {
rateLimit: writeLimit
},
schema: {
hide: false,
tags: [ApiDocsTags.Folders],
params: z.object({
projectId: z.string().trim().describe(SECRET_TAGS.UPDATE.projectId),
tagId: z.string().trim().describe(SECRET_TAGS.UPDATE.tagId)
}),
body: z.object({
slug: slugSchema({ max: 64 }).describe(SECRET_TAGS.UPDATE.slug),
color: z.string().trim().describe(SECRET_TAGS.UPDATE.color)
}),
response: {
200: z.object({
workspaceTag: SecretTagsSchema
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const workspaceTag = await server.services.secretTag.updateTag({
actor: req.permission.type,
actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId,
...req.body,
id: req.params.tagId
});
return { workspaceTag };
}
});
server.route({
method: "DELETE",
url: "/:projectId/tags/:tagId",
config: {
rateLimit: writeLimit
},
schema: {
hide: false,
tags: [ApiDocsTags.Folders],
params: z.object({
projectId: z.string().trim().describe(SECRET_TAGS.DELETE.projectId),
tagId: z.string().trim().describe(SECRET_TAGS.DELETE.tagId)
}),
response: {
200: z.object({
workspaceTag: SecretTagsSchema
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const workspaceTag = await server.services.secretTag.deleteTag({
actor: req.permission.type,
actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId,
id: req.params.tagId
});
return { workspaceTag };
}
});
};
+20 -5
View File
@@ -13,6 +13,9 @@ import { registerCaRouter } from "./certificate-authority-router";
import { CERTIFICATE_AUTHORITY_REGISTER_ROUTER_MAP } from "./certificate-authority-routers"; import { CERTIFICATE_AUTHORITY_REGISTER_ROUTER_MAP } from "./certificate-authority-routers";
import { registerCertRouter } from "./certificate-router"; import { registerCertRouter } from "./certificate-router";
import { registerCertificateTemplateRouter } from "./certificate-template-router"; import { registerCertificateTemplateRouter } from "./certificate-template-router";
import { registerDepreciatedProjectEnvRouter } from "./depreciated-project-env-router";
import { registerDepreciatedProjectMembershipRouter } from "./depreciated-project-membership-router";
import { registerDepreciatedSecretTagRouter } from "./depreciated-secret-tag-router";
import { registerEventRouter } from "./event-router"; import { registerEventRouter } from "./event-router";
import { registerExternalGroupOrgRoleMappingRouter } from "./external-group-org-role-mapping-router"; import { registerExternalGroupOrgRoleMappingRouter } from "./external-group-org-role-mapping-router";
import { registerIdentityAccessTokenRouter } from "./identity-access-token-router"; import { registerIdentityAccessTokenRouter } from "./identity-access-token-router";
@@ -43,10 +46,10 @@ import { registerPkiSubscriberRouter } from "./pki-subscriber-router";
import { registerProjectEnvRouter } from "./project-env-router"; import { registerProjectEnvRouter } from "./project-env-router";
import { registerProjectKeyRouter } from "./project-key-router"; import { registerProjectKeyRouter } from "./project-key-router";
import { registerProjectMembershipRouter } from "./project-membership-router"; import { registerProjectMembershipRouter } from "./project-membership-router";
import { registerDepreciatedProjectRouter } from "./depreciated-project-router";
import { registerProjectRouter } from "./project-router"; import { registerProjectRouter } from "./project-router";
import { SECRET_REMINDER_REGISTER_ROUTER_MAP } from "./reminder-routers"; import { SECRET_REMINDER_REGISTER_ROUTER_MAP } from "./reminder-routers";
import { registerSecretFolderRouter } from "./secret-folder-router"; import { registerSecretFolderRouter } from "./secret-folder-router";
import { registerSecretImportRouter } from "./secret-import-router";
import { registerSecretRequestsRouter } from "./secret-requests-router"; import { registerSecretRequestsRouter } from "./secret-requests-router";
import { registerSecretSharingRouter } from "./secret-sharing-router"; import { registerSecretSharingRouter } from "./secret-sharing-router";
import { registerSecretTagRouter } from "./secret-tag-router"; import { registerSecretTagRouter } from "./secret-tag-router";
@@ -57,6 +60,7 @@ import { registerUserEngagementRouter } from "./user-engagement-router";
import { registerUserRouter } from "./user-router"; import { registerUserRouter } from "./user-router";
import { registerWebhookRouter } from "./webhook-router"; import { registerWebhookRouter } from "./webhook-router";
import { registerWorkflowIntegrationRouter } from "./workflow-integration-router"; import { registerWorkflowIntegrationRouter } from "./workflow-integration-router";
import { registerSecretImportRouter } from "./secret-import-router";
export const registerV1Routes = async (server: FastifyZodProvider) => { export const registerV1Routes = async (server: FastifyZodProvider) => {
await server.register(registerSsoRouter, { prefix: "/sso" }); await server.register(registerSsoRouter, { prefix: "/sso" });
@@ -101,15 +105,26 @@ export const registerV1Routes = async (server: FastifyZodProvider) => {
await server.register( await server.register(
async (projectRouter) => { async (projectRouter) => {
await projectRouter.register(registerProjectRouter); await projectRouter.register(registerDepreciatedProjectRouter);
await projectRouter.register(registerProjectEnvRouter); await projectRouter.register(registerDepreciatedProjectEnvRouter);
// depreciated completed in use
await projectRouter.register(registerProjectKeyRouter); await projectRouter.register(registerProjectKeyRouter);
await projectRouter.register(registerProjectMembershipRouter); await projectRouter.register(registerDepreciatedProjectMembershipRouter);
await projectRouter.register(registerSecretTagRouter); await projectRouter.register(registerDepreciatedSecretTagRouter);
}, },
{ prefix: "/workspace" } { prefix: "/workspace" }
); );
await server.register(
async (projectRouter) => {
await projectRouter.register(registerProjectRouter);
await projectRouter.register(registerProjectMembershipRouter);
await projectRouter.register(registerProjectEnvRouter);
await projectRouter.register(registerSecretTagRouter);
},
{ prefix: "/projects" }
);
await server.register( await server.register(
async (pkiRouter) => { async (pkiRouter) => {
await pkiRouter.register(registerCaRouter, { prefix: "/ca" }); await pkiRouter.register(registerCaRouter, { prefix: "/ca" });
@@ -11,58 +11,7 @@ import { AuthMode } from "@app/services/auth/auth-type";
export const registerProjectEnvRouter = async (server: FastifyZodProvider) => { export const registerProjectEnvRouter = async (server: FastifyZodProvider) => {
server.route({ server.route({
method: "GET", method: "GET",
url: "/:workspaceId/environments/:envId", url: "/:projectId/environments/:envId",
config: {
rateLimit: readLimit
},
schema: {
hide: false,
tags: [ApiDocsTags.Environments],
description: "Get Environment",
security: [
{
bearerAuth: []
}
],
params: z.object({
// NOTE(daniel): workspaceId isn't used, but we need to keep it for backwards compatibility. The endpoint defined below, uses no project ID, and is takes a pure environment ID.
workspaceId: z.string().trim().describe(ENVIRONMENTS.GET.workspaceId),
envId: z.string().trim().describe(ENVIRONMENTS.GET.id)
}),
response: {
200: z.object({
environment: ProjectEnvironmentsSchema
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const environment = await server.services.projectEnv.getEnvironmentById({
actorId: req.permission.id,
actor: req.permission.type,
actorOrgId: req.permission.orgId,
actorAuthMethod: req.permission.authMethod,
id: req.params.envId
});
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
projectId: environment.projectId,
event: {
type: EventType.GET_ENVIRONMENT,
metadata: {
id: environment.id
}
}
});
return { environment };
}
});
server.route({
method: "GET",
url: "/environments/:envId",
config: { config: {
rateLimit: readLimit rateLimit: readLimit
}, },
@@ -76,7 +25,8 @@ export const registerProjectEnvRouter = async (server: FastifyZodProvider) => {
} }
], ],
params: z.object({ params: z.object({
envId: z.string().trim().describe(ENVIRONMENTS.GET.id) envId: z.string().trim().describe(ENVIRONMENTS.GET.id),
projectId: z.string().trim().describe(ENVIRONMENTS.GET.projectId)
}), }),
response: { response: {
200: z.object({ 200: z.object({
@@ -111,7 +61,7 @@ export const registerProjectEnvRouter = async (server: FastifyZodProvider) => {
server.route({ server.route({
method: "POST", method: "POST",
url: "/:workspaceId/environments", url: "/:projectId/environments",
config: { config: {
rateLimit: writeLimit rateLimit: writeLimit
}, },
@@ -125,7 +75,7 @@ export const registerProjectEnvRouter = async (server: FastifyZodProvider) => {
} }
], ],
params: z.object({ params: z.object({
workspaceId: z.string().trim().describe(ENVIRONMENTS.CREATE.workspaceId) projectId: z.string().trim().describe(ENVIRONMENTS.CREATE.projectId)
}), }),
body: z.object({ body: z.object({
name: z.string().trim().describe(ENVIRONMENTS.CREATE.name), name: z.string().trim().describe(ENVIRONMENTS.CREATE.name),
@@ -147,7 +97,7 @@ export const registerProjectEnvRouter = async (server: FastifyZodProvider) => {
actor: req.permission.type, actor: req.permission.type,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
projectId: req.params.workspaceId, projectId: req.params.projectId,
...req.body ...req.body
}); });
@@ -164,7 +114,7 @@ export const registerProjectEnvRouter = async (server: FastifyZodProvider) => {
}); });
return { return {
message: "Successfully created new environment", message: "Successfully created new environment",
workspace: req.params.workspaceId, workspace: req.params.projectId,
environment environment
}; };
} }
@@ -172,7 +122,7 @@ export const registerProjectEnvRouter = async (server: FastifyZodProvider) => {
server.route({ server.route({
method: "PATCH", method: "PATCH",
url: "/:workspaceId/environments/:id", url: "/:projectId/environments/:id",
config: { config: {
rateLimit: writeLimit rateLimit: writeLimit
}, },
@@ -186,7 +136,7 @@ export const registerProjectEnvRouter = async (server: FastifyZodProvider) => {
} }
], ],
params: z.object({ params: z.object({
workspaceId: z.string().trim().describe(ENVIRONMENTS.UPDATE.workspaceId), projectId: z.string().trim().describe(ENVIRONMENTS.UPDATE.projectId),
id: z.string().trim().describe(ENVIRONMENTS.UPDATE.id) id: z.string().trim().describe(ENVIRONMENTS.UPDATE.id)
}), }),
body: z.object({ body: z.object({
@@ -209,7 +159,7 @@ export const registerProjectEnvRouter = async (server: FastifyZodProvider) => {
actor: req.permission.type, actor: req.permission.type,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId, projectId: req.params.projectId,
id: req.params.id, id: req.params.id,
...req.body ...req.body
}); });
@@ -232,7 +182,7 @@ export const registerProjectEnvRouter = async (server: FastifyZodProvider) => {
return { return {
message: "Successfully updated environment", message: "Successfully updated environment",
workspace: req.params.workspaceId, workspace: req.params.projectId,
environment environment
}; };
} }
@@ -240,7 +190,7 @@ export const registerProjectEnvRouter = async (server: FastifyZodProvider) => {
server.route({ server.route({
method: "DELETE", method: "DELETE",
url: "/:workspaceId/environments/:id", url: "/:projectId/environments/:id",
config: { config: {
rateLimit: writeLimit rateLimit: writeLimit
}, },
@@ -254,7 +204,7 @@ export const registerProjectEnvRouter = async (server: FastifyZodProvider) => {
} }
], ],
params: z.object({ params: z.object({
workspaceId: z.string().trim().describe(ENVIRONMENTS.DELETE.workspaceId), projectId: z.string().trim().describe(ENVIRONMENTS.DELETE.projectId),
id: z.string().trim().describe(ENVIRONMENTS.DELETE.id) id: z.string().trim().describe(ENVIRONMENTS.DELETE.id)
}), }),
response: { response: {
@@ -272,7 +222,7 @@ export const registerProjectEnvRouter = async (server: FastifyZodProvider) => {
actor: req.permission.type, actor: req.permission.type,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId, projectId: req.params.projectId,
id: req.params.id id: req.params.id
}); });
@@ -290,7 +240,7 @@ export const registerProjectEnvRouter = async (server: FastifyZodProvider) => {
return { return {
message: "Successfully deleted environment", message: "Successfully deleted environment",
workspace: req.params.workspaceId, workspace: req.params.projectId,
environment environment
}; };
} }
@@ -18,7 +18,7 @@ import { ProjectUserMembershipTemporaryMode } from "@app/services/project-member
export const registerProjectMembershipRouter = async (server: FastifyZodProvider) => { export const registerProjectMembershipRouter = async (server: FastifyZodProvider) => {
server.route({ server.route({
method: "GET", method: "GET",
url: "/:workspaceId/memberships", url: "/:projectId/memberships",
config: { config: {
rateLimit: readLimit rateLimit: readLimit
}, },
@@ -32,7 +32,7 @@ export const registerProjectMembershipRouter = async (server: FastifyZodProvider
} }
], ],
params: z.object({ params: z.object({
workspaceId: z.string().trim().describe(PROJECT_USERS.GET_USER_MEMBERSHIPS.workspaceId) projectId: z.string().trim().describe(PROJECT_USERS.GET_USER_MEMBERSHIPS.projectId)
}), }),
response: { response: {
200: z.object({ 200: z.object({
@@ -71,7 +71,7 @@ export const registerProjectMembershipRouter = async (server: FastifyZodProvider
actor: req.permission.type, actor: req.permission.type,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId projectId: req.params.projectId
}); });
return { memberships }; return { memberships };
} }
@@ -79,7 +79,7 @@ export const registerProjectMembershipRouter = async (server: FastifyZodProvider
server.route({ server.route({
method: "GET", method: "GET",
url: "/:workspaceId/memberships/:membershipId", url: "/:projectId/memberships/:membershipId",
config: { config: {
rateLimit: readLimit rateLimit: readLimit
}, },
@@ -91,7 +91,7 @@ export const registerProjectMembershipRouter = async (server: FastifyZodProvider
} }
], ],
params: z.object({ params: z.object({
workspaceId: z.string().min(1).trim().describe(PROJECT_USERS.GET_USER_MEMBERSHIP.workspaceId), projectId: z.string().min(1).trim().describe(PROJECT_USERS.GET_USER_MEMBERSHIP.projectId),
membershipId: z.string().min(1).trim().describe(PROJECT_USERS.GET_USER_MEMBERSHIP.membershipId) membershipId: z.string().min(1).trim().describe(PROJECT_USERS.GET_USER_MEMBERSHIP.membershipId)
}), }),
response: { response: {
@@ -129,16 +129,17 @@ export const registerProjectMembershipRouter = async (server: FastifyZodProvider
actor: req.permission.type, actor: req.permission.type,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId, projectId: req.params.projectId,
id: req.params.membershipId id: req.params.membershipId
}); });
return { membership }; return { membership };
} }
}); });
// TODO(depri): ask this usage again
server.route({ server.route({
method: "POST", method: "POST",
url: "/:workspaceId/memberships/details", url: "/:projectId/memberships/details",
config: { config: {
rateLimit: readLimit rateLimit: readLimit
}, },
@@ -152,7 +153,7 @@ export const registerProjectMembershipRouter = async (server: FastifyZodProvider
} }
], ],
params: z.object({ params: z.object({
workspaceId: z.string().min(1).trim().describe(PROJECT_USERS.GET_USER_MEMBERSHIP.workspaceId) projectId: z.string().min(1).trim().describe(PROJECT_USERS.GET_USER_MEMBERSHIP.projectId)
}), }),
body: z.object({ body: z.object({
username: z.string().min(1).trim().describe(PROJECT_USERS.GET_USER_MEMBERSHIP.username) username: z.string().min(1).trim().describe(PROJECT_USERS.GET_USER_MEMBERSHIP.username)
@@ -191,7 +192,7 @@ export const registerProjectMembershipRouter = async (server: FastifyZodProvider
actor: req.permission.type, actor: req.permission.type,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId, projectId: req.params.projectId,
username: req.body.username username: req.body.username
}); });
return { membership }; return { membership };
@@ -200,13 +201,13 @@ export const registerProjectMembershipRouter = async (server: FastifyZodProvider
server.route({ server.route({
method: "POST", method: "POST",
url: "/:workspaceId/memberships", url: "/:projectId/memberships",
config: { config: {
rateLimit: writeLimit rateLimit: writeLimit
}, },
schema: { schema: {
params: z.object({ params: z.object({
workspaceId: z.string().trim() projectId: z.string().trim()
}), }),
body: z.object({ body: z.object({
members: z members: z
@@ -232,12 +233,12 @@ export const registerProjectMembershipRouter = async (server: FastifyZodProvider
actor: req.permission.type, actor: req.permission.type,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId, projectId: req.params.projectId,
members: req.body.members members: req.body.members
}); });
await server.services.auditLog.createAuditLog({ await server.services.auditLog.createAuditLog({
projectId: req.params.workspaceId, projectId: req.params.projectId,
...req.auditLogInfo, ...req.auditLogInfo,
event: { event: {
type: EventType.ADD_BATCH_WORKSPACE_MEMBER, type: EventType.ADD_BATCH_WORKSPACE_MEMBER,
@@ -254,7 +255,7 @@ export const registerProjectMembershipRouter = async (server: FastifyZodProvider
server.route({ server.route({
method: "PATCH", method: "PATCH",
url: "/:workspaceId/memberships/:membershipId", url: "/:projectId/memberships/:membershipId",
config: { config: {
rateLimit: writeLimit rateLimit: writeLimit
}, },
@@ -268,7 +269,7 @@ export const registerProjectMembershipRouter = async (server: FastifyZodProvider
} }
], ],
params: z.object({ params: z.object({
workspaceId: z.string().trim().describe(PROJECT_USERS.UPDATE_USER_MEMBERSHIP.workspaceId), projectId: z.string().trim().describe(PROJECT_USERS.UPDATE_USER_MEMBERSHIP.projectId),
membershipId: z.string().trim().describe(PROJECT_USERS.UPDATE_USER_MEMBERSHIP.membershipId) membershipId: z.string().trim().describe(PROJECT_USERS.UPDATE_USER_MEMBERSHIP.membershipId)
}), }),
body: z.object({ body: z.object({
@@ -305,14 +306,14 @@ export const registerProjectMembershipRouter = async (server: FastifyZodProvider
actor: req.permission.type, actor: req.permission.type,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId, projectId: req.params.projectId,
membershipId: req.params.membershipId, membershipId: req.params.membershipId,
roles: req.body.roles roles: req.body.roles
}); });
// await server.services.auditLog.createAuditLog({ // await server.services.auditLog.createAuditLog({
// ...req.auditLogInfo, // ...req.auditLogInfo,
// projectId: req.params.workspaceId, // projectId: req.params.projectId,
// event: { // event: {
// type: EventType.UPDATE_USER_WORKSPACE_ROLE, // type: EventType.UPDATE_USER_WORKSPACE_ROLE,
// metadata: { // metadata: {
@@ -329,7 +330,7 @@ export const registerProjectMembershipRouter = async (server: FastifyZodProvider
server.route({ server.route({
method: "DELETE", method: "DELETE",
url: "/:workspaceId/memberships/:membershipId", url: "/:projectId/memberships/:membershipId",
config: { config: {
rateLimit: writeLimit rateLimit: writeLimit
}, },
@@ -341,7 +342,7 @@ export const registerProjectMembershipRouter = async (server: FastifyZodProvider
} }
], ],
params: z.object({ params: z.object({
workspaceId: z.string().trim(), projectId: z.string().trim(),
membershipId: z.string().trim() membershipId: z.string().trim()
}), }),
response: { response: {
@@ -357,13 +358,13 @@ export const registerProjectMembershipRouter = async (server: FastifyZodProvider
actor: req.permission.type, actor: req.permission.type,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId, projectId: req.params.projectId,
membershipId: req.params.membershipId membershipId: req.params.membershipId
}); });
await server.services.auditLog.createAuditLog({ await server.services.auditLog.createAuditLog({
...req.auditLogInfo, ...req.auditLogInfo,
projectId: req.params.workspaceId, projectId: req.params.projectId,
event: { event: {
type: EventType.REMOVE_WORKSPACE_MEMBER, type: EventType.REMOVE_WORKSPACE_MEMBER,
metadata: { metadata: {
@@ -378,13 +379,13 @@ export const registerProjectMembershipRouter = async (server: FastifyZodProvider
server.route({ server.route({
method: "DELETE", method: "DELETE",
url: "/:workspaceId/leave", url: "/:projectId/leave",
config: { config: {
rateLimit: writeLimit rateLimit: writeLimit
}, },
schema: { schema: {
params: z.object({ params: z.object({
workspaceId: z.string().trim() projectId: z.string().trim()
}), }),
response: { response: {
200: z.object({ 200: z.object({
@@ -398,7 +399,7 @@ export const registerProjectMembershipRouter = async (server: FastifyZodProvider
const membership = await server.services.projectMembership.leaveProject({ const membership = await server.services.projectMembership.leaveProject({
actorId: req.permission.id, actorId: req.permission.id,
actor: req.permission.type, actor: req.permission.type,
projectId: req.params.workspaceId projectId: req.params.projectId
}); });
return { membership }; return { membership };
} }
+84 -166
View File
@@ -40,41 +40,7 @@ const projectWithEnv = SanitizedProjectSchema.merge(
export const registerProjectRouter = async (server: FastifyZodProvider) => { export const registerProjectRouter = async (server: FastifyZodProvider) => {
server.route({ server.route({
method: "GET", method: "GET",
url: "/:workspaceId/keys", url: "/:projectId/users",
config: {
rateLimit: readLimit
},
schema: {
params: z.object({
workspaceId: z.string().trim()
}),
response: {
200: z.object({
publicKeys: z
.object({
publicKey: z.string().nullable().optional(),
userId: z.string()
})
.array()
})
}
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
const publicKeys = await server.services.projectKey.getProjectPublicKeys({
actorId: req.permission.id,
actor: req.permission.type,
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId
});
return { publicKeys };
}
});
server.route({
method: "GET",
url: "/:workspaceId/users",
config: { config: {
rateLimit: readLimit rateLimit: readLimit
}, },
@@ -96,7 +62,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
.optional() .optional()
}), }),
params: z.object({ params: z.object({
workspaceId: z.string().trim() projectId: z.string().trim()
}), }),
response: { response: {
200: z.object({ 200: z.object({
@@ -142,7 +108,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
actor: req.permission.type, actor: req.permission.type,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
includeGroupMembers: req.query.includeGroupMembers, includeGroupMembers: req.query.includeGroupMembers,
projectId: req.params.workspaceId, projectId: req.params.projectId,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
roles roles
}); });
@@ -167,7 +133,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
}), }),
response: { response: {
200: z.object({ 200: z.object({
workspaces: projectWithEnv projects: projectWithEnv
.extend({ .extend({
roles: ProjectRolesSchema.array().optional() roles: ProjectRolesSchema.array().optional()
}) })
@@ -177,7 +143,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
}, },
onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.IDENTITY_ACCESS_TOKEN]), onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => { handler: async (req) => {
const workspaces = await server.services.project.getProjects({ const projects = await server.services.project.getProjects({
includeRoles: req.query.includeRoles, includeRoles: req.query.includeRoles,
actorId: req.permission.id, actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
@@ -185,13 +151,13 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
type: req.query.type type: req.query.type
}); });
return { workspaces }; return { projects };
} }
}); });
server.route({ server.route({
method: "GET", method: "GET",
url: "/:workspaceId", url: "/:projectId",
config: { config: {
rateLimit: readLimit rateLimit: readLimit
}, },
@@ -205,33 +171,33 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
} }
], ],
params: z.object({ params: z.object({
workspaceId: z.string().trim().describe(PROJECTS.GET.workspaceId) projectId: z.string().trim().describe(PROJECTS.GET.projectId)
}), }),
response: { response: {
200: z.object({ 200: z.object({
workspace: projectWithEnv.optional() project: projectWithEnv.optional()
}) })
} }
}, },
onRequest: verifyAuth([AuthMode.JWT, AuthMode.SERVICE_TOKEN, AuthMode.IDENTITY_ACCESS_TOKEN]), onRequest: verifyAuth([AuthMode.JWT, AuthMode.SERVICE_TOKEN, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => { handler: async (req) => {
const workspace = await server.services.project.getAProject({ const project = await server.services.project.getAProject({
filter: { filter: {
type: ProjectFilterType.ID, type: ProjectFilterType.ID,
projectId: req.params.workspaceId projectId: req.params.projectId
}, },
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
actorId: req.permission.id, actorId: req.permission.id,
actor: req.permission.type, actor: req.permission.type,
actorOrgId: req.permission.orgId actorOrgId: req.permission.orgId
}); });
return { workspace }; return { project };
} }
}); });
server.route({ server.route({
method: "DELETE", method: "DELETE",
url: "/:workspaceId", url: "/:projectId",
config: { config: {
rateLimit: writeLimit rateLimit: writeLimit
}, },
@@ -245,20 +211,20 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
} }
], ],
params: z.object({ params: z.object({
workspaceId: z.string().trim().describe(PROJECTS.DELETE.workspaceId) projectId: z.string().trim().describe(PROJECTS.DELETE.projectId)
}), }),
response: { response: {
200: z.object({ 200: z.object({
workspace: SanitizedProjectSchema.optional() project: SanitizedProjectSchema.optional()
}) })
} }
}, },
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]), onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => { handler: async (req) => {
const workspace = await server.services.project.deleteProject({ const project = await server.services.project.deleteProject({
filter: { filter: {
type: ProjectFilterType.ID, type: ProjectFilterType.ID,
projectId: req.params.workspaceId projectId: req.params.projectId
}, },
actorId: req.permission.id, actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
@@ -269,68 +235,20 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
await server.services.auditLog.createAuditLog({ await server.services.auditLog.createAuditLog({
...req.auditLogInfo, ...req.auditLogInfo,
orgId: req.permission.orgId, orgId: req.permission.orgId,
projectId: req.params.workspaceId, projectId: req.params.projectId,
event: { event: {
type: EventType.DELETE_PROJECT, type: EventType.DELETE_PROJECT,
metadata: workspace metadata: project
} }
}); });
return { workspace }; return { project };
}
});
server.route({
url: "/:workspaceId/name",
method: "POST",
config: {
rateLimit: writeLimit
},
schema: {
params: z.object({
workspaceId: z.string().trim()
}),
body: z.object({
name: z.string().trim()
}),
response: {
200: z.object({
message: z.string(),
workspace: SanitizedProjectSchema
})
}
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
const workspace = await server.services.project.updateName({
actorId: req.permission.id,
actor: req.permission.type,
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId,
name: req.body.name
});
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
orgId: req.permission.orgId,
projectId: req.params.workspaceId,
event: {
type: EventType.UPDATE_PROJECT,
metadata: req.body
}
});
return {
message: "Successfully changed workspace name",
workspace
};
} }
}); });
server.route({ server.route({
method: "PATCH", method: "PATCH",
url: "/:workspaceId", url: "/:projectId",
config: { config: {
rateLimit: writeLimit rateLimit: writeLimit
}, },
@@ -344,7 +262,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
} }
], ],
params: z.object({ params: z.object({
workspaceId: z.string().trim().describe(PROJECTS.UPDATE.workspaceId) projectId: z.string().trim().describe(PROJECTS.UPDATE.projectId)
}), }),
body: z.object({ body: z.object({
name: z name: z
@@ -381,16 +299,16 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
}), }),
response: { response: {
200: z.object({ 200: z.object({
workspace: SanitizedProjectSchema project: SanitizedProjectSchema
}) })
} }
}, },
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]), onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => { handler: async (req) => {
const workspace = await server.services.project.updateProject({ const project = await server.services.project.updateProject({
filter: { filter: {
type: ProjectFilterType.ID, type: ProjectFilterType.ID,
projectId: req.params.workspaceId projectId: req.params.projectId
}, },
update: { update: {
name: req.body.name, name: req.body.name,
@@ -412,7 +330,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
await server.services.auditLog.createAuditLog({ await server.services.auditLog.createAuditLog({
...req.auditLogInfo, ...req.auditLogInfo,
orgId: req.permission.orgId, orgId: req.permission.orgId,
projectId: req.params.workspaceId, projectId: req.params.projectId,
event: { event: {
type: EventType.UPDATE_PROJECT, type: EventType.UPDATE_PROJECT,
metadata: req.body metadata: req.body
@@ -420,20 +338,20 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
}); });
return { return {
workspace project
}; };
} }
}); });
server.route({ server.route({
method: "POST", method: "POST",
url: "/:workspaceId/auto-capitalization", url: "/:projectId/auto-capitalization",
config: { config: {
rateLimit: writeLimit rateLimit: writeLimit
}, },
schema: { schema: {
params: z.object({ params: z.object({
workspaceId: z.string().trim() projectId: z.string().trim()
}), }),
body: z.object({ body: z.object({
autoCapitalization: z.boolean() autoCapitalization: z.boolean()
@@ -441,25 +359,25 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
response: { response: {
200: z.object({ 200: z.object({
message: z.string(), message: z.string(),
workspace: SanitizedProjectSchema project: SanitizedProjectSchema
}) })
} }
}, },
onRequest: verifyAuth([AuthMode.JWT]), onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => { handler: async (req) => {
const workspace = await server.services.project.toggleAutoCapitalization({ const project = await server.services.project.toggleAutoCapitalization({
actorId: req.permission.id, actorId: req.permission.id,
actor: req.permission.type, actor: req.permission.type,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId, projectId: req.params.projectId,
autoCapitalization: req.body.autoCapitalization autoCapitalization: req.body.autoCapitalization
}); });
await server.services.auditLog.createAuditLog({ await server.services.auditLog.createAuditLog({
...req.auditLogInfo, ...req.auditLogInfo,
orgId: req.permission.orgId, orgId: req.permission.orgId,
projectId: req.params.workspaceId, projectId: req.params.projectId,
event: { event: {
type: EventType.UPDATE_PROJECT, type: EventType.UPDATE_PROJECT,
metadata: req.body metadata: req.body
@@ -467,21 +385,21 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
}); });
return { return {
message: "Successfully changed workspace settings", message: "Successfully changed project settings",
workspace project
}; };
} }
}); });
server.route({ server.route({
method: "POST", method: "POST",
url: "/:workspaceId/delete-protection", url: "/:projectId/delete-protection",
config: { config: {
rateLimit: writeLimit rateLimit: writeLimit
}, },
schema: { schema: {
params: z.object({ params: z.object({
workspaceId: z.string().trim() projectId: z.string().trim()
}), }),
body: z.object({ body: z.object({
hasDeleteProtection: z.boolean() hasDeleteProtection: z.boolean()
@@ -489,25 +407,25 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
response: { response: {
200: z.object({ 200: z.object({
message: z.string(), message: z.string(),
workspace: SanitizedProjectSchema project: SanitizedProjectSchema
}) })
} }
}, },
onRequest: verifyAuth([AuthMode.JWT]), onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => { handler: async (req) => {
const workspace = await server.services.project.toggleDeleteProtection({ const project = await server.services.project.toggleDeleteProtection({
actorId: req.permission.id, actorId: req.permission.id,
actor: req.permission.type, actor: req.permission.type,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId, projectId: req.params.projectId,
hasDeleteProtection: req.body.hasDeleteProtection hasDeleteProtection: req.body.hasDeleteProtection
}); });
await server.services.auditLog.createAuditLog({ await server.services.auditLog.createAuditLog({
...req.auditLogInfo, ...req.auditLogInfo,
orgId: req.permission.orgId, orgId: req.permission.orgId,
projectId: req.params.workspaceId, projectId: req.params.projectId,
event: { event: {
type: EventType.UPDATE_PROJECT, type: EventType.UPDATE_PROJECT,
metadata: req.body metadata: req.body
@@ -515,8 +433,8 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
}); });
return { return {
message: "Successfully changed workspace settings", message: "Successfully changed project settings",
workspace project
}; };
} }
}); });
@@ -537,13 +455,13 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
response: { response: {
200: z.object({ 200: z.object({
message: z.string(), message: z.string(),
workspace: SanitizedProjectSchema project: SanitizedProjectSchema
}) })
} }
}, },
onRequest: verifyAuth([AuthMode.JWT]), onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => { handler: async (req) => {
const workspace = await server.services.project.updateVersionLimit({ const project = await server.services.project.updateVersionLimit({
actorId: req.permission.id, actorId: req.permission.id,
actor: req.permission.type, actor: req.permission.type,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
@@ -555,7 +473,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
await server.services.auditLog.createAuditLog({ await server.services.auditLog.createAuditLog({
...req.auditLogInfo, ...req.auditLogInfo,
orgId: req.permission.orgId, orgId: req.permission.orgId,
projectId: workspace.id, projectId: project.id,
event: { event: {
type: EventType.UPDATE_PROJECT, type: EventType.UPDATE_PROJECT,
metadata: req.body metadata: req.body
@@ -563,8 +481,8 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
}); });
return { return {
message: "Successfully changed workspace version limit", message: "Successfully changed project version limit",
workspace project
}; };
} }
}); });
@@ -585,13 +503,13 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
response: { response: {
200: z.object({ 200: z.object({
message: z.string(), message: z.string(),
workspace: SanitizedProjectSchema project: SanitizedProjectSchema
}) })
} }
}, },
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]), onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => { handler: async (req) => {
const workspace = await server.services.project.updateAuditLogsRetention({ const project = await server.services.project.updateAuditLogsRetention({
actorId: req.permission.id, actorId: req.permission.id,
actor: req.permission.type, actor: req.permission.type,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
@@ -603,7 +521,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
await server.services.auditLog.createAuditLog({ await server.services.auditLog.createAuditLog({
...req.auditLogInfo, ...req.auditLogInfo,
orgId: req.permission.orgId, orgId: req.permission.orgId,
projectId: workspace.id, projectId: project.id,
event: { event: {
type: EventType.UPDATE_PROJECT, type: EventType.UPDATE_PROJECT,
metadata: req.body metadata: req.body
@@ -612,14 +530,14 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
return { return {
message: "Successfully updated project's audit logs retention period", message: "Successfully updated project's audit logs retention period",
workspace project
}; };
} }
}); });
server.route({ server.route({
method: "GET", method: "GET",
url: "/:workspaceId/integrations", url: "/:projectId/integrations",
config: { config: {
rateLimit: readLimit rateLimit: readLimit
}, },
@@ -633,7 +551,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
} }
], ],
params: z.object({ params: z.object({
workspaceId: z.string().trim().describe(PROJECTS.LIST_INTEGRATION.workspaceId) projectId: z.string().trim().describe(PROJECTS.LIST_INTEGRATION.projectId)
}), }),
response: { response: {
200: z.object({ 200: z.object({
@@ -656,7 +574,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
actor: req.permission.type, actor: req.permission.type,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId projectId: req.params.projectId
}); });
return { integrations }; return { integrations };
} }
@@ -664,21 +582,21 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
server.route({ server.route({
method: "GET", method: "GET",
url: "/:workspaceId/authorizations", url: "/:projectId/authorizations",
config: { config: {
rateLimit: readLimit rateLimit: readLimit
}, },
schema: { schema: {
hide: false, hide: false,
tags: [ApiDocsTags.Integrations], tags: [ApiDocsTags.Integrations],
description: "List integration auth objects for a workspace.", description: "List integration auth objects for a project.",
security: [ security: [
{ {
bearerAuth: [] bearerAuth: []
} }
], ],
params: z.object({ params: z.object({
workspaceId: z.string().trim().describe(PROJECTS.LIST_INTEGRATION_AUTHORIZATION.workspaceId) projectId: z.string().trim().describe(PROJECTS.LIST_INTEGRATION_AUTHORIZATION.projectId)
}), }),
response: { response: {
200: z.object({ 200: z.object({
@@ -693,7 +611,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
actor: req.permission.type, actor: req.permission.type,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId projectId: req.params.projectId
}); });
return { authorizations }; return { authorizations };
} }
@@ -701,13 +619,13 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
server.route({ server.route({
method: "GET", method: "GET",
url: "/:workspaceId/service-token-data", url: "/:projectId/service-token-data",
config: { config: {
rateLimit: readLimit rateLimit: readLimit
}, },
schema: { schema: {
params: z.object({ params: z.object({
workspaceId: z.string().trim() projectId: z.string().trim()
}), }),
response: { response: {
200: z.object({ 200: z.object({
@@ -722,7 +640,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
actor: req.permission.type, actor: req.permission.type,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId projectId: req.params.projectId
}); });
return { serviceTokenData }; return { serviceTokenData };
} }
@@ -730,13 +648,13 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
server.route({ server.route({
method: "GET", method: "GET",
url: "/:workspaceId/ssh-config", url: "/:projectId/ssh-config",
config: { config: {
rateLimit: readLimit rateLimit: readLimit
}, },
schema: { schema: {
params: z.object({ params: z.object({
workspaceId: z.string().trim() projectId: z.string().trim()
}), }),
response: { response: {
200: ProjectSshConfigsSchema.pick({ 200: ProjectSshConfigsSchema.pick({
@@ -756,7 +674,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
actor: req.permission.type, actor: req.permission.type,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId projectId: req.params.projectId
}); });
await server.services.auditLog.createAuditLog({ await server.services.auditLog.createAuditLog({
@@ -777,13 +695,13 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
server.route({ server.route({
method: "PATCH", method: "PATCH",
url: "/:workspaceId/ssh-config", url: "/:projectId/ssh-config",
config: { config: {
rateLimit: writeLimit rateLimit: writeLimit
}, },
schema: { schema: {
params: z.object({ params: z.object({
workspaceId: z.string().trim() projectId: z.string().trim()
}), }),
body: z.object({ body: z.object({
defaultUserSshCaId: z.string().optional(), defaultUserSshCaId: z.string().optional(),
@@ -807,7 +725,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
actor: req.permission.type, actor: req.permission.type,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId, projectId: req.params.projectId,
...req.body ...req.body
}); });
@@ -831,13 +749,13 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
server.route({ server.route({
method: "GET", method: "GET",
url: "/:workspaceId/workflow-integration-config/:integration", url: "/:projectId/workflow-integration-config/:integration",
config: { config: {
rateLimit: readLimit rateLimit: readLimit
}, },
schema: { schema: {
params: z.object({ params: z.object({
workspaceId: z.string().trim(), projectId: z.string().trim(),
integration: z.nativeEnum(WorkflowIntegration) integration: z.nativeEnum(WorkflowIntegration)
}), }),
response: { response: {
@@ -876,13 +794,13 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
actor: req.permission.type, actor: req.permission.type,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId, projectId: req.params.projectId,
integration: req.params.integration integration: req.params.integration
}); });
await server.services.auditLog.createAuditLog({ await server.services.auditLog.createAuditLog({
...req.auditLogInfo, ...req.auditLogInfo,
projectId: req.params.workspaceId, projectId: req.params.projectId,
event: { event: {
type: EventType.GET_PROJECT_WORKFLOW_INTEGRATION_CONFIG, type: EventType.GET_PROJECT_WORKFLOW_INTEGRATION_CONFIG,
metadata: { metadata: {
@@ -936,13 +854,13 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
server.route({ server.route({
method: "PUT", method: "PUT",
url: "/:workspaceId/workflow-integration", url: "/:projectId/workflow-integration",
config: { config: {
rateLimit: readLimit rateLimit: readLimit
}, },
schema: { schema: {
params: z.object({ params: z.object({
workspaceId: z.string().trim() projectId: z.string().trim()
}), }),
body: z.discriminatedUnion("integration", [ body: z.discriminatedUnion("integration", [
@@ -999,13 +917,13 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
actor: req.permission.type, actor: req.permission.type,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
projectId: req.params.workspaceId, projectId: req.params.projectId,
...req.body ...req.body
}); });
await server.services.auditLog.createAuditLog({ await server.services.auditLog.createAuditLog({
...req.auditLogInfo, ...req.auditLogInfo,
projectId: req.params.workspaceId, projectId: req.params.projectId,
event: { event: {
type: EventType.UPDATE_PROJECT_WORKFLOW_INTEGRATION_CONFIG, type: EventType.UPDATE_PROJECT_WORKFLOW_INTEGRATION_CONFIG,
metadata: { metadata: {
@@ -1026,13 +944,13 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
server.route({ server.route({
method: "GET", method: "GET",
url: "/:workspaceId/environment-folder-tree", url: "/:projectId/environment-folder-tree",
config: { config: {
rateLimit: readLimit rateLimit: readLimit
}, },
schema: { schema: {
params: z.object({ params: z.object({
workspaceId: z.string().trim() projectId: z.string().trim()
}), }),
response: { response: {
200: z.record( 200: z.record(
@@ -1043,7 +961,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
onRequest: verifyAuth([AuthMode.JWT]), onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => { handler: async (req) => {
const environmentsFolders = await server.services.folder.getProjectEnvironmentsFolders( const environmentsFolders = await server.services.folder.getProjectEnvironmentsFolders(
req.params.workspaceId, req.params.projectId,
req.permission req.permission
); );
@@ -1092,13 +1010,13 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
server.route({ server.route({
method: "POST", method: "POST",
url: "/:workspaceId/project-access", url: "/:projectId/project-access",
config: { config: {
rateLimit: requestAccessLimit rateLimit: requestAccessLimit
}, },
schema: { schema: {
params: z.object({ params: z.object({
workspaceId: z.string().trim() projectId: z.string().trim()
}), }),
body: z.object({ body: z.object({
comment: z comment: z
@@ -1132,17 +1050,17 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
await server.services.project.requestProjectAccess({ await server.services.project.requestProjectAccess({
permission: req.permission, permission: req.permission,
comment: req.body.comment, comment: req.body.comment,
projectId: req.params.workspaceId projectId: req.params.projectId
}); });
if (req.auth.actor === ActorType.USER) { if (req.auth.actor === ActorType.USER) {
await server.services.auditLog.createAuditLog({ await server.services.auditLog.createAuditLog({
...req.auditLogInfo, ...req.auditLogInfo,
projectId: req.params.workspaceId, projectId: req.params.projectId,
event: { event: {
type: EventType.PROJECT_ACCESS_REQUEST, type: EventType.PROJECT_ACCESS_REQUEST,
metadata: { metadata: {
projectId: req.params.workspaceId, projectId: req.params.projectId,
requesterEmail: req.auth.user.email || req.auth.user.username, requesterEmail: req.auth.user.email || req.auth.user.username,
requesterId: req.auth.userId requesterId: req.auth.userId
} }
@@ -22,20 +22,20 @@ export const registerSecretTagRouter = async (server: FastifyZodProvider) => {
}), }),
response: { response: {
200: z.object({ 200: z.object({
workspaceTags: SecretTagsSchema.array() tags: SecretTagsSchema.array()
}) })
} }
}, },
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]), onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => { handler: async (req) => {
const workspaceTags = await server.services.secretTag.getProjectTags({ const tags = await server.services.secretTag.getProjectTags({
actor: req.permission.type, actor: req.permission.type,
actorId: req.permission.id, actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
projectId: req.params.projectId projectId: req.params.projectId
}); });
return { workspaceTags }; return { tags };
} }
}); });
@@ -55,20 +55,20 @@ export const registerSecretTagRouter = async (server: FastifyZodProvider) => {
response: { response: {
200: z.object({ 200: z.object({
// akhilmhdh: for terraform backward compatiability // akhilmhdh: for terraform backward compatiability
workspaceTag: SecretTagsSchema.extend({ name: z.string() }) tag: SecretTagsSchema.extend({ name: z.string() })
}) })
} }
}, },
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]), onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => { handler: async (req) => {
const workspaceTag = await server.services.secretTag.getTagById({ const tag = await server.services.secretTag.getTagById({
actor: req.permission.type, actor: req.permission.type,
actorId: req.permission.id, actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
id: req.params.tagId id: req.params.tagId
}); });
return { workspaceTag }; return { tag };
} }
}); });
@@ -88,13 +88,13 @@ export const registerSecretTagRouter = async (server: FastifyZodProvider) => {
response: { response: {
200: z.object({ 200: z.object({
// akhilmhdh: for terraform backward compatiability // akhilmhdh: for terraform backward compatiability
workspaceTag: SecretTagsSchema.extend({ name: z.string() }) tag: SecretTagsSchema.extend({ name: z.string() })
}) })
} }
}, },
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]), onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => { handler: async (req) => {
const workspaceTag = await server.services.secretTag.getTagBySlug({ const tag = await server.services.secretTag.getTagBySlug({
actor: req.permission.type, actor: req.permission.type,
actorId: req.permission.id, actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
@@ -102,7 +102,7 @@ export const registerSecretTagRouter = async (server: FastifyZodProvider) => {
slug: req.params.tagSlug, slug: req.params.tagSlug,
projectId: req.params.projectId projectId: req.params.projectId
}); });
return { workspaceTag }; return { tag };
} }
}); });
@@ -124,13 +124,13 @@ export const registerSecretTagRouter = async (server: FastifyZodProvider) => {
}), }),
response: { response: {
200: z.object({ 200: z.object({
workspaceTag: SecretTagsSchema tag: SecretTagsSchema
}) })
} }
}, },
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]), onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => { handler: async (req) => {
const workspaceTag = await server.services.secretTag.createTag({ const tag = await server.services.secretTag.createTag({
actor: req.permission.type, actor: req.permission.type,
actorId: req.permission.id, actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
@@ -138,7 +138,7 @@ export const registerSecretTagRouter = async (server: FastifyZodProvider) => {
projectId: req.params.projectId, projectId: req.params.projectId,
...req.body ...req.body
}); });
return { workspaceTag }; return { tag };
} }
}); });
@@ -161,13 +161,13 @@ export const registerSecretTagRouter = async (server: FastifyZodProvider) => {
}), }),
response: { response: {
200: z.object({ 200: z.object({
workspaceTag: SecretTagsSchema tag: SecretTagsSchema
}) })
} }
}, },
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]), onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => { handler: async (req) => {
const workspaceTag = await server.services.secretTag.updateTag({ const tag = await server.services.secretTag.updateTag({
actor: req.permission.type, actor: req.permission.type,
actorId: req.permission.id, actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
@@ -175,7 +175,7 @@ export const registerSecretTagRouter = async (server: FastifyZodProvider) => {
...req.body, ...req.body,
id: req.params.tagId id: req.params.tagId
}); });
return { workspaceTag }; return { tag };
} }
}); });
@@ -194,20 +194,20 @@ export const registerSecretTagRouter = async (server: FastifyZodProvider) => {
}), }),
response: { response: {
200: z.object({ 200: z.object({
workspaceTag: SecretTagsSchema tag: SecretTagsSchema
}) })
} }
}, },
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]), onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => { handler: async (req) => {
const workspaceTag = await server.services.secretTag.deleteTag({ const tag = await server.services.secretTag.deleteTag({
actor: req.permission.type, actor: req.permission.type,
actorId: req.permission.id, actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
id: req.params.tagId id: req.params.tagId
}); });
return { workspaceTag }; return { tag };
} }
}); });
}; };
@@ -1,7 +1,7 @@
import { useSuspenseQuery } from "@tanstack/react-query"; import { useSuspenseQuery } from "@tanstack/react-query";
import { useParams } from "@tanstack/react-router"; import { useParams } from "@tanstack/react-router";
import { workspaceKeys } from "@app/hooks/api"; import { projectKeys } from "@app/hooks/api";
import { fetchWorkspaceById } from "@app/hooks/api/workspace/queries"; import { fetchWorkspaceById } from "@app/hooks/api/workspace/queries";
export const useWorkspace = () => { export const useWorkspace = () => {
@@ -13,7 +13,7 @@ export const useWorkspace = () => {
} }
const { data: currentWorkspace } = useSuspenseQuery({ const { data: currentWorkspace } = useSuspenseQuery({
queryKey: workspaceKeys.getWorkspaceById(params.projectId), queryKey: projectKeys.getWorkspaceById(params.projectId),
queryFn: () => fetchWorkspaceById(params.projectId as string), queryFn: () => fetchWorkspaceById(params.projectId as string),
staleTime: Infinity staleTime: Infinity
}); });
@@ -7,27 +7,27 @@ import { Commit, CommitHistoryItem, CommitWithChanges, RollbackPreview } from ".
export const commitKeys = { export const commitKeys = {
count: ({ count: ({
workspaceId, projectId,
environment, environment,
directory directory
}: { }: {
workspaceId: string; projectId: string;
environment: string; environment: string;
directory?: string; directory?: string;
}) => [{ workspaceId, environment, directory }, "folder-commits-count"] as const, }) => [{ projectId, environment, directory }, "folder-commits-count"] as const,
history: ({ history: ({
workspaceId, projectId,
environment, environment,
directory directory
}: { }: {
workspaceId: string; projectId: string;
environment: string; environment: string;
directory?: string; directory?: string;
}) => [{ workspaceId, environment, directory }, "folder-commits"] as const, }) => [{ projectId, environment, directory }, "folder-commits"] as const,
details: ({ workspaceId, commitId }: { workspaceId: string; commitId: string }) => details: ({ projectId, commitId }: { projectId: string; commitId: string }) =>
[{ workspaceId, commitId }, "commit-details"] as const, [{ projectId, commitId }, "commit-details"] as const,
rollbackPreview: ({ rollbackPreview: ({
folderId, folderId,
@@ -45,11 +45,11 @@ export const commitKeys = {
}; };
const fetchFolderCommitsCount = async ({ const fetchFolderCommitsCount = async ({
workspaceId, projectId,
environment, environment,
directory directory
}: { }: {
workspaceId: string; projectId: string;
environment: string; environment: string;
directory?: string; directory?: string;
}) => { }) => {
@@ -59,7 +59,7 @@ const fetchFolderCommitsCount = async ({
params: { params: {
environment, environment,
path: directory, path: directory,
projectId: workspaceId projectId
} }
} }
); );
@@ -67,7 +67,7 @@ const fetchFolderCommitsCount = async ({
}; };
const fetchFolderCommitHistory = async ( const fetchFolderCommitHistory = async (
workspaceId: string, projectId: string,
environment: string, environment: string,
directory: string, directory: string,
offset: number = 0, offset: number = 0,
@@ -87,7 +87,7 @@ const fetchFolderCommitHistory = async (
params: { params: {
environment, environment,
path: directory, path: directory,
projectId: workspaceId, projectId: projectId,
offset, offset,
limit, limit,
search, search,
@@ -97,12 +97,12 @@ const fetchFolderCommitHistory = async (
return res.data; return res.data;
}; };
export const fetchCommitDetails = async (workspaceId: string, commitId: string) => { export const fetchCommitDetails = async (projectId: string, commitId: string) => {
const { data } = await apiRequest.get<CommitWithChanges>( const { data } = await apiRequest.get<CommitWithChanges>(
`/api/v1/pit/commits/${commitId}/changes`, `/api/v1/pit/commits/${commitId}/changes`,
{ {
params: { params: {
projectId: workspaceId projectId: projectId
} }
} }
); );
@@ -113,7 +113,7 @@ export const fetchRollbackPreview = async (
folderId: string, folderId: string,
commitId: string, commitId: string,
envSlug: string, envSlug: string,
workspaceId: string, projectId: string,
deepRollback: boolean, deepRollback: boolean,
secretPath: string secretPath: string
): Promise<RollbackPreview[]> => { ): Promise<RollbackPreview[]> => {
@@ -125,7 +125,7 @@ export const fetchRollbackPreview = async (
environment: envSlug, environment: envSlug,
deepRollback, deepRollback,
secretPath, secretPath,
projectId: workspaceId projectId: projectId
} }
} }
); );
@@ -135,7 +135,7 @@ export const fetchRollbackPreview = async (
const fetchRollback = async ( const fetchRollback = async (
folderId: string, folderId: string,
commitId: string, commitId: string,
workspaceId: string, projectId: string,
deepRollback: boolean, deepRollback: boolean,
message?: string, message?: string,
envSlug?: string envSlug?: string
@@ -147,17 +147,17 @@ const fetchRollback = async (
deepRollback, deepRollback,
message, message,
environment: envSlug, environment: envSlug,
projectId: workspaceId projectId
} }
); );
return data; return data;
}; };
const fetchRevert = async (commitId: string, workspaceId: string) => { const fetchRevert = async (commitId: string, projectId: string) => {
const { data } = await apiRequest.post<{ success: boolean; message: string }>( const { data } = await apiRequest.post<{ success: boolean; message: string }>(
`/api/v1/pit/commits/${commitId}/revert`, `/api/v1/pit/commits/${commitId}/revert`,
{ {
projectId: workspaceId projectId: projectId
} }
); );
return data; return data;
@@ -180,9 +180,9 @@ export const useCommitRevert = ({
onSuccess: () => { onSuccess: () => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: [ queryKey: [
commitKeys.details({ workspaceId: projectId, commitId }), commitKeys.details({ projectId, commitId }),
commitKeys.history({ workspaceId: projectId, environment, directory }), commitKeys.history({ projectId, environment, directory }),
commitKeys.count({ workspaceId: projectId, environment, directory }) commitKeys.count({ projectId, environment, directory })
] ]
}); });
} }
@@ -190,7 +190,7 @@ export const useCommitRevert = ({
}; };
export const useCommitRollback = ({ export const useCommitRollback = ({
workspaceId, projectId,
commitId, commitId,
folderId, folderId,
deepRollback, deepRollback,
@@ -198,7 +198,7 @@ export const useCommitRollback = ({
directory, directory,
envSlug envSlug
}: { }: {
workspaceId: string; projectId: string;
commitId: string; commitId: string;
folderId: string; folderId: string;
deepRollback: boolean; deepRollback: boolean;
@@ -209,13 +209,13 @@ export const useCommitRollback = ({
const queryClient = useQueryClient(); const queryClient = useQueryClient();
return useMutation({ return useMutation({
mutationFn: (message: string) => mutationFn: (message: string) =>
fetchRollback(folderId, commitId, workspaceId, deepRollback, message, envSlug), fetchRollback(folderId, commitId, projectId, deepRollback, message, envSlug),
onSuccess: () => { onSuccess: () => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: [ queryKey: [
commitKeys.details({ workspaceId, commitId }), commitKeys.details({ projectId, commitId }),
commitKeys.history({ workspaceId, environment, directory }), commitKeys.history({ projectId, environment, directory }),
commitKeys.count({ workspaceId, environment, directory }) commitKeys.count({ projectId, environment, directory })
] ]
}); });
} }
@@ -223,31 +223,31 @@ export const useCommitRollback = ({
}; };
export const useGetFolderCommitsCount = ({ export const useGetFolderCommitsCount = ({
workspaceId, projectId,
environment, environment,
directory, directory,
isPaused isPaused
}: { }: {
workspaceId: string; projectId: string;
environment: string; environment: string;
directory: string; directory: string;
isPaused?: boolean; isPaused?: boolean;
}) => }) =>
useQuery({ useQuery({
enabled: Boolean(workspaceId && environment) && !isPaused, enabled: Boolean(projectId && environment) && !isPaused,
queryKey: commitKeys.count({ workspaceId, environment, directory }), queryKey: commitKeys.count({ projectId: projectId, environment, directory }),
queryFn: () => fetchFolderCommitsCount({ workspaceId, environment, directory }) queryFn: () => fetchFolderCommitsCount({ projectId, environment, directory })
}); });
export const useGetFolderCommitHistory = ({ export const useGetFolderCommitHistory = ({
workspaceId, projectId,
environment, environment,
directory, directory,
limit = 20, limit = 20,
search, search,
sort = "desc" sort = "desc"
}: { }: {
workspaceId: string; projectId: string;
environment: string; environment: string;
directory: string; directory: string;
limit?: number; limit?: number;
@@ -256,10 +256,10 @@ export const useGetFolderCommitHistory = ({
}) => { }) => {
return useInfiniteQuery({ return useInfiniteQuery({
initialPageParam: 0, initialPageParam: 0,
queryKey: [commitKeys.history({ workspaceId, environment, directory }), limit, search, sort], queryKey: [commitKeys.history({ projectId, environment, directory }), limit, search, sort],
queryFn: ({ pageParam }) => queryFn: ({ pageParam }) =>
fetchFolderCommitHistory(workspaceId, environment, directory, pageParam, limit, search, sort), fetchFolderCommitHistory(projectId, environment, directory, pageParam, limit, search, sort),
enabled: Boolean(workspaceId && environment), enabled: Boolean(projectId && environment),
select: (data) => { select: (data) => {
return (data?.pages ?? []) return (data?.pages ?? [])
?.map((page) => page.commits) ?.map((page) => page.commits)
@@ -280,11 +280,11 @@ export const useGetFolderCommitHistory = ({
}); });
}; };
export const useGetCommitDetails = (workspaceId: string, commitId: string) => { export const useGetCommitDetails = (projectId: string, commitId: string) => {
return useQuery({ return useQuery({
queryKey: commitKeys.details({ workspaceId, commitId }), queryKey: commitKeys.details({ projectId, commitId }),
queryFn: () => fetchCommitDetails(workspaceId, commitId), queryFn: () => fetchCommitDetails(projectId, commitId),
enabled: Boolean(workspaceId) && Boolean(commitId) enabled: Boolean(projectId) && Boolean(commitId)
}); });
}; };
+2 -2
View File
@@ -1,7 +1,7 @@
import { OrderByDirection } from "../generic/types"; import { OrderByDirection } from "../generic/types";
import { OrgIdentityOrderBy } from "../organization/types"; import { OrgIdentityOrderBy } from "../organization/types";
import { TOrgRole } from "../roles/types"; import { TOrgRole } from "../roles/types";
import { ProjectUserMembershipTemporaryMode, Workspace } from "../workspace/types"; import { ProjectUserMembershipTemporaryMode, Project } from "../workspace/types";
import { IdentityAuthMethod, IdentityJwtConfigurationType } from "./enums"; import { IdentityAuthMethod, IdentityJwtConfigurationType } from "./enums";
export type IdentityTrustedIp = { export type IdentityTrustedIp = {
@@ -54,7 +54,7 @@ export type IdentityMembershipOrg = {
export type IdentityMembership = { export type IdentityMembership = {
id: string; id: string;
identity: Identity; identity: Identity;
project: Pick<Workspace, "id" | "name" | "type">; project: Pick<Project, "id" | "name" | "type">;
roles: Array< roles: Array<
{ {
id: string; id: string;
-1
View File
@@ -1 +0,0 @@
export { useGetUserWsKey, useUploadWsKey } from "./queries";
-43
View File
@@ -1,43 +0,0 @@
import { useMutation, useQuery } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { UploadWsKeyDTO, UserWsKeyPair } from "./types";
const encKeyKeys = {
getUserWorkspaceKey: (workspaceID: string) => ["workspace-key-pair", { workspaceID }] as const
};
export const fetchUserWsKey = async (projectId: string) => {
const { data } = await apiRequest.get<UserWsKeyPair>(
`/api/v2/workspace/${projectId}/encrypted-key`
);
return data;
};
export const useGetUserWsKey = (workspaceID: string) =>
useQuery({
queryKey: encKeyKeys.getUserWorkspaceKey(workspaceID),
queryFn: () => fetchUserWsKey(workspaceID),
enabled: Boolean(workspaceID)
});
// mutations
export const uploadWsKey = async ({ workspaceId, userId, encryptedKey, nonce }: UploadWsKeyDTO) => {
return apiRequest.post(`/api/v1/workspace/${workspaceId}/key`, {
key: { userId, encryptedKey, nonce }
});
};
export const useUploadWsKey = () =>
useMutation<object, object, UploadWsKeyDTO>({
mutationFn: async ({ encryptedKey, nonce, userId, workspaceId }) => {
return uploadWsKey({
workspaceId,
userId,
encryptedKey,
nonce
});
}
});
-29
View File
@@ -1,29 +0,0 @@
export type UserWsKeyPair = {
id: string;
encryptedKey: string;
nonce: string;
sender: Sender;
receiver: string;
workspace: string;
createdAt: string;
updatedAt: string;
__v: number;
};
export type Sender = {
id: string;
email: string;
createdAt: string;
updatedAt: string;
__v: number;
firstName: string;
lastName: string;
publicKey: string;
};
export type UploadWsKeyDTO = {
userId: string;
encryptedKey: string;
nonce: string;
workspaceId: string;
};
@@ -3,7 +3,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request"; import { apiRequest } from "@app/config/request";
import { TCreateCertificateResponse } from "../ca/types"; import { TCreateCertificateResponse } from "../ca/types";
import { workspaceKeys } from "../workspace/query-keys"; import { projectKeys } from "../workspace/query-keys";
import { pkiSubscriberKeys } from "./queries"; import { pkiSubscriberKeys } from "./queries";
import { import {
TCreatePkiSubscriberDTO, TCreatePkiSubscriberDTO,
@@ -22,7 +22,7 @@ export const useCreatePkiSubscriber = () => {
}, },
onSuccess: ({ projectId, name }) => { onSuccess: ({ projectId, name }) => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.getWorkspacePkiSubscribers(projectId) queryKey: projectKeys.getWorkspacePkiSubscribers(projectId)
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: pkiSubscriberKeys.getPkiSubscriber({ queryKey: pkiSubscriberKeys.getPkiSubscriber({
@@ -46,7 +46,7 @@ export const useUpdatePkiSubscriber = () => {
}, },
onSuccess: ({ projectId, name }) => { onSuccess: ({ projectId, name }) => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.getWorkspacePkiSubscribers(projectId) queryKey: projectKeys.getWorkspacePkiSubscribers(projectId)
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: pkiSubscriberKeys.getPkiSubscriber({ queryKey: pkiSubscriberKeys.getPkiSubscriber({
@@ -74,7 +74,7 @@ export const useDeletePkiSubscriber = () => {
}, },
onSuccess: ({ name, projectId }) => { onSuccess: ({ name, projectId }) => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.getWorkspacePkiSubscribers(projectId) queryKey: projectKeys.getWorkspacePkiSubscribers(projectId)
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: pkiSubscriberKeys.getPkiSubscriber({ queryKey: pkiSubscriberKeys.getPkiSubscriber({
@@ -57,7 +57,7 @@ export const useListProjectEnvironmentsFolders = (
queryKey: folderQueryKeys.getProjectEnvironmentsFolders(projectId), queryKey: folderQueryKeys.getProjectEnvironmentsFolders(projectId),
queryFn: async () => { queryFn: async () => {
const { data } = await apiRequest.get<TProjectEnvironmentsFolders>( const { data } = await apiRequest.get<TProjectEnvironmentsFolders>(
`/api/v1/workspace/${projectId}/environment-folder-tree` `/api/v1/projects/${projectId}/environment-folder-tree`
); );
return data; return data;
}, },
@@ -162,13 +162,13 @@ export const useCreateFolder = () => {
queryKey: folderQueryKeys.getSecretFolders({ projectId, environment, path }) queryKey: folderQueryKeys.getSecretFolders({ projectId, environment, path })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.list({ workspaceId: projectId, environment, directory: path }) queryKey: secretSnapshotKeys.list({ projectId, environment, directory: path })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.count({ workspaceId: projectId, environment, directory: path }) queryKey: secretSnapshotKeys.count({ projectId, environment, directory: path })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.count({ workspaceId: projectId, environment, directory: path }) queryKey: commitKeys.count({ projectId, environment, directory: path })
}); });
} }
}); });
@@ -199,16 +199,16 @@ export const useUpdateFolder = () => {
queryKey: folderQueryKeys.getSecretFolders({ projectId, environment, path }) queryKey: folderQueryKeys.getSecretFolders({ projectId, environment, path })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.list({ workspaceId: projectId, environment, directory: path }) queryKey: secretSnapshotKeys.list({ projectId, environment, directory: path })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.count({ workspaceId: projectId, environment, directory: path }) queryKey: secretSnapshotKeys.count({ projectId, environment, directory: path })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.count({ workspaceId: projectId, environment, directory: path }) queryKey: commitKeys.count({ projectId, environment, directory: path })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.history({ workspaceId: projectId, environment, directory: path }) queryKey: commitKeys.history({ projectId, environment, directory: path })
}); });
} }
}); });
@@ -239,16 +239,16 @@ export const useDeleteFolder = () => {
queryKey: folderQueryKeys.getSecretFolders({ projectId, environment, path }) queryKey: folderQueryKeys.getSecretFolders({ projectId, environment, path })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.list({ workspaceId: projectId, environment, directory: path }) queryKey: secretSnapshotKeys.list({ projectId, environment, directory: path })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.count({ workspaceId: projectId, environment, directory: path }) queryKey: secretSnapshotKeys.count({ projectId, environment, directory: path })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.count({ workspaceId: projectId, environment, directory: path }) queryKey: commitKeys.count({ projectId, environment, directory: path })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.history({ workspaceId: projectId, environment, directory: path }) queryKey: commitKeys.history({ projectId, environment, directory: path })
}); });
} }
}); });
@@ -283,28 +283,28 @@ export const useUpdateFolderBatch = () => {
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.list({ queryKey: secretSnapshotKeys.list({
workspaceId: projectId, projectId,
environment: folder.environment, environment: folder.environment,
directory: folder.path directory: folder.path
}) })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.count({ queryKey: secretSnapshotKeys.count({
workspaceId: projectId, projectId,
environment: folder.environment, environment: folder.environment,
directory: folder.path directory: folder.path
}) })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.count({ queryKey: commitKeys.count({
workspaceId: projectId, projectId,
environment: folder.environment, environment: folder.environment,
directory: folder.path directory: folder.path
}) })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.history({ queryKey: commitKeys.history({
workspaceId: projectId, projectId,
environment: folder.environment, environment: folder.environment,
directory: folder.path directory: folder.path
}) })
+8 -8
View File
@@ -66,7 +66,7 @@ export const useCreateSecretV3 = ({
queryKey: secretSnapshotKeys.count({ environment, workspaceId, directory: secretPath }) queryKey: secretSnapshotKeys.count({ environment, workspaceId, directory: secretPath })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.count({ workspaceId, environment, directory: secretPath }) queryKey: commitKeys.count({ projectId: workspaceId, environment, directory: secretPath })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath }) queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath })
@@ -131,7 +131,7 @@ export const useUpdateSecretV3 = ({
queryKey: secretSnapshotKeys.count({ environment, workspaceId, directory: secretPath }) queryKey: secretSnapshotKeys.count({ environment, workspaceId, directory: secretPath })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.count({ workspaceId, environment, directory: secretPath }) queryKey: commitKeys.count({ projectId: workspaceId, environment, directory: secretPath })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath }) queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath })
@@ -183,7 +183,7 @@ export const useDeleteSecretV3 = ({
queryKey: secretSnapshotKeys.count({ environment, workspaceId, directory: secretPath }) queryKey: secretSnapshotKeys.count({ environment, workspaceId, directory: secretPath })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.count({ workspaceId, environment, directory: secretPath }) queryKey: commitKeys.count({ projectId: workspaceId, environment, directory: secretPath })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath }) queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath })
@@ -225,7 +225,7 @@ export const useCreateSecretBatch = ({
queryKey: secretSnapshotKeys.count({ environment, workspaceId, directory: secretPath }) queryKey: secretSnapshotKeys.count({ environment, workspaceId, directory: secretPath })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.count({ workspaceId, environment, directory: secretPath }) queryKey: commitKeys.count({ projectId: workspaceId, environment, directory: secretPath })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath }) queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath })
@@ -267,7 +267,7 @@ export const useUpdateSecretBatch = ({
queryKey: secretSnapshotKeys.count({ environment, workspaceId, directory: secretPath }) queryKey: secretSnapshotKeys.count({ environment, workspaceId, directory: secretPath })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.count({ workspaceId, environment, directory: secretPath }) queryKey: commitKeys.count({ projectId: workspaceId, environment, directory: secretPath })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath }) queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath })
@@ -311,7 +311,7 @@ export const useDeleteSecretBatch = ({
queryKey: secretSnapshotKeys.count({ environment, workspaceId, directory: secretPath }) queryKey: secretSnapshotKeys.count({ environment, workspaceId, directory: secretPath })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.count({ workspaceId, environment, directory: secretPath }) queryKey: commitKeys.count({ projectId: workspaceId, environment, directory: secretPath })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath }) queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath })
@@ -391,7 +391,7 @@ export const useMoveSecrets = ({
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.count({ queryKey: commitKeys.count({
workspaceId: projectId, projectId: projectId,
environment: sourceEnvironment, environment: sourceEnvironment,
directory: sourceSecretPath directory: sourceSecretPath
}) })
@@ -515,7 +515,7 @@ export const useCreateCommit = () => {
queryKey: secretSnapshotKeys.count({ environment, workspaceId, directory: secretPath }) queryKey: secretSnapshotKeys.count({ environment, workspaceId, directory: secretPath })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.count({ workspaceId, environment, directory: secretPath }) queryKey: commitKeys.count({ projectId: workspaceId, environment, directory: secretPath })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath }) queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath })
@@ -13,9 +13,9 @@ const serviceTokenKeys = {
getAllWorkspaceServiceToken: (workspaceID: string) => [{ workspaceID }, "service-tokens"] as const getAllWorkspaceServiceToken: (workspaceID: string) => [{ workspaceID }, "service-tokens"] as const
}; };
const fetchWorkspaceServiceTokens = async (workspaceID: string) => { const fetchWorkspaceServiceTokens = async (projectID: string) => {
const { data } = await apiRequest.get<{ serviceTokenData: ServiceToken[] }>( const { data } = await apiRequest.get<{ serviceTokenData: ServiceToken[] }>(
`/api/v1/workspace/${workspaceID}/service-token-data` `/api/v1/projects/${projectID}/service-token-data`
); );
return data.serviceTokenData; return data.serviceTokenData;
+6 -6
View File
@@ -2,7 +2,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request"; import { apiRequest } from "@app/config/request";
import { workspaceKeys } from "../workspace/query-keys"; import { projectKeys } from "../workspace/query-keys";
import { import {
TCreateSshCaDTO, TCreateSshCaDTO,
TDeleteSshCaDTO, TDeleteSshCaDTO,
@@ -28,7 +28,7 @@ export const useCreateSshCa = () => {
return ca; return ca;
}, },
onSuccess: ({ projectId }) => { onSuccess: ({ projectId }) => {
queryClient.invalidateQueries({ queryKey: workspaceKeys.getWorkspaceSshCas(projectId) }); queryClient.invalidateQueries({ queryKey: projectKeys.getWorkspaceSshCas(projectId) });
} }
}); });
}; };
@@ -43,7 +43,7 @@ export const useUpdateSshCa = () => {
return ca; return ca;
}, },
onSuccess: ({ projectId }, { caId }) => { onSuccess: ({ projectId }, { caId }) => {
queryClient.invalidateQueries({ queryKey: workspaceKeys.getWorkspaceSshCas(projectId) }); queryClient.invalidateQueries({ queryKey: projectKeys.getWorkspaceSshCas(projectId) });
queryClient.invalidateQueries({ queryKey: sshCaKeys.getSshCaById(caId) }); queryClient.invalidateQueries({ queryKey: sshCaKeys.getSshCaById(caId) });
} }
}); });
@@ -59,7 +59,7 @@ export const useDeleteSshCa = () => {
return ca; return ca;
}, },
onSuccess: ({ projectId }) => { onSuccess: ({ projectId }) => {
queryClient.invalidateQueries({ queryKey: workspaceKeys.getWorkspaceSshCas(projectId) }); queryClient.invalidateQueries({ queryKey: projectKeys.getWorkspaceSshCas(projectId) });
} }
}); });
}; };
@@ -76,7 +76,7 @@ export const useSignSshKey = () => {
}, },
onSuccess: (_, { projectId }) => { onSuccess: (_, { projectId }) => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.allWorkspaceSshCertificates(projectId) queryKey: projectKeys.allWorkspaceSshCertificates(projectId)
}); });
} }
}); });
@@ -94,7 +94,7 @@ export const useIssueSshCreds = () => {
}, },
onSuccess: (_, { projectId }) => { onSuccess: (_, { projectId }) => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.allWorkspaceSshCertificates(projectId) queryKey: projectKeys.allWorkspaceSshCertificates(projectId)
}); });
} }
}); });
+4 -4
View File
@@ -2,7 +2,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request"; import { apiRequest } from "@app/config/request";
import { workspaceKeys } from "../workspace/query-keys"; import { projectKeys } from "../workspace/query-keys";
import { TCreateSshHostDTO, TDeleteSshHostDTO, TSshHost, TUpdateSshHostDTO } from "./types"; import { TCreateSshHostDTO, TDeleteSshHostDTO, TSshHost, TUpdateSshHostDTO } from "./types";
export const useCreateSshHost = () => { export const useCreateSshHost = () => {
@@ -13,7 +13,7 @@ export const useCreateSshHost = () => {
return host; return host;
}, },
onSuccess: ({ projectId }) => { onSuccess: ({ projectId }) => {
queryClient.invalidateQueries({ queryKey: workspaceKeys.getWorkspaceSshHosts(projectId) }); queryClient.invalidateQueries({ queryKey: projectKeys.getWorkspaceSshHosts(projectId) });
} }
}); });
}; };
@@ -26,7 +26,7 @@ export const useUpdateSshHost = () => {
return host; return host;
}, },
onSuccess: ({ projectId }) => { onSuccess: ({ projectId }) => {
queryClient.invalidateQueries({ queryKey: workspaceKeys.getWorkspaceSshHosts(projectId) }); queryClient.invalidateQueries({ queryKey: projectKeys.getWorkspaceSshHosts(projectId) });
} }
}); });
}; };
@@ -39,7 +39,7 @@ export const useDeleteSshHost = () => {
return host; return host;
}, },
onSuccess: ({ projectId }) => { onSuccess: ({ projectId }) => {
queryClient.invalidateQueries({ queryKey: workspaceKeys.getWorkspaceSshHosts(projectId) }); queryClient.invalidateQueries({ queryKey: projectKeys.getWorkspaceSshHosts(projectId) });
} }
}); });
}; };
@@ -2,7 +2,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request"; import { apiRequest } from "@app/config/request";
import { workspaceKeys } from "../workspace/query-keys"; import { projectKeys } from "../workspace/query-keys";
import { sshHostGroupKeys } from "./queries"; import { sshHostGroupKeys } from "./queries";
import { import {
TCreateSshHostGroupDTO, TCreateSshHostGroupDTO,
@@ -20,7 +20,7 @@ export const useCreateSshHostGroup = () => {
}, },
onSuccess: ({ projectId, id }) => { onSuccess: ({ projectId, id }) => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.getWorkspaceSshHostGroups(projectId) queryKey: projectKeys.getWorkspaceSshHostGroups(projectId)
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: sshHostGroupKeys.getSshHostGroupById(id) queryKey: sshHostGroupKeys.getSshHostGroupById(id)
@@ -41,10 +41,10 @@ export const useUpdateSshHostGroup = () => {
}, },
onSuccess: ({ projectId }, { sshHostGroupId }) => { onSuccess: ({ projectId }, { sshHostGroupId }) => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.getWorkspaceSshHostGroups(projectId) queryKey: projectKeys.getWorkspaceSshHostGroups(projectId)
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.getWorkspaceSshHosts(projectId) queryKey: projectKeys.getWorkspaceSshHosts(projectId)
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: sshHostGroupKeys.getSshHostGroupById(sshHostGroupId) queryKey: sshHostGroupKeys.getSshHostGroupById(sshHostGroupId)
@@ -64,10 +64,10 @@ export const useDeleteSshHostGroup = () => {
}, },
onSuccess: ({ projectId }, { sshHostGroupId }) => { onSuccess: ({ projectId }, { sshHostGroupId }) => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.getWorkspaceSshHostGroups(projectId) queryKey: projectKeys.getWorkspaceSshHostGroups(projectId)
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.getWorkspaceSshHosts(projectId) queryKey: projectKeys.getWorkspaceSshHosts(projectId)
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: sshHostGroupKeys.getSshHostGroupById(sshHostGroupId) queryKey: sshHostGroupKeys.getSshHostGroupById(sshHostGroupId)
+1 -2
View File
@@ -7,7 +7,6 @@ export type { GetAuthTokenAPI } from "./auth/types";
export type { IncidentContact } from "./incidentContacts/types"; export type { IncidentContact } from "./incidentContacts/types";
export type { IntegrationAuth } from "./integrationAuth/types"; export type { IntegrationAuth } from "./integrationAuth/types";
export type { TCloudIntegration, TIntegration } from "./integrations/types"; export type { TCloudIntegration, TIntegration } from "./integrations/types";
export type { UserWsKeyPair } from "./keys/types";
export type { Organization } from "./organization/types"; export type { Organization } from "./organization/types";
export type { TSecretApprovalPolicy } from "./secretApproval/types"; export type { TSecretApprovalPolicy } from "./secretApproval/types";
export type { export type {
@@ -37,7 +36,7 @@ export type {
ToggleAutoCapitalizationDTO, ToggleAutoCapitalizationDTO,
UpdateEnvironmentDTO, UpdateEnvironmentDTO,
UpdateProjectDTO, UpdateProjectDTO,
Workspace, Project as Workspace,
WorkspaceEnv, WorkspaceEnv,
WorkspaceTag WorkspaceTag
} from "./workspace/types"; } from "./workspace/types";
+3 -3
View File
@@ -2,7 +2,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request"; import { apiRequest } from "@app/config/request";
import { workspaceKeys } from "../workspace"; import { projectKeys } from "../workspace";
import { userKeys } from "./query-keys"; import { userKeys } from "./query-keys";
import { AddUserToWsDTONonE2EE } from "./types"; import { AddUserToWsDTONonE2EE } from "./types";
@@ -11,14 +11,14 @@ export const useAddUserToWsNonE2EE = () => {
return useMutation<object, object, AddUserToWsDTONonE2EE>({ return useMutation<object, object, AddUserToWsDTONonE2EE>({
mutationFn: async ({ projectId, usernames, roleSlugs }) => { mutationFn: async ({ projectId, usernames, roleSlugs }) => {
const { data } = await apiRequest.post(`/api/v2/workspace/${projectId}/memberships`, { const { data } = await apiRequest.post(`/api/v1/projects/${projectId}/memberships`, {
usernames, usernames,
roleSlugs roleSlugs
}); });
return data; return data;
}, },
onSuccess: (_, { orgId, projectId }) => { onSuccess: (_, { orgId, projectId }) => {
queryClient.invalidateQueries({ queryKey: workspaceKeys.getWorkspaceUsers(projectId) }); queryClient.invalidateQueries({ queryKey: projectKeys.getWorkspaceUsers(projectId) });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: userKeys.allOrgMembershipProjectMemberships(orgId) queryKey: userKeys.allOrgMembershipProjectMemberships(orgId)
}); });
@@ -2,7 +2,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request"; import { apiRequest } from "@app/config/request";
import { workspaceKeys } from "../workspace/query-keys"; import { projectKeys } from "../workspace/query-keys";
import { workflowIntegrationKeys } from "./queries"; import { workflowIntegrationKeys } from "./queries";
import { import {
TCheckMicrosoftTeamsIntegrationInstallationStatusDTO, TCheckMicrosoftTeamsIntegrationInstallationStatusDTO,
@@ -126,7 +126,7 @@ export const useUpdateProjectWorkflowIntegrationConfig = () => {
}, },
onSuccess: (_, { workspaceId, integration }) => { onSuccess: (_, { workspaceId, integration }) => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.getWorkspaceWorkflowIntegrationConfig(workspaceId, integration) queryKey: projectKeys.getWorkspaceWorkflowIntegrationConfig(workspaceId, integration)
}); });
} }
}); });
@@ -145,7 +145,7 @@ export const useDeleteProjectWorkflowIntegration = () => {
}, },
onSuccess: (_, { projectId, integration }) => { onSuccess: (_, { projectId, integration }) => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.getWorkspaceWorkflowIntegrationConfig(projectId, integration) queryKey: projectKeys.getWorkspaceWorkflowIntegrationConfig(projectId, integration)
}); });
} }
}); });
+1 -1
View File
@@ -50,4 +50,4 @@ export {
useUpdateWsEnvironment, useUpdateWsEnvironment,
useUpgradeProject useUpgradeProject
} from "./queries"; } from "./queries";
export { workspaceKeys } from "./query-keys"; export { projectKeys } from "./query-keys";
@@ -3,7 +3,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request"; import { apiRequest } from "@app/config/request";
import { userKeys } from "../users/query-keys"; import { userKeys } from "../users/query-keys";
import { workspaceKeys as projectKeys } from "./query-keys"; import { projectKeys } from "./query-keys";
import { import {
TProjectSshConfig, TProjectSshConfig,
TUpdateProjectSshConfigDTO, TUpdateProjectSshConfigDTO,
@@ -24,7 +24,7 @@ export const useAddGroupToWorkspace = () => {
}) => { }) => {
const { const {
data: { groupMembership } data: { groupMembership }
} = await apiRequest.post(`/api/v2/workspace/${projectId}/groups/${groupId}`, { } = await apiRequest.post(`/api/v1/projects/${projectId}/groups/${groupId}`, {
role role
}); });
@@ -44,7 +44,7 @@ export const useUpdateGroupWorkspaceRole = () => {
mutationFn: async ({ groupId, projectId, roles }: TUpdateWorkspaceGroupRoleDTO) => { mutationFn: async ({ groupId, projectId, roles }: TUpdateWorkspaceGroupRoleDTO) => {
const { const {
data: { groupMembership } data: { groupMembership }
} = await apiRequest.patch(`/api/v2/workspace/${projectId}/groups/${groupId}`, { } = await apiRequest.patch(`/api/v1/projects/${projectId}/groups/${groupId}`, {
roles roles
}); });
@@ -74,7 +74,7 @@ export const useDeleteGroupFromWorkspace = () => {
}) => { }) => {
const { const {
data: { groupMembership } data: { groupMembership }
} = await apiRequest.delete(`/api/v2/workspace/${projectId}/groups/${groupId}`); } = await apiRequest.delete(`/api/v1/projects/${projectId}/groups/${groupId}`);
return groupMembership; return groupMembership;
}, },
onSuccess: (_, { projectId, username }) => { onSuccess: (_, { projectId, username }) => {
@@ -91,9 +91,9 @@ export const useDeleteGroupFromWorkspace = () => {
export const useLeaveProject = () => { export const useLeaveProject = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
return useMutation<object, object, { workspaceId: string }>({ return useMutation<object, object, { projectId: string }>({
mutationFn: ({ workspaceId }) => { mutationFn: ({ projectId }) => {
return apiRequest.delete(`/api/v1/workspace/${workspaceId}/leave`); return apiRequest.delete(`/api/v1/projects/${projectId}/leave`);
}, },
onSuccess: () => { onSuccess: () => {
queryClient.invalidateQueries({ queryKey: projectKeys.getAllUserWorkspace() }); queryClient.invalidateQueries({ queryKey: projectKeys.getAllUserWorkspace() });
@@ -118,7 +118,7 @@ export const useMigrateProjectToV3 = () => {
export const useRequestProjectAccess = () => { export const useRequestProjectAccess = () => {
return useMutation<object, object, { projectId: string; comment: string }>({ return useMutation<object, object, { projectId: string; comment: string }>({
mutationFn: ({ projectId, comment }) => { mutationFn: ({ projectId, comment }) => {
return apiRequest.post(`/api/v1/workspace/${projectId}/project-access`, { return apiRequest.post(`/api/v1/projects/${projectId}/project-access`, {
comment comment
}); });
} }
@@ -129,7 +129,7 @@ export const useUpdateProjectSshConfig = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
return useMutation<TProjectSshConfig, object, TUpdateProjectSshConfigDTO>({ return useMutation<TProjectSshConfig, object, TUpdateProjectSshConfigDTO>({
mutationFn: ({ projectId, defaultUserSshCaId, defaultHostSshCaId }) => { mutationFn: ({ projectId, defaultUserSshCaId, defaultHostSshCaId }) => {
return apiRequest.patch(`/api/v1/workspace/${projectId}/ssh-config`, { return apiRequest.patch(`/api/v1/projects/${projectId}/ssh-config`, {
defaultUserSshCaId, defaultUserSshCaId,
defaultHostSshCaId defaultHostSshCaId
}); });
+175 -190
View File
@@ -26,7 +26,7 @@ import {
ProjectWorkflowIntegrationConfig, ProjectWorkflowIntegrationConfig,
WorkflowIntegrationPlatform WorkflowIntegrationPlatform
} from "../workflowIntegrations/types"; } from "../workflowIntegrations/types";
import { workspaceKeys } from "./query-keys"; import { projectKeys } from "./query-keys";
import { import {
CreateEnvironmentDTO, CreateEnvironmentDTO,
CreateWorkspaceDTO, CreateWorkspaceDTO,
@@ -47,21 +47,19 @@ import {
UpdateEnvironmentDTO, UpdateEnvironmentDTO,
UpdatePitVersionLimitDTO, UpdatePitVersionLimitDTO,
UpdateProjectDTO, UpdateProjectDTO,
Workspace, Project,
WorkspaceEnv WorkspaceEnv
} from "./types"; } from "./types";
export const fetchWorkspaceById = async (workspaceId: string) => { export const fetchWorkspaceById = async (projectId: string) => {
const { data } = await apiRequest.get<{ workspace: Workspace }>( const { data } = await apiRequest.get<{ project: Project }>(`/api/v1/projects/${projectId}`);
`/api/v1/workspace/${workspaceId}`
);
return data.workspace; return data.project;
}; };
const fetchWorkspaceIndexStatus = async (workspaceId: string) => { const fetchWorkspaceIndexStatus = async (projectId: string) => {
const { data } = await apiRequest.get<boolean>( const { data } = await apiRequest.get<boolean>(
`/api/v3/workspaces/${workspaceId}/secrets/blind-index-status` `/api/v3/projects/${projectId}/secrets/blind-index-status`
); );
return data; return data;
@@ -69,18 +67,16 @@ const fetchWorkspaceIndexStatus = async (workspaceId: string) => {
const fetchProjectUpgradeStatus = async (projectId: string) => { const fetchProjectUpgradeStatus = async (projectId: string) => {
const { data } = await apiRequest.get<{ status: string }>( const { data } = await apiRequest.get<{ status: string }>(
`/api/v2/workspace/${projectId}/upgrade/status` `/api/v1/projects/${projectId}/upgrade/status`
); );
return data; return data;
}; };
export const fetchWorkspaceSecrets = async (workspaceId: string) => { export const fetchWorkspaceSecrets = async (projectId: string) => {
const { const {
data: { secrets } data: { secrets }
} = await apiRequest.get<{ secrets: EncryptedSecret[] }>( } = await apiRequest.get<{ secrets: EncryptedSecret[] }>(`/api/v3/projects/${projectId}/secrets`);
`/api/v3/workspaces/${workspaceId}/secrets`
);
return secrets; return secrets;
}; };
@@ -90,13 +86,13 @@ export const useUpgradeProject = () => {
return useMutation<object, object, { projectId: string; privateKey: string }>({ return useMutation<object, object, { projectId: string; privateKey: string }>({
mutationFn: ({ projectId, privateKey }) => { mutationFn: ({ projectId, privateKey }) => {
return apiRequest.post(`/api/v2/workspace/${projectId}/upgrade`, { return apiRequest.post(`/api/v1/projects/${projectId}/upgrade`, {
userPrivateKey: privateKey userPrivateKey: privateKey
}); });
}, },
onSuccess: () => { onSuccess: () => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.getAllUserWorkspace() queryKey: projectKeys.getAllUserWorkspace()
}); });
} }
}); });
@@ -108,7 +104,7 @@ export const useGetUpgradeProjectStatus = ({
refetchInterval refetchInterval
}: TGetUpgradeProjectStatusDTO) => { }: TGetUpgradeProjectStatusDTO) => {
return useQuery({ return useQuery({
queryKey: workspaceKeys.getProjectUpgradeStatus(projectId), queryKey: projectKeys.getProjectUpgradeStatus(projectId),
queryFn: () => fetchProjectUpgradeStatus(projectId), queryFn: () => fetchProjectUpgradeStatus(projectId),
enabled, enabled,
refetchInterval refetchInterval
@@ -116,39 +112,39 @@ export const useGetUpgradeProjectStatus = ({
}; };
const fetchUserWorkspaces = async (includeRoles?: boolean, type?: ProjectType | "all") => { const fetchUserWorkspaces = async (includeRoles?: boolean, type?: ProjectType | "all") => {
const { data } = await apiRequest.get<{ workspaces: Workspace[] }>("/api/v1/workspace", { const { data } = await apiRequest.get<{ projects: Project[] }>("/api/v1/projects", {
params: { params: {
includeRoles, includeRoles,
type type
} }
}); });
return data.workspaces; return data.projects;
}; };
export const useGetWorkspaceIndexStatus = (workspaceId: string) => { export const useGetWorkspaceIndexStatus = (projectId: string) => {
return useQuery({ return useQuery({
queryKey: workspaceKeys.getWorkspaceIndexStatus(workspaceId), queryKey: projectKeys.getWorkspaceIndexStatus(projectId),
queryFn: () => fetchWorkspaceIndexStatus(workspaceId), queryFn: () => fetchWorkspaceIndexStatus(projectId),
enabled: true enabled: true
}); });
}; };
export const useGetWorkspaceSecrets = (workspaceId: string) => { export const useGetWorkspaceSecrets = (projectId: string) => {
return useQuery({ return useQuery({
queryKey: workspaceKeys.getWorkspaceSecrets(workspaceId), queryKey: projectKeys.getWorkspaceSecrets(projectId),
queryFn: () => fetchWorkspaceSecrets(workspaceId), queryFn: () => fetchWorkspaceSecrets(projectId),
enabled: true enabled: true
}); });
}; };
export const useGetWorkspaceById = ( export const useGetWorkspaceById = (
workspaceId: string, projectId: string,
dto?: { refetchInterval?: number | false } dto?: { refetchInterval?: number | false }
) => { ) => {
return useQuery({ return useQuery({
queryKey: workspaceKeys.getWorkspaceById(workspaceId), queryKey: projectKeys.getWorkspaceById(projectId),
queryFn: () => fetchWorkspaceById(workspaceId), queryFn: () => fetchWorkspaceById(projectId),
enabled: Boolean(workspaceId), enabled: Boolean(projectId),
refetchInterval: dto?.refetchInterval refetchInterval: dto?.refetchInterval
}); });
}; };
@@ -161,19 +157,19 @@ export const useGetUserWorkspaces = ({
options?: { enabled?: boolean }; options?: { enabled?: boolean };
} = {}) => } = {}) =>
useQuery({ useQuery({
queryKey: workspaceKeys.getAllUserWorkspace(), queryKey: projectKeys.getAllUserWorkspace(),
queryFn: () => fetchUserWorkspaces(includeRoles), queryFn: () => fetchUserWorkspaces(includeRoles),
...options ...options
}); });
export const useSearchProjects = ({ options, ...dto }: TSearchProjectsDTO) => export const useSearchProjects = ({ options, ...dto }: TSearchProjectsDTO) =>
useQuery({ useQuery({
queryKey: workspaceKeys.searchWorkspace(dto), queryKey: projectKeys.searchWorkspace(dto),
queryFn: async () => { queryFn: async () => {
const { data } = await apiRequest.post<{ const { data } = await apiRequest.post<{
projects: (Workspace & { isMember: boolean })[]; projects: (Project & { isMember: boolean })[];
totalCount: number; totalCount: number;
}>("/api/v1/workspace/search", dto); }>("/api/v1/projects/search", dto);
return data; return data;
}, },
@@ -181,17 +177,17 @@ export const useSearchProjects = ({ options, ...dto }: TSearchProjectsDTO) =>
}); });
const fetchUserWorkspaceMemberships = async (orgId: string) => { const fetchUserWorkspaceMemberships = async (orgId: string) => {
const { data } = await apiRequest.get<Record<string, Workspace[]>>( const { data } = await apiRequest.get<Record<string, Project[]>>(
`/api/v1/organization/${orgId}/workspace-memberships` `/api/v1/organization/${orgId}/project-memberships`
); );
return data; return data;
}; };
// to get all userids in an org with the workspace they are part of // to get all userids in an org with the project they are part of
export const useGetUserWorkspaceMemberships = (orgId: string) => export const useGetUserWorkspaceMemberships = (orgId: string) =>
useQuery({ useQuery({
queryKey: workspaceKeys.getWorkspaceMemberships(orgId), queryKey: projectKeys.getWorkspaceMemberships(orgId),
queryFn: () => fetchUserWorkspaceMemberships(orgId), queryFn: () => fetchUserWorkspaceMemberships(orgId),
enabled: Boolean(orgId) enabled: Boolean(orgId)
}); });
@@ -200,62 +196,62 @@ export const useNameWorkspaceSecrets = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
return useMutation<object, object, NameWorkspaceSecretsDTO>({ return useMutation<object, object, NameWorkspaceSecretsDTO>({
mutationFn: async ({ workspaceId, secretsToUpdate }) => mutationFn: async ({ projectId, secretsToUpdate }) =>
apiRequest.post(`/api/v3/workspaces/${workspaceId}/secrets/names`, { apiRequest.post(`/api/v3/projects/${projectId}/secrets/names`, {
secretsToUpdate secretsToUpdate
}), }),
onSuccess: (_, variables) => { onSuccess: (_, variables) => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.getWorkspaceIndexStatus(variables.workspaceId) queryKey: projectKeys.getWorkspaceIndexStatus(variables.projectId)
}); });
} }
}); });
}; };
const fetchWorkspaceAuthorization = async (workspaceId: string) => { const fetchWorkspaceAuthorization = async (projectId: string) => {
const { data } = await apiRequest.get<{ authorizations: IntegrationAuth[] }>( const { data } = await apiRequest.get<{ authorizations: IntegrationAuth[] }>(
`/api/v1/workspace/${workspaceId}/authorizations` `/api/v1/projects/${projectId}/authorizations`
); );
return data.authorizations; return data.authorizations;
}; };
export const useGetWorkspaceAuthorizations = <TData = IntegrationAuth[],>( export const useGetWorkspaceAuthorizations = <TData = IntegrationAuth[],>(
workspaceId: string, projectId: string,
select?: (data: IntegrationAuth[]) => TData select?: (data: IntegrationAuth[]) => TData
) => ) =>
useQuery({ useQuery({
queryKey: workspaceKeys.getWorkspaceAuthorization(workspaceId), queryKey: projectKeys.getWorkspaceAuthorization(projectId),
queryFn: () => fetchWorkspaceAuthorization(workspaceId), queryFn: () => fetchWorkspaceAuthorization(projectId),
enabled: Boolean(workspaceId), enabled: Boolean(projectId),
select select
}); });
export const fetchWorkspaceIntegrations = async (workspaceId: string) => { export const fetchWorkspaceIntegrations = async (projectId: string) => {
const { data } = await apiRequest.get<{ integrations: TIntegration[] }>( const { data } = await apiRequest.get<{ integrations: TIntegration[] }>(
`/api/v1/workspace/${workspaceId}/integrations` `/api/v1/projects/${projectId}/integrations`
); );
return data.integrations; return data.integrations;
}; };
export const useGetWorkspaceIntegrations = (workspaceId: string) => export const useGetWorkspaceIntegrations = (projectId: string) =>
useQuery({ useQuery({
queryKey: workspaceKeys.getWorkspaceIntegrations(workspaceId), queryKey: projectKeys.getWorkspaceIntegrations(projectId),
queryFn: () => fetchWorkspaceIntegrations(workspaceId), queryFn: () => fetchWorkspaceIntegrations(projectId),
enabled: Boolean(workspaceId), enabled: Boolean(projectId),
refetchInterval: 4000 refetchInterval: 4000
}); });
export const createWorkspace = ( export const createWorkspace = (
dto: CreateWorkspaceDTO dto: CreateWorkspaceDTO
): Promise<{ data: { project: Workspace } }> => { ): Promise<{ data: { project: Project } }> => {
return apiRequest.post("/api/v2/workspace", dto); return apiRequest.post("/api/v1/projects", dto);
}; };
export const useCreateWorkspace = () => { export const useCreateWorkspace = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
return useMutation<{ data: { project: Workspace } }, object, CreateWorkspaceDTO>({ return useMutation<{ data: { project: Project } }, object, CreateWorkspaceDTO>({
mutationFn: async ({ projectName, projectDescription, kmsKeyId, template, type }) => mutationFn: async ({ projectName, projectDescription, kmsKeyId, template, type }) =>
createWorkspace({ createWorkspace({
projectName, projectName,
@@ -266,7 +262,7 @@ export const useCreateWorkspace = () => {
}), }),
onSuccess: () => { onSuccess: () => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.getAllUserWorkspace() queryKey: projectKeys.getAllUserWorkspace()
}); });
} }
}); });
@@ -275,7 +271,7 @@ export const useCreateWorkspace = () => {
export const useUpdateProject = () => { export const useUpdateProject = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
return useMutation<Workspace, object, UpdateProjectDTO>({ return useMutation<Project, object, UpdateProjectDTO>({
mutationFn: async ({ mutationFn: async ({
projectID, projectID,
newProjectName, newProjectName,
@@ -285,8 +281,8 @@ export const useUpdateProject = () => {
showSnapshotsLegacy, showSnapshotsLegacy,
secretDetectionIgnoreValues secretDetectionIgnoreValues
}) => { }) => {
const { data } = await apiRequest.patch<{ workspace: Workspace }>( const { data } = await apiRequest.patch<{ project: Project }>(
`/api/v1/workspace/${projectID}`, `/api/v1/projects/${projectID}`,
{ {
name: newProjectName, name: newProjectName,
description: newProjectDescription, description: newProjectDescription,
@@ -296,10 +292,10 @@ export const useUpdateProject = () => {
secretDetectionIgnoreValues secretDetectionIgnoreValues
} }
); );
return data.workspace; return data.project;
}, },
onSuccess: () => { onSuccess: () => {
queryClient.invalidateQueries({ queryKey: workspaceKeys.getAllUserWorkspace() }); queryClient.invalidateQueries({ queryKey: projectKeys.getAllUserWorkspace() });
} }
}); });
}; };
@@ -307,18 +303,18 @@ export const useUpdateProject = () => {
export const useToggleAutoCapitalization = () => { export const useToggleAutoCapitalization = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
return useMutation<Workspace, object, ToggleAutoCapitalizationDTO>({ return useMutation<Project, object, ToggleAutoCapitalizationDTO>({
mutationFn: async ({ workspaceID, state }) => { mutationFn: async ({ projectID, state }) => {
const { data } = await apiRequest.post<{ workspace: Workspace }>( const { data } = await apiRequest.post<{ project: Project }>(
`/api/v1/workspace/${workspaceID}/auto-capitalization`, `/api/v1/projects/${projectID}/auto-capitalization`,
{ {
autoCapitalization: state autoCapitalization: state
} }
); );
return data.workspace; return data.project;
}, },
onSuccess: () => { onSuccess: () => {
queryClient.invalidateQueries({ queryKey: workspaceKeys.getAllUserWorkspace() }); queryClient.invalidateQueries({ queryKey: projectKeys.getAllUserWorkspace() });
} }
}); });
}; };
@@ -326,18 +322,18 @@ export const useToggleAutoCapitalization = () => {
export const useToggleDeleteProjectProtection = () => { export const useToggleDeleteProjectProtection = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
return useMutation<Workspace, object, ToggleDeleteProjectProtectionDTO>({ return useMutation<Project, object, ToggleDeleteProjectProtectionDTO>({
mutationFn: async ({ workspaceID, state }) => { mutationFn: async ({ projectID, state }) => {
const { data } = await apiRequest.post<{ workspace: Workspace }>( const { data } = await apiRequest.post<{ project: Project }>(
`/api/v1/workspace/${workspaceID}/delete-protection`, `/api/v1/projects/${projectID}/delete-protection`,
{ {
hasDeleteProtection: state hasDeleteProtection: state
} }
); );
return data.workspace; return data.project;
}, },
onSuccess: () => { onSuccess: () => {
queryClient.invalidateQueries({ queryKey: workspaceKeys.getAllUserWorkspace() }); queryClient.invalidateQueries({ queryKey: projectKeys.getAllUserWorkspace() });
} }
}); });
}; };
@@ -345,15 +341,15 @@ export const useToggleDeleteProjectProtection = () => {
export const useUpdateWorkspaceVersionLimit = () => { export const useUpdateWorkspaceVersionLimit = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
return useMutation<Workspace, object, UpdatePitVersionLimitDTO>({ return useMutation<Project, object, UpdatePitVersionLimitDTO>({
mutationFn: async ({ projectSlug, pitVersionLimit }) => { mutationFn: async ({ projectSlug, pitVersionLimit }) => {
const { data } = await apiRequest.put(`/api/v1/workspace/${projectSlug}/version-limit`, { const { data } = await apiRequest.put(`/api/v1/projects/${projectSlug}/version-limit`, {
pitVersionLimit pitVersionLimit
}); });
return data.workspace; return data.project;
}, },
onSuccess: () => { onSuccess: () => {
queryClient.invalidateQueries({ queryKey: workspaceKeys.getAllUserWorkspace() }); queryClient.invalidateQueries({ queryKey: projectKeys.getAllUserWorkspace() });
} }
}); });
}; };
@@ -361,18 +357,18 @@ export const useUpdateWorkspaceVersionLimit = () => {
export const useUpdateWorkspaceAuditLogsRetention = () => { export const useUpdateWorkspaceAuditLogsRetention = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
return useMutation<Workspace, object, UpdateAuditLogsRetentionDTO>({ return useMutation<Project, object, UpdateAuditLogsRetentionDTO>({
mutationFn: async ({ projectSlug, auditLogsRetentionDays }) => { mutationFn: async ({ projectSlug, auditLogsRetentionDays }) => {
const { data } = await apiRequest.put( const { data } = await apiRequest.put(
`/api/v1/workspace/${projectSlug}/audit-logs-retention`, `/api/v1/projects/${projectSlug}/audit-logs-retention`,
{ {
auditLogsRetentionDays auditLogsRetentionDays
} }
); );
return data.workspace; return data.project;
}, },
onSuccess: () => { onSuccess: () => {
queryClient.invalidateQueries({ queryKey: workspaceKeys.getAllUserWorkspace() }); queryClient.invalidateQueries({ queryKey: projectKeys.getAllUserWorkspace() });
} }
}); });
}; };
@@ -380,13 +376,13 @@ export const useUpdateWorkspaceAuditLogsRetention = () => {
export const useDeleteWorkspace = () => { export const useDeleteWorkspace = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
return useMutation<Workspace, object, DeleteWorkspaceDTO>({ return useMutation<Project, object, DeleteWorkspaceDTO>({
mutationFn: async ({ workspaceID }) => { mutationFn: async ({ projectID }) => {
const { data } = await apiRequest.delete(`/api/v1/workspace/${workspaceID}`); const { data } = await apiRequest.delete(`/api/v1/projects/${projectID}`);
return data.workspace; return data.project;
}, },
onSuccess: () => { onSuccess: () => {
queryClient.invalidateQueries({ queryKey: workspaceKeys.getAllUserWorkspace() }); queryClient.invalidateQueries({ queryKey: projectKeys.getAllUserWorkspace() });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: ["org-admin-projects"] queryKey: ["org-admin-projects"]
}); });
@@ -398,9 +394,9 @@ export const useCreateWsEnvironment = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
return useMutation<WorkspaceEnv, WorkspaceEnv, CreateEnvironmentDTO>({ return useMutation<WorkspaceEnv, WorkspaceEnv, CreateEnvironmentDTO>({
mutationFn: async ({ workspaceId, name, slug }) => { mutationFn: async ({ projectId, name, slug }) => {
const { data } = await apiRequest.post<{ environment: WorkspaceEnv }>( const { data } = await apiRequest.post<{ environment: WorkspaceEnv }>(
`/api/v1/workspace/${workspaceId}/environments`, `/api/v1/projects/${projectId}/environments`,
{ {
name, name,
slug slug
@@ -410,7 +406,7 @@ export const useCreateWsEnvironment = () => {
}, },
onSuccess: () => { onSuccess: () => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.getAllUserWorkspace() queryKey: projectKeys.getAllUserWorkspace()
}); });
} }
}); });
@@ -420,8 +416,8 @@ export const useUpdateWsEnvironment = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
return useMutation<object, object, UpdateEnvironmentDTO>({ return useMutation<object, object, UpdateEnvironmentDTO>({
mutationFn: ({ workspaceId, id, name, slug, position }) => { mutationFn: ({ projectId, id, name, slug, position }) => {
return apiRequest.patch(`/api/v1/workspace/${workspaceId}/environments/${id}`, { return apiRequest.patch(`/api/v1/projects/${projectId}/environments/${id}`, {
name, name,
slug, slug,
position position
@@ -429,7 +425,7 @@ export const useUpdateWsEnvironment = () => {
}, },
onSuccess: () => { onSuccess: () => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.getAllUserWorkspace() queryKey: projectKeys.getAllUserWorkspace()
}); });
} }
}); });
@@ -439,57 +435,54 @@ export const useDeleteWsEnvironment = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
return useMutation<object, object, DeleteEnvironmentDTO>({ return useMutation<object, object, DeleteEnvironmentDTO>({
mutationFn: ({ id, workspaceId }) => { mutationFn: ({ id, projectId }) => {
return apiRequest.delete(`/api/v1/workspace/${workspaceId}/environments/${id}`); return apiRequest.delete(`/api/v1/projects/${projectId}/environments/${id}`);
}, },
onSuccess: () => { onSuccess: () => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.getAllUserWorkspace() queryKey: projectKeys.getAllUserWorkspace()
}); });
} }
}); });
}; };
export const useGetWorkspaceUsers = ( export const useGetWorkspaceUsers = (
workspaceId: string, projectId: string,
includeGroupMembers?: boolean, includeGroupMembers?: boolean,
roles?: string[] roles?: string[]
) => { ) => {
return useQuery({ return useQuery({
queryKey: workspaceKeys.getWorkspaceUsers(workspaceId, includeGroupMembers, roles), queryKey: projectKeys.getWorkspaceUsers(projectId, includeGroupMembers, roles),
queryFn: async () => { queryFn: async () => {
const { const {
data: { users } data: { users }
} = await apiRequest.get<{ users: TWorkspaceUser[] }>( } = await apiRequest.get<{ users: TWorkspaceUser[] }>(`/api/v1/projects/${projectId}/users`, {
`/api/v1/workspace/${workspaceId}/users`, params: {
{ includeGroupMembers,
params: { roles:
includeGroupMembers, roles && roles.length > 0
roles: ? roles.map((role) => encodeURIComponent(role)).join(",")
roles && roles.length > 0 : undefined
? roles.map((role) => encodeURIComponent(role)).join(",")
: undefined
}
} }
); });
return users; return users;
}, },
enabled: true enabled: true
}); });
}; };
export const useGetWorkspaceUserDetails = (workspaceId: string, membershipId: string) => { export const useGetWorkspaceUserDetails = (projectId: string, membershipId: string) => {
return useQuery({ return useQuery({
queryKey: workspaceKeys.getWorkspaceUserDetails(workspaceId, membershipId), queryKey: projectKeys.getWorkspaceUserDetails(projectId, membershipId),
queryFn: async () => { queryFn: async () => {
const { const {
data: { membership } data: { membership }
} = await apiRequest.get<{ membership: TWorkspaceUser }>( } = await apiRequest.get<{ membership: TWorkspaceUser }>(
`/api/v1/workspace/${workspaceId}/memberships/${membershipId}` `/api/v1/projects/${projectId}/memberships/${membershipId}`
); );
return membership; return membership;
}, },
enabled: Boolean(workspaceId) && Boolean(membershipId) enabled: Boolean(projectId) && Boolean(membershipId)
}); });
}; };
@@ -499,21 +492,21 @@ export const useDeleteUserFromWorkspace = () => {
return useMutation({ return useMutation({
mutationFn: async ({ mutationFn: async ({
usernames, usernames,
workspaceId projectId
}: { }: {
workspaceId: string; projectId: string;
usernames: string[]; usernames: string[];
orgId: string; orgId: string;
}) => { }) => {
const { const {
data: { deletedMembership } data: { deletedMembership }
} = await apiRequest.delete(`/api/v2/workspace/${workspaceId}/memberships`, { } = await apiRequest.delete(`/api/v1/projects/${projectId}/memberships`, {
data: { usernames } data: { usernames }
}); });
return deletedMembership; return deletedMembership;
}, },
onSuccess: (_, { orgId, workspaceId }) => { onSuccess: (_, { orgId, projectId }) => {
queryClient.invalidateQueries({ queryKey: workspaceKeys.getWorkspaceUsers(workspaceId) }); queryClient.invalidateQueries({ queryKey: projectKeys.getWorkspaceUsers(projectId) });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: userKeys.allOrgMembershipProjectMemberships(orgId) queryKey: userKeys.allOrgMembershipProjectMemberships(orgId)
}); });
@@ -524,21 +517,21 @@ export const useDeleteUserFromWorkspace = () => {
export const useUpdateUserWorkspaceRole = () => { export const useUpdateUserWorkspaceRole = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
return useMutation({ return useMutation({
mutationFn: async ({ membershipId, roles, workspaceId }: TUpdateWorkspaceUserRoleDTO) => { mutationFn: async ({ membershipId, roles, projectId }: TUpdateWorkspaceUserRoleDTO) => {
const { const {
data: { membership } data: { membership }
} = await apiRequest.patch<{ membership: { projectId: string } }>( } = await apiRequest.patch<{ membership: { projectId: string } }>(
`/api/v1/workspace/${workspaceId}/memberships/${membershipId}`, `/api/v1/projects/${projectId}/memberships/${membershipId}`,
{ {
roles roles
} }
); );
return membership; return membership;
}, },
onSuccess: (_, { workspaceId, membershipId }) => { onSuccess: (_, { projectId, membershipId }) => {
queryClient.invalidateQueries({ queryKey: workspaceKeys.getWorkspaceUsers(workspaceId) }); queryClient.invalidateQueries({ queryKey: projectKeys.getWorkspaceUsers(projectId) });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.getWorkspaceUserDetails(workspaceId, membershipId) queryKey: projectKeys.getWorkspaceUserDetails(projectId, membershipId)
}); });
} }
}); });
@@ -549,17 +542,17 @@ export const useAddIdentityToWorkspace = () => {
return useMutation({ return useMutation({
mutationFn: async ({ mutationFn: async ({
identityId, identityId,
workspaceId, projectId,
role role
}: { }: {
identityId: string; identityId: string;
workspaceId: string; projectId: string;
role?: string; role?: string;
}) => { }) => {
const { const {
data: { identityMembership } data: { identityMembership }
} = await apiRequest.post( } = await apiRequest.post(
`/api/v2/workspace/${workspaceId}/identity-memberships/${identityId}`, `/api/v1/projects/${projectId}/identity-memberships/${identityId}`,
{ {
role role
} }
@@ -567,9 +560,9 @@ export const useAddIdentityToWorkspace = () => {
return identityMembership; return identityMembership;
}, },
onSuccess: (_, { identityId, workspaceId }) => { onSuccess: (_, { identityId, projectId }) => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.getWorkspaceIdentityMemberships(workspaceId) queryKey: projectKeys.getWorkspaceIdentityMemberships(projectId)
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: identitiesKeys.getIdentityProjectMemberships(identityId) queryKey: identitiesKeys.getIdentityProjectMemberships(identityId)
@@ -581,11 +574,11 @@ export const useAddIdentityToWorkspace = () => {
export const useUpdateIdentityWorkspaceRole = () => { export const useUpdateIdentityWorkspaceRole = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
return useMutation({ return useMutation({
mutationFn: async ({ identityId, workspaceId, roles }: TUpdateWorkspaceIdentityRoleDTO) => { mutationFn: async ({ identityId, projectId, roles }: TUpdateWorkspaceIdentityRoleDTO) => {
const { const {
data: { identityMembership } data: { identityMembership }
} = await apiRequest.patch( } = await apiRequest.patch(
`/api/v2/workspace/${workspaceId}/identity-memberships/${identityId}`, `/api/v1/projects/${projectId}/identity-memberships/${identityId}`,
{ {
roles roles
} }
@@ -593,15 +586,15 @@ export const useUpdateIdentityWorkspaceRole = () => {
return identityMembership; return identityMembership;
}, },
onSuccess: (_, { identityId, workspaceId }) => { onSuccess: (_, { identityId, projectId }) => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.getWorkspaceIdentityMemberships(workspaceId) queryKey: projectKeys.getWorkspaceIdentityMemberships(projectId)
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: identitiesKeys.getIdentityProjectMemberships(identityId) queryKey: identitiesKeys.getIdentityProjectMemberships(identityId)
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.getWorkspaceIdentityMembershipDetails(workspaceId, identityId) queryKey: projectKeys.getWorkspaceIdentityMembershipDetails(projectId, identityId)
}); });
} }
}); });
@@ -610,23 +603,17 @@ export const useUpdateIdentityWorkspaceRole = () => {
export const useDeleteIdentityFromWorkspace = () => { export const useDeleteIdentityFromWorkspace = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
return useMutation({ return useMutation({
mutationFn: async ({ mutationFn: async ({ identityId, projectId }: { identityId: string; projectId: string }) => {
identityId,
workspaceId
}: {
identityId: string;
workspaceId: string;
}) => {
const { const {
data: { identityMembership } data: { identityMembership }
} = await apiRequest.delete( } = await apiRequest.delete(
`/api/v2/workspace/${workspaceId}/identity-memberships/${identityId}` `/api/v1/projects/${projectId}/identity-memberships/${identityId}`
); );
return identityMembership; return identityMembership;
}, },
onSuccess: (_, { identityId, workspaceId }) => { onSuccess: (_, { identityId, projectId }) => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: workspaceKeys.getWorkspaceIdentityMemberships(workspaceId) queryKey: projectKeys.getWorkspaceIdentityMemberships(projectId)
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: identitiesKeys.getIdentityProjectMemberships(identityId) queryKey: identitiesKeys.getIdentityProjectMemberships(identityId)
@@ -637,7 +624,7 @@ export const useDeleteIdentityFromWorkspace = () => {
export const useGetWorkspaceIdentityMemberships = ( export const useGetWorkspaceIdentityMemberships = (
{ {
workspaceId, projectId,
offset = 0, offset = 0,
limit = 100, limit = 100,
orderBy = ProjectIdentityOrderBy.Name, orderBy = ProjectIdentityOrderBy.Name,
@@ -649,14 +636,14 @@ export const useGetWorkspaceIdentityMemberships = (
TProjectIdentitiesList, TProjectIdentitiesList,
unknown, unknown,
TProjectIdentitiesList, TProjectIdentitiesList,
ReturnType<typeof workspaceKeys.getWorkspaceIdentityMembershipsWithParams> ReturnType<typeof projectKeys.getWorkspaceIdentityMembershipsWithParams>
>, >,
"queryKey" | "queryFn" "queryKey" | "queryFn"
> >
) => { ) => {
return useQuery({ return useQuery({
queryKey: workspaceKeys.getWorkspaceIdentityMembershipsWithParams({ queryKey: projectKeys.getWorkspaceIdentityMembershipsWithParams({
workspaceId, projectId,
offset, offset,
limit, limit,
orderBy, orderBy,
@@ -673,7 +660,7 @@ export const useGetWorkspaceIdentityMemberships = (
}); });
const { data } = await apiRequest.get<TProjectIdentitiesList>( const { data } = await apiRequest.get<TProjectIdentitiesList>(
`/api/v2/workspace/${workspaceId}/identity-memberships`, `/api/v1/projects/${projectId}/identity-memberships`,
{ params } { params }
); );
return data; return data;
@@ -686,12 +673,12 @@ export const useGetWorkspaceIdentityMemberships = (
export const useGetWorkspaceIdentityMembershipDetails = (projectId: string, identityId: string) => { export const useGetWorkspaceIdentityMembershipDetails = (projectId: string, identityId: string) => {
return useQuery({ return useQuery({
enabled: Boolean(projectId && identityId), enabled: Boolean(projectId && identityId),
queryKey: workspaceKeys.getWorkspaceIdentityMembershipDetails(projectId, identityId), queryKey: projectKeys.getWorkspaceIdentityMembershipDetails(projectId, identityId),
queryFn: async () => { queryFn: async () => {
const { const {
data: { identityMembership } data: { identityMembership }
} = await apiRequest.get<{ identityMembership: IdentityMembership }>( } = await apiRequest.get<{ identityMembership: IdentityMembership }>(
`/api/v2/workspace/${projectId}/identity-memberships/${identityId}` `/api/v1/projects/${projectId}/identity-memberships/${identityId}`
); );
return identityMembership; return identityMembership;
} }
@@ -701,12 +688,12 @@ export const useGetWorkspaceIdentityMembershipDetails = (projectId: string, iden
export const useGetWorkspaceGroupMembershipDetails = (projectId: string, groupId: string) => { export const useGetWorkspaceGroupMembershipDetails = (projectId: string, groupId: string) => {
return useQuery({ return useQuery({
enabled: Boolean(projectId && groupId), enabled: Boolean(projectId && groupId),
queryKey: workspaceKeys.getWorkspaceGroupMembershipDetails(projectId, groupId), queryKey: projectKeys.getWorkspaceGroupMembershipDetails(projectId, groupId),
queryFn: async () => { queryFn: async () => {
const { const {
data: { groupMembership } data: { groupMembership }
} = await apiRequest.get<{ groupMembership: TGroupMembership }>( } = await apiRequest.get<{ groupMembership: TGroupMembership }>(
`/api/v2/workspace/${projectId}/groups/${groupId}` `/api/v1/projects/${projectId}/groups/${groupId}`
); );
return groupMembership; return groupMembership;
} }
@@ -715,12 +702,12 @@ export const useGetWorkspaceGroupMembershipDetails = (projectId: string, groupId
export const useListWorkspaceGroups = (projectId: string) => { export const useListWorkspaceGroups = (projectId: string) => {
return useQuery({ return useQuery({
queryKey: workspaceKeys.getWorkspaceGroupMemberships(projectId), queryKey: projectKeys.getWorkspaceGroupMemberships(projectId),
queryFn: async () => { queryFn: async () => {
const { const {
data: { groupMemberships } data: { groupMemberships }
} = await apiRequest.get<{ groupMemberships: TGroupMembership[] }>( } = await apiRequest.get<{ groupMemberships: TGroupMembership[] }>(
`/api/v2/workspace/${projectId}/groups` `/api/v1/projects/${projectId}/groups`
); );
return groupMemberships; return groupMemberships;
}, },
@@ -736,7 +723,7 @@ export const useListWorkspaceCas = ({
status?: CaStatus; status?: CaStatus;
}) => { }) => {
return useQuery({ return useQuery({
queryKey: workspaceKeys.specificWorkspaceCas({ queryKey: projectKeys.specificWorkspaceCas({
projectSlug, projectSlug,
status status
}), }),
@@ -748,7 +735,7 @@ export const useListWorkspaceCas = ({
const { const {
data: { cas } data: { cas }
} = await apiRequest.get<{ cas: TCertificateAuthority[] }>( } = await apiRequest.get<{ cas: TCertificateAuthority[] }>(
`/api/v2/workspace/${projectSlug}/cas`, `/api/v1/projects/${projectSlug}/cas`,
{ {
params params
} }
@@ -769,7 +756,7 @@ export const useListWorkspaceCertificates = ({
limit: number; limit: number;
}) => { }) => {
return useQuery({ return useQuery({
queryKey: workspaceKeys.specificWorkspaceCertificates({ queryKey: projectKeys.specificWorkspaceCertificates({
slug: projectSlug, slug: projectSlug,
offset, offset,
limit limit
@@ -783,7 +770,7 @@ export const useListWorkspaceCertificates = ({
const { const {
data: { certificates, totalCount } data: { certificates, totalCount }
} = await apiRequest.get<{ certificates: TCertificate[]; totalCount: number }>( } = await apiRequest.get<{ certificates: TCertificate[]; totalCount: number }>(
`/api/v2/workspace/${projectSlug}/certificates`, `/api/v1/projects/${projectSlug}/certificates`,
{ {
params params
} }
@@ -795,51 +782,49 @@ export const useListWorkspaceCertificates = ({
}); });
}; };
export const useListWorkspacePkiAlerts = ({ workspaceId }: { workspaceId: string }) => { export const useListWorkspacePkiAlerts = ({ projectId }: { projectId: string }) => {
return useQuery({ return useQuery({
queryKey: workspaceKeys.getWorkspacePkiAlerts(workspaceId), queryKey: projectKeys.getWorkspacePkiAlerts(projectId),
queryFn: async () => { queryFn: async () => {
const { const {
data: { alerts } data: { alerts }
} = await apiRequest.get<{ alerts: TPkiAlert[] }>( } = await apiRequest.get<{ alerts: TPkiAlert[] }>(`/api/v1/projects/${projectId}/pki-alerts`);
`/api/v2/workspace/${workspaceId}/pki-alerts`
);
return { alerts }; return { alerts };
}, },
enabled: Boolean(workspaceId) enabled: Boolean(projectId)
}); });
}; };
export const useListWorkspacePkiCollections = ({ workspaceId }: { workspaceId: string }) => { export const useListWorkspacePkiCollections = ({ projectId }: { projectId: string }) => {
return useQuery({ return useQuery({
queryKey: workspaceKeys.getWorkspacePkiCollections(workspaceId), queryKey: projectKeys.getWorkspacePkiCollections(projectId),
queryFn: async () => { queryFn: async () => {
const { const {
data: { collections } data: { collections }
} = await apiRequest.get<{ collections: TPkiCollection[] }>( } = await apiRequest.get<{ collections: TPkiCollection[] }>(
`/api/v2/workspace/${workspaceId}/pki-collections` `/api/v1/projects/${projectId}/pki-collections`
); );
return { collections }; return { collections };
}, },
enabled: Boolean(workspaceId) enabled: Boolean(projectId)
}); });
}; };
export const useListWorkspaceCertificateTemplates = ({ workspaceId }: { workspaceId: string }) => { export const useListWorkspaceCertificateTemplates = ({ projectId }: { projectId: string }) => {
return useQuery({ return useQuery({
queryKey: workspaceKeys.getWorkspaceCertificateTemplates(workspaceId), queryKey: projectKeys.getWorkspaceCertificateTemplates(projectId),
queryFn: async () => { queryFn: async () => {
const { const {
data: { certificateTemplates } data: { certificateTemplates }
} = await apiRequest.get<{ certificateTemplates: TCertificateTemplate[] }>( } = await apiRequest.get<{ certificateTemplates: TCertificateTemplate[] }>(
`/api/v2/workspace/${workspaceId}/certificate-templates` `/api/v1/projects/${projectId}/certificate-templates`
); );
return { certificateTemplates }; return { certificateTemplates };
}, },
enabled: Boolean(workspaceId) enabled: Boolean(projectId)
}); });
}; };
@@ -853,7 +838,7 @@ export const useListWorkspaceSshCertificates = ({
projectId: string; projectId: string;
}) => { }) => {
return useQuery({ return useQuery({
queryKey: workspaceKeys.specificWorkspaceSshCertificates({ queryKey: projectKeys.specificWorkspaceSshCertificates({
offset, offset,
limit, limit,
projectId projectId
@@ -867,7 +852,7 @@ export const useListWorkspaceSshCertificates = ({
const { data } = await apiRequest.get<{ const { data } = await apiRequest.get<{
certificates: TSshCertificate[]; certificates: TSshCertificate[];
totalCount: number; totalCount: number;
}>(`/api/v2/workspace/${projectId}/ssh-certificates`, { }>(`/api/v1/projects/${projectId}/ssh-certificates`, {
params params
}); });
return data; return data;
@@ -878,12 +863,12 @@ export const useListWorkspaceSshCertificates = ({
export const useListWorkspaceSshCas = (projectId: string) => { export const useListWorkspaceSshCas = (projectId: string) => {
return useQuery({ return useQuery({
queryKey: workspaceKeys.getWorkspaceSshCas(projectId), queryKey: projectKeys.getWorkspaceSshCas(projectId),
queryFn: async () => { queryFn: async () => {
const { const {
data: { cas } data: { cas }
} = await apiRequest.get<{ cas: Omit<TSshCertificateAuthority, "publicKey">[] }>( } = await apiRequest.get<{ cas: Omit<TSshCertificateAuthority, "publicKey">[] }>(
`/api/v2/workspace/${projectId}/ssh-cas` `/api/v1/projects/${projectId}/ssh-cas`
); );
return cas; return cas;
}, },
@@ -893,11 +878,11 @@ export const useListWorkspaceSshCas = (projectId: string) => {
export const useListWorkspaceSshHosts = (projectId: string) => { export const useListWorkspaceSshHosts = (projectId: string) => {
return useQuery({ return useQuery({
queryKey: workspaceKeys.getWorkspaceSshHosts(projectId), queryKey: projectKeys.getWorkspaceSshHosts(projectId),
queryFn: async () => { queryFn: async () => {
const { const {
data: { hosts } data: { hosts }
} = await apiRequest.get<{ hosts: TSshHost[] }>(`/api/v2/workspace/${projectId}/ssh-hosts`); } = await apiRequest.get<{ hosts: TSshHost[] }>(`/api/v1/projects/${projectId}/ssh-hosts`);
return hosts; return hosts;
}, },
enabled: Boolean(projectId) enabled: Boolean(projectId)
@@ -906,12 +891,12 @@ export const useListWorkspaceSshHosts = (projectId: string) => {
export const useListWorkspacePkiSubscribers = (projectId: string) => { export const useListWorkspacePkiSubscribers = (projectId: string) => {
return useQuery({ return useQuery({
queryKey: workspaceKeys.getWorkspacePkiSubscribers(projectId), queryKey: projectKeys.getWorkspacePkiSubscribers(projectId),
queryFn: async () => { queryFn: async () => {
const { const {
data: { subscribers } data: { subscribers }
} = await apiRequest.get<{ subscribers: TPkiSubscriber[] }>( } = await apiRequest.get<{ subscribers: TPkiSubscriber[] }>(
`/api/v2/workspace/${projectId}/pki-subscribers` `/api/v1/projects/${projectId}/pki-subscribers`
); );
return subscribers; return subscribers;
}, },
@@ -921,12 +906,12 @@ export const useListWorkspacePkiSubscribers = (projectId: string) => {
export const useListWorkspaceSshHostGroups = (projectId: string) => { export const useListWorkspaceSshHostGroups = (projectId: string) => {
return useQuery({ return useQuery({
queryKey: workspaceKeys.getWorkspaceSshHostGroups(projectId), queryKey: projectKeys.getWorkspaceSshHostGroups(projectId),
queryFn: async () => { queryFn: async () => {
const { const {
data: { groups } data: { groups }
} = await apiRequest.get<{ groups: (TSshHostGroup & { hostCount: number })[] }>( } = await apiRequest.get<{ groups: (TSshHostGroup & { hostCount: number })[] }>(
`/api/v2/workspace/${projectId}/ssh-host-groups` `/api/v1/projects/${projectId}/ssh-host-groups`
); );
return groups; return groups;
}, },
@@ -936,10 +921,10 @@ export const useListWorkspaceSshHostGroups = (projectId: string) => {
export const useListWorkspaceSshCertificateTemplates = (projectId: string) => { export const useListWorkspaceSshCertificateTemplates = (projectId: string) => {
return useQuery({ return useQuery({
queryKey: workspaceKeys.getWorkspaceSshCertificateTemplates(projectId), queryKey: projectKeys.getWorkspaceSshCertificateTemplates(projectId),
queryFn: async () => { queryFn: async () => {
const { data } = await apiRequest.get<{ certificateTemplates: TSshCertificateTemplate[] }>( const { data } = await apiRequest.get<{ certificateTemplates: TSshCertificateTemplate[] }>(
`/api/v2/workspace/${projectId}/ssh-certificate-templates` `/api/v1/projects/${projectId}/ssh-certificate-templates`
); );
return data; return data;
}, },
@@ -948,18 +933,18 @@ export const useListWorkspaceSshCertificateTemplates = (projectId: string) => {
}; };
export const useGetWorkspaceWorkflowIntegrationConfig = ({ export const useGetWorkspaceWorkflowIntegrationConfig = ({
workspaceId, projectId,
integration integration
}: { }: {
workspaceId: string; projectId: string;
integration: WorkflowIntegrationPlatform; integration: WorkflowIntegrationPlatform;
}) => { }) => {
return useQuery({ return useQuery({
queryKey: workspaceKeys.getWorkspaceWorkflowIntegrationConfig(workspaceId, integration), queryKey: projectKeys.getWorkspaceWorkflowIntegrationConfig(projectId, integration),
queryFn: async () => { queryFn: async () => {
const { data } = await apiRequest const { data } = await apiRequest
.get<ProjectWorkflowIntegrationConfig>( .get<ProjectWorkflowIntegrationConfig>(
`/api/v1/workspace/${workspaceId}/workflow-integration-config/${integration}` `/api/v1/projects/${projectId}/workflow-integration-config/${integration}`
) )
.catch((err) => { .catch((err) => {
if (err.response.status === 404) { if (err.response.status === 404) {
@@ -971,16 +956,16 @@ export const useGetWorkspaceWorkflowIntegrationConfig = ({
return data; return data;
}, },
enabled: Boolean(workspaceId) enabled: Boolean(projectId)
}); });
}; };
export const useGetProjectSshConfig = (projectId: string) => { export const useGetProjectSshConfig = (projectId: string) => {
return useQuery({ return useQuery({
queryKey: workspaceKeys.getProjectSshConfig(projectId), queryKey: projectKeys.getProjectSshConfig(projectId),
queryFn: async () => { queryFn: async () => {
const { data } = await apiRequest.get<TProjectSshConfig>( const { data } = await apiRequest.get<TProjectSshConfig>(
`/api/v1/workspace/${projectId}/ssh-config` `/api/v1/projects/${projectId}/ssh-config`
); );
return data; return data;
+42 -46
View File
@@ -3,47 +3,44 @@ import { TListProjectIdentitiesDTO, TSearchProjectsDTO } from "@app/hooks/api/wo
import type { CaStatus } from "../ca"; import type { CaStatus } from "../ca";
import { WorkflowIntegrationPlatform } from "../workflowIntegrations/types"; import { WorkflowIntegrationPlatform } from "../workflowIntegrations/types";
export const workspaceKeys = { export const projectKeys = {
getWorkspaceById: (workspaceId: string) => ["workspaces", { workspaceId }] as const, getWorkspaceById: (projectId: string) => ["projects", { projectId }] as const,
getWorkspaceSecrets: (workspaceId: string) => [{ workspaceId }, "workspace-secrets"] as const, getWorkspaceSecrets: (projectId: string) => [{ projectId }, "project-secrets"] as const,
getWorkspaceIndexStatus: (workspaceId: string) => getWorkspaceIndexStatus: (projectId: string) => [{ projectId }, "project-index-status"] as const,
[{ workspaceId }, "workspace-index-status"] as const, getProjectUpgradeStatus: (projectId: string) => [{ projectId }, "project-upgrade-status"],
getProjectUpgradeStatus: (workspaceId: string) => [{ workspaceId }, "workspace-upgrade-status"], getWorkspaceMemberships: (orgId: string) => [{ orgId }, "project-memberships"],
getWorkspaceMemberships: (orgId: string) => [{ orgId }, "workspace-memberships"], getWorkspaceAuthorization: (projectId: string) => [{ projectId }, "project-authorizations"],
getWorkspaceAuthorization: (workspaceId: string) => [{ workspaceId }, "workspace-authorizations"], getWorkspaceIntegrations: (projectId: string) => [{ projectId }, "project-integrations"],
getWorkspaceIntegrations: (workspaceId: string) => [{ workspaceId }, "workspace-integrations"], getAllUserWorkspace: () => ["projects"] as const,
getAllUserWorkspace: () => ["workspaces"] as const, getWorkspaceAuditLogs: (projectId: string) => [{ projectId }, "project-audit-logs"] as const,
getWorkspaceAuditLogs: (workspaceId: string) =>
[{ workspaceId }, "workspace-audit-logs"] as const,
getWorkspaceUsers: ( getWorkspaceUsers: (
workspaceId: string, projectId: string,
includeGroupMembers: boolean = false, includeGroupMembers: boolean = false,
roles: string[] = [] roles: string[] = []
) => [{ workspaceId, includeGroupMembers, roles }, "workspace-users"] as const, ) => [{ projectId, includeGroupMembers, roles }, "project-users"] as const,
getWorkspaceUserDetails: (workspaceId: string, membershipId: string) => getWorkspaceUserDetails: (projectId: string, membershipId: string) =>
[{ workspaceId, membershipId }, "workspace-user-details"] as const, [{ projectId, membershipId }, "project-user-details"] as const,
getWorkspaceIdentityMemberships: (workspaceId: string) => getWorkspaceIdentityMemberships: (projectId: string) =>
[{ workspaceId }, "workspace-identity-memberships"] as const, [{ projectId }, "project-identity-memberships"] as const,
getWorkspaceIdentityMembershipDetails: (workspaceId: string, identityId: string) => getWorkspaceIdentityMembershipDetails: (projectId: string, identityId: string) =>
[{ workspaceId, identityId }, "workspace-identity-membership-details"] as const, [{ projectId, identityId }, "project-identity-membership-details"] as const,
// allows invalidation using above key without knowing params // allows invalidation using above key without knowing params
getWorkspaceIdentityMembershipsWithParams: ({ getWorkspaceIdentityMembershipsWithParams: ({
workspaceId, projectId,
...params ...params
}: TListProjectIdentitiesDTO) => }: TListProjectIdentitiesDTO) =>
[...workspaceKeys.getWorkspaceIdentityMemberships(workspaceId), params] as const, [...projectKeys.getWorkspaceIdentityMemberships(projectId), params] as const,
searchWorkspace: (dto: TSearchProjectsDTO) => ["search-projects", dto] as const, searchWorkspace: (dto: TSearchProjectsDTO) => ["search-projects", dto] as const,
getWorkspaceGroupMemberships: (workspaceId: string) => getWorkspaceGroupMemberships: (projectId: string) => [{ projectId }, "project-groups"] as const,
[{ workspaceId }, "workspace-groups"] as const, getWorkspaceGroupMembershipDetails: (projectId: string, groupId: string) =>
getWorkspaceGroupMembershipDetails: (workspaceId: string, groupId: string) => [{ projectId, groupId }, "project-group-membership-details"] as const,
[{ workspaceId, groupId }, "workspace-group-membership-details"] as const,
getWorkspaceCas: ({ projectSlug }: { projectSlug: string }) => getWorkspaceCas: ({ projectSlug }: { projectSlug: string }) =>
[{ projectSlug }, "workspace-cas"] as const, [{ projectSlug }, "project-cas"] as const,
specificWorkspaceCas: ({ projectSlug, status }: { projectSlug: string; status?: CaStatus }) => specificWorkspaceCas: ({ projectSlug, status }: { projectSlug: string; status?: CaStatus }) =>
[...workspaceKeys.getWorkspaceCas({ projectSlug }), { status }] as const, [...projectKeys.getWorkspaceCas({ projectSlug }), { status }] as const,
allWorkspaceCertificates: () => ["workspace-certificates"] as const, allWorkspaceCertificates: () => ["project-certificates"] as const,
forWorkspaceCertificates: (slug: string) => forWorkspaceCertificates: (slug: string) =>
[...workspaceKeys.allWorkspaceCertificates(), slug] as const, [...projectKeys.allWorkspaceCertificates(), slug] as const,
specificWorkspaceCertificates: ({ specificWorkspaceCertificates: ({
slug, slug,
offset, offset,
@@ -52,25 +49,24 @@ export const workspaceKeys = {
slug: string; slug: string;
offset: number; offset: number;
limit: number; limit: number;
}) => [...workspaceKeys.forWorkspaceCertificates(slug), { offset, limit }] as const, }) => [...projectKeys.forWorkspaceCertificates(slug), { offset, limit }] as const,
getWorkspacePkiAlerts: (workspaceId: string) => getWorkspacePkiAlerts: (projectId: string) => [{ projectId }, "project-pki-alerts"] as const,
[{ workspaceId }, "workspace-pki-alerts"] as const,
getWorkspacePkiSubscribers: (projectId: string) => getWorkspacePkiSubscribers: (projectId: string) =>
[{ projectId }, "workspace-pki-subscribers"] as const, [{ projectId }, "project-pki-subscribers"] as const,
getWorkspacePkiCollections: (workspaceId: string) => getWorkspacePkiCollections: (projectId: string) =>
[{ workspaceId }, "workspace-pki-collections"] as const, [{ projectId }, "project-pki-collections"] as const,
getWorkspaceCertificateTemplates: (workspaceId: string) => getWorkspaceCertificateTemplates: (projectId: string) =>
[{ workspaceId }, "workspace-certificate-templates"] as const, [{ projectId }, "project-certificate-templates"] as const,
getWorkspaceWorkflowIntegrationConfig: ( getWorkspaceWorkflowIntegrationConfig: (
workspaceId: string, projectId: string,
integration: WorkflowIntegrationPlatform integration: WorkflowIntegrationPlatform
) => [{ workspaceId, integration }, "workspace-workflow-integration-config"] as const, ) => [{ projectId, integration }, "project-workflow-integration-config"] as const,
getWorkspaceSshCas: (projectId: string) => [{ projectId }, "workspace-ssh-cas"] as const, getWorkspaceSshCas: (projectId: string) => [{ projectId }, "project-ssh-cas"] as const,
allWorkspaceSshCertificates: (projectId: string) => allWorkspaceSshCertificates: (projectId: string) =>
[{ projectId }, "workspace-ssh-certificates"] as const, [{ projectId }, "project-ssh-certificates"] as const,
getWorkspaceSshHosts: (projectId: string) => [{ projectId }, "workspace-ssh-hosts"] as const, getWorkspaceSshHosts: (projectId: string) => [{ projectId }, "project-ssh-hosts"] as const,
getWorkspaceSshHostGroups: (projectId: string) => getWorkspaceSshHostGroups: (projectId: string) =>
[{ projectId }, "workspace-ssh-host-groups"] as const, [{ projectId }, "project-ssh-host-groups"] as const,
specificWorkspaceSshCertificates: ({ specificWorkspaceSshCertificates: ({
offset, offset,
limit, limit,
@@ -79,8 +75,8 @@ export const workspaceKeys = {
offset: number; offset: number;
limit: number; limit: number;
projectId: string; projectId: string;
}) => [...workspaceKeys.allWorkspaceSshCertificates(projectId), { offset, limit }] as const, }) => [...projectKeys.allWorkspaceSshCertificates(projectId), { offset, limit }] as const,
getWorkspaceSshCertificateTemplates: (projectId: string) => getWorkspaceSshCertificateTemplates: (projectId: string) =>
[{ projectId }, "workspace-ssh-certificate-templates"] as const, [{ projectId }, "project-ssh-certificate-templates"] as const,
getProjectSshConfig: (projectId: string) => [{ projectId }, "project-ssh-config"] as const getProjectSshConfig: (projectId: string) => [{ projectId }, "project-ssh-config"] as const
}; };
+12 -12
View File
@@ -20,7 +20,7 @@ export enum ProjectUserMembershipTemporaryMode {
Relative = "relative" Relative = "relative"
} }
export type Workspace = { export type Project = {
__v: number; __v: number;
id: string; id: string;
name: string; name: string;
@@ -52,7 +52,7 @@ export type WorkspaceEnv = {
export type WorkspaceTag = { id: string; name: string; slug: string }; export type WorkspaceTag = { id: string; name: string; slug: string };
export type NameWorkspaceSecretsDTO = { export type NameWorkspaceSecretsDTO = {
workspaceId: string; projectId: string;
secretsToUpdate: { secretsToUpdate: {
secretName: string; secretName: string;
secretId: string; secretId: string;
@@ -87,19 +87,19 @@ export type UpdateProjectDTO = {
export type UpdatePitVersionLimitDTO = { projectSlug: string; pitVersionLimit: number }; export type UpdatePitVersionLimitDTO = { projectSlug: string; pitVersionLimit: number };
export type UpdateAuditLogsRetentionDTO = { projectSlug: string; auditLogsRetentionDays: number }; export type UpdateAuditLogsRetentionDTO = { projectSlug: string; auditLogsRetentionDays: number };
export type ToggleAutoCapitalizationDTO = { workspaceID: string; state: boolean }; export type ToggleAutoCapitalizationDTO = { projectID: string; state: boolean };
export type ToggleDeleteProjectProtectionDTO = { workspaceID: string; state: boolean }; export type ToggleDeleteProjectProtectionDTO = { projectID: string; state: boolean };
export type DeleteWorkspaceDTO = { workspaceID: string }; export type DeleteWorkspaceDTO = { projectID: string };
export type CreateEnvironmentDTO = { export type CreateEnvironmentDTO = {
workspaceId: string; projectId: string;
name: string; name: string;
slug: string; slug: string;
}; };
export type ReorderEnvironmentsDTO = { export type ReorderEnvironmentsDTO = {
workspaceId: string; projectId: string;
environmentSlug: string; environmentSlug: string;
environmentName: string; environmentName: string;
otherEnvironmentSlug: string; otherEnvironmentSlug: string;
@@ -107,18 +107,18 @@ export type ReorderEnvironmentsDTO = {
}; };
export type UpdateEnvironmentDTO = { export type UpdateEnvironmentDTO = {
workspaceId: string; projectId: string;
id: string; id: string;
name?: string; name?: string;
slug?: string; slug?: string;
position?: number; position?: number;
}; };
export type DeleteEnvironmentDTO = { workspaceId: string; id: string }; export type DeleteEnvironmentDTO = { projectId: string; id: string };
export type TUpdateWorkspaceUserRoleDTO = { export type TUpdateWorkspaceUserRoleDTO = {
membershipId: string; membershipId: string;
workspaceId: string; projectId: string;
roles: ( roles: (
| { | {
role: string; role: string;
@@ -136,7 +136,7 @@ export type TUpdateWorkspaceUserRoleDTO = {
export type TUpdateWorkspaceIdentityRoleDTO = { export type TUpdateWorkspaceIdentityRoleDTO = {
identityId: string; identityId: string;
workspaceId: string; projectId: string;
roles: ( roles: (
| { | {
role: string; role: string;
@@ -171,7 +171,7 @@ export type TUpdateWorkspaceGroupRoleDTO = {
}; };
export type TListProjectIdentitiesDTO = { export type TListProjectIdentitiesDTO = {
workspaceId: string; projectId: string;
offset?: number; offset?: number;
limit?: number; limit?: number;
orderBy?: ProjectIdentityOrderBy; orderBy?: ProjectIdentityOrderBy;
@@ -36,7 +36,7 @@ import { usePopUp } from "@app/hooks";
import { useGetUserWorkspaces } from "@app/hooks/api"; import { useGetUserWorkspaces } from "@app/hooks/api";
import { useUpdateUserProjectFavorites } from "@app/hooks/api/users/mutation"; import { useUpdateUserProjectFavorites } from "@app/hooks/api/users/mutation";
import { useGetUserProjectFavorites } from "@app/hooks/api/users/queries"; import { useGetUserProjectFavorites } from "@app/hooks/api/users/queries";
import { Workspace } from "@app/hooks/api/workspace/types"; import { Project } from "@app/hooks/api/workspace/types";
export const ProjectSelect = () => { export const ProjectSelect = () => {
const [searchProject, setSearchProject] = useState(""); const [searchProject, setSearchProject] = useState("");
@@ -88,7 +88,7 @@ export const ProjectSelect = () => {
const projects = useMemo(() => { const projects = useMemo(() => {
const projectOptions = workspaces const projectOptions = workspaces
.map((w): Workspace & { isFavorite: boolean } => ({ .map((w): Project & { isFavorite: boolean } => ({
...w, ...w,
isFavorite: Boolean(projectFavorites?.includes(w.id)) isFavorite: Boolean(projectFavorites?.includes(w.id))
})) }))
@@ -29,7 +29,7 @@ import {
} from "@app/hooks/api/auditLogs/constants"; } from "@app/hooks/api/auditLogs/constants";
import { EventType } from "@app/hooks/api/auditLogs/enums"; import { EventType } from "@app/hooks/api/auditLogs/enums";
import { UserAgentType } from "@app/hooks/api/auth/types"; import { UserAgentType } from "@app/hooks/api/auth/types";
import { Workspace } from "@app/hooks/api/workspace/types"; import { Project } from "@app/hooks/api/workspace/types";
import { LogFilterItem } from "./LogFilterItem"; import { LogFilterItem } from "./LogFilterItem";
import { auditLogFilterFormSchema, Presets, TAuditLogFilterFormData } from "./types"; import { auditLogFilterFormSchema, Presets, TAuditLogFilterFormData } from "./types";
@@ -44,7 +44,7 @@ type Props = {
presets?: Presets; presets?: Presets;
setFilter: (data: TAuditLogFilterFormData) => void; setFilter: (data: TAuditLogFilterFormData) => void;
filter: TAuditLogFilterFormData; filter: TAuditLogFilterFormData;
project?: Workspace; project?: Project;
}; };
const getActiveFilterCount = (filter: TAuditLogFilterFormData) => { const getActiveFilterCount = (filter: TAuditLogFilterFormData) => {
@@ -13,7 +13,7 @@ import {
} from "@app/context"; } from "@app/context";
import { Timezone } from "@app/helpers/datetime"; import { Timezone } from "@app/helpers/datetime";
import { withPermission, withProjectPermission } from "@app/hoc"; import { withPermission, withProjectPermission } from "@app/hoc";
import { Workspace } from "@app/hooks/api/workspace/types"; import { Project } from "@app/hooks/api/workspace/types";
import { usePopUp } from "@app/hooks/usePopUp"; import { usePopUp } from "@app/hooks/usePopUp";
import { LogsDateFilter } from "./LogsDateFilter"; import { LogsDateFilter } from "./LogsDateFilter";
@@ -31,7 +31,7 @@ type Props = {
refetchInterval?: number; refetchInterval?: number;
showFilters?: boolean; showFilters?: boolean;
pageView?: boolean; pageView?: boolean;
project?: Workspace; project?: Project;
}; };
const LogsSectionComponent = ({ const LogsSectionComponent = ({
@@ -48,7 +48,7 @@ import {
useRequestProjectAccess, useRequestProjectAccess,
useSearchProjects useSearchProjects
} from "@app/hooks/api"; } from "@app/hooks/api";
import { ProjectType, Workspace, WorkspaceEnv } from "@app/hooks/api/workspace/types"; import { ProjectType, Project, WorkspaceEnv } from "@app/hooks/api/workspace/types";
import { import {
ProjectListToggle, ProjectListToggle,
ProjectListView ProjectListView
@@ -180,7 +180,7 @@ export const AllProjectView = ({
offset, offset,
totalCount: searchedProjects?.totalCount || 0 totalCount: searchedProjects?.totalCount || 0
}); });
const requestedWorkspaceDetails = (popUp.requestAccessConfirmation.data || {}) as Workspace; const requestedWorkspaceDetails = (popUp.requestAccessConfirmation.data || {}) as Project;
const handleToggleFilterByProjectType = (el: ProjectType) => const handleToggleFilterByProjectType = (el: ProjectType) =>
setProjectTypeFilter((state) => (state === el ? undefined : el)); setProjectTypeFilter((state) => (state === el ? undefined : el));
@@ -43,7 +43,7 @@ import { useGetUserWorkspaces } from "@app/hooks/api";
import { OrderByDirection } from "@app/hooks/api/generic/types"; import { OrderByDirection } from "@app/hooks/api/generic/types";
import { useUpdateUserProjectFavorites } from "@app/hooks/api/users/mutation"; import { useUpdateUserProjectFavorites } from "@app/hooks/api/users/mutation";
import { useGetUserProjectFavorites } from "@app/hooks/api/users/queries"; import { useGetUserProjectFavorites } from "@app/hooks/api/users/queries";
import { ProjectType, Workspace } from "@app/hooks/api/workspace/types"; import { ProjectType, Project } from "@app/hooks/api/workspace/types";
import { import {
ProjectListToggle, ProjectListToggle,
ProjectListView ProjectListView
@@ -136,7 +136,7 @@ export const MyProjectView = ({
const { workspacesWithFaveProp } = useMemo(() => { const { workspacesWithFaveProp } = useMemo(() => {
const workspacesWithFav = filteredWorkspaces const workspacesWithFav = filteredWorkspaces
.map((w): Workspace & { isFavorite: boolean } => ({ .map((w): Project & { isFavorite: boolean } => ({
...w, ...w,
isFavorite: Boolean(projectFavorites?.includes(w.id)) isFavorite: Boolean(projectFavorites?.includes(w.id))
})) }))
@@ -188,7 +188,7 @@ export const MyProjectView = ({
} }
}; };
const renderProjectGridItem = (workspace: Workspace, isFavorite: boolean) => ( const renderProjectGridItem = (workspace: Project, isFavorite: boolean) => (
// eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events // eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events
<div <div
onClick={() => { onClick={() => {
@@ -242,7 +242,7 @@ export const MyProjectView = ({
</p> </p>
</div> </div>
); );
const renderProjectListItem = (workspace: Workspace, isFavorite: boolean, index: number) => ( const renderProjectListItem = (workspace: Project, isFavorite: boolean, index: number) => (
// eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events // eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events
<div <div
onClick={() => { onClick={() => {
@@ -120,7 +120,7 @@ export const RollbackPreviewTab = (): JSX.Element => {
] as const); ] as const);
const { mutateAsync: rollback } = useCommitRollback({ const { mutateAsync: rollback } = useCommitRollback({
workspaceId: currentWorkspace.id, projectId: currentWorkspace.id,
commitId: selectedCommitId, commitId: selectedCommitId,
folderId, folderId,
deepRollback, deepRollback,
@@ -414,7 +414,7 @@ export const SecretListView = ({
queryKey: secretSnapshotKeys.count({ workspaceId, environment, directory: secretPath }) queryKey: secretSnapshotKeys.count({ workspaceId, environment, directory: secretPath })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.count({ workspaceId, environment, directory: secretPath }) queryKey: commitKeys.count({ projectId: workspaceId, environment, directory: secretPath })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath }) queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath })
@@ -492,7 +492,7 @@ export const SecretListView = ({
queryKey: secretSnapshotKeys.count({ workspaceId, environment, directory: secretPath }) queryKey: secretSnapshotKeys.count({ workspaceId, environment, directory: secretPath })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.count({ workspaceId, environment, directory: secretPath }) queryKey: commitKeys.count({ projectId: workspaceId, environment, directory: secretPath })
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath }) queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath })