splunk-events
Advanced tools
Comparing version 1.6.1-beta to 1.6.1
@@ -10,5 +10,6 @@ # Changelog | ||
## [1.6.1-beta] - 2021-04-12 | ||
### Changed | ||
- Removed `Content-Type` from default headers list. | ||
## [1.6.1] - 2021-10-26 | ||
### Fixed | ||
- Events logged during in flight request with exponential backoff strategy | ||
being dropped. | ||
@@ -15,0 +16,0 @@ ## [1.6.0] - 2021-04-07 |
/*! | ||
* splunk-events v1.6.1-beta | ||
* splunk-events v1.6.1 | ||
* Copyright (c) VTEX | ||
@@ -238,3 +238,3 @@ * Released under the MIT License. | ||
if (_this.isBackoffInProgress) { | ||
return; | ||
return Promise.resolve(); | ||
} | ||
@@ -245,6 +245,12 @@ _this.isBackoffInProgress = true; | ||
if (depth === void 0) { depth = 0; } | ||
return _this.flush() | ||
_this.pendingEvents = _this.pendingEvents.concat(_this.events); | ||
_this.events = []; | ||
return _this.flush(_this.pendingEvents) | ||
.then(function () { | ||
_this.events = []; | ||
_this.pendingEvents = []; | ||
_this.isBackoffInProgress = false; | ||
if (_this.events.length > 0) { | ||
return _this._backoffFlush(); | ||
} | ||
return Promise.resolve(); | ||
})["catch"](function () { | ||
@@ -332,3 +338,3 @@ var waitTime = Math.pow(backoffMultiplier, depth) * 1000; | ||
(_s = config === null || config === void 0 ? void 0 : config.maxNumberOfRetries) !== null && _s !== void 0 ? _s : this.maxNumberOfRetries; | ||
this.headers = __assign({ Authorization: "Splunk " + this.token }, ((_t = config === null || config === void 0 ? void 0 : config.headers) !== null && _t !== void 0 ? _t : {})); | ||
this.headers = __assign({ Authorization: "Splunk " + this.token, 'Content-Type': 'application/json' }, ((_t = config === null || config === void 0 ? void 0 : config.headers) !== null && _t !== void 0 ? _t : {})); | ||
}; | ||
@@ -335,0 +341,0 @@ /** |
/*! | ||
* splunk-events v1.6.1-beta | ||
* splunk-events v1.6.1 | ||
* Copyright (c) VTEX | ||
@@ -20,3 +20,3 @@ * Released under the MIT License. | ||
***************************************************************************** */ | ||
var n=function(){return(n=Object.assign||function(n){for(var t,e=1,o=arguments.length;e<o;e++)for(var i in t=arguments[e])Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i]);return n}).apply(this,arguments)};function t(n,t,e,o){return new(e||(e=Promise))((function(i,s){function u(n){try{l(o.next(n))}catch(n){s(n)}}function r(n){try{l(o.throw(n))}catch(n){s(n)}}function l(n){var t;n.done?i(n.value):(t=n.value,t instanceof e?t:new e((function(n){n(t)}))).then(u,r)}l((o=o.apply(n,t||[])).next())}))}function e(n,t){var e,o,i,s,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:r(0),throw:r(1),return:r(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function r(s){return function(r){return function(s){if(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,o&&(i=2&s[0]?o.return:s[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,s[1])).done)return i;switch(o=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return u.label++,{value:s[1],done:!1};case 5:u.label++,o=s[1],s=[0];continue;case 7:s=u.ops.pop(),u.trys.pop();continue;default:if(!(i=u.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){u=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){u.label=s[1];break}if(6===s[0]&&u.label<i[1]){u.label=i[1],i=s;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(s);break}i[2]&&u.ops.pop(),u.trys.pop();continue}s=t.call(n,u)}catch(n){s=[6,n],o=0}finally{e=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,r])}}}function o(n,t){void 0===t&&(t=100);var e=null,o=null,i=function(){for(var i=[],s=0;s<arguments.length;s++)i[s]=arguments[s];return e&&(clearTimeout(e),e=null),new Promise((function(s,u){o=u,e=setTimeout((function(){var t=n.apply(void 0,i);null!=t&&t.then(s).catch(u)}),t)}))};return i.clear=function(){e&&(clearTimeout(e),null==o||o(),e=null)},i}function i(t){return"undefined"!=typeof window&&"function"!=typeof window.fetch||"undefined"!=typeof global&&"function"!=typeof global.fetch?(console.log("Error, using fetchRequest without fetch object"),Promise.resolve(null)):fetch(t.url,n(n({},t),{body:t.data})).then((function(n){return"json"===t.responseType?n.json():n}))}var s=function(){function s(s){var u=this;this._requestImpl=i,this.autoFlush=!0,this.autoRetryFlush=!0,this.debounceTime=2e3,this.debug=!1,this.events=[],this.host="-",this.injectAdditionalInfo=!1,this.injectTimestamp=!1,this.isSendingEvents=!1,this.path="/services/collector/event",this.pendingEvents=[],this.shouldParseEventData=!0,this.source="log",this.flushPending=!1,this.useExponentialBackoff=!1,this.exponentialBackoffLimit=6e4,this.isBackoffInProgress=!1,this.maxNumberOfRetries=1/0,this.logEvent=function(t,e,o,i,s,r){void 0===r&&(r=""),u.validateEvent(s);var l=n(n({level:t,type:e,workflowType:o,workflowInstance:i,account:r},s),u.injectAdditionalInfo?u.getAdditionalInfo():{}),a=u.shouldParseEventData?u.parseEventData(l):l,h=n(n({sourcetype:u.source,host:u.host},u.injectTimestamp&&{time:+new Date}),{event:a});u.events.push(h),u.autoFlush&&u.flushEvents()},this.flushEvents=function(){u.useExponentialBackoff?u._backoffFlush():u.debouncedFlush()},this.flush=function(n){return void 0===n&&(n=u.events),t(u,void 0,void 0,(function(){var t,o,i=this;return e(this,(function(e){return this.validateConfig(),0===n.length?[2]:(this.debug&&console.log("sending "+n.length+" events to splunk"),t=this.formatEventsForSplunkBatch(n),[2,this.request({url:""+this.endpoint+this.path,method:"POST",data:t,headers:null!==(o=this.headers)&&void 0!==o?o:{},responseType:"json"}).then((function(){i.debug&&console.log(n.length+" events successfuly sent to splunk")})).catch((function(n){throw i.debug&&console.warn("Error sending events to splunk.",n),n}))])}))}))},this._backoffFlush=function(){if(!u.isBackoffInProgress){u.isBackoffInProgress=!0;var n=function(t){return void 0===t&&(t=0),u.flush().then((function(){u.events=[],u.isBackoffInProgress=!1})).catch((function(){var e=1e3*Math.pow(2,t);return t>u.maxNumberOfRetries?(u.events=[],void(u.isBackoffInProgress=!1)):new Promise((function(o,i){setTimeout((function(){n(t+1).then(o,i).catch(i)}),Math.min(e,u.exponentialBackoffLimit))}))}))};return n()}},this._debouncedFlush=function(){u.isSendingEvents?u.flushPending=!0:(u.pendingEvents=Array.from(u.events),u.events=[],u.isSendingEvents=!0,u.flush(u.pendingEvents).then((function(){if(u.pendingEvents=[],u.isSendingEvents=!1,u.flushPending)return u.flushPending=!1,u._debouncedFlush()})).catch((function(){u.events=u.events.concat(u.pendingEvents),u.pendingEvents=[],u.isSendingEvents=!1,u.autoRetryFlush&&u.flushEvents()})))},this.debouncedFlush=o(this._debouncedFlush,this.debounceTime),s&&this.config(s)}return s.prototype.config=function(t){var e,i,s,u,r,l,a,h,c,f,d,v,p,g,b,m,y,w;this.endpoint=null!==(e=null==t?void 0:t.endpoint)&&void 0!==e?e:this.endpoint,this.token=null!==(i=null==t?void 0:t.token)&&void 0!==i?i:this.endpoint,this.injectAdditionalInfo=null!==(u=null!==(s=null==t?void 0:t.injectAditionalInfo)&&void 0!==s?s:null==t?void 0:t.injectAdditionalInfo)&&void 0!==u?u:this.injectAdditionalInfo,this.useExponentialBackoff=null!==(r=null==t?void 0:t.useExponentialBackoff)&&void 0!==r?r:this.useExponentialBackoff,this.exponentialBackoffLimit=null!==(l=null==t?void 0:t.exponentialBackoffLimit)&&void 0!==l?l:this.exponentialBackoffLimit,this.autoFlush=!!this.useExponentialBackoff||(null!==(a=null==t?void 0:t.autoFlush)&&void 0!==a?a:this.autoFlush),this.autoRetryFlush=null!==(h=null==t?void 0:t.autoRetryFlush)&&void 0!==h?h:this.autoRetryFlush,this.source=null!==(c=null==t?void 0:t.source)&&void 0!==c?c:this.source,this.path=null!==(f=null==t?void 0:t.path)&&void 0!==f?f:this.path,this.host=null!==(d=null==t?void 0:t.host)&&void 0!==d?d:this.host,this.debug=null!==(v=null==t?void 0:t.debug)&&void 0!==v?v:this.debug;var E=this.debounceTime;this.debounceTime=null!==(p=null==t?void 0:t.debounceTime)&&void 0!==p?p:this.debounceTime,this.debounceTime!==E&&(this.debouncedFlush.clear(),this.debouncedFlush=o(this._debouncedFlush,this.debounceTime)),this._requestImpl=null!==(g=null==t?void 0:t.request)&&void 0!==g?g:this._requestImpl,this.injectTimestamp=null!==(b=null==t?void 0:t.injectTimestamp)&&void 0!==b?b:this.injectTimestamp,this.shouldParseEventData=null!==(m=null==t?void 0:t.shouldParseEventData)&&void 0!==m?m:this.shouldParseEventData,this.maxNumberOfRetries=null!==(y=null==t?void 0:t.maxNumberOfRetries)&&void 0!==y?y:this.maxNumberOfRetries,this.headers=n({Authorization:"Splunk "+this.token},null!==(w=null==t?void 0:t.headers)&&void 0!==w?w:{})},s.prototype.request=function(n){return this._requestImpl(n)},s.prototype.parseEventData=function(n){var t="";for(var e in n)if(Object.prototype.hasOwnProperty.call(n,e)&&null!=n[e]){var o=n[e];switch(typeof o){case"string":t+=e+'="'+o.replace(/"/g,"")+'" ';break;case"boolean":case"number":t+=e+"="+o+" ";break;default:throw new Error("Event property must be string, number or boolean")}}return t},s.prototype.validateEvent=function(n){if(null===n)throw new Error("Event must not be null");if(void 0===n)throw new Error("Event must not be undefined");if("object"!=typeof n)throw new Error("Event must be an object")},s.prototype.getAdditionalInfo=function(){if("undefined"==typeof navigator||"undefined"==typeof window)return"";var n=window.screen,t=window.location;return{additional_info:navigator.userAgent.replace(/,/g,";")+","+(navigator.browserLanguage||navigator.language)+","+navigator.platform+","+(n.availWidth||"-")+","+(n.availHeight||"-")+","+t.hostname+","+t.pathname+","+t.protocol.replace(":","")+","+(t.hash||"-")}},s.prototype.formatEventsForSplunkBatch=function(n){return n.map((function(n){return JSON.stringify(n)})).join("\n")},s.prototype.validateConfig=function(){if(null==this.token)throw new Error("Token must not be null nor undefined");if(null==this.endpoint)throw new Error("Endpoint must not be null nor undefined")},s}();export default s; | ||
var n=function(){return(n=Object.assign||function(n){for(var e,t=1,o=arguments.length;t<o;t++)for(var i in e=arguments[t])Object.prototype.hasOwnProperty.call(e,i)&&(n[i]=e[i]);return n}).apply(this,arguments)};function e(n,e,t,o){return new(t||(t=Promise))((function(i,s){function u(n){try{l(o.next(n))}catch(n){s(n)}}function r(n){try{l(o.throw(n))}catch(n){s(n)}}function l(n){var e;n.done?i(n.value):(e=n.value,e instanceof t?e:new t((function(n){n(e)}))).then(u,r)}l((o=o.apply(n,e||[])).next())}))}function t(n,e){var t,o,i,s,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:r(0),throw:r(1),return:r(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function r(s){return function(r){return function(s){if(t)throw new TypeError("Generator is already executing.");for(;u;)try{if(t=1,o&&(i=2&s[0]?o.return:s[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,s[1])).done)return i;switch(o=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return u.label++,{value:s[1],done:!1};case 5:u.label++,o=s[1],s=[0];continue;case 7:s=u.ops.pop(),u.trys.pop();continue;default:if(!(i=u.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){u=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){u.label=s[1];break}if(6===s[0]&&u.label<i[1]){u.label=i[1],i=s;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(s);break}i[2]&&u.ops.pop(),u.trys.pop();continue}s=e.call(n,u)}catch(n){s=[6,n],o=0}finally{t=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,r])}}}function o(n,e){void 0===e&&(e=100);var t=null,o=null,i=function(){for(var i=[],s=0;s<arguments.length;s++)i[s]=arguments[s];return t&&(clearTimeout(t),t=null),new Promise((function(s,u){o=u,t=setTimeout((function(){var e=n.apply(void 0,i);null!=e&&e.then(s).catch(u)}),e)}))};return i.clear=function(){t&&(clearTimeout(t),null==o||o(),t=null)},i}function i(e){return"undefined"!=typeof window&&"function"!=typeof window.fetch||"undefined"!=typeof global&&"function"!=typeof global.fetch?(console.log("Error, using fetchRequest without fetch object"),Promise.resolve(null)):fetch(e.url,n(n({},e),{body:e.data})).then((function(n){return"json"===e.responseType?n.json():n}))}var s=function(){function s(s){var u=this;this._requestImpl=i,this.autoFlush=!0,this.autoRetryFlush=!0,this.debounceTime=2e3,this.debug=!1,this.events=[],this.host="-",this.injectAdditionalInfo=!1,this.injectTimestamp=!1,this.isSendingEvents=!1,this.path="/services/collector/event",this.pendingEvents=[],this.shouldParseEventData=!0,this.source="log",this.flushPending=!1,this.useExponentialBackoff=!1,this.exponentialBackoffLimit=6e4,this.isBackoffInProgress=!1,this.maxNumberOfRetries=1/0,this.logEvent=function(e,t,o,i,s,r){void 0===r&&(r=""),u.validateEvent(s);var l=n(n({level:e,type:t,workflowType:o,workflowInstance:i,account:r},s),u.injectAdditionalInfo?u.getAdditionalInfo():{}),a=u.shouldParseEventData?u.parseEventData(l):l,h=n(n({sourcetype:u.source,host:u.host},u.injectTimestamp&&{time:+new Date}),{event:a});u.events.push(h),u.autoFlush&&u.flushEvents()},this.flushEvents=function(){u.useExponentialBackoff?u._backoffFlush():u.debouncedFlush()},this.flush=function(n){return void 0===n&&(n=u.events),e(u,void 0,void 0,(function(){var e,o,i=this;return t(this,(function(t){return this.validateConfig(),0===n.length?[2]:(this.debug&&console.log("sending "+n.length+" events to splunk"),e=this.formatEventsForSplunkBatch(n),[2,this.request({url:""+this.endpoint+this.path,method:"POST",data:e,headers:null!==(o=this.headers)&&void 0!==o?o:{},responseType:"json"}).then((function(){i.debug&&console.log(n.length+" events successfuly sent to splunk")})).catch((function(n){throw i.debug&&console.warn("Error sending events to splunk.",n),n}))])}))}))},this._backoffFlush=function(){if(u.isBackoffInProgress)return Promise.resolve();u.isBackoffInProgress=!0;var n=function(e){return void 0===e&&(e=0),u.pendingEvents=u.pendingEvents.concat(u.events),u.events=[],u.flush(u.pendingEvents).then((function(){return u.pendingEvents=[],u.isBackoffInProgress=!1,u.events.length>0?u._backoffFlush():Promise.resolve()})).catch((function(){var t=1e3*Math.pow(2,e);return e>u.maxNumberOfRetries?(u.events=[],void(u.isBackoffInProgress=!1)):new Promise((function(o,i){setTimeout((function(){n(e+1).then(o,i).catch(i)}),Math.min(t,u.exponentialBackoffLimit))}))}))};return n()},this._debouncedFlush=function(){u.isSendingEvents?u.flushPending=!0:(u.pendingEvents=Array.from(u.events),u.events=[],u.isSendingEvents=!0,u.flush(u.pendingEvents).then((function(){if(u.pendingEvents=[],u.isSendingEvents=!1,u.flushPending)return u.flushPending=!1,u._debouncedFlush()})).catch((function(){u.events=u.events.concat(u.pendingEvents),u.pendingEvents=[],u.isSendingEvents=!1,u.autoRetryFlush&&u.flushEvents()})))},this.debouncedFlush=o(this._debouncedFlush,this.debounceTime),s&&this.config(s)}return s.prototype.config=function(e){var t,i,s,u,r,l,a,h,c,f,d,v,p,g,b,m,y,E;this.endpoint=null!==(t=null==e?void 0:e.endpoint)&&void 0!==t?t:this.endpoint,this.token=null!==(i=null==e?void 0:e.token)&&void 0!==i?i:this.endpoint,this.injectAdditionalInfo=null!==(u=null!==(s=null==e?void 0:e.injectAditionalInfo)&&void 0!==s?s:null==e?void 0:e.injectAdditionalInfo)&&void 0!==u?u:this.injectAdditionalInfo,this.useExponentialBackoff=null!==(r=null==e?void 0:e.useExponentialBackoff)&&void 0!==r?r:this.useExponentialBackoff,this.exponentialBackoffLimit=null!==(l=null==e?void 0:e.exponentialBackoffLimit)&&void 0!==l?l:this.exponentialBackoffLimit,this.autoFlush=!!this.useExponentialBackoff||(null!==(a=null==e?void 0:e.autoFlush)&&void 0!==a?a:this.autoFlush),this.autoRetryFlush=null!==(h=null==e?void 0:e.autoRetryFlush)&&void 0!==h?h:this.autoRetryFlush,this.source=null!==(c=null==e?void 0:e.source)&&void 0!==c?c:this.source,this.path=null!==(f=null==e?void 0:e.path)&&void 0!==f?f:this.path,this.host=null!==(d=null==e?void 0:e.host)&&void 0!==d?d:this.host,this.debug=null!==(v=null==e?void 0:e.debug)&&void 0!==v?v:this.debug;var w=this.debounceTime;this.debounceTime=null!==(p=null==e?void 0:e.debounceTime)&&void 0!==p?p:this.debounceTime,this.debounceTime!==w&&(this.debouncedFlush.clear(),this.debouncedFlush=o(this._debouncedFlush,this.debounceTime)),this._requestImpl=null!==(g=null==e?void 0:e.request)&&void 0!==g?g:this._requestImpl,this.injectTimestamp=null!==(b=null==e?void 0:e.injectTimestamp)&&void 0!==b?b:this.injectTimestamp,this.shouldParseEventData=null!==(m=null==e?void 0:e.shouldParseEventData)&&void 0!==m?m:this.shouldParseEventData,this.maxNumberOfRetries=null!==(y=null==e?void 0:e.maxNumberOfRetries)&&void 0!==y?y:this.maxNumberOfRetries,this.headers=n({Authorization:"Splunk "+this.token,"Content-Type":"application/json"},null!==(E=null==e?void 0:e.headers)&&void 0!==E?E:{})},s.prototype.request=function(n){return this._requestImpl(n)},s.prototype.parseEventData=function(n){var e="";for(var t in n)if(Object.prototype.hasOwnProperty.call(n,t)&&null!=n[t]){var o=n[t];switch(typeof o){case"string":e+=t+'="'+o.replace(/"/g,"")+'" ';break;case"boolean":case"number":e+=t+"="+o+" ";break;default:throw new Error("Event property must be string, number or boolean")}}return e},s.prototype.validateEvent=function(n){if(null===n)throw new Error("Event must not be null");if(void 0===n)throw new Error("Event must not be undefined");if("object"!=typeof n)throw new Error("Event must be an object")},s.prototype.getAdditionalInfo=function(){if("undefined"==typeof navigator||"undefined"==typeof window)return"";var n=window.screen,e=window.location;return{additional_info:navigator.userAgent.replace(/,/g,";")+","+(navigator.browserLanguage||navigator.language)+","+navigator.platform+","+(n.availWidth||"-")+","+(n.availHeight||"-")+","+e.hostname+","+e.pathname+","+e.protocol.replace(":","")+","+(e.hash||"-")}},s.prototype.formatEventsForSplunkBatch=function(n){return n.map((function(n){return JSON.stringify(n)})).join("\n")},s.prototype.validateConfig=function(){if(null==this.token)throw new Error("Token must not be null nor undefined");if(null==this.endpoint)throw new Error("Endpoint must not be null nor undefined")},s}();export default s; | ||
//# sourceMappingURL=splunk-events.esm.min.js.map |
/*! | ||
* splunk-events v1.6.1-beta | ||
* splunk-events v1.6.1 | ||
* Copyright (c) VTEX | ||
@@ -240,3 +240,3 @@ * Released under the MIT License. | ||
if (_this.isBackoffInProgress) { | ||
return; | ||
return Promise.resolve(); | ||
} | ||
@@ -247,6 +247,12 @@ _this.isBackoffInProgress = true; | ||
if (depth === void 0) { depth = 0; } | ||
return _this.flush() | ||
_this.pendingEvents = _this.pendingEvents.concat(_this.events); | ||
_this.events = []; | ||
return _this.flush(_this.pendingEvents) | ||
.then(function () { | ||
_this.events = []; | ||
_this.pendingEvents = []; | ||
_this.isBackoffInProgress = false; | ||
if (_this.events.length > 0) { | ||
return _this._backoffFlush(); | ||
} | ||
return Promise.resolve(); | ||
})["catch"](function () { | ||
@@ -334,3 +340,3 @@ var waitTime = Math.pow(backoffMultiplier, depth) * 1000; | ||
(_s = config === null || config === void 0 ? void 0 : config.maxNumberOfRetries) !== null && _s !== void 0 ? _s : this.maxNumberOfRetries; | ||
this.headers = __assign({ Authorization: "Splunk " + this.token }, ((_t = config === null || config === void 0 ? void 0 : config.headers) !== null && _t !== void 0 ? _t : {})); | ||
this.headers = __assign({ Authorization: "Splunk " + this.token, 'Content-Type': 'application/json' }, ((_t = config === null || config === void 0 ? void 0 : config.headers) !== null && _t !== void 0 ? _t : {})); | ||
}; | ||
@@ -337,0 +343,0 @@ /** |
/*! | ||
* splunk-events v1.6.1-beta | ||
* splunk-events v1.6.1 | ||
* Copyright (c) VTEX | ||
@@ -20,3 +20,3 @@ * Released under the MIT License. | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */var n=function(){return(n=Object.assign||function(n){for(var t,e=1,o=arguments.length;e<o;e++)for(var i in t=arguments[e])Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i]);return n}).apply(this,arguments)};function t(n,t,e,o){return new(e||(e=Promise))((function(i,s){function u(n){try{l(o.next(n))}catch(n){s(n)}}function r(n){try{l(o.throw(n))}catch(n){s(n)}}function l(n){var t;n.done?i(n.value):(t=n.value,t instanceof e?t:new e((function(n){n(t)}))).then(u,r)}l((o=o.apply(n,t||[])).next())}))}function e(n,t){var e,o,i,s,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:r(0),throw:r(1),return:r(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function r(s){return function(r){return function(s){if(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,o&&(i=2&s[0]?o.return:s[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,s[1])).done)return i;switch(o=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return u.label++,{value:s[1],done:!1};case 5:u.label++,o=s[1],s=[0];continue;case 7:s=u.ops.pop(),u.trys.pop();continue;default:if(!(i=u.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){u=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){u.label=s[1];break}if(6===s[0]&&u.label<i[1]){u.label=i[1],i=s;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(s);break}i[2]&&u.ops.pop(),u.trys.pop();continue}s=t.call(n,u)}catch(n){s=[6,n],o=0}finally{e=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,r])}}}function o(n,t){void 0===t&&(t=100);var e=null,o=null,i=function(){for(var i=[],s=0;s<arguments.length;s++)i[s]=arguments[s];return e&&(clearTimeout(e),e=null),new Promise((function(s,u){o=u,e=setTimeout((function(){var t=n.apply(void 0,i);null!=t&&t.then(s).catch(u)}),t)}))};return i.clear=function(){e&&(clearTimeout(e),null==o||o(),e=null)},i}function i(t){return"undefined"!=typeof window&&"function"!=typeof window.fetch||"undefined"!=typeof global&&"function"!=typeof global.fetch?(console.log("Error, using fetchRequest without fetch object"),Promise.resolve(null)):fetch(t.url,n(n({},t),{body:t.data})).then((function(n){return"json"===t.responseType?n.json():n}))}var s=function(){function s(s){var u=this;this._requestImpl=i,this.autoFlush=!0,this.autoRetryFlush=!0,this.debounceTime=2e3,this.debug=!1,this.events=[],this.host="-",this.injectAdditionalInfo=!1,this.injectTimestamp=!1,this.isSendingEvents=!1,this.path="/services/collector/event",this.pendingEvents=[],this.shouldParseEventData=!0,this.source="log",this.flushPending=!1,this.useExponentialBackoff=!1,this.exponentialBackoffLimit=6e4,this.isBackoffInProgress=!1,this.maxNumberOfRetries=1/0,this.logEvent=function(t,e,o,i,s,r){void 0===r&&(r=""),u.validateEvent(s);var l=n(n({level:t,type:e,workflowType:o,workflowInstance:i,account:r},s),u.injectAdditionalInfo?u.getAdditionalInfo():{}),a=u.shouldParseEventData?u.parseEventData(l):l,h=n(n({sourcetype:u.source,host:u.host},u.injectTimestamp&&{time:+new Date}),{event:a});u.events.push(h),u.autoFlush&&u.flushEvents()},this.flushEvents=function(){u.useExponentialBackoff?u._backoffFlush():u.debouncedFlush()},this.flush=function(n){return void 0===n&&(n=u.events),t(u,void 0,void 0,(function(){var t,o,i=this;return e(this,(function(e){return this.validateConfig(),0===n.length?[2]:(this.debug&&console.log("sending "+n.length+" events to splunk"),t=this.formatEventsForSplunkBatch(n),[2,this.request({url:""+this.endpoint+this.path,method:"POST",data:t,headers:null!==(o=this.headers)&&void 0!==o?o:{},responseType:"json"}).then((function(){i.debug&&console.log(n.length+" events successfuly sent to splunk")})).catch((function(n){throw i.debug&&console.warn("Error sending events to splunk.",n),n}))])}))}))},this._backoffFlush=function(){if(!u.isBackoffInProgress){u.isBackoffInProgress=!0;var n=function(t){return void 0===t&&(t=0),u.flush().then((function(){u.events=[],u.isBackoffInProgress=!1})).catch((function(){var e=1e3*Math.pow(2,t);return t>u.maxNumberOfRetries?(u.events=[],void(u.isBackoffInProgress=!1)):new Promise((function(o,i){setTimeout((function(){n(t+1).then(o,i).catch(i)}),Math.min(e,u.exponentialBackoffLimit))}))}))};return n()}},this._debouncedFlush=function(){u.isSendingEvents?u.flushPending=!0:(u.pendingEvents=Array.from(u.events),u.events=[],u.isSendingEvents=!0,u.flush(u.pendingEvents).then((function(){if(u.pendingEvents=[],u.isSendingEvents=!1,u.flushPending)return u.flushPending=!1,u._debouncedFlush()})).catch((function(){u.events=u.events.concat(u.pendingEvents),u.pendingEvents=[],u.isSendingEvents=!1,u.autoRetryFlush&&u.flushEvents()})))},this.debouncedFlush=o(this._debouncedFlush,this.debounceTime),s&&this.config(s)}return s.prototype.config=function(t){var e,i,s,u,r,l,a,h,c,f,d,v,p,g,b,m,y,w;this.endpoint=null!==(e=null==t?void 0:t.endpoint)&&void 0!==e?e:this.endpoint,this.token=null!==(i=null==t?void 0:t.token)&&void 0!==i?i:this.endpoint,this.injectAdditionalInfo=null!==(u=null!==(s=null==t?void 0:t.injectAditionalInfo)&&void 0!==s?s:null==t?void 0:t.injectAdditionalInfo)&&void 0!==u?u:this.injectAdditionalInfo,this.useExponentialBackoff=null!==(r=null==t?void 0:t.useExponentialBackoff)&&void 0!==r?r:this.useExponentialBackoff,this.exponentialBackoffLimit=null!==(l=null==t?void 0:t.exponentialBackoffLimit)&&void 0!==l?l:this.exponentialBackoffLimit,this.autoFlush=!!this.useExponentialBackoff||(null!==(a=null==t?void 0:t.autoFlush)&&void 0!==a?a:this.autoFlush),this.autoRetryFlush=null!==(h=null==t?void 0:t.autoRetryFlush)&&void 0!==h?h:this.autoRetryFlush,this.source=null!==(c=null==t?void 0:t.source)&&void 0!==c?c:this.source,this.path=null!==(f=null==t?void 0:t.path)&&void 0!==f?f:this.path,this.host=null!==(d=null==t?void 0:t.host)&&void 0!==d?d:this.host,this.debug=null!==(v=null==t?void 0:t.debug)&&void 0!==v?v:this.debug;var E=this.debounceTime;this.debounceTime=null!==(p=null==t?void 0:t.debounceTime)&&void 0!==p?p:this.debounceTime,this.debounceTime!==E&&(this.debouncedFlush.clear(),this.debouncedFlush=o(this._debouncedFlush,this.debounceTime)),this._requestImpl=null!==(g=null==t?void 0:t.request)&&void 0!==g?g:this._requestImpl,this.injectTimestamp=null!==(b=null==t?void 0:t.injectTimestamp)&&void 0!==b?b:this.injectTimestamp,this.shouldParseEventData=null!==(m=null==t?void 0:t.shouldParseEventData)&&void 0!==m?m:this.shouldParseEventData,this.maxNumberOfRetries=null!==(y=null==t?void 0:t.maxNumberOfRetries)&&void 0!==y?y:this.maxNumberOfRetries,this.headers=n({Authorization:"Splunk "+this.token},null!==(w=null==t?void 0:t.headers)&&void 0!==w?w:{})},s.prototype.request=function(n){return this._requestImpl(n)},s.prototype.parseEventData=function(n){var t="";for(var e in n)if(Object.prototype.hasOwnProperty.call(n,e)&&null!=n[e]){var o=n[e];switch(typeof o){case"string":t+=e+'="'+o.replace(/"/g,"")+'" ';break;case"boolean":case"number":t+=e+"="+o+" ";break;default:throw new Error("Event property must be string, number or boolean")}}return t},s.prototype.validateEvent=function(n){if(null===n)throw new Error("Event must not be null");if(void 0===n)throw new Error("Event must not be undefined");if("object"!=typeof n)throw new Error("Event must be an object")},s.prototype.getAdditionalInfo=function(){if("undefined"==typeof navigator||"undefined"==typeof window)return"";var n=window.screen,t=window.location;return{additional_info:navigator.userAgent.replace(/,/g,";")+","+(navigator.browserLanguage||navigator.language)+","+navigator.platform+","+(n.availWidth||"-")+","+(n.availHeight||"-")+","+t.hostname+","+t.pathname+","+t.protocol.replace(":","")+","+(t.hash||"-")}},s.prototype.formatEventsForSplunkBatch=function(n){return n.map((function(n){return JSON.stringify(n)})).join("\n")},s.prototype.validateConfig=function(){if(null==this.token)throw new Error("Token must not be null nor undefined");if(null==this.endpoint)throw new Error("Endpoint must not be null nor undefined")},s}();module.exports=s; | ||
***************************************************************************** */var n=function(){return(n=Object.assign||function(n){for(var e,t=1,o=arguments.length;t<o;t++)for(var i in e=arguments[t])Object.prototype.hasOwnProperty.call(e,i)&&(n[i]=e[i]);return n}).apply(this,arguments)};function e(n,e,t,o){return new(t||(t=Promise))((function(i,s){function u(n){try{l(o.next(n))}catch(n){s(n)}}function r(n){try{l(o.throw(n))}catch(n){s(n)}}function l(n){var e;n.done?i(n.value):(e=n.value,e instanceof t?e:new t((function(n){n(e)}))).then(u,r)}l((o=o.apply(n,e||[])).next())}))}function t(n,e){var t,o,i,s,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:r(0),throw:r(1),return:r(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function r(s){return function(r){return function(s){if(t)throw new TypeError("Generator is already executing.");for(;u;)try{if(t=1,o&&(i=2&s[0]?o.return:s[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,s[1])).done)return i;switch(o=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return u.label++,{value:s[1],done:!1};case 5:u.label++,o=s[1],s=[0];continue;case 7:s=u.ops.pop(),u.trys.pop();continue;default:if(!(i=u.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){u=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){u.label=s[1];break}if(6===s[0]&&u.label<i[1]){u.label=i[1],i=s;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(s);break}i[2]&&u.ops.pop(),u.trys.pop();continue}s=e.call(n,u)}catch(n){s=[6,n],o=0}finally{t=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,r])}}}function o(n,e){void 0===e&&(e=100);var t=null,o=null,i=function(){for(var i=[],s=0;s<arguments.length;s++)i[s]=arguments[s];return t&&(clearTimeout(t),t=null),new Promise((function(s,u){o=u,t=setTimeout((function(){var e=n.apply(void 0,i);null!=e&&e.then(s).catch(u)}),e)}))};return i.clear=function(){t&&(clearTimeout(t),null==o||o(),t=null)},i}function i(e){return"undefined"!=typeof window&&"function"!=typeof window.fetch||"undefined"!=typeof global&&"function"!=typeof global.fetch?(console.log("Error, using fetchRequest without fetch object"),Promise.resolve(null)):fetch(e.url,n(n({},e),{body:e.data})).then((function(n){return"json"===e.responseType?n.json():n}))}var s=function(){function s(s){var u=this;this._requestImpl=i,this.autoFlush=!0,this.autoRetryFlush=!0,this.debounceTime=2e3,this.debug=!1,this.events=[],this.host="-",this.injectAdditionalInfo=!1,this.injectTimestamp=!1,this.isSendingEvents=!1,this.path="/services/collector/event",this.pendingEvents=[],this.shouldParseEventData=!0,this.source="log",this.flushPending=!1,this.useExponentialBackoff=!1,this.exponentialBackoffLimit=6e4,this.isBackoffInProgress=!1,this.maxNumberOfRetries=1/0,this.logEvent=function(e,t,o,i,s,r){void 0===r&&(r=""),u.validateEvent(s);var l=n(n({level:e,type:t,workflowType:o,workflowInstance:i,account:r},s),u.injectAdditionalInfo?u.getAdditionalInfo():{}),a=u.shouldParseEventData?u.parseEventData(l):l,h=n(n({sourcetype:u.source,host:u.host},u.injectTimestamp&&{time:+new Date}),{event:a});u.events.push(h),u.autoFlush&&u.flushEvents()},this.flushEvents=function(){u.useExponentialBackoff?u._backoffFlush():u.debouncedFlush()},this.flush=function(n){return void 0===n&&(n=u.events),e(u,void 0,void 0,(function(){var e,o,i=this;return t(this,(function(t){return this.validateConfig(),0===n.length?[2]:(this.debug&&console.log("sending "+n.length+" events to splunk"),e=this.formatEventsForSplunkBatch(n),[2,this.request({url:""+this.endpoint+this.path,method:"POST",data:e,headers:null!==(o=this.headers)&&void 0!==o?o:{},responseType:"json"}).then((function(){i.debug&&console.log(n.length+" events successfuly sent to splunk")})).catch((function(n){throw i.debug&&console.warn("Error sending events to splunk.",n),n}))])}))}))},this._backoffFlush=function(){if(u.isBackoffInProgress)return Promise.resolve();u.isBackoffInProgress=!0;var n=function(e){return void 0===e&&(e=0),u.pendingEvents=u.pendingEvents.concat(u.events),u.events=[],u.flush(u.pendingEvents).then((function(){return u.pendingEvents=[],u.isBackoffInProgress=!1,u.events.length>0?u._backoffFlush():Promise.resolve()})).catch((function(){var t=1e3*Math.pow(2,e);return e>u.maxNumberOfRetries?(u.events=[],void(u.isBackoffInProgress=!1)):new Promise((function(o,i){setTimeout((function(){n(e+1).then(o,i).catch(i)}),Math.min(t,u.exponentialBackoffLimit))}))}))};return n()},this._debouncedFlush=function(){u.isSendingEvents?u.flushPending=!0:(u.pendingEvents=Array.from(u.events),u.events=[],u.isSendingEvents=!0,u.flush(u.pendingEvents).then((function(){if(u.pendingEvents=[],u.isSendingEvents=!1,u.flushPending)return u.flushPending=!1,u._debouncedFlush()})).catch((function(){u.events=u.events.concat(u.pendingEvents),u.pendingEvents=[],u.isSendingEvents=!1,u.autoRetryFlush&&u.flushEvents()})))},this.debouncedFlush=o(this._debouncedFlush,this.debounceTime),s&&this.config(s)}return s.prototype.config=function(e){var t,i,s,u,r,l,a,h,c,f,d,v,p,g,m,b,y,E;this.endpoint=null!==(t=null==e?void 0:e.endpoint)&&void 0!==t?t:this.endpoint,this.token=null!==(i=null==e?void 0:e.token)&&void 0!==i?i:this.endpoint,this.injectAdditionalInfo=null!==(u=null!==(s=null==e?void 0:e.injectAditionalInfo)&&void 0!==s?s:null==e?void 0:e.injectAdditionalInfo)&&void 0!==u?u:this.injectAdditionalInfo,this.useExponentialBackoff=null!==(r=null==e?void 0:e.useExponentialBackoff)&&void 0!==r?r:this.useExponentialBackoff,this.exponentialBackoffLimit=null!==(l=null==e?void 0:e.exponentialBackoffLimit)&&void 0!==l?l:this.exponentialBackoffLimit,this.autoFlush=!!this.useExponentialBackoff||(null!==(a=null==e?void 0:e.autoFlush)&&void 0!==a?a:this.autoFlush),this.autoRetryFlush=null!==(h=null==e?void 0:e.autoRetryFlush)&&void 0!==h?h:this.autoRetryFlush,this.source=null!==(c=null==e?void 0:e.source)&&void 0!==c?c:this.source,this.path=null!==(f=null==e?void 0:e.path)&&void 0!==f?f:this.path,this.host=null!==(d=null==e?void 0:e.host)&&void 0!==d?d:this.host,this.debug=null!==(v=null==e?void 0:e.debug)&&void 0!==v?v:this.debug;var w=this.debounceTime;this.debounceTime=null!==(p=null==e?void 0:e.debounceTime)&&void 0!==p?p:this.debounceTime,this.debounceTime!==w&&(this.debouncedFlush.clear(),this.debouncedFlush=o(this._debouncedFlush,this.debounceTime)),this._requestImpl=null!==(g=null==e?void 0:e.request)&&void 0!==g?g:this._requestImpl,this.injectTimestamp=null!==(m=null==e?void 0:e.injectTimestamp)&&void 0!==m?m:this.injectTimestamp,this.shouldParseEventData=null!==(b=null==e?void 0:e.shouldParseEventData)&&void 0!==b?b:this.shouldParseEventData,this.maxNumberOfRetries=null!==(y=null==e?void 0:e.maxNumberOfRetries)&&void 0!==y?y:this.maxNumberOfRetries,this.headers=n({Authorization:"Splunk "+this.token,"Content-Type":"application/json"},null!==(E=null==e?void 0:e.headers)&&void 0!==E?E:{})},s.prototype.request=function(n){return this._requestImpl(n)},s.prototype.parseEventData=function(n){var e="";for(var t in n)if(Object.prototype.hasOwnProperty.call(n,t)&&null!=n[t]){var o=n[t];switch(typeof o){case"string":e+=t+'="'+o.replace(/"/g,"")+'" ';break;case"boolean":case"number":e+=t+"="+o+" ";break;default:throw new Error("Event property must be string, number or boolean")}}return e},s.prototype.validateEvent=function(n){if(null===n)throw new Error("Event must not be null");if(void 0===n)throw new Error("Event must not be undefined");if("object"!=typeof n)throw new Error("Event must be an object")},s.prototype.getAdditionalInfo=function(){if("undefined"==typeof navigator||"undefined"==typeof window)return"";var n=window.screen,e=window.location;return{additional_info:navigator.userAgent.replace(/,/g,";")+","+(navigator.browserLanguage||navigator.language)+","+navigator.platform+","+(n.availWidth||"-")+","+(n.availHeight||"-")+","+e.hostname+","+e.pathname+","+e.protocol.replace(":","")+","+(e.hash||"-")}},s.prototype.formatEventsForSplunkBatch=function(n){return n.map((function(n){return JSON.stringify(n)})).join("\n")},s.prototype.validateConfig=function(){if(null==this.token)throw new Error("Token must not be null nor undefined");if(null==this.endpoint)throw new Error("Endpoint must not be null nor undefined")},s}();module.exports=s; | ||
//# sourceMappingURL=splunk-events.min.js.map |
/*! | ||
* splunk-events v1.6.1-beta | ||
* splunk-events v1.6.1 | ||
* Copyright (c) VTEX | ||
@@ -244,3 +244,3 @@ * Released under the MIT License. | ||
if (_this.isBackoffInProgress) { | ||
return; | ||
return Promise.resolve(); | ||
} | ||
@@ -251,6 +251,12 @@ _this.isBackoffInProgress = true; | ||
if (depth === void 0) { depth = 0; } | ||
return _this.flush() | ||
_this.pendingEvents = _this.pendingEvents.concat(_this.events); | ||
_this.events = []; | ||
return _this.flush(_this.pendingEvents) | ||
.then(function () { | ||
_this.events = []; | ||
_this.pendingEvents = []; | ||
_this.isBackoffInProgress = false; | ||
if (_this.events.length > 0) { | ||
return _this._backoffFlush(); | ||
} | ||
return Promise.resolve(); | ||
})["catch"](function () { | ||
@@ -338,3 +344,3 @@ var waitTime = Math.pow(backoffMultiplier, depth) * 1000; | ||
(_s = config === null || config === void 0 ? void 0 : config.maxNumberOfRetries) !== null && _s !== void 0 ? _s : this.maxNumberOfRetries; | ||
this.headers = __assign({ Authorization: "Splunk " + this.token }, ((_t = config === null || config === void 0 ? void 0 : config.headers) !== null && _t !== void 0 ? _t : {})); | ||
this.headers = __assign({ Authorization: "Splunk " + this.token, 'Content-Type': 'application/json' }, ((_t = config === null || config === void 0 ? void 0 : config.headers) !== null && _t !== void 0 ? _t : {})); | ||
}; | ||
@@ -341,0 +347,0 @@ /** |
/*! | ||
* splunk-events v1.6.1-beta | ||
* splunk-events v1.6.1 | ||
* Copyright (c) VTEX | ||
* Released under the MIT License. | ||
*/ | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(n="undefined"!=typeof globalThis?globalThis:n||self).SplunkEvents=t()}(this,(function(){"use strict"; | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(n="undefined"!=typeof globalThis?globalThis:n||self).SplunkEvents=e()}(this,(function(){"use strict"; | ||
/*! ***************************************************************************** | ||
@@ -20,3 +20,3 @@ Copyright (c) Microsoft Corporation. | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */var n=function(){return(n=Object.assign||function(n){for(var t,e=1,o=arguments.length;e<o;e++)for(var i in t=arguments[e])Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i]);return n}).apply(this,arguments)};function t(n,t,e,o){return new(e||(e=Promise))((function(i,s){function u(n){try{r(o.next(n))}catch(n){s(n)}}function l(n){try{r(o.throw(n))}catch(n){s(n)}}function r(n){var t;n.done?i(n.value):(t=n.value,t instanceof e?t:new e((function(n){n(t)}))).then(u,l)}r((o=o.apply(n,t||[])).next())}))}function e(n,t){var e,o,i,s,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function l(s){return function(l){return function(s){if(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,o&&(i=2&s[0]?o.return:s[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,s[1])).done)return i;switch(o=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return u.label++,{value:s[1],done:!1};case 5:u.label++,o=s[1],s=[0];continue;case 7:s=u.ops.pop(),u.trys.pop();continue;default:if(!(i=u.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){u=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){u.label=s[1];break}if(6===s[0]&&u.label<i[1]){u.label=i[1],i=s;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(s);break}i[2]&&u.ops.pop(),u.trys.pop();continue}s=t.call(n,u)}catch(n){s=[6,n],o=0}finally{e=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}function o(n,t){void 0===t&&(t=100);var e=null,o=null,i=function(){for(var i=[],s=0;s<arguments.length;s++)i[s]=arguments[s];return e&&(clearTimeout(e),e=null),new Promise((function(s,u){o=u,e=setTimeout((function(){var t=n.apply(void 0,i);null!=t&&t.then(s).catch(u)}),t)}))};return i.clear=function(){e&&(clearTimeout(e),null==o||o(),e=null)},i}function i(t){return"undefined"!=typeof window&&"function"!=typeof window.fetch||"undefined"!=typeof global&&"function"!=typeof global.fetch?(console.log("Error, using fetchRequest without fetch object"),Promise.resolve(null)):fetch(t.url,n(n({},t),{body:t.data})).then((function(n){return"json"===t.responseType?n.json():n}))}return function(){function s(s){var u=this;this._requestImpl=i,this.autoFlush=!0,this.autoRetryFlush=!0,this.debounceTime=2e3,this.debug=!1,this.events=[],this.host="-",this.injectAdditionalInfo=!1,this.injectTimestamp=!1,this.isSendingEvents=!1,this.path="/services/collector/event",this.pendingEvents=[],this.shouldParseEventData=!0,this.source="log",this.flushPending=!1,this.useExponentialBackoff=!1,this.exponentialBackoffLimit=6e4,this.isBackoffInProgress=!1,this.maxNumberOfRetries=1/0,this.logEvent=function(t,e,o,i,s,l){void 0===l&&(l=""),u.validateEvent(s);var r=n(n({level:t,type:e,workflowType:o,workflowInstance:i,account:l},s),u.injectAdditionalInfo?u.getAdditionalInfo():{}),a=u.shouldParseEventData?u.parseEventData(r):r,h=n(n({sourcetype:u.source,host:u.host},u.injectTimestamp&&{time:+new Date}),{event:a});u.events.push(h),u.autoFlush&&u.flushEvents()},this.flushEvents=function(){u.useExponentialBackoff?u._backoffFlush():u.debouncedFlush()},this.flush=function(n){return void 0===n&&(n=u.events),t(u,void 0,void 0,(function(){var t,o,i=this;return e(this,(function(e){return this.validateConfig(),0===n.length?[2]:(this.debug&&console.log("sending "+n.length+" events to splunk"),t=this.formatEventsForSplunkBatch(n),[2,this.request({url:""+this.endpoint+this.path,method:"POST",data:t,headers:null!==(o=this.headers)&&void 0!==o?o:{},responseType:"json"}).then((function(){i.debug&&console.log(n.length+" events successfuly sent to splunk")})).catch((function(n){throw i.debug&&console.warn("Error sending events to splunk.",n),n}))])}))}))},this._backoffFlush=function(){if(!u.isBackoffInProgress){u.isBackoffInProgress=!0;var n=function(t){return void 0===t&&(t=0),u.flush().then((function(){u.events=[],u.isBackoffInProgress=!1})).catch((function(){var e=1e3*Math.pow(2,t);return t>u.maxNumberOfRetries?(u.events=[],void(u.isBackoffInProgress=!1)):new Promise((function(o,i){setTimeout((function(){n(t+1).then(o,i).catch(i)}),Math.min(e,u.exponentialBackoffLimit))}))}))};return n()}},this._debouncedFlush=function(){u.isSendingEvents?u.flushPending=!0:(u.pendingEvents=Array.from(u.events),u.events=[],u.isSendingEvents=!0,u.flush(u.pendingEvents).then((function(){if(u.pendingEvents=[],u.isSendingEvents=!1,u.flushPending)return u.flushPending=!1,u._debouncedFlush()})).catch((function(){u.events=u.events.concat(u.pendingEvents),u.pendingEvents=[],u.isSendingEvents=!1,u.autoRetryFlush&&u.flushEvents()})))},this.debouncedFlush=o(this._debouncedFlush,this.debounceTime),s&&this.config(s)}return s.prototype.config=function(t){var e,i,s,u,l,r,a,h,c,f,d,v,p,g,b,m,y,w;this.endpoint=null!==(e=null==t?void 0:t.endpoint)&&void 0!==e?e:this.endpoint,this.token=null!==(i=null==t?void 0:t.token)&&void 0!==i?i:this.endpoint,this.injectAdditionalInfo=null!==(u=null!==(s=null==t?void 0:t.injectAditionalInfo)&&void 0!==s?s:null==t?void 0:t.injectAdditionalInfo)&&void 0!==u?u:this.injectAdditionalInfo,this.useExponentialBackoff=null!==(l=null==t?void 0:t.useExponentialBackoff)&&void 0!==l?l:this.useExponentialBackoff,this.exponentialBackoffLimit=null!==(r=null==t?void 0:t.exponentialBackoffLimit)&&void 0!==r?r:this.exponentialBackoffLimit,this.autoFlush=!!this.useExponentialBackoff||(null!==(a=null==t?void 0:t.autoFlush)&&void 0!==a?a:this.autoFlush),this.autoRetryFlush=null!==(h=null==t?void 0:t.autoRetryFlush)&&void 0!==h?h:this.autoRetryFlush,this.source=null!==(c=null==t?void 0:t.source)&&void 0!==c?c:this.source,this.path=null!==(f=null==t?void 0:t.path)&&void 0!==f?f:this.path,this.host=null!==(d=null==t?void 0:t.host)&&void 0!==d?d:this.host,this.debug=null!==(v=null==t?void 0:t.debug)&&void 0!==v?v:this.debug;var E=this.debounceTime;this.debounceTime=null!==(p=null==t?void 0:t.debounceTime)&&void 0!==p?p:this.debounceTime,this.debounceTime!==E&&(this.debouncedFlush.clear(),this.debouncedFlush=o(this._debouncedFlush,this.debounceTime)),this._requestImpl=null!==(g=null==t?void 0:t.request)&&void 0!==g?g:this._requestImpl,this.injectTimestamp=null!==(b=null==t?void 0:t.injectTimestamp)&&void 0!==b?b:this.injectTimestamp,this.shouldParseEventData=null!==(m=null==t?void 0:t.shouldParseEventData)&&void 0!==m?m:this.shouldParseEventData,this.maxNumberOfRetries=null!==(y=null==t?void 0:t.maxNumberOfRetries)&&void 0!==y?y:this.maxNumberOfRetries,this.headers=n({Authorization:"Splunk "+this.token},null!==(w=null==t?void 0:t.headers)&&void 0!==w?w:{})},s.prototype.request=function(n){return this._requestImpl(n)},s.prototype.parseEventData=function(n){var t="";for(var e in n)if(Object.prototype.hasOwnProperty.call(n,e)&&null!=n[e]){var o=n[e];switch(typeof o){case"string":t+=e+'="'+o.replace(/"/g,"")+'" ';break;case"boolean":case"number":t+=e+"="+o+" ";break;default:throw new Error("Event property must be string, number or boolean")}}return t},s.prototype.validateEvent=function(n){if(null===n)throw new Error("Event must not be null");if(void 0===n)throw new Error("Event must not be undefined");if("object"!=typeof n)throw new Error("Event must be an object")},s.prototype.getAdditionalInfo=function(){if("undefined"==typeof navigator||"undefined"==typeof window)return"";var n=window.screen,t=window.location;return{additional_info:navigator.userAgent.replace(/,/g,";")+","+(navigator.browserLanguage||navigator.language)+","+navigator.platform+","+(n.availWidth||"-")+","+(n.availHeight||"-")+","+t.hostname+","+t.pathname+","+t.protocol.replace(":","")+","+(t.hash||"-")}},s.prototype.formatEventsForSplunkBatch=function(n){return n.map((function(n){return JSON.stringify(n)})).join("\n")},s.prototype.validateConfig=function(){if(null==this.token)throw new Error("Token must not be null nor undefined");if(null==this.endpoint)throw new Error("Endpoint must not be null nor undefined")},s}()})); | ||
***************************************************************************** */var n=function(){return(n=Object.assign||function(n){for(var e,t=1,o=arguments.length;t<o;t++)for(var i in e=arguments[t])Object.prototype.hasOwnProperty.call(e,i)&&(n[i]=e[i]);return n}).apply(this,arguments)};function e(n,e,t,o){return new(t||(t=Promise))((function(i,s){function u(n){try{l(o.next(n))}catch(n){s(n)}}function r(n){try{l(o.throw(n))}catch(n){s(n)}}function l(n){var e;n.done?i(n.value):(e=n.value,e instanceof t?e:new t((function(n){n(e)}))).then(u,r)}l((o=o.apply(n,e||[])).next())}))}function t(n,e){var t,o,i,s,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:r(0),throw:r(1),return:r(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function r(s){return function(r){return function(s){if(t)throw new TypeError("Generator is already executing.");for(;u;)try{if(t=1,o&&(i=2&s[0]?o.return:s[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,s[1])).done)return i;switch(o=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return u.label++,{value:s[1],done:!1};case 5:u.label++,o=s[1],s=[0];continue;case 7:s=u.ops.pop(),u.trys.pop();continue;default:if(!(i=u.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){u=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){u.label=s[1];break}if(6===s[0]&&u.label<i[1]){u.label=i[1],i=s;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(s);break}i[2]&&u.ops.pop(),u.trys.pop();continue}s=e.call(n,u)}catch(n){s=[6,n],o=0}finally{t=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,r])}}}function o(n,e){void 0===e&&(e=100);var t=null,o=null,i=function(){for(var i=[],s=0;s<arguments.length;s++)i[s]=arguments[s];return t&&(clearTimeout(t),t=null),new Promise((function(s,u){o=u,t=setTimeout((function(){var e=n.apply(void 0,i);null!=e&&e.then(s).catch(u)}),e)}))};return i.clear=function(){t&&(clearTimeout(t),null==o||o(),t=null)},i}function i(e){return"undefined"!=typeof window&&"function"!=typeof window.fetch||"undefined"!=typeof global&&"function"!=typeof global.fetch?(console.log("Error, using fetchRequest without fetch object"),Promise.resolve(null)):fetch(e.url,n(n({},e),{body:e.data})).then((function(n){return"json"===e.responseType?n.json():n}))}return function(){function s(s){var u=this;this._requestImpl=i,this.autoFlush=!0,this.autoRetryFlush=!0,this.debounceTime=2e3,this.debug=!1,this.events=[],this.host="-",this.injectAdditionalInfo=!1,this.injectTimestamp=!1,this.isSendingEvents=!1,this.path="/services/collector/event",this.pendingEvents=[],this.shouldParseEventData=!0,this.source="log",this.flushPending=!1,this.useExponentialBackoff=!1,this.exponentialBackoffLimit=6e4,this.isBackoffInProgress=!1,this.maxNumberOfRetries=1/0,this.logEvent=function(e,t,o,i,s,r){void 0===r&&(r=""),u.validateEvent(s);var l=n(n({level:e,type:t,workflowType:o,workflowInstance:i,account:r},s),u.injectAdditionalInfo?u.getAdditionalInfo():{}),a=u.shouldParseEventData?u.parseEventData(l):l,h=n(n({sourcetype:u.source,host:u.host},u.injectTimestamp&&{time:+new Date}),{event:a});u.events.push(h),u.autoFlush&&u.flushEvents()},this.flushEvents=function(){u.useExponentialBackoff?u._backoffFlush():u.debouncedFlush()},this.flush=function(n){return void 0===n&&(n=u.events),e(u,void 0,void 0,(function(){var e,o,i=this;return t(this,(function(t){return this.validateConfig(),0===n.length?[2]:(this.debug&&console.log("sending "+n.length+" events to splunk"),e=this.formatEventsForSplunkBatch(n),[2,this.request({url:""+this.endpoint+this.path,method:"POST",data:e,headers:null!==(o=this.headers)&&void 0!==o?o:{},responseType:"json"}).then((function(){i.debug&&console.log(n.length+" events successfuly sent to splunk")})).catch((function(n){throw i.debug&&console.warn("Error sending events to splunk.",n),n}))])}))}))},this._backoffFlush=function(){if(u.isBackoffInProgress)return Promise.resolve();u.isBackoffInProgress=!0;var n=function(e){return void 0===e&&(e=0),u.pendingEvents=u.pendingEvents.concat(u.events),u.events=[],u.flush(u.pendingEvents).then((function(){return u.pendingEvents=[],u.isBackoffInProgress=!1,u.events.length>0?u._backoffFlush():Promise.resolve()})).catch((function(){var t=1e3*Math.pow(2,e);return e>u.maxNumberOfRetries?(u.events=[],void(u.isBackoffInProgress=!1)):new Promise((function(o,i){setTimeout((function(){n(e+1).then(o,i).catch(i)}),Math.min(t,u.exponentialBackoffLimit))}))}))};return n()},this._debouncedFlush=function(){u.isSendingEvents?u.flushPending=!0:(u.pendingEvents=Array.from(u.events),u.events=[],u.isSendingEvents=!0,u.flush(u.pendingEvents).then((function(){if(u.pendingEvents=[],u.isSendingEvents=!1,u.flushPending)return u.flushPending=!1,u._debouncedFlush()})).catch((function(){u.events=u.events.concat(u.pendingEvents),u.pendingEvents=[],u.isSendingEvents=!1,u.autoRetryFlush&&u.flushEvents()})))},this.debouncedFlush=o(this._debouncedFlush,this.debounceTime),s&&this.config(s)}return s.prototype.config=function(e){var t,i,s,u,r,l,a,h,c,f,d,v,p,g,b,m,y,E;this.endpoint=null!==(t=null==e?void 0:e.endpoint)&&void 0!==t?t:this.endpoint,this.token=null!==(i=null==e?void 0:e.token)&&void 0!==i?i:this.endpoint,this.injectAdditionalInfo=null!==(u=null!==(s=null==e?void 0:e.injectAditionalInfo)&&void 0!==s?s:null==e?void 0:e.injectAdditionalInfo)&&void 0!==u?u:this.injectAdditionalInfo,this.useExponentialBackoff=null!==(r=null==e?void 0:e.useExponentialBackoff)&&void 0!==r?r:this.useExponentialBackoff,this.exponentialBackoffLimit=null!==(l=null==e?void 0:e.exponentialBackoffLimit)&&void 0!==l?l:this.exponentialBackoffLimit,this.autoFlush=!!this.useExponentialBackoff||(null!==(a=null==e?void 0:e.autoFlush)&&void 0!==a?a:this.autoFlush),this.autoRetryFlush=null!==(h=null==e?void 0:e.autoRetryFlush)&&void 0!==h?h:this.autoRetryFlush,this.source=null!==(c=null==e?void 0:e.source)&&void 0!==c?c:this.source,this.path=null!==(f=null==e?void 0:e.path)&&void 0!==f?f:this.path,this.host=null!==(d=null==e?void 0:e.host)&&void 0!==d?d:this.host,this.debug=null!==(v=null==e?void 0:e.debug)&&void 0!==v?v:this.debug;var w=this.debounceTime;this.debounceTime=null!==(p=null==e?void 0:e.debounceTime)&&void 0!==p?p:this.debounceTime,this.debounceTime!==w&&(this.debouncedFlush.clear(),this.debouncedFlush=o(this._debouncedFlush,this.debounceTime)),this._requestImpl=null!==(g=null==e?void 0:e.request)&&void 0!==g?g:this._requestImpl,this.injectTimestamp=null!==(b=null==e?void 0:e.injectTimestamp)&&void 0!==b?b:this.injectTimestamp,this.shouldParseEventData=null!==(m=null==e?void 0:e.shouldParseEventData)&&void 0!==m?m:this.shouldParseEventData,this.maxNumberOfRetries=null!==(y=null==e?void 0:e.maxNumberOfRetries)&&void 0!==y?y:this.maxNumberOfRetries,this.headers=n({Authorization:"Splunk "+this.token,"Content-Type":"application/json"},null!==(E=null==e?void 0:e.headers)&&void 0!==E?E:{})},s.prototype.request=function(n){return this._requestImpl(n)},s.prototype.parseEventData=function(n){var e="";for(var t in n)if(Object.prototype.hasOwnProperty.call(n,t)&&null!=n[t]){var o=n[t];switch(typeof o){case"string":e+=t+'="'+o.replace(/"/g,"")+'" ';break;case"boolean":case"number":e+=t+"="+o+" ";break;default:throw new Error("Event property must be string, number or boolean")}}return e},s.prototype.validateEvent=function(n){if(null===n)throw new Error("Event must not be null");if(void 0===n)throw new Error("Event must not be undefined");if("object"!=typeof n)throw new Error("Event must be an object")},s.prototype.getAdditionalInfo=function(){if("undefined"==typeof navigator||"undefined"==typeof window)return"";var n=window.screen,e=window.location;return{additional_info:navigator.userAgent.replace(/,/g,";")+","+(navigator.browserLanguage||navigator.language)+","+navigator.platform+","+(n.availWidth||"-")+","+(n.availHeight||"-")+","+e.hostname+","+e.pathname+","+e.protocol.replace(":","")+","+(e.hash||"-")}},s.prototype.formatEventsForSplunkBatch=function(n){return n.map((function(n){return JSON.stringify(n)})).join("\n")},s.prototype.validateConfig=function(){if(null==this.token)throw new Error("Token must not be null nor undefined");if(null==this.endpoint)throw new Error("Endpoint must not be null nor undefined")},s}()})); | ||
//# sourceMappingURL=splunk-events.umd.min.js.map |
{ | ||
"name": "splunk-events", | ||
"version": "1.6.1-beta", | ||
"version": "1.6.1", | ||
"description": "Javascript lib to create Splunk Logs via HTTP", | ||
@@ -5,0 +5,0 @@ "main": "lib/splunk-events.min.js", |
@@ -383,3 +383,3 @@ import SplunkEvents from '../splunk-events' | ||
it('should reset events to flush after successfull request', async () => { | ||
it('should discard previous events after successfull request', async () => { | ||
const requestMock = jest.fn().mockReturnValue(Promise.resolve()) | ||
@@ -425,3 +425,55 @@ | ||
}) | ||
it('should not drop pending events when requests succeed', async () => { | ||
let resolve = () => {} | ||
const requestMock = jest | ||
.fn() | ||
.mockReturnValue(Promise.resolve()) | ||
.mockImplementationOnce( | ||
() => | ||
new Promise<void>((res) => { | ||
resolve = res | ||
}) | ||
) | ||
splunkEvents.config({ | ||
endpoint: '/splunk', | ||
token: 'splunk-token-123', | ||
useExponentialBackoff: true, | ||
request: requestMock, | ||
}) | ||
splunkEvents.logEvent('debug', 'info', 'request', 'requestMockImpl', { | ||
requestNum: 1, | ||
}) | ||
await flushPromises() | ||
expect(requestMock).toHaveBeenCalledTimes(1) | ||
expect( | ||
// @ts-expect-error: asserting on private property | ||
splunkEvents.isBackoffInProgress | ||
).toBe(true) | ||
splunkEvents.logEvent( | ||
'debug', | ||
'info', | ||
'request', | ||
'requestInFlightTest', | ||
{} | ||
) | ||
resolve() | ||
await flushPromises() | ||
expect(requestMock).toHaveBeenCalledTimes(2) | ||
expect(requestMock).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
data: expect.stringContaining('requestInFlightTest'), | ||
}) | ||
) | ||
}) | ||
}) | ||
}) |
@@ -184,2 +184,3 @@ import debounce from './debounce' | ||
Authorization: `Splunk ${this.token}`, | ||
'Content-Type': 'application/json', | ||
...(config?.headers ?? {}), | ||
@@ -377,5 +378,5 @@ } | ||
private _backoffFlush = () => { | ||
private _backoffFlush = (): Promise<void> => { | ||
if (this.isBackoffInProgress) { | ||
return | ||
return Promise.resolve() | ||
} | ||
@@ -387,7 +388,17 @@ | ||
const executeFlush = (depth = 0) => { | ||
return this.flush() | ||
const executeFlush = (depth = 0): Promise<void> => { | ||
this.pendingEvents = this.pendingEvents.concat(this.events) | ||
this.events = [] | ||
return this.flush(this.pendingEvents) | ||
.then(() => { | ||
this.events = [] | ||
this.pendingEvents = [] | ||
this.isBackoffInProgress = false | ||
if (this.events.length > 0) { | ||
return this._backoffFlush() | ||
} | ||
return Promise.resolve() | ||
}) | ||
@@ -394,0 +405,0 @@ .catch(() => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
275542
2372
1