@dr.pogodin/react-utils 1.21.1 → 1.21.3
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/build/development/client/index.js +0 -7
- package/build/development/client/index.js.map +1 -1
- package/build/development/client/init.js +3 -17
- package/build/development/client/init.js.map +1 -1
- package/build/development/index.js +0 -13
- package/build/development/index.js.map +1 -1
- package/build/development/server/Cache.js +2 -9
- package/build/development/server/Cache.js.map +1 -1
- package/build/development/server/index.js +7 -32
- package/build/development/server/index.js.map +1 -1
- package/build/development/server/renderer.js +24 -80
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js +21 -61
- package/build/development/server/server.js.map +1 -1
- package/build/development/server/utils/errors.js +2 -9
- package/build/development/server/utils/errors.js.map +1 -1
- package/build/development/server/utils/index.js +0 -4
- package/build/development/shared/components/Button/index.js +2 -13
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js +2 -9
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/CodeSplit/index.js +11 -22
- package/build/development/shared/components/CodeSplit/index.js.map +1 -1
- package/build/development/shared/components/Dropdown/index.js +0 -11
- package/build/development/shared/components/Dropdown/index.js.map +1 -1
- package/build/development/shared/components/GenericLink/index.js +3 -9
- package/build/development/shared/components/GenericLink/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +0 -7
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/Link.js +3 -6
- package/build/development/shared/components/Link.js.map +1 -1
- package/build/development/shared/components/MetaTags.js +1 -8
- package/build/development/shared/components/MetaTags.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +2 -19
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/NavLink.js +2 -6
- package/build/development/shared/components/NavLink.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js +0 -7
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/ScalableRect/index.js +1 -6
- package/build/development/shared/components/ScalableRect/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js +0 -9
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js +9 -28
- package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js +0 -16
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js +3 -11
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/index.js +0 -17
- package/build/development/shared/components/index.js.map +1 -1
- package/build/development/shared/utils/Barrier.js +1 -13
- package/build/development/shared/utils/Barrier.js.map +1 -1
- package/build/development/shared/utils/Emitter.js +4 -13
- package/build/development/shared/utils/Emitter.js.map +1 -1
- package/build/development/shared/utils/Semaphore.js +13 -19
- package/build/development/shared/utils/Semaphore.js.map +1 -1
- package/build/development/shared/utils/config.js +0 -5
- package/build/development/shared/utils/config.js.map +1 -1
- package/build/development/shared/utils/index.js +5 -26
- package/build/development/shared/utils/index.js.map +1 -1
- package/build/development/shared/utils/isomorphy.js +6 -12
- package/build/development/shared/utils/isomorphy.js.map +1 -1
- package/build/development/shared/utils/jest/E2eSsrEnv.js +20 -41
- package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/development/shared/utils/jest/index.js +10 -31
- package/build/development/shared/utils/jest/index.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +2 -5
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/shared/utils/time.js +52 -14
- package/build/development/shared/utils/time.js.map +1 -1
- package/build/development/shared/utils/webpack.js +1 -5
- package/build/development/shared/utils/webpack.js.map +1 -1
- package/build/development/style.css +5 -24
- package/build/development/web.bundle.js +27 -27
- package/build/production/client/index.js.map +1 -1
- package/build/production/client/init.js.map +1 -1
- package/build/production/index.js.map +1 -1
- package/build/production/server/Cache.js.map +1 -1
- package/build/production/server/index.js.map +1 -1
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/server/server.js.map +1 -1
- package/build/production/server/utils/errors.js.map +1 -1
- package/build/production/shared/components/Button/index.js.map +1 -1
- package/build/production/shared/components/Checkbox/index.js.map +1 -1
- package/build/production/shared/components/CodeSplit/index.js.map +1 -1
- package/build/production/shared/components/Dropdown/index.js.map +1 -1
- package/build/production/shared/components/GenericLink/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/components/Link.js.map +1 -1
- package/build/production/shared/components/MetaTags.js.map +1 -1
- package/build/production/shared/components/Modal/index.js.map +1 -1
- package/build/production/shared/components/NavLink.js.map +1 -1
- package/build/production/shared/components/PageLayout/index.js.map +1 -1
- package/build/production/shared/components/ScalableRect/index.js.map +1 -1
- package/build/production/shared/components/Throbber/index.js.map +1 -1
- package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/production/shared/components/WithTooltip/index.js.map +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/production/shared/components/index.js.map +1 -1
- package/build/production/shared/utils/Barrier.js.map +1 -1
- package/build/production/shared/utils/Emitter.js.map +1 -1
- package/build/production/shared/utils/Semaphore.js.map +1 -1
- package/build/production/shared/utils/config.js.map +1 -1
- package/build/production/shared/utils/index.js.map +1 -1
- package/build/production/shared/utils/isomorphy.js.map +1 -1
- package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/production/shared/utils/jest/index.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/shared/utils/time.js +21 -2
- package/build/production/shared/utils/time.js.map +1 -1
- package/build/production/shared/utils/webpack.js.map +1 -1
- package/build/production/style.css +1 -1
- package/build/production/style.css.map +1 -1
- package/build/production/web.bundle.js +1 -1
- package/build/production/web.bundle.js.map +1 -1
- package/config/babel/node-ssr.js +1 -1
- package/package.json +33 -31
|
@@ -1,41 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = factory;
|
|
9
8
|
exports.getDefaultCspSettings = getDefaultCspSettings;
|
|
10
|
-
|
|
11
9
|
var _path = require("path");
|
|
12
|
-
|
|
13
10
|
var _url = require("url");
|
|
14
|
-
|
|
15
11
|
var _lodash = require("lodash");
|
|
16
|
-
|
|
17
12
|
var _compression = _interopRequireDefault(require("compression"));
|
|
18
|
-
|
|
19
13
|
var _cookieParser = _interopRequireDefault(require("cookie-parser"));
|
|
20
|
-
|
|
21
14
|
var _csurf = _interopRequireDefault(require("csurf"));
|
|
22
|
-
|
|
23
15
|
var _express = _interopRequireDefault(require("express"));
|
|
24
|
-
|
|
25
16
|
var _serveFavicon = _interopRequireDefault(require("serve-favicon"));
|
|
26
|
-
|
|
27
17
|
var _helmet = _interopRequireDefault(require("helmet"));
|
|
28
|
-
|
|
29
18
|
var _morgan = _interopRequireDefault(require("morgan"));
|
|
30
|
-
|
|
31
19
|
var _requestIp = _interopRequireDefault(require("request-ip"));
|
|
32
|
-
|
|
33
20
|
var _uuid = require("uuid");
|
|
34
|
-
|
|
35
21
|
var _renderer = _interopRequireDefault(require("./renderer"));
|
|
36
|
-
|
|
37
22
|
var _errors = require("./utils/errors");
|
|
38
|
-
|
|
39
23
|
/**
|
|
40
24
|
* Creation of standard ExpressJS server for ReactJS apps.
|
|
41
25
|
*/
|
|
@@ -45,20 +29,24 @@ var _errors = require("./utils/errors");
|
|
|
45
29
|
* @ignore
|
|
46
30
|
*/
|
|
47
31
|
const defaultCspSettings = {
|
|
48
|
-
directives: (0, _lodash.mapValues)(_helmet.default.contentSecurityPolicy.getDefaultDirectives(),
|
|
32
|
+
directives: (0, _lodash.mapValues)(_helmet.default.contentSecurityPolicy.getDefaultDirectives(),
|
|
33
|
+
// 'https:' options (automatic re-write of insecure URLs to secure ones)
|
|
49
34
|
// is removed to facilitate local development with HTTP server. In cloud
|
|
50
35
|
// deployments we assume Apache or Nginx server in front of out app takes
|
|
51
36
|
// care about such re-writes.
|
|
52
37
|
array => array.filter(item => item !== 'https:'))
|
|
53
38
|
};
|
|
54
|
-
defaultCspSettings.directives['frame-src'] = ["'self'",
|
|
39
|
+
defaultCspSettings.directives['frame-src'] = ["'self'",
|
|
40
|
+
// YouTube domain is whitelisted to allow <YouTubeVideo> component to work
|
|
55
41
|
// out of box.
|
|
56
42
|
'https://*.youtube.com'];
|
|
57
|
-
defaultCspSettings.directives['script-src'].push("'unsafe-eval'");
|
|
43
|
+
defaultCspSettings.directives['script-src'].push("'unsafe-eval'");
|
|
44
|
+
|
|
45
|
+
// No need for automatic re-writes via Content Security Policy settings:
|
|
58
46
|
// the forefront Apache or Nginx server is supposed to take care of this
|
|
59
47
|
// in production cloud deployments.
|
|
60
|
-
|
|
61
48
|
delete defaultCspSettings.directives['upgrade-insecure-requests'];
|
|
49
|
+
|
|
62
50
|
/**
|
|
63
51
|
* @category Utilities
|
|
64
52
|
* @func server/getDefaultCspSettings
|
|
@@ -74,11 +62,9 @@ delete defaultCspSettings.directives['upgrade-insecure-requests'];
|
|
|
74
62
|
* with the exception of `nonce-xxx` clause in `script-src` directive,
|
|
75
63
|
* which is added dynamically for each request.
|
|
76
64
|
*/
|
|
77
|
-
|
|
78
65
|
function getDefaultCspSettings() {
|
|
79
66
|
return (0, _lodash.cloneDeep)(defaultCspSettings);
|
|
80
67
|
}
|
|
81
|
-
|
|
82
68
|
async function factory(webpackConfig, options) {
|
|
83
69
|
const rendererOps = (0, _lodash.pick)(options, ['Application', 'beforeRender', 'favicon', 'logger', 'maxSsrRounds', 'noCsp', 'ssrTimeout', 'staticCacheController', 'staticCacheSize']);
|
|
84
70
|
const renderer = (0, _renderer.default)(webpackConfig, rendererOps);
|
|
@@ -86,27 +72,21 @@ async function factory(webpackConfig, options) {
|
|
|
86
72
|
publicPath
|
|
87
73
|
} = webpackConfig.output;
|
|
88
74
|
const server = (0, _express.default)();
|
|
89
|
-
|
|
90
75
|
if (options.beforeExpressJsSetup) {
|
|
91
76
|
await options.beforeExpressJsSetup(server);
|
|
92
77
|
}
|
|
93
|
-
|
|
94
78
|
server.logger = options.logger;
|
|
95
|
-
|
|
96
79
|
if (options.httpsRedirect) {
|
|
97
80
|
server.use((req, res, next) => {
|
|
98
81
|
const schema = req.headers['x-forwarded-proto'];
|
|
99
|
-
|
|
100
82
|
if (schema === 'http') {
|
|
101
83
|
let url = `https://${req.headers.host}`;
|
|
102
84
|
if (req.originalUrl !== '/') url += req.originalUrl;
|
|
103
85
|
return res.redirect(url);
|
|
104
86
|
}
|
|
105
|
-
|
|
106
87
|
return next();
|
|
107
88
|
});
|
|
108
89
|
}
|
|
109
|
-
|
|
110
90
|
server.use((0, _compression.default)());
|
|
111
91
|
server.use((0, _helmet.default)({
|
|
112
92
|
contentSecurityPolicy: false,
|
|
@@ -114,30 +94,27 @@ async function factory(webpackConfig, options) {
|
|
|
114
94
|
crossOriginOpenerPolicy: false,
|
|
115
95
|
crossOriginResourcePolicy: false
|
|
116
96
|
}));
|
|
117
|
-
|
|
118
97
|
if (!options.noCsp) {
|
|
119
98
|
server.use((req, res, next) => {
|
|
120
|
-
req.nonce = (0, _uuid.v4)();
|
|
99
|
+
req.nonce = (0, _uuid.v4)();
|
|
100
|
+
|
|
101
|
+
// TODO: This is deprecated, but it is kept for now for backward
|
|
121
102
|
// compatibility. Should be removed sometime later.
|
|
103
|
+
req.cspNonce = req.nonce;
|
|
122
104
|
|
|
123
|
-
|
|
105
|
+
// The deep clone is necessary here to ensure that default value can't be
|
|
124
106
|
// mutated during request processing.
|
|
125
|
-
|
|
126
107
|
let cspSettings = (0, _lodash.cloneDeep)(defaultCspSettings);
|
|
127
108
|
cspSettings.directives['script-src'].push(`'nonce-${req.nonce}'`);
|
|
128
|
-
|
|
129
109
|
if (options.cspSettingsHook) {
|
|
130
110
|
cspSettings = options.cspSettingsHook(cspSettings, req);
|
|
131
111
|
}
|
|
132
|
-
|
|
133
112
|
_helmet.default.contentSecurityPolicy(cspSettings)(req, res, next);
|
|
134
113
|
});
|
|
135
114
|
}
|
|
136
|
-
|
|
137
115
|
if (options.favicon) {
|
|
138
116
|
server.use((0, _serveFavicon.default)(options.favicon));
|
|
139
117
|
}
|
|
140
|
-
|
|
141
118
|
server.use('/robots.txt', (req, res) => res.send('User-agent: *\nDisallow:'));
|
|
142
119
|
server.use(_express.default.json({
|
|
143
120
|
limit: '300kb'
|
|
@@ -150,32 +127,28 @@ async function factory(webpackConfig, options) {
|
|
|
150
127
|
server.use((0, _csurf.default)({
|
|
151
128
|
cookie: true
|
|
152
129
|
}));
|
|
153
|
-
|
|
154
130
|
_morgan.default.token('ip', req => req.clientIp);
|
|
155
|
-
|
|
156
131
|
const FORMAT = ':ip > :status :method :url :response-time ms :res[content-length] :referrer :user-agent';
|
|
157
132
|
server.use((0, _morgan.default)(FORMAT, {
|
|
158
133
|
stream: {
|
|
159
134
|
write: options.logger.info.bind(options.logger)
|
|
160
135
|
}
|
|
161
|
-
}));
|
|
136
|
+
}));
|
|
137
|
+
|
|
138
|
+
// Note: no matter the "public path", we want the service worker, if any,
|
|
162
139
|
// to be served from the root, to have all web app pages in its scope.
|
|
163
140
|
// Thus, this setup to serve it. Probably, need some more configuration
|
|
164
141
|
// for special cases, but this will do for now.
|
|
165
|
-
|
|
166
142
|
server.get('/__service-worker.js', _express.default.static(webpackConfig.output.path, {
|
|
167
143
|
setHeaders: res => res.set('Cache-Control', 'no-cache')
|
|
168
144
|
}));
|
|
145
|
+
|
|
169
146
|
/* Setup of Hot Module Reloading for development environment.
|
|
170
147
|
* These dependencies are not used, nor installed for production use,
|
|
171
148
|
* hence we should violate some import-related lint rules. */
|
|
172
|
-
|
|
173
149
|
/* eslint-disable global-require */
|
|
174
|
-
|
|
175
150
|
/* eslint-disable import/no-extraneous-dependencies */
|
|
176
|
-
|
|
177
151
|
/* eslint-disable import/no-unresolved */
|
|
178
|
-
|
|
179
152
|
if (options.devMode) {
|
|
180
153
|
// This is a workaround for SASS bug:
|
|
181
154
|
// https://github.com/dart-lang/sdk/issues/27979
|
|
@@ -186,13 +159,9 @@ async function factory(webpackConfig, options) {
|
|
|
186
159
|
href: `${(0, _url.pathToFileURL)(process.cwd()).href}${_path.sep}`
|
|
187
160
|
};
|
|
188
161
|
}
|
|
189
|
-
|
|
190
162
|
const webpack = require('webpack');
|
|
191
|
-
|
|
192
163
|
const webpackDevMiddleware = require('webpack-dev-middleware');
|
|
193
|
-
|
|
194
164
|
const webpackHotMiddleware = require('webpack-hot-middleware');
|
|
195
|
-
|
|
196
165
|
const compiler = webpack(webpackConfig);
|
|
197
166
|
server.use(webpackDevMiddleware(compiler, {
|
|
198
167
|
publicPath,
|
|
@@ -201,32 +170,25 @@ async function factory(webpackConfig, options) {
|
|
|
201
170
|
server.use(webpackHotMiddleware(compiler));
|
|
202
171
|
}
|
|
203
172
|
/* eslint-enable global-require */
|
|
204
|
-
|
|
205
173
|
/* eslint-enable import/no-extraneous-dependencies */
|
|
206
|
-
|
|
207
174
|
/* eslint-enable import/no-unresolved */
|
|
208
175
|
|
|
209
|
-
|
|
210
176
|
server.use(publicPath, _express.default.static(webpackConfig.output.path));
|
|
211
|
-
|
|
212
177
|
if (options.onExpressJsSetup) {
|
|
213
178
|
await options.onExpressJsSetup(server);
|
|
214
179
|
}
|
|
215
|
-
|
|
216
180
|
server.use(renderer);
|
|
217
|
-
/* Detects 404 errors, and forwards them to the error handler. */
|
|
218
181
|
|
|
182
|
+
/* Detects 404 errors, and forwards them to the error handler. */
|
|
219
183
|
server.use((req, res, next) => {
|
|
220
184
|
next((0, _errors.newError)(_errors.ERRORS.NOT_FOUND, _errors.CODES.NOT_FOUND));
|
|
221
185
|
});
|
|
222
186
|
let dontAttachDefaultErrorHandler;
|
|
223
|
-
|
|
224
187
|
if (options.beforeExpressJsError) {
|
|
225
188
|
dontAttachDefaultErrorHandler = await options.beforeExpressJsError(server);
|
|
226
189
|
}
|
|
227
|
-
/* Error handler. */
|
|
228
|
-
|
|
229
190
|
|
|
191
|
+
/* Error handler. */
|
|
230
192
|
if (!dontAttachDefaultErrorHandler) {
|
|
231
193
|
// TODO: Do we need this error handler at all? It actually seems to do
|
|
232
194
|
// what the default ExpressJS error handler does anyway, see:
|
|
@@ -241,20 +203,18 @@ async function factory(webpackConfig, options) {
|
|
|
241
203
|
// sending initial response to the client.
|
|
242
204
|
if (res.headersSent) return next(error);
|
|
243
205
|
const status = error.status || _errors.CODES.INTERNAL_SERVER_ERROR;
|
|
244
|
-
const serverSide = status >= _errors.CODES.INTERNAL_SERVER_ERROR;
|
|
206
|
+
const serverSide = status >= _errors.CODES.INTERNAL_SERVER_ERROR;
|
|
245
207
|
|
|
208
|
+
// Log server-side errors always, client-side at debug level only.
|
|
246
209
|
options.logger.log(serverSide ? 'error' : 'debug', error);
|
|
247
210
|
let message = error.message || (0, _errors.getErrorForCode)(status);
|
|
248
|
-
|
|
249
211
|
if (serverSide && process.env.NODE_ENV === 'production') {
|
|
250
212
|
message = _errors.ERRORS.INTERNAL_SERVER_ERROR;
|
|
251
213
|
}
|
|
252
|
-
|
|
253
214
|
res.status(status).send(message);
|
|
254
215
|
return undefined;
|
|
255
216
|
});
|
|
256
217
|
}
|
|
257
|
-
|
|
258
218
|
return server;
|
|
259
219
|
}
|
|
260
220
|
//# sourceMappingURL=server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","names":["defaultCspSettings","directives","mapValues","helmet","contentSecurityPolicy","getDefaultDirectives","array","filter","item","push","getDefaultCspSettings","cloneDeep","factory","webpackConfig","options","rendererOps","pick","renderer","rendererFactory","publicPath","output","server","express","beforeExpressJsSetup","logger","httpsRedirect","use","req","res","next","schema","headers","url","host","originalUrl","redirect","compression","crossOriginEmbedderPolicy","crossOriginOpenerPolicy","crossOriginResourcePolicy","noCsp","nonce","uuid","cspNonce","cspSettings","cspSettingsHook","favicon","send","json","limit","urlencoded","extended","cookieParser","requestIp","mw","csrf","cookie","loggerMiddleware","token","clientIp","FORMAT","stream","write","info","bind","get","static","path","setHeaders","set","devMode","global","location","href","pathToFileURL","process","cwd","sep","webpack","require","webpackDevMiddleware","webpackHotMiddleware","compiler","serverSideRender","onExpressJsSetup","newError","ERRORS","NOT_FOUND","CODES","dontAttachDefaultErrorHandler","beforeExpressJsError","error","headersSent","status","INTERNAL_SERVER_ERROR","serverSide","log","message","getErrorForCode","env","NODE_ENV","undefined"],"sources":["../../../src/server/server.js"],"sourcesContent":["/**\n * Creation of standard ExpressJS server for ReactJS apps.\n */\n\nimport { sep } from 'path';\nimport { pathToFileURL } from 'url';\n\nimport {\n cloneDeep,\n mapValues,\n pick,\n} from 'lodash';\n\nimport compression from 'compression';\nimport cookieParser from 'cookie-parser';\nimport csrf from 'csurf';\nimport express from 'express';\nimport favicon from 'serve-favicon';\nimport helmet from 'helmet';\nimport loggerMiddleware from 'morgan';\nimport requestIp from 'request-ip';\nimport { v4 as uuid } from 'uuid';\n\nimport rendererFactory from './renderer';\n\nimport {\n CODES,\n ERRORS,\n getErrorForCode,\n newError,\n} from './utils/errors';\n\n/**\n * Default Content Security Policy settings.\n * @ignore\n */\nconst defaultCspSettings = {\n directives: mapValues(\n helmet.contentSecurityPolicy.getDefaultDirectives(),\n\n // 'https:' options (automatic re-write of insecure URLs to secure ones)\n // is removed to facilitate local development with HTTP server. In cloud\n // deployments we assume Apache or Nginx server in front of out app takes\n // care about such re-writes.\n (array) => array.filter((item) => item !== 'https:'),\n ),\n};\ndefaultCspSettings.directives['frame-src'] = [\n \"'self'\",\n\n // YouTube domain is whitelisted to allow <YouTubeVideo> component to work\n // out of box.\n 'https://*.youtube.com',\n];\ndefaultCspSettings.directives['script-src'].push(\"'unsafe-eval'\");\n\n// No need for automatic re-writes via Content Security Policy settings:\n// the forefront Apache or Nginx server is supposed to take care of this\n// in production cloud deployments.\ndelete defaultCspSettings.directives['upgrade-insecure-requests'];\n\n/**\n * @category Utilities\n * @func server/getDefaultCspSettings\n * @global\n * @desc\n * ```js\n * import { server } from '@dr.pogodin/react-utils';\n * const { getDefaultCspSettings } from '@dr.pogodin/react-utils';\n * ```\n * @return {{\n * directives: object\n * }} A deep copy of default CSP settings object used by `react-utils`,\n * with the exception of `nonce-xxx` clause in `script-src` directive,\n * which is added dynamically for each request.\n */\nexport function getDefaultCspSettings() {\n return cloneDeep(defaultCspSettings);\n}\n\nexport default async function factory(webpackConfig, options) {\n const rendererOps = pick(options, [\n 'Application',\n 'beforeRender',\n 'favicon',\n 'logger',\n 'maxSsrRounds',\n 'noCsp',\n 'ssrTimeout',\n 'staticCacheController',\n 'staticCacheSize',\n ]);\n const renderer = rendererFactory(webpackConfig, rendererOps);\n const { publicPath } = webpackConfig.output;\n\n const server = express();\n\n if (options.beforeExpressJsSetup) {\n await options.beforeExpressJsSetup(server);\n }\n\n server.logger = options.logger;\n\n if (options.httpsRedirect) {\n server.use((req, res, next) => {\n const schema = req.headers['x-forwarded-proto'];\n if (schema === 'http') {\n let url = `https://${req.headers.host}`;\n if (req.originalUrl !== '/') url += req.originalUrl;\n return res.redirect(url);\n }\n return next();\n });\n }\n\n server.use(compression());\n server.use(\n helmet({\n contentSecurityPolicy: false,\n crossOriginEmbedderPolicy: false,\n crossOriginOpenerPolicy: false,\n crossOriginResourcePolicy: false,\n }),\n );\n\n if (!options.noCsp) {\n server.use((req, res, next) => {\n req.nonce = uuid();\n\n // TODO: This is deprecated, but it is kept for now for backward\n // compatibility. Should be removed sometime later.\n req.cspNonce = req.nonce;\n\n // The deep clone is necessary here to ensure that default value can't be\n // mutated during request processing.\n let cspSettings = cloneDeep(defaultCspSettings);\n cspSettings.directives['script-src'].push(`'nonce-${req.nonce}'`);\n if (options.cspSettingsHook) {\n cspSettings = options.cspSettingsHook(cspSettings, req);\n }\n helmet.contentSecurityPolicy(cspSettings)(req, res, next);\n });\n }\n\n if (options.favicon) {\n server.use(favicon(options.favicon));\n }\n\n server.use('/robots.txt', (req, res) => res.send('User-agent: *\\nDisallow:'));\n\n server.use(express.json({ limit: '300kb' }));\n server.use(express.urlencoded({ extended: false }));\n server.use(cookieParser());\n server.use(requestIp.mw());\n\n server.use(csrf({ cookie: true }));\n\n loggerMiddleware.token('ip', (req) => req.clientIp);\n const FORMAT = ':ip > :status :method :url :response-time ms :res[content-length] :referrer :user-agent';\n server.use(loggerMiddleware(FORMAT, {\n stream: {\n write: options.logger.info.bind(options.logger),\n },\n }));\n\n // Note: no matter the \"public path\", we want the service worker, if any,\n // to be served from the root, to have all web app pages in its scope.\n // Thus, this setup to serve it. Probably, need some more configuration\n // for special cases, but this will do for now.\n server.get('/__service-worker.js', express.static(\n webpackConfig.output.path,\n {\n setHeaders: (res) => res.set('Cache-Control', 'no-cache'),\n },\n ));\n\n /* Setup of Hot Module Reloading for development environment.\n * These dependencies are not used, nor installed for production use,\n * hence we should violate some import-related lint rules. */\n /* eslint-disable global-require */\n /* eslint-disable import/no-extraneous-dependencies */\n /* eslint-disable import/no-unresolved */\n if (options.devMode) {\n // This is a workaround for SASS bug:\n // https://github.com/dart-lang/sdk/issues/27979\n // which manifests itself sometimes when webpack dev middleware is used\n // (in dev mode), and app modules are imported in some unfortunate ways.\n if (!global.location) {\n global.location = {\n href: `${pathToFileURL(process.cwd()).href}${sep}`,\n };\n }\n\n const webpack = require('webpack');\n const webpackDevMiddleware = require('webpack-dev-middleware');\n const webpackHotMiddleware = require('webpack-hot-middleware');\n const compiler = webpack(webpackConfig);\n server.use(webpackDevMiddleware(compiler, {\n publicPath,\n serverSideRender: true,\n }));\n server.use(webpackHotMiddleware(compiler));\n }\n /* eslint-enable global-require */\n /* eslint-enable import/no-extraneous-dependencies */\n /* eslint-enable import/no-unresolved */\n\n server.use(publicPath, express.static(webpackConfig.output.path));\n\n if (options.onExpressJsSetup) {\n await options.onExpressJsSetup(server);\n }\n server.use(renderer);\n\n /* Detects 404 errors, and forwards them to the error handler. */\n server.use((req, res, next) => {\n next(newError(ERRORS.NOT_FOUND, CODES.NOT_FOUND));\n });\n\n let dontAttachDefaultErrorHandler;\n if (options.beforeExpressJsError) {\n dontAttachDefaultErrorHandler = await options.beforeExpressJsError(server);\n }\n\n /* Error handler. */\n if (!dontAttachDefaultErrorHandler) {\n // TODO: Do we need this error handler at all? It actually seems to do\n // what the default ExpressJS error handler does anyway, see:\n // https://expressjs.com/en/guide/error-handling.html\n //\n // TODO: It is better to move the default error handler definition\n // to a stand-alone function at top-level, but the use of options.logger\n // prevents to do it without some extra refactoring. Should be done sometime\n // though.\n server.use((error, req, res, next) => {\n // TODO: This is needed to correctly handled any errors thrown after\n // sending initial response to the client.\n if (res.headersSent) return next(error);\n\n const status = error.status || CODES.INTERNAL_SERVER_ERROR;\n const serverSide = status >= CODES.INTERNAL_SERVER_ERROR;\n\n // Log server-side errors always, client-side at debug level only.\n options.logger.log(serverSide ? 'error' : 'debug', error);\n\n let message = error.message || getErrorForCode(status);\n if (serverSide && process.env.NODE_ENV === 'production') {\n message = ERRORS.INTERNAL_SERVER_ERROR;\n }\n\n res.status(status).send(message);\n return undefined;\n });\n }\n\n return server;\n}\n"],"mappings":";;;;;;;;;;AAIA;;AACA;;AAEA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AAEA;;AAzBA;AACA;AACA;;AA8BA;AACA;AACA;AACA;AACA,MAAMA,kBAAkB,GAAG;EACzBC,UAAU,EAAE,IAAAC,iBAAA,EACVC,eAAA,CAAOC,qBAAP,CAA6BC,oBAA7B,EADU,EAGV;EACA;EACA;EACA;EACCC,KAAD,IAAWA,KAAK,CAACC,MAAN,CAAcC,IAAD,IAAUA,IAAI,KAAK,QAAhC,CAPD;AADa,CAA3B;AAWAR,kBAAkB,CAACC,UAAnB,CAA8B,WAA9B,IAA6C,CAC3C,QAD2C,EAG3C;AACA;AACA,uBAL2C,CAA7C;AAOAD,kBAAkB,CA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AQhE,GAAR,EAAaC,GAAb,EAAkBC,IAAlB,KAA2B;MACpC;MACA;MACA,IAAID,GAAG,CAACgE,WAAR,EAAqB,OAAO/D,IAAI,CAAC8D,KAAD,CAAX;MAErB,MAAME,MAAM,GAAGF,KAAK,CAACE,MAAN,IAAgBL,aAAA,CAAMM,qBAArC;MACA,MAAMC,UAAU,GAAGF,MAAM,IAAIL,aAAA,CAAMM,qBAAnC,CANoC,CAQpC;;MACAhF,OAAO,CAACU,MAAR,CAAewE,GAAf,CAAmBD,UAAU,GAAG,OAAH,GAAa,OAA1C,EAAmDJ,KAAnD;MAEA,IAAIM,OAAO,GAAGN,KAAK,CAACM,OAAN,IAAiB,IAAAC,uBAAA,EAAgBL,MAAhB,CAA/B;;MACA,IAAIE,UAAU,IAAIpB,OAAO,CAACwB,GAAR,CAAYC,QAAZ,KAAyB,YAA3C,EAAyD;QACvDH,OAAO,GAAGX,cAAA,CAAOQ,qBAAjB;MACD;;MAEDlE,GAAG,CAACiE,MAAJ,CAAWA,MAAX,EAAmB9C,IAAnB,CAAwBkD,OAAxB;MACA,OAAOI,SAAP;IACD,CAlBD;EAmBD;;EAED,OAAOhF,MAAP;AACD"}
|
|
1
|
+
{"version":3,"file":"server.js","names":["defaultCspSettings","directives","mapValues","helmet","contentSecurityPolicy","getDefaultDirectives","array","filter","item","push","getDefaultCspSettings","cloneDeep","factory","webpackConfig","options","rendererOps","pick","renderer","rendererFactory","publicPath","output","server","express","beforeExpressJsSetup","logger","httpsRedirect","use","req","res","next","schema","headers","url","host","originalUrl","redirect","compression","crossOriginEmbedderPolicy","crossOriginOpenerPolicy","crossOriginResourcePolicy","noCsp","nonce","uuid","cspNonce","cspSettings","cspSettingsHook","favicon","send","json","limit","urlencoded","extended","cookieParser","requestIp","mw","csrf","cookie","loggerMiddleware","token","clientIp","FORMAT","stream","write","info","bind","get","static","path","setHeaders","set","devMode","global","location","href","pathToFileURL","process","cwd","sep","webpack","require","webpackDevMiddleware","webpackHotMiddleware","compiler","serverSideRender","onExpressJsSetup","newError","ERRORS","NOT_FOUND","CODES","dontAttachDefaultErrorHandler","beforeExpressJsError","error","headersSent","status","INTERNAL_SERVER_ERROR","serverSide","log","message","getErrorForCode","env","NODE_ENV","undefined"],"sources":["../../../src/server/server.js"],"sourcesContent":["/**\n * Creation of standard ExpressJS server for ReactJS apps.\n */\n\nimport { sep } from 'path';\nimport { pathToFileURL } from 'url';\n\nimport {\n cloneDeep,\n mapValues,\n pick,\n} from 'lodash';\n\nimport compression from 'compression';\nimport cookieParser from 'cookie-parser';\nimport csrf from 'csurf';\nimport express from 'express';\nimport favicon from 'serve-favicon';\nimport helmet from 'helmet';\nimport loggerMiddleware from 'morgan';\nimport requestIp from 'request-ip';\nimport { v4 as uuid } from 'uuid';\n\nimport rendererFactory from './renderer';\n\nimport {\n CODES,\n ERRORS,\n getErrorForCode,\n newError,\n} from './utils/errors';\n\n/**\n * Default Content Security Policy settings.\n * @ignore\n */\nconst defaultCspSettings = {\n directives: mapValues(\n helmet.contentSecurityPolicy.getDefaultDirectives(),\n\n // 'https:' options (automatic re-write of insecure URLs to secure ones)\n // is removed to facilitate local development with HTTP server. In cloud\n // deployments we assume Apache or Nginx server in front of out app takes\n // care about such re-writes.\n (array) => array.filter((item) => item !== 'https:'),\n ),\n};\ndefaultCspSettings.directives['frame-src'] = [\n \"'self'\",\n\n // YouTube domain is whitelisted to allow <YouTubeVideo> component to work\n // out of box.\n 'https://*.youtube.com',\n];\ndefaultCspSettings.directives['script-src'].push(\"'unsafe-eval'\");\n\n// No need for automatic re-writes via Content Security Policy settings:\n// the forefront Apache or Nginx server is supposed to take care of this\n// in production cloud deployments.\ndelete defaultCspSettings.directives['upgrade-insecure-requests'];\n\n/**\n * @category Utilities\n * @func server/getDefaultCspSettings\n * @global\n * @desc\n * ```js\n * import { server } from '@dr.pogodin/react-utils';\n * const { getDefaultCspSettings } from '@dr.pogodin/react-utils';\n * ```\n * @return {{\n * directives: object\n * }} A deep copy of default CSP settings object used by `react-utils`,\n * with the exception of `nonce-xxx` clause in `script-src` directive,\n * which is added dynamically for each request.\n */\nexport function getDefaultCspSettings() {\n return cloneDeep(defaultCspSettings);\n}\n\nexport default async function factory(webpackConfig, options) {\n const rendererOps = pick(options, [\n 'Application',\n 'beforeRender',\n 'favicon',\n 'logger',\n 'maxSsrRounds',\n 'noCsp',\n 'ssrTimeout',\n 'staticCacheController',\n 'staticCacheSize',\n ]);\n const renderer = rendererFactory(webpackConfig, rendererOps);\n const { publicPath } = webpackConfig.output;\n\n const server = express();\n\n if (options.beforeExpressJsSetup) {\n await options.beforeExpressJsSetup(server);\n }\n\n server.logger = options.logger;\n\n if (options.httpsRedirect) {\n server.use((req, res, next) => {\n const schema = req.headers['x-forwarded-proto'];\n if (schema === 'http') {\n let url = `https://${req.headers.host}`;\n if (req.originalUrl !== '/') url += req.originalUrl;\n return res.redirect(url);\n }\n return next();\n });\n }\n\n server.use(compression());\n server.use(\n helmet({\n contentSecurityPolicy: false,\n crossOriginEmbedderPolicy: false,\n crossOriginOpenerPolicy: false,\n crossOriginResourcePolicy: false,\n }),\n );\n\n if (!options.noCsp) {\n server.use((req, res, next) => {\n req.nonce = uuid();\n\n // TODO: This is deprecated, but it is kept for now for backward\n // compatibility. Should be removed sometime later.\n req.cspNonce = req.nonce;\n\n // The deep clone is necessary here to ensure that default value can't be\n // mutated during request processing.\n let cspSettings = cloneDeep(defaultCspSettings);\n cspSettings.directives['script-src'].push(`'nonce-${req.nonce}'`);\n if (options.cspSettingsHook) {\n cspSettings = options.cspSettingsHook(cspSettings, req);\n }\n helmet.contentSecurityPolicy(cspSettings)(req, res, next);\n });\n }\n\n if (options.favicon) {\n server.use(favicon(options.favicon));\n }\n\n server.use('/robots.txt', (req, res) => res.send('User-agent: *\\nDisallow:'));\n\n server.use(express.json({ limit: '300kb' }));\n server.use(express.urlencoded({ extended: false }));\n server.use(cookieParser());\n server.use(requestIp.mw());\n\n server.use(csrf({ cookie: true }));\n\n loggerMiddleware.token('ip', (req) => req.clientIp);\n const FORMAT = ':ip > :status :method :url :response-time ms :res[content-length] :referrer :user-agent';\n server.use(loggerMiddleware(FORMAT, {\n stream: {\n write: options.logger.info.bind(options.logger),\n },\n }));\n\n // Note: no matter the \"public path\", we want the service worker, if any,\n // to be served from the root, to have all web app pages in its scope.\n // Thus, this setup to serve it. Probably, need some more configuration\n // for special cases, but this will do for now.\n server.get('/__service-worker.js', express.static(\n webpackConfig.output.path,\n {\n setHeaders: (res) => res.set('Cache-Control', 'no-cache'),\n },\n ));\n\n /* Setup of Hot Module Reloading for development environment.\n * These dependencies are not used, nor installed for production use,\n * hence we should violate some import-related lint rules. */\n /* eslint-disable global-require */\n /* eslint-disable import/no-extraneous-dependencies */\n /* eslint-disable import/no-unresolved */\n if (options.devMode) {\n // This is a workaround for SASS bug:\n // https://github.com/dart-lang/sdk/issues/27979\n // which manifests itself sometimes when webpack dev middleware is used\n // (in dev mode), and app modules are imported in some unfortunate ways.\n if (!global.location) {\n global.location = {\n href: `${pathToFileURL(process.cwd()).href}${sep}`,\n };\n }\n\n const webpack = require('webpack');\n const webpackDevMiddleware = require('webpack-dev-middleware');\n const webpackHotMiddleware = require('webpack-hot-middleware');\n const compiler = webpack(webpackConfig);\n server.use(webpackDevMiddleware(compiler, {\n publicPath,\n serverSideRender: true,\n }));\n server.use(webpackHotMiddleware(compiler));\n }\n /* eslint-enable global-require */\n /* eslint-enable import/no-extraneous-dependencies */\n /* eslint-enable import/no-unresolved */\n\n server.use(publicPath, express.static(webpackConfig.output.path));\n\n if (options.onExpressJsSetup) {\n await options.onExpressJsSetup(server);\n }\n server.use(renderer);\n\n /* Detects 404 errors, and forwards them to the error handler. */\n server.use((req, res, next) => {\n next(newError(ERRORS.NOT_FOUND, CODES.NOT_FOUND));\n });\n\n let dontAttachDefaultErrorHandler;\n if (options.beforeExpressJsError) {\n dontAttachDefaultErrorHandler = await options.beforeExpressJsError(server);\n }\n\n /* Error handler. */\n if (!dontAttachDefaultErrorHandler) {\n // TODO: Do we need this error handler at all? It actually seems to do\n // what the default ExpressJS error handler does anyway, see:\n // https://expressjs.com/en/guide/error-handling.html\n //\n // TODO: It is better to move the default error handler definition\n // to a stand-alone function at top-level, but the use of options.logger\n // prevents to do it without some extra refactoring. Should be done sometime\n // though.\n server.use((error, req, res, next) => {\n // TODO: This is needed to correctly handled any errors thrown after\n // sending initial response to the client.\n if (res.headersSent) return next(error);\n\n const status = error.status || CODES.INTERNAL_SERVER_ERROR;\n const serverSide = status >= CODES.INTERNAL_SERVER_ERROR;\n\n // Log server-side errors always, client-side at debug level only.\n options.logger.log(serverSide ? 'error' : 'debug', error);\n\n let message = error.message || getErrorForCode(status);\n if (serverSide && process.env.NODE_ENV === 'production') {\n message = ERRORS.INTERNAL_SERVER_ERROR;\n }\n\n res.status(status).send(message);\n return undefined;\n });\n }\n\n return server;\n}\n"],"mappings":";;;;;;;;AAIA;AACA;AAEA;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AAzBA;AACA;AACA;;AA8BA;AACA;AACA;AACA;AACA,MAAMA,kBAAkB,GAAG;EACzBC,UAAU,EAAE,IAAAC,iBAAS,EACnBC,eAAM,CAACC,qBAAqB,CAACC,oBAAoB,EAAE;EAEnD;EACA;EACA;EACA;EACCC,KAAK,IAAKA,KAAK,CAACC,MAAM,CAAEC,IAAI,IAAKA,IAAI,KAAK,QAAQ,CAAC;AAExD,CAAC;AACDR,kBAAkB,CAACC,UAAU,CAAC,WAAW,CAAC,GAAG,CAC3C,QAAQ;AAER;AACA;AACA,uBAAuB,CACxB;AACDD,kBAAkB,CAACC,UAAU,CAAC,YAAY,CAAC,CAACQ,IAAI,CAAC,eAAe,CAAC;;AAEjE;AACA;AACA;AACA,OAAOT,kBAAkB,CAACC,UAAU,CAAC,2BAA2B,CAAC;;AAEjE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASS,qBAAqB,GAAG;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ACM,qBAAqB;;MAExD;MACAhF,OAAO,CAACU,MAAM,CAACwE,GAAG,CAACD,UAAU,GAAG,OAAO,GAAG,OAAO,EAAEJ,KAAK,CAAC;MAEzD,IAAIM,OAAO,GAAGN,KAAK,CAACM,OAAO,IAAI,IAAAC,uBAAe,EAACL,MAAM,CAAC;MACtD,IAAIE,UAAU,IAAIpB,OAAO,CAACwB,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;QACvDH,OAAO,GAAGX,cAAM,CAACQ,qBAAqB;MACxC;MAEAlE,GAAG,CAACiE,MAAM,CAACA,MAAM,CAAC,CAAC9C,IAAI,CAACkD,OAAO,CAAC;MAChC,OAAOI,SAAS;IAClB,CAAC,CAAC;EACJ;EAEA,OAAOhF,MAAM;AACf"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -32,11 +31,8 @@ Object.defineProperty(exports, "joi", {
|
|
|
32
31
|
}
|
|
33
32
|
});
|
|
34
33
|
exports.newError = newError;
|
|
35
|
-
|
|
36
34
|
var _httpStatusCodes = require("http-status-codes");
|
|
37
|
-
|
|
38
35
|
var _joi = _interopRequireDefault(require("joi"));
|
|
39
|
-
|
|
40
36
|
/**
|
|
41
37
|
* @category Utilities
|
|
42
38
|
* @module server/errors
|
|
@@ -116,6 +112,7 @@ function newError(message, statusCode = _httpStatusCodes.StatusCodes.INTERNAL_SE
|
|
|
116
112
|
error.status = statusCode;
|
|
117
113
|
return error;
|
|
118
114
|
}
|
|
115
|
+
|
|
119
116
|
/**
|
|
120
117
|
* ```js
|
|
121
118
|
* import { server } from '@dr.pogodin/react-utils';
|
|
@@ -127,11 +124,10 @@ function newError(message, statusCode = _httpStatusCodes.StatusCodes.INTERNAL_SE
|
|
|
127
124
|
* Server Error).
|
|
128
125
|
* @throws {Error}
|
|
129
126
|
*/
|
|
130
|
-
|
|
131
|
-
|
|
132
127
|
function fail(message, statusCode = _httpStatusCodes.StatusCodes.INTERNAL_SERVER_ERROR) {
|
|
133
128
|
throw newError(message, statusCode);
|
|
134
129
|
}
|
|
130
|
+
|
|
135
131
|
/**
|
|
136
132
|
* ```js
|
|
137
133
|
* import { server } from '@dr.pogodin/react-utils';
|
|
@@ -146,15 +142,12 @@ function fail(message, statusCode = _httpStatusCodes.StatusCodes.INTERNAL_SERVER
|
|
|
146
142
|
* Request).
|
|
147
143
|
* @throws {Error}
|
|
148
144
|
*/
|
|
149
|
-
|
|
150
|
-
|
|
151
145
|
function assert(value, schema, message = '', statusCode = _httpStatusCodes.StatusCodes.BAD_REQUEST) {
|
|
152
146
|
const {
|
|
153
147
|
error
|
|
154
148
|
} = schema.validate(value, {
|
|
155
149
|
abortEarly: false
|
|
156
150
|
});
|
|
157
|
-
|
|
158
151
|
if (error) {
|
|
159
152
|
fail(message.concat(message ? '\n' : '', error.message), statusCode);
|
|
160
153
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":["newError","message","statusCode","CODES","INTERNAL_SERVER_ERROR","error","Error","status","fail","assert","value","schema","BAD_REQUEST","validate","abortEarly","concat"],"sources":["../../../../src/server/utils/errors.js"],"sourcesContent":["/**\n * @category Utilities\n * @module server/errors\n * @desc\n * ```js\n * import { server } from '@dr.pogodin/react-utils';\n * const { errors } = server;\n * ```\n * Server-side helpers for error handling.\n */\n\nimport {\n StatusCodes as CODES,\n ReasonPhrases as ERRORS,\n getReasonPhrase as getErrorForCode,\n} from 'http-status-codes';\n\nimport joi from 'joi';\n\n/**\n * @static\n * @const CODES\n * @desc An alias for\n * [StatusCodes object from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).\n * It is a map between HTTP status code names and corresponding numeric codes.\n * @example\n * import { server } from '@dr.pogodin/react-utils';\n * const { CODES } = server.errors;\n * console.log(CODES.BAD_REQUEST); // Prints: 400\n */\nexport { CODES };\n\n/**\n * @static\n * @const ERRORS\n * @desc An alias for\n * [ReasonPhrases object from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).\n * It is a map between HTTP status code names and their pretty-printed forms.\n * @example\n * import { server } from '@dr.pogodin/react-utils';\n * const { ERRORS } = server.errors;\n * console.log(ERRORS.BAD_REQUEST); // Prints: Bad Request\n */\nexport { ERRORS };\n\n/**\n * @static\n * @func getErrorForCode\n * @desc An alias for\n * [getReasonPhrase() function from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).\n * Given an HTTP code it returns the corresponding error text.\n * @param {number} code HTTP code.\n * @return {string} HTTP error text.\n * @example\n * import { server } from '@dr.pogodin/react-utils';\n * console.log(server.errors.getErrorForCode(400)); // Prints: Bad Request\n */\nexport { getErrorForCode };\n\n/**\n * @static\n * @const joi\n * @desc An alias for [Joi library](https://joi.dev/api/?v=17.4.0),\n * which provides tooling for HTTP request validation. You can use it in any\n * way you would use that library import.\n * @example\n * import { server } from '@dr.pogodin/react-utils';\n * const { joi } = server.errors;\n * const requestBodySchema = joi.object({\n * sampleKey: joi.string().max(16).required(),\n * });\n */\nexport { joi };\n\n/**\n * ```js\n * import { server } from '@dr.pogodin/react-utils';\n * const { newError } = server.errors;\n * ```\n * Creates a new `Error` object with given message, and HTTP status code\n * attached as `status` field.\n * @param {string} message Error message.\n * @param {number} [statusCode=500] HTTP status code. Defaults to 500 (Internal\n * Server Error).\n * @return {Error}\n */\nexport function newError(message, statusCode = CODES.INTERNAL_SERVER_ERROR) {\n const error = new Error(message);\n error.status = statusCode;\n return error;\n}\n\n/**\n * ```js\n * import { server } from '@dr.pogodin/react-utils';\n * const { fail } = server.errors;\n * ```\n * Throws an error with given message and HTTP status code.\n * @param {string} message Error message.\n * @param {number} [statusCode=500] HTTP error code. Defaults to 500 (Internal\n * Server Error).\n * @throws {Error}\n */\nexport function fail(message, statusCode = CODES.INTERNAL_SERVER_ERROR) {\n throw newError(message, statusCode);\n}\n\n/**\n * ```js\n * import { server } from '@dr.pogodin/react-utils';\n * const { assert } = server.errors;\n * ```\n * Validates a value using given Joi schema, and throws an error with given\n * message and HTTP status code in case of the validation failure.\n * @param {any} value\n * @param {object} schema\n * @param {string} [message] Error message.\n * @param {number} [statusCode=500] HTTP status code. Defaults to 400 (Bad\n * Request).\n * @throws {Error}\n */\nexport function assert(\n value,\n schema,\n message = '',\n statusCode = CODES.BAD_REQUEST,\n) {\n const { error } = schema.validate(value, { abortEarly: false });\n if (error) {\n fail(message.concat(message ? '\\n' : '', error.message), statusCode);\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.js","names":["newError","message","statusCode","CODES","INTERNAL_SERVER_ERROR","error","Error","status","fail","assert","value","schema","BAD_REQUEST","validate","abortEarly","concat"],"sources":["../../../../src/server/utils/errors.js"],"sourcesContent":["/**\n * @category Utilities\n * @module server/errors\n * @desc\n * ```js\n * import { server } from '@dr.pogodin/react-utils';\n * const { errors } = server;\n * ```\n * Server-side helpers for error handling.\n */\n\nimport {\n StatusCodes as CODES,\n ReasonPhrases as ERRORS,\n getReasonPhrase as getErrorForCode,\n} from 'http-status-codes';\n\nimport joi from 'joi';\n\n/**\n * @static\n * @const CODES\n * @desc An alias for\n * [StatusCodes object from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).\n * It is a map between HTTP status code names and corresponding numeric codes.\n * @example\n * import { server } from '@dr.pogodin/react-utils';\n * const { CODES } = server.errors;\n * console.log(CODES.BAD_REQUEST); // Prints: 400\n */\nexport { CODES };\n\n/**\n * @static\n * @const ERRORS\n * @desc An alias for\n * [ReasonPhrases object from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).\n * It is a map between HTTP status code names and their pretty-printed forms.\n * @example\n * import { server } from '@dr.pogodin/react-utils';\n * const { ERRORS } = server.errors;\n * console.log(ERRORS.BAD_REQUEST); // Prints: Bad Request\n */\nexport { ERRORS };\n\n/**\n * @static\n * @func getErrorForCode\n * @desc An alias for\n * [getReasonPhrase() function from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).\n * Given an HTTP code it returns the corresponding error text.\n * @param {number} code HTTP code.\n * @return {string} HTTP error text.\n * @example\n * import { server } from '@dr.pogodin/react-utils';\n * console.log(server.errors.getErrorForCode(400)); // Prints: Bad Request\n */\nexport { getErrorForCode };\n\n/**\n * @static\n * @const joi\n * @desc An alias for [Joi library](https://joi.dev/api/?v=17.4.0),\n * which provides tooling for HTTP request validation. You can use it in any\n * way you would use that library import.\n * @example\n * import { server } from '@dr.pogodin/react-utils';\n * const { joi } = server.errors;\n * const requestBodySchema = joi.object({\n * sampleKey: joi.string().max(16).required(),\n * });\n */\nexport { joi };\n\n/**\n * ```js\n * import { server } from '@dr.pogodin/react-utils';\n * const { newError } = server.errors;\n * ```\n * Creates a new `Error` object with given message, and HTTP status code\n * attached as `status` field.\n * @param {string} message Error message.\n * @param {number} [statusCode=500] HTTP status code. Defaults to 500 (Internal\n * Server Error).\n * @return {Error}\n */\nexport function newError(message, statusCode = CODES.INTERNAL_SERVER_ERROR) {\n const error = new Error(message);\n error.status = statusCode;\n return error;\n}\n\n/**\n * ```js\n * import { server } from '@dr.pogodin/react-utils';\n * const { fail } = server.errors;\n * ```\n * Throws an error with given message and HTTP status code.\n * @param {string} message Error message.\n * @param {number} [statusCode=500] HTTP error code. Defaults to 500 (Internal\n * Server Error).\n * @throws {Error}\n */\nexport function fail(message, statusCode = CODES.INTERNAL_SERVER_ERROR) {\n throw newError(message, statusCode);\n}\n\n/**\n * ```js\n * import { server } from '@dr.pogodin/react-utils';\n * const { assert } = server.errors;\n * ```\n * Validates a value using given Joi schema, and throws an error with given\n * message and HTTP status code in case of the validation failure.\n * @param {any} value\n * @param {object} schema\n * @param {string} [message] Error message.\n * @param {number} [statusCode=500] HTTP status code. Defaults to 400 (Bad\n * Request).\n * @throws {Error}\n */\nexport function assert(\n value,\n schema,\n message = '',\n statusCode = CODES.BAD_REQUEST,\n) {\n const { error } = schema.validate(value, { abortEarly: false });\n if (error) {\n fail(message.concat(message ? '\\n' : '', error.message), statusCode);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA;AAMA;AAjBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,QAAQ,CAACC,OAAO,EAAEC,UAAU,GAAGC,4BAAK,CAACC,qBAAqB,EAAE;EAC1E,MAAMC,KAAK,GAAG,IAAIC,KAAK,CAACL,OAAO,CAAC;EAChCI,KAAK,CAACE,MAAM,GAAGL,UAAU;EACzB,OAAOG,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,IAAI,CAACP,OAAO,EAAEC,UAAU,GAAGC,4BAAK,CAACC,qBAAqB,EAAE;EACtE,MAAMJ,QAAQ,CAACC,OAAO,EAAEC,UAAU,CAAC;AACrC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASO,MAAM,CACpBC,KAAK,EACLC,MAAM,EACNV,OAAO,GAAG,EAAE,EACZC,UAAU,GAAGC,4BAAK,CAACS,WAAW,EAC9B;EACA,MAAM;IAAEP;EAAM,CAAC,GAAGM,MAAM,CAACE,QAAQ,CAACH,KAAK,EAAE;IAAEI,UAAU,EAAE;EAAM,CAAC,CAAC;EAC/D,IAAIT,KAAK,EAAE;IACTG,IAAI,CAACP,OAAO,CAACc,MAAM,CAACd,OAAO,GAAG,IAAI,GAAG,EAAE,EAAEI,KAAK,CAACJ,OAAO,CAAC,EAAEC,UAAU,CAAC;EACtE;AACF"}
|
|
@@ -4,12 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.errors = void 0;
|
|
7
|
-
|
|
8
7
|
var _errors = _interopRequireWildcard(require("./errors"));
|
|
9
|
-
|
|
10
8
|
exports.errors = _errors;
|
|
11
|
-
|
|
12
9
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
-
|
|
14
10
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
9
|
var _Link = _interopRequireDefault(require("../Link"));
|
|
13
|
-
|
|
14
10
|
var _utils = require("../../utils");
|
|
15
|
-
|
|
16
11
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
17
|
-
|
|
18
12
|
// The <Button> component implements a standard button / button-like link.
|
|
19
13
|
const defaultTheme = {
|
|
20
14
|
"context": "-dr-pogodin-react-utils___src-shared-components-Button-style___context___KM0v4f",
|
|
@@ -24,7 +18,6 @@ const defaultTheme = {
|
|
|
24
18
|
"active": "-dr-pogodin-react-utils___src-shared-components-Button-style___active___MAe9O6",
|
|
25
19
|
"disabled": "-dr-pogodin-react-utils___src-shared-components-Button-style___disabled___Br9IWV"
|
|
26
20
|
};
|
|
27
|
-
|
|
28
21
|
function BaseButton({
|
|
29
22
|
active,
|
|
30
23
|
children,
|
|
@@ -39,7 +32,6 @@ function BaseButton({
|
|
|
39
32
|
}) {
|
|
40
33
|
let className = theme.button;
|
|
41
34
|
if (active && theme.active) className += ` ${theme.active}`;
|
|
42
|
-
|
|
43
35
|
if (disabled) {
|
|
44
36
|
if (theme.disabled) className += ` ${theme.disabled}`;
|
|
45
37
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
@@ -47,7 +39,6 @@ function BaseButton({
|
|
|
47
39
|
children: children
|
|
48
40
|
});
|
|
49
41
|
}
|
|
50
|
-
|
|
51
42
|
if (to) {
|
|
52
43
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Link.default, {
|
|
53
44
|
className: className,
|
|
@@ -60,7 +51,6 @@ function BaseButton({
|
|
|
60
51
|
children: children
|
|
61
52
|
});
|
|
62
53
|
}
|
|
63
|
-
|
|
64
54
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
65
55
|
className: className,
|
|
66
56
|
onClick: onClick,
|
|
@@ -71,6 +61,7 @@ function BaseButton({
|
|
|
71
61
|
children: children
|
|
72
62
|
});
|
|
73
63
|
}
|
|
64
|
+
|
|
74
65
|
/**
|
|
75
66
|
* Button component theme: a map of CSS
|
|
76
67
|
* class names to append to button elements:
|
|
@@ -78,9 +69,8 @@ function BaseButton({
|
|
|
78
69
|
* @prop {string} [button] to the root element of any button.
|
|
79
70
|
* @prop {string} [disabled] to the root element of disabled button.
|
|
80
71
|
*/
|
|
81
|
-
|
|
82
|
-
|
|
83
72
|
const ThemedButton = (0, _utils.themed)('Button', ['active', 'button', 'disabled'], defaultTheme)(BaseButton);
|
|
73
|
+
|
|
84
74
|
/**
|
|
85
75
|
* Implements themeable buttons, and button-line links (elements which look
|
|
86
76
|
* like buttons, but behave as links) in the same uniform manner.
|
|
@@ -107,7 +97,6 @@ const ThemedButton = (0, _utils.themed)('Button', ['active', 'button', 'disabled
|
|
|
107
97
|
* @param {...any} [props....]
|
|
108
98
|
* [Other properties of themeable components](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)
|
|
109
99
|
*/
|
|
110
|
-
|
|
111
100
|
BaseButton.defaultProps = {
|
|
112
101
|
active: false,
|
|
113
102
|
children: undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["BaseButton","active","children","disabled","enforceA","onClick","onMouseDown","openNewTab","replace","theme","to","className","button","ThemedButton","themed","defaultTheme","defaultProps","undefined","propTypes","PT","bool","node","func","themeType","isRequired","oneOfType","object","string"],"sources":["../../../../../src/shared/components/Button/index.jsx"],"sourcesContent":["// The <Button> component implements a standard button / button-like link.\n\nimport PT from 'prop-types';\n\nimport Link from 'components/Link';\n\nimport { themed } from 'utils';\n\nimport defaultTheme from './style.scss';\n\nfunction BaseButton({\n active,\n children,\n disabled,\n enforceA,\n onClick,\n onMouseDown,\n openNewTab,\n replace,\n theme,\n to,\n}) {\n let className = theme.button;\n if (active && theme.active) className += ` ${theme.active}`;\n if (disabled) {\n if (theme.disabled) className += ` ${theme.disabled}`;\n return (\n <div className={className}>\n {children}\n </div>\n );\n }\n if (to) {\n return (\n <Link\n className={className}\n enforceA={enforceA}\n onClick={onClick}\n onMouseDown={onMouseDown}\n openNewTab={openNewTab}\n replace={replace}\n to={to}\n >\n {children}\n </Link>\n );\n }\n return (\n <div\n className={className}\n onClick={onClick}\n onKeyPress={onClick}\n onMouseDown={onMouseDown}\n role=\"button\"\n tabIndex={0}\n >\n {children}\n </div>\n );\n}\n\n/**\n * Button component theme: a map of CSS\n * class names to append to button elements:\n * @prop {string} [active] to the root element of active button.\n * @prop {string} [button] to the root element of any button.\n * @prop {string} [disabled] to the root element of disabled button.\n */\nconst ThemedButton = themed('Button', [\n 'active',\n 'button',\n 'disabled',\n], defaultTheme)(BaseButton);\n\n/**\n * Implements themeable buttons, and button-line links (elements which look\n * like buttons, but behave as links) in the same uniform manner.\n * @param {object} [props] Component props.\n * @param {boolean} [props.active] Set `true` to render the button as\n * active, even if it is not active otherwise.\n * @param {boolean} [props.disabled] Set `true` to disable the button.\n * @param {boolean} [props.enforceA] When the button is rendered as `<Link>`\n * component, this prop enforces it to be rendered as a simple `<a>` element\n * (external link), rather than the React router's internal link.\n * See `<Link>` documentation to learn when links are rendered as `<a>`\n * by default.\n * @param {function} [props.onClick] Click event handler.\n * @param {function} [props.onMouseDown] Mouse down event handler.\n * @param {boolean} [props.openNewTab] Set `true` to open link in the new tab.\n * @param {boolean} [props.replace] When the button is rendered as\n * `<Link>`, and the target URL is internal, this property tells that\n * the new route should replace the last record in the browser's history,\n * rather than to be pushed as a new entry into the history stack.\n * @param {ButtonTheme} [props.theme] _Ad hoc_ button theme.\n * @param {object|string} [props.to] If specified, the button will be rendered\n * as `<Link>` (if not disabled), and it will point to the specified location\n * or URL.\n * @param {...any} [props....]\n * [Other properties of themeable components](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)\n */\nBaseButton.defaultProps = {\n active: false,\n children: undefined,\n disabled: false,\n enforceA: false,\n onClick: undefined,\n onMouseDown: undefined,\n openNewTab: false,\n replace: false,\n to: undefined,\n};\n\nBaseButton.propTypes = {\n active: PT.bool,\n children: PT.node,\n disabled: PT.bool,\n enforceA: PT.bool,\n onClick: PT.func,\n onMouseDown: PT.func,\n openNewTab: PT.bool,\n replace: PT.bool,\n theme: ThemedButton.themeType.isRequired,\n to: PT.oneOfType([PT.object, PT.string]),\n};\n\nexport default ThemedButton;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["BaseButton","active","children","disabled","enforceA","onClick","onMouseDown","openNewTab","replace","theme","to","className","button","ThemedButton","themed","defaultTheme","defaultProps","undefined","propTypes","PT","bool","node","func","themeType","isRequired","oneOfType","object","string"],"sources":["../../../../../src/shared/components/Button/index.jsx"],"sourcesContent":["// The <Button> component implements a standard button / button-like link.\n\nimport PT from 'prop-types';\n\nimport Link from 'components/Link';\n\nimport { themed } from 'utils';\n\nimport defaultTheme from './style.scss';\n\nfunction BaseButton({\n active,\n children,\n disabled,\n enforceA,\n onClick,\n onMouseDown,\n openNewTab,\n replace,\n theme,\n to,\n}) {\n let className = theme.button;\n if (active && theme.active) className += ` ${theme.active}`;\n if (disabled) {\n if (theme.disabled) className += ` ${theme.disabled}`;\n return (\n <div className={className}>\n {children}\n </div>\n );\n }\n if (to) {\n return (\n <Link\n className={className}\n enforceA={enforceA}\n onClick={onClick}\n onMouseDown={onMouseDown}\n openNewTab={openNewTab}\n replace={replace}\n to={to}\n >\n {children}\n </Link>\n );\n }\n return (\n <div\n className={className}\n onClick={onClick}\n onKeyPress={onClick}\n onMouseDown={onMouseDown}\n role=\"button\"\n tabIndex={0}\n >\n {children}\n </div>\n );\n}\n\n/**\n * Button component theme: a map of CSS\n * class names to append to button elements:\n * @prop {string} [active] to the root element of active button.\n * @prop {string} [button] to the root element of any button.\n * @prop {string} [disabled] to the root element of disabled button.\n */\nconst ThemedButton = themed('Button', [\n 'active',\n 'button',\n 'disabled',\n], defaultTheme)(BaseButton);\n\n/**\n * Implements themeable buttons, and button-line links (elements which look\n * like buttons, but behave as links) in the same uniform manner.\n * @param {object} [props] Component props.\n * @param {boolean} [props.active] Set `true` to render the button as\n * active, even if it is not active otherwise.\n * @param {boolean} [props.disabled] Set `true` to disable the button.\n * @param {boolean} [props.enforceA] When the button is rendered as `<Link>`\n * component, this prop enforces it to be rendered as a simple `<a>` element\n * (external link), rather than the React router's internal link.\n * See `<Link>` documentation to learn when links are rendered as `<a>`\n * by default.\n * @param {function} [props.onClick] Click event handler.\n * @param {function} [props.onMouseDown] Mouse down event handler.\n * @param {boolean} [props.openNewTab] Set `true` to open link in the new tab.\n * @param {boolean} [props.replace] When the button is rendered as\n * `<Link>`, and the target URL is internal, this property tells that\n * the new route should replace the last record in the browser's history,\n * rather than to be pushed as a new entry into the history stack.\n * @param {ButtonTheme} [props.theme] _Ad hoc_ button theme.\n * @param {object|string} [props.to] If specified, the button will be rendered\n * as `<Link>` (if not disabled), and it will point to the specified location\n * or URL.\n * @param {...any} [props....]\n * [Other properties of themeable components](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)\n */\nBaseButton.defaultProps = {\n active: false,\n children: undefined,\n disabled: false,\n enforceA: false,\n onClick: undefined,\n onMouseDown: undefined,\n openNewTab: false,\n replace: false,\n to: undefined,\n};\n\nBaseButton.propTypes = {\n active: PT.bool,\n children: PT.node,\n disabled: PT.bool,\n enforceA: PT.bool,\n onClick: PT.func,\n onMouseDown: PT.func,\n openNewTab: PT.bool,\n replace: PT.bool,\n theme: ThemedButton.themeType.isRequired,\n to: PT.oneOfType([PT.object, PT.string]),\n};\n\nexport default ThemedButton;\n"],"mappings":";;;;;;;AAEA;AAEA;AAEA;AAA+B;AAN/B;AAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAUA,SAASA,UAAU,CAAC;EAClBC,MAAM;EACNC,QAAQ;EACRC,QAAQ;EACRC,QAAQ;EACRC,OAAO;EACPC,WAAW;EACXC,UAAU;EACVC,OAAO;EACPC,KAAK;EACLC;AACF,CAAC,EAAE;EACD,IAAIC,SAAS,GAAGF,KAAK,CAAC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V,UAAU,EAAE,KAAK;EACjBC,OAAO,EAAE,KAAK;EACdE,EAAE,EAAEO;AACN,CAAC;AAEDjB,UAAU,CAACkB,SAAS,GAAG;EACrBjB,MAAM,EAAEkB,kBAAE,CAACC,IAAI;EACflB,QAAQ,EAAEiB,kBAAE,CAACE,IAAI;EACjBlB,QAAQ,EAAEgB,kBAAE,CAACC,IAAI;EACjBhB,QAAQ,EAAEe,kBAAE,CAACC,IAAI;EACjBf,OAAO,EAAEc,kBAAE,CAACG,IAAI;EAChBhB,WAAW,EAAEa,kBAAE,CAACG,IAAI;EACpBf,UAAU,EAAEY,kBAAE,CAACC,IAAI;EACnBZ,OAAO,EAAEW,kBAAE,CAACC,IAAI;EAChBX,KAAK,EAAEI,YAAY,CAACU,SAAS,CAACC,UAAU;EACxCd,EAAE,EAAES,kBAAE,CAACM,SAAS,CAAC,CAACN,kBAAE,CAACO,MAAM,EAAEP,kBAAE,CAACQ,MAAM,CAAC;AACzC,CAAC;AAAC,eAEad,YAAY;AAAA"}
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
9
|
var _utils = require("../../utils");
|
|
13
|
-
|
|
14
10
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
-
|
|
16
11
|
const defaultTheme = {
|
|
17
12
|
"context": "-dr-pogodin-react-utils___src-shared-components-Checkbox-theme___context___dNQcC6",
|
|
18
13
|
"ad": "-dr-pogodin-react-utils___src-shared-components-Checkbox-theme___ad___earXxa",
|
|
@@ -21,7 +16,6 @@ const defaultTheme = {
|
|
|
21
16
|
"container": "-dr-pogodin-react-utils___src-shared-components-Checkbox-theme___container___Kr0g3M",
|
|
22
17
|
"label": "-dr-pogodin-react-utils___src-shared-components-Checkbox-theme___label___3dML-O"
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
function Checkbox({
|
|
26
20
|
checked,
|
|
27
21
|
label,
|
|
@@ -41,6 +35,7 @@ function Checkbox({
|
|
|
41
35
|
})]
|
|
42
36
|
});
|
|
43
37
|
}
|
|
38
|
+
|
|
44
39
|
/**
|
|
45
40
|
* Checkbox component theme: a map of
|
|
46
41
|
* CSS classes to append to its elements:
|
|
@@ -48,9 +43,8 @@ function Checkbox({
|
|
|
48
43
|
* @prop {string} [container] to the root checkbox element.
|
|
49
44
|
* @prop {string} [label] to the checkbox label element.
|
|
50
45
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
46
|
const ThemedCheckbox = (0, _utils.themed)('Checkbox', ['checkbox', 'container', 'label'], defaultTheme)(Checkbox);
|
|
47
|
+
|
|
54
48
|
/**
|
|
55
49
|
* The `<Checkbox>` component implements themeable checkboxes.
|
|
56
50
|
* @param {object} [props] Component properties.
|
|
@@ -61,7 +55,6 @@ const ThemedCheckbox = (0, _utils.themed)('Checkbox', ['checkbox', 'container',
|
|
|
61
55
|
* @param {...any} [props....]
|
|
62
56
|
* [Other properties of themeable components](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties).
|
|
63
57
|
*/
|
|
64
|
-
|
|
65
58
|
Checkbox.propTypes = {
|
|
66
59
|
checked: _propTypes.default.bool,
|
|
67
60
|
label: _propTypes.default.string,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Checkbox","checked","label","onChange","theme","container","undefined","checkbox","ThemedCheckbox","themed","defaultTheme","propTypes","PT","bool","string","func","themeType","isRequired","defaultProps"],"sources":["../../../../../src/shared/components/Checkbox/index.jsx"],"sourcesContent":["import PT from 'prop-types';\n\nimport { themed } from 'utils';\n\nimport defaultTheme from './theme.scss';\n\nfunction Checkbox({\n checked,\n label,\n onChange,\n theme,\n}) {\n return (\n <div className={theme.container}>\n { label === undefined ? null : <p className={theme.label}>{label}</p> }\n <input\n checked={checked}\n className={theme.checkbox}\n onChange={onChange}\n type=\"checkbox\"\n />\n </div>\n );\n}\n\n/**\n * Checkbox component theme: a map of\n * CSS classes to append to its elements:\n * @prop {string} [checkbox] to the underlying checkbox `<input>` element.\n * @prop {string} [container] to the root checkbox element.\n * @prop {string} [label] to the checkbox label element.\n */\nconst ThemedCheckbox = themed('Checkbox', [\n 'checkbox',\n 'container',\n 'label',\n], defaultTheme)(Checkbox);\n\n/**\n * The `<Checkbox>` component implements themeable checkboxes.\n * @param {object} [props] Component properties.\n * @param {boolean} [props.checked] Checkbox value.\n * @param {string} [props.label] Checkbox label.\n * @param {function} [props.onChange] State change handler.\n * @param {CheckboxTheme} [props.theme] _Ad hoc_ theme.\n * @param {...any} [props....]\n * [Other properties of themeable components](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties).\n */\nCheckbox.propTypes = {\n checked: PT.bool,\n label: PT.string,\n onChange: PT.func,\n theme: ThemedCheckbox.themeType.isRequired,\n};\n\nCheckbox.defaultProps = {\n checked: undefined,\n label: undefined,\n onChange: undefined,\n};\n\nexport default ThemedCheckbox;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["Checkbox","checked","label","onChange","theme","container","undefined","checkbox","ThemedCheckbox","themed","defaultTheme","propTypes","PT","bool","string","func","themeType","isRequired","defaultProps"],"sources":["../../../../../src/shared/components/Checkbox/index.jsx"],"sourcesContent":["import PT from 'prop-types';\n\nimport { themed } from 'utils';\n\nimport defaultTheme from './theme.scss';\n\nfunction Checkbox({\n checked,\n label,\n onChange,\n theme,\n}) {\n return (\n <div className={theme.container}>\n { label === undefined ? null : <p className={theme.label}>{label}</p> }\n <input\n checked={checked}\n className={theme.checkbox}\n onChange={onChange}\n type=\"checkbox\"\n />\n </div>\n );\n}\n\n/**\n * Checkbox component theme: a map of\n * CSS classes to append to its elements:\n * @prop {string} [checkbox] to the underlying checkbox `<input>` element.\n * @prop {string} [container] to the root checkbox element.\n * @prop {string} [label] to the checkbox label element.\n */\nconst ThemedCheckbox = themed('Checkbox', [\n 'checkbox',\n 'container',\n 'label',\n], defaultTheme)(Checkbox);\n\n/**\n * The `<Checkbox>` component implements themeable checkboxes.\n * @param {object} [props] Component properties.\n * @param {boolean} [props.checked] Checkbox value.\n * @param {string} [props.label] Checkbox label.\n * @param {function} [props.onChange] State change handler.\n * @param {CheckboxTheme} [props.theme] _Ad hoc_ theme.\n * @param {...any} [props....]\n * [Other properties of themeable components](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties).\n */\nCheckbox.propTypes = {\n checked: PT.bool,\n label: PT.string,\n onChange: PT.func,\n theme: ThemedCheckbox.themeType.isRequired,\n};\n\nCheckbox.defaultProps = {\n checked: undefined,\n label: undefined,\n onChange: undefined,\n};\n\nexport default ThemedCheckbox;\n"],"mappings":";;;;;;;AAAA;AAEA;AAA+B;AAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAI/B,SAASA,QAAQ,CAAC;EAChBC,OAAO;EACPC,KAAK;EACLC,QAAQ;EACRC;AACF,CAAC,EAAE;EACD,oBACE;IAAK,SAAS,EAAEA,KAAK,CAACC,SAAU;IAAA,WAC5BH,KAAK,KAAKI,SAAS,GAAG,IAAI,gBAAG;MAAG,SAAS,EAAEF,KAAK,CAACF,KAAM;MAAA,UAAEA;IAAK,EAAK,eACrE;MACE,OAAO,EAAED,OAAQ;MACjB,SAAS,EAAEG,KAAK,CAACG,QAAS;MAC1B,QAAQ,EAAEJ,QAAS;MACnB,IAAI,EAAC;IAAU,EACf;EAAA,EACE;AAEV;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMK,cAAc,GAAG,IAAAC,aAAM,EAAC,UAAU,EAAE,CACxC,UAAU,EACV,WAAW,EACX,OAAO,CACR,EAAEC,YAAY,CAAC,CAACV,QAAQ,CAAC;;AAE1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACAA,QAAQ,CAACW,SAAS,GAAG;EACnBV,OAAO,EAAEW,kBAAE,CAACC,IAAI;EAChBX,KAAK,EAAEU,kBAAE,CAACE,MAAM;EAChBX,QAAQ,EAAES,kBAAE,CAACG,IAAI;EACjBX,KAAK,EAAEI,cAAc,CAACQ,SAAS,CAACC;AAClC,CAAC;AAEDjB,QAAQ,CAACkB,YAAY,GAAG;EACtBjB,OAAO,EAAEK,SAAS;EAClBJ,KAAK,EAAEI,SAAS;EAChBH,QAAQ,EAAEG;AACZ,CAAC;AAAC,eAEaE,cAAc;AAAA"}
|