create project

This commit is contained in:
ismailsosic
2022-12-27 12:05:56 +01:00
parent 2a33a2d3de
commit cd2143287c
16035 changed files with 2489703 additions and 0 deletions

View File

@@ -0,0 +1,206 @@
import { PageSignatureError } from "./error";
import { fromNodeHeaders } from "./utils";
import { NextFetchEvent } from "./spec-extension/fetch-event";
import { NextRequest } from "./spec-extension/request";
import { NextResponse } from "./spec-extension/response";
import { relativizeURL } from "../../shared/lib/router/utils/relativize-url";
import { waitUntilSymbol } from "./spec-extension/fetch-event";
import { NextURL } from "./next-url";
import { stripInternalSearchParams } from "../internal-utils";
import { normalizeRscPath } from "../../shared/lib/router/utils/app-paths";
import { FETCH_CACHE_HEADER, NEXT_ROUTER_PREFETCH, NEXT_ROUTER_STATE_TREE, RSC } from "../../client/components/app-router-headers";
class NextRequestHint extends NextRequest {
constructor(params){
super(params.input, params.init);
this.sourcePage = params.page;
}
get request() {
throw new PageSignatureError({
page: this.sourcePage
});
}
respondWith() {
throw new PageSignatureError({
page: this.sourcePage
});
}
waitUntil() {
throw new PageSignatureError({
page: this.sourcePage
});
}
}
const FLIGHT_PARAMETERS = [
[
RSC
],
[
NEXT_ROUTER_STATE_TREE
],
[
NEXT_ROUTER_PREFETCH
],
[
FETCH_CACHE_HEADER
],
];
export async function adapter(params) {
// TODO-APP: use explicit marker for this
const isEdgeRendering = typeof self.__BUILD_MANIFEST !== "undefined";
params.request.url = normalizeRscPath(params.request.url, true);
const requestUrl = new NextURL(params.request.url, {
headers: params.request.headers,
nextConfig: params.request.nextConfig
});
// Ensure users only see page requests, never data requests.
const buildId = requestUrl.buildId;
requestUrl.buildId = "";
const isDataReq = params.request.headers["x-nextjs-data"];
if (isDataReq && requestUrl.pathname === "/index") {
requestUrl.pathname = "/";
}
const requestHeaders = fromNodeHeaders(params.request.headers);
// Parameters should only be stripped for middleware
if (!isEdgeRendering) {
for (const param of FLIGHT_PARAMETERS){
requestHeaders.delete(param.toString().toLowerCase());
}
}
// Strip internal query parameters off the request.
stripInternalSearchParams(requestUrl.searchParams, true);
const request = new NextRequestHint({
page: params.page,
input: String(requestUrl),
init: {
body: params.request.body,
geo: params.request.geo,
headers: requestHeaders,
ip: params.request.ip,
method: params.request.method,
nextConfig: params.request.nextConfig
}
});
/**
* This allows to identify the request as a data request. The user doesn't
* need to know about this property neither use it. We add it for testing
* purposes.
*/ if (isDataReq) {
Object.defineProperty(request, "__isData", {
enumerable: false,
value: true
});
}
const event = new NextFetchEvent({
request,
page: params.page
});
let response = await params.handler(request, event);
// check if response is a Response object
if (response && !(response instanceof Response)) {
throw new TypeError("Expected an instance of Response to be returned");
}
/**
* For rewrites we must always include the locale in the final pathname
* so we re-create the NextURL forcing it to include it when the it is
* an internal rewrite. Also we make sure the outgoing rewrite URL is
* a data URL if the request was a data request.
*/ const rewrite = response == null ? void 0 : response.headers.get("x-middleware-rewrite");
if (response && rewrite) {
const rewriteUrl = new NextURL(rewrite, {
forceLocale: true,
headers: params.request.headers,
nextConfig: params.request.nextConfig
});
if (!process.env.__NEXT_NO_MIDDLEWARE_URL_NORMALIZE) {
if (rewriteUrl.host === request.nextUrl.host) {
rewriteUrl.buildId = buildId || rewriteUrl.buildId;
response.headers.set("x-middleware-rewrite", String(rewriteUrl));
}
}
/**
* When the request is a data request we must show if there was a rewrite
* with an internal header so the client knows which component to load
* from the data request.
*/ if (isDataReq) {
response.headers.set("x-nextjs-rewrite", relativizeURL(String(rewriteUrl), String(requestUrl)));
}
}
/**
* For redirects we will not include the locale in case when it is the
* default and we must also make sure the outgoing URL is a data one if
* the incoming request was a data request.
*/ const redirect = response == null ? void 0 : response.headers.get("Location");
if (response && redirect) {
const redirectURL = new NextURL(redirect, {
forceLocale: false,
headers: params.request.headers,
nextConfig: params.request.nextConfig
});
/**
* Responses created from redirects have immutable headers so we have
* to clone the response to be able to modify it.
*/ response = new Response(response.body, response);
if (!process.env.__NEXT_NO_MIDDLEWARE_URL_NORMALIZE) {
if (redirectURL.host === request.nextUrl.host) {
redirectURL.buildId = buildId || redirectURL.buildId;
response.headers.set("Location", String(redirectURL));
}
}
/**
* When the request is a data request we can't use the location header as
* it may end up with CORS error. Instead we map to an internal header so
* the client knows the destination.
*/ if (isDataReq) {
response.headers.delete("Location");
response.headers.set("x-nextjs-redirect", relativizeURL(String(redirectURL), String(requestUrl)));
}
}
return {
response: response || NextResponse.next(),
waitUntil: Promise.all(event[waitUntilSymbol])
};
}
function getUnsupportedModuleErrorMessage(module) {
// warning: if you change these messages, you must adjust how react-dev-overlay's middleware detects modules not found
return `The edge runtime does not support Node.js '${module}' module.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime`;
}
function __import_unsupported(moduleName) {
const proxy = new Proxy(function() {}, {
get (_obj, prop) {
if (prop === "then") {
return {};
}
throw new Error(getUnsupportedModuleErrorMessage(moduleName));
},
construct () {
throw new Error(getUnsupportedModuleErrorMessage(moduleName));
},
apply (_target, _this, args) {
if (typeof args[0] === "function") {
return args[0](proxy);
}
throw new Error(getUnsupportedModuleErrorMessage(moduleName));
}
});
return new Proxy({}, {
get: ()=>proxy
});
}
export function enhanceGlobals() {
// The condition is true when the "process" module is provided
if (process !== global.process) {
// prefer local process but global.process has correct "env"
process.env = global.process.env;
global.process = process;
}
// to allow building code that import but does not use node.js modules,
// webpack will expect this function to exist in global scope
Object.defineProperty(globalThis, "__import_unsupported", {
value: __import_unsupported,
enumerable: false,
configurable: false
});
}
//# sourceMappingURL=adapter.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,28 @@
export class PageSignatureError extends Error {
constructor({ page }){
super(`The middleware "${page}" accepts an async API directly with the form:
export function middleware(request, event) {
return NextResponse.redirect('/new-location')
}
Read more: https://nextjs.org/docs/messages/middleware-new-signature
`);
}
}
export class RemovedPageError extends Error {
constructor(){
super(`The request.page has been deprecated in favour of \`URLPattern\`.
Read more: https://nextjs.org/docs/messages/middleware-request-page
`);
}
}
export class RemovedUAError extends Error {
constructor(){
super(`The request.ua has been removed in favour of \`userAgent\` function.
Read more: https://nextjs.org/docs/messages/middleware-parse-user-agent
`);
}
}
//# sourceMappingURL=error.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../server/web/error.ts"],"names":["PageSignatureError","Error","constructor","page","RemovedPageError","RemovedUAError"],"mappings":"AAAA,OAAO,MAAMA,kBAAkB,SAASC,KAAK;IAC3CC,YAAY,EAAEC,IAAI,CAAA,EAAoB,CAAE;QACtC,KAAK,CAAC,CAAC,gBAAgB,EAAEA,IAAI,CAAC;;;;;;;EAOhC,CAAC,CAAC;KACD;CACF;AAED,OAAO,MAAMC,gBAAgB,SAASH,KAAK;IACzCC,aAAc;QACZ,KAAK,CAAC,CAAC;;EAET,CAAC,CAAC;KACD;CACF;AAED,OAAO,MAAMG,cAAc,SAASJ,KAAK;IACvCC,aAAc;QACZ,KAAK,CAAC,CAAC;;EAET,CAAC,CAAC;KACD;CACF"}

