Using Delivery Hooks
Below is an example of how you can implement a Connectifi Delivery Hook that both adds an extra identifier to the context data (for tracking purposes) and redacts sensitive fields (such as SSNs and emails) before the data is further distributed. You can use this hook to ensure that outbound Broadcast messages have additional metadata yet remove any sensitive details.
Example: Delivery Hook to Decorate and Redact Context Data
This TypeScript example demonstrates a Delivery Hook using Connectifi SDK types. It works as follows:
• It checks and clones the incoming context for immutability.
• It adds a new identifier (for example, a tracking ID based on the current timestamp).
• It redacts sensitive fields such as “ssn” and “email” from the data payload.
• Finally, it returns the modified context for downstream processing.
import { Context } from '@finos/fdc3';
import { DeliveryHookHandler } from '@connectifi/sdk';
import { RequestError } from '../types'; // reference your error types as needed
export const decorateAndRedactHook: DeliveryHookHandler = async (request) => {
const { context } = request;
// Create a shallow copy of the context to ensure immutability
const modifiedContext: Context = { ...context };
// Add an additional identifier (e.g., trackingId)
modifiedContext['trackingId'] = `TRACK-${Date.now()}`;
// Check if the context has a data property to further process
if (modifiedContext.hasOwnProperty('data') && typeof modifiedContext['data'] === 'object') {
const data = { ...modifiedContext['data'] };
// Redact sensitive fields by deleting them from the data
if ('ssn' in data) {
delete data['ssn'];
}
if ('email' in data) {
delete data['email'];
}
// Optionally, you can flag the data as redacted
data['redacted'] = true;
// Assign the cleaned data back to the context
modifiedContext['data'] = data;
} else {
// If data property is missing or not an object, you can raise an error (if necessary)
throw new RequestError('Context data is missing or invalid for decoration/redaction.');
}
// Return the modified context wrapped in the expected DeliveryHook format
return { context: modifiedContext };
};
How This Works
-
Identifier Decoration:
The hook adds a new property “trackingId” generated usingDate.now()
. This additional identifier helps track the message as it moves through your integration pipelines. -
Sensitive Data Redaction:
It inspects thedata
property of the context and removes any sensitive fields (for example, SSN and email) to ensure that no sensitive information is broadcasted in subsequent steps. -
Error Handling:
If the context does not have a valid data object, the hook throws an error using a customRequestError
, ensuring that only valid contexts are processed.
Next Steps
- Integrate this Delivery Hook in your Connectifi Platform Admin UI by adding it to the list of configured hooks for your directory.
- Test the hook by broadcasting sample contexts that include sensitive data elements and verify that they are correctly redacted after processing.
- Refine or extend the hook to handle other types of context data or apply custom redaction logic as needed.