www/index.js
function(options) {
    this._handlers = {
        'progress': [],
        'cancel': [],
        'error': [],
        'complete': []
    };

    // require options parameter
    if (typeof options === 'undefined') {
        throw new Error('The options argument is required.');
    }

    // require options.src parameter
    if (typeof options.src === 'undefined' && options.type !== "local") {
        throw new Error('The options.src argument is required for merge replace types.');
    }

    // require options.id parameter
    if (typeof options.id === 'undefined') {
        throw new Error('The options.id argument is required.');
    }

    // define synchronization strategy
    //
    //     replace: This is the normal behavior. Existing content is replaced
    //              completely by the imported content, i.e. is overridden or
    //              deleted accordingly.
    //     merge:   Existing content is not modified, i.e. only new content is
    //              added and none is deleted or modified.
    //     local:   Existing content is not modified, i.e. only new content is
    //              added and none is deleted or modified.
    //
    if (typeof options.type === 'undefined') {
        options.type = 'replace';
    }

    if (typeof options.headers === 'undefined') {
        options.headers = null;
    }

    if (typeof options.copyCordovaAssets === 'undefined') {
        options.copyCordovaAssets = false;
    }

    if (typeof options.copyRootApp === 'undefined') {
        options.copyRootApp = false;
    }

    if (typeof options.timeout === 'undefined') {
        options.timeout = 15.0;
    }

    if (typeof options.trustHost === 'undefined') {
        options.trustHost = false;
    }

    if (typeof options.manifest === 'undefined') {
        options.manifest = "";
    }

    if (typeof options.validateSrc === 'undefined') {
        options.validateSrc = true;
    }

    // store the options to this object instance
    this.options = options;

    // triggered on update and completion
    var that = this;
    var success = function(result) {
        if (result && typeof result.progress !== 'undefined') {
            that.emit('progress', result);
        } else if (result && typeof result.localPath !== 'undefined') {
            that.emit('complete', result);
        }
    };

    // triggered on error
    var fail = function(msg) {
        var e = (typeof msg === 'string') ? new Error(msg) : msg;
        that.emit('error', e);
    };

    // wait at least one process tick to allow event subscriptions
    setTimeout(function() {
        exec(success, fail, 'Sync', 'sync', [options.src, options.id, options.type, options.headers, options.copyCordovaAssets, options.copyRootApp, options.timeout, options.trustHost, options.manifest, options.validateSrc]);
    }, 10);
}
function(options) {
    this._handlers = {
        'progress': [],
        'cancel': [],
        'error': [],
        'complete': []
    };

    // require options parameter
    if (typeof options === 'undefined') {
        throw new Error('The options argument is required.');
    }

    // require options.src parameter
    if (typeof options.src === 'undefined' && options.type !== "local") {
        throw new Error('The options.src argument is required for merge replace types.');
    }

    // require options.id parameter
    if (typeof options.id === 'undefined') {
        throw new Error('The options.id argument is required.');
    }

    // define synchronization strategy
    //
    //     replace: This is the normal behavior. Existing content is replaced
    //              completely by the imported content, i.e. is overridden or
    //              deleted accordingly.
    //     merge:   Existing content is not modified, i.e. only new content is
    //              added and none is deleted or modified.
    //     local:   Existing content is not modified, i.e. only new content is
    //              added and none is deleted or modified.
    //
    if (typeof options.type === 'undefined') {
        options.type = 'replace';
    }

    if (typeof options.headers === 'undefined') {
        options.headers = null;
    }

    if (typeof options.copyCordovaAssets === 'undefined') {
        options.copyCordovaAssets = false;
    }

    if (typeof options.copyRootApp === 'undefined') {
        options.copyRootApp = false;
    }

    if (typeof options.timeout === 'undefined') {
        options.timeout = 15.0;
    }

    if (typeof options.trustHost === 'undefined') {
        options.trustHost = false;
    }

    if (typeof options.manifest === 'undefined') {
        options.manifest = "";
    }

    if (typeof options.validateSrc === 'undefined') {
        options.validateSrc = true;
    }

    // store the options to this object instance
    this.options = options;

    // triggered on update and completion
    var that = this;
    var success = function(result) {
        if (result && typeof result.progress !== 'undefined') {
            that.emit('progress', result);
        } else if (result && typeof result.localPath !== 'undefined') {
            that.emit('complete', result);
        }
    };

    // triggered on error
    var fail = function(msg) {
        var e = (typeof msg === 'string') ? new Error(msg) : msg;
        that.emit('error', e);
    };

    // wait at least one process tick to allow event subscriptions
    setTimeout(function() {
        exec(success, fail, 'Sync', 'sync', [options.src, options.id, options.type, options.headers, options.copyCordovaAssets, options.copyRootApp, options.timeout, options.trustHost, options.manifest, options.validateSrc]);
    }, 10);
}
ContentSync constructor.

@param {Object} options to initiate a new content synchronization.
@param {String} src is a URL to the content sync end-point.
@param {String} id is used as a unique identifier for the sync operation
@param {Object} type defines the sync strategy applied to the content.
@param {String} replace completely removes existing content then copies new content.
@param {String} merge   does not modify existing content, but adds new content.
@param {Object} headers are used to set the headers for when we send a request to the src URL
@param {Boolean} validateSrc whether to validate src url with a HEAD request before download (ios only, default true).
@return {ContentSync} instance that can be monitored and cancelled.