View File

@@ -0,0 +1,179 @@
import { detectDomainLocale } from "../../shared/lib/i18n/detect-domain-locale";
import { formatNextPathnameInfo } from "../../shared/lib/router/utils/format-next-pathname-info";
import { getHostname } from "../../shared/lib/get-hostname";
import { getNextPathnameInfo } from "../../shared/lib/router/utils/get-next-pathname-info";
const REGEX_LOCALHOST_HOSTNAME = /(?!^https?:\/\/)(127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}|::1|localhost)/;
function parseURL(url, base) {
return new URL(String(url).replace(REGEX_LOCALHOST_HOSTNAME, "localhost"), base && String(base).replace(REGEX_LOCALHOST_HOSTNAME, "localhost"));
}
const Internal = Symbol("NextURLInternal");
export class NextURL {
constructor(input, baseOrOpts, opts){
let base;
let options;
if (typeof baseOrOpts === "object" && "pathname" in baseOrOpts || typeof baseOrOpts === "string") {
base = baseOrOpts;
options = opts || {};
} else {
options = opts || baseOrOpts || {};
}
this[Internal] = {
url: parseURL(input, base ?? options.base),
options: options,
basePath: ""
};
this.analyzeUrl();
}
analyzeUrl() {
var ref, ref1, ref2, ref3, ref4;
const pathnameInfo = getNextPathnameInfo(this[Internal].url.pathname, {
nextConfig: this[Internal].options.nextConfig,
parseData: !process.env.__NEXT_NO_MIDDLEWARE_URL_NORMALIZE
});
this[Internal].domainLocale = detectDomainLocale((ref = this[Internal].options.nextConfig) == null ? void 0 : (ref1 = ref.i18n) == null ? void 0 : ref1.domains, getHostname(this[Internal].url, this[Internal].options.headers));
const defaultLocale = ((ref2 = this[Internal].domainLocale) == null ? void 0 : ref2.defaultLocale) || ((ref3 = this[Internal].options.nextConfig) == null ? void 0 : (ref4 = ref3.i18n) == null ? void 0 : ref4.defaultLocale);
this[Internal].url.pathname = pathnameInfo.pathname;
this[Internal].defaultLocale = defaultLocale;
this[Internal].basePath = pathnameInfo.basePath ?? "";
this[Internal].buildId = pathnameInfo.buildId;
this[Internal].locale = pathnameInfo.locale ?? defaultLocale;
this[Internal].trailingSlash = pathnameInfo.trailingSlash;
}
formatPathname() {
return formatNextPathnameInfo({
basePath: this[Internal].basePath,
buildId: this[Internal].buildId,
defaultLocale: !this[Internal].options.forceLocale ? this[Internal].defaultLocale : undefined,
locale: this[Internal].locale,
pathname: this[Internal].url.pathname,
trailingSlash: this[Internal].trailingSlash
});
}
formatSearch() {
return this[Internal].url.search;
}
get buildId() {
return this[Internal].buildId;
}
set buildId(buildId) {
this[Internal].buildId = buildId;
}
get locale() {
return this[Internal].locale ?? "";
}
set locale(locale) {
var ref, ref5;
if (!this[Internal].locale || !((ref = this[Internal].options.nextConfig) == null ? void 0 : (ref5 = ref.i18n) == null ? void 0 : ref5.locales.includes(locale))) {
throw new TypeError(`The NextURL configuration includes no locale "${locale}"`);
}
this[Internal].locale = locale;
}
get defaultLocale() {
return this[Internal].defaultLocale;
}
get domainLocale() {
return this[Internal].domainLocale;
}
get searchParams() {
return this[Internal].url.searchParams;
}
get host() {
return this[Internal].url.host;
}
set host(value) {
this[Internal].url.host = value;
}
get hostname() {
return this[Internal].url.hostname;
}
set hostname(value) {
this[Internal].url.hostname = value;
}
get port() {
return this[Internal].url.port;
}
set port(value) {
this[Internal].url.port = value;
}
get protocol() {
return this[Internal].url.protocol;
}
set protocol(value) {
this[Internal].url.protocol = value;
}
get href() {
const pathname = this.formatPathname();
const search = this.formatSearch();
return `${this.protocol}//${this.host}${pathname}${search}${this.hash}`;
}
set href(url) {
this[Internal].url = parseURL(url);
this.analyzeUrl();
}
get origin() {
return this[Internal].url.origin;
}
get pathname() {
return this[Internal].url.pathname;
}
set pathname(value) {
this[Internal].url.pathname = value;
}
get hash() {
return this[Internal].url.hash;
}
set hash(value) {
this[Internal].url.hash = value;
}
get search() {
return this[Internal].url.search;
}
set search(value) {
this[Internal].url.search = value;
}
get password() {
return this[Internal].url.password;
}
set password(value) {
this[Internal].url.password = value;
}
get username() {
return this[Internal].url.username;
}
set username(value) {
this[Internal].url.username = value;
}
get basePath() {
return this[Internal].basePath;
}
set basePath(value) {
this[Internal].basePath = value.startsWith("/") ? value : `/${value}`;
}
toString() {
return this.href;
}
toJSON() {
return this.href;
}
[Symbol.for("edge-runtime.inspect.custom")]() {
return {
href: this.href,
origin: this.origin,
protocol: this.protocol,
username: this.username,
password: this.password,
host: this.host,
hostname: this.hostname,
port: this.port,
pathname: this.pathname,
search: this.search,
searchParams: this.searchParams,
hash: this.hash
};
}
clone() {
return new NextURL(String(this), this[Internal].options);
}
}
//# sourceMappingURL=next-url.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,279 @@
import { AsyncLocalStorage } from "async_hooks";
import { decorateServerError, getServerError } from "next/dist/compiled/@next/react-dev-overlay/dist/middleware";
import { COMPILER_NAMES, EDGE_UNSUPPORTED_NODE_APIS } from "../../../shared/lib/constants";
import { EdgeRuntime } from "next/dist/compiled/edge-runtime";
import { readFileSync, promises as fs } from "fs";
import { validateURL } from "../utils";
import { pick } from "../../../lib/pick";
import { fetchInlineAsset } from "./fetch-inline-assets";
const WEBPACK_HASH_REGEX = /__webpack_require__\.h = function\(\) \{ return "[0-9a-f]+"; \}/g;
/**
* A Map of cached module contexts indexed by the module name. It allows
* to have a different cache scoped per module name or depending on the
* provided module key on creation.
*/ const moduleContexts = new Map();
/**
* For a given path a context, this function checks if there is any module
* context that contains the path with an older content and, if that's the
* case, removes the context from the cache.
*/ export function clearModuleContext(path, content) {
for (const [key, cache] of moduleContexts){
var ref;
const prev = (ref = cache == null ? void 0 : cache.paths.get(path)) == null ? void 0 : ref.replace(WEBPACK_HASH_REGEX, "");
if (typeof prev !== "undefined" && prev !== content.toString().replace(WEBPACK_HASH_REGEX, "")) {
moduleContexts.delete(key);
}
}
}
async function loadWasm(wasm) {
const modules = {};
await Promise.all(wasm.map(async (binding)=>{
const module = await WebAssembly.compile(await fs.readFile(binding.filePath));
modules[binding.name] = module;
}));
return modules;
}
function buildEnvironmentVariablesFrom(keys) {
const pairs = keys.map((key)=>[
key,
process.env[key]
]);
const env = Object.fromEntries(pairs);
env.NEXT_RUNTIME = "edge";
return env;
}
function throwUnsupportedAPIError(name) {
const error = new Error(`A Node.js API is used (${name}) which is not supported in the Edge Runtime.
Learn more: https://nextjs.org/docs/api-reference/edge-runtime`);
decorateServerError(error, COMPILER_NAMES.edgeServer);
throw error;
}
function createProcessPolyfill(options) {
const env = buildEnvironmentVariablesFrom(options.env);
const processPolyfill = {
env
};
const overridenValue = {};
for (const key of Object.keys(process)){
if (key === "env") continue;
Object.defineProperty(processPolyfill, key, {
get () {
if (overridenValue[key]) {
return overridenValue[key];
}
if (typeof process[key] === "function") {
return ()=>throwUnsupportedAPIError(`process.${key}`);
}
return undefined;
},
set (value) {
overridenValue[key] = value;
},
enumerable: false
});
}
return processPolyfill;
}
function addStub(context, name) {
Object.defineProperty(context, name, {
get () {
return function() {
throwUnsupportedAPIError(name);
};
},
enumerable: false
});
}
function getDecorateUnhandledError(runtime) {
const EdgeRuntimeError = runtime.evaluate(`Error`);
return (error)=>{
if (error instanceof EdgeRuntimeError) {
decorateServerError(error, COMPILER_NAMES.edgeServer);
}
};
}
function getDecorateUnhandledRejection(runtime) {
const EdgeRuntimeError = runtime.evaluate(`Error`);
return (rejected)=>{
if (rejected.reason instanceof EdgeRuntimeError) {
decorateServerError(rejected.reason, COMPILER_NAMES.edgeServer);
}
};
}
/**
* Create a module cache specific for the provided parameters. It includes
* a runtime context, require cache and paths cache.
*/ async function createModuleContext(options) {
const warnedEvals = new Set();
const warnedWasmCodegens = new Set();
const wasm = await loadWasm(options.edgeFunctionEntry.wasm ?? []);
const runtime = new EdgeRuntime({
codeGeneration: process.env.NODE_ENV !== "production" ? {
strings: true,
wasm: true
} : undefined,
extend: (context)=>{
context.process = createProcessPolyfill(options);
context.__next_eval__ = function __next_eval__(fn) {
const key = fn.toString();
if (!warnedEvals.has(key)) {
const warning = getServerError(new Error(`Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation`), COMPILER_NAMES.edgeServer);
warning.name = "DynamicCodeEvaluationWarning";
Error.captureStackTrace(warning, __next_eval__);
warnedEvals.add(key);
options.onWarning(warning);
}
return fn();
};
context.__next_webassembly_compile__ = function __next_webassembly_compile__(fn) {
const key = fn.toString();
if (!warnedWasmCodegens.has(key)) {
const warning = getServerError(new Error(`Dynamic WASM code generation (e. g. 'WebAssembly.compile') not allowed in Edge Runtime.
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation`), COMPILER_NAMES.edgeServer);
warning.name = "DynamicWasmCodeGenerationWarning";
Error.captureStackTrace(warning, __next_webassembly_compile__);
warnedWasmCodegens.add(key);
options.onWarning(warning);
}
return fn();
};
context.__next_webassembly_instantiate__ = async function __next_webassembly_instantiate__(fn) {
const result = await fn();
// If a buffer is given, WebAssembly.instantiate returns an object
// containing both a module and an instance while it returns only an
// instance if a WASM module is given. Utilize the fact to determine
// if the WASM code generation happens.
//
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate#primary_overload_%E2%80%94_taking_wasm_binary_code
const instantiatedFromBuffer = result.hasOwnProperty("module");
const key = fn.toString();
if (instantiatedFromBuffer && !warnedWasmCodegens.has(key)) {
const warning = getServerError(new Error(`Dynamic WASM code generation ('WebAssembly.instantiate' with a buffer parameter) not allowed in Edge Runtime.
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation`), COMPILER_NAMES.edgeServer);
warning.name = "DynamicWasmCodeGenerationWarning";
Error.captureStackTrace(warning, __next_webassembly_instantiate__);
warnedWasmCodegens.add(key);
options.onWarning(warning);
}
return result;
};
const __fetch = context.fetch;
context.fetch = async (input, init = {})=>{
var ref;
const assetResponse = await fetchInlineAsset({
input,
assets: options.edgeFunctionEntry.assets,
distDir: options.distDir,
context
});
if (assetResponse) {
return assetResponse;
}
init.headers = new Headers(init.headers ?? {});
const prevs = ((ref = init.headers.get(`x-middleware-subrequest`)) == null ? void 0 : ref.split(":")) || [];
const value = prevs.concat(options.moduleName).join(":");
init.headers.set("x-middleware-subrequest", value);
if (!init.headers.has("user-agent")) {
init.headers.set(`user-agent`, `Next.js Middleware`);
}
if (typeof input === "object" && "url" in input) {
return __fetch(input.url, {
...pick(input, [
"method",
"body",
"cache",
"credentials",
"integrity",
"keepalive",
"mode",
"redirect",
"referrer",
"referrerPolicy",
"signal",
]),
...init,
headers: {
...Object.fromEntries(input.headers),
...Object.fromEntries(init.headers)
}
});
}
return __fetch(String(input), init);
};
const __Request = context.Request;
context.Request = class extends __Request {
constructor(input, init){
const url = typeof input !== "string" && "url" in input ? input.url : String(input);
validateURL(url);
super(url, init);
this.next = init == null ? void 0 : init.next;
}
};
const __redirect = context.Response.redirect.bind(context.Response);
context.Response.redirect = (...args)=>{
validateURL(args[0]);
return __redirect(...args);
};
for (const name of EDGE_UNSUPPORTED_NODE_APIS){
addStub(context, name);
}
Object.assign(context, wasm);
context.AsyncLocalStorage = AsyncLocalStorage;
return context;
}
});
const decorateUnhandledError = getDecorateUnhandledError(runtime);
runtime.context.addEventListener("error", decorateUnhandledError);
const decorateUnhandledRejection = getDecorateUnhandledRejection(runtime);
runtime.context.addEventListener("unhandledrejection", decorateUnhandledRejection);
return {
runtime,
paths: new Map(),
warnedEvals: new Set()
};
}
const pendingModuleCaches = new Map();
function getModuleContextShared(options) {
let deferredModuleContext = pendingModuleCaches.get(options.moduleName);
if (!deferredModuleContext) {
deferredModuleContext = createModuleContext(options);
pendingModuleCaches.set(options.moduleName, deferredModuleContext);
}
return deferredModuleContext;
}
/**
* For a given module name this function will get a cached module
* context or create it. It will return the module context along
* with a function that allows to run some code from a given
* filepath within the context.
*/ export async function getModuleContext(options) {
let moduleContext;
if (options.useCache) {
moduleContext = moduleContexts.get(options.moduleName) || await getModuleContextShared(options);
}
if (!moduleContext) {
moduleContext = await createModuleContext(options);
moduleContexts.set(options.moduleName, moduleContext);
}
const evaluateInContext = (filepath)=>{
if (!moduleContext.paths.has(filepath)) {
const content = readFileSync(filepath, "utf-8");
try {
moduleContext == null ? void 0 : moduleContext.runtime.evaluate(content);
moduleContext.paths.set(filepath, content);
} catch (error) {
if (options.useCache) {
moduleContext == null ? void 0 : moduleContext.paths.delete(options.moduleName);
}
throw error;
}
}
};
return {
...moduleContext,
evaluateInContext
};
}
//# sourceMappingURL=context.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,27 @@
import { createReadStream, promises as fs } from "fs";
import { requestToBodyStream } from "../../body-streams";
import { resolve } from "path";
/**
* Short-circuits the `fetch` function
* to return a stream for a given asset, if a user used `new URL("file", import.meta.url)`.
* This allows to embed assets in Edge Runtime.
*/ export async function fetchInlineAsset(options) {
var ref;
const inputString = String(options.input);
if (!inputString.startsWith("blob:")) {
return;
}
const hash = inputString.replace("blob:", "");
const asset = (ref = options.assets) == null ? void 0 : ref.find((x)=>x.name === hash);
if (!asset) {
return;
}
const filePath = resolve(options.distDir, asset.filePath);
const fileIsReadable = await fs.access(filePath).then(()=>true, ()=>false);
if (fileIsReadable) {
const readStream = createReadStream(filePath);
return new options.context.Response(requestToBodyStream(options.context, Uint8Array, readStream));
}
}
//# sourceMappingURL=fetch-inline-assets.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../server/web/sandbox/fetch-inline-assets.ts"],"names":["createReadStream","promises","fs","requestToBodyStream","resolve","fetchInlineAsset","options","inputString","String","input","startsWith","hash","replace","asset","assets","find","x","name","filePath","distDir","fileIsReadable","access","then","readStream","context","Response","Uint8Array"],"mappings":"AACA,SAASA,gBAAgB,EAAEC,QAAQ,IAAIC,EAAE,QAAQ,IAAI,CAAA;AACrD,SAASC,mBAAmB,QAAQ,oBAAoB,CAAA;AACxD,SAASC,OAAO,QAAQ,MAAM,CAAA;AAE9B;;;;GAIG,CACH,OAAO,eAAeC,gBAAgB,CAACC,OAKtC,EAAiC;QAOlBA,GAAc;IAN5B,MAAMC,WAAW,GAAGC,MAAM,CAACF,OAAO,CAACG,KAAK,CAAC;IACzC,IAAI,CAACF,WAAW,CAACG,UAAU,CAAC,OAAO,CAAC,EAAE;QACpC,OAAM;KACP;IAED,MAAMC,IAAI,GAAGJ,WAAW,CAACK,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;IAC7C,MAAMC,KAAK,GAAGP,CAAAA,GAAc,GAAdA,OAAO,CAACQ,MAAM,SAAM,GAApBR,KAAAA,CAAoB,GAApBA,GAAc,CAAES,IAAI,CAAC,CAACC,CAAC,GAAKA,CAAC,CAACC,IAAI,KAAKN,IAAI,CAAC;IAC1D,IAAI,CAACE,KAAK,EAAE;QACV,OAAM;KACP;IAED,MAAMK,QAAQ,GAAGd,OAAO,CAACE,OAAO,CAACa,OAAO,EAAEN,KAAK,CAACK,QAAQ,CAAC;IACzD,MAAME,cAAc,GAAG,MAAMlB,EAAE,CAACmB,MAAM,CAACH,QAAQ,CAAC,CAACI,IAAI,CACnD,IAAM,IAAI,EACV,IAAM,KAAK,CACZ;IAED,IAAIF,cAAc,EAAE;QAClB,MAAMG,UAAU,GAAGvB,gBAAgB,CAACkB,QAAQ,CAAC;QAC7C,OAAO,IAAIZ,OAAO,CAACkB,OAAO,CAACC,QAAQ,CACjCtB,mBAAmB,CAACG,OAAO,CAACkB,OAAO,EAAEE,UAAU,EAAEH,UAAU,CAAC,CAC7D,CAAA;KACF;CACF"}

