Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release version to master #265

Merged
merged 42 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
cdedfcf
Add user flags isSyncOnStartupRequired to model
ZIMkaRU Mar 9, 2023
ab79efc
Bump db version up to 33
ZIMkaRU Mar 9, 2023
7244245
Add ability to pick session isSyncOnStartupRequired prop
ZIMkaRU Mar 9, 2023
bf8f072
Add ability to get user session for data inserter
ZIMkaRU Mar 9, 2023
5051426
Match ledgers balances hook with getting auth
ZIMkaRU Mar 9, 2023
57e69dc
Set user sync state after successful sync
ZIMkaRU Mar 9, 2023
aa507a1
Return isSyncOnStartupRequired flags on sign-in
ZIMkaRU Mar 10, 2023
14c9f22
Launch sync on sign-in if required
ZIMkaRU Mar 10, 2023
6f276f5
Add ability to update user
ZIMkaRU Mar 10, 2023
b287393
Fix isRestrictedToBeAddedToSubAccount flag
ZIMkaRU Mar 13, 2023
32868dc
Add UserUpdatingError class
ZIMkaRU Mar 13, 2023
d58c871
Improve updateUser method
ZIMkaRU Mar 13, 2023
79194b9
Add updateUser endpoint
ZIMkaRU Mar 13, 2023
cfaeae8
Fix setting user sync state after syncing
ZIMkaRU Mar 14, 2023
a7e5505
Add ability to update users sync on startup required state
ZIMkaRU Mar 14, 2023
df8901e
Fix launching sync after sign-in if required
ZIMkaRU Mar 14, 2023
7cc09e9
Request sync after db migration
ZIMkaRU Mar 14, 2023
a11d070
Add ability request sync via ipc for electron app auto-update
ZIMkaRU Mar 14, 2023
15114f6
Add v33 db migration
ZIMkaRU Mar 14, 2023
0a4d310
Merge pull request #260 from ZIMkaRU/bugfix/fix-is-restricted-to-be-a…
prdn Mar 15, 2023
d49668c
Add test case for updateUser endpoint
ZIMkaRU Mar 15, 2023
6bcd2da
Improve test case for getUsers endpoint
ZIMkaRU Mar 15, 2023
c9cf766
Fix user data normalization
ZIMkaRU Mar 15, 2023
0552563
Fix updating user data
ZIMkaRU Mar 15, 2023
395037c
Add ability to set options into AuthTokenGenerationError
ZIMkaRU Mar 21, 2023
5f480dd
Add auth token invalid flag into AuthError
ZIMkaRU Mar 21, 2023
d33c94a
Merge pull request #261 from ZIMkaRU/feature/add-ability-to-auto-star…
prdn Mar 22, 2023
b949c8d
Merge pull request #262 from ZIMkaRU/feature/add-invalid-auth-token-f…
prdn Mar 22, 2023
200aa82
Add HTTPRequest service type
ZIMkaRU Mar 22, 2023
9319495
Add helper to make request to bfx
ZIMkaRU Mar 22, 2023
7541e98
Implement service to make login http request
ZIMkaRU Mar 22, 2023
f730e57
Inject HTTPRequest service into di
ZIMkaRU Mar 22, 2023
af01557
Add loginToBFX endpoint
ZIMkaRU Mar 22, 2023
b1fa853
Add verifyOnBFX endpoint
ZIMkaRU Mar 22, 2023
759c7f5
Add login mock data
ZIMkaRU Mar 23, 2023
6b00148
Inject login mock methods
ZIMkaRU Mar 23, 2023
190b45b
Add test case for loginToBFX endpoint
ZIMkaRU Mar 23, 2023
61a74de
Add test case for verifyOnBFX endpoint
ZIMkaRU Mar 23, 2023
65eaa53
Merge pull request #263 from ZIMkaRU/feature/add-proxy-endpoints-for-…
prdn Mar 23, 2023
1dfcbe0
Update bfx-report-ui sub-module
ZIMkaRU Mar 29, 2023
d76b162
Bump version up to 4.3.0
ZIMkaRU Mar 29, 2023
f7000c2
Merge pull request #264 from ZIMkaRU/feature/release-version
prdn Mar 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bfx-report-ui
Submodule bfx-report-ui updated 43 files
+1 −1 package.json
+20 −2 public/locales/en/translations.json
+8 −5 src/components/Auth/Auth.js
+29 −20 src/components/Auth/InputKey/InputKey.js
+34 −0 src/components/Auth/LoginEmail/LoginEmail.js
+1 −0 src/components/Auth/LoginEmail/index.js
+56 −0 src/components/Auth/LoginOtp/LoginOtp.js
+1 −0 src/components/Auth/LoginOtp/index.js
+16 −2 src/components/Auth/PasswordRecovery/PasswordRecovery.container.js
+150 −72 src/components/Auth/PasswordRecovery/PasswordRecovery.js
+0 −16 src/components/Auth/PasswordRecovery/PasswordRecovery.props.js
+18 −6 src/components/Auth/RegisterSubAccounts/RegisterSubAccounts.js
+14 −1 src/components/Auth/SignIn/SignIn.container.js
+147 −75 src/components/Auth/SignIn/SignIn.js
+18 −3 src/components/Auth/SignUp/SignUp.container.js
+185 −102 src/components/Auth/SignUp/SignUp.js
+15 −15 src/components/Auth/_Auth.scss
+2 −1 src/components/Header/AccountMenu/AccountMenu.container.js
+6 −2 src/components/Header/AccountMenu/AccountMenu.js
+2 −1 src/components/Header/TopNavigation/TopNavigation.container.js
+9 −6 src/components/Header/TopNavigation/TopNavigation.js
+2 −1 src/components/Main/Main.container.js
+6 −1 src/components/Main/Main.js
+2 −0 src/components/Preferences/Preferences.container.js
+66 −57 src/components/Preferences/Preferences.js
+6 −1 src/components/SubAccounts/SubAccount/SubAccount.js
+1 −1 src/config.js
+63 −0 src/state/auth/actions.js
+9 −0 src/state/auth/constants.js
+22 −3 src/state/auth/reducer.js
+173 −7 src/state/auth/saga.js
+13 −0 src/state/auth/selectors.js
+11 −3 src/state/utils.js
+1 −0 src/state/ws/constants.js
+6 −0 src/state/ws/saga.js
+1 −1 src/styles/button.scss
+4 −4 src/styles/index.scss
+4 −3 src/styles/modals.scss
+1 −1 src/ui/DateInput/_DateInput.scss
+2 −1 src/ui/Select/Select.js
+3 −2 src/ui/Select/_Select.scss
+8 −1 src/utils/handleElectronLoad.js
+5 −1 src/utils/triggerElectronLoad.js
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bfx-reports-framework",
"version": "4.2.0",
"version": "4.3.0",
"description": "Bitfinex reports framework",
"main": "worker.js",
"license": "Apache-2.0",
Expand Down
17 changes: 14 additions & 3 deletions test/helpers/helpers.mock-rest-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,27 @@ const getMockDataOpts = () => ({
...getBaseMockDataOpts(),
candles: { limit: 500 },
generate_token: null,
delete_token: null
delete_token: null,
login: null,
login_verify: null
})

