@apps-in-toss/native-modules 1.14.0 → 2.0.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.
Files changed (80) hide show
  1. package/dist/bridges-meta.json +11 -7
  2. package/dist/index.cjs +201 -219
  3. package/dist/index.d.cts +1479 -1446
  4. package/dist/index.d.ts +1479 -1446
  5. package/dist/index.js +173 -192
  6. package/package.json +10 -8
  7. package/src/BedrockModule/native-modules/index.ts +0 -2
  8. package/src/BedrockModule/native-modules/natives/BedrockModule.ts +8 -18
  9. package/src/BedrockModule/native-modules/natives/closeView.ts +2 -2
  10. package/src/BedrockModule/native-modules/natives/generateHapticFeedback/index.ts +2 -2
  11. package/src/BedrockModule/native-modules/natives/getLocale.ts +2 -2
  12. package/src/BedrockModule/native-modules/natives/getNetworkStatus/index.ts +2 -2
  13. package/src/BedrockModule/native-modules/natives/getSchemeUri.ts +2 -2
  14. package/src/BedrockModule/native-modules/natives/setIosSwipeGestureEnabled.ts +3 -3
  15. package/src/BedrockModule/native-modules/natives/setScreenAwakeMode.ts +2 -2
  16. package/src/BedrockModule/native-modules/natives/setSecureScreen.ts +2 -2
  17. package/src/BedrockModule/native-modules/natives/share.ts +2 -2
  18. package/src/CommonModule.brick.ts +36 -0
  19. package/src/{AppsInTossModule → MiniAppModule}/native-event-emitter/event-plugins/UpdateLocationEvent.ts +9 -6
  20. package/src/{AppsInTossModule → MiniAppModule}/native-event-emitter/internal/AppBridgeCallbackEvent.ts +8 -9
  21. package/src/{AppsInTossModule → MiniAppModule}/native-event-emitter/internal/VisibilityChangedByTransparentServiceWebEvent.ts +13 -12
  22. package/src/{AppsInTossModule → MiniAppModule}/native-event-emitter/internal/appBridge.spec.ts +5 -5
  23. package/src/{AppsInTossModule → MiniAppModule}/native-event-emitter/internal/appBridge.ts +4 -12
  24. package/src/MiniAppModule/native-modules/ads/types.ts +179 -0
  25. package/src/{AppsInTossModule → MiniAppModule}/native-modules/appLogin.ts +2 -2
  26. package/src/{AppsInTossModule → MiniAppModule}/native-modules/appsInTossSignTossCert.ts +6 -18
  27. package/src/{AppsInTossModule → MiniAppModule}/native-modules/checkoutPayment.ts +3 -3
  28. package/src/{AppsInTossModule → MiniAppModule}/native-modules/eventLog.ts +3 -3
  29. package/src/{AppsInTossModule → MiniAppModule}/native-modules/getDeviceId.ts +2 -2
  30. package/src/{AppsInTossModule → MiniAppModule}/native-modules/getGameCenterGameProfile.ts +2 -2
  31. package/src/MiniAppModule/native-modules/getGroupId.ts +20 -0
  32. package/src/{AppsInTossModule → MiniAppModule}/native-modules/getIsTossLoginIntegratedService.ts +2 -2
  33. package/src/{AppsInTossModule → MiniAppModule}/native-modules/getOperationalEnvironment.ts +2 -2
  34. package/src/{AppsInTossModule → MiniAppModule}/native-modules/getPermission.ts +2 -2
  35. package/src/{AppsInTossModule → MiniAppModule}/native-modules/getServerTime.ts +2 -2
  36. package/src/{AppsInTossModule → MiniAppModule}/native-modules/getTossAppVersion.ts +2 -2
  37. package/src/MiniAppModule/native-modules/getTossShareLink.ts +39 -0
  38. package/src/{AppsInTossModule → MiniAppModule}/native-modules/getUserKeyForGame.ts +2 -2
  39. package/src/{AppsInTossModule → MiniAppModule}/native-modules/grantPromotionRewardForGame.ts +10 -6
  40. package/src/{AppsInTossModule → MiniAppModule}/native-modules/iap.ts +11 -12
  41. package/src/{AppsInTossModule → MiniAppModule}/native-modules/index.ts +5 -3
  42. package/src/{AppsInTossModule → MiniAppModule}/native-modules/isMinVersionSupported.ts +3 -3
  43. package/src/{AppsInTossModule → MiniAppModule}/native-modules/permissions/fetchAlbumPhotos/fetchAlbumPhotos.ts +2 -2
  44. package/src/{AppsInTossModule → MiniAppModule}/native-modules/permissions/fetchContacts/fetchContacts.ts +2 -2
  45. package/src/{AppsInTossModule → MiniAppModule}/native-modules/permissions/getClipboardText/getClipboardText.ts +2 -2
  46. package/src/{AppsInTossModule → MiniAppModule}/native-modules/permissions/getCurrentLocation/getCurrentLocation.ts +2 -2
  47. package/src/{AppsInTossModule → MiniAppModule}/native-modules/permissions/openCamera/openCamera.ts +2 -2
  48. package/src/{AppsInTossModule → MiniAppModule}/native-modules/permissions/openPermissionDialog.ts +2 -2
  49. package/src/{AppsInTossModule → MiniAppModule}/native-modules/permissions/setClipboardText/setClipboardText.ts +2 -2
  50. package/src/{AppsInTossModule → MiniAppModule}/native-modules/saveBase64Data.ts +2 -2
  51. package/src/{AppsInTossModule → MiniAppModule}/native-modules/setDeviceOrientation.ts +2 -2
  52. package/src/MiniAppModule/native-modules/shareWithScheme.ts +23 -0
  53. package/src/{AppsInTossModule → MiniAppModule}/native-modules/storage.ts +5 -8
  54. package/src/{AppsInTossModule → MiniAppModule}/native-modules/submitGameCenterLeaderBoardScore.ts +2 -2
  55. package/src/{AppsInTossModule → MiniAppModule}/native-modules/tossCore.ts +5 -17
  56. package/src/MiniAppModule.brick.ts +158 -0
  57. package/src/TossCoreModule.brick.ts +17 -0
  58. package/src/async-bridges.ts +23 -23
  59. package/src/constant-bridges.ts +4 -3
  60. package/src/event-bridges.ts +3 -3
  61. package/src/index.ts +6 -5
  62. package/src/natives.ts +10 -0
  63. package/src/AppsInTossModule/native-event-emitter/nativeEventEmitter.ts +0 -35
  64. package/src/AppsInTossModule/native-modules/AppsInTossModule.ts +0 -107
  65. package/src/AppsInTossModule/native-modules/getTossShareLink.ts +0 -65
  66. package/src/BedrockModule/native-modules/core/BedrockCoreModule.ts +0 -8
  67. /package/src/{AppsInTossModule → MiniAppModule}/constants.ts +0 -0
  68. /package/src/{AppsInTossModule → MiniAppModule}/native-event-emitter/StartUpdateLocationPermissionError.ts +0 -0
  69. /package/src/{AppsInTossModule → MiniAppModule}/native-event-emitter/appsInTossEvent.ts +0 -0
  70. /package/src/{AppsInTossModule → MiniAppModule}/native-event-emitter/contactsViral.ts +0 -0
  71. /package/src/{AppsInTossModule → MiniAppModule}/native-event-emitter/index.ts +0 -0
  72. /package/src/{AppsInTossModule → MiniAppModule}/native-event-emitter/internal/onVisibilityChangedByTransparentServiceWeb.ts +0 -0
  73. /package/src/{AppsInTossModule → MiniAppModule}/native-event-emitter/startUpdateLocation.ts +0 -0
  74. /package/src/{AppsInTossModule → MiniAppModule}/native-event-emitter/types.ts +0 -0
  75. /package/src/{AppsInTossModule → MiniAppModule}/native-modules/ads/googleAdMobV2.ts +0 -0
  76. /package/src/{AppsInTossModule → MiniAppModule}/native-modules/eventLog.spec.ts +0 -0
  77. /package/src/{AppsInTossModule → MiniAppModule}/native-modules/isMinVersionSupported.spec.ts +0 -0
  78. /package/src/{AppsInTossModule → MiniAppModule}/native-modules/openGameCenterLeaderboard.ts +0 -0
  79. /package/src/{AppsInTossModule → MiniAppModule}/native-modules/permissions/createPermissionFunction.ts +0 -0
  80. /package/src/{AppsInTossModule → MiniAppModule}/native-modules/permissions/requestPermission.ts +0 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@apps-in-toss/native-modules",
