@emilgroup/payment-sdk 1.4.1-beta.31 → 1.4.1-beta.32
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/payment-setup-api.ts +16 -8
- package/base.ts +15 -7
- package/dist/api/payment-setup-api.d.ts +16 -8
- package/dist/api/payment-setup-api.js +16 -8
- 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/payment-sdk@1.4.1-beta.
|
|
20
|
+
npm install @emilgroup/payment-sdk@1.4.1-beta.32 --save
|
|
21
21
|
```
|
|
22
22
|
or
|
|
23
23
|
```
|
|
24
|
-
yarn add @emilgroup/payment-sdk@1.4.1-beta.
|
|
24
|
+
yarn add @emilgroup/payment-sdk@1.4.1-beta.32
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
And then you can import `PaymentsApi`.
|
package/api/payment-setup-api.ts
CHANGED
|
@@ -27,7 +27,8 @@ import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } fr
|
|
|
27
27
|
export const PaymentSetupApiAxiosParamCreator = function (configuration?: Configuration) {
|
|
28
28
|
return {
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* This endpoint is used to save user-provided payment information. The service will send a request to the configured PSP to securely store the payment data.
|
|
31
|
+
* @summary Complete a payment setup
|
|
31
32
|
* @param {object} body
|
|
32
33
|
* @param {string} [authorization] Bearer Token
|
|
33
34
|
* @param {*} [options] Override http request option.
|
|
@@ -73,7 +74,8 @@ export const PaymentSetupApiAxiosParamCreator = function (configuration?: Config
|
|
|
73
74
|
};
|
|
74
75
|
},
|
|
75
76
|
/**
|
|
76
|
-
*
|
|
77
|
+
* This initiates an account within the configured payment service provider, whichgenerates a secret token, allowing the user to add their payment information.
|
|
78
|
+
* @summary Initiate a payment setup
|
|
77
79
|
* @param {object} body
|
|
78
80
|
* @param {string} [authorization] Bearer Token
|
|
79
81
|
* @param {*} [options] Override http request option.
|
|
@@ -129,7 +131,8 @@ export const PaymentSetupApiFp = function(configuration?: Configuration) {
|
|
|
129
131
|
const localVarAxiosParamCreator = PaymentSetupApiAxiosParamCreator(configuration)
|
|
130
132
|
return {
|
|
131
133
|
/**
|
|
132
|
-
*
|
|
134
|
+
* This endpoint is used to save user-provided payment information. The service will send a request to the configured PSP to securely store the payment data.
|
|
135
|
+
* @summary Complete a payment setup
|
|
133
136
|
* @param {object} body
|
|
134
137
|
* @param {string} [authorization] Bearer Token
|
|
135
138
|
* @param {*} [options] Override http request option.
|
|
@@ -140,7 +143,8 @@ export const PaymentSetupApiFp = function(configuration?: Configuration) {
|
|
|
140
143
|
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
141
144
|
},
|
|
142
145
|
/**
|
|
143
|
-
*
|
|
146
|
+
* This initiates an account within the configured payment service provider, whichgenerates a secret token, allowing the user to add their payment information.
|
|
147
|
+
* @summary Initiate a payment setup
|
|
144
148
|
* @param {object} body
|
|
145
149
|
* @param {string} [authorization] Bearer Token
|
|
146
150
|
* @param {*} [options] Override http request option.
|
|
@@ -161,7 +165,8 @@ export const PaymentSetupApiFactory = function (configuration?: Configuration, b
|
|
|
161
165
|
const localVarFp = PaymentSetupApiFp(configuration)
|
|
162
166
|
return {
|
|
163
167
|
/**
|
|
164
|
-
*
|
|
168
|
+
* This endpoint is used to save user-provided payment information. The service will send a request to the configured PSP to securely store the payment data.
|
|
169
|
+
* @summary Complete a payment setup
|
|
165
170
|
* @param {object} body
|
|
166
171
|
* @param {string} [authorization] Bearer Token
|
|
167
172
|
* @param {*} [options] Override http request option.
|
|
@@ -171,7 +176,8 @@ export const PaymentSetupApiFactory = function (configuration?: Configuration, b
|
|
|
171
176
|
return localVarFp.completePaymentSetup(body, authorization, options).then((request) => request(axios, basePath));
|
|
172
177
|
},
|
|
173
178
|
/**
|
|
174
|
-
*
|
|
179
|
+
* This initiates an account within the configured payment service provider, whichgenerates a secret token, allowing the user to add their payment information.
|
|
180
|
+
* @summary Initiate a payment setup
|
|
175
181
|
* @param {object} body
|
|
176
182
|
* @param {string} [authorization] Bearer Token
|
|
177
183
|
* @param {*} [options] Override http request option.
|
|
@@ -233,7 +239,8 @@ export interface PaymentSetupApiInitiatePaymentSetupRequest {
|
|
|
233
239
|
*/
|
|
234
240
|
export class PaymentSetupApi extends BaseAPI {
|
|
235
241
|
/**
|
|
236
|
-
*
|
|
242
|
+
* This endpoint is used to save user-provided payment information. The service will send a request to the configured PSP to securely store the payment data.
|
|
243
|
+
* @summary Complete a payment setup
|
|
237
244
|
* @param {PaymentSetupApiCompletePaymentSetupRequest} requestParameters Request parameters.
|
|
238
245
|
* @param {*} [options] Override http request option.
|
|
239
246
|
* @throws {RequiredError}
|
|
@@ -244,7 +251,8 @@ export class PaymentSetupApi extends BaseAPI {
|
|
|
244
251
|
}
|
|
245
252
|
|
|
246
253
|
/**
|
|
247
|
-
*
|
|
254
|
+
* This initiates an account within the configured payment service provider, whichgenerates a secret token, allowing the user to add their payment information.
|
|
255
|
+
* @summary Initiate a payment setup
|
|
248
256
|
* @param {PaymentSetupApiInitiatePaymentSetupRequest} requestParameters Request parameters.
|
|
249
257
|
* @param {*} [options] Override http request option.
|
|
250
258
|
* @throws {RequiredError}
|
package/base.ts
CHANGED
|
@@ -77,6 +77,7 @@ const TOKEN_DATA = 'APP_TOKEN';
|
|
|
77
77
|
export class BaseAPI {
|
|
78
78
|
protected configuration: Configuration | undefined;
|
|
79
79
|
private tokenData?: TokenData;
|
|
80
|
+
private permissions: Array<string> = [];
|
|
80
81
|
|
|
81
82
|
constructor(configuration?: Configuration,
|
|
82
83
|
protected basePath: string = BASE_PATH,
|
|
@@ -109,6 +110,10 @@ export class BaseAPI {
|
|
|
109
110
|
this.configuration.basePath = path;
|
|
110
111
|
}
|
|
111
112
|
|
|
113
|
+
getPermissions(): Array<string> {
|
|
114
|
+
return this.permissions;
|
|
115
|
+
}
|
|
116
|
+
|
|
112
117
|
async authorize(username: string, password: string): Promise<void> {
|
|
113
118
|
const options: AxiosRequestConfig = {
|
|
114
119
|
method: 'POST',
|
|
@@ -123,23 +128,24 @@ export class BaseAPI {
|
|
|
123
128
|
|
|
124
129
|
const response = await globalAxios.request<LoginClass>(options);
|
|
125
130
|
|
|
126
|
-
const { data: { accessToken } } = response;
|
|
131
|
+
const { data: { accessToken, permissions } } = response;
|
|
127
132
|
|
|
128
133
|
this.configuration.username = username;
|
|
129
134
|
this.configuration.accessToken = `Bearer ${accessToken}`;
|
|
130
135
|
this.tokenData.username = username;
|
|
131
136
|
this.tokenData.accessToken = accessToken;
|
|
137
|
+
this.permissions = permissions;
|
|
132
138
|
|
|
133
139
|
this.storeTokenData({
|
|
134
140
|
...this.tokenData
|
|
135
141
|
});
|
|
136
142
|
}
|
|
137
143
|
|
|
138
|
-
async refreshTokenInternal(): Promise<
|
|
144
|
+
async refreshTokenInternal(): Promise<LoginClass> {
|
|
139
145
|
const { username } = this.configuration;
|
|
140
146
|
|
|
141
147
|
if (!username) {
|
|
142
|
-
|
|
148
|
+
throw new Error('Failed to refresh token.');
|
|
143
149
|
}
|
|
144
150
|
|
|
145
151
|
const options: AxiosRequestConfig = {
|
|
@@ -152,9 +158,9 @@ export class BaseAPI {
|
|
|
152
158
|
withCredentials: true,
|
|
153
159
|
};
|
|
154
160
|
|
|
155
|
-
const
|
|
161
|
+
const response = await globalAxios.request<LoginClass>(options);
|
|
156
162
|
|
|
157
|
-
return
|
|
163
|
+
return response.data;
|
|
158
164
|
}
|
|
159
165
|
|
|
160
166
|
private storeTokenData(tokenData?: TokenData) {
|
|
@@ -188,8 +194,9 @@ export class BaseAPI {
|
|
|
188
194
|
&& !originalConfig._retry) {
|
|
189
195
|
originalConfig._retry = true;
|
|
190
196
|
try {
|
|
191
|
-
|
|
197
|
+
const { accessToken: tokenString, permissions } = await this.refreshTokenInternal();
|
|
192
198
|
const accessToken = `Bearer ${tokenString}`;
|
|
199
|
+
this.permissions = permissions;
|
|
193
200
|
|
|
194
201
|
delete originalConfig.headers['Authorization']
|
|
195
202
|
|
|
@@ -214,8 +221,9 @@ export class BaseAPI {
|
|
|
214
221
|
) {
|
|
215
222
|
_retry_count++;
|
|
216
223
|
try {
|
|
217
|
-
|
|
224
|
+
const { accessToken: tokenString, permissions } = await this.refreshTokenInternal();
|
|
218
225
|
const accessToken = `Bearer ${tokenString}`;
|
|
226
|
+
this.permissions = permissions;
|
|
219
227
|
|
|
220
228
|
_retry = true;
|
|
221
229
|
originalConfig.headers['Authorization'] = accessToken;
|
|
@@ -18,7 +18,8 @@ import { RequestArgs, BaseAPI } from '../base';
|
|
|
18
18
|
*/
|
|
19
19
|
export declare const PaymentSetupApiAxiosParamCreator: (configuration?: Configuration) => {
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* This endpoint is used to save user-provided payment information. The service will send a request to the configured PSP to securely store the payment data.
|
|
22
|
+
* @summary Complete a payment setup
|
|
22
23
|
* @param {object} body
|
|
23
24
|
* @param {string} [authorization] Bearer Token
|
|
24
25
|
* @param {*} [options] Override http request option.
|
|
@@ -26,7 +27,8 @@ export declare const PaymentSetupApiAxiosParamCreator: (configuration?: Configur
|
|
|
26
27
|
*/
|
|
27
28
|
completePaymentSetup: (body: object, authorization?: string, options?: AxiosRequestConfig) => Promise<RequestArgs>;
|
|
28
29
|
/**
|
|
29
|
-
*
|
|
30
|
+
* This initiates an account within the configured payment service provider, whichgenerates a secret token, allowing the user to add their payment information.
|
|
31
|
+
* @summary Initiate a payment setup
|
|
30
32
|
* @param {object} body
|
|
31
33
|
* @param {string} [authorization] Bearer Token
|
|
32
34
|
* @param {*} [options] Override http request option.
|
|
@@ -40,7 +42,8 @@ export declare const PaymentSetupApiAxiosParamCreator: (configuration?: Configur
|
|
|
40
42
|
*/
|
|
41
43
|
export declare const PaymentSetupApiFp: (configuration?: Configuration) => {
|
|
42
44
|
/**
|
|
43
|
-
*
|
|
45
|
+
* This endpoint is used to save user-provided payment information. The service will send a request to the configured PSP to securely store the payment data.
|
|
46
|
+
* @summary Complete a payment setup
|
|
44
47
|
* @param {object} body
|
|
45
48
|
* @param {string} [authorization] Bearer Token
|
|
46
49
|
* @param {*} [options] Override http request option.
|
|
@@ -48,7 +51,8 @@ export declare const PaymentSetupApiFp: (configuration?: Configuration) => {
|
|
|
48
51
|
*/
|
|
49
52
|
completePaymentSetup(body: object, authorization?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>>;
|
|
50
53
|
/**
|
|
51
|
-
*
|
|
54
|
+
* This initiates an account within the configured payment service provider, whichgenerates a secret token, allowing the user to add their payment information.
|
|
55
|
+
* @summary Initiate a payment setup
|
|
52
56
|
* @param {object} body
|
|
53
57
|
* @param {string} [authorization] Bearer Token
|
|
54
58
|
* @param {*} [options] Override http request option.
|
|
@@ -62,7 +66,8 @@ export declare const PaymentSetupApiFp: (configuration?: Configuration) => {
|
|
|
62
66
|
*/
|
|
63
67
|
export declare const PaymentSetupApiFactory: (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) => {
|
|
64
68
|
/**
|
|
65
|
-
*
|
|
69
|
+
* This endpoint is used to save user-provided payment information. The service will send a request to the configured PSP to securely store the payment data.
|
|
70
|
+
* @summary Complete a payment setup
|
|
66
71
|
* @param {object} body
|
|
67
72
|
* @param {string} [authorization] Bearer Token
|
|
68
73
|
* @param {*} [options] Override http request option.
|
|
@@ -70,7 +75,8 @@ export declare const PaymentSetupApiFactory: (configuration?: Configuration, bas
|
|
|
70
75
|
*/
|
|
71
76
|
completePaymentSetup(body: object, authorization?: string, options?: any): AxiosPromise<void>;
|
|
72
77
|
/**
|
|
73
|
-
*
|
|
78
|
+
* This initiates an account within the configured payment service provider, whichgenerates a secret token, allowing the user to add their payment information.
|
|
79
|
+
* @summary Initiate a payment setup
|
|
74
80
|
* @param {object} body
|
|
75
81
|
* @param {string} [authorization] Bearer Token
|
|
76
82
|
* @param {*} [options] Override http request option.
|
|
@@ -124,7 +130,8 @@ export interface PaymentSetupApiInitiatePaymentSetupRequest {
|
|
|
124
130
|
*/
|
|
125
131
|
export declare class PaymentSetupApi extends BaseAPI {
|
|
126
132
|
/**
|
|
127
|
-
*
|
|
133
|
+
* This endpoint is used to save user-provided payment information. The service will send a request to the configured PSP to securely store the payment data.
|
|
134
|
+
* @summary Complete a payment setup
|
|
128
135
|
* @param {PaymentSetupApiCompletePaymentSetupRequest} requestParameters Request parameters.
|
|
129
136
|
* @param {*} [options] Override http request option.
|
|
130
137
|
* @throws {RequiredError}
|
|
@@ -132,7 +139,8 @@ export declare class PaymentSetupApi extends BaseAPI {
|
|
|
132
139
|
*/
|
|
133
140
|
completePaymentSetup(requestParameters: PaymentSetupApiCompletePaymentSetupRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any>>;
|
|
134
141
|
/**
|
|
135
|
-
*
|
|
142
|
+
* This initiates an account within the configured payment service provider, whichgenerates a secret token, allowing the user to add their payment information.
|
|
143
|
+
* @summary Initiate a payment setup
|
|
136
144
|
* @param {PaymentSetupApiInitiatePaymentSetupRequest} requestParameters Request parameters.
|
|
137
145
|
* @param {*} [options] Override http request option.
|
|
138
146
|
* @throws {RequiredError}
|
|
@@ -93,7 +93,8 @@ var PaymentSetupApiAxiosParamCreator = function (configuration) {
|
|
|
93
93
|
var _this = this;
|
|
94
94
|
return {
|
|
95
95
|
/**
|
|
96
|
-
*
|
|
96
|
+
* This endpoint is used to save user-provided payment information. The service will send a request to the configured PSP to securely store the payment data.
|
|
97
|
+
* @summary Complete a payment setup
|
|
97
98
|
* @param {object} body
|
|
98
99
|
* @param {string} [authorization] Bearer Token
|
|
99
100
|
* @param {*} [options] Override http request option.
|
|
@@ -141,7 +142,8 @@ var PaymentSetupApiAxiosParamCreator = function (configuration) {
|
|
|
141
142
|
});
|
|
142
143
|
},
|
|
143
144
|
/**
|
|
144
|
-
*
|
|
145
|
+
* This initiates an account within the configured payment service provider, whichgenerates a secret token, allowing the user to add their payment information.
|
|
146
|
+
* @summary Initiate a payment setup
|
|
145
147
|
* @param {object} body
|
|
146
148
|
* @param {string} [authorization] Bearer Token
|
|
147
149
|
* @param {*} [options] Override http request option.
|
|
@@ -199,7 +201,8 @@ var PaymentSetupApiFp = function (configuration) {
|
|
|
199
201
|
var localVarAxiosParamCreator = (0, exports.PaymentSetupApiAxiosParamCreator)(configuration);
|
|
200
202
|
return {
|
|
201
203
|
/**
|
|
202
|
-
*
|
|
204
|
+
* This endpoint is used to save user-provided payment information. The service will send a request to the configured PSP to securely store the payment data.
|
|
205
|
+
* @summary Complete a payment setup
|
|
203
206
|
* @param {object} body
|
|
204
207
|
* @param {string} [authorization] Bearer Token
|
|
205
208
|
* @param {*} [options] Override http request option.
|
|
@@ -219,7 +222,8 @@ var PaymentSetupApiFp = function (configuration) {
|
|
|
219
222
|
});
|
|
220
223
|
},
|
|
221
224
|
/**
|
|
222
|
-
*
|
|
225
|
+
* This initiates an account within the configured payment service provider, whichgenerates a secret token, allowing the user to add their payment information.
|
|
226
|
+
* @summary Initiate a payment setup
|
|
223
227
|
* @param {object} body
|
|
224
228
|
* @param {string} [authorization] Bearer Token
|
|
225
229
|
* @param {*} [options] Override http request option.
|
|
@@ -249,7 +253,8 @@ var PaymentSetupApiFactory = function (configuration, basePath, axios) {
|
|
|
249
253
|
var localVarFp = (0, exports.PaymentSetupApiFp)(configuration);
|
|
250
254
|
return {
|
|
251
255
|
/**
|
|
252
|
-
*
|
|
256
|
+
* This endpoint is used to save user-provided payment information. The service will send a request to the configured PSP to securely store the payment data.
|
|
257
|
+
* @summary Complete a payment setup
|
|
253
258
|
* @param {object} body
|
|
254
259
|
* @param {string} [authorization] Bearer Token
|
|
255
260
|
* @param {*} [options] Override http request option.
|
|
@@ -259,7 +264,8 @@ var PaymentSetupApiFactory = function (configuration, basePath, axios) {
|
|
|
259
264
|
return localVarFp.completePaymentSetup(body, authorization, options).then(function (request) { return request(axios, basePath); });
|
|
260
265
|
},
|
|
261
266
|
/**
|
|
262
|
-
*
|
|
267
|
+
* This initiates an account within the configured payment service provider, whichgenerates a secret token, allowing the user to add their payment information.
|
|
268
|
+
* @summary Initiate a payment setup
|
|
263
269
|
* @param {object} body
|
|
264
270
|
* @param {string} [authorization] Bearer Token
|
|
265
271
|
* @param {*} [options] Override http request option.
|
|
@@ -283,7 +289,8 @@ var PaymentSetupApi = /** @class */ (function (_super) {
|
|
|
283
289
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
284
290
|
}
|
|
285
291
|
/**
|
|
286
|
-
*
|
|
292
|
+
* This endpoint is used to save user-provided payment information. The service will send a request to the configured PSP to securely store the payment data.
|
|
293
|
+
* @summary Complete a payment setup
|
|
287
294
|
* @param {PaymentSetupApiCompletePaymentSetupRequest} requestParameters Request parameters.
|
|
288
295
|
* @param {*} [options] Override http request option.
|
|
289
296
|
* @throws {RequiredError}
|
|
@@ -294,7 +301,8 @@ var PaymentSetupApi = /** @class */ (function (_super) {
|
|
|
294
301
|
return (0, exports.PaymentSetupApiFp)(this.configuration).completePaymentSetup(requestParameters.body, requestParameters.authorization, options).then(function (request) { return request(_this.axios, _this.basePath); });
|
|
295
302
|
};
|
|
296
303
|
/**
|
|
297
|
-
*
|
|
304
|
+
* This initiates an account within the configured payment service provider, whichgenerates a secret token, allowing the user to add their payment information.
|
|
305
|
+
* @summary Initiate a payment setup
|
|
298
306
|
* @param {PaymentSetupApiInitiatePaymentSetupRequest} requestParameters Request parameters.
|
|
299
307
|
* @param {*} [options] Override http request option.
|
|
300
308
|
* @throws {RequiredError}
|
package/dist/base.d.ts
CHANGED
|
@@ -52,11 +52,13 @@ export declare class BaseAPI {
|
|
|
52
52
|
protected axios: AxiosInstance;
|
|
53
53
|
protected configuration: Configuration | undefined;
|
|
54
54
|
private tokenData?;
|
|
55
|
+
private permissions;
|
|
55
56
|
constructor(configuration?: Configuration, basePath?: string, axios?: AxiosInstance);
|
|
56
57
|
selectEnvironment(env: Environment): void;
|
|
57
58
|
selectBasePath(path: string): void;
|
|
59
|
+
getPermissions(): Array<string>;
|
|
58
60
|
authorize(username: string, password: string): Promise<void>;
|
|
59
|
-
refreshTokenInternal(): Promise<
|
|
61
|
+
refreshTokenInternal(): Promise<LoginClass>;
|
|
60
62
|
private storeTokenData;
|
|
61
63
|
loadTokenData(): void;
|
|
62
64
|
cleanTokenData(): void;
|
package/dist/base.js
CHANGED
|
@@ -121,6 +121,7 @@ var BaseAPI = /** @class */ (function () {
|
|
|
121
121
|
if (axios === void 0) { axios = axios_1.default; }
|
|
122
122
|
this.basePath = basePath;
|
|
123
123
|
this.axios = axios;
|
|
124
|
+
this.permissions = [];
|
|
124
125
|
this.loadTokenData();
|
|
125
126
|
if (configuration) {
|
|
126
127
|
this.configuration = configuration;
|
|
@@ -143,11 +144,14 @@ var BaseAPI = /** @class */ (function () {
|
|
|
143
144
|
BaseAPI.prototype.selectBasePath = function (path) {
|
|
144
145
|
this.configuration.basePath = path;
|
|
145
146
|
};
|
|
147
|
+
BaseAPI.prototype.getPermissions = function () {
|
|
148
|
+
return this.permissions;
|
|
149
|
+
};
|
|
146
150
|
BaseAPI.prototype.authorize = function (username, password) {
|
|
147
151
|
return __awaiter(this, void 0, void 0, function () {
|
|
148
|
-
var options, response, accessToken;
|
|
149
|
-
return __generator(this, function (
|
|
150
|
-
switch (
|
|
152
|
+
var options, response, _a, accessToken, permissions;
|
|
153
|
+
return __generator(this, function (_b) {
|
|
154
|
+
switch (_b.label) {
|
|
151
155
|
case 0:
|
|
152
156
|
options = {
|
|
153
157
|
method: 'POST',
|
|
@@ -161,12 +165,13 @@ var BaseAPI = /** @class */ (function () {
|
|
|
161
165
|
};
|
|
162
166
|
return [4 /*yield*/, axios_1.default.request(options)];
|
|
163
167
|
case 1:
|
|
164
|
-
response =
|
|
165
|
-
|
|
168
|
+
response = _b.sent();
|
|
169
|
+
_a = response.data, accessToken = _a.accessToken, permissions = _a.permissions;
|
|
166
170
|
this.configuration.username = username;
|
|
167
171
|
this.configuration.accessToken = "Bearer ".concat(accessToken);
|
|
168
172
|
this.tokenData.username = username;
|
|
169
173
|
this.tokenData.accessToken = accessToken;
|
|
174
|
+
this.permissions = permissions;
|
|
170
175
|
this.storeTokenData(__assign({}, this.tokenData));
|
|
171
176
|
return [2 /*return*/];
|
|
172
177
|
}
|
|
@@ -175,13 +180,13 @@ var BaseAPI = /** @class */ (function () {
|
|
|
175
180
|
};
|
|
176
181
|
BaseAPI.prototype.refreshTokenInternal = function () {
|
|
177
182
|
return __awaiter(this, void 0, void 0, function () {
|
|
178
|
-
var username, options,
|
|
183
|
+
var username, options, response;
|
|
179
184
|
return __generator(this, function (_a) {
|
|
180
185
|
switch (_a.label) {
|
|
181
186
|
case 0:
|
|
182
187
|
username = this.configuration.username;
|
|
183
188
|
if (!username) {
|
|
184
|
-
|
|
189
|
+
throw new Error('Failed to refresh token.');
|
|
185
190
|
}
|
|
186
191
|
options = {
|
|
187
192
|
method: 'POST',
|
|
@@ -194,8 +199,8 @@ var BaseAPI = /** @class */ (function () {
|
|
|
194
199
|
};
|
|
195
200
|
return [4 /*yield*/, axios_1.default.request(options)];
|
|
196
201
|
case 1:
|
|
197
|
-
|
|
198
|
-
return [2 /*return*/,
|
|
202
|
+
response = _a.sent();
|
|
203
|
+
return [2 /*return*/, response.data];
|
|
199
204
|
}
|
|
200
205
|
});
|
|
201
206
|
});
|
|
@@ -221,22 +226,23 @@ var BaseAPI = /** @class */ (function () {
|
|
|
221
226
|
axios.interceptors.response.use(function (res) {
|
|
222
227
|
return res;
|
|
223
228
|
}, function (err) { return __awaiter(_this, void 0, void 0, function () {
|
|
224
|
-
var originalConfig, tokenString, accessToken, _error_1, tokenString, accessToken, _error_2;
|
|
225
|
-
return __generator(this, function (
|
|
226
|
-
switch (
|
|
229
|
+
var originalConfig, _a, tokenString, permissions, accessToken, _error_1, _b, tokenString, permissions, accessToken, _error_2;
|
|
230
|
+
return __generator(this, function (_c) {
|
|
231
|
+
switch (_c.label) {
|
|
227
232
|
case 0:
|
|
228
233
|
originalConfig = err.config;
|
|
229
234
|
if (!(err.response && !(err.response instanceof XMLHttpRequest))) return [3 /*break*/, 5];
|
|
230
235
|
if (!((err.response.status === 401 || err.response.status === 403)
|
|
231
236
|
&& !originalConfig._retry)) return [3 /*break*/, 4];
|
|
232
237
|
originalConfig._retry = true;
|
|
233
|
-
|
|
238
|
+
_c.label = 1;
|
|
234
239
|
case 1:
|
|
235
|
-
|
|
240
|
+
_c.trys.push([1, 3, , 4]);
|
|
236
241
|
return [4 /*yield*/, this.refreshTokenInternal()];
|
|
237
242
|
case 2:
|
|
238
|
-
|
|
243
|
+
_a = _c.sent(), tokenString = _a.accessToken, permissions = _a.permissions;
|
|
239
244
|
accessToken = "Bearer ".concat(tokenString);
|
|
245
|
+
this.permissions = permissions;
|
|
240
246
|
delete originalConfig.headers['Authorization'];
|
|
241
247
|
originalConfig.headers['Authorization'] = accessToken;
|
|
242
248
|
this.configuration.accessToken = accessToken;
|
|
@@ -244,7 +250,7 @@ var BaseAPI = /** @class */ (function () {
|
|
|
244
250
|
this.storeTokenData(this.tokenData);
|
|
245
251
|
return [2 /*return*/, axios(originalConfig)];
|
|
246
252
|
case 3:
|
|
247
|
-
_error_1 =
|
|
253
|
+
_error_1 = _c.sent();
|
|
248
254
|
if (_error_1.response && _error_1.response.data) {
|
|
249
255
|
return [2 /*return*/, Promise.reject(_error_1.response.data)];
|
|
250
256
|
}
|
|
@@ -255,13 +261,14 @@ var BaseAPI = /** @class */ (function () {
|
|
|
255
261
|
&& originalConfig.headers.hasOwnProperty('Authorization')
|
|
256
262
|
&& _retry_count < 4)) return [3 /*break*/, 9];
|
|
257
263
|
_retry_count++;
|
|
258
|
-
|
|
264
|
+
_c.label = 6;
|
|
259
265
|
case 6:
|
|
260
|
-
|
|
266
|
+
_c.trys.push([6, 8, , 9]);
|
|
261
267
|
return [4 /*yield*/, this.refreshTokenInternal()];
|
|
262
268
|
case 7:
|
|
263
|
-
|
|
269
|
+
_b = _c.sent(), tokenString = _b.accessToken, permissions = _b.permissions;
|
|
264
270
|
accessToken = "Bearer ".concat(tokenString);
|
|
271
|
+
this.permissions = permissions;
|
|
265
272
|
_retry = true;
|
|
266
273
|
originalConfig.headers['Authorization'] = accessToken;
|
|
267
274
|
this.configuration.accessToken = accessToken;
|
|
@@ -269,7 +276,7 @@ var BaseAPI = /** @class */ (function () {
|
|
|
269
276
|
this.storeTokenData(this.tokenData);
|
|
270
277
|
return [2 /*return*/, axios.request(__assign({}, originalConfig))];
|
|
271
278
|
case 8:
|
|
272
|
-
_error_2 =
|
|
279
|
+
_error_2 = _c.sent();
|
|
273
280
|
if (_error_2.response && _error_2.response.data) {
|
|
274
281
|
return [2 /*return*/, Promise.reject(_error_2.response.data)];
|
|
275
282
|
}
|