login-authorization-v2 2.0.0-beta.6 → 2.0.0-beta.7

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/dist/index.esm.js CHANGED
@@ -2,6 +2,38 @@ import Cookie from 'js-cookie';
2
2
  import { Base64 } from 'js-base64';
3
3
  import axios from 'axios';
4
4
 
5
+ /******************************************************************************
6
+ Copyright (c) Microsoft Corporation.
7
+
8
+ Permission to use, copy, modify, and/or distribute this software for any
9
+ purpose with or without fee is hereby granted.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ ***************************************************************************** */
19
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
20
+
21
+
22
+ function __awaiter(thisArg, _arguments, P, generator) {
23
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
24
+ return new (P || (P = Promise))(function (resolve, reject) {
25
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
26
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
27
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
28
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
29
+ });
30
+ }
31
+
32
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
33
+ var e = new Error(message);
34
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
35
+ };
36
+
5
37
  const NO_ACCESS_TOKEN = 'Access token not found';
6
38
  const INVALID_ACCESS_TOKEN = 'Invalid access token';
7
39
  const INVALID_REFRESH_TOKEN = 'Invalid refresh token';
@@ -17,13 +49,9 @@ const makeSetCookieFn = (key, options) => {
17
49
  : window.location.hostname.slice(index);
18
50
  return (value) => {
19
51
  if (value === null) {
20
- return Cookie.remove(key, { domain, ...options });
52
+ return Cookie.remove(key, Object.assign({ domain }, options));
21
53
  }
22
- Cookie.set(key, value, {
23
- domain,
24
- expires: 30,
25
- ...options
26
- });
54
+ Cookie.set(key, value, Object.assign({ domain, expires: 30 }, options));
27
55
  };
28
56
  };
29
57
  const setIdTokenFront = makeSetCookieFn('idTokenFront');
@@ -202,8 +230,8 @@ const openDialog = () => {
202
230
  : container.innerHTML = createPcDialog();
203
231
  const confirmButton = container.querySelector('#confirm');
204
232
  const cancelButton = container.querySelector('#cancel');
205
- confirmButton?.addEventListener('click', onConfirmHandler);
206
- cancelButton?.addEventListener('click', onCancelHandler);
233
+ confirmButton === null || confirmButton === void 0 ? void 0 : confirmButton.addEventListener('click', onConfirmHandler);
234
+ cancelButton === null || cancelButton === void 0 ? void 0 : cancelButton.addEventListener('click', onCancelHandler);
207
235
  document.body.appendChild(container);
208
236
  };
209
237
 
@@ -211,10 +239,10 @@ let instance;
211
239
  /**
212
240
  * 没找到更好的方式,只能这样做了
213
241
  */
