@seekprotocol/game 0.1.0 → 0.1.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@seekprotocol/game",
3
- "version": "0.1.0",
4
- "description": "GameKit: the browser bridge a Seek minigame imports to talk to the Seek app.",
3
+ "version": "0.1.1",
4
+ "description": "GameKit: the bridge between a minigame and the Seek app.",
5
5
  "author": {
6
6
  "name": "Seek Protocol",
7
7
  "url": "https://www.seekprotocol.ai/en"
@@ -11,7 +11,6 @@
11
11
  "seek",
12
12
  "seekprotocol",
13
13
  "quests",
14
- "location-based",
15
14
  "games"
16
15
  ],
17
16
  "license": "MIT",
package/perf.d.ts CHANGED
@@ -1,15 +1,3 @@
1
- /**
2
- * Seekprotocol Vitals: how smooth a game runs, measured in the game itself.
3
- *
4
- * Each heartbeat carries what happened since the one before: frames per
5
- * second, frames that took longer than 50 ms (jank: the player feels them),
6
- * and the JavaScript heap where the browser tells it (Chrome and Android's
7
- * WebView do, Safari does not). The start entry carries how long the page
8
- * took from navigation to ready(). The frame loop is the browser's own
9
- * (`requestAnimationFrame`), so it slows down when the game blocks the main
10
- * thread, whether the game draws on a canvas or not. Nothing is measured
11
- * while the page is hidden: a phone in a pocket draws no frames.
12
- */
13
1
  export interface PerfWindow {
14
2
  requestAnimationFrame?: (fn: (t: number) => void) => number;
15
3
  cancelAnimationFrame?: (id: number) => void;
@@ -24,20 +12,14 @@ export interface PerfWindow {
24
12
  };
25
13
  }
26
14
  export interface PerfSample {
27
- /** Frames per second since the last sample, while visible. */
28
15
  fps?: number;
29
- /** Frames that took longer than 50 ms since the last sample. */
30
16
  jank?: number;
31
- /** The JavaScript heap in MB, where the browser reports it. */
32
17
  heap_mb?: number;
33
18
  }
34
19
  export interface PerfSampler {
35
- /** What happened since the last call; empty when nothing could be measured. */
36
20
  sample(): PerfSample;
37
- /** ms from navigation to now, or undefined without a performance clock. */
38
21
  sinceLoad(): number | undefined;
39
22
  stop(): void;
40
23
  }
41
- /** A frame longer than this is one the player notices. */
42
24
  export declare const JANK_FRAME_MS = 50;
43
25
  export declare function createPerfSampler(win: PerfWindow): PerfSampler;
package/protocol.d.ts CHANGED
@@ -1,35 +1,18 @@
1
- /**
2
- * The GameKit protocol between a minigame and its host.
3
- *
4
- * The host is the Seek app's WebView (or Store Connect's simulator in an
5
- * iframe). Every message is a small JSON object tagged `seek: 'seek-game'`
6
- * with the protocol version `v`. The game sends requests with an `id`; the
7
- * host answers each with `re: <id>` and `ok`. The host may also send events
8
- * (`pause`, `resume`, `exit`). Shapes and sizes are checked on both sides, and
9
- * the proxy (`seek-gameproxy`) runs the very same checks on storage and track.
10
- *
11
- * No dependencies and no DOM, so the Workers import this file too.
12
- */
13
1
  export declare const PROTOCOL: "seek-game";
14
2
  export declare const PROTOCOL_VERSION: 1;
15
3
  export declare const BRIDGE_VERSION = "0.1.0";
16
- /** The largest message either side sends or accepts, as UTF-8 JSON. */
17
4
  export declare const MAX_MESSAGE_BYTES: number;
18
- /** What one player may keep per game, all keys together, as UTF-8 JSON of the whole object. */
19
5
  export declare const STORAGE_MAX_BYTES: number;
20
6
  export declare const STORAGE_KEY: RegExp;
21
7
  export declare const TRACK_EVENT: RegExp;
22
8
  export declare const TRACK_PROP_KEY: RegExp;
