@shopify/remix-oxygen 2.0.12 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,54 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var serverRuntime = require('@remix-run/server-runtime');
3
+ var reactRouter = require('react-router');
4
4
 
5
- // src/implementations.ts
6
-
7
- // src/crypto.ts
8
- var encoder = new TextEncoder();
9
- var sign = async (value, secret) => {
10
- const key = await createKey(secret, ["sign"]);
11
- const data2 = encoder.encode(value);
12
- const signature = await crypto.subtle.sign("HMAC", key, data2);
13
- const hash = btoa(String.fromCharCode(...new Uint8Array(signature))).replace(
14
- /=+$/,
15
- ""
16
- );
17
- return value + "." + hash;
18
- };
19
- var unsign = async (signed, secret) => {
20
- const index = signed.lastIndexOf(".");
21
- const value = signed.slice(0, index);
22
- const hash = signed.slice(index + 1);
23
- const key = await createKey(secret, ["verify"]);
24
- const data2 = encoder.encode(value);
25
- const signature = byteStringToUint8Array(atob(hash));
26
- const valid = await crypto.subtle.verify("HMAC", key, signature, data2);
27
- return valid ? value : false;
28
- };
29
- async function createKey(secret, usages) {
30
- const key = await crypto.subtle.importKey(
31
- "raw",
32
- encoder.encode(secret),
33
- { name: "HMAC", hash: "SHA-256" },
34
- false,
35
- usages
36
- );
37
- return key;
38
- }
39
- function byteStringToUint8Array(byteString) {
40
- const array = new Uint8Array(byteString.length);
41
- for (let i = 0; i < byteString.length; i++) {
42
- array[i] = byteString.charCodeAt(i);
43
- }
44
- return array;
45
- }
46
-
47
- // src/implementations.ts
48
- var createCookie = serverRuntime.createCookieFactory({ sign, unsign });
49
- var createCookieSessionStorage = serverRuntime.createCookieSessionStorageFactory(createCookie);
50
- var createSessionStorage = serverRuntime.createSessionStorageFactory(createCookie);
51
- var createMemorySessionStorage = serverRuntime.createMemorySessionStorageFactory(createSessionStorage);
5
+ // src/server.ts
52
6
 
53
7
  // src/event-logger.ts
54
8
  var hasWarned = false;
