scorezilla 0.3.1 → 0.5.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,5 +1,6 @@
1
- import { S as ScorezillaConfig, A as ApiSuccess, a as SubmitScoreResponse, L as LeaderboardResponse, P as PlayerRankResponse, W as WindowAroundResponse } from './errors-CWTmormh.js';
2
- export { b as ApiError, c as ApiResponse, B as BaseConfig, O as OutOfBoundsReason, d as PublicKeyConfig, R as RankedEntry, e as ScorezillaError, f as ScorezillaErrorCode, g as SecretKeyConfig } from './errors-CWTmormh.js';
1
+ import { a as ScorezillaConfig, b as ApiSuccess, c as SubmitScoreResponse, L as LeaderboardResponse, d as PlayerRankResponse, W as WindowAroundResponse } from './types-C6VO4OWP.js';
2
+ export { A as ApiError, e as ApiResponse, f as BaseConfig, O as OutOfBoundsReason, P as PublicKeyConfig, R as RankedEntry, S as ScorezillaErrorCode, g as SecretKeyConfig } from './types-C6VO4OWP.js';
3
+ export { S as ScorezillaError } from './errors-maldlTY-.js';
3
4
 
4
5
  /**
5
6
  * `Scorezilla` — the public-key client for v0.1.0.
@@ -54,6 +55,15 @@ interface SubmitScoreInput extends CancellableInput {
54
55
  * locally before send: no functions, no symbols, no circular refs;
55
56
  * ≤ 4 KB UTF-8 bytes when JSON-stringified. */
56
57
  metadata?: Record<string, unknown> | undefined;
58
+ /** Optional public display name shown on the leaderboard. The API binds it to
59
+ * this `playerId` and rejects (`name_taken`) a name held by a different
60
+ * player on the board. 1-32 printable ASCII after trimming. */
61
+ name?: string | undefined;
62
+ /** Optional Cloudflare Turnstile token. Required only when the board has
63
+ * Turnstile gating on AND this is a cross-origin submit. Obtained by the host
64
+ * (e.g. via a hidden broker iframe on a trusted origin); the SDK just
65
+ * forwards it. */
66
+ turnstileToken?: string | undefined;
57
67
  }
58
68
  /** Input for {@link Scorezilla.getLeaderboard}. */
59
69
  interface GetLeaderboardInput extends CancellableInput {
@@ -146,22 +156,19 @@ declare class Scorezilla {
146
156
  /**
147
157
  * Fetch a single player's rank on a board.
148
158
  *
149
- * Maps to `GET /v1/boards/:boardId/players/:playerId/rank`. Returns 404
150
- * (`not_found`) if the player has no entry yet.
159
+ * Maps to `GET /v1/boards/:boardId/players/:playerId/rank`. "No entry yet"
160
+ * is a normal result, NOT an error: the response is `{ ranked: false }`
161
+ * (narrow on `ranked` before reading `rank`). A `not_found` is thrown only
162
+ * when the board itself doesn't exist.
151
163
  *
152
164
  * @example
153
165
  * ```ts
154
- * try {
155
- * const { rank, score } = await sz.getPlayerRank({ boardId, playerId: 'alice' });
156
- * console.log(`Alice is rank ${rank} with score ${score}`);
157
- * } catch (e) {
158
- * if (e instanceof ScorezillaError && e.isNotFound()) {
159
- * console.log('Alice has no submission on this board yet.');
160
- * } else throw e;
161
- * }
166
+ * const r = await sz.getPlayerRank({ boardId, playerId: 'alice' });
167
+ * if (r.ranked) console.log(`Alice is rank ${r.rank} with score ${r.score}`);
168
+ * else console.log('Alice has no submission on this board yet.');
162
169
  * ```
163
170
  *
164
- * @throws {ScorezillaError} `not_found` (player has no submission),
171
+ * @throws {ScorezillaError} `not_found` (board does not exist),
165
172
  * `network_error`, `timeout`.
166
173
  * @since 0.1.0
167
174
  * @stability stable
package/dist/index.js CHANGED
@@ -654,7 +654,7 @@ function validateMetadata(metadata) {
654
654
  }
655
655
  var Scorezilla = class _Scorezilla {
656
656
  /** The package version, injected at build time from `package.json`. */
657
- static version = "0.3.1";
657
+ static version = "0.5.0";
658
658
  #config;
659
659
  #userAgent;
660
660
  #authHeader;
@@ -709,6 +709,12 @@ var Scorezilla = class _Scorezilla {
709
709
  if (input.metadata !== void 0) {
710
710
  body.metadata = input.metadata;
711
711
  }
712
+ if (input.name !== void 0) {
713
+ body.name = input.name;
714
+ }
715
+ if (input.turnstileToken !== void 0) {
716
+ body.turnstileToken = input.turnstileToken;
717
+ }
712
718
  return this.#request({
713
719
  path: submitScorePath(input.boardId),
714
720
  method: "POST",
@@ -744,22 +750,19 @@ var Scorezilla = class _Scorezilla {
744
750
  /**
745
751
  * Fetch a single player's rank on a board.
746
752
  *
747
- * Maps to `GET /v1/boards/:boardId/players/:playerId/rank`. Returns 404
748
- * (`not_found`) if the player has no entry yet.
753
+ * Maps to `GET /v1/boards/:boardId/players/:playerId/rank`. "No entry yet"
754
+ * is a normal result, NOT an error: the response is `{ ranked: false }`
755
+ * (narrow on `ranked` before reading `rank`). A `not_found` is thrown only
756
+ * when the board itself doesn't exist.
749
757
  *
750
758
  * @example
751
759
  * ```ts
752
- * try {
753
- * const { rank, score } = await sz.getPlayerRank({ boardId, playerId: 'alice' });
754
- * console.log(`Alice is rank ${rank} with score ${score}`);
755
- * } catch (e) {
756
- * if (e instanceof ScorezillaError && e.isNotFound()) {
757
- * console.log('Alice has no submission on this board yet.');
758
- * } else throw e;
759
- * }
760
+ * const r = await sz.getPlayerRank({ boardId, playerId: 'alice' });
761
+ * if (r.ranked) console.log(`Alice is rank ${r.rank} with score ${r.score}`);
762
+ * else console.log('Alice has no submission on this board yet.');
760
763
  * ```
761
764
  *
762
- * @throws {ScorezillaError} `not_found` (player has no submission),
765
+ * @throws {ScorezillaError} `not_found` (board does not exist),
763
766
  * `network_error`, `timeout`.
764
767
  * @since 0.1.0
765
768
  * @stability stable
@@ -839,7 +842,7 @@ function createClient(config) {
839
842
  }
840
843
 
841
844
  // src/index.ts
842
- var SDK_VERSION = "0.3.1";
845
+ var SDK_VERSION = "0.5.0";
843
846
 
844
847
  export { SDK_VERSION, Scorezilla, ScorezillaError, createClient, detectRuntime };
845
848
  //# sourceMappingURL=index.js.map