From adeab1fe388dfcdc6952fddb5771944c176c0746 Mon Sep 17 00:00:00 2001 From: Andrew Richardson Date: Tue, 8 Feb 2022 11:38:32 -0500 Subject: [PATCH] Replace requestID with requestId This matches the case used by other FireFly connectors. Signed-off-by: Andrew Richardson --- README.md | 8 ++++---- src/handlers/blobs.ts | 12 ++++++------ src/handlers/messages.ts | 12 ++++++------ src/lib/interfaces.ts | 6 +++--- src/routers/api.ts | 20 ++++++++++---------- src/swagger.yaml | 8 ++++---- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 3f0621d..1358e97 100644 --- a/README.md +++ b/README.md @@ -131,11 +131,11 @@ This will make it possible for the organizations to establish MTLS communication | Type | Description | Additional properties |-----------------|------------------------------------------------------------|----------------------- |blob-received | Emitted to the recipient when a blob has been transferred | sender, path, hash -|blob-delivered | Emitted to the sender when a blob has been delivered | recipient, path, requestID (optional) -|blob-failed | Emitted to the sender when a blob could not be delivered | recipient, path, requestID (optional) +|blob-delivered | Emitted to the sender when a blob has been delivered | recipient, path, requestId (optional) +|blob-failed | Emitted to the sender when a blob could not be delivered | recipient, path, requestId (optional) |message-received | Emitted to the recipient when a message has been sent | sender, message -|message-delivered| Emitted to the sender when a message has been delivered | recipient, message, requestID (optional) -|message-failed | Emitted to the sender when a message could not be delivered| recipient, message, requestID (optional) +|message-delivered| Emitted to the sender when a message has been delivered | recipient, message, requestId (optional) +|message-failed | Emitted to the sender when a message could not be delivered| recipient, message, requestId (optional) - After receiving a websocket message, a commit must be sent in order to receive the next one: ``` diff --git a/src/handlers/blobs.ts b/src/handlers/blobs.ts index 5d2e946..41aa8e2 100644 --- a/src/handlers/blobs.ts +++ b/src/handlers/blobs.ts @@ -68,12 +68,12 @@ export const storeBlob = async (file: IFile, filePath: string) => { return await upsertMetadata(filePath, blobHash, blobSize); }; -export const sendBlob = async (blobPath: string, recipient: string, recipientURL: string, requestID: string | undefined) => { +export const sendBlob = async (blobPath: string, recipient: string, recipientURL: string, requestId: string | undefined) => { if (sending) { - blobQueue.push({ blobPath, recipient, recipientURL, requestID }); + blobQueue.push({ blobPath, recipient, recipientURL, requestId }); } else { sending = true; - blobQueue.push({ blobPath, recipient, recipientURL, requestID }); + blobQueue.push({ blobPath, recipient, recipientURL, requestId }); while (blobQueue.length > 0) { await deliverBlob(blobQueue.shift()!); } @@ -81,7 +81,7 @@ export const sendBlob = async (blobPath: string, recipient: string, recipientURL } }; -export const deliverBlob = async ({ blobPath, recipient, recipientURL, requestID }: BlobTask) => { +export const deliverBlob = async ({ blobPath, recipient, recipientURL, requestId }: BlobTask) => { const resolvedFilePath = path.join(utils.constants.DATA_DIRECTORY, utils.constants.BLOBS_SUBDIRECTORY, blobPath); if (!(await utils.fileExists(resolvedFilePath))) { throw new RequestError('Blob not found', 404); @@ -105,7 +105,7 @@ export const deliverBlob = async ({ blobPath, recipient, recipientURL, requestID type: 'blob-delivered', path: blobPath, recipient, - requestID + requestId } as IBlobDeliveredEvent); log.trace(`Blob delivered`); } catch (err: any) { @@ -114,7 +114,7 @@ export const deliverBlob = async ({ blobPath, recipient, recipientURL, requestID type: 'blob-failed', path: blobPath, recipient, - requestID, + requestId, error: err.message, } as IBlobFailedEvent); log.error(`Failed to deliver blob ${err}`); diff --git a/src/handlers/messages.ts b/src/handlers/messages.ts index 18ac862..6f669a7 100644 --- a/src/handlers/messages.ts +++ b/src/handlers/messages.ts @@ -29,12 +29,12 @@ let messageQueue: MessageTask[] = []; let sending = false; export const eventEmitter = new EventEmitter(); -export const sendMessage = async (message: string, recipient: string, recipientURL: string, requestID: string | undefined) => { +export const sendMessage = async (message: string, recipient: string, recipientURL: string, requestId: string | undefined) => { if (sending) { - messageQueue.push({ message, recipient, recipientURL, requestID }); + messageQueue.push({ message, recipient, recipientURL, requestId }); } else { sending = true; - messageQueue.push({ message, recipient, recipientURL, requestID }); + messageQueue.push({ message, recipient, recipientURL, requestId }); while (messageQueue.length > 0) { await deliverMessage(messageQueue.shift()!); } @@ -42,7 +42,7 @@ export const sendMessage = async (message: string, recipient: string, recipientU } }; -export const deliverMessage = async ({ message, recipient, recipientURL, requestID }: MessageTask) => { +export const deliverMessage = async ({ message, recipient, recipientURL, requestId }: MessageTask) => { const httpsAgent = new https.Agent({ cert, key, ca }); const formData = new FormData(); formData.append('message', message); @@ -60,7 +60,7 @@ export const deliverMessage = async ({ message, recipient, recipientURL, request type: 'message-delivered', message, recipient, - requestID + requestId } as IMessageDeliveredEvent); log.trace(`Message delivered`); } catch(err: any) { @@ -69,7 +69,7 @@ export const deliverMessage = async ({ message, recipient, recipientURL, request type: 'message-failed', message, recipient, - requestID, + requestId, error: err.message, } as IMessageFailedEvent); log.error(`Failed to deliver message ${err}`); diff --git a/src/lib/interfaces.ts b/src/lib/interfaces.ts index f31114d..149d9f7 100644 --- a/src/lib/interfaces.ts +++ b/src/lib/interfaces.ts @@ -65,7 +65,7 @@ export interface IMessageFailedEvent { type: 'message-failed' recipient: string message: string - requestID?: string + requestId?: string } export interface IBlobReceivedEvent { @@ -106,14 +106,14 @@ export interface ICommitEvent { } export type MessageTask = { - requestID?: string + requestId?: string message: string recipient: string recipientURL: string } export type BlobTask = { - requestID?: string + requestId?: string blobPath: string recipient: string recipientURL: string diff --git a/src/routers/api.ts b/src/routers/api.ts index 1d7d0a0..f9cdb15 100644 --- a/src/routers/api.ts +++ b/src/routers/api.ts @@ -138,12 +138,12 @@ router.post('/messages', async (req, res, next) => { if (recipientURL === undefined) { throw new RequestError(`Unknown recipient`, 400); } - let requestID = uuidV4(); - if(typeof req.body.requestID === 'string') { - requestID = req.body.requestID; + let requestId = uuidV4(); + if(typeof req.body.requestId === 'string') { + requestId = req.body.requestId; } - messagesHandler.sendMessage(req.body.message, req.body.recipient, recipientURL, requestID); - res.send({ requestID }); + messagesHandler.sendMessage(req.body.message, req.body.recipient, recipientURL, requestId); + res.send({ requestId }); } catch (err) { next(err); } @@ -211,12 +211,12 @@ router.post('/transfers', async (req, res, next) => { if (recipientURL === undefined) { throw new RequestError(`Unknown recipient`, 400); } - let requestID = uuidV4(); - if(typeof req.body.requestID === 'string') { - requestID = req.body.requestID; + let requestId = uuidV4(); + if(typeof req.body.requestId === 'string') { + requestId = req.body.requestId; } - blobsHandler.sendBlob(req.body.path, req.body.recipient, recipientURL, requestID); - res.send({ requestID }); + blobsHandler.sendBlob(req.body.path, req.body.recipient, recipientURL, requestId); + res.send({ requestId }); } catch (err) { next(err); } diff --git a/src/swagger.yaml b/src/swagger.yaml index e4e075c..80be586 100644 --- a/src/swagger.yaml +++ b/src/swagger.yaml @@ -356,7 +356,7 @@ type: string recipient: type: string - requestID: + requestId: type: string BlobHash: type: object @@ -375,14 +375,14 @@ type: string recipient: type: string - requestID: + requestId: type: string Submitted: type: object required: - - requestID + - requestId properties: - requestID: + requestId: type: string Error: type: object