abler-api 0.2.3 → 0.2.4

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 +37 -34
  2. package/package.json +46 -45
@@ -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$3,
30
+ t_f: t_f$4,
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$3("*** 由于以下原因,%s 尚不能正常提供服务:\n\n", preconditions$2.appName) + preconditions$2.messages.join("\n\n") + t$1("\n\n*** 请检查以上各项条件,修复后重新启动服务");
111
+ text = t_f$4("*** 由于以下原因,%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$3("\n*** 已創建新的本機環境配置文件\n%s\n请檢查各項內容是否正确(此项更新服务可正常运行)\n\n", fileName));
165
+ console.log(t_f$4("\n*** 已創建新的本機環境配置文件\n%s\n请檢查各項內容是否正确(此项更新服务可正常运行)\n\n", fileName));
166
166
  return "";
167
167
  }
168
- return t_f$3("已創建新的本機環境配置文件\n%s\n请檢查並正確設置各項內容,然後將配置版本號修改為%s", fileName, conf$3._envSettings.default.cfgVersion);
168
+ return t_f$4("已創建新的本機環境配置文件\n%s\n请檢查並正確設置各項內容,然後將配置版本號修改為%s", fileName, conf$3._envSettings.default.cfgVersion);
169
169
  } catch (e) {
170
- return t_f$3("創建本機環境配置文件失敗\n《%s》\n%s", fileName, err$1.ERROR(e).message);
170
+ return t_f$4("創建本機環境配置文件失敗\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$3("导入本机环境配置失败\n%s", e.stack);
200
+ return t_f$4("导入本机环境配置失败\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$3("未能成功連接 redis: %s,請檢查相關設置", redis.error));
221
- return t_f$3("未能成功連接 redis: %s,請檢查相關設置", redis.error);
220
+ console.log(t_f$4("未能成功連接 redis: %s,請檢查相關設置", redis.error));
221
+ return t_f$4("未能成功連接 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$3("解密数据库密码(%s)失败", conf$3.dbconn.dbpwd));
231
+ e = new Error(t_f$4("解密数据库密码(%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$3("初始化数据库连接失败(%s)", e.message);
236
+ return t_f$4("初始化数据库连接失败(%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$3("初始化键值对存储器失败(%s)", e.message);
251
+ return t_f$4("初始化键值对存储器失败(%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$2,
260
+ t_f: t_f$3,
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$2("参数 %s 必须是 %s ~ %s 之间的数字", name, minValue, maxValue)];
413
+ throw [errCfg.INVALID_PARAM, t_f$3("参数 %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$2("response.send 出错了,req.url: %s, response:", response.req.url), response);
525
+ console.log(t_f$3("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$2("获取企业证书失败:%s", errCfg.ERROR(e).message)];
1002
+ throw [errCfg.ACCESS_REFUSED, t_f$3("获取企业证书失败:%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$2("必须在请求头中设置时戳")];
1015
+ throw [errCfg.ACCESS_REFUSED, t_f$3("必须在请求头中设置时戳")];
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$2("时戳(%s)无效,当前时戳:%s,时差 %s秒", timestamp, currentTime, (currentTime - timestamp) / 1000)];
1021
+ throw [errCfg.ACCESS_REFUSED, t_f$3("时戳(%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$2("必须在请求头中提供签名")];
1025
+ throw [errCfg.ACCESS_REFUSED, t_f$3("必须在请求头中提供签名")];
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$2("公司(%s)备用证书验签成功,正式启用...", tokenData.apiKey));
1086
+ console.log(t_f$3("公司(%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$2("公司(%s)备用证书成功转换为正式证书", tokenData.apiKey));
1110
+ console.log(t_f$3("公司(%s)备用证书成功转换为正式证书", tokenData.apiKey));
1111
1111
  });
1112
1112
  }
1113
1113
  } catch (e) {
@@ -1164,10 +1164,10 @@ class apiUtil$2 {
1164
1164
  * @param token
1165
1165
  * @returns {*}
1166
1166
  */
1167
- static tokenDataExist(token) {
1168
- return kvStorage.stored(token);
1167
+ static async tokenDataExist(token) {
1168
+ return await kvStorage.stored(token);
1169
1169
  }
1170
- static parametersOK(params) {
1170
+ static checkParametersOK(params) {
1171
1171
  configNeeded();
1172
1172
  let paramSufix = params._param_sufix || "";
1173
1173
  for (let i = 1; i < arguments.length; i++) {
@@ -1199,9 +1199,12 @@ class apiUtil$2 {
1199
1199
  } else {
1200
1200
  paramExists = typeof params[paramName] != 'undefined' || typeof params[paramName + paramSufix] != 'undefined';
1201
1201
  }
1202
- if (!paramExists) return ppUtil$3.errorPormise(errCfg.ERROR(errCfg.PARAMETER_NEEDED, paramName));
1202
+ if (!paramExists) throw errCfg$1.ERROR(errCfg$1.PARAMETER_NEEDED, paramName);
1203
1203
  }
1204
- return Promise.resolve(paramSufix);
1204
+ return paramSufix;
1205
+ }
1206
+ static async parametersOK(params) {
1207
+ return await apiUtil$2.checkParametersOK(params);
1205
1208
  }
1206
1209
 
1207
1210
  /**
@@ -1265,7 +1268,7 @@ class apiUtil$2 {
1265
1268
  const myEnvHosts = apiUtil$2.getEnvHosts(params);
1266
1269
  const myIp = ppUtil$3.getMyIp();
1267
1270
  const host = params.host || myIp;
1268
- if (!myEnvHosts.hosts.contains(host)) throw [errCfg.ACCESS_REFUSED, t_f$2("环境%s貌似无此主机:%s", conf$2.envId, params.host)];
1271
+ if (!myEnvHosts.hosts.contains(host)) throw [errCfg.ACCESS_REFUSED, t_f$3("环境%s貌似无此主机:%s", conf$2.envId, params.host)];
1269
1272
  if (!apiUtil$2.hostIsMySelf(host, options._res.req)) {
1270
1273
  let result = await apiUtil$2.forwardsTo(host, myEnvHosts.port, params, options._res.req, myIp);
1271
1274
  options._res.send(result);
@@ -1295,7 +1298,7 @@ class apiUtil$2 {
1295
1298
  };
1296
1299
  let result = await netUtil$1.apiRequest(reqOptions);
1297
1300
  if (result.status !== 200) {
1298
- console.log(t_f$2("访问 %s 出错", reqOptions.url), result.status, result.res.statusMessage);
1301
+ console.log(t_f$3("访问 %s 出错", reqOptions.url), result.status, result.res.statusMessage);
1299
1302
  throw [errCfg.EXCEPTION, `[${result.status}] - ${result.res.statusMessage}`];
1300
1303
  }
1301
1304
  return result.data;
@@ -1318,7 +1321,7 @@ class apiUtil$2 {
1318
1321
  key = keys[i];
1319
1322
  value = parent[key];
1320
1323
  if (value === undefined) {
1321
- throw [errCfg.INVALID_PARAM, t_f$2("无此配置项: %s", key)];
1324
+ throw [errCfg.INVALID_PARAM, t_f$3("无此配置项: %s", key)];
1322
1325
  }
1323
1326
  }
1324
1327
  return {
@@ -1474,7 +1477,7 @@ class apiUtil$2 {
1474
1477
  };
1475
1478
  const appInfo = await this.restoreAppInfo(params.apiKey, options._res.req);
1476
1479
  if (!appInfo) {
1477
- throw [errCfg.ACCESS_REFUSED, t_f$2("apiKey (%s) 无效", params.apiKey)];
1480
+ throw [errCfg.ACCESS_REFUSED, t_f$3("apiKey (%s) 无效", params.apiKey)];
1478
1481
  }
1479
1482
  let content = '';
1480
1483
  if (appSetting.e2eEncryptionNeeded) {
@@ -1527,7 +1530,7 @@ class apiUtil$2 {
1527
1530
  }
1528
1531
  req.appInfo = await this.restoreAppInfo(apiKey, req);
1529
1532
  if (!req.appInfo) {
1530
- throw [errCfg.ACCESS_REFUSED, t_f$2("api-key (%s) 无效", apiKey)];
1533
+ throw [errCfg.ACCESS_REFUSED, t_f$3("api-key (%s) 无效", apiKey)];
1531
1534
  }
1532
1535
  }
1533
1536
  }
@@ -1538,17 +1541,17 @@ class apiUtil$2 {
1538
1541
  await this.reqAppInfoNeeded(req);
1539
1542
  if (!appSetting.reqSignatureNeeded) return true;
1540
1543
  if (!req.headers.timestamp) {
1541
- throw [errCfg.ACCESS_REFUSED, t_f$2("必须在请求头中设置时戳")];
1544
+ throw [errCfg.ACCESS_REFUSED, t_f$3("必须在请求头中设置时戳")];
1542
1545
  }
1543
1546
  let timestamp = parseInt(req.headers.timestamp);
1544
1547
  let currentTime = new Date().valueOf();
1545
1548
  let maxTimeDiff = apiUtil$2.isDebugMode(req) ? 7 * 24 * 3600 : apiUtil$2.isTestMode(req) ? 4 * 3600 : 300; // 100
1546
1549
  if (timestamp.toString() === "NaN" || currentTime < timestamp - 5000 || currentTime - timestamp > maxTimeDiff * 1000) {
1547
- throw [errCfg.ACCESS_REFUSED, t_f$2("时戳(%s)无效,当前时戳:%s,时差 %s秒", timestamp, currentTime, (currentTime - timestamp) / 1000)];
1550
+ throw [errCfg.ACCESS_REFUSED, t_f$3("时戳(%s)无效,当前时戳:%s,时差 %s秒", timestamp, currentTime, (currentTime - timestamp) / 1000)];
1548
1551
  }
1549
1552
  let signature = req.headers.signature;
1550
1553
  if (!signature) {
1551
- throw [errCfg.ACCESS_REFUSED, t_f$2("必须在请求头中提供签名")];
1554
+ throw [errCfg.ACCESS_REFUSED, t_f$3("必须在请求头中提供签名")];
1552
1555
  }
1553
1556
  const params = apiUtil$2.extractParams(req);
1554
1557
  const content = appSetting.e2eEncryptionNeeded ? params?.encryptedContent || '' : JSON.stringify(params || null);
@@ -1855,7 +1858,7 @@ class apiUtil$2 {
1855
1858
  await apiUtil$2.parametersOK(params, "value");
1856
1859
  let c = apiUtil$2.parseCfgPath(cfgItem);
1857
1860
  if (typeof c.value === "object") {
1858
- throw [errCfg.ACCESS_REFUSED, t_f$2("暂不支持修改复杂配置")];
1861
+ throw [errCfg.ACCESS_REFUSED, t_f$3("暂不支持修改复杂配置")];
1859
1862
  }
1860
1863
  // c.oldValue = c.value;
1861
1864
  c.newValue = params.value;
package/package.json CHANGED
@@ -1,45 +1,46 @@
1
- {
2
- "name": "abler-api",
3
- "version": "0.2.3",
4
- "description": "API服务相关工具",
5
- "main": "./dist/cjs/pp-util.js",
6
- "-module": "./dist/es/pp-util.js",
7
- "scripts": {
8
- "build": "npx rollup -c rollup.config.js",
9
- "postbuild": "node ..\\postbuild.js",
10
- "test": "echo \"Error: no test specified\" && exit 1"
11
- },
12
- "files": [
13
- "dist"
14
- ],
15
- "author": "peng_peng",
16
- "license": "ISC",
17
- "dependencies": {
18
- "q": "^1.5.1",
19
- "abler-util": ">=0.3.0",
20
- "abler-db": ">=0.1.1",
21
- "abler-i18n": "^0.1.20",
22
- "abler-messenger": ">=0.1.1",
23
- "abler-net": ">=0.1.1",
24
- "basic-auth": "^2.0.1",
25
- "node-cron": "^3.0.1"
26
- },
27
- "devDependencies": {
28
- "@babel/core": "^7.18.5",
29
- "@babel/eslint-parser": "^7.18.2",
30
- "@babel/plugin-transform-runtime": "^7.18.0",
31
- "@babel/preset-env": "^7.18.2",
32
- "@babel/runtime": "^7.18.0",
33
- "@rollup/plugin-babel": "^5.3.1",
34
- "@rollup/plugin-commonjs": "^22.0.0",
35
- "@rollup/plugin-eslint": "^8.0.2",
36
- "@rollup/plugin-node-resolve": "^13.3.0",
37
- "@typescript-eslint/eslint-plugin": "^5.25.0",
38
- "@typescript-eslint/parser": "^5.25.0",
39
- "eslint": "^8.16.0",
40
- "eslint-plugin-react": "^7.30.0",
41
- "rollup-plugin-filesize": "^9.1.2",
42
- "rollup-plugin-json": "^4.0.0",
43
- "rollup-plugin-terser": "^7.0.2"
44
- }
45
- }
1
+ {
2
+ "name": "abler-api",
3
+ "version": "0.2.4",
4
+ "description": "API服务相关工具",
5
+ "main": "./dist/cjs/pp-util.js",
6
+ "-module": "./dist/es/pp-util.js",
7
+ "scripts": {
8
+ "build": "npx rollup -c rollup.config.js",
9
+ "postbuild": "node ..\\postbuild.js",
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "author": "peng_peng",
16
+ "license": "ISC",
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",
23
+ "basic-auth": "^2.0.1",
24
+ "node-cron": "^3.0.1",
25
+ "q": "^1.5.1"
26
+ },
27
+ "devDependencies": {
28
+ "@babel/core": "^7.18.5",
29
+ "@babel/eslint-parser": "^7.18.2",
30
+ "@babel/plugin-transform-runtime": "^7.18.0",
31
+ "@babel/preset-env": "^7.18.2",
32
+ "@babel/runtime": "^7.18.0",
33
+ "@rollup/plugin-babel": "^5.3.1",
34
+ "@rollup/plugin-commonjs": "^22.0.0",
35
+ "@rollup/plugin-eslint": "^8.0.2",
36
+ "@rollup/plugin-node-resolve": "^13.3.0",
37
+ "@typescript-eslint/eslint-plugin": "^5.25.0",
38
+ "@typescript-eslint/parser": "^5.25.0",
39
+ "eslint": "^8.16.0",
40
+ "eslint-plugin-react": "^7.30.0",
41
+ "rollup-plugin-filesize": "^9.1.2",
42
+ "rollup-plugin-json": "^4.0.0",
43
+ "rollup-plugin-terser": "^7.0.2"
44
+ },
45
+ "gitHead": "b371a71a41ed24e889f0c35e51deb13916351ff6"
46
+ }