UNPKG

next-csrf

Version:

CSRF mitigation library for Next.js

1 lines 10.1 kB
{"ast":null,"code":"\"use strict\";\n\nvar _interopRequireDefault = require(\"@babel/runtime/helpers/interopRequireDefault\");\n\nexports.__esModule = true;\nexports.Container = Container;\nexports.createUrl = createUrl;\nexports.default = void 0;\n\nvar _react = _interopRequireDefault(require(\"react\"));\n\nvar _utils = require(\"../next-server/lib/utils\");\n\nexports.AppInitialProps = _utils.AppInitialProps;\nexports.NextWebVitalsMetric = _utils.NextWebVitalsMetric;\n/**\n* `App` component is used for initialize of pages. It allows for overwriting and full control of the `page` initialization.\n* This allows for keeping state between navigation, custom error handling, injecting additional data.\n*/\n\nasync function appGetInitialProps({\n Component,\n ctx\n}) {\n const pageProps = await (0, _utils.loadGetInitialProps)(Component, ctx);\n return {\n pageProps\n };\n}\n\nclass App extends _react.default.Component {\n // Kept here for backwards compatibility.\n // When someone ended App they could call `super.componentDidCatch`.\n // @deprecated This method is no longer needed. Errors are caught at the top level\n componentDidCatch(error, _errorInfo) {\n throw error;\n }\n\n render() {\n const {\n router,\n Component,\n pageProps,\n __N_SSG,\n __N_SSP\n } = this.props;\n return /*#__PURE__*/_react.default.createElement(Component, Object.assign({}, pageProps, // we don't add the legacy URL prop if it's using non-legacy\n // methods like getStaticProps and getServerSideProps\n !(__N_SSG || __N_SSP) ? {\n url: createUrl(router)\n } : {}));\n }\n\n}\n\nexports.default = App;\nApp.origGetInitialProps = appGetInitialProps;\nApp.getInitialProps = appGetInitialProps;\nlet warnContainer;\nlet warnUrl;\n\nif (true) {\n warnContainer = (0, _utils.execOnce)(() => {\n console.warn(`Warning: the \\`Container\\` in \\`_app\\` has been deprecated and should be removed. https://err.sh/vercel/next.js/app-container-deprecated`);\n });\n warnUrl = (0, _utils.execOnce)(() => {\n console.error(`Warning: the 'url' property is deprecated. https://err.sh/vercel/next.js/url-deprecated`);\n });\n} // @deprecated noop for now until removal\n\n\nfunction Container(p) {\n if (true) warnContainer();\n return p.children;\n}\n\nfunction createUrl(router) {\n // This is to make sure we don't references the router object at call time\n const {\n pathname,\n asPath,\n query\n } = router;\n return {\n get query() {\n if (true) warnUrl();\n return query;\n },\n\n get pathname() {\n if (true) warnUrl();\n return pathname;\n },\n\n get asPath() {\n if (true) warnUrl();\n return asPath;\n },\n\n back: () => {\n if (true) warnUrl();\n router.back();\n },\n push: (url, as) => {\n if (true) warnUrl();\n return router.push(url, as);\n },\n pushTo: (href, as) => {\n if (true) warnUrl();\n const pushRoute = as ? href : '';\n const pushUrl = as || href;\n return router.push(pushRoute, pushUrl);\n },\n replace: (url, as) => {\n if (true) warnUrl();\n return router.replace(url, as);\n },\n replaceTo: (href, as) => {\n if (true) warnUrl();\n const replaceRoute = as ? href : '';\n const replaceUrl = as || href;\n return router.replace(replaceRoute, replaceUrl);\n }\n };\n}","map":{"version":3,"sources":["../../pages/_app.tsx"],"names":["pageProps","App","React","Component","origGetInitialProps","appGetInitialProps","getInitialProps","componentDidCatch","render","__N_SSG","url","createUrl","warnContainer","console","warnUrl","p","back","router","push","pushTo","pushRoute","as","pushUrl","replace","replaceTo","replaceRoute","replaceUrl"],"mappings":";;;;;;;;;AAAA,IAAA,MAAA,GAAA,sBAAA,CAAA,OAAA,CAAA,OAAA,CAAA,CAAA;;AACA,IAAA,MAAA,GAAA,OAAA,CAAA,0BAAA,CAAA;;;;AAkBA;;;;;AAIA,eAAA,kBAAA,CAAkC;AAAA,EAAA,SAAA;AAAlC,EAAA;AAAkC,CAAlC,EAGyC;AACvC,QAAMA,SAAS,GAAG,MAAM,CAAA,GAAA,MAAA,CAAA,mBAAA,EAAA,SAAA,EAAxB,GAAwB,CAAxB;AACA,SAAO;AAAP,IAAA;AAAO,GAAP;AAGa;;AAAA,MAAA,GAAA,SAA2CE,MAAAA,CAAAA,OAAAA,CAAMC,SAAjD,CAGb;AAIA;AACA;AACA;AACAI,EAAAA,iBAAiB,CAAA,KAAA,EAAA,UAAA,EAA4C;AAC3D,UAAA,KAAA;AAGFC;;AAAAA,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AA2CA,OAAO;AAClD,aAAA,MAAA;AAXG,KAAA;;AAaLE,IAAAA,IAAI,EAAE,MAAM;AACV,gBAA2CF,OAAO;AAClDG,MAAAA,MAAM,CAANA,IAAAA;AAfG,KAAA;AAiBLC,IAAAA,IAAI,EAAE,CAAA,GAAA,EAAA,EAAA,KAA8B;AAClC,gBAA2CJ,OAAO;AAClD,aAAOG,MAAM,CAANA,IAAAA,CAAAA,GAAAA,EAAP,EAAOA,CAAP;AAnBG,KAAA;AAqBLE,IAAAA,MAAM,EAAE,CAAA,IAAA,EAAA,EAAA,KAA+B;AACrC,gBAA2CL,OAAO;AAClD,YAAMM,SAAS,GAAGC,EAAE,GAAA,IAAA,GAApB,EAAA;AACA,YAAMC,OAAO,GAAGD,EAAE,IAAlB,IAAA;AAEA,aAAOJ,MAAM,CAANA,IAAAA,CAAAA,SAAAA,EAAP,OAAOA,CAAP;AA1BG,KAAA;AA4BLM,IAAAA,OAAO,EAAE,CAAA,GAAA,EAAA,EAAA,KAA8B;AACrC,gBAA2CT,OAAO;AAClD,aAAOG,MAAM,CAANA,OAAAA,CAAAA,GAAAA,EAAP,EAAOA,CAAP;AA9BG,KAAA;AAgCLO,IAAAA,SAAS,EAAE,CAAA,IAAA,EAAA,EAAA,KAA+B;AACxC,gBAA2CV,OAAO;AAClD,YAAMW,YAAY,GAAGJ,EAAE,GAAA,IAAA,GAAvB,EAAA;AACA,YAAMK,UAAU,GAAGL,EAAE,IAArB,IAAA;AAEA,aAAOJ,MAAM,CAANA,OAAAA,CAAAA,YAAAA,EAAP,UAAOA,CAAP;AArCJ;AAAO,GAAP;AAwCD","sourcesContent":["import React, { ErrorInfo } from 'react'\nimport {\n execOnce,\n loadGetInitialProps,\n AppContextType,\n AppInitialProps,\n AppPropsType,\n NextWebVitalsMetric,\n} from '../next-server/lib/utils'\nimport { Router } from '../client/router'\n\nexport { AppInitialProps }\n\nexport { NextWebVitalsMetric }\n\nexport type AppContext = AppContextType<Router>\n\nexport type AppProps<P = {}> = AppPropsType<Router, P>\n\n/**\n * `App` component is used for initialize of pages. It allows for overwriting and full control of the `page` initialization.\n * This allows for keeping state between navigation, custom error handling, injecting additional data.\n */\nasync function appGetInitialProps({\n Component,\n ctx,\n}: AppContext): Promise<AppInitialProps> {\n const pageProps = await loadGetInitialProps(Component, ctx)\n return { pageProps }\n}\n\nexport default class App<P = {}, CP = {}, S = {}> extends React.Component<\n P & AppProps<CP>,\n S\n> {\n static origGetInitialProps = appGetInitialProps\n static getInitialProps = appGetInitialProps\n\n // Kept here for backwards compatibility.\n // When someone ended App they could call `super.componentDidCatch`.\n // @deprecated This method is no longer needed. Errors are caught at the top level\n componentDidCatch(error: Error, _errorInfo: ErrorInfo): void {\n throw error\n }\n\n render() {\n const { router, Component, pageProps, __N_SSG, __N_SSP } = this\n .props as AppProps<CP>\n\n return (\n <Component\n {...pageProps}\n {\n // we don't add the legacy URL prop if it's using non-legacy\n // methods like getStaticProps and getServerSideProps\n ...(!(__N_SSG || __N_SSP) ? { url: createUrl(router) } : {})\n }\n />\n )\n }\n}\n\nlet warnContainer: () => void\nlet warnUrl: () => void\n\nif (process.env.NODE_ENV !== 'production') {\n warnContainer = execOnce(() => {\n console.warn(\n `Warning: the \\`Container\\` in \\`_app\\` has been deprecated and should be removed. https://err.sh/vercel/next.js/app-container-deprecated`\n )\n })\n\n warnUrl = execOnce(() => {\n console.error(\n `Warning: the 'url' property is deprecated. https://err.sh/vercel/next.js/url-deprecated`\n )\n })\n}\n\n// @deprecated noop for now until removal\nexport function Container(p: any) {\n if (process.env.NODE_ENV !== 'production') warnContainer()\n return p.children\n}\n\nexport function createUrl(router: Router) {\n // This is to make sure we don't references the router object at call time\n const { pathname, asPath, query } = router\n return {\n get query() {\n if (process.env.NODE_ENV !== 'production') warnUrl()\n return query\n },\n get pathname() {\n if (process.env.NODE_ENV !== 'production') warnUrl()\n return pathname\n },\n get asPath() {\n if (process.env.NODE_ENV !== 'production') warnUrl()\n return asPath\n },\n back: () => {\n if (process.env.NODE_ENV !== 'production') warnUrl()\n router.back()\n },\n push: (url: string, as?: string) => {\n if (process.env.NODE_ENV !== 'production') warnUrl()\n return router.push(url, as)\n },\n pushTo: (href: string, as?: string) => {\n if (process.env.NODE_ENV !== 'production') warnUrl()\n const pushRoute = as ? href : ''\n const pushUrl = as || href\n\n return router.push(pushRoute, pushUrl)\n },\n replace: (url: string, as?: string) => {\n if (process.env.NODE_ENV !== 'production') warnUrl()\n return router.replace(url, as)\n },\n replaceTo: (href: string, as?: string) => {\n if (process.env.NODE_ENV !== 'production') warnUrl()\n const replaceRoute = as ? href : ''\n const replaceUrl = as || href\n\n return router.replace(replaceRoute, replaceUrl)\n },\n }\n}\n"]},"metadata":{},"sourceType":"script"}