@mu-cabin/opms-permission 0.9.10 → 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,
@@ -587,8 +592,9 @@ var Permission = class {
587
592
  this.baseUrl = options.baseUrl;
588
593
  this.systemId = options.systemId;
589
594
  this.hasSubApp = options.hasSubApp ?? false;
590
- storage.setSystemId(this.systemId);
591
- storage.setVersion("1.0.0");
595
+ this.storage = new Storage();
596
+ this.storage.setSystemId(this.systemId);
597
+ this.storage.setVersion("1.0.0");
592
598
  }
593
599
  /**
594
600
  * Add event listener
@@ -649,7 +655,7 @@ var Permission = class {
649
655
  });
650
656
  }
651
657
  const { token } = obj;
652
- storage.setItem(TOKEN_KEY, token);
658
+ this.storage.setItem(TOKEN_KEY, token);
653
659
  this.emit("tokenChange", token);
654
660
  return token;
655
661
  }
@@ -678,7 +684,7 @@ var Permission = class {
678
684
  }
679
685
  const { token } = obj;
680
686
  url.searchParams.delete("code");
681
- storage.setItem(TOKEN_KEY, token);
687
+ this.storage.setItem(TOKEN_KEY, token);
682
688
  this.emit("tokenChange", token);
683
689
  return token;
684
690
  }
@@ -690,7 +696,7 @@ var Permission = class {
690
696
  clearData && this.clear();
691
697
  }
692
698
  clear() {
693
- storage.clear();
699
+ this.storage.clear();
694
700
  this.emit("tokenChange", "");
695
701
  }
696
702
  async getUserInfo() {
@@ -702,7 +708,7 @@ var Permission = class {
702
708
  * Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
703
709
  */
