Skip to content

Commit

Permalink
feat(schema, api-client): Migrate integration schemas and types to @k…
Browse files Browse the repository at this point in the history
…eyshade/schema (#547)
  • Loading branch information
muntaxir4 authored Nov 22, 2024
1 parent a3267de commit 08868c3
Show file tree
Hide file tree
Showing 9 changed files with 490 additions and 140 deletions.
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 @@ -9,7 +9,7 @@ import {
GetIntegrationResponse,
UpdateIntegrationRequest,
UpdateIntegrationResponse
} from '@api-client/types/integration.types'
} from '@keyshade/schema'
import { APIClient } from '@api-client/core/client'
import { ClientResponse } from '@keyshade/schema'
import { parseResponse } from '@api-client/core/response-parser'
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
Expand Up @@ -45,7 +45,7 @@ export default class UserController {
headers?: Record<string, string>
): Promise<ClientResponse<ValidateEmailChangeOTPResponse>> {
const response = await this.apiClient.post(
`./api/user/validate-email-change-otp?otp=${request.otp}`,
`/api/user/validate-email-change-otp?otp=${request.otp}`,
request,
headers
)
Expand Down
89 changes: 0 additions & 89 deletions packages/api-client/src/types/integration.types.d.ts

This file was deleted.

5 changes: 1 addition & 4 deletions packages/schema/src/index.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { z } from 'zod'
import { CreateApiKeySchema, UpdateApiKeySchema } from './api-key'
import { CreateIntegrationSchema, UpdateIntegrationSchema } from './integration'
import {
CreateWorkspaceRoleSchema,
UpdateWorkspaceRoleSchema
Expand All @@ -15,12 +14,10 @@ export * from './user/index.types'
export * from './workspace/index.types'
export * from './variable/index.types'
export * from './event/index.types'
export * from './integration/index.types'

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

export type TCreateIntegration = z.infer<typeof CreateIntegrationSchema>
export type TUpdateIntegration = z.infer<typeof UpdateIntegrationSchema>

export type TCreateWorkspaceRole = z.infer<typeof CreateWorkspaceRoleSchema>
export type TUpdateWorkspaceRole = z.infer<typeof UpdateWorkspaceRoleSchema>
13 changes: 0 additions & 13 deletions packages/schema/src/integration.ts

This file was deleted.

64 changes: 64 additions & 0 deletions packages/schema/src/integration/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { z } from 'zod'
import { PageRequestSchema, PageResponseSchema } from '@/pagination'
import { eventTypeEnum, integrationTypeEnum } from '@/enums'
import { WorkspaceSchema } from '@/workspace'
import { BaseProjectSchema } from '@/project'
import { EnvironmentSchema } from '@/environment'

export const IntegrationSchema = z.object({
id: z.string(),
name: z.string(),
slug: z.string(),
metadata: z.record(z.string()),
createdAt: z.string(),
updatedAt: z.string(),
type: integrationTypeEnum,
notifyOn: z.array(eventTypeEnum),
workspaceId: WorkspaceSchema.shape.id,
projectId: BaseProjectSchema.shape.id,
environmentId: EnvironmentSchema.shape.id
})

export const CreateIntegrationRequestSchema = z.object({
workspaceSlug: WorkspaceSchema.shape.slug,
projectSlug: BaseProjectSchema.shape.slug.optional(),
name: z.string(),
type: IntegrationSchema.shape.type,
notifyOn: IntegrationSchema.shape.notifyOn.min(1).optional(),
metadata: z.record(z.string()),
environmentSlug: EnvironmentSchema.shape.slug.optional()
})

export const CreateIntegrationResponseSchema = IntegrationSchema

export const UpdateIntegrationRequestSchema =
CreateIntegrationRequestSchema.partial()
.omit({
workspaceSlug: true
})
.extend({
integrationSlug: IntegrationSchema.shape.slug
})

export const UpdateIntegrationResponseSchema = IntegrationSchema

export const DeleteIntegrationRequestSchema = z.object({
integrationSlug: IntegrationSchema.shape.slug
})

export const DeleteIntegrationResponseSchema = z.void()

export const GetIntegrationRequestSchema = z.object({
integrationSlug: IntegrationSchema.shape.slug
})

export const GetIntegrationResponseSchema = IntegrationSchema.extend({
workspace: WorkspaceSchema
})

export const GetAllIntegrationRequestSchema = PageRequestSchema.extend({
workspaceSlug: WorkspaceSchema.shape.slug
})

export const GetAllIntegrationResponseSchema =
PageResponseSchema(IntegrationSchema)
54 changes: 54 additions & 0 deletions packages/schema/src/integration/index.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {
IntegrationSchema,
CreateIntegrationRequestSchema,
CreateIntegrationResponseSchema,
UpdateIntegrationRequestSchema,
UpdateIntegrationResponseSchema,
DeleteIntegrationRequestSchema,
DeleteIntegrationResponseSchema,
GetIntegrationRequestSchema,
GetIntegrationResponseSchema,
GetAllIntegrationRequestSchema,
GetAllIntegrationResponseSchema
} from '.'
import { z } from 'zod'

export type Integration = z.infer<typeof IntegrationSchema>

export type CreateIntegrationRequest = z.infer<
typeof CreateIntegrationRequestSchema
>

export type CreateIntegrationResponse = z.infer<
typeof CreateIntegrationResponseSchema
>

export type UpdateIntegrationRequest = z.infer<
typeof UpdateIntegrationRequestSchema
>

export type UpdateIntegrationResponse = z.infer<
typeof UpdateIntegrationResponseSchema
>

export type DeleteIntegrationRequest = z.infer<
typeof DeleteIntegrationRequestSchema
>

export type DeleteIntegrationResponse = z.infer<
typeof DeleteIntegrationResponseSchema
>

export type GetIntegrationRequest = z.infer<typeof GetIntegrationRequestSchema>

export type GetIntegrationResponse = z.infer<
typeof GetIntegrationResponseSchema
>

export type GetAllIntegrationRequest = z.infer<
typeof GetAllIntegrationRequestSchema
>

export type GetAllIntegrationResponse = z.infer<
typeof GetAllIntegrationResponseSchema
>
44 changes: 22 additions & 22 deletions packages/schema/src/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ import { PageRequestSchema, PageResponseSchema } from '@/pagination'
import { CreateEnvironmentRequestSchema } 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: projectAccessLevelEnum,
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 BaseProjectSchema = 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()
})

export const ProjectSchema = BaseProjectSchema.refine((obj) =>
obj.isForked ? obj.forkedFromId !== null : obj.forkedFromId === null
)

export const CreateProjectRequestSchema = z.object({
name: z.string(),
Expand Down
Loading

0 comments on commit 08868c3

Please sign in to comment.