test-api-client 0.0.1

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.js ADDED
@@ -0,0 +1,1092 @@
1
+ 'use strict';
2
+
3
+ var axios = require('axios');
4
+ var CryptoJS = require('crypto-js');
5
+
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
+
8
+ var axios__default = /*#__PURE__*/_interopDefault(axios);
9
+ var CryptoJS__default = /*#__PURE__*/_interopDefault(CryptoJS);
10
+
11
+ // src/types.ts
12
+ var ErrorLevel = /* @__PURE__ */ ((ErrorLevel3) => {
13
+ ErrorLevel3[ErrorLevel3["SUCCESS"] = 0] = "SUCCESS";
14
+ ErrorLevel3[ErrorLevel3["SYSTEM"] = 1] = "SYSTEM";
15
+ ErrorLevel3[ErrorLevel3["CLIENT_PARAM"] = 2] = "CLIENT_PARAM";
16
+ ErrorLevel3[ErrorLevel3["AUTH"] = 3] = "AUTH";
17
+ ErrorLevel3[ErrorLevel3["BUSINESS"] = 4] = "BUSINESS";
18
+ ErrorLevel3[ErrorLevel3["RESOURCE"] = 5] = "RESOURCE";
19
+ ErrorLevel3[ErrorLevel3["NETWORK"] = 6] = "NETWORK";
20
+ ErrorLevel3[ErrorLevel3["FILE_MEDIA"] = 7] = "FILE_MEDIA";
21
+ ErrorLevel3[ErrorLevel3["DEVICE_HARDWARE"] = 8] = "DEVICE_HARDWARE";
22
+ ErrorLevel3[ErrorLevel3["THIRD_PARTY"] = 9] = "THIRD_PARTY";
23
+ return ErrorLevel3;
24
+ })(ErrorLevel || {});
25
+ var FunctionModule = /* @__PURE__ */ ((FunctionModule4) => {
26
+ FunctionModule4["GENERAL"] = "00";
27
+ FunctionModule4["USER_AUTH"] = "01";
28
+ FunctionModule4["SELF_CHECK"] = "02";
29
+ FunctionModule4["AIRLINE"] = "03";
30
+ FunctionModule4["FENCE"] = "04";
31
+ FunctionModule4["REAL_TIME_DATA"] = "05";
32
+ FunctionModule4["VIDEO_STREAM"] = "06";
33
+ FunctionModule4["AUDIO_STREAM"] = "07";
34
+ FunctionModule4["MEDIA_SERVICE"] = "08";
35
+ FunctionModule4["AV_CONTROL"] = "09";
36
+ FunctionModule4["LOG_FILE"] = "10";
37
+ FunctionModule4["REMOTE_CONTROL"] = "11";
38
+ FunctionModule4["FLIGHT_STATUS"] = "12";
39
+ return FunctionModule4;
40
+ })(FunctionModule || {});
41
+ var ApiError = class extends Error {
42
+ /**
43
+ * 创建ApiError实例
44
+ * @param params - 错误参数
45
+ * @param params.message - 错误消息
46
+ * @param params.type - 错误类型
47
+ * @param params.httpStatus - HTTP状态码(可选)
48
+ * @param params.code - 业务错误码(可选)
49
+ * @param params.subCode - 业务子错误码(可选)
50
+ * @param params.subMsg - 业务子错误消息(可选)
51
+ * @param params.errorLevel - 错误级别(可选)
52
+ * @param params.module - 功能模块(可选)
53
+ * @param params.raw - 原始错误数据(可选)
54
+ */
55
+ constructor(params) {
56
+ super(params.message);
57
+ this.name = "ApiError";
58
+ this.type = params.type;
59
+ this.httpStatus = params.httpStatus;
60
+ this.code = params.code;
61
+ this.subCode = params.subCode;
62
+ this.subMsg = params.subMsg;
63
+ this.errorLevel = params.errorLevel;
64
+ this.module = params.module;
65
+ this.raw = params.raw;
66
+ }
67
+ };
68
+
69
+ // src/client/logger.ts
70
+ var LOG_LEVEL_WEIGHT = {
71
+ "ALL": 0,
72
+ "TRACE": 1,
73
+ "DEBUG": 2,
74
+ "INFO": 3,
75
+ "WARN": 4,
76
+ "ERROR": 5,
77
+ "FATAL": 6,
78
+ "OFF": 7
79
+ };
80
+ function shouldHandle(config, level) {
81
+ var _a;
82
+ if (!(config == null ? void 0 : config.debug)) return false;
83
+ const cfgLevel = (_a = config.logLevel) != null ? _a : "INFO";
84
+ if (cfgLevel === "OFF") return false;
85
+ if (cfgLevel === "ALL") return true;
86
+ return LOG_LEVEL_WEIGHT[level] >= LOG_LEVEL_WEIGHT[cfgLevel];
87
+ }
88
+ function formatSensitiveData(data) {
89
+ if (typeof data !== "object" || data === null) {
90
+ return data;
91
+ }
92
+ if (Array.isArray(data)) {
93
+ return data.map((item) => formatSensitiveData(item));
94
+ }
95
+ const result = {};
96
+ for (const [key, value] of Object.entries(data)) {
97
+ const lowerKey = key.toLowerCase();
98
+ if (lowerKey.includes("password") || lowerKey.includes("passwd") || lowerKey.includes("token") || lowerKey.includes("auth") || lowerKey.includes("secret")) {
99
+ result[key] = typeof value === "string" ? "******" : "******";
100
+ } else {
101
+ result[key] = formatSensitiveData(value);
102
+ }
103
+ }
104
+ return result;
105
+ }
106
+ function generateStructuredLog(config, level, event, message, httpLog, meta) {
107
+ const structuredLog = {
108
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
109
+ level,
110
+ module: "api-client",
111
+ event,
112
+ message
113
+ };
114
+ if (httpLog) {
115
+ if (httpLog.url && httpLog.method) {
116
+ structuredLog.request = {
117
+ url: httpLog.url,
118
+ method: httpLog.method,
119
+ headers: httpLog.headers,
120
+ body: formatSensitiveData(httpLog.request)
121
+ };
122
+ }
123
+ if (httpLog.response && typeof httpLog.response === "object") {
124
+ const responseObj = httpLog.response;
125
+ structuredLog.response = {
126
+ status: responseObj.status || responseObj.code || 0,
127
+ body: responseObj
128
+ };
129
+ }
130
+ if (httpLog.durationMs) {
131
+ structuredLog.duration_ms = httpLog.durationMs;
132
+ }
133
+ }
134
+ return structuredLog;
135
+ }
136
+ function formatJsonLog(log) {
137
+ return JSON.stringify(log, null, 2);
138
+ }
139
+ function formatTextLog(log) {
140
+ const { timestamp, level, module, event, message, duration_ms } = log;
141
+ let text = `${timestamp} [${level}] [${module}] [${event}]`;
142
+ if (log.trace_id) {
143
+ text += ` [trace_id: ${log.trace_id}]`;
144
+ }
145
+ if (duration_ms) {
146
+ text += ` [duration: ${duration_ms}ms]`;
147
+ }
148
+ text += ` - ${message}`;
149
+ if (log.request) {
150
+ text += `
151
+ Request: ${log.request.method} ${log.request.url}`;
152
+ if (log.request.headers) {
153
+ text += `
154
+ Headers: ${JSON.stringify(log.request.headers)}`;
155
+ }
156
+ if (log.request.body) {
157
+ text += `
158
+ Body: ${JSON.stringify(log.request.body)}`;
159
+ }
160
+ }
161
+ if (log.response) {
162
+ text += `
163
+ Response: ${log.response.status}`;
164
+ if (log.response.body) {
165
+ text += `
166
+ Body: ${JSON.stringify(log.response.body)}`;
167
+ }
168
+ }
169
+ return text;
170
+ }
171
+ function formatLog(config, log) {
172
+ var _a;
173
+ const formatType = (_a = config == null ? void 0 : config.logFormat) != null ? _a : 1;
174
+ return formatType === 1 ? formatJsonLog(log) : formatTextLog(log);
175
+ }
176
+ function printLog(config, log) {
177
+ var _a;
178
+ const logOutput = (_a = config == null ? void 0 : config.logOutput) != null ? _a : [1];
179
+ if (!logOutput.includes(1)) return;
180
+ const formattedLog = formatLog(config, log);
181
+ switch (log.level) {
182
+ case "DEBUG":
183
+ case "TRACE":
184
+ console.debug(formattedLog);
185
+ break;
186
+ case "INFO":
187
+ console.info(formattedLog);
188
+ break;
189
+ case "WARN":
190
+ console.warn(formattedLog);
191
+ break;
192
+ case "ERROR":
193
+ case "FATAL":
194
+ console.error(formattedLog);
195
+ break;
196
+ default:
197
+ console.log(formattedLog);
198
+ }
199
+ }
200
+ function sendLogToClient(config, log) {
201
+ var _a, _b;
202
+ const logOutput = (_a = config == null ? void 0 : config.logOutput) != null ? _a : [1];
203
+ if (!logOutput.includes(2)) return;
204
+ (_b = config == null ? void 0 : config.logger) == null ? void 0 : _b.call(config, log, log.level, log);
205
+ }
206
+ function handleHttpLog(config, level, httpLog) {
207
+ if (!shouldHandle(config, level)) return;
208
+ const message = `${httpLog.name || "HTTP Request"} ${httpLog.method || ""} ${httpLog.url || ""}`;
209
+ const structuredLog = generateStructuredLog(config, level, "request", message, httpLog);
210
+ printLog(config, structuredLog);
211
+ sendLogToClient(config, structuredLog);
212
+ }
213
+ function getUri(urlOrPath) {
214
+ try {
215
+ const url = new URL(urlOrPath, "https://example.com");
216
+ return url.pathname;
217
+ } catch {
218
+ return urlOrPath.split("?")[0];
219
+ }
220
+ }
221
+ function serializeValue(value) {
222
+ if (typeof value === "object" && value !== null) {
223
+ if (value instanceof Date) return value.toISOString();
224
+ return JSON.stringify(value);
225
+ }
226
+ return String(value);
227
+ }
228
+ function generateSignature(params, secret, salt) {
229
+ const entries = [];
230
+ for (const [key, value] of Object.entries(params)) {
231
+ if (value != null && value !== "") {
232
+ entries.push([key, value]);
233
+ }
234
+ }
235
+ entries.sort(
236
+ (a, b) => a[0].toLowerCase().localeCompare(b[0].toLowerCase())
237
+ );
238
+ let strToSign = "";
239
+ for (const [key, value] of entries) {
240
+ strToSign += `${key.toLowerCase()}=${serializeValue(value)}&`;
241
+ }
242
+ strToSign += `secret=${secret}`;
243
+ const hmac = CryptoJS__default.default.HmacMD5(strToSign, salt);
244
+ return hmac.toString(CryptoJS__default.default.enc.Hex);
245
+ }
246
+ function randomNonce(length = 32) {
247
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
248
+ let result = "";
249
+ for (let i = 0; i < length; i++) {
250
+ result += chars.charAt(Math.floor(Math.random() * chars.length));
251
+ }
252
+ return result;
253
+ }
254
+ function generateSign(input) {
255
+ const params = {};
256
+ params.uri = getUri(input.uri);
257
+ params["X-Timestamp"] = String(input.timestamp);
258
+ params["X-Nonce"] = input.nonce;
259
+ if (input.query) {
260
+ Object.assign(params, input.query);
261
+ }
262
+ if (input.body !== void 0 && input.body !== null && input.body !== "") {
263
+ if (typeof input.body === "object" && !Array.isArray(input.body)) {
264
+ Object.assign(params, input.body);
265
+ } else if (typeof input.body === "string") {
266
+ const s = input.body.trim();
267
+ if (s.startsWith("{") && s.endsWith("}")) {
268
+ try {
269
+ const obj = JSON.parse(s);
270
+ if (obj && typeof obj === "object" && !Array.isArray(obj)) {
271
+ Object.assign(params, obj);
272
+ } else {
273
+ params.body = input.body;
274
+ }
275
+ } catch {
276
+ params.body = input.body;
277
+ }
278
+ } else {
279
+ params.body = input.body;
280
+ }
281
+ } else {
282
+ params.body = input.body;
283
+ }
284
+ }
285
+ const sign = generateSignature(params, input.secret, input.salt);
286
+ const entries = [];
287
+ for (const [key, value] of Object.entries(params)) {
288
+ if (value != null && value !== "") {
289
+ entries.push([key, value]);
290
+ }
291
+ }
292
+ entries.sort((a, b) => a[0].toLowerCase().localeCompare(b[0].toLowerCase()));
293
+ let signString = "";
294
+ for (const [key, value] of entries) {
295
+ signString += `${key.toLowerCase()}=${serializeValue(value)}&`;
296
+ }
297
+ signString += `secret=${input.secret}`;
298
+ return { sign, signString };
299
+ }
300
+
301
+ // src/client/state.ts
302
+ var state = {};
303
+
304
+ // src/client/token.ts
305
+ function setApiToken(token) {
306
+ state.token = token;
307
+ }
308
+ function getApiToken() {
309
+ return state.token;
310
+ }
311
+
312
+ // src/client/error-codes.ts
313
+ var HTTP_STATUS_MAP = {
314
+ 200: "\u8BF7\u6C42\u6210\u529F",
315
+ 400: "\u53C2\u6570\u5217\u8868\u9519\u8BEF",
316
+ 401: "\u672A\u6388\u6743",
317
+ 403: "\u8BBF\u95EE\u53D7\u9650\uFF0C\u6388\u6743\u8FC7\u671F",
318
+ 404: "\u8D44\u6E90\u6216\u670D\u52A1\u672A\u627E\u5230",
319
+ 405: "\u4E0D\u5141\u8BB8\u7684HTTP\u65B9\u6CD5",
320
+ 408: "\u8BF7\u6C42\u8D85\u65F6",
321
+ 500: "\u7CFB\u7EDF\u5185\u90E8\u9519\u8BEF",
322
+ 501: "\u672A\u5B9E\u73B0",
323
+ 503: "\u670D\u52A1\u4E0D\u53EF\u7528"
324
+ };
325
+ var BUSINESS_ERROR_MAP = {
326
+ // 系统级错误 (1YYZZ)
327
+ "10000": "\u7CFB\u7EDF\u5185\u90E8\u9519\u8BEF",
328
+ "10001": "\u6570\u636E\u5E93\u64CD\u4F5C\u5931\u8D25",
329
+ "10002": "\u7F13\u5B58\u670D\u52A1\u5F02\u5E38",
330
+ "10003": "\u914D\u7F6E\u6587\u4EF6\u9519\u8BEF",
331
+ "10004": "\u670D\u52A1\u521D\u59CB\u5316\u5931\u8D25",
332
+ "10005": "\u7CFB\u7EDF\u8D44\u6E90\u4E0D\u8DB3",
333
+ "10006": "\u7EBF\u7A0B\u6C60\u5F02\u5E38",
334
+ "10007": "\u6D88\u606F\u961F\u5217\u5F02\u5E38",
335
+ "10008": "\u670D\u52A1\u95F4\u901A\u4FE1\u5931\u8D25",
336
+ "10009": "\u6570\u636E\u5E8F\u5217\u5316\u5931\u8D25",
337
+ "10010": "\u6570\u636E\u53CD\u5E8F\u5217\u5316\u5931\u8D25",
338
+ // 客户端参数错误 (2YYZZ)
339
+ "20000": "\u901A\u7528\u53C2\u6570\u9519\u8BEF",
340
+ "20001": "\u5FC5\u586B\u53C2\u6570\u7F3A\u5931",
341
+ "20002": "\u53C2\u6570\u683C\u5F0F\u9519\u8BEF",
342
+ "20003": "\u53C2\u6570\u7C7B\u578B\u4E0D\u5339\u914D",
343
+ "20004": "\u53C2\u6570\u503C\u8D85\u51FA\u8303\u56F4",
344
+ "20005": "\u53C2\u6570\u6821\u9A8C\u5931\u8D25",
345
+ "20006": "JSON\u89E3\u6790\u5931\u8D25",
346
+ "20007": "XML\u89E3\u6790\u5931\u8D25",
347
+ "20008": "\u53C2\u6570\u957F\u5EA6\u8D85\u9650",
348
+ "20009": "\u65E0\u6548\u7684\u679A\u4E3E\u503C",
349
+ "20010": "\u53C2\u6570\u7EC4\u5408\u65E0\u6548",
350
+ "20011": "\u8BF7\u6C42\u4F53\u8FC7\u5927",
351
+ "20012": "\u65F6\u95F4\u53C2\u6570\u683C\u5F0F\u9519\u8BEF",
352
+ // 认证授权错误 (3YYZZ)
353
+ "30001": "\u7528\u6237\u540D\u4E0D\u5B58\u5728",
354
+ "30002": "\u5BC6\u7801\u9519\u8BEF",
355
+ "30003": "\u7528\u6237\u8D26\u53F7\u5DF2\u7981\u7528",
356
+ "30004": "\u7528\u6237\u8D26\u53F7\u5DF2\u9501\u5B9A",
357
+ "30005": "\u767B\u5F55\u5C1D\u8BD5\u6B21\u6570\u8D85\u9650",
358
+ "30006": "\u4F1A\u8BDD\u5DF2\u8FC7\u671F",
359
+ "30007": "\u4EE4\u724C\u65E0\u6548",
360
+ "30008": "\u4EE4\u724C\u5DF2\u8FC7\u671F",
361
+ "30009": "\u5237\u65B0\u4EE4\u724C\u65E0\u6548",
362
+ "30010": "\u6743\u9650\u4E0D\u8DB3",
363
+ "30011": "\u89D2\u8272\u4E0D\u5B58\u5728",
364
+ "30012": "\u8BBF\u95EEIP\u53D7\u9650",
365
+ "30013": "\u8BBF\u95EE\u65F6\u95F4\u53D7\u9650",
366
+ "30014": "\u53CC\u56E0\u7D20\u8BA4\u8BC1\u5931\u8D25",
367
+ "30015": "\u7528\u6237\u540D\u4E0D\u80FD\u4E3A\u7A7A",
368
+ "30016": "\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A",
369
+ "30017": "\u7528\u6237\u540D\u5DF2\u7ECF\u5B58\u5728",
370
+ "30018": "\u7528\u6237\u540D\u9000\u51FA\u5931\u8D25",
371
+ // 业务逻辑错误 (4YYZZ)
372
+ // 403ZZ: 航线管理
373
+ "40300": "\u822A\u7EBF\u64CD\u4F5C\u5931\u8D25",
374
+ "40301": "\u822A\u7EBFID\u5DF2\u5B58\u5728",
375
+ "40302": "\u822A\u7EBF\u4E0D\u5B58\u5728",
376
+ "40303": "\u822A\u7EBF\u540D\u79F0\u91CD\u590D",
377
+ "40304": "\u822A\u7EBF\u6570\u636E\u65E0\u6548",
378
+ "40305": "\u822A\u70B9\u5217\u8868\u4E3A\u7A7A",
379
+ "40306": "\u822A\u70B9\u6570\u91CF\u8D85\u9650",
380
+ "40307": "\u822A\u70B9\u5E8F\u53F7\u4E0D\u8FDE\u7EED",
381
+ "40308": "\u822A\u70B9\u7C7B\u578B\u4E0D\u5408\u6CD5\uFF08\u5141\u8BB8\u503C\uFF1A0/1/2\uFF09",
382
+ "40309": "\u7ECF\u7EAC\u5EA6\u683C\u5F0F\u9519\u8BEF",
383
+ "40310": "\u7ECF\u7EAC\u5EA6\u8D85\u51FA\u8303\u56F4",
384
+ "40311": "\u9AD8\u5EA6\u503C\u975E\u6CD5",
385
+ "40312": "\u901F\u5EA6\u503C\u975E\u6CD5",
386
+ "40313": "\u5207\u6362\u6A21\u5F0F\u4E0D\u5408\u6CD5",
387
+ "40314": "\u822A\u7EBF\u603B\u8DDD\u79BB\u8D85\u9650",
388
+ "40315": "\u822A\u7EBF\u4FDD\u5B58\u5931\u8D25",
389
+ "40316": "\u822A\u7EBF\u5220\u9664\u5931\u8D25",
390
+ "40317": "\u822A\u7EBF\u590D\u5236\u5931\u8D25",
391
+ "40318": "\u822A\u7EBF\u5BFC\u5165\u5931\u8D25",
392
+ "40319": "\u822A\u7EBF\u5BFC\u51FA\u5931\u8D25",
393
+ "40320": "\u822A\u7EBF\u6267\u884C\u51B2\u7A81\uFF08\u6B63\u5728\u6267\u884C\uFF09",
394
+ // 404ZZ: 电子围栏
395
+ "40400": "\u56F4\u680F\u64CD\u4F5C\u5931\u8D25",
396
+ "40401": "\u56F4\u680F\u540D\u79F0\u91CD\u590D",
397
+ "40402": "\u56F4\u680F\u4E0D\u5B58\u5728",
398
+ "40403": "\u51E0\u4F55\u7C7B\u578B\u4E0D\u5408\u6CD5\uFF080=\u591A\u8FB9\u5F62\uFF0C1=\u5706\u5F62\uFF0C2=\u6247\u533A\uFF09",
399
+ "40404": "\u7A7A\u57DF\u5C5E\u6027\u4E0D\u5408\u6CD5\uFF080=\u7981\u98DE\uFF0C1=\u8B66\u544A\uFF0C2=\u9650\u9AD8\uFF0C3=\u7BA1\u5236\uFF09",
400
+ "40405": "\u591A\u8FB9\u5F62\u9876\u70B9\u6570\u4E0D\u8DB3\uFF08\u81F3\u5C113\u4E2A\uFF09",
401
+ "40406": "\u9876\u70B9\u5750\u6807\u683C\u5F0F\u9519\u8BEF",
402
+ "40407": "\u9876\u70B9\u5E8F\u53F7\u4E0D\u8FDE\u7EED",
403
+ "40408": "\u591A\u8FB9\u5F62\u81EA\u76F8\u4EA4",
404
+ "40409": "\u5706\u5F62\u534A\u5F84\u975E\u6CD5",
405
+ "40410": "\u6247\u533A\u534A\u5F84\u975E\u6CD5",
406
+ "40411": "\u8D77\u59CB\u65B9\u5411\u4E0D\u5408\u6CD5\uFF080-360\uFF09",
407
+ "40412": "\u7ED3\u675F\u65B9\u5411\u4E0D\u5408\u6CD5\uFF080-360\uFF09",
408
+ "40413": "\u65F6\u95F4\u8303\u56F4\u91CD\u53E0",
409
+ "40414": "\u76F8\u5BF9\u9AD8\u5EA6\u975E\u6CD5",
410
+ "40415": "\u56F4\u680F\u7A7A\u95F4\u51B2\u7A81\uFF08\u4E0E\u73B0\u6709\u56F4\u680F\u91CD\u53E0\uFF09",
411
+ // 405ZZ: 实时数据
412
+ "40500": "\u5B9E\u65F6\u6570\u636E\u9519\u8BEF",
413
+ "40501": "\u6570\u636E\u6D41\u4E0D\u5B58\u5728",
414
+ "40502": "\u6570\u636E\u8BA2\u9605\u5931\u8D25",
415
+ "40503": "\u6570\u636E\u53D1\u5E03\u5931\u8D25",
416
+ "40504": "\u6570\u636E\u683C\u5F0F\u9519\u8BEF",
417
+ "40505": "\u6570\u636E\u89E3\u6790\u5931\u8D25",
418
+ "40506": "\u65F6\u95F4\u6233\u65E0\u6548",
419
+ "40507": "\u6570\u636E\u8FC7\u671F",
420
+ "40508": "\u6570\u636E\u9891\u7387\u8D85\u9650",
421
+ "40509": "\u6570\u636E\u91CF\u8FC7\u5927",
422
+ "40510": "\u6570\u636E\u6D41\u4E2D\u65AD",
423
+ "40511": "\u6570\u636E\u7C7B\u578B\u4E0D\u652F\u6301",
424
+ "40512": "\u6570\u636E\u9A8C\u8BC1\u5931\u8D25",
425
+ // 文件/媒体错误 (7YYZZ)
426
+ // 706ZZ: 视频流
427
+ "70600": "\u89C6\u9891\u6D41\u9519\u8BEF",
428
+ "70601": "\u89C6\u9891\u6D41\u4E0D\u5B58\u5728\u6216\u672A\u5F00\u542F",
429
+ "70602": "\u89C6\u9891\u6D41\u6743\u9650\u4E0D\u8DB3",
430
+ "70603": "\u89C6\u9891\u7F16\u7801\u683C\u5F0F\u4E0D\u652F\u6301\uFF08\u652F\u6301\uFF1AH.264, H.265, VP9\uFF09",
431
+ "70604": "\u89C6\u9891\u5206\u8FA8\u7387\u4E0D\u652F\u6301",
432
+ "70605": "\u89C6\u9891\u5E27\u7387\u5F02\u5E38\uFF08\u8303\u56F4\uFF1A1-60fps\uFF09",
433
+ "70606": "\u89C6\u9891\u6D41\u8FDE\u63A5\u5931\u8D25\uFF08RTSP/WebRTC\uFF09",
434
+ "70607": "\u89C6\u9891\u6D41\u4E2D\u65AD",
435
+ "70608": "\u89C6\u9891\u89E3\u7801\u5931\u8D25",
436
+ "70609": "\u89C6\u9891\u7F13\u51B2\u8D85\u65F6",
437
+ "70610": "\u89C6\u9891\u6D41\u4F1A\u8BDD\u8D85\u9650\uFF08\u6BCF\u7EC8\u7AEF\u6700\u591AX\u8DEF\uFF09",
438
+ "70611": "\u89C6\u9891\u5B58\u50A8\u5931\u8D25",
439
+ "70612": "\u89C6\u9891\u65F6\u95F4\u6233\u5F02\u5E38",
440
+ "70613": "\u89C6\u9891\u7801\u7387\u5F02\u5E38",
441
+ "70614": "\u89C6\u9891\u5173\u952E\u5E27\u4E22\u5931",
442
+ "70615": "\u89C6\u9891\u6C34\u5370\u6DFB\u52A0\u5931\u8D25",
443
+ // 707ZZ: 音频流
444
+ "70700": "\u97F3\u9891\u6D41\u9519\u8BEF",
445
+ "70701": "\u97F3\u9891\u6D41\u4E0D\u5B58\u5728\u6216\u672A\u5F00\u542F",
446
+ "70702": "\u97F3\u9891\u6D41\u6743\u9650\u4E0D\u8DB3",
447
+ "70703": "\u97F3\u9891\u7F16\u7801\u683C\u5F0F\u4E0D\u652F\u6301\uFF08\u652F\u6301\uFF1AAAC, MP3, Opus\uFF09",
448
+ "70704": "\u97F3\u9891\u91C7\u6837\u7387\u4E0D\u652F\u6301",
449
+ "70705": "\u97F3\u9891\u58F0\u9053\u6570\u4E0D\u652F\u6301\uFF08\u652F\u6301\uFF1A\u5355\u58F0\u9053/\u7ACB\u4F53\u58F0\uFF09",
450
+ "70706": "\u97F3\u9891\u6D41\u8FDE\u63A5\u5931\u8D25",
451
+ "70707": "\u97F3\u9891\u6D41\u4E2D\u65AD",
452
+ "70708": "\u97F3\u9891\u89E3\u7801\u5931\u8D25",
453
+ "70709": "\u97F3\u9891\u91C7\u96C6\u8BBE\u5907\u5F02\u5E38",
454
+ "70710": "\u97F3\u9891\u64AD\u653E\u8BBE\u5907\u5F02\u5E38",
455
+ "70711": "\u97F3\u9891\u964D\u566A\u5931\u8D25",
456
+ "70712": "\u97F3\u9891\u56DE\u58F0\u6D88\u9664\u5931\u8D25",
457
+ "70713": "\u97F3\u9891\u6BD4\u7279\u7387\u5F02\u5E38",
458
+ // 708ZZ: 流媒体服务
459
+ "70800": "\u6D41\u5A92\u4F53\u670D\u52A1\u9519\u8BEF",
460
+ "70801": "\u6D41\u5A92\u4F53\u670D\u52A1\u5668\u4E0D\u53EF\u7528",
461
+ "70802": "\u7F51\u7EDC\u5E26\u5BBD\u4E0D\u8DB3",
462
+ "70803": "\u7F51\u7EDC\u5EF6\u8FDF\u8FC7\u9AD8\uFF08>300ms\uFF09",
463
+ "70804": "\u7F51\u7EDC\u4E22\u5305\u4E25\u91CD\uFF08>5%\uFF09",
464
+ "70805": "\u6D41\u5A92\u4F53\u534F\u8BAE\u4E0D\u652F\u6301",
465
+ "70806": "\u6D41\u5A92\u4F53\u4F1A\u8BDD\u8FC7\u671F",
466
+ "70807": "\u6D41\u5A92\u4F53\u4F1A\u8BDD\u51B2\u7A81",
467
+ "70808": "\u8F6C\u7801\u670D\u52A1\u5931\u8D25",
468
+ "70809": "\u5408\u6D41\u670D\u52A1\u5931\u8D25",
469
+ "70810": "\u5F55\u5236\u670D\u52A1\u5931\u8D25",
470
+ // 709ZZ: 音视频控制
471
+ "70900": "\u97F3\u89C6\u9891\u63A7\u5236\u9519\u8BEF",
472
+ "70901": "\u5F00\u59CB\u63A8\u6D41\u5931\u8D25",
473
+ "70902": "\u505C\u6B62\u63A8\u6D41\u5931\u8D25",
474
+ "70903": "\u5207\u6362\u7801\u7387\u5931\u8D25",
475
+ "70904": "\u5207\u6362\u5206\u8FA8\u7387\u5931\u8D25",
476
+ "70905": "\u9759\u97F3\u64CD\u4F5C\u5931\u8D25",
477
+ "70906": "\u53D6\u6D88\u9759\u97F3\u5931\u8D25",
478
+ "70907": "\u5F00\u59CB\u5F55\u50CF\u5931\u8D25",
479
+ "70908": "\u505C\u6B62\u5F55\u50CF\u5931\u8D25",
480
+ "70909": "\u89C6\u9891\u6293\u62CD\u5931\u8D25",
481
+ "70910": "\u4E91\u53F0\u63A7\u5236\u5931\u8D25",
482
+ "70911": "\u955C\u5934\u53D8\u7126\u5931\u8D25",
483
+ "70912": "\u7126\u70B9\u8C03\u6574\u5931\u8D25",
484
+ "70913": "\u767D\u5E73\u8861\u8C03\u6574\u5931\u8D25",
485
+ // 710ZZ: 日志文件
486
+ "71000": "\u6587\u4EF6\u64CD\u4F5C\u9519\u8BEF",
487
+ "71001": "\u6587\u4EF6\u53C2\u6570\u7F3A\u5931",
488
+ "71002": "\u6587\u4EF6\u683C\u5F0F\u4E0D\u652F\u6301",
489
+ "71003": "\u6587\u4EF6\u8BFB\u53D6\u5931\u8D25",
490
+ "71004": "\u6587\u4EF6\u89E3\u6790\u5931\u8D25",
491
+ "71005": "\u6587\u4EF6\u5927\u5C0F\u8D85\u9650\uFF08\u6700\u5927\uFF1A100MB\uFF09",
492
+ "71006": "\u6587\u4EF6\u4E0A\u4F20\u5931\u8D25",
493
+ "71007": "\u6587\u4EF6\u4E0B\u8F7D\u5931\u8D25",
494
+ "71008": "\u6587\u4EF6\u5220\u9664\u5931\u8D25",
495
+ "71009": "\u6587\u4EF6\u6821\u9A8C\u5931\u8D25\uFF08MD5/SHA\uFF09",
496
+ "71010": "\u6587\u4EF6\u538B\u7F29\u5931\u8D25",
497
+ "71011": "\u6587\u4EF6\u89E3\u538B\u5931\u8D25",
498
+ "71012": "\u5B58\u50A8\u7A7A\u95F4\u4E0D\u8DB3",
499
+ // 设备硬件错误 (8YYZZ)
500
+ // 802ZZ: 自检维护
501
+ "80200": "\u81EA\u68C0\u7EF4\u62A4\u9519\u8BEF",
502
+ "80201": "\u9065\u63A7\u7AD9\u81EA\u68C0\u53C2\u6570\u7F3A\u5931",
503
+ "80202": "\u9065\u63A7\u7AD9\u81EA\u68C0\u53C2\u6570\u9519\u8BEF",
504
+ "80203": "\u673A\u4E0A\u7CFB\u7EDF\u81EA\u68C0\u53C2\u6570\u7F3A\u5931",
505
+ "80204": "\u673A\u4E0A\u7CFB\u7EDF\u81EA\u68C0\u53C2\u6570\u9519\u8BEF",
506
+ "80205": "\u7EF4\u62A4\u6307\u4EE4\u53C2\u6570\u7F3A\u5931",
507
+ "80206": "\u7EF4\u62A4\u6307\u4EE4\u53C2\u6570\u9519\u8BEF",
508
+ "80207": "\u81EA\u68C0\u8D85\u65F6\uFF08>30\u79D2\uFF09",
509
+ "80208": "\u81EA\u68C0\u5931\u8D25\uFF08\u786C\u4EF6\u5F02\u5E38\uFF09",
510
+ "80209": "GPS\u6A21\u5757\u5F02\u5E38",
511
+ "80210": "IMU\u4F20\u611F\u5668\u5F02\u5E38",
512
+ "80211": "\u6C14\u538B\u8BA1\u5F02\u5E38",
513
+ "80212": "\u78C1\u529B\u8BA1\u5F02\u5E38",
514
+ "80213": "\u7535\u6C60\u72B6\u6001\u5F02\u5E38",
515
+ "80214": "\u7535\u673A\u72B6\u6001\u5F02\u5E38",
516
+ "80215": "\u901A\u4FE1\u6A21\u5757\u5F02\u5E38",
517
+ "80216": "\u98DE\u63A7\u7CFB\u7EDF\u5F02\u5E38",
518
+ "80217": "\u56FA\u4EF6\u7248\u672C\u4E0D\u5339\u914D"
519
+ };
520
+ var ErrorLevel2 = /* @__PURE__ */ ((ErrorLevel3) => {
521
+ ErrorLevel3[ErrorLevel3["SUCCESS"] = 0] = "SUCCESS";
522
+ ErrorLevel3[ErrorLevel3["SYSTEM"] = 1] = "SYSTEM";
523
+ ErrorLevel3[ErrorLevel3["CLIENT_PARAM"] = 2] = "CLIENT_PARAM";
524
+ ErrorLevel3[ErrorLevel3["AUTH"] = 3] = "AUTH";
525
+ ErrorLevel3[ErrorLevel3["BUSINESS"] = 4] = "BUSINESS";
526
+ ErrorLevel3[ErrorLevel3["RESOURCE"] = 5] = "RESOURCE";
527
+ ErrorLevel3[ErrorLevel3["NETWORK"] = 6] = "NETWORK";
528
+ ErrorLevel3[ErrorLevel3["FILE_MEDIA"] = 7] = "FILE_MEDIA";
529
+ ErrorLevel3[ErrorLevel3["DEVICE_HARDWARE"] = 8] = "DEVICE_HARDWARE";
530
+ ErrorLevel3[ErrorLevel3["THIRD_PARTY"] = 9] = "THIRD_PARTY";
531
+ return ErrorLevel3;
532
+ })(ErrorLevel2 || {});
533
+ var FunctionModule2 = /* @__PURE__ */ ((FunctionModule4) => {
534
+ FunctionModule4["GENERAL"] = "00";
535
+ FunctionModule4["USER_AUTH"] = "01";
536
+ FunctionModule4["SELF_CHECK"] = "02";
537
+ FunctionModule4["AIRLINE"] = "03";
538
+ FunctionModule4["FENCE"] = "04";
539
+ FunctionModule4["REAL_TIME_DATA"] = "05";
540
+ FunctionModule4["VIDEO_STREAM"] = "06";
541
+ FunctionModule4["AUDIO_STREAM"] = "07";
542
+ FunctionModule4["MEDIA_SERVICE"] = "08";
543
+ FunctionModule4["AV_CONTROL"] = "09";
544
+ FunctionModule4["LOG_FILE"] = "10";
545
+ FunctionModule4["REMOTE_CONTROL"] = "11";
546
+ FunctionModule4["FLIGHT_STATUS"] = "12";
547
+ return FunctionModule4;
548
+ })(FunctionModule2 || {});
549
+ function resolveBusinessError(subCode) {
550
+ if (!subCode) return "\u4E1A\u52A1\u9519\u8BEF";
551
+ const codeStr = String(subCode);
552
+ return BUSINESS_ERROR_MAP[codeStr] || "\u672A\u77E5\u4E1A\u52A1\u9519\u8BEF";
553
+ }
554
+ function resolveHttpStatus(status) {
555
+ if (!status) return "\u672A\u77E5\u72B6\u6001";
556
+ return HTTP_STATUS_MAP[status] || "\u672A\u77E5HTTP\u72B6\u6001";
557
+ }
558
+ function resolveErrorLevel(subCode) {
559
+ if (!subCode) return 4 /* BUSINESS */;
560
+ const codeStr = String(subCode);
561
+ const level = parseInt(codeStr[0], 10);
562
+ return Object.values(ErrorLevel2).includes(level) ? level : 4 /* BUSINESS */;
563
+ }
564
+ function resolveFunctionModule(subCode) {
565
+ if (!subCode) return "00" /* GENERAL */;
566
+ const codeStr = String(subCode);
567
+ if (codeStr.length < 3) return "00" /* GENERAL */;
568
+ const module = codeStr.slice(1, 3);
569
+ return Object.values(FunctionModule2).includes(module) ? module : "00" /* GENERAL */;
570
+ }
571
+
572
+ // src/client/http.ts
573
+ var notifiedErrors = /* @__PURE__ */ new WeakSet();
574
+ function pickMsg(r) {
575
+ var _a, _b;
576
+ return (_b = (_a = r.msg) != null ? _a : r.message) != null ? _b : "";
577
+ }
578
+ function notifyError(config, error) {
579
+ var _a;
580
+ try {
581
+ if (notifiedErrors.has(error)) return;
582
+ notifiedErrors.add(error);
583
+ if (config.debug) {
584
+ const raw = error.raw;
585
+ handleHttpLog(config, "ERROR", {
586
+ name: "ApiError",
587
+ url: typeof raw === "object" && raw !== null && "url" in raw ? String(raw.url) : void 0,
588
+ method: typeof raw === "object" && raw !== null && "method" in raw ? String(raw.method) : void 0,
589
+ response: {
590
+ code: error.code || error.httpStatus || 500,
591
+ message: error.message,
592
+ error: error.type,
593
+ sub_code: error.subCode,
594
+ sub_msg: error.subMsg
595
+ },
596
+ status: error.httpStatus,
597
+ request: typeof raw === "object" && raw !== null && ("request" in raw || "data" in raw) ? raw.request || raw.data : void 0,
598
+ headers: typeof raw === "object" && raw !== null && "headers" in raw ? raw.headers : void 0
599
+ });
600
+ }
601
+ (_a = config.onError) == null ? void 0 : _a.call(config, error);
602
+ } catch {
603
+ return;
604
+ }
605
+ }
606
+ function simulateNext401(count = 1) {
607
+ state.simulate401Remaining = count;
608
+ }
609
+ function resolveBusinessMessage(config, data) {
610
+ var _a, _b;
611
+ const key = (_a = data.sub_code) != null ? _a : data.code;
612
+ if (key !== void 0) {
613
+ const mapped = (_b = config.businessErrorMessageMap) == null ? void 0 : _b[key];
614
+ if (mapped) return mapped;
615
+ }
616
+ const businessMsg = resolveBusinessError(data.sub_code);
617
+ if (businessMsg !== "\u4E1A\u52A1\u9519\u8BEF") return businessMsg;
618
+ return pickMsg(data) || "\u4E1A\u52A1\u9519\u8BEF";
619
+ }
620
+ function isRefreshRequest(cfg) {
621
+ var _a;
622
+ const url = (_a = cfg == null ? void 0 : cfg.url) != null ? _a : "";
623
+ return url.includes("/auth/v1/refresh");
624
+ }
625
+ function parseQueryFromUrl(url) {
626
+ const idx = url.indexOf("?");
627
+ if (idx < 0) return {};
628
+ const qs = url.slice(idx + 1);
629
+ if (!qs) return {};
630
+ const out = {};
631
+ for (const part of qs.split("&")) {
632
+ if (!part) continue;
633
+ const eq = part.indexOf("=");
634
+ if (eq < 0) {
635
+ out[decodeURIComponent(part)] = "";
636
+ continue;
637
+ }
638
+ const k = decodeURIComponent(part.slice(0, eq));
639
+ const v = decodeURIComponent(part.slice(eq + 1));
640
+ out[k] = v;
641
+ }
642
+ return out;
643
+ }
644
+ function setHeader(cfg, key, value) {
645
+ if (!cfg.headers) cfg.headers = new axios.AxiosHeaders();
646
+ const headers = cfg.headers;
647
+ const headerSetter = headers;
648
+ if (typeof headerSetter.set === "function") {
649
+ headerSetter.set(key, value);
650
+ return;
651
+ }
652
+ cfg.headers[key] = value;
653
+ }
654
+ var isRefreshing = false;
655
+ var refreshPromise;
656
+ var pending = [];
657
+ function sleep(ms) {
658
+ return new Promise((resolve) => setTimeout(resolve, ms));
659
+ }
660
+ async function refreshTokenWithRetry(instance, config) {
661
+ var _a;
662
+ const maxRetries = (_a = config.tokenRefreshMaxRetries) != null ? _a : 1;
663
+ let retryCount = 0;
664
+ while (true) {
665
+ try {
666
+ return await refreshToken(instance, config);
667
+ } catch (e) {
668
+ if (e instanceof ApiError && e.message.includes("\u672A\u8BBE\u7F6E token")) throw e;
669
+ retryCount += 1;
670
+ const shouldRetry = maxRetries === 0 || retryCount <= maxRetries;
671
+ if (!shouldRetry) throw e;
672
+ await sleep(500);
673
+ }
674
+ }
675
+ }
676
+ async function refreshAndReplay(instance, config, cfg) {
677
+ cfg._retry = true;
678
+ if (isRefreshing) {
679
+ return new Promise((resolve, reject) => {
680
+ pending.push({ resolve, reject, config: cfg });
681
+ }).then(() => instance.request(cfg));
682
+ }
683
+ isRefreshing = true;
684
+ refreshPromise = refreshTokenWithRetry(instance, config);
685
+ try {
686
+ await refreshPromise;
687
+ for (const p of pending.splice(0, pending.length)) {
688
+ p.resolve();
689
+ }
690
+ return instance.request(cfg);
691
+ } catch (e) {
692
+ for (const p of pending.splice(0, pending.length)) {
693
+ p.reject(e);
694
+ }
695
+ throw e;
696
+ } finally {
697
+ isRefreshing = false;
698
+ refreshPromise = void 0;
699
+ }
700
+ }
701
+ async function refreshToken(instance, config) {
702
+ var _a, _b, _c, _d, _e;
703
+ handleHttpLog(config, "INFO", {
704
+ name: "refreshToken",
705
+ url: `${config.baseUrl}/auth/v1/refresh`,
706
+ method: "POST"});
707
+ const token = getApiToken();
708
+ if (!token) {
709
+ const error = new ApiError({ message: "\u672A\u8BBE\u7F6E token\uFF0C\u65E0\u6CD5\u5237\u65B0", type: "auth" });
710
+ handleHttpLog(config, "ERROR", {
711
+ name: "refreshToken",
712
+ url: `${config.baseUrl}/auth/v1/refresh`,
713
+ method: "POST"});
714
+ throw error;
715
+ }
716
+ handleHttpLog(config, "DEBUG", {
717
+ name: "refreshToken",
718
+ url: `${config.baseUrl}/auth/v1/refresh`,
719
+ method: "POST",
720
+ request: {}
721
+ });
722
+ const res = await instance.request({
723
+ url: "/auth/v1/refresh",
724
+ method: "POST",
725
+ data: {}
726
+ });
727
+ if (!res.data || res.data.code !== 200 || !((_a = res.data.data) == null ? void 0 : _a.token)) {
728
+ const error = new ApiError({
729
+ message: pickMsg((_b = res.data) != null ? _b : {}) || "\u5237\u65B0 token \u5931\u8D25",
730
+ type: "auth",
731
+ httpStatus: res.status,
732
+ code: (_c = res.data) == null ? void 0 : _c.code,
733
+ subCode: (_d = res.data) == null ? void 0 : _d.sub_code,
734
+ subMsg: (_e = res.data) == null ? void 0 : _e.sub_msg,
735
+ raw: res.data
736
+ });
737
+ handleHttpLog(config, "ERROR", {
738
+ name: "refreshToken",
739
+ url: `${config.baseUrl}/auth/v1/refresh`,
740
+ method: "POST",
741
+ response: res.data,
742
+ status: res.status,
743
+ request: {},
744
+ headers: res.config.headers
745
+ });
746
+ throw error;
747
+ }
748
+ const newToken = res.data.data.token;
749
+ setApiToken(newToken);
750
+ handleHttpLog(config, "INFO", {
751
+ name: "refreshToken",
752
+ url: `${config.baseUrl}/auth/v1/refresh`,
753
+ method: "POST",
754
+ response: res.data,
755
+ status: res.status
756
+ });
757
+ return newToken;
758
+ }
759
+ function createHttpClient(config) {
760
+ const instance = axios__default.default.create({
761
+ baseURL: config.baseUrl
762
+ });
763
+ instance.interceptors.request.use(async (cfg) => {
764
+ var _a, _b, _c, _d, _e, _f;
765
+ const c = cfg;
766
+ if (isRefreshing && refreshPromise && !isRefreshRequest(c)) {
767
+ await refreshPromise;
768
+ }
769
+ c.metadata = { startTime: Date.now(), apiName: (_a = c.metadata) == null ? void 0 : _a.apiName };
770
+ handleHttpLog(config, "DEBUG", {
771
+ name: ((_b = c.metadata) == null ? void 0 : _b.apiName) || "request",
772
+ url: `${config.baseUrl}${c.url || ""}`,
773
+ method: c.method || "",
774
+ headers: c.headers,
775
+ request: c.data || c.params
776
+ });
777
+ const timestamp = Date.now();
778
+ const nonce = randomNonce(32);
779
+ setHeader(c, "X-Timestamp", timestamp);
780
+ setHeader(c, "X-Nonce", nonce);
781
+ const token = getApiToken();
782
+ if (token) setHeader(c, "Authorization", token);
783
+ const rawUrl = (_c = c.url) != null ? _c : "";
784
+ const uri = rawUrl.split("?")[0];
785
+ const paramsFromUrl = parseQueryFromUrl(rawUrl);
786
+ const mergedQuery = {
787
+ ...paramsFromUrl,
788
+ ...(_d = c.params) != null ? _d : {}
789
+ };
790
+ handleHttpLog(config, "TRACE", {
791
+ name: ((_e = c.metadata) == null ? void 0 : _e.apiName) || "generate-sign",
792
+ url: `${config.baseUrl}${c.url || ""}`,
793
+ method: c.method || "",
794
+ request: {
795
+ timestamp,
796
+ nonce,
797
+ uri,
798
+ query: mergedQuery,
799
+ method: c.method || "GET"
800
+ }
801
+ });
802
+ const { sign } = generateSign({
803
+ uri,
804
+ timestamp,
805
+ nonce,
806
+ query: mergedQuery,
807
+ body: c.data,
808
+ secret: config.secret,
809
+ salt: config.salt
810
+ });
811
+ setHeader(c, "X-Sign", sign);
812
+ handleHttpLog(config, "TRACE", {
813
+ name: ((_f = c.metadata) == null ? void 0 : _f.apiName) || "generate-sign",
814
+ url: `${config.baseUrl}${c.url || ""}`,
815
+ method: c.method || ""
816
+ });
817
+ return c;
818
+ });
819
+ instance.interceptors.response.use(
820
+ // 成功响应处理
821
+ async (resp) => {
822
+ var _a, _b, _c, _d, _e, _f, _g, _h;
823
+ const cfg = resp.config;
824
+ const durationMs = cfg.metadata ? Date.now() - cfg.metadata.startTime : void 0;
825
+ const apiName = (_b = (_a = cfg.metadata) == null ? void 0 : _a.apiName) != null ? _b : "request";
826
+ const data = resp.data;
827
+ if (typeof data === "object" && data && "code" in data) {
828
+ const shouldSimulateAuth = ((_c = state.simulate401Remaining) != null ? _c : 0) > 0 && !cfg._retry && !isRefreshRequest(cfg);
829
+ if (shouldSimulateAuth) {
830
+ state.simulate401Remaining = ((_d = state.simulate401Remaining) != null ? _d : 1) - 1;
831
+ }
832
+ const normalizedData = shouldSimulateAuth ? { ...data, code: 401 } : data;
833
+ const httpLog = {
834
+ name: apiName,
835
+ url: `${config.baseUrl}${(_e = cfg.url) != null ? _e : ""}`,
836
+ method: cfg.method,
837
+ headers: cfg.headers,
838
+ request: (_f = cfg.data) != null ? _f : cfg.params,
839
+ response: shouldSimulateAuth ? normalizedData : resp.data,
840
+ durationMs,
841
+ status: resp.status
842
+ };
843
+ if ((normalizedData.code === 401 || normalizedData.code === 403) && !cfg._retry && !isRefreshRequest(cfg)) {
844
+ handleHttpLog(config, "WARN", httpLog);
845
+ return await refreshAndReplay(instance, config, cfg);
846
+ }
847
+ if (normalizedData.code !== 200) {
848
+ const errorLevel = resolveErrorLevel(normalizedData.sub_code);
849
+ const module = resolveFunctionModule(normalizedData.sub_code);
850
+ const e = new ApiError({
851
+ message: resolveBusinessMessage(config, normalizedData),
852
+ type: normalizedData.code === 401 || normalizedData.code === 403 ? "auth" : "business",
853
+ httpStatus: resp.status,
854
+ code: normalizedData.code,
855
+ subCode: normalizedData.sub_code,
856
+ subMsg: normalizedData.sub_msg,
857
+ errorLevel,
858
+ module,
859
+ raw: {
860
+ ...normalizedData,
861
+ url: `${config.baseUrl}${(_g = cfg.url) != null ? _g : ""}`,
862
+ method: cfg.method,
863
+ headers: cfg.headers,
864
+ request: (_h = cfg.data) != null ? _h : cfg.params,
865
+ durationMs: cfg.metadata ? Date.now() - cfg.metadata.startTime : void 0
866
+ }
867
+ });
868
+ notifyError(config, e);
869
+ throw e;
870
+ }
871
+ handleHttpLog(config, "INFO", httpLog);
872
+ }
873
+ return resp;
874
+ },
875
+ // 错误响应处理
876
+ async (error) => {
877
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
878
+ if (error instanceof ApiError) {
879
+ notifyError(config, error);
880
+ throw error;
881
+ }
882
+ const axiosErr = error;
883
+ const cfg = (_a = axiosErr.config) != null ? _a : {};
884
+ const status = (_b = axiosErr.response) == null ? void 0 : _b.status;
885
+ const url = `${config.baseUrl}${(_c = cfg.url) != null ? _c : ""}`;
886
+ const method = (_d = cfg.method) != null ? _d : "";
887
+ const request = (_e = cfg.data) != null ? _e : cfg.params;
888
+ const response = (_f = axiosErr.response) == null ? void 0 : _f.data;
889
+ const durationMs = cfg.metadata ? Date.now() - cfg.metadata.startTime : void 0;
890
+ const apiName = (_h = (_g = cfg.metadata) == null ? void 0 : _g.apiName) != null ? _h : "request";
891
+ const httpLog = {
892
+ name: apiName,
893
+ url,
894
+ method,
895
+ headers: cfg.headers,
896
+ request,
897
+ response,
898
+ durationMs};
899
+ handleHttpLog(config, "ERROR", httpLog);
900
+ if ((status === 401 || status === 403) && !cfg._retry && !isRefreshRequest(cfg)) {
901
+ return await refreshAndReplay(instance, config, cfg);
902
+ }
903
+ if (axiosErr.response) {
904
+ const httpStatusText = resolveHttpStatus(status);
905
+ let message = `${httpStatusText}(${status})`;
906
+ let subCode;
907
+ let subMsg;
908
+ let errorLevel;
909
+ let module;
910
+ if (axiosErr.response.data && typeof axiosErr.response.data === "object") {
911
+ const data = axiosErr.response.data;
912
+ subCode = data.sub_code;
913
+ subMsg = data.sub_msg || data.msg || data.message;
914
+ if (subCode) {
915
+ errorLevel = resolveErrorLevel(subCode);
916
+ module = resolveFunctionModule(subCode);
917
+ const businessMsg = resolveBusinessError(subCode);
918
+ message = businessMsg;
919
+ }
920
+ }
921
+ const e2 = new ApiError({
922
+ message,
923
+ type: status === 401 || status === 403 ? "auth" : "server",
924
+ httpStatus: status,
925
+ subCode,
926
+ subMsg,
927
+ errorLevel,
928
+ module,
929
+ raw: axiosErr.response.data
930
+ });
931
+ notifyError(config, e2);
932
+ throw e2;
933
+ }
934
+ if (axiosErr.request) {
935
+ const e2 = new ApiError({
936
+ message: "\u7F51\u7EDC\u9519\u8BEF",
937
+ type: "network",
938
+ errorLevel: 6 /* NETWORK */,
939
+ raw: (_i = axiosErr.toJSON) == null ? void 0 : _i.call(axiosErr)
940
+ });
941
+ notifyError(config, e2);
942
+ throw e2;
943
+ }
944
+ const e = new ApiError({
945
+ message: axiosErr.message || "\u672A\u77E5\u9519\u8BEF",
946
+ type: "unknown",
947
+ raw: (_j = axiosErr.toJSON) == null ? void 0 : _j.call(axiosErr)
948
+ });
949
+ notifyError(config, e);
950
+ throw e;
951
+ }
952
+ );
953
+ return instance;
954
+ }
955
+ function initApiClient(config) {
956
+ state.config = config;
957
+ state.axios = createHttpClient(config);
958
+ }
959
+ function getHttpClient() {
960
+ if (!state.axios) {
961
+ const error = new ApiError({ message: "Api Client \u672A\u521D\u59CB\u5316\uFF0C\u8BF7\u5148\u8C03\u7528 initApiClient", type: "unknown" });
962
+ handleHttpLog({
963
+ baseUrl: window.location.origin,
964
+ secret: "undefined",
965
+ salt: "undefined",
966
+ debug: true,
967
+ logLevel: "ERROR"
968
+ }, "ERROR", {
969
+ name: "getHttpClient",
970
+ response: {
971
+ code: null,
972
+ message: error.message,
973
+ error: error.type
974
+ }
975
+ });
976
+ throw error;
977
+ }
978
+ return state.axios;
979
+ }
980
+ async function requestData(cfg, apiName) {
981
+ var _a, _b;
982
+ const instance = getHttpClient();
983
+ const c = cfg;
984
+ c.metadata = { ...(_a = c.metadata) != null ? _a : { startTime: Date.now() }, apiName };
985
+ const resp = await instance.request(c);
986
+ const data = resp.data;
987
+ return (_b = data == null ? void 0 : data.data) != null ? _b : {};
988
+ }
989
+
990
+ // src/api/v1/auth.ts
991
+ var loginApi = async (req) => {
992
+ return requestData({
993
+ url: "/auth/v1/login",
994
+ method: "POST",
995
+ data: req
996
+ }, "login");
997
+ };
998
+ var refreshTokenApi = async (req) => {
999
+ return requestData({
1000
+ url: "/auth/v1/refresh",
1001
+ method: "POST",
1002
+ data: req
1003
+ }, "refreshToken");
1004
+ };
1005
+ var logoutApi = async (req) => {
1006
+ return requestData({
1007
+ url: "/auth/v1/logout",
1008
+ method: "POST",
1009
+ data: req
1010
+ }, "logout");
1011
+ };
1012
+
1013
+ // src/api/v1/airline.ts
1014
+ var airlineAddApi = async (req) => {
1015
+ return requestData({
1016
+ url: "/api/v1/airline/add",
1017
+ method: "POST",
1018
+ data: req
1019
+ }, "airlineAdd");
1020
+ };
1021
+ var airlineListApi = async (req) => {
1022
+ return requestData({
1023
+ url: "/api/v1/airline/list",
1024
+ method: "POST",
1025
+ data: req
1026
+ }, "airlineList");
1027
+ };
1028
+ var airlineQueryApi = async (req) => {
1029
+ return requestData({
1030
+ url: "/api/v1/airline/query",
1031
+ method: "POST",
1032
+ data: req
1033
+ }, "airlineQuery");
1034
+ };
1035
+ var airlineUpdateApi = async (req) => {
1036
+ return requestData({
1037
+ url: "/api/v1/airline/update",
1038
+ method: "POST",
1039
+ data: req
1040
+ }, "airlineUpdate");
1041
+ };
1042
+
1043
+ // src/api/v1/fence.ts
1044
+ var fenceAddApi = async (req) => {
1045
+ return requestData({
1046
+ url: "/api/v1/fence/add",
1047
+ method: "POST",
1048
+ data: req
1049
+ }, "fenceAdd");
1050
+ };
1051
+ var fenceListApi = async (req) => {
1052
+ return requestData({
1053
+ url: "/api/v1/fence/list",
1054
+ method: "POST",
1055
+ data: req
1056
+ }, "fenceList");
1057
+ };
1058
+ var fenceQueryApi = async (req) => {
1059
+ return requestData({
1060
+ url: "/api/v1/fence/query",
1061
+ method: "POST",
1062
+ data: req
1063
+ }, "fenceQuery");
1064
+ };
1065
+ var fenceUpdateApi = async (req) => {
1066
+ return requestData({
1067
+ url: "/api/v1/fence/update",
1068
+ method: "POST",
1069
+ data: req
1070
+ }, "fenceUpdate");
1071
+ };
1072
+
1073
+ exports.ApiError = ApiError;
1074
+ exports.ErrorLevel = ErrorLevel;
1075
+ exports.FunctionModule = FunctionModule;
1076
+ exports.airlineAddApi = airlineAddApi;
1077
+ exports.airlineListApi = airlineListApi;
1078
+ exports.airlineQueryApi = airlineQueryApi;
1079
+ exports.airlineUpdateApi = airlineUpdateApi;
1080
+ exports.fenceAddApi = fenceAddApi;
1081
+ exports.fenceListApi = fenceListApi;
1082
+ exports.fenceQueryApi = fenceQueryApi;
1083
+ exports.fenceUpdateApi = fenceUpdateApi;
1084
+ exports.getApiToken = getApiToken;
1085
+ exports.initApiClient = initApiClient;
1086
+ exports.loginApi = loginApi;
1087
+ exports.logoutApi = logoutApi;
1088
+ exports.refreshTokenApi = refreshTokenApi;
1089
+ exports.setApiToken = setApiToken;
1090
+ exports.simulateNext401 = simulateNext401;
1091
+ //# sourceMappingURL=index.js.map
1092
+ //# sourceMappingURL=index.js.map