Contacting the store support regarding an order (Node.js)

In this use case, the user wants to contact the customer support due to an issue with the order. Here the seller returns the customer support info of the seller

Support

Code snippets

Client calls the BAP server to trigger support:

    router.post("/local_retail/contact_store", contactStore);

    async function contactStore({ body }, res) {
        try {
            //  .. Validate the client request before below function
            await generateSupportRequest(body)
        } catch (error) {
            res.status(500).send(httpResponse("NACK", error));
        }
    };

BAP server generates the protocol request body

    // Code to generate the protocol request body i.e. function generateSupportRequest() specified above

    async function generateSupportRequest(body) {
/*
Example Request JSON :
{
    "context": {
        "domain": "local_retail",
        "country": "IND",
        "city": "std:080",
        "action": "support",
        "core_version": "0.9.2",
        "bap_id": "https://mock_bap.com/",
        "bap_uri": "https://mock_bap.com/beckn/",
        "transaction_id": "1239890342",
        "message_id": "123793824",
        "timestamp": "2021-06-23T08:22:44.059Z"
    },
    "message": {
        "ref_id": "order_1"
    }
}
*/
        //The below code generates the above example JSON.
        const transactionId = _.get(body, "transactionId");
        // Returns the Context including MessageId
        const context = createContext(transactionId);
        const supportRequestBody = {
            context,
            message:  {
                // Construct from the request
            }
        };
        //call protocol support
        const response = await callSupport(supportRequestBody);
        res
        .status(200)
        .send({ ...response.data, messageId: context["message_id"] });
    }

BAP server calls protocol support to the network

    async function callSupport(supportRequestBody) {
        // It lookups the registry for BG OR BPP
        let uri = lookup();
        // Construct Header
        const headers = constructAuthHeader(); // Auth Header with digital Signature
        return axios({ url: `${uri}/local_retail/support`, method: "POST", headers, data: supportRequestBody }); 
    }

BAP receives protocol on_support

/*
Example Response JSON:
{
    "context": {
        "domain": "local_retail",
        "country": "IND",
        "city": "std:080",
        "action": "on_support",
        "core_version": "0.9.2",
        "bap_id": "https://mock_bap.com/",
        "bap_uri": "https://mock_bap.com/beckn/",
        "transaction_id": "1239890342",
        "message_id": "123793824",
        "timestamp": "2021-06-23T08:24:26.519Z"
    },
    "message": {
        "phone": "+919898989898",
        "email": "[email protected]",
        "uri": "http://support.bpp.com?order_id=order_1"
    }
}
*/
    // Auth middleware authenticates the digital signature of the incoming request
    router.post("/local_retail/on_support", auth, onSupport);
    async function onSupport({ body }, res) {
        // Save the response to Database
        await saveToDb(body);
    };

Client polls BAP to get the on_support results

    // Endpoint for the client to poll the search data based on the message id
    async function getMessageById(req) {
        try {
            const messageId = _.get(req, "messageId");
            // Get the data using message Id
            const response = await getData(messageId);
            res.status(200).send(httpResponse('ACK', "", response));
        } catch(error) {
            res.status(500).send(httpResponse("NACK", error));
        }
    };