rekwest 7.2.7 → 8.1.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/README.md +264 -260
- package/dist/ackn.cjs +9 -0
- package/dist/config.cjs +2 -1
- package/dist/cookies.cjs +1 -1
- package/dist/transfer.cjs +1 -5
- package/dist/utils.cjs +4 -0
- package/package.json +81 -76
- package/src/ackn.js +46 -33
- package/src/config.js +91 -90
- package/src/constants.js +11 -11
- package/src/cookies.js +121 -121
- package/src/errors.js +18 -18
- package/src/formdata.js +229 -229
- package/src/index.js +83 -83
- package/src/mediatypes.js +6 -6
- package/src/mixin.js +118 -118
- package/src/postflight.js +64 -64
- package/src/preflight.js +84 -84
- package/src/redirects.js +86 -86
- package/src/transfer.js +104 -106
- package/src/transform.js +112 -112
- package/src/utils.js +198 -193
- package/src/validation.js +33 -33
package/src/cookies.js
CHANGED
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
import {
|
|
2
|
-
brandCheck,
|
|
3
|
-
toCamelCase,
|
|
4
|
-
} from './utils.js';
|
|
5
|
-
|
|
6
|
-
export const cookieRex = /^[^=]+=(?:"[^"]*"|[^\p{Control};]*)(?:;\s*(?:[^=]+=(?:"[^"]*"|[^\p{Control};]*)|[^=]+))*$/u;
|
|
7
|
-
export const cookiePairRex = /[^;\s]+=(?:"[^"]*"|[
|
|
8
|
-
export const illegalCookieChars = /\p{Control}/u;
|
|
9
|
-
export const isValidCookie = (str) => str?.constructor === String && cookieRex.test(str);
|
|
10
|
-
export const maxCookieLifetimeCap = 3456e7; // 400 days
|
|
11
|
-
export const maxCookieSize = 4096;
|
|
12
|
-
export const splitCookie = (str) => str.match(cookiePairRex);
|
|
13
|
-
|
|
14
|
-
export class Cookies extends URLSearchParams {
|
|
15
|
-
|
|
16
|
-
static #finalizers = new Set();
|
|
17
|
-
static jar = new Map();
|
|
18
|
-
|
|
19
|
-
static #register(target, val) {
|
|
20
|
-
const finalizer = new FinalizationRegistry((heldVal) => {
|
|
21
|
-
clearTimeout(heldVal);
|
|
22
|
-
this.#finalizers.delete(finalizer);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
finalizer.register(target, val);
|
|
26
|
-
this.#finalizers.add(finalizer);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
#chronometry = new Map();
|
|
30
|
-
|
|
31
|
-
get [Symbol.toStringTag]() {
|
|
32
|
-
return this.constructor.name;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
constructor(input, { cookiesTTL } = { cookiesTTL: false }) {
|
|
36
|
-
if (isValidCookie(input)) {
|
|
37
|
-
input = splitCookie(input);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const ttlMap = new Map();
|
|
41
|
-
|
|
42
|
-
if (Array.isArray(input)) {
|
|
43
|
-
if (input.every((it) => isValidCookie(it))) {
|
|
44
|
-
input = input.filter((it) => !illegalCookieChars.test(it) && it.length <= maxCookieSize);
|
|
45
|
-
input = input.map(splitCookie).map(([cookie, ...attrs]) => {
|
|
46
|
-
cookie = cookie.split(/=(?<v>.*)/s, 2).map((it) => {
|
|
47
|
-
try {
|
|
48
|
-
return decodeURIComponent(it);
|
|
49
|
-
} catch {
|
|
50
|
-
return it;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
if (cookiesTTL) {
|
|
55
|
-
for (const attr of attrs) {
|
|
56
|
-
if (/(?:expires|max-age)=/i.test(attr)) {
|
|
57
|
-
const [key, val] = attr.split(/=(?<v>.*)/s, 2);
|
|
58
|
-
let interval = val * 1e3 || Date.parse(val) - Date.now();
|
|
59
|
-
|
|
60
|
-
if (interval < 0 || Number.isNaN(interval)) {
|
|
61
|
-
interval = 0;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
ttlMap.set(
|
|
65
|
-
cookie[0],
|
|
66
|
-
{ [toCamelCase(key)]: Math.min(interval, maxCookieLifetimeCap) },
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return cookie;
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
super(input);
|
|
78
|
-
|
|
79
|
-
if (ttlMap.size) {
|
|
80
|
-
for (const [key, attrs] of ttlMap) {
|
|
81
|
-
|
|
82
|
-
if (this.#chronometry.has(key)) {
|
|
83
|
-
clearTimeout(this.#chronometry.get(key));
|
|
84
|
-
this.#chronometry.delete(key);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const { expires, maxAge } = attrs;
|
|
88
|
-
|
|
89
|
-
for (const interval of [
|
|
90
|
-
maxAge,
|
|
91
|
-
expires,
|
|
92
|
-
]) {
|
|
93
|
-
if (!Number.isInteger(interval)) {
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const ref = new WeakRef(this);
|
|
98
|
-
const tid = setTimeout(() => {
|
|
99
|
-
const ctx = ref.deref();
|
|
100
|
-
|
|
101
|
-
if (ctx) {
|
|
102
|
-
ctx.#chronometry.delete(key);
|
|
103
|
-
ctx.delete(key);
|
|
104
|
-
}
|
|
105
|
-
}, Math.max(interval, 0));
|
|
106
|
-
|
|
107
|
-
this.constructor.#register(this, tid);
|
|
108
|
-
this.#chronometry.set(key, tid);
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
toString() {
|
|
116
|
-
brandCheck(this, Cookies);
|
|
117
|
-
|
|
118
|
-
return super.toString().split('&').join('; ');
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
brandCheck,
|
|
3
|
+
toCamelCase,
|
|
4
|
+
} from './utils.js';
|
|
5
|
+
|
|
6
|
+
export const cookieRex = /^[^=]+=(?:"[^"]*"|[^\p{Control};]*)(?:;\s*(?:[^=]+=(?:"[^"]*"|[^\p{Control};]*)|[^=]+))*$/u;
|
|
7
|
+
export const cookiePairRex = /[^;\s]+=(?:"[^"]*"|[^;]*)/g;
|
|
8
|
+
export const illegalCookieChars = /\p{Control}/u;
|
|
9
|
+
export const isValidCookie = (str) => str?.constructor === String && cookieRex.test(str);
|
|
10
|
+
export const maxCookieLifetimeCap = 3456e7; // 400 days
|
|
11
|
+
export const maxCookieSize = 4096;
|
|
12
|
+
export const splitCookie = (str) => str.match(cookiePairRex);
|
|
13
|
+
|
|
14
|
+
export class Cookies extends URLSearchParams {
|
|
15
|
+
|
|
16
|
+
static #finalizers = new Set();
|
|
17
|
+
static jar = new Map();
|
|
18
|
+
|
|
19
|
+
static #register(target, val) {
|
|
20
|
+
const finalizer = new FinalizationRegistry((heldVal) => {
|
|
21
|
+
clearTimeout(heldVal);
|
|
22
|
+
this.#finalizers.delete(finalizer);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
finalizer.register(target, val);
|
|
26
|
+
this.#finalizers.add(finalizer);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
#chronometry = new Map();
|
|
30
|
+
|
|
31
|
+
get [Symbol.toStringTag]() {
|
|
32
|
+
return this.constructor.name;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
constructor(input, { cookiesTTL } = { cookiesTTL: false }) {
|
|
36
|
+
if (isValidCookie(input)) {
|
|
37
|
+
input = splitCookie(input);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const ttlMap = new Map();
|
|
41
|
+
|
|
42
|
+
if (Array.isArray(input)) {
|
|
43
|
+
if (input.every((it) => isValidCookie(it))) {
|
|
44
|
+
input = input.filter((it) => !illegalCookieChars.test(it) && it.length <= maxCookieSize);
|
|
45
|
+
input = input.map(splitCookie).map(([cookie, ...attrs]) => {
|
|
46
|
+
cookie = cookie.split(/=(?<v>.*)/s, 2).map((it) => {
|
|
47
|
+
try {
|
|
48
|
+
return decodeURIComponent(it);
|
|
49
|
+
} catch {
|
|
50
|
+
return it;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
if (cookiesTTL) {
|
|
55
|
+
for (const attr of attrs) {
|
|
56
|
+
if (/(?:expires|max-age)=/i.test(attr)) {
|
|
57
|
+
const [key, val] = attr.split(/=(?<v>.*)/s, 2);
|
|
58
|
+
let interval = val * 1e3 || Date.parse(val) - Date.now();
|
|
59
|
+
|
|
60
|
+
if (interval < 0 || Number.isNaN(interval)) {
|
|
61
|
+
interval = 0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
ttlMap.set(
|
|
65
|
+
cookie[0],
|
|
66
|
+
{ [toCamelCase(key)]: Math.min(interval, maxCookieLifetimeCap) },
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return cookie;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
super(input);
|
|
78
|
+
|
|
79
|
+
if (ttlMap.size) {
|
|
80
|
+
for (const [key, attrs] of ttlMap) {
|
|
81
|
+
|
|
82
|
+
if (this.#chronometry.has(key)) {
|
|
83
|
+
clearTimeout(this.#chronometry.get(key));
|
|
84
|
+
this.#chronometry.delete(key);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const { expires, maxAge } = attrs;
|
|
88
|
+
|
|
89
|
+
for (const interval of [
|
|
90
|
+
maxAge,
|
|
91
|
+
expires,
|
|
92
|
+
]) {
|
|
93
|
+
if (!Number.isInteger(interval)) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const ref = new WeakRef(this);
|
|
98
|
+
const tid = setTimeout(() => {
|
|
99
|
+
const ctx = ref.deref();
|
|
100
|
+
|
|
101
|
+
if (ctx) {
|
|
102
|
+
ctx.#chronometry.delete(key);
|
|
103
|
+
ctx.delete(key);
|
|
104
|
+
}
|
|
105
|
+
}, Math.max(interval, 0));
|
|
106
|
+
|
|
107
|
+
this.constructor.#register(this, tid);
|
|
108
|
+
this.#chronometry.set(key, tid);
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
toString() {
|
|
116
|
+
brandCheck(this, Cookies);
|
|
117
|
+
|
|
118
|
+
return super.toString().split('&').join('; ');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
}
|
package/src/errors.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export class RequestError extends Error {
|
|
2
|
-
|
|
3
|
-
get [Symbol.toStringTag]() {
|
|
4
|
-
return this.constructor.name;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
get name() {
|
|
8
|
-
return this[Symbol.toStringTag];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
constructor(...args) {
|
|
12
|
-
super(...args);
|
|
13
|
-
Error.captureStackTrace(this, this.constructor);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class TimeoutError extends RequestError {}
|
|
1
|
+
export class RequestError extends Error {
|
|
2
|
+
|
|
3
|
+
get [Symbol.toStringTag]() {
|
|
4
|
+
return this.constructor.name;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
get name() {
|
|
8
|
+
return this[Symbol.toStringTag];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
constructor(...args) {
|
|
12
|
+
super(...args);
|
|
13
|
+
Error.captureStackTrace(this, this.constructor);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class TimeoutError extends RequestError {}
|