From fe3c2331f2a7e92e7f883f7a66072de3497aec53 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Thu, 27 Aug 2020 12:53:06 -0400 Subject: [PATCH 1/7] gun playground --- guntest.html | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 guntest.html diff --git a/guntest.html b/guntest.html new file mode 100644 index 00000000..1671aa1b --- /dev/null +++ b/guntest.html @@ -0,0 +1,63 @@ + + + + + + + Document + + + + + + + + + + + + + + + + \ No newline at end of file From f6f681c0a14a708e1a2ffc9b0641e6f8495748d6 Mon Sep 17 00:00:00 2001 From: hatim boufnichel Date: Thu, 27 Aug 2020 20:06:57 +0200 Subject: [PATCH 2/7] send payment try catch --- src/routes.js | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/src/routes.js b/src/routes.js index f7657e9d..ad478e25 100644 --- a/src/routes.js +++ b/src/routes.js @@ -1507,36 +1507,41 @@ module.exports = async ( }) } - if (keysend) { - const { dest, amt, finalCltvDelta = 40 } = req.body - if (!dest || !amt) { - return res.status(400).json({ - errorMessage: 'please provide "dest" and "amt" for keysend payments' - }) - } + try { + if (keysend) { + const { dest, amt, finalCltvDelta = 40 } = req.body + if (!dest || !amt) { + return res.status(400).json({ + errorMessage: 'please provide "dest" and "amt" for keysend payments' + }) + } - const payment = await sendPaymentV2Keysend({ - amt, - dest, + const payment = await sendPaymentV2Keysend({ + amt, + dest, + feeLimit, + finalCltvDelta, + maxParts, + timeoutSeconds + }) + + return res.status(200).json(payment) + } + const { payreq } = req.body + + const payment = await sendPaymentV2Invoice({ feeLimit, - finalCltvDelta, - maxParts, + payment_request: payreq, + amt: req.body.amt, + max_parts: maxParts, timeoutSeconds }) return res.status(200).json(payment) + } catch (e) { + logger.error(e) + return res.status(500).json({ errorMessage: e }) } - const { payreq } = req.body - - const payment = await sendPaymentV2Invoice({ - feeLimit, - payment_request: payreq, - amt: req.body.amt, - max_parts: maxParts, - timeoutSeconds - }) - - return res.status(200).json(payment) }) app.post('/api/lnd/trackpayment', (req, res) => { From c13a33f3df5309650e115395c55a4f4a84695810 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Thu, 27 Aug 2020 14:46:00 -0400 Subject: [PATCH 3/7] upgrade deps --- package.json | 4 +- yarn.lock | 105 +++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 96 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index e44df199..40b1f6d5 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "request-promise": "^4.2.2", "response-time": "^2.3.2", "shelljs": "^0.8.2", - "shock-common": "4.0.1", + "shock-common": "6.0.0", "socket.io": "2.1.1", "text-encoding": "^0.7.0", "tingodb": "^0.6.1", @@ -79,7 +79,7 @@ "nodemon": "^1.19.3", "prettier": "^1.18.2", "ts-type": "^1.2.16", - "typescript": "^3.9.6" + "typescript": "^4.0.2" }, "lint-staged": { "*.js": [ diff --git a/yarn.lock b/yarn.lock index 4f4343d6..81652516 100644 --- a/yarn.lock +++ b/yarn.lock @@ -156,6 +156,13 @@ dependencies: "@babel/helper-plugin-utils" "^7.0.0" +"@babel/runtime@^7.6.3": + version "7.11.2" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.11.2.tgz#f549c13c754cc40b87644b9fa9f09a6a95fe0736" + integrity sha512-TeWkU52so0mPtDcaCTxNBI/IHiz0pZgr8VEFqXFtZWpYD08ZB6FaSwVAS8MKRQAP3bYKiVjwysOJgMFY28o6Tw== + dependencies: + regenerator-runtime "^0.13.4" + "@babel/template@^7.1.0", "@babel/template@^7.4.0", "@babel/template@^7.6.0": version "7.6.0" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.6.0.tgz#7f0159c7f5012230dad64cca42ec9bdb5c9536e6" @@ -467,6 +474,50 @@ resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570" integrity sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA= +"@redux-saga/core@^1.1.3": + version "1.1.3" + resolved "https://registry.yarnpkg.com/@redux-saga/core/-/core-1.1.3.tgz#3085097b57a4ea8db5528d58673f20ce0950f6a4" + integrity sha512-8tInBftak8TPzE6X13ABmEtRJGjtK17w7VUs7qV17S8hCO5S3+aUTWZ/DBsBJPdE8Z5jOPwYALyvofgq1Ws+kg== + dependencies: + "@babel/runtime" "^7.6.3" + "@redux-saga/deferred" "^1.1.2" + "@redux-saga/delay-p" "^1.1.2" + "@redux-saga/is" "^1.1.2" + "@redux-saga/symbols" "^1.1.2" + "@redux-saga/types" "^1.1.0" + redux "^4.0.4" + typescript-tuple "^2.2.1" + +"@redux-saga/deferred@^1.1.2": + version "1.1.2" + resolved "https://registry.yarnpkg.com/@redux-saga/deferred/-/deferred-1.1.2.tgz#59937a0eba71fff289f1310233bc518117a71888" + integrity sha512-908rDLHFN2UUzt2jb4uOzj6afpjgJe3MjICaUNO3bvkV/kN/cNeI9PMr8BsFXB/MR8WTAZQq/PlTq8Kww3TBSQ== + +"@redux-saga/delay-p@^1.1.2": + version "1.1.2" + resolved "https://registry.yarnpkg.com/@redux-saga/delay-p/-/delay-p-1.1.2.tgz#8f515f4b009b05b02a37a7c3d0ca9ddc157bb355" + integrity sha512-ojc+1IoC6OP65Ts5+ZHbEYdrohmIw1j9P7HS9MOJezqMYtCDgpkoqB5enAAZrNtnbSL6gVCWPHaoaTY5KeO0/g== + dependencies: + "@redux-saga/symbols" "^1.1.2" + +"@redux-saga/is@^1.1.2": + version "1.1.2" + resolved "https://registry.yarnpkg.com/@redux-saga/is/-/is-1.1.2.tgz#ae6c8421f58fcba80faf7cadb7d65b303b97e58e" + integrity sha512-OLbunKVsCVNTKEf2cH4TYyNbbPgvmZ52iaxBD4I1fTif4+MTXMa4/Z07L83zW/hTCXwpSZvXogqMqLfex2Tg6w== + dependencies: + "@redux-saga/symbols" "^1.1.2" + "@redux-saga/types" "^1.1.0" + +"@redux-saga/symbols@^1.1.2": + version "1.1.2" + resolved "https://registry.yarnpkg.com/@redux-saga/symbols/-/symbols-1.1.2.tgz#216a672a487fc256872b8034835afc22a2d0595d" + integrity sha512-EfdGnF423glv3uMwLsGAtE6bg+R9MdqlHEzExnfagXPrIiuxwr3bdiAwz3gi+PsrQ3yBlaBpfGLtDG8rf3LgQQ== + +"@redux-saga/types@^1.1.0": + version "1.1.0" + resolved "https://registry.yarnpkg.com/@redux-saga/types/-/types-1.1.0.tgz#0e81ce56b4883b4b2a3001ebe1ab298b84237204" + integrity sha512-afmTuJrylUU/0OtqzaRkbyYFFNgCF73Bvel/sw90pvGrWIZ+vyoIJqA6eMSoA6+nb443kTmulmBtC9NerXboNg== + "@samverschueren/stream-to-observable@^0.3.0": version "0.3.0" resolved "https://registry.yarnpkg.com/@samverschueren/stream-to-observable/-/stream-to-observable-0.3.0.tgz#ecdf48d532c58ea477acfcab80348424f8d0662f" @@ -4358,7 +4409,7 @@ lodash@=4.17.4: resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" integrity sha1-eCA6TRwyiuHYbcpkYONptX9AVa4= -lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.20, lodash@^4.17.4, lodash@^4.17.5: +lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.4, lodash@^4.17.5: version "4.17.20" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52" integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA== @@ -5556,12 +5607,19 @@ rechoir@^0.6.2: dependencies: resolve "^1.1.6" +redux-saga@^1.1.3: + version "1.1.3" + resolved "https://registry.yarnpkg.com/redux-saga/-/redux-saga-1.1.3.tgz#9f3e6aebd3c994bbc0f6901a625f9a42b51d1112" + integrity sha512-RkSn/z0mwaSa5/xH/hQLo8gNf4tlvT18qXDNvedihLcfzh+jMchDgaariQoehCpgRltEm4zHKJyINEz6aqswTw== + dependencies: + "@redux-saga/core" "^1.1.3" + redux-thunk@^2.3.0: version "2.3.0" resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.3.0.tgz#51c2c19a185ed5187aaa9a2d08b666d0d6467622" integrity sha512-km6dclyFnmcvxhAcrQV2AkZmPQjzPDjgVlQtR0EQjxZPyJ0BnMf3in1ryuR8A2qU0HldVRfxYXbFSKlI3N7Slw== -redux@^4.0.5: +redux@^4.0.4, redux@^4.0.5: version "4.0.5" resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.5.tgz#4db5de5816e17891de8a80c424232d06f051d93f" integrity sha512-VSz1uMAH24DM6MF72vcojpYPtrTUu3ByVWfPL1nPfVRb5mZVTve5GnNCUV53QM/BZ66xfWrm0CTWoM+Xlz8V1w== @@ -5574,6 +5632,11 @@ regenerator-runtime@^0.11.0: resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9" integrity sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg== +regenerator-runtime@^0.13.4: + version "0.13.7" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.7.tgz#cac2dacc8a1ea675feaabaeb8ae833898ae46f55" + integrity sha512-a54FxoJDIr27pgf7IgeQGxmqUNYrcV338lf/6gH456HZ/PhX+5BcwHXG9ajESmwe6WRO0tAzRUrRmNONWgkrew== + regex-not@^1.0.0, regex-not@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/regex-not/-/regex-not-1.0.2.tgz#1f4ece27e00b0b65e0247a6810e6a85d83a5752c" @@ -5950,15 +6013,16 @@ shellwords@^0.1.1: resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b" integrity sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww== -shock-common@4.0.1: - version "4.0.1" - resolved "https://registry.yarnpkg.com/shock-common/-/shock-common-4.0.1.tgz#035e7081b6e67f6721e68dcc6b4d1e4c8f2cd96d" - integrity sha512-3xAkG8lyfyZHK8trgOy2aN75uG1ZBm0MPoIEzP4hgXhyT/b80WmQzX3DqVSSmjfhq1Di0sjmNCY7O5Nf6cEmFg== +shock-common@6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/shock-common/-/shock-common-6.0.0.tgz#77701dabb344830046b85ece0103de21775197b9" + integrity sha512-kbSkLTtWTK8qVcbW6uViWtar3otW2S5oJIMO/1twPs6Iuv9ATF0QviDtUiU1YN/Y4bX/SXAMm/jRZ3OJ3PLyUA== dependencies: immer "^6.0.6" - lodash "^4.17.15" + lodash "^4.17.19" normalizr "^3.6.0" redux "^4.0.5" + redux-saga "^1.1.3" redux-thunk "^2.3.0" uuid "3.x.x" @@ -6654,10 +6718,29 @@ typedarray-dts@^1.0.0: resolved "https://registry.yarnpkg.com/typedarray-dts/-/typedarray-dts-1.0.0.tgz#9dec9811386dbfba964c295c2606cf9a6b982d06" integrity sha512-Ka0DBegjuV9IPYFT1h0Qqk5U4pccebNIJCGl8C5uU7xtOs+jpJvKGAY4fHGK25hTmXZOEUl9Cnsg5cS6K/b5DA== -typescript@^3.9.6: - version "3.9.6" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.6.tgz#8f3e0198a34c3ae17091b35571d3afd31999365a" - integrity sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw== +typescript-compare@^0.0.2: + version "0.0.2" + resolved "https://registry.yarnpkg.com/typescript-compare/-/typescript-compare-0.0.2.tgz#7ee40a400a406c2ea0a7e551efd3309021d5f425" + integrity sha512-8ja4j7pMHkfLJQO2/8tut7ub+J3Lw2S3061eJLFQcvs3tsmJKp8KG5NtpLn7KcY2w08edF74BSVN7qJS0U6oHA== + dependencies: + typescript-logic "^0.0.0" + +typescript-logic@^0.0.0: + version "0.0.0" + resolved "https://registry.yarnpkg.com/typescript-logic/-/typescript-logic-0.0.0.tgz#66ebd82a2548f2b444a43667bec120b496890196" + integrity sha512-zXFars5LUkI3zP492ls0VskH3TtdeHCqu0i7/duGt60i5IGPIpAHE/DWo5FqJ6EjQ15YKXrt+AETjv60Dat34Q== + +typescript-tuple@^2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/typescript-tuple/-/typescript-tuple-2.2.1.tgz#7d9813fb4b355f69ac55032e0363e8bb0f04dad2" + integrity sha512-Zcr0lbt8z5ZdEzERHAMAniTiIKerFCMgd7yjq1fPnDJ43et/k9twIFQMUYff9k5oXcsQ0WpvFcgzK2ZKASoW6Q== + dependencies: + typescript-compare "^0.0.2" + +typescript@^4.0.2: + version "4.0.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.2.tgz#7ea7c88777c723c681e33bf7988be5d008d05ac2" + integrity sha512-e4ERvRV2wb+rRZ/IQeb3jm2VxBsirQLpQhdxplZ2MEzGvDkkMmPglecnNDfSUBivMjP93vRbngYYDQqQ/78bcQ== uglify-js@^3.1.4: version "3.6.0" From a5d767638b1771d8792f8f5053a756f402866b39 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Thu, 27 Aug 2020 15:31:41 -0400 Subject: [PATCH 4/7] correctly catch err message --- src/routes.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/routes.js b/src/routes.js index ad478e25..eab259dd 100644 --- a/src/routes.js +++ b/src/routes.js @@ -1539,8 +1539,12 @@ module.exports = async ( return res.status(200).json(payment) } catch (e) { + let msg = 'Unknown Error' + + if (e.message) msg = e.message + logger.error(e) - return res.status(500).json({ errorMessage: e }) + return res.status(500).json({ errorMessage: msg }) } }) From 873d9f5b74f16058fc55fe366651da36a1ae5373 Mon Sep 17 00:00:00 2001 From: hatim boufnichel Date: Thu, 27 Aug 2020 21:38:24 +0200 Subject: [PATCH 5/7] ts ignores --- services/gunDB/contact-api/actions.js | 5 +++++ services/gunDB/contact-api/getters/feed.js | 4 +++- services/gunDB/contact-api/getters/index.js | 5 +++-- services/gunDB/contact-api/getters/user.js | 10 ++++++---- services/gunDB/contact-api/getters/wall.js | 6 ++++-- services/gunDB/contact-api/jobs/onOrders.js | 2 ++ services/gunDB/contact-api/streams/index.js | 1 + services/gunDB/contact-api/streams/pubToFeed.js | 2 +- 8 files changed, 25 insertions(+), 10 deletions(-) diff --git a/services/gunDB/contact-api/actions.js b/services/gunDB/contact-api/actions.js index b64887a8..39f5e1b9 100644 --- a/services/gunDB/contact-api/actions.js +++ b/services/gunDB/contact-api/actions.js @@ -74,6 +74,7 @@ const __createOutgoingFeed = async (withPublicKey, user, SEA) => { const newOutgoingFeedID = await new Promise((res, rej) => { const _outFeedNode = user .get(Key.OUTGOINGS) + //@ts-ignore .set(newPartialOutgoingFeed, ack => { if (ack.err && typeof ack.err !== 'number') { rej(new Error(ack.err)) @@ -98,6 +99,7 @@ const __createOutgoingFeed = async (withPublicKey, user, SEA) => { .get(Key.OUTGOINGS) .get(newOutgoingFeedID) .get(Key.MESSAGES) + //@ts-ignore .set(initialMsg, ack => { if (ack.err && typeof ack.err !== 'number') { rej(new Error(ack.err)) @@ -591,6 +593,7 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => { const hr = gun .get(Key.HANDSHAKE_NODES) .get(currentHandshakeAddress) + //@ts-ignore .set(handshakeRequestData, ack => { if (ack.err && typeof ack.err !== 'number') { rej(new Error(`Error trying to create request: ${ack.err}`)) @@ -627,6 +630,7 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => { } await new Promise((res, rej) => { + //@ts-ignore user.get(Key.STORED_REQS).set(storedReq, ack => { if (ack.err && typeof ack.err !== 'number') { rej( @@ -959,6 +963,7 @@ const sendSpontaneousPayment = async (to, amount, memo, feeLimit) => { .getGun() .get(Key.ORDER_NODES) .get(currOrderAddress) + //@ts-ignore .set(order, ack => { if (ack.err && typeof ack.err !== 'number') { rej( diff --git a/services/gunDB/contact-api/getters/feed.js b/services/gunDB/contact-api/getters/feed.js index 22e160a7..ba4704ce 100644 --- a/services/gunDB/contact-api/getters/feed.js +++ b/services/gunDB/contact-api/getters/feed.js @@ -1,6 +1,7 @@ /** * @format */ +//@ts-ignore const Common = require('shock-common') const isFinite = require('lodash/isFinite') const shuffle = require('lodash/shuffle') @@ -29,8 +30,9 @@ const calculateWallRequest = (numberOfPublicKeyGroups, pageRequested) => { * @param {number} page * @throws {TypeError} * @throws {RangeError} - * @returns {Promise} + * @returns {Promise} */ +//@returns {Promise} const getFeedPage = async page => { if (!isFinite(page)) { throw new TypeError(`Please provide an actual number for [page]`) diff --git a/services/gunDB/contact-api/getters/index.js b/services/gunDB/contact-api/getters/index.js index 4472ed41..c8811e45 100644 --- a/services/gunDB/contact-api/getters/index.js +++ b/services/gunDB/contact-api/getters/index.js @@ -47,8 +47,9 @@ exports.userToIncomingID = async pub => { } /** - * @returns {Promise} + * @returns {Promise} */ +//@returns {Promise} const getMyUser = async () => { const oldProfile = await Utils.tryAndWait( (_, user) => new Promise(res => user.get(Key.PROFILE).load(res)), @@ -85,7 +86,7 @@ const getMyUser = async () => { (_, user) => Promise.resolve(user.is && user.is.pub), v => typeof v !== 'string' ) - + //@ts-ignore /** @type {Common.SchemaTypes.User} */ const u = { avatar: oldProfile.avatar, diff --git a/services/gunDB/contact-api/getters/user.js b/services/gunDB/contact-api/getters/user.js index 52d04e72..f560d65c 100644 --- a/services/gunDB/contact-api/getters/user.js +++ b/services/gunDB/contact-api/getters/user.js @@ -9,8 +9,9 @@ const Utils = require('../utils') /** * @param {string} publicKey - * @returns {Promise} + * @returns {Promise} */ +//@returns {Promise} const getAnUser = async publicKey => { const oldProfile = await Utils.tryAndWait( (g, u) => { @@ -47,7 +48,7 @@ const getAnUser = async publicKey => { }, v => typeof v !== 'number' ) - + //@ts-ignore /** @type {Common.SchemaTypes.User} */ const u = { avatar: oldProfile.avatar || null, @@ -68,8 +69,9 @@ const getAnUser = async publicKey => { module.exports.getAnUser = getAnUser /** - * @returns {Promise} + * @returns {Promise} */ +//@returns {Promise} const getMyUser = async () => { const oldProfile = await Utils.tryAndWait( (_, user) => new Promise(res => user.get(Key.PROFILE).load(res)), @@ -106,7 +108,7 @@ const getMyUser = async () => { (_, user) => Promise.resolve(user.is && user.is.pub), v => typeof v !== 'string' ) - + //@ts-ignore /** @type {Common.SchemaTypes.User} */ const u = { avatar: oldProfile.avatar, diff --git a/services/gunDB/contact-api/getters/wall.js b/services/gunDB/contact-api/getters/wall.js index 879ec97b..96c7fd70 100644 --- a/services/gunDB/contact-api/getters/wall.js +++ b/services/gunDB/contact-api/getters/wall.js @@ -43,8 +43,9 @@ const getWallTotalPages = async publicKey => { * @param {string=} publicKey * @throws {TypeError} * @throws {RangeError} - * @returns {Promise} + * @returns {Promise} */ +////@returns {Promise} const getWallPage = async (page, publicKey) => { const totalPages = await getWallTotalPages(publicKey) @@ -103,9 +104,10 @@ const getWallPage = async (page, publicKey) => { */ const mockUser = await User.getMyUser() - /** + /* * @type {Common.SchemaTypes.WallPage} */ + //@ts-ignore const thePage = await Utils.tryAndWait( (g, u) => { /** diff --git a/services/gunDB/contact-api/jobs/onOrders.js b/services/gunDB/contact-api/jobs/onOrders.js index 840526f2..b7c3e43b 100644 --- a/services/gunDB/contact-api/jobs/onOrders.js +++ b/services/gunDB/contact-api/jobs/onOrders.js @@ -154,6 +154,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => { getUser() .get(Key.ORDER_TO_RESPONSE) .get(orderID) + //@ts-ignore .put(orderResponse, ack => { if (ack.err && typeof ack.err !== 'number') { rej( @@ -183,6 +184,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => { getUser() .get(Key.ORDER_TO_RESPONSE) .get(orderID) + //@ts-ignore .put(orderResponse, ack => { if (ack.err && typeof ack.err !== 'number') { logger.error( diff --git a/services/gunDB/contact-api/streams/index.js b/services/gunDB/contact-api/streams/index.js index a76fecbf..d4fab683 100644 --- a/services/gunDB/contact-api/streams/index.js +++ b/services/gunDB/contact-api/streams/index.js @@ -151,6 +151,7 @@ const onStoredReqs = cb => { .get(Key.STORED_REQS) .open(d => { if (typeof d === 'object' && d !== null) { + //@ts-ignore encryptedStoredReqs = /** @type {StoredRequest[]} */ (Object.values( d ).filter(i => Schema.isStoredRequest(i))) diff --git a/services/gunDB/contact-api/streams/pubToFeed.js b/services/gunDB/contact-api/streams/pubToFeed.js index f6f96cc4..f140aaea 100644 --- a/services/gunDB/contact-api/streams/pubToFeed.js +++ b/services/gunDB/contact-api/streams/pubToFeed.js @@ -98,7 +98,7 @@ const onOpenForPubFeedPair = ([pub, feed]) => }) return } - + //@ts-ignore const incoming = /** @type {import('shock-common').Schema.Outgoing} */ (data) // incomplete data, let's not assume anything From 90755ae0a114348ccde50003aa38d59d78e58474 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Thu, 27 Aug 2020 15:57:54 -0400 Subject: [PATCH 6/7] respect NOT_AUTH constnat --- services/gunDB/Mediator/index.js | 2 +- .../contact-api/streams/lastSentReqID.js | 3 +- services/gunDB/contact-api/utils/index.js | 6 +-- src/routes.js | 40 ++++++++++++------- 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/services/gunDB/Mediator/index.js b/services/gunDB/Mediator/index.js index bb590285..d6c93292 100644 --- a/services/gunDB/Mediator/index.js +++ b/services/gunDB/Mediator/index.js @@ -246,7 +246,7 @@ const getGun = () => { const getUser = () => { if (!user.is) { logger.warn('called getUser() without being authed') - throw new Error('NOT_AUTH') + throw new Error(Constants.ErrorCode.NOT_AUTH) } return user } diff --git a/services/gunDB/contact-api/streams/lastSentReqID.js b/services/gunDB/contact-api/streams/lastSentReqID.js index 01cce49d..431adb58 100644 --- a/services/gunDB/contact-api/streams/lastSentReqID.js +++ b/services/gunDB/contact-api/streams/lastSentReqID.js @@ -1,5 +1,6 @@ /** @format */ const logger = require('winston') +const { Constants } = require('shock-common') const Key = require('../key') @@ -23,7 +24,7 @@ const onLastSentReqIDs = cb => { const user = require('../../Mediator').getUser() if (!user.is) { logger.warn('lastSentReqID() -> tried to sub without authing') - throw new Error('NOT_AUTH') + throw new Error(Constants.ErrorCode.NOT_AUTH) } user.get(Key.USER_TO_LAST_REQUEST_SENT).open(data => { diff --git a/services/gunDB/contact-api/utils/index.js b/services/gunDB/contact-api/utils/index.js index a35bbea5..bafa0378 100644 --- a/services/gunDB/contact-api/utils/index.js +++ b/services/gunDB/contact-api/utils/index.js @@ -129,7 +129,7 @@ const tryAndWait = async (promGen, shouldRetry = () => false) => { } catch (e) { logger.error(e) logger.info(JSON.stringify(e)) - if (e.message === 'NOT_AUTH') { + if (e.message === Constants.ErrorCode.NOT_AUTH) { throw e } } @@ -159,7 +159,7 @@ const tryAndWait = async (promGen, shouldRetry = () => false) => { } } catch (e) { logger.error(e) - if (e.message === 'NOT_AUTH') { + if (e.message === Constants.ErrorCode.NOT_AUTH) { throw e } } @@ -189,7 +189,7 @@ const tryAndWait = async (promGen, shouldRetry = () => false) => { } } catch (e) { logger.error(e) - if (e.message === 'NOT_AUTH') { + if (e.message === Constants.ErrorCode.NOT_AUTH) { throw e } } diff --git a/src/routes.js b/src/routes.js index eab259dd..3701a119 100644 --- a/src/routes.js +++ b/src/routes.js @@ -1944,9 +1944,11 @@ module.exports = async ( } catch (err) { logger.info('Error in Chats poll:') logger.error(err) - res.status(err.message === 'NON_AUTH' ? 401 : 500).json({ - errorMessage: typeof err === 'string' ? err : err.message - }) + res + .status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500) + .json({ + errorMessage: typeof err === 'string' ? err : err.message + }) } }) @@ -1966,9 +1968,11 @@ module.exports = async ( } catch (err) { logger.info('Error in Avatar poll:') logger.error(err) - res.status(err.message === 'NON_AUTH' ? 401 : 500).json({ - errorMessage: typeof err === 'string' ? err : err.message - }) + res + .status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500) + .json({ + errorMessage: typeof err === 'string' ? err : err.message + }) } }) @@ -1988,9 +1992,11 @@ module.exports = async ( } catch (err) { logger.info('Error in Display Name poll:') logger.error(err) - res.status(err.message === 'NON_AUTH' ? 401 : 500).json({ - errorMessage: typeof err === 'string' ? err : err.message - }) + res + .status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500) + .json({ + errorMessage: typeof err === 'string' ? err : err.message + }) } }) @@ -2007,9 +2013,11 @@ module.exports = async ( } catch (err) { logger.info('Error in Handshake Address poll:') logger.error(err) - res.status(err.message === 'NON_AUTH' ? 401 : 500).json({ - errorMessage: typeof err === 'string' ? err : err.message - }) + res + .status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500) + .json({ + errorMessage: typeof err === 'string' ? err : err.message + }) } }) @@ -2024,9 +2032,11 @@ module.exports = async ( } catch (err) { logger.info('Error in BIO poll:') logger.error(err) - res.status(err.message === 'NON_AUTH' ? 401 : 500).json({ - errorMessage: typeof err === 'string' ? err : err.message - }) + res + .status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500) + .json({ + errorMessage: typeof err === 'string' ? err : err.message + }) } }) //////////////////////////////////////////////////////////////////////////////// From e628117b967fe6bccbb4c33643b54bbf870f7f2d Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Thu, 27 Aug 2020 15:48:57 -0400 Subject: [PATCH 7/7] cleaner logs, correct route log --- services/auth/auth.js | 2 +- src/routes.js | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/services/auth/auth.js b/services/auth/auth.js index e9327fde..5e2add5e 100644 --- a/services/auth/auth.js +++ b/services/auth/auth.js @@ -65,7 +65,7 @@ class Auth { logger.info('validateToken err', err) reject(err) } else { - logger.info('decoded', decoded) + // logger.info('decoded', decoded) resolve({ valid: true }) } }) diff --git a/src/routes.js b/src/routes.js index 3701a119..65fc1a68 100644 --- a/src/routes.js +++ b/src/routes.js @@ -327,7 +327,7 @@ module.exports = async ( }) app.use(async (req, res, next) => { - logger.info('Route:', req.path) + logger.info(`Route: ${req.path}`) if (unprotectedRoutes[req.method][req.path]) { next() } else { @@ -1937,7 +1937,6 @@ module.exports = async ( app.get(`/api/gun/${GunEvent.ON_CHATS}`, (_, res) => { try { const data = Events.getChats() - logger.info(`Chats polled: ${data.length}`) res.json({ data }) @@ -1961,7 +1960,6 @@ module.exports = async ( .get(Key.AVATAR) .then() ) - logger.info(`avatar poll:${(data || '').length} chars`) res.json({ data }) @@ -1985,7 +1983,6 @@ module.exports = async ( .get(Key.DISPLAY_NAME) .then() ) - logger.info(`display name poll:${data}`) res.json({ data }) @@ -2006,7 +2003,6 @@ module.exports = async ( const data = await timeout5( user.get(Key.CURRENT_HANDSHAKE_ADDRESS).then() ) - logger.info(`handshake address poll:${data}`) res.json({ data })