704
710
  async getResources() {
705
- let resources = storage.getItem(RESOURCE_KEY) || null;
711
+ let resources = this.storage.getItem(RESOURCE_KEY) || null;
706
712
  if (!resources) {
707
713
  const { obj, success, msg, code } = await queryResource(this.baseUrl, {
708
714
  systemId: this.systemId
@@ -714,7 +720,7 @@ var Permission = class {
714
720
  });
715
721
  }
716
722
  resources = obj;
717
- storage.setItem(
723
+ this.storage.setItem(
718
724
  RESOURCE_KEY,
719
725
  resources,
720
726
  60 * 12
@@ -759,7 +765,7 @@ var Permission = class {
759
765
  let orgTreeData = null;
760
766
  if (!force) {
761
767
  const cacheKey = this.generateUserOrgsCacheKey(params);
762
- orgTreeData = storage.getItem(cacheKey) || null;
768
+ orgTreeData = this.storage.getItem(cacheKey) || null;
763
769
  }
764
770
  if (!orgTreeData) {
765
771
  const res = await getUserOrgTree(this.baseUrl, params);
@@ -778,7 +784,7 @@ var Permission = class {
778
784
  };
779
785
  });
780
786
  const cacheKey = this.generateUserOrgsCacheKey(params);
781
- storage.setItem(cacheKey, orgTreeData, cacheTimeout);
787
+ this.storage.setItem(cacheKey, orgTreeData, cacheTimeout);
782
788
  }
783
789
  const data = handlePermissionTree(orgTreeData, "orgId");
784
790
  const { tree } = data;
@@ -799,7 +805,7 @@ var Permission = class {
799
805
  const { force, cacheTimeout = 2 } = config;
800
806
  let orgCompanyList;
801
807
  if (!force) {
802
- orgCompanyList = storage.getItem(USER_TOTAL_COMPANY_KEY);
808
+ orgCompanyList = this.storage.getItem(USER_TOTAL_COMPANY_KEY);
803
809
  }
804
810
  if (!orgCompanyList) {
805
811
  const { obj } = await queryOrgCustom(this.baseUrl, {
@@ -822,18 +828,22 @@ var Permission = class {
822
828
  orgId: item.orgId
823
829
  };
824
830
  });
825
- storage.setItem(USER_TOTAL_COMPANY_KEY, orgCompanyList, cacheTimeout);
831
+ this.storage.setItem(
832
+ USER_TOTAL_COMPANY_KEY,
833
+ orgCompanyList,
834
+ cacheTimeout
835
+ );
826
836
  }
827
837
  return orgCompanyList;
828
838
  }
829
839
  isLogin() {
830
- return !!storage.getItem(TOKEN_KEY);
840
+ return !!this.storage.getItem(TOKEN_KEY);
831
841
  }
832
842
  getToken() {
833
- return storage.getItem(TOKEN_KEY);
843
+ return this.storage.getItem(TOKEN_KEY);
834
844
  }
835
845
  setToken(token) {
836
- storage.setItem(TOKEN_KEY, token);
846
+ this.storage.setItem(TOKEN_KEY, token);
837
847
  this.emit("tokenChange", token);
838
848
  }
839
849
  // --- Getters ---
@@ -858,21 +868,21 @@ var Permission = class {
858
868
  * Get storage information for debugging and monitoring
859
869
  */
860
870
  getStorageInfo() {
861
- const keys = storage.getKeys();
871
+ const keys = this.storage.getKeys();
862
872
  const userOrgsCacheKeys = keys.filter(
863
873
  (key) => key.startsWith(USER_ORG_KEY)
864
874
  );
865
875
  return {
866
- ...storage.getStorageInfo(),
876
+ ...this.storage.getStorageInfo(),
867
877
  permissionKeys: {
868
878
  resourceKey: RESOURCE_KEY,
869
879
  tokenKey: TOKEN_KEY,
870
880
  userInfoKey: USER_INFO_KEY
871
881
  },
872
882
  hasData: {
873
- resources: storage.hasKey(RESOURCE_KEY),
874
- token: storage.hasKey(TOKEN_KEY),
875
- 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)
876
886
  },
877
887
  cacheInfo: {
878
888
  userOrgsCacheCount: userOrgsCacheKeys.length,
@@ -884,13 +894,16 @@ var Permission = class {
884
894
  * Get current storage version
885
895
  */
886
896
  getStorageVersion() {
887
- return storage.getVersion();
897
+ return this.storage.getVersion();
888
898
  }
889
899
  /**
890
900
  * Clear all storage data for this system
891
901
  */
892
902
  clearStorage() {
893
- storage.clear();
903
+ this.storage.clear();
904
+ }
905
+ clearAuthCache() {
906
+ this.storage.removeItem(TOKEN_KEY);
894
907
  }
895
908
  /**
896
909
  * Clear user orgs cache for specific parameters or all
@@ -898,16 +911,32 @@ var Permission = class {
898
911
  clearUserOrgsCache(params) {
899
912
  if (params) {
900
913
  const cacheKey = this.generateUserOrgsCacheKey(params);
901
- storage.removeItem(cacheKey);
914
+ this.storage.removeItem(cacheKey);
902
915
  } else {
903
- const keys = storage.getKeys();
916
+ const keys = this.storage.getKeys();
904
917
  keys.forEach((key) => {
905
918
  if (key.startsWith(USER_ORG_KEY)) {
906
- storage.removeItem(key);
919
+ this.storage.removeItem(key);
907
920
  }
908
921
  });
909
922
  }
910
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
+ }
911
940
  };
912
941
 
913
942
  // src/sso.ts
@@ -951,6 +980,11 @@ function jumpToSSOLogout({
951
980
  EnumOrgQueryScope,
952
981
  EventEmitter,
953
982
  OpmsPermission,
983
+ RESOURCE_KEY,
984
+ TOKEN_KEY,
985
+ USER_INFO_KEY,
986
+ USER_ORG_KEY,
987
+ USER_TOTAL_COMPANY_KEY,
954
988
  getOrgTree,
955
989
  getUserInfo,
956
990
  getUserOrgTree,
package/dist/index.d.mts CHANGED
@@ -136,6 +136,62 @@ interface QueryOrgCustomParams {
136
136
  */
137
137
  declare function queryOrgCustom(baseUrl: string, params: QueryOrgCustomParams): Promise<ApiResponse<OrgRecord$1[]>>;
138
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";
194
+
139
195
  interface MenuItem {
140
196
  icon?: string;
141
197
  path: string;
@@ -317,6 +373,7 @@ declare class Permission {
317
373
  [path: string]: MenuItem;
318
374
  };
319
375
  hasSubApp: boolean;
376
+ storage: Storage;
320
377
  private eventEmitter;
321
378
  constructor(options: PermissionOptions);
322
379
  /**
@@ -419,10 +476,13 @@ declare class Permission {
419
476
  * Clear all storage data for this system
420
477
  */
421
478
  clearStorage(): void;
479
+ clearAuthCache(): void;
422
480
  /**
423
481
  * Clear user orgs cache for specific parameters or all
424
482
  */
425
483
  clearUserOrgsCache(params?: UserOrgTreeParams): void;
484
+ clearUserCache(): void;
485
+ clearAppCache(): void;
426
486
  }
427
487
 
428
488
  /**
@@ -447,4 +507,4 @@ declare function jumpToSSOLogout({ baseUrl, redirectToUrl, clientId, }: {
447
507
  clientId?: string;
448
508
  }): void;
449
509
 
450
- 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, superLogin };
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
@@ -136,6 +136,62 @@ interface QueryOrgCustomParams {
136
136
  */
137
137
  declare function queryOrgCustom(baseUrl: string, params: QueryOrgCustomParams): Promise<ApiResponse<OrgRecord$1[]>>;
138
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";
194
+
139
195
  interface MenuItem {
140
196
  icon?: string;
141
197
  path: string;
@@ -317,6 +373,7 @@ declare class Permission {
317
373
  [path: string]: MenuItem;
318
374
  };
319
375
  hasSubApp: boolean;
376
+ storage: Storage;
320
377
  private eventEmitter;
321
378
  constructor(options: PermissionOptions);
322
379
  /**
@@ -419,10 +476,13 @@ declare class Permission {
419
476
  * Clear all storage data for this system
420
477
  */
421
478
  clearStorage(): void;
479
+ clearAuthCache(): void;
422
480
  /**
423
481
  * Clear user orgs cache for specific parameters or all
424
482
  */
425
483
  clearUserOrgsCache(params?: UserOrgTreeParams): void;
484
+ clearUserCache(): void;
485
+ clearAppCache(): void;
426
486
  }
427
487
 
428
488
  /**
@@ -447,4 +507,4 @@ declare function jumpToSSOLogout({ baseUrl, redirectToUrl, clientId, }: {
447
507
  clientId?: string;
448
508
  }): void;
449
509
 
450
- 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, superLogin };
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
@@ -536,8 +536,9 @@ var Permission = class {
536
536
  this.baseUrl = options.baseUrl;
537
537
  this.systemId = options.systemId;
538
538
  this.hasSubApp = options.hasSubApp ?? false;
539
- storage.setSystemId(this.systemId);
540
- storage.setVersion("1.0.0");
539
+ this.storage = new Storage();
540
+ this.storage.setSystemId(this.systemId);
541
+ this.storage.setVersion("1.0.0");
541
542
  }
542
543
  /**
543
544
  * Add event listener
@@ -598,7 +599,7 @@ var Permission = class {
598
599
  });
599
600
  }
600
601
  const { token } = obj;
601
- storage.setItem(TOKEN_KEY, token);
602
+ this.storage.setItem(TOKEN_KEY, token);
602
603
  this.emit("tokenChange", token);
603
604
  return token;
604
605
  }
@@ -627,7 +628,7 @@ var Permission = class {
627
628
  }
628
629
  const { token } = obj;
629
630
  url.searchParams.delete("code");
630
- storage.setItem(TOKEN_KEY, token);
631
+ this.storage.setItem(TOKEN_KEY, token);
631
632
  this.emit("tokenChange", token);
632
633
  return token;
633
634
  }
@@ -639,7 +640,7 @@ var Permission = class {
639
640
  clearData && this.clear();
640
641
  }
641
642
  clear() {
642
- storage.clear();
643
+ this.storage.clear();
643
644
  this.emit("tokenChange", "");
644
645
  }
645
646
  async getUserInfo() {
@@ -651,7 +652,7 @@ var Permission = class {
651
652
  * Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
652
653
  */
653
654
  async getResources() {
654
- let resources = storage.getItem(RESOURCE_KEY) || null;
655
+ let resources = this.storage.getItem(RESOURCE_KEY) || null;
655
656
  if (!resources) {
656
657
  const { obj, success, msg, code } = await queryResource(this.baseUrl, {
657
658
  systemId: this.systemId
@@ -663,7 +664,7 @@ var Permission = class {
663
664
  });
664
665
  }
665
666
  resources = obj;
666
- storage.setItem(
667
+ this.storage.setItem(
667
668
  RESOURCE_KEY,
668
669
  resources,
669
670
  60 * 12
@@ -708,7 +709,7 @@ var Permission = class {
708
709
  let orgTreeData = null;
709
710
  if (!force) {
710
711
  const cacheKey = this.generateUserOrgsCacheKey(params);
711
- orgTreeData = storage.getItem(cacheKey) || null;
712
+ orgTreeData = this.storage.getItem(cacheKey) || null;
712
713
  }
713
714
  if (!orgTreeData) {
714
715
  const res = await getUserOrgTree(this.baseUrl, params);
@@ -727,7 +728,7 @@ var Permission = class {
727
728
  };
728
729
  });
729
730
  const cacheKey = this.generateUserOrgsCacheKey(params);
730
- storage.setItem(cacheKey, orgTreeData, cacheTimeout);
731
+ this.storage.setItem(cacheKey, orgTreeData, cacheTimeout);
731
732
  }
732
733
  const data = handlePermissionTree(orgTreeData, "orgId");
733
734
  const { tree } = data;
@@ -748,7 +749,7 @@ var Permission = class {
748
749
  const { force, cacheTimeout = 2 } = config;
749
750
  let orgCompanyList;
750
751
  if (!force) {
751
- orgCompanyList = storage.getItem(USER_TOTAL_COMPANY_KEY);
752
+ orgCompanyList = this.storage.getItem(USER_TOTAL_COMPANY_KEY);
752
753
  }
753
754
  if (!orgCompanyList) {
754
755
  const { obj } = await queryOrgCustom(this.baseUrl, {
@@ -771,18 +772,22 @@ var Permission = class {
771
772
  orgId: item.orgId
772
773
  };
773
774
  });
774
- storage.setItem(USER_TOTAL_COMPANY_KEY, orgCompanyList, cacheTimeout);
775
+ this.storage.setItem(
776
+ USER_TOTAL_COMPANY_KEY,
777
+ orgCompanyList,
778
+ cacheTimeout
779
+ );
775
780
  }
776
781
  return orgCompanyList;
777
782
  }
778
783
  isLogin() {
779
- return !!storage.getItem(TOKEN_KEY);
784
+ return !!this.storage.getItem(TOKEN_KEY);
780
785
  }
781
786
  getToken() {
782
- return storage.getItem(TOKEN_KEY);
787
+ return this.storage.getItem(TOKEN_KEY);
783
788
  }
784
789
  setToken(token) {
785
- storage.setItem(TOKEN_KEY, token);
790
+ this.storage.setItem(TOKEN_KEY, token);
786
791
  this.emit("tokenChange", token);
787
792
  }
788
793
  // --- Getters ---
@@ -807,21 +812,21 @@ var Permission = class {
807
812
  * Get storage information for debugging and monitoring
808
813
  */
809
814
  getStorageInfo() {
810
- const keys = storage.getKeys();
815
+ const keys = this.storage.getKeys();
811
816
  const userOrgsCacheKeys = keys.filter(
812
817
  (key) => key.startsWith(USER_ORG_KEY)
813
818
  );
814
819
  return {
815
- ...storage.getStorageInfo(),
820
+ ...this.storage.getStorageInfo(),
816
821
  permissionKeys: {
817
822
  resourceKey: RESOURCE_KEY,
818
823
  tokenKey: TOKEN_KEY,
819
824
  userInfoKey: USER_INFO_KEY
820
825
  },
821
826
  hasData: {
822
- resources: storage.hasKey(RESOURCE_KEY),
823
- token: storage.hasKey(TOKEN_KEY),
824
- 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)
825
830
  },
826
831
  cacheInfo: {
827
832
  userOrgsCacheCount: userOrgsCacheKeys.length,
@@ -833,13 +838,16 @@ var Permission = class {
833
838
  * Get current storage version
834
839
  */
835
840
  getStorageVersion() {
836
- return storage.getVersion();
841
+ return this.storage.getVersion();
837
842
  }
838
843
  /**
839
844
  * Clear all storage data for this system
840
845
  */
841
846
  clearStorage() {
842
- storage.clear();
847
+ this.storage.clear();
848
+ }
849
+ clearAuthCache() {
850
+ this.storage.removeItem(TOKEN_KEY);
843
851
  }
844
852
  /**
845
853
  * Clear user orgs cache for specific parameters or all
@@ -847,16 +855,32 @@ var Permission = class {
847
855
  clearUserOrgsCache(params) {
848
856
  if (params) {
849
857
  const cacheKey = this.generateUserOrgsCacheKey(params);
850
- storage.removeItem(cacheKey);
858
+ this.storage.removeItem(cacheKey);
851
859
  } else {
852
- const keys = storage.getKeys();
860
+ const keys = this.storage.getKeys();
853
861
  keys.forEach((key) => {
854
862
  if (key.startsWith(USER_ORG_KEY)) {
855
- storage.removeItem(key);
863
+ this.storage.removeItem(key);
856
864
  }
857
865
  });
858
866
  }
859
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
+ }
860
884
  };
861
885
 
862
886
  // src/sso.ts
@@ -899,6 +923,11 @@ export {
899
923
  EnumOrgQueryScope,
900
924
  EventEmitter,
901
925
  Permission as OpmsPermission,
926
+ RESOURCE_KEY,
927
+ TOKEN_KEY,
928
+ USER_INFO_KEY,
929
+ USER_ORG_KEY,
930
+ USER_TOTAL_COMPANY_KEY,
902
931
  getOrgTree,
903
932
  getUserInfo,
904
933
  getUserOrgTree,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mu-cabin/opms-permission",
3
- "version": "0.9.10",
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",