@shopify/remix-oxygen
Advanced tools
Comparing version 0.0.0-next-6116da5-20230414160127 to 0.0.0-next-616dee2-20240917025841
import { createCookieFactory, createCookieSessionStorageFactory, createSessionStorageFactory, createMemorySessionStorageFactory, createRequestHandler as createRequestHandler$1 } from '@remix-run/server-runtime'; | ||
export { MaxPartSizeExceededError, createSession, defer, isCookie, isSession, json, redirect, unstable_composeUploadHandlers, unstable_createMemoryUploadHandler, unstable_parseMultipartFormData } from '@remix-run/server-runtime'; | ||
export { MaxPartSizeExceededError, createSession, defer, isCookie, isSession, json, redirect, redirectDocument, unstable_composeUploadHandlers, unstable_createMemoryUploadHandler, unstable_defineAction, unstable_defineLoader, unstable_parseMultipartFormData } from '@remix-run/server-runtime'; | ||
@@ -51,5 +51,44 @@ // src/implementations.ts | ||
var createMemorySessionStorage = createMemorySessionStorageFactory(createSessionStorage); | ||
// src/event-logger.ts | ||
var hasWarned = false; | ||
function createEventLogger(appLoadContext) { | ||
const context = appLoadContext || {}; | ||
const eventLoggerService = context?.env?.H2O_LOG_EVENT; | ||
if (typeof eventLoggerService?.fetch !== "function") return; | ||
return ({ | ||
url, | ||
endTime = Date.now(), | ||
waitUntil = context?.waitUntil, | ||
...rest | ||
}) => { | ||
const promise = Promise.resolve().then( | ||
() => eventLoggerService.fetch( | ||
new Request(url, { | ||
method: "POST", | ||
body: JSON.stringify({ | ||
endTime, | ||
...rest | ||
}) | ||
}) | ||
).catch((error) => { | ||
if (!hasWarned) { | ||
console.debug("Failed to log H2O event\n", error.stack); | ||
hasWarned = true; | ||
} | ||
}) | ||
); | ||
promise && waitUntil?.(promise); | ||
}; | ||
} | ||
// src/server.ts | ||
var originalErrorToString = Error.prototype.toString; | ||
Error.prototype.toString = function() { | ||
return this.stack || originalErrorToString.call(this); | ||
}; | ||
function createRequestHandler({ | ||
build, | ||
mode, | ||
poweredByHeader = true, | ||
getLoadContext | ||
@@ -59,11 +98,43 @@ }) { | ||
return async (request) => { | ||
return handleRequest( | ||
request, | ||
await getLoadContext?.(request) | ||
); | ||
const method = request.method; | ||
if ((method === "GET" || method === "HEAD") && request.body) { | ||
return new Response(`${method} requests cannot have a body`, { | ||
status: 400 | ||
}); | ||
} | ||
const url = new URL(request.url); | ||
if (url.pathname.includes("//")) { | ||
return new Response(null, { | ||
status: 301, | ||
headers: { | ||
location: url.pathname.replace(/\/+/g, "/") | ||
} | ||
}); | ||
} | ||
const context = getLoadContext ? await getLoadContext(request) : void 0; | ||
if (context) { | ||
globalThis.__H2O_LOG_EVENT ??= createEventLogger(context); | ||
} | ||
const startTime = Date.now(); | ||
const response = await handleRequest(request, context); | ||
if (poweredByHeader) { | ||
response.headers.append("powered-by", "Shopify, Hydrogen"); | ||
} | ||
{ | ||
globalThis.__H2O_LOG_EVENT?.({ | ||
eventType: "request", | ||
url: request.url, | ||
requestId: request.headers.get("request-id"), | ||
purpose: request.headers.get("purpose"), | ||
startTime, | ||
responseInit: { | ||
status: response.status, | ||
statusText: response.statusText, | ||
headers: Array.from(response.headers.entries()) | ||
} | ||
}); | ||
} | ||
return response; | ||
}; | ||
} | ||
function getBuyerIp(request) { | ||
return request.headers.get("oxygen-buyer-ip") ?? void 0; | ||
} | ||
function getStorefrontHeaders(request) { | ||
@@ -74,8 +145,9 @@ const headers = request.headers; | ||
buyerIp: headers.get("oxygen-buyer-ip"), | ||
cookie: headers.get("cookie") | ||
cookie: headers.get("cookie"), | ||
purpose: headers.get("purpose") | ||
}; | ||
} | ||
export { createCookie, createCookieSessionStorage, createMemorySessionStorage, createRequestHandler, createSessionStorage, getBuyerIp, getStorefrontHeaders }; | ||
export { createCookie, createCookieSessionStorage, createMemorySessionStorage, createRequestHandler, createSessionStorage, getStorefrontHeaders }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.js.map |
import * as _remix_run_server_runtime from '@remix-run/server-runtime'; | ||
import { ServerBuild } from '@remix-run/server-runtime'; | ||
export { ActionArgs, ActionFunction, AppData, AppLoadContext, Cookie, CookieOptions, CookieParseOptions, CookieSerializeOptions, CookieSignatureOptions, DataFunctionArgs, EntryContext, ErrorBoundaryComponent, HandleDataRequestFunction, HandleDocumentRequestFunction, HeadersFunction, HtmlLinkDescriptor, HtmlMetaDescriptor, LinkDescriptor, LinksFunction, LoaderArgs, LoaderFunction, MaxPartSizeExceededError, MemoryUploadHandlerFilterArgs, MemoryUploadHandlerOptions, MetaDescriptor, MetaFunction, PageLinkDescriptor, RequestHandler, RouteComponent, RouteHandle, SerializeFrom, ServerBuild, ServerEntryModule, Session, SessionData, SessionIdStorageStrategy, SessionStorage, SignFunction, TypedResponse, UnsignFunction, UploadHandler, UploadHandlerPart, V2_ServerRuntimeMetaDescriptor as V2_HtmlMetaDescriptor, V2_ServerRuntimeMetaArgs as V2_MetaArgs, V2_ServerRuntimeMetaDescriptor as V2_MetaDescriptor, V2_ServerRuntimeMetaFunction as V2_MetaFunction, createSession, defer, isCookie, isSession, json, redirect, unstable_composeUploadHandlers, unstable_createMemoryUploadHandler, unstable_parseMultipartFormData } from '@remix-run/server-runtime'; | ||
export { ActionFunction, ActionFunctionArgs, AppLoadContext, Cookie, CookieOptions, CookieParseOptions, CookieSerializeOptions, CookieSignatureOptions, DataFunctionArgs, EntryContext, ErrorResponse, HandleDataRequestFunction, HandleDocumentRequestFunction, HandleErrorFunction, HeadersArgs, HeadersFunction, HtmlLinkDescriptor, JsonFunction, LinkDescriptor, LinksFunction, LoaderFunction, LoaderFunctionArgs, MaxPartSizeExceededError, MemoryUploadHandlerFilterArgs, MemoryUploadHandlerOptions, ServerRuntimeMetaArgs as MetaArgs, ServerRuntimeMetaDescriptor as MetaDescriptor, ServerRuntimeMetaFunction as MetaFunction, PageLinkDescriptor, RequestHandler, SerializeFrom, ServerBuild, ServerEntryModule, Session, SessionData, SessionIdStorageStrategy, SessionStorage, SignFunction, TypedDeferredData, TypedResponse, UnsignFunction, UploadHandler, UploadHandlerPart, createSession, defer, isCookie, isSession, json, redirect, redirectDocument, unstable_composeUploadHandlers, unstable_createMemoryUploadHandler, unstable_defineAction, unstable_defineLoader, unstable_parseMultipartFormData } from '@remix-run/server-runtime'; | ||
@@ -10,8 +10,8 @@ declare const createCookie: _remix_run_server_runtime.CreateCookieFunction; | ||
declare function createRequestHandler<Context = unknown>({ build, mode, getLoadContext, }: { | ||
declare function createRequestHandler<Context = unknown>({ build, mode, poweredByHeader, getLoadContext, }: { | ||
build: ServerBuild; | ||
mode?: string; | ||
poweredByHeader?: boolean; | ||
getLoadContext?: (request: Request) => Promise<Context> | Context; | ||
}): (request: Request) => Promise<Response>; | ||
declare function getBuyerIp(request: Request): string | undefined; | ||
type StorefrontHeaders = { | ||
@@ -21,5 +21,6 @@ requestGroupId: string | null; | ||
cookie: string | null; | ||
purpose: string | null; | ||
}; | ||
declare function getStorefrontHeaders(request: Request): StorefrontHeaders; | ||
export { createCookie, createCookieSessionStorage, createMemorySessionStorage, createRequestHandler, createSessionStorage, getBuyerIp, getStorefrontHeaders }; | ||
export { createCookie, createCookieSessionStorage, createMemorySessionStorage, createRequestHandler, createSessionStorage, getStorefrontHeaders }; |
import { createCookieFactory, createCookieSessionStorageFactory, createSessionStorageFactory, createMemorySessionStorageFactory, createRequestHandler } from '@remix-run/server-runtime'; | ||
export { MaxPartSizeExceededError, createSession, defer, isCookie, isSession, json, redirect, unstable_composeUploadHandlers, unstable_createMemoryUploadHandler, unstable_parseMultipartFormData } from '@remix-run/server-runtime'; | ||
export { MaxPartSizeExceededError, createSession, defer, isCookie, isSession, json, redirect, redirectDocument, unstable_composeUploadHandlers, unstable_createMemoryUploadHandler, unstable_defineAction, unstable_defineLoader, unstable_parseMultipartFormData } from '@remix-run/server-runtime'; | ||
var s=new TextEncoder,c=async(e,t)=>{let r=await p(t,["sign"]),o=s.encode(e),n=await crypto.subtle.sign("HMAC",r,o),a=btoa(String.fromCharCode(...new Uint8Array(n))).replace(/=+$/,"");return e+"."+a},u=async(e,t)=>{let r=e.lastIndexOf("."),o=e.slice(0,r),n=e.slice(r+1),a=await p(t,["verify"]),l=s.encode(o),g=y(atob(n));return await crypto.subtle.verify("HMAC",a,g,l)?o:!1};async function p(e,t){return await crypto.subtle.importKey("raw",s.encode(e),{name:"HMAC",hash:"SHA-256"},!1,t)}function y(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}var i=createCookieFactory({sign:c,unsign:u}),f=createCookieSessionStorageFactory(i),d=createSessionStorageFactory(i),H=createMemorySessionStorageFactory(d);function F({build:e,mode:t,getLoadContext:r}){let o=createRequestHandler(e,t);return async n=>o(n,await r?.(n))}function M(e){return e.headers.get("oxygen-buyer-ip")??void 0}function A(e){let t=e.headers;return {requestGroupId:t.get("request-id"),buyerIp:t.get("oxygen-buyer-ip"),cookie:t.get("cookie")}} | ||
var c=new TextEncoder,l=async(e,t)=>{let r=await y(t,["sign"]),n=c.encode(e),s=await crypto.subtle.sign("HMAC",r,n),o=btoa(String.fromCharCode(...new Uint8Array(s))).replace(/=+$/,"");return e+"."+o},g=async(e,t)=>{let r=e.lastIndexOf("."),n=e.slice(0,r),s=e.slice(r+1),o=await y(t,["verify"]),a=c.encode(n),i=m(atob(s));return await crypto.subtle.verify("HMAC",o,i,a)?n:!1};async function y(e,t){return await crypto.subtle.importKey("raw",c.encode(e),{name:"HMAC",hash:"SHA-256"},!1,t)}function m(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}var u=createCookieFactory({sign:l,unsign:g}),C=createCookieSessionStorageFactory(u),S=createSessionStorageFactory(u),F=createMemorySessionStorageFactory(S);var A=Error.prototype.toString;Error.prototype.toString=function(){return this.stack||A.call(this)};function E({build:e,mode:t,poweredByHeader:r=!0,getLoadContext:n}){let s=createRequestHandler(e,t);return async o=>{let a=o.method;if((a==="GET"||a==="HEAD")&&o.body)return new Response(`${a} requests cannot have a body`,{status:400});let i=new URL(o.url);if(i.pathname.includes("//"))return new Response(null,{status:301,headers:{location:i.pathname.replace(/\/+/g,"/")}});let p=n?await n(o):void 0,d=await s(o,p);return r&&d.headers.append("powered-by","Shopify, Hydrogen"),d}}function v(e){let t=e.headers;return {requestGroupId:t.get("request-id"),buyerIp:t.get("oxygen-buyer-ip"),cookie:t.get("cookie"),purpose:t.get("purpose")}} | ||
export { i as createCookie, f as createCookieSessionStorage, H as createMemorySessionStorage, F as createRequestHandler, d as createSessionStorage, M as getBuyerIp, A as getStorefrontHeaders }; | ||
export { u as createCookie, C as createCookieSessionStorage, F as createMemorySessionStorage, E as createRequestHandler, S as createSessionStorage, v as getStorefrontHeaders }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.js.map |
@@ -8,4 +8,4 @@ { | ||
"type": "module", | ||
"version": "0.0.0-next-6116da5-20230414160127", | ||
"license": "SEE LICENSE IN LICENSE.md", | ||
"version": "0.0.0-next-616dee2-20240917025841", | ||
"license": "MIT", | ||
"main": "dist/index.cjs", | ||
@@ -16,4 +16,4 @@ "module": "dist/production/index.js", | ||
"scripts": { | ||
"build": "tsup --clean --config ../../tsup.config.ts", | ||
"dev": "tsup --watch --config ../../tsup.config.ts", | ||
"build": "tsup --clean", | ||
"dev": "tsup --watch", | ||
"prepack": "npm run build", | ||
@@ -44,11 +44,10 @@ "typecheck": "tsc --noEmit" | ||
], | ||
"dependencies": { | ||
"@remix-run/server-runtime": "1.15.0" | ||
}, | ||
"devDependencies": { | ||
"@shopify/oxygen-workers-types": "^3.17.2" | ||
"@remix-run/server-runtime": "^2.10.1", | ||
"@shopify/oxygen-workers-types": "^4.1.2" | ||
}, | ||
"peerDependencies": { | ||
"@shopify/oxygen-workers-types": "^3.17.2" | ||
"@remix-run/server-runtime": "^2.1.0", | ||
"@shopify/oxygen-workers-types": "^3.17.3 || ^4.1.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
66886
14
0
447
19
57
2
+ Added@remix-run/router@1.21.0(transitive)
+ Added@remix-run/server-runtime@2.15.1(transitive)
+ Added@shopify/oxygen-workers-types@4.1.6(transitive)
+ Added@types/cookie@0.6.0(transitive)
+ Addedcookie@0.6.0(transitive)
+ Addedturbo-stream@2.4.0(transitive)
- Removed@remix-run/server-runtime@1.15.0
- Removed@remix-run/router@1.5.0(transitive)
- Removed@remix-run/server-runtime@1.15.0(transitive)
- Removed@shopify/oxygen-workers-types@3.17.3(transitive)
- Removed@types/cookie@0.4.1(transitive)
- Removed@types/prop-types@15.7.14(transitive)
- Removed@types/react@18.3.16(transitive)
- Removedcookie@0.4.2(transitive)
- Removedcsstype@3.1.3(transitive)