View File

@@ -0,0 +1,4 @@
export * from "./sandbox";
export { clearModuleContext } from "./context";
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../server/web/sandbox/index.ts"],"names":["clearModuleContext"],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,SAASA,kBAAkB,QAAQ,WAAW,CAAA"}

View File

@@ -0,0 +1,82 @@
import { getServerError } from "next/dist/compiled/@next/react-dev-overlay/dist/middleware";
import { getModuleContext } from "./context";
import { requestToBodyStream } from "../../body-streams";
export const ErrorSource = Symbol("SandboxError");
const FORBIDDEN_HEADERS = [
"content-length",
"content-encoding",
"transfer-encoding",
];
/**
* Decorates the runner function making sure all errors it can produce are
* tagged with `edge-server` so they can properly be rendered in dev.
*/ function withTaggedErrors(fn) {
return (params)=>{
return fn(params).then((result)=>{
var ref;
return {
...result,
waitUntil: result == null ? void 0 : (ref = result.waitUntil) == null ? void 0 : ref.catch((error)=>{
// TODO: used COMPILER_NAMES.edgeServer instead. Verify that it does not increase the runtime size.
throw getServerError(error, "edge-server");
})
};
}).catch((error)=>{
// TODO: used COMPILER_NAMES.edgeServer instead
throw getServerError(error, "edge-server");
});
};
}
export const getRuntimeContext = async (params)=>{
const { runtime , evaluateInContext } = await getModuleContext({
moduleName: params.name,
onWarning: params.onWarning ?? (()=>{}),
useCache: params.useCache !== false,
env: params.env,
edgeFunctionEntry: params.edgeFunctionEntry,
distDir: params.distDir
});
for (const paramPath of params.paths){
evaluateInContext(paramPath);
}
return runtime;
};
export const run = withTaggedErrors(async (params)=>{
var ref;
const runtime = await getRuntimeContext(params);
const subreq = params.request.headers[`x-middleware-subrequest`];
const subrequests = typeof subreq === "string" ? subreq.split(":") : [];
if (subrequests.includes(params.name)) {
return {
waitUntil: Promise.resolve(),
response: new runtime.context.Response(null, {
headers: {
"x-middleware-next": "1"
}
})
};
}
const edgeFunction = runtime.context._ENTRIES[`middleware_${params.name}`].default;
const cloned = ![
"HEAD",
"GET"
].includes(params.request.method) ? (ref = params.request.body) == null ? void 0 : ref.cloneBodyStream() : undefined;
const KUint8Array = runtime.evaluate("Uint8Array");
try {
const result = await edgeFunction({
request: {
...params.request,
body: cloned && requestToBodyStream(runtime.context, KUint8Array, cloned)
}
});
for (const headerName of FORBIDDEN_HEADERS){
result.response.headers.delete(headerName);
}
return result;
} finally{
var ref1;
await ((ref1 = params.request.body) == null ? void 0 : ref1.finalize());
}
});
//# sourceMappingURL=sandbox.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../server/web/sandbox/sandbox.ts"],"names":["getServerError","getModuleContext","requestToBodyStream","ErrorSource","Symbol","FORBIDDEN_HEADERS","withTaggedErrors","fn","params","then","result","waitUntil","catch","error","getRuntimeContext","runtime","evaluateInContext","moduleName","name","onWarning","useCache","env","edgeFunctionEntry","distDir","paramPath","paths","run","subreq","request","headers","subrequests","split","includes","Promise","resolve","response","context","Response","edgeFunction","_ENTRIES","default","cloned","method","body","cloneBodyStream","undefined","KUint8Array","evaluate","headerName","delete","finalize"],"mappings":"AACA,SAASA,cAAc,QAAQ,4DAA4D,CAAA;AAC3F,SAASC,gBAAgB,QAAQ,WAAW,CAAA;AAE5C,SAASC,mBAAmB,QAAQ,oBAAoB,CAAA;AAGxD,OAAO,MAAMC,WAAW,GAAGC,MAAM,CAAC,cAAc,CAAC,CAAA;AAEjD,MAAMC,iBAAiB,GAAG;IACxB,gBAAgB;IAChB,kBAAkB;IAClB,mBAAmB;CACpB;AAaD;;;GAGG,CACH,SAASC,gBAAgB,CAACC,EAAY,EAAY;IAChD,OAAO,CAACC,MAAM;QACZD,OAAAA,EAAE,CAACC,MAAM,CAAC,CACPC,IAAI,CAAC,CAACC,MAAM;gBAEAA,GAAiB;YAFZ,OAAC;gBACjB,GAAGA,MAAM;gBACTC,SAAS,EAAED,M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AA;KACd,QAAS;YACFF,IAAmB;QAAzB,OAAMA,CAAAA,IAAmB,GAAnBA,MAAM,CAACoB,OAAO,CAACe,IAAI,SAAU,GAA7BnC,KAAAA,CAA6B,GAA7BA,IAAmB,CAAE0C,QAAQ,EAAE,CAAA;KACtC;CACF,CAAC,CAAA"}

