@mpgd/adapter-capacitor 0.12.1 → 0.12.3

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.
@@ -11,16 +11,16 @@ export interface CreateNotificationProviderBridgeInput {
11
11
  readonly provider: NotificationProvider;
12
12
  }
13
13
  /**
14
- * In-process `NativeBridge` over a notifications v2 provider. Each
15
- * `notifications.v2.*` request validates its payload (a payload the contract
16
- * rejects answers `NOTIFICATIONS_INVALID_INPUT`) and its answer (one the
17
- * contract rejects answers `NOTIFICATIONS_CONFIGURATION_REQUIRED`, because the
18
- * provider broke it). A method the
19
- * provider does not implement answers `NOTIFICATIONS_UNSUPPORTED`, except
20
- * `openSettings`, which answers `unavailable`. Events go out through
21
- * `createBridgeEventSource`, which attaches to the provider only for the
22
- * first listener, so events the provider buffered reach it. Any other method
23
- * answers `UNSUPPORTED_METHOD`.
14
+ * In-process `NativeBridge` over a notifications v2 provider:
15
+ * `createNotificationsV2BridgeHandler` from `@mpgd/bridge/notifications`.
16
+ * Each `notifications.v2.*` request validates its payload (a payload the
17
+ * contract rejects answers `NOTIFICATIONS_INVALID_INPUT`) and its answer (one
18
+ * the contract rejects answers `NOTIFICATIONS_CONFIGURATION_REQUIRED`, because
19
+ * the provider broke it). A method the provider does not implement answers
20
+ * `NOTIFICATIONS_UNSUPPORTED`, except `openSettings`, which answers
21
+ * `unavailable`. Events go out through `createBridgeEventSource`, which
22
+ * attaches to the provider only for the first listener, so events the
23
+ * provider buffered reach it. Any other method answers `UNSUPPORTED_METHOD`.
24
24
  */
25
25
  export declare function createNotificationProviderBridge(input: CreateNotificationProviderBridgeInput): NotificationProviderBridge;
26
26
  export interface CreateNotificationServiceProviderInput {
@@ -1,86 +1,24 @@
1
- import { bridgeNotificationsEventProtocol, createBridgeError, createBridgeEventSource, isBridgeNotificationsV2Method, } from '@mpgd/bridge';
2
- import { assertBridgeNotificationsV2Payload, assertBridgeNotificationsV2Result, } from '@mpgd/bridge/notifications';
1
+ import { bridgeNotificationsEventProtocol, } from '@mpgd/bridge';
2
+ import { assertBridgeNotificationsV2Payload, assertBridgeNotificationsV2Result, createNotificationsV2BridgeHandler, } from '@mpgd/bridge/notifications';
3
3
  import { PlatformOperationError } from '@mpgd/platform';
4
4
  import { assertNotificationEventEnvelope, isNotificationErrorCode, NotificationError, notificationsProtocol, notificationsProtocolVersion, toNotificationSubscriptionAdapter, } from '@mpgd/platform/notifications';
5
5
  import { namesOtherProtocol } from './bridge-events.js';
6
6
  /**
7
- * In-process `NativeBridge` over a notifications v2 provider. Each
8
- * `notifications.v2.*` request validates its payload (a payload the contract
9
- * rejects answers `NOTIFICATIONS_INVALID_INPUT`) and its answer (one the
10
- * contract rejects answers `NOTIFICATIONS_CONFIGURATION_REQUIRED`, because the
11
- * provider broke it). A method the
12
- * provider does not implement answers `NOTIFICATIONS_UNSUPPORTED`, except
13
- * `openSettings`, which answers `unavailable`. Events go out through
14
- * `createBridgeEventSource`, which attaches to the provider only for the
15
- * first listener, so events the provider buffered reach it. Any other method
16
- * answers `UNSUPPORTED_METHOD`.
7
+ * In-process `NativeBridge` over a notifications v2 provider:
8
+ * `createNotificationsV2BridgeHandler` from `@mpgd/bridge/notifications`.
9
+ * Each `notifications.v2.*` request validates its payload (a payload the
10
+ * contract rejects answers `NOTIFICATIONS_INVALID_INPUT`) and its answer (one
11
+ * the contract rejects answers `NOTIFICATIONS_CONFIGURATION_REQUIRED`, because
12
+ * the provider broke it). A method the provider does not implement answers
13
+ * `NOTIFICATIONS_UNSUPPORTED`, except `openSettings`, which answers
14
+ * `unavailable`. Events go out through `createBridgeEventSource`, which
15
+ * attaches to the provider only for the first listener, so events the
16
+ * provider buffered reach it. Any other method answers `UNSUPPORTED_METHOD`.
17
17
  */
18
18
  export function createNotificationProviderBridge(input) {
19
- const { provider } = input;
20
- const events = createBridgeEventSource(bridgeNotificationsEventProtocol, provider);
21
- const serve = async (method, payload) => {
22
- const checked = checkedPayload(method, payload);
23
- switch (method) {
24
- case 'notifications.v2.getCapabilities':
25
- return {
26
- protocolVersion: notificationsProtocolVersion,
27
- provider: provider.provider,
28
- capabilities: await provider.getCapabilities(),
29
- };
30
- case 'notifications.v2.getPermission':
31
- return provider.getPermission(checked);
32
- case 'notifications.v2.requestPermission':
33
- return provider.requestPermission(checked);
34
- case 'notifications.v2.revokePermission':
35
- return implemented(provider.revokePermission, method).call(provider, checked);
36
- case 'notifications.v2.register':
37
- return { registration: await implemented(provider.register, method).call(provider) };
38
- case 'notifications.v2.scheduleLocal':
39
- return implemented(provider.scheduleLocal, method).call(provider, checked);
40
- case 'notifications.v2.cancelLocal':
41
- await implemented(provider.cancelLocal, method).call(provider, checked);
42
- return { cancelled: true };
43
- case 'notifications.v2.listLocal':
44
- return { pending: await implemented(provider.listLocal, method).call(provider) };
45
- case 'notifications.v2.openSettings':
46
- return {
47
- status: provider.openSettings === undefined
48
- ? 'unavailable'
49
- : await provider.openSettings(),
50
- };
51
- default: {
52
- // A method added to the list without a case here fails to compile.
53
- const unhandled = method;
54
- throw new NotificationError('NOTIFICATIONS_UNSUPPORTED', {
55
- message: `The notifications bridge does not serve ${String(unhandled)}.`,
56
- });
57
- }
58
- }
59
- };
60
- return {
61
- async request(request) {
62
- if (!isBridgeNotificationsV2Method(request.method)) {
63
- return createBridgeError(request.id, 'UNSUPPORTED_METHOD', `${request.method} is not a notifications v2 method.`);
64
- }
65
- const method = request.method;
66
- let data;
67
- try {
68
- data = await serve(method, request.payload);
69
- }
70
- catch (error) {
71
- return toBridgeError(request, error);
72
- }
73
- try {
74
- return { id: request.id, ok: true, data: assertBridgeNotificationsV2Result(method, data) };
75
- }
76
- catch (error) {
77
- return createBridgeError(request.id, 'NOTIFICATIONS_CONFIGURATION_REQUIRED', `Notifications provider returned invalid data for ${method}: ${error instanceof Error ? error.message : String(error)}`);
78
- }
79
- },
80
- subscribe: (listener) => events.subscribe(listener),
81
- };
19
+ return createNotificationsV2BridgeHandler({ provider: input.provider });
82
20
  }
83
- /** The payload as the contract reads it, or `NOTIFICATIONS_INVALID_INPUT`; both sides of the bridge use it. */
21
+ /** The payload as the contract reads it, or `NOTIFICATIONS_INVALID_INPUT`, before the game side sends it. */
84
22
  function checkedPayload(method, payload) {
85
23
  try {
86
24
  return assertBridgeNotificationsV2Payload(method, payload);
@@ -92,23 +30,6 @@ function checkedPayload(method, payload) {
92
30
  });
93
31
  }
94
32
  }
