|
| 1 | +import { FastifyInstance, FastifyPluginAsync } from "fastify"; |
| 2 | +import { allAppRoles, AppRoles } from "../../common/roles.js"; |
| 3 | +import { |
| 4 | + addToTenant, |
| 5 | + getEntraIdToken, |
| 6 | + listGroupMembers, |
| 7 | + modifyGroup, |
| 8 | + patchUserProfile, |
| 9 | +} from "../functions/entraId.js"; |
| 10 | +import { |
| 11 | + BaseError, |
| 12 | + DatabaseFetchError, |
| 13 | + DatabaseInsertError, |
| 14 | + EntraGroupError, |
| 15 | + EntraInvitationError, |
| 16 | + InternalServerError, |
| 17 | + NotFoundError, |
| 18 | + UnauthorizedError, |
| 19 | +} from "../../common/errors/index.js"; |
| 20 | +import { PutItemCommand } from "@aws-sdk/client-dynamodb"; |
| 21 | +import { genericConfig } from "../../common/config.js"; |
| 22 | +import { marshall } from "@aws-sdk/util-dynamodb"; |
| 23 | +import { |
| 24 | + InviteUserPostRequest, |
| 25 | + invitePostRequestSchema, |
| 26 | + GroupMappingCreatePostRequest, |
| 27 | + groupMappingCreatePostSchema, |
| 28 | + entraActionResponseSchema, |
| 29 | + groupModificationPatchSchema, |
| 30 | + GroupModificationPatchRequest, |
| 31 | + EntraGroupActions, |
| 32 | + entraGroupMembershipListResponse, |
| 33 | + ProfilePatchRequest, |
| 34 | + entraProfilePatchRequest, |
| 35 | +} from "../../common/types/iam.js"; |
| 36 | +import { |
| 37 | + AUTH_DECISION_CACHE_SECONDS, |
| 38 | + getGroupRoles, |
| 39 | +} from "../functions/authorization.js"; |
| 40 | +import { OrganizationList } from "common/orgs.js"; |
| 41 | +import { z } from "zod"; |
| 42 | + |
| 43 | +const OrganizationListEnum = z.enum(OrganizationList as [string, ...string[]]); |
| 44 | +export type Org = z.infer<typeof OrganizationListEnum>; |
| 45 | + |
| 46 | +type Member = { name: string; email: string }; |
| 47 | +type OrgMembersResponse = { org: Org; members: Member[] }; |
| 48 | + |
| 49 | +const sigleadRoutes: FastifyPluginAsync = async (fastify, _options) => { |
| 50 | + fastify.get<{ |
| 51 | + Reply: OrgMembersResponse[]; |
| 52 | + }>("/groups", async (request, reply) => { |
| 53 | + const entraIdToken = await getEntraIdToken( |
| 54 | + { |
| 55 | + smClient: fastify.secretsManagerClient, |
| 56 | + dynamoClient: fastify.dynamoClient, |
| 57 | + }, |
| 58 | + fastify.environmentConfig.AadValidClientId, |
| 59 | + ); |
| 60 | + |
| 61 | + const data = await Promise.all( |
| 62 | + OrganizationList.map(async (org) => { |
| 63 | + const members: Member[] = await listGroupMembers(entraIdToken, org); |
| 64 | + return { org, members } as OrgMembersResponse; |
| 65 | + }), |
| 66 | + ); |
| 67 | + |
| 68 | + reply.status(200).send(data); |
| 69 | + }); |
| 70 | +}; |
| 71 | + |
| 72 | +export default sigleadRoutes; |
0 commit comments