@emilgroup/tenant-sdk 1.5.0 → 1.5.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.
@@ -85,10 +85,6 @@ var axios_1 = __importDefault(require("axios"));
85
85
  var common_1 = require("../common");
86
86
  // @ts-ignore
87
87
  var base_1 = require("../base");
88
- // URLSearchParams not necessarily used
89
- // @ts-ignore
90
- var url_1 = require("url");
91
- var FormData = require('form-data');
92
88
  /**
93
89
  * InviteUsersApi - axios parameter creator
94
90
  * @export
@@ -115,7 +111,7 @@ var InviteUsersApiAxiosParamCreator = function (configuration) {
115
111
  (0, common_1.assertParamExists)('deleteInvite', 'id', id);
116
112
  localVarPath = "/tenantservice/v1/users/invites/{id}"
117
113
  .replace("{".concat("id", "}"), encodeURIComponent(String(id)));
118
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
114
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
119
115
  if (configuration) {
120
116
  baseOptions = configuration.baseOptions;
121
117
  baseAccessToken = configuration.accessToken;
@@ -162,7 +158,7 @@ var InviteUsersApiAxiosParamCreator = function (configuration) {
162
158
  // verify required parameter 'batchDeleteRequestDto' is not null or undefined
163
159
  (0, common_1.assertParamExists)('deleteInvites', 'batchDeleteRequestDto', batchDeleteRequestDto);
164
160
  localVarPath = "/tenantservice/v1/users/invites/delete-batch";
165
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
161
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
166
162
  if (configuration) {
167
163
  baseOptions = configuration.baseOptions;
168
164
  baseAccessToken = configuration.accessToken;
@@ -211,7 +207,7 @@ var InviteUsersApiAxiosParamCreator = function (configuration) {
211
207
  // verify required parameter 'inviteUserRequestDto' is not null or undefined
212
208
  (0, common_1.assertParamExists)('inviteUser', 'inviteUserRequestDto', inviteUserRequestDto);
213
209
  localVarPath = "/tenantservice/v1/users/invites";
214
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
210
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
215
211
  if (configuration) {
216
212
  baseOptions = configuration.baseOptions;
217
213
  baseAccessToken = configuration.accessToken;
@@ -260,7 +256,7 @@ var InviteUsersApiAxiosParamCreator = function (configuration) {
260
256
  // verify required parameter 'inviteUsersRequestDto' is not null or undefined
261
257
  (0, common_1.assertParamExists)('inviteUsers', 'inviteUsersRequestDto', inviteUsersRequestDto);
262
258
  localVarPath = "/tenantservice/v1/users/invites/batch";
263
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
259
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
264
260
  if (configuration) {
265
261
  baseOptions = configuration.baseOptions;
266
262
  baseAccessToken = configuration.accessToken;
@@ -312,7 +308,7 @@ var InviteUsersApiAxiosParamCreator = function (configuration) {
312
308
  switch (_a.label) {
313
309
  case 0:
314
310
  localVarPath = "/tenantservice/v1/users/invites";
315
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
311
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
316
312
  if (configuration) {
317
313
  baseOptions = configuration.baseOptions;
318
314
  baseAccessToken = configuration.accessToken;
@@ -85,10 +85,6 @@ var axios_1 = __importDefault(require("axios"));
85
85
  var common_1 = require("../common");
86
86
  // @ts-ignore
87
87
  var base_1 = require("../base");
88
- // URLSearchParams not necessarily used
89
- // @ts-ignore
90
- var url_1 = require("url");
91
- var FormData = require('form-data');
92
88
  /**
93
89
  * ListOrganizationInvitationsApi - axios parameter creator
94
90
  * @export
@@ -117,7 +113,7 @@ var ListOrganizationInvitationsApiAxiosParamCreator = function (configuration) {
117
113
  switch (_a.label) {
118
114
  case 0:
119
115
  localVarPath = "/tenantservice/v1/invitations/organizations";
120
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
116
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
121
117
  if (configuration) {
122
118
  baseOptions = configuration.baseOptions;
123
119
  baseAccessToken = configuration.accessToken;
@@ -85,10 +85,6 @@ var axios_1 = __importDefault(require("axios"));
85
85
  var common_1 = require("../common");
86
86
  // @ts-ignore
87
87
  var base_1 = require("../base");
88
- // URLSearchParams not necessarily used
89
- // @ts-ignore
90
- var url_1 = require("url");
91
- var FormData = require('form-data');
92
88
  /**
93
89
  * OrganizationsApi - axios parameter creator
94
90
  * @export
@@ -115,7 +111,7 @@ var OrganizationsApiAxiosParamCreator = function (configuration) {
115
111
  (0, common_1.assertParamExists)('getOrganization', 'code', code);
116
112
  localVarPath = "/tenantservice/v1/organizations/{code}"
117
113
  .replace("{".concat("code", "}"), encodeURIComponent(String(code)));
118
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
114
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
119
115
  if (configuration) {
120
116
  baseOptions = configuration.baseOptions;
121
117
  baseAccessToken = configuration.accessToken;
@@ -165,7 +161,7 @@ var OrganizationsApiAxiosParamCreator = function (configuration) {
165
161
  switch (_a.label) {
166
162
  case 0:
167
163
  localVarPath = "/tenantservice/v1/organizations";
168
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
164
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
169
165
  if (configuration) {
170
166
  baseOptions = configuration.baseOptions;
171
167
  baseAccessToken = configuration.accessToken;
@@ -234,7 +230,7 @@ var OrganizationsApiAxiosParamCreator = function (configuration) {
234
230
  (0, common_1.assertParamExists)('updateOrganization', 'updateOrganizationRequestDtoRest', updateOrganizationRequestDtoRest);
235
231
  localVarPath = "/tenantservice/v1/organizations/{code}"
236
232
  .replace("{".concat("code", "}"), encodeURIComponent(String(code)));
237
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
233
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
238
234
  if (configuration) {
239
235
  baseOptions = configuration.baseOptions;
240
236
  baseAccessToken = configuration.accessToken;
@@ -85,10 +85,6 @@ var axios_1 = __importDefault(require("axios"));
85
85
  var common_1 = require("../common");
86
86
  // @ts-ignore
87
87
  var base_1 = require("../base");
88
- // URLSearchParams not necessarily used
89
- // @ts-ignore
90
- var url_1 = require("url");
91
- var FormData = require('form-data');
92
88
  /**
93
89
  * ReInviteAnOrganizationApi - axios parameter creator
94
90
  * @export
@@ -113,7 +109,7 @@ var ReInviteAnOrganizationApiAxiosParamCreator = function (configuration) {
113
109
  // verify required parameter 'reInviteOrgRequestDto' is not null or undefined
114
110
  (0, common_1.assertParamExists)('reInviteOrganization', 'reInviteOrgRequestDto', reInviteOrgRequestDto);
115
111
  localVarPath = "/tenantservice/v1/invitations/organizations";
116
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
112
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
117
113
  if (configuration) {
118
114
  baseOptions = configuration.baseOptions;
119
115
  baseAccessToken = configuration.accessToken;
@@ -85,10 +85,6 @@ var axios_1 = __importDefault(require("axios"));
85
85
  var common_1 = require("../common");
86
86
  // @ts-ignore
87
87
  var base_1 = require("../base");
88
- // URLSearchParams not necessarily used
89
- // @ts-ignore
90
- var url_1 = require("url");
91
- var FormData = require('form-data');
92
88
  /**
93
89
  * RolesApi - axios parameter creator
94
90
  * @export
@@ -117,7 +113,7 @@ var RolesApiAxiosParamCreator = function (configuration) {
117
113
  switch (_a.label) {
118
114
  case 0:
119
115
  localVarPath = "/tenantservice/v1/roles";
120
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
116
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
121
117
  if (configuration) {
122
118
  baseOptions = configuration.baseOptions;
123
119
  baseAccessToken = configuration.accessToken;
@@ -85,10 +85,6 @@ var axios_1 = __importDefault(require("axios"));
85
85
  var common_1 = require("../common");
86
86
  // @ts-ignore
87
87
  var base_1 = require("../base");
88
- // URLSearchParams not necessarily used
89
- // @ts-ignore
90
- var url_1 = require("url");
91
- var FormData = require('form-data');
92
88
  /**
93
89
  * SettingsApi - axios parameter creator
94
90
  * @export
@@ -114,7 +110,7 @@ var SettingsApiAxiosParamCreator = function (configuration) {
114
110
  // verify required parameter 'keys' is not null or undefined
115
111
  (0, common_1.assertParamExists)('getTenantSettings', 'keys', keys);
116
112
  localVarPath = "/tenantservice/v1/settings/tenant";
117
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
113
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
118
114
  if (configuration) {
119
115
  baseOptions = configuration.baseOptions;
120
116
  baseAccessToken = configuration.accessToken;
@@ -85,10 +85,6 @@ var axios_1 = __importDefault(require("axios"));
85
85
  var common_1 = require("../common");
86
86
  // @ts-ignore
87
87
  var base_1 = require("../base");
88
- // URLSearchParams not necessarily used
89
- // @ts-ignore
90
- var url_1 = require("url");
91
- var FormData = require('form-data');
92
88
  /**
93
89
  * UsersApi - axios parameter creator
94
90
  * @export
@@ -117,7 +113,7 @@ var UsersApiAxiosParamCreator = function (configuration) {
117
113
  (0, common_1.assertParamExists)('assignUserRoles', 'assignUserRolesRequestDto', assignUserRolesRequestDto);
118
114
  localVarPath = "/tenantservice/v1/users/{id}/assign-roles"
119
115
  .replace("{".concat("id", "}"), encodeURIComponent(String(id)));
120
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
116
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
121
117
  if (configuration) {
122
118
  baseOptions = configuration.baseOptions;
123
119
  baseAccessToken = configuration.accessToken;
@@ -166,7 +162,7 @@ var UsersApiAxiosParamCreator = function (configuration) {
166
162
  (0, common_1.assertParamExists)('deleteUser', 'id', id);
167
163
  localVarPath = "/tenantservice/v1/users/{id}"
168
164
  .replace("{".concat("id", "}"), encodeURIComponent(String(id)));
169
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
165
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
170
166
  if (configuration) {
171
167
  baseOptions = configuration.baseOptions;
172
168
  baseAccessToken = configuration.accessToken;
@@ -212,7 +208,7 @@ var UsersApiAxiosParamCreator = function (configuration) {
212
208
  // verify required parameter 'batchDeleteRequestDto' is not null or undefined
213
209
  (0, common_1.assertParamExists)('deleteUsers', 'batchDeleteRequestDto', batchDeleteRequestDto);
214
210
  localVarPath = "/tenantservice/v1/users/delete-batch";
215
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
211
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
216
212
  if (configuration) {
217
213
  baseOptions = configuration.baseOptions;
218
214
  baseAccessToken = configuration.accessToken;
@@ -261,7 +257,7 @@ var UsersApiAxiosParamCreator = function (configuration) {
261
257
  (0, common_1.assertParamExists)('disableUser', 'id', id);
262
258
  localVarPath = "/tenantservice/v1/users/{id}/disable"
263
259
  .replace("{".concat("id", "}"), encodeURIComponent(String(id)));
264
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
260
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
265
261
  if (configuration) {
266
262
  baseOptions = configuration.baseOptions;
267
263
  baseAccessToken = configuration.accessToken;
@@ -307,7 +303,7 @@ var UsersApiAxiosParamCreator = function (configuration) {
307
303
  // verify required parameter 'disableUsersRequestDto' is not null or undefined
308
304
  (0, common_1.assertParamExists)('disableUsers', 'disableUsersRequestDto', disableUsersRequestDto);
309
305
  localVarPath = "/tenantservice/v1/users/disable-batch";
310
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
306
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
311
307
  if (configuration) {
312
308
  baseOptions = configuration.baseOptions;
313
309
  baseAccessToken = configuration.accessToken;
@@ -356,7 +352,7 @@ var UsersApiAxiosParamCreator = function (configuration) {
356
352
  (0, common_1.assertParamExists)('enableUser', 'id', id);
357
353
  localVarPath = "/tenantservice/v1/users/{id}/enable"
358
354
  .replace("{".concat("id", "}"), encodeURIComponent(String(id)));
359
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
355
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
360
356
  if (configuration) {
361
357
  baseOptions = configuration.baseOptions;
362
358
  baseAccessToken = configuration.accessToken;
@@ -402,7 +398,7 @@ var UsersApiAxiosParamCreator = function (configuration) {
402
398
  // verify required parameter 'enableUsersRequestDto' is not null or undefined
403
399
  (0, common_1.assertParamExists)('enableUsers', 'enableUsersRequestDto', enableUsersRequestDto);
404
400
  localVarPath = "/tenantservice/v1/users/enable-batch";
405
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
401
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
406
402
  if (configuration) {
407
403
  baseOptions = configuration.baseOptions;
408
404
  baseAccessToken = configuration.accessToken;
@@ -455,7 +451,7 @@ var UsersApiAxiosParamCreator = function (configuration) {
455
451
  (0, common_1.assertParamExists)('getUser', 'code2', code2);
456
452
  localVarPath = "/tenantservice/v1/users/{code}"
457
453
  .replace("{".concat("code", "}"), encodeURIComponent(String(code)));
458
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
454
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
459
455
  if (configuration) {
460
456
  baseOptions = configuration.baseOptions;
461
457
  baseAccessToken = configuration.accessToken;
@@ -511,7 +507,7 @@ var UsersApiAxiosParamCreator = function (configuration) {
511
507
  switch (_a.label) {
512
508
  case 0:
513
509
  localVarPath = "/tenantservice/v1/users";
514
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
510
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
515
511
  if (configuration) {
516
512
  baseOptions = configuration.baseOptions;
517
513
  baseAccessToken = configuration.accessToken;
package/dist/base.d.ts CHANGED
@@ -49,19 +49,15 @@ export interface RequestArgs {
49
49
  export declare class BaseAPI {
50
50
  protected basePath: string;
51
51
  protected axios: AxiosInstance;
52
- protected configuration: Configuration;
53
- private username?;
54
- private password?;
52
+ protected configuration: Configuration | undefined;
53
+ private tokenData?;
55
54
  constructor(configuration?: Configuration, basePath?: string, axios?: AxiosInstance);
56
- initialize(env?: Environment): Promise<void>;
57
- private loadCredentials;
58
- private readConfigFile;
59
- private readEnvVariables;
60
55
  selectEnvironment(env: Environment): void;
61
56
  authorize(username: string, password: string): Promise<void>;
62
57
  refreshTokenInternal(): Promise<string>;
63
- private extractRefreshToken;
64
- getConfiguration(): Configuration;
58
+ private storeTokenData;
59
+ loadTokenData(): void;
60
+ cleanTokenData(): void;
65
61
  private attachInterceptor;
66
62
  }
67
63
  /**
package/dist/base.js CHANGED
@@ -38,29 +38,6 @@ var __assign = (this && this.__assign) || function () {
38
38
  };
39
39
  return __assign.apply(this, arguments);
40
40
  };
41
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
42
- if (k2 === undefined) k2 = k;
43
- var desc = Object.getOwnPropertyDescriptor(m, k);
44
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
45
- desc = { enumerable: true, get: function() { return m[k]; } };
46
- }
47
- Object.defineProperty(o, k2, desc);
48
- }) : (function(o, m, k, k2) {
49
- if (k2 === undefined) k2 = k;
50
- o[k2] = m[k];
51
- }));
52
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
53
- Object.defineProperty(o, "default", { enumerable: true, value: v });
54
- }) : function(o, v) {
55
- o["default"] = v;
56
- });
57
- var __importStar = (this && this.__importStar) || function (mod) {
58
- if (mod && mod.__esModule) return mod;
59
- var result = {};
60
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
61
- __setModuleDefault(result, mod);
62
- return result;
63
- };
64
41
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
65
42
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
66
43
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -103,18 +80,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
103
80
  Object.defineProperty(exports, "__esModule", { value: true });
104
81
  exports.RequiredError = exports.BaseAPI = exports.resetRetry = exports.Environment = exports.COLLECTION_FORMATS = exports.BASE_PATH = void 0;
105
82
  var configuration_1 = require("./configuration");
83
+ var common_1 = require("./common");
106
84
  // Some imports not used depending on template conditions
107
85
  // @ts-ignore
108
86
  var axios_1 = __importDefault(require("axios"));
109
- var fs = __importStar(require("fs"));
110
- var path = __importStar(require("path"));
111
- var os = __importStar(require("os"));
112
87
  exports.BASE_PATH = "https://apiv2.emil.de".replace(/\/+$/, "");
113
- var CONFIG_DIRECTORY = '.emil';
114
- var CONFIG_FILENAME = 'credentials';
115
- var KEY_USERNAME = 'emil_username';
116
- var KEY_PASSWORD = 'emil_password';
117
- var filePath = os.homedir() + path.sep + CONFIG_DIRECTORY + path.sep + CONFIG_FILENAME;
118
88
  /**
119
89
  *
120
90
  * @export
@@ -138,6 +108,7 @@ function resetRetry() {
138
108
  }
139
109
  exports.resetRetry = resetRetry;
140
110
  var NETWORK_ERROR_MESSAGE = "Network Error";
111
+ var TOKEN_DATA = 'APP_TOKEN';
141
112
  /**
142
113
  *
143
114
  * @export
@@ -149,101 +120,27 @@ var BaseAPI = /** @class */ (function () {
149
120
  if (axios === void 0) { axios = axios_1.default; }
150
121
  this.basePath = basePath;
151
122
  this.axios = axios;
123
+ this.loadTokenData();
152
124
  if (configuration) {
153
125
  this.configuration = configuration;
154
126
  this.basePath = configuration.basePath || this.basePath;
155
127
  }
156
128
  else {
129
+ var _a = this.tokenData, accessToken = _a.accessToken, username = _a.username;
157
130
  this.configuration = new configuration_1.Configuration({
158
131
  basePath: this.basePath,
132
+ accessToken: accessToken ? "Bearer ".concat(accessToken) : '',
133
+ username: username,
159
134
  });
160
135
  }
161
136
  this.attachInterceptor(axios);
162
137
  }
163
- BaseAPI.prototype.initialize = function (env) {
164
- if (env === void 0) { env = Environment.Production; }
165
- return __awaiter(this, void 0, void 0, function () {
166
- return __generator(this, function (_a) {
167
- switch (_a.label) {
168
- case 0:
169
- this.configuration.basePath = env;
170
- return [4 /*yield*/, this.loadCredentials()];
171
- case 1:
172
- _a.sent();
173
- if (!this.username) return [3 /*break*/, 3];
174
- return [4 /*yield*/, this.authorize(this.username, this.password)];
175
- case 2:
176
- _a.sent();
177
- this.password = null; // to avoid keeping password loaded in memory.
178
- _a.label = 3;
179
- case 3: return [2 /*return*/];
180
- }
181
- });
182
- });
183
- };
184
- BaseAPI.prototype.loadCredentials = function () {
185
- return __awaiter(this, void 0, void 0, function () {
186
- var error_1;
187
- return __generator(this, function (_a) {
188
- switch (_a.label) {
189
- case 0:
190
- _a.trys.push([0, 2, , 3]);
191
- return [4 /*yield*/, this.readConfigFile()];
192
- case 1:
193
- _a.sent();
194
- return [3 /*break*/, 3];
195
- case 2:
196
- error_1 = _a.sent();
197
- console.warn("No credentials file found. Check that ".concat(filePath, " exists."));
198
- return [3 /*break*/, 3];
199
- case 3:
200
- this.readEnvVariables();
201
- if (!this.username) {
202
- console.info("No credentials found in credentials file or environment variables. Either provide some or use \n authorize() function.");
203
- }
204
- return [2 /*return*/];
205
- }
206
- });
207
- });
208
- };
209
- BaseAPI.prototype.readConfigFile = function () {
210
- return __awaiter(this, void 0, void 0, function () {
211
- var file, lines;
212
- var _this = this;
213
- return __generator(this, function (_a) {
214
- switch (_a.label) {
215
- case 0: return [4 /*yield*/, fs.promises.readFile(filePath, 'utf-8')];
216
- case 1:
217
- file = _a.sent();
218
- lines = file.split(os.EOL)
219
- .filter(Boolean);
220
- lines.forEach(function (line) {
221
- if (line.startsWith(KEY_USERNAME)) {
222
- _this.username = line.length > KEY_USERNAME.length + 1 ? line.substring(KEY_USERNAME.length + 1) : '';
223
- }
224
- else if (line.startsWith(KEY_PASSWORD)) {
225
- _this.password = line.length > KEY_PASSWORD.length + 1 ? line.substring(KEY_PASSWORD.length + 1) : '';
226
- }
227
- });
228
- return [2 /*return*/];
229
- }
230
- });
231
- });
232
- };
233
- BaseAPI.prototype.readEnvVariables = function () {
234
- if (process.env.EMIL_USERNAME) {
235
- this.username = process.env.EMIL_USERNAME;
236
- this.password = process.env.EMIL_PASSWORD || '';
237
- return true;
238
- }
239
- return false;
240
- };
241
138
  BaseAPI.prototype.selectEnvironment = function (env) {
242
139
  this.configuration.basePath = env;
243
140
  };
244
141
  BaseAPI.prototype.authorize = function (username, password) {
245
142
  return __awaiter(this, void 0, void 0, function () {
246
- var options, response, accessToken, refreshToken;
143
+ var options, response, accessToken;
247
144
  return __generator(this, function (_a) {
248
145
  switch (_a.label) {
249
146
  case 0:
@@ -263,8 +160,9 @@ var BaseAPI = /** @class */ (function () {
263
160
  accessToken = response.data.accessToken;
264
161
  this.configuration.username = username;
265
162
  this.configuration.accessToken = "Bearer ".concat(accessToken);
266
- refreshToken = this.extractRefreshToken(response);
267
- this.configuration.refreshToken = refreshToken;
163
+ this.tokenData.username = username;
164
+ this.tokenData.accessToken = accessToken;
165
+ this.storeTokenData(__assign({}, this.tokenData));
268
166
  return [2 /*return*/];
269
167
  }
270
168
  });
@@ -272,12 +170,12 @@ var BaseAPI = /** @class */ (function () {
272
170
  };
273
171
  BaseAPI.prototype.refreshTokenInternal = function () {
274
172
  return __awaiter(this, void 0, void 0, function () {
275
- var _a, username, refreshToken, options, accessToken;
276
- return __generator(this, function (_b) {
277
- switch (_b.label) {
173
+ var username, options, accessToken;
174
+ return __generator(this, function (_a) {
175
+ switch (_a.label) {
278
176
  case 0:
279
- _a = this.configuration, username = _a.username, refreshToken = _a.refreshToken;
280
- if (!username || !refreshToken) {
177
+ username = this.configuration.username;
178
+ if (!username) {
281
179
  return [2 /*return*/, ''];
282
180
  }
283
181
  options = {
@@ -285,28 +183,33 @@ var BaseAPI = /** @class */ (function () {
285
183
  url: "".concat(this.configuration.basePath, "/authservice/v1/refresh-token"),
286
184
  headers: {
287
185
  'Content-Type': 'application/json',
288
- Cookie: refreshToken,
289
186
  },
290
187
  data: { username: username },
291
188
  withCredentials: true,
292
189
  };
293
190
  return [4 /*yield*/, axios_1.default.request(options)];
294
191
  case 1:
295
- accessToken = (_b.sent()).data.accessToken;
192
+ accessToken = (_a.sent()).data.accessToken;
296
193
  return [2 /*return*/, accessToken];
297
194
  }
298
195
  });
299
196
  });
300
197
  };
301
- BaseAPI.prototype.extractRefreshToken = function (response) {
302
- if (response.headers && response.headers['set-cookie']
303
- && response.headers['set-cookie'].length > 0) {
304
- return "".concat(response.headers['set-cookie'][0].split(';')[0], ";");
198
+ BaseAPI.prototype.storeTokenData = function (tokenData) {
199
+ if (typeof window !== 'undefined') {
200
+ (0, common_1.defaultStorage)().set(TOKEN_DATA, tokenData);
305
201
  }
306
- return '';
307
202
  };
308
- BaseAPI.prototype.getConfiguration = function () {
309
- return this.configuration;
203
+ BaseAPI.prototype.loadTokenData = function () {
204
+ if (typeof window !== 'undefined') {
205
+ this.tokenData = (0, common_1.defaultStorage)().get(TOKEN_DATA) || {};
206
+ }
207
+ else {
208
+ this.tokenData = {};
209
+ }
210
+ };
211
+ BaseAPI.prototype.cleanTokenData = function () {
212
+ this.storeTokenData(null);
310
213
  };
311
214
  BaseAPI.prototype.attachInterceptor = function (axios) {
312
215
  var _this = this;
@@ -318,8 +221,9 @@ var BaseAPI = /** @class */ (function () {
318
221
  switch (_a.label) {
319
222
  case 0:
320
223
  originalConfig = err.config;
321
- if (!err.response) return [3 /*break*/, 5];
322
- if (!(err.response.status === 401 && !originalConfig._retry)) return [3 /*break*/, 4];
224
+ if (!(err.response && !(err.response instanceof XMLHttpRequest))) return [3 /*break*/, 5];
225
+ if (!((err.response.status === 401 || err.response.status === 403)
226
+ && !originalConfig._retry)) return [3 /*break*/, 4];
323
227
  originalConfig._retry = true;
324
228
  _a.label = 1;
325
229
  case 1:
@@ -328,23 +232,21 @@ var BaseAPI = /** @class */ (function () {
328
232
  case 2:
329
233
  tokenString = _a.sent();
330
234
  accessToken = "Bearer ".concat(tokenString);
331
- originalConfig.headers['Authorization'] = "Bearer ".concat(accessToken);
235
+ delete originalConfig.headers['Authorization'];
236
+ originalConfig.headers['Authorization'] = accessToken;
332
237
  this.configuration.accessToken = accessToken;
333
- return [2 /*return*/, axios.request(originalConfig)];
238
+ this.tokenData.accessToken = tokenString;
239
+ this.storeTokenData(this.tokenData);
240
+ return [2 /*return*/, axios(originalConfig)];
334
241
  case 3:
335
242
  _error_1 = _a.sent();
336
243
  if (_error_1.response && _error_1.response.data) {
337
244
  return [2 /*return*/, Promise.reject(_error_1.response.data)];
338
245
  }
339
246
  return [2 /*return*/, Promise.reject(_error_1)];
340
- case 4:
341
- if (err.response.status === 403 && err.response.data) {
342
- return [2 /*return*/, Promise.reject(err.response.data)];
343
- }
344
- return [3 /*break*/, 9];
247
+ case 4: return [3 /*break*/, 9];
345
248
  case 5:
346
249
  if (!(err.message === NETWORK_ERROR_MESSAGE
347
- && err.isAxiosError
348
250
  && originalConfig.headers.hasOwnProperty('Authorization')
349
251
  && _retry_count < 4)) return [3 /*break*/, 9];
350
252
  _retry_count++;
@@ -358,6 +260,8 @@ var BaseAPI = /** @class */ (function () {
358
260
  _retry = true;
359
261
  originalConfig.headers['Authorization'] = accessToken;
360
262
  this.configuration.accessToken = accessToken;
263
+ this.tokenData.accessToken = tokenString;
264
+ this.storeTokenData(this.tokenData);
361
265
  return [2 /*return*/, axios.request(__assign({}, originalConfig))];
362
266
  case 8:
363
267
  _error_2 = _a.sent();
package/dist/common.d.ts CHANGED
@@ -12,7 +12,6 @@
12
12
  import { Configuration } from "./configuration";
13
13
  import { RequestArgs } from "./base";
14
14
  import { AxiosInstance, AxiosResponse } from 'axios';
15
- import { URL } from 'url';
16
15
  /**
17
16
  *
18
17
  * @export
package/dist/common.js CHANGED
@@ -62,7 +62,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
62
62
  Object.defineProperty(exports, "__esModule", { value: true });
63
63
  exports.defaultStorage = exports.LocalStorage = exports.createRequestFunction = exports.toPathString = exports.serializeDataIfNeeded = exports.setSearchParams = exports.setOAuthToObject = exports.setBearerAuthToObject = exports.setBasicAuthToObject = exports.setApiKeyToObject = exports.assertParamExists = exports.DUMMY_BASE_URL = void 0;
64
64
  var base_1 = require("./base");
65
- var url_1 = require("url");
66
65
  /**
67
66
  *
68
67
  * @export
@@ -188,7 +187,7 @@ var setSearchParams = function (url) {
188
187
  for (var _i = 1; _i < arguments.length; _i++) {
189
188
  objects[_i - 1] = arguments[_i];
190
189
  }
191
- var searchParams = new url_1.URLSearchParams(url.search);
190
+ var searchParams = new URLSearchParams(url.search);
192
191
  for (var _a = 0, objects_1 = objects; _a < objects_1.length; _a++) {
193
192
  var object = objects_1[_a];
194
193
  for (var key in object) {
@@ -68,13 +68,6 @@ export declare class Configuration {
68
68
  * @type {new () => FormData}
69
69
  */
70
70
  formDataCtor?: new () => any;
71
- /**
72
- * parameter for automatically refreshing access token for oauth2 security
73
- *
74
- * @type {string}
75
- * @memberof Configuration
76
- */
77
- refreshToken?: string;
78
71
  constructor(param?: ConfigurationParameters);
79
72
  /**
80
73
  * Check if the given MIME is a JSON MIME.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emilgroup/tenant-sdk",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "OpenAPI client for @emilgroup/tenant-sdk",
5
5
  "author": "OpenAPI-Generator Contributors",
6
6
  "keywords": [
@@ -18,12 +18,10 @@
18
18
  "prepare": "npm run build"
19
19
  },
20
20
  "dependencies": {
21
- "axios": "^0.27.2",
22
- "form-data": "^4.0.0",
23
- "url": "^0.11.0"
21
+ "axios": "^0.27.2"
24
22
  },
25
23
  "devDependencies": {
26
- "@types/node": "^12.11.5",
24
+
27
25
  "typescript": "^4.0"
28
26
  }
29
27
  }