@farm.js/integration-utils 0.1.30 → 0.1.34
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/dist/cookies.d.ts.map +1 -1
- package/dist/cookies.js +30 -6
- package/package.json +2 -2
package/dist/cookies.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../src/cookies.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,IAAI,CAAC;CAChB;AAED,8EAA8E;AAC9E,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CASlF;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,YAAY,EAAE,CAE3E;AAED,iFAAiF;AACjF,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAK5E;AAED,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,oBAAyB,GACjC,MAAM,
|
|
1
|
+
{"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../src/cookies.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,IAAI,CAAC;CAChB;AAED,8EAA8E;AAC9E,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CASlF;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,YAAY,EAAE,CAE3E;AAED,iFAAiF;AACjF,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAK5E;AAED,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,oBAAyB,GACjC,MAAM,CA0CR;AAED,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,IAAI,CAAC,oBAAoB,EAAE,QAAQ,CAAM,GACjD,MAAM,CAKR"}
|
package/dist/cookies.js
CHANGED
|
@@ -18,14 +18,27 @@ export function getCookieValue(headers, name) {
|
|
|
18
18
|
null);
|
|
19
19
|
}
|
|
20
20
|
export function createRequestCookie(name, value, request, options = {}) {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const sameSite = options.sameSite || "Lax";
|
|
22
|
+
// Browsers silently discard a `__Host-` or `__Secure-` cookie without the
|
|
23
|
+
// attributes its name requires, and a SameSite=None cookie without Secure.
|
|
24
|
+
// Both a set and its deletion would then do nothing, so these come from the
|
|
25
|
+
// name and SameSite rather than from the caller.
|
|
26
|
+
const hostPrefixed = name.startsWith("__Host-");
|
|
27
|
+
const secure = hostPrefixed ||
|
|
28
|
+
name.startsWith("__Secure-") ||
|
|
29
|
+
sameSite === "None" ||
|
|
30
|
+
(options.secure ?? isHttpsRequest(request));
|
|
31
|
+
const path = hostPrefixed ? "/" : options.path || "/";
|
|
32
|
+
const domain = hostPrefixed ? undefined : options.domain;
|
|
33
|
+
const parts = [`${encodeURIComponent(name)}=${encodeURIComponent(value)}`, `Path=${path}`];
|
|
24
34
|
if (options.maxAge != null) {
|
|
35
|
+
if (!Number.isFinite(options.maxAge)) {
|
|
36
|
+
throw new TypeError(`Cookie "${name}" maxAge must be a finite number of seconds.`);
|
|
37
|
+
}
|
|
25
38
|
parts.push(`Max-Age=${Math.max(0, Math.floor(options.maxAge))}`);
|
|
26
39
|
}
|
|
27
|
-
if (
|
|
28
|
-
parts.push(`Domain=${
|
|
40
|
+
if (domain) {
|
|
41
|
+
parts.push(`Domain=${domain}`);
|
|
29
42
|
}
|
|
30
43
|
if (options.expires) {
|
|
31
44
|
parts.push(`Expires=${options.expires.toUTCString()}`);
|
|
@@ -36,7 +49,7 @@ export function createRequestCookie(name, value, request, options = {}) {
|
|
|
36
49
|
if (secure) {
|
|
37
50
|
parts.push("Secure");
|
|
38
51
|
}
|
|
39
|
-
parts.push(`SameSite=${
|
|
52
|
+
parts.push(`SameSite=${sameSite}`);
|
|
40
53
|
return parts.join("; ");
|
|
41
54
|
}
|
|
42
55
|
export function clearRequestCookie(name, request, options = {}) {
|
|
@@ -45,3 +58,14 @@ export function clearRequestCookie(name, request, options = {}) {
|
|
|
45
58
|
maxAge: 0,
|
|
46
59
|
});
|
|
47
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Behind a TLS-terminating proxy the request URL is `http:`. Trusting
|
|
63
|
+
* `X-Forwarded-Proto: https` here only ever adds `Secure`, and only for the
|
|
64
|
+
* client that sent it, so it is safe without `trustProxy`.
|
|
65
|
+
*/
|
|
66
|
+
function isHttpsRequest(request) {
|
|
67
|
+
if (new URL(request.url).protocol === "https:")
|
|
68
|
+
return true;
|
|
69
|
+
const forwarded = request.headers.get("x-forwarded-proto")?.split(",")[0]?.trim();
|
|
70
|
+
return forwarded?.toLowerCase() === "https";
|
|
71
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farm.js/integration-utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.34",
|
|
4
4
|
"description": "Shared integration utilities for Farm.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"access": "public"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@farm.js/core": "0.1.
|
|
56
|
+
"@farm.js/core": "0.1.34"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc",
|