@mpgd/bridge 0.4.0 → 0.6.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/dist/cloudflare-pages.d.ts +2 -2
- package/dist/cloudflare-pages.js +29 -3
- package/dist/fixtures.d.ts +1 -0
- package/dist/fixtures.js +17 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +25 -25
- package/dist/orpc-node.d.ts +12 -0
- package/dist/orpc-node.js +52 -0
- package/dist/orpc.d.ts +1 -1
- package/dist/orpc.js +1 -1
- package/package.json +10 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type BridgeRequest, type BridgeResponse } from './index';
|
|
2
|
-
import { type BridgeRpcPrefix } from './orpc';
|
|
1
|
+
import { type BridgeRequest, type BridgeResponse } from './index.js';
|
|
2
|
+
import { type BridgeRpcPrefix } from './orpc.js';
|
|
3
3
|
export declare const defaultCloudflarePagesBridgeEndpoint: '/api/mpgd/bridge';
|
|
4
4
|
export declare const defaultCloudflarePagesGameServicesPrefix: '/api/game-services';
|
|
5
5
|
export declare const defaultCloudflarePagesGameServicesForwardHeaders: readonly ['accept', 'authorization', 'content-type'];
|
package/dist/cloudflare-pages.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { assertBridgeRequest, createBridgeError, } from './index';
|
|
2
|
-
import { createBridgeRpcFetchHandler, createBridgeRpcRouter, defaultBridgeRpcEndpoint, } from './orpc';
|
|
1
|
+
import { assertBridgeRequest, createBridgeError, } from './index.js';
|
|
2
|
+
import { createBridgeRpcFetchHandler, createBridgeRpcRouter, defaultBridgeRpcEndpoint, } from './orpc.js';
|
|
3
3
|
export const defaultCloudflarePagesBridgeEndpoint = '/api/mpgd/bridge';
|
|
4
4
|
export const defaultCloudflarePagesGameServicesPrefix = '/api/game-services';
|
|
5
5
|
export const defaultCloudflarePagesGameServicesForwardHeaders = [
|
|
@@ -74,13 +74,39 @@ export function createMpgdCloudflarePagesBridgeHandler() {
|
|
|
74
74
|
nativeLeaderboard: false,
|
|
75
75
|
achievements: false,
|
|
76
76
|
cloudSave: false,
|
|
77
|
-
socialShare:
|
|
77
|
+
socialShare: false,
|
|
78
78
|
haptics: false,
|
|
79
79
|
localizedContent: true,
|
|
80
80
|
});
|
|
81
81
|
case 'identity.getPlayer': {
|
|
82
82
|
return ok(input.bridgeRequest, null);
|
|
83
83
|
}
|
|
84
|
+
case 'identity.getSession':
|
|
85
|
+
return ok(input.bridgeRequest, {
|
|
86
|
+
identityLevel: 'guest',
|
|
87
|
+
trustLevel: 'local',
|
|
88
|
+
});
|
|
89
|
+
case 'identity.requestUpgrade':
|
|
90
|
+
return ok(input.bridgeRequest, {
|
|
91
|
+
status: 'unavailable',
|
|
92
|
+
reloadExpected: false,
|
|
93
|
+
});
|
|
94
|
+
case 'presentation.getLaunchIntent':
|
|
95
|
+
return ok(input.bridgeRequest, {
|
|
96
|
+
entry: 'home',
|
|
97
|
+
});
|
|
98
|
+
case 'presentation.requestGameSurface':
|
|
99
|
+
return ok(input.bridgeRequest, 'already-fullscreen');
|
|
100
|
+
case 'share.share':
|
|
101
|
+
return ok(input.bridgeRequest, {
|
|
102
|
+
status: 'unavailable',
|
|
103
|
+
});
|
|
104
|
+
case 'share.readInboundShare':
|
|
105
|
+
return ok(input.bridgeRequest, null);
|
|
106
|
+
case 'notifications.getStatus':
|
|
107
|
+
return ok(input.bridgeRequest, 'unsupported');
|
|
108
|
+
case 'notifications.requestSubscription':
|
|
109
|
+
return ok(input.bridgeRequest, 'unavailable');
|
|
84
110
|
case 'commerce.getProducts':
|
|
85
111
|
case 'commerce.getEntitlements':
|
|
86
112
|
return ok(input.bridgeRequest, []);
|
package/dist/fixtures.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { BridgeRequest, BridgeResponse } from './index';
|
|
2
2
|
export declare const validBridgeRequest: BridgeRequest;
|
|
3
|
+
export declare const validNewBridgeRequests: BridgeRequest<unknown>[];
|
|
3
4
|
export declare const validBridgeOkResponse: BridgeResponse<{
|
|
4
5
|
readonly nativeAds: boolean;
|
|
5
6
|
}>;
|
package/dist/fixtures.js
CHANGED
|
@@ -9,6 +9,16 @@ export const validBridgeRequest = {
|
|
|
9
9
|
sentAt: '2026-07-03T00:00:00.000Z',
|
|
10
10
|
},
|
|
11
11
|
};
|
|
12
|
+
export const validNewBridgeRequests = [
|
|
13
|
+
createBridgeRequest('identity.getSession'),
|
|
14
|
+
createBridgeRequest('identity.requestUpgrade'),
|
|
15
|
+
createBridgeRequest('presentation.getLaunchIntent'),
|
|
16
|
+
createBridgeRequest('presentation.requestGameSurface'),
|
|
17
|
+
createBridgeRequest('share.share'),
|
|
18
|
+
createBridgeRequest('share.readInboundShare'),
|
|
19
|
+
createBridgeRequest('notifications.getStatus'),
|
|
20
|
+
createBridgeRequest('notifications.requestSubscription'),
|
|
21
|
+
];
|
|
12
22
|
export const validBridgeOkResponse = {
|
|
13
23
|
id: validBridgeRequest.id,
|
|
14
24
|
ok: true,
|
|
@@ -42,3 +52,10 @@ export const invalidBridgeRequests = [
|
|
|
42
52
|
},
|
|
43
53
|
},
|
|
44
54
|
];
|
|
55
|
+
function createBridgeRequest(method) {
|
|
56
|
+
return {
|
|
57
|
+
...validBridgeRequest,
|
|
58
|
+
id: `bridge-request-${method}`,
|
|
59
|
+
method,
|
|
60
|
+
};
|
|
61
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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';
|
|
1
|
+
export type BridgeMethod = 'runtime.getCapabilities' | 'identity.getPlayer' | 'identity.getSession' | 'identity.requestUpgrade' | 'presentation.getLaunchIntent' | 'presentation.requestGameSurface' | 'share.share' | 'share.readInboundShare' | 'notifications.getStatus' | 'notifications.requestSubscription' | 'commerce.getProducts' | 'commerce.purchase' | 'commerce.restore' | 'commerce.getEntitlements' | 'ads.preload' | 'ads.showRewarded' | 'ads.showInterstitial' | 'leaderboard.submitScore' | 'leaderboard.open' | 'storage.load' | 'storage.save';
|
|
2
2
|
export interface BridgeRequest<TPayload = unknown> {
|
|
3
3
|
readonly id: string;
|
|
4
4
|
readonly method: BridgeMethod;
|
package/dist/index.js
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _assertGuard_1 from "typia/lib/internal/_assertGuard";
|
|
2
2
|
import typia from 'typia';
|
|
3
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 ||
|
|
4
|
+
const _iv0 = new Set(["ads.preload", "ads.showInterstitial", "ads.showRewarded", "commerce.getEntitlements", "commerce.getProducts", "commerce.purchase", "commerce.restore", "identity.getPlayer", "identity.getSession", "identity.requestUpgrade", "leaderboard.open", "leaderboard.submitScore", "notifications.getStatus", "notifications.requestSubscription", "presentation.getLaunchIntent", "presentation.requestGameSurface", "runtime.getCapabilities", "share.readInboundShare", "share.share", "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", "identity.getSession", "identity.requestUpgrade", "leaderboard.open", "leaderboard.submitScore", "notifications.getStatus", "notifications.requestSubscription", "presentation.getLaunchIntent", "presentation.requestGameSurface", "runtime.getCapabilities", "share.readInboundShare", "share.share", "storage.load", "storage.save"]);
|
|
6
|
+
const _ae0 = "(\"ads.preload\" | \"ads.showInterstitial\" | \"ads.showRewarded\" | \"commerce.getEntitlements\" | \"commerce.getProducts\" | \"commerce.purchase\" | \"commerce.restore\" | \"identity.getPlayer\" | \"identity.getSession\" | \"identity.requestUpgrade\" | \"leaderboard.open\" | \"leaderboard.submitScore\" | \"notifications.getStatus\" | \"notifications.requestSubscription\" | \"presentation.getLaunchIntent\" | \"presentation.requestGameSurface\" | \"runtime.getCapabilities\" | \"share.readInboundShare\" | \"share.share\" | \"storage.load\" | \"storage.save\")";
|
|
7
|
+
const _ao0 = (input, _path, _exceptionable = true) => ("string" === typeof input.id || _assertGuard_1._assertGuard(_exceptionable, {
|
|
8
8
|
method: "typia.createAssert",
|
|
9
9
|
path: _path + ".id",
|
|
10
10
|
expected: "string",
|
|
11
11
|
value: input.id
|
|
12
|
-
}, _errorFactory)) && (true === _av0.has(input.method) ||
|
|
12
|
+
}, _errorFactory)) && (true === _av0.has(input.method) || _assertGuard_1._assertGuard(_exceptionable, {
|
|
13
13
|
method: "typia.createAssert",
|
|
14
14
|
path: _path + ".method",
|
|
15
15
|
expected: _ae0,
|
|
16
16
|
value: input.method
|
|
17
|
-
}, _errorFactory)) && true && (("object" === typeof input.meta && null !== input.meta ||
|
|
17
|
+
}, _errorFactory)) && true && (("object" === typeof input.meta && null !== input.meta || _assertGuard_1._assertGuard(_exceptionable, {
|
|
18
18
|
method: "typia.createAssert",
|
|
19
19
|
path: _path + ".meta",
|
|
20
20
|
expected: "{ readonly target: string; readonly appVersion: string; readonly buildId: string; readonly sentAt: string; }",
|
|
21
21
|
value: input.meta
|
|
22
|
-
}, _errorFactory)) && _ao1(input.meta, _path + ".meta", true && _exceptionable) ||
|
|
22
|
+
}, _errorFactory)) && _ao1(input.meta, _path + ".meta", true && _exceptionable) || _assertGuard_1._assertGuard(_exceptionable, {
|
|
23
23
|
method: "typia.createAssert",
|
|
24
24
|
path: _path + ".meta",
|
|
25
25
|
expected: "{ readonly target: string; readonly appVersion: string; readonly buildId: string; readonly sentAt: string; }",
|
|
26
26
|
value: input.meta
|
|
27
27
|
}, _errorFactory));
|
|
28
|
-
const _ao1 = (input, _path, _exceptionable = true) => ("string" === typeof input.target ||
|
|
28
|
+
const _ao1 = (input, _path, _exceptionable = true) => ("string" === typeof input.target || _assertGuard_1._assertGuard(_exceptionable, {
|
|
29
29
|
method: "typia.createAssert",
|
|
30
30
|
path: _path + ".target",
|
|
31
31
|
expected: "string",
|
|
32
32
|
value: input.target
|
|
33
|
-
}, _errorFactory)) && ("string" === typeof input.appVersion ||
|
|
33
|
+
}, _errorFactory)) && ("string" === typeof input.appVersion || _assertGuard_1._assertGuard(_exceptionable, {
|
|
34
34
|
method: "typia.createAssert",
|
|
35
35
|
path: _path + ".appVersion",
|
|
36
36
|
expected: "string",
|
|
37
37
|
value: input.appVersion
|
|
38
|
-
}, _errorFactory)) && ("string" === typeof input.buildId ||
|
|
38
|
+
}, _errorFactory)) && ("string" === typeof input.buildId || _assertGuard_1._assertGuard(_exceptionable, {
|
|
39
39
|
method: "typia.createAssert",
|
|
40
40
|
path: _path + ".buildId",
|
|
41
41
|
expected: "string",
|
|
42
42
|
value: input.buildId
|
|
43
|
-
}, _errorFactory)) && ("string" === typeof input.sentAt ||
|
|
43
|
+
}, _errorFactory)) && ("string" === typeof input.sentAt || _assertGuard_1._assertGuard(_exceptionable, {
|
|
44
44
|
method: "typia.createAssert",
|
|
45
45
|
path: _path + ".sentAt",
|
|
46
46
|
expected: "string",
|
|
@@ -53,12 +53,12 @@ export const assertBridgeRequest = (() => {
|
|
|
53
53
|
return (input, errorFactory) => {
|
|
54
54
|
if (false === __is(input)) {
|
|
55
55
|
_errorFactory = errorFactory;
|
|
56
|
-
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input ||
|
|
56
|
+
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _assertGuard_1._assertGuard(true, {
|
|
57
57
|
method: "typia.createAssert",
|
|
58
58
|
path: _path + "",
|
|
59
59
|
expected: "BridgeRequest<unknown>",
|
|
60
60
|
value: input
|
|
61
|
-
}, _errorFactory)) && _ao0(input, _path + "", true) ||
|
|
61
|
+
}, _errorFactory)) && _ao0(input, _path + "", true) || _assertGuard_1._assertGuard(true, {
|
|
62
62
|
method: "typia.createAssert",
|
|
63
63
|
path: _path + "",
|
|
64
64
|
expected: "BridgeRequest<unknown>",
|
|
@@ -71,46 +71,46 @@ export const assertBridgeRequest = (() => {
|
|
|
71
71
|
export const assertBridgeResponse = (() => {
|
|
72
72
|
const _ip0 = input => "string" === typeof input["id"];
|
|
73
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"] ||
|
|
74
|
+
const _ap0 = (input, _path, _exceptionable = true) => "string" === typeof input["id"] || _assertGuard_1._assertGuard(_exceptionable, {
|
|
75
75
|
method: "typia.createAssert",
|
|
76
76
|
path: _path + ".id",
|
|
77
77
|
expected: "string",
|
|
78
78
|
value: input["id"]
|
|
79
79
|
}, _errorFactory);
|
|
80
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 ||
|
|
81
|
+
const _ao0 = (input, _path, _exceptionable = true) => _ap0(input, _path, true && _exceptionable) && (true === input.ok || _assertGuard_1._assertGuard(_exceptionable, {
|
|
82
82
|
method: "typia.createAssert",
|
|
83
83
|
path: _path + ".ok",
|
|
84
84
|
expected: "true",
|
|
85
85
|
value: input.ok
|
|
86
86
|
}, _errorFactory)) && true;
|
|
87
|
-
const _ao1 = (input, _path, _exceptionable = true) => _ap0(input, _path, true && _exceptionable) && (false === input.ok ||
|
|
87
|
+
const _ao1 = (input, _path, _exceptionable = true) => _ap0(input, _path, true && _exceptionable) && (false === input.ok || _assertGuard_1._assertGuard(_exceptionable, {
|
|
88
88
|
method: "typia.createAssert",
|
|
89
89
|
path: _path + ".ok",
|
|
90
90
|
expected: "false",
|
|
91
91
|
value: input.ok
|
|
92
|
-
}, _errorFactory)) && (("object" === typeof input.error && null !== input.error ||
|
|
92
|
+
}, _errorFactory)) && (("object" === typeof input.error && null !== input.error || _assertGuard_1._assertGuard(_exceptionable, {
|
|
93
93
|
method: "typia.createAssert",
|
|
94
94
|
path: _path + ".error",
|
|
95
95
|
expected: "{ readonly code: string; readonly message: string; readonly retryable: boolean; }",
|
|
96
96
|
value: input.error
|
|
97
|
-
}, _errorFactory)) && _ao2(input.error, _path + ".error", true && _exceptionable) ||
|
|
97
|
+
}, _errorFactory)) && _ao2(input.error, _path + ".error", true && _exceptionable) || _assertGuard_1._assertGuard(_exceptionable, {
|
|
98
98
|
method: "typia.createAssert",
|
|
99
99
|
path: _path + ".error",
|
|
100
100
|
expected: "{ readonly code: string; readonly message: string; readonly retryable: boolean; }",
|
|
101
101
|
value: input.error
|
|
102
102
|
}, _errorFactory));
|
|
103
|
-
const _ao2 = (input, _path, _exceptionable = true) => ("string" === typeof input.code ||
|
|
103
|
+
const _ao2 = (input, _path, _exceptionable = true) => ("string" === typeof input.code || _assertGuard_1._assertGuard(_exceptionable, {
|
|
104
104
|
method: "typia.createAssert",
|
|
105
105
|
path: _path + ".code",
|
|
106
106
|
expected: "string",
|
|
107
107
|
value: input.code
|
|
108
|
-
}, _errorFactory)) && ("string" === typeof input.message ||
|
|
108
|
+
}, _errorFactory)) && ("string" === typeof input.message || _assertGuard_1._assertGuard(_exceptionable, {
|
|
109
109
|
method: "typia.createAssert",
|
|
110
110
|
path: _path + ".message",
|
|
111
111
|
expected: "string",
|
|
112
112
|
value: input.message
|
|
113
|
-
}, _errorFactory)) && ("boolean" === typeof input.retryable ||
|
|
113
|
+
}, _errorFactory)) && ("boolean" === typeof input.retryable || _assertGuard_1._assertGuard(_exceptionable, {
|
|
114
114
|
method: "typia.createAssert",
|
|
115
115
|
path: _path + ".retryable",
|
|
116
116
|
expected: "boolean",
|
|
@@ -122,7 +122,7 @@ export const assertBridgeResponse = (() => {
|
|
|
122
122
|
else if (false === input.ok)
|
|
123
123
|
return _ao1(input, _path, true && _exceptionable);
|
|
124
124
|
else
|
|
125
|
-
return
|
|
125
|
+
return _assertGuard_1._assertGuard(_exceptionable, {
|
|
126
126
|
method: "typia.createAssert",
|
|
127
127
|
path: _path,
|
|
128
128
|
expected: _ae1,
|
|
@@ -145,12 +145,12 @@ export const assertBridgeResponse = (() => {
|
|
|
145
145
|
return (input, errorFactory) => {
|
|
146
146
|
if (false === __is(input)) {
|
|
147
147
|
_errorFactory = errorFactory;
|
|
148
|
-
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input ||
|
|
148
|
+
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _assertGuard_1._assertGuard(true, {
|
|
149
149
|
method: "typia.createAssert",
|
|
150
150
|
path: _path + "",
|
|
151
151
|
expected: _ae0,
|
|
152
152
|
value: input
|
|
153
|
-
}, _errorFactory)) && _au0(input, _path + "", true) ||
|
|
153
|
+
}, _errorFactory)) && _au0(input, _path + "", true) || _assertGuard_1._assertGuard(true, {
|
|
154
154
|
method: "typia.createAssert",
|
|
155
155
|
path: _path + "",
|
|
156
156
|
expected: _ae0,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import { type BridgeRpcPrefix, type BridgeRpcRouter } from './orpc.js';
|
|
3
|
+
export interface CreateBridgeRpcNodeHandlerOptions {
|
|
4
|
+
readonly maxBodySize?: number;
|
|
5
|
+
readonly prefix?: BridgeRpcPrefix;
|
|
6
|
+
}
|
|
7
|
+
export type BridgeRpcNodeHandler = (request: IncomingMessage, response: ServerResponse) => Promise<boolean>;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a bridge transport that writes oRPC responses directly to Node HTTP.
|
|
10
|
+
* The boolean result is false when another route should handle the request.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createBridgeRpcNodeHandler(router: BridgeRpcRouter, options?: CreateBridgeRpcNodeHandlerOptions): BridgeRpcNodeHandler;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { BodyLimitHandlerPlugin, RPCHandler } from '@orpc/server/node';
|
|
2
|
+
import { defaultBridgeRpcEndpoint } from './orpc.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a bridge transport that writes oRPC responses directly to Node HTTP.
|
|
5
|
+
* The boolean result is false when another route should handle the request.
|
|
6
|
+
*/
|
|
7
|
+
export function createBridgeRpcNodeHandler(router, options = {}) {
|
|
8
|
+
const handler = new RPCHandler(router, {
|
|
9
|
+
plugins: [
|
|
10
|
+
new BodyLimitHandlerPlugin({
|
|
11
|
+
maxBodySize: options.maxBodySize ?? 1000000,
|
|
12
|
+
}),
|
|
13
|
+
],
|
|
14
|
+
});
|
|
15
|
+
const prefix = options.prefix ?? defaultBridgeRpcEndpoint;
|
|
16
|
+
return async (request, response) => {
|
|
17
|
+
try {
|
|
18
|
+
const result = await handler.handle(request, response, {
|
|
19
|
+
prefix,
|
|
20
|
+
context: {
|
|
21
|
+
request,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
return result.matched;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
console.error('Bridge RPC internal error:', error);
|
|
28
|
+
finishInternalErrorResponse(response);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function finishInternalErrorResponse(response) {
|
|
34
|
+
if (response.headersSent) {
|
|
35
|
+
if (!response.writableEnded) {
|
|
36
|
+
response.destroy();
|
|
37
|
+
}
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (response.destroyed) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const payload = JSON.stringify({
|
|
44
|
+
error: 'BRIDGE_RPC_INTERNAL_ERROR',
|
|
45
|
+
});
|
|
46
|
+
response.statusCode = 500;
|
|
47
|
+
response.setHeader('cache-control', 'no-store');
|
|
48
|
+
response.setHeader('content-length', Buffer.byteLength(payload));
|
|
49
|
+
response.setHeader('content-type', 'application/json; charset=utf-8');
|
|
50
|
+
response.setHeader('x-content-type-options', 'nosniff');
|
|
51
|
+
response.end(payload);
|
|
52
|
+
}
|
package/dist/orpc.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { StandardUrl } from '@orpc/client/standard';
|
|
2
2
|
import { type RouterContractClient } from '@orpc/contract';
|
|
3
|
-
import { type BridgeRequest, type BridgeResponse } from './index';
|
|
3
|
+
import { type BridgeRequest, type BridgeResponse } from './index.js';
|
|
4
4
|
export type BridgeRpcEndpoint = StandardUrl;
|
|
5
5
|
export type BridgeRpcPrefix = `/${string}`;
|
|
6
6
|
export declare const defaultBridgeRpcEndpoint = "/api/mpgd/rpc";
|
package/dist/orpc.js
CHANGED
|
@@ -3,7 +3,7 @@ import { RPCLink } from '@orpc/client/fetch';
|
|
|
3
3
|
import { oc, type as orpcType } from '@orpc/contract';
|
|
4
4
|
import { implement } from '@orpc/server';
|
|
5
5
|
import { RPCHandler } from '@orpc/server/fetch';
|
|
6
|
-
import { assertBridgeRequest, createBridgeError, } from './index';
|
|
6
|
+
import { assertBridgeRequest, createBridgeError, } from './index.js';
|
|
7
7
|
export const defaultBridgeRpcEndpoint = '/api/mpgd/rpc';
|
|
8
8
|
export const bridgeRpcContract = oc.router({
|
|
9
9
|
request: oc.input(orpcType()).output(orpcType()),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpgd/bridge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Typed native bridge protocol for mpgd platform adapters.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -33,6 +33,10 @@
|
|
|
33
33
|
"types": "./dist/orpc.d.ts",
|
|
34
34
|
"default": "./dist/orpc.js"
|
|
35
35
|
},
|
|
36
|
+
"./orpc/node": {
|
|
37
|
+
"types": "./dist/orpc-node.d.ts",
|
|
38
|
+
"default": "./dist/orpc-node.js"
|
|
39
|
+
},
|
|
36
40
|
"./cloudflare-pages": {
|
|
37
41
|
"types": "./dist/cloudflare-pages.d.ts",
|
|
38
42
|
"default": "./dist/cloudflare-pages.js"
|
|
@@ -45,11 +49,12 @@
|
|
|
45
49
|
"@orpc/client": "2.0.0-beta.14",
|
|
46
50
|
"@orpc/contract": "2.0.0-beta.14",
|
|
47
51
|
"@orpc/server": "2.0.0-beta.14",
|
|
48
|
-
"typia": "
|
|
52
|
+
"typia": "13.0.2"
|
|
49
53
|
},
|
|
50
54
|
"devDependencies": {
|
|
51
|
-
"
|
|
52
|
-
"
|
|
55
|
+
"@types/node": "^24.0.0",
|
|
56
|
+
"ttsc": "0.18.4",
|
|
57
|
+
"typescript": "7.0.2"
|
|
53
58
|
},
|
|
54
59
|
"main": "./dist/index.js",
|
|
55
60
|
"types": "./dist/index.d.ts",
|
|
@@ -61,6 +66,6 @@
|
|
|
61
66
|
"lint": "ttsc --noEmit",
|
|
62
67
|
"format": "ttsc format",
|
|
63
68
|
"fix": "ttsc fix",
|
|
64
|
-
"test": "cd ../.. && node tools/run-ttsx.mjs packages/bridge/src/bridge-protocol.test.ts && node tools/run-ttsx.mjs packages/bridge/src/orpc.test.ts && node tools/run-ttsx.mjs packages/bridge/src/cloudflare-pages.test.ts"
|
|
69
|
+
"test": "cd ../.. && node tools/run-ttsx.mjs packages/bridge/src/bridge-protocol.test.ts && node tools/run-ttsx.mjs packages/bridge/src/orpc.test.ts && node tools/run-ttsx.mjs packages/bridge/src/orpc-node.test.ts && node tools/run-ttsx.mjs packages/bridge/src/cloudflare-pages.test.ts && node packages/bridge/test/orpc-node-dist-import.mjs"
|
|
65
70
|
}
|
|
66
71
|
}
|