@whatwg-node/cookie-store 0.0.1-alpha-20230425095535-e20a748
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 +12 -0
- package/cjs/CookieStore.js +150 -0
- package/cjs/index.js +7 -0
- package/cjs/package.json +1 -0
- package/cjs/parse.js +49 -0
- package/cjs/types.js +0 -0
- package/esm/CookieChangeEvent.js +8 -0
- package/esm/CookieStore.js +146 -0
- package/esm/index.js +4 -0
- package/esm/parse.js +45 -0
- package/esm/types.js +0 -0
- package/package.json +41 -0
- package/typings/CookieChangeEvent.d.cts +7 -0
- package/typings/CookieChangeEvent.d.ts +7 -0
- package/typings/CookieStore.d.cts +14 -0
- package/typings/CookieStore.d.ts +14 -0
- package/typings/index.d.cts +4 -0
- package/typings/index.d.ts +4 -0
- package/typings/parse.d.cts +11 -0
- package/typings/parse.d.ts +11 -0
- package/typings/types.d.cts +33 -0
- package/typings/types.d.ts +33 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CookieChangeEvent = void 0;
|
|
4
|
+
const events_1 = require("@whatwg-node/events");
|
|
5
|
+
class CookieChangeEvent extends events_1.Event {
|
|
6
|
+
constructor(type, eventInitDict = { changed: [], deleted: [] }) {
|
|
7
|
+
super(type, eventInitDict);
|
|
8
|
+
this.changed = eventInitDict.changed || [];
|
|
9
|
+
this.deleted = eventInitDict.deleted || [];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.CookieChangeEvent = CookieChangeEvent;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CookieStore = void 0;
|
|
4
|
+
const events_1 = require("@whatwg-node/events");
|
|
5
|
+
const CookieChangeEvent_js_1 = require("./CookieChangeEvent.js");
|
|
6
|
+
const parse_js_1 = require("./parse.js");
|
|
7
|
+
class CookieStore extends events_1.EventTarget {
|
|
8
|
+
get [Symbol.toStringTag]() {
|
|
9
|
+
return 'CookieStore';
|
|
10
|
+
}
|
|
11
|
+
constructor(cookieString) {
|
|
12
|
+
super();
|
|
13
|
+
this.cookieMap = new Map();
|
|
14
|
+
this.cookieMap = (0, parse_js_1.parse)(cookieString);
|
|
15
|
+
}
|
|
16
|
+
async get(init) {
|
|
17
|
+
if (init == null) {
|
|
18
|
+
throw new TypeError('CookieStoreGetOptions must not be empty');
|
|
19
|
+
}
|
|
20
|
+
else if (init instanceof Object && !Object.keys(init).length) {
|
|
21
|
+
throw new TypeError('CookieStoreGetOptions must not be empty');
|
|
22
|
+
}
|
|
23
|
+
return (await this.getAll(init))[0];
|
|
24
|
+
}
|
|
25
|
+
async set(init, possibleValue) {
|
|
26
|
+
var _a, _b, _c;
|
|
27
|
+
const item = {
|
|
28
|
+
name: '',
|
|
29
|
+
value: '',
|
|
30
|
+
path: '/',
|
|
31
|
+
secure: false,
|
|
32
|
+
sameSite: 'strict',
|
|
33
|
+
expires: null,
|
|
34
|
+
domain: null,
|
|
35
|
+
};
|
|
36
|
+
if (typeof init === 'string') {
|
|
37
|
+
item.name = init;
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
39
|
+
item.value = possibleValue;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
Object.assign(item, init);
|
|
43
|
+
if (item.path && !item.path.startsWith('/')) {
|
|
44
|
+
throw new TypeError('Cookie path must start with "/"');
|
|
45
|
+
}
|
|
46
|
+
if ((_a = item.domain) === null || _a === void 0 ? void 0 : _a.startsWith('.')) {
|
|
47
|
+
throw new TypeError('Cookie domain cannot start with "."');
|
|
48
|
+
}
|
|
49
|
+
if (((_b = item.name) === null || _b === void 0 ? void 0 : _b.startsWith('__Host')) && item.domain) {
|
|
50
|
+
throw new TypeError('Cookie domain must not be specified for host cookies');
|
|
51
|
+
}
|
|
52
|
+
if (((_c = item.name) === null || _c === void 0 ? void 0 : _c.startsWith('__Host')) && item.path !== '/') {
|
|
53
|
+
throw new TypeError('Cookie path must not be specified for host cookies');
|
|
54
|
+
}
|
|
55
|
+
if (item.path && item.path.endsWith('/')) {
|
|
56
|
+
item.path = item.path.slice(0, -1);
|
|
57
|
+
}
|
|
58
|
+
if (item.path === '') {
|
|
59
|
+
item.path = '/';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (item.name === '' && item.value && item.value.includes('=')) {
|
|
63
|
+
throw new TypeError("Cookie value cannot contain '=' if the name is empty");
|
|
64
|
+
}
|
|
65
|
+
if (item.name && item.name.startsWith('__Host')) {
|
|
66
|
+
item.secure = true;
|
|
67
|
+
}
|
|
68
|
+
const previousCookie = await this.get(item);
|
|
69
|
+
this.cookieMap.set(item.name || '', item);
|
|
70
|
+
if (this.onchange) {
|
|
71
|
+
const changed = [];
|
|
72
|
+
const deleted = [];
|
|
73
|
+
if (previousCookie && !(await this.get(item))) {
|
|
74
|
+
deleted.push({ ...item, value: undefined });
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
changed.push(item);
|
|
78
|
+
}
|
|
79
|
+
const event = new CookieChangeEvent_js_1.CookieChangeEvent('change', { changed, deleted });
|
|
80
|
+
this.onchange(event);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async getAll(init) {
|
|
84
|
+
const cookies = Array.from(this.cookieMap.values());
|
|
85
|
+
if (init == null || Object.keys(init).length === 0) {
|
|
86
|
+
return cookies;
|
|
87
|
+
}
|
|
88
|
+
let name;
|
|
89
|
+
if (typeof init === 'string') {
|
|
90
|
+
name = init;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
name = init.name;
|
|
94
|
+
}
|
|
95
|
+
return cookies.filter(cookie => cookie.name === name);
|
|
96
|
+
}
|
|
97
|
+
async delete(init) {
|
|
98
|
+
const item = {
|
|
99
|
+
name: '',
|
|
100
|
+
value: '',
|
|
101
|
+
path: '/',
|
|
102
|
+
secure: false,
|
|
103
|
+
sameSite: 'strict',
|
|
104
|
+
expires: null,
|
|
105
|
+
domain: null,
|
|
106
|
+
};
|
|
107
|
+
if (typeof init === 'string') {
|
|
108
|
+
item.name = init;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
Object.assign(item, init);
|
|
112
|
+
}
|
|
113
|
+
item.expires = 0;
|
|
114
|
+
await this.set(item);
|
|
115
|
+
}
|
|
116
|
+
get cookieString() {
|
|
117
|
+
const cookieStrings = [];
|
|
118
|
+
for (const [, item] of this.cookieMap) {
|
|
119
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
120
|
+
let cookieString = `${item.name}=${encodeURIComponent(item.value)}`;
|
|
121
|
+
if (item.domain) {
|
|
122
|
+
cookieString += '; Domain=' + item.domain;
|
|
123
|
+
}
|
|
124
|
+
if (item.path) {
|
|
125
|
+
cookieString += '; Path=' + item.path;
|
|
126
|
+
}
|
|
127
|
+
if (typeof item.expires === 'number') {
|
|
128
|
+
cookieString += '; Expires=' + new Date(item.expires).toUTCString();
|
|
129
|
+
}
|
|
130
|
+
if ((item.name && item.name.startsWith('__Secure')) || item.secure) {
|
|
131
|
+
item.sameSite = 'lax';
|
|
132
|
+
cookieString += '; Secure';
|
|
133
|
+
}
|
|
134
|
+
switch (item.sameSite) {
|
|
135
|
+
case 'lax':
|
|
136
|
+
cookieString += '; SameSite=Lax';
|
|
137
|
+
break;
|
|
138
|
+
case 'strict':
|
|
139
|
+
cookieString += '; SameSite=Strict';
|
|
140
|
+
break;
|
|
141
|
+
case 'none':
|
|
142
|
+
cookieString += '; SameSite=None';
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
cookieStrings.push(cookieString);
|
|
146
|
+
}
|
|
147
|
+
return cookieStrings.join('; ');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.CookieStore = CookieStore;
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./CookieChangeEvent.js"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./CookieStore.js"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./parse.js"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./types.js"), exports);
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
package/cjs/parse.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parse = void 0;
|
|
4
|
+
const decode = decodeURIComponent;
|
|
5
|
+
const pairSplitRegExp = /; */;
|
|
6
|
+
// Try decoding a string using a decoding function.
|
|
7
|
+
function tryDecode(str, decode) {
|
|
8
|
+
try {
|
|
9
|
+
return typeof decode === 'boolean' ? decodeURIComponent(str) : decode(str);
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
return str;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Parse a cookie header.
|
|
17
|
+
*
|
|
18
|
+
* Parse the given cookie header string into an object
|
|
19
|
+
* The object has the various cookies as keys(names) => values
|
|
20
|
+
*/
|
|
21
|
+
function parse(str, options = {}) {
|
|
22
|
+
if (typeof str !== 'string') {
|
|
23
|
+
throw new TypeError('argument str must be a string');
|
|
24
|
+
}
|
|
25
|
+
const map = new Map();
|
|
26
|
+
const opt = options || {};
|
|
27
|
+
const pairs = str.split(pairSplitRegExp);
|
|
28
|
+
const dec = opt.decode || decode;
|
|
29
|
+
for (let i = 0; i < pairs.length; i++) {
|
|
30
|
+
const pair = pairs[i];
|
|
31
|
+
let eqIdx = pair.indexOf('=');
|
|
32
|
+
// skip things that don't look like key=value
|
|
33
|
+
if (eqIdx < 0) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const key = pair.substr(0, eqIdx).trim();
|
|
37
|
+
let val = pair.substr(++eqIdx, pair.length).trim();
|
|
38
|
+
// quoted values
|
|
39
|
+
if (val[0] === '"') {
|
|
40
|
+
val = val.slice(1, -1);
|
|
41
|
+
}
|
|
42
|
+
const cookiesPerKey = map.get(key);
|
|
43
|
+
if (!cookiesPerKey) {
|
|
44
|
+
map.set(key, { name: key, value: tryDecode(val, dec) });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return map;
|
|
48
|
+
}
|
|
49
|
+
exports.parse = parse;
|
package/cjs/types.js
ADDED
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Event } from '@whatwg-node/events';
|
|
2
|
+
export class CookieChangeEvent extends Event {
|
|
3
|
+
constructor(type, eventInitDict = { changed: [], deleted: [] }) {
|
|
4
|
+
super(type, eventInitDict);
|
|
5
|
+
this.changed = eventInitDict.changed || [];
|
|
6
|
+
this.deleted = eventInitDict.deleted || [];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { EventTarget } from '@whatwg-node/events';
|
|
2
|
+
import { CookieChangeEvent } from './CookieChangeEvent.js';
|
|
3
|
+
import { parse } from './parse.js';
|
|
4
|
+
export class CookieStore extends EventTarget {
|
|
5
|
+
get [Symbol.toStringTag]() {
|
|
6
|
+
return 'CookieStore';
|
|
7
|
+
}
|
|
8
|
+
constructor(cookieString) {
|
|
9
|
+
super();
|
|
10
|
+
this.cookieMap = new Map();
|
|
11
|
+
this.cookieMap = parse(cookieString);
|
|
12
|
+
}
|
|
13
|
+
async get(init) {
|
|
14
|
+
if (init == null) {
|
|
15
|
+
throw new TypeError('CookieStoreGetOptions must not be empty');
|
|
16
|
+
}
|
|
17
|
+
else if (init instanceof Object && !Object.keys(init).length) {
|
|
18
|
+
throw new TypeError('CookieStoreGetOptions must not be empty');
|
|
19
|
+
}
|
|
20
|
+
return (await this.getAll(init))[0];
|
|
21
|
+
}
|
|
22
|
+
async set(init, possibleValue) {
|
|
23
|
+
var _a, _b, _c;
|
|
24
|
+
const item = {
|
|
25
|
+
name: '',
|
|
26
|
+
value: '',
|
|
27
|
+
path: '/',
|
|
28
|
+
secure: false,
|
|
29
|
+
sameSite: 'strict',
|
|
30
|
+
expires: null,
|
|
31
|
+
domain: null,
|
|
32
|
+
};
|
|
33
|
+
if (typeof init === 'string') {
|
|
34
|
+
item.name = init;
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
36
|
+
item.value = possibleValue;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
Object.assign(item, init);
|
|
40
|
+
if (item.path && !item.path.startsWith('/')) {
|
|
41
|
+
throw new TypeError('Cookie path must start with "/"');
|
|
42
|
+
}
|
|
43
|
+
if ((_a = item.domain) === null || _a === void 0 ? void 0 : _a.startsWith('.')) {
|
|
44
|
+
throw new TypeError('Cookie domain cannot start with "."');
|
|
45
|
+
}
|
|
46
|
+
if (((_b = item.name) === null || _b === void 0 ? void 0 : _b.startsWith('__Host')) && item.domain) {
|
|
47
|
+
throw new TypeError('Cookie domain must not be specified for host cookies');
|
|
48
|
+
}
|
|
49
|
+
if (((_c = item.name) === null || _c === void 0 ? void 0 : _c.startsWith('__Host')) && item.path !== '/') {
|
|
50
|
+
throw new TypeError('Cookie path must not be specified for host cookies');
|
|
51
|
+
}
|
|
52
|
+
if (item.path && item.path.endsWith('/')) {
|
|
53
|
+
item.path = item.path.slice(0, -1);
|
|
54
|
+
}
|
|
55
|
+
if (item.path === '') {
|
|
56
|
+
item.path = '/';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (item.name === '' && item.value && item.value.includes('=')) {
|
|
60
|
+
throw new TypeError("Cookie value cannot contain '=' if the name is empty");
|
|
61
|
+
}
|
|
62
|
+
if (item.name && item.name.startsWith('__Host')) {
|
|
63
|
+
item.secure = true;
|
|
64
|
+
}
|
|
65
|
+
const previousCookie = await this.get(item);
|
|
66
|
+
this.cookieMap.set(item.name || '', item);
|
|
67
|
+
if (this.onchange) {
|
|
68
|
+
const changed = [];
|
|
69
|
+
const deleted = [];
|
|
70
|
+
if (previousCookie && !(await this.get(item))) {
|
|
71
|
+
deleted.push({ ...item, value: undefined });
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
changed.push(item);
|
|
75
|
+
}
|
|
76
|
+
const event = new CookieChangeEvent('change', { changed, deleted });
|
|
77
|
+
this.onchange(event);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async getAll(init) {
|
|
81
|
+
const cookies = Array.from(this.cookieMap.values());
|
|
82
|
+
if (init == null || Object.keys(init).length === 0) {
|
|
83
|
+
return cookies;
|
|
84
|
+
}
|
|
85
|
+
let name;
|
|
86
|
+
if (typeof init === 'string') {
|
|
87
|
+
name = init;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
name = init.name;
|
|
91
|
+
}
|
|
92
|
+
return cookies.filter(cookie => cookie.name === name);
|
|
93
|
+
}
|
|
94
|
+
async delete(init) {
|
|
95
|
+
const item = {
|
|
96
|
+
name: '',
|
|
97
|
+
value: '',
|
|
98
|
+
path: '/',
|
|
99
|
+
secure: false,
|
|
100
|
+
sameSite: 'strict',
|
|
101
|
+
expires: null,
|
|
102
|
+
domain: null,
|
|
103
|
+
};
|
|
104
|
+
if (typeof init === 'string') {
|
|
105
|
+
item.name = init;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
Object.assign(item, init);
|
|
109
|
+
}
|
|
110
|
+
item.expires = 0;
|
|
111
|
+
await this.set(item);
|
|
112
|
+
}
|
|
113
|
+
get cookieString() {
|
|
114
|
+
const cookieStrings = [];
|
|
115
|
+
for (const [, item] of this.cookieMap) {
|
|
116
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
117
|
+
let cookieString = `${item.name}=${encodeURIComponent(item.value)}`;
|
|
118
|
+
if (item.domain) {
|
|
119
|
+
cookieString += '; Domain=' + item.domain;
|
|
120
|
+
}
|
|
121
|
+
if (item.path) {
|
|
122
|
+
cookieString += '; Path=' + item.path;
|
|
123
|
+
}
|
|
124
|
+
if (typeof item.expires === 'number') {
|
|
125
|
+
cookieString += '; Expires=' + new Date(item.expires).toUTCString();
|
|
126
|
+
}
|
|
127
|
+
if ((item.name && item.name.startsWith('__Secure')) || item.secure) {
|
|
128
|
+
item.sameSite = 'lax';
|
|
129
|
+
cookieString += '; Secure';
|
|
130
|
+
}
|
|
131
|
+
switch (item.sameSite) {
|
|
132
|
+
case 'lax':
|
|
133
|
+
cookieString += '; SameSite=Lax';
|
|
134
|
+
break;
|
|
135
|
+
case 'strict':
|
|
136
|
+
cookieString += '; SameSite=Strict';
|
|
137
|
+
break;
|
|
138
|
+
case 'none':
|
|
139
|
+
cookieString += '; SameSite=None';
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
cookieStrings.push(cookieString);
|
|
143
|
+
}
|
|
144
|
+
return cookieStrings.join('; ');
|
|
145
|
+
}
|
|
146
|
+
}
|
package/esm/index.js
ADDED
package/esm/parse.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const decode = decodeURIComponent;
|
|
2
|
+
const pairSplitRegExp = /; */;
|
|
3
|
+
// Try decoding a string using a decoding function.
|
|
4
|
+
function tryDecode(str, decode) {
|
|
5
|
+
try {
|
|
6
|
+
return typeof decode === 'boolean' ? decodeURIComponent(str) : decode(str);
|
|
7
|
+
}
|
|
8
|
+
catch (e) {
|
|
9
|
+
return str;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Parse a cookie header.
|
|
14
|
+
*
|
|
15
|
+
* Parse the given cookie header string into an object
|
|
16
|
+
* The object has the various cookies as keys(names) => values
|
|
17
|
+
*/
|
|
18
|
+
export function parse(str, options = {}) {
|
|
19
|
+
if (typeof str !== 'string') {
|
|
20
|
+
throw new TypeError('argument str must be a string');
|
|
21
|
+
}
|
|
22
|
+
const map = new Map();
|
|
23
|
+
const opt = options || {};
|
|
24
|
+
const pairs = str.split(pairSplitRegExp);
|
|
25
|
+
const dec = opt.decode || decode;
|
|
26
|
+
for (let i = 0; i < pairs.length; i++) {
|
|
27
|
+
const pair = pairs[i];
|
|
28
|
+
let eqIdx = pair.indexOf('=');
|
|
29
|
+
// skip things that don't look like key=value
|
|
30
|
+
if (eqIdx < 0) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const key = pair.substr(0, eqIdx).trim();
|
|
34
|
+
let val = pair.substr(++eqIdx, pair.length).trim();
|
|
35
|
+
// quoted values
|
|
36
|
+
if (val[0] === '"') {
|
|
37
|
+
val = val.slice(1, -1);
|
|
38
|
+
}
|
|
39
|
+
const cookiesPerKey = map.get(key);
|
|
40
|
+
if (!cookiesPerKey) {
|
|
41
|
+
map.set(key, { name: key, value: tryDecode(val, dec) });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return map;
|
|
45
|
+
}
|
package/esm/types.js
ADDED
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@whatwg-node/cookie-store",
|
|
3
|
+
"version": "0.0.1-alpha-20230425095535-e20a748",
|
|
4
|
+
"description": "Cookie Store",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@whatwg-node/events": "^0.0.3",
|
|
8
|
+
"tslib": "^2.3.1"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "ardatan/whatwg-node",
|
|
13
|
+
"directory": "packages/cookie-store"
|
|
14
|
+
},
|
|
15
|
+
"author": "Arda TANRIKULU <ardatanrikulu@gmail.com>",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"main": "cjs/index.js",
|
|
18
|
+
"module": "esm/index.js",
|
|
19
|
+
"typings": "typings/index.d.ts",
|
|
20
|
+
"typescript": {
|
|
21
|
+
"definition": "typings/index.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"require": {
|
|
27
|
+
"types": "./typings/index.d.cts",
|
|
28
|
+
"default": "./cjs/index.js"
|
|
29
|
+
},
|
|
30
|
+
"import": {
|
|
31
|
+
"types": "./typings/index.d.ts",
|
|
32
|
+
"default": "./esm/index.js"
|
|
33
|
+
},
|
|
34
|
+
"default": {
|
|
35
|
+
"types": "./typings/index.d.ts",
|
|
36
|
+
"default": "./esm/index.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"./package.json": "./package.json"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Event } from '@whatwg-node/events';
|
|
2
|
+
import { CookieChangeEventInit, CookieList } from './types.cjs';
|
|
3
|
+
export declare class CookieChangeEvent extends Event {
|
|
4
|
+
changed: CookieList;
|
|
5
|
+
deleted: CookieList;
|
|
6
|
+
constructor(type: string, eventInitDict?: CookieChangeEventInit);
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Event } from '@whatwg-node/events';
|
|
2
|
+
import { CookieChangeEventInit, CookieList } from './types.js';
|
|
3
|
+
export declare class CookieChangeEvent extends Event {
|
|
4
|
+
changed: CookieList;
|
|
5
|
+
deleted: CookieList;
|
|
6
|
+
constructor(type: string, eventInitDict?: CookieChangeEventInit);
|
|
7
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EventTarget } from '@whatwg-node/events';
|
|
2
|
+
import { CookieChangeEvent } from './CookieChangeEvent.cjs';
|
|
3
|
+
import { Cookie, CookieListItem, CookieStoreDeleteOptions, CookieStoreGetOptions } from './types.cjs';
|
|
4
|
+
export declare class CookieStore extends EventTarget {
|
|
5
|
+
onchange?: (event: CookieChangeEvent) => void;
|
|
6
|
+
private cookieMap;
|
|
7
|
+
get [Symbol.toStringTag](): 'CookieStore';
|
|
8
|
+
constructor(cookieString: string);
|
|
9
|
+
get(init?: CookieStoreGetOptions['name'] | CookieStoreGetOptions): Promise<Cookie | undefined>;
|
|
10
|
+
set(init: CookieListItem | string, possibleValue?: string): Promise<void>;
|
|
11
|
+
getAll(init?: CookieStoreGetOptions['name'] | CookieStoreGetOptions): Promise<Cookie[]>;
|
|
12
|
+
delete(init: CookieStoreDeleteOptions['name'] | CookieStoreDeleteOptions): Promise<void>;
|
|
13
|
+
get cookieString(): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EventTarget } from '@whatwg-node/events';
|
|
2
|
+
import { CookieChangeEvent } from './CookieChangeEvent.js';
|
|
3
|
+
import { Cookie, CookieListItem, CookieStoreDeleteOptions, CookieStoreGetOptions } from './types.js';
|
|
4
|
+
export declare class CookieStore extends EventTarget {
|
|
5
|
+
onchange?: (event: CookieChangeEvent) => void;
|
|
6
|
+
private cookieMap;
|
|
7
|
+
get [Symbol.toStringTag](): 'CookieStore';
|
|
8
|
+
constructor(cookieString: string);
|
|
9
|
+
get(init?: CookieStoreGetOptions['name'] | CookieStoreGetOptions): Promise<Cookie | undefined>;
|
|
10
|
+
set(init: CookieListItem | string, possibleValue?: string): Promise<void>;
|
|
11
|
+
getAll(init?: CookieStoreGetOptions['name'] | CookieStoreGetOptions): Promise<Cookie[]>;
|
|
12
|
+
delete(init: CookieStoreDeleteOptions['name'] | CookieStoreDeleteOptions): Promise<void>;
|
|
13
|
+
get cookieString(): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Cookie } from './types.cjs';
|
|
2
|
+
export interface ParseOptions {
|
|
3
|
+
decode?: boolean;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Parse a cookie header.
|
|
7
|
+
*
|
|
8
|
+
* Parse the given cookie header string into an object
|
|
9
|
+
* The object has the various cookies as keys(names) => values
|
|
10
|
+
*/
|
|
11
|
+
export declare function parse(str: string, options?: ParseOptions): Map<string, Cookie>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Cookie } from './types.js';
|
|
2
|
+
export interface ParseOptions {
|
|
3
|
+
decode?: boolean;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Parse a cookie header.
|
|
7
|
+
*
|
|
8
|
+
* Parse the given cookie header string into an object
|
|
9
|
+
* The object has the various cookies as keys(names) => values
|
|
10
|
+
*/
|
|
11
|
+
export declare function parse(str: string, options?: ParseOptions): Map<string, Cookie>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface Cookie {
|
|
2
|
+
domain?: string;
|
|
3
|
+
expires?: number;
|
|
4
|
+
name: string;
|
|
5
|
+
path?: string;
|
|
6
|
+
secure?: boolean;
|
|
7
|
+
sameSite?: CookieSameSite;
|
|
8
|
+
value: string;
|
|
9
|
+
}
|
|
10
|
+
export interface CookieStoreDeleteOptions {
|
|
11
|
+
name: string;
|
|
12
|
+
domain?: string;
|
|
13
|
+
path?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface CookieStoreGetOptions {
|
|
16
|
+
name?: string;
|
|
17
|
+
url?: string;
|
|
18
|
+
}
|
|
19
|
+
export type CookieSameSite = 'strict' | 'lax' | 'none';
|
|
20
|
+
export interface CookieListItem {
|
|
21
|
+
name?: string;
|
|
22
|
+
value?: string;
|
|
23
|
+
domain: string | null;
|
|
24
|
+
path?: string;
|
|
25
|
+
expires: Date | number | null;
|
|
26
|
+
secure?: boolean;
|
|
27
|
+
sameSite?: CookieSameSite;
|
|
28
|
+
}
|
|
29
|
+
export type CookieList = CookieListItem[];
|
|
30
|
+
export interface CookieChangeEventInit extends EventInit {
|
|
31
|
+
changed: CookieList;
|
|
32
|
+
deleted: CookieList;
|
|
33
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface Cookie {
|
|
2
|
+
domain?: string;
|
|
3
|
+
expires?: number;
|
|
4
|
+
name: string;
|
|
5
|
+
path?: string;
|
|
6
|
+
secure?: boolean;
|
|
7
|
+
sameSite?: CookieSameSite;
|
|
8
|
+
value: string;
|
|
9
|
+
}
|
|
10
|
+
export interface CookieStoreDeleteOptions {
|
|
11
|
+
name: string;
|
|
12
|
+
domain?: string;
|
|
13
|
+
path?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface CookieStoreGetOptions {
|
|
16
|
+
name?: string;
|
|
17
|
+
url?: string;
|
|
18
|
+
}
|
|
19
|
+
export type CookieSameSite = 'strict' | 'lax' | 'none';
|
|
20
|
+
export interface CookieListItem {
|
|
21
|
+
name?: string;
|
|
22
|
+
value?: string;
|
|
23
|
+
domain: string | null;
|
|
24
|
+
path?: string;
|
|
25
|
+
expires: Date | number | null;
|
|
26
|
+
secure?: boolean;
|
|
27
|
+
sameSite?: CookieSameSite;
|
|
28
|
+
}
|
|
29
|
+
export type CookieList = CookieListItem[];
|
|
30
|
+
export interface CookieChangeEventInit extends EventInit {
|
|
31
|
+
changed: CookieList;
|
|
32
|
+
deleted: CookieList;
|
|
33
|
+
}
|