@mpgd/adapter-ait 0.4.3 → 0.4.4

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/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { BridgeRequest, BridgeResponse } from '@mpgd/bridge';
1
+ import { type BridgeRequest, type BridgeResponse } from '@mpgd/bridge';
2
2
  import type { PlatformGateway } from '@mpgd/platform';
3
3
  export interface GamePlatformBridge {
4
4
  request(input: BridgeRequest): Promise<BridgeResponse>;
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { bridgeStorageLoadProtocol, decodeBridgeStorageLoadData, } from '@mpgd/bridge';
1
2
  export function createAitPlatformGateway(input) {
2
3
  async function request(method, payload) {
3
4
  const bridge = input.bridge ?? getBridge() ?? input.fallbackBridge;
@@ -22,7 +23,9 @@ export function createAitPlatformGateway(input) {
22
23
  }
23
24
  return {
24
25
  target: 'ait',
25
- getCapabilities: () => request('runtime.getCapabilities', {}),
26
+ async getCapabilities() {
27
+ return { ...await request('runtime.getCapabilities', {}) };
28
+ },
26
29
  identity: {
27
30
  getPlayer: () => request('identity.getPlayer', {}),
28
31
  getSession: () => request('identity.getSession', {}),
@@ -65,8 +68,7 @@ export function createAitPlatformGateway(input) {
65
68
  },
66
69
  storage: {
67
70
  async load(payload) {
68
- const value = await request('storage.load', payload);
69
- return value === null ? null : { value };
71
+ return decodeBridgeStorageLoadData(await request('storage.load', payload));
70
72
  },
71
73
  save: (payload) => request('storage.save', payload),
72
74
  },
@@ -170,12 +172,18 @@ export function createAitSandboxBridge() {
170
172
  return ok(input, {});
171
173
  case 'storage.load': {
172
174
  const payload = input.payload;
173
- return ok(input, payload.key === undefined ? null : (storage.get(payload.key) ?? null));
175
+ const found = payload.key !== undefined && storage.has(payload.key);
176
+ const value = found && payload.key !== undefined
177
+ ? cloneJsonValue(storage.get(payload.key))
178
+ : undefined;
179
+ return ok(input, !found
180
+ ? { __mpgdBridgeProtocol: bridgeStorageLoadProtocol, found: false }
181
+ : { __mpgdBridgeProtocol: bridgeStorageLoadProtocol, found: true, value });
174
182
  }
175
183
  case 'storage.save': {
176
184
  const payload = input.payload;
177
185
  if (payload.key !== undefined) {
178
- storage.set(payload.key, payload.value);
186
+ storage.set(payload.key, cloneJsonValue(payload.value));
179
187
  }
180
188
  return ok(input, {});
181
189
  }
@@ -193,6 +201,13 @@ export function createAitSandboxBridge() {
193
201
  },
194
202
  };
195
203
  }
204
+ function cloneJsonValue(input) {
205
+ const serialized = JSON.stringify(input);
206
+ if (serialized === undefined) {
207
+ throw new Error('AIT sandbox storage values must be JSON-serializable.');
208
+ }
209
+ return JSON.parse(serialized);
210
+ }
196
211
  function ok(input, data) {
197
212
  return {
198
213
  id: input.id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpgd/adapter-ait",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "Apps in Toss WebView platform adapter for mpgd games.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -34,8 +34,8 @@
34
34
  "dist"
35
35
  ],
36
36
  "dependencies": {
37
- "@mpgd/bridge": "0.6.0",
38
- "@mpgd/platform": "0.6.0"
37
+ "@mpgd/bridge": "0.6.1",
38
+ "@mpgd/platform": "0.7.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "ttsc": "0.18.4",