Skip to content

Commit 5a31aaf

Browse files
chore(eio): revert cookie to version ~0.7.2
This reverts commit 7427109. The new version of the `cookie` package contains code with optional chaining (`?.`), which is not supported by older Node.js versions (< 14). The types for cookie are now bundled, so that there is no conflict with the types coming from `cookie@1`: > error TS2724: '"cookie"' has no exported member named 'CookieSerializeOptions'. Did you mean 'SerializeOptions'? > > import type { CookieSerializeOptions } from "cookie"; > ~~~~~~~~~~~~~~~~~~~~~~ Related: #5283
1 parent 62e4da1 commit 5a31aaf

File tree

5 files changed

+129
-10
lines changed

5 files changed

+129
-10
lines changed

package-lock.json

+8-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"base64-arraybuffer": "^1.0.2",
4444
"benchmark": "^2.1.4",
4545
"blob": "^0.1.0",
46+
"cookie": "~0.7.2",
4647
"eiows": "^7.1.0",
4748
"engine.io-client-v3": "npm:engine.io-client@^3.5.2",
4849
"expect.js": "^0.3.1",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// imported from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/b83cf9ef8b044e69f05b2a00aa7c6cb767a9acd2/types/cookie/index.d.ts (now deleted)
2+
/**
3+
* Basic HTTP cookie parser and serializer for HTTP servers.
4+
*/
5+
6+
/**
7+
* Additional serialization options
8+
*/
9+
export interface CookieSerializeOptions {
10+
/**
11+
* Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.3|Domain Set-Cookie attribute}. By default, no
12+
* domain is set, and most clients will consider the cookie to apply to only
13+
* the current domain.
14+
*/
15+
domain?: string | undefined;
16+
17+
/**
18+
* Specifies a function that will be used to encode a cookie's value. Since
19+
* value of a cookie has a limited character set (and must be a simple
20+
* string), this function can be used to encode a value into a string suited
21+
* for a cookie's value.
22+
*
23+
* The default function is the global `encodeURIComponent`, which will
24+
* encode a JavaScript string into UTF-8 byte sequences and then URL-encode
25+
* any that fall outside of the cookie range.
26+
*/
27+
encode?(value: string): string;
28+
29+
/**
30+
* Specifies the `Date` object to be the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.1|`Expires` `Set-Cookie` attribute}. By default,
31+
* no expiration is set, and most clients will consider this a "non-persistent cookie" and will delete
32+
* it on a condition like exiting a web browser application.
33+
*
34+
* *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification}
35+
* states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is
36+
* possible not all clients by obey this, so if both are set, they should
37+
* point to the same date and time.
38+
*/
39+
expires?: Date | undefined;
40+
/**
41+
* Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.6|`HttpOnly` `Set-Cookie` attribute}.
42+
* When truthy, the `HttpOnly` attribute is set, otherwise it is not. By
43+
* default, the `HttpOnly` attribute is not set.
44+
*
45+
* *Note* be careful when setting this to true, as compliant clients will
46+
* not allow client-side JavaScript to see the cookie in `document.cookie`.
47+
*/
48+
httpOnly?: boolean | undefined;
49+
/**
50+
* Specifies the number (in seconds) to be the value for the `Max-Age`
51+
* `Set-Cookie` attribute. The given number will be converted to an integer
52+
* by rounding down. By default, no maximum age is set.
53+
*
54+
* *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification}
55+
* states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is
56+
* possible not all clients by obey this, so if both are set, they should
57+
* point to the same date and time.
58+
*/
59+
maxAge?: number | undefined;
60+
/**
61+
* Specifies the `boolean` value for the [`Partitioned` `Set-Cookie`](rfc-cutler-httpbis-partitioned-cookies)
62+
* attribute. When truthy, the `Partitioned` attribute is set, otherwise it is not. By default, the
63+
* `Partitioned` attribute is not set.
64+
*
65+
* **note** This is an attribute that has not yet been fully standardized, and may change in the future.
66+
* This also means many clients may ignore this attribute until they understand it.
67+
*
68+
* More information about can be found in [the proposal](https://github.com/privacycg/CHIPS)
69+
*/
70+
partitioned?: boolean | undefined;
71+
/**
72+
* Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.4|`Path` `Set-Cookie` attribute}.
73+
* By default, the path is considered the "default path".
74+
*/
75+
path?: string | undefined;
76+
/**
77+
* Specifies the `string` to be the value for the [`Priority` `Set-Cookie` attribute][rfc-west-cookie-priority-00-4.1].
78+
*
79+
* - `'low'` will set the `Priority` attribute to `Low`.
80+
* - `'medium'` will set the `Priority` attribute to `Medium`, the default priority when not set.
81+
* - `'high'` will set the `Priority` attribute to `High`.
82+
*
83+
* More information about the different priority levels can be found in
84+
* [the specification][rfc-west-cookie-priority-00-4.1].
85+
*
86+
* **note** This is an attribute that has not yet been fully standardized, and may change in the future.
87+
* This also means many clients may ignore this attribute until they understand it.
88+
*/
89+
priority?: "low" | "medium" | "high" | undefined;
90+
/**
91+
* Specifies the boolean or string to be the value for the {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|`SameSite` `Set-Cookie` attribute}.
92+
*
93+
* - `true` will set the `SameSite` attribute to `Strict` for strict same
94+
* site enforcement.
95+
* - `false` will not set the `SameSite` attribute.
96+
* - `'lax'` will set the `SameSite` attribute to Lax for lax same site
97+
* enforcement.
98+
* - `'strict'` will set the `SameSite` attribute to Strict for strict same
99+
* site enforcement.
100+
* - `'none'` will set the SameSite attribute to None for an explicit
101+
* cross-site cookie.
102+
*
103+
* More information about the different enforcement levels can be found in {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|the specification}.
104+
*
105+
* *note* This is an attribute that has not yet been fully standardized, and may change in the future. This also means many clients may ignore this attribute until they understand it.
106+
*/
107+
sameSite?: true | false | "lax" | "strict" | "none" | undefined;
108+
/**
109+
* Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.5|`Secure` `Set-Cookie` attribute}. When truthy, the
110+
* `Secure` attribute is set, otherwise it is not. By default, the `Secure` attribute is not set.
111+
*
112+
* *Note* be careful when setting this to `true`, as compliant clients will
113+
* not send the cookie back to the server in the future if the browser does
114+
* not have an HTTPS connection.
115+
*/
116+
secure?: boolean | undefined;
117+
}

