-
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(schema): Add API KEY schemas and types
- Loading branch information
Showing
7 changed files
with
410 additions
and
24 deletions.
There are no files selected for viewing
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,64 @@ | ||
import { z } from 'zod' | ||
import { expiresAfterEnum, authorityEnum } from '@/enums' | ||
import { PageRequestSchema } from '@/pagination' | ||
|
||
export const ApiKeySchema = z.object({ | ||
id: z.string(), | ||
name: z.string(), | ||
slug: z.string(), | ||
value: z.string(), | ||
expiresAt: z | ||
.date() | ||
.transform((d) => d.toISOString()) | ||
.nullable(), | ||
createdAt: z.date().transform((d) => d.toISOString()), | ||
updatedAt: z.date().transform((d) => d.toISOString()), | ||
authorities: z.array(authorityEnum), | ||
userId: z.string() | ||
}) | ||
|
||
export const CreateApiKeyRequestSchema = z.object({ | ||
name: ApiKeySchema.shape.name, | ||
expiresAfter: expiresAfterEnum.optional(), | ||
authorities: ApiKeySchema.shape.authorities.optional() | ||
}) | ||
|
||
export const CreateApiKeyResponseSchema = ApiKeySchema | ||
|
||
export const UpdateApiKeyRequestSchema = | ||
CreateApiKeyRequestSchema.partial().extend({ | ||
apiKeySlug: ApiKeySchema.shape.slug | ||
}) | ||
|
||
export const UpdateApiKeyResponseSchema = ApiKeySchema.omit({ | ||
value: true, | ||
userId: true | ||
}) | ||
|
||
export const DeleteApiKeyRequestSchema = z.object({ | ||
apiKeySlug: ApiKeySchema.shape.slug | ||
}) | ||
|
||
export const DeleteApiKeyResponseSchema = z.void() | ||
|
||
export const GetApiKeysOfUserRequestSchema = PageRequestSchema | ||
|
||
export const GetApiKeysOfUserResponseSchema = ApiKeySchema.omit({ | ||
value: true, | ||
userId: true | ||
}).array() | ||
|
||
export const GetApiKeyRequestSchema = z.object({ | ||
apiKeySlug: ApiKeySchema.shape.slug | ||
}) | ||
|
||
export const GetApiKeyResponseSchema = ApiKeySchema.omit({ | ||
value: true, | ||
userId: true | ||
}) | ||
|
||
export const CanAccessLiveUpdatesApiKeyRequestSchema = z.void() | ||
|
||
export const CanAccessLiveUpdatesApiKeyResponseSchema = z.object({ | ||
canAccessLiveUpdates: z.boolean() | ||
}) |
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,50 @@ | ||
import { z } from 'zod' | ||
import { | ||
ApiKeySchema, | ||
CreateApiKeyRequestSchema, | ||
CreateApiKeyResponseSchema, | ||
UpdateApiKeyRequestSchema, | ||
UpdateApiKeyResponseSchema, | ||
DeleteApiKeyRequestSchema, | ||
DeleteApiKeyResponseSchema, | ||
GetApiKeysOfUserRequestSchema, | ||
GetApiKeysOfUserResponseSchema, | ||
GetApiKeyRequestSchema, | ||
GetApiKeyResponseSchema, | ||
CanAccessLiveUpdatesApiKeyRequestSchema, | ||
CanAccessLiveUpdatesApiKeyResponseSchema | ||
} from '.' | ||
|
||
export type ApiKey = z.infer<typeof ApiKeySchema> | ||
|
||
export type CreateApiKeyRequest = z.infer<typeof CreateApiKeyRequestSchema> | ||
|
||
export type CreateApiKeyResponse = z.infer<typeof CreateApiKeyResponseSchema> | ||
|
||
export type UpdateApiKeyRequest = z.infer<typeof UpdateApiKeyRequestSchema> | ||
|
||
export type UpdateApiKeyResponse = z.infer<typeof UpdateApiKeyResponseSchema> | ||
|
||
export type DeleteApiKeyRequest = z.infer<typeof DeleteApiKeyRequestSchema> | ||
|
||
export type DeleteApiKeyResponse = z.infer<typeof DeleteApiKeyResponseSchema> | ||
|
||
export type GetApiKeysOfUserRequest = z.infer< | ||
typeof GetApiKeysOfUserRequestSchema | ||
> | ||
|
||
export type GetApiKeysOfUserResponse = z.infer< | ||
typeof GetApiKeysOfUserResponseSchema | ||
> | ||
|
||
export type GetApiKeyRequest = z.infer<typeof GetApiKeyRequestSchema> | ||
|
||
export type GetApiKeyResponse = z.infer<typeof GetApiKeyResponseSchema> | ||
|
||
export type CanAccessLiveUpdatesApiKeyRequest = z.infer< | ||
typeof CanAccessLiveUpdatesApiKeyRequestSchema | ||
> | ||
|
||
export type CanAccessLiveUpdatesApiKeyResponse = z.infer< | ||
typeof CanAccessLiveUpdatesApiKeyResponseSchema | ||
> |
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
Oops, something went wrong.