@burdenoff/microfe-coolandlovely 2026.1110.3 → 2026.1112.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.
@@ -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 { useQuery as t } from "@tanstack/react-query";
4
- import { graphqlFetch as n } from "@burdenoff/fe-libs/shared/graphql";
5
- import { clearGraphqlFetchResponseCache as r } from "@burdenoff/fe-libs/shared/graphql/fetch";
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 i = 21600, a = {
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 o(e, t, i) {
16
- let a = await n({
16
+ async function s(e, t, n) {
17
+ let a = await r({
17
18
  gateway: "workspace",
18
- baseUrl: i,
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) && r(), a.data;
26
+ return /^\s*mutation\b/.test(e) && i(), a.data;
26
27
  }
27
- var s = "\n mutation CooEnsureFolder($path: String!) {\n ensureFolderByPath(path: $path) { id }\n }\n", c = "\n mutation CooInitiateUpload($input: InitiateUploadInput!) {\n initiateUpload(input: $input) {\n uploadUrl\n session { id }\n }\n }\n", l = "\n mutation CooCompleteUpload($input: CompleteUploadInput!) {\n completeUpload(input: $input) {\n fileId\n file { id name }\n }\n }\n", u = "\n query CooGetFileDownloadUrl($id: ID!, $expiresIn: Int) {\n getFileDownloadUrl(id: $id, expiresIn: $expiresIn)\n }\n";
28
- function d(e, t) {
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 f(e, t, n, r) {
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 p(e, t, n = a.items, r) {
52
- let p = e.type || "application/octet-stream", m = String(e.size), h;
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
- h = (await o(s, { path: n }, t)).ensureFolderByPath?.id ?? void 0;
55
+ v = (await s(c, { path: r }, n)).ensureFolderByPath?.id ?? void 0;
55
56
  } catch {
56
- h = void 0;
57
+ v = void 0;
57
58
  }
58
- let g = await o(c, { input: {
59
+ let y = await s(l, { input: {
59
60
  fileName: e.name,
60
- extension: d(e.name, p),
61
- fileSize: m,
62
- mimeType: p,
63
- ...h ? { folderId: h } : {}
64
- } }, t), _ = g.initiateUpload?.uploadUrl, v = g.initiateUpload?.session.id;
65
- if (!_ || !v) throw Error("The files service did not return an upload URL.");
66
- await f(_, e, p, r);
67
- let y = await o(l, { input: {
68
- sessionId: v,
69
- fileSize: m,
70
- ...h ? { folderId: h } : {}
71
- } }, t), b = y.completeUpload?.file, x = y.completeUpload?.fileId ?? b?.id;
72
- if (!x) throw Error("The upload could not be finalized.");
73
- let S = "";
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
- S = (await o(u, {
76
- id: x,
77
- expiresIn: i
78
- }, t)).getFileDownloadUrl ?? "";
77
+ T = (await s(d, {
78
+ id: w,
79
+ expiresIn: a
80
+ }, n)).getFileDownloadUrl ?? "";
79
81
  } catch {
80
- S = "";
82
+ T = "";
81
83
  }
82
84
  return {
83
- id: x,
84
- url: S,
85
- name: b?.name ?? e.name
85
+ id: w,
86
+ url: T,
87
+ name: C?.name ?? e.name
86
88
  };
87
89
  }
88
- async function m(e, t, n = a.items) {
89
- return p(e, t, n);
90
+ async function h(e, t, n = o.items, r) {
91
+ return m(e, t, n, void 0, r);
90
92
  }
91
- async function h(e, t, n = a.items, r) {
92
- return p(e, t, n, r);
93
+ async function g(e, t, n = o.items, r, i) {
94
+ return m(e, t, n, r, i);
93
95
  }
94
- function g(n) {
96
+ function _(t) {
95
97
  let { apiGatewayUrl: r } = e();
96
- return t({
98
+ return n({
97
99
  queryKey: [
98
100
  "coolandlovely",
99
101
  "file-url",
100
- n ?? ""
102
+ t ?? ""
101
103
  ],
102
- enabled: !!n,
104
+ enabled: !!t,
103
105
  staleTime: 12e5,
104
106
  retry: 1,
105
- queryFn: async () => (await o(u, {
106
- id: n,
107
- expiresIn: i
107
+ queryFn: async () => (await s(d, {
108
+ id: t,
109
+ expiresIn: a
108
110
  }, r)).getFileDownloadUrl ?? null
109
111
  });
110
112
  }
111
- export { a as COO_FILE_FOLDERS, m as uploadImageToFiles, h as uploadImageToFilesWithProgress, g as useFileUrl };
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,
@@ -200,6 +200,7 @@ function j() {
200
200
  className: "mt-4"
201
201
  }),
202
202
  /* @__PURE__ */ w(u, {
203
+ allowWorkspace: !0,
203
204
  label: "Cover image",
204
205
  aspect: "wide",
205
206
  value: z.coverFileId,
@@ -213,6 +213,7 @@ function M() {
213
213
  className: "mt-4"
214
214
  }),
215
215
  /* @__PURE__ */ D(d, {
216
+ allowWorkspace: !0,
216
217
  label: "Product photo",
217
218
  value: B.imageFileId,
218
219
  onChange: (e) => G("imageFileId", e),
@@ -92,6 +92,7 @@ function E() {
92
92
  className: "mt-4"
93
93
  }),
94
94
  /* @__PURE__ */ S(d, {
95
+ allowWorkspace: !0,
95
96
  label: D("coolandlovely.field.coverImage", "Cover image"),
96
97
  aspect: "wide",
97
98
  value: B,
@@ -128,6 +128,7 @@ function x() {
128
128
  className: "mt-4"
129
129
  }),
130
130
  /* @__PURE__ */ g(ee, {
131
+ allowWorkspace: !0,
131
132
  label: "Look photo",
132
133
  aspect: "wide",
133
134
  value: L,
@@ -213,6 +213,7 @@ function w() {
213
213
  className: "mt-4"
214
214
  }),
215
215
  /* @__PURE__ */ y(i, {
216
+ allowWorkspace: !1,
216
217
  label: "Photo",
217
218
  value: D.imageFileId,
218
219
  onChange: (e) => N("imageFileId", e),
@@ -0,0 +1,10 @@
1
+ type GraphQLErrorLike = {
2
+ message: string;
3
+ extensions?: Record<string, unknown>;
4
+ };
5
+ export type CoolAndLovelyQuotaError = {
6
+ graphQLErrors: GraphQLErrorLike[];
7
+ };
8
+ /** Keep plain graphqlFetch errors compatible with shared quota handling. */
9
+ export declare function findQuotaExhaustedError(errors: readonly GraphQLErrorLike[] | undefined): CoolAndLovelyQuotaError | null;
10
+ export {};
@@ -0,0 +1,5 @@
1
+ // src/coolandlovely/utils/quota.ts
2
+ function e(e) {
3
+ return e?.some((e) => e.extensions?.code === "QUOTA_EXHAUSTED") ? { graphQLErrors: [...e] } : null;
4
+ }
5
+ export { e as findQuotaExhaustedError };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@burdenoff/microfe-coolandlovely",
3
- "version": "2026.1110.3",
3
+ "version": "2026.1112.2",
4
4
  "description": "Burdenoff CoolAndLovely Microfrontend",
5
5
  "type": "module",
6
6
  "files": [