abler-api 0.2.4 → 0.2.6

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.
Files changed (2) hide show
  1. package/dist/cjs/pp-util.js +30 -30
  2. package/package.json +7 -7
@@ -27,7 +27,7 @@ var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
27
27
  const fs$1 = require$$0__default["default"];
28
28
  const path = require$$1__default["default"];
29
29
  const {
30
- t_f: t_f$4,
30
+ t_f: t_f$3,
31
31
  t: t$1
32
32
  } = require$$2__default["default"];
33
33
  const ppUtil$4 = require$$3__default["default"].ppUtil;
@@ -108,7 +108,7 @@ class preconditions$2 {
108
108
  }
109
109
  let text = "";
110
110
  if (preconditions$2.messages) {
111
- text = t_f$4("*** 由于以下原因,%s 尚不能正常提供服务:\n\n", preconditions$2.appName) + preconditions$2.messages.join("\n\n") + t$1("\n\n*** 请检查以上各项条件,修复后重新启动服务");
111
+ text = t_f$3("*** 由于以下原因,%s 尚不能正常提供服务:\n\n", preconditions$2.appName) + preconditions$2.messages.join("\n\n") + t$1("\n\n*** 请检查以上各项条件,修复后重新启动服务");
112
112
  console.log("\n" + text);
113
113
  // for (let i = 0; i < preconditions.messages.length; i++) {
114
114
  // console.log(preconditions.messages[i]);
@@ -162,12 +162,12 @@ async function createEnvSettingFile(fileName, lastEnvSettingEx) {
162
162
  try {
163
163
  const cfgText = await ppUtil$4.doCreateEnvSettingFile(fileName, lastEnvSettingEx);
164
164
  if (cfgText.indexOf(`cfgVersion: "${conf$3._envSetting.cfgVersion}"`) > 0) {
165
- console.log(t_f$4("\n*** 已創建新的本機環境配置文件\n%s\n请檢查各項內容是否正确(此项更新服务可正常运行)\n\n", fileName));
165
+ console.log(t_f$3("\n*** 已創建新的本機環境配置文件\n%s\n请檢查各項內容是否正确(此项更新服务可正常运行)\n\n", fileName));
166
166
  return "";
167
167
  }
168
- return t_f$4("已創建新的本機環境配置文件\n%s\n请檢查並正確設置各項內容,然後將配置版本號修改為%s", fileName, conf$3._envSettings.default.cfgVersion);
168
+ return t_f$3("已創建新的本機環境配置文件\n%s\n请檢查並正確設置各項內容,然後將配置版本號修改為%s", fileName, conf$3._envSettings.default.cfgVersion);
169
169
  } catch (e) {
170
- return t_f$4("創建本機環境配置文件失敗\n《%s》\n%s", fileName, err$1.ERROR(e).message);
170
+ return t_f$3("創建本機環境配置文件失敗\n《%s》\n%s", fileName, err$1.ERROR(e).message);
171
171
  }
172
172
  }
173
173
  async function checkExEnvSetting(loadjs) {
@@ -197,7 +197,7 @@ async function checkExEnvSetting(loadjs) {
197
197
  }
198
198
  ppUtil$4.importExEnvSetting(conf$3._envSetting, fileName, loadjs);
199
199
  } catch (e) {
200
- return t_f$4("导入本机环境配置失败\n%s", e.stack);
200
+ return t_f$3("导入本机环境配置失败\n%s", e.stack);
201
201
  }
202
202
  }
203
203
 
@@ -217,8 +217,8 @@ async function checkRedis() {
217
217
  redis.error = e;
218
218
  });
219
219
  if (redis.error) {
220
- console.log(t_f$4("未能成功連接 redis: %s,請檢查相關設置", redis.error));
221
- return t_f$4("未能成功連接 redis: %s,請檢查相關設置", redis.error);
220
+ console.log(t_f$3("未能成功連接 redis: %s,請檢查相關設置", redis.error));
221
+ return t_f$3("未能成功連接 redis: %s,請檢查相關設置", redis.error);
222
222
  }
223
223
  // console.log(`checkRedis done:`);
224
224
  // console.log(redis);
@@ -228,12 +228,12 @@ async function initDb(dbSql) {
228
228
  dbUtil$1.config(conf$3, err$1, dbSql);
229
229
  } catch (e) {
230
230
  if (e.reason === 'bad decrypt') {
231
- e = new Error(t_f$4("解密数据库密码(%s)失败", conf$3.dbconn.dbpwd));
231
+ e = new Error(t_f$3("解密数据库密码(%s)失败", conf$3.dbconn.dbpwd));
232
232
  }
233
233
  // if (e.reason === 'bad decrypt') {
234
234
  // e = new Error(`解密Redis密码(${conf.redis.password})失败`);
235
235
  // }
236
- return t_f$4("初始化数据库连接失败(%s)", e.message);
236
+ return t_f$3("初始化数据库连接失败(%s)", e.message);
237
237
  }
