@emilgroup/billing-sdk 1.0.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 +37 -0
- package/.openapi-generator/VERSION +1 -0
- package/.openapi-generator-ignore +23 -0
- package/README.md +51 -0
- package/api/correction-invoices-api.ts +161 -0
- package/api/estimated-invoices-api.ts +264 -0
- package/api/initial-invoices-api.ts +161 -0
- package/api/invoices-api.ts +398 -0
- package/api/recurring-invoices-api.ts +161 -0
- package/api.ts +40 -0
- package/base.ts +247 -0
- package/common.ts +198 -0
- package/configuration.ts +101 -0
- package/dist/api/correction-invoices-api.d.ts +93 -0
- package/dist/api/correction-invoices-api.js +220 -0
- package/dist/api/estimated-invoices-api.d.ts +146 -0
- package/dist/api/estimated-invoices-api.js +309 -0
- package/dist/api/initial-invoices-api.d.ts +93 -0
- package/dist/api/initial-invoices-api.js +220 -0
- package/dist/api/invoices-api.d.ts +234 -0
- package/dist/api/invoices-api.js +369 -0
- package/dist/api/recurring-invoices-api.d.ts +93 -0
- package/dist/api/recurring-invoices-api.js +220 -0
- package/dist/api.d.ts +20 -0
- package/dist/api.js +40 -0
- package/dist/base.d.ts +72 -0
- package/dist/base.js +293 -0
- package/dist/common.d.ts +91 -0
- package/dist/common.js +276 -0
- package/dist/configuration.d.ts +83 -0
- package/dist/configuration.js +44 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +35 -0
- package/dist/models/create-correction-invoices-response-class.d.ts +25 -0
- package/dist/models/create-correction-invoices-response-class.js +15 -0
- package/dist/models/create-custom-estimated-invoice-request-dto.d.ts +35 -0
- package/dist/models/create-custom-estimated-invoice-request-dto.js +20 -0
- package/dist/models/create-custom-estimated-invoice-response-class.d.ts +24 -0
- package/dist/models/create-custom-estimated-invoice-response-class.js +15 -0
- package/dist/models/create-estimated-invoice-request-dto.d.ts +31 -0
- package/dist/models/create-estimated-invoice-request-dto.js +15 -0
- package/dist/models/create-estimated-invoice-response-class.d.ts +31 -0
- package/dist/models/create-estimated-invoice-response-class.js +15 -0
- package/dist/models/create-invoice-request-dto.d.ts +75 -0
- package/dist/models/create-invoice-request-dto.js +24 -0
- package/dist/models/create-invoice-response-class.d.ts +25 -0
- package/dist/models/create-invoice-response-class.js +15 -0
- package/dist/models/index.d.ts +19 -0
- package/dist/models/index.js +35 -0
- package/dist/models/invoice-class.d.ts +121 -0
- package/dist/models/invoice-class.js +15 -0
- package/dist/models/invoice-item-class.d.ts +108 -0
- package/dist/models/invoice-item-class.js +15 -0
- package/dist/models/list-invoices-response-class.d.ts +31 -0
- package/dist/models/list-invoices-response-class.js +15 -0
- package/dist/models/list-policies-billing-dates-response-class.d.ts +30 -0
- package/dist/models/list-policies-billing-dates-response-class.js +15 -0
- package/dist/models/list-request-dto.d.ts +54 -0
- package/dist/models/list-request-dto.js +15 -0
- package/dist/models/policy-dto.d.ts +85 -0
- package/dist/models/policy-dto.js +15 -0
- package/dist/models/policy-object-dto.d.ts +42 -0
- package/dist/models/policy-object-dto.js +15 -0
- package/dist/models/policy-premium-dto.d.ts +43 -0
- package/dist/models/policy-premium-dto.js +15 -0
- package/dist/models/policy-premium-item-dto.d.ts +49 -0
- package/dist/models/policy-premium-item-dto.js +15 -0
- package/dist/models/policy-version-dto.d.ts +55 -0
- package/dist/models/policy-version-dto.js +15 -0
- package/dist/models/premium-formula-dto.d.ts +72 -0
- package/dist/models/premium-formula-dto.js +15 -0
- package/dist/models/timeslice-dto.d.ts +62 -0
- package/dist/models/timeslice-dto.js +15 -0
- package/git_push.sh +57 -0
- package/index.ts +19 -0
- package/models/create-correction-invoices-response-class.ts +31 -0
- package/models/create-custom-estimated-invoice-request-dto.ts +44 -0
- package/models/create-custom-estimated-invoice-response-class.ts +30 -0
- package/models/create-estimated-invoice-request-dto.ts +37 -0
- package/models/create-estimated-invoice-response-class.ts +37 -0
- package/models/create-invoice-request-dto.ts +84 -0
- package/models/create-invoice-response-class.ts +31 -0
- package/models/index.ts +19 -0
- package/models/invoice-class.ts +127 -0
- package/models/invoice-item-class.ts +114 -0
- package/models/list-invoices-response-class.ts +37 -0
- package/models/list-policies-billing-dates-response-class.ts +36 -0
- package/models/list-request-dto.ts +60 -0
- package/models/policy-dto.ts +91 -0
- package/models/policy-object-dto.ts +48 -0
- package/models/policy-premium-dto.ts +49 -0
- package/models/policy-premium-item-dto.ts +55 -0
- package/models/policy-version-dto.ts +61 -0
- package/models/premium-formula-dto.ts +78 -0
- package/models/timeslice-dto.ts +68 -0
- package/package.json +27 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL BillingService
|
|
5
|
+
* The EMIL BillingService API description
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 1.0
|
|
8
|
+
*
|
|
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 { CreateInvoiceRequestDto } from '../models';
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
import { CreateInvoiceResponseClass } from '../models';
|
|
27
|
+
/**
|
|
28
|
+
* RecurringInvoicesApi - axios parameter creator
|
|
29
|
+
* @export
|
|
30
|
+
*/
|
|
31
|
+
export const RecurringInvoicesApiAxiosParamCreator = function (configuration?: Configuration) {
|
|
32
|
+
return {
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param {CreateInvoiceRequestDto} createInvoiceRequestDto
|
|
36
|
+
* @param {string} [authorization] Bearer Token
|
|
37
|
+
* @param {*} [options] Override http request option.
|
|
38
|
+
* @throws {RequiredError}
|
|
39
|
+
*/
|
|
40
|
+
createRecurringInvoice: async (createInvoiceRequestDto: CreateInvoiceRequestDto, authorization?: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
|
41
|
+
// verify required parameter 'createInvoiceRequestDto' is not null or undefined
|
|
42
|
+
assertParamExists('createRecurringInvoice', 'createInvoiceRequestDto', createInvoiceRequestDto)
|
|
43
|
+
const localVarPath = `/billingservice/v1/recurring-invoices`;
|
|
44
|
+
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
45
|
+
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
46
|
+
let baseOptions;
|
|
47
|
+
let baseAccessToken;
|
|
48
|
+
if (configuration) {
|
|
49
|
+
baseOptions = configuration.baseOptions;
|
|
50
|
+
baseAccessToken = configuration.accessToken;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
|
|
54
|
+
const localVarHeaderParameter = {} as any;
|
|
55
|
+
const localVarQueryParameter = {} as any;
|
|
56
|
+
|
|
57
|
+
// authentication bearer required
|
|
58
|
+
// http bearer authentication required
|
|
59
|
+
await setBearerAuthToObject(localVarHeaderParameter, configuration)
|
|
60
|
+
|
|
61
|
+
if (authorization !== undefined && authorization !== null || baseAccessToken !== undefined && baseAccessToken !== null) {
|
|
62
|
+
localVarHeaderParameter['Authorization'] = String(authorization ? authorization : baseAccessToken);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
localVarHeaderParameter['Content-Type'] = 'application/json';
|
|
68
|
+
|
|
69
|
+
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
70
|
+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
71
|
+
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
|
|
72
|
+
localVarRequestOptions.data = serializeDataIfNeeded(createInvoiceRequestDto, localVarRequestOptions, configuration)
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
url: toPathString(localVarUrlObj),
|
|
76
|
+
options: localVarRequestOptions,
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* RecurringInvoicesApi - functional programming interface
|
|
84
|
+
* @export
|
|
85
|
+
*/
|
|
86
|
+
export const RecurringInvoicesApiFp = function(configuration?: Configuration) {
|
|
87
|
+
const localVarAxiosParamCreator = RecurringInvoicesApiAxiosParamCreator(configuration)
|
|
88
|
+
return {
|
|
89
|
+
/**
|
|
90
|
+
*
|
|
91
|
+
* @param {CreateInvoiceRequestDto} createInvoiceRequestDto
|
|
92
|
+
* @param {string} [authorization] Bearer Token
|
|
93
|
+
* @param {*} [options] Override http request option.
|
|
94
|
+
* @throws {RequiredError}
|
|
95
|
+
*/
|
|
96
|
+
async createRecurringInvoice(createInvoiceRequestDto: CreateInvoiceRequestDto, authorization?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<CreateInvoiceResponseClass>> {
|
|
97
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.createRecurringInvoice(createInvoiceRequestDto, authorization, options);
|
|
98
|
+
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
99
|
+
},
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* RecurringInvoicesApi - factory interface
|
|
105
|
+
* @export
|
|
106
|
+
*/
|
|
107
|
+
export const RecurringInvoicesApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
|
|
108
|
+
const localVarFp = RecurringInvoicesApiFp(configuration)
|
|
109
|
+
return {
|
|
110
|
+
/**
|
|
111
|
+
*
|
|
112
|
+
* @param {CreateInvoiceRequestDto} createInvoiceRequestDto
|
|
113
|
+
* @param {string} [authorization] Bearer Token
|
|
114
|
+
* @param {*} [options] Override http request option.
|
|
115
|
+
* @throws {RequiredError}
|
|
116
|
+
*/
|
|
117
|
+
createRecurringInvoice(createInvoiceRequestDto: CreateInvoiceRequestDto, authorization?: string, options?: any): AxiosPromise<CreateInvoiceResponseClass> {
|
|
118
|
+
return localVarFp.createRecurringInvoice(createInvoiceRequestDto, authorization, options).then((request) => request(axios, basePath));
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Request parameters for createRecurringInvoice operation in RecurringInvoicesApi.
|
|
125
|
+
* @export
|
|
126
|
+
* @interface RecurringInvoicesApiCreateRecurringInvoiceRequest
|
|
127
|
+
*/
|
|
128
|
+
export interface RecurringInvoicesApiCreateRecurringInvoiceRequest {
|
|
129
|
+
/**
|
|
130
|
+
*
|
|
131
|
+
* @type {CreateInvoiceRequestDto}
|
|
132
|
+
* @memberof RecurringInvoicesApiCreateRecurringInvoice
|
|
133
|
+
*/
|
|
134
|
+
readonly createInvoiceRequestDto: CreateInvoiceRequestDto
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Bearer Token
|
|
138
|
+
* @type {string}
|
|
139
|
+
* @memberof RecurringInvoicesApiCreateRecurringInvoice
|
|
140
|
+
*/
|
|
141
|
+
readonly authorization?: string
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* RecurringInvoicesApi - object-oriented interface
|
|
146
|
+
* @export
|
|
147
|
+
* @class RecurringInvoicesApi
|
|
148
|
+
* @extends {BaseAPI}
|
|
149
|
+
*/
|
|
150
|
+
export class RecurringInvoicesApi extends BaseAPI {
|
|
151
|
+
/**
|
|
152
|
+
*
|
|
153
|
+
* @param {RecurringInvoicesApiCreateRecurringInvoiceRequest} requestParameters Request parameters.
|
|
154
|
+
* @param {*} [options] Override http request option.
|
|
155
|
+
* @throws {RequiredError}
|
|
156
|
+
* @memberof RecurringInvoicesApi
|
|
157
|
+
*/
|
|
158
|
+
public createRecurringInvoice(requestParameters: RecurringInvoicesApiCreateRecurringInvoiceRequest, options?: AxiosRequestConfig) {
|
|
159
|
+
return RecurringInvoicesApiFp(this.configuration).createRecurringInvoice(requestParameters.createInvoiceRequestDto, requestParameters.authorization, options).then((request) => request(this.axios, this.basePath));
|
|
160
|
+
}
|
|
161
|
+
}
|
package/api.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL BillingService
|
|
5
|
+
* The EMIL BillingService API description
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 1.0
|
|
8
|
+
*
|
|
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
|
+
// 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
|
+
import { CorrectionInvoicesApi } from './api';
|
|
24
|
+
import { EstimatedInvoicesApi } from './api';
|
|
25
|
+
import { InitialInvoicesApi } from './api';
|
|
26
|
+
import { InvoicesApi } from './api';
|
|
27
|
+
import { RecurringInvoicesApi } from './api';
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
export * from './api/correction-invoices-api';
|
|
31
|
+
export * from './api/estimated-invoices-api';
|
|
32
|
+
export * from './api/initial-invoices-api';
|
|
33
|
+
export * from './api/invoices-api';
|
|
34
|
+
export * from './api/recurring-invoices-api';
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
export enum Environment {
|
|
38
|
+
Production = 'https://apiv2.emil.de',
|
|
39
|
+
Test = 'https://apiv2-test.emil.de',
|
|
40
|
+
}
|
package/base.ts
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL BillingService
|
|
5
|
+
* The EMIL BillingService API description
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 1.0
|
|
8
|
+
*
|
|
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 LoginClass {
|
|
36
|
+
accessToken: string;
|
|
37
|
+
permissions: Array<string>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export enum Environment {
|
|
41
|
+
Production = 'https://apiv2.emil.de',
|
|
42
|
+
Test = 'https://apiv2-test.emil.de',
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let _retry_count = 0
|
|
46
|
+
let _retry = null
|
|
47
|
+
|
|
48
|
+
export function resetRetry() {
|
|
49
|
+
_retry_count = 0
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
* @export
|
|
55
|
+
* @interface RequestArgs
|
|
56
|
+
*/
|
|
57
|
+
export interface RequestArgs {
|
|
58
|
+
url: string;
|
|
59
|
+
options: AxiosRequestConfig;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface TokenData {
|
|
63
|
+
accessToken?: string;
|
|
64
|
+
username?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const NETWORK_ERROR_MESSAGE = "Network Error";
|
|
68
|
+
const TOKEN_DATA = 'APP_TOKEN';
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
*
|
|
72
|
+
* @export
|
|
73
|
+
* @class BaseAPI
|
|
74
|
+
*/
|
|
75
|
+
export class BaseAPI {
|
|
76
|
+
protected configuration: Configuration | undefined;
|
|
77
|
+
private tokenData?: TokenData;
|
|
78
|
+
|
|
79
|
+
constructor(configuration?: Configuration,
|
|
80
|
+
protected basePath: string = BASE_PATH,
|
|
81
|
+
protected axios: AxiosInstance = globalAxios) {
|
|
82
|
+
|
|
83
|
+
this.loadTokenData();
|
|
84
|
+
|
|
85
|
+
if (configuration) {
|
|
86
|
+
this.configuration = configuration;
|
|
87
|
+
this.basePath = configuration.basePath || this.basePath;
|
|
88
|
+
} else {
|
|
89
|
+
const { accessToken, username } = this.tokenData;
|
|
90
|
+
|
|
91
|
+
this.configuration = new Configuration({
|
|
92
|
+
basePath: this.basePath,
|
|
93
|
+
accessToken: accessToken ? `Bearer ${accessToken}` : '',
|
|
94
|
+
username,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
this.attachInterceptor(axios);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
selectEnvironment(env: Environment) {
|
|
102
|
+
this.configuration.basePath = env;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async authorize(username: string, password: string): Promise<void> {
|
|
106
|
+
const options: AxiosRequestConfig = {
|
|
107
|
+
method: 'POST',
|
|
108
|
+
url: `${this.configuration.basePath}/authservice/v1/login`,
|
|
109
|
+
headers: { 'Content-Type': 'application/json' },
|
|
110
|
+
data: {
|
|
111
|
+
username,
|
|
112
|
+
password,
|
|
113
|
+
},
|
|
114
|
+
withCredentials: true,
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const response = await globalAxios.request<LoginClass>(options);
|
|
118
|
+
|
|
119
|
+
const { data: { accessToken } } = response;
|
|
120
|
+
|
|
121
|
+
this.configuration.username = username;
|
|
122
|
+
this.configuration.accessToken = `Bearer ${accessToken}`;
|
|
123
|
+
this.tokenData.username = username;
|
|
124
|
+
this.tokenData.accessToken = accessToken;
|
|
125
|
+
|
|
126
|
+
this.storeTokenData({
|
|
127
|
+
...this.tokenData
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async refreshToken(): Promise<string> {
|
|
132
|
+
const { username } = this.configuration;
|
|
133
|
+
|
|
134
|
+
if (!username) {
|
|
135
|
+
return '';
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const options: AxiosRequestConfig = {
|
|
139
|
+
method: 'POST',
|
|
140
|
+
url: `${this.configuration.basePath}/authservice/v1/refresh-token`,
|
|
141
|
+
headers: {
|
|
142
|
+
'Content-Type': 'application/json',
|
|
143
|
+
},
|
|
144
|
+
data: { username: username },
|
|
145
|
+
withCredentials: true,
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const { data: { accessToken } } = await globalAxios.request<LoginClass>(options);
|
|
149
|
+
|
|
150
|
+
return accessToken;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private storeTokenData(tokenData?: TokenData) {
|
|
154
|
+
if (typeof window !== 'undefined') {
|
|
155
|
+
defaultStorage().set<TokenData>(TOKEN_DATA, tokenData);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
public loadTokenData() {
|
|
160
|
+
if (typeof window !== 'undefined') {
|
|
161
|
+
this.tokenData = defaultStorage().get<TokenData>(TOKEN_DATA) || {};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
public cleanTokenData() {
|
|
166
|
+
this.storeTokenData(null);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private attachInterceptor(axios: AxiosInstance) {
|
|
170
|
+
axios.interceptors.response.use(
|
|
171
|
+
(res) => {
|
|
172
|
+
return res;
|
|
173
|
+
},
|
|
174
|
+
async (err) => {
|
|
175
|
+
let originalConfig = err.config;
|
|
176
|
+
if (err.response && !(err.response instanceof XMLHttpRequest)) { // sometimes buggy and is of type request
|
|
177
|
+
// Access Token was expired
|
|
178
|
+
if ((err.response.status === 401 || err.response.status === 403)
|
|
179
|
+
&& !originalConfig._retry) {
|
|
180
|
+
originalConfig._retry = true;
|
|
181
|
+
try {
|
|
182
|
+
let tokenString = await this.refreshToken();
|
|
183
|
+
const accessToken = `Bearer ${tokenString}`;
|
|
184
|
+
|
|
185
|
+
delete originalConfig.headers['Authorization']
|
|
186
|
+
|
|
187
|
+
originalConfig.headers['Authorization'] = accessToken;
|
|
188
|
+
|
|
189
|
+
this.configuration.accessToken = accessToken;
|
|
190
|
+
this.tokenData.accessToken = tokenString;
|
|
191
|
+
|
|
192
|
+
this.storeTokenData(this.tokenData);
|
|
193
|
+
|
|
194
|
+
return axios(originalConfig);
|
|
195
|
+
} catch (_error) {
|
|
196
|
+
if (_error.response && _error.response.data) {
|
|
197
|
+
return Promise.reject(_error.response.data);
|
|
198
|
+
}
|
|
199
|
+
return Promise.reject(_error);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
} else if (err.message === NETWORK_ERROR_MESSAGE
|
|
203
|
+
&& originalConfig.headers.hasOwnProperty('Authorization')
|
|
204
|
+
&& _retry_count < 4
|
|
205
|
+
) {
|
|
206
|
+
_retry_count++;
|
|
207
|
+
try {
|
|
208
|
+
let tokenString = await this.refreshToken();
|
|
209
|
+
const accessToken = `Bearer ${tokenString}`;
|
|
210
|
+
|
|
211
|
+
_retry = true;
|
|
212
|
+
originalConfig.headers['Authorization'] = accessToken;
|
|
213
|
+
|
|
214
|
+
this.configuration.accessToken = accessToken;
|
|
215
|
+
this.tokenData.accessToken = tokenString;
|
|
216
|
+
|
|
217
|
+
this.storeTokenData(this.tokenData);
|
|
218
|
+
|
|
219
|
+
return axios.request({
|
|
220
|
+
...originalConfig,
|
|
221
|
+
});
|
|
222
|
+
} catch (_error) {
|
|
223
|
+
if (_error.response && _error.response.data) {
|
|
224
|
+
return Promise.reject(_error.response.data);
|
|
225
|
+
}
|
|
226
|
+
return Promise.reject(_error);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return Promise.reject(err);
|
|
230
|
+
}
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
*
|
|
237
|
+
* @export
|
|
238
|
+
* @class RequiredError
|
|
239
|
+
* @extends {Error}
|
|
240
|
+
*/
|
|
241
|
+
export class RequiredError extends Error {
|
|
242
|
+
name: "RequiredError" = "RequiredError";
|
|
243
|
+
constructor(public field: string, msg?: string) {
|
|
244
|
+
super(msg);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
package/common.ts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL BillingService
|
|
5
|
+
* The EMIL BillingService API description
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 1.0
|
|
8
|
+
*
|
|
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"] = "Bearer " + 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"] = "Bearer " + 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
|
+
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
|
|
134
|
+
const axiosRequestArgs = {...axiosArgs.options, url: (configuration?.basePath || basePath) + axiosArgs.url};
|
|
135
|
+
return axios.request<T, R>(axiosRequestArgs);
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/* tslint:disable */
|
|
140
|
+
/* eslint-disable */
|
|
141
|
+
/**
|
|
142
|
+
* EMIL BillingService
|
|
143
|
+
* The EMIL BillingService API description
|
|
144
|
+
*
|
|
145
|
+
* The version of the OpenAPI document: 1.0
|
|
146
|
+
*
|
|
147
|
+
*
|
|
148
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
149
|
+
* https://openapi-generator.tech
|
|
150
|
+
* Do not edit the class manually.
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
export interface IStorageConverter<D, SD> {
|
|
155
|
+
toStorageData( data: D ): SD;
|
|
156
|
+
fromStorageData( storageData: SD ): D;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface IStorage {
|
|
160
|
+
get<T>( key: string, converter?: IStorageConverter<T, any> ): T | null;
|
|
161
|
+
set<T>( key: string, value: T, converter?: IStorageConverter<T, any> ): void;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export class LocalStorage implements IStorage {
|
|
165
|
+
readonly storage: Storage;
|
|
166
|
+
|
|
167
|
+
constructor() {
|
|
168
|
+
this.storage = localStorage;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
get<T>( key: string, converter?: IStorageConverter<T, any> ): T | null {
|
|
172
|
+
const jsonValue = this.storage.getItem( key );
|
|
173
|
+
if ( jsonValue === null ) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
const value = JSON.parse( jsonValue );
|
|
177
|
+
if ( converter !== undefined ) {
|
|
178
|
+
return converter.fromStorageData( value );
|
|
179
|
+
} else {
|
|
180
|
+
return value as T;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
set<T>( key: string, value: T, converter?: IStorageConverter<T, any> ): void {
|
|
185
|
+
let valueToStore: any = value;
|
|
186
|
+
if ( converter !== undefined ) {
|
|
187
|
+
valueToStore = converter.toStorageData( value );
|
|
188
|
+
}
|
|
189
|
+
const jsonValue = JSON.stringify( valueToStore );
|
|
190
|
+
this.storage.setItem( key, jsonValue );
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
let _defaultStorage: IStorage = null;
|
|
195
|
+
|
|
196
|
+
export const defaultStorage = (): IStorage => {
|
|
197
|
+
return _defaultStorage || (_defaultStorage = new LocalStorage());
|
|
198
|
+
};
|