Search code examples
deepstream.io

Make deepstream server enhance data coming to RPC


I'm looking for a way to make my deepstream server enhance data sent to an RPC endpoint with authorized client data. I wonder if it is realistic. If yes how could I achieve it?

I can see clearly I have authorized user data in canPerformAction call. I'm not sure how I can modify a message so.


Solution

  • Transform functions allow you to do so.

    https://deepstream.io/tutorials/transforming-data.html

    It provides you a hook to insert or delete data from every incoming and outgoing message from deepstream, including RPC, events and records.

    server.set( 'dataTransforms', [{
        topic: C.TOPIC.RPC,
        action: C.ACTIONS.REQUEST,
        transform: function( data, metaData ) {
            if( metaData.rpcName === 'do-something' ) {
                // Add user sensitive data to rpc
                data.userData = confidentialUserData[ metaData.sender ];
            }
            return data;
        }
    }] );