@emilgroup/accounting-sdk-node 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.
Files changed (49) hide show
  1. package/.openapi-generator/FILES +21 -0
  2. package/.openapi-generator/VERSION +1 -0
  3. package/.openapi-generator-ignore +23 -0
  4. package/README.md +68 -0
  5. package/api/default-api.ts +128 -0
  6. package/api/financial-accounts-api.ts +571 -0
  7. package/api/transactions-api.ts +167 -0
  8. package/api.ts +35 -0
  9. package/base.ts +285 -0
  10. package/common.ts +199 -0
  11. package/configuration.ts +109 -0
  12. package/dist/api/default-api.d.ts +70 -0
  13. package/dist/api/default-api.js +204 -0
  14. package/dist/api/financial-accounts-api.d.ts +324 -0
  15. package/dist/api/financial-accounts-api.js +549 -0
  16. package/dist/api/transactions-api.d.ts +96 -0
  17. package/dist/api/transactions-api.js +228 -0
  18. package/dist/api.d.ts +14 -0
  19. package/dist/api.js +32 -0
  20. package/dist/base.d.ts +78 -0
  21. package/dist/base.js +394 -0
  22. package/dist/common.d.ts +92 -0
  23. package/dist/common.js +277 -0
  24. package/dist/configuration.d.ts +90 -0
  25. package/dist/configuration.js +44 -0
  26. package/dist/index.d.ts +15 -0
  27. package/dist/index.js +36 -0
  28. package/dist/models/create-financial-account-request-dto.d.ts +56 -0
  29. package/dist/models/create-financial-account-request-dto.js +23 -0
  30. package/dist/models/create-transaction-request-dto.d.ts +55 -0
  31. package/dist/models/create-transaction-request-dto.js +15 -0
  32. package/dist/models/entry-data-dto.d.ts +36 -0
  33. package/dist/models/entry-data-dto.js +15 -0
  34. package/dist/models/index.d.ts +5 -0
  35. package/dist/models/index.js +21 -0
  36. package/dist/models/inline-response200.d.ts +54 -0
  37. package/dist/models/inline-response200.js +15 -0
  38. package/dist/models/inline-response503.d.ts +54 -0
  39. package/dist/models/inline-response503.js +15 -0
  40. package/git_push.sh +57 -0
  41. package/index.ts +19 -0
  42. package/models/create-financial-account-request-dto.ts +65 -0
  43. package/models/create-transaction-request-dto.ts +61 -0
  44. package/models/entry-data-dto.ts +42 -0
  45. package/models/index.ts +5 -0
  46. package/models/inline-response200.ts +48 -0
  47. package/models/inline-response503.ts +48 -0
  48. package/package.json +29 -0
  49. package/tsconfig.json +22 -0
