@mjhls/mjh-framework 1.0.844-beta.0 → 1.0.844-beta.1

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.
Files changed (51) hide show
  1. package/dist/cjs/AdSlotsProvider.js +2 -895
  2. package/dist/cjs/AlgoliaSearch.js +336 -237
  3. package/dist/cjs/ArticleProgramLandingPage.js +2 -3
  4. package/dist/cjs/ArticleSeriesLandingPage.js +1 -1
  5. package/dist/cjs/ArticleSeriesListing.js +1 -1
  6. package/dist/cjs/DeckContent.js +1 -1
  7. package/dist/cjs/DeckQueue.js +1 -1
  8. package/dist/cjs/ExternalResources.js +2 -3
  9. package/dist/cjs/GridContent.js +1 -1
  10. package/dist/cjs/HorizontalArticleListing.js +2 -3
  11. package/dist/cjs/IssueLanding.js +2 -3
  12. package/dist/cjs/MasterDeck.js +1 -1
  13. package/dist/cjs/MediaSeriesLanding.js +5 -6
  14. package/dist/cjs/PartnerDetailListing.js +6 -1105
  15. package/dist/cjs/TaxonomyDescription.js +2 -3
  16. package/dist/cjs/VideoProgramLandingPage.js +2 -3
  17. package/dist/cjs/VideoSeriesCard.js +2 -2
  18. package/dist/cjs/VideoSeriesLandingPage.js +3 -3
  19. package/dist/cjs/VideoSeriesListing.js +1 -1
  20. package/dist/cjs/View.js +4 -6
  21. package/dist/cjs/faundadb.js +321 -4
  22. package/dist/cjs/getRelatedArticle.js +20 -24
  23. package/dist/cjs/getSerializers.js +2 -3
  24. package/dist/cjs/{index-45f8b70b.js → index-a8b50ae3.js} +615 -27
  25. package/dist/cjs/index.js +4 -11
  26. package/dist/cjs/{inherits-452ff02c.js → inherits-9953db94.js} +4 -4
  27. package/dist/esm/AdSlotsProvider.js +6 -898
  28. package/dist/esm/AlgoliaSearch.js +100 -1
  29. package/dist/esm/ArticleProgramLandingPage.js +1 -2
  30. package/dist/esm/ExternalResources.js +1 -2
  31. package/dist/esm/HorizontalArticleListing.js +1 -2
  32. package/dist/esm/IssueLanding.js +1 -2
  33. package/dist/esm/MediaSeriesLanding.js +1 -2
  34. package/dist/esm/PartnerDetailListing.js +5 -1103
  35. package/dist/esm/TaxonomyDescription.js +1 -2
  36. package/dist/esm/VideoProgramLandingPage.js +1 -2
  37. package/dist/esm/View.js +1 -3
  38. package/dist/esm/faundadb.js +319 -2
  39. package/dist/esm/getRelatedArticle.js +20 -24
  40. package/dist/esm/getSerializers.js +1 -2
  41. package/dist/esm/{index-ea86ff20.js → index-1ecf523d.js} +603 -15
  42. package/dist/esm/index.js +3 -9
  43. package/package.json +6 -2
  44. package/dist/cjs/Auth.js +0 -3628
  45. package/dist/cjs/inherits-8d29278d.js +0 -110
  46. package/dist/cjs/md5-5039b1a6.js +0 -323
  47. package/dist/cjs/util-f2c1b65b.js +0 -576
  48. package/dist/esm/Auth.js +0 -3612
  49. package/dist/esm/inherits-77d5e4fc.js +0 -101
  50. package/dist/esm/md5-9be0e905.js +0 -321
  51. package/dist/esm/util-7700fc59.js +0 -574
