@orieljs/cookie 0.1.0-alpha.1 → 0.1.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +7 -0
- package/README.md +33 -0
- package/TRADEMARKS.md +33 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +7 -5
package/NOTICE
CHANGED
|
@@ -7,3 +7,10 @@ This product includes software developed by the Oriel project
|
|
|
7
7
|
Oriel is licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
8
8
|
The Oriel name and logo are not covered by that license; see TRADEMARKS.md
|
|
9
9
|
(https://github.com/orieljs/framework/blob/main/TRADEMARKS.md).
|
|
10
|
+
|
|
11
|
+
@orieljs/support (and @orieljs/framework, which bundles it) includes transliteration data from
|
|
12
|
+
voku/portable-ascii (https://github.com/voku/portable-ascii), Copyright (C) 2019 Lars Moelleken, MIT License.
|
|
13
|
+
|
|
14
|
+
@orieljs/notifications (and @orieljs/framework, which bundles it) includes the HTML and CSS of
|
|
15
|
+
Laravel's default notification mail (laravel/framework, https://github.com/laravel/framework),
|
|
16
|
+
Copyright (c) Taylor Otwell, MIT License.
|
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# @orieljs/cookie
|
|
2
|
+
|
|
3
|
+
Cookies for Oriel: the cookie jar, queued cookies and cookie encryption. It follows Laravel's `Illuminate\Cookie`. Cookie is part of `@orieljs/framework`, which every Oriel app already installs, and is re-exported from it. In an app, import it from `@orieljs/framework`; `@orieljs/cookie` is also published on its own.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @orieljs/framework
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts title="app/Http/Controllers/ThemeController.ts"
|
|
10
|
+
import { back, Cookie, cookie, request } from '@orieljs/framework'
|
|
11
|
+
import { Controller } from './Controller'
|
|
12
|
+
|
|
13
|
+
export class ThemeController extends Controller {
|
|
14
|
+
update() {
|
|
15
|
+
const theme = request().input('theme') === 'dark' ? 'dark' : 'light'
|
|
16
|
+
Cookie.queue(cookie('theme', theme, 60 * 24 * 365))
|
|
17
|
+
|
|
18
|
+
return back()
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`cookie(name, value, minutes)` makes a cookie and `Cookie.queue()` sends it with the response; `Cookie.get()` and `request().cookie()` read one. `EncryptCookies` encrypts cookies on the way out and decrypts them on the way in, and `AddQueuedCookiesToResponse` writes the queued ones.
|
|
24
|
+
|
|
25
|
+
Documentation: https://orieljs.vercel.app/docs/responses
|
|
26
|
+
|
|
27
|
+
Status: early alpha. APIs will change.
|
|
28
|
+
|
|
29
|
+
## License
|
|
30
|
+
|
|
31
|
+
Oriel is open-source software licensed under the Apache License 2.0 (Apache-2.0; see `LICENSE` and `NOTICE`). The Oriel name and logo are trademarks; see `TRADEMARKS.md`.
|
|
32
|
+
|
|
33
|
+
Website: https://orieljs.vercel.app
|
package/TRADEMARKS.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Oriel trademark policy
|
|
2
|
+
|
|
3
|
+
The Oriel code is open source under the Apache License 2.0. The **Oriel name and logo** are not: the license covers
|
|
4
|
+
the code only (section 6 of the license says so), and the name and logo stay with the project. This page explains
|
|
5
|
+
what you can and can't do with them. The goal is simple: people should always be able to tell what is the real Oriel
|
|
6
|
+
and what isn't.
|
|
7
|
+
|
|
8
|
+
## You can, without asking
|
|
9
|
+
|
|
10
|
+
- Use, change, ship and sell the code, as the license allows.
|
|
11
|
+
- Say that your app or package is "built with Oriel", "for Oriel" or "compatible with Oriel".
|
|
12
|
+
- Name a package `oriel-<something>` or `<something>-for-oriel` when it works with Oriel, as long as it is clear that
|
|
13
|
+
it is not official (for example, don't publish it under the `@orieljs` npm scope).
|
|
14
|
+
- Use the name and logo to write about Oriel, teach it, or link to it, in articles, talks, videos and courses.
|
|
15
|
+
- Use the unmodified logo to point to the project, as it is (no recolouring, cropping or
|
|
16
|
+
distortion).
|
|
17
|
+
|
|
18
|
+
## You can't, without written permission
|
|
19
|
+
|
|
20
|
+
- Call a fork, a modified copy or a competing product "Oriel", or anything likely to be confused with it.
|
|
21
|
+
- Use the name or logo as the name, logo or domain of your own product, company or service.
|
|
22
|
+
- Suggest that the Oriel project made, endorses or supports your work when it doesn't.
|
|
23
|
+
- Sell merchandise with the name or logo.
|
|
24
|
+
|
|
25
|
+
## Forks
|
|
26
|
+
|
|
27
|
+
Forks are welcome. Please give yours a different name and logo, keep the `LICENSE` and `NOTICE` files, and say that
|
|
28
|
+
it is based on Oriel.
|
|
29
|
+
|
|
30
|
+
## Questions
|
|
31
|
+
|
|
32
|
+
Open an issue at https://github.com/orieljs/framework or email meeeet.dev@gmail.com. If you're unsure whether a use
|
|
33
|
+
is fine, ask; the answer is usually yes.
|
package/dist/index.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ declare class CookieJar implements CookieJar$1 {
|
|
|
40
40
|
#private;
|
|
41
41
|
constructor(defaults?: CookieDefaults);
|
|
42
42
|
make(name: string, value: string, minutes?: number, options?: CookieOptions): Cookie$1;
|
|
43
|
-
/**
|
|
43
|
+
/** 400 days, as in Laravel: the longest lifetime browsers keep a cookie. */
|
|
44
44
|
forever(name: string, value: string, options?: CookieOptions): Cookie$1;
|
|
45
45
|
/** An expired cookie that makes the browser delete it. */
|
|
46
46
|
forget(name: string, options?: CookieOptions): Cookie$1;
|
package/dist/index.js
CHANGED
|
@@ -96,7 +96,7 @@ var CookieJar = class {
|
|
|
96
96
|
sameSite: options.sameSite ?? this.#defaults.sameSite
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
|
-
/**
|
|
99
|
+
/** 400 days, as in Laravel: the longest lifetime browsers keep a cookie. */
|
|
100
100
|
forever(name, value, options = {}) {
|
|
101
101
|
return this.make(name, value, 576e3, options);
|
|
102
102
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../serialize.ts","../CookieValuePrefix.ts","../CookieJar.ts","../middleware/AddQueuedCookiesToResponse.ts","../middleware/EncryptCookies.ts","../facade.ts","../CookieServiceProvider.ts"],"sourcesContent":["import type { Cookie } from '@orieljs/contracts'\n\nconst SAME_SITE = { lax: 'Lax', strict: 'Strict', none: 'None' } as const\n\n/** A Set-Cookie header value. Negative minutes delete the cookie; 0 is a session cookie. */\nexport function serializeCookie(cookie: Cookie, now: number = Date.now()): string {\n const parts: string[] = []\n if (cookie.minutes < 0) {\n parts.push(`${cookie.name}=`, 'Expires=Thu, 01 Jan 1970 00:00:00 GMT', 'Max-Age=0')\n } else {\n parts.push(`${cookie.name}=${encodeURIComponent(cookie.value)}`)\n if (cookie.minutes > 0) {\n parts.push(`Expires=${new Date(now + cookie.minutes * 60_000).toUTCString()}`, `Max-Age=${cookie.minutes * 60}`)\n }\n }\n parts.push(`Path=${cookie.path}`)\n if (cookie.domain !== undefined && cookie.domain !== '') parts.push(`Domain=${cookie.domain}`)\n if (cookie.secure) parts.push('Secure')\n if (cookie.httpOnly) parts.push('HttpOnly')\n parts.push(`SameSite=${SAME_SITE[cookie.sameSite]}`)\n return parts.join('; ')\n}\n\nexport interface ParsedSetCookie {\n name: string\n value: string\n /** Everything after the name=value pair, including the leading '; ' (empty when there are no attributes). */\n attributes: string\n}\n\nconst decode = (value: string): string => {\n try {\n return decodeURIComponent(value)\n } catch {\n return value\n }\n}\n\n/** Splits a Set-Cookie header value into its name, decoded value and untouched attributes. */\nexport function parseSetCookie(header: string): ParsedSetCookie {\n const semicolon = header.indexOf(';')\n const pair = semicolon === -1 ? header : header.slice(0, semicolon)\n const equals = pair.indexOf('=')\n return {\n name: (equals === -1 ? pair : pair.slice(0, equals)).trim(),\n value: equals === -1 ? '' : decode(pair.slice(equals + 1).trim()),\n attributes: semicolon === -1 ? '' : header.slice(semicolon),\n }\n}\n\n/** Parses a Cookie request header (`a=1; b=2`). The first occurrence of a name wins. */\nexport function parseCookieHeader(header: string | undefined): Record<string, string> {\n const cookies: Record<string, string> = {}\n for (const part of (header ?? '').split(';')) {\n const equals = part.indexOf('=')\n if (equals === -1) continue\n const name = part.slice(0, equals).trim()\n if (name === '' || Object.hasOwn(cookies, name) || name === '__proto__') continue\n cookies[name] = decode(part.slice(equals + 1).trim())\n }\n return cookies\n}\n\n/** A copy of the response whose headers can be changed (Response.redirect() and fetch() headers are immutable). */\nexport function withHeaders(response: Response, change: (headers: Headers) => void): Response {\n const headers = new Headers(response.headers)\n change(headers)\n return new Response(response.body, { status: response.status, statusText: response.statusText, headers })\n}\n","import { createHmac, timingSafeEqual } from 'node:crypto'\n\n/**\n * Laravel's CookieValuePrefix: encrypted cookie values start with hmac_sha1(name + 'v2', key) + '|', which binds\n * each value to its cookie name so an encrypted value can't be replayed under another cookie.\n */\nexport const CookieValuePrefix = {\n create(name: string, key: Uint8Array): string {\n return `${createHmac('sha1', key).update(`${name}v2`).digest('hex')}|`\n },\n\n remove(value: string): string {\n return value.slice(41)\n },\n\n /** The value without its prefix when the prefix matches one of the keys, else undefined. */\n validate(name: string, value: string, keys: Uint8Array[]): string | undefined {\n const actual = Buffer.from(value.slice(0, 41))\n for (const key of keys) {\n const expected = Buffer.from(CookieValuePrefix.create(name, key))\n if (actual.length === expected.length && timingSafeEqual(actual, expected)) return CookieValuePrefix.remove(value)\n }\n return undefined\n },\n}\n","import type { Cookie, CookieJar as CookieJarContract } from '@orieljs/contracts'\n\nexport interface CookieDefaults {\n path?: string\n domain?: string | undefined\n secure?: boolean\n sameSite?: Cookie['sameSite']\n}\n\ntype CookieOptions = Partial<Omit<Cookie, 'name' | 'value' | 'minutes'>>\n\n/** Laravel's CookieJar. One per request scope: queued cookies are attached by AddQueuedCookiesToResponse. */\nexport class CookieJar implements CookieJarContract {\n readonly #queued = new Map<string, Cookie>()\n readonly #defaults: Required<Omit<CookieDefaults, 'domain'>> & { domain: string | undefined }\n\n constructor(defaults: CookieDefaults = {}) {\n this.#defaults = {\n path: defaults.path ?? '/',\n domain: defaults.domain ?? undefined,\n secure: defaults.secure ?? false,\n sameSite: defaults.sameSite ?? 'lax',\n }\n }\n\n make(name: string, value: string, minutes = 0, options: CookieOptions = {}): Cookie {\n const domain = options.domain ?? this.#defaults.domain\n return {\n name,\n value,\n minutes,\n path: options.path ?? this.#defaults.path,\n ...(domain === undefined ? {} : { domain }),\n secure: options.secure ?? this.#defaults.secure,\n httpOnly: options.httpOnly ?? true,\n sameSite: options.sameSite ?? this.#defaults.sameSite,\n }\n }\n\n /** Five years, like Laravel. */\n forever(name: string, value: string, options: CookieOptions = {}): Cookie {\n return this.make(name, value, 576000, options)\n }\n\n /** An expired cookie that makes the browser delete it. */\n forget(name: string, options: CookieOptions = {}): Cookie {\n return this.make(name, '', -2628000, options)\n }\n\n /** Queue a cookie for the response. A cookie with the same name and path replaces the earlier one. */\n queue(cookie: Cookie): void {\n this.#queued.set(`${cookie.name}\\0${cookie.path}`, cookie)\n }\n\n queued(): Cookie[] {\n return [...this.#queued.values()]\n }\n\n hasQueued(name: string, path?: string): boolean {\n return this.queuedCookie(name, path) !== undefined\n }\n\n queuedCookie(name: string, path?: string): Cookie | undefined {\n return this.queued().find((cookie) => cookie.name === name && (path === undefined || cookie.path === path))\n }\n\n unqueue(name: string, path?: string): void {\n for (const [key, cookie] of this.#queued) {\n if (cookie.name === name && (path === undefined || cookie.path === path)) this.#queued.delete(key)\n }\n }\n}\n","import { CookieJar, type HttpRequest, type Middleware, type Next } from '@orieljs/contracts'\nimport { inject } from '@orieljs/container'\nimport { serializeCookie, withHeaders } from '../serialize'\n\n/** Laravel's AddQueuedCookiesToResponse: writes the request's queued cookies as Set-Cookie headers. */\nexport class AddQueuedCookiesToResponse implements Middleware {\n readonly #jar = inject(CookieJar)\n\n async handle(request: HttpRequest, next: Next): Promise<Response> {\n const response = await next(request)\n const cookies = this.#jar.queued()\n if (cookies.length === 0) return response\n return withHeaders(response, (headers) => {\n for (const cookie of cookies) headers.append('Set-Cookie', serializeCookie(cookie))\n })\n }\n}\n","import { Encrypter, type HttpRequest, type Middleware, type Next } from '@orieljs/contracts'\nimport { inject } from '@orieljs/container'\nimport { CookieValuePrefix } from '../CookieValuePrefix'\nimport { parseCookieHeader, parseSetCookie, withHeaders } from '../serialize'\n\nconst neverEncrypt = new Set<string>()\n\n/** Whether a Set-Cookie deletes the cookie (Max-Age <= 0, or Expires in the past): its value is left alone. */\nfunction isDeletion(attributes: string, now = Date.now()): boolean {\n for (const part of attributes.split(';')) {\n const equals = part.indexOf('=')\n if (equals === -1) continue\n const key = part.slice(0, equals).trim().toLowerCase()\n const value = part.slice(equals + 1).trim()\n if (key === 'max-age' && Number(value) <= 0) return true\n if (key === 'expires' && Date.parse(value) <= now) return true\n }\n return false\n}\n\n/**\n * Laravel's EncryptCookies: request cookies are decrypted (and dropped when they don't decrypt), and every\n * Set-Cookie on the outgoing response is encrypted, whoever wrote it (queued on the CookieJar, or written straight\n * onto the response such as RedirectResponse.withCookie()), except the names in `except` and deletions. It runs\n * once, outermost in `web`, so every cookie is encrypted exactly once.\n */\nexport class EncryptCookies implements Middleware {\n /** Cookie names that are never encrypted (Laravel 11's $middleware->encryptCookies(except: [...])). */\n static except(cookies: string | string[]): void {\n for (const name of Array.isArray(cookies) ? cookies : [cookies]) neverEncrypt.add(name)\n }\n\n /** Forget the names added with except() (for tests). */\n static flushState(): void {\n neverEncrypt.clear()\n }\n\n /** Subclasses list cookie names that are not encrypted. */\n protected except: string[] = []\n\n protected readonly encrypter = inject(Encrypter)\n\n isDisabled(name: string): boolean {\n return this.except.includes(name) || neverEncrypt.has(name)\n }\n\n async handle(request: HttpRequest, next: Next): Promise<Response> {\n this.decrypt(request)\n return this.encrypt(await next(request))\n }\n\n protected decrypt(request: HttpRequest): void {\n const keys = (this.encrypter as { getAllKeys?(): Uint8Array[] }).getAllKeys?.() ?? [this.encrypter.getKey()]\n const decrypted: Record<string, string> = {}\n for (const [name, value] of Object.entries(parseCookieHeader(request.header('cookie')))) {\n if (this.isDisabled(name)) {\n decrypted[name] = value\n continue\n }\n try {\n const plain = CookieValuePrefix.validate(name, this.encrypter.decrypt<string>(value, false), keys)\n if (plain !== undefined) decrypted[name] = plain\n } catch {\n // A cookie that doesn't decrypt reads as absent (Laravel sets it to null).\n }\n }\n request.setCookies(decrypted)\n }\n\n protected encrypt(response: Response): Response {\n const cookies = response.headers.getSetCookie()\n if (cookies.length === 0) return response\n return withHeaders(response, (headers) => {\n headers.delete('Set-Cookie')\n for (const header of cookies) {\n const { name, value, attributes } = parseSetCookie(header)\n if (this.isDisabled(name) || isDeletion(attributes)) {\n headers.append('Set-Cookie', header)\n continue\n }\n const encrypted = this.encrypter.encrypt(CookieValuePrefix.create(name, this.encrypter.getKey()) + value, false)\n headers.append('Set-Cookie', `${name}=${encodeURIComponent(encrypted)}${attributes}`)\n }\n })\n }\n}\n","import { CookieJar, HttpRequest, type Cookie as CookieShape } from '@orieljs/contracts'\nimport { inject } from '@orieljs/container'\nimport { facade } from '@orieljs/support'\n\n/** The Cookie facade: the request's jar, plus get()/has() reading the (decrypted) request cookies. */\nexport const Cookie = facade(CookieJar, {\n get: (name: string, defaultValue?: string): string | undefined => inject(HttpRequest).cookie(name) ?? defaultValue,\n has: (name: string): boolean => inject(HttpRequest).cookie(name) !== undefined,\n})\n\n/** cookie(): the jar; cookie(name, value, minutes?, options?): a new cookie (queue it, or attach it to a redirect). */\nexport function cookie(): CookieJar\nexport function cookie(name: string, value: string, minutes?: number, options?: Partial<Omit<CookieShape, 'name' | 'value' | 'minutes'>>): CookieShape\nexport function cookie(\n name?: string,\n value?: string,\n minutes?: number,\n options?: Partial<Omit<CookieShape, 'name' | 'value' | 'minutes'>>,\n): CookieJar | CookieShape {\n const jar = inject(CookieJar)\n return name === undefined ? jar : jar.make(name, value ?? '', minutes, options)\n}\n","import { ConfigRepository, CookieJar as CookieJarToken, HttpRequest, Router, type Cookie } from '@orieljs/contracts'\nimport { ServiceProvider } from '@orieljs/support'\nimport { CookieJar } from './CookieJar'\nimport { AddQueuedCookiesToResponse } from './middleware/AddQueuedCookiesToResponse'\nimport { EncryptCookies } from './middleware/EncryptCookies'\n\nexport class CookieServiceProvider extends ServiceProvider {\n override register(): void {\n // Laravel's CookieServiceProvider takes the jar's defaults from config/session.php.\n this.app.scoped(CookieJarToken, (container) => {\n const config = container.make(ConfigRepository)\n const domain = config.get<string | null | undefined>('session.domain')\n // secure defaults to null (ruling F6); an explicit true/false wins, otherwise it follows the request's scheme\n // (Symfony's setSecureDefault), so cookies built from these defaults (e.g. the remember cookie) are Secure on HTTPS.\n const secureConfig = config.get<boolean | null | undefined>('session.secure', null)\n const secure = secureConfig ?? (container.bound(HttpRequest) && container.make(HttpRequest).url().startsWith('https:'))\n return new CookieJar({\n path: config.get('session.path', '/'),\n domain: domain ?? undefined,\n secure,\n sameSite: config.get<Cookie['sameSite'] | null>('session.same_site', 'lax') ?? 'lax',\n })\n })\n }\n\n override boot(): void {\n if (!this.app.bound(Router)) return\n this.app.make(Router).pushMiddlewareToGroup('web', EncryptCookies).pushMiddlewareToGroup('web', AddQueuedCookiesToResponse)\n }\n}\n"],"mappings":";AAEA,IAAM,YAAY,EAAE,KAAK,OAAO,QAAQ,UAAU,MAAM,OAAO;AAGxD,SAAS,gBAAgBA,SAAgB,MAAc,KAAK,IAAI,GAAW;AAChF,QAAM,QAAkB,CAAC;AACzB,MAAIA,QAAO,UAAU,GAAG;AACtB,UAAM,KAAK,GAAGA,QAAO,IAAI,KAAK,yCAAyC,WAAW;AAAA,EACpF,OAAO;AACL,UAAM,KAAK,GAAGA,QAAO,IAAI,IAAI,mBAAmBA,QAAO,KAAK,CAAC,EAAE;AAC/D,QAAIA,QAAO,UAAU,GAAG;AACtB,YAAM,KAAK,WAAW,IAAI,KAAK,MAAMA,QAAO,UAAU,GAAM,EAAE,YAAY,CAAC,IAAI,WAAWA,QAAO,UAAU,EAAE,EAAE;AAAA,IACjH;AAAA,EACF;AACA,QAAM,KAAK,QAAQA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C,QAAO,WAAW,EAAE,OAAO,IAAI,KAAK;AAAA,EACtG,KAAK,CAAC,SAA0BA,QAAO,WAAW,EAAE,OAAO,IAAI,MAAM;AACvE,CAAC;AAKM,SAAS,OACd,MACA,OACA,SACA,SACyB;AACzB,QAAM,MAAMA,QAAOD,UAAS;AAC5B,SAAO,SAAS,SAAY,MAAM,IAAI,KAAK,MAAM,SAAS,IAAI,SAAS,OAAO;AAChF;;;ACrBA,SAAS,kBAAkB,aAAa,gBAAgB,eAAAE,cAAa,cAA2B;AAChG,SAAS,uBAAuB;AAKzB,IAAM,wBAAN,cAAoC,gBAAgB;AAAA,EAChD,WAAiB;AAExB,SAAK,IAAI,OAAO,gBAAgB,CAAC,cAAc;AAC7C,YAAM,SAAS,UAAU,KAAK,gBAAgB;AAC9C,YAAM,SAAS,OAAO,IAA+B,gBAAgB;AAGrE,YAAM,eAAe,OAAO,IAAgC,kBAAkB,IAAI;AAClF,YAAM,SAAS,iBAAiB,UAAU,MAAMC,YAAW,KAAK,UAAU,KAAKA,YAAW,EAAE,IAAI,EAAE,WAAW,QAAQ;AACrH,aAAO,IAAI,UAAU;AAAA,QACnB,MAAM,OAAO,IAAI,gBAAgB,GAAG;AAAA,QACpC,QAAQ,UAAU;AAAA,QAClB;AAAA,QACA,UAAU,OAAO,IAA+B,qBAAqB,KAAK,KAAK;AAAA,MACjF,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAAA,EAES,OAAa;AACpB,QAAI,CAAC,KAAK,IAAI,MAAM,MAAM,EAAG;AAC7B,SAAK,IAAI,KAAK,MAAM,EAAE,sBAAsB,OAAO,cAAc,EAAE,sBAAsB,OAAO,0BAA0B;AAAA,EAC5H;AACF;","names":["cookie","cookie","CookieJar","CookieJar","cookie","inject","inject","CookieJar","inject","HttpRequest","HttpRequest"]}
|
|
1
|
+
{"version":3,"sources":["../serialize.ts","../CookieValuePrefix.ts","../CookieJar.ts","../middleware/AddQueuedCookiesToResponse.ts","../middleware/EncryptCookies.ts","../facade.ts","../CookieServiceProvider.ts"],"sourcesContent":["import type { Cookie } from '@orieljs/contracts'\n\nconst SAME_SITE = { lax: 'Lax', strict: 'Strict', none: 'None' } as const\n\n/** A Set-Cookie header value. Negative minutes delete the cookie; 0 is a session cookie. */\nexport function serializeCookie(cookie: Cookie, now: number = Date.now()): string {\n const parts: string[] = []\n if (cookie.minutes < 0) {\n parts.push(`${cookie.name}=`, 'Expires=Thu, 01 Jan 1970 00:00:00 GMT', 'Max-Age=0')\n } else {\n parts.push(`${cookie.name}=${encodeURIComponent(cookie.value)}`)\n if (cookie.minutes > 0) {\n parts.push(`Expires=${new Date(now + cookie.minutes * 60_000).toUTCString()}`, `Max-Age=${cookie.minutes * 60}`)\n }\n }\n parts.push(`Path=${cookie.path}`)\n if (cookie.domain !== undefined && cookie.domain !== '') parts.push(`Domain=${cookie.domain}`)\n if (cookie.secure) parts.push('Secure')\n if (cookie.httpOnly) parts.push('HttpOnly')\n parts.push(`SameSite=${SAME_SITE[cookie.sameSite]}`)\n return parts.join('; ')\n}\n\nexport interface ParsedSetCookie {\n name: string\n value: string\n /** Everything after the name=value pair, including the leading '; ' (empty when there are no attributes). */\n attributes: string\n}\n\nconst decode = (value: string): string => {\n try {\n return decodeURIComponent(value)\n } catch {\n return value\n }\n}\n\n/** Splits a Set-Cookie header value into its name, decoded value and untouched attributes. */\nexport function parseSetCookie(header: string): ParsedSetCookie {\n const semicolon = header.indexOf(';')\n const pair = semicolon === -1 ? header : header.slice(0, semicolon)\n const equals = pair.indexOf('=')\n return {\n name: (equals === -1 ? pair : pair.slice(0, equals)).trim(),\n value: equals === -1 ? '' : decode(pair.slice(equals + 1).trim()),\n attributes: semicolon === -1 ? '' : header.slice(semicolon),\n }\n}\n\n/** Parses a Cookie request header (`a=1; b=2`). The first occurrence of a name wins. */\nexport function parseCookieHeader(header: string | undefined): Record<string, string> {\n const cookies: Record<string, string> = {}\n for (const part of (header ?? '').split(';')) {\n const equals = part.indexOf('=')\n if (equals === -1) continue\n const name = part.slice(0, equals).trim()\n if (name === '' || Object.hasOwn(cookies, name) || name === '__proto__') continue\n cookies[name] = decode(part.slice(equals + 1).trim())\n }\n return cookies\n}\n\n/** A copy of the response whose headers can be changed (Response.redirect() and fetch() headers are immutable). */\nexport function withHeaders(response: Response, change: (headers: Headers) => void): Response {\n const headers = new Headers(response.headers)\n change(headers)\n return new Response(response.body, { status: response.status, statusText: response.statusText, headers })\n}\n","import { createHmac, timingSafeEqual } from 'node:crypto'\n\n/**\n * Laravel's CookieValuePrefix: encrypted cookie values start with hmac_sha1(name + 'v2', key) + '|', which binds\n * each value to its cookie name so an encrypted value can't be replayed under another cookie.\n */\nexport const CookieValuePrefix = {\n create(name: string, key: Uint8Array): string {\n return `${createHmac('sha1', key).update(`${name}v2`).digest('hex')}|`\n },\n\n remove(value: string): string {\n return value.slice(41)\n },\n\n /** The value without its prefix when the prefix matches one of the keys, else undefined. */\n validate(name: string, value: string, keys: Uint8Array[]): string | undefined {\n const actual = Buffer.from(value.slice(0, 41))\n for (const key of keys) {\n const expected = Buffer.from(CookieValuePrefix.create(name, key))\n if (actual.length === expected.length && timingSafeEqual(actual, expected)) return CookieValuePrefix.remove(value)\n }\n return undefined\n },\n}\n","import type { Cookie, CookieJar as CookieJarContract } from '@orieljs/contracts'\n\nexport interface CookieDefaults {\n path?: string\n domain?: string | undefined\n secure?: boolean\n sameSite?: Cookie['sameSite']\n}\n\ntype CookieOptions = Partial<Omit<Cookie, 'name' | 'value' | 'minutes'>>\n\n/** Laravel's CookieJar. One per request scope: queued cookies are attached by AddQueuedCookiesToResponse. */\nexport class CookieJar implements CookieJarContract {\n readonly #queued = new Map<string, Cookie>()\n readonly #defaults: Required<Omit<CookieDefaults, 'domain'>> & { domain: string | undefined }\n\n constructor(defaults: CookieDefaults = {}) {\n this.#defaults = {\n path: defaults.path ?? '/',\n domain: defaults.domain ?? undefined,\n secure: defaults.secure ?? false,\n sameSite: defaults.sameSite ?? 'lax',\n }\n }\n\n make(name: string, value: string, minutes = 0, options: CookieOptions = {}): Cookie {\n const domain = options.domain ?? this.#defaults.domain\n return {\n name,\n value,\n minutes,\n path: options.path ?? this.#defaults.path,\n ...(domain === undefined ? {} : { domain }),\n secure: options.secure ?? this.#defaults.secure,\n httpOnly: options.httpOnly ?? true,\n sameSite: options.sameSite ?? this.#defaults.sameSite,\n }\n }\n\n /** 400 days, as in Laravel: the longest lifetime browsers keep a cookie. */\n forever(name: string, value: string, options: CookieOptions = {}): Cookie {\n return this.make(name, value, 576000, options)\n }\n\n /** An expired cookie that makes the browser delete it. */\n forget(name: string, options: CookieOptions = {}): Cookie {\n return this.make(name, '', -2628000, options)\n }\n\n /** Queue a cookie for the response. A cookie with the same name and path replaces the earlier one. */\n queue(cookie: Cookie): void {\n this.#queued.set(`${cookie.name}\\0${cookie.path}`, cookie)\n }\n\n queued(): Cookie[] {\n return [...this.#queued.values()]\n }\n\n hasQueued(name: string, path?: string): boolean {\n return this.queuedCookie(name, path) !== undefined\n }\n\n queuedCookie(name: string, path?: string): Cookie | undefined {\n return this.queued().find((cookie) => cookie.name === name && (path === undefined || cookie.path === path))\n }\n\n unqueue(name: string, path?: string): void {\n for (const [key, cookie] of this.#queued) {\n if (cookie.name === name && (path === undefined || cookie.path === path)) this.#queued.delete(key)\n }\n }\n}\n","import { CookieJar, type HttpRequest, type Middleware, type Next } from '@orieljs/contracts'\nimport { inject } from '@orieljs/container'\nimport { serializeCookie, withHeaders } from '../serialize'\n\n/** Laravel's AddQueuedCookiesToResponse: writes the request's queued cookies as Set-Cookie headers. */\nexport class AddQueuedCookiesToResponse implements Middleware {\n readonly #jar = inject(CookieJar)\n\n async handle(request: HttpRequest, next: Next): Promise<Response> {\n const response = await next(request)\n const cookies = this.#jar.queued()\n if (cookies.length === 0) return response\n return withHeaders(response, (headers) => {\n for (const cookie of cookies) headers.append('Set-Cookie', serializeCookie(cookie))\n })\n }\n}\n","import { Encrypter, type HttpRequest, type Middleware, type Next } from '@orieljs/contracts'\nimport { inject } from '@orieljs/container'\nimport { CookieValuePrefix } from '../CookieValuePrefix'\nimport { parseCookieHeader, parseSetCookie, withHeaders } from '../serialize'\n\nconst neverEncrypt = new Set<string>()\n\n/** Whether a Set-Cookie deletes the cookie (Max-Age <= 0, or Expires in the past): its value is left alone. */\nfunction isDeletion(attributes: string, now = Date.now()): boolean {\n for (const part of attributes.split(';')) {\n const equals = part.indexOf('=')\n if (equals === -1) continue\n const key = part.slice(0, equals).trim().toLowerCase()\n const value = part.slice(equals + 1).trim()\n if (key === 'max-age' && Number(value) <= 0) return true\n if (key === 'expires' && Date.parse(value) <= now) return true\n }\n return false\n}\n\n/**\n * Laravel's EncryptCookies: request cookies are decrypted (and dropped when they don't decrypt), and every\n * Set-Cookie on the outgoing response is encrypted, whoever wrote it (queued on the CookieJar, or written straight\n * onto the response such as RedirectResponse.withCookie()), except the names in `except` and deletions. It runs\n * once, outermost in `web`, so every cookie is encrypted exactly once.\n */\nexport class EncryptCookies implements Middleware {\n /** Cookie names that are never encrypted (Laravel 11's $middleware->encryptCookies(except: [...])). */\n static except(cookies: string | string[]): void {\n for (const name of Array.isArray(cookies) ? cookies : [cookies]) neverEncrypt.add(name)\n }\n\n /** Forget the names added with except() (for tests). */\n static flushState(): void {\n neverEncrypt.clear()\n }\n\n /** Subclasses list cookie names that are not encrypted. */\n protected except: string[] = []\n\n protected readonly encrypter = inject(Encrypter)\n\n isDisabled(name: string): boolean {\n return this.except.includes(name) || neverEncrypt.has(name)\n }\n\n async handle(request: HttpRequest, next: Next): Promise<Response> {\n this.decrypt(request)\n return this.encrypt(await next(request))\n }\n\n protected decrypt(request: HttpRequest): void {\n const keys = (this.encrypter as { getAllKeys?(): Uint8Array[] }).getAllKeys?.() ?? [this.encrypter.getKey()]\n const decrypted: Record<string, string> = {}\n for (const [name, value] of Object.entries(parseCookieHeader(request.header('cookie')))) {\n if (this.isDisabled(name)) {\n decrypted[name] = value\n continue\n }\n try {\n const plain = CookieValuePrefix.validate(name, this.encrypter.decrypt<string>(value, false), keys)\n if (plain !== undefined) decrypted[name] = plain\n } catch {\n // A cookie that doesn't decrypt reads as absent (Laravel sets it to null).\n }\n }\n request.setCookies(decrypted)\n }\n\n protected encrypt(response: Response): Response {\n const cookies = response.headers.getSetCookie()\n if (cookies.length === 0) return response\n return withHeaders(response, (headers) => {\n headers.delete('Set-Cookie')\n for (const header of cookies) {\n const { name, value, attributes } = parseSetCookie(header)\n if (this.isDisabled(name) || isDeletion(attributes)) {\n headers.append('Set-Cookie', header)\n continue\n }\n const encrypted = this.encrypter.encrypt(CookieValuePrefix.create(name, this.encrypter.getKey()) + value, false)\n headers.append('Set-Cookie', `${name}=${encodeURIComponent(encrypted)}${attributes}`)\n }\n })\n }\n}\n","import { CookieJar, HttpRequest, type Cookie as CookieShape } from '@orieljs/contracts'\nimport { inject } from '@orieljs/container'\nimport { facade } from '@orieljs/support'\n\n/** The Cookie facade: the request's jar, plus get()/has() reading the (decrypted) request cookies. */\nexport const Cookie = facade(CookieJar, {\n get: (name: string, defaultValue?: string): string | undefined => inject(HttpRequest).cookie(name) ?? defaultValue,\n has: (name: string): boolean => inject(HttpRequest).cookie(name) !== undefined,\n})\n\n/** cookie(): the jar; cookie(name, value, minutes?, options?): a new cookie (queue it, or attach it to a redirect). */\nexport function cookie(): CookieJar\nexport function cookie(name: string, value: string, minutes?: number, options?: Partial<Omit<CookieShape, 'name' | 'value' | 'minutes'>>): CookieShape\nexport function cookie(\n name?: string,\n value?: string,\n minutes?: number,\n options?: Partial<Omit<CookieShape, 'name' | 'value' | 'minutes'>>,\n): CookieJar | CookieShape {\n const jar = inject(CookieJar)\n return name === undefined ? jar : jar.make(name, value ?? '', minutes, options)\n}\n","import { ConfigRepository, CookieJar as CookieJarToken, HttpRequest, Router, type Cookie } from '@orieljs/contracts'\nimport { ServiceProvider } from '@orieljs/support'\nimport { CookieJar } from './CookieJar'\nimport { AddQueuedCookiesToResponse } from './middleware/AddQueuedCookiesToResponse'\nimport { EncryptCookies } from './middleware/EncryptCookies'\n\nexport class CookieServiceProvider extends ServiceProvider {\n override register(): void {\n // Laravel's CookieServiceProvider takes the jar's defaults from config/session.php.\n this.app.scoped(CookieJarToken, (container) => {\n const config = container.make(ConfigRepository)\n const domain = config.get<string | null | undefined>('session.domain')\n // secure defaults to null (ruling F6); an explicit true/false wins, otherwise it follows the request's scheme\n // (Symfony's setSecureDefault), so cookies built from these defaults (e.g. the remember cookie) are Secure on HTTPS.\n const secureConfig = config.get<boolean | null | undefined>('session.secure', null)\n const secure = secureConfig ?? (container.bound(HttpRequest) && container.make(HttpRequest).url().startsWith('https:'))\n return new CookieJar({\n path: config.get('session.path', '/'),\n domain: domain ?? undefined,\n secure,\n sameSite: config.get<Cookie['sameSite'] | null>('session.same_site', 'lax') ?? 'lax',\n })\n })\n }\n\n override boot(): void {\n if (!this.app.bound(Router)) return\n this.app.make(Router).pushMiddlewareToGroup('web', EncryptCookies).pushMiddlewareToGroup('web', AddQueuedCookiesToResponse)\n }\n}\n"],"mappings":";AAEA,IAAM,YAAY,EAAE,KAAK,OAAO,QAAQ,UAAU,MAAM,OAAO;AAGxD,SAAS,gBAAgBA,SAAgB,MAAc,KAAK,IAAI,GAAW;AAChF,QAAM,QAAkB,CAAC;AACzB,MAAIA,QAAO,UAAU,GAAG;AACtB,UAAM,KAAK,GAAGA,QAAO,IAAI,KAAK,yCAAyC,WAAW;AAAA,EACpF,OAAO;AACL,UAAM,KAAK,GAAGA,QAAO,IAAI,IAAI,mBAAmBA,QAAO,KAAK,CAAC,EAAE;AAC/D,QAAIA,QAAO,UAAU,GAAG;AACtB,YAAM,KAAK,WAAW,IAAI,KAAK,MAAMA,QAAO,UAAU,GAAM,EAAE,YAAY,CAAC,IAAI,WAAWA,QAAO,UAAU,EAAE,EAAE;AAAA,IACjH;AAAA,EACF;AACA,QAAM,KAAK,QAAQA,QAAO,IAAI,EAAE;AAChC,MAAIA,QAAO,WAAW,UAAaA,QAAO,WAAW,GAAI,OAAM,KAAK,UAAUA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,OAAO,IAAI,MAAM;AACvE,CAAC;AAKM,SAAS,OACd,MACA,OACA,SACA,SACyB;AACzB,QAAM,MAAMA,QAAOD,UAAS;AAC5B,SAAO,SAAS,SAAY,MAAM,IAAI,KAAK,MAAM,SAAS,IAAI,SAAS,OAAO;AAChF;;;ACrBA,SAAS,kBAAkB,aAAa,gBAAgB,eAAAE,cAAa,cAA2B;AAChG,SAAS,uBAAuB;AAKzB,IAAM,wBAAN,cAAoC,gBAAgB;AAAA,EAChD,WAAiB;AAExB,SAAK,IAAI,OAAO,gBAAgB,CAAC,cAAc;AAC7C,YAAM,SAAS,UAAU,KAAK,gBAAgB;AAC9C,YAAM,SAAS,OAAO,IAA+B,gBAAgB;AAGrE,YAAM,eAAe,OAAO,IAAgC,kBAAkB,IAAI;AAClF,YAAM,SAAS,iBAAiB,UAAU,MAAMC,YAAW,KAAK,UAAU,KAAKA,YAAW,EAAE,IAAI,EAAE,WAAW,QAAQ;AACrH,aAAO,IAAI,UAAU;AAAA,QACnB,MAAM,OAAO,IAAI,gBAAgB,GAAG;AAAA,QACpC,QAAQ,UAAU;AAAA,QAClB;AAAA,QACA,UAAU,OAAO,IAA+B,qBAAqB,KAAK,KAAK;AAAA,MACjF,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAAA,EAES,OAAa;AACpB,QAAI,CAAC,KAAK,IAAI,MAAM,MAAM,EAAG;AAC7B,SAAK,IAAI,KAAK,MAAM,EAAE,sBAAsB,OAAO,cAAc,EAAE,sBAAsB,OAAO,0BAA0B;AAAA,EAC5H;AACF;","names":["cookie","cookie","CookieJar","CookieJar","cookie","inject","inject","CookieJar","inject","HttpRequest","HttpRequest"]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orieljs/cookie",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.11",
|
|
4
4
|
"description": "The Oriel Cookie component.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
|
+
"homepage": "https://orieljs.vercel.app",
|
|
7
8
|
"sideEffects": false,
|
|
8
9
|
"repository": {
|
|
9
10
|
"type": "git",
|
|
@@ -26,12 +27,13 @@
|
|
|
26
27
|
"files": [
|
|
27
28
|
"dist",
|
|
28
29
|
"LICENSE",
|
|
29
|
-
"NOTICE"
|
|
30
|
+
"NOTICE",
|
|
31
|
+
"TRADEMARKS.md"
|
|
30
32
|
],
|
|
31
33
|
"dependencies": {
|
|
32
|
-
"@orieljs/
|
|
33
|
-
"@orieljs/
|
|
34
|
-
"@orieljs/support": "0.1.0-alpha.
|
|
34
|
+
"@orieljs/container": "0.1.0-alpha.11",
|
|
35
|
+
"@orieljs/contracts": "0.1.0-alpha.11",
|
|
36
|
+
"@orieljs/support": "0.1.0-alpha.11"
|
|
35
37
|
},
|
|
36
38
|
"scripts": {
|
|
37
39
|
"build": "tsup && node ../../../scripts/copy-license.mjs"
|