@@ -0,0 +1,167 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * EMIL AccountingService
5
+ * The EMIL AccountingService 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 globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios';
17
+ import { Configuration } from '../configuration';
18
+ // Some imports not used depending on template conditions
19
+ // @ts-ignore
20
+ import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from '../common';
21
+ // @ts-ignore
22
+ import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from '../base';
23
+ // @ts-ignore
24
+ import { CreateTransactionRequestDto } from '../models';
25
+ // URLSearchParams not necessarily used
26
+ // @ts-ignore
27
+ import { URL, URLSearchParams } from 'url';
28
+ const FormData = require('form-data');
29
+ /**
30
+ * TransactionsApi - axios parameter creator
31
+ * @export
32
+ */
33
+ export const TransactionsApiAxiosParamCreator = function (configuration?: Configuration) {
34
+ return {
35
+ /**
36
+ * Create a new transaction.
37
+ * @summary Create the Transaction
38
+ * @param {CreateTransactionRequestDto} createTransactionRequestDto
39
+ * @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
40
+ * @param {*} [options] Override http request option.
41
+ * @throws {RequiredError}
42
+ */
43
+ createTransaction: async (createTransactionRequestDto: CreateTransactionRequestDto, authorization?: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
44
+ // verify required parameter 'createTransactionRequestDto' is not null or undefined
45
+ assertParamExists('createTransaction', 'createTransactionRequestDto', createTransactionRequestDto)
46
+ const localVarPath = `/accountingservice/v1/transactions`;
47
+ // use dummy base URL string because the URL constructor only accepts absolute URLs.
48
+ const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
49
+ let baseOptions;
50
+ let baseAccessToken;
51
+ if (configuration) {
52
+ baseOptions = configuration.baseOptions;
53
+ baseAccessToken = configuration.accessToken;
54
+ }
55
+
56
+ const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
57
+ const localVarHeaderParameter = {} as any;
58
+ const localVarQueryParameter = {} as any;
59
+
60
+ // authentication bearer required
61
+ // http bearer authentication required
62
+ await setBearerAuthToObject(localVarHeaderParameter, configuration)
63
+
64
+ if (authorization !== undefined && authorization !== null || baseAccessToken !== undefined && baseAccessToken !== null) {
65
+ localVarHeaderParameter['Authorization'] = String(authorization ? authorization : baseAccessToken);
66
+ }
67
+
68
+
69
+
70
+ localVarHeaderParameter['Content-Type'] = 'application/json';
71
+
72
+ setSearchParams(localVarUrlObj, localVarQueryParameter);
73
+ let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
74
+ localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
75
+ localVarRequestOptions.data = serializeDataIfNeeded(createTransactionRequestDto, localVarRequestOptions, configuration)
76
+
77
+ return {
78
+ url: toPathString(localVarUrlObj),
79
+ options: localVarRequestOptions,
80
+ };
81
+ },
82
+ }
83
+ };
84
+
85
+ /**
86
+ * TransactionsApi - functional programming interface
87
+ * @export
88
+ */
89
+ export const TransactionsApiFp = function(configuration?: Configuration) {
90
+ const localVarAxiosParamCreator = TransactionsApiAxiosParamCreator(configuration)
91
+ return {
92
+ /**
93
+ * Create a new transaction.
94
+ * @summary Create the Transaction
95
+ * @param {CreateTransactionRequestDto} createTransactionRequestDto
96
+ * @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
97
+ * @param {*} [options] Override http request option.
98
+ * @throws {RequiredError}
99
+ */
100
+ async createTransaction(createTransactionRequestDto: CreateTransactionRequestDto, authorization?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
101
+ const localVarAxiosArgs = await localVarAxiosParamCreator.createTransaction(createTransactionRequestDto, authorization, options);
102
+ return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
103
+ },
104
+ }
105
+ };
106
+
107
+ /**
108
+ * TransactionsApi - factory interface
109
+ * @export
110
+ */
111
+ export const TransactionsApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
112
+ const localVarFp = TransactionsApiFp(configuration)
113
+ return {
114
+ /**
115
+ * Create a new transaction.
116
+ * @summary Create the Transaction
117
+ * @param {CreateTransactionRequestDto} createTransactionRequestDto
118
+ * @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
119
+ * @param {*} [options] Override http request option.
120
+ * @throws {RequiredError}
121
+ */
122
+ createTransaction(createTransactionRequestDto: CreateTransactionRequestDto, authorization?: string, options?: any): AxiosPromise<void> {
123
+ return localVarFp.createTransaction(createTransactionRequestDto, authorization, options).then((request) => request(axios, basePath));
124
+ },
125
+ };
126
+ };
127
+
128
+ /**
129
+ * Request parameters for createTransaction operation in TransactionsApi.
130
+ * @export
131
+ * @interface TransactionsApiCreateTransactionRequest
132
+ */
133
+ export interface TransactionsApiCreateTransactionRequest {
134
+ /**
135
+ *
136
+ * @type {CreateTransactionRequestDto}
137
+ * @memberof TransactionsApiCreateTransaction
138
+ */
139
+ readonly createTransactionRequestDto: CreateTransactionRequestDto
140
+
141
+ /**
142
+ * Bearer Token: provided by the login endpoint under the name accessToken.
143
+ * @type {string}
144
+ * @memberof TransactionsApiCreateTransaction
145
+ */
146
+ readonly authorization?: string
147
+ }
148
+
149
+ /**
150
+ * TransactionsApi - object-oriented interface
151
+ * @export
152
+ * @class TransactionsApi
153
+ * @extends {BaseAPI}
154
+ */
155
+ export class TransactionsApi extends BaseAPI {
156
+ /**
157
+ * Create a new transaction.
158
+ * @summary Create the Transaction
159
+ * @param {TransactionsApiCreateTransactionRequest} requestParameters Request parameters.
160
+ * @param {*} [options] Override http request option.
161
+ * @throws {RequiredError}
162
+ * @memberof TransactionsApi
163
+ */
164
+ public createTransaction(requestParameters: TransactionsApiCreateTransactionRequest, options?: AxiosRequestConfig) {
165
+ return TransactionsApiFp(this.configuration).createTransaction(requestParameters.createTransactionRequestDto, requestParameters.authorization, options).then((request) => request(this.axios, this.basePath));
166
+ }
167
+ }
package/api.ts ADDED
@@ -0,0 +1,35 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * EMIL AccountingService
5
+ * The EMIL AccountingService 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 globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
18
+ // URLSearchParams not necessarily used
19
+ // @ts-ignore
20
+ import { URL, URLSearchParams } from 'url';
21
+ import FormData from 'form-data'
22
+ // Some imports not used depending on template conditions
23
+ // @ts-ignore
24
+ import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from './common';
25
+ // @ts-ignore
26
+ import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from './base';
27
+ import { DefaultApi } from './api';
28
+ import { FinancialAccountsApi } from './api';
29
+ import { TransactionsApi } from './api';
30
+
31
+
32
+ export * from './api/default-api';
33
+ export * from './api/financial-accounts-api';
34
+ export * from './api/transactions-api';
35
+
package/base.ts ADDED
@@ -0,0 +1,285 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * EMIL AccountingService
5
+ * The EMIL AccountingService 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
+ // Some imports not used depending on template conditions
18
+ // @ts-ignore
19
+ import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
20
+ import * as fs from 'fs';
21
+ import * as path from 'path';
22
+ import * as os from 'os';
23
+
24
+ export const BASE_PATH = "https://apiv2.emil.de".replace(/\/+$/, "");
25
+ const CONFIG_DIRECTORY = '.emil';
26
+ const CONFIG_FILENAME = 'credentials';
27
+ const KEY_USERNAME = 'emil_username';
28
+ const KEY_PASSWORD = 'emil_password';
29
+
30
+ const filePath = os.homedir() + path.sep + CONFIG_DIRECTORY + path.sep + CONFIG_FILENAME;
31
+ /**
32
+ *
33
+ * @export
34
+ */
35
+ export const COLLECTION_FORMATS = {
36
+ csv: ",",
37
+ ssv: " ",
38
+ tsv: "\t",
39
+ pipes: "|",
40
+ };
41
+
42
+ export interface LoginClass {
43
+ accessToken: string;
44
+ permissions: Array<string>;
45
+ }
46
+
47
+ export enum Environment {
48
+ Production = 'https://apiv2.emil.de',
49
+ Test = 'https://apiv2-test.emil.de',
50
+ Development = 'https://apiv2-dev.emil.de',
51
+ ProductionZurich = 'https://eu-central-2.apiv2.emil.de',
52
+ }
53
+
54
+ let _retry_count = 0
55
+ let _retry = null
56
+
57
+ export function resetRetry() {
58
+ _retry_count = 0
59
+ }
60
+
61
+ /**
62
+ *
63
+ * @export
64
+ * @interface RequestArgs
65
+ */
66
+ export interface RequestArgs {
67
+ url: string;
68
+ options: AxiosRequestConfig;
69
+ }
70
+
71
+ const NETWORK_ERROR_MESSAGE = "Network Error";
72
+
73
+ /**
74
+ *
75
+ * @export
76
+ * @class BaseAPI
77
+ */
78
+ export class BaseAPI {
79
+ protected configuration: Configuration;
80
+ private username?: string;
81
+ private password?: string;
82
+
83
+ constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) {
84
+ if (configuration) {
85
+ this.configuration = configuration;
86
+ this.basePath = configuration.basePath || this.basePath;
87
+ } else {
88
+ this.configuration = new Configuration({
89
+ basePath: this.basePath,
90
+ });
91
+ }
92
+
93
+ this.attachInterceptor(axios);
94
+ }
95
+
96
+ async initialize(env: Environment = Environment.Production) {
97
+ this.configuration.basePath = env;
98
+
99
+ await this.loadCredentials();
100
+
101
+ if (this.username) {
102
+ await this.authorize(this.username, this.password);
103
+ this.password = null; // to avoid keeping password loaded in memory.
104
+ }
105
+ }
106
+
107
+ private async loadCredentials() {
108
+ try {
109
+ await this.readConfigFile();
110
+ } catch (error) {
111
+ console.warn(`No credentials file found. Check that ${filePath} exists.`);
112
+ }
113
+
114
+ this.readEnvVariables();
115
+
116
+ if (!this.username) {
117
+ console.info(`No credentials found in credentials file or environment variables. Either provide some or use
118
+ authorize() function.`);
119
+ }
120
+ }
121
+
122
+ private async readConfigFile() {
123
+ const file = await fs.promises.readFile(filePath, 'utf-8');
124
+
125
+ const lines = file.split(os.EOL)
126
+ .filter(Boolean);
127
+
128
+ lines.forEach((line: string) => {
129
+ if (line.startsWith(KEY_USERNAME)) {
130
+ this.username = line.length > KEY_USERNAME.length + 1 ? line.substring(KEY_USERNAME.length + 1) : '';
131
+ } else if (line.startsWith(KEY_PASSWORD)) {
132
+ this.password = line.length > KEY_PASSWORD.length + 1 ? line.substring(KEY_PASSWORD.length + 1) : '';
133
+ }
134
+ });
135
+ }
136
+
137
+ private readEnvVariables(): boolean {
138
+ if (process.env.EMIL_USERNAME) {
139
+ this.username = process.env.EMIL_USERNAME;
140
+ this.password = process.env.EMIL_PASSWORD || '';
141
+
142
+ return true;
143
+ }
144
+
145
+ return false;
146
+ }
147
+
148
+ selectEnvironment(env: Environment) {
149
+ this.configuration.basePath = env;
150
+ }
151
+
152
+ async authorize(username: string, password: string): Promise<void> {
153
+ const options: AxiosRequestConfig = {
154
+ method: 'POST',
155
+ url: `${this.configuration.basePath}/authservice/v1/login`,
156
+ headers: { 'Content-Type': 'application/json' },
157
+ data: {
158
+ username,
159
+ password,
160
+ },
161
+ withCredentials: true,
162
+ };
163
+
164
+ const response = await globalAxios.request<LoginClass>(options);
165
+
166
+ const { data: { accessToken } } = response;
167
+ this.configuration.username = username;
168
+ this.configuration.accessToken = `Bearer ${accessToken}`;
169
+
170
+ const refreshToken = this.extractRefreshToken(response)
171
+ this.configuration.refreshToken = refreshToken;
172
+ }
173
+
174
+ async refreshTokenInternal(): Promise<string> {
175
+ const { username, refreshToken } = this.configuration;
176
+
177
+
178
+ if (!username || !refreshToken) {
179
+ return '';
180
+ }
181
+
182
+ const options: AxiosRequestConfig = {
183
+ method: 'POST',
184
+ url: `${this.configuration.basePath}/authservice/v1/refresh-token`,
185
+ headers: {
186
+ 'Content-Type': 'application/json',
187
+ Cookie: refreshToken,
188
+ },
189
+ data: { username: username },
190
+ withCredentials: true,
191
+ };
192
+
193
+ const { data: { accessToken } } = await globalAxios.request<LoginClass>(options);
194
+
195
+ return accessToken;
196
+ }
197
+
198
+ private extractRefreshToken(response: AxiosResponse): string {
199
+ if (response.headers && response.headers['set-cookie']
200
+ && response.headers['set-cookie'].length > 0) {
201
+
202
+ return `${response.headers['set-cookie'][0].split(';')[0]};`;
203
+ }
204
+
205
+ return '';
206
+ }
207
+
208
+ getConfiguration(): Configuration {
209
+ return this.configuration;
210
+ }
211
+
212
+ private attachInterceptor(axios: AxiosInstance) {
213
+ axios.interceptors.response.use(
214
+ (res) => {
215
+ return res;
216
+ },
217
+ async (err) => {
218
+ let originalConfig = err.config;
219
+ if (err.response) {
220
+ // Access Token was expired
221
+ if (err.response.status === 401 && !originalConfig._retry) {
222
+ originalConfig._retry = true;
223
+ try {
224
+ const tokenString = await this.refreshTokenInternal();
225
+ const accessToken = `Bearer ${tokenString}`;
226
+
227
+ originalConfig.headers['Authorization'] = `Bearer ${accessToken}`
228
+
229
+ this.configuration.accessToken = accessToken;
230
+
231
+ return axios.request(originalConfig);
232
+ } catch (_error) {
233
+ if (_error.response && _error.response.data) {
234
+ return Promise.reject(_error.response.data);
235
+ }
236
+ return Promise.reject(_error);
237
+ }
238
+ }
239
+ if (err.response.status === 403 && err.response.data) {
240
+ return Promise.reject(err.response.data);
241
+ }
242
+ } else if(err.message === NETWORK_ERROR_MESSAGE
243
+ && err.isAxiosError
244
+ && originalConfig.headers.hasOwnProperty('Authorization')
245
+ && _retry_count < 4
246
+ ){
247
+ _retry_count++;
248
+ try {
249
+ const tokenString = await this.refreshTokenInternal();
250
+ const accessToken = `Bearer ${tokenString}`;
251
+
252
+ _retry = true;
253
+ originalConfig.headers['Authorization'] = accessToken;
254
+
255
+ this.configuration.accessToken = accessToken;
256
+
257
+ return axios.request({
258
+ ...originalConfig,
259
+ });
260
+ } catch (_error) {
261
+ if (_error.response && _error.response.data) {
262
+ return Promise.reject(_error.response.data);
263
+ }
264
+ return Promise.reject(_error);
265
+ }
266
+ }
267
+ return Promise.reject(err);
268
+ }
269
+ );
270
+ }
271
+ };
272
+
273
+ /**
274
+ *
275
+ * @export
276
+ * @class RequiredError
277
+ * @extends {Error}
278
+ */
279
+ export class RequiredError extends Error {
280
+ name: "RequiredError" = "RequiredError";
281
+ constructor(public field: string, msg?: string) {
282
+ super(msg);
283
+ }
284
+ }
285
+
package/common.ts ADDED
@@ -0,0 +1,199 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * EMIL AccountingService
5
+ * The EMIL AccountingService 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
+ import { URL, URLSearchParams } from 'url';
20
+ /**
21
+ *
22
+ * @export
23
+ */
24
+ export const DUMMY_BASE_URL = 'https://example.com'
25
+
26
+ /**
27
+ *
28
+ * @throws {RequiredError}
29
+ * @export
30
+ */
31
+ export const assertParamExists = function (functionName: string, paramName: string, paramValue: unknown) {
32
+ if (paramValue === null || paramValue === undefined) {
33
+ throw new RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`);
34
+ }
35
+ }
36
+
37
+ /**
38
+ *
39
+ * @export
40
+ */
41
+ export const setApiKeyToObject = async function (object: any, keyParamName: string, configuration?: Configuration) {
42
+ if (configuration && configuration.apiKey) {
43
+ const localVarApiKeyValue = typeof configuration.apiKey === 'function'
44
+ ? await configuration.apiKey(keyParamName)
45
+ : await configuration.apiKey;
46
+ object[keyParamName] = localVarApiKeyValue;
47
+ }
48
+ }
49
+
50
+ /**
51
+ *
52
+ * @export
53
+ */
54
+ export const setBasicAuthToObject = function (object: any, configuration?: Configuration) {
55
+ if (configuration && (configuration.username || configuration.password)) {
56
+ object["auth"] = { username: configuration.username, password: configuration.password };
57
+ }
58
+ }
59
+
60
+ /**
61
+ *
62
+ * @export
63
+ */
64
+ export const setBearerAuthToObject = async function (object: any, configuration?: Configuration) {
65
+ if (configuration && configuration.accessToken) {
66
+ const accessToken = typeof configuration.accessToken === 'function'
67
+ ? await configuration.accessToken()
68
+ : await configuration.accessToken;
69
+ object["Authorization"] = "Bearer " + accessToken;
70
+ }
71
+ }
72
+
73
+ /**
74
+ *
75
+ * @export
76
+ */
77
+ export const setOAuthToObject = async function (object: any, name: string, scopes: string[], configuration?: Configuration) {
78
+ if (configuration && configuration.accessToken) {
79
+ const localVarAccessTokenValue = typeof configuration.accessToken === 'function'
80
+ ? await configuration.accessToken(name, scopes)
81
+ : await configuration.accessToken;
82
+ object["Authorization"] = "Bearer " + localVarAccessTokenValue;
83
+ }
84
+ }
85
+
86
+ /**
87
+ *
88
+ * @export
89
+ */
90
+ export const setSearchParams = function (url: URL, ...objects: any[]) {
91
+ const searchParams = new URLSearchParams(url.search);
92
+ for (const object of objects) {
93
+ for (const key in object) {
94
+ if (Array.isArray(object[key])) {
95
+ searchParams.delete(key);
96
+ for (const item of object[key]) {
97
+ searchParams.append(key, item);
98
+ }
99
+ } else {
100
+ searchParams.set(key, object[key]);
101
+ }
102
+ }
103
+ }
104
+ url.search = searchParams.toString();
105
+ }
106
+
107
+ /**
108
+ *
109
+ * @export
110
+ */
111
+ export const serializeDataIfNeeded = function (value: any, requestOptions: any, configuration?: Configuration) {
112
+ const nonString = typeof value !== 'string';
113
+ const needsSerialization = nonString && configuration && configuration.isJsonMime
114
+ ? configuration.isJsonMime(requestOptions.headers['Content-Type'])
115
+ : nonString;
116
+ return needsSerialization
117
+ ? JSON.stringify(value !== undefined ? value : {})
118
+ : (value || "");
119
+ }
120
+
121
+ /**
122
+ *
123
+ * @export
124
+ */
125
+ export const toPathString = function (url: URL) {
126
+ return url.pathname + url.search + url.hash
127
+ }
128
+
129
+ /**
130
+ *
131
+ * @export
132
+ */
133
+ export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
134
+ return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
135
+ const axiosRequestArgs = {...axiosArgs.options, url: (configuration?.basePath || basePath) + axiosArgs.url};
136
+ return axios.request<T, R>(axiosRequestArgs);
137
+ };
138
+ }
139
+
140
+ /* tslint:disable */
141
+ /* eslint-disable */
142
+ /**
143
+ * EMIL AccountingService
144
+ * The EMIL AccountingService 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
+ };