Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type Notifications to Users #5571

Merged
merged 43 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ceec612
Add Types for notification message for 'message_completion_error' and…
Nov 20, 2024
46cb621
TEMP: ignore PR actions for now
Nov 20, 2024
62f736f
Add Types for notification message for '_contact_full_update_complete'
Nov 20, 2024
7ba160e
Add typing to ServeDocumentErrorNotification;
Nov 20, 2024
8f93821
Add message type for 'ServeDocumentCompleteNotification'
Nov 21, 2024
5e1397d
Add message type for 'RetryAsyncRequestNotification'
Nov 21, 2024
08b6ac8
Add message type for 'BatchDownloadCsvDataNotification'
Nov 21, 2024
c2c42c5
Add message type for 'DownloadCsvFileNotification'
Nov 21, 2024
699ff5c
Update message type for 'ServeDocumentCompleteNotification'
Nov 21, 2024
9ea32ca
Add message type for 'SaveDocketEntryForLaterCompleteNotification'
Nov 21, 2024
009771c
Add message type for 'BatchDownloadErrorNotification'
Nov 21, 2024
3424ad8
Add message type for 'BatchDownloadProgressNotification'
Nov 21, 2024
2466589
Add message type for 'BatchDownloadReadyNotification'
Nov 21, 2024
026244c
Add message type for 'AwsBatchDownloadProgressNotification'
Nov 21, 2024
cc902b9
Add message type for 'MessageCompletionSucessNotification' and 'Admin…
Nov 21, 2024
5fd94dd
Add message type for 'ServeToIrsComplteNotification'
Nov 21, 2024
3c87bf6
Add message type for 'ServeToIrsErrorNotification'
Nov 21, 2024
ea8cc21
Add message type for 'BatchDownloadDocketGeneratedNotification'
Nov 21, 2024
c1bcf17
Add message type for 'NoticeGenerationUpdatedNotification'
Nov 21, 2024
40c8e84
Add message type for 'PaperServiceStartedNotification'
Nov 21, 2024
6132819
Add message type for 'PaperServiceUpdatedNotification'
Nov 21, 2024
cdf2466
Add message type for 'SetTrialCalendarPaperServiceCompleteNotification'
Nov 21, 2024
fe12318
Add message type for 'ThirtyDayNoticePaperServiceCompleteNotification'
Nov 21, 2024
492350f
Add message type for 'NoticeGenerationCompleteNotification'
Nov 21, 2024
1ae2e12
Add message type for 'NoticeGenerationStartNotification'
Nov 21, 2024
97e2105
Updated message type for 'NoticeGenerationCompleteNotification'
Nov 21, 2024
99adb14
Add message type for 'SetTrialSessionCalendarCompleteNotification'
Nov 21, 2024
8f034bd
Add message type for 'SetTrialSessionCalendarErrorNotification'
Nov 21, 2024
58ac725
Add message type for 'UpdateTrialSessionCompleteNotification'
Nov 21, 2024
f2902dd
Add message type for 'UserContactInitialUpdateCompleteNotification'
Nov 21, 2024
fe01151
Add message type for 'UserContactUpdateErrorNotification'
Nov 21, 2024
23b389f
Update test to take in a real message;
Nov 21, 2024
1b839ff
Extract types to separate file;
Nov 21, 2024
f95f806
Move github actions back to original folder;
Nov 21, 2024
a2ae77a
Fix import statement;
Nov 21, 2024
cc70d8a
Add typing to applicationContext;
Nov 21, 2024
f16a157
Add typing to Maintenance Mode;
Nov 21, 2024
48ebe54
Fix Typo;
Nov 21, 2024
b70f855
Move socket router message type to same file
Nov 22, 2024
6bb52ed
Merge branch 'staging' into type-notifications-to-user
cruzjone-flexion Dec 3, 2024
618c592
Merge branch 'staging' into type-notifications-to-user
cruzjone-flexion Dec 4, 2024
bba9d43
Merge branch 'staging' into type-notifications-to-user
cruzjone-flexion Dec 4, 2024
eb21bc2
Merge branch 'staging' into type-notifications-to-user
jimlerza Dec 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const generateChangeOfAddressHelper = async ({
jobId: string;
user: RawPractitioner;
requestUserId?: string;
websocketMessagePrefix: string;
websocketMessagePrefix: 'user' | 'admin';
}) => {
try {
const newData = contactInfo;
Expand Down Expand Up @@ -107,10 +107,15 @@ export const generateChangeOfAddressHelper = async ({
applicationContext.logger.error(error);
}

const NOTIFICATION_ACTION:
| 'user_contact_update_progress'
| 'admin_contact_update_progress' =
`${websocketMessagePrefix}_contact_update_progress`;

await applicationContext.getNotificationGateway().sendNotificationToUser({
applicationContext,
message: {
action: `${websocketMessagePrefix}_contact_update_progress`,
action: NOTIFICATION_ACTION,
},
userId: requestUserId || user.userId,
});
Expand Down Expand Up @@ -138,10 +143,15 @@ export const generateChangeOfAddressHelper = async ({
});
}

const CONTACT_UPDATE_COMPLETE_ACTION:
| 'user_contact_full_update_complete'
| 'admin_contact_full_update_complete' =
`${websocketMessagePrefix}_contact_full_update_complete`;

await applicationContext.getNotificationGateway().sendNotificationToUser({
applicationContext,
message: {
action: `${websocketMessagePrefix}_contact_full_update_complete`,
action: CONTACT_UPDATE_COMPLETE_ACTION,
user,
},
userId: requestUserId || user.userId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const fileAndServeCourtIssuedDocument = async (
docketEntryId,
});

let error;
let error: Error | undefined;
if (!docketEntryToServe) {
error = new NotFoundError(`Docket entry ${docketEntryId} was not found.`);
} else if (docketEntryToServe.servedAt) {
Expand Down Expand Up @@ -285,7 +285,7 @@ export const determineEntitiesToLock = (
});

export const handleLockError = async (
applicationContext,
applicationContext: ServerApplicationContext,
originalRequest,
authorizedUser: UnknownAuthUser,
) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export const determineEntitiesToLock = (
});

export const handleLockError = async (
applicationContext,
applicationContext: ServerApplicationContext,
originalRequest,
authorizedUser: UnknownAuthUser,
) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const createCsvCustomCaseReportFileInteractor = async (
const csvBuffer = Buffer.from(csvString);

const today = formatNow(FORMATS.MMDDYYYY_UNDERSCORED);
const fileName = 'Custom Case Report - ' + today;
const fileName: string = 'Custom Case Report - ' + today;

const fileInfo = await saveFileAndGenerateUrl({
applicationContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export const determineEntitiesToLock = (
});

export const handleLockError = async (
applicationContext,
applicationContext: ServerApplicationContext,
originalRequest,
authorizedUser: UnknownAuthUser,
) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ export const determineEntitiesToLock = (
});

export const handleLockError = async (
applicationContext,
applicationContext: ServerApplicationContext,
originalRequest,
authorizedUser: UnknownAuthUser,
) => {
Expand Down
9 changes: 7 additions & 2 deletions web-api/src/business/useCases/user/generateChangeOfAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const generateChangeOfAddressForPractitioner = async ({
updatedEmail?: string;
updatedName?: string;
user: any;
websocketMessagePrefix?: string;
websocketMessagePrefix?: 'user' | 'admin';
authorizedUser: AuthUser;
}): Promise<any[] | undefined> => {
const associatedUserCases = await applicationContext
Expand All @@ -65,10 +65,15 @@ const generateChangeOfAddressForPractitioner = async ({
}

let completedCases = 0;
const NOTIFICATION_ACTION:
| 'user_contact_update_progress'
| 'admin_contact_update_progress' =
`${websocketMessagePrefix}_contact_update_progress`;

await applicationContext.getNotificationGateway().sendNotificationToUser({
applicationContext,
message: {
action: `${websocketMessagePrefix}_contact_update_progress`,
action: NOTIFICATION_ACTION,
completedCases,
totalCases: associatedUserCases.length,
},
Expand Down
9 changes: 8 additions & 1 deletion web-api/src/notifications/sendNotificationToUser.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NotificationMessage } from '@web-api/notifications/sendNotificationToUserTypes';
import { applicationContext } from '../../../shared/src/business/test/createTestApplicationContext';
import { sendNotificationToUser } from './sendNotificationToUser';

Expand Down Expand Up @@ -28,7 +29,13 @@ describe('sendNotificationToUser', () => {
sk: 'sk-04',
},
];
const mockMessage = 'hello, computer';
const mockMessage: NotificationMessage = {
action: 'download_csv_file',
csvInfo: {
fileName: 'TEST NAME',
url: 'SOME URL',
},
};

const send = jest.fn().mockResolvedValue('ok');

Expand Down
3 changes: 2 additions & 1 deletion web-api/src/notifications/sendNotificationToUser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NotificationMessage } from '@web-api/notifications/sendNotificationToUserTypes';
import { ServerApplicationContext } from '@web-api/applicationContext';

export const sendNotificationToUser = async ({
Expand All @@ -8,7 +9,7 @@ export const sendNotificationToUser = async ({
}: {
applicationContext: ServerApplicationContext;
clientConnectionId?: string;
message: any;
message: NotificationMessage;
userId: string;
}) => {
let connections = await applicationContext
Expand Down
226 changes: 226 additions & 0 deletions web-api/src/notifications/sendNotificationToUserTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
import { RawPractitioner } from '@shared/business/entities/Practitioner';
import { UserRecord } from '@web-api/persistence/dynamo/dynamoTypes';

type MessageCompletionErrorNotification = {
action: 'message_completion_error';
alertError: {
message: string;
title: string;
};
};

type ContactUpdateProgressNotification = {
action: 'user_contact_update_progress' | 'admin_contact_update_progress';
completedCases?: number;
totalCases?: number;
};

type ContactUpdateCompleteNotification = {
action:
| 'user_contact_full_update_complete'
| 'admin_contact_full_update_complete';
user?: RawPractitioner | UserRecord;
};

type ServeDocumentErrorNotification = {
action: 'serve_document_error';
error: string;
};

type ServeDocumentCompleteNotification = {
action: 'serve_document_complete';
alertSuccess: {
message: string;
overwritable: boolean;
};
generateCoversheet?: boolean;
docketEntryId?: string;
pdfUrl?: string;
};

type RetryAsyncRequestNotification = {
action: 'retry_async_request';
originalRequest: any;
requestToRetry: string;
};

type BatchDownloadCsvDataNotification = {
action: 'batch_download_csv_data';
filesCompleted: number;
totalFiles: number;
};

type DownloadCsvFileNotification = {
action: 'download_csv_file';
csvInfo: {
fileName: string;
url: string;
};
};

type SaveDocketEntryForLaterCompleteNotification = {
action: 'save_docket_entry_for_later_complete';
alertSuccess: {
message: string;
overwritable: boolean;
};
docketEntryId: string;
};

type BatchDownloadErrorNotification = {
action: 'batch_download_error';
error: any;
};

type BatchDownloadProgressNotification = {
action: 'batch_download_progress';
filesCompleted: number;
totalFiles: number;
};

type BatchDownloadReadyNotification = {
action: 'batch_download_ready';
url: string;
};

type AwsBatchDownloadProgressNotification = {
action: 'aws_batch_download_progress';
filesCompleted: number;
totalFiles: number;
};

type MessageCompletionSucessNotification = {
action: 'message_completion_success';
completedMessageIds: string[];
};

type AdminContactInitialUpdateCompleteNotification = {
action: 'admin_contact_initial_update_complete';
};

type ServeToIrsCompleteNotification = {
action: 'serve_to_irs_complete';
pdfUrl: string;
};

type ServeToIrsErrorNotification = {
action: 'serve_to_irs_error';
};

type BatchDownloadDocketGeneratedNotification = {
action: 'batch_download_docket_generated';
filesCompleted: number;
totalFiles: number;
};

type NoticeGenerationUpdatedNotification = {
action: 'notice_generation_updated';
};

type PaperServiceStartedNotification = {
action: 'paper_service_started';
totalPdfs: number;
};

type PaperServiceUpdatedNotification = {
action: 'paper_service_updated';
pdfsAppended: number;
};

type SetTrialCalendarPaperServiceCompleteNotification = {
action: 'set_trial_calendar_paper_service_complete';
fileId: string;
hasPaper: boolean;
pdfUrl: string;
};

type ThirtyDayNoticePaperServiceCompleteNotification = {
action: 'thirty_day_notice_paper_service_complete';
pdfUrl?: string;
fileId?: string;
hasPaper?: boolean;
};

type NoticeGenerationCompleteNotification = {
action: 'notice_generation_complete';
hasPaper?: boolean;
trialNoticePdfsKeys: string[];
trialSessionId?: string;
};

type NoticeGenerationStartNotification = {
action: 'notice_generation_start';
totalCases: number;
};

type SetTrialSessionCalendarCompleteNotification = {
action: 'set_trial_session_calendar_complete';
trialSessionId: string;
};

type SetTrialSessionCalendarErrorNotification = {
action: 'set_trial_session_calendar_error';
message: string;
};

type UpdateTrialSessionCompleteNotification = {
action: 'update_trial_session_complete';
fileId?: string;
hasPaper?: boolean;
pdfUrl?: string;
trialSessionId?: string;
};

type UserContactInitialUpdateCompleteNotification = {
action: 'user_contact_initial_update_complete';
};

type UserContactUpdateErrorNotification = {
action: 'user_contact_update_error';
error: string;
};

export type NotificationMessage =
| MessageCompletionErrorNotification
| ContactUpdateProgressNotification
| ContactUpdateCompleteNotification
| ServeDocumentErrorNotification
| ServeDocumentCompleteNotification
| RetryAsyncRequestNotification
| BatchDownloadCsvDataNotification
| DownloadCsvFileNotification
| SaveDocketEntryForLaterCompleteNotification
| BatchDownloadErrorNotification
| BatchDownloadProgressNotification
| BatchDownloadReadyNotification
| AwsBatchDownloadProgressNotification
| MessageCompletionSucessNotification
| AdminContactInitialUpdateCompleteNotification
| ServeToIrsCompleteNotification
| ServeToIrsErrorNotification
| BatchDownloadDocketGeneratedNotification
| NoticeGenerationUpdatedNotification
| PaperServiceStartedNotification
| PaperServiceUpdatedNotification
| SetTrialCalendarPaperServiceCompleteNotification
| ThirtyDayNoticePaperServiceCompleteNotification
| NoticeGenerationCompleteNotification
| NoticeGenerationStartNotification
| SetTrialSessionCalendarCompleteNotification
| SetTrialSessionCalendarErrorNotification
| UpdateTrialSessionCompleteNotification
| UserContactInitialUpdateCompleteNotification
| UserContactUpdateErrorNotification;

type MaintenanceModeEngaged = {
action: 'maintenance_mode_engaged';
};

type MaintenanceModeDisengaged = {
action: 'maintenance_mode_disengaged';
};

export type SocketRouterNotificationMessage =
| NotificationMessage
| MaintenanceModeEngaged
| MaintenanceModeDisengaged;
4 changes: 3 additions & 1 deletion web-client/src/providers/socketRouter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { SocketRouterNotificationMessage } from '@web-api/notifications/sendNotificationToUserTypes';

/* eslint-disable complexity */
const noop = () => {};

export const socketRouter = (app, onMessageCallbackFn?) => {
return async event => {
const message = JSON.parse(event.data);
const { action } = message;
const { action } = message as SocketRouterNotificationMessage;

switch (action) {
case 'paper_service_started':
Expand Down
Loading