@emilgroup/financemanager-sdk 1.0.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.openapi-generator/FILES +22 -0
- package/.openapi-generator/VERSION +1 -0
- package/.openapi-generator-ignore +23 -0
- package/README.md +51 -0
- package/api/payout-matching-service-api.ts +232 -0
- package/api.ts +27 -0
- package/base.ts +465 -0
- package/common.ts +199 -0
- package/configuration.ts +130 -0
- package/dist/api/payout-matching-service-api.d.ts +141 -0
- package/dist/api/payout-matching-service-api.js +251 -0
- package/dist/api.d.ts +12 -0
- package/dist/api.js +30 -0
- package/dist/base.d.ts +111 -0
- package/dist/base.js +487 -0
- package/dist/common.d.ts +91 -0
- package/dist/common.js +277 -0
- package/dist/configuration.d.ts +106 -0
- package/dist/configuration.js +54 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +36 -0
- package/dist/models/any.d.ts +25 -0
- package/dist/models/any.js +15 -0
- package/dist/models/bank-order-payment-requests.d.ts +79 -0
- package/dist/models/bank-order-payment-requests.js +15 -0
- package/dist/models/bank-transaction-summary.d.ts +48 -0
- package/dist/models/bank-transaction-summary.js +15 -0
- package/dist/models/candidate-row.d.ts +32 -0
- package/dist/models/candidate-row.js +15 -0
- package/dist/models/counterparty.d.ts +30 -0
- package/dist/models/counterparty.js +15 -0
- package/dist/models/get-payment-request-candidates-response.d.ts +56 -0
- package/dist/models/get-payment-request-candidates-response.js +15 -0
- package/dist/models/index.d.ts +8 -0
- package/dist/models/index.js +24 -0
- package/dist/models/payment-request-candidate.d.ts +79 -0
- package/dist/models/payment-request-candidate.js +15 -0
- package/dist/models/status.d.ts +37 -0
- package/dist/models/status.js +15 -0
- package/git_push.sh +57 -0
- package/index.ts +19 -0
- package/models/any.ts +32 -0
- package/models/bank-order-payment-requests.ts +85 -0
- package/models/bank-transaction-summary.ts +54 -0
- package/models/candidate-row.ts +38 -0
- package/models/counterparty.ts +36 -0
- package/models/get-payment-request-candidates-response.ts +62 -0
- package/models/index.ts +8 -0
- package/models/payment-request-candidate.ts +85 -0
- package/models/status.ts +43 -0
- package/package.json +27 -0
- package/tsconfig.json +23 -0
package/base.ts
ADDED
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL Financemanager
|
|
5
|
+
* The EMIL Financemanager API description.
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 1.0
|
|
8
|
+
* Contact: kontakt@emil.de
|
|
9
|
+
*
|
|
10
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
11
|
+
* https://openapi-generator.tech
|
|
12
|
+
* Do not edit the class manually.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
import { Configuration } from "./configuration";
|
|
17
|
+
import { defaultStorage } from "./common";
|
|
18
|
+
// Some imports not used depending on template conditions
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
export const BASE_PATH = "https://apiv2.emil.de".replace(/\/+$/, "");
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @export
|
|
27
|
+
*/
|
|
28
|
+
export const COLLECTION_FORMATS = {
|
|
29
|
+
csv: ",",
|
|
30
|
+
ssv: " ",
|
|
31
|
+
tsv: "\t",
|
|
32
|
+
pipes: "|",
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export interface SessionClass {
|
|
36
|
+
sub: string;
|
|
37
|
+
username?: string;
|
|
38
|
+
email?: string;
|
|
39
|
+
tenantSlug?: string;
|
|
40
|
+
permissions?: string;
|
|
41
|
+
expiresAt?: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface LoginClass {
|
|
45
|
+
accessToken: string;
|
|
46
|
+
permissions: string;
|
|
47
|
+
authMode?: string;
|
|
48
|
+
session?: SessionClass;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface SwitchWorkspaceRequest {
|
|
52
|
+
username: string;
|
|
53
|
+
targetWorkspace: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface SwitchWorkspaceResponseClass {
|
|
57
|
+
accessToken: string;
|
|
58
|
+
permissions: string;
|
|
59
|
+
authMode?: string;
|
|
60
|
+
session?: SessionClass;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export enum Environment {
|
|
64
|
+
Production = 'https://apiv2.emil.de',
|
|
65
|
+
Test = 'https://apiv2-test.emil.de',
|
|
66
|
+
Staging = 'https://apiv2-staging.emil.de',
|
|
67
|
+
Development = 'https://apiv2-dev.emil.de',
|
|
68
|
+
ProductionZurich = 'https://eu-central-2.apiv2.emil.de',
|
|
69
|
+
StagingZurich = 'https://eu-central-2.apiv2-staging.emil.de',
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let _retry_count = 0
|
|
73
|
+
let _retry = null
|
|
74
|
+
|
|
75
|
+
export function resetRetry() {
|
|
76
|
+
_retry_count = 0
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
*
|
|
81
|
+
* @export
|
|
82
|
+
* @interface RequestArgs
|
|
83
|
+
*/
|
|
84
|
+
export interface RequestArgs {
|
|
85
|
+
url: string;
|
|
86
|
+
options: AxiosRequestConfig;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
interface TokenData {
|
|
90
|
+
accessToken?: string;
|
|
91
|
+
username?: string;
|
|
92
|
+
permissions?: string;
|
|
93
|
+
// 'both' or 'session' when authservice keeps the tokens in a server session.
|
|
94
|
+
authMode?: string;
|
|
95
|
+
sub?: string;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const NETWORK_ERROR_MESSAGE = "Network Error";
|
|
99
|
+
const TOKEN_DATA = 'APP_TOKEN';
|
|
100
|
+
// Sent only to authservice, to ask for a server session.
|
|
101
|
+
const AUTH_MODE_HEADER = 'X-Emil-Auth-Mode';
|
|
102
|
+
// Names the account on every call; one browser session can hold several.
|
|
103
|
+
const ACCOUNT_HEADER = 'X-Emil-Account';
|
|
104
|
+
const SESSION_MODES = ['both', 'session'];
|
|
105
|
+
const RESEND_SAFE_METHODS = ['get', 'head', 'options'];
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
*
|
|
109
|
+
* @export
|
|
110
|
+
* @class BaseAPI
|
|
111
|
+
*/
|
|
112
|
+
export class BaseAPI {
|
|
113
|
+
protected configuration: Configuration | undefined;
|
|
114
|
+
private tokenData?: TokenData;
|
|
115
|
+
|
|
116
|
+
constructor(configuration?: Configuration,
|
|
117
|
+
protected basePath: string = BASE_PATH,
|
|
118
|
+
protected axios: AxiosInstance = globalAxios) {
|
|
119
|
+
|
|
120
|
+
this.loadTokenData();
|
|
121
|
+
|
|
122
|
+
if (configuration) {
|
|
123
|
+
const { accessToken } = this.tokenData;
|
|
124
|
+
this.configuration = configuration;
|
|
125
|
+
this.basePath = configuration.basePath || this.basePath;
|
|
126
|
+
|
|
127
|
+
if (configuration.cookieAuth) {
|
|
128
|
+
this.configuration.username = this.configuration.username || this.tokenData.username;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (this.usesSession()) {
|
|
132
|
+
this.useSessionAuth();
|
|
133
|
+
} else {
|
|
134
|
+
// Use config token if provided, otherwise use tokenData token
|
|
135
|
+
const configToken = this.configuration.accessToken;
|
|
136
|
+
const storedToken = accessToken ? `Bearer ${accessToken}` : '';
|
|
137
|
+
this.configuration.accessToken = configToken || storedToken;
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
const { accessToken, username } = this.tokenData;
|
|
141
|
+
|
|
142
|
+
this.configuration = new Configuration({
|
|
143
|
+
basePath: this.basePath,
|
|
144
|
+
accessToken: accessToken ? `Bearer ${accessToken}` : '',
|
|
145
|
+
username,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
this.attachInterceptor(axios);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// The app's own account wins over APP_TOKEN, which holds whichever tab wrote last.
|
|
153
|
+
private sessionAccount(): string | undefined {
|
|
154
|
+
return this.configuration.account || this.tokenData.sub;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Apps may pass the address as the second argument only; authservice is on the same host.
|
|
158
|
+
private authBasePath(): string {
|
|
159
|
+
return this.configuration.basePath || this.basePath;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private usesSession(): boolean {
|
|
163
|
+
return !!this.configuration.cookieAuth && SESSION_MODES.indexOf(this.tokenData.authMode) !== -1 && !!this.sessionAccount();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private useSessionAuth() {
|
|
167
|
+
const { headers, ...baseOptions } = this.configuration.baseOptions || {};
|
|
168
|
+
this.configuration.accessToken = '';
|
|
169
|
+
this.configuration.baseOptions = {
|
|
170
|
+
...baseOptions,
|
|
171
|
+
withCredentials: true,
|
|
172
|
+
headers: { ...headers, [ACCOUNT_HEADER]: this.sessionAccount() },
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
private useHeaderAuth(accessToken: string) {
|
|
177
|
+
this.configuration.accessToken = accessToken ? `Bearer ${accessToken}` : '';
|
|
178
|
+
this.tokenData.accessToken = accessToken;
|
|
179
|
+
delete this.tokenData.authMode;
|
|
180
|
+
delete this.tokenData.sub;
|
|
181
|
+
if (this.configuration.cookieAuth) {
|
|
182
|
+
const { withCredentials, headers, ...baseOptions } = this.configuration.baseOptions || {};
|
|
183
|
+
const { [ACCOUNT_HEADER]: account, ...otherHeaders } = headers || {};
|
|
184
|
+
this.configuration.baseOptions = { ...baseOptions, headers: otherHeaders };
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
private applyTokenReply({ accessToken, authMode, session }: LoginClass) {
|
|
189
|
+
if (this.configuration.cookieAuth && SESSION_MODES.indexOf(authMode) !== -1 && session?.sub) {
|
|
190
|
+
this.tokenData.authMode = authMode;
|
|
191
|
+
this.tokenData.sub = session.sub;
|
|
192
|
+
if (this.configuration.account) {
|
|
193
|
+
// A workspace switch moves the app to another account.
|
|
194
|
+
this.configuration.account = session.sub;
|
|
195
|
+
}
|
|
196
|
+
// Both keeps the token for apps not moved yet; session mode keeps no token at all.
|
|
197
|
+
if (authMode === 'both' && accessToken) {
|
|
198
|
+
this.tokenData.accessToken = accessToken;
|
|
199
|
+
} else {
|
|
200
|
+
delete this.tokenData.accessToken;
|
|
201
|
+
}
|
|
202
|
+
this.useSessionAuth();
|
|
203
|
+
} else {
|
|
204
|
+
this.useHeaderAuth(accessToken);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private sessionHeaders(): Record<string, string> {
|
|
209
|
+
if (!this.configuration.cookieAuth) {
|
|
210
|
+
return {};
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
[AUTH_MODE_HEADER]: 'session',
|
|
214
|
+
...(this.usesSession() && { [ACCOUNT_HEADER]: this.sessionAccount() }),
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
private withCurrentAuth(config: AxiosRequestConfig): AxiosRequestConfig {
|
|
219
|
+
delete config.headers['Authorization'];
|
|
220
|
+
delete config.headers[ACCOUNT_HEADER];
|
|
221
|
+
if (this.usesSession()) {
|
|
222
|
+
config.headers[ACCOUNT_HEADER] = this.sessionAccount();
|
|
223
|
+
config.withCredentials = true;
|
|
224
|
+
} else if (this.configuration.accessToken) {
|
|
225
|
+
config.headers['Authorization'] = this.configuration.accessToken;
|
|
226
|
+
}
|
|
227
|
+
return config;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Both keeps the token, so a session call the browser could not complete can be sent again with it.
|
|
231
|
+
private canRetryWithToken(config: AxiosRequestConfig): boolean {
|
|
232
|
+
return !!config.withCredentials && !!config.headers?.[ACCOUNT_HEADER]
|
|
233
|
+
&& !!this.tokenData.accessToken && this.tokenData.authMode !== 'session';
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// A network error can come after the server ran the call, so only a call that is safe to repeat is sent again.
|
|
237
|
+
private canResend(config: AxiosRequestConfig): boolean {
|
|
238
|
+
return RESEND_SAFE_METHODS.indexOf((config.method || 'get').toLowerCase()) !== -1
|
|
239
|
+
|| Object.keys(config.headers || {}).some((name) => name.toLowerCase() === 'idempotency-key');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
private switchToToken() {
|
|
243
|
+
this.useHeaderAuth(this.tokenData.accessToken);
|
|
244
|
+
this.storeTokenData(this.tokenData);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
private retryWithToken(axios: AxiosInstance, config: AxiosRequestConfig) {
|
|
248
|
+
this.switchToToken();
|
|
249
|
+
config.withCredentials = false;
|
|
250
|
+
return axios(this.withCurrentAuth(config));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
selectEnvironment(env: Environment) {
|
|
254
|
+
this.selectBasePath(env);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
selectBasePath(path: string) {
|
|
258
|
+
this.configuration.basePath = path;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
getPermissions(): Array<string> {
|
|
262
|
+
if (!this.tokenData?.permissions) {
|
|
263
|
+
return [];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return this.tokenData.permissions.split(',');
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
async authorize(username: string, password: string, targetWorkspace?: string): Promise<void> {
|
|
270
|
+
const options: AxiosRequestConfig = {
|
|
271
|
+
method: 'POST',
|
|
272
|
+
url: `${this.authBasePath()}/authservice/v1/login`,
|
|
273
|
+
headers: { 'Content-Type': 'application/json', ...(this.configuration.cookieAuth && { [AUTH_MODE_HEADER]: 'session' }) },
|
|
274
|
+
data: {
|
|
275
|
+
username,
|
|
276
|
+
password,
|
|
277
|
+
},
|
|
278
|
+
withCredentials: true,
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
const response = await globalAxios.request<LoginClass>(options);
|
|
282
|
+
|
|
283
|
+
this.configuration.username = username;
|
|
284
|
+
this.tokenData.username = username;
|
|
285
|
+
this.tokenData.permissions = response.data.permissions;
|
|
286
|
+
this.applyTokenReply(response.data);
|
|
287
|
+
|
|
288
|
+
// Switch workspace if provided
|
|
289
|
+
if (targetWorkspace) {
|
|
290
|
+
await this.switchWorkspace(targetWorkspace);
|
|
291
|
+
} else {
|
|
292
|
+
// Only store if no workspace switch (since switchWorkspace will store after switching)
|
|
293
|
+
this.storeTokenData({
|
|
294
|
+
...this.tokenData
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
this.storeTokenData({
|
|
299
|
+
...this.tokenData
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
async switchWorkspace(targetWorkspace: string): Promise<void> {
|
|
304
|
+
const options: AxiosRequestConfig = {
|
|
305
|
+
method: 'POST',
|
|
306
|
+
url: `${this.authBasePath()}/authservice/v1/workspaces/switch`,
|
|
307
|
+
headers: {
|
|
308
|
+
'Content-Type': 'application/json',
|
|
309
|
+
...this.sessionHeaders(),
|
|
310
|
+
...(!this.usesSession() && !!this.configuration.accessToken && { 'Authorization': this.configuration.accessToken as string }),
|
|
311
|
+
},
|
|
312
|
+
data: {
|
|
313
|
+
username: this.configuration.username,
|
|
314
|
+
targetWorkspace,
|
|
315
|
+
} as SwitchWorkspaceRequest,
|
|
316
|
+
withCredentials: true,
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
const response = await globalAxios.request<SwitchWorkspaceResponseClass>(options);
|
|
320
|
+
|
|
321
|
+
this.tokenData.permissions = response.data.permissions;
|
|
322
|
+
this.applyTokenReply(response.data);
|
|
323
|
+
|
|
324
|
+
this.storeTokenData({
|
|
325
|
+
...this.tokenData
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
async refreshTokenInternal(): Promise<LoginClass> {
|
|
330
|
+
const { username } = this.configuration;
|
|
331
|
+
|
|
332
|
+
if (!username) {
|
|
333
|
+
throw new Error('Failed to refresh token.');
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const refreshTokenAxios = globalAxios.create()
|
|
337
|
+
refreshTokenAxios.interceptors.response.use(response => {
|
|
338
|
+
const { permissions } = response.data;
|
|
339
|
+
|
|
340
|
+
this.tokenData.permissions = permissions;
|
|
341
|
+
this.storeTokenData(this.tokenData);
|
|
342
|
+
|
|
343
|
+
return response;
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
const options: AxiosRequestConfig = {
|
|
347
|
+
method: 'POST',
|
|
348
|
+
url: `${this.authBasePath()}/authservice/v1/refresh-token`,
|
|
349
|
+
headers: {
|
|
350
|
+
'Content-Type': 'application/json',
|
|
351
|
+
...this.sessionHeaders(),
|
|
352
|
+
},
|
|
353
|
+
data: { username: username },
|
|
354
|
+
withCredentials: true,
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
const response = await refreshTokenAxios.request<LoginClass>(options);
|
|
358
|
+
return response.data;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
private storeTokenData(tokenData?: TokenData) {
|
|
362
|
+
if (typeof window !== 'undefined') {
|
|
363
|
+
defaultStorage().set<TokenData>(TOKEN_DATA, tokenData);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
public loadTokenData() {
|
|
368
|
+
if (typeof window !== 'undefined') {
|
|
369
|
+
this.tokenData = defaultStorage().get<TokenData>(TOKEN_DATA) || {};
|
|
370
|
+
} else {
|
|
371
|
+
this.tokenData = {};
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
public cleanTokenData() {
|
|
376
|
+
this.storeTokenData(null);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
private attachInterceptor(axios: AxiosInstance) {
|
|
380
|
+
axios.interceptors.response.use(
|
|
381
|
+
(res) => {
|
|
382
|
+
return res;
|
|
383
|
+
},
|
|
384
|
+
async (err) => {
|
|
385
|
+
let originalConfig = err.config;
|
|
386
|
+
if (err.response && !(err.response instanceof XMLHttpRequest)) { // sometimes buggy and is of type request
|
|
387
|
+
// Access Token was expired
|
|
388
|
+
if ((err.response.status === 401 || err.response.status === 403)
|
|
389
|
+
&& !originalConfig._retry) {
|
|
390
|
+
originalConfig._retry = true;
|
|
391
|
+
try {
|
|
392
|
+
const reply = await this.refreshTokenInternal();
|
|
393
|
+
this.tokenData.permissions = reply.permissions;
|
|
394
|
+
this.applyTokenReply(reply);
|
|
395
|
+
this.storeTokenData(this.tokenData);
|
|
396
|
+
|
|
397
|
+
if (!this.usesSession()) {
|
|
398
|
+
return axios(this.withCurrentAuth(originalConfig));
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// Both mode: if the browser does not send the session cookie (another site), use the token.
|
|
402
|
+
return axios(this.withCurrentAuth(originalConfig)).catch((retryError) => {
|
|
403
|
+
if (retryError?.response?.status !== 401 || !this.tokenData.accessToken) {
|
|
404
|
+
return Promise.reject(retryError);
|
|
405
|
+
}
|
|
406
|
+
return this.retryWithToken(axios, originalConfig);
|
|
407
|
+
});
|
|
408
|
+
} catch (_error) {
|
|
409
|
+
if (_error.response && _error.response.data) {
|
|
410
|
+
return Promise.reject(_error.response.data);
|
|
411
|
+
}
|
|
412
|
+
return Promise.reject(_error);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
} else if (err.message === NETWORK_ERROR_MESSAGE && this.canRetryWithToken(originalConfig)) {
|
|
416
|
+
// Both mode: the browser blocked the session call or hid its reply; later calls use the token.
|
|
417
|
+
if (!this.canResend(originalConfig)) {
|
|
418
|
+
this.switchToToken();
|
|
419
|
+
return Promise.reject(err);
|
|
420
|
+
}
|
|
421
|
+
return this.retryWithToken(axios, originalConfig);
|
|
422
|
+
} else if (err.message === NETWORK_ERROR_MESSAGE
|
|
423
|
+
&& (originalConfig.headers.hasOwnProperty('Authorization')
|
|
424
|
+
|| (this.configuration.cookieAuth && originalConfig.withCredentials && this.canResend(originalConfig)))
|
|
425
|
+
&& _retry_count < 4
|
|
426
|
+
) {
|
|
427
|
+
_retry_count++;
|
|
428
|
+
try {
|
|
429
|
+
// In session mode an unreadable 401 (no CORS headers on the error reply) also lands here.
|
|
430
|
+
const reply = await this.refreshTokenInternal();
|
|
431
|
+
this.tokenData.permissions = reply.permissions;
|
|
432
|
+
|
|
433
|
+
_retry = true;
|
|
434
|
+
this.applyTokenReply(reply);
|
|
435
|
+
this.storeTokenData(this.tokenData);
|
|
436
|
+
|
|
437
|
+
return axios.request({
|
|
438
|
+
...this.withCurrentAuth(originalConfig),
|
|
439
|
+
});
|
|
440
|
+
} catch (_error) {
|
|
441
|
+
if (_error.response && _error.response.data) {
|
|
442
|
+
return Promise.reject(_error.response.data);
|
|
443
|
+
}
|
|
444
|
+
return Promise.reject(_error);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
return Promise.reject(err);
|
|
448
|
+
}
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
*
|
|
455
|
+
* @export
|
|
456
|
+
* @class RequiredError
|
|
457
|
+
* @extends {Error}
|
|
458
|
+
*/
|
|
459
|
+
export class RequiredError extends Error {
|
|
460
|
+
override name: "RequiredError" = "RequiredError";
|
|
461
|
+
constructor(public field: string, msg?: string) {
|
|
462
|
+
super(msg);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
package/common.ts
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL Financemanager
|
|
5
|
+
* The EMIL Financemanager API description.
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 1.0
|
|
8
|
+
* Contact: kontakt@emil.de
|
|
9
|
+
*
|
|
10
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
11
|
+
* https://openapi-generator.tech
|
|
12
|
+
* Do not edit the class manually.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
import { Configuration } from "./configuration";
|
|
17
|
+
import { RequiredError, RequestArgs } from "./base";
|
|
18
|
+
import { AxiosInstance, AxiosResponse } from 'axios';
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @export
|
|
22
|
+
*/
|
|
23
|
+
export const DUMMY_BASE_URL = 'https://example.com'
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @throws {RequiredError}
|
|
28
|
+
* @export
|
|
29
|
+
*/
|
|
30
|
+
export const assertParamExists = function (functionName: string, paramName: string, paramValue: unknown) {
|
|
31
|
+
if (paramValue === null || paramValue === undefined) {
|
|
32
|
+
throw new RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* @export
|
|
39
|
+
*/
|
|
40
|
+
export const setApiKeyToObject = async function (object: any, keyParamName: string, configuration?: Configuration) {
|
|
41
|
+
if (configuration && configuration.apiKey) {
|
|
42
|
+
const localVarApiKeyValue = typeof configuration.apiKey === 'function'
|
|
43
|
+
? await configuration.apiKey(keyParamName)
|
|
44
|
+
: await configuration.apiKey;
|
|
45
|
+
object[keyParamName] = localVarApiKeyValue;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* @export
|
|
52
|
+
*/
|
|
53
|
+
export const setBasicAuthToObject = function (object: any, configuration?: Configuration) {
|
|
54
|
+
if (configuration && (configuration.username || configuration.password)) {
|
|
55
|
+
object["auth"] = { username: configuration.username, password: configuration.password };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
*
|
|
61
|
+
* @export
|
|
62
|
+
*/
|
|
63
|
+
export const setBearerAuthToObject = async function (object: any, configuration?: Configuration) {
|
|
64
|
+
if (configuration && configuration.accessToken) {
|
|
65
|
+
const accessToken = typeof configuration.accessToken === 'function'
|
|
66
|
+
? await configuration.accessToken()
|
|
67
|
+
: await configuration.accessToken;
|
|
68
|
+
object["Authorization"] = configuration.getBearerToken(accessToken);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
*
|
|
74
|
+
* @export
|
|
75
|
+
*/
|
|
76
|
+
export const setOAuthToObject = async function (object: any, name: string, scopes: string[], configuration?: Configuration) {
|
|
77
|
+
if (configuration && configuration.accessToken) {
|
|
78
|
+
const localVarAccessTokenValue = typeof configuration.accessToken === 'function'
|
|
79
|
+
? await configuration.accessToken(name, scopes)
|
|
80
|
+
: await configuration.accessToken;
|
|
81
|
+
object["Authorization"] = configuration.getBearerToken(localVarAccessTokenValue);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
*
|
|
87
|
+
* @export
|
|
88
|
+
*/
|
|
89
|
+
export const setSearchParams = function (url: URL, ...objects: any[]) {
|
|
90
|
+
const searchParams = new URLSearchParams(url.search);
|
|
91
|
+
for (const object of objects) {
|
|
92
|
+
for (const key in object) {
|
|
93
|
+
if (Array.isArray(object[key])) {
|
|
94
|
+
searchParams.delete(key);
|
|
95
|
+
for (const item of object[key]) {
|
|
96
|
+
searchParams.append(key, item);
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
searchParams.set(key, object[key]);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
url.search = searchParams.toString();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
*
|
|
108
|
+
* @export
|
|
109
|
+
*/
|
|
110
|
+
export const serializeDataIfNeeded = function (value: any, requestOptions: any, configuration?: Configuration) {
|
|
111
|
+
const nonString = typeof value !== 'string';
|
|
112
|
+
const needsSerialization = nonString && configuration && configuration.isJsonMime
|
|
113
|
+
? configuration.isJsonMime(requestOptions.headers['Content-Type'])
|
|
114
|
+
: nonString;
|
|
115
|
+
return needsSerialization
|
|
116
|
+
? JSON.stringify(value !== undefined ? value : {})
|
|
117
|
+
: (value || "");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
*
|
|
122
|
+
* @export
|
|
123
|
+
*/
|
|
124
|
+
export const toPathString = function (url: URL) {
|
|
125
|
+
return url.pathname + url.search + url.hash
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
*
|
|
130
|
+
* @export
|
|
131
|
+
*/
|
|
132
|
+
export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
|
|
133
|
+
// Typed by hand: since axios 1.20, request() returns an internal axios type that SDK declarations cannot name.
|
|
134
|
+
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH): Promise<R> => {
|
|
135
|
+
const axiosRequestArgs = {...axiosArgs.options, url: (configuration?.basePath || basePath) + axiosArgs.url};
|
|
136
|
+
return axios.request<T, R>(axiosRequestArgs) as Promise<R>;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/* tslint:disable */
|
|
141
|
+
/* eslint-disable */
|
|
142
|
+
/**
|
|
143
|
+
* EMIL Financemanager
|
|
144
|
+
* The EMIL Financemanager API description.
|
|
145
|
+
*
|
|
146
|
+
* The version of the OpenAPI document: 1.0
|
|
147
|
+
* Contact: kontakt@emil.de
|
|
148
|
+
*
|
|
149
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
150
|
+
* https://openapi-generator.tech
|
|
151
|
+
* Do not edit the class manually.
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
export interface IStorageConverter<D, SD> {
|
|
156
|
+
toStorageData( data: D ): SD;
|
|
157
|
+
fromStorageData( storageData: SD ): D;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface IStorage {
|
|
161
|
+
get<T>( key: string, converter?: IStorageConverter<T, any> ): T | null;
|
|
162
|
+
set<T>( key: string, value: T, converter?: IStorageConverter<T, any> ): void;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export class LocalStorage implements IStorage {
|
|
166
|
+
readonly storage: Storage;
|
|
167
|
+
|
|
168
|
+
constructor() {
|
|
169
|
+
this.storage = localStorage;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
get<T>( key: string, converter?: IStorageConverter<T, any> ): T | null {
|
|
173
|
+
const jsonValue = this.storage.getItem( key );
|
|
174
|
+
if ( jsonValue === null ) {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
const value = JSON.parse( jsonValue );
|
|
178
|
+
if ( converter !== undefined ) {
|
|
179
|
+
return converter.fromStorageData( value );
|
|
180
|
+
} else {
|
|
181
|
+
return value as T;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
set<T>( key: string, value: T, converter?: IStorageConverter<T, any> ): void {
|
|
186
|
+
let valueToStore: any = value;
|
|
187
|
+
if ( converter !== undefined ) {
|
|
188
|
+
valueToStore = converter.toStorageData( value );
|
|
189
|
+
}
|
|
190
|
+
const jsonValue = JSON.stringify( valueToStore );
|
|
191
|
+
this.storage.setItem( key, jsonValue );
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
let _defaultStorage: IStorage = null;
|
|
196
|
+
|
|
197
|
+
export const defaultStorage = (): IStorage => {
|
|
198
|
+
return _defaultStorage || (_defaultStorage = new LocalStorage());
|
|
199
|
+
};
|