@inappstory/game-center-api 1.3.12 → 1.3.13

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.
package/lib/env.js CHANGED
@@ -2,6 +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
6
  const semver = require("semver");
6
7
  const isAndroid = Boolean(window.Android && window.Android.gameLoaded);
7
8
  exports.isAndroid = isAndroid;
@@ -28,7 +29,7 @@ const parseSdkVersion = () => {
28
29
  }
29
30
  }
30
31
  catch (e) {
31
- console.error(e);
32
+ (0, errorHandler_1.logError)(e);
32
33
  }
33
34
  };
34
35
  const getSdkVersion = () => {
@@ -0,0 +1 @@
1
+ export declare const logError: (e: unknown) => void;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logError = void 0;
4
+ const logError = (e) => {
5
+ const error = e;
6
+ const message = {
7
+ type: "error",
8
+ errorName: error.name ?? "",
9
+ message: error.message ?? "",
10
+ stack: error.stack ?? "",
11
+ cause: error.cause ?? "",
12
+ // @ts-ignore Non-standard: This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.
13
+ fileName: error.fileName ?? "",
14
+ // @ts-ignore Non-standard: This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.
15
+ lineNumber: error.lineNumber ?? "",
16
+ // @ts-ignore Non-standard: This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.
17
+ columnNumber: error.columnNumber ?? "",
18
+ };
19
+ // will be handled via sdk console.error override
20
+ console.error(message);
21
+ };
22
+ exports.logError = logError;
package/lib/index.d.ts CHANGED
@@ -16,6 +16,7 @@ import { eventGame } from "./sdkApi/events";
16
16
  import { ResourceManager } from "./ResourceManager";
17
17
  import { hasFilePickerApi, openFilePicker } from "./sdkApi/filePicker";
18
18
  import { FilePickerResultType, isFilePickerResultFileList, isFilePickerResultLocalFileList, isLocalFile } from "./sdkApi/filePicker.h";
19
+ import { logError } from "./errorHandler";
19
20
  export type { OpenFilePickerProps, SDKFileResponse, LocalFile, LocalFileList, FilePickerResultPayload, FilePickerResult } from "./sdkApi/filePicker.h";
20
21
  export type { PrimaryFontVariants as SDKPrimaryFontVariants, SecondaryFontVariants as SDKSecondaryFontVariants } from "./gameResources";
21
22
  export type { OpenUrlOptions as SDKOpenUrlOptions } from "./sdkApi/openUrl.h";
@@ -25,7 +26,7 @@ export type { ProjectFontFamily } from "./gameResources";
25
26
  export type { ResourceInterface } from "./ResourceManager";
26
27
  export type { OpenStoryOptions } from "./sdkApi/openStory.h";
27
28
  export type { OpenGameInstanceOptions } from "./sdkApi/openGameInstance.h";
28
- export { createSdkApi, closeGameReader, gameLoadedSdkCallback, gameLoadFailedSdkCallback, gameLaunchConfig, isIos, isWeb, isAndroid, isDev, getSdkVersion, getSemverSdkVersion, gameLocalData, sendIasApiRequest, openUrl, shareText, shareUrl, shareFiles, vibrate, getDynamicResourceAsset, getDynamicResourceFont, getProjectFontFamilyStylesheet, getIsDemoMode, getSessionId, getApiBaseUrl, ScreenOrientation, PlaceholderType, fetchLocalFile, openStory, ResourceManager, dynamicResourceAssets, dynamicResourceFonts, staticResourcesImagePlaceholders, StaticResourceList, eventGame, reloadGameReader, openFilePicker, FilePickerResultType, isFilePickerResultFileList, isFilePickerResultLocalFileList, isLocalFile, hasFilePickerApi, gameShouldForegroundCallback, gameOnForeground, getApplicationVersion, getApplicationBuildVersion, openGameInstance, };
29
+ export { createSdkApi, closeGameReader, gameLoadedSdkCallback, gameLoadFailedSdkCallback, gameLaunchConfig, isIos, isWeb, isAndroid, isDev, getSdkVersion, getSemverSdkVersion, gameLocalData, sendIasApiRequest, openUrl, shareText, shareUrl, shareFiles, vibrate, getDynamicResourceAsset, getDynamicResourceFont, getProjectFontFamilyStylesheet, getIsDemoMode, getSessionId, getApiBaseUrl, ScreenOrientation, PlaceholderType, fetchLocalFile, openStory, ResourceManager, dynamicResourceAssets, dynamicResourceFonts, staticResourcesImagePlaceholders, StaticResourceList, eventGame, reloadGameReader, openFilePicker, FilePickerResultType, isFilePickerResultFileList, isFilePickerResultLocalFileList, isLocalFile, hasFilePickerApi, gameShouldForegroundCallback, gameOnForeground, getApplicationVersion, getApplicationBuildVersion, openGameInstance, logError, };
29
30
  declare const GameCenterApi: {
30
31
  createSdkApi: ({ mounted, beforeUnmount: beforeUnmountCb, onSdkCloseGameReaderIntent, onPause, onResume, onBackGesture, onAudioFocusChange, filterPlaceholders, gameShouldForeground, }: Partial<{
31
32
  mounted: () => void;
@@ -90,5 +91,6 @@ declare const GameCenterApi: {
90
91
  getApplicationVersion: () => string | null;
91
92
  getApplicationBuildVersion: () => number | null;
92
93
  openGameInstance: (openGameInstance: import("./sdkApi/openGameInstance.h").OpenGameInstanceOptions) => void;
94
+ logError: (e: unknown) => void;
93
95
  };
94
96
  export { GameCenterApi as default };
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = exports.openGameInstance = exports.getApplicationBuildVersion = exports.getApplicationVersion = exports.gameOnForeground = exports.gameShouldForegroundCallback = exports.hasFilePickerApi = exports.isLocalFile = exports.isFilePickerResultLocalFileList = exports.isFilePickerResultFileList = exports.FilePickerResultType = exports.openFilePicker = exports.reloadGameReader = exports.eventGame = exports.StaticResourceList = exports.staticResourcesImagePlaceholders = exports.dynamicResourceFonts = exports.dynamicResourceAssets = exports.ResourceManager = exports.openStory = exports.fetchLocalFile = exports.PlaceholderType = exports.ScreenOrientation = exports.getApiBaseUrl = exports.getSessionId = exports.getIsDemoMode = exports.getProjectFontFamilyStylesheet = exports.getDynamicResourceFont = exports.getDynamicResourceAsset = exports.vibrate = exports.shareFiles = exports.shareUrl = exports.shareText = exports.openUrl = exports.sendIasApiRequest = exports.gameLocalData = exports.getSemverSdkVersion = exports.getSdkVersion = exports.isDev = exports.isAndroid = exports.isWeb = exports.isIos = exports.gameLaunchConfig = exports.gameLoadFailedSdkCallback = exports.gameLoadedSdkCallback = exports.closeGameReader = exports.createSdkApi = void 0;
3
+ exports.default = exports.logError = exports.openGameInstance = exports.getApplicationBuildVersion = exports.getApplicationVersion = exports.gameOnForeground = exports.gameShouldForegroundCallback = exports.hasFilePickerApi = exports.isLocalFile = exports.isFilePickerResultLocalFileList = exports.isFilePickerResultFileList = exports.FilePickerResultType = exports.openFilePicker = exports.reloadGameReader = exports.eventGame = exports.StaticResourceList = exports.staticResourcesImagePlaceholders = exports.dynamicResourceFonts = exports.dynamicResourceAssets = exports.ResourceManager = exports.openStory = exports.fetchLocalFile = exports.PlaceholderType = exports.ScreenOrientation = exports.getApiBaseUrl = exports.getSessionId = exports.getIsDemoMode = exports.getProjectFontFamilyStylesheet = exports.getDynamicResourceFont = exports.getDynamicResourceAsset = exports.vibrate = exports.shareFiles = exports.shareUrl = exports.shareText = exports.openUrl = exports.sendIasApiRequest = exports.gameLocalData = exports.getSemverSdkVersion = exports.getSdkVersion = exports.isDev = exports.isAndroid = exports.isWeb = exports.isIos = exports.gameLaunchConfig = exports.gameLoadFailedSdkCallback = exports.gameLoadedSdkCallback = exports.closeGameReader = exports.createSdkApi = void 0;
4
4
  const env_1 = require("./env");
5
5
  Object.defineProperty(exports, "getApplicationBuildVersion", { enumerable: true, get: function () { return env_1.getApplicationBuildVersion; } });
6
6
  Object.defineProperty(exports, "getApplicationVersion", { enumerable: true, get: function () { return env_1.getApplicationVersion; } });
@@ -65,6 +65,8 @@ Object.defineProperty(exports, "FilePickerResultType", { enumerable: true, get:
65
65
  Object.defineProperty(exports, "isFilePickerResultFileList", { enumerable: true, get: function () { return filePicker_h_1.isFilePickerResultFileList; } });
66
66
  Object.defineProperty(exports, "isFilePickerResultLocalFileList", { enumerable: true, get: function () { return filePicker_h_1.isFilePickerResultLocalFileList; } });
67
67
  Object.defineProperty(exports, "isLocalFile", { enumerable: true, get: function () { return filePicker_h_1.isLocalFile; } });
68
+ const errorHandler_1 = require("./errorHandler");
69
+ Object.defineProperty(exports, "logError", { enumerable: true, get: function () { return errorHandler_1.logError; } });
68
70
  const GameCenterApi = {
69
71
  createSdkApi: sdkApi_1.createSdkApi,
70
72
  closeGameReader: sdkApi_1.closeGameReader,
@@ -112,6 +114,7 @@ const GameCenterApi = {
112
114
  getApplicationVersion: env_1.getApplicationVersion,
113
115
  getApplicationBuildVersion: env_1.getApplicationBuildVersion,
114
116
  openGameInstance: openGameInstance_1.openGameInstance,
117
+ logError: errorHandler_1.logError,
115
118
  };
116
119
  exports.default = GameCenterApi;
117
120
  // export { Placeholder as default};
package/lib/localData.js CHANGED
@@ -7,6 +7,7 @@ const asyncQueue_1 = require("./asyncQueue");
7
7
  const gameLaunchConfig_1 = require("./gameLaunchConfig");
8
8
  const Source_1 = require("./sdkApi/web/Source");
9
9
  const iasApi_1 = require("./iasApi");
10
+ const errorHandler_1 = require("./errorHandler");
10
11
  class LocalDataMap extends Map {
11
12
  set(key, value) {
12
13
  super.set(key, value);
@@ -61,7 +62,7 @@ const getClientLocalData = async () => {
61
62
  console.log(`call getGameInstanceLocalData with gameInstanceId: ${gameInstanceId}`);
62
63
  if (gameInstanceId == null) {
63
64
  // Prevent call with incorrect storyId
64
- console.error("Call getGameInstanceLocalData with empty `gameInstanceId`");
65
+ (0, errorHandler_1.logError)(new Error("Call getGameInstanceLocalData with empty `gameInstanceId`"));
65
66
  return {};
66
67
  }
67
68
  if (env_1.isAndroid) {
@@ -115,7 +116,8 @@ window.gameInstanceGetLocalDataCb = function (id, plainData) {
115
116
  localData = JSON.parse(plainData);
116
117
  }
117
118
  catch (e) {
118
- console.error(e, { inputData: plainData });
119
+ e.cause = { inputData: plainData };
120
+ (0, errorHandler_1.logError)(e);
119
121
  }
120
122
  finally {
121
123
  if (asyncQueue_1.asyncQueue.has(id)) {
@@ -132,7 +134,7 @@ const setGameLocalData = async (sendToServer = true) => {
132
134
  const gameInstanceId = (0, gameLaunchConfig_1.getGameInstanceId)();
133
135
  if (gameInstanceId == null) {
134
136
  // Prevent call with incorrect storyId
135
- console.error("Call getGameInstanceLocalData with empty `gameInstanceId`");
137
+ (0, errorHandler_1.logError)(new Error("Call getGameInstanceLocalData with empty `gameInstanceId`"));
136
138
  return;
137
139
  }
138
140
  if (process.env.NODE_ENV === "development") {
package/lib/logger.html CHANGED
@@ -160,7 +160,9 @@
160
160
  // https://stackoverflow.com/questions/45844565/script-error-errors-in-window-onerror-in-safari-only
161
161
  return false;
162
162
  }
163
- window._sendErrorLog(payload);
163
+ // window._sendErrorLog(payload);
164
+ // log via sdk logger and internal _sendErrorLog
165
+ console.error(payload);
164
166
 
165
167
  return false;
166
168
  };
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetchLocalFile = void 0;
4
4
  const env_1 = require("../env");
5
+ const errorHandler_1 = require("../errorHandler");
5
6
  const semver = require("semver");
6
7
  let instance;
7
8
  class URLResolver {
@@ -63,7 +64,7 @@ function fetchLocalFile(url, remoteUrl) {
63
64
  resolve(new Response(xhr.response, { status: xhr.status >= 200 && xhr.status <= 599 ? xhr.status : 200 }));
64
65
  }
65
66
  catch (e) {
66
- console.error(e);
67
+ (0, errorHandler_1.logError)(e);
67
68
  reject(e);
68
69
  }
69
70
  };
@@ -9,6 +9,7 @@ const isFunction_1 = require("../helpers/isFunction");
9
9
  const isObject_1 = require("../helpers/isObject");
10
10
  const gameLaunchConfig_1 = require("../gameLaunchConfig");
11
11
  const asyncQueue_1 = require("../asyncQueue");
12
+ const errorHandler_1 = require("../errorHandler");
12
13
  let beforeUnmount;
13
14
  const createSdkApi = ({ mounted, beforeUnmount: beforeUnmountCb, onSdkCloseGameReaderIntent, onPause, onResume, onBackGesture, onAudioFocusChange, filterPlaceholders, gameShouldForeground, }) => {
14
15
  beforeUnmount = beforeUnmountCb;
@@ -50,7 +51,8 @@ const createSdkApi = ({ mounted, beforeUnmount: beforeUnmountCb, onSdkCloseGameR
50
51
  }
51
52
  }
52
53
  catch (e) {
53
- console.error(e, { inputData: payload });
54
+ e.cause = { inputData: payload };
55
+ (0, errorHandler_1.logError)(e);
54
56
  }
55
57
  };
56
58
  // create bridge for web-sdk
@@ -116,7 +118,7 @@ const createSdkApi = ({ mounted, beforeUnmount: beforeUnmountCb, onSdkCloseGameR
116
118
  }
117
119
  }
118
120
  catch (e) {
119
- console.error(e);
121
+ (0, errorHandler_1.logError)(e);
120
122
  }
121
123
  }
122
124
  }
@@ -6,6 +6,7 @@ const gameLaunchConfig_1 = require("../gameLaunchConfig");
6
6
  const env_1 = require("../env");
7
7
  const Source_1 = require("./web/Source");
8
8
  const createNonce_1 = require("../createNonce");
9
+ const errorHandler_1 = require("../errorHandler");
9
10
  const semver = require("semver");
10
11
  const _gameLoadingInfo = {
11
12
  loadStarted: false,
@@ -35,13 +36,8 @@ const gameReader = (function () {
35
36
  window.gameLoadingInfo.description = "index: " + i;
36
37
  }
37
38
  catch (e) {
38
- window._sendErrorLog &&
39
- window._sendErrorLog({
40
- src: "gameReaderInit queue",
41
- message: e.message,
42
- stack: e.stack,
43
- });
44
- console.error(e);
39
+ e.cause = { src: "gameReaderInit queue" };
40
+ (0, errorHandler_1.logError)(e);
45
41
  }
46
42
  };
47
43
  })(self._e[i], i));
@@ -66,13 +62,8 @@ const gameReader = (function () {
66
62
  window.gameLoadingInfo.description = "index: " + i;
67
63
  }
68
64
  catch (e) {
69
- window._sendErrorLog &&
70
- window._sendErrorLog({
71
- src: "gameReaderInit sessionStorage queue",
72
- message: e.message,
73
- stack: e.stack,
74
- });
75
- console.error(e);
65
+ e.cause = { src: "gameReaderInit sessionStorage queue" };
66
+ (0, errorHandler_1.logError)(e);
76
67
  }
77
68
  };
78
69
  })(_initQueue[i], i));
@@ -81,7 +72,7 @@ const gameReader = (function () {
81
72
  window.sessionStorage.removeItem("_initQueue");
82
73
  }
83
74
  catch (e) {
84
- console.error(e);
75
+ (0, errorHandler_1.logError)(e);
85
76
  }
86
77
  }
87
78
  self.ready = function (cb) {
@@ -94,13 +85,8 @@ const gameReader = (function () {
94
85
  window.gameLoadingInfo.description = "";
95
86
  }
96
87
  catch (e) {
97
- window._sendErrorLog &&
98
- window._sendErrorLog({
99
- src: "gameReaderInit ready",
100
- message: e.message,
101
- stack: e.stack,
102
- });
103
- console.error(e);
88
+ e.cause = { src: "gameReaderInit ready" };
89
+ (0, errorHandler_1.logError)(e);
104
90
  }
105
91
  });
106
92
  };
@@ -115,7 +101,7 @@ const createInitGame = (initLocalData, mounted = () => { }) => {
115
101
  window.gameLoadingInfo.state = "before call initGame";
116
102
  window.gameLoadingInfo.description = JSON.stringify(config);
117
103
  if (!(0, isObject_1.isObject)(config)) {
118
- console.error("Invalid gameConfig");
104
+ (0, errorHandler_1.logError)(new Error("Invalid gameConfig"));
119
105
  return;
120
106
  }
121
107
  // dto -> model
@@ -138,13 +124,8 @@ const createInitGame = (initLocalData, mounted = () => { }) => {
138
124
  window.gameLoadingInfo.description = JSON.stringify(config);
139
125
  }
140
126
  catch (e) {
141
- window._sendErrorLog &&
142
- window._sendErrorLog({
143
- src: "initGame",
144
- message: e.message,
145
- stack: e.stack,
146
- });
147
- console.error(e);
127
+ e.cause = { src: "initGame" };
128
+ (0, errorHandler_1.logError)(e);
148
129
  }
149
130
  };
150
131
  };
@@ -221,13 +202,8 @@ const gameLoadedSdkCallbackInternal = (config) => {
221
202
  }
222
203
  }
223
204
  catch (e) {
224
- window._sendErrorLog &&
225
- window._sendErrorLog({
226
- src: "gameLoadedSdkCallback",
227
- message: e.message,
228
- stack: e.stack,
229
- });
230
- console.error(e);
205
+ e.cause = { src: "gameLoadedSdkCallback" };
206
+ (0, errorHandler_1.logError)(e);
231
207
  }
232
208
  };
233
209
  const _gameLoadingInfoCreated = {
@@ -5,6 +5,7 @@ const uuid_1 = require("uuid");
5
5
  const asyncQueue_1 = require("../asyncQueue");
6
6
  const env_1 = require("../env");
7
7
  const Source_1 = require("./web/Source");
8
+ const errorHandler_1 = require("../errorHandler");
8
9
  const shareText = (text) => share({ text });
9
10
  exports.shareText = shareText;
10
11
  const shareUrl = (url) => share({ url });
@@ -50,6 +51,7 @@ window.share_complete = function (requestId, isSuccess) {
50
51
  }
51
52
  }
52
53
  catch (e) {
53
- console.error(e, { inputData: { requestId, isSuccess } });
54
+ e.cause = { inputData: { requestId, isSuccess } };
55
+ (0, errorHandler_1.logError)(e);
54
56
  }
55
57
  };
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.vibrate = void 0;
4
4
  const env_1 = require("../env");
5
+ const errorHandler_1 = require("../errorHandler");
5
6
  /**
6
7
  * https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API
7
8
  * accept 200 | [200, 100, 200] | null | 0, [0]
@@ -55,7 +56,7 @@ const vibrate = (duration, fallbackStyle) => {
55
56
  window.Android.vibrate(patternResult);
56
57
  }
57
58
  catch (e) {
58
- console.error(e);
59
+ (0, errorHandler_1.logError)(e);
59
60
  }
60
61
  }
61
62
  else {
@@ -63,7 +64,7 @@ const vibrate = (duration, fallbackStyle) => {
63
64
  navigator.vibrate(patternResult);
64
65
  }
65
66
  catch (e) {
66
- console.error(e);
67
+ (0, errorHandler_1.logError)(e);
67
68
  }
68
69
  }
69
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inappstory/game-center-api",
3
- "version": "1.3.12",
3
+ "version": "1.3.13",
4
4
  "description": "",
5
5
  "dependencies": {
6
6
  "semver": "^7.3.8",