UNPKG

@worker-tools/request-cookie-store

Version:

An implementation of the Cookie Store API for request handlers.

41 lines (40 loc) 2.05 kB
import type { CookieStore, CookieListItem, CookieList, CookieInit, CookieStoreGetOptions, CookieStoreDeleteOptions } from 'cookie-store-interface'; export * from 'cookie-store-interface'; /** * An implementation of the [Cookie Store API](https://wicg.github.io/cookie-store) for request handlers. * * It uses the `Cookie` header of a request to populate the store and * keeps a record of changes that can be exported as a list of `Set-Cookie` headers. * * Note that this is not a polyfill! It is intended as a cookie middleware for Cloudflare Workers, * and perhaps some other uses. */ export declare class RequestCookieStore implements CookieStore { #private; constructor(request: Request); get(name?: string): Promise<CookieListItem | null>; get(options?: CookieStoreGetOptions): Promise<CookieListItem | null>; getAll(name?: string): Promise<CookieList>; getAll(options?: CookieStoreGetOptions): Promise<CookieList>; set(name: string, value: string): Promise<void>; set(options: CookieInit): Promise<void>; delete(name: string): Promise<void>; delete(options: CookieStoreDeleteOptions): Promise<void>; /** * Exports the recorded changes to this store as a list of `Set-Cookie` headers. * * Can be passed as the `headers` field when building a new `Response`: * ```ts * new Response(body, { headers: cookieStore.headers }) * ``` */ get headers(): [string, string][]; /** Exports the entire cookie store as a `cookie` header string */ toCookieString(): string; /** Helper to turn a single `CookieInit` into a `set-cookie` string. * @deprecated Might remove/change name */ static toSetCookie(cookie: CookieInit): string; addEventListener(_type: string, _listener: EventListenerOrEventListenerObject, _options?: boolean | AddEventListenerOptions): void; dispatchEvent(_event: Event): boolean; removeEventListener(_type: string, _callback: EventListenerOrEventListenerObject, _options?: boolean | EventListenerOptions): void; }