repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
keyshade
github_2023
keyshade-xyz
typescript
AuthorityCheckerService.checkAuthorityOverProject
public async checkAuthorityOverProject( input: AuthorityInput ): Promise<ProjectWithSecrets> { const { userId, entity, authorities, prisma } = input let project: ProjectWithSecrets try { if (entity.slug) { project = await prisma.project.findUnique({ where: { slug:...
/** * Checks if the user has the required authorities to access the given project. * * @param input The input object containing the userId, entity, authorities, and prisma client * @returns The project if the user has the required authorities * @throws InternalServerErrorException if there's an error whe...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/common/authority-checker.service.ts#L96-L177
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
AuthorityCheckerService.checkAuthorityOverEnvironment
public async checkAuthorityOverEnvironment( input: AuthorityInput ): Promise<EnvironmentWithProject> { const { userId, entity, authorities, prisma } = input let environment: EnvironmentWithProject try { if (entity.slug) { environment = await prisma.environment.findUnique({ wh...
/** * Checks if the user has the required authorities to access the given environment. * * @param input The input object containing the userId, entity, authorities, and prisma client * @returns The environment if the user has the required authorities * @throws InternalServerErrorException if there's an e...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/common/authority-checker.service.ts#L188-L234
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
AuthorityCheckerService.checkAuthorityOverVariable
public async checkAuthorityOverVariable( input: AuthorityInput ): Promise<VariableWithProjectAndVersion> { const { userId, entity, authorities, prisma } = input let variable: VariableWithProjectAndVersion try { if (entity.slug) { variable = await prisma.variable.findUnique({ ...
/** * Checks if the user has the required authorities to access the given variable. * * @param input The input object containing the userId, entity, authorities, and prisma client * @returns The variable if the user has the required authorities * @throws InternalServerErrorException if there's an error w...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/common/authority-checker.service.ts#L245-L293
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
AuthorityCheckerService.checkAuthorityOverSecret
public async checkAuthorityOverSecret( input: AuthorityInput ): Promise<SecretWithProjectAndVersion> { const { userId, entity, authorities, prisma } = input let secret: SecretWithProjectAndVersion try { if (entity.slug) { secret = await prisma.secret.findUnique({ where: { ...
/** * Checks if the user has the required authorities to access the given secret. * * @param input The input object containing the userId, entity, authorities, and prisma client * @returns The secret if the user has the required authorities * @throws InternalServerErrorException if there's an error when ...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/common/authority-checker.service.ts#L304-L352
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
AuthorityCheckerService.checkAuthorityOverIntegration
public async checkAuthorityOverIntegration( input: AuthorityInput ): Promise<IntegrationWithWorkspace> { const { userId, entity, authorities, prisma } = input let integration: IntegrationWithWorkspace | null try { if (entity.slug) { integration = await prisma.integration.findUnique({ ...
/** * Checks if the user has the required authorities to access the given integration. * * @param input The input object containing the userId, entity, authorities, and prisma client * @returns The integration if the user has the required authorities * @throws InternalServerErrorException if there's an e...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/common/authority-checker.service.ts#L363-L431
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
AuthorityCheckerService.checkHasPermissionOverEntity
private checkHasPermissionOverEntity( permittedAuthorities: Set<Authority>, authorities: Authority[], userId: string ): void { // We commence the check if WORKSPACE_ADMIN isn't in the list of permitted authorities if (!permittedAuthorities.has(Authority.WORKSPACE_ADMIN)) { // Check if the au...
/** * Checks if the user has all the required authorities to perform an action. * Throws UnauthorizedException if the user does not have all the required authorities. * * @param permittedAuthorities The set of authorities that the user has * @param authorities The set of authorities required to perform t...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/common/authority-checker.service.ts#L443-L461
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
getQueryString
const getQueryString = (query: QueryOptions) => { return Object.keys(query) .map((key) => `${key}=${query[key]}`) .join('&') }
//convert query object to query string to use in links
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/common/paginate.ts#L24-L28
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
sampleRateSchema
const sampleRateSchema = (name: string) => z .string() .optional() .transform((val) => (val === undefined ? undefined : parseFloat(val))) .pipe(z.number().min(0).max(1).optional()) .refine((val) => val === undefined || !isNaN(val), { message: `${name} must be a number between 0 and 1` })
/* Apparently zod validates empty strings. https://github.com/colinhacks/zod/issues/2466 So if you have your variable in the .env set to empty, zod turns a blind eye to it since it parses to VARIABLE = '' To over come this you need to set a min length (.min()) if you want zod to throw an error Zod only throws ...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/common/env/env.schema.ts#L21-L29
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
QueryTransformPipe.transform
transform(value: any, metadata: ArgumentMetadata) { if (metadata.type === 'query') { if (metadata.data === 'limit') return isNaN(value) || value === 0 ? 10 : parseInt(value) if (metadata.data === 'page') return isNaN(value) ? 0 : Number(value) } return value }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/common/pipes/query.transform.pipe.ts#L10-L17
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
EnvironmentService.createEnvironment
async createEnvironment( user: User, dto: CreateEnvironment, projectSlug: Project['slug'] ) { // Check if the user has the required role to create an environment const project = await this.authorityCheckerService.checkAuthorityOverProject({ userId: user.id, entity: { slug: pr...
/** * Creates a new environment in the given project. * * This endpoint requires the following authorities: * - `CREATE_ENVIRONMENT` on the project * - `READ_ENVIRONMENT` on the project * - `READ_PROJECT` on the project * * If the user does not have the required authorities, a `ForbiddenExceptio...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/environment/service/environment.service.ts#L58-L132
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
EnvironmentService.updateEnvironment
async updateEnvironment( user: User, dto: UpdateEnvironment, environmentSlug: Environment['slug'] ) { const environment = await this.authorityCheckerService.checkAuthorityOverEnvironment({ userId: user.id, entity: { slug: environmentSlug }, authorities: [ Author...
/** * Updates an environment in the given project. * * This endpoint requires the following authorities: * - `UPDATE_ENVIRONMENT` on the environment * - `READ_ENVIRONMENT` on the environment * - `READ_PROJECT` on the project * * If the user does not have the required authorities, a `ForbiddenExc...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/environment/service/environment.service.ts#L159-L218
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
EnvironmentService.getEnvironment
async getEnvironment(user: User, environmentSlug: Environment['slug']) { const environment = await this.authorityCheckerService.checkAuthorityOverEnvironment({ userId: user.id, entity: { slug: environmentSlug }, authorities: [Authority.READ_ENVIRONMENT], prisma: this.prisma ...
/** * Gets an environment by its slug. * * This endpoint requires the `READ_ENVIRONMENT` authority on the environment. * * If the user does not have the required authority, a `ForbiddenException` is thrown. * * The returned environment object does not include the project property. * * @param ...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/environment/service/environment.service.ts#L233-L245
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
EnvironmentService.getEnvironmentsOfProject
async getEnvironmentsOfProject( user: User, projectSlug: Project['slug'], page: number, limit: number, sort: string, order: string, search: string ) { const project = await this.authorityCheckerService.checkAuthorityOverProject({ userId: user.id, entity: { slug: p...
/** * Gets a list of all environments in the given project. * * This endpoint requires the `READ_ENVIRONMENT` authority on the project. * * If the user does not have the required authority, a `ForbiddenException` is thrown. * * The returned list of environments is paginated and sorted according to ...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/environment/service/environment.service.ts#L277-L352
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
EnvironmentService.deleteEnvironment
async deleteEnvironment(user: User, environmentSlug: Environment['slug']) { const environment = await this.authorityCheckerService.checkAuthorityOverEnvironment({ userId: user.id, entity: { slug: environmentSlug }, authorities: [Authority.DELETE_ENVIRONMENT], prisma: this.prism...
/** * Deletes an environment in a project. * * This endpoint requires the `DELETE_ENVIRONMENT` authority on the environment. * * If the user does not have the required authority, a `ForbiddenException` is thrown. * * If this is the only existing environment in the project, a `BadRequestException` i...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/environment/service/environment.service.ts#L371-L419
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
EnvironmentService.environmentExists
private async environmentExists(name: Environment['name'], project: Project) { const { id: projectId, slug } = project if ( (await this.prisma.environment.findUnique({ where: { projectId_name: { projectId, name } } })) !== null ) { ...
/** * Checks if an environment with the given name already exists in the given project. * @throws ConflictException if an environment with the given name already exists * @private */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/environment/service/environment.service.ts#L426-L443
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
EnvironmentService.getSecretCount
private async getSecretCount( environmentId: Environment['id'] ): Promise<number> { const secrets = await this.prisma.secretVersion.findMany({ distinct: ['secretId'], where: { environmentId } }) return secrets.length }
/** * Counts the number of unique secrets in an environment. * @param environmentId The ID of the environment to count secrets for. * @returns The number of unique secrets in the environment. * @private */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/environment/service/environment.service.ts#L451-L462
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
EnvironmentService.getVariableCount
private async getVariableCount( environmentId: Environment['id'] ): Promise<number> { const variables = await this.prisma.variableVersion.findMany({ distinct: ['variableId'], where: { environmentId } }) return variables.length }
/** * Counts the number of unique variables in an environment. * @param environmentId The ID of the environment to count variables for. * @returns The number of unique variables in the environment. * @private */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/environment/service/environment.service.ts#L470-L481
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
FeedbackService.registerFeedback
async registerFeedback(feedback: string): Promise<void> { if (!feedback || feedback.trim().length === 0) { throw new BadRequestException('Feedback cannot be null or empty') } const adminEmail = process.env.FEEDBACK_FORWARD_EMAIL await this.mailService.feedbackEmail(adminEmail, feedback.trim()) ...
/** * Registers a feedback to be sent to the admin's email. * @param feedback The feedback to be sent. * @throws {BadRequestException} If the feedback is null or empty. */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/feedback/service/feedback.service.ts#L15-L22
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
IntegrationFactory.createIntegration
public static createIntegration( integrationType: IntegrationType ): BaseIntegration { switch (integrationType) { case IntegrationType.DISCORD: return new DiscordIntegration() case IntegrationType.SLACK: return new SlackIntegration() default: throw new InternalServerE...
/** * Create an integration based on the integration type. * @param integrationType The type of integration to create. * @returns The integration object. */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/integration/plugins/factory/integration.factory.ts#L17-L28
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
IntegrationService.createIntegration
async createIntegration( user: User, dto: CreateIntegration, workspaceSlug: Workspace['slug'] ) { // Check if the user is permitted to create integrations in the workspace const workspace = await this.authorityCheckerService.checkAuthorityOverWorkspace({ userId: user.id, enti...
/** * Creates a new integration in the given workspace. The user needs to have * `CREATE_INTEGRATION` and `READ_WORKSPACE` authority in the workspace. * * If the integration is of type `PROJECT`, the user needs to have `READ_PROJECT` * authority in the project specified by `projectSlug`. * * If the...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/integration/service/integration.service.ts#L60-L152
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
IntegrationService.updateIntegration
async updateIntegration( user: User, dto: UpdateIntegration, integrationSlug: Integration['slug'] ) { const integration = await this.authorityCheckerService.checkAuthorityOverIntegration({ userId: user.id, entity: { slug: integrationSlug }, authorities: [Authority.UPDATE_...
/** * Updates an integration. The user needs to have `UPDATE_INTEGRATION` authority * over the integration. * * If the integration is of type `PROJECT`, the user needs to have `READ_PROJECT` * authority in the project specified by `projectSlug`. * * If the integration is of type `ENVIRONMENT`, the ...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/integration/service/integration.service.ts#L176-L272
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
IntegrationService.getIntegration
async getIntegration(user: User, integrationSlug: Integration['slug']) { return this.authorityCheckerService.checkAuthorityOverIntegration({ userId: user.id, entity: { slug: integrationSlug }, authorities: [Authority.READ_INTEGRATION], prisma: this.prisma }) }
/** * Retrieves an integration by its slug. The user needs to have `READ_INTEGRATION` * authority over the integration. * * @param user The user retrieving the integration * @param integrationSlug The slug of the integration to retrieve * @returns The integration with the given slug */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/integration/service/integration.service.ts#L282-L289
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
IntegrationService.getAllIntegrationsOfWorkspace
async getAllIntegrationsOfWorkspace( user: User, workspaceSlug: Workspace['slug'], page: number, limit: number, sort: string, order: string, search: string ) { // Check if the user has READ authority over the workspace const workspace = await this.authorityCheckerService.chec...
/** * Retrieves all integrations in a workspace that the user has READ authority over. * * The user needs to have `READ_INTEGRATION` authority over the workspace. * * The results are paginated and can be sorted by name ascending or descending. * * @param user The user retrieving the integrations ...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/integration/service/integration.service.ts#L309-L418
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
IntegrationService.deleteIntegration
async deleteIntegration(user: User, integrationSlug: Integration['slug']) { const integration = await this.authorityCheckerService.checkAuthorityOverIntegration({ userId: user.id, entity: { slug: integrationSlug }, authorities: [Authority.DELETE_INTEGRATION], prisma: this.prism...
/** * Deletes an integration by its slug. The user needs to have `DELETE_INTEGRATION` * authority over the integration. * * @param user The user deleting the integration * @param integrationSlug The slug of the integration to delete * @returns Nothing */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/integration/service/integration.service.ts#L428-L460
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
IntegrationService.existsByNameAndWorkspaceId
private async existsByNameAndWorkspaceId( name: Integration['name'], workspace: Workspace ) { const workspaceId = workspace.id if ( (await this.prisma.integration.findUnique({ where: { workspaceId_name: { workspaceId, name } } })...
/** * Checks if an integration with the same name already exists in the workspace. * Throws a ConflictException if the integration already exists. * * @param name The name of the integration to check * @param workspace The workspace to check in */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/integration/service/integration.service.ts#L469-L488
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
PrismaRepository.findUserByEmail
async findUserByEmail(email: string): Promise<User | null> { return await this.prisma.user.findUnique({ where: { email } }) }
/** * Find a user by email * @param email the email to search for * @returns the user if found, null otherwise */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/prisma/prisma.repository.ts#L14-L20
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
PrismaRepository.findUserById
async findUserById(id: string): Promise<User | null> { return await this.prisma.user.findUnique({ where: { id } }) }
/** * Find a user by the user id * @param id The id of the user to find * @returns the user if found, null otherwise */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/prisma/prisma.repository.ts#L27-L33
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
PrismaRepository.findUsers
async findUsers( page: number, limit: number, sort: string, order: string, search: string ): Promise<User[]> { return await this.prisma.user.findMany({ skip: (page - 1) * limit, take: limit, orderBy: { [sort]: order }, where: { OR: [ { ...
/** * Find all users * @param page The page number * @param limit The number of items per page * @param sort The field to sort by * @param order The order to sort by * @param search The search string * @returns The list of users */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/prisma/prisma.repository.ts#L44-L72
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
PrismaRepository.createUser
async createUser(email: string): Promise<User> { return await this.prisma.user.create({ data: { email } }) }
/** * Create a user with the given email. The onboarding process * will aim at updating the user further. * @param email The email of the user to create * @returns */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/prisma/prisma.repository.ts#L80-L86
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
PrismaRepository.updateUser
async updateUser(id: string, data: Partial<User>): Promise<User> { return await this.prisma.user.update({ where: { id }, data }) }
/** * Update an existing user * @param id ID of the user to update * @param data The data to update * @returns The updated user */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/prisma/prisma.repository.ts#L94-L101
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
PrismaRepository.deleteUser
async deleteUser(id: string): Promise<User> { return await this.prisma.user.delete({ where: { id } }) }
/** * Delete a user by id * @param id The id of the user to delete * @returns The deleted user */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/prisma/prisma.repository.ts#L108-L114
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
PrismaRepository.isOtpValid
async isOtpValid(email: string, otp: string): Promise<boolean> { const timeNow = new Date() return ( (await this.prisma.otp.count({ where: { code: otp, user: { email }, expiresAt: { gt: timeNow } } })) > 0 ...
/** * An OTP is valid if it exists, is not expired, and is associated with the given email * @param email the email against which to check the OTP * @param otp the OTP code to check * @returns returns true if the OTP is valid, false otherwise */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/prisma/prisma.repository.ts#L122-L137
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
PrismaRepository.invalidateOldOtps
private async invalidateOldOtps(email: string): Promise<void> { const user = await this.prisma.user.findUnique({ where: { email } }) if (user) { await this.prisma.otp.deleteMany({ where: { userId: user.id, expiresAt: { gte: new Date() ...
/** * Invalidate Old OTPs for a User * * This method invalidates old OTPs (One-Time Passwords) associated with a user. * It finds and deletes OTPs that belong to the user and have not expired yet. * * @param email - The email address of the user for whom old OTPs should be invalidated. * * @exam...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/prisma/prisma.repository.ts#L172-L189
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
ProjectService.createProject
async createProject( user: User, workspaceSlug: Workspace['slug'], dto: CreateProject ) { // Check if the workspace exists or not const workspace = await this.authorityCheckerService.checkAuthorityOverWorkspace({ userId: user.id, entity: { slug: workspaceSlug }, autho...
/** * Creates a new project in a workspace * * @param user The user who is creating the project * @param workspaceSlug The slug of the workspace where the project will be created * @param dto The data for the new project * @returns The newly created project */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/project/service/project.service.ts#L50-L210
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
ProjectService.updateProject
async updateProject( user: User, projectSlug: Project['slug'], dto: UpdateProject ) { // Check if the user has the authority to update the project let authority: Authority = Authority.UPDATE_PROJECT // Only admins can change the visibility of the project if (dto.accessLevel) authority = A...
/** * Updates a project. * * @param user The user who is updating the project * @param projectSlug The slug of the project to update * @param dto The data to update the project with * @returns The updated project * * @throws ConflictException If a project with the same name already exists for th...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/project/service/project.service.ts#L223-L365
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
ProjectService.forkProject
async forkProject( user: User, projectSlug: Project['slug'], forkMetadata: ForkProject ) { const project = await this.authorityCheckerService.checkAuthorityOverProject({ userId: user.id, entity: { slug: projectSlug }, authorities: [Authority.READ_PROJECT], prisma:...
/** * Forks a project. * * @param user The user who is creating the new project * @param projectSlug The slug of the project to fork * @param forkMetadata The metadata for the new project * @returns The newly forked project * * @throws ConflictException If a project with the same name already ex...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/project/service/project.service.ts#L378-L512
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
ProjectService.unlinkParentOfFork
async unlinkParentOfFork(user: User, projectSlug: Project['slug']) { const project = await this.authorityCheckerService.checkAuthorityOverProject({ userId: user.id, entity: { slug: projectSlug }, authorities: [Authority.UPDATE_PROJECT], prisma: this.prisma }) const pr...
/** * Unlinks a forked project from its parent project. * * @param user The user who is unlinking the project * @param projectSlug The slug of the project to unlink * @returns The updated project * * @throws BadRequestException If the project is not a forked project * @throws UnauthorizedExcepti...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/project/service/project.service.ts#L524-L543
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
ProjectService.syncFork
async syncFork(user: User, projectSlug: Project['slug'], hardSync: boolean) { const project = await this.authorityCheckerService.checkAuthorityOverProject({ userId: user.id, entity: { slug: projectSlug }, authorities: [Authority.UPDATE_PROJECT], prisma: this.prisma }) ...
/** * Syncs a forked project with its parent project. * * @param user The user who is syncing the project * @param projectSlug The slug of the project to sync * @param hardSync Whether to do a hard sync or not. If true, all items in the * forked project will be replaced with the items from the parent ...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/project/service/project.service.ts#L558-L602
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
ProjectService.deleteProject
async deleteProject(user: User, projectSlug: Project['slug']) { const project = await this.authorityCheckerService.checkAuthorityOverProject({ userId: user.id, entity: { slug: projectSlug }, authorities: [Authority.DELETE_PROJECT], prisma: this.prisma }) const op = [...
/** * Deletes a project. * @param user The user who is deleting the project * @param projectSlug The slug of the project to delete * * @throws UnauthorizedException If the user does not have the authority to delete the project */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/project/service/project.service.ts#L611-L663
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
ProjectService.getAllProjectForks
async getAllProjectForks( user: User, projectSlug: Project['slug'], page: number, limit: number ) { const project = await this.authorityCheckerService.checkAuthorityOverProject({ userId: user.id, entity: { slug: projectSlug }, authorities: [Authority.READ_PROJECT], ...
/** * Gets all the forks of a project. * * @param user The user who is requesting the forks * @param projectSlug The slug of the project to get forks for * @param page The page number to get the forks for * @param limit The number of forks to get per page * @returns An object with two properties: `...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/project/service/project.service.ts#L676-L722
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
ProjectService.getProject
async getProject(user: User, projectSlug: Project['slug']) { const project = await this.authorityCheckerService.checkAuthorityOverProject({ userId: user.id, entity: { slug: projectSlug }, authorities: [Authority.READ_PROJECT], prisma: this.prisma }) delete project.se...
/** * Gets a project by slug. * * @param user The user who is requesting the project * @param projectSlug The slug of the project to get * @returns The project with secrets removed * * @throws UnauthorizedException If the user does not have the authority to read the project */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/project/service/project.service.ts#L733-L748
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
ProjectService.getProjectsOfWorkspace
async getProjectsOfWorkspace( user: User, workspaceSlug: Workspace['slug'], page: number, limit: number, sort: string, order: string, search: string ) { const workspace = await this.authorityCheckerService.checkAuthorityOverWorkspace({ userId: user.id, entity: { s...
/** * Gets all the projects in a workspace that the user has access to. * * @param user The user who is requesting the projects * @param workspaceSlug The slug of the workspace to get the projects from * @param page The page number to get the projects for * @param limit The number of projects to get p...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/project/service/project.service.ts#L764-L868
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
ProjectService.projectExists
private async projectExists( projectName: string, workspaceId: Workspace['id'] ): Promise<boolean> { return ( (await this.prisma.workspaceMember.count({ where: { workspaceId, workspace: { projects: { some: { name: projectName ...
/** * Checks if a project with a given name exists in a workspace. * * @param projectName The name of the project to check * @param workspaceId The ID of the workspace to check in * @returns true if the project exists, false otherwise */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/project/service/project.service.ts#L877-L895
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
ProjectService.copyProjectData
private async copyProjectData( user: User, fromProject: { id: Project['id'] privateKey: string // Need the private key to decrypt the secrets }, toProject: { id: Project['id'] publicKey: string // Need the public key to encrypt the secrets }, // hardCopy = true: Replace e...
/** * Copies the project data from one project to another project. * * @param user The user who is performing the copy operation * @param fromProject The project from which the data is being copied * @param toProject The project to which the data is being copied * @param hardCopy If true, replace all ...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/project/service/project.service.ts#L907-L1155
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
ProjectService.updateProjectKeyPair
private async updateProjectKeyPair( project: ProjectWithSecrets, oldPrivateKey: string, storePrivateKey: boolean ) { // A new key pair can be generated only if: // - The existing private key is provided // - Or, the private key was stored const { privateKey: newPrivateKey, publicKey: newPu...
/** * Updates the key pair of a project. * * @param project The project to update * @param oldPrivateKey The old private key of the project * @param storePrivateKey Whether to store the new private key in the database * * @returns An object with three properties: * - `txs`: an array of database ...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/project/service/project.service.ts#L1169-L1233
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
uploadFile
async function uploadFile(file) { if (!isServiceLoaded) { throw new InternalServerErrorException('Minio Client has not loaded') } const fileName = `${Date.now()}-${file.originalname}` try { await minioClient.putObject( bucketName, fileName, file.bu...
// eslint-disable-next-line @typescript-eslint/no-unused-vars
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/provider/minio.provider.ts#L74-L93
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
getFileUrl
async function getFileUrl(fileName: string) { if (!isServiceLoaded) { throw new InternalServerErrorException('Minio Client has not loaded') } try { return await minioClient.presignedUrl('GET', bucketName, fileName) } catch (error) { logger.error('Error generating file UR...
// eslint-disable-next-line @typescript-eslint/no-unused-vars
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/provider/minio.provider.ts#L96-L109
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
deleteFile
async function deleteFile(fileName: string) { if (!isServiceLoaded) { throw new InternalServerErrorException('Minio Client has not loaded') } try { await minioClient.removeObject(bucketName, fileName) return true } catch (error) { logger.error('Error deleting fil...
// eslint-disable-next-line @typescript-eslint/no-unused-vars
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/provider/minio.provider.ts#L112-L124
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
SecretService.createSecret
async createSecret( user: User, dto: CreateSecret, projectSlug: Project['slug'] ): Promise<SecretWithValues> { // Fetch the project const project = await this.authorityCheckerService.checkAuthorityOverProject({ userId: user.id, entity: { slug: projectSlug }, authoriti...
/** * Creates a new secret in a project * @param user the user creating the secret * @param dto the secret data * @param projectSlug the slug of the project * @returns the created secret */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/secret/service/secret.service.ts#L65-L181
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
SecretService.updateSecret
async updateSecret( user: User, secretSlug: Secret['slug'], dto: UpdateSecret ) { const secret = await this.authorityCheckerService.checkAuthorityOverSecret({ userId: user.id, entity: { slug: secretSlug }, authorities: [Authority.UPDATE_SECRET], prisma: this.prisma }) ...
/** * Updates a secret in a project * @param user the user performing the action * @param secretSlug the slug of the secret to update * @param dto the new secret data * @returns the updated secret and the updated versions */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/secret/service/secret.service.ts#L190-L346
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
SecretService.rollbackSecret
async rollbackSecret( user: User, secretSlug: Secret['slug'], environmentSlug: Environment['slug'], rollbackVersion: SecretVersion['version'] ) { // Fetch the secret const secret = await this.authorityCheckerService.checkAuthorityOverSecret({ userId: user.id, entity: { slug: secret...
/** * Rollback a secret to a specific version * @param user the user performing the action * @param secretSlug the slug of the secret to rollback * @param environmentSlug the slug of the environment to rollback * @param rollbackVersion the version to rollback to * @returns the deleted secret versions ...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/secret/service/secret.service.ts#L356-L450
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
SecretService.deleteSecret
async deleteSecret(user: User, secretSlug: Secret['slug']) { // Check if the user has the required role const secret = await this.authorityCheckerService.checkAuthorityOverSecret({ userId: user.id, entity: { slug: secretSlug }, authorities: [Authority.DELETE_SECRET], prisma: this.prisma ...
/** * Deletes a secret from a project * @param user the user performing the action * @param secretSlug the slug of the secret to delete * @returns void */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/secret/service/secret.service.ts#L458-L490
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
SecretService.getRevisionsOfSecret
async getRevisionsOfSecret( user: User, secretSlug: Secret['slug'], environmentSlug: Environment['slug'], decryptValue: boolean, page: number, limit: number, order: 'asc' | 'desc' = 'desc' ) { // Fetch the secret const secret = await this.authorityCheckerService.checkAuthorityOverS...
/** * Gets all revisions of a secret in an environment * @param user the user performing the action * @param secretSlug the slug of the secret * @param environmentSlug the slug of the environment * @param decryptValue whether to decrypt the secret values or not * @param page the page of items to retur...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/secret/service/secret.service.ts#L503-L577
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
SecretService.getAllSecretsOfProject
async getAllSecretsOfProject( user: User, projectSlug: Project['slug'], decryptValue: boolean, page: number, limit: number, sort: string, order: string, search: string ) { // Fetch the project const project = await this.authorityCheckerService.checkAuthorityOverProject({ ...
/** * Gets all secrets of a project * @param user the user performing the action * @param projectSlug the slug of the project * @param decryptValue whether to decrypt the secret values or not * @param page the page of items to return * @param limit the number of items to return per page * @param so...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/secret/service/secret.service.ts#L591-L768
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
SecretService.secretExists
private async secretExists(secretName: Secret['name'], project: Project) { if ( (await this.prisma.secret.findFirst({ where: { name: secretName, projectId: project.id } })) !== null ) { throw new ConflictException( `Secret already exists: ${secretNam...
/** * Checks if a secret with a given name already exists in the project * @throws {ConflictException} if the secret already exists * @param secretName the name of the secret to check * @param project the project to check the secret in */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/secret/service/secret.service.ts#L901-L914
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
SecretService.checkAutoDecrypt
private async checkAutoDecrypt(decryptValue: boolean, project: Project) { // Check if the project is allowed to store the private key if (decryptValue && !project.storePrivateKey) { throw new BadRequestException( `Cannot decrypt secret values as the project does not store the private key` ) ...
/** * Checks if the project is allowed to decrypt secret values * @param decryptValue whether to decrypt the secret values or not * @param project the project to check * @throws {BadRequestException} if the project does not store the private key and decryptValue is true * @throws {NotFoundException} if t...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/secret/service/secret.service.ts#L923-L938
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
ChangeNotifier.afterInit
async afterInit() { this.logger.log('Initialized change notifier socket gateway') await this.redisSubscriber.subscribe( CHANGE_NOTIFIER_RSC, this.notifyConfigurationUpdate.bind(this) ) }
/** * We want the socket gateway to subscribe to the Redis channel. * This approach allows us to handle distributed computing where * multiple clients can connect to different instances of the API. * Any server that will get an update, will publish it to the Redis * channel, and all connected clients wil...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/socket/change-notifier.socket.ts#L69-L75
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
VariableService.createVariable
async createVariable( user: User, dto: CreateVariable, projectSlug: Project['slug'] ): Promise<VariableWithValues> { // Fetch the project const project = await this.authorityCheckerService.checkAuthorityOverProject({ userId: user.id, entity: { slug: projectSlug }, aut...
/** * Creates a new variable in a project * @param user the user performing the action * @param dto the variable to create * @param projectSlug the slug of the project to create the variable in * @returns the newly created variable */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/variable/service/variable.service.ts#L56-L166
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
VariableService.updateVariable
async updateVariable( user: User, variableSlug: Variable['slug'], dto: UpdateVariable ) { const variable = await this.authorityCheckerService.checkAuthorityOverVariable({ userId: user.id, entity: { slug: variableSlug }, authorities: [Authority.UPDATE_VARIABLE], pr...
/** * Updates a variable in a project * @param user the user performing the action * @param variableSlug the slug of the variable to update * @param dto the data to update the variable with * @returns the updated variable and its new versions */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/variable/service/variable.service.ts#L175-L327
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
VariableService.rollbackVariable
async rollbackVariable( user: User, variableSlug: Variable['slug'], environmentSlug: Environment['slug'], rollbackVersion: VariableVersion['version'] ) { const environment = await this.authorityCheckerService.checkAuthorityOverEnvironment({ userId: user.id, entity: { slug: en...
/** * Rollback a variable to a specific version in a given environment. * * Throws a NotFoundException if the variable does not exist or if the version is invalid. * @param user the user performing the action * @param variableSlug the slug of the variable to rollback * @param environmentSlug the slug ...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/variable/service/variable.service.ts#L339-L430
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
VariableService.deleteVariable
async deleteVariable(user: User, variableSlug: Variable['slug']) { const variable = await this.authorityCheckerService.checkAuthorityOverVariable({ userId: user.id, entity: { slug: variableSlug }, authorities: [Authority.DELETE_VARIABLE], prisma: this.prisma }) // De...
/** * Deletes a variable from a project. * @param user the user performing the action * @param variableSlug the slug of the variable to delete * @returns nothing * @throws `NotFoundException` if the variable does not exist * @throws `ForbiddenException` if the user does not have the required authority...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/variable/service/variable.service.ts#L440-L475
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
VariableService.getAllVariablesOfProject
async getAllVariablesOfProject( user: User, projectSlug: Project['slug'], page: number, limit: number, sort: string, order: string, search: string ) { // Check if the user has the required authorities in the project const { id: projectId } = await this.authorityCheckerService...
/** * Gets all variables of a project, paginated, sorted and filtered by search query. * @param user the user performing the action * @param projectSlug the slug of the project to get the variables from * @param page the page number to fetch * @param limit the number of items per page * @param sort th...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/variable/service/variable.service.ts#L490-L654
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
VariableService.getRevisionsOfVariable
async getRevisionsOfVariable( user: User, variableSlug: Variable['slug'], environmentSlug: Environment['slug'], page: number, limit: number, order: 'asc' | 'desc' = 'desc' ) { const { id: variableId } = await this.authorityCheckerService.checkAuthorityOverVariable({ userId: u...
/** * Gets all revisions of a variable in a given environment. * * The response is paginated and sorted by the version in the given order. * @param user the user performing the action * @param variableSlug the slug of the variable * @param environmentSlug the slug of the environment * @param page t...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/variable/service/variable.service.ts#L670-L729
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
VariableService.variableExists
private async variableExists( variableName: Variable['name'], project: Project ) { if ( (await this.prisma.variable.findFirst({ where: { name: variableName, projectId: project.id } })) !== null ) { throw new ConflictException( `Variable alr...
/** * Checks if a variable with a given name already exists in a project. * Throws a ConflictException if the variable already exists. * @param variableName the name of the variable to check for * @param project the project to check in * @returns nothing * @throws `ConflictException` if the variable a...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/variable/service/variable.service.ts#L739-L755
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceMembershipService.transferOwnership
async transferOwnership( user: User, workspaceSlug: Workspace['slug'], otherUserEmail: User['email'] ): Promise<void> { const workspace = await this.authorityCheckerService.checkAuthorityOverWorkspace({ userId: user.id, entity: { slug: workspaceSlug }, authorities: [Autho...
/** * Transfers ownership of a workspace to another user. * @param user The user transferring the ownership * @param workspaceSlug The slug of the workspace to transfer * @param otherUserEmail The email of the user to transfer the ownership to * @throws BadRequestException if the user is already the owne...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-membership/service/workspace-membership.service.ts#L53-L183
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceMembershipService.inviteUsersToWorkspace
async inviteUsersToWorkspace( user: User, workspaceSlug: Workspace['slug'], members: CreateWorkspaceMember[] ): Promise<void> { const workspace = await this.authorityCheckerService.checkAuthorityOverWorkspace({ userId: user.id, entity: { slug: workspaceSlug }, authorities...
/** * Invites users to a workspace. * @param user The user to invite the users for * @param workspaceSlug The slug of the workspace to invite users to * @param members The members to invite * @throws BadRequestException if the user does not have the authority to add users to the workspace * @throws No...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-membership/service/workspace-membership.service.ts#L194-L238
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceMembershipService.removeUsersFromWorkspace
async removeUsersFromWorkspace( user: User, workspaceSlug: Workspace['slug'], userEmails: User['email'][] ): Promise<void> { const workspace = await this.authorityCheckerService.checkAuthorityOverWorkspace({ userId: user.id, entity: { slug: workspaceSlug }, authorities: [...
/** * Removes users from a workspace. * @param user The user to remove users from the workspace for * @param workspaceSlug The slug of the workspace to remove users from * @param userEmails The emails of the users to remove from the workspace * @throws BadRequestException if the user is trying to remove ...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-membership/service/workspace-membership.service.ts#L250-L327
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceMembershipService.updateMemberRoles
async updateMemberRoles( user: User, workspaceSlug: Workspace['slug'], otherUserEmail: User['email'], roleSlugs: WorkspaceRole['slug'][] ): Promise<void> { const otherUser = await getUserByEmailOrId(otherUserEmail, this.prisma) const workspace = await this.authorityCheckerService.checkA...
/** * Updates the roles of a user in a workspace. * * @throws NotFoundException if the user is not a member of the workspace * @throws BadRequestException if the admin role is tried to be assigned to the user * @param user The user to update the roles for * @param workspaceSlug The slug of the workspa...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-membership/service/workspace-membership.service.ts#L339-L443
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceMembershipService.getAllMembersOfWorkspace
async getAllMembersOfWorkspace( user: User, workspaceSlug: Workspace['slug'], page: number, limit: number, sort: string, order: string, search: string ) { const workspace = await this.authorityCheckerService.checkAuthorityOverWorkspace({ userId: user.id, entity: {...
/** * Gets all members of a workspace, paginated. * @param user The user to get the members for * @param workspaceSlug The slug of the workspace to get the members from * @param page The page number to get * @param limit The number of items per page to get * @param sort The field to sort by * @para...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-membership/service/workspace-membership.service.ts#L456-L558
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceMembershipService.acceptInvitation
async acceptInvitation( user: User, workspaceSlug: Workspace['slug'] ): Promise<void> { // Check if the user has a pending invitation to the workspace await this.checkInvitationPending(workspaceSlug, user) const workspace = await this.prisma.workspace.findUnique({ where: { slug: wor...
/** * Accepts an invitation to a workspace. * @param user The user to accept the invitation for * @param workspaceSlug The slug of the workspace to accept the invitation for * @throws BadRequestException if the user does not have a pending invitation to the workspace * @throws NotFoundException if the wo...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-membership/service/workspace-membership.service.ts#L568-L612
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceMembershipService.cancelInvitation
async cancelInvitation( user: User, workspaceSlug: Workspace['slug'], inviteeEmail: User['email'] ): Promise<void> { const inviteeUser = await getUserByEmailOrId(inviteeEmail, this.prisma) const workspace = await this.authorityCheckerService.checkAuthorityOverWorkspace({ userId: use...
/** * Cancels an invitation to a workspace. * @param user The user cancelling the invitation * @param workspaceSlug The slug of the workspace to cancel the invitation for * @param inviteeEmail The email of the user to cancel the invitation for * @throws BadRequestException if the user does not have a pen...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-membership/service/workspace-membership.service.ts#L623-L663
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceMembershipService.declineInvitation
async declineInvitation( user: User, workspaceSlug: Workspace['slug'] ): Promise<void> { // Check if the user has a pending invitation to the workspace await this.checkInvitationPending(workspaceSlug, user) const workspace = await this.prisma.workspace.findUnique({ where: { slug: wo...
/** * Declines an invitation to a workspace. * @param user The user declining the invitation * @param workspaceSlug The slug of the workspace to decline the invitation for * @throws BadRequestException if the user does not have a pending invitation to the workspace * @throws NotFoundException if the work...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-membership/service/workspace-membership.service.ts#L673-L707
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceMembershipService.leaveWorkspace
async leaveWorkspace( user: User, workspaceSlug: Workspace['slug'] ): Promise<void> { const workspace = await this.authorityCheckerService.checkAuthorityOverWorkspace({ userId: user.id, entity: { slug: workspaceSlug }, authorities: [Authority.READ_WORKSPACE], prisma: ...
/** * Leaves a workspace. * @throws BadRequestException if the user is the owner of the workspace * @param user The user to leave the workspace for * @param workspaceSlug The slug of the workspace to leave */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-membership/service/workspace-membership.service.ts#L715-L765
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceMembershipService.isUserMemberOfWorkspace
async isUserMemberOfWorkspace( user: User, workspaceSlug: Workspace['slug'], otherUserEmail: User['email'] ): Promise<boolean> { let otherUser: User | null = null try { otherUser = await getUserByEmailOrId(otherUserEmail, this.prisma) } catch (e) { return false } const wo...
/** * Checks if a user is a member of a workspace. * @param user The user to check if the other user is a member of the workspace for * @param workspaceSlug The slug of the workspace to check if the user is a member of * @param otherUserEmail The email of the user to check if is a member of the workspace ...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-membership/service/workspace-membership.service.ts#L774-L796
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceMembershipService.addMembersToWorkspace
private async addMembersToWorkspace( workspace: Workspace, currentUser: User, members: CreateWorkspaceMember[] ) { const workspaceAdminRole = await this.getWorkspaceAdminRole(workspace.id) for (const member of members) { // Check if the admin role is tried to be assigned to the user i...
/** * Adds members to a workspace. * @param workspace The workspace to add members to * @param currentUser The user performing the action * @param members The members to add to the workspace * @throws BadRequestException if the admin role is tried to be assigned to the user * @throws ConflictException...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-membership/service/workspace-membership.service.ts#L827-L953
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceMembershipService.memberExistsInWorkspace
private async memberExistsInWorkspace( workspaceId: string, userId: string ): Promise<boolean> { return ( (await this.prisma.workspaceMember.count({ where: { workspaceId, userId } })) > 0 ) }
/** * Checks if a user is a member of a workspace. * @param workspaceId The ID of the workspace to check * @param userId The ID of the user to check * @returns True if the user is a member of the workspace, false otherwise * @private */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-membership/service/workspace-membership.service.ts#L962-L974
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceMembershipService.getWorkspaceMembership
private async getWorkspaceMembership( workspaceId: Workspace['id'], userId: User['id'] ): Promise<WorkspaceMember> { return await this.prisma.workspaceMember.findUnique({ where: { workspaceId_userId: { workspaceId, userId } } }) }
/** * Gets the workspace membership of a user in a workspace. * @param workspaceId The ID of the workspace to get the membership for * @param userId The ID of the user to get the membership for * @returns The workspace membership of the user in the workspace * @private */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-membership/service/workspace-membership.service.ts#L983-L995
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceMembershipService.deleteMembership
private async deleteMembership( workspaceId: Workspace['id'], userId: User['id'] ): Promise<void> { await this.prisma.workspaceMember.delete({ where: { workspaceId_userId: { workspaceId, userId } } }) }
/** * Deletes the membership of a user in a workspace. * @param workspaceId The ID of the workspace to delete the membership from * @param userId The ID of the user to delete the membership for * @returns A promise that resolves when the membership is deleted * @private */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-membership/service/workspace-membership.service.ts#L1004-L1016
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceMembershipService.checkInvitationPending
private async checkInvitationPending( workspaceSlug: Workspace['slug'], user: User ): Promise<void> { const membershipExists = await this.prisma.workspaceMember .count({ where: { workspace: { slug: workspaceSlug }, userId: user.id, invitati...
/** * Checks if a user has a pending invitation to a workspace. * @throws BadRequestException if the user is not invited to the workspace * @param workspaceSlug The slug of the workspace to check if the user is invited to * @param user The user to check if the user is invited to the workspace */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-membership/service/workspace-membership.service.ts#L1024-L1044
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceRoleService.createWorkspaceRole
async createWorkspaceRole( user: User, workspaceSlug: Workspace['slug'], dto: CreateWorkspaceRole ) { if ( dto.authorities && dto.authorities.includes(Authority.WORKSPACE_ADMIN) ) { throw new BadRequestException( 'You can not explicitly assign workspace admin authority to...
/** * Creates a new workspace role * @throws {BadRequestException} if the role has workspace admin authority * @throws {ConflictException} if a workspace role with the same name already exists * @param user the user that is creating the workspace role * @param workspaceSlug the slug of the workspace *...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-role/service/workspace-role.service.ts#L47-L235
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceRoleService.updateWorkspaceRole
async updateWorkspaceRole( user: User, workspaceRoleSlug: WorkspaceRole['slug'], dto: UpdateWorkspaceRole ) { if ( dto.authorities && dto.authorities.includes(Authority.WORKSPACE_ADMIN) ) { throw new BadRequestException( 'You can not explicitly assign workspace admin auth...
/** * Updates a workspace role * @throws {BadRequestException} if the role has workspace admin authority * @throws {ConflictException} if a workspace role with the same name already exists * @param user the user that is updating the workspace role * @param workspaceRoleSlug the slug of the workspace role...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-role/service/workspace-role.service.ts#L246-L429
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceRoleService.deleteWorkspaceRole
async deleteWorkspaceRole( user: User, workspaceRoleSlug: WorkspaceRole['slug'] ) { const workspaceRole = await this.getWorkspaceRoleWithAuthority( user.id, workspaceRoleSlug, Authority.DELETE_WORKSPACE_ROLE ) const workspaceRoleId = workspaceRole.id if (workspaceRole.hasAdm...
/** * Deletes a workspace role * @throws {UnauthorizedException} if the role has administrative authority * @param user the user that is deleting the workspace role * @param workspaceRoleSlug the slug of the workspace role to be deleted */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-role/service/workspace-role.service.ts#L437-L478
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceRoleService.checkWorkspaceRoleExists
async checkWorkspaceRoleExists( user: User, workspaceSlug: Workspace['slug'], name: string ) { const workspace = await this.authorityCheckerService.checkAuthorityOverWorkspace({ userId: user.id, entity: { slug: workspaceSlug }, authorities: [Authority.READ_WORKSPACE_ROLE]...
/** * Checks if a workspace role with the given name exists * @throws {UnauthorizedException} if the user does not have the required authority * @param user the user performing the check * @param workspaceSlug the slug of the workspace * @param name the name of the workspace role to check * @returns t...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-role/service/workspace-role.service.ts#L488-L510
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceRoleService.getWorkspaceRole
async getWorkspaceRole( user: User, workspaceRoleSlug: WorkspaceRole['slug'] ): Promise<WorkspaceRole> { return await this.getWorkspaceRoleWithAuthority( user.id, workspaceRoleSlug, Authority.READ_WORKSPACE_ROLE ) }
/** * Gets a workspace role by its slug * @throws {UnauthorizedException} if the user does not have the required authority * @param user the user performing the request * @param workspaceRoleSlug the slug of the workspace role to get * @returns the workspace role with the given slug */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-role/service/workspace-role.service.ts#L519-L528
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceRoleService.getWorkspaceRolesOfWorkspace
async getWorkspaceRolesOfWorkspace( user: User, workspaceSlug: Workspace['slug'], page: number, limit: number, sort: string, order: string, search: string ): Promise<{ items: WorkspaceRole[]; metadata: PaginatedMetadata }> { const { id: workspaceId } = await this.authorityChecker...
/** * Gets all workspace roles of a workspace, with pagination and optional filtering by name * @throws {UnauthorizedException} if the user does not have the required authority * @param user the user performing the request * @param workspaceSlug the slug of the workspace * @param page the page to get (0-...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-role/service/workspace-role.service.ts#L542-L597
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceRoleService.getWorkspaceRoleWithAuthority
private async getWorkspaceRoleWithAuthority( userId: User['id'], workspaceRoleSlug: Workspace['slug'], authorities: Authority ) { const workspaceRole = (await this.prisma.workspaceRole.findUnique({ where: { slug: workspaceRoleSlug }, include: { projects: { s...
/** * Gets a workspace role by its slug, with additional authorities check * @throws {NotFoundException} if the workspace role does not exist * @throws {UnauthorizedException} if the user does not have the required authority * @param userId the user that is performing the request * @param workspaceRoleSl...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-role/service/workspace-role.service.ts#L608-L661
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceRoleService.getProjectSlugToIdMap
private async getProjectSlugToIdMap(projectSlugs: string[]) { const projects = projectSlugs.length ? await this.prisma.project.findMany({ where: { slug: { in: projectSlugs } } }) : [] return new Map(projects.map((project) => [project...
/** * Given an array of project slugs, returns a Map of slug to id for all projects * found in the database. * * @param projectSlugs the array of project slugs * @returns a Map of project slug to id */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace-role/service/workspace-role.service.ts#L670-L682
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceService.createWorkspace
async createWorkspace(user: User, dto: CreateWorkspace) { if (await this.existsByName(dto.name, user.id)) { throw new ConflictException('Workspace already exists') } return await createWorkspace(user, dto, this.prisma) }
/** * Creates a new workspace for the given user. * @throws ConflictException if the workspace with the same name already exists * @param user The user to create the workspace for * @param dto The data to create the workspace with * @returns The created workspace */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace/service/workspace.service.ts#L51-L57
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceService.updateWorkspace
async updateWorkspace( user: User, workspaceSlug: Workspace['slug'], dto: UpdateWorkspace ) { // Fetch the workspace const workspace = await this.authorityCheckerService.checkAuthorityOverWorkspace({ userId: user.id, entity: { slug: workspaceSlug }, authorities: [Auth...
/** * Updates a workspace * @throws ConflictException if the workspace with the same name already exists * @param user The user to update the workspace for * @param workspaceSlug The slug of the workspace to update * @param dto The data to update the workspace with * @returns The updated workspace ...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace/service/workspace.service.ts#L67-L126
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceService.deleteWorkspace
async deleteWorkspace( user: User, workspaceSlug: Workspace['slug'] ): Promise<void> { const workspace = await this.authorityCheckerService.checkAuthorityOverWorkspace({ userId: user.id, entity: { slug: workspaceSlug }, authorities: [Authority.DELETE_WORKSPACE], prism...
/** * Deletes a workspace. * @throws BadRequestException if the workspace is the default workspace * @param user The user to delete the workspace for * @param workspaceSlug The slug of the workspace to delete */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace/service/workspace.service.ts#L134-L161
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceService.getWorkspaceBySlug
async getWorkspaceBySlug( user: User, workspaceSlug: Workspace['slug'] ): Promise<Workspace> { const workspace = await this.authorityCheckerService.checkAuthorityOverWorkspace({ userId: user.id, entity: { slug: workspaceSlug }, authorities: [Authority.READ_USERS], pri...
/** * Gets a workspace by its slug. * @param user The user to get the workspace for * @param workspaceSlug The slug of the workspace to get * @returns The workspace * @throws NotFoundException if the workspace does not exist or the user does not have the authority to read the workspace */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace/service/workspace.service.ts#L170-L186
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceService.getWorkspacesOfUser
async getWorkspacesOfUser( user: User, page: number, limit: number, sort: string, order: string, search: string ) { // Get all workspaces of user for page with limit const items = await this.prisma.workspace.findMany({ skip: page * limit, take: Number(limit), orderBy:...
/** * Gets all workspaces of a user, paginated. * @param user The user to get the workspaces for * @param page The page number to get * @param limit The number of items per page to get * @param sort The field to sort by * @param order The order to sort in * @param search The search string to filter...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace/service/workspace.service.ts#L198-L264
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceService.exportData
async exportData(user: User, workspaceSlug: Workspace['slug']) { const workspace = await this.authorityCheckerService.checkAuthorityOverWorkspace({ userId: user.id, entity: { slug: workspaceSlug }, authorities: [Authority.WORKSPACE_ADMIN], prisma: this.prisma }) // e...
/** * Exports all data of a workspace, including its roles, projects, environments, variables and secrets. * @param user The user to export the data for * @param workspaceSlug The slug of the workspace to export * @returns The exported data * @throws NotFoundException if the workspace does not exist or t...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace/service/workspace.service.ts#L274-L350
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceService.globalSearch
async globalSearch( user: User, workspaceSlug: Workspace['slug'], searchTerm: string ): Promise<{ projects: Partial<Project>[] environments: Partial<Environment>[] secrets: Partial<Secret>[] variables: Partial<Variable>[] }> { // Check authority over workspace const workspace = ...
/** * Searches for projects, environments, secrets and variables * based on a search term. The search is scoped to the workspace * and the user's permissions. * @param user The user to search for * @param workspaceSlug The slug of the workspace to search in * @param searchTerm The search term to searc...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace/service/workspace.service.ts#L361-L405
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceService.getAllWorkspaceInvitations
async getAllWorkspaceInvitations( user: User, page: number, limit: number, sort: string, order: string, search: string ) { // fetch all workspaces of user where they are not admin const items = await this.prisma.workspaceMember.findMany({ skip: page * limit, take: limitMaxI...
/** * Gets all the invitations a user has to various workspaces, paginated. * @param user The user to get the workspaces for * @param page The page number to get * @param limit The number of items per page to get * @param sort The field to sort by * @param order The order to sort in * @param search...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace/service/workspace.service.ts#L417-L510
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceService.getAccessibleProjectIds
private async getAccessibleProjectIds( userId: string, workspaceId: string ): Promise<string[]> { const projects = await this.prisma.project.findMany({ where: { workspaceId } }) const accessibleProjectIds: string[] = [] for (const project of projects) { if (project.accessLevel ===...
/** * Gets a list of project IDs that the user has access to READ. * The user has access to a project if the project is global or if the user has the READ_PROJECT authority. * @param userId The ID of the user to get the accessible project IDs for * @param workspaceId The ID of the workspace to get the acces...
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace/service/workspace.service.ts#L520-L547
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceService.queryProjects
private async queryProjects( projectIds: string[], searchTerm: string ): Promise<Partial<Project>[]> { // Fetch projects where user has READ_PROJECT authority and match search term return this.prisma.project.findMany({ where: { id: { in: projectIds }, OR: [ { name: { co...
/** * Queries projects by IDs and search term. * @param projectIds The IDs of projects to query * @param searchTerm The search term to query by * @returns The projects that match the search term * @private */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace/service/workspace.service.ts#L556-L571
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceService.queryEnvironments
private async queryEnvironments( projectIds: string[], searchTerm: string ): Promise<Partial<Environment>[]> { return this.prisma.environment.findMany({ where: { project: { id: { in: projectIds } }, OR: [ { name: { contains: searchTerm, mode: 'insensitive'...
/** * Queries environments by IDs and search term. * @param projectIds The IDs of projects to query * @param searchTerm The search term to query by * @returns The environments that match the search term * @private */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace/service/workspace.service.ts#L580-L596
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceService.querySecrets
private async querySecrets( projectIds: string[], searchTerm: string ): Promise<Partial<Secret>[]> { // Fetch secrets associated with projects user has READ_SECRET authority on return await this.prisma.secret.findMany({ where: { project: { id: { in: projectIds } }, ...
/** * Queries secrets by IDs and search term. * @param projectIds The IDs of projects to query * @param searchTerm The search term to query by * @returns The secrets that match the search term * @private */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace/service/workspace.service.ts#L605-L622
557b3b63dd7c589d484d4eab0b46e90a7c696af3
keyshade
github_2023
keyshade-xyz
typescript
WorkspaceService.queryVariables
private async queryVariables( projectIds: string[], searchTerm: string ): Promise<Partial<Variable>[]> { return this.prisma.variable.findMany({ where: { project: { id: { in: projectIds } }, OR: [ { name: { contains: searchTerm, mode: 'insensitive' } }, ...
/** * Queries variables by IDs and search term. * @param projectIds The IDs of projects to query * @param searchTerm The search term to query by * @returns The variables that match the search term * @private */
https://github.com/keyshade-xyz/keyshade/blob/557b3b63dd7c589d484d4eab0b46e90a7c696af3/apps/api/src/workspace/service/workspace.service.ts#L631-L647
557b3b63dd7c589d484d4eab0b46e90a7c696af3