1 | import ApiAdapter from "./ApiAdapter";
|
2 | import Session from "./Session";
|
3 | import StorageInteface from "./Interfaces/StorageInterface";
|
4 | import LoggerInterface from "./Interfaces/LoggerInterface";
|
5 | import ApiEndpointCollection from "./Interfaces/ApiEndpointCollection";
|
6 | import { RequestLimitProxyTypes } from "./RequestLimitFactory";
|
7 | export default class BunqJSClient {
|
8 | storageInterface: StorageInteface;
|
9 | logger: LoggerInterface;
|
10 | apiKey: string | false;
|
11 | Session: Session;
|
12 | ApiAdapter: ApiAdapter;
|
13 | /**
|
14 | * Decides whether the session is kept alive (which will be slightly faster)
|
15 | * or creates a new session when required
|
16 | * @type {boolean}
|
17 | */
|
18 | keepAlive: boolean;
|
19 | /**
|
20 | * Contains the promise for fetching a new session to prevent duplicate requests
|
21 | * @type {boolean}
|
22 | */
|
23 | fetchingNewSession: Promise<boolean> | false;
|
24 | /**
|
25 | * Contains object with all API endpoints
|
26 | */
|
27 | api: ApiEndpointCollection;
|
28 | /**
|
29 | * A list of all custom bunqJSClient error codes to make error handling easier
|
30 | * @type {{INSTALLATION_HAS_SESSION}}
|
31 | */
|
32 | errorCodes: any;
|
33 | /**
|
34 | * @param {StorageInterface|false} storageInterface
|
35 | * @param {LoggerInterface} loggerInterface
|
36 | */
|
37 | constructor(storageInterface?: StorageInteface | false, loggerInterface?: LoggerInterface);
|
38 | /**
|
39 | * Starts the client and sets up the required components
|
40 | * @returns {Promise.<void>}
|
41 | */
|
42 | run(apiKey: string | false, allowedIps?: string[], environment?: string, encryptionKey?: string | boolean): Promise<void>;
|
43 | /**
|
44 | * If true, polling requests will be sent to try and keep the current session
|
45 | * alive instead of creating a new session when required
|
46 | * If false, a new session will be created when required
|
47 | * @param {boolean} keepAlive
|
48 | */
|
49 | setKeepAlive(keepAlive: boolean): void;
|
50 | /**
|
51 | * Use one or more proxies when sending requests. Proxies are used
|
52 | * @param enabledProxies
|
53 | */
|
54 | setRequestProxies(enabledProxies: RequestLimitProxyTypes): void;
|
55 | /**
|
56 | * Installs this application
|
57 | * @returns {Promise<boolean>}
|
58 | */
|
59 | install(): Promise<boolean>;
|
60 | /**
|
61 | * Registers a new device for this installation
|
62 | * @param {string} deviceName
|
63 | * @returns {Promise<boolean>}
|
64 | */
|
65 | registerDevice(deviceName?: string): Promise<boolean>;
|
66 | /**
|
67 | * Registers a new session when required for this device and installation
|
68 | * @returns {Promise<boolean>}
|
69 | */
|
70 | registerSession(): Promise<boolean>;
|
71 | /**
|
72 | * Send the actual request and handle it
|
73 | * @returns {Promise<boolean>}
|
74 | */
|
75 | private generateSession;
|
76 | /**
|
77 | * Change the encryption key and
|
78 | * @param {string} encryptionKey
|
79 | * @returns {Promise<boolean>}
|
80 | */
|
81 | changeEncryptionKey(encryptionKey: string): Promise<boolean>;
|
82 | /**
|
83 | * Handles the oauth type users
|
84 | * @param userInfoParsed
|
85 | * @returns {any}
|
86 | */
|
87 | private parseOauthUser;
|
88 | /**
|
89 | * Create a new credential password ip
|
90 | * @returns {Promise<any>}
|
91 | */
|
92 | createCredentials(): Promise<any>;
|
93 | /**
|
94 | * Check if a credential password ip has been accepted
|
95 | * @param {string} uuid
|
96 | * @returns {Promise<any>}
|
97 | */
|
98 | checkCredentialStatus(uuid: string): Promise<any>;
|
99 | /**
|
100 | *
|
101 | * @param {string} clientId
|
102 | * @param {string} clientSecret
|
103 | * @param {string} redirectUri
|
104 | * @param {string} code
|
105 | * @param {string|false} state
|
106 | * @param {boolean} sandbox
|
107 | * @param {string} grantType
|
108 | * @returns {Promise<string>}
|
109 | */
|
110 | exchangeOAuthToken(clientId: string, clientSecret: string, redirectUri: string, code: string, state?: string | false, sandbox?: boolean, grantType?: string): Promise<string>;
|
111 | /**
|
112 | * Formats a correct bunq OAuth url to begin the login flow
|
113 | * @param {string} clientId
|
114 | * @param {string} redirectUri
|
115 | * @param {string|false} state
|
116 | * @param {boolean} sandbox
|
117 | * @returns {string}
|
118 | */
|
119 | formatOAuthAuthorizationRequestUrl(clientId: string, redirectUri: string, state?: string | false, sandbox?: boolean): string;
|
120 | /**
|
121 | * Formats the given parameters into the url used for the token exchange
|
122 | * @param {string} clientId
|
123 | * @param {string} clientSecret
|
124 | * @param {string} redirectUri
|
125 | * @param {string} code
|
126 | * @param {boolean} sandbox
|
127 | * @param {string} grantType
|
128 | * @returns {string}
|
129 | */
|
130 | formatOAuthKeyExchangeUrl(clientId: string, clientSecret: string, redirectUri: string, code: string, sandbox?: boolean, grantType?: string): string;
|
131 | /**
|
132 | * Sets an automatic timer to keep the session alive when possible
|
133 | */
|
134 | setExpiryTimer(shortTimeout?: boolean): boolean;
|
135 | /**
|
136 | * Resets the session expiry timer
|
137 | */
|
138 | clearExpiryTimer(): void;
|
139 | /**
|
140 | * Handles the expiry timer checker callback
|
141 | */
|
142 | private expiryTimerCallback;
|
143 | /**
|
144 | * Calculate in how many milliseconds the session will expire
|
145 | * @param {boolean} shortTimeout
|
146 | * @returns {number}
|
147 | */
|
148 | calculateSessionExpiry(shortTimeout?: boolean): number;
|
149 | /**
|
150 | * Destroys the current installation and session and all variables associated with it
|
151 | * @returns {Promise<void>}
|
152 | */
|
153 | destroySession(): Promise<void>;
|
154 | /**
|
155 | * Destroys the current session and all variables associated with it
|
156 | * @param save
|
157 | */
|
158 | destroyApiSession(save?: boolean): Promise<void>;
|
159 | /**
|
160 | * Returns the registered user for the session of a specific type
|
161 | * @returns {any}
|
162 | */
|
163 | getUser(userType: any, updated?: boolean): Promise<any>;
|
164 | /**
|
165 | * Returns the registered users for the session
|
166 | * @returns {any}
|
167 | */
|
168 | getUsers(updated?: boolean): Promise<any>;
|
169 | /**
|
170 | * Receives an object with an unknown user type and returns an object with
|
171 | * the correct info and a isOAuth boolean
|
172 | * @param userInfo
|
173 | * @returns {{info: any; isOAuth: boolean}}
|
174 | */
|
175 | private getUserType;
|
176 | }
|