@emilgroup/commission-sdk-node 1.0.0-beta.1
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 +40 -0
- package/.openapi-generator/VERSION +1 -0
- package/.openapi-generator-ignore +23 -0
- package/README.md +84 -0
- package/api/commission-agreement-versions-api.ts +535 -0
- package/api/commission-agreements-api.ts +642 -0
- package/api/commissions-api.ts +641 -0
- package/api/default-api.ts +128 -0
- package/api.ts +37 -0
- package/base.ts +327 -0
- package/common.ts +199 -0
- package/configuration.ts +118 -0
- package/dist/api/commission-agreement-versions-api.d.ts +300 -0
- package/dist/api/commission-agreement-versions-api.js +531 -0
- package/dist/api/commission-agreements-api.d.ts +357 -0
- package/dist/api/commission-agreements-api.js +624 -0
- package/dist/api/commissions-api.d.ts +357 -0
- package/dist/api/commissions-api.js +624 -0
- package/dist/api/default-api.d.ts +70 -0
- package/dist/api/default-api.js +204 -0
- package/dist/api.d.ts +15 -0
- package/dist/api.js +33 -0
- package/dist/base.d.ts +88 -0
- package/dist/base.js +434 -0
- package/dist/common.d.ts +92 -0
- package/dist/common.js +277 -0
- package/dist/configuration.d.ts +96 -0
- package/dist/configuration.js +52 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +36 -0
- package/dist/models/commission-agreement-class.d.ts +89 -0
- package/dist/models/commission-agreement-class.js +25 -0
- package/dist/models/commission-agreement-version-class.d.ts +79 -0
- package/dist/models/commission-agreement-version-class.js +15 -0
- package/dist/models/commission-class.d.ts +103 -0
- package/dist/models/commission-class.js +15 -0
- package/dist/models/commission-item-class.d.ts +84 -0
- package/dist/models/commission-item-class.js +21 -0
- package/dist/models/create-commission-agreement-request-dto.d.ts +71 -0
- package/dist/models/create-commission-agreement-request-dto.js +25 -0
- package/dist/models/create-commission-agreement-response-class.d.ts +25 -0
- package/dist/models/create-commission-agreement-response-class.js +15 -0
- package/dist/models/create-commission-agreement-version-request-dto.d.ts +42 -0
- package/dist/models/create-commission-agreement-version-request-dto.js +15 -0
- package/dist/models/create-commission-agreement-version-response-class.d.ts +25 -0
- package/dist/models/create-commission-agreement-version-response-class.js +15 -0
- package/dist/models/create-commission-item-request-dto.d.ts +48 -0
- package/dist/models/create-commission-item-request-dto.js +21 -0
- package/dist/models/create-commission-request-dto.d.ts +55 -0
- package/dist/models/create-commission-request-dto.js +15 -0
- package/dist/models/create-commission-response-class.d.ts +25 -0
- package/dist/models/create-commission-response-class.js +15 -0
- package/dist/models/get-commission-agreement-response-class.d.ts +25 -0
- package/dist/models/get-commission-agreement-response-class.js +15 -0
- package/dist/models/get-commission-agreement-version-response-class.d.ts +25 -0
- package/dist/models/get-commission-agreement-version-response-class.js +15 -0
- package/dist/models/get-commission-response-class.d.ts +25 -0
- package/dist/models/get-commission-response-class.js +15 -0
- package/dist/models/index.d.ts +23 -0
- package/dist/models/index.js +39 -0
- package/dist/models/inline-response200.d.ts +54 -0
- package/dist/models/inline-response200.js +15 -0
- package/dist/models/inline-response503.d.ts +54 -0
- package/dist/models/inline-response503.js +15 -0
- package/dist/models/list-commission-agreement-versions-response-class.d.ts +43 -0
- package/dist/models/list-commission-agreement-versions-response-class.js +15 -0
- package/dist/models/list-commission-agreements-response-class.d.ts +43 -0
- package/dist/models/list-commission-agreements-response-class.js +15 -0
- package/dist/models/list-commissions-response-class.d.ts +43 -0
- package/dist/models/list-commissions-response-class.js +15 -0
- package/dist/models/update-commission-agreement-request-dto.d.ts +48 -0
- package/dist/models/update-commission-agreement-request-dto.js +21 -0
- package/dist/models/update-commission-agreement-response-class.d.ts +25 -0
- package/dist/models/update-commission-agreement-response-class.js +15 -0
- package/dist/models/update-commission-request-dto.d.ts +53 -0
- package/dist/models/update-commission-request-dto.js +20 -0
- package/dist/models/update-commission-response-class.d.ts +25 -0
- package/dist/models/update-commission-response-class.js +15 -0
- package/git_push.sh +57 -0
- package/index.ts +19 -0
- package/models/commission-agreement-class.ts +99 -0
- package/models/commission-agreement-version-class.ts +85 -0
- package/models/commission-class.ts +109 -0
- package/models/commission-item-class.ts +93 -0
- package/models/create-commission-agreement-request-dto.ts +81 -0
- package/models/create-commission-agreement-response-class.ts +31 -0
- package/models/create-commission-agreement-version-request-dto.ts +48 -0
- package/models/create-commission-agreement-version-response-class.ts +31 -0
- package/models/create-commission-item-request-dto.ts +57 -0
- package/models/create-commission-request-dto.ts +61 -0
- package/models/create-commission-response-class.ts +31 -0
- package/models/get-commission-agreement-response-class.ts +31 -0
- package/models/get-commission-agreement-version-response-class.ts +31 -0
- package/models/get-commission-response-class.ts +31 -0
- package/models/index.ts +23 -0
- package/models/inline-response200.ts +48 -0
- package/models/inline-response503.ts +48 -0
- package/models/list-commission-agreement-versions-response-class.ts +49 -0
- package/models/list-commission-agreements-response-class.ts +49 -0
- package/models/list-commissions-response-class.ts +49 -0
- package/models/update-commission-agreement-request-dto.ts +57 -0
- package/models/update-commission-agreement-response-class.ts +31 -0
- package/models/update-commission-request-dto.ts +62 -0
- package/models/update-commission-response-class.ts +31 -0
- package/package.json +29 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL CommissionService
|
|
5
|
+
* The EMIL CommissionService 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 { InlineResponse200 } from '../models';
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
import { InlineResponse503 } from '../models';
|
|
27
|
+
// URLSearchParams not necessarily used
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
import { URL, URLSearchParams } from 'url';
|
|
30
|
+
const FormData = require('form-data');
|
|
31
|
+
/**
|
|
32
|
+
* DefaultApi - axios parameter creator
|
|
33
|
+
* @export
|
|
34
|
+
*/
|
|
35
|
+
export const DefaultApiAxiosParamCreator = function (configuration?: Configuration) {
|
|
36
|
+
return {
|
|
37
|
+
/**
|
|
38
|
+
* Returns the health status of the CommissionService service. This endpoint is used to monitor the operational status of the CommissionService service. It typically returns a simple status indicator, such as \'UP\' or \'OK\', confirming that the service is operational and available.
|
|
39
|
+
* @summary Health Check
|
|
40
|
+
* @param {*} [options] Override http request option.
|
|
41
|
+
* @throws {RequiredError}
|
|
42
|
+
*/
|
|
43
|
+
check: async (options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
|
44
|
+
const localVarPath = `/commissionservice/health`;
|
|
45
|
+
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
46
|
+
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
47
|
+
let baseOptions;
|
|
48
|
+
let baseAccessToken;
|
|
49
|
+
if (configuration) {
|
|
50
|
+
baseOptions = configuration.baseOptions;
|
|
51
|
+
baseAccessToken = configuration.accessToken;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
|
|
55
|
+
const localVarHeaderParameter = {} as any;
|
|
56
|
+
const localVarQueryParameter = {} as any;
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
61
|
+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
62
|
+
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
url: toPathString(localVarUrlObj),
|
|
66
|
+
options: localVarRequestOptions,
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* DefaultApi - functional programming interface
|
|
74
|
+
* @export
|
|
75
|
+
*/
|
|
76
|
+
export const DefaultApiFp = function(configuration?: Configuration) {
|
|
77
|
+
const localVarAxiosParamCreator = DefaultApiAxiosParamCreator(configuration)
|
|
78
|
+
return {
|
|
79
|
+
/**
|
|
80
|
+
* Returns the health status of the CommissionService service. This endpoint is used to monitor the operational status of the CommissionService service. It typically returns a simple status indicator, such as \'UP\' or \'OK\', confirming that the service is operational and available.
|
|
81
|
+
* @summary Health Check
|
|
82
|
+
* @param {*} [options] Override http request option.
|
|
83
|
+
* @throws {RequiredError}
|
|
84
|
+
*/
|
|
85
|
+
async check(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<InlineResponse200>> {
|
|
86
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.check(options);
|
|
87
|
+
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
88
|
+
},
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* DefaultApi - factory interface
|
|
94
|
+
* @export
|
|
95
|
+
*/
|
|
96
|
+
export const DefaultApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
|
|
97
|
+
const localVarFp = DefaultApiFp(configuration)
|
|
98
|
+
return {
|
|
99
|
+
/**
|
|
100
|
+
* Returns the health status of the CommissionService service. This endpoint is used to monitor the operational status of the CommissionService service. It typically returns a simple status indicator, such as \'UP\' or \'OK\', confirming that the service is operational and available.
|
|
101
|
+
* @summary Health Check
|
|
102
|
+
* @param {*} [options] Override http request option.
|
|
103
|
+
* @throws {RequiredError}
|
|
104
|
+
*/
|
|
105
|
+
check(options?: any): AxiosPromise<InlineResponse200> {
|
|
106
|
+
return localVarFp.check(options).then((request) => request(axios, basePath));
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* DefaultApi - object-oriented interface
|
|
113
|
+
* @export
|
|
114
|
+
* @class DefaultApi
|
|
115
|
+
* @extends {BaseAPI}
|
|
116
|
+
*/
|
|
117
|
+
export class DefaultApi extends BaseAPI {
|
|
118
|
+
/**
|
|
119
|
+
* Returns the health status of the CommissionService service. This endpoint is used to monitor the operational status of the CommissionService service. It typically returns a simple status indicator, such as \'UP\' or \'OK\', confirming that the service is operational and available.
|
|
120
|
+
* @summary Health Check
|
|
121
|
+
* @param {*} [options] Override http request option.
|
|
122
|
+
* @throws {RequiredError}
|
|
123
|
+
* @memberof DefaultApi
|
|
124
|
+
*/
|
|
125
|
+
public check(options?: AxiosRequestConfig) {
|
|
126
|
+
return DefaultApiFp(this.configuration).check(options).then((request) => request(this.axios, this.basePath));
|
|
127
|
+
}
|
|
128
|
+
}
|
package/api.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL CommissionService
|
|
5
|
+
* The EMIL CommissionService 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 { CommissionAgreementVersionsApi } from './api';
|
|
28
|
+
import { CommissionAgreementsApi } from './api';
|
|
29
|
+
import { CommissionsApi } from './api';
|
|
30
|
+
import { DefaultApi } from './api';
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
export * from './api/commission-agreement-versions-api';
|
|
34
|
+
export * from './api/commission-agreements-api';
|
|
35
|
+
export * from './api/commissions-api';
|
|
36
|
+
export * from './api/default-api';
|
|
37
|
+
|
package/base.ts
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL CommissionService
|
|
5
|
+
* The EMIL CommissionService 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: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface SwitchWorkspaceRequest {
|
|
48
|
+
username: string;
|
|
49
|
+
targetWorkspace: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface SwitchWorkspaceResponseClass {
|
|
53
|
+
accessToken: string;
|
|
54
|
+
permissions: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export enum Environment {
|
|
58
|
+
Production = 'https://apiv2.emil.de',
|
|
59
|
+
Test = 'https://apiv2-test.emil.de',
|
|
60
|
+
Staging = 'https://apiv2-staging.emil.de',
|
|
61
|
+
Development = 'https://apiv2-dev.emil.de',
|
|
62
|
+
ProductionZurich = 'https://eu-central-2.apiv2.emil.de',
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let _retry_count = 0
|
|
66
|
+
let _retry = null
|
|
67
|
+
|
|
68
|
+
export function resetRetry() {
|
|
69
|
+
_retry_count = 0
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
*
|
|
74
|
+
* @export
|
|
75
|
+
* @interface RequestArgs
|
|
76
|
+
*/
|
|
77
|
+
export interface RequestArgs {
|
|
78
|
+
url: string;
|
|
79
|
+
options: AxiosRequestConfig;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const NETWORK_ERROR_MESSAGE = "Network Error";
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
*
|
|
86
|
+
* @export
|
|
87
|
+
* @class BaseAPI
|
|
88
|
+
*/
|
|
89
|
+
export class BaseAPI {
|
|
90
|
+
protected configuration: Configuration;
|
|
91
|
+
private username?: string;
|
|
92
|
+
private password?: string;
|
|
93
|
+
|
|
94
|
+
constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) {
|
|
95
|
+
if (configuration) {
|
|
96
|
+
this.configuration = configuration;
|
|
97
|
+
this.basePath = configuration.basePath || this.basePath;
|
|
98
|
+
} else {
|
|
99
|
+
this.configuration = new Configuration({
|
|
100
|
+
basePath: this.basePath,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
this.attachInterceptor(axios);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async initialize(env: Environment = Environment.Production, targetWorkspace?: string) {
|
|
108
|
+
this.configuration.basePath = env;
|
|
109
|
+
|
|
110
|
+
await this.loadCredentials();
|
|
111
|
+
|
|
112
|
+
if (this.username) {
|
|
113
|
+
await this.authorize(this.username, this.password, targetWorkspace);
|
|
114
|
+
this.password = null; // to avoid keeping password loaded in memory.
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private async loadCredentials() {
|
|
119
|
+
try {
|
|
120
|
+
await this.readConfigFile();
|
|
121
|
+
} catch (error) {
|
|
122
|
+
console.warn(`No credentials file found. Check that ${filePath} exists.`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
this.readEnvVariables();
|
|
126
|
+
|
|
127
|
+
if (!this.username) {
|
|
128
|
+
console.info(`No credentials found in credentials file or environment variables. Either provide some or use
|
|
129
|
+
authorize() function.`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private async readConfigFile() {
|
|
134
|
+
const file = await fs.promises.readFile(filePath, 'utf-8');
|
|
135
|
+
|
|
136
|
+
const lines = file.split(os.EOL)
|
|
137
|
+
.filter(Boolean);
|
|
138
|
+
|
|
139
|
+
lines.forEach((line: string) => {
|
|
140
|
+
if (line.startsWith(KEY_USERNAME)) {
|
|
141
|
+
this.username = line.length > KEY_USERNAME.length + 1 ? line.substring(KEY_USERNAME.length + 1) : '';
|
|
142
|
+
} else if (line.startsWith(KEY_PASSWORD)) {
|
|
143
|
+
this.password = line.length > KEY_PASSWORD.length + 1 ? line.substring(KEY_PASSWORD.length + 1) : '';
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private readEnvVariables(): boolean {
|
|
149
|
+
if (process.env.EMIL_USERNAME) {
|
|
150
|
+
this.username = process.env.EMIL_USERNAME;
|
|
151
|
+
this.password = process.env.EMIL_PASSWORD || '';
|
|
152
|
+
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
selectEnvironment(env: Environment) {
|
|
160
|
+
this.configuration.basePath = env;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async authorize(username: string, password: string, targetWorkspace?: string): Promise<void> {
|
|
164
|
+
const options: AxiosRequestConfig = {
|
|
165
|
+
method: 'POST',
|
|
166
|
+
url: `${this.configuration.basePath}/authservice/v1/login`,
|
|
167
|
+
headers: { 'Content-Type': 'application/json' },
|
|
168
|
+
data: {
|
|
169
|
+
username,
|
|
170
|
+
password,
|
|
171
|
+
},
|
|
172
|
+
withCredentials: true,
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const response = await globalAxios.request<LoginClass>(options);
|
|
176
|
+
|
|
177
|
+
const { data: { accessToken } } = response;
|
|
178
|
+
this.configuration.username = username;
|
|
179
|
+
this.configuration.accessToken = `Bearer ${accessToken}`;
|
|
180
|
+
|
|
181
|
+
const refreshToken = this.extractRefreshToken(response)
|
|
182
|
+
this.configuration.refreshToken = refreshToken;
|
|
183
|
+
|
|
184
|
+
// Switch workspace if provided
|
|
185
|
+
if (targetWorkspace) {
|
|
186
|
+
await this.switchWorkspace(targetWorkspace);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
async switchWorkspace(targetWorkspace: string): Promise<void> {
|
|
190
|
+
const options: AxiosRequestConfig = {
|
|
191
|
+
method: 'POST',
|
|
192
|
+
url: `${this.configuration.basePath}/authservice/v1/workspaces/switch`,
|
|
193
|
+
headers: {
|
|
194
|
+
'Content-Type': 'application/json',
|
|
195
|
+
'Authorization': `Bearer ${this.configuration.accessToken}`,
|
|
196
|
+
'Cookie': this.configuration.refreshToken,
|
|
197
|
+
},
|
|
198
|
+
data: {
|
|
199
|
+
username: this.configuration.username,
|
|
200
|
+
targetWorkspace,
|
|
201
|
+
} as SwitchWorkspaceRequest,
|
|
202
|
+
withCredentials: true,
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const response = await globalAxios.request<SwitchWorkspaceResponseClass>(options);
|
|
206
|
+
|
|
207
|
+
const { data: { accessToken } } = response;
|
|
208
|
+
this.configuration.accessToken = `Bearer ${accessToken}`;
|
|
209
|
+
|
|
210
|
+
const refreshToken = this.extractRefreshToken(response);
|
|
211
|
+
if (refreshToken) {
|
|
212
|
+
this.configuration.refreshToken = refreshToken;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
async refreshTokenInternal(): Promise<string> {
|
|
217
|
+
const { username, refreshToken } = this.configuration;
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
if (!username || !refreshToken) {
|
|
221
|
+
return '';
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const options: AxiosRequestConfig = {
|
|
225
|
+
method: 'POST',
|
|
226
|
+
url: `${this.configuration.basePath}/authservice/v1/refresh-token`,
|
|
227
|
+
headers: {
|
|
228
|
+
'Content-Type': 'application/json',
|
|
229
|
+
Cookie: refreshToken,
|
|
230
|
+
},
|
|
231
|
+
data: { username: username },
|
|
232
|
+
withCredentials: true,
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const { data: { accessToken } } = await globalAxios.request<LoginClass>(options);
|
|
236
|
+
|
|
237
|
+
return accessToken;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
private extractRefreshToken(response: AxiosResponse): string {
|
|
241
|
+
if (response.headers && response.headers['set-cookie']
|
|
242
|
+
&& response.headers['set-cookie'].length > 0) {
|
|
243
|
+
|
|
244
|
+
return `${response.headers['set-cookie'][0].split(';')[0]};`;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return '';
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
getConfiguration(): Configuration {
|
|
251
|
+
return this.configuration;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
private attachInterceptor(axios: AxiosInstance) {
|
|
255
|
+
axios.interceptors.response.use(
|
|
256
|
+
(res) => {
|
|
257
|
+
return res;
|
|
258
|
+
},
|
|
259
|
+
async (err) => {
|
|
260
|
+
let originalConfig = err.config;
|
|
261
|
+
if (err.response) {
|
|
262
|
+
// Access Token was expired
|
|
263
|
+
if (err.response.status === 401 && !originalConfig._retry) {
|
|
264
|
+
originalConfig._retry = true;
|
|
265
|
+
try {
|
|
266
|
+
const tokenString = await this.refreshTokenInternal();
|
|
267
|
+
const accessToken = `Bearer ${tokenString}`;
|
|
268
|
+
|
|
269
|
+
originalConfig.headers['Authorization'] = accessToken;
|
|
270
|
+
|
|
271
|
+
this.configuration.accessToken = accessToken;
|
|
272
|
+
|
|
273
|
+
return axios.request(originalConfig);
|
|
274
|
+
} catch (_error) {
|
|
275
|
+
if (_error.response && _error.response.data) {
|
|
276
|
+
return Promise.reject(_error.response.data);
|
|
277
|
+
}
|
|
278
|
+
return Promise.reject(_error);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (err.response.status === 403 && err.response.data) {
|
|
282
|
+
return Promise.reject(err.response.data);
|
|
283
|
+
}
|
|
284
|
+
} else if(err.message === NETWORK_ERROR_MESSAGE
|
|
285
|
+
&& err.isAxiosError
|
|
286
|
+
&& originalConfig.headers.hasOwnProperty('Authorization')
|
|
287
|
+
&& _retry_count < 4
|
|
288
|
+
){
|
|
289
|
+
_retry_count++;
|
|
290
|
+
try {
|
|
291
|
+
const tokenString = await this.refreshTokenInternal();
|
|
292
|
+
const accessToken = `Bearer ${tokenString}`;
|
|
293
|
+
|
|
294
|
+
_retry = true;
|
|
295
|
+
originalConfig.headers['Authorization'] = accessToken;
|
|
296
|
+
|
|
297
|
+
this.configuration.accessToken = accessToken;
|
|
298
|
+
|
|
299
|
+
return axios.request({
|
|
300
|
+
...originalConfig,
|
|
301
|
+
});
|
|
302
|
+
} catch (_error) {
|
|
303
|
+
if (_error.response && _error.response.data) {
|
|
304
|
+
return Promise.reject(_error.response.data);
|
|
305
|
+
}
|
|
306
|
+
return Promise.reject(_error);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return Promise.reject(err);
|
|
310
|
+
}
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
*
|
|
317
|
+
* @export
|
|
318
|
+
* @class RequiredError
|
|
319
|
+
* @extends {Error}
|
|
320
|
+
*/
|
|
321
|
+
export class RequiredError extends Error {
|
|
322
|
+
override name: "RequiredError" = "RequiredError";
|
|
323
|
+
constructor(public field: string, msg?: string) {
|
|
324
|
+
super(msg);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
package/common.ts
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL CommissionService
|
|
5
|
+
* The EMIL CommissionService 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"] = configuration.getBearerToken(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"] = configuration.getBearerToken(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 CommissionService
|
|
144
|
+
* The EMIL CommissionService 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
|
+
};
|