@burdenoff/microfe-coolandlovely 2026.1110.2 → 2026.1112.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/coolandlovely/components/ImageUploadField.d.ts +2 -0
- package/dist/coolandlovely/components/ImageUploadField.js +142 -119
- package/dist/coolandlovely/hooks/uploadVisibility.d.ts +2 -0
- package/dist/coolandlovely/hooks/uploadVisibility.js +6 -0
- package/dist/coolandlovely/hooks/useCatalogImport.js +1 -1
- package/dist/coolandlovely/hooks/useFiles.d.ts +3 -25
- package/dist/coolandlovely/hooks/useFiles.js +52 -50
- package/dist/coolandlovely/pages/brands/BrandFormPage.js +2 -0
- package/dist/coolandlovely/pages/collections/CollectionFormPage.js +1 -0
- package/dist/coolandlovely/pages/items/StyleItemFormPage.js +1 -0
- package/dist/coolandlovely/pages/lookbooks/LookbooksListPage.js +1 -0
- package/dist/coolandlovely/pages/looks/LookFormPage.js +1 -0
- package/dist/coolandlovely/pages/wardrobe/WardrobeFormPage.js +1 -0
- package/package.json +1 -1
|
@@ -7,6 +7,8 @@ interface ImageUploadFieldProps {
|
|
|
7
7
|
onChange: (fileId: string) => void;
|
|
8
8
|
/** Destination folder in wspace-files (see COO_FILE_FOLDERS). */
|
|
9
9
|
folder?: string;
|
|
10
|
+
/** Only catalog forms opt into this choice. Personal wardrobe never does. */
|
|
11
|
+
allowWorkspace?: boolean;
|
|
10
12
|
hint?: string;
|
|
11
13
|
/** `accept` for the input; images only by default. */
|
|
12
14
|
accept?: string;
|
|
@@ -2,151 +2,174 @@ import { FieldShell as e } from "./Field.js";
|
|
|
2
2
|
import { useCoolAndLovely as t } from "../context/CoolAndLovelyContext.js";
|
|
3
3
|
import { uploadImageToFilesWithProgress as n, useFileUrl as r } from "../hooks/useFiles.js";
|
|
4
4
|
import { cn as i } from "../utils/cn.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import { uploadVisibility as a } from "../hooks/uploadVisibility.js";
|
|
6
|
+
import { useTr as o } from "../hooks/useTr.js";
|
|
7
|
+
import { useEffect as s, useId as c, useRef as l, useState as u } from "react";
|
|
8
|
+
import { ImagePlus as d, Loader2 as f, UploadCloud as p, X as m } from "lucide-react";
|
|
9
|
+
import { jsx as h, jsxs as g } from "react/jsx-runtime";
|
|
8
10
|
// src/coolandlovely/components/ImageUploadField.tsx
|
|
9
|
-
var
|
|
10
|
-
function
|
|
11
|
+
var ee = 10485760;
|
|
12
|
+
function _(e) {
|
|
11
13
|
if (e < 1024) return `${e} B`;
|
|
12
14
|
let t = e / 1024;
|
|
13
15
|
return t < 1024 ? `${t < 10 ? t.toFixed(1) : Math.round(t)} KB` : `${(t / 1024).toFixed(1)} MB`;
|
|
14
16
|
}
|
|
15
|
-
var
|
|
16
|
-
let { apiGatewayUrl:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}, [
|
|
20
|
-
let
|
|
17
|
+
var v = ({ label: v, value: y, onChange: b, folder: x, allowWorkspace: S = !1, hint: C, accept: w = "image/*", disabled: T = !1, className: E, aspect: D = "square" }) => {
|
|
18
|
+
let O = o(), { apiGatewayUrl: k } = t(), A = l(null), j = c(), [M, N] = u(!1), [P, F] = u(null), [I, L] = u(null), [R, z] = u(null), [B, V] = u(!1), [H, U] = u(), [W, G] = u("PRIVATE"), K = l(!1);
|
|
19
|
+
s(() => () => {
|
|
20
|
+
R && URL.revokeObjectURL(R);
|
|
21
|
+
}, [R]);
|
|
22
|
+
let q = r(M ? void 0 : y || void 0).data ?? null, J = T || M, Y = async (e) => {
|
|
23
|
+
if (T || K.current) return;
|
|
21
24
|
if (!e.type.startsWith("image/")) {
|
|
22
|
-
|
|
25
|
+
U("Please choose an image file (JPG or PNG).");
|
|
23
26
|
return;
|
|
24
27
|
}
|
|
25
|
-
if (e.size >
|
|
26
|
-
|
|
28
|
+
if (e.size > ee) {
|
|
29
|
+
U("That image is over 10 MB — please choose a smaller file.");
|
|
27
30
|
return;
|
|
28
31
|
}
|
|
29
|
-
|
|
32
|
+
U(void 0), L(e.name);
|
|
30
33
|
let t = URL.createObjectURL(e);
|
|
31
|
-
|
|
34
|
+
z(t), F({
|
|
32
35
|
loaded: 0,
|
|
33
36
|
total: e.size,
|
|
34
37
|
pct: 0
|
|
35
|
-
}),
|
|
38
|
+
}), K.current = !0, N(!0);
|
|
36
39
|
try {
|
|
37
|
-
|
|
40
|
+
b((await n(e, k, x, F, S ? W : "PRIVATE")).id);
|
|
38
41
|
} catch (e) {
|
|
39
|
-
|
|
42
|
+
U(e instanceof Error ? e.message : "Upload failed — please try again.");
|
|
40
43
|
} finally {
|
|
41
|
-
|
|
44
|
+
K.current = !1, N(!1), F(null), L(null), z(null);
|
|
42
45
|
}
|
|
43
|
-
},
|
|
46
|
+
}, X = (e) => {
|
|
44
47
|
let t = e.target.files?.[0];
|
|
45
|
-
e.target.value = "", t &&
|
|
46
|
-
},
|
|
47
|
-
if (e.preventDefault(),
|
|
48
|
+
e.target.value = "", t && Y(t);
|
|
49
|
+
}, Z = (e) => {
|
|
50
|
+
if (e.preventDefault(), V(!1), J) return;
|
|
48
51
|
let t = e.dataTransfer.files?.[0];
|
|
49
|
-
t &&
|
|
50
|
-
},
|
|
51
|
-
e.preventDefault(),
|
|
52
|
-
},
|
|
53
|
-
e.preventDefault(),
|
|
54
|
-
},
|
|
55
|
-
return /* @__PURE__ */
|
|
56
|
-
label:
|
|
57
|
-
htmlFor:
|
|
58
|
-
hint:
|
|
59
|
-
error:
|
|
60
|
-
className:
|
|
61
|
-
children: [
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
52
|
+
t && Y(t);
|
|
53
|
+
}, Q = (e) => {
|
|
54
|
+
e.preventDefault(), J || V(!0);
|
|
55
|
+
}, te = (e) => {
|
|
56
|
+
e.preventDefault(), V(!1);
|
|
57
|
+
}, $ = P?.pct ?? 0;
|
|
58
|
+
return /* @__PURE__ */ g(e, {
|
|
59
|
+
label: v,
|
|
60
|
+
htmlFor: j,
|
|
61
|
+
hint: C,
|
|
62
|
+
error: H,
|
|
63
|
+
className: E,
|
|
64
|
+
children: [
|
|
65
|
+
S ? /* @__PURE__ */ g("label", {
|
|
66
|
+
className: "mb-2 block text-sm text-text-secondary",
|
|
67
|
+
children: [O("coolandlovely.upload.audience", "New image audience"), /* @__PURE__ */ g("select", {
|
|
68
|
+
value: W,
|
|
69
|
+
disabled: J,
|
|
70
|
+
onChange: (e) => G(a(e.target.value)),
|
|
71
|
+
className: "ml-2 rounded-lg border border-border-seam bg-bg-surface p-2 text-text-primary",
|
|
72
|
+
children: [/* @__PURE__ */ h("option", {
|
|
73
|
+
value: "PRIVATE",
|
|
74
|
+
children: O("coolandlovely.upload.private", "Only me")
|
|
75
|
+
}), /* @__PURE__ */ h("option", {
|
|
76
|
+
value: "WORKSPACE",
|
|
77
|
+
children: O("coolandlovely.upload.workspace", "Workspace members")
|
|
78
|
+
})]
|
|
79
|
+
})]
|
|
80
|
+
}) : null,
|
|
81
|
+
/* @__PURE__ */ h("div", {
|
|
82
|
+
onDragEnter: Q,
|
|
83
|
+
onDragOver: Q,
|
|
84
|
+
onDragLeave: te,
|
|
85
|
+
onDrop: Z,
|
|
86
|
+
children: M ? /* @__PURE__ */ g("div", {
|
|
87
|
+
className: "flex items-center gap-3 rounded-lg border border-border-seam bg-bg-surface p-3",
|
|
88
|
+
children: [/* @__PURE__ */ h("div", {
|
|
89
|
+
className: "flex h-14 w-14 shrink-0 items-center justify-center overflow-hidden rounded-lg bg-bg-sunken",
|
|
90
|
+
children: R ? /* @__PURE__ */ h("img", {
|
|
91
|
+
src: R,
|
|
92
|
+
alt: "",
|
|
93
|
+
className: "h-full w-full object-cover"
|
|
94
|
+
}) : /* @__PURE__ */ h(f, { className: "h-5 w-5 animate-spin text-text-secondary" })
|
|
95
|
+
}), /* @__PURE__ */ g("div", {
|
|
96
|
+
className: "min-w-0 flex-1",
|
|
97
|
+
children: [
|
|
98
|
+
/* @__PURE__ */ h("p", {
|
|
99
|
+
className: "truncate text-sm font-medium text-text-primary",
|
|
100
|
+
children: I ?? "Uploading…"
|
|
101
|
+
}),
|
|
102
|
+
/* @__PURE__ */ h("div", {
|
|
103
|
+
className: "mt-1.5 h-1.5 w-full overflow-hidden rounded-full bg-bg-sunken",
|
|
104
|
+
children: /* @__PURE__ */ h("div", {
|
|
105
|
+
className: "h-full rounded-full bg-accent-primary transition-[width] duration-200",
|
|
106
|
+
style: { width: `${$}%` }
|
|
107
|
+
})
|
|
108
|
+
}),
|
|
109
|
+
/* @__PURE__ */ g("p", {
|
|
110
|
+
className: "mt-1 text-xs text-text-secondary tabular-nums",
|
|
111
|
+
children: [
|
|
112
|
+
$,
|
|
113
|
+
"%",
|
|
114
|
+
P ? ` · ${_(P.loaded)} of ${_(P.total)}` : ""
|
|
115
|
+
]
|
|
116
|
+
})
|
|
117
|
+
]
|
|
118
|
+
})]
|
|
119
|
+
}) : q ? /* @__PURE__ */ g("div", {
|
|
120
|
+
className: "relative overflow-hidden rounded-lg border border-border-seam bg-bg-sunken",
|
|
121
|
+
children: [/* @__PURE__ */ h("img", {
|
|
122
|
+
src: q,
|
|
72
123
|
alt: "",
|
|
73
|
-
className: "
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
|
|
124
|
+
className: i("w-full object-cover", D === "wide" ? "aspect-video" : "aspect-square max-h-64")
|
|
125
|
+
}), /* @__PURE__ */ g("div", {
|
|
126
|
+
className: "absolute inset-x-0 bottom-0 flex justify-end gap-2 bg-gradient-to-t from-bg-canvas/85 to-transparent p-2",
|
|
127
|
+
children: [/* @__PURE__ */ g("button", {
|
|
128
|
+
type: "button",
|
|
129
|
+
disabled: J,
|
|
130
|
+
onClick: () => A.current?.click(),
|
|
131
|
+
className: "inline-flex items-center gap-1.5 rounded-lg bg-bg-surface/90 px-3 py-1.5 text-sm font-medium text-text-primary shadow-sm backdrop-blur transition-colors hover:bg-bg-surface disabled:opacity-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-focus-ring)]",
|
|
132
|
+
children: [/* @__PURE__ */ h(d, { className: "h-4 w-4" }), " Replace"]
|
|
133
|
+
}), /* @__PURE__ */ g("button", {
|
|
134
|
+
type: "button",
|
|
135
|
+
disabled: T,
|
|
136
|
+
onClick: () => b(""),
|
|
137
|
+
className: "inline-flex items-center gap-1 rounded-lg bg-bg-surface/90 px-3 py-1.5 text-sm text-text-secondary shadow-sm backdrop-blur transition-colors hover:bg-status-error-bg-subtle hover:text-status-error-text disabled:opacity-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-focus-ring)]",
|
|
138
|
+
children: [/* @__PURE__ */ h(m, { className: "h-4 w-4" }), " Remove"]
|
|
139
|
+
})]
|
|
140
|
+
})]
|
|
141
|
+
}) : /* @__PURE__ */ g("button", {
|
|
142
|
+
type: "button",
|
|
143
|
+
disabled: J,
|
|
144
|
+
onClick: () => A.current?.click(),
|
|
145
|
+
className: i("flex min-h-40 w-full flex-col items-center justify-center gap-2 rounded-lg border-2 border-dashed p-6 text-center transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-focus-ring)] disabled:opacity-50", B ? "border-accent-primary bg-[var(--color-accent-soft)]" : "border-border-seam hover:border-accent-primary/60 hover:bg-bg-sunken"),
|
|
77
146
|
children: [
|
|
78
|
-
/* @__PURE__ */
|
|
79
|
-
className: "
|
|
80
|
-
|
|
147
|
+
/* @__PURE__ */ h(p, {
|
|
148
|
+
className: "h-8 w-8 text-text-secondary",
|
|
149
|
+
"aria-hidden": "true"
|
|
81
150
|
}),
|
|
82
|
-
/* @__PURE__ */
|
|
83
|
-
className: "
|
|
84
|
-
children:
|
|
85
|
-
className: "h-full rounded-full bg-accent-primary transition-[width] duration-200",
|
|
86
|
-
style: { width: `${J}%` }
|
|
87
|
-
})
|
|
151
|
+
/* @__PURE__ */ h("span", {
|
|
152
|
+
className: "text-sm font-medium text-text-primary",
|
|
153
|
+
children: "Drag & drop an image here, or click to browse"
|
|
88
154
|
}),
|
|
89
|
-
/* @__PURE__ */
|
|
90
|
-
className: "
|
|
91
|
-
children:
|
|
92
|
-
J,
|
|
93
|
-
"%",
|
|
94
|
-
j ? ` · ${g(j.loaded)} of ${g(j.total)}` : ""
|
|
95
|
-
]
|
|
155
|
+
/* @__PURE__ */ h("span", {
|
|
156
|
+
className: "text-xs text-text-secondary",
|
|
157
|
+
children: "JPG · PNG · up to 10 MB"
|
|
96
158
|
})
|
|
97
159
|
]
|
|
98
|
-
})
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
disabled: H,
|
|
110
|
-
onClick: () => D.current?.click(),
|
|
111
|
-
className: "inline-flex items-center gap-1.5 rounded-lg bg-bg-surface/90 px-3 py-1.5 text-sm font-medium text-text-primary shadow-sm backdrop-blur transition-colors hover:bg-bg-surface disabled:opacity-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-focus-ring)]",
|
|
112
|
-
children: [/* @__PURE__ */ p(l, { className: "h-4 w-4" }), " Replace"]
|
|
113
|
-
}), /* @__PURE__ */ m("button", {
|
|
114
|
-
type: "button",
|
|
115
|
-
disabled: C,
|
|
116
|
-
onClick: () => y(""),
|
|
117
|
-
className: "inline-flex items-center gap-1 rounded-lg bg-bg-surface/90 px-3 py-1.5 text-sm text-text-secondary shadow-sm backdrop-blur transition-colors hover:bg-status-error-bg-subtle hover:text-status-error-text disabled:opacity-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-focus-ring)]",
|
|
118
|
-
children: [/* @__PURE__ */ p(f, { className: "h-4 w-4" }), " Remove"]
|
|
119
|
-
})]
|
|
120
|
-
})]
|
|
121
|
-
}) : /* @__PURE__ */ m("button", {
|
|
122
|
-
type: "button",
|
|
123
|
-
disabled: H,
|
|
124
|
-
onClick: () => D.current?.click(),
|
|
125
|
-
className: i("flex min-h-40 w-full flex-col items-center justify-center gap-2 rounded-lg border-2 border-dashed p-6 text-center transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-focus-ring)] disabled:opacity-50", L ? "border-accent-primary bg-[var(--color-accent-soft)]" : "border-border-seam hover:border-accent-primary/60 hover:bg-bg-sunken"),
|
|
126
|
-
children: [
|
|
127
|
-
/* @__PURE__ */ p(d, {
|
|
128
|
-
className: "h-8 w-8 text-text-secondary",
|
|
129
|
-
"aria-hidden": "true"
|
|
130
|
-
}),
|
|
131
|
-
/* @__PURE__ */ p("span", {
|
|
132
|
-
className: "text-sm font-medium text-text-primary",
|
|
133
|
-
children: "Drag & drop an image here, or click to browse"
|
|
134
|
-
}),
|
|
135
|
-
/* @__PURE__ */ p("span", {
|
|
136
|
-
className: "text-xs text-text-secondary",
|
|
137
|
-
children: "JPG · PNG · up to 10 MB"
|
|
138
|
-
})
|
|
139
|
-
]
|
|
160
|
+
})
|
|
161
|
+
}),
|
|
162
|
+
/* @__PURE__ */ h("input", {
|
|
163
|
+
ref: A,
|
|
164
|
+
id: j,
|
|
165
|
+
type: "file",
|
|
166
|
+
accept: w,
|
|
167
|
+
disabled: J,
|
|
168
|
+
className: "sr-only",
|
|
169
|
+
"aria-label": v,
|
|
170
|
+
onChange: X
|
|
140
171
|
})
|
|
141
|
-
|
|
142
|
-
ref: D,
|
|
143
|
-
id: O,
|
|
144
|
-
type: "file",
|
|
145
|
-
accept: S,
|
|
146
|
-
className: "sr-only",
|
|
147
|
-
"aria-label": _,
|
|
148
|
-
onChange: W
|
|
149
|
-
})]
|
|
172
|
+
]
|
|
150
173
|
});
|
|
151
174
|
};
|
|
152
|
-
export {
|
|
175
|
+
export { v as ImageUploadField };
|
|
@@ -25,7 +25,7 @@ async function f(e, t, n, i) {
|
|
|
25
25
|
let o = await a.blob();
|
|
26
26
|
if (!o.type.startsWith("image/") || o.size === 0 || o.size > c) return null;
|
|
27
27
|
let s = new File([o], d(e, t, o.type), { type: o.type });
|
|
28
|
-
return (await r(s, i, n)).id;
|
|
28
|
+
return (await r(s, i, n, "PRIVATE")).id;
|
|
29
29
|
} catch {
|
|
30
30
|
return null;
|
|
31
31
|
}
|
|
@@ -1,26 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* File hooks — image upload + display via wspace-files-svc (NO duplication).
|
|
3
|
-
* @module coolandlovely/hooks
|
|
4
|
-
*
|
|
5
|
-
* CoolAndLovely never stores blobs. Brand logos/covers, collection covers,
|
|
6
|
-
* style-item photos, look photos, wardrobe photos and lookbook covers are
|
|
7
|
-
* wspace-files `File` records referenced by id (the coo* inputs take *FileId;
|
|
8
|
-
* the coo* types expose logo/cover/image: File resolved via federation).
|
|
9
|
-
*
|
|
10
|
-
* Upload uses the SAME graphqlFetch transport as every other coo* call — NOT
|
|
11
|
-
* Apollo — driving the wspace-files 3-step presigned flow directly:
|
|
12
|
-
* ensureFolderByPath -> initiateUpload -> HTTP PUT -> completeUpload
|
|
13
|
-
* Display resolves a File id to a short-lived presigned URL via
|
|
14
|
-
* getFileDownloadUrl.
|
|
15
|
-
*
|
|
16
|
-
* Two fleet gotchas are handled here:
|
|
17
|
-
* (a) `fileSize` is REQUIRED on completeUpload even though this MFE's generated
|
|
18
|
-
* `CompleteUploadInput` is stale and omits it. Because we send a hand-written
|
|
19
|
-
* query with `Record<string, unknown>` variables (not typed against the
|
|
20
|
-
* generated input) we simply include it and it works at runtime.
|
|
21
|
-
* (b) `getFileDownloadUrl(expiresIn)` must be <= 604800 (S3 7-day cap → 500).
|
|
22
|
-
* We use 21600 (6h); do NOT raise it.
|
|
23
|
-
*/
|
|
1
|
+
import { UploadVisibility } from './uploadVisibility';
|
|
24
2
|
/** Per-entity folders in wspace-files. */
|
|
25
3
|
export declare const COO_FILE_FOLDERS: {
|
|
26
4
|
readonly brands: "/CoolAndLovely/Brands";
|
|
@@ -50,12 +28,12 @@ export interface UploadProgress {
|
|
|
50
28
|
* caller persists `id` (e.g. cooUpdateBrand({ logoFileId })); `url` is for an
|
|
51
29
|
* immediate preview. `baseUrl` is the shell's apiGatewayUrl.
|
|
52
30
|
*/
|
|
53
|
-
export declare function uploadImageToFiles(file: File, baseUrl?: string, folderPath?: string): Promise<UploadedImage>;
|
|
31
|
+
export declare function uploadImageToFiles(file: File, baseUrl?: string, folderPath?: string, visibility?: UploadVisibility): Promise<UploadedImage>;
|
|
54
32
|
/**
|
|
55
33
|
* Same as {@link uploadImageToFiles} but reports transfer progress via
|
|
56
34
|
* `onProgress` (XHR `upload.onprogress`) so callers can render a live progress
|
|
57
35
|
* bar. `baseUrl` is the shell's apiGatewayUrl.
|
|
58
36
|
*/
|
|
59
|
-
export declare function uploadImageToFilesWithProgress(file: File, baseUrl?: string, folderPath?: string, onProgress?: (progress: UploadProgress) => void): Promise<UploadedImage>;
|
|
37
|
+
export declare function uploadImageToFilesWithProgress(file: File, baseUrl?: string, folderPath?: string, onProgress?: (progress: UploadProgress) => void, visibility?: UploadVisibility): Promise<UploadedImage>;
|
|
60
38
|
/** Resolve a wspace-files File id to a presigned URL for display. */
|
|
61
39
|
export declare function useFileUrl(fileId?: string | null): import('@tanstack/react-query').UseQueryResult<string | null, Error>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { useCoolAndLovely as e } from "../context/CoolAndLovelyContext.js";
|
|
2
2
|
import "../context/index.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { uploadVisibility as t } from "./uploadVisibility.js";
|
|
4
|
+
import { useQuery as n } from "@tanstack/react-query";
|
|
5
|
+
import { graphqlFetch as r } from "@burdenoff/fe-libs/shared/graphql";
|
|
6
|
+
import { clearGraphqlFetchResponseCache as i } from "@burdenoff/fe-libs/shared/graphql/fetch";
|
|
6
7
|
// src/coolandlovely/hooks/useFiles.ts
|
|
7
|
-
var
|
|
8
|
+
var a = 21600, o = {
|
|
8
9
|
brands: "/CoolAndLovely/Brands",
|
|
9
10
|
collections: "/CoolAndLovely/Collections",
|
|
10
11
|
items: "/CoolAndLovely/Items",
|
|
@@ -12,24 +13,24 @@ var i = 21600, a = {
|
|
|
12
13
|
wardrobe: "/CoolAndLovely/Wardrobe",
|
|
13
14
|
lookbooks: "/CoolAndLovely/Lookbooks"
|
|
14
15
|
};
|
|
15
|
-
async function
|
|
16
|
-
let a = await
|
|
16
|
+
async function s(e, t, n) {
|
|
17
|
+
let a = await r({
|
|
17
18
|
gateway: "workspace",
|
|
18
|
-
baseUrl:
|
|
19
|
+
baseUrl: n,
|
|
19
20
|
query: e,
|
|
20
21
|
variables: t,
|
|
21
22
|
workspaceToken: !0
|
|
22
23
|
});
|
|
23
24
|
if (a.errors?.length) throw Error(a.errors[0]?.message ?? "Files request failed");
|
|
24
25
|
if (!a.data) throw Error("Files response did not include data");
|
|
25
|
-
return /^\s*mutation\b/.test(e) &&
|
|
26
|
+
return /^\s*mutation\b/.test(e) && i(), a.data;
|
|
26
27
|
}
|
|
27
|
-
var
|
|
28
|
-
function
|
|
28
|
+
var c = "\n mutation CooEnsureFolder($path: String!) {\n ensureFolderByPath(path: $path) { id }\n }\n", l = "\n mutation CooInitiateUpload($input: InitiateUploadInput!) {\n initiateUpload(input: $input) {\n uploadUrl\n session { id }\n }\n }\n", u = "\n mutation CooCompleteUpload($input: CompleteUploadInput!) {\n completeUpload(input: $input) {\n fileId\n file { id name }\n }\n }\n", d = "\n query CooGetFileDownloadUrl($id: ID!, $expiresIn: Int) {\n getFileDownloadUrl(id: $id, expiresIn: $expiresIn)\n }\n";
|
|
29
|
+
function f(e, t) {
|
|
29
30
|
let n = e.lastIndexOf(".");
|
|
30
31
|
return n > -1 && n < e.length - 1 ? e.slice(n + 1).toLowerCase() : (t.split("/")[1] ?? "bin").toLowerCase();
|
|
31
32
|
}
|
|
32
|
-
function
|
|
33
|
+
function p(e, t, n, r) {
|
|
33
34
|
return new Promise((i, a) => {
|
|
34
35
|
let o = new XMLHttpRequest();
|
|
35
36
|
o.open("PUT", e, !0), o.setRequestHeader("Content-Type", n), r && (o.upload.onprogress = (e) => {
|
|
@@ -48,64 +49,65 @@ function f(e, t, n, r) {
|
|
|
48
49
|
}, o.onerror = () => a(/* @__PURE__ */ Error("Upload to storage failed — a network error occurred.")), o.onabort = () => a(/* @__PURE__ */ Error("Upload was cancelled.")), o.send(t);
|
|
49
50
|
});
|
|
50
51
|
}
|
|
51
|
-
async function
|
|
52
|
-
let
|
|
52
|
+
async function m(e, n, r = o.items, i, m) {
|
|
53
|
+
let h = t(m), g = e.type || "application/octet-stream", _ = String(e.size), v;
|
|
53
54
|
try {
|
|
54
|
-
|
|
55
|
+
v = (await s(c, { path: r }, n)).ensureFolderByPath?.id ?? void 0;
|
|
55
56
|
} catch {
|
|
56
|
-
|
|
57
|
+
v = void 0;
|
|
57
58
|
}
|
|
58
|
-
let
|
|
59
|
+
let y = await s(l, { input: {
|
|
59
60
|
fileName: e.name,
|
|
60
|
-
extension:
|
|
61
|
-
fileSize:
|
|
62
|
-
mimeType:
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
61
|
+
extension: f(e.name, g),
|
|
62
|
+
fileSize: _,
|
|
63
|
+
mimeType: g,
|
|
64
|
+
visibility: h,
|
|
65
|
+
...v ? { folderId: v } : {}
|
|
66
|
+
} }, n), b = y.initiateUpload?.uploadUrl, x = y.initiateUpload?.session.id;
|
|
67
|
+
if (!b || !x) throw Error("The files service did not return an upload URL.");
|
|
68
|
+
await p(b, e, g, i);
|
|
69
|
+
let S = await s(u, { input: {
|
|
70
|
+
sessionId: x,
|
|
71
|
+
fileSize: _,
|
|
72
|
+
...v ? { folderId: v } : {}
|
|
73
|
+
} }, n), C = S.completeUpload?.file, w = S.completeUpload?.fileId ?? C?.id;
|
|
74
|
+
if (!w) throw Error("The upload could not be finalized.");
|
|
75
|
+
let T = "";
|
|
74
76
|
try {
|
|
75
|
-
|
|
76
|
-
id:
|
|
77
|
-
expiresIn:
|
|
78
|
-
},
|
|
77
|
+
T = (await s(d, {
|
|
78
|
+
id: w,
|
|
79
|
+
expiresIn: a
|
|
80
|
+
}, n)).getFileDownloadUrl ?? "";
|
|
79
81
|
} catch {
|
|
80
|
-
|
|
82
|
+
T = "";
|
|
81
83
|
}
|
|
82
84
|
return {
|
|
83
|
-
id:
|
|
84
|
-
url:
|
|
85
|
-
name:
|
|
85
|
+
id: w,
|
|
86
|
+
url: T,
|
|
87
|
+
name: C?.name ?? e.name
|
|
86
88
|
};
|
|
87
89
|
}
|
|
88
|
-
async function
|
|
89
|
-
return
|
|
90
|
+
async function h(e, t, n = o.items, r) {
|
|
91
|
+
return m(e, t, n, void 0, r);
|
|
90
92
|
}
|
|
91
|
-
async function
|
|
92
|
-
return
|
|
93
|
+
async function g(e, t, n = o.items, r, i) {
|
|
94
|
+
return m(e, t, n, r, i);
|
|
93
95
|
}
|
|
94
|
-
function
|
|
96
|
+
function _(t) {
|
|
95
97
|
let { apiGatewayUrl: r } = e();
|
|
96
|
-
return
|
|
98
|
+
return n({
|
|
97
99
|
queryKey: [
|
|
98
100
|
"coolandlovely",
|
|
99
101
|
"file-url",
|
|
100
|
-
|
|
102
|
+
t ?? ""
|
|
101
103
|
],
|
|
102
|
-
enabled: !!
|
|
104
|
+
enabled: !!t,
|
|
103
105
|
staleTime: 12e5,
|
|
104
106
|
retry: 1,
|
|
105
|
-
queryFn: async () => (await
|
|
106
|
-
id:
|
|
107
|
-
expiresIn:
|
|
107
|
+
queryFn: async () => (await s(d, {
|
|
108
|
+
id: t,
|
|
109
|
+
expiresIn: a
|
|
108
110
|
}, r)).getFileDownloadUrl ?? null
|
|
109
111
|
});
|
|
110
112
|
}
|
|
111
|
-
export {
|
|
113
|
+
export { o as COO_FILE_FOLDERS, h as uploadImageToFiles, g as uploadImageToFilesWithProgress, _ as useFileUrl };
|
|
@@ -181,12 +181,14 @@ function C() {
|
|
|
181
181
|
/* @__PURE__ */ b("div", {
|
|
182
182
|
className: "mt-4 grid grid-cols-1 gap-4 sm:grid-cols-2",
|
|
183
183
|
children: [/* @__PURE__ */ y(l, {
|
|
184
|
+
allowWorkspace: !0,
|
|
184
185
|
label: "Logo",
|
|
185
186
|
value: k.logoFileId,
|
|
186
187
|
onChange: (e) => N("logoFileId", e),
|
|
187
188
|
folder: d.brands,
|
|
188
189
|
hint: "Square storefront logo"
|
|
189
190
|
}), /* @__PURE__ */ y(l, {
|
|
191
|
+
allowWorkspace: !0,
|
|
190
192
|
label: "Cover",
|
|
191
193
|
aspect: "wide",
|
|
192
194
|
value: k.coverFileId,
|