95
- function implemented(method, name) {
96
- if (method === undefined) {
97
- throw new NotificationError('NOTIFICATIONS_UNSUPPORTED', {
98
- message: `The notifications provider does not implement ${name}.`,
99
- });
100
- }
101
- return method;
102
- }
103
- function toBridgeError(request, error) {
104
- if (error instanceof PlatformOperationError) {
105
- // A host code kept with `NOTIFICATIONS_CONFIGURATION_REQUIRED` crosses in
106
- // the message: the bridge error has no field for it.
107
- const hostCode = error instanceof NotificationError ? error.hostCode : undefined;
108
- return createBridgeError(request.id, error.code, hostCode === undefined ? error.message : `${error.message} (host code ${hostCode})`, error.retryable);
109
- }
110
- return createBridgeError(request.id, 'NOTIFICATIONS_TEMPORARILY_UNAVAILABLE', `${request.method} failed: ${error instanceof Error ? error.message : String(error)}`, true);
111
- }
112
33
  /**
113
34
  * Registry entry for a notifications v2 provider, as
114
35
  * `createCommerceServiceProvider` is for commerce: it declares no feature and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpgd/adapter-capacitor",
3
- "version": "0.12.1",
3
+ "version": "0.12.3",
4
4
  "description": "Capacitor platform adapter for mpgd Android and iOS shells.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -43,11 +43,11 @@
43
43
  ],
44
44
  "dependencies": {
45
45
  "@capacitor/app": "8.1.1",
46
- "@mpgd/capacitor-game-services": "0.8.1",
47
- "@mpgd/bridge": "0.14.2",
48
- "@mpgd/game-services": "0.27.0",
49
- "@mpgd/target-config": "0.23.5",
50
- "@mpgd/platform": "0.27.0"
46
+ "@mpgd/bridge": "0.15.0",
47
+ "@mpgd/capacitor-game-services": "0.8.3",
48
+ "@mpgd/game-services": "0.27.2",
49
+ "@mpgd/target-config": "0.23.7",
50
+ "@mpgd/platform": "0.27.2"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "@capacitor-community/admob": "^8.1.0",
@@ -74,7 +74,7 @@
74
74
  "ttsc": "0.32.1",
75
75
  "typescript": "7.0.2",
76
76
  "vitest": "^4.0.0",
77
- "@mpgd/game-runtime": "0.7.5"
77
+ "@mpgd/game-runtime": "0.8.0"
78
78
  },
79
79
  "main": "./dist/index.js",
80
80
  "types": "./dist/index.d.ts",