jsforce
Version:
Salesforce API Library for JavaScript
4 lines • 38.9 kB
JavaScript
/*! 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);var c=b;c=c.jsforce||(c.jsforce={}),c=c.modules||(c.modules={}),c=c.api||(c.api={}),c.Streaming=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=jsforce.require("events"),d=jsforce.require("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},{faye:3}],2:[function(a,b){function c(){}var d=b.exports={};d.nextTick=function(){var a="undefined"!=typeof window&&window.setImmediate,b="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(a)return function(a){return window.setImmediate(a)};if(b){var c=[];return window.addEventListener("message",function(a){var b=a.source;if((b===window||null===b)&&"process-tick"===a.data&&(a.stopPropagation(),c.length>0)){var d=c.shift();d()}},!0),function(a){c.push(a),window.postMessage("process-tick","*")}}return function(a){setTimeout(a,0)}}(),d.title="browser",d.browser=!0,d.env={},d.argv=[],d.on=c,d.addListener=c,d.once=c,d.off=c,d.removeListener=c,d.removeAllListeners=c,d.emit=c,d.binding=function(){throw new Error("process.binding is not supported")},d.cwd=function(){return"/"},d.chdir=function(){throw new Error("process.chdir is not supported")}},{}],3:[function(require,module,exports){(function(process,global){!function(){"use strict";var Faye={VERSION:"1.0.3",BAYEUX_VERSION:"1.0",ID_LENGTH:160,JSONP_CALLBACK:"jsonpcallback",CONNECTION_TYPES:["long-polling","cross-origin-long-polling","callback-polling","websocket","eventsource","in-process"],MANDATORY_CONNECTION_TYPES:["long-polling","callback-polling","in-process"],ENV:"undefined"!=typeof window?window:global,extend:function(a,b,c){if(!b)return a;for(var d in b)b.hasOwnProperty(d)&&(a.hasOwnProperty(d)&&c===!1||a[d]!==b[d]&&(a[d]=b[d]));return a},random:function(a){return a=a||this.ID_LENGTH,csprng(a,36)},clientIdFromMessages:function(a){var b=this.filter([].concat(a),function(a){return"/meta/connect"===a.channel});return b[0]&&b[0].clientId},copyObject:function(a){var b,c,d;if(a instanceof Array){for(b=[],c=a.length;c--;)b[c]=Faye.copyObject(a[c]);return b}if("object"==typeof a){b=null===a?null:{};for(d in a)b[d]=Faye.copyObject(a[d]);return b}return a},commonElement:function(a,b){for(var c=0,d=a.length;d>c;c++)if(-1!==this.indexOf(b,a[c]))return a[c];return null},indexOf:function(a,b){if(a.indexOf)return a.indexOf(b);for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1},map:function(a,b,c){if(a.map)return a.map(b,c);var d=[];if(a instanceof Array)for(var e=0,f=a.length;f>e;e++)d.push(b.call(c||null,a[e],e));else for(var g in a)a.hasOwnProperty(g)&&d.push(b.call(c||null,g,a[g]));return d},filter:function(a,b,c){if(a.filter)return a.filter(b,c);for(var d=[],e=0,f=a.length;f>e;e++)b.call(c||null,a[e],e)&&d.push(a[e]);return d},asyncEach:function(a,b,c,d){var e=a.length,f=-1,g=0,h=!1,i=function(){return g-=1,f+=1,f===e?c&&c.call(d):void b(a[f],k)},j=function(){if(!h){for(h=!0;g>0;)i();h=!1}},k=function(){g+=1,j()};k()},toJSON:function(a){return this.stringify?this.stringify(a,function(a,b){return this[a]instanceof Array?this[a]:b}):JSON.stringify(a)}};"undefined"!=typeof module?module.exports=Faye:"undefined"!=typeof window&&(window.Faye=Faye),Faye.Class=function(a,b){"function"!=typeof a&&(b=a,a=Object);var c=function(){return this.initialize?this.initialize.apply(this,arguments)||this:this},d=function(){};return d.prototype=a.prototype,c.prototype=new d,Faye.extend(c.prototype,b),c},function(){function a(a,b){if(a.indexOf)return a.indexOf(b);for(var c=0;c<a.length;c++)if(b===a[c])return c;return-1}var b=Faye.EventEmitter=function(){},c="function"==typeof Array.isArray?Array.isArray:function(a){return"[object Array]"===Object.prototype.toString.call(a)};b.prototype.emit=function(a){if("error"===a&&(!this._events||!this._events.error||c(this._events.error)&&!this._events.error.length))throw arguments[1]instanceof Error?arguments[1]:new Error("Uncaught, unspecified 'error' event.");if(!this._events)return!1;var b=this._events[a];if(!b)return!1;if("function"==typeof b){switch(arguments.length){case 1:b.call(this);break;case 2:b.call(this,arguments[1]);break;case 3:b.call(this,arguments[1],arguments[2]);break;default:var d=Array.prototype.slice.call(arguments,1);b.apply(this,d)}return!0}if(c(b)){for(var d=Array.prototype.slice.call(arguments,1),e=b.slice(),f=0,g=e.length;g>f;f++)e[f].apply(this,d);return!0}return!1},b.prototype.addListener=function(a,b){if("function"!=typeof b)throw new Error("addListener only takes instances of Function");return this._events||(this._events={}),this.emit("newListener",a,b),this._events[a]?c(this._events[a])?this._events[a].push(b):this._events[a]=[this._events[a],b]:this._events[a]=b,this},b.prototype.on=b.prototype.addListener,b.prototype.once=function(a,b){var c=this;return c.on(a,function d(){c.removeListener(a,d),b.apply(this,arguments)}),this},b.prototype.removeListener=function(b,d){if("function"!=typeof d)throw new Error("removeListener only takes instances of Function");if(!this._events||!this._events[b])return this;var e=this._events[b];if(c(e)){var f=a(e,d);if(0>f)return this;e.splice(f,1),0==e.length&&delete this._events[b]}else this._events[b]===d&&delete this._events[b];return this},b.prototype.removeAllListeners=function(a){return 0===arguments.length?(this._events={},this):(a&&this._events&&this._events[a]&&(this._events[a]=null),this)},b.prototype.listeners=function(a){return this._events||(this._events={}),this._events[a]||(this._events[a]=[]),c(this._events[a])||(this._events[a]=[this._events[a]]),this._events[a]}}(),Faye.Namespace=Faye.Class({initialize:function(){this._used={}},exists:function(a){return this._used.hasOwnProperty(a)},generate:function(){for(var a=Faye.random();this._used.hasOwnProperty(a);)a=Faye.random();return this._used[a]=a},release:function(a){delete this._used[a]}}),function(){var a,b=setTimeout;a="function"==typeof setImmediate?function(a){setImmediate(a)}:"object"==typeof process&&process.nextTick?function(a){process.nextTick(a)}:function(a){b(a,0)};var c=0,d=1,e=2,f=function(a){return a},g=function(a){throw a},h=function(a){if(this._state=c,this._callbacks=[],this._errbacks=[],"function"==typeof a){var b=this;a(function(a){m(b,a)},function(a){n(b,a)})}};h.prototype.then=function(a,b){var c={},d=this;return c.promise=new h(function(e,f){c.fulfill=e,c.reject=f,i(d,a,c),j(d,b,c)}),c.promise};var i=function(a,b,e){"function"!=typeof b&&(b=f);var g=function(a){k(b,a,e)};a._state===c?a._callbacks.push(g):a._state===d&&g(a._value)},j=function(a,b,d){"function"!=typeof b&&(b=g);var f=function(a){k(b,a,d)};a._state===c?a._errbacks.push(f):a._state===e&&f(a._reason)},k=function(b,c,d){a(function(){l(b,c,d)})},l=function(a,b,c){var d,e,g,h=!1;try{if(d=a(b),e=typeof d,g=null!==d&&("function"===e||"object"===e)&&d.then,d===c.promise)return c.reject(new TypeError("Recursive promise chain detected"));if("function"!=typeof g)return c.fulfill(d);g.call(d,function(a){h||(h=!0,l(f,a,c))},function(a){h||(h=!0,c.reject(a))})}catch(i){if(h)return;h=!0,c.reject(i)}},m=h.fulfill=h.resolve=function(a,b){if(a._state===c){a._state=d,a._value=b,a._errbacks=[];for(var e,f=a._callbacks;e=f.shift();)e(b)}},n=h.reject=function(a,b){if(a._state===c){a._state=e,a._reason=b,a._callbacks=[];for(var d,f=a._errbacks;d=f.shift();)d(b)}};h.defer=a,h.deferred=h.pending=function(){var a={};return a.promise=new h(function(b,c){a.fulfill=a.resolve=b,a.reject=c}),a},h.fulfilled=h.resolved=function(a){return new h(function(b){b(a)})},h.rejected=function(a){return new h(function(b,c){c(a)})},"undefined"==typeof Faye?module.exports=h:Faye.Promise=h}(),Faye.Set=Faye.Class({initialize:function(){this._index={}},add:function(a){var b=void 0!==a.id?a.id:a;return this._index.hasOwnProperty(b)?!1:(this._index[b]=a,!0)},forEach:function(a,b){for(var c in this._index)this._index.hasOwnProperty(c)&&a.call(b,this._index[c])},isEmpty:function(){for(var a in this._index)if(this._index.hasOwnProperty(a))return!1;return!0},member:function(a){for(var b in this._index)if(this._index[b]===a)return!0;return!1},remove:function(a){var b=void 0!==a.id?a.id:a,c=this._index[b];return delete this._index[b],c},toArray:function(){var a=[];return this.forEach(function(b){a.push(b)}),a}}),Faye.URI={isURI:function(a){return a&&a.protocol&&a.host&&a.path},isSameOrigin:function(a){var b=Faye.ENV.location;return a.protocol===b.protocol&&a.hostname===b.hostname&&a.port===b.port},parse:function(a){if("string"!=typeof a)return a;var b,c,d,e,f,g,h={},i=function(b,c){a=a.replace(c,function(a){return h[b]=a,""}),h[b]=h[b]||""};for(i("protocol",/^[a-z]+\:/i),i("host",/^\/\/[^\/\?#]+/),/^\//.test(a)||h.host||(a=Faye.ENV.location.pathname.replace(/[^\/]*$/,"")+a),i("pathname",/^[^\?#]*/),i("search",/^\?[^#]*/),i("hash",/^#.*/),h.protocol=h.protocol||Faye.ENV.location.protocol,h.host?(h.host=h.host.substr(2),b=h.host.split(":"),h.hostname=b[0],h.port=b[1]||""):(h.host=Faye.ENV.location.host,h.hostname=Faye.ENV.location.hostname,h.port=Faye.ENV.location.port),h.pathname=h.pathname||"/",h.path=h.pathname+h.search,c=h.search.replace(/^\?/,""),d=c?c.split("&"):[],g={},e=0,f=d.length;f>e;e++)b=d[e].split("="),g[decodeURIComponent(b[0]||"")]=decodeURIComponent(b[1]||"");return h.query=g,h.href=this.stringify(h),h},stringify:function(a){var b=a.protocol+"//"+a.hostname;return a.port&&(b+=":"+a.port),b+=a.pathname+this.queryString(a.query)+(a.hash||"")},queryString:function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return 0===b.length?"":"?"+b.join("&")}},Faye.Error=Faye.Class({initialize:function(a,b,c){this.code=a,this.params=Array.prototype.slice.call(b),this.message=c},toString:function(){return this.code+":"+this.params.join(",")+":"+this.message}}),Faye.Error.parse=function(a){if(a=a||"",!Faye.Grammar.ERROR.test(a))return new this(null,[],a);var b=a.split(":"),c=parseInt(b[0]),d=b[1].split(","),a=b[2];return new this(c,d,a)},Faye.Error.versionMismatch=function(){return new this(300,arguments,"Version mismatch").toString()},Faye.Error.conntypeMismatch=function(){return new this(301,arguments,"Connection types not supported").toString()},Faye.Error.extMismatch=function(){return new this(302,arguments,"Extension mismatch").toString()},Faye.Error.badRequest=function(){return new this(400,arguments,"Bad request").toString()},Faye.Error.clientUnknown=function(){return new this(401,arguments,"Unknown client").toString()},Faye.Error.parameterMissing=function(){return new this(402,arguments,"Missing required parameter").toString()},Faye.Error.channelForbidden=function(){return new this(403,arguments,"Forbidden channel").toString()},Faye.Error.channelUnknown=function(){return new this(404,arguments,"Unknown channel").toString()},Faye.Error.channelInvalid=function(){return new this(405,arguments,"Invalid channel").toString()},Faye.Error.extUnknown=function(){return new this(406,arguments,"Unknown extension").toString()},Faye.Error.publishFailed=function(){return new this(407,arguments,"Failed to publish").toString()},Faye.Error.serverError=function(){return new this(500,arguments,"Internal server error").toString()},Faye.Deferrable={then:function(a,b){var c=this;return this._promise||(this._promise=new Faye.Promise(function(a,b){c._fulfill=a,c._reject=b})),0===arguments.length?this._promise:this._promise.then(a,b)},callback:function(a,b){return this.then(function(c){a.call(b,c)})},errback:function(a,b){return this.then(null,function(c){a.call(b,c)})},timeout:function(a,b){this.then();var c=this;this._timer=Faye.ENV.setTimeout(function(){c._reject(b)},1e3*a)},setDeferredStatus:function(a,b){this._timer&&Faye.ENV.clearTimeout(this._timer);this.then();"succeeded"===a?this._fulfill(b):"failed"===a?this._reject(b):delete this._promise}},Faye.Publisher={countListeners:function(a){return this.listeners(a).length},bind:function(a,b,c){var d=Array.prototype.slice,e=function(){b.apply(c,d.call(arguments))};return this._listeners=this._listeners||[],this._listeners.push([a,b,c,e]),this.on(a,e)},unbind:function(a,b,c){this._listeners=this._listeners||[];for(var d,e=this._listeners.length;e--;)d=this._listeners[e],d[0]===a&&(!b||d[1]===b&&d[2]===c)&&(this._listeners.splice(e,1),this.removeListener(a,d[3]))}},Faye.extend(Faye.Publisher,Faye.EventEmitter.prototype),Faye.Publisher.trigger=Faye.Publisher.emit,Faye.Timeouts={addTimeout:function(a,b,c,d){if(this._timeouts=this._timeouts||{},!this._timeouts.hasOwnProperty(a)){var e=this;this._timeouts[a]=Faye.ENV.setTimeout(function(){delete e._timeouts[a],c.call(d)},1e3*b)}},removeTimeout:function(a){this._timeouts=this._timeouts||{};var b=this._timeouts[a];b&&(clearTimeout(b),delete this._timeouts[a])},removeAllTimeouts:function(){this._timeouts=this._timeouts||{};for(var a in this._timeouts)this.removeTimeout(a)}},Faye.Logging={LOG_LEVELS:{fatal:4,error:3,warn:2,info:1,debug:0},writeLog:function(a,b){if(Faye.logger){var a=Array.prototype.slice.apply(a),c="[Faye",d=this.className,e=a.shift().replace(/\?/g,function(){try{return Faye.toJSON(a.shift())}catch(b){return"[Object]"}});for(var f in Faye)d||"function"==typeof Faye[f]&&this instanceof Faye[f]&&(d=f);d&&(c+="."+d),c+="] ","function"==typeof Faye.logger[b]?Faye.logger[b](c+e):"function"==typeof Faye.logger&&Faye.logger(c+e)}}},function(){for(var a in Faye.Logging.LOG_LEVELS)(function(a){Faye.Logging[a]=function(){this.writeLog(arguments,a)}})(a,Faye.Logging.LOG_LEVELS[a])}(),Faye.Grammar={CHANNEL_NAME:/^\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+(\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+)*$/,CHANNEL_PATTERN:/^(\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+)*\/\*{1,2}$/,ERROR:/^([0-9][0-9][0-9]:(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*(,(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*)*:(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*|[0-9][0-9][0-9]::(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*)$/,VERSION:/^([0-9])+(\.(([a-z]|[A-Z])|[0-9])(((([a-z]|[A-Z])|[0-9])|\-|\_))*)*$/},Faye.Extensible={addExtension:function(a){this._extensions=this._extensions||[],this._extensions.push(a),a.added&&a.added(this)},removeExtension:function(a){if(this._extensions)for(var b=this._extensions.length;b--;)this._extensions[b]===a&&(this._extensions.splice(b,1),a.removed&&a.removed(this))},pipeThroughExtensions:function(a,b,c,d,e){if(this.debug("Passing through ? extensions: ?",a,b),!this._extensions)return d.call(e,b);var f=this._extensions.slice(),g=function(b){if(!b)return d.call(e,b);var h=f.shift();if(!h)return d.call(e,b);var i=h[a];return i?void(i.length>=3?h[a](b,c,g):h[a](b,g)):g(b)};g(b)}},Faye.extend(Faye.Extensible,Faye.Logging),Faye.Channel=Faye.Class({initialize:function(a){this.id=this.name=a},push:function(a){this.trigger("message",a)},isUnused:function(){return 0===this.countListeners("message")}}),Faye.extend(Faye.Channel.prototype,Faye.Publisher),Faye.extend(Faye.Channel,{HANDSHAKE:"/meta/handshake",CONNECT:"/meta/connect",SUBSCRIBE:"/meta/subscribe",UNSUBSCRIBE:"/meta/unsubscribe",DISCONNECT:"/meta/disconnect",META:"meta",SERVICE:"service",expand:function(a){var b=this.parse(a),c=["/**",a],d=b.slice();d[d.length-1]="*",c.push(this.unparse(d));for(var e=1,f=b.length;f>e;e++)d=b.slice(0,e),d.push("**"),c.push(this.unparse(d));return c},isValid:function(a){return Faye.Grammar.CHANNEL_NAME.test(a)||Faye.Grammar.CHANNEL_PATTERN.test(a)},parse:function(a){return this.isValid(a)?a.split("/").slice(1):null},unparse:function(a){return"/"+a.join("/")},isMeta:function(a){var b=this.parse(a);return b?b[0]===this.META:null},isService:function(a){var b=this.parse(a);return b?b[0]===this.SERVICE:null},isSubscribable:function(a){return this.isValid(a)?!this.isMeta(a)&&!this.isService(a):null},Set:Faye.Class({initialize:function(){this._channels={}},getKeys:function(){var a=[];for(var b in this._channels)a.push(b);return a},remove:function(a){delete this._channels[a]},hasSubscription:function(a){return this._channels.hasOwnProperty(a)},subscribe:function(a,b,c){if(b)for(var d,e=0,f=a.length;f>e;e++){d=a[e];var g=this._channels[d]=this._channels[d]||new Faye.Channel(d);g.bind("message",b,c)}},unsubscribe:function(a,b,c){var d=this._channels[a];return d?(d.unbind("message",b,c),d.isUnused()?(this.remove(a),!0):!1):!1},distributeMessage:function(a){for(var b=Faye.Channel.expand(a.channel),c=0,d=b.length;d>c;c++){var e=this._channels[b[c]];e&&e.trigger("message",a.data)}}})}),Faye.Envelope=Faye.Class({initialize:function(a,b){this.id=a.id,this.message=a,void 0!==b&&this.timeout(b/1e3,!1)}}),Faye.extend(Faye.Envelope.prototype,Faye.Deferrable),Faye.Publication=Faye.Class(Faye.Deferrable),Faye.Subscription=Faye.Class({initialize:function(a,b,c,d){this._client=a,this._channels=b,this._callback=c,this._context=d,this._cancelled=!1},cancel:function(){this._cancelled||(this._client.unsubscribe(this._channels,this._callback,this._context),this._cancelled=!0)},unsubscribe:function(){this.cancel()}}),Faye.extend(Faye.Subscription.prototype,Faye.Deferrable),Faye.Client=Faye.Class({UNCONNECTED:1,CONNECTING:2,CONNECTED:3,DISCONNECTED:4,HANDSHAKE:"handshake",RETRY:"retry",NONE:"none",CONNECTION_TIMEOUT:60,DEFAULT_RETRY:5,MAX_REQUEST_SIZE:2048,DEFAULT_ENDPOINT:"/bayeux",INTERVAL:0,initialize:function(a,b){this.info("New client created for ?",a),this._options=b||{},this.endpoint=Faye.URI.parse(a||this.DEFAULT_ENDPOINT),this.endpoints=this._options.endpoints||{},this.transports={},this.cookies=Faye.CookieJar&&new Faye.CookieJar,this.headers={},this.ca=this._options.ca,this._disabled=[],this._retry=this._options.retry||this.DEFAULT_RETRY;for(var c in this.endpoints)this.endpoints[c]=Faye.URI.parse(this.endpoints[c]);this.maxRequestSize=this.MAX_REQUEST_SIZE,this._state=this.UNCONNECTED,this._channels=new Faye.Channel.Set,this._messageId=0,this._responseCallbacks={},this._advice={reconnect:this.RETRY,interval:1e3*(this._options.interval||this.INTERVAL),timeout:1e3*(this._options.timeout||this.CONNECTION_TIMEOUT)},Faye.Event&&void 0!==Faye.ENV.onbeforeunload&&Faye.Event.on(Faye.ENV,"beforeunload",function(){Faye.indexOf(this._disabled,"autodisconnect")<0&&this.disconnect()},this)},disable:function(a){this._disabled.push(a)},setHeader:function(a,b){this.headers[a]=b},handshake:function(a,b){if(this._advice.reconnect!==this.NONE&&this._state===this.UNCONNECTED){this._state=this.CONNECTING;var c=this;this.info("Initiating handshake with ?",Faye.URI.stringify(this.endpoint)),this._selectTransport(Faye.MANDATORY_CONNECTION_TYPES),this._send({channel:Faye.Channel.HANDSHAKE,version:Faye.BAYEUX_VERSION,supportedConnectionTypes:[this._transport.connectionType]},function(d){d.successful?(this._state=this.CONNECTED,this._clientId=d.clientId,this._selectTransport(d.supportedConnectionTypes),this.info("Handshake successful: ?",this._clientId),this.subscribe(this._channels.getKeys(),!0),a&&Faye.Promise.defer(function(){a.call(b)})):(this.info("Handshake unsuccessful"),Faye.ENV.setTimeout(function(){c.handshake(a,b)},this._advice.interval),this._state=this.UNCONNECTED)},this)}},connect:function(a,b){if(this._advice.reconnect!==this.NONE&&this._state!==this.DISCONNECTED){if(this._state===this.UNCONNECTED)return this.handshake(function(){this.connect(a,b)},this);this.callback(a,b),this._state===this.CONNECTED&&(this.info("Calling deferred actions for ?",this._clientId),this.setDeferredStatus("succeeded"),this.setDeferredStatus("unknown"),this._connectRequest||(this._connectRequest=!0,this.info("Initiating connection for ?",this._clientId),this._send({channel:Faye.Channel.CONNECT,clientId:this._clientId,connectionType:this._transport.connectionType},this._cycleConnection,this)))}},disconnect:function(){this._state===this.CONNECTED&&(this._state=this.DISCONNECTED,this.info("Disconnecting ?",this._clientId),this._send({channel:Faye.Channel.DISCONNECT,clientId:this._clientId},function(a){a.successful&&(this._transport.close(),delete this._transport)},this),this.info("Clearing channel listeners for ?",this._clientId),this._channels=new Faye.Channel.Set)},subscribe:function(a,b,c){if(a instanceof Array)return Faye.map(a,function(a){return this.subscribe(a,b,c)},this);var d=new Faye.Subscription(this,a,b,c),e=b===!0,f=this._channels.hasSubscription(a);return f&&!e?(this._channels.subscribe([a],b,c),d.setDeferredStatus("succeeded"),d):(this.connect(function(){this.info("Client ? attempting to subscribe to ?",this._clientId,a),e||this._channels.subscribe([a],b,c),this._send({channel:Faye.Channel.SUBSCRIBE,clientId:this._clientId,subscription:a},function(e){if(!e.successful)return d.setDeferredStatus("failed",Faye.Error.parse(e.error)),this._channels.unsubscribe(a,b,c);var f=[].concat(e.subscription);this.info("Subscription acknowledged for ? to ?",this._clientId,f),d.setDeferredStatus("succeeded")},this)},this),d)},unsubscribe:function(a,b,c){if(a instanceof Array)return Faye.map(a,function(a){return this.unsubscribe(a,b,c)},this);var d=this._channels.unsubscribe(a,b,c);d&&this.connect(function(){this.info("Client ? attempting to unsubscribe from ?",this._clientId,a),this._send({channel:Faye.Channel.UNSUBSCRIBE,clientId:this._clientId,subscription:a},function(a){if(a.successful){var b=[].concat(a.subscription);this.info("Unsubscription acknowledged for ? from ?",this._clientId,b)}},this)},this)},publish:function(a,b){var c=new Faye.Publication;return this.connect(function(){this.info("Client ? queueing published message to ?: ?",this._clientId,a,b),this._send({channel:a,data:b,clientId:this._clientId},function(a){a.successful?c.setDeferredStatus("succeeded"):c.setDeferredStatus("failed",Faye.Error.parse(a.error))},this)},this),c},receiveMessage:function(a){var b,c=a.id;void 0!==a.successful&&(b=this._responseCallbacks[c],delete this._responseCallbacks[c]),this.pipeThroughExtensions("incoming",a,null,function(a){a&&(a.advice&&this._handleAdvice(a.advice),this._deliverMessage(a),b&&b[0].call(b[1],a))},this),this._transportUp!==!0&&(this._transportUp=!0,this.trigger("transport:up"))},messageError:function(a,b){for(var c,d,e=this._retry,f=this,g=0,h=a.length;h>g;g++)d=a[g],c=d.id,b?this._transportSend(d):Faye.ENV.setTimeout(function(){f._transportSend(d)},1e3*e);b||this._transportUp===!1||(this._transportUp=!1,this.trigger("transport:down"))},_selectTransport:function(a){Faye.Transport.get(this,a,this._disabled,function(a){this.debug("Selected ? transport for ?",a.connectionType,Faye.URI.stringify(a.endpoint)),a!==this._transport&&(this._transport&&this._transport.close(),this._transport=a)},this)},_send:function(a,b,c){this._transport&&(a.id=a.id||this._generateMessageId(),this.pipeThroughExtensions("outgoing",a,null,function(a){a&&(b&&(this._responseCallbacks[a.id]=[b,c]),this._transportSend(a))},this))},_transportSend:function(a){if(this._transport){var b=1.2*(this._advice.timeout||1e3*this._retry),c=new Faye.Envelope(a,b);c.errback(function(b){this.messageError([a],b)},this),this._transport.send(c)}},_generateMessageId:function(){return this._messageId+=1,this._messageId>=Math.pow(2,32)&&(this._messageId=0),this._messageId.toString(36)},_handleAdvice:function(a){Faye.extend(this._advice,a),this._advice.reconnect===this.HANDSHAKE&&this._state!==this.DISCONNECTED&&(this._state=this.UNCONNECTED,this._clientId=null,this._cycleConnection())},_deliverMessage:function(a){a.channel&&void 0!==a.data&&(this.info("Client ? calling listeners for ? with ?",this._clientId,a.channel,a.data),this._channels.distributeMessage(a))},_cycleConnection:function(){this._connectRequest&&(this._connectRequest=null,this.info("Closed connection for ?",this._clientId));var a=this;Faye.ENV.setTimeout(function(){a.connect()},this._advice.interval)}}),Faye.extend(Faye.Client.prototype,Faye.Deferrable),Faye.extend(Faye.Client.prototype,Faye.Publisher),Faye.extend(Faye.Client.prototype,Faye.Logging),Faye.extend(Faye.Client.prototype,Faye.Extensible),Faye.Transport=Faye.extend(Faye.Class({MAX_DELAY:0,batching:!0,initialize:function(a,b){this._client=a,this.endpoint=b,this._outbox=[]},close:function(){},encode:function(){return""},send:function(a){var b=a.message;return this.debug("Client ? sending message to ?: ?",this._client._clientId,Faye.URI.stringify(this.endpoint),b),this.batching?(this._outbox.push(a),b.channel===Faye.Channel.HANDSHAKE?this.addTimeout("publish",.01,this.flush,this):(b.channel===Faye.Channel.CONNECT&&(this._connectMessage=b),this.flushLargeBatch(),void this.addTimeout("publish",this.MAX_DELAY,this.flush,this))):this.request([a])},flush:function(){this.removeTimeout("publish"),this._outbox.length>1&&this._connectMessage&&(this._connectMessage.advice={timeout:0}),this.request(this._outbox),this._connectMessage=null,this._outbox=[]},flushLargeBatch:function(){var a=this.encode(this._outbox);if(!(a.length<this._client.maxRequestSize)){var b=this._outbox.pop();this.flush(),b&&this._outbox.push(b)}},receive:function(a,b){for(var c=a.length;c--;)a[c].setDeferredStatus("succeeded");b=[].concat(b),this.debug("Client ? received from ?: ?",this._client._clientId,Faye.URI.stringify(this.endpoint),b);for(var d=0,c=b.length;c>d;d++)this._client.receiveMessage(b[d])},handleError:function(a,b){for(var c=a.length;c--;)a[c].setDeferredStatus("failed",b)},_getCookies:function(){var a=this._client.cookies;return a?a.getCookies({domain:this.endpoint.hostname,path:this.endpoint.path,secure:"https:"===this.endpoint.protocol}).toValueString():""},_storeCookies:function(a){if(a&&this._client.cookies){a=[].concat(a);for(var b,c=0,d=a.length;d>c;c++)b=this._client.cookies.setCookie(a[c]),b=b[0]||b,b.domain=b.domain||this.endpoint.hostname}}}),{get:function(a,b,c,d,e){var f=a.endpoint;Faye.asyncEach(this._transports,function(g,h){var i=g[0],j=g[1],k=a.endpoints[i]||f;return Faye.indexOf(c,i)>=0?h():Faye.indexOf(b,i)<0?(j.isUsable(a,k,function(){}),h()):void j.isUsable(a,k,function(b){if(!b)return h();var c=j.hasOwnProperty("create")?j.create(a,k):new j(a,k);d.call(e,c)})},function(){throw new Error("Could not find a usable connection type for "+Faye.URI.stringify(f))})},register:function(a,b){this._transports.push([a,b]),b.prototype.connectionType=a},_transports:[]}),Faye.extend(Faye.Transport.prototype,Faye.Logging),Faye.extend(Faye.Transport.prototype,Faye.Timeouts),Faye.Event={_registry:[],on:function(a,b,c,d){var e=function(){c.call(d)};a.addEventListener?a.addEventListener(b,e,!1):a.attachEvent("on"+b,e),this._registry.push({_element:a,_type:b,_callback:c,_context:d,_handler:e})},detach:function(a,b,c,d){for(var e,f=this._registry.length;f--;)e=this._registry[f],a&&a!==e._element||b&&b!==e._type||c&&c!==e._callback||d&&d!==e._context||(e._element.removeEventListener?e._element.removeEventListener(e._type,e._handler,!1):e._element.detachEvent("on"+e._type,e._handler),this._registry.splice(f,1),e=null)}},void 0!==Faye.ENV.onunload&&Faye.Event.on(Faye.ENV,"unload",Faye.Event.detach,Faye.Event),"object"!=typeof JSON&&(JSON={}),function(){function f(a){return 10>a?"0"+a:a}function quote(a){return escapable.lastIndex=0,escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return"string"==typeof b?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function str(a,b){var c,d,e,f,g,h=gap,i=b[a];switch(i&&"object"==typeof i&&"function"==typeof i.toJSON&&(i=i.toJSON(a)),"function"==typeof rep&&(i=rep.call(b,a,i)),typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";if(gap+=indent,g=[],"[object Array]"===Object.prototype.toString.apply(i)){for(f=i.length,c=0;f>c;c+=1)g[c]=str(c,i)||"null";return e=0===g.length?"[]":gap?"[\n"+gap+g.join(",\n"+gap)+"\n"+h+"]":"["+g.join(",")+"]",gap=h,e}if(rep&&"object"==typeof rep)for(f=rep.length,c=0;f>c;c+=1)"string"==typeof rep[c]&&(d=rep[c],e=str(d,i),e&&g.push(quote(d)+(gap?": ":":")+e));else for(d in i)Object.prototype.hasOwnProperty.call(i,d)&&(e=str(d,i),e&&g.push(quote(d)+(gap?": ":":")+e));return e=0===g.length?"{}":gap?"{\n"+gap+g.join(",\n"+gap)+"\n"+h+"}":"{"+g.join(",")+"}",gap=h,e}}"function"!=typeof Date.prototype.toJSON&&(Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()});var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;Faye.stringify=function(a,b,c){var d;if(gap="",indent="","number"==typeof c)for(d=0;c>d;d+=1)indent+=" ";else"string"==typeof c&&(indent=c);if(rep=b,b&&"function"!=typeof b&&("object"!=typeof b||"number"!=typeof b.length))throw new Error("JSON.stringify");return str("",{"":a})},"function"!=typeof JSON.stringify&&(JSON.stringify=Faye.stringify),"function"!=typeof JSON.parse&&(JSON.parse=function(text,reviver){function walk(a,b){var c,d,e=a[b];if(e&&"object"==typeof e)for(c in e)Object.prototype.hasOwnProperty.call(e,c)&&(d=walk(e,c),void 0!==d?e[c]=d:delete e[c]);return reviver.call(a,b,e)}var j;if(text=String(text),cx.lastIndex=0,cx.test(text)&&(text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})),/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return j=eval("("+text+")"),"function"==typeof reviver?walk({"":j},""):j;throw new SyntaxError("JSON.parse")})}(),Faye.Transport.WebSocket=Faye.extend(Faye.Class(Faye.Transport,{UNCONNECTED:1,CONNECTING:2,CONNECTED:3,batching:!1,isUsable:function(a,b){this.callback(function(){a.call(b,!0)}),this.errback(function(){a.call(b,!1)}),this.connect()},request:function(a){this._pending=this._pending||new Faye.Set;for(var b=0,c=a.length;c>b;b++)this._pending.add(a[b]);this.callback(function(b){if(b){var c=Faye.map(a,function(a){return a.message});b.send(Faye.toJSON(c))}},this),this.connect()},connect:function(){if(!Faye.Transport.WebSocket._unloaded&&(this._state=this._state||this.UNCONNECTED,this._state===this.UNCONNECTED)){this._state=this.CONNECTING;
var a=this._createSocket();if(!a)return this.setDeferredStatus("failed");var b=this;a.onopen=function(){a.headers&&b._storeCookies(a.headers["set-cookie"]),b._socket=a,b._state=b.CONNECTED,b._everConnected=!0,b._ping(),b.setDeferredStatus("succeeded",a)};var c=!1;a.onclose=a.onerror=function(){if(!c){c=!0;var d=b._state===b.CONNECTED;a.onopen=a.onclose=a.onerror=a.onmessage=null,delete b._socket,b._state=b.UNCONNECTED,b.removeTimeout("ping"),b.setDeferredStatus("unknown");var e=b._pending?b._pending.toArray():[];delete b._pending,d?b.handleError(e,!0):b._everConnected?b.handleError(e):b.setDeferredStatus("failed")}},a.onmessage=function(a){var c,d=JSON.parse(a.data),e=[];if(d){d=[].concat(d);for(var f=0,g=d.length;g>f;f++)void 0!==d[f].successful&&(c=b._pending.remove(d[f]),c&&e.push(c));b.receive(e,d)}}}},close:function(){this._socket&&this._socket.close()},_createSocket:function(){var a=Faye.Transport.WebSocket.getSocketUrl(this.endpoint),b={headers:Faye.copyObject(this._client.headers),ca:this._client.ca};return b.headers.Cookie=this._getCookies(),Faye.WebSocket?new Faye.WebSocket.Client(a,[],b):Faye.ENV.MozWebSocket?new MozWebSocket(a):Faye.ENV.WebSocket?new WebSocket(a):void 0},_ping:function(){this._socket&&(this._socket.send("[]"),this.addTimeout("ping",this._client._advice.timeout/2e3,this._ping,this))}}),{PROTOCOLS:{"http:":"ws:","https:":"wss:"},create:function(a,b){var c=a.transports.websocket=a.transports.websocket||{};return c[b.href]=c[b.href]||new this(a,b),c[b.href]},getSocketUrl:function(a){return a=Faye.copyObject(a),a.protocol=this.PROTOCOLS[a.protocol],Faye.URI.stringify(a)},isUsable:function(a,b,c,d){this.create(a,b).isUsable(c,d)}}),Faye.extend(Faye.Transport.WebSocket.prototype,Faye.Deferrable),Faye.Transport.register("websocket",Faye.Transport.WebSocket),Faye.Event&&Faye.Event.on(Faye.ENV,"beforeunload",function(){Faye.Transport.WebSocket._unloaded=!0}),Faye.Transport.EventSource=Faye.extend(Faye.Class(Faye.Transport,{initialize:function(a,b){if(Faye.Transport.prototype.initialize.call(this,a,b),!Faye.ENV.EventSource)return this.setDeferredStatus("failed");this._xhr=new Faye.Transport.XHR(a,b),b=Faye.copyObject(b),b.pathname+="/"+a._clientId;var c=new EventSource(Faye.URI.stringify(b)),d=this;c.onopen=function(){d._everConnected=!0,d.setDeferredStatus("succeeded")},c.onerror=function(){d._everConnected?d._client.messageError([]):(d.setDeferredStatus("failed"),c.close())},c.onmessage=function(a){d.receive([],JSON.parse(a.data))},this._socket=c},close:function(){this._socket&&(this._socket.onopen=this._socket.onerror=this._socket.onmessage=null,this._socket.close(),delete this._socket)},isUsable:function(a,b){this.callback(function(){a.call(b,!0)}),this.errback(function(){a.call(b,!1)})},encode:function(a){return this._xhr.encode(a)},request:function(a){this._xhr.request(a)}}),{isUsable:function(a,b,c,d){var e=a._clientId;return e?void Faye.Transport.XHR.isUsable(a,b,function(e){return e?void this.create(a,b).isUsable(c,d):c.call(d,!1)},this):c.call(d,!1)},create:function(a,b){var c=a.transports.eventsource=a.transports.eventsource||{},d=a._clientId;b=Faye.copyObject(b),b.pathname+="/"+(d||"");var e=Faye.URI.stringify(b);return c[e]=c[e]||new this(a,b),c[e]}}),Faye.extend(Faye.Transport.EventSource.prototype,Faye.Deferrable),Faye.Transport.register("eventsource",Faye.Transport.EventSource),Faye.Transport.XHR=Faye.extend(Faye.Class(Faye.Transport,{encode:function(a){var b=Faye.map(a,function(a){return a.message});return Faye.toJSON(b)},request:function(a){var b=this.endpoint.path,c=Faye.ENV.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest,d=this;c.open("POST",b,!0),c.setRequestHeader("Content-Type","application/json"),c.setRequestHeader("Pragma","no-cache"),c.setRequestHeader("X-Requested-With","XMLHttpRequest");var e=this._client.headers;for(var f in e)e.hasOwnProperty(f)&&c.setRequestHeader(f,e[f]);var g=function(){c.abort()};Faye.Event.on(Faye.ENV,"beforeunload",g),c.onreadystatechange=function(){if(c&&4===c.readyState){var b=null,e=c.status,f=c.responseText,h=e>=200&&300>e||304===e||1223===e;if(Faye.Event.detach(Faye.ENV,"beforeunload",g),c.onreadystatechange=function(){},c=null,!h)return d.handleError(a);try{b=JSON.parse(f)}catch(i){}b?d.receive(a,b):d.handleError(a)}},c.send(this.encode(a))}}),{isUsable:function(a,b,c,d){c.call(d,Faye.URI.isSameOrigin(b))}}),Faye.Transport.register("long-polling",Faye.Transport.XHR),Faye.Transport.CORS=Faye.extend(Faye.Class(Faye.Transport,{encode:function(a){var b=Faye.map(a,function(a){return a.message});return"message="+encodeURIComponent(Faye.toJSON(b))},request:function(a){var b,c=Faye.ENV.XDomainRequest?XDomainRequest:XMLHttpRequest,d=new c,e=this._client.headers,f=this;if(d.open("POST",Faye.URI.stringify(this.endpoint),!0),d.setRequestHeader){d.setRequestHeader("Pragma","no-cache");for(b in e)e.hasOwnProperty(b)&&d.setRequestHeader(b,e[b])}var g=function(){return d?(d.onload=d.onerror=d.ontimeout=d.onprogress=null,void(d=null)):!1};d.onload=function(){var b=null;try{b=JSON.parse(d.responseText)}catch(c){}g(),b?f.receive(a,b):f.handleError(a)},d.onerror=d.ontimeout=function(){g(),f.handleError(a)},d.onprogress=function(){},d.send(this.encode(a))}}),{isUsable:function(a,b,c,d){if(Faye.URI.isSameOrigin(b))return c.call(d,!1);if(Faye.ENV.XDomainRequest)return c.call(d,b.protocol===Faye.ENV.location.protocol);if(Faye.ENV.XMLHttpRequest){var e=new Faye.ENV.XMLHttpRequest;return c.call(d,void 0!==e.withCredentials)}return c.call(d,!1)}}),Faye.Transport.register("cross-origin-long-polling",Faye.Transport.CORS),Faye.Transport.JSONP=Faye.extend(Faye.Class(Faye.Transport,{encode:function(a){var b=Faye.map(a,function(a){return a.message}),c=Faye.copyObject(this.endpoint);return c.query.message=Faye.toJSON(b),c.query.jsonp="__jsonp"+Faye.Transport.JSONP._cbCount+"__",Faye.URI.stringify(c)},request:function(a){var b=Faye.map(a,function(a){return a.message}),c=document.getElementsByTagName("head")[0],d=document.createElement("script"),e=Faye.Transport.JSONP.getCallbackName(),f=Faye.copyObject(this.endpoint),g=this;f.query.message=Faye.toJSON(b),f.query.jsonp=e,Faye.ENV[e]=function(b){if(!Faye.ENV[e])return!1;Faye.ENV[e]=void 0;try{delete Faye.ENV[e]}catch(c){}d.parentNode.removeChild(d),g.receive(a,b)},d.type="text/javascript",d.src=Faye.URI.stringify(f),c.appendChild(d)}}),{_cbCount:0,getCallbackName:function(){return this._cbCount+=1,"__jsonp"+this._cbCount+"__"},isUsable:function(a,b,c,d){c.call(d,!0)}}),Faye.Transport.register("callback-polling",Faye.Transport.JSONP)}()}).call(this,require("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{_process:2}]},{},[1])(1)});
//# sourceMappingURL=jsforce-api-streaming.min.js.map