abler-api 0.1.59 → 0.1.62
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/cjs/pp-util.js +98 -30
- package/package.json +1 -1
package/dist/cjs/pp-util.js
CHANGED
|
@@ -26,8 +26,8 @@ const crypto = require$$0__default["default"];
|
|
|
26
26
|
const getBasicAuthorization = require$$1__default["default"];
|
|
27
27
|
const ppUtil$4 = require$$2__default["default"].ppUtil;
|
|
28
28
|
const {
|
|
29
|
-
dbUtil,
|
|
30
|
-
kvStorage
|
|
29
|
+
dbUtil: dbUtil$1,
|
|
30
|
+
kvStorage: kvStorage$1
|
|
31
31
|
} = require$$3__default["default"];
|
|
32
32
|
const {
|
|
33
33
|
netUtil: netUtil$1
|
|
@@ -669,17 +669,17 @@ class apiUtil$2 {
|
|
|
669
669
|
tokenData.certPublicKey = req.certPublicKey;
|
|
670
670
|
}
|
|
671
671
|
|
|
672
|
-
await kvStorage.storeObj(token, tokenData, timeout);
|
|
672
|
+
await kvStorage$1.storeObj(token, tokenData, timeout);
|
|
673
673
|
|
|
674
674
|
if (dataId) {
|
|
675
|
-
await kvStorage.restoreValue("token_" + dataId).then(async oldToken => {
|
|
675
|
+
await kvStorage$1.restoreValue("token_" + dataId).then(async oldToken => {
|
|
676
676
|
if (oldToken !== token) {
|
|
677
|
-
await kvStorage.unstoreValue(oldToken);
|
|
677
|
+
await kvStorage$1.unstoreValue(oldToken);
|
|
678
678
|
} else {
|
|
679
679
|
dataId = "";
|
|
680
680
|
}
|
|
681
681
|
}, function (e) {}).then(async () => {
|
|
682
|
-
if (dataId !== "") await kvStorage.storeValue("token_" + dataId, token, timeout);
|
|
682
|
+
if (dataId !== "") await kvStorage$1.storeValue("token_" + dataId, token, timeout);
|
|
683
683
|
});
|
|
684
684
|
}
|
|
685
685
|
}
|
|
@@ -692,7 +692,7 @@ class apiUtil$2 {
|
|
|
692
692
|
|
|
693
693
|
|
|
694
694
|
static async restoreTokenData(accessToken, expireTime) {
|
|
695
|
-
return await kvStorage.restoreObj(accessToken, expireTime);
|
|
695
|
+
return await kvStorage$1.restoreObj(accessToken, expireTime);
|
|
696
696
|
}
|
|
697
697
|
/**
|
|
698
698
|
* 创建 API 调用记录
|
|
@@ -705,7 +705,7 @@ class apiUtil$2 {
|
|
|
705
705
|
static createApiCallRec(tokenData, req) {
|
|
706
706
|
if (!req.apiCallRec) {
|
|
707
707
|
if (req.apiCallRecId) {
|
|
708
|
-
return dbUtil.dbQueryOne(dbSql.loadApiUsage, {
|
|
708
|
+
return dbUtil$1.dbQueryOne(dbSql.loadApiUsage, {
|
|
709
709
|
replacements: {
|
|
710
710
|
id: req.apiCallRecId
|
|
711
711
|
}
|
|
@@ -780,7 +780,7 @@ class apiUtil$2 {
|
|
|
780
780
|
|
|
781
781
|
|
|
782
782
|
static async queryCompanyInfo(companyId, nullable) {
|
|
783
|
-
return await dbUtil.dbQueryOne(dbSql.queryCompanyInfo, {
|
|
783
|
+
return await dbUtil$1.dbQueryOne(dbSql.queryCompanyInfo, {
|
|
784
784
|
companyId
|
|
785
785
|
}, nullable);
|
|
786
786
|
}
|
|
@@ -799,7 +799,7 @@ class apiUtil$2 {
|
|
|
799
799
|
certSpare: null,
|
|
800
800
|
certSpareId: ''
|
|
801
801
|
};
|
|
802
|
-
return await dbUtil.dbQueryOne(dbSql.queryCertDataByOwner, {
|
|
802
|
+
return await dbUtil$1.dbQueryOne(dbSql.queryCertDataByOwner, {
|
|
803
803
|
ownerId: companyId,
|
|
804
804
|
applyId: "company"
|
|
805
805
|
}, false).then(certRec => {
|
|
@@ -810,7 +810,7 @@ class apiUtil$2 {
|
|
|
810
810
|
|
|
811
811
|
certInfo.certLiving = pubKeyData;
|
|
812
812
|
certInfo.certLivingId = certRec.id;
|
|
813
|
-
return dbUtil.dbQueryOne(dbSql.queryCertDataByOwner, {
|
|
813
|
+
return dbUtil$1.dbQueryOne(dbSql.queryCertDataByOwner, {
|
|
814
814
|
ownerId: companyId,
|
|
815
815
|
applyId: "company_spare"
|
|
816
816
|
}, false).then(certRec1 => {
|
|
@@ -930,14 +930,14 @@ class apiUtil$2 {
|
|
|
930
930
|
if (verifyOK) {
|
|
931
931
|
// 备用证书验证成功了,则将备用证书替换为正式证书
|
|
932
932
|
console.log(`公司(${tokenData.apiKey})备用证书验签成功,正式启用...`);
|
|
933
|
-
return dbUtil.dbTrans(trans => {
|
|
934
|
-
let p1 = dbUtil.dbExec(dbSql.deleteCertRecById, {
|
|
933
|
+
return dbUtil$1.dbTrans(trans => {
|
|
934
|
+
let p1 = dbUtil$1.dbExec(dbSql.deleteCertRecById, {
|
|
935
935
|
replacements: {
|
|
936
936
|
id: tokenData.certLivingId
|
|
937
937
|
},
|
|
938
938
|
transaction: trans
|
|
939
939
|
});
|
|
940
|
-
let p2 = dbUtil.dbExec(dbSql.spareCertToLiving, {
|
|
940
|
+
let p2 = dbUtil$1.dbExec(dbSql.spareCertToLiving, {
|
|
941
941
|
replacements: {
|
|
942
942
|
id: tokenData.certSpareId
|
|
943
943
|
},
|
|
@@ -1021,7 +1021,7 @@ class apiUtil$2 {
|
|
|
1021
1021
|
|
|
1022
1022
|
|
|
1023
1023
|
static tokenDataExist(token) {
|
|
1024
|
-
return kvStorage.stored(token);
|
|
1024
|
+
return kvStorage$1.stored(token);
|
|
1025
1025
|
}
|
|
1026
1026
|
|
|
1027
1027
|
static parametersOK(params) {
|
|
@@ -1572,7 +1572,12 @@ var ppUtilApi = apiUtil$2;
|
|
|
1572
1572
|
const fs = require$$5__default["default"];
|
|
1573
1573
|
const path = require$$1__default$1["default"];
|
|
1574
1574
|
const ppUtil$3 = require$$2__default["default"].ppUtil;
|
|
1575
|
-
const
|
|
1575
|
+
const {
|
|
1576
|
+
dbUtil,
|
|
1577
|
+
ppRedis,
|
|
1578
|
+
kvStorage,
|
|
1579
|
+
redisSimulator
|
|
1580
|
+
} = require$$3__default["default"];
|
|
1576
1581
|
let conf$2, err$1; // const dbCheck = require('../dbupdate/dd-version');
|
|
1577
1582
|
|
|
1578
1583
|
/**
|
|
@@ -1604,30 +1609,47 @@ class preconditions$1 {
|
|
|
1604
1609
|
return preconditions$1;
|
|
1605
1610
|
}
|
|
1606
1611
|
|
|
1607
|
-
static addChecker(checkFunc, args) {
|
|
1612
|
+
static addChecker(checkFunc, args, blocked) {
|
|
1608
1613
|
preconditions$1.checkFunctions.push({
|
|
1609
1614
|
check: checkFunc,
|
|
1610
|
-
args: args
|
|
1615
|
+
args: args,
|
|
1616
|
+
blocked: blocked
|
|
1611
1617
|
});
|
|
1612
1618
|
return preconditions$1;
|
|
1613
1619
|
}
|
|
1614
1620
|
|
|
1615
|
-
static
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1621
|
+
static pushMessage(msg) {
|
|
1622
|
+
if (msg) {
|
|
1623
|
+
if (!preconditions$1.messages) {
|
|
1624
|
+
preconditions$1.messages = [];
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
preconditions$1.messages.push(`${preconditions$1.messages.length + 1}. ${msg}`);
|
|
1619
1628
|
}
|
|
1620
1629
|
|
|
1621
|
-
|
|
1622
|
-
|
|
1630
|
+
return msg;
|
|
1631
|
+
}
|
|
1623
1632
|
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1633
|
+
static async checkAll() {
|
|
1634
|
+
// for (let i = 0; i < preconditions.checkFunctions.length; i++) {
|
|
1635
|
+
// const f = preconditions.checkFunctions[i];
|
|
1636
|
+
// // preconditions.addCheckPromise(f.check(f.args));
|
|
1637
|
+
// preconditions.pushMessage(await f.check(f.args));
|
|
1638
|
+
// }
|
|
1639
|
+
while (preconditions$1.checkFunctions.length > 0) {
|
|
1640
|
+
const f = preconditions$1.checkFunctions.shift();
|
|
1628
1641
|
|
|
1629
|
-
|
|
1642
|
+
if (preconditions$1.pushMessage(await f.check(f.args)) && f.blocked) {
|
|
1643
|
+
break;
|
|
1630
1644
|
}
|
|
1645
|
+
} // for (let i = 0; i < preconditions.checkPromises.length; i++) {
|
|
1646
|
+
// preconditions.pushMessage(await preconditions.checkPromises[i]);
|
|
1647
|
+
// }
|
|
1648
|
+
|
|
1649
|
+
|
|
1650
|
+
while (preconditions$1.checkPromises.length > 0) {
|
|
1651
|
+
const p = preconditions$1.checkPromises.shift();
|
|
1652
|
+
preconditions$1.pushMessage(await p);
|
|
1631
1653
|
}
|
|
1632
1654
|
|
|
1633
1655
|
let text = "";
|
|
@@ -1662,6 +1684,22 @@ class preconditions$1 {
|
|
|
1662
1684
|
|
|
1663
1685
|
static async checkRedis() {
|
|
1664
1686
|
return await checkRedis();
|
|
1687
|
+
}
|
|
1688
|
+
/**
|
|
1689
|
+
* 初始化数据库连接
|
|
1690
|
+
*/
|
|
1691
|
+
|
|
1692
|
+
|
|
1693
|
+
static async initDb() {
|
|
1694
|
+
return await initDb();
|
|
1695
|
+
}
|
|
1696
|
+
/**
|
|
1697
|
+
* 初始化键值对存储器
|
|
1698
|
+
*/
|
|
1699
|
+
|
|
1700
|
+
|
|
1701
|
+
static async initKvStorage(dbSql) {
|
|
1702
|
+
return await initKvStorage(dbSql);
|
|
1665
1703
|
} // /**
|
|
1666
1704
|
// * 数据库可用性及业务数据版本版本检查
|
|
1667
1705
|
// */
|
|
@@ -1709,7 +1747,7 @@ async function checkExEnvSetting(loadjs) {
|
|
|
1709
1747
|
|
|
1710
1748
|
let msg = await createEnvSettingFile(fileName, envSettingEx);
|
|
1711
1749
|
|
|
1712
|
-
if (
|
|
1750
|
+
if (msg) {
|
|
1713
1751
|
return msg;
|
|
1714
1752
|
}
|
|
1715
1753
|
|
|
@@ -1743,6 +1781,36 @@ async function checkRedis() {
|
|
|
1743
1781
|
|
|
1744
1782
|
}
|
|
1745
1783
|
|
|
1784
|
+
async function initDb() {
|
|
1785
|
+
try {
|
|
1786
|
+
dbUtil.config(conf$2, err$1);
|
|
1787
|
+
} catch (e) {
|
|
1788
|
+
if (e.reason === 'bad decrypt') {
|
|
1789
|
+
e = new Error(`解密数据库密码(${conf$2.dbconn.dbpwd})失败`);
|
|
1790
|
+
} // if (e.reason === 'bad decrypt') {
|
|
1791
|
+
// e = new Error(`解密Redis密码(${conf.redis.password})失败`);
|
|
1792
|
+
// }
|
|
1793
|
+
|
|
1794
|
+
|
|
1795
|
+
return `初始化数据库连接失败(${e.message})`;
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
|
|
1799
|
+
async function initKvStorage(dbSql) {
|
|
1800
|
+
try {
|
|
1801
|
+
kvStorage.config(conf$2, err$1);
|
|
1802
|
+
|
|
1803
|
+
if (!conf$2.redis.enabled) {
|
|
1804
|
+
kvStorage.setRedis(new redisSimulator(dbSql));
|
|
1805
|
+
}
|
|
1806
|
+
} catch (e) {
|
|
1807
|
+
// if (e.reason === 'bad decrypt') {
|
|
1808
|
+
// e = new Error(`解密Redis密码(${conf.redis.password})失败`);
|
|
1809
|
+
// }
|
|
1810
|
+
return `初始化键值对存储器失败(${e.message})`;
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
|
|
1746
1814
|
var ppPrecond = preconditions$1;
|
|
1747
1815
|
|
|
1748
1816
|
// 若 redis 可用,则使用基于 redis 的消息订阅发布系统
|