/* * Copyright (c) 2015, salesforce.com, inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /*jslint browser: true, plusplus: true*/ /*global alert, Promise, forcetk, JXON*/ /* * BulkTK: JavaScript library to wrap Force.com Bulk API. Extends ForceTK. * Dependencies: * jquery - http://jquery.com/ * ForceTK - https://github.com/developerforce/Force.com-JavaScript-REST-Toolkit/blob/master/forcetk.js * jxon - https://github.com/developerforce/Force.com-JavaScript-REST-Toolkit/blob/master/jxon.js * (originally from the [Ratatosk](https://github.com/wireload/Ratatosk) * project; this version preserves case in element and attribute names) */ forcetk.Client.prototype.xmlHeader = "\n"; /* * Low level utility function to call the Bulk API. * @param path resource path * @param parseXML set to true to parse XML response * @param [method="GET"] HTTP method for call * @param [contentType=null] Content type of payload - e.g. 'application/xml; charset=UTF-8' * @param [payload=null] payload for POST * @param [parseXML=false] set to true to parse XML response */ forcetk.Client.prototype.bulkAjax = function (path, parseXML, method, contentType, payload, retry) { 'use strict'; if (this.debug) { console.log('bulkAjax sending: ', payload); } var that = this, url = this.instanceUrl + path, promise = new Promise(function (resolve, reject) { method = method || 'GET'; var xhr = new XMLHttpRequest(); if (that.asyncAjax) { xhr.onreadystatechange = function () { if (xhr.readyState === 4) { if (xhr.status > 199 && xhr.status < 300) { var respContentType = xhr.getResponseHeader('Content-Type'), data = xhr.responseText; // Naughty Bulk API doesn't always set Content-Type! if (parseXML && ((respContentType && respContentType.indexOf('application/xml') === 0) || data.indexOf('