@burdenoff/microfe-files 2026.1110.2 → 2026.1111.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.
Files changed (69) hide show
  1. package/dist/files/components/ActionMenu.d.ts +6 -0
  2. package/dist/files/components/ActionMenu.js +2 -1
  3. package/dist/files/components/ActionMenu.js.map +1 -1
  4. package/dist/files/components/ContextMenu.d.ts +6 -0
  5. package/dist/files/components/ContextMenu.js +2 -0
  6. package/dist/files/components/ContextMenu.js.map +1 -1
  7. package/dist/files/components/FileBrowser.d.ts +8 -2
  8. package/dist/files/components/FileBrowser.js +275 -238
  9. package/dist/files/components/FileBrowser.js.map +1 -1
  10. package/dist/files/components/FileCard.d.ts +5 -0
  11. package/dist/files/components/FileCard.js +98 -94
  12. package/dist/files/components/FileCard.js.map +1 -1
  13. package/dist/files/components/FileListItem.d.ts +5 -0
  14. package/dist/files/components/FileListItem.js +88 -87
  15. package/dist/files/components/FileListItem.js.map +1 -1
  16. package/dist/files/components/FilePreviewModal.d.ts +6 -1
  17. package/dist/files/components/FilePreviewModal.js +30 -29
  18. package/dist/files/components/FilePreviewModal.js.map +1 -1
  19. package/dist/files/components/FolderCard.d.ts +5 -0
  20. package/dist/files/components/FolderCard.js +108 -104
  21. package/dist/files/components/FolderCard.js.map +1 -1
  22. package/dist/files/components/ShareDialog.d.ts +12 -5
  23. package/dist/files/components/ShareDialog.js +348 -188
  24. package/dist/files/components/ShareDialog.js.map +1 -1
  25. package/dist/files/components/UploadQueue.js +1 -1
  26. package/dist/files/components/contextMenuItems.d.ts +32 -0
  27. package/dist/files/components/contextMenuItems.js +6 -2
  28. package/dist/files/components/contextMenuItems.js.map +1 -1
  29. package/dist/files/hooks/useBrowsePage.d.ts +10 -0
  30. package/dist/files/hooks/useCopyFile.d.ts +3 -0
  31. package/dist/files/hooks/useCreateFolder.d.ts +2 -0
  32. package/dist/files/hooks/useFoldersQuery.d.ts +1 -1
  33. package/dist/files/hooks/useKeyboardNavigation.js +57 -56
  34. package/dist/files/hooks/useKeyboardNavigation.js.map +1 -1
  35. package/dist/files/hooks/useMoveFile.d.ts +3 -0
  36. package/dist/files/hooks/useMoveFolder.d.ts +2 -0
  37. package/dist/files/hooks/useRenameFile.d.ts +3 -0
  38. package/dist/files/hooks/useRenameFolder.d.ts +2 -0
  39. package/dist/files/hooks/useRestoreFile.d.ts +3 -0
  40. package/dist/files/hooks/useRestoreFolder.d.ts +2 -0
  41. package/dist/files/hooks/useShareDialogPermission.d.ts +45 -0
  42. package/dist/files/hooks/useShareDialogPermission.js +31 -0
  43. package/dist/files/hooks/useShareDialogPermission.js.map +1 -0
  44. package/dist/files/hooks/useSharePermissions.d.ts +30 -0
  45. package/dist/files/hooks/useSharePermissions.js +81 -0
  46. package/dist/files/hooks/useSharePermissions.js.map +1 -0
  47. package/dist/files/hooks/useToggleStar.d.ts +5 -0
  48. package/dist/files/hooks/useUploadFile.d.ts +3 -0
  49. package/dist/files/pages/BrowserPage.js +353 -348
  50. package/dist/files/pages/BrowserPage.js.map +1 -1
  51. package/dist/files/types.d.ts +10 -2
  52. package/dist/files/utils/fileViewModel.js +7 -2
  53. package/dist/files/utils/fileViewModel.js.map +1 -1
  54. package/dist/files/utils/itemCapabilities.d.ts +84 -0
  55. package/dist/files/utils/itemCapabilities.js +54 -0
  56. package/dist/files/utils/itemCapabilities.js.map +1 -0
  57. package/dist/files/utils/sharePermission.d.ts +144 -0
  58. package/dist/files/utils/sharePermission.js +77 -0
  59. package/dist/files/utils/sharePermission.js.map +1 -0
  60. package/dist/generated/global-types.d.ts +6615 -870
  61. package/dist/generated/wspace-operations.d.ts +104 -0
  62. package/dist/generated/wspace-operations.js +1418 -39
  63. package/dist/generated/wspace-operations.js.map +1 -1
  64. package/dist/generated/wspace-types.d.ts +94395 -11225
  65. package/dist/generated/wspace-types.js.map +1 -1
  66. package/dist/translations/en.d.ts +16 -0
  67. package/dist/translations/en.js +16 -0
  68. package/dist/translations/en.js.map +1 -1
  69. package/package.json +2 -1
@@ -90,11 +90,17 @@ export interface FileItem {
90
90
  isFavorite?: boolean;
91
91
  isShared?: boolean;
92
92
  downloadUrl?: string;
93
+ /**
94
+ * Capabilities resolved per file by wspace-files-svc (BOFF-11801). Each is
95
+ * true only when both the service rule and the gateway's RBAC rule allow the
96
+ * matching operation; see `utils/itemCapabilities.ts` for what each gates.
97
+ */
93
98
  canRead?: boolean;
94
99
  canUpdate?: boolean;
95
- canWrite?: boolean;
96
100
  canDelete?: boolean;
97
101
  canShare?: boolean;
102
+ canMove?: boolean;
103
+ canCopy?: boolean;
98
104
  canAdmin?: boolean;
99
105
  }
100
106
  /**
@@ -126,10 +132,12 @@ export interface FolderItem {
126
132
  updatedAt: string;
127
133
  parentId?: string;
128
134
  subfolders?: FolderItem[];
135
+ /** Capabilities resolved per folder by wspace-files-svc (BOFF-11801). */
129
136
  canRead?: boolean;
130
137
  canUpdate?: boolean;
131
138
  canDelete?: boolean;
132
- permissions?: FolderPermissions;
139
+ canShare?: boolean;
140
+ canMove?: boolean;
133
141
  }
