File tree Expand file tree Collapse file tree 5 files changed +16
-13
lines changed Expand file tree Collapse file tree 5 files changed +16
-13
lines changed Original file line number Diff line number Diff line change @@ -8,12 +8,12 @@ export type SelectableApiKey = Selectable<Apiaccess>
88const apiAccessIdSchema = z . number ( ) . brand ( 'api-access' )
99export type ApiAccessId = z . infer < typeof apiAccessIdSchema >
1010
11- const apiKeyKeySchema = z . string ( ) . uuid ( ) . brand ( 'api-key' )
12- export type ApiKey = z . infer < typeof apiKeyKeySchema >
11+ export const apiKeySchema = z . string ( ) . uuid ( ) . brand ( 'api-key' )
12+ export type ApiKey = z . infer < typeof apiKeySchema >
1313
1414export const apiAccessSchema = z . object ( {
1515 id : apiAccessIdSchema ,
16- apikey : apiKeyKeySchema ,
16+ apikey : apiKeySchema ,
1717 name : z . string ( ) ,
1818 project_id : z . number ( ) ,
1919 created_at : z . date ( ) ,
Original file line number Diff line number Diff line change 11import { validateRequestBody } from '$lib/server/request-utils'
2+ import type { ProjectId } from 'services/project/project'
23import { authorize } from '../../../api-utils'
3- import { translationPOSTRequestSchema , type ProjectId } from '../../../api.model'
4+ import { translationPOSTRequestSchema } from '../../../api.model'
45import type { RequestHandler } from './$types'
56
67export const POST : RequestHandler = async ( { params, request } ) => {
Original file line number Diff line number Diff line change 11import { validateRequestBody } from '$lib/server/request-utils'
2+ import type { ProjectId } from 'services/project/project'
23import { authorize } from '../../api-utils'
3- import { projectConfigPOSTRequestSchema , type ProjectId } from '../../api.model'
4+ import { projectConfigPOSTRequestSchema } from '../../api.model'
45import type { RequestHandler } from './$types'
56
67export const POST : RequestHandler = async ( { params, request } ) => {
Original file line number Diff line number Diff line change 11import { checkApiKeyAccess } from 'services/auth/api-access.service'
2- import type { ProjectId } from './api.model'
32import { error } from '@sveltejs/kit'
3+ import { apiKeySchema } from 'services/auth/api-access'
4+ import type { ProjectId } from 'services/project/project'
45
5- export const authorize = async ( req : Request , project : ProjectId ) => {
6- const apiKey = req . headers . get ( 'Authorization' )
7- if ( ! apiKey ) {
6+ export const authorize = async ( req : Request , projectId : ProjectId ) => {
7+ if ( req . headers . get ( 'Authorization' ) ) {
88 error ( 401 , 'No API key provided in the Authorization header' )
99 }
10- const hasAccess = await checkApiKeyAccess ( apiKey , project )
10+ const parsedApiKey = apiKeySchema . safeParse ( req . headers . get ( 'Authorization' ) )
11+ if ( parsedApiKey . error ) {
12+ error ( 400 , 'The provided API key does not conform to the correct schema' )
13+ }
14+ const hasAccess = await checkApiKeyAccess ( parsedApiKey . data , projectId )
1115 if ( ! hasAccess ) {
1216 error (
1317 403 ,
Original file line number Diff line number Diff line change @@ -6,9 +6,6 @@ export type TranslationKey = z.infer<typeof translationKeySchema>
66const translationValueSchema = z . string ( ) . brand ( 'translation-value' )
77export type TranslationValue = z . infer < typeof translationValueSchema >
88
9- const projectIdSchema = z . number ( ) . brand ( 'project-id' )
10- export type ProjectId = z . infer < typeof projectIdSchema >
11-
129const addTranslationCommandSchema = z . object ( {
1310 key : translationKeySchema ,
1411 value : translationValueSchema
You can’t perform that action at this time.
0 commit comments