238
238
  }
239
239
  async function initKvStorage(dbSql) {
@@ -248,7 +248,7 @@ async function initKvStorage(dbSql) {
248
248
  // if (e.reason === 'bad decrypt') {
249
249
  // e = new Error(`解密Redis密码(${conf.redis.password})失败`);
250
250
  // }
251
- return t_f$4("初始化键值对存储器失败(%s)", e.message);
251
+ return t_f$3("初始化键值对存储器失败(%s)", e.message);
252
252
  }
253
253
  }
254
254
  var ppPrecond = preconditions$2;
@@ -257,7 +257,7 @@ const fs = require$$0__default["default"];
257
257
  const crypto = require$$1__default$1["default"];
258
258
  const getBasicAuthorization = require$$2__default$1["default"];
259
259
  const {
260
- t_f: t_f$3,
260
+ t_f: t_f$2,
261
261
  t
262
262
  } = require$$2__default["default"];
263
263
  const {
@@ -410,7 +410,7 @@ class apiUtil$2 {
410
410
  if (this[name] === undefined) return defaultValue;
411
411
  let result = +this[name];
412
412
  if (typeof result !== "number" || result < minValue || result > maxValue) {
413
- throw [errCfg.INVALID_PARAM, t_f$3("参数 %s 必须是 %s ~ %s 之间的数字", name, minValue, maxValue)];
413
+ throw [errCfg.INVALID_PARAM, t_f$2("参数 %s 必须是 %s ~ %s 之间的数字", name, minValue, maxValue)];
414
414
  }
415
415
  return result;
416
416
  });
@@ -522,7 +522,7 @@ class apiUtil$2 {
522
522
  try {
523
523
  response.send(data);
524
524
  } catch (e) {
525
- console.log(t_f$3("response.send 出错了,req.url: %s, response:", response.req.url), response);
525
+ console.log(t_f$2("response.send 出错了,req.url: %s, response:", response.req.url), response);
526
526
  console.log("异常信息", e);
527
527
  }
528
528
  }
@@ -999,7 +999,7 @@ class apiUtil$2 {
999
999
  return certInfo;
1000
1000
  }).catch(e => {
1001
1001
  console.log('获取企业证书失败:\n', e);
1002
- throw [errCfg.ACCESS_REFUSED, t_f$3("获取企业证书失败:%s", errCfg.ERROR(e).message)];
1002
+ throw [errCfg.ACCESS_REFUSED, t_f$2("获取企业证书失败:%s", errCfg.ERROR(e).message)];
1003
1003
  });
1004
1004
  }
1005
1005
 
