@emilgroup/document-sdk-node 1.26.0 → 1.27.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/api/documents-api.ts +22 -6
- package/base.ts +15 -7
- package/dist/api/documents-api.d.ts +12 -3
- package/dist/api/documents-api.js +14 -6
- package/dist/base.d.ts +3 -1
- package/dist/base.js +27 -20
- 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/document-sdk-node@1.
|
|
20
|
+
npm install @emilgroup/document-sdk-node@1.27.1-beta.0 --save
|
|
21
21
|
```
|
|
22
22
|
or
|
|
23
23
|
```
|
|
24
|
-
yarn add @emilgroup/document-sdk-node@1.
|
|
24
|
+
yarn add @emilgroup/document-sdk-node@1.27.1-beta.0
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
And then you can import `DocumentsApi`.
|
package/api/documents-api.ts
CHANGED
|
@@ -229,13 +229,16 @@ export const DocumentsApiAxiosParamCreator = function (configuration?: Configura
|
|
|
229
229
|
* This will return a presigned URL for a random S3 key
|
|
230
230
|
* @summary Fetches a presigned URL for a S3 key
|
|
231
231
|
* @param {string} s3Key Key for the file in S3 bucket to create the presigned download URL for
|
|
232
|
+
* @param {'attachment' | 'inline'} contentDisposition Content disposition override. Default will be depending on the document type.
|
|
232
233
|
* @param {string} [authorization] Bearer Token
|
|
233
234
|
* @param {*} [options] Override http request option.
|
|
234
235
|
* @throws {RequiredError}
|
|
235
236
|
*/
|
|
236
|
-
getSignedS3keyUrl: async (s3Key: string, authorization?: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
|
237
|
+
getSignedS3keyUrl: async (s3Key: string, contentDisposition: 'attachment' | 'inline', authorization?: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
|
237
238
|
// verify required parameter 's3Key' is not null or undefined
|
|
238
239
|
assertParamExists('getSignedS3keyUrl', 's3Key', s3Key)
|
|
240
|
+
// verify required parameter 'contentDisposition' is not null or undefined
|
|
241
|
+
assertParamExists('getSignedS3keyUrl', 'contentDisposition', contentDisposition)
|
|
239
242
|
const localVarPath = `/documentservice/v1/documents/signed-s3-url`;
|
|
240
243
|
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
241
244
|
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
@@ -258,6 +261,10 @@ export const DocumentsApiAxiosParamCreator = function (configuration?: Configura
|
|
|
258
261
|
localVarQueryParameter['s3Key'] = s3Key;
|
|
259
262
|
}
|
|
260
263
|
|
|
264
|
+
if (contentDisposition !== undefined) {
|
|
265
|
+
localVarQueryParameter['contentDisposition'] = contentDisposition;
|
|
266
|
+
}
|
|
267
|
+
|
|
261
268
|
if (authorization !== undefined && authorization !== null || baseAccessToken !== undefined && baseAccessToken !== null) {
|
|
262
269
|
localVarHeaderParameter['Authorization'] = String(authorization ? authorization : baseAccessToken);
|
|
263
270
|
}
|
|
@@ -463,12 +470,13 @@ export const DocumentsApiFp = function(configuration?: Configuration) {
|
|
|
463
470
|
* This will return a presigned URL for a random S3 key
|
|
464
471
|
* @summary Fetches a presigned URL for a S3 key
|
|
465
472
|
* @param {string} s3Key Key for the file in S3 bucket to create the presigned download URL for
|
|
473
|
+
* @param {'attachment' | 'inline'} contentDisposition Content disposition override. Default will be depending on the document type.
|
|
466
474
|
* @param {string} [authorization] Bearer Token
|
|
467
475
|
* @param {*} [options] Override http request option.
|
|
468
476
|
* @throws {RequiredError}
|
|
469
477
|
*/
|
|
470
|
-
async getSignedS3keyUrl(s3Key: string, authorization?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
|
|
471
|
-
const localVarAxiosArgs = await localVarAxiosParamCreator.getSignedS3keyUrl(s3Key, authorization, options);
|
|
478
|
+
async getSignedS3keyUrl(s3Key: string, contentDisposition: 'attachment' | 'inline', authorization?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
|
|
479
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.getSignedS3keyUrl(s3Key, contentDisposition, authorization, options);
|
|
472
480
|
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
473
481
|
},
|
|
474
482
|
/**
|
|
@@ -561,12 +569,13 @@ export const DocumentsApiFactory = function (configuration?: Configuration, base
|
|
|
561
569
|
* This will return a presigned URL for a random S3 key
|
|
562
570
|
* @summary Fetches a presigned URL for a S3 key
|
|
563
571
|
* @param {string} s3Key Key for the file in S3 bucket to create the presigned download URL for
|
|
572
|
+
* @param {'attachment' | 'inline'} contentDisposition Content disposition override. Default will be depending on the document type.
|
|
564
573
|
* @param {string} [authorization] Bearer Token
|
|
565
574
|
* @param {*} [options] Override http request option.
|
|
566
575
|
* @throws {RequiredError}
|
|
567
576
|
*/
|
|
568
|
-
getSignedS3keyUrl(s3Key: string, authorization?: string, options?: any): AxiosPromise<void> {
|
|
569
|
-
return localVarFp.getSignedS3keyUrl(s3Key, authorization, options).then((request) => request(axios, basePath));
|
|
577
|
+
getSignedS3keyUrl(s3Key: string, contentDisposition: 'attachment' | 'inline', authorization?: string, options?: any): AxiosPromise<void> {
|
|
578
|
+
return localVarFp.getSignedS3keyUrl(s3Key, contentDisposition, authorization, options).then((request) => request(axios, basePath));
|
|
570
579
|
},
|
|
571
580
|
/**
|
|
572
581
|
* Returns a list of documents you have previously created. The documents are returned in sorted order, with the oldest one appearing first. For more information about pagination, read the Pagination documentation.
|
|
@@ -704,6 +713,13 @@ export interface DocumentsApiGetSignedS3keyUrlRequest {
|
|
|
704
713
|
*/
|
|
705
714
|
readonly s3Key: string
|
|
706
715
|
|
|
716
|
+
/**
|
|
717
|
+
* Content disposition override. Default will be depending on the document type.
|
|
718
|
+
* @type {'attachment' | 'inline'}
|
|
719
|
+
* @memberof DocumentsApiGetSignedS3keyUrl
|
|
720
|
+
*/
|
|
721
|
+
readonly contentDisposition: 'attachment' | 'inline'
|
|
722
|
+
|
|
707
723
|
/**
|
|
708
724
|
* Bearer Token
|
|
709
725
|
* @type {string}
|
|
@@ -867,7 +883,7 @@ export class DocumentsApi extends BaseAPI {
|
|
|
867
883
|
* @memberof DocumentsApi
|
|
868
884
|
*/
|
|
869
885
|
public getSignedS3keyUrl(requestParameters: DocumentsApiGetSignedS3keyUrlRequest, options?: AxiosRequestConfig) {
|
|
870
|
-
return DocumentsApiFp(this.configuration).getSignedS3keyUrl(requestParameters.s3Key, requestParameters.authorization, options).then((request) => request(this.axios, this.basePath));
|
|
886
|
+
return DocumentsApiFp(this.configuration).getSignedS3keyUrl(requestParameters.s3Key, requestParameters.contentDisposition, requestParameters.authorization, options).then((request) => request(this.axios, this.basePath));
|
|
871
887
|
}
|
|
872
888
|
|
|
873
889
|
/**
|
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<
|
|
180
|
+
async refreshTokenInternal(): Promise<LoginClass> {
|
|
175
181
|
const { username, refreshToken } = this.configuration;
|
|
176
182
|
|
|
177
183
|
|
|
178
184
|
if (!username || !refreshToken) {
|
|
179
|
-
|
|
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
|
|
199
|
+
const response = await globalAxios.request<LoginClass>(options);
|
|
194
200
|
|
|
195
|
-
return
|
|
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;
|
|
@@ -61,11 +61,12 @@ export declare const DocumentsApiAxiosParamCreator: (configuration?: Configurati
|
|
|
61
61
|
* This will return a presigned URL for a random S3 key
|
|
62
62
|
* @summary Fetches a presigned URL for a S3 key
|
|
63
63
|
* @param {string} s3Key Key for the file in S3 bucket to create the presigned download URL for
|
|
64
|
+
* @param {'attachment' | 'inline'} contentDisposition Content disposition override. Default will be depending on the document type.
|
|
64
65
|
* @param {string} [authorization] Bearer Token
|
|
65
66
|
* @param {*} [options] Override http request option.
|
|
66
67
|
* @throws {RequiredError}
|
|
67
68
|
*/
|
|
68
|
-
getSignedS3keyUrl: (s3Key: string, authorization?: string, options?: AxiosRequestConfig) => Promise<RequestArgs>;
|
|
69
|
+
getSignedS3keyUrl: (s3Key: string, contentDisposition: 'attachment' | 'inline', authorization?: string, options?: AxiosRequestConfig) => Promise<RequestArgs>;
|
|
69
70
|
/**
|
|
70
71
|
* Returns a list of documents you have previously created. The documents are returned in sorted order, with the oldest one appearing first. For more information about pagination, read the Pagination documentation.
|
|
71
72
|
* @summary List documents
|
|
@@ -138,11 +139,12 @@ export declare const DocumentsApiFp: (configuration?: Configuration) => {
|
|
|
138
139
|
* This will return a presigned URL for a random S3 key
|
|
139
140
|
* @summary Fetches a presigned URL for a S3 key
|
|
140
141
|
* @param {string} s3Key Key for the file in S3 bucket to create the presigned download URL for
|
|
142
|
+
* @param {'attachment' | 'inline'} contentDisposition Content disposition override. Default will be depending on the document type.
|
|
141
143
|
* @param {string} [authorization] Bearer Token
|
|
142
144
|
* @param {*} [options] Override http request option.
|
|
143
145
|
* @throws {RequiredError}
|
|
144
146
|
*/
|
|
145
|
-
getSignedS3keyUrl(s3Key: string, authorization?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>>;
|
|
147
|
+
getSignedS3keyUrl(s3Key: string, contentDisposition: 'attachment' | 'inline', authorization?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>>;
|
|
146
148
|
/**
|
|
147
149
|
* Returns a list of documents you have previously created. The documents are returned in sorted order, with the oldest one appearing first. For more information about pagination, read the Pagination documentation.
|
|
148
150
|
* @summary List documents
|
|
@@ -215,11 +217,12 @@ export declare const DocumentsApiFactory: (configuration?: Configuration, basePa
|
|
|
215
217
|
* This will return a presigned URL for a random S3 key
|
|
216
218
|
* @summary Fetches a presigned URL for a S3 key
|
|
217
219
|
* @param {string} s3Key Key for the file in S3 bucket to create the presigned download URL for
|
|
220
|
+
* @param {'attachment' | 'inline'} contentDisposition Content disposition override. Default will be depending on the document type.
|
|
218
221
|
* @param {string} [authorization] Bearer Token
|
|
219
222
|
* @param {*} [options] Override http request option.
|
|
220
223
|
* @throws {RequiredError}
|
|
221
224
|
*/
|
|
222
|
-
getSignedS3keyUrl(s3Key: string, authorization?: string, options?: any): AxiosPromise<void>;
|
|
225
|
+
getSignedS3keyUrl(s3Key: string, contentDisposition: 'attachment' | 'inline', authorization?: string, options?: any): AxiosPromise<void>;
|
|
223
226
|
/**
|
|
224
227
|
* Returns a list of documents you have previously created. The documents are returned in sorted order, with the oldest one appearing first. For more information about pagination, read the Pagination documentation.
|
|
225
228
|
* @summary List documents
|
|
@@ -340,6 +343,12 @@ export interface DocumentsApiGetSignedS3keyUrlRequest {
|
|
|
340
343
|
* @memberof DocumentsApiGetSignedS3keyUrl
|
|
341
344
|
*/
|
|
342
345
|
readonly s3Key: string;
|
|
346
|
+
/**
|
|
347
|
+
* Content disposition override. Default will be depending on the document type.
|
|
348
|
+
* @type {'attachment' | 'inline'}
|
|
349
|
+
* @memberof DocumentsApiGetSignedS3keyUrl
|
|
350
|
+
*/
|
|
351
|
+
readonly contentDisposition: 'attachment' | 'inline';
|
|
343
352
|
/**
|
|
344
353
|
* Bearer Token
|
|
345
354
|
* @type {string}
|
|
@@ -298,11 +298,12 @@ var DocumentsApiAxiosParamCreator = function (configuration) {
|
|
|
298
298
|
* This will return a presigned URL for a random S3 key
|
|
299
299
|
* @summary Fetches a presigned URL for a S3 key
|
|
300
300
|
* @param {string} s3Key Key for the file in S3 bucket to create the presigned download URL for
|
|
301
|
+
* @param {'attachment' | 'inline'} contentDisposition Content disposition override. Default will be depending on the document type.
|
|
301
302
|
* @param {string} [authorization] Bearer Token
|
|
302
303
|
* @param {*} [options] Override http request option.
|
|
303
304
|
* @throws {RequiredError}
|
|
304
305
|
*/
|
|
305
|
-
getSignedS3keyUrl: function (s3Key, authorization, options) {
|
|
306
|
+
getSignedS3keyUrl: function (s3Key, contentDisposition, authorization, options) {
|
|
306
307
|
if (options === void 0) { options = {}; }
|
|
307
308
|
return __awaiter(_this, void 0, void 0, function () {
|
|
308
309
|
var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, headersFromBaseOptions;
|
|
@@ -311,6 +312,8 @@ var DocumentsApiAxiosParamCreator = function (configuration) {
|
|
|
311
312
|
case 0:
|
|
312
313
|
// verify required parameter 's3Key' is not null or undefined
|
|
313
314
|
(0, common_1.assertParamExists)('getSignedS3keyUrl', 's3Key', s3Key);
|
|
315
|
+
// verify required parameter 'contentDisposition' is not null or undefined
|
|
316
|
+
(0, common_1.assertParamExists)('getSignedS3keyUrl', 'contentDisposition', contentDisposition);
|
|
314
317
|
localVarPath = "/documentservice/v1/documents/signed-s3-url";
|
|
315
318
|
localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
|
|
316
319
|
if (configuration) {
|
|
@@ -330,6 +333,9 @@ var DocumentsApiAxiosParamCreator = function (configuration) {
|
|
|
330
333
|
if (s3Key !== undefined) {
|
|
331
334
|
localVarQueryParameter['s3Key'] = s3Key;
|
|
332
335
|
}
|
|
336
|
+
if (contentDisposition !== undefined) {
|
|
337
|
+
localVarQueryParameter['contentDisposition'] = contentDisposition;
|
|
338
|
+
}
|
|
333
339
|
if (authorization !== undefined && authorization !== null || baseAccessToken !== undefined && baseAccessToken !== null) {
|
|
334
340
|
localVarHeaderParameter['Authorization'] = String(authorization ? authorization : baseAccessToken);
|
|
335
341
|
}
|
|
@@ -568,16 +574,17 @@ var DocumentsApiFp = function (configuration) {
|
|
|
568
574
|
* This will return a presigned URL for a random S3 key
|
|
569
575
|
* @summary Fetches a presigned URL for a S3 key
|
|
570
576
|
* @param {string} s3Key Key for the file in S3 bucket to create the presigned download URL for
|
|
577
|
+
* @param {'attachment' | 'inline'} contentDisposition Content disposition override. Default will be depending on the document type.
|
|
571
578
|
* @param {string} [authorization] Bearer Token
|
|
572
579
|
* @param {*} [options] Override http request option.
|
|
573
580
|
* @throws {RequiredError}
|
|
574
581
|
*/
|
|
575
|
-
getSignedS3keyUrl: function (s3Key, authorization, options) {
|
|
582
|
+
getSignedS3keyUrl: function (s3Key, contentDisposition, authorization, options) {
|
|
576
583
|
return __awaiter(this, void 0, void 0, function () {
|
|
577
584
|
var localVarAxiosArgs;
|
|
578
585
|
return __generator(this, function (_a) {
|
|
579
586
|
switch (_a.label) {
|
|
580
|
-
case 0: return [4 /*yield*/, localVarAxiosParamCreator.getSignedS3keyUrl(s3Key, authorization, options)];
|
|
587
|
+
case 0: return [4 /*yield*/, localVarAxiosParamCreator.getSignedS3keyUrl(s3Key, contentDisposition, authorization, options)];
|
|
581
588
|
case 1:
|
|
582
589
|
localVarAxiosArgs = _a.sent();
|
|
583
590
|
return [2 /*return*/, (0, common_1.createRequestFunction)(localVarAxiosArgs, axios_1.default, base_1.BASE_PATH, configuration)];
|
|
@@ -693,12 +700,13 @@ var DocumentsApiFactory = function (configuration, basePath, axios) {
|
|
|
693
700
|
* This will return a presigned URL for a random S3 key
|
|
694
701
|
* @summary Fetches a presigned URL for a S3 key
|
|
695
702
|
* @param {string} s3Key Key for the file in S3 bucket to create the presigned download URL for
|
|
703
|
+
* @param {'attachment' | 'inline'} contentDisposition Content disposition override. Default will be depending on the document type.
|
|
696
704
|
* @param {string} [authorization] Bearer Token
|
|
697
705
|
* @param {*} [options] Override http request option.
|
|
698
706
|
* @throws {RequiredError}
|
|
699
707
|
*/
|
|
700
|
-
getSignedS3keyUrl: function (s3Key, authorization, options) {
|
|
701
|
-
return localVarFp.getSignedS3keyUrl(s3Key, authorization, options).then(function (request) { return request(axios, basePath); });
|
|
708
|
+
getSignedS3keyUrl: function (s3Key, contentDisposition, authorization, options) {
|
|
709
|
+
return localVarFp.getSignedS3keyUrl(s3Key, contentDisposition, authorization, options).then(function (request) { return request(axios, basePath); });
|
|
702
710
|
},
|
|
703
711
|
/**
|
|
704
712
|
* Returns a list of documents you have previously created. The documents are returned in sorted order, with the oldest one appearing first. For more information about pagination, read the Pagination documentation.
|
|
@@ -801,7 +809,7 @@ var DocumentsApi = /** @class */ (function (_super) {
|
|
|
801
809
|
*/
|
|
802
810
|
DocumentsApi.prototype.getSignedS3keyUrl = function (requestParameters, options) {
|
|
803
811
|
var _this = this;
|
|
804
|
-
return (0, exports.DocumentsApiFp)(this.configuration).getSignedS3keyUrl(requestParameters.s3Key, requestParameters.authorization, options).then(function (request) { return request(_this.axios, _this.basePath); });
|
|
812
|
+
return (0, exports.DocumentsApiFp)(this.configuration).getSignedS3keyUrl(requestParameters.s3Key, requestParameters.contentDisposition, requestParameters.authorization, options).then(function (request) { return request(_this.axios, _this.basePath); });
|
|
805
813
|
};
|
|
806
814
|
/**
|
|
807
815
|
* Returns a list of documents you have previously created. The documents are returned in sorted order, with the oldest one appearing first. For more information about pagination, read the Pagination documentation.
|
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<
|
|
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 (
|
|
249
|
-
switch (
|
|
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 =
|
|
264
|
-
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
297
|
-
return [2 /*return*/,
|
|
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 (
|
|
319
|
-
switch (
|
|
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
|
-
|
|
330
|
+
_c.label = 1;
|
|
326
331
|
case 1:
|
|
327
|
-
|
|
332
|
+
_c.trys.push([1, 3, , 4]);
|
|
328
333
|
return [4 /*yield*/, this.refreshTokenInternal()];
|
|
329
334
|
case 2:
|
|
330
|
-
|
|
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 =
|
|
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
|
-
|
|
358
|
+
_c.label = 6;
|
|
353
359
|
case 6:
|
|
354
|
-
|
|
360
|
+
_c.trys.push([6, 8, , 9]);
|
|
355
361
|
return [4 /*yield*/, this.refreshTokenInternal()];
|
|
356
362
|
case 7:
|
|
357
|
-
|
|
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 =
|
|
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
|
}
|