View File

@@ -0,0 +1,19 @@
/**
* A simple caching behavior.
* We cache the result based on the key `K`
* which uses referential equality, to avoid re-computing
* the result for the same key.
*/ export function cached(generate) {
let cache = undefined;
return (key)=>{
if ((cache == null ? void 0 : cache.key) !== key) {
cache = {
key,
value: generate(key)
};
}
return cache.value;
};
}
//# sourceMappingURL=cached.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../server/web/spec-extension/cookies/cached.ts"],"names":["cached","generate","cache","undefined","key","value"],"mappings":"AAAA;;;;;GAKG,CACH,OAAO,SAASA,MAAM,CAAOC,QAAuB,EAAE;IACpD,IAAIC,KAAK,GAAqCC,SAAS;IACvD,OAAO,CAACC,GAAM,GAAK;QACjB,IAAIF,CAAAA,KAAK,QAAK,GAAVA,KAAAA,CAAU,GAAVA,KAAK,CAAEE,GAAG,CAAA,KAAKA,GAAG,EAAE;YACtBF,KAAK,GAAG;gBAAEE,GAAG;gBAAEC,KAAK,EAAEJ,QAAQ,CAACG,GAAG,CAAC;aAAE;SACtC;QAED,OAAOF,KAAK,CAACG,KAAK,CAAA;KACnB,CAAA;CACF"}

View File

@@ -0,0 +1,4 @@
export { RequestCookies } from "./request-cookies";
export { ResponseCookies } from "./response-cookies";
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../server/web/spec-extension/cookies/index.ts"],"names":["RequestCookies","ResponseCookies"],"mappings":"AAEA,SAASA,cAAc,QAAQ,mBAAmB,CAAA;AAClD,SAASC,eAAe,QAAQ,oBAAoB,CAAA"}

