@inappstory/game-center-api 1.3.16 → 1.3.18

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.
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ResourceManager = void 0;
4
4
  const fetchLocalFile_1 = require("./sdkApi/fetchLocalFile");
5
- const errorHandler_1 = require("./errorHandler");
5
+ const eventLogger_1 = require("./eventLogger");
6
6
  let instance;
7
7
  class ResourceManager {
8
8
  resLists;
@@ -60,7 +60,7 @@ class ResourceManager {
60
60
  resolve();
61
61
  }
62
62
  catch (e) {
63
- (0, errorHandler_1.logError)(e, { resourceKeys });
63
+ (0, eventLogger_1.logError)(e, { resourceKeys });
64
64
  reject(`Can't load resource for [${resourceKeys.join(", ")}]`);
65
65
  }
66
66
  });
@@ -71,7 +71,7 @@ class ResourceManager {
71
71
  await Promise.all(promises);
72
72
  }
73
73
  catch (e) {
74
- (0, errorHandler_1.logError)(e);
74
+ (0, eventLogger_1.logError)(e);
75
75
  }
76
76
  for (const resList of this.resLists)
77
77
  resList["onCacheDone"]();
@@ -82,14 +82,14 @@ class ResourceManager {
82
82
  objectUrl = await this.createObjectUrlByUri(uri, resourceKeys);
83
83
  }
84
84
  catch (e) {
85
- (0, errorHandler_1.logError)(e, { uri, resourceKeys });
85
+ (0, eventLogger_1.logError)(e, { uri, resourceKeys });
86
86
  }
87
87
  if (objectUrl === null && uri !== originUri) {
88
88
  try {
89
89
  objectUrl = await this.createObjectUrlByUri(originUri, resourceKeys);
90
90
  }
91
91
  catch (e) {
92
- (0, errorHandler_1.logError)(e, { originUri, resourceKeys });
92
+ (0, eventLogger_1.logError)(e, { originUri, resourceKeys });
93
93
  }
94
94
  }
95
95
  if (objectUrl !== null) {
@@ -114,7 +114,7 @@ class ResourceManager {
114
114
  blob = await response.blob();
115
115
  }
116
116
  catch (e) {
117
- (0, errorHandler_1.logError)(e);
117
+ (0, eventLogger_1.logError)(e);
118
118
  throw e;
119
119
  }
120
120
  return URL.createObjectURL(blob);
package/lib/env.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getApplicationVersion = exports.getApplicationBuildVersion = exports.getSemverSdkVersion = exports.getSdkVersion = exports.isDev = exports.iosMh = exports.isAndroid = exports.isWeb = exports.isIos = void 0;
4
4
  const gameLaunchConfig_1 = require("./gameLaunchConfig");
5
- const errorHandler_1 = require("./errorHandler");
5
+ const eventLogger_1 = require("./eventLogger");
6
6
  const semver = require("semver");
7
7
  const isAndroid = Boolean(window.Android && window.Android.gameLoaded);
8
8
  exports.isAndroid = isAndroid;
@@ -29,7 +29,7 @@ const parseSdkVersion = () => {
29
29
  }
30
30
  }
31
31
  catch (e) {
32
- (0, errorHandler_1.logError)(e);
32
+ (0, eventLogger_1.logError)(e);
33
33
  }
34
34
  };
