-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #265 from bitfinexcom/beta
Release version to master
- Loading branch information
Showing
25 changed files
with
591 additions
and
56 deletions.
There are no files selected for viewing
Submodule bfx-report-ui
updated
43 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict' | ||
|
||
const { | ||
AuthError | ||
} = require('bfx-report/workers/loc.api/errors') | ||
|
||
const isAuthApiError = (err) => { | ||
return /ERR_AUTH_API/.test(err.toString()) | ||
} | ||
|
||
const makeRequestToBFX = async (requestFn) => { | ||
try { | ||
return await requestFn() | ||
} catch (err) { | ||
if (isAuthApiError(err)) { | ||
throw new AuthError() | ||
} | ||
|
||
throw err | ||
} | ||
} | ||
|
||
module.exports = { | ||
isAuthApiError, | ||
makeRequestToBFX | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'use strict' | ||
|
||
const { RESTv2 } = require('bfx-api-node-rest') | ||
|
||
const { | ||
makeRequestToBFX | ||
} = require('./helpers') | ||
|
||
const { decorateInjectable } = require('../di/utils') | ||
|
||
const depsTypes = (TYPES) => [ | ||
TYPES.CONF | ||
] | ||
class HTTPRequest { | ||
constructor ( | ||
conf | ||
) { | ||
this.conf = conf | ||
|
||
this._TEST_REST_URL = 'http://localhost:9999' | ||
this._isTestEnv = process.env.NODE_ENV === 'test' | ||
|
||
this._transportCache = new Map() | ||
this.getRequest() // Init default cache | ||
} | ||
|
||
getRequest (opts = {}) { | ||
const key = JSON.stringify(opts) | ||
|
||
const _opts = { | ||
transform: true, | ||
url: this._isTestEnv | ||
? this._TEST_REST_URL | ||
: this.conf?.restUrl, | ||
...opts | ||
} | ||
|
||
if (this._transportCache.has(key)) { | ||
return this._transportCache.get(key) | ||
} | ||
|
||
const rest = new ExpandedRESTv2(_opts) | ||
this._transportCache.set(key, rest) | ||
|
||
return rest | ||
} | ||
} | ||
|
||
class ExpandedRESTv2 extends RESTv2 { | ||
async login (body) { | ||
return makeRequestToBFX(() => this | ||
._makePublicPostRequest('/login', body)) | ||
} | ||
|
||
async verify (body) { | ||
return makeRequestToBFX(() => this | ||
._makePublicPostRequest('/login/verify', body)) | ||
} | ||
} | ||
|
||
decorateInjectable(HTTPRequest, depsTypes) | ||
|
||
module.exports = HTTPRequest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.