View File

@@ -0,0 +1,77 @@
import { parseCookieString, serialize } from "./serialize";
/**
* A class for manipulating {@link Request} cookies (`Cookie` header).
*/ export class RequestCookies {
_parsed = new Map();
constructor(requestHeaders){
this._headers = requestHeaders;
const header = requestHeaders.get("cookie");
if (header) {
const parsed = parseCookieString(header);
for (const [name, value] of parsed){
this._parsed.set(name, {
name,
value
});
}
}
}
[Symbol.iterator]() {
return this._parsed[Symbol.iterator]();
}
/**
* The amount of cookies received from the client
*/ get size() {
return this._parsed.size;
}
get(...args) {
const name = typeof args[0] === "string" ? args[0] : args[0].name;
return this._parsed.get(name);
}
getAll(...args) {
var ref;
const all = Array.from(this._parsed);
if (!args.length) {
return all.map(([_, value])=>value);
}
const name = typeof args[0] === "string" ? args[0] : (ref = args[0]) == null ? void 0 : ref.name;
return all.filter(([n])=>n === name).map(([_, value])=>value);
}
has(name) {
return this._parsed.has(name);
}
set(...args) {
const [name, value] = args.length === 1 ? [
args[0].name,
args[0].value
] : args;
const map = this._parsed;
map.set(name, {
name,
value
});
this._headers.set("cookie", Array.from(map).map(([_, v])=>serialize(v)).join("; "));
return this;
}
/**
* Delete the cookies matching the passed name or names in the request.
*/ delete(/** Name or names of the cookies to be deleted */ names) {
const map = this._parsed;
const result = !Array.isArray(names) ? map.delete(names) : names.map((name)=>map.delete(name));
this._headers.set("cookie", Array.from(map).map(([_, value])=>serialize(value)).join("; "));
return result;
}
/**
* Delete all the cookies in the cookies in the request.
*/ clear() {
this.delete(Array.from(this._parsed.keys()));
return this;
}
/**
* Format the cookies in the request as a string for logging
*/ [Symbol.for("edge-runtime.inspect.custom")]() {
return `RequestCookies ${JSON.stringify(Object.fromEntries(this._parsed))}`;
}
}
//# sourceMappingURL=request-cookies.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../server/web/spec-extension/cookies/request-cookies.ts"],"names":["parseCookieString","serialize","RequestCookies","_parsed","Map","constructor","requestHeaders","_headers","header","get","parsed","name","value","set","Symbol","iterator","size","args","getAll","all","Array","from","length","map","_","filter","n","has","v","join","delete","names","result","isArray","clear","keys","for","JSON","stringify","Object","fromEntries"],"mappings":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ACH;QACrB,MAAMR,GAAG,GAAG,IAAI,CAACpB,OAAO;QACxB,MAAM6B,MAAM,GAAG,CAACZ,KAAK,CAACa,OAAO,CAACF,KAAK,CAAC,GAChCR,GAAG,CAACO,MAAM,CAACC,KAAK,CAAC,GACjBA,KAAK,CAACR,GAAG,CAAC,CAACZ,IAAI,GAAKY,GAAG,CAACO,MAAM,CAACnB,IAAI,CAAC,CAAC;QACzC,IAAI,CAACJ,QAAQ,CAACM,GAAG,CACf,QAAQ,EACRO,KAAK,CAACC,IAAI,CAACE,GAAG,CAAC,CACZA,GAAG,CAAC,CAAC,CAACC,CAAC,EAAEZ,KAAK,CAAC,GAAKX,SAAS,CAACW,KAAK,CAAC,CAAC,CACrCiB,IAAI,CAAC,IAAI,CAAC,CACd;QACD,OAAOG,MAAM,CAAA;KACd;IAED;;KAEG,CACHE,KAAK,GAAS;QACZ,IAAI,CAACJ,MAAM,CAACV,KAAK,CAACC,IAAI,CAAC,IAAI,CAAClB,OAAO,CAACgC,IAAI,EAAE,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAA;KACZ;IAED;;KAEG,CACH,CAACrB,MAAM,CAACsB,GAAG,CAAC,6BAA6B,CAAC,CAAC,GAAG;QAC5C,OAAO,CAAC,eAAe,EAAEC,IAAI,CAACC,SAAS,CAACC,MAAM,CAACC,WAAW,CAAC,IAAI,CAACrC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;KAC5E;CACF"}

View File

@@ -0,0 +1,87 @@
import { parseSetCookieString, serialize } from "./serialize";
function replace(bag, headers) {
headers.delete("set-cookie");
for (const [, value] of bag){
const serialized = serialize(value);
headers.append("set-cookie", serialized);
}
}
function normalizeCookie(cookie = {
name: "",
value: ""
}) {
if (cookie.maxAge) {
cookie.expires = new Date(Date.now() + cookie.maxAge * 1000);
}
if (cookie.path === null || cookie.path === undefined) {
cookie.path = "/";
}
return cookie;
}
/**
* A class for manipulating {@link Response} cookies (`Set-Cookie` header).
* Loose implementation of the experimental [Cookie Store API](https://wicg.github.io/cookie-store/#dictdef-cookie)
* The main difference is `ResponseCookies` methods do not return a Promise.
*/ export class ResponseCookies {
_parsed = new Map();
constructor(responseHeaders){
this._headers = responseHeaders;
// @ts-expect-error See https://github.com/whatwg/fetch/issues/973
const headers = this._headers.getAll("set-cookie");
for (const header of headers){
const parsed = parseSetCookieString(header);
if (parsed) {
this._parsed.set(parsed.name, parsed);
}
}
}
/**
* {@link https://wicg.github.io/cookie-store/#CookieStore-get CookieStore#get} without the Promise.
*/ get(...args) {
const key = typeof args[0] === "string" ? args[0] : args[0].name;
return this._parsed.get(key);
}
/**
* {@link https://wicg.github.io/cookie-store/#CookieStore-getAll CookieStore#getAll} without the Promise.
*/ getAll(...args) {
var ref;
const all = Array.from(this._parsed.values());
if (!args.length) {
return all;
}
const key = typeof args[0] === "string" ? args[0] : (ref = args[0]) == null ? void 0 : ref.name;
return all.filter((c)=>c.name === key);
}
/**
* {@link https://wicg.github.io/cookie-store/#CookieStore-set CookieStore#set} without the Promise.
*/ set(...args) {
const [name, value, cookie] = args.length === 1 ? [
args[0].name,
args[0].value,
args[0]
] : args;
const map = this._parsed;
map.set(name, normalizeCookie({
name,
value,
...cookie
}));
replace(map, this._headers);
return this;
}
/**
* {@link https://wicg.github.io/cookie-store/#CookieStore-delete CookieStore#delete} without the Promise.
*/ delete(...args) {
const name = typeof args[0] === "string" ? args[0] : args[0].name;
return this.set({
name,
value: "",
expires: new Date(0)
});
}
[Symbol.for("edge-runtime.inspect.custom")]() {
return `ResponseCookies ${JSON.stringify(Object.fromEntries(this._parsed))}`;
}
}
//# sourceMappingURL=response-cookies.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../server/web/spec-extension/cookies/response-cookies.ts"],"names":["parseSetCookieString","serialize","replace","bag","headers","delete","value","serialized","append","normalizeCookie","cookie","name","maxAge","expires","Date","now","path","undefined","ResponseCookies","_parsed","Map","constructor","responseHeaders","_headers","getAll","header","parsed","set","get","args","key","all","Array","from","values","length","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,IAAI,EAAEF,eAAe,CAAC;YAAEE,IAAI;YAAEL,KAAK;YAAE,GAAGI,MAAM;SAAE,CAAC,CAAC;QAC1DR,OAAO,CAACoC,GAAG,EAAE,IAAI,CAACf,QAAQ,CAAC;QAE3B,OAAO,IAAI,CAAA;KACZ;IAED;;KAEG,CACHlB,MAAM,CAAC,GAAGwB,IAAI,AAA2C,EAAQ;QAC/D,MAAMlB,IAAI,GAAG,OAAOkB,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,GAAGA,IAAI,CAAC,CAAC,CAAC,GAAGA,IAAI,CAAC,CAAC,CAAC,CAAClB,IAAI;QACjE,OAAO,IAAI,CAACgB,GAAG,CAAC;YAAEhB,IAAI;YAAEL,KAAK,EAAE,EAAE;YAAEO,OAAO,EAAE,IAAIC,IAAI,CAAC,CAAC,CAAC;SAAE,CAAC,CAAA;KAC3D;IAED,CAACyB,MAAM,CAACC,GAAG,CAAC,6BAA6B,CAAC,CAAC,GAAG;QAC5C,OAAO,CAAC,gBAAgB,EAAEC,IAAI,CAACC,SAAS,CAACC,MAAM,CAACC,WAAW,CAAC,IAAI,CAACzB,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;KAC7E;CACF"}

