@inappstory/game-center-api 1.2.2 → 1.3.0

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/README.md CHANGED
@@ -40,22 +40,13 @@ createSdkApi({
40
40
 
41
41
  ```tsx
42
42
  const gameLoaded = () => {
43
- if (GameCenterApi.isSdkSupportGameShouldForegroundCallback()) {
44
- GameCenterApi.gameLoadedSdkCallback();
45
- } else {
46
- // fallback for old sdk versions
47
- gameShouldForeground();
48
- }
43
+ GameCenterApi.gameLoadedSdkCallback();
49
44
  };
50
45
 
51
46
  const gameStarted = () => {
52
47
  setTimeout(() => {
53
48
  // Wait for render complete - then remove native loader screen
54
- if (GameCenterApi.isSdkSupportGameShouldForegroundCallback()) {
55
- GameCenterApi.gameShouldForegroundCallback();
56
- } else {
57
- GameCenterApi.gameLoadedSdkCallback();
58
- }
49
+ GameCenterApi.gameShouldForegroundCallback();
59
50
  }, 50);
60
51
  };
61
52
 
@@ -108,3 +99,21 @@ import GameCenterApi from "@inappstory/game-center-api";
108
99
 
109
100
  const closeGame = () => GameCenterApi.closeGameReader();
110
101
  ```
102
+
103
+ ## Get Application version
104
+
105
+ ```ts
106
+ import GameCenterApi from "@inappstory/game-center-api";
107
+
108
+ // 1.2.3
109
+ const version: string | null = GameCenterApi.getApplicationVersion();
110
+ ```
111
+
112
+ ## Get Application build version
113
+
114
+ ```ts
115
+ import GameCenterApi from "@inappstory/game-center-api";
116
+
117
+ // 300
118
+ const version: number | null = GameCenterApi.getApplicationBuildVersion();
119
+ ```
package/lib/env.d.ts CHANGED
@@ -14,4 +14,12 @@ declare let iosMh: Record<string, any>;
14
14
  declare const isDev: boolean;
15
15
  declare const getSdkVersion: () => string | false | null;
16
16
  declare const getSemverSdkVersion: () => false | SemVer | null;
17
- export { isIos, isWeb, isAndroid, iosMh, isDev, getSdkVersion, getSemverSdkVersion };
17
+ /**
18
+ * Get host application build version
19
+ */
20
+ declare const getApplicationBuildVersion: () => number | null;
21
+ /**
22
+ * Get host application sem version
23
+ */
24
+ declare const getApplicationVersion: () => string | null;
25
+ export { isIos, isWeb, isAndroid, iosMh, isDev, getSdkVersion, getSemverSdkVersion, getApplicationBuildVersion, getApplicationVersion };
package/lib/env.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSemverSdkVersion = exports.getSdkVersion = exports.isDev = exports.iosMh = exports.isAndroid = exports.isWeb = exports.isIos = void 0;
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
5
  const semver = require("semver");
6
6
  const isAndroid = Boolean(window.Android && window.Android.gameLoaded);
@@ -45,3 +45,36 @@ const getSemverSdkVersion = () => {
45
45
  return semverSdkVersion;
46
46
  };
47
47
  exports.getSemverSdkVersion = getSemverSdkVersion;
48
+ /**
49
+ * For match app build version and app sem version from user agent
50
+ * InAppStorySDK/750 Dalvik/2.1.0 (Linux; U; Android 11; XQ-AT51 Build/58.1.A.5.530) Application/258 (com.inappstory.android 3.1.0)
51
+ */
52
+ const appVersionFromUserAgentRegexp = /.*Application\/(\d+)\s\([a-zA-Z.]+\s([0-9.]+)\)/;
53
+ /**
54
+ * Get host application build version
55
+ */
56
+ const getApplicationBuildVersion = () => {
57
+ const userAgent = gameLaunchConfig_1.gameLaunchConfig.clientConfig.userAgent;
58
+ if (userAgent) {
59
+ const match = userAgent.match(appVersionFromUserAgentRegexp);
60
+ if (match && match[1]) {
61
+ return parseInt(match[1]);
62
+ }
63
+ }
64
+ return null;
65
+ };
66
+ exports.getApplicationBuildVersion = getApplicationBuildVersion;
67
+ /**
68
+ * Get host application sem version
69
+ */
70
+ const getApplicationVersion = () => {
71
+ const userAgent = gameLaunchConfig_1.gameLaunchConfig.clientConfig.userAgent;
72
+ if (userAgent) {
73
+ const match = userAgent.match(appVersionFromUserAgentRegexp);
74
+ if (match && match[2]) {
75
+ return match[2];
76
+ }
77
+ }
78
+ return null;
79
+ };
80
+ exports.getApplicationVersion = getApplicationVersion;
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { getSdkVersion, getSemverSdkVersion, isAndroid, isDev, isIos, isWeb } from "./env";
1
+ import { getApplicationBuildVersion, getApplicationVersion, getSdkVersion, getSemverSdkVersion, isAndroid, isDev, isIos, isWeb } from "./env";
2
2
  import { gameLaunchConfig, getIsDemoMode, getSessionId, getApiBaseUrl } from "./gameLaunchConfig";
3
3
  import { getDynamicResourceAsset, getDynamicResourceFont, getProjectFontFamilyStylesheet, dynamicResourceAssets, dynamicResourceFonts, staticResourcesImagePlaceholders, StaticResourceList } from "./gameResources";
4
4
  import { sendIasApiRequest } from "./iasApi";
@@ -6,7 +6,7 @@ import { gameLocalData } from "./localData";
6
6
  import { closeGameReader, createSdkApi, reloadGameReader } from "./sdkApi";
7
7
  import { gameLoadedSdkCallback, gameLoadFailedSdkCallback, gameShouldForegroundCallback, gameOnForeground } from "./sdkApi/initGame";
8
8
  import { openUrl } from "./sdkApi/openUrl";
9
- import { share } from "./sdkApi/share";
9
+ import { shareText, shareUrl, shareFiles } from "./sdkApi/share";
10
10
  import { vibrate } from "./sdkApi/vibrate";
11
11
  import { ScreenOrientation, Placeholder, PlaceholderType, GameLaunchConfig } from "./gameLaunchConfig.h";
12
12
  import { fetchLocalFile } from "./sdkApi/fetchLocalFile";
@@ -16,14 +16,13 @@ import { ResourceManager } from "./ResourceManager";
16
16
  import { hasFilePickerApi, openFilePicker } from "./sdkApi/filePicker";
17
17
  import { FilePickerResultType, isFilePickerResultFileList, isFilePickerResultLocalFileList, isLocalFile } from "./sdkApi/filePicker.h";
18
18
  export type { OpenFilePickerProps, SDKFileResponse, LocalFile, LocalFileList, FilePickerResultPayload, FilePickerResult } from "./sdkApi/filePicker.h";
19
- export type { ShareData as SDKShareData } from "./sdkApi/share";
20
19
  export type { PrimaryFontVariants as SDKPrimaryFontVariants, SecondaryFontVariants as SDKSecondaryFontVariants } from "./gameResources";
21
20
  export type { OpenUrlOptions as SDKOpenUrlOptions } from "./sdkApi/openUrl.h";
22
21
  export type { RequestInfo as APIRequestInfo, Response as APIResponse } from "./iasApi";
23
22
  export type { Placeholder, GameLaunchConfig };
24
23
  export type { ProjectFontFamily } from "./gameResources";
25
24
  export type { ResourceInterface } from "./ResourceManager";
26
- export { createSdkApi, closeGameReader, gameLoadedSdkCallback, gameLoadFailedSdkCallback, gameLaunchConfig, isIos, isWeb, isAndroid, isDev, getSdkVersion, getSemverSdkVersion, gameLocalData, sendIasApiRequest, openUrl, share, 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, };
25
+ 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, };
27
26
  declare const GameCenterApi: {
28
27
  createSdkApi: ({ mounted, beforeUnmount: beforeUnmountCb, onSdkCloseGameReaderIntent, onPause, onResume, onBackGesture, onAudioFocusChange, filterPlaceholders, gameShouldForeground, }: Partial<{
29
28
  mounted: () => void;
@@ -49,16 +48,13 @@ declare const GameCenterApi: {
49
48
  gameLocalData: import("./localData").LocalDataMap<string, any>;
50
49
  sendIasApiRequest: typeof sendIasApiRequest;
51
50
  openUrl: ({ url, closeGameReader }: import("./sdkApi/openUrl.h").OpenUrlOptions) => void;
52
- share: (config: Partial<{
53
- title: string | null;
54
- text: string | null;
55
- url: string | null;
56
- files: ({
57
- file: string;
58
- name: string;
59
- type: string;
60
- } | null)[];
61
- }>) => Promise<boolean>;
51
+ shareText: (text: string) => Promise<boolean>;
52
+ shareUrl: (url: string) => Promise<boolean>;
53
+ shareFiles: (files: {
54
+ file: string;
55
+ name: string;
56
+ type: string;
57
+ }[]) => Promise<boolean>;
62
58
  vibrate: (duration: number | number[] | null, fallbackStyle?: "impactLight" | "impactMedium" | "impactHeavy" | "selection" | "notificationSuccess" | "notificationWarning" | "notificationError" | undefined) => void;
63
59
  getDynamicResourceAsset: (key: string, defaultValue: any) => any;
64
60
  getDynamicResourceFont: (key: import("./gameResources").PrimaryFontVariants | import("./gameResources").SecondaryFontVariants) => string | null;
@@ -88,5 +84,7 @@ declare const GameCenterApi: {
88
84
  backGesture: boolean;
89
85
  }>> | undefined) => void;
90
86
  gameOnForeground: Promise<void>;
87
+ getApplicationVersion: () => string | null;
88
+ getApplicationBuildVersion: () => number | null;
91
89
  };
92
90
  export { GameCenterApi as default };
package/lib/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = 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.share = 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.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
+ Object.defineProperty(exports, "getApplicationBuildVersion", { enumerable: true, get: function () { return env_1.getApplicationBuildVersion; } });
6
+ Object.defineProperty(exports, "getApplicationVersion", { enumerable: true, get: function () { return env_1.getApplicationVersion; } });
5
7
  Object.defineProperty(exports, "getSdkVersion", { enumerable: true, get: function () { return env_1.getSdkVersion; } });
6
8
  Object.defineProperty(exports, "getSemverSdkVersion", { enumerable: true, get: function () { return env_1.getSemverSdkVersion; } });
7
9
  Object.defineProperty(exports, "isAndroid", { enumerable: true, get: function () { return env_1.isAndroid; } });
@@ -37,7 +39,9 @@ Object.defineProperty(exports, "gameOnForeground", { enumerable: true, get: func
37
39
  const openUrl_1 = require("./sdkApi/openUrl");
38
40
  Object.defineProperty(exports, "openUrl", { enumerable: true, get: function () { return openUrl_1.openUrl; } });
39
41
  const share_1 = require("./sdkApi/share");
40
- Object.defineProperty(exports, "share", { enumerable: true, get: function () { return share_1.share; } });
42
+ Object.defineProperty(exports, "shareText", { enumerable: true, get: function () { return share_1.shareText; } });
43
+ Object.defineProperty(exports, "shareUrl", { enumerable: true, get: function () { return share_1.shareUrl; } });
44
+ Object.defineProperty(exports, "shareFiles", { enumerable: true, get: function () { return share_1.shareFiles; } });
41
45
  const vibrate_1 = require("./sdkApi/vibrate");
42
46
  Object.defineProperty(exports, "vibrate", { enumerable: true, get: function () { return vibrate_1.vibrate; } });
43
47
  const gameLaunchConfig_h_1 = require("./gameLaunchConfig.h");
@@ -74,7 +78,9 @@ const GameCenterApi = {
74
78
  gameLocalData: localData_1.gameLocalData,
75
79
  sendIasApiRequest: iasApi_1.sendIasApiRequest,
76
80
  openUrl: openUrl_1.openUrl,
77
- share: share_1.share,
81
+ shareText: share_1.shareText,
82
+ shareUrl: share_1.shareUrl,
83
+ shareFiles: share_1.shareFiles,
78
84
  vibrate: vibrate_1.vibrate,
79
85
  getDynamicResourceAsset: gameResources_1.getDynamicResourceAsset,
80
86
  getDynamicResourceFont: gameResources_1.getDynamicResourceFont,
@@ -101,6 +107,8 @@ const GameCenterApi = {
101
107
  hasFilePickerApi: filePicker_1.hasFilePickerApi,
102
108
  gameShouldForegroundCallback: initGame_1.gameShouldForegroundCallback,
103
109
  gameOnForeground: initGame_1.gameOnForeground,
110
+ getApplicationVersion: env_1.getApplicationVersion,
111
+ getApplicationBuildVersion: env_1.getApplicationBuildVersion,
104
112
  };
105
113
  exports.default = GameCenterApi;
106
114
  // export { Placeholder as default};
@@ -1,16 +1,12 @@
1
- export type ShareData = Partial<{
2
- title: string | null;
3
- text: string | null;
4
- url: string | null;
5
- files: Array<{
6
- file: string;
7
- name: string;
8
- type: string;
9
- } | null>;
10
- }>;
11
1
  declare global {
12
2
  interface Window {
13
3
  share_complete: (requestId: string, isSuccess: boolean) => void;
14
4
  }
15
5
  }
16
- export declare const share: (config: ShareData) => Promise<boolean>;
6
+ export declare const shareText: (text: string) => Promise<boolean>;
7
+ export declare const shareUrl: (url: string) => Promise<boolean>;
8
+ export declare const shareFiles: (files: Array<{
9
+ file: string;
10
+ name: string;
11
+ type: string;
12
+ }>) => Promise<boolean>;
@@ -1,11 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.share = void 0;
3
+ exports.shareFiles = exports.shareUrl = exports.shareText = void 0;
4
4
  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 share = async (config) => {
8
+ const shareText = (text) => share({ text });
9
+ exports.shareText = shareText;
10
+ const shareUrl = (url) => share({ url });
11
+ exports.shareUrl = shareUrl;
12
+ const shareFiles = (files) => share({ files });
13
+ exports.shareFiles = shareFiles;
14
+ const share = (config) => {
9
15
  return new Promise((resolve, reject) => {
10
16
  const id = (0, uuid_1.v4)();
11
17
  asyncQueue_1.asyncQueue.set(id, (plainData) => {
@@ -35,7 +41,6 @@ const share = async (config) => {
35
41
  }
36
42
  });
37
43
  };
38
- exports.share = share;
39
44
  window.share_complete = function (requestId, isSuccess) {
40
45
  try {
41
46
  if (asyncQueue_1.asyncQueue.has(requestId)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inappstory/game-center-api",
3
- "version": "1.2.2",
3
+ "version": "1.3.0",
4
4
  "description": "",
5
5
  "dependencies": {
6
6
  "semver": "^7.3.8",