@emilgroup/public-api-sdk 1.40.1-beta.27 → 1.40.1-beta.28
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/address-completions-validations-api.ts +6 -16
- package/api/booking-funnels-api.ts +3 -8
- package/api/documents-api.ts +21 -56
- package/api/health-api.ts +1 -1
- package/api/ibanvalidator-api.ts +3 -8
- package/api/leads-api.ts +24 -64
- package/api/named-ranges-api.ts +3 -8
- package/api/notifications-api.ts +9 -24
- package/api/partners-api.ts +3 -8
- package/api/payments-setup-api.ts +20 -60
- package/api/product-versions-api.ts +12 -32
- package/api/products-api.ts +27 -72
- package/base.ts +54 -310
- package/common.ts +2 -3
- package/configuration.ts +0 -20
- package/dist/api/address-completions-validations-api.d.ts +2 -2
- package/dist/api/address-completions-validations-api.js +14 -22
- package/dist/api/booking-funnels-api.d.ts +1 -1
- package/dist/api/booking-funnels-api.js +7 -11
- package/dist/api/documents-api.d.ts +7 -7
- package/dist/api/documents-api.js +53 -93
- package/dist/api/health-api.d.ts +1 -1
- package/dist/api/health-api.js +1 -1
- package/dist/api/ibanvalidator-api.d.ts +1 -1
- package/dist/api/ibanvalidator-api.js +8 -15
- package/dist/api/leads-api.d.ts +8 -8
- package/dist/api/leads-api.js +64 -120
- package/dist/api/named-ranges-api.d.ts +1 -1
- package/dist/api/named-ranges-api.js +7 -11
- package/dist/api/notifications-api.d.ts +3 -3
- package/dist/api/notifications-api.js +24 -45
- package/dist/api/partners-api.d.ts +1 -1
- package/dist/api/partners-api.js +8 -15
- package/dist/api/payments-setup-api.d.ts +4 -4
- package/dist/api/payments-setup-api.js +40 -80
- package/dist/api/product-versions-api.d.ts +4 -4
- package/dist/api/product-versions-api.js +31 -56
- package/dist/api/products-api.d.ts +9 -9
- package/dist/api/products-api.js +68 -119
- package/dist/base.d.ts +0 -33
- package/dist/base.js +72 -308
- package/dist/common.d.ts +1 -1
- package/dist/common.js +0 -1
- package/dist/configuration.d.ts +0 -17
- package/dist/configuration.js +0 -2
- package/package.json +2 -2
package/base.ts
CHANGED
|
@@ -32,20 +32,9 @@ export const COLLECTION_FORMATS = {
|
|
|
32
32
|
pipes: "|",
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
-
export interface SessionClass {
|
|
36
|
-
sub: string;
|
|
37
|
-
username?: string;
|
|
38
|
-
email?: string;
|
|
39
|
-
tenantSlug?: string;
|
|
40
|
-
permissions?: string;
|
|
41
|
-
expiresAt?: number;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
35
|
export interface LoginClass {
|
|
45
36
|
accessToken: string;
|
|
46
37
|
permissions: string;
|
|
47
|
-
authMode?: string;
|
|
48
|
-
session?: SessionClass;
|
|
49
38
|
}
|
|
50
39
|
|
|
51
40
|
export interface SwitchWorkspaceRequest {
|
|
@@ -56,8 +45,6 @@ export interface SwitchWorkspaceRequest {
|
|
|
56
45
|
export interface SwitchWorkspaceResponseClass {
|
|
57
46
|
accessToken: string;
|
|
58
47
|
permissions: string;
|
|
59
|
-
authMode?: string;
|
|
60
|
-
session?: SessionClass;
|
|
61
48
|
}
|
|
62
49
|
|
|
63
50
|
export enum Environment {
|
|
@@ -72,9 +59,6 @@ export enum Environment {
|
|
|
72
59
|
let _retry_count = 0
|
|
73
60
|
let _retry = null
|
|
74
61
|
|
|
75
|
-
// Refreshes in flight per account (BaseAPI.shareRefresh).
|
|
76
|
-
const refreshesInFlight = new Map<string, Promise<LoginClass>>();
|
|
77
|
-
|
|
78
62
|
export function resetRetry() {
|
|
79
63
|
_retry_count = 0
|
|
80
64
|
}
|
|
@@ -93,19 +77,10 @@ interface TokenData {
|
|
|
93
77
|
accessToken?: string;
|
|
94
78
|
username?: string;
|
|
95
79
|
permissions?: string;
|
|
96
|
-
// 'both' or 'session' when authservice keeps the tokens in a server session.
|
|
97
|
-
authMode?: string;
|
|
98
|
-
sub?: string;
|
|
99
80
|
}
|
|
100
81
|
|
|
101
82
|
const NETWORK_ERROR_MESSAGE = "Network Error";
|
|
102
83
|
const TOKEN_DATA = 'APP_TOKEN';
|
|
103
|
-
// Sent only to authservice, to ask for a server session.
|
|
104
|
-
const AUTH_MODE_HEADER = 'X-Emil-Auth-Mode';
|
|
105
|
-
// Names the account on every call; one browser session can hold several.
|
|
106
|
-
const ACCOUNT_HEADER = 'X-Emil-Account';
|
|
107
|
-
const SESSION_MODES = ['both', 'session'];
|
|
108
|
-
const RESEND_SAFE_METHODS = ['get', 'head', 'options'];
|
|
109
84
|
|
|
110
85
|
/**
|
|
111
86
|
*
|
|
@@ -123,31 +98,14 @@ export class BaseAPI {
|
|
|
123
98
|
this.loadTokenData();
|
|
124
99
|
|
|
125
100
|
if (configuration) {
|
|
126
|
-
// Two accounts in one browser share APP_TOKEN: never take the token or session account saved for
|
|
127
|
-
// another account. The mode stays (an app naming its account keeps its session). Saved with the next refresh.
|
|
128
|
-
const ownUser = configuration.username;
|
|
129
|
-
const storedUser = this.tokenData.username;
|
|
130
|
-
if (ownUser && storedUser && ownUser.toLowerCase() !== storedUser.toLowerCase()) {
|
|
131
|
-
delete this.tokenData.accessToken;
|
|
132
|
-
delete this.tokenData.sub;
|
|
133
|
-
this.tokenData.username = ownUser;
|
|
134
|
-
}
|
|
135
101
|
const { accessToken } = this.tokenData;
|
|
136
102
|
this.configuration = configuration;
|
|
137
103
|
this.basePath = configuration.basePath || this.basePath;
|
|
138
104
|
|
|
139
|
-
if
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (this.usesSession()) {
|
|
144
|
-
this.useSessionAuth();
|
|
145
|
-
} else {
|
|
146
|
-
// Use config token if provided, otherwise use tokenData token
|
|
147
|
-
const configToken = this.configuration.accessToken;
|
|
148
|
-
const storedToken = accessToken ? `Bearer ${accessToken}` : '';
|
|
149
|
-
this.configuration.accessToken = configToken || storedToken;
|
|
150
|
-
}
|
|
105
|
+
// Use config token if provided, otherwise use tokenData token
|
|
106
|
+
const configToken = this.configuration.accessToken;
|
|
107
|
+
const storedToken = accessToken ? `Bearer ${accessToken}` : '';
|
|
108
|
+
this.configuration.accessToken = configToken || storedToken;
|
|
151
109
|
} else {
|
|
152
110
|
const { accessToken, username } = this.tokenData;
|
|
153
111
|
|
|
@@ -161,110 +119,6 @@ export class BaseAPI {
|
|
|
161
119
|
this.attachInterceptor(axios);
|
|
162
120
|
}
|
|
163
121
|
|
|
164
|
-
// The app's own account wins over APP_TOKEN, which holds whichever tab wrote last.
|
|
165
|
-
private sessionAccount(): string | undefined {
|
|
166
|
-
return this.configuration.account || this.tokenData.sub;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Apps may pass the address as the second argument only; authservice is on the same host.
|
|
170
|
-
private authBasePath(): string {
|
|
171
|
-
return this.configuration.basePath || this.basePath;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
private usesSession(): boolean {
|
|
175
|
-
return !!this.configuration.cookieAuth && SESSION_MODES.indexOf(this.tokenData.authMode) !== -1 && !!this.sessionAccount();
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
private useSessionAuth() {
|
|
179
|
-
const { headers, ...baseOptions } = this.configuration.baseOptions || {};
|
|
180
|
-
this.configuration.accessToken = '';
|
|
181
|
-
this.configuration.baseOptions = {
|
|
182
|
-
...baseOptions,
|
|
183
|
-
withCredentials: true,
|
|
184
|
-
headers: { ...headers, [ACCOUNT_HEADER]: this.sessionAccount() },
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
private useHeaderAuth(accessToken: string, keepSessionData = false) {
|
|
189
|
-
this.configuration.accessToken = accessToken ? `Bearer ${accessToken}` : '';
|
|
190
|
-
this.tokenData.accessToken = accessToken;
|
|
191
|
-
// An app without cookieAuth does not own the session fields: its refresh leaves them for the session apps.
|
|
192
|
-
if (!keepSessionData || this.configuration.cookieAuth) {
|
|
193
|
-
delete this.tokenData.authMode;
|
|
194
|
-
delete this.tokenData.sub;
|
|
195
|
-
}
|
|
196
|
-
if (this.configuration.cookieAuth) {
|
|
197
|
-
const { withCredentials, headers, ...baseOptions } = this.configuration.baseOptions || {};
|
|
198
|
-
const { [ACCOUNT_HEADER]: account, ...otherHeaders } = headers || {};
|
|
199
|
-
this.configuration.baseOptions = { ...baseOptions, headers: otherHeaders };
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
private applyTokenReply({ accessToken, authMode, session }: LoginClass, fromRefresh = false) {
|
|
204
|
-
if (this.configuration.cookieAuth && SESSION_MODES.indexOf(authMode) !== -1 && session?.sub) {
|
|
205
|
-
this.tokenData.authMode = authMode;
|
|
206
|
-
this.tokenData.sub = session.sub;
|
|
207
|
-
if (this.configuration.account) {
|
|
208
|
-
// A workspace switch moves the app to another account.
|
|
209
|
-
this.configuration.account = session.sub;
|
|
210
|
-
}
|
|
211
|
-
// Both keeps the token for apps not moved yet; session mode keeps no token at all.
|
|
212
|
-
if (authMode === 'both' && accessToken) {
|
|
213
|
-
this.tokenData.accessToken = accessToken;
|
|
214
|
-
} else {
|
|
215
|
-
delete this.tokenData.accessToken;
|
|
216
|
-
}
|
|
217
|
-
this.useSessionAuth();
|
|
218
|
-
} else {
|
|
219
|
-
this.useHeaderAuth(accessToken, fromRefresh);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
private sessionHeaders(): Record<string, string> {
|
|
224
|
-
if (!this.configuration.cookieAuth) {
|
|
225
|
-
return {};
|
|
226
|
-
}
|
|
227
|
-
return {
|
|
228
|
-
[AUTH_MODE_HEADER]: 'session',
|
|
229
|
-
...(this.usesSession() && { [ACCOUNT_HEADER]: this.sessionAccount() }),
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
private withCurrentAuth(config: AxiosRequestConfig): AxiosRequestConfig {
|
|
234
|
-
delete config.headers['Authorization'];
|
|
235
|
-
delete config.headers[ACCOUNT_HEADER];
|
|
236
|
-
if (this.usesSession()) {
|
|
237
|
-
config.headers[ACCOUNT_HEADER] = this.sessionAccount();
|
|
238
|
-
config.withCredentials = true;
|
|
239
|
-
} else if (this.configuration.accessToken) {
|
|
240
|
-
config.headers['Authorization'] = this.configuration.accessToken;
|
|
241
|
-
}
|
|
242
|
-
return config;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// Both keeps the token, so a session call the browser could not complete can be sent again with it.
|
|
246
|
-
private canRetryWithToken(config: AxiosRequestConfig): boolean {
|
|
247
|
-
return !!config.withCredentials && !!config.headers?.[ACCOUNT_HEADER]
|
|
248
|
-
&& !!this.tokenData.accessToken && this.tokenData.authMode !== 'session';
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// A network error can come after the server ran the call, so only a call that is safe to repeat is sent again.
|
|
252
|
-
private canResend(config: AxiosRequestConfig): boolean {
|
|
253
|
-
return RESEND_SAFE_METHODS.indexOf((config.method || 'get').toLowerCase()) !== -1
|
|
254
|
-
|| Object.keys(config.headers || {}).some((name) => name.toLowerCase() === 'idempotency-key');
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
private switchToToken() {
|
|
258
|
-
this.useHeaderAuth(this.tokenData.accessToken);
|
|
259
|
-
this.storeTokenData(this.tokenData);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
private retryWithToken(axios: AxiosInstance, config: AxiosRequestConfig) {
|
|
263
|
-
this.switchToToken();
|
|
264
|
-
config.withCredentials = false;
|
|
265
|
-
return axios(this.withCurrentAuth(config));
|
|
266
|
-
}
|
|
267
|
-
|
|
268
122
|
selectEnvironment(env: Environment) {
|
|
269
123
|
this.selectBasePath(env);
|
|
270
124
|
}
|
|
@@ -284,8 +138,8 @@ export class BaseAPI {
|
|
|
284
138
|
async authorize(username: string, password: string, targetWorkspace?: string): Promise<void> {
|
|
285
139
|
const options: AxiosRequestConfig = {
|
|
286
140
|
method: 'POST',
|
|
287
|
-
url: `${this.
|
|
288
|
-
headers: { 'Content-Type': 'application/json'
|
|
141
|
+
url: `${this.configuration.basePath}/authservice/v1/login`,
|
|
142
|
+
headers: { 'Content-Type': 'application/json' },
|
|
289
143
|
data: {
|
|
290
144
|
username,
|
|
291
145
|
password,
|
|
@@ -295,10 +149,13 @@ export class BaseAPI {
|
|
|
295
149
|
|
|
296
150
|
const response = await globalAxios.request<LoginClass>(options);
|
|
297
151
|
|
|
152
|
+
const { data: { accessToken, permissions } } = response;
|
|
153
|
+
|
|
298
154
|
this.configuration.username = username;
|
|
155
|
+
this.configuration.accessToken = `Bearer ${accessToken}`;
|
|
299
156
|
this.tokenData.username = username;
|
|
300
|
-
this.tokenData.
|
|
301
|
-
this.
|
|
157
|
+
this.tokenData.accessToken = accessToken;
|
|
158
|
+
this.tokenData.permissions = permissions;
|
|
302
159
|
|
|
303
160
|
// Switch workspace if provided
|
|
304
161
|
if (targetWorkspace) {
|
|
@@ -318,11 +175,10 @@ export class BaseAPI {
|
|
|
318
175
|
async switchWorkspace(targetWorkspace: string): Promise<void> {
|
|
319
176
|
const options: AxiosRequestConfig = {
|
|
320
177
|
method: 'POST',
|
|
321
|
-
url: `${this.
|
|
178
|
+
url: `${this.configuration.basePath}/authservice/v1/workspaces/switch`,
|
|
322
179
|
headers: {
|
|
323
180
|
'Content-Type': 'application/json',
|
|
324
|
-
|
|
325
|
-
...(!this.usesSession() && !!this.configuration.accessToken && { 'Authorization': this.configuration.accessToken as string }),
|
|
181
|
+
'Authorization': `Bearer ${this.configuration.accessToken}`,
|
|
326
182
|
},
|
|
327
183
|
data: {
|
|
328
184
|
username: this.configuration.username,
|
|
@@ -333,8 +189,11 @@ export class BaseAPI {
|
|
|
333
189
|
|
|
334
190
|
const response = await globalAxios.request<SwitchWorkspaceResponseClass>(options);
|
|
335
191
|
|
|
336
|
-
|
|
337
|
-
|
|
192
|
+
const { data: { accessToken, permissions } } = response;
|
|
193
|
+
|
|
194
|
+
this.configuration.accessToken = `Bearer ${accessToken}`;
|
|
195
|
+
this.tokenData.accessToken = accessToken;
|
|
196
|
+
this.tokenData.permissions = permissions;
|
|
338
197
|
|
|
339
198
|
this.storeTokenData({
|
|
340
199
|
...this.tokenData
|
|
@@ -345,42 +204,14 @@ export class BaseAPI {
|
|
|
345
204
|
const { username } = this.configuration;
|
|
346
205
|
|
|
347
206
|
if (!username) {
|
|
348
|
-
|
|
349
|
-
const cannotRefresh: any = new Error('Failed to refresh token.');
|
|
350
|
-
cannotRefresh.sessionExpired = true;
|
|
351
|
-
throw cannotRefresh;
|
|
207
|
+
throw new Error('Failed to refresh token.');
|
|
352
208
|
}
|
|
353
209
|
|
|
354
210
|
const refreshTokenAxios = globalAxios.create()
|
|
355
211
|
refreshTokenAxios.interceptors.response.use(response => {
|
|
356
|
-
const { permissions
|
|
357
|
-
|
|
358
|
-
const onSession = this.usesSession();
|
|
359
|
-
|
|
360
|
-
// Newer data saved for this account (e.g. the session mode the shell saved later) wins over the copy
|
|
361
|
-
// read when the object was made; data of another account or another workspace (sub) is never taken.
|
|
362
|
-
const latest = ((typeof window !== 'undefined' && defaultStorage().get<TokenData>(TOKEN_DATA)) || {}) as TokenData;
|
|
363
|
-
const ownSub = this.sessionAccount();
|
|
364
|
-
if (latest.username?.toLowerCase() === username.toLowerCase()
|
|
365
|
-
&& (!ownSub || !latest.sub || latest.sub === ownSub)) {
|
|
366
|
-
// A bare reset ({username}, an app's account check) keeps this copy's other fields; any fuller record
|
|
367
|
-
// is the truth, so fields it lacks were removed on purpose (e.g. a rollback) and stay removed.
|
|
368
|
-
const bareReset = Object.keys(latest).every((key) => key === 'username');
|
|
369
|
-
this.tokenData = bareReset ? { ...this.tokenData, ...latest } : { ...latest };
|
|
370
|
-
}
|
|
371
|
-
// The reply is for this account: label it, or an SDK object of another account would take the token.
|
|
372
|
-
if (this.tokenData.username?.toLowerCase() !== username.toLowerCase()) {
|
|
373
|
-
this.tokenData.username = username;
|
|
374
|
-
}
|
|
212
|
+
const { permissions } = response.data;
|
|
213
|
+
|
|
375
214
|
this.tokenData.permissions = permissions;
|
|
376
|
-
// Keep the new token for the page's next SDK objects; session data is left as it is.
|
|
377
|
-
if (accessToken && !onSession) {
|
|
378
|
-
this.tokenData.accessToken = accessToken;
|
|
379
|
-
this.configuration.accessToken = `Bearer ${accessToken}`;
|
|
380
|
-
} else if (accessToken && authMode === 'both') {
|
|
381
|
-
// Both: this app stays on the session; the token is kept for apps not moved yet.
|
|
382
|
-
this.tokenData.accessToken = accessToken;
|
|
383
|
-
}
|
|
384
215
|
this.storeTokenData(this.tokenData);
|
|
385
216
|
|
|
386
217
|
return response;
|
|
@@ -388,10 +219,9 @@ export class BaseAPI {
|
|
|
388
219
|
|
|
389
220
|
const options: AxiosRequestConfig = {
|
|
390
221
|
method: 'POST',
|
|
391
|
-
url: `${this.
|
|
222
|
+
url: `${this.configuration.basePath}/authservice/v1/refresh-token`,
|
|
392
223
|
headers: {
|
|
393
224
|
'Content-Type': 'application/json',
|
|
394
|
-
...this.sessionHeaders(),
|
|
395
225
|
},
|
|
396
226
|
data: { username: username },
|
|
397
227
|
withCredentials: true,
|
|
@@ -419,85 +249,6 @@ export class BaseAPI {
|
|
|
419
249
|
this.storeTokenData(null);
|
|
420
250
|
}
|
|
421
251
|
|
|
422
|
-
// Marks each request with the account (username) of the SDK object that sent it: only SDK objects of that
|
|
423
|
-
// account refresh and resend it, never an object of another account in the same app.
|
|
424
|
-
private static readonly REQUEST_OWNER = '_emilSdkOwner';
|
|
425
|
-
|
|
426
|
-
private ownAccount(): string {
|
|
427
|
-
return (this.configuration.username || '').toLowerCase();
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
protected withOwner(options?: AxiosRequestConfig): AxiosRequestConfig {
|
|
431
|
-
// An object without a username cannot refresh itself: its requests stay unmarked, as before.
|
|
432
|
-
if (!this.ownAccount()) {
|
|
433
|
-
return { ...options };
|
|
434
|
-
}
|
|
435
|
-
return { ...options, [BaseAPI.REQUEST_OWNER]: this.ownAccount() } as AxiosRequestConfig;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
// Sent for another account: only that account's SDK objects handle it. Unmarked requests as before.
|
|
439
|
-
private sentByOtherAccount(config?: AxiosRequestConfig): boolean {
|
|
440
|
-
const owner = (config as Record<string, unknown> | undefined)?.[BaseAPI.REQUEST_OWNER];
|
|
441
|
-
return owner !== undefined && owner !== this.ownAccount();
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
// One refresh per account; an object without a username keeps its own, which fails as before.
|
|
446
|
-
private sharedRefresh(): Promise<LoginClass> {
|
|
447
|
-
const account = this.ownAccount();
|
|
448
|
-
if (!account) {
|
|
449
|
-
return this.refreshTokenInternal();
|
|
450
|
-
}
|
|
451
|
-
return BaseAPI.shareRefresh(refreshesInFlight, account, () => this.refreshTokenInternal());
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
private refreshRunning(): boolean {
|
|
455
|
-
const account = this.ownAccount();
|
|
456
|
-
return !!account && refreshesInFlight.has(account);
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
// Joins the refresh already in flight for this key, or starts one: calls refused at the same time wait for
|
|
460
|
-
// one refresh instead of each starting their own (a refresh token may be single-use). The entry is removed
|
|
461
|
-
// when the refresh settles.
|
|
462
|
-
private static shareRefresh<K, T>(inFlight: Map<K, Promise<T>>, key: K, start: () => Promise<T>): Promise<T> {
|
|
463
|
-
const running = inFlight.get(key);
|
|
464
|
-
if (running) {
|
|
465
|
-
return running;
|
|
466
|
-
}
|
|
467
|
-
const refresh = start();
|
|
468
|
-
inFlight.set(key, refresh);
|
|
469
|
-
const settled = () => { inFlight.delete(key); };
|
|
470
|
-
refresh.then(settled, settled);
|
|
471
|
-
return refresh;
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
// A refused call that joins a refresh already running is not a new try: only started refreshes count toward
|
|
475
|
-
// the limit, so every call refused at the same time is retried.
|
|
476
|
-
private mayRefreshAfterNetworkError(): boolean {
|
|
477
|
-
if (this.refreshRunning()) {
|
|
478
|
-
return true;
|
|
479
|
-
}
|
|
480
|
-
if (_retry_count >= 4) {
|
|
481
|
-
return false;
|
|
482
|
-
}
|
|
483
|
-
_retry_count++;
|
|
484
|
-
return true;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
// Rejects as before (the refresh's response body, or its error). Marks it as an ended session only when the
|
|
489
|
-
// refresh was refused (401 or 403) or could not run (no username, marked where it is thrown); a server error
|
|
490
|
-
// or a network error says nothing about the session, so an app must not log the user out for it. A body that
|
|
491
|
-
// is not an object cannot carry the mark and is kept as it is.
|
|
492
|
-
private rejectEndedSession(error: any): Promise<never> {
|
|
493
|
-
const rejection = error.response?.data || error;
|
|
494
|
-
const status = error.response?.status;
|
|
495
|
-
if (typeof rejection === 'object' && (status === 401 || status === 403)) {
|
|
496
|
-
rejection.sessionExpired = true;
|
|
497
|
-
}
|
|
498
|
-
return Promise.reject(rejection);
|
|
499
|
-
}
|
|
500
|
-
|
|
501
252
|
private attachInterceptor(axios: AxiosInstance) {
|
|
502
253
|
axios.interceptors.response.use(
|
|
503
254
|
(res) => {
|
|
@@ -505,66 +256,59 @@ export class BaseAPI {
|
|
|
505
256
|
},
|
|
506
257
|
async (err) => {
|
|
507
258
|
let originalConfig = err.config;
|
|
508
|
-
if (this.sentByOtherAccount(originalConfig)) {
|
|
509
|
-
return Promise.reject(err);
|
|
510
|
-
}
|
|
511
259
|
if (err.response && !(err.response instanceof XMLHttpRequest)) { // sometimes buggy and is of type request
|
|
512
260
|
// Access Token was expired
|
|
513
261
|
if ((err.response.status === 401 || err.response.status === 403)
|
|
514
262
|
&& !originalConfig._retry) {
|
|
515
263
|
originalConfig._retry = true;
|
|
516
264
|
try {
|
|
517
|
-
const
|
|
518
|
-
|
|
519
|
-
this.
|
|
520
|
-
this.storeTokenData(this.tokenData);
|
|
265
|
+
const { accessToken: tokenString, permissions } = await this.refreshTokenInternal();
|
|
266
|
+
const accessToken = `Bearer ${tokenString}`;
|
|
267
|
+
this.tokenData.permissions = permissions;
|
|
521
268
|
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
269
|
+
delete originalConfig.headers['Authorization']
|
|
270
|
+
|
|
271
|
+
originalConfig.headers['Authorization'] = accessToken;
|
|
272
|
+
|
|
273
|
+
this.configuration.accessToken = accessToken;
|
|
274
|
+
this.tokenData.accessToken = tokenString;
|
|
275
|
+
|
|
276
|
+
this.storeTokenData(this.tokenData);
|
|
525
277
|
|
|
526
|
-
|
|
527
|
-
return axios(this.withCurrentAuth(originalConfig)).catch((retryError) => {
|
|
528
|
-
if (retryError?.response?.status !== 401 || !this.tokenData.accessToken) {
|
|
529
|
-
return Promise.reject(retryError);
|
|
530
|
-
}
|
|
531
|
-
return this.retryWithToken(axios, originalConfig);
|
|
532
|
-
});
|
|
278
|
+
return axios(originalConfig);
|
|
533
279
|
} catch (_error) {
|
|
534
|
-
|
|
280
|
+
if (_error.response && _error.response.data) {
|
|
281
|
+
return Promise.reject(_error.response.data);
|
|
282
|
+
}
|
|
283
|
+
return Promise.reject(_error);
|
|
535
284
|
}
|
|
536
285
|
}
|
|
537
|
-
} else if (err.message === NETWORK_ERROR_MESSAGE && this.canRetryWithToken(originalConfig)) {
|
|
538
|
-
// Both mode: the browser blocked the session call or hid its reply; later calls use the token.
|
|
539
|
-
if (!this.canResend(originalConfig)) {
|
|
540
|
-
this.switchToToken();
|
|
541
|
-
return Promise.reject(err);
|
|
542
|
-
}
|
|
543
|
-
return this.retryWithToken(axios, originalConfig);
|
|
544
286
|
} else if (err.message === NETWORK_ERROR_MESSAGE
|
|
545
|
-
&&
|
|
546
|
-
|
|
547
|
-
&& this.mayRefreshAfterNetworkError()
|
|
287
|
+
&& originalConfig.headers.hasOwnProperty('Authorization')
|
|
288
|
+
&& _retry_count < 4
|
|
548
289
|
) {
|
|
290
|
+
_retry_count++;
|
|
549
291
|
try {
|
|
550
|
-
|
|
551
|
-
const
|
|
552
|
-
this.tokenData.permissions =
|
|
292
|
+
const { accessToken: tokenString, permissions } = await this.refreshTokenInternal();
|
|
293
|
+
const accessToken = `Bearer ${tokenString}`;
|
|
294
|
+
this.tokenData.permissions = permissions;
|
|
553
295
|
|
|
554
296
|
_retry = true;
|
|
555
|
-
|
|
297
|
+
originalConfig.headers['Authorization'] = accessToken;
|
|
298
|
+
|
|
299
|
+
this.configuration.accessToken = accessToken;
|
|
300
|
+
this.tokenData.accessToken = tokenString;
|
|
301
|
+
|
|
556
302
|
this.storeTokenData(this.tokenData);
|
|
557
303
|
|
|
558
|
-
// The limit is for refreshes that do not help; one that worked starts the count again.
|
|
559
|
-
// Not awaited, so a failed retry reaches the app as the same axios error as before.
|
|
560
304
|
return axios.request({
|
|
561
|
-
...
|
|
562
|
-
}).then((retried) => {
|
|
563
|
-
_retry_count = 0;
|
|
564
|
-
return retried;
|
|
305
|
+
...originalConfig,
|
|
565
306
|
});
|
|
566
307
|
} catch (_error) {
|
|
567
|
-
|
|
308
|
+
if (_error.response && _error.response.data) {
|
|
309
|
+
return Promise.reject(_error.response.data);
|
|
310
|
+
}
|
|
311
|
+
return Promise.reject(_error);
|
|
568
312
|
}
|
|
569
313
|
}
|
|
570
314
|
return Promise.reject(err);
|
package/common.ts
CHANGED
|
@@ -130,10 +130,9 @@ export const toPathString = function (url: URL) {
|
|
|
130
130
|
* @export
|
|
131
131
|
*/
|
|
132
132
|
export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
|
|
133
|
-
|
|
134
|
-
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH): Promise<R> => {
|
|
133
|
+
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
|
|
135
134
|
const axiosRequestArgs = {...axiosArgs.options, url: (configuration?.basePath || basePath) + axiosArgs.url};
|
|
136
|
-
return axios.request<T, R>(axiosRequestArgs)
|
|
135
|
+
return axios.request<T, R>(axiosRequestArgs);
|
|
137
136
|
};
|
|
138
137
|
}
|
|
139
138
|
|
package/configuration.ts
CHANGED
|
@@ -21,8 +21,6 @@ export interface ConfigurationParameters {
|
|
|
21
21
|
basePath?: string;
|
|
22
22
|
baseOptions?: any;
|
|
23
23
|
formDataCtor?: new () => any;
|
|
24
|
-
cookieAuth?: boolean;
|
|
25
|
-
account?: string;
|
|
26
24
|
}
|
|
27
25
|
|
|
28
26
|
export class Configuration {
|
|
@@ -76,22 +74,6 @@ export class Configuration {
|
|
|
76
74
|
*/
|
|
77
75
|
formDataCtor?: new () => any;
|
|
78
76
|
|
|
79
|
-
/**
|
|
80
|
-
* Use a server session when authservice makes one; otherwise the token, as without this option.
|
|
81
|
-
* Set `account` too, so each SDK object keeps its own account.
|
|
82
|
-
*
|
|
83
|
-
* @type {boolean}
|
|
84
|
-
* @memberof Configuration
|
|
85
|
-
*/
|
|
86
|
-
cookieAuth?: boolean;
|
|
87
|
-
/**
|
|
88
|
-
* The session account (Cognito sub) this app shows, so the SDK never takes another tab's account.
|
|
89
|
-
*
|
|
90
|
-
* @type {string}
|
|
91
|
-
* @memberof Configuration
|
|
92
|
-
*/
|
|
93
|
-
account?: string;
|
|
94
|
-
|
|
95
77
|
constructor(param: ConfigurationParameters = {}) {
|
|
96
78
|
this.apiKey = param.apiKey;
|
|
97
79
|
this.username = param.username;
|
|
@@ -100,8 +82,6 @@ export class Configuration {
|
|
|
100
82
|
this.basePath = param.basePath;
|
|
101
83
|
this.baseOptions = param.baseOptions;
|
|
102
84
|
this.formDataCtor = param.formDataCtor;
|
|
103
|
-
this.cookieAuth = param.cookieAuth;
|
|
104
|
-
this.account = param.account;
|
|
105
85
|
}
|
|
106
86
|
|
|
107
87
|
/**
|
|
@@ -211,7 +211,7 @@ export declare class AddressCompletionsValidationsApi extends BaseAPI {
|
|
|
211
211
|
* @throws {RequiredError}
|
|
212
212
|
* @memberof AddressCompletionsValidationsApi
|
|
213
213
|
*/
|
|
214
|
-
listAddressCompletions(requestParameters: AddressCompletionsValidationsApiListAddressCompletionsRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<AddressCompletionResponseClass, any, {}
|
|
214
|
+
listAddressCompletions(requestParameters: AddressCompletionsValidationsApiListAddressCompletionsRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<AddressCompletionResponseClass, any, {}>>;
|
|
215
215
|
/**
|
|
216
216
|
* This will return a response whether the provided address is valid or not.
|
|
217
217
|
* @summary Retrieve the Address validation
|
|
@@ -220,5 +220,5 @@ export declare class AddressCompletionsValidationsApi extends BaseAPI {
|
|
|
220
220
|
* @throws {RequiredError}
|
|
221
221
|
* @memberof AddressCompletionsValidationsApi
|
|
222
222
|
*/
|
|
223
|
-
validateAddress(requestParameters: AddressCompletionsValidationsApiValidateAddressRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<ValidateAddressResponseClass, any, {}
|
|
223
|
+
validateAddress(requestParameters: AddressCompletionsValidationsApiValidateAddressRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<ValidateAddressResponseClass, any, {}>>;
|
|
224
224
|
}
|
|
@@ -105,10 +105,9 @@ var AddressCompletionsValidationsApiAxiosParamCreator = function (configuration)
|
|
|
105
105
|
listAddressCompletions: function (partialAddress, authorization, country, limit, options) {
|
|
106
106
|
if (options === void 0) { options = {}; }
|
|
107
107
|
return __awaiter(_this, void 0, void 0, function () {
|
|
108
|
-
var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter,
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
switch (_b.label) {
|
|
108
|
+
var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, headersFromBaseOptions;
|
|
109
|
+
return __generator(this, function (_a) {
|
|
110
|
+
switch (_a.label) {
|
|
112
111
|
case 0:
|
|
113
112
|
// verify required parameter 'partialAddress' is not null or undefined
|
|
114
113
|
(0, common_1.assertParamExists)('listAddressCompletions', 'partialAddress', partialAddress);
|
|
@@ -127,7 +126,7 @@ var AddressCompletionsValidationsApiAxiosParamCreator = function (configuration)
|
|
|
127
126
|
case 1:
|
|
128
127
|
// authentication bearer required
|
|
129
128
|
// http bearer authentication required
|
|
130
|
-
|
|
129
|
+
_a.sent();
|
|
131
130
|
if (partialAddress !== undefined) {
|
|
132
131
|
localVarQueryParameter['partialAddress'] = partialAddress;
|
|
133
132
|
}
|
|
@@ -137,11 +136,8 @@ var AddressCompletionsValidationsApiAxiosParamCreator = function (configuration)
|
|
|
137
136
|
if (limit !== undefined) {
|
|
138
137
|
localVarQueryParameter['limit'] = limit;
|
|
139
138
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
authorizationKeepEmpty = authorizationIsAuth && authorizationValue === '' && !((_a = baseOptions === null || baseOptions === void 0 ? void 0 : baseOptions.headers) === null || _a === void 0 ? void 0 : _a['X-Emil-Account']);
|
|
143
|
-
if (authorizationValue || authorizationKeepEmpty) {
|
|
144
|
-
localVarHeaderParameter['Authorization'] = String(authorizationValue);
|
|
139
|
+
if (authorization !== undefined && authorization !== null || baseAccessToken !== undefined && baseAccessToken !== null) {
|
|
140
|
+
localVarHeaderParameter['Authorization'] = String(authorization ? authorization : baseAccessToken);
|
|
145
141
|
}
|
|
146
142
|
(0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter);
|
|
147
143
|
headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
@@ -171,10 +167,9 @@ var AddressCompletionsValidationsApiAxiosParamCreator = function (configuration)
|
|
|
171
167
|
validateAddress: function (city, country, postalCode, street, houseNumber, authorization, completeAddress, limit, options) {
|
|
172
168
|
if (options === void 0) { options = {}; }
|
|
173
169
|
return __awaiter(_this, void 0, void 0, function () {
|
|
174
|
-
var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter,
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
switch (_b.label) {
|
|
170
|
+
var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, headersFromBaseOptions;
|
|
171
|
+
return __generator(this, function (_a) {
|
|
172
|
+
switch (_a.label) {
|
|
178
173
|
case 0:
|
|
179
174
|
// verify required parameter 'city' is not null or undefined
|
|
180
175
|
(0, common_1.assertParamExists)('validateAddress', 'city', city);
|
|
@@ -201,7 +196,7 @@ var AddressCompletionsValidationsApiAxiosParamCreator = function (configuration)
|
|
|
201
196
|
case 1:
|
|
202
197
|
// authentication bearer required
|
|
203
198
|
// http bearer authentication required
|
|
204
|
-
|
|
199
|
+
_a.sent();
|
|
205
200
|
if (completeAddress !== undefined) {
|
|
206
201
|
localVarQueryParameter['completeAddress'] = completeAddress;
|
|
207
202
|
}
|
|
@@ -223,11 +218,8 @@ var AddressCompletionsValidationsApiAxiosParamCreator = function (configuration)
|
|
|
223
218
|
if (limit !== undefined) {
|
|
224
219
|
localVarQueryParameter['limit'] = limit;
|
|
225
220
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
authorizationKeepEmpty = authorizationIsAuth && authorizationValue === '' && !((_a = baseOptions === null || baseOptions === void 0 ? void 0 : baseOptions.headers) === null || _a === void 0 ? void 0 : _a['X-Emil-Account']);
|
|
229
|
-
if (authorizationValue || authorizationKeepEmpty) {
|
|
230
|
-
localVarHeaderParameter['Authorization'] = String(authorizationValue);
|
|
221
|
+
if (authorization !== undefined && authorization !== null || baseAccessToken !== undefined && baseAccessToken !== null) {
|
|
222
|
+
localVarHeaderParameter['Authorization'] = String(authorization ? authorization : baseAccessToken);
|
|
231
223
|
}
|
|
232
224
|
(0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter);
|
|
233
225
|
headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
@@ -364,7 +356,7 @@ var AddressCompletionsValidationsApi = /** @class */ (function (_super) {
|
|
|
364
356
|
*/
|
|
365
357
|
AddressCompletionsValidationsApi.prototype.listAddressCompletions = function (requestParameters, options) {
|
|
366
358
|
var _this = this;
|
|
367
|
-
return (0, exports.AddressCompletionsValidationsApiFp)(this.configuration).listAddressCompletions(requestParameters.partialAddress, requestParameters.authorization, requestParameters.country, requestParameters.limit,
|
|
359
|
+
return (0, exports.AddressCompletionsValidationsApiFp)(this.configuration).listAddressCompletions(requestParameters.partialAddress, requestParameters.authorization, requestParameters.country, requestParameters.limit, options).then(function (request) { return request(_this.axios, _this.basePath); });
|
|
368
360
|
};
|
|
369
361
|
/**
|
|
370
362
|
* This will return a response whether the provided address is valid or not.
|
|
@@ -376,7 +368,7 @@ var AddressCompletionsValidationsApi = /** @class */ (function (_super) {
|
|
|
376
368
|
*/
|
|
377
369
|
AddressCompletionsValidationsApi.prototype.validateAddress = function (requestParameters, options) {
|
|
378
370
|
var _this = this;
|
|
379
|
-
return (0, exports.AddressCompletionsValidationsApiFp)(this.configuration).validateAddress(requestParameters.city, requestParameters.country, requestParameters.postalCode, requestParameters.street, requestParameters.houseNumber, requestParameters.authorization, requestParameters.completeAddress, requestParameters.limit,
|
|
371
|
+
return (0, exports.AddressCompletionsValidationsApiFp)(this.configuration).validateAddress(requestParameters.city, requestParameters.country, requestParameters.postalCode, requestParameters.street, requestParameters.houseNumber, requestParameters.authorization, requestParameters.completeAddress, requestParameters.limit, options).then(function (request) { return request(_this.axios, _this.basePath); });
|
|
380
372
|
};
|
|
381
373
|
return AddressCompletionsValidationsApi;
|
|
382
374
|
}(base_1.BaseAPI));
|