@emilgroup/auth-sdk-node 1.11.0 → 1.11.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/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/auth-sdk-node@1.11.0 --save
20
+ npm install @emilgroup/auth-sdk-node@1.11.1-beta.1 --save
21
21
  ```
22
22
  or
23
23
  ```
24
- yarn add @emilgroup/auth-sdk-node@1.11.0
24
+ yarn add @emilgroup/auth-sdk-node@1.11.1-beta.1
25
25
  ```
26
26
 
27
27
  And then you can import ``.
@@ -168,6 +168,37 @@ export const AuthserviceApiAxiosParamCreator = function (configuration?: Configu
168
168
  options: localVarRequestOptions,
169
169
  };
170
170
  },
171
+ /**
172
+ *
173
+ * @param {*} [options] Override http request option.
174
+ * @throws {RequiredError}
175
+ */
176
+ generateReadmeToken: async (options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
177
+ const localVarPath = `/authservice/v1/readme-token`;
178
+ // use dummy base URL string because the URL constructor only accepts absolute URLs.
179
+ const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
180
+ let baseOptions;
181
+ let baseAccessToken;
182
+ if (configuration) {
183
+ baseOptions = configuration.baseOptions;
184
+ baseAccessToken = configuration.accessToken;
185
+ }
186
+
187
+ const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
188
+ const localVarHeaderParameter = {} as any;
189
+ const localVarQueryParameter = {} as any;
190
+
191
+
192
+
193
+ setSearchParams(localVarUrlObj, localVarQueryParameter);
194
+ let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
195
+ localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
196
+
197
+ return {
198
+ url: toPathString(localVarUrlObj),
199
+ options: localVarRequestOptions,
200
+ };
201
+ },
171
202
  /**
172
203
  * Get SAML login link configured for the tenant in cognito as well as tenant settings
173
204
  * @summary Get SAML login link for tenant
@@ -562,6 +593,15 @@ export const AuthserviceApiFp = function(configuration?: Configuration) {
562
593
  const localVarAxiosArgs = await localVarAxiosParamCreator.forgotPassword(forgotPasswordRequestDto, options);
563
594
  return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
564
595
  },
596
+ /**
597
+ *
598
+ * @param {*} [options] Override http request option.
599
+ * @throws {RequiredError}
600
+ */
601
+ async generateReadmeToken(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
602
+ const localVarAxiosArgs = await localVarAxiosParamCreator.generateReadmeToken(options);
603
+ return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
604
+ },
565
605
  /**
566
606
  * Get SAML login link configured for the tenant in cognito as well as tenant settings
567
607
  * @summary Get SAML login link for tenant
@@ -702,6 +742,14 @@ export const AuthserviceApiFactory = function (configuration?: Configuration, ba
702
742
  forgotPassword(forgotPasswordRequestDto: ForgotPasswordRequestDto, options?: any): AxiosPromise<void> {
703
743
  return localVarFp.forgotPassword(forgotPasswordRequestDto, options).then((request) => request(axios, basePath));
704
744
  },
745
+ /**
746
+ *
747
+ * @param {*} [options] Override http request option.
748
+ * @throws {RequiredError}
749
+ */
750
+ generateReadmeToken(options?: any): AxiosPromise<void> {
751
+ return localVarFp.generateReadmeToken(options).then((request) => request(axios, basePath));
752
+ },
705
753
  /**
706
754
  * Get SAML login link configured for the tenant in cognito as well as tenant settings
707
755
  * @summary Get SAML login link for tenant
@@ -1014,6 +1062,16 @@ export class AuthserviceApi extends BaseAPI {
1014
1062
  return AuthserviceApiFp(this.configuration).forgotPassword(requestParameters.forgotPasswordRequestDto, options).then((request) => request(this.axios, this.basePath));
1015
1063
  }
1016
1064
 
1065
+ /**
1066
+ *
1067
+ * @param {*} [options] Override http request option.
1068
+ * @throws {RequiredError}
1069
+ * @memberof AuthserviceApi
1070
+ */
1071
+ public generateReadmeToken(options?: AxiosRequestConfig) {
1072
+ return AuthserviceApiFp(this.configuration).generateReadmeToken(options).then((request) => request(this.axios, this.basePath));
1073
+ }
1074
+
1017
1075
  /**
1018
1076
  * Get SAML login link configured for the tenant in cognito as well as tenant settings
1019
1077
  * @summary Get SAML login link for tenant
package/base.ts CHANGED
@@ -79,6 +79,7 @@ export class BaseAPI {
79
79
  protected configuration: Configuration;
80
80
  private username?: string;
81
81
  private password?: string;
82
+ private permissions: Array<string> = [];
82
83
 
83
84
  constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) {
84
85
  if (configuration) {
@@ -149,6 +150,10 @@ export class BaseAPI {
149
150
  this.configuration.basePath = env;
150
151
  }
151
152
 
153
+ getPermissions(): Array<string> {
154
+ return this.permissions;
155
+ }
156
+
152
157
  async authorize(username: string, password: string): Promise<void> {
153
158
  const options: AxiosRequestConfig = {
154
159
  method: 'POST',
@@ -163,20 +168,21 @@ export class BaseAPI {
163
168
 
164
169
  const response = await globalAxios.request<LoginClass>(options);
165
170
 
166
- const { data: { accessToken } } = response;
171
+ const { data: { accessToken, permissions } } = response;
167
172
  this.configuration.username = username;
168
173
  this.configuration.accessToken = `Bearer ${accessToken}`;
174
+ this.permissions = permissions;
169
175
 
170
176
  const refreshToken = this.extractRefreshToken(response)
171
177
  this.configuration.refreshToken = refreshToken;
172
178
  }
173
179
 
174
- async refreshTokenInternal(): Promise<string> {
180
+ async refreshTokenInternal(): Promise<LoginClass> {
175
181
  const { username, refreshToken } = this.configuration;
176
182
 
177
183
 
178
184
  if (!username || !refreshToken) {
179
- return '';
185
+ throw new Error('Failed to refresh token.');
180
186
  }
181
187
 
182
188
  const options: AxiosRequestConfig = {
@@ -190,9 +196,9 @@ export class BaseAPI {
190
196
  withCredentials: true,
191
197
  };
192
198
 
193
- const { data: { accessToken } } = await globalAxios.request<LoginClass>(options);
199
+ const response = await globalAxios.request<LoginClass>(options);
194
200
 
195
- return accessToken;
201
+ return response.data;
196
202
  }
197
203
 
198
204
  private extractRefreshToken(response: AxiosResponse): string {
@@ -221,8 +227,9 @@ export class BaseAPI {
221
227
  if (err.response.status === 401 && !originalConfig._retry) {
222
228
  originalConfig._retry = true;
223
229
  try {
224
- const tokenString = await this.refreshTokenInternal();
230
+ const { accessToken: tokenString, permissions } = await this.refreshTokenInternal();
225
231
  const accessToken = `Bearer ${tokenString}`;
232
+ this.permissions = permissions;
226
233
 
227
234
  originalConfig.headers['Authorization'] = `Bearer ${accessToken}`
228
235
 
@@ -246,8 +253,9 @@ export class BaseAPI {
246
253
  ){
247
254
  _retry_count++;
248
255
  try {
249
- const tokenString = await this.refreshTokenInternal();
256
+ const { accessToken: tokenString, permissions } = await this.refreshTokenInternal();
250
257
  const accessToken = `Bearer ${tokenString}`;
258
+ this.permissions = permissions;
251
259
 
252
260
  _retry = true;
253
261
  originalConfig.headers['Authorization'] = accessToken;
@@ -53,6 +53,12 @@ export declare const AuthserviceApiAxiosParamCreator: (configuration?: Configura
53
53
  * @throws {RequiredError}
54
54
  */
55
55
  forgotPassword: (forgotPasswordRequestDto: ForgotPasswordRequestDto, options?: AxiosRequestConfig) => Promise<RequestArgs>;
56
+ /**
57
+ *
58
+ * @param {*} [options] Override http request option.
59
+ * @throws {RequiredError}
60
+ */
61
+ generateReadmeToken: (options?: AxiosRequestConfig) => Promise<RequestArgs>;
56
62
  /**
57
63
  * Get SAML login link configured for the tenant in cognito as well as tenant settings
58
64
  * @summary Get SAML login link for tenant
@@ -156,6 +162,12 @@ export declare const AuthserviceApiFp: (configuration?: Configuration) => {
156
162
  * @throws {RequiredError}
157
163
  */
158
164
  forgotPassword(forgotPasswordRequestDto: ForgotPasswordRequestDto, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>>;
165
+ /**
166
+ *
167
+ * @param {*} [options] Override http request option.
168
+ * @throws {RequiredError}
169
+ */
170
+ generateReadmeToken(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>>;
159
171
  /**
160
172
  * Get SAML login link configured for the tenant in cognito as well as tenant settings
161
173
  * @summary Get SAML login link for tenant
@@ -259,6 +271,12 @@ export declare const AuthserviceApiFactory: (configuration?: Configuration, base
259
271
  * @throws {RequiredError}
260
272
  */
261
273
  forgotPassword(forgotPasswordRequestDto: ForgotPasswordRequestDto, options?: any): AxiosPromise<void>;
274
+ /**
275
+ *
276
+ * @param {*} [options] Override http request option.
277
+ * @throws {RequiredError}
278
+ */
279
+ generateReadmeToken(options?: any): AxiosPromise<void>;
262
280
  /**
263
281
  * Get SAML login link configured for the tenant in cognito as well as tenant settings
264
282
  * @summary Get SAML login link for tenant
@@ -529,6 +547,13 @@ export declare class AuthserviceApi extends BaseAPI {
529
547
  * @memberof AuthserviceApi
530
548
  */
531
549
  forgotPassword(requestParameters: AuthserviceApiForgotPasswordRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any>>;
550
+ /**
551
+ *
552
+ * @param {*} [options] Override http request option.
553
+ * @throws {RequiredError}
554
+ * @memberof AuthserviceApi
555
+ */
556
+ generateReadmeToken(options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any>>;
532
557
  /**
533
558
  * Get SAML login link configured for the tenant in cognito as well as tenant settings
534
559
  * @summary Get SAML login link for tenant
@@ -201,6 +201,35 @@ var AuthserviceApiAxiosParamCreator = function (configuration) {
201
201
  });
202
202
  });
203
203
  },
204
+ /**
205
+ *
206
+ * @param {*} [options] Override http request option.
207
+ * @throws {RequiredError}
208
+ */
209
+ generateReadmeToken: function (options) {
210
+ if (options === void 0) { options = {}; }
211
+ return __awaiter(_this, void 0, void 0, function () {
212
+ var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, headersFromBaseOptions;
213
+ return __generator(this, function (_a) {
214
+ localVarPath = "/authservice/v1/readme-token";
215
+ localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
216
+ if (configuration) {
217
+ baseOptions = configuration.baseOptions;
218
+ baseAccessToken = configuration.accessToken;
219
+ }
220
+ localVarRequestOptions = __assign(__assign({ method: 'POST' }, baseOptions), options);
221
+ localVarHeaderParameter = {};
222
+ localVarQueryParameter = {};
223
+ (0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter);
224
+ headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
225
+ localVarRequestOptions.headers = __assign(__assign(__assign({}, localVarHeaderParameter), headersFromBaseOptions), options.headers);
226
+ return [2 /*return*/, {
227
+ url: (0, common_1.toPathString)(localVarUrlObj),
228
+ options: localVarRequestOptions,
229
+ }];
230
+ });
231
+ });
232
+ },
204
233
  /**
205
234
  * Get SAML login link configured for the tenant in cognito as well as tenant settings
206
235
  * @summary Get SAML login link for tenant
@@ -594,6 +623,24 @@ var AuthserviceApiFp = function (configuration) {
594
623
  });
595
624
  });
596
625
  },
626
+ /**
627
+ *
628
+ * @param {*} [options] Override http request option.
629
+ * @throws {RequiredError}
630
+ */
631
+ generateReadmeToken: function (options) {
632
+ return __awaiter(this, void 0, void 0, function () {
633
+ var localVarAxiosArgs;
634
+ return __generator(this, function (_a) {
635
+ switch (_a.label) {
636
+ case 0: return [4 /*yield*/, localVarAxiosParamCreator.generateReadmeToken(options)];
637
+ case 1:
638
+ localVarAxiosArgs = _a.sent();
639
+ return [2 /*return*/, (0, common_1.createRequestFunction)(localVarAxiosArgs, axios_1.default, base_1.BASE_PATH, configuration)];
640
+ }
641
+ });
642
+ });
643
+ },
597
644
  /**
598
645
  * Get SAML login link configured for the tenant in cognito as well as tenant settings
599
646
  * @summary Get SAML login link for tenant
@@ -815,6 +862,14 @@ var AuthserviceApiFactory = function (configuration, basePath, axios) {
815
862
  forgotPassword: function (forgotPasswordRequestDto, options) {
816
863
  return localVarFp.forgotPassword(forgotPasswordRequestDto, options).then(function (request) { return request(axios, basePath); });
817
864
  },
865
+ /**
866
+ *
867
+ * @param {*} [options] Override http request option.
868
+ * @throws {RequiredError}
869
+ */
870
+ generateReadmeToken: function (options) {
871
+ return localVarFp.generateReadmeToken(options).then(function (request) { return request(axios, basePath); });
872
+ },
818
873
  /**
819
874
  * Get SAML login link configured for the tenant in cognito as well as tenant settings
820
875
  * @summary Get SAML login link for tenant
@@ -956,6 +1011,16 @@ var AuthserviceApi = /** @class */ (function (_super) {
956
1011
  var _this = this;
957
1012
  return (0, exports.AuthserviceApiFp)(this.configuration).forgotPassword(requestParameters.forgotPasswordRequestDto, options).then(function (request) { return request(_this.axios, _this.basePath); });
958
1013
  };
1014
+ /**
1015
+ *
1016
+ * @param {*} [options] Override http request option.
1017
+ * @throws {RequiredError}
1018
+ * @memberof AuthserviceApi
1019
+ */
1020
+ AuthserviceApi.prototype.generateReadmeToken = function (options) {
1021
+ var _this = this;
1022
+ return (0, exports.AuthserviceApiFp)(this.configuration).generateReadmeToken(options).then(function (request) { return request(_this.axios, _this.basePath); });
1023
+ };
959
1024
  /**
960
1025
  * Get SAML login link configured for the tenant in cognito as well as tenant settings
961
1026
  * @summary Get SAML login link for tenant
package/dist/base.d.ts CHANGED
@@ -53,14 +53,16 @@ export declare class BaseAPI {
53
53
  protected configuration: Configuration;
54
54
  private username?;
55
55
  private password?;
56
+ private permissions;
56
57
  constructor(configuration?: Configuration, basePath?: string, axios?: AxiosInstance);
57
58
  initialize(env?: Environment): Promise<void>;
58
59
  private loadCredentials;
59
60
  private readConfigFile;
60
61
  private readEnvVariables;
61
62
  selectEnvironment(env: Environment): void;
63
+ getPermissions(): Array<string>;
62
64
  authorize(username: string, password: string): Promise<void>;
63
- refreshTokenInternal(): Promise<string>;
65
+ refreshTokenInternal(): Promise<LoginClass>;
64
66
  private extractRefreshToken;
65
67
  getConfiguration(): Configuration;
66
68
  private attachInterceptor;
package/dist/base.js CHANGED
@@ -150,6 +150,7 @@ var BaseAPI = /** @class */ (function () {
150
150
  if (axios === void 0) { axios = axios_1.default; }
151
151
  this.basePath = basePath;
152
152
  this.axios = axios;
153
+ this.permissions = [];
153
154
  if (configuration) {
154
155
  this.configuration = configuration;
155
156
  this.basePath = configuration.basePath || this.basePath;
@@ -242,11 +243,14 @@ var BaseAPI = /** @class */ (function () {
242
243
  BaseAPI.prototype.selectEnvironment = function (env) {
243
244
  this.configuration.basePath = env;
244
245
  };
246
+ BaseAPI.prototype.getPermissions = function () {
247
+ return this.permissions;
248
+ };
245
249
  BaseAPI.prototype.authorize = function (username, password) {
246
250
  return __awaiter(this, void 0, void 0, function () {
247
- var options, response, accessToken, refreshToken;
248
- return __generator(this, function (_a) {
249
- switch (_a.label) {
251
+ var options, response, _a, accessToken, permissions, refreshToken;
252
+ return __generator(this, function (_b) {
253
+ switch (_b.label) {
250
254
  case 0:
251
255
  options = {
252
256
  method: 'POST',
@@ -260,10 +264,11 @@ var BaseAPI = /** @class */ (function () {
260
264
  };
261
265
  return [4 /*yield*/, axios_1.default.request(options)];
262
266
  case 1:
263
- response = _a.sent();
264
- accessToken = response.data.accessToken;
267
+ response = _b.sent();
268
+ _a = response.data, accessToken = _a.accessToken, permissions = _a.permissions;
265
269
  this.configuration.username = username;
266
270
  this.configuration.accessToken = "Bearer ".concat(accessToken);
271
+ this.permissions = permissions;
267
272
  refreshToken = this.extractRefreshToken(response);
268
273
  this.configuration.refreshToken = refreshToken;
269
274
  return [2 /*return*/];
@@ -273,13 +278,13 @@ var BaseAPI = /** @class */ (function () {
273
278
  };
274
279
  BaseAPI.prototype.refreshTokenInternal = function () {
275
280
  return __awaiter(this, void 0, void 0, function () {
276
- var _a, username, refreshToken, options, accessToken;
281
+ var _a, username, refreshToken, options, response;
277
282
  return __generator(this, function (_b) {
278
283
  switch (_b.label) {
279
284
  case 0:
280
285
  _a = this.configuration, username = _a.username, refreshToken = _a.refreshToken;
281
286
  if (!username || !refreshToken) {
282
- return [2 /*return*/, ''];
287
+ throw new Error('Failed to refresh token.');
283
288
  }
284
289
  options = {
285
290
  method: 'POST',
@@ -293,8 +298,8 @@ var BaseAPI = /** @class */ (function () {
293
298
  };
294
299
  return [4 /*yield*/, axios_1.default.request(options)];
295
300
  case 1:
296
- accessToken = (_b.sent()).data.accessToken;
297
- return [2 /*return*/, accessToken];
301
+ response = _b.sent();
302
+ return [2 /*return*/, response.data];
298
303
  }
299
304
  });
300
305
  });
@@ -314,26 +319,27 @@ var BaseAPI = /** @class */ (function () {
314
319
  axios.interceptors.response.use(function (res) {
315
320
  return res;
316
321
  }, function (err) { return __awaiter(_this, void 0, void 0, function () {
317
- var originalConfig, tokenString, accessToken, _error_1, tokenString, accessToken, _error_2;
318
- return __generator(this, function (_a) {
319
- switch (_a.label) {
322
+ var originalConfig, _a, tokenString, permissions, accessToken, _error_1, _b, tokenString, permissions, accessToken, _error_2;
323
+ return __generator(this, function (_c) {
324
+ switch (_c.label) {
320
325
  case 0:
321
326
  originalConfig = err.config;
322
327
  if (!err.response) return [3 /*break*/, 5];
323
328
  if (!(err.response.status === 401 && !originalConfig._retry)) return [3 /*break*/, 4];
324
329
  originalConfig._retry = true;
325
- _a.label = 1;
330
+ _c.label = 1;
326
331
  case 1:
327
- _a.trys.push([1, 3, , 4]);
332
+ _c.trys.push([1, 3, , 4]);
328
333
  return [4 /*yield*/, this.refreshTokenInternal()];
329
334
  case 2:
330
- tokenString = _a.sent();
335
+ _a = _c.sent(), tokenString = _a.accessToken, permissions = _a.permissions;
331
336
  accessToken = "Bearer ".concat(tokenString);
337
+ this.permissions = permissions;
332
338
  originalConfig.headers['Authorization'] = "Bearer ".concat(accessToken);
333
339
  this.configuration.accessToken = accessToken;
334
340
  return [2 /*return*/, axios.request(originalConfig)];
335
341
  case 3:
336
- _error_1 = _a.sent();
342
+ _error_1 = _c.sent();
337
343
  if (_error_1.response && _error_1.response.data) {
338
344
  return [2 /*return*/, Promise.reject(_error_1.response.data)];
339
345
  }
@@ -349,19 +355,20 @@ var BaseAPI = /** @class */ (function () {
349
355
  && originalConfig.headers.hasOwnProperty('Authorization')
350
356
  && _retry_count < 4)) return [3 /*break*/, 9];
351
357
  _retry_count++;
352
- _a.label = 6;
358
+ _c.label = 6;
353
359
  case 6:
354
- _a.trys.push([6, 8, , 9]);
360
+ _c.trys.push([6, 8, , 9]);
355
361
  return [4 /*yield*/, this.refreshTokenInternal()];
356
362
  case 7:
357
- tokenString = _a.sent();
363
+ _b = _c.sent(), tokenString = _b.accessToken, permissions = _b.permissions;
358
364
  accessToken = "Bearer ".concat(tokenString);
365
+ this.permissions = permissions;
359
366
  _retry = true;
360
367
  originalConfig.headers['Authorization'] = accessToken;
361
368
  this.configuration.accessToken = accessToken;
362
369
  return [2 /*return*/, axios.request(__assign({}, originalConfig))];
363
370
  case 8:
364
- _error_2 = _a.sent();
371
+ _error_2 = _c.sent();
365
372
  if (_error_2.response && _error_2.response.data) {
366
373
  return [2 /*return*/, Promise.reject(_error_2.response.data)];
367
374
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emilgroup/auth-sdk-node",
3
- "version": "1.11.0",
3
+ "version": "1.11.1-beta.1",
4
4
  "description": "OpenAPI client for @emilgroup/auth-sdk-node",
5
5
  "author": "OpenAPI-Generator Contributors",
6
6
  "keywords": [