@mu-cabin/opms-permission 0.9.13 → 0.9.14
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 +45 -1
- package/dist/index.d.mts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.mjs +44 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -40,6 +40,7 @@ __export(index_exports, {
|
|
40
40
|
TOKEN_KEY: () => TOKEN_KEY,
|
41
41
|
USER_INFO_KEY: () => USER_INFO_KEY,
|
42
42
|
USER_ORG_KEY: () => USER_ORG_KEY,
|
43
|
+
USER_ORG_NO_AUTH_KEY: () => USER_ORG_NO_AUTH_KEY,
|
43
44
|
USER_TOTAL_COMPANY_KEY: () => USER_TOTAL_COMPANY_KEY,
|
44
45
|
jumpToSSOLogin: () => jumpToSSOLogin,
|
45
46
|
jumpToSSOLogout: () => jumpToSSOLogout
|
@@ -294,6 +295,7 @@ var RESOURCE_KEY = "opms_resources";
|
|
294
295
|
var TOKEN_KEY = "opms_authorization";
|
295
296
|
var USER_TOTAL_COMPANY_KEY = "opms_user_total_company";
|
296
297
|
var USER_ORG_KEY = "opms_user_orgs";
|
298
|
+
var USER_ORG_NO_AUTH_KEY = "opms_user_org_no_auth";
|
297
299
|
|
298
300
|
// src/utils/eventEmitter.ts
|
299
301
|
var EventEmitter = class {
|
@@ -842,6 +844,47 @@ var Permission = class {
|
|
842
844
|
}
|
843
845
|
};
|
844
846
|
}
|
847
|
+
/**
|
848
|
+
* Get organization map by codes with caching
|
849
|
+
* Checks localStorage first, then fetches missing orgs from API
|
850
|
+
*/
|
851
|
+
async getOrgMapByCodes(orgCodes, config = {
|
852
|
+
force: false,
|
853
|
+
cacheTimeout: 60 * 24
|
854
|
+
// 24 hours default
|
855
|
+
}) {
|
856
|
+
const { force, cacheTimeout = 60 * 24 } = config;
|
857
|
+
const result = {};
|
858
|
+
const missingOrgCodes = [];
|
859
|
+
let cachedOrgMap = {};
|
860
|
+
if (!force) {
|
861
|
+
cachedOrgMap = this.storage.getItem(USER_ORG_NO_AUTH_KEY) || {};
|
862
|
+
}
|
863
|
+
for (const orgCode of orgCodes) {
|
864
|
+
if (cachedOrgMap[orgCode]) {
|
865
|
+
result[orgCode] = cachedOrgMap[orgCode];
|
866
|
+
} else {
|
867
|
+
missingOrgCodes.push(orgCode);
|
868
|
+
}
|
869
|
+
}
|
870
|
+
if (missingOrgCodes.length > 0) {
|
871
|
+
try {
|
872
|
+
const { obj } = await this.api.queryOrgCustom({
|
873
|
+
orgCodes: missingOrgCodes
|
874
|
+
});
|
875
|
+
for (const org of obj) {
|
876
|
+
const orgCode = org.orgCode;
|
877
|
+
result[orgCode] = org;
|
878
|
+
cachedOrgMap[orgCode] = org;
|
879
|
+
}
|
880
|
+
this.storage.setItem(USER_ORG_NO_AUTH_KEY, cachedOrgMap, cacheTimeout);
|
881
|
+
} catch (error) {
|
882
|
+
console.error("Error fetching org data:", error);
|
883
|
+
throw error;
|
884
|
+
}
|
885
|
+
}
|
886
|
+
return result;
|
887
|
+
}
|
845
888
|
/**
|
846
889
|
* Get current storage version
|
847
890
|
*/
|
@@ -876,7 +919,7 @@ var Permission = class {
|
|
876
919
|
clearUserCache() {
|
877
920
|
const keys = this.storage.getKeys();
|
878
921
|
keys.forEach((key) => {
|
879
|
-
if (key.startsWith(USER_ORG_KEY) || key.startsWith(USER_TOTAL_COMPANY_KEY) || key.startsWith(USER_INFO_KEY)) {
|
922
|
+
if (key.startsWith(USER_ORG_KEY) || key.startsWith(USER_TOTAL_COMPANY_KEY) || key.startsWith(USER_INFO_KEY) || key.startsWith(USER_ORG_NO_AUTH_KEY)) {
|
880
923
|
this.storage.removeItem(key);
|
881
924
|
}
|
882
925
|
});
|
@@ -937,6 +980,7 @@ function jumpToSSOLogout({
|
|
937
980
|
TOKEN_KEY,
|
938
981
|
USER_INFO_KEY,
|
939
982
|
USER_ORG_KEY,
|
983
|
+
USER_ORG_NO_AUTH_KEY,
|
940
984
|
USER_TOTAL_COMPANY_KEY,
|
941
985
|
jumpToSSOLogin,
|
942
986
|
jumpToSSOLogout
|
package/dist/index.d.mts
CHANGED
@@ -173,11 +173,12 @@ type OrgDirectionType = 'NONE' | 'FROM_SELF_TO_ROOT' | 'FROM_SELF_TO_LEAF' | 'TW
|
|
173
173
|
type OrgType = 'HEAD' | 'BRANCH' | 'DEPARTMENT';
|
174
174
|
interface QueryOrgCustomParams {
|
175
175
|
resultView?: ResultViewType;
|
176
|
-
orgCodeSource
|
176
|
+
orgCodeSource?: CodeSourceType;
|
177
177
|
ids?: number[];
|
178
178
|
direction?: OrgDirectionType;
|
179
179
|
maxDepth?: number;
|
180
180
|
orgTypes?: OrgType[];
|
181
|
+
orgCodes?: string[];
|
181
182
|
}
|
182
183
|
|
183
184
|
declare const USER_INFO_KEY = "opms_user_info";
|
@@ -185,6 +186,7 @@ declare const RESOURCE_KEY = "opms_resources";
|
|
185
186
|
declare const TOKEN_KEY = "opms_authorization";
|
186
187
|
declare const USER_TOTAL_COMPANY_KEY = "opms_user_total_company";
|
187
188
|
declare const USER_ORG_KEY = "opms_user_orgs";
|
189
|
+
declare const USER_ORG_NO_AUTH_KEY = "opms_user_org_no_auth";
|
188
190
|
|
189
191
|
interface MenuItem {
|
190
192
|
icon?: string;
|
@@ -464,6 +466,16 @@ declare class Permission {
|
|
464
466
|
totalKeys: number;
|
465
467
|
systemKeys: number;
|
466
468
|
};
|
469
|
+
/**
|
470
|
+
* Get organization map by codes with caching
|
471
|
+
* Checks localStorage first, then fetches missing orgs from API
|
472
|
+
*/
|
473
|
+
getOrgMapByCodes(orgCodes: string[], config?: {
|
474
|
+
force?: boolean;
|
475
|
+
cacheTimeout?: number;
|
476
|
+
}): Promise<{
|
477
|
+
[orgCode: string]: OrgRecord$1;
|
478
|
+
}>;
|
467
479
|
/**
|
468
480
|
* Get current storage version
|
469
481
|
*/
|
@@ -503,4 +515,4 @@ declare function jumpToSSOLogout({ baseUrl, redirectToUrl, clientId, }: {
|
|
503
515
|
clientId?: string;
|
504
516
|
}): void;
|
505
517
|
|
506
|
-
export { ApiClient, 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, jumpToSSOLogin, jumpToSSOLogout };
|
518
|
+
export { ApiClient, 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_ORG_NO_AUTH_KEY, USER_TOTAL_COMPANY_KEY, type UserInfo, type UserOrgTreeParams, type UserOrganization, type UserRole, jumpToSSOLogin, jumpToSSOLogout };
|
package/dist/index.d.ts
CHANGED
@@ -173,11 +173,12 @@ type OrgDirectionType = 'NONE' | 'FROM_SELF_TO_ROOT' | 'FROM_SELF_TO_LEAF' | 'TW
|
|
173
173
|
type OrgType = 'HEAD' | 'BRANCH' | 'DEPARTMENT';
|
174
174
|
interface QueryOrgCustomParams {
|
175
175
|
resultView?: ResultViewType;
|
176
|
-
orgCodeSource
|
176
|
+
orgCodeSource?: CodeSourceType;
|
177
177
|
ids?: number[];
|
178
178
|
direction?: OrgDirectionType;
|
179
179
|
maxDepth?: number;
|
180
180
|
orgTypes?: OrgType[];
|
181
|
+
orgCodes?: string[];
|
181
182
|
}
|
182
183
|
|
183
184
|
declare const USER_INFO_KEY = "opms_user_info";
|
@@ -185,6 +186,7 @@ declare const RESOURCE_KEY = "opms_resources";
|
|
185
186
|
declare const TOKEN_KEY = "opms_authorization";
|
186
187
|
declare const USER_TOTAL_COMPANY_KEY = "opms_user_total_company";
|
187
188
|
declare const USER_ORG_KEY = "opms_user_orgs";
|
189
|
+
declare const USER_ORG_NO_AUTH_KEY = "opms_user_org_no_auth";
|
188
190
|
|
189
191
|
interface MenuItem {
|
190
192
|
icon?: string;
|
@@ -464,6 +466,16 @@ declare class Permission {
|
|
464
466
|
totalKeys: number;
|
465
467
|
systemKeys: number;
|
466
468
|
};
|
469
|
+
/**
|
470
|
+
* Get organization map by codes with caching
|
471
|
+
* Checks localStorage first, then fetches missing orgs from API
|
472
|
+
*/
|
473
|
+
getOrgMapByCodes(orgCodes: string[], config?: {
|
474
|
+
force?: boolean;
|
475
|
+
cacheTimeout?: number;
|
476
|
+
}): Promise<{
|
477
|
+
[orgCode: string]: OrgRecord$1;
|
478
|
+
}>;
|
467
479
|
/**
|
468
480
|
* Get current storage version
|
469
481
|
*/
|
@@ -503,4 +515,4 @@ declare function jumpToSSOLogout({ baseUrl, redirectToUrl, clientId, }: {
|
|
503
515
|
clientId?: string;
|
504
516
|
}): void;
|
505
517
|
|
506
|
-
export { ApiClient, 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, jumpToSSOLogin, jumpToSSOLogout };
|
518
|
+
export { ApiClient, 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_ORG_NO_AUTH_KEY, USER_TOTAL_COMPANY_KEY, type UserInfo, type UserOrgTreeParams, type UserOrganization, type UserRole, jumpToSSOLogin, jumpToSSOLogout };
|
package/dist/index.mjs
CHANGED
@@ -246,6 +246,7 @@ var RESOURCE_KEY = "opms_resources";
|
|
246
246
|
var TOKEN_KEY = "opms_authorization";
|
247
247
|
var USER_TOTAL_COMPANY_KEY = "opms_user_total_company";
|
248
248
|
var USER_ORG_KEY = "opms_user_orgs";
|
249
|
+
var USER_ORG_NO_AUTH_KEY = "opms_user_org_no_auth";
|
249
250
|
|
250
251
|
// src/utils/eventEmitter.ts
|
251
252
|
var EventEmitter = class {
|
@@ -794,6 +795,47 @@ var Permission = class {
|
|
794
795
|
}
|
795
796
|
};
|
796
797
|
}
|
798
|
+
/**
|
799
|
+
* Get organization map by codes with caching
|
800
|
+
* Checks localStorage first, then fetches missing orgs from API
|
801
|
+
*/
|
802
|
+
async getOrgMapByCodes(orgCodes, config = {
|
803
|
+
force: false,
|
804
|
+
cacheTimeout: 60 * 24
|
805
|
+
// 24 hours default
|
806
|
+
}) {
|
807
|
+
const { force, cacheTimeout = 60 * 24 } = config;
|
808
|
+
const result = {};
|
809
|
+
const missingOrgCodes = [];
|
810
|
+
let cachedOrgMap = {};
|
811
|
+
if (!force) {
|
812
|
+
cachedOrgMap = this.storage.getItem(USER_ORG_NO_AUTH_KEY) || {};
|
813
|
+
}
|
814
|
+
for (const orgCode of orgCodes) {
|
815
|
+
if (cachedOrgMap[orgCode]) {
|
816
|
+
result[orgCode] = cachedOrgMap[orgCode];
|
817
|
+
} else {
|
818
|
+
missingOrgCodes.push(orgCode);
|
819
|
+
}
|
820
|
+
}
|
821
|
+
if (missingOrgCodes.length > 0) {
|
822
|
+
try {
|
823
|
+
const { obj } = await this.api.queryOrgCustom({
|
824
|
+
orgCodes: missingOrgCodes
|
825
|
+
});
|
826
|
+
for (const org of obj) {
|
827
|
+
const orgCode = org.orgCode;
|
828
|
+
result[orgCode] = org;
|
829
|
+
cachedOrgMap[orgCode] = org;
|
830
|
+
}
|
831
|
+
this.storage.setItem(USER_ORG_NO_AUTH_KEY, cachedOrgMap, cacheTimeout);
|
832
|
+
} catch (error) {
|
833
|
+
console.error("Error fetching org data:", error);
|
834
|
+
throw error;
|
835
|
+
}
|
836
|
+
}
|
837
|
+
return result;
|
838
|
+
}
|
797
839
|
/**
|
798
840
|
* Get current storage version
|
799
841
|
*/
|
@@ -828,7 +870,7 @@ var Permission = class {
|
|
828
870
|
clearUserCache() {
|
829
871
|
const keys = this.storage.getKeys();
|
830
872
|
keys.forEach((key) => {
|
831
|
-
if (key.startsWith(USER_ORG_KEY) || key.startsWith(USER_TOTAL_COMPANY_KEY) || key.startsWith(USER_INFO_KEY)) {
|
873
|
+
if (key.startsWith(USER_ORG_KEY) || key.startsWith(USER_TOTAL_COMPANY_KEY) || key.startsWith(USER_INFO_KEY) || key.startsWith(USER_ORG_NO_AUTH_KEY)) {
|
832
874
|
this.storage.removeItem(key);
|
833
875
|
}
|
834
876
|
});
|
@@ -888,6 +930,7 @@ export {
|
|
888
930
|
TOKEN_KEY,
|
889
931
|
USER_INFO_KEY,
|
890
932
|
USER_ORG_KEY,
|
933
|
+
USER_ORG_NO_AUTH_KEY,
|
891
934
|
USER_TOTAL_COMPANY_KEY,
|
892
935
|
jumpToSSOLogin,
|
893
936
|
jumpToSSOLogout
|