Skip to main content
Module

x/request_cookie_store/index.js.map

An implementation of the Cookie Store API for request handlers.
Go to Latest
File
{"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAE9E;;;;;;;;;;GAUG;AACH,MAAM,OAAO,kBAAkB;IAC7B,OAAO,CAAa;IACpB,IAAI,GAAwB,IAAI,GAAG,EAAE,CAAC;IACtC,QAAQ,GAA4B,IAAI,GAAG,EAAE,CAAC;IAE9C,YAAY,OAAgB;QAC1B,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC7C,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC7C,IAAI,CAAC,OAAO,GAAG,CAAC,MAAM,IAAI,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,IAAI,CAAC;QACnD,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;IAID,KAAK,CAAC,GAAG,CAAC,OAAwC;QAChD,QAAQ;QACR,IAAI,OAAO,OAAO,KAAK,QAAQ;YAAE,MAAM,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAE1E,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;YAC3B,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAU,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;YAC1D,CAAC,CAAC,IAAI,CAAC;IACX,CAAC;IAID,KAAK,CAAC,MAAM,CAAC,OAAwC;QACnD,QAAQ;QACR,IAAI,OAAO,IAAI,IAAI;YAAE,MAAM,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAE9D,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,CA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AAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE;YAC1C,OAAO,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SACvD;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,kEAAkE;IAClE,cAAc;QACZ,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnE,CAAC;IAED;8CAC0C;IAC1C,MAAM,CAAC,WAAW,CAAC,MAAkB;QACnC,MAAM,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;QAC5B,OAAO,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACzC,CAAC;IAED,gBAAgB,CACd,IAAY,EACZ,QAA4C,EAC5C,OAA2C;QAE3C,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;IAC5C,CAAC;IACD,aAAa,CAAC,KAAY;QACxB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;IAC5C,CAAC;IACD,mBAAmB,CACjB,IAAY,EACZ,QAA4C,EAC5C,OAAwC;QAExC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;IAC5C,CAAC;CACF;AAED,cAAc,wBAAwB,CAAC","sourcesContent":["import { \n CookieStore, CookieListItem, CookieList, CookieInit, CookieStoreGetOptions, CookieStoreDeleteOptions,\n} from 'cookie-store-interface';\n\nimport { setCookie, attrsToSetCookie, parseCookieHeader } from './set-cookie';\n\n/**\n * # Request Cookie Store\n * An implementation of the [Cookie Store API](https://wicg.github.io/cookie-store)\n * for request handlers. \n * \n * It uses the `Cookie` header of a request to populate the store and\n * keeps a record of changes that can be exported as a list of `Set-Cookie` headers.\n * \n * Note that this is not a polyfill! It is intended as a cookie middleware for Cloudflare Workers,\n * and perhaps some other uses.\n */\nexport class RequestCookieStore implements CookieStore {\n #origin: URL | null;\n #map: Map<string, string> = new Map();\n #changes: Map<string, string[][]> = new Map();\n\n constructor(request: Request) {\n const origin = request.headers.get('origin');\n const cookie = request.headers.get('cookie');\n this.#origin = (origin && new URL(origin)) || null;\n this.#map = parseCookieHeader(cookie);\n }\n\n get(name?: string): Promise<CookieListItem | null>;\n get(options?: CookieStoreGetOptions): Promise<CookieListItem | null>;\n async get(options?: string | CookieStoreGetOptions) {\n // FIXME\n if (typeof options !== 'string') throw Error('Overload not implemented.');\n\n return this.#map.has(options)\n ? { name: options, value: <string>this.#map.get(options) }\n : null;\n }\n\n getAll(name?: string): Promise<CookieList>;\n getAll(options?: CookieStoreGetOptions): Promise<CookieList>;\n async getAll(options?: string | CookieStoreGetOptions) {\n // FIXME\n if (options != null) throw Error('Overload not implemented.');\n\n return [...this.#map.entries()].map(([name, value]) => ({ name, value }))\n }\n\n set(name: string, value: string): Promise<void>;\n set(options: CookieInit): Promise<void>;\n async set(options: string | CookieInit, value?: string) {\n const result = setCookie(options, value, this.#origin);\n if (!result) return;\n\n const [attributes, expires] = result;\n const [[name, val]] = attributes;\n this.#changes.set(name, attributes);\n\n if (expires && expires < new Date())\n this.#map.delete(name);\n else\n this.#map.set(name, val);\n }\n\n delete(name: string): Promise<void>;\n delete(options: CookieStoreDeleteOptions): Promise<void>;\n async delete(options: string | CookieStoreDeleteOptions) {\n // FIXME\n if (typeof options !== 'string') throw Error('Overload not implemented.');\n\n const expires = new Date(0);\n const value = '';\n const sameSite = 'strict';\n this.set({ name: options, expires, value, sameSite });\n }\n\n /** \n * Exports the recorded changes to this store as a list of `Set-Cookie` headers.\n * \n * Can be passed as the `headers` field when building a new `Response`:\n * ```ts\n * new Response(body, { headers: cookieStore.headers })\n * ```\n */\n get headers(): Iterable<[string, string]> {\n const headers: [string, string][] = [];\n for (const attrs of this.#changes.values()) {\n headers.push(['Set-Cookie', attrsToSetCookie(attrs)]);\n }\n return headers;\n }\n\n /** Exports the entire cookie store as a `cookie` header string */\n toCookieString() {\n return [...this.#map.entries()].map(x => x.join('=')).join('; ');\n }\n\n /** Helper to turn a single `CookieInit` into a `set-cookie` string. \n * @deprecated Might remove/change name */\n static toSetCookie(cookie: CookieInit): string {\n const x = setCookie(cookie);\n return x ? attrsToSetCookie(x[0]) : '';\n }\n\n addEventListener(\n type: string,\n listener: EventListenerOrEventListenerObject,\n options?: boolean | AddEventListenerOptions\n ): void {\n throw new Error(\"Method not implemented.\")\n }\n dispatchEvent(event: Event): boolean {\n throw new Error(\"Method not implemented.\")\n }\n removeEventListener(\n type: string,\n callback: EventListenerOrEventListenerObject,\n options?: boolean | EventListenerOptions\n ): void {\n throw new Error(\"Method not implemented.\")\n }\n}\n\nexport * from 'cookie-store-interface';\n"]}