Skip to content

Commit 68c77cf

Browse files
committed
update server endpoints to conform to new names and types
1 parent 6643d8b commit 68c77cf

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

services/src/auth/api-access.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ export type SelectableApiKey = Selectable<Apiaccess>
88
const apiAccessIdSchema = z.number().brand('api-access')
99
export 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

1414
export 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(),

src/routes/(api)/api/[project]/[lang]/translations/+server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { validateRequestBody } from '$lib/server/request-utils'
2+
import type { ProjectId } from 'services/project/project'
23
import { authorize } from '../../../api-utils'
3-
import { translationPOSTRequestSchema, type ProjectId } from '../../../api.model'
4+
import { translationPOSTRequestSchema } from '../../../api.model'
45
import type { RequestHandler } from './$types'
56

67
export const POST: RequestHandler = async ({ params, request }) => {

src/routes/(api)/api/[project]/config/+server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { validateRequestBody } from '$lib/server/request-utils'
2+
import type { ProjectId } from 'services/project/project'
23
import { authorize } from '../../api-utils'
3-
import { projectConfigPOSTRequestSchema, type ProjectId } from '../../api.model'
4+
import { projectConfigPOSTRequestSchema } from '../../api.model'
45
import type { RequestHandler } from './$types'
56

67
export const POST: RequestHandler = async ({ params, request }) => {

src/routes/(api)/api/api-utils.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { checkApiKeyAccess } from 'services/auth/api-access.service'
2-
import type { ProjectId } from './api.model'
32
import { 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,

src/routes/(api)/api/api.model.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ export type TranslationKey = z.infer<typeof translationKeySchema>
66
const translationValueSchema = z.string().brand('translation-value')
77
export type TranslationValue = z.infer<typeof translationValueSchema>
88

9-
const projectIdSchema = z.number().brand('project-id')
10-
export type ProjectId = z.infer<typeof projectIdSchema>
11-
129
const addTranslationCommandSchema = z.object({
1310
key: translationKeySchema,
1411
value: translationValueSchema

0 commit comments

Comments
 (0)