@burdenoff/microfe-brainyrich 2026.825.1 → 2026.827.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.
Files changed (29) hide show
  1. package/dist/brainyrich/components/reuse/DocumentsPanel.d.ts +4 -0
  2. package/dist/brainyrich/components/reuse/DocumentsPanel.d.ts.map +1 -1
  3. package/dist/brainyrich/components/reuse/DocumentsPanel.js +150 -99
  4. package/dist/brainyrich/components/reuse/DocumentsPanel.js.map +1 -1
  5. package/dist/brainyrich/hooks/useBrainyRichApi.d.ts +176 -0
  6. package/dist/brainyrich/hooks/useBrainyRichApi.d.ts.map +1 -1
  7. package/dist/brainyrich/hooks/useBrainyRichApi.js +96 -82
  8. package/dist/brainyrich/hooks/useBrainyRichApi.js.map +1 -1
  9. package/dist/brainyrich/pages/AdminFirmPage.d.ts.map +1 -1
  10. package/dist/brainyrich/pages/AdminFirmPage.js +115 -83
  11. package/dist/brainyrich/pages/AdminFirmPage.js.map +1 -1
  12. package/dist/brainyrich/pages/AiAssistantPage.d.ts.map +1 -1
  13. package/dist/brainyrich/pages/AiAssistantPage.js +251 -230
  14. package/dist/brainyrich/pages/AiAssistantPage.js.map +1 -1
  15. package/dist/brainyrich/pages/FirmPage.d.ts.map +1 -1
  16. package/dist/brainyrich/pages/FirmPage.js +148 -116
  17. package/dist/brainyrich/pages/FirmPage.js.map +1 -1
  18. package/dist/brainyrich/pages/PortfoliosPage.d.ts +14 -0
  19. package/dist/brainyrich/pages/PortfoliosPage.d.ts.map +1 -1
  20. package/dist/brainyrich/pages/PortfoliosPage.js +530 -353
  21. package/dist/brainyrich/pages/PortfoliosPage.js.map +1 -1
  22. package/dist/brainyrich/pages/RiskPage.d.ts.map +1 -1
  23. package/dist/brainyrich/pages/RiskPage.js +381 -396
  24. package/dist/brainyrich/pages/RiskPage.js.map +1 -1
  25. package/dist/brainyrich/pages/_shared.d.ts +21 -0
  26. package/dist/brainyrich/pages/_shared.d.ts.map +1 -1
  27. package/dist/brainyrich/pages/_shared.js +66 -31
  28. package/dist/brainyrich/pages/_shared.js.map +1 -1
  29. package/package.json +1 -1
@@ -14,8 +14,12 @@
14
14
  * first upload via `createFolder`); no side-effects on read.
15
15
  * - list → `getFilesInFolder(folderId, pagination)`
16
16
  * - upload (3-step) → `initiateUpload` → S3 `PUT` (byte-progress) → `completeUpload`
17
+ * reachable by click OR by dropping a file on the zone; both take one file,
18
+ * which is exactly what the single-file upload mutation supports.
17
19
  * - download → `getFileDownloadUrl(id, expiresIn)` capped at 21600s to
18
20
  * avoid the >604800 fleet bug (S3 7-day cap → 500).
21
+ * - delete → `deleteFile(id)` (RBAC `delete`/`file`, enforced at the
22
+ * gateway) behind a confirm step.
19
23
  *
20
24
  * Presentational + self-contained: owns its hooks, reads the gateway base URL
21
25
  * from `useBrainyRich()`, uses fe-libs/ui primitives + semantic tokens.
@@ -1 +1 @@
1
- {"version":3,"file":"DocumentsPanel.d.ts","sourceRoot":"","sources":["../../../../src/brainyrich/components/reuse/DocumentsPanel.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAkOH,MAAM,WAAW,mBAAmB;IAClC,mFAAmF;IACnF,UAAU,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,wBAAgB,cAAc,CAAC,EAC7B,UAAU,EACV,QAAQ,EACR,OAAqB,EACrB,WAAmB,GACpB,EAAE,mBAAmB,2CA0IrB"}
1
+ {"version":3,"file":"DocumentsPanel.d.ts","sourceRoot":"","sources":["../../../../src/brainyrich/components/reuse/DocumentsPanel.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAyPH,MAAM,WAAW,mBAAmB;IAClC,mFAAmF;IACnF,UAAU,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,wBAAgB,cAAc,CAAC,EAC7B,UAAU,EACV,QAAQ,EACR,OAAqB,EACrB,WAAmB,GACpB,EAAE,mBAAmB,2CAmNrB"}
@@ -1,39 +1,40 @@
1
1
  import { useBrainyRich as e } from "../../providers/BrainyRichProvider.js";
2
- import { formatDate as t } from "../../pages/_shared.js";
3
- import { wspaceFetch as n, wspaceMutate as r } from "./transport.js";
4
- import { useCallback as i, useRef as a, useState as o } from "react";
5
- import { Download as s, FileText as c, Upload as l } from "lucide-react";
6
- import { useMutation as u, useQuery as d, useQueryClient as f } from "@tanstack/react-query";
7
- import { jsx as p, jsxs as m } from "react/jsx-runtime";
8
- import { Button as h, Card as g, CardContent as _, Skeleton as v } from "@burdenoff/fe-libs/ui";
2
+ import { ConfirmDialog as t } from "../ConfirmDialog.js";
3
+ import { formatDate as n } from "../../pages/_shared.js";
4
+ import { wspaceFetch as r, wspaceMutate as i } from "./transport.js";
5
+ import { useCallback as a, useRef as o, useState as s } from "react";
6
+ import { Download as c, FileText as l, Trash2 as u, Upload as d, UploadCloud as f } from "lucide-react";
7
+ import { useMutation as p, useQuery as m, useQueryClient as h } from "@tanstack/react-query";
8
+ import { jsx as g, jsxs as _ } from "react/jsx-runtime";
9
+ import { Button as v, Card as y, CardContent as b, Skeleton as x } from "@burdenoff/fe-libs/ui";
9
10
  //#region src/brainyrich/components/reuse/DocumentsPanel.tsx
10
- var y = 21600, b = "id name extension mimeType size createdAt", x = (e, t) => `BrainyRich · ${e} · ${t}`, S = (e, t) => [
11
+ var S = 21600, C = "id name extension mimeType size createdAt", w = (e, t) => `BrainyRich · ${e} · ${t}`, T = (e, t) => [
11
12
  "brainyrich",
12
13
  "entity-folder",
13
14
  e,
14
15
  t
15
- ], C = (e) => [
16
+ ], E = (e) => [
16
17
  "brainyrich",
17
18
  "folder-files",
18
19
  e ?? "none"
19
- ], w = (t, r) => {
20
- let { apiGatewayUrl: i } = e(), a = r ? x(t, r) : "";
21
- return d({
22
- queryKey: S(t, r ?? ""),
23
- enabled: !!r,
24
- queryFn: async () => (await n("query BraGetFolders($pagination: PaginationInput) {\n getFolders(pagination: $pagination) { folders { id name } }\n }", { pagination: {
20
+ ], D = (t, n) => {
21
+ let { apiGatewayUrl: i } = e(), a = n ? w(t, n) : "";
22
+ return m({
23
+ queryKey: T(t, n ?? ""),
24
+ enabled: !!n,
25
+ queryFn: async () => (await r("query BraGetFolders($pagination: PaginationInput) {\n getFolders(pagination: $pagination) { folders { id name } }\n }", { pagination: {
25
26
  limit: 200,
26
27
  offset: 0
27
28
  } }, i)).getFolders.folders.find((e) => e.name === a) ?? null
28
29
  });
29
- }, T = (t) => {
30
- let { apiGatewayUrl: r } = e();
31
- return d({
32
- queryKey: C(t),
30
+ }, O = (t) => {
31
+ let { apiGatewayUrl: n } = e();
32
+ return m({
33
+ queryKey: E(t),
33
34
  enabled: !!t,
34
- queryFn: async () => (await n(`query BraGetFilesInFolder($folderId: ID, $pagination: PaginationInput) {
35
+ queryFn: async () => (await r(`query BraGetFilesInFolder($folderId: ID, $pagination: PaginationInput) {
35
36
  getFilesInFolder(folderId: $folderId, pagination: $pagination) {
36
- files { ${b} }
37
+ files { ${C} }
37
38
  }
38
39
  }`, {
39
40
  folderId: t,
@@ -41,10 +42,10 @@ var y = 21600, b = "id name extension mimeType size createdAt", x = (e, t) => `B
41
42
  limit: 100,
42
43
  offset: 0
43
44
  }
44
- }, r)).getFilesInFolder.files
45
+ }, n)).getFilesInFolder.files
45
46
  });
46
47
  };
47
- function E(e, t, n, r) {
48
+ function k(e, t, n, r) {
48
49
  return new Promise((i, a) => {
49
50
  let o = new XMLHttpRequest();
50
51
  o.open("PUT", e), o.setRequestHeader("Content-Type", n), o.upload.onprogress = (e) => {
@@ -52,22 +53,22 @@ function E(e, t, n, r) {
52
53
  }, o.onload = () => o.status >= 200 && o.status < 300 ? i() : a(/* @__PURE__ */ Error(`File storage rejected the upload (HTTP ${o.status}).`)), o.onerror = () => a(/* @__PURE__ */ Error("Network error while uploading the file.")), o.onabort = () => a(/* @__PURE__ */ Error("The upload was cancelled.")), o.send(t);
53
54
  });
54
55
  }
55
- var D = (t, i) => {
56
- let { apiGatewayUrl: a } = e(), s = f(), [c, l] = o(0);
56
+ var A = (t, n) => {
57
+ let { apiGatewayUrl: a } = e(), o = h(), [c, l] = s(0);
57
58
  return {
58
- ...u({
59
+ ...p({
59
60
  mutationFn: async (e) => {
60
61
  l(0);
61
- let o = await n("query BraResolveFolder($pagination: PaginationInput) {\n getFolders(pagination: $pagination) { folders { id name } }\n }", { pagination: {
62
+ let o = await r("query BraResolveFolder($pagination: PaginationInput) {\n getFolders(pagination: $pagination) { folders { id name } }\n }", { pagination: {
62
63
  limit: 200,
63
64
  offset: 0
64
- } }, a).then((e) => e.getFolders.folders.find((e) => e.name === x(t, i)));
65
- o ||= (await r("mutation BraCreateFolder($input: CreateFolderInput!) {\n createFolder(input: $input) { id name }\n }", { input: {
66
- name: x(t, i),
67
- description: `Documents attached to ${t} ${i}.`,
65
+ } }, a).then((e) => e.getFolders.folders.find((e) => e.name === w(t, n)));
66
+ o ||= (await i("mutation BraCreateFolder($input: CreateFolderInput!) {\n createFolder(input: $input) { id name }\n }", { input: {
67
+ name: w(t, n),
68
+ description: `Documents attached to ${t} ${n}.`,
68
69
  visibility: "WORKSPACE"
69
70
  } }, a)).createFolder;
70
- let s = o.id, c = e.name.lastIndexOf("."), u = c > -1 ? e.name.slice(c + 1) : "", d = e.type || "application/octet-stream", f = String(e.size), p = await r("mutation BraInitiateUpload($input: InitiateUploadInput!) {\n initiateUpload(input: $input) { uploadUrl session { id } }\n }", { input: {
71
+ let s = o.id, c = e.name.lastIndexOf("."), u = c > -1 ? e.name.slice(c + 1) : "", d = e.type || "application/octet-stream", f = String(e.size), p = await i("mutation BraInitiateUpload($input: InitiateUploadInput!) {\n initiateUpload(input: $input) { uploadUrl session { id } }\n }", { input: {
71
72
  fileName: e.name,
72
73
  extension: u,
73
74
  mimeType: d,
@@ -76,147 +77,182 @@ var D = (t, i) => {
76
77
  visibility: "WORKSPACE"
77
78
  } }, a), { uploadUrl: m } = p.initiateUpload, h = p.initiateUpload.session.id;
78
79
  if (!m) throw Error("The file service did not return an upload URL.");
79
- return await E(m, e, d, l), await r("mutation BraCompleteUpload($input: CompleteUploadInput!) {\n completeUpload(input: $input) { fileId }\n }", { input: {
80
+ return await k(m, e, d, l), await i("mutation BraCompleteUpload($input: CompleteUploadInput!) {\n completeUpload(input: $input) { fileId }\n }", { input: {
80
81
  sessionId: h,
81
82
  fileSize: f,
82
83
  folderId: s
83
84
  } }, a), l(100), s;
84
85
  },
85
86
  onSuccess: (e) => {
86
- s.invalidateQueries({ queryKey: S(t, i) }), s.invalidateQueries({ queryKey: C(e) });
87
+ o.invalidateQueries({ queryKey: T(t, n) }), o.invalidateQueries({ queryKey: E(e) });
87
88
  }
88
89
  }),
89
90
  progress: c
90
91
  };
91
- }, O = () => {
92
+ }, j = () => {
92
93
  let { apiGatewayUrl: t } = e();
93
- return u({ mutationFn: async (e) => (await n("query BraGetFileDownloadUrl($id: ID!, $expiresIn: Int) {\n getFileDownloadUrl(id: $id, expiresIn: $expiresIn)\n }", {
94
+ return p({ mutationFn: async (e) => (await r("query BraGetFileDownloadUrl($id: ID!, $expiresIn: Int) {\n getFileDownloadUrl(id: $id, expiresIn: $expiresIn)\n }", {
94
95
  id: e,
95
- expiresIn: y
96
+ expiresIn: S
96
97
  }, t)).getFileDownloadUrl });
97
- }, k = (e) => {
98
+ }, M = (t) => {
99
+ let { apiGatewayUrl: n } = e(), r = h();
100
+ return p({
101
+ mutationFn: async (e) => (await i("mutation BraDeleteFile($id: ID!) { deleteFile(id: $id) }", { id: e }, n)).deleteFile,
102
+ onSuccess: () => r.invalidateQueries({ queryKey: E(t) })
103
+ });
104
+ }, N = (e) => {
98
105
  let t = Number(e);
99
106
  return !Number.isFinite(t) || t <= 0 ? "—" : t < 1024 ? `${t} B` : t < 1024 * 1024 ? `${(t / 1024).toFixed(0)} KB` : `${(t / (1024 * 1024)).toFixed(1)} MB`;
100
107
  };
101
- function A({ entityType: e, entityId: n, heading: r = "Documents", hideHeading: o = !1 }) {
102
- let u = a(null), d = w(e, n), f = T(d.data?.id), y = D(e, n), b = O(), x = i((e) => {
108
+ function P({ entityType: e, entityId: r, heading: i = "Documents", hideHeading: p = !1 }) {
109
+ let m = o(null), h = D(e, r), S = O(h.data?.id), C = A(e, r), w = j(), T = M(h.data?.id), [E, k] = s(!1), [P, F] = s(null), I = a((e) => {
103
110
  let t = e.target.files?.[0];
104
- t && y.mutate(t), e.target.value = "";
105
- }, [y]), S = async (e) => {
106
- let t = await b.mutateAsync(e);
111
+ t && C.mutate(t), e.target.value = "";
112
+ }, [C]), L = a((e) => {
113
+ if (e.preventDefault(), k(!1), C.isPending) return;
114
+ let t = e.dataTransfer.files?.[0];
115
+ t && C.mutate(t);
116
+ }, [C]), R = async (e) => {
117
+ let t = await w.mutateAsync(e);
107
118
  t && window.open(t, "_blank", "noopener,noreferrer");
108
- }, C = d.isLoading || !!d.data && f.isLoading, E = f.data ?? [];
109
- return /* @__PURE__ */ m("div", {
119
+ }, z = h.isLoading || !!h.data && S.isLoading, B = S.data ?? [];
120
+ return /* @__PURE__ */ _("div", {
110
121
  className: "space-y-3",
111
122
  children: [
112
- /* @__PURE__ */ m("div", {
123
+ /* @__PURE__ */ _("div", {
113
124
  className: "flex items-center justify-between",
114
- children: [!o && /* @__PURE__ */ m("h3", {
125
+ children: [!p && /* @__PURE__ */ _("h3", {
115
126
  className: "flex items-center gap-2 text-sm font-semibold text-text-primary",
116
- children: [/* @__PURE__ */ p(c, {
127
+ children: [/* @__PURE__ */ g(l, {
117
128
  className: "size-4",
118
129
  "aria-hidden": "true"
119
- }), r]
120
- }), /* @__PURE__ */ m("div", {
130
+ }), i]
131
+ }), /* @__PURE__ */ _("div", {
121
132
  className: "ml-auto",
122
- children: [/* @__PURE__ */ p("input", {
123
- ref: u,
133
+ children: [/* @__PURE__ */ g("input", {
134
+ ref: m,
124
135
  type: "file",
125
136
  className: "sr-only",
126
137
  "aria-hidden": "true",
127
138
  tabIndex: -1,
128
- onChange: x
129
- }), /* @__PURE__ */ m(h, {
139
+ onChange: I
140
+ }), /* @__PURE__ */ _(v, {
130
141
  type: "button",
131
142
  size: "sm",
132
143
  variant: "outline",
133
- onClick: () => u.current?.click(),
134
- disabled: y.isPending,
135
- children: [/* @__PURE__ */ p(l, {
144
+ onClick: () => m.current?.click(),
145
+ disabled: C.isPending,
146
+ children: [/* @__PURE__ */ g(d, {
136
147
  className: "size-4",
137
148
  "aria-hidden": "true"
138
- }), y.isPending ? `Uploading ${y.progress}%` : "Upload"]
149
+ }), C.isPending ? `Uploading ${C.progress}%` : "Upload"]
139
150
  })]
140
151
  })]
141
152
  }),
142
- y.isPending && /* @__PURE__ */ p("div", {
153
+ C.isPending && /* @__PURE__ */ g("div", {
143
154
  className: "h-1.5 w-full overflow-hidden rounded-full bg-bg-sunken",
144
155
  role: "progressbar",
145
156
  "aria-label": "Upload progress",
146
- "aria-valuenow": y.progress,
157
+ "aria-valuenow": C.progress,
147
158
  "aria-valuemin": 0,
148
159
  "aria-valuemax": 100,
149
- children: /* @__PURE__ */ p("div", {
160
+ children: /* @__PURE__ */ g("div", {
150
161
  className: "h-full rounded-full bg-primary motion-safe:transition-[width] motion-safe:duration-200",
151
- style: { width: `${y.progress}%` }
162
+ style: { width: `${C.progress}%` }
152
163
  })
153
164
  }),
154
- C ? /* @__PURE__ */ m("div", {
165
+ /* @__PURE__ */ _("button", {
166
+ type: "button",
167
+ onClick: () => m.current?.click(),
168
+ disabled: C.isPending,
169
+ onDragOver: (e) => {
170
+ e.preventDefault(), C.isPending || k(!0);
171
+ },
172
+ onDragLeave: () => k(!1),
173
+ onDrop: L,
174
+ className: `w-full rounded-lg border border-dashed px-4 py-8 text-center transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-action-primary-border)] disabled:cursor-not-allowed disabled:opacity-60 ${E ? "border-[var(--color-action-primary-border)] bg-bg-elevated" : "border-border-subtle bg-bg-surface hover:border-[var(--color-action-primary-border)]"}`,
175
+ children: [
176
+ /* @__PURE__ */ g(f, {
177
+ className: "mx-auto mb-2 size-6 text-text-secondary",
178
+ "aria-hidden": "true"
179
+ }),
180
+ /* @__PURE__ */ g("span", {
181
+ className: "block text-sm text-text-primary",
182
+ children: "Drop a statement, KYC or tax document here"
183
+ }),
184
+ /* @__PURE__ */ g("span", {
185
+ className: "mt-0.5 block text-xs text-text-secondary",
186
+ children: "or click to choose one file"
187
+ })
188
+ ]
189
+ }),
190
+ z ? /* @__PURE__ */ _("div", {
155
191
  className: "space-y-2",
156
192
  "aria-busy": "true",
157
- children: [/* @__PURE__ */ p(v, { className: "h-12 w-full rounded-md" }), /* @__PURE__ */ p(v, { className: "h-12 w-full rounded-md" })]
158
- }) : f.isError ? /* @__PURE__ */ m("p", {
193
+ children: [/* @__PURE__ */ g(x, { className: "h-12 w-full rounded-md" }), /* @__PURE__ */ g(x, { className: "h-12 w-full rounded-md" })]
194
+ }) : S.isError ? /* @__PURE__ */ _("p", {
159
195
  className: "text-sm text-status-error-text",
160
196
  children: [
161
197
  "Could not load documents.",
162
198
  " ",
163
- /* @__PURE__ */ p("button", {
199
+ /* @__PURE__ */ g("button", {
164
200
  type: "button",
165
201
  className: "underline underline-offset-2",
166
- onClick: () => f.refetch(),
202
+ onClick: () => S.refetch(),
167
203
  children: "Retry"
168
204
  })
169
205
  ]
170
- }) : E.length === 0 ? /* @__PURE__ */ m("div", {
171
- className: "rounded-lg border border-dashed border-border-subtle bg-bg-surface px-4 py-8 text-center",
172
- children: [
173
- /* @__PURE__ */ p(c, {
174
- className: "mx-auto mb-2 size-6 text-text-secondary",
175
- "aria-hidden": "true"
176
- }),
177
- /* @__PURE__ */ p("p", {
178
- className: "text-sm text-text-primary",
179
- children: "No documents yet"
180
- }),
181
- /* @__PURE__ */ p("p", {
182
- className: "mt-0.5 text-xs text-text-secondary",
183
- children: "Upload statements, KYC or tax documents for this record."
184
- })
185
- ]
186
- }) : /* @__PURE__ */ p("ul", {
206
+ }) : B.length === 0 ? /* @__PURE__ */ g("p", {
207
+ className: "text-center text-xs text-text-secondary",
208
+ children: "No documents attached to this record yet."
209
+ }) : /* @__PURE__ */ g("ul", {
187
210
  className: "space-y-2",
188
- children: E.map((e) => /* @__PURE__ */ p("li", { children: /* @__PURE__ */ p(g, { children: /* @__PURE__ */ m(_, {
211
+ children: B.map((e) => /* @__PURE__ */ g("li", { children: /* @__PURE__ */ g(y, { children: /* @__PURE__ */ _(b, {
189
212
  className: "flex items-center gap-3 p-3",
190
213
  children: [
191
- /* @__PURE__ */ p("div", {
214
+ /* @__PURE__ */ g("div", {
192
215
  className: "flex size-9 shrink-0 items-center justify-center rounded-md bg-bg-sunken text-text-secondary",
193
- children: /* @__PURE__ */ p(c, {
216
+ children: /* @__PURE__ */ g(l, {
194
217
  className: "size-4",
195
218
  "aria-hidden": "true"
196
219
  })
197
220
  }),
198
- /* @__PURE__ */ m("div", {
221
+ /* @__PURE__ */ _("div", {
199
222
  className: "min-w-0 flex-1",
200
- children: [/* @__PURE__ */ p("p", {
223
+ children: [/* @__PURE__ */ g("p", {
201
224
  className: "truncate text-sm font-medium text-text-primary",
202
225
  children: e.name
203
- }), /* @__PURE__ */ m("p", {
226
+ }), /* @__PURE__ */ _("p", {
204
227
  className: "text-xs text-text-secondary",
205
228
  children: [
206
- k(e.size),
229
+ N(e.size),
207
230
  " · ",
208
- t(e.createdAt)
231
+ n(e.createdAt)
209
232
  ]
210
233
  })]
211
234
  }),
212
- /* @__PURE__ */ p(h, {
235
+ /* @__PURE__ */ g(v, {
213
236
  type: "button",
214
237
  size: "sm",
215
238
  variant: "ghost",
216
239
  "aria-label": `Download ${e.name}`,
217
- disabled: b.isPending,
218
- onClick: () => S(e.id),
219
- children: /* @__PURE__ */ p(s, {
240
+ disabled: w.isPending,
241
+ onClick: () => R(e.id),
242
+ children: /* @__PURE__ */ g(c, {
243
+ className: "size-4",
244
+ "aria-hidden": "true"
245
+ })
246
+ }),
247
+ /* @__PURE__ */ g(v, {
248
+ type: "button",
249
+ size: "sm",
250
+ variant: "ghost",
251
+ className: "text-status-error-text hover:text-status-error-text",
252
+ "aria-label": `Delete ${e.name}`,
253
+ disabled: T.isPending,
254
+ onClick: () => F(e),
255
+ children: /* @__PURE__ */ g(u, {
220
256
  className: "size-4",
221
257
  "aria-hidden": "true"
222
258
  })
@@ -224,14 +260,29 @@ function A({ entityType: e, entityId: n, heading: r = "Documents", hideHeading:
224
260
  ]
225
261
  }) }) }, e.id))
226
262
  }),
227
- (y.isError || b.isError) && /* @__PURE__ */ p("p", {
263
+ (C.isError || w.isError || T.isError) && /* @__PURE__ */ g("p", {
228
264
  className: "text-sm text-status-error-text",
229
- children: y.error instanceof Error ? y.error.message : b.error instanceof Error ? "Could not open the document. Please try again." : "Something went wrong. Please try again."
265
+ children: C.error instanceof Error ? C.error.message : T.error instanceof Error ? `Could not delete the document. ${T.error.message}` : w.error instanceof Error ? "Could not open the document. Please try again." : "Something went wrong. Please try again."
266
+ }),
267
+ /* @__PURE__ */ g(t, {
268
+ open: P !== null,
269
+ onOpenChange: (e) => {
270
+ e || F(null);
271
+ },
272
+ title: "Delete this document?",
273
+ description: P ? `“${P.name}” will be removed from this record. This cannot be undone.` : void 0,
274
+ confirmLabel: "Delete",
275
+ pendingLabel: "Deleting…",
276
+ destructive: !0,
277
+ pending: T.isPending,
278
+ onConfirm: () => {
279
+ P && T.mutate(P.id, { onSuccess: () => F(null) });
280
+ }
230
281
  })
231
282
  ]
232
283
  });
233
284
  }
234
285
  //#endregion
235
- export { A as DocumentsPanel };
286
+ export { P as DocumentsPanel };
236
287
 
237
288
  //# sourceMappingURL=DocumentsPanel.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DocumentsPanel.js","names":[],"sources":["../../../../src/brainyrich/components/reuse/DocumentsPanel.tsx"],"sourcesContent":["/**\n * DocumentsPanel — REUSE of `wspace-files-svc` for statement / KYC / tax-doc\n * attachments on Accounts + Households.\n * @module brainyrich/components/reuse/DocumentsPanel\n *\n * A wealth product needs to attach documents (statements, KYC, tax packs) to\n * accounts and households. `wspace-files-svc` has no native entity-owned link on\n * `File`, so we scope documents to an entity via a dedicated, stably-named\n * FOLDER per `(entityType, entityId)` and list its contents. All ops route\n * through the workspace supergraph the MFE already uses.\n *\n * Flow:\n * - resolve folder → `getFolders(filter)` matched by name (created lazily on\n * first upload via `createFolder`); no side-effects on read.\n * - list → `getFilesInFolder(folderId, pagination)`\n * - upload (3-step) → `initiateUpload` → S3 `PUT` (byte-progress) → `completeUpload`\n * - download → `getFileDownloadUrl(id, expiresIn)` capped at 21600s to\n * avoid the >604800 fleet bug (S3 7-day cap → 500).\n *\n * Presentational + self-contained: owns its hooks, reads the gateway base URL\n * from `useBrainyRich()`, uses fe-libs/ui primitives + semantic tokens.\n */\n\nimport { useCallback, useRef, useState } from 'react';\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';\nimport { Download, FileText, Upload } from 'lucide-react';\nimport { Button, Card, CardContent, Skeleton } from '@burdenoff/fe-libs/ui';\n\nimport { useBrainyRich } from '../../providers/BrainyRichProvider';\nimport { formatDate } from '../../pages/_shared';\nimport { wspaceFetch, wspaceMutate } from './transport';\n\n// Presigned-URL TTL: cap at 21600s (6h). >604800 (S3 7-day) → INTERNAL_SERVER_ERROR.\nconst DOWNLOAD_URL_TTL_SECONDS = 21600;\n\ninterface FilesFolder {\n id: string;\n name: string;\n}\n\ninterface FilesFile {\n id: string;\n name: string;\n extension: string;\n mimeType: string;\n size: string;\n createdAt: string;\n}\n\nconst FILE_FIELDS = 'id name extension mimeType size createdAt';\n\nconst folderName = (entityType: string, entityId: string) =>\n `BrainyRich · ${entityType} · ${entityId}`;\n\nconst folderKey = (entityType: string, entityId: string) =>\n ['brainyrich', 'entity-folder', entityType, entityId] as const;\n\nconst filesKey = (folderId: string | null | undefined) =>\n ['brainyrich', 'folder-files', folderId ?? 'none'] as const;\n\n// ============================================================================\n// Folder resolution (read-only — no lazy creation here)\n// ============================================================================\n\nconst useEntityFolder = (entityType: string, entityId: string | undefined) => {\n const { apiGatewayUrl } = useBrainyRich();\n const wanted = entityId ? folderName(entityType, entityId) : '';\n return useQuery({\n queryKey: folderKey(entityType, entityId ?? ''),\n enabled: Boolean(entityId),\n queryFn: async () => {\n const data = await wspaceFetch<{ getFolders: { folders: FilesFolder[] } }>(\n `query BraGetFolders($pagination: PaginationInput) {\n getFolders(pagination: $pagination) { folders { id name } }\n }`,\n { pagination: { limit: 200, offset: 0 } },\n apiGatewayUrl\n );\n return data.getFolders.folders.find((f) => f.name === wanted) ?? null;\n },\n });\n};\n\nconst useFolderFiles = (folderId: string | null | undefined) => {\n const { apiGatewayUrl } = useBrainyRich();\n return useQuery({\n queryKey: filesKey(folderId),\n enabled: Boolean(folderId),\n queryFn: async () => {\n const data = await wspaceFetch<{ getFilesInFolder: { files: FilesFile[] } }>(\n `query BraGetFilesInFolder($folderId: ID, $pagination: PaginationInput) {\n getFilesInFolder(folderId: $folderId, pagination: $pagination) {\n files { ${FILE_FIELDS} }\n }\n }`,\n { folderId, pagination: { limit: 100, offset: 0 } },\n apiGatewayUrl\n );\n return data.getFilesInFolder.files;\n },\n });\n};\n\n// ============================================================================\n// Upload (3-step platform flow, with lazy folder creation)\n// ============================================================================\n\nfunction putWithProgress(\n url: string,\n file: File,\n contentType: string,\n onProgress: (percent: number) => void\n): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n const xhr = new XMLHttpRequest();\n xhr.open('PUT', url);\n xhr.setRequestHeader('Content-Type', contentType);\n xhr.upload.onprogress = (event) => {\n if (event.lengthComputable) {\n onProgress(Math.round((event.loaded / event.total) * 100));\n }\n };\n xhr.onload = () =>\n xhr.status >= 200 && xhr.status < 300\n ? resolve()\n : reject(new Error(`File storage rejected the upload (HTTP ${xhr.status}).`));\n xhr.onerror = () => reject(new Error('Network error while uploading the file.'));\n xhr.onabort = () => reject(new Error('The upload was cancelled.'));\n xhr.send(file);\n });\n}\n\nconst useDocumentUpload = (entityType: string, entityId: string) => {\n const { apiGatewayUrl } = useBrainyRich();\n const qc = useQueryClient();\n const [progress, setProgress] = useState(0);\n\n const mutation = useMutation({\n mutationFn: async (file: File) => {\n setProgress(0);\n\n // 0. resolve or create the entity folder\n let folder = await wspaceFetch<{ getFolders: { folders: FilesFolder[] } }>(\n `query BraResolveFolder($pagination: PaginationInput) {\n getFolders(pagination: $pagination) { folders { id name } }\n }`,\n { pagination: { limit: 200, offset: 0 } },\n apiGatewayUrl\n ).then((d) => d.getFolders.folders.find((f) => f.name === folderName(entityType, entityId)));\n\n if (!folder) {\n const created = await wspaceMutate<{ createFolder: FilesFolder }>(\n `mutation BraCreateFolder($input: CreateFolderInput!) {\n createFolder(input: $input) { id name }\n }`,\n {\n input: {\n name: folderName(entityType, entityId),\n description: `Documents attached to ${entityType} ${entityId}.`,\n visibility: 'WORKSPACE',\n },\n },\n apiGatewayUrl\n );\n folder = created.createFolder;\n }\n const folderId = folder.id;\n\n const dotIndex = file.name.lastIndexOf('.');\n const extension = dotIndex > -1 ? file.name.slice(dotIndex + 1) : '';\n const mimeType = file.type || 'application/octet-stream';\n const fileSize = String(file.size);\n\n // 1. initiate\n const initiated = await wspaceMutate<{\n initiateUpload: { uploadUrl: string | null; session: { id: string } };\n }>(\n `mutation BraInitiateUpload($input: InitiateUploadInput!) {\n initiateUpload(input: $input) { uploadUrl session { id } }\n }`,\n {\n input: {\n fileName: file.name,\n extension,\n mimeType,\n fileSize,\n folderId,\n visibility: 'WORKSPACE',\n },\n },\n apiGatewayUrl\n );\n const { uploadUrl } = initiated.initiateUpload;\n const sessionId = initiated.initiateUpload.session.id;\n if (!uploadUrl) throw new Error('The file service did not return an upload URL.');\n\n // 2. PUT the bytes\n await putWithProgress(uploadUrl, file, mimeType, setProgress);\n\n // 3. complete\n await wspaceMutate<{ completeUpload: { fileId: string } }>(\n `mutation BraCompleteUpload($input: CompleteUploadInput!) {\n completeUpload(input: $input) { fileId }\n }`,\n { input: { sessionId, fileSize, folderId } },\n apiGatewayUrl\n );\n setProgress(100);\n return folderId;\n },\n onSuccess: (folderId) => {\n qc.invalidateQueries({ queryKey: folderKey(entityType, entityId) });\n qc.invalidateQueries({ queryKey: filesKey(folderId) });\n },\n });\n\n return { ...mutation, progress };\n};\n\nconst useDownloadFile = () => {\n const { apiGatewayUrl } = useBrainyRich();\n return useMutation({\n mutationFn: async (id: string) => {\n const data = await wspaceFetch<{ getFileDownloadUrl: string }>(\n `query BraGetFileDownloadUrl($id: ID!, $expiresIn: Int) {\n getFileDownloadUrl(id: $id, expiresIn: $expiresIn)\n }`,\n { id, expiresIn: DOWNLOAD_URL_TTL_SECONDS },\n apiGatewayUrl\n );\n return data.getFileDownloadUrl;\n },\n });\n};\n\n// ============================================================================\n// Component\n// ============================================================================\n\nconst formatSize = (bytes: string): string => {\n const n = Number(bytes);\n if (!Number.isFinite(n) || n <= 0) return '—';\n if (n < 1024) return `${n} B`;\n if (n < 1024 * 1024) return `${(n / 1024).toFixed(0)} KB`;\n return `${(n / (1024 * 1024)).toFixed(1)} MB`;\n};\n\nexport interface DocumentsPanelProps {\n /** Polymorphic entity type, e.g. \"brainyrich-account\" | \"brainyrich-household\". */\n entityType: string;\n /** The bra entity's id (an ID scalar). */\n entityId: string;\n /** Optional heading; hide with `hideHeading`. */\n heading?: string;\n hideHeading?: boolean;\n}\n\nexport function DocumentsPanel({\n entityType,\n entityId,\n heading = 'Documents',\n hideHeading = false,\n}: DocumentsPanelProps) {\n const inputRef = useRef<HTMLInputElement>(null);\n const folder = useEntityFolder(entityType, entityId);\n const files = useFolderFiles(folder.data?.id);\n const upload = useDocumentUpload(entityType, entityId);\n const download = useDownloadFile();\n\n const onPick = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const file = e.target.files?.[0];\n if (file) upload.mutate(file);\n e.target.value = '';\n },\n [upload]\n );\n\n const onDownload = async (id: string) => {\n const url = await download.mutateAsync(id);\n if (url) window.open(url, '_blank', 'noopener,noreferrer');\n };\n\n const loading = folder.isLoading || (Boolean(folder.data) && files.isLoading);\n const list = files.data ?? [];\n\n return (\n <div className=\"space-y-3\">\n <div className=\"flex items-center justify-between\">\n {!hideHeading && (\n <h3 className=\"flex items-center gap-2 text-sm font-semibold text-text-primary\">\n <FileText className=\"size-4\" aria-hidden=\"true\" />\n {heading}\n </h3>\n )}\n <div className=\"ml-auto\">\n <input\n ref={inputRef}\n type=\"file\"\n className=\"sr-only\"\n aria-hidden=\"true\"\n tabIndex={-1}\n onChange={onPick}\n />\n <Button\n type=\"button\"\n size=\"sm\"\n variant=\"outline\"\n onClick={() => inputRef.current?.click()}\n disabled={upload.isPending}\n >\n <Upload className=\"size-4\" aria-hidden=\"true\" />\n {upload.isPending ? `Uploading ${upload.progress}%` : 'Upload'}\n </Button>\n </div>\n </div>\n\n {upload.isPending && (\n <div\n className=\"h-1.5 w-full overflow-hidden rounded-full bg-bg-sunken\"\n role=\"progressbar\"\n aria-label=\"Upload progress\"\n aria-valuenow={upload.progress}\n aria-valuemin={0}\n aria-valuemax={100}\n >\n <div\n className=\"h-full rounded-full bg-primary motion-safe:transition-[width] motion-safe:duration-200\"\n style={{ width: `${upload.progress}%` }}\n />\n </div>\n )}\n\n {loading ? (\n <div className=\"space-y-2\" aria-busy=\"true\">\n <Skeleton className=\"h-12 w-full rounded-md\" />\n <Skeleton className=\"h-12 w-full rounded-md\" />\n </div>\n ) : files.isError ? (\n <p className=\"text-sm text-status-error-text\">\n Could not load documents.{' '}\n <button\n type=\"button\"\n className=\"underline underline-offset-2\"\n onClick={() => files.refetch()}\n >\n Retry\n </button>\n </p>\n ) : list.length === 0 ? (\n <div className=\"rounded-lg border border-dashed border-border-subtle bg-bg-surface px-4 py-8 text-center\">\n <FileText className=\"mx-auto mb-2 size-6 text-text-secondary\" aria-hidden=\"true\" />\n <p className=\"text-sm text-text-primary\">No documents yet</p>\n <p className=\"mt-0.5 text-xs text-text-secondary\">\n Upload statements, KYC or tax documents for this record.\n </p>\n </div>\n ) : (\n <ul className=\"space-y-2\">\n {list.map((file) => (\n <li key={file.id}>\n <Card>\n <CardContent className=\"flex items-center gap-3 p-3\">\n <div className=\"flex size-9 shrink-0 items-center justify-center rounded-md bg-bg-sunken text-text-secondary\">\n <FileText className=\"size-4\" aria-hidden=\"true\" />\n </div>\n <div className=\"min-w-0 flex-1\">\n <p className=\"truncate text-sm font-medium text-text-primary\">{file.name}</p>\n <p className=\"text-xs text-text-secondary\">\n {formatSize(file.size)} · {formatDate(file.createdAt)}\n </p>\n </div>\n <Button\n type=\"button\"\n size=\"sm\"\n variant=\"ghost\"\n aria-label={`Download ${file.name}`}\n disabled={download.isPending}\n onClick={() => onDownload(file.id)}\n >\n <Download className=\"size-4\" aria-hidden=\"true\" />\n </Button>\n </CardContent>\n </Card>\n </li>\n ))}\n </ul>\n )}\n\n {(upload.isError || download.isError) && (\n <p className=\"text-sm text-status-error-text\">\n {upload.error instanceof Error\n ? upload.error.message\n : download.error instanceof Error\n ? 'Could not open the document. Please try again.'\n : 'Something went wrong. Please try again.'}\n </p>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AAiCA,IAAM,IAA2B,OAgB3B,IAAc,6CAEd,KAAc,GAAoB,MACtC,gBAAgB,EAAW,KAAK,KAE5B,KAAa,GAAoB,MACrC;CAAC;CAAc;CAAiB;CAAY;AAAQ,GAEhD,KAAY,MAChB;CAAC;CAAc;CAAgB,KAAY;AAAM,GAM7C,KAAmB,GAAoB,MAAiC;CAC5E,IAAM,EAAE,qBAAkB,EAAc,GAClC,IAAS,IAAW,EAAW,GAAY,CAAQ,IAAI;CAC7D,OAAO,EAAS;EACd,UAAU,EAAU,GAAY,KAAY,EAAE;EAC9C,SAAS,EA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EAAK,IAAI;SAAE;SAAI,EAAW,EAAK,SAAS;QACnD;SACA;;MACL,kBAAC,GAAD;OACE,MAAK;OACL,MAAK;OACL,SAAQ;OACR,cAAY,YAAY,EAAK;OAC7B,UAAU,EAAS;OACnB,eAAe,EAAW,EAAK,EAAE;iBAEjC,kBAAC,GAAD;QAAU,WAAU;QAAS,eAAY;OAAQ,CAAA;MAC3C,CAAA;KACG;OACT,CAAA,EACJ,GAxBK,EAAK,EAwBV,CACL;GACC,CAAA;IAGJ,EAAO,WAAW,EAAS,YAC3B,kBAAC,KAAD;IAAG,WAAU;cACV,EAAO,iBAAiB,QACrB,EAAO,MAAM,UACb,EAAS,iBAAiB,QACxB,mDACA;GACL,CAAA;EAEF;;AAET"}
1
+ {"version":3,"file":"DocumentsPanel.js","names":[],"sources":["../../../../src/brainyrich/components/reuse/DocumentsPanel.tsx"],"sourcesContent":["/**\n * DocumentsPanel — REUSE of `wspace-files-svc` for statement / KYC / tax-doc\n * attachments on Accounts + Households.\n * @module brainyrich/components/reuse/DocumentsPanel\n *\n * A wealth product needs to attach documents (statements, KYC, tax packs) to\n * accounts and households. `wspace-files-svc` has no native entity-owned link on\n * `File`, so we scope documents to an entity via a dedicated, stably-named\n * FOLDER per `(entityType, entityId)` and list its contents. All ops route\n * through the workspace supergraph the MFE already uses.\n *\n * Flow:\n * - resolve folder → `getFolders(filter)` matched by name (created lazily on\n * first upload via `createFolder`); no side-effects on read.\n * - list → `getFilesInFolder(folderId, pagination)`\n * - upload (3-step) → `initiateUpload` → S3 `PUT` (byte-progress) → `completeUpload`\n * reachable by click OR by dropping a file on the zone; both take one file,\n * which is exactly what the single-file upload mutation supports.\n * - download → `getFileDownloadUrl(id, expiresIn)` capped at 21600s to\n * avoid the >604800 fleet bug (S3 7-day cap → 500).\n * - delete → `deleteFile(id)` (RBAC `delete`/`file`, enforced at the\n * gateway) behind a confirm step.\n *\n * Presentational + self-contained: owns its hooks, reads the gateway base URL\n * from `useBrainyRich()`, uses fe-libs/ui primitives + semantic tokens.\n */\n\nimport { useCallback, useRef, useState } from 'react';\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';\nimport { Download, FileText, Trash2, Upload, UploadCloud } from 'lucide-react';\nimport { Button, Card, CardContent, Skeleton } from '@burdenoff/fe-libs/ui';\n\nimport { useBrainyRich } from '../../providers/BrainyRichProvider';\nimport { formatDate } from '../../pages/_shared';\nimport { ConfirmDialog } from '../ConfirmDialog';\nimport { wspaceFetch, wspaceMutate } from './transport';\n\n// Presigned-URL TTL: cap at 21600s (6h). >604800 (S3 7-day) → INTERNAL_SERVER_ERROR.\nconst DOWNLOAD_URL_TTL_SECONDS = 21600;\n\ninterface FilesFolder {\n id: string;\n name: string;\n}\n\ninterface FilesFile {\n id: string;\n name: string;\n extension: string;\n mimeType: string;\n size: string;\n createdAt: string;\n}\n\nconst FILE_FIELDS = 'id name extension mimeType size createdAt';\n\nconst folderName = (entityType: string, entityId: string) =>\n `BrainyRich · ${entityType} · ${entityId}`;\n\nconst folderKey = (entityType: string, entityId: string) =>\n ['brainyrich', 'entity-folder', entityType, entityId] as const;\n\nconst filesKey = (folderId: string | null | undefined) =>\n ['brainyrich', 'folder-files', folderId ?? 'none'] as const;\n\n// ============================================================================\n// Folder resolution (read-only — no lazy creation here)\n// ============================================================================\n\nconst useEntityFolder = (entityType: string, entityId: string | undefined) => {\n const { apiGatewayUrl } = useBrainyRich();\n const wanted = entityId ? folderName(entityType, entityId) : '';\n return useQuery({\n queryKey: folderKey(entityType, entityId ?? ''),\n enabled: Boolean(entityId),\n queryFn: async () => {\n const data = await wspaceFetch<{ getFolders: { folders: FilesFolder[] } }>(\n `query BraGetFolders($pagination: PaginationInput) {\n getFolders(pagination: $pagination) { folders { id name } }\n }`,\n { pagination: { limit: 200, offset: 0 } },\n apiGatewayUrl\n );\n return data.getFolders.folders.find((f) => f.name === wanted) ?? null;\n },\n });\n};\n\nconst useFolderFiles = (folderId: string | null | undefined) => {\n const { apiGatewayUrl } = useBrainyRich();\n return useQuery({\n queryKey: filesKey(folderId),\n enabled: Boolean(folderId),\n queryFn: async () => {\n const data = await wspaceFetch<{ getFilesInFolder: { files: FilesFile[] } }>(\n `query BraGetFilesInFolder($folderId: ID, $pagination: PaginationInput) {\n getFilesInFolder(folderId: $folderId, pagination: $pagination) {\n files { ${FILE_FIELDS} }\n }\n }`,\n { folderId, pagination: { limit: 100, offset: 0 } },\n apiGatewayUrl\n );\n return data.getFilesInFolder.files;\n },\n });\n};\n\n// ============================================================================\n// Upload (3-step platform flow, with lazy folder creation)\n// ============================================================================\n\nfunction putWithProgress(\n url: string,\n file: File,\n contentType: string,\n onProgress: (percent: number) => void\n): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n const xhr = new XMLHttpRequest();\n xhr.open('PUT', url);\n xhr.setRequestHeader('Content-Type', contentType);\n xhr.upload.onprogress = (event) => {\n if (event.lengthComputable) {\n onProgress(Math.round((event.loaded / event.total) * 100));\n }\n };\n xhr.onload = () =>\n xhr.status >= 200 && xhr.status < 300\n ? resolve()\n : reject(new Error(`File storage rejected the upload (HTTP ${xhr.status}).`));\n xhr.onerror = () => reject(new Error('Network error while uploading the file.'));\n xhr.onabort = () => reject(new Error('The upload was cancelled.'));\n xhr.send(file);\n });\n}\n\nconst useDocumentUpload = (entityType: string, entityId: string) => {\n const { apiGatewayUrl } = useBrainyRich();\n const qc = useQueryClient();\n const [progress, setProgress] = useState(0);\n\n const mutation = useMutation({\n mutationFn: async (file: File) => {\n setProgress(0);\n\n // 0. resolve or create the entity folder\n let folder = await wspaceFetch<{ getFolders: { folders: FilesFolder[] } }>(\n `query BraResolveFolder($pagination: PaginationInput) {\n getFolders(pagination: $pagination) { folders { id name } }\n }`,\n { pagination: { limit: 200, offset: 0 } },\n apiGatewayUrl\n ).then((d) => d.getFolders.folders.find((f) => f.name === folderName(entityType, entityId)));\n\n if (!folder) {\n const created = await wspaceMutate<{ createFolder: FilesFolder }>(\n `mutation BraCreateFolder($input: CreateFolderInput!) {\n createFolder(input: $input) { id name }\n }`,\n {\n input: {\n name: folderName(entityType, entityId),\n description: `Documents attached to ${entityType} ${entityId}.`,\n visibility: 'WORKSPACE',\n },\n },\n apiGatewayUrl\n );\n folder = created.createFolder;\n }\n const folderId = folder.id;\n\n const dotIndex = file.name.lastIndexOf('.');\n const extension = dotIndex > -1 ? file.name.slice(dotIndex + 1) : '';\n const mimeType = file.type || 'application/octet-stream';\n const fileSize = String(file.size);\n\n // 1. initiate\n const initiated = await wspaceMutate<{\n initiateUpload: { uploadUrl: string | null; session: { id: string } };\n }>(\n `mutation BraInitiateUpload($input: InitiateUploadInput!) {\n initiateUpload(input: $input) { uploadUrl session { id } }\n }`,\n {\n input: {\n fileName: file.name,\n extension,\n mimeType,\n fileSize,\n folderId,\n visibility: 'WORKSPACE',\n },\n },\n apiGatewayUrl\n );\n const { uploadUrl } = initiated.initiateUpload;\n const sessionId = initiated.initiateUpload.session.id;\n if (!uploadUrl) throw new Error('The file service did not return an upload URL.');\n\n // 2. PUT the bytes\n await putWithProgress(uploadUrl, file, mimeType, setProgress);\n\n // 3. complete\n await wspaceMutate<{ completeUpload: { fileId: string } }>(\n `mutation BraCompleteUpload($input: CompleteUploadInput!) {\n completeUpload(input: $input) { fileId }\n }`,\n { input: { sessionId, fileSize, folderId } },\n apiGatewayUrl\n );\n setProgress(100);\n return folderId;\n },\n onSuccess: (folderId) => {\n qc.invalidateQueries({ queryKey: folderKey(entityType, entityId) });\n qc.invalidateQueries({ queryKey: filesKey(folderId) });\n },\n });\n\n return { ...mutation, progress };\n};\n\nconst useDownloadFile = () => {\n const { apiGatewayUrl } = useBrainyRich();\n return useMutation({\n mutationFn: async (id: string) => {\n const data = await wspaceFetch<{ getFileDownloadUrl: string }>(\n `query BraGetFileDownloadUrl($id: ID!, $expiresIn: Int) {\n getFileDownloadUrl(id: $id, expiresIn: $expiresIn)\n }`,\n { id, expiresIn: DOWNLOAD_URL_TTL_SECONDS },\n apiGatewayUrl\n );\n return data.getFileDownloadUrl;\n },\n });\n};\n\n/**\n * Remove one document. `deleteFile(id: ID!): Boolean!` is a real mutation on the\n * files subgraph of the same workspace supergraph; the gateway enforces its\n * `delete`/`file` @rbac directive, so a caller without the right gets a GraphQL\n * error surfaced below rather than a silently ignored click.\n */\nconst useDeleteFile = (folderId: string | null | undefined) => {\n const { apiGatewayUrl } = useBrainyRich();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: async (id: string) => {\n const data = await wspaceMutate<{ deleteFile: boolean }>(\n `mutation BraDeleteFile($id: ID!) { deleteFile(id: $id) }`,\n { id },\n apiGatewayUrl\n );\n return data.deleteFile;\n },\n onSuccess: () => qc.invalidateQueries({ queryKey: filesKey(folderId) }),\n });\n};\n\n// ============================================================================\n// Component\n// ============================================================================\n\nconst formatSize = (bytes: string): string => {\n const n = Number(bytes);\n if (!Number.isFinite(n) || n <= 0) return '—';\n if (n < 1024) return `${n} B`;\n if (n < 1024 * 1024) return `${(n / 1024).toFixed(0)} KB`;\n return `${(n / (1024 * 1024)).toFixed(1)} MB`;\n};\n\nexport interface DocumentsPanelProps {\n /** Polymorphic entity type, e.g. \"brainyrich-account\" | \"brainyrich-household\". */\n entityType: string;\n /** The bra entity's id (an ID scalar). */\n entityId: string;\n /** Optional heading; hide with `hideHeading`. */\n heading?: string;\n hideHeading?: boolean;\n}\n\nexport function DocumentsPanel({\n entityType,\n entityId,\n heading = 'Documents',\n hideHeading = false,\n}: DocumentsPanelProps) {\n const inputRef = useRef<HTMLInputElement>(null);\n const folder = useEntityFolder(entityType, entityId);\n const files = useFolderFiles(folder.data?.id);\n const upload = useDocumentUpload(entityType, entityId);\n const download = useDownloadFile();\n const remove = useDeleteFile(folder.data?.id);\n\n const [dragActive, setDragActive] = useState(false);\n const [fileToDelete, setFileToDelete] = useState<FilesFile | null>(null);\n\n const onPick = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const file = e.target.files?.[0];\n if (file) upload.mutate(file);\n e.target.value = '';\n },\n [upload]\n );\n\n // The upload mutation handles one file per call, so the drop zone accepts one\n // — matching the picker, which is deliberately not `multiple`.\n const onDrop = useCallback(\n (e: React.DragEvent<HTMLElement>) => {\n e.preventDefault();\n setDragActive(false);\n if (upload.isPending) return;\n const file = e.dataTransfer.files?.[0];\n if (file) upload.mutate(file);\n },\n [upload]\n );\n\n const onDownload = async (id: string) => {\n const url = await download.mutateAsync(id);\n if (url) window.open(url, '_blank', 'noopener,noreferrer');\n };\n\n const loading = folder.isLoading || (Boolean(folder.data) && files.isLoading);\n const list = files.data ?? [];\n\n return (\n <div className=\"space-y-3\">\n <div className=\"flex items-center justify-between\">\n {!hideHeading && (\n <h3 className=\"flex items-center gap-2 text-sm font-semibold text-text-primary\">\n <FileText className=\"size-4\" aria-hidden=\"true\" />\n {heading}\n </h3>\n )}\n <div className=\"ml-auto\">\n <input\n ref={inputRef}\n type=\"file\"\n className=\"sr-only\"\n aria-hidden=\"true\"\n tabIndex={-1}\n onChange={onPick}\n />\n <Button\n type=\"button\"\n size=\"sm\"\n variant=\"outline\"\n onClick={() => inputRef.current?.click()}\n disabled={upload.isPending}\n >\n <Upload className=\"size-4\" aria-hidden=\"true\" />\n {upload.isPending ? `Uploading ${upload.progress}%` : 'Upload'}\n </Button>\n </div>\n </div>\n\n {upload.isPending && (\n <div\n className=\"h-1.5 w-full overflow-hidden rounded-full bg-bg-sunken\"\n role=\"progressbar\"\n aria-label=\"Upload progress\"\n aria-valuenow={upload.progress}\n aria-valuemin={0}\n aria-valuemax={100}\n >\n <div\n className=\"h-full rounded-full bg-primary motion-safe:transition-[width] motion-safe:duration-200\"\n style={{ width: `${upload.progress}%` }}\n />\n </div>\n )}\n\n {/* Drop target — same single-file upload path as the picker button */}\n <button\n type=\"button\"\n onClick={() => inputRef.current?.click()}\n disabled={upload.isPending}\n onDragOver={(e) => {\n e.preventDefault();\n if (!upload.isPending) setDragActive(true);\n }}\n onDragLeave={() => setDragActive(false)}\n onDrop={onDrop}\n className={`w-full rounded-lg border border-dashed px-4 py-8 text-center transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-action-primary-border)] disabled:cursor-not-allowed disabled:opacity-60 ${\n dragActive\n ? 'border-[var(--color-action-primary-border)] bg-bg-elevated'\n : 'border-border-subtle bg-bg-surface hover:border-[var(--color-action-primary-border)]'\n }`}\n >\n <UploadCloud className=\"mx-auto mb-2 size-6 text-text-secondary\" aria-hidden=\"true\" />\n <span className=\"block text-sm text-text-primary\">\n Drop a statement, KYC or tax document here\n </span>\n <span className=\"mt-0.5 block text-xs text-text-secondary\">\n or click to choose one file\n </span>\n </button>\n\n {loading ? (\n <div className=\"space-y-2\" aria-busy=\"true\">\n <Skeleton className=\"h-12 w-full rounded-md\" />\n <Skeleton className=\"h-12 w-full rounded-md\" />\n </div>\n ) : files.isError ? (\n <p className=\"text-sm text-status-error-text\">\n Could not load documents.{' '}\n <button\n type=\"button\"\n className=\"underline underline-offset-2\"\n onClick={() => files.refetch()}\n >\n Retry\n </button>\n </p>\n ) : list.length === 0 ? (\n <p className=\"text-center text-xs text-text-secondary\">\n No documents attached to this record yet.\n </p>\n ) : (\n <ul className=\"space-y-2\">\n {list.map((file) => (\n <li key={file.id}>\n <Card>\n <CardContent className=\"flex items-center gap-3 p-3\">\n <div className=\"flex size-9 shrink-0 items-center justify-center rounded-md bg-bg-sunken text-text-secondary\">\n <FileText className=\"size-4\" aria-hidden=\"true\" />\n </div>\n <div className=\"min-w-0 flex-1\">\n <p className=\"truncate text-sm font-medium text-text-primary\">{file.name}</p>\n <p className=\"text-xs text-text-secondary\">\n {formatSize(file.size)} · {formatDate(file.createdAt)}\n </p>\n </div>\n <Button\n type=\"button\"\n size=\"sm\"\n variant=\"ghost\"\n aria-label={`Download ${file.name}`}\n disabled={download.isPending}\n onClick={() => onDownload(file.id)}\n >\n <Download className=\"size-4\" aria-hidden=\"true\" />\n </Button>\n <Button\n type=\"button\"\n size=\"sm\"\n variant=\"ghost\"\n className=\"text-status-error-text hover:text-status-error-text\"\n aria-label={`Delete ${file.name}`}\n disabled={remove.isPending}\n onClick={() => setFileToDelete(file)}\n >\n <Trash2 className=\"size-4\" aria-hidden=\"true\" />\n </Button>\n </CardContent>\n </Card>\n </li>\n ))}\n </ul>\n )}\n\n {(upload.isError || download.isError || remove.isError) && (\n <p className=\"text-sm text-status-error-text\">\n {upload.error instanceof Error\n ? upload.error.message\n : remove.error instanceof Error\n ? `Could not delete the document. ${remove.error.message}`\n : download.error instanceof Error\n ? 'Could not open the document. Please try again.'\n : 'Something went wrong. Please try again.'}\n </p>\n )}\n\n <ConfirmDialog\n open={fileToDelete !== null}\n onOpenChange={(open) => {\n if (!open) setFileToDelete(null);\n }}\n title=\"Delete this document?\"\n description={\n fileToDelete\n ? `“${fileToDelete.name}” will be removed from this record. This cannot be undone.`\n : undefined\n }\n confirmLabel=\"Delete\"\n pendingLabel=\"Deleting…\"\n destructive\n pending={remove.isPending}\n onConfirm={() => {\n if (!fileToDelete) return;\n remove.mutate(fileToDelete.id, { onSuccess: () => setFileToDelete(null) });\n }}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;AAsCA,IAAM,IAA2B,OAgB3B,IAAc,6CAEd,KAAc,GAAoB,MACtC,gBAAgB,EAAW,KAAK,KAE5B,KAAa,GAAoB,MACrC;CAAC;CAAc;CAAiB;CAAY;AAAQ,GAEhD,KAAY,MAChB;CAAC;CAAc;CAAgB,KAAY;AAAM,GAM7C,KAAmB,GAAoB,MAAiC;CAC5E,IAAM,EAAE,qBAAkB,EAAc,GAClC,IAAS,IAAW,EAAW,GAAY,CAAQ,IAAI;CAC7D,OAAO,EAAS;EACd,UAAU,EAAU,GAAY,KAAY,EAAE;EAC9C,SAAS,EAAQ;EACjB,SAAS,aAQA,MAPY,EACjB,yIAGA,EAAE,YAAY;GAAE,OAAO;GAAK,QAAQ;EAAE,EAAE,GACxC,CACF,GACY,WAAW,QAAQ,MAAM,MAAM,EAAE,SAAS,CAAM,KAAK;CAErE,CAAC;AACH,GAE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