@whatwg-node/server-plugin-cookies 0.0.1 → 0.0.2-alpha-20230320123631-3fc1dd7
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/{index.js → cjs/CookieStore.js} +10 -81
- package/cjs/index.js +4 -0
- package/cjs/package.json +1 -0
- package/cjs/parse.js +52 -0
- package/cjs/types.js +0 -0
- package/cjs/useCookies.js +17 -0
- package/esm/CookieChangeEvent.js +8 -0
- package/{index.mjs → esm/CookieStore.js} +4 -75
- package/esm/index.js +1 -0
- package/esm/parse.js +48 -0
- package/esm/types.js +0 -0
- package/esm/useCookies.js +13 -0
- package/package.json +20 -13
- package/typings/CookieChangeEvent.d.cts +7 -0
- package/{CookieChangeEvent.d.ts → typings/CookieChangeEvent.d.ts} +1 -1
- package/typings/CookieStore.d.cts +13 -0
- package/{CookieStore.d.ts → typings/CookieStore.d.ts} +2 -2
- package/typings/index.d.cts +1 -0
- package/typings/index.d.ts +1 -0
- package/typings/parse.d.cts +11 -0
- package/{parse.d.ts → typings/parse.d.ts} +1 -1
- package/typings/types.d.ts +33 -0
- package/typings/useCookies.d.cts +8 -0
- package/{useCookies.d.ts → typings/useCookies.d.ts} +1 -1
- package/index.d.ts +0 -1
- /package/{types.d.ts → typings/types.d.cts} +0 -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;
|
|
@@ -1,67 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
class
|
|
8
|
-
constructor(type, eventInitDict = { changed: [], deleted: [] }) {
|
|
9
|
-
super(type, eventInitDict);
|
|
10
|
-
this.changed = eventInitDict.changed || [];
|
|
11
|
-
this.deleted = eventInitDict.deleted || [];
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const decode = decodeURIComponent;
|
|
16
|
-
const pairSplitRegExp = /; */;
|
|
17
|
-
// Try decoding a string using a decoding function.
|
|
18
|
-
function tryDecode(str, decode) {
|
|
19
|
-
try {
|
|
20
|
-
return typeof decode === 'boolean' ? decodeURIComponent(str) : decode(str);
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
return str;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Parse a cookie header.
|
|
28
|
-
*
|
|
29
|
-
* Parse the given cookie header string into an object
|
|
30
|
-
* The object has the various cookies as keys(names) => values
|
|
31
|
-
*/
|
|
32
|
-
function parse(str, options = {}) {
|
|
33
|
-
if (typeof str !== 'string') {
|
|
34
|
-
throw new TypeError('argument str must be a string');
|
|
35
|
-
}
|
|
36
|
-
const obj = [];
|
|
37
|
-
const opt = options || {};
|
|
38
|
-
const pairs = str.split(pairSplitRegExp);
|
|
39
|
-
const dec = opt.decode || decode;
|
|
40
|
-
for (let i = 0; i < pairs.length; i++) {
|
|
41
|
-
const pair = pairs[i];
|
|
42
|
-
let eqIdx = pair.indexOf('=');
|
|
43
|
-
// skip things that don't look like key=value
|
|
44
|
-
if (eqIdx < 0) {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
const key = pair.substr(0, eqIdx).trim();
|
|
48
|
-
let val = pair.substr(++eqIdx, pair.length).trim();
|
|
49
|
-
// quoted values
|
|
50
|
-
if (val[0] === '"') {
|
|
51
|
-
val = val.slice(1, -1);
|
|
52
|
-
}
|
|
53
|
-
// only assign once
|
|
54
|
-
if (obj[key] == null) {
|
|
55
|
-
obj.push({
|
|
56
|
-
name: key,
|
|
57
|
-
value: tryDecode(val, dec),
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return obj;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
class CookieStore extends events.EventTarget {
|
|
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 {
|
|
65
8
|
get [Symbol.toStringTag]() {
|
|
66
9
|
return 'CookieStore';
|
|
67
10
|
}
|
|
@@ -163,12 +106,12 @@ class CookieStore extends events.EventTarget {
|
|
|
163
106
|
}
|
|
164
107
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
165
108
|
// @ts-ignore
|
|
166
|
-
const event = new CookieChangeEvent('change', { changed, deleted });
|
|
109
|
+
const event = new CookieChangeEvent_js_1.CookieChangeEvent('change', { changed, deleted });
|
|
167
110
|
this.onchange(event);
|
|
168
111
|
}
|
|
169
112
|
}
|
|
170
113
|
async getAll(init) {
|
|
171
|
-
const cookies = parse(this.cookieString);
|
|
114
|
+
const cookies = (0, parse_js_1.parse)(this.cookieString);
|
|
172
115
|
if (init == null || Object.keys(init).length === 0) {
|
|
173
116
|
return cookies;
|
|
174
117
|
}
|
|
@@ -201,18 +144,4 @@ class CookieStore extends events.EventTarget {
|
|
|
201
144
|
await this.set(item);
|
|
202
145
|
}
|
|
203
146
|
}
|
|
204
|
-
|
|
205
|
-
function useCookies() {
|
|
206
|
-
return {
|
|
207
|
-
onRequest({ request }) {
|
|
208
|
-
request.cookieStore = new CookieStore(request.headers.get('cookie') || '');
|
|
209
|
-
},
|
|
210
|
-
onResponse({ request, response }) {
|
|
211
|
-
if (request.cookieStore) {
|
|
212
|
-
response.headers.set('set-cookie', request.cookieStore.cookieString);
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
exports.useCookies = useCookies;
|
|
147
|
+
exports.CookieStore = CookieStore;
|
package/cjs/index.js
ADDED
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
package/cjs/parse.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
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 obj = [];
|
|
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
|
+
// only assign once
|
|
43
|
+
if (obj[key] == null) {
|
|
44
|
+
obj.push({
|
|
45
|
+
name: key,
|
|
46
|
+
value: tryDecode(val, dec),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return obj;
|
|
51
|
+
}
|
|
52
|
+
exports.parse = parse;
|
package/cjs/types.js
ADDED
|
File without changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useCookies = void 0;
|
|
4
|
+
const CookieStore_js_1 = require("./CookieStore.js");
|
|
5
|
+
function useCookies() {
|
|
6
|
+
return {
|
|
7
|
+
onRequest({ request }) {
|
|
8
|
+
request.cookieStore = new CookieStore_js_1.CookieStore(request.headers.get('cookie') || '');
|
|
9
|
+
},
|
|
10
|
+
onResponse({ request, response }) {
|
|
11
|
+
if (request.cookieStore) {
|
|
12
|
+
response.headers.set('set-cookie', request.cookieStore.cookieString);
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
exports.useCookies = useCookies;
|
|
@@ -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
|
+
}
|
|
@@ -1,63 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
super(type, eventInitDict);
|
|
6
|
-
this.changed = eventInitDict.changed || [];
|
|
7
|
-
this.deleted = eventInitDict.deleted || [];
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const decode = decodeURIComponent;
|
|
12
|
-
const pairSplitRegExp = /; */;
|
|
13
|
-
// Try decoding a string using a decoding function.
|
|
14
|
-
function tryDecode(str, decode) {
|
|
15
|
-
try {
|
|
16
|
-
return typeof decode === 'boolean' ? decodeURIComponent(str) : decode(str);
|
|
17
|
-
}
|
|
18
|
-
catch (e) {
|
|
19
|
-
return str;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Parse a cookie header.
|
|
24
|
-
*
|
|
25
|
-
* Parse the given cookie header string into an object
|
|
26
|
-
* The object has the various cookies as keys(names) => values
|
|
27
|
-
*/
|
|
28
|
-
function parse(str, options = {}) {
|
|
29
|
-
if (typeof str !== 'string') {
|
|
30
|
-
throw new TypeError('argument str must be a string');
|
|
31
|
-
}
|
|
32
|
-
const obj = [];
|
|
33
|
-
const opt = options || {};
|
|
34
|
-
const pairs = str.split(pairSplitRegExp);
|
|
35
|
-
const dec = opt.decode || decode;
|
|
36
|
-
for (let i = 0; i < pairs.length; i++) {
|
|
37
|
-
const pair = pairs[i];
|
|
38
|
-
let eqIdx = pair.indexOf('=');
|
|
39
|
-
// skip things that don't look like key=value
|
|
40
|
-
if (eqIdx < 0) {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
const key = pair.substr(0, eqIdx).trim();
|
|
44
|
-
let val = pair.substr(++eqIdx, pair.length).trim();
|
|
45
|
-
// quoted values
|
|
46
|
-
if (val[0] === '"') {
|
|
47
|
-
val = val.slice(1, -1);
|
|
48
|
-
}
|
|
49
|
-
// only assign once
|
|
50
|
-
if (obj[key] == null) {
|
|
51
|
-
obj.push({
|
|
52
|
-
name: key,
|
|
53
|
-
value: tryDecode(val, dec),
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return obj;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
class CookieStore extends EventTarget {
|
|
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 {
|
|
61
5
|
get [Symbol.toStringTag]() {
|
|
62
6
|
return 'CookieStore';
|
|
63
7
|
}
|
|
@@ -197,18 +141,3 @@ class CookieStore extends EventTarget {
|
|
|
197
141
|
await this.set(item);
|
|
198
142
|
}
|
|
199
143
|
}
|
|
200
|
-
|
|
201
|
-
function useCookies() {
|
|
202
|
-
return {
|
|
203
|
-
onRequest({ request }) {
|
|
204
|
-
request.cookieStore = new CookieStore(request.headers.get('cookie') || '');
|
|
205
|
-
},
|
|
206
|
-
onResponse({ request, response }) {
|
|
207
|
-
if (request.cookieStore) {
|
|
208
|
-
response.headers.set('set-cookie', request.cookieStore.cookieString);
|
|
209
|
-
}
|
|
210
|
-
},
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export { useCookies };
|
package/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useCookies.js';
|
package/esm/parse.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
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 obj = [];
|
|
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
|
+
// only assign once
|
|
40
|
+
if (obj[key] == null) {
|
|
41
|
+
obj.push({
|
|
42
|
+
name: key,
|
|
43
|
+
value: tryDecode(val, dec),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return obj;
|
|
48
|
+
}
|
package/esm/types.js
ADDED
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CookieStore } from './CookieStore.js';
|
|
2
|
+
export function useCookies() {
|
|
3
|
+
return {
|
|
4
|
+
onRequest({ request }) {
|
|
5
|
+
request.cookieStore = new CookieStore(request.headers.get('cookie') || '');
|
|
6
|
+
},
|
|
7
|
+
onResponse({ request, response }) {
|
|
8
|
+
if (request.cookieStore) {
|
|
9
|
+
response.headers.set('set-cookie', request.cookieStore.cookieString);
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@whatwg-node/server-plugin-cookies",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2-alpha-20230320123631-3fc1dd7",
|
|
4
4
|
"description": "Cookies Plugin",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
|
-
"@whatwg-node/server": "
|
|
7
|
+
"@whatwg-node/server": "0.7.5-alpha-20230320123631-3fc1dd7"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@whatwg-node/events": "^0.0.2",
|
|
@@ -17,21 +17,28 @@
|
|
|
17
17
|
},
|
|
18
18
|
"author": "Arda TANRIKULU <ardatanrikulu@gmail.com>",
|
|
19
19
|
"license": "MIT",
|
|
20
|
-
"main": "index.js",
|
|
21
|
-
"module": "index.
|
|
22
|
-
"typings": "index.d.ts",
|
|
20
|
+
"main": "cjs/index.js",
|
|
21
|
+
"module": "esm/index.js",
|
|
22
|
+
"typings": "typings/index.d.ts",
|
|
23
23
|
"typescript": {
|
|
24
|
-
"definition": "index.d.ts"
|
|
24
|
+
"definition": "typings/index.d.ts"
|
|
25
25
|
},
|
|
26
|
+
"type": "module",
|
|
26
27
|
"exports": {
|
|
27
28
|
".": {
|
|
28
|
-
"require":
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./typings/index.d.cts",
|
|
31
|
+
"default": "./cjs/index.js"
|
|
32
|
+
},
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./typings/index.d.ts",
|
|
35
|
+
"default": "./esm/index.js"
|
|
36
|
+
},
|
|
37
|
+
"default": {
|
|
38
|
+
"types": "./typings/index.d.ts",
|
|
39
|
+
"default": "./esm/index.js"
|
|
40
|
+
}
|
|
34
41
|
},
|
|
35
42
|
"./package.json": "./package.json"
|
|
36
43
|
}
|
|
37
|
-
}
|
|
44
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Event } from '@whatwg-node/events';
|
|
2
|
-
import { CookieChangeEventInit, CookieList } from './types';
|
|
2
|
+
import { CookieChangeEventInit, CookieList } from './types.js';
|
|
3
3
|
export declare class CookieChangeEvent extends Event {
|
|
4
4
|
changed: CookieList;
|
|
5
5
|
deleted: CookieList;
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
cookieString: string;
|
|
6
|
+
onchange?: (event: CookieChangeEvent) => void;
|
|
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
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventTarget } from '@whatwg-node/events';
|
|
2
|
-
import { CookieChangeEvent } from './CookieChangeEvent';
|
|
3
|
-
import { Cookie, CookieListItem, CookieStoreDeleteOptions, CookieStoreGetOptions } from './types';
|
|
2
|
+
import { CookieChangeEvent } from './CookieChangeEvent.js';
|
|
3
|
+
import { Cookie, CookieListItem, CookieStoreDeleteOptions, CookieStoreGetOptions } from './types.js';
|
|
4
4
|
export declare class CookieStore extends EventTarget {
|
|
5
5
|
cookieString: string;
|
|
6
6
|
onchange?: (event: CookieChangeEvent) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useCookies.cjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useCookies.js';
|
|
@@ -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): 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,8 @@
|
|
|
1
|
+
import { ServerAdapterPlugin } from '@whatwg-node/server';
|
|
2
|
+
import { CookieStore } from './CookieStore.cjs';
|
|
3
|
+
declare global {
|
|
4
|
+
interface Request {
|
|
5
|
+
cookieStore?: CookieStore;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export declare function useCookies<TServerContext>(): ServerAdapterPlugin<TServerContext>;
|
package/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useCookies';
|
|
File without changes
|