@emilgroup/insurance-sdk 1.4.0-beta.0 → 1.4.0-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/base.ts CHANGED
@@ -59,8 +59,8 @@ export interface RequestArgs {
59
59
  }
60
60
 
61
61
  interface TokenData {
62
- accessToken: string;
63
- username: string;
62
+ accessToken?: string;
63
+ username?: string;
64
64
  }
65
65
 
66
66
  const NETWORK_ERROR_MESSAGE = "Network Error";
@@ -73,26 +73,25 @@ const NETWORK_ERROR_MESSAGE = "Network Error";
73
73
  export class BaseAPI {
74
74
  protected configuration: Configuration;
75
75
  private lastRequestConfig?: AxiosRequestConfig;
76
- private tokenData: TokenData;
76
+ private tokenData?: TokenData;
77
77
 
78
78
  constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) {
79
+ this.tokenData = defaultStorage.get<TokenData>('TOKEN') || {};
80
+
79
81
  if (configuration) {
80
82
  this.configuration = configuration;
81
83
  this.basePath = configuration.basePath || this.basePath;
82
84
  } else {
83
- this.tokenData = defaultStorage.get<TokenData>('TOKEN');
84
- const { accessToken, username } = this.tokenData;
85
-
86
85
  this.configuration = new Configuration({
87
86
  basePath: this.basePath,
88
- accessToken: accessToken ? `Bearer ${accessToken}` : '',
89
- username,
87
+ accessToken: this.tokenData?.accessToken ? `Bearer ${this.tokenData.accessToken}` : null,
88
+ username: this.tokenData?.username ? this.tokenData.username : null,
90
89
  });
91
90
  }
92
91
 
93
92
  this.attachInterceptor(axios);
94
93
  }
95
-
94
+
96
95
  selectEnvironment(env: Environment) {
97
96
  this.configuration.basePath = env;
98
97
  }
@@ -142,12 +141,11 @@ export class BaseAPI {
142
141
 
143
142
  const { data: { accessToken } } = await globalAxios.request<LoginClass>(options);
144
143
 
145
- this.tokenData.accessToken = accessToken;
146
-
147
- defaultStorage.set<TokenData>('TOKEN', {
148
- ...this.tokenData,
144
+ this.tokenData = {
149
145
  accessToken,
150
- });
146
+ username
147
+ };
148
+ defaultStorage.set<TokenData>('TOKEN', this.tokenData);
151
149
 
152
150
  return accessToken;
153
151
  }
@@ -190,18 +188,18 @@ export class BaseAPI {
190
188
  return Promise.reject(_error);
191
189
  }
192
190
  }
193
- } else if(err.message === NETWORK_ERROR_MESSAGE
191
+ } else if (err.message === NETWORK_ERROR_MESSAGE
194
192
  && err.isAxiosError
195
193
  && originalConfig.headers.hasOwnProperty('Authorization')
196
194
  && _retry_count < 4
197
- ){
195
+ ) {
198
196
  _retry_count++;
199
197
  try {
200
198
  const tokenString = await this.refreshToken();
201
199
  const accessToken = `Bearer ${tokenString}`;
202
200
 
203
201
  _retry = true;
204
- originalConfig.headers['Authorization'] = accessToken;
202
+ originalConfig.headers['Authorization'] = accessToken;
205
203
 
206
204
  this.configuration.accessToken = accessToken;
207
205
 
@@ -213,7 +211,7 @@ export class BaseAPI {
213
211
  return Promise.reject(_error.response.data);
214
212
  }
215
213
  return Promise.reject(_error);
216
- }
214
+ }
217
215
  }
218
216
  return Promise.reject(err);
219
217
  }
package/dist/base.d.ts CHANGED
@@ -50,7 +50,7 @@ export declare class BaseAPI {
50
50
  protected axios: AxiosInstance;
51
51
  protected configuration: Configuration;
52
52
  private lastRequestConfig?;
53
- private tokenData;
53
+ private tokenData?;
54
54
  constructor(configuration?: Configuration, basePath?: string, axios?: AxiosInstance);
55
55
  selectEnvironment(env: Environment): void;
56
56
  authorize(username: string, password: string): Promise<void>;
package/dist/base.js CHANGED
@@ -116,19 +116,19 @@ var BaseAPI = /** @class */ (function () {
116
116
  function BaseAPI(configuration, basePath, axios) {
117
117
  if (basePath === void 0) { basePath = exports.BASE_PATH; }
118
118
  if (axios === void 0) { axios = axios_1.default; }
119
+ var _a, _b;
119
120
  this.basePath = basePath;
120
121
  this.axios = axios;
122
+ this.tokenData = storage_1.defaultStorage.get('TOKEN') || {};
121
123
  if (configuration) {
122
124
  this.configuration = configuration;
123
125
  this.basePath = configuration.basePath || this.basePath;
124
126
  }
125
127
  else {
126
- this.tokenData = storage_1.defaultStorage.get('TOKEN');
127
- var _a = this.tokenData, accessToken = _a.accessToken, username = _a.username;
128
128
  this.configuration = new configuration_1.Configuration({
129
129
  basePath: this.basePath,
130
- accessToken: accessToken ? "Bearer ".concat(accessToken) : '',
131
- username: username,
130
+ accessToken: ((_a = this.tokenData) === null || _a === void 0 ? void 0 : _a.accessToken) ? "Bearer ".concat(this.tokenData.accessToken) : null,
131
+ username: ((_b = this.tokenData) === null || _b === void 0 ? void 0 : _b.username) ? this.tokenData.username : null,
132
132
  });
133
133
  }
134
134
  this.attachInterceptor(axios);
@@ -190,8 +190,11 @@ var BaseAPI = /** @class */ (function () {
190
190
  return [4 /*yield*/, axios_1.default.request(options)];
191
191
  case 1:
192
192
  accessToken = (_a.sent()).data.accessToken;
193
- this.tokenData.accessToken = accessToken;
194
- storage_1.defaultStorage.set('TOKEN', __assign(__assign({}, this.tokenData), { accessToken: accessToken }));
193
+ this.tokenData = {
194
+ accessToken: accessToken,
195
+ username: username
196
+ };
197
+ storage_1.defaultStorage.set('TOKEN', this.tokenData);
195
198
  return [2 /*return*/, accessToken];
196
199
  }
197
200
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emilgroup/insurance-sdk",
3
- "version": "1.4.0-beta.0",
3
+ "version": "1.4.0-beta.1",
4
4
  "description": "OpenAPI client for @emilgroup/insurance-sdk",
5
5
  "author": "OpenAPI-Generator Contributors",
6
6
  "keywords": [