const getExtraMockMethods = () => (new Map([
['post', {
'/v2/login': 'login',
'/v2/login/verify': 'login_verify'
}]
]))

const createMockRESTv2SrvWithDate = (
start = Date.now(),
end = start,
limit = null,
opts = getMockDataOpts(),
{
_getMockData = getMockData,
_setDataTo = setDataTo
_setDataTo = setDataTo,
extraMockMethods = getExtraMockMethods()
} = {}
) => {
return _createMockRESTv2SrvWithDate(
Expand All @@ -67,7 +77,8 @@ const createMockRESTv2SrvWithDate = (
opts,
{
_getMockData,
_setDataTo
_setDataTo,
extraMockMethods
}
)
}
Expand Down
19 changes: 19 additions & 0 deletions test/helpers/mock-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ const _ms = Date.now()

module.exports = new Map([
...mockData,
[
'login',
[
'12345678-8888-4321-1234-8cb090a01360',
[
[
'otp',
true
]
]
]
],
[
'login_verify',
[
'pub:api:88888888-4444-4444-4444-121212121212-caps:s:o:f:w:wd:a-write',
'2023-03-21T12:00:00.000Z'
]
],
[
'generate_token',
['pub:api:88888888-4444-4444-4444-121212121212-caps:s:o:f:w:wd:a-write']
Expand Down
80 changes: 80 additions & 0 deletions test/test-cases/api-sync-mode-sqlite-test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,58 @@ module.exports = (
assert.isOk(res.body.result)
})

it('it should be successfully performed by the loginToBFX method', async function () {
this.timeout(5000)

const res = await agent
.post(`${basePath}/json-rpc`)
.type('json')
.send({
auth: {
login: 'user-name',
password: 'user-pwd'
},
method: 'loginToBFX',
id: 5
})
.expect('Content-Type', /json/)
.expect(200)

assert.isObject(res.body)
assert.propertyVal(res.body, 'id', 5)
assert.isArray(res.body.result)
assert.isString(res.body.result[0])
assert.isArray(res.body.result[1])
assert.isArray(res.body.result[1][0])
assert.isString(res.body.result[1][0][0])
assert.isBoolean(res.body.result[1][0][1])
})

it('it should be successfully performed by the verifyOnBFX method', async function () {
this.timeout(5000)

const res = await agent
.post(`${basePath}/json-rpc`)
.type('json')
.send({
auth: {
loginToken: '12345678-8888-4321-1234-8cb090a01360',
token: '123456',
verifyMethod: 'otp'
},
method: 'verifyOnBFX',
id: 5
})
.expect('Content-Type', /json/)
.expect(200)

assert.isObject(res.body)
assert.propertyVal(res.body, 'id', 5)
assert.isArray(res.body.result)
assert.isString(res.body.result[0])
assert.isString(res.body.result[1])
})

it('it should be successfully performed by the signIn method', async function () {
this.timeout(5000)

Expand All @@ -107,10 +159,35 @@ module.exports = (
assert.strictEqual(res.body.result.email, email)
assert.strictEqual(res.body.result.isSubAccount, isSubAccount)
assert.isString(res.body.result.token)
assert.isBoolean(res.body.result.shouldNotSyncOnStartupAfterUpdate)
assert.isNotOk(res.body.result.shouldNotSyncOnStartupAfterUpdate)

auth.token = res.body.result.token
})

it('it should be successfully performed by the updateUser method', async function () {
this.timeout(5000)

const res = await agent
.post(`${basePath}/json-rpc`)
.type('json')
.send({
auth,
method: 'updateUser',
params: {
shouldNotSyncOnStartupAfterUpdate: true
},
id: 5
})
.expect('Content-Type', /json/)
.expect(200)

assert.isObject(res.body)
assert.propertyVal(res.body, 'id', 5)
assert.isBoolean(res.body.result)
assert.isOk(res.body.result)
})

it('it should be successfully performed by the signIn method by token', async function () {
this.timeout(5000)

Expand All @@ -131,6 +208,8 @@ module.exports = (
assert.strictEqual(res.body.result.email, email)
assert.strictEqual(res.body.result.isSubAccount, isSubAccount)
assert.strictEqual(res.body.result.token, auth.token)
assert.isBoolean(res.body.result.shouldNotSyncOnStartupAfterUpdate)
assert.isOk(res.body.result.shouldNotSyncOnStartupAfterUpdate)
})

it('it should not be successfully performed by the signIn method', async function () {
Expand Down Expand Up @@ -328,6 +407,7 @@ module.exports = (
assert.isString(user.email)
assert.isBoolean(user.isSubAccount)
assert.isBoolean(user.isNotProtected)
assert.isBoolean(user.isRestrictedToBeAddedToSubAccount)
assert.isArray(user.subUsers)

user.subUsers.forEach((subUser) => {
Expand Down
7 changes: 6 additions & 1 deletion workers/loc.api/di/app.deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ const Crypto = require('../sync/crypto')
const Authenticator = require('../sync/authenticator')
const privResponder = require('../responder')
const ProcessMessageManager = require('../process.message.manager')
const HTTPRequest = require('../http.request')

decorate(injectable(), EventEmitter)

Expand Down Expand Up @@ -157,7 +158,8 @@ module.exports = ({
['_dataConsistencyChecker', TYPES.DataConsistencyChecker],
['_winLossVSAccountBalance', TYPES.WinLossVSAccountBalance],
['_weightedAveragesReport', TYPES.WeightedAveragesReport],
['_getDataFromApi', TYPES.GetDataFromApi]
['_getDataFromApi', TYPES.GetDataFromApi],
['_httpRequest', TYPES.HTTPRequest]
]
})
rebind(TYPES.RServiceDepsSchemaAliase)
Expand Down Expand Up @@ -197,6 +199,9 @@ module.exports = ({
bind(TYPES.ProcessMessageManager)
.to(ProcessMessageManager)
.inSingletonScope()
bind(TYPES.HTTPRequest)
.to(HTTPRequest)
.inSingletonScope()
bind(TYPES.WSTransport)
.to(WSTransport)
.inSingletonScope()
Expand Down
3 changes: 2 additions & 1 deletion workers/loc.api/di/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ module.exports = {
SyncUserStepData: Symbol.for('SyncUserStepData'),
SyncUserStepDataFactory: Symbol.for('SyncUserStepDataFactory'),
WeightedAveragesReport: Symbol.for('WeightedAveragesReport'),
WeightedAveragesReportCsvWriter: Symbol.for('WeightedAveragesReportCsvWriter')
WeightedAveragesReportCsvWriter: Symbol.for('WeightedAveragesReportCsvWriter'),
HTTPRequest: Symbol.for('HTTPRequest')
}
18 changes: 16 additions & 2 deletions workers/loc.api/errors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const {
ConflictError,
ArgsParamsError
} = require('bfx-report/workers/loc.api/errors')
const {
getErrorArgs
} = require('bfx-report/workers/loc.api/errors/helpers')

class CollSyncPermissionError extends BaseError {
constructor (message = 'ERR_PERMISSION_DENIED_TO_SYNC_SELECTED_COLL') {
Expand Down Expand Up @@ -113,6 +116,14 @@ class SubAccountUpdatingError extends AuthError {
}
}

class UserUpdatingError extends AuthError {
constructor (message = 'ERR_USER_UPDATE_HAS_BEEN_FAILED') {
super(message)

this.statusMessage = 'User update has been failed'
}
}

class UserRemovingError extends AuthError {
constructor (message = 'ERR_USER_REMOVE_HAS_BEEN_FAILED') {
super(message)
Expand Down Expand Up @@ -212,8 +223,10 @@ class SyncInfoUpdatingError extends BaseError {
}

class AuthTokenGenerationError extends AuthError {
constructor (message = 'ERR_AUTH_TOKEN_HAS_NOT_BEEN_GENERATED') {
super(message)
constructor (args) {
const _args = getErrorArgs(args, 'ERR_AUTH_TOKEN_HAS_NOT_BEEN_GENERATED')

super(_args)
}
}

Expand All @@ -235,6 +248,7 @@ module.exports = {
MigrationLaunchingError,
SubAccountCreatingError,
SubAccountUpdatingError,
UserUpdatingError,
UserRemovingError,
UserWasPreviouslyStoredInDbError,
SubAccountLedgersBalancesRecalcError,
Expand Down
26 changes: 26 additions & 0 deletions workers/loc.api/http.request/helpers.js
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
}
63 changes: 63 additions & 0 deletions workers/loc.api/http.request/index.js
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
22 changes: 22 additions & 0 deletions workers/loc.api/process.message.manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,28 @@ class ProcessMessageManager {
{ backupFilesMetadata }
)
}

async [PROCESS_STATES.REQUEST_UPDATE_USERS_SYNC_ON_STARTUP_REQUIRED_STATE] (err, state, data) {
if (err) {
this.logger.debug('[Users sync on startup required state has not been updated]')
this.logger.error(err)

this.sendState(
PROCESS_MESSAGES.RESPONSE_UPDATE_USERS_SYNC_ON_STARTUP_REQUIRED_STATE,
{ err }
)

return
}

const isDone = await this.dao
.updateUsersSyncOnStartupRequiredState()

this.sendState(
PROCESS_MESSAGES.RESPONSE_UPDATE_USERS_SYNC_ON_STARTUP_REQUIRED_STATE,
{ isDone }
)
}
}

decorateInjectable(ProcessMessageManager, depsTypes)
Expand Down
4 changes: 3 additions & 1 deletion workers/loc.api/process.message.manager/process.messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ module.exports = {
REQUEST_MIGRATION_HAS_FAILED_WHAT_SHOULD_BE_DONE: 'request:migration-has-failed:what-should-be-done',
REQUEST_SHOULD_ALL_TABLES_BE_REMOVED: 'request:should-all-tables-be-removed',

RESPONSE_GET_BACKUP_FILES_METADATA: 'response:get-backup-files-metadata'
RESPONSE_GET_BACKUP_FILES_METADATA: 'response:get-backup-files-metadata',

RESPONSE_UPDATE_USERS_SYNC_ON_STARTUP_REQUIRED_STATE: 'response:update-users-sync-on-startup-required-state'
}
Loading