Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@tanstack/start-server-core

Package Overview
Dependencies
Maintainers
5
Versions
443
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tanstack/start-server-core - npm Package Compare versions

Comparing version
1.169.7
to
1.169.8
+26
-26
dist/esm/request-response.js
import { AsyncLocalStorage } from "node:async_hooks";
import { H3Event, clearSession, deleteCookie, getRequestHost, getRequestIP, getRequestProtocol, getRequestURL, getSession, getValidatedQuery, parseCookies, sanitizeStatusCode, sanitizeStatusMessage, sealSession, setCookie, toResponse, unsealSession, updateSession, useSession } from "h3-v2";
import { H3Event, clearSession as clearSession$1, deleteCookie as deleteCookie$1, getRequestHost as getRequestHost$1, getRequestIP as getRequestIP$1, getRequestProtocol as getRequestProtocol$1, getRequestURL, getSession as getSession$1, getValidatedQuery as getValidatedQuery$1, parseCookies, sanitizeStatusCode, sanitizeStatusMessage, sealSession as sealSession$1, setCookie as setCookie$1, toResponse, unsealSession as unsealSession$1, updateSession as updateSession$1, useSession as useSession$1 } from "h3-v2";
//#region src/request-response.ts

@@ -63,4 +63,4 @@ var GLOBAL_EVENT_STORAGE_KEY = Symbol.for("tanstack-start:event-storage");

}
function getRequestIP$1(opts) {
return getRequestIP(getH3Event(), opts);
function getRequestIP(opts) {
return getRequestIP$1(getH3Event(), opts);
}

@@ -74,4 +74,4 @@ /**

*/
function getRequestHost$1(opts) {
return getRequestHost(getH3Event(), opts);
function getRequestHost(opts) {
return getRequestHost$1(getH3Event(), opts);
}

@@ -95,4 +95,4 @@ /**

*/
function getRequestProtocol$1(opts) {
return getRequestProtocol(getH3Event(), opts);
function getRequestProtocol(opts) {
return getRequestProtocol$1(getH3Event(), opts);
}

@@ -165,4 +165,4 @@ function setResponseHeaders(headers) {

*/
function setCookie$1(name, value, options) {
setCookie(getH3Event(), name, value, options);
function setCookie(name, value, options) {
setCookie$1(getH3Event(), name, value, options);
}

@@ -177,4 +177,4 @@ /**

*/
function deleteCookie$1(name, options) {
deleteCookie(getH3Event(), name, options);
function deleteCookie(name, options) {
deleteCookie$1(getH3Event(), name, options);
}

@@ -190,4 +190,4 @@ function getDefaultSessionConfig(config) {

*/
function useSession$1(config) {
return useSession(getH3Event(), getDefaultSessionConfig(config));
function useSession(config) {
return useSession$1(getH3Event(), getDefaultSessionConfig(config));
}

@@ -197,4 +197,4 @@ /**

*/
function getSession$1(config) {
return getSession(getH3Event(), getDefaultSessionConfig(config));
function getSession(config) {
return getSession$1(getH3Event(), getDefaultSessionConfig(config));
}

@@ -204,4 +204,4 @@ /**

*/
function updateSession$1(config, update) {
return updateSession(getH3Event(), getDefaultSessionConfig(config), update);
function updateSession(config, update) {
return updateSession$1(getH3Event(), getDefaultSessionConfig(config), update);
}

@@ -211,4 +211,4 @@ /**

*/
function sealSession$1(config) {
return sealSession(getH3Event(), getDefaultSessionConfig(config));
function sealSession(config) {
return sealSession$1(getH3Event(), getDefaultSessionConfig(config));
}

@@ -218,4 +218,4 @@ /**

*/
function unsealSession$1(config, sealed) {
return unsealSession(getH3Event(), getDefaultSessionConfig(config), sealed);
function unsealSession(config, sealed) {
return unsealSession$1(getH3Event(), getDefaultSessionConfig(config), sealed);
}

@@ -225,4 +225,4 @@ /**

*/
function clearSession$1(config) {
return clearSession(getH3Event(), {
function clearSession(config) {
return clearSession$1(getH3Event(), {
name: "start",

@@ -235,8 +235,8 @@ ...config

}
function getValidatedQuery$1(schema) {
return getValidatedQuery(getH3Event(), schema);
function getValidatedQuery(schema) {
return getValidatedQuery$1(getH3Event(), schema);
}
//#endregion
export { clearResponseHeaders, clearSession$1 as clearSession, deleteCookie$1 as deleteCookie, getCookie, getCookies, getRequest, getRequestHeader, getRequestHeaders, getRequestHost$1 as getRequestHost, getRequestIP$1 as getRequestIP, getRequestProtocol$1 as getRequestProtocol, getRequestUrl, getResponse, getResponseHeader, getResponseHeaders, getResponseStatus, getSession$1 as getSession, getValidatedQuery$1 as getValidatedQuery, removeResponseHeader, requestHandler, sealSession$1 as sealSession, setCookie$1 as setCookie, setResponseHeader, setResponseHeaders, setResponseStatus, unsealSession$1 as unsealSession, updateSession$1 as updateSession, useSession$1 as useSession };
export { clearResponseHeaders, clearSession, deleteCookie, getCookie, getCookies, getRequest, getRequestHeader, getRequestHeaders, getRequestHost, getRequestIP, getRequestProtocol, getRequestUrl, getResponse, getResponseHeader, getResponseHeaders, getResponseStatus, getSession, getValidatedQuery, removeResponseHeader, requestHandler, sealSession, setCookie, setResponseHeader, setResponseHeaders, setResponseStatus, unsealSession, updateSession, useSession };
//# sourceMappingURL=request-response.js.map

@@ -1,1 +0,1 @@

{"version":3,"file":"request-response.js","names":[],"sources":["../../src/request-response.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\n\nimport {\n H3Event,\n clearSession as h3_clearSession,\n deleteCookie as h3_deleteCookie,\n getRequestHost as h3_getRequestHost,\n getRequestIP as h3_getRequestIP,\n getRequestProtocol as h3_getRequestProtocol,\n getRequestURL as h3_getRequestURL,\n getSession as h3_getSession,\n getValidatedQuery as h3_getValidatedQuery,\n parseCookies as h3_parseCookies,\n sanitizeStatusCode as h3_sanitizeStatusCode,\n sanitizeStatusMessage as h3_sanitizeStatusMessage,\n sealSession as h3_sealSession,\n setCookie as h3_setCookie,\n toResponse as h3_toResponse,\n unsealSession as h3_unsealSession,\n updateSession as h3_updateSession,\n useSession as h3_useSession,\n} from 'h3-v2'\nimport type {\n RequestHeaderMap,\n RequestHeaderName,\n ResponseHeaderMap,\n ResponseHeaderName,\n TypedHeaders,\n} from 'fetchdts'\n\nimport type { CookieSerializeOptions } from 'cookie-es'\nimport type {\n Session,\n SessionConfig,\n SessionData,\n SessionManager,\n SessionUpdate,\n} from './session'\nimport type { StandardSchemaV1 } from '@standard-schema/spec'\nimport type { RequestHandler } from './request-handler'\n\ninterface StartEvent {\n h3Event: H3Event\n}\n\n// Use a global symbol to ensure the same AsyncLocalStorage instance is shared\n// across different bundles that may each bundle this module.\nconst GLOBAL_EVENT_STORAGE_KEY = Symbol.for('tanstack-start:event-storage')\n\nconst globalObj = globalThis as typeof globalThis & {\n [GLOBAL_EVENT_STORAGE_KEY]?: AsyncLocalStorage<StartEvent>\n}\n\nif (!globalObj[GLOBAL_EVENT_STORAGE_KEY]) {\n globalObj[GLOBAL_EVENT_STORAGE_KEY] = new AsyncLocalStorage<StartEvent>()\n}\n\nconst eventStorage = globalObj[GLOBAL_EVENT_STORAGE_KEY]\n\nexport type { ResponseHeaderName, RequestHeaderName }\n\ntype HeadersWithGetSetCookie = Headers & {\n getSetCookie?: () => Array<string>\n}\n\ntype MaybePromise<T> = T | Promise<T>\n\nfunction isPromiseLike<T>(value: MaybePromise<T>): value is Promise<T> {\n return typeof (value as Promise<T>).then === 'function'\n}\n\nfunction getSetCookieValues(headers: Headers): Array<string> {\n const headersWithSetCookie = headers as HeadersWithGetSetCookie\n if (typeof headersWithSetCookie.getSetCookie === 'function') {\n return headersWithSetCookie.getSetCookie()\n }\n const value = headers.get('set-cookie')\n return value ? [value] : []\n}\n\nfunction mergeEventResponseHeaders(response: Response, event: H3Event): void {\n if (response.ok) {\n return\n }\n\n const eventSetCookies = getSetCookieValues(event.res.headers)\n if (eventSetCookies.length === 0) {\n return\n }\n\n const responseSetCookies = getSetCookieValues(response.headers)\n response.headers.delete('set-cookie')\n for (const cookie of responseSetCookies) {\n response.headers.append('set-cookie', cookie)\n }\n for (const cookie of eventSetCookies) {\n response.headers.append('set-cookie', cookie)\n }\n}\n\nfunction attachResponseHeaders<T>(\n value: MaybePromise<T>,\n event: H3Event,\n): MaybePromise<T> {\n if (isPromiseLike(value)) {\n return value.then((resolved) => {\n if (resolved instanceof Response) {\n mergeEventResponseHeaders(resolved, event)\n }\n return resolved\n })\n }\n\n if (value instanceof Response) {\n mergeEventResponseHeaders(value, event)\n }\n\n return value\n}\n\nexport function requestHandler<TRegister = unknown>(\n handler: RequestHandler<TRegister>,\n) {\n return (request: Request, requestOpts: any): Promise<Response> | Response => {\n let h3Event: H3Event\n try {\n h3Event = new H3Event(request)\n } catch (error) {\n if (error instanceof URIError) {\n return new Response(null, {\n status: 400,\n statusText: 'Bad Request',\n })\n }\n throw error\n }\n\n const response = eventStorage.run({ h3Event }, () =>\n handler(request, requestOpts),\n )\n return h3_toResponse(attachResponseHeaders(response, h3Event), h3Event)\n }\n}\n\nfunction getH3Event() {\n const event = eventStorage.getStore()\n if (!event) {\n throw new Error(\n `No StartEvent found in AsyncLocalStorage. Make sure you are using the function within the server runtime.`,\n )\n }\n return event.h3Event\n}\n\nexport function getRequest(): Request {\n const event = getH3Event()\n return event.req\n}\n\nexport function getRequestHeaders(): TypedHeaders<RequestHeaderMap> {\n return getH3Event().req.headers\n}\n\nexport function getRequestHeader(name: RequestHeaderName): string | undefined {\n return getRequestHeaders().get(name) || undefined\n}\n\nexport function getRequestIP(opts?: {\n /**\n * Use the X-Forwarded-For HTTP header set by proxies.\n *\n * Note: Make sure that this header can be trusted (your application running behind a CDN or reverse proxy) before enabling.\n */\n xForwardedFor?: boolean\n}) {\n return h3_getRequestIP(getH3Event(), opts)\n}\n\n/**\n * Get the request hostname.\n *\n * If `xForwardedHost` is `true`, it will use the `x-forwarded-host` header if it exists.\n *\n * If no host header is found, it will default to \"localhost\".\n */\nexport function getRequestHost(opts?: { xForwardedHost?: boolean }) {\n return h3_getRequestHost(getH3Event(), opts)\n}\n\n/**\n * Get the full incoming request URL.\n *\n * If `xForwardedHost` is `true`, it will use the `x-forwarded-host` header if it exists.\n *\n * If `xForwardedProto` is `false`, it will not use the `x-forwarded-proto` header.\n */\nexport function getRequestUrl(opts?: {\n xForwardedHost?: boolean\n xForwardedProto?: boolean\n}) {\n return h3_getRequestURL(getH3Event(), opts)\n}\n\n/**\n * Get the request protocol.\n *\n * If `x-forwarded-proto` header is set to \"https\", it will return \"https\". You can disable this behavior by setting `xForwardedProto` to `false`.\n *\n * If protocol cannot be determined, it will default to \"http\".\n */\nexport function getRequestProtocol(opts?: {\n xForwardedProto?: boolean\n}): 'http' | 'https' | (string & {}) {\n return h3_getRequestProtocol(getH3Event(), opts)\n}\n\nexport function setResponseHeaders(\n headers: TypedHeaders<ResponseHeaderMap>,\n): void {\n const event = getH3Event()\n for (const [name, value] of Object.entries(headers)) {\n event.res.headers.set(name, value)\n }\n}\n\nexport function getResponseHeaders(): TypedHeaders<ResponseHeaderMap> {\n const event = getH3Event()\n return event.res.headers\n}\n\nexport function getResponseHeader(\n name: ResponseHeaderName,\n): string | undefined {\n const event = getH3Event()\n return event.res.headers.get(name) || undefined\n}\n\nexport function setResponseHeader(\n name: ResponseHeaderName,\n value: string | Array<string>,\n): void {\n const event = getH3Event()\n if (Array.isArray(value)) {\n event.res.headers.delete(name)\n for (const valueItem of value) {\n event.res.headers.append(name, valueItem)\n }\n } else {\n event.res.headers.set(name, value)\n }\n}\nexport function removeResponseHeader(name: ResponseHeaderName): void {\n const event = getH3Event()\n event.res.headers.delete(name)\n}\n\nexport function clearResponseHeaders(\n headerNames?: Array<ResponseHeaderName>,\n): void {\n const event = getH3Event()\n // If headerNames is provided, clear only those headers\n if (headerNames && headerNames.length > 0) {\n for (const name of headerNames) {\n event.res.headers.delete(name)\n }\n // Otherwise, clear all headers\n } else {\n for (const name of event.res.headers.keys()) {\n event.res.headers.delete(name)\n }\n }\n}\n\nexport function getResponseStatus(): number {\n return getH3Event().res.status || 200\n}\n\nexport function setResponseStatus(code?: number, text?: string): void {\n const event = getH3Event()\n if (code) {\n event.res.status = h3_sanitizeStatusCode(code, event.res.status)\n }\n if (text) {\n event.res.statusText = h3_sanitizeStatusMessage(text)\n }\n}\n\n/**\n * Parse the request to get HTTP Cookie header string and return an object of all cookie name-value pairs.\n * @returns Object of cookie name-value pairs\n * ```ts\n * const cookies = getCookies()\n * ```\n */\nexport function getCookies(): Record<string, string> {\n const event = getH3Event()\n const cookies = h3_parseCookies(event)\n const definedCookies: Record<string, string> = Object.create(null)\n\n for (const [name, value] of Object.entries(cookies)) {\n if (value !== undefined) {\n definedCookies[name] = value\n }\n }\n\n return definedCookies\n}\n\n/**\n * Get a cookie value by name.\n * @param name Name of the cookie to get\n * @returns {*} Value of the cookie (String or undefined)\n * ```ts\n * const authorization = getCookie('Authorization')\n * ```\n */\nexport function getCookie(name: string): string | undefined {\n return getCookies()[name]\n}\n\n/**\n * Set a cookie value by name.\n * @param name Name of the cookie to set\n * @param value Value of the cookie to set\n * @param options {CookieSerializeOptions} Options for serializing the cookie\n * ```ts\n * setCookie('Authorization', '1234567')\n * ```\n */\nexport function setCookie(\n name: string,\n value: string,\n options?: CookieSerializeOptions,\n): void {\n const event = getH3Event()\n h3_setCookie(event, name, value, options)\n}\n\n/**\n * Remove a cookie by name.\n * @param name Name of the cookie to delete\n * @param serializeOptions {CookieSerializeOptions} Cookie options\n * ```ts\n * deleteCookie('SessionId')\n * ```\n */\nexport function deleteCookie(\n name: string,\n options?: CookieSerializeOptions,\n): void {\n const event = getH3Event()\n h3_deleteCookie(event, name, options)\n}\n\nfunction getDefaultSessionConfig(config: SessionConfig): SessionConfig {\n return {\n name: 'start',\n ...config,\n }\n}\n\n/**\n * Create a session manager for the current request.\n */\nexport function useSession<TSessionData extends SessionData = SessionData>(\n config: SessionConfig,\n): Promise<SessionManager<TSessionData>> {\n const event = getH3Event()\n return h3_useSession(event, getDefaultSessionConfig(config))\n}\n/**\n * Get the session for the current request\n */\nexport function getSession<TSessionData extends SessionData = SessionData>(\n config: SessionConfig,\n): Promise<Session<TSessionData>> {\n const event = getH3Event()\n return h3_getSession(event, getDefaultSessionConfig(config))\n}\n\n/**\n * Update the session data for the current request.\n */\nexport function updateSession<TSessionData extends SessionData = SessionData>(\n config: SessionConfig,\n update?: SessionUpdate<TSessionData>,\n): Promise<Session<TSessionData>> {\n const event = getH3Event()\n return h3_updateSession(event, getDefaultSessionConfig(config), update)\n}\n\n/**\n * Encrypt and sign the session data for the current request.\n */\nexport function sealSession(config: SessionConfig): Promise<string> {\n const event = getH3Event()\n return h3_sealSession(event, getDefaultSessionConfig(config))\n}\n/**\n * Decrypt and verify the session data for the current request.\n */\nexport function unsealSession(\n config: SessionConfig,\n sealed: string,\n): Promise<Partial<Session>> {\n const event = getH3Event()\n return h3_unsealSession(event, getDefaultSessionConfig(config), sealed)\n}\n\n/**\n * Clear the session data for the current request.\n */\nexport function clearSession(config: Partial<SessionConfig>): Promise<void> {\n const event = getH3Event()\n return h3_clearSession(event, { name: 'start', ...config })\n}\n\nexport function getResponse() {\n const event = getH3Event()\n return event.res\n}\n\n// not public API (yet)\nexport function getValidatedQuery<TSchema extends StandardSchemaV1>(\n schema: StandardSchemaV1,\n): Promise<StandardSchemaV1.InferOutput<TSchema>> {\n return h3_getValidatedQuery(getH3Event(), schema)\n}\n"],"mappings":";;;AA+CA,IAAM,2BAA2B,OAAO,IAAI,8BAA8B;AAE1E,IAAM,YAAY;AAIlB,IAAI,CAAC,UAAU,2BACb,UAAU,4BAA4B,IAAI,kBAA8B;AAG1E,IAAM,eAAe,UAAU;AAU/B,SAAS,cAAiB,OAA6C;CACrE,OAAO,OAAQ,MAAqB,SAAS;AAC/C;AAEA,SAAS,mBAAmB,SAAiC;CAC3D,MAAM,uBAAuB;CAC7B,IAAI,OAAO,qBAAqB,iBAAiB,YAC/C,OAAO,qBAAqB,aAAa;CAE3C,MAAM,QAAQ,QAAQ,IAAI,YAAY;CACtC,OAAO,QAAQ,CAAC,KAAK,IAAI,CAAC;AAC5B;AAEA,SAAS,0BAA0B,UAAoB,OAAsB;CAC3E,IAAI,SAAS,IACX;CAGF,MAAM,kBAAkB,mBAAmB,MAAM,IAAI,OAAO;CAC5D,IAAI,gBAAgB,WAAW,GAC7B;CAGF,MAAM,qBAAqB,mBAAmB,SAAS,OAAO;CAC9D,SAAS,QAAQ,OAAO,YAAY;CACpC,KAAK,MAAM,UAAU,oBACnB,SAAS,QAAQ,OAAO,cAAc,MAAM;CAE9C,KAAK,MAAM,UAAU,iBACnB,SAAS,QAAQ,OAAO,cAAc,MAA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,OAAO,GAChD,IAAI,UAAU,KAAA,GACZ,eAAe,QAAQ;CAI3B,OAAO;AACT;;;;;;;;;AAUA,SAAgB,UAAU,MAAkC;CAC1D,OAAO,WAAW,EAAE;AACtB;;;;;;;;;;AAWA,SAAgB,YACd,MACA,OACA,SACM;CAEN,UADc,WACD,GAAO,MAAM,OAAO,OAAO;AAC1C;;;;;;;;;AAUA,SAAgB,eACd,MACA,SACM;CAEN,aADc,WACE,GAAO,MAAM,OAAO;AACtC;AAEA,SAAS,wBAAwB,QAAsC;CACrE,OAAO;EACL,MAAM;EACN,GAAG;CACL;AACF;;;;AAKA,SAAgB,aACd,QACuC;CAEvC,OAAO,WADO,WACO,GAAO,wBAAwB,MAAM,CAAC;AAC7D;;;;AAIA,SAAgB,aACd,QACgC;CAEhC,OAAO,WADO,WACO,GAAO,wBAAwB,MAAM,CAAC;AAC7D;;;;AAKA,SAAgB,gBACd,QACA,QACgC;CAEhC,OAAO,cADO,WACU,GAAO,wBAAwB,MAAM,GAAG,MAAM;AACxE;;;;AAKA,SAAgB,cAAY,QAAwC;CAElE,OAAO,YADO,WACQ,GAAO,wBAAwB,MAAM,CAAC;AAC9D;;;;AAIA,SAAgB,gBACd,QACA,QAC2B;CAE3B,OAAO,cADO,WACU,GAAO,wBAAwB,MAAM,GAAG,MAAM;AACxE;;;;AAKA,SAAgB,eAAa,QAA+C;CAE1E,OAAO,aADO,WACS,GAAO;EAAE,MAAM;EAAS,GAAG;CAAO,CAAC;AAC5D;AAEA,SAAgB,cAAc;CAE5B,OADc,WACP,EAAM;AACf;AAGA,SAAgB,oBACd,QACgD;CAChD,OAAO,kBAAqB,WAAW,GAAG,MAAM;AAClD"}
{"version":3,"file":"request-response.js","names":[],"sources":["../../src/request-response.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\n\nimport {\n H3Event,\n clearSession as h3_clearSession,\n deleteCookie as h3_deleteCookie,\n getRequestHost as h3_getRequestHost,\n getRequestIP as h3_getRequestIP,\n getRequestProtocol as h3_getRequestProtocol,\n getRequestURL as h3_getRequestURL,\n getSession as h3_getSession,\n getValidatedQuery as h3_getValidatedQuery,\n parseCookies as h3_parseCookies,\n sanitizeStatusCode as h3_sanitizeStatusCode,\n sanitizeStatusMessage as h3_sanitizeStatusMessage,\n sealSession as h3_sealSession,\n setCookie as h3_setCookie,\n toResponse as h3_toResponse,\n unsealSession as h3_unsealSession,\n updateSession as h3_updateSession,\n useSession as h3_useSession,\n} from 'h3-v2'\nimport type {\n RequestHeaderMap,\n RequestHeaderName,\n ResponseHeaderMap,\n ResponseHeaderName,\n TypedHeaders,\n} from 'fetchdts'\n\nimport type { CookieSerializeOptions } from 'cookie-es'\nimport type {\n Session,\n SessionConfig,\n SessionData,\n SessionManager,\n SessionUpdate,\n} from './session'\nimport type { StandardSchemaV1 } from '@standard-schema/spec'\nimport type { RequestHandler } from './request-handler'\n\ninterface StartEvent {\n h3Event: H3Event\n}\n\n// Use a global symbol to ensure the same AsyncLocalStorage instance is shared\n// across different bundles that may each bundle this module.\nconst GLOBAL_EVENT_STORAGE_KEY = Symbol.for('tanstack-start:event-storage')\n\nconst globalObj = globalThis as typeof globalThis & {\n [GLOBAL_EVENT_STORAGE_KEY]?: AsyncLocalStorage<StartEvent>\n}\n\nif (!globalObj[GLOBAL_EVENT_STORAGE_KEY]) {\n globalObj[GLOBAL_EVENT_STORAGE_KEY] = new AsyncLocalStorage<StartEvent>()\n}\n\nconst eventStorage = globalObj[GLOBAL_EVENT_STORAGE_KEY]\n\nexport type { ResponseHeaderName, RequestHeaderName }\n\ntype HeadersWithGetSetCookie = Headers & {\n getSetCookie?: () => Array<string>\n}\n\ntype MaybePromise<T> = T | Promise<T>\n\nfunction isPromiseLike<T>(value: MaybePromise<T>): value is Promise<T> {\n return typeof (value as Promise<T>).then === 'function'\n}\n\nfunction getSetCookieValues(headers: Headers): Array<string> {\n const headersWithSetCookie = headers as HeadersWithGetSetCookie\n if (typeof headersWithSetCookie.getSetCookie === 'function') {\n return headersWithSetCookie.getSetCookie()\n }\n const value = headers.get('set-cookie')\n return value ? [value] : []\n}\n\nfunction mergeEventResponseHeaders(response: Response, event: H3Event): void {\n if (response.ok) {\n return\n }\n\n const eventSetCookies = getSetCookieValues(event.res.headers)\n if (eventSetCookies.length === 0) {\n return\n }\n\n const responseSetCookies = getSetCookieValues(response.headers)\n response.headers.delete('set-cookie')\n for (const cookie of responseSetCookies) {\n response.headers.append('set-cookie', cookie)\n }\n for (const cookie of eventSetCookies) {\n response.headers.append('set-cookie', cookie)\n }\n}\n\nfunction attachResponseHeaders<T>(\n value: MaybePromise<T>,\n event: H3Event,\n): MaybePromise<T> {\n if (isPromiseLike(value)) {\n return value.then((resolved) => {\n if (resolved instanceof Response) {\n mergeEventResponseHeaders(resolved, event)\n }\n return resolved\n })\n }\n\n if (value instanceof Response) {\n mergeEventResponseHeaders(value, event)\n }\n\n return value\n}\n\nexport function requestHandler<TRegister = unknown>(\n handler: RequestHandler<TRegister>,\n) {\n return (request: Request, requestOpts: any): Promise<Response> | Response => {\n let h3Event: H3Event\n try {\n h3Event = new H3Event(request)\n } catch (error) {\n if (error instanceof URIError) {\n return new Response(null, {\n status: 400,\n statusText: 'Bad Request',\n })\n }\n throw error\n }\n\n const response = eventStorage.run({ h3Event }, () =>\n handler(request, requestOpts),\n )\n return h3_toResponse(attachResponseHeaders(response, h3Event), h3Event)\n }\n}\n\nfunction getH3Event() {\n const event = eventStorage.getStore()\n if (!event) {\n throw new Error(\n `No StartEvent found in AsyncLocalStorage. Make sure you are using the function within the server runtime.`,\n )\n }\n return event.h3Event\n}\n\nexport function getRequest(): Request {\n const event = getH3Event()\n return event.req\n}\n\nexport function getRequestHeaders(): TypedHeaders<RequestHeaderMap> {\n return getH3Event().req.headers\n}\n\nexport function getRequestHeader(name: RequestHeaderName): string | undefined {\n return getRequestHeaders().get(name) || undefined\n}\n\nexport function getRequestIP(opts?: {\n /**\n * Use the X-Forwarded-For HTTP header set by proxies.\n *\n * Note: Make sure that this header can be trusted (your application running behind a CDN or reverse proxy) before enabling.\n */\n xForwardedFor?: boolean\n}) {\n return h3_getRequestIP(getH3Event(), opts)\n}\n\n/**\n * Get the request hostname.\n *\n * If `xForwardedHost` is `true`, it will use the `x-forwarded-host` header if it exists.\n *\n * If no host header is found, it will default to \"localhost\".\n */\nexport function getRequestHost(opts?: { xForwardedHost?: boolean }) {\n return h3_getRequestHost(getH3Event(), opts)\n}\n\n/**\n * Get the full incoming request URL.\n *\n * If `xForwardedHost` is `true`, it will use the `x-forwarded-host` header if it exists.\n *\n * If `xForwardedProto` is `false`, it will not use the `x-forwarded-proto` header.\n */\nexport function getRequestUrl(opts?: {\n xForwardedHost?: boolean\n xForwardedProto?: boolean\n}) {\n return h3_getRequestURL(getH3Event(), opts)\n}\n\n/**\n * Get the request protocol.\n *\n * If `x-forwarded-proto` header is set to \"https\", it will return \"https\". You can disable this behavior by setting `xForwardedProto` to `false`.\n *\n * If protocol cannot be determined, it will default to \"http\".\n */\nexport function getRequestProtocol(opts?: {\n xForwardedProto?: boolean\n}): 'http' | 'https' | (string & {}) {\n return h3_getRequestProtocol(getH3Event(), opts)\n}\n\nexport function setResponseHeaders(\n headers: TypedHeaders<ResponseHeaderMap>,\n): void {\n const event = getH3Event()\n for (const [name, value] of Object.entries(headers)) {\n event.res.headers.set(name, value)\n }\n}\n\nexport function getResponseHeaders(): TypedHeaders<ResponseHeaderMap> {\n const event = getH3Event()\n return event.res.headers\n}\n\nexport function getResponseHeader(\n name: ResponseHeaderName,\n): string | undefined {\n const event = getH3Event()\n return event.res.headers.get(name) || undefined\n}\n\nexport function setResponseHeader(\n name: ResponseHeaderName,\n value: string | Array<string>,\n): void {\n const event = getH3Event()\n if (Array.isArray(value)) {\n event.res.headers.delete(name)\n for (const valueItem of value) {\n event.res.headers.append(name, valueItem)\n }\n } else {\n event.res.headers.set(name, value)\n }\n}\nexport function removeResponseHeader(name: ResponseHeaderName): void {\n const event = getH3Event()\n event.res.headers.delete(name)\n}\n\nexport function clearResponseHeaders(\n headerNames?: Array<ResponseHeaderName>,\n): void {\n const event = getH3Event()\n // If headerNames is provided, clear only those headers\n if (headerNames && headerNames.length > 0) {\n for (const name of headerNames) {\n event.res.headers.delete(name)\n }\n // Otherwise, clear all headers\n } else {\n for (const name of event.res.headers.keys()) {\n event.res.headers.delete(name)\n }\n }\n}\n\nexport function getResponseStatus(): number {\n return getH3Event().res.status || 200\n}\n\nexport function setResponseStatus(code?: number, text?: string): void {\n const event = getH3Event()\n if (code) {\n event.res.status = h3_sanitizeStatusCode(code, event.res.status)\n }\n if (text) {\n event.res.statusText = h3_sanitizeStatusMessage(text)\n }\n}\n\n/**\n * Parse the request to get HTTP Cookie header string and return an object of all cookie name-value pairs.\n * @returns Object of cookie name-value pairs\n * ```ts\n * const cookies = getCookies()\n * ```\n */\nexport function getCookies(): Record<string, string> {\n const event = getH3Event()\n const cookies = h3_parseCookies(event)\n const definedCookies: Record<string, string> = Object.create(null)\n\n for (const [name, value] of Object.entries(cookies)) {\n if (value !== undefined) {\n definedCookies[name] = value\n }\n }\n\n return definedCookies\n}\n\n/**\n * Get a cookie value by name.\n * @param name Name of the cookie to get\n * @returns {*} Value of the cookie (String or undefined)\n * ```ts\n * const authorization = getCookie('Authorization')\n * ```\n */\nexport function getCookie(name: string): string | undefined {\n return getCookies()[name]\n}\n\n/**\n * Set a cookie value by name.\n * @param name Name of the cookie to set\n * @param value Value of the cookie to set\n * @param options {CookieSerializeOptions} Options for serializing the cookie\n * ```ts\n * setCookie('Authorization', '1234567')\n * ```\n */\nexport function setCookie(\n name: string,\n value: string,\n options?: CookieSerializeOptions,\n): void {\n const event = getH3Event()\n h3_setCookie(event, name, value, options)\n}\n\n/**\n * Remove a cookie by name.\n * @param name Name of the cookie to delete\n * @param serializeOptions {CookieSerializeOptions} Cookie options\n * ```ts\n * deleteCookie('SessionId')\n * ```\n */\nexport function deleteCookie(\n name: string,\n options?: CookieSerializeOptions,\n): void {\n const event = getH3Event()\n h3_deleteCookie(event, name, options)\n}\n\nfunction getDefaultSessionConfig(config: SessionConfig): SessionConfig {\n return {\n name: 'start',\n ...config,\n }\n}\n\n/**\n * Create a session manager for the current request.\n */\nexport function useSession<TSessionData extends SessionData = SessionData>(\n config: SessionConfig,\n): Promise<SessionManager<TSessionData>> {\n const event = getH3Event()\n return h3_useSession(event, getDefaultSessionConfig(config))\n}\n/**\n * Get the session for the current request\n */\nexport function getSession<TSessionData extends SessionData = SessionData>(\n config: SessionConfig,\n): Promise<Session<TSessionData>> {\n const event = getH3Event()\n return h3_getSession(event, getDefaultSessionConfig(config))\n}\n\n/**\n * Update the session data for the current request.\n */\nexport function updateSession<TSessionData extends SessionData = SessionData>(\n config: SessionConfig,\n update?: SessionUpdate<TSessionData>,\n): Promise<Session<TSessionData>> {\n const event = getH3Event()\n return h3_updateSession(event, getDefaultSessionConfig(config), update)\n}\n\n/**\n * Encrypt and sign the session data for the current request.\n */\nexport function sealSession(config: SessionConfig): Promise<string> {\n const event = getH3Event()\n return h3_sealSession(event, getDefaultSessionConfig(config))\n}\n/**\n * Decrypt and verify the session data for the current request.\n */\nexport function unsealSession(\n config: SessionConfig,\n sealed: string,\n): Promise<Partial<Session>> {\n const event = getH3Event()\n return h3_unsealSession(event, getDefaultSessionConfig(config), sealed)\n}\n\n/**\n * Clear the session data for the current request.\n */\nexport function clearSession(config: Partial<SessionConfig>): Promise<void> {\n const event = getH3Event()\n return h3_clearSession(event, { name: 'start', ...config })\n}\n\nexport function getResponse() {\n const event = getH3Event()\n return event.res\n}\n\n// not public API (yet)\nexport function getValidatedQuery<TSchema extends StandardSchemaV1>(\n schema: StandardSchemaV1,\n): Promise<StandardSchemaV1.InferOutput<TSchema>> {\n return h3_getValidatedQuery(getH3Event(), schema)\n}\n"],"mappings":";;;AA+CA,IAAM,2BAA2B,OAAO,IAAI,8BAA8B;AAE1E,IAAM,YAAY;AAIlB,IAAI,CAAC,UAAU,2BACb,UAAU,4BAA4B,IAAI,kBAA8B;AAG1E,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wBAAwB,MAAM,GAAG,MAAM;AACxE;;;;AAKA,SAAgB,YAAY,QAAwC;CAElE,OAAO,cADO,WACQ,GAAO,wBAAwB,MAAM,CAAC;AAC9D;;;;AAIA,SAAgB,cACd,QACA,QAC2B;CAE3B,OAAO,gBADO,WACU,GAAO,wBAAwB,MAAM,GAAG,MAAM;AACxE;;;;AAKA,SAAgB,aAAa,QAA+C;CAE1E,OAAO,eADO,WACS,GAAO;EAAE,MAAM;EAAS,GAAG;CAAO,CAAC;AAC5D;AAEA,SAAgB,cAAc;CAE5B,OADc,WACP,EAAM;AACf;AAGA,SAAgB,kBACd,QACgD;CAChD,OAAO,oBAAqB,WAAW,GAAG,MAAM;AAClD"}
{
"name": "@tanstack/start-server-core",
"version": "1.169.7",
"version": "1.169.8",
"description": "Modern and scalable routing for React applications",

@@ -47,2 +47,8 @@ "author": "Tanner Linsley",

},
"./request-response": {
"import": {
"types": "./dist/esm/request-response.d.ts",
"default": "./dist/esm/request-response.js"
}
},
"./package.json": "./package.json"

@@ -49,0 +55,0 @@ },