next-csrf
Version:
CSRF mitigation library for Next.js
1 lines • 27.2 kB
JSON
{"ast":null,"code":"\"use strict\";\n\nvar _interopRequireDefault = require(\"@babel/runtime/helpers/interopRequireDefault\");\n\nvar _interopRequireWildcard = require(\"@babel/runtime/helpers/interopRequireWildcard\");\n\nexports.__esModule = true;\nexports[\"default\"] = connect;\n\nvar DevOverlay = _interopRequireWildcard(require(\"@next/react-dev-overlay/lib/client\"));\n\nvar _stripAnsi = _interopRequireDefault(require(\"next/dist/compiled/strip-ansi\"));\n\nvar _eventsource = require(\"./eventsource\");\n\nvar _formatWebpackMessages = _interopRequireDefault(require(\"./format-webpack-messages\"));\n/**\n* MIT License\n*\n* Copyright (c) 2013-present, Facebook, Inc.\n*\n* Permission is hereby granted, free of charge, to any person obtaining a copy\n* of this software and associated documentation files (the \"Software\"), to deal\n* in the Software without restriction, including without limitation the rights\n* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n* copies of the Software, and to permit persons to whom the Software is\n* furnished to do so, subject to the following conditions:\n*\n* The above copyright notice and this permission notice shall be included in all\n* copies or substantial portions of the Software.\n*\n* THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n* SOFTWARE.\n*/\n// This file is a modified version of the Create React App HMR dev client that\n// can be found here:\n// https://github.com/facebook/create-react-app/blob/v3.4.1/packages/react-dev-utils/webpackHotDevClient.js\n// This alternative WebpackDevServer combines the functionality of:\n// https://github.com/webpack/webpack-dev-server/blob/webpack-1/client/index.js\n// https://github.com/webpack/webpack/blob/webpack-1/hot/dev-server.js\n// It only supports their simplest configuration (hot updates on same server).\n// It makes some opinionated choices on top, like adding a syntax error overlay\n// that looks similar to our console output. The error overlay is inspired by:\n// https://github.com/glenjamin/webpack-hot-middleware\n\n\nvar hadRuntimeError = false;\nvar customHmrEventHandler;\n\nfunction connect(options) {\n DevOverlay.register();\n (0, _eventsource.getEventSourceWrapper)(options).addMessageListener(function (event) {\n // This is the heartbeat event\n if (event.data === \"\\uD83D\\uDC93\") {\n return;\n }\n\n try {\n processMessage(event);\n } catch (ex) {\n console.warn('Invalid HMR message: ' + event.data + '\\n' + ex);\n }\n });\n return {\n subscribeToHmrEvent: function subscribeToHmrEvent(handler) {\n customHmrEventHandler = handler;\n },\n onUnrecoverableError: function onUnrecoverableError() {\n hadRuntimeError = true;\n }\n };\n} // Remember some state related to hot module replacement.\n\n\nvar isFirstCompilation = true;\nvar mostRecentCompilationHash = null;\nvar hasCompileErrors = false;\n\nfunction clearOutdatedErrors() {\n // Clean up outdated compile errors, if any.\n if (typeof console !== 'undefined' && typeof console.clear === 'function') {\n if (hasCompileErrors) {\n console.clear();\n }\n }\n} // Successful compilation.\n\n\nfunction handleSuccess() {\n clearOutdatedErrors();\n var isHotUpdate = !isFirstCompilation;\n isFirstCompilation = false;\n hasCompileErrors = false; // Attempt to apply hot updates or reload.\n\n if (isHotUpdate) {\n tryApplyUpdates(function onSuccessfulHotUpdate(hasUpdates) {\n // Only dismiss it when we're sure it's a hot update.\n // Otherwise it would flicker right before the reload.\n onFastRefresh(hasUpdates);\n });\n }\n} // Compilation with warnings (e.g. ESLint).\n\n\nfunction handleWarnings(warnings) {\n clearOutdatedErrors();\n var isHotUpdate = !isFirstCompilation;\n isFirstCompilation = false;\n hasCompileErrors = false;\n\n function printWarnings() {\n // Print warnings to the console.\n var formatted = (0, _formatWebpackMessages[\"default\"])({\n warnings: warnings,\n errors: []\n });\n\n if (typeof console !== 'undefined' && typeof console.warn === 'function') {\n for (var i = 0; i < formatted.warnings.length; i++) {\n if (i === 5) {\n console.warn('There were more warnings in other files.\\n' + 'You can find a complete log in the terminal.');\n break;\n }\n\n console.warn((0, _stripAnsi[\"default\"])(formatted.warnings[i]));\n }\n }\n }\n\n printWarnings(); // Attempt to apply hot updates or reload.\n\n if (isHotUpdate) {\n tryApplyUpdates(function onSuccessfulHotUpdate(hasUpdates) {\n // Only dismiss it when we're sure it's a hot update.\n // Otherwise it would flicker right before the reload.\n onFastRefresh(hasUpdates);\n });\n }\n} // Compilation with errors (e.g. syntax error or missing modules).\n\n\nfunction handleErrors(errors) {\n clearOutdatedErrors();\n isFirstCompilation = false;\n hasCompileErrors = true; // \"Massage\" webpack messages.\n\n var formatted = (0, _formatWebpackMessages[\"default\"])({\n errors: errors,\n warnings: []\n }); // Only show the first error.\n\n DevOverlay.onBuildError(formatted.errors[0]); // Also log them to the console.\n\n if (typeof console !== 'undefined' && typeof console.error === 'function') {\n for (var i = 0; i < formatted.errors.length; i++) {\n console.error((0, _stripAnsi[\"default\"])(formatted.errors[i]));\n }\n } // Do not attempt to reload now.\n // We will reload on next success instead.\n\n\n if (process.env.__NEXT_TEST_MODE) {\n if (self.__NEXT_HMR_CB) {\n self.__NEXT_HMR_CB(formatted.errors[0]);\n\n self.__NEXT_HMR_CB = null;\n }\n }\n}\n\nfunction onFastRefresh(hasUpdates) {\n DevOverlay.onBuildOk();\n\n if (hasUpdates) {\n DevOverlay.onRefresh();\n }\n\n console.log('[Fast Refresh] done');\n} // There is a newer version of the code available.\n\n\nfunction handleAvailableHash(hash) {\n // Update last known compilation hash.\n mostRecentCompilationHash = hash;\n} // Handle messages from the server.\n\n\nfunction processMessage(e) {\n var obj = JSON.parse(e.data);\n\n switch (obj.action) {\n case 'building':\n {\n console.log('[Fast Refresh] rebuilding');\n break;\n }\n\n case 'built':\n case 'sync':\n {\n if (obj.hash) {\n handleAvailableHash(obj.hash);\n }\n\n var errors = obj.errors,\n warnings = obj.warnings;\n var hasErrors = Boolean(errors && errors.length);\n\n if (hasErrors) {\n return handleErrors(errors);\n }\n\n var hasWarnings = Boolean(warnings && warnings.length);\n\n if (hasWarnings) {\n return handleWarnings(warnings);\n }\n\n return handleSuccess();\n }\n\n default:\n {\n if (customHmrEventHandler) {\n customHmrEventHandler(obj);\n break;\n }\n\n break;\n }\n }\n} // Is there a newer version of this code available?\n\n\nfunction isUpdateAvailable() {\n /* globals __webpack_hash__ */\n // __webpack_hash__ is the hash of the current compilation.\n // It's a global variable injected by Webpack.\n return mostRecentCompilationHash !== __webpack_hash__;\n} // Webpack disallows updates in other states.\n\n\nfunction canApplyUpdates() {\n return module.hot.status() === 'idle';\n}\n\nfunction afterApplyUpdates(fn) {\n if (canApplyUpdates()) {\n fn();\n } else {\n var handler = function handler(status) {\n if (status === 'idle') {\n module.hot.removeStatusHandler(handler);\n fn();\n }\n };\n\n module.hot.addStatusHandler(handler);\n }\n} // Attempt to update code on the fly, fall back to a hard reload.\n\n\nfunction tryApplyUpdates(onHotUpdateSuccess) {\n if (!module.hot) {\n // HotModuleReplacementPlugin is not in Webpack configuration.\n console.error('HotModuleReplacementPlugin is not in Webpack configuration.'); // window.location.reload();\n\n return;\n }\n\n if (!isUpdateAvailable() || !canApplyUpdates()) {\n return;\n }\n\n function handleApplyUpdates(err, updatedModules) {\n if (err || hadRuntimeError || !updatedModules) {\n if (err) {\n console.warn('[Fast Refresh] performing full reload\\n\\n' + \"Fast Refresh will perform a full reload when you edit a file that's imported by modules outside of the React rendering tree.\\n\" + 'You might have a file which exports a React component but also exports a value that is imported by a non-React component file.\\n' + 'Consider migrating the non-React component export to a separate file and importing it into both files.\\n\\n' + 'It is also possible the parent component of the component you edited is a class component, which disables Fast Refresh.\\n' + 'Fast Refresh requires at least one parent function component in your React tree.');\n } else if (hadRuntimeError) {\n console.warn('[Fast Refresh] performing full reload because your application had an unrecoverable error');\n }\n\n window.location.reload();\n return;\n }\n\n var hasUpdates = Boolean(updatedModules.length);\n\n if (typeof onHotUpdateSuccess === 'function') {\n // Maybe we want to do something.\n onHotUpdateSuccess(hasUpdates);\n }\n\n if (isUpdateAvailable()) {\n // While we were updating, there was a new update! Do it again.\n tryApplyUpdates(hasUpdates ? undefined : onHotUpdateSuccess);\n } else {\n if (process.env.__NEXT_TEST_MODE) {\n afterApplyUpdates(function () {\n if (self.__NEXT_HMR_CB) {\n self.__NEXT_HMR_CB();\n\n self.__NEXT_HMR_CB = null;\n }\n });\n }\n }\n } // https://webpack.js.org/api/hot-module-replacement/#check\n\n\n module.hot.check(\n /* autoApply */\n true).then(function (updatedModules) {\n handleApplyUpdates(null, updatedModules);\n }, function (err) {\n handleApplyUpdates(err, null);\n });\n}","map":{"version":3,"sources":["../../../../client/dev/error-overlay/hot-dev-client.js"],"names":["hadRuntimeError","DevOverlay","event","processMessage","console","subscribeToHmrEvent","customHmrEventHandler","onUnrecoverableError","isFirstCompilation","mostRecentCompilationHash","hasCompileErrors","clearOutdatedErrors","isHotUpdate","tryApplyUpdates","onFastRefresh","formatted","warnings","errors","i","printWarnings","process","self","obj","JSON","e","handleAvailableHash","hasErrors","Boolean","handleErrors","hasWarnings","handleWarnings","handleSuccess","module","canApplyUpdates","fn","status","isUpdateAvailable","err","window","hasUpdates","updatedModules","onHotUpdateSuccess","afterApplyUpdates","handleApplyUpdates"],"mappings":";;;;;;;;;AA4BA,IAAA,UAAA,GAAA,uBAAA,CAAA,OAAA,CAAA,oCAAA,CAAA,CAAA;;AACA,IAAA,UAAA,GAAA,sBAAA,CAAA,OAAA,CAAA,+BAAA,CAAA,CAAA;;AACA,IAAA,YAAA,GAAA,OAAA,CAAA,eAAA,CAAA;;AACA,IAAA,sBAAA,GAAA,sBAAA,CAAA,OAAA,CAAA,2BAAA,CAAA,CAAA;AA/BA;;;;;;;;;;;;;;;;;;;;;;;AAwBA;AACA;AACA;AAOA;AACA;AACA;AAEA;AACA;AACA;AACA;;;AAEA,IAAIA,eAAe,GAAnB,KAAA;AACA,IA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,QAAAA,iBAAiB,CAAC,YAAM;AACtB,cAAIrB,IAAI,CAAR,aAAA,EAAwB;AACtBA,YAAAA,IAAI,CAAJA,aAAAA;;AACAA,YAAAA,IAAI,CAAJA,aAAAA,GAAAA,IAAAA;AAEH;AALDqB,SAAiB,CAAjBA;AAOH;AACF;AAED,GArD2C,CAqD3C;;;AACAV,EAAAA,MAAM,CAANA,GAAAA,CAAAA,KAAAA;AAAiB;AAAjBA,MAAAA,EAAAA,IAAAA,CACGQ,UAAAA,cAAD,EAAoB;AAClBG,IAAAA,kBAAkB,CAAA,IAAA,EAAlBA,cAAkB,CAAlBA;AAFJX,GAAAA,EAIGK,UAAAA,GAAD,EAAS;AACPM,IAAAA,kBAAkB,CAAA,GAAA,EAAlBA,IAAkB,CAAlBA;AALJX,GAAAA;AAQD","sourcesContent":["/**\n * MIT License\n *\n * Copyright (c) 2013-present, Facebook, Inc.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n// This file is a modified version of the Create React App HMR dev client that\n// can be found here:\n// https://github.com/facebook/create-react-app/blob/v3.4.1/packages/react-dev-utils/webpackHotDevClient.js\n\nimport * as DevOverlay from '@next/react-dev-overlay/lib/client'\nimport stripAnsi from 'next/dist/compiled/strip-ansi'\nimport { getEventSourceWrapper } from './eventsource'\nimport formatWebpackMessages from './format-webpack-messages'\n\n// This alternative WebpackDevServer combines the functionality of:\n// https://github.com/webpack/webpack-dev-server/blob/webpack-1/client/index.js\n// https://github.com/webpack/webpack/blob/webpack-1/hot/dev-server.js\n\n// It only supports their simplest configuration (hot updates on same server).\n// It makes some opinionated choices on top, like adding a syntax error overlay\n// that looks similar to our console output. The error overlay is inspired by:\n// https://github.com/glenjamin/webpack-hot-middleware\n\nlet hadRuntimeError = false\nlet customHmrEventHandler\nexport default function connect(options) {\n DevOverlay.register()\n\n getEventSourceWrapper(options).addMessageListener((event) => {\n // This is the heartbeat event\n if (event.data === '\\uD83D\\uDC93') {\n return\n }\n try {\n processMessage(event)\n } catch (ex) {\n console.warn('Invalid HMR message: ' + event.data + '\\n' + ex)\n }\n })\n\n return {\n subscribeToHmrEvent(handler) {\n customHmrEventHandler = handler\n },\n onUnrecoverableError() {\n hadRuntimeError = true\n },\n }\n}\n\n// Remember some state related to hot module replacement.\nvar isFirstCompilation = true\nvar mostRecentCompilationHash = null\nvar hasCompileErrors = false\n\nfunction clearOutdatedErrors() {\n // Clean up outdated compile errors, if any.\n if (typeof console !== 'undefined' && typeof console.clear === 'function') {\n if (hasCompileErrors) {\n console.clear()\n }\n }\n}\n\n// Successful compilation.\nfunction handleSuccess() {\n clearOutdatedErrors()\n\n const isHotUpdate = !isFirstCompilation\n isFirstCompilation = false\n hasCompileErrors = false\n\n // Attempt to apply hot updates or reload.\n if (isHotUpdate) {\n tryApplyUpdates(function onSuccessfulHotUpdate(hasUpdates) {\n // Only dismiss it when we're sure it's a hot update.\n // Otherwise it would flicker right before the reload.\n onFastRefresh(hasUpdates)\n })\n }\n}\n\n// Compilation with warnings (e.g. ESLint).\nfunction handleWarnings(warnings) {\n clearOutdatedErrors()\n\n const isHotUpdate = !isFirstCompilation\n isFirstCompilation = false\n hasCompileErrors = false\n\n function printWarnings() {\n // Print warnings to the console.\n const formatted = formatWebpackMessages({\n warnings: warnings,\n errors: [],\n })\n\n if (typeof console !== 'undefined' && typeof console.warn === 'function') {\n for (let i = 0; i < formatted.warnings.length; i++) {\n if (i === 5) {\n console.warn(\n 'There were more warnings in other files.\\n' +\n 'You can find a complete log in the terminal.'\n )\n break\n }\n console.warn(stripAnsi(formatted.warnings[i]))\n }\n }\n }\n\n printWarnings()\n\n // Attempt to apply hot updates or reload.\n if (isHotUpdate) {\n tryApplyUpdates(function onSuccessfulHotUpdate(hasUpdates) {\n // Only dismiss it when we're sure it's a hot update.\n // Otherwise it would flicker right before the reload.\n onFastRefresh(hasUpdates)\n })\n }\n}\n\n// Compilation with errors (e.g. syntax error or missing modules).\nfunction handleErrors(errors) {\n clearOutdatedErrors()\n\n isFirstCompilation = false\n hasCompileErrors = true\n\n // \"Massage\" webpack messages.\n var formatted = formatWebpackMessages({\n errors: errors,\n warnings: [],\n })\n\n // Only show the first error.\n DevOverlay.onBuildError(formatted.errors[0])\n\n // Also log them to the console.\n if (typeof console !== 'undefined' && typeof console.error === 'function') {\n for (var i = 0; i < formatted.errors.length; i++) {\n console.error(stripAnsi(formatted.errors[i]))\n }\n }\n\n // Do not attempt to reload now.\n // We will reload on next success instead.\n if (process.env.__NEXT_TEST_MODE) {\n if (self.__NEXT_HMR_CB) {\n self.__NEXT_HMR_CB(formatted.errors[0])\n self.__NEXT_HMR_CB = null\n }\n }\n}\n\nfunction onFastRefresh(hasUpdates) {\n DevOverlay.onBuildOk()\n if (hasUpdates) {\n DevOverlay.onRefresh()\n }\n\n console.log('[Fast Refresh] done')\n}\n\n// There is a newer version of the code available.\nfunction handleAvailableHash(hash) {\n // Update last known compilation hash.\n mostRecentCompilationHash = hash\n}\n\n// Handle messages from the server.\nfunction processMessage(e) {\n const obj = JSON.parse(e.data)\n switch (obj.action) {\n case 'building': {\n console.log('[Fast Refresh] rebuilding')\n break\n }\n case 'built':\n case 'sync': {\n if (obj.hash) {\n handleAvailableHash(obj.hash)\n }\n\n const { errors, warnings } = obj\n const hasErrors = Boolean(errors && errors.length)\n if (hasErrors) {\n return handleErrors(errors)\n }\n\n const hasWarnings = Boolean(warnings && warnings.length)\n if (hasWarnings) {\n return handleWarnings(warnings)\n }\n\n return handleSuccess()\n }\n default: {\n if (customHmrEventHandler) {\n customHmrEventHandler(obj)\n break\n }\n break\n }\n }\n}\n\n// Is there a newer version of this code available?\nfunction isUpdateAvailable() {\n /* globals __webpack_hash__ */\n // __webpack_hash__ is the hash of the current compilation.\n // It's a global variable injected by Webpack.\n return mostRecentCompilationHash !== __webpack_hash__\n}\n\n// Webpack disallows updates in other states.\nfunction canApplyUpdates() {\n return module.hot.status() === 'idle'\n}\nfunction afterApplyUpdates(fn) {\n if (canApplyUpdates()) {\n fn()\n } else {\n function handler(status) {\n if (status === 'idle') {\n module.hot.removeStatusHandler(handler)\n fn()\n }\n }\n module.hot.addStatusHandler(handler)\n }\n}\n\n// Attempt to update code on the fly, fall back to a hard reload.\nfunction tryApplyUpdates(onHotUpdateSuccess) {\n if (!module.hot) {\n // HotModuleReplacementPlugin is not in Webpack configuration.\n console.error('HotModuleReplacementPlugin is not in Webpack configuration.')\n // window.location.reload();\n return\n }\n\n if (!isUpdateAvailable() || !canApplyUpdates()) {\n return\n }\n\n function handleApplyUpdates(err, updatedModules) {\n if (err || hadRuntimeError || !updatedModules) {\n if (err) {\n console.warn(\n '[Fast Refresh] performing full reload\\n\\n' +\n \"Fast Refresh will perform a full reload when you edit a file that's imported by modules outside of the React rendering tree.\\n\" +\n 'You might have a file which exports a React component but also exports a value that is imported by a non-React component file.\\n' +\n 'Consider migrating the non-React component export to a separate file and importing it into both files.\\n\\n' +\n 'It is also possible the parent component of the component you edited is a class component, which disables Fast Refresh.\\n' +\n 'Fast Refresh requires at least one parent function component in your React tree.'\n )\n } else if (hadRuntimeError) {\n console.warn(\n '[Fast Refresh] performing full reload because your application had an unrecoverable error'\n )\n }\n window.location.reload()\n return\n }\n\n const hasUpdates = Boolean(updatedModules.length)\n if (typeof onHotUpdateSuccess === 'function') {\n // Maybe we want to do something.\n onHotUpdateSuccess(hasUpdates)\n }\n\n if (isUpdateAvailable()) {\n // While we were updating, there was a new update! Do it again.\n tryApplyUpdates(hasUpdates ? undefined : onHotUpdateSuccess)\n } else {\n if (process.env.__NEXT_TEST_MODE) {\n afterApplyUpdates(() => {\n if (self.__NEXT_HMR_CB) {\n self.__NEXT_HMR_CB()\n self.__NEXT_HMR_CB = null\n }\n })\n }\n }\n }\n\n // https://webpack.js.org/api/hot-module-replacement/#check\n module.hot.check(/* autoApply */ true).then(\n (updatedModules) => {\n handleApplyUpdates(null, updatedModules)\n },\n (err) => {\n handleApplyUpdates(err, null)\n }\n )\n}\n"]},"metadata":{},"sourceType":"script"}