11import { FastifyPluginAsync } from "fastify" ;
22import { AppRoles } from "../../common/roles.js" ;
3- import { z } from "zod" ;
43import { zodToJsonSchema } from "zod-to-json-schema" ;
54import { addToTenant , getEntraIdToken } from "../functions/entraId.js" ;
65import {
@@ -18,33 +17,13 @@ import {
1817} from "@aws-sdk/client-dynamodb" ;
1918import { genericConfig } from "../../common/config.js" ;
2019import { marshall , unmarshall } from "@aws-sdk/util-dynamodb" ;
21-
22- const invitePostRequestSchema = z . object ( {
23- emails : z . array ( z . string ( ) ) ,
24- } ) ;
25- export type InviteUserPostRequest = z . infer < typeof invitePostRequestSchema > ;
26-
27- const groupMappingCreatePostSchema = z . object ( {
28- roles : z
29- . array ( z . nativeEnum ( AppRoles ) )
30- . min ( 1 )
31- . refine ( ( items ) => new Set ( items ) . size === items . length , {
32- message : "All roles must be unique, no duplicate values allowed" ,
33- } ) ,
34- } ) ;
35-
36- export type GroupMappingCreatePostRequest = z . infer <
37- typeof groupMappingCreatePostSchema
38- > ;
39-
40- const invitePostResponseSchema = zodToJsonSchema (
41- z . object ( {
42- success : z . array ( z . object ( { email : z . string ( ) } ) ) . optional ( ) ,
43- failure : z
44- . array ( z . object ( { email : z . string ( ) , message : z . string ( ) } ) )
45- . optional ( ) ,
46- } ) ,
47- ) ;
20+ import {
21+ InviteUserPostRequest ,
22+ invitePostRequestSchema ,
23+ GroupMappingCreatePostRequest ,
24+ groupMappingCreatePostSchema ,
25+ invitePostResponseSchema ,
26+ } from "../../common/types/iam.js" ;
4827
4928const dynamoClient = new DynamoDBClient ( {
5029 region : genericConfig . AwsRegion ,
@@ -155,13 +134,13 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
155134 "/inviteUsers" ,
156135 {
157136 schema : {
158- response : { 200 : invitePostResponseSchema } ,
137+ response : { 200 : zodToJsonSchema ( invitePostResponseSchema ) } ,
159138 } ,
160139 preValidation : async ( request , reply ) => {
161140 await fastify . zodValidateBody ( request , reply , invitePostRequestSchema ) ;
162141 } ,
163142 onRequest : async ( request , reply ) => {
164- await fastify . authorize ( request , reply , [ AppRoles . SSO_INVITE_USER ] ) ;
143+ await fastify . authorize ( request , reply , [ AppRoles . IAM_INVITE_ONLY ] ) ;
165144 } ,
166145 } ,
167146 async ( request , reply ) => {
@@ -194,11 +173,7 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
194173 }
195174 }
196175 }
197- let statusCode = 201 ;
198- if ( response . success . length === 0 ) {
199- statusCode = 500 ;
200- }
201- reply . status ( statusCode ) . send ( response ) ;
176+ reply . status ( 202 ) . send ( response ) ;
202177 } ,
203178 ) ;
204179} ;
0 commit comments