3
3
  "type": "module",
4
- "version": "1.14.0",
4
+ "version": "2.0.0",
5
5
  "description": "Native Modules for Apps In Toss",
6
6
  "scripts": {
7
7
  "typecheck": "tsc --noEmit",
@@ -29,25 +29,27 @@
29
29
  ],
30
30
  "devDependencies": {
31
31
  "@babel/runtime": "^7",
32
- "@granite-js/native": "0.1.31",
33
- "@granite-js/react-native": "0.1.31",
34
- "@types/react": "18.3.3",
32
+ "@granite-js/native": "1.0.4",
33
+ "@granite-js/react-native": "1.0.4",
34
+ "@types/react": "19.2.3",
35
35
  "dts-bundle-generator": "^9.5.1",
36
36
  "esbuild": "0.25.5",
37
37
  "picocolors": "^1.1.1",
38
- "react": "18.2.0",
39
- "react-native": "0.72.6",
38
+ "react": "19.2.3",
39
+ "react-native": "0.84.0",
40
40
  "tsup": "^8.5.0",
41
- "typescript": "4.9.5",
41
+ "typescript": "5.8.3",
42
42
  "vitest": "^3.2.4"
43
43
  },
44
44
  "dependencies": {
45
- "@apps-in-toss/types": "^1.14.0",
45
+ "@apps-in-toss/types": "2.0.0",
46
+ "brick-module": "0.5.0",
46
47
  "es-toolkit": "^1.39.3"
47
48
  },
