@scaleflex/dam-core 0.4.0 → 0.4.1
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/api/folders.service.d.ts +1 -1
- package/dist/api/folders.service.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +35 -34
- package/dist/index.js.map +1 -1
- package/dist/types/api.types.d.ts +3 -0
- package/dist/types/api.types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/api/archive.test.d.ts +0 -2
- package/dist/api/archive.test.d.ts.map +0 -1
- package/dist/api/files.service.test.d.ts +0 -2
- package/dist/api/files.service.test.d.ts.map +0 -1
- package/dist/api/variations.service.test.d.ts +0 -2
- package/dist/api/variations.service.test.d.ts.map +0 -1
- package/dist/auth/auth.service.test.d.ts +0 -2
- package/dist/auth/auth.service.test.d.ts.map +0 -1
- package/dist/helpers/cdn.test.d.ts +0 -2
- package/dist/helpers/cdn.test.d.ts.map +0 -1
- package/dist/helpers/format.test.d.ts +0 -2
- package/dist/helpers/format.test.d.ts.map +0 -1
- package/dist/helpers/thumbnail.test.d.ts +0 -2
- package/dist/helpers/thumbnail.test.d.ts.map +0 -1
- package/dist/helpers/variations.test.d.ts +0 -2
- package/dist/helpers/variations.test.d.ts.map +0 -1
- package/dist/store/browse-store.test.d.ts +0 -2
- package/dist/store/browse-store.test.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
const
|
|
2
|
-
function
|
|
1
|
+
const B = "https://api.filerobot.com";
|
|
2
|
+
function G(t) {
|
|
3
3
|
return t === 404 || t === 408 || t === 429 || t >= 500;
|
|
4
4
|
}
|
|
5
|
-
const
|
|
5
|
+
const W = (t) => new Promise((e) => setTimeout(e, t));
|
|
6
6
|
function M(t, e) {
|
|
7
|
-
return `${(e ||
|
|
7
|
+
return `${(e || B).replace(/\/+$/, "")}/${t}`;
|
|
8
8
|
}
|
|
9
|
-
async function
|
|
9
|
+
async function X(t, e, s, i = {}) {
|
|
10
10
|
const r = `${M(t, s)}/key/${encodeURIComponent(e)}`, o = i.retries ?? 2, l = i.retryDelayMs ?? 400;
|
|
11
11
|
let a = new Error("SASS key exchange failed");
|
|
12
12
|
for (let c = 0; c <= o; c++) {
|
|
13
|
-
c > 0 && await
|
|
13
|
+
c > 0 && await W(l * c);
|
|
14
14
|
const f = new AbortController(), h = setTimeout(() => f.abort(), 3e4);
|
|
15
15
|
try {
|
|
16
16
|
const d = await fetch(r, { signal: f.signal, cache: "no-store" });
|
|
17
17
|
if (clearTimeout(h), !d.ok) {
|
|
18
|
-
if (a = new Error(`SASS key exchange failed (HTTP ${d.status})`),
|
|
18
|
+
if (a = new Error(`SASS key exchange failed (HTTP ${d.status})`), G(d.status) && c < o) continue;
|
|
19
19
|
throw a;
|
|
20
20
|
}
|
|
21
21
|
const u = await d.json();
|
|
@@ -50,11 +50,11 @@ function T(t, e) {
|
|
|
50
50
|
}
|
|
51
51
|
return t.airboxPuid && (s["X-Filerobot-Airbox-Puid"] = t.airboxPuid), s;
|
|
52
52
|
}
|
|
53
|
-
function
|
|
53
|
+
function V(t) {
|
|
54
54
|
return t.mode === "securityTemplate" || t.mode === "sassKey";
|
|
55
55
|
}
|
|
56
|
-
function
|
|
57
|
-
return
|
|
56
|
+
function H(t) {
|
|
57
|
+
return V(t) ? t.mode === "securityTemplate" ? {
|
|
58
58
|
mode: "security-template",
|
|
59
59
|
container: t.projectToken,
|
|
60
60
|
securityTemplateId: t.securityTemplateKey,
|
|
@@ -67,14 +67,14 @@ function V(t) {
|
|
|
67
67
|
} : t;
|
|
68
68
|
}
|
|
69
69
|
async function I(t, e) {
|
|
70
|
-
const s =
|
|
70
|
+
const s = H(t), i = M(s.container, e);
|
|
71
71
|
if (s.mode === "security-template") {
|
|
72
|
-
const r = await
|
|
72
|
+
const r = await X(s.container, s.securityTemplateId, e);
|
|
73
73
|
return { apiBase: i, headers: T(s, r), sassKey: r };
|
|
74
74
|
}
|
|
75
75
|
return { apiBase: i, headers: T(s) };
|
|
76
76
|
}
|
|
77
|
-
const
|
|
77
|
+
const J = 3e4;
|
|
78
78
|
class R {
|
|
79
79
|
constructor(e, s, i) {
|
|
80
80
|
this.baseUrl = `${e.apiBase}/v5`, this.headers = e.headers, this.auth = s, this.apiDomain = i;
|
|
@@ -120,7 +120,7 @@ class R {
|
|
|
120
120
|
}
|
|
121
121
|
async send(e, s, i = !1) {
|
|
122
122
|
var l;
|
|
123
|
-
const r = new AbortController(), o = setTimeout(() => r.abort(),
|
|
123
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), J);
|
|
124
124
|
try {
|
|
125
125
|
const a = await fetch(e.toString(), {
|
|
126
126
|
...s,
|
|
@@ -152,7 +152,7 @@ class R {
|
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
|
-
function
|
|
155
|
+
function O(t) {
|
|
156
156
|
const e = t.path ?? t.name, s = e.replace(/\/[^/]*$/, "") || "/";
|
|
157
157
|
return {
|
|
158
158
|
uuid: t.uuid,
|
|
@@ -172,11 +172,12 @@ async function b(t, e = {}) {
|
|
|
172
172
|
offset: e.offset ?? 0,
|
|
173
173
|
q: e.q,
|
|
174
174
|
sort: `${s}:${i}`
|
|
175
|
-
})).folders ?? []).map(
|
|
175
|
+
})).folders ?? []).map(O);
|
|
176
176
|
}
|
|
177
177
|
async function K(t, e, s) {
|
|
178
178
|
const i = s.replace(/\/+$/, ""), r = i ? `${i}/${e}` : `/${e}`, o = await t.post("/folders", { name: r });
|
|
179
|
-
if (o.status !== "success") throw new Error(o.msg || "Failed to create folder");
|
|
179
|
+
if (o.status !== "success" || !o.folder) throw new Error(o.msg || "Failed to create folder");
|
|
180
|
+
return O(o.folder);
|
|
180
181
|
}
|
|
181
182
|
async function Y(t, e, s) {
|
|
182
183
|
const i = await t.put(`/folder/${encodeURIComponent(e)}/name`, {
|
|
@@ -195,7 +196,7 @@ async function Q(t, e, s) {
|
|
|
195
196
|
});
|
|
196
197
|
if ((i == null ? void 0 : i.status) === "error") throw new Error(i.msg || "Failed to move folders");
|
|
197
198
|
}
|
|
198
|
-
const
|
|
199
|
+
const L = {
|
|
199
200
|
small: [null, 1048576],
|
|
200
201
|
// < 1 MB
|
|
201
202
|
medium: [1048576, 10485760],
|
|
@@ -214,7 +215,7 @@ function y(t, e) {
|
|
|
214
215
|
const s = new Date(e);
|
|
215
216
|
return s.setUTCHours(0, 0, 0, 0), s.setUTCDate(s.getUTCDate() - ee[t]), s;
|
|
216
217
|
}
|
|
217
|
-
const
|
|
218
|
+
const z = ["cdn_permalink"], F = {}, m = (t, e) => e.split(" ").forEach((s) => F[s] = t);
|
|
218
219
|
m("image", "jpg jpeg png gif webp svg avif bmp tif tiff heic ico");
|
|
219
220
|
m("video", "mp4 webm mov m4v avi mkv ogv");
|
|
220
221
|
m("audio", "mp3 wav ogg oga m4a aac flac");
|
|
@@ -226,7 +227,7 @@ function te(t) {
|
|
|
226
227
|
const s = (t.file_type || t.type || "").toLowerCase();
|
|
227
228
|
return s.startsWith("image") ? "image" : s.startsWith("video") ? "video" : s.startsWith("audio") ? "audio" : s.includes("pdf") || s.includes("document") || s.includes("text") ? "document" : F[e] ?? "other";
|
|
228
229
|
}
|
|
229
|
-
function
|
|
230
|
+
function q(t) {
|
|
230
231
|
var e, s, i, r, o, l, a;
|
|
231
232
|
return {
|
|
232
233
|
uuid: t.uuid,
|
|
@@ -247,9 +248,9 @@ function z(t) {
|
|
|
247
248
|
}
|
|
248
249
|
function se(t) {
|
|
249
250
|
var l;
|
|
250
|
-
const e = t.fields ??
|
|
251
|
+
const e = t.fields ?? z, s = t.sortBy ?? "created_at", i = t.sortDirection ?? "desc", r = [];
|
|
251
252
|
if (t.search && r.push(t.search), t.q && r.push(t.q), (l = t.types) != null && l.length && r.push(`type:${t.types.map((a) => `"${a}"`).join(",")}`), t.sizeBucket) {
|
|
252
|
-
const [a, c] =
|
|
253
|
+
const [a, c] = L[t.sizeBucket];
|
|
253
254
|
r.push(`size:"${a ?? ""}..${c ?? ""}"`);
|
|
254
255
|
}
|
|
255
256
|
if (t.durationRange) {
|
|
@@ -271,7 +272,7 @@ function se(t) {
|
|
|
271
272
|
};
|
|
272
273
|
}
|
|
273
274
|
async function w(t, e = {}) {
|
|
274
|
-
const s = se(e), i = await t.get("/files", s), r = (i.files ?? []).map(
|
|
275
|
+
const s = se(e), i = await t.get("/files", s), r = (i.files ?? []).map(q), o = typeof i.total == "number" ? i.total : i.count ?? r.length;
|
|
275
276
|
return { assets: r, total: o };
|
|
276
277
|
}
|
|
277
278
|
async function $e(t, e = {}) {
|
|
@@ -292,7 +293,7 @@ function re(t, e, s) {
|
|
|
292
293
|
var i;
|
|
293
294
|
if ((i = e.types) != null && i.length && !e.types.includes(ie[t.type])) return !1;
|
|
294
295
|
if (e.sizeBucket) {
|
|
295
|
-
const [r, o] =
|
|
296
|
+
const [r, o] = L[e.sizeBucket];
|
|
296
297
|
if (t.size == null || r != null && t.size < r || o != null && t.size >= o) return !1;
|
|
297
298
|
}
|
|
298
299
|
if (e.durationRange) {
|
|
@@ -323,7 +324,7 @@ function ne(t, e, s) {
|
|
|
323
324
|
});
|
|
324
325
|
}
|
|
325
326
|
async function oe(t, e, s = {}) {
|
|
326
|
-
const i = s.fields ??
|
|
327
|
+
const i = s.fields ?? z, r = new Array(e.length);
|
|
327
328
|
let o = 0;
|
|
328
329
|
const l = async () => {
|
|
329
330
|
for (; o < e.length; ) {
|
|
@@ -334,7 +335,7 @@ async function oe(t, e, s = {}) {
|
|
|
334
335
|
preview: 2301,
|
|
335
336
|
fields: i.length ? i : void 0
|
|
336
337
|
});
|
|
337
|
-
f != null && f.file && (r[c] =
|
|
338
|
+
f != null && f.file && (r[c] = q(f.file));
|
|
338
339
|
} catch {
|
|
339
340
|
}
|
|
340
341
|
}
|
|
@@ -506,7 +507,7 @@ async function Ce(t, e, s = {}) {
|
|
|
506
507
|
const i = await we(t, e);
|
|
507
508
|
return await _e(t, i, s), Ae(t, i);
|
|
508
509
|
}
|
|
509
|
-
const Fe = ["cdn_permalink"],
|
|
510
|
+
const Fe = ["cdn_permalink"], j = {
|
|
510
511
|
created_at: "created_at",
|
|
511
512
|
modified_at: "modified_at",
|
|
512
513
|
name: "name",
|
|
@@ -525,7 +526,7 @@ function Ee(t) {
|
|
|
525
526
|
};
|
|
526
527
|
e.length > 0 && (s.fields = e);
|
|
527
528
|
const i = t.sort_by ?? "created_at", r = t.sort_direction ?? "desc";
|
|
528
|
-
s.sort = `${
|
|
529
|
+
s.sort = `${j[i] || i}:${r}`, t.folder && (s.folder = t.folder);
|
|
529
530
|
const o = [];
|
|
530
531
|
return t.search && !t.with_ai && o.push(t.search), t.q && o.push(t.q), o.length > 0 && (s.q = o.join(" ")), t.with_ai && (s.with_ai = !0, t.ai_query && (s.ai_query = t.ai_query), t.ai_lang && (s.ai_lang = t.ai_lang)), t.collection_uuid && (s.collection_uuid = t.collection_uuid), t.f64 && (s.f64 = t.f64), s;
|
|
531
532
|
}
|
|
@@ -547,7 +548,7 @@ function ke(t, e = {}) {
|
|
|
547
548
|
};
|
|
548
549
|
e.q && (s.q = e.q);
|
|
549
550
|
const i = e.sort_by ?? "created_at", r = e.sort_direction ?? "asc";
|
|
550
|
-
return s.sort = `${
|
|
551
|
+
return s.sort = `${j[i] || i}:${r}`, t.get("/folders", s);
|
|
551
552
|
}
|
|
552
553
|
async function Me(t, e) {
|
|
553
554
|
return e.length === 0 ? {} : (await t.post("/folders/previews", {
|
|
@@ -949,7 +950,7 @@ const Le = { excellent: 90, good: 75, fair: 60 }, ze = { fullhd: 1920, large: 12
|
|
|
949
950
|
webp: "awebp,webp",
|
|
950
951
|
gif: "agif,gif"
|
|
951
952
|
};
|
|
952
|
-
function
|
|
953
|
+
function N(t, e) {
|
|
953
954
|
t.searchParams.delete("download"), e.width && t.searchParams.set("w", String(e.width)), e.height && t.searchParams.set("h", String(e.height)), e.quality != null && t.searchParams.set("q", String(e.quality)), e.format && t.searchParams.set("force_format", Pe[e.format] ?? e.format), e.strictSizes !== void 0 && (e.width || e.height) && t.searchParams.set("func", e.strictSizes ? "bound" : "cover");
|
|
954
955
|
}
|
|
955
956
|
function Te(t, e) {
|
|
@@ -959,11 +960,11 @@ function Te(t, e) {
|
|
|
959
960
|
}
|
|
960
961
|
function qe(t, e, s = {}) {
|
|
961
962
|
const i = new URL(t);
|
|
962
|
-
return
|
|
963
|
+
return N(i, s), i.searchParams.set("force_download", Te(e, s.format)), i.toString();
|
|
963
964
|
}
|
|
964
965
|
function je(t, e = {}) {
|
|
965
966
|
const s = new URL(t);
|
|
966
|
-
return
|
|
967
|
+
return N(s, e), s.toString();
|
|
967
968
|
}
|
|
968
969
|
const k = /^(https:\/\/)([a-z0-9_-]+)\.filerobot\.com\/(?:v\d+\/)?/i;
|
|
969
970
|
function _(t) {
|
|
@@ -1169,7 +1170,7 @@ export {
|
|
|
1169
1170
|
He as debounce,
|
|
1170
1171
|
ce as deleteFiles,
|
|
1171
1172
|
Z as deleteFolders,
|
|
1172
|
-
|
|
1173
|
+
X as exchangeSassKey,
|
|
1173
1174
|
Xe as formatDate,
|
|
1174
1175
|
Ve as formatDimensions,
|
|
1175
1176
|
We as formatFileSize,
|
|
@@ -1194,7 +1195,7 @@ export {
|
|
|
1194
1195
|
xe as loadVariations,
|
|
1195
1196
|
le as moveFiles,
|
|
1196
1197
|
Q as moveFolders,
|
|
1197
|
-
|
|
1198
|
+
H as normalizeAuth,
|
|
1198
1199
|
me as normalizePresets,
|
|
1199
1200
|
x as normalizeVariation,
|
|
1200
1201
|
_e as pollArchive,
|