@cookie-store/core
v0.1.0
Published
Simple in-memory mirror of the Cookie Store API for synchronous reads.
Readme
@cookie-store/core
Synchronous cache for the Cookie Store API. Mirrors cookies in memory for synchronous reads so framework bindings can stay reactive. This package is internal and not meant for general or public use.
Scope
This package targets main thread (document) usage for UI reactivity only. As the Cookie Store API docs state:
"The
urloption enables the modification of a cookie scoped under a particular URL. Service workers can obtain cookies that would be sent to any URL under their scope. From a document you may only obtain the cookies at the current URL, so the only valid URL in a document context is the document's URL."
The url (CookieStoreGetOptions) option is strictly for service workers and is omitted from this API.
Usage
import { cookieStoreCache } from '@cookie-store/core';
// Sync read
const session = cookieStoreCache.get('session');
// Writes use the native API
await window.cookieStore.set('session', 'token', {
expires: Date.now() + 86400000,
});