Search docs
Search guides, modules and symbols
Modules

Docs / API / Modules / cookies

Cookies

Persistence

@s2script/sdk/cookies

SM-parity client preference cookies. Cookies.set / setAuthId return boolean admission — false leaves the cache unchanged; true is host-owned until DB ACK, not a durability guarantee.

Import

import { CookieAccess } from "@s2script/sdk/cookies";

Author-time types ship in the npm package; the engine injects the runtime at plugin load. Add @s2script/sdk to your plugin's dependencies.

API reference

Generated from the shipped type definitions.

enum
CookieAccess

SM-parity access level carried as metadata on a Cookie definition (client cookie-menu visibility/editability).

Public
— Visible and editable by the client in the cookie menu.
Protected
— Visible to the client but not editable.
Private
— Hidden from the client; plugin-only.
interface
CookieOptions

Options for Cookies.register.

description?: string
— Human-readable description (shown in a cookie menu).
access?: CookieAccess
— Client visibility/editability.
default?: string
— Fallback value when the client has no stored value.
const
Cookies

Entry point for registering and reading/writing client preference cookies.

register(name: string, opts?: CookieOptions): Cookie

Register (or return an existing) cookie definition. Idempotent per plugin context — the same name returns the already-registered Cookie.

import { Cookies } from "@s2script/sdk/cookies";
const boots = Cookies.register("demo_boots", { default: "0" });
const n = parseInt(Cookies.get(client, boots), 10);
get(client: Client, cookie: Cookie): string
— Cache value for this client (a stored "" is a real value), else the cookie's default. Default for bots.
set(client: Client, cookie: Cookie, value: string): boolean
— Accept a cache change into the bounded host persistence outbox. Returns false for invalid/stale/bot clients or exhausted capacity, without changing the cache. True remains host-owned until DB ACK; it is not a durability acknowledgement. Check false and report, shed, or retry the change.
areCached(client: Client): boolean
— Has this client's cookies finished loading from the DB?
getTime(client: Client, cookie: Cookie): number
— Unix timestamp of the cookie's last write (set or DB load), or 0 if never set. 0 for bots.
setAuthId(steamId: string, cookie: Cookie, value: string): boolean
— Accept an online or offline SteamID cookie change under the same bounded admission contract as set. False leaves both cache and outbox unchanged (including empty/"0" identity). Accepted writes survive clientprefs reload and same-process core reinit, but not process exit or library destruction.
Back to modules All packages