@@ -1012,17 +1012,17 @@ class apiUtil$2 {
1012
1012
  static async verifyApiTokenSignature(tokenData, req) {
1013
1013
  try {
1014
1014
  if (!req.headers.timestamp) {
1015
- throw [errCfg.ACCESS_REFUSED, t_f$3("必须在请求头中设置时戳")];
1015
+ throw [errCfg.ACCESS_REFUSED, t_f$2("必须在请求头中设置时戳")];
1016
1016
  }
1017
1017
  let timestamp = parseInt(req.headers.timestamp);
1018
1018
  let currentTime = new Date().valueOf();
1019
1019
  let maxTimeDiff = apiUtil$2.isDebugMode(req) ? 7 * 24 * 3600 : apiUtil$2.isTestMode(req) ? 4 * 3600 : 100; // 100
1020
1020
  if (timestamp.toString() == "NaN" || currentTime < timestamp - 5000 || currentTime - timestamp > maxTimeDiff * 1000) {
1021
- throw [errCfg.ACCESS_REFUSED, t_f$3("时戳(%s)无效,当前时戳:%s,时差 %s秒", timestamp, currentTime, (currentTime - timestamp) / 1000)];
1021
+ throw [errCfg.ACCESS_REFUSED, t_f$2("时戳(%s)无效,当前时戳:%s,时差 %s秒", timestamp, currentTime, (currentTime - timestamp) / 1000)];
1022
1022
  }
1023
1023
  let signature = req.headers.signature;
1024
1024
  if (!signature) {
1025
- throw [errCfg.ACCESS_REFUSED, t_f$3("必须在请求头中提供签名")];
1025
+ throw [errCfg.ACCESS_REFUSED, t_f$2("必须在请求头中提供签名")];
1026
1026
  }
1027
1027
  let signData = apiUtil$2.extractToken(req, null, true) || tokenData.apiKey;
1028
1028
  signData += timestamp;
@@ -1083,7 +1083,7 @@ class apiUtil$2 {
1083
1083
  verifyOK = verifySpare.verify(tokenData.certPublicKeySpare, signature, 'base64');
1084
1084
  if (verifyOK) {
1085
1085
  // 备用证书验证成功了,则将备用证书替换为正式证书
1086
- console.log(t_f$3("公司(%s)备用证书验签成功,正式启用...", tokenData.apiKey));
1086
+ console.log(t_f$2("公司(%s)备用证书验签成功,正式启用...", tokenData.apiKey));
1087
1087
  return dbUtil.dbTrans(trans => {
1088
1088
  let p1 = dbUtil.dbExec(dbSql.deleteCertRecById, {
1089
1089
  replacements: {
@@ -1107,7 +1107,7 @@ class apiUtil$2 {
1107
1107
  if (token) {
1108
1108
  apiUtil$2.storeToken(apiUtil$2.apiTokenStoreKey(token), tokenData, tokenData.apiKey, req);
1109
1109
  }
1110
- console.log(t_f$3("公司(%s)备用证书成功转换为正式证书", tokenData.apiKey));
1110
+ console.log(t_f$2("公司(%s)备用证书成功转换为正式证书", tokenData.apiKey));
1111
1111
  });
1112
1112
  }
1113
1113
  } catch (e) {
@@ -1199,7 +1199,7 @@ class apiUtil$2 {
1199
1199
  } else {
1200
1200
  paramExists = typeof params[paramName] != 'undefined' || typeof params[paramName + paramSufix] != 'undefined';
1201
1201
  }
1202
- if (!paramExists) throw errCfg$1.ERROR(errCfg$1.PARAMETER_NEEDED, paramName);
1202
+ if (!paramExists) throw errCfg.ERROR(errCfg.PARAMETER_NEEDED, paramName);
1203
1203
  }
1204
1204
  return paramSufix;
1205
1205
  }
@@ -1268,7 +1268,7 @@ class apiUtil$2 {
1268
1268
  const myEnvHosts = apiUtil$2.getEnvHosts(params);
1269
1269
  const myIp = ppUtil$3.getMyIp();
1270
1270
  const host = params.host || myIp;
1271
- if (!myEnvHosts.hosts.contains(host)) throw [errCfg.ACCESS_REFUSED, t_f$3("环境%s貌似无此主机:%s", conf$2.envId, params.host)];
1271
+ if (!myEnvHosts.hosts.contains(host)) throw [errCfg.ACCESS_REFUSED, t_f$2("环境%s貌似无此主机:%s", conf$2.envId, params.host)];
1272
1272
  if (!apiUtil$2.hostIsMySelf(host, options._res.req)) {
1273
1273
  let result = await apiUtil$2.forwardsTo(host, myEnvHosts.port, params, options._res.req, myIp);
1274
1274
  options._res.send(result);
@@ -1298,7 +1298,7 @@ class apiUtil$2 {
1298
1298
  };
1299
1299
  let result = await netUtil$1.apiRequest(reqOptions);
1300
1300
  if (result.status !== 200) {
1301
- console.log(t_f$3("访问 %s 出错", reqOptions.url), result.status, result.res.statusMessage);
1301
+ console.log(t_f$2("访问 %s 出错", reqOptions.url), result.status, result.res.statusMessage);
1302
1302
  throw [errCfg.EXCEPTION, `[${result.status}] - ${result.res.statusMessage}`];
1303
1303
  }
1304
1304
  return result.data;
@@ -1321,7 +1321,7 @@ class apiUtil$2 {
1321
1321
  key = keys[i];
1322
1322
  value = parent[key];
1323
1323
  if (value === undefined) {
1324
- throw [errCfg.INVALID_PARAM, t_f$3("无此配置项: %s", key)];
1324
+ throw [errCfg.INVALID_PARAM, t_f$2("无此配置项: %s", key)];
1325
1325
  }
1326
1326
  }
1327
1327
  return {
@@ -1477,7 +1477,7 @@ class apiUtil$2 {
1477
1477
  };
1478
1478
  const appInfo = await this.restoreAppInfo(params.apiKey, options._res.req);
1479
1479
  if (!appInfo) {
1480
- throw [errCfg.ACCESS_REFUSED, t_f$3("apiKey (%s) 无效", params.apiKey)];
1480
+ throw [errCfg.ACCESS_REFUSED, t_f$2("apiKey (%s) 无效", params.apiKey)];
1481
1481
  }
1482
1482
  let content = '';
1483
1483
  if (appSetting.e2eEncryptionNeeded) {
@@ -1530,7 +1530,7 @@ class apiUtil$2 {
1530
1530
  }
1531
1531
  req.appInfo = await this.restoreAppInfo(apiKey, req);
1532
1532
  if (!req.appInfo) {
1533
- throw [errCfg.ACCESS_REFUSED, t_f$3("api-key (%s) 无效", apiKey)];
1533
+ throw [errCfg.ACCESS_REFUSED, t_f$2("api-key (%s) 无效", apiKey)];
1534
1534
  }
1535
1535
  }
1536
1536
  }
@@ -1541,17 +1541,17 @@ class apiUtil$2 {
1541
1541
  await this.reqAppInfoNeeded(req);
1542
1542
  if (!appSetting.reqSignatureNeeded) return true;
1543
1543
  if (!req.headers.timestamp) {
1544
- throw [errCfg.ACCESS_REFUSED, t_f$3("必须在请求头中设置时戳")];
1544
+ throw [errCfg.ACCESS_REFUSED, t_f$2("必须在请求头中设置时戳")];
1545
1545
  }
1546
1546
  let timestamp = parseInt(req.headers.timestamp);
1547
1547
  let currentTime = new Date().valueOf();
1548
1548
  let maxTimeDiff = apiUtil$2.isDebugMode(req) ? 7 * 24 * 3600 : apiUtil$2.isTestMode(req) ? 4 * 3600 : 300; // 100
1549
1549
  if (timestamp.toString() === "NaN" || currentTime < timestamp - 5000 || currentTime - timestamp > maxTimeDiff * 1000) {
1550
- throw [errCfg.ACCESS_REFUSED, t_f$3("时戳(%s)无效,当前时戳:%s,时差 %s秒", timestamp, currentTime, (currentTime - timestamp) / 1000)];
1550
+ throw [errCfg.ACCESS_REFUSED, t_f$2("时戳(%s)无效,当前时戳:%s,时差 %s秒", timestamp, currentTime, (currentTime - timestamp) / 1000)];
1551
1551
  }
1552
1552
  let signature = req.headers.signature;
1553
1553
  if (!signature) {
1554
- throw [errCfg.ACCESS_REFUSED, t_f$3("必须在请求头中提供签名")];
1554
+ throw [errCfg.ACCESS_REFUSED, t_f$2("必须在请求头中提供签名")];
1555
1555
  }
1556
1556
  const params = apiUtil$2.extractParams(req);
1557
1557
  const content = appSetting.e2eEncryptionNeeded ? params?.encryptedContent || '' : JSON.stringify(params || null);
@@ -1858,7 +1858,7 @@ class apiUtil$2 {
1858
1858
  await apiUtil$2.parametersOK(params, "value");
1859
1859
  let c = apiUtil$2.parseCfgPath(cfgItem);
1860
1860
  if (typeof c.value === "object") {
1861
- throw [errCfg.ACCESS_REFUSED, t_f$3("暂不支持修改复杂配置")];
1861
+ throw [errCfg.ACCESS_REFUSED, t_f$2("暂不支持修改复杂配置")];
1862
1862
  }
1863
1863
  // c.oldValue = c.value;
1864
1864
  c.newValue = params.value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abler-api",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "API服务相关工具",
5
5
  "main": "./dist/cjs/pp-util.js",
6
6
  "-module": "./dist/es/pp-util.js",
@@ -15,11 +15,11 @@
15
15
  "author": "peng_peng",
16
16
  "license": "ISC",
17
17
  "dependencies": {
18
- "abler-db": "^0.1.57",
19
- "abler-i18n": "^0.1.25",
20
- "abler-messenger": "^0.1.16",
21
- "abler-net": "^0.1.13",
22
- "abler-util": "^0.3.4",
18
+ "abler-db": "^0.1.60",
19
+ "abler-i18n": "^0.1.26",
20
+ "abler-messenger": "^0.1.19",
21
+ "abler-net": "^0.1.16",
22
+ "abler-util": "^0.3.7",
23
23
  "basic-auth": "^2.0.1",
24
24
  "node-cron": "^3.0.1",
25
25
  "q": "^1.5.1"
@@ -42,5 +42,5 @@
42
42
  "rollup-plugin-json": "^4.0.0",
43
43
  "rollup-plugin-terser": "^7.0.2"
44
44
  },
45
- "gitHead": "b371a71a41ed24e889f0c35e51deb13916351ff6"
45
+ "gitHead": "8bcda8b0d9e52c739b1386f830dd2138276e99c3"
46
46
  }