@ultimat3/core 31.57.0 → 31.58.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/core",
3
- "version": "31.57.0",
3
+ "version": "31.58.0",
4
4
  "description": "Ultimate's foundation: errors, context, env, config, clock, ids, logging, telemetry, lifecycle",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -57,6 +57,6 @@
57
57
  "test": "bun test"
58
58
  },
59
59
  "dependencies": {
60
- "@ultimat3/schema": "31.57.0"
60
+ "@ultimat3/schema": "31.58.0"
61
61
  }
62
62
  }
package/src/cookie.ts CHANGED
@@ -1,4 +1,4 @@
1
- // The one cookie header codec: `readCookie` reads a `Cookie:` request header, `serializeSetCookie`
1
+ // The one cookie header codec: `readCookie` (and `readCookies`) reads a `Cookie:` request header, `serializeSetCookie`
2
2
  // builds a `Set-Cookie` value. At tier 0 because three packages need it — auth and http at tier 2
3
3
  // cannot import each other, i18n sits below both — and each copy had to rediscover the same thrown
4
4
  // `URIError` on its own (`bun run flight-copies` refuses a fourth).
@@ -28,14 +28,26 @@ const decodeCookieValue = (raw: string): string => {
28
28
  * a header that is not a string at all is no cookie.
29
29
  */
30
30
  export function readCookie(header: string | null | undefined, name: string): string | null {
31
- if (typeof header !== 'string') return null;
31
+ return readCookies(header).find(([key]) => key === name)?.[1] ?? null;
32
+ }
33
+
34
+ /**
35
+ * Every `[name, value]` pair of a `Cookie:` header, in the order the browser sent them (older
36
+ * first, for one path), values decoded as `readCookie` decodes them. A part with no `=` is no
37
+ * cookie; a header that is not a string has none. For a reader that must see cookies it cannot
38
+ * name in advance (a family sharing a prefix); a known name is `readCookie`.
39
+ */
40
+ export function readCookies(
41
+ header: string | null | undefined,
42
+ ): readonly (readonly [name: string, value: string])[] {
43
+ if (typeof header !== 'string') return [];
44
+ const pairs: (readonly [string, string])[] = [];
32
45
  for (const part of header.split(';')) {
33
46
  const equals = part.indexOf('=');
34
47
  if (equals === -1) continue;
35
- if (part.slice(0, equals).trim() !== name) continue;
36
- return decodeCookieValue(part.slice(equals + 1).trim());
48
+ pairs.push([part.slice(0, equals).trim(), decodeCookieValue(part.slice(equals + 1).trim())]);
37
49
  }
38
- return null;
50
+ return pairs;
39
51
  }
40
52
 
41
53
  /** `SameSite`: `None` sends the cookie cross-site, so it is only accepted beside `Secure`. */
package/src/index.ts CHANGED
@@ -282,7 +282,7 @@ export {
282
282
  } from './context';
283
283
  /** The one cookie codec — auth, http and i18n each parsed `Cookie:` and spelled `Set-Cookie`. */
284
284
  export type { CookiePriority, CookieSameSite, SetCookieOptions } from './cookie';
285
- export { CookieInvalidError, readCookie, serializeSetCookie } from './cookie';
285
+ export { CookieInvalidError, readCookie, readCookies, serializeSetCookie } from './cookie';
286
286
  export type { CursorPayload } from './cursor';
287
287
  export {
288
288
  CURSOR_SECRET_FIX,