@vestra-player/sdk - v1.11.3
    Preparing search index...

    Interface Secrets

    Per-plugin secrets (API keys, passwords) in the system's secret store: the login keychain on macOS, the Credential Manager on Windows. Needs secrets. unsupported on systems without a store, unavailable when the store cannot be reached (no keychain, a read-only store, no logged-in session on Windows): keep a fallback (or ask again).

    The user denying access and other system errors reject failed. Never write secrets to settings files.

    The user types the token the first time; later runs read it from the system's secret store. get resolves null when nothing is stored; a store that is missing or refuses access rejects (unsupported, unavailable, failed), and then the plugin keeps the token for this run only and asks again next time.

    let token: string | null = null;
    try {
    token = await plugin.secrets.get("api-token");
    } catch {
    // No usable store: fall through and ask.
    }
    if (token === null) {
    token = await askUser();
    if (token)
    await plugin.secrets.set("api-token", token).catch(() => {}); // best effort
    }

    Values are stored by the player in the system's secret store under this plugin's id: other plugins cannot read them. Names are 1–64 of a-z 0-9 . _ -, values 1–1024 bytes of text, at most 256 names per plugin (SECRET_LIMITS). In a temporary window (AppInfo.temporary) get reads the main window's values and set and delete reject with unavailable (player 0.10.3).

    1.0.0

    interface Secrets {
        get(name: string): Promise<string | null>;
        set(name: string, value: string): Promise<void>;
        delete(name: string): Promise<void>;
    }
    Index
    • The stored value, null when there is none.

      Parameters

      • name: string

      Returns Promise<string | null>

      unsupported (rejects) The system has no secret store.

      unavailable (rejects) The store cannot be reached (no keychain, a read-only store, no logged-in session on Windows).

      failed (rejects) The user denied access, or another system error.

      invalid (rejects) A bad name.

      The plugin uses the token the user saved earlier, or asks for one when there is none. get resolves with the stored text or null.

      const token = await plugin.secrets.get("api-token");
      if (token === null) await plugin.osd.show("Sign in first");

      1.0.0

    • Store or replace (name: 1–64 of a-z 0-9 . _ -; value 1–1024 bytes). At most 256 different names per plugin: a new name beyond that rejects limit. Uninstalling with removeData deletes them.

      Parameters

      • name: string
      • value: string

      Returns Promise<void>

      invalid (rejects) A bad name, or a value that is empty, has NUL or is over 1024 bytes.

      limit (rejects) A new name beyond 256.

      unsupported (rejects) The system has no secret store.

      unavailable (rejects) The store cannot be reached (no keychain, a read-only store, no logged-in session on Windows), or the player is a temporary window (AppInfo.temporary, player 0.10.3), which reads the main window's secrets and saves none.

      failed (rejects) The user denied access, or another system error.

      The token the user typed is kept in the system's secret store for later runs. set stores or replaces it; the store can refuse, in which case the plugin keeps the token for this run only.

      await plugin.secrets.set("api-token", token).catch((error: PluginError) => {
      // No store, or access denied: the token is not kept for next time.
      void plugin.osd.show("The token could not be saved ({})", [error.code]);
      });

      1.0.0

    • Remove; removing a missing secret is fine.

      Parameters

      • name: string

      Returns Promise<void>

      invalid (rejects) A bad name.

      unsupported (rejects) The system has no secret store.

      unavailable (rejects) The store cannot be reached (no keychain, a read-only store, no logged-in session on Windows), or the player is a temporary window (AppInfo.temporary, player 0.10.3), which deletes none of the main window's secrets.

      failed (rejects) The user denied access, or another system error.

      Signing out removes the stored token, so the next start asks again. Removing a name that is not stored is fine.

      await plugin.secrets.delete("api-token");
      

      1.0.0