diff --git a/packages/cloud/package.json b/packages/cloud/package.json index f303957c6..b6737a80a 100644 --- a/packages/cloud/package.json +++ b/packages/cloud/package.json @@ -28,7 +28,8 @@ "dotenv": "^16.0.0", "find-up": "^6.3.0", "http-proxy": "^1.18.1", - "mime-types": "^2.1.35" + "mime-types": "^2.1.35", + "zod": "^3.20.2" }, "devDependencies": { "@silverhand/eslint-config": "2.0.1", diff --git a/packages/cloud/src/routes/tenants.ts b/packages/cloud/src/routes/tenants.ts index d6943907a..8a7d3b892 100644 --- a/packages/cloud/src/routes/tenants.ts +++ b/packages/cloud/src/routes/tenants.ts @@ -1,4 +1,5 @@ import { Router } from '@withtyped/server'; +import { z } from 'zod'; import { client } from '#src/queries/index.js'; import { createTenantsQueries } from '#src/queries/tenants.js'; @@ -6,15 +7,19 @@ import { getTenantIdFromManagementApiIndicator } from '#src/utils/tenant.js'; const { getManagementApiLikeIndicatorsForUser } = createTenantsQueries(client); -export const tenants = new Router('/tenants').get('/', {}, async (context, next) => { - const { rows } = await getManagementApiLikeIndicatorsForUser('some_user_id'); +export const tenants = new Router('/tenants').get( + '/', + { response: z.object({ id: z.string(), indicator: z.string() }).array() }, + async (context, next) => { + const { rows } = await getManagementApiLikeIndicatorsForUser('some_user_id'); - const tenants = rows - .map(({ indicator }) => ({ - id: getTenantIdFromManagementApiIndicator(indicator), - indicator, - })) - .filter((tenant): tenant is { id: string; indicator: string } => Boolean(tenant.id)); + const tenants = rows + .map(({ indicator }) => ({ + id: getTenantIdFromManagementApiIndicator(indicator), + indicator, + })) + .filter((tenant): tenant is { id: string; indicator: string } => Boolean(tenant.id)); - return next({ ...context, json: tenants }); -}); + return next({ ...context, json: tenants }); + } +); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 054a3f029..7b55b4b6e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -126,6 +126,7 @@ importers: nodemon: ^2.0.19 prettier: ^2.8.1 typescript: ^4.9.4 + zod: ^3.20.2 dependencies: '@logto/schemas': link:../schemas '@logto/shared': link:../shared @@ -137,6 +138,7 @@ importers: find-up: 6.3.0 http-proxy: 1.18.1 mime-types: 2.1.35 + zod: 3.20.2 devDependencies: '@silverhand/eslint-config': 2.0.1_kjzxg5porcw5dx54sezsklj5cy '@silverhand/ts-config': 2.0.2_typescript@4.9.4