login-authorization-v2 2.0.0 → 2.0.2

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 CHANGED
@@ -18,6 +18,7 @@ const { init, logout } = make({
18
18
  moduleName: 'Portal', // 当前模块名称
19
19
  moduleBaseUrl: 'https://servers-api.gztest.net:8107', // 后端的 module_base 服务地址
20
20
  loginPageUrl: 'http://huangcheng.ddmarketinghub.com:8080', // 如果未登录,跳转的登录页地址
21
+ needMenus: true // 是否需要获取菜单权限数据,默认为 true, 如果能确保就是有权限,可以设置为false,可以少调用一次后端接口
21
22
  })
22
23
 
23
24
  init({ brand: 1, tenantId: 1 }).then(menus => {
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ type MakeFnParams = {
6
6
  moduleName: ModuleName;
7
7
  moduleBaseUrl: string;
8
8
  loginPageUrl: string;
9
+ needMenus?: boolean;
9
10
  };
10
11
  type InitFnParams = {
11
12
  brand?: Brand;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAO3B,OAAO,EAAE,KAAK,EAAE,KAAK,UAAU,EAAc,MAAM,EAAiB,MAAM,aAAa,CAAA;AAGvF,KAAK,YAAY,GAAG;IAClB,UAAU,EAAE,UAAU,CAAA;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,KAAK,YAAY,GAAG;IAClB,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,IAAI,GAAI,QAAQ,YAAY;uBAUb,YAAY;;;;;;;;;CAiIvC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAO3B,OAAO,EAAE,KAAK,EAAE,KAAK,UAAU,EAAc,MAAM,EAAiB,MAAM,aAAa,CAAA;AAGvF,KAAK,YAAY,GAAG;IAClB,UAAU,EAAE,UAAU,CAAA;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB,CAAA;AAKD,KAAK,YAAY,GAAG;IAClB,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAOD,eAAO,MAAM,IAAI,GAAI,QAAQ,YAAY;uBAuCb,YAAY;;;;;;;;;CA0GvC,CAAA"}
package/dist/index.esm.js CHANGED
@@ -302,7 +302,15 @@ const fetchServerListHTTP = () => {
302
302
  });
303
303
  };
304
304
 
305
+ const defaultMakeFnParams = {
306
+ needMenus: true
307
+ };
308
+ const whiteList = ['commonLogin', 'App'];
309
+ const isInWhiteList = (moduleName) => {
310
+ return whiteList.includes(moduleName);
311
+ };
305
312
  const make = (config) => {
313
+ config = Object.assign({}, defaultMakeFnParams, config);
306
314
  if (!config.moduleBaseUrl) {
307
315
  throw new Error(NO_MODULE_BASE_URL);
308
316
  }
@@ -310,6 +318,28 @@ const make = (config) => {
310
318
  setModuleBaseUrl(config.moduleBaseUrl);
311
319
  setLoginPageUrl(config.loginPageUrl);
312
320
  initInstance();
321
+ const doFetchServerList = () => {
322
+ return fetchServerListHTTP()
323
+ .then(resp => {
324
+ const menus = resp.data.content || [];
325
+ const group = menus.find(menu => menu.groupName === config.moduleName);
326
+ if (menus.length <= 0) {
327
+ openDialog();
328
+ return Promise.reject();
329
+ }
330
+ if (isInWhiteList(config.moduleName)) {
331
+ setupRefreshTokenTimer();
332
+ return Promise.resolve(menus);
333
+ }
334
+ if (!group) {
335
+ openDialog();
336
+ return Promise.reject();
337
+ }
338
+ setSystemType(group.staffEndpoint ? SystemType.Staff : SystemType.Client);
339
+ setupRefreshTokenTimer();
340
+ return Promise.resolve(menus);
341
+ });
342
+ };
313
343
  const init = (initConfig) => {
314
344
  setTenantId(initConfig.tenantId);
315
345
  setBrand(initConfig.brand || Brand.ZERO);
@@ -331,27 +361,10 @@ const make = (config) => {
331
361
  if (!valid) {
332
362
  return Promise.reject();
333
363
  }
334
- return fetchServerListHTTP();
364
+ return config.needMenus
365
+ ? doFetchServerList()
366
+ : Promise.resolve([]);
335
367
  }))
336
- .then(resp => {
337
- const menus = resp.data.content || [];
338
- const group = menus.find(menu => menu.groupName === config.moduleName);
339
- if (menus.length <= 0) {
340
- openDialog();
341
- return Promise.reject();
342
- }
343
- if (config.moduleName === 'commonLogin') {
344
- setupRefreshTokenTimer();
345
- return Promise.resolve(menus);
346
- }
347
- if (!group) {
348
- openDialog();
349
- return Promise.reject();
350
- }
351
- setSystemType(group.staffEndpoint ? SystemType.Staff : SystemType.Client);
352
- setupRefreshTokenTimer();
353
- return Promise.resolve(menus);
354
- })
355
368
  .catch((error) => __awaiter(void 0, void 0, void 0, function* () {
356
369
  clearRefreshTokenTimer();
357
370
  setAccessToken(null);
@@ -361,9 +374,8 @@ const make = (config) => {
361
374
  };
362
375
  const detectUserInfoGroupAuth = (userInfo) => {
363
376
  const groups = userInfo['cognito:groups'] || [];
364
- if (!groups.includes(config.moduleName)
365
- && config.moduleName !== 'commonLogin'
366
- && config.moduleName !== 'App') {
377
+ if (!groups.includes(config.moduleName) &&
378
+ !isInWhiteList(config.moduleName)) {
367
379
  return false;
368
380
  }
369
381
  return true;
package/dist/index.umd.js CHANGED
@@ -304,7 +304,15 @@
304
304
  });
305
305
  };
306
306
 
307
+ const defaultMakeFnParams = {
308
+ needMenus: true
309
+ };
310
+ const whiteList = ['commonLogin', 'App'];
311
+ const isInWhiteList = (moduleName) => {
312
+ return whiteList.includes(moduleName);
313
+ };
307
314
  const make = (config) => {
315
+ config = Object.assign({}, defaultMakeFnParams, config);
308
316
  if (!config.moduleBaseUrl) {
309
317
  throw new Error(NO_MODULE_BASE_URL);
310
318
  }
@@ -312,6 +320,28 @@
312
320
  setModuleBaseUrl(config.moduleBaseUrl);
313
321
  setLoginPageUrl(config.loginPageUrl);
314
322
  initInstance();
323
+ const doFetchServerList = () => {
324
+ return fetchServerListHTTP()
325
+ .then(resp => {
326
+ const menus = resp.data.content || [];
327
+ const group = menus.find(menu => menu.groupName === config.moduleName);
328
+ if (menus.length <= 0) {
329
+ openDialog();
330
+ return Promise.reject();
331
+ }
332
+ if (isInWhiteList(config.moduleName)) {
333
+ setupRefreshTokenTimer();
334
+ return Promise.resolve(menus);
335
+ }
336
+ if (!group) {
337
+ openDialog();
338
+ return Promise.reject();
339
+ }
340
+ setSystemType(group.staffEndpoint ? SystemType.Staff : SystemType.Client);
341
+ setupRefreshTokenTimer();
342
+ return Promise.resolve(menus);
343
+ });
344
+ };
315
345
  const init = (initConfig) => {
316
346
  setTenantId(initConfig.tenantId);
317
347
  setBrand(initConfig.brand || Brand.ZERO);
@@ -333,27 +363,10 @@
333
363
  if (!valid) {
334
364
  return Promise.reject();
335
365
  }
336
- return fetchServerListHTTP();
366
+ return config.needMenus
367
+ ? doFetchServerList()
368
+ : Promise.resolve([]);
337
369
  }))
338
- .then(resp => {
339
- const menus = resp.data.content || [];
340
- const group = menus.find(menu => menu.groupName === config.moduleName);
341
- if (menus.length <= 0) {
342
- openDialog();
343
- return Promise.reject();
344
- }
345
- if (config.moduleName === 'commonLogin') {
346
- setupRefreshTokenTimer();
347
- return Promise.resolve(menus);
348
- }
349
- if (!group) {
350
- openDialog();
351
- return Promise.reject();
352
- }
353
- setSystemType(group.staffEndpoint ? SystemType.Staff : SystemType.Client);
354
- setupRefreshTokenTimer();
355
- return Promise.resolve(menus);
356
- })
357
370
  .catch((error) => __awaiter(void 0, void 0, void 0, function* () {
358
371
  clearRefreshTokenTimer();
359
372
  setAccessToken(null);
@@ -363,9 +376,8 @@
363
376
  };
364
377
  const detectUserInfoGroupAuth = (userInfo) => {
365
378
  const groups = userInfo['cognito:groups'] || [];
366
- if (!groups.includes(config.moduleName)
367
- && config.moduleName !== 'commonLogin'
368
- && config.moduleName !== 'App') {
379
+ if (!groups.includes(config.moduleName) &&
380
+ !isInWhiteList(config.moduleName)) {
369
381
  return false;
370
382
  }
371
383
  return true;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "login-authorization-v2",
4
- "version": "2.0.0",
4
+ "version": "2.0.2",
5
5
  "engines": {
6
6
  "node": "^20"
7
7
  },