abler-api 0.1.34 → 0.1.37

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.
@@ -689,7 +689,7 @@ class apiUtil$2 {
689
689
  static createApiCallRec(tokenData, req) {
690
690
  if (!req.apiCallRec) {
691
691
  if (req.apiCallRecId) {
692
- return dbQueryOne(dbSql.loadApiUsage, {
692
+ return dbUtil.dbQueryOne(dbSql.loadApiUsage, {
693
693
  replacements: {
694
694
  id: req.apiCallRecId
695
695
  }
@@ -698,10 +698,10 @@ class apiUtil$2 {
698
698
  return req.apiCallRec;
699
699
  });
700
700
  } else {
701
- let params = extractParams(req); // let contentLength = parseInt(req.headers["content-length"]) || 0;
701
+ let params = this.extractParams(req); // let contentLength = parseInt(req.headers["content-length"]) || 0;
702
702
 
703
703
  let rec = {
704
- id: newGuid(),
704
+ id: ppUtil$4.newGuid(),
705
705
  companyId: tokenData.apiKey || '',
706
706
  orderId: params.orderId || '',
707
707
  signerId: params.signerId || '',
@@ -736,6 +736,24 @@ class apiUtil$2 {
736
736
  }
737
737
 
738
738
  return req.apiCallRec;
739
+
740
+ function _getBodyLogStr(req) {
741
+ let contentLength = parseInt(req.headers["content-length"]) || 0;
742
+ if (contentLength < 500) return req.rawBody || '';
743
+ let tempBody = {};
744
+
745
+ for (let key in req.body) {
746
+ let value = req.body[key];
747
+
748
+ if (typeof value == 'string' && value.length > 500) {
749
+ value = value.substring(0, 31) + '...(' + value.length + ')';
750
+ }
751
+
752
+ tempBody[key] = value;
753
+ }
754
+
755
+ return JSON.stringify(tempBody);
756
+ }
739
757
  }
740
758
  /**
741
759
  * 查询机构信息
@@ -1077,9 +1095,14 @@ class apiUtil$2 {
1077
1095
 
1078
1096
  static async hostIsMySelf(host, req) {
1079
1097
  let clientIp = apiUtil$2.getClientIp(req);
1080
- return ppUtil$4.getMyIp({
1081
- hosts: [host, clientIp]
1082
- });
1098
+
1099
+ try {
1100
+ return !!ppUtil$4.getMyIp({
1101
+ hosts: [host, clientIp]
1102
+ });
1103
+ } catch (e) {
1104
+ return false;
1105
+ }
1083
1106
  }
1084
1107
  /**
1085
1108
  * 检查是否应该把请求转发到其它服务器,若是则转发
@@ -1462,7 +1485,7 @@ var ppUtilApi = apiUtil$2;
1462
1485
  const fs = require$$4__default["default"];
1463
1486
  const path = require$$1__default$1["default"];
1464
1487
  const ppUtil$3 = require$$1__default["default"].ppUtil;
1465
- const redisUtil = require$$2__default["default"].redisUtil;
1488
+ const ppRedis = require$$2__default["default"].ppRedis;
1466
1489
  let conf$2, err$1; // const dbCheck = require('../dbupdate/dd-version');
1467
1490
 
1468
1491
  /**
@@ -1601,8 +1624,7 @@ async function checkExEnvSetting(loadjs) {
1601
1624
 
1602
1625
  if (!msg) {
1603
1626
  delete require.cache[fileName];
1604
- const envSettingEx = loadjs(fileName);
1605
- ppUtil$3.importExEnvSetting(conf$2._envSetting, envSettingEx);
1627
+ ppUtil$3.importExEnvSetting(conf$2._envSetting, fileName, loadjs);
1606
1628
  }
1607
1629
 
1608
1630
  return msg;
@@ -1615,7 +1637,7 @@ async function checkExEnvSetting(loadjs) {
1615
1637
 
1616
1638
  async function checkRedis() {
1617
1639
  if (!conf$2.redis.enabled) return "";
1618
- const redis = redisUtil.newClient("io"); // console.log(`checkRedis begin:`);
1640
+ const redis = ppRedis.newClient("kv"); // console.log(`checkRedis begin:`);
1619
1641
 
1620
1642
  await ppUtil$3.wait(15 * 1000, param => {
1621
1643
  if (redis.ready && redis.connected || redis.error) {
@@ -1064,9 +1064,14 @@ class apiUtil$2 {
1064
1064
 
1065
1065
  static async hostIsMySelf(host, req) {
1066
1066
  let clientIp = apiUtil$2.getClientIp(req);
1067
- return ppUtil$4.getMyIp({
1068
- hosts: [host, clientIp]
1069
- });
1067
+
1068
+ try {
1069
+ return !!ppUtil$4.getMyIp({
1070
+ hosts: [host, clientIp]
1071
+ });
1072
+ } catch (e) {
1073
+ return false;
1074
+ }
1070
1075
  }
1071
1076
  /**
1072
1077
  * 检查是否应该把请求转发到其它服务器,若是则转发
@@ -1449,7 +1454,7 @@ var ppUtilApi = apiUtil$2;
1449
1454
  const fs = require$$4;
1450
1455
  const path = require$$1$1;
1451
1456
  const ppUtil$3 = require$$1.ppUtil;
1452
- const redisUtil = require$$2.redisUtil;
1457
+ const ppRedis = require$$2.ppRedis;
1453
1458
  let conf$2, err$1; // const dbCheck = require('../dbupdate/dd-version');
1454
1459
 
1455
1460
  /**
@@ -1588,8 +1593,7 @@ async function checkExEnvSetting(loadjs) {
1588
1593
 
1589
1594
  if (!msg) {
1590
1595
  delete require.cache[fileName];
1591
- const envSettingEx = loadjs(fileName);
1592
- ppUtil$3.importExEnvSetting(conf$2._envSetting, envSettingEx);
1596
+ ppUtil$3.importExEnvSetting(conf$2._envSetting, fileName, loadjs);
1593
1597
  }
1594
1598
 
1595
1599
  return msg;
@@ -1602,7 +1606,7 @@ async function checkExEnvSetting(loadjs) {
1602
1606
 
1603
1607
  async function checkRedis() {
1604
1608
  if (!conf$2.redis.enabled) return "";
1605
- const redis = redisUtil.newClient("io"); // console.log(`checkRedis begin:`);
1609
+ const redis = ppRedis.newClient("kv"); // console.log(`checkRedis begin:`);
1606
1610
 
1607
1611
  await ppUtil$3.wait(15 * 1000, param => {
1608
1612
  if (redis.ready && redis.connected || redis.error) {
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "abler-api",
3
- "version": "0.1.34",
3
+ "version": "0.1.37",
4
4
  "description": "API服务相关工具",
5
5
  "main": "./dist/cjs/pp-util.js",
6
- "module": "./dist/es/pp-util.js",
6
+ "-module": "./dist/es/pp-util.js",
7
7
  "scripts": {
8
8
  "build": "npx rollup -c rollup.config.js",
9
9
  "test": "echo \"Error: no test specified\" && exit 1"