finos / FDC3

An open standard for the financial desktop.
https://fdc3.finos.org
Other
201 stars 132 forks source link

Suggestions: Context Translation Middleware #1419

Open pvoznyuk opened 2 weeks ago

pvoznyuk commented 2 weeks ago

Enhancement Request

Use Case:

Suppose there is an existing ecosystem of applications that communicate with each other via DesktopAgent. The context for the fdc3.instrument type includes the id.ISIN property. One day, a third-party application is to be integrated into the ecosystem and communicate with the existing applications via DesktopAgent.

The problem is that this application doesn’t support id.ISIN but instead supports id.FIGI.

Refactoring all existing applications to add id.FIGI to every context broadcast is expensive, so it would be helpful if the contexts could be converted automatically according to defined rules.

Workflow Description

Context Translation Middleware: Middleware within DesktopAgent that automatically converts contexts based on defined rules (e.g., context type) during broadcasting.

Error Handling: If there are any cases where the translation is not feasible, DesktopAgent should handle this so developers can log the situation and alert the administrators. This ensures visibility for unsupported context translations and reduces potential issues during runtime.

Workflow Examples

const contextTransform = async (context) => {
    if (context.type === 'fdc3.instrument') {
        if (context.id.ISIN && !context.id.FIGI) {
           const FIGI = await convertISINtoFIGI(context.id.ISIN) // a fetch request to some service
           if (!FIGI) {
              throw new Error(`Cannot convert ISIN ${context.id.ISIN} to FIGI for fdc3.instrument`)
           }
           return { 
               ...context,
               id: {
                  ...context.id,
                  FIGI,
               }
           }
        }
    }
}

getAgent({
   middleware: [
      contextTransform
   ]
})
novavi commented 2 weeks ago

This is an interesting proposal. Someone in my firm raised this same issue to me last year e.g. whether there are standard mechanisms in FDC3 to handle this type of requirement. I've also had similar discussions more recently relating to translation not so much between two different standard identifiers, but between standard and internal/proprietary identifiers. Just to open up the just discussion a bit, here's a few thoughts I had when reading the above:

[1] Just to be more specific about one of the suggestions above on guardrails and changing the concept of the transform function to instead emit just the additional properties, what I was getting at was something along the lines of:

Original context (pre-middleware execution):

{ 
    type: "fdc3.instrument",
    id: {
        cusip: "594918104"
    }
}

Additional properties (return value from enrichment function provided to middleware executor):

{ 
    id: {
        isin: "US5949181045"
    }
}

Enriched Context (post-middleware execution):

{ 
    type: "fdc3.instrument",
    id: {
        cusip: "594918104",
        isin: "US5949181045"
    }
}

But given that you could not prevent the enrichment function from returning an object also containing existing properties, the deep merge would have to ensure it only added new properties and did not update existing property values. On this basis, the enrichment function would effectively be free to return an extended context (containing both existing and new properties) which would likely be easier to author. But the key point is that the middleware handler would not simply use the value returned from the enrichment function as-is, it would apply this very specific (guarded) deep merge.

Of course, there are downsides to the above approach - hence I think that if there was an intention to make the proposal support guardrails, a number of different approaches and patterns would need to be put on the table, evaluated, and discussed.