@formant/data-sdk 1.16.0 → 1.18.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.
@@ -300,6 +300,30 @@ class AuthenticationStore {
300
300
  })).json();
301
301
  await this.loginWithToken(r.authentication.accessToken, t);
302
302
  }
303
+ async checkSso(t, n) {
304
+ return await (await fetch(`${this._apiUrl}/v1/admin/auth/check-sso`, {
305
+ method: "POST",
306
+ body: JSON.stringify({ email: t, allowUserAutoCreation: n }),
307
+ headers: {
308
+ "Content-Type": "application/json"
309
+ }
310
+ })).json();
311
+ }
312
+ async loginWithSso(t, n) {
313
+ const o = await (await fetch(`${this._apiUrl}/v1/admin/auth/login-sso`, {
314
+ method: "POST",
315
+ body: JSON.stringify({ token: t, refreshToken: n }),
316
+ headers: {
317
+ "Content-Type": "application/json"
318
+ }
319
+ })).json();
320
+ if (!o.authentication)
321
+ throw new Error("Failed to login with SSO");
322
+ return await this.loginWithToken(
323
+ o.authentication.accessToken,
324
+ o.authentication.refreshToken
325
+ );
326
+ }
303
327
  }
304
328
  function getCurrentModuleContext() {
305
329
  return typeof window < "u" && window.location ? new URLSearchParams(window.location.search).get("module") : null;
@@ -826,8 +850,6 @@ function filterDataByTime(e, t, n) {
826
850
  )
827
851
  })).filter(({ points: l }) => l.length > 0);
828
852
  }
829
- function fork(e) {
830
- }
831
853
  class StoreCache {
832
854
  constructor({
833
855
  capacity: t,
@@ -836,20 +858,21 @@ class StoreCache {
836
858
  _e(this, "entries", /* @__PURE__ */ new Map());
837
859
  _e(this, "metadata", /* @__PURE__ */ new Map());
838
860
  _e(this, "capacity");
839
- _e(this, "timeout");
840
- this.capacity = t || 1e4, this.timeout = n || duration.minute;
861
+ _e(this, "staleIntervalMs");
862
+ this.capacity = t || 1e4, this.staleIntervalMs = n || duration.minute;
841
863
  }
842
864
  get(t, n) {
843
- const r = this.keyToCacheKey(t), o = this.entries.get(r), l = this.metadata.get(r);
844
- return (o === void 0 || l && (l == null ? void 0 : l.expiration.getTime()) < Date.now()) && !(l != null && l.generating) && n && this.generate(t, n()), o === void 0 && l && l.lastValue !== void 0 ? l.lastValue : o;
865
+ const r = this.keyToCacheKey(t);
866
+ return this.isStale(r) && !this.isGenerating(r) && n && this.generate(t, n), this.entries.get(r);
845
867
  }
846
868
  set(t, n) {
847
869
  const r = this.keyToCacheKey(t);
848
870
  this.metadata.set(r, {
849
871
  generating: !1,
850
- expiration: new Date(Date.now() + this.timeout),
851
- lastValue: n
852
- }), this.entries.set(r, n), this.metadata.size > this.capacity && this.deleteOldestEntry();
872
+ staleAt: performance.now() + this.staleIntervalMs
873
+ });
874
+ const o = this.entries.get(r);
875
+ JSON.stringify(o) === JSON.stringify(n) || (this.entries.set(r, n), this.enforceMaxSize());
853
876
  }
854
877
  clear() {
855
878
  this.entries.clear(), [...this.metadata.values()].forEach((t) => t.generating = !1);
@@ -860,26 +883,34 @@ class StoreCache {
860
883
  keyToCacheKey(t) {
861
884
  return JSON.stringify(t);
862
885
  }
863
- deleteOldestEntry() {
864
- if (this.metadata.size < 1)
865
- return;
866
- const [t] = [...this.metadata.entries()].reduce(
867
- ([n, r], [o, l]) => l.expiration.getTime() < r.expiration.getTime() ? [o, l] : [n, r]
868
- );
869
- this.clearKey(t);
886
+ enforceMaxSize() {
887
+ for (; this.metadata.size > this.capacity && this.metadata.size > 0; ) {
888
+ const [t] = [...this.metadata.entries()].reduce(
889
+ ([n, r], [o, l]) => l.staleAt < r.staleAt ? [o, l] : [n, r]
890
+ );
891
+ this.clearKey(t);
892
+ }
893
+ }
894
+ isStale(t) {
895
+ const n = this.metadata.get(t);
896
+ return n ? (n == null ? void 0 : n.staleAt) < performance.now() : !0;
897
+ }
898
+ isGenerating(t) {
899
+ const n = this.metadata.get(t);
900
+ return n ? n.generating : !1;
870
901
  }
871
902
  generate(t, n) {
872
- const r = this.keyToCacheKey(t), o = this.metadata.get(r) || {};
903
+ const r = this.keyToCacheKey(t), o = this.metadata.get(r) || {}, l = n().then((u) => {
904
+ const s = this.metadata.get(r);
905
+ return (s == null ? void 0 : s.generating) !== l || this.set(t, u), u;
906
+ }).catch((u) => {
907
+ throw this.metadata.delete(r), u;
908
+ });
873
909
  this.metadata.set(r, {
874
910
  ...o,
875
- generating: !0,
876
- expiration: new Date(Date.now() + this.timeout)
877
- }), setTimeout(() => {
878
- n.then((l) => {
879
- const u = this.metadata.get(r);
880
- !(u != null && u.generating) || this.set(t, l);
881
- });
882
- }, 0);
911
+ generating: l,
912
+ staleAt: performance.now() + this.staleIntervalMs
913
+ });
883
914
  }
884
915
  }
885
916
  async function queryTelemetry(e) {
@@ -24936,6 +24967,8 @@ class KeyValue {
24936
24967
  function stringToArrayBuffer(e) {
24937
24968
  return Uint8Array.from(base64Exports.decode(e), (t) => t.charCodeAt(0));
24938
24969
  }
24970
+ function fork(e) {
24971
+ }
24939
24972
  function browser() {
24940
24973
  const { userAgent: e } = navigator;
24941
24974
  return e ? e.includes("Firefox/") ? "Firefox" : e.includes("Edg/") ? "Edge" : e.includes("Chrome/") ? "Chrome" : e.includes("Safari/") ? "Safari" : e.includes("MSIE/") || e.includes("Trident/") ? "IE" : "Other" : "Other";