11import { BASE_API_URL } from './models'
2- import { fetchJson } from '../../common/network'
2+ import { fetchJson , FetchOptions , FetchResponse } from '../../common/network'
33import type * as T from './types/fetch'
44import { FetchError , FetchOutput } from './types/base'
55import { isNonEmptyString } from './helpers'
66
77const makeUrl = ( domain : 'auth' | 'core' , url : string ) : string =>
88 `${ BASE_API_URL } /${ domain } /services/v3${ url } `
99
10+ async function fetchApi ( url : string , options : FetchOptions ) : Promise < FetchResponse > {
11+ return await fetchJson ( url , {
12+ ...options ,
13+ sanitizeRequestLog : {
14+ headers : {
15+ Authorization : true
16+ } ,
17+ body : {
18+ login : true ,
19+ password : true
20+ }
21+ } ,
22+ sanitizeResponseLog : {
23+ body : {
24+ sessionToken : true
25+ }
26+ }
27+ } )
28+ }
29+
1030/**
1131 * Login using a new deviceId created a device listed in the user's account
1232 * Device name is usually `{platform} {browser}`
1333 * **/
1434export const fetchLogin = async ( { login, password, deviceId } : T . AuthenticateInput ) : Promise < FetchOutput < T . AuthenticateOutput > > => {
15- const { status, body } = await fetchJson ( makeUrl ( 'auth' , '/authentication/login' ) , {
35+ const { status, body } = await fetchApi ( makeUrl ( 'auth' , '/authentication/login' ) , {
1636 method : 'POST' ,
1737 body : {
1838 login,
@@ -35,7 +55,7 @@ export const fetchLogin = async ({ login, password, deviceId }: T.AuthenticateIn
3555}
3656
3757export const fetchAccounts = async ( { sessionToken } : T . FetchAccountsInput ) : Promise < FetchOutput < T . FetchAccountsOutput > > => {
38- const { status, body } = await fetchJson ( makeUrl ( 'core' , '/product/get-products?getCreditDetail=false' ) , {
58+ const { status, body } = await fetchApi ( makeUrl ( 'core' , '/product/get-products?getCreditDetail=false' ) , {
3959 headers : {
4060 Authorization : `Bearer ${ sessionToken } `
4161 }
@@ -49,7 +69,7 @@ export const fetchAccounts = async ({ sessionToken }: T.FetchAccountsInput): Pro
4969}
5070
5171export const fetchTransactions = async ( { sessionToken, from, to, account } : T . FetchTransactionsInput ) : Promise < FetchOutput < T . FetchTransactionsOutput > > => {
52- const { status, body } = await fetchJson ( makeUrl ( 'core' , '/operation/history/get-operations-history' ) , {
72+ const { status, body } = await fetchApi ( makeUrl ( 'core' , '/operation/history/get-operations-history' ) , {
5373 method : 'POST' ,
5474 headers : {
5575 Authorization : `Bearer ${ sessionToken } `
0 commit comments