login-authorization-v2 2.0.1 → 2.1.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
@@ -171,6 +171,7 @@ var Tenant;
171
171
  Tenant[Tenant["ZERO_LA"] = 4] = "ZERO_LA";
172
172
  Tenant[Tenant["ZERO_BR"] = 4] = "ZERO_BR";
173
173
  Tenant[Tenant["NISE_EU"] = 5] = "NISE_EU";
174
+ Tenant[Tenant["ZERO_AU"] = 6] = "ZERO_AU";
174
175
  })(Tenant || (Tenant = {}));
175
176
  var SystemType;
176
177
  (function (SystemType) {
@@ -302,7 +303,15 @@ const fetchServerListHTTP = () => {
302
303
  });
303
304
  };
304
305
 
306
+ const defaultMakeFnParams = {
307
+ needMenus: true
308
+ };
309
+ const whiteList = ['commonLogin', 'App'];
310
+ const isInWhiteList = (moduleName) => {
311
+ return whiteList.includes(moduleName);
312
+ };
305
313
  const make = (config) => {
314
+ config = Object.assign({}, defaultMakeFnParams, config);
306
315
  if (!config.moduleBaseUrl) {
307
316
  throw new Error(NO_MODULE_BASE_URL);
308
317
  }
@@ -310,6 +319,28 @@ const make = (config) => {
310
319
  setModuleBaseUrl(config.moduleBaseUrl);
311
320
  setLoginPageUrl(config.loginPageUrl);
312
321
  initInstance();
322
+ const doFetchServerList = () => {
323
+ return fetchServerListHTTP()
324
+ .then(resp => {
325
+ const menus = resp.data.content || [];
326
+ const group = menus.find(menu => menu.groupName === config.moduleName);
327
+ if (menus.length <= 0) {
328
+ openDialog();
329
+ return Promise.reject();
330
+ }
331
+ if (isInWhiteList(config.moduleName)) {
332
+ setupRefreshTokenTimer();
333
+ return Promise.resolve(menus);
334
+ }
335
+ if (!group) {
336
+ openDialog();
337
+ return Promise.reject();
338
+ }
339
+ setSystemType(group.staffEndpoint ? SystemType.Staff : SystemType.Client);
340
+ setupRefreshTokenTimer();
341
+ return Promise.resolve(menus);
342
+ });
343
+ };
313
344
  const init = (initConfig) => {
314
345
  setTenantId(initConfig.tenantId);
315
346
  setBrand(initConfig.brand || Brand.ZERO);
@@ -331,27 +362,10 @@ const make = (config) => {
331
362
  if (!valid) {
332
363
  return Promise.reject();
333
364
  }
334
- return fetchServerListHTTP();
365
+ return config.needMenus
366
+ ? doFetchServerList()
367
+ : Promise.resolve([]);
335
368
  }))
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' || config.moduleName === 'App') {
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
369
  .catch((error) => __awaiter(void 0, void 0, void 0, function* () {
356
370
  clearRefreshTokenTimer();
357
371
  setAccessToken(null);
@@ -361,9 +375,8 @@ const make = (config) => {
361
375
  };
362
376
  const detectUserInfoGroupAuth = (userInfo) => {
363
377
  const groups = userInfo['cognito:groups'] || [];
364
- if (!groups.includes(config.moduleName)
365
- && config.moduleName !== 'commonLogin'
366
- && config.moduleName !== 'App') {
378
+ if (!groups.includes(config.moduleName) &&
379
+ !isInWhiteList(config.moduleName)) {
367
380
  return false;
368
381
  }
369
382
  return true;
package/dist/index.umd.js CHANGED
@@ -173,6 +173,7 @@
173
173
  Tenant[Tenant["ZERO_LA"] = 4] = "ZERO_LA";
174
174
  Tenant[Tenant["ZERO_BR"] = 4] = "ZERO_BR";
175
175
  Tenant[Tenant["NISE_EU"] = 5] = "NISE_EU";
176
+ Tenant[Tenant["ZERO_AU"] = 6] = "ZERO_AU";
176
177
  })(Tenant || (Tenant = {}));
177
178
  var SystemType;
178
179
  (function (SystemType) {
@@ -304,7 +305,15 @@
304
305
  });
305
306
  };
306
307
 
308
+ const defaultMakeFnParams = {
309
+ needMenus: true
310
+ };
311
+ const whiteList = ['commonLogin', 'App'];
312
+ const isInWhiteList = (moduleName) => {
313
+ return whiteList.includes(moduleName);
314
+ };
307
315
  const make = (config) => {
316
+ config = Object.assign({}, defaultMakeFnParams, config);
308
317
  if (!config.moduleBaseUrl) {
309
318
  throw new Error(NO_MODULE_BASE_URL);
310
319
  }
@@ -312,6 +321,28 @@
312
321
  setModuleBaseUrl(config.moduleBaseUrl);
313
322
  setLoginPageUrl(config.loginPageUrl);
314
323
  initInstance();
324
+ const doFetchServerList = () => {
325
+ return fetchServerListHTTP()
326
+ .then(resp => {
327
+ const menus = resp.data.content || [];
328
+ const group = menus.find(menu => menu.groupName === config.moduleName);
329
+ if (menus.length <= 0) {
330
+ openDialog();
331
+ return Promise.reject();
332
+ }
333
+ if (isInWhiteList(config.moduleName)) {
334
+ setupRefreshTokenTimer();
335
+ return Promise.resolve(menus);
336
+ }
337
+ if (!group) {
338
+ openDialog();
339
+ return Promise.reject();
340
+ }
341
+ setSystemType(group.staffEndpoint ? SystemType.Staff : SystemType.Client);
342
+ setupRefreshTokenTimer();
343
+ return Promise.resolve(menus);
344
+ });
345
+ };
315
346
  const init = (initConfig) => {
316
347
  setTenantId(initConfig.tenantId);
317
348
  setBrand(initConfig.brand || Brand.ZERO);
@@ -333,27 +364,10 @@
333
364
  if (!valid) {
334
365
  return Promise.reject();
335
366
  }
336
- return fetchServerListHTTP();
367
+ return config.needMenus
368
+ ? doFetchServerList()
369
+ : Promise.resolve([]);
337
370
  }))
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' || config.moduleName === 'App') {
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
371
  .catch((error) => __awaiter(void 0, void 0, void 0, function* () {
358
372
  clearRefreshTokenTimer();
359
373
  setAccessToken(null);
@@ -363,9 +377,8 @@
363
377
  };
364
378
  const detectUserInfoGroupAuth = (userInfo) => {
365
379
  const groups = userInfo['cognito:groups'] || [];
366
- if (!groups.includes(config.moduleName)
367
- && config.moduleName !== 'commonLogin'
368
- && config.moduleName !== 'App') {
380
+ if (!groups.includes(config.moduleName) &&
381
+ !isInWhiteList(config.moduleName)) {
369
382
  return false;
370
383
  }
371
384
  return true;
@@ -85,7 +85,8 @@ export declare enum Tenant {
85
85
  ZERO_NZ = 3,
86
86
  ZERO_LA = 4,
87
87
  ZERO_BR = 4,
88
- NISE_EU = 5
88
+ NISE_EU = 5,
89
+ ZERO_AU = 6
89
90
  }
90
91
  export declare enum SystemType {
91
92
  Staff = "staff",
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyEH,CAAA;AAEV,MAAM,MAAM,UAAU,GAAG,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CA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gB,EAAE,UAAU,EAAE,CAAA;IAC9B,kBAAkB,EAAE,MAAM,CAAA;IAC1B,0BAA0B,EAAE,MAAM,CAAA;IAClC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,gBAAgB,EAAE,MAAM,CAAA;IACxB,OAAO,EAAE,MAAM,CAAA;IACf,gBAAgB,EAAE,OAAO,CAAA;IACzB,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,YAAY,EAAE,MAAM,CAAA;IACpB,oBAAoB,EAAE,MAAM,CAAA;IAC5B,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,oBAAY,KAAK;IACf,IAAI,IAAI;IACR,SAAS,IAAI;IACb,IAAI,IAAI;CACT;AAED,oBAAY,MAAM;IAChB,QAAQ,IAAI;IACZ,SAAS,IAAI;IACb,OAAO,IAAI;IACX,OAAO,IAAI;IACX,OAAO,IAAI;IACX,OAAO,IAAI;IACX,OAAO,IAAI;CACZ;AAED,oBAAY,UAAU;IACpB,KAAK,UAAU;IACf,MAAM,WAAW;CAClB"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "login-authorization-v2",
4
- "version": "2.0.1",
4
+ "version": "2.1.2",
5
5
  "engines": {
6
6
  "node": "^20"
7
7
  },
@@ -41,6 +41,7 @@
41
41
  },
42
42
  "devDependencies": {
43
43
  "@babel/preset-typescript": "^7.28.5",
44
+ "@babel/preset-env": "^7.22.20",
44
45
  "@jest/globals": "^30.2.0",
45
46
  "@rollup/plugin-commonjs": "^29.0.0",
46
47
  "@rollup/plugin-node-resolve": "^16.0.3",