@ohbug/core 1.1.6 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,29 +0,0 @@
1
- /*! *****************************************************************************
2
- Copyright (c) Microsoft Corporation.
3
-
4
- Permission to use, copy, modify, and/or distribute this software for any
5
- purpose with or without fee is hereby granted.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
- PERFORMANCE OF THIS SOFTWARE.
14
- ***************************************************************************** */
15
- var t=function(){return(t=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function e(t,e,n,r){return new(n||(n=Promise))((function(o,a){function i(t){try{s(r.next(t))}catch(t){a(t)}}function u(t){try{s(r.throw(t))}catch(t){a(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,u)}s((r=r.apply(t,e||[])).next())}))}function n(t,e){var n,r,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=e.call(t,i)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}function r(t,e){for(var n=0,r=e.length,o=t.length;n<r;n++,o++)t[o]=e[n];return t}
16
- /*! *****************************************************************************
17
- Copyright (c) Microsoft Corporation.
18
-
19
- Permission to use, copy, modify, and/or distribute this software for any
20
- purpose with or without fee is hereby granted.
21
-
22
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
23
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
24
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
25
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
26
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
27
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28
- PERFORMANCE OF THIS SOFTWARE.
29
- ***************************************************************************** */function o(t,e){for(var n=0,r=e.length,o=t.length;n<r;n++,o++)t[o]=e[n];return t}function a(t){return"string"==typeof t}function i(t){return"function"==typeof t}function u(t){return"[object Object]"===Object.prototype.toString.call(t)}var s={apiKey:{defaultValue:void 0,message:"is required",validate:function(t){return Boolean(t)&&a(t)}},appVersion:{defaultValue:void 0,message:"should be a string",validate:function(t){return void 0===t||a(t)}},appType:{defaultValue:void 0,message:"should be a string",validate:function(t){return void 0===t||a(t)}},releaseStage:{defaultValue:"production",message:"should be a string",validate:function(t){return void 0===t||a(t)}},endpoint:{defaultValue:"http://localhost:6660/report",message:"should be a string",validate:function(t){return void 0===t||a(t)}},maxActions:{defaultValue:30,message:"should be a number between 0 and 100",validate:function(t){return void 0===t||function(t){return"number"==typeof t&&parseInt(""+t,10)===t}(t)&&t>=1&&t<=100}},created:{defaultValue:function(t){return t},message:"should be a function",validate:function(t){return void 0===t||i(t)}},notified:{defaultValue:function(){},message:"should be a function",validate:function(t){return void 0===t||i(t)}},logger:{defaultValue:{log:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];console.log.apply(console,o(["Ohbug"],t))},info:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];console.info.apply(console,o(["Ohbug"],t))},warn:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];console.warn.apply(console,o(["Ohbug"],t))},error:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];console.error.apply(console,o(["Ohbug"],t))}},message:"should be null or an object with methods { log, info, warn, error }",validate:function(t){return void 0===t||t&&["log","info","warn","error"].reduce((function(e,n){return e&&"function"==typeof t[n]}),!0)}},user:{defaultValue:void 0,message:"should be an object and have up to 6 attributes",validate:function(t){return void 0===t||u(t)&&Object.keys(t).length<=6}},metaData:{defaultValue:void 0,message:"should be an object",validate:function(t){return void 0===t||u(t)}}};function c(t){return t}function l(t){return t}function f(t,e){for(var n,o=[],a=2;a<arguments.length;a++)o[a-2]=arguments[a];var u=null===(n=t.init)||void 0===n?void 0:n.call.apply(n,r([t,e],o));return e._extensions.push(t),e._hooks.created=function(t,e){var n,o,a=r([e._config.created],e._extensions.filter((function(t){return i(t.created)})).map((function(t){return t.created})));return 0===a.length?function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return t}(t,e):1===a.length?null===(n=a[0])||void 0===n?void 0:n.call(a,t,e):null===(o=a.reduce((function(t,n){return function(r){return n(t(r,e),e)}})))||void 0===o?void 0:o(t,e)},e._hooks.notified=function(t,e){return r([e._config.notified],e._extensions.filter((function(t){return i(t.notified)})).map((function(t){return t.notified}))).forEach((function(n){return null==n?void 0:n(t,e)}))},u||e}var p=function(t,e,n,r){this.type=n,this.timestamp=r||(new Date).toISOString(),this.message=t,this.data=e};function d(t,e){return new Error("Invalid data\n- "+t+", got "+JSON.stringify(e))}function h(t,e,n){e&&(t[e]=n)}function g(t,e){if(t[e])return t[e]}function v(t,e){if(t[e])return delete t[e]}var y=function(){function e(t,e){var n=t.apiKey,r=t.appVersion,o=t.appType,a=t.releaseStage,i=t.timestamp,u=t.category,s=t.type,c=t.sdk,l=t.detail,f=t.device,p=t.user,d=t.actions,h=t.metaData;this.apiKey=n,this.appVersion=r,this.appType=o,this.releaseStage=a,this.timestamp=i,this.category=u,this.type=s,this.sdk=c,this.detail=l,this.device=f,this.user=p,this.actions=d,this.metaData=h,this._client=e}return Object.defineProperty(e.prototype,"_isOhbugEvent",{get:function(){return!0},enumerable:!1,configurable:!0}),e.prototype.addAction=function(t,e,n,r){var o,i,u=this.actions,s=a(t)?t:"",c=e||{},l=a(n)?n:"",f=new p(s,c,l,r);u.length>=(null!==(i=null===(o=this._client)||void 0===o?void 0:o._config.maxActions)&&void 0!==i?i:30)&&u.shift(),u.push(f)},e.prototype.getUser=function(){return this.user},e.prototype.setUser=function(e){var n;if(u(e)&&Object.keys(e).length<=6)return this.user=t(t({},this.user),e),this.getUser();null===(n=this._client)||void 0===n||n._logger.warn(d("setUser should be an object and have up to 6 attributes",e))},e.prototype.addMetaData=function(t,e){return h(this.metaData,t,e)},e.prototype.getMetaData=function(t){return g(this.metaData,t)},e.prototype.deleteMetaData=function(t){return v(this.metaData,t)},e.prototype.toJSON=function(){var t=this;return{apiKey:t.apiKey,appVersion:t.appVersion,appType:t.appType,timestamp:t.timestamp,category:t.category,type:t.type,sdk:t.sdk,device:t.device,detail:t.detail,user:t.user,actions:t.actions,metaData:t.metaData,releaseStage:t.releaseStage}},e}();function b(t){return Boolean(null==t?void 0:t._isOhbugEvent)}var m=function(){function o(t){var e=this,n=t.sdk,r=t.config,o=t.schema,a=void 0===o?s:o,i=t.device,c=t.notifier,l=function(t,e){return Object.keys(e).reduce((function(n,r){var o=t[r],a=e[r],i=a.defaultValue,u=a.message,s=a.validate;return void 0!==o?s(o)?n.config[r]=o:(n.config[r]=i,n.errors[r]=u):n.config[r]=i,n}),{config:{},errors:{}})}(r,a),f=l.config,p=l.errors;this._sdk=n,this._config=f,this._logger=f.logger,this._device=i,this._notifier=c,this._extensions=[],this._hooks={created:f.created,notified:f.notified},this._actions=[],this._user=f.user,this._metaData={},u(f.metaData)&&Object.keys(f.metaData).forEach((function(t){e.addMetaData(t,f.metaData[t])})),Object.keys(p).length&&this._logger.warn(function(t,e){return new Error("Invalid configuration\n"+Object.keys(t).map((function(n){return"- "+n+" "+t[n]+", got "+JSON.stringify(e[n])})).join("\n")+"\n ")}(p,r))}return o.prototype.use=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];return f.apply(void 0,r([t,this],e))},o.prototype.createEvent=function(t){var e,n,r,o,a,s,c,l,f,p,d,h,g=(e=t,s=(n=this)._config,c=s.apiKey,l=s.appVersion,f=s.appType,p=s.releaseStage,d=(new Date).toISOString(),h=n._device(n),u(e)&&Object.prototype.hasOwnProperty.call(e,"type")&&Object.prototype.hasOwnProperty.call(e,"detail")?(r=e.category||"error",o=e.type,a=e.detail):(r="error",o="unknownError",a=e),new y({apiKey:c,appVersion:l,appType:f,timestamp:d,category:r,type:o,sdk:n._sdk,device:h,user:n._user,detail:a,actions:n._actions,metaData:n._metaData,releaseStage:p},n));return i(this._hooks.created)?this._hooks.created(g,this):g},o.prototype.notify=function(t,r){var o;return o=Boolean(t)&&!b(t)?this.createEvent(t):t,r&&(o=r(o)),function(t,r){return e(this,void 0,void 0,(function(){var e,o;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),e=null,t?[4,r._notifier(t)]:[3,2];case 1:e=n.sent(),n.label=2;case 2:return i(r._hooks.notified)&&r._hooks.notified(t,r),[2,e];case 3:return o=n.sent(),r._logger.error(o),[3,4];case 4:return[2]}}))}))}(o,this)},o.prototype.addAction=function(t,e,n,r){var o=this._actions,i=a(t)?t:"",u=e||{},s=a(n)?n:"",c=new p(i,u,s,r);o.length>=this._config.maxActions&&o.shift(),o.push(c)},o.prototype.getUser=function(){return this._user},o.prototype.setUser=function(e){if(u(e)&&Object.keys(e).length<=6)return this._user=t(t({},this._user),e),this.getUser();this._logger.warn(d("setUser should be an object and have up to 6 attributes",e))},o.prototype.addMetaData=function(t,e){return h(this._metaData,t,e)},o.prototype.getMetaData=function(t){return g(this._metaData,t)},o.prototype.deleteMetaData=function(t){return v(this._metaData,t)},o}();export{m as Client,c as createExtension,l as createExtensionUI,b as isEvent};