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

Merged
merged 6 commits into from
Nov 18, 2024
Merged
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/secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
RollBackSecretResponse,
UpdateSecretRequest,
UpdateSecretResponse
} from '@api-client/types/secret.types'
} from '@keyshade/schema'
import { parsePaginationUrl } from '@api-client/core/pagination-parser'

export default class SecretController {
Expand Down
124 changes: 0 additions & 124 deletions packages/api-client/src/types/secret.types.d.ts

This file was deleted.

4 changes: 1 addition & 3 deletions packages/schema/src/index.types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { z } from 'zod'
import { CreateApiKeySchema, UpdateApiKeySchema } from './api-key'
import { CreateIntegrationSchema, UpdateIntegrationSchema } from './integration'
import { CreateSecretSchema, UpdateSecretSchema } from './secret'
import { CreateVariableSchema, UpdateVariableSchema } from './variable'
import {
CreateWorkspaceRoleSchema,
Expand All @@ -24,8 +23,7 @@ export type TUpdateIntegration = z.infer<typeof UpdateIntegrationSchema>

export * from './project/index.types'

export type TCreateSecret = z.infer<typeof CreateSecretSchema>
export type TUpdateSecret = z.infer<typeof UpdateSecretSchema>
export * from './secret/index.types'

export * from './user/index.types'

Expand Down
16 changes: 0 additions & 16 deletions packages/schema/src/secret.ts

This file was deleted.

141 changes: 141 additions & 0 deletions packages/schema/src/secret/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import { z } from 'zod'
import { PageRequestSchema, PageResponseSchema } from '@/pagination/pagination'
import { rotateAfterEnum } from '@/enums'

export const SecretSchema = z.object({
id: z.string(),
name: z.string(),
slug: z.string(),
createdAt: z.string(),
updatedAt: z.string(),
rotateAt: z.string().nullable(),
note: z.string().nullable(),
lastUpdatedById: z.string(),
projectId: z.string(),
project: z.object({
workspaceId: z.string()
}),
versions: z.array(
z.object({
id: z.string().optional(),
environmentId: z.string(),
value: z.string(),
environment: z.object({
id: z.string(),
slug: z.string()
})
})
)
})

export const CreateSecretRequestSchema = z.object({
projectSlug: z.string(),
name: z.string(),
note: z.string().optional(),
rotateAfter: rotateAfterEnum.optional(),
entries: z
.array(
z.object({
value: z.string(),
environmentSlug: z.string()
})
)
.optional()
})

export const CreateSecretResponseSchema = SecretSchema

export const UpdateSecretRequestSchema =
CreateSecretRequestSchema.partial().extend({
secretSlug: z.string()
})

export const UpdateSecretResponseSchema = z.object({
secret: z.object({
id: z.string(),
name: z.string(),
slug: z.string(),
note: z.string().nullable()
}),
updatedVersions: z.array(
z.object({
id: z.string().optional(),
environmentId: z.string(),
environment: z.object({
id: z.string(),
slug: z.string()
}),
value: z.string()
})
)
})

export const DeleteSecretRequestSchema = z.object({
secretSlug: z.string()
})

export const DeleteSecretResponseSchema = z.void()

export const RollBackSecretRequestSchema = z.object({
environmentSlug: z.string(),
version: z.number(),
secretSlug: z.string()
})

export const RollBackSecretResponseSchema = z.object({
count: z.string()
})

export const GetAllSecretsOfProjectRequestSchema = PageRequestSchema.extend({
projectSlug: z.string()
})

export const GetAllSecretsOfProjectResponseSchema = PageResponseSchema(
z.object({
secret: SecretSchema.omit({ versions: true, project: true }).extend({
lastUpdatedBy: z.object({
id: z.string(),
name: z.string()
})
}),
values: z.object({
environment: z.object({
id: z.string(),
name: z.string(),
slug: z.string()
}),
value: z.string(),
version: z.number()
})
})
)

export const GetAllSecretsOfEnvironmentRequestSchema = z.object({
projectSlug: z.string(),
environmentSlug: z.string()
})

export const GetAllSecretsOfEnvironmentResponseSchema = z.array(
z.object({
name: z.string(),
value: z.string(),
isPlaintext: z.boolean()
})
)

export const GetRevisionsOfSecretRequestSchema =
PageRequestSchema.partial().extend({
secretSlug: z.string(),
environmentSlug: z.string()
})

export const GetRevisionsOfSecretResponseSchema = PageResponseSchema(
z.object({
id: z.string(),
value: z.string(),
version: z.number(),
createdOn: z.string(),
createdById: z.string(),
environmentId: z.string()
})
)
62 changes: 62 additions & 0 deletions packages/schema/src/secret/index.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { z } from 'zod'
import {
SecretSchema,
CreateSecretRequestSchema,
CreateSecretResponseSchema,
UpdateSecretRequestSchema,
UpdateSecretResponseSchema,
DeleteSecretRequestSchema,
DeleteSecretResponseSchema,
RollBackSecretRequestSchema,
RollBackSecretResponseSchema,
GetAllSecretsOfProjectRequestSchema,
GetAllSecretsOfProjectResponseSchema,
GetAllSecretsOfEnvironmentRequestSchema,
GetAllSecretsOfEnvironmentResponseSchema,
GetRevisionsOfSecretRequestSchema,
GetRevisionsOfSecretResponseSchema
} from '.'

export type Secret = z.infer<typeof SecretSchema>

export type CreateSecretRequest = z.infer<typeof CreateSecretRequestSchema>

export type CreateSecretResponse = z.infer<typeof CreateSecretResponseSchema>

export type UpdateSecretRequest = z.infer<typeof UpdateSecretRequestSchema>

export type UpdateSecretResponse = z.infer<typeof UpdateSecretResponseSchema>

export type DeleteSecretRequest = z.infer<typeof DeleteSecretRequestSchema>

export type DeleteSecretResponse = z.infer<typeof DeleteSecretResponseSchema>

export type RollBackSecretRequest = z.infer<typeof RollBackSecretRequestSchema>

export type RollBackSecretResponse = z.infer<
typeof RollBackSecretResponseSchema
>

export type GetAllSecretsOfProjectRequest = z.infer<
typeof GetAllSecretsOfProjectRequestSchema
>

export type GetAllSecretsOfProjectResponse = z.infer<
typeof GetAllSecretsOfProjectResponseSchema
>

export type GetAllSecretsOfEnvironmentRequest = z.infer<
typeof GetAllSecretsOfEnvironmentRequestSchema
>

export type GetAllSecretsOfEnvironmentResponse = z.infer<
typeof GetAllSecretsOfEnvironmentResponseSchema
>

export type GetRevisionsOfSecretRequest = z.infer<
typeof GetRevisionsOfSecretRequestSchema
>

export type GetRevisionsOfSecretResponse = z.infer<
typeof GetRevisionsOfSecretResponseSchema
>
Loading
Loading