packages/engine.io/lib/server.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { EventEmitter } from "events";
66
import { Socket } from "./socket";
77
import debugModule from "debug";
88
import { serialize } from "cookie";
9-
import type { SerializeOptions } from "cookie";
109
import { Server as DEFAULT_WS_ENGINE } from "ws";
1110
import type {
1211
IncomingMessage,
@@ -18,6 +17,7 @@ import type { Duplex } from "stream";
1817
import { WebTransport } from "./transports/webtransport";
1918
import { createPacketDecoderStream } from "engine.io-parser";
2019
import type { EngineRequest } from "./transport";
20+
import type { CookieSerializeOptions } from "./contrib/types.cookie";
2121

2222
const debug = debugModule("engine");
2323

@@ -123,7 +123,7 @@ export interface ServerOptions {
123123
* might be used for sticky-session. Defaults to not sending any cookie.
124124
* @default false
125125
*/
126-
cookie?: (SerializeOptions & { name: string }) | boolean;
126+
cookie?: (CookieSerializeOptions & { name: string }) | boolean;
127127
/**
128128
* the options that will be forwarded to the cors module
129129
*/

packages/engine.io/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"@types/node": ">=10.0.0",
3636
"accepts": "~1.3.4",
3737
"base64id": "2.0.0",
38-
"cookie": "~1.0.2",
38+
"cookie": "~0.7.2",
3939
"cors": "~2.8.5",
4040
"debug": "~4.3.1",
4141
"engine.io-parser": "~5.2.1",

0 commit comments

Comments
 (0)