-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
5384 lines (4284 loc) · 168 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 59);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */,
/* 1 */
/***/ (function(module, exports) {
module.exports = require("redux-auth");
/***/ }),
/* 2 */,
/* 3 */,
/* 4 */
/***/ (function(module, exports) {
module.exports = require("immutable");
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.STORE_CURRENT_ENDPOINT_KEY = exports.SET_ENDPOINT_KEYS = undefined;
exports.setEndpointKeys = setEndpointKeys;
exports.storeCurrentEndpointKey = storeCurrentEndpointKey;
exports.configure = configure;
var _extend = __webpack_require__(14);
var _extend2 = _interopRequireDefault(_extend);
var _constants = __webpack_require__(19);
var C = _interopRequireWildcard(_constants);
var _authenticate = __webpack_require__(25);
var _ui = __webpack_require__(35);
var _server = __webpack_require__(26);
var _clientSettings = __webpack_require__(60);
var _sessionStorage = __webpack_require__(9);
var _verifyAuth = __webpack_require__(49);
var _verifyAuth2 = _interopRequireDefault(_verifyAuth);
var _parseUrl = __webpack_require__(36);
var _parseUrl2 = _interopRequireDefault(_parseUrl);
var _reactRouterRedux = __webpack_require__(65);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var SET_ENDPOINT_KEYS = exports.SET_ENDPOINT_KEYS = "SET_ENDPOINT_KEYS";
var STORE_CURRENT_ENDPOINT_KEY = exports.STORE_CURRENT_ENDPOINT_KEY = "STORE_CURRENT_ENDPOINT_KEY";
function setEndpointKeys(endpoints, currentEndpointKey, defaultEndpointKey) {
return { type: SET_ENDPOINT_KEYS, endpoints: endpoints, currentEndpointKey: currentEndpointKey, defaultEndpointKey: defaultEndpointKey };
};
function storeCurrentEndpointKey(currentEndpointKey) {
return { type: STORE_CURRENT_ENDPOINT_KEY, currentEndpointKey: currentEndpointKey };
};
function configure() {
var endpoint = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var settings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return function (dispatch) {
// don't render anything for OAuth redirects
if (settings.currentLocation && settings.currentLocation.match(/blank=true/)) {
return Promise.resolve({ blank: true });
}
dispatch((0, _authenticate.authenticateStart)());
var promise = void 0,
firstTimeLogin = void 0,
user = void 0,
headers = void 0,
mustResetPassword = void 0;
if (settings.isServer) {
promise = (0, _verifyAuth2.default)(endpoint, settings).then(function (_ref) {
var user = _ref.user,
headers = _ref.headers,
firstTimeLogin = _ref.firstTimeLogin,
mustResetPassword = _ref.mustResetPassword,
currentEndpoint = _ref.currentEndpoint,
currentEndpointKey = _ref.currentEndpointKey,
defaultEndpointKey = _ref.defaultEndpointKey;
dispatch((0, _server.ssAuthTokenUpdate)({
headers: headers,
user: user,
firstTimeLogin: firstTimeLogin,
mustResetPassword: mustResetPassword
}));
dispatch(setEndpointKeys(Object.keys(currentEndpoint), currentEndpointKey, defaultEndpointKey));
return user;
}).catch(function (_ref2) {
var reason = _ref2.reason,
firstTimeLogin = _ref2.firstTimeLogin,
mustResetPassword = _ref2.mustResetPassword,
currentEndpoint = _ref2.currentEndpoint,
defaultEndpointKey = _ref2.defaultEndpointKey;
dispatch((0, _server.ssAuthTokenUpdate)({ firstTimeLogin: firstTimeLogin, mustResetPassword: mustResetPassword }));
dispatch(setEndpointKeys(Object.keys(currentEndpoint || {}), null, defaultEndpointKey));
return Promise.reject({ reason: reason });
});
} else {
// if the authentication happened server-side, find the resulting auth
// credentials that were injected into the dom.
var tokenBridge = document.getElementById("token-bridge");
if (tokenBridge) {
var rawServerCreds = tokenBridge.innerHTML;
if (rawServerCreds) {
var serverCreds = JSON.parse(rawServerCreds);
headers = serverCreds.headers;
user = serverCreds.user;
firstTimeLogin = serverCreds.firstTimeLogin;
mustResetPassword = serverCreds.mustResetPassword;
if (user) {
dispatch((0, _authenticate.authenticateComplete)(user));
// do NOT send initial validation request.
// instead use the credentials that were sent back by the server.
settings.initialCredentials = serverCreds;
}
// sync client dom to prevent React "out of sync" error
dispatch((0, _server.ssAuthTokenUpdate)({
user: user,
headers: headers,
mustResetPassword: mustResetPassword,
firstTimeLogin: firstTimeLogin
}));
}
}
var _getRedirectInfo = (0, _parseUrl2.default)(window.location),
authRedirectPath = _getRedirectInfo.authRedirectPath,
authRedirectHeaders = _getRedirectInfo.authRedirectHeaders;
if (authRedirectPath) {
dispatch((0, _reactRouterRedux.push)({ pathname: authRedirectPath }));
}
if (authRedirectHeaders && authRedirectHeaders.uid && authRedirectHeaders["access-token"]) {
settings.initialCredentials = Object.assign({}, settings.initialCredentials, { headers: authRedirectHeaders });
}
// if tokens were invalidated by server or from the settings, make sure
// to clear browser credentials
if (!settings.clientOnly && !settings.initialCredentials || settings.cleanSession) {
(0, _sessionStorage.destroySession)();
}
promise = Promise.resolve((0, _clientSettings.applyConfig)({ dispatch: dispatch, endpoint: endpoint, settings: settings }));
}
return promise.then(function (user) {
dispatch((0, _authenticate.authenticateComplete)(user));
if (firstTimeLogin) {
dispatch((0, _ui.showFirstTimeLoginSuccessModal)());
}
if (mustResetPassword) {
dispatch((0, _ui.showPasswordResetSuccessModal)());
}
return user;
}).catch(function () {
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
reason = _ref3.reason;
dispatch((0, _authenticate.authenticateError)([reason]));
if (firstTimeLogin) {
dispatch((0, _ui.showFirstTimeLoginErrorModal)());
}
if (mustResetPassword) {
dispatch((0, _ui.showPasswordResetErrorModal)());
}
return Promise.resolve({ reason: reason });
});
};
}
/***/ }),
/* 6 */,
/* 7 */,
/* 8 */,
/* 9 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.setCurrentSettings = setCurrentSettings;
exports.getCurrentSettings = getCurrentSettings;
exports.setCurrentEndpoint = setCurrentEndpoint;
exports.getCurrentEndpoint = getCurrentEndpoint;
exports.setCurrentEndpointKey = setCurrentEndpointKey;
exports.getCurrentEndpointKey = getCurrentEndpointKey;
exports.setDefaultEndpointKey = setDefaultEndpointKey;
exports.getDefaultEndpointKey = getDefaultEndpointKey;
exports.resetConfig = resetConfig;
exports.destroySession = destroySession;
exports.getInitialEndpointKey = getInitialEndpointKey;
exports.getSessionEndpointKey = getSessionEndpointKey;
exports.getSessionEndpoint = getSessionEndpoint;
exports.getDestroyAccountUrl = getDestroyAccountUrl;
exports.getSignOutUrl = getSignOutUrl;
exports.getEmailSignInUrl = getEmailSignInUrl;
exports.getEmailSignUpUrl = getEmailSignUpUrl;
exports.getPasswordResetRequestUrl = getPasswordResetRequestUrl;
exports.getPasswordUpdateUrl = getPasswordUpdateUrl;
exports.getAccountUpdateUrl = getAccountUpdateUrl;
exports.getTokenValidationPath = getTokenValidationPath;
exports.getOAuthUrl = getOAuthUrl;
exports.getConfirmationSuccessUrl = getConfirmationSuccessUrl;
exports.getPasswordResetRedirectUrl = getPasswordResetRedirectUrl;
exports.getApiUrl = getApiUrl;
exports.getTokenFormat = getTokenFormat;
exports.removeData = removeData;
exports.persistData = persistData;
exports.retrieveData = retrieveData;
var _browserCookies = __webpack_require__(61);
var _browserCookies2 = _interopRequireDefault(_browserCookies);
var _constants = __webpack_require__(19);
var C = _interopRequireWildcard(_constants);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// even though this code shouldn't be used server-side, node will throw
// errors if "window" is used
var root = Function("return this")() || (42, eval)("this");
// stateful variables that persist throughout session
root.authState = {
currentSettings: {},
currentEndpoint: {},
defaultEndpointKey: null
};
function setCurrentSettings(s) {
root.authState.currentSettings = s;
}
function getCurrentSettings() {
return root.authState.currentSettings;
}
function setCurrentEndpoint(e) {
root.authState.currentEndpoint = e;
}
function getCurrentEndpoint() {
return root.authState.currentEndpoint;
}
function setCurrentEndpointKey(k) {
persistData(C.SAVED_CONFIG_KEY, k || getDefaultEndpointKey());
}
function getCurrentEndpointKey() {
return retrieveData(C.SAVED_CONFIG_KEY) || getDefaultEndpointKey();
}
function setDefaultEndpointKey(k) {
persistData(C.DEFAULT_CONFIG_KEY, k);
}
function getDefaultEndpointKey() {
return retrieveData(C.DEFAULT_CONFIG_KEY);
}
// reset stateful variables
function resetConfig() {
root.authState = root.authState || {};
root.authState.currentSettings = {};
root.authState.currentEndpoint = {};
destroySession();
}
function destroySession() {
var sessionKeys = [C.SAVED_CREDS_KEY, C.SAVED_CONFIG_KEY];
for (var key in sessionKeys) {
key = sessionKeys[key];
// kill all local storage keys
if (root.localStorage) {
root.localStorage.removeItem(key);
}
// remove from base path in case config is not specified
_browserCookies2.default.erase(key, {
path: root.authState.currentSettings.cookiePath || "/"
});
}
}
function unescapeQuotes(val) {
return val && val.replace(/("|')/g, "");
};
function getInitialEndpointKey() {
return unescapeQuotes(_browserCookies2.default.get(C.SAVED_CONFIG_KEY) || root.localStorage && root.localStorage.getItem(C.SAVED_CONFIG_KEY));
}
// TODO: make this really work
function getSessionEndpointKey(k) {
var key = k || getCurrentEndpointKey();
if (!key) {
throw "You must configure redux-auth before use.";
} else {
return key;
}
}
function getSessionEndpoint(k) {
return getCurrentEndpoint()[getSessionEndpointKey(k)];
}
// only should work for current session
function getDestroyAccountUrl(endpointKey) {
return "" + getApiUrl(endpointKey) + getSessionEndpoint(endpointKey).accountDeletePath;
}
// only should work for current session
function getSignOutUrl(endpointKey) {
return "" + getApiUrl(endpointKey) + getSessionEndpoint(endpointKey).signOutPath;
}
function getEmailSignInUrl(endpointKey) {
return "" + getApiUrl(endpointKey) + getSessionEndpoint(endpointKey).emailSignInPath;
}
function getEmailSignUpUrl(endpointKey) {
return "" + getApiUrl(endpointKey) + getSessionEndpoint(endpointKey).emailRegistrationPath + "?config_name=" + endpointKey;
}
function getPasswordResetRequestUrl(endpointKey) {
return "" + getApiUrl(endpointKey) + getSessionEndpoint(endpointKey).passwordResetPath + "?config_name=" + endpointKey;
}
function getPasswordUpdateUrl(endpointKey) {
return "" + getApiUrl(endpointKey) + getSessionEndpoint(endpointKey).passwordUpdatePath;
}
function getAccountUpdateUrl(endpointKey) {
return "" + getApiUrl(endpointKey) + getSessionEndpoint(endpointKey).accountUpdatePath;
}
function getTokenValidationPath(endpointKey) {
return "" + getApiUrl(endpointKey) + getSessionEndpoint(endpointKey).tokenValidationPath;
}
function getOAuthUrl(_ref) {
var provider = _ref.provider,
params = _ref.params,
endpointKey = _ref.endpointKey;
var oAuthUrl = getApiUrl(endpointKey) + getSessionEndpoint(endpointKey).authProviderPaths[provider] + "?auth_origin_url=" + encodeURIComponent(root.location.href) + "&config_name=" + encodeURIComponent(getSessionEndpointKey(endpointKey));
if (params) {
for (var key in params) {
oAuthUrl += "&";
oAuthUrl += encodeURIComponent(key);
oAuthUrl += "=";
oAuthUrl += encodeURIComponent(params[key]);
}
}
return oAuthUrl;
}
function getConfirmationSuccessUrl() {
return root.authState.currentSettings.confirmationSuccessUrl();
}
function getPasswordResetRedirectUrl() {
return root.authState.currentSettings.confirmationSuccessUrl();
}
function getApiUrl(key) {
var configKey = getSessionEndpointKey(key);
return root.authState.currentEndpoint[configKey].apiUrl;
}
function getTokenFormat() {
return root.authState.currentSettings.tokenFormat;
}
function removeData(key) {
switch (root.authState.currentSettings.storage) {
case "localStorage":
root.localStorage.removeItem(key);
break;
default:
_browserCookies2.default.erase(key);
}
}
function persistData(key, val) {
val = JSON.stringify(val);
switch (root.authState.currentSettings.storage) {
case "localStorage":
root.localStorage.setItem(key, val);
break;
default:
_browserCookies2.default.set(key, val, {
expires: root.authState.currentSettings.cookieExpiry,
path: root.authState.currentSettings.cookiePath
});
break;
}
};
function retrieveData(key, storage) {
var val = null;
switch (storage || root.authState.currentSettings.storage) {
case "localStorage":
val = root.localStorage && root.localStorage.getItem(key);
break;
default:
val = _browserCookies2.default.get(key);
break;
}
// if value is a simple string, the parser will fail. in that case, simply
// unescape the quotes and return the string.
try {
// return parsed json response
return JSON.parse(val);
} catch (err) {
// unescape quotes
return unescapeQuotes(val);
}
};
/***/ }),
/* 10 */
/***/ (function(module, exports) {
module.exports = require("redux-immutablejs");
/***/ }),
/* 11 */,
/* 12 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.addAuthorizationHeader = addAuthorizationHeader;
exports.default = function (url) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!options.headers) {
options.headers = {};
}
(0, _extend2.default)(options.headers, getAuthHeaders(url));
return (0, _isomorphicFetch2.default)(url, options).then(function (resp) {
return updateAuthCredentials(resp);
});
};
var _isomorphicFetch = __webpack_require__(47);
var _isomorphicFetch2 = _interopRequireDefault(_isomorphicFetch);
var _constants = __webpack_require__(19);
var C = _interopRequireWildcard(_constants);
var _extend = __webpack_require__(14);
var _extend2 = _interopRequireDefault(_extend);
var _sessionStorage = __webpack_require__(9);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var isApiRequest = function isApiRequest(url) {
return url.match((0, _sessionStorage.getApiUrl)((0, _sessionStorage.getSessionEndpointKey)()));
};
/**
* Add access token as a bearer token in accordance to RFC 6750
*
* @param {string} accessToken
* @param {object} headers
* @returns {object} New extended headers object, with Authorization property
*/
function addAuthorizationHeader(accessToken, headers) {
return Object.assign({}, headers, {
Authorization: "Bearer " + accessToken
});
}
function getAuthHeaders(url) {
if (isApiRequest(url)) {
// fetch current auth headers from storage
var currentHeaders = (0, _sessionStorage.retrieveData)(C.SAVED_CREDS_KEY) || {},
nextHeaders = {};
// bust IE cache
nextHeaders["If-Modified-Since"] = "Mon, 26 Jul 1997 05:00:00 GMT";
// set header for each key in `tokenFormat` config
for (var key in (0, _sessionStorage.getTokenFormat)()) {
nextHeaders[key] = currentHeaders[key];
}
return addAuthorizationHeader(currentHeaders['access-token'], nextHeaders);
} else {
return {};
}
}
function updateAuthCredentials(resp) {
// check config apiUrl matches the current response url
if (isApiRequest(resp.url)) {
// set header for each key in `tokenFormat` config
var newHeaders = {};
// set flag to ensure that we don't accidentally nuke the headers
// if the response tokens aren't sent back from the API
var blankHeaders = true;
// set header key + val for each key in `tokenFormat` config
for (var key in (0, _sessionStorage.getTokenFormat)()) {
newHeaders[key] = resp.headers.get(key);
if (newHeaders[key]) {
blankHeaders = false;
}
}
// persist headers for next request
if (!blankHeaders) {
(0, _sessionStorage.persistData)(C.SAVED_CREDS_KEY, newHeaders);
}
}
return resp;
}
/***/ }),
/* 13 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var bind = __webpack_require__(50);
var isBuffer = __webpack_require__(70);
/*global toString:true*/
// utils is a library of generic helper functions non-specific to axios
var toString = Object.prototype.toString;
/**
* Determine if a value is an Array
*
* @param {Object} val The value to test
* @returns {boolean} True if value is an Array, otherwise false
*/
function isArray(val) {
return toString.call(val) === '[object Array]';
}
/**
* Determine if a value is an ArrayBuffer
*
* @param {Object} val The value to test
* @returns {boolean} True if value is an ArrayBuffer, otherwise false
*/
function isArrayBuffer(val) {
return toString.call(val) === '[object ArrayBuffer]';
}
/**
* Determine if a value is a FormData
*
* @param {Object} val The value to test
* @returns {boolean} True if value is an FormData, otherwise false
*/
function isFormData(val) {
return typeof FormData !== 'undefined' && val instanceof FormData;
}
/**
* Determine if a value is a view on an ArrayBuffer
*
* @param {Object} val The value to test
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
*/
function isArrayBufferView(val) {
var result;
if (typeof ArrayBuffer !== 'undefined' && ArrayBuffer.isView) {
result = ArrayBuffer.isView(val);
} else {
result = val && val.buffer && val.buffer instanceof ArrayBuffer;
}
return result;
}
/**
* Determine if a value is a String
*
* @param {Object} val The value to test
* @returns {boolean} True if value is a String, otherwise false
*/
function isString(val) {
return typeof val === 'string';
}
/**
* Determine if a value is a Number
*
* @param {Object} val The value to test
* @returns {boolean} True if value is a Number, otherwise false
*/
function isNumber(val) {
return typeof val === 'number';
}
/**
* Determine if a value is undefined
*
* @param {Object} val The value to test
* @returns {boolean} True if the value is undefined, otherwise false
*/
function isUndefined(val) {
return typeof val === 'undefined';
}
/**
* Determine if a value is an Object
*
* @param {Object} val The value to test
* @returns {boolean} True if value is an Object, otherwise false
*/
function isObject(val) {
return val !== null && (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object';
}
/**
* Determine if a value is a Date
*
* @param {Object} val The value to test
* @returns {boolean} True if value is a Date, otherwise false
*/
function isDate(val) {
return toString.call(val) === '[object Date]';
}
/**
* Determine if a value is a File
*
* @param {Object} val The value to test
* @returns {boolean} True if value is a File, otherwise false
*/
function isFile(val) {
return toString.call(val) === '[object File]';
}
/**
* Determine if a value is a Blob
*
* @param {Object} val The value to test
* @returns {boolean} True if value is a Blob, otherwise false
*/
function isBlob(val) {
return toString.call(val) === '[object Blob]';
}
/**
* Determine if a value is a Function
*
* @param {Object} val The value to test
* @returns {boolean} True if value is a Function, otherwise false
*/
function isFunction(val) {
return toString.call(val) === '[object Function]';
}
/**
* Determine if a value is a Stream
*
* @param {Object} val The value to test
* @returns {boolean} True if value is a Stream, otherwise false
*/
function isStream(val) {
return isObject(val) && isFunction(val.pipe);
}
/**
* Determine if a value is a URLSearchParams object
*
* @param {Object} val The value to test
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
*/
function isURLSearchParams(val) {
return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams;
}
/**
* Trim excess whitespace off the beginning and end of a string
*
* @param {String} str The String to trim
* @returns {String} The String freed of excess whitespace
*/
function trim(str) {
return str.replace(/^\s*/, '').replace(/\s*$/, '');
}
/**
* Determine if we're running in a standard browser environment
*
* This allows axios to run in a web worker, and react-native.
* Both environments support XMLHttpRequest, but not fully standard globals.
*
* web workers:
* typeof window -> undefined
* typeof document -> undefined
*
* react-native:
* navigator.product -> 'ReactNative'
*/
function isStandardBrowserEnv() {
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
return false;
}
return typeof window !== 'undefined' && typeof document !== 'undefined';
}
/**
* Iterate over an Array or an Object invoking a function for each item.
*
* If `obj` is an Array callback will be called passing
* the value, index, and complete array for each item.
*
* If 'obj' is an Object callback will be called passing
* the value, key, and complete object for each property.
*
* @param {Object|Array} obj The object to iterate
* @param {Function} fn The callback to invoke for each item
*/
function forEach(obj, fn) {
// Don't bother if no value provided
if (obj === null || typeof obj === 'undefined') {
return;
}
// Force an array if not already something iterable
if ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) !== 'object' && !isArray(obj)) {
/*eslint no-param-reassign:0*/
obj = [obj];
}
if (isArray(obj)) {
// Iterate over array values
for (var i = 0, l = obj.length; i < l; i++) {
fn.call(null, obj[i], i, obj);
}
} else {
// Iterate over object keys
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
fn.call(null, obj[key], key, obj);
}
}
}
}
/**
* Accepts varargs expecting each argument to be an object, then
* immutably merges the properties of each object and returns result.
*
* When multiple objects contain the same key the later object in
* the arguments list will take precedence.
*
* Example:
*
* ```js
* var result = merge({foo: 123}, {foo: 456});
* console.log(result.foo); // outputs 456
* ```
*
* @param {Object} obj1 Object to merge
* @returns {Object} Result of all merge properties
*/
function merge() /* obj1, obj2, obj3, ... */{
var result = {};
function assignValue(val, key) {
if (_typeof(result[key]) === 'object' && (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object') {
result[key] = merge(result[key], val);
} else {
result[key] = val;
}
}
for (var i = 0, l = arguments.length; i < l; i++) {
forEach(arguments[i], assignValue);
}
return result;
}
/**
* Extends object a by mutably adding to it the properties of object b.
*
* @param {Object} a The object to be extended
* @param {Object} b The object to copy properties from
* @param {Object} thisArg The object to bind function to
* @return {Object} The resulting value of object a
*/
function extend(a, b, thisArg) {
forEach(b, function assignValue(val, key) {
if (thisArg && typeof val === 'function') {
a[key] = bind(val, thisArg);
} else {
a[key] = val;
}
});
return a;
}
module.exports = {
isArray: isArray,
isArrayBuffer: isArrayBuffer,
isBuffer: isBuffer,
isFormData: isFormData,
isArrayBufferView: isArrayBufferView,
isString: isString,
isNumber: isNumber,
isObject: isObject,
isUndefined: isUndefined,
isDate: isDate,
isFile: isFile,
isBlob: isBlob,
isFunction: isFunction,
isStream: isStream,
isURLSearchParams: isURLSearchParams,
isStandardBrowserEnv: isStandardBrowserEnv,
forEach: forEach,
merge: merge,
extend: extend,
trim: trim
};
/***/ }),
/* 14 */
/***/ (function(module, exports) {
module.exports = require("extend");
/***/ }),
/* 15 */,
/* 16 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.parseResponse = parseResponse;
function parseResponse(response) {
var json = response.json();
if (response.status >= 200 && response.status < 300) {
return json;
} else {
return json.then(function (err) {
return Promise.reject(err);
});
}
}
/***/ }),
/* 17 */,
/* 18 */,
/* 19 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {