@mpgd/adapter-devvit 0.6.0 → 0.7.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/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { type BridgeRequest, type BridgeResponse } from '@mpgd/bridge';
2
2
  import { type BridgeRpcClient, type BridgeRpcEndpoint } from '@mpgd/bridge/orpc';
3
3
  import type { PlatformGateway } from '@mpgd/platform';
4
- export declare const defaultDevvitBridgeEndpoint = "/api/mpgd/bridge";
5
4
  export declare const defaultDevvitRpcEndpoint = "/api/mpgd/rpc";
6
5
  type BridgeErrorResponse = Extract<BridgeResponse, {
7
6
  readonly ok: false;
@@ -20,7 +19,6 @@ export interface DevvitPlatformGatewayOptions {
20
19
  readonly buildId: string;
21
20
  readonly bridge?: DevvitBridge;
22
21
  readonly fallbackBridge?: DevvitBridge;
23
- readonly endpoint?: string;
24
22
  readonly rpcEndpoint?: BridgeRpcEndpoint;
25
23
  }
26
24
  export declare function createDevvitPlatformGateway(input: DevvitPlatformGatewayOptions): PlatformGateway;
@@ -29,9 +27,5 @@ export declare function createDevvitOrpcBridge(input?: {
29
27
  readonly fetch?: typeof fetch | undefined;
30
28
  readonly client?: BridgeRpcClient | undefined;
31
29
  }): DevvitBridge;
32
- export declare function createDevvitFetchBridge(input?: {
33
- readonly endpoint?: string | undefined;
34
- readonly fetch?: typeof fetch | undefined;
35
- }): DevvitBridge;
36
30
  export declare function createDevvitSandboxBridge(): DevvitBridge;
37
31
  export {};
package/dist/index.js CHANGED
@@ -1,6 +1,5 @@
1
- import { assertBridgeResponse, createBridgeError, } from '@mpgd/bridge';
1
+ import { createBridgeError, } from '@mpgd/bridge';
2
2
  import { createBridgeOrpcClient, defaultBridgeRpcEndpoint, } from '@mpgd/bridge/orpc';
3
- export const defaultDevvitBridgeEndpoint = '/api/mpgd/bridge';
4
3
  export const defaultDevvitRpcEndpoint = defaultBridgeRpcEndpoint;
5
4
  const devvitFallbackStoragePrefix = 'mpgd:devvit:fallback:';
6
5
  export class DevvitBridgeError extends Error {
@@ -21,9 +20,7 @@ export function createDevvitPlatformGateway(input) {
21
20
  const bridge = input.bridge ??
22
21
  getBridge() ??
23
22
  input.fallbackBridge ??
24
- (input.endpoint === undefined
25
- ? createDevvitOrpcBridge({ endpoint: input.rpcEndpoint })
26
- : createDevvitFetchBridge({ endpoint: input.endpoint }));
23
+ createDevvitOrpcBridge({ endpoint: input.rpcEndpoint });
27
24
  const response = await bridge.request({
28
25
  id: generateRequestId(),
29
26
  method,
@@ -204,40 +201,6 @@ export function createDevvitOrpcBridge(input = {}) {
204
201
  },
205
202
  };
206
203
  }
207
- export function createDevvitFetchBridge(input = {}) {
208
- const endpoint = input.endpoint ?? defaultDevvitBridgeEndpoint;
209
- return {
210
- async request(bridgeRequest) {
211
- const fetchImpl = input.fetch ?? globalThis.fetch;
212
- if (typeof fetchImpl !== 'function') {
213
- return createBridgeError(bridgeRequest.id, 'DEVVIT_FETCH_UNAVAILABLE', 'Devvit bridge fetch is not available.', false);
214
- }
215
- let response;
216
- try {
217
- response = await fetchImpl(endpoint, {
218
- method: 'POST',
219
- headers: {
220
- 'content-type': 'application/json',
221
- },
222
- body: JSON.stringify(bridgeRequest),
223
- });
224
- }
225
- catch (error) {
226
- return createBridgeError(bridgeRequest.id, 'DEVVIT_BRIDGE_NETWORK_ERROR', `Devvit bridge network request failed: ${errorMessage(error)}`, true);
227
- }
228
- if (!response.ok) {
229
- return createBridgeError(bridgeRequest.id, 'DEVVIT_BRIDGE_HTTP_ERROR', `Devvit bridge request failed with HTTP ${response.status}.`, response.status >= 500);
230
- }
231
- try {
232
- const body = await response.json();
233
- return assertBridgeResponse(body);
234
- }
235
- catch (error) {
236
- return createBridgeError(bridgeRequest.id, 'DEVVIT_BRIDGE_PARSE_ERROR', `Devvit bridge response was not valid JSON: ${errorMessage(error)}`, false);
237
- }
238
- },
239
- };
240
- }
241
204
  function getBridge() {
242
205
  const globalBridgeHost = globalThis;
243
206
  return globalBridgeHost.__DEVVIT_GAME_PLATFORM_BRIDGE__ ?? globalBridgeHost.__GAME_PLATFORM_BRIDGE__;
@@ -411,7 +374,6 @@ function removeDevvitStorageFallback(key, namespace) {
411
374
  if (namespace !== undefined) {
412
375
  storage.removeItem(devvitStorageFallbackKey(key, namespace));
413
376
  }
414
- storage.removeItem(legacyDevvitStorageFallbackKey(key));
415
377
  }
416
378
  }
417
379
  function hasDevvitStorageFallbackCandidate(key, appVersion) {
@@ -435,9 +397,6 @@ function devvitStorageFallbackNamespace(appVersion, playerId) {
435
397
  function devvitStorageFallbackKey(key, namespace) {
436
398
  return `${devvitFallbackStoragePrefix}${namespace}:${encodeURIComponent(key)}`;
437
399
  }
438
- function legacyDevvitStorageFallbackKey(key) {
439
- return `${devvitFallbackStoragePrefix}${encodeURIComponent(key)}`;
440
- }
441
400
  function browserLocalStorage() {
442
401
  try {
443
402
  return globalThis.localStorage;
@@ -1,4 +1,4 @@
1
- import { assertGetVerifiedLeaderboardSnapshotRequest, assertRecordVerifiedLeaderboardAttemptRequest, assertRecordVerifiedLeaderboardAttemptResponse, assertVerifiedLeaderboardAttempt, assertVerifiedLeaderboardDefinition, assertVerifiedLeaderboardSnapshot, createVerifiedLeaderboardCursor, parseVerifiedLeaderboardCursor, } from '@mpgd/game-services/verified-leaderboard';
1
+ import { areVerifiedLeaderboardMetricsEqual, assertGetVerifiedLeaderboardSnapshotRequest, assertRecordVerifiedLeaderboardAttemptRequest, assertRecordVerifiedLeaderboardAttemptResponse, assertVerifiedLeaderboardAttempt, assertVerifiedLeaderboardDefinition, assertVerifiedLeaderboardSnapshot, createVerifiedLeaderboardCursor, normalizeVerifiedLeaderboardMetrics, parseVerifiedLeaderboardCursor, } from '@mpgd/game-services/verified-leaderboard';
2
2
  const defaultKeyPrefix = 'mpgd:verified-leaderboard:v1';
3
3
  const defaultSnapshotLimit = 10;
4
4
  const defaultTransactionAttempts = 3;
@@ -256,6 +256,9 @@ function toRankedEntries(rankedAttempts) {
256
256
  : { participantLabel: attempt.participantLabel }),
257
257
  attemptId: attempt.attemptId,
258
258
  score: attempt.score,
259
+ ...(attempt.metrics === undefined
260
+ ? {}
261
+ : { metrics: normalizeVerifiedLeaderboardMetrics(attempt.metrics) }),
259
262
  completedAt: attempt.completedAt,
260
263
  }));
261
264
  }
@@ -305,6 +308,7 @@ function assertSameAttempt(existing, candidate) {
305
308
  if (existing.participantId !== candidate.participantId
306
309
  || existing.attemptId !== candidate.attemptId
307
310
  || existing.score !== candidate.score
311
+ || !areVerifiedLeaderboardMetricsEqual(existing.metrics, candidate.metrics)
308
312
  || Date.parse(existing.completedAt) !== Date.parse(candidate.completedAt)
309
313
  || existing.verification.authorityId !== candidate.verification.authorityId
310
314
  || existing.verification.evidenceId !== candidate.verification.evidenceId
@@ -376,6 +380,9 @@ function cloneAttempt(input) {
376
380
  : { participantLabel: input.participantLabel }),
377
381
  attemptId: input.attemptId,
378
382
  score: input.score,
383
+ ...(input.metrics === undefined
384
+ ? {}
385
+ : { metrics: normalizeVerifiedLeaderboardMetrics(input.metrics) }),
379
386
  completedAt: input.completedAt,
380
387
  verification: {
381
388
  authorityId: input.verification.authorityId,
@@ -397,6 +404,9 @@ function cloneRecordResponse(input, alreadyProcessed) {
397
404
  : { participantLabel: input.entry.participantLabel }),
398
405
  attemptId: input.entry.attemptId,
399
406
  score: input.entry.score,
407
+ ...(input.entry.metrics === undefined
408
+ ? {}
409
+ : { metrics: normalizeVerifiedLeaderboardMetrics(input.entry.metrics) }),
400
410
  completedAt: input.entry.completedAt,
401
411
  },
402
412
  ...(input.reason === undefined ? {} : { reason: input.reason }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpgd/adapter-devvit",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Reddit Devvit Web platform adapter for mpgd games.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -46,10 +46,10 @@
46
46
  "dist"
47
47
  ],
48
48
  "dependencies": {
49
- "@devvit/web": "0.13.7",
49
+ "@devvit/web": "0.13.8",
50
50
  "@mpgd/bridge": "0.6.0",
51
- "@mpgd/platform": "0.5.1",
52
- "@mpgd/game-services": "0.6.0"
51
+ "@mpgd/game-services": "0.7.0",
52
+ "@mpgd/platform": "0.5.1"
53
53
  },
54
54
  "devDependencies": {
55
55
  "ttsc": "0.18.4",