package/dist/esm/Auth.js DELETED
@@ -1,3612 +0,0 @@
1
- import { a as commonjsGlobal } from './_commonjsHelpers-0c4b6f40.js';
2
- import './_to-object-a4107da3.js';
3
- import './es6.string.iterator-c990c18c.js';
4
- import './_library-528f1934.js';
5
- import './_iter-detect-5d49a330.js';
6
- import './core.get-iterator-method-e1de7503.js';
7
- import './_object-pie-33c40e79.js';
8
- import { _ as _extends } from './extends-6f2fcc99.js';
9
- import './web.dom.iterable-4439f05a.js';
10
- import React__default, { useEffect, useState } from 'react';
11
- import Router from 'next/router';
12
- import { _ as _slicedToArray, a as _getIterator } from './slicedToArray-641f241f.js';
13
- import { _ as _JSON$stringify } from './stringify-4330ccdc.js';
14
- import { a as _asyncToGenerator, r as regenerator } from './asyncToGenerator-fc1c2e29.js';
15
- import { Col, Form, Button, Spinner } from 'react-bootstrap';
16
- import { u as util } from './util-7700fc59.js';
17
- import useSWR from 'swr';
18
- import Local from 'passport-local';
19
- import mysql from 'mysql';
20
- import { m as md5 } from './md5-9be0e905.js';
21
-
22
- var returnFormField = function returnFormField(_ref) {
23
- var name = _ref.name,
24
- label = _ref.label,
25
- type = _ref.type,
26
- _ref$required = _ref.required,
27
- required = _ref$required === undefined ? false : _ref$required,
28
- _ref$readonly = _ref.readonly,
29
- readonly = _ref$readonly === undefined ? false : _ref$readonly,
30
- _ref$options = _ref.options,
31
- options = _ref$options === undefined ? null : _ref$options,
32
- _ref$groupType = _ref.groupType,
33
- groupType = _ref$groupType === undefined ? '' : _ref$groupType,
34
- _ref$errors = _ref.errors,
35
- errors = _ref$errors === undefined ? {} : _ref$errors,
36
- _ref$handleChanged = _ref.handleChanged,
37
- handleChanged = _ref$handleChanged === undefined ? null : _ref$handleChanged,
38
- _ref$default_value = _ref.default_value,
39
- default_value = _ref$default_value === undefined ? null : _ref$default_value;
40
-
41
- var opts = [];
42
- if (groupType) {
43
- opts['as'] = groupType;
44
- if (groupType === Col) {
45
- opts['xs'] = 12;
46
- opts['md'] = 6;
47
- }
48
- }
49
-
50
- if (handleChanged) {
51
- opts['onChange'] = handleChanged;
52
- }
53
-
54
- if (readonly) {
55
- opts['readOnly'] = readonly;
56
- }
57
-
58
- if (type == 'text' || type == 'email' || type == 'password' || type == 'number') {
59
- return React__default.createElement(
60
- Form.Group,
61
- _extends({}, opts, { controlId: name }),
62
- React__default.createElement(
63
- Form.Label,
64
- { kye: name + '_label' },
65
- label,
66
- required && React__default.createElement(
67
- 'span',
68
- { style: { color: 'red' } },
69
- '*'
70
- )
71
- ),
72
- React__default.createElement(Form.Control, { key: name + '_' + type, type: type, readOnly: readonly, name: name, placeholder: '', defaultValue: default_value, required: required }),
73
- React__default.createElement(
74
- Form.Control.Feedback,
75
- { key: name + '_feedback', type: 'invalid' },
76
- errors[name]
77
- )
78
- );
79
- }
80
- if (type == 'select') {
81
- return React__default.createElement(
82
- Form.Group,
83
- _extends({}, opts, { key: name, controlId: name }),
84
- React__default.createElement(
85
- Form.Label,
86
- { key: name + '_' + label },
87
- label,
88
- required && React__default.createElement(
89
- 'span',
90
- { key: name + '_required_span', style: { color: 'red' } },
91
- '*'
92
- )
93
- ),
94
- React__default.createElement(
95
- Form.Control,
96
- { key: name + '_select', as: 'select', name: name, required: required, defaultValue: default_value },
97
- React__default.createElement('option', { value: '', key: name + '_options_empty' }),
98
- options.map(function (option, index) {
99
- var value = option.value ? option.value : option;
100
- var label = option.label ? option.label : option;
101
- var key = name + '_options_' + index;
102
- return React__default.createElement(
103
- 'option',
104
- { key: key, value: value },
105
- label
106
- );
107
- })
108
- )
109
- );
110
- }
111
-
112
- if (type == 'radio' || type == 'checkbox') {
113
- return React__default.createElement(
114
- Form.Group,
115
- opts,
116
- React__default.createElement(
117
- Form.Label,
118
- null,
119
- label,
120
- required && React__default.createElement(
121
- 'span',
122
- { style: { color: 'red' } },
123
- '*'
124
- )
125
- ),
126
- options.map(function (option, index) {
127
- return React__default.createElement(
128
- Form.Check,
129
- { type: type, key: index, required: required },
130
- React__default.createElement(Form.Check.Input, { type: type, key: type + '_' + index + '_input', defaultChecked: default_value ? default_value === option.value : false, name: name, id: name + '_' + index, value: option.value, required: required }),
131
- React__default.createElement(Form.Check.Label, { style: { cursor: 'pointer' }, 'for': name + '_' + index, key: type + '_' + index + '_label', dangerouslySetInnerHTML: { __html: option.label } })
132
- );
133
- })
134
- );
135
- }
136
- };
137
-
138
- var _this = undefined;
139
-
140
- var dataHandler = function () {
141
- var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(api_url, body) {
142
- var res, result;
143
- return regenerator.wrap(function _callee$(_context) {
144
- while (1) {
145
- switch (_context.prev = _context.next) {
146
- case 0:
147
- _context.prev = 0;
148
- _context.next = 3;
149
- return fetch(api_url, {
150
- method: 'POST',
151
- headers: { 'Content-Type': 'application/json' },
152
- body: _JSON$stringify(body)
153
- });
154
-
155
- case 3:
156
- res = _context.sent;
157
-
158
- if (!(res.status === 200)) {
159
- _context.next = 13;
160
- break;
161
- }
162
-
163
- _context.next = 7;
164
- return res.json();
165
-
166
- case 7:
167
- result = _context.sent;
168
-
169
- if (!result.error) {
170
- _context.next = 10;
171
- break;
172
- }
173
-
174
- throw new Error(result.error);
175
-
176
- case 10:
177
- return _context.abrupt('return', result.data);
178
-
179
- case 13:
180
- _context.t0 = Error;
181
- _context.next = 16;
182
- return res.text();
183
-
184
- case 16:
185
- _context.t1 = _context.sent;
186
- throw new _context.t0(_context.t1);
187
-
188
- case 18:
189
- _context.next = 24;
190
- break;
191
-
192
- case 20:
193
- _context.prev = 20;
194
- _context.t2 = _context['catch'](0);
195
-
196
- console.error('data handler failed : ' + api_url, _context.t2);
197
- return _context.abrupt('return', null);
198
-
199
- case 24:
200
- case 'end':
201
- return _context.stop();
202
- }
203
- }
204
- }, _callee, _this, [[0, 20]]);
205
- }));
206
-
207
- return function dataHandler(_x, _x2) {
208
- return _ref.apply(this, arguments);
209
- };
210
- }();
211
-
212
- function useUser() {
213
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
214
- redirectTo = _ref.redirectTo,
215
- redirectIfFound = _ref.redirectIfFound;
216
-
217
- var _useSWR = useSWR('/api/auth/user', dataHandler),
218
- data = _useSWR.data,
219
- error = _useSWR.error;
220
-
221
- var user = data;
222
- var finished = Boolean(data);
223
- var hasUser = Boolean(user);
224
-
225
- useEffect(function () {
226
- if (!redirectTo || !finished) return;
227
- if (
228
- // If redirectTo is set, redirect if the user was not found.
229
- redirectTo && !redirectIfFound && !hasUser ||
230
- // If redirectIfFound is also set, redirect if the user was found
231
- redirectIfFound && hasUser) {
232
- Router.push(redirectTo);
233
- }
234
- }, [redirectTo, redirectIfFound, finished, hasUser]);
235
-
236
- return error ? null : user;
237
- }
238
-
239
- var hooks = /*#__PURE__*/Object.freeze({
240
- __proto__: null,
241
- useUser: useUser
242
- });
243
-
244
- var LoginForm = function LoginForm(props) {
245
- var handleSubmit = function () {
246
- var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
247
- var body, res;
248
- return regenerator.wrap(function _callee$(_context) {
249
- while (1) {
250
- switch (_context.prev = _context.next) {
251
- case 0:
252
- event.preventDefault();
253
-
254
- if (errorMsg) setErrorMsg('');
255
- setLoading(true);
256
-
257
- body = {
258
- email: e.currentTarget.email.value,
259
- password: e.currentTarget.password.value
260
- };
261
- _context.prev = 4;
262
- _context.next = 7;
263
- return fetch('/api/auth/login', {
264
- method: 'POST',
265
- headers: { 'Content-Type': 'application/json' },
266
- body: _JSON$stringify(body)
267
- });
268
-
269
- case 7:
270
- res = _context.sent;
271
-
272
- setLoading(false);
273
-
274
- if (!(res.status === 200)) {
275
- _context.next = 13;
276
- break;
277
- }
278
-
279
- // here, Router.push() does not carry new cookie value.
280
- // so need hard redirect
281
- window.location.href = callbackUrl;
282
- _context.next = 18;
283
- break;
284
-
285
- case 13:
286
- _context.t0 = Error;
287
- _context.next = 16;
288
- return res.text();
289
-
290
- case 16:
291
- _context.t1 = _context.sent;
292
- throw new _context.t0(_context.t1);
293
-
294
- case 18:
295
- _context.next = 23;
296
- break;
297
-
298
- case 20:
299
- _context.prev = 20;
300
- _context.t2 = _context['catch'](4);
301
-
302
- setErrorMsg(_context.t2.message);
303
-
304
- case 23:
305
- case 'end':
306
- return _context.stop();
307
- }
308
- }
309
- }, _callee, this, [[4, 20]]);
310
- }));
311
-
312
- return function handleSubmit(_x) {
313
- return _ref.apply(this, arguments);
314
- };
315
- }();
316
-
317
- var _props$callbackUrl = props.callbackUrl,
318
- callbackUrl = _props$callbackUrl === undefined ? '/' : _props$callbackUrl;
319
-
320
-
321
- useEffect(function () {
322
- if (props.user) {
323
- window.location.href = '/auth/profile';
324
- }
325
- }, []);
326
- useUser('/auth/profile', true);
327
-
328
- var _useState = useState(''),
329
- _useState2 = _slicedToArray(_useState, 2),
330
- errorMsg = _useState2[0],
331
- setErrorMsg = _useState2[1];
332
-
333
- var _useState3 = useState(false),
334
- _useState4 = _slicedToArray(_useState3, 2),
335
- loading = _useState4[0],
336
- setLoading = _useState4[1];
337
-
338
- return React__default.createElement(
339
- Form,
340
- { className: 'login', onSubmit: handleSubmit },
341
- React__default.createElement(
342
- 'h1',
343
- null,
344
- 'Login'
345
- ),
346
- React__default.createElement('hr', null),
347
- returnFormField({ name: 'email', label: 'Email', type: 'email', required: true }),
348
- returnFormField({ name: 'password', label: 'Password', type: 'password', required: true }),
349
- React__default.createElement('hr', null),
350
- React__default.createElement(
351
- Form.Row,
352
- null,
353
- React__default.createElement(
354
- Form.Group,
355
- { as: Col },
356
- React__default.createElement(
357
- 'a',
358
- { href: '/auth/signup' },
359
- 'I don\'t have an account'
360
- )
361
- ),
362
- React__default.createElement(
363
- Form.Group,
364
- { as: Col, className: 'text-right' },
365
- !loading && React__default.createElement(
366
- Button,
367
- { type: 'submit' },
368
- 'Login'
369
- ),
370
- loading && React__default.createElement(
371
- Button,
372
- { variant: 'primary', disabled: true },
373
- React__default.createElement(Spinner, { as: 'span', animation: 'border', role: 'status', 'aria-hidden': 'true', size: 'sm' }),
374
- React__default.createElement(
375
- 'span',
376
- { className: 'sr-only' },
377
- 'Loading...'
378
- )
379
- )
380
- )
381
- ),
382
- errorMsg && React__default.createElement(
383
- 'p',
384
- { className: 'error' },
385
- errorMsg
386
- ),
387
- React__default.createElement(
388
- 'style',
389
- { jsx: 'true'.toString() },
390
- '\n .login {\n margin: 0 auto;\n padding: 1rem;\n border: 1px solid #ccc;\n border-radius: 4px;\n }\n .error {\n color: red;\n margin: 1rem 0 0;\n }\n '
391
- )
392
- );
393
- };
394
-
395
- // get country & state options
396
- var countries = ["United States", "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas (the)", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia (Plurinational State of)", "Bonaire, Sint Eustatius and Saba", "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory (the)", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cabo Verde", "Cambodia", "Cameroon", "Canada", "Cayman Islands (the)", "Central African Republic (the)", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands (the)", "Colombia", "Comoros (the)", "Congo (the Democratic Republic of the)", "Congo (the)", "Cook Islands (the)", "Costa Rica", "Croatia", "Cuba", "Curaçao", "Cyprus", "Czechia", "Côte d'Ivoire", "Denmark", "Djibouti", "Dominica", "Dominican Republic (the)", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Eswatini", "Ethiopia", "Falkland Islands (the) [Malvinas]", "Faroe Islands (the)", "Fiji", "Finland", "France", "French Guiana", "French Polynesia", "French Southern Territories (the)", "Gabon", "Gambia (the)", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard Island and McDonald Islands", "Holy See (the)", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran (Islamic Republic of)", "Iraq", "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea (the Democratic People's Republic of)", "Korea (the Republic of)", "Kuwait", "Kyrgyzstan", "Lao People's Democratic Republic (the)", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macao", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands (the)", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia (Federated States of)", "Moldova (the Republic of)", "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands (the)", "New Caledonia", "New Zealand", "Nicaragua", "Niger (the)", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands (the)", "Norway", "Oman", "Pakistan", "Palau", "Palestine, State of", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines (the)", "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Republic of North Macedonia", "Romania", "Russian Federation (the)", "Rwanda", "Réunion", "Saint Barthélemy", "Saint Helena, Ascension and Tristan da Cunha", "Saint Kitts and Nevis", "Saint Lucia", "Saint Martin (French part)", "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Sint Maarten (Dutch part)", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "South Sudan", "Spain", "Sri Lanka", "Sudan (the)", "Suriname", "Svalbard and Jan Mayen", "Sweden", "Switzerland", "Syrian Arab Republic", "Taiwan (Province of China)", "Tajikistan", "Tanzania, United Republic of", "Thailand", "Timor-Leste", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands (the)", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates (the)", "United Kingdom of Great Britain and Northern Ireland (the)", "United States Minor Outlying Islands (the)", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela (Bolivarian Republic of)", "Viet Nam", "Virgin Islands (British)", "Virgin Islands (U.S.)", "Wallis and Futuna", "Western Sahara", "Yemen", "Zambia", "Zimbabwe", "Åland Islands"];
397
-
398
- var states = ['AL', 'AK', 'AS', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FM', 'FL', 'GA', 'GU', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MH', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'MP', 'OH', 'OK', 'OR', 'PW', 'PA', 'PR', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VI', 'VA', 'WA', 'WV', 'WI', 'WY'];
399
-
400
- var _this$1 = undefined;
401
-
402
- var SignupForm = function SignupForm(props) {
403
- var handleSubmit = function () {
404
- var _ref3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e) {
405
- var formData, body, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, key, res;
406
-
407
- return regenerator.wrap(function _callee3$(_context3) {
408
- while (1) {
409
- switch (_context3.prev = _context3.next) {
410
- case 0:
411
- event.preventDefault();
412
- setLoading(true);
413
- if (errorMsg) setErrorMsg('');
414
-
415
- formData = new FormData(e.currentTarget);
416
- body = {};
417
- _iteratorNormalCompletion = true;
418
- _didIteratorError = false;
419
- _iteratorError = undefined;
420
- _context3.prev = 8;
421
-
422
- for (_iterator = _getIterator(formData.keys()); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
423
- key = _step.value;
424
-
425
- body[key] = formData.get(key);
426
- }
427
-
428
- _context3.next = 16;
429
- break;
430
-
431
- case 12:
432
- _context3.prev = 12;
433
- _context3.t0 = _context3['catch'](8);
434
- _didIteratorError = true;
435
- _iteratorError = _context3.t0;
436
-
437
- case 16:
438
- _context3.prev = 16;
439
- _context3.prev = 17;
440
-
441
- if (!_iteratorNormalCompletion && _iterator.return) {
442
- _iterator.return();
443
- }
444
-
445
- case 19:
446
- _context3.prev = 19;
447
-
448
- if (!_didIteratorError) {
449
- _context3.next = 22;
450
- break;
451
- }
452
-
453
- throw _iteratorError;
454
-
455
- case 22:
456
- return _context3.finish(19);
457
-
458
- case 23:
459
- return _context3.finish(16);
460
-
461
- case 24:
462
- _context3.prev = 24;
463
- _context3.next = 27;
464
- return fetch('/api/auth/signup', {
465
- method: 'POST',
466
- headers: { 'Content-Type': 'application/json' },
467
- body: _JSON$stringify(body)
468
- });
469
-
470
- case 27:
471
- res = _context3.sent;
472
-
473
- setLoading(false);
474
-
475
- if (!(res.status === 200)) {
476
- _context3.next = 33;
477
- break;
478
- }
479
-
480
- window.location.href = '/';
481
- _context3.next = 38;
482
- break;
483
-
484
- case 33:
485
- _context3.t1 = Error;
486
- _context3.next = 36;
487
- return res.text();
488
-
489
- case 36:
490
- _context3.t2 = _context3.sent;
491
- throw new _context3.t1(_context3.t2);
492
-
493
- case 38:
494
- _context3.next = 43;
495
- break;
496
-
497
- case 40:
498
- _context3.prev = 40;
499
- _context3.t3 = _context3['catch'](24);
500
-
501
- setErrorMsg(_context3.t3.message);
502
-
503
- case 43:
504
- case 'end':
505
- return _context3.stop();
506
- }
507
- }
508
- }, _callee3, this, [[8, 12, 16, 24], [17,, 19, 23], [24, 40]]);
509
- }));
510
-
511
- return function handleSubmit(_x2) {
512
- return _ref3.apply(this, arguments);
513
- };
514
- }();
515
-
516
- var _useState = useState(''),
517
- _useState2 = _slicedToArray(_useState, 2),
518
- errorMsg = _useState2[0],
519
- setErrorMsg = _useState2[1];
520
-
521
- var _useState3 = useState(false),
522
- _useState4 = _slicedToArray(_useState3, 2),
523
- countryUS = _useState4[0],
524
- setCountryUS = _useState4[1];
525
-
526
- var _useState5 = useState([]),
527
- _useState6 = _slicedToArray(_useState5, 2),
528
- healthcareOccupation = _useState6[0],
529
- setHealthcareOccupation = _useState6[1];
530
-
531
- var _useState7 = useState([]),
532
- _useState8 = _slicedToArray(_useState7, 2),
533
- nonHealthcareOccupation = _useState8[0],
534
- setNonHealthcareOccupation = _useState8[1];
535
-
536
- var loadInitData = function () {
537
- var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
538
- var healthcare_occupation, non_healthcare_occupation;
539
- return regenerator.wrap(function _callee$(_context) {
540
- while (1) {
541
- switch (_context.prev = _context.next) {
542
- case 0:
543
- _context.next = 2;
544
- return dataHandler('/api/auth/data', { action: 'get-occupation', type: 'Healthcare' });
545
-
546
- case 2:
547
- healthcare_occupation = _context.sent;
548
- _context.next = 5;
549
- return dataHandler('/api/auth/data', { action: 'get-occupation', type: 'Non-Healthcare' });
550
-
551
- case 5:
552
- non_healthcare_occupation = _context.sent;
553
-
554
-
555
- setHealthcareOccupation(healthcare_occupation);
556
- setNonHealthcareOccupation(non_healthcare_occupation);
557
-
558
- case 8:
559
- case 'end':
560
- return _context.stop();
561
- }
562
- }
563
- }, _callee, _this$1);
564
- }));
565
-
566
- return function loadInitData() {
567
- return _ref.apply(this, arguments);
568
- };
569
- }();
570
-
571
- useEffect(function () {
572
- if (props.user) {
573
- window.location.href = '/auth/profile';
574
- } else {
575
- loadInitData();
576
- }
577
- }, []);
578
-
579
- // make it to change layout based on radio buton
580
- var handleCountryChanged = function handleCountryChanged(e) {
581
- if (e.target.value === 'United States') {
582
- setCountryUS(true);
583
- } else {
584
- setCountryUS(false);
585
- }
586
- };
587
-
588
- var _useState9 = useState(true),
589
- _useState10 = _slicedToArray(_useState9, 2),
590
- healcareProfessional = _useState10[0],
591
- setHealthcareProfessional = _useState10[1];
592
-
593
- var handleHealthcareProfessionalChanged = function handleHealthcareProfessionalChanged(e) {
594
-
595
- if (e.target.value === 'Y') {
596
- setHealthcareProfessional(true);
597
- } else {
598
- setHealthcareProfessional(false);
599
- }
600
- document.getElementById('occupation').value = '';
601
- setOccupationFields(null);
602
- };
603
-
604
- var _useState11 = useState(null),
605
- _useState12 = _slicedToArray(_useState11, 2),
606
- occupationFields = _useState12[0],
607
- setOccupationFields = _useState12[1];
608
-
609
- var handleOccupationChanged = function () {
610
- var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(e) {
611
- var occupation, fields;
612
- return regenerator.wrap(function _callee2$(_context2) {
613
- while (1) {
614
- switch (_context2.prev = _context2.next) {
615
- case 0:
616
- occupation = e.target.value;
617
- _context2.next = 3;
618
- return dataHandler('/api/auth/data', { action: 'get-fields', occupation: occupation });
619
-
620
- case 3:
621
- fields = _context2.sent;
622
-
623
- setOccupationFields(fields);
624
-
625
- case 5:
626
- case 'end':
627
- return _context2.stop();
628
- }
629
- }
630
- }, _callee2, _this$1);
631
- }));
632
-
633
- return function handleOccupationChanged(_x) {
634
- return _ref2.apply(this, arguments);
635
- };
636
- }();
637
-
638
- var _useState13 = useState(false),
639
- _useState14 = _slicedToArray(_useState13, 2),
640
- loading = _useState14[0],
641
- setLoading = _useState14[1];
642
-
643
- return React__default.createElement(
644
- Form,
645
- { className: 'login', id: 'signupForm', onSubmit: handleSubmit },
646
- React__default.createElement(
647
- 'h1',
648
- null,
649
- 'Sign Up'
650
- ),
651
- React__default.createElement('hr', null),
652
- returnFormField({ name: 'email', label: 'Email', type: 'email', required: true }),
653
- React__default.createElement(
654
- Form.Row,
655
- null,
656
- returnFormField({ name: 'password', label: 'Password', type: 'password', groupType: Col, required: true }),
657
- returnFormField({ name: 'rpassword', label: 'Retype Password', type: 'password', groupType: Col, required: true })
658
- ),
659
- React__default.createElement(
660
- Form.Row,
661
- null,
662
- returnFormField({ name: 'first_name', label: 'First Name', type: 'text', groupType: Col, required: true }),
663
- returnFormField({ name: 'last_name', label: 'Last Name', type: 'text', groupType: Col, required: true })
664
- ),
665
- React__default.createElement(
666
- Form.Row,
667
- null,
668
- returnFormField({
669
- name: 'country',
670
- label: 'Country',
671
- type: 'select',
672
- required: true,
673
- groupType: Col,
674
- options: countries,
675
- handleChanged: handleCountryChanged
676
- }),
677
- countryUS && returnFormField({ name: 'state', label: 'State', type: 'select', required: true, groupType: Col, options: states })
678
- ),
679
- React__default.createElement(
680
- Form.Row,
681
- null,
682
- countryUS && returnFormField({ name: 'zip', label: 'Working Zip Code', type: 'text', required: true, groupType: Col }),
683
- countryUS && returnFormField({ name: 'phone', label: 'Phone', type: 'text', required: true, groupType: Col })
684
- ),
685
- returnFormField({
686
- name: 'healthcare_professional',
687
- label: 'Are You a Health Care Professional?',
688
- type: 'radio',
689
- required: true,
690
- options: [{ value: 'Y', label: 'Yes', checked: true }, { value: 'N', label: 'No', checked: false }],
691
- handleChanged: handleHealthcareProfessionalChanged,
692
- default_value: 'Y'
693
- }),
694
- healcareProfessional && returnFormField({
695
- name: 'occupation',
696
- label: 'Occupation',
697
- type: 'select',
698
- required: true,
699
- options: healthcareOccupation,
700
- handleChanged: handleOccupationChanged
701
- }),
702
- !healcareProfessional && returnFormField({
703
- name: 'occupation',
704
- label: 'Non Provider Role',
705
- type: 'select',
706
- required: true,
707
- options: nonHealthcareOccupation,
708
- handleChanged: handleOccupationChanged
709
- }),
710
- occupationFields && occupationFields.map(function (field) {
711
- return returnFormField({
712
- name: field.name,
713
- label: field.label,
714
- type: field.type,
715
- required: field.required === 1,
716
- options: field.options
717
- });
718
- }),
719
- returnFormField({
720
- name: 'agree',
721
- label: 'Terms & Conditions | Privacy Policy',
722
- type: 'checkbox',
723
- required: true,
724
- options: [{ label: 'By registering you agree to our <a href="/terms" style="color:blue">Terms and Conditions</a> and <a href="/privacy" style="color:blue">Privacy Policy</a> and understand that you will be receiving email communications', value: 'Y' }]
725
- }),
726
- React__default.createElement('hr', null),
727
- React__default.createElement(
728
- Form.Row,
729
- null,
730
- React__default.createElement(
731
- Form.Group,
732
- { as: Col },
733
- React__default.createElement(
734
- 'a',
735
- { href: '/auth/login' },
736
- 'I already have an account'
737
- )
738
- ),
739
- React__default.createElement(
740
- Form.Group,
741
- { as: Col, className: 'text-right' },
742
- !loading && React__default.createElement(
743
- Button,
744
- { type: 'submit' },
745
- 'Sign Up'
746
- ),
747
- loading && React__default.createElement(
748
- Button,
749
- { variant: 'primary', disabled: true },
750
- React__default.createElement(Spinner, {
751
- as: 'span',
752
- animation: 'border',
753
- role: 'status',
754
- 'aria-hidden': 'true',
755
- size: 'sm'
756
- }),
757
- React__default.createElement(
758
- 'span',
759
- { className: 'sr-only' },
760
- 'Loading...'
761
- )
762
- )
763
- )
764
- ),
765
- errorMsg && React__default.createElement(
766
- 'p',
767
- { className: 'error' },
768
- errorMsg
769
- ),
770
- React__default.createElement(
771
- 'style',
772
- { jsx: 'true'.toString() },
773
- ' \n .login {\n margin: 0 auto;\n padding: 1rem;\n border: 1px solid #ccc;\n border-radius: 4px;\n }\n .error {\n color: red;\n margin: 1rem 0 0;\n }\n '
774
- )
775
- );
776
- };
777
-
778
- var _this$2 = undefined;
779
-
780
- var SignupForm$1 = function SignupForm(props) {
781
- var handleSubmit = function () {
782
- var _ref3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e) {
783
- var formData, body, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, key, res;
784
-
785
- return regenerator.wrap(function _callee3$(_context3) {
786
- while (1) {
787
- switch (_context3.prev = _context3.next) {
788
- case 0:
789
- event.preventDefault();
790
-
791
- setErrorMsg('');
792
- setSuccessMsg('');
793
- setLoading(true);
794
-
795
- formData = new FormData(e.currentTarget);
796
- body = {};
797
- _iteratorNormalCompletion = true;
798
- _didIteratorError = false;
799
- _iteratorError = undefined;
800
- _context3.prev = 9;
801
-
802
- for (_iterator = _getIterator(formData.keys()); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
803
- key = _step.value;
804
-
805
- body[key] = formData.get(key);
806
- }
807
-
808
- _context3.next = 17;
809
- break;
810
-
811
- case 13:
812
- _context3.prev = 13;
813
- _context3.t0 = _context3['catch'](9);
814
- _didIteratorError = true;
815
- _iteratorError = _context3.t0;
816
-
817
- case 17:
818
- _context3.prev = 17;
819
- _context3.prev = 18;
820
-
821
- if (!_iteratorNormalCompletion && _iterator.return) {
822
- _iterator.return();
823
- }
824
-
825
- case 20:
826
- _context3.prev = 20;
827
-
828
- if (!_didIteratorError) {
829
- _context3.next = 23;
830
- break;
831
- }
832
-
833
- throw _iteratorError;
834
-
835
- case 23:
836
- return _context3.finish(20);
837
-
838
- case 24:
839
- return _context3.finish(17);
840
-
841
- case 25:
842
- body['user_id'] = userData.id;
843
-
844
- _context3.prev = 26;
845
- _context3.next = 29;
846
- return fetch('/api/auth/profile', {
847
- method: 'POST',
848
- headers: { 'Content-Type': 'application/json' },
849
- body: _JSON$stringify(body)
850
- });
851
-
852
- case 29:
853
- res = _context3.sent;
854
-
855
- setLoading(false);
856
-
857
- if (!(res.status === 200)) {
858
- _context3.next = 35;
859
- break;
860
- }
861
-
862
- setSuccessMsg('Your request has been processed successfully!');
863
- _context3.next = 40;
864
- break;
865
-
866
- case 35:
867
- _context3.t1 = Error;
868
- _context3.next = 38;
869
- return res.text();
870
-
871
- case 38:
872
- _context3.t2 = _context3.sent;
873
- throw new _context3.t1(_context3.t2);
874
-
875
- case 40:
876
- _context3.next = 45;
877
- break;
878
-
879
- case 42:
880
- _context3.prev = 42;
881
- _context3.t3 = _context3['catch'](26);
882
-
883
- setErrorMsg(_context3.t3.message);
884
-
885
- case 45:
886
- case 'end':
887
- return _context3.stop();
888
- }
889
- }
890
- }, _callee3, this, [[9, 13, 17, 25], [18,, 20, 24], [26, 42]]);
891
- }));
892
-
893
- return function handleSubmit(_x2) {
894
- return _ref3.apply(this, arguments);
895
- };
896
- }();
897
-
898
- var _useState = useState(''),
899
- _useState2 = _slicedToArray(_useState, 2),
900
- errorMsg = _useState2[0],
901
- setErrorMsg = _useState2[1];
902
-
903
- var _useState3 = useState(false),
904
- _useState4 = _slicedToArray(_useState3, 2),
905
- countryUS = _useState4[0],
906
- setCountryUS = _useState4[1];
907
-
908
- var _useState5 = useState([]),
909
- _useState6 = _slicedToArray(_useState5, 2),
910
- healthcareOccupation = _useState6[0],
911
- setHealthcareOccupation = _useState6[1];
912
-
913
- var _useState7 = useState([]),
914
- _useState8 = _slicedToArray(_useState7, 2),
915
- nonHealthcareOccupation = _useState8[0],
916
- setNonHealthcareOccupation = _useState8[1];
917
-
918
- var _useState9 = useState(null),
919
- _useState10 = _slicedToArray(_useState9, 2),
920
- userData = _useState10[0],
921
- setUserData = _useState10[1];
922
-
923
- var user = props.user;
924
-
925
- var loadInitData = function () {
926
- var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
927
- var healthcare_occupation, non_healthcare_occupation, foundOccupation, fields;
928
- return regenerator.wrap(function _callee$(_context) {
929
- while (1) {
930
- switch (_context.prev = _context.next) {
931
- case 0:
932
- _context.next = 2;
933
- return dataHandler('/api/auth/data', { action: 'get-occupation', type: 'Healthcare' });
934
-
935
- case 2:
936
- healthcare_occupation = _context.sent;
937
- _context.next = 5;
938
- return dataHandler('/api/auth/data', { action: 'get-occupation', type: 'Non-Healthcare' });
939
-
940
- case 5:
941
- non_healthcare_occupation = _context.sent;
942
- foundOccupation = healthcare_occupation.find(function (item) {
943
- return item.value === user.shared.occupation_id;
944
- });
945
-
946
- if (foundOccupation) {
947
- user.shared.healthcare_professional = 'Y';
948
- } else {
949
- user.shared.healthcare_professional = 'N';
950
- }
951
-
952
- setHealthcareOccupation(healthcare_occupation);
953
- setNonHealthcareOccupation(non_healthcare_occupation);
954
- setUserData(user);
955
-
956
- if (user.shared.country === 'United States') {
957
- setCountryUS(true);
958
- } else {
959
- setCountryUS(false);
960
- }
961
-
962
- _context.next = 14;
963
- return dataHandler('/api/auth/data', { action: 'get-fields', occupation: user.shared.occupation_id });
964
-
965
- case 14:
966
- fields = _context.sent;
967
-
968
- setOccupationFields(fields);
969
-
970
- case 16:
971
- case 'end':
972
- return _context.stop();
973
- }
974
- }
975
- }, _callee, _this$2);
976
- }));
977
-
978
- return function loadInitData() {
979
- return _ref.apply(this, arguments);
980
- };
981
- }();
982
-
983
- useEffect(function () {
984
- if (!user) {
985
- window.location.href = '/auth/login';
986
- } else {
987
- loadInitData();
988
- }
989
- }, []);
990
-
991
- // make it to change layout based on radio buton
992
- var handleCountryChanged = function handleCountryChanged(e) {
993
- if (e.target.value === 'United States') {
994
- setCountryUS(true);
995
- } else {
996
- setCountryUS(false);
997
- }
998
- };
999
-
1000
- var _useState11 = useState(true),
1001
- _useState12 = _slicedToArray(_useState11, 2),
1002
- healcareProfessional = _useState12[0],
1003
- setHealthcareProfessional = _useState12[1];
1004
-
1005
- var handleHealthcareProfessionalChanged = function handleHealthcareProfessionalChanged(e) {
1006
-
1007
- if (e.target.value === 'Y') {
1008
- setHealthcareProfessional(true);
1009
- } else {
1010
- setHealthcareProfessional(false);
1011
- }
1012
- document.getElementById('occupation').value = '';
1013
- setOccupationFields(null);
1014
- };
1015
-
1016
- var _useState13 = useState(null),
1017
- _useState14 = _slicedToArray(_useState13, 2),
1018
- occupationFields = _useState14[0],
1019
- setOccupationFields = _useState14[1];
1020
-
1021
- var handleOccupationChanged = function () {
1022
- var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(e) {
1023
- var occupation, fields;
1024
- return regenerator.wrap(function _callee2$(_context2) {
1025
- while (1) {
1026
- switch (_context2.prev = _context2.next) {
1027
- case 0:
1028
- occupation = e.target.value;
1029
- _context2.next = 3;
1030
- return dataHandler('/api/auth/data', { action: 'get-fields', occupation: occupation });
1031
-
1032
- case 3:
1033
- fields = _context2.sent;
1034
-
1035
- setOccupationFields(fields);
1036
-
1037
- case 5:
1038
- case 'end':
1039
- return _context2.stop();
1040
- }
1041
- }
1042
- }, _callee2, _this$2);
1043
- }));
1044
-
1045
- return function handleOccupationChanged(_x) {
1046
- return _ref2.apply(this, arguments);
1047
- };
1048
- }();
1049
-
1050
- var _useState15 = useState(''),
1051
- _useState16 = _slicedToArray(_useState15, 2),
1052
- successMsg = _useState16[0],
1053
- setSuccessMsg = _useState16[1];
1054
-
1055
- var _useState17 = useState(false),
1056
- _useState18 = _slicedToArray(_useState17, 2),
1057
- loading = _useState18[0],
1058
- setLoading = _useState18[1];
1059
-
1060
- return React__default.createElement(
1061
- Form,
1062
- { className: 'login', id: 'signupForm', onSubmit: handleSubmit },
1063
- React__default.createElement(
1064
- 'h1',
1065
- null,
1066
- 'Profile'
1067
- ),
1068
- React__default.createElement('hr', null),
1069
- userData ? React__default.createElement(
1070
- React__default.Fragment,
1071
- null,
1072
- returnFormField({ name: 'email', label: 'Email', type: 'email', required: true, readonly: true, default_value: userData.email }),
1073
- React__default.createElement(
1074
- Form.Row,
1075
- null,
1076
- returnFormField({ name: 'password', label: 'Password', type: 'password', groupType: Col, required: false }),
1077
- returnFormField({ name: 'rpassword', label: 'Retype Password', type: 'password', groupType: Col, required: false })
1078
- ),
1079
- React__default.createElement(
1080
- Form.Row,
1081
- null,
1082
- returnFormField({ name: 'first_name', label: 'First Name', type: 'text', groupType: Col, required: true, default_value: userData.shared.first_name }),
1083
- returnFormField({ name: 'last_name', label: 'Last Name', type: 'text', groupType: Col, required: true, default_value: userData.shared.last_name })
1084
- ),
1085
- React__default.createElement(
1086
- Form.Row,
1087
- null,
1088
- returnFormField({
1089
- name: 'country',
1090
- label: 'Country',
1091
- type: 'select',
1092
- required: true,
1093
- groupType: Col,
1094
- options: countries,
1095
- handleChanged: handleCountryChanged,
1096
- default_value: userData.shared.country
1097
- }),
1098
- countryUS && returnFormField({ name: 'state', label: 'State', type: 'select', required: true, groupType: Col, options: states, default_value: userData.shared.state })
1099
- ),
1100
- React__default.createElement(
1101
- Form.Row,
1102
- null,
1103
- countryUS && returnFormField({ name: 'zip', label: 'Working Zip Code', type: 'text', required: true, groupType: Col, default_value: userData.shared.zip }),
1104
- countryUS && returnFormField({ name: 'phone', label: 'Phone', type: 'text', required: true, groupType: Col, default_value: userData.shared.phone })
1105
- ),
1106
- returnFormField({
1107
- name: 'healthcare_professional',
1108
- label: 'Are You a Health Care Professional?',
1109
- type: 'radio',
1110
- required: true,
1111
- options: [{ value: 'Y', label: 'Yes', checked: true }, { value: 'N', label: 'No', checked: false }],
1112
- default_value: userData.shared.healthcare_professional,
1113
- handleChanged: handleHealthcareProfessionalChanged
1114
- }),
1115
- healcareProfessional && returnFormField({
1116
- name: 'occupation',
1117
- label: 'Occupation',
1118
- type: 'select',
1119
- required: true,
1120
- options: healthcareOccupation,
1121
- handleChanged: handleOccupationChanged,
1122
- default_value: userData.shared.occupation_id
1123
- }),
1124
- !healcareProfessional && returnFormField({
1125
- name: 'occupation',
1126
- label: 'Non Provider Role',
1127
- type: 'select',
1128
- required: true,
1129
- options: nonHealthcareOccupation,
1130
- handleChanged: handleOccupationChanged,
1131
- default_value: userData.shared.occupation_id
1132
- }),
1133
- occupationFields && occupationFields.map(function (field) {
1134
- return returnFormField({
1135
- name: field.name,
1136
- label: field.label,
1137
- type: field.type,
1138
- required: field.required === 1,
1139
- options: field.options,
1140
- default_value: userData.shared[field.name]
1141
- });
1142
- }),
1143
- returnFormField({
1144
- name: 'agree',
1145
- label: 'Terms & Conditions | Privacy Policy',
1146
- type: 'checkbox',
1147
- required: true,
1148
- options: [{ label: 'By registering you agree to our <a href="/terms">Terms and Conditions</a> and <a href="/privacy">Privacy Policy</a> and understand that you will be receiving email communications', value: 'Y' }]
1149
- }),
1150
- React__default.createElement('hr', null),
1151
- React__default.createElement(
1152
- Form.Row,
1153
- null,
1154
- React__default.createElement(
1155
- Form.Group,
1156
- { as: Col },
1157
- !loading && React__default.createElement(
1158
- Button,
1159
- { type: 'submit' },
1160
- 'Update'
1161
- ),
1162
- loading && React__default.createElement(
1163
- Button,
1164
- { variant: 'primary', disabled: true },
1165
- React__default.createElement(Spinner, {
1166
- as: 'span',
1167
- animation: 'border',
1168
- role: 'status',
1169
- 'aria-hidden': 'true',
1170
- size: 'sm'
1171
- }),
1172
- React__default.createElement(
1173
- 'span',
1174
- { className: 'sr-only' },
1175
- 'Loading...'
1176
- )
1177
- )
1178
- )
1179
- )
1180
- ) : React__default.createElement(Spinner, {
1181
- as: 'span',
1182
- animation: 'border',
1183
- role: 'status',
1184
- 'aria-hidden': 'true',
1185
- size: 'sm'
1186
- }),
1187
- errorMsg && React__default.createElement(
1188
- 'p',
1189
- { className: 'error' },
1190
- errorMsg
1191
- ),
1192
- successMsg && React__default.createElement(
1193
- 'p',
1194
- { className: 'success' },
1195
- successMsg
1196
- ),
1197
- React__default.createElement(
1198
- 'style',
1199
- { jsx: 'true'.toString() },
1200
- ' \n .login {\n margin: 0 auto;\n padding: 1rem;\n border: 1px solid #ccc;\n border-radius: 4px;\n }\n .error {\n color: red;\n margin: 1rem 0 0;\n }\n .success {\n color: green;\n margin: 1rem 0 0;\n }\n '
1201
- )
1202
- );
1203
- };
1204
-
1205
- /*!
1206
- * cookie
1207
- * Copyright(c) 2012-2014 Roman Shtylman
1208
- * Copyright(c) 2015 Douglas Christopher Wilson
1209
- * MIT Licensed
1210
- */
1211
-
1212
- /**
1213
- * Module exports.
1214
- * @public
1215
- */
1216
-
1217
- var parse_1 = parse;
1218
- var serialize_1 = serialize;
1219
-
1220
- /**
1221
- * Module variables.
1222
- * @private
1223
- */
1224
-
1225
- var decode = decodeURIComponent;
1226
- var encode = encodeURIComponent;
1227
- var pairSplitRegExp = /; */;
1228
-
1229
- /**
1230
- * RegExp to match field-content in RFC 7230 sec 3.2
1231
- *
1232
- * field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
1233
- * field-vchar = VCHAR / obs-text
1234
- * obs-text = %x80-FF
1235
- */
1236
-
1237
- var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
1238
-
1239
- /**
1240
- * Parse a cookie header.
1241
- *
1242
- * Parse the given cookie header string into an object
1243
- * The object has the various cookies as keys(names) => values
1244
- *
1245
- * @param {string} str
1246
- * @param {object} [options]
1247
- * @return {object}
1248
- * @public
1249
- */
1250
-
1251
- function parse(str, options) {
1252
- if (typeof str !== 'string') {
1253
- throw new TypeError('argument str must be a string');
1254
- }
1255
-
1256
- var obj = {};
1257
- var opt = options || {};
1258
- var pairs = str.split(pairSplitRegExp);
1259
- var dec = opt.decode || decode;
1260
-
1261
- for (var i = 0; i < pairs.length; i++) {
1262
- var pair = pairs[i];
1263
- var eq_idx = pair.indexOf('=');
1264
-
1265
- // skip things that don't look like key=value
1266
- if (eq_idx < 0) {
1267
- continue;
1268
- }
1269
-
1270
- var key = pair.substr(0, eq_idx).trim();
1271
- var val = pair.substr(++eq_idx, pair.length).trim();
1272
-
1273
- // quoted values
1274
- if ('"' == val[0]) {
1275
- val = val.slice(1, -1);
1276
- }
1277
-
1278
- // only assign once
1279
- if (undefined == obj[key]) {
1280
- obj[key] = tryDecode(val, dec);
1281
- }
1282
- }
1283
-
1284
- return obj;
1285
- }
1286
-
1287
- /**
1288
- * Serialize data into a cookie header.
1289
- *
1290
- * Serialize the a name value pair into a cookie string suitable for
1291
- * http headers. An optional options object specified cookie parameters.
1292
- *
1293
- * serialize('foo', 'bar', { httpOnly: true })
1294
- * => "foo=bar; httpOnly"
1295
- *
1296
- * @param {string} name
1297
- * @param {string} val
1298
- * @param {object} [options]
1299
- * @return {string}
1300
- * @public
1301
- */
1302
-
1303
- function serialize(name, val, options) {
1304
- var opt = options || {};
1305
- var enc = opt.encode || encode;
1306
-
1307
- if (typeof enc !== 'function') {
1308
- throw new TypeError('option encode is invalid');
1309
- }
1310
-
1311
- if (!fieldContentRegExp.test(name)) {
1312
- throw new TypeError('argument name is invalid');
1313
- }
1314
-
1315
- var value = enc(val);
1316
-
1317
- if (value && !fieldContentRegExp.test(value)) {
1318
- throw new TypeError('argument val is invalid');
1319
- }
1320
-
1321
- var str = name + '=' + value;
1322
-
1323
- if (null != opt.maxAge) {
1324
- var maxAge = opt.maxAge - 0;
1325
-
1326
- if (isNaN(maxAge) || !isFinite(maxAge)) {
1327
- throw new TypeError('option maxAge is invalid')
1328
- }
1329
-
1330
- str += '; Max-Age=' + Math.floor(maxAge);
1331
- }
1332
-
1333
- if (opt.domain) {
1334
- if (!fieldContentRegExp.test(opt.domain)) {
1335
- throw new TypeError('option domain is invalid');
1336
- }
1337
-
1338
- str += '; Domain=' + opt.domain;
1339
- }
1340
-
1341
- if (opt.path) {
1342
- if (!fieldContentRegExp.test(opt.path)) {
1343
- throw new TypeError('option path is invalid');
1344
- }
1345
-
1346
- str += '; Path=' + opt.path;
1347
- }
1348
-
1349
- if (opt.expires) {
1350
- if (typeof opt.expires.toUTCString !== 'function') {
1351
- throw new TypeError('option expires is invalid');
1352
- }
1353
-
1354
- str += '; Expires=' + opt.expires.toUTCString();
1355
- }
1356
-
1357
- if (opt.httpOnly) {
1358
- str += '; HttpOnly';
1359
- }
1360
-
1361
- if (opt.secure) {
1362
- str += '; Secure';
1363
- }
1364
-
1365
- if (opt.sameSite) {
1366
- var sameSite = typeof opt.sameSite === 'string'
1367
- ? opt.sameSite.toLowerCase() : opt.sameSite;
1368
-
1369
- switch (sameSite) {
1370
- case true:
1371
- str += '; SameSite=Strict';
1372
- break;
1373
- case 'lax':
1374
- str += '; SameSite=Lax';
1375
- break;
1376
- case 'strict':
1377
- str += '; SameSite=Strict';
1378
- break;
1379
- case 'none':
1380
- str += '; SameSite=None';
1381
- break;
1382
- default:
1383
- throw new TypeError('option sameSite is invalid');
1384
- }
1385
- }
1386
-
1387
- return str;
1388
- }
1389
-
1390
- /**
1391
- * Try decoding a string using a decoding function.
1392
- *
1393
- * @param {string} str
1394
- * @param {function} decode
1395
- * @private
1396
- */
1397
-
1398
- function tryDecode(str, decode) {
1399
- try {
1400
- return decode(str);
1401
- } catch (e) {
1402
- return str;
1403
- }
1404
- }
1405
-
1406
- var TOKEN_NAME = 'token';
1407
- var MAX_AGE = 60 * 60 * 8; // 8 hours
1408
-
1409
- function setTokenCookie(res, token, eKey) {
1410
- var cookies_serailized = [];
1411
- cookies_serailized.push(serialize_1(TOKEN_NAME, token, {
1412
- //maxAge: MAX_AGE, // we want login cookie to expire when browser
1413
- //expires: new Date(Date.now() + MAX_AGE * 1000),
1414
- //httpOnly: true,
1415
- //secure: process.env.NODE_ENV === 'production',
1416
- path: '/'
1417
- //sameSite: 'lax',
1418
- }));
1419
-
1420
- cookies_serailized.push(serialize_1('eKey', eKey, {
1421
- //maxAge: MAX_AGE, // we want login cookie to expire when browser
1422
- //expires: new Date(Date.now() + MAX_AGE * 1000),
1423
- //httpOnly: true,
1424
- //secure: process.env.NODE_ENV === 'production',
1425
- path: '/'
1426
- //sameSite: 'lax',
1427
- }));
1428
-
1429
- res.setHeader('Set-Cookie', cookies_serailized);
1430
- }
1431
-
1432
- function removeTokenCookie(res) {
1433
- var cookies_serailized = [];
1434
- cookies_serailized.push(serialize_1(TOKEN_NAME, '', {
1435
- maxAge: -1,
1436
- expires: new Date(Date.now() - MAX_AGE * 1000),
1437
- path: '/'
1438
- }));
1439
- cookies_serailized.push(serialize_1('eKey', '', {
1440
- maxAge: -1,
1441
- expires: new Date(Date.now() - MAX_AGE * 1000),
1442
- path: '/'
1443
- }));
1444
-
1445
- res.setHeader('Set-Cookie', cookies_serailized);
1446
- }
1447
-
1448
- function parseCookies(req) {
1449
- // For API Routes we don't need to parse the cookies.
1450
- if (req.cookies) return req.cookies;
1451
-
1452
- // For pages we do need to parse the cookies.
1453
- var cookie = req.headers ? req.headers.cookie : null;
1454
- return parse_1(cookie || '');
1455
- }
1456
-
1457
- function getTokenCookie(req) {
1458
- var cookies = parseCookies(req);
1459
- return cookies[TOKEN_NAME];
1460
- }
1461
-
1462
- var authCookies = /*#__PURE__*/Object.freeze({
1463
- __proto__: null,
1464
- setTokenCookie: setTokenCookie,
1465
- removeTokenCookie: removeTokenCookie,
1466
- parseCookies: parseCookies,
1467
- getTokenCookie: getTokenCookie
1468
- });
1469
-
1470
- function encryptSession(session) {
1471
- var buffer = new Buffer(_JSON$stringify(session));
1472
- return buffer.toString('base64');
1473
- //return jwt.sign(session, TOKEN_SECRET)
1474
- //return Iron.seal(session, TOKEN_SECRET, Iron.defaults)
1475
- }
1476
-
1477
- var getSession = function () {
1478
- var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(req) {
1479
- var token, buff;
1480
- return regenerator.wrap(function _callee$(_context) {
1481
- while (1) {
1482
- switch (_context.prev = _context.next) {
1483
- case 0:
1484
- token = getTokenCookie(req);
1485
-
1486
- if (!token) {
1487
- _context.next = 4;
1488
- break;
1489
- }
1490
-
1491
- buff = new Buffer(token, 'base64');
1492
- return _context.abrupt('return', JSON.parse(buff.toString('utf8')));
1493
-
1494
- case 4:
1495
- return _context.abrupt('return', null);
1496
-
1497
- case 5:
1498
- case 'end':
1499
- return _context.stop();
1500
- }
1501
- }
1502
- }, _callee, this);
1503
- }));
1504
-
1505
- return function getSession(_x) {
1506
- return _ref.apply(this, arguments);
1507
- };
1508
- }();
1509
-
1510
- var iron = /*#__PURE__*/Object.freeze({
1511
- __proto__: null,
1512
- encryptSession: encryptSession,
1513
- getSession: getSession
1514
- });
1515
-
1516
- var toStr = Object.prototype.toString;
1517
-
1518
- var isArguments = function isArguments(value) {
1519
- var str = toStr.call(value);
1520
- var isArgs = str === '[object Arguments]';
1521
- if (!isArgs) {
1522
- isArgs = str !== '[object Array]' &&
1523
- value !== null &&
1524
- typeof value === 'object' &&
1525
- typeof value.length === 'number' &&
1526
- value.length >= 0 &&
1527
- toStr.call(value.callee) === '[object Function]';
1528
- }
1529
- return isArgs;
1530
- };
1531
-
1532
- var keysShim;
1533
- if (!Object.keys) {
1534
- // modified from https://github.com/es-shims/es5-shim
1535
- var has = Object.prototype.hasOwnProperty;
1536
- var toStr$1 = Object.prototype.toString;
1537
- var isArgs = isArguments; // eslint-disable-line global-require
1538
- var isEnumerable = Object.prototype.propertyIsEnumerable;
1539
- var hasDontEnumBug = !isEnumerable.call({ toString: null }, 'toString');
1540
- var hasProtoEnumBug = isEnumerable.call(function () {}, 'prototype');
1541
- var dontEnums = [
1542
- 'toString',
1543
- 'toLocaleString',
1544
- 'valueOf',
1545
- 'hasOwnProperty',
1546
- 'isPrototypeOf',
1547
- 'propertyIsEnumerable',
1548
- 'constructor'
1549
- ];
1550
- var equalsConstructorPrototype = function (o) {
1551
- var ctor = o.constructor;
1552
- return ctor && ctor.prototype === o;
1553
- };
1554
- var excludedKeys = {
1555
- $applicationCache: true,
1556
- $console: true,
1557
- $external: true,
1558
- $frame: true,
1559
- $frameElement: true,
1560
- $frames: true,
1561
- $innerHeight: true,
1562
- $innerWidth: true,
1563
- $onmozfullscreenchange: true,
1564
- $onmozfullscreenerror: true,
1565
- $outerHeight: true,
1566
- $outerWidth: true,
1567
- $pageXOffset: true,
1568
- $pageYOffset: true,
1569
- $parent: true,
1570
- $scrollLeft: true,
1571
- $scrollTop: true,
1572
- $scrollX: true,
1573
- $scrollY: true,
1574
- $self: true,
1575
- $webkitIndexedDB: true,
1576
- $webkitStorageInfo: true,
1577
- $window: true
1578
- };
1579
- var hasAutomationEqualityBug = (function () {
1580
- /* global window */
1581
- if (typeof window === 'undefined') { return false; }
1582
- for (var k in window) {
1583
- try {
1584
- if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') {
1585
- try {
1586
- equalsConstructorPrototype(window[k]);
1587
- } catch (e) {
1588
- return true;
1589
- }
1590
- }
1591
- } catch (e) {
1592
- return true;
1593
- }
1594
- }
1595
- return false;
1596
- }());
1597
- var equalsConstructorPrototypeIfNotBuggy = function (o) {
1598
- /* global window */
1599
- if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
1600
- return equalsConstructorPrototype(o);
1601
- }
1602
- try {
1603
- return equalsConstructorPrototype(o);
1604
- } catch (e) {
1605
- return false;
1606
- }
1607
- };
1608
-
1609
- keysShim = function keys(object) {
1610
- var isObject = object !== null && typeof object === 'object';
1611
- var isFunction = toStr$1.call(object) === '[object Function]';
1612
- var isArguments = isArgs(object);
1613
- var isString = isObject && toStr$1.call(object) === '[object String]';
1614
- var theKeys = [];
1615
-
1616
- if (!isObject && !isFunction && !isArguments) {
1617
- throw new TypeError('Object.keys called on a non-object');
1618
- }
1619
-
1620
- var skipProto = hasProtoEnumBug && isFunction;
1621
- if (isString && object.length > 0 && !has.call(object, 0)) {
1622
- for (var i = 0; i < object.length; ++i) {
1623
- theKeys.push(String(i));
1624
- }
1625
- }
1626
-
1627
- if (isArguments && object.length > 0) {
1628
- for (var j = 0; j < object.length; ++j) {
1629
- theKeys.push(String(j));
1630
- }
1631
- } else {
1632
- for (var name in object) {
1633
- if (!(skipProto && name === 'prototype') && has.call(object, name)) {
1634
- theKeys.push(String(name));
1635
- }
1636
- }
1637
- }
1638
-
1639
- if (hasDontEnumBug) {
1640
- var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
1641
-
1642
- for (var k = 0; k < dontEnums.length; ++k) {
1643
- if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) {
1644
- theKeys.push(dontEnums[k]);
1645
- }
1646
- }
1647
- }
1648
- return theKeys;
1649
- };
1650
- }
1651
- var implementation = keysShim;
1652
-
1653
- var slice = Array.prototype.slice;
1654
-
1655
-
1656
- var origKeys = Object.keys;
1657
- var keysShim$1 = origKeys ? function keys(o) { return origKeys(o); } : implementation;
1658
-
1659
- var originalKeys = Object.keys;
1660
-
1661
- keysShim$1.shim = function shimObjectKeys() {
1662
- if (Object.keys) {
1663
- var keysWorksWithArguments = (function () {
1664
- // Safari 5.0 bug
1665
- var args = Object.keys(arguments);
1666
- return args && args.length === arguments.length;
1667
- }(1, 2));
1668
- if (!keysWorksWithArguments) {
1669
- Object.keys = function keys(object) { // eslint-disable-line func-name-matching
1670
- if (isArguments(object)) {
1671
- return originalKeys(slice.call(object));
1672
- }
1673
- return originalKeys(object);
1674
- };
1675
- }
1676
- } else {
1677
- Object.keys = keysShim$1;
1678
- }
1679
- return Object.keys || keysShim$1;
1680
- };
1681
-
1682
- var objectKeys = keysShim$1;
1683
-
1684
- var hasSymbols = typeof Symbol === 'function' && typeof Symbol('foo') === 'symbol';
1685
-
1686
- var toStr$2 = Object.prototype.toString;
1687
- var concat = Array.prototype.concat;
1688
- var origDefineProperty = Object.defineProperty;
1689
-
1690
- var isFunction = function (fn) {
1691
- return typeof fn === 'function' && toStr$2.call(fn) === '[object Function]';
1692
- };
1693
-
1694
- var arePropertyDescriptorsSupported = function () {
1695
- var obj = {};
1696
- try {
1697
- origDefineProperty(obj, 'x', { enumerable: false, value: obj });
1698
- // eslint-disable-next-line no-unused-vars, no-restricted-syntax
1699
- for (var _ in obj) { // jscs:ignore disallowUnusedVariables
1700
- return false;
1701
- }
1702
- return obj.x === obj;
1703
- } catch (e) { /* this is IE 8. */
1704
- return false;
1705
- }
1706
- };
1707
- var supportsDescriptors = origDefineProperty && arePropertyDescriptorsSupported();
1708
-
1709
- var defineProperty = function (object, name, value, predicate) {
1710
- if (name in object && (!isFunction(predicate) || !predicate())) {
1711
- return;
1712
- }
1713
- if (supportsDescriptors) {
1714
- origDefineProperty(object, name, {
1715
- configurable: true,
1716
- enumerable: false,
1717
- value: value,
1718
- writable: true
1719
- });
1720
- } else {
1721
- object[name] = value;
1722
- }
1723
- };
1724
-
1725
- var defineProperties = function (object, map) {
1726
- var predicates = arguments.length > 2 ? arguments[2] : {};
1727
- var props = objectKeys(map);
1728
- if (hasSymbols) {
1729
- props = concat.call(props, Object.getOwnPropertySymbols(map));
1730
- }
1731
- for (var i = 0; i < props.length; i += 1) {
1732
- defineProperty(object, props[i], map[props[i]], predicates[props[i]]);
1733
- }
1734
- };
1735
-
1736
- defineProperties.supportsDescriptors = !!supportsDescriptors;
1737
-
1738
- var defineProperties_1 = defineProperties;
1739
-
1740
- /* eslint complexity: [2, 18], max-statements: [2, 33] */
1741
- var shams = function hasSymbols() {
1742
- if (typeof Symbol !== 'function' || typeof Object.getOwnPropertySymbols !== 'function') { return false; }
1743
- if (typeof Symbol.iterator === 'symbol') { return true; }
1744
-
1745
- var obj = {};
1746
- var sym = Symbol('test');
1747
- var symObj = Object(sym);
1748
- if (typeof sym === 'string') { return false; }
1749
-
1750
- if (Object.prototype.toString.call(sym) !== '[object Symbol]') { return false; }
1751
- if (Object.prototype.toString.call(symObj) !== '[object Symbol]') { return false; }
1752
-
1753
- // temp disabled per https://github.com/ljharb/object.assign/issues/17
1754
- // if (sym instanceof Symbol) { return false; }
1755
- // temp disabled per https://github.com/WebReflection/get-own-property-symbols/issues/4
1756
- // if (!(symObj instanceof Symbol)) { return false; }
1757
-
1758
- // if (typeof Symbol.prototype.toString !== 'function') { return false; }
1759
- // if (String(sym) !== Symbol.prototype.toString.call(sym)) { return false; }
1760
-
1761
- var symVal = 42;
1762
- obj[sym] = symVal;
1763
- for (sym in obj) { return false; } // eslint-disable-line no-restricted-syntax
1764
- if (typeof Object.keys === 'function' && Object.keys(obj).length !== 0) { return false; }
1765
-
1766
- if (typeof Object.getOwnPropertyNames === 'function' && Object.getOwnPropertyNames(obj).length !== 0) { return false; }
1767
-
1768
- var syms = Object.getOwnPropertySymbols(obj);
1769
- if (syms.length !== 1 || syms[0] !== sym) { return false; }
1770
-
1771
- if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) { return false; }
1772
-
1773
- if (typeof Object.getOwnPropertyDescriptor === 'function') {
1774
- var descriptor = Object.getOwnPropertyDescriptor(obj, sym);
1775
- if (descriptor.value !== symVal || descriptor.enumerable !== true) { return false; }
1776
- }
1777
-
1778
- return true;
1779
- };
1780
-
1781
- var origSymbol = commonjsGlobal.Symbol;
1782
-
1783
-
1784
- var hasSymbols$1 = function hasNativeSymbols() {
1785
- if (typeof origSymbol !== 'function') { return false; }
1786
- if (typeof Symbol !== 'function') { return false; }
1787
- if (typeof origSymbol('foo') !== 'symbol') { return false; }
1788
- if (typeof Symbol('bar') !== 'symbol') { return false; }
1789
-
1790
- return shams();
1791
- };
1792
-
1793
- /* eslint no-invalid-this: 1 */
1794
-
1795
- var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible ';
1796
- var slice$1 = Array.prototype.slice;
1797
- var toStr$3 = Object.prototype.toString;
1798
- var funcType = '[object Function]';
1799
-
1800
- var implementation$1 = function bind(that) {
1801
- var target = this;
1802
- if (typeof target !== 'function' || toStr$3.call(target) !== funcType) {
1803
- throw new TypeError(ERROR_MESSAGE + target);
1804
- }
1805
- var args = slice$1.call(arguments, 1);
1806
-
1807
- var bound;
1808
- var binder = function () {
1809
- if (this instanceof bound) {
1810
- var result = target.apply(
1811
- this,
1812
- args.concat(slice$1.call(arguments))
1813
- );
1814
- if (Object(result) === result) {
1815
- return result;
1816
- }
1817
- return this;
1818
- } else {
1819
- return target.apply(
1820
- that,
1821
- args.concat(slice$1.call(arguments))
1822
- );
1823
- }
1824
- };
1825
-
1826
- var boundLength = Math.max(0, target.length - args.length);
1827
- var boundArgs = [];
1828
- for (var i = 0; i < boundLength; i++) {
1829
- boundArgs.push('$' + i);
1830
- }
1831
-
1832
- bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this,arguments); }')(binder);
1833
-
1834
- if (target.prototype) {
1835
- var Empty = function Empty() {};
1836
- Empty.prototype = target.prototype;
1837
- bound.prototype = new Empty();
1838
- Empty.prototype = null;
1839
- }
1840
-
1841
- return bound;
1842
- };
1843
-
1844
- var functionBind = Function.prototype.bind || implementation$1;
1845
-
1846
- /* globals
1847
- Atomics,
1848
- SharedArrayBuffer,
1849
- */
1850
-
1851
- var undefined$1;
1852
-
1853
- var $TypeError = TypeError;
1854
-
1855
- var $gOPD = Object.getOwnPropertyDescriptor;
1856
- if ($gOPD) {
1857
- try {
1858
- $gOPD({}, '');
1859
- } catch (e) {
1860
- $gOPD = null; // this is IE 8, which has a broken gOPD
1861
- }
1862
- }
1863
-
1864
- var throwTypeError = function () { throw new $TypeError(); };
1865
- var ThrowTypeError = $gOPD
1866
- ? (function () {
1867
- try {
1868
- // eslint-disable-next-line no-unused-expressions, no-caller, no-restricted-properties
1869
- arguments.callee; // IE 8 does not throw here
1870
- return throwTypeError;
1871
- } catch (calleeThrows) {
1872
- try {
1873
- // IE 8 throws on Object.getOwnPropertyDescriptor(arguments, '')
1874
- return $gOPD(arguments, 'callee').get;
1875
- } catch (gOPDthrows) {
1876
- return throwTypeError;
1877
- }
1878
- }
1879
- }())
1880
- : throwTypeError;
1881
-
1882
- var hasSymbols$2 = hasSymbols$1();
1883
-
1884
- var getProto = Object.getPrototypeOf || function (x) { return x.__proto__; }; // eslint-disable-line no-proto
1885
- var generatorFunction = undefined$1;
1886
- var asyncFunction = undefined$1;
1887
- var asyncGenFunction = undefined$1;
1888
-
1889
- var TypedArray = typeof Uint8Array === 'undefined' ? undefined$1 : getProto(Uint8Array);
1890
-
1891
- var INTRINSICS = {
1892
- '%Array%': Array,
1893
- '%ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined$1 : ArrayBuffer,
1894
- '%ArrayBufferPrototype%': typeof ArrayBuffer === 'undefined' ? undefined$1 : ArrayBuffer.prototype,
1895
- '%ArrayIteratorPrototype%': hasSymbols$2 ? getProto([][Symbol.iterator]()) : undefined$1,
1896
- '%ArrayPrototype%': Array.prototype,
1897
- '%ArrayProto_entries%': Array.prototype.entries,
1898
- '%ArrayProto_forEach%': Array.prototype.forEach,
1899
- '%ArrayProto_keys%': Array.prototype.keys,
1900
- '%ArrayProto_values%': Array.prototype.values,
1901
- '%AsyncFromSyncIteratorPrototype%': undefined$1,
1902
- '%AsyncFunction%': asyncFunction,
1903
- '%AsyncFunctionPrototype%': undefined$1,
1904
- '%AsyncGenerator%': undefined$1,
1905
- '%AsyncGeneratorFunction%': asyncGenFunction,
1906
- '%AsyncGeneratorPrototype%': undefined$1,
1907
- '%AsyncIteratorPrototype%': undefined$1,
1908
- '%Atomics%': typeof Atomics === 'undefined' ? undefined$1 : Atomics,
1909
- '%Boolean%': Boolean,
1910
- '%BooleanPrototype%': Boolean.prototype,
1911
- '%DataView%': typeof DataView === 'undefined' ? undefined$1 : DataView,
1912
- '%DataViewPrototype%': typeof DataView === 'undefined' ? undefined$1 : DataView.prototype,
1913
- '%Date%': Date,
1914
- '%DatePrototype%': Date.prototype,
1915
- '%decodeURI%': decodeURI,
1916
- '%decodeURIComponent%': decodeURIComponent,
1917
- '%encodeURI%': encodeURI,
1918
- '%encodeURIComponent%': encodeURIComponent,
1919
- '%Error%': Error,
1920
- '%ErrorPrototype%': Error.prototype,
1921
- '%eval%': eval, // eslint-disable-line no-eval
1922
- '%EvalError%': EvalError,
1923
- '%EvalErrorPrototype%': EvalError.prototype,
1924
- '%Float32Array%': typeof Float32Array === 'undefined' ? undefined$1 : Float32Array,
1925
- '%Float32ArrayPrototype%': typeof Float32Array === 'undefined' ? undefined$1 : Float32Array.prototype,
1926
- '%Float64Array%': typeof Float64Array === 'undefined' ? undefined$1 : Float64Array,
1927
- '%Float64ArrayPrototype%': typeof Float64Array === 'undefined' ? undefined$1 : Float64Array.prototype,
1928
- '%Function%': Function,
1929
- '%FunctionPrototype%': Function.prototype,
1930
- '%Generator%': undefined$1,
1931
- '%GeneratorFunction%': generatorFunction,
1932
- '%GeneratorPrototype%': undefined$1,
1933
- '%Int8Array%': typeof Int8Array === 'undefined' ? undefined$1 : Int8Array,
1934
- '%Int8ArrayPrototype%': typeof Int8Array === 'undefined' ? undefined$1 : Int8Array.prototype,
1935
- '%Int16Array%': typeof Int16Array === 'undefined' ? undefined$1 : Int16Array,
1936
- '%Int16ArrayPrototype%': typeof Int16Array === 'undefined' ? undefined$1 : Int8Array.prototype,
1937
- '%Int32Array%': typeof Int32Array === 'undefined' ? undefined$1 : Int32Array,
1938
- '%Int32ArrayPrototype%': typeof Int32Array === 'undefined' ? undefined$1 : Int32Array.prototype,
1939
- '%isFinite%': isFinite,
1940
- '%isNaN%': isNaN,
1941
- '%IteratorPrototype%': hasSymbols$2 ? getProto(getProto([][Symbol.iterator]())) : undefined$1,
1942
- '%JSON%': typeof JSON === 'object' ? JSON : undefined$1,
1943
- '%JSONParse%': typeof JSON === 'object' ? JSON.parse : undefined$1,
1944
- '%Map%': typeof Map === 'undefined' ? undefined$1 : Map,
1945
- '%MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols$2 ? undefined$1 : getProto(new Map()[Symbol.iterator]()),
1946
- '%MapPrototype%': typeof Map === 'undefined' ? undefined$1 : Map.prototype,
1947
- '%Math%': Math,
1948
- '%Number%': Number,
1949
- '%NumberPrototype%': Number.prototype,
1950
- '%Object%': Object,
1951
- '%ObjectPrototype%': Object.prototype,
1952
- '%ObjProto_toString%': Object.prototype.toString,
1953
- '%ObjProto_valueOf%': Object.prototype.valueOf,
1954
- '%parseFloat%': parseFloat,
1955
- '%parseInt%': parseInt,
1956
- '%Promise%': typeof Promise === 'undefined' ? undefined$1 : Promise,
1957
- '%PromisePrototype%': typeof Promise === 'undefined' ? undefined$1 : Promise.prototype,
1958
- '%PromiseProto_then%': typeof Promise === 'undefined' ? undefined$1 : Promise.prototype.then,
1959
- '%Promise_all%': typeof Promise === 'undefined' ? undefined$1 : Promise.all,
1960
- '%Promise_reject%': typeof Promise === 'undefined' ? undefined$1 : Promise.reject,
1961
- '%Promise_resolve%': typeof Promise === 'undefined' ? undefined$1 : Promise.resolve,
1962
- '%Proxy%': typeof Proxy === 'undefined' ? undefined$1 : Proxy,
1963
- '%RangeError%': RangeError,
1964
- '%RangeErrorPrototype%': RangeError.prototype,
1965
- '%ReferenceError%': ReferenceError,
1966
- '%ReferenceErrorPrototype%': ReferenceError.prototype,
1967
- '%Reflect%': typeof Reflect === 'undefined' ? undefined$1 : Reflect,
1968
- '%RegExp%': RegExp,
1969
- '%RegExpPrototype%': RegExp.prototype,
1970
- '%Set%': typeof Set === 'undefined' ? undefined$1 : Set,
1971
- '%SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols$2 ? undefined$1 : getProto(new Set()[Symbol.iterator]()),
1972
- '%SetPrototype%': typeof Set === 'undefined' ? undefined$1 : Set.prototype,
1973
- '%SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined$1 : SharedArrayBuffer,
1974
- '%SharedArrayBufferPrototype%': typeof SharedArrayBuffer === 'undefined' ? undefined$1 : SharedArrayBuffer.prototype,
1975
- '%String%': String,
1976
- '%StringIteratorPrototype%': hasSymbols$2 ? getProto(''[Symbol.iterator]()) : undefined$1,
1977
- '%StringPrototype%': String.prototype,
1978
- '%Symbol%': hasSymbols$2 ? Symbol : undefined$1,
1979
- '%SymbolPrototype%': hasSymbols$2 ? Symbol.prototype : undefined$1,
1980
- '%SyntaxError%': SyntaxError,
1981
- '%SyntaxErrorPrototype%': SyntaxError.prototype,
1982
- '%ThrowTypeError%': ThrowTypeError,
1983
- '%TypedArray%': TypedArray,
1984
- '%TypedArrayPrototype%': TypedArray ? TypedArray.prototype : undefined$1,
1985
- '%TypeError%': $TypeError,
1986
- '%TypeErrorPrototype%': $TypeError.prototype,
1987
- '%Uint8Array%': typeof Uint8Array === 'undefined' ? undefined$1 : Uint8Array,
1988
- '%Uint8ArrayPrototype%': typeof Uint8Array === 'undefined' ? undefined$1 : Uint8Array.prototype,
1989
- '%Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined$1 : Uint8ClampedArray,
1990
- '%Uint8ClampedArrayPrototype%': typeof Uint8ClampedArray === 'undefined' ? undefined$1 : Uint8ClampedArray.prototype,
1991
- '%Uint16Array%': typeof Uint16Array === 'undefined' ? undefined$1 : Uint16Array,
1992
- '%Uint16ArrayPrototype%': typeof Uint16Array === 'undefined' ? undefined$1 : Uint16Array.prototype,
1993
- '%Uint32Array%': typeof Uint32Array === 'undefined' ? undefined$1 : Uint32Array,
1994
- '%Uint32ArrayPrototype%': typeof Uint32Array === 'undefined' ? undefined$1 : Uint32Array.prototype,
1995
- '%URIError%': URIError,
1996
- '%URIErrorPrototype%': URIError.prototype,
1997
- '%WeakMap%': typeof WeakMap === 'undefined' ? undefined$1 : WeakMap,
1998
- '%WeakMapPrototype%': typeof WeakMap === 'undefined' ? undefined$1 : WeakMap.prototype,
1999
- '%WeakSet%': typeof WeakSet === 'undefined' ? undefined$1 : WeakSet,
2000
- '%WeakSetPrototype%': typeof WeakSet === 'undefined' ? undefined$1 : WeakSet.prototype
2001
- };
2002
-
2003
-
2004
- var $replace = functionBind.call(Function.call, String.prototype.replace);
2005
-
2006
- /* adapted from https://github.com/lodash/lodash/blob/4.17.15/dist/lodash.js#L6735-L6744 */
2007
- var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g;
2008
- var reEscapeChar = /\\(\\)?/g; /** Used to match backslashes in property paths. */
2009
- var stringToPath = function stringToPath(string) {
2010
- var result = [];
2011
- $replace(string, rePropName, function (match, number, quote, subString) {
2012
- result[result.length] = quote ? $replace(subString, reEscapeChar, '$1') : (number || match);
2013
- });
2014
- return result;
2015
- };
2016
- /* end adaptation */
2017
-
2018
- var getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) {
2019
- if (!(name in INTRINSICS)) {
2020
- throw new SyntaxError('intrinsic ' + name + ' does not exist!');
2021
- }
2022
-
2023
- // istanbul ignore if // hopefully this is impossible to test :-)
2024
- if (typeof INTRINSICS[name] === 'undefined' && !allowMissing) {
2025
- throw new $TypeError('intrinsic ' + name + ' exists, but is not available. Please file an issue!');
2026
- }
2027
-
2028
- return INTRINSICS[name];
2029
- };
2030
-
2031
- var GetIntrinsic = function GetIntrinsic(name, allowMissing) {
2032
- if (typeof name !== 'string' || name.length === 0) {
2033
- throw new TypeError('intrinsic name must be a non-empty string');
2034
- }
2035
- if (arguments.length > 1 && typeof allowMissing !== 'boolean') {
2036
- throw new TypeError('"allowMissing" argument must be a boolean');
2037
- }
2038
-
2039
- var parts = stringToPath(name);
2040
-
2041
- var value = getBaseIntrinsic('%' + (parts.length > 0 ? parts[0] : '') + '%', allowMissing);
2042
- for (var i = 1; i < parts.length; i += 1) {
2043
- if (value != null) {
2044
- if ($gOPD && (i + 1) >= parts.length) {
2045
- var desc = $gOPD(value, parts[i]);
2046
- if (!allowMissing && !(parts[i] in value)) {
2047
- throw new $TypeError('base intrinsic for ' + name + ' exists, but the property is not available.');
2048
- }
2049
- value = desc ? (desc.get || desc.value) : value[parts[i]];
2050
- } else {
2051
- value = value[parts[i]];
2052
- }
2053
- }
2054
- }
2055
- return value;
2056
- };
2057
-
2058
- var $Function = GetIntrinsic('%Function%');
2059
- var $apply = $Function.apply;
2060
- var $call = $Function.call;
2061
-
2062
- var callBind = function callBind() {
2063
- return functionBind.apply($call, arguments);
2064
- };
2065
-
2066
- var apply = function applyBind() {
2067
- return functionBind.apply($apply, arguments);
2068
- };
2069
- callBind.apply = apply;
2070
-
2071
- var $indexOf = callBind(GetIntrinsic('String.prototype.indexOf'));
2072
-
2073
- var callBound = function callBoundIntrinsic(name, allowMissing) {
2074
- var intrinsic = GetIntrinsic(name, !!allowMissing);
2075
- if (typeof intrinsic === 'function' && $indexOf(name, '.prototype.')) {
2076
- return callBind(intrinsic);
2077
- }
2078
- return intrinsic;
2079
- };
2080
-
2081
- var $defineProperty = GetIntrinsic('%Object.defineProperty%', true);
2082
-
2083
- if ($defineProperty) {
2084
- try {
2085
- $defineProperty({}, 'a', { value: 1 });
2086
- } catch (e) {
2087
- // IE 8 has a broken defineProperty
2088
- $defineProperty = null;
2089
- }
2090
- }
2091
-
2092
-
2093
-
2094
- var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
2095
-
2096
- // eslint-disable-next-line max-params
2097
- var DefineOwnProperty = function DefineOwnProperty(IsDataDescriptor, SameValue, FromPropertyDescriptor, O, P, desc) {
2098
- if (!$defineProperty) {
2099
- if (!IsDataDescriptor(desc)) {
2100
- // ES3 does not support getters/setters
2101
- return false;
2102
- }
2103
- if (!desc['[[Configurable]]'] || !desc['[[Writable]]']) {
2104
- return false;
2105
- }
2106
-
2107
- // fallback for ES3
2108
- if (P in O && $isEnumerable(O, P) !== !!desc['[[Enumerable]]']) {
2109
- // a non-enumerable existing property
2110
- return false;
2111
- }
2112
-
2113
- // property does not exist at all, or exists but is enumerable
2114
- var V = desc['[[Value]]'];
2115
- // eslint-disable-next-line no-param-reassign
2116
- O[P] = V; // will use [[Define]]
2117
- return SameValue(O[P], V);
2118
- }
2119
- $defineProperty(O, P, FromPropertyDescriptor(desc));
2120
- return true;
2121
- };
2122
-
2123
- var src = functionBind.call(Function.call, Object.prototype.hasOwnProperty);
2124
-
2125
- var $TypeError$1 = GetIntrinsic('%TypeError%');
2126
- var $SyntaxError = GetIntrinsic('%SyntaxError%');
2127
-
2128
-
2129
-
2130
- var predicates = {
2131
- // https://ecma-international.org/ecma-262/6.0/#sec-property-descriptor-specification-type
2132
- 'Property Descriptor': function isPropertyDescriptor(Type, Desc) {
2133
- if (Type(Desc) !== 'Object') {
2134
- return false;
2135
- }
2136
- var allowed = {
2137
- '[[Configurable]]': true,
2138
- '[[Enumerable]]': true,
2139
- '[[Get]]': true,
2140
- '[[Set]]': true,
2141
- '[[Value]]': true,
2142
- '[[Writable]]': true
2143
- };
2144
-
2145
- for (var key in Desc) { // eslint-disable-line
2146
- if (src(Desc, key) && !allowed[key]) {
2147
- return false;
2148
- }
2149
- }
2150
-
2151
- var isData = src(Desc, '[[Value]]');
2152
- var IsAccessor = src(Desc, '[[Get]]') || src(Desc, '[[Set]]');
2153
- if (isData && IsAccessor) {
2154
- throw new $TypeError$1('Property Descriptors may not be both accessor and data descriptors');
2155
- }
2156
- return true;
2157
- }
2158
- };
2159
-
2160
- var assertRecord = function assertRecord(Type, recordType, argumentName, value) {
2161
- var predicate = predicates[recordType];
2162
- if (typeof predicate !== 'function') {
2163
- throw new $SyntaxError('unknown record type: ' + recordType);
2164
- }
2165
- if (!predicate(Type, value)) {
2166
- throw new $TypeError$1(argumentName + ' must be a ' + recordType);
2167
- }
2168
- };
2169
-
2170
- // https://www.ecma-international.org/ecma-262/5.1/#sec-8
2171
-
2172
- var Type = function Type(x) {
2173
- if (x === null) {
2174
- return 'Null';
2175
- }
2176
- if (typeof x === 'undefined') {
2177
- return 'Undefined';
2178
- }
2179
- if (typeof x === 'function' || typeof x === 'object') {
2180
- return 'Object';
2181
- }
2182
- if (typeof x === 'number') {
2183
- return 'Number';
2184
- }
2185
- if (typeof x === 'boolean') {
2186
- return 'Boolean';
2187
- }
2188
- if (typeof x === 'string') {
2189
- return 'String';
2190
- }
2191
- };
2192
-
2193
- // https://www.ecma-international.org/ecma-262/6.0/#sec-tostring
2194
-
2195
- var Type$1 = function Type$1(x) {
2196
- if (typeof x === 'symbol') {
2197
- return 'Symbol';
2198
- }
2199
- return Type(x);
2200
- };
2201
-
2202
- // https://www.ecma-international.org/ecma-262/6.0/#sec-frompropertydescriptor
2203
-
2204
- var FromPropertyDescriptor = function FromPropertyDescriptor(Desc) {
2205
- if (typeof Desc === 'undefined') {
2206
- return Desc;
2207
- }
2208
-
2209
- assertRecord(Type$1, 'Property Descriptor', 'Desc', Desc);
2210
-
2211
- var obj = {};
2212
- if ('[[Value]]' in Desc) {
2213
- obj.value = Desc['[[Value]]'];
2214
- }
2215
- if ('[[Writable]]' in Desc) {
2216
- obj.writable = Desc['[[Writable]]'];
2217
- }
2218
- if ('[[Get]]' in Desc) {
2219
- obj.get = Desc['[[Get]]'];
2220
- }
2221
- if ('[[Set]]' in Desc) {
2222
- obj.set = Desc['[[Set]]'];
2223
- }
2224
- if ('[[Enumerable]]' in Desc) {
2225
- obj.enumerable = Desc['[[Enumerable]]'];
2226
- }
2227
- if ('[[Configurable]]' in Desc) {
2228
- obj.configurable = Desc['[[Configurable]]'];
2229
- }
2230
- return obj;
2231
- };
2232
-
2233
- var $gOPD$1 = GetIntrinsic('%Object.getOwnPropertyDescriptor%');
2234
- if ($gOPD$1) {
2235
- try {
2236
- $gOPD$1([], 'length');
2237
- } catch (e) {
2238
- // IE 8 has a broken gOPD
2239
- $gOPD$1 = null;
2240
- }
2241
- }
2242
-
2243
- var getOwnPropertyDescriptor = $gOPD$1;
2244
-
2245
- var $Array = GetIntrinsic('%Array%');
2246
-
2247
- // eslint-disable-next-line global-require
2248
- var toStr$4 = !$Array.isArray && callBound('Object.prototype.toString');
2249
-
2250
- // https://www.ecma-international.org/ecma-262/6.0/#sec-isarray
2251
-
2252
- var IsArray = $Array.isArray || function IsArray(argument) {
2253
- return toStr$4(argument) === '[object Array]';
2254
- };
2255
-
2256
- // https://www.ecma-international.org/ecma-262/6.0/#sec-ispropertykey
2257
-
2258
- var IsPropertyKey = function IsPropertyKey(argument) {
2259
- return typeof argument === 'string' || typeof argument === 'symbol';
2260
- };
2261
-
2262
- var regexExec = RegExp.prototype.exec;
2263
- var gOPD = Object.getOwnPropertyDescriptor;
2264
-
2265
- var tryRegexExecCall = function tryRegexExec(value) {
2266
- try {
2267
- var lastIndex = value.lastIndex;
2268
- value.lastIndex = 0; // eslint-disable-line no-param-reassign
2269
-
2270
- regexExec.call(value);
2271
- return true;
2272
- } catch (e) {
2273
- return false;
2274
- } finally {
2275
- value.lastIndex = lastIndex; // eslint-disable-line no-param-reassign
2276
- }
2277
- };
2278
- var toStr$5 = Object.prototype.toString;
2279
- var regexClass = '[object RegExp]';
2280
- var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
2281
-
2282
- var isRegex = function isRegex(value) {
2283
- if (!value || typeof value !== 'object') {
2284
- return false;
2285
- }
2286
- if (!hasToStringTag) {
2287
- return toStr$5.call(value) === regexClass;
2288
- }
2289
-
2290
- var descriptor = gOPD(value, 'lastIndex');
2291
- var hasLastIndexDataProperty = descriptor && src(descriptor, 'value');
2292
- if (!hasLastIndexDataProperty) {
2293
- return false;
2294
- }
2295
-
2296
- return tryRegexExecCall(value);
2297
- };
2298
-
2299
- // http://www.ecma-international.org/ecma-262/5.1/#sec-9.2
2300
-
2301
- var ToBoolean = function ToBoolean(value) { return !!value; };
2302
-
2303
- var $match = GetIntrinsic('%Symbol.match%', true);
2304
-
2305
-
2306
-
2307
-
2308
-
2309
- // https://ecma-international.org/ecma-262/6.0/#sec-isregexp
2310
-
2311
- var IsRegExp = function IsRegExp(argument) {
2312
- if (!argument || typeof argument !== 'object') {
2313
- return false;
2314
- }
2315
- if ($match) {
2316
- var isRegExp = argument[$match];
2317
- if (typeof isRegExp !== 'undefined') {
2318
- return ToBoolean(isRegExp);
2319
- }
2320
- }
2321
- return isRegex(argument);
2322
- };
2323
-
2324
- var fnToStr = Function.prototype.toString;
2325
-
2326
- var constructorRegex = /^\s*class\b/;
2327
- var isES6ClassFn = function isES6ClassFunction(value) {
2328
- try {
2329
- var fnStr = fnToStr.call(value);
2330
- return constructorRegex.test(fnStr);
2331
- } catch (e) {
2332
- return false; // not a function
2333
- }
2334
- };
2335
-
2336
- var tryFunctionObject = function tryFunctionToStr(value) {
2337
- try {
2338
- if (isES6ClassFn(value)) { return false; }
2339
- fnToStr.call(value);
2340
- return true;
2341
- } catch (e) {
2342
- return false;
2343
- }
2344
- };
2345
- var toStr$6 = Object.prototype.toString;
2346
- var fnClass = '[object Function]';
2347
- var genClass = '[object GeneratorFunction]';
2348
- var hasToStringTag$1 = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
2349
-
2350
- var isCallable = function isCallable(value) {
2351
- if (!value) { return false; }
2352
- if (typeof value !== 'function' && typeof value !== 'object') { return false; }
2353
- if (typeof value === 'function' && !value.prototype) { return true; }
2354
- if (hasToStringTag$1) { return tryFunctionObject(value); }
2355
- if (isES6ClassFn(value)) { return false; }
2356
- var strClass = toStr$6.call(value);
2357
- return strClass === fnClass || strClass === genClass;
2358
- };
2359
-
2360
- // http://www.ecma-international.org/ecma-262/5.1/#sec-9.11
2361
-
2362
- var IsCallable = isCallable;
2363
-
2364
- var $TypeError$2 = GetIntrinsic('%TypeError%');
2365
-
2366
-
2367
-
2368
-
2369
-
2370
- // https://ecma-international.org/ecma-262/5.1/#sec-8.10.5
2371
-
2372
- var ToPropertyDescriptor = function ToPropertyDescriptor(Obj) {
2373
- if (Type$1(Obj) !== 'Object') {
2374
- throw new $TypeError$2('ToPropertyDescriptor requires an object');
2375
- }
2376
-
2377
- var desc = {};
2378
- if (src(Obj, 'enumerable')) {
2379
- desc['[[Enumerable]]'] = ToBoolean(Obj.enumerable);
2380
- }
2381
- if (src(Obj, 'configurable')) {
2382
- desc['[[Configurable]]'] = ToBoolean(Obj.configurable);
2383
- }
2384
- if (src(Obj, 'value')) {
2385
- desc['[[Value]]'] = Obj.value;
2386
- }
2387
- if (src(Obj, 'writable')) {
2388
- desc['[[Writable]]'] = ToBoolean(Obj.writable);
2389
- }
2390
- if (src(Obj, 'get')) {
2391
- var getter = Obj.get;
2392
- if (typeof getter !== 'undefined' && !IsCallable(getter)) {
2393
- throw new TypeError('getter must be a function');
2394
- }
2395
- desc['[[Get]]'] = getter;
2396
- }
2397
- if (src(Obj, 'set')) {
2398
- var setter = Obj.set;
2399
- if (typeof setter !== 'undefined' && !IsCallable(setter)) {
2400
- throw new $TypeError$2('setter must be a function');
2401
- }
2402
- desc['[[Set]]'] = setter;
2403
- }
2404
-
2405
- if ((src(desc, '[[Get]]') || src(desc, '[[Set]]')) && (src(desc, '[[Value]]') || src(desc, '[[Writable]]'))) {
2406
- throw new $TypeError$2('Invalid property descriptor. Cannot both specify accessors and a value or writable attribute');
2407
- }
2408
- return desc;
2409
- };
2410
-
2411
- var $TypeError$3 = GetIntrinsic('%TypeError%');
2412
-
2413
-
2414
-
2415
- var $isEnumerable$1 = callBound('Object.prototype.propertyIsEnumerable');
2416
-
2417
-
2418
-
2419
-
2420
-
2421
-
2422
-
2423
-
2424
-
2425
- // https://www.ecma-international.org/ecma-262/6.0/#sec-ordinarygetownproperty
2426
-
2427
- var OrdinaryGetOwnProperty = function OrdinaryGetOwnProperty(O, P) {
2428
- if (Type$1(O) !== 'Object') {
2429
- throw new $TypeError$3('Assertion failed: O must be an Object');
2430
- }
2431
- if (!IsPropertyKey(P)) {
2432
- throw new $TypeError$3('Assertion failed: P must be a Property Key');
2433
- }
2434
- if (!src(O, P)) {
2435
- return void 0;
2436
- }
2437
- if (!getOwnPropertyDescriptor) {
2438
- // ES3 / IE 8 fallback
2439
- var arrayLength = IsArray(O) && P === 'length';
2440
- var regexLastIndex = IsRegExp(O) && P === 'lastIndex';
2441
- return {
2442
- '[[Configurable]]': !(arrayLength || regexLastIndex),
2443
- '[[Enumerable]]': $isEnumerable$1(O, P),
2444
- '[[Value]]': O[P],
2445
- '[[Writable]]': true
2446
- };
2447
- }
2448
- return ToPropertyDescriptor(getOwnPropertyDescriptor(O, P));
2449
- };
2450
-
2451
- // https://www.ecma-international.org/ecma-262/6.0/#sec-isdatadescriptor
2452
-
2453
- var IsDataDescriptor = function IsDataDescriptor(Desc) {
2454
- if (typeof Desc === 'undefined') {
2455
- return false;
2456
- }
2457
-
2458
- assertRecord(Type$1, 'Property Descriptor', 'Desc', Desc);
2459
-
2460
- if (!src(Desc, '[[Value]]') && !src(Desc, '[[Writable]]')) {
2461
- return false;
2462
- }
2463
-
2464
- return true;
2465
- };
2466
-
2467
- var isPrimitive = function isPrimitive(value) {
2468
- return value === null || (typeof value !== 'function' && typeof value !== 'object');
2469
- };
2470
-
2471
- var $Object = GetIntrinsic('%Object%');
2472
-
2473
-
2474
-
2475
- var $preventExtensions = $Object.preventExtensions;
2476
- var $isExtensible = $Object.isExtensible;
2477
-
2478
- // https://www.ecma-international.org/ecma-262/6.0/#sec-isextensible-o
2479
-
2480
- var IsExtensible = $preventExtensions
2481
- ? function IsExtensible(obj) {
2482
- return !isPrimitive(obj) && $isExtensible(obj);
2483
- }
2484
- : function IsExtensible(obj) {
2485
- return !isPrimitive(obj);
2486
- };
2487
-
2488
- var _isNaN = Number.isNaN || function isNaN(a) {
2489
- return a !== a;
2490
- };
2491
-
2492
- // http://www.ecma-international.org/ecma-262/5.1/#sec-9.12
2493
-
2494
- var SameValue = function SameValue(x, y) {
2495
- if (x === y) { // 0 === -0, but they are not identical.
2496
- if (x === 0) { return 1 / x === 1 / y; }
2497
- return true;
2498
- }
2499
- return _isNaN(x) && _isNaN(y);
2500
- };
2501
-
2502
- var $TypeError$4 = GetIntrinsic('%TypeError%');
2503
-
2504
-
2505
-
2506
-
2507
-
2508
-
2509
-
2510
-
2511
-
2512
-
2513
-
2514
- // https://www.ecma-international.org/ecma-262/6.0/#sec-createdataproperty
2515
-
2516
- var CreateDataProperty = function CreateDataProperty(O, P, V) {
2517
- if (Type$1(O) !== 'Object') {
2518
- throw new $TypeError$4('Assertion failed: Type(O) is not Object');
2519
- }
2520
- if (!IsPropertyKey(P)) {
2521
- throw new $TypeError$4('Assertion failed: IsPropertyKey(P) is not true');
2522
- }
2523
- var oldDesc = OrdinaryGetOwnProperty(O, P);
2524
- var extensible = oldDesc || IsExtensible(O);
2525
- var immutable = oldDesc && (!oldDesc.writable || !oldDesc.configurable);
2526
- if (immutable || !extensible) {
2527
- return false;
2528
- }
2529
- return DefineOwnProperty(
2530
- IsDataDescriptor,
2531
- SameValue,
2532
- FromPropertyDescriptor,
2533
- O,
2534
- P,
2535
- {
2536
- '[[Configurable]]': true,
2537
- '[[Enumerable]]': true,
2538
- '[[Value]]': V,
2539
- '[[Writable]]': true
2540
- }
2541
- );
2542
- };
2543
-
2544
- var $TypeError$5 = GetIntrinsic('%TypeError%');
2545
-
2546
- // http://www.ecma-international.org/ecma-262/5.1/#sec-9.10
2547
-
2548
- var CheckObjectCoercible = function CheckObjectCoercible(value, optMessage) {
2549
- if (value == null) {
2550
- throw new $TypeError$5(optMessage || ('Cannot call method on ' + value));
2551
- }
2552
- return value;
2553
- };
2554
-
2555
- var RequireObjectCoercible = CheckObjectCoercible;
2556
-
2557
- var $Object$1 = GetIntrinsic('%Object%');
2558
-
2559
-
2560
-
2561
- // https://www.ecma-international.org/ecma-262/6.0/#sec-toobject
2562
-
2563
- var ToObject = function ToObject(value) {
2564
- RequireObjectCoercible(value);
2565
- return $Object$1(value);
2566
- };
2567
-
2568
- var $gOPD$2 = Object.getOwnPropertyDescriptor;
2569
- var $getOwnNames = Object.getOwnPropertyNames;
2570
- var $getSymbols = Object.getOwnPropertySymbols;
2571
- var $concat = callBound('Array.prototype.concat');
2572
- var $reduce = callBound('Array.prototype.reduce');
2573
- var getAll = $getSymbols ? function (obj) {
2574
- return $concat($getOwnNames(obj), $getSymbols(obj));
2575
- } : $getOwnNames;
2576
-
2577
- var isES5 = IsCallable($gOPD$2) && IsCallable($getOwnNames);
2578
-
2579
- var implementation$2 = function getOwnPropertyDescriptors(value) {
2580
- RequireObjectCoercible(value);
2581
- if (!isES5) {
2582
- throw new TypeError('getOwnPropertyDescriptors requires Object.getOwnPropertyDescriptor');
2583
- }
2584
-
2585
- var O = ToObject(value);
2586
- return $reduce(
2587
- getAll(O),
2588
- function (acc, key) {
2589
- var descriptor = $gOPD$2(O, key);
2590
- if (typeof descriptor !== 'undefined') {
2591
- CreateDataProperty(acc, key, descriptor);
2592
- }
2593
- return acc;
2594
- },
2595
- {}
2596
- );
2597
- };
2598
-
2599
- var polyfill = function getPolyfill() {
2600
- return typeof Object.getOwnPropertyDescriptors === 'function' ? Object.getOwnPropertyDescriptors : implementation$2;
2601
- };
2602
-
2603
- var shim = function shimGetOwnPropertyDescriptors() {
2604
- var polyfill$1 = polyfill();
2605
- defineProperties_1(
2606
- Object,
2607
- { getOwnPropertyDescriptors: polyfill$1 },
2608
- { getOwnPropertyDescriptors: function () { return Object.getOwnPropertyDescriptors !== polyfill$1; } }
2609
- );
2610
- return polyfill$1;
2611
- };
2612
-
2613
- defineProperties_1(implementation$2, {
2614
- getPolyfill: polyfill,
2615
- implementation: implementation$2,
2616
- shim: shim
2617
- });
2618
-
2619
- var object_getownpropertydescriptors = implementation$2;
2620
-
2621
- var isES5$1 = typeof Object.defineProperty === 'function'
2622
- && typeof Object.defineProperties === 'function';
2623
-
2624
- var hasProto = [].__proto__ === Array.prototype; // eslint-disable-line no-proto
2625
-
2626
- if (!isES5$1 || !hasProto) {
2627
- throw new TypeError('util.promisify requires a true ES5 environment, that also supports `__proto__`');
2628
- }
2629
-
2630
-
2631
-
2632
- if (typeof Promise !== 'function') {
2633
- throw new TypeError('`Promise` must be globally available for util.promisify to work.');
2634
- }
2635
-
2636
-
2637
-
2638
- var $slice = callBound('Array.prototype.slice');
2639
- var $concat$1 = callBound('Array.prototype.concat');
2640
- var $forEach = callBound('Array.prototype.forEach');
2641
-
2642
- var hasSymbols$3 = hasSymbols$1();
2643
-
2644
- var kCustomPromisifiedSymbol = hasSymbols$3 ? Symbol('util.promisify.custom') : null;
2645
- var kCustomPromisifyArgsSymbol = hasSymbols$3 ? Symbol('customPromisifyArgs') : null;
2646
-
2647
- var implementation$3 = function promisify(orig) {
2648
- if (typeof orig !== 'function') {
2649
- var error = new TypeError('The "original" argument must be of type function');
2650
- error.name = 'TypeError [ERR_INVALID_ARG_TYPE]';
2651
- error.code = 'ERR_INVALID_ARG_TYPE';
2652
- throw error;
2653
- }
2654
-
2655
- if (hasSymbols$3 && orig[kCustomPromisifiedSymbol]) {
2656
- var customFunction = orig[kCustomPromisifiedSymbol];
2657
- if (typeof customFunction !== 'function') {
2658
- throw new TypeError('The [util.promisify.custom] property must be a function');
2659
- }
2660
- Object.defineProperty(customFunction, kCustomPromisifiedSymbol, {
2661
- configurable: true,
2662
- enumerable: false,
2663
- value: customFunction,
2664
- writable: false
2665
- });
2666
- return customFunction;
2667
- }
2668
-
2669
- // Names to create an object from in case the callback receives multiple
2670
- // arguments, e.g. ['stdout', 'stderr'] for child_process.exec.
2671
- var argumentNames = orig[kCustomPromisifyArgsSymbol];
2672
-
2673
- var promisified = function fn() {
2674
- var args = $slice(arguments);
2675
- var self = this; // eslint-disable-line no-invalid-this
2676
- return new Promise(function (resolve, reject) {
2677
- orig.apply(self, $concat$1(args, function (err) {
2678
- var values = arguments.length > 1 ? $slice(arguments, 1) : [];
2679
- if (err) {
2680
- reject(err);
2681
- } else if (typeof argumentNames !== 'undefined' && values.length > 1) {
2682
- var obj = {};
2683
- $forEach(argumentNames, function (name, index) {
2684
- obj[name] = values[index];
2685
- });
2686
- resolve(obj);
2687
- } else {
2688
- resolve(values[0]);
2689
- }
2690
- }));
2691
- });
2692
- };
2693
-
2694
- promisified.__proto__ = orig.__proto__; // eslint-disable-line no-proto
2695
-
2696
- Object.defineProperty(promisified, kCustomPromisifiedSymbol, {
2697
- configurable: true,
2698
- enumerable: false,
2699
- value: promisified,
2700
- writable: false
2701
- });
2702
- return Object.defineProperties(promisified, object_getownpropertydescriptors(orig));
2703
- };
2704
-
2705
- var custom = kCustomPromisifiedSymbol;
2706
- var customPromisifyArgs = kCustomPromisifyArgsSymbol;
2707
- implementation$3.custom = custom;
2708
- implementation$3.customPromisifyArgs = customPromisifyArgs;
2709
-
2710
- var polyfill$1 = function getPolyfill() {
2711
- if (typeof util.promisify === 'function') {
2712
- return util.promisify;
2713
- }
2714
- return implementation$3;
2715
- };
2716
-
2717
- var shim$1 = function shimUtilPromisify() {
2718
- var polyfill = polyfill$1();
2719
- if (polyfill !== util.promisify) {
2720
- Object.defineProperty(util, 'promisify', {
2721
- configurable: true,
2722
- enumerable: true,
2723
- value: polyfill,
2724
- writable: true
2725
- });
2726
- }
2727
- return polyfill;
2728
- };
2729
-
2730
- var polyfill$2 = polyfill$1();
2731
-
2732
-
2733
- /* eslint-disable no-unused-vars */
2734
- var boundPromisify = function promisify(orig) {
2735
- /* eslint-enable no-unused-vars */
2736
- return polyfill$2.apply(util, arguments);
2737
- };
2738
- defineProperties_1(boundPromisify, {
2739
- custom: polyfill$2.custom,
2740
- customPromisifyArgs: polyfill$2.customPromisifyArgs,
2741
- getPolyfill: polyfill$1,
2742
- implementation: implementation$3,
2743
- shim: shim$1
2744
- });
2745
-
2746
- var util_promisify = boundPromisify;
2747
-
2748
- util_promisify.shim();
2749
-
2750
- function connect() {
2751
- var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
2752
-
2753
- if (!config) {
2754
- config = {
2755
- host: 'sanity-datasource.cluster-crao688bsrdh.us-east-1.rds.amazonaws.com',
2756
- user: 'nasp',
2757
- password: 'uRNkF9SkfXQs6AKK',
2758
- database: 'user'
2759
- };
2760
- }
2761
-
2762
- var connection = mysql.createConnection(config);
2763
- return {
2764
- query: function query(sql, args) {
2765
- return util.promisify(connection.query).call(connection, sql, args);
2766
- },
2767
- beginTransaction: function beginTransaction() {
2768
- return util.promisify(connection.beginTransaction).call(connection);
2769
- },
2770
- commit: function commit() {
2771
- return util.promisify(connection.commit).call(connection);
2772
- },
2773
- rollback: function rollback() {
2774
- return util.promisify(connection.rollback).call(connection);
2775
- },
2776
- close: function close() {
2777
- return util.promisify(connection.end).call(connection);
2778
- }
2779
- };
2780
- }
2781
-
2782
- var db = connect;
2783
-
2784
- var _this$3 = undefined;
2785
-
2786
- var config = {
2787
- host: 'sanity-datasource.cluster-crao688bsrdh.us-east-1.rds.amazonaws.com',
2788
- user: 'nasp',
2789
- password: 'uRNkF9SkfXQs6AKK',
2790
- database: 'user'
2791
- };
2792
-
2793
- var findUser = function () {
2794
- var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(email) {
2795
- var password = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
2796
- var db$1, query, res, user, hash, passwordsMatch, user_shared, occupation_id;
2797
- return regenerator.wrap(function _callee$(_context) {
2798
- while (1) {
2799
- switch (_context.prev = _context.next) {
2800
- case 0:
2801
- db$1 = null;
2802
- _context.prev = 1;
2803
-
2804
-
2805
- db$1 = db(config);
2806
-
2807
- query = '\n select * \n from user \n where trim(lower(email)) = ?\n ';
2808
- _context.next = 6;
2809
- return db$1.query(query, [email.toLowerCase().trim()]);
2810
-
2811
- case 6:
2812
- res = _context.sent;
2813
- user = res.length > 0 ? res[0] : null;
2814
-
2815
- if (user) {
2816
- _context.next = 10;
2817
- break;
2818
- }
2819
-
2820
- throw new Error('Invalid credential provided');
2821
-
2822
- case 10:
2823
- if (!password) {
2824
- _context.next = 15;
2825
- break;
2826
- }
2827
-
2828
- hash = md5(password);
2829
- passwordsMatch = hash === user.password;
2830
-
2831
- if (passwordsMatch) {
2832
- _context.next = 15;
2833
- break;
2834
- }
2835
-
2836
- throw new Error('Password doesn\'t match');
2837
-
2838
- case 15:
2839
-
2840
- query = '\n select * \n from user_shared \n where user_id = ?\n ';
2841
- _context.next = 18;
2842
- return db$1.query(query, [user.id]);
2843
-
2844
- case 18:
2845
- res = _context.sent;
2846
- user_shared = res.length > 0 ? res[0] : null;
2847
-
2848
- user.shared = user_shared;
2849
-
2850
- // occupation
2851
- query = '\n select id \n from occupation \n where name = ?\n ';
2852
- _context.next = 24;
2853
- return db$1.query(query, [user_shared.occupation]);
2854
-
2855
- case 24:
2856
- res = _context.sent;
2857
- occupation_id = res.length > 0 ? res[0].id : '';
2858
-
2859
- user.shared.occupation_id = occupation_id;
2860
-
2861
- _context.next = 29;
2862
- return db$1.close();
2863
-
2864
- case 29:
2865
- return _context.abrupt('return', {
2866
- error: '',
2867
- user: user
2868
- });
2869
-
2870
- case 32:
2871
- _context.prev = 32;
2872
- _context.t0 = _context['catch'](1);
2873
-
2874
- if (!db$1) {
2875
- _context.next = 37;
2876
- break;
2877
- }
2878
-
2879
- _context.next = 37;
2880
- return db$1.close();
2881
-
2882
- case 37:
2883
- return _context.abrupt('return', {
2884
- error: _context.t0.message,
2885
- user: null
2886
- });
2887
-
2888
- case 38:
2889
- case 'end':
2890
- return _context.stop();
2891
- }
2892
- }
2893
- }, _callee, this, [[1, 32]]);
2894
- }));
2895
-
2896
- return function findUser(_x) {
2897
- return _ref.apply(this, arguments);
2898
- };
2899
- }();
2900
-
2901
- var updateUser = function () {
2902
- var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(data) {
2903
- var db$1, query, res, hash, columns, i, column, occupation_name;
2904
- return regenerator.wrap(function _callee2$(_context2) {
2905
- while (1) {
2906
- switch (_context2.prev = _context2.next) {
2907
- case 0:
2908
- db$1 = null;
2909
- _context2.prev = 1;
2910
-
2911
-
2912
- validateUserData(data);
2913
-
2914
- db$1 = db(config);
2915
-
2916
- _context2.next = 6;
2917
- return db$1.beginTransaction();
2918
-
2919
- case 6:
2920
- if (data.user_id) {
2921
- _context2.next = 8;
2922
- break;
2923
- }
2924
-
2925
- throw new Error('Please provide user ID');
2926
-
2927
- case 8:
2928
-
2929
- data.email = data.email.toLowerCase().trim();
2930
-
2931
- // check if new email is taken
2932
- query = '\n select * \n from user \n where lower(trim(email)) = ?\n and id != ?\n ';
2933
- _context2.next = 12;
2934
- return db$1.query(query, [data.email, data.user_id]);
2935
-
2936
- case 12:
2937
- res = _context2.sent;
2938
-
2939
- if (!(res && res.length > 0)) {
2940
- _context2.next = 15;
2941
- break;
2942
- }
2943
-
2944
- throw new Error('Email already taken');
2945
-
2946
- case 15:
2947
- if (!data.password) {
2948
- _context2.next = 23;
2949
- break;
2950
- }
2951
-
2952
- hash = md5(data.password);
2953
-
2954
- query = '\n update user \n set password = ?\n where user_id = ?\n ';
2955
- _context2.next = 20;
2956
- return db$1.query(query, [hash, data.user_id]);
2957
-
2958
- case 20:
2959
- res = _context2.sent;
2960
-
2961
- if (!(!res || res.affectedRows < 1)) {
2962
- _context2.next = 23;
2963
- break;
2964
- }
2965
-
2966
- throw new Error('Failed to update password');
2967
-
2968
- case 23:
2969
-
2970
- query = 'show columns from user_shared';
2971
- _context2.next = 26;
2972
- return db$1.query(query);
2973
-
2974
- case 26:
2975
- columns = _context2.sent;
2976
-
2977
-
2978
- for (i = 0; i < columns.length; i++) {
2979
- column = columns[i].Field;
2980
-
2981
- if (typeof data[column] === 'undefined') {
2982
- data[column] = '';
2983
- }
2984
- }
2985
-
2986
- // user_shared
2987
- query = '\n update user_shared\n set \n first_name = ?,\n last_name = ?,\n country = ?,\n city = ?,\n state = ?,\n zip = ?,\n phone = ?,\n occupation = ?,\n primary_specialty = ?,\n area_of_practice = ?,\n work_place = ?,\n graduation_year = ?,\n medical_school = ?,\n npi = ?,\n role = ?,\n updated = current_timestamp\n where user_id = ?\n ';
2988
-
2989
- _context2.next = 31;
2990
- return getOccupationNameById(db$1, data.occupation);
2991
-
2992
- case 31:
2993
- occupation_name = _context2.sent;
2994
- _context2.next = 34;
2995
- return db$1.query(query, [data.first_name, data.last_name, data.country, data.city, data.state, data.zip, data.phone, occupation_name, data.primary_specialty, data.area_of_practice, data.work_place, data.graduation_year, data.medical_school, data.npi, data.role, data.user_id]);
2996
-
2997
- case 34:
2998
- res = _context2.sent;
2999
-
3000
- if (!(!res || res.affectedRows < 1)) {
3001
- _context2.next = 37;
3002
- break;
3003
- }
3004
-
3005
- throw new Error('Failed to update user shared information record');
3006
-
3007
- case 37:
3008
- _context2.next = 39;
3009
- return db$1.commit();
3010
-
3011
- case 39:
3012
- _context2.next = 41;
3013
- return db$1.close();
3014
-
3015
- case 41:
3016
-
3017
- db$1 = null;
3018
-
3019
- return _context2.abrupt('return', {
3020
- error: '',
3021
- user: findUser(data.email)
3022
- });
3023
-
3024
- case 45:
3025
- _context2.prev = 45;
3026
- _context2.t0 = _context2['catch'](1);
3027
-
3028
-
3029
- console.log('error:', _context2.t0);
3030
-
3031
- if (!db$1) {
3032
- _context2.next = 53;
3033
- break;
3034
- }
3035
-
3036
- _context2.next = 51;
3037
- return db$1.rollback();
3038
-
3039
- case 51:
3040
- _context2.next = 53;
3041
- return db$1.close();
3042
-
3043
- case 53:
3044
- return _context2.abrupt('return', {
3045
- error: _context2.t0.message,
3046
- user: null
3047
- });
3048
-
3049
- case 54:
3050
- case 'end':
3051
- return _context2.stop();
3052
- }
3053
- }
3054
- }, _callee2, this, [[1, 45]]);
3055
- }));
3056
-
3057
- return function updateUser(_x3) {
3058
- return _ref2.apply(this, arguments);
3059
- };
3060
- }();
3061
-
3062
- var validateUserData = function validateUserData(data) {
3063
- var requirePassword = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
3064
-
3065
- if (!data.email) {
3066
- throw new Error('Email is required');
3067
- }
3068
-
3069
- if (requirePassword && !data.password) {
3070
- throw new Error('Password is required');
3071
- }
3072
-
3073
- if (data.password && data.password !== data.rpassword) {
3074
- throw new Error('Password does not match');
3075
- }
3076
-
3077
- if (!data.first_name) {
3078
- throw new Error('First name is required');
3079
- }
3080
-
3081
- if (!data.last_name) {
3082
- throw new Error('Last name is required');
3083
- }
3084
-
3085
- if (!data.country) {
3086
- throw new Error('Country is required');
3087
- }
3088
-
3089
- if (data.country === 'United States') {
3090
- if (!data.state) {
3091
- throw new Error('State is required');
3092
- }
3093
-
3094
- if (!data.zip) {
3095
- throw new Error('Zip code is required');
3096
- }
3097
-
3098
- if (!data.phone) {
3099
- throw new Error('Phone is required');
3100
- }
3101
- }
3102
- };
3103
-
3104
- var getOccupationNameById = function () {
3105
- var _ref3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(db, occupation_id) {
3106
- var query, res;
3107
- return regenerator.wrap(function _callee3$(_context3) {
3108
- while (1) {
3109
- switch (_context3.prev = _context3.next) {
3110
- case 0:
3111
- query = '\n select name\n from occupation \n where id = ?\n ';
3112
- _context3.next = 3;
3113
- return db.query(query, [occupation_id]);
3114
-
3115
- case 3:
3116
- res = _context3.sent;
3117
-
3118
- if (!(res && res.length > 0)) {
3119
- _context3.next = 6;
3120
- break;
3121
- }
3122
-
3123
- return _context3.abrupt('return', res[0].name);
3124
-
3125
- case 6:
3126
- throw new Error('Failed to get occupation name by ID: ' + occupation_id);
3127
-
3128
- case 7:
3129
- case 'end':
3130
- return _context3.stop();
3131
- }
3132
- }
3133
- }, _callee3, _this$3);
3134
- }));
3135
-
3136
- return function getOccupationNameById(_x5, _x6) {
3137
- return _ref3.apply(this, arguments);
3138
- };
3139
- }();
3140
-
3141
- var createUser = function () {
3142
- var _ref4 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(data) {
3143
- var db$1, query, res, hash, columns, i, column, user_id, occupation_name;
3144
- return regenerator.wrap(function _callee4$(_context4) {
3145
- while (1) {
3146
- switch (_context4.prev = _context4.next) {
3147
- case 0:
3148
- db$1 = null;
3149
- _context4.prev = 1;
3150
-
3151
-
3152
- validateUserData(data, true);
3153
-
3154
- db$1 = db(config);
3155
-
3156
- _context4.next = 6;
3157
- return db$1.beginTransaction();
3158
-
3159
- case 6:
3160
-
3161
- data.email = data.email.toLowerCase().trim();
3162
-
3163
- // check if user exists
3164
- query = '\n select * \n from user \n where lower(trim(email)) = ?\n ';
3165
- _context4.next = 10;
3166
- return db$1.query(query, [data.email]);
3167
-
3168
- case 10:
3169
- res = _context4.sent;
3170
-
3171
- if (!(res && res.length > 0)) {
3172
- _context4.next = 13;
3173
- break;
3174
- }
3175
-
3176
- throw new Error('User already exists');
3177
-
3178
- case 13:
3179
- hash = md5(data.password);
3180
-
3181
- // basic user info
3182
-
3183
- query = '\n insert into user ( \n email, password, created\n ) values (\n ?, ?, current_timestamp\n )\n ';
3184
- _context4.next = 17;
3185
- return db$1.query(query, [data.email, hash]);
3186
-
3187
- case 17:
3188
- res = _context4.sent;
3189
-
3190
- if (!(!res || res.insertId < 1)) {
3191
- _context4.next = 20;
3192
- break;
3193
- }
3194
-
3195
- throw new Error('Failed to create user');
3196
-
3197
- case 20:
3198
-
3199
- query = 'show columns from user_shared';
3200
- _context4.next = 23;
3201
- return db$1.query(query);
3202
-
3203
- case 23:
3204
- columns = _context4.sent;
3205
-
3206
-
3207
- for (i = 0; i < columns.length; i++) {
3208
- column = columns[i].Field;
3209
-
3210
- if (typeof data[column] === 'undefined') {
3211
- data[column] = '';
3212
- }
3213
- }
3214
-
3215
- user_id = res.insertId;
3216
-
3217
- // user_shared
3218
-
3219
- query = '\n insert into user_shared (\n user_id, first_name, last_name, country, city, state, zip, phone, \n occupation, primary_specialty, area_of_practice, work_place, graduation_year, medical_school, \n npi, role, updated \n ) values (\n ?, ?, ?, ?, ?, ?, ?, ?,\n ?, ?, ?, ?, ?, ?,\n ?, ?, current_timestamp\n )\n ';
3220
-
3221
- _context4.next = 29;
3222
- return getOccupationNameById(db$1, data.occupation);
3223
-
3224
- case 29:
3225
- occupation_name = _context4.sent;
3226
- _context4.next = 32;
3227
- return db$1.query(query, [user_id, data.first_name, data.last_name, data.country, data.city, data.state, data.zip, data.phone, occupation_name, data.primary_specialty, data.area_of_practice, data.work_place, data.graduation_year, data.medical_school, data.npi, data.role]);
3228
-
3229
- case 32:
3230
- res = _context4.sent;
3231
-
3232
- if (!(!res || res.affectedRows < 1)) {
3233
- _context4.next = 35;
3234
- break;
3235
- }
3236
-
3237
- throw new Error('Failed to create user shared information record');
3238
-
3239
- case 35:
3240
- _context4.next = 37;
3241
- return db$1.commit();
3242
-
3243
- case 37:
3244
- _context4.next = 39;
3245
- return db$1.close();
3246
-
3247
- case 39:
3248
- return _context4.abrupt('return', {
3249
- error: '',
3250
- user: findUser(data.email)
3251
- });
3252
-
3253
- case 42:
3254
- _context4.prev = 42;
3255
- _context4.t0 = _context4['catch'](1);
3256
-
3257
- if (!db$1) {
3258
- _context4.next = 49;
3259
- break;
3260
- }
3261
-
3262
- _context4.next = 47;
3263
- return db$1.rollback();
3264
-
3265
- case 47:
3266
- _context4.next = 49;
3267
- return db$1.close();
3268
-
3269
- case 49:
3270
- return _context4.abrupt('return', {
3271
- error: _context4.t0.message,
3272
- user: null
3273
- });
3274
-
3275
- case 50:
3276
- case 'end':
3277
- return _context4.stop();
3278
- }
3279
- }
3280
- }, _callee4, this, [[1, 42]]);
3281
- }));
3282
-
3283
- return function createUser(_x7) {
3284
- return _ref4.apply(this, arguments);
3285
- };
3286
- }();
3287
-
3288
- var createUser$1 = function () {
3289
- var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(data) {
3290
- var res;
3291
- return regenerator.wrap(function _callee$(_context) {
3292
- while (1) {
3293
- switch (_context.prev = _context.next) {
3294
- case 0:
3295
- _context.next = 2;
3296
- return createUser(data);
3297
-
3298
- case 2:
3299
- res = _context.sent;
3300
-
3301
- if (!res.error) {
3302
- _context.next = 5;
3303
- break;
3304
- }
3305
-
3306
- throw new Error(res.error);
3307
-
3308
- case 5:
3309
- return _context.abrupt('return', res.user);
3310
-
3311
- case 6:
3312
- case 'end':
3313
- return _context.stop();
3314
- }
3315
- }
3316
- }, _callee, this);
3317
- }));
3318
-
3319
- return function createUser(_x) {
3320
- return _ref.apply(this, arguments);
3321
- };
3322
- }();
3323
-
3324
- var updateUser$1 = function () {
3325
- var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(data) {
3326
- var res;
3327
- return regenerator.wrap(function _callee2$(_context2) {
3328
- while (1) {
3329
- switch (_context2.prev = _context2.next) {
3330
- case 0:
3331
- _context2.next = 2;
3332
- return updateUser(data);
3333
-
3334
- case 2:
3335
- res = _context2.sent;
3336
-
3337
- if (!res.error) {
3338
- _context2.next = 5;
3339
- break;
3340
- }
3341
-
3342
- throw new Error(res.error);
3343
-
3344
- case 5:
3345
- return _context2.abrupt('return', res.user);
3346
-
3347
- case 6:
3348
- case 'end':
3349
- return _context2.stop();
3350
- }
3351
- }
3352
- }, _callee2, this);
3353
- }));
3354
-
3355
- return function updateUser(_x2) {
3356
- return _ref2.apply(this, arguments);
3357
- };
3358
- }();
3359
-
3360
- var findUser$1 = function () {
3361
- var _ref3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(_ref4) {
3362
- var email = _ref4.email,
3363
- password = _ref4.password;
3364
- var res;
3365
- return regenerator.wrap(function _callee3$(_context3) {
3366
- while (1) {
3367
- switch (_context3.prev = _context3.next) {
3368
- case 0:
3369
- _context3.next = 2;
3370
- return findUser(email, password);
3371
-
3372
- case 2:
3373
- res = _context3.sent;
3374
-
3375
- if (!res.error) {
3376
- _context3.next = 5;
3377
- break;
3378
- }
3379
-
3380
- throw new Error(res.error);
3381
-
3382
- case 5:
3383
- return _context3.abrupt('return', res.user);
3384
-
3385
- case 6:
3386
- case 'end':
3387
- return _context3.stop();
3388
- }
3389
- }
3390
- }, _callee3, this);
3391
- }));
3392
-
3393
- return function findUser(_x3) {
3394
- return _ref3.apply(this, arguments);
3395
- };
3396
- }();
3397
-
3398
- var user = /*#__PURE__*/Object.freeze({
3399
- __proto__: null,
3400
- createUser: createUser$1,
3401
- updateUser: updateUser$1,
3402
- findUser: findUser$1
3403
- });
3404
-
3405
- var localStrategy = new Local.Strategy({
3406
- usernameField: 'email',
3407
- passwordField: 'password'
3408
- }, function (email, password, done) {
3409
-
3410
- findUser$1({ email: email, password: password }).then(function (user) {
3411
- done(null, user);
3412
- }).catch(function (error) {
3413
- done(error);
3414
- });
3415
- });
3416
-
3417
- var passportLocal = /*#__PURE__*/Object.freeze({
3418
- __proto__: null,
3419
- localStrategy: localStrategy
3420
- });
3421
-
3422
- var _this$4 = undefined;
3423
-
3424
- var config$1 = {
3425
- host: 'sanity-datasource.cluster-crao688bsrdh.us-east-1.rds.amazonaws.com',
3426
- user: 'nasp',
3427
- password: 'uRNkF9SkfXQs6AKK',
3428
- database: 'user'
3429
- };
3430
-
3431
- var getOccupation = function () {
3432
- var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(type) {
3433
- var db$1, query, result;
3434
- return regenerator.wrap(function _callee$(_context) {
3435
- while (1) {
3436
- switch (_context.prev = _context.next) {
3437
- case 0:
3438
- db$1 = db(config$1);
3439
- query = '\n select name as label, id as value\n from occupation\n where type = ?\n ';
3440
- _context.next = 4;
3441
- return db$1.query(query, [type]);
3442
-
3443
- case 4:
3444
- result = _context.sent;
3445
- _context.next = 7;
3446
- return db$1.close();
3447
-
3448
- case 7:
3449
- return _context.abrupt('return', result);
3450
-
3451
- case 8:
3452
- case 'end':
3453
- return _context.stop();
3454
- }
3455
- }
3456
- }, _callee, _this$4);
3457
- }));
3458
-
3459
- return function getOccupation(_x) {
3460
- return _ref.apply(this, arguments);
3461
- };
3462
- }();
3463
-
3464
- var getFieldsAndOptions = function () {
3465
- var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(occupation) {
3466
- var db$1, query, result, i, field, optionQuery, options;
3467
- return regenerator.wrap(function _callee2$(_context2) {
3468
- while (1) {
3469
- switch (_context2.prev = _context2.next) {
3470
- case 0:
3471
- db$1 = db(config$1);
3472
- query = '\n select * \n from field\n where occupation_id = ?\n order by sorting\n ';
3473
- _context2.next = 4;
3474
- return db$1.query(query, [occupation]);
3475
-
3476
- case 4:
3477
- result = _context2.sent;
3478
- i = 0;
3479
-
3480
- case 6:
3481
- if (!(i < result.length)) {
3482
- _context2.next = 17;
3483
- break;
3484
- }
3485
-
3486
- field = result[i];
3487
-
3488
- if (!(field.type === 'select')) {
3489
- _context2.next = 14;
3490
- break;
3491
- }
3492
-
3493
- optionQuery = '\n select * \n from options\n where list_id = ?\n order by sorting\n ';
3494
- _context2.next = 12;
3495
- return db$1.query(optionQuery, [field.list_id]);
3496
-
3497
- case 12:
3498
- options = _context2.sent;
3499
-
3500
- field.options = options ? options : [];
3501
-
3502
- case 14:
3503
- i++;
3504
- _context2.next = 6;
3505
- break;
3506
-
3507
- case 17:
3508
- _context2.next = 19;
3509
- return db$1.close();
3510
-
3511
- case 19:
3512
- return _context2.abrupt('return', result);
3513
-
3514
- case 20:
3515
- case 'end':
3516
- return _context2.stop();
3517
- }
3518
- }
3519
- }, _callee2, _this$4);
3520
- }));
3521
-
3522
- return function getFieldsAndOptions(_x2) {
3523
- return _ref2.apply(this, arguments);
3524
- };
3525
- }();
3526
-
3527
- var ProcessData = (function () {
3528
- var _ref3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(req, res) {
3529
- var action, data, type, occupation;
3530
- return regenerator.wrap(function _callee3$(_context3) {
3531
- while (1) {
3532
- switch (_context3.prev = _context3.next) {
3533
- case 0:
3534
- _context3.prev = 0;
3535
- action = req.body.action;
3536
- data = null;
3537
- _context3.t0 = action;
3538
- _context3.next = _context3.t0 === 'get-occupation' ? 6 : _context3.t0 === 'get-fields' ? 11 : 16;
3539
- break;
3540
-
3541
- case 6:
3542
- type = req.body.type;
3543
- _context3.next = 9;
3544
- return getOccupation(type);
3545
-
3546
- case 9:
3547
- data = _context3.sent;
3548
- return _context3.abrupt('break', 17);
3549
-
3550
- case 11:
3551
- occupation = req.body.occupation;
3552
- _context3.next = 14;
3553
- return getFieldsAndOptions(occupation);
3554
-
3555
- case 14:
3556
- data = _context3.sent;
3557
- return _context3.abrupt('break', 17);
3558
-
3559
- case 16:
3560
- throw new Error('Invalid action: ' + action);
3561
-
3562
- case 17:
3563
- return _context3.abrupt('return', res.json({
3564
- error: '',
3565
- data: data
3566
- }));
3567
-
3568
- case 20:
3569
- _context3.prev = 20;
3570
- _context3.t1 = _context3['catch'](0);
3571
- return _context3.abrupt('return', res.json({
3572
- error: _context3.t1.message,
3573
- data: null
3574
- }));
3575
-
3576
- case 23:
3577
- case 'end':
3578
- return _context3.stop();
3579
- }
3580
- }
3581
- }, _callee3, this, [[0, 20]]);
3582
- }));
3583
-
3584
- return function (_x3, _x4) {
3585
- return _ref3.apply(this, arguments);
3586
- };
3587
- })();
3588
-
3589
- var LoginForm_1 = LoginForm;
3590
- var SignupForm_1 = SignupForm;
3591
- var ProfileForm_1 = SignupForm$1;
3592
- var AuthCookies_1 = authCookies;
3593
- var AuthHooks_1 = hooks;
3594
- var Iron_1 = iron;
3595
- var PassportLocal_1 = passportLocal;
3596
- var User_1 = user;
3597
- var ProcessData_1 = ProcessData;
3598
-
3599
- var auth = {
3600
- LoginForm: LoginForm_1,
3601
- SignupForm: SignupForm_1,
3602
- ProfileForm: ProfileForm_1,
3603
- AuthCookies: AuthCookies_1,
3604
- AuthHooks: AuthHooks_1,
3605
- Iron: Iron_1,
3606
- PassportLocal: PassportLocal_1,
3607
- User: User_1,
3608
- ProcessData: ProcessData_1
3609
- };
3610
-
3611
- export default auth;
3612
- export { AuthCookies_1 as AuthCookies, AuthHooks_1 as AuthHooks, Iron_1 as Iron, LoginForm_1 as LoginForm, PassportLocal_1 as PassportLocal, ProcessData_1 as ProcessData, ProfileForm_1 as ProfileForm, SignupForm_1 as SignupForm, User_1 as User };