@mpgd/bridge 0.1.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/LICENSE +21 -0
- package/dist/fixtures.d.ts +7 -0
- package/dist/fixtures.js +44 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +173 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 imjlk
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BridgeRequest, BridgeResponse } from './index';
|
|
2
|
+
export declare const validBridgeRequest: BridgeRequest;
|
|
3
|
+
export declare const validBridgeOkResponse: BridgeResponse<{
|
|
4
|
+
readonly nativeAds: boolean;
|
|
5
|
+
}>;
|
|
6
|
+
export declare const validBridgeErrorResponse: BridgeResponse;
|
|
7
|
+
export declare const invalidBridgeRequests: readonly unknown[];
|
package/dist/fixtures.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export const validBridgeRequest = {
|
|
2
|
+
id: 'bridge-request-1',
|
|
3
|
+
method: 'runtime.getCapabilities',
|
|
4
|
+
payload: {},
|
|
5
|
+
meta: {
|
|
6
|
+
target: 'android',
|
|
7
|
+
appVersion: '1.0.0',
|
|
8
|
+
buildId: 'build-1',
|
|
9
|
+
sentAt: '2026-07-03T00:00:00.000Z',
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
export const validBridgeOkResponse = {
|
|
13
|
+
id: validBridgeRequest.id,
|
|
14
|
+
ok: true,
|
|
15
|
+
data: {
|
|
16
|
+
nativeAds: true,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
export const validBridgeErrorResponse = {
|
|
20
|
+
id: validBridgeRequest.id,
|
|
21
|
+
ok: false,
|
|
22
|
+
error: {
|
|
23
|
+
code: 'UNSUPPORTED_METHOD',
|
|
24
|
+
message: 'Unsupported bridge method.',
|
|
25
|
+
retryable: false,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
export const invalidBridgeRequests = [
|
|
29
|
+
{
|
|
30
|
+
...validBridgeRequest,
|
|
31
|
+
id: 42,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
...validBridgeRequest,
|
|
35
|
+
method: 'unknown.method',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
...validBridgeRequest,
|
|
39
|
+
meta: {
|
|
40
|
+
...validBridgeRequest.meta,
|
|
41
|
+
sentAt: 42,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
];
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type BridgeMethod = 'runtime.getCapabilities' | 'identity.getPlayer' | 'commerce.getProducts' | 'commerce.purchase' | 'commerce.restore' | 'commerce.getEntitlements' | 'ads.preload' | 'ads.showRewarded' | 'ads.showInterstitial' | 'leaderboard.submitScore' | 'leaderboard.open' | 'storage.load' | 'storage.save';
|
|
2
|
+
export interface BridgeRequest<TPayload = unknown> {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly method: BridgeMethod;
|
|
5
|
+
readonly payload: TPayload;
|
|
6
|
+
readonly meta: {
|
|
7
|
+
readonly target: string;
|
|
8
|
+
readonly appVersion: string;
|
|
9
|
+
readonly buildId: string;
|
|
10
|
+
readonly sentAt: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export type BridgeResponse<TData = unknown> = {
|
|
14
|
+
readonly id: string;
|
|
15
|
+
readonly ok: true;
|
|
16
|
+
readonly data: TData;
|
|
17
|
+
} | {
|
|
18
|
+
readonly id: string;
|
|
19
|
+
readonly ok: false;
|
|
20
|
+
readonly error: {
|
|
21
|
+
readonly code: string;
|
|
22
|
+
readonly message: string;
|
|
23
|
+
readonly retryable: boolean;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export declare const assertBridgeRequest: (input: unknown) => BridgeRequest<unknown>;
|
|
27
|
+
export declare const assertBridgeResponse: (input: unknown) => BridgeResponse<unknown>;
|
|
28
|
+
export declare function createBridgeError(id: string, code: string, message: string, retryable?: boolean): BridgeResponse;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import * as _a from "typia/lib/internal/_assertGuard";
|
|
2
|
+
import typia from 'typia';
|
|
3
|
+
export const assertBridgeRequest = (() => {
|
|
4
|
+
const _iv0 = new Set(["ads.preload", "ads.showInterstitial", "ads.showRewarded", "commerce.getEntitlements", "commerce.getProducts", "commerce.purchase", "commerce.restore", "identity.getPlayer", "leaderboard.open", "leaderboard.submitScore", "runtime.getCapabilities", "storage.load", "storage.save"]);
|
|
5
|
+
const _av0 = new Set(["ads.preload", "ads.showInterstitial", "ads.showRewarded", "commerce.getEntitlements", "commerce.getProducts", "commerce.purchase", "commerce.restore", "identity.getPlayer", "leaderboard.open", "leaderboard.submitScore", "runtime.getCapabilities", "storage.load", "storage.save"]);
|
|
6
|
+
const _ae0 = "(\"ads.preload\" | \"ads.showInterstitial\" | \"ads.showRewarded\" | \"commerce.getEntitlements\" | \"commerce.getProducts\" | \"commerce.purchase\" | \"commerce.restore\" | \"identity.getPlayer\" | \"leaderboard.open\" | \"leaderboard.submitScore\" | \"runtime.getCapabilities\" | \"storage.load\" | \"storage.save\")";
|
|
7
|
+
const _ao0 = (input, _path, _exceptionable = true) => ("string" === typeof input.id || _a._assertGuard(_exceptionable, {
|
|
8
|
+
method: "typia.createAssert",
|
|
9
|
+
path: _path + ".id",
|
|
10
|
+
expected: "string",
|
|
11
|
+
value: input.id
|
|
12
|
+
}, _errorFactory)) && (true === _av0.has(input.method) || _a._assertGuard(_exceptionable, {
|
|
13
|
+
method: "typia.createAssert",
|
|
14
|
+
path: _path + ".method",
|
|
15
|
+
expected: _ae0,
|
|
16
|
+
value: input.method
|
|
17
|
+
}, _errorFactory)) && true && (("object" === typeof input.meta && null !== input.meta || _a._assertGuard(_exceptionable, {
|
|
18
|
+
method: "typia.createAssert",
|
|
19
|
+
path: _path + ".meta",
|
|
20
|
+
expected: "{ readonly target: string; readonly appVersion: string; readonly buildId: string; readonly sentAt: string; }",
|
|
21
|
+
value: input.meta
|
|
22
|
+
}, _errorFactory)) && _ao1(input.meta, _path + ".meta", true && _exceptionable) || _a._assertGuard(_exceptionable, {
|
|
23
|
+
method: "typia.createAssert",
|
|
24
|
+
path: _path + ".meta",
|
|
25
|
+
expected: "{ readonly target: string; readonly appVersion: string; readonly buildId: string; readonly sentAt: string; }",
|
|
26
|
+
value: input.meta
|
|
27
|
+
}, _errorFactory));
|
|
28
|
+
const _ao1 = (input, _path, _exceptionable = true) => ("string" === typeof input.target || _a._assertGuard(_exceptionable, {
|
|
29
|
+
method: "typia.createAssert",
|
|
30
|
+
path: _path + ".target",
|
|
31
|
+
expected: "string",
|
|
32
|
+
value: input.target
|
|
33
|
+
}, _errorFactory)) && ("string" === typeof input.appVersion || _a._assertGuard(_exceptionable, {
|
|
34
|
+
method: "typia.createAssert",
|
|
35
|
+
path: _path + ".appVersion",
|
|
36
|
+
expected: "string",
|
|
37
|
+
value: input.appVersion
|
|
38
|
+
}, _errorFactory)) && ("string" === typeof input.buildId || _a._assertGuard(_exceptionable, {
|
|
39
|
+
method: "typia.createAssert",
|
|
40
|
+
path: _path + ".buildId",
|
|
41
|
+
expected: "string",
|
|
42
|
+
value: input.buildId
|
|
43
|
+
}, _errorFactory)) && ("string" === typeof input.sentAt || _a._assertGuard(_exceptionable, {
|
|
44
|
+
method: "typia.createAssert",
|
|
45
|
+
path: _path + ".sentAt",
|
|
46
|
+
expected: "string",
|
|
47
|
+
value: input.sentAt
|
|
48
|
+
}, _errorFactory));
|
|
49
|
+
const _io0 = input => "string" === typeof input.id && true === _iv0.has(input.method) && true && ("object" === typeof input.meta && null !== input.meta && _io1(input.meta));
|
|
50
|
+
const _io1 = input => "string" === typeof input.target && "string" === typeof input.appVersion && "string" === typeof input.buildId && "string" === typeof input.sentAt;
|
|
51
|
+
const __is = input => "object" === typeof input && null !== input && _io0(input);
|
|
52
|
+
let _errorFactory;
|
|
53
|
+
return (input, errorFactory) => {
|
|
54
|
+
if (false === __is(input)) {
|
|
55
|
+
_errorFactory = errorFactory;
|
|
56
|
+
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _a._assertGuard(true, {
|
|
57
|
+
method: "typia.createAssert",
|
|
58
|
+
path: _path + "",
|
|
59
|
+
expected: "BridgeRequest<unknown>",
|
|
60
|
+
value: input
|
|
61
|
+
}, _errorFactory)) && _ao0(input, _path + "", true) || _a._assertGuard(true, {
|
|
62
|
+
method: "typia.createAssert",
|
|
63
|
+
path: _path + "",
|
|
64
|
+
expected: "BridgeRequest<unknown>",
|
|
65
|
+
value: input
|
|
66
|
+
}, _errorFactory))(input, "$input", true);
|
|
67
|
+
}
|
|
68
|
+
return input;
|
|
69
|
+
};
|
|
70
|
+
})();
|
|
71
|
+
export const assertBridgeResponse = (() => {
|
|
72
|
+
const _ip0 = input => "string" === typeof input["id"];
|
|
73
|
+
const _ae0 = "({ readonly id: string; readonly ok: false; readonly error: { readonly code: string; readonly message: string; readonly retryable: boolean; }; } | { readonly id: string; readonly ok: true; readonly data: unknown; })";
|
|
74
|
+
const _ap0 = (input, _path, _exceptionable = true) => "string" === typeof input["id"] || _a._assertGuard(_exceptionable, {
|
|
75
|
+
method: "typia.createAssert",
|
|
76
|
+
path: _path + ".id",
|
|
77
|
+
expected: "string",
|
|
78
|
+
value: input["id"]
|
|
79
|
+
}, _errorFactory);
|
|
80
|
+
const _ae1 = "({ readonly id: string; readonly ok: true; readonly data: unknown; } | { readonly id: string; readonly ok: false; readonly error: { readonly code: string; readonly message: string; readonly retryable: boolean; }; })";
|
|
81
|
+
const _ao0 = (input, _path, _exceptionable = true) => _ap0(input, _path, true && _exceptionable) && (true === input.ok || _a._assertGuard(_exceptionable, {
|
|
82
|
+
method: "typia.createAssert",
|
|
83
|
+
path: _path + ".ok",
|
|
84
|
+
expected: "true",
|
|
85
|
+
value: input.ok
|
|
86
|
+
}, _errorFactory)) && true;
|
|
87
|
+
const _ao1 = (input, _path, _exceptionable = true) => _ap0(input, _path, true && _exceptionable) && (false === input.ok || _a._assertGuard(_exceptionable, {
|
|
88
|
+
method: "typia.createAssert",
|
|
89
|
+
path: _path + ".ok",
|
|
90
|
+
expected: "false",
|
|
91
|
+
value: input.ok
|
|
92
|
+
}, _errorFactory)) && (("object" === typeof input.error && null !== input.error || _a._assertGuard(_exceptionable, {
|
|
93
|
+
method: "typia.createAssert",
|
|
94
|
+
path: _path + ".error",
|
|
95
|
+
expected: "{ readonly code: string; readonly message: string; readonly retryable: boolean; }",
|
|
96
|
+
value: input.error
|
|
97
|
+
}, _errorFactory)) && _ao2(input.error, _path + ".error", true && _exceptionable) || _a._assertGuard(_exceptionable, {
|
|
98
|
+
method: "typia.createAssert",
|
|
99
|
+
path: _path + ".error",
|
|
100
|
+
expected: "{ readonly code: string; readonly message: string; readonly retryable: boolean; }",
|
|
101
|
+
value: input.error
|
|
102
|
+
}, _errorFactory));
|
|
103
|
+
const _ao2 = (input, _path, _exceptionable = true) => ("string" === typeof input.code || _a._assertGuard(_exceptionable, {
|
|
104
|
+
method: "typia.createAssert",
|
|
105
|
+
path: _path + ".code",
|
|
106
|
+
expected: "string",
|
|
107
|
+
value: input.code
|
|
108
|
+
}, _errorFactory)) && ("string" === typeof input.message || _a._assertGuard(_exceptionable, {
|
|
109
|
+
method: "typia.createAssert",
|
|
110
|
+
path: _path + ".message",
|
|
111
|
+
expected: "string",
|
|
112
|
+
value: input.message
|
|
113
|
+
}, _errorFactory)) && ("boolean" === typeof input.retryable || _a._assertGuard(_exceptionable, {
|
|
114
|
+
method: "typia.createAssert",
|
|
115
|
+
path: _path + ".retryable",
|
|
116
|
+
expected: "boolean",
|
|
117
|
+
value: input.retryable
|
|
118
|
+
}, _errorFactory));
|
|
119
|
+
const _au0 = (input, _path, _exceptionable = true) => (() => {
|
|
120
|
+
if (true === input.ok)
|
|
121
|
+
return _ao0(input, _path, true && _exceptionable);
|
|
122
|
+
else if (false === input.ok)
|
|
123
|
+
return _ao1(input, _path, true && _exceptionable);
|
|
124
|
+
else
|
|
125
|
+
return _a._assertGuard(_exceptionable, {
|
|
126
|
+
method: "typia.createAssert",
|
|
127
|
+
path: _path,
|
|
128
|
+
expected: _ae1,
|
|
129
|
+
value: input
|
|
130
|
+
}, _errorFactory);
|
|
131
|
+
})();
|
|
132
|
+
const _io0 = input => _ip0(input) && true === input.ok && true;
|
|
133
|
+
const _io1 = input => _ip0(input) && false === input.ok && ("object" === typeof input.error && null !== input.error && _io2(input.error));
|
|
134
|
+
const _io2 = input => "string" === typeof input.code && "string" === typeof input.message && "boolean" === typeof input.retryable;
|
|
135
|
+
const _iu0 = input => (() => {
|
|
136
|
+
if (true === input.ok)
|
|
137
|
+
return _io0(input);
|
|
138
|
+
else if (false === input.ok)
|
|
139
|
+
return _io1(input);
|
|
140
|
+
else
|
|
141
|
+
return false;
|
|
142
|
+
})();
|
|
143
|
+
const __is = input => "object" === typeof input && null !== input && _iu0(input);
|
|
144
|
+
let _errorFactory;
|
|
145
|
+
return (input, errorFactory) => {
|
|
146
|
+
if (false === __is(input)) {
|
|
147
|
+
_errorFactory = errorFactory;
|
|
148
|
+
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _a._assertGuard(true, {
|
|
149
|
+
method: "typia.createAssert",
|
|
150
|
+
path: _path + "",
|
|
151
|
+
expected: _ae0,
|
|
152
|
+
value: input
|
|
153
|
+
}, _errorFactory)) && _au0(input, _path + "", true) || _a._assertGuard(true, {
|
|
154
|
+
method: "typia.createAssert",
|
|
155
|
+
path: _path + "",
|
|
156
|
+
expected: _ae0,
|
|
157
|
+
value: input
|
|
158
|
+
}, _errorFactory))(input, "$input", true);
|
|
159
|
+
}
|
|
160
|
+
return input;
|
|
161
|
+
};
|
|
162
|
+
})();
|
|
163
|
+
export function createBridgeError(id, code, message, retryable = false) {
|
|
164
|
+
return {
|
|
165
|
+
id,
|
|
166
|
+
ok: false,
|
|
167
|
+
error: {
|
|
168
|
+
code,
|
|
169
|
+
message,
|
|
170
|
+
retryable,
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mpgd/bridge",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Typed native bridge protocol for mpgd platform adapters.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/imjlk/mpgd-kit.git",
|
|
9
|
+
"directory": "packages/bridge"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/imjlk/mpgd-kit/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/imjlk/mpgd-kit#readme",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"mpgd",
|
|
17
|
+
"phaser",
|
|
18
|
+
"vite",
|
|
19
|
+
"typescript",
|
|
20
|
+
"capacitor",
|
|
21
|
+
"apps-in-toss",
|
|
22
|
+
"game-development",
|
|
23
|
+
"game-distribution"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"default": "./dist/index.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"typia": "rc"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"ttsc": "0.16.9",
|
|
41
|
+
"typescript": "7.0.1-rc"
|
|
42
|
+
},
|
|
43
|
+
"main": "./dist/index.js",
|
|
44
|
+
"types": "./dist/index.d.ts",
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"check": "ttsc --noEmit",
|
|
50
|
+
"lint": "ttsc --noEmit",
|
|
51
|
+
"format": "ttsc format",
|
|
52
|
+
"fix": "ttsc fix",
|
|
53
|
+
"test": "cd ../.. && node tools/run-ttsx.mjs packages/bridge/src/bridge-protocol.test.ts"
|
|
54
|
+
}
|
|
55
|
+
}
|