@emilgroup/customer-sdk-node 1.1.1 → 1.3.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/dist/base.js CHANGED
@@ -106,6 +106,7 @@ var configuration_1 = require("./configuration");
106
106
  // Some imports not used depending on template conditions
107
107
  // @ts-ignore
108
108
  var axios_1 = __importDefault(require("axios"));
109
+ var fs = __importStar(require("fs"));
109
110
  var path = __importStar(require("path"));
110
111
  var os = __importStar(require("os"));
111
112
  exports.BASE_PATH = "https://apiv2.emil.de".replace(/\/+$/, "");
@@ -140,6 +141,7 @@ var BaseAPI = /** @class */ (function () {
140
141
  if (axios === void 0) { axios = axios_1.default; }
141
142
  this.basePath = basePath;
142
143
  this.axios = axios;
144
+ this.isCustomerToken = false;
143
145
  if (configuration) {
144
146
  this.configuration = configuration;
145
147
  this.basePath = configuration.basePath || this.basePath;
@@ -151,10 +153,88 @@ var BaseAPI = /** @class */ (function () {
151
153
  }
152
154
  this.attachInterceptor(axios);
153
155
  }
156
+ BaseAPI.prototype.initialize = function (env) {
157
+ if (env === void 0) { env = Environment.Production; }
158
+ return __awaiter(this, void 0, void 0, function () {
159
+ return __generator(this, function (_a) {
160
+ switch (_a.label) {
161
+ case 0:
162
+ this.configuration.basePath = env;
163
+ return [4 /*yield*/, this.loadCredentials()];
164
+ case 1:
165
+ _a.sent();
166
+ if (!this.username) return [3 /*break*/, 3];
167
+ return [4 /*yield*/, this.authorize(this.username, this.password)];
168
+ case 2:
169
+ _a.sent();
170
+ this.password = null; // to avoid keeping password loaded in memory.
171
+ _a.label = 3;
172
+ case 3: return [2 /*return*/];
173
+ }
174
+ });
175
+ });
176
+ };
177
+ BaseAPI.prototype.loadCredentials = function () {
178
+ return __awaiter(this, void 0, void 0, function () {
179
+ var error_1;
180
+ return __generator(this, function (_a) {
181
+ switch (_a.label) {
182
+ case 0:
183
+ _a.trys.push([0, 2, , 3]);
184
+ return [4 /*yield*/, this.readConfigFile()];
185
+ case 1:
186
+ _a.sent();
187
+ return [3 /*break*/, 3];
188
+ case 2:
189
+ error_1 = _a.sent();
190
+ console.warn("No credentials file found. Check that ".concat(filePath, " exists."));
191
+ return [3 /*break*/, 3];
192
+ case 3:
193
+ this.readEnvVariables();
194
+ if (!this.username) {
195
+ console.info("No credentials found in credentials file or environment variables. Either provide some or use \n authorize() function.");
196
+ }
197
+ return [2 /*return*/];
198
+ }
199
+ });
200
+ });
201
+ };
202
+ BaseAPI.prototype.readConfigFile = function () {
203
+ return __awaiter(this, void 0, void 0, function () {
204
+ var file, lines;
205
+ var _this = this;
206
+ return __generator(this, function (_a) {
207
+ switch (_a.label) {
208
+ case 0: return [4 /*yield*/, fs.promises.readFile(filePath, 'utf-8')];
209
+ case 1:
210
+ file = _a.sent();
211
+ lines = file.split(os.EOL)
212
+ .filter(Boolean);
213
+ lines.forEach(function (line) {
214
+ if (line.startsWith(KEY_USERNAME)) {
215
+ _this.username = line.length > KEY_USERNAME.length + 1 ? line.substring(KEY_USERNAME.length + 1) : '';
216
+ }
217
+ else if (line.startsWith(KEY_PASSWORD)) {
218
+ _this.password = line.length > KEY_PASSWORD.length + 1 ? line.substring(KEY_PASSWORD.length + 1) : '';
219
+ }
220
+ });
221
+ return [2 /*return*/];
222
+ }
223
+ });
224
+ });
225
+ };
226
+ BaseAPI.prototype.readEnvVariables = function () {
227
+ if (process.env.EMIL_USERNAME) {
228
+ this.username = process.env.EMIL_USERNAME;
229
+ this.password = process.env.EMIL_PASSWORD || '';
230
+ return true;
231
+ }
232
+ return false;
233
+ };
154
234
  BaseAPI.prototype.selectEnvironment = function (env) {
155
235
  this.configuration.basePath = env;
156
236
  };
157
- BaseAPI.prototype.authorize = function (username, password, tenantSlug) {
237
+ BaseAPI.prototype.authorize = function (username, password) {
158
238
  return __awaiter(this, void 0, void 0, function () {
159
239
  var options, response, accessToken, refreshToken;
160
240
  return __generator(this, function (_a) {
@@ -162,12 +242,11 @@ var BaseAPI = /** @class */ (function () {
162
242
  case 0:
163
243
  options = {
164
244
  method: 'POST',
165
- url: "".concat(this.configuration.basePath, "/v1/customers/login"),
245
+ url: "".concat(this.configuration.basePath, "/authservice/v1/login"),
166
246
  headers: { 'Content-Type': 'application/json' },
167
247
  data: {
168
248
  username: username,
169
249
  password: password,
170
- tenantSlug: tenantSlug,
171
250
  },
172
251
  withCredentials: true,
173
252
  };
@@ -177,7 +256,6 @@ var BaseAPI = /** @class */ (function () {
177
256
  accessToken = response.data.accessToken;
178
257
  refreshToken = this.extractRefreshToken(response);
179
258
  this.configuration.username = username;
180
- this.configuration.tenantSlug = tenantSlug;
181
259
  this.configuration.accessToken = "Bearer ".concat(accessToken);
182
260
  this.configuration.refreshToken = refreshToken;
183
261
  return [2 /*return*/];
@@ -185,7 +263,100 @@ var BaseAPI = /** @class */ (function () {
185
263
  });
186
264
  });
187
265
  };
188
- BaseAPI.prototype.refreshTokenInternal = function () {
266
+ BaseAPI.prototype.initiateAuthorization = function (username, password, tenantSlug) {
267
+ return __awaiter(this, void 0, void 0, function () {
268
+ var options, response, accessToken, refreshToken;
269
+ return __generator(this, function (_a) {
270
+ switch (_a.label) {
271
+ case 0:
272
+ options = {
273
+ method: 'POST',
274
+ url: "".concat(this.configuration.basePath, "/v1/customers/auth/initiate"),
275
+ headers: { 'Content-Type': 'application/json' },
276
+ data: {
277
+ authFlow: "USER_PASSWORD_AUTH",
278
+ authParameters: {
279
+ "USERNAME": username,
280
+ "PASSWORD": password,
281
+ },
282
+ tenantSlug: tenantSlug,
283
+ },
284
+ withCredentials: true,
285
+ };
286
+ return [4 /*yield*/, axios_1.default.request(options)];
287
+ case 1:
288
+ response = _a.sent();
289
+ if (response.data.authenticationResult) {
290
+ accessToken = response.data.authenticationResult.accessToken;
291
+ refreshToken = this.extractRefreshToken(response);
292
+ this.configuration.username = username;
293
+ this.configuration.tenantSlug = tenantSlug;
294
+ this.configuration.accessToken = "Bearer ".concat(accessToken);
295
+ this.configuration.refreshToken = refreshToken;
296
+ this.isCustomerToken = true;
297
+ }
298
+ return [2 /*return*/, response];
299
+ }
300
+ });
301
+ });
302
+ };
303
+ BaseAPI.prototype.respondToAuthorizationChallenge = function (respondToAuthChallengeRequestDto) {
304
+ return __awaiter(this, void 0, void 0, function () {
305
+ var options, response, accessToken, refreshToken;
306
+ return __generator(this, function (_a) {
307
+ switch (_a.label) {
308
+ case 0:
309
+ options = {
310
+ method: 'POST',
311
+ url: "".concat(this.configuration.basePath, "/v1/customers/auth/respond"),
312
+ headers: { 'Content-Type': 'application/json' },
313
+ data: __assign({}, respondToAuthChallengeRequestDto),
314
+ withCredentials: true,
315
+ };
316
+ return [4 /*yield*/, axios_1.default.request(options)];
317
+ case 1:
318
+ response = _a.sent();
319
+ if (response.data.authenticationResult) {
320
+ accessToken = response.data.authenticationResult.accessToken;
321
+ refreshToken = this.extractRefreshToken(response);
322
+ this.configuration.accessToken = "Bearer ".concat(accessToken);
323
+ this.configuration.refreshToken = refreshToken;
324
+ this.isCustomerToken = true;
325
+ }
326
+ return [2 /*return*/, response];
327
+ }
328
+ });
329
+ });
330
+ };
331
+ BaseAPI.prototype.refreshTokenTenant = function () {
332
+ return __awaiter(this, void 0, void 0, function () {
333
+ var _a, username, refreshToken, options, accessToken;
334
+ return __generator(this, function (_b) {
335
+ switch (_b.label) {
336
+ case 0:
337
+ _a = this.configuration, username = _a.username, refreshToken = _a.refreshToken;
338
+ if (!username || !refreshToken) {
339
+ return [2 /*return*/, ''];
340
+ }
341
+ options = {
342
+ method: 'POST',
343
+ url: "".concat(this.configuration.basePath, "/authservice/v1/refresh-token"),
344
+ headers: {
345
+ 'Content-Type': 'application/json',
346
+ Cookie: refreshToken,
347
+ },
348
+ data: { username: username },
349
+ withCredentials: true,
350
+ };
351
+ return [4 /*yield*/, axios_1.default.request(options)];
352
+ case 1:
353
+ accessToken = (_b.sent()).data.accessToken;
354
+ return [2 /*return*/, accessToken];
355
+ }
356
+ });
357
+ });
358
+ };
359
+ BaseAPI.prototype.refreshTokenCustomer = function () {
189
360
  return __awaiter(this, void 0, void 0, function () {
190
361
  var _a, username, refreshToken, tenantSlug, options, accessToken;
191
362
  return __generator(this, function (_b) {
@@ -230,33 +401,41 @@ var BaseAPI = /** @class */ (function () {
230
401
  switch (_a.label) {
231
402
  case 0:
232
403
  originalConfig = err.config;
233
- if (!err.response) return [3 /*break*/, 5];
234
- if (!(err.response.status === 401 && !originalConfig._retry)) return [3 /*break*/, 4];
404
+ if (!err.response) return [3 /*break*/, 8];
405
+ if (!(err.response.status === 401 && !originalConfig._retry)) return [3 /*break*/, 7];
235
406
  originalConfig._retry = true;
236
407
  _a.label = 1;
237
408
  case 1:
238
- _a.trys.push([1, 3, , 4]);
239
- return [4 /*yield*/, this.refreshTokenInternal()];
409
+ _a.trys.push([1, 6, , 7]);
410
+ tokenString = void 0;
411
+ if (!this.isCustomerToken) return [3 /*break*/, 3];
412
+ return [4 /*yield*/, this.refreshTokenCustomer()];
240
413
  case 2:
241
414
  tokenString = _a.sent();
415
+ return [3 /*break*/, 5];
416
+ case 3: return [4 /*yield*/, this.refreshTokenTenant()];
417
+ case 4:
418
+ tokenString = _a.sent();
419
+ _a.label = 5;
420
+ case 5:
242
421
  accessToken = "Bearer ".concat(tokenString);
243
422
  localVarHeaderParameter = {};
244
423
  localVarHeaderParameter['Authorization'] = accessToken;
245
424
  originalConfig.headers = __assign(__assign({}, originalConfig.headers), localVarHeaderParameter);
246
425
  this.configuration.accessToken = accessToken;
247
426
  return [2 /*return*/, axios(originalConfig)];
248
- case 3:
427
+ case 6:
249
428
  _error_1 = _a.sent();
250
429
  if (_error_1.response && _error_1.response.data) {
251
430
  return [2 /*return*/, Promise.reject(_error_1.response.data)];
252
431
  }
253
432
  return [2 /*return*/, Promise.reject(_error_1)];
254
- case 4:
433
+ case 7:
255
434
  if (err.response.status === 403 && err.response.data) {
256
435
  return [2 /*return*/, Promise.reject(err.response.data)];
257
436
  }
258
- _a.label = 5;
259
- case 5: return [2 /*return*/, Promise.reject(err)];
437
+ _a.label = 8;
438
+ case 8: return [2 /*return*/, Promise.reject(err)];
260
439
  }
261
440
  });
262
441
  }); });
@@ -18,6 +18,7 @@ export * from './policy-premium-class';
18
18
  export * from './policy-premium-item-class';
19
19
  export * from './policy-version-class';
20
20
  export * from './refresh-token-dto';
21
+ export * from './request-policy-update-response-class';
21
22
  export * from './reset-password-by-customer-request-dto';
22
23
  export * from './respond-to-auth-challenge-class';
23
24
  export * from './respond-to-auth-challenge-request-dto';
@@ -34,6 +34,7 @@ __exportStar(require("./policy-premium-class"), exports);
34
34
  __exportStar(require("./policy-premium-item-class"), exports);
35
35
  __exportStar(require("./policy-version-class"), exports);
36
36
  __exportStar(require("./refresh-token-dto"), exports);
37
+ __exportStar(require("./request-policy-update-response-class"), exports);
37
38
  __exportStar(require("./reset-password-by-customer-request-dto"), exports);
38
39
  __exportStar(require("./respond-to-auth-challenge-class"), exports);
39
40
  __exportStar(require("./respond-to-auth-challenge-request-dto"), exports);
@@ -21,23 +21,23 @@ export interface InitiateAuthResponseClass {
21
21
  * @type {AuthenticationResultClass}
22
22
  * @memberof InitiateAuthResponseClass
23
23
  */
24
- 'authenticationResult': AuthenticationResultClass;
24
+ 'authenticationResult'?: AuthenticationResultClass;
25
25
  /**
26
26
  * Challenge name
27
27
  * @type {string}
28
28
  * @memberof InitiateAuthResponseClass
29
29
  */
30
- 'challengeName': string;
30
+ 'challengeName'?: string;
31
31
  /**
32
32
  * MFA Challenge parameters
33
33
  * @type {object}
34
34
  * @memberof InitiateAuthResponseClass
35
35
  */
36
- 'challengeParameters': object;
36
+ 'challengeParameters'?: object;
37
37
  /**
38
38
  * session
39
39
  * @type {string}
40
40
  * @memberof InitiateAuthResponseClass
41
41
  */
42
- 'session': string;
42
+ 'session'?: string;
43
43
  }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * EMIL CustomerService
3
+ * The EMIL CustomerService API description
4
+ *
5
+ * The version of the OpenAPI document: 1.0
6
+ *
7
+ *
8
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
+ * https://openapi-generator.tech
10
+ * Do not edit the class manually.
11
+ */
12
+ import { PolicyClass } from './policy-class';
13
+ /**
14
+ *
15
+ * @export
16
+ * @interface RequestPolicyUpdateResponseClass
17
+ */
18
+ export interface RequestPolicyUpdateResponseClass {
19
+ /**
20
+ * Policy
21
+ * @type {PolicyClass}
22
+ * @memberof RequestPolicyUpdateResponseClass
23
+ */
24
+ 'policy': PolicyClass;
25
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ /**
5
+ * EMIL CustomerService
6
+ * The EMIL CustomerService API description
7
+ *
8
+ * The version of the OpenAPI document: 1.0
9
+ *
10
+ *
11
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
12
+ * https://openapi-generator.tech
13
+ * Do not edit the class manually.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -21,23 +21,23 @@ export interface RespondToAuthChallengeClass {
21
21
  * @type {AuthenticationResultClass}
22
22
  * @memberof RespondToAuthChallengeClass
23
23
  */
24
- 'authenticationResult': AuthenticationResultClass;
24
+ 'authenticationResult'?: AuthenticationResultClass;
25
25
  /**
26
26
  * Challenge name
27
27
  * @type {string}
28
28
  * @memberof RespondToAuthChallengeClass
29
29
  */
30
- 'challengeName': string;
30
+ 'challengeName'?: string;
31
31
  /**
32
32
  * MFA Challenge
33
33
  * @type {object}
34
34
  * @memberof RespondToAuthChallengeClass
35
35
  */
36
- 'challengeParameters': object;
36
+ 'challengeParameters'?: object;
37
37
  /**
38
38
  * session
39
39
  * @type {string}
40
40
  * @memberof RespondToAuthChallengeClass
41
41
  */
42
- 'session': string;
42
+ 'session'?: string;
43
43
  }
package/models/index.ts CHANGED
@@ -18,6 +18,7 @@ export * from './policy-premium-class';
18
18
  export * from './policy-premium-item-class';
19
19
  export * from './policy-version-class';
20
20
  export * from './refresh-token-dto';
21
+ export * from './request-policy-update-response-class';
21
22
  export * from './reset-password-by-customer-request-dto';
22
23
  export * from './respond-to-auth-challenge-class';
23
24
  export * from './respond-to-auth-challenge-request-dto';
@@ -26,24 +26,24 @@ export interface InitiateAuthResponseClass {
26
26
  * @type {AuthenticationResultClass}
27
27
  * @memberof InitiateAuthResponseClass
28
28
  */
29
- 'authenticationResult': AuthenticationResultClass;
29
+ 'authenticationResult'?: AuthenticationResultClass;
30
30
  /**
31
31
  * Challenge name
32
32
  * @type {string}
33
33
  * @memberof InitiateAuthResponseClass
34
34
  */
35
- 'challengeName': string;
35
+ 'challengeName'?: string;
36
36
  /**
37
37
  * MFA Challenge parameters
38
38
  * @type {object}
39
39
  * @memberof InitiateAuthResponseClass
40
40
  */
41
- 'challengeParameters': object;
41
+ 'challengeParameters'?: object;
42
42
  /**
43
43
  * session
44
44
  * @type {string}
45
45
  * @memberof InitiateAuthResponseClass
46
46
  */
47
- 'session': string;
47
+ 'session'?: string;
48
48
  }
49
49
 
@@ -0,0 +1,31 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * EMIL CustomerService
5
+ * The EMIL CustomerService 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 { PolicyClass } from './policy-class';
17
+
18
+ /**
19
+ *
20
+ * @export
21
+ * @interface RequestPolicyUpdateResponseClass
22
+ */
23
+ export interface RequestPolicyUpdateResponseClass {
24
+ /**
25
+ * Policy
26
+ * @type {PolicyClass}
27
+ * @memberof RequestPolicyUpdateResponseClass
28
+ */
29
+ 'policy': PolicyClass;
30
+ }
31
+
@@ -26,24 +26,24 @@ export interface RespondToAuthChallengeClass {
26
26
  * @type {AuthenticationResultClass}
27
27
  * @memberof RespondToAuthChallengeClass
28
28
  */
29
- 'authenticationResult': AuthenticationResultClass;
29
+ 'authenticationResult'?: AuthenticationResultClass;
30
30
  /**
31
31
  * Challenge name
32
32
  * @type {string}
33
33
  * @memberof RespondToAuthChallengeClass
34
34
  */
35
- 'challengeName': string;
35
+ 'challengeName'?: string;
36
36
  /**
37
37
  * MFA Challenge
38
38
  * @type {object}
39
39
  * @memberof RespondToAuthChallengeClass
40
40
  */
41
- 'challengeParameters': object;
41
+ 'challengeParameters'?: object;
42
42
  /**
43
43
  * session
44
44
  * @type {string}
45
45
  * @memberof RespondToAuthChallengeClass
46
46
  */
47
- 'session': string;
47
+ 'session'?: string;
48
48
  }
49
49
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emilgroup/customer-sdk-node",
3
- "version": "1.1.1",
3
+ "version": "1.3.0",
4
4
  "description": "OpenAPI client for @emilgroup/customer-sdk-node",
5
5
  "author": "OpenAPI-Generator Contributors",
6
6
  "keywords": [
@@ -18,12 +18,13 @@
18
18
  "prepare": "npm run build"
19
19
  },
20
20
  "dependencies": {
21
- "axios": "^0.26.1",
21
+ "axios": "^0.26.1"
22
+ ,
22
23
  "form-data": "^4.0.0",
23
24
  "url": "^0.11.0"
24
25
  },
25
26
  "devDependencies": {
26
- "@types/node": "^12.11.5",
27
+ "@types/node": "^12.11.5",
27
28
  "typescript": "^4.0"
28
29
  }
29
30
  }