scorezilla 0.4.0 → 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.
@@ -160,6 +160,9 @@ interface RankedEntry {
160
160
  /** Milliseconds since epoch. */
161
161
  submittedAt: number;
162
162
  metadata?: Record<string, unknown>;
163
+ /** The player's public display name, when they've set one. Absent on older
164
+ * entries and for players who submit without a name. */
165
+ name?: string;
163
166
  }
164
167
  /** Payload from `POST /v1/boards/:boardId/scores`. */
165
168
  interface SubmitScoreResponse {
@@ -217,171 +220,4 @@ interface WindowAroundResponse {
217
220
  entries: RankedEntry[];
218
221
  }
219
222
 
220
- /**
221
- * SDK error type.
222
- *
223
- * Every non-2xx API response is normalized into a `ScorezillaError` instance
224
- * by the transport layer. Network failures and timeouts surface as the same
225
- * class (with `status: 0`) so callers have a single error type to catch.
226
- *
227
- * **Invariant — consumers MUST branch on `code` (and optionally `reason`),
228
- * never on `message`.** The English-language `message` is for operator
229
- * logging only and is explicitly **not** part of the SemVer contract; a
230
- * minor release MAY reword any message. Machine logic that depends on
231
- * message text will break silently across upgrades.
232
- */
233
-
234
- /**
235
- * Options for {@link ScorezillaError.from}.
236
- *
237
- * The fields mirror what's available after a fetch round-trip: the HTTP
238
- * status, the parsed JSON body (if any), the request ID from
239
- * `X-Request-Id`, and an optional `cause` for the underlying
240
- * network/abort error.
241
- */
242
- interface ScorezillaErrorFromInit {
243
- status: number;
244
- body?: ApiError | undefined;
245
- requestId?: string | undefined;
246
- cause?: unknown;
247
- }
248
- /**
249
- * Thrown by the SDK for every failure path — non-2xx responses, network
250
- * errors, aborts, and timeouts.
251
- *
252
- * Cross-realm `instanceof` is guaranteed: the class sets `Error.prototype`
253
- * explicitly so checks survive iframe / worker boundaries.
254
- *
255
- * @example
256
- * ```ts
257
- * try {
258
- * await sz.submitScore({ boardId, playerId, score });
259
- * } catch (e) {
260
- * if (!(e instanceof ScorezillaError)) throw e;
261
- *
262
- * if (e.isRateLimited()) {
263
- * await sleep((e.retryAfter ?? 30) * 1000);
264
- * return retry();
265
- * }
266
- * if (e.code === 'out_of_bounds') {
267
- * console.warn(`Score crosses ${e.reason} bound (limit ${e.bound})`);
268
- * return;
269
- * }
270
- * if (e.isAuth()) throw new Error('SDK misconfigured — bad publicKey');
271
- *
272
- * // Anything else: surface to your reporter with requestId for support.
273
- * console.error(`Scorezilla ${e.code} (${e.status}) — request ${e.requestId}`);
274
- * throw e;
275
- * }
276
- * ```
277
- *
278
- * @since 0.1.0
279
- * @stability stable
280
- */
281
- declare class ScorezillaError extends Error {
282
- /** HTTP status of the response, or {@link STATUS_NETWORK_ERROR} (0) for
283
- * network / abort / timeout. */
284
- readonly status: number;
285
- /** Machine-stable error code from the API. Open union — see
286
- * {@link ScorezillaErrorCode}. For network errors, this is `'network_error'`;
287
- * for aborts, `'aborted'`; for timeouts, `'timeout'`. */
288
- readonly code: ScorezillaErrorCode;
289
- /** Sub-classifier — present on:
290
- * - `out_of_bounds`: `'below_min' | 'above_max'`
291
- * - `usage_cap_exceeded`: `'over_cap' | 'suspended'`
292
- * and possibly other codes in future minor releases. */
293
- readonly reason: OutOfBoundsReason | UsageCapReason | string | undefined;
294
- /** Seconds — present on `rate_limited`. Honored by the transport's retry
295
- * policy (Step 2.4). */
296
- readonly retryAfter: number | undefined;
297
- /** Server-issued request ID, lifted from the `X-Request-Id` response
298
- * header. Pass this to support when filing bugs. */
299
- readonly requestId: string | undefined;
300
- /** The bound value crossed on `out_of_bounds`. */
301
- readonly bound: number | undefined;
302
- /** Which rate-limit layer fired on `rate_limited`. */
303
- readonly layer: string | undefined;
304
- /** Tenant's billing tier — present on `usage_cap_exceeded`. */
305
- readonly tier: BillingTier | undefined;
306
- /** The cap value crossed on `usage_cap_exceeded`. `0` indicates a
307
- * suspended tenant. `undefined` on all other error codes. */
308
- readonly cap: number | undefined;
309
- /** The post-increment submit count on `usage_cap_exceeded`. Always
310
- * `> cap` when `reason === 'over_cap'`. */
311
- readonly count: number | undefined;
312
- /** The period the count belongs to on `usage_cap_exceeded`, in `YYYY-MM`
313
- * UTC form. */
314
- readonly period: string | undefined;
315
- /** ISO-8601 timestamp of midnight UTC on the 1st of the next month —
316
- * the counter's natural reset point on `usage_cap_exceeded`. */
317
- readonly resetsAt: string | undefined;
318
- /** The underlying cause (e.g., a `TypeError: fetch failed`) for
319
- * network/abort/timeout paths. `undefined` when the error came from a
320
- * successfully-parsed API error body. */
321
- readonly cause: unknown;
322
- constructor(message: string, init: {
323
- status: number;
324
- code: ScorezillaErrorCode;
325
- reason?: string | undefined;
326
- retryAfter?: number | undefined;
327
- requestId?: string | undefined;
328
- bound?: number | undefined;
329
- layer?: string | undefined;
330
- tier?: BillingTier | undefined;
331
- cap?: number | undefined;
332
- count?: number | undefined;
333
- period?: string | undefined;
334
- resetsAt?: string | undefined;
335
- cause?: unknown;
336
- });
337
- /** `true` when this error is a 429 / `rate_limited`. */
338
- isRateLimited(): boolean;
339
- /**
340
- * `true` when this error is a 402 / `usage_cap_exceeded`. The tenant
341
- * has either hit their tier's monthly submit cap (`reason ===
342
- * 'over_cap'`) or is suspended (`reason === 'suspended'`).
343
- *
344
- * Consumers SHOULD NOT auto-retry on this error — the cap doesn't lift
345
- * until `resetsAt`. Surface to the developer with an upgrade prompt
346
- * (over_cap) or contact-support message (suspended).
347
- */
348
- isUsageCapExceeded(): boolean;
349
- /** `true` when this error is a 402 + reason 'suspended' (vs over-cap). */
350
- isSuspended(): boolean;
351
- /** `true` when this error is a 401 / `unauthorized` (or 403 / `forbidden`). */
352
- isAuth(): boolean;
353
- /** `true` when this error is a 404 / `not_found`. */
354
- isNotFound(): boolean;
355
- /** `true` when this error is a 422 / `out_of_bounds` (score below/above board limit). */
356
- isOutOfBounds(): boolean;
357
- /** `true` for the SDK's retryable conditions: pure network errors, 5xx, and
358
- * 429. Deliberately excludes `timeout` and `aborted` — those are caller-
359
- * observable terminal states, not transient. Aligned with `shouldRetryError`
360
- * in `retry.ts` so a consumer mirroring the SDK's retry policy gets the
361
- * same answer the transport does. */
362
- isTransient(): boolean;
363
- /** `true` when this error is a 409 / `conflict` (idempotency-key conflict
364
- * on retry). */
365
- isConflict(): boolean;
366
- /**
367
- * Build a `ScorezillaError` from a fetch round-trip outcome.
368
- *
369
- * Prefer this over `new ScorezillaError(...)` from the transport layer —
370
- * it does the mapping from API response shape to error fields in one
371
- * place, so future fields like `correlationId` get added once here.
372
- *
373
- * @param init - status, optional parsed body, optional requestId, optional cause
374
- */
375
- static from(init: ScorezillaErrorFromInit): ScorezillaError;
376
- /**
377
- * Build a `ScorezillaError` for a transport-level failure (no HTTP
378
- * response received): network error, abort, or timeout.
379
- */
380
- static network(message: string, cause: unknown): ScorezillaError;
381
- /** Build a `ScorezillaError` for an `AbortSignal`-triggered cancellation. */
382
- static aborted(cause: unknown): ScorezillaError;
383
- /** Build a `ScorezillaError` for a request that exceeded its timeout budget. */
384
- static timeout(timeoutMs: number): ScorezillaError;
385
- }
386
-
387
- export { type ApiSuccess as A, type BaseConfig as B, type FetchImpl as F, type LeaderboardResponse as L, type OutOfBoundsReason as O, type PlayerRankResponse as P, type RankedEntry as R, type ScorezillaConfig as S, type WindowAroundResponse as W, type SubmitScoreResponse as a, type ApiError as b, type ApiResponse as c, type PublicKeyConfig as d, ScorezillaError as e, type ScorezillaErrorCode as f, type SecretKeyConfig as g };
223
+ export type { ApiError as A, BillingTier as B, FetchImpl as F, LeaderboardResponse as L, OutOfBoundsReason as O, PublicKeyConfig as P, RankedEntry as R, ScorezillaErrorCode as S, UsageCapReason as U, WindowAroundResponse as W, ScorezillaConfig as a, ApiSuccess as b, SubmitScoreResponse as c, PlayerRankResponse as d, ApiResponse as e, BaseConfig as f, SecretKeyConfig as g };
@@ -160,6 +160,9 @@ interface RankedEntry {
160
160
  /** Milliseconds since epoch. */
161
161
  submittedAt: number;
162
162
  metadata?: Record<string, unknown>;
163
+ /** The player's public display name, when they've set one. Absent on older
164
+ * entries and for players who submit without a name. */
165
+ name?: string;
163
166
  }
164
167
  /** Payload from `POST /v1/boards/:boardId/scores`. */
165
168
  interface SubmitScoreResponse {
@@ -217,171 +220,4 @@ interface WindowAroundResponse {
217
220
  entries: RankedEntry[];
218
221
  }
219
222
 
220
- /**
221
- * SDK error type.
222
- *
223
- * Every non-2xx API response is normalized into a `ScorezillaError` instance
224
- * by the transport layer. Network failures and timeouts surface as the same
225
- * class (with `status: 0`) so callers have a single error type to catch.
226
- *
227
- * **Invariant — consumers MUST branch on `code` (and optionally `reason`),
228
- * never on `message`.** The English-language `message` is for operator
229
- * logging only and is explicitly **not** part of the SemVer contract; a
230
- * minor release MAY reword any message. Machine logic that depends on
231
- * message text will break silently across upgrades.
232
- */
233
-
234
- /**
235
- * Options for {@link ScorezillaError.from}.
236
- *
237
- * The fields mirror what's available after a fetch round-trip: the HTTP
238
- * status, the parsed JSON body (if any), the request ID from
239
- * `X-Request-Id`, and an optional `cause` for the underlying
240
- * network/abort error.
241
- */
242
- interface ScorezillaErrorFromInit {
243
- status: number;
244
- body?: ApiError | undefined;
245
- requestId?: string | undefined;
246
- cause?: unknown;
247
- }
248
- /**
249
- * Thrown by the SDK for every failure path — non-2xx responses, network
250
- * errors, aborts, and timeouts.
251
- *
252
- * Cross-realm `instanceof` is guaranteed: the class sets `Error.prototype`
253
- * explicitly so checks survive iframe / worker boundaries.
254
- *
255
- * @example
256
- * ```ts
257
- * try {
258
- * await sz.submitScore({ boardId, playerId, score });
259
- * } catch (e) {
260
- * if (!(e instanceof ScorezillaError)) throw e;
261
- *
262
- * if (e.isRateLimited()) {
263
- * await sleep((e.retryAfter ?? 30) * 1000);
264
- * return retry();
265
- * }
266
- * if (e.code === 'out_of_bounds') {
267
- * console.warn(`Score crosses ${e.reason} bound (limit ${e.bound})`);
268
- * return;
269
- * }
270
- * if (e.isAuth()) throw new Error('SDK misconfigured — bad publicKey');
271
- *
272
- * // Anything else: surface to your reporter with requestId for support.
273
- * console.error(`Scorezilla ${e.code} (${e.status}) — request ${e.requestId}`);
274
- * throw e;
275
- * }
276
- * ```
277
- *
278
- * @since 0.1.0
279
- * @stability stable
280
- */
281
- declare class ScorezillaError extends Error {
282
- /** HTTP status of the response, or {@link STATUS_NETWORK_ERROR} (0) for
283
- * network / abort / timeout. */
284
- readonly status: number;
285
- /** Machine-stable error code from the API. Open union — see
286
- * {@link ScorezillaErrorCode}. For network errors, this is `'network_error'`;
287
- * for aborts, `'aborted'`; for timeouts, `'timeout'`. */
288
- readonly code: ScorezillaErrorCode;
289
- /** Sub-classifier — present on:
290
- * - `out_of_bounds`: `'below_min' | 'above_max'`
291
- * - `usage_cap_exceeded`: `'over_cap' | 'suspended'`
292
- * and possibly other codes in future minor releases. */
293
- readonly reason: OutOfBoundsReason | UsageCapReason | string | undefined;
294
- /** Seconds — present on `rate_limited`. Honored by the transport's retry
295
- * policy (Step 2.4). */
296
- readonly retryAfter: number | undefined;
297
- /** Server-issued request ID, lifted from the `X-Request-Id` response
298
- * header. Pass this to support when filing bugs. */
299
- readonly requestId: string | undefined;
300
- /** The bound value crossed on `out_of_bounds`. */
301
- readonly bound: number | undefined;
302
- /** Which rate-limit layer fired on `rate_limited`. */
303
- readonly layer: string | undefined;
304
- /** Tenant's billing tier — present on `usage_cap_exceeded`. */
305
- readonly tier: BillingTier | undefined;
306
- /** The cap value crossed on `usage_cap_exceeded`. `0` indicates a
307
- * suspended tenant. `undefined` on all other error codes. */
308
- readonly cap: number | undefined;
309
- /** The post-increment submit count on `usage_cap_exceeded`. Always
310
- * `> cap` when `reason === 'over_cap'`. */
311
- readonly count: number | undefined;
312
- /** The period the count belongs to on `usage_cap_exceeded`, in `YYYY-MM`
313
- * UTC form. */
314
- readonly period: string | undefined;
315
- /** ISO-8601 timestamp of midnight UTC on the 1st of the next month —
316
- * the counter's natural reset point on `usage_cap_exceeded`. */
317
- readonly resetsAt: string | undefined;
318
- /** The underlying cause (e.g., a `TypeError: fetch failed`) for
319
- * network/abort/timeout paths. `undefined` when the error came from a
320
- * successfully-parsed API error body. */
321
- readonly cause: unknown;
322
- constructor(message: string, init: {
323
- status: number;
324
- code: ScorezillaErrorCode;
325
- reason?: string | undefined;
326
- retryAfter?: number | undefined;
327
- requestId?: string | undefined;
328
- bound?: number | undefined;
329
- layer?: string | undefined;
330
- tier?: BillingTier | undefined;
331
- cap?: number | undefined;
332
- count?: number | undefined;
333
- period?: string | undefined;
334
- resetsAt?: string | undefined;
335
- cause?: unknown;
336
- });
337
- /** `true` when this error is a 429 / `rate_limited`. */
338
- isRateLimited(): boolean;
339
- /**
340
- * `true` when this error is a 402 / `usage_cap_exceeded`. The tenant
341
- * has either hit their tier's monthly submit cap (`reason ===
342
- * 'over_cap'`) or is suspended (`reason === 'suspended'`).
343
- *
344
- * Consumers SHOULD NOT auto-retry on this error — the cap doesn't lift
345
- * until `resetsAt`. Surface to the developer with an upgrade prompt
346
- * (over_cap) or contact-support message (suspended).
347
- */
348
- isUsageCapExceeded(): boolean;
349
- /** `true` when this error is a 402 + reason 'suspended' (vs over-cap). */
350
- isSuspended(): boolean;
351
- /** `true` when this error is a 401 / `unauthorized` (or 403 / `forbidden`). */
352
- isAuth(): boolean;
353
- /** `true` when this error is a 404 / `not_found`. */
354
- isNotFound(): boolean;
355
- /** `true` when this error is a 422 / `out_of_bounds` (score below/above board limit). */
356
- isOutOfBounds(): boolean;
357
- /** `true` for the SDK's retryable conditions: pure network errors, 5xx, and
358
- * 429. Deliberately excludes `timeout` and `aborted` — those are caller-
359
- * observable terminal states, not transient. Aligned with `shouldRetryError`
360
- * in `retry.ts` so a consumer mirroring the SDK's retry policy gets the
361
- * same answer the transport does. */
362
- isTransient(): boolean;
363
- /** `true` when this error is a 409 / `conflict` (idempotency-key conflict
364
- * on retry). */
365
- isConflict(): boolean;
366
- /**
367
- * Build a `ScorezillaError` from a fetch round-trip outcome.
368
- *
369
- * Prefer this over `new ScorezillaError(...)` from the transport layer —
370
- * it does the mapping from API response shape to error fields in one
371
- * place, so future fields like `correlationId` get added once here.
372
- *
373
- * @param init - status, optional parsed body, optional requestId, optional cause
374
- */
375
- static from(init: ScorezillaErrorFromInit): ScorezillaError;
376
- /**
377
- * Build a `ScorezillaError` for a transport-level failure (no HTTP
378
- * response received): network error, abort, or timeout.
379
- */
380
- static network(message: string, cause: unknown): ScorezillaError;
381
- /** Build a `ScorezillaError` for an `AbortSignal`-triggered cancellation. */
382
- static aborted(cause: unknown): ScorezillaError;
383
- /** Build a `ScorezillaError` for a request that exceeded its timeout budget. */
384
- static timeout(timeoutMs: number): ScorezillaError;
385
- }
386
-
387
- export { type ApiSuccess as A, type BaseConfig as B, type FetchImpl as F, type LeaderboardResponse as L, type OutOfBoundsReason as O, type PlayerRankResponse as P, type RankedEntry as R, type ScorezillaConfig as S, type WindowAroundResponse as W, type SubmitScoreResponse as a, type ApiError as b, type ApiResponse as c, type PublicKeyConfig as d, ScorezillaError as e, type ScorezillaErrorCode as f, type SecretKeyConfig as g };
223
+ export type { ApiError as A, BillingTier as B, FetchImpl as F, LeaderboardResponse as L, OutOfBoundsReason as O, PublicKeyConfig as P, RankedEntry as R, ScorezillaErrorCode as S, UsageCapReason as U, WindowAroundResponse as W, ScorezillaConfig as a, ApiSuccess as b, SubmitScoreResponse as c, PlayerRankResponse as d, ApiResponse as e, BaseConfig as f, SecretKeyConfig as g };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scorezilla",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,
@@ -80,6 +80,16 @@
80
80
  "default": "./dist/identity.cjs"
81
81
  }
82
82
  },
83
+ "./headless": {
84
+ "import": {
85
+ "types": "./dist/headless.d.ts",
86
+ "default": "./dist/headless.js"
87
+ },
88
+ "require": {
89
+ "types": "./dist/headless.d.cts",
90
+ "default": "./dist/headless.cjs"
91
+ }
92
+ },
83
93
  "./phaser": {
84
94
  "import": {
85
95
  "types": "./dist/phaser.d.ts",
@@ -105,6 +115,9 @@
105
115
  ],
106
116
  "identity": [
107
117
  "./dist/identity.d.ts"
118
+ ],
119
+ "headless": [
120
+ "./dist/headless.d.ts"
108
121
  ]
109
122
  }
110
123
  },