@or-sdk/auth 0.25.0-beta.631.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/Auth.js CHANGED
@@ -1,3 +1,12 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import axios from 'axios';
2
11
  import { Settings } from '@or-sdk/settings';
3
12
  import { SdkApi } from '@or-sdk/sdk-api';
@@ -9,27 +18,12 @@ const defaultCookiePollingInterval = 500;
9
18
  const defaultExpireInShort = 3600000;
10
19
  const defaultExpireInLong = 30758400000;
11
20
  export class Auth {
12
- discoveryUrl;
13
- sdkUrl;
14
- cookieDomain;
15
- cookie;
16
- userCookieName;
17
- allowGuestLogin;
18
- allowIframe;
19
- deprecatedCookieName;
20
- deprecatedUserExpireCookieName;
21
- deprecatedDomain;
22
- multiUserCookieName;
23
- userExpireCookieName;
24
- cookiePollingInterval;
25
- expireInShort;
26
- expireInLong;
27
- loggedIn = false;
28
- monitorCookieTimeout;
29
21
  constructor(params) {
30
- const { discoveryUrl, sdkUrl, cookieDomain, allowGuestLogin, userCookieName, userExpireCookieName, cookiePrefix, multiUserCookieName, cookiePollingInterval, expireInShort, expireInLong, allowIframe, } = params;
22
+ this.loggedIn = false;
23
+ const { discoveryUrl, sdkUrl, cookieDomain, allowGuestLogin, userCookieName, userExpireCookieName, cookiePrefix, multiUserCookieName, cookiePollingInterval, expireInShort, expireInLong, allowIframe, authUiUrl, } = params;
31
24
  this.discoveryUrl = discoveryUrl;
32
25
  this.sdkUrl = sdkUrl;
26
+ this.authUiUrl = authUiUrl;
33
27
  this.cookie = new Cookie();
34
28
  this.cookieDomain = cookieDomain;
35
29
  this.allowGuestLogin = Boolean(allowGuestLogin);
@@ -85,38 +79,13 @@ export class Auth {
85
79
  }
86
80
  _saveCookies(user, expireIn) {
87
81
  const nextExpiration = this._getNextExpiration(expireIn);
88
- this.cookie.set(this.userCookieName, user, {
89
- path: '/',
90
- expires: nextExpiration,
91
- secure: true,
92
- sameSite: this.allowIframe ? 'none' : 'lax',
93
- ...this.domain,
94
- });
95
- this.cookie.set(this.userExpireCookieName, expireIn, {
96
- path: '/',
97
- expires: nextExpiration,
98
- secure: true,
99
- sameSite: this.allowIframe ? 'none' : 'lax',
100
- ...this.domain,
101
- });
102
- this.cookie.set(this.deprecatedCookieName, user, {
103
- path: '/',
104
- expires: nextExpiration,
105
- ...this.domain,
106
- });
107
- this.cookie.set(this.deprecatedUserExpireCookieName, expireIn, {
108
- path: '/',
109
- expires: nextExpiration,
110
- ...this.domain,
111
- });
82
+ this.cookie.set(this.userCookieName, user, Object.assign({ path: '/', expires: nextExpiration, secure: true, sameSite: this.allowIframe ? 'none' : 'lax' }, this.domain));
83
+ this.cookie.set(this.userExpireCookieName, expireIn, Object.assign({ path: '/', expires: nextExpiration, secure: true, sameSite: this.allowIframe ? 'none' : 'lax' }, this.domain));
84
+ this.cookie.set(this.deprecatedCookieName, user, Object.assign({ path: '/', expires: nextExpiration }, this.domain));
85
+ this.cookie.set(this.deprecatedUserExpireCookieName, expireIn, Object.assign({ path: '/', expires: nextExpiration }, this.domain));
112
86
  }
113
87
  saveMultiUser(user, expiration) {
114
- this.cookie.set(this.multiUserCookieName, user, {
115
- path: '/',
116
- expires: this._getNextExpiration(expiration),
117
- secure: true,
118
- ...this.domain,
119
- });
88
+ this.cookie.set(this.multiUserCookieName, user, Object.assign({ path: '/', expires: this._getNextExpiration(expiration), secure: true }, this.domain));
120
89
  }
121
90
  updateCookieExpiration() {
122
91
  const user = this._getUser;
@@ -134,356 +103,352 @@ export class Auth {
134
103
  throw new NoRightsError('Authorization for guests is not allowed');
135
104
  }
136
105
  }
137
- async saveUser({ long, user }) {
138
- const key = long ? 'cookieExpirationLong' : 'cookieExpirationShort';
139
- const settingsApi = new Settings({
140
- token: user.token,
141
- discoveryUrl: this.discoveryUrl,
142
- sdkUrl: this.sdkUrl,
106
+ saveUser({ long, user }) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ const key = long ? 'cookieExpirationLong' : 'cookieExpirationShort';
109
+ const settingsApi = new Settings({
110
+ token: user.token,
111
+ discoveryUrl: this.discoveryUrl,
112
+ sdkUrl: this.sdkUrl,
113
+ });
114
+ let cookieExpirationDuration;
115
+ try {
116
+ cookieExpirationDuration = yield settingsApi.getMergedSettings({ key });
117
+ }
118
+ catch (error) {
119
+ console.log('Unable to fetch settingCookiesExpire from user Settings: ', error);
120
+ }
121
+ if (!cookieExpirationDuration) {
122
+ cookieExpirationDuration = long ? this.expireInLong : this.expireInShort;
123
+ }
124
+ this._saveCookies(user, cookieExpirationDuration);
143
125
  });
144
- let cookieExpirationDuration;
145
- try {
146
- cookieExpirationDuration = await settingsApi.getMergedSettings({ key });
147
- }
148
- catch (error) {
149
- console.log('Unable to fetch settingCookiesExpire from user Settings: ', error);
150
- }
151
- if (!cookieExpirationDuration) {
152
- cookieExpirationDuration = long ? this.expireInLong : this.expireInShort;
153
- }
154
- this._saveCookies(user, cookieExpirationDuration);
155
126
  }
156
- async signIn({ credentials, long, allowGuestLogin = false, captchaToken, isCaptchaV2Checkbox, verificationCode, userToken, rememberTwoFactor, }) {
157
- const fingerPrint = await generateFingerPrint();
158
- const options = {
159
- ...credentials,
160
- captchaToken,
161
- isCaptchaV2Checkbox,
162
- verificationCode,
163
- fingerPrint,
164
- rememberTwoFactor,
165
- ...userToken ? { userToken } : {},
166
- };
167
- const sdkApi = new SdkApi({
168
- token: '',
169
- discoveryUrl: this.discoveryUrl,
170
- sdkUrl: this.sdkUrl,
171
- });
172
- const user = await sdkApi.makeRequest({
173
- method: 'POST',
174
- route: '/auth/token',
175
- data: options,
176
- });
177
- this._validateGuest(user.role, allowGuestLogin);
178
- if (!user.twoFactorCheck && !user.captchaCheck) {
179
- if (user.tokenType === 'multi-user') {
180
- this.saveMultiUser(user, long ? this.expireInLong : this.expireInShort);
181
- }
182
- else {
183
- await this.saveUser({
184
- long,
185
- user,
186
- });
127
+ signIn({ credentials, long, allowGuestLogin = false, captchaToken, isCaptchaV2Checkbox, verificationCode, userToken, rememberTwoFactor, }) {
128
+ return __awaiter(this, void 0, void 0, function* () {
129
+ const fingerPrint = yield generateFingerPrint();
130
+ const options = Object.assign(Object.assign(Object.assign({}, credentials), { captchaToken,
131
+ isCaptchaV2Checkbox,
132
+ verificationCode,
133
+ fingerPrint,
134
+ rememberTwoFactor }), userToken ? { userToken } : {});
135
+ const sdkApi = new SdkApi({
136
+ token: '',
137
+ discoveryUrl: this.discoveryUrl,
138
+ sdkUrl: this.sdkUrl,
139
+ });
140
+ const user = yield sdkApi.makeRequest({
141
+ method: 'POST',
142
+ route: '/auth/token',
143
+ data: options,
144
+ });
145
+ this._validateGuest(user.role, allowGuestLogin);
146
+ if (!user.twoFactorCheck && !user.captchaCheck) {
147
+ if (user.tokenType === 'multi-user') {
148
+ this.saveMultiUser(user, long ? this.expireInLong : this.expireInShort);
149
+ }
150
+ else {
151
+ yield this.saveUser({
152
+ long,
153
+ user,
154
+ });
155
+ }
187
156
  }
188
- }
189
- return user;
157
+ return user;
158
+ });
190
159
  }
191
160
  _checkDeprecatedCookies() {
192
161
  const user = this.cookie.get(this.deprecatedCookieName);
193
162
  if (user) {
194
163
  const deprecatedUserExpireValue = this.getUserExpire(this.deprecatedUserExpireCookieName);
195
164
  const nextExpiration = this._getNextExpiration(deprecatedUserExpireValue);
196
- this.cookie.set(this.userCookieName, user, {
197
- path: '/',
198
- expires: nextExpiration,
199
- secure: true,
200
- ...this.domain,
201
- });
202
- this.cookie.set(this.userExpireCookieName, deprecatedUserExpireValue, {
203
- path: '/',
204
- expires: nextExpiration,
205
- secure: true,
206
- ...this.domain,
207
- });
165
+ this.cookie.set(this.userCookieName, user, Object.assign({ path: '/', expires: nextExpiration, secure: true }, this.domain));
166
+ this.cookie.set(this.userExpireCookieName, deprecatedUserExpireValue, Object.assign({ path: '/', expires: nextExpiration, secure: true }, this.domain));
208
167
  }
209
168
  }
210
- async _validateToken(token, allowGuestLogin = false) {
211
- const sdkApi = new SdkApi({
212
- token,
213
- discoveryUrl: this.discoveryUrl,
214
- sdkUrl: this.sdkUrl,
215
- });
216
- const user = await sdkApi.makeRequest({
217
- method: 'GET',
218
- route: '/auth/token',
169
+ _validateToken(token, allowGuestLogin = false) {
170
+ return __awaiter(this, void 0, void 0, function* () {
171
+ const sdkApi = new SdkApi({
172
+ token,
173
+ discoveryUrl: this.discoveryUrl,
174
+ sdkUrl: this.sdkUrl,
175
+ });
176
+ const user = yield sdkApi.makeRequest({
177
+ method: 'GET',
178
+ route: '/auth/token',
179
+ });
180
+ this._validateGuest(user.role, allowGuestLogin);
181
+ return user;
219
182
  });
220
- this._validateGuest(user.role, allowGuestLogin);
221
- return user;
222
183
  }
223
- async signInWithToken(token, allowGuestLogin = false, shouldNotSaveCookies = false) {
224
- let userInfo = {};
225
- if (_.isObject(token)) {
226
- allowGuestLogin = _.get(token, 'allowGuestLogin', false);
227
- shouldNotSaveCookies = _.get(token, 'shouldNotSaveCookies', false);
228
- userInfo = _.get(token, 'userInfo', {});
229
- token = token.token;
230
- }
231
- if (!token) {
232
- return Promise.reject(new Error('No token given'));
233
- }
234
- this._checkDeprecatedCookies();
235
- const user = await this._validateToken(token, allowGuestLogin);
236
- _.assign(user, { token });
237
- const allow = _.get(user, 'allow', false);
238
- if (!allow) {
239
- throw Error('Invalid Token');
240
- }
241
- if (!shouldNotSaveCookies) {
242
- this._saveCookies({
243
- ...userInfo,
244
- ...user,
245
- }, this.getUserExpire());
246
- }
247
- return user;
184
+ signInWithToken(token, allowGuestLogin = false, shouldNotSaveCookies = false) {
185
+ return __awaiter(this, void 0, void 0, function* () {
186
+ let userInfo = {};
187
+ if (_.isObject(token)) {
188
+ allowGuestLogin = _.get(token, 'allowGuestLogin', false);
189
+ shouldNotSaveCookies = _.get(token, 'shouldNotSaveCookies', false);
190
+ userInfo = _.get(token, 'userInfo', {});
191
+ token = token.token;
192
+ }
193
+ if (!token) {
194
+ return Promise.reject(new Error('No token given'));
195
+ }
196
+ this._checkDeprecatedCookies();
197
+ const user = yield this._validateToken(token, allowGuestLogin);
198
+ _.assign(user, { token });
199
+ const allow = _.get(user, 'allow', false);
200
+ if (!allow) {
201
+ throw Error('Invalid Token');
202
+ }
203
+ if (!shouldNotSaveCookies) {
204
+ this._saveCookies(Object.assign(Object.assign({}, userInfo), user), this.getUserExpire());
205
+ }
206
+ return user;
207
+ });
248
208
  }
249
209
  get multiUserHeaders() {
250
210
  const { token = '' } = this.cookie.get(this.multiUserCookieName) || {};
251
211
  return { headers: { Authorization: token } };
252
212
  }
253
213
  removeCookies() {
254
- this.cookie.remove(this.userExpireCookieName, {
255
- path: '/',
256
- ...this.domain,
257
- });
258
- this.cookie.remove(this.userCookieName, {
259
- path: '/',
260
- ...this.domain,
261
- });
262
- this.cookie.remove(this.multiUserCookieName, {
263
- path: '/',
264
- ...this.domain,
265
- });
266
- this.cookie.remove(this.deprecatedCookieName, {
267
- path: '/',
268
- ...this.domain,
269
- });
270
- this.cookie.remove(this.deprecatedUserExpireCookieName, {
271
- path: '/',
272
- ...this.domain,
273
- });
274
- this.cookie.remove(this.deprecatedCookieName, {
275
- path: '/',
276
- ...this.domain,
277
- });
278
- this.cookie.remove(this.deprecatedUserExpireCookieName, {
279
- path: '/',
280
- ...this.domain,
281
- });
214
+ this.cookie.remove(this.userExpireCookieName, Object.assign({ path: '/' }, this.domain));
215
+ this.cookie.remove(this.userCookieName, Object.assign({ path: '/' }, this.domain));
216
+ this.cookie.remove(this.multiUserCookieName, Object.assign({ path: '/' }, this.domain));
217
+ this.cookie.remove(this.deprecatedCookieName, Object.assign({ path: '/' }, this.domain));
218
+ this.cookie.remove(this.deprecatedUserExpireCookieName, Object.assign({ path: '/' }, this.domain));
219
+ this.cookie.remove(this.deprecatedCookieName, Object.assign({ path: '/' }, this.domain));
220
+ this.cookie.remove(this.deprecatedUserExpireCookieName, Object.assign({ path: '/' }, this.domain));
282
221
  }
283
- async signOut(token) {
284
- try {
285
- const promises = [];
286
- if (token) {
287
- const sdkApi = new SdkApi({
288
- token,
289
- discoveryUrl: this.discoveryUrl,
290
- sdkUrl: this.sdkUrl,
291
- });
292
- promises.push(sdkApi.makeRequest({
293
- method: 'DELETE',
294
- route: '/auth/fingerprint-token',
295
- }));
222
+ signOut(token) {
223
+ return __awaiter(this, void 0, void 0, function* () {
224
+ try {
225
+ const promises = [];
226
+ if (token) {
227
+ const sdkApi = new SdkApi({
228
+ token,
229
+ discoveryUrl: this.discoveryUrl,
230
+ sdkUrl: this.sdkUrl,
231
+ });
232
+ promises.push(sdkApi.makeRequest({
233
+ method: 'DELETE',
234
+ route: '/auth/fingerprint-token',
235
+ }));
236
+ }
237
+ if (this.multiUserHeaders.headers.Authorization) {
238
+ const sdkApi = new SdkApi({
239
+ token: this.multiUserHeaders.headers.Authorization,
240
+ discoveryUrl: this.discoveryUrl,
241
+ sdkUrl: this.sdkUrl,
242
+ });
243
+ promises.push(sdkApi.makeRequest({
244
+ method: 'DELETE',
245
+ route: '/multi-user/fingerprint-token',
246
+ }));
247
+ }
248
+ yield Promise.all(promises);
296
249
  }
297
- if (this.multiUserHeaders.headers.Authorization) {
298
- const sdkApi = new SdkApi({
299
- token: this.multiUserHeaders.headers.Authorization,
300
- discoveryUrl: this.discoveryUrl,
301
- sdkUrl: this.sdkUrl,
302
- });
303
- promises.push(sdkApi.makeRequest({
304
- method: 'DELETE',
305
- route: '/multi-user/fingerprint-token',
306
- }));
250
+ catch (error) {
251
+ console.log('Logout failed: ', error);
307
252
  }
308
- await Promise.all(promises);
309
- }
310
- catch (error) {
311
- console.log('Logout failed: ', error);
312
- }
313
- this.removeCookies();
253
+ this.removeCookies();
254
+ });
314
255
  }
315
- async validateUser(allowGuestLogin = false) {
316
- this._checkDeprecatedCookies();
317
- const userParams = this._getUser;
318
- if (!userParams) {
319
- return Promise.reject(new Error('No cached user params are available'));
320
- }
321
- const user = await this._validateToken(userParams.token, allowGuestLogin);
322
- if (!user.identityProvider && userParams.identityProvider) {
323
- user.identityProvider = userParams.identityProvider;
324
- }
325
- _.assign(user, { token: userParams.token });
326
- const allow = _.get(user, 'allow', false);
327
- if (!allow) {
328
- throw Error('Invalid Token');
329
- }
330
- return user;
256
+ validateUser(allowGuestLogin = false, shouldNotSaveCookies = false) {
257
+ return __awaiter(this, void 0, void 0, function* () {
258
+ this._checkDeprecatedCookies();
259
+ const userParams = this._getUser;
260
+ if (!userParams) {
261
+ return Promise.reject(new Error('No cached user params are available'));
262
+ }
263
+ const user = yield this._validateToken(userParams.token, allowGuestLogin);
264
+ if (!user.identityProvider && userParams.identityProvider) {
265
+ user.identityProvider = userParams.identityProvider;
266
+ }
267
+ _.assign(user, { token: userParams.token });
268
+ const allow = _.get(user, 'allow', false);
269
+ if (!allow) {
270
+ throw Error('Invalid Token');
271
+ }
272
+ if (shouldNotSaveCookies)
273
+ return user;
274
+ const _user = Object.assign(Object.assign({}, userParams), { role: user.role, twoFactorenabled: user.twoFactorEnabled });
275
+ this._saveCookies(_user, this.getUserExpire());
276
+ return user;
277
+ });
331
278
  }
332
279
  hasUserParams() {
333
280
  return Boolean(this._getUser);
334
281
  }
335
- async multiUserGetUsersList() {
336
- if (!this.multiUserHeaders.headers.Authorization)
337
- return false;
338
- const sdkApi = new SdkApi({
339
- token: this.multiUserHeaders.headers.Authorization,
340
- discoveryUrl: this.discoveryUrl,
341
- sdkUrl: this.sdkUrl,
342
- });
343
- return sdkApi.makeRequest({
344
- method: 'GET',
345
- route: '/multi-user/list-users',
282
+ multiUserGetUsersList() {
283
+ return __awaiter(this, void 0, void 0, function* () {
284
+ if (!this.multiUserHeaders.headers.Authorization)
285
+ return false;
286
+ const sdkApi = new SdkApi({
287
+ token: this.multiUserHeaders.headers.Authorization,
288
+ discoveryUrl: this.discoveryUrl,
289
+ sdkUrl: this.sdkUrl,
290
+ });
291
+ return sdkApi.makeRequest({
292
+ method: 'GET',
293
+ route: '/multi-user/list-users',
294
+ });
346
295
  });
347
296
  }
348
- async multiUserLoginUser({ accountId, id, long }) {
349
- const sdkApi = new SdkApi({
350
- token: this.multiUserHeaders.headers.Authorization,
351
- discoveryUrl: this.discoveryUrl,
352
- sdkUrl: this.sdkUrl,
353
- });
354
- const user = await sdkApi.makeRequest({
355
- method: 'POST',
356
- route: '/multi-user/user-token',
357
- data: {
358
- accountId,
359
- id,
360
- },
297
+ multiUserLoginUser({ accountId, id, long }) {
298
+ return __awaiter(this, void 0, void 0, function* () {
299
+ const sdkApi = new SdkApi({
300
+ token: this.multiUserHeaders.headers.Authorization,
301
+ discoveryUrl: this.discoveryUrl,
302
+ sdkUrl: this.sdkUrl,
303
+ });
304
+ const user = yield sdkApi.makeRequest({
305
+ method: 'POST',
306
+ route: '/multi-user/user-token',
307
+ data: {
308
+ accountId,
309
+ id,
310
+ },
311
+ });
312
+ yield this.saveUser({
313
+ long,
314
+ user,
315
+ });
316
+ return user;
361
317
  });
362
- await this.saveUser({
363
- long,
364
- user,
318
+ }
319
+ getUserNameForLockScreen(user) {
320
+ return __awaiter(this, void 0, void 0, function* () {
321
+ const multiUserCookie = this.cookie.get(this.multiUserCookieName) || {};
322
+ if (multiUserCookie.username)
323
+ return multiUserCookie.username;
324
+ const { multiUserId, username, token } = user;
325
+ if (multiUserId) {
326
+ const sdkApi = new SdkApi({
327
+ token: token,
328
+ discoveryUrl: this.discoveryUrl,
329
+ sdkUrl: this.sdkUrl,
330
+ });
331
+ const { username } = yield sdkApi.makeRequest({
332
+ method: 'GET',
333
+ route: '/user/multi-user',
334
+ });
335
+ return username;
336
+ }
337
+ return username;
365
338
  });
366
- return user;
367
339
  }
368
- async getUserNameForLockScreen(user) {
369
- const multiUserCookie = this.cookie.get(this.multiUserCookieName) || {};
370
- if (multiUserCookie.username)
371
- return multiUserCookie.username;
372
- const { multiUserId, username, token } = user;
373
- if (multiUserId) {
340
+ multiUserGetProfile() {
341
+ return __awaiter(this, void 0, void 0, function* () {
374
342
  const sdkApi = new SdkApi({
375
- token: token,
343
+ token: this.multiUserHeaders.headers.Authorization,
376
344
  discoveryUrl: this.discoveryUrl,
377
345
  sdkUrl: this.sdkUrl,
378
346
  });
379
- const { username } = await sdkApi.makeRequest({
347
+ return sdkApi.makeRequest({
380
348
  method: 'GET',
381
- route: '/user/multi-user',
349
+ route: '/multi-user/profile',
382
350
  });
383
- return username;
384
- }
385
- return username;
386
- }
387
- async multiUserGetProfile() {
388
- const sdkApi = new SdkApi({
389
- token: this.multiUserHeaders.headers.Authorization,
390
- discoveryUrl: this.discoveryUrl,
391
- sdkUrl: this.sdkUrl,
392
- });
393
- return sdkApi.makeRequest({
394
- method: 'GET',
395
- route: '/multi-user/profile',
396
351
  });
397
352
  }
398
- async multiUserSetProfile(profile) {
399
- const sdkApi = new SdkApi({
400
- token: this.multiUserHeaders.headers.Authorization,
401
- discoveryUrl: this.discoveryUrl,
402
- sdkUrl: this.sdkUrl,
403
- });
404
- return sdkApi.makeRequest({
405
- method: 'POST',
406
- route: '/multi-user/profile',
407
- data: profile,
353
+ multiUserSetProfile(profile) {
354
+ return __awaiter(this, void 0, void 0, function* () {
355
+ const sdkApi = new SdkApi({
356
+ token: this.multiUserHeaders.headers.Authorization,
357
+ discoveryUrl: this.discoveryUrl,
358
+ sdkUrl: this.sdkUrl,
359
+ });
360
+ return sdkApi.makeRequest({
361
+ method: 'POST',
362
+ route: '/multi-user/profile',
363
+ data: profile,
364
+ });
408
365
  });
409
366
  }
410
- async validateMultiUserToken() {
411
- const sdkApi = new SdkApi({
412
- token: this.multiUserHeaders.headers.Authorization,
413
- discoveryUrl: this.discoveryUrl,
414
- sdkUrl: this.sdkUrl,
415
- });
416
- return sdkApi.makeRequest({
417
- method: 'GET',
418
- route: '/multi-user/token',
367
+ validateMultiUserToken() {
368
+ return __awaiter(this, void 0, void 0, function* () {
369
+ const sdkApi = new SdkApi({
370
+ token: this.multiUserHeaders.headers.Authorization,
371
+ discoveryUrl: this.discoveryUrl,
372
+ sdkUrl: this.sdkUrl,
373
+ });
374
+ return sdkApi.makeRequest({
375
+ method: 'GET',
376
+ route: '/multi-user/token',
377
+ });
419
378
  });
420
379
  }
421
- async multiUserUploadIcon({ name, contentType, cacheControl = 'no-cache', file }) {
422
- const sdkApi = new SdkApi({
423
- token: this.multiUserHeaders.headers.Authorization,
424
- discoveryUrl: this.discoveryUrl,
425
- sdkUrl: this.sdkUrl,
426
- });
427
- const data = await sdkApi.makeRequest({
428
- method: 'POST',
429
- route: '/multi-user/sign-upload-url',
430
- data: {
431
- name,
432
- contentType,
433
- cacheControl,
434
- },
435
- });
436
- const FormDataLib = isNode ? require('form-data') : FormData;
437
- const formData = new FormDataLib();
438
- _.forEach(data.uploadParams.fields, (value, key) => {
439
- formData.append(key, value);
440
- });
441
- formData.append('cache-control', cacheControl);
442
- formData.append('content-type', contentType);
443
- formData.append('File', file, name);
444
- if (isNode) {
445
- await new Promise((resolve, reject) => {
446
- formData.submit(data.uploadParams.url, (error) => {
447
- if (error)
448
- return reject(error);
449
- resolve();
450
- });
380
+ multiUserUploadIcon({ name, contentType, cacheControl = 'no-cache', file }) {
381
+ return __awaiter(this, void 0, void 0, function* () {
382
+ const sdkApi = new SdkApi({
383
+ token: this.multiUserHeaders.headers.Authorization,
384
+ discoveryUrl: this.discoveryUrl,
385
+ sdkUrl: this.sdkUrl,
451
386
  });
452
- }
453
- else {
454
- await axios.post(data.uploadParams.url, formData);
455
- }
456
- return data.downloadUrl;
457
- }
458
- async confirmEmailChange({ token }) {
459
- const sdkApi = new SdkApi({
460
- token: '',
461
- discoveryUrl: this.discoveryUrl,
462
- sdkUrl: this.sdkUrl,
463
- });
464
- return sdkApi.makeRequest({
465
- method: 'POST',
466
- route: '/multi-user/change-email-finish',
467
- data: {
468
- token,
469
- },
387
+ const data = yield sdkApi.makeRequest({
388
+ method: 'POST',
389
+ route: '/multi-user/sign-upload-url',
390
+ data: {
391
+ name,
392
+ contentType,
393
+ cacheControl,
394
+ },
395
+ });
396
+ const FormDataLib = isNode ? require('form-data') : FormData;
397
+ const formData = new FormDataLib();
398
+ _.forEach(data.uploadParams.fields, (value, key) => {
399
+ formData.append(key, value);
400
+ });
401
+ formData.append('cache-control', cacheControl);
402
+ formData.append('content-type', contentType);
403
+ formData.append('File', file, name);
404
+ if (isNode) {
405
+ yield new Promise((resolve, reject) => {
406
+ formData.submit(data.uploadParams.url, (error) => {
407
+ if (error)
408
+ return reject(error);
409
+ resolve();
410
+ });
411
+ });
412
+ }
413
+ else {
414
+ yield axios.post(data.uploadParams.url, formData);
415
+ }
416
+ return data.downloadUrl;
470
417
  });
471
418
  }
472
- async multiUserUpdateTwoFactor({ secret, enabled, codes, verificationCode }) {
473
- const sdkApi = new SdkApi({
474
- token: this.multiUserHeaders.headers.Authorization,
475
- discoveryUrl: this.discoveryUrl,
476
- sdkUrl: this.sdkUrl,
419
+ confirmEmailChange({ token }) {
420
+ return __awaiter(this, void 0, void 0, function* () {
421
+ const sdkApi = new SdkApi({
422
+ token: '',
423
+ discoveryUrl: this.discoveryUrl,
424
+ sdkUrl: this.sdkUrl,
425
+ });
426
+ return sdkApi.makeRequest({
427
+ method: 'POST',
428
+ route: '/multi-user/change-email-finish',
429
+ data: {
430
+ token,
431
+ },
432
+ });
477
433
  });
478
- return sdkApi.makeRequest({
479
- method: 'POST',
480
- route: '/multi-user/twofactor',
481
- data: {
482
- secret,
483
- enabled,
484
- codes,
485
- verificationCode,
486
- },
434
+ }
435
+ multiUserUpdateTwoFactor({ secret, enabled, codes, verificationCode }) {
436
+ return __awaiter(this, void 0, void 0, function* () {
437
+ const sdkApi = new SdkApi({
438
+ token: this.multiUserHeaders.headers.Authorization,
439
+ discoveryUrl: this.discoveryUrl,
440
+ sdkUrl: this.sdkUrl,
441
+ });
442
+ return sdkApi.makeRequest({
443
+ method: 'POST',
444
+ route: '/multi-user/twofactor',
445
+ data: {
446
+ secret,
447
+ enabled,
448
+ codes,
449
+ verificationCode,
450
+ },
451
+ });
487
452
  });
488
453
  }
489
454
  }