View File

@@ -0,0 +1,77 @@
const SAME_SITE = [
"strict",
"lax",
"none"
];
function parseSameSite(string) {
string = string.toLowerCase();
return SAME_SITE.includes(string) ? string : undefined;
}
function compact(t) {
const newT = {};
for(const key in t){
if (t[key]) {
newT[key] = t[key];
}
}
return newT;
}
export function serialize(c) {
const attrs = [
"path" in c && c.path && `Path=${c.path}`,
"expires" in c && c.expires && `Expires=${c.expires.toUTCString()}`,
"maxAge" in c && c.maxAge && `Max-Age=${c.maxAge}`,
"domain" in c && c.domain && `Domain=${c.domain}`,
"secure" in c && c.secure && "Secure",
"httpOnly" in c && c.httpOnly && "HttpOnly",
"sameSite" in c && c.sameSite && `SameSite=${c.sameSite}`,
].filter(Boolean);
return `${c.name}=${encodeURIComponent(c.value ?? "")}; ${attrs.join("; ")}`;
}
/**
* Parse a `Cookie` or `Set-Cookie header value
*/ export function parseCookieString(cookie) {
const map = new Map();
for (const pair of cookie.split(/; */)){
if (!pair) continue;
const [key, value] = pair.split("=", 2);
map.set(key, decodeURIComponent(value ?? "true"));
}
return map;
}
/**
* Parse a `Set-Cookie` header value
*/ export function parseSetCookieString(setCookie) {
if (!setCookie) {
return undefined;
}
const [[name, value], ...attributes] = parseCookieString(setCookie);
const { domain , expires , httponly , maxage , path , samesite , secure } = Object.fromEntries(attributes.map(([key, v])=>[
key.toLowerCase(),
v
]));
const cookie = {
name,
value: decodeURIComponent(value),
domain,
...expires && {
expires: new Date(expires)
},
...httponly && {
httpOnly: true
},
...typeof maxage === "string" && {
maxAge: Number(maxage)
},
path,
...samesite && {
sameSite: parseSameSite(samesite)
},
...secure && {
secure: true
}
};
return compact(cookie);
}
//# sourceMappingURL=serialize.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../server/web/spec-extension/cookies/serialize.ts"],"names":["SAME_SITE","parseSameSite","string","toLowerCase","includes","undefined","compact","t","newT","key","serialize","c","attrs","path","expires","toUTCString","maxAge","domain","secure","httpOnly","sameSite","filter","Boolean","name","encodeURIComponent","value","join","parseCookieString","cookie","map","Map","pair","split","set","decodeURIComponent","parseSetCookieString","setCookie","attributes","httponly","maxage","samesite","Object","fromEntries","v","Date","Number"],"mappings":"AAEA,MAAMA,SAAS,GAAiC;IAAC,QAAQ;IAAE,KAAK;IAAE,MAAM;CAAC;AACzE,SAASC,aAAa,CAACC,MAAc,EAA8B;IACjEA,MAAM,GAAGA,MAAM,CAACC,WAAW,EAAE;IAC7B,OAAOH,SAAS,CAACI,QAAQ,CAACF,MAAM,CAAQ,GACnCA,MAAM,GACPG,SAAS,CAAA;CACd;AAED,SAASC,OAAO,CAAIC,CAAI,EAAK;IAC3B,MAAMC,IAAI,GAAG,EAAE,AAAc;IAC7B,IAAK,MAAMC,GAAG,IAAIF,CAAC,CAAE;QACnB,IAA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;QACJ,GAAI2B,QAAQ,IAAI;YAAEpB,QAAQ,EAAEnB,aAAa,CAACuC,QAAQ,CAAC;SAAE;QACrD,GAAItB,MAAM,IAAI;YAAEA,MAAM,EAAE,IAAI;SAAE;KAC/B;IAED,OAAOZ,OAAO,CAACsB,MAAM,CAAC,CAAA;CACvB"}

View File

@@ -0,0 +1,3 @@
export { };
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../server/web/spec-extension/cookies/types.ts"],"names":[],"mappings":"AAAA,WAgHkE"}

View File

@@ -0,0 +1,47 @@
import { PageSignatureError } from "../error";
const responseSymbol = Symbol("response");
const passThroughSymbol = Symbol("passThrough");
export const waitUntilSymbol = Symbol("waitUntil");
class FetchEvent {
[waitUntilSymbol] = [];
[passThroughSymbol] = false;
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
constructor(_request){}
respondWith(response) {
if (!this[responseSymbol]) {
this[responseSymbol] = Promise.resolve(response);
}
}
passThroughOnException() {
this[passThroughSymbol] = true;
}
waitUntil(promise) {
this[waitUntilSymbol].push(promise);
}
}
export class NextFetchEvent extends FetchEvent {
constructor(params){
super(params.request);
this.sourcePage = params.page;
}
/**
* @deprecated The `request` is now the first parameter and the API is now async.
*
* Read more: https://nextjs.org/docs/messages/middleware-new-signature
*/ get request() {
throw new PageSignatureError({
page: this.sourcePage
});
}
/**
* @deprecated Using `respondWith` is no longer needed.
*
* Read more: https://nextjs.org/docs/messages/middleware-new-signature
*/ respondWith() {
throw new PageSignatureError({
page: this.sourcePage
});
}
}
//# sourceMappingURL=fetch-event.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../server/web/spec-extension/fetch-event.ts"],"names":["PageSignatureError","responseSymbol","Symbol","passThroughSymbol","waitUntilSymbol","FetchEvent","constructor","_request","respondWith","response","Promise","resolve","passThroughOnException","waitUntil","promise","push","NextFetchEvent","params","request","sourcePage","page"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,UAAU,CAAA;AAG7C,MAAMC,cAAc,GAAGC,MAAM,CAAC,UAAU,CAAC;AACzC,MAAMC,iBAAiB,GAAGD,MAAM,CAAC,aAAa,CAAC;AAC/C,OAAO,MAAME,eAAe,GAAGF,MAAM,CAAC,WAAW,CAAC,CAAA;AAElD,MAAMG,UAAU;IACL,CAACD,eAAe,CAAC,GAAmB,EAAE,CAAC;IAEhD,CAACD,iBAAiB,CAAC,GAAG,KAAK,CAAA;IAE3B,qEAAqE;IACrEG,YAAYC,QAAiB,CAAE,EAAE;IAEjCC,WAAW,CAACC,QAAsC,EAAQ;QACxD,IAAI,CAAC,IAAI,CAACR,cAAc,CAAC,EAAE;YACzB,IAAI,CAACA,cAAc,CAAC,GAAGS,OAAO,CAACC,OAAO,CAACF,QAAQ,CAAC;SACjD;KACF;IAEDG,sBAAsB,GAAS;QAC7B,IAAI,CAACT,iBAAiB,CAAC,GAAG,IAAI;KAC/B;IAEDU,SAAS,CAACC,OAAqB,EAAQ;QACrC,IAAI,CAACV,eAAe,CAAC,CAACW,IAAI,CAACD,OAAO,CAAC;KACpC;CACF;AAED,OAAO,MAAME,cAAc,SAASX,UAAU;IAG5CC,YAAYW,MAA8C,CAAE;QAC1D,KAAK,CAACA,MAAM,CAACC,OAAO,CAAC;QACrB,IAAI,CAACC,UAAU,GAAGF,MAAM,CAACG,IAAI;KAC9B;IAED;;;;KAIG,CACH,IAAIF,OAAO,GAAG;QACZ,MAAM,IAAIlB,kBAAkB,CAAC;YAC3BoB,IAAI,EAAE,IAAI,CAACD,UAAU;SACtB,CAAC,CAAA;KACH;IAED;;;;KAIG,CACHX,WAAW,GAAG;QACZ,MAAM,IAAIR,kBAAkB,CAAC;YAC3BoB,IAAI,EAAE,IAAI,CAACD,UAAU;SACtB,CAAC,CAAA;KACH;CACF"}