214
- const initInstance = async () => {
242
+ const initInstance = () => __awaiter(void 0, void 0, void 0, function* () {
215
243
  let userInfo = null;
216
244
  try {
217
- userInfo = await getUserInfo();
245
+ userInfo = yield getUserInfo();
218
246
  }
219
247
  catch (error) {
220
248
  console.warn('initInstance getUserInfo error:', error);
@@ -222,13 +250,9 @@ const initInstance = async () => {
222
250
  instance = axios.create({
223
251
  baseURL: moduleBaseUrl,
224
252
  timeout: 1.5e4,
225
- headers: {
226
- 'X-tenant-id': userInfo ? userInfo['custom:tenant_id'].toString() : tenantId.toString(),
227
- 'X-brand': brand.toString(),
228
- 'Authorization': `Bearer ${getAccessToken()}`,
229
- }
230
253
  });
231
254
  instance.interceptors.request.use((config) => {
255
+ 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()}` });
232
256
  return config;
233
257
  }, (error) => {
234
258
  return Promise.reject(error);
@@ -241,7 +265,7 @@ const initInstance = async () => {
241
265
  }, (error) => {
242
266
  return Promise.reject(error);
243
267
  });
244
- };
268
+ });
245
269
  const fetchRefreshTokenHTTP = (refreshToken) => {
246
270
  return instance({
247
271
  method: 'post',
@@ -288,13 +312,13 @@ const make = (config) => {
288
312
  return Promise.reject(new Error(NO_REFRESH_TOKEN));
289
313
  }
290
314
  return getUserInfo()
291
- .then(async (userInfo) => {
315
+ .then((userInfo) => __awaiter(void 0, void 0, void 0, function* () {
292
316
  const valid = detectUserInfoGroupAuth(userInfo);
293
317
  if (!valid) {
294
318
  return Promise.reject();
295
319
  }
296
320
  return fetchServerListHTTP();
297
- })
321
+ }))
298
322
  .catch(error => {
299
323
  openDialog();
300
324
  throw error;
@@ -310,13 +334,13 @@ const make = (config) => {
310
334
  setupRefreshTokenTimer();
311
335
  return Promise.resolve(menus);
312
336
  })
313
- .catch(async (error) => {
337
+ .catch((error) => __awaiter(void 0, void 0, void 0, function* () {
314
338
  clearRefreshTokenTimer();
315
339
  setAccessToken(null);
316
340
  setRefreshToken(null);
317
- await logout();
341
+ yield logout();
318
342
  throw error;
319
- });
343
+ }));
320
344
  };
321
345
  const detectUserInfoGroupAuth = (userInfo) => {
322
346
  const groups = userInfo['cognito:groups'] || [];
package/dist/index.umd.js CHANGED
@@ -4,6 +4,38 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.LoginAuthorizationV2 = {}, global.Cookies, global.Base64, global.axios));
5
5
  })(this, (function (exports, Cookie, jsBase64, axios) { 'use strict';
6
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
+
7
39
  const NO_ACCESS_TOKEN = 'Access token not found';
8
40
  const INVALID_ACCESS_TOKEN = 'Invalid access token';
9
41
  const INVALID_REFRESH_TOKEN = 'Invalid refresh token';
@@ -19,13 +51,9 @@
19
51
  : window.location.hostname.slice(index);
20
52
  return (value) => {
21
53
  if (value === null) {
22
- return Cookie.remove(key, { domain, ...options });
54
+ return Cookie.remove(key, Object.assign({ domain }, options));
23
55
  }
24
- Cookie.set(key, value, {
25
- domain,
26
- expires: 30,
27
- ...options
28
- });
56
+ Cookie.set(key, value, Object.assign({ domain, expires: 30 }, options));
29
57
  };
30
58
  };
31
59
  const setIdTokenFront = makeSetCookieFn('idTokenFront');
@@ -204,8 +232,8 @@
204
232
  : container.innerHTML = createPcDialog();
205
233
  const confirmButton = container.querySelector('#confirm');
206
234
  const cancelButton = container.querySelector('#cancel');
207
- confirmButton?.addEventListener('click', onConfirmHandler);
208
- cancelButton?.addEventListener('click', onCancelHandler);
235
+ confirmButton === null || confirmButton === void 0 ? void 0 : confirmButton.addEventListener('click', onConfirmHandler);
236
+ cancelButton === null || cancelButton === void 0 ? void 0 : cancelButton.addEventListener('click', onCancelHandler);
209
237
  document.body.appendChild(container);
210
238
  };
211
239
 
@@ -213,10 +241,10 @@
213
241
  /**
214
242
  * 没找到更好的方式,只能这样做了
215
243
  */
216
- const initInstance = async () => {
244
+ const initInstance = () => __awaiter(void 0, void 0, void 0, function* () {
217
245
  let userInfo = null;
218
246
  try {
219
- userInfo = await getUserInfo();
247
+ userInfo = yield getUserInfo();
220
248
  }
221
249
  catch (error) {
222
250
  console.warn('initInstance getUserInfo error:', error);
@@ -224,13 +252,9 @@
224
252
  instance = axios.create({
225
253
  baseURL: moduleBaseUrl,
226
254
  timeout: 1.5e4,
227
- headers: {
228
- 'X-tenant-id': userInfo ? userInfo['custom:tenant_id'].toString() : tenantId.toString(),
229
- 'X-brand': brand.toString(),
230
- 'Authorization': `Bearer ${getAccessToken()}`,
231
- }
232
255
  });
233
256
  instance.interceptors.request.use((config) => {
257
+ 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()}` });
234
258
  return config;
235
259
  }, (error) => {
236
260
  return Promise.reject(error);
@@ -243,7 +267,7 @@
243
267
  }, (error) => {
244
268
  return Promise.reject(error);
245
269
  });
246
- };
270
+ });
247
271
  const fetchRefreshTokenHTTP = (refreshToken) => {
248
272
  return instance({
249
273
  method: 'post',
@@ -290,13 +314,13 @@
290
314
  return Promise.reject(new Error(NO_REFRESH_TOKEN));
291
315
  }
292
316
  return getUserInfo()
293
- .then(async (userInfo) => {
317
+ .then((userInfo) => __awaiter(void 0, void 0, void 0, function* () {
294
318
  const valid = detectUserInfoGroupAuth(userInfo);
295
319
  if (!valid) {
296
320
  return Promise.reject();
297
321
  }
298
322
  return fetchServerListHTTP();
299
- })
323
+ }))
300
324
  .catch(error => {
301
325
  openDialog();
302
326
  throw error;
@@ -312,13 +336,13 @@
312
336
  setupRefreshTokenTimer();
313
337
  return Promise.resolve(menus);
314
338
  })
315
- .catch(async (error) => {
339
+ .catch((error) => __awaiter(void 0, void 0, void 0, function* () {
316
340
  clearRefreshTokenTimer();
317
341
  setAccessToken(null);
318
342
  setRefreshToken(null);
319
- await logout();
343
+ yield logout();
320
344
  throw error;
321
- });
345
+ }));
322
346
  };
323
347
  const detectUserInfoGroupAuth = (userInfo) => {
324
348
  const groups = userInfo['cognito:groups'] || [];
@@ -1 +1 @@
1
- {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,SAAS,CAAA;AAEnD,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,OAAO,CAAA;AAKxD;;GAEG;AACH,eAAO,MAAM,YAAY,qBAqCxB,CAAA;AAED,KAAK,oBAAoB,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAAE;QACP,WAAW,EAAE,MAAM,CAAA;QACnB,SAAS,EAAE,MAAM,CAAA;Q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eAAO,MAAM,qBAAqB,GAAI,cAAc,MAAM,KAOlD,YAAY,CAAC,oBAAoB,CACxC,CAAA;AAED,eAAO,MAAM,eAAe,yBAK3B,CAAA;AAED,KAAK,OAAO,GAAG;IACb,SAAS,EAAE,UAAU,CAAA;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,aAAa,EAAE,OAAO,CAAA;IACtB,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AACD,KAAK,kBAAkB,GAAG;IACxB,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,aAAa,EAAE,MAAM,CAAA;CACtB,CAAA;AACD,eAAO,MAAM,mBAAmB,QAIxB,YAAY,CAAC,kBAAkB,CACtC,CAAA"}
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "login-authorization-v2",
4
- "version": "2.0.0-beta.6",
4
+ "version": "2.0.0-beta.7",
5
5
  "engines": {
6
6
  "node": "^20"
7
7
  },
8
8
  "description": "login authorization",
9
- "main": "./dist-cjs/index.js",
10
- "module": "./dist-esm/index.js",
11
- "types": "./dist-cjs/index.d.ts",
9
+ "main": "./dist/index.esm.js",
10
+ "module": "./dist/index.esm.js",
11
+ "types": "./dist/index.d.ts",
12
12
  "exports": {
13
13
  ".": {
14
- "import": "./dist-esm/index.js",
15
- "require": "./dist-cjs/index.js",
16
- "types": "./dist-cjs/index.d.ts"
14
+ "module": "./dist/index.esm.js",
15
+ "require": "./dist/index.umd.js",
16
+ "types": "./dist/index.d.ts"
17
17
  },
18
18
  "./package.json": "./package.json"
19
19
  },
@@ -44,6 +44,7 @@
44
44
  "@jest/globals": "^30.2.0",
45
45
  "@rollup/plugin-commonjs": "^29.0.0",
46
46
  "@rollup/plugin-node-resolve": "^16.0.3",
47
+ "@rollup/plugin-terser": "^0.4.4",
47
48
  "@rollup/plugin-typescript": "^12.3.0",
48
49
  "@types/axios": "^0.14.4",
49
50
  "@types/jest": "^30.0.0",