@mu-cabin/opms-permission 0.9.9 → 0.9.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/dist/index.cjs CHANGED
@@ -35,6 +35,11 @@ __export(index_exports, {
35
35
  EnumOrgQueryScope: () => EnumOrgQueryScope,
36
36
  EventEmitter: () => EventEmitter,
37
37
  OpmsPermission: () => Permission,
38
+ RESOURCE_KEY: () => RESOURCE_KEY,
39
+ TOKEN_KEY: () => TOKEN_KEY,
40
+ USER_INFO_KEY: () => USER_INFO_KEY,
41
+ USER_ORG_KEY: () => USER_ORG_KEY,
42
+ USER_TOTAL_COMPANY_KEY: () => USER_TOTAL_COMPANY_KEY,
38
43
  getOrgTree: () => getOrgTree,
39
44
  getUserInfo: () => getUserInfo,
40
45
  getUserOrgTree: () => getUserOrgTree,
@@ -44,7 +49,8 @@ __export(index_exports, {
44
49
  logout: () => logout,
45
50
  queryOrgCompanies: () => queryOrgCompanies,
46
51
  queryOrgCustom: () => queryOrgCustom,
47
- queryResource: () => queryResource
52
+ queryResource: () => queryResource,
53
+ superLogin: () => superLogin
48
54
  });
49
55
  module.exports = __toCommonJS(index_exports);
50
56
 
@@ -365,6 +371,12 @@ async function login(baseUrl, authorizationCode) {
365
371
  }
366
372
  );
367
373
  }
