lib/converters/v1.0.0/converter-v1-to-v2.js
function (responseV1) {
        var self = this,
            associatedRequestId;

        if (responseV1.requestObject) {
            if (_.isString(responseV1.requestObject)) {
                try {
                    return JSON.parse(responseV1.requestObject);
                }
                catch (e) {
                    // if there was an error parsing it as JSON, it's probably an ID, so store it in the ID variable
                    associatedRequestId = responseV1.requestObject;
                }
            }
            else {
                return responseV1.requestObject;
            }
        }

        if (responseV1.request) {
            if (_.isString(responseV1.request)) {
                try {
                    return JSON.parse(responseV1.request);
                }
                catch (e) {
                    // if there was an error parsing it as JSON, it's probably an ID, so store it in the ID variable
                    associatedRequestId = responseV1.request;
                }
            }
            else {
                return responseV1.request;
            }
        }

        // we have a request ID
        return associatedRequestId && _.get(self, ['cache', associatedRequestId]);
    }
function (responseV1) {
        var self = this,
            associatedRequestId;

        if (responseV1.requestObject) {
            if (_.isString(responseV1.requestObject)) {
                try {
                    return JSON.parse(responseV1.requestObject);
                }
                catch (e) {
                    // if there was an error parsing it as JSON, it's probably an ID, so store it in the ID variable
                    associatedRequestId = responseV1.requestObject;
                }
            }
            else {
                return responseV1.requestObject;
            }
        }

        if (responseV1.request) {
            if (_.isString(responseV1.request)) {
                try {
                    return JSON.parse(responseV1.request);
                }
                catch (e) {
                    // if there was an error parsing it as JSON, it's probably an ID, so store it in the ID variable
                    associatedRequestId = responseV1.request;
                }
            }
            else {
                return responseV1.request;
            }
        }

        // we have a request ID
        return associatedRequestId && _.get(self, ['cache', associatedRequestId]);
    }
function ( responseV1 ) { var self = this , associatedRequestId ; if ( responseV1 . requestObject ) { if ( _ . isString ( responseV1 . requestObject ) ) { try { return JSON . parse ( responseV1 . requestObject ) ; } catch ( e ) { // if there was an error parsing it as JSON, it's probably an ID, so store it in the ID variable associatedRequestId = responseV1 . requestObject ; } } else { return responseV1 . requestObject ; } } if ( responseV1 . request ) { if ( _ . isString ( responseV1 . request ) ) { try { return JSON . parse ( responseV1 . request ) ; } catch ( e ) { // if there was an error parsing it as JSON, it's probably an ID, so store it in the ID variable associatedRequestId = responseV1 . request ; } } else { return responseV1 . request ; } } // we have a request ID return associatedRequestId && _ . get ( self , [ 'cache' , associatedRequestId ] ) ; }
Gets the saved request for the given response, and handles edge cases between Apps & Sync

Handles a lot of edge cases, so the code is not very clean.

The Flow followed here is:

If responseV1.requestObject is present
If it is a string
Try parsing it as JSON
If parsed,
return it
else
It is a request ID
If responseV1.request is present
If it is a string
Try parsing it as JSON
If parsed,
return it
else
It is a request ID
Look up the collection for the request ID and return it, or return undefined.

@param {Object} responseV1 - The v1 response to be converted.
@returns {Object} - The converted saved request, in v2 format.
Gets the saved request for the given response and handles edge cases between Apps & Sync