@emilgroup/account-sdk-node 1.30.1-beta.1 → 1.33.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/base.ts +8 -15
- package/dist/base.d.ts +2 -3
- package/dist/base.js +21 -26
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,11 +17,11 @@ Although this package can be used in both TypeScript and JavaScript, it is inten
|
|
|
17
17
|
Navigate to the folder of your consuming project and run one of the following commands:
|
|
18
18
|
|
|
19
19
|
```
|
|
20
|
-
npm install @emilgroup/account-sdk-node@1.
|
|
20
|
+
npm install @emilgroup/account-sdk-node@1.33.1-beta.0 --save
|
|
21
21
|
```
|
|
22
22
|
or
|
|
23
23
|
```
|
|
24
|
-
yarn add @emilgroup/account-sdk-node@1.
|
|
24
|
+
yarn add @emilgroup/account-sdk-node@1.33.1-beta.0
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
And then you can import `AccountsApi`.
|
package/base.ts
CHANGED
|
@@ -47,6 +47,7 @@ export interface LoginClass {
|
|
|
47
47
|
export enum Environment {
|
|
48
48
|
Production = 'https://apiv2.emil.de',
|
|
49
49
|
Test = 'https://apiv2-test.emil.de',
|
|
50
|
+
Staging = 'https://apiv2-staging.emil.de',
|
|
50
51
|
Development = 'https://apiv2-dev.emil.de',
|
|
51
52
|
ProductionZurich = 'https://eu-central-2.apiv2.emil.de',
|
|
52
53
|
}
|
|
@@ -79,7 +80,6 @@ export class BaseAPI {
|
|
|
79
80
|
protected configuration: Configuration;
|
|
80
81
|
private username?: string;
|
|
81
82
|
private password?: string;
|
|
82
|
-
private permissions?: string;
|
|
83
83
|
|
|
84
84
|
constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) {
|
|
85
85
|
if (configuration) {
|
|
@@ -150,10 +150,6 @@ export class BaseAPI {
|
|
|
150
150
|
this.configuration.basePath = env;
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
getPermissions(): Array<string> {
|
|
154
|
-
return this.permissions.split(',');
|
|
155
|
-
}
|
|
156
|
-
|
|
157
153
|
async authorize(username: string, password: string): Promise<void> {
|
|
158
154
|
const options: AxiosRequestConfig = {
|
|
159
155
|
method: 'POST',
|
|
@@ -168,21 +164,20 @@ export class BaseAPI {
|
|
|
168
164
|
|
|
169
165
|
const response = await globalAxios.request<LoginClass>(options);
|
|
170
166
|
|
|
171
|
-
const { data: { accessToken
|
|
167
|
+
const { data: { accessToken } } = response;
|
|
172
168
|
this.configuration.username = username;
|
|
173
169
|
this.configuration.accessToken = `Bearer ${accessToken}`;
|
|
174
|
-
this.permissions = permissions;
|
|
175
170
|
|
|
176
171
|
const refreshToken = this.extractRefreshToken(response)
|
|
177
172
|
this.configuration.refreshToken = refreshToken;
|
|
178
173
|
}
|
|
179
174
|
|
|
180
|
-
async refreshTokenInternal(): Promise<
|
|
175
|
+
async refreshTokenInternal(): Promise<string> {
|
|
181
176
|
const { username, refreshToken } = this.configuration;
|
|
182
177
|
|
|
183
178
|
|
|
184
179
|
if (!username || !refreshToken) {
|
|
185
|
-
|
|
180
|
+
return '';
|
|
186
181
|
}
|
|
187
182
|
|
|
188
183
|
const options: AxiosRequestConfig = {
|
|
@@ -196,9 +191,9 @@ export class BaseAPI {
|
|
|
196
191
|
withCredentials: true,
|
|
197
192
|
};
|
|
198
193
|
|
|
199
|
-
const
|
|
194
|
+
const { data: { accessToken } } = await globalAxios.request<LoginClass>(options);
|
|
200
195
|
|
|
201
|
-
return
|
|
196
|
+
return accessToken;
|
|
202
197
|
}
|
|
203
198
|
|
|
204
199
|
private extractRefreshToken(response: AxiosResponse): string {
|
|
@@ -227,9 +222,8 @@ export class BaseAPI {
|
|
|
227
222
|
if (err.response.status === 401 && !originalConfig._retry) {
|
|
228
223
|
originalConfig._retry = true;
|
|
229
224
|
try {
|
|
230
|
-
const
|
|
225
|
+
const tokenString = await this.refreshTokenInternal();
|
|
231
226
|
const accessToken = `Bearer ${tokenString}`;
|
|
232
|
-
this.permissions = permissions;
|
|
233
227
|
|
|
234
228
|
originalConfig.headers['Authorization'] = `Bearer ${accessToken}`
|
|
235
229
|
|
|
@@ -253,9 +247,8 @@ export class BaseAPI {
|
|
|
253
247
|
){
|
|
254
248
|
_retry_count++;
|
|
255
249
|
try {
|
|
256
|
-
const
|
|
250
|
+
const tokenString = await this.refreshTokenInternal();
|
|
257
251
|
const accessToken = `Bearer ${tokenString}`;
|
|
258
|
-
this.permissions = permissions;
|
|
259
252
|
|
|
260
253
|
_retry = true;
|
|
261
254
|
originalConfig.headers['Authorization'] = accessToken;
|
package/dist/base.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export interface LoginClass {
|
|
|
29
29
|
export declare enum Environment {
|
|
30
30
|
Production = "https://apiv2.emil.de",
|
|
31
31
|
Test = "https://apiv2-test.emil.de",
|
|
32
|
+
Staging = "https://apiv2-staging.emil.de",
|
|
32
33
|
Development = "https://apiv2-dev.emil.de",
|
|
33
34
|
ProductionZurich = "https://eu-central-2.apiv2.emil.de"
|
|
34
35
|
}
|
|
@@ -53,16 +54,14 @@ export declare class BaseAPI {
|
|
|
53
54
|
protected configuration: Configuration;
|
|
54
55
|
private username?;
|
|
55
56
|
private password?;
|
|
56
|
-
private permissions?;
|
|
57
57
|
constructor(configuration?: Configuration, basePath?: string, axios?: AxiosInstance);
|
|
58
58
|
initialize(env?: Environment): Promise<void>;
|
|
59
59
|
private loadCredentials;
|
|
60
60
|
private readConfigFile;
|
|
61
61
|
private readEnvVariables;
|
|
62
62
|
selectEnvironment(env: Environment): void;
|
|
63
|
-
getPermissions(): Array<string>;
|
|
64
63
|
authorize(username: string, password: string): Promise<void>;
|
|
65
|
-
refreshTokenInternal(): Promise<
|
|
64
|
+
refreshTokenInternal(): Promise<string>;
|
|
66
65
|
private extractRefreshToken;
|
|
67
66
|
getConfiguration(): Configuration;
|
|
68
67
|
private attachInterceptor;
|
package/dist/base.js
CHANGED
|
@@ -129,6 +129,7 @@ var Environment;
|
|
|
129
129
|
(function (Environment) {
|
|
130
130
|
Environment["Production"] = "https://apiv2.emil.de";
|
|
131
131
|
Environment["Test"] = "https://apiv2-test.emil.de";
|
|
132
|
+
Environment["Staging"] = "https://apiv2-staging.emil.de";
|
|
132
133
|
Environment["Development"] = "https://apiv2-dev.emil.de";
|
|
133
134
|
Environment["ProductionZurich"] = "https://eu-central-2.apiv2.emil.de";
|
|
134
135
|
})(Environment = exports.Environment || (exports.Environment = {}));
|
|
@@ -242,14 +243,11 @@ var BaseAPI = /** @class */ (function () {
|
|
|
242
243
|
BaseAPI.prototype.selectEnvironment = function (env) {
|
|
243
244
|
this.configuration.basePath = env;
|
|
244
245
|
};
|
|
245
|
-
BaseAPI.prototype.getPermissions = function () {
|
|
246
|
-
return this.permissions.split(',');
|
|
247
|
-
};
|
|
248
246
|
BaseAPI.prototype.authorize = function (username, password) {
|
|
249
247
|
return __awaiter(this, void 0, void 0, function () {
|
|
250
|
-
var options, response,
|
|
251
|
-
return __generator(this, function (
|
|
252
|
-
switch (
|
|
248
|
+
var options, response, accessToken, refreshToken;
|
|
249
|
+
return __generator(this, function (_a) {
|
|
250
|
+
switch (_a.label) {
|
|
253
251
|
case 0:
|
|
254
252
|
options = {
|
|
255
253
|
method: 'POST',
|
|
@@ -263,11 +261,10 @@ var BaseAPI = /** @class */ (function () {
|
|
|
263
261
|
};
|
|
264
262
|
return [4 /*yield*/, axios_1.default.request(options)];
|
|
265
263
|
case 1:
|
|
266
|
-
response =
|
|
267
|
-
|
|
264
|
+
response = _a.sent();
|
|
265
|
+
accessToken = response.data.accessToken;
|
|
268
266
|
this.configuration.username = username;
|
|
269
267
|
this.configuration.accessToken = "Bearer ".concat(accessToken);
|
|
270
|
-
this.permissions = permissions;
|
|
271
268
|
refreshToken = this.extractRefreshToken(response);
|
|
272
269
|
this.configuration.refreshToken = refreshToken;
|
|
273
270
|
return [2 /*return*/];
|
|
@@ -277,13 +274,13 @@ var BaseAPI = /** @class */ (function () {
|
|
|
277
274
|
};
|
|
278
275
|
BaseAPI.prototype.refreshTokenInternal = function () {
|
|
279
276
|
return __awaiter(this, void 0, void 0, function () {
|
|
280
|
-
var _a, username, refreshToken, options,
|
|
277
|
+
var _a, username, refreshToken, options, accessToken;
|
|
281
278
|
return __generator(this, function (_b) {
|
|
282
279
|
switch (_b.label) {
|
|
283
280
|
case 0:
|
|
284
281
|
_a = this.configuration, username = _a.username, refreshToken = _a.refreshToken;
|
|
285
282
|
if (!username || !refreshToken) {
|
|
286
|
-
|
|
283
|
+
return [2 /*return*/, ''];
|
|
287
284
|
}
|
|
288
285
|
options = {
|
|
289
286
|
method: 'POST',
|
|
@@ -297,8 +294,8 @@ var BaseAPI = /** @class */ (function () {
|
|
|
297
294
|
};
|
|
298
295
|
return [4 /*yield*/, axios_1.default.request(options)];
|
|
299
296
|
case 1:
|
|
300
|
-
|
|
301
|
-
return [2 /*return*/,
|
|
297
|
+
accessToken = (_b.sent()).data.accessToken;
|
|
298
|
+
return [2 /*return*/, accessToken];
|
|
302
299
|
}
|
|
303
300
|
});
|
|
304
301
|
});
|
|
@@ -318,27 +315,26 @@ var BaseAPI = /** @class */ (function () {
|
|
|
318
315
|
axios.interceptors.response.use(function (res) {
|
|
319
316
|
return res;
|
|
320
317
|
}, function (err) { return __awaiter(_this, void 0, void 0, function () {
|
|
321
|
-
var originalConfig,
|
|
322
|
-
return __generator(this, function (
|
|
323
|
-
switch (
|
|
318
|
+
var originalConfig, tokenString, accessToken, _error_1, tokenString, accessToken, _error_2;
|
|
319
|
+
return __generator(this, function (_a) {
|
|
320
|
+
switch (_a.label) {
|
|
324
321
|
case 0:
|
|
325
322
|
originalConfig = err.config;
|
|
326
323
|
if (!err.response) return [3 /*break*/, 5];
|
|
327
324
|
if (!(err.response.status === 401 && !originalConfig._retry)) return [3 /*break*/, 4];
|
|
328
325
|
originalConfig._retry = true;
|
|
329
|
-
|
|
326
|
+
_a.label = 1;
|
|
330
327
|
case 1:
|
|
331
|
-
|
|
328
|
+
_a.trys.push([1, 3, , 4]);
|
|
332
329
|
return [4 /*yield*/, this.refreshTokenInternal()];
|
|
333
330
|
case 2:
|
|
334
|
-
|
|
331
|
+
tokenString = _a.sent();
|
|
335
332
|
accessToken = "Bearer ".concat(tokenString);
|
|
336
|
-
this.permissions = permissions;
|
|
337
333
|
originalConfig.headers['Authorization'] = "Bearer ".concat(accessToken);
|
|
338
334
|
this.configuration.accessToken = accessToken;
|
|
339
335
|
return [2 /*return*/, axios.request(originalConfig)];
|
|
340
336
|
case 3:
|
|
341
|
-
_error_1 =
|
|
337
|
+
_error_1 = _a.sent();
|
|
342
338
|
if (_error_1.response && _error_1.response.data) {
|
|
343
339
|
return [2 /*return*/, Promise.reject(_error_1.response.data)];
|
|
344
340
|
}
|
|
@@ -354,20 +350,19 @@ var BaseAPI = /** @class */ (function () {
|
|
|
354
350
|
&& originalConfig.headers.hasOwnProperty('Authorization')
|
|
355
351
|
&& _retry_count < 4)) return [3 /*break*/, 9];
|
|
356
352
|
_retry_count++;
|
|
357
|
-
|
|
353
|
+
_a.label = 6;
|
|
358
354
|
case 6:
|
|
359
|
-
|
|
355
|
+
_a.trys.push([6, 8, , 9]);
|
|
360
356
|
return [4 /*yield*/, this.refreshTokenInternal()];
|
|
361
357
|
case 7:
|
|
362
|
-
|
|
358
|
+
tokenString = _a.sent();
|
|
363
359
|
accessToken = "Bearer ".concat(tokenString);
|
|
364
|
-
this.permissions = permissions;
|
|
365
360
|
_retry = true;
|
|
366
361
|
originalConfig.headers['Authorization'] = accessToken;
|
|
367
362
|
this.configuration.accessToken = accessToken;
|
|
368
363
|
return [2 /*return*/, axios.request(__assign({}, originalConfig))];
|
|
369
364
|
case 8:
|
|
370
|
-
_error_2 =
|
|
365
|
+
_error_2 = _a.sent();
|
|
371
366
|
if (_error_2.response && _error_2.response.data) {
|
|
372
367
|
return [2 /*return*/, Promise.reject(_error_2.response.data)];
|
|
373
368
|
}
|