@emilgroup/public-api-sdk 1.40.1-beta.26 → 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 +43 -239
- 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 -26
- package/dist/base.js +60 -243
- 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,10 +59,6 @@ export enum Environment {
|
|
|
72
59
|
let _retry_count = 0
|
|
73
60
|
let _retry = null
|
|
74
61
|
|
|
75
|
-
// Marks each request with the account (username) of the SDK object that sent it: only SDK objects of that
|
|
76
|
-
// account refresh and resend it, never an object of another account open in the same browser.
|
|
77
|
-
const REQUEST_OWNER = '_emilSdkOwner';
|
|
78
|
-
|
|
79
62
|
export function resetRetry() {
|
|
80
63
|
_retry_count = 0
|
|
81
64
|
}
|
|
@@ -94,19 +77,10 @@ interface TokenData {
|
|
|
94
77
|
accessToken?: string;
|
|
95
78
|
username?: string;
|
|
96
79
|
permissions?: string;
|
|
97
|
-
// 'both' or 'session' when authservice keeps the tokens in a server session.
|
|
98
|
-
authMode?: string;
|
|
99
|
-
sub?: string;
|
|
100
80
|
}
|
|
101
81
|
|
|
102
82
|
const NETWORK_ERROR_MESSAGE = "Network Error";
|
|
103
83
|
const TOKEN_DATA = 'APP_TOKEN';
|
|
104
|
-
// Sent only to authservice, to ask for a server session.
|
|
105
|
-
const AUTH_MODE_HEADER = 'X-Emil-Auth-Mode';
|
|
106
|
-
// Names the account on every call; one browser session can hold several.
|
|
107
|
-
const ACCOUNT_HEADER = 'X-Emil-Account';
|
|
108
|
-
const SESSION_MODES = ['both', 'session'];
|
|
109
|
-
const RESEND_SAFE_METHODS = ['get', 'head', 'options'];
|
|
110
84
|
|
|
111
85
|
/**
|
|
112
86
|
*
|
|
@@ -124,31 +98,14 @@ export class BaseAPI {
|
|
|
124
98
|
this.loadTokenData();
|
|
125
99
|
|
|
126
100
|
if (configuration) {
|
|
127
|
-
// Two accounts in one browser share APP_TOKEN: never take the token or session account saved for
|
|
128
|
-
// another account. The mode stays (an app naming its account keeps its session). Saved with the next refresh.
|
|
129
|
-
const ownUser = configuration.username;
|
|
130
|
-
const storedUser = this.tokenData.username;
|
|
131
|
-
if (ownUser && storedUser && ownUser.toLowerCase() !== storedUser.toLowerCase()) {
|
|
132
|
-
delete this.tokenData.accessToken;
|
|
133
|
-
delete this.tokenData.sub;
|
|
134
|
-
this.tokenData.username = ownUser;
|
|
135
|
-
}
|
|
136
101
|
const { accessToken } = this.tokenData;
|
|
137
102
|
this.configuration = configuration;
|
|
138
103
|
this.basePath = configuration.basePath || this.basePath;
|
|
139
104
|
|
|
140
|
-
if
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (this.usesSession()) {
|
|
145
|
-
this.useSessionAuth();
|
|
146
|
-
} else {
|
|
147
|
-
// Use config token if provided, otherwise use tokenData token
|
|
148
|
-
const configToken = this.configuration.accessToken;
|
|
149
|
-
const storedToken = accessToken ? `Bearer ${accessToken}` : '';
|
|
150
|
-
this.configuration.accessToken = configToken || storedToken;
|
|
151
|
-
}
|
|
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;
|
|
152
109
|
} else {
|
|
153
110
|
const { accessToken, username } = this.tokenData;
|
|
154
111
|
|
|
@@ -162,110 +119,6 @@ export class BaseAPI {
|
|
|
162
119
|
this.attachInterceptor(axios);
|
|
163
120
|
}
|
|
164
121
|
|
|
165
|
-
// The app's own account wins over APP_TOKEN, which holds whichever tab wrote last.
|
|
166
|
-
private sessionAccount(): string | undefined {
|
|
167
|
-
return this.configuration.account || this.tokenData.sub;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Apps may pass the address as the second argument only; authservice is on the same host.
|
|
171
|
-
private authBasePath(): string {
|
|
172
|
-
return this.configuration.basePath || this.basePath;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
private usesSession(): boolean {
|
|
176
|
-
return !!this.configuration.cookieAuth && SESSION_MODES.indexOf(this.tokenData.authMode) !== -1 && !!this.sessionAccount();
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
private useSessionAuth() {
|
|
180
|
-
const { headers, ...baseOptions } = this.configuration.baseOptions || {};
|
|
181
|
-
this.configuration.accessToken = '';
|
|
182
|
-
this.configuration.baseOptions = {
|
|
183
|
-
...baseOptions,
|
|
184
|
-
withCredentials: true,
|
|
185
|
-
headers: { ...headers, [ACCOUNT_HEADER]: this.sessionAccount() },
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
private useHeaderAuth(accessToken: string, keepSessionData = false) {
|
|
190
|
-
this.configuration.accessToken = accessToken ? `Bearer ${accessToken}` : '';
|
|
191
|
-
this.tokenData.accessToken = accessToken;
|
|
192
|
-
// An app without cookieAuth does not own the session fields: its refresh leaves them for the session apps.
|
|
193
|
-
if (!keepSessionData || this.configuration.cookieAuth) {
|
|
194
|
-
delete this.tokenData.authMode;
|
|
195
|
-
delete this.tokenData.sub;
|
|
196
|
-
}
|
|
197
|
-
if (this.configuration.cookieAuth) {
|
|
198
|
-
const { withCredentials, headers, ...baseOptions } = this.configuration.baseOptions || {};
|
|
199
|
-
const { [ACCOUNT_HEADER]: account, ...otherHeaders } = headers || {};
|
|
200
|
-
this.configuration.baseOptions = { ...baseOptions, headers: otherHeaders };
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
private applyTokenReply({ accessToken, authMode, session }: LoginClass, fromRefresh = false) {
|
|
205
|
-
if (this.configuration.cookieAuth && SESSION_MODES.indexOf(authMode) !== -1 && session?.sub) {
|
|
206
|
-
this.tokenData.authMode = authMode;
|
|
207
|
-
this.tokenData.sub = session.sub;
|
|
208
|
-
if (this.configuration.account) {
|
|
209
|
-
// A workspace switch moves the app to another account.
|
|
210
|
-
this.configuration.account = session.sub;
|
|
211
|
-
}
|
|
212
|
-
// Both keeps the token for apps not moved yet; session mode keeps no token at all.
|
|
213
|
-
if (authMode === 'both' && accessToken) {
|
|
214
|
-
this.tokenData.accessToken = accessToken;
|
|
215
|
-
} else {
|
|
216
|
-
delete this.tokenData.accessToken;
|
|
217
|
-
}
|
|
218
|
-
this.useSessionAuth();
|
|
219
|
-
} else {
|
|
220
|
-
this.useHeaderAuth(accessToken, fromRefresh);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
private sessionHeaders(): Record<string, string> {
|
|
225
|
-
if (!this.configuration.cookieAuth) {
|
|
226
|
-
return {};
|
|
227
|
-
}
|
|
228
|
-
return {
|
|
229
|
-
[AUTH_MODE_HEADER]: 'session',
|
|
230
|
-
...(this.usesSession() && { [ACCOUNT_HEADER]: this.sessionAccount() }),
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
private withCurrentAuth(config: AxiosRequestConfig): AxiosRequestConfig {
|
|
235
|
-
delete config.headers['Authorization'];
|
|
236
|
-
delete config.headers[ACCOUNT_HEADER];
|
|
237
|
-
if (this.usesSession()) {
|
|
238
|
-
config.headers[ACCOUNT_HEADER] = this.sessionAccount();
|
|
239
|
-
config.withCredentials = true;
|
|
240
|
-
} else if (this.configuration.accessToken) {
|
|
241
|
-
config.headers['Authorization'] = this.configuration.accessToken;
|
|
242
|
-
}
|
|
243
|
-
return config;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// Both keeps the token, so a session call the browser could not complete can be sent again with it.
|
|
247
|
-
private canRetryWithToken(config: AxiosRequestConfig): boolean {
|
|
248
|
-
return !!config.withCredentials && !!config.headers?.[ACCOUNT_HEADER]
|
|
249
|
-
&& !!this.tokenData.accessToken && this.tokenData.authMode !== 'session';
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// A network error can come after the server ran the call, so only a call that is safe to repeat is sent again.
|
|
253
|
-
private canResend(config: AxiosRequestConfig): boolean {
|
|
254
|
-
return RESEND_SAFE_METHODS.indexOf((config.method || 'get').toLowerCase()) !== -1
|
|
255
|
-
|| Object.keys(config.headers || {}).some((name) => name.toLowerCase() === 'idempotency-key');
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
private switchToToken() {
|
|
259
|
-
this.useHeaderAuth(this.tokenData.accessToken);
|
|
260
|
-
this.storeTokenData(this.tokenData);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
private retryWithToken(axios: AxiosInstance, config: AxiosRequestConfig) {
|
|
264
|
-
this.switchToToken();
|
|
265
|
-
config.withCredentials = false;
|
|
266
|
-
return axios(this.withCurrentAuth(config));
|
|
267
|
-
}
|
|
268
|
-
|
|
269
122
|
selectEnvironment(env: Environment) {
|
|
270
123
|
this.selectBasePath(env);
|
|
271
124
|
}
|
|
@@ -285,8 +138,8 @@ export class BaseAPI {
|
|
|
285
138
|
async authorize(username: string, password: string, targetWorkspace?: string): Promise<void> {
|
|
286
139
|
const options: AxiosRequestConfig = {
|
|
287
140
|
method: 'POST',
|
|
288
|
-
url: `${this.
|
|
289
|
-
headers: { 'Content-Type': 'application/json'
|
|
141
|
+
url: `${this.configuration.basePath}/authservice/v1/login`,
|
|
142
|
+
headers: { 'Content-Type': 'application/json' },
|
|
290
143
|
data: {
|
|
291
144
|
username,
|
|
292
145
|
password,
|
|
@@ -296,10 +149,13 @@ export class BaseAPI {
|
|
|
296
149
|
|
|
297
150
|
const response = await globalAxios.request<LoginClass>(options);
|
|
298
151
|
|
|
152
|
+
const { data: { accessToken, permissions } } = response;
|
|
153
|
+
|
|
299
154
|
this.configuration.username = username;
|
|
155
|
+
this.configuration.accessToken = `Bearer ${accessToken}`;
|
|
300
156
|
this.tokenData.username = username;
|
|
301
|
-
this.tokenData.
|
|
302
|
-
this.
|
|
157
|
+
this.tokenData.accessToken = accessToken;
|
|
158
|
+
this.tokenData.permissions = permissions;
|
|
303
159
|
|
|
304
160
|
// Switch workspace if provided
|
|
305
161
|
if (targetWorkspace) {
|
|
@@ -319,11 +175,10 @@ export class BaseAPI {
|
|
|
319
175
|
async switchWorkspace(targetWorkspace: string): Promise<void> {
|
|
320
176
|
const options: AxiosRequestConfig = {
|
|
321
177
|
method: 'POST',
|
|
322
|
-
url: `${this.
|
|
178
|
+
url: `${this.configuration.basePath}/authservice/v1/workspaces/switch`,
|
|
323
179
|
headers: {
|
|
324
180
|
'Content-Type': 'application/json',
|
|
325
|
-
|
|
326
|
-
...(!this.usesSession() && !!this.configuration.accessToken && { 'Authorization': this.configuration.accessToken as string }),
|
|
181
|
+
'Authorization': `Bearer ${this.configuration.accessToken}`,
|
|
327
182
|
},
|
|
328
183
|
data: {
|
|
329
184
|
username: this.configuration.username,
|
|
@@ -334,8 +189,11 @@ export class BaseAPI {
|
|
|
334
189
|
|
|
335
190
|
const response = await globalAxios.request<SwitchWorkspaceResponseClass>(options);
|
|
336
191
|
|
|
337
|
-
|
|
338
|
-
|
|
192
|
+
const { data: { accessToken, permissions } } = response;
|
|
193
|
+
|
|
194
|
+
this.configuration.accessToken = `Bearer ${accessToken}`;
|
|
195
|
+
this.tokenData.accessToken = accessToken;
|
|
196
|
+
this.tokenData.permissions = permissions;
|
|
339
197
|
|
|
340
198
|
this.storeTokenData({
|
|
341
199
|
...this.tokenData
|
|
@@ -351,34 +209,9 @@ export class BaseAPI {
|
|
|
351
209
|
|
|
352
210
|
const refreshTokenAxios = globalAxios.create()
|
|
353
211
|
refreshTokenAxios.interceptors.response.use(response => {
|
|
354
|
-
const { permissions
|
|
355
|
-
|
|
356
|
-
const onSession = this.usesSession();
|
|
357
|
-
|
|
358
|
-
// Newer data saved for this account (e.g. the session mode the shell saved later) wins over the copy
|
|
359
|
-
// read when the object was made; data of another account or another workspace (sub) is never taken.
|
|
360
|
-
const latest = ((typeof window !== 'undefined' && defaultStorage().get<TokenData>(TOKEN_DATA)) || {}) as TokenData;
|
|
361
|
-
const ownSub = this.sessionAccount();
|
|
362
|
-
if (latest.username?.toLowerCase() === username.toLowerCase()
|
|
363
|
-
&& (!ownSub || !latest.sub || latest.sub === ownSub)) {
|
|
364
|
-
// A bare reset ({username}, an app's account check) keeps this copy's other fields; any fuller record
|
|
365
|
-
// is the truth, so fields it lacks were removed on purpose (e.g. a rollback) and stay removed.
|
|
366
|
-
const bareReset = Object.keys(latest).every((key) => key === 'username');
|
|
367
|
-
this.tokenData = bareReset ? { ...this.tokenData, ...latest } : { ...latest };
|
|
368
|
-
}
|
|
369
|
-
// The reply is for this account: label it, or an SDK object of another account would take the token.
|
|
370
|
-
if (this.tokenData.username?.toLowerCase() !== username.toLowerCase()) {
|
|
371
|
-
this.tokenData.username = username;
|
|
372
|
-
}
|
|
212
|
+
const { permissions } = response.data;
|
|
213
|
+
|
|
373
214
|
this.tokenData.permissions = permissions;
|
|
374
|
-
// Keep the new token for the page's next SDK objects; session data is left as it is.
|
|
375
|
-
if (accessToken && !onSession) {
|
|
376
|
-
this.tokenData.accessToken = accessToken;
|
|
377
|
-
this.configuration.accessToken = `Bearer ${accessToken}`;
|
|
378
|
-
} else if (accessToken && authMode === 'both') {
|
|
379
|
-
// Both: this app stays on the session; the token is kept for apps not moved yet.
|
|
380
|
-
this.tokenData.accessToken = accessToken;
|
|
381
|
-
}
|
|
382
215
|
this.storeTokenData(this.tokenData);
|
|
383
216
|
|
|
384
217
|
return response;
|
|
@@ -386,10 +219,9 @@ export class BaseAPI {
|
|
|
386
219
|
|
|
387
220
|
const options: AxiosRequestConfig = {
|
|
388
221
|
method: 'POST',
|
|
389
|
-
url: `${this.
|
|
222
|
+
url: `${this.configuration.basePath}/authservice/v1/refresh-token`,
|
|
390
223
|
headers: {
|
|
391
224
|
'Content-Type': 'application/json',
|
|
392
|
-
...this.sessionHeaders(),
|
|
393
225
|
},
|
|
394
226
|
data: { username: username },
|
|
395
227
|
withCredentials: true,
|
|
@@ -417,18 +249,6 @@ export class BaseAPI {
|
|
|
417
249
|
this.storeTokenData(null);
|
|
418
250
|
}
|
|
419
251
|
|
|
420
|
-
private ownAccount(): string {
|
|
421
|
-
return (this.configuration.username || '').toLowerCase();
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
protected withOwner(options?: AxiosRequestConfig): AxiosRequestConfig {
|
|
425
|
-
// An object without a username cannot refresh itself: its requests stay unmarked, as before.
|
|
426
|
-
if (!this.ownAccount()) {
|
|
427
|
-
return { ...options };
|
|
428
|
-
}
|
|
429
|
-
return { ...options, [REQUEST_OWNER]: this.ownAccount() } as AxiosRequestConfig;
|
|
430
|
-
}
|
|
431
|
-
|
|
432
252
|
private attachInterceptor(axios: AxiosInstance) {
|
|
433
253
|
axios.interceptors.response.use(
|
|
434
254
|
(res) => {
|
|
@@ -436,33 +256,26 @@ export class BaseAPI {
|
|
|
436
256
|
},
|
|
437
257
|
async (err) => {
|
|
438
258
|
let originalConfig = err.config;
|
|
439
|
-
// Sent for another account: only that account's SDK objects handle it. Unmarked requests as before.
|
|
440
|
-
const owner = originalConfig?.[REQUEST_OWNER];
|
|
441
|
-
if (owner !== undefined && owner !== this.ownAccount()) {
|
|
442
|
-
return Promise.reject(err);
|
|
443
|
-
}
|
|
444
259
|
if (err.response && !(err.response instanceof XMLHttpRequest)) { // sometimes buggy and is of type request
|
|
445
260
|
// Access Token was expired
|
|
446
261
|
if ((err.response.status === 401 || err.response.status === 403)
|
|
447
262
|
&& !originalConfig._retry) {
|
|
448
263
|
originalConfig._retry = true;
|
|
449
264
|
try {
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
this.
|
|
453
|
-
this.storeTokenData(this.tokenData);
|
|
265
|
+
const { accessToken: tokenString, permissions } = await this.refreshTokenInternal();
|
|
266
|
+
const accessToken = `Bearer ${tokenString}`;
|
|
267
|
+
this.tokenData.permissions = permissions;
|
|
454
268
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
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);
|
|
458
277
|
|
|
459
|
-
|
|
460
|
-
return axios(this.withCurrentAuth(originalConfig)).catch((retryError) => {
|
|
461
|
-
if (retryError?.response?.status !== 401 || !this.tokenData.accessToken) {
|
|
462
|
-
return Promise.reject(retryError);
|
|
463
|
-
}
|
|
464
|
-
return this.retryWithToken(axios, originalConfig);
|
|
465
|
-
});
|
|
278
|
+
return axios(originalConfig);
|
|
466
279
|
} catch (_error) {
|
|
467
280
|
if (_error.response && _error.response.data) {
|
|
468
281
|
return Promise.reject(_error.response.data);
|
|
@@ -470,35 +283,26 @@ export class BaseAPI {
|
|
|
470
283
|
return Promise.reject(_error);
|
|
471
284
|
}
|
|
472
285
|
}
|
|
473
|
-
} else if (err.message === NETWORK_ERROR_MESSAGE && this.canRetryWithToken(originalConfig)) {
|
|
474
|
-
// Both mode: the browser blocked the session call or hid its reply; later calls use the token.
|
|
475
|
-
if (!this.canResend(originalConfig)) {
|
|
476
|
-
this.switchToToken();
|
|
477
|
-
return Promise.reject(err);
|
|
478
|
-
}
|
|
479
|
-
return this.retryWithToken(axios, originalConfig);
|
|
480
286
|
} else if (err.message === NETWORK_ERROR_MESSAGE
|
|
481
|
-
&&
|
|
482
|
-
|| (this.configuration.cookieAuth && originalConfig.withCredentials && this.canResend(originalConfig)))
|
|
287
|
+
&& originalConfig.headers.hasOwnProperty('Authorization')
|
|
483
288
|
&& _retry_count < 4
|
|
484
289
|
) {
|
|
485
290
|
_retry_count++;
|
|
486
291
|
try {
|
|
487
|
-
|
|
488
|
-
const
|
|
489
|
-
this.tokenData.permissions =
|
|
292
|
+
const { accessToken: tokenString, permissions } = await this.refreshTokenInternal();
|
|
293
|
+
const accessToken = `Bearer ${tokenString}`;
|
|
294
|
+
this.tokenData.permissions = permissions;
|
|
490
295
|
|
|
491
296
|
_retry = true;
|
|
492
|
-
|
|
297
|
+
originalConfig.headers['Authorization'] = accessToken;
|
|
298
|
+
|
|
299
|
+
this.configuration.accessToken = accessToken;
|
|
300
|
+
this.tokenData.accessToken = tokenString;
|
|
301
|
+
|
|
493
302
|
this.storeTokenData(this.tokenData);
|
|
494
303
|
|
|
495
|
-
// The limit is for refreshes that do not help; one that worked starts the count again.
|
|
496
|
-
// Not awaited, so a failed retry reaches the app as the same axios error as before.
|
|
497
304
|
return axios.request({
|
|
498
|
-
...
|
|
499
|
-
}).then((retried) => {
|
|
500
|
-
_retry_count = 0;
|
|
501
|
-
return retried;
|
|
305
|
+
...originalConfig,
|
|
502
306
|
});
|
|
503
307
|
} catch (_error) {
|
|
504
308
|
if (_error.response && _error.response.data) {
|
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));
|
|
@@ -101,5 +101,5 @@ export declare class BookingFunnelsApi extends BaseAPI {
|
|
|
101
101
|
* @throws {RequiredError}
|
|
102
102
|
* @memberof BookingFunnelsApi
|
|
103
103
|
*/
|
|
104
|
-
getBookingFunnel(requestParameters: BookingFunnelsApiGetBookingFunnelRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<GetBookingFunnelResponseClass, any, {}
|
|
104
|
+
getBookingFunnel(requestParameters: BookingFunnelsApiGetBookingFunnelRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<GetBookingFunnelResponseClass, any, {}>>;
|
|
105
105
|
}
|
|
@@ -104,10 +104,9 @@ var BookingFunnelsApiAxiosParamCreator = function (configuration) {
|
|
|
104
104
|
getBookingFunnel: function (code, authorization, language, options) {
|
|
105
105
|
if (options === void 0) { options = {}; }
|
|
106
106
|
return __awaiter(_this, void 0, void 0, function () {
|
|
107
|
-
var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
switch (_b.label) {
|
|
107
|
+
var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, headersFromBaseOptions;
|
|
108
|
+
return __generator(this, function (_a) {
|
|
109
|
+
switch (_a.label) {
|
|
111
110
|
case 0:
|
|
112
111
|
// verify required parameter 'code' is not null or undefined
|
|
113
112
|
(0, common_1.assertParamExists)('getBookingFunnel', 'code', code);
|
|
@@ -127,15 +126,12 @@ var BookingFunnelsApiAxiosParamCreator = function (configuration) {
|
|
|
127
126
|
case 1:
|
|
128
127
|
// authentication bearer required
|
|
129
128
|
// http bearer authentication required
|
|
130
|
-
|
|
129
|
+
_a.sent();
|
|
131
130
|
if (language !== undefined) {
|
|
132
131
|
localVarQueryParameter['language'] = language;
|
|
133
132
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
authorizationKeepEmpty = authorizationIsAuth && authorizationValue === '' && !((_a = baseOptions === null || baseOptions === void 0 ? void 0 : baseOptions.headers) === null || _a === void 0 ? void 0 : _a['X-Emil-Account']);
|
|
137
|
-
if (authorizationValue || authorizationKeepEmpty) {
|
|
138
|
-
localVarHeaderParameter['Authorization'] = String(authorizationValue);
|
|
133
|
+
if (authorization !== undefined && authorization !== null || baseAccessToken !== undefined && baseAccessToken !== null) {
|
|
134
|
+
localVarHeaderParameter['Authorization'] = String(authorization ? authorization : baseAccessToken);
|
|
139
135
|
}
|
|
140
136
|
(0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter);
|
|
141
137
|
headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
@@ -226,7 +222,7 @@ var BookingFunnelsApi = /** @class */ (function (_super) {
|
|
|
226
222
|
*/
|
|
227
223
|
BookingFunnelsApi.prototype.getBookingFunnel = function (requestParameters, options) {
|
|
228
224
|
var _this = this;
|
|
229
|
-
return (0, exports.BookingFunnelsApiFp)(this.configuration).getBookingFunnel(requestParameters.code, requestParameters.authorization, requestParameters.language,
|
|
225
|
+
return (0, exports.BookingFunnelsApiFp)(this.configuration).getBookingFunnel(requestParameters.code, requestParameters.authorization, requestParameters.language, options).then(function (request) { return request(_this.axios, _this.basePath); });
|
|
230
226
|
};
|
|
231
227
|
return BookingFunnelsApi;
|
|
232
228
|
}(base_1.BaseAPI));
|