UNPKG

sf-composite-call

Version:

Support for making Salesforce composite call requests with integration for JSforce.

1 lines 16.9 kB
(()=>{"use strict";var e={492:function(e,t,r){var i=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),s=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||i(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),s(r(990),t)},990:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CompositeCall=void 0;const i=r(500),s=r(236),n=r(845),o=r(973);t.CompositeCall=class{constructor(e){this.version=this.versionRX.test(e.version)?e.version:"v48.0",this.calls=[],this.options={allOrNone:e.allOrNone,collateSubrequests:e.collateSubrequests},this.connection=e.jsforceConnection,this.limits={query:5,total:25,queryCount:0,totalCount:0}}get versionRX(){return/v\d\d\.\d/gu}get url(){return`/services/data/${this.version}/composite`}get request(){const e=this.calls.map((e=>e.subrequest));return Object.assign({compositeRequest:e},this.options)}get queryLimitMet(){return this.limits.queryCount===this.limits.query}get totalLimitMet(){return this.limits.totalCount===this.limits.total}addQuery(e,t,r){if(this.queryLimitMet)throw new Error("Query limit met. No more queries may be added.");if(this.totalLimitMet)throw new Error("Total request limit met. No more requests may be added.");r=i.isNullOrUndefined(r)?this.version:r;const n=new s.CompositeSubrequestQuery(e,t,r);return this.calls.push(n),this.limits.queryCount+=1,this.limits.totalCount+=1,n}addSObject(e,t,r){if(this.totalLimitMet)throw new Error("Total request limit met. No more requests may be added.");r=i.isNullOrUndefined(r)?this.version:r;const s=new n.CompositeSubrequestSObject(e,t,r);return this.calls.push(s),this.limits.totalCount+=1,s}addSObjectCollection(e,t){if(this.totalLimitMet)throw new Error("Total request limit met. No more requests may be added.");t=i.isNullOrUndefined(t)?this.version:t;const r=new o.CompositeSubrequestSObjectCollection(e,t);return this.calls.push(r),this.limits.totalCount+=1,r}clear(){this.calls=[],this.limits.queryCount=0,this.limits.totalCount=0}async execute(e){return i.isNullOrUndefined(e)?i.isNullOrUndefined(this.connection)?void console.warn("No JSForce Connection object provided. Request cannot be executed."):await this.connection.requestPost(this.url,this.request):await e.requestPost(this.url,this.request)}}},402:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CompositeSubrequest=void 0;const i=r(614),s=r(500);t.CompositeSubrequest=class{constructor(e,t){this.version=this.versionRX.test(t)?t:"v48.0",this.referenceId=s.isNullOrUndefined(e)?i.v4().replace(/-/gu,""):e}get versionRX(){return/v\d\d\.\d/gu}get subrequest(){return s.isNullOrUndefined(this.obj)?this.makeRequest():this.obj}url(){return`/services/data/${this.version}`}makeRequest(e,t,r,i){return{method:e=s.isNullOrUndefined(e)?"GET":e,url:t=s.isNullOrUndefined(t)?this.url():t,body:r,httpHeaders:i,referenceId:this.referenceId}}}},236:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CompositeSubrequestQuery=void 0;const i=r(500),s=r(402);class n extends s.CompositeSubrequest{constructor(e,t,r){super(t,r),this.soql=e,this.verb="query"}url(){return super.url()+`/${this.verb}`}get subrequest(){return i.isNullOrUndefined(this.obj)?this.get():this.obj}get(e,t){const r=this.soql.replace(/\s/gu,"+");return this.obj=this.makeRequest(null,i.isNullOrUndefined(e)?this.url()+`?q=${r}`:"explain"===e.trim().toLowerCase()?this.url()+`?explain=${r}`:e,void 0,t),this.obj}explain(e){return this.verb="query",this.get("explain",e)}explainAll(e){return this.verb="queryAll",this.get("explain",e)}nextRecords(e,t){return this.verb="query",this.get(e,t)}nextRecordsAll(e,t){return this.verb="queryAll",this.get(e,t)}query(e){return this.verb="query",this.get(null,e)}queryAll(e){return this.verb="queryAll",this.get(null,e)}}t.CompositeSubrequestQuery=n},845:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CompositeSubrequestSObject=void 0;const i=r(500),s=r(402);class n extends s.CompositeSubrequest{constructor(e,t,r){super(t,r),this.sobject=e}url(){return super.url()+`/sobjects/${this.sobject}`}delete(e,t,r){return this.obj=this.makeRequest("DELETE",i.isNullOrUndefined(t)?this.url():this.url()+"/"+t,e,r),this.obj}destroy(e,t){return this.delete(void 0,e,t)}get(e,t,r){return this.obj=this.makeRequest(null,i.isNullOrUndefined(t)?this.url():this.url()+"/"+t,e,r),this.obj}describe(e){return this.get(void 0,"describe",e)}retrieve(e,t){return this.get(void 0,e,t)}patch(e,t,r){return this.obj=this.makeRequest("PATCH",i.isNullOrUndefined(t)?this.url():this.url()+"/"+t,e,r),this.obj}update(e,t,r){i.isNullOrUndefined(t)&&(t="Id"),"object"!=typeof t||i.isNullOrUndefined(r)||(r=t,t="Id"),e=Object.assign({},e);const s=("Id"===t?"":t+"/")+encodeURIComponent(e[t]);return delete e.Id,delete e[t],this.patch(e,s,r)}post(e,t,r){return this.obj=this.makeRequest("POST",i.isNullOrUndefined(t)?this.url():this.url()+"/"+t,e,r),this.obj}create(e,t){return this.post(e,null,t)}insert(e,t){return this.create(e,t)}put(e,t,r){return this.obj=this.makeRequest("PUT",i.isNullOrUndefined(t)?this.url():`${this.url()}/${t}`,e,r),this.obj}}t.CompositeSubrequestSObject=n},973:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CompositeSubrequestSObjectCollection=void 0;const i=r(500),s=r(402);class n extends s.CompositeSubrequest{url(){return super.url()+"/composite/sobjects"}delete(e,t=!1,r){if(e.length>200)throw new Error(`Too many IDs specified for SObject Collection DELETE request; limit is 200, ${e.length} were provided.`);return this.obj=this.makeRequest("DELETE",this.url()+`?ids=${e.join(",")}&allOrNone=${t?"true":"false"}`,void 0,r),this.obj}destroy(e,t,r){const i=Array.isArray(e)?e:[e];return this.delete(i,t,r)}get(e,t,r,i){if(t.length>800)throw new Error(`Too many IDs specified for SObject Collection GET request; limit is 800, ${t.length} were provided.`);return this.obj=this.makeRequest(null,this.url()+`/${e}?ids=${t.join(",")}&fields=${r.join(",")}`,void 0,i),this.obj}patch(e,t,r,s){if(e.length>200)throw new Error(`Too many records specified for PATCH request; limit is 200, ${e.length} were provided.`);const n=e.map((e=>i.isNullOrUndefined(e.attributes)?"":e.attributes.type)).filter((e=>""!==e)).length===e.length;let o="";if(e=e.map((e=>Object.assign({},e))),i.isNullOrUndefined(t)){if(!n)throw new Error("No SObject type provided for PATCH request.")}else if("string"==typeof t)e.forEach((e=>{i.isNullOrUndefined(e.attributes)&&(e.attributes={}),i.isNullOrUndefined(e.attributes.type)&&(e.attributes.type=t)}));else{const{externalId:r,sobject:s}=t;let u="";if(i.isNullOrUndefined(s)){if(!n)throw new Error("No SObject type provided for PATCH request.");{const{attributes:t={}}=e[0],{type:r=""}=t;u=r}}else u=s,e.forEach((e=>{i.isNullOrUndefined(e.attributes)&&(e.attributes={}),i.isNullOrUndefined(e.attributes.type)&&(e.attributes.type=s)}));if(i.isNullOrUndefined(r))throw new Error("No externalId provided for PATCH request.");o=u+"/"+r}const u={allOrNone:r,records:e};return this.obj=this.makeRequest("PATCH",""===o?this.url():this.url()+"/"+o,u,s),this.obj}update(e,t,r,i){const s=Array.isArray(e)?e:[e];return this.patch(s,t,r,i)}post(e,t,r){return this.obj=this.makeRequest("POST",i.isNullOrUndefined(t)?this.url():`${this.url()}/${t}`,e,r),this.obj}retrieve(e,t,r,i){const s=Array.isArray(t)?t:[t],n={ids:s,fields:Array.isArray(r)?r:[r]};if(s.length>2e3)throw new Error(`Too many IDs specified for SObject Collection retrieve request; limit is 2000, ${t.length} were provided.`);return this.post(n,e,i)}create(e,t,r,s){let n=Array.isArray(e)?e:[e];if(n.length>200)throw new Error(`Too many records specified for create request; limit is 200, ${n.length} were provided.`);if(n=n.map((e=>Object.assign({},e))),i.isNullOrUndefined(t)){if(n.map((e=>i.isNullOrUndefined(e.attributes)?"":e.attributes.type)).filter((e=>""!==e)).length!==n.length)throw new Error("No SObject type provided for create request.")}else n.forEach((e=>{i.isNullOrUndefined(e.attributes)&&(e.attributes={}),i.isNullOrUndefined(e.attributes.type)&&(e.attributes.type=t)}));const o={allOrNone:r,records:n};return this.post(o,null,s)}insert(e,t,r,i){return this.create(e,t,r,i)}}t.CompositeSubrequestSObjectCollection=n},500:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.isNullOrUndefined=void 0,t.isNullOrUndefined=function(e){return null==e}},614:(e,t,r)=>{var i;r.r(t),r.d(t,{NIL:()=>R,parse:()=>v,stringify:()=>d,v1:()=>b,v3:()=>U,v4:()=>N,v5:()=>E,validate:()=>u,version:()=>I});var s=new Uint8Array(16);function n(){if(!i&&!(i="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return i(s)}const o=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i,u=function(e){return"string"==typeof e&&o.test(e)};for(var l=[],a=0;a<256;++a)l.push((a+256).toString(16).substr(1));const d=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(l[e[t+0]]+l[e[t+1]]+l[e[t+2]]+l[e[t+3]]+"-"+l[e[t+4]]+l[e[t+5]]+"-"+l[e[t+6]]+l[e[t+7]]+"-"+l[e[t+8]]+l[e[t+9]]+"-"+l[e[t+10]]+l[e[t+11]]+l[e[t+12]]+l[e[t+13]]+l[e[t+14]]+l[e[t+15]]).toLowerCase();if(!u(r))throw TypeError("Stringified UUID is invalid");return r};var c,h,f=0,p=0;const b=function(e,t,r){var i=t&&r||0,s=t||new Array(16),o=(e=e||{}).node||c,u=void 0!==e.clockseq?e.clockseq:h;if(null==o||null==u){var l=e.random||(e.rng||n)();null==o&&(o=c=[1|l[0],l[1],l[2],l[3],l[4],l[5]]),null==u&&(u=h=16383&(l[6]<<8|l[7]))}var a=void 0!==e.msecs?e.msecs:Date.now(),b=void 0!==e.nsecs?e.nsecs:p+1,v=a-f+(b-p)/1e4;if(v<0&&void 0===e.clockseq&&(u=u+1&16383),(v<0||a>f)&&void 0===e.nsecs&&(b=0),b>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");f=a,p=b,h=u;var y=(1e4*(268435455&(a+=122192928e5))+b)%4294967296;s[i++]=y>>>24&255,s[i++]=y>>>16&255,s[i++]=y>>>8&255,s[i++]=255&y;var m=a/4294967296*1e4&268435455;s[i++]=m>>>8&255,s[i++]=255&m,s[i++]=m>>>24&15|16,s[i++]=m>>>16&255,s[i++]=u>>>8|128,s[i++]=255&u;for(var g=0;g<6;++g)s[i+g]=o[g];return t||d(s)},v=function(e){if(!u(e))throw TypeError("Invalid UUID");var t,r=new Uint8Array(16);return r[0]=(t=parseInt(e.slice(0,8),16))>>>24,r[1]=t>>>16&255,r[2]=t>>>8&255,r[3]=255&t,r[4]=(t=parseInt(e.slice(9,13),16))>>>8,r[5]=255&t,r[6]=(t=parseInt(e.slice(14,18),16))>>>8,r[7]=255&t,r[8]=(t=parseInt(e.slice(19,23),16))>>>8,r[9]=255&t,r[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,r[11]=t/4294967296&255,r[12]=t>>>24&255,r[13]=t>>>16&255,r[14]=t>>>8&255,r[15]=255&t,r};function y(e,t,r){function i(e,i,s,n){if("string"==typeof e&&(e=function(e){e=unescape(encodeURIComponent(e));for(var t=[],r=0;r<e.length;++r)t.push(e.charCodeAt(r));return t}(e)),"string"==typeof i&&(i=v(i)),16!==i.length)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");var o=new Uint8Array(16+e.length);if(o.set(i),o.set(e,i.length),(o=r(o))[6]=15&o[6]|t,o[8]=63&o[8]|128,s){n=n||0;for(var u=0;u<16;++u)s[n+u]=o[u];return s}return d(o)}try{i.name=e}catch(e){}return i.DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",i.URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8",i}function m(e){return 14+(e+64>>>9<<4)+1}function g(e,t){var r=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(r>>16)<<16|65535&r}function q(e,t,r,i,s,n){return g((o=g(g(t,e),g(i,n)))<<(u=s)|o>>>32-u,r);var o,u}function O(e,t,r,i,s,n,o){return q(t&r|~t&i,e,t,s,n,o)}function j(e,t,r,i,s,n,o){return q(t&i|r&~i,e,t,s,n,o)}function w(e,t,r,i,s,n,o){return q(t^r^i,e,t,s,n,o)}function C(e,t,r,i,s,n,o){return q(r^(t|~i),e,t,s,n,o)}const U=y("v3",48,(function(e){if("string"==typeof e){var t=unescape(encodeURIComponent(e));e=new Uint8Array(t.length);for(var r=0;r<t.length;++r)e[r]=t.charCodeAt(r)}return function(e){for(var t=[],r=32*e.length,i="0123456789abcdef",s=0;s<r;s+=8){var n=e[s>>5]>>>s%32&255,o=parseInt(i.charAt(n>>>4&15)+i.charAt(15&n),16);t.push(o)}return t}(function(e,t){e[t>>5]|=128<<t%32,e[m(t)-1]=t;for(var r=1732584193,i=-271733879,s=-1732584194,n=271733878,o=0;o<e.length;o+=16){var u=r,l=i,a=s,d=n;r=O(r,i,s,n,e[o],7,-680876936),n=O(n,r,i,s,e[o+1],12,-389564586),s=O(s,n,r,i,e[o+2],17,606105819),i=O(i,s,n,r,e[o+3],22,-1044525330),r=O(r,i,s,n,e[o+4],7,-176418897),n=O(n,r,i,s,e[o+5],12,1200080426),s=O(s,n,r,i,e[o+6],17,-1473231341),i=O(i,s,n,r,e[o+7],22,-45705983),r=O(r,i,s,n,e[o+8],7,1770035416),n=O(n,r,i,s,e[o+9],12,-1958414417),s=O(s,n,r,i,e[o+10],17,-42063),i=O(i,s,n,r,e[o+11],22,-1990404162),r=O(r,i,s,n,e[o+12],7,1804603682),n=O(n,r,i,s,e[o+13],12,-40341101),s=O(s,n,r,i,e[o+14],17,-1502002290),r=j(r,i=O(i,s,n,r,e[o+15],22,1236535329),s,n,e[o+1],5,-165796510),n=j(n,r,i,s,e[o+6],9,-1069501632),s=j(s,n,r,i,e[o+11],14,643717713),i=j(i,s,n,r,e[o],20,-373897302),r=j(r,i,s,n,e[o+5],5,-701558691),n=j(n,r,i,s,e[o+10],9,38016083),s=j(s,n,r,i,e[o+15],14,-660478335),i=j(i,s,n,r,e[o+4],20,-405537848),r=j(r,i,s,n,e[o+9],5,568446438),n=j(n,r,i,s,e[o+14],9,-1019803690),s=j(s,n,r,i,e[o+3],14,-187363961),i=j(i,s,n,r,e[o+8],20,1163531501),r=j(r,i,s,n,e[o+13],5,-1444681467),n=j(n,r,i,s,e[o+2],9,-51403784),s=j(s,n,r,i,e[o+7],14,1735328473),r=w(r,i=j(i,s,n,r,e[o+12],20,-1926607734),s,n,e[o+5],4,-378558),n=w(n,r,i,s,e[o+8],11,-2022574463),s=w(s,n,r,i,e[o+11],16,1839030562),i=w(i,s,n,r,e[o+14],23,-35309556),r=w(r,i,s,n,e[o+1],4,-1530992060),n=w(n,r,i,s,e[o+4],11,1272893353),s=w(s,n,r,i,e[o+7],16,-155497632),i=w(i,s,n,r,e[o+10],23,-1094730640),r=w(r,i,s,n,e[o+13],4,681279174),n=w(n,r,i,s,e[o],11,-358537222),s=w(s,n,r,i,e[o+3],16,-722521979),i=w(i,s,n,r,e[o+6],23,76029189),r=w(r,i,s,n,e[o+9],4,-640364487),n=w(n,r,i,s,e[o+12],11,-421815835),s=w(s,n,r,i,e[o+15],16,530742520),r=C(r,i=w(i,s,n,r,e[o+2],23,-995338651),s,n,e[o],6,-198630844),n=C(n,r,i,s,e[o+7],10,1126891415),s=C(s,n,r,i,e[o+14],15,-1416354905),i=C(i,s,n,r,e[o+5],21,-57434055),r=C(r,i,s,n,e[o+12],6,1700485571),n=C(n,r,i,s,e[o+3],10,-1894986606),s=C(s,n,r,i,e[o+10],15,-1051523),i=C(i,s,n,r,e[o+1],21,-2054922799),r=C(r,i,s,n,e[o+8],6,1873313359),n=C(n,r,i,s,e[o+15],10,-30611744),s=C(s,n,r,i,e[o+6],15,-1560198380),i=C(i,s,n,r,e[o+13],21,1309151649),r=C(r,i,s,n,e[o+4],6,-145523070),n=C(n,r,i,s,e[o+11],10,-1120210379),s=C(s,n,r,i,e[o+2],15,718787259),i=C(i,s,n,r,e[o+9],21,-343485551),r=g(r,u),i=g(i,l),s=g(s,a),n=g(n,d)}return[r,i,s,n]}(function(e){if(0===e.length)return[];for(var t=8*e.length,r=new Uint32Array(m(t)),i=0;i<t;i+=8)r[i>>5]|=(255&e[i/8])<<i%32;return r}(e),8*e.length))})),N=function(e,t,r){var i=(e=e||{}).random||(e.rng||n)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,t){r=r||0;for(var s=0;s<16;++s)t[r+s]=i[s];return t}return d(i)};function S(e,t,r,i){switch(e){case 0:return t&r^~t&i;case 1:return t^r^i;case 2:return t&r^t&i^r&i;case 3:return t^r^i}}function A(e,t){return e<<t|e>>>32-t}const E=y("v5",80,(function(e){var t=[1518500249,1859775393,2400959708,3395469782],r=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof e){var i=unescape(encodeURIComponent(e));e=[];for(var s=0;s<i.length;++s)e.push(i.charCodeAt(s))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);for(var n=e.length/4+2,o=Math.ceil(n/16),u=new Array(o),l=0;l<o;++l){for(var a=new Uint32Array(16),d=0;d<16;++d)a[d]=e[64*l+4*d]<<24|e[64*l+4*d+1]<<16|e[64*l+4*d+2]<<8|e[64*l+4*d+3];u[l]=a}u[o-1][14]=8*(e.length-1)/Math.pow(2,32),u[o-1][14]=Math.floor(u[o-1][14]),u[o-1][15]=8*(e.length-1)&4294967295;for(var c=0;c<o;++c){for(var h=new Uint32Array(80),f=0;f<16;++f)h[f]=u[c][f];for(var p=16;p<80;++p)h[p]=A(h[p-3]^h[p-8]^h[p-14]^h[p-16],1);for(var b=r[0],v=r[1],y=r[2],m=r[3],g=r[4],q=0;q<80;++q){var O=Math.floor(q/20),j=A(b,5)+S(O,v,y,m)+g+t[O]+h[q]>>>0;g=m,m=y,y=A(v,30)>>>0,v=b,b=j}r[0]=r[0]+b>>>0,r[1]=r[1]+v>>>0,r[2]=r[2]+y>>>0,r[3]=r[3]+m>>>0,r[4]=r[4]+g>>>0}return[r[0]>>24&255,r[0]>>16&255,r[0]>>8&255,255&r[0],r[1]>>24&255,r[1]>>16&255,r[1]>>8&255,255&r[1],r[2]>>24&255,r[2]>>16&255,r[2]>>8&255,255&r[2],r[3]>>24&255,r[3]>>16&255,r[3]>>8&255,255&r[3],r[4]>>24&255,r[4]>>16&255,r[4]>>8&255,255&r[4]]})),R="00000000-0000-0000-0000-000000000000",I=function(e){if(!u(e))throw TypeError("Invalid UUID");return parseInt(e.substr(14,1),16)}}},t={};function r(i){var s=t[i];if(void 0!==s)return s.exports;var n=t[i]={exports:{}};return e[i].call(n.exports,n,n.exports,r),n.exports}r.d=(e,t)=>{for(var i in t)r.o(t,i)&&!r.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r(492)})();