@mpgd/adapter-capacitor 0.4.11 → 0.4.12

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,5 +1,5 @@
1
1
  import { type BridgeRequest, type BridgeResponse } from '@mpgd/bridge';
2
- import type { PlatformGateway, PlatformTarget } from '@mpgd/platform';
2
+ import { type PlatformGateway, type PlatformTarget } from '@mpgd/platform';
3
3
  export interface NativeBridge {
4
4
  request(input: BridgeRequest): Promise<BridgeResponse>;
5
5
  }
package/dist/index.js CHANGED
@@ -1,10 +1,15 @@
1
1
  import { decodeBridgeStorageLoadData, } from '@mpgd/bridge';
2
2
  import { CapacitorGameServices } from '@mpgd/capacitor-game-services';
3
+ import { PlatformOperationError, } from '@mpgd/platform';
4
+ function isRecord(value) {
5
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
6
+ }
3
7
  export function createCapacitorPlatformGateway(input) {
4
8
  const bridge = input.bridge ?? CapacitorGameServices;
5
9
  async function request(method, payload) {
6
- const response = (await bridge.request({
7
- id: crypto.randomUUID(),
10
+ const id = crypto.randomUUID();
11
+ const response = await bridge.request({
12
+ id,
8
13
  method,
9
14
  payload,
10
15
  meta: {
@@ -13,11 +18,32 @@ export function createCapacitorPlatformGateway(input) {
13
18
  buildId: input.buildId,
14
19
  sentAt: new Date().toISOString(),
15
20
  },
16
- }));
17
- if (!response.ok) {
18
- throw new Error(response.error.message);
21
+ });
22
+ if (!isRecord(response) || response.id !== id || typeof response.ok !== 'boolean') {
23
+ throw new PlatformOperationError({
24
+ code: 'NATIVE_BRIDGE_INVALID_RESPONSE',
25
+ message: `Native bridge returned an invalid response for ${method}.`,
26
+ });
27
+ }
28
+ if (response.ok) {
29
+ if (!Object.hasOwn(response, 'data')) {
30
+ throw new PlatformOperationError({
31
+ code: 'NATIVE_BRIDGE_INVALID_RESPONSE',
32
+ message: `Native bridge omitted response data for ${method}.`,
33
+ });
34
+ }
35
+ return response.data;
36
+ }
37
+ if (!isRecord(response.error)
38
+ || typeof response.error.code !== 'string'
39
+ || typeof response.error.message !== 'string'
40
+ || typeof response.error.retryable !== 'boolean') {
41
+ throw new PlatformOperationError({
42
+ code: 'NATIVE_BRIDGE_INVALID_RESPONSE',
43
+ message: `Native bridge returned an invalid error for ${method}.`,
44
+ });
19
45
  }
20
- return response.data;
46
+ throw new PlatformOperationError(response.error);
21
47
  }
22
48
  return {
23
49
  target: input.target,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpgd/adapter-capacitor",
3
- "version": "0.4.11",
3
+ "version": "0.4.12",
4
4
  "description": "Capacitor platform adapter for mpgd Android and iOS shells.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -35,10 +35,14 @@
35
35
  ],
36
36
  "dependencies": {
37
37
  "@mpgd/bridge": "0.9.1",
38
- "@mpgd/capacitor-game-services": "0.5.3",
39
- "@mpgd/platform": "0.12.1"
38
+ "@mpgd/capacitor-game-services": "0.5.4",
39
+ "@mpgd/platform": "0.12.2"
40
+ },
41
+ "peerDependencies": {
42
+ "@capacitor/core": "^8.5.1"
40
43
  },
41
44
  "devDependencies": {
45
+ "@capacitor/core": "8.5.2",
42
46
  "ttsc": "0.30.4",
43
47
  "typescript": "7.0.2",
44
48
  "vitest": "^4.0.0"