134
142
  /**
135
143
  * File permissions
@@ -12,7 +12,10 @@ function t(t) {
12
12
  downloadUrl: t.downloadUrl ?? void 0,
13
13
  canRead: t.canRead ?? void 0,
14
14
  canUpdate: t.canUpdate ?? void 0,
15
- canDelete: t.canDelete ?? void 0
15
+ canDelete: t.canDelete ?? void 0,
16
+ canShare: t.canShare ?? void 0,
17
+ canMove: t.canMove ?? void 0,
18
+ canCopy: t.canCopy ?? void 0
16
19
  };
17
20
  }
18
21
  function n(e) {
@@ -25,7 +28,9 @@ function n(e) {
25
28
  icon: e.icon ?? void 0,
26
29
  canRead: e.canRead ?? void 0,
27
30
  canUpdate: e.canUpdate ?? void 0,
28
- canDelete: e.canDelete ?? void 0
31
+ canDelete: e.canDelete ?? void 0,
32
+ canShare: e.canShare ?? void 0,
33
+ canMove: e.canMove ?? void 0
29
34
  };
30
35
  }
31
36
  export { e as browserFileSize, t as fileViewModel, n as folderViewModel };
@@ -1 +1 @@
1
- {"version":3,"file":"fileViewModel.js","names":["browserFileSize","size","fileViewModel","file","folderViewModel","folder"],"sources":["../../../src/files/utils/fileViewModel.ts"],"sourcesContent":["import type {\n FileCard_FileFragment,\n FilePreviewModal_FileFragment,\n FolderCard_FolderFragment,\n} from \"../../generated/wspace-operations\";\nimport type { FileItem, FolderItem } from \"../types\";\n\n/** Browser sizes use numbers; refuse an unrepresentable BigInt rather than round it. */\nexport function browserFileSize(size: string): number {\n if (\n !/^(0|[1-9][0-9]*)$/.test(size) ||\n BigInt(size) > BigInt(Number.MAX_SAFE_INTEGER)\n ) {\n throw new Error(\"File size cannot be represented safely\");\n }\n return Number(size);\n}\n\nexport function fileViewModel(\n file: FileCard_FileFragment & FilePreviewModal_FileFragment,\n): FileItem {\n return {\n ...file,\n size: browserFileSize(file.size),\n description: file.description ?? undefined,\n // Empty is an unavailable URL, never a synthesized location. Preview/download\n // callers must refuse it before creating a viewer, link, or native open request.\n url: file.downloadUrl ?? \"\",\n downloadUrl: file.downloadUrl ?? undefined,\n canRead: file.canRead ?? undefined,\n canUpdate: file.canUpdate ?? undefined,\n canDelete: file.canDelete ?? undefined,\n };\n}\n\nexport function folderViewModel(folder: FolderCard_FolderFragment): FolderItem {\n return {\n ...folder,\n description: folder.description ?? undefined,\n color: folder.color ?? undefined,\n filesCount: folder.filesCount ?? undefined,\n subfoldersCount: folder.subfoldersCount ?? undefined,\n icon: folder.icon ?? undefined,\n canRead: folder.canRead ?? undefined,\n canUpdate: folder.canUpdate ?? undefined,\n canDelete: folder.canDelete ?? undefined,\n };\n}\n"],"mappings":";AAQA,SAAgBA,EAAgB,GAAsB;CACpD,IACE,CAAC,oBAAoB,KAAKC,CAAI,KAC9B,OAAOA,CAAI,IAAI,kBAA8B,GAE7C,MAAU,MAAM,wCAAwC;CAE1D,OAAO,OAAOA,CAAI;AACpB;AAEA,SAAgBC,EACd,GACU;CACV,OAAO;EACL,GAAGC;EACH,MAAMH,EAAgBG,EAAK,IAAI;EAC/B,aAAaA,EAAK,eAAe,KAAA;EAGjC,KAAKA,EAAK,eAAe;EACzB,aAAaA,EAAK,eAAe,KAAA;EACjC,SAASA,EAAK,WAAW,KAAA;EACzB,WAAWA,EAAK,aAAa,KAAA;EAC7B,WAAWA,EAAK,aAAa,KAAA;CAC/B;AACF;AAEA,SAAgBC,EAAgB,GAA+C;CAC7E,OAAO;EACL,GAAGC;EACH,aAAaA,EAAO,eAAe,KAAA;EACnC,OAAOA,EAAO,SAAS,KAAA;EACvB,YAAYA,EAAO,cAAc,KAAA;EACjC,iBAAiBA,EAAO,mBAAmB,KAAA;EAC3C,MAAMA,EAAO,QAAQ,KAAA;EACrB,SAASA,EAAO,WAAW,KAAA;EAC3B,WAAWA,EAAO,aAAa,KAAA;EAC/B,WAAWA,EAAO,aAAa,KAAA;CACjC;AACF"}
1
+ {"version":3,"file":"fileViewModel.js","names":["browserFileSize","size","fileViewModel","file","folderViewModel","folder"],"sources":["../../../src/files/utils/fileViewModel.ts"],"sourcesContent":["import type {\n FileCard_FileFragment,\n FilePreviewModal_FileFragment,\n FolderCard_FolderFragment,\n} from \"../../generated/wspace-operations\";\nimport type { FileItem, FolderItem } from \"../types\";\n\n/** Browser sizes use numbers; refuse an unrepresentable BigInt rather than round it. */\nexport function browserFileSize(size: string): number {\n if (\n !/^(0|[1-9][0-9]*)$/.test(size) ||\n BigInt(size) > BigInt(Number.MAX_SAFE_INTEGER)\n ) {\n throw new Error(\"File size cannot be represented safely\");\n }\n return Number(size);\n}\n\nexport function fileViewModel(\n file: FileCard_FileFragment & FilePreviewModal_FileFragment,\n): FileItem {\n return {\n ...file,\n size: browserFileSize(file.size),\n description: file.description ?? undefined,\n // Empty is an unavailable URL, never a synthesized location. Preview/download\n // callers must refuse it before creating a viewer, link, or native open request.\n url: file.downloadUrl ?? \"\",\n downloadUrl: file.downloadUrl ?? undefined,\n canRead: file.canRead ?? undefined,\n canUpdate: file.canUpdate ?? undefined,\n canDelete: file.canDelete ?? undefined,\n canShare: file.canShare ?? undefined,\n canMove: file.canMove ?? undefined,\n canCopy: file.canCopy ?? undefined,\n };\n}\n\nexport function folderViewModel(folder: FolderCard_FolderFragment): FolderItem {\n return {\n ...folder,\n description: folder.description ?? undefined,\n color: folder.color ?? undefined,\n filesCount: folder.filesCount ?? undefined,\n subfoldersCount: folder.subfoldersCount ?? undefined,\n icon: folder.icon ?? undefined,\n canRead: folder.canRead ?? undefined,\n canUpdate: folder.canUpdate ?? undefined,\n canDelete: folder.canDelete ?? undefined,\n canShare: folder.canShare ?? undefined,\n canMove: folder.canMove ?? undefined,\n };\n}\n"],"mappings":";AAQA,SAAgBA,EAAgB,GAAsB;CACpD,IACE,CAAC,oBAAoB,KAAKC,CAAI,KAC9B,OAAOA,CAAI,IAAI,kBAA8B,GAE7C,MAAU,MAAM,wCAAwC;CAE1D,OAAO,OAAOA,CAAI;AACpB;AAEA,SAAgBC,EACd,GACU;CACV,OAAO;EACL,GAAGC;EACH,MAAMH,EAAgBG,EAAK,IAAI;EAC/B,aAAaA,EAAK,eAAe,KAAA;EAGjC,KAAKA,EAAK,eAAe;EACzB,aAAaA,EAAK,eAAe,KAAA;EACjC,SAASA,EAAK,WAAW,KAAA;EACzB,WAAWA,EAAK,aAAa,KAAA;EAC7B,WAAWA,EAAK,aAAa,KAAA;EAC7B,UAAUA,EAAK,YAAY,KAAA;EAC3B,SAASA,EAAK,WAAW,KAAA;EACzB,SAASA,EAAK,WAAW,KAAA;CAC3B;AACF;AAEA,SAAgBC,EAAgB,GAA+C;CAC7E,OAAO;EACL,GAAGC;EACH,aAAaA,EAAO,eAAe,KAAA;EACnC,OAAOA,EAAO,SAAS,KAAA;EACvB,YAAYA,EAAO,cAAc,KAAA;EACjC,iBAAiBA,EAAO,mBAAmB,KAAA;EAC3C,MAAMA,EAAO,QAAQ,KAAA;EACrB,SAASA,EAAO,WAAW,KAAA;EAC3B,WAAWA,EAAO,aAAa,KAAA;EAC/B,WAAWA,EAAO,aAAa,KAAA;EAC/B,UAAUA,EAAO,YAAY,KAAA;EAC7B,SAASA,EAAO,WAAW,KAAA;CAC7B;AACF"}
@@ -0,0 +1,84 @@
1
+ import { FileItem, FolderItem } from '../types';
2
+ import { ShareTarget } from './sharePermission';
3
+ /**
4
+ * Which actions the browser offers for a file or folder (BOFF-11801).
5
+ *
6
+ * wspace-files-svc resolves each capability field per item as "the service
7
+ * rule allows it AND the gateway's `@rbac` rule allows it for this actor and
8
+ * this resource", so every flag is the same answer the matching mutation will
9
+ * give. The browser therefore gates each action on its own flag and nothing
10
+ * else, and treats anything but a literal `true` (false, null when a field
11
+ * failed, undefined in older payloads) as "not allowed".
12
+ *
13
+ * - `canRead`: Preview a file; open a folder (and, with `canUpdate`, drop
14
+ * items onto it).
15
+ * - `canCopy` (files only): Copy, including a Ctrl/Cmd drag.
16
+ * - `canShare`: Share (see `ShareOffer` for a payload without it).
17
+ * - `canUpdate`: Rename, Star.
18
+ * - `canMove`: Move, including a plain drag.
19
+ * - `canDelete`: Delete, including the Delete/Backspace shortcut.
20
+ *
21
+ * Download and Restore are deliberately not gated on any flag: `File.canRead`
22
+ * only answers `getFile` (it promises neither a download URL nor a restore),
23
+ * and neither `File.canUpdate` nor `Folder.canUpdate` covers
24
+ * `restoreFile`/`restoreFolder`. Both are offered wherever the view provides
25
+ * a handler (the Bin for Restore), and the service's own answer decides, as
26
+ * it does for a folder copy, which no folder flag answers either.
27
+ */
28
+ export interface FileCapabilities {
29
+ canPreview: boolean;
30
+ canCopy: boolean;
31
+ canUpdate: boolean;
32
+ canMove: boolean;
33
+ canDelete: boolean;
34
+ share: ShareOffer;
35
+ }
36
+ export interface FolderCapabilities {
37
+ canOpen: boolean;
38
+ canUpdate: boolean;
39
+ canMove: boolean;
40
+ canDelete: boolean;
41
+ /** Whether the folder accepts dropped items (open it and change it). */
42
+ canAcceptDrop: boolean;
43
+ share: ShareOffer;
44
+ }
45
+ /**
46
+ * How Share is offered for an item.
47
+ *
48
+ * - `offered`: the payload carries `canShare: true`; Share is offered as is.
49
+ * - `hidden`: the payload carries `canShare: false`; Share is not offered.
50
+ * - `lazy`: the payload has no `canShare` (a field error, or an older
51
+ * payload). Share falls back to the BOFF-10039 behaviour: it is offered to
52
+ * anyone who can read the item and, for PRIVATE/TEAM files and every
53
+ * folder, SHARE is looked up on demand through `lookupTarget` so a denial
54
+ * can be marked. The share dialog re-checks either way.
55
+ */
56
+ export type ShareOffer = {
57
+ mode: "offered";
58
+ } | {
59
+ mode: "hidden";
60
+ } | {
61
+ mode: "lazy";
62
+ lookupTarget: ShareTarget | null;
63
+ };
64
+ export declare function fileCapabilities(file: FileItem): FileCapabilities;
65
+ export declare function folderCapabilities(folder: FolderItem): FolderCapabilities;
66
+ /** True when Share is offered at all (offered outright, or lazily). */
67
+ export declare function isShareOffered(offer: ShareOffer): boolean;
68
+ /**
69
+ * The SHARE lookup target for an item, or `null` when no lookup should run:
70
+ * the payload already answered (`offered`/`hidden`), or the item is a
71
+ * WORKSPACE/PUBLIC file in the lazy fallback.
72
+ */
73
+ export declare function shareLookupTarget(offer: ShareOffer): ShareTarget | null;
74
+ /**
75
+ * Whether a drag of a file may start. A dragged file is moved (`canMove`) or,
76
+ * with Ctrl/Cmd held, copied (`canCopy`).
77
+ */
78
+ export declare function canStartFileDrag(file: FileItem, operation: "move" | "copy"): boolean;
79
+ /**
80
+ * Whether a drag of a folder may start. Moving needs `canMove`; no folder flag
81
+ * answers a folder copy, so a copy keeps its previous behaviour (offered, and
82
+ * the service decides).
83
+ */
84
+ export declare function canStartFolderDrag(folder: FolderItem, operation: "move" | "copy"): boolean;
@@ -0,0 +1,54 @@
1
+ import { fileShareTarget as e, folderShareTarget as t } from "./sharePermission.js";
2
+ // src/files/utils/itemCapabilities.ts
3
+ function n(e) {
4
+ return e === !0 ? { mode: "offered" } : e === !1 ? { mode: "hidden" } : null;
5
+ }
6
+ function r(t) {
7
+ return n(t.canShare) || (t.canRead === !0 ? {
8
+ mode: "lazy",
9
+ lookupTarget: e(t)
10
+ } : { mode: "hidden" });
11
+ }
12
+ function i(e) {
13
+ return n(e.canShare) || (e.canRead === !0 ? {
14
+ mode: "lazy",
15
+ lookupTarget: t(e)
16
+ } : { mode: "hidden" });
17
+ }
18
+ function a(e) {
19
+ return {
20
+ canPreview: e.canRead === !0,
21
+ canCopy: e.canCopy === !0,
22
+ canUpdate: e.canUpdate === !0,
23
+ canMove: e.canMove === !0,
24
+ canDelete: e.canDelete === !0,
25
+ share: r(e)
26
+ };
27
+ }
28
+ function o(e) {
29
+ let t = e.canRead === !0, n = e.canUpdate === !0;
30
+ return {
31
+ canOpen: t,
32
+ canUpdate: n,
33
+ canMove: e.canMove === !0,
34
+ canDelete: e.canDelete === !0,
35
+ canAcceptDrop: t && n,
36
+ share: i(e)
37
+ };
38
+ }
39
+ function s(e) {
40
+ return e.mode !== "hidden";
41
+ }
42
+ function c(e) {
43
+ return e.mode === "lazy" ? e.lookupTarget : null;
44
+ }
45
+ function l(e, t) {
46
+ let n = a(e);
47
+ return t === "move" ? n.canMove : n.canCopy;
48
+ }
49
+ function u(e, t) {
50
+ return t !== "move" || o(e).canMove;
51
+ }
52
+ export { l as canStartFileDrag, u as canStartFolderDrag, a as fileCapabilities, o as folderCapabilities, s as isShareOffered, c as shareLookupTarget };
53
+
54
+ //# sourceMappingURL=itemCapabilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"itemCapabilities.js","names":["eagerShareOffer","canShare","fileShareOffer","file","fileShareTarget","folderShareOffer","folder","folderShareTarget","fileCapabilities","folderCapabilities","canOpen","canUpdate","isShareOffered","offer","shareLookupTarget","canStartFileDrag","caps","operation","canStartFolderDrag"],"sources":["../../../src/files/utils/itemCapabilities.ts"],"sourcesContent":["import type { FileItem, FolderItem } from \"../types\";\nimport {\n fileShareTarget,\n folderShareTarget,\n type ShareTarget,\n} from \"./sharePermission\";\n\n/**\n * Which actions the browser offers for a file or folder (BOFF-11801).\n *\n * wspace-files-svc resolves each capability field per item as \"the service\n * rule allows it AND the gateway's `@rbac` rule allows it for this actor and\n * this resource\", so every flag is the same answer the matching mutation will\n * give. The browser therefore gates each action on its own flag and nothing\n * else, and treats anything but a literal `true` (false, null when a field\n * failed, undefined in older payloads) as \"not allowed\".\n *\n * - `canRead`: Preview a file; open a folder (and, with `canUpdate`, drop\n * items onto it).\n * - `canCopy` (files only): Copy, including a Ctrl/Cmd drag.\n * - `canShare`: Share (see `ShareOffer` for a payload without it).\n * - `canUpdate`: Rename, Star.\n * - `canMove`: Move, including a plain drag.\n * - `canDelete`: Delete, including the Delete/Backspace shortcut.\n *\n * Download and Restore are deliberately not gated on any flag: `File.canRead`\n * only answers `getFile` (it promises neither a download URL nor a restore),\n * and neither `File.canUpdate` nor `Folder.canUpdate` covers\n * `restoreFile`/`restoreFolder`. Both are offered wherever the view provides\n * a handler (the Bin for Restore), and the service's own answer decides, as\n * it does for a folder copy, which no folder flag answers either.\n */\nexport interface FileCapabilities {\n canPreview: boolean;\n canCopy: boolean;\n canUpdate: boolean;\n canMove: boolean;\n canDelete: boolean;\n share: ShareOffer;\n}\n\nexport interface FolderCapabilities {\n canOpen: boolean;\n canUpdate: boolean;\n canMove: boolean;\n canDelete: boolean;\n /** Whether the folder accepts dropped items (open it and change it). */\n canAcceptDrop: boolean;\n share: ShareOffer;\n}\n\n/**\n * How Share is offered for an item.\n *\n * - `offered`: the payload carries `canShare: true`; Share is offered as is.\n * - `hidden`: the payload carries `canShare: false`; Share is not offered.\n * - `lazy`: the payload has no `canShare` (a field error, or an older\n * payload). Share falls back to the BOFF-10039 behaviour: it is offered to\n * anyone who can read the item and, for PRIVATE/TEAM files and every\n * folder, SHARE is looked up on demand through `lookupTarget` so a denial\n * can be marked. The share dialog re-checks either way.\n */\nexport type ShareOffer =\n | { mode: \"offered\" }\n | { mode: \"hidden\" }\n | { mode: \"lazy\"; lookupTarget: ShareTarget | null };\n\nfunction eagerShareOffer(\n canShare: boolean | null | undefined,\n): ShareOffer | null {\n if (canShare === true) return { mode: \"offered\" };\n if (canShare === false) return { mode: \"hidden\" };\n return null;\n}\n\nfunction fileShareOffer(file: FileItem): ShareOffer {\n const eager = eagerShareOffer(file.canShare);\n if (eager) return eager;\n if (file.canRead !== true) return { mode: \"hidden\" };\n return { mode: \"lazy\", lookupTarget: fileShareTarget(file) };\n}\n\nfunction folderShareOffer(folder: FolderItem): ShareOffer {\n const eager = eagerShareOffer(folder.canShare);\n if (eager) return eager;\n if (folder.canRead !== true) return { mode: \"hidden\" };\n return { mode: \"lazy\", lookupTarget: folderShareTarget(folder) };\n}\n\nexport function fileCapabilities(file: FileItem): FileCapabilities {\n return {\n canPreview: file.canRead === true,\n canCopy: file.canCopy === true,\n canUpdate: file.canUpdate === true,\n canMove: file.canMove === true,\n canDelete: file.canDelete === true,\n share: fileShareOffer(file),\n };\n}\n\nexport function folderCapabilities(folder: FolderItem): FolderCapabilities {\n const canOpen = folder.canRead === true;\n const canUpdate = folder.canUpdate === true;\n return {\n canOpen,\n canUpdate,\n canMove: folder.canMove === true,\n canDelete: folder.canDelete === true,\n canAcceptDrop: canOpen && canUpdate,\n share: folderShareOffer(folder),\n };\n}\n\n/** True when Share is offered at all (offered outright, or lazily). */\nexport function isShareOffered(offer: ShareOffer): boolean {\n return offer.mode !== \"hidden\";\n}\n\n/**\n * The SHARE lookup target for an item, or `null` when no lookup should run:\n * the payload already answered (`offered`/`hidden`), or the item is a\n * WORKSPACE/PUBLIC file in the lazy fallback.\n */\nexport function shareLookupTarget(offer: ShareOffer): ShareTarget | null {\n return offer.mode === \"lazy\" ? offer.lookupTarget : null;\n}\n\n/**\n * Whether a drag of a file may start. A dragged file is moved (`canMove`) or,\n * with Ctrl/Cmd held, copied (`canCopy`).\n */\nexport function canStartFileDrag(\n file: FileItem,\n operation: \"move\" | \"copy\",\n): boolean {\n const caps = fileCapabilities(file);\n return operation === \"move\" ? caps.canMove : caps.canCopy;\n}\n\n/**\n * Whether a drag of a folder may start. Moving needs `canMove`; no folder flag\n * answers a folder copy, so a copy keeps its previous behaviour (offered, and\n * the service decides).\n */\nexport function canStartFolderDrag(\n folder: FolderItem,\n operation: \"move\" | \"copy\",\n): boolean {\n return operation === \"move\" ? folderCapabilities(folder).canMove : true;\n}\n"],"mappings":";;AAmEA,SAASA,EACP,GACmB;CAGnB,OAFIC,MAAa,KAAa,EAAE,MAAM,UAAU,IAC5CA,MAAa,KAAc,EAAE,MAAM,SAAS,IACzC;AACT;AAEA,SAASC,EAAe,GAA4B;CAIlD,OAHcF,EAAgBG,EAAK,QAC/B,MACAA,EAAK,YAAY,KACd;EAAE,MAAM;EAAQ,cAAcC,EAAgBD,CAAI;CAAE,IADzB,EAAE,MAAM,SAAS;AAErD;AAEA,SAASE,EAAiB,GAAgC;CAIxD,OAHcL,EAAgBM,EAAO,QACjC,MACAA,EAAO,YAAY,KAChB;EAAE,MAAM;EAAQ,cAAcC,EAAkBD,CAAM;CAAE,IAD3B,EAAE,MAAM,SAAS;AAEvD;AAEA,SAAgBE,EAAiB,GAAkC;CACjE,OAAO;EACL,YAAYL,EAAK,YAAY;EAC7B,SAASA,EAAK,YAAY;EAC1B,WAAWA,EAAK,cAAc;EAC9B,SAASA,EAAK,YAAY;EAC1B,WAAWA,EAAK,cAAc;EAC9B,OAAOD,EAAeC,CAAI;CAC5B;AACF;AAEA,SAAgBM,EAAmB,GAAwC;CACzE,IAAMC,IAAUJ,EAAO,YAAY,IAC7BK,IAAYL,EAAO,cAAc;CACvC,OAAO;EACL;EACA;EACA,SAASA,EAAO,YAAY;EAC5B,WAAWA,EAAO,cAAc;EAChC,eAAeI,KAAWC;EAC1B,OAAON,EAAiBC,CAAM;CAChC;AACF;AAGA,SAAgBM,EAAe,GAA4B;CACzD,OAAOC,EAAM,SAAS;AACxB;AAOA,SAAgBC,EAAkB,GAAuC;CACvE,OAAOD,EAAM,SAAS,SAASA,EAAM,eAAe;AACtD;AAMA,SAAgBE,EACd,GACA,GACS;CACT,IAAMC,IAAOR,EAAiBL,CAAI;CAClC,OAAOc,MAAc,SAASD,EAAK,UAAUA,EAAK;AACpD;AAOA,SAAgBE,EACd,GACA,GACS;CACT,OAAOD,MAAc,UAASR,EAAmBH,CAAM,CAAC,CAAC;AAC3D"}
@@ -0,0 +1,144 @@
1
+ import { I18nContextValue } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';
2
+ /**
3
+ * Whether the current user may share a file or folder (BOFF-10039).
4
+ *
5
+ * What wspace-files-svc enforces:
6
+ *
7
+ * - Files: SHARE is checked only for PRIVATE and TEAM files (the uploader, a
8
+ * SHARE or MANAGE grant, or a MANAGER share). Sharing a WORKSPACE or PUBLIC
9
+ * file is governed by the gateway's `@rbac(share, file)` alone. The lazy
10
+ * lookup below still only gates PRIVATE/TEAM files, so a WORKSPACE/PUBLIC
11
+ * file with no eager `canShare` is decided by the share mutation itself,
12
+ * whose refusal the share dialog explains.
13
+ * - Folders: every folder share needs folder SHARE (the creator, a SHARE or
14
+ * MANAGE folder grant, or a MANAGER folder share), so
15
+ * `getUserFolderPermissions.canShare` is authoritative for all folders.
16
+ *
17
+ * Since BOFF-11801, listing payloads carry an eager `canShare` per item that
18
+ * already combines the service rule with the gateway's `@rbac` rule, and the
19
+ * browser gates Share on it (`utils/itemCapabilities.ts`). The lookup below is
20
+ * the fallback for an item whose payload has no `canShare`, and the share
21
+ * dialog's re-check: it resolves SHARE lazily through `getUserFilePermissions`
22
+ * / `getUserFolderPermissions` for the one item the user is about to act on.
23
+ *
24
+ * - `checking`: the permission query is in flight.
25
+ * - `allowed`: the service reported `canShare: true`.
26
+ * - `denied`: the service reported `canShare: false`.
27
+ * - `unknown`: the query failed, including a FORBIDDEN refusal of the query
28
+ * itself (it needs `@rbac(read, file-permission)`, which some
29
+ * product roles lack). The UI falls through here: the share
30
+ * mutation still enforces the rule, and its FORBIDDEN is the
31
+ * authoritative denial, which the share dialog explains.
32
+ *
33
+ * Only `denied` marks a Share entry point as denied. Every entry point, denied
34
+ * or not, opens the share dialog, which re-checks and shows the denied state.
35
+ */
36
+ export type SharePermissionStatus = "checking" | "allowed" | "denied" | "unknown";
37
+ export type ShareTargetKind = "file" | "folder";
38
+ export interface ShareTarget {
39
+ kind: ShareTargetKind;
40
+ id: string;
41
+ }
42
+ /**
43
+ * True when wspace-files-svc enforces SHARE for a file with this visibility.
44
+ * An unknown or missing visibility is not gated: the share mutation still
45
+ * decides, so the UI never blocks on a guess.
46
+ */
47
+ export declare function fileShareRequiresPermission(visibility: string | null | undefined): boolean;
48
+ /**
49
+ * The permission lookup target for sharing a file, or `null` when the file's
50
+ * visibility means `canShare` must not gate it (WORKSPACE/PUBLIC).
51
+ */
52
+ export declare function fileShareTarget(file: {
53
+ id: string;
54
+ visibility?: string | null;
55
+ }): ShareTarget | null;
56
+ /** The permission lookup target for sharing a folder (always gated). */
57
+ export declare function folderShareTarget(folder: {
58
+ id: string;
59
+ }): ShareTarget;
60
+ export declare function shareTargetKey(target: ShareTarget): string;
61
+ /**
62
+ * Map a permission query outcome onto a share status. A failed query, a
63
+ * FORBIDDEN refusal of the query included, is `unknown`, never `denied`.
64
+ */
65
+ export declare function resolveSharePermissionStatus(input: {
66
+ loading: boolean;
67
+ error?: unknown;
68
+ canShare?: boolean | null;
69
+ }): SharePermissionStatus;
70
+ /**
71
+ * The explanation a Share entry point carries for a given status. Only a
72
+ * confirmed `denied` is marked (with an explanation); the entry point still
73
+ * opens the share dialog, which re-checks and shows the denied state, so a
74
+ * click is never swallowed (touch devices have no tooltip to explain it).
75
+ */
76
+ export declare function shareEntryDeniedReason(status: SharePermissionStatus | undefined, messages: SharePermissionMessages): string | undefined;
77
+ /** How long a `denied` answer is trusted before the next interaction re-asks. */
78
+ export declare const DENIED_SHARE_PERMISSION_TTL_MS = 30000;
79
+ export interface SharePermissionEntry {
80
+ status: SharePermissionStatus;
81
+ /** When the status was recorded (ms since epoch). */
82
+ at: number;
83
+ }
84
+ /**
85
+ * Whether an interaction should (re)query SHARE for an item, given what the
86
+ * listing already knows about it.
87
+ *
88
+ * - never asked, or the last attempt failed (`unknown`): ask.
89
+ * - in flight (`checking`) or `allowed`: do not ask again.
90
+ * - `denied`: ask again once the answer is older than `deniedTtlMs`, so a
91
+ * grant made since then is picked up without reloading the view.
92
+ */
93
+ export declare function shouldLookUpSharePermission(entry: SharePermissionEntry | undefined, now: number, deniedTtlMs?: number): boolean;
94
+ /**
95
+ * The status a share dialog may show before its own re-check answers: a
96
+ * denial the listing recorded within the TTL is shown at once, anything else
97
+ * (including an expired denial) waits for the dialog's own lookup.
98
+ */
99
+ export declare function knownShareDenial(entry: SharePermissionEntry | undefined, now: number, deniedTtlMs?: number): "denied" | undefined;
100
+ /**
101
+ * Where an authorization refusal of a share came from.
102
+ *
103
+ * - `service`: wspace-files-svc refused the share (PRIVATE/TEAM files, all
104
+ * folders). It arrives as HTTP 200 with `errors[].extensions.code`
105
+ * FORBIDDEN, which Apollo 4 surfaces as `CombinedGraphQLErrors`.
106
+ * - `gateway`: the gateway's `@rbac` rule refused the caller's role. It
107
+ * arrives as HTTP 403 with a JSON body, which Apollo 4 surfaces as a
108
+ * `ServerError` carrying `statusCode` and `bodyText` and no errors array.
109
+ *
110
+ * Anything else, a 503 RBAC_SERVICE_UNAVAILABLE included, is not a denial.
111
+ */
112
+ export type ShareRefusalSource = "service" | "gateway";
113
+ export declare function classifyShareRefusal(error: unknown): ShareRefusalSource | null;
114
+ /** True when an Apollo error is an authorization refusal (service or gateway). */
115
+ export declare function isForbiddenError(error: unknown): boolean;
116
+ /**
117
+ * Which explanation a denied share dialog shows.
118
+ *
119
+ * - `restricted`: a PRIVATE/TEAM file the service refused (or reported
120
+ * `canShare: false` for); only its owner, a Share/Manage grant or a manager
121
+ * can share it.
122
+ * - `folder`: a folder the service refused; folder shares need folder SHARE.
123
+ * - `role`: the gateway refused the caller's workspace role, or the file is
124
+ * WORKSPACE/PUBLIC, where only the gateway's `@rbac` rule applies.
125
+ */
126
+ export type ShareDenialCause = "restricted" | "folder" | "role";
127
+ export declare function shareDenialCause(input: {
128
+ itemType: ShareTargetKind;
129
+ visibility?: string | null;
130
+ /** `permission`: the dialog's own SHARE lookup reported `canShare: false`. */
131
+ source: ShareRefusalSource | "permission";
132
+ }): ShareDenialCause;
133
+ export interface ShareDenialCopy {
134
+ title: string;
135
+ description: string;
136
+ }
137
+ /** Copy for a denied share dialog, matched to the cause of the denial. */
138
+ export declare function shareDenialCopy(t: I18nContextValue["t"], cause: ShareDenialCause, itemTypeLabel: string): ShareDenialCopy;
139
+ export interface SharePermissionMessages {
140
+ checking: string;
141
+ denied: string;
142
+ }
143
+ /** Copy shown on a Share entry point that is not (yet) usable. */
144
+ export declare function sharePermissionMessages(t: I18nContextValue["t"]): SharePermissionMessages;
@@ -0,0 +1,77 @@
1
+ import { tWithFallback as e } from "./i18n.js";
2
+ import { CombinedGraphQLErrors as t, ServerError as n } from "@apollo/client";
3
+ // src/files/utils/sharePermission.ts
4
+ var r = /* @__PURE__ */ new Set(["PRIVATE", "TEAM"]);
5
+ function i(e) {
6
+ return typeof e == "string" && r.has(e.toUpperCase());
7
+ }
8
+ function a(e) {
9
+ return i(e.visibility) ? {
10
+ kind: "file",
11
+ id: e.id
12
+ } : null;
13
+ }
14
+ function o(e) {
15
+ return {
16
+ kind: "folder",
17
+ id: e.id
18
+ };
19
+ }
20
+ function s(e) {
21
+ return `${e.kind}:${e.id}`;
22
+ }
23
+ function c(e) {
24
+ return e.error ? "unknown" : typeof e.canShare == "boolean" ? e.canShare ? "allowed" : "denied" : e.loading ? "checking" : "unknown";
25
+ }
26
+ function l(e, t) {
27
+ return e === "denied" ? t.denied : void 0;
28
+ }
29
+ var u = 3e4;
30
+ function d(e, t, n = u) {
31
+ if (!e) return !0;
32
+ switch (e.status) {
33
+ case "checking":
34
+ case "allowed": return !1;
35
+ case "denied": return t - e.at >= n;
36
+ default: return !0;
37
+ }
38
+ }
39
+ function f(e, t, n = u) {
40
+ return e?.status === "denied" && t - e.at < n ? "denied" : void 0;
41
+ }
42
+ var p = /* @__PURE__ */ new Set(["FORBIDDEN", "PERMISSION_DENIED"]);
43
+ function m(e) {
44
+ return t.is(e) ? e.errors.some((e) => {
45
+ let t = e.extensions?.code;
46
+ return typeof t == "string" && p.has(t);
47
+ }) ? "service" : null : n.is(e) && e.statusCode === 403 ? "gateway" : null;
48
+ }
49
+ function h(e) {
50
+ return e.source === "gateway" ? "role" : e.itemType === "folder" ? "folder" : i(e.visibility) ? "restricted" : "role";
51
+ }
52
+ function g(t, n, r) {
53
+ let i = e(t, "files.shareDialog.forbidden.title", "You can't share this {{itemType}}", { itemType: r });
54
+ switch (n) {
55
+ case "restricted": return {
56
+ title: i,
57
+ description: e(t, "files.shareDialog.forbidden.restricted", "Only its owner, people with Share or Manage access, or a manager can share a private or team file. Ask one of them to share it or to give you Share access.")
58
+ };
59
+ case "folder": return {
60
+ title: i,
61
+ description: e(t, "files.shareDialog.forbidden.folder", "Only the folder's creator, people with Share or Manage access to it, or a folder manager can share a folder. Ask one of them to share it or to give you Share access.")
62
+ };
63
+ default: return {
64
+ title: i,
65
+ description: e(t, "files.shareDialog.forbidden.role", "Your workspace role doesn't allow sharing. Ask a workspace admin.")
66
+ };
67
+ }
68
+ }
69
+ function _(t) {
70
+ return {
71
+ checking: e(t, "files.share.permission.checking", "Checking whether you can share this…"),
72
+ denied: e(t, "files.share.permission.denied", "You don't have permission to share this. Ask its owner or a manager for Share access.")
73
+ };
74
+ }
75
+ export { u as DENIED_SHARE_PERMISSION_TTL_MS, m as classifyShareRefusal, i as fileShareRequiresPermission, a as fileShareTarget, o as folderShareTarget, f as knownShareDenial, c as resolveSharePermissionStatus, h as shareDenialCause, g as shareDenialCopy, l as shareEntryDeniedReason, _ as sharePermissionMessages, s as shareTargetKey, d as shouldLookUpSharePermission };
76
+
77
+ //# sourceMappingURL=sharePermission.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sharePermission.js","names":["SHARE_ENFORCED_FILE_VISIBILITIES","fileShareRequiresPermission","visibility","fileShareTarget","file","folderShareTarget","folder","shareTargetKey","target","resolveSharePermissionStatus","input","shareEntryDeniedReason","status","messages","DENIED_SHARE_PERMISSION_TTL_MS","shouldLookUpSharePermission","entry","now","deniedTtlMs","knownShareDenial","FORBIDDEN_CODES","classifyShareRefusal","CombinedGraphQLErrors","error","code","graphQLError","ServerError","shareDenialCause","shareDenialCopy","title","tWithFallback","itemTypeLabel","cause","sharePermissionMessages"],"sources":["../../../src/files/utils/sharePermission.ts"],"sourcesContent":["import { CombinedGraphQLErrors, ServerError } from \"@apollo/client\";\nimport type { I18nContextValue } from \"@burdenoff/fe-libs/shared/providers/shell/I18nProvider\";\n\nimport { tWithFallback } from \"./i18n\";\n\n/**\n * Whether the current user may share a file or folder (BOFF-10039).\n *\n * What wspace-files-svc enforces:\n *\n * - Files: SHARE is checked only for PRIVATE and TEAM files (the uploader, a\n * SHARE or MANAGE grant, or a MANAGER share). Sharing a WORKSPACE or PUBLIC\n * file is governed by the gateway's `@rbac(share, file)` alone. The lazy\n * lookup below still only gates PRIVATE/TEAM files, so a WORKSPACE/PUBLIC\n * file with no eager `canShare` is decided by the share mutation itself,\n * whose refusal the share dialog explains.\n * - Folders: every folder share needs folder SHARE (the creator, a SHARE or\n * MANAGE folder grant, or a MANAGER folder share), so\n * `getUserFolderPermissions.canShare` is authoritative for all folders.\n *\n * Since BOFF-11801, listing payloads carry an eager `canShare` per item that\n * already combines the service rule with the gateway's `@rbac` rule, and the\n * browser gates Share on it (`utils/itemCapabilities.ts`). The lookup below is\n * the fallback for an item whose payload has no `canShare`, and the share\n * dialog's re-check: it resolves SHARE lazily through `getUserFilePermissions`\n * / `getUserFolderPermissions` for the one item the user is about to act on.\n *\n * - `checking`: the permission query is in flight.\n * - `allowed`: the service reported `canShare: true`.\n * - `denied`: the service reported `canShare: false`.\n * - `unknown`: the query failed, including a FORBIDDEN refusal of the query\n * itself (it needs `@rbac(read, file-permission)`, which some\n * product roles lack). The UI falls through here: the share\n * mutation still enforces the rule, and its FORBIDDEN is the\n * authoritative denial, which the share dialog explains.\n *\n * Only `denied` marks a Share entry point as denied. Every entry point, denied\n * or not, opens the share dialog, which re-checks and shows the denied state.\n */\nexport type SharePermissionStatus =\n \"checking\" | \"allowed\" | \"denied\" | \"unknown\";\n\nexport type ShareTargetKind = \"file\" | \"folder\";\n\nexport interface ShareTarget {\n kind: ShareTargetKind;\n id: string;\n}\n\n/** File visibilities for which the service enforces SHARE on the file itself. */\nconst SHARE_ENFORCED_FILE_VISIBILITIES = new Set([\"PRIVATE\", \"TEAM\"]);\n\n/**\n * True when wspace-files-svc enforces SHARE for a file with this visibility.\n * An unknown or missing visibility is not gated: the share mutation still\n * decides, so the UI never blocks on a guess.\n */\nexport function fileShareRequiresPermission(\n visibility: string | null | undefined,\n): boolean {\n return (\n typeof visibility === \"string\" &&\n SHARE_ENFORCED_FILE_VISIBILITIES.has(visibility.toUpperCase())\n );\n}\n\n/**\n * The permission lookup target for sharing a file, or `null` when the file's\n * visibility means `canShare` must not gate it (WORKSPACE/PUBLIC).\n */\nexport function fileShareTarget(file: {\n id: string;\n visibility?: string | null;\n}): ShareTarget | null {\n return fileShareRequiresPermission(file.visibility)\n ? { kind: \"file\", id: file.id }\n : null;\n}\n\n/** The permission lookup target for sharing a folder (always gated). */\nexport function folderShareTarget(folder: { id: string }): ShareTarget {\n return { kind: \"folder\", id: folder.id };\n}\n\nexport function shareTargetKey(target: ShareTarget): string {\n return `${target.kind}:${target.id}`;\n}\n\n/**\n * Map a permission query outcome onto a share status. A failed query, a\n * FORBIDDEN refusal of the query included, is `unknown`, never `denied`.\n */\nexport function resolveSharePermissionStatus(input: {\n loading: boolean;\n error?: unknown;\n canShare?: boolean | null;\n}): SharePermissionStatus {\n if (input.error) return \"unknown\";\n if (typeof input.canShare === \"boolean\") {\n return input.canShare ? \"allowed\" : \"denied\";\n }\n return input.loading ? \"checking\" : \"unknown\";\n}\n\n/**\n * The explanation a Share entry point carries for a given status. Only a\n * confirmed `denied` is marked (with an explanation); the entry point still\n * opens the share dialog, which re-checks and shows the denied state, so a\n * click is never swallowed (touch devices have no tooltip to explain it).\n */\nexport function shareEntryDeniedReason(\n status: SharePermissionStatus | undefined,\n messages: SharePermissionMessages,\n): string | undefined {\n return status === \"denied\" ? messages.denied : undefined;\n}\n\n/** How long a `denied` answer is trusted before the next interaction re-asks. */\nexport const DENIED_SHARE_PERMISSION_TTL_MS = 30_000;\n\nexport interface SharePermissionEntry {\n status: SharePermissionStatus;\n /** When the status was recorded (ms since epoch). */\n at: number;\n}\n\n/**\n * Whether an interaction should (re)query SHARE for an item, given what the\n * listing already knows about it.\n *\n * - never asked, or the last attempt failed (`unknown`): ask.\n * - in flight (`checking`) or `allowed`: do not ask again.\n * - `denied`: ask again once the answer is older than `deniedTtlMs`, so a\n * grant made since then is picked up without reloading the view.\n */\nexport function shouldLookUpSharePermission(\n entry: SharePermissionEntry | undefined,\n now: number,\n deniedTtlMs: number = DENIED_SHARE_PERMISSION_TTL_MS,\n): boolean {\n if (!entry) return true;\n switch (entry.status) {\n case \"checking\":\n case \"allowed\":\n return false;\n case \"denied\":\n return now - entry.at >= deniedTtlMs;\n default:\n return true;\n }\n}\n\n/**\n * The status a share dialog may show before its own re-check answers: a\n * denial the listing recorded within the TTL is shown at once, anything else\n * (including an expired denial) waits for the dialog's own lookup.\n */\nexport function knownShareDenial(\n entry: SharePermissionEntry | undefined,\n now: number,\n deniedTtlMs: number = DENIED_SHARE_PERMISSION_TTL_MS,\n): \"denied\" | undefined {\n return entry?.status === \"denied\" && now - entry.at < deniedTtlMs\n ? \"denied\"\n : undefined;\n}\n\nconst FORBIDDEN_CODES = new Set([\"FORBIDDEN\", \"PERMISSION_DENIED\"]);\n\n/**\n * Where an authorization refusal of a share came from.\n *\n * - `service`: wspace-files-svc refused the share (PRIVATE/TEAM files, all\n * folders). It arrives as HTTP 200 with `errors[].extensions.code`\n * FORBIDDEN, which Apollo 4 surfaces as `CombinedGraphQLErrors`.\n * - `gateway`: the gateway's `@rbac` rule refused the caller's role. It\n * arrives as HTTP 403 with a JSON body, which Apollo 4 surfaces as a\n * `ServerError` carrying `statusCode` and `bodyText` and no errors array.\n *\n * Anything else, a 503 RBAC_SERVICE_UNAVAILABLE included, is not a denial.\n */\nexport type ShareRefusalSource = \"service\" | \"gateway\";\n\nexport function classifyShareRefusal(\n error: unknown,\n): ShareRefusalSource | null {\n if (CombinedGraphQLErrors.is(error)) {\n const refused = error.errors.some((graphQLError) => {\n const code = graphQLError.extensions?.code;\n return typeof code === \"string\" && FORBIDDEN_CODES.has(code);\n });\n return refused ? \"service\" : null;\n }\n if (ServerError.is(error)) {\n return error.statusCode === 403 ? \"gateway\" : null;\n }\n return null;\n}\n\n/** True when an Apollo error is an authorization refusal (service or gateway). */\nexport function isForbiddenError(error: unknown): boolean {\n return classifyShareRefusal(error) !== null;\n}\n\n/**\n * Which explanation a denied share dialog shows.\n *\n * - `restricted`: a PRIVATE/TEAM file the service refused (or reported\n * `canShare: false` for); only its owner, a Share/Manage grant or a manager\n * can share it.\n * - `folder`: a folder the service refused; folder shares need folder SHARE.\n * - `role`: the gateway refused the caller's workspace role, or the file is\n * WORKSPACE/PUBLIC, where only the gateway's `@rbac` rule applies.\n */\nexport type ShareDenialCause = \"restricted\" | \"folder\" | \"role\";\n\nexport function shareDenialCause(input: {\n itemType: ShareTargetKind;\n visibility?: string | null;\n /** `permission`: the dialog's own SHARE lookup reported `canShare: false`. */\n source: ShareRefusalSource | \"permission\";\n}): ShareDenialCause {\n if (input.source === \"gateway\") return \"role\";\n if (input.itemType === \"folder\") return \"folder\";\n return fileShareRequiresPermission(input.visibility) ? \"restricted\" : \"role\";\n}\n\nexport interface ShareDenialCopy {\n title: string;\n description: string;\n}\n\n/** Copy for a denied share dialog, matched to the cause of the denial. */\nexport function shareDenialCopy(\n t: I18nContextValue[\"t\"],\n cause: ShareDenialCause,\n itemTypeLabel: string,\n): ShareDenialCopy {\n const title = tWithFallback(\n t,\n \"files.shareDialog.forbidden.title\",\n \"You can't share this {{itemType}}\",\n { itemType: itemTypeLabel },\n );\n switch (cause) {\n case \"restricted\":\n return {\n title,\n description: tWithFallback(\n t,\n \"files.shareDialog.forbidden.restricted\",\n \"Only its owner, people with Share or Manage access, or a manager can share a private or team file. Ask one of them to share it or to give you Share access.\",\n ),\n };\n case \"folder\":\n return {\n title,\n description: tWithFallback(\n t,\n \"files.shareDialog.forbidden.folder\",\n \"Only the folder's creator, people with Share or Manage access to it, or a folder manager can share a folder. Ask one of them to share it or to give you Share access.\",\n ),\n };\n default:\n return {\n title,\n description: tWithFallback(\n t,\n \"files.shareDialog.forbidden.role\",\n \"Your workspace role doesn't allow sharing. Ask a workspace admin.\",\n ),\n };\n }\n}\n\nexport interface SharePermissionMessages {\n checking: string;\n denied: string;\n}\n\n/** Copy shown on a Share entry point that is not (yet) usable. */\nexport function sharePermissionMessages(\n t: I18nContextValue[\"t\"],\n): SharePermissionMessages {\n return {\n checking: tWithFallback(\n t,\n \"files.share.permission.checking\",\n \"Checking whether you can share this…\",\n ),\n denied: tWithFallback(\n t,\n \"files.share.permission.denied\",\n \"You don't have permission to share this. Ask its owner or a manager for Share access.\",\n ),\n };\n}\n"],"mappings":";;;AAkDA,IAAMA,oBAAmC,IAAI,IAAI,CAAC,WAAW,MAAM,CAAC;AAOpE,SAAgBC,EACd,GACS;CACT,OACE,OAAOC,KAAe,YACtBF,EAAiC,IAAIE,EAAW,YAAY,CAAC;AAEjE;AAMA,SAAgBC,EAAgB,GAGT;CACrB,OAAOF,EAA4BG,EAAK,UAAU,IAC9C;EAAE,MAAM;EAAQ,IAAIA,EAAK;CAAG,IAC5B;AACN;AAGA,SAAgBC,EAAkB,GAAqC;CACrE,OAAO;EAAE,MAAM;EAAU,IAAIC,EAAO;CAAG;AACzC;AAEA,SAAgBC,EAAe,GAA6B;CAC1D,OAAO,GAAGC,EAAO,KAAK,GAAGA,EAAO;AAClC;AAMA,SAAgBC,EAA6B,GAInB;CAKxB,OAJIC,EAAM,QAAc,YACpB,OAAOA,EAAM,YAAa,YACrBA,EAAM,WAAW,YAAY,WAE/BA,EAAM,UAAU,aAAa;AACtC;AAQA,SAAgBC,EACd,GACA,GACoB;CACpB,OAAOC,MAAW,WAAWC,EAAS,SAAS,KAAA;AACjD;AAGA,IAAaC,IAAiC;AAiB9C,SAAgBC,EACd,GACA,GACA,IAAsBD,GACb;CACT,IAAI,CAACE,GAAO,OAAO;CACnB,QAAQA,EAAM,QAAd;EACE,KAAK;EACL,KAAK,WACH,OAAO;EACT,KAAK,UACH,OAAOC,IAAMD,EAAM,MAAME;EAC3B,SACE,OAAO;CACX;AACF;AAOA,SAAgBC,EACd,GACA,GACA,IAAsBL,GACA;CACtB,OAAOE,GAAO,WAAW,YAAYC,IAAMD,EAAM,KAAKE,IAClD,WACA,KAAA;AACN;AAEA,IAAME,oBAAkB,IAAI,IAAI,CAAC,aAAa,mBAAmB,CAAC;AAgBlE,SAAgBC,EACd,GAC2B;CAW3B,OAVIC,EAAsB,GAAGC,CAAK,IAChBA,EAAM,OAAO,MAAM,MAAiB;EAClD,IAAMC,IAAOC,EAAa,YAAY;EACtC,OAAO,OAAOD,KAAS,YAAYJ,EAAgB,IAAII,CAAI;CAC7D,CACO,IAAU,YAAY,OAE3BE,EAAY,GAAGH,CAAK,KACfA,EAAM,eAAe,MAAM,YAE7B;AACT;AAmBA,SAAgBI,EAAiB,GAKZ;CAGnB,OAFIjB,EAAM,WAAW,YAAkB,SACnCA,EAAM,aAAa,WAAiB,WACjCT,EAA4BS,EAAM,UAAU,IAAI,eAAe;AACxE;AAQA,SAAgBkB,EACd,GACA,GACA,GACiB;CACjB,IAAMC,IAAQC,EACZ,GACA,qCACA,qCACA,EAAE,UAAUC,EAAc,CAC5B;CACA,QAAQC,GAAR;EACE,KAAK,cACH,OAAO;GACL;GACA,aAAaF,EACX,GACA,0CACA,6JACF;EACF;EACF,KAAK,UACH,OAAO;GACL;GACA,aAAaA,EACX,GACA,sCACA,uKACF;EACF;EACF,SACE,OAAO;GACL;GACA,aAAaA,EACX,GACA,oCACA,mEACF;EACF;CACJ;AACF;AAQA,SAAgBG,EACd,GACyB;CACzB,OAAO;EACL,UAAUH,EACR,GACA,mCACA,sCACF;EACA,QAAQA,EACN,GACA,iCACA,uFACF;CACF;AACF"}