@formant/data-sdk 1.78.0 → 1.78.2

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.
@@ -228,32 +228,32 @@ class AuthenticationStore {
228
228
  };
229
229
  }
230
230
  }
231
- async loginWithToken(t, n) {
232
- var o;
233
- const r = JSON.parse(base64Exports.decode(t.split(".")[1]));
231
+ async loginWithToken(t, n, r = !1) {
232
+ var s;
233
+ const o = JSON.parse(base64Exports.decode(t.split(".")[1]));
234
234
  try {
235
- let s;
236
- if (this._isShareToken = r["formant:claims"] && r["formant:claims"].type == "share", r["formant:claims"] && (this._currentOrganization = r["formant:claims"].organizationId), r["custom:organization_id"] && (this._currentOrganization = r["custom:organization_id"]), this._isShareToken || (s = r.sub), r["formant:claims"] && r["formant:claims"].userId && (s = r["formant:claims"].userId), s && ((o = this._currentUser) == null ? void 0 : o.id) !== s) {
237
- const g = await fetch(`${this._apiUrl}/v1/admin/users/${s}`, {
235
+ let g;
236
+ if (this._isShareToken = o["formant:claims"] && o["formant:claims"].type == "share", o["formant:claims"] && (this._currentOrganization = o["formant:claims"].organizationId), o["custom:organization_id"] && (this._currentOrganization = o["custom:organization_id"]), this._isShareToken || (g = o.sub), o["formant:claims"] && o["formant:claims"].userId && (g = o["formant:claims"].userId), g && ((s = this._currentUser) == null ? void 0 : s.id) !== g && !r) {
237
+ const l = await fetch(`${this._apiUrl}/v1/admin/users/${g}`, {
238
238
  method: "GET",
239
239
  headers: {
240
240
  "Content-Type": "application/json",
241
241
  Authorization: "Bearer " + t
242
242
  }
243
- }), l = await g.json();
244
- if (g.status !== 200)
245
- throw new Error(l.message);
246
- this._currentUser = l;
243
+ }), u = await l.json();
244
+ if (l.status !== 200)
245
+ throw new Error(u.message);
246
+ this._currentUser = u;
247
247
  }
248
- this._token = t, this._waitingForAuth.forEach((g) => g(!0));
249
- } catch (s) {
250
- console.error("loginWithToken() failed", { err: s }), this._waitingForAuth.forEach((g) => g(!1));
248
+ this._token = t, this._waitingForAuth.forEach((l) => l(!0));
249
+ } catch (g) {
250
+ console.error("loginWithToken() failed", { err: g }), this._waitingForAuth.forEach((l) => l(!1));
251
251
  } finally {
252
252
  this._waitingForAuth.clear();
253
253
  }
254
254
  n && (this._refreshToken = n, setInterval(async () => {
255
255
  if (this._refreshToken) {
256
- const g = await (await fetch(`${this._apiUrl}/v1/admin/auth/refresh`, {
256
+ const l = await (await fetch(`${this._apiUrl}/v1/admin/auth/refresh`, {
257
257
  method: "POST",
258
258
  headers: {
259
259
  "Content-Type": "application/json"
@@ -262,7 +262,7 @@ class AuthenticationStore {
262
262
  refreshToken: this._refreshToken
263
263
  })
264
264
  })).json();
265
- this._token = g.authentication.accessToken;
265
+ this._token = l.authentication.accessToken;
266
266
  }
267
267
  }, 1e3 * 60 * 60));
268
268
  }