修改后台权限
This commit is contained in:
9
node_modules/headers-polyfill/LICENSE
generated
vendored
Normal file
9
node_modules/headers-polyfill/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020–present Artem Zakharchenko
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
204
node_modules/headers-polyfill/README.md
generated
vendored
Normal file
204
node_modules/headers-polyfill/README.md
generated
vendored
Normal file
@@ -0,0 +1,204 @@
|
||||
[](https://www.npmjs.com/package/headers-polyfill)
|
||||
|
||||
# `headers-polyfill`
|
||||
|
||||
A `Headers` class polyfill and transformation library.
|
||||
|
||||
## Motivation
|
||||
|
||||
Various request issuing libraries utilize a different format of headers. This library chooses the [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) instance as the middle-ground between server and client, and provides functions to convert that instance to primitives and vice-versa.
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
npm install headers-polyfill
|
||||
```
|
||||
|
||||
## Polyfill
|
||||
|
||||
This package exports the `Headers` class that polyfills the native [`window.Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) implementation. This allows you to construct and manage headers using the same API in non-browser environments.
|
||||
|
||||
```js
|
||||
import { Headers } from 'headers-polyfill'
|
||||
|
||||
const headers = new Headers({
|
||||
Accept: '*/*',
|
||||
'Content-Type': 'application/json',
|
||||
})
|
||||
|
||||
headers.get('accept') // "*/*"
|
||||
```
|
||||
|
||||
## Methods
|
||||
|
||||
The `Headers` polyfill instance supports the same methods as the standard `Headers` instance:
|
||||
|
||||
- [`.has()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/has)
|
||||
- [`.get()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/get)
|
||||
- [`.set()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/set)
|
||||
- [`.append()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/append)
|
||||
- [`.delete()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/delete)
|
||||
- [`.forEach()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/forEach)
|
||||
- [`.getSetCookie()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/getSetCookie)
|
||||
|
||||
As well as the iterator methods:
|
||||
|
||||
- [`.keys()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/keys)
|
||||
- [`.values()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/values)
|
||||
- [`.entries()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/entries)
|
||||
|
||||
## Transformations
|
||||
|
||||
### `getRawHeaders()`
|
||||
|
||||
Returns an object consisting of the header name/value pairs but preserving raw header names.
|
||||
|
||||
```js
|
||||
const headers = new Headers({
|
||||
Accept: '*/*',
|
||||
'Content-Type': 'application/json',
|
||||
})
|
||||
|
||||
headers.raw()
|
||||
// { "Accept": "*/*", "Content-Type": "application/json" }
|
||||
```
|
||||
|
||||
### Headers ⭢ N
|
||||
|
||||
- `headersToString: (h: Headers): string`
|
||||
|
||||
```js
|
||||
import { headersToString } from 'headers-polyfill'
|
||||
|
||||
headersToString(
|
||||
new Headers({
|
||||
connection: 'keep-alive',
|
||||
'content-type': ['text/plain', 'image/png'],
|
||||
})
|
||||
)
|
||||
// connetion: keep-alive
|
||||
// content-type: text/plain, image/png
|
||||
```
|
||||
|
||||
- `headersToList: (h: Headers): Array<[string, string | string[]]>`
|
||||
|
||||
```js
|
||||
import { headersToList } from 'headers-polyfill'
|
||||
|
||||
headersToList(
|
||||
new Headers({
|
||||
connection: 'keep-alive',
|
||||
'content-type': ['text/plain', 'image/png'],
|
||||
})
|
||||
)
|
||||
// [['connection', 'keep-alive'], ['content-type', ['text/plain', 'image/png']]]
|
||||
```
|
||||
|
||||
- `headersToObject: (h: Headers): Record<string, string | string[]>`
|
||||
|
||||
```js
|
||||
import { headersToObject } from 'headers-polyfill'
|
||||
|
||||
headersToObject(
|
||||
new Headers({
|
||||
connection: 'keep-alive',
|
||||
'content-type': ['text/plain', 'image/png'],
|
||||
})
|
||||
)
|
||||
// { connection: 'keep-alive', 'content-type': ['text/plain', 'image/png'] }
|
||||
```
|
||||
|
||||
### N ⭢ Headers
|
||||
|
||||
- `stringToHeaders: (s: string): Headers`
|
||||
|
||||
```js
|
||||
import { stringToHeaders } from 'headers-polyfill'
|
||||
|
||||
|
||||
const stringToHeaders(`
|
||||
connection: keep-alive
|
||||
content-type: text/plain, image/png
|
||||
`)
|
||||
// Headers { connection: 'keep-alive', 'content-type': ['text/plain', 'image/png'] }
|
||||
```
|
||||
|
||||
- `listToHeaders: (l: Array<[string, string | string[]]>): Headers`
|
||||
|
||||
```js
|
||||
import { listToHeaders } from 'headers-polyfill'
|
||||
|
||||
listToHeaders([
|
||||
['connection', 'keep-alive'],
|
||||
['content-type', ['text/plain', 'image/png']],
|
||||
])
|
||||
// Headers { connection: 'keep-alive', 'content-type': ['text/plain', 'image/png'] }
|
||||
```
|
||||
|
||||
- `objectToHeaders: (o: Record<string, string | string[] | undefined>): Headers`
|
||||
|
||||
```js
|
||||
import { objectToHeaders } from 'headers-polyfill'
|
||||
|
||||
objectToHeaders({
|
||||
connection: 'keep-alive',
|
||||
'content-type': ['text/plain', 'image/png'],
|
||||
})
|
||||
// Headers { connection: 'keep-alive', 'content-type': ['text/plain', 'image/png'] }
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Utilities
|
||||
|
||||
- `reduceHeadersObject: <R>(o: Record<string, string | string[]>, reducer: (acc: R, name: string, value: string | string[]) => R) => R`
|
||||
|
||||
```js
|
||||
import { reduceHeadersObject } from 'headers-polyfill'
|
||||
|
||||
reduceHeadersObject <
|
||||
HeadersObject >
|
||||
({
|
||||
Accept: '*/*',
|
||||
'Content-Type': ['application/json', 'text/plain'],
|
||||
},
|
||||
(headers, name, value) => {
|
||||
headers[name.toLowerCase()] = value
|
||||
return headers
|
||||
},
|
||||
{})
|
||||
// { 'accept': '*/*', 'content-type': ['application/json', 'text/plain'] }
|
||||
```
|
||||
|
||||
- `appendHeader: (o: Record<string, string | string[]>, n: string, v: string | string[]): Record<string, string | string[]>`
|
||||
|
||||
```js
|
||||
import { appendHeader } from 'headers-polyfill'
|
||||
|
||||
appendHeader(
|
||||
{ 'content-type': 'application/json' },
|
||||
'content-type',
|
||||
'text/plain'
|
||||
)
|
||||
// { 'content-type': ['application/json', 'text/plain']}
|
||||
```
|
||||
|
||||
- `flattenHeadersList: (l: Array<[string, string | string[]]>): Array<string, string>`
|
||||
|
||||
```js
|
||||
import { flattenHeadersList } from 'headers-polyfill'
|
||||
|
||||
flattenHeadersList([['content-type', ['text/plain', 'image/png']]])
|
||||
// ['content-type', 'text/plain, image/png']
|
||||
```
|
||||
|
||||
- `flattenHeadersObject: (o: Record<string, string | string[]>): Record<string, string>`
|
||||
|
||||
```js
|
||||
import { flattenHeadersObject } from 'headers-polyfill'
|
||||
|
||||
flattenHeadersObject({
|
||||
'content-type': ['text/plain', 'image/png'],
|
||||
})
|
||||
// { 'content-type': 'text/plain, image/png' }
|
||||
```
|
||||
90
node_modules/headers-polyfill/lib/index.d.mts
generated
vendored
Normal file
90
node_modules/headers-polyfill/lib/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
type HeadersList = Array<[string, string | string[]]>;
|
||||
type FlatHeadersList = [string, string][];
|
||||
type HeadersObject = Record<string, string | string[]>;
|
||||
type FlatHeadersObject = Record<string, string>;
|
||||
|
||||
declare const NORMALIZED_HEADERS: unique symbol;
|
||||
declare const RAW_HEADER_NAMES: unique symbol;
|
||||
declare class Headers$1 {
|
||||
private [NORMALIZED_HEADERS];
|
||||
private [RAW_HEADER_NAMES];
|
||||
constructor(init?: HeadersInit | HeadersObject | HeadersList);
|
||||
[Symbol.toStringTag]: string;
|
||||
[Symbol.iterator](): IterableIterator<[string, string]>;
|
||||
keys(): IterableIterator<string>;
|
||||
values(): IterableIterator<string>;
|
||||
entries(): IterableIterator<[string, string]>;
|
||||
/**
|
||||
* Returns a boolean stating whether a `Headers` object contains a certain header.
|
||||
*/
|
||||
has(name: string): boolean;
|
||||
/**
|
||||
* Returns a `ByteString` sequence of all the values of a header with a given name.
|
||||
*/
|
||||
get(name: string): string | null;
|
||||
/**
|
||||
* Sets a new value for an existing header inside a `Headers` object, or adds the header if it does not already exist.
|
||||
*/
|
||||
set(name: string, value: string): void;
|
||||
/**
|
||||
* Appends a new value onto an existing header inside a `Headers` object, or adds the header if it does not already exist.
|
||||
*/
|
||||
append(name: string, value: string): void;
|
||||
/**
|
||||
* Deletes a header from the `Headers` object.
|
||||
*/
|
||||
delete(name: string): void;
|
||||
/**
|
||||
* Traverses the `Headers` object,
|
||||
* calling the given callback for each header.
|
||||
*/
|
||||
forEach<ThisArg = this>(callback: (this: ThisArg, value: string, name: string, parent: this) => void, thisArg?: ThisArg): void;
|
||||
/**
|
||||
* Returns an array containing the values
|
||||
* of all Set-Cookie headers associated
|
||||
* with a response
|
||||
*/
|
||||
getSetCookie(): string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object of all raw headers.
|
||||
*/
|
||||
declare function getRawHeaders(headers: Headers): Record<string, string>;
|
||||
|
||||
/**
|
||||
* Converts a given `Headers` instance to its string representation.
|
||||
*/
|
||||
declare function headersToString(headers: Headers): string;
|
||||
|
||||
declare function headersToList(headers: Headers): HeadersList;
|
||||
|
||||
/**
|
||||
* Converts a given `Headers` instance into a plain object.
|
||||
* Respects headers with multiple values.
|
||||
*/
|
||||
declare function headersToObject(headers: Headers): HeadersObject;
|
||||
|
||||
/**
|
||||
* Converts a string representation of headers (i.e. from XMLHttpRequest)
|
||||
* to a new `Headers` instance.
|
||||
*/
|
||||
declare function stringToHeaders(str: string): Headers$1;
|
||||
|
||||
declare function listToHeaders(list: HeadersList): Headers$1;
|
||||
|
||||
/**
|
||||
* Converts a given headers object to a new `Headers` instance.
|
||||
*/
|
||||
declare function objectToHeaders(headersObject: Record<string, string | string[] | undefined>): Headers$1;
|
||||
|
||||
/**
|
||||
* Reduces given headers object instnace.
|
||||
*/
|
||||
declare function reduceHeadersObject<R>(headers: HeadersObject, reducer: (headers: R, name: string, value: string | string[]) => R, initialState: R): R;
|
||||
|
||||
declare function flattenHeadersList(list: HeadersList): FlatHeadersList;
|
||||
|
||||
declare function flattenHeadersObject(headersObject: HeadersObject): FlatHeadersObject;
|
||||
|
||||
export { FlatHeadersList, FlatHeadersObject, Headers$1 as Headers, HeadersList, HeadersObject, flattenHeadersList, flattenHeadersObject, getRawHeaders, headersToList, headersToObject, headersToString, listToHeaders, objectToHeaders, reduceHeadersObject, stringToHeaders };
|
||||
90
node_modules/headers-polyfill/lib/index.d.ts
generated
vendored
Normal file
90
node_modules/headers-polyfill/lib/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
type HeadersList = Array<[string, string | string[]]>;
|
||||
type FlatHeadersList = [string, string][];
|
||||
type HeadersObject = Record<string, string | string[]>;
|
||||
type FlatHeadersObject = Record<string, string>;
|
||||
|
||||
declare const NORMALIZED_HEADERS: unique symbol;
|
||||
declare const RAW_HEADER_NAMES: unique symbol;
|
||||
declare class Headers$1 {
|
||||
private [NORMALIZED_HEADERS];
|
||||
private [RAW_HEADER_NAMES];
|
||||
constructor(init?: HeadersInit | HeadersObject | HeadersList);
|
||||
[Symbol.toStringTag]: string;
|
||||
[Symbol.iterator](): IterableIterator<[string, string]>;
|
||||
keys(): IterableIterator<string>;
|
||||
values(): IterableIterator<string>;
|
||||
entries(): IterableIterator<[string, string]>;
|
||||
/**
|
||||
* Returns a boolean stating whether a `Headers` object contains a certain header.
|
||||
*/
|
||||
has(name: string): boolean;
|
||||
/**
|
||||
* Returns a `ByteString` sequence of all the values of a header with a given name.
|
||||
*/
|
||||
get(name: string): string | null;
|
||||
/**
|
||||
* Sets a new value for an existing header inside a `Headers` object, or adds the header if it does not already exist.
|
||||
*/
|
||||
set(name: string, value: string): void;
|
||||
/**
|
||||
* Appends a new value onto an existing header inside a `Headers` object, or adds the header if it does not already exist.
|
||||
*/
|
||||
append(name: string, value: string): void;
|
||||
/**
|
||||
* Deletes a header from the `Headers` object.
|
||||
*/
|
||||
delete(name: string): void;
|
||||
/**
|
||||
* Traverses the `Headers` object,
|
||||
* calling the given callback for each header.
|
||||
*/
|
||||
forEach<ThisArg = this>(callback: (this: ThisArg, value: string, name: string, parent: this) => void, thisArg?: ThisArg): void;
|
||||
/**
|
||||
* Returns an array containing the values
|
||||
* of all Set-Cookie headers associated
|
||||
* with a response
|
||||
*/
|
||||
getSetCookie(): string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object of all raw headers.
|
||||
*/
|
||||
declare function getRawHeaders(headers: Headers): Record<string, string>;
|
||||
|
||||
/**
|
||||
* Converts a given `Headers` instance to its string representation.
|
||||
*/
|
||||
declare function headersToString(headers: Headers): string;
|
||||
|
||||
declare function headersToList(headers: Headers): HeadersList;
|
||||
|
||||
/**
|
||||
* Converts a given `Headers` instance into a plain object.
|
||||
* Respects headers with multiple values.
|
||||
*/
|
||||
declare function headersToObject(headers: Headers): HeadersObject;
|
||||
|
||||
/**
|
||||
* Converts a string representation of headers (i.e. from XMLHttpRequest)
|
||||
* to a new `Headers` instance.
|
||||
*/
|
||||
declare function stringToHeaders(str: string): Headers$1;
|
||||
|
||||
declare function listToHeaders(list: HeadersList): Headers$1;
|
||||
|
||||
/**
|
||||
* Converts a given headers object to a new `Headers` instance.
|
||||
*/
|
||||
declare function objectToHeaders(headersObject: Record<string, string | string[] | undefined>): Headers$1;
|
||||
|
||||
/**
|
||||
* Reduces given headers object instnace.
|
||||
*/
|
||||
declare function reduceHeadersObject<R>(headers: HeadersObject, reducer: (headers: R, name: string, value: string | string[]) => R, initialState: R): R;
|
||||
|
||||
declare function flattenHeadersList(list: HeadersList): FlatHeadersList;
|
||||
|
||||
declare function flattenHeadersObject(headersObject: HeadersObject): FlatHeadersObject;
|
||||
|
||||
export { FlatHeadersList, FlatHeadersObject, Headers$1 as Headers, HeadersList, HeadersObject, flattenHeadersList, flattenHeadersObject, getRawHeaders, headersToList, headersToObject, headersToString, listToHeaders, objectToHeaders, reduceHeadersObject, stringToHeaders };
|
||||
1102
node_modules/headers-polyfill/lib/index.js
generated
vendored
Normal file
1102
node_modules/headers-polyfill/lib/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
node_modules/headers-polyfill/lib/index.js.map
generated
vendored
Normal file
1
node_modules/headers-polyfill/lib/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
548
node_modules/headers-polyfill/lib/index.mjs
generated
vendored
Normal file
548
node_modules/headers-polyfill/lib/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,548 @@
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __commonJS = (cb, mod) => function __require() {
|
||||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
|
||||
// node_modules/set-cookie-parser/lib/set-cookie.js
|
||||
var require_set_cookie = __commonJS({
|
||||
"node_modules/set-cookie-parser/lib/set-cookie.js"(exports, module) {
|
||||
"use strict";
|
||||
var defaultParseOptions = {
|
||||
decodeValues: true,
|
||||
map: false,
|
||||
silent: false
|
||||
};
|
||||
function isNonEmptyString(str) {
|
||||
return typeof str === "string" && !!str.trim();
|
||||
}
|
||||
function parseString(setCookieValue, options) {
|
||||
var parts = setCookieValue.split(";").filter(isNonEmptyString);
|
||||
var nameValuePairStr = parts.shift();
|
||||
var parsed = parseNameValuePair(nameValuePairStr);
|
||||
var name = parsed.name;
|
||||
var value = parsed.value;
|
||||
options = options ? Object.assign({}, defaultParseOptions, options) : defaultParseOptions;
|
||||
try {
|
||||
value = options.decodeValues ? decodeURIComponent(value) : value;
|
||||
} catch (e) {
|
||||
console.error(
|
||||
"set-cookie-parser encountered an error while decoding a cookie with value '" + value + "'. Set options.decodeValues to false to disable this feature.",
|
||||
e
|
||||
);
|
||||
}
|
||||
var cookie = {
|
||||
name,
|
||||
value
|
||||
};
|
||||
parts.forEach(function(part) {
|
||||
var sides = part.split("=");
|
||||
var key = sides.shift().trimLeft().toLowerCase();
|
||||
var value2 = sides.join("=");
|
||||
if (key === "expires") {
|
||||
cookie.expires = new Date(value2);
|
||||
} else if (key === "max-age") {
|
||||
cookie.maxAge = parseInt(value2, 10);
|
||||
} else if (key === "secure") {
|
||||
cookie.secure = true;
|
||||
} else if (key === "httponly") {
|
||||
cookie.httpOnly = true;
|
||||
} else if (key === "samesite") {
|
||||
cookie.sameSite = value2;
|
||||
} else {
|
||||
cookie[key] = value2;
|
||||
}
|
||||
});
|
||||
return cookie;
|
||||
}
|
||||
function parseNameValuePair(nameValuePairStr) {
|
||||
var name = "";
|
||||
var value = "";
|
||||
var nameValueArr = nameValuePairStr.split("=");
|
||||
if (nameValueArr.length > 1) {
|
||||
name = nameValueArr.shift();
|
||||
value = nameValueArr.join("=");
|
||||
} else {
|
||||
value = nameValuePairStr;
|
||||
}
|
||||
return { name, value };
|
||||
}
|
||||
function parse(input, options) {
|
||||
options = options ? Object.assign({}, defaultParseOptions, options) : defaultParseOptions;
|
||||
if (!input) {
|
||||
if (!options.map) {
|
||||
return [];
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
if (input.headers) {
|
||||
if (typeof input.headers.getSetCookie === "function") {
|
||||
input = input.headers.getSetCookie();
|
||||
} else if (input.headers["set-cookie"]) {
|
||||
input = input.headers["set-cookie"];
|
||||
} else {
|
||||
var sch = input.headers[Object.keys(input.headers).find(function(key) {
|
||||
return key.toLowerCase() === "set-cookie";
|
||||
})];
|
||||
if (!sch && input.headers.cookie && !options.silent) {
|
||||
console.warn(
|
||||
"Warning: set-cookie-parser appears to have been called on a request object. It is designed to parse Set-Cookie headers from responses, not Cookie headers from requests. Set the option {silent: true} to suppress this warning."
|
||||
);
|
||||
}
|
||||
input = sch;
|
||||
}
|
||||
}
|
||||
if (!Array.isArray(input)) {
|
||||
input = [input];
|
||||
}
|
||||
options = options ? Object.assign({}, defaultParseOptions, options) : defaultParseOptions;
|
||||
if (!options.map) {
|
||||
return input.filter(isNonEmptyString).map(function(str) {
|
||||
return parseString(str, options);
|
||||
});
|
||||
} else {
|
||||
var cookies = {};
|
||||
return input.filter(isNonEmptyString).reduce(function(cookies2, str) {
|
||||
var cookie = parseString(str, options);
|
||||
cookies2[cookie.name] = cookie;
|
||||
return cookies2;
|
||||
}, cookies);
|
||||
}
|
||||
}
|
||||
function splitCookiesString2(cookiesString) {
|
||||
if (Array.isArray(cookiesString)) {
|
||||
return cookiesString;
|
||||
}
|
||||
if (typeof cookiesString !== "string") {
|
||||
return [];
|
||||
}
|
||||
var cookiesStrings = [];
|
||||
var pos = 0;
|
||||
var start;
|
||||
var ch;
|
||||
var lastComma;
|
||||
var nextStart;
|
||||
var cookiesSeparatorFound;
|
||||
function skipWhitespace() {
|
||||
while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) {
|
||||
pos += 1;
|
||||
}
|
||||
return pos < cookiesString.length;
|
||||
}
|
||||
function notSpecialChar() {
|
||||
ch = cookiesString.charAt(pos);
|
||||
return ch !== "=" && ch !== ";" && ch !== ",";
|
||||
}
|
||||
while (pos < cookiesString.length) {
|
||||
start = pos;
|
||||
cookiesSeparatorFound = false;
|
||||
while (skipWhitespace()) {
|
||||
ch = cookiesString.charAt(pos);
|
||||
if (ch === ",") {
|
||||
lastComma = pos;
|
||||
pos += 1;
|
||||
skipWhitespace();
|
||||
nextStart = pos;
|
||||
while (pos < cookiesString.length && notSpecialChar()) {
|
||||
pos += 1;
|
||||
}
|
||||
if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
|
||||
cookiesSeparatorFound = true;
|
||||
pos = nextStart;
|
||||
cookiesStrings.push(cookiesString.substring(start, lastComma));
|
||||
start = pos;
|
||||
} else {
|
||||
pos = lastComma + 1;
|
||||
}
|
||||
} else {
|
||||
pos += 1;
|
||||
}
|
||||
}
|
||||
if (!cookiesSeparatorFound || pos >= cookiesString.length) {
|
||||
cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
|
||||
}
|
||||
}
|
||||
return cookiesStrings;
|
||||
}
|
||||
module.exports = parse;
|
||||
module.exports.parse = parse;
|
||||
module.exports.parseString = parseString;
|
||||
module.exports.splitCookiesString = splitCookiesString2;
|
||||
}
|
||||
});
|
||||
|
||||
// src/Headers.ts
|
||||
var import_set_cookie_parser = __toESM(require_set_cookie());
|
||||
|
||||
// src/utils/normalizeHeaderName.ts
|
||||
var HEADERS_INVALID_CHARACTERS = /[^a-z0-9\-#$%&'*+.^_`|~]/i;
|
||||
function normalizeHeaderName(name) {
|
||||
if (HEADERS_INVALID_CHARACTERS.test(name) || name.trim() === "") {
|
||||
throw new TypeError("Invalid character in header field name");
|
||||
}
|
||||
return name.trim().toLowerCase();
|
||||
}
|
||||
|
||||
// src/utils/normalizeHeaderValue.ts
|
||||
var charCodesToRemove = [
|
||||
String.fromCharCode(10),
|
||||
String.fromCharCode(13),
|
||||
String.fromCharCode(9),
|
||||
String.fromCharCode(32)
|
||||
];
|
||||
var HEADER_VALUE_REMOVE_REGEXP = new RegExp(
|
||||
`(^[${charCodesToRemove.join("")}]|$[${charCodesToRemove.join("")}])`,
|
||||
"g"
|
||||
);
|
||||
function normalizeHeaderValue(value) {
|
||||
const nextValue = value.replace(HEADER_VALUE_REMOVE_REGEXP, "");
|
||||
return nextValue;
|
||||
}
|
||||
|
||||
// src/utils/isValidHeaderName.ts
|
||||
function isValidHeaderName(value) {
|
||||
if (typeof value !== "string") {
|
||||
return false;
|
||||
}
|
||||
if (value.length === 0) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
const character = value.charCodeAt(i);
|
||||
if (character > 127 || !isToken(character)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function isToken(value) {
|
||||
return ![
|
||||
127,
|
||||
32,
|
||||
"(",
|
||||
")",
|
||||
"<",
|
||||
">",
|
||||
"@",
|
||||
",",
|
||||
";",
|
||||
":",
|
||||
"\\",
|
||||
'"',
|
||||
"/",
|
||||
"[",
|
||||
"]",
|
||||
"?",
|
||||
"=",
|
||||
"{",
|
||||
"}"
|
||||
].includes(value);
|
||||
}
|
||||
|
||||
// src/utils/isValidHeaderValue.ts
|
||||
function isValidHeaderValue(value) {
|
||||
if (typeof value !== "string") {
|
||||
return false;
|
||||
}
|
||||
if (value.trim() !== value) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
const character = value.charCodeAt(i);
|
||||
if (
|
||||
// NUL.
|
||||
character === 0 || // HTTP newline bytes.
|
||||
character === 10 || character === 13
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// src/Headers.ts
|
||||
var NORMALIZED_HEADERS = Symbol("normalizedHeaders");
|
||||
var RAW_HEADER_NAMES = Symbol("rawHeaderNames");
|
||||
var HEADER_VALUE_DELIMITER = ", ";
|
||||
var _a, _b, _c;
|
||||
var Headers = class _Headers {
|
||||
constructor(init) {
|
||||
// Normalized header {"name":"a, b"} storage.
|
||||
this[_a] = {};
|
||||
// Keeps the mapping between the raw header name
|
||||
// and the normalized header name to ease the lookup.
|
||||
this[_b] = /* @__PURE__ */ new Map();
|
||||
this[_c] = "Headers";
|
||||
if (["Headers", "HeadersPolyfill"].includes(init?.constructor.name) || init instanceof _Headers || typeof globalThis.Headers !== "undefined" && init instanceof globalThis.Headers) {
|
||||
const initialHeaders = init;
|
||||
initialHeaders.forEach((value, name) => {
|
||||
this.append(name, value);
|
||||
}, this);
|
||||
} else if (Array.isArray(init)) {
|
||||
init.forEach(([name, value]) => {
|
||||
this.append(
|
||||
name,
|
||||
Array.isArray(value) ? value.join(HEADER_VALUE_DELIMITER) : value
|
||||
);
|
||||
});
|
||||
} else if (init) {
|
||||
Object.getOwnPropertyNames(init).forEach((name) => {
|
||||
const value = init[name];
|
||||
this.append(
|
||||
name,
|
||||
Array.isArray(value) ? value.join(HEADER_VALUE_DELIMITER) : value
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
[(_a = NORMALIZED_HEADERS, _b = RAW_HEADER_NAMES, _c = Symbol.toStringTag, Symbol.iterator)]() {
|
||||
return this.entries();
|
||||
}
|
||||
*keys() {
|
||||
for (const [name] of this.entries()) {
|
||||
yield name;
|
||||
}
|
||||
}
|
||||
*values() {
|
||||
for (const [, value] of this.entries()) {
|
||||
yield value;
|
||||
}
|
||||
}
|
||||
*entries() {
|
||||
let sortedKeys = Object.keys(this[NORMALIZED_HEADERS]).sort(
|
||||
(a, b) => a.localeCompare(b)
|
||||
);
|
||||
for (const name of sortedKeys) {
|
||||
if (name === "set-cookie") {
|
||||
for (const value of this.getSetCookie()) {
|
||||
yield [name, value];
|
||||
}
|
||||
} else {
|
||||
yield [name, this.get(name)];
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns a boolean stating whether a `Headers` object contains a certain header.
|
||||
*/
|
||||
has(name) {
|
||||
if (!isValidHeaderName(name)) {
|
||||
throw new TypeError(`Invalid header name "${name}"`);
|
||||
}
|
||||
return this[NORMALIZED_HEADERS].hasOwnProperty(normalizeHeaderName(name));
|
||||
}
|
||||
/**
|
||||
* Returns a `ByteString` sequence of all the values of a header with a given name.
|
||||
*/
|
||||
get(name) {
|
||||
if (!isValidHeaderName(name)) {
|
||||
throw TypeError(`Invalid header name "${name}"`);
|
||||
}
|
||||
return this[NORMALIZED_HEADERS][normalizeHeaderName(name)] ?? null;
|
||||
}
|
||||
/**
|
||||
* Sets a new value for an existing header inside a `Headers` object, or adds the header if it does not already exist.
|
||||
*/
|
||||
set(name, value) {
|
||||
if (!isValidHeaderName(name) || !isValidHeaderValue(value)) {
|
||||
return;
|
||||
}
|
||||
const normalizedName = normalizeHeaderName(name);
|
||||
const normalizedValue = normalizeHeaderValue(value);
|
||||
this[NORMALIZED_HEADERS][normalizedName] = normalizeHeaderValue(normalizedValue);
|
||||
this[RAW_HEADER_NAMES].set(normalizedName, name);
|
||||
}
|
||||
/**
|
||||
* Appends a new value onto an existing header inside a `Headers` object, or adds the header if it does not already exist.
|
||||
*/
|
||||
append(name, value) {
|
||||
if (!isValidHeaderName(name) || !isValidHeaderValue(value)) {
|
||||
return;
|
||||
}
|
||||
const normalizedName = normalizeHeaderName(name);
|
||||
const normalizedValue = normalizeHeaderValue(value);
|
||||
let resolvedValue = this.has(normalizedName) ? `${this.get(normalizedName)}, ${normalizedValue}` : normalizedValue;
|
||||
this.set(name, resolvedValue);
|
||||
}
|
||||
/**
|
||||
* Deletes a header from the `Headers` object.
|
||||
*/
|
||||
delete(name) {
|
||||
if (!isValidHeaderName(name)) {
|
||||
return;
|
||||
}
|
||||
if (!this.has(name)) {
|
||||
return;
|
||||
}
|
||||
const normalizedName = normalizeHeaderName(name);
|
||||
delete this[NORMALIZED_HEADERS][normalizedName];
|
||||
this[RAW_HEADER_NAMES].delete(normalizedName);
|
||||
}
|
||||
/**
|
||||
* Traverses the `Headers` object,
|
||||
* calling the given callback for each header.
|
||||
*/
|
||||
forEach(callback, thisArg) {
|
||||
for (const [name, value] of this.entries()) {
|
||||
callback.call(thisArg, value, name, this);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns an array containing the values
|
||||
* of all Set-Cookie headers associated
|
||||
* with a response
|
||||
*/
|
||||
getSetCookie() {
|
||||
const setCookieHeader = this.get("set-cookie");
|
||||
if (setCookieHeader === null) {
|
||||
return [];
|
||||
}
|
||||
if (setCookieHeader === "") {
|
||||
return [""];
|
||||
}
|
||||
return (0, import_set_cookie_parser.splitCookiesString)(setCookieHeader);
|
||||
}
|
||||
};
|
||||
|
||||
// src/getRawHeaders.ts
|
||||
function getRawHeaders(headers) {
|
||||
const rawHeaders = {};
|
||||
for (const [name, value] of headers.entries()) {
|
||||
rawHeaders[headers[RAW_HEADER_NAMES].get(name)] = value;
|
||||
}
|
||||
return rawHeaders;
|
||||
}
|
||||
|
||||
// src/transformers/headersToList.ts
|
||||
function headersToList(headers) {
|
||||
const headersList = [];
|
||||
headers.forEach((value, name) => {
|
||||
const resolvedValue = value.includes(",") ? value.split(",").map((value2) => value2.trim()) : value;
|
||||
headersList.push([name, resolvedValue]);
|
||||
});
|
||||
return headersList;
|
||||
}
|
||||
|
||||
// src/transformers/headersToString.ts
|
||||
function headersToString(headers) {
|
||||
const list = headersToList(headers);
|
||||
const lines = list.map(([name, value]) => {
|
||||
const values = [].concat(value);
|
||||
return `${name}: ${values.join(", ")}`;
|
||||
});
|
||||
return lines.join("\r\n");
|
||||
}
|
||||
|
||||
// src/transformers/headersToObject.ts
|
||||
var singleValueHeaders = ["user-agent"];
|
||||
function headersToObject(headers) {
|
||||
const headersObject = {};
|
||||
headers.forEach((value, name) => {
|
||||
const isMultiValue = !singleValueHeaders.includes(name.toLowerCase()) && value.includes(",");
|
||||
headersObject[name] = isMultiValue ? value.split(",").map((s) => s.trim()) : value;
|
||||
});
|
||||
return headersObject;
|
||||
}
|
||||
|
||||
// src/transformers/stringToHeaders.ts
|
||||
function stringToHeaders(str) {
|
||||
const lines = str.trim().split(/[\r\n]+/);
|
||||
return lines.reduce((headers, line) => {
|
||||
if (line.trim() === "") {
|
||||
return headers;
|
||||
}
|
||||
const parts = line.split(": ");
|
||||
const name = parts.shift();
|
||||
const value = parts.join(": ");
|
||||
headers.append(name, value);
|
||||
return headers;
|
||||
}, new Headers());
|
||||
}
|
||||
|
||||
// src/transformers/listToHeaders.ts
|
||||
function listToHeaders(list) {
|
||||
const headers = new Headers();
|
||||
list.forEach(([name, value]) => {
|
||||
const values = [].concat(value);
|
||||
values.forEach((value2) => {
|
||||
headers.append(name, value2);
|
||||
});
|
||||
});
|
||||
return headers;
|
||||
}
|
||||
|
||||
// src/transformers/reduceHeadersObject.ts
|
||||
function reduceHeadersObject(headers, reducer, initialState) {
|
||||
return Object.keys(headers).reduce((nextHeaders, name) => {
|
||||
return reducer(nextHeaders, name, headers[name]);
|
||||
}, initialState);
|
||||
}
|
||||
|
||||
// src/transformers/objectToHeaders.ts
|
||||
function objectToHeaders(headersObject) {
|
||||
return reduceHeadersObject(
|
||||
headersObject,
|
||||
(headers, name, value) => {
|
||||
const values = [].concat(value).filter(Boolean);
|
||||
values.forEach((value2) => {
|
||||
headers.append(name, value2);
|
||||
});
|
||||
return headers;
|
||||
},
|
||||
new Headers()
|
||||
);
|
||||
}
|
||||
|
||||
// src/transformers/flattenHeadersList.ts
|
||||
function flattenHeadersList(list) {
|
||||
return list.map(([name, values]) => {
|
||||
return [name, [].concat(values).join(", ")];
|
||||
});
|
||||
}
|
||||
|
||||
// src/transformers/flattenHeadersObject.ts
|
||||
function flattenHeadersObject(headersObject) {
|
||||
return reduceHeadersObject(
|
||||
headersObject,
|
||||
(headers, name, value) => {
|
||||
headers[name] = [].concat(value).join(", ");
|
||||
return headers;
|
||||
},
|
||||
{}
|
||||
);
|
||||
}
|
||||
export {
|
||||
Headers,
|
||||
flattenHeadersList,
|
||||
flattenHeadersObject,
|
||||
getRawHeaders,
|
||||
headersToList,
|
||||
headersToObject,
|
||||
headersToString,
|
||||
listToHeaders,
|
||||
objectToHeaders,
|
||||
reduceHeadersObject,
|
||||
stringToHeaders
|
||||
};
|
||||
//# sourceMappingURL=index.mjs.map
|
||||
1
node_modules/headers-polyfill/lib/index.mjs.map
generated
vendored
Normal file
1
node_modules/headers-polyfill/lib/index.mjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
43
node_modules/headers-polyfill/package.json
generated
vendored
Normal file
43
node_modules/headers-polyfill/package.json
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "headers-polyfill",
|
||||
"version": "4.0.3",
|
||||
"description": "A native \"Headers\" class polyfill.",
|
||||
"main": "./lib/index.js",
|
||||
"module": "./lib/index.mjs",
|
||||
"types": "./lib/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./lib/index.d.ts",
|
||||
"require": "./lib/index.js",
|
||||
"default": "./lib/index.mjs"
|
||||
}
|
||||
},
|
||||
"repository": "https://github.com/mswjs/headers-polyfill",
|
||||
"author": "Artem Zakharchenko",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"start": "tsup --watch",
|
||||
"clean": "rimraf lib",
|
||||
"build": "yarn clean && tsup",
|
||||
"test": "jest",
|
||||
"release": "release publish",
|
||||
"prepublishOnly": "yarn test && yarn build"
|
||||
},
|
||||
"files": [
|
||||
"lib",
|
||||
"README.md"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@ossjs/release": "^0.7.3",
|
||||
"@swc/core": "^1.3.84",
|
||||
"@swc/jest": "^0.2.29",
|
||||
"@types/jest": "^28.1.4",
|
||||
"@types/set-cookie-parser": "^2.4.3",
|
||||
"jest": "^28.1.2",
|
||||
"jest-environment-jsdom": "^28.1.2",
|
||||
"rimraf": "^3.0.2",
|
||||
"set-cookie-parser": "^2.6.0",
|
||||
"tsup": "^7.2.0",
|
||||
"typescript": "^5.2.2"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user