UNPKG

jsforce

Version:

Salesforce API Library for JavaScript

3 lines 262 kB
/*! jsforce - v1.3.0 - 2014-09-15 */ !function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;"undefined"!=typeof window?b=window:"undefined"!=typeof global?b=global:"undefined"!=typeof self&&(b=self),b.jsforce=a()}}(function(){var define,module,exports;return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){var c=a("underscore")._,d=(a("../promise"),function(a,b){this._report=a,this._conn=a._conn,this.id=b});d.prototype.retrieve=function(a){var b=this._conn,c=this._report,d=[b._baseUrl(),"analytics","reports",c.id,"instances",this.id].join("/");return b._request(d).thenCall(a)};var e=function(a,b){this._conn=a,this.id=b};e.prototype.describe=function(a){var b=[this._conn._baseUrl(),"analytics","reports",this.id,"describe"].join("/");return this._conn._request(b).thenCall(a)},e.prototype.run=e.prototype.exec=e.prototype.execute=function(a,b){a=a||{},c.isFunction(a)&&(b=a,a={});var d=[this._conn._baseUrl(),"analytics","reports",this.id].join("/");a.details&&(d+="?includeDetails=true");var e={method:a.metadata?"POST":"GET",url:d};return a.metadata&&(e.headers={"Content-Type":"application/json"},e.body=JSON.stringify(a.metadata)),this._conn._request(e).thenCall(b)},e.prototype.executeAsync=function(a,b){a=a||{},c.isFunction(a)&&(b=a,a={});var d=[this._conn._baseUrl(),"analytics","reports",this.id,"instances"].join("/");a.details&&(d+="?includeDetails=true");var e={method:"POST",url:d,body:""};return a.metadata&&(e.headers={"Content-Type":"application/json"},e.body=JSON.stringify(a.metadata)),this._conn._request(e).thenCall(b)},e.prototype.instance=function(a){return new d(this,a)},e.prototype.instances=function(a){var b=[this._conn._baseUrl(),"analytics","reports",this.id,"instances"].join("/");return this._conn._request(b).thenCall(a)};var f=function(a){this._conn=a};f.prototype.report=function(a){return new e(this._conn,a)},f.prototype.reports=function(a){var b=[this._conn._baseUrl(),"analytics","reports"].join("/");return this._conn._request(b).thenCall(a)},b.exports=f},{"../promise":21,underscore:63}],2:[function(a,b){var c=function(a){this._conn=a};c.prototype._baseUrl=function(){return this._conn.instanceUrl+"/services/apexrest"},c.prototype._createRequestParams=function(a,b,c){var d={method:a,url:this._baseUrl()+b};return/^(GET|DELETE)$/i.test(a)||(d.headers={"Content-Type":"application/json"}),c&&(d.body=JSON.stringify(c)),d},c.prototype.get=function(a,b){return this._conn._request(this._createRequestParams("GET",a)).thenCall(b)},c.prototype.post=function(a,b,c){"function"==typeof b&&(c=b,b=void 0);var d=this._createRequestParams("POST",a,b);return this._conn._request(d).thenCall(c)},c.prototype.put=function(a,b,c){"function"==typeof b&&(c=b,b=void 0);var d=this._createRequestParams("PUT",a,b);return this._conn._request(d).thenCall(c)},c.prototype.patch=function(a,b,c){"function"==typeof b&&(c=b,b=void 0);var d=this._createRequestParams("PATCH",a,b);return this._conn._request(d).thenCall(c)},c.prototype.del=c.prototype["delete"]=function(a,b){return this._conn._request(this._createRequestParams("DELETE",a)).thenCall(b)},b.exports=c},{}],3:[function(a,b){(function(c){var d=a("util"),e=a("stream"),f=e.Stream,g=a("events"),h=a("underscore")._,i=(a("../connection"),a("../record-stream")),j=(a("../csv"),a("../promise")),k=function(a,b,c,d,e){this._bulk=a,this.type=b,this.operation=c,this.options=d||{},this.id=e,this.state=this.id?"Open":"Unknown",this._batches={}};d.inherits(k,g.EventEmitter),k.prototype.info=function(a){return this._jobInfo||(this._jobInfo=this.check()),this._jobInfo.thenCall(a)},k.prototype.open=function(a){{var b=this,c=this._bulk;c._logger}if(!this._jobInfo){var d=['<?xml version="1.0" encoding="UTF-8"?>','<jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload">',"<operation>"+this.operation.toLowerCase()+"</operation>","<object>"+this.type+"</object>",this.options.extIdField?"<externalIdFieldName>"+this.options.extIdField+"</externalIdFieldName>":"","<contentType>CSV</contentType>","</jobInfo>"].join("");this._jobInfo=c._request({method:"POST",path:"/job",body:d,headers:{"Content-Type":"application/xml; charset=utf-8"},responseType:"application/xml"}).then(function(a){return b.emit("open",a.jobInfo),b.id=a.jobInfo.id,b.state=a.jobInfo.state,a.jobInfo},function(a){throw b.emit("error",a),a})}return this._jobInfo.thenCall(a)},k.prototype.createBatch=function(){var a=new l(this),b=this;return a.on("queue",function(){b._batches[a.id]=a}),a},k.prototype.batch=function(a){var b=this._batches[a];return b||(b=new l(this,a),this._batches[a]=b),b},k.prototype.check=function(a){var b=this,c=this._bulk,d=c._logger;return this._jobInfo=this._waitAssign().then(function(){return c._request({method:"GET",path:"/job/"+b.id,responseType:"application/xml"})}).then(function(a){return d.debug(a.jobInfo),b.id=a.jobInfo.id,b.type=a.jobInfo.object,b.operation=a.jobInfo.operation,b.state=a.jobInfo.state,a.jobInfo}),this._jobInfo.thenCall(a)},k.prototype._waitAssign=function(a){return(this.id?new j({id:this.id}):this.open()).thenCall(a)},k.prototype.list=function(a){var b=this,c=this._bulk,d=c._logger;return this._waitAssign().then(function(){return c._request({method:"GET",path:"/job/"+b.id+"/batch",responseType:"application/xml"})}).then(function(a){d.debug(a.batchInfoList.batchInfo);var b=a.batchInfoList;return b=h.isArray(b.batchInfo)?b.batchInfo:[b.batchInfo]}).thenCall(a)},k.prototype.close=function(){var a=this;return this._changeState("Closed").then(function(b){return a.id=null,a.emit("close",b),b},function(b){throw a.emit("error",b),b})},k.prototype.abort=function(){var a=this;return this._changeState("Aborted").then(function(b){return a.id=null,a.emit("abort",b),b},function(b){throw a.emit("error",b),b})},k.prototype._changeState=function(a,b){var c=this,d=this._bulk,e=d._logger;return this._jobInfo=this._waitAssign().then(function(){var b=['<?xml version="1.0" encoding="UTF-8"?>','<jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload">',"<state>"+a+"</state>","</jobInfo>"].join("");return d._request({method:"POST",path:"/job/"+c.id,body:b,headers:{"Content-Type":"application/xml; charset=utf-8"},responseType:"application/xml"})}).then(function(a){return e.debug(a.jobInfo),c.state=a.jobInfo.state,a.jobInfo}),this._jobInfo.thenCall(b)};var l=function(a,b){l.super_.apply(this),this.sendable=!0,this.job=a,this.id=b,this._bulk=a._bulk,this._csvStream=new i.CSVStream({nullValue:"#N/A"}),this._csvStream.stream().pipe(this.stream()),this._deferred=j.defer()};d.inherits(l,i),l.prototype.run=l.prototype.exec=l.prototype.execute=function(a,b){var c=this;if("function"==typeof a&&(b=a,a=null),this._result)throw new Error("Batch already executed.");var d=j.defer();if(this._result=d.promise,this._result.then(function(a){c._deferred.resolve(a)},function(a){c._deferred.reject(a)}),this.once("response",function(a){d.resolve(a)}),this.once("error",function(a){d.reject(a)}),a instanceof f)a.pipe(this.stream());else{var e;if(h.isArray(a))h.forEach(a,function(a){c.send(a)}),c.end();else if(h.isString(a)){e=a;var g=this.stream();g.write(e),g.end()}}return this.thenCall(b)},l.prototype.then=function(a,b,c){return this._deferred.promise.then(a,b,c)},l.prototype.thenCall=function(a){return h.isFunction(a)&&this.then(function(b){c.nextTick(function(){a(null,b)})},function(b){c.nextTick(function(){a(b)})}),this},l.prototype.send=function(a){return a=h.clone(a),"insert"===this.job.operation?delete a.Id:"delete"===this.job.operation&&(a={Id:a.Id}),delete a.type,delete a.attributes,this._csvStream.send(a)},l.prototype.end=function(a){a&&this.send(a),this.sendable=!1,this._csvStream.end()},l.prototype.check=function(a){var b=this._bulk,c=b._logger,d=this.job.id,e=this.id;if(!d||!e)throw new Error("Batch not started.");return b._request({method:"GET",path:"/job/"+d+"/batch/"+e,responseType:"application/xml"}).then(function(a){return c.debug(a.batchInfo),a.batchInfo}).thenCall(a)},l.prototype.poll=function(a,b){var c=this,d=this.job.id,e=this.id;if(!d||!e)throw new Error("Batch not started.");var f=(new Date).getTime(),g=function(){var d=(new Date).getTime();return d>f+b?void c.emit("error",new Error("polling time out")):void c.check(function(b,d){b?c.emit("error",b):"Failed"===d.state?parseInt(d.numberRecordsProcessed,10)>0?c.retrieve():c.emit("error",new Error(d.stateMessage)):"Completed"===d.state?c.retrieve():(c.emit("progress",d),setTimeout(g,a))})};setTimeout(g,a)},l.prototype.retrieve=function(a){var b=this,c=this._bulk,d=this.job.id,e=this.job,f=this.id;if(!d||!f)throw new Error("Batch not started.");return e.info().then(function(){return c._request({method:"GET",path:"/job/"+d+"/batch/"+f+"/result"})}).then(function(a){var g;if("query"===e.operation){{c._conn,a["result-list"].result}g=a["result-list"].result,g=h.map(h.isArray(g)?g:[g],function(a){return{id:a,batchId:f,jobId:d}})}else g=h.map(a,function(a){return{id:a.Id||null,success:"true"===a.Success,errors:a.Error?[a.Error]:[]}});return b.emit("response",g),g},function(a){throw b.emit("error",a),a}).thenCall(a)},l.prototype.result=function(a){var b=this.job.id,c=this.id;if(!b||!c)throw new Error("Batch not started.");return new i.CSVStream(null,this._bulk._request({method:"GET",path:"/job/"+b+"/batch/"+c+"/result/"+a}).stream())},l.prototype.stream=function(){return this._stream||(this._stream=new m(this)),this._stream};var m=function(a){m.super_.call(this),this.batch=a,this.writable=!0};d.inherits(m,f),m.prototype._getRequestStream=function(){var a=this.batch,b=a._bulk,c=b._logger;return this._reqStream||(this._reqStream=b._request({method:"POST",path:"/job/"+a.job.id+"/batch",headers:{"Content-Type":"text/csv"},responseType:"application/xml"},function(b,d){b?a.emit("error",b):(c.debug(d.batchInfo),a.id=d.batchInfo.id,a.emit("queue",d.batchInfo))}).stream()),this._reqStream},m.prototype.write=function(a){var b=this.batch;return b.job.id?this._getRequestStream().write(a):void this._queue(a)},m.prototype.end=function(a){var b=this.batch;return b.job.id?(this.writable=!1,void this._getRequestStream().end(a)):(this._ending=!0,void(a&&this._queue(a)))},m.prototype._queue=function(a){var b=this,c=this.batch,d=c.job;this._buffer||(this._buffer=[],d.open(function(a){return a?void c.emit("error",a):(b._buffer.forEach(function(a){b.write(a)}),b._ending&&b.end(),void(b._buffer=[]))})),this._buffer.push(a)};var n=function(a){this._conn=a,this._logger=a._logger};n.prototype.pollInterval=1e3,n.prototype.pollTimeout=1e4,n.prototype._request=function(a,b){var c=this._conn;a=h.clone(a);var d=[c.instanceUrl,"services/async",c.version].join("/");a.url=d+a.path;var e={responseContentType:a.responseType,beforesend:function(a,b){b.headers["X-SFDC-SESSION"]=a.accessToken},parseError:function(a){return{code:a.error.exceptionCode,message:a.error.exceptionMessage}}};return delete a.path,delete a.responseType,this._conn._request(a,b,e)},n.prototype.load=function(a,b,c,d,e){var f=this;if(!a||!b)throw new Error("Insufficient arguments. At least, 'type' and 'operation' are required.");"upsert"!==b.toLowerCase()&&(e=d,d=c,c=null);var g=this.createJob(a,b,c),h=g.createBatch(),i=function(){g.close()};return h.on("response",i),h.on("error",i),h.on("queue",function(){h.poll(f.pollInterval,f.pollTimeout)}),h.execute(d,e)},n.prototype.query=function(a){var b=a.replace(/\([\s\S]+\)/g,"").match(/FROM\s+(\w+)/i);if(!b)throw new Error("No sobject type found in query, maybe caused by invalid SOQL.");var c=b[1],d=this,e=new i.CSVStream;return this.load(c,"query",a).then(function(a){var b=a[0],c=d.job(b.jobId).batch(b.batchId).result(b.id);c.stream().pipe(e.stream())}),e},n.prototype.createJob=function(a,b,c){var d=new k(this,a,b,c);return d.open(),d},n.prototype.job=function(a){return new k(this,null,null,null,a)},b.exports=n}).call(this,a("_process"))},{"../connection":14,"../csv":16,"../promise":21,"../record-stream":23,_process:39,events:37,stream:43,underscore:63,util:46}],4:[function(a,b){var c=a("util"),d=a("underscore"),e=a("../promise"),f=b.exports=function(a){this._conn=a};f.prototype._request=function(a,b){return/^(put|post|patch)$/i.test(a.method)&&d.isObject(a.body)&&(a.headers={"Content-Type":"application/json"},a.body=JSON.stringify(a.body)),a.url=this._normalizeUrl(a.url),this._conn._request(a,b)},f.prototype._normalizeUrl=function(a){return 0===a.indexOf("/chatter/")||0===a.indexOf("/connect/")?"/services/data/v"+this._conn.version+a:/^\/v[\d]+\.[\d]+\//.test(a)?"/services/data"+a:0!==a.indexOf("/services/")&&"/"===a[0]?"/services/data/v"+this._conn.version+"/chatter"+a:a},f.prototype.request=function(a,b){return new g(this,a).thenCall(b)},f.prototype.resource=function(a,b){return new h(this,a,b)},f.prototype.batch=function(a,b){var c=[],f=[];d.forEach(a,function(a){var b=e.defer();a._promise=b.promise,c.push(a.batchParams()),f.push(b)});var g={method:"POST",url:this._normalizeUrl("/connect/batch"),body:{batchRequests:c}};return this._request(g).then(function(a){return d.forEach(a.results,function(a,b){var c=f[b];a.statusCode>=400?c.reject(a.result):c.resolve(a.result)}),a}).thenCall(b)};var g=function(a,b){this._chatter=a,this._params=b,this._promise=null};g.prototype.batchParams=function(){var a=this._params,b={method:a.method,url:this._chatter._normalizeUrl(a.url)};return this._params.body&&(b.richInput=this._params.body),b},g.prototype.promise=function(){return this._promise||this._chatter._request(this._params)},g.prototype.stream=function(){return this._chatter._request(this._params).stream()},g.prototype.then=function(a,b){return this.promise().then(a,b)},g.prototype.thenCall=function(a){return d.isFunction(a)?this.promise().thenCall(a):this};var h=function(a,b,c){if(c){var e=d.map(d.keys(c),function(a){return a+"="+encodeURIComponent(c[a])}).join("&");b+=(b.indexOf("?")>0?"&":"?")+e}h.super_.call(this,a,{method:"GET",url:b}),this._url=b};c.inherits(h,g),h.prototype.create=function(a,b){return this._chatter.request({method:"POST",url:this._url,body:a}).thenCall(b)},h.prototype.retrieve=function(a){return this.thenCall(a)},h.prototype.update=function(a,b){return this._chatter.request({method:"POST",url:this._url,body:a}).thenCall(b)},h.prototype.del=h.prototype["delete"]=function(a){return this._chatter.request({method:"DELETE",url:this._url}).thenCall(a)}},{"../promise":21,underscore:63,util:46}],5:[function(a,b){(function(c,d){function e(a){var b=k.clone(a);return b.success="true"===b.success,b}function f(a){var b=k.clone(a);return delete b.$,b}var g=a("util"),h=a("events"),i=a("stream"),j=i.Stream,k=a("underscore"),l=a("../promise"),m=a("../soap"),n=b.exports=function(a){this._conn=a};n.prototype.pollInterval=1e3,n.prototype.pollTimeout=1e4,n.prototype._invoke=function(a,b,c){var d=new m({sessionId:this._conn.accessToken,serverUrl:this._conn.instanceUrl+"/services/Soap/m/"+this._conn.version,xmlns:"http://soap.sforce.com/2006/04/metadata"},this._conn._transport);return d.invoke(a,b).then(function(a){return a.result}).thenCall(c)},n.prototype.createAsync=function(a,b,c){if(Number(this._conn.version)>30)throw new Error("Async metadata CRUD calls are not supported on ver 31.0 or later.");var d=function(b){return b["@xsi:type"]=a,b},e=k.isArray(b);b=e?k.map(b,d):d(b);var f=this._invoke("create",{metadata:b});return new o(this,f,e).thenCall(c)},n.prototype.createSync=n.prototype.create=function(a,b,c){var d=function(b){return b["@xsi:type"]=a,b},f=k.isArray(b);return b=f?k.map(b,d):d(b),this._invoke("createMetadata",{metadata:b}).then(function(a){return k.isArray(a)?k.map(a,e):e(a)}).thenCall(c)},n.prototype.readSync=n.prototype.read=function(a,b,c){return this._invoke("readMetadata",{type:a,fullNames:b}).then(function(a){return k.isArray(a.records)?k.map(a.records,f):f(a.records)}).thenCall(c)},n.prototype.updateAsync=function(a,b,c){if(Number(this._conn.version)>30)throw new Error("Async metadata CRUD calls are not supported on ver 31.0 or later.");var d=function(b){return b.metadata["@xsi:type"]=a,b},e=k.isArray(b);b=e?k.map(b,d):d(b);var f=this._invoke("update",{updateMetadata:b});return new o(this,f,e).thenCall(c)},n.prototype.updateSync=n.prototype.update=function(a,b,c){var d=function(b){return b["@xsi:type"]=a,b},f=k.isArray(b);return b=f?k.map(b,d):d(b),this._invoke("updateMetadata",{metadata:b}).then(function(a){return k.isArray(a)?k.map(a,e):e(a)}).thenCall(c)},n.prototype.upsertSync=n.prototype.upsert=function(a,b,c){var d=function(b){return b["@xsi:type"]=a,b},f=k.isArray(b);return b=f?k.map(b,d):d(b),this._invoke("upsertMetadata",{metadata:b}).then(function(a){return k.isArray(a)?k.map(a,e):e(a)}).thenCall(c)},n.prototype.deleteAsync=function(a,b,c){if(Number(this._conn.version)>30)throw new Error("Async metadata CRUD calls are not supported on ver 31.0 or later.");var d=function(b){return k.isString(b)&&(b={fullName:b}),b["@xsi:type"]=a,b},e=k.isArray(b);b=e?k.map(b,d):d(b);var f=this._invoke("delete",{metadata:b});return new o(this,f,e).thenCall(c)},n.prototype.del=n.prototype.deleteSync=n.prototype["delete"]=function(a,b,c){return this._invoke("deleteMetadata",{type:a,fullNames:b}).then(function(a){return k.isArray(a)?k.map(a,e):e(a)}).thenCall(c)},n.prototype.rename=function(a,b,c,d){return this._invoke("renameMetadata",{type:a,oldFullName:b,newFullName:c}).then(function(a){return e(a)}).thenCall(d)},n.prototype.checkStatus=function(a,b){var c=k.isArray(a),d=this._invoke("checkStatus",{asyncProcessId:a});return new o(this,d,c).thenCall(b)},n.prototype.describe=function(a,b){return k.isString(a)||(b=a,a=this._conn.version),this._invoke("describeMetadata",{asOfVersion:a}).then(function(a){return a.metadataObjects=k.isArray(a.metadataObjects)?a.metadataObjects:[a.metadataObjects],a.metadataObjects=k.map(a.metadataObjects,function(a){return a.childXmlNames&&(a.childXmlNames=k.isArray(a.childXmlNames)?a.childXmlNames:[a.childXmlNames]),a.inFolder="true"===a.inFolder,a.metaFile="true"===a.metaFile,a}),a.partialSaveAllowed="true"===a.partialSaveAllowed,a.testRequired="true"===a.testRequired,a}).thenCall(b)},n.prototype.list=function(a,b,c){return k.isString(b)||(c=b,b=this._conn.version),k.isArray(a)||(a=[a]),this._invoke("listMetadata",{queries:a,asOfVersion:b},c)},n.prototype.retrieve=function(a,b){var c=this._invoke("retrieve",{request:a});return new p(this,c).thenCall(b)},n.prototype.checkRetrieveStatus=function(a,b){return this._invoke("checkRetrieveStatus",{asyncProcessId:a},b)},n.prototype.deploy=function(a,b,c){(!b||k.isFunction(b))&&(c=b,b={});var e=l.defer();if(a instanceof j){var f=[];a.on("data",function(a){f.push(a)}),a.on("end",function(){e.resolve(d.concat(f))}),a.resume()}else{if(!(a instanceof d))throw"Unexpected zipInput type";e.resolve(a)}var g=this,h=e.promise.then(function(a){var d=a.toString("base64");return g._invoke("deploy",{ZipFile:d,DeployOptions:b},c)});return new q(this,h).thenCall(c)},n.prototype.checkDeployStatus=function(a,b,c){return k.isObject(b)||k.isBoolean(b)?b=!!b:(c=b,b=!1),this._invoke("checkDeployStatus",{asyncProcessId:a,includeDetails:b}).then(function(a){return a.done="true"===a.done,a.success="true"===a.success,a.checkOnly="true"===a.checkOnly,a.ignoreWarnings&&(a.ignoreWarnings="true"===a.ignoreWarnings),a.rollbackOnError&&(a.rollbackOnError="true"===a.rollbackOnError),a.numberComponentErrors=Number(a.numberComponentErrors),a.numberComponentsDeployed=Number(a.numberComponentsDeployed),a.numberComponentsTotal=Number(a.numberComponentsTotal),a.numberTestErrors=Number(a.numberTestErrors),a.numberTestsCompleted=Number(a.numberTestsCompleted),a.numberTestsTotal=Number(a.numberTestsTotal),a}).thenCall(c)};var o=function(a,b,c){this._meta=a,this._results=b,this._isArray=c};g.inherits(o,h.EventEmitter),o.prototype.then=function(a,b){var c=this;return this._results.then(function(b){var d=function(a){return a.$&&"true"===a.$["xsi:nil"]?null:(a.done="true"===a.done,a)};return b=k.isArray(b)?k.map(b,d):d(b),c._isArray&&!k.isArray(b)&&(b=[b]),a(b)},b)},o.prototype.thenCall=function(a){return k.isFunction(a)?this.then(function(b){c.nextTick(function(){a(null,b)})},function(b){c.nextTick(function(){a(b)})}):this},o.prototype.check=function(a){var b=this._meta;return this.then(function(a){var c=k.isArray(a)?k.map(a,function(a){return a.id}):a.id;return b.checkStatus(c)}).thenCall(a)},o.prototype.poll=function(a,b){var c=this,d=(new Date).getTime(),e=function(){var f=(new Date).getTime();return f>d+b?void c.emit("error",new Error("polling time out")):void c.check().then(function(b){for(var d=!0,f=k.isArray(b)?b:[b],g=0,h=f.length;h>g;g++){var i=f[g];i&&!i.done&&(d=!1)}d?c.emit("complete",b):setTimeout(e,a)},function(a){c.emit("error",a)})};setTimeout(e,a)},o.prototype.complete=function(a){var b=l.defer();this.on("complete",function(a){b.resolve(a)}),this.on("error",function(a){b.reject(a)});var c=this._meta;return this.poll(c.pollInterval,c.pollTimeout),b.promise.thenCall(a)};var p=function(a,b){p.super_.call(this,a,b)};g.inherits(p,o),p.prototype.complete=function(a){var b=this._meta;return p.super_.prototype.complete.call(this).then(function(a){return b.checkRetrieveStatus(a.id)}).thenCall(a)},p.prototype.stream=function(){var a=new j;return a.readable=!0,this.complete(function(b,c){b?a.emit("error",b):(a.emit("data",new d(c.zipFile,"base64")),a.emit("end"))}),a};var q=function(a,b){q.super_.call(this,a,b)};g.inherits(q,o),q.prototype.complete=function(a,b){k.isFunction(a)&&(b=a,a=!1);var c=this._meta;return q.super_.prototype.complete.call(this).then(function(b){return c.checkDeployStatus(b.id,a)}).thenCall(b)}}).call(this,a("_process"),a("buffer").Buffer)},{"../promise":21,"../soap":25,_process:39,buffer:33,events:37,stream:43,underscore:63,util:46}],6:[function(a,b){var c=a("events"),d=a("util"),e=a("faye"),f=b.exports=function(a,b){this._streaming=a,this.name=b};f.prototype.subscribe=function(a){return this._streaming.subscribe(this.name,a),this},f.prototype.unsubscribe=function(a){return this._streaming.unsubscribe(this.name,a),this};var g=function(a){this._conn=a};d.inherits(g,c.EventEmitter),g.prototype._createClient=function(){var a=[this._conn.instanceUrl,"cometd",this._conn.version].join("/"),b=new e.Client(a,{});return b.setHeader("Authorization","OAuth "+this._conn.accessToken),b},g.prototype.topic=function(a){this._topics=this._topics||{};var b=this._topics[a]=this._topics[a]||new f(this,a);return b},g.prototype.subscribe=function(a,b){return this._fayeClient||(e.Transport.NodeHttp&&(e.Transport.NodeHttp.prototype.batching=!1),this._fayeClient=this._createClient()),this._fayeClient.subscribe("/topic/"+a,b),this},g.prototype.unsubscribe=function(a,b){return this._fayeClient&&this._fayeClient.unsubscribe("/topic/"+a,b),this},b.exports=g},{events:37,faye:47,util:46}],7:[function(a,b){var c=(a("util"),a("underscore")._),d=a("../cache"),e=function(a){this._conn=a,this._logger=a._logger;var b=["query","queryMore","create","insert","retrieve","update","upsert","del","delete","destroy","describe","describeGlobal","sobject"];b.forEach(function(b){this[b]=a.constructor.prototype[b]},this),this.cache=new d;var c={key:function(a){return a?"describe."+a:"describe"}};this.describe$=this.cache.makeCacheable(this.describe,this,c),this.describe=this.cache.makeResponseCacheable(this.describe,this,c),this.describeSObject$=this.describe$,this.describeSObject=this.describe,c={key:"describeGlobal"},this.describeGlobal$=this.cache.makeCacheable(this.describeGlobal,this,c),this.describeGlobal=this.cache.makeResponseCacheable(this.describeGlobal,this,c),this.initialize()};e.prototype.initialize=function(){this.sobjects={},this.cache.clear(),this.cache.get("describeGlobal").on("value",c.bind(function(a){if(a.result){var b=c.map(a.result.sobjects,function(a){return a.name});c.each(b,this.sobject,this)}},this))},e.prototype._baseUrl=function(){return this._conn.urls.rest.base+"/tooling"},e.prototype._request=function(){return this._conn._request.apply(this._conn,arguments)},e.prototype.executeAnonymous=function(a,b){var c=this._baseUrl()+"/executeAnonymous?anonymousBody="+encodeURIComponent(a);return this._request(c).thenCall(b)},e.prototype.completions=function(a,b){c.isString(a)||(b=a,a="apex");var d=this._baseUrl()+"/completions?type="+encodeURIComponent(a);return this._request(d).thenCall(b)},b.exports=e},{"../cache":13,underscore:63,util:46}],8:[function(a,b){function c(a){var b={};return a.split(/\n/).forEach(function(a){var c=a.split(/\s*:\s*/),d=c[0].toLowerCase(),e=c[1];b[d]=e}),b}var d=a("stream"),e=a("underscore");b.exports={supported:"object"==typeof Sfdc&&"undefined"!=typeof Sfdc.canvas,createRequest:function(a){return function(b,f){function g(d){var g={client:a.client,method:b.method,data:d};if(b.headers){g.headers={};for(var j in b.headers)"content-type"===j.toLowerCase()?g.contentType=b.headers[j]:g.headers[j]=b.headers[j]}g.success=function(a){var b=c(a.responseHeaders),d=a.payload;e.isString(d)||(d=JSON.stringify(d)),h={statusCode:a.status,headers:b,body:d},f&&f(null,h,h.body),i.end()},g.failure=function(a){f&&f(a)},Sfdc.canvas.client.ajax(b.url,g)}var h,i=new d.Duplex;i._read=function(){h&&i.push(h.body)};var j=[],k=!1;return i._write=function(a,b,c){j.push(a.toString(b)),c()},i.on("finish",function(){k||(g(j.join("")),k=!0)}),(b.body||""===b.body||!/^(put|post|patch)$/i.test(b.method))&&(g(b.body),k=!0),i}}}},{stream:43,underscore:63}],9:[function(a,b){function c(a,b,c){var d=screen.width/2-b/2,e=screen.height/2-c/2;return window.open(a,null,"location=yes,toolbar=no,status=no,menubar=no,width="+b+",height="+c+",top="+e+",left="+d)}function d(){var a=e(),b=localStorage.getItem("jsforce_state");if(a&&b&&a.body.state===b){localStorage.removeItem("jsforce_state");var c=b.split("."),d=c[0],f=c[1],g=new m(d);return a.success?(g._storeTokens(a.body),location.hash=""):g._storeError(a.body),"popup"===f&&window.close(),!0}}function e(){var a;if(window.location.hash){if(a=h.parse(window.location.hash.substring(1)),a.access_token)return{success:!0,body:a}}else if(window.location.search&&(a=h.parse(window.location.search.substring(1)),a.error))return{success:!1,body:a}}var f=a("events"),g=a("util"),h=a("querystring"),i=a("underscore"),j=a("../connection"),k=a("../oauth2"),l=0,m=function(a){this._prefix=a||"jsforce"+l++,this.connection=null};g.inherits(m,f.EventEmitter),m.prototype.init=function(a){if(!d()){this.config=a,this.connection=new j(a);var b=this._getTokens();if(b){this.connection.initialize(b);var c=this;setTimeout(function(){c.emit("connect",c.connection)},10)}}},m.prototype.login=function(a,b){i.isFunction(a)&&(b=a,a={}),a=a||{},b=b||function(){},i.extend(a,this.config);this._prompt(a,b)},m.prototype._prompt=function(a,b){var d=this,e=new k(a),f=Math.random().toString(36).substring(2),g=[this._prefix,"popup",f].join(".");localStorage.setItem("jsforce_state",g);var h=e.getAuthorizationUrl({response_type:"token",scope:a.scope,state:g}),i=a.size||{},j=c(h,i.width||912,i.height||513);if(!j)return g=[this._prefix,"redirect",f].join("."),localStorage.setItem("jsforce_state",g),h=e.getAuthorizationUrl({response_type:"token",scope:a.scope,state:g}),void(location.href=h);d._removeTokens();var l=setInterval(function(){try{if(!j||j.closed){clearInterval(l);var a=d._getTokens();if(a)d.connection.initialize(a),d.emit("connect",d.connection),b(null,{status:"connect"});else{var c=d._getError();c?b(new Error(c.error+": "+c.error_description)):b(null,{status:"cancel"})}}}catch(e){}},1e3)},m.prototype.isLoggedIn=function(){return!(!this.connection||!this.connection.accessToken)},m.prototype.logout=function(){this.connection.logout(),this._removeTokens(),this.emit("disconnect")},m.prototype._getTokens=function(){var a=new RegExp("(^|;\\s*)"+this._prefix+"_loggedin=true(;|$)");if(document.cookie.match(a)){var b=Number(localStorage.getItem(this._prefix+"_issued_at"));if(Date.now()<b+72e5){var c,d=localStorage.getItem(this._prefix+"_id");if(d){var e=d.split("/");c={id:e.pop(),organizationId:e.pop(),url:d}}return{accessToken:localStorage.getItem(this._prefix+"_access_token"),instanceUrl:localStorage.getItem(this._prefix+"_instance_url"),userInfo:c}}}return null},m.prototype._storeTokens=function(a){localStorage.setItem(this._prefix+"_access_token",a.access_token),localStorage.setItem(this._prefix+"_instance_url",a.instance_url),localStorage.setItem(this._prefix+"_issued_at",a.issued_at),localStorage.setItem(this._prefix+"_id",a.id),document.cookie=this._prefix+"_loggedin=true;"},m.prototype._removeTokens=function(){localStorage.removeItem(this._prefix+"_access_token"),localStorage.removeItem(this._prefix+"_instance_url"),localStorage.removeItem(this._prefix+"_issued_at"),localStorage.removeItem(this._prefix+"_id"),document.cookie=this._prefix+"_loggedin="},m.prototype._getError=function(){try{var a=JSON.parse(localStorage.getItem(this._prefix+"_error"));return localStorage.removeItem(this._prefix+"_error"),a}catch(b){}},m.prototype._storeError=function(a){localStorage.setItem(this._prefix+"_error",JSON.stringify(a))},b.exports=new m,b.exports.Client=m},{"../connection":14,"../oauth2":20,events:37,querystring:42,underscore:63,util:46}],10:[function(a,b){var c,d=a("../jsforce");try{c=a("../core-require")}catch(e){}d.browser=a("./client"),d.modules=d.modules||{},d.require=function(a){try{return c(a)}catch(b){if("jsforce"===a||"./jsforce"===a)return d;if("./"===a.substring(0,2)){var e=a.substring(2).split("/"),f=e.pop();e.push(f.replace(/(^|\-)([a-zA-Z])/g,function(a,b,c){return c.toUpperCase()}));for(var g=d.modules;g&&e.length>0;)g=g[e.shift()];return g}}},b.exports=d},{"../core-require":15,"../jsforce":18,"./client":9}],11:[function(a,b){var c=0;b.exports={supported:"undefined"!=typeof window,createRequest:function(a,b){return a=a||"callback",b=b||1e4,function(d,e){if("GET"!==d.method.toUpperCase())return e(new Error("JSONP only supports GET request."));var f="_jsforce_jsonpCallback_"+ ++c,g=window,h=d.url;h+=h.indexOf("?")>0?"&":"?",h+=a+"="+f;var i=document.createElement("script");i.type="text/javascript",i.src=h,document.documentElement.appendChild(i);var j=setTimeout(function(){k(),e(new Error("JSONP call time out."))},b);g[f]=function(a){k(),e(null,{statusCode:200,headers:{"content-type":"application/json"},body:JSON.stringify(a)})};var k=function(){clearTimeout(j),document.documentElement.removeChild(i),delete g[f]}}}}},{}],12:[function(a,b){var c=a("stream");b.exports=function(a,b){var d=new XMLHttpRequest;if(d.open(a.method,a.url),a.headers)for(var e in a.headers)d.setRequestHeader(e,a.headers[e]);d.setRequestHeader("Accept","*/*");var f,g=new c.Duplex;g._read=function(){f&&g.push(f.body)};var h=[],i=!1;return g._write=function(a,b,c){h.push(a.toString("buffer"===b?"binary":b)),c()},g.on("finish",function(){i||(d.send(h.join("")),i=!0)}),(a.body||""===a.body||!/^(put|post|patch)$/i.test(a.method))&&(d.send(a.body),i=!0),d.onreadystatechange=function(){if(4===d.readyState){var a={"content-type":d.getResponseHeader("content-type")};f={statusCode:d.status,headers:a,body:d.response},f.statusCode||(f.statusCode=400,f.body="Access Declined"),b&&b(null,f,f.body),g.end()}},g}},{stream:43}],13:[function(a,b){function c(a,b){return b=Array.prototype.slice.apply(b),a+"("+f.map(b,function(a){return JSON.stringify(a)}).join(",")+")"}var d=a("events"),e=a("util"),f=a("underscore")._,g=function(){this.fetching=!1};e.inherits(g,d.EventEmitter),g.prototype.get=function(a){return a?(this.once("value",a),void(f.isUndefined(this._value)||this.emit("value",this._value))):this._value},g.prototype.set=function(a){this._value=a,this.emit("value",this._value)},g.prototype.clear=function(){this.fetching=!1,delete this._value };var h=function(){this._entries={}};h.prototype.get=function(a){if(a&&this._entries[a])return this._entries[a];var b=new g;return this._entries[a]=b,b},h.prototype.clear=function(a){for(var b in this._entries)a&&0!==b.indexOf(a)||this._entries[b].clear()},h.prototype.makeResponseCacheable=function(a,b,d){var e=this;return d=d||{},function(){var g=Array.prototype.slice.apply(arguments),h=g.pop();f.isFunction(h)||(g.push(h),h=null);var i=f.isString(d.key)?d.key:f.isFunction(d.key)?d.key.apply(b,g):c(d.namespace,g),j=e.get(i);j.fetching=!0,h&&g.push(function(a,b){j.set({error:a,result:b}),h(a,b)});var k,l;try{k=a.apply(b||this,g)}catch(m){l=m}if(k&&f.isFunction(k.then))return h?k:k.then(function(a){return j.set({error:void 0,result:a}),a},function(a){throw j.set({error:a,result:void 0}),a});if(j.set({error:l,result:k}),l)throw l;return k}},h.prototype.makeCacheable=function(a,b,d){var e=this;d=d||{};var g=function(){var g=Array.prototype.slice.apply(arguments),h=g.pop();f.isFunction(h)||g.push(h);var i=f.isString(d.key)?d.key:f.isFunction(d.key)?d.key.apply(b,g):c(d.namespace,g),j=e.get(i);if(!f.isFunction(h)){var k=j.get();if(!k)throw new Error("Function call result is not cached yet.");if(k.error)throw k.error;return k.result}j.get(function(a){h(a.error,a.result)}),j.fetching||(j.fetching=!0,g.push(function(a,b){j.set({error:a,result:b})}),a.apply(b||this,g))};return g.clear=function(){var a=f.isString(d.key)?d.key:f.isFunction(d.key)?d.key.apply(b,arguments):c(d.namespace,arguments);e.clear(a)},g},b.exports=h},{events:37,underscore:63,util:46}],14:[function(a,b){(function(c){function d(a){if(n.isString(a)){if("{"===a[0])return JSON.parse(a);var b=a.split(".").pop(),d=new c(b,"base64").toString("utf-8");return JSON.parse(d)}return a}function e(a){return JSON.parse(a)}function f(b){var c={};if(a("xml2js").parseString(b,{explicitArray:!1},function(a,b){c={error:a,result:b}}),c.error)throw c.error;return c.result}function g(b){return a("./csv").parseCSV(b)}function h(a){return a}function i(a){function b(a){return 10>a?"0"+a:a}return a.getUTCFullYear()+"-"+b(a.getUTCMonth()+1)+"-"+b(a.getUTCDate())+"T"+b(a.getUTCHours())+":"+b(a.getUTCMinutes())+":"+b(a.getUTCSeconds())+"+00:00"}function j(a){var b=a.split("/"),c=b.pop(),d=b.pop();return{id:c,organizationId:d,url:a}}function k(a){return a&&String(a).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}var l=a("events"),m=a("util"),n=(a("async"),a("underscore")._),o=a("./promise"),p=a("./logger"),q=a("./oauth2"),r=a("./query"),s=a("./sobject"),t=a("./transport"),u=a("./cache"),v={loginUrl:"https://login.salesforce.com",instanceUrl:"",version:"31.0"},w=b.exports=function(b){var c=a("./api/bulk"),d=a("./api/streaming"),e=a("./api/tooling"),f=a("./api/analytics"),g=a("./api/chatter"),h=a("./api/apex"),i=a("./api/metadata");b=b||{},this._logger=new p(b.logLevel);var j=b.oauth2||{loginUrl:b.loginUrl,clientId:b.clientId,clientSecret:b.clientSecret,redirectUri:b.redirectUri};this.oauth2=j instanceof q?j:new q(j),this.loginUrl=b.loginUrl||j.loginUrl||v.loginUrl,this.version=b.version||v.version,this.maxRequest=b.maxRequest||this.maxRequest||10,this._transport=b.proxyUrl?new t.ProxyTransport(b.proxyUrl):new t,d&&(this.streaming=new d(this)),c&&(this.bulk=new c(this)),e&&(this.tooling=new e(this)),f&&(this.analytics=new f(this)),g&&(this.chatter=new g(this)),i&&(this.metadata=new i(this)),h&&(this.apex=new h(this)),this.cache=new u,b.refreshFn&&(this._refreshDelegate={refreshToken:b.refreshFn});var k={key:function(a){return a?"describe."+a:"describe"}};this.describe$=this.cache.makeCacheable(this.describe,this,k),this.describe=this.cache.makeResponseCacheable(this.describe,this,k),this.describeSObject$=this.describe$,this.describeSObject=this.describe,k={key:"describeGlobal"},this.describeGlobal$=this.cache.makeCacheable(this.describeGlobal,this,k),this.describeGlobal=this.cache.makeResponseCacheable(this.describeGlobal,this,k),this.initialize(b)};m.inherits(w,l.EventEmitter),w.prototype.initialize=function(a){if(!a.instanceUrl&&a.serverUrl&&(a.instanceUrl=a.serverUrl.split("/").slice(0,3).join("/")),this.instanceUrl=a.instanceUrl||a.serverUrl||this.instanceUrl||v.instanceUrl,this.urls={soap:{login:[this.loginUrl,"services/Soap/u",this.version].join("/"),service:[this.instanceUrl,"services/Soap/u",this.version].join("/")},rest:{base:[this.instanceUrl,"services/data","v"+this.version].join("/")}},this.accessToken=a.sessionId||a.accessToken||this.accessToken,this.refreshToken=a.refreshToken||this.refreshToken,this.refreshToken&&!this.oauth2&&!this._refreshDelegate)throw new Error("Refresh token is specified without oauth2 client information");this.signedRequest=a.signedRequest&&d(a.signedRequest),this.signedRequest&&(this.accessToken=this.signedRequest.client.oauthToken),a.userInfo&&(this.userInfo=a.userInfo),this.limitInfo={},this.sobjects={},this.cache.clear(),this.cache.get("describeGlobal").on("value",n.bind(function(a){if(a.result){var b=n.map(a.result.sobjects,function(a){return a.name});n.each(b,this.sobject,this)}},this)),this.tooling&&this.tooling.initialize(),this._sessionType=a.sessionId?"soap":"oauth2",this._initializedAt=Date.now()},w.prototype._baseUrl=function(){return this.urls.rest.base},w.prototype._request=function(a,b,c){c=c||{},n.isString(a)&&(a={method:"GET",url:a}),"/"===a.url[0]&&(a.url=this.instanceUrl+a.url);var d=this,i=this._logger,j=o.defer(),k=function(b){return b?void j.reject(b):void d._request(a,null,c).then(function(a){j.resolve(a)},function(a){j.reject(a)})};if(d._suspended)return d.once("resume",k),j.promise.thenCall(b);a.headers=a.headers||{},this.accessToken&&(a.headers.Authorization="Bearer "+this.accessToken),c.beforesend&&c.beforesend(this,a),this.signedRequest&&(c.signedRequest=this.signedRequest),d.emit("request",a.method,a.url,a),i.debug("<request> method="+a.method+", url="+a.url);var l=Date.now(),m=function(a){var b=Date.now();throw i.debug("elappsed time : "+(b-l)+"msec"),i.error(a),a},p=function(b){var m=Date.now();if(i.debug("elappsed time : "+(m-l)+"msec"),i.debug("<response> status="+b.statusCode+", url="+a.url),d.emit("response",b.statusCode,b.body,b),b.headers&&b.headers["sforce-limit-info"]){var o=b.headers["sforce-limit-info"].match(/api\-usage=(\d+)\/(\d+)/);o&&(d.limitInfo={apiUsage:{used:parseInt(o[1],10),limit:parseInt(o[2],10)}})}if(401===b.statusCode&&(d._refreshDelegate||d.oauth2&&d.refreshToken))return d._initializedAt>l?k():(d.once("resume",k),d._suspended||(d._suspended=!0,d._refresh())),j.promise;var p,q=c.responseContentType||b.headers&&b.headers["content-type"],r=/^application\/xml(;|$)/.test(q)?f:/^application\/json(;|$)/.test(q)?e:/^text\/csv(;|$)/.test(q)?g:h;if(b.statusCode>=400){var s;try{var t=c.parseError||function(a){var b=n.isArray(a)?a[0]:a;return n.isObject(b)&&n.isString(b.message)?b:void 0};s=t(r(b.body))}catch(u){}s||(s={message:b.body,errorCode:"ERROR_HTTP_"+b.statusCode}),p=new Error(s.message),p.name=s.errorCode;for(var v in s)p[v]=s[v];throw p}if(204===b.statusCode)return c.noContentResponse;var w=r(b.body);if(300===b.statusCode)throw p=new Error("Multiple records found"),p.name="MULTIPLE_CHOICES",p.content=w,p;return w};return this._transport.httpRequest(a,null,c).then(p,m).thenCall(b)},w.prototype._refresh=function(){var a=this,b=this._logger;b.debug("<refresh token>");var c=this._refreshDelegate||this.oauth2;return c.refreshToken(this.refreshToken,function(c,d){if(!c){var e=j(d.id);a.initialize({instanceUrl:d.instance_url,accessToken:d.access_token,userInfo:e}),b.debug("token refresh completed. result = "+JSON.stringify(d)),a.emit("refresh",d.access_token,d)}a._suspended=!1,a.emit("resume",c)})},w.prototype.query=function(a,b){var c=new r(this,a);return b&&c.run(b),c},w.prototype.queryAll=function(a,b){var c=new r(this,a);return c.scanAll(!0),b&&c.run(b),c},w.prototype.queryMore=function(a,b){var c=new r(this,null,a);return b&&c.run(b),c},w.prototype.retrieve=function(a,b,c,d){"function"==typeof c&&(d=c,c={});var e=this,f=n.isArray(b);return b=f?b:[b],b.length>e.maxRequest?o.reject(new Error("Exceeded max limit of concurrent call")).thenCall(d):o.all(n.map(b,function(b){var c=[e._baseUrl(),"sobjects",a,b].join("/");return e._request(c)})).then(function(a){return!f&&n.isArray(a)?a[0]:a}).thenCall(d)},w.prototype.insert=w.prototype.create=function(a,b,c,d){n.isString(a)||(d=c,c=b,b=a,a=null),"function"==typeof c&&(d=c,c={}),c=c||{};var e=this,f=n.isArray(b);return b=f?b:[b],b.length>e.maxRequest?o.reject(new Error("Exceeded max limit of concurrent call")).thenCall(d):o.all(n.map(b,function(b){var d=a||b.attributes&&b.attributes.type||b.type;if(!d)throw new Error("No SObject Type defined in record");b=n.clone(b),delete b.Id,delete b.type,delete b.attributes;var f=[e._baseUrl(),"sobjects",d].join("/");return e._request({method:"POST",url:f,body:JSON.stringify(b),headers:n.defaults(c.headers||{},{"Content-Type":"application/json"})})})).then(function(a){return!f&&n.isArray(a)?a[0]:a}).thenCall(d)},w.prototype.update=function(a,b,c,d){n.isString(a)||(d=c,c=b,b=a,a=null),"function"==typeof c&&(d=c,c={}),c=c||{};var e=this,f=n.isArray(b);return b=f?b:[b],b.length>e.maxRequest?o.reject(new Error("Exceeded max limit of concurrent call")).thenCall(d):o.all(n.map(b,function(b){var d=b.Id;if(!d)throw new Error("Record id is not found in record.");var f=a||b.attributes&&b.attributes.type||b.type;if(!f)throw new Error("No SObject Type defined in record");b=n.clone(b),delete b.Id,delete b.type,delete b.attributes;var g=[e._baseUrl(),"sobjects",f,d].join("/");return e._request({method:"PATCH",url:g,body:JSON.stringify(b),headers:n.defaults(c.headers||{},{"Content-Type":"application/json"})},null,{noContentResponse:{id:d,success:!0,errors:[]}})})).then(function(a){return!f&&n.isArray(a)?a[0]:a}).thenCall(d)},w.prototype.upsert=function(a,b,c,d,e){n.isString(a)||(e=d,d=c,c=b,b=a,a=null),"function"==typeof d&&(e=d,d={}),d=d||{};var f=this,g=n.isArray(b);return b=g?b:[b],b.length>f.maxRequest?o.reject(new Error("Exceeded max limit of concurrent call")).thenCall(e):o.all(n.map(b,function(b){var e=a||b.attributes&&b.attributes.type||b.type,g=b[c];if(!g)return o.reject(new Error("External ID is not defined in the record"));b=n.clone(b),delete b[c],delete b.type,delete b.attributes;var h=[f._baseUrl(),"sobjects",e,c,g].join("/");return f._request({method:"PATCH",url:h,body:JSON.stringify(b),headers:n.defaults(d.headers||{},{"Content-Type":"application/json"})},null,{noContentResponse:{success:!0,errors:[]}})})).then(function(a){return!g&&n.isArray(a)?a[0]:a}).thenCall(e)},w.prototype["delete"]=w.prototype.del=w.prototype.destroy=function(a,b,c,d){"function"==typeof c&&(d=c,c={}),c=c||{};var e=this,f=n.isArray(b);return b=f?b:[b],b.length>e.maxRequest?o.reject(new Error("Exceeded max limit of concurrent call")).thenCall(d):o.all(n.map(b,function(b){var d=[e._baseUrl(),"sobjects",a,b].join("/");return e._request({method:"DELETE",url:d,headers:c.headers||null},null,{noContentResponse:{id:b,success:!0,errors:[]}})})).then(function(a){return!f&&n.isArray(a)?a[0]:a}).thenCall(d)},w.prototype.search=function(a,b){var c=this._baseUrl()+"/search?q="+encodeURIComponent(a);return this._request(c).thenCall(b)},w.prototype.describe=w.prototype.describeSObject=function(a,b){var c=[this._baseUrl(),"sobjects",a,"describe"].join("/");return this._request(c).thenCall(b)},w.prototype.describeGlobal=function(a){var b=this._baseUrl()+"/sobjects";return this._request(b).thenCall(a)},w.prototype.sobject=function(a){this.sobjects=this.sobjects||{};var b=this.sobjects[a]=this.sobjects[a]||new s(this,a);return b},w.prototype.identity=function(a){var b=this,c=this.userInfo&&this.userInfo.url;return new o(c?{identity:c}:this._request(this._baseUrl())).then(function(a){var c=a.identity;return c+="?format=json&oauth_token="+encodeURIComponent(b.accessToken),b._request(c,null,{jsonp:"callback"})}).then(function(a){return b.userInfo={id:a.user_id,organizationId:a.organization_id,url:a.id},a}).thenCall(a)},w.prototype.authorize=function(a,b){var c=this,d=this._logger;return this.oauth2.requestToken(a).then(function(a){d.debug("OAuth2 token response = "+JSON.stringify(a));var b=j(a.id);return c.initialize({instanceUrl:a.instance_url,accessToken:a.access_token,refreshToken:a.refresh_token,userInfo:b}),d.debug("<login> completed. user id = "+b.id+", org id = "+b.organizationId),b}).thenCall(b)},w.prototype.login=function(a,b,c){return this.oauth2&&this.oauth2.clientId&&this.oauth2.clientSecret?this.loginByOAuth2(a,b,c):this.loginBySoap(a,b,c)},w.prototype.loginByOAuth2=function(a,b,c){var d=this,e=this._logger;return this.oauth2.authenticate(a,b).then(function(a){e.debug("OAuth2 token response = "+JSON.stringify(a));var b=j(a.id);return d.initialize({instanceUrl:a.instance_url,accessToken:a.access_token,userInfo:b}),e.debug("<login> completed. user id = "+b.id+", org id = "+b.organizationId),b}).thenCall(c)},w.prototype.loginBySoap=function(a,b,c){var d=this,e=this._logger,f=['<se:Envelope xmlns:se="http://schemas.xmlsoap.org/soap/envelope/">',"<se:Header/>","<se:Body>",'<login xmlns="urn:partner.soap.sforce.com">',"<username>"+k(a)+"</username>","<password>"+k(b)+"</password>","</login>","</se:Body>","</se:Envelope>"].join("");return this._transport.httpRequest({method:"POST",url:this.urls.soap.login,body:f,headers:{"Content-Type":"text/xml",SOAPAction:'""'}}).then(function(a){var b;if(a.statusCode>=400){b=a.body.match(/<faultstring>([^<]+)<\/faultstring>/);var c=b&&b[1];throw new Error(c||a.body)}e.debug("SOAP response = "+a.body),b=a.body.match(/<serverUrl>([^<]+)<\/serverUrl>/);var f=b&&b[1];b=a.body.match(/<sessionId>([^<]+)<\/sessionId>/);var g=b&&b[1];b=a.body.match(/<userId>([^<]+)<\/userId>/);var h=b&&b[1];b=a.body.match(/<organizationId>([^<]+)<\/organizationId>/);var i=b&&b[1],j=d.urls.soap.login.split("/").slice(0,3).join("/");j+="/id/"+i+"/"+h;var k={id:h,organizationId:i,url:j};return d.initialize({serverUrl:f.split("/").slice(0,3).join("/"),sessionId:g,userInfo:k}),e.debug("<login> completed. user id = "+h+", org id = "+i),k}).thenCall(c)},w.prototype.logout=function(a){return"oauth2"===this._sessionType?this.logoutByOAuth2(a):this.logoutBySoap(a)},w.prototype.logoutByOAuth2=function(a){{var b=this;this._logger}return this.oauth2.revokeToken(this.accessToken).then(function(){return b.accessToken=null,b.userInfo=null,b.refreshToken=null,b.instanceUrl=null,void b.cache.clear()}).thenCall(a)},w.prototype.logoutBySoap=function(a){var b=this,c=this._logger,d=['<se:Envelope xmlns:se="http://schemas.xmlsoap.org/soap/envelope/">',"<se:Header>",'<SessionHeader xmlns="urn:partner.soap.sforce.com">',"<sessionId>"+k(this.accessToken)+"</sessionId>","</SessionHeader>","</se:Header>","<se:Body>",'<logout xmlns="urn:partner.soap.sforce.com"/>',"</se:Body>","</se:Envelope>"].join("");return this._transport.httpRequest({method:"POST",url:this.urls.soap.service,body:d,headers:{"Content-Type":"text/xml",SOAPAction:'""'}}).then(function(a){if(c.debug("SOAP statusCode = "+a.statusCode+", response = "+a.body),a.statusCode>=400){var d=a.body.match(/<faultstring>([^<]+)<\/faultstring>/),e=d&&d[1];throw new Error(e||a.body)}return b.accessToken=null,b.userInfo=null,b.refreshToken=null,b.instanceUrl=null,void b.cache.clear()}).thenCall(a)},w.prototype.recent=function(a,b,c){n.isString(a)||(c=b,b=a,a=void 0),n.isNumber(b)||(c=b,b=void 0);var d;return a?(d=[this._baseUrl(),"sobjects",a].join("/"),this._request(d).then(function(a){return b?a.recentItems.slice(0,b):a.recentItems}).thenCall(c)):(d=this._baseUrl()+"/recent",b&&(d+="?limit="+b),this._request(d).thenCall(c))},w.prototype.updated=function(a,b,c,d){var e=[this._baseUrl(),"sobjects",a,"updated"].join("/");return"string"==typeof b&&(b=new Date(b)),b instanceof Date&&(b=i(b)),b&&(e+="?start="+encodeURIComponent(b)),"string"==typeof c&&(c=new Date(c)),c instanceof Date&&(c=i(c)),c&&(e+="&end="+encodeURIComponent(c)),this._request(e).thenCall(d)},w.prototype.deleted=function(a,b,c,d){var e=[this._baseUrl(),"sobjects",a,"deleted"].join("/");return"string"==typeof b&&(b=new Date(b)),b instanceof Date&&(b=i(b)),b&&(e+="?start="+encodeURIComponent(b)),"string"==typeof c&&(c=new Date(c)),c instanceof Date&&(c=i(c)),c&&(e+="&end="+encodeURIComponent(c)),this._request(e).thenCall(d)}}).call(this,a("buffer").Buffer)},{"./api/analytics":1,"./api/apex":2,"./api/bulk":3,"./api/chatter":4,"./api/metadata":5,"./api/streaming":6,"./api/tooling":7,"./cache":13,"./csv":16,"./logger":19,"./oauth2":20,"./promise":21,"./query":22,"./sobject":26,"./transport":28,async:29,buffer:33,events:37,underscore:63,util:46,xml2js:66}],15:[function(a,b){b.exports=function(b){return a(b)},a("events"),a("util"),a("underscore"),a("async"),a("./promise"),a("./logger"),a("./oauth2"),a("./query"),a("./sobject"),a("./transport"),a("./cache"),a("xml2js"),a("./csv"),a("./date"),a("./connection"),a("./record-stream"),a("querystring"),a("q"),a("./soql-builder"),a("stream"),a("./record"),a("request"),a("./browser/request"),a("./browser/canvas"),a("./browser/jsonp")},{"./browser/canvas":8,"./browser/jsonp":11,"./browser/request":12,"./cache":13,"./connection":14,"./csv":16,"./date":17,"./logger":19,"./oauth2":20,"./promise":21,"./query":22,"./record":24,"./record-stream":23,"./sobject":26,"./soql-builder":27,"./transport":28,async:29,events:37,q:48,querystring:42,request:31,stream:43,underscore:63,util:46,xml2js:66}],16:[function(a,b){function c(a,b,c){c=c||{},b||(b=d(a,c));var g=i.map(a,function(a){return e(a,b,c)});return f(b)+"\n"+g.join("\n")}function d(a,b){b=b||{};var c={};return i.forEach(a,function(a){for(var b in a){var d=a[b];!a.hasOwnProperty(b)||null!==d&&"object"==typeof d||(c[b]=!0)}}),i.keys(c)}function e(a,b,c){c=c||{};var d=[];return i.forEach(b,function(b){var e=a[b];null===e&&"undefined"!=typeof c.nullValue&&(e=c.nullValue),"undefined"==typeof e&&(e=null),d.push