374
+ async function superLogin(baseUrl, params) {
375
+ return await axiosClient.post(
376
+ `${baseUrl}/opmsDefaultAuth/superLogin`,
377
+ params
378
+ );
379
+ }
368
380
  async function logout(baseUrl) {
369
381
  return await axiosClient.post(
370
382
  `${baseUrl}/opmsDefaultAuth/logout`
@@ -400,9 +412,9 @@ async function queryOrgCompanies(baseUrl, params) {
400
412
  params
401
413
  );
402
414
  }
403
- function queryOrgCustom(params) {
415
+ function queryOrgCustom(baseUrl, params) {
404
416
  return import_axios.default.post(
405
- "/api/opmsDefaultUser/queryOrgCustom",
417
+ `${baseUrl}/opmsDefaultUser/queryOrgCustom`,
406
418
  params
407
419
  );
408
420
  }
@@ -580,8 +592,9 @@ var Permission = class {
580
592
  this.baseUrl = options.baseUrl;
581
593
  this.systemId = options.systemId;
582
594
  this.hasSubApp = options.hasSubApp ?? false;
583
- storage.setSystemId(this.systemId);
584
- storage.setVersion("1.0.0");
595
+ this.storage = new Storage();
596
+ this.storage.setSystemId(this.systemId);
597
+ this.storage.setVersion("1.0.0");
585
598
  }
586
599
  /**
587
600
  * Add event listener
@@ -629,6 +642,23 @@ var Permission = class {
629
642
  isEventSupported(event) {
630
643
  return this.eventEmitter.isEventAllowed(event);
631
644
  }
645
+ async superLogin(userName, password) {
646
+ this.clear();
647
+ const { obj, msg, code } = await superLogin(this.baseUrl, {
648
+ userName,
649
+ password
650
+ });
651
+ if (code !== 200 || !obj.token) {
652
+ return Promise.reject({
653
+ code,
654
+ msg
655
+ });
656
+ }
657
+ const { token } = obj;
658
+ this.storage.setItem(TOKEN_KEY, token);
659
+ this.emit("tokenChange", token);
660
+ return token;
661
+ }
632
662
  /**
633
663
  * Login using code from URL, save userInfo
634
664
  */
@@ -654,7 +684,7 @@ var Permission = class {
654
684
  }
655
685
  const { token } = obj;
656
686
  url.searchParams.delete("code");
657
- storage.setItem(TOKEN_KEY, token);
687
+ this.storage.setItem(TOKEN_KEY, token);
658
688
  this.emit("tokenChange", token);
659
689
  return token;
660
690
  }
@@ -666,7 +696,7 @@ var Permission = class {
666
696
  clearData && this.clear();
667
697
  }
668
698
  clear() {
669
- storage.clear();
699
+ this.storage.clear();
670
700
  this.emit("tokenChange", "");
671
701
  }
672
702
  async getUserInfo() {
@@ -678,7 +708,7 @@ var Permission = class {
678
708
  * Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
679
709
  */
680
710
  async getResources() {
681
- let resources = storage.getItem(RESOURCE_KEY) || null;
711
+ let resources = this.storage.getItem(RESOURCE_KEY) || null;
682
712
  if (!resources) {
683
713
  const { obj, success, msg, code } = await queryResource(this.baseUrl, {
684
714
  systemId: this.systemId
@@ -690,7 +720,7 @@ var Permission = class {
690
720
  });
691
721
  }
692
722
  resources = obj;
693
- storage.setItem(
723
+ this.storage.setItem(
694
724
  RESOURCE_KEY,
695
725
  resources,
696
726
  60 * 12
@@ -735,7 +765,7 @@ var Permission = class {
735
765
  let orgTreeData = null;
736
766
  if (!force) {
737
767
  const cacheKey = this.generateUserOrgsCacheKey(params);
738
- orgTreeData = storage.getItem(cacheKey) || null;
768
+ orgTreeData = this.storage.getItem(cacheKey) || null;
739
769
  }
740
770
  if (!orgTreeData) {
741
771
  const res = await getUserOrgTree(this.baseUrl, params);
@@ -754,7 +784,7 @@ var Permission = class {
754
784
  };
755
785
  });
756
786
  const cacheKey = this.generateUserOrgsCacheKey(params);
757
- storage.setItem(cacheKey, orgTreeData, cacheTimeout);
787
+ this.storage.setItem(cacheKey, orgTreeData, cacheTimeout);
758
788
  }
759
789
  const data = handlePermissionTree(orgTreeData, "orgId");
760
790
  const { tree } = data;
@@ -775,10 +805,10 @@ var Permission = class {
775
805
  const { force, cacheTimeout = 2 } = config;
776
806
  let orgCompanyList;
777
807
  if (!force) {
778
- orgCompanyList = storage.getItem(USER_TOTAL_COMPANY_KEY);
808
+ orgCompanyList = this.storage.getItem(USER_TOTAL_COMPANY_KEY);
779
809
  }
780
810
  if (!orgCompanyList) {
781
- const { obj } = await queryOrgCustom({
811
+ const { obj } = await queryOrgCustom(this.baseUrl, {
782
812
  resultView: "LIST",
783
813
  orgCodeSource: "COS",
784
814
  direction: "FROM_SELF_TO_LEAF",
@@ -798,18 +828,22 @@ var Permission = class {
798
828
  orgId: item.orgId
799
829
  };
800
830
  });
801
- storage.setItem(USER_TOTAL_COMPANY_KEY, orgCompanyList, cacheTimeout);
831
+ this.storage.setItem(
832
+ USER_TOTAL_COMPANY_KEY,
833
+ orgCompanyList,
834
+ cacheTimeout
835
+ );
802
836
  }
803
837
  return orgCompanyList;
804
838
  }
805
839
  isLogin() {
806
- return !!storage.getItem(TOKEN_KEY);
840
+ return !!this.storage.getItem(TOKEN_KEY);
807
841
  }
808
842
  getToken() {
809
- return storage.getItem(TOKEN_KEY);
843
+ return this.storage.getItem(TOKEN_KEY);
810
844
  }
811
845
  setToken(token) {
812
- storage.setItem(TOKEN_KEY, token);
846
+ this.storage.setItem(TOKEN_KEY, token);
813
847
  this.emit("tokenChange", token);
814
848
  }
815
849
  // --- Getters ---
@@ -834,21 +868,21 @@ var Permission = class {
834
868
  * Get storage information for debugging and monitoring
835
869
  */
836
870
  getStorageInfo() {
837
- const keys = storage.getKeys();
871
+ const keys = this.storage.getKeys();
838
872
  const userOrgsCacheKeys = keys.filter(
839
873
  (key) => key.startsWith(USER_ORG_KEY)
840
874
  );
841
875
  return {
842
- ...storage.getStorageInfo(),
876
+ ...this.storage.getStorageInfo(),
843
877
  permissionKeys: {
844
878
  resourceKey: RESOURCE_KEY,
845
879
  tokenKey: TOKEN_KEY,
846
880
  userInfoKey: USER_INFO_KEY
847
881
  },
848
882
  hasData: {
849
- resources: storage.hasKey(RESOURCE_KEY),
850
- token: storage.hasKey(TOKEN_KEY),
851
- userInfo: storage.hasKey(USER_INFO_KEY)
883
+ resources: this.storage.hasKey(RESOURCE_KEY),
884
+ token: this.storage.hasKey(TOKEN_KEY),
885
+ userInfo: this.storage.hasKey(USER_INFO_KEY)
852
886
  },
853
887
  cacheInfo: {
854
888
  userOrgsCacheCount: userOrgsCacheKeys.length,
@@ -860,13 +894,16 @@ var Permission = class {
860
894
  * Get current storage version
861
895
  */
862
896
  getStorageVersion() {
863
- return storage.getVersion();
897
+ return this.storage.getVersion();
864
898
  }
865
899
  /**
866
900
  * Clear all storage data for this system
867
901
  */
868
902
  clearStorage() {
869
- storage.clear();
903
+ this.storage.clear();
904
+ }
905
+ clearAuthCache() {
906
+ this.storage.removeItem(TOKEN_KEY);
870
907
  }
871
908
  /**
872
909
  * Clear user orgs cache for specific parameters or all
@@ -874,16 +911,32 @@ var Permission = class {
874
911
  clearUserOrgsCache(params) {
875
912
  if (params) {
876
913
  const cacheKey = this.generateUserOrgsCacheKey(params);
877
- storage.removeItem(cacheKey);
914
+ this.storage.removeItem(cacheKey);
878
915
  } else {
879
- const keys = storage.getKeys();
916
+ const keys = this.storage.getKeys();
880
917
  keys.forEach((key) => {
881
918
  if (key.startsWith(USER_ORG_KEY)) {
882
- storage.removeItem(key);
919
+ this.storage.removeItem(key);
883
920
  }
884
921
  });
885
922
  }
886
923
  }
924
+ clearUserCache() {
925
+ const keys = this.storage.getKeys();
926
+ keys.forEach((key) => {
927
+ if (key.startsWith(USER_ORG_KEY) || key.startsWith(USER_TOTAL_COMPANY_KEY) || key.startsWith(USER_INFO_KEY)) {
928
+ this.storage.removeItem(key);
929
+ }
930
+ });
931
+ }
932
+ clearAppCache() {
933
+ const keys = this.storage.getKeys();
934
+ keys.forEach((key) => {
935
+ if (key.startsWith(RESOURCE_KEY)) {
936
+ this.storage.removeItem(key);
937
+ }
938
+ });
939
+ }
887
940
  };
888
941
 
889
942
  // src/sso.ts
@@ -927,6 +980,11 @@ function jumpToSSOLogout({
927
980
  EnumOrgQueryScope,
928
981
  EventEmitter,
929
982
  OpmsPermission,
983
+ RESOURCE_KEY,
984
+ TOKEN_KEY,
985
+ USER_INFO_KEY,
986
+ USER_ORG_KEY,
987
+ USER_TOTAL_COMPANY_KEY,
930
988
  getOrgTree,
931
989
  getUserInfo,
932
990
  getUserOrgTree,
@@ -936,5 +994,6 @@ function jumpToSSOLogout({
936
994
  logout,
937
995
  queryOrgCompanies,
938
996
  queryOrgCustom,
939
- queryResource
997
+ queryResource,
998
+ superLogin
940
999
  });
package/dist/index.d.mts CHANGED
@@ -101,6 +101,12 @@ interface UserOrgTreeParams {
101
101
  declare function login(baseUrl: string, authorizationCode: string): Promise<ApiResponse<{
102
102
  token: string;
103
103
  }>>;
104
+ declare function superLogin(baseUrl: string, params: {
105
+ userName: string;
106
+ password: string;
107
+ }): Promise<ApiResponse<{
108
+ token: string;
109
+ }>>;
104
110
  declare function logout(baseUrl: string): Promise<ApiResponse<void>>;
105
111
  declare function getUserInfo(baseUrl: string): Promise<ApiResponse<UserInfo$1>>;
106
112
  declare function queryResource(baseUrl: string, params: {
@@ -128,7 +134,63 @@ interface QueryOrgCustomParams {
128
134
  /**
129
135
  * 根据查询条件自定义组织机构查询
130
136
  */
131
- declare function queryOrgCustom(params: QueryOrgCustomParams): Promise<ApiResponse<OrgRecord$1[]>>;
137
+ declare function queryOrgCustom(baseUrl: string, params: QueryOrgCustomParams): Promise<ApiResponse<OrgRecord$1[]>>;
138
+
139
+ declare class Storage {
140
+ private systemId?;
141
+ private currentVersion;
142
+ setSystemId(systemId: number | string): void;
143
+ /**
144
+ * Set the current version for new data
145
+ * If version changes, all existing data for this systemId will be cleared
146
+ */
147
+ setVersion(version: string): void;
148
+ /**
149
+ * Get the current version
150
+ */
151
+ getVersion(): string;
152
+ private prefixKey;
153
+ /**
154
+ * Set an item in localStorage, with optional expiration in minutes
155
+ */
156
+ setItem<T>(key: string, value: T, expireMinutes?: number): void;
157
+ /**
158
+ * Get an item from localStorage, returns undefined if expired or not found
159
+ * Automatically expires data if version is different
160
+ */
161
+ getItem<T>(key: string): T | undefined;
162
+ /**
163
+ * Remove an item from localStorage
164
+ */
165
+ removeItem(key: string): void;
166
+ /**
167
+ * Clear all data for the current systemId
168
+ */
169
+ clear(): void;
170
+ /**
171
+ * Get all keys for the current systemId
172
+ */
173
+ getKeys(): string[];
174
+ /**
175
+ * Check if a key exists
176
+ */
177
+ hasKey(key: string): boolean;
178
+ /**
179
+ * Get storage info for debugging
180
+ */
181
+ getStorageInfo(): {
182
+ systemId: number | string | undefined;
183
+ currentVersion: string;
184
+ totalKeys: number;
185
+ systemKeys: number;
186
+ };
187
+ }
188
+
189
+ declare const USER_INFO_KEY = "opms_user_info";
190
+ declare const RESOURCE_KEY = "opms_resources";
191
+ declare const TOKEN_KEY = "opms_authorization";
192
+ declare const USER_TOTAL_COMPANY_KEY = "opms_user_total_company";
193
+ declare const USER_ORG_KEY = "opms_user_orgs";
132
194
 
133
195
  interface MenuItem {
134
196
  icon?: string;
@@ -311,6 +373,7 @@ declare class Permission {
311
373
  [path: string]: MenuItem;
312
374
  };
313
375
  hasSubApp: boolean;
376
+ storage: Storage;
314
377
  private eventEmitter;
315
378
  constructor(options: PermissionOptions);
316
379
  /**
@@ -337,6 +400,7 @@ declare class Permission {
337
400
  * Check if an event is supported
338
401
  */
339
402
  isEventSupported(event: string): event is PermissionEventType;
403
+ superLogin(userName: string, password: string): Promise<string>;
340
404
  /**
341
405
  * Login using code from URL, save userInfo
342
406
  */
@@ -412,10 +476,13 @@ declare class Permission {
412
476
  * Clear all storage data for this system
413
477
  */
414
478
  clearStorage(): void;
479
+ clearAuthCache(): void;
415
480
  /**
416
481
  * Clear user orgs cache for specific parameters or all
417
482
  */
418
483
  clearUserOrgsCache(params?: UserOrgTreeParams): void;
484
+ clearUserCache(): void;
485
+ clearAppCache(): void;
419
486
  }
420
487
 
421
488
  /**
@@ -440,4 +507,4 @@ declare function jumpToSSOLogout({ baseUrl, redirectToUrl, clientId, }: {
440
507
  clientId?: string;
441
508
  }): void;
442
509
 
443
- export { type ApiResponse, type ChildOrganization, type CodeSourceType, DataHandler, EnumOrgQueryMode, EnumOrgQueryScope, EventEmitter, type MenuItem, type OpenIndicatorType, Permission as OpmsPermission, type Option, type OrgDirectionType, type OrgRecord, type OrgTreeItem, type OrgType, type PermissionEventListener, type PermissionEventMap, type PermissionEventType, type QueryOrgCustomParams, type Resource, type ResourceType, type ResultViewType, type UserInfo, type UserOrgTreeParams, type UserOrganization, type UserRole, getOrgTree, getUserInfo, getUserOrgTree, jumpToSSOLogin, jumpToSSOLogout, login, logout, queryOrgCompanies, queryOrgCustom, queryResource };
510
+ export { type ApiResponse, type ChildOrganization, type CodeSourceType, DataHandler, EnumOrgQueryMode, EnumOrgQueryScope, EventEmitter, type MenuItem, type OpenIndicatorType, Permission as OpmsPermission, type Option, type OrgDirectionType, type OrgRecord, type OrgTreeItem, type OrgType, type PermissionEventListener, type PermissionEventMap, type PermissionEventType, type QueryOrgCustomParams, RESOURCE_KEY, type Resource, type ResourceType, type ResultViewType, TOKEN_KEY, USER_INFO_KEY, USER_ORG_KEY, USER_TOTAL_COMPANY_KEY, type UserInfo, type UserOrgTreeParams, type UserOrganization, type UserRole, getOrgTree, getUserInfo, getUserOrgTree, jumpToSSOLogin, jumpToSSOLogout, login, logout, queryOrgCompanies, queryOrgCustom, queryResource, superLogin };
package/dist/index.d.ts CHANGED
@@ -101,6 +101,12 @@ interface UserOrgTreeParams {
101
101
  declare function login(baseUrl: string, authorizationCode: string): Promise<ApiResponse<{
102
102
  token: string;
103
103
  }>>;
104
+ declare function superLogin(baseUrl: string, params: {
105
+ userName: string;
106
+ password: string;
107
+ }): Promise<ApiResponse<{
108
+ token: string;
109
+ }>>;
104
110
  declare function logout(baseUrl: string): Promise<ApiResponse<void>>;
105
111
  declare function getUserInfo(baseUrl: string): Promise<ApiResponse<UserInfo$1>>;
106
112
  declare function queryResource(baseUrl: string, params: {
@@ -128,7 +134,63 @@ interface QueryOrgCustomParams {
128
134
  /**
129
135
  * 根据查询条件自定义组织机构查询
130
136
  */
131
- declare function queryOrgCustom(params: QueryOrgCustomParams): Promise<ApiResponse<OrgRecord$1[]>>;
137
+ declare function queryOrgCustom(baseUrl: string, params: QueryOrgCustomParams): Promise<ApiResponse<OrgRecord$1[]>>;
138
+
139
+ declare class Storage {
140
+ private systemId?;
141
+ private currentVersion;
142
+ setSystemId(systemId: number | string): void;
143
+ /**
144
+ * Set the current version for new data
145
+ * If version changes, all existing data for this systemId will be cleared
146
+ */
147
+ setVersion(version: string): void;
148
+ /**
149
+ * Get the current version
150
+ */
151
+ getVersion(): string;
152
+ private prefixKey;
153
+ /**
154
+ * Set an item in localStorage, with optional expiration in minutes
155
+ */
156
+ setItem<T>(key: string, value: T, expireMinutes?: number): void;
157
+ /**
158
+ * Get an item from localStorage, returns undefined if expired or not found
159
+ * Automatically expires data if version is different
160
+ */
161
+ getItem<T>(key: string): T | undefined;
162
+ /**
163
+ * Remove an item from localStorage
164
+ */
165
+ removeItem(key: string): void;
166
+ /**
167
+ * Clear all data for the current systemId
168
+ */
169
+ clear(): void;
170
+ /**
171
+ * Get all keys for the current systemId
172
+ */
173
+ getKeys(): string[];
174
+ /**
175
+ * Check if a key exists
176
+ */
177
+ hasKey(key: string): boolean;
178
+ /**
179
+ * Get storage info for debugging
180
+ */
181
+ getStorageInfo(): {
182
+ systemId: number | string | undefined;
183
+ currentVersion: string;
184
+ totalKeys: number;
185
+ systemKeys: number;
186
+ };
187
+ }
188
+
189
+ declare const USER_INFO_KEY = "opms_user_info";
190
+ declare const RESOURCE_KEY = "opms_resources";
191
+ declare const TOKEN_KEY = "opms_authorization";
192
+ declare const USER_TOTAL_COMPANY_KEY = "opms_user_total_company";
193
+ declare const USER_ORG_KEY = "opms_user_orgs";
132
194
 
133
195
  interface MenuItem {
134
196
  icon?: string;
@@ -311,6 +373,7 @@ declare class Permission {
311
373
  [path: string]: MenuItem;
312
374
  };
313
375
  hasSubApp: boolean;
376
+ storage: Storage;
314
377
  private eventEmitter;
315
378
  constructor(options: PermissionOptions);
316
379
  /**
@@ -337,6 +400,7 @@ declare class Permission {
337
400
  * Check if an event is supported
338
401
  */
339
402
  isEventSupported(event: string): event is PermissionEventType;
403
+ superLogin(userName: string, password: string): Promise<string>;
340
404
  /**
341
405
  * Login using code from URL, save userInfo
342
406
  */
@@ -412,10 +476,13 @@ declare class Permission {
412
476
  * Clear all storage data for this system
413
477
  */
414
478
  clearStorage(): void;
479
+ clearAuthCache(): void;
415
480
  /**
416
481
  * Clear user orgs cache for specific parameters or all
417
482
  */
418
483
  clearUserOrgsCache(params?: UserOrgTreeParams): void;
484
+ clearUserCache(): void;
485
+ clearAppCache(): void;
419
486
  }
420
487
 
421
488
  /**
@@ -440,4 +507,4 @@ declare function jumpToSSOLogout({ baseUrl, redirectToUrl, clientId, }: {
440
507
  clientId?: string;
441
508
  }): void;
442
509
 
443
- export { type ApiResponse, type ChildOrganization, type CodeSourceType, DataHandler, EnumOrgQueryMode, EnumOrgQueryScope, EventEmitter, type MenuItem, type OpenIndicatorType, Permission as OpmsPermission, type Option, type OrgDirectionType, type OrgRecord, type OrgTreeItem, type OrgType, type PermissionEventListener, type PermissionEventMap, type PermissionEventType, type QueryOrgCustomParams, type Resource, type ResourceType, type ResultViewType, type UserInfo, type UserOrgTreeParams, type UserOrganization, type UserRole, getOrgTree, getUserInfo, getUserOrgTree, jumpToSSOLogin, jumpToSSOLogout, login, logout, queryOrgCompanies, queryOrgCustom, queryResource };
510
+ export { type ApiResponse, type ChildOrganization, type CodeSourceType, DataHandler, EnumOrgQueryMode, EnumOrgQueryScope, EventEmitter, type MenuItem, type OpenIndicatorType, Permission as OpmsPermission, type Option, type OrgDirectionType, type OrgRecord, type OrgTreeItem, type OrgType, type PermissionEventListener, type PermissionEventMap, type PermissionEventType, type QueryOrgCustomParams, RESOURCE_KEY, type Resource, type ResourceType, type ResultViewType, TOKEN_KEY, USER_INFO_KEY, USER_ORG_KEY, USER_TOTAL_COMPANY_KEY, type UserInfo, type UserOrgTreeParams, type UserOrganization, type UserRole, getOrgTree, getUserInfo, getUserOrgTree, jumpToSSOLogin, jumpToSSOLogout, login, logout, queryOrgCompanies, queryOrgCustom, queryResource, superLogin };
package/dist/index.mjs CHANGED
@@ -315,6 +315,12 @@ async function login(baseUrl, authorizationCode) {
315
315
  }
316
316
  );
317
317
  }
318
+ async function superLogin(baseUrl, params) {
319
+ return await axiosClient.post(
320
+ `${baseUrl}/opmsDefaultAuth/superLogin`,
321
+ params
322
+ );
323
+ }
318
324
  async function logout(baseUrl) {
319
325
  return await axiosClient.post(
320
326
  `${baseUrl}/opmsDefaultAuth/logout`
@@ -350,9 +356,9 @@ async function queryOrgCompanies(baseUrl, params) {
350
356
  params
351
357
  );
352
358
  }
353
- function queryOrgCustom(params) {
359
+ function queryOrgCustom(baseUrl, params) {
354
360
  return axios.post(
355
- "/api/opmsDefaultUser/queryOrgCustom",
361
+ `${baseUrl}/opmsDefaultUser/queryOrgCustom`,
356
362
  params
357
363
  );
358
364
  }
@@ -530,8 +536,9 @@ var Permission = class {
530
536
  this.baseUrl = options.baseUrl;
531
537
  this.systemId = options.systemId;
532
538
  this.hasSubApp = options.hasSubApp ?? false;
533
- storage.setSystemId(this.systemId);
534
- storage.setVersion("1.0.0");
539
+ this.storage = new Storage();
540
+ this.storage.setSystemId(this.systemId);
541
+ this.storage.setVersion("1.0.0");
535
542
  }
536
543
  /**
537
544
  * Add event listener
@@ -579,6 +586,23 @@ var Permission = class {
579
586
  isEventSupported(event) {
580
587
  return this.eventEmitter.isEventAllowed(event);
581
588
  }
589
+ async superLogin(userName, password) {
590
+ this.clear();
591
+ const { obj, msg, code } = await superLogin(this.baseUrl, {
592
+ userName,
593
+ password
594
+ });
595
+ if (code !== 200 || !obj.token) {
596
+ return Promise.reject({
597
+ code,
598
+ msg
599
+ });
600
+ }
601
+ const { token } = obj;
602
+ this.storage.setItem(TOKEN_KEY, token);
603
+ this.emit("tokenChange", token);
604
+ return token;
605
+ }
582
606
  /**
583
607
  * Login using code from URL, save userInfo
584
608
  */
@@ -604,7 +628,7 @@ var Permission = class {
604
628
  }
605
629
  const { token } = obj;
606
630
  url.searchParams.delete("code");
607
- storage.setItem(TOKEN_KEY, token);
631
+ this.storage.setItem(TOKEN_KEY, token);
608
632
  this.emit("tokenChange", token);
609
633
  return token;
610
634
  }
@@ -616,7 +640,7 @@ var Permission = class {
616
640
  clearData && this.clear();
617
641
  }
618
642
  clear() {
619
- storage.clear();
643
+ this.storage.clear();
620
644
  this.emit("tokenChange", "");
621
645
  }
622
646
  async getUserInfo() {
@@ -628,7 +652,7 @@ var Permission = class {
628
652
  * Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
629
653
  */
630
654
  async getResources() {
631
- let resources = storage.getItem(RESOURCE_KEY) || null;
655
+ let resources = this.storage.getItem(RESOURCE_KEY) || null;
632
656
  if (!resources) {
633
657
  const { obj, success, msg, code } = await queryResource(this.baseUrl, {
634
658
  systemId: this.systemId
@@ -640,7 +664,7 @@ var Permission = class {
640
664
  });
641
665
  }
642
666
  resources = obj;
643
- storage.setItem(
667
+ this.storage.setItem(
644
668
  RESOURCE_KEY,
645
669
  resources,
646
670
  60 * 12
@@ -685,7 +709,7 @@ var Permission = class {
685
709
  let orgTreeData = null;
686
710
  if (!force) {
687
711
  const cacheKey = this.generateUserOrgsCacheKey(params);
688
- orgTreeData = storage.getItem(cacheKey) || null;
712
+ orgTreeData = this.storage.getItem(cacheKey) || null;
689
713
  }
690
714
  if (!orgTreeData) {
691
715
  const res = await getUserOrgTree(this.baseUrl, params);
@@ -704,7 +728,7 @@ var Permission = class {
704
728
  };
705
729
  });
706
730
  const cacheKey = this.generateUserOrgsCacheKey(params);
707
- storage.setItem(cacheKey, orgTreeData, cacheTimeout);
731
+ this.storage.setItem(cacheKey, orgTreeData, cacheTimeout);
708
732
  }
709
733
  const data = handlePermissionTree(orgTreeData, "orgId");
710
734
  const { tree } = data;
@@ -725,10 +749,10 @@ var Permission = class {
725
749
  const { force, cacheTimeout = 2 } = config;
726
750
  let orgCompanyList;
727
751
  if (!force) {
728
- orgCompanyList = storage.getItem(USER_TOTAL_COMPANY_KEY);
752
+ orgCompanyList = this.storage.getItem(USER_TOTAL_COMPANY_KEY);
729
753
  }
730
754
  if (!orgCompanyList) {
731
- const { obj } = await queryOrgCustom({
755
+ const { obj } = await queryOrgCustom(this.baseUrl, {
732
756
  resultView: "LIST",
733
757
  orgCodeSource: "COS",
734
758
  direction: "FROM_SELF_TO_LEAF",
@@ -748,18 +772,22 @@ var Permission = class {
748
772
  orgId: item.orgId
749
773
  };
750
774
  });
751
- storage.setItem(USER_TOTAL_COMPANY_KEY, orgCompanyList, cacheTimeout);
775
+ this.storage.setItem(
776
+ USER_TOTAL_COMPANY_KEY,
777
+ orgCompanyList,
778
+ cacheTimeout
779
+ );
752
780
  }
753
781
  return orgCompanyList;
754
782
  }
755
783
  isLogin() {
756
- return !!storage.getItem(TOKEN_KEY);
784
+ return !!this.storage.getItem(TOKEN_KEY);
757
785
  }
758
786
  getToken() {
759
- return storage.getItem(TOKEN_KEY);
787
+ return this.storage.getItem(TOKEN_KEY);
760
788
  }
761
789
  setToken(token) {
762
- storage.setItem(TOKEN_KEY, token);
790
+ this.storage.setItem(TOKEN_KEY, token);
763
791
  this.emit("tokenChange", token);
764
792
  }
765
793
  // --- Getters ---
@@ -784,21 +812,21 @@ var Permission = class {
784
812
  * Get storage information for debugging and monitoring
785
813
  */
786
814
  getStorageInfo() {
787
- const keys = storage.getKeys();
815
+ const keys = this.storage.getKeys();
788
816
  const userOrgsCacheKeys = keys.filter(
789
817
  (key) => key.startsWith(USER_ORG_KEY)
790
818
  );
791
819
  return {
792
- ...storage.getStorageInfo(),
820
+ ...this.storage.getStorageInfo(),
793
821
  permissionKeys: {
794
822
  resourceKey: RESOURCE_KEY,
795
823
  tokenKey: TOKEN_KEY,
796
824
  userInfoKey: USER_INFO_KEY
797
825
  },
798
826
  hasData: {
799
- resources: storage.hasKey(RESOURCE_KEY),
800
- token: storage.hasKey(TOKEN_KEY),
801
- userInfo: storage.hasKey(USER_INFO_KEY)
827
+ resources: this.storage.hasKey(RESOURCE_KEY),
828
+ token: this.storage.hasKey(TOKEN_KEY),
829
+ userInfo: this.storage.hasKey(USER_INFO_KEY)
802
830
  },
803
831
  cacheInfo: {
804
832
  userOrgsCacheCount: userOrgsCacheKeys.length,
@@ -810,13 +838,16 @@ var Permission = class {
810
838
  * Get current storage version
811
839
  */
812
840
  getStorageVersion() {
813
- return storage.getVersion();
841
+ return this.storage.getVersion();
814
842
  }
815
843
  /**
816
844
  * Clear all storage data for this system
817
845
  */
818
846
  clearStorage() {
819
- storage.clear();
847
+ this.storage.clear();
848
+ }
849
+ clearAuthCache() {
850
+ this.storage.removeItem(TOKEN_KEY);
820
851
  }
821
852
  /**
822
853
  * Clear user orgs cache for specific parameters or all
@@ -824,16 +855,32 @@ var Permission = class {
824
855
  clearUserOrgsCache(params) {
825
856
  if (params) {
826
857
  const cacheKey = this.generateUserOrgsCacheKey(params);
827
- storage.removeItem(cacheKey);
858
+ this.storage.removeItem(cacheKey);
828
859
  } else {
829
- const keys = storage.getKeys();
860
+ const keys = this.storage.getKeys();
830
861
  keys.forEach((key) => {
831
862
  if (key.startsWith(USER_ORG_KEY)) {
832
- storage.removeItem(key);
863
+ this.storage.removeItem(key);
833
864
  }
834
865
  });
835
866
  }
836
867
  }
868
+ clearUserCache() {
869
+ const keys = this.storage.getKeys();
870
+ keys.forEach((key) => {
871
+ if (key.startsWith(USER_ORG_KEY) || key.startsWith(USER_TOTAL_COMPANY_KEY) || key.startsWith(USER_INFO_KEY)) {
872
+ this.storage.removeItem(key);
873
+ }
874
+ });
875
+ }
876
+ clearAppCache() {
877
+ const keys = this.storage.getKeys();
878
+ keys.forEach((key) => {
879
+ if (key.startsWith(RESOURCE_KEY)) {
880
+ this.storage.removeItem(key);
881
+ }
882
+ });
883
+ }
837
884
  };
838
885
 
839
886
  // src/sso.ts
@@ -876,6 +923,11 @@ export {
876
923
  EnumOrgQueryScope,
877
924
  EventEmitter,
878
925
  Permission as OpmsPermission,
926
+ RESOURCE_KEY,
927
+ TOKEN_KEY,
928
+ USER_INFO_KEY,
929
+ USER_ORG_KEY,
930
+ USER_TOTAL_COMPANY_KEY,
879
931
  getOrgTree,
880
932
  getUserInfo,
881
933
  getUserOrgTree,
@@ -885,5 +937,6 @@ export {
885
937
  logout,
886
938
  queryOrgCompanies,
887
939
  queryOrgCustom,
888
- queryResource
940
+ queryResource,
941
+ superLogin
889
942
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mu-cabin/opms-permission",
3
- "version": "0.9.9",
3
+ "version": "0.9.11",
4
4
  "description": "Frontend SDK for OPMS permission and auth management.",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",