@@ -93,7 +47,7 @@ function createRequestHandler({
93
47
  poweredByHeader = true,
94
48
  getLoadContext
95
49
  }) {
96
- const handleRequest = serverRuntime.createRequestHandler(build, mode);
50
+ const handleRequest = reactRouter.createRequestHandler(build, mode);
97
51
  return async (request) => {
98
52
  const method = request.method;
99
53
  if ((method === "GET" || method === "HEAD") && request.body) {
@@ -146,47 +100,47 @@ function getStorefrontHeaders(request) {
146
100
  };
147
101
  }
148
102
 
149
- Object.defineProperty(exports, "MaxPartSizeExceededError", {
103
+ Object.defineProperty(exports, "createCookie", {
150
104
  enumerable: true,
151
- get: function () { return serverRuntime.MaxPartSizeExceededError; }
105
+ get: function () { return reactRouter.createCookie; }
106
+ });
107
+ Object.defineProperty(exports, "createCookieSessionStorage", {
108
+ enumerable: true,
109
+ get: function () { return reactRouter.createCookieSessionStorage; }
110
+ });
111
+ Object.defineProperty(exports, "createMemorySessionStorage", {
112
+ enumerable: true,
113
+ get: function () { return reactRouter.createMemorySessionStorage; }
152
114
  });
153
115
  Object.defineProperty(exports, "createSession", {
154
116
  enumerable: true,
155
- get: function () { return serverRuntime.createSession; }
117
+ get: function () { return reactRouter.createSession; }
156
118
  });
157
- Object.defineProperty(exports, "data", {
119
+ Object.defineProperty(exports, "createSessionStorage", {
158
120
  enumerable: true,
159
- get: function () { return serverRuntime.data; }
121
+ get: function () { return reactRouter.createSessionStorage; }
160
122
  });
161
- Object.defineProperty(exports, "defer", {
123
+ Object.defineProperty(exports, "data", {
162
124
  enumerable: true,
163
- get: function () { return serverRuntime.defer; }
125
+ get: function () { return reactRouter.data; }
164
126
  });
165
127
  Object.defineProperty(exports, "isCookie", {
166
128
  enumerable: true,
167
- get: function () { return serverRuntime.isCookie; }
129
+ get: function () { return reactRouter.isCookie; }
168
130
  });
169
131
  Object.defineProperty(exports, "isSession", {
170
132
  enumerable: true,
171
- get: function () { return serverRuntime.isSession; }
172
- });
173
- Object.defineProperty(exports, "json", {
174
- enumerable: true,
175
- get: function () { return serverRuntime.json; }
133
+ get: function () { return reactRouter.isSession; }
176
134
  });
177
135
  Object.defineProperty(exports, "redirect", {
178
136
  enumerable: true,
179
- get: function () { return serverRuntime.redirect; }
137
+ get: function () { return reactRouter.redirect; }
180
138
  });
181
139
  Object.defineProperty(exports, "redirectDocument", {
182
140
  enumerable: true,
183
- get: function () { return serverRuntime.redirectDocument; }
141
+ get: function () { return reactRouter.redirectDocument; }
184
142
  });
185
- exports.createCookie = createCookie;
186
- exports.createCookieSessionStorage = createCookieSessionStorage;
187
- exports.createMemorySessionStorage = createMemorySessionStorage;
188
143
  exports.createRequestHandler = createRequestHandler;
189
- exports.createSessionStorage = createSessionStorage;
190
144
  exports.getStorefrontHeaders = getStorefrontHeaders;
191
145
  //# sourceMappingURL=index.cjs.map
192
146
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/crypto.ts","../../src/implementations.ts","../../src/event-logger.ts","../../src/server.ts"],"names":["data","createCookieFactory","createCookieSessionStorageFactory","createSessionStorageFactory","createMemorySessionStorageFactory","createRemixRequestHandler"],"mappings":";;;;;;;AAEA,IAAM,OAAA,GAAU,IAAI,WAAY,EAAA;AAEzB,IAAM,IAAA,GAAqB,OAAO,KAAA,EAAO,MAAW,KAAA;AACzD,EAAA,MAAM,MAAM,MAAM,SAAA,CAAU,MAAQ,EAAA,CAAC,MAAM,CAAC,CAAA;AAC5C,EAAMA,MAAAA,KAAAA,GAAO,OAAQ,CAAA,MAAA,CAAO,KAAK,CAAA;AACjC,EAAA,MAAM,YAAY,MAAM,MAAA,CAAO,OAAO,IAAK,CAAA,MAAA,EAAQ,KAAKA,KAAI,CAAA;AAC5D,EAAM,MAAA,IAAA,GAAO,IAAK,CAAA,MAAA,CAAO,YAAa,CAAA,GAAG,IAAI,UAAW,CAAA,SAAS,CAAC,CAAC,CAAE,CAAA,OAAA;AAAA,IACnE,KAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,OAAO,QAAQ,GAAM,GAAA,IAAA;AACvB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AA;AAE3B,IAAA,MAAM,QAAW,GAAA,MAAM,aAAc,CAAA,OAAA,EAAS,OAAO,CAAA;AAErD,IAAA,IAAI,eAAiB,EAAA;AACnB,MAAS,QAAA,CAAA,OAAA,CAAQ,MAAO,CAAA,YAAA,EAAc,mBAAmB,CAAA;AAAA;AAG3D,IAA4C;AAC1C,MAAA,UAAA,CAAW,eAAkB,GAAA;AAAA,QAC3B,SAAW,EAAA,SAAA;AAAA,QACX,KAAK,OAAQ,CAAA,GAAA;AAAA,QACb,SAAW,EAAA,OAAA,CAAQ,OAAQ,CAAA,GAAA,CAAI,YAAY,CAAA;AAAA,QAC3C,OAAS,EAAA,OAAA,CAAQ,OAAQ,CAAA,GAAA,CAAI,SAAS,CAAA;AAAA,QACtC,SAAA;AAAA,QACA,YAAc,EAAA;AAAA,UACZ,QAAQ,QAAS,CAAA,MAAA;AAAA,UACjB,YAAY,QAAS,CAAA,UAAA;AAAA,UACrB,SAAS,KAAM,CAAA,IAAA,CAAK,QAAS,CAAA,OAAA,CAAQ,SAAS;AAAA;AAChD,OACD,CAAA;AAAA;AAGH,IAAO,OAAA,QAAA;AAAA,GACT;AACF;AASO,SAAS,qBAAqB,OAAqC,EAAA;AACxE,EAAA,MAAM,UAAU,OAAQ,CAAA,OAAA;AACxB,EAAO,OAAA;AAAA,IACL,cAAA,EAAgB,OAAQ,CAAA,GAAA,CAAI,YAAY,CAAA;AAAA,IACxC,OAAA,EAAS,OAAQ,CAAA,GAAA,CAAI,iBAAiB,CAAA;AAAA,IACtC,MAAA,EAAQ,OAAQ,CAAA,GAAA,CAAI,QAAQ,CAAA;AAAA,IAC5B,OAAA,EAAS,OAAQ,CAAA,GAAA,CAAI,SAAS;AAAA,GAChC;AACF","file":"index.cjs","sourcesContent":["import type {SignFunction, UnsignFunction} from '@remix-run/server-runtime';\n\nconst encoder = new TextEncoder();\n\nexport const sign: SignFunction = async (value, secret) => {\n const key = await createKey(secret, ['sign']);\n const data = encoder.encode(value);\n const signature = await crypto.subtle.sign('HMAC', key, data);\n const hash = btoa(String.fromCharCode(...new Uint8Array(signature))).replace(\n /=+$/,\n '',\n );\n\n return value + '.' + hash;\n};\n\nexport const unsign: UnsignFunction = async (signed, secret) => {\n const index = signed.lastIndexOf('.');\n const value = signed.slice(0, index);\n const hash = signed.slice(index + 1);\n\n const key = await createKey(secret, ['verify']);\n const data = encoder.encode(value);\n const signature = byteStringToUint8Array(atob(hash));\n const valid = await crypto.subtle.verify('HMAC', key, signature, data);\n\n return valid ? value : false;\n};\n\nasync function createKey(\n secret: string,\n usages: CryptoKey['usages'],\n): Promise<CryptoKey> {\n const key = await crypto.subtle.importKey(\n 'raw',\n encoder.encode(secret),\n {name: 'HMAC', hash: 'SHA-256'},\n false,\n usages,\n );\n\n return key;\n}\n\nfunction byteStringToUint8Array(byteString: string): Uint8Array {\n const array = new Uint8Array(byteString.length);\n\n for (let i = 0; i < byteString.length; i++) {\n array[i] = byteString.charCodeAt(i);\n }\n\n return array;\n}\n","import {\n createCookieFactory,\n createCookieSessionStorageFactory,\n createMemorySessionStorageFactory,\n createSessionStorageFactory,\n} from '@remix-run/server-runtime';\n\nimport {sign, unsign} from './crypto';\n\nexport const createCookie = createCookieFactory({sign, unsign});\nexport const createCookieSessionStorage =\n createCookieSessionStorageFactory(createCookie);\nexport const createSessionStorage = createSessionStorageFactory(createCookie);\nexport const createMemorySessionStorage =\n createMemorySessionStorageFactory(createSessionStorage);\n","type H2OEvent = Parameters<NonNullable<typeof __H2O_LOG_EVENT>>[0];\n\nlet hasWarned = false;\n\n/**\n * @deprecated Only used with the classic Remix compiler\n */\nexport function createEventLogger(appLoadContext: Record<string, unknown>) {\n const context = (appLoadContext || {}) as {\n env?: Record<string, any>;\n waitUntil?: (promise: Promise<any>) => void;\n };\n\n const eventLoggerService = context?.env?.H2O_LOG_EVENT as\n | undefined\n | {fetch: (req: Request) => Promise<Response>};\n\n if (typeof eventLoggerService?.fetch !== 'function') return;\n\n return ({\n url,\n endTime = Date.now(),\n waitUntil = context?.waitUntil,\n ...rest\n }: H2OEvent) => {\n const promise = Promise.resolve().then(() =>\n eventLoggerService\n .fetch(\n new Request(url, {\n method: 'POST',\n body: JSON.stringify({\n endTime,\n ...rest,\n }),\n }),\n )\n .catch((error: Error) => {\n if (!hasWarned) {\n // This might repeat a lot of times due to\n // the same issue, so we only warn once.\n console.debug('Failed to log H2O event\\n', error.stack);\n hasWarned = true;\n }\n }),\n );\n\n promise && waitUntil?.(promise);\n };\n}\n","/// <reference types=\"@shopify/hydrogen\" />\nimport {\n createRequestHandler as createRemixRequestHandler,\n type AppLoadContext,\n type ServerBuild,\n} from '@remix-run/server-runtime';\nimport {createEventLogger} from './event-logger';\n\nconst originalErrorToString = Error.prototype.toString;\nError.prototype.toString = function () {\n return this.stack || originalErrorToString.call(this);\n};\n\nexport function createRequestHandler<Context = unknown>({\n build,\n mode,\n poweredByHeader = true,\n getLoadContext,\n}: {\n build: ServerBuild;\n mode?: string;\n poweredByHeader?: boolean;\n getLoadContext?: (request: Request) => Promise<Context> | Context;\n}) {\n const handleRequest = createRemixRequestHandler(build, mode);\n\n return async (request: Request) => {\n const method = request.method;\n\n if ((method === 'GET' || method === 'HEAD') && request.body) {\n return new Response(`${method} requests cannot have a body`, {\n status: 400,\n });\n }\n\n const url = new URL(request.url);\n\n if (url.pathname.includes('//')) {\n return new Response(null, {\n status: 301,\n headers: {\n location: url.pathname.replace(/\\/+/g, '/'),\n },\n });\n }\n\n const context = getLoadContext\n ? ((await getLoadContext(request)) as AppLoadContext)\n : undefined;\n\n if (process.env.NODE_ENV === 'development' && context) {\n // Store logger in globalThis so it can be accessed from the worker.\n // The global property must be different from the binding name,\n // otherwise Miniflare throws an error when accessing it.\n globalThis.__H2O_LOG_EVENT ??= createEventLogger(context);\n }\n\n const startTime = Date.now();\n\n const response = await handleRequest(request, context);\n\n if (poweredByHeader) {\n response.headers.append('powered-by', 'Shopify, Hydrogen');\n }\n\n if (process.env.NODE_ENV === 'development') {\n globalThis.__H2O_LOG_EVENT?.({\n eventType: 'request',\n url: request.url,\n requestId: request.headers.get('request-id'),\n purpose: request.headers.get('purpose'),\n startTime,\n responseInit: {\n status: response.status,\n statusText: response.statusText,\n headers: Array.from(response.headers.entries()),\n } satisfies ResponseInit,\n });\n }\n\n return response;\n };\n}\n\ntype StorefrontHeaders = {\n requestGroupId: string | null;\n buyerIp: string | null;\n cookie: string | null;\n purpose: string | null;\n};\n\nexport function getStorefrontHeaders(request: Request): StorefrontHeaders {\n const headers = request.headers;\n return {\n requestGroupId: headers.get('request-id'),\n buyerIp: headers.get('oxygen-buyer-ip'),\n cookie: headers.get('cookie'),\n purpose: headers.get('purpose'),\n };\n}\n"]}
1
+ {"version":3,"sources":["../../src/event-logger.ts","../../src/server.ts"],"names":["createReactRouterRequestHandler"],"mappings":";;;;;;;AAEA,IAAI,SAAY,GAAA,KAAA;AAKT,SAAS,kBAAkB,cAAyC,EAAA;AACzE,EAAM,MAAA,OAAA,GAAW,kBAAkB,EAAC;AAKpC,EAAM,MAAA,kBAAA,GAAqB,SAAS,GAAK,EAAA,aAAA;AAIzC,EAAI,IAAA,OAAO,kBAAoB,EAAA,KAAA,KAAU,UAAY,EAAA;AAErD,EAAA,OAAO,CAAC;AAAA,IACN,GAAA;AAAA,IACA,OAAA,GAAU,KAAK,GAAI,EAAA;AAAA,IACnB,YAAY,OAAS,EAAA,SAAA;AAAA,IACrB,GAAG;AAAA,GACW,KAAA;AACd,IAAM,MAAA,OAAA,GAAU,OAAQ,CAAA,OAAA,EAAU,CAAA,IAAA;AAAA,MAAK,MACrC,kBACG,CAAA,KAAA;AAAA,QACC,IAAI,QAAQ,GAAK,EAAA;AAAA,UACf,MAAQ,EAAA,MAAA;AAAA,UACR,IAAA,EAAM,KAAK,SAAU,CAAA;AAAA,YACnB,OAAA;AAAA,YACA,GAAG;AAAA,WACJ;AAAA,SACF;AAAA,OACH,CACC,KAAM,CAAA,CAAC,KAAiB,KAAA;AACvB,QAAA,IAAI,CAAC,S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AA,IAC5B,OAAA,EAAS,OAAQ,CAAA,GAAA,CAAI,SAAS;AAAA,GAChC;AACF","file":"index.cjs","sourcesContent":["type H2OEvent = Parameters<NonNullable<typeof __H2O_LOG_EVENT>>[0];\n\nlet hasWarned = false;\n\n/**\n * @deprecated Only used with the classic Remix compiler\n */\nexport function createEventLogger(appLoadContext: Record<string, unknown>) {\n const context = (appLoadContext || {}) as {\n env?: Record<string, any>;\n waitUntil?: (promise: Promise<any>) => void;\n };\n\n const eventLoggerService = context?.env?.H2O_LOG_EVENT as\n | undefined\n | {fetch: (req: Request) => Promise<Response>};\n\n if (typeof eventLoggerService?.fetch !== 'function') return;\n\n return ({\n url,\n endTime = Date.now(),\n waitUntil = context?.waitUntil,\n ...rest\n }: H2OEvent) => {\n const promise = Promise.resolve().then(() =>\n eventLoggerService\n .fetch(\n new Request(url, {\n method: 'POST',\n body: JSON.stringify({\n endTime,\n ...rest,\n }),\n }),\n )\n .catch((error: Error) => {\n if (!hasWarned) {\n // This might repeat a lot of times due to\n // the same issue, so we only warn once.\n console.debug('Failed to log H2O event\\n', error.stack);\n hasWarned = true;\n }\n }),\n );\n\n promise && waitUntil?.(promise);\n };\n}\n","/// <reference types=\"@shopify/hydrogen\" />\nimport {\n createRequestHandler as createReactRouterRequestHandler,\n type AppLoadContext,\n type ServerBuild,\n} from 'react-router';\nimport {createEventLogger} from './event-logger';\n\nconst originalErrorToString = Error.prototype.toString;\nError.prototype.toString = function () {\n return this.stack || originalErrorToString.call(this);\n};\n\nexport function createRequestHandler<Context = unknown>({\n build,\n mode,\n poweredByHeader = true,\n getLoadContext,\n}: {\n build: ServerBuild;\n mode?: string;\n poweredByHeader?: boolean;\n getLoadContext?: (request: Request) => Promise<Context> | Context;\n}) {\n const handleRequest = createReactRouterRequestHandler(build, mode);\n\n return async (request: Request) => {\n const method = request.method;\n\n if ((method === 'GET' || method === 'HEAD') && request.body) {\n return new Response(`${method} requests cannot have a body`, {\n status: 400,\n });\n }\n\n const url = new URL(request.url);\n\n if (url.pathname.includes('//')) {\n return new Response(null, {\n status: 301,\n headers: {\n location: url.pathname.replace(/\\/+/g, '/'),\n },\n });\n }\n\n const context = getLoadContext\n ? ((await getLoadContext(request)) as AppLoadContext)\n : undefined;\n\n if (process.env.NODE_ENV === 'development' && context) {\n // Store logger in globalThis so it can be accessed from the worker.\n // The global property must be different from the binding name,\n // otherwise Miniflare throws an error when accessing it.\n globalThis.__H2O_LOG_EVENT ??= createEventLogger(context);\n }\n\n const startTime = Date.now();\n\n const response = await handleRequest(request, context);\n\n if (poweredByHeader) {\n response.headers.append('powered-by', 'Shopify, Hydrogen');\n }\n\n if (process.env.NODE_ENV === 'development') {\n globalThis.__H2O_LOG_EVENT?.({\n eventType: 'request',\n url: request.url,\n requestId: request.headers.get('request-id'),\n purpose: request.headers.get('purpose'),\n startTime,\n responseInit: {\n status: response.status,\n statusText: response.statusText,\n headers: Array.from(response.headers.entries()),\n } satisfies ResponseInit,\n });\n }\n\n return response;\n };\n}\n\ntype StorefrontHeaders = {\n requestGroupId: string | null;\n buyerIp: string | null;\n cookie: string | null;\n purpose: string | null;\n};\n\nexport function getStorefrontHeaders(request: Request): StorefrontHeaders {\n const headers = request.headers;\n return {\n requestGroupId: headers.get('request-id'),\n buyerIp: headers.get('oxygen-buyer-ip'),\n cookie: headers.get('cookie'),\n purpose: headers.get('purpose'),\n };\n}\n"]}
@@ -1,53 +1,7 @@
1
- import { createCookieFactory, createCookieSessionStorageFactory, createSessionStorageFactory, createMemorySessionStorageFactory, createRequestHandler as createRequestHandler$1 } from '@remix-run/server-runtime';
2
- export { MaxPartSizeExceededError, createSession, data, defer, isCookie, isSession, json, redirect, redirectDocument } from '@remix-run/server-runtime';
1
+ import { createRequestHandler as createRequestHandler$1 } from 'react-router';
2
+ export { createCookie, createCookieSessionStorage, createMemorySessionStorage, createSession, createSessionStorage, data, isCookie, isSession, redirect, redirectDocument } from 'react-router';
3
3
 
4
- // src/implementations.ts
5
-
6
- // src/crypto.ts
7
- var encoder = new TextEncoder();
8
- var sign = async (value, secret) => {
9
- const key = await createKey(secret, ["sign"]);
10
- const data2 = encoder.encode(value);
11
- const signature = await crypto.subtle.sign("HMAC", key, data2);
12
- const hash = btoa(String.fromCharCode(...new Uint8Array(signature))).replace(
13
- /=+$/,
14
- ""
15
- );
16
- return value + "." + hash;
17
- };
18
- var unsign = async (signed, secret) => {
19
- const index = signed.lastIndexOf(".");
20
- const value = signed.slice(0, index);
21
- const hash = signed.slice(index + 1);
22
- const key = await createKey(secret, ["verify"]);
23
- const data2 = encoder.encode(value);
24
- const signature = byteStringToUint8Array(atob(hash));
25
- const valid = await crypto.subtle.verify("HMAC", key, signature, data2);
26
- return valid ? value : false;
27
- };
28
- async function createKey(secret, usages) {
29
- const key = await crypto.subtle.importKey(
30
- "raw",
31
- encoder.encode(secret),
32
- { name: "HMAC", hash: "SHA-256" },
33
- false,
34
- usages
35
- );
36
- return key;
37
- }
38
- function byteStringToUint8Array(byteString) {
39
- const array = new Uint8Array(byteString.length);
40
- for (let i = 0; i < byteString.length; i++) {
41
- array[i] = byteString.charCodeAt(i);
42
- }
43
- return array;
44
- }
45
-
46
- // src/implementations.ts
47
- var createCookie = createCookieFactory({ sign, unsign });
48
- var createCookieSessionStorage = createCookieSessionStorageFactory(createCookie);
49
- var createSessionStorage = createSessionStorageFactory(createCookie);
50
- var createMemorySessionStorage = createMemorySessionStorageFactory(createSessionStorage);
4
+ // src/server.ts
51
5
 
52
6
  // src/event-logger.ts
53
7
  var hasWarned = false;
@@ -145,6 +99,6 @@ function getStorefrontHeaders(request) {
145
99
  };
146
100
  }
147
101
 
148
- export { createCookie, createCookieSessionStorage, createMemorySessionStorage, createRequestHandler, createSessionStorage, getStorefrontHeaders };
102
+ export { createRequestHandler, getStorefrontHeaders };
149
103
  //# sourceMappingURL=index.js.map
150
104
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/crypto.ts","../../src/implementations.ts","../../src/event-logger.ts","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A,CAAQ,SAAS;AAAA;AAChD,OACD,CAAA;AAAA;AAGH,IAAO,OAAA,QAAA;AAAA,GACT;AACF;AASO,SAAS,qBAAqB,OAAqC,EAAA;AACxE,EAAA,MAAM,UAAU,OAAQ,CAAA,OAAA;AACxB,EAAO,OAAA;AAAA,IACL,cAAA,EAAgB,OAAQ,CAAA,GAAA,CAAI,YAAY,CAAA;AAAA,IACxC,OAAA,EAAS,OAAQ,CAAA,GAAA,CAAI,iBAAiB,CAAA;AAAA,IACtC,MAAA,EAAQ,OAAQ,CAAA,GAAA,CAAI,QAAQ,CAAA;AAAA,IAC5B,OAAA,EAAS,OAAQ,CAAA,GAAA,CAAI,SAAS;AAAA,GAChC;AACF","file":"index.js","sourcesContent":["import type {SignFunction, UnsignFunction} from '@remix-run/server-runtime';\n\nconst encoder = new TextEncoder();\n\nexport const sign: SignFunction = async (value, secret) => {\n const key = await createKey(secret, ['sign']);\n const data = encoder.encode(value);\n const signature = await crypto.subtle.sign('HMAC', key, data);\n const hash = btoa(String.fromCharCode(...new Uint8Array(signature))).replace(\n /=+$/,\n '',\n );\n\n return value + '.' + hash;\n};\n\nexport const unsign: UnsignFunction = async (signed, secret) => {\n const index = signed.lastIndexOf('.');\n const value = signed.slice(0, index);\n const hash = signed.slice(index + 1);\n\n const key = await createKey(secret, ['verify']);\n const data = encoder.encode(value);\n const signature = byteStringToUint8Array(atob(hash));\n const valid = await crypto.subtle.verify('HMAC', key, signature, data);\n\n return valid ? value : false;\n};\n\nasync function createKey(\n secret: string,\n usages: CryptoKey['usages'],\n): Promise<CryptoKey> {\n const key = await crypto.subtle.importKey(\n 'raw',\n encoder.encode(secret),\n {name: 'HMAC', hash: 'SHA-256'},\n false,\n usages,\n );\n\n return key;\n}\n\nfunction byteStringToUint8Array(byteString: string): Uint8Array {\n const array = new Uint8Array(byteString.length);\n\n for (let i = 0; i < byteString.length; i++) {\n array[i] = byteString.charCodeAt(i);\n }\n\n return array;\n}\n","import {\n createCookieFactory,\n createCookieSessionStorageFactory,\n createMemorySessionStorageFactory,\n createSessionStorageFactory,\n} from '@remix-run/server-runtime';\n\nimport {sign, unsign} from './crypto';\n\nexport const createCookie = createCookieFactory({sign, unsign});\nexport const createCookieSessionStorage =\n createCookieSessionStorageFactory(createCookie);\nexport const createSessionStorage = createSessionStorageFactory(createCookie);\nexport const createMemorySessionStorage =\n createMemorySessionStorageFactory(createSessionStorage);\n","type H2OEvent = Parameters<NonNullable<typeof __H2O_LOG_EVENT>>[0];\n\nlet hasWarned = false;\n\n/**\n * @deprecated Only used with the classic Remix compiler\n */\nexport function createEventLogger(appLoadContext: Record<string, unknown>) {\n const context = (appLoadContext || {}) as {\n env?: Record<string, any>;\n waitUntil?: (promise: Promise<any>) => void;\n };\n\n const eventLoggerService = context?.env?.H2O_LOG_EVENT as\n | undefined\n | {fetch: (req: Request) => Promise<Response>};\n\n if (typeof eventLoggerService?.fetch !== 'function') return;\n\n return ({\n url,\n endTime = Date.now(),\n waitUntil = context?.waitUntil,\n ...rest\n }: H2OEvent) => {\n const promise = Promise.resolve().then(() =>\n eventLoggerService\n .fetch(\n new Request(url, {\n method: 'POST',\n body: JSON.stringify({\n endTime,\n ...rest,\n }),\n }),\n )\n .catch((error: Error) => {\n if (!hasWarned) {\n // This might repeat a lot of times due to\n // the same issue, so we only warn once.\n console.debug('Failed to log H2O event\\n', error.stack);\n hasWarned = true;\n }\n }),\n );\n\n promise && waitUntil?.(promise);\n };\n}\n","/// <reference types=\"@shopify/hydrogen\" />\nimport {\n createRequestHandler as createRemixRequestHandler,\n type AppLoadContext,\n type ServerBuild,\n} from '@remix-run/server-runtime';\nimport {createEventLogger} from './event-logger';\n\nconst originalErrorToString = Error.prototype.toString;\nError.prototype.toString = function () {\n return this.stack || originalErrorToString.call(this);\n};\n\nexport function createRequestHandler<Context = unknown>({\n build,\n mode,\n poweredByHeader = true,\n getLoadContext,\n}: {\n build: ServerBuild;\n mode?: string;\n poweredByHeader?: boolean;\n getLoadContext?: (request: Request) => Promise<Context> | Context;\n}) {\n const handleRequest = createRemixRequestHandler(build, mode);\n\n return async (request: Request) => {\n const method = request.method;\n\n if ((method === 'GET' || method === 'HEAD') && request.body) {\n return new Response(`${method} requests cannot have a body`, {\n status: 400,\n });\n }\n\n const url = new URL(request.url);\n\n if (url.pathname.includes('//')) {\n return new Response(null, {\n status: 301,\n headers: {\n location: url.pathname.replace(/\\/+/g, '/'),\n },\n });\n }\n\n const context = getLoadContext\n ? ((await getLoadContext(request)) as AppLoadContext)\n : undefined;\n\n if (process.env.NODE_ENV === 'development' && context) {\n // Store logger in globalThis so it can be accessed from the worker.\n // The global property must be different from the binding name,\n // otherwise Miniflare throws an error when accessing it.\n globalThis.__H2O_LOG_EVENT ??= createEventLogger(context);\n }\n\n const startTime = Date.now();\n\n const response = await handleRequest(request, context);\n\n if (poweredByHeader) {\n response.headers.append('powered-by', 'Shopify, Hydrogen');\n }\n\n if (process.env.NODE_ENV === 'development') {\n globalThis.__H2O_LOG_EVENT?.({\n eventType: 'request',\n url: request.url,\n requestId: request.headers.get('request-id'),\n purpose: request.headers.get('purpose'),\n startTime,\n responseInit: {\n status: response.status,\n statusText: response.statusText,\n headers: Array.from(response.headers.entries()),\n } satisfies ResponseInit,\n });\n }\n\n return response;\n };\n}\n\ntype StorefrontHeaders = {\n requestGroupId: string | null;\n buyerIp: string | null;\n cookie: string | null;\n purpose: string | null;\n};\n\nexport function getStorefrontHeaders(request: Request): StorefrontHeaders {\n const headers = request.headers;\n return {\n requestGroupId: headers.get('request-id'),\n buyerIp: headers.get('oxygen-buyer-ip'),\n cookie: headers.get('cookie'),\n purpose: headers.get('purpose'),\n };\n}\n"]}
1
+ {"version":3,"sources":["../../src/event-logger.ts","../../src/server.ts"],"names":["createReactRouterRequestHandler"],"mappings":";;;;;;AAEA,IAAI,SAAY,GAAA,KAAA;AAKT,SAAS,kBAAkB,cAAyC,EAAA;AACzE,EAAM,MAAA,OAAA,GAAW,kBAAkB,EAAC;AAKpC,EAAM,MAA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AAA,OAAA,CAAQ,OAAQ,CAAA,GAAA,CAAI,SAAS,CAAA;AAAA,QACtC,SAAA;AAAA,QACA,YAAc,EAAA;AAAA,UACZ,QAAQ,QAAS,CAAA,MAAA;AAAA,UACjB,YAAY,QAAS,CAAA,UAAA;AAAA,UACrB,SAAS,KAAM,CAAA,IAAA,CAAK,QAAS,CAAA,OAAA,CAAQ,SAAS;AAAA;AAChD,OACD,CAAA;AAAA;AAGH,IAAO,OAAA,QAAA;AAAA,GACT;AACF;AASO,SAAS,qBAAqB,OAAqC,EAAA;AACxE,EAAA,MAAM,UAAU,OAAQ,CAAA,OAAA;AACxB,EAAO,OAAA;AAAA,IACL,cAAA,EAAgB,OAAQ,CAAA,GAAA,CAAI,YAAY,CAAA;AAAA,IACxC,OAAA,EAAS,OAAQ,CAAA,GAAA,CAAI,iBAAiB,CAAA;AAAA,IACtC,MAAA,EAAQ,OAAQ,CAAA,GAAA,CAAI,QAAQ,CAAA;AAAA,IAC5B,OAAA,EAAS,OAAQ,CAAA,GAAA,CAAI,SAAS;AAAA,GAChC;AACF","file":"index.js","sourcesContent":["type H2OEvent = Parameters<NonNullable<typeof __H2O_LOG_EVENT>>[0];\n\nlet hasWarned = false;\n\n/**\n * @deprecated Only used with the classic Remix compiler\n */\nexport function createEventLogger(appLoadContext: Record<string, unknown>) {\n const context = (appLoadContext || {}) as {\n env?: Record<string, any>;\n waitUntil?: (promise: Promise<any>) => void;\n };\n\n const eventLoggerService = context?.env?.H2O_LOG_EVENT as\n | undefined\n | {fetch: (req: Request) => Promise<Response>};\n\n if (typeof eventLoggerService?.fetch !== 'function') return;\n\n return ({\n url,\n endTime = Date.now(),\n waitUntil = context?.waitUntil,\n ...rest\n }: H2OEvent) => {\n const promise = Promise.resolve().then(() =>\n eventLoggerService\n .fetch(\n new Request(url, {\n method: 'POST',\n body: JSON.stringify({\n endTime,\n ...rest,\n }),\n }),\n )\n .catch((error: Error) => {\n if (!hasWarned) {\n // This might repeat a lot of times due to\n // the same issue, so we only warn once.\n console.debug('Failed to log H2O event\\n', error.stack);\n hasWarned = true;\n }\n }),\n );\n\n promise && waitUntil?.(promise);\n };\n}\n","/// <reference types=\"@shopify/hydrogen\" />\nimport {\n createRequestHandler as createReactRouterRequestHandler,\n type AppLoadContext,\n type ServerBuild,\n} from 'react-router';\nimport {createEventLogger} from './event-logger';\n\nconst originalErrorToString = Error.prototype.toString;\nError.prototype.toString = function () {\n return this.stack || originalErrorToString.call(this);\n};\n\nexport function createRequestHandler<Context = unknown>({\n build,\n mode,\n poweredByHeader = true,\n getLoadContext,\n}: {\n build: ServerBuild;\n mode?: string;\n poweredByHeader?: boolean;\n getLoadContext?: (request: Request) => Promise<Context> | Context;\n}) {\n const handleRequest = createReactRouterRequestHandler(build, mode);\n\n return async (request: Request) => {\n const method = request.method;\n\n if ((method === 'GET' || method === 'HEAD') && request.body) {\n return new Response(`${method} requests cannot have a body`, {\n status: 400,\n });\n }\n\n const url = new URL(request.url);\n\n if (url.pathname.includes('//')) {\n return new Response(null, {\n status: 301,\n headers: {\n location: url.pathname.replace(/\\/+/g, '/'),\n },\n });\n }\n\n const context = getLoadContext\n ? ((await getLoadContext(request)) as AppLoadContext)\n : undefined;\n\n if (process.env.NODE_ENV === 'development' && context) {\n // Store logger in globalThis so it can be accessed from the worker.\n // The global property must be different from the binding name,\n // otherwise Miniflare throws an error when accessing it.\n globalThis.__H2O_LOG_EVENT ??= createEventLogger(context);\n }\n\n const startTime = Date.now();\n\n const response = await handleRequest(request, context);\n\n if (poweredByHeader) {\n response.headers.append('powered-by', 'Shopify, Hydrogen');\n }\n\n if (process.env.NODE_ENV === 'development') {\n globalThis.__H2O_LOG_EVENT?.({\n eventType: 'request',\n url: request.url,\n requestId: request.headers.get('request-id'),\n purpose: request.headers.get('purpose'),\n startTime,\n responseInit: {\n status: response.status,\n statusText: response.statusText,\n headers: Array.from(response.headers.entries()),\n } satisfies ResponseInit,\n });\n }\n\n return response;\n };\n}\n\ntype StorefrontHeaders = {\n requestGroupId: string | null;\n buyerIp: string | null;\n cookie: string | null;\n purpose: string | null;\n};\n\nexport function getStorefrontHeaders(request: Request): StorefrontHeaders {\n const headers = request.headers;\n return {\n requestGroupId: headers.get('request-id'),\n buyerIp: headers.get('oxygen-buyer-ip'),\n cookie: headers.get('cookie'),\n purpose: headers.get('purpose'),\n };\n}\n"]}
@@ -1,3 +1,3 @@
1
- 'use strict';var serverRuntime=require('@remix-run/server-runtime');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:false};async function y(e,t){return await crypto.subtle.importKey("raw",c.encode(e),{name:"HMAC",hash:"SHA-256"},false,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=serverRuntime.createCookieFactory({sign:l,unsign:g}),C=serverRuntime.createCookieSessionStorageFactory(u),S=serverRuntime.createSessionStorageFactory(u),k=serverRuntime.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=true,getLoadContext:n}){let s=serverRuntime.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")}}
2
- Object.defineProperty(exports,"MaxPartSizeExceededError",{enumerable:true,get:function(){return serverRuntime.MaxPartSizeExceededError}});Object.defineProperty(exports,"createSession",{enumerable:true,get:function(){return serverRuntime.createSession}});Object.defineProperty(exports,"data",{enumerable:true,get:function(){return serverRuntime.data}});Object.defineProperty(exports,"defer",{enumerable:true,get:function(){return serverRuntime.defer}});Object.defineProperty(exports,"isCookie",{enumerable:true,get:function(){return serverRuntime.isCookie}});Object.defineProperty(exports,"isSession",{enumerable:true,get:function(){return serverRuntime.isSession}});Object.defineProperty(exports,"json",{enumerable:true,get:function(){return serverRuntime.json}});Object.defineProperty(exports,"redirect",{enumerable:true,get:function(){return serverRuntime.redirect}});Object.defineProperty(exports,"redirectDocument",{enumerable:true,get:function(){return serverRuntime.redirectDocument}});exports.createCookie=u;exports.createCookieSessionStorage=C;exports.createMemorySessionStorage=k;exports.createRequestHandler=E;exports.createSessionStorage=S;exports.getStorefrontHeaders=v;//# sourceMappingURL=index.cjs.map
1
+ 'use strict';var reactRouter=require('react-router');var d=Error.prototype.toString;Error.prototype.toString=function(){return this.stack||d.call(this)};function l({build:r,mode:e,poweredByHeader:a=true,getLoadContext:n}){let u=reactRouter.createRequestHandler(r,e);return async t=>{let o=t.method;if((o==="GET"||o==="HEAD")&&t.body)return new Response(`${o} requests cannot have a body`,{status:400});let s=new URL(t.url);if(s.pathname.includes("//"))return new Response(null,{status:301,headers:{location:s.pathname.replace(/\/+/g,"/")}});let p=n?await n(t):void 0,i=await u(t,p);return a&&i.headers.append("powered-by","Shopify, Hydrogen"),i}}function g(r){let e=r.headers;return {requestGroupId:e.get("request-id"),buyerIp:e.get("oxygen-buyer-ip"),cookie:e.get("cookie"),purpose:e.get("purpose")}}
2
+ Object.defineProperty(exports,"createCookie",{enumerable:true,get:function(){return reactRouter.createCookie}});Object.defineProperty(exports,"createCookieSessionStorage",{enumerable:true,get:function(){return reactRouter.createCookieSessionStorage}});Object.defineProperty(exports,"createMemorySessionStorage",{enumerable:true,get:function(){return reactRouter.createMemorySessionStorage}});Object.defineProperty(exports,"createSession",{enumerable:true,get:function(){return reactRouter.createSession}});Object.defineProperty(exports,"createSessionStorage",{enumerable:true,get:function(){return reactRouter.createSessionStorage}});Object.defineProperty(exports,"data",{enumerable:true,get:function(){return reactRouter.data}});Object.defineProperty(exports,"isCookie",{enumerable:true,get:function(){return reactRouter.isCookie}});Object.defineProperty(exports,"isSession",{enumerable:true,get:function(){return reactRouter.isSession}});Object.defineProperty(exports,"redirect",{enumerable:true,get:function(){return reactRouter.redirect}});Object.defineProperty(exports,"redirectDocument",{enumerable:true,get:function(){return reactRouter.redirectDocument}});exports.createRequestHandler=l;exports.getStorefrontHeaders=g;//# sourceMappingURL=index.cjs.map
3
3
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/crypto.ts","../../src/implementations.ts","../../src/server.ts"],"names":["encoder","sign","value","secret","key","createKey","data","signature","hash","unsign","signed","index","byteStringToUint8Array","usages","byteString","array","i","createCookie","createCookieFactory","createCookieSessionStorage","createCookieSessionStorageFactory","createSessionStorage","createSessionStorageFactory","createMemorySessionStorage","createMemorySessionStorageFactory","originalErrorToString","createRequestHandler","build","mode","poweredByHeader","getLoadContext","handleRequest","createRemixRequestHandler","request","method","url","context","response","getStorefrontHeaders","headers"],"mappings":"oEAEA,IAAMA,CAAU,CAAA,IAAI,YAEPC,CAAqB,CAAA,MAAOC,EAAOC,CAAW,GAAA,CACzD,IAAMC,CAAM,CAAA,MAAMC,CAAUF,CAAAA,CAAAA,CAAQ,CAAC,MAAM,CAAC,EACtCG,CAAON,CAAAA,CAAAA,CAAQ,OAAOE,CAAK,CAAA,CAC3BK,EAAY,MAAM,MAAA,CAAO,OAAO,IAAK,CAAA,MAAA,CAAQH,EAAKE,CAAI,CAAA,CACtDE,EAAO,IAAK,CAAA,MAAA,CAAO,YAAa,CAAA,GAAG,IAAI,UAAWD,CAAAA,CAAS,CAAC,CAAC,CAAA,CAAE,QACnE,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SAASC,CAAAA,CAAqBL,EAAqC,CACxE,IAAMM,CAAUN,CAAAA,CAAAA,CAAQ,QACxB,OAAO,CACL,eAAgBM,CAAQ,CAAA,GAAA,CAAI,YAAY,CACxC,CAAA,OAAA,CAASA,EAAQ,GAAI,CAAA,iBAAiB,EACtC,MAAQA,CAAAA,CAAAA,CAAQ,IAAI,QAAQ,CAAA,CAC5B,QAASA,CAAQ,CAAA,GAAA,CAAI,SAAS,CAChC,CACF","file":"index.cjs","sourcesContent":["import type {SignFunction, UnsignFunction} from '@remix-run/server-runtime';\n\nconst encoder = new TextEncoder();\n\nexport const sign: SignFunction = async (value, secret) => {\n const key = await createKey(secret, ['sign']);\n const data = encoder.encode(value);\n const signature = await crypto.subtle.sign('HMAC', key, data);\n const hash = btoa(String.fromCharCode(...new Uint8Array(signature))).replace(\n /=+$/,\n '',\n );\n\n return value + '.' + hash;\n};\n\nexport const unsign: UnsignFunction = async (signed, secret) => {\n const index = signed.lastIndexOf('.');\n const value = signed.slice(0, index);\n const hash = signed.slice(index + 1);\n\n const key = await createKey(secret, ['verify']);\n const data = encoder.encode(value);\n const signature = byteStringToUint8Array(atob(hash));\n const valid = await crypto.subtle.verify('HMAC', key, signature, data);\n\n return valid ? value : false;\n};\n\nasync function createKey(\n secret: string,\n usages: CryptoKey['usages'],\n): Promise<CryptoKey> {\n const key = await crypto.subtle.importKey(\n 'raw',\n encoder.encode(secret),\n {name: 'HMAC', hash: 'SHA-256'},\n false,\n usages,\n );\n\n return key;\n}\n\nfunction byteStringToUint8Array(byteString: string): Uint8Array {\n const array = new Uint8Array(byteString.length);\n\n for (let i = 0; i < byteString.length; i++) {\n array[i] = byteString.charCodeAt(i);\n }\n\n return array;\n}\n","import {\n createCookieFactory,\n createCookieSessionStorageFactory,\n createMemorySessionStorageFactory,\n createSessionStorageFactory,\n} from '@remix-run/server-runtime';\n\nimport {sign, unsign} from './crypto';\n\nexport const createCookie = createCookieFactory({sign, unsign});\nexport const createCookieSessionStorage =\n createCookieSessionStorageFactory(createCookie);\nexport const createSessionStorage = createSessionStorageFactory(createCookie);\nexport const createMemorySessionStorage =\n createMemorySessionStorageFactory(createSessionStorage);\n","/// <reference types=\"@shopify/hydrogen\" />\nimport {\n createRequestHandler as createRemixRequestHandler,\n type AppLoadContext,\n type ServerBuild,\n} from '@remix-run/server-runtime';\nimport {createEventLogger} from './event-logger';\n\nconst originalErrorToString = Error.prototype.toString;\nError.prototype.toString = function () {\n return this.stack || originalErrorToString.call(this);\n};\n\nexport function createRequestHandler<Context = unknown>({\n build,\n mode,\n poweredByHeader = true,\n getLoadContext,\n}: {\n build: ServerBuild;\n mode?: string;\n poweredByHeader?: boolean;\n getLoadContext?: (request: Request) => Promise<Context> | Context;\n}) {\n const handleRequest = createRemixRequestHandler(build, mode);\n\n return async (request: Request) => {\n const method = request.method;\n\n if ((method === 'GET' || method === 'HEAD') && request.body) {\n return new Response(`${method} requests cannot have a body`, {\n status: 400,\n });\n }\n\n const url = new URL(request.url);\n\n if (url.pathname.includes('//')) {\n return new Response(null, {\n status: 301,\n headers: {\n location: url.pathname.replace(/\\/+/g, '/'),\n },\n });\n }\n\n const context = getLoadContext\n ? ((await getLoadContext(request)) as AppLoadContext)\n : undefined;\n\n if (process.env.NODE_ENV === 'development' && context) {\n // Store logger in globalThis so it can be accessed from the worker.\n // The global property must be different from the binding name,\n // otherwise Miniflare throws an error when accessing it.\n globalThis.__H2O_LOG_EVENT ??= createEventLogger(context);\n }\n\n const startTime = Date.now();\n\n const response = await handleRequest(request, context);\n\n if (poweredByHeader) {\n response.headers.append('powered-by', 'Shopify, Hydrogen');\n }\n\n if (process.env.NODE_ENV === 'development') {\n globalThis.__H2O_LOG_EVENT?.({\n eventType: 'request',\n url: request.url,\n requestId: request.headers.get('request-id'),\n purpose: request.headers.get('purpose'),\n startTime,\n responseInit: {\n status: response.status,\n statusText: response.statusText,\n headers: Array.from(response.headers.entries()),\n } satisfies ResponseInit,\n });\n }\n\n return response;\n };\n}\n\ntype StorefrontHeaders = {\n requestGroupId: string | null;\n buyerIp: string | null;\n cookie: string | null;\n purpose: string | null;\n};\n\nexport function getStorefrontHeaders(request: Request): StorefrontHeaders {\n const headers = request.headers;\n return {\n requestGroupId: headers.get('request-id'),\n buyerIp: headers.get('oxygen-buyer-ip'),\n cookie: headers.get('cookie'),\n purpose: headers.get('purpose'),\n };\n}\n"]}
1
+ {"version":3,"sources":["../../src/server.ts"],"names":["originalErrorToString","createRequestHandler","build","mode","poweredByHeader","getLoadContext","handleRequest","createReactRouterRequestHandler","request","method","url","context","response","getStorefrontHeaders","headers"],"mappings":"qDAQA,IAAMA,CAAwB,CAAA,KAAA,CAAM,UAAU,QAC9C,CAAA,KAAA,CAAM,UAAU,QAAW,CAAA,UAAY,CACrC,OAAO,IAAA,CAAK,OAASA,CAAsB,CAAA,IAAA,CAAK,IAAI,CACtD,CAAA,CAEO,SAASC,CAAAA,CAAwC,CACtD,KAAAC,CAAAA,CAAAA,CACA,KAAAC,CACA,CAAA,eAAA,CAAAC,EAAkB,IAClB,CAAA,cAAA,CAAAC,CACF,CAKG,CAAA,CACD,IAAMC,CAAgBC,CAAAA,gCAAAA,CAAgCL,EAAOC,CAAI,CAAA,CAEjE,OAAcK,MAAAA,CAAAA,EAAqB,CACjC,IAAMC,EAASD,CAAQ,CAAA,MAAA,CAEvB,IAAKC,CAAW,GAAA,KAAA,EAASA,IAAW,MAAWD,GAAAA,CAAAA,CAAQ,KACrD,OAAO,IAAI,SAAS,CAAGC,EAAAA,CAAM,+BAAgC,CAC3D,MAAA,CAAQ,GACV,CAAC,CAAA,CAGH,IAAMC,CAAAA,CAAM,IAAI,GAAIF,CAAAA,CAAAA,CAAQ,GAAG,CAE/B,CAAA,GAAIE,EAAI,QAAS,CAAA,QAAA,CAAS,IAAI,CAC5B,CAAA,OAAO,IAAI,QAAS,CAAA,IAAA,CAAM,CACxB,MAAQ,CAAA,GAAA,CACR,QAAS,CACP,QAAA,CAAUA,CAAI,CAAA,QAAA,CAAS,QAAQ,MAAQ,CAAA,GAAG,CAC5C,CACF,CAAC,EAGGC,IAAAA,CAAAA,CAAUN,EACV,MAAMA,CAAAA,CAAeG,CAAO,CAC9B,CAAA,MAAA,CAWEI,CAAW,CAAA,MAAMN,CAAcE,CAAAA,CAAAA,CAASG,CAAO,EAErD,OAAIP,GACFQ,CAAS,CAAA,OAAA,CAAQ,OAAO,YAAc,CAAA,mBAAmB,EAkBpDA,CACT,CACF,CASO,SAASC,CAAAA,CAAqBL,EAAqC,CACxE,IAAMM,EAAUN,CAAQ,CAAA,OAAA,CACxB,OAAO,CACL,eAAgBM,CAAQ,CAAA,GAAA,CAAI,YAAY,CACxC,CAAA,OAAA,CAASA,EAAQ,GAAI,CAAA,iBAAiB,EACtC,MAAQA,CAAAA,CAAAA,CAAQ,IAAI,QAAQ,CAAA,CAC5B,QAASA,CAAQ,CAAA,GAAA,CAAI,SAAS,CAChC,CACF","file":"index.cjs","sourcesContent":["/// <reference types=\"@shopify/hydrogen\" />\nimport {\n createRequestHandler as createReactRouterRequestHandler,\n type AppLoadContext,\n type ServerBuild,\n} from 'react-router';\nimport {createEventLogger} from './event-logger';\n\nconst originalErrorToString = Error.prototype.toString;\nError.prototype.toString = function () {\n return this.stack || originalErrorToString.call(this);\n};\n\nexport function createRequestHandler<Context = unknown>({\n build,\n mode,\n poweredByHeader = true,\n getLoadContext,\n}: {\n build: ServerBuild;\n mode?: string;\n poweredByHeader?: boolean;\n getLoadContext?: (request: Request) => Promise<Context> | Context;\n}) {\n const handleRequest = createReactRouterRequestHandler(build, mode);\n\n return async (request: Request) => {\n const method = request.method;\n\n if ((method === 'GET' || method === 'HEAD') && request.body) {\n return new Response(`${method} requests cannot have a body`, {\n status: 400,\n });\n }\n\n const url = new URL(request.url);\n\n if (url.pathname.includes('//')) {\n return new Response(null, {\n status: 301,\n headers: {\n location: url.pathname.replace(/\\/+/g, '/'),\n },\n });\n }\n\n const context = getLoadContext\n ? ((await getLoadContext(request)) as AppLoadContext)\n : undefined;\n\n if (process.env.NODE_ENV === 'development' && context) {\n // Store logger in globalThis so it can be accessed from the worker.\n // The global property must be different from the binding name,\n // otherwise Miniflare throws an error when accessing it.\n globalThis.__H2O_LOG_EVENT ??= createEventLogger(context);\n }\n\n const startTime = Date.now();\n\n const response = await handleRequest(request, context);\n\n if (poweredByHeader) {\n response.headers.append('powered-by', 'Shopify, Hydrogen');\n }\n\n if (process.env.NODE_ENV === 'development') {\n globalThis.__H2O_LOG_EVENT?.({\n eventType: 'request',\n url: request.url,\n requestId: request.headers.get('request-id'),\n purpose: request.headers.get('purpose'),\n startTime,\n responseInit: {\n status: response.status,\n statusText: response.statusText,\n headers: Array.from(response.headers.entries()),\n } satisfies ResponseInit,\n });\n }\n\n return response;\n };\n}\n\ntype StorefrontHeaders = {\n requestGroupId: string | null;\n buyerIp: string | null;\n cookie: string | null;\n purpose: string | null;\n};\n\nexport function getStorefrontHeaders(request: Request): StorefrontHeaders {\n const headers = request.headers;\n return {\n requestGroupId: headers.get('request-id'),\n buyerIp: headers.get('oxygen-buyer-ip'),\n cookie: headers.get('cookie'),\n purpose: headers.get('purpose'),\n };\n}\n"]}
@@ -1,11 +1,5 @@
1
- import * as _remix_run_server_runtime from '@remix-run/server-runtime';
2
- import { ServerBuild } from '@remix-run/server-runtime';
3
- 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, data, defer, isCookie, isSession, json, redirect, redirectDocument } from '@remix-run/server-runtime';
4
-
5
- declare const createCookie: _remix_run_server_runtime.CreateCookieFunction;
6
- declare const createCookieSessionStorage: _remix_run_server_runtime.CreateCookieSessionStorageFunction;
7
- declare const createSessionStorage: _remix_run_server_runtime.CreateSessionStorageFunction;
8
- declare const createMemorySessionStorage: _remix_run_server_runtime.CreateMemorySessionStorageFunction;
1
+ import { ServerBuild } from 'react-router';
2
+ export { ActionFunction, ActionFunctionArgs, AppLoadContext, Cookie, CookieOptions, CookieParseOptions, CookieSerializeOptions, CookieSignatureOptions, EntryContext, ErrorResponse, HandleDataRequestFunction, HandleDocumentRequestFunction, HandleErrorFunction, HeadersArgs, HeadersFunction, HtmlLinkDescriptor, LinkDescriptor, LinksFunction, LoaderFunction, LoaderFunctionArgs, MetaArgs, MetaDescriptor, MetaFunction, PageLinkDescriptor, RequestHandler, ServerBuild, ServerEntryModule, Session, SessionData, SessionIdStorageStrategy, SessionStorage, createCookie, createCookieSessionStorage, createMemorySessionStorage, createSession, createSessionStorage, data, isCookie, isSession, redirect, redirectDocument } from 'react-router';
9
3
 
10
4
  declare function createRequestHandler<Context = unknown>({ build, mode, poweredByHeader, getLoadContext, }: {
11
5
  build: ServerBuild;
@@ -21,4 +15,4 @@ type StorefrontHeaders = {
21
15
  };
22
16
  declare function getStorefrontHeaders(request: Request): StorefrontHeaders;
23
17
 
24
- export { createCookie, createCookieSessionStorage, createMemorySessionStorage, createRequestHandler, createSessionStorage, getStorefrontHeaders };
18
+ export { createRequestHandler, getStorefrontHeaders };
@@ -1,11 +1,5 @@
1
- import * as _remix_run_server_runtime from '@remix-run/server-runtime';
2
- import { ServerBuild } from '@remix-run/server-runtime';
3
- 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, data, defer, isCookie, isSession, json, redirect, redirectDocument } from '@remix-run/server-runtime';
4
-
5
- declare const createCookie: _remix_run_server_runtime.CreateCookieFunction;
6
- declare const createCookieSessionStorage: _remix_run_server_runtime.CreateCookieSessionStorageFunction;
7
- declare const createSessionStorage: _remix_run_server_runtime.CreateSessionStorageFunction;
8
- declare const createMemorySessionStorage: _remix_run_server_runtime.CreateMemorySessionStorageFunction;
1
+ import { ServerBuild } from 'react-router';
2
+ export { ActionFunction, ActionFunctionArgs, AppLoadContext, Cookie, CookieOptions, CookieParseOptions, CookieSerializeOptions, CookieSignatureOptions, EntryContext, ErrorResponse, HandleDataRequestFunction, HandleDocumentRequestFunction, HandleErrorFunction, HeadersArgs, HeadersFunction, HtmlLinkDescriptor, LinkDescriptor, LinksFunction, LoaderFunction, LoaderFunctionArgs, MetaArgs, MetaDescriptor, MetaFunction, PageLinkDescriptor, RequestHandler, ServerBuild, ServerEntryModule, Session, SessionData, SessionIdStorageStrategy, SessionStorage, createCookie, createCookieSessionStorage, createMemorySessionStorage, createSession, createSessionStorage, data, isCookie, isSession, redirect, redirectDocument } from 'react-router';
9
3
 
10
4
  declare function createRequestHandler<Context = unknown>({ build, mode, poweredByHeader, getLoadContext, }: {
11
5
  build: ServerBuild;
@@ -21,4 +15,4 @@ type StorefrontHeaders = {
21
15
  };
22
16
  declare function getStorefrontHeaders(request: Request): StorefrontHeaders;
23
17
 
24
- export { createCookie, createCookieSessionStorage, createMemorySessionStorage, createRequestHandler, createSessionStorage, getStorefrontHeaders };
18
+ export { createRequestHandler, getStorefrontHeaders };
@@ -1,3 +1,3 @@
1
- import {createCookieFactory,createCookieSessionStorageFactory,createSessionStorageFactory,createMemorySessionStorageFactory,createRequestHandler}from'@remix-run/server-runtime';export{MaxPartSizeExceededError,createSession,data,defer,isCookie,isSession,json,redirect,redirectDocument}from'@remix-run/server-runtime';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:false};async function y(e,t){return await crypto.subtle.importKey("raw",c.encode(e),{name:"HMAC",hash:"SHA-256"},false,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),k=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=true,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")}}
2
- export{u as createCookie,C as createCookieSessionStorage,k as createMemorySessionStorage,E as createRequestHandler,S as createSessionStorage,v as getStorefrontHeaders};//# sourceMappingURL=index.js.map
1
+ import {createRequestHandler}from'react-router';export{createCookie,createCookieSessionStorage,createMemorySessionStorage,createSession,createSessionStorage,data,isCookie,isSession,redirect,redirectDocument}from'react-router';var d=Error.prototype.toString;Error.prototype.toString=function(){return this.stack||d.call(this)};function l({build:r,mode:e,poweredByHeader:a=true,getLoadContext:n}){let u=createRequestHandler(r,e);return async t=>{let o=t.method;if((o==="GET"||o==="HEAD")&&t.body)return new Response(`${o} requests cannot have a body`,{status:400});let s=new URL(t.url);if(s.pathname.includes("//"))return new Response(null,{status:301,headers:{location:s.pathname.replace(/\/+/g,"/")}});let p=n?await n(t):void 0,i=await u(t,p);return a&&i.headers.append("powered-by","Shopify, Hydrogen"),i}}function g(r){let e=r.headers;return {requestGroupId:e.get("request-id"),buyerIp:e.get("oxygen-buyer-ip"),cookie:e.get("cookie"),purpose:e.get("purpose")}}
2
+ export{l as createRequestHandler,g as getStorefrontHeaders};//# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/crypto.ts","../../src/implementations.ts","../../src/server.ts"],"names":["encoder","sign","value","secret","key","createKey","data","signature","hash","unsign","signed","index","byteStringToUint8Array","usages","byteString","array","i","createCookie","createCookieFactory","createCookieSessionStorage","createCookieSessionStorageFactory","createSessionStorage","createSessionStorageFactory","createMemorySessionStorage","createMemorySessionStorageFactory","originalErrorToString","createRequestHandler","build","mode","poweredByHeader","getLoadContext","handleRequest","createRemixRequestHandler","request","method","url","context","response","getStorefrontHeaders","headers"],"mappings":"4TAEA,IAAMA,CAAU,CAAA,IAAI,YAEPC,CAAqB,CAAA,MAAOC,EAAOC,CAAW,GAAA,CACzD,IAAMC,CAAM,CAAA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AAAA,CAAAA,CAAI,SAAS,OAAQ,CAAA,MAAA,CAAQ,GAAG,CAC5C,CACF,CAAC,CAGH,CAAA,IAAMC,EAAUN,CACV,CAAA,MAAMA,EAAeG,CAAO,CAAA,CAC9B,OAWEI,CAAAA,CAAW,MAAMN,CAAcE,CAAAA,CAAAA,CAASG,CAAO,EAErD,OAAIP,GACFQ,CAAS,CAAA,OAAA,CAAQ,OAAO,YAAc,CAAA,mBAAmB,EAkBpDA,CACT,CACF,CASO,SAASC,CAAAA,CAAqBL,EAAqC,CACxE,IAAMM,CAAUN,CAAAA,CAAAA,CAAQ,QACxB,OAAO,CACL,eAAgBM,CAAQ,CAAA,GAAA,CAAI,YAAY,CACxC,CAAA,OAAA,CAASA,EAAQ,GAAI,CAAA,iBAAiB,EACtC,MAAQA,CAAAA,CAAAA,CAAQ,IAAI,QAAQ,CAAA,CAC5B,QAASA,CAAQ,CAAA,GAAA,CAAI,SAAS,CAChC,CACF","file":"index.js","sourcesContent":["import type {SignFunction, UnsignFunction} from '@remix-run/server-runtime';\n\nconst encoder = new TextEncoder();\n\nexport const sign: SignFunction = async (value, secret) => {\n const key = await createKey(secret, ['sign']);\n const data = encoder.encode(value);\n const signature = await crypto.subtle.sign('HMAC', key, data);\n const hash = btoa(String.fromCharCode(...new Uint8Array(signature))).replace(\n /=+$/,\n '',\n );\n\n return value + '.' + hash;\n};\n\nexport const unsign: UnsignFunction = async (signed, secret) => {\n const index = signed.lastIndexOf('.');\n const value = signed.slice(0, index);\n const hash = signed.slice(index + 1);\n\n const key = await createKey(secret, ['verify']);\n const data = encoder.encode(value);\n const signature = byteStringToUint8Array(atob(hash));\n const valid = await crypto.subtle.verify('HMAC', key, signature, data);\n\n return valid ? value : false;\n};\n\nasync function createKey(\n secret: string,\n usages: CryptoKey['usages'],\n): Promise<CryptoKey> {\n const key = await crypto.subtle.importKey(\n 'raw',\n encoder.encode(secret),\n {name: 'HMAC', hash: 'SHA-256'},\n false,\n usages,\n );\n\n return key;\n}\n\nfunction byteStringToUint8Array(byteString: string): Uint8Array {\n const array = new Uint8Array(byteString.length);\n\n for (let i = 0; i < byteString.length; i++) {\n array[i] = byteString.charCodeAt(i);\n }\n\n return array;\n}\n","import {\n createCookieFactory,\n createCookieSessionStorageFactory,\n createMemorySessionStorageFactory,\n createSessionStorageFactory,\n} from '@remix-run/server-runtime';\n\nimport {sign, unsign} from './crypto';\n\nexport const createCookie = createCookieFactory({sign, unsign});\nexport const createCookieSessionStorage =\n createCookieSessionStorageFactory(createCookie);\nexport const createSessionStorage = createSessionStorageFactory(createCookie);\nexport const createMemorySessionStorage =\n createMemorySessionStorageFactory(createSessionStorage);\n","/// <reference types=\"@shopify/hydrogen\" />\nimport {\n createRequestHandler as createRemixRequestHandler,\n type AppLoadContext,\n type ServerBuild,\n} from '@remix-run/server-runtime';\nimport {createEventLogger} from './event-logger';\n\nconst originalErrorToString = Error.prototype.toString;\nError.prototype.toString = function () {\n return this.stack || originalErrorToString.call(this);\n};\n\nexport function createRequestHandler<Context = unknown>({\n build,\n mode,\n poweredByHeader = true,\n getLoadContext,\n}: {\n build: ServerBuild;\n mode?: string;\n poweredByHeader?: boolean;\n getLoadContext?: (request: Request) => Promise<Context> | Context;\n}) {\n const handleRequest = createRemixRequestHandler(build, mode);\n\n return async (request: Request) => {\n const method = request.method;\n\n if ((method === 'GET' || method === 'HEAD') && request.body) {\n return new Response(`${method} requests cannot have a body`, {\n status: 400,\n });\n }\n\n const url = new URL(request.url);\n\n if (url.pathname.includes('//')) {\n return new Response(null, {\n status: 301,\n headers: {\n location: url.pathname.replace(/\\/+/g, '/'),\n },\n });\n }\n\n const context = getLoadContext\n ? ((await getLoadContext(request)) as AppLoadContext)\n : undefined;\n\n if (process.env.NODE_ENV === 'development' && context) {\n // Store logger in globalThis so it can be accessed from the worker.\n // The global property must be different from the binding name,\n // otherwise Miniflare throws an error when accessing it.\n globalThis.__H2O_LOG_EVENT ??= createEventLogger(context);\n }\n\n const startTime = Date.now();\n\n const response = await handleRequest(request, context);\n\n if (poweredByHeader) {\n response.headers.append('powered-by', 'Shopify, Hydrogen');\n }\n\n if (process.env.NODE_ENV === 'development') {\n globalThis.__H2O_LOG_EVENT?.({\n eventType: 'request',\n url: request.url,\n requestId: request.headers.get('request-id'),\n purpose: request.headers.get('purpose'),\n startTime,\n responseInit: {\n status: response.status,\n statusText: response.statusText,\n headers: Array.from(response.headers.entries()),\n } satisfies ResponseInit,\n });\n }\n\n return response;\n };\n}\n\ntype StorefrontHeaders = {\n requestGroupId: string | null;\n buyerIp: string | null;\n cookie: string | null;\n purpose: string | null;\n};\n\nexport function getStorefrontHeaders(request: Request): StorefrontHeaders {\n const headers = request.headers;\n return {\n requestGroupId: headers.get('request-id'),\n buyerIp: headers.get('oxygen-buyer-ip'),\n cookie: headers.get('cookie'),\n purpose: headers.get('purpose'),\n };\n}\n"]}
1
+ {"version":3,"sources":["../../src/server.ts"],"names":["originalErrorToString","createRequestHandler","build","mode","poweredByHeader","getLoadContext","handleRequest","createReactRouterRequestHandler","request","method","url","context","response","getStorefrontHeaders","headers"],"mappings":"kOAQA,IAAMA,CAAwB,CAAA,KAAA,CAAM,UAAU,QAC9C,CAAA,KAAA,CAAM,UAAU,QAAW,CAAA,UAAY,CACrC,OAAO,IAAA,CAAK,OAASA,CAAsB,CAAA,IAAA,CAAK,IAAI,CACtD,CAAA,CAEO,SAASC,CAAAA,CAAwC,CACtD,KAAAC,CAAAA,CAAAA,CACA,KAAAC,CACA,CAAA,eAAA,CAAAC,EAAkB,IAClB,CAAA,cAAA,CAAAC,CACF,CAKG,CAAA,CACD,IAAMC,CAAgBC,CAAAA,oBAAAA,CAAgCL,EAAOC,CAAI,CAAA,CAEjE,OAAcK,MAAAA,CAAAA,EAAqB,CACjC,IAAMC,EAASD,CAAQ,CAAA,MAAA,CAEvB,IAAKC,CAAW,GAAA,KAAA,EAASA,IAAW,MAAWD,GAAAA,CAAAA,CAAQ,KACrD,OAAO,IAAI,SAAS,CAAGC,EAAAA,CAAM,+BAAgC,CAC3D,MAAA,CAAQ,GACV,CAAC,CAAA,CAGH,IAAMC,CAAAA,CAAM,IAAI,GAAIF,CAAAA,CAAAA,CAAQ,GAAG,CAE/B,CAAA,GAAIE,EAAI,QAAS,CAAA,QAAA,CAAS,IAAI,CAC5B,CAAA,OAAO,IAAI,QAAS,CAAA,IAAA,CAAM,CACxB,MAAQ,CAAA,GAAA,CACR,QAAS,CACP,QAAA,CAAUA,CAAI,CAAA,QAAA,CAAS,QAAQ,MAAQ,CAAA,GAAG,CAC5C,CACF,CAAC,EAGGC,IAAAA,CAAAA,CAAUN,EACV,MAAMA,CAAAA,CAAeG,CAAO,CAC9B,CAAA,MAAA,CAWEI,CAAW,CAAA,MAAMN,CAAcE,CAAAA,CAAAA,CAASG,CAAO,EAErD,OAAIP,GACFQ,CAAS,CAAA,OAAA,CAAQ,OAAO,YAAc,CAAA,mBAAmB,EAkBpDA,CACT,CACF,CASO,SAASC,CAAAA,CAAqBL,EAAqC,CACxE,IAAMM,EAAUN,CAAQ,CAAA,OAAA,CACxB,OAAO,CACL,eAAgBM,CAAQ,CAAA,GAAA,CAAI,YAAY,CACxC,CAAA,OAAA,CAASA,EAAQ,GAAI,CAAA,iBAAiB,EACtC,MAAQA,CAAAA,CAAAA,CAAQ,IAAI,QAAQ,CAAA,CAC5B,QAASA,CAAQ,CAAA,GAAA,CAAI,SAAS,CAChC,CACF","file":"index.js","sourcesContent":["/// <reference types=\"@shopify/hydrogen\" />\nimport {\n createRequestHandler as createReactRouterRequestHandler,\n type AppLoadContext,\n type ServerBuild,\n} from 'react-router';\nimport {createEventLogger} from './event-logger';\n\nconst originalErrorToString = Error.prototype.toString;\nError.prototype.toString = function () {\n return this.stack || originalErrorToString.call(this);\n};\n\nexport function createRequestHandler<Context = unknown>({\n build,\n mode,\n poweredByHeader = true,\n getLoadContext,\n}: {\n build: ServerBuild;\n mode?: string;\n poweredByHeader?: boolean;\n getLoadContext?: (request: Request) => Promise<Context> | Context;\n}) {\n const handleRequest = createReactRouterRequestHandler(build, mode);\n\n return async (request: Request) => {\n const method = request.method;\n\n if ((method === 'GET' || method === 'HEAD') && request.body) {\n return new Response(`${method} requests cannot have a body`, {\n status: 400,\n });\n }\n\n const url = new URL(request.url);\n\n if (url.pathname.includes('//')) {\n return new Response(null, {\n status: 301,\n headers: {\n location: url.pathname.replace(/\\/+/g, '/'),\n },\n });\n }\n\n const context = getLoadContext\n ? ((await getLoadContext(request)) as AppLoadContext)\n : undefined;\n\n if (process.env.NODE_ENV === 'development' && context) {\n // Store logger in globalThis so it can be accessed from the worker.\n // The global property must be different from the binding name,\n // otherwise Miniflare throws an error when accessing it.\n globalThis.__H2O_LOG_EVENT ??= createEventLogger(context);\n }\n\n const startTime = Date.now();\n\n const response = await handleRequest(request, context);\n\n if (poweredByHeader) {\n response.headers.append('powered-by', 'Shopify, Hydrogen');\n }\n\n if (process.env.NODE_ENV === 'development') {\n globalThis.__H2O_LOG_EVENT?.({\n eventType: 'request',\n url: request.url,\n requestId: request.headers.get('request-id'),\n purpose: request.headers.get('purpose'),\n startTime,\n responseInit: {\n status: response.status,\n statusText: response.statusText,\n headers: Array.from(response.headers.entries()),\n } satisfies ResponseInit,\n });\n }\n\n return response;\n };\n}\n\ntype StorefrontHeaders = {\n requestGroupId: string | null;\n buyerIp: string | null;\n cookie: string | null;\n purpose: string | null;\n};\n\nexport function getStorefrontHeaders(request: Request): StorefrontHeaders {\n const headers = request.headers;\n return {\n requestGroupId: headers.get('request-id'),\n buyerIp: headers.get('oxygen-buyer-ip'),\n cookie: headers.get('cookie'),\n purpose: headers.get('purpose'),\n };\n}\n"]}
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "@shopify:registry": "https://registry.npmjs.org"
6
6
  },
7
7
  "type": "module",
8
- "version": "2.0.12",
8
+ "version": "3.0.0",
9
9
  "license": "MIT",
10
10
  "main": "dist/index.cjs",
11
11
  "module": "dist/production/index.js",
@@ -45,11 +45,11 @@
45
45
  "dist"
46
46
  ],
47
47
  "devDependencies": {
48
- "@remix-run/server-runtime": "^2.16.1",
49
- "@shopify/oxygen-workers-types": "^4.1.6"
48
+ "@shopify/oxygen-workers-types": "^4.1.6",
49
+ "react-router": "7.6.0"
50
50
  },
51
51
  "peerDependencies": {
52
- "@remix-run/server-runtime": "^2.16.1",
53
- "@shopify/oxygen-workers-types": "^3.17.3 || ^4.1.2"
52
+ "@shopify/oxygen-workers-types": "^3.17.3 || ^4.1.2",
53
+ "react-router": "7.6.0"
54
54
  }
55
55
  }