-
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(schema, api-client): Add workspace's schemas and types in schema…
… package - Export zod schemas and types for workspace and include its tests. - Add extra schemas required in modules PageRequest. - Add schema package as dependency for api-client and replace existing dependency on workspace's types.
- Loading branch information
Showing
10 changed files
with
934 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,60 @@ | ||
import { z } from 'zod' | ||
|
||
export const PageRequestSchema = z.object({ | ||
page: z.number().optional(), | ||
limit: z.number().optional(), | ||
sort: z.string().optional(), | ||
order: z.string().optional(), | ||
search: z.string().optional() | ||
}) | ||
export type PageRequest = z.infer<typeof PageRequestSchema> | ||
|
||
export const PageResponseSchema = <T>(itemSchema: z.ZodType<T>) => | ||
z.object({ | ||
items: z.array(itemSchema), | ||
metadata: z.object({ | ||
page: z.number(), | ||
perPage: z.number(), | ||
pageCount: z.number(), | ||
totalCount: z.number(), | ||
links: z.object({ | ||
self: z.string(), | ||
first: z.string(), | ||
previous: z.string().nullable(), | ||
next: z.string().nullable(), | ||
last: z.string() | ||
}) | ||
}) | ||
}) | ||
export type PageResponse<T> = z.infer<ReturnType<typeof PageResponseSchema<T>>> | ||
|
||
export const ResponseErrorSchema = z.object({ | ||
message: z.string(), | ||
error: z.string(), | ||
statusCode: z.number() | ||
}) | ||
export type ResponseError = z.infer<typeof ResponseErrorSchema> | ||
|
||
export const ClientResponseSchema = <T>(dataSchema: z.ZodType<T>) => | ||
z.object({ | ||
success: z.boolean(), | ||
error: ResponseErrorSchema.nullable(), | ||
data: dataSchema.nullable() | ||
}) | ||
export type ClientResponse<T> = z.infer< | ||
ReturnType<typeof ClientResponseSchema<T>> | ||
> | ||
|
||
//Export Other Schemas | ||
export * from './api-key' | ||
export * from './environment' | ||
export * from './integration' | ||
export * from './project' | ||
export * from './secret' | ||
export * from './variable' | ||
export * from './workspace' | ||
export * from './workspace-role' | ||
|
||
export * from './workspace/workspace' | ||
export * from './workspace/workspace.types' | ||
|
||
export * from './workspace-role' | ||
export * from './enums' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import { z } from 'zod' | ||
import { PageRequestSchema, PageResponseSchema } from '../index' | ||
|
||
export const CreateWorkspaceSchema = z.object({ | ||
name: z.string(), | ||
icon: z.string().optional(), | ||
isDefault: z.boolean().optional() | ||
}) | ||
|
||
export const UpdateWorkspaceSchema = CreateWorkspaceSchema.partial() | ||
|
||
export const InviteMemberSchema = z.object({ | ||
email: z.string(), | ||
roleIds: z.array(z.string()).optional() | ||
}) | ||
|
||
//Request and Response types | ||
export const WorkspaceSchema = z.object({ | ||
id: z.string(), | ||
name: z.string(), | ||
slug: z.string(), | ||
icon: z.string(), | ||
isFreeTier: z.boolean(), | ||
createdAt: z.string(), | ||
updatedAt: z.string(), | ||
ownerId: z.string(), | ||
isDefault: z.boolean(), | ||
lastUpdatedBy: z.string() | ||
}) | ||
|
||
export const CreateWorkspaceRequestSchema = z.object({ | ||
name: z.string(), | ||
icon: z.string().optional() | ||
}) | ||
|
||
export const CreateWorkspaceResponseSchema = WorkspaceSchema | ||
|
||
export const UpdateWorkspaceRequestSchema = | ||
CreateWorkspaceRequestSchema.partial().extend({ | ||
workspaceSlug: z.string() | ||
}) | ||
|
||
export const UpdateWorkspaceResponseSchema = WorkspaceSchema | ||
|
||
export const DeleteWorkspaceRequestSchema = z.object({ | ||
workspaceSlug: z.string() | ||
}) | ||
|
||
export const DeleteWorkspaceResponseSchema = z.object({}).strict() | ||
|
||
export const GetWorkspaceRequestSchema = z.object({ | ||
workspaceSlug: z.string() | ||
}) | ||
|
||
export const GetWorkspaceResponseSchema = WorkspaceSchema | ||
|
||
export const GetAllWorkspacesOfUserRequestSchema = PageRequestSchema | ||
|
||
export const GetAllWorkspacesOfUserResponseSchema = | ||
PageResponseSchema(WorkspaceSchema) | ||
|
||
export const ExportDataRequestSchema = z.object({ | ||
workspaceSlug: z.string() | ||
}) | ||
|
||
export const ExportDataResponseSchema = z.object({ | ||
name: z.string(), | ||
icon: z.string(), | ||
workspaceRoles: z.array( | ||
z.object({ | ||
name: z.string(), | ||
description: z.string(), | ||
colorCode: z.string(), | ||
hasAdminAuthority: z.boolean(), | ||
authorities: z.array(z.string()) | ||
}) | ||
), | ||
projects: z.array( | ||
z.object({ | ||
name: z.string(), | ||
description: z.string(), | ||
publicKey: z.string(), | ||
privateKey: z.string(), | ||
storePrivateKey: z.boolean(), | ||
accessLevel: z.enum(['GLOBAL', 'PRIVATE', 'INTERNAL']), | ||
environments: z.array( | ||
z.object({ | ||
name: z.string(), | ||
description: z.string() | ||
}) | ||
), | ||
secrets: z.array( | ||
z.object({ | ||
name: z.string(), | ||
note: z.string(), | ||
rotateAt: z.string(), | ||
versions: z.array( | ||
z.object({ | ||
value: z.string(), | ||
version: z.number() | ||
}) | ||
) | ||
}) | ||
), | ||
variables: z.array( | ||
z.object({ | ||
name: z.string(), | ||
note: z.string(), | ||
versions: z.array( | ||
z.object({ | ||
value: z.string(), | ||
version: z.number() | ||
}) | ||
) | ||
}) | ||
) | ||
}) | ||
) | ||
}) | ||
|
||
export const GlobalSearchRequestSchema = z.object({ | ||
workspaceSlug: z.string(), | ||
search: z.string() | ||
}) | ||
|
||
export const GlobalSearchResponseSchema = z.object({ | ||
projects: z.array( | ||
z.object({ | ||
slug: z.string(), | ||
name: z.string(), | ||
description: z.string() | ||
}) | ||
), | ||
environments: z.array( | ||
z.object({ | ||
slug: z.string(), | ||
name: z.string(), | ||
description: z.string() | ||
}) | ||
), | ||
secrets: z.array( | ||
z.object({ | ||
slug: z.string(), | ||
name: z.string(), | ||
note: z.string() | ||
}) | ||
), | ||
variables: z.array( | ||
z.object({ | ||
slug: z.string(), | ||
name: z.string(), | ||
note: z.string() | ||
}) | ||
) | ||
}) |
Oops, something went wrong.