@whatwg-node/cookie-store 0.3.0-rc-20230710180432-33f220b → 0.3.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/cjs/CookieChangeEvent.js +2 -0
- package/cjs/CookieStore.js +10 -9
- package/cjs/getCookieString.js +2 -4
- package/cjs/parse.js +3 -4
- package/esm/CookieChangeEvent.js +2 -0
- package/esm/CookieStore.js +10 -9
- package/esm/getCookieString.js +1 -2
- package/esm/parse.js +2 -2
- package/package.json +4 -3
- package/typings/CookieStore.d.cts +1 -1
- package/typings/CookieStore.d.ts +1 -1
- package/typings/getCookieString.d.cts +1 -1
- package/typings/getCookieString.d.ts +1 -1
- package/typings/types.d.cts +7 -7
- package/typings/types.d.ts +7 -7
package/cjs/CookieChangeEvent.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CookieChangeEvent = void 0;
|
|
4
4
|
class CookieChangeEvent extends Event {
|
|
5
|
+
changed;
|
|
6
|
+
deleted;
|
|
5
7
|
constructor(type, eventInitDict = { changed: [], deleted: [] }) {
|
|
6
8
|
super(type, eventInitDict);
|
|
7
9
|
this.changed = eventInitDict.changed || [];
|
package/cjs/CookieStore.js
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CookieStore = void 0;
|
|
4
|
+
const promise_helpers_1 = require("@whatwg-node/promise-helpers");
|
|
4
5
|
const CookieChangeEvent_js_1 = require("./CookieChangeEvent.js");
|
|
5
6
|
const parse_js_1 = require("./parse.js");
|
|
6
7
|
class CookieStore extends EventTarget {
|
|
8
|
+
onchange;
|
|
9
|
+
cookieMap = new Map();
|
|
7
10
|
get [Symbol.toStringTag]() {
|
|
8
11
|
return 'CookieStore';
|
|
9
12
|
}
|
|
10
13
|
constructor(cookieString) {
|
|
11
14
|
super();
|
|
12
|
-
this.cookieMap = new Map();
|
|
13
15
|
this.cookieMap = (0, parse_js_1.parse)(cookieString);
|
|
14
16
|
}
|
|
15
|
-
|
|
17
|
+
get(init) {
|
|
16
18
|
if (init == null) {
|
|
17
19
|
throw new TypeError('CookieStoreGetOptions must not be empty');
|
|
18
20
|
}
|
|
19
21
|
else if (init instanceof Object && !Object.keys(init).length) {
|
|
20
22
|
throw new TypeError('CookieStoreGetOptions must not be empty');
|
|
21
23
|
}
|
|
22
|
-
return
|
|
24
|
+
return this.getAll(init).then(cookies => cookies[0]);
|
|
23
25
|
}
|
|
24
26
|
async set(init, possibleValue) {
|
|
25
27
|
const item = {
|
|
@@ -34,7 +36,6 @@ class CookieStore extends EventTarget {
|
|
|
34
36
|
};
|
|
35
37
|
if (typeof init === 'string') {
|
|
36
38
|
item.name = init;
|
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
38
39
|
item.value = possibleValue;
|
|
39
40
|
}
|
|
40
41
|
else {
|
|
@@ -79,10 +80,10 @@ class CookieStore extends EventTarget {
|
|
|
79
80
|
this.onchange(event);
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
|
-
|
|
83
|
+
getAll(init) {
|
|
83
84
|
const cookies = Array.from(this.cookieMap.values());
|
|
84
85
|
if (init == null || Object.keys(init).length === 0) {
|
|
85
|
-
return cookies;
|
|
86
|
+
return (0, promise_helpers_1.fakePromise)(cookies);
|
|
86
87
|
}
|
|
87
88
|
let name;
|
|
88
89
|
if (typeof init === 'string') {
|
|
@@ -91,9 +92,9 @@ class CookieStore extends EventTarget {
|
|
|
91
92
|
else {
|
|
92
93
|
name = init.name;
|
|
93
94
|
}
|
|
94
|
-
return cookies.filter(cookie => cookie.name === name);
|
|
95
|
+
return (0, promise_helpers_1.fakePromise)(cookies.filter(cookie => cookie.name === name));
|
|
95
96
|
}
|
|
96
|
-
|
|
97
|
+
delete(init) {
|
|
97
98
|
const item = {
|
|
98
99
|
name: '',
|
|
99
100
|
value: '',
|
|
@@ -111,7 +112,7 @@ class CookieStore extends EventTarget {
|
|
|
111
112
|
Object.assign(item, init);
|
|
112
113
|
}
|
|
113
114
|
item.expires = 0;
|
|
114
|
-
|
|
115
|
+
return this.set(item);
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
118
|
exports.CookieStore = CookieStore;
|
package/cjs/getCookieString.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCookieString =
|
|
3
|
+
exports.getCookieString = getCookieString;
|
|
4
4
|
function getCookieString(item) {
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
6
5
|
let cookieString = `${item.name}=${encodeURIComponent(item.value)}`;
|
|
7
6
|
if (item.domain) {
|
|
8
7
|
cookieString += '; Domain=' + item.domain;
|
|
@@ -17,7 +16,7 @@ function getCookieString(item) {
|
|
|
17
16
|
cookieString += '; Expires=' + item.expires.toUTCString();
|
|
18
17
|
}
|
|
19
18
|
if ((item.name && item.name.startsWith('__Secure')) || item.secure) {
|
|
20
|
-
item.sameSite = 'lax';
|
|
19
|
+
item.sameSite = item.sameSite || 'lax';
|
|
21
20
|
cookieString += '; Secure';
|
|
22
21
|
}
|
|
23
22
|
switch (item.sameSite) {
|
|
@@ -36,4 +35,3 @@ function getCookieString(item) {
|
|
|
36
35
|
}
|
|
37
36
|
return cookieString;
|
|
38
37
|
}
|
|
39
|
-
exports.getCookieString = getCookieString;
|
package/cjs/parse.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parse =
|
|
3
|
+
exports.parse = parse;
|
|
4
4
|
const decode = decodeURIComponent;
|
|
5
5
|
const pairSplitRegExp = /; */;
|
|
6
6
|
// Try decoding a string using a decoding function.
|
|
@@ -28,13 +28,13 @@ function parse(str, options = {}) {
|
|
|
28
28
|
const dec = opt.decode || decode;
|
|
29
29
|
for (let i = 0; i < pairs.length; i++) {
|
|
30
30
|
const pair = pairs[i];
|
|
31
|
-
|
|
31
|
+
const eqIdx = pair.indexOf('=');
|
|
32
32
|
// skip things that don't look like key=value
|
|
33
33
|
if (eqIdx < 0) {
|
|
34
34
|
continue;
|
|
35
35
|
}
|
|
36
36
|
const key = pair.substr(0, eqIdx).trim();
|
|
37
|
-
let val = pair.substr(
|
|
37
|
+
let val = pair.substr(eqIdx + 1, pair.length).trim();
|
|
38
38
|
// quoted values
|
|
39
39
|
if (val[0] === '"') {
|
|
40
40
|
val = val.slice(1, -1);
|
|
@@ -46,4 +46,3 @@ function parse(str, options = {}) {
|
|
|
46
46
|
}
|
|
47
47
|
return map;
|
|
48
48
|
}
|
|
49
|
-
exports.parse = parse;
|
package/esm/CookieChangeEvent.js
CHANGED
package/esm/CookieStore.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
|
+
import { fakePromise } from '@whatwg-node/promise-helpers';
|
|
1
2
|
import { CookieChangeEvent } from './CookieChangeEvent.js';
|
|
2
3
|
import { parse } from './parse.js';
|
|
3
4
|
export class CookieStore extends EventTarget {
|
|
5
|
+
onchange;
|
|
6
|
+
cookieMap = new Map();
|
|
4
7
|
get [Symbol.toStringTag]() {
|
|
5
8
|
return 'CookieStore';
|
|
6
9
|
}
|
|
7
10
|
constructor(cookieString) {
|
|
8
11
|
super();
|
|
9
|
-
this.cookieMap = new Map();
|
|
10
12
|
this.cookieMap = parse(cookieString);
|
|
11
13
|
}
|
|
12
|
-
|
|
14
|
+
get(init) {
|
|
13
15
|
if (init == null) {
|
|
14
16
|
throw new TypeError('CookieStoreGetOptions must not be empty');
|
|
15
17
|
}
|
|
16
18
|
else if (init instanceof Object && !Object.keys(init).length) {
|
|
17
19
|
throw new TypeError('CookieStoreGetOptions must not be empty');
|
|
18
20
|
}
|
|
19
|
-
return
|
|
21
|
+
return this.getAll(init).then(cookies => cookies[0]);
|
|
20
22
|
}
|
|
21
23
|
async set(init, possibleValue) {
|
|
22
24
|
const item = {
|
|
@@ -31,7 +33,6 @@ export class CookieStore extends EventTarget {
|
|
|
31
33
|
};
|
|
32
34
|
if (typeof init === 'string') {
|
|
33
35
|
item.name = init;
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
35
36
|
item.value = possibleValue;
|
|
36
37
|
}
|
|
37
38
|
else {
|
|
@@ -76,10 +77,10 @@ export class CookieStore extends EventTarget {
|
|
|
76
77
|
this.onchange(event);
|
|
77
78
|
}
|
|
78
79
|
}
|
|
79
|
-
|
|
80
|
+
getAll(init) {
|
|
80
81
|
const cookies = Array.from(this.cookieMap.values());
|
|
81
82
|
if (init == null || Object.keys(init).length === 0) {
|
|
82
|
-
return cookies;
|
|
83
|
+
return fakePromise(cookies);
|
|
83
84
|
}
|
|
84
85
|
let name;
|
|
85
86
|
if (typeof init === 'string') {
|
|
@@ -88,9 +89,9 @@ export class CookieStore extends EventTarget {
|
|
|
88
89
|
else {
|
|
89
90
|
name = init.name;
|
|
90
91
|
}
|
|
91
|
-
return cookies.filter(cookie => cookie.name === name);
|
|
92
|
+
return fakePromise(cookies.filter(cookie => cookie.name === name));
|
|
92
93
|
}
|
|
93
|
-
|
|
94
|
+
delete(init) {
|
|
94
95
|
const item = {
|
|
95
96
|
name: '',
|
|
96
97
|
value: '',
|
|
@@ -108,6 +109,6 @@ export class CookieStore extends EventTarget {
|
|
|
108
109
|
Object.assign(item, init);
|
|
109
110
|
}
|
|
110
111
|
item.expires = 0;
|
|
111
|
-
|
|
112
|
+
return this.set(item);
|
|
112
113
|
}
|
|
113
114
|
}
|
package/esm/getCookieString.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export function getCookieString(item) {
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
3
2
|
let cookieString = `${item.name}=${encodeURIComponent(item.value)}`;
|
|
4
3
|
if (item.domain) {
|
|
5
4
|
cookieString += '; Domain=' + item.domain;
|
|
@@ -14,7 +13,7 @@ export function getCookieString(item) {
|
|
|
14
13
|
cookieString += '; Expires=' + item.expires.toUTCString();
|
|
15
14
|
}
|
|
16
15
|
if ((item.name && item.name.startsWith('__Secure')) || item.secure) {
|
|
17
|
-
item.sameSite = 'lax';
|
|
16
|
+
item.sameSite = item.sameSite || 'lax';
|
|
18
17
|
cookieString += '; Secure';
|
|
19
18
|
}
|
|
20
19
|
switch (item.sameSite) {
|
package/esm/parse.js
CHANGED
|
@@ -25,13 +25,13 @@ export function parse(str, options = {}) {
|
|
|
25
25
|
const dec = opt.decode || decode;
|
|
26
26
|
for (let i = 0; i < pairs.length; i++) {
|
|
27
27
|
const pair = pairs[i];
|
|
28
|
-
|
|
28
|
+
const eqIdx = pair.indexOf('=');
|
|
29
29
|
// skip things that don't look like key=value
|
|
30
30
|
if (eqIdx < 0) {
|
|
31
31
|
continue;
|
|
32
32
|
}
|
|
33
33
|
const key = pair.substr(0, eqIdx).trim();
|
|
34
|
-
let val = pair.substr(
|
|
34
|
+
let val = pair.substr(eqIdx + 1, pair.length).trim();
|
|
35
35
|
// quoted values
|
|
36
36
|
if (val[0] === '"') {
|
|
37
37
|
val = val.slice(1, -1);
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@whatwg-node/cookie-store",
|
|
3
|
-
"version": "0.3.0
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Cookie Store",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"
|
|
7
|
+
"@whatwg-node/promise-helpers": "^2.0.0",
|
|
8
|
+
"tslib": "^2.6.3"
|
|
8
9
|
},
|
|
9
10
|
"repository": {
|
|
10
11
|
"type": "git",
|
|
@@ -14,7 +15,7 @@
|
|
|
14
15
|
"author": "Arda TANRIKULU <ardatanrikulu@gmail.com>",
|
|
15
16
|
"license": "MIT",
|
|
16
17
|
"engines": {
|
|
17
|
-
"node": ">=
|
|
18
|
+
"node": ">=22.15.0"
|
|
18
19
|
},
|
|
19
20
|
"main": "cjs/index.js",
|
|
20
21
|
"module": "esm/index.js",
|
|
@@ -5,7 +5,7 @@ export declare class CookieStore extends EventTarget {
|
|
|
5
5
|
private cookieMap;
|
|
6
6
|
get [Symbol.toStringTag](): 'CookieStore';
|
|
7
7
|
constructor(cookieString: string);
|
|
8
|
-
get(init?: CookieStoreGetOptions['name'] | CookieStoreGetOptions): Promise<Cookie | undefined>;
|
|
8
|
+
get(init?: CookieStoreGetOptions['name'] | CookieStoreGetOptions | undefined): Promise<Cookie | undefined>;
|
|
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>;
|
package/typings/CookieStore.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare class CookieStore extends EventTarget {
|
|
|
5
5
|
private cookieMap;
|
|
6
6
|
get [Symbol.toStringTag](): 'CookieStore';
|
|
7
7
|
constructor(cookieString: string);
|
|
8
|
-
get(init?: CookieStoreGetOptions['name'] | CookieStoreGetOptions): Promise<Cookie | undefined>;
|
|
8
|
+
get(init?: CookieStoreGetOptions['name'] | CookieStoreGetOptions | undefined): Promise<Cookie | undefined>;
|
|
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>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Cookie, CookieListItem } from './types';
|
|
1
|
+
import type { Cookie, CookieListItem } from './types.cjs';
|
|
2
2
|
export declare function getCookieString(item: CookieListItem | Cookie): string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Cookie, CookieListItem } from './types';
|
|
1
|
+
import type { Cookie, CookieListItem } from './types.js';
|
|
2
2
|
export declare function getCookieString(item: CookieListItem | Cookie): string;
|
package/typings/types.d.cts
CHANGED
|
@@ -14,19 +14,19 @@ export interface CookieStoreDeleteOptions {
|
|
|
14
14
|
path?: string;
|
|
15
15
|
}
|
|
16
16
|
export interface CookieStoreGetOptions {
|
|
17
|
-
name?: string;
|
|
17
|
+
name?: string | undefined;
|
|
18
18
|
url?: string;
|
|
19
19
|
}
|
|
20
20
|
export type CookieSameSite = 'strict' | 'lax' | 'none';
|
|
21
21
|
export interface CookieListItem {
|
|
22
|
-
name?: string;
|
|
23
|
-
value?: string;
|
|
22
|
+
name?: string | undefined;
|
|
23
|
+
value?: string | undefined;
|
|
24
24
|
domain: string | null;
|
|
25
|
-
path?: string;
|
|
25
|
+
path?: string | undefined;
|
|
26
26
|
expires: Date | number | null;
|
|
27
|
-
secure?: boolean;
|
|
28
|
-
sameSite?: CookieSameSite;
|
|
29
|
-
httpOnly?: boolean;
|
|
27
|
+
secure?: boolean | undefined;
|
|
28
|
+
sameSite?: CookieSameSite | undefined;
|
|
29
|
+
httpOnly?: boolean | undefined;
|
|
30
30
|
}
|
|
31
31
|
export type CookieList = CookieListItem[];
|
|
32
32
|
export interface CookieChangeEventInit extends EventInit {
|
package/typings/types.d.ts
CHANGED
|
@@ -14,19 +14,19 @@ export interface CookieStoreDeleteOptions {
|
|
|
14
14
|
path?: string;
|
|
15
15
|
}
|
|
16
16
|
export interface CookieStoreGetOptions {
|
|
17
|
-
name?: string;
|
|
17
|
+
name?: string | undefined;
|
|
18
18
|
url?: string;
|
|
19
19
|
}
|
|
20
20
|
export type CookieSameSite = 'strict' | 'lax' | 'none';
|
|
21
21
|
export interface CookieListItem {
|
|
22
|
-
name?: string;
|
|
23
|
-
value?: string;
|
|
22
|
+
name?: string | undefined;
|
|
23
|
+
value?: string | undefined;
|
|
24
24
|
domain: string | null;
|
|
25
|
-
path?: string;
|
|
25
|
+
path?: string | undefined;
|
|
26
26
|
expires: Date | number | null;
|
|
27
|
-
secure?: boolean;
|
|
28
|
-
sameSite?: CookieSameSite;
|
|
29
|
-
httpOnly?: boolean;
|
|
27
|
+
secure?: boolean | undefined;
|
|
28
|
+
sameSite?: CookieSameSite | undefined;
|
|
29
|
+
httpOnly?: boolean | undefined;
|
|
30
30
|
}
|
|
31
31
|
export type CookieList = CookieListItem[];
|
|
32
32
|
export interface CookieChangeEventInit extends EventInit {
|