UNPKG

jsforce

Version:

Salesforce API Library for JavaScript

3 lines (2 loc) 3.41 kB
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e=e.jsforce||(e.jsforce={}),e=e.modules||(e.modules={}),e=e.api||(e.api={}),e.Chatter=t()}}(function(){return function(){function t(e,r,n){function o(s,u){if(!r[s]){if(!e[s]){var a="function"==typeof require&&require;if(!u&&a)return a(s,!0);if(i)return i(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var h=r[s]={exports:{}};e[s][0].call(h.exports,function(t){var r=e[s][1][t];return o(r||t)},h,h.exports,t,e,r,n)}return r[s].exports}for(var i="function"==typeof require&&require,s=0;s<n.length;s++)o(n[s]);return o}return t}()({1:[function(t,e,r){"use strict";var n=window.jsforce.require("inherits"),o=window.jsforce.require("lodash/core"),i=window.jsforce.require("./core"),s=window.jsforce.require("./promise"),u=e.exports=function(t){this._conn=t};u.prototype._request=function(t,e){return/^(put|post|patch)$/i.test(t.method)&&o.isObject(t.body)&&(t.headers={"Content-Type":"application/json"},t.body=JSON.stringify(t.body)),t.url=this._normalizeUrl(t.url),this._conn.request(t,e)},u.prototype._normalizeUrl=function(t){return 0===t.indexOf("/chatter/")||0===t.indexOf("/connect/")?"/services/data/v"+this._conn.version+t:/^\/v[\d]+\.[\d]+\//.test(t)?"/services/data"+t:0!==t.indexOf("/services/")&&"/"===t[0]?"/services/data/v"+this._conn.version+"/chatter"+t:t},u.prototype.request=function(t,e){return new a(this,t).thenCall(e)},u.prototype.resource=function(t,e){return new c(this,t,e)},u.prototype.batch=function(t,e){var r=[],n=[];o.forEach(t,function(t){var e=s.defer();t._promise=e.promise,r.push(t.batchParams()),n.push(e)});var i={method:"POST",url:this._normalizeUrl("/connect/batch"),body:{batchRequests:r}};return this.request(i).then(function(t){return o.forEach(t.results,function(t,e){var r=n[e];t.statusCode>=400?r.reject(t.result):r.resolve(t.result)}),t}).thenCall(e)};var a=function(t,e){this._chatter=t,this._params=e,this._promise=null};a.prototype.batchParams=function(){var t=this._params,e={method:t.method,url:this._chatter._normalizeUrl(t.url)};return this._params.body&&(e.richInput=this._params.body),e},a.prototype.promise=function(){return this._promise||this._chatter._request(this._params)},a.prototype.stream=function(){return this._chatter._request(this._params).stream()},a.prototype.then=function(t,e){return this.promise().then(t,e)},a.prototype.thenCall=function(t){return o.isFunction(t)?this.promise().thenCall(t):this};var c=function(t,e,r){if(r){var n=o.map(o.keys(r),function(t){return t+"="+encodeURIComponent(r[t])}).join("&");e+=(e.indexOf("?")>0?"&":"?")+n}c.super_.call(this,t,{method:"GET",url:e}),this._url=e};n(c,a),c.prototype.create=function(t,e){return this._chatter.request({method:"POST",url:this._url,body:t}).thenCall(e)},c.prototype.retrieve=function(t){return this.thenCall(t)},c.prototype.update=function(t,e){return this._chatter.request({method:"POST",url:this._url,body:t}).thenCall(e)},c.prototype.del=c.prototype["delete"]=function(t){return this._chatter.request({method:"DELETE",url:this._url}).thenCall(t)},i.on("connection:new",function(t){t.chatter=new u(t)})},{}]},{},[1])(1)}); //# sourceMappingURL=jsforce-api-chatter.min.js.map