48
49
  "peerDependencies": {
49
50
  "@granite-js/native": "*",
50
51
  "@granite-js/react-native": "*",
52
+ "react": "*",
51
53
  "react-native": "*"
52
54
  }
53
55
  }
@@ -1,4 +1,2 @@
1
1
  /** Bridges API */
2
2
  export * from './natives';
3
- export { BedrockModule } from './natives/BedrockModule';
4
- export { BedrockCoreModule } from './core/BedrockCoreModule';
@@ -1,20 +1,10 @@
1
- import { NativeModules } from 'react-native';
2
- import type { HapticFeedbackOptions } from './generateHapticFeedback/types';
3
- import type { NetworkStatus } from './getNetworkStatus/types';
1
+ /**
2
+ * CommonModule (formerly BedrockModule) - BrickModule based implementation
3
+ * All native module access is now unified through natives.ts (SSOT)
4
+ */
4
5
 
5
- interface BedrockModule {
6
- closeView: () => void;
7
- generateHapticFeedback: (options: HapticFeedbackOptions) => Promise<void>;
8
- share: (message: { message: string }) => void;
9
- setSecureScreen: (options: { enabled: boolean }) => Promise<{ enabled: boolean }>;
10
- setScreenAwakeMode: (options: { enabled: boolean }) => Promise<{ enabled: boolean }>;
11
- getNetworkStatus: () => Promise<NetworkStatus>;
12
- setIosSwipeGestureEnabled: ({ isEnabled }: { isEnabled: boolean }) => Promise<void>;
13
- deviceId: string;
14
- DeviceInfo: {
15
- locale: string;
16
- };
17
- schemeUri: string;
18
- }
6
+ import { CommonModule as CommonModuleFromNatives } from '../../../natives';
19
7
 
20
- export const BedrockModule: BedrockModule = NativeModules.BedrockModule;
8
+ export const CommonModule = CommonModuleFromNatives;
9
+ /** @deprecated Use CommonModule instead */
10
+ export const BedrockModule = CommonModuleFromNatives;
@@ -1,4 +1,4 @@
1
- import { BedrockModule } from './BedrockModule';
1
+ import { CommonModule } from './BedrockModule';
2
2
 
3
3
  /**
4
4
  * @public
@@ -21,5 +21,5 @@ import { BedrockModule } from './BedrockModule';
21
21
  * ```
22
22
  */
23
23
  export async function closeView() {
24
- return BedrockModule.closeView();
24
+ return CommonModule.closeView();
25
25
  }
@@ -1,5 +1,5 @@
1
1
  import { HapticFeedbackOptions, HapticFeedbackType } from './types';
2
- import { BedrockModule } from '../BedrockModule';
2
+ import { CommonModule } from '../BedrockModule';
3
3
 
4
4
  /**
5
5
  * @public
@@ -21,7 +21,7 @@ import { BedrockModule } from '../BedrockModule';
21
21
  * ```
22
22
  */
23
23
  export function generateHapticFeedback(options: HapticFeedbackOptions) {
24
- return BedrockModule.generateHapticFeedback(options);
24
+ return CommonModule.generateHapticFeedback(options);
25
25
  }
26
26
 
27
27
  export type { HapticFeedbackType };
@@ -1,5 +1,5 @@
1
1
  import { Platform } from 'react-native';
2
- import { BedrockModule } from './BedrockModule';
2
+ import { CommonModule } from './BedrockModule';
3
3
 
4
4
  /**
5
5
  * @public
@@ -29,7 +29,7 @@ import { BedrockModule } from './BedrockModule';
29
29
  * ```
30
30
  */
