From e7bcc28f49e4eac79baaa98e8322a412f2fea2c0 Mon Sep 17 00:00:00 2001 From: Adhidarma Hadiwinoto <me@adhisimon.org> Date: Tue, 6 Aug 2024 14:48:34 +0700 Subject: [PATCH] Use await on calling axios at webhook-sender --- lib/webhook-sender.js | 7 ++++--- package-lock.json | 20 ++++++++++++-------- package.json | 2 +- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/webhook-sender.js b/lib/webhook-sender.js index 098f637..a2d74c2 100644 --- a/lib/webhook-sender.js +++ b/lib/webhook-sender.js @@ -20,7 +20,7 @@ const baseDumpDir = path.join('dump', 'webhook-sender'); if (!fs.existsSync(baseDumpDir)) { fs.mkdirSync(baseDumpDir, { recursive: true }); } -const lastDumpFileName = path.join(baseDumpDir, 'last'); +const lastDumpFileName = path.join(baseDumpDir, 'last.json'); const sleepMs = (ms) => new Promise((resolve) => { setTimeout(() => { @@ -34,8 +34,9 @@ const dumper = async (xid, webhookType, body) => { } try { + const filename = [moment().format('YYYYMMDD-HHmmssSSS'), xid].join('_'); await fs.promises.writeFile( - path.join(baseDumpDir, [moment().format('YYYYMMDD-HHmmssSSS'), xid].join('_')), + path.join(baseDumpDir, `${filename}.json`), stringify({ webhookType, body }), ); @@ -66,7 +67,7 @@ const sender = async (xid, webhookType, body, retry) => { request_id: body.request_id, }); - axios.post(config.listener.partner.webhook, { + await axios.post(config.listener.partner.webhook, { webhookType, body, }); diff --git a/package-lock.json b/package-lock.json index f95689e..a297005 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.18.6", "license": "ISC", "dependencies": { - "axios": "^1.7.2", + "axios": "^1.7.3", "express": "^4.17.1", "express-rate-limit": "^6.6.0", "join-path": "^1.1.1", @@ -306,9 +306,10 @@ "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==" }, "node_modules/axios": { - "version": "1.7.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", - "integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==", + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.3.tgz", + "integrity": "sha512-Ar7ND9pU99eJ9GpoGQKhKf58GpUOgnzuaB7ueNQ5BMi0p+LZ5oaEnfF999fAArcTIBwXTCHAmGcHOZJaWPq9Nw==", + "license": "MIT", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -319,6 +320,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "license": "MIT", "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -1467,6 +1469,7 @@ "url": "https://github.com/sponsors/RubenVerborgh" } ], + "license": "MIT", "engines": { "node": ">=4.0" }, @@ -3318,7 +3321,8 @@ "node_modules/proxy-from-env": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "license": "MIT" }, "node_modules/pseudomap": { "version": "1.0.2", @@ -4893,9 +4897,9 @@ "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==" }, "axios": { - "version": "1.7.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", - "integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==", + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.3.tgz", + "integrity": "sha512-Ar7ND9pU99eJ9GpoGQKhKf58GpUOgnzuaB7ueNQ5BMi0p+LZ5oaEnfF999fAArcTIBwXTCHAmGcHOZJaWPq9Nw==", "requires": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", diff --git a/package.json b/package.json index 757e452..d5973c8 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "should": "^13.2.3" }, "dependencies": { - "axios": "^1.7.2", + "axios": "^1.7.3", "express": "^4.17.1", "express-rate-limit": "^6.6.0", "join-path": "^1.1.1", -- 1.9.0