File tree Expand file tree Collapse file tree 3 files changed +54
-1
lines changed Expand file tree Collapse file tree 3 files changed +54
-1
lines changed Original file line number Diff line number Diff line change 1- import { projectHasKey } from './api-key.repository'
1+ import {
2+ createApiKey ,
3+ getApiKeysForProject ,
4+ projectHasKey ,
5+ setApiKeyName
6+ } from './api-key.repository'
27
38export const checkApiKeyAccess = async ( apiKey : string , projectId : number ) : Promise < boolean > => {
49 return await projectHasKey ( projectId , apiKey )
510}
11+
12+ export const addApiKey = async ( projectId : number ) : Promise < string > => {
13+ const key = await createApiKey ( projectId )
14+ return key . key
15+ }
16+
17+ export const changeApiKeyName = async ( apiKeyId : number , name : string ) => {
18+ await setApiKeyName ( apiKeyId , name )
19+ }
20+
21+ export const listApiKeys = async ( projectId : number ) : Promise < string [ ] > => {
22+ const result = await getApiKeysForProject ( projectId )
23+ return result . map ( ( it ) => it . key )
24+ }
Original file line number Diff line number Diff line change 11import type { Insertable , Selectable } from 'kysely'
22import type { Apikeys } from 'kysely-codegen'
3+ import { z } from 'zod'
34
45export type ApiKeyCreationParams = Insertable < Omit < Apikeys , 'id' | 'created_at' > >
56export type SelectableApiKey = Selectable < Apikeys >
7+
8+ const apiKeyIdSchema = z . number ( ) . brand ( 'apiKeyId' )
9+ export type ApiKeyId = z . infer < typeof apiKeyIdSchema >
10+
11+ const apiKeyKeySchema = z . string ( ) . uuid ( ) . brand ( 'apiKeyKey' )
12+ export type ApiKeyKey = z . infer < typeof apiKeyKeySchema >
13+
14+ const apiKeySchema = z . object ( {
15+ id : apiKeyIdSchema ,
16+ key : apiKeyKeySchema ,
17+ name : z . string ( ) ,
18+ project_id : z . number ( ) ,
19+ created_at : z . date ( ) ,
20+ updated_at : z . date ( )
21+ } )
22+ export type ApiKey = z . infer < typeof apiKeySchema >
23+
24+ const frontendApiKeySchema = apiKeySchema . omit ( {
25+ id : true
26+ } )
Original file line number Diff line number Diff line change 11import type { Insertable , Selectable } from 'kysely'
22import type { Projects } from 'kysely-codegen'
3+ import { z } from 'zod'
34
45export type PojectCreationParams = Insertable <
56 Omit < Projects , 'id' | 'created_at' | 'updated_at' | 'base_language' >
67>
78export type SelectableProject = Selectable < Projects >
9+
10+ const projectIdSchema = z . number ( ) . brand ( 'projectId' )
11+ export type ProjectId = z . infer < typeof projectIdSchema >
12+
13+ const projectSchema = z . object ( {
14+ id : projectIdSchema ,
15+ created_at : z . string ( ) ,
16+ updated_at : z . string ( ) ,
17+ name : z . string ( ) ,
18+ base_language : z . number ( ) . nullable ( )
19+ } )
20+ export type Project = z . infer < typeof projectSchema >
You can’t perform that action at this time.
0 commit comments