Skip to content

Commit

Permalink
feat(schema, api-client): Migrate auth types to @keyshade/schema (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
muntaxir4 authored Nov 13, 2024
1 parent 1793d92 commit d880098
Show file tree
Hide file tree
Showing 31 changed files with 133 additions and 88 deletions.
7 changes: 2 additions & 5 deletions packages/api-client/src/controllers/auth.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {
ResendOTPResponse,
ResendOTPRequest
} from '@api-client/types/auth.types'
import { ResendOTPResponse, ResendOTPRequest } from '@keyshade/schema'
import { APIClient } from '@api-client/core/client'
import { parseResponse } from '@api-client/core/response-parser'
import { ClientResponse } from '@api-client/types/index.types'
import { ClientResponse } from '@keyshade/schema'

export default class AuthController {
private apiClient: APIClient
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/src/controllers/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
UpdateEnvironmentRequest,
UpdateEnvironmentResponse
} from '@api-client/types/environment.types'
import { ClientResponse } from '@api-client/types/index.types'
import { ClientResponse } from '@keyshade/schema'

export default class EnvironmentController {
private apiClient: APIClient
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/src/controllers/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
GetEventsResponse
} from '@api-client/types/event.types'
import { APIClient } from '../core/client'
import { ClientResponse } from '@api-client/types/index.types'
import { ClientResponse } from '@keyshade/schema'
import { parseResponse } from '@api-client/core/response-parser'

export default class EventController {
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/src/controllers/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
UpdateIntegrationResponse
} from '@api-client/types/integration.types'
import { APIClient } from '@api-client/core/client'
import { ClientResponse } from '@api-client/types/index.types'
import { ClientResponse } from '@keyshade/schema'
import { parseResponse } from '@api-client/core/response-parser'
import { parsePaginationUrl } from '@api-client/core/pagination-parser'

Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/src/controllers/project.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClientResponse } from '@api-client/types/index.types'
import { ClientResponse } from '@keyshade/schema'
import { APIClient } from '@api-client/core/client'
import {
CreateProjectRequest,
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/src/controllers/secret.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { APIClient } from '@api-client/core/client'
import { ClientResponse } from '@api-client/types/index.types'
import { ClientResponse } from '@keyshade/schema'
import { parseResponse } from '@api-client/core/response-parser'
import {
CreateSecretRequest,
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/src/controllers/user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { APIClient } from '@api-client/core/client'
import { parseResponse } from '@api-client/core/response-parser'
import { ClientResponse } from '@api-client/types/index.types'
import { ClientResponse } from '@keyshade/schema'
import {
GetSelfResponse,
UpdateSelfRequest,
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/src/controllers/variable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { APIClient } from '@api-client/core/client'
import { parsePaginationUrl } from '@api-client/core/pagination-parser'
import { parseResponse } from '@api-client/core/response-parser'
import { ClientResponse } from '@api-client/types/index.types'
import { ClientResponse } from '@keyshade/schema'
import {
CreateVariableRequest,
CreateVariableResponse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
GetMembersRequest,
GetMembersResponse
} from '@api-client/types/workspace-membership.types'
import { ClientResponse } from '@api-client/types/index.types'
import { ClientResponse } from '@keyshade/schema'

export default class WorkspaceMembershipController {
private apiClient: APIClient
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/src/controllers/workspace-role.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { APIClient } from '@api-client/core/client'
import { parsePaginationUrl } from '@api-client/core/pagination-parser'
import { parseResponse } from '@api-client/core/response-parser'
import { ClientResponse } from '@api-client/types/index.types'
import { ClientResponse } from '@keyshade/schema'
import {
CreateWorkspaceRoleRequest,
CreateWorkspaceRoleResponse,
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/src/core/pagination-parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PageRequest } from '@api-client/types/index.types'
import { PageRequest } from '@keyshade/schema'

/**
* Constructs a URL by appending the given page request
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/src/core/response-parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClientResponse, ResponseError } from '@api-client/types/index.types'
import { ClientResponse, ResponseError } from '@keyshade/schema'

/**
* Takes a Response object and parses its contents into a ClientResponse object.
Expand Down
4 changes: 0 additions & 4 deletions packages/api-client/src/types/auth.types.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/api-client/src/types/environment.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PageRequest, PageResponse } from './index.types'
import { PageRequest, PageResponse } from '@keyshade/schema'

export interface Environment {
id: string
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/src/types/event.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PageResponse } from './index.types'
import { PageResponse } from '@keyshade/schema'

export enum EventSource {
SECRET,
Expand Down
36 changes: 0 additions & 36 deletions packages/api-client/src/types/index.types.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/api-client/src/types/integration.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PageRequest, PageResponse } from './index.types'
import { PageRequest, PageResponse } from '@keyshade/schema'

export enum IntegrationType {
DISCORD,
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/src/types/project.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PageRequest, PageResponse } from './index.types'
import { PageRequest, PageResponse } from '@keyshade/schema'

export interface Project {
id: string
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/src/types/secret.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PageRequest, PageResponse } from './index.types'
import { PageRequest, PageResponse } from '@keyshade/schema'

export interface Secret {
id: string
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/src/types/user.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Workspace } from '@api-client/types/workspace.types'
import { Workspace } from '@keyshade/schema'

export interface GetSelfResponse {
id: string
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/src/types/variable.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PageRequest, PageResponse } from './index.types'
import { PageRequest, PageResponse } from '@keyshade/schema'

export interface Variable {
id: string
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/src/types/workspace-role.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PageRequest, PageResponse } from './index.types'
import { PageRequest, PageResponse } from '@keyshade/schema'

export interface WorkspaceRole {
id: string
Expand Down
10 changes: 3 additions & 7 deletions packages/api-client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@
"@api-client/*": ["./src/*"]
},
"outDir": "dist",
"plugins": [{ "transform": "typescript-transform-paths" }]
"plugins": [{ "transform": "typescript-transform-paths" }],
"moduleResolution": "Bundler"
},
"tsc-alias": {
"resolveFullPaths": true,
"verbose": false
},
"include": [
"src/**/*.ts",
"tests/**/*.ts",
"jest.config.ts",
".eslintrc.cjs"
],
"include": ["src/**/*.ts", "tests/**/*.ts", "jest.config.ts"],
"exclude": ["node_modules", "dist"]
}
4 changes: 4 additions & 0 deletions packages/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"private": true,
"exports": {
".": {
"types": "./dist/src/index.types.d.ts",
"default": "./dist/src/index.types.js"
},
"./schemas": {
"types": "./dist/src/index.d.ts",
"default": "./dist/src/index.js"
}
Expand Down
7 changes: 7 additions & 0 deletions packages/schema/src/auth/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { z } from 'zod'

export const ResendOTPRequestSchema = z.object({
userEmail: z.string().email()
})

export const ResendOTPResponseSchema = z.void()
6 changes: 6 additions & 0 deletions packages/schema/src/auth/auth.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { z } from 'zod'
import { ResendOTPRequestSchema, ResendOTPResponseSchema } from './auth'

export type ResendOTPRequest = z.infer<typeof ResendOTPRequestSchema>

export type ResendOTPResponse = z.infer<typeof ResendOTPResponseSchema>
5 changes: 3 additions & 2 deletions packages/schema/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
//Export all Schemas and types

export * from './pagination/pagination'
export * from './pagination/pagination.types'

export * from './api-key'

export * from './auth/auth'

export * from './environment'
export * from './integration'
export * from './project'
export * from './secret'
export * from './variable'

export * from './workspace/workspace'
export * from './workspace/workspace.types'

export * from './workspace-role'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ import {
} from './project'
import { CreateSecretSchema, UpdateSecretSchema } from './secret'
import { CreateVariableSchema, UpdateVariableSchema } from './variable'
import {
CreateWorkspaceSchema,
InviteMemberSchema,
UpdateWorkspaceSchema
} from './workspace'
import {
CreateWorkspaceRoleSchema,
UpdateWorkspaceRoleSchema
} from './workspace-role'

//Export types from pagination.types.ts
export * from './pagination/pagination.types'

export type TCreateApiKey = z.infer<typeof CreateApiKeySchema>
export type TUpdateApiKey = z.infer<typeof UpdateApiKeySchema>

// Export types from auth.types.ts
export * from './auth/auth.types'

export type TCreateEnvironment = z.infer<typeof CreateEnvironmentSchema>
export type TUpdateEnvironment = z.infer<typeof UpdateEnvironmentSchema>

Expand All @@ -38,9 +39,8 @@ export type TUpdateSecret = z.infer<typeof UpdateSecretSchema>
export type TCreateVariable = z.infer<typeof CreateVariableSchema>
export type TUpdateVariable = z.infer<typeof UpdateVariableSchema>

export type TCreateWorkspace = z.infer<typeof CreateWorkspaceSchema>
export type TUpdateWorkspace = z.infer<typeof UpdateWorkspaceSchema>
export type TInviteMember = z.infer<typeof InviteMemberSchema>
// Export types from workspace.types.ts
export * from './workspace/workspace.types'

export type TCreateWorkspaceRole = z.infer<typeof CreateWorkspaceRoleSchema>
export type TUpdateWorkspaceRole = z.infer<typeof UpdateWorkspaceRoleSchema>
8 changes: 6 additions & 2 deletions packages/schema/src/workspace/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PageRequestSchema, PageResponseSchema } from '@/pagination/pagination'
import { projectAccessLevelEnum, rotateAfterEnum } from '@/enums'

export const InviteMemberSchema = z.object({
email: z.string(),
email: z.string().email(),
roleSlugs: z.array(z.string()).optional()
})

Expand Down Expand Up @@ -40,7 +40,7 @@ export const DeleteWorkspaceRequestSchema = z.object({
workspaceSlug: z.string()
})

export const DeleteWorkspaceResponseSchema = z.never()
export const DeleteWorkspaceResponseSchema = z.void()

export const GetWorkspaceRequestSchema = z.object({
workspaceSlug: z.string()
Expand Down Expand Up @@ -120,27 +120,31 @@ export const GlobalSearchRequestSchema = z.object({
export const GlobalSearchResponseSchema = z.object({
projects: z.array(
z.object({
id: z.string(),
slug: z.string(),
name: z.string(),
description: z.string()
})
),
environments: z.array(
z.object({
id: z.string(),
slug: z.string(),
name: z.string(),
description: z.string()
})
),
secrets: z.array(
z.object({
id: z.string(),
slug: z.string(),
name: z.string(),
note: z.string()
})
),
variables: z.array(
z.object({
id: z.string(),
slug: z.string(),
name: z.string(),
note: z.string()
Expand Down
Loading

0 comments on commit d880098

Please sign in to comment.