Next.js website for Rocky Mountain Vending company featuring: - Product catalog with Stripe integration - Service areas and parts pages - Admin dashboard with Clerk authentication - SEO optimized pages with JSON-LD structured data Co-authored-by: Cursor <cursoragent@cursor.com>
1 line
No EOL
16 KiB
Text
1 line
No EOL
16 KiB
Text
{"version":3,"sources":["../../../src/server/app-render/encryption.ts"],"sourcesContent":["/* eslint-disable import/no-extraneous-dependencies */\nimport 'server-only'\n\n/* eslint-disable import/no-extraneous-dependencies */\nimport { renderToReadableStream } from 'react-server-dom-webpack/server'\n/* eslint-disable import/no-extraneous-dependencies */\nimport { createFromReadableStream } from 'react-server-dom-webpack/client'\n\nimport { streamToString } from '../stream-utils/node-web-streams-helper'\nimport {\n arrayBufferToString,\n decrypt,\n encrypt,\n getActionEncryptionKey,\n getClientReferenceManifestForRsc,\n getServerModuleMap,\n stringToUint8Array,\n} from './encryption-utils'\nimport {\n getCacheSignal,\n getPrerenderResumeDataCache,\n getRenderResumeDataCache,\n workUnitAsyncStorage,\n} from './work-unit-async-storage.external'\nimport { createHangingInputAbortSignal } from './dynamic-rendering'\nimport React from 'react'\n\nconst isEdgeRuntime = process.env.NEXT_RUNTIME === 'edge'\n\nconst textEncoder = new TextEncoder()\nconst textDecoder = new TextDecoder()\n\nconst filterStackFrame =\n process.env.NODE_ENV !== 'production'\n ? (require('../lib/source-maps') as typeof import('../lib/source-maps'))\n .filterStackFrameDEV\n : undefined\nconst findSourceMapURL =\n process.env.NODE_ENV !== 'production'\n ? (require('../lib/source-maps') as typeof import('../lib/source-maps'))\n .findSourceMapURLDEV\n : undefined\n\n/**\n * Decrypt the serialized string with the action id as the salt.\n */\nasync function decodeActionBoundArg(actionId: string, arg: string) {\n const key = await getActionEncryptionKey()\n if (typeof key === 'undefined') {\n throw new Error(\n `Missing encryption key for Server Action. This is a bug in Next.js`\n )\n }\n\n // Get the iv (16 bytes) and the payload from the arg.\n const originalPayload = atob(arg)\n const ivValue = originalPayload.slice(0, 16)\n const payload = originalPayload.slice(16)\n\n const decrypted = textDecoder.decode(\n await decrypt(key, stringToUint8Array(ivValue), stringToUint8Array(payload))\n )\n\n if (!decrypted.startsWith(actionId)) {\n throw new Error('Invalid Server Action payload: failed to decrypt.')\n }\n\n return decrypted.slice(actionId.length)\n}\n\n/**\n * Encrypt the serialized string with the action id as the salt. Add a prefix to\n * later ensure that the payload is correctly decrypted, similar to a checksum.\n */\nasync function encodeActionBoundArg(actionId: string, arg: string) {\n const key = await getActionEncryptionKey()\n if (key === undefined) {\n throw new Error(\n `Missing encryption key for Server Action. This is a bug in Next.js`\n )\n }\n\n // Get 16 random bytes as iv.\n const randomBytes = new Uint8Array(16)\n workUnitAsyncStorage.exit(() => crypto.getRandomValues(randomBytes))\n const ivValue = arrayBufferToString(randomBytes.buffer)\n\n const encrypted = await encrypt(\n key,\n randomBytes,\n textEncoder.encode(actionId + arg)\n )\n\n return btoa(ivValue + arrayBufferToString(encrypted))\n}\n\nenum ReadStatus {\n Ready,\n Pending,\n Complete,\n}\n\n// Encrypts the action's bound args into a string. For the same combination of\n// actionId and args the same cached promise is returned. This ensures reference\n// equality for returned objects from \"use cache\" functions when they're invoked\n// multiple times within one render pass using the same bound args.\nexport const encryptActionBoundArgs = React.cache(\n async function encryptActionBoundArgs(actionId: string, ...args: any[]) {\n const workUnitStore = workUnitAsyncStorage.getStore()\n const cacheSignal = workUnitStore\n ? getCacheSignal(workUnitStore)\n : undefined\n\n const { clientModules } = getClientReferenceManifestForRsc()\n\n // Create an error before any asynchronous calls, to capture the original\n // call stack in case we need it when the serialization errors.\n const error = new Error()\n Error.captureStackTrace(error, encryptActionBoundArgs)\n\n let didCatchError = false\n\n const hangingInputAbortSignal = workUnitStore\n ? createHangingInputAbortSignal(workUnitStore)\n : undefined\n\n let readStatus = ReadStatus.Ready\n function startReadOnce() {\n if (readStatus === ReadStatus.Ready) {\n readStatus = ReadStatus.Pending\n cacheSignal?.beginRead()\n }\n }\n\n function endReadIfStarted() {\n if (readStatus === ReadStatus.Pending) {\n cacheSignal?.endRead()\n }\n readStatus = ReadStatus.Complete\n }\n\n // streamToString might take longer than a microtask to resolve and then other things\n // waiting on the cache signal might not realize there is another cache to fill so if\n // we are no longer waiting on the bound args serialization via the hangingInputAbortSignal\n // we should eagerly start the cache read to prevent other readers of the cache signal from\n // missing this cache fill. We use a idempotent function to only start reading once because\n // it's also possible that streamToString finishes before the hangingInputAbortSignal aborts.\n if (hangingInputAbortSignal && cacheSignal) {\n hangingInputAbortSignal.addEventListener('abort', startReadOnce, {\n once: true,\n })\n }\n\n // Using Flight to serialize the args into a string.\n const serialized = await streamToString(\n renderToReadableStream(args, clientModules, {\n filterStackFrame,\n signal: hangingInputAbortSignal,\n onError(err) {\n if (hangingInputAbortSignal?.aborted) {\n return\n }\n\n // We're only reporting one error at a time, starting with the first.\n if (didCatchError) {\n return\n }\n\n didCatchError = true\n\n // Use the original error message together with the previously created\n // stack, because err.stack is a useless Flight Server call stack.\n error.message = err instanceof Error ? err.message : String(err)\n },\n }),\n // We pass the abort signal to `streamToString` so that no chunks are\n // included that are emitted after the signal was already aborted. This\n // ensures that we can encode hanging promises.\n hangingInputAbortSignal\n )\n\n if (didCatchError) {\n if (process.env.NODE_ENV === 'development') {\n // Logging the error is needed for server functions that are passed to the\n // client where the decryption is not done during rendering. Console\n // replaying allows us to still show the error dev overlay in this case.\n console.error(error)\n }\n\n endReadIfStarted()\n throw error\n }\n\n if (!workUnitStore) {\n // We don't need to call cacheSignal.endRead here because we can't have a cacheSignal\n // if we do not have a workUnitStore.\n return encodeActionBoundArg(actionId, serialized)\n }\n\n startReadOnce()\n\n const prerenderResumeDataCache = getPrerenderResumeDataCache(workUnitStore)\n const renderResumeDataCache = getRenderResumeDataCache(workUnitStore)\n const cacheKey = actionId + serialized\n\n const cachedEncrypted =\n prerenderResumeDataCache?.encryptedBoundArgs.get(cacheKey) ??\n renderResumeDataCache?.encryptedBoundArgs.get(cacheKey)\n\n if (cachedEncrypted) {\n return cachedEncrypted\n }\n\n const encrypted = await encodeActionBoundArg(actionId, serialized)\n\n endReadIfStarted()\n prerenderResumeDataCache?.encryptedBoundArgs.set(cacheKey, encrypted)\n\n return encrypted\n }\n)\n\n// Decrypts the action's bound args from the encrypted string.\nexport async function decryptActionBoundArgs(\n actionId: string,\n encryptedPromise: Promise<string>\n) {\n const encrypted = await encryptedPromise\n const workUnitStore = workUnitAsyncStorage.getStore()\n\n let decrypted: string | undefined\n\n if (workUnitStore) {\n const cacheSignal = getCacheSignal(workUnitStore)\n const prerenderResumeDataCache = getPrerenderResumeDataCache(workUnitStore)\n const renderResumeDataCache = getRenderResumeDataCache(workUnitStore)\n\n decrypted =\n prerenderResumeDataCache?.decryptedBoundArgs.get(encrypted) ??\n renderResumeDataCache?.decryptedBoundArgs.get(encrypted)\n\n if (!decrypted) {\n cacheSignal?.beginRead()\n decrypted = await decodeActionBoundArg(actionId, encrypted)\n cacheSignal?.endRead()\n prerenderResumeDataCache?.decryptedBoundArgs.set(encrypted, decrypted)\n }\n } else {\n decrypted = await decodeActionBoundArg(actionId, encrypted)\n }\n\n const { edgeRscModuleMapping, rscModuleMapping } =\n getClientReferenceManifestForRsc()\n\n // Using Flight to deserialize the args from the string.\n const deserialized = await createFromReadableStream(\n new ReadableStream({\n start(controller) {\n controller.enqueue(textEncoder.encode(decrypted))\n\n switch (workUnitStore?.type) {\n case 'prerender':\n case 'prerender-runtime':\n // Explicitly don't close the stream here (until prerendering is\n // complete) so that hanging promises are not rejected.\n if (workUnitStore.renderSignal.aborted) {\n controller.close()\n } else {\n workUnitStore.renderSignal.addEventListener(\n 'abort',\n () => controller.close(),\n { once: true }\n )\n }\n break\n case 'prerender-client':\n case 'prerender-ppr':\n case 'prerender-legacy':\n case 'request':\n case 'cache':\n case 'private-cache':\n case 'unstable-cache':\n case undefined:\n return controller.close()\n default:\n workUnitStore satisfies never\n }\n },\n }),\n {\n findSourceMapURL,\n serverConsumerManifest: {\n // moduleLoading must be null because we don't want to trigger preloads of ClientReferences\n // to be added to the current execution. Instead, we'll wait for any ClientReference\n // to be emitted which themselves will handle the preloading.\n moduleLoading: null,\n moduleMap: isEdgeRuntime ? edgeRscModuleMapping : rscModuleMapping,\n serverModuleMap: getServerModuleMap(),\n },\n }\n )\n\n return deserialized\n}\n"],"names":["decryptActionBoundArgs","encryptActionBoundArgs","isEdgeRuntime","process","env","NEXT_RUNTIME","textEncoder","TextEncoder","textDecoder","TextDecoder","filterStackFrame","NODE_ENV","require","filterStackFrameDEV","undefined","findSourceMapURL","findSourceMapURLDEV","decodeActionBoundArg","actionId","arg","key","getActionEncryptionKey","Error","originalPayload","atob","ivValue","slice","payload","decrypted","decode","decrypt","stringToUint8Array","startsWith","length","encodeActionBoundArg","randomBytes","Uint8Array","workUnitAsyncStorage","exit","crypto","getRandomValues","arrayBufferToString","buffer","encrypted","encrypt","encode","btoa","ReadStatus","React","cache","args","workUnitStore","getStore","cacheSignal","getCacheSignal","clientModules","getClientReferenceManifestForRsc","error","captureStackTrace","didCatchError","hangingInputAbortSignal","createHangingInputAbortSignal","readStatus","startReadOnce","beginRead","endReadIfStarted","endRead","addEventListener","once","serialized","streamToString","renderToReadableStream","signal","onError","err","aborted","message","String","console","prerenderResumeDataCache","getPrerenderResumeDataCache","renderResumeDataCache","getRenderResumeDataCache","cacheKey","cachedEncrypted","encryptedBoundArgs","get","set","encryptedPromise","decryptedBoundArgs","edgeRscModuleMapping","rscModuleMapping","deserialized","createFromReadableStream","ReadableStream","start","controller","enqueue","type","renderSignal","close","serverConsumerManifest","moduleLoading","moduleMap","serverModuleMap","getServerModuleMap"],"mappings":"AAAA,oDAAoD;;;;;;;;;;;;;;;IA+N9BA,sBAAsB;eAAtBA;;IArHTC,sBAAsB;eAAtBA;;;QAzGN;wBAGgC;wBAEE;sCAEV;iCASxB;8CAMA;kCACuC;8DAC5B;;;;;;AAElB,MAAMC,gBAAgBC,QAAQC,GAAG,CAACC,YAAY,KAAK;AAEnD,MAAMC,cAAc,IAAIC;AACxB,MAAMC,cAAc,IAAIC;AA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