import { RequestHandler } from 'express'; import { RestClient, ApiConfig, AuthenticationClient } from '@ministryofjustice/hmpps-rest-client'; import Logger from 'bunyan'; type AvailableComponent = 'header' | 'footer'; interface Component { html: string; css: string[]; javascript: string[]; } type ConnectDpsComponentLogger = Logger | typeof console; interface CaseLoad { caseLoadId: string; description: string; type: string; caseloadFunction: string; currentlyActive: boolean; } interface Service { id: string; heading: string; description: string; href: string; navEnabled: boolean; } type AllocationJobResponsibility = 'KEY_WORKER' | 'PERSONAL_OFFICER'; /** Map of CSP directive to necessary URL values */ type CspDirectives = Record; /** * Information about the current user and environment */ interface SharedData { /** Caseloads available to prison user */ caseLoads: CaseLoad[]; /** Currently active caseload for prison user */ activeCaseLoad: CaseLoad | null; /** Services available to prison user */ services: Service[]; /** Prison user allocated responsibilites */ allocationJobResponsibilities: AllocationJobResponsibility[]; /** Content-Security-Policy directives needed to use components from a different domain/origin */ cspDirectives: CspDirectives; } type ComponentsApiResponse = Record & { meta: SharedData; }; declare class ComponentApiClient extends RestClient { constructor(logger: ConnectDpsComponentLogger, config: ApiConfig); getComponents(userToken: string): Promise>; } interface FrontendComponentRequestOptions { authUrl?: string; supportUrl?: string; environmentName?: 'DEV' | 'PRE-PRODUCTION' | 'PRODUCTION'; includeSharedData?: boolean; useFallbacksByDefault?: boolean; /** * Update Content-Security-Policy with directives returned by MFE components service * (instead of built-in fallback set); true by default */ updateContentSecurityPolicy?: boolean; } declare class ComponentsService { private readonly logger; private readonly componentApiConfig; private readonly componentApiClient; private readonly dpsUrl; constructor(logger: ConnectDpsComponentLogger, componentApiConfig: ApiConfig, componentApiClient: ComponentApiClient, dpsUrl: string); static create({ logger, componentApiConfig, dpsUrl, }: { logger?: ConnectDpsComponentLogger; componentApiConfig: ApiConfig; dpsUrl: string; }): ComponentsService; getFrontendComponents(requestOptions?: FrontendComponentRequestOptions): RequestHandler; } type FrontendComponentsMiddlewareOptions = { requestOptions?: FrontendComponentRequestOptions; } & Parameters[0]; declare function getFrontendComponents({ logger, componentApiConfig, dpsUrl, requestOptions, }: FrontendComponentsMiddlewareOptions): RequestHandler; declare class PrisonApiClient extends RestClient { constructor(logger: ConnectDpsComponentLogger, config: ApiConfig); getUserCaseLoads(userToken: string): Promise; } declare class CaseLoadService { private readonly logger; private readonly prisonApiClient; constructor(logger: ConnectDpsComponentLogger, prisonApiClient: PrisonApiClient); static create({ logger, prisonApiConfig, }: { logger?: ConnectDpsComponentLogger; prisonApiConfig: ApiConfig; }): CaseLoadService; retrieveCaseLoadData(): RequestHandler; } declare function retrieveCaseLoadData({ logger, prisonApiConfig, }: Parameters[0]): RequestHandler; type AuthSource = 'nomis' | 'delius' | 'external' | 'azuread'; /** * These are the details that all user types share. */ interface BaseUser { authSource: AuthSource; username: string; userId: string; name: string; displayName: string; token?: string; backLink?: string; } /** * Prison users are those that have a user account in NOMIS. * HMPPS Auth automatically grants these users a `ROLE_PRISON` role. * Prison users have an additional numerical staffId. The userId is * a stringified version of the staffId. Some teams may need to separately * retrieve the user case load (which prisons that a prison user has access * to) and store it here, an example can be found in `hmpps-prisoner-profile`. */ interface PrisonUser extends BaseUser { authSource: 'nomis'; staffId: number; caseLoads: CaseLoad[]; activeCaseLoad?: CaseLoad; activeCaseLoadId?: string; allocationJobResponsibilities?: AllocationJobResponsibility[]; } declare class AllocationsApiClient extends RestClient { constructor(logger: ConnectDpsComponentLogger, config: ApiConfig, authenticationClient: AuthenticationClient); getStaffAllocationPolicies(user: PrisonUser): Promise<{ policies: AllocationJobResponsibility[]; }>; } declare class AllocationService { private readonly logger; private readonly allocationsApiClient; constructor(logger: ConnectDpsComponentLogger, allocationsApiClient: AllocationsApiClient); static create({ logger, allocationsApiConfig, authenticationClient, }: { logger?: ConnectDpsComponentLogger; allocationsApiConfig: ApiConfig; authenticationClient: AuthenticationClient; }): AllocationService; retrieveAllocationJobResponsibilities(): RequestHandler; } declare function retrieveAllocationJobResponsibilities({ logger, allocationsApiConfig, authenticationClient, }: Parameters[0]): RequestHandler; export { AllocationService, CaseLoadService, ComponentsService, getFrontendComponents, retrieveAllocationJobResponsibilities, retrieveCaseLoadData };