31
31
  export function getLocale() {
32
- const locale = BedrockModule?.DeviceInfo?.locale ?? 'ko-KR';
32
+ const locale = CommonModule?.getConstants().locale ?? 'ko-KR';
33
33
 
34
34
  if (Platform.OS === 'android') {
35
35
  return replaceUnderbarToHypen(locale);
@@ -1,5 +1,5 @@
1
1
  import type { NetworkStatus } from './types';
2
- import { BedrockModule } from '../BedrockModule';
2
+ import { CommonModule } from '../BedrockModule';
3
3
 
4
4
  /**
5
5
  * @public
@@ -52,7 +52,7 @@ import { BedrockModule } from '../BedrockModule';
52
52
  * ```
53
53
  */
54
54
  export function getNetworkStatus(): Promise<NetworkStatus> {
55
- return BedrockModule.getNetworkStatus();
55
+ return CommonModule.getNetworkStatus();
56
56
  }
57
57
 
58
58
  /** export type */
@@ -1,4 +1,4 @@
1
- import { BedrockModule } from './BedrockModule';
1
+ import { CommonModule } from './BedrockModule';
2
2
 
3
3
  /**
4
4
  * @public
@@ -23,5 +23,5 @@ import { BedrockModule } from './BedrockModule';
23
23
  * ```
24
24
  */
25
25
  export function getSchemeUri() {
26
- return BedrockModule.schemeUri;
26
+ return CommonModule.getConstants().schemeUri;
27
27
  }
@@ -1,4 +1,4 @@
1
- import { BedrockModule } from './BedrockModule';
1
+ import { CommonModule } from './BedrockModule';
2
2
 
3
3
  /**
4
4
  * @public
@@ -35,9 +35,9 @@ import { BedrockModule } from './BedrockModule';
35
35
  *
36
36
  */
37
37
  export async function setIosSwipeGestureEnabled(options: { isEnabled: boolean }) {
38
- if (BedrockModule.setIosSwipeGestureEnabled == null) {
38
+ if (CommonModule.setIosSwipeGestureEnabled == null) {
39
39
  return;
40
40
  }
41
41
 
42
- return BedrockModule.setIosSwipeGestureEnabled(options);
42
+ return CommonModule.setIosSwipeGestureEnabled(options);
43
43
  }
@@ -1,4 +1,4 @@
1
- import { BedrockModule } from './BedrockModule';
1
+ import { CommonModule } from './BedrockModule';
2
2
 
3
3
  /**
4
4
  * @public
@@ -62,5 +62,5 @@ import { BedrockModule } from './BedrockModule';
62
62
  * ```
63
63
  */
64
64
  export async function setScreenAwakeMode(options: { enabled: boolean }) {
65
- return BedrockModule.setScreenAwakeMode(options);
65
+ return CommonModule.setScreenAwakeMode(options);
66
66
  }
@@ -1,4 +1,4 @@
1
- import { BedrockModule } from './BedrockModule';
1
+ import { CommonModule } from './BedrockModule';
2
2
 
3
3
  /**
4
4
  * @public
@@ -27,5 +27,5 @@ import { BedrockModule } from './BedrockModule';
27
27
  * ```
28
28
  */
29
29
  export function setSecureScreen(options: { enabled: boolean }): Promise<{ enabled: boolean }> {
30
- return BedrockModule.setSecureScreen(options);
30
+ return CommonModule.setSecureScreen(options);
31
31
  }
@@ -1,4 +1,4 @@
1
- import { BedrockModule } from './BedrockModule';
1
+ import { CommonModule } from './BedrockModule';
2
2
 
3
3
  /**
4
4
  * @public
@@ -32,5 +32,5 @@ import { BedrockModule } from './BedrockModule';
32
32
  * ```
33
33
  */
34
34
  export async function share(message: { message: string }) {
35
- BedrockModule.share(message);
35
+ CommonModule.share(message);
36
36
  }
@@ -0,0 +1,36 @@
1
+ import { BrickModule, BrickModuleSpec } from 'brick-module';
2
+ import type { HapticFeedbackOptions } from './BedrockModule/native-modules/natives/generateHapticFeedback/types';
3
+ import type { NetworkStatus } from './BedrockModule/native-modules/natives/getNetworkStatus/types';
4
+
5
+ /**
6
+ * CommonModule Spec
7
+ * Unified type definition for CommonModule (formerly BedrockModule)
8
+ */
9
+ export interface CommonModuleSpec extends BrickModuleSpec {
10
+ readonly moduleName: 'BedrockModule';
11
+
12
+ getConstants(): {
13
+ locale: string;
14
+ schemeUri: string;
15
+ };
16
+
17
+ closeView: () => void;
18
+ generateHapticFeedback: (options: HapticFeedbackOptions) => Promise<void>;
19
+ share: (message: { message: string }) => void;
20
+ setSecureScreen: (options: { enabled: boolean }) => Promise<{ enabled: boolean }>;
21
+ setScreenAwakeMode: (options: { enabled: boolean }) => Promise<{ enabled: boolean }>;
22
+ getNetworkStatus: () => Promise<NetworkStatus>;
23
+ setIosSwipeGestureEnabled: ({ isEnabled }: { isEnabled: boolean }) => Promise<void>;
24
+ }
25
+
26
+ /**
27
+ * CommonModule Instance
28
+ * Native module instance accessed through BrickModule
29
+ */
30
+ export const CommonModule = BrickModule.get<CommonModuleSpec>('CommonModule');
31
+
32
+ /**
33
+ * Deprecated exports for backward compatibility
34
+ */
35
+ /** @deprecated Use CommonModule instead */
36
+ export const BedrockModule = CommonModule;
@@ -1,8 +1,7 @@
1
1
  import { Accuracy, GetCurrentLocationPermissionError, Location } from '@apps-in-toss/types';
2
2
  import { GraniteEventDefinition } from '@granite-js/react-native';
3
- import { AppsInTossModuleInstance } from '../../native-modules/AppsInTossModule';
3
+ import { MiniAppModule, safePostMessage, safeSyncPostMessage } from '../../../natives';
4
4
  import { requestPermission } from '../../native-modules/permissions/requestPermission';
5
- import { nativeEventEmitter } from '../nativeEventEmitter';
6
5
 
7
6
  export interface StartUpdateLocationOptions {
8
7
  /**
@@ -29,7 +28,7 @@ export class UpdateLocationEvent extends GraniteEventDefinition<StartUpdateLocat
29
28
  };
30
29
  remove() {
31
30
  if (--this.subscriptionCount === 0) {
32
- AppsInTossModuleInstance.stopUpdateLocation({});
31
+ safeSyncPostMessage('stopUpdateLocation', {});
33
32
  }
34
33
  this.ref.remove();
35
34
  }
@@ -47,11 +46,15 @@ export class UpdateLocationEvent extends GraniteEventDefinition<StartUpdateLocat
47
46
  }
48
47
 
49
48
  // @internal
50
- void AppsInTossModuleInstance.startUpdateLocation(options).catch(onError);
51
- const subscription = nativeEventEmitter.addListener('updateLocation', onEvent);
49
+ void safePostMessage('startUpdateLocation', options).catch(onError);
50
+ const unsubscribe = MiniAppModule.onSendEvent(({ eventName, body }) => {
51
+ if (eventName === 'updateLocation') {
52
+ onEvent(body as Location);
53
+ }
54
+ });
52
55
 
53
56
  this.ref = {
54
- remove: () => subscription?.remove(),
57
+ remove: () => unsubscribe.remove(),
55
58
  };
56
59
  this.subscriptionCount++;
57
60
  })
@@ -1,18 +1,15 @@
1
1
  /* eslint-disable @typescript-eslint/naming-convention */
2
2
  import { GraniteEventDefinition } from '@granite-js/react-native';
3
- import { EmitterSubscription, NativeEventEmitter } from 'react-native';
4
3
  import { INTERNAL__appBridgeHandler } from './appBridge';
5
- import { nativeEventEmitter } from '../nativeEventEmitter';
4
+ import { MiniAppModule } from '../../../natives';
6
5
 
7
6
  export interface AppBridgeCallbackResult {
8
7
  name: string;
9
8
  params?: any;
10
9
  }
11
10
 
12
- const UNSAFE__nativeEventEmitter = nativeEventEmitter as unknown as NativeEventEmitter;
13
-
14
11
  export class AppBridgeCallbackEvent extends GraniteEventDefinition<void, AppBridgeCallbackResult> {
15
- private static INTERNAL__appBridgeSubscription?: EmitterSubscription;
12
+ private static INTERNAL__appBridgeSubscription?: () => void;
16
13
 
17
14
  name = 'appBridgeCallbackEvent' as const;
18
15
 
@@ -29,10 +26,12 @@ export class AppBridgeCallbackEvent extends GraniteEventDefinition<void, AppBrid
29
26
  return;
30
27
  }
31
28
 
32
- AppBridgeCallbackEvent.INTERNAL__appBridgeSubscription = UNSAFE__nativeEventEmitter.addListener(
33
- 'appBridgeCallback',
34
- this.ensureInvokeAppBridgeCallback
35
- );
29
+ const subscription = MiniAppModule.onSendEvent(({ eventName, body }) => {
30
+ if (eventName === 'appBridgeCallback') {
31
+ this.ensureInvokeAppBridgeCallback(body as AppBridgeCallbackResult);
32
+ }
33
+ });
34
+ AppBridgeCallbackEvent.INTERNAL__appBridgeSubscription = () => subscription.remove();
36
35
  }
37
36
 
38
37
  private ensureInvokeAppBridgeCallback(result: AppBridgeCallbackResult) {
@@ -1,6 +1,5 @@
1
1
  import { GraniteEventDefinition } from '@granite-js/react-native';
2
- import type { EmitterSubscription } from 'react-native';
3
- import { nativeEventEmitter } from '../nativeEventEmitter';
2
+ import { MiniAppModule } from '../../../natives';
4
3
 
5
4
  export interface VisibilityChangedByTransparentServiceWebOptions {
6
5
  callbackId: string;
@@ -17,11 +16,11 @@ export class VisibilityChangedByTransparentServiceWebEvent extends GraniteEventD
17
16
  > {
18
17
  name = 'onVisibilityChangedByTransparentServiceWeb' as const;
19
18
 
20
- subscription: EmitterSubscription | null = null;
19
+ unsubscribe: (() => void) | null = null;
21
20
 
22
21
  remove() {
23
- this.subscription?.remove();
24
- this.subscription = null;
22
+ this.unsubscribe?.();
23
+ this.unsubscribe = null;
25
24
  }
26
25
 
27
26
  listener(
@@ -29,17 +28,19 @@ export class VisibilityChangedByTransparentServiceWebEvent extends GraniteEventD
29
28
  onEvent: (isVisible: boolean) => void,
30
29
  onError: (error: unknown) => void
31
30
  ) {
32
- const subscription = nativeEventEmitter.addListener('visibilityChangedByTransparentServiceWeb', (params) => {
33
- if (this.isVisibilityChangedByTransparentServiceWebResult(params)) {
34
- if (params.callbackId === options.callbackId) {
35
- onEvent(params.isVisible);
31
+ const subscription = MiniAppModule.onSendEvent(({ eventName, body }) => {
32
+ if (eventName === 'visibilityChangedByTransparentServiceWeb') {
33
+ if (this.isVisibilityChangedByTransparentServiceWebResult(body)) {
34
+ if (body.callbackId === options.callbackId) {
35
+ onEvent(body.isVisible);
36
+ }
37
+ } else {
38
+ onError(new Error('Invalid visibility changed by transparent service web result'));
36
39
  }
37
- } else {
38
- onError(new Error('Invalid visibility changed by transparent service web result'));
39
40
  }
40
41
  });
41
42
 
42
- this.subscription = subscription;
43
+ this.unsubscribe = () => subscription.remove();
43
44
  }
44
45
 
45
46
  private isVisibilityChangedByTransparentServiceWebResult(
@@ -68,19 +68,19 @@ describe('appBridge', () => {
68
68
 
69
69
  await expect(task).resolves.toEqual({ value: mocks.mockedReturnValue });
70
70
  expect(mocks.mockedNativeMethod).toHaveBeenCalledTimes(1);
71
- expect(mocks.mockedNativeMethod).toHaveBeenCalledWith({
72
- params: {
71
+ expect(mocks.mockedNativeMethod).toHaveBeenCalledWith(
72
+ {
73
73
  value_1: 1,
74
74
  value_2: 2,
75
75
  value_3: 3,
76
76
  },
77
- callbacks: {
77
+ {
78
78
  // Callbacks are replaced with their unique IDs
79
79
  onFoo: expect.any(String),
80
80
  onBar: expect.any(String),
81
81
  onBaz: expect.any(String),
82
- },
83
- });
82
+ }
83
+ );
84
84
  });
85
85
 
86
86
  it('when the native method is rejected, the error callback is called', async () => {
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/naming-convention */
2
+ import type { AnyObject } from 'brick-module';
3
+ import { MiniAppModule } from '../../../natives';
2
4
  import { generateUUID } from '../../../utils/generateUUID';
3
- import { AppsInTossModuleInstance } from '../../native-modules/AppsInTossModule';
4
5
 
5
6
  export interface AppBridgeCompatCallbacks<Result> {
6
7
  onSuccess: (result: Result) => void;
@@ -20,24 +21,15 @@ function invokeAppBridgeCallback(id: string, ...args: any[]): boolean {
20
21
  return Boolean(callback);
21
22
  }
22
23
 
23
- function invokeAppBridgeMethod<Result = any, Params = any>(
24
+ function invokeAppBridgeMethod<Result = any, Params extends AnyObject = any>(
24
25
  methodName: string,
25
26
  params: Params,
26
27
  callbacks: AppBridgeCompatCallbacks<Result> & Record<string, AppBridgeCallback>
27
28
  ) {
28
29
  const { onSuccess, onError, ...appBridgeCallbacks } = callbacks;
29
30
  const { callbackMap, unregisterAll } = registerCallbacks(appBridgeCallbacks);
30
- const method = AppsInTossModuleInstance[methodName];
31
31
 
32
- if (method == null) {
33
- onError(new Error(`'${methodName}' is not defined in AppsInTossModule`));
34
- return unregisterAll;
35
- }
36
-
37
- const promise = method({
38
- params,
39
- callbacks: callbackMap,
40
- }) as Promise<Result>;
32
+ const promise = MiniAppModule.postMessage(methodName, params, callbackMap) as Promise<Result>;
41
33
 
42
34
  void promise.then(onSuccess).catch(onError);
43
35
 
@@ -0,0 +1,179 @@
1
+ /**
2
+ * @public
3
+ * @category 광고
4
+ * @name AdMobFullScreenEvent
5
+ * @description 앱 화면을 덮는 광고(예: 전면 광고, 보상형 광고)를 사용하는 경우에 발생하는 이벤트 타입이에요.
6
+ * @example
7
+ * ### 광고 이벤트 처리하기
8
+ * ```ts
9
+ * function handleEvent(event: AdMobFullScreenEvent) {
10
+ * switch (event.type) {
11
+ * case 'clicked':
12
+ * console.log('광고가 클릭됐어요.');
13
+ * break;
14
+ *
15
+ * case 'dismissed':
16
+ * console.log('광고가 닫혔어요.');
17
+ * break;
18
+ *
19
+ * case 'failedToShow':
20
+ * console.log('광고가 보여지지 않았어요.');
21
+ * break;
22
+ *
23
+ * case 'impression':
24
+ * console.log('광고가 노출됐어요.');
25
+ * break;
26
+ *
27
+ * case 'show':
28
+ * console.log('광고가 보여졌어요.');
29
+ * break;
30
+ * }
31
+ * }
32
+ * ```
33
+ */
34
+ export type AdMobFullScreenEvent = AdClicked | AdDismissed | AdFailedToShow | AdImpression | AdShow;
35
+
36
+ type AdClicked = { type: 'clicked' };
37
+ type AdDismissed = { type: 'dismissed' };
38
+ type AdFailedToShow = { type: 'failedToShow' };
39
+ type AdImpression = { type: 'impression' };
40
+ type AdShow = { type: 'show' };
41
+
42
+ export type AdUserEarnedReward = { type: 'userEarnedReward'; data: { unitType: string; unitAmount: number } };
43
+
44
+ export interface AdMobHandlerParams<Options = void, Event = AdMobFullScreenEvent> {
45
+ options: Options;
46
+ onEvent: (event: Event) => void;
47
+ onError: (error: unknown) => void;
48
+ }
49
+
50
+ /**
51
+ * @public
52
+ * @category 광고
53
+ * @name ResponseInfo
54
+ * @description 광고 로드 응답 정보를 담고 있는 객체예요.
55
+ * @property {Array<AdNetworkResponseInfo>} adNetworkInfoArray 광고 네트워크 응답 정보 배열예요.
56
+ * @property {AdNetworkResponseInfo | null} loadedAdNetworkInfo 로드된 광고 네트워크 응답 정보예요.
57
+ * @property {string | null} responseId 광고 응답 ID예요.
58
+ */
59
+ export interface ResponseInfo {
60
+ adNetworkInfoArray: Array<AdNetworkResponseInfo>;
61
+ loadedAdNetworkInfo: AdNetworkResponseInfo | null;
62
+ responseId: string | null;
63
+ }
64
+
65
+ /**
66
+ * @public
67
+ * @category 광고
68
+ * @name AdNetworkResponseInfo
69
+ * @description 광고 네트워크 응답 정보를 담고 있는 객체예요.
70
+ * @property {string} adSourceId 광고 소스 ID예요.
71
+ * @property {string} adSourceName 광고 소스 이름이예요.
72
+ * @property {string} adSourceInstanceId 광고 소스 인스턴스 ID예요.
73
+ * @property {string} adSourceInstanceName 광고 소스 인스턴스 이름이예요.
74
+ * @property {string | null} adNetworkClassName 광고 네트워크 클래스 이름이예요.
75
+ */
76
+ export interface AdNetworkResponseInfo {
77
+ adSourceId: string;
78
+ adSourceName: string;
79
+ adSourceInstanceId: string;
80
+ adSourceInstanceName: string;
81
+ adNetworkClassName: string | null;
82
+ }
83
+
84
+ /**
85
+ * @public
86
+ * @category 광고
87
+ * @name InterstitialAd
88
+ * @description 전면 광고의 ID와 응답 정보를 담고 있는 객체예요. 광고를 로드한 뒤, 관련 정보를 확인할 때 유용해요.
89
+ * @property {string} adUnitId 광고 ID예요.
90
+ * @property {ResponseInfo} responseInfo 광고 로드 응답 정보예요. 자세한 내용은 [ResponseInfo](/react-native/reference/native-modules/광고/ResponseInfo.html)를 참고하세요.
91
+ */
92
+ export interface InterstitialAd {
93
+ adUnitId: string;
94
+ responseInfo: ResponseInfo;
95
+ }
96
+
97
+ /**
98
+ * @public
99
+ * @category 광고
100
+ * @name RewardedAd
101
+ * @description 보상형 광고의 ID와 응답 정보를 담고 있는 객체예요. 광고를 로드한 뒤, 관련 정보를 확인할 때 유용해요.
102
+ * @property {string} adUnitId 광고 ID예요.
103
+ * @property {ResponseInfo} responseInfo 광고 로드 응답 정보예요. 자세한 내용은 [ResponseInfo](/react-native/reference/native-modules/광고/ResponseInfo.html)를 참고하세요.
104
+ */
105
+ export interface RewardedAd {
106
+ adUnitId: string;
107
+ responseInfo: ResponseInfo;
108
+ }
109
+
110
+ /**
111
+ * @public
112
+ * @category 광고
113
+ * @name AdMobLoadResult
114
+ * @description 광고의 ID와 응답 정보를 담고 있는 객체예요. 광고를 로드한 뒤, 관련 정보를 확인할 때 유용해요.
115
+ * @property {string} adGroupId 광고 그룹 ID예요.
116
+ * @property {string} adUnitId 광고 ID예요.
117
+ * @property {ResponseInfo} responseInfo 광고 로드 응답 정보예요. 자세한 내용은 [ResponseInfo](/react-native/reference/native-modules/광고/ResponseInfo.html)를 참고하세요.
118
+ */
119
+ export interface AdMobLoadResult {
120
+ adGroupId: string;
121
+ adUnitId: string;
122
+ responseInfo: ResponseInfo;
123
+ }
124
+
125
+ export interface LoadAdMobOptions {
126
+ /**
127
+ * 광고 그룹 단위 ID
128
+ */
129
+ adGroupId: string;
130
+ }
131
+
132
+ /**
133
+ * @public
134
+ * @category 광고
135
+ * @name LoadAdMobEvent
136
+ * @description 광고를 불러오는 함수에서 발생하는 이벤트 타입이에요. `loaded` 이벤트가 발생하면 광고를 성공적으로 불러온 거예요. 이때 [AdMobLoadResult](/react-native/reference/native-modules/광고/AdMobLoadResult.html) 객체가 함께 반환돼요.
137
+ */
138
+ export type LoadAdMobEvent = {
139
+ type: 'loaded';
140
+ data: AdMobLoadResult;
141
+ };
142
+
143
+ /**
144
+ * @public
145
+ * @category 광고
146
+ * @name LoadAdMobParams
147
+ * @description 광고를 불러오는 함수에 필요한 옵션 객체예요.
148
+ */
149
+ export type LoadAdMobParams = AdMobHandlerParams<LoadAdMobOptions, LoadAdMobEvent>;
150
+
151
+ export interface ShowAdMobOptions {
152
+ /**
153
+ * 광고 그룹 단위 ID
154
+ */
155
+ adGroupId: string;
156
+ }
157
+
158
+ /**
159
+ * @public
160
+ * @category 광고
161
+ * @name ShowAdMobEvent
162
+ * @description 광고를 보여주는 함수에서 발생하는 이벤트 타입이에요. `requested` 이벤트가 발생하면 광고 노출 요청이 Google AdMob에 성공적으로 전달된 거예요.
163
+ */
164
+ export type ShowAdMobEvent = AdMobFullScreenEvent | AdUserEarnedReward | { type: 'requested' };
165
+
166
+ /**
167
+ * @public
168
+ * @category 광고
169
+ * @name ShowAdMobParams
170
+ * @description 불러온 광고를 보여주는 함수에 필요한 옵션 객체예요.
171
+ */
172
+ export type ShowAdMobParams = AdMobHandlerParams<ShowAdMobOptions, ShowAdMobEvent>;
173
+
174
+ export interface IsAdMobLoadedOptions {
175
+ /**
176
+ * 광고 그룹 단위 ID
177
+ */
178
+ adGroupId: string;
179
+ }
@@ -1,4 +1,4 @@
1
- import { AppsInTossModule } from './AppsInTossModule';
1
+ import { safePostMessage } from '../../natives';
2
2
 
3
3
  /**
4
4
  * @public
@@ -25,5 +25,5 @@ import { AppsInTossModule } from './AppsInTossModule';
25
25
  * ```
26
26
  */
27
27
  export async function appLogin(): Promise<{ authorizationCode: string; referrer: 'DEFAULT' | 'SANDBOX' }> {
28
- return AppsInTossModule.appLogin({});
28
+ return safePostMessage('appLogin', {});
29
29
  }