@vestra-player/sdk 1.5.29 → 1.5.31

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.
@@ -247,13 +247,31 @@ class Store {
247
247
  * with the key and the request around the value). The player's tests check
248
248
  * that these agree with the player.
249
249
  *
250
- * @example
250
+ * @example Remember a position per URL without breaking the limits
251
+ * The plugin keeps the last position of each URL for this player session
252
+ * and skips a URL too long to be a key. Keys are counted in UTF-8 bytes, so
253
+ * the length is measured with `Buffer.byteLength`, not `length`; a `set`
254
+ * that would take the plugin's entries over 1 MiB rejects with `limit` and
255
+ * changes nothing, so the plugin clears the old entries and goes on.
251
256
  * ```ts
252
- * import assert from "node:assert/strict";
257
+ * import type { Plugin, PluginError } from "@vestra-player/sdk";
258
+ * declare const plugin: Plugin;
259
+ * declare const url: string;
260
+ * declare const position: number;
261
+ * // ---cut---
253
262
  * import { SESSION_STORAGE_LIMITS } from "@vestra-player/sdk/testing";
254
263
  *
255
- * const key = "https://example.com/a.mkv";
256
- * assert.ok(Buffer.byteLength(key) <= SESSION_STORAGE_LIMITS.keyBytes);
264
+ * const session = plugin.storage.session;
265
+ * if (Buffer.byteLength(url) <= SESSION_STORAGE_LIMITS.keyBytes) {
266
+ * try {
267
+ * await session.set(url, position);
268
+ * } catch (error) {
269
+ * if ((error as PluginError).code !== "limit") throw error;
270
+ * // Full: start over rather than lose the newest position.
271
+ * for (const key of await session.keys()) await session.delete(key);
272
+ * await session.set(url, position);
273
+ * }
274
+ * }
257
275
  * ```
258
276
  *
259
277
  * @since 1.5.25
@@ -390,11 +408,34 @@ export function system(scope) {
390
408
  * fails with code `invalid`; a new name beyond `names` fails with `limit`.
391
409
  * The player's tests check that these agree with the player.
392
410
  *
393
- * @example
411
+ * @example Store an API token only when it fits
412
+ * The plugin keeps a token the user pasted, or tells them it is empty or
413
+ * too long. Values are 1–1024 bytes counted in UTF-8, so the check uses
414
+ * `Buffer.byteLength`; `secrets.set` would refuse other values with
415
+ * `invalid`. The store itself can still refuse (`unsupported` without a
416
+ * system store, `unavailable` when it cannot be reached, `failed` when the
417
+ * user denies access): only
418
+ * those codes get the "could not be saved" message, anything else (a
419
+ * missing `secrets` capability) is a bug and is thrown on.
394
420
  * ```ts
421
+ * import type { Plugin, PluginError } from "@vestra-player/sdk";
422
+ * declare const plugin: Plugin;
423
+ * declare const token: string;
424
+ * // ---cut---
395
425
  * import { SECRET_LIMITS } from "@vestra-player/sdk/testing";
396
426
  *
397
- * assert.ok(Buffer.byteLength(token) <= SECRET_LIMITS.valueBytes);
427
+ * if (!token || Buffer.byteLength(token) > SECRET_LIMITS.valueBytes) {
428
+ * await plugin.osd.show("Paste a token of at most 1024 bytes.");
429
+ * } else {
430
+ * try {
431
+ * await plugin.secrets.set("api-token", token);
432
+ * } catch (error) {
433
+ * const { code } = error as PluginError;
434
+ * if (!["unsupported", "unavailable", "failed"].includes(code)) throw error;
435
+ * // No keychain or access denied: ask again next time.
436
+ * await plugin.osd.show("The token could not be saved.");
437
+ * }
438
+ * }
398
439
  * ```
399
440
  *
400
441
  * @since 1.5.14