@spinajs/http 2.0.482 → 2.0.484
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/lib/cjs/config/http.d.ts +15 -7
- package/lib/cjs/config/http.d.ts.map +1 -1
- package/lib/cjs/config/http.js +17 -9
- package/lib/cjs/config/http.js.map +1 -1
- package/lib/cjs/cookie.d.ts +8 -0
- package/lib/cjs/cookie.d.ts.map +1 -0
- package/lib/cjs/cookie.js +40 -0
- package/lib/cjs/cookie.js.map +1 -0
- package/lib/mjs/config/http.d.ts +15 -7
- package/lib/mjs/config/http.d.ts.map +1 -1
- package/lib/mjs/config/http.js +17 -9
- package/lib/mjs/config/http.js.map +1 -1
- package/lib/mjs/cookie.d.ts +8 -0
- package/lib/mjs/cookie.d.ts.map +1 -0
- package/lib/mjs/cookie.js +32 -0
- package/lib/mjs/cookie.js.map +1 -0
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +12 -11
package/lib/cjs/config/http.d.ts
CHANGED
|
@@ -6,13 +6,6 @@ declare const http: {
|
|
|
6
6
|
cli: string[];
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
|
-
cookie: {
|
|
10
|
-
secret: string;
|
|
11
|
-
options: {
|
|
12
|
-
maxAge: number;
|
|
13
|
-
httpOnly: boolean;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
9
|
fs: {
|
|
17
10
|
providers: {
|
|
18
11
|
service: string;
|
|
@@ -21,6 +14,21 @@ declare const http: {
|
|
|
21
14
|
}[];
|
|
22
15
|
};
|
|
23
16
|
http: {
|
|
17
|
+
/**
|
|
18
|
+
* Cookie defaults. This MUST live under `http.` - every consumer reads
|
|
19
|
+
* `http.cookie.secret` ( responses, @FromCookie, the rbac session middleware ),
|
|
20
|
+
* and the parser that makes signed cookies work is bound to it.
|
|
21
|
+
*
|
|
22
|
+
* Override the secret per app: this default is public, and signed cookies are
|
|
23
|
+
* only as trustworthy as the key that signs them.
|
|
24
|
+
*/
|
|
25
|
+
cookie: {
|
|
26
|
+
secret: string;
|
|
27
|
+
options: {
|
|
28
|
+
maxAge: number;
|
|
29
|
+
httpOnly: boolean;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
24
32
|
/**
|
|
25
33
|
* File upload default middlewares
|
|
26
34
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/config/http.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AA0B9B,QAAA,MAAM,IAAI
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/config/http.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AA0B9B,QAAA,MAAM,IAAI;;;;;;;;;;;;;;;QAgCN;;;;;;;WAOG;;;;;;;;QASH;;WAEG;;;;;;;;;;;;;;;QAwCH;;WAEG;;YAGC;;eAEG;;YAGH;;eAEG;;;QAKP;;WAEG;;QAGH;;;WAGG;;;CAgBN,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
package/lib/cjs/config/http.js
CHANGED
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const express_1 = __importDefault(require("express"));
|
|
7
7
|
const helmet_1 = __importDefault(require("helmet"));
|
|
8
|
-
const
|
|
8
|
+
const cookie_js_1 = require("../cookie.js");
|
|
9
9
|
const compression_1 = __importDefault(require("compression"));
|
|
10
10
|
const path_1 = require("path");
|
|
11
11
|
const os_1 = __importDefault(require("os"));
|
|
@@ -30,13 +30,6 @@ const http = {
|
|
|
30
30
|
cli: [...dir('cli')],
|
|
31
31
|
},
|
|
32
32
|
},
|
|
33
|
-
cookie: {
|
|
34
|
-
secret: '1234adreewD',
|
|
35
|
-
options: {
|
|
36
|
-
maxAge: 900000,
|
|
37
|
-
httpOnly: true,
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
33
|
fs: {
|
|
41
34
|
providers: [
|
|
42
35
|
// formidable default file provider, incoming
|
|
@@ -60,6 +53,21 @@ const http = {
|
|
|
60
53
|
],
|
|
61
54
|
},
|
|
62
55
|
http: {
|
|
56
|
+
/**
|
|
57
|
+
* Cookie defaults. This MUST live under `http.` - every consumer reads
|
|
58
|
+
* `http.cookie.secret` ( responses, @FromCookie, the rbac session middleware ),
|
|
59
|
+
* and the parser that makes signed cookies work is bound to it.
|
|
60
|
+
*
|
|
61
|
+
* Override the secret per app: this default is public, and signed cookies are
|
|
62
|
+
* only as trustworthy as the key that signs them.
|
|
63
|
+
*/
|
|
64
|
+
cookie: {
|
|
65
|
+
secret: '1234adreewD',
|
|
66
|
+
options: {
|
|
67
|
+
maxAge: 900000,
|
|
68
|
+
httpOnly: true,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
63
71
|
/**
|
|
64
72
|
* File upload default middlewares
|
|
65
73
|
*/
|
|
@@ -96,7 +104,7 @@ const http = {
|
|
|
96
104
|
type: ['application/xml', 'text/xml', 'application/*+xml'],
|
|
97
105
|
limit: '5mb',
|
|
98
106
|
}),
|
|
99
|
-
|
|
107
|
+
cookie_js_1.configuredCookieParser,
|
|
100
108
|
(0, compression_1.default)(),
|
|
101
109
|
],
|
|
102
110
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/config/http.ts"],"names":[],"mappings":";;;;;AAAA,sDAA8B;AAC9B,oDAA4B;AAC5B,
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/config/http.ts"],"names":[],"mappings":";;;;;AAAA,sDAA8B;AAC9B,oDAA4B;AAC5B,4CAAsD;AACtD,8DAAsC;AACtC,+BAAgD;AAChD,4CAAoB;AAEpB,SAAS,GAAG,CAAC,GAAG,IAAe;IAC7B,OAAO,IAAA,W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AAC,QAAQ,CAAC;aACpB;SACF;QAED;;WAEG;QACH,aAAa,EAAE,CAAC,GAAG,CAAC;QAEpB;;;WAGG;QACH,aAAa,EAAE;;;;;;;;;;;;;4BAaS;KACzB;CACF,CAAC;AAEF,kBAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type express from 'express';
|
|
2
|
+
export declare const configuredCookieParser: express.RequestHandler;
|
|
3
|
+
/**
|
|
4
|
+
* Drops the memoised parser. Only needed where the configured secret can change
|
|
5
|
+
* within one process, ie. tests.
|
|
6
|
+
*/
|
|
7
|
+
export declare function resetCookieParser(): void;
|
|
8
|
+
//# sourceMappingURL=cookie.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../src/cookie.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAoBnC,eAAO,MAAM,sBAAsB,EAAE,OAAO,CAAC,cAO5C,CAAC;AAEF;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAExC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.configuredCookieParser = void 0;
|
|
7
|
+
exports.resetCookieParser = resetCookieParser;
|
|
8
|
+
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
|
9
|
+
const di_1 = require("@spinajs/di");
|
|
10
|
+
const configuration_1 = require("@spinajs/configuration");
|
|
11
|
+
/**
|
|
12
|
+
* cookie-parser bound to the configured `http.cookie.secret`.
|
|
13
|
+
*
|
|
14
|
+
* It MUST be constructed with the secret: that is what puts `req.secret` in place,
|
|
15
|
+
* and without it express throws `cookieParser("secret") required for signed cookies`
|
|
16
|
+
* from any `res.cookie(..., { signed: true })`. Logging in sets a signed `ssid`
|
|
17
|
+
* cookie, so a secretless parser breaks authentication outright.
|
|
18
|
+
*
|
|
19
|
+
* The secret is read on FIRST REQUEST rather than when this module is evaluated,
|
|
20
|
+
* because the config file that installs this middleware is itself loaded before the
|
|
21
|
+
* Configuration service exists. Capturing the value at module scope would freeze the
|
|
22
|
+
* shipped default and silently ignore whatever the app configured.
|
|
23
|
+
*/
|
|
24
|
+
let parser;
|
|
25
|
+
const configuredCookieParser = (req, res, next) => {
|
|
26
|
+
if (!parser) {
|
|
27
|
+
const secret = di_1.DI.get(configuration_1.Configuration)?.get('http.cookie.secret');
|
|
28
|
+
parser = (0, cookie_parser_1.default)(secret);
|
|
29
|
+
}
|
|
30
|
+
return parser(req, res, next);
|
|
31
|
+
};
|
|
32
|
+
exports.configuredCookieParser = configuredCookieParser;
|
|
33
|
+
/**
|
|
34
|
+
* Drops the memoised parser. Only needed where the configured secret can change
|
|
35
|
+
* within one process, ie. tests.
|
|
36
|
+
*/
|
|
37
|
+
function resetCookieParser() {
|
|
38
|
+
parser = undefined;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=cookie.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../src/cookie.ts"],"names":[],"mappings":";;;;;;AAiCA,8CAEC;AAlCD,kEAAyC;AACzC,oCAAiC;AACjC,0DAAuD;AAEvD;;;;;;;;;;;;GAYG;AACH,IAAI,MAA0C,CAAC;AAExC,MAAM,sBAAsB,GAA2B,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;IAC/E,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,MAAM,GAAG,OAAE,CAAC,GAAG,CAAC,6BAAa,CAAC,EAAE,GAAG,CAAS,oBAAoB,CAAC,CAAC;QACxE,MAAM,GAAG,IAAA,uBAAY,EAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;AAChC,CAAC,CAAC;AAPW,QAAA,sBAAsB,0BAOjC;AAEF;;;GAGG;AACH,SAAgB,iBAAiB;IAC/B,MAAM,GAAG,SAAS,CAAC;AACrB,CAAC"}
|
package/lib/mjs/config/http.d.ts
CHANGED
|
@@ -6,13 +6,6 @@ declare const http: {
|
|
|
6
6
|
cli: string[];
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
|
-
cookie: {
|
|
10
|
-
secret: string;
|
|
11
|
-
options: {
|
|
12
|
-
maxAge: number;
|
|
13
|
-
httpOnly: boolean;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
9
|
fs: {
|
|
17
10
|
providers: {
|
|
18
11
|
service: string;
|
|
@@ -21,6 +14,21 @@ declare const http: {
|
|
|
21
14
|
}[];
|
|
22
15
|
};
|
|
23
16
|
http: {
|
|
17
|
+
/**
|
|
18
|
+
* Cookie defaults. This MUST live under `http.` - every consumer reads
|
|
19
|
+
* `http.cookie.secret` ( responses, @FromCookie, the rbac session middleware ),
|
|
20
|
+
* and the parser that makes signed cookies work is bound to it.
|
|
21
|
+
*
|
|
22
|
+
* Override the secret per app: this default is public, and signed cookies are
|
|
23
|
+
* only as trustworthy as the key that signs them.
|
|
24
|
+
*/
|
|
25
|
+
cookie: {
|
|
26
|
+
secret: string;
|
|
27
|
+
options: {
|
|
28
|
+
maxAge: number;
|
|
29
|
+
httpOnly: boolean;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
24
32
|
/**
|
|
25
33
|
* File upload default middlewares
|
|
26
34
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/config/http.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AA0B9B,QAAA,MAAM,IAAI
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/config/http.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AA0B9B,QAAA,MAAM,IAAI;;;;;;;;;;;;;;;QAgCN;;;;;;;WAOG;;;;;;;;QASH;;WAEG;;;;;;;;;;;;;;;QAwCH;;WAEG;;YAGC;;eAEG;;YAGH;;eAEG;;;QAKP;;WAEG;;QAGH;;;WAGG;;;CAgBN,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
package/lib/mjs/config/http.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import helmet from 'helmet';
|
|
3
|
-
import
|
|
3
|
+
import { configuredCookieParser } from '../cookie.js';
|
|
4
4
|
import compression from 'compression';
|
|
5
5
|
import { join, normalize, resolve } from 'path';
|
|
6
6
|
import os from 'os';
|
|
@@ -25,13 +25,6 @@ const http = {
|
|
|
25
25
|
cli: [...dir('cli')],
|
|
26
26
|
},
|
|
27
27
|
},
|
|
28
|
-
cookie: {
|
|
29
|
-
secret: '1234adreewD',
|
|
30
|
-
options: {
|
|
31
|
-
maxAge: 900000,
|
|
32
|
-
httpOnly: true,
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
28
|
fs: {
|
|
36
29
|
providers: [
|
|
37
30
|
// formidable default file provider, incoming
|
|
@@ -55,6 +48,21 @@ const http = {
|
|
|
55
48
|
],
|
|
56
49
|
},
|
|
57
50
|
http: {
|
|
51
|
+
/**
|
|
52
|
+
* Cookie defaults. This MUST live under `http.` - every consumer reads
|
|
53
|
+
* `http.cookie.secret` ( responses, @FromCookie, the rbac session middleware ),
|
|
54
|
+
* and the parser that makes signed cookies work is bound to it.
|
|
55
|
+
*
|
|
56
|
+
* Override the secret per app: this default is public, and signed cookies are
|
|
57
|
+
* only as trustworthy as the key that signs them.
|
|
58
|
+
*/
|
|
59
|
+
cookie: {
|
|
60
|
+
secret: '1234adreewD',
|
|
61
|
+
options: {
|
|
62
|
+
maxAge: 900000,
|
|
63
|
+
httpOnly: true,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
58
66
|
/**
|
|
59
67
|
* File upload default middlewares
|
|
60
68
|
*/
|
|
@@ -91,7 +99,7 @@ const http = {
|
|
|
91
99
|
type: ['application/xml', 'text/xml', 'application/*+xml'],
|
|
92
100
|
limit: '5mb',
|
|
93
101
|
}),
|
|
94
|
-
|
|
102
|
+
configuredCookieParser,
|
|
95
103
|
compression(),
|
|
96
104
|
],
|
|
97
105
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/config/http.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/config/http.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,WAAW,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAChD,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,SAAS,GAAG,CAAC,GAAG,IAAe;IAC7B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;AACzE,CAAC;AAED,SAAS,GAAG,CAAC,GAAG,IAAc;IAC5B,OAAO,IAAI,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;AACzE,CAAC;AAED,SAAS,GAAG,CAAC,IAAY;IACvB,MAAM,UAAU,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;IACj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G,EAAE;YACH,GAAG,EAAE,EAAE;YACP,IAAI,EAAE,EAAE;SACT;QACD,WAAW,EAAE;YACX,KAAK,EAAE;gBACL,2CAA2C;gBAC3C,MAAM,EAAE,EAAE;aACX;SACF;QACD,IAAI,EAAE,IAAI;QACV,WAAW,EAAE;YACX,MAAM,EAAE;YACR,OAAO,CAAC,IAAI,CAAC;gBACX,KAAK,EAAE,KAAK;gBACZ,gEAAgE;gBAChE,8DAA8D;gBAC9D,MAAM,EAAE,CAAC,GAAQ,EAAE,IAAS,EAAE,GAAW,EAAE,EAAE;oBAC3C,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC;gBACpB,CAAC;aACF,CAAC;YACF,OAAO,CAAC,UAAU,CAAC;gBACjB,QAAQ,EAAE,IAAI;aACf,CAAC;YACF,wEAAwE;YACxE,oEAAoE;YACpE,OAAO,CAAC,IAAI,CAAC;gBACX,IAAI,EAAE,CAAC,iBAAiB,EAAE,UAAU,EAAE,mBAAmB,CAAC;gBAC1D,KAAK,EAAE,KAAK;aACb,CAAC;YACF,sBAAsB;YACtB,WAAW,EAAE;SACd;QAED;;WAEG;QACH,MAAM,EAAE;YACN;gBACE;;mBAEG;gBACH,KAAK,EAAE,UAAU;gBAEjB;;mBAEG;gBACH,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC;aACpB;SACF;QAED;;WAEG;QACH,aAAa,EAAE,CAAC,GAAG,CAAC;QAEpB;;;WAGG;QACH,aAAa,EAAE;;;;;;;;;;;;;4BAaS;KACzB;CACF,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type express from 'express';
|
|
2
|
+
export declare const configuredCookieParser: express.RequestHandler;
|
|
3
|
+
/**
|
|
4
|
+
* Drops the memoised parser. Only needed where the configured secret can change
|
|
5
|
+
* within one process, ie. tests.
|
|
6
|
+
*/
|
|
7
|
+
export declare function resetCookieParser(): void;
|
|
8
|
+
//# sourceMappingURL=cookie.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../src/cookie.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAoBnC,eAAO,MAAM,sBAAsB,EAAE,OAAO,CAAC,cAO5C,CAAC;AAEF;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAExC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import cookieParser from 'cookie-parser';
|
|
2
|
+
import { DI } from '@spinajs/di';
|
|
3
|
+
import { Configuration } from '@spinajs/configuration';
|
|
4
|
+
/**
|
|
5
|
+
* cookie-parser bound to the configured `http.cookie.secret`.
|
|
6
|
+
*
|
|
7
|
+
* It MUST be constructed with the secret: that is what puts `req.secret` in place,
|
|
8
|
+
* and without it express throws `cookieParser("secret") required for signed cookies`
|
|
9
|
+
* from any `res.cookie(..., { signed: true })`. Logging in sets a signed `ssid`
|
|
10
|
+
* cookie, so a secretless parser breaks authentication outright.
|
|
11
|
+
*
|
|
12
|
+
* The secret is read on FIRST REQUEST rather than when this module is evaluated,
|
|
13
|
+
* because the config file that installs this middleware is itself loaded before the
|
|
14
|
+
* Configuration service exists. Capturing the value at module scope would freeze the
|
|
15
|
+
* shipped default and silently ignore whatever the app configured.
|
|
16
|
+
*/
|
|
17
|
+
let parser;
|
|
18
|
+
export const configuredCookieParser = (req, res, next) => {
|
|
19
|
+
if (!parser) {
|
|
20
|
+
const secret = DI.get(Configuration)?.get('http.cookie.secret');
|
|
21
|
+
parser = cookieParser(secret);
|
|
22
|
+
}
|
|
23
|
+
return parser(req, res, next);
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Drops the memoised parser. Only needed where the configured secret can change
|
|
27
|
+
* within one process, ie. tests.
|
|
28
|
+
*/
|
|
29
|
+
export function resetCookieParser() {
|
|
30
|
+
parser = undefined;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=cookie.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../src/cookie.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD;;;;;;;;;;;;GAYG;AACH,IAAI,MAA0C,CAAC;AAE/C,MAAM,CAAC,MAAM,sBAAsB,GAA2B,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;IAC/E,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,MAAM,GAAG,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,GAAG,CAAS,oBAAoB,CAAC,CAAC;QACxE,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,iBAAiB;IAC/B,MAAM,GAAG,SAAS,CAAC;AACrB,CAAC"}
|