degiro-api
Advanced tools
Comparing version 0.0.5 to 0.0.6
{ | ||
"name": "degiro-api", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"public": true, | ||
@@ -22,2 +22,7 @@ "description": "Degiro test scripts", | ||
"devDependencies": { | ||
"@types/cookie": "^0.4.0", | ||
"@types/node": "^13.13.5", | ||
"@types/node-fetch": "^2.5.7", | ||
"install": "^0.13.0", | ||
"npm": "^6.14.5", | ||
"tslint": "^6.1.2", | ||
@@ -28,4 +33,4 @@ "tslint-config-airbnb": "^5.11.2", | ||
"dependencies": { | ||
"@types/node": "^13.13.5" | ||
"node-fetch": "^2.6.0" | ||
} | ||
} |
@@ -5,4 +5,10 @@ // Import interfaces | ||
// Import types | ||
import { DeGiroSettupType, PortfolioPositionType } from './types' | ||
import { DeGiroSettupType, LoginResponseType, AccountConfigType, AccountDataType } from './types' | ||
// Import requests | ||
import { loginRequest, getAccountConfigRequest, getAccountDataRequest } from './requests' | ||
// Import debug console log | ||
import { debug } from './utils' | ||
/** | ||
@@ -16,6 +22,14 @@ * @class DeGiro | ||
private readonly pwd: string | ||
private loginResponse: LoginResponseType | undefined | ||
private accountConfig: AccountConfigType | undefined | ||
private accountData: AccountDataType | undefined | ||
constructor(params: DeGiroSettupType) { | ||
this.username = params.username | ||
this.pwd = params.pwd | ||
const { username, pwd } = params | ||
if (!username) throw new Error('DeGiro api needs an username to access') | ||
if (!pwd) throw new Error('DeGiro api needs an password to access') | ||
this.username = username | ||
this.pwd = pwd | ||
} | ||
@@ -27,6 +41,49 @@ | ||
login(): never { | ||
throw new Error('Method not implemented.') | ||
login(): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
loginRequest({ username: this.username, pwd: this.pwd }) | ||
.then((loginResponse: LoginResponseType) => { | ||
this.loginResponse = loginResponse | ||
return this.getAccountConfig() | ||
}) | ||
.then(() => this.getAccountData()) | ||
.then((accountData) => { | ||
resolve() | ||
}) | ||
.catch(reject) | ||
}) | ||
} | ||
getAccountConfig(): Promise<AccountConfigType> { | ||
return new Promise((resolve, reject) => { | ||
if (!this.loginResponse || !this.loginResponse.sessionId) { | ||
return reject('No session id found.') | ||
} | ||
getAccountConfigRequest(this.loginResponse.sessionId) | ||
.then((accountConfig: AccountConfigType) => { | ||
this.accountConfig = accountConfig | ||
resolve(accountConfig) | ||
}) | ||
.catch(reject) | ||
}) | ||
} | ||
getAccountData(): Promise<AccountDataType> { | ||
return new Promise((resolve, reject) => { | ||
if (!this.loginResponse || !this.loginResponse.sessionId || !this.accountConfig) { | ||
return reject('No session id found.') | ||
} | ||
getAccountDataRequest(this.loginResponse.sessionId, this.accountConfig) | ||
.then((accountData: AccountDataType) => { | ||
this.accountData = accountData | ||
resolve(accountData) | ||
}) | ||
.catch(reject) | ||
}) | ||
} | ||
hasLogin(): boolean { | ||
return this.loginResponse !== undefined | ||
} | ||
getCashFunds(): import('./types/CashFoundType').CashFoundType[] { | ||
@@ -33,0 +90,0 @@ throw new Error('Method not implemented.') |
@@ -1,3 +0,2 @@ | ||
import { CashFoundType, DeGiroSettupType, PortfolioPositionType } from '../types' | ||
import { DeGiro } from '../DeGiro' | ||
import { CashFoundType, AccountConfigType, PortfolioPositionType, AccountDataType } from '../types' | ||
@@ -9,4 +8,10 @@ /** | ||
login(): never | ||
login(): Promise<void> | ||
hasLogin(): boolean | ||
getAccountConfig(): Promise<AccountConfigType> | ||
getAccountData(): Promise<AccountDataType> | ||
getCashFunds(): CashFoundType[] | ||
@@ -13,0 +18,0 @@ |
import { CashFoundType } from './CashFoundType' | ||
import { DeGiroSettupType } from './DeGiroSettupType' | ||
import { PortfolioPositionType } from './PortfolioPositionType' | ||
import { LoginResponseType } from './LoginResponseType' | ||
import { LoginRequestParamsType } from './LoginRequestParamsType' | ||
import { LoginRequestBodyType } from './LoginRequestBodyType' | ||
import { AccountConfigType } from './AccountConfigType' | ||
import { AccountDataType } from './AccountDataType' | ||
@@ -9,2 +14,7 @@ export { | ||
PortfolioPositionType, | ||
LoginResponseType, | ||
LoginRequestParamsType, | ||
LoginRequestBodyType, | ||
AccountConfigType, | ||
AccountDataType, | ||
} |
import DeGiro from './../main' | ||
const degiro: DeGiro = new DeGiro({ | ||
username: 'nachoogoomezomg', | ||
pwd: '**********', | ||
username: 'arganzana', | ||
pwd: <string>process.env.DEGIRO_PWD, | ||
}) | ||
degiro.printConfig() | ||
degiro.login() | ||
.then(() => { | ||
console.log('Loggin success') | ||
}) | ||
.catch((error) => { | ||
throw new Error(error) | ||
}) |
@@ -8,5 +8,14 @@ { | ||
"semicolon":false, | ||
"import-name": [false, "ignore-modules"] | ||
"import-name": [false, "ignore-modules"], | ||
"max-line-length": [ | ||
true, | ||
{ | ||
"limit": 150, | ||
"ignore-pattern": "^import |^export {(.*?)}", | ||
"check-strings": true, | ||
"check-regex": true | ||
} | ||
] | ||
}, | ||
"rulesDirectory": [] | ||
} |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
199239
37
4977
8
+ Addednode-fetch@^2.6.0
+ Addednode-fetch@2.7.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
- Removed@types/node@^13.13.5
- Removed@types/node@13.13.52(transitive)