@shopify/remix-oxygen 2.0.11 → 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.
- package/dist/development/index.cjs +23 -69
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +5 -51
- package/dist/development/index.js.map +1 -1
- package/dist/production/index.cjs +2 -49
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.d.cts +3 -9
- package/dist/production/index.d.ts +3 -9
- package/dist/production/index.js +2 -7
- package/dist/production/index.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,54 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var reactRouter = require('react-router');
|
|
4
4
|
|
|
5
|
-
// src/
|
|
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 =
|
|
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, "
|
|
103
|
+
Object.defineProperty(exports, "createCookie", {
|
|
150
104
|
enumerable: true,
|
|
151
|
-
get: function () { return
|
|
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
|
|
117
|
+
get: function () { return reactRouter.createSession; }
|
|
156
118
|
});
|
|
157
|
-
Object.defineProperty(exports, "
|
|
119
|
+
Object.defineProperty(exports, "createSessionStorage", {
|
|
158
120
|
enumerable: true,
|
|
159
|
-
get: function () { return
|
|
121
|
+
get: function () { return reactRouter.createSessionStorage; }
|
|
160
122
|
});
|
|
161
|
-
Object.defineProperty(exports, "
|
|
123
|
+
Object.defineProperty(exports, "data", {
|
|
162
124
|
enumerable: true,
|
|
163
|
-
get: function () { return
|
|
125
|
+
get: function () { return reactRouter.data; }
|
|
164
126
|
});
|
|
165
127
|
Object.defineProperty(exports, "isCookie", {
|
|
166
128
|
enumerable: true,
|
|
167
|
-
get: function () { return
|
|
129
|
+
get: function () { return reactRouter.isCookie; }
|
|
168
130
|
});
|
|
169
131
|
Object.defineProperty(exports, "isSession", {
|
|
170
132
|
enumerable: true,
|
|
171
|
-
get: function () { return
|
|
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
|
|
137
|
+
get: function () { return reactRouter.redirect; }
|
|
180
138
|
});
|
|
181
139
|
Object.defineProperty(exports, "redirectDocument", {
|
|
182
140
|
enumerable: true,
|
|
183
|
-
get: function () { return
|
|
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
|
-
//# sourceMappingURL=
|
|
145
|
+
//# sourceMappingURL=index.cjs.map
|
|
192
146
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/implementations.ts","../../src/crypto.ts","../../src/server.ts","../../src/event-logger.ts","../../src/index.ts"],"names":["data"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACHP,IAAM,UAAU,IAAI,YAAY;AAEzB,IAAM,OAAqB,OAAO,OAAO,WAAW;AACzD,QAAM,MAAM,MAAM,UAAU,QAAQ,CAAC,MAAM,CAAC;AAC5C,QAAMA,QAAO,QAAQ,OAAO,KAAK;AACjC,QAAM,YAAY,MAAM,OAAO,OAAO,KAAK,QAAQ,KAAKA,KAAI;AAC5D,QAAM,OAAO,KAAK,OAAO,aAAa,GAAG,IAAI,WAAW,SAAS,CAAC,CAAC,EAAE;AAAA,IACnE;AAAA,IACA;AAAA,EACF;AAEA,SAAO,QAAQ,MAAM;AACvB;AAEO,IAAM,SAAyB,OAAO,QAAQ,WAAW;AAC9D,QAAM,QAAQ,OAAO,YAAY,GAAG;AACpC,QAAM,QAAQ,OAAO,MAAM,GAAG,KAAK;AACnC,QAAM,OAAO,OAAO,MAAM,QAAQ,CAAC;AAEnC,QAAM,MAAM,MAAM,UAAU,QAAQ,CAAC,QAAQ,CAAC;AAC9C,QAAMA,QAAO,QAAQ,OAAO,KAAK;AACjC,QAAM,YAAY,uBAAuB,KAAK,IAAI,CAAC;AACnD,QAAM,QAAQ,MAAM,OAAO,OAAO,OAAO,QAAQ,KAAK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AAA,UACZ,QAAQ,SAAS;AAAA,UACjB,YAAY,SAAS;AAAA,UACrB,SAAS,MAAM,KAAK,SAAS,QAAQ,QAAQ,CAAC;AAAA,QAChD;AAAA,MACF,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AACF;AASO,SAAS,qBAAqB,SAAqC;AACxE,QAAM,UAAU,QAAQ;AACxB,SAAO;AAAA,IACL,gBAAgB,QAAQ,IAAI,YAAY;AAAA,IACxC,SAAS,QAAQ,IAAI,iBAAiB;AAAA,IACtC,QAAQ,QAAQ,IAAI,QAAQ;AAAA,IAC5B,SAAS,QAAQ,IAAI,SAAS;AAAA,EAChC;AACF;;;AEhDA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK","sourcesContent":["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","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","/// <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","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","export {\n createCookie,\n createCookieSessionStorage,\n createMemorySessionStorage,\n createSessionStorage,\n} from './implementations';\nexport {createRequestHandler, getStorefrontHeaders} from './server';\nexport type {\n ActionFunction,\n ActionFunctionArgs,\n AppLoadContext,\n Cookie,\n CookieOptions,\n CookieParseOptions,\n CookieSerializeOptions,\n CookieSignatureOptions,\n DataFunctionArgs,\n EntryContext,\n ErrorResponse,\n HandleDataRequestFunction,\n HandleDocumentRequestFunction,\n HandleErrorFunction,\n HeadersArgs,\n HeadersFunction,\n HtmlLinkDescriptor,\n JsonFunction,\n LinkDescriptor,\n LinksFunction,\n LoaderFunction,\n LoaderFunctionArgs,\n MemoryUploadHandlerFilterArgs,\n MemoryUploadHandlerOptions,\n ServerRuntimeMetaArgs as MetaArgs,\n ServerRuntimeMetaDescriptor as MetaDescriptor,\n ServerRuntimeMetaFunction as MetaFunction,\n PageLinkDescriptor,\n RequestHandler,\n SerializeFrom,\n ServerBuild,\n ServerEntryModule,\n Session,\n SessionData,\n SessionIdStorageStrategy,\n SessionStorage,\n SignFunction,\n TypedDeferredData,\n TypedResponse,\n UnsignFunction,\n UploadHandler,\n UploadHandlerPart,\n} from '@remix-run/server-runtime';\nexport {\n createSession,\n data,\n defer,\n isCookie,\n isSession,\n json,\n MaxPartSizeExceededError,\n redirect,\n redirectDocument,\n} from '@remix-run/server-runtime';\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,E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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":["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 {
|
|
2
|
-
export {
|
|
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/
|
|
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 {
|
|
149
|
-
//# sourceMappingURL=
|
|
102
|
+
export { createRequestHandler, getStorefrontHeaders };
|
|
103
|
+
//# sourceMappingURL=index.js.map
|
|
150
104
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/implementations.ts","../../src/crypto.ts","../../src/server.ts","../../src/event-logger.ts","../../src/index.ts"],"names":["data"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACHP,IAAM,UAAU,IAAI,YAAY;AAEzB,IAAM,OAAqB,OAAO,OAAO,WAAW;AACzD,QAAM,MAAM,MAAM,UAAU,QAAQ,CAAC,MAAM,CAAC;AAC5C,QAAMA,QAAO,QAAQ,OAAO,KAAK;AACjC,QAAM,YAAY,MAAM,OAAO,OAAO,KAAK,QAAQ,KAAKA,KAAI;AAC5D,QAAM,OAAO,KAAK,OAAO,aAAa,GAAG,IAAI,WAAW,SAAS,CAAC,CAAC,EAAE;AAAA,IACnE;AAAA,IACA;AAAA,EACF;AAEA,SAAO,QAAQ,MAAM;AACvB;AAEO,IAAM,SAAyB,OAAO,QAAQ,WAAW;AAC9D,QAAM,QAAQ,OAAO,YAAY,GAAG;AACpC,QAAM,QAAQ,OAAO,MAAM,GAAG,KAAK;AACnC,QAAM,OAAO,OAAO,MAAM,QAA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D;AAEA,QAAI,MAAwC;AAC1C,iBAAW,kBAAkB;AAAA,QAC3B,WAAW;AAAA,QACX,KAAK,QAAQ;AAAA,QACb,WAAW,QAAQ,QAAQ,IAAI,YAAY;AAAA,QAC3C,SAAS,QAAQ,QAAQ,IAAI,SAAS;AAAA,QACtC;AAAA,QACA,cAAc;AAAA,UACZ,QAAQ,SAAS;AAAA,UACjB,YAAY,SAAS;AAAA,UACrB,SAAS,MAAM,KAAK,SAAS,QAAQ,QAAQ,CAAC;AAAA,QAChD;AAAA,MACF,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AACF;AASO,SAAS,qBAAqB,SAAqC;AACxE,QAAM,UAAU,QAAQ;AACxB,SAAO;AAAA,IACL,gBAAgB,QAAQ,IAAI,YAAY;AAAA,IACxC,SAAS,QAAQ,IAAI,iBAAiB;AAAA,IACtC,QAAQ,QAAQ,IAAI,QAAQ;AAAA,IAC5B,SAAS,QAAQ,IAAI,SAAS;AAAA,EAChC;AACF;;;AEhDA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK","sourcesContent":["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","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","/// <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","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","export {\n createCookie,\n createCookieSessionStorage,\n createMemorySessionStorage,\n createSessionStorage,\n} from './implementations';\nexport {createRequestHandler, getStorefrontHeaders} from './server';\nexport type {\n ActionFunction,\n ActionFunctionArgs,\n AppLoadContext,\n Cookie,\n CookieOptions,\n CookieParseOptions,\n CookieSerializeOptions,\n CookieSignatureOptions,\n DataFunctionArgs,\n EntryContext,\n ErrorResponse,\n HandleDataRequestFunction,\n HandleDocumentRequestFunction,\n HandleErrorFunction,\n HeadersArgs,\n HeadersFunction,\n HtmlLinkDescriptor,\n JsonFunction,\n LinkDescriptor,\n LinksFunction,\n LoaderFunction,\n LoaderFunctionArgs,\n MemoryUploadHandlerFilterArgs,\n MemoryUploadHandlerOptions,\n ServerRuntimeMetaArgs as MetaArgs,\n ServerRuntimeMetaDescriptor as MetaDescriptor,\n ServerRuntimeMetaFunction as MetaFunction,\n PageLinkDescriptor,\n RequestHandler,\n SerializeFrom,\n ServerBuild,\n ServerEntryModule,\n Session,\n SessionData,\n SessionIdStorageStrategy,\n SessionStorage,\n SignFunction,\n TypedDeferredData,\n TypedResponse,\n UnsignFunction,\n UploadHandler,\n UploadHandlerPart,\n} from '@remix-run/server-runtime';\nexport {\n createSession,\n data,\n defer,\n isCookie,\n isSession,\n json,\n MaxPartSizeExceededError,\n redirect,\n redirectDocument,\n} from '@remix-run/server-runtime';\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,EA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,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,50 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var serverRuntime = require('@remix-run/server-runtime');
|
|
4
|
-
|
|
5
|
-
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=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=!0,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")}}
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "MaxPartSizeExceededError", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () { return serverRuntime.MaxPartSizeExceededError; }
|
|
10
|
-
});
|
|
11
|
-
Object.defineProperty(exports, "createSession", {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function () { return serverRuntime.createSession; }
|
|
14
|
-
});
|
|
15
|
-
Object.defineProperty(exports, "data", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: function () { return serverRuntime.data; }
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(exports, "defer", {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
get: function () { return serverRuntime.defer; }
|
|
22
|
-
});
|
|
23
|
-
Object.defineProperty(exports, "isCookie", {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
get: function () { return serverRuntime.isCookie; }
|
|
26
|
-
});
|
|
27
|
-
Object.defineProperty(exports, "isSession", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
get: function () { return serverRuntime.isSession; }
|
|
30
|
-
});
|
|
31
|
-
Object.defineProperty(exports, "json", {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
get: function () { return serverRuntime.json; }
|
|
34
|
-
});
|
|
35
|
-
Object.defineProperty(exports, "redirect", {
|
|
36
|
-
enumerable: true,
|
|
37
|
-
get: function () { return serverRuntime.redirect; }
|
|
38
|
-
});
|
|
39
|
-
Object.defineProperty(exports, "redirectDocument", {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
get: function () { return serverRuntime.redirectDocument; }
|
|
42
|
-
});
|
|
43
|
-
exports.createCookie = u;
|
|
44
|
-
exports.createCookieSessionStorage = C;
|
|
45
|
-
exports.createMemorySessionStorage = k;
|
|
46
|
-
exports.createRequestHandler = E;
|
|
47
|
-
exports.createSessionStorage = S;
|
|
48
|
-
exports.getStorefrontHeaders = v;
|
|
49
|
-
//# sourceMappingURL=out.js.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
|
|
50
3
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/
|
|
1
|
+
{"version":3,"sources":["../../src/server.ts"],"names":["originalErrorToString","createRequestHandler","build","mode","poweredByHeader","getLoadContext","handleRequest","createReactRouterRequestHandler","request","method","url","context","response","getStorefr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ACxB,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
|
|
2
|
-
|
|
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 {
|
|
18
|
+
export { createRequestHandler, getStorefrontHeaders };
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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 {
|
|
18
|
+
export { createRequestHandler, getStorefrontHeaders };
|
package/dist/production/index.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
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),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=!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")}}
|
|
5
|
-
|
|
6
|
-
export { u as createCookie, C as createCookieSessionStorage, k as createMemorySessionStorage, E as createRequestHandler, S as createSessionStorage, v as getStorefrontHeaders };
|
|
7
|
-
//# sourceMappingURL=out.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
|
|
8
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/
|
|
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": "
|
|
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
|
-
"@
|
|
49
|
-
"
|
|
48
|
+
"@shopify/oxygen-workers-types": "^4.1.6",
|
|
49
|
+
"react-router": "7.6.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@
|
|
53
|
-
"
|
|
52
|
+
"@shopify/oxygen-workers-types": "^3.17.3 || ^4.1.2",
|
|
53
|
+
"react-router": "7.6.0"
|
|
54
54
|
}
|
|
55
55
|
}
|