@stryke/http 0.8.4 → 0.9.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/dist/agent.cjs +84 -0
- package/dist/agent.d.ts +36 -0
- package/dist/agent.mjs +2 -0
- package/dist/fetch.cjs +38 -0
- package/dist/fetch.d.ts +19 -0
- package/dist/fetch.mjs +1 -0
- package/dist/format-data-uri.cjs +24 -2
- package/dist/format-data-uri.d.ts +40 -0
- package/dist/format-data-uri.mjs +1 -1
- package/dist/http-proxy.cjs +71 -0
- package/dist/http-proxy.d.ts +39 -0
- package/dist/http-proxy.mjs +3 -0
- package/dist/https-proxy.cjs +88 -0
- package/dist/https-proxy.d.ts +43 -0
- package/dist/https-proxy.mjs +4 -0
- package/dist/index.cjs +52 -8
- package/dist/index.d.ts +6 -2
- package/dist/index.mjs +1 -1
- package/dist/parse-response.cjs +63 -0
- package/dist/parse-response.d.ts +12 -0
- package/dist/parse-response.mjs +4 -0
- package/dist/proxy-agent.cjs +14 -0
- package/dist/proxy-agent.d.ts +5 -0
- package/dist/proxy-agent.mjs +1 -0
- package/package.json +69 -18
- package/dist/cookie.cjs +0 -187
- package/dist/cookie.d.ts +0 -37
- package/dist/cookie.mjs +0 -1
- package/dist/types.cjs +0 -1
- package/dist/types.d.ts +0 -184
- package/dist/types.mjs +0 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.parseProxyResponse = parseProxyResponse;
|
|
7
|
+
var _nodeBuffer = require("node:buffer");
|
|
8
|
+
async function parseProxyResponse(e) {
|
|
9
|
+
return new Promise((g, o) => {
|
|
10
|
+
let p = 0;
|
|
11
|
+
const m = [];
|
|
12
|
+
function t() {
|
|
13
|
+
const r = e.read();
|
|
14
|
+
r ? v(r) : e.once("readable", t);
|
|
15
|
+
}
|
|
16
|
+
function f() {
|
|
17
|
+
e.removeListener("end", l), e.removeListener("error", y), e.removeListener("readable", t);
|
|
18
|
+
}
|
|
19
|
+
function l() {
|
|
20
|
+
f(), o(new Error("Proxy connection ended before receiving CONNECT response"));
|
|
21
|
+
}
|
|
22
|
+
function y(r) {
|
|
23
|
+
f(), o(r);
|
|
24
|
+
}
|
|
25
|
+
function v(r) {
|
|
26
|
+
m.push(r), p += r.length;
|
|
27
|
+
const a = _nodeBuffer.Buffer.concat(m, p),
|
|
28
|
+
h = a.indexOf(`\r
|
|
29
|
+
\r
|
|
30
|
+
`);
|
|
31
|
+
if (h === -1) {
|
|
32
|
+
t();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const C = a.subarray(0, h).toString("ascii").split(`\r
|
|
36
|
+
`),
|
|
37
|
+
b = C.shift();
|
|
38
|
+
if (!b) return e.destroy(), o(new Error("No header received from proxy CONNECT response"));
|
|
39
|
+
const x = b.split(" "),
|
|
40
|
+
E = +x[1],
|
|
41
|
+
H = x.slice(2).join(" "),
|
|
42
|
+
s = {};
|
|
43
|
+
for (const n of C) {
|
|
44
|
+
if (!n) continue;
|
|
45
|
+
const c = n.indexOf(":");
|
|
46
|
+
if (c === -1) return e.destroy(), o(new Error(`Invalid header from proxy CONNECT response: "${n}"`));
|
|
47
|
+
const d = n.slice(0, c).toLowerCase(),
|
|
48
|
+
u = n.slice(c + 1).trimStart(),
|
|
49
|
+
i = s[d];
|
|
50
|
+
typeof i == "string" ? s[d] = [i, u] : Array.isArray(i) ? i.push(u) : s[d] = u;
|
|
51
|
+
}
|
|
52
|
+
f(), g({
|
|
53
|
+
connect: {
|
|
54
|
+
statusCode: E,
|
|
55
|
+
statusText: H,
|
|
56
|
+
headers: s
|
|
57
|
+
},
|
|
58
|
+
buffered: a
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
e.on("error", y), e.on("end", l), t();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import type { IncomingHttpHeaders } from "node:http";
|
|
3
|
+
import type { Readable } from "node:stream";
|
|
4
|
+
export interface ConnectResponse {
|
|
5
|
+
statusCode: number;
|
|
6
|
+
statusText: string;
|
|
7
|
+
headers: IncomingHttpHeaders;
|
|
8
|
+
}
|
|
9
|
+
export declare function parseProxyResponse(socket: Readable): Promise<{
|
|
10
|
+
connect: ConnectResponse;
|
|
11
|
+
buffered: Buffer;
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{Buffer as L}from"node:buffer";export async function parseProxyResponse(e){return new Promise((g,o)=>{let p=0;const m=[];function t(){const r=e.read();r?v(r):e.once("readable",t)}function f(){e.removeListener("end",l),e.removeListener("error",y),e.removeListener("readable",t)}function l(){f(),o(new Error("Proxy connection ended before receiving CONNECT response"))}function y(r){f(),o(r)}function v(r){m.push(r),p+=r.length;const a=L.concat(m,p),h=a.indexOf(`\r
|
|
2
|
+
\r
|
|
3
|
+
`);if(h===-1){t();return}const C=a.subarray(0,h).toString("ascii").split(`\r
|
|
4
|
+
`),b=C.shift();if(!b)return e.destroy(),o(new Error("No header received from proxy CONNECT response"));const x=b.split(" "),E=+x[1],H=x.slice(2).join(" "),s={};for(const n of C){if(!n)continue;const c=n.indexOf(":");if(c===-1)return e.destroy(),o(new Error(`Invalid header from proxy CONNECT response: "${n}"`));const d=n.slice(0,c).toLowerCase(),u=n.slice(c+1).trimStart(),i=s[d];typeof i=="string"?s[d]=[i,u]:Array.isArray(i)?i.push(u):s[d]=u}f(),g({connect:{statusCode:E,statusText:H,headers:s},buffered:a})}e.on("error",y),e.on("end",l),t()})}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getProxyAgent = getProxyAgent;
|
|
7
|
+
var _httpProxy = require("./http-proxy.cjs");
|
|
8
|
+
var _httpsProxy = require("./https-proxy.cjs");
|
|
9
|
+
function getProxyAgent() {
|
|
10
|
+
const t = process.env.https_proxy || process.env.HTTPS_PROXY;
|
|
11
|
+
if (t) return new _httpsProxy.HttpsProxyAgent(t);
|
|
12
|
+
const e = process.env.http_proxy || process.env.HTTP_PROXY;
|
|
13
|
+
if (e) return new _httpProxy.HttpProxyAgent(e);
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{HttpProxyAgent as r}from"./http-proxy";import{HttpsProxyAgent as n}from"./https-proxy";export function getProxyAgent(){const t=process.env.https_proxy||process.env.HTTPS_PROXY;if(t)return new n(t);const e=process.env.http_proxy||process.env.HTTP_PROXY;if(e)return new r(e)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/http",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package containing HTTP communication utilities used by Storm Software.",
|
|
6
6
|
"repository": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"private": false,
|
|
12
12
|
"devDependencies": { "@types/node": "^22.14.0" },
|
|
13
13
|
"publishConfig": { "access": "public" },
|
|
14
|
-
"dependencies": { "@stryke/type-checks": "^0.3.
|
|
14
|
+
"dependencies": { "@stryke/type-checks": "^0.3.9" },
|
|
15
15
|
"sideEffects": false,
|
|
16
16
|
"files": ["dist/**/*"],
|
|
17
17
|
"homepage": "https://stormsoftware.com",
|
|
@@ -55,13 +55,33 @@
|
|
|
55
55
|
}
|
|
56
56
|
],
|
|
57
57
|
"exports": {
|
|
58
|
-
"./
|
|
59
|
-
"import": {
|
|
58
|
+
"./proxy-agent": {
|
|
59
|
+
"import": {
|
|
60
|
+
"types": "./dist/proxy-agent.d.ts",
|
|
61
|
+
"default": "./dist/proxy-agent.mjs"
|
|
62
|
+
},
|
|
60
63
|
"require": {
|
|
61
|
-
"types": "./dist/
|
|
62
|
-
"default": "./dist/
|
|
64
|
+
"types": "./dist/proxy-agent.d.ts",
|
|
65
|
+
"default": "./dist/proxy-agent.cjs"
|
|
63
66
|
},
|
|
64
|
-
"default": {
|
|
67
|
+
"default": {
|
|
68
|
+
"types": "./dist/proxy-agent.d.ts",
|
|
69
|
+
"default": "./dist/proxy-agent.mjs"
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"./parse-response": {
|
|
73
|
+
"import": {
|
|
74
|
+
"types": "./dist/parse-response.d.ts",
|
|
75
|
+
"default": "./dist/parse-response.mjs"
|
|
76
|
+
},
|
|
77
|
+
"require": {
|
|
78
|
+
"types": "./dist/parse-response.d.ts",
|
|
79
|
+
"default": "./dist/parse-response.cjs"
|
|
80
|
+
},
|
|
81
|
+
"default": {
|
|
82
|
+
"types": "./dist/parse-response.d.ts",
|
|
83
|
+
"default": "./dist/parse-response.mjs"
|
|
84
|
+
}
|
|
65
85
|
},
|
|
66
86
|
"./index": {
|
|
67
87
|
"import": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" },
|
|
@@ -71,6 +91,34 @@
|
|
|
71
91
|
},
|
|
72
92
|
"default": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" }
|
|
73
93
|
},
|
|
94
|
+
"./https-proxy": {
|
|
95
|
+
"import": {
|
|
96
|
+
"types": "./dist/https-proxy.d.ts",
|
|
97
|
+
"default": "./dist/https-proxy.mjs"
|
|
98
|
+
},
|
|
99
|
+
"require": {
|
|
100
|
+
"types": "./dist/https-proxy.d.ts",
|
|
101
|
+
"default": "./dist/https-proxy.cjs"
|
|
102
|
+
},
|
|
103
|
+
"default": {
|
|
104
|
+
"types": "./dist/https-proxy.d.ts",
|
|
105
|
+
"default": "./dist/https-proxy.mjs"
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
"./http-proxy": {
|
|
109
|
+
"import": {
|
|
110
|
+
"types": "./dist/http-proxy.d.ts",
|
|
111
|
+
"default": "./dist/http-proxy.mjs"
|
|
112
|
+
},
|
|
113
|
+
"require": {
|
|
114
|
+
"types": "./dist/http-proxy.d.ts",
|
|
115
|
+
"default": "./dist/http-proxy.cjs"
|
|
116
|
+
},
|
|
117
|
+
"default": {
|
|
118
|
+
"types": "./dist/http-proxy.d.ts",
|
|
119
|
+
"default": "./dist/http-proxy.mjs"
|
|
120
|
+
}
|
|
121
|
+
},
|
|
74
122
|
"./format-data-uri": {
|
|
75
123
|
"import": {
|
|
76
124
|
"types": "./dist/format-data-uri.d.ts",
|
|
@@ -85,19 +133,21 @@
|
|
|
85
133
|
"default": "./dist/format-data-uri.mjs"
|
|
86
134
|
}
|
|
87
135
|
},
|
|
88
|
-
"./
|
|
89
|
-
"import": {
|
|
90
|
-
|
|
91
|
-
"
|
|
136
|
+
"./fetch": {
|
|
137
|
+
"import": { "types": "./dist/fetch.d.ts", "default": "./dist/fetch.mjs" },
|
|
138
|
+
"require": {
|
|
139
|
+
"types": "./dist/fetch.d.ts",
|
|
140
|
+
"default": "./dist/fetch.cjs"
|
|
92
141
|
},
|
|
142
|
+
"default": { "types": "./dist/fetch.d.ts", "default": "./dist/fetch.mjs" }
|
|
143
|
+
},
|
|
144
|
+
"./agent": {
|
|
145
|
+
"import": { "types": "./dist/agent.d.ts", "default": "./dist/agent.mjs" },
|
|
93
146
|
"require": {
|
|
94
|
-
"types": "./dist/
|
|
95
|
-
"default": "./dist/
|
|
147
|
+
"types": "./dist/agent.d.ts",
|
|
148
|
+
"default": "./dist/agent.cjs"
|
|
96
149
|
},
|
|
97
|
-
"default": {
|
|
98
|
-
"types": "./dist/cookie.d.ts",
|
|
99
|
-
"default": "./dist/cookie.mjs"
|
|
100
|
-
}
|
|
150
|
+
"default": { "types": "./dist/agent.d.ts", "default": "./dist/agent.mjs" }
|
|
101
151
|
},
|
|
102
152
|
".": {
|
|
103
153
|
"import": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" },
|
|
@@ -111,5 +161,6 @@
|
|
|
111
161
|
},
|
|
112
162
|
"main": "./dist/index.cjs",
|
|
113
163
|
"module": "./dist/index.mjs",
|
|
114
|
-
"types": "./dist/index.d.ts"
|
|
164
|
+
"types": "./dist/index.d.ts",
|
|
165
|
+
"gitHead": "e16a03d7f9db49ef07f8b9368c56182fa84e2bf6"
|
|
115
166
|
}
|
package/dist/cookie.cjs
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.parseCookie = parseCookie;
|
|
7
|
-
exports.parseSetCookie = parseSetCookie;
|
|
8
|
-
exports.serializeCookie = serializeCookie;
|
|
9
|
-
exports.splitSetCookieString = splitSetCookieString;
|
|
10
|
-
var _typeChecks = require("@stryke/type-checks");
|
|
11
|
-
function parseCookie(r, c) {
|
|
12
|
-
if (!(0, _typeChecks.isString)(r)) throw new Error("argument str must be a string");
|
|
13
|
-
const i = {},
|
|
14
|
-
e = c ?? {},
|
|
15
|
-
o = e.decode ?? (t => t.includes("%") ? decodeURIComponent(t) : t);
|
|
16
|
-
let a = 0;
|
|
17
|
-
for (; a < r.length;) {
|
|
18
|
-
const t = r.indexOf("=", a);
|
|
19
|
-
if (t === -1) break;
|
|
20
|
-
let n = r.indexOf(";", a);
|
|
21
|
-
if (n === -1) n = r.length;else if (n < t) {
|
|
22
|
-
a = r.lastIndexOf(";", t - 1) + 1;
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
const s = r.slice(a, t).trim();
|
|
26
|
-
if (e?.filter && !e?.filter(s)) {
|
|
27
|
-
a = n + 1;
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
if (i[s] === void 0) {
|
|
31
|
-
let l = r.slice(t + 1, n).trim();
|
|
32
|
-
l.codePointAt(0) === 34 && (l = l.slice(1, -1));
|
|
33
|
-
try {
|
|
34
|
-
i[s] = o(l);
|
|
35
|
-
} catch {
|
|
36
|
-
i[s] = l;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
a = n + 1;
|
|
40
|
-
}
|
|
41
|
-
return i;
|
|
42
|
-
}
|
|
43
|
-
function parseSetCookie(r, c) {
|
|
44
|
-
const i = (r || "").split(";").filter(s => (0, _typeChecks.isString)(s) && !!s.trim()),
|
|
45
|
-
e = i.shift() || "";
|
|
46
|
-
let o = "",
|
|
47
|
-
a = "";
|
|
48
|
-
const t = e.split("=");
|
|
49
|
-
t.length > 1 ? (o = t.shift(), a = t.join("=")) : a = e;
|
|
50
|
-
try {
|
|
51
|
-
a = c?.decode === !1 ? a : (c?.decode ?? decodeURIComponent)(a);
|
|
52
|
-
} catch {}
|
|
53
|
-
const n = {
|
|
54
|
-
name: o,
|
|
55
|
-
value: a
|
|
56
|
-
};
|
|
57
|
-
for (const s of i) {
|
|
58
|
-
const l = s.split("="),
|
|
59
|
-
f = (l.shift() || "").trimStart().toLowerCase(),
|
|
60
|
-
m = l.join("=");
|
|
61
|
-
switch (f) {
|
|
62
|
-
case "expires":
|
|
63
|
-
{
|
|
64
|
-
n.expires = new Date(m);
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
case "max-age":
|
|
68
|
-
{
|
|
69
|
-
n.maxAge = Number.parseInt(m, 10);
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
case "secure":
|
|
73
|
-
{
|
|
74
|
-
n.secure = !0;
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
case "httponly":
|
|
78
|
-
{
|
|
79
|
-
n.httpOnly = !0;
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
case "samesite":
|
|
83
|
-
{
|
|
84
|
-
n.sameSite = m;
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
default:
|
|
88
|
-
n[f] = m;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return n;
|
|
92
|
-
}
|
|
93
|
-
const u = /^[\t\u0020-\u007E\u0080-\u00FF]+$/;
|
|
94
|
-
function serializeCookie(r, c, i) {
|
|
95
|
-
const e = i ?? {},
|
|
96
|
-
o = e.encode ?? encodeURIComponent;
|
|
97
|
-
if (!(0, _typeChecks.isFunction)(o)) throw new Error("option encode is invalid");
|
|
98
|
-
if (!u.test(r)) throw new Error("argument name is invalid");
|
|
99
|
-
const a = o(c);
|
|
100
|
-
if (a && !u.test(a)) throw new Error("argument val is invalid");
|
|
101
|
-
let t = `${r}=${a}`;
|
|
102
|
-
if (!(0, _typeChecks.isSet)(e.maxAge)) {
|
|
103
|
-
const n = Number(e.maxAge);
|
|
104
|
-
if (Number.isNaN(n) || !Number.isFinite(n)) throw new TypeError("option maxAge is invalid");
|
|
105
|
-
t += `; Max-Age=${Math.floor(n)}`;
|
|
106
|
-
}
|
|
107
|
-
if (e.domain) {
|
|
108
|
-
if (!u.test(e.domain)) throw new Error("option domain is invalid");
|
|
109
|
-
t += `; Domain=${e.domain}`;
|
|
110
|
-
}
|
|
111
|
-
if (e.path) {
|
|
112
|
-
if (!u.test(e.path)) throw new Error("option path is invalid");
|
|
113
|
-
t += `; Path=${e.path}`;
|
|
114
|
-
}
|
|
115
|
-
if (e.expires) {
|
|
116
|
-
if (!(0, _typeChecks.isDate)(e.expires) || Number.isNaN(e.expires.valueOf())) throw new Error("option expires is invalid");
|
|
117
|
-
t += `; Expires=${e.expires.toUTCString()}`;
|
|
118
|
-
}
|
|
119
|
-
if (e.httpOnly && (t += "; HttpOnly"), e.secure && (t += "; Secure"), e.priority) switch ((0, _typeChecks.isString)(e.priority) ? e.priority.toLowerCase() : e.priority) {
|
|
120
|
-
case "low":
|
|
121
|
-
{
|
|
122
|
-
t += "; Priority=Low";
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
case "medium":
|
|
126
|
-
{
|
|
127
|
-
t += "; Priority=Medium";
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
case "high":
|
|
131
|
-
{
|
|
132
|
-
t += "; Priority=High";
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
default:
|
|
136
|
-
throw new Error("option priority is invalid");
|
|
137
|
-
}
|
|
138
|
-
if (e.sameSite) switch ((0, _typeChecks.isString)(e.sameSite) ? e.sameSite.toLowerCase() : e.sameSite) {
|
|
139
|
-
case !0:
|
|
140
|
-
{
|
|
141
|
-
t += "; SameSite=Strict";
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
case "lax":
|
|
145
|
-
{
|
|
146
|
-
t += "; SameSite=Lax";
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
case "strict":
|
|
150
|
-
{
|
|
151
|
-
t += "; SameSite=Strict";
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
case "none":
|
|
155
|
-
{
|
|
156
|
-
t += "; SameSite=None";
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
default:
|
|
160
|
-
throw new Error("option sameSite is invalid");
|
|
161
|
-
}
|
|
162
|
-
return e.partitioned && (t += "; Partitioned"), t;
|
|
163
|
-
}
|
|
164
|
-
function splitSetCookieString(r) {
|
|
165
|
-
if (Array.isArray(r)) return r.flatMap(f => splitSetCookieString(f));
|
|
166
|
-
if (!(0, _typeChecks.isString)(r)) return [];
|
|
167
|
-
const c = [];
|
|
168
|
-
let i = 0,
|
|
169
|
-
e,
|
|
170
|
-
o,
|
|
171
|
-
a,
|
|
172
|
-
t,
|
|
173
|
-
n;
|
|
174
|
-
const s = () => {
|
|
175
|
-
for (; i < r.length && /\s/.test(r.charAt(i));) i += 1;
|
|
176
|
-
return i < r.length;
|
|
177
|
-
},
|
|
178
|
-
l = () => (o = r.charAt(i), o !== "=" && o !== ";" && o !== ",");
|
|
179
|
-
for (; i < r.length;) {
|
|
180
|
-
for (e = i, n = !1; s();) if (o = r.charAt(i), o === ",") {
|
|
181
|
-
for (a = i, i += 1, s(), t = i; i < r.length && l();) i += 1;
|
|
182
|
-
i < r.length && r.charAt(i) === "=" ? (n = !0, i = t, c.push(r.slice(e, a)), e = i) : i = a + 1;
|
|
183
|
-
} else i += 1;
|
|
184
|
-
(!n || i >= r.length) && c.push(r.slice(e));
|
|
185
|
-
}
|
|
186
|
-
return c;
|
|
187
|
-
}
|
package/dist/cookie.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { CookieParseOptions, CookieSerializeOptions, SetCookie, SetCookieParseOptions } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Parse an HTTP Cookie header string and returning an object of all cookie
|
|
4
|
-
* name-value pairs.
|
|
5
|
-
*
|
|
6
|
-
* @param strCookie - the string representing a `Cookie` header value
|
|
7
|
-
* @param options - object containing parsing options
|
|
8
|
-
* @returns an object with the parsed cookies
|
|
9
|
-
*/
|
|
10
|
-
export declare function parseCookie(strCookie: string, options?: CookieParseOptions): Record<string, string>;
|
|
11
|
-
/**
|
|
12
|
-
* Parse a [Set-Cookie](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie) header string into an object.
|
|
13
|
-
*
|
|
14
|
-
* @param setCookieValue - the string representing a `Set-Cookie` header value
|
|
15
|
-
* @param options - object containing parsing options
|
|
16
|
-
* @returns an object with the parsed cookie
|
|
17
|
-
*/
|
|
18
|
-
export declare function parseSetCookie(setCookieValue: string, options?: SetCookieParseOptions): SetCookie;
|
|
19
|
-
/**
|
|
20
|
-
* Serialize a cookie name-value pair into a `Set-Cookie` header string.
|
|
21
|
-
*
|
|
22
|
-
* @param name - the name for the cookie
|
|
23
|
-
* @param value - value to set the cookie to
|
|
24
|
-
* @param options - object containing serialization options
|
|
25
|
-
* @returns a `Set-Cookie` header string
|
|
26
|
-
*/
|
|
27
|
-
export declare function serializeCookie(name: string, value: string, options?: CookieSerializeOptions): string;
|
|
28
|
-
/**
|
|
29
|
-
* Set-Cookie header field-values are sometimes comma joined in one string. This splits them without choking on commas
|
|
30
|
-
* that are within a single set-cookie field-value, such as in the Expires portion.
|
|
31
|
-
*
|
|
32
|
-
* See https://tools.ietf.org/html/rfc2616#section-4.2
|
|
33
|
-
*
|
|
34
|
-
* @param strCookie - The string representing a `Set-Cookie` header value
|
|
35
|
-
* @returns An array of strings representing individual `Set-Cookie` header values
|
|
36
|
-
*/
|
|
37
|
-
export declare function splitSetCookieString(strCookie: string | string[]): string[];
|
package/dist/cookie.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{isDate as h,isFunction as d,isSet as g,isString as p}from"@stryke/type-checks";export function parseCookie(r,c){if(!p(r))throw new Error("argument str must be a string");const i={},e=c??{},o=e.decode??(t=>t.includes("%")?decodeURIComponent(t):t);let a=0;for(;a<r.length;){const t=r.indexOf("=",a);if(t===-1)break;let n=r.indexOf(";",a);if(n===-1)n=r.length;else if(n<t){a=r.lastIndexOf(";",t-1)+1;continue}const s=r.slice(a,t).trim();if(e?.filter&&!e?.filter(s)){a=n+1;continue}if(i[s]===void 0){let l=r.slice(t+1,n).trim();l.codePointAt(0)===34&&(l=l.slice(1,-1));try{i[s]=o(l)}catch{i[s]=l}}a=n+1}return i}export function parseSetCookie(r,c){const i=(r||"").split(";").filter(s=>p(s)&&!!s.trim()),e=i.shift()||"";let o="",a="";const t=e.split("=");t.length>1?(o=t.shift(),a=t.join("=")):a=e;try{a=c?.decode===!1?a:(c?.decode??decodeURIComponent)(a)}catch{}const n={name:o,value:a};for(const s of i){const l=s.split("="),f=(l.shift()||"").trimStart().toLowerCase(),m=l.join("=");switch(f){case"expires":{n.expires=new Date(m);break}case"max-age":{n.maxAge=Number.parseInt(m,10);break}case"secure":{n.secure=!0;break}case"httponly":{n.httpOnly=!0;break}case"samesite":{n.sameSite=m;break}default:n[f]=m}}return n}const u=/^[\t\u0020-\u007E\u0080-\u00FF]+$/;export function serializeCookie(r,c,i){const e=i??{},o=e.encode??encodeURIComponent;if(!d(o))throw new Error("option encode is invalid");if(!u.test(r))throw new Error("argument name is invalid");const a=o(c);if(a&&!u.test(a))throw new Error("argument val is invalid");let t=`${r}=${a}`;if(!g(e.maxAge)){const n=Number(e.maxAge);if(Number.isNaN(n)||!Number.isFinite(n))throw new TypeError("option maxAge is invalid");t+=`; Max-Age=${Math.floor(n)}`}if(e.domain){if(!u.test(e.domain))throw new Error("option domain is invalid");t+=`; Domain=${e.domain}`}if(e.path){if(!u.test(e.path))throw new Error("option path is invalid");t+=`; Path=${e.path}`}if(e.expires){if(!h(e.expires)||Number.isNaN(e.expires.valueOf()))throw new Error("option expires is invalid");t+=`; Expires=${e.expires.toUTCString()}`}if(e.httpOnly&&(t+="; HttpOnly"),e.secure&&(t+="; Secure"),e.priority)switch(p(e.priority)?e.priority.toLowerCase():e.priority){case"low":{t+="; Priority=Low";break}case"medium":{t+="; Priority=Medium";break}case"high":{t+="; Priority=High";break}default:throw new Error("option priority is invalid")}if(e.sameSite)switch(p(e.sameSite)?e.sameSite.toLowerCase():e.sameSite){case!0:{t+="; SameSite=Strict";break}case"lax":{t+="; SameSite=Lax";break}case"strict":{t+="; SameSite=Strict";break}case"none":{t+="; SameSite=None";break}default:throw new Error("option sameSite is invalid")}return e.partitioned&&(t+="; Partitioned"),t}export function splitSetCookieString(r){if(Array.isArray(r))return r.flatMap(f=>splitSetCookieString(f));if(!p(r))return[];const c=[];let i=0,e,o,a,t,n;const s=()=>{for(;i<r.length&&/\s/.test(r.charAt(i));)i+=1;return i<r.length},l=()=>(o=r.charAt(i),o!=="="&&o!==";"&&o!==",");for(;i<r.length;){for(e=i,n=!1;s();)if(o=r.charAt(i),o===","){for(a=i,i+=1,s(),t=i;i<r.length&&l();)i+=1;i<r.length&&r.charAt(i)==="="?(n=!0,i=t,c.push(r.slice(e,a)),e=i):i=a+1}else i+=1;(!n||i>=r.length)&&c.push(r.slice(e))}return c}
|
package/dist/types.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/dist/types.d.ts
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cookie serialization options
|
|
3
|
-
*/
|
|
4
|
-
export interface CookieSerializeOptions {
|
|
5
|
-
/**
|
|
6
|
-
* Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.3 | Domain Set-Cookie attribute}. By default, no
|
|
7
|
-
* domain is set, and most clients will consider the cookie to apply to only
|
|
8
|
-
* the current domain.
|
|
9
|
-
*/
|
|
10
|
-
domain?: string | undefined;
|
|
11
|
-
/**
|
|
12
|
-
* Specifies a function that will be used to encode a cookie's value. Since
|
|
13
|
-
* value of a cookie has a limited character set (and must be a simple
|
|
14
|
-
* string), this function can be used to encode a value into a string suited
|
|
15
|
-
* for a cookie's value.
|
|
16
|
-
*
|
|
17
|
-
* The default function is the global `encodeURIComponent`, which will
|
|
18
|
-
* encode a JavaScript string into UTF-8 byte sequences and then URL-encode
|
|
19
|
-
* any that fall outside of the cookie range.
|
|
20
|
-
*/
|
|
21
|
-
encode?: (value: string) => string;
|
|
22
|
-
/**
|
|
23
|
-
* 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,
|
|
24
|
-
* no expiration is set, and most clients will consider this a "non-persistent cookie" and will delete
|
|
25
|
-
* it on a condition like exiting a web browser application.
|
|
26
|
-
*
|
|
27
|
-
* Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3 | cookie storage model specification}
|
|
28
|
-
* states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is
|
|
29
|
-
* possible not all clients by obey this, so if both are set, they should
|
|
30
|
-
* point to the same date and time.
|
|
31
|
-
*/
|
|
32
|
-
expires?: Date | undefined;
|
|
33
|
-
/**
|
|
34
|
-
* Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.6 | `HttpOnly` `Set-Cookie` attribute}.
|
|
35
|
-
* When truthy, the `HttpOnly` attribute is set, otherwise it is not. By
|
|
36
|
-
* default, the `HttpOnly` attribute is not set.
|
|
37
|
-
*
|
|
38
|
-
* Note* be careful when setting this to true, as compliant clients will
|
|
39
|
-
* not allow client-side JavaScript to see the cookie in `document.cookie`.
|
|
40
|
-
*/
|
|
41
|
-
httpOnly?: boolean | undefined;
|
|
42
|
-
/**
|
|
43
|
-
* Specifies the number (in seconds) to be the value for the `Max-Age`
|
|
44
|
-
* `Set-Cookie` attribute. The given number will be converted to an integer
|
|
45
|
-
* by rounding down. By default, no maximum age is set.
|
|
46
|
-
*
|
|
47
|
-
* Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3 | cookie storage model specification}
|
|
48
|
-
* states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is
|
|
49
|
-
* possible not all clients by obey this, so if both are set, they should
|
|
50
|
-
* point to the same date and time.
|
|
51
|
-
*/
|
|
52
|
-
maxAge?: number | undefined;
|
|
53
|
-
/**
|
|
54
|
-
* Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.4|`Path` `Set-Cookie` attribute}.
|
|
55
|
-
* By default, the path is considered the "default path".
|
|
56
|
-
*/
|
|
57
|
-
path?: string | undefined;
|
|
58
|
-
/**
|
|
59
|
-
* Specifies the `string` to be the value for the [`Priority` `Set-Cookie` attribute][rfc-west-cookie-priority-00-4.1].
|
|
60
|
-
*
|
|
61
|
-
* - `'low'` will set the `Priority` attribute to `Low`.
|
|
62
|
-
* - `'medium'` will set the `Priority` attribute to `Medium`, the default priority when not set.
|
|
63
|
-
* - `'high'` will set the `Priority` attribute to `High`.
|
|
64
|
-
*
|
|
65
|
-
* More information about the different priority levels can be found in
|
|
66
|
-
* [the specification][rfc-west-cookie-priority-00-4.1].
|
|
67
|
-
*
|
|
68
|
-
* **note** This is an attribute that has not yet been fully standardized, and may change in the future.
|
|
69
|
-
* This also means many clients may ignore this attribute until they understand it.
|
|
70
|
-
*/
|
|
71
|
-
priority?: "low" | "medium" | "high" | undefined;
|
|
72
|
-
/**
|
|
73
|
-
* 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}.
|
|
74
|
-
*
|
|
75
|
-
* - `true` will set the `SameSite` attribute to `Strict` for strict same
|
|
76
|
-
* site enforcement.
|
|
77
|
-
* - `false` will not set the `SameSite` attribute.
|
|
78
|
-
* - `'lax'` will set the `SameSite` attribute to Lax for lax same site
|
|
79
|
-
* enforcement.
|
|
80
|
-
* - `'strict'` will set the `SameSite` attribute to Strict for strict same
|
|
81
|
-
* site enforcement.
|
|
82
|
-
* - `'none'` will set the SameSite attribute to None for an explicit
|
|
83
|
-
* cross-site cookie.
|
|
84
|
-
*
|
|
85
|
-
* 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}.
|
|
86
|
-
*
|
|
87
|
-
* 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.
|
|
88
|
-
*/
|
|
89
|
-
sameSite?: true | false | "lax" | "strict" | "none" | undefined;
|
|
90
|
-
/**
|
|
91
|
-
* Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.5 | `Secure` `Set-Cookie` attribute}. When truthy, the
|
|
92
|
-
* `Secure` attribute is set, otherwise it is not. By default, the `Secure` attribute is not set.
|
|
93
|
-
*
|
|
94
|
-
* Note* be careful when setting this to `true`, as compliant clients will
|
|
95
|
-
* not send the cookie back to the server in the future if the browser does
|
|
96
|
-
* not have an HTTPS connection.
|
|
97
|
-
*/
|
|
98
|
-
secure?: boolean | undefined;
|
|
99
|
-
/**
|
|
100
|
-
* Specifies the `boolean` value for the [`Partitioned` `Set-Cookie`](https://datatracker.ietf.org/doc/html/draft-cutler-httpbis-partitioned-cookies#section-2.1)
|
|
101
|
-
* attribute. When truthy, the `Partitioned` attribute is set, otherwise it is not. By default, the
|
|
102
|
-
* `Partitioned` attribute is not set.
|
|
103
|
-
*
|
|
104
|
-
* **note** This is an attribute that has not yet been fully standardized, and may change in the future.
|
|
105
|
-
* This also means many clients may ignore this attribute until they understand it.
|
|
106
|
-
*
|
|
107
|
-
* More information can be found in the [proposal](https://github.com/privacycg/CHIPS).
|
|
108
|
-
*/
|
|
109
|
-
partitioned?: boolean;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Additional parsing options
|
|
113
|
-
*/
|
|
114
|
-
export interface CookieParseOptions {
|
|
115
|
-
/**
|
|
116
|
-
* Specifies a function that will be used to decode a cookie's value. Since
|
|
117
|
-
* the value of a cookie has a limited character set (and must be a simple
|
|
118
|
-
* string), this function can be used to decode a previously-encoded cookie
|
|
119
|
-
* value into a JavaScript string or other object.
|
|
120
|
-
*
|
|
121
|
-
* The default function is the global `decodeURIComponent`, which will decode
|
|
122
|
-
* any URL-encoded sequences into their byte representations.
|
|
123
|
-
*
|
|
124
|
-
* Note* if an error is thrown from this function, the original, non-decoded
|
|
125
|
-
* cookie value will be returned as the cookie's value.
|
|
126
|
-
*/
|
|
127
|
-
decode?: (value: string) => string;
|
|
128
|
-
/**
|
|
129
|
-
* Custom function to filter parsing specific keys.
|
|
130
|
-
*/
|
|
131
|
-
filter?: (key: string) => boolean;
|
|
132
|
-
}
|
|
133
|
-
export interface SetCookieParseOptions {
|
|
134
|
-
/**
|
|
135
|
-
* Custom decode function to use on cookie values.
|
|
136
|
-
*
|
|
137
|
-
* By default, `decodeURIComponent` is used.
|
|
138
|
-
*
|
|
139
|
-
* **Note:** If decoding fails, the original (undecoded) value will be used
|
|
140
|
-
*/
|
|
141
|
-
decode?: false | ((value: string) => string);
|
|
142
|
-
}
|
|
143
|
-
export interface SetCookie {
|
|
144
|
-
/**
|
|
145
|
-
* Cookie name
|
|
146
|
-
*/
|
|
147
|
-
name: string;
|
|
148
|
-
/**
|
|
149
|
-
* Cookie value
|
|
150
|
-
*/
|
|
151
|
-
value: string;
|
|
152
|
-
/**
|
|
153
|
-
* Cookie path
|
|
154
|
-
*/
|
|
155
|
-
path?: string | undefined;
|
|
156
|
-
/**
|
|
157
|
-
* Absolute expiration date for the cookie
|
|
158
|
-
*/
|
|
159
|
-
expires?: Date | undefined;
|
|
160
|
-
/**
|
|
161
|
-
* Relative max age of the cookie in seconds from when the client receives it (integer or undefined)
|
|
162
|
-
*
|
|
163
|
-
* Note: when using with express's res.cookie() method, multiply maxAge by 1000 to convert to milliseconds
|
|
164
|
-
*/
|
|
165
|
-
maxAge?: number | undefined;
|
|
166
|
-
/**
|
|
167
|
-
* Domain for the cookie,
|
|
168
|
-
* May begin with "." to indicate the named domain or any subdomain of it
|
|
169
|
-
*/
|
|
170
|
-
domain?: string | undefined;
|
|
171
|
-
/**
|
|
172
|
-
* Indicates that this cookie should only be sent over HTTPs
|
|
173
|
-
*/
|
|
174
|
-
secure?: boolean | undefined;
|
|
175
|
-
/**
|
|
176
|
-
* Indicates that this cookie should not be accessible to client-side JavaScript
|
|
177
|
-
*/
|
|
178
|
-
httpOnly?: boolean | undefined;
|
|
179
|
-
/**
|
|
180
|
-
* Indicates a cookie ought not to be sent along with cross-site requests
|
|
181
|
-
*/
|
|
182
|
-
sameSite?: true | false | "lax" | "strict" | "none" | undefined;
|
|
183
|
-
[key: string]: unknown;
|
|
184
|
-
}
|
package/dist/types.mjs
DELETED
|
File without changes
|