@mpgd/adapter-ait 0.11.0 → 0.12.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/dist/host.d.ts CHANGED
@@ -4,6 +4,12 @@ import type { AitAdPlacementType } from './ad-config.js';
4
4
  import type { GamePlatformBridge } from './index.js';
5
5
  export type AitIdentityProvider = () => Promise<unknown>;
6
6
  /**
7
+ * Shares one game identity hash read across a wrapper session.
8
+ * Rejected reads are evicted so a resumed mobile host can retry after login or
9
+ * WebView state has recovered.
10
+ */
11
+ export declare function createAitSessionIdentityProvider(provider?: AitIdentityProvider): AitIdentityProvider;
12
+ /**
7
13
  * The AIT SDK adds support-version metadata to native functions over time.
8
14
  * The host only depends on the callable surface and an optional support probe
9
15
  * so adapter tests remain compatible with older wrappers and newer SDKs.
package/dist/host.js CHANGED
@@ -44,8 +44,31 @@ const launchEntries = new Set([
44
44
  'leaderboard',
45
45
  'friend-challenge',
46
46
  ]);
47
+ const defaultAitIdentityProvider = () => getUserKeyForGame();
48
+ /**
49
+ * Shares one game identity hash read across a wrapper session.
50
+ * Rejected reads are evicted so a resumed mobile host can retry after login or
51
+ * WebView state has recovered.
52
+ */
53
+ export function createAitSessionIdentityProvider(provider = defaultAitIdentityProvider) {
54
+ let pending;
55
+ return () => {
56
+ const current = pending;
57
+ if (current !== undefined) {
58
+ return current;
59
+ }
60
+ const attempt = Promise.resolve().then(provider);
61
+ void (pending = attempt);
62
+ void attempt.catch(() => {
63
+ if (pending === attempt) {
64
+ pending = undefined;
65
+ }
66
+ });
67
+ return attempt;
68
+ };
69
+ }
47
70
  const defaultDependencies = {
48
- identityProvider: getUserKeyForGame,
71
+ identityProvider: defaultAitIdentityProvider,
49
72
  storage: Storage,
50
73
  getTossShareLink,
51
74
  share,
@@ -65,7 +88,11 @@ export function installAitHostBridge(options = {}) {
65
88
  return bridge;
66
89
  }
67
90
  export function createAitHostBridge(options = {}) {
68
- const dependencies = { ...defaultDependencies, ...options.dependencies };
91
+ const configuredDependencies = { ...defaultDependencies, ...options.dependencies };
92
+ const dependencies = {
93
+ ...configuredDependencies,
94
+ identityProvider: createAitSessionIdentityProvider(configuredDependencies.identityProvider),
95
+ };
69
96
  const appName = normalizeAppName(options.appName ?? 'mpgd-kit');
70
97
  const adGroupIds = normalizeAdGroupIds(options.adGroupIds);
71
98
  const adPlacementTypes = normalizeAdPlacementTypes(options.adPlacementTypes);
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type BridgeRequest, type BridgeResponse } from '@mpgd/bridge';
2
- import type { PlatformGateway } from '@mpgd/platform';
2
+ import { type PlatformGateway } from '@mpgd/platform';
3
3
  export interface GamePlatformBridge {
4
4
  request(input: BridgeRequest): Promise<BridgeResponse>;
5
5
  }
package/dist/index.js CHANGED
@@ -1,10 +1,15 @@
1
1
  import { bridgeStorageLoadProtocol, decodeBridgeStorageLoadData, } from '@mpgd/bridge';
2
+ import { PlatformOperationError, } from '@mpgd/platform';
2
3
  import { createAitLifecycleAdapter } from './lifecycle.js';
3
4
  export function createAitPlatformGateway(input) {
4
5
  async function request(method, payload) {
5
6
  const bridge = input.bridge ?? getBridge() ?? input.fallbackBridge;
6
7
  if (bridge === undefined) {
7
- throw new Error('AIT bridge is not installed.');
8
+ throw new PlatformOperationError({
9
+ code: 'AIT_BRIDGE_NOT_INSTALLED',
10
+ message: 'AIT bridge is not installed.',
11
+ retryable: false,
12
+ });
8
13
  }
9
14
  const response = await bridge.request({
10
15
  id: crypto.randomUUID(),
@@ -18,7 +23,7 @@ export function createAitPlatformGateway(input) {
18
23
  },
19
24
  });
20
25
  if (!response.ok) {
21
- throw new Error(response.error.message);
26
+ throw new PlatformOperationError(response.error);
22
27
  }
23
28
  return response.data;
24
29
  }
@@ -22,6 +22,12 @@ export declare const Storage: {
22
22
  setItem(key: string, value: string): Promise<void>;
23
23
  removeItem(key: string): Promise<void>;
24
24
  };
25
+ export declare const User: {
26
+ getAnonymousKey(): Promise<{
27
+ readonly type: 'HASH';
28
+ readonly hash: string;
29
+ }>;
30
+ };
25
31
  export declare function getUserKeyForGame(): Promise<{
26
32
  readonly type: 'HASH';
27
33
  readonly hash: string;
@@ -36,8 +36,13 @@ export const Storage = {
36
36
  localStorageValues.delete(key);
37
37
  },
38
38
  };
39
+ export const User = {
40
+ async getAnonymousKey() {
41
+ return { type: 'HASH', hash: 'ait-local-player' };
42
+ },
43
+ };
39
44
  export async function getUserKeyForGame() {
40
- return { type: 'HASH', hash: 'ait-local-player' };
45
+ return User.getAnonymousKey();
41
46
  }
42
47
  export async function getTossShareLink() {
43
48
  return globalThis.location?.href ?? 'https://localhost/';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpgd/adapter-ait",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Apps in Toss WebView platform adapter for mpgd games.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -56,7 +56,7 @@
56
56
  ],
57
57
  "dependencies": {
58
58
  "@mpgd/bridge": "0.9.0",
59
- "@mpgd/platform": "0.10.0"
59
+ "@mpgd/platform": "0.11.0"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "@apps-in-toss/web-framework": ">=3.0.0 <4"