All files / lib/packages/shared-types user.ts

100% Statements 21/21
100% Branches 2/2
100% Functions 2/2
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84                        275x 131x 131x 131x 131x 131x 131x 131x                                           275x               275x             275x   275x             275x   275x                                
import { UserStatusType } from "@aws-sdk/client-cognito-identity-provider";
 
import { UserRole } from "./events/legacy-user";
 
export { CognitoUser } from "amazon-cognito-identity-js";
export type { UserData } from "amazon-cognito-identity-js";
export type {
  APIGatewayEvent,
  APIGatewayEventIdentity,
  APIGatewayEventRequestContext,
} from "aws-lambda";
 
export enum UserRoles {
  DEFAULT_CMS_USER = "defaultcmsuser",
  CMS_REVIEWER = "cmsreviewer",
  CMS_ROLE_APPROVER = "cmsroleapprover",
  HELPDESK = "helpdesk",
  STATE_SUBMITTER = "statesubmitter",
  SYSTEM_ADMIN = "systemadmin",
  STATE_SYSTEM_ADMIN = "statesystemadmin",
}
 
export type UserRolesString = `${UserRoles}${"," | ""}` | "";
 
export type CognitoUserAttributes = {
  sub: string;
  "custom:cms-roles": UserRolesString; // comma-separated list of UserRoles ex. "onemac-micro-reviewer,onemac-micro-helpdesk" or "onemac-micro-statesubmitter"
  "custom:ismemberof"?: UserRolesString;
  email_verified: boolean;
  "custom:state"?: string; // ex. "VA" or "VA,MD,CA" or undefined
  given_name: string;
  family_name: string;
  email: string;
  username: string;
};
 
export type FullUser = CognitoUserAttributes & {
  role: UserRole;
  states?: string[];
};
 
export const CMS_ROLES = [
  "cmsreviewer",
  "cmsroleapprover",
  "defaultcmsuser",
  "helpdesk",
  "systemadmin",
] satisfies UserRole[];
 
export const CMS_WRITE_ROLES = [
  "cmsreviewer",
  "defaultcmsuser",
  "cmsroleapprover",
  "systemadmin",
] satisfies UserRole[];
 
export const CMS_READ_ONLY_ROLES = ["helpdesk"] satisfies UserRole[];
 
export const USER_MANAGER_ROLES = [
  "systemadmin",
  "statesystemadmin",
  "cmsroleapprover",
  "helpdesk",
] satisfies UserRole[];
 
export const STATE_ROLES = ["statesubmitter", "statesystemadmin"] satisfies UserRole[];
 
export const RoleDescriptionStrings: { [key: string]: string } = {
  [UserRoles.CMS_REVIEWER]: "Reviewer",
  [UserRoles.HELPDESK]: "Helpdesk",
  [UserRoles.STATE_SUBMITTER]: "State Submitter",
};
 
export type UserAttributes = {
  firstName: string | undefined;
  lastName: string | undefined;
  email: string | undefined;
  states: string | undefined;
  roles: string | undefined;
  enabled: boolean | undefined;
  status: UserStatusType | undefined;
  username: string | undefined;
};