login-authorization-v2 2.0.0-beta.1 → 2.0.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -47
- package/dist/index.d.ts +14 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +413 -497
- package/dist/index.umd.js +432 -537
- package/dist/src/compatible.d.ts +1 -1
- package/dist/src/compatible.d.ts.map +1 -1
- package/dist/src/cookie.d.ts +2 -2
- package/dist/src/cookie.d.ts.map +1 -1
- package/dist/src/request.d.ts.map +1 -1
- package/package.json +29 -25
- package/babel.config.js +0 -6
- package/coverage/clover.xml +0 -140
- package/coverage/coverage-final.json +0 -8
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/common-authorization-v2/index.html +0 -116
- package/coverage/lcov-report/common-authorization-v2/index.ts.html +0 -547
- package/coverage/lcov-report/common-authorization-v2/src/compatible.ts.html +0 -223
- package/coverage/lcov-report/common-authorization-v2/src/constance.ts.html +0 -106
- package/coverage/lcov-report/common-authorization-v2/src/cookie.ts.html +0 -346
- package/coverage/lcov-report/common-authorization-v2/src/dom.ts.html +0 -262
- package/coverage/lcov-report/common-authorization-v2/src/index.html +0 -206
- package/coverage/lcov-report/common-authorization-v2/src/request.ts.html +0 -361
- package/coverage/lcov-report/common-authorization-v2/src/shares.ts.html +0 -163
- package/coverage/lcov-report/common-authorization-v2/src/types.ts.html +0 -412
- package/coverage/lcov-report/common-authorization-v2/src/utils.ts.html +0 -145
- package/coverage/lcov-report/compatible.ts.html +0 -223
- package/coverage/lcov-report/constance.ts.html +0 -106
- package/coverage/lcov-report/cookie.ts.html +0 -310
- package/coverage/lcov-report/dom.ts.html +0 -262
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -206
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/shares.ts.html +0 -163
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov-report/types.ts.html +0 -412
- package/coverage/lcov-report/utils.ts.html +0 -145
- package/coverage/lcov.info +0 -268
- package/dist/compatible.d.ts +0 -10
- package/dist/compatible.d.ts.map +0 -1
- package/dist/constance.d.ts +0 -6
- package/dist/constance.d.ts.map +0 -1
- package/dist/cookie.d.ts +0 -8
- package/dist/cookie.d.ts.map +0 -1
- package/dist/dom.d.ts +0 -2
- package/dist/dom.d.ts.map +0 -1
- package/dist/index.js.LICENSE.txt +0 -1
- package/dist/request.d.ts +0 -36
- package/dist/request.d.ts.map +0 -1
- package/dist/shares.d.ts +0 -10
- package/dist/shares.d.ts.map +0 -1
- package/dist/test/cookie.test.d.ts +0 -2
- package/dist/test/cookie.test.d.ts.map +0 -1
- package/dist/test/shares.test.d.ts +0 -2
- package/dist/test/shares.test.d.ts.map +0 -1
- package/dist/types.d.ts +0 -89
- package/dist/types.d.ts.map +0 -1
- package/dist/utils.d.ts +0 -2
- package/dist/utils.d.ts.map +0 -1
- package/index.html +0 -28
- package/index.ts +0 -154
- package/jest.config.js +0 -6
- package/src/compatible.ts +0 -46
- package/src/constance.ts +0 -7
- package/src/cookie.ts +0 -75
- package/src/dom.ts +0 -59
- package/src/request.ts +0 -99
- package/src/shares.ts +0 -26
- package/src/types.ts +0 -109
- package/src/utils.ts +0 -20
- package/tests/compatible.test.ts +0 -420
- package/tests/cookie.test.ts +0 -78
- package/tests/dom.test.ts +0 -95
- package/tests/index.test.ts +0 -126
- package/tests/shares.test.ts +0 -52
- package/tests/utils.test.ts +0 -79
- package/tsconfig.json +0 -49
- package/webpack.config.mjs +0 -47
package/dist/index.umd.js
CHANGED
|
@@ -1,537 +1,432 @@
|
|
|
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
|
-
"use strict";
|
|
434
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"isMobile\": () => (/* binding */ isMobile),\n/* harmony export */ \"getUserInfo\": () => (/* binding */ getUserInfo)\n/* harmony export */ });\n/* harmony import */ var _cookie__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./cookie */ \"./src/cookie.ts\");\n/* harmony import */ var _constance__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./constance */ \"./src/constance.ts\");\n/* harmony import */ var js_base64__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! js-base64 */ \"./node_modules/js-base64/base64.mjs\");\n\n\n\nconst isMobile = () => {\n const ua = navigator.userAgent;\n return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(ua);\n};\nconst getUserInfo = () => {\n return new Promise((resolve, reject) => {\n const token = (0,_cookie__WEBPACK_IMPORTED_MODULE_0__.getAccessToken)();\n if (!token)\n return reject(new Error(_constance__WEBPACK_IMPORTED_MODULE_1__.NO_ACCESS_TOKEN));\n const splits = token.split('.');\n if (splits.length < 3)\n return reject(new Error(_constance__WEBPACK_IMPORTED_MODULE_1__.NO_ACCESS_TOKEN));\n resolve(JSON.parse(js_base64__WEBPACK_IMPORTED_MODULE_2__.Base64.decode(splits[1])));\n });\n};\n\n\n//# sourceURL=webpack://login-authorization-v2/./src/utils.ts?");
|
|
435
|
-
|
|
436
|
-
/***/ }),
|
|
437
|
-
|
|
438
|
-
/***/ "./node_modules/js-base64/base64.mjs":
|
|
439
|
-
/*!*******************************************!*\
|
|
440
|
-
!*** ./node_modules/js-base64/base64.mjs ***!
|
|
441
|
-
\*******************************************/
|
|
442
|
-
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
443
|
-
|
|
444
|
-
"use strict";
|
|
445
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"version\": () => (/* binding */ version),\n/* harmony export */ \"VERSION\": () => (/* binding */ VERSION),\n/* harmony export */ \"atob\": () => (/* binding */ _atob),\n/* harmony export */ \"atobPolyfill\": () => (/* binding */ atobPolyfill),\n/* harmony export */ \"btoa\": () => (/* binding */ _btoa),\n/* harmony export */ \"btoaPolyfill\": () => (/* binding */ btoaPolyfill),\n/* harmony export */ \"fromBase64\": () => (/* binding */ decode),\n/* harmony export */ \"toBase64\": () => (/* binding */ encode),\n/* harmony export */ \"utob\": () => (/* binding */ utob),\n/* harmony export */ \"encode\": () => (/* binding */ encode),\n/* harmony export */ \"encodeURI\": () => (/* binding */ encodeURI),\n/* harmony export */ \"encodeURL\": () => (/* binding */ encodeURI),\n/* harmony export */ \"btou\": () => (/* binding */ btou),\n/* harmony export */ \"decode\": () => (/* binding */ decode),\n/* harmony export */ \"isValid\": () => (/* binding */ isValid),\n/* harmony export */ \"fromUint8Array\": () => (/* binding */ fromUint8Array),\n/* harmony export */ \"toUint8Array\": () => (/* binding */ toUint8Array),\n/* harmony export */ \"extendString\": () => (/* binding */ extendString),\n/* harmony export */ \"extendUint8Array\": () => (/* binding */ extendUint8Array),\n/* harmony export */ \"extendBuiltins\": () => (/* binding */ extendBuiltins),\n/* harmony export */ \"Base64\": () => (/* binding */ gBase64)\n/* harmony export */ });\n/**\n * base64.ts\n *\n * Licensed under the BSD 3-Clause License.\n * http://opensource.org/licenses/BSD-3-Clause\n *\n * References:\n * http://en.wikipedia.org/wiki/Base64\n *\n * @author Dan Kogai (https://github.com/dankogai)\n */\nconst version = '3.7.7';\n/**\n * @deprecated use lowercase `version`.\n */\nconst VERSION = version;\nconst _hasBuffer = typeof Buffer === 'function';\nconst _TD = typeof TextDecoder === 'function' ? new TextDecoder() : undefined;\nconst _TE = typeof TextEncoder === 'function' ? new TextEncoder() : undefined;\nconst b64ch = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';\nconst b64chs = Array.prototype.slice.call(b64ch);\nconst b64tab = ((a) => {\n let tab = {};\n a.forEach((c, i) => tab[c] = i);\n return tab;\n})(b64chs);\nconst b64re = /^(?:[A-Za-z\\d+\\/]{4})*?(?:[A-Za-z\\d+\\/]{2}(?:==)?|[A-Za-z\\d+\\/]{3}=?)?$/;\nconst _fromCC = String.fromCharCode.bind(String);\nconst _U8Afrom = typeof Uint8Array.from === 'function'\n ? Uint8Array.from.bind(Uint8Array)\n : (it) => new Uint8Array(Array.prototype.slice.call(it, 0));\nconst _mkUriSafe = (src) => src\n .replace(/=/g, '').replace(/[+\\/]/g, (m0) => m0 == '+' ? '-' : '_');\nconst _tidyB64 = (s) => s.replace(/[^A-Za-z0-9\\+\\/]/g, '');\n/**\n * polyfill version of `btoa`\n */\nconst btoaPolyfill = (bin) => {\n // console.log('polyfilled');\n let u32, c0, c1, c2, asc = '';\n const pad = bin.length % 3;\n for (let i = 0; i < bin.length;) {\n if ((c0 = bin.charCodeAt(i++)) > 255 ||\n (c1 = bin.charCodeAt(i++)) > 255 ||\n (c2 = bin.charCodeAt(i++)) > 255)\n throw new TypeError('invalid character found');\n u32 = (c0 << 16) | (c1 << 8) | c2;\n asc += b64chs[u32 >> 18 & 63]\n + b64chs[u32 >> 12 & 63]\n + b64chs[u32 >> 6 & 63]\n + b64chs[u32 & 63];\n }\n return pad ? asc.slice(0, pad - 3) + \"===\".substring(pad) : asc;\n};\n/**\n * does what `window.btoa` of web browsers do.\n * @param {String} bin binary string\n * @returns {string} Base64-encoded string\n */\nconst _btoa = typeof btoa === 'function' ? (bin) => btoa(bin)\n : _hasBuffer ? (bin) => Buffer.from(bin, 'binary').toString('base64')\n : btoaPolyfill;\nconst _fromUint8Array = _hasBuffer\n ? (u8a) => Buffer.from(u8a).toString('base64')\n : (u8a) => {\n // cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326\n const maxargs = 0x1000;\n let strs = [];\n for (let i = 0, l = u8a.length; i < l; i += maxargs) {\n strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));\n }\n return _btoa(strs.join(''));\n };\n/**\n * converts a Uint8Array to a Base64 string.\n * @param {boolean} [urlsafe] URL-and-filename-safe a la RFC4648 §5\n * @returns {string} Base64 string\n */\nconst fromUint8Array = (u8a, urlsafe = false) => urlsafe ? _mkUriSafe(_fromUint8Array(u8a)) : _fromUint8Array(u8a);\n// This trick is found broken https://github.com/dankogai/js-base64/issues/130\n// const utob = (src: string) => unescape(encodeURIComponent(src));\n// reverting good old fationed regexp\nconst cb_utob = (c) => {\n if (c.length < 2) {\n var cc = c.charCodeAt(0);\n return cc < 0x80 ? c\n : cc < 0x800 ? (_fromCC(0xc0 | (cc >>> 6))\n + _fromCC(0x80 | (cc & 0x3f)))\n : (_fromCC(0xe0 | ((cc >>> 12) & 0x0f))\n + _fromCC(0x80 | ((cc >>> 6) & 0x3f))\n + _fromCC(0x80 | (cc & 0x3f)));\n }\n else {\n var cc = 0x10000\n + (c.charCodeAt(0) - 0xD800) * 0x400\n + (c.charCodeAt(1) - 0xDC00);\n return (_fromCC(0xf0 | ((cc >>> 18) & 0x07))\n + _fromCC(0x80 | ((cc >>> 12) & 0x3f))\n + _fromCC(0x80 | ((cc >>> 6) & 0x3f))\n + _fromCC(0x80 | (cc & 0x3f)));\n }\n};\nconst re_utob = /[\\uD800-\\uDBFF][\\uDC00-\\uDFFFF]|[^\\x00-\\x7F]/g;\n/**\n * @deprecated should have been internal use only.\n * @param {string} src UTF-8 string\n * @returns {string} UTF-16 string\n */\nconst utob = (u) => u.replace(re_utob, cb_utob);\n//\nconst _encode = _hasBuffer\n ? (s) => Buffer.from(s, 'utf8').toString('base64')\n : _TE\n ? (s) => _fromUint8Array(_TE.encode(s))\n : (s) => _btoa(utob(s));\n/**\n * converts a UTF-8-encoded string to a Base64 string.\n * @param {boolean} [urlsafe] if `true` make the result URL-safe\n * @returns {string} Base64 string\n */\nconst encode = (src, urlsafe = false) => urlsafe\n ? _mkUriSafe(_encode(src))\n : _encode(src);\n/**\n * converts a UTF-8-encoded string to URL-safe Base64 RFC4648 §5.\n * @returns {string} Base64 string\n */\nconst encodeURI = (src) => encode(src, true);\n// This trick is found broken https://github.com/dankogai/js-base64/issues/130\n// const btou = (src: string) => decodeURIComponent(escape(src));\n// reverting good old fationed regexp\nconst re_btou = /[\\xC0-\\xDF][\\x80-\\xBF]|[\\xE0-\\xEF][\\x80-\\xBF]{2}|[\\xF0-\\xF7][\\x80-\\xBF]{3}/g;\nconst cb_btou = (cccc) => {\n switch (cccc.length) {\n case 4:\n var cp = ((0x07 & cccc.charCodeAt(0)) << 18)\n | ((0x3f & cccc.charCodeAt(1)) << 12)\n | ((0x3f & cccc.charCodeAt(2)) << 6)\n | (0x3f & cccc.charCodeAt(3)), offset = cp - 0x10000;\n return (_fromCC((offset >>> 10) + 0xD800)\n + _fromCC((offset & 0x3FF) + 0xDC00));\n case 3:\n return _fromCC(((0x0f & cccc.charCodeAt(0)) << 12)\n | ((0x3f & cccc.charCodeAt(1)) << 6)\n | (0x3f & cccc.charCodeAt(2)));\n default:\n return _fromCC(((0x1f & cccc.charCodeAt(0)) << 6)\n | (0x3f & cccc.charCodeAt(1)));\n }\n};\n/**\n * @deprecated should have been internal use only.\n * @param {string} src UTF-16 string\n * @returns {string} UTF-8 string\n */\nconst btou = (b) => b.replace(re_btou, cb_btou);\n/**\n * polyfill version of `atob`\n */\nconst atobPolyfill = (asc) => {\n // console.log('polyfilled');\n asc = asc.replace(/\\s+/g, '');\n if (!b64re.test(asc))\n throw new TypeError('malformed base64.');\n asc += '=='.slice(2 - (asc.length & 3));\n let u24, bin = '', r1, r2;\n for (let i = 0; i < asc.length;) {\n u24 = b64tab[asc.charAt(i++)] << 18\n | b64tab[asc.charAt(i++)] << 12\n | (r1 = b64tab[asc.charAt(i++)]) << 6\n | (r2 = b64tab[asc.charAt(i++)]);\n bin += r1 === 64 ? _fromCC(u24 >> 16 & 255)\n : r2 === 64 ? _fromCC(u24 >> 16 & 255, u24 >> 8 & 255)\n : _fromCC(u24 >> 16 & 255, u24 >> 8 & 255, u24 & 255);\n }\n return bin;\n};\n/**\n * does what `window.atob` of web browsers do.\n * @param {String} asc Base64-encoded string\n * @returns {string} binary string\n */\nconst _atob = typeof atob === 'function' ? (asc) => atob(_tidyB64(asc))\n : _hasBuffer ? (asc) => Buffer.from(asc, 'base64').toString('binary')\n : atobPolyfill;\n//\nconst _toUint8Array = _hasBuffer\n ? (a) => _U8Afrom(Buffer.from(a, 'base64'))\n : (a) => _U8Afrom(_atob(a).split('').map(c => c.charCodeAt(0)));\n/**\n * converts a Base64 string to a Uint8Array.\n */\nconst toUint8Array = (a) => _toUint8Array(_unURI(a));\n//\nconst _decode = _hasBuffer\n ? (a) => Buffer.from(a, 'base64').toString('utf8')\n : _TD\n ? (a) => _TD.decode(_toUint8Array(a))\n : (a) => btou(_atob(a));\nconst _unURI = (a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 == '-' ? '+' : '/'));\n/**\n * converts a Base64 string to a UTF-8 string.\n * @param {String} src Base64 string. Both normal and URL-safe are supported\n * @returns {string} UTF-8 string\n */\nconst decode = (src) => _decode(_unURI(src));\n/**\n * check if a value is a valid Base64 string\n * @param {String} src a value to check\n */\nconst isValid = (src) => {\n if (typeof src !== 'string')\n return false;\n const s = src.replace(/\\s+/g, '').replace(/={0,2}$/, '');\n return !/[^\\s0-9a-zA-Z\\+/]/.test(s) || !/[^\\s0-9a-zA-Z\\-_]/.test(s);\n};\n//\nconst _noEnum = (v) => {\n return {\n value: v, enumerable: false, writable: true, configurable: true\n };\n};\n/**\n * extend String.prototype with relevant methods\n */\nconst extendString = function () {\n const _add = (name, body) => Object.defineProperty(String.prototype, name, _noEnum(body));\n _add('fromBase64', function () { return decode(this); });\n _add('toBase64', function (urlsafe) { return encode(this, urlsafe); });\n _add('toBase64URI', function () { return encode(this, true); });\n _add('toBase64URL', function () { return encode(this, true); });\n _add('toUint8Array', function () { return toUint8Array(this); });\n};\n/**\n * extend Uint8Array.prototype with relevant methods\n */\nconst extendUint8Array = function () {\n const _add = (name, body) => Object.defineProperty(Uint8Array.prototype, name, _noEnum(body));\n _add('toBase64', function (urlsafe) { return fromUint8Array(this, urlsafe); });\n _add('toBase64URI', function () { return fromUint8Array(this, true); });\n _add('toBase64URL', function () { return fromUint8Array(this, true); });\n};\n/**\n * extend Builtin prototypes with relevant methods\n */\nconst extendBuiltins = () => {\n extendString();\n extendUint8Array();\n};\nconst gBase64 = {\n version: version,\n VERSION: VERSION,\n atob: _atob,\n atobPolyfill: atobPolyfill,\n btoa: _btoa,\n btoaPolyfill: btoaPolyfill,\n fromBase64: decode,\n toBase64: encode,\n encode: encode,\n encodeURI: encodeURI,\n encodeURL: encodeURI,\n utob: utob,\n btou: btou,\n decode: decode,\n isValid: isValid,\n fromUint8Array: fromUint8Array,\n toUint8Array: toUint8Array,\n extendString: extendString,\n extendUint8Array: extendUint8Array,\n extendBuiltins: extendBuiltins\n};\n// makecjs:CUT //\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n// and finally,\n\n\n\n//# sourceURL=webpack://login-authorization-v2/./node_modules/js-base64/base64.mjs?");
|
|
446
|
-
|
|
447
|
-
/***/ }),
|
|
448
|
-
|
|
449
|
-
/***/ "./node_modules/js-cookie/dist/js.cookie.mjs":
|
|
450
|
-
/*!***************************************************!*\
|
|
451
|
-
!*** ./node_modules/js-cookie/dist/js.cookie.mjs ***!
|
|
452
|
-
\***************************************************/
|
|
453
|
-
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
454
|
-
|
|
455
|
-
"use strict";
|
|
456
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ api)\n/* harmony export */ });\n/*! js-cookie v3.0.5 | MIT */\n/* eslint-disable no-var */\nfunction assign (target) {\n for (var i = 1; i < arguments.length; i++) {\n var source = arguments[i];\n for (var key in source) {\n target[key] = source[key];\n }\n }\n return target\n}\n/* eslint-enable no-var */\n\n/* eslint-disable no-var */\nvar defaultConverter = {\n read: function (value) {\n if (value[0] === '\"') {\n value = value.slice(1, -1);\n }\n return value.replace(/(%[\\dA-F]{2})+/gi, decodeURIComponent)\n },\n write: function (value) {\n return encodeURIComponent(value).replace(\n /%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,\n decodeURIComponent\n )\n }\n};\n/* eslint-enable no-var */\n\n/* eslint-disable no-var */\n\nfunction init (converter, defaultAttributes) {\n function set (name, value, attributes) {\n if (typeof document === 'undefined') {\n return\n }\n\n attributes = assign({}, defaultAttributes, attributes);\n\n if (typeof attributes.expires === 'number') {\n attributes.expires = new Date(Date.now() + attributes.expires * 864e5);\n }\n if (attributes.expires) {\n attributes.expires = attributes.expires.toUTCString();\n }\n\n name = encodeURIComponent(name)\n .replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)\n .replace(/[()]/g, escape);\n\n var stringifiedAttributes = '';\n for (var attributeName in attributes) {\n if (!attributes[attributeName]) {\n continue\n }\n\n stringifiedAttributes += '; ' + attributeName;\n\n if (attributes[attributeName] === true) {\n continue\n }\n\n // Considers RFC 6265 section 5.2:\n // ...\n // 3. If the remaining unparsed-attributes contains a %x3B (\";\")\n // character:\n // Consume the characters of the unparsed-attributes up to,\n // not including, the first %x3B (\";\") character.\n // ...\n stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];\n }\n\n return (document.cookie =\n name + '=' + converter.write(value, name) + stringifiedAttributes)\n }\n\n function get (name) {\n if (typeof document === 'undefined' || (arguments.length && !name)) {\n return\n }\n\n // To prevent the for loop in the first place assign an empty array\n // in case there are no cookies at all.\n var cookies = document.cookie ? document.cookie.split('; ') : [];\n var jar = {};\n for (var i = 0; i < cookies.length; i++) {\n var parts = cookies[i].split('=');\n var value = parts.slice(1).join('=');\n\n try {\n var found = decodeURIComponent(parts[0]);\n jar[found] = converter.read(value, found);\n\n if (name === found) {\n break\n }\n } catch (e) {}\n }\n\n return name ? jar[name] : jar\n }\n\n return Object.create(\n {\n set,\n get,\n remove: function (name, attributes) {\n set(\n name,\n '',\n assign({}, attributes, {\n expires: -1\n })\n );\n },\n withAttributes: function (attributes) {\n return init(this.converter, assign({}, this.attributes, attributes))\n },\n withConverter: function (converter) {\n return init(assign({}, this.converter, converter), this.attributes)\n }\n },\n {\n attributes: { value: Object.freeze(defaultAttributes) },\n converter: { value: Object.freeze(converter) }\n }\n )\n}\n\nvar api = init(defaultConverter, { path: '/' });\n/* eslint-enable no-var */\n\n\n\n\n//# sourceURL=webpack://login-authorization-v2/./node_modules/js-cookie/dist/js.cookie.mjs?");
|
|
457
|
-
|
|
458
|
-
/***/ })
|
|
459
|
-
|
|
460
|
-
/******/ });
|
|
461
|
-
/************************************************************************/
|
|
462
|
-
/******/ // The module cache
|
|
463
|
-
/******/ var __webpack_module_cache__ = {};
|
|
464
|
-
/******/
|
|
465
|
-
/******/ // The require function
|
|
466
|
-
/******/ function __webpack_require__(moduleId) {
|
|
467
|
-
/******/ // Check if module is in cache
|
|
468
|
-
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
469
|
-
/******/ if (cachedModule !== undefined) {
|
|
470
|
-
/******/ return cachedModule.exports;
|
|
471
|
-
/******/ }
|
|
472
|
-
/******/ // Create a new module (and put it into the cache)
|
|
473
|
-
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
474
|
-
/******/ // no module.id needed
|
|
475
|
-
/******/ // no module.loaded needed
|
|
476
|
-
/******/ exports: {}
|
|
477
|
-
/******/ };
|
|
478
|
-
/******/
|
|
479
|
-
/******/ // Execute the module function
|
|
480
|
-
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
481
|
-
/******/
|
|
482
|
-
/******/ // Return the exports of the module
|
|
483
|
-
/******/ return module.exports;
|
|
484
|
-
/******/ }
|
|
485
|
-
/******/
|
|
486
|
-
/************************************************************************/
|
|
487
|
-
/******/ /* webpack/runtime/compat get default export */
|
|
488
|
-
/******/ (() => {
|
|
489
|
-
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
490
|
-
/******/ __webpack_require__.n = (module) => {
|
|
491
|
-
/******/ var getter = module && module.__esModule ?
|
|
492
|
-
/******/ () => (module['default']) :
|
|
493
|
-
/******/ () => (module);
|
|
494
|
-
/******/ __webpack_require__.d(getter, { a: getter });
|
|
495
|
-
/******/ return getter;
|
|
496
|
-
/******/ };
|
|
497
|
-
/******/ })();
|
|
498
|
-
/******/
|
|
499
|
-
/******/ /* webpack/runtime/define property getters */
|
|
500
|
-
/******/ (() => {
|
|
501
|
-
/******/ // define getter functions for harmony exports
|
|
502
|
-
/******/ __webpack_require__.d = (exports, definition) => {
|
|
503
|
-
/******/ for(var key in definition) {
|
|
504
|
-
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
505
|
-
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
506
|
-
/******/ }
|
|
507
|
-
/******/ }
|
|
508
|
-
/******/ };
|
|
509
|
-
/******/ })();
|
|
510
|
-
/******/
|
|
511
|
-
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
512
|
-
/******/ (() => {
|
|
513
|
-
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
514
|
-
/******/ })();
|
|
515
|
-
/******/
|
|
516
|
-
/******/ /* webpack/runtime/make namespace object */
|
|
517
|
-
/******/ (() => {
|
|
518
|
-
/******/ // define __esModule on exports
|
|
519
|
-
/******/ __webpack_require__.r = (exports) => {
|
|
520
|
-
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
521
|
-
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
522
|
-
/******/ }
|
|
523
|
-
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
524
|
-
/******/ };
|
|
525
|
-
/******/ })();
|
|
526
|
-
/******/
|
|
527
|
-
/************************************************************************/
|
|
528
|
-
/******/
|
|
529
|
-
/******/ // startup
|
|
530
|
-
/******/ // Load entry module and return exports
|
|
531
|
-
/******/ // This entry module can't be inlined because the eval devtool is used.
|
|
532
|
-
/******/ var __webpack_exports__ = __webpack_require__("./index.ts");
|
|
533
|
-
/******/
|
|
534
|
-
/******/ return __webpack_exports__;
|
|
535
|
-
/******/ })()
|
|
536
|
-
;
|
|
537
|
-
});
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('js-cookie'), require('js-base64'), require('axios')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'js-cookie', 'js-base64', 'axios'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.LoginAuthorizationV2 = {}, global.Cookies, global.Base64, global.axios));
|
|
5
|
+
})(this, (function (exports, Cookie, jsBase64, axios) { 'use strict';
|
|
6
|
+
|
|
7
|
+
/******************************************************************************
|
|
8
|
+
Copyright (c) Microsoft Corporation.
|
|
9
|
+
|
|
10
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
+
purpose with or without fee is hereby granted.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
+
***************************************************************************** */
|
|
21
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
25
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
26
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
27
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
28
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
29
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
30
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
35
|
+
var e = new Error(message);
|
|
36
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const NO_ACCESS_TOKEN = 'Access token not found';
|
|
40
|
+
const INVALID_ACCESS_TOKEN = 'Invalid access token';
|
|
41
|
+
const INVALID_REFRESH_TOKEN = 'Invalid refresh token';
|
|
42
|
+
const NO_REFRESH_TOKEN = 'Refresh token not found';
|
|
43
|
+
const NO_MODULE_BASE_URL = 'Module base URL is required';
|
|
44
|
+
const INVALID_TENANT_ID = 'Invalid tenant ID';
|
|
45
|
+
const INVALID_BRAND = 'Invalid brand';
|
|
46
|
+
|
|
47
|
+
const makeSetCookieFn = (key, options) => {
|
|
48
|
+
const index = window.location.hostname.indexOf('.');
|
|
49
|
+
const domain = index === -1
|
|
50
|
+
? window.location.hostname
|
|
51
|
+
: window.location.hostname.slice(index);
|
|
52
|
+
return (value) => {
|
|
53
|
+
if (value === null) {
|
|
54
|
+
return Cookie.remove(key, Object.assign({ domain }, options));
|
|
55
|
+
}
|
|
56
|
+
Cookie.set(key, value, Object.assign({ domain, expires: 30 }, options));
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
const setIdTokenFront = makeSetCookieFn('idTokenFront');
|
|
60
|
+
const setIdTokenBack = makeSetCookieFn('idTokenBack');
|
|
61
|
+
const getIdTokenFront = () => Cookie.get('idTokenFront');
|
|
62
|
+
const getIdTokenBack = () => Cookie.get('idTokenBack');
|
|
63
|
+
const setRefreshTokenFront = makeSetCookieFn('refreshTokenFront');
|
|
64
|
+
const setRefreshTokenBack = makeSetCookieFn('refreshTokenBack');
|
|
65
|
+
const getRefreshTokenFront = () => Cookie.get('refreshTokenFront');
|
|
66
|
+
const getRefreshTokenBack = () => Cookie.get('refreshTokenBack');
|
|
67
|
+
const setRefreshToken = (token) => {
|
|
68
|
+
if (!token) {
|
|
69
|
+
setIdTokenBack(null);
|
|
70
|
+
setIdTokenFront(null);
|
|
71
|
+
// makeSetCookieFn('refresh_token')(null)
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const splits = token.split('.');
|
|
75
|
+
if (splits.length < 5)
|
|
76
|
+
throw new Error(INVALID_REFRESH_TOKEN);
|
|
77
|
+
const refreshTokenFront = splits[0] + '.' + splits[1];
|
|
78
|
+
const refreshTokenBack = splits[2] + '.' + splits[3] + '.' + splits[4];
|
|
79
|
+
setRefreshTokenFront(refreshTokenFront);
|
|
80
|
+
setRefreshTokenBack(refreshTokenBack);
|
|
81
|
+
// makeSetCookieFn('refresh_token')(token)
|
|
82
|
+
};
|
|
83
|
+
const setAccessToken = (token) => {
|
|
84
|
+
if (!token) {
|
|
85
|
+
setIdTokenBack(null);
|
|
86
|
+
setIdTokenFront(null);
|
|
87
|
+
// makeSetCookieFn('access_token')(null)
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const splits = token.split('.');
|
|
91
|
+
if (splits.length < 3)
|
|
92
|
+
throw new Error(INVALID_ACCESS_TOKEN);
|
|
93
|
+
const idTokenFront = splits[0] + '.' + splits[1];
|
|
94
|
+
const idTokenBack = splits[2] || '';
|
|
95
|
+
setIdTokenFront(idTokenFront);
|
|
96
|
+
setIdTokenBack(idTokenBack);
|
|
97
|
+
// makeSetCookieFn('access_token')(token)
|
|
98
|
+
};
|
|
99
|
+
const getAccessToken = () => {
|
|
100
|
+
return getIdTokenFront() + '.' + getIdTokenBack();
|
|
101
|
+
};
|
|
102
|
+
const getRefreshToken = () => {
|
|
103
|
+
return getRefreshTokenFront() + '.' + getRefreshTokenBack();
|
|
104
|
+
};
|
|
105
|
+
const setSystemType = makeSetCookieFn('currentSystemType');
|
|
106
|
+
const getSystemType = () => Cookie.get('currentSystemType');
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 这个文件是写一些兼容的方法,避免各个项目做出大量调整
|
|
110
|
+
*/
|
|
111
|
+
const setIdToken = setAccessToken;
|
|
112
|
+
const getIdToken = getAccessToken;
|
|
113
|
+
const setCookie = (name, value, domain, path = '/', time = 30 * 24 * 60 * 60 * 1000) => {
|
|
114
|
+
if (value === null || value === undefined) {
|
|
115
|
+
return Cookie.remove(name);
|
|
116
|
+
}
|
|
117
|
+
Cookie.set(name, value, {
|
|
118
|
+
domain,
|
|
119
|
+
path,
|
|
120
|
+
expires: time / (24 * 60 * 60 * 1000)
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
const clearLoginCookie = () => {
|
|
124
|
+
setAccessToken(null);
|
|
125
|
+
setRefreshToken(null);
|
|
126
|
+
};
|
|
127
|
+
const getCookie = (c_name) => {
|
|
128
|
+
if (!c_name)
|
|
129
|
+
return null;
|
|
130
|
+
const reg = new RegExp('(?:^|; )' + encodeURIComponent(c_name) + '=([^;]*)');
|
|
131
|
+
const result = reg.exec(document.cookie);
|
|
132
|
+
return result ? decodeURIComponent(result[1] || '') : null;
|
|
133
|
+
};
|
|
134
|
+
const getUrlParam = (key, href) => {
|
|
135
|
+
const search = '?' + ((href || window.location.href).split('?')[1] || '');
|
|
136
|
+
const searchParams = new URLSearchParams(search);
|
|
137
|
+
return searchParams.get(key);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const isMobile = () => {
|
|
141
|
+
const ua = navigator.userAgent;
|
|
142
|
+
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(ua);
|
|
143
|
+
};
|
|
144
|
+
const getUserInfo = () => {
|
|
145
|
+
return new Promise((resolve, reject) => {
|
|
146
|
+
const token = getAccessToken();
|
|
147
|
+
if (!token)
|
|
148
|
+
return reject(new Error(NO_ACCESS_TOKEN));
|
|
149
|
+
const splits = token.split('.');
|
|
150
|
+
if (splits.length < 3)
|
|
151
|
+
return reject(new Error(NO_ACCESS_TOKEN));
|
|
152
|
+
resolve(JSON.parse(jsBase64.Base64.decode(splits[1])));
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
var Brand;
|
|
157
|
+
(function (Brand) {
|
|
158
|
+
Brand[Brand["ZERO"] = 1] = "ZERO";
|
|
159
|
+
Brand[Brand["HEDGEHOOD"] = 2] = "HEDGEHOOD";
|
|
160
|
+
Brand[Brand["NISE"] = 3] = "NISE";
|
|
161
|
+
})(Brand || (Brand = {}));
|
|
162
|
+
var Tenant;
|
|
163
|
+
(function (Tenant) {
|
|
164
|
+
Tenant[Tenant["ZERO_INT"] = 1] = "ZERO_INT";
|
|
165
|
+
Tenant[Tenant["HEDGEHOOD"] = 2] = "HEDGEHOOD";
|
|
166
|
+
Tenant[Tenant["ZERO_NZ"] = 3] = "ZERO_NZ";
|
|
167
|
+
Tenant[Tenant["ZERO_LA"] = 4] = "ZERO_LA";
|
|
168
|
+
Tenant[Tenant["ZERO_BR"] = 4] = "ZERO_BR";
|
|
169
|
+
Tenant[Tenant["NISE_EU"] = 5] = "NISE_EU";
|
|
170
|
+
})(Tenant || (Tenant = {}));
|
|
171
|
+
var SystemType;
|
|
172
|
+
(function (SystemType) {
|
|
173
|
+
SystemType["Staff"] = "staff";
|
|
174
|
+
SystemType["Client"] = "client";
|
|
175
|
+
})(SystemType || (SystemType = {}));
|
|
176
|
+
|
|
177
|
+
let tenantId;
|
|
178
|
+
let brand;
|
|
179
|
+
let moduleBaseUrl = '';
|
|
180
|
+
let loginPageUrl = '';
|
|
181
|
+
const setTenantId = (id) => {
|
|
182
|
+
if (!Object.values(Tenant).includes(id)) {
|
|
183
|
+
throw new Error(INVALID_TENANT_ID);
|
|
184
|
+
}
|
|
185
|
+
tenantId = id;
|
|
186
|
+
};
|
|
187
|
+
const setBrand = (id) => {
|
|
188
|
+
if (!Object.values(Brand).includes(id)) {
|
|
189
|
+
throw new Error(INVALID_BRAND);
|
|
190
|
+
}
|
|
191
|
+
brand = id;
|
|
192
|
+
};
|
|
193
|
+
const setModuleBaseUrl = (url) => {
|
|
194
|
+
moduleBaseUrl = url;
|
|
195
|
+
};
|
|
196
|
+
const setLoginPageUrl = (url) => {
|
|
197
|
+
loginPageUrl = url;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const createPcDialog = () => {
|
|
201
|
+
return `<div id="confirm-container" style="box-sizing:border-box;position:fixed;width:615px;height:145px;box-shadow: 0 0 2px 2px #eeeeee;border-radius: 5px;z-index: 10000000;display: block;left: 35%;padding:20px 20px;top:10px;font-size: 16px;">
|
|
202
|
+
<div id="href" style="color: rgb(32,33,36);"></div>
|
|
203
|
+
<div style="margin: 10px 0 20px 0;color: rgb(32,33,36);font-size: 14px;">You do not have access to the system.</div>
|
|
204
|
+
<div style="display: flex;justify-content: flex-end;">
|
|
205
|
+
<button id="cancel" style="padding: 8px 15px;background: #ffffff;color:rgb(26,115,232);border:1px solid #ccc;border-radius:5px;cursor: pointer;font-size:14px;">Cancel</button>
|
|
206
|
+
<button id="confirm" style="padding: 8px 15px;background: rgb(26,115,232);color:#ffffff;border:none;border-radius:5px;margin-left: 10px;cursor: pointer;font-size:14px;">Sign in to another ZERO account</button>
|
|
207
|
+
</div>
|
|
208
|
+
</div>`;
|
|
209
|
+
};
|
|
210
|
+
const createMobileDialog = () => {
|
|
211
|
+
return `<div id="confirm-container" style="box-sizing:border-box;position:fixed;width:97.6vw;height:145px;box-shadow: 0 0 2px 2px #eeeeee;border-radius: 5px;z-index: 10000000;display: block;left:0px;padding:20px 20px;top:4px;margin:0 4px;font-size: 16px;">
|
|
212
|
+
<div id="href" style="color: rgb(32,33,36);"></div>
|
|
213
|
+
<div style="margin: 10px 0 20px 0;color: rgb(32,33,36);font-size: 14px;">You do not have access to the system.</div>
|
|
214
|
+
<div style="display: flex;justify-content: flex-end;">
|
|
215
|
+
<div style="display: flex;justify-content: flex-end;">
|
|
216
|
+
<button id="cancel" style="padding: 8px 15px;background: #ffffff;color:rgb(26,115,232);border:1px solid #ccc;border-radius:5px;cursor: pointer;font-size:14px;">Cancel</button>
|
|
217
|
+
<button id="confirm" style="padding: 8px 15px;background: rgb(26,115,232);color:#ffffff;border:none;border-radius:5px;margin-left: 10px;cursor: pointer;font-size:14px;">Sign in to another ZERO account</button>
|
|
218
|
+
</div>
|
|
219
|
+
</div>
|
|
220
|
+
</div>`;
|
|
221
|
+
};
|
|
222
|
+
const onConfirmHandler = (evt) => {
|
|
223
|
+
closeDialog();
|
|
224
|
+
window.location.href = loginPageUrl;
|
|
225
|
+
};
|
|
226
|
+
const onCancelHandler = () => {
|
|
227
|
+
closeDialog();
|
|
228
|
+
window.location.href = 'about:blank';
|
|
229
|
+
};
|
|
230
|
+
const closeDialog = () => {
|
|
231
|
+
const container = document.getElementById('confirm-container');
|
|
232
|
+
if (!container || !container.parentNode)
|
|
233
|
+
return;
|
|
234
|
+
document.body.removeChild(container.parentNode);
|
|
235
|
+
};
|
|
236
|
+
const openDialog = () => {
|
|
237
|
+
const container = document.createElement('div');
|
|
238
|
+
isMobile()
|
|
239
|
+
? container.innerHTML = createMobileDialog()
|
|
240
|
+
: container.innerHTML = createPcDialog();
|
|
241
|
+
const confirmButton = container.querySelector('#confirm');
|
|
242
|
+
const cancelButton = container.querySelector('#cancel');
|
|
243
|
+
confirmButton === null || confirmButton === void 0 ? void 0 : confirmButton.addEventListener('click', onConfirmHandler);
|
|
244
|
+
cancelButton === null || cancelButton === void 0 ? void 0 : cancelButton.addEventListener('click', onCancelHandler);
|
|
245
|
+
document.body.appendChild(container);
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
let instance;
|
|
249
|
+
/**
|
|
250
|
+
* 没找到更好的方式,只能这样做了
|
|
251
|
+
*/
|
|
252
|
+
const initInstance = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
253
|
+
let userInfo = null;
|
|
254
|
+
try {
|
|
255
|
+
userInfo = yield getUserInfo();
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
console.warn('initInstance getUserInfo error:', error);
|
|
259
|
+
}
|
|
260
|
+
instance = axios.create({
|
|
261
|
+
baseURL: moduleBaseUrl,
|
|
262
|
+
timeout: 1.5e4,
|
|
263
|
+
});
|
|
264
|
+
instance.interceptors.request.use((config) => {
|
|
265
|
+
config.headers = Object.assign(Object.assign({}, config.headers), { 'X-tenant-id': userInfo ? userInfo['custom:tenant_id'].toString() : tenantId.toString(), 'X-brand': brand.toString(), 'Authorization': `Bearer ${getAccessToken()}` });
|
|
266
|
+
return config;
|
|
267
|
+
}, (error) => {
|
|
268
|
+
return Promise.reject(error);
|
|
269
|
+
});
|
|
270
|
+
instance.interceptors.response.use((response) => {
|
|
271
|
+
if (response.data.code !== 200) {
|
|
272
|
+
return Promise.reject(response.data.msg);
|
|
273
|
+
}
|
|
274
|
+
return response;
|
|
275
|
+
}, (error) => {
|
|
276
|
+
return Promise.reject(error);
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
const fetchRefreshTokenHTTP = (refreshToken) => {
|
|
280
|
+
return instance({
|
|
281
|
+
method: 'post',
|
|
282
|
+
url: '/user-profile/refresh-token/refresh',
|
|
283
|
+
data: {
|
|
284
|
+
refreshToken
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
};
|
|
288
|
+
const fetchLogoutHTTP = () => {
|
|
289
|
+
return instance({
|
|
290
|
+
method: 'get',
|
|
291
|
+
url: '/user-profile/logout'
|
|
292
|
+
});
|
|
293
|
+
};
|
|
294
|
+
const fetchServerListHTTP = () => {
|
|
295
|
+
return instance({
|
|
296
|
+
method: 'get',
|
|
297
|
+
url: '/session/current/servers'
|
|
298
|
+
});
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
const make = (config) => {
|
|
302
|
+
if (!config.moduleBaseUrl) {
|
|
303
|
+
throw new Error(NO_MODULE_BASE_URL);
|
|
304
|
+
}
|
|
305
|
+
let timer = undefined;
|
|
306
|
+
setModuleBaseUrl(config.moduleBaseUrl);
|
|
307
|
+
setLoginPageUrl(config.loginPageUrl);
|
|
308
|
+
initInstance();
|
|
309
|
+
const init = (initConfig) => {
|
|
310
|
+
setTenantId(initConfig.tenantId);
|
|
311
|
+
setBrand(initConfig.brand || Brand.ZERO);
|
|
312
|
+
const token = getAccessToken();
|
|
313
|
+
const refreshToken = getRefreshToken();
|
|
314
|
+
if (!token) {
|
|
315
|
+
setAccessToken(null);
|
|
316
|
+
setRefreshToken(null);
|
|
317
|
+
return Promise.reject(new Error(NO_ACCESS_TOKEN));
|
|
318
|
+
}
|
|
319
|
+
if (!refreshToken) {
|
|
320
|
+
setAccessToken(null);
|
|
321
|
+
setRefreshToken(null);
|
|
322
|
+
return Promise.reject(new Error(NO_REFRESH_TOKEN));
|
|
323
|
+
}
|
|
324
|
+
return getUserInfo()
|
|
325
|
+
.then((userInfo) => __awaiter(void 0, void 0, void 0, function* () {
|
|
326
|
+
const valid = detectUserInfoGroupAuth(userInfo);
|
|
327
|
+
if (!valid) {
|
|
328
|
+
return Promise.reject();
|
|
329
|
+
}
|
|
330
|
+
return fetchServerListHTTP();
|
|
331
|
+
}))
|
|
332
|
+
.then(resp => {
|
|
333
|
+
const menus = resp.data.content || [];
|
|
334
|
+
const group = menus.find(menu => menu.groupName === config.moduleName);
|
|
335
|
+
if (menus.length <= 0) {
|
|
336
|
+
openDialog();
|
|
337
|
+
return Promise.reject();
|
|
338
|
+
}
|
|
339
|
+
if (config.moduleName === 'commonLogin') {
|
|
340
|
+
setupRefreshTokenTimer();
|
|
341
|
+
return Promise.resolve(menus);
|
|
342
|
+
}
|
|
343
|
+
if (!group) {
|
|
344
|
+
openDialog();
|
|
345
|
+
return Promise.reject();
|
|
346
|
+
}
|
|
347
|
+
setSystemType(group.staffEndpoint ? SystemType.Staff : SystemType.Client);
|
|
348
|
+
setupRefreshTokenTimer();
|
|
349
|
+
return Promise.resolve(menus);
|
|
350
|
+
})
|
|
351
|
+
.catch((error) => __awaiter(void 0, void 0, void 0, function* () {
|
|
352
|
+
clearRefreshTokenTimer();
|
|
353
|
+
setAccessToken(null);
|
|
354
|
+
setRefreshToken(null);
|
|
355
|
+
yield logout();
|
|
356
|
+
throw error;
|
|
357
|
+
}));
|
|
358
|
+
};
|
|
359
|
+
const detectUserInfoGroupAuth = (userInfo) => {
|
|
360
|
+
const groups = userInfo['cognito:groups'] || [];
|
|
361
|
+
if (!groups.includes(config.moduleName)
|
|
362
|
+
&& config.moduleName !== 'commonLogin'
|
|
363
|
+
&& config.moduleName !== 'App') {
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
return true;
|
|
367
|
+
};
|
|
368
|
+
const setupRefreshTokenTimer = () => {
|
|
369
|
+
const refreshToken = getRefreshToken();
|
|
370
|
+
if (!refreshToken)
|
|
371
|
+
return;
|
|
372
|
+
if (timer) {
|
|
373
|
+
clearInterval(timer);
|
|
374
|
+
}
|
|
375
|
+
timer = setInterval(() => {
|
|
376
|
+
fetchRefreshTokenHTTP(refreshToken)
|
|
377
|
+
.then(resp => {
|
|
378
|
+
const { content: { idToken } } = resp.data;
|
|
379
|
+
setAccessToken(idToken);
|
|
380
|
+
return getUserInfo();
|
|
381
|
+
})
|
|
382
|
+
.then(userInfo => {
|
|
383
|
+
const valid = detectUserInfoGroupAuth(userInfo);
|
|
384
|
+
if (!valid) {
|
|
385
|
+
clearRefreshTokenTimer();
|
|
386
|
+
openDialog();
|
|
387
|
+
return logout();
|
|
388
|
+
}
|
|
389
|
+
})
|
|
390
|
+
.catch(error => {
|
|
391
|
+
clearRefreshTokenTimer();
|
|
392
|
+
throw error;
|
|
393
|
+
});
|
|
394
|
+
}, 1e3 * 60 * 3); // 3 minutes
|
|
395
|
+
};
|
|
396
|
+
const logout = () => {
|
|
397
|
+
return fetchLogoutHTTP()
|
|
398
|
+
.finally(() => {
|
|
399
|
+
clearRefreshTokenTimer();
|
|
400
|
+
setAccessToken(null);
|
|
401
|
+
setRefreshToken(null);
|
|
402
|
+
});
|
|
403
|
+
};
|
|
404
|
+
const clearRefreshTokenTimer = () => {
|
|
405
|
+
if (!timer)
|
|
406
|
+
return;
|
|
407
|
+
clearInterval(timer);
|
|
408
|
+
timer = null;
|
|
409
|
+
};
|
|
410
|
+
return {
|
|
411
|
+
init,
|
|
412
|
+
logout
|
|
413
|
+
};
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
exports.clearLoginCookie = clearLoginCookie;
|
|
417
|
+
exports.getAccessToken = getAccessToken;
|
|
418
|
+
exports.getCookie = getCookie;
|
|
419
|
+
exports.getIdToken = getIdToken;
|
|
420
|
+
exports.getRefreshToken = getRefreshToken;
|
|
421
|
+
exports.getSystemType = getSystemType;
|
|
422
|
+
exports.getUrlParam = getUrlParam;
|
|
423
|
+
exports.getUserInfo = getUserInfo;
|
|
424
|
+
exports.isMobile = isMobile;
|
|
425
|
+
exports.make = make;
|
|
426
|
+
exports.setAccessToken = setAccessToken;
|
|
427
|
+
exports.setCookie = setCookie;
|
|
428
|
+
exports.setIdToken = setIdToken;
|
|
429
|
+
exports.setRefreshToken = setRefreshToken;
|
|
430
|
+
exports.setSystemType = setSystemType;
|
|
431
|
+
|
|
432
|
+
}));
|