23
9
  export declare const TRACK_MAX_PROPS = 8;
24
10
  export declare const TRACK_MAX_STRING = 64;
25
- /** The longest launch token the bridge accepts from a host. */
26
11
  export declare const MAX_TOKEN_LENGTH = 4096;
27
- /** Where storage and track go when the host does not relay them. Fixed: a host cannot point the token elsewhere. */
28
12
  export declare const PROXY_ORIGIN = "https://api.play.seekprotocol.ai";
29
- /** Frame hosts the bridge talks to by default: Store Connect's simulator. The app talks through its native channel. */
30
13
  export declare const DEFAULT_HOST_ORIGINS: readonly string[];
31
- export type GameRequestType = 'ready' | 'finish' | 'storage.get' | 'storage.set' | 'storage.remove' | 'track' | 'heartbeat' | 'diagnostics';
32
- export type HostEventType = 'pause' | 'resume' | 'exit';
14
+ export type GameRequestType = "ready" | "finish" | "storage.get" | "storage.set" | "storage.remove" | "track" | "heartbeat" | "diagnostics";
15
+ export type HostEventType = "pause" | "resume" | "exit";
33
16
  export interface GameRequest {
34
17
  seek: typeof PROTOCOL;
35
18
  v: typeof PROTOCOL_VERSION;
@@ -53,47 +36,26 @@ export interface HostEvent {
53
36
  v: typeof PROTOCOL_VERSION;
54
37
  event: HostEventType;
55
38
  }
56
- /** What the host answers to `ready`. */
57
39
  export interface ReadyPayload {
58
- /** The launch token from platform-quest `run_start`. */
59
40
  token: string;
60
- /** `proxy` (default): storage, track and Vitals go to the proxy with the token. `host`: the host relays them. */
61
- transport?: 'proxy' | 'host';
41
+ transport?: "proxy" | "host";
62
42
  }
63
- /** What a game knows about its run, from the launch token's claims. */
64
43
  export interface LaunchInfo {
65
44
  runId: string;
66
- /** Use it for anything random, so a run can be checked. */
67
45
  seed: number;
68
- /** The player's language, BCP 47 (`en`, `nl`, `pt-BR`). */
69
46
  lang: string;
70
- /** The player, pseudonymous: the same for this game across runs, different in every other game. */
71
47
  sub: string;
72
- /** The game's app id: `<gameId>-<16 hex>`. */
73
48
  game: string;
74
- /** The game hash that is running. */
75
49
  version: string;
76
- /** When the token stops working, in ms since 1970. */
77
50
  expiresAt: number;
78
51
  }
79
52
  export declare const utf8Bytes: (s: string) => number;
80
- /** UTF-8 size of a value as JSON, or Infinity when it is not JSON. */
81
53
  export declare function jsonBytes(value: unknown): number;
82
- /** Plain JSON only: no functions, no cycles, no NaN. */
83
54
  export declare function isJsonValue(v: unknown, depth?: number): boolean;
84
55
  export declare const storageKeyProblem: (key: unknown) => string | null;
85
56
  export type TrackProps = Record<string, string | number | boolean>;
86
- /** Why an analytics event cannot be sent, or null. Events are counted, not stored per player. */
87
57
  export declare function trackProblem(event: unknown, props: unknown): string | null;
88
- /** A score report the host will pass on to platform-quest. */
89
58
  export declare function finishProblem(r: unknown): string | null;
90
- /** A message from the host, checked, or null to ignore it. Strings (the native channel) are parsed. */
91
59
  export declare function parseHostMessage(data: unknown): HostReply | HostEvent | null;
92
- /** A request from a game, checked: what a host runs before acting on one. */
93
60
  export declare function parseGameRequest(data: unknown): GameRequest | null;
94
- /**
95
- * The claims of a launch token, read without checking the signature: a game
96
- * cannot check it and does not need to; the proxy does. Null when the token
97
- * is not one.
98
- */
99
61
  export declare function decodeLaunchToken(token: unknown): LaunchInfo | null;