@scaleflex/dam-core 0.3.1-beta.0 → 0.3.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.
package/dist/index.js CHANGED
@@ -11,10 +11,10 @@ async function W(s, e, t, i = {}) {
11
11
  let a = new Error("SASS key exchange failed");
12
12
  for (let c = 0; c <= o; c++) {
13
13
  c > 0 && await G(l * c);
14
- const h = new AbortController(), f = setTimeout(() => h.abort(), 3e4);
14
+ const f = new AbortController(), h = setTimeout(() => f.abort(), 3e4);
15
15
  try {
16
- const d = await fetch(r, { signal: h.signal, cache: "no-store" });
17
- if (clearTimeout(f), !d.ok) {
16
+ const d = await fetch(r, { signal: f.signal, cache: "no-store" });
17
+ if (clearTimeout(h), !d.ok) {
18
18
  if (a = new Error(`SASS key exchange failed (HTTP ${d.status})`), B(d.status) && c < o) continue;
19
19
  throw a;
20
20
  }
@@ -23,7 +23,7 @@ async function W(s, e, t, i = {}) {
23
23
  throw new Error(`SASS key exchange failed: ${u.msg || "Unknown error"}`);
24
24
  return u.key;
25
25
  } catch (d) {
26
- if (clearTimeout(f), d instanceof DOMException && d.name === "AbortError")
26
+ if (clearTimeout(h), d instanceof DOMException && d.name === "AbortError")
27
27
  throw new Error("SASS key exchange timed out");
28
28
  if (d instanceof TypeError && c < o) {
29
29
  a = d;
@@ -128,25 +128,25 @@ class O {
128
128
  signal: r.signal
129
129
  });
130
130
  if (clearTimeout(o), a.status === 401 && !i && ((l = this.auth) == null ? void 0 : l.mode) === "security-template") {
131
- const f = await I(this.auth, this.apiDomain);
132
- return this.headers = f.headers, this.send(e, t, !0);
131
+ const h = await I(this.auth, this.apiDomain);
132
+ return this.headers = h.headers, this.send(e, t, !0);
133
133
  }
134
134
  if (!a.ok) {
135
- let f = `API error: ${a.status} ${a.statusText}`;
135
+ let h = `API error: ${a.status} ${a.statusText}`;
136
136
  try {
137
137
  const d = await a.json();
138
- d != null && d.msg && (f = `API error: ${a.status} - ${d.msg}`);
138
+ d != null && d.msg && (h = `API error: ${a.status} - ${d.msg}`);
139
139
  } catch {
140
140
  }
141
- throw new Error(f);
141
+ throw new Error(h);
142
142
  }
143
143
  if (a.status === 204) return;
144
144
  const c = await a.text();
145
145
  if (!c) return;
146
- const h = JSON.parse(c);
147
- if ((h == null ? void 0 : h.status) === "error")
148
- throw new Error(`API error: ${h.msg || "Unknown error"}`);
149
- return h;
146
+ const f = JSON.parse(c);
147
+ if ((f == null ? void 0 : f.status) === "error")
148
+ throw new Error(`API error: ${f.msg || "Unknown error"}`);
149
+ return f;
150
150
  } catch (a) {
151
151
  throw clearTimeout(o), a instanceof DOMException && a.name === "AbortError" ? new Error("API request timed out") : a;
152
152
  }
@@ -320,12 +320,12 @@ async function oe(s, e, t = {}) {
320
320
  for (; o < e.length; ) {
321
321
  const c = o++;
322
322
  try {
323
- const h = await s.get(`/file/${encodeURIComponent(e[c])}`, {
323
+ const f = await s.get(`/file/${encodeURIComponent(e[c])}`, {
324
324
  format: "json,regvar:api,select:internal",
325
325
  preview: 2301,
326
326
  fields: i.length ? i : void 0
327
327
  });
328
- h != null && h.file && (r[c] = z(h.file));
328
+ f != null && f.file && (r[c] = z(f.file));
329
329
  } catch {
330
330
  }
331
331
  }
@@ -466,17 +466,17 @@ function be(s) {
466
466
  throw new Error(`Archive job failed: ${(s == null ? void 0 : s.task_status) ?? "unknown status"}`);
467
467
  }
468
468
  async function _e(s, e, t = {}) {
469
- var f, d;
469
+ var h, d;
470
470
  const i = t.intervalMs ?? 1500, r = t.timeoutMs ?? 12e4, o = t.maxRetries ?? 5, l = t.sleep ?? ((u) => new Promise((g) => setTimeout(g, u))), a = t.now ?? Date.now, c = a() + r;
471
- let h = 0;
471
+ let f = 0;
472
472
  for (; ; ) {
473
- if ((f = t.signal) != null && f.aborted) throw new Error("Archive polling aborted");
473
+ if ((h = t.signal) != null && h.aborted) throw new Error("Archive polling aborted");
474
474
  if (a() > c) throw new Error("Archive polling timed out");
475
475
  let u;
476
476
  try {
477
477
  u = await ye(s, e);
478
478
  } catch (S) {
479
- if (h++ < o) {
479
+ if (f++ < o) {
480
480
  await l(i);
481
481
  continue;
482
482
  }
@@ -810,30 +810,31 @@ class E {
810
810
  async fetchAssetsPage(e) {
811
811
  const { scope: t, sortBy: i, sortDirection: r } = this.state, o = this.state.searchQuery || void 0, l = this.facetParams();
812
812
  if (t.type === "favourites") {
813
- const f = [...this.state.favourites], d = await oe(this.client, f.slice(0, U)), u = Date.now(), g = d.filter((S) => re(S, l, u)), p = ne(g, i, r);
813
+ const h = [...this.state.favourites], d = await oe(this.client, h.slice(0, U)), u = Date.now(), g = d.filter((S) => re(S, l, u)), p = ne(g, i, r);
814
814
  return {
815
815
  assets: p,
816
816
  total: p.length,
817
- truncated: f.length > U,
817
+ truncated: h.length > U,
818
818
  hasMore: !1,
819
819
  fetched: 0
820
820
  };
821
821
  }
822
822
  const a = { sortBy: i, sortDirection: r, search: o, ...l, offset: e, limit: C };
823
823
  let c;
824
- if (t.type === "folder")
825
- c = await w(this.client, { ...a, folder: t.value ?? "/", recursive: 0 });
826
- else if (t.type === "label") {
827
- const f = this.state.labels.find((u) => u.uuid === t.value), d = f ? he(f) : void 0;
824
+ if (t.type === "folder") {
825
+ const h = this.state.searchQuery.trim() ? 1 : 0;
826
+ c = await w(this.client, { ...a, folder: t.value ?? "/", recursive: h });
827
+ } else if (t.type === "label") {
828
+ const h = this.state.labels.find((u) => u.uuid === t.value), d = h ? he(h) : void 0;
828
829
  c = await w(this.client, { ...a, recursive: 1, q: d });
829
830
  } else
830
831
  c = await w(this.client, { ...a, recursive: 1 });
831
- const h = c.assets.length === C;
832
+ const f = c.assets.length === C;
832
833
  return {
833
834
  assets: c.assets,
834
835
  total: c.total,
835
836
  truncated: !1,
836
- hasMore: h,
837
+ hasMore: f,
837
838
  fetched: c.assets.length
838
839
  };
839
840
  }
@@ -1109,8 +1110,8 @@ function We(s) {
1109
1110
  for (; t >= 1024 && i < e.length - 1; )
1110
1111
  t /= 1024, i++;
1111
1112
  const r = (a, c) => {
1112
- const h = c > 0 && Math.round(a * 10) / 10 < 10 ? 1 : 0, f = a.toFixed(h);
1113
- return { str: f, rounded: Number(f) };
1113
+ const f = c > 0 && Math.round(a * 10) / 10 < 10 ? 1 : 0, h = a.toFixed(f);
1114
+ return { str: h, rounded: Number(h) };
1114
1115
  }, o = r(t, i);
1115
1116
  let l = o.str;
1116
1117
  return o.rounded >= 1024 && i < e.length - 1 && (t /= 1024, i++, l = r(t, i).str), `${l} ${e[i]}`;