View File

@@ -0,0 +1,75 @@
import { NextURL } from "../next-url";
import { toNodeHeaders, validateURL } from "../utils";
import { RemovedUAError, RemovedPageError } from "../error";
import { RequestCookies } from "./cookies";
export const INTERNALS = Symbol("internal request");
export class NextRequest extends Request {
constructor(input, init = {}){
const url = typeof input !== "string" && "url" in input ? input.url : String(input);
validateURL(url);
super(url, init);
this[INTERNALS] = {
cookies: new RequestCookies(this.headers),
geo: init.geo || {},
ip: init.ip,
url: new NextURL(url, {
headers: toNodeHeaders(this.headers),
nextConfig: init.nextConfig
})
};
}
[Symbol.for("edge-runtime.inspect.custom")]() {
return {
cookies: this.cookies,
geo: this.geo,
ip: this.ip,
nextUrl: this.nextUrl,
url: this.url,
// rest of props come from Request
bodyUsed: this.bodyUsed,
cache: this.cache,
credentials: this.credentials,
destination: this.destination,
headers: Object.fromEntries(this.headers),
integrity: this.integrity,
keepalive: this.keepalive,
method: this.method,
mode: this.mode,
redirect: this.redirect,
referrer: this.referrer,
referrerPolicy: this.referrerPolicy,
signal: this.signal
};
}
get cookies() {
return this[INTERNALS].cookies;
}
get geo() {
return this[INTERNALS].geo;
}
get ip() {
return this[INTERNALS].ip;
}
get nextUrl() {
return this[INTERNALS].url;
}
/**
* @deprecated
* `page` has been deprecated in favour of `URLPattern`.
* Read more: https://nextjs.org/docs/messages/middleware-request-page
*/ get page() {
throw new RemovedPageError();
}
/**
* @deprecated
* `ua` has been removed in favour of \`userAgent\` function.
* Read more: https://nextjs.org/docs/messages/middleware-parse-user-agent
*/ get ua() {
throw new RemovedUAError();
}
get url() {
return this[INTERNALS].url.toString();
}
}
//# sourceMappingURL=request.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../server/web/spec-extension/request.ts"],"names":["NextURL","toNodeHeaders","validateURL","RemovedUAError","RemovedPageError","RequestCookies","INTERNALS","Symbol","NextRequest","Request","constructor","input","init","url","String","cookies","headers","geo","ip","nextConfig","for","nextUrl","bodyUsed","cache","credentials","destination","Object","fromEntries","integrity","keepalive","method","mode","redirect","referrer","referrerPolicy","signal","page","ua","toString"],"mappings":"AAEA,SAASA,OAAO,QAAQ,aAAa,CAAA;AACrC,SAASC,aAAa,EAAEC,WAAW,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W,EAAE,IAAI,CAACA,WAAW;YAC7BT,OAAO,EAAEU,MAAM,CAACC,WAAW,CAAC,IAAI,CAACX,OAAO,CAAC;YACzCY,SAAS,EAAE,IAAI,CAACA,SAAS;YACzBC,SAAS,EAAE,IAAI,CAACA,SAAS;YACzBC,MAAM,EAAE,IAAI,CAACA,MAAM;YACnBC,IAAI,EAAE,IAAI,CAACA,IAAI;YACfC,QAAQ,EAAE,IAAI,CAACA,QAAQ;YACvBC,QAAQ,EAAE,IAAI,CAACA,QAAQ;YACvBC,cAAc,EAAE,IAAI,CAACA,cAAc;YACnCC,MAAM,EAAE,IAAI,CAACA,MAAM;SACpB,CAAA;KACF;IAED,IAAWpB,OAAO,GAAG;QACnB,OAAO,IAAI,CAACT,SAAS,CAAC,CAACS,OAAO,CAAA;KAC/B;IAED,IAAWE,GAAG,GAAG;QACf,OAAO,IAAI,CAACX,SAAS,CAAC,CAACW,GAAG,CAAA;KAC3B;IAED,IAAWC,EAAE,GAAG;QACd,OAAO,IAAI,CAACZ,SAAS,CAAC,CAACY,EAAE,CAAA;KAC1B;IAED,IAAWG,OAAO,GAAG;QACnB,OAAO,IAAI,CAACf,SAAS,CAAC,CAACO,GAAG,CAAA;KAC3B;IAED;;;;KAIG,CACH,IAAWuB,IAAI,GAAG;QAChB,MAAM,IAAIhC,gBAAgB,EAAE,CAAA;KAC7B;IAED;;;;KAIG,CACH,IAAWiC,EAAE,GAAG;QACd,MAAM,IAAIlC,cAAc,EAAE,CAAA;KAC3B;IAED,IAAWU,GAAG,GAAG;QACf,OAAO,IAAI,CAACP,SAAS,CAAC,CAACO,GAAG,CAACyB,QAAQ,EAAE,CAAA;KACtC;CACF"}

View File

@@ -0,0 +1,94 @@
import { NextURL } from "../next-url";
import { toNodeHeaders, validateURL } from "../utils";
import { ResponseCookies } from "./cookies";
const INTERNALS = Symbol("internal response");
const REDIRECTS = new Set([
301,
302,
303,
307,
308
]);
function handleMiddlewareField(init, headers) {
var ref;
if (init == null ? void 0 : (ref = init.request) == null ? void 0 : ref.headers) {
if (!(init.request.headers instanceof Headers)) {
throw new Error("request.headers must be an instance of Headers");
}
const keys = [];
for (const [key, value] of init.request.headers){
headers.set("x-middleware-request-" + key, value);
keys.push(key);
}
headers.set("x-middleware-override-headers", keys.join(","));
}
}
export class NextResponse extends Response {
constructor(body, init = {}){
super(body, init);
this[INTERNALS] = {
cookies: new ResponseCookies(this.headers),
url: init.url ? new NextURL(init.url, {
headers: toNodeHeaders(this.headers),
nextConfig: init.nextConfig
}) : undefined
};
}
[Symbol.for("edge-runtime.inspect.custom")]() {
return {
cookies: this.cookies,
url: this.url,
// rest of props come from Response
body: this.body,
bodyUsed: this.bodyUsed,
headers: Object.fromEntries(this.headers),
ok: this.ok,
redirected: this.redirected,
status: this.status,
statusText: this.statusText,
type: this.type
};
}
get cookies() {
return this[INTERNALS].cookies;
}
static json(body, init) {
// @ts-expect-error This is not in lib/dom right now, and we can't augment it.
const response = Response.json(body, init);
return new NextResponse(response.body, response);
}
static redirect(url, init) {
const status = typeof init === "number" ? init : (init == null ? void 0 : init.status) ?? 307;
if (!REDIRECTS.has(status)) {
throw new RangeError('Failed to execute "redirect" on "response": Invalid status code');
}
const initObj = typeof init === "object" ? init : {};
const headers = new Headers(initObj == null ? void 0 : initObj.headers);
headers.set("Location", validateURL(url));
return new NextResponse(null, {
...initObj,
headers,
status
});
}
static rewrite(destination, init) {
const headers = new Headers(init == null ? void 0 : init.headers);
headers.set("x-middleware-rewrite", validateURL(destination));
handleMiddlewareField(init, headers);
return new NextResponse(null, {
...init,
headers
});
}
static next(init) {
const headers = new Headers(init == null ? void 0 : init.headers);
headers.set("x-middleware-next", "1");
handleMiddlewareField(init, headers);
return new NextResponse(null, {
...init,
headers
});
}
}
//# sourceMappingURL=response.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../server/web/spec-extension/response.ts"],"names":["NextURL","toNodeHeaders","validateURL","ResponseCookies","INTERNALS","Symbol","REDIRECTS","Set","handleMiddlewareField","init","headers","request","Headers","Error","keys","key","value","set","push","join","NextResponse","Response","constructor","body","cookies","url","nextConfig","undefined","for","bodyUsed","Object","fromEntries","ok","redirected","status","statusText","type","json","response","redirect","has","RangeError","initObj","rewrite","destination","next"],"mappings":"AACA,SAASA,OAAO,QAAQ,aAAa,CAAA;AACrC,SAASC,aAAa,EAAEC,WAAW,QAAQ,UAAU,CAAA;AAErD,SAASC,eAAe,QAAQ,WAAW,CAAA;AAE3C,MAAMC,SAAS,GAAGC,MAAM,CAAC,mBAAmB,CAAC;AAC7C,MAAMC,SAAS,GAAG,IAAIC,GAAG,CAAC;AAAC,OAAG;AAAE,OAAG;AAAE,OAAG;AAAE,OAAG;AAAE,OAAG;CAAC,CAAC;AAEpD,SAASC,qBAAqB,CAC5BC,IAAwC,EACxCC,OAAgB,EAChB;QACID,GAAa;IAAjB,IAAIA,IAAI,QAAS,GAAbA,KAAAA,CAAa,GAAbA,CAAAA,GAAa,GAAbA,IAAI,CAAEE,OAAO,SAAA,GAAbF,KAAAA,CAAa,GAAbA,GAAa,CAAEC,OAAO,AAAT,EAAW;QAC1B,IAAI,CAAC,CAACD,IAAI,CAACE,OAAO,CAACD,OAAO,YAAYE,OAAO,CAAC,EAAE;YAC9C,MAAM,IAAIC,KAAK,CAAC,gDAAgD,CAAC,CAAA;SAClE;QAED,MAAMC,IAAI,GAAG,EAAE;QACf,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIP,IAAI,CAACE,OAAO,CAACD,OAAO,CAAE;YAC/CA,OAAO,CAACO,GAAG,CAAC,uBAAuB,GAAGF,GAAG,EAAEC,KAAK,CAAC;YACjDF,IAAI,CAACI,IAAI,CAACH,GAAG,CAAC;SACf;QAEDL,OAAO,CAACO,GAAG,CAAC,+BAA+B,EAAEH,IAAI,CAACK,IAAI,CAAC,GAAG,CAAC,CAAC;KAC7D;CACF;AAED,OAAO,MAAMC,YAAY,SAASC,QAAQ;IAMxCC,YAAYC,IAAsB,EAAEd,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,CAAa,GAAbA,IAAI,CAAEC,OAAO,CAAC;QAC1CA,OAAO,CAACO,GAAG,CAAC,mBAAmB,EAAE,GAAG,CAAC;QAErCT,qBAAqB,CAACC,IAAI,EAAEC,OAAO,CAAC;QACpC,OAAO,IAAIU,YAAY,CAAC,IAAI,EAAE;YAAE,GAAGX,IAAI;YAAEC,OAAO;SAAE,CAAC,CAAA;KACpD;CACF"}