35
35
  const getSdkVersion = () => {
@@ -0,0 +1,30 @@
1
+ import { SeverityLevel as SentrySeverityLevel, Exception as SentryException } from "@sentry/browser";
2
+ /**
3
+ * for call instead of console.error(err)
4
+ * this method collect Error stack to error logger
5
+ **/
6
+ export declare const logError: (e: unknown, cause?: any) => void;
7
+ /** An event to be sent to API. */
8
+ interface Event {
9
+ exception?: {
10
+ values?: Array<Exception>;
11
+ };
12
+ level?: SentrySeverityLevel;
13
+ source?: "onerror" | "onunhandledrejection" | "consoleErrorMessage";
14
+ gameLoaded: boolean;
15
+ gameLaunchRawConfig: Record<string, any>;
16
+ gameVersion: string;
17
+ gameSlug: string;
18
+ sdkVersion: string;
19
+ env: "prod" | "test" | "";
20
+ }
21
+ interface Exception extends SentryException {
22
+ cause?: string;
23
+ }
24
+ export declare const eventFromConsoleErrorMessage: (exception: unknown) => Event;
25
+ declare const EventLogger: {
26
+ eventFromException: (exception: unknown) => Event;
27
+ eventFromConsoleErrorMessage: (exception: unknown) => Event;
28
+ eventFromUnhandledRejection: (rawEvent: PromiseRejectionEvent) => Event;
29
+ };
30
+ export default EventLogger;
@@ -0,0 +1 @@
1
+ var EventLogger;!function(){"use strict";var e={938:function(e,n,r){function t(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=Array(n);r<n;r++)t[r]=e[r];return t}n.nN=void 0;var a=r(651),o=Object.prototype.toString;function i(e){switch(o.call(e)){case"[object Error]":case"[object Exception]":case"[object DOMException]":case"[object WebAssembly.Exception]":return!0;default:return function(e,n){try{return e instanceof n}catch(e){return!1}}(e,Error)}}function c(e){if(i(e))return e;var n="";if(function(e){return o.call(e)==="[object ".concat("Object","]")}(e))try{n=JSON.stringify(e)}catch(e){}else if("string"==typeof e)n=e;else try{n=JSON.stringify(e)}catch(e){}var r=new Error(n);return r.message="".concat(n),r}function u(e){var n=[e],r=function(e){return i(e.cause)?(n.push(e.cause),r(e.cause)):null};return r(e),n}function f(e,n){var r={type:n.name||n.constructor.name,value:n.message};null!=n.cause&&"string"==typeof n.cause&&(r.cause=n.cause);var t=e(n.stack||"",0);return t.length&&(r.stacktrace={frames:t}),r}n.nN=function(e){var n,r={level:"error",source:"consoleErrorMessage",exception:{values:u(c(e)).map((function(e){return f(a.defaultStackParser,e)}))},gameLoaded:!1,gameLaunchRawConfig:{},gameSlug:"",gameVersion:"",sdkVersion:"",env:""};return r.gameLoaded=window.gameLoadingInfo.loaded,null!=window.gameLoadingInfo.gameLaunchRawConfig&&(r.gameSlug=window.gameLoadingInfo.gameLaunchRawConfig.gameSlug,r.gameVersion=window.gameLoadingInfo.gameLaunchRawConfig.gameVersion,r.env=window.gameLoadingInfo.gameLaunchRawConfig.projectEnv,r.sdkVersion=null===(n=window.gameLoadingInfo.gameLaunchRawConfig.clientConfig)||void 0===n?void 0:n.sdkVersion,r.gameLaunchRawConfig=window.gameLoadingInfo.gameLaunchRawConfig),r};var s={eventFromException:function(e){var n,r={level:"error",source:"onerror",exception:{values:u(c(e)).map((function(e){return f(a.defaultStackParser,e)}))},gameLoaded:!1,gameLaunchRawConfig:{},gameSlug:"",gameVersion:"",sdkVersion:"",env:""};return r.gameLoaded=window.gameLoadingInfo.loaded,null!=window.gameLoadingInfo.gameLaunchRawConfig&&(r.gameSlug=window.gameLoadingInfo.gameLaunchRawConfig.gameSlug,r.gameVersion=window.gameLoadingInfo.gameLaunchRawConfig.gameVersion,r.env=window.gameLoadingInfo.gameLaunchRawConfig.projectEnv,r.sdkVersion=null===(n=window.gameLoadingInfo.gameLaunchRawConfig.clientConfig)||void 0===n?void 0:n.sdkVersion,r.gameLaunchRawConfig=window.gameLoadingInfo.gameLaunchRawConfig),r},eventFromConsoleErrorMessage:n.nN,eventFromUnhandledRejection:function(e){var n=[];i(e.reason)&&(n=u(e.reason).map((function(e){return f(a.defaultStackParser,e)})));var r="";if("string"==typeof e.reason)r=e.reason;else try{r=JSON.stringify(e.reason)}catch(e){}var o={type:"PromiseRejection",value:r},c=e.promise.creationPoint;if(null!=c&&"string"==typeof c){var s=(0,a.defaultStackParser)(c||"",0);s.length&&(o.stacktrace={frames:s})}var l,g,d={level:"error",source:"onunhandledrejection",exception:{values:[].concat((g=n,function(e){if(Array.isArray(e))return t(e)}(g)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(g)||function(e,n){if(e){if("string"==typeof e)return t(e,n);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?t(e,n):void 0}}(g)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),[o]).filter(Boolean)},gameLoaded:!1,gameLaunchRawConfig:{},gameSlug:"",gameVersion:"",sdkVersion:"",env:""};return null!=window.gameLoadingInfo&&(d.gameLoaded=window.gameLoadingInfo.loaded,null!=window.gameLoadingInfo.gameLaunchRawConfig&&(d.gameSlug=window.gameLoadingInfo.gameLaunchRawConfig.gameSlug,d.gameVersion=window.gameLoadingInfo.gameLaunchRawConfig.gameVersion,d.env=window.gameLoadingInfo.gameLaunchRawConfig.projectEnv,d.sdkVersion=null===(l=window.gameLoadingInfo.gameLaunchRawConfig.clientConfig)||void 0===l?void 0:l.sdkVersion,d.gameLaunchRawConfig=window.gameLoadingInfo.gameLaunchRawConfig)),d}};n.default=s},651:function(e,n,r){function t(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var t,a,o,i,c=[],u=!0,f=!1;try{if(o=(r=r.call(e)).next,0===n){if(Object(r)!==r)return;u=!1}else for(;!(u=(t=o.call(r)).done)&&(c.push(t.value),c.length!==n);u=!0);}catch(e){f=!0,a=e}finally{try{if(!u&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(f)throw a}}return c}}(e,n)||a(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(e,n){if(e){if("string"==typeof e)return o(e,n);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(e,n):void 0}}function o(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=Array(n);r<n;r++)t[r]=e[r];return t}Object.defineProperty(n,"__esModule",{value:!0}),n.defaultStackParser=n.defaultStackLineParsers=n.opera11StackLineParser=n.opera10StackLineParser=n.winjsStackLineParser=n.geckoStackLineParser=n.chromeStackLineParser=void 0;var i=r(425);function c(e,n,r,t){var a={filename:e,function:"<anonymous>"===n?i.UNKNOWN_FUNCTION:n,in_app:!0};return void 0!==r&&(a.lineno=r),void 0!==t&&(a.colno=t),a}var u=/^\s*at (\S+?)(?::(\d+))(?::(\d+))\s*$/i,f=/^\s*at (?:(.+?\)(?: \[.+\])?|.*?) ?\((?:address at )?)?(?:async )?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,s=/\((\S*)(?::(\d+))(?::(\d+))\)/;n.chromeStackLineParser=[30,function(e){var n=u.exec(e);if(n){var r=t(n,4),a=r[1],o=r[2],l=r[3];return c(a,i.UNKNOWN_FUNCTION,+o,+l)}var g=f.exec(e);if(g){if(g[2]&&0===g[2].indexOf("eval")){var d=s.exec(g[2]);d&&(g[2]=d[1],g[3]=d[2],g[4]=d[3])}var m=t(p(g[1]||i.UNKNOWN_FUNCTION,g[2]),2),v=m[0];return c(m[1],v,g[3]?+g[3]:void 0,g[4]?+g[4]:void 0)}}];var l=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. /=]+)(?::(\d+))?(?::(\d+))?\s*$/i,g=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i;n.geckoStackLineParser=[50,function(e){var n=l.exec(e);if(n){if(n[3]&&n[3].indexOf(" > eval")>-1){var r=g.exec(n[3]);r&&(n[1]=n[1]||"eval",n[3]=r[1],n[4]=r[2],n[5]="")}var a=n[3],o=n[1]||i.UNKNOWN_FUNCTION,u=t(p(o,a),2);return o=u[0],c(a=u[1],o,n[4]?+n[4]:void 0,n[5]?+n[5]:void 0)}}];var d=/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:[-a-z]+):.*?):(\d+)(?::(\d+))?\)?\s*$/i;n.winjsStackLineParser=[40,function(e){var n=d.exec(e);return n?c(n[2],n[1]||i.UNKNOWN_FUNCTION,+n[3],n[4]?+n[4]:void 0):void 0}];var m=/ line (\d+).*script (?:in )?(\S+)(?:: in function (\S+))?$/i;n.opera10StackLineParser=[10,function(e){var n=m.exec(e);return n?c(n[2],n[3]||i.UNKNOWN_FUNCTION,+n[1]):void 0}];var v,y=/ line (\d+), column (\d+)\s*(?:in (?:<anonymous function: ([^>]+)>|([^)]+))\(.*\))? in (.*):\s*$/i;n.opera11StackLineParser=[20,function(e){var n=y.exec(e);return n?c(n[5],n[3]||n[4]||i.UNKNOWN_FUNCTION,+n[1],+n[2]):void 0}],n.defaultStackLineParsers=[n.chromeStackLineParser,n.geckoStackLineParser],n.defaultStackParser=i.createStackParser.apply(void 0,function(e){if(Array.isArray(e))return o(e)}(v=n.defaultStackLineParsers)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(v)||a(v)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}());var p=function(e,n){var r=-1!==e.indexOf("safari-extension"),t=-1!==e.indexOf("safari-web-extension");return r||t?[-1!==e.indexOf("@")?e.split("@")[0]:i.UNKNOWN_FUNCTION,r?"safari-extension:".concat(n):"safari-web-extension:".concat(n)]:[e,n]}},425:function(e,n){function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function t(e,n){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);n&&(t=t.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),r.push.apply(r,t)}return r}function a(e){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?t(Object(r),!0).forEach((function(n){o(e,n,r[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):t(Object(r)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))}))}return e}function o(e,n,t){return(n=function(e){var n=function(e){if("object"!=r(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var t=n.call(e,"string");if("object"!=r(t))return t;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==r(n)?n:n+""}(n))in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function i(e){return function(e){if(Array.isArray(e))return f(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||u(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(e,n){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=u(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var t=0,a=function(){};return{s:a,n:function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,i=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return i=e.done,e},e:function(e){c=!0,o=e},f:function(){try{i||null==r.return||r.return()}finally{if(c)throw o}}}}function u(e,n){if(e){if("string"==typeof e)return f(e,n);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?f(e,n):void 0}}function f(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=Array(n);r<n;r++)t[r]=e[r];return t}Object.defineProperty(n,"__esModule",{value:!0}),n.getFramesFromEvent=n.getFunctionName=n.stripSentryFramesAndReverse=n.stackParserFromStackParserOptions=n.createStackParser=n.UNKNOWN_FUNCTION=void 0,n.UNKNOWN_FUNCTION="?";var s=/\(error: (.*)\)/,l=/captureMessage|captureException/;function g(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];var t=n.sort((function(e,n){return e[0]-n[0]})).map((function(e){return e[1]}));return function(e){for(var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,a=[],o=e.split("\n"),i=n;i<o.length;i++){var u=o[i];if(!(u.length>1024)){var f=s.test(u)?u.replace(s,"$1"):u;if(!f.match(/\S*Error: /)){var l,g=c(t);try{for(g.s();!(l=g.n()).done;){var m=(0,l.value)(f);if(m){a.push(m);break}}}catch(e){g.e(e)}finally{g.f()}if(a.length>=50+r)break}}}return d(a.slice(r))}}function d(e){if(!e.length)return[];var r=Array.from(e);return/sentryWrapped/.test(m(r).function||"")&&r.pop(),r.reverse(),l.test(m(r).function||"")&&(r.pop(),l.test(m(r).function||"")&&r.pop()),r.slice(0,50).map((function(e){return a(a({},e),{},{filename:e.filename||m(r).filename,function:e.function||n.UNKNOWN_FUNCTION})}))}function m(e){return e[e.length-1]||{}}n.createStackParser=g,n.stackParserFromStackParserOptions=function(e){return Array.isArray(e)?g.apply(void 0,i(e)):e},n.stripSentryFramesAndReverse=d;var v="<anonymous>";n.getFunctionName=function(e){try{return e&&"function"==typeof e&&e.name||v}catch(e){return v}},n.getFramesFromEvent=function(e){var n=e.exception;if(n){var r=[];try{return n.values.forEach((function(e){e.stacktrace.frames&&r.push.apply(r,i(e.stacktrace.frames))})),r}catch(e){return}}}}},n={},r=function r(t){var a=n[t];if(void 0!==a)return a.exports;var o=n[t]={exports:{}};return e[t](o,o.exports,r),o.exports}(938);EventLogger=r.default}();
@@ -0,0 +1,248 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.eventFromConsoleErrorMessage = exports.logError = void 0;
4
+ const stack_parsers_1 = require("./stack-parsers");
5
+ /**
6
+ * for call instead of console.error(err)
7
+ * this method collect Error stack to error logger
8
+ **/
9
+ const logError = (e, cause) => {
10
+ let error = null;
11
+ if (e instanceof Error) {
12
+ error = e;
13
+ if (cause != null) {
14
+ error.cause = cause;
15
+ }
16
+ }
17
+ if (typeof e === "string") {
18
+ error = new Error(e);
19
+ }
20
+ if (error !== null) {
21
+ // will be handled via sdk console.error override
22
+ console.error((0, exports.eventFromConsoleErrorMessage)(e));
23
+ }
24
+ else {
25
+ console.error(e);
26
+ }
27
+ };
28
+ exports.logError = logError;
29
+ // eslint-disable-next-line @typescript-eslint/unbound-method
30
+ const objectToString = Object.prototype.toString;
31
+ /**
32
+ * Checks whether given value's type is an instance of provided constructor.
33
+ * {@link isInstanceOf}.
34
+ *
35
+ * @param wat A value to be checked.
36
+ * @param base A constructor to be used in a check.
37
+ * @returns A boolean representing the result.
38
+ */
39
+ function isInstanceOf(wat, base) {
40
+ try {
41
+ return wat instanceof base;
42
+ }
43
+ catch (_e) {
44
+ return false;
45
+ }
46
+ }
47
+ /**
48
+ * Checks whether given value's type is one of a few Error or Error-like
49
+ * {@link isError}.
50
+ *
51
+ * @param wat A value to be checked.
52
+ * @returns A boolean representing the result.
53
+ */
54
+ function isError(wat) {
55
+ switch (objectToString.call(wat)) {
56
+ case "[object Error]":
57
+ case "[object Exception]":
58
+ case "[object DOMException]":
59
+ case "[object WebAssembly.Exception]":
60
+ return true;
61
+ default:
62
+ return isInstanceOf(wat, Error);
63
+ }
64
+ }
65
+ /**
66
+ * Checks whether given value is an instance of the given built-in class.
67
+ *
68
+ * @param wat The value to be checked
69
+ * @param className
70
+ * @returns A boolean representing the result.
71
+ */
72
+ function isBuiltin(wat, className) {
73
+ return objectToString.call(wat) === `[object ${className}]`;
74
+ }
75
+ /**
76
+ * Checks whether given value's type is an object literal, or a class instance.
77
+ * {@link isPlainObject}.
78
+ *
79
+ * @param wat A value to be checked.
80
+ * @returns A boolean representing the result.
81
+ */
82
+ function isPlainObject(wat) {
83
+ return isBuiltin(wat, "Object");
84
+ }
85
+ function getException(exception) {
86
+ if (isError(exception)) {
87
+ return exception;
88
+ }
89
+ let message = "";
90
+ if (isPlainObject(exception)) {
91
+ try {
92
+ message = JSON.stringify(exception);
93
+ }
94
+ catch (e) {
95
+ // do nothing
96
+ }
97
+ }
98
+ else if (typeof exception === "string") {
99
+ message = exception;
100
+ }
101
+ else {
102
+ try {
103
+ message = JSON.stringify(exception);
104
+ }
105
+ catch (e) {
106
+ // do nothing
107
+ }
108
+ }
109
+ // This handles when someone does: `throw "something awesome";`
110
+ // We use synthesized Error here so we can extract a (rough) stack trace.
111
+ const ex = new Error(message);
112
+ ex.message = `${message}`;
113
+ return ex;
114
+ }
115
+ function flatErrorCause(error) {
116
+ const errors = [error];
117
+ const _getErrorOrErrorCause = (error) => {
118
+ if (isError(error.cause)) {
119
+ errors.push(error.cause);
120
+ return _getErrorOrErrorCause(error.cause);
121
+ }
122
+ return null;
123
+ };
124
+ _getErrorOrErrorCause(error);
125
+ return errors;
126
+ }
127
+ function exceptionFromError(stackParser, error) {
128
+ const exception = {
129
+ type: error.name || error.constructor.name,
130
+ value: error.message,
131
+ };
132
+ if (error.cause != null && typeof error.cause === "string") {
133
+ exception.cause = error.cause;
134
+ }
135
+ const frames = stackParser(error.stack || "", 0);
136
+ if (frames.length) {
137
+ exception.stacktrace = { frames };
138
+ }
139
+ return exception;
140
+ }
141
+ const eventFromException = (exception) => {
142
+ const event = {
143
+ level: "error",
144
+ source: "onerror",
145
+ exception: {
146
+ values: flatErrorCause(getException(exception)).map(error => exceptionFromError(stack_parsers_1.defaultStackParser, error)),
147
+ },
148
+ gameLoaded: false,
149
+ gameLaunchRawConfig: {},
150
+ gameSlug: "",
151
+ gameVersion: "",
152
+ sdkVersion: "",
153
+ env: "",
154
+ };
155
+ event.gameLoaded = window.gameLoadingInfo.loaded;
156
+ if (window.gameLoadingInfo.gameLaunchRawConfig != null) {
157
+ event.gameSlug = window.gameLoadingInfo.gameLaunchRawConfig.gameSlug;
158
+ event.gameVersion = window.gameLoadingInfo.gameLaunchRawConfig.gameVersion;
159
+ event.env = window.gameLoadingInfo.gameLaunchRawConfig.projectEnv;
160
+ event.sdkVersion = window.gameLoadingInfo.gameLaunchRawConfig.clientConfig?.sdkVersion;
161
+ event.gameLaunchRawConfig = window.gameLoadingInfo.gameLaunchRawConfig;
162
+ }
163
+ return event;
164
+ };
165
+ const eventFromConsoleErrorMessage = (exception) => {
166
+ const event = {
167
+ level: "error",
168
+ source: "consoleErrorMessage",
169
+ exception: {
170
+ values: flatErrorCause(getException(exception)).map(error => exceptionFromError(stack_parsers_1.defaultStackParser, error)),
171
+ },
172
+ gameLoaded: false,
173
+ gameLaunchRawConfig: {},
174
+ gameSlug: "",
175
+ gameVersion: "",
176
+ sdkVersion: "",
177
+ env: "",
178
+ };
179
+ event.gameLoaded = window.gameLoadingInfo.loaded;
180
+ if (window.gameLoadingInfo.gameLaunchRawConfig != null) {
181
+ event.gameSlug = window.gameLoadingInfo.gameLaunchRawConfig.gameSlug;
182
+ event.gameVersion = window.gameLoadingInfo.gameLaunchRawConfig.gameVersion;
183
+ event.env = window.gameLoadingInfo.gameLaunchRawConfig.projectEnv;
184
+ event.sdkVersion = window.gameLoadingInfo.gameLaunchRawConfig.clientConfig?.sdkVersion;
185
+ event.gameLaunchRawConfig = window.gameLoadingInfo.gameLaunchRawConfig;
186
+ }
187
+ return event;
188
+ };
189
+ exports.eventFromConsoleErrorMessage = eventFromConsoleErrorMessage;
190
+ const eventFromUnhandledRejection = (rawEvent) => {
191
+ let promiseErrors = [];
192
+ if (isError(rawEvent.reason)) {
193
+ promiseErrors = flatErrorCause(rawEvent.reason).map(error => exceptionFromError(stack_parsers_1.defaultStackParser, error));
194
+ }
195
+ let stringReason = "";
196
+ if (typeof rawEvent.reason === "string") {
197
+ stringReason = rawEvent.reason;
198
+ }
199
+ else {
200
+ try {
201
+ stringReason = JSON.stringify(rawEvent.reason);
202
+ }
203
+ catch (e) {
204
+ // do nothing
205
+ }
206
+ }
207
+ const promiseRejection = {
208
+ type: "PromiseRejection",
209
+ value: stringReason,
210
+ };
211
+ const creationPointStack = rawEvent.promise.creationPoint;
212
+ if (creationPointStack != null && typeof creationPointStack === "string") {
213
+ const frames = (0, stack_parsers_1.defaultStackParser)(creationPointStack || "", 0);
214
+ if (frames.length) {
215
+ promiseRejection.stacktrace = { frames };
216
+ }
217
+ }
218
+ const event = {
219
+ level: "error",
220
+ source: "onunhandledrejection",
221
+ exception: {
222
+ values: [...promiseErrors, promiseRejection].filter(Boolean),
223
+ },
224
+ gameLoaded: false,
225
+ gameLaunchRawConfig: {},
226
+ gameSlug: "",
227
+ gameVersion: "",
228
+ sdkVersion: "",
229
+ env: "",
230
+ };
231
+ if (window.gameLoadingInfo != null) {
232
+ event.gameLoaded = window.gameLoadingInfo.loaded;
233
+ if (window.gameLoadingInfo.gameLaunchRawConfig != null) {
234
+ event.gameSlug = window.gameLoadingInfo.gameLaunchRawConfig.gameSlug;
235
+ event.gameVersion = window.gameLoadingInfo.gameLaunchRawConfig.gameVersion;
236
+ event.env = window.gameLoadingInfo.gameLaunchRawConfig.projectEnv;
237
+ event.sdkVersion = window.gameLoadingInfo.gameLaunchRawConfig.clientConfig?.sdkVersion;
238
+ event.gameLaunchRawConfig = window.gameLoadingInfo.gameLaunchRawConfig;
239
+ }
240
+ }
241
+ return event;
242
+ };
243
+ const EventLogger = {
244
+ eventFromException,
245
+ eventFromConsoleErrorMessage: exports.eventFromConsoleErrorMessage,
246
+ eventFromUnhandledRejection,
247
+ };
248
+ exports.default = EventLogger;
@@ -0,0 +1,8 @@
1
+ import type { StackLineParser } from "@sentry/core";
2
+ export declare const chromeStackLineParser: StackLineParser;
3
+ export declare const geckoStackLineParser: StackLineParser;
4
+ export declare const winjsStackLineParser: StackLineParser;
5
+ export declare const opera10StackLineParser: StackLineParser;
6
+ export declare const opera11StackLineParser: StackLineParser;
7
+ export declare const defaultStackLineParsers: StackLineParser[];
8
+ export declare const defaultStackParser: import("@sentry/core").StackParser;
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ // This was originally forked from https://github.com/csnover/TraceKit, and was largely
3
+ // re - written as part of raven - js.
4
+ //
5
+ // This code was later copied to the JavaScript mono - repo and further modified and
6
+ // refactored over the years.
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.defaultStackParser = exports.defaultStackLineParsers = exports.opera11StackLineParser = exports.opera10StackLineParser = exports.winjsStackLineParser = exports.geckoStackLineParser = exports.chromeStackLineParser = void 0;
9
+ // Copyright (c) 2013 Onur Can Cakmak onur.cakmak@gmail.com and all TraceKit contributors.
10
+ //
11
+ // Permission is hereby granted, free of charge, to any person obtaining a copy of this
12
+ // software and associated documentation files(the 'Software'), to deal in the Software
13
+ // without restriction, including without limitation the rights to use, copy, modify,
14
+ // merge, publish, distribute, sublicense, and / or sell copies of the Software, and to
15
+ // permit persons to whom the Software is furnished to do so, subject to the following
16
+ // conditions:
17
+ //
18
+ // The above copyright notice and this permission notice shall be included in all copies
19
+ // or substantial portions of the Software.
20
+ //
21
+ // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ // PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ const stacktrace_1 = require("./stacktrace");
28
+ const OPERA10_PRIORITY = 10;
29
+ const OPERA11_PRIORITY = 20;
30
+ const CHROME_PRIORITY = 30;
31
+ const WINJS_PRIORITY = 40;
32
+ const GECKO_PRIORITY = 50;
33
+ function createFrame(filename, func, lineno, colno) {
34
+ const frame = {
35
+ filename,
36
+ function: func === "<anonymous>" ? stacktrace_1.UNKNOWN_FUNCTION : func,
37
+ in_app: true, // All browser frames are considered in_app
38
+ };
39
+ if (lineno !== undefined) {
40
+ frame.lineno = lineno;
41
+ }
42
+ if (colno !== undefined) {
43
+ frame.colno = colno;
44
+ }
45
+ return frame;
46
+ }
47
+ // This regex matches frames that have no function name (ie. are at the top level of a module).
48
+ // For example "at http://localhost:5000//script.js:1:126"
49
+ // Frames _with_ function names usually look as follows: "at commitLayoutEffects (react-dom.development.js:23426:1)"
50
+ const chromeRegexNoFnName = /^\s*at (\S+?)(?::(\d+))(?::(\d+))\s*$/i;
51
+ // This regex matches all the frames that have a function name.
52
+ const chromeRegex = /^\s*at (?:(.+?\)(?: \[.+\])?|.*?) ?\((?:address at )?)?(?:async )?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
53
+ const chromeEvalRegex = /\((\S*)(?::(\d+))(?::(\d+))\)/;
54
+ // Chromium based browsers: Chrome, Brave, new Opera, new Edge
55
+ // We cannot call this variable `chrome` because it can conflict with global `chrome` variable in certain environments
56
+ // See: https://github.com/getsentry/sentry-javascript/issues/6880
57
+ const chromeStackParserFn = line => {
58
+ // If the stack line has no function name, we need to parse it differently
59
+ const noFnParts = chromeRegexNoFnName.exec(line);
60
+ if (noFnParts) {
61
+ const [, filename, line, col] = noFnParts;
62
+ return createFrame(filename, stacktrace_1.UNKNOWN_FUNCTION, +line, +col);
63
+ }
64
+ const parts = chromeRegex.exec(line);
65
+ if (parts) {
66
+ const isEval = parts[2] && parts[2].indexOf("eval") === 0; // start of line
67
+ if (isEval) {
68
+ const subMatch = chromeEvalRegex.exec(parts[2]);
69
+ if (subMatch) {
70
+ // throw out eval line/column and use top-most line/column number
71
+ parts[2] = subMatch[1]; // url
72
+ parts[3] = subMatch[2]; // line
73
+ parts[4] = subMatch[3]; // column
74
+ }
75
+ }
76
+ // Kamil: One more hack won't hurt us right? Understanding and adding more rules on top of these regexps right now
77
+ // would be way too time consuming. (TODO: Rewrite whole RegExp to be more readable)
78
+ const [func, filename] = extractSafariExtensionDetails(parts[1] || stacktrace_1.UNKNOWN_FUNCTION, parts[2]);
79
+ return createFrame(filename, func, parts[3] ? +parts[3] : undefined, parts[4] ? +parts[4] : undefined);
80
+ }
81
+ return;
82
+ };
83
+ exports.chromeStackLineParser = [CHROME_PRIORITY, chromeStackParserFn];
84
+ // gecko regex: `(?:bundle|\d+\.js)`: `bundle` is for react native, `\d+\.js` also but specifically for ram bundles because it
85
+ // generates filenames without a prefix like `file://` the filenames in the stacktrace are just 42.js
86
+ // We need this specific case for now because we want no other regex to match.
87
+ const geckoREgex = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. /=]+)(?::(\d+))?(?::(\d+))?\s*$/i;
88
+ const geckoEvalRegex = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
89
+ const gecko = line => {
90
+ const parts = geckoREgex.exec(line);
91
+ if (parts) {
92
+ const isEval = parts[3] && parts[3].indexOf(" > eval") > -1;
93
+ if (isEval) {
94
+ const subMatch = geckoEvalRegex.exec(parts[3]);
95
+ if (subMatch) {
96
+ // throw out eval line/column and use top-most line number
97
+ parts[1] = parts[1] || "eval";
98
+ parts[3] = subMatch[1];
99
+ parts[4] = subMatch[2];
100
+ parts[5] = ""; // no column when eval
101
+ }
102
+ }
103
+ let filename = parts[3];
104
+ let func = parts[1] || stacktrace_1.UNKNOWN_FUNCTION;
105
+ [func, filename] = extractSafariExtensionDetails(func, filename);
106
+ return createFrame(filename, func, parts[4] ? +parts[4] : undefined, parts[5] ? +parts[5] : undefined);
107
+ }
108
+ return;
109
+ };
110
+ exports.geckoStackLineParser = [GECKO_PRIORITY, gecko];
111
+ const winjsRegex = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:[-a-z]+):.*?):(\d+)(?::(\d+))?\)?\s*$/i;
112
+ const winjs = line => {
113
+ const parts = winjsRegex.exec(line);
114
+ return parts ? createFrame(parts[2], parts[1] || stacktrace_1.UNKNOWN_FUNCTION, +parts[3], parts[4] ? +parts[4] : undefined) : undefined;
115
+ };
116
+ exports.winjsStackLineParser = [WINJS_PRIORITY, winjs];
117
+ const opera10Regex = / line (\d+).*script (?:in )?(\S+)(?:: in function (\S+))?$/i;
118
+ const opera10 = line => {
119
+ const parts = opera10Regex.exec(line);
120
+ return parts ? createFrame(parts[2], parts[3] || stacktrace_1.UNKNOWN_FUNCTION, +parts[1]) : undefined;
121
+ };
122
+ exports.opera10StackLineParser = [OPERA10_PRIORITY, opera10];
123
+ const opera11Regex = / line (\d+), column (\d+)\s*(?:in (?:<anonymous function: ([^>]+)>|([^)]+))\(.*\))? in (.*):\s*$/i;
124
+ const opera11 = line => {
125
+ const parts = opera11Regex.exec(line);
126
+ return parts ? createFrame(parts[5], parts[3] || parts[4] || stacktrace_1.UNKNOWN_FUNCTION, +parts[1], +parts[2]) : undefined;
127
+ };
128
+ exports.opera11StackLineParser = [OPERA11_PRIORITY, opera11];
129
+ exports.defaultStackLineParsers = [exports.chromeStackLineParser, exports.geckoStackLineParser];
130
+ exports.defaultStackParser = (0, stacktrace_1.createStackParser)(...exports.defaultStackLineParsers);
131
+ /**
132
+ * Safari web extensions, starting version unknown, can produce "frames-only" stacktraces.
133
+ * What it means, is that instead of format like:
134
+ *
135
+ * Error: wat
136
+ * at function@url:row:col
137
+ * at function@url:row:col
138
+ * at function@url:row:col
139
+ *
140
+ * it produces something like:
141
+ *
142
+ * function@url:row:col
143
+ * function@url:row:col
144
+ * function@url:row:col
145
+ *
146
+ * Because of that, it won't be captured by `chrome` RegExp and will fall into `Gecko` branch.
147
+ * This function is extracted so that we can use it in both places without duplicating the logic.
148
+ * Unfortunately "just" changing RegExp is too complicated now and making it pass all tests
149
+ * and fix this case seems like an impossible, or at least way too time-consuming task.
150
+ */
151
+ const extractSafariExtensionDetails = (func, filename) => {
152
+ const isSafariExtension = func.indexOf("safari-extension") !== -1;
153
+ const isSafariWebExtension = func.indexOf("safari-web-extension") !== -1;
154
+ return isSafariExtension || isSafariWebExtension
155
+ ? [
156
+ func.indexOf("@") !== -1 ? func.split("@")[0] : stacktrace_1.UNKNOWN_FUNCTION,
157
+ isSafariExtension ? `safari-extension:${filename}` : `safari-web-extension:${filename}`,
158
+ ]
159
+ : [func, filename];
160
+ };
@@ -0,0 +1,32 @@
1
+ import type { Event, StackFrame, StackLineParser, StackParser } from "@sentry/core";
2
+ export declare const UNKNOWN_FUNCTION = "?";
3
+ /**
4
+ * Creates a stack parser with the supplied line parsers
5
+ *
6
+ * StackFrames are returned in the correct order for Sentry Exception
7
+ * frames and with Sentry SDK internal frames removed from the top and bottom
8
+ *
9
+ */
10
+ export declare function createStackParser(...parsers: StackLineParser[]): StackParser;
11
+ /**
12
+ * Gets a stack parser implementation from Options.stackParser
13
+ * @see Options
14
+ *
15
+ * If options contains an array of line parsers, it is converted into a parser
16
+ */
17
+ export declare function stackParserFromStackParserOptions(stackParser: StackParser | StackLineParser[]): StackParser;
18
+ /**
19
+ * Removes Sentry frames from the top and bottom of the stack if present and enforces a limit of max number of frames.
20
+ * Assumes stack input is ordered from top to bottom and returns the reverse representation so call site of the
21
+ * function that caused the crash is the last frame in the array.
22
+ * @hidden
23
+ */
24
+ export declare function stripSentryFramesAndReverse(stack: ReadonlyArray<StackFrame>): StackFrame[];
25
+ /**
26
+ * Safely extract function name from itself
27
+ */
28
+ export declare function getFunctionName(fn: unknown): string;
29
+ /**
30
+ * Get's stack frames from an event without needing to check for undefined properties.
31
+ */
32
+ export declare function getFramesFromEvent(event: Event): StackFrame[] | undefined;