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

Merged
merged 2 commits into from
Nov 22, 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
5 changes: 1 addition & 4 deletions packages/api-client/src/controllers/event.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
GetEventsRequest,
GetEventsResponse
} from '@api-client/types/event.types'
import { GetEventsRequest, GetEventsResponse } from '@keyshade/schema'
import { APIClient } from '../core/client'
import { ClientResponse } from '@keyshade/schema'
import { parseResponse } from '@api-client/core/response-parser'
Expand Down
82 changes: 0 additions & 82 deletions packages/api-client/src/types/event.types.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/schema/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@keyshade/schema",
"version": "1.0.0",
"main": "dist/src/index.js",
"main": "dist/src/index.types.js",
rajdip-b marked this conversation as resolved.
Show resolved Hide resolved
"description": "This package holds the schemas that other applications can use to validate the input data.",
"private": true,
"exports": {
Expand Down
14 changes: 14 additions & 0 deletions packages/schema/src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ export const expiresAfterEnum = z.enum(['never', '24', '168', '720', '8760'])

export const rotateAfterEnum = z.enum(['never', '24', '168', '720', '8760'])

export const eventSourceEnum = z.enum([
'SECRET',
'VARIABLE',
'ENVIRONMENT',
'PROJECT',
'WORKSPACE',
'WORKSPACE_ROLE',
'INTEGRATION'
])

export const eventTriggererEnum = z.enum(['USER', 'SYSTEM'])

export const eventSeverityEnum = z.enum(['INFO', 'WARN', 'ERROR'])

export const eventTypeEnum = z.enum([
'INVITED_TO_WORKSPACE',
'REMOVED_FROM_WORKSPACE',
Expand Down
40 changes: 40 additions & 0 deletions packages/schema/src/event/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
eventSourceEnum,
eventSeverityEnum,
eventTriggererEnum,
eventTypeEnum
} from '@/enums'
import { PageRequestSchema, PageResponseSchema } from '@/pagination'
import { z } from 'zod'

export const GetEventsRequestSchema = PageRequestSchema.extend({
workspaceSlug: z.string(),
source: eventSourceEnum.optional(),
severity: eventSeverityEnum.optional()
})

export const GetEventsResponseSchema = PageResponseSchema(
z.object({
id: z.string(),
source: eventSourceEnum,
triggerer: eventTriggererEnum,
severity: eventSeverityEnum,
type: eventTypeEnum,
timestamp: z.string(),
metadata: z.object({
name: z.string(),
projectName: z.string(),
projectId: z.string().optional(),
variableId: z.string().optional(),
environmentId: z.string().optional(),
secretId: z.string().optional(),
workspaceId: z.string().optional(),
workspaceName: z.string().optional()
}),
title: z.string(),
description: z.string(),
itemId: z.string(),
userId: z.string(),
workspaceId: z.string()
})
)
6 changes: 6 additions & 0 deletions packages/schema/src/event/index.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { z } from 'zod'
import { GetEventsRequestSchema, GetEventsResponseSchema } from '.'

export type GetEventsRequest = z.infer<typeof GetEventsRequestSchema>

export type GetEventsResponse = z.infer<typeof GetEventsResponseSchema>
1 change: 1 addition & 0 deletions packages/schema/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export * from './user'
export * from './variable'
export * from './workspace'
export * from './workspace-role'
export * from './event'
1 change: 1 addition & 0 deletions packages/schema/src/index.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export * from './secret/index.types'
export * from './user/index.types'
export * from './workspace/index.types'
export * from './variable/index.types'
export * from './event/index.types'

export type TCreateApiKey = z.infer<typeof CreateApiKeySchema>
export type TUpdateApiKey = z.infer<typeof UpdateApiKeySchema>
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/src/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const ProjectSchema = z
privateKey: z.string(),
storePrivateKey: z.boolean(),
isDisabled: z.boolean(),
accessLevel: z.string(),
accessLevel: projectAccessLevelEnum,
pendingCreation: z.boolean(),
isForked: z.boolean(),
lastUpdatedById: z.string(),
Expand Down
149 changes: 149 additions & 0 deletions packages/schema/tests/enums.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import { z } from 'zod'

Check warning on line 1 in packages/schema/tests/enums.test.ts

View workflow job for this annotation

GitHub Actions / Validate Schema

'z' is defined but never used
import {
integrationTypeEnum,
expiresAfterEnum,
rotateAfterEnum,
eventSourceEnum,
eventTriggererEnum,
eventSeverityEnum,
eventTypeEnum,
authorityEnum,
projectAccessLevelEnum
} from '@//enums'

describe('Enums Tests', () => {
it('integrationTypeEnum should have correct values', () => {
expect(integrationTypeEnum.options).toEqual([
'DISCORD',
'SLACK',
'GITHUB',
'GITLAB'
])
})

it('expiresAfterEnum should have correct values', () => {
expect(expiresAfterEnum.options).toEqual([
'never',
'24',
'168',
'720',
'8760'
])
})

it('rotateAfterEnum should have correct values', () => {
expect(rotateAfterEnum.options).toEqual([
'never',
'24',
'168',
'720',
'8760'
])
})

it('eventSourceEnum should have correct values', () => {
expect(eventSourceEnum.options).toEqual([
'SECRET',
'VARIABLE',
'ENVIRONMENT',
'PROJECT',
'WORKSPACE',
'WORKSPACE_ROLE',
'INTEGRATION'
])
})

it('eventTriggererEnum should have correct values', () => {
expect(eventTriggererEnum.options).toEqual(['USER', 'SYSTEM'])
})

it('eventSeverityEnum should have correct values', () => {
expect(eventSeverityEnum.options).toEqual(['INFO', 'WARN', 'ERROR'])
})

it('eventTypeEnum should have correct values', () => {
expect(eventTypeEnum.options).toEqual([
'INVITED_TO_WORKSPACE',
'REMOVED_FROM_WORKSPACE',
'ACCEPTED_INVITATION',
'DECLINED_INVITATION',
'CANCELLED_INVITATION',
'LEFT_WORKSPACE',
'WORKSPACE_MEMBERSHIP_UPDATED',
'WORKSPACE_UPDATED',
'WORKSPACE_CREATED',
'WORKSPACE_ROLE_CREATED',
'WORKSPACE_ROLE_UPDATED',
'WORKSPACE_ROLE_DELETED',
'PROJECT_CREATED',
'PROJECT_UPDATED',
'PROJECT_DELETED',
'SECRET_UPDATED',
'SECRET_DELETED',
'SECRET_ADDED',
'VARIABLE_UPDATED',
'VARIABLE_DELETED',
'VARIABLE_ADDED',
'ENVIRONMENT_UPDATED',
'ENVIRONMENT_DELETED',
'ENVIRONMENT_ADDED',
'INTEGRATION_ADDED',
'INTEGRATION_UPDATED',
'INTEGRATION_DELETED'
])
})

it('authorityEnum should have correct values', () => {
expect(authorityEnum.options).toEqual([
'CREATE_PROJECT',
'READ_USERS',
'ADD_USER',
'REMOVE_USER',
'UPDATE_USER_ROLE',
'READ_WORKSPACE',
'UPDATE_WORKSPACE',
'DELETE_WORKSPACE',
'CREATE_WORKSPACE_ROLE',
'READ_WORKSPACE_ROLE',
'UPDATE_WORKSPACE_ROLE',
'DELETE_WORKSPACE_ROLE',
'WORKSPACE_ADMIN',
'READ_PROJECT',
'UPDATE_PROJECT',
'DELETE_PROJECT',
'CREATE_SECRET',
'READ_SECRET',
'UPDATE_SECRET',
'DELETE_SECRET',
'CREATE_ENVIRONMENT',
'READ_ENVIRONMENT',
'UPDATE_ENVIRONMENT',
'DELETE_ENVIRONMENT',
'CREATE_VARIABLE',
'READ_VARIABLE',
'UPDATE_VARIABLE',
'DELETE_VARIABLE',
'CREATE_INTEGRATION',
'READ_INTEGRATION',
'UPDATE_INTEGRATION',
'DELETE_INTEGRATION',
'CREATE_WORKSPACE',
'CREATE_API_KEY',
'READ_API_KEY',
'UPDATE_API_KEY',
'DELETE_API_KEY',
'UPDATE_PROFILE',
'READ_SELF',
'UPDATE_SELF',
'READ_EVENT'
])
})

it('projectAccessLevelEnum should have correct values', () => {
expect(projectAccessLevelEnum.options).toEqual([
'GLOBAL',
'INTERNAL',
'PRIVATE'
])
})
})
Loading
Loading