View File

@@ -0,0 +1,15 @@
import parseua from "next/dist/compiled/ua-parser-js";
export function isBot(input) {
return /Googlebot|Mediapartners-Google|AdsBot-Google|googleweblight|Storebot-Google|Google-PageRenderer|Bingbot|BingPreview|Slurp|DuckDuckBot|baiduspider|yandex|sogou|LinkedInBot|bitlybot|tumblr|vkShare|quora link preview|facebookexternalhit|facebookcatalog|Twitterbot|applebot|redditbot|Slackbot|Discordbot|WhatsApp|SkypeUriPreview|ia_archiver/i.test(input);
}
export function userAgentFromString(input) {
return {
...parseua(input),
isBot: input === undefined ? false : isBot(input)
};
}
export function userAgent({ headers }) {
return userAgentFromString(headers.get("user-agent") || undefined);
}
//# sourceMappingURL=user-agent.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../server/web/spec-extension/user-agent.ts"],"names":["parseua","isBot","input","test","userAgentFromString","undefined","userAgent","headers","get"],"mappings":"AAAA,OAAOA,OAAO,MAAM,iCAAiC,CAAA;AA2BrD,OAAO,SAASC,KAAK,CAACC,KAAa,EAAW;IAC5C,OAAO,oVAAoVC,IAAI,CAC7VD,KAAK,CACN,CAAA;CACF;AAED,OAAO,SAASE,mBAAmB,CAACF,KAAyB,EAAa;IACxE,OAAO;QACL,GAAGF,OAAO,CAACE,KAAK,CAAC;QACjBD,KAAK,EAAEC,KAAK,KAAKG,SAAS,GAAG,KAAK,GAAGJ,KAAK,CAACC,KAAK,CAAC;KAClD,CAAA;CACF;AAED,OAAO,SAASI,SAAS,CAAC,EAAEC,OAAO,CAAA,EAAwB,EAAa;IACtE,OAAOH,mBAAmB,CAACG,OAAO,CAACC,GAAG,CAAC,YAAY,CAAC,IAAIH,SAAS,CAAC,CAAA;CACnE"}

View File

@@ -0,0 +1,3 @@
export { };
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../server/web/types.ts"],"names":[],"mappings":"AAAA,WAqDyD"}

View File

@@ -0,0 +1,103 @@
export function fromNodeHeaders(object) {
const headers = new Headers();
for (let [key, value] of Object.entries(object)){
const values = Array.isArray(value) ? value : [
value
];
for (let v of values){
if (v !== undefined) {
headers.append(key, v);
}
}
}
return headers;
}
/*
Set-Cookie header field-values are sometimes comma joined in one string. This splits them without choking on commas
that are within a single set-cookie field-value, such as in the Expires portion.
This is uncommon, but explicitly allowed - see https://tools.ietf.org/html/rfc2616#section-4.2
Node.js does this for every header *except* set-cookie - see https://github.com/nodejs/node/blob/d5e363b77ebaf1caf67cd7528224b651c86815c1/lib/_http_incoming.js#L128
React Native's fetch does this for *every* header, including set-cookie.
Based on: https://github.com/google/j2objc/commit/16820fdbc8f76ca0c33472810ce0cb03d20efe25
Credits to: https://github.com/tomball for original and https://github.com/chrusart for JavaScript implementation
*/ export function splitCookiesString(cookiesString) {
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 === ",") {
// ',' is a cookie separator if we have later first '=', not ';' or ','
lastComma = pos;
pos += 1;
skipWhitespace();
nextStart = pos;
while(pos < cookiesString.length && notSpecialChar()){
pos += 1;
}
// currently special character
if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
// we found cookies separator
cookiesSeparatorFound = true;
// pos is inside the next cookie, so back up and return it.
pos = nextStart;
cookiesStrings.push(cookiesString.substring(start, lastComma));
start = pos;
} else {
// in param ',' or param separator ';',
// we continue from that comma
pos = lastComma + 1;
}
} else {
pos += 1;
}
}
if (!cookiesSeparatorFound || pos >= cookiesString.length) {
cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
}
}
return cookiesStrings;
}
export function toNodeHeaders(headers) {
const result = {};
if (headers) {
for (const [key, value] of headers.entries()){
result[key] = value;
if (key.toLowerCase() === "set-cookie") {
result[key] = splitCookiesString(value);
}
}
}
return result;
}
/**
* Validate the correctness of a user-provided URL.
*/ export function validateURL(url) {
try {
return String(new URL(String(url)));
} catch (error) {
throw new Error(`URL is malformed "${String(url)}". Please use only absolute URLs - https://nextjs.org/docs/messages/middleware-relative-urls`, {
cause: error
});
}
}
//# sourceMappingURL=utils.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../server/web/utils.ts"],"names":["fromNodeHeaders","object","headers","Headers","key","value","Object","entries","values","Array","isArray","v","undefined","append","splitCookiesString","cookiesString","cookiesStrings","pos","start","ch","lastComma","nextStart","cookiesSeparatorFound","skipWhitespace","length","test","charAt","notSpecialChar","push","substring","toNodeHeaders","result","toLowerCase","validateURL","url","String","URL","error","Error","cause"],"mappings":"AAEA,OAAO,SAASA,eAAe,CAACC,MAAmB,EAAW;IAC5D,MAAMC,OAAO,GAAG,IAAIC,OAAO,EAAE;IAC7B,KAAK,IAAI,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACN,MAAM,CAAC,CAAE;QAC/C,MAAMO,MAAM,GAAGC,KAAK,CAACC,OAAO,CAACL,KAAK,CAAC,GAAGA,KAAK,GAAG;YAACA,KAAK;SAAC;QACrD,KAAK,IAAIM,CAAC,IAAIH,MAAM,CAAE;YACpB,IAAIG,CAAC,KAAKC,SAAS,EAAE;gBACnBV,OAAO,CAACW,MAAM,CAACT,GAAG,EAAEO,CAAC,CAAC;aACvB;SACF;KACF;IACD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