@mpgd/adapter-capacitor 0.12.2 → 0.12.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/notifications-bridge.d.ts +10 -10
- package/dist/notifications-bridge.js +14 -93
- package/package.json +7 -7
|
@@ -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
|
|
15
|
-
* `
|
|
16
|
-
*
|
|
17
|
-
* contract rejects answers `
|
|
18
|
-
*
|
|
19
|
-
* provider does not implement answers
|
|
20
|
-
* `openSettings`, which answers
|
|
21
|
-
* `
|
|
22
|
-
*
|
|
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,
|
|
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
|
|
8
|
-
* `
|
|
9
|
-
*
|
|
10
|
-
* contract rejects answers `
|
|
11
|
-
*
|
|
12
|
-
* provider does not implement answers
|
|
13
|
-
* `openSettings`, which answers
|
|
14
|
-
* `
|
|
15
|
-
*
|
|
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
|
-
|
|
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
|
|
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.
|
|
3
|
+
"version": "0.12.4",
|
|
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/
|
|
47
|
-
"@mpgd/
|
|
48
|
-
"@mpgd/
|
|
49
|
-
"@mpgd/
|
|
50
|
-
"@mpgd/
|
|
46
|
+
"@mpgd/game-services": "0.28.0",
|
|
47
|
+
"@mpgd/bridge": "0.15.0",
|
|
48
|
+
"@mpgd/platform": "0.27.2",
|
|
49
|
+
"@mpgd/target-config": "0.23.7",
|
|
50
|
+
"@mpgd/capacitor-game-services": "0.8.3"
|
|
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.
|
|
77
|
+
"@mpgd/game-runtime": "0.8.1"
|
|
78
78
|
},
|
|
79
79
|
"main": "./dist/index.js",
|
|
80
80
|
"types": "./dist/index.d.ts",
|