Erster Docker-Stand
This commit is contained in:
63
_node_modules/hono/dist/utils/accept.js
generated
vendored
Normal file
63
_node_modules/hono/dist/utils/accept.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
// src/utils/accept.ts
|
||||
var parseAccept = (acceptHeader) => {
|
||||
if (!acceptHeader) {
|
||||
return [];
|
||||
}
|
||||
const acceptValues = acceptHeader.split(",").map((value, index) => ({ value, index }));
|
||||
return acceptValues.map(parseAcceptValue).filter((item) => Boolean(item)).sort(sortByQualityAndIndex).map(({ type, params, q }) => ({ type, params, q }));
|
||||
};
|
||||
var parseAcceptValueRegex = /;(?=(?:(?:[^"]*"){2})*[^"]*$)/;
|
||||
var parseAcceptValue = ({ value, index }) => {
|
||||
const parts = value.trim().split(parseAcceptValueRegex).map((s) => s.trim());
|
||||
const type = parts[0];
|
||||
if (!type) {
|
||||
return null;
|
||||
}
|
||||
const params = parseParams(parts.slice(1));
|
||||
const q = parseQuality(params.q);
|
||||
return { type, params, q, index };
|
||||
};
|
||||
var parseParams = (paramParts) => {
|
||||
return paramParts.reduce((acc, param) => {
|
||||
const [key, val] = param.split("=").map((s) => s.trim());
|
||||
if (key && val) {
|
||||
acc[key] = val;
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
};
|
||||
var parseQuality = (qVal) => {
|
||||
if (qVal === void 0) {
|
||||
return 1;
|
||||
}
|
||||
if (qVal === "") {
|
||||
return 1;
|
||||
}
|
||||
if (qVal === "NaN") {
|
||||
return 0;
|
||||
}
|
||||
const num = Number(qVal);
|
||||
if (num === Infinity) {
|
||||
return 1;
|
||||
}
|
||||
if (num === -Infinity) {
|
||||
return 0;
|
||||
}
|
||||
if (Number.isNaN(num)) {
|
||||
return 1;
|
||||
}
|
||||
if (num < 0 || num > 1) {
|
||||
return 1;
|
||||
}
|
||||
return num;
|
||||
};
|
||||
var sortByQualityAndIndex = (a, b) => {
|
||||
const qDiff = b.q - a.q;
|
||||
if (qDiff !== 0) {
|
||||
return qDiff;
|
||||
}
|
||||
return a.index - b.index;
|
||||
};
|
||||
export {
|
||||
parseAccept
|
||||
};
|
||||
23
_node_modules/hono/dist/utils/basic-auth.js
generated
vendored
Normal file
23
_node_modules/hono/dist/utils/basic-auth.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
// src/utils/basic-auth.ts
|
||||
import { decodeBase64 } from "./encode.js";
|
||||
var CREDENTIALS_REGEXP = /^ *(?:[Bb][Aa][Ss][Ii][Cc]) +([A-Za-z0-9._~+/-]+=*) *$/;
|
||||
var USER_PASS_REGEXP = /^([^:]*):(.*)$/;
|
||||
var utf8Decoder = new TextDecoder();
|
||||
var auth = (req) => {
|
||||
const match = CREDENTIALS_REGEXP.exec(req.headers.get("Authorization") || "");
|
||||
if (!match) {
|
||||
return void 0;
|
||||
}
|
||||
let userPass = void 0;
|
||||
try {
|
||||
userPass = USER_PASS_REGEXP.exec(utf8Decoder.decode(decodeBase64(match[1])));
|
||||
} catch {
|
||||
}
|
||||
if (!userPass) {
|
||||
return void 0;
|
||||
}
|
||||
return { username: userPass[1], password: userPass[2] };
|
||||
};
|
||||
export {
|
||||
auth
|
||||
};
|
||||
72
_node_modules/hono/dist/utils/body.js
generated
vendored
Normal file
72
_node_modules/hono/dist/utils/body.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
// src/utils/body.ts
|
||||
import { HonoRequest } from "../request.js";
|
||||
var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
|
||||
const { all = false, dot = false } = options;
|
||||
const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
|
||||
const contentType = headers.get("Content-Type");
|
||||
if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) {
|
||||
return parseFormData(request, { all, dot });
|
||||
}
|
||||
return {};
|
||||
};
|
||||
async function parseFormData(request, options) {
|
||||
const formData = await request.formData();
|
||||
if (formData) {
|
||||
return convertFormDataToBodyData(formData, options);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
function convertFormDataToBodyData(formData, options) {
|
||||
const form = /* @__PURE__ */ Object.create(null);
|
||||
formData.forEach((value, key) => {
|
||||
const shouldParseAllValues = options.all || key.endsWith("[]");
|
||||
if (!shouldParseAllValues) {
|
||||
form[key] = value;
|
||||
} else {
|
||||
handleParsingAllValues(form, key, value);
|
||||
}
|
||||
});
|
||||
if (options.dot) {
|
||||
Object.entries(form).forEach(([key, value]) => {
|
||||
const shouldParseDotValues = key.includes(".");
|
||||
if (shouldParseDotValues) {
|
||||
handleParsingNestedValues(form, key, value);
|
||||
delete form[key];
|
||||
}
|
||||
});
|
||||
}
|
||||
return form;
|
||||
}
|
||||
var handleParsingAllValues = (form, key, value) => {
|
||||
if (form[key] !== void 0) {
|
||||
if (Array.isArray(form[key])) {
|
||||
;
|
||||
form[key].push(value);
|
||||
} else {
|
||||
form[key] = [form[key], value];
|
||||
}
|
||||
} else {
|
||||
if (!key.endsWith("[]")) {
|
||||
form[key] = value;
|
||||
} else {
|
||||
form[key] = [value];
|
||||
}
|
||||
}
|
||||
};
|
||||
var handleParsingNestedValues = (form, key, value) => {
|
||||
let nestedForm = form;
|
||||
const keys = key.split(".");
|
||||
keys.forEach((key2, index) => {
|
||||
if (index === keys.length - 1) {
|
||||
nestedForm[key2] = value;
|
||||
} else {
|
||||
if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
|
||||
nestedForm[key2] = /* @__PURE__ */ Object.create(null);
|
||||
}
|
||||
nestedForm = nestedForm[key2];
|
||||
}
|
||||
});
|
||||
};
|
||||
export {
|
||||
parseBody
|
||||
};
|
||||
50
_node_modules/hono/dist/utils/buffer.js
generated
vendored
Normal file
50
_node_modules/hono/dist/utils/buffer.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
// src/utils/buffer.ts
|
||||
import { sha256 } from "./crypto.js";
|
||||
var equal = (a, b) => {
|
||||
if (a === b) {
|
||||
return true;
|
||||
}
|
||||
if (a.byteLength !== b.byteLength) {
|
||||
return false;
|
||||
}
|
||||
const va = new DataView(a);
|
||||
const vb = new DataView(b);
|
||||
let i = va.byteLength;
|
||||
while (i--) {
|
||||
if (va.getUint8(i) !== vb.getUint8(i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
var timingSafeEqual = async (a, b, hashFunction) => {
|
||||
if (!hashFunction) {
|
||||
hashFunction = sha256;
|
||||
}
|
||||
const [sa, sb] = await Promise.all([hashFunction(a), hashFunction(b)]);
|
||||
if (!sa || !sb) {
|
||||
return false;
|
||||
}
|
||||
return sa === sb && a === b;
|
||||
};
|
||||
var bufferToString = (buffer) => {
|
||||
if (buffer instanceof ArrayBuffer) {
|
||||
const enc = new TextDecoder("utf-8");
|
||||
return enc.decode(buffer);
|
||||
}
|
||||
return buffer;
|
||||
};
|
||||
var bufferToFormData = (arrayBuffer, contentType) => {
|
||||
const response = new Response(arrayBuffer, {
|
||||
headers: {
|
||||
"Content-Type": contentType
|
||||
}
|
||||
});
|
||||
return response.formData();
|
||||
};
|
||||
export {
|
||||
bufferToFormData,
|
||||
bufferToString,
|
||||
equal,
|
||||
timingSafeEqual
|
||||
};
|
||||
25
_node_modules/hono/dist/utils/color.js
generated
vendored
Normal file
25
_node_modules/hono/dist/utils/color.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
// src/utils/color.ts
|
||||
function getColorEnabled() {
|
||||
const { process, Deno } = globalThis;
|
||||
const isNoColor = typeof Deno?.noColor === "boolean" ? Deno.noColor : process !== void 0 ? (
|
||||
// eslint-disable-next-line no-unsafe-optional-chaining
|
||||
"NO_COLOR" in process?.env
|
||||
) : false;
|
||||
return !isNoColor;
|
||||
}
|
||||
async function getColorEnabledAsync() {
|
||||
const { navigator } = globalThis;
|
||||
const cfWorkers = "cloudflare:workers";
|
||||
const isNoColor = navigator !== void 0 && navigator.userAgent === "Cloudflare-Workers" ? await (async () => {
|
||||
try {
|
||||
return "NO_COLOR" in ((await import(cfWorkers)).env ?? {});
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
})() : !getColorEnabled();
|
||||
return !isNoColor;
|
||||
}
|
||||
export {
|
||||
getColorEnabled,
|
||||
getColorEnabledAsync
|
||||
};
|
||||
5
_node_modules/hono/dist/utils/compress.js
generated
vendored
Normal file
5
_node_modules/hono/dist/utils/compress.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
// src/utils/compress.ts
|
||||
var COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/(?!event-stream(?:[;\s]|$))[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
|
||||
export {
|
||||
COMPRESSIBLE_CONTENT_TYPE_REGEX
|
||||
};
|
||||
39
_node_modules/hono/dist/utils/concurrent.js
generated
vendored
Normal file
39
_node_modules/hono/dist/utils/concurrent.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
// src/utils/concurrent.ts
|
||||
var DEFAULT_CONCURRENCY = 1024;
|
||||
var createPool = ({
|
||||
concurrency,
|
||||
interval
|
||||
} = {}) => {
|
||||
concurrency ||= DEFAULT_CONCURRENCY;
|
||||
if (concurrency === Infinity) {
|
||||
return {
|
||||
run: async (fn) => fn()
|
||||
};
|
||||
}
|
||||
const pool = /* @__PURE__ */ new Set();
|
||||
const run = async (fn, promise, resolve) => {
|
||||
if (pool.size >= concurrency) {
|
||||
promise ||= new Promise((r) => resolve = r);
|
||||
setTimeout(() => run(fn, promise, resolve));
|
||||
return promise;
|
||||
}
|
||||
const marker = {};
|
||||
pool.add(marker);
|
||||
const result = await fn();
|
||||
if (interval) {
|
||||
setTimeout(() => pool.delete(marker), interval);
|
||||
} else {
|
||||
pool.delete(marker);
|
||||
}
|
||||
if (resolve) {
|
||||
resolve(result);
|
||||
return promise;
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
};
|
||||
return { run };
|
||||
};
|
||||
export {
|
||||
createPool
|
||||
};
|
||||
5
_node_modules/hono/dist/utils/constants.js
generated
vendored
Normal file
5
_node_modules/hono/dist/utils/constants.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
// src/utils/constants.ts
|
||||
var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
|
||||
export {
|
||||
COMPOSED_HANDLER
|
||||
};
|
||||
147
_node_modules/hono/dist/utils/cookie.js
generated
vendored
Normal file
147
_node_modules/hono/dist/utils/cookie.js
generated
vendored
Normal file
@@ -0,0 +1,147 @@
|
||||
// src/utils/cookie.ts
|
||||
import { decodeURIComponent_, tryDecode } from "./url.js";
|
||||
var algorithm = { name: "HMAC", hash: "SHA-256" };
|
||||
var getCryptoKey = async (secret) => {
|
||||
const secretBuf = typeof secret === "string" ? new TextEncoder().encode(secret) : secret;
|
||||
return await crypto.subtle.importKey("raw", secretBuf, algorithm, false, ["sign", "verify"]);
|
||||
};
|
||||
var makeSignature = async (value, secret) => {
|
||||
const key = await getCryptoKey(secret);
|
||||
const signature = await crypto.subtle.sign(algorithm.name, key, new TextEncoder().encode(value));
|
||||
return btoa(String.fromCharCode(...new Uint8Array(signature)));
|
||||
};
|
||||
var verifySignature = async (base64Signature, value, secret) => {
|
||||
try {
|
||||
const signatureBinStr = atob(base64Signature);
|
||||
const signature = new Uint8Array(signatureBinStr.length);
|
||||
for (let i = 0, len = signatureBinStr.length; i < len; i++) {
|
||||
signature[i] = signatureBinStr.charCodeAt(i);
|
||||
}
|
||||
return await crypto.subtle.verify(algorithm, secret, signature, new TextEncoder().encode(value));
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
var validCookieNameRegEx = /^[\w!#$%&'*.^`|~+-]+$/;
|
||||
var validCookieValueRegEx = /^[ !#-:<-[\]-~]*$/;
|
||||
var parse = (cookie, name) => {
|
||||
if (name && cookie.indexOf(name) === -1) {
|
||||
return {};
|
||||
}
|
||||
const pairs = cookie.trim().split(";");
|
||||
const parsedCookie = {};
|
||||
for (let pairStr of pairs) {
|
||||
pairStr = pairStr.trim();
|
||||
const valueStartPos = pairStr.indexOf("=");
|
||||
if (valueStartPos === -1) {
|
||||
continue;
|
||||
}
|
||||
const cookieName = pairStr.substring(0, valueStartPos).trim();
|
||||
if (name && name !== cookieName || !validCookieNameRegEx.test(cookieName)) {
|
||||
continue;
|
||||
}
|
||||
let cookieValue = pairStr.substring(valueStartPos + 1).trim();
|
||||
if (cookieValue.startsWith('"') && cookieValue.endsWith('"')) {
|
||||
cookieValue = cookieValue.slice(1, -1);
|
||||
}
|
||||
if (validCookieValueRegEx.test(cookieValue)) {
|
||||
parsedCookie[cookieName] = cookieValue.indexOf("%") !== -1 ? tryDecode(cookieValue, decodeURIComponent_) : cookieValue;
|
||||
if (name) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return parsedCookie;
|
||||
};
|
||||
var parseSigned = async (cookie, secret, name) => {
|
||||
const parsedCookie = {};
|
||||
const secretKey = await getCryptoKey(secret);
|
||||
for (const [key, value] of Object.entries(parse(cookie, name))) {
|
||||
const signatureStartPos = value.lastIndexOf(".");
|
||||
if (signatureStartPos < 1) {
|
||||
continue;
|
||||
}
|
||||
const signedValue = value.substring(0, signatureStartPos);
|
||||
const signature = value.substring(signatureStartPos + 1);
|
||||
if (signature.length !== 44 || !signature.endsWith("=")) {
|
||||
continue;
|
||||
}
|
||||
const isVerified = await verifySignature(signature, signedValue, secretKey);
|
||||
parsedCookie[key] = isVerified ? signedValue : false;
|
||||
}
|
||||
return parsedCookie;
|
||||
};
|
||||
var _serialize = (name, value, opt = {}) => {
|
||||
let cookie = `${name}=${value}`;
|
||||
if (name.startsWith("__Secure-") && !opt.secure) {
|
||||
throw new Error("__Secure- Cookie must have Secure attributes");
|
||||
}
|
||||
if (name.startsWith("__Host-")) {
|
||||
if (!opt.secure) {
|
||||
throw new Error("__Host- Cookie must have Secure attributes");
|
||||
}
|
||||
if (opt.path !== "/") {
|
||||
throw new Error('__Host- Cookie must have Path attributes with "/"');
|
||||
}
|
||||
if (opt.domain) {
|
||||
throw new Error("__Host- Cookie must not have Domain attributes");
|
||||
}
|
||||
}
|
||||
if (opt && typeof opt.maxAge === "number" && opt.maxAge >= 0) {
|
||||
if (opt.maxAge > 3456e4) {
|
||||
throw new Error(
|
||||
"Cookies Max-Age SHOULD NOT be greater than 400 days (34560000 seconds) in duration."
|
||||
);
|
||||
}
|
||||
cookie += `; Max-Age=${opt.maxAge | 0}`;
|
||||
}
|
||||
if (opt.domain && opt.prefix !== "host") {
|
||||
cookie += `; Domain=${opt.domain}`;
|
||||
}
|
||||
if (opt.path) {
|
||||
cookie += `; Path=${opt.path}`;
|
||||
}
|
||||
if (opt.expires) {
|
||||
if (opt.expires.getTime() - Date.now() > 3456e7) {
|
||||
throw new Error(
|
||||
"Cookies Expires SHOULD NOT be greater than 400 days (34560000 seconds) in the future."
|
||||
);
|
||||
}
|
||||
cookie += `; Expires=${opt.expires.toUTCString()}`;
|
||||
}
|
||||
if (opt.httpOnly) {
|
||||
cookie += "; HttpOnly";
|
||||
}
|
||||
if (opt.secure) {
|
||||
cookie += "; Secure";
|
||||
}
|
||||
if (opt.sameSite) {
|
||||
cookie += `; SameSite=${opt.sameSite.charAt(0).toUpperCase() + opt.sameSite.slice(1)}`;
|
||||
}
|
||||
if (opt.priority) {
|
||||
cookie += `; Priority=${opt.priority.charAt(0).toUpperCase() + opt.priority.slice(1)}`;
|
||||
}
|
||||
if (opt.partitioned) {
|
||||
if (!opt.secure) {
|
||||
throw new Error("Partitioned Cookie must have Secure attributes");
|
||||
}
|
||||
cookie += "; Partitioned";
|
||||
}
|
||||
return cookie;
|
||||
};
|
||||
var serialize = (name, value, opt) => {
|
||||
value = encodeURIComponent(value);
|
||||
return _serialize(name, value, opt);
|
||||
};
|
||||
var serializeSigned = async (name, value, secret, opt = {}) => {
|
||||
const signature = await makeSignature(value, secret);
|
||||
value = `${value}.${signature}`;
|
||||
value = encodeURIComponent(value);
|
||||
return _serialize(name, value, opt);
|
||||
};
|
||||
export {
|
||||
parse,
|
||||
parseSigned,
|
||||
serialize,
|
||||
serializeSigned
|
||||
};
|
||||
44
_node_modules/hono/dist/utils/crypto.js
generated
vendored
Normal file
44
_node_modules/hono/dist/utils/crypto.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
// src/utils/crypto.ts
|
||||
var sha256 = async (data) => {
|
||||
const algorithm = { name: "SHA-256", alias: "sha256" };
|
||||
const hash = await createHash(data, algorithm);
|
||||
return hash;
|
||||
};
|
||||
var sha1 = async (data) => {
|
||||
const algorithm = { name: "SHA-1", alias: "sha1" };
|
||||
const hash = await createHash(data, algorithm);
|
||||
return hash;
|
||||
};
|
||||
var md5 = async (data) => {
|
||||
const algorithm = { name: "MD5", alias: "md5" };
|
||||
const hash = await createHash(data, algorithm);
|
||||
return hash;
|
||||
};
|
||||
var createHash = async (data, algorithm) => {
|
||||
let sourceBuffer;
|
||||
if (ArrayBuffer.isView(data) || data instanceof ArrayBuffer) {
|
||||
sourceBuffer = data;
|
||||
} else {
|
||||
if (typeof data === "object") {
|
||||
data = JSON.stringify(data);
|
||||
}
|
||||
sourceBuffer = new TextEncoder().encode(String(data));
|
||||
}
|
||||
if (crypto && crypto.subtle) {
|
||||
const buffer = await crypto.subtle.digest(
|
||||
{
|
||||
name: algorithm.name
|
||||
},
|
||||
sourceBuffer
|
||||
);
|
||||
const hash = Array.prototype.map.call(new Uint8Array(buffer), (x) => ("00" + x.toString(16)).slice(-2)).join("");
|
||||
return hash;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
export {
|
||||
createHash,
|
||||
md5,
|
||||
sha1,
|
||||
sha256
|
||||
};
|
||||
29
_node_modules/hono/dist/utils/encode.js
generated
vendored
Normal file
29
_node_modules/hono/dist/utils/encode.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
// src/utils/encode.ts
|
||||
var decodeBase64Url = (str) => {
|
||||
return decodeBase64(str.replace(/_|-/g, (m) => ({ _: "/", "-": "+" })[m] ?? m));
|
||||
};
|
||||
var encodeBase64Url = (buf) => encodeBase64(buf).replace(/\/|\+/g, (m) => ({ "/": "_", "+": "-" })[m] ?? m);
|
||||
var encodeBase64 = (buf) => {
|
||||
let binary = "";
|
||||
const bytes = new Uint8Array(buf);
|
||||
for (let i = 0, len = bytes.length; i < len; i++) {
|
||||
binary += String.fromCharCode(bytes[i]);
|
||||
}
|
||||
return btoa(binary);
|
||||
};
|
||||
var decodeBase64 = (str) => {
|
||||
const binary = atob(str);
|
||||
const bytes = new Uint8Array(new ArrayBuffer(binary.length));
|
||||
const half = binary.length / 2;
|
||||
for (let i = 0, j = binary.length - 1; i <= half; i++, j--) {
|
||||
bytes[i] = binary.charCodeAt(i);
|
||||
bytes[j] = binary.charCodeAt(j);
|
||||
}
|
||||
return bytes;
|
||||
};
|
||||
export {
|
||||
decodeBase64,
|
||||
decodeBase64Url,
|
||||
encodeBase64,
|
||||
encodeBase64Url
|
||||
};
|
||||
35
_node_modules/hono/dist/utils/filepath.js
generated
vendored
Normal file
35
_node_modules/hono/dist/utils/filepath.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
// src/utils/filepath.ts
|
||||
var getFilePath = (options) => {
|
||||
let filename = options.filename;
|
||||
const defaultDocument = options.defaultDocument || "index.html";
|
||||
if (filename.endsWith("/")) {
|
||||
filename = filename.concat(defaultDocument);
|
||||
} else if (!filename.match(/\.[a-zA-Z0-9_-]+$/)) {
|
||||
filename = filename.concat("/" + defaultDocument);
|
||||
}
|
||||
const path = getFilePathWithoutDefaultDocument({
|
||||
root: options.root,
|
||||
filename
|
||||
});
|
||||
return path;
|
||||
};
|
||||
var getFilePathWithoutDefaultDocument = (options) => {
|
||||
let root = options.root || "";
|
||||
let filename = options.filename;
|
||||
if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) {
|
||||
return;
|
||||
}
|
||||
filename = filename.replace(/^\.?[\/\\]/, "");
|
||||
filename = filename.replace(/\\/, "/");
|
||||
root = root.replace(/\/$/, "");
|
||||
let path = root ? root + "/" + filename : filename;
|
||||
path = path.replace(/^\.?\//, "");
|
||||
if (root[0] !== "/" && path[0] === "/") {
|
||||
return;
|
||||
}
|
||||
return path;
|
||||
};
|
||||
export {
|
||||
getFilePath,
|
||||
getFilePathWithoutDefaultDocument
|
||||
};
|
||||
13
_node_modules/hono/dist/utils/handler.js
generated
vendored
Normal file
13
_node_modules/hono/dist/utils/handler.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
// src/utils/handler.ts
|
||||
import { COMPOSED_HANDLER } from "./constants.js";
|
||||
var isMiddleware = (handler) => handler.length > 1;
|
||||
var findTargetHandler = (handler) => {
|
||||
return handler[COMPOSED_HANDLER] ? (
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
findTargetHandler(handler[COMPOSED_HANDLER])
|
||||
) : handler;
|
||||
};
|
||||
export {
|
||||
findTargetHandler,
|
||||
isMiddleware
|
||||
};
|
||||
0
_node_modules/hono/dist/utils/headers.js
generated
vendored
Normal file
0
_node_modules/hono/dist/utils/headers.js
generated
vendored
Normal file
123
_node_modules/hono/dist/utils/html.js
generated
vendored
Normal file
123
_node_modules/hono/dist/utils/html.js
generated
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
// src/utils/html.ts
|
||||
var HtmlEscapedCallbackPhase = {
|
||||
Stringify: 1,
|
||||
BeforeStream: 2,
|
||||
Stream: 3
|
||||
};
|
||||
var raw = (value, callbacks) => {
|
||||
const escapedString = new String(value);
|
||||
escapedString.isEscaped = true;
|
||||
escapedString.callbacks = callbacks;
|
||||
return escapedString;
|
||||
};
|
||||
var escapeRe = /[&<>'"]/;
|
||||
var stringBufferToString = async (buffer, callbacks) => {
|
||||
let str = "";
|
||||
callbacks ||= [];
|
||||
const resolvedBuffer = await Promise.all(buffer);
|
||||
for (let i = resolvedBuffer.length - 1; ; i--) {
|
||||
str += resolvedBuffer[i];
|
||||
i--;
|
||||
if (i < 0) {
|
||||
break;
|
||||
}
|
||||
let r = resolvedBuffer[i];
|
||||
if (typeof r === "object") {
|
||||
callbacks.push(...r.callbacks || []);
|
||||
}
|
||||
const isEscaped = r.isEscaped;
|
||||
r = await (typeof r === "object" ? r.toString() : r);
|
||||
if (typeof r === "object") {
|
||||
callbacks.push(...r.callbacks || []);
|
||||
}
|
||||
if (r.isEscaped ?? isEscaped) {
|
||||
str += r;
|
||||
} else {
|
||||
const buf = [str];
|
||||
escapeToBuffer(r, buf);
|
||||
str = buf[0];
|
||||
}
|
||||
}
|
||||
return raw(str, callbacks);
|
||||
};
|
||||
var escapeToBuffer = (str, buffer) => {
|
||||
const match = str.search(escapeRe);
|
||||
if (match === -1) {
|
||||
buffer[0] += str;
|
||||
return;
|
||||
}
|
||||
let escape;
|
||||
let index;
|
||||
let lastIndex = 0;
|
||||
for (index = match; index < str.length; index++) {
|
||||
switch (str.charCodeAt(index)) {
|
||||
case 34:
|
||||
escape = """;
|
||||
break;
|
||||
case 39:
|
||||
escape = "'";
|
||||
break;
|
||||
case 38:
|
||||
escape = "&";
|
||||
break;
|
||||
case 60:
|
||||
escape = "<";
|
||||
break;
|
||||
case 62:
|
||||
escape = ">";
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
buffer[0] += str.substring(lastIndex, index) + escape;
|
||||
lastIndex = index + 1;
|
||||
}
|
||||
buffer[0] += str.substring(lastIndex, index);
|
||||
};
|
||||
var resolveCallbackSync = (str) => {
|
||||
const callbacks = str.callbacks;
|
||||
if (!callbacks?.length) {
|
||||
return str;
|
||||
}
|
||||
const buffer = [str];
|
||||
const context = {};
|
||||
callbacks.forEach((c) => c({ phase: HtmlEscapedCallbackPhase.Stringify, buffer, context }));
|
||||
return buffer[0];
|
||||
};
|
||||
var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
|
||||
if (typeof str === "object" && !(str instanceof String)) {
|
||||
if (!(str instanceof Promise)) {
|
||||
str = str.toString();
|
||||
}
|
||||
if (str instanceof Promise) {
|
||||
str = await str;
|
||||
}
|
||||
}
|
||||
const callbacks = str.callbacks;
|
||||
if (!callbacks?.length) {
|
||||
return Promise.resolve(str);
|
||||
}
|
||||
if (buffer) {
|
||||
buffer[0] += str;
|
||||
} else {
|
||||
buffer = [str];
|
||||
}
|
||||
const resStr = Promise.all(callbacks.map((c) => c({ phase, buffer, context }))).then(
|
||||
(res) => Promise.all(
|
||||
res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer))
|
||||
).then(() => buffer[0])
|
||||
);
|
||||
if (preserveCallbacks) {
|
||||
return raw(await resStr, callbacks);
|
||||
} else {
|
||||
return resStr;
|
||||
}
|
||||
};
|
||||
export {
|
||||
HtmlEscapedCallbackPhase,
|
||||
escapeToBuffer,
|
||||
raw,
|
||||
resolveCallback,
|
||||
resolveCallbackSync,
|
||||
stringBufferToString
|
||||
};
|
||||
0
_node_modules/hono/dist/utils/http-status.js
generated
vendored
Normal file
0
_node_modules/hono/dist/utils/http-status.js
generated
vendored
Normal file
101
_node_modules/hono/dist/utils/ipaddr.js
generated
vendored
Normal file
101
_node_modules/hono/dist/utils/ipaddr.js
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
// src/utils/ipaddr.ts
|
||||
var expandIPv6 = (ipV6) => {
|
||||
const sections = ipV6.split(":");
|
||||
if (IPV4_REGEX.test(sections.at(-1))) {
|
||||
sections.splice(
|
||||
-1,
|
||||
1,
|
||||
...convertIPv6BinaryToString(convertIPv4ToBinary(sections.at(-1))).substring(2).split(":")
|
||||
// => ['7f00', '0001']
|
||||
);
|
||||
}
|
||||
for (let i = 0; i < sections.length; i++) {
|
||||
const node = sections[i];
|
||||
if (node !== "") {
|
||||
sections[i] = node.padStart(4, "0");
|
||||
} else {
|
||||
sections[i + 1] === "" && sections.splice(i + 1, 1);
|
||||
sections[i] = new Array(8 - sections.length + 1).fill("0000").join(":");
|
||||
}
|
||||
}
|
||||
return sections.join(":");
|
||||
};
|
||||
var IPV4_REGEX = /^[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}$/;
|
||||
var distinctRemoteAddr = (remoteAddr) => {
|
||||
if (IPV4_REGEX.test(remoteAddr)) {
|
||||
return "IPv4";
|
||||
}
|
||||
if (remoteAddr.includes(":")) {
|
||||
return "IPv6";
|
||||
}
|
||||
};
|
||||
var convertIPv4ToBinary = (ipv4) => {
|
||||
const parts = ipv4.split(".");
|
||||
let result = 0n;
|
||||
for (let i = 0; i < 4; i++) {
|
||||
result <<= 8n;
|
||||
result += BigInt(parts[i]);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
var convertIPv6ToBinary = (ipv6) => {
|
||||
const sections = expandIPv6(ipv6).split(":");
|
||||
let result = 0n;
|
||||
for (let i = 0; i < 8; i++) {
|
||||
result <<= 16n;
|
||||
result += BigInt(parseInt(sections[i], 16));
|
||||
}
|
||||
return result;
|
||||
};
|
||||
var convertIPv4BinaryToString = (ipV4) => {
|
||||
const sections = [];
|
||||
for (let i = 0; i < 4; i++) {
|
||||
sections.push(ipV4 >> BigInt(8 * (3 - i)) & 0xffn);
|
||||
}
|
||||
return sections.join(".");
|
||||
};
|
||||
var convertIPv6BinaryToString = (ipV6) => {
|
||||
if (ipV6 >> 32n === 0xffffn) {
|
||||
return `::ffff:${convertIPv4BinaryToString(ipV6 & 0xffffffffn)}`;
|
||||
}
|
||||
const sections = [];
|
||||
for (let i = 0; i < 8; i++) {
|
||||
sections.push((ipV6 >> BigInt(16 * (7 - i)) & 0xffffn).toString(16));
|
||||
}
|
||||
let currentZeroStart = -1;
|
||||
let maxZeroStart = -1;
|
||||
let maxZeroEnd = -1;
|
||||
for (let i = 0; i < 8; i++) {
|
||||
if (sections[i] === "0") {
|
||||
if (currentZeroStart === -1) {
|
||||
currentZeroStart = i;
|
||||
}
|
||||
} else {
|
||||
if (currentZeroStart > -1) {
|
||||
if (i - currentZeroStart > maxZeroEnd - maxZeroStart) {
|
||||
maxZeroStart = currentZeroStart;
|
||||
maxZeroEnd = i;
|
||||
}
|
||||
currentZeroStart = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (currentZeroStart > -1) {
|
||||
if (8 - currentZeroStart > maxZeroEnd - maxZeroStart) {
|
||||
maxZeroStart = currentZeroStart;
|
||||
maxZeroEnd = 8;
|
||||
}
|
||||
}
|
||||
if (maxZeroStart !== -1) {
|
||||
sections.splice(maxZeroStart, maxZeroEnd - maxZeroStart, ":");
|
||||
}
|
||||
return sections.join(":").replace(/:{2,}/g, "::");
|
||||
};
|
||||
export {
|
||||
convertIPv4BinaryToString,
|
||||
convertIPv4ToBinary,
|
||||
convertIPv6BinaryToString,
|
||||
convertIPv6ToBinary,
|
||||
distinctRemoteAddr,
|
||||
expandIPv6
|
||||
};
|
||||
6
_node_modules/hono/dist/utils/jwt/index.js
generated
vendored
Normal file
6
_node_modules/hono/dist/utils/jwt/index.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
// src/utils/jwt/index.ts
|
||||
import { decode, sign, verify, verifyWithJwks } from "./jwt.js";
|
||||
var Jwt = { sign, verify, decode, verifyWithJwks };
|
||||
export {
|
||||
Jwt
|
||||
};
|
||||
20
_node_modules/hono/dist/utils/jwt/jwa.js
generated
vendored
Normal file
20
_node_modules/hono/dist/utils/jwt/jwa.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
// src/utils/jwt/jwa.ts
|
||||
var AlgorithmTypes = /* @__PURE__ */ ((AlgorithmTypes2) => {
|
||||
AlgorithmTypes2["HS256"] = "HS256";
|
||||
AlgorithmTypes2["HS384"] = "HS384";
|
||||
AlgorithmTypes2["HS512"] = "HS512";
|
||||
AlgorithmTypes2["RS256"] = "RS256";
|
||||
AlgorithmTypes2["RS384"] = "RS384";
|
||||
AlgorithmTypes2["RS512"] = "RS512";
|
||||
AlgorithmTypes2["PS256"] = "PS256";
|
||||
AlgorithmTypes2["PS384"] = "PS384";
|
||||
AlgorithmTypes2["PS512"] = "PS512";
|
||||
AlgorithmTypes2["ES256"] = "ES256";
|
||||
AlgorithmTypes2["ES384"] = "ES384";
|
||||
AlgorithmTypes2["ES512"] = "ES512";
|
||||
AlgorithmTypes2["EdDSA"] = "EdDSA";
|
||||
return AlgorithmTypes2;
|
||||
})(AlgorithmTypes || {});
|
||||
export {
|
||||
AlgorithmTypes
|
||||
};
|
||||
192
_node_modules/hono/dist/utils/jwt/jws.js
generated
vendored
Normal file
192
_node_modules/hono/dist/utils/jwt/jws.js
generated
vendored
Normal file
@@ -0,0 +1,192 @@
|
||||
// src/utils/jwt/jws.ts
|
||||
import { getRuntimeKey } from "../../helper/adapter/index.js";
|
||||
import { decodeBase64 } from "../encode.js";
|
||||
import { CryptoKeyUsage, JwtAlgorithmNotImplemented } from "./types.js";
|
||||
import { utf8Encoder } from "./utf8.js";
|
||||
async function signing(privateKey, alg, data) {
|
||||
const algorithm = getKeyAlgorithm(alg);
|
||||
const cryptoKey = await importPrivateKey(privateKey, algorithm);
|
||||
return await crypto.subtle.sign(algorithm, cryptoKey, data);
|
||||
}
|
||||
async function verifying(publicKey, alg, signature, data) {
|
||||
const algorithm = getKeyAlgorithm(alg);
|
||||
const cryptoKey = await importPublicKey(publicKey, algorithm);
|
||||
return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
|
||||
}
|
||||
function pemToBinary(pem) {
|
||||
return decodeBase64(pem.replace(/-+(BEGIN|END).*/g, "").replace(/\s/g, ""));
|
||||
}
|
||||
async function importPrivateKey(key, alg) {
|
||||
if (!crypto.subtle || !crypto.subtle.importKey) {
|
||||
throw new Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");
|
||||
}
|
||||
if (isCryptoKey(key)) {
|
||||
if (key.type !== "private" && key.type !== "secret") {
|
||||
throw new Error(
|
||||
`unexpected key type: CryptoKey.type is ${key.type}, expected private or secret`
|
||||
);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
const usages = [CryptoKeyUsage.Sign];
|
||||
if (typeof key === "object") {
|
||||
return await crypto.subtle.importKey("jwk", key, alg, false, usages);
|
||||
}
|
||||
if (key.includes("PRIVATE")) {
|
||||
return await crypto.subtle.importKey("pkcs8", pemToBinary(key), alg, false, usages);
|
||||
}
|
||||
return await crypto.subtle.importKey("raw", utf8Encoder.encode(key), alg, false, usages);
|
||||
}
|
||||
async function importPublicKey(key, alg) {
|
||||
if (!crypto.subtle || !crypto.subtle.importKey) {
|
||||
throw new Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");
|
||||
}
|
||||
if (isCryptoKey(key)) {
|
||||
if (key.type === "public" || key.type === "secret") {
|
||||
return key;
|
||||
}
|
||||
key = await exportPublicJwkFrom(key);
|
||||
}
|
||||
if (typeof key === "string" && key.includes("PRIVATE")) {
|
||||
const privateKey = await crypto.subtle.importKey("pkcs8", pemToBinary(key), alg, true, [
|
||||
CryptoKeyUsage.Sign
|
||||
]);
|
||||
key = await exportPublicJwkFrom(privateKey);
|
||||
}
|
||||
const usages = [CryptoKeyUsage.Verify];
|
||||
if (typeof key === "object") {
|
||||
return await crypto.subtle.importKey("jwk", key, alg, false, usages);
|
||||
}
|
||||
if (key.includes("PUBLIC")) {
|
||||
return await crypto.subtle.importKey("spki", pemToBinary(key), alg, false, usages);
|
||||
}
|
||||
return await crypto.subtle.importKey("raw", utf8Encoder.encode(key), alg, false, usages);
|
||||
}
|
||||
async function exportPublicJwkFrom(privateKey) {
|
||||
if (privateKey.type !== "private") {
|
||||
throw new Error(`unexpected key type: ${privateKey.type}`);
|
||||
}
|
||||
if (!privateKey.extractable) {
|
||||
throw new Error("unexpected private key is unextractable");
|
||||
}
|
||||
const jwk = await crypto.subtle.exportKey("jwk", privateKey);
|
||||
const { kty } = jwk;
|
||||
const { alg, e, n } = jwk;
|
||||
const { crv, x, y } = jwk;
|
||||
return { kty, alg, e, n, crv, x, y, key_ops: [CryptoKeyUsage.Verify] };
|
||||
}
|
||||
function getKeyAlgorithm(name) {
|
||||
switch (name) {
|
||||
case "HS256":
|
||||
return {
|
||||
name: "HMAC",
|
||||
hash: {
|
||||
name: "SHA-256"
|
||||
}
|
||||
};
|
||||
case "HS384":
|
||||
return {
|
||||
name: "HMAC",
|
||||
hash: {
|
||||
name: "SHA-384"
|
||||
}
|
||||
};
|
||||
case "HS512":
|
||||
return {
|
||||
name: "HMAC",
|
||||
hash: {
|
||||
name: "SHA-512"
|
||||
}
|
||||
};
|
||||
case "RS256":
|
||||
return {
|
||||
name: "RSASSA-PKCS1-v1_5",
|
||||
hash: {
|
||||
name: "SHA-256"
|
||||
}
|
||||
};
|
||||
case "RS384":
|
||||
return {
|
||||
name: "RSASSA-PKCS1-v1_5",
|
||||
hash: {
|
||||
name: "SHA-384"
|
||||
}
|
||||
};
|
||||
case "RS512":
|
||||
return {
|
||||
name: "RSASSA-PKCS1-v1_5",
|
||||
hash: {
|
||||
name: "SHA-512"
|
||||
}
|
||||
};
|
||||
case "PS256":
|
||||
return {
|
||||
name: "RSA-PSS",
|
||||
hash: {
|
||||
name: "SHA-256"
|
||||
},
|
||||
saltLength: 32
|
||||
// 256 >> 3
|
||||
};
|
||||
case "PS384":
|
||||
return {
|
||||
name: "RSA-PSS",
|
||||
hash: {
|
||||
name: "SHA-384"
|
||||
},
|
||||
saltLength: 48
|
||||
// 384 >> 3
|
||||
};
|
||||
case "PS512":
|
||||
return {
|
||||
name: "RSA-PSS",
|
||||
hash: {
|
||||
name: "SHA-512"
|
||||
},
|
||||
saltLength: 64
|
||||
// 512 >> 3,
|
||||
};
|
||||
case "ES256":
|
||||
return {
|
||||
name: "ECDSA",
|
||||
hash: {
|
||||
name: "SHA-256"
|
||||
},
|
||||
namedCurve: "P-256"
|
||||
};
|
||||
case "ES384":
|
||||
return {
|
||||
name: "ECDSA",
|
||||
hash: {
|
||||
name: "SHA-384"
|
||||
},
|
||||
namedCurve: "P-384"
|
||||
};
|
||||
case "ES512":
|
||||
return {
|
||||
name: "ECDSA",
|
||||
hash: {
|
||||
name: "SHA-512"
|
||||
},
|
||||
namedCurve: "P-521"
|
||||
};
|
||||
case "EdDSA":
|
||||
return {
|
||||
name: "Ed25519",
|
||||
namedCurve: "Ed25519"
|
||||
};
|
||||
default:
|
||||
throw new JwtAlgorithmNotImplemented(name);
|
||||
}
|
||||
}
|
||||
function isCryptoKey(key) {
|
||||
const runtime = getRuntimeKey();
|
||||
if (runtime === "node" && !!crypto.webcrypto) {
|
||||
return key instanceof crypto.webcrypto.CryptoKey;
|
||||
}
|
||||
return key instanceof CryptoKey;
|
||||
}
|
||||
export {
|
||||
signing,
|
||||
verifying
|
||||
};
|
||||
197
_node_modules/hono/dist/utils/jwt/jwt.js
generated
vendored
Normal file
197
_node_modules/hono/dist/utils/jwt/jwt.js
generated
vendored
Normal file
@@ -0,0 +1,197 @@
|
||||
// src/utils/jwt/jwt.ts
|
||||
import { decodeBase64Url, encodeBase64Url } from "../../utils/encode.js";
|
||||
import { AlgorithmTypes } from "./jwa.js";
|
||||
import { signing, verifying } from "./jws.js";
|
||||
import {
|
||||
JwtAlgorithmMismatch,
|
||||
JwtAlgorithmNotAllowed,
|
||||
JwtAlgorithmRequired,
|
||||
JwtHeaderInvalid,
|
||||
JwtHeaderRequiresKid,
|
||||
JwtPayloadRequiresAud,
|
||||
JwtSymmetricAlgorithmNotAllowed,
|
||||
JwtTokenAudience,
|
||||
JwtTokenExpired,
|
||||
JwtTokenInvalid,
|
||||
JwtTokenIssuedAt,
|
||||
JwtTokenIssuer,
|
||||
JwtTokenNotBefore,
|
||||
JwtTokenSignatureMismatched
|
||||
} from "./types.js";
|
||||
import { utf8Decoder, utf8Encoder } from "./utf8.js";
|
||||
var encodeJwtPart = (part) => encodeBase64Url(utf8Encoder.encode(JSON.stringify(part)).buffer).replace(/=/g, "");
|
||||
var encodeSignaturePart = (buf) => encodeBase64Url(buf).replace(/=/g, "");
|
||||
var decodeJwtPart = (part) => JSON.parse(utf8Decoder.decode(decodeBase64Url(part)));
|
||||
function isTokenHeader(obj) {
|
||||
if (typeof obj === "object" && obj !== null) {
|
||||
const objWithAlg = obj;
|
||||
return "alg" in objWithAlg && Object.values(AlgorithmTypes).includes(objWithAlg.alg) && (!("typ" in objWithAlg) || objWithAlg.typ === "JWT");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
var sign = async (payload, privateKey, alg = "HS256") => {
|
||||
const encodedPayload = encodeJwtPart(payload);
|
||||
let encodedHeader;
|
||||
if (typeof privateKey === "object" && "alg" in privateKey) {
|
||||
alg = privateKey.alg;
|
||||
encodedHeader = encodeJwtPart({ alg, typ: "JWT", kid: privateKey.kid });
|
||||
} else {
|
||||
encodedHeader = encodeJwtPart({ alg, typ: "JWT" });
|
||||
}
|
||||
const partialToken = `${encodedHeader}.${encodedPayload}`;
|
||||
const signaturePart = await signing(privateKey, alg, utf8Encoder.encode(partialToken));
|
||||
const signature = encodeSignaturePart(signaturePart);
|
||||
return `${partialToken}.${signature}`;
|
||||
};
|
||||
var verify = async (token, publicKey, algOrOptions) => {
|
||||
if (!algOrOptions) {
|
||||
throw new JwtAlgorithmRequired();
|
||||
}
|
||||
const {
|
||||
alg,
|
||||
iss,
|
||||
nbf = true,
|
||||
exp = true,
|
||||
iat = true,
|
||||
aud
|
||||
} = typeof algOrOptions === "string" ? { alg: algOrOptions } : algOrOptions;
|
||||
if (!alg) {
|
||||
throw new JwtAlgorithmRequired();
|
||||
}
|
||||
const tokenParts = token.split(".");
|
||||
if (tokenParts.length !== 3) {
|
||||
throw new JwtTokenInvalid(token);
|
||||
}
|
||||
const { header, payload } = decode(token);
|
||||
if (!isTokenHeader(header)) {
|
||||
throw new JwtHeaderInvalid(header);
|
||||
}
|
||||
if (header.alg !== alg) {
|
||||
throw new JwtAlgorithmMismatch(alg, header.alg);
|
||||
}
|
||||
const now = Date.now() / 1e3 | 0;
|
||||
if (nbf && payload.nbf && payload.nbf > now) {
|
||||
throw new JwtTokenNotBefore(token);
|
||||
}
|
||||
if (exp && payload.exp && payload.exp <= now) {
|
||||
throw new JwtTokenExpired(token);
|
||||
}
|
||||
if (iat && payload.iat && now < payload.iat) {
|
||||
throw new JwtTokenIssuedAt(now, payload.iat);
|
||||
}
|
||||
if (iss) {
|
||||
if (!payload.iss) {
|
||||
throw new JwtTokenIssuer(iss, null);
|
||||
}
|
||||
if (typeof iss === "string" && payload.iss !== iss) {
|
||||
throw new JwtTokenIssuer(iss, payload.iss);
|
||||
}
|
||||
if (iss instanceof RegExp && !iss.test(payload.iss)) {
|
||||
throw new JwtTokenIssuer(iss, payload.iss);
|
||||
}
|
||||
}
|
||||
if (aud) {
|
||||
if (!payload.aud) {
|
||||
throw new JwtPayloadRequiresAud(payload);
|
||||
}
|
||||
const audiences = Array.isArray(payload.aud) ? payload.aud : [payload.aud];
|
||||
const matched = audiences.some(
|
||||
(payloadAud) => aud instanceof RegExp ? aud.test(payloadAud) : typeof aud === "string" ? payloadAud === aud : Array.isArray(aud) && aud.includes(payloadAud)
|
||||
);
|
||||
if (!matched) {
|
||||
throw new JwtTokenAudience(aud, payload.aud);
|
||||
}
|
||||
}
|
||||
const headerPayload = token.substring(0, token.lastIndexOf("."));
|
||||
const verified = await verifying(
|
||||
publicKey,
|
||||
alg,
|
||||
decodeBase64Url(tokenParts[2]),
|
||||
utf8Encoder.encode(headerPayload)
|
||||
);
|
||||
if (!verified) {
|
||||
throw new JwtTokenSignatureMismatched(token);
|
||||
}
|
||||
return payload;
|
||||
};
|
||||
var symmetricAlgorithms = [
|
||||
AlgorithmTypes.HS256,
|
||||
AlgorithmTypes.HS384,
|
||||
AlgorithmTypes.HS512
|
||||
];
|
||||
var verifyWithJwks = async (token, options, init) => {
|
||||
const verifyOpts = options.verification || {};
|
||||
const header = decodeHeader(token);
|
||||
if (!isTokenHeader(header)) {
|
||||
throw new JwtHeaderInvalid(header);
|
||||
}
|
||||
if (!header.kid) {
|
||||
throw new JwtHeaderRequiresKid(header);
|
||||
}
|
||||
if (symmetricAlgorithms.includes(header.alg)) {
|
||||
throw new JwtSymmetricAlgorithmNotAllowed(header.alg);
|
||||
}
|
||||
if (!options.allowedAlgorithms.includes(header.alg)) {
|
||||
throw new JwtAlgorithmNotAllowed(header.alg, options.allowedAlgorithms);
|
||||
}
|
||||
if (options.jwks_uri) {
|
||||
const response = await fetch(options.jwks_uri, init);
|
||||
if (!response.ok) {
|
||||
throw new Error(`failed to fetch JWKS from ${options.jwks_uri}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
if (!data.keys) {
|
||||
throw new Error('invalid JWKS response. "keys" field is missing');
|
||||
}
|
||||
if (!Array.isArray(data.keys)) {
|
||||
throw new Error('invalid JWKS response. "keys" field is not an array');
|
||||
}
|
||||
if (options.keys) {
|
||||
options.keys.push(...data.keys);
|
||||
} else {
|
||||
options.keys = data.keys;
|
||||
}
|
||||
} else if (!options.keys) {
|
||||
throw new Error('verifyWithJwks requires options for either "keys" or "jwks_uri" or both');
|
||||
}
|
||||
const matchingKey = options.keys.find((key) => key.kid === header.kid);
|
||||
if (!matchingKey) {
|
||||
throw new JwtTokenInvalid(token);
|
||||
}
|
||||
if (matchingKey.alg && matchingKey.alg !== header.alg) {
|
||||
throw new JwtAlgorithmMismatch(matchingKey.alg, header.alg);
|
||||
}
|
||||
return await verify(token, matchingKey, {
|
||||
alg: header.alg,
|
||||
...verifyOpts
|
||||
});
|
||||
};
|
||||
var decode = (token) => {
|
||||
try {
|
||||
const [h, p] = token.split(".");
|
||||
const header = decodeJwtPart(h);
|
||||
const payload = decodeJwtPart(p);
|
||||
return {
|
||||
header,
|
||||
payload
|
||||
};
|
||||
} catch {
|
||||
throw new JwtTokenInvalid(token);
|
||||
}
|
||||
};
|
||||
var decodeHeader = (token) => {
|
||||
try {
|
||||
const [h] = token.split(".");
|
||||
return decodeJwtPart(h);
|
||||
} catch {
|
||||
throw new JwtTokenInvalid(token);
|
||||
}
|
||||
};
|
||||
export {
|
||||
decode,
|
||||
decodeHeader,
|
||||
isTokenHeader,
|
||||
sign,
|
||||
verify,
|
||||
verifyWithJwks
|
||||
};
|
||||
124
_node_modules/hono/dist/utils/jwt/types.js
generated
vendored
Normal file
124
_node_modules/hono/dist/utils/jwt/types.js
generated
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
// src/utils/jwt/types.ts
|
||||
var JwtAlgorithmNotImplemented = class extends Error {
|
||||
constructor(alg) {
|
||||
super(`${alg} is not an implemented algorithm`);
|
||||
this.name = "JwtAlgorithmNotImplemented";
|
||||
}
|
||||
};
|
||||
var JwtAlgorithmRequired = class extends Error {
|
||||
constructor() {
|
||||
super('JWT verification requires "alg" option to be specified');
|
||||
this.name = "JwtAlgorithmRequired";
|
||||
}
|
||||
};
|
||||
var JwtAlgorithmMismatch = class extends Error {
|
||||
constructor(expected, actual) {
|
||||
super(`JWT algorithm mismatch: expected "${expected}", got "${actual}"`);
|
||||
this.name = "JwtAlgorithmMismatch";
|
||||
}
|
||||
};
|
||||
var JwtTokenInvalid = class extends Error {
|
||||
constructor(token) {
|
||||
super(`invalid JWT token: ${token}`);
|
||||
this.name = "JwtTokenInvalid";
|
||||
}
|
||||
};
|
||||
var JwtTokenNotBefore = class extends Error {
|
||||
constructor(token) {
|
||||
super(`token (${token}) is being used before it's valid`);
|
||||
this.name = "JwtTokenNotBefore";
|
||||
}
|
||||
};
|
||||
var JwtTokenExpired = class extends Error {
|
||||
constructor(token) {
|
||||
super(`token (${token}) expired`);
|
||||
this.name = "JwtTokenExpired";
|
||||
}
|
||||
};
|
||||
var JwtTokenIssuedAt = class extends Error {
|
||||
constructor(currentTimestamp, iat) {
|
||||
super(
|
||||
`Invalid "iat" claim, must be a valid number lower than "${currentTimestamp}" (iat: "${iat}")`
|
||||
);
|
||||
this.name = "JwtTokenIssuedAt";
|
||||
}
|
||||
};
|
||||
var JwtTokenIssuer = class extends Error {
|
||||
constructor(expected, iss) {
|
||||
super(`expected issuer "${expected}", got ${iss ? `"${iss}"` : "none"} `);
|
||||
this.name = "JwtTokenIssuer";
|
||||
}
|
||||
};
|
||||
var JwtHeaderInvalid = class extends Error {
|
||||
constructor(header) {
|
||||
super(`jwt header is invalid: ${JSON.stringify(header)}`);
|
||||
this.name = "JwtHeaderInvalid";
|
||||
}
|
||||
};
|
||||
var JwtHeaderRequiresKid = class extends Error {
|
||||
constructor(header) {
|
||||
super(`required "kid" in jwt header: ${JSON.stringify(header)}`);
|
||||
this.name = "JwtHeaderRequiresKid";
|
||||
}
|
||||
};
|
||||
var JwtSymmetricAlgorithmNotAllowed = class extends Error {
|
||||
constructor(alg) {
|
||||
super(`symmetric algorithm "${alg}" is not allowed for JWK verification`);
|
||||
this.name = "JwtSymmetricAlgorithmNotAllowed";
|
||||
}
|
||||
};
|
||||
var JwtAlgorithmNotAllowed = class extends Error {
|
||||
constructor(alg, allowedAlgorithms) {
|
||||
super(`algorithm "${alg}" is not in the allowed list: [${allowedAlgorithms.join(", ")}]`);
|
||||
this.name = "JwtAlgorithmNotAllowed";
|
||||
}
|
||||
};
|
||||
var JwtTokenSignatureMismatched = class extends Error {
|
||||
constructor(token) {
|
||||
super(`token(${token}) signature mismatched`);
|
||||
this.name = "JwtTokenSignatureMismatched";
|
||||
}
|
||||
};
|
||||
var JwtPayloadRequiresAud = class extends Error {
|
||||
constructor(payload) {
|
||||
super(`required "aud" in jwt payload: ${JSON.stringify(payload)}`);
|
||||
this.name = "JwtPayloadRequiresAud";
|
||||
}
|
||||
};
|
||||
var JwtTokenAudience = class extends Error {
|
||||
constructor(expected, aud) {
|
||||
super(
|
||||
`expected audience "${Array.isArray(expected) ? expected.join(", ") : expected}", got "${aud}"`
|
||||
);
|
||||
this.name = "JwtTokenAudience";
|
||||
}
|
||||
};
|
||||
var CryptoKeyUsage = /* @__PURE__ */ ((CryptoKeyUsage2) => {
|
||||
CryptoKeyUsage2["Encrypt"] = "encrypt";
|
||||
CryptoKeyUsage2["Decrypt"] = "decrypt";
|
||||
CryptoKeyUsage2["Sign"] = "sign";
|
||||
CryptoKeyUsage2["Verify"] = "verify";
|
||||
CryptoKeyUsage2["DeriveKey"] = "deriveKey";
|
||||
CryptoKeyUsage2["DeriveBits"] = "deriveBits";
|
||||
CryptoKeyUsage2["WrapKey"] = "wrapKey";
|
||||
CryptoKeyUsage2["UnwrapKey"] = "unwrapKey";
|
||||
return CryptoKeyUsage2;
|
||||
})(CryptoKeyUsage || {});
|
||||
export {
|
||||
CryptoKeyUsage,
|
||||
JwtAlgorithmMismatch,
|
||||
JwtAlgorithmNotAllowed,
|
||||
JwtAlgorithmNotImplemented,
|
||||
JwtAlgorithmRequired,
|
||||
JwtHeaderInvalid,
|
||||
JwtHeaderRequiresKid,
|
||||
JwtPayloadRequiresAud,
|
||||
JwtSymmetricAlgorithmNotAllowed,
|
||||
JwtTokenAudience,
|
||||
JwtTokenExpired,
|
||||
JwtTokenInvalid,
|
||||
JwtTokenIssuedAt,
|
||||
JwtTokenIssuer,
|
||||
JwtTokenNotBefore,
|
||||
JwtTokenSignatureMismatched
|
||||
};
|
||||
7
_node_modules/hono/dist/utils/jwt/utf8.js
generated
vendored
Normal file
7
_node_modules/hono/dist/utils/jwt/utf8.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
// src/utils/jwt/utf8.ts
|
||||
var utf8Encoder = new TextEncoder();
|
||||
var utf8Decoder = new TextDecoder();
|
||||
export {
|
||||
utf8Decoder,
|
||||
utf8Encoder
|
||||
};
|
||||
84
_node_modules/hono/dist/utils/mime.js
generated
vendored
Normal file
84
_node_modules/hono/dist/utils/mime.js
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
// src/utils/mime.ts
|
||||
var getMimeType = (filename, mimes = baseMimes) => {
|
||||
const regexp = /\.([a-zA-Z0-9]+?)$/;
|
||||
const match = filename.match(regexp);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
let mimeType = mimes[match[1]];
|
||||
if (mimeType && mimeType.startsWith("text")) {
|
||||
mimeType += "; charset=utf-8";
|
||||
}
|
||||
return mimeType;
|
||||
};
|
||||
var getExtension = (mimeType) => {
|
||||
for (const ext in baseMimes) {
|
||||
if (baseMimes[ext] === mimeType) {
|
||||
return ext;
|
||||
}
|
||||
}
|
||||
};
|
||||
var _baseMimes = {
|
||||
aac: "audio/aac",
|
||||
avi: "video/x-msvideo",
|
||||
avif: "image/avif",
|
||||
av1: "video/av1",
|
||||
bin: "application/octet-stream",
|
||||
bmp: "image/bmp",
|
||||
css: "text/css",
|
||||
csv: "text/csv",
|
||||
eot: "application/vnd.ms-fontobject",
|
||||
epub: "application/epub+zip",
|
||||
gif: "image/gif",
|
||||
gz: "application/gzip",
|
||||
htm: "text/html",
|
||||
html: "text/html",
|
||||
ico: "image/x-icon",
|
||||
ics: "text/calendar",
|
||||
jpeg: "image/jpeg",
|
||||
jpg: "image/jpeg",
|
||||
js: "text/javascript",
|
||||
json: "application/json",
|
||||
jsonld: "application/ld+json",
|
||||
map: "application/json",
|
||||
mid: "audio/x-midi",
|
||||
midi: "audio/x-midi",
|
||||
mjs: "text/javascript",
|
||||
mp3: "audio/mpeg",
|
||||
mp4: "video/mp4",
|
||||
mpeg: "video/mpeg",
|
||||
oga: "audio/ogg",
|
||||
ogv: "video/ogg",
|
||||
ogx: "application/ogg",
|
||||
opus: "audio/opus",
|
||||
otf: "font/otf",
|
||||
pdf: "application/pdf",
|
||||
png: "image/png",
|
||||
rtf: "application/rtf",
|
||||
svg: "image/svg+xml",
|
||||
tif: "image/tiff",
|
||||
tiff: "image/tiff",
|
||||
ts: "video/mp2t",
|
||||
ttf: "font/ttf",
|
||||
txt: "text/plain",
|
||||
wasm: "application/wasm",
|
||||
webm: "video/webm",
|
||||
weba: "audio/webm",
|
||||
webmanifest: "application/manifest+json",
|
||||
webp: "image/webp",
|
||||
woff: "font/woff",
|
||||
woff2: "font/woff2",
|
||||
xhtml: "application/xhtml+xml",
|
||||
xml: "application/xml",
|
||||
zip: "application/zip",
|
||||
"3gp": "video/3gpp",
|
||||
"3g2": "video/3gpp2",
|
||||
gltf: "model/gltf+json",
|
||||
glb: "model/gltf-binary"
|
||||
};
|
||||
var baseMimes = _baseMimes;
|
||||
export {
|
||||
getExtension,
|
||||
getMimeType,
|
||||
baseMimes as mimes
|
||||
};
|
||||
79
_node_modules/hono/dist/utils/stream.js
generated
vendored
Normal file
79
_node_modules/hono/dist/utils/stream.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
// src/utils/stream.ts
|
||||
var StreamingApi = class {
|
||||
writer;
|
||||
encoder;
|
||||
writable;
|
||||
abortSubscribers = [];
|
||||
responseReadable;
|
||||
/**
|
||||
* Whether the stream has been aborted.
|
||||
*/
|
||||
aborted = false;
|
||||
/**
|
||||
* Whether the stream has been closed normally.
|
||||
*/
|
||||
closed = false;
|
||||
constructor(writable, _readable) {
|
||||
this.writable = writable;
|
||||
this.writer = writable.getWriter();
|
||||
this.encoder = new TextEncoder();
|
||||
const reader = _readable.getReader();
|
||||
this.abortSubscribers.push(async () => {
|
||||
await reader.cancel();
|
||||
});
|
||||
this.responseReadable = new ReadableStream({
|
||||
async pull(controller) {
|
||||
const { done, value } = await reader.read();
|
||||
done ? controller.close() : controller.enqueue(value);
|
||||
},
|
||||
cancel: () => {
|
||||
this.abort();
|
||||
}
|
||||
});
|
||||
}
|
||||
async write(input) {
|
||||
try {
|
||||
if (typeof input === "string") {
|
||||
input = this.encoder.encode(input);
|
||||
}
|
||||
await this.writer.write(input);
|
||||
} catch {
|
||||
}
|
||||
return this;
|
||||
}
|
||||
async writeln(input) {
|
||||
await this.write(input + "\n");
|
||||
return this;
|
||||
}
|
||||
sleep(ms) {
|
||||
return new Promise((res) => setTimeout(res, ms));
|
||||
}
|
||||
async close() {
|
||||
try {
|
||||
await this.writer.close();
|
||||
} catch {
|
||||
}
|
||||
this.closed = true;
|
||||
}
|
||||
async pipe(body) {
|
||||
this.writer.releaseLock();
|
||||
await body.pipeTo(this.writable, { preventClose: true });
|
||||
this.writer = this.writable.getWriter();
|
||||
}
|
||||
onAbort(listener) {
|
||||
this.abortSubscribers.push(listener);
|
||||
}
|
||||
/**
|
||||
* Abort the stream.
|
||||
* You can call this method when stream is aborted by external event.
|
||||
*/
|
||||
abort() {
|
||||
if (!this.aborted) {
|
||||
this.aborted = true;
|
||||
this.abortSubscribers.forEach((subscriber) => subscriber());
|
||||
}
|
||||
}
|
||||
};
|
||||
export {
|
||||
StreamingApi
|
||||
};
|
||||
0
_node_modules/hono/dist/utils/types.js
generated
vendored
Normal file
0
_node_modules/hono/dist/utils/types.js
generated
vendored
Normal file
219
_node_modules/hono/dist/utils/url.js
generated
vendored
Normal file
219
_node_modules/hono/dist/utils/url.js
generated
vendored
Normal file
@@ -0,0 +1,219 @@
|
||||
// src/utils/url.ts
|
||||
var splitPath = (path) => {
|
||||
const paths = path.split("/");
|
||||
if (paths[0] === "") {
|
||||
paths.shift();
|
||||
}
|
||||
return paths;
|
||||
};
|
||||
var splitRoutingPath = (routePath) => {
|
||||
const { groups, path } = extractGroupsFromPath(routePath);
|
||||
const paths = splitPath(path);
|
||||
return replaceGroupMarks(paths, groups);
|
||||
};
|
||||
var extractGroupsFromPath = (path) => {
|
||||
const groups = [];
|
||||
path = path.replace(/\{[^}]+\}/g, (match, index) => {
|
||||
const mark = `@${index}`;
|
||||
groups.push([mark, match]);
|
||||
return mark;
|
||||
});
|
||||
return { groups, path };
|
||||
};
|
||||
var replaceGroupMarks = (paths, groups) => {
|
||||
for (let i = groups.length - 1; i >= 0; i--) {
|
||||
const [mark] = groups[i];
|
||||
for (let j = paths.length - 1; j >= 0; j--) {
|
||||
if (paths[j].includes(mark)) {
|
||||
paths[j] = paths[j].replace(mark, groups[i][1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return paths;
|
||||
};
|
||||
var patternCache = {};
|
||||
var getPattern = (label, next) => {
|
||||
if (label === "*") {
|
||||
return "*";
|
||||
}
|
||||
const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
||||
if (match) {
|
||||
const cacheKey = `${label}#${next}`;
|
||||
if (!patternCache[cacheKey]) {
|
||||
if (match[2]) {
|
||||
patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey, match[1], new RegExp(`^${match[2]}(?=/${next})`)] : [label, match[1], new RegExp(`^${match[2]}$`)];
|
||||
} else {
|
||||
patternCache[cacheKey] = [label, match[1], true];
|
||||
}
|
||||
}
|
||||
return patternCache[cacheKey];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
var tryDecode = (str, decoder) => {
|
||||
try {
|
||||
return decoder(str);
|
||||
} catch {
|
||||
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
|
||||
try {
|
||||
return decoder(match);
|
||||
} catch {
|
||||
return match;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
var tryDecodeURI = (str) => tryDecode(str, decodeURI);
|
||||
var getPath = (request) => {
|
||||
const url = request.url;
|
||||
const start = url.indexOf("/", url.indexOf(":") + 4);
|
||||
let i = start;
|
||||
for (; i < url.length; i++) {
|
||||
const charCode = url.charCodeAt(i);
|
||||
if (charCode === 37) {
|
||||
const queryIndex = url.indexOf("?", i);
|
||||
const path = url.slice(start, queryIndex === -1 ? void 0 : queryIndex);
|
||||
return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
|
||||
} else if (charCode === 63) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return url.slice(start, i);
|
||||
};
|
||||
var getQueryStrings = (url) => {
|
||||
const queryIndex = url.indexOf("?", 8);
|
||||
return queryIndex === -1 ? "" : "?" + url.slice(queryIndex + 1);
|
||||
};
|
||||
var getPathNoStrict = (request) => {
|
||||
const result = getPath(request);
|
||||
return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
|
||||
};
|
||||
var mergePath = (base, sub, ...rest) => {
|
||||
if (rest.length) {
|
||||
sub = mergePath(sub, ...rest);
|
||||
}
|
||||
return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`;
|
||||
};
|
||||
var checkOptionalParameter = (path) => {
|
||||
if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":")) {
|
||||
return null;
|
||||
}
|
||||
const segments = path.split("/");
|
||||
const results = [];
|
||||
let basePath = "";
|
||||
segments.forEach((segment) => {
|
||||
if (segment !== "" && !/\:/.test(segment)) {
|
||||
basePath += "/" + segment;
|
||||
} else if (/\:/.test(segment)) {
|
||||
if (/\?/.test(segment)) {
|
||||
if (results.length === 0 && basePath === "") {
|
||||
results.push("/");
|
||||
} else {
|
||||
results.push(basePath);
|
||||
}
|
||||
const optionalSegment = segment.replace("?", "");
|
||||
basePath += "/" + optionalSegment;
|
||||
results.push(basePath);
|
||||
} else {
|
||||
basePath += "/" + segment;
|
||||
}
|
||||
}
|
||||
});
|
||||
return results.filter((v, i, a) => a.indexOf(v) === i);
|
||||
};
|
||||
var _decodeURI = (value) => {
|
||||
if (!/[%+]/.test(value)) {
|
||||
return value;
|
||||
}
|
||||
if (value.indexOf("+") !== -1) {
|
||||
value = value.replace(/\+/g, " ");
|
||||
}
|
||||
return value.indexOf("%") !== -1 ? tryDecode(value, decodeURIComponent_) : value;
|
||||
};
|
||||
var _getQueryParam = (url, key, multiple) => {
|
||||
let encoded;
|
||||
if (!multiple && key && !/[%+]/.test(key)) {
|
||||
let keyIndex2 = url.indexOf("?", 8);
|
||||
if (keyIndex2 === -1) {
|
||||
return void 0;
|
||||
}
|
||||
if (!url.startsWith(key, keyIndex2 + 1)) {
|
||||
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
||||
}
|
||||
while (keyIndex2 !== -1) {
|
||||
const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
|
||||
if (trailingKeyCode === 61) {
|
||||
const valueIndex = keyIndex2 + key.length + 2;
|
||||
const endIndex = url.indexOf("&", valueIndex);
|
||||
return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
|
||||
} else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
|
||||
return "";
|
||||
}
|
||||
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
||||
}
|
||||
encoded = /[%+]/.test(url);
|
||||
if (!encoded) {
|
||||
return void 0;
|
||||
}
|
||||
}
|
||||
const results = {};
|
||||
encoded ??= /[%+]/.test(url);
|
||||
let keyIndex = url.indexOf("?", 8);
|
||||
while (keyIndex !== -1) {
|
||||
const nextKeyIndex = url.indexOf("&", keyIndex + 1);
|
||||
let valueIndex = url.indexOf("=", keyIndex);
|
||||
if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) {
|
||||
valueIndex = -1;
|
||||
}
|
||||
let name = url.slice(
|
||||
keyIndex + 1,
|
||||
valueIndex === -1 ? nextKeyIndex === -1 ? void 0 : nextKeyIndex : valueIndex
|
||||
);
|
||||
if (encoded) {
|
||||
name = _decodeURI(name);
|
||||
}
|
||||
keyIndex = nextKeyIndex;
|
||||
if (name === "") {
|
||||
continue;
|
||||
}
|
||||
let value;
|
||||
if (valueIndex === -1) {
|
||||
value = "";
|
||||
} else {
|
||||
value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? void 0 : nextKeyIndex);
|
||||
if (encoded) {
|
||||
value = _decodeURI(value);
|
||||
}
|
||||
}
|
||||
if (multiple) {
|
||||
if (!(results[name] && Array.isArray(results[name]))) {
|
||||
results[name] = [];
|
||||
}
|
||||
;
|
||||
results[name].push(value);
|
||||
} else {
|
||||
results[name] ??= value;
|
||||
}
|
||||
}
|
||||
return key ? results[key] : results;
|
||||
};
|
||||
var getQueryParam = _getQueryParam;
|
||||
var getQueryParams = (url, key) => {
|
||||
return _getQueryParam(url, key, true);
|
||||
};
|
||||
var decodeURIComponent_ = decodeURIComponent;
|
||||
export {
|
||||
checkOptionalParameter,
|
||||
decodeURIComponent_,
|
||||
getPath,
|
||||
getPathNoStrict,
|
||||
getPattern,
|
||||
getQueryParam,
|
||||
getQueryParams,
|
||||
getQueryStrings,
|
||||
mergePath,
|
||||
splitPath,
|
||||
splitRoutingPath,
|
||||
tryDecode
|
||||
};
|
||||
Reference in New Issue
Block a user