Initial commit: New MoreminiMore website with fresh design
This commit is contained in:
37
node_modules/@astrojs/internal-helpers/dist/cli.d.ts
generated
vendored
Normal file
37
node_modules/@astrojs/internal-helpers/dist/cli.d.ts
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Validates npm package names to prevent command injection attacks in CLI tools.
|
||||
*
|
||||
* This regex follows npm naming rules and blocks shell metacharacters that could
|
||||
* be used for command injection attacks.
|
||||
*
|
||||
* @see https://docs.npmjs.com/cli/v10/configuring-npm/package-json#name
|
||||
*/
|
||||
export declare const NPM_PACKAGE_NAME_REGEX: RegExp;
|
||||
/**
|
||||
* Validates a package name for use in CLI commands.
|
||||
*
|
||||
* @param packageName - The package name to validate
|
||||
* @returns true if the package name is valid, false otherwise
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* validatePackageName('react'); // true
|
||||
* validatePackageName('@astrojs/tailwind'); // true
|
||||
* validatePackageName('react; whoami'); // false
|
||||
* validatePackageName('react$(whoami)'); // false
|
||||
* ```
|
||||
*/
|
||||
export declare function validatePackageName(packageName: string): boolean;
|
||||
/**
|
||||
* Validates a package name and throws an error if invalid.
|
||||
*
|
||||
* @param packageName - The package name to validate
|
||||
* @throws {Error} If the package name is invalid
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* assertValidPackageName('react'); // OK
|
||||
* assertValidPackageName('react; whoami'); // throws Error
|
||||
* ```
|
||||
*/
|
||||
export declare function assertValidPackageName(packageName: string): asserts packageName is string;
|
||||
16
node_modules/@astrojs/internal-helpers/dist/cli.js
generated
vendored
Normal file
16
node_modules/@astrojs/internal-helpers/dist/cli.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
const NPM_PACKAGE_NAME_REGEX = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;
|
||||
function validatePackageName(packageName) {
|
||||
return NPM_PACKAGE_NAME_REGEX.test(packageName);
|
||||
}
|
||||
function assertValidPackageName(packageName) {
|
||||
if (!validatePackageName(packageName)) {
|
||||
throw new Error(
|
||||
`Invalid package name "${packageName}". Package names must follow npm naming rules: lowercase letters, numbers, hyphens, underscores, and dots. Scoped packages like @org/package are also supported.`
|
||||
);
|
||||
}
|
||||
}
|
||||
export {
|
||||
NPM_PACKAGE_NAME_REGEX,
|
||||
assertValidPackageName,
|
||||
validatePackageName
|
||||
};
|
||||
2
node_modules/@astrojs/internal-helpers/dist/create-filter.d.ts
generated
vendored
Normal file
2
node_modules/@astrojs/internal-helpers/dist/create-filter.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export type FilterPattern = readonly (string | RegExp)[] | string | RegExp | null;
|
||||
export declare function createFilter(include?: FilterPattern, exclude?: FilterPattern): (id: string | unknown) => boolean;
|
||||
43
node_modules/@astrojs/internal-helpers/dist/create-filter.js
generated
vendored
Normal file
43
node_modules/@astrojs/internal-helpers/dist/create-filter.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
import picomatch from "picomatch";
|
||||
import { slash as normalizePath } from "./path.js";
|
||||
function ensureArray(thing) {
|
||||
if (Array.isArray(thing)) return thing;
|
||||
if (thing == null) return [];
|
||||
return [thing];
|
||||
}
|
||||
function toMatcher(pattern) {
|
||||
if (pattern instanceof RegExp) {
|
||||
return pattern;
|
||||
}
|
||||
const normalized = normalizePath(pattern);
|
||||
const fn = picomatch(normalized, { dot: true });
|
||||
return { test: (what) => fn(what) };
|
||||
}
|
||||
function createFilter(include, exclude) {
|
||||
const includeMatchers = ensureArray(include).map(toMatcher);
|
||||
const excludeMatchers = ensureArray(exclude).map(toMatcher);
|
||||
if (!includeMatchers.length && !excludeMatchers.length) {
|
||||
return (id) => typeof id === "string" && !id.includes("\0");
|
||||
}
|
||||
return function(id) {
|
||||
if (typeof id !== "string") return false;
|
||||
if (id.includes("\0")) return false;
|
||||
const pathId = normalizePath(id);
|
||||
for (const matcher of excludeMatchers) {
|
||||
if (matcher instanceof RegExp) {
|
||||
matcher.lastIndex = 0;
|
||||
}
|
||||
if (matcher.test(pathId)) return false;
|
||||
}
|
||||
for (const matcher of includeMatchers) {
|
||||
if (matcher instanceof RegExp) {
|
||||
matcher.lastIndex = 0;
|
||||
}
|
||||
if (matcher.test(pathId)) return true;
|
||||
}
|
||||
return !includeMatchers.length;
|
||||
};
|
||||
}
|
||||
export {
|
||||
createFilter
|
||||
};
|
||||
15
node_modules/@astrojs/internal-helpers/dist/fs.d.ts
generated
vendored
Normal file
15
node_modules/@astrojs/internal-helpers/dist/fs.d.ts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import type { PathLike } from 'node:fs';
|
||||
export declare function writeJson<T>(path: PathLike, data: T): Promise<void>;
|
||||
export declare function removeDir(dir: PathLike): Promise<void>;
|
||||
export declare function emptyDir(dir: PathLike): Promise<void>;
|
||||
export declare function getFilesFromFolder(dir: URL): Promise<URL[]>;
|
||||
/**
|
||||
* Copies files into a folder keeping the folder structure intact.
|
||||
* The resulting file tree will start at the common ancestor.
|
||||
*
|
||||
* @param {URL[]} files A list of files to copy (absolute path).
|
||||
* @param {URL} outDir Destination folder where to copy the files to (absolute path).
|
||||
* @param {URL[]} [exclude] A list of files to exclude (absolute path).
|
||||
* @returns {Promise<string>} The common ancestor of the copied files.
|
||||
*/
|
||||
export declare function copyFilesToFolder(files: URL[], outDir: URL, exclude?: URL[]): Promise<string>;
|
||||
66
node_modules/@astrojs/internal-helpers/dist/fs.js
generated
vendored
Normal file
66
node_modules/@astrojs/internal-helpers/dist/fs.js
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
import { existsSync } from "node:fs";
|
||||
import * as fs from "node:fs/promises";
|
||||
import nodePath from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
async function writeJson(path, data) {
|
||||
await fs.writeFile(path, JSON.stringify(data, null, " "), { encoding: "utf-8" });
|
||||
}
|
||||
async function removeDir(dir) {
|
||||
await fs.rm(dir, { recursive: true, force: true, maxRetries: 3 });
|
||||
}
|
||||
async function emptyDir(dir) {
|
||||
await removeDir(dir);
|
||||
await fs.mkdir(dir, { recursive: true });
|
||||
}
|
||||
async function getFilesFromFolder(dir) {
|
||||
const data = await fs.readdir(dir, { withFileTypes: true });
|
||||
let files = [];
|
||||
for (const item of data) {
|
||||
if (item.isDirectory()) {
|
||||
const moreFiles = await getFilesFromFolder(new URL(`./${item.name}/`, dir));
|
||||
files = files.concat(moreFiles);
|
||||
} else {
|
||||
files.push(new URL(`./${item.name}`, dir));
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
async function copyFilesToFolder(files, outDir, exclude = []) {
|
||||
const excludeList = exclude.map((url) => fileURLToPath(url));
|
||||
const fileList = files.map((url) => fileURLToPath(url)).filter((f) => !excludeList.includes(f));
|
||||
if (files.length === 0) throw new Error("No files found to copy");
|
||||
let commonAncestor = nodePath.dirname(fileList[0]);
|
||||
for (const file of fileList.slice(1)) {
|
||||
while (!file.startsWith(commonAncestor)) {
|
||||
commonAncestor = nodePath.dirname(commonAncestor);
|
||||
}
|
||||
}
|
||||
for (const origin of fileList) {
|
||||
const dest = new URL(nodePath.relative(commonAncestor, origin), outDir);
|
||||
const realpath = await fs.realpath(origin);
|
||||
const isSymlink = realpath !== origin;
|
||||
const isDir = (await fs.stat(origin)).isDirectory();
|
||||
if (isDir && !isSymlink) {
|
||||
await fs.mkdir(new URL("..", dest), { recursive: true });
|
||||
} else {
|
||||
await fs.mkdir(new URL(".", dest), { recursive: true });
|
||||
}
|
||||
if (isSymlink) {
|
||||
const realdest = fileURLToPath(new URL(nodePath.relative(commonAncestor, realpath), outDir));
|
||||
const target = nodePath.relative(fileURLToPath(new URL(".", dest)), realdest);
|
||||
if (!existsSync(dest)) {
|
||||
await fs.symlink(target, dest, isDir ? "dir" : "file");
|
||||
}
|
||||
} else if (!isDir) {
|
||||
await fs.copyFile(origin, dest);
|
||||
}
|
||||
}
|
||||
return commonAncestor;
|
||||
}
|
||||
export {
|
||||
copyFilesToFolder,
|
||||
emptyDir,
|
||||
getFilesFromFolder,
|
||||
removeDir,
|
||||
writeJson
|
||||
};
|
||||
49
node_modules/@astrojs/internal-helpers/dist/path.d.ts
generated
vendored
Normal file
49
node_modules/@astrojs/internal-helpers/dist/path.d.ts
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* A set of common path utilities commonly used through the Astro core and integration
|
||||
* projects. These do things like ensure a forward slash prepends paths.
|
||||
*/
|
||||
export declare function appendExtension(path: string, extension: string): string;
|
||||
export declare function appendForwardSlash(path: string): string;
|
||||
export declare function prependForwardSlash(path: string): string;
|
||||
export declare const MANY_LEADING_SLASHES: RegExp;
|
||||
export declare function collapseDuplicateLeadingSlashes(path: string): string;
|
||||
export declare function collapseDuplicateSlashes(path: string): string;
|
||||
export declare const MANY_TRAILING_SLASHES: RegExp;
|
||||
export declare function collapseDuplicateTrailingSlashes(path: string, trailingSlash: boolean): string;
|
||||
export declare function removeTrailingForwardSlash(path: string): string;
|
||||
export declare function removeLeadingForwardSlash(path: string): string;
|
||||
export declare function removeLeadingForwardSlashWindows(path: string): string;
|
||||
export declare function trimSlashes(path: string): string;
|
||||
export declare function isRelativePath(path: string): boolean;
|
||||
export declare function isInternalPath(path: string): boolean;
|
||||
export declare function joinPaths(...paths: (string | undefined)[]): string;
|
||||
export declare function removeFileExtension(path: string): string;
|
||||
export declare function removeQueryString(path: string): string;
|
||||
/**
|
||||
* Checks whether the path is considered a remote path.
|
||||
* Remote means untrusted in this context, so anything that isn't a straightforward
|
||||
* local path is considered remote.
|
||||
*
|
||||
* @param src
|
||||
*/
|
||||
export declare function isRemotePath(src: string): boolean;
|
||||
/**
|
||||
* Checks if parentPath is a parent directory of childPath.
|
||||
*/
|
||||
export declare function isParentDirectory(parentPath: string, childPath: string): boolean;
|
||||
export declare function slash(path: string): string;
|
||||
export declare function fileExtension(path: string): string;
|
||||
export declare function removeBase(path: string, base: string): string;
|
||||
export declare function hasFileExtension(path: string): boolean;
|
||||
/**
|
||||
* Normalizes a URL pathname to match the canonical form used by route generation.
|
||||
* This reverses the transformations done by `getUrlForPath` in generate.ts.
|
||||
*
|
||||
* - For `buildFormat: 'file'`: strips `.html` extension
|
||||
* - For `buildFormat: 'directory'/'preserve'` with `trailingSlash: 'ignore'`: strips trailing slash
|
||||
*
|
||||
* @param pathname - The URL pathname to normalize
|
||||
* @param buildFormat - The build format ('file', 'directory', or 'preserve')
|
||||
* @param trailingSlash - The trailing slash setting ('always', 'never', or 'ignore')
|
||||
*/
|
||||
export declare function normalizePathname(pathname: string, buildFormat: 'file' | 'directory' | 'preserve', trailingSlash: 'always' | 'never' | 'ignore'): string;
|
||||
215
node_modules/@astrojs/internal-helpers/dist/path.js
generated
vendored
Normal file
215
node_modules/@astrojs/internal-helpers/dist/path.js
generated
vendored
Normal file
@@ -0,0 +1,215 @@
|
||||
function appendExtension(path, extension) {
|
||||
return path + "." + extension;
|
||||
}
|
||||
function appendForwardSlash(path) {
|
||||
return path.endsWith("/") ? path : path + "/";
|
||||
}
|
||||
function prependForwardSlash(path) {
|
||||
return path[0] === "/" ? path : "/" + path;
|
||||
}
|
||||
const MANY_LEADING_SLASHES = /^\/{2,}/;
|
||||
function collapseDuplicateLeadingSlashes(path) {
|
||||
if (!path) {
|
||||
return path;
|
||||
}
|
||||
return path.replace(MANY_LEADING_SLASHES, "/");
|
||||
}
|
||||
const MANY_SLASHES = /\/{2,}/g;
|
||||
function collapseDuplicateSlashes(path) {
|
||||
if (!path) {
|
||||
return path;
|
||||
}
|
||||
return path.replace(MANY_SLASHES, "/");
|
||||
}
|
||||
const MANY_TRAILING_SLASHES = /\/{2,}$/g;
|
||||
function collapseDuplicateTrailingSlashes(path, trailingSlash) {
|
||||
if (!path) {
|
||||
return path;
|
||||
}
|
||||
return path.replace(MANY_TRAILING_SLASHES, trailingSlash ? "/" : "") || "/";
|
||||
}
|
||||
function removeTrailingForwardSlash(path) {
|
||||
return path.endsWith("/") ? path.slice(0, path.length - 1) : path;
|
||||
}
|
||||
function removeLeadingForwardSlash(path) {
|
||||
return path.startsWith("/") ? path.substring(1) : path;
|
||||
}
|
||||
function removeLeadingForwardSlashWindows(path) {
|
||||
return path.startsWith("/") && path[2] === ":" ? path.substring(1) : path;
|
||||
}
|
||||
function trimSlashes(path) {
|
||||
return path.replace(/^\/|\/$/g, "");
|
||||
}
|
||||
function startsWithDotDotSlash(path) {
|
||||
const c1 = path[0];
|
||||
const c2 = path[1];
|
||||
const c3 = path[2];
|
||||
return c1 === "." && c2 === "." && c3 === "/";
|
||||
}
|
||||
function startsWithDotSlash(path) {
|
||||
const c1 = path[0];
|
||||
const c2 = path[1];
|
||||
return c1 === "." && c2 === "/";
|
||||
}
|
||||
function isRelativePath(path) {
|
||||
return startsWithDotDotSlash(path) || startsWithDotSlash(path);
|
||||
}
|
||||
function isString(path) {
|
||||
return typeof path === "string" || path instanceof String;
|
||||
}
|
||||
const INTERNAL_PREFIXES = /* @__PURE__ */ new Set(["/_", "/@", "/.", "//"]);
|
||||
const JUST_SLASHES = /^\/{2,}$/;
|
||||
function isInternalPath(path) {
|
||||
return INTERNAL_PREFIXES.has(path.slice(0, 2)) && !JUST_SLASHES.test(path);
|
||||
}
|
||||
function joinPaths(...paths) {
|
||||
return paths.filter(isString).map((path, i) => {
|
||||
if (i === 0) {
|
||||
return removeTrailingForwardSlash(path);
|
||||
} else if (i === paths.length - 1) {
|
||||
return removeLeadingForwardSlash(path);
|
||||
} else {
|
||||
return trimSlashes(path);
|
||||
}
|
||||
}).join("/");
|
||||
}
|
||||
function removeFileExtension(path) {
|
||||
let idx = path.lastIndexOf(".");
|
||||
return idx === -1 ? path : path.slice(0, idx);
|
||||
}
|
||||
function removeQueryString(path) {
|
||||
const index = path.lastIndexOf("?");
|
||||
return index > 0 ? path.substring(0, index) : path;
|
||||
}
|
||||
function isRemotePath(src) {
|
||||
if (!src) return false;
|
||||
const trimmed = src.trim();
|
||||
if (!trimmed) return false;
|
||||
let decoded = trimmed;
|
||||
let previousDecoded = "";
|
||||
let maxIterations = 10;
|
||||
while (decoded !== previousDecoded && maxIterations > 0) {
|
||||
previousDecoded = decoded;
|
||||
try {
|
||||
decoded = decodeURIComponent(decoded);
|
||||
} catch {
|
||||
break;
|
||||
}
|
||||
maxIterations--;
|
||||
}
|
||||
if (/^[a-zA-Z]:/.test(decoded)) {
|
||||
return false;
|
||||
}
|
||||
if (decoded[0] === "/" && decoded[1] !== "/" && decoded[1] !== "\\") {
|
||||
return false;
|
||||
}
|
||||
if (decoded[0] === "\\") {
|
||||
return true;
|
||||
}
|
||||
if (decoded.startsWith("//")) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
const url = new URL(decoded, "http://n");
|
||||
if (url.username || url.password) {
|
||||
return true;
|
||||
}
|
||||
if (decoded.includes("@") && !url.pathname.includes("@") && !url.search.includes("@")) {
|
||||
return true;
|
||||
}
|
||||
if (url.origin !== "http://n") {
|
||||
const protocol = url.protocol.toLowerCase();
|
||||
if (protocol === "file:") {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (URL.canParse(decoded)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function isParentDirectory(parentPath, childPath) {
|
||||
if (!parentPath || !childPath) {
|
||||
return false;
|
||||
}
|
||||
if (parentPath.includes("://") || childPath.includes("://")) {
|
||||
return false;
|
||||
}
|
||||
if (isRemotePath(parentPath) || isRemotePath(childPath)) {
|
||||
return false;
|
||||
}
|
||||
if (parentPath.includes("..") || childPath.includes("..")) {
|
||||
return false;
|
||||
}
|
||||
if (parentPath.includes("\0") || childPath.includes("\0")) {
|
||||
return false;
|
||||
}
|
||||
const normalizedParent = appendForwardSlash(slash(parentPath).toLowerCase());
|
||||
const normalizedChild = slash(childPath).toLowerCase();
|
||||
if (normalizedParent === normalizedChild || normalizedParent === normalizedChild + "/") {
|
||||
return false;
|
||||
}
|
||||
return normalizedChild.startsWith(normalizedParent);
|
||||
}
|
||||
function slash(path) {
|
||||
return path.replace(/\\/g, "/");
|
||||
}
|
||||
function fileExtension(path) {
|
||||
const ext = path.split(".").pop();
|
||||
return ext !== path ? `.${ext}` : "";
|
||||
}
|
||||
function removeBase(path, base) {
|
||||
if (path.startsWith(base)) {
|
||||
return path.slice(removeTrailingForwardSlash(base).length);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
const WITH_FILE_EXT = /\/[^/]+\.\w+$/;
|
||||
function hasFileExtension(path) {
|
||||
return WITH_FILE_EXT.test(path);
|
||||
}
|
||||
function normalizePathname(pathname, buildFormat, trailingSlash) {
|
||||
if (buildFormat === "file") {
|
||||
if (pathname.endsWith(".html") && pathname !== "/.html") {
|
||||
return pathname.slice(0, -5);
|
||||
}
|
||||
if (pathname !== "/" && !pathname.endsWith(".html")) {
|
||||
return "/";
|
||||
}
|
||||
} else {
|
||||
if (trailingSlash === "ignore" && pathname.endsWith("/") && pathname !== "/") {
|
||||
return pathname.slice(0, -1);
|
||||
}
|
||||
}
|
||||
return pathname;
|
||||
}
|
||||
export {
|
||||
MANY_LEADING_SLASHES,
|
||||
MANY_TRAILING_SLASHES,
|
||||
appendExtension,
|
||||
appendForwardSlash,
|
||||
collapseDuplicateLeadingSlashes,
|
||||
collapseDuplicateSlashes,
|
||||
collapseDuplicateTrailingSlashes,
|
||||
fileExtension,
|
||||
hasFileExtension,
|
||||
isInternalPath,
|
||||
isParentDirectory,
|
||||
isRelativePath,
|
||||
isRemotePath,
|
||||
joinPaths,
|
||||
normalizePathname,
|
||||
prependForwardSlash,
|
||||
removeBase,
|
||||
removeFileExtension,
|
||||
removeLeadingForwardSlash,
|
||||
removeLeadingForwardSlashWindows,
|
||||
removeQueryString,
|
||||
removeTrailingForwardSlash,
|
||||
slash,
|
||||
trimSlashes
|
||||
};
|
||||
62
node_modules/@astrojs/internal-helpers/dist/remote.d.ts
generated
vendored
Normal file
62
node_modules/@astrojs/internal-helpers/dist/remote.d.ts
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
export type RemotePattern = {
|
||||
hostname?: string;
|
||||
pathname?: string;
|
||||
protocol?: string;
|
||||
port?: string;
|
||||
};
|
||||
/**
|
||||
* Evaluates whether a given URL matches the specified remote pattern based on protocol, hostname, port, and pathname.
|
||||
*
|
||||
* @param {URL} url - The URL object to be matched against the remote pattern.
|
||||
* @param {RemotePattern} remotePattern - The remote pattern object containing the protocol, hostname, port, and pathname to match.
|
||||
* @return {boolean} Returns `true` if the URL matches the given remote pattern; otherwise, `false`.
|
||||
*/
|
||||
export declare function matchPattern(url: URL, remotePattern: RemotePattern): boolean;
|
||||
/**
|
||||
* Checks if the given URL's port matches the specified port. If no port is provided, it returns `true`.
|
||||
*
|
||||
* @param {URL} url - The URL object whose port will be checked.
|
||||
* @param {string} [port=] - The port to match against the URL's port. Optional.
|
||||
* @return {boolean} Returns `true` if the URL's port matches the specified port or if no port is provided; otherwise, `false`.
|
||||
*/
|
||||
export declare function matchPort(url: URL, port?: string): boolean;
|
||||
/**
|
||||
* Compares the protocol of the provided URL with a specified protocol.
|
||||
*
|
||||
* @param {URL} url - The URL object whose protocol needs to be checked.
|
||||
* @param {string} [protocol] - The protocol to compare against, without the trailing colon. If not provided, the method will always return `true`.
|
||||
* @return {boolean} Returns `true` if the protocol matches or if no protocol is specified; otherwise, `false`.
|
||||
*/
|
||||
export declare function matchProtocol(url: URL, protocol?: string): boolean;
|
||||
/**
|
||||
* Matches a given URL's hostname against a specified hostname, with optional support for wildcard patterns.
|
||||
*
|
||||
* @param {URL} url - The URL object whose hostname is to be matched.
|
||||
* @param {string} [hostname] - The hostname to match against. Supports wildcard patterns if `allowWildcard` is `true`.
|
||||
* @param {boolean} [allowWildcard=false] - Indicates whether wildcard patterns in the `hostname` parameter are allowed.
|
||||
* @return {boolean} - Returns `true` if the URL's hostname matches the given hostname criteria; otherwise, `false`.
|
||||
*/
|
||||
export declare function matchHostname(url: URL, hostname?: string, allowWildcard?: boolean): boolean;
|
||||
/**
|
||||
* Matches a given URL's pathname against a specified pattern, with optional support for wildcards.
|
||||
*
|
||||
* @param {URL} url - The URL object containing the pathname to be matched.
|
||||
* @param {string} [pathname] - The pathname pattern to match the URL against.
|
||||
* @param {boolean} [allowWildcard=false] - Determines whether wildcard matching is allowed.
|
||||
* @return {boolean} - Returns `true` if the URL's pathname matches the specified pattern; otherwise, `false`.
|
||||
*/
|
||||
export declare function matchPathname(url: URL, pathname?: string, allowWildcard?: boolean): boolean;
|
||||
/**
|
||||
* Determines whether a given remote resource, identified by its source URL,
|
||||
* is allowed based on specified domains and remote patterns.
|
||||
*
|
||||
* @param {string} src - The source URL of the remote resource to be validated.
|
||||
* @param {Object} options - The configuration options for domain and pattern matching.
|
||||
* @param {string[]} options.domains - A list of allowed domain names.
|
||||
* @param {RemotePattern[]} options.remotePatterns - A list of allowed remote patterns for matching.
|
||||
* @return {boolean} Returns `true` if the source URL matches any of the specified domains or remote patterns; otherwise, `false`.
|
||||
*/
|
||||
export declare function isRemoteAllowed(src: string, { domains, remotePatterns, }: {
|
||||
domains: string[];
|
||||
remotePatterns: RemotePattern[];
|
||||
}): boolean;
|
||||
66
node_modules/@astrojs/internal-helpers/dist/remote.js
generated
vendored
Normal file
66
node_modules/@astrojs/internal-helpers/dist/remote.js
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
function matchPattern(url, remotePattern) {
|
||||
return matchProtocol(url, remotePattern.protocol) && matchHostname(url, remotePattern.hostname, true) && matchPort(url, remotePattern.port) && matchPathname(url, remotePattern.pathname, true);
|
||||
}
|
||||
function matchPort(url, port) {
|
||||
return !port || port === url.port;
|
||||
}
|
||||
function matchProtocol(url, protocol) {
|
||||
return !protocol || protocol === url.protocol.slice(0, -1);
|
||||
}
|
||||
function matchHostname(url, hostname, allowWildcard = false) {
|
||||
if (!hostname) {
|
||||
return true;
|
||||
} else if (!allowWildcard || !hostname.startsWith("*")) {
|
||||
return hostname === url.hostname;
|
||||
} else if (hostname.startsWith("**.")) {
|
||||
const slicedHostname = hostname.slice(2);
|
||||
return slicedHostname !== url.hostname && url.hostname.endsWith(slicedHostname);
|
||||
} else if (hostname.startsWith("*.")) {
|
||||
const slicedHostname = hostname.slice(1);
|
||||
if (!url.hostname.endsWith(slicedHostname)) {
|
||||
return false;
|
||||
}
|
||||
const subdomainWithDot = url.hostname.slice(0, -(slicedHostname.length - 1));
|
||||
return subdomainWithDot.endsWith(".") && !subdomainWithDot.slice(0, -1).includes(".");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function matchPathname(url, pathname, allowWildcard = false) {
|
||||
if (!pathname) {
|
||||
return true;
|
||||
} else if (!allowWildcard || !pathname.endsWith("*")) {
|
||||
return pathname === url.pathname;
|
||||
} else if (pathname.endsWith("/**")) {
|
||||
const slicedPathname = pathname.slice(0, -2);
|
||||
return slicedPathname !== url.pathname && url.pathname.startsWith(slicedPathname);
|
||||
} else if (pathname.endsWith("/*")) {
|
||||
const slicedPathname = pathname.slice(0, -1);
|
||||
if (!url.pathname.startsWith(slicedPathname)) {
|
||||
return false;
|
||||
}
|
||||
const additionalPathChunks = url.pathname.slice(slicedPathname.length).split("/").filter(Boolean);
|
||||
return additionalPathChunks.length === 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function isRemoteAllowed(src, {
|
||||
domains,
|
||||
remotePatterns
|
||||
}) {
|
||||
if (!URL.canParse(src)) {
|
||||
return false;
|
||||
}
|
||||
const url = new URL(src);
|
||||
if (!["http:", "https:", "data:"].includes(url.protocol)) {
|
||||
return false;
|
||||
}
|
||||
return domains.some((domain) => matchHostname(url, domain)) || remotePatterns.some((remotePattern) => matchPattern(url, remotePattern));
|
||||
}
|
||||
export {
|
||||
isRemoteAllowed,
|
||||
matchHostname,
|
||||
matchPathname,
|
||||
matchPattern,
|
||||
matchPort,
|
||||
matchProtocol
|
||||
};
|
||||
27
node_modules/@astrojs/internal-helpers/dist/request.d.ts
generated
vendored
Normal file
27
node_modules/@astrojs/internal-helpers/dist/request.d.ts
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Utilities for extracting information from `Request`
|
||||
*/
|
||||
export declare function getFirstForwardedValue(multiValueHeader?: string | string[] | null): string | undefined;
|
||||
/**
|
||||
* Checks whether a string looks like an IP address (contains only characters
|
||||
* that can appear in IPv4/IPv6 addresses and is within a reasonable length).
|
||||
*
|
||||
* This is a permissive allowlist — it won't catch every malformed IP, but it
|
||||
* reliably rejects injection payloads. Does NOT use Node.js APIs so it works
|
||||
* in all runtimes (Workers, Deno, etc.).
|
||||
*/
|
||||
export declare function isValidIpAddress(value: string): boolean;
|
||||
/**
|
||||
* Extracts the first value from a potentially multi-value header and validates
|
||||
* that it is a syntactically valid IP address.
|
||||
*
|
||||
* Useful for adapters that read client IP from a platform-specific header
|
||||
*/
|
||||
export declare function getValidatedIpFromHeader(headerValue: string | string[] | null | undefined): string | undefined;
|
||||
/**
|
||||
* Returns the first value associated to the `x-forwarded-for` header,
|
||||
* but only if it is a valid IP address. Returns `undefined` otherwise.
|
||||
*
|
||||
* @param {Request} request
|
||||
*/
|
||||
export declare function getClientIpAddress(request: Request): string | undefined;
|
||||
23
node_modules/@astrojs/internal-helpers/dist/request.js
generated
vendored
Normal file
23
node_modules/@astrojs/internal-helpers/dist/request.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
function getFirstForwardedValue(multiValueHeader) {
|
||||
return multiValueHeader?.toString()?.split(",").map((e) => e.trim())?.[0];
|
||||
}
|
||||
const IP_RE = /^[0-9a-fA-F.:]{1,45}$/;
|
||||
function isValidIpAddress(value) {
|
||||
return IP_RE.test(value);
|
||||
}
|
||||
function getValidatedIpFromHeader(headerValue) {
|
||||
const raw = getFirstForwardedValue(headerValue);
|
||||
if (raw && isValidIpAddress(raw)) {
|
||||
return raw;
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
function getClientIpAddress(request) {
|
||||
return getValidatedIpFromHeader(request.headers.get("x-forwarded-for"));
|
||||
}
|
||||
export {
|
||||
getClientIpAddress,
|
||||
getFirstForwardedValue,
|
||||
getValidatedIpFromHeader,
|
||||
isValidIpAddress
|
||||
};
|
||||
Reference in New Issue
Block a user