Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(schema, api-client): Migrate workspace-membership schemas and types to @keyshade/schema #569

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ delete {
auth: none
}

params:query {
userEmails: [email protected],[email protected]
}

params:path {
workspace_slug: workspace-1-cahli
}

docs {
## Description

Remove one or more users from the workspace.

### Request Query Params

The endpoint accepts a string of comma separated emails
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ export class WorkspaceMembershipController {
async removeUsers(
@CurrentUser() user: User,
@Param('workspaceSlug') workspaceSlug: Workspace['slug'],
@Body() userEmails: User['email'][]
@Query('userEmails') userEmails: string = ''
) {
return this.workspaceMembershipService.removeUsersFromWorkspace(
user,
workspaceSlug,
userEmails
userEmails.split(/\s*,\s*/)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,9 @@ describe('Workspace Membership Controller Tests', () => {
'x-e2e-user-email': user1.email
},
url: `/workspace-membership/${workspace1.slug}/remove-users`,
payload: [user2.id]
query: {
userEmails: user2.email
}
})

expect(response.statusCode).toBe(200)
Expand All @@ -548,7 +550,9 @@ describe('Workspace Membership Controller Tests', () => {
'x-e2e-user-email': user1.email
},
url: `/workspace-membership/${workspace1.slug}/remove-users`,
payload: [user1.email]
query: {
userEmails: user1.email
}
})

expect(response.statusCode).toBe(400)
Expand Down
4 changes: 2 additions & 2 deletions packages/api-client/src/controllers/workspace-membership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
IsMemberResponse,
GetMembersRequest,
GetMembersResponse
} from '@api-client/types/workspace-membership.types'
} from '@keyshade/schema'
import { ClientResponse } from '@keyshade/schema'

export default class WorkspaceMembershipController {
Expand Down Expand Up @@ -61,7 +61,7 @@ export default class WorkspaceMembershipController {
headers?: Record<string, string>
): Promise<ClientResponse<RemoveUsersResponse>> {
const response = await this.apiClient.delete(
`/api/workspace-membership/${request.workspaceSlug}/remove-users`,
`/api/workspace-membership/${request.workspaceSlug}/remove-users?userEmails=${request.userEmails}`,
headers
)
return await parseResponse<RemoveUsersResponse>(response)
Expand Down
7 changes: 6 additions & 1 deletion packages/api-client/src/core/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,14 @@
* Sends a DELETE request to the specified URL and returns a Promise that resolves to the response data.
*
* @param url - The URL to send the DELETE request to.
* @param headers - Optional headers to include in the request.
* @returns A Promise that resolves to the response data.
*/
delete(url: string, headers?: Record<string, string>): Promise<Response> {
delete(
url: string,
headers?: Record<string, string>,
data?: any

Check warning on line 80 in packages/api-client/src/core/client.ts

View workflow job for this annotation

GitHub Actions / Validate API Client

'data' is defined but never used
): Promise<Response> {
return this.request(url, {
method: 'DELETE',
headers: {
Expand Down
145 changes: 0 additions & 145 deletions packages/api-client/src/types/workspace-membership.types.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/api-client/tests/config/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function executeCommand(

function startAPI(): Promise<void> {
return new Promise((resolve) => {
const apiProcess = exec('cd ../../ && pnpm run start:api', {
const apiProcess = exec('pnpm run --filter=api start', {
env: {
PATH: process.env.PATH,
DATABASE_URL: 'postgresql://prisma:prisma@localhost:5432/tests',
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/tests/workspace-membership.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('Workspace Membership Controller Tests', () => {
it('should remove users', async () => {
const request = {
workspaceSlug: workspaceSlug!,
userEmails: ['[email protected]']
userEmails: '[email protected]'
}
const response = await workspaceMembershipController.removeUsers(request, {
'x-e2e-user-email': userEmail
Expand Down
18 changes: 9 additions & 9 deletions packages/eslint-config-custom/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "eslint-config-custom",
"license": "MIT",
"version": "0.0.0",
"private": true,
"devDependencies": {
"@vercel/style-guide": "^5.0.0",
"eslint-config-turbo": "^2.3.1",
"typescript": "^4.5.3"
}
"name": "eslint-config-custom",
"license": "MIT",
"version": "0.0.0",
"private": true,
"devDependencies": {
"@vercel/style-guide": "^5.0.0",
"eslint-config-turbo": "^2.3.1",
"typescript": "^4.5.3"
}
}
1 change: 1 addition & 0 deletions packages/schema/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export * from './workspace'
export * from './workspace-role'
export * from './event'
export * from './api-key'
export * from './workspace-membership'
1 change: 1 addition & 0 deletions packages/schema/src/index.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './event/index.types'
export * from './integration/index.types'
export * from './api-key/index.types'
export * from './workspace-role/index.types'
export * from './workspace-membership/index.types'
16 changes: 7 additions & 9 deletions packages/schema/src/user/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { z } from 'zod'
import { WorkspaceSchema } from '@/workspace'

export const GetSelfResponseSchema = z.object({
export const UserSchema = z.object({
id: z.string(),
email: z.string().email(),
name: z.string(),
profilePictureUrl: z.string().nullable(),
isActive: z.boolean(),
isOnboardingFinished: z.boolean(),
isAdmin: z.boolean(),
authProvider: z.string(),
authProvider: z.string()
})

export const GetSelfResponseSchema = UserSchema.extend({
defaultWorkspace: WorkspaceSchema
})

Expand All @@ -20,9 +23,7 @@ export const UpdateSelfRequestSchema = z.object({
email: z.string().email().optional()
})

export const UpdateSelfResponseSchema = GetSelfResponseSchema.partial().omit({
defaultWorkspace: true
})
export const UpdateSelfResponseSchema = UserSchema

export const DeleteSelfRequestSchema = z.void()

Expand All @@ -32,10 +33,7 @@ export const ValidateEmailChangeOTPRequestSchema = z.object({
otp: z.string().min(6).max(6)
})

export const ValidateEmailChangeOTPResponseSchema =
GetSelfResponseSchema.partial().omit({
defaultWorkspace: true
})
export const ValidateEmailChangeOTPResponseSchema = UserSchema

export const ResendEmailChangeOTPRequestSchema = z.void()

Expand Down
Loading
Loading