@whatwg-node/cookie-store 0.1.0 → 0.1.1-alpha-20230616103058-439c10e
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/cjs/CookieStore.js +4 -41
- package/cjs/getCookieString.js +33 -0
- package/cjs/index.js +1 -0
- package/esm/CookieStore.js +4 -41
- package/esm/getCookieString.js +29 -0
- package/esm/index.js +1 -0
- package/package.json +1 -1
- package/typings/CookieStore.d.cts +0 -2
- package/typings/CookieStore.d.ts +0 -2
- package/typings/getCookieString.d.cts +2 -0
- package/typings/getCookieString.d.ts +2 -0
- package/typings/index.d.cts +1 -0
- package/typings/index.d.ts +1 -0
package/cjs/CookieStore.js
CHANGED
|
@@ -22,7 +22,6 @@ class CookieStore extends EventTarget {
|
|
|
22
22
|
return (await this.getAll(init))[0];
|
|
23
23
|
}
|
|
24
24
|
async set(init, possibleValue) {
|
|
25
|
-
var _a, _b, _c;
|
|
26
25
|
const item = {
|
|
27
26
|
name: '',
|
|
28
27
|
value: '',
|
|
@@ -42,13 +41,13 @@ class CookieStore extends EventTarget {
|
|
|
42
41
|
if (item.path && !item.path.startsWith('/')) {
|
|
43
42
|
throw new TypeError('Cookie path must start with "/"');
|
|
44
43
|
}
|
|
45
|
-
if (
|
|
44
|
+
if (item.domain?.startsWith('.')) {
|
|
46
45
|
throw new TypeError('Cookie domain cannot start with "."');
|
|
47
46
|
}
|
|
48
|
-
if (
|
|
47
|
+
if (item.name?.startsWith('__Host') && item.domain) {
|
|
49
48
|
throw new TypeError('Cookie domain must not be specified for host cookies');
|
|
50
49
|
}
|
|
51
|
-
if (
|
|
50
|
+
if (item.name?.startsWith('__Host') && item.path !== '/') {
|
|
52
51
|
throw new TypeError('Cookie path must not be specified for host cookies');
|
|
53
52
|
}
|
|
54
53
|
if (item.path && item.path.endsWith('/')) {
|
|
@@ -64,7 +63,7 @@ class CookieStore extends EventTarget {
|
|
|
64
63
|
if (item.name && item.name.startsWith('__Host')) {
|
|
65
64
|
item.secure = true;
|
|
66
65
|
}
|
|
67
|
-
const previousCookie = await this.get(item);
|
|
66
|
+
const previousCookie = await this.get(item.name);
|
|
68
67
|
this.cookieMap.set(item.name || '', item);
|
|
69
68
|
if (this.onchange) {
|
|
70
69
|
const changed = [];
|
|
@@ -112,41 +111,5 @@ class CookieStore extends EventTarget {
|
|
|
112
111
|
item.expires = 0;
|
|
113
112
|
await this.set(item);
|
|
114
113
|
}
|
|
115
|
-
get cookieString() {
|
|
116
|
-
const cookieStrings = [];
|
|
117
|
-
for (const [, item] of this.cookieMap) {
|
|
118
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
119
|
-
let cookieString = `${item.name}=${encodeURIComponent(item.value)}`;
|
|
120
|
-
if (item.domain) {
|
|
121
|
-
cookieString += '; Domain=' + item.domain;
|
|
122
|
-
}
|
|
123
|
-
if (item.path) {
|
|
124
|
-
cookieString += '; Path=' + item.path;
|
|
125
|
-
}
|
|
126
|
-
if (typeof item.expires === 'number') {
|
|
127
|
-
cookieString += '; Expires=' + new Date(item.expires).toUTCString();
|
|
128
|
-
}
|
|
129
|
-
if ((item.name && item.name.startsWith('__Secure')) || item.secure) {
|
|
130
|
-
item.sameSite = 'lax';
|
|
131
|
-
cookieString += '; Secure';
|
|
132
|
-
}
|
|
133
|
-
switch (item.sameSite) {
|
|
134
|
-
case 'lax':
|
|
135
|
-
cookieString += '; SameSite=Lax';
|
|
136
|
-
break;
|
|
137
|
-
case 'strict':
|
|
138
|
-
cookieString += '; SameSite=Strict';
|
|
139
|
-
break;
|
|
140
|
-
case 'none':
|
|
141
|
-
cookieString += '; SameSite=None';
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
cookieStrings.push(cookieString);
|
|
145
|
-
}
|
|
146
|
-
return cookieStrings.join('; ');
|
|
147
|
-
}
|
|
148
|
-
set cookieString(cookieString) {
|
|
149
|
-
this.cookieMap = (0, parse_js_1.parse)(cookieString);
|
|
150
|
-
}
|
|
151
114
|
}
|
|
152
115
|
exports.CookieStore = CookieStore;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCookieString = void 0;
|
|
4
|
+
function getCookieString(item) {
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
6
|
+
let cookieString = `${item.name}=${encodeURIComponent(item.value)}`;
|
|
7
|
+
if (item.domain) {
|
|
8
|
+
cookieString += '; Domain=' + item.domain;
|
|
9
|
+
}
|
|
10
|
+
if (item.path) {
|
|
11
|
+
cookieString += '; Path=' + item.path;
|
|
12
|
+
}
|
|
13
|
+
if (typeof item.expires === 'number') {
|
|
14
|
+
cookieString += '; Expires=' + new Date(item.expires).toUTCString();
|
|
15
|
+
}
|
|
16
|
+
if ((item.name && item.name.startsWith('__Secure')) || item.secure) {
|
|
17
|
+
item.sameSite = 'lax';
|
|
18
|
+
cookieString += '; Secure';
|
|
19
|
+
}
|
|
20
|
+
switch (item.sameSite) {
|
|
21
|
+
case 'lax':
|
|
22
|
+
cookieString += '; SameSite=Lax';
|
|
23
|
+
break;
|
|
24
|
+
case 'strict':
|
|
25
|
+
cookieString += '; SameSite=Strict';
|
|
26
|
+
break;
|
|
27
|
+
case 'none':
|
|
28
|
+
cookieString += '; SameSite=None';
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
return cookieString;
|
|
32
|
+
}
|
|
33
|
+
exports.getCookieString = getCookieString;
|
package/cjs/index.js
CHANGED
|
@@ -5,3 +5,4 @@ tslib_1.__exportStar(require("./CookieChangeEvent.js"), exports);
|
|
|
5
5
|
tslib_1.__exportStar(require("./CookieStore.js"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./parse.js"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./types.js"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./getCookieString.js"), exports);
|
package/esm/CookieStore.js
CHANGED
|
@@ -19,7 +19,6 @@ export class CookieStore extends EventTarget {
|
|
|
19
19
|
return (await this.getAll(init))[0];
|
|
20
20
|
}
|
|
21
21
|
async set(init, possibleValue) {
|
|
22
|
-
var _a, _b, _c;
|
|
23
22
|
const item = {
|
|
24
23
|
name: '',
|
|
25
24
|
value: '',
|
|
@@ -39,13 +38,13 @@ export class CookieStore extends EventTarget {
|
|
|
39
38
|
if (item.path && !item.path.startsWith('/')) {
|
|
40
39
|
throw new TypeError('Cookie path must start with "/"');
|
|
41
40
|
}
|
|
42
|
-
if (
|
|
41
|
+
if (item.domain?.startsWith('.')) {
|
|
43
42
|
throw new TypeError('Cookie domain cannot start with "."');
|
|
44
43
|
}
|
|
45
|
-
if (
|
|
44
|
+
if (item.name?.startsWith('__Host') && item.domain) {
|
|
46
45
|
throw new TypeError('Cookie domain must not be specified for host cookies');
|
|
47
46
|
}
|
|
48
|
-
if (
|
|
47
|
+
if (item.name?.startsWith('__Host') && item.path !== '/') {
|
|
49
48
|
throw new TypeError('Cookie path must not be specified for host cookies');
|
|
50
49
|
}
|
|
51
50
|
if (item.path && item.path.endsWith('/')) {
|
|
@@ -61,7 +60,7 @@ export class CookieStore extends EventTarget {
|
|
|
61
60
|
if (item.name && item.name.startsWith('__Host')) {
|
|
62
61
|
item.secure = true;
|
|
63
62
|
}
|
|
64
|
-
const previousCookie = await this.get(item);
|
|
63
|
+
const previousCookie = await this.get(item.name);
|
|
65
64
|
this.cookieMap.set(item.name || '', item);
|
|
66
65
|
if (this.onchange) {
|
|
67
66
|
const changed = [];
|
|
@@ -109,40 +108,4 @@ export class CookieStore extends EventTarget {
|
|
|
109
108
|
item.expires = 0;
|
|
110
109
|
await this.set(item);
|
|
111
110
|
}
|
|
112
|
-
get cookieString() {
|
|
113
|
-
const cookieStrings = [];
|
|
114
|
-
for (const [, item] of this.cookieMap) {
|
|
115
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
116
|
-
let cookieString = `${item.name}=${encodeURIComponent(item.value)}`;
|
|
117
|
-
if (item.domain) {
|
|
118
|
-
cookieString += '; Domain=' + item.domain;
|
|
119
|
-
}
|
|
120
|
-
if (item.path) {
|
|
121
|
-
cookieString += '; Path=' + item.path;
|
|
122
|
-
}
|
|
123
|
-
if (typeof item.expires === 'number') {
|
|
124
|
-
cookieString += '; Expires=' + new Date(item.expires).toUTCString();
|
|
125
|
-
}
|
|
126
|
-
if ((item.name && item.name.startsWith('__Secure')) || item.secure) {
|
|
127
|
-
item.sameSite = 'lax';
|
|
128
|
-
cookieString += '; Secure';
|
|
129
|
-
}
|
|
130
|
-
switch (item.sameSite) {
|
|
131
|
-
case 'lax':
|
|
132
|
-
cookieString += '; SameSite=Lax';
|
|
133
|
-
break;
|
|
134
|
-
case 'strict':
|
|
135
|
-
cookieString += '; SameSite=Strict';
|
|
136
|
-
break;
|
|
137
|
-
case 'none':
|
|
138
|
-
cookieString += '; SameSite=None';
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
cookieStrings.push(cookieString);
|
|
142
|
-
}
|
|
143
|
-
return cookieStrings.join('; ');
|
|
144
|
-
}
|
|
145
|
-
set cookieString(cookieString) {
|
|
146
|
-
this.cookieMap = parse(cookieString);
|
|
147
|
-
}
|
|
148
111
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function getCookieString(item) {
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
3
|
+
let cookieString = `${item.name}=${encodeURIComponent(item.value)}`;
|
|
4
|
+
if (item.domain) {
|
|
5
|
+
cookieString += '; Domain=' + item.domain;
|
|
6
|
+
}
|
|
7
|
+
if (item.path) {
|
|
8
|
+
cookieString += '; Path=' + item.path;
|
|
9
|
+
}
|
|
10
|
+
if (typeof item.expires === 'number') {
|
|
11
|
+
cookieString += '; Expires=' + new Date(item.expires).toUTCString();
|
|
12
|
+
}
|
|
13
|
+
if ((item.name && item.name.startsWith('__Secure')) || item.secure) {
|
|
14
|
+
item.sameSite = 'lax';
|
|
15
|
+
cookieString += '; Secure';
|
|
16
|
+
}
|
|
17
|
+
switch (item.sameSite) {
|
|
18
|
+
case 'lax':
|
|
19
|
+
cookieString += '; SameSite=Lax';
|
|
20
|
+
break;
|
|
21
|
+
case 'strict':
|
|
22
|
+
cookieString += '; SameSite=Strict';
|
|
23
|
+
break;
|
|
24
|
+
case 'none':
|
|
25
|
+
cookieString += '; SameSite=None';
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
return cookieString;
|
|
29
|
+
}
|
package/esm/index.js
CHANGED
package/package.json
CHANGED
|
@@ -9,6 +9,4 @@ export declare class CookieStore extends EventTarget {
|
|
|
9
9
|
set(init: CookieListItem | string, possibleValue?: string): Promise<void>;
|
|
10
10
|
getAll(init?: CookieStoreGetOptions['name'] | CookieStoreGetOptions): Promise<Cookie[]>;
|
|
11
11
|
delete(init: CookieStoreDeleteOptions['name'] | CookieStoreDeleteOptions): Promise<void>;
|
|
12
|
-
get cookieString(): string;
|
|
13
|
-
set cookieString(cookieString: string);
|
|
14
12
|
}
|
package/typings/CookieStore.d.ts
CHANGED
|
@@ -9,6 +9,4 @@ export declare class CookieStore extends EventTarget {
|
|
|
9
9
|
set(init: CookieListItem | string, possibleValue?: string): Promise<void>;
|
|
10
10
|
getAll(init?: CookieStoreGetOptions['name'] | CookieStoreGetOptions): Promise<Cookie[]>;
|
|
11
11
|
delete(init: CookieStoreDeleteOptions['name'] | CookieStoreDeleteOptions): Promise<void>;
|
|
12
|
-
get cookieString(): string;
|
|
13
|
-
set cookieString(cookieString: string);
|
|
14
12
|
}
|
package/typings/index.d.cts
CHANGED
package/typings/index.d.ts
CHANGED