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 project types and schemas to @keyshade/schema #537

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/api-client/src/controllers/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
UnlinkProjectResponse,
UpdateProjectRequest,
UpdateProjectResponse
} from '@api-client/types/project.types'
} from '@keyshade/schema'
import { parseResponse } from '@api-client/core/response-parser'
import { parsePaginationUrl } from '@api-client/core/pagination-parser'

Expand Down
87 changes: 0 additions & 87 deletions packages/api-client/src/types/project.types.d.ts

This file was deleted.

4 changes: 3 additions & 1 deletion packages/schema/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export * from './auth/auth'

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

export * from './project/project'

export * from './secret'
export * from './variable'

Expand Down
10 changes: 2 additions & 8 deletions packages/schema/src/index.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import { z } from 'zod'
import { CreateApiKeySchema, UpdateApiKeySchema } from './api-key'
import { CreateEnvironmentSchema, UpdateEnvironmentSchema } from './environment'
import { CreateIntegrationSchema, UpdateIntegrationSchema } from './integration'
import {
CreateProjectSchema,
ForkProjectSchema,
UpdateProjectSchema
} from './project'
import { CreateSecretSchema, UpdateSecretSchema } from './secret'
import { CreateVariableSchema, UpdateVariableSchema } from './variable'
import {
Expand All @@ -29,9 +24,8 @@ export type TUpdateEnvironment = z.infer<typeof UpdateEnvironmentSchema>
export type TCreateIntegration = z.infer<typeof CreateIntegrationSchema>
export type TUpdateIntegration = z.infer<typeof UpdateIntegrationSchema>

export type TCreateProject = z.infer<typeof CreateProjectSchema>
export type TUpdateProject = z.infer<typeof UpdateProjectSchema>
export type TForkProject = z.infer<typeof ForkProjectSchema>
// Export types from project.types.ts
export * from './project/project.types'

export type TCreateSecret = z.infer<typeof CreateSecretSchema>
export type TUpdateSecret = z.infer<typeof UpdateSecretSchema>
Expand Down
19 changes: 0 additions & 19 deletions packages/schema/src/project.ts

This file was deleted.

99 changes: 99 additions & 0 deletions packages/schema/src/project/project.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { z } from 'zod'
import { PageRequestSchema, PageResponseSchema } from '@/pagination/pagination'
import { CreateEnvironmentSchema } from '@/environment'
import { projectAccessLevelEnum } from '@/enums'

export const ProjectSchema = z
.object({
id: z.string(),
name: z.string(),
slug: z.string(),
description: z.string(),
createdAt: z.string(),
updatedAt: z.string(),
publicKey: z.string(),
privateKey: z.string(),
storePrivateKey: z.boolean(),
isDisabled: z.boolean(),
accessLevel: z.string(),
pendingCreation: z.boolean(),
isForked: z.boolean(),
lastUpdatedById: z.string(),
workspaceId: z.string(),
forkedFromId: z.string().nullable()
})
.refine((obj) =>
obj.isForked ? obj.forkedFromId !== null : obj.forkedFromId === null
)

export const CreateProjectRequestSchema = z.object({
name: z.string(),
workspaceSlug: z.string(),
description: z.string().optional(),
storePrivateKey: z.boolean().optional(),
environments: CreateEnvironmentSchema.array().optional(),
accessLevel: projectAccessLevelEnum
})

export const CreateProjectResponseSchema = ProjectSchema

export const UpdateProjectRequestSchema = CreateProjectRequestSchema.partial()
.omit({
workspaceSlug: true
})
.merge(
z.object({
projectSlug: z.string(),
regenerateKeyPair: z.boolean().optional(),
privateKey: z.string().optional()
})
)

export const UpdateProjectResponseSchema = ProjectSchema

export const DeleteProjectRequestSchema = z.object({
projectSlug: z.string()
})

export const DeleteProjectResponseSchema = z.void()

export const GetProjectRequestSchema = z.object({
projectSlug: z.string()
})

export const GetProjectResponseSchema = ProjectSchema

export const ForkProjectRequestSchema = z.object({
projectSlug: z.string(),
name: z.string().optional(),
workspaceSlug: z.string().optional(),
storePrivateKey: z.boolean().optional()
})

export const ForkProjectResponseSchema = ProjectSchema

export const SyncProjectRequestSchema = z.object({
projectSlug: z.string(),
hardSync: z.boolean().optional()
})

export const SyncProjectResponseSchema = z.void()

export const UnlinkProjectRequestSchema = z.object({
projectSlug: z.string()
})

export const UnlinkProjectResponseSchema = z.void()

export const GetForkRequestSchema = PageRequestSchema.extend({
projectSlug: z.string(),
workspaceSlug: z.string()
})

export const GetForkResponseSchema = PageResponseSchema(ProjectSchema)

export const GetAllProjectsRequestSchema = PageRequestSchema.extend({
workspaceSlug: z.string()
})

export const GetAllProjectsResponseSchema = PageResponseSchema(ProjectSchema)
62 changes: 62 additions & 0 deletions packages/schema/src/project/project.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { z } from 'zod'
import {
ProjectSchema,
CreateProjectRequestSchema,
CreateProjectResponseSchema,
UpdateProjectRequestSchema,
UpdateProjectResponseSchema,
DeleteProjectRequestSchema,
DeleteProjectResponseSchema,
GetProjectRequestSchema,
GetProjectResponseSchema,
ForkProjectRequestSchema,
ForkProjectResponseSchema,
SyncProjectRequestSchema,
SyncProjectResponseSchema,
UnlinkProjectRequestSchema,
UnlinkProjectResponseSchema,
GetForkRequestSchema,
GetForkResponseSchema,
GetAllProjectsRequestSchema,
GetAllProjectsResponseSchema
} from './project'

export type Project = z.infer<typeof ProjectSchema>

export type CreateProjectRequest = z.infer<typeof CreateProjectRequestSchema>

export type CreateProjectResponse = z.infer<typeof CreateProjectResponseSchema>

export type UpdateProjectRequest = z.infer<typeof UpdateProjectRequestSchema>

export type UpdateProjectResponse = z.infer<typeof UpdateProjectResponseSchema>

export type DeleteProjectRequest = z.infer<typeof DeleteProjectRequestSchema>

export type DeleteProjectResponse = z.infer<typeof DeleteProjectResponseSchema>

export type GetProjectRequest = z.infer<typeof GetProjectRequestSchema>

export type GetProjectResponse = z.infer<typeof GetProjectResponseSchema>

export type ForkProjectRequest = z.infer<typeof ForkProjectRequestSchema>

export type ForkProjectResponse = z.infer<typeof ForkProjectResponseSchema>

export type SyncProjectRequest = z.infer<typeof SyncProjectRequestSchema>

export type SyncProjectResponse = z.infer<typeof SyncProjectResponseSchema>

export type UnlinkProjectRequest = z.infer<typeof UnlinkProjectRequestSchema>

export type UnlinkProjectResponse = z.infer<typeof UnlinkProjectResponseSchema>

export type GetForkRequest = z.infer<typeof GetForkRequestSchema>

export type GetForkResponse = z.infer<typeof GetForkResponseSchema>

export type GetAllProjectsRequest = z.infer<typeof GetAllProjectsRequestSchema>

export type GetAllProjectsResponse = z.infer<
typeof GetAllProjectsResponseSchema
>
Loading
Loading