apaas-oapi-client 0.1.16 → 0.1.17
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/UserManual copy.md +568 -0
- package/UserManual.md +253 -36
- package/dist/index.d.ts +186 -0
- package/dist/index.js +416 -0
- package/package.json +1 -1
- package/src/index.ts +522 -0
package/src/index.ts
CHANGED
|
@@ -776,6 +776,528 @@ class Client {
|
|
|
776
776
|
return res.data;
|
|
777
777
|
}
|
|
778
778
|
};
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* 页面模块
|
|
782
|
+
*/
|
|
783
|
+
public page = {
|
|
784
|
+
/**
|
|
785
|
+
* 获取所有页面
|
|
786
|
+
* @param params 请求参数 { limit: number (max 200), offset: number }
|
|
787
|
+
* @returns 接口返回结果
|
|
788
|
+
*/
|
|
789
|
+
list: async (params: { limit: number; offset: number }): Promise<any> => {
|
|
790
|
+
const { limit, offset } = params;
|
|
791
|
+
await this.ensureTokenValid();
|
|
792
|
+
|
|
793
|
+
const url = `/api/builder/v1/namespaces/${this.namespace}/meta/pages`;
|
|
794
|
+
|
|
795
|
+
this.log(LoggerLevel.info, `[page.list] Fetching pages list: offset=${offset}, limit=${limit}`);
|
|
796
|
+
|
|
797
|
+
const res = await this.axiosInstance.post(
|
|
798
|
+
url,
|
|
799
|
+
{ limit, offset },
|
|
800
|
+
{
|
|
801
|
+
headers: {
|
|
802
|
+
Authorization: `${this.accessToken}`,
|
|
803
|
+
'Content-Type': 'application/json'
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
);
|
|
807
|
+
|
|
808
|
+
this.log(LoggerLevel.debug, `[page.list] Pages list fetched: code=${res.data.code}`);
|
|
809
|
+
this.log(LoggerLevel.trace, `[page.list] Response: ${JSON.stringify(res.data)}`);
|
|
810
|
+
|
|
811
|
+
return res.data;
|
|
812
|
+
},
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* 获取所有页面 - 支持自动分页,获取全部数据
|
|
816
|
+
* @description 该方法会自动处理分页,直到获取所有页面数据
|
|
817
|
+
* @param params 请求参数 { limit?: number }
|
|
818
|
+
* @returns { total, items }
|
|
819
|
+
*/
|
|
820
|
+
listWithIterator: async (params?: { limit?: number }): Promise<{ total: number; items: any[] }> => {
|
|
821
|
+
const limit = params?.limit || 100;
|
|
822
|
+
let results: any[] = [];
|
|
823
|
+
let offset = 0;
|
|
824
|
+
let total = 0;
|
|
825
|
+
let page = 0;
|
|
826
|
+
let totalPages = 0;
|
|
827
|
+
|
|
828
|
+
do {
|
|
829
|
+
const pageRes = await functionLimiter(async () => {
|
|
830
|
+
const res = await this.page.list({ limit, offset });
|
|
831
|
+
|
|
832
|
+
page += 1;
|
|
833
|
+
|
|
834
|
+
if (res.data && Array.isArray(res.data.items)) {
|
|
835
|
+
results = results.concat(res.data.items);
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
if (page === 1) {
|
|
839
|
+
total = res.data.total || 0;
|
|
840
|
+
totalPages = Math.ceil(total / limit);
|
|
841
|
+
this.log(LoggerLevel.info, `[page.listWithIterator] Starting paginated query: total=${total}, pages=${totalPages}`);
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
offset += limit;
|
|
845
|
+
|
|
846
|
+
const padLength = totalPages.toString().length;
|
|
847
|
+
const pageStr = page.toString().padStart(padLength, '0');
|
|
848
|
+
const totalPagesStr = totalPages.toString().padStart(padLength, '0');
|
|
849
|
+
|
|
850
|
+
this.log(LoggerLevel.info, `[page.listWithIterator] Page completed: [${pageStr}/${totalPagesStr}]`);
|
|
851
|
+
this.log(LoggerLevel.debug, `[page.listWithIterator] Page ${page} details: items=${res.data.items?.length}, offset=${offset}`);
|
|
852
|
+
this.log(LoggerLevel.trace, `[page.listWithIterator] Page ${page} data: ${JSON.stringify(res.data?.items)}`);
|
|
853
|
+
|
|
854
|
+
return res;
|
|
855
|
+
});
|
|
856
|
+
} while (results.length < total);
|
|
857
|
+
|
|
858
|
+
return { total, items: results };
|
|
859
|
+
},
|
|
860
|
+
|
|
861
|
+
/**
|
|
862
|
+
* 获取页面详情
|
|
863
|
+
* @param params 请求参数 { page_id: string }
|
|
864
|
+
* @returns 接口返回结果
|
|
865
|
+
*/
|
|
866
|
+
detail: async (params: { page_id: string }): Promise<any> => {
|
|
867
|
+
const { page_id } = params;
|
|
868
|
+
await this.ensureTokenValid();
|
|
869
|
+
|
|
870
|
+
const url = `/api/builder/v1/namespaces/${this.namespace}/meta/pages/${page_id}`;
|
|
871
|
+
|
|
872
|
+
this.log(LoggerLevel.info, `[page.detail] Fetching page detail: ${page_id}`);
|
|
873
|
+
|
|
874
|
+
const res = await this.axiosInstance.get(url, {
|
|
875
|
+
headers: {
|
|
876
|
+
Authorization: `${this.accessToken}`
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
|
|
880
|
+
this.log(LoggerLevel.debug, `[page.detail] Page detail fetched: ${page_id}, code=${res.data.code}`);
|
|
881
|
+
this.log(LoggerLevel.trace, `[page.detail] Response: ${JSON.stringify(res.data)}`);
|
|
882
|
+
|
|
883
|
+
return res.data;
|
|
884
|
+
},
|
|
885
|
+
|
|
886
|
+
/**
|
|
887
|
+
* 获取页面访问地址
|
|
888
|
+
* @param params 请求参数 { page_id: string, pageParams?: any, parentPageParams?: any, navId?: string, tabId?: string }
|
|
889
|
+
* @returns 接口返回结果
|
|
890
|
+
*/
|
|
891
|
+
url: async (params: { page_id: string; pageParams?: any; parentPageParams?: any; navId?: string; tabId?: string }): Promise<any> => {
|
|
892
|
+
const { page_id, pageParams, parentPageParams, navId, tabId } = params;
|
|
893
|
+
await this.ensureTokenValid();
|
|
894
|
+
|
|
895
|
+
const url = `/api/builder/v1/namespaces/${this.namespace}/meta/pages/${page_id}/link`;
|
|
896
|
+
|
|
897
|
+
this.log(LoggerLevel.info, `[page.url] Fetching page URL: ${page_id}`);
|
|
898
|
+
|
|
899
|
+
const requestData: any = {};
|
|
900
|
+
if (pageParams) requestData.pageParams = pageParams;
|
|
901
|
+
if (parentPageParams) requestData.parentPageParams = parentPageParams;
|
|
902
|
+
if (navId) requestData.navId = navId;
|
|
903
|
+
if (tabId) requestData.tabId = tabId;
|
|
904
|
+
|
|
905
|
+
const res = await this.axiosInstance.post(url, requestData, {
|
|
906
|
+
headers: {
|
|
907
|
+
Authorization: `${this.accessToken}`,
|
|
908
|
+
'Content-Type': 'application/json'
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
|
|
912
|
+
this.log(LoggerLevel.debug, `[page.url] Page URL fetched: ${page_id}, code=${res.data.code}`);
|
|
913
|
+
this.log(LoggerLevel.trace, `[page.url] Response: ${JSON.stringify(res.data)}`);
|
|
914
|
+
|
|
915
|
+
return res.data;
|
|
916
|
+
}
|
|
917
|
+
};
|
|
918
|
+
|
|
919
|
+
/**
|
|
920
|
+
* 附件模块
|
|
921
|
+
*/
|
|
922
|
+
public attachment = {
|
|
923
|
+
/**
|
|
924
|
+
* 文件操作
|
|
925
|
+
*/
|
|
926
|
+
file: {
|
|
927
|
+
/**
|
|
928
|
+
* 上传文件
|
|
929
|
+
* @param params 请求参数 { file: any }
|
|
930
|
+
* @returns 接口返回结果
|
|
931
|
+
*/
|
|
932
|
+
upload: async (params: { file: any }): Promise<any> => {
|
|
933
|
+
const { file } = params;
|
|
934
|
+
await this.ensureTokenValid();
|
|
935
|
+
|
|
936
|
+
const url = '/api/attachment/v1/files';
|
|
937
|
+
|
|
938
|
+
this.log(LoggerLevel.info, '[attachment.file.upload] Uploading file');
|
|
939
|
+
|
|
940
|
+
const FormData = require('form-data');
|
|
941
|
+
const formData = new FormData();
|
|
942
|
+
formData.append('file', file);
|
|
943
|
+
|
|
944
|
+
const res = await this.axiosInstance.post(url, formData, {
|
|
945
|
+
headers: {
|
|
946
|
+
Authorization: `${this.accessToken}`,
|
|
947
|
+
...formData.getHeaders()
|
|
948
|
+
}
|
|
949
|
+
});
|
|
950
|
+
|
|
951
|
+
this.log(LoggerLevel.debug, `[attachment.file.upload] File uploaded: code=${res.data.code}`);
|
|
952
|
+
this.log(LoggerLevel.trace, `[attachment.file.upload] Response: ${JSON.stringify(res.data)}`);
|
|
953
|
+
|
|
954
|
+
return res.data;
|
|
955
|
+
},
|
|
956
|
+
|
|
957
|
+
/**
|
|
958
|
+
* 下载文件
|
|
959
|
+
* @param params 请求参数 { file_id: string }
|
|
960
|
+
* @returns 文件二进制流
|
|
961
|
+
*/
|
|
962
|
+
download: async (params: { file_id: string }): Promise<any> => {
|
|
963
|
+
const { file_id } = params;
|
|
964
|
+
await this.ensureTokenValid();
|
|
965
|
+
|
|
966
|
+
const url = `/api/attachment/v1/files/${file_id}`;
|
|
967
|
+
|
|
968
|
+
this.log(LoggerLevel.info, `[attachment.file.download] Downloading file: ${file_id}`);
|
|
969
|
+
|
|
970
|
+
const res = await this.axiosInstance.get(url, {
|
|
971
|
+
headers: {
|
|
972
|
+
Authorization: `${this.accessToken}`
|
|
973
|
+
},
|
|
974
|
+
responseType: 'arraybuffer'
|
|
975
|
+
});
|
|
976
|
+
|
|
977
|
+
this.log(LoggerLevel.debug, `[attachment.file.download] File downloaded: ${file_id}`);
|
|
978
|
+
|
|
979
|
+
return res.data;
|
|
980
|
+
},
|
|
981
|
+
|
|
982
|
+
/**
|
|
983
|
+
* 删除文件
|
|
984
|
+
* @param params 请求参数 { file_id: string }
|
|
985
|
+
* @returns 接口返回结果
|
|
986
|
+
*/
|
|
987
|
+
delete: async (params: { file_id: string }): Promise<any> => {
|
|
988
|
+
const { file_id } = params;
|
|
989
|
+
await this.ensureTokenValid();
|
|
990
|
+
|
|
991
|
+
const url = `/v1/files/${file_id}`;
|
|
992
|
+
|
|
993
|
+
this.log(LoggerLevel.info, `[attachment.file.delete] Deleting file: ${file_id}`);
|
|
994
|
+
|
|
995
|
+
const res = await this.axiosInstance.delete(url, {
|
|
996
|
+
headers: {
|
|
997
|
+
Authorization: `${this.accessToken}`
|
|
998
|
+
}
|
|
999
|
+
});
|
|
1000
|
+
|
|
1001
|
+
this.log(LoggerLevel.debug, `[attachment.file.delete] File deleted: ${file_id}, code=${res.data.code}`);
|
|
1002
|
+
this.log(LoggerLevel.trace, `[attachment.file.delete] Response: ${JSON.stringify(res.data)}`);
|
|
1003
|
+
|
|
1004
|
+
return res.data;
|
|
1005
|
+
}
|
|
1006
|
+
},
|
|
1007
|
+
|
|
1008
|
+
/**
|
|
1009
|
+
* 头像图片操作
|
|
1010
|
+
*/
|
|
1011
|
+
avatar: {
|
|
1012
|
+
/**
|
|
1013
|
+
* 上传头像图片
|
|
1014
|
+
* @param params 请求参数 { image: any }
|
|
1015
|
+
* @returns 接口返回结果
|
|
1016
|
+
*/
|
|
1017
|
+
upload: async (params: { image: any }): Promise<any> => {
|
|
1018
|
+
const { image } = params;
|
|
1019
|
+
await this.ensureTokenValid();
|
|
1020
|
+
|
|
1021
|
+
const url = '/api/attachment/v1/images';
|
|
1022
|
+
|
|
1023
|
+
this.log(LoggerLevel.info, '[attachment.avatar.upload] Uploading avatar image');
|
|
1024
|
+
|
|
1025
|
+
const FormData = require('form-data');
|
|
1026
|
+
const formData = new FormData();
|
|
1027
|
+
formData.append('image', image);
|
|
1028
|
+
|
|
1029
|
+
const res = await this.axiosInstance.post(url, formData, {
|
|
1030
|
+
headers: {
|
|
1031
|
+
Authorization: `${this.accessToken}`,
|
|
1032
|
+
...formData.getHeaders()
|
|
1033
|
+
}
|
|
1034
|
+
});
|
|
1035
|
+
|
|
1036
|
+
this.log(LoggerLevel.debug, `[attachment.avatar.upload] Avatar image uploaded: code=${res.data.code}`);
|
|
1037
|
+
this.log(LoggerLevel.trace, `[attachment.avatar.upload] Response: ${JSON.stringify(res.data)}`);
|
|
1038
|
+
|
|
1039
|
+
return res.data;
|
|
1040
|
+
},
|
|
1041
|
+
|
|
1042
|
+
/**
|
|
1043
|
+
* 下载头像图片
|
|
1044
|
+
* @param params 请求参数 { image_id: string }
|
|
1045
|
+
* @returns 图片二进制流
|
|
1046
|
+
*/
|
|
1047
|
+
download: async (params: { image_id: string }): Promise<any> => {
|
|
1048
|
+
const { image_id } = params;
|
|
1049
|
+
await this.ensureTokenValid();
|
|
1050
|
+
|
|
1051
|
+
const url = `/api/attachment/v1/images/${image_id}`;
|
|
1052
|
+
|
|
1053
|
+
this.log(LoggerLevel.info, `[attachment.avatar.download] Downloading avatar image: ${image_id}`);
|
|
1054
|
+
|
|
1055
|
+
const res = await this.axiosInstance.get(url, {
|
|
1056
|
+
headers: {
|
|
1057
|
+
Authorization: `${this.accessToken}`
|
|
1058
|
+
},
|
|
1059
|
+
responseType: 'arraybuffer'
|
|
1060
|
+
});
|
|
1061
|
+
|
|
1062
|
+
this.log(LoggerLevel.debug, `[attachment.avatar.download] Avatar image downloaded: ${image_id}`);
|
|
1063
|
+
|
|
1064
|
+
return res.data;
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
};
|
|
1068
|
+
|
|
1069
|
+
/**
|
|
1070
|
+
* 全局数据模块
|
|
1071
|
+
*/
|
|
1072
|
+
public global = {
|
|
1073
|
+
/**
|
|
1074
|
+
* 全局选项
|
|
1075
|
+
*/
|
|
1076
|
+
options: {
|
|
1077
|
+
/**
|
|
1078
|
+
* 查询全局选项详情
|
|
1079
|
+
* @param params 请求参数 { api_name: string }
|
|
1080
|
+
* @returns 接口返回结果
|
|
1081
|
+
*/
|
|
1082
|
+
detail: async (params: { api_name: string }): Promise<any> => {
|
|
1083
|
+
const { api_name } = params;
|
|
1084
|
+
await this.ensureTokenValid();
|
|
1085
|
+
|
|
1086
|
+
const url = `/api/data/v1/namespaces/${this.namespace}/globalOptions/${api_name}`;
|
|
1087
|
+
|
|
1088
|
+
this.log(LoggerLevel.info, `[global.options.detail] Fetching global option detail: ${api_name}`);
|
|
1089
|
+
|
|
1090
|
+
const res = await this.axiosInstance.get(url, {
|
|
1091
|
+
headers: {
|
|
1092
|
+
Authorization: `${this.accessToken}`
|
|
1093
|
+
}
|
|
1094
|
+
});
|
|
1095
|
+
|
|
1096
|
+
this.log(LoggerLevel.debug, `[global.options.detail] Global option detail fetched: ${api_name}, code=${res.data.code}`);
|
|
1097
|
+
this.log(LoggerLevel.trace, `[global.options.detail] Response: ${JSON.stringify(res.data)}`);
|
|
1098
|
+
|
|
1099
|
+
return res.data;
|
|
1100
|
+
},
|
|
1101
|
+
|
|
1102
|
+
/**
|
|
1103
|
+
* 查询全局选项列表
|
|
1104
|
+
* @param params 请求参数 { limit: number, offset: number, filter?: { quickQuery?: string } }
|
|
1105
|
+
* @returns 接口返回结果
|
|
1106
|
+
*/
|
|
1107
|
+
list: async (params: { limit: number; offset: number; filter?: { quickQuery?: string } }): Promise<any> => {
|
|
1108
|
+
const { limit, offset, filter } = params;
|
|
1109
|
+
await this.ensureTokenValid();
|
|
1110
|
+
|
|
1111
|
+
const url = `/api/data/v1/namespaces/${this.namespace}/globalOptions/list`;
|
|
1112
|
+
|
|
1113
|
+
this.log(LoggerLevel.info, `[global.options.list] Fetching global options list: offset=${offset}, limit=${limit}`);
|
|
1114
|
+
|
|
1115
|
+
const requestData: any = { limit, offset };
|
|
1116
|
+
if (filter) {
|
|
1117
|
+
requestData.filter = filter;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
const res = await this.axiosInstance.post(url, requestData, {
|
|
1121
|
+
headers: {
|
|
1122
|
+
Authorization: `${this.accessToken}`,
|
|
1123
|
+
'Content-Type': 'application/json'
|
|
1124
|
+
}
|
|
1125
|
+
});
|
|
1126
|
+
|
|
1127
|
+
this.log(LoggerLevel.debug, `[global.options.list] Global options list fetched: code=${res.data.code}`);
|
|
1128
|
+
this.log(LoggerLevel.trace, `[global.options.list] Response: ${JSON.stringify(res.data)}`);
|
|
1129
|
+
|
|
1130
|
+
return res.data;
|
|
1131
|
+
},
|
|
1132
|
+
|
|
1133
|
+
/**
|
|
1134
|
+
* 查询所有全局选项 - 支持自动分页,获取全部数据
|
|
1135
|
+
* @description 该方法会自动处理分页,直到获取所有全局选项数据
|
|
1136
|
+
* @param params 请求参数 { limit?: number, filter?: { quickQuery?: string } }
|
|
1137
|
+
* @returns { total, items }
|
|
1138
|
+
*/
|
|
1139
|
+
listWithIterator: async (params?: { limit?: number; filter?: { quickQuery?: string } }): Promise<{ total: number; items: any[] }> => {
|
|
1140
|
+
const limit = params?.limit || 100;
|
|
1141
|
+
const filter = params?.filter;
|
|
1142
|
+
let results: any[] = [];
|
|
1143
|
+
let offset = 0;
|
|
1144
|
+
let total = 0;
|
|
1145
|
+
let page = 0;
|
|
1146
|
+
let totalPages = 0;
|
|
1147
|
+
|
|
1148
|
+
do {
|
|
1149
|
+
const pageRes = await functionLimiter(async () => {
|
|
1150
|
+
const requestParams: any = { limit, offset };
|
|
1151
|
+
if (filter) {
|
|
1152
|
+
requestParams.filter = filter;
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
const res = await this.global.options.list(requestParams);
|
|
1156
|
+
|
|
1157
|
+
page += 1;
|
|
1158
|
+
|
|
1159
|
+
if (res.data && Array.isArray(res.data.items)) {
|
|
1160
|
+
results = results.concat(res.data.items);
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
if (page === 1) {
|
|
1164
|
+
total = res.data.total || 0;
|
|
1165
|
+
totalPages = Math.ceil(total / limit);
|
|
1166
|
+
this.log(LoggerLevel.info, `[global.options.listWithIterator] Starting paginated query: total=${total}, pages=${totalPages}`);
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
offset += limit;
|
|
1170
|
+
|
|
1171
|
+
const padLength = totalPages.toString().length;
|
|
1172
|
+
const pageStr = page.toString().padStart(padLength, '0');
|
|
1173
|
+
const totalPagesStr = totalPages.toString().padStart(padLength, '0');
|
|
1174
|
+
|
|
1175
|
+
this.log(LoggerLevel.info, `[global.options.listWithIterator] Page completed: [${pageStr}/${totalPagesStr}]`);
|
|
1176
|
+
this.log(LoggerLevel.debug, `[global.options.listWithIterator] Page ${page} details: items=${res.data.items?.length}, offset=${offset}`);
|
|
1177
|
+
this.log(LoggerLevel.trace, `[global.options.listWithIterator] Page ${page} data: ${JSON.stringify(res.data?.items)}`);
|
|
1178
|
+
|
|
1179
|
+
return res;
|
|
1180
|
+
});
|
|
1181
|
+
} while (results.length < total);
|
|
1182
|
+
|
|
1183
|
+
return { total, items: results };
|
|
1184
|
+
}
|
|
1185
|
+
},
|
|
1186
|
+
|
|
1187
|
+
/**
|
|
1188
|
+
* 环境变量
|
|
1189
|
+
*/
|
|
1190
|
+
variables: {
|
|
1191
|
+
/**
|
|
1192
|
+
* 查询环境变量详情
|
|
1193
|
+
* @param params 请求参数 { api_name: string }
|
|
1194
|
+
* @returns 接口返回结果
|
|
1195
|
+
*/
|
|
1196
|
+
detail: async (params: { api_name: string }): Promise<any> => {
|
|
1197
|
+
const { api_name } = params;
|
|
1198
|
+
await this.ensureTokenValid();
|
|
1199
|
+
|
|
1200
|
+
const url = `/api/data/v1/namespaces/${this.namespace}/globalVariables/${api_name}`;
|
|
1201
|
+
|
|
1202
|
+
this.log(LoggerLevel.info, `[global.variables.detail] Fetching global variable detail: ${api_name}`);
|
|
1203
|
+
|
|
1204
|
+
const res = await this.axiosInstance.get(url, {
|
|
1205
|
+
headers: {
|
|
1206
|
+
Authorization: `${this.accessToken}`
|
|
1207
|
+
}
|
|
1208
|
+
});
|
|
1209
|
+
|
|
1210
|
+
this.log(LoggerLevel.debug, `[global.variables.detail] Global variable detail fetched: ${api_name}, code=${res.data.code}`);
|
|
1211
|
+
this.log(LoggerLevel.trace, `[global.variables.detail] Response: ${JSON.stringify(res.data)}`);
|
|
1212
|
+
|
|
1213
|
+
return res.data;
|
|
1214
|
+
},
|
|
1215
|
+
|
|
1216
|
+
/**
|
|
1217
|
+
* 查询环境变量列表
|
|
1218
|
+
* @param params 请求参数 { limit: number, offset: number, filter?: { quickQuery?: string } }
|
|
1219
|
+
* @returns 接口返回结果
|
|
1220
|
+
*/
|
|
1221
|
+
list: async (params: { limit: number; offset: number; filter?: { quickQuery?: string } }): Promise<any> => {
|
|
1222
|
+
const { limit, offset, filter } = params;
|
|
1223
|
+
await this.ensureTokenValid();
|
|
1224
|
+
|
|
1225
|
+
const url = `/api/data/v1/namespaces/${this.namespace}/globalVariables/list`;
|
|
1226
|
+
|
|
1227
|
+
this.log(LoggerLevel.info, `[global.variables.list] Fetching global variables list: offset=${offset}, limit=${limit}`);
|
|
1228
|
+
|
|
1229
|
+
const requestData: any = { limit, offset };
|
|
1230
|
+
if (filter) {
|
|
1231
|
+
requestData.filter = filter;
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
const res = await this.axiosInstance.post(url, requestData, {
|
|
1235
|
+
headers: {
|
|
1236
|
+
Authorization: `${this.accessToken}`,
|
|
1237
|
+
'Content-Type': 'application/json'
|
|
1238
|
+
}
|
|
1239
|
+
});
|
|
1240
|
+
|
|
1241
|
+
this.log(LoggerLevel.debug, `[global.variables.list] Global variables list fetched: code=${res.data.code}`);
|
|
1242
|
+
this.log(LoggerLevel.trace, `[global.variables.list] Response: ${JSON.stringify(res.data)}`);
|
|
1243
|
+
|
|
1244
|
+
return res.data;
|
|
1245
|
+
},
|
|
1246
|
+
|
|
1247
|
+
/**
|
|
1248
|
+
* 查询所有环境变量 - 支持自动分页,获取全部数据
|
|
1249
|
+
* @description 该方法会自动处理分页,直到获取所有环境变量数据
|
|
1250
|
+
* @param params 请求参数 { limit?: number, filter?: { quickQuery?: string } }
|
|
1251
|
+
* @returns { total, items }
|
|
1252
|
+
*/
|
|
1253
|
+
listWithIterator: async (params?: { limit?: number; filter?: { quickQuery?: string } }): Promise<{ total: number; items: any[] }> => {
|
|
1254
|
+
const limit = params?.limit || 100;
|
|
1255
|
+
const filter = params?.filter;
|
|
1256
|
+
let results: any[] = [];
|
|
1257
|
+
let offset = 0;
|
|
1258
|
+
let total = 0;
|
|
1259
|
+
let page = 0;
|
|
1260
|
+
let totalPages = 0;
|
|
1261
|
+
|
|
1262
|
+
do {
|
|
1263
|
+
const pageRes = await functionLimiter(async () => {
|
|
1264
|
+
const requestParams: any = { limit, offset };
|
|
1265
|
+
if (filter) {
|
|
1266
|
+
requestParams.filter = filter;
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
const res = await this.global.variables.list(requestParams);
|
|
1270
|
+
|
|
1271
|
+
page += 1;
|
|
1272
|
+
|
|
1273
|
+
if (res.data && Array.isArray(res.data.items)) {
|
|
1274
|
+
results = results.concat(res.data.items);
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
if (page === 1) {
|
|
1278
|
+
total = res.data.total || 0;
|
|
1279
|
+
totalPages = Math.ceil(total / limit);
|
|
1280
|
+
this.log(LoggerLevel.info, `[global.variables.listWithIterator] Starting paginated query: total=${total}, pages=${totalPages}`);
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
offset += limit;
|
|
1284
|
+
|
|
1285
|
+
const padLength = totalPages.toString().length;
|
|
1286
|
+
const pageStr = page.toString().padStart(padLength, '0');
|
|
1287
|
+
const totalPagesStr = totalPages.toString().padStart(padLength, '0');
|
|
1288
|
+
|
|
1289
|
+
this.log(LoggerLevel.info, `[global.variables.listWithIterator] Page completed: [${pageStr}/${totalPagesStr}]`);
|
|
1290
|
+
this.log(LoggerLevel.debug, `[global.variables.listWithIterator] Page ${page} details: items=${res.data.items?.length}, offset=${offset}`);
|
|
1291
|
+
this.log(LoggerLevel.trace, `[global.variables.listWithIterator] Page ${page} data: ${JSON.stringify(res.data?.items)}`);
|
|
1292
|
+
|
|
1293
|
+
return res;
|
|
1294
|
+
});
|
|
1295
|
+
} while (results.length < total);
|
|
1296
|
+
|
|
1297
|
+
return { total, items: results };
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
};
|
|
779
1301
|
}
|
|
780
1302
|
|
|
781
1303
|
export const apaas = {
|