@emilgroup/billing-v2-sdk-node 0.0.0-stage → 1.0.1-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 +93 -0
- package/.openapi-generator/VERSION +1 -0
- package/.openapi-generator-ignore +23 -0
- package/README.md +83 -2
- package/api/bill-runs-api.ts +472 -0
- package/api/bills-api.ts +149 -0
- package/api/invoices-api.ts +1534 -0
- package/api/jobs-api.ts +760 -0
- package/api/policy-billings-api.ts +595 -0
- package/api.ts +39 -0
- package/base.ts +396 -0
- package/common.ts +200 -0
- package/configuration.ts +118 -0
- package/dist/api/bill-runs-api.d.ts +266 -0
- package/dist/api/bill-runs-api.js +470 -0
- package/dist/api/bills-api.d.ts +87 -0
- package/dist/api/bills-api.js +211 -0
- package/dist/api/invoices-api.d.ts +847 -0
- package/dist/api/invoices-api.js +1357 -0
- package/dist/api/jobs-api.d.ts +426 -0
- package/dist/api/jobs-api.js +712 -0
- package/dist/api/policy-billings-api.d.ts +332 -0
- package/dist/api/policy-billings-api.js +565 -0
- package/dist/api.d.ts +16 -0
- package/dist/api.js +34 -0
- package/dist/base.d.ts +97 -0
- package/dist/base.js +493 -0
- package/dist/common.d.ts +92 -0
- package/dist/common.js +278 -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/any.d.ts +25 -0
- package/dist/models/any.js +15 -0
- package/dist/models/bill-item.d.ts +132 -0
- package/dist/models/bill-item.js +15 -0
- package/dist/models/bill-run.d.ts +145 -0
- package/dist/models/bill-run.js +15 -0
- package/dist/models/bill.d.ts +194 -0
- package/dist/models/bill.js +15 -0
- package/dist/models/cancel-job-response.d.ts +25 -0
- package/dist/models/cancel-job-response.js +15 -0
- package/dist/models/create-correction-invoices-request.d.ts +72 -0
- package/dist/models/create-correction-invoices-request.js +15 -0
- package/dist/models/create-correction-invoices-response.d.ts +31 -0
- package/dist/models/create-correction-invoices-response.js +15 -0
- package/dist/models/create-detail-export-job-request.d.ts +56 -0
- package/dist/models/create-detail-export-job-request.js +15 -0
- package/dist/models/create-detail-export-job-response.d.ts +25 -0
- package/dist/models/create-detail-export-job-response.js +15 -0
- package/dist/models/create-estimated-invoice-for-interval-request.d.ts +42 -0
- package/dist/models/create-estimated-invoice-for-interval-request.js +15 -0
- package/dist/models/create-estimated-invoice-for-interval-response.d.ts +25 -0
- package/dist/models/create-estimated-invoice-for-interval-response.js +15 -0
- package/dist/models/create-estimated-invoice-request.d.ts +36 -0
- package/dist/models/create-estimated-invoice-request.js +15 -0
- package/dist/models/create-estimated-invoice-response.d.ts +25 -0
- package/dist/models/create-estimated-invoice-response.js +15 -0
- package/dist/models/create-export-job-request.d.ts +68 -0
- package/dist/models/create-export-job-request.js +15 -0
- package/dist/models/create-export-job-response.d.ts +25 -0
- package/dist/models/create-export-job-response.js +15 -0
- package/dist/models/create-initial-invoice-request.d.ts +72 -0
- package/dist/models/create-initial-invoice-request.js +15 -0
- package/dist/models/create-initial-invoice-response.d.ts +25 -0
- package/dist/models/create-initial-invoice-response.js +15 -0
- package/dist/models/create-invoice-request.d.ts +67 -0
- package/dist/models/create-invoice-request.js +15 -0
- package/dist/models/create-invoice-response.d.ts +25 -0
- package/dist/models/create-invoice-response.js +15 -0
- package/dist/models/create-invoice-status-body.d.ts +24 -0
- package/dist/models/create-invoice-status-body.js +15 -0
- package/dist/models/create-invoice-status-response.d.ts +25 -0
- package/dist/models/create-invoice-status-response.js +15 -0
- package/dist/models/create-item-request.d.ts +36 -0
- package/dist/models/create-item-request.js +15 -0
- package/dist/models/create-policy-billing-request.d.ts +42 -0
- package/dist/models/create-policy-billing-request.js +15 -0
- package/dist/models/create-policy-billing-response.d.ts +25 -0
- package/dist/models/create-policy-billing-response.js +15 -0
- package/dist/models/create-recurring-invoice-request.d.ts +72 -0
- package/dist/models/create-recurring-invoice-request.js +15 -0
- package/dist/models/create-recurring-invoice-response.d.ts +31 -0
- package/dist/models/create-recurring-invoice-response.js +15 -0
- package/dist/models/create-termination-invoice-request.d.ts +60 -0
- package/dist/models/create-termination-invoice-request.js +15 -0
- package/dist/models/create-termination-invoice-response.d.ts +25 -0
- package/dist/models/create-termination-invoice-response.js +15 -0
- package/dist/models/create-withdraw-invoice-request.d.ts +48 -0
- package/dist/models/create-withdraw-invoice-request.js +15 -0
- package/dist/models/create-withdraw-invoice-response.d.ts +25 -0
- package/dist/models/create-withdraw-invoice-response.js +15 -0
- package/dist/models/estimate-history-entry.d.ts +36 -0
- package/dist/models/estimate-history-entry.js +15 -0
- package/dist/models/export-column.d.ts +36 -0
- package/dist/models/export-column.js +15 -0
- package/dist/models/filter-field.d.ts +110 -0
- package/dist/models/filter-field.js +15 -0
- package/dist/models/filter-value.d.ts +37 -0
- package/dist/models/filter-value.js +15 -0
- package/dist/models/get-bill-response.d.ts +25 -0
- package/dist/models/get-bill-response.js +15 -0
- package/dist/models/get-bill-run-filter-catalog-response.d.ts +31 -0
- package/dist/models/get-bill-run-filter-catalog-response.js +15 -0
- package/dist/models/get-bill-run-response.d.ts +25 -0
- package/dist/models/get-bill-run-response.js +15 -0
- package/dist/models/get-invoice-filter-catalog-response.d.ts +31 -0
- package/dist/models/get-invoice-filter-catalog-response.js +15 -0
- package/dist/models/get-invoice-response.d.ts +25 -0
- package/dist/models/get-invoice-response.js +15 -0
- package/dist/models/get-job-download-response.d.ts +25 -0
- package/dist/models/get-job-download-response.js +15 -0
- package/dist/models/get-job-filter-catalog-response.d.ts +31 -0
- package/dist/models/get-job-filter-catalog-response.js +15 -0
- package/dist/models/get-job-response.d.ts +25 -0
- package/dist/models/get-job-response.js +15 -0
- package/dist/models/get-policies-billing-date-filter-catalog-response.d.ts +31 -0
- package/dist/models/get-policies-billing-date-filter-catalog-response.js +15 -0
- package/dist/models/get-policies-billing-filter-catalog-response.d.ts +31 -0
- package/dist/models/get-policies-billing-filter-catalog-response.js +15 -0
- package/dist/models/get-policy-billing-response.d.ts +25 -0
- package/dist/models/get-policy-billing-response.js +15 -0
- package/dist/models/highlight.d.ts +30 -0
- package/dist/models/highlight.js +15 -0
- package/dist/models/index.d.ts +75 -0
- package/dist/models/index.js +91 -0
- package/dist/models/invoice-item.d.ts +204 -0
- package/dist/models/invoice-item.js +15 -0
- package/dist/models/invoice-payment.d.ts +108 -0
- package/dist/models/invoice-payment.js +15 -0
- package/dist/models/invoice-payments.d.ts +25 -0
- package/dist/models/invoice-payments.js +15 -0
- package/dist/models/invoice-status.d.ts +54 -0
- package/dist/models/invoice-status.js +15 -0
- package/dist/models/invoice.d.ts +275 -0
- package/dist/models/invoice.js +15 -0
- package/dist/models/job-download.d.ts +36 -0
- package/dist/models/job-download.js +15 -0
- package/dist/models/job-error.d.ts +30 -0
- package/dist/models/job-error.js +15 -0
- package/dist/models/job-progress.d.ts +36 -0
- package/dist/models/job-progress.js +15 -0
- package/dist/models/job.d.ts +134 -0
- package/dist/models/job.js +15 -0
- package/dist/models/list-bill-runs-response.d.ts +37 -0
- package/dist/models/list-bill-runs-response.js +15 -0
- package/dist/models/list-invoices-response.d.ts +37 -0
- package/dist/models/list-invoices-response.js +15 -0
- package/dist/models/list-jobs-response.d.ts +37 -0
- package/dist/models/list-jobs-response.js +15 -0
- package/dist/models/list-policies-billing-dates-response.d.ts +37 -0
- package/dist/models/list-policies-billing-dates-response.js +15 -0
- package/dist/models/list-policies-billings-response.d.ts +37 -0
- package/dist/models/list-policies-billings-response.js +15 -0
- package/dist/models/list-request.d.ts +60 -0
- package/dist/models/list-request.js +15 -0
- package/dist/models/localized-text.d.ts +30 -0
- package/dist/models/localized-text.js +15 -0
- package/dist/models/match.d.ts +69 -0
- package/dist/models/match.js +15 -0
- package/dist/models/payment-term.d.ts +42 -0
- package/dist/models/payment-term.js +15 -0
- package/dist/models/policy-billing.d.ts +139 -0
- package/dist/models/policy-billing.js +15 -0
- package/dist/models/request-bill-run-request.d.ts +30 -0
- package/dist/models/request-bill-run-request.js +15 -0
- package/dist/models/request-bill-run-response.d.ts +25 -0
- package/dist/models/request-bill-run-response.js +15 -0
- package/dist/models/resolved-billing-config.d.ts +130 -0
- package/dist/models/resolved-billing-config.js +15 -0
- package/dist/models/revert-invoice-request.d.ts +24 -0
- package/dist/models/revert-invoice-request.js +15 -0
- package/dist/models/revert-invoice-response.d.ts +25 -0
- package/dist/models/revert-invoice-response.js +15 -0
- package/dist/models/slice.d.ts +30 -0
- package/dist/models/slice.js +15 -0
- package/dist/models/status.d.ts +37 -0
- package/dist/models/status.js +15 -0
- package/dist/models/tax.d.ts +30 -0
- package/dist/models/tax.js +15 -0
- package/dist/models/update-policy-billing-body.d.ts +24 -0
- package/dist/models/update-policy-billing-body.js +15 -0
- package/dist/models/update-policy-billing-response.d.ts +25 -0
- package/dist/models/update-policy-billing-response.js +15 -0
- package/git_push.sh +57 -0
- package/index.ts +19 -0
- package/models/any.ts +32 -0
- package/models/bill-item.ts +138 -0
- package/models/bill-run.ts +151 -0
- package/models/bill.ts +200 -0
- package/models/cancel-job-response.ts +31 -0
- package/models/create-correction-invoices-request.ts +78 -0
- package/models/create-correction-invoices-response.ts +37 -0
- package/models/create-detail-export-job-request.ts +60 -0
- package/models/create-detail-export-job-response.ts +31 -0
- package/models/create-estimated-invoice-for-interval-request.ts +48 -0
- package/models/create-estimated-invoice-for-interval-response.ts +31 -0
- package/models/create-estimated-invoice-request.ts +42 -0
- package/models/create-estimated-invoice-response.ts +31 -0
- package/models/create-export-job-request.ts +74 -0
- package/models/create-export-job-response.ts +31 -0
- package/models/create-initial-invoice-request.ts +78 -0
- package/models/create-initial-invoice-response.ts +31 -0
- package/models/create-invoice-request.ts +73 -0
- package/models/create-invoice-response.ts +31 -0
- package/models/create-invoice-status-body.ts +30 -0
- package/models/create-invoice-status-response.ts +31 -0
- package/models/create-item-request.ts +42 -0
- package/models/create-policy-billing-request.ts +48 -0
- package/models/create-policy-billing-response.ts +31 -0
- package/models/create-recurring-invoice-request.ts +78 -0
- package/models/create-recurring-invoice-response.ts +37 -0
- package/models/create-termination-invoice-request.ts +66 -0
- package/models/create-termination-invoice-response.ts +31 -0
- package/models/create-withdraw-invoice-request.ts +54 -0
- package/models/create-withdraw-invoice-response.ts +31 -0
- package/models/estimate-history-entry.ts +42 -0
- package/models/export-column.ts +42 -0
- package/models/filter-field.ts +116 -0
- package/models/filter-value.ts +43 -0
- package/models/get-bill-response.ts +31 -0
- package/models/get-bill-run-filter-catalog-response.ts +37 -0
- package/models/get-bill-run-response.ts +31 -0
- package/models/get-invoice-filter-catalog-response.ts +37 -0
- package/models/get-invoice-response.ts +31 -0
- package/models/get-job-download-response.ts +31 -0
- package/models/get-job-filter-catalog-response.ts +37 -0
- package/models/get-job-response.ts +31 -0
- package/models/get-policies-billing-date-filter-catalog-response.ts +37 -0
- package/models/get-policies-billing-filter-catalog-response.ts +37 -0
- package/models/get-policy-billing-response.ts +31 -0
- package/models/highlight.ts +36 -0
- package/models/index.ts +75 -0
- package/models/invoice-item.ts +210 -0
- package/models/invoice-payment.ts +114 -0
- package/models/invoice-payments.ts +31 -0
- package/models/invoice-status.ts +60 -0
- package/models/invoice.ts +281 -0
- package/models/job-download.ts +42 -0
- package/models/job-error.ts +36 -0
- package/models/job-progress.ts +42 -0
- package/models/job.ts +140 -0
- package/models/list-bill-runs-response.ts +43 -0
- package/models/list-invoices-response.ts +43 -0
- package/models/list-jobs-response.ts +43 -0
- package/models/list-policies-billing-dates-response.ts +43 -0
- package/models/list-policies-billings-response.ts +43 -0
- package/models/list-request.ts +66 -0
- package/models/localized-text.ts +36 -0
- package/models/match.ts +75 -0
- package/models/payment-term.ts +48 -0
- package/models/policy-billing.ts +145 -0
- package/models/request-bill-run-request.ts +36 -0
- package/models/request-bill-run-response.ts +31 -0
- package/models/resolved-billing-config.ts +134 -0
- package/models/revert-invoice-request.ts +30 -0
- package/models/revert-invoice-response.ts +31 -0
- package/models/slice.ts +36 -0
- package/models/status.ts +43 -0
- package/models/tax.ts +36 -0
- package/models/update-policy-billing-body.ts +30 -0
- package/models/update-policy-billing-response.ts +31 -0
- package/package.json +27 -4
- package/tsconfig.json +23 -0
package/base.ts
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL Billing Service
|
|
5
|
+
* The billing service: bills, bill runs, invoices and policy billings.
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 2.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
|
+
// 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
|
+
StagingZurich = 'https://eu-central-2.apiv2-staging.emil.de',
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let _retry_count = 0
|
|
67
|
+
let _retry = null
|
|
68
|
+
|
|
69
|
+
export function resetRetry() {
|
|
70
|
+
_retry_count = 0
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
*
|
|
75
|
+
* @export
|
|
76
|
+
* @interface RequestArgs
|
|
77
|
+
*/
|
|
78
|
+
export interface RequestArgs {
|
|
79
|
+
url: string;
|
|
80
|
+
options: AxiosRequestConfig;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const NETWORK_ERROR_MESSAGE = "Network Error";
|
|
84
|
+
|
|
85
|
+
// Refreshes in flight per configuration (BaseAPI.shareRefresh): SDK objects that share a configuration share its token.
|
|
86
|
+
const refreshesInFlight = new Map<Configuration, Promise<string>>();
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
*
|
|
90
|
+
* @export
|
|
91
|
+
* @class BaseAPI
|
|
92
|
+
*/
|
|
93
|
+
export class BaseAPI {
|
|
94
|
+
protected configuration: Configuration;
|
|
95
|
+
private username?: string;
|
|
96
|
+
private password?: string;
|
|
97
|
+
|
|
98
|
+
// Marks each request with the account (username) of the SDK object that sent it: only SDK objects of that
|
|
99
|
+
// account refresh and resend it, never an object of another account in the same app.
|
|
100
|
+
private static readonly REQUEST_OWNER = '_emilSdkOwner';
|
|
101
|
+
|
|
102
|
+
private ownAccount(): string {
|
|
103
|
+
return (this.configuration.username || '').toLowerCase();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
protected withOwner(options?: AxiosRequestConfig): AxiosRequestConfig {
|
|
107
|
+
// An object without a username cannot refresh itself: its requests stay unmarked, as before.
|
|
108
|
+
if (!this.ownAccount()) {
|
|
109
|
+
return { ...options };
|
|
110
|
+
}
|
|
111
|
+
return { ...options, [BaseAPI.REQUEST_OWNER]: this.ownAccount() } as AxiosRequestConfig;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Sent for another account: only that account's SDK objects handle it. Unmarked requests as before.
|
|
115
|
+
private sentByOtherAccount(config?: AxiosRequestConfig): boolean {
|
|
116
|
+
const owner = (config as Record<string, unknown> | undefined)?.[BaseAPI.REQUEST_OWNER];
|
|
117
|
+
return owner !== undefined && owner !== this.ownAccount();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) {
|
|
122
|
+
if (configuration) {
|
|
123
|
+
this.configuration = configuration;
|
|
124
|
+
this.basePath = configuration.basePath || this.basePath;
|
|
125
|
+
} else {
|
|
126
|
+
this.configuration = new Configuration({
|
|
127
|
+
basePath: this.basePath,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
this.attachInterceptor(axios);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async initialize(env: Environment = Environment.Production, targetWorkspace?: string) {
|
|
135
|
+
this.configuration.basePath = env;
|
|
136
|
+
|
|
137
|
+
await this.loadCredentials();
|
|
138
|
+
|
|
139
|
+
if (this.username) {
|
|
140
|
+
await this.authorize(this.username, this.password, targetWorkspace);
|
|
141
|
+
this.password = null; // to avoid keeping password loaded in memory.
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private async loadCredentials() {
|
|
146
|
+
try {
|
|
147
|
+
await this.readConfigFile();
|
|
148
|
+
} catch (error) {
|
|
149
|
+
console.warn(`No credentials file found. Check that ${filePath} exists.`);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
this.readEnvVariables();
|
|
153
|
+
|
|
154
|
+
if (!this.username) {
|
|
155
|
+
console.info(`No credentials found in credentials file or environment variables. Either provide some or use
|
|
156
|
+
authorize() function.`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private async readConfigFile() {
|
|
161
|
+
const file = await fs.promises.readFile(filePath, 'utf-8');
|
|
162
|
+
|
|
163
|
+
const lines = file.split(os.EOL)
|
|
164
|
+
.filter(Boolean);
|
|
165
|
+
|
|
166
|
+
lines.forEach((line: string) => {
|
|
167
|
+
if (line.startsWith(KEY_USERNAME)) {
|
|
168
|
+
this.username = line.length > KEY_USERNAME.length + 1 ? line.substring(KEY_USERNAME.length + 1) : '';
|
|
169
|
+
} else if (line.startsWith(KEY_PASSWORD)) {
|
|
170
|
+
this.password = line.length > KEY_PASSWORD.length + 1 ? line.substring(KEY_PASSWORD.length + 1) : '';
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private readEnvVariables(): boolean {
|
|
176
|
+
if (process.env.EMIL_USERNAME) {
|
|
177
|
+
this.username = process.env.EMIL_USERNAME;
|
|
178
|
+
this.password = process.env.EMIL_PASSWORD || '';
|
|
179
|
+
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
selectEnvironment(env: Environment) {
|
|
187
|
+
this.configuration.basePath = env;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async authorize(username: string, password: string, targetWorkspace?: string): Promise<void> {
|
|
191
|
+
const options: AxiosRequestConfig = {
|
|
192
|
+
method: 'POST',
|
|
193
|
+
url: `${this.configuration.basePath}/authservice/v1/login`,
|
|
194
|
+
headers: { 'Content-Type': 'application/json' },
|
|
195
|
+
data: {
|
|
196
|
+
username,
|
|
197
|
+
password,
|
|
198
|
+
},
|
|
199
|
+
withCredentials: true,
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const response = await globalAxios.request<LoginClass>(options);
|
|
203
|
+
|
|
204
|
+
const { data: { accessToken } } = response;
|
|
205
|
+
this.configuration.username = username;
|
|
206
|
+
this.configuration.accessToken = `Bearer ${accessToken}`;
|
|
207
|
+
|
|
208
|
+
const refreshToken = this.extractRefreshToken(response)
|
|
209
|
+
this.configuration.refreshToken = refreshToken;
|
|
210
|
+
|
|
211
|
+
// Switch workspace if provided
|
|
212
|
+
if (targetWorkspace) {
|
|
213
|
+
await this.switchWorkspace(targetWorkspace);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
async switchWorkspace(targetWorkspace: string): Promise<void> {
|
|
217
|
+
const options: AxiosRequestConfig = {
|
|
218
|
+
method: 'POST',
|
|
219
|
+
url: `${this.configuration.basePath}/authservice/v1/workspaces/switch`,
|
|
220
|
+
headers: {
|
|
221
|
+
'Content-Type': 'application/json',
|
|
222
|
+
'Authorization': `Bearer ${this.configuration.accessToken}`,
|
|
223
|
+
'Cookie': this.configuration.refreshToken,
|
|
224
|
+
},
|
|
225
|
+
data: {
|
|
226
|
+
username: this.configuration.username,
|
|
227
|
+
targetWorkspace,
|
|
228
|
+
} as SwitchWorkspaceRequest,
|
|
229
|
+
withCredentials: true,
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const response = await globalAxios.request<SwitchWorkspaceResponseClass>(options);
|
|
233
|
+
|
|
234
|
+
const { data: { accessToken } } = response;
|
|
235
|
+
this.configuration.accessToken = `Bearer ${accessToken}`;
|
|
236
|
+
|
|
237
|
+
const refreshToken = this.extractRefreshToken(response);
|
|
238
|
+
if (refreshToken) {
|
|
239
|
+
this.configuration.refreshToken = refreshToken;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
async refreshTokenInternal(): Promise<string> {
|
|
244
|
+
const { username, refreshToken } = this.configuration;
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
if (!username || !refreshToken) {
|
|
248
|
+
return '';
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Sent through globalAxios like any call; marked as retried, so a refused refresh is not refreshed again.
|
|
252
|
+
const options = {
|
|
253
|
+
method: 'POST',
|
|
254
|
+
url: `${this.configuration.basePath}/authservice/v1/refresh-token`,
|
|
255
|
+
headers: {
|
|
256
|
+
'Content-Type': 'application/json',
|
|
257
|
+
Cookie: refreshToken,
|
|
258
|
+
},
|
|
259
|
+
data: { username: username },
|
|
260
|
+
withCredentials: true,
|
|
261
|
+
_retry: true,
|
|
262
|
+
} as AxiosRequestConfig;
|
|
263
|
+
|
|
264
|
+
const { data: { accessToken } } = await globalAxios.request<LoginClass>(options);
|
|
265
|
+
|
|
266
|
+
return accessToken;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
private extractRefreshToken(response: AxiosResponse): string {
|
|
270
|
+
if (response.headers && response.headers['set-cookie']
|
|
271
|
+
&& response.headers['set-cookie'].length > 0) {
|
|
272
|
+
|
|
273
|
+
return `${response.headers['set-cookie'][0].split(';')[0]};`;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return '';
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
getConfiguration(): Configuration {
|
|
280
|
+
return this.configuration;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
private sharedRefresh(): Promise<string> {
|
|
284
|
+
return BaseAPI.shareRefresh(refreshesInFlight, this.configuration, () => this.refreshTokenInternal());
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
private refreshRunning(): boolean {
|
|
288
|
+
return refreshesInFlight.has(this.configuration);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Joins the refresh already in flight for this key, or starts one: calls refused at the same time wait for
|
|
292
|
+
// one refresh instead of each starting their own (a refresh token may be single-use). The entry is removed
|
|
293
|
+
// when the refresh settles.
|
|
294
|
+
private static shareRefresh<K, T>(inFlight: Map<K, Promise<T>>, key: K, start: () => Promise<T>): Promise<T> {
|
|
295
|
+
const running = inFlight.get(key);
|
|
296
|
+
if (running) {
|
|
297
|
+
return running;
|
|
298
|
+
}
|
|
299
|
+
const refresh = start();
|
|
300
|
+
inFlight.set(key, refresh);
|
|
301
|
+
const settled = () => { inFlight.delete(key); };
|
|
302
|
+
refresh.then(settled, settled);
|
|
303
|
+
return refresh;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// A refused call that joins a refresh already running is not a new try: only started refreshes count toward
|
|
307
|
+
// the limit, so every call refused at the same time is retried.
|
|
308
|
+
private mayRefreshAfterNetworkError(): boolean {
|
|
309
|
+
if (this.refreshRunning()) {
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
312
|
+
if (_retry_count >= 4) {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
_retry_count++;
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
private attachInterceptor(axios: AxiosInstance) {
|
|
321
|
+
axios.interceptors.response.use(
|
|
322
|
+
(res) => {
|
|
323
|
+
return res;
|
|
324
|
+
},
|
|
325
|
+
async (err) => {
|
|
326
|
+
let originalConfig = err.config;
|
|
327
|
+
if (this.sentByOtherAccount(originalConfig)) {
|
|
328
|
+
return Promise.reject(err);
|
|
329
|
+
}
|
|
330
|
+
if (err.response) {
|
|
331
|
+
// Access Token was expired
|
|
332
|
+
if (err.response.status === 401 && !originalConfig._retry) {
|
|
333
|
+
originalConfig._retry = true;
|
|
334
|
+
try {
|
|
335
|
+
const tokenString = await this.sharedRefresh();
|
|
336
|
+
const accessToken = `Bearer ${tokenString}`;
|
|
337
|
+
|
|
338
|
+
originalConfig.headers['Authorization'] = accessToken;
|
|
339
|
+
|
|
340
|
+
this.configuration.accessToken = accessToken;
|
|
341
|
+
|
|
342
|
+
return axios.request(originalConfig);
|
|
343
|
+
} catch (_error) {
|
|
344
|
+
if (_error.response && _error.response.data) {
|
|
345
|
+
return Promise.reject(_error.response.data);
|
|
346
|
+
}
|
|
347
|
+
return Promise.reject(_error);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (err.response.status === 403 && err.response.data) {
|
|
351
|
+
return Promise.reject(err.response.data);
|
|
352
|
+
}
|
|
353
|
+
} else if(err.message === NETWORK_ERROR_MESSAGE
|
|
354
|
+
&& err.isAxiosError
|
|
355
|
+
&& !originalConfig._retry
|
|
356
|
+
&& originalConfig.headers.hasOwnProperty('Authorization')
|
|
357
|
+
&& this.mayRefreshAfterNetworkError()
|
|
358
|
+
){
|
|
359
|
+
try {
|
|
360
|
+
const tokenString = await this.sharedRefresh();
|
|
361
|
+
const accessToken = `Bearer ${tokenString}`;
|
|
362
|
+
|
|
363
|
+
_retry = true;
|
|
364
|
+
originalConfig.headers['Authorization'] = accessToken;
|
|
365
|
+
|
|
366
|
+
this.configuration.accessToken = accessToken;
|
|
367
|
+
|
|
368
|
+
return axios.request({
|
|
369
|
+
...originalConfig,
|
|
370
|
+
});
|
|
371
|
+
} catch (_error) {
|
|
372
|
+
if (_error.response && _error.response.data) {
|
|
373
|
+
return Promise.reject(_error.response.data);
|
|
374
|
+
}
|
|
375
|
+
return Promise.reject(_error);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return Promise.reject(err);
|
|
379
|
+
}
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
*
|
|
386
|
+
* @export
|
|
387
|
+
* @class RequiredError
|
|
388
|
+
* @extends {Error}
|
|
389
|
+
*/
|
|
390
|
+
export class RequiredError extends Error {
|
|
391
|
+
override name: "RequiredError" = "RequiredError";
|
|
392
|
+
constructor(public field: string, msg?: string) {
|
|
393
|
+
super(msg);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
package/common.ts
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL Billing Service
|
|
5
|
+
* The billing service: bills, bill runs, invoices and policy billings.
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 2.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
|
+
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
|
+
// Typed by hand: since axios 1.20, request() returns an internal axios type that SDK declarations cannot name.
|
|
135
|
+
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH): Promise<R> => {
|
|
136
|
+
const axiosRequestArgs = {...axiosArgs.options, url: (configuration?.basePath || basePath) + axiosArgs.url};
|
|
137
|
+
return axios.request<T, R>(axiosRequestArgs) as Promise<R>;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/* tslint:disable */
|
|
142
|
+
/* eslint-disable */
|
|
143
|
+
/**
|
|
144
|
+
* EMIL Billing Service
|
|
145
|
+
* The billing service: bills, bill runs, invoices and policy billings.
|
|
146
|
+
*
|
|
147
|
+
* The version of the OpenAPI document: 2.0
|
|
148
|
+
*
|
|
149
|
+
*
|
|
150
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
151
|
+
* https://openapi-generator.tech
|
|
152
|
+
* Do not edit the class manually.
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
export interface IStorageConverter<D, SD> {
|
|
157
|
+
toStorageData( data: D ): SD;
|
|
158
|
+
fromStorageData( storageData: SD ): D;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface IStorage {
|
|
162
|
+
get<T>( key: string, converter?: IStorageConverter<T, any> ): T | null;
|
|
163
|
+
set<T>( key: string, value: T, converter?: IStorageConverter<T, any> ): void;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export class LocalStorage implements IStorage {
|
|
167
|
+
readonly storage: Storage;
|
|
168
|
+
|
|
169
|
+
constructor() {
|
|
170
|
+
this.storage = localStorage;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
get<T>( key: string, converter?: IStorageConverter<T, any> ): T | null {
|
|
174
|
+
const jsonValue = this.storage.getItem( key );
|
|
175
|
+
if ( jsonValue === null ) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
const value = JSON.parse( jsonValue );
|
|
179
|
+
if ( converter !== undefined ) {
|
|
180
|
+
return converter.fromStorageData( value );
|
|
181
|
+
} else {
|
|
182
|
+
return value as T;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
set<T>( key: string, value: T, converter?: IStorageConverter<T, any> ): void {
|
|
187
|
+
let valueToStore: any = value;
|
|
188
|
+
if ( converter !== undefined ) {
|
|
189
|
+
valueToStore = converter.toStorageData( value );
|
|
190
|
+
}
|
|
191
|
+
const jsonValue = JSON.stringify( valueToStore );
|
|
192
|
+
this.storage.setItem( key, jsonValue );
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
let _defaultStorage: IStorage = null;
|
|
197
|
+
|
|
198
|
+
export const defaultStorage = (): IStorage => {
|
|
199
|
+
return _defaultStorage || (_defaultStorage = new LocalStorage());
|
|
200
|
+
};
|
package/configuration.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* EMIL Billing Service
|
|
5
|
+
* The billing service: bills, bill runs, invoices and policy billings.
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 2.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
|
+
export interface ConfigurationParameters {
|
|
17
|
+
apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
|
|
18
|
+
username?: string;
|
|
19
|
+
password?: string;
|
|
20
|
+
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
|
|
21
|
+
basePath?: string;
|
|
22
|
+
baseOptions?: any;
|
|
23
|
+
formDataCtor?: new () => any;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class Configuration {
|
|
27
|
+
/**
|
|
28
|
+
* parameter for apiKey security
|
|
29
|
+
* @param name security name
|
|
30
|
+
* @memberof Configuration
|
|
31
|
+
*/
|
|
32
|
+
apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
|
|
33
|
+
/**
|
|
34
|
+
* parameter for basic security
|
|
35
|
+
*
|
|
36
|
+
* @type {string}
|
|
37
|
+
* @memberof Configuration
|
|
38
|
+
*/
|
|
39
|
+
username?: string;
|
|
40
|
+
/**
|
|
41
|
+
* parameter for basic security
|
|
42
|
+
*
|
|
43
|
+
* @type {string}
|
|
44
|
+
* @memberof Configuration
|
|
45
|
+
*/
|
|
46
|
+
password?: string;
|
|
47
|
+
/**
|
|
48
|
+
* parameter for oauth2 security
|
|
49
|
+
* @param name security name
|
|
50
|
+
* @param scopes oauth2 scope
|
|
51
|
+
* @memberof Configuration
|
|
52
|
+
*/
|
|
53
|
+
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
|
|
54
|
+
/**
|
|
55
|
+
* override base path
|
|
56
|
+
*
|
|
57
|
+
* @type {string}
|
|
58
|
+
* @memberof Configuration
|
|
59
|
+
*/
|
|
60
|
+
basePath?: string;
|
|
61
|
+
/**
|
|
62
|
+
* base options for axios calls
|
|
63
|
+
*
|
|
64
|
+
* @type {any}
|
|
65
|
+
* @memberof Configuration
|
|
66
|
+
*/
|
|
67
|
+
baseOptions?: any;
|
|
68
|
+
/**
|
|
69
|
+
* The FormData constructor that will be used to create multipart form data
|
|
70
|
+
* requests. You can inject this here so that execution environments that
|
|
71
|
+
* do not support the FormData class can still run the generated client.
|
|
72
|
+
*
|
|
73
|
+
* @type {new () => FormData}
|
|
74
|
+
*/
|
|
75
|
+
formDataCtor?: new () => any;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* parameter for automatically refreshing access token for oauth2 security
|
|
79
|
+
*
|
|
80
|
+
* @type {string}
|
|
81
|
+
* @memberof Configuration
|
|
82
|
+
*/
|
|
83
|
+
refreshToken?: string;
|
|
84
|
+
|
|
85
|
+
constructor(param: ConfigurationParameters = {}) {
|
|
86
|
+
this.apiKey = param.apiKey;
|
|
87
|
+
this.username = param.username;
|
|
88
|
+
this.password = param.password;
|
|
89
|
+
this.accessToken = param.accessToken;
|
|
90
|
+
this.basePath = param.basePath;
|
|
91
|
+
this.baseOptions = param.baseOptions;
|
|
92
|
+
this.formDataCtor = param.formDataCtor;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Check if the given MIME is a JSON MIME.
|
|
97
|
+
* JSON MIME examples:
|
|
98
|
+
* application/json
|
|
99
|
+
* application/json; charset=UTF8
|
|
100
|
+
* APPLICATION/JSON
|
|
101
|
+
* application/vnd.company+json
|
|
102
|
+
* @param mime - MIME (Multipurpose Internet Mail Extensions)
|
|
103
|
+
* @return True if the given MIME is JSON, false otherwise.
|
|
104
|
+
*/
|
|
105
|
+
public isJsonMime(mime: string): boolean {
|
|
106
|
+
const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
|
|
107
|
+
return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Returns "Bearer" token.
|
|
112
|
+
* @param token - access token.
|
|
113
|
+
* @return Bearer token.
|
|
114
|
+
*/
|
|
115
|
+
public getBearerToken(token?: string): string {
|
|
116
|
+
return ('' + token).startsWith("Bearer") ? token : "Bearer " + token;
|
|
117
|
+
}
|
|
118
|
+
}
|