UNPKG

next-csrf

Version:

CSRF mitigation library for Next.js

1 lines 9.81 kB
{"ast":null,"code":"\"use strict\";\n\nvar _classCallCheck = require(\"@babel/runtime/helpers/classCallCheck\");\n\nvar _createClass = require(\"@babel/runtime/helpers/createClass\");\n\nvar _inherits = require(\"@babel/runtime/helpers/inherits\");\n\nvar _possibleConstructorReturn = require(\"@babel/runtime/helpers/possibleConstructorReturn\");\n\nvar _getPrototypeOf = require(\"@babel/runtime/helpers/getPrototypeOf\");\n\nfunction _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }\n\nfunction _isNativeReflectConstruct() { if (typeof Reflect === \"undefined\" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === \"function\") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }\n\nvar _interopRequireDefault = require(\"@babel/runtime/helpers/interopRequireDefault\");\n\nexports.__esModule = true;\nexports[\"default\"] = void 0;\n\nvar _react = _interopRequireDefault(require(\"react\"));\n\nvar _head = _interopRequireDefault(require(\"../next-server/lib/head\"));\n\nvar statusCodes = {\n 400: 'Bad Request',\n 404: 'This page could not be found',\n 405: 'Method Not Allowed',\n 500: 'Internal Server Error'\n};\n\nfunction _getInitialProps(_ref) {\n var res = _ref.res,\n err = _ref.err;\n var statusCode = res && res.statusCode ? res.statusCode : err ? err.statusCode : 404;\n return {\n statusCode: statusCode\n };\n}\n/**\n* `Error` component used for handling errors.\n*/\n\n\nvar Error = /*#__PURE__*/function (_react$default$Compon) {\n _inherits(Error, _react$default$Compon);\n\n var _super = _createSuper(Error);\n\n function Error() {\n _classCallCheck(this, Error);\n\n return _super.apply(this, arguments);\n }\n\n _createClass(Error, [{\n key: \"render\",\n value: function render() {\n var statusCode = this.props.statusCode;\n var title = this.props.title || statusCodes[statusCode] || 'An unexpected error has occurred';\n return /*#__PURE__*/_react[\"default\"].createElement(\"div\", {\n style: styles.error\n }, /*#__PURE__*/_react[\"default\"].createElement(_head[\"default\"], null, /*#__PURE__*/_react[\"default\"].createElement(\"title\", null, statusCode, \": \", title)), /*#__PURE__*/_react[\"default\"].createElement(\"div\", null, /*#__PURE__*/_react[\"default\"].createElement(\"style\", {\n dangerouslySetInnerHTML: {\n __html: 'body { margin: 0 }'\n }\n }), statusCode ? /*#__PURE__*/_react[\"default\"].createElement(\"h1\", {\n style: styles.h1\n }, statusCode) : null, /*#__PURE__*/_react[\"default\"].createElement(\"div\", {\n style: styles.desc\n }, /*#__PURE__*/_react[\"default\"].createElement(\"h2\", {\n style: styles.h2\n }, title, \".\"))));\n }\n }]);\n\n return Error;\n}(_react[\"default\"].Component);\n\nexports[\"default\"] = Error;\nError.displayName = 'ErrorPage';\nError.getInitialProps = _getInitialProps;\nError.origGetInitialProps = _getInitialProps;\nvar styles = {\n error: {\n color: '#000',\n background: '#fff',\n fontFamily: '-apple-system, BlinkMacSystemFont, Roboto, \"Segoe UI\", \"Fira Sans\", Avenir, \"Helvetica Neue\", \"Lucida Grande\", sans-serif',\n height: '100vh',\n textAlign: 'center',\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'center',\n justifyContent: 'center'\n },\n desc: {\n display: 'inline-block',\n textAlign: 'left',\n lineHeight: '49px',\n height: '49px',\n verticalAlign: 'middle'\n },\n h1: {\n display: 'inline-block',\n borderRight: '1px solid rgba(0, 0, 0,.3)',\n margin: 0,\n marginRight: '20px',\n padding: '10px 23px 10px 0',\n fontSize: '24px',\n fontWeight: 500,\n verticalAlign: 'top'\n },\n h2: {\n fontSize: '14px',\n fontWeight: 'normal',\n lineHeight: 'inherit',\n margin: 0,\n padding: 0\n }\n};","map":{"version":3,"sources":["../../pages/_error.tsx"],"names":["statusCodes","statusCode","res","err","Error","React","Component","displayName","getInitialProps","_getInitialProps","origGetInitialProps","render","title","styles","__html","error","color","background","fontFamily","height","textAlign","display","flexDirection","alignItems","justifyContent","desc","lineHeight","verticalAlign","h1","borderRight","margin","marginRight","padding","fontSize","fontWeight","h2"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAA,MAAA,GAAA,sBAAA,CAAA,OAAA,CAAA,OAAA,CAAA,CAAA;;AACA,IAAA,KAAA,GAAA,sBAAA,CAAA,OAAA,CAAA,yBAAA,CAAA,CAAA;;AAGA,IAAMA,WAAuC,GAAG;AAC9C,OAD8C,aAAA;AAE9C,OAF8C,8BAAA;AAG9C,OAH8C,oBAAA;AAI9C,OAJF;AAAgD,CAAhD;;AAYA,SAAA,gBAAA,OAGsD;AAAA,MAH5B,GAG4B,QAH5B,GAG4B;AAAA,MAHtD,GAGsD,QAHtD,GAGsD;AACpD,MAAMC,UAAU,GACdC,GAAG,IAAIA,GAAG,CAAVA,UAAAA,GAAwBA,GAAG,CAA3BA,UAAAA,GAAyCC,GAAG,GAAGA,GAAG,CAAN,UAAA,GAD9C,GAAA;AAEA,SAAO;AAAEF,IAAAA,UAAT,EAASA;AAAF,GAAP;AAGF;AAAA;;AAGe;;;IAAA,K;;;;;;;;;;;;;WAMbU,kBAAS;AAAA,UACD,UADC,GACgB,KAAvB,KADO,CACD,UADC;AAEP,UAAMC,KAAK,GACT,KAAA,KAAA,CAAA,KAAA,IACAZ,WAAW,CADX,UACW,CADX,IADF,kCAAA;AAKA,aAAA,aACE,MAAA,WAAA,CAAA,aAAA,CAAA,KAAA,EAAA;AAAK,QAAA,KAAK,EAAEa,MAAM,CAAlB;AAAA,OAAA,EAAA,aACE,MAAA,WAAA,CAAA,aAAA,CAAC,KAAD,WAAA,EAAA,IAAA,EAAA,aACE,MAAA,WAAA,CAAA,aAAA,CAAA,OAAA,EAAA,IAAA,EAAA,UAAA,EAAA,IAAA,EAFJ,KAEI,CADF,CADF,EAAA,aAME,MAAA,WAAA,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AA;AAKJQ,IAAAA,aAAa,EAnBoC;AAc7C,GAd6C;AAsBnDC,EAAAA,EAAE,EAAE;AACFP,IAAAA,OAAO,EADL,cAAA;AAEFQ,IAAAA,WAAW,EAFT,4BAAA;AAGFC,IAAAA,MAAM,EAHJ,CAAA;AAIFC,IAAAA,WAAW,EAJT,MAAA;AAKFC,IAAAA,OAAO,EALL,kBAAA;AAMFC,IAAAA,QAAQ,EANN,MAAA;AAOFC,IAAAA,UAAU,EAPR,GAAA;AAQFP,IAAAA,aAAa,EA9BoC;AAsB/C,GAtB+C;AAiCnDQ,EAAAA,EAAE,EAAE;AACFF,IAAAA,QAAQ,EADN,MAAA;AAEFC,IAAAA,UAAU,EAFR,QAAA;AAGFR,IAAAA,UAAU,EAHR,SAAA;AAIFI,IAAAA,MAAM,EAJJ,CAAA;AAKFE,IAAAA,OAAO,EAtCX;AAiCM;AAjC+C,CAArD","sourcesContent":["import React from 'react'\nimport Head from '../next-server/lib/head'\nimport { NextPageContext } from '../next-server/lib/utils'\n\nconst statusCodes: { [code: number]: string } = {\n 400: 'Bad Request',\n 404: 'This page could not be found',\n 405: 'Method Not Allowed',\n 500: 'Internal Server Error',\n}\n\nexport type ErrorProps = {\n statusCode: number\n title?: string\n}\n\nfunction _getInitialProps({\n res,\n err,\n}: NextPageContext): Promise<ErrorProps> | ErrorProps {\n const statusCode =\n res && res.statusCode ? res.statusCode : err ? err.statusCode! : 404\n return { statusCode }\n}\n\n/**\n * `Error` component used for handling errors.\n */\nexport default class Error<P = {}> extends React.Component<P & ErrorProps> {\n static displayName = 'ErrorPage'\n\n static getInitialProps = _getInitialProps\n static origGetInitialProps = _getInitialProps\n\n render() {\n const { statusCode } = this.props\n const title =\n this.props.title ||\n statusCodes[statusCode] ||\n 'An unexpected error has occurred'\n\n return (\n <div style={styles.error}>\n <Head>\n <title>\n {statusCode}: {title}\n </title>\n </Head>\n <div>\n <style dangerouslySetInnerHTML={{ __html: 'body { margin: 0 }' }} />\n {statusCode ? <h1 style={styles.h1}>{statusCode}</h1> : null}\n <div style={styles.desc}>\n <h2 style={styles.h2}>{title}.</h2>\n </div>\n </div>\n </div>\n )\n }\n}\n\nconst styles: { [k: string]: React.CSSProperties } = {\n error: {\n color: '#000',\n background: '#fff',\n fontFamily:\n '-apple-system, BlinkMacSystemFont, Roboto, \"Segoe UI\", \"Fira Sans\", Avenir, \"Helvetica Neue\", \"Lucida Grande\", sans-serif',\n height: '100vh',\n textAlign: 'center',\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'center',\n justifyContent: 'center',\n },\n\n desc: {\n display: 'inline-block',\n textAlign: 'left',\n lineHeight: '49px',\n height: '49px',\n verticalAlign: 'middle',\n },\n\n h1: {\n display: 'inline-block',\n borderRight: '1px solid rgba(0, 0, 0,.3)',\n margin: 0,\n marginRight: '20px',\n padding: '10px 23px 10px 0',\n fontSize: '24px',\n fontWeight: 500,\n verticalAlign: 'top',\n },\n\n h2: {\n fontSize: '14px',\n fontWeight: 'normal',\n lineHeight: 'inherit',\n margin: 0,\n padding: 0,\n },\n}\n"]},"metadata":{},"sourceType":"script"}