@mpgd/bridge 0.6.0 → 0.6.1
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.js +5 -2
- package/dist/index.d.ts +12 -0
- package/dist/index.js +25 -0
- package/package.json +1 -1
package/dist/cloudflare-pages.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assertBridgeRequest, createBridgeError, } from './index.js';
|
|
1
|
+
import { assertBridgeRequest, bridgeStorageLoadProtocol, createBridgeError, } from './index.js';
|
|
2
2
|
import { createBridgeRpcFetchHandler, createBridgeRpcRouter, defaultBridgeRpcEndpoint, } from './orpc.js';
|
|
3
3
|
export const defaultCloudflarePagesBridgeEndpoint = '/api/mpgd/bridge';
|
|
4
4
|
export const defaultCloudflarePagesGameServicesPrefix = '/api/game-services';
|
|
@@ -137,7 +137,10 @@ export function createMpgdCloudflarePagesBridgeHandler() {
|
|
|
137
137
|
case 'leaderboard.open':
|
|
138
138
|
return createBridgeError(input.bridgeRequest.id, 'CLOUDFLARE_PAGES_LEADERBOARD_OPEN_UNAVAILABLE', 'Cloudflare Pages host does not provide a native leaderboard UI.');
|
|
139
139
|
case 'storage.load':
|
|
140
|
-
return ok(input.bridgeRequest,
|
|
140
|
+
return ok(input.bridgeRequest, {
|
|
141
|
+
__mpgdBridgeProtocol: bridgeStorageLoadProtocol,
|
|
142
|
+
found: false,
|
|
143
|
+
});
|
|
141
144
|
case 'storage.save':
|
|
142
145
|
return ok(input.bridgeRequest, {
|
|
143
146
|
saved: false,
|
package/dist/index.d.ts
CHANGED
|
@@ -23,6 +23,18 @@ export type BridgeResponse<TData = unknown> = {
|
|
|
23
23
|
readonly retryable: boolean;
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
|
+
export declare const bridgeStorageLoadProtocol: 'mpgd.storage.load.v1';
|
|
27
|
+
export type BridgeStorageLoadData = {
|
|
28
|
+
readonly __mpgdBridgeProtocol: typeof bridgeStorageLoadProtocol;
|
|
29
|
+
readonly found: false;
|
|
30
|
+
} | {
|
|
31
|
+
readonly __mpgdBridgeProtocol: typeof bridgeStorageLoadProtocol;
|
|
32
|
+
readonly found: true;
|
|
33
|
+
readonly value: unknown;
|
|
34
|
+
};
|
|
26
35
|
export declare const assertBridgeRequest: (input: unknown) => BridgeRequest<unknown>;
|
|
27
36
|
export declare const assertBridgeResponse: (input: unknown) => BridgeResponse<unknown>;
|
|
37
|
+
export declare function decodeBridgeStorageLoadData(input: unknown): {
|
|
38
|
+
readonly value: unknown;
|
|
39
|
+
} | null;
|
|
28
40
|
export declare function createBridgeError(id: string, code: string, message: string, retryable?: boolean): BridgeResponse;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as _assertGuard_1 from "typia/lib/internal/_assertGuard";
|
|
2
2
|
import typia from 'typia';
|
|
3
|
+
export const bridgeStorageLoadProtocol = 'mpgd.storage.load.v1';
|
|
3
4
|
export const assertBridgeRequest = (() => {
|
|
4
5
|
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
6
|
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"]);
|
|
@@ -160,6 +161,30 @@ export const assertBridgeResponse = (() => {
|
|
|
160
161
|
return input;
|
|
161
162
|
};
|
|
162
163
|
})();
|
|
164
|
+
export function decodeBridgeStorageLoadData(input) {
|
|
165
|
+
if (input === null) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
if (input === undefined) {
|
|
169
|
+
throw new Error('Storage bridge load returned an invalid response.');
|
|
170
|
+
}
|
|
171
|
+
if (typeof input !== 'object' ||
|
|
172
|
+
!(input !== null && '__mpgdBridgeProtocol' in input) ||
|
|
173
|
+
input.__mpgdBridgeProtocol !== bridgeStorageLoadProtocol) {
|
|
174
|
+
return { value: input };
|
|
175
|
+
}
|
|
176
|
+
const response = input;
|
|
177
|
+
if (response.found === false) {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
if (response.found !== true) {
|
|
181
|
+
throw new Error('Storage bridge load returned an invalid response.');
|
|
182
|
+
}
|
|
183
|
+
if (!Object.prototype.hasOwnProperty.call(response, 'value')) {
|
|
184
|
+
throw new Error('Storage bridge load returned an invalid response.');
|
|
185
|
+
}
|
|
186
|
+
return { value: response.value };
|
|
187
|
+
}
|
|
163
188
|
export function createBridgeError(id, code, message, retryable = false) {
|
|
164
189
|
return {
|
|
165
190
|
id,
|