@coffre/ui 0.3.0 → 0.4.0

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 (177) hide show
  1. package/dist/chunks/audit-sentence-BhHmvQX_.js +660 -0
  2. package/dist/chunks/audit-sentence-BhHmvQX_.js.map +1 -0
  3. package/dist/chunks/delete-place-CRX7ntE8.js +206 -0
  4. package/dist/chunks/delete-place-CRX7ntE8.js.map +1 -0
  5. package/dist/chunks/{directory-CSjWWUQ1.js → directory-zr3ek7Mc.js} +175 -60
  6. package/dist/chunks/directory-zr3ek7Mc.js.map +1 -0
  7. package/dist/chunks/folders-DoBmCwOi.js +207 -0
  8. package/dist/chunks/folders-DoBmCwOi.js.map +1 -0
  9. package/dist/chunks/grants-Cw1FyGID.js +669 -0
  10. package/dist/chunks/grants-Cw1FyGID.js.map +1 -0
  11. package/dist/chunks/offboarding-CE6d7um1.js +305 -0
  12. package/dist/chunks/offboarding-CE6d7um1.js.map +1 -0
  13. package/dist/chunks/one-time-DXEl9hbg.js +35 -0
  14. package/dist/chunks/one-time-DXEl9hbg.js.map +1 -0
  15. package/dist/chunks/page-DvsgZ2Hd.js +391 -0
  16. package/dist/chunks/page-DvsgZ2Hd.js.map +1 -0
  17. package/dist/chunks/principal-BIN-xwZw.js +42 -0
  18. package/dist/chunks/principal-BIN-xwZw.js.map +1 -0
  19. package/dist/chunks/{principal-page-D_91OA0l.js → principal-page-DhjO76GH.js} +245 -251
  20. package/dist/chunks/principal-page-DhjO76GH.js.map +1 -0
  21. package/dist/chunks/project-page-SRCtRe2g.js +17 -0
  22. package/dist/chunks/project-page-SRCtRe2g.js.map +1 -0
  23. package/dist/chunks/{queries-CQ81o4so.js → queries-DVR_i3rA.js} +132 -30
  24. package/dist/chunks/queries-DVR_i3rA.js.map +1 -0
  25. package/dist/chunks/references-B6pLT1uQ.js +343 -0
  26. package/dist/chunks/references-B6pLT1uQ.js.map +1 -0
  27. package/dist/chunks/{row-state-0PsrEzOL.js → row-state-DOPUsjQK.js} +3 -3
  28. package/dist/chunks/{row-state-0PsrEzOL.js.map → row-state-DOPUsjQK.js.map} +1 -1
  29. package/dist/chunks/signin-errors--ykMFuqN.js +57 -0
  30. package/dist/chunks/signin-errors--ykMFuqN.js.map +1 -0
  31. package/dist/chunks/tabs-BmwKfUeK.js +22 -0
  32. package/dist/chunks/tabs-BmwKfUeK.js.map +1 -0
  33. package/dist/chunks/{theme-B2vQolVR.js → theme-DJuz-xLM.js} +3 -3
  34. package/dist/chunks/{theme-B2vQolVR.js.map → theme-DJuz-xLM.js.map} +1 -1
  35. package/dist/chunks/{ui-DixXLQvQ.js → ui-DJje3gST.js} +6 -3
  36. package/dist/chunks/ui-DJje3gST.js.map +1 -0
  37. package/dist/chunks/{use-change-c6CeLRin.js → use-change-DUiGO19U.js} +52 -21
  38. package/dist/chunks/use-change-DUiGO19U.js.map +1 -0
  39. package/dist/chunks/{use-shell-jxd7Tzd-.js → use-shell-rNKfGjdj.js} +3 -3
  40. package/dist/chunks/{use-shell-jxd7Tzd-.js.map → use-shell-rNKfGjdj.js.map} +1 -1
  41. package/dist/chunks/validation-D312_NLf.js +87 -0
  42. package/dist/chunks/validation-D312_NLf.js.map +1 -0
  43. package/dist/index.d.ts +361 -27
  44. package/dist/index.js +188 -98
  45. package/dist/index.js.map +1 -1
  46. package/dist/pages/account.d.ts +2 -2
  47. package/dist/pages/account.js +297 -135
  48. package/dist/pages/account.js.map +1 -1
  49. package/dist/pages/approval.d.ts +9 -0
  50. package/dist/pages/approval.js +207 -0
  51. package/dist/pages/approval.js.map +1 -0
  52. package/dist/pages/audit.js +17 -542
  53. package/dist/pages/audit.js.map +1 -1
  54. package/dist/pages/device-login.js +2 -3
  55. package/dist/pages/device-login.js.map +1 -1
  56. package/dist/pages/environment.js +647 -257
  57. package/dist/pages/environment.js.map +1 -1
  58. package/dist/pages/login.js +18 -7
  59. package/dist/pages/login.js.map +1 -1
  60. package/dist/pages/oauth-authorize.d.ts +10 -0
  61. package/dist/pages/oauth-authorize.js +249 -0
  62. package/dist/pages/oauth-authorize.js.map +1 -0
  63. package/dist/pages/project-access.d.ts +6 -0
  64. package/dist/pages/project-access.js +370 -0
  65. package/dist/pages/project-access.js.map +1 -0
  66. package/dist/pages/project-environments.d.ts +4 -0
  67. package/dist/pages/project-environments.js +593 -0
  68. package/dist/pages/project-environments.js.map +1 -0
  69. package/dist/pages/project-settings.d.ts +4 -0
  70. package/dist/pages/project-settings.js +242 -0
  71. package/dist/pages/project-settings.js.map +1 -0
  72. package/dist/pages/project.d.ts +10 -2
  73. package/dist/pages/project.js +57 -934
  74. package/dist/pages/project.js.map +1 -1
  75. package/dist/pages/projects.js +53 -21
  76. package/dist/pages/projects.js.map +1 -1
  77. package/dist/pages/service-account.d.ts +10 -0
  78. package/dist/pages/{token.js → service-account.js} +112 -54
  79. package/dist/pages/service-account.js.map +1 -0
  80. package/dist/pages/service-accounts.d.ts +3 -0
  81. package/dist/pages/service-accounts.js +38 -0
  82. package/dist/pages/service-accounts.js.map +1 -0
  83. package/dist/pages/settings.d.ts +1 -0
  84. package/dist/pages/settings.js +104 -42
  85. package/dist/pages/settings.js.map +1 -1
  86. package/dist/pages/unregistered.js +2 -3
  87. package/dist/pages/unregistered.js.map +1 -1
  88. package/dist/pages/user.d.ts +6 -1
  89. package/dist/pages/user.js +18 -6
  90. package/dist/pages/user.js.map +1 -1
  91. package/dist/pages/users.js +6 -10
  92. package/dist/pages/users.js.map +1 -1
  93. package/package.json +3 -3
  94. package/src/components/actions-log.tsx +117 -0
  95. package/src/components/audit-sentence.tsx +55 -0
  96. package/src/components/command-palette.tsx +4 -4
  97. package/src/components/delete-place.tsx +180 -0
  98. package/src/components/directory.tsx +259 -110
  99. package/src/components/every-project.tsx +287 -0
  100. package/src/components/expiry-field.tsx +42 -0
  101. package/src/components/folders.tsx +219 -0
  102. package/src/components/grants.tsx +11 -4
  103. package/src/components/icons.tsx +2 -0
  104. package/src/components/missing.tsx +110 -0
  105. package/src/components/offboarding.tsx +61 -33
  106. package/src/components/page.tsx +4 -1
  107. package/src/components/principal-page.tsx +136 -106
  108. package/src/components/principal-picker.tsx +5 -5
  109. package/src/components/principal.tsx +4 -4
  110. package/src/components/references.tsx +323 -0
  111. package/src/components/service-tokens.tsx +112 -93
  112. package/src/components/shell.tsx +11 -32
  113. package/src/components/tabs.tsx +18 -0
  114. package/src/components/trusted-workloads.tsx +97 -79
  115. package/src/components/ui.tsx +8 -1
  116. package/src/index.ts +13 -2
  117. package/src/layout.tsx +2 -2
  118. package/src/lib/access-plan.ts +2 -2
  119. package/src/lib/audit-sentences.ts +161 -77
  120. package/src/lib/changes.ts +56 -5
  121. package/src/lib/coffre.ts +3 -2
  122. package/src/lib/one-time.ts +32 -0
  123. package/src/lib/project-access.ts +11 -23
  124. package/src/lib/project-page.ts +14 -0
  125. package/src/lib/queries.ts +126 -32
  126. package/src/lib/search.ts +25 -0
  127. package/src/lib/signin-errors.ts +45 -1
  128. package/src/lib/validation.ts +14 -0
  129. package/src/options.ts +187 -35
  130. package/src/pages/account.tsx +274 -129
  131. package/src/pages/approval.tsx +197 -0
  132. package/src/pages/audit.tsx +9 -61
  133. package/src/pages/environment.tsx +585 -286
  134. package/src/pages/login.tsx +8 -2
  135. package/src/pages/oauth-authorize.tsx +233 -0
  136. package/src/pages/project-access.tsx +219 -0
  137. package/src/pages/project-environments.tsx +582 -0
  138. package/src/pages/project-settings.tsx +259 -0
  139. package/src/pages/project.tsx +52 -879
  140. package/src/pages/projects.tsx +55 -18
  141. package/src/pages/service-account.tsx +50 -0
  142. package/src/pages/{tokens.tsx → service-accounts.tsx} +9 -6
  143. package/src/pages/settings.tsx +62 -8
  144. package/src/pages/user.tsx +16 -4
  145. package/src/pages/users.tsx +2 -2
  146. package/src/parity.ts +160 -0
  147. package/src/register.ts +58 -9
  148. package/src/router.tsx +4 -0
  149. package/src/shared/models.ts +6 -2
  150. package/src/styles/globals.css +536 -31
  151. package/dist/chunks/directory-CSjWWUQ1.js.map +0 -1
  152. package/dist/chunks/grants-saMQagmG.js +0 -160
  153. package/dist/chunks/grants-saMQagmG.js.map +0 -1
  154. package/dist/chunks/icons-D-PfAfnH.js +0 -203
  155. package/dist/chunks/icons-D-PfAfnH.js.map +0 -1
  156. package/dist/chunks/offboarding-C6l30DZR.js +0 -263
  157. package/dist/chunks/offboarding-C6l30DZR.js.map +0 -1
  158. package/dist/chunks/page-C5HcNqf2.js +0 -190
  159. package/dist/chunks/page-C5HcNqf2.js.map +0 -1
  160. package/dist/chunks/principal-page-D_91OA0l.js.map +0 -1
  161. package/dist/chunks/queries-CQ81o4so.js.map +0 -1
  162. package/dist/chunks/signin-errors-BEFlVDbQ.js +0 -30
  163. package/dist/chunks/signin-errors-BEFlVDbQ.js.map +0 -1
  164. package/dist/chunks/ui-DixXLQvQ.js.map +0 -1
  165. package/dist/chunks/use-action-CWsg_YWU.js +0 -49
  166. package/dist/chunks/use-action-CWsg_YWU.js.map +0 -1
  167. package/dist/chunks/use-change-c6CeLRin.js.map +0 -1
  168. package/dist/chunks/validation-BQtqPe2V.js +0 -29
  169. package/dist/chunks/validation-BQtqPe2V.js.map +0 -1
  170. package/dist/pages/token.d.ts +0 -3
  171. package/dist/pages/token.js.map +0 -1
  172. package/dist/pages/tokens.d.ts +0 -3
  173. package/dist/pages/tokens.js +0 -39
  174. package/dist/pages/tokens.js.map +0 -1
  175. package/dist/project-BqIy8gYR.d.ts +0 -5
  176. package/src/lib/instance.ts +0 -13
  177. package/src/pages/token.tsx +0 -34
@@ -0,0 +1,249 @@
1
+ import { a as ErrorLine, c as Notice, l as Spinner } from "../chunks/ui-DJje3gST.js";
2
+ import { N as Link, X as SlashCircle, c as statusOf, g as ArrowRight, n as ClosedDoor, o as failureMessage, u as useCoffre } from "../chunks/page-DvsgZ2Hd.js";
3
+ import { t as pageRoute } from "../chunks/page-route-Drfw7lmn.js";
4
+ import { useState } from "react";
5
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
6
+ import { MCP_SCOPE_INFO, supersedes } from "@coffre/core/mcp";
7
+ //#region src/pages/oauth-authorize.tsx
8
+ var Route = pageRoute();
9
+ /**
10
+ * Where an MCP client, such as Claude, sends you to connect: who it is,
11
+ * where coffre's answer goes, and what it may do as you. Nothing is granted
12
+ * until you press Approve, and every connection asks again: there is no
13
+ * silent re-consent. Either answer goes back to the app by `location`,
14
+ * never a form post, which the page's `form-action 'self'` would stop.
15
+ */
16
+ function OauthAuthorizePage() {
17
+ const loaded = Route.useLoaderData();
18
+ const [leaving, setLeaving] = useState(false);
19
+ if (leaving) return /* @__PURE__ */ jsx(ClosedDoor, {
20
+ icon: /* @__PURE__ */ jsx(ArrowRight, { size: 18 }),
21
+ label: "Connect an app",
22
+ title: "Sending you back to the app",
23
+ children: /* @__PURE__ */ jsx("p", { children: "You can close this tab if the app has already opened." })
24
+ });
25
+ if (!loaded.result.ok) return /* @__PURE__ */ jsx(CannotConnect, { message: loaded.result.error });
26
+ const view = loaded.result;
27
+ if (view.status === "invalid") return /* @__PURE__ */ jsx(CannotConnect, { message: view.message });
28
+ if (view.status === "refused") return /* @__PURE__ */ jsx(ClosedDoor, {
29
+ icon: /* @__PURE__ */ jsx(SlashCircle, { size: 18 }),
30
+ label: "Connect an app",
31
+ title: "This request can't be approved",
32
+ actions: /* @__PURE__ */ jsx("button", {
33
+ className: "btn",
34
+ onClick: () => {
35
+ setLeaving(true);
36
+ location.assign(view.redirect);
37
+ },
38
+ children: "Back to the app"
39
+ }),
40
+ children: /* @__PURE__ */ jsxs("p", { children: [view.message, ". Nothing was granted; the app is told why."] })
41
+ });
42
+ return /* @__PURE__ */ jsx(Approve, {
43
+ view,
44
+ email: loaded.email,
45
+ request: loaded.request,
46
+ onLeave: (redirect) => {
47
+ setLeaving(true);
48
+ location.assign(redirect);
49
+ }
50
+ });
51
+ }
52
+ /** A client or redirect that fails its checks: said here, and never redirected to, which would be an open redirect. */
53
+ function CannotConnect({ message }) {
54
+ return /* @__PURE__ */ jsxs(ClosedDoor, {
55
+ icon: /* @__PURE__ */ jsx(SlashCircle, { size: 18 }),
56
+ label: "Connect an app",
57
+ title: "This app can't connect",
58
+ children: [/* @__PURE__ */ jsx("p", { children: message }), /* @__PURE__ */ jsx("p", { children: "Nothing was sent to it. If you were trying to connect it, tell whoever makes it." })]
59
+ });
60
+ }
61
+ function Approve({ view, email, request, onLeave }) {
62
+ const coffre = useCoffre();
63
+ const [chosen, setChosen] = useState(() => new Set(view.scopes));
64
+ const [pending, setPending] = useState(null);
65
+ const [error, setError] = useState(null);
66
+ const { client } = view;
67
+ const unverified = client.registration === "dcr";
68
+ const granted = view.scopes.filter((scope) => chosen.has(scope));
69
+ const replaced = view.connections.filter((held) => supersedes(granted, held)).length;
70
+ const kept = view.connections.length - replaced;
71
+ async function decide(approve) {
72
+ setPending(approve ? "approve" : "deny");
73
+ try {
74
+ const { redirect } = await coffre.oauth.decide({
75
+ request,
76
+ approve,
77
+ scopes: [...chosen]
78
+ });
79
+ onLeave(redirect);
80
+ } catch (error) {
81
+ setError(statusOf(error) === void 0 ? "The answer could not be sent. Nothing was approved." : failureMessage(error));
82
+ setPending(null);
83
+ }
84
+ }
85
+ function toggle(scope, on) {
86
+ const next = new Set(chosen);
87
+ if (on) next.add(scope);
88
+ else next.delete(scope);
89
+ setChosen(next);
90
+ }
91
+ return /* @__PURE__ */ jsxs("section", {
92
+ className: "card signin",
93
+ "aria-labelledby": "consent-title",
94
+ children: [
95
+ /* @__PURE__ */ jsxs("div", {
96
+ className: "signin-head",
97
+ children: [/* @__PURE__ */ jsxs("h1", {
98
+ className: "signin-title",
99
+ id: "consent-title",
100
+ children: [
101
+ "Connect ",
102
+ client.name,
103
+ " to coffre?"
104
+ ]
105
+ }), /* @__PURE__ */ jsx("p", {
106
+ className: "signin-lede",
107
+ children: "Only if you just asked it to connect. It acts as you, and can never do more than you can."
108
+ })]
109
+ }),
110
+ /* @__PURE__ */ jsxs("div", {
111
+ className: "consent-client",
112
+ children: [/* @__PURE__ */ jsx(Link, { size: 16 }), /* @__PURE__ */ jsxs("span", {
113
+ className: "cell-stack",
114
+ children: [client.host !== null ? /* @__PURE__ */ jsx("span", {
115
+ className: "consent-host mono",
116
+ children: client.host
117
+ }) : /* @__PURE__ */ jsx("span", {
118
+ className: "consent-host",
119
+ children: client.name
120
+ }), /* @__PURE__ */ jsxs("span", { children: [
121
+ client.host !== null && /* @__PURE__ */ jsxs(Fragment$1, { children: [client.name, " "] }),
122
+ unverified && /* @__PURE__ */ jsx("span", {
123
+ className: "tag tag-amber",
124
+ children: "Unverified"
125
+ }),
126
+ unverified && /* @__PURE__ */ jsx("small", { children: " It registered itself: its name is its own claim." })
127
+ ] })]
128
+ })]
129
+ }),
130
+ /* @__PURE__ */ jsxs("dl", {
131
+ className: "facts device-facts",
132
+ children: [
133
+ /* @__PURE__ */ jsxs("div", {
134
+ className: "fact",
135
+ children: [/* @__PURE__ */ jsx("dt", { children: "As" }), /* @__PURE__ */ jsx("dd", {
136
+ className: "mono",
137
+ children: email
138
+ })]
139
+ }),
140
+ /* @__PURE__ */ jsxs("div", {
141
+ className: "fact",
142
+ children: [/* @__PURE__ */ jsx("dt", { children: "Answer goes to" }), /* @__PURE__ */ jsx("dd", {
143
+ className: "mono",
144
+ children: view.redirectHost
145
+ })]
146
+ }),
147
+ /* @__PURE__ */ jsxs("div", {
148
+ className: "fact",
149
+ children: [/* @__PURE__ */ jsx("dt", { children: "For" }), /* @__PURE__ */ jsxs("dd", { children: [view.days, " days, or until you disconnect it on your account page"] })]
150
+ })
151
+ ]
152
+ }),
153
+ /* @__PURE__ */ jsxs("fieldset", {
154
+ className: "consent-scopes",
155
+ children: [/* @__PURE__ */ jsx("legend", {
156
+ className: "label",
157
+ children: "It may"
158
+ }), view.scopes.map((scope) => {
159
+ const { label, description } = MCP_SCOPE_INFO[scope];
160
+ const locked = scope === "browse";
161
+ return /* @__PURE__ */ jsxs("label", {
162
+ className: "consent-scope",
163
+ children: [/* @__PURE__ */ jsx("input", {
164
+ type: "checkbox",
165
+ checked: chosen.has(scope),
166
+ disabled: locked || pending !== null,
167
+ onChange: (event) => toggle(scope, event.target.checked)
168
+ }), /* @__PURE__ */ jsxs("span", {
169
+ className: "cell-stack",
170
+ children: [/* @__PURE__ */ jsxs("span", { children: [label, locked && /* @__PURE__ */ jsx("span", {
171
+ className: "hint",
172
+ children: " · always"
173
+ })] }), /* @__PURE__ */ jsx("small", { children: description })]
174
+ })]
175
+ }, scope);
176
+ })]
177
+ }),
178
+ /* @__PURE__ */ jsxs("div", {
179
+ className: "consent-notices",
180
+ children: [
181
+ chosen.has("read-values") && /* @__PURE__ */ jsxs(Notice, {
182
+ tone: "bad",
183
+ children: [
184
+ "Values will be sent to ",
185
+ client.name,
186
+ ". They become part of the conversation: whoever can read that conversation, and wherever ",
187
+ client.name,
188
+ " stores it, has them."
189
+ ]
190
+ }),
191
+ view.loopbackOnly && /* @__PURE__ */ jsxs(Notice, {
192
+ tone: "warn",
193
+ children: [
194
+ "The answer goes to a program on this computer, ",
195
+ /* @__PURE__ */ jsx("span", {
196
+ className: "mono",
197
+ children: view.redirectHost
198
+ }),
199
+ ". Any program running here could be it: approve only if you just started ",
200
+ client.name,
201
+ " yourself."
202
+ ]
203
+ }),
204
+ replaced > 0 && /* @__PURE__ */ jsxs(Notice, {
205
+ tone: "info",
206
+ children: [
207
+ "This replaces your earlier connection",
208
+ replaced === 1 ? "" : "s",
209
+ " of ",
210
+ client.name,
211
+ ", with fewer scopes: ",
212
+ replaced === 1 ? "it ends" : "they end",
213
+ " once the app has this one."
214
+ ]
215
+ }),
216
+ kept > 0 && /* @__PURE__ */ jsxs(Notice, {
217
+ tone: "info",
218
+ children: [
219
+ "You have connected ",
220
+ client.name,
221
+ " ",
222
+ kept === 1 ? "once" : `${kept} times`,
223
+ " already. This adds another connection; your account page lists them."
224
+ ]
225
+ }),
226
+ /* @__PURE__ */ jsx(ErrorLine, { error })
227
+ ]
228
+ }),
229
+ /* @__PURE__ */ jsxs("div", {
230
+ className: "device-actions",
231
+ children: [/* @__PURE__ */ jsxs("button", {
232
+ className: "btn",
233
+ disabled: pending !== null,
234
+ onClick: () => void decide(false),
235
+ children: [pending === "deny" && /* @__PURE__ */ jsx(Spinner, {}), "Deny"]
236
+ }), /* @__PURE__ */ jsxs("button", {
237
+ className: "btn btn-primary",
238
+ disabled: pending !== null,
239
+ onClick: () => void decide(true),
240
+ children: [pending === "approve" && /* @__PURE__ */ jsx(Spinner, {}), "Approve"]
241
+ })]
242
+ })
243
+ ]
244
+ });
245
+ }
246
+ //#endregion
247
+ export { OauthAuthorizePage };
248
+
249
+ //# sourceMappingURL=oauth-authorize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-authorize.js","names":[],"sources":["../../src/pages/oauth-authorize.tsx"],"sourcesContent":["import { useState } from 'react';\nimport type { AuthorizationView, RouteInput } from '@coffre/client';\nimport { MCP_SCOPE_INFO, supersedes, type McpScope } from '@coffre/core/mcp';\n\nimport { failureMessage, statusOf, useCoffre } from '../lib/coffre';\nimport { ClosedDoor } from '../components/page';\nimport { ErrorLine, Notice, Spinner } from '../components/ui';\nimport { ArrowRight, Link as LinkIcon, SlashCircle } from '../components/icons';\nimport { pageRoute } from '../lib/page-route';\nimport type { oauthAuthorize } from '../options';\n\nconst Route = pageRoute<typeof oauthAuthorize>();\n\ntype Ready = Extract<AuthorizationView, { status: 'ready' }>;\n\n/**\n * Where an MCP client, such as Claude, sends you to connect: who it is,\n * where coffre's answer goes, and what it may do as you. Nothing is granted\n * until you press Approve, and every connection asks again: there is no\n * silent re-consent. Either answer goes back to the app by `location`,\n * never a form post, which the page's `form-action 'self'` would stop.\n */\n\nexport function OauthAuthorizePage() {\n const loaded = Route.useLoaderData();\n const [leaving, setLeaving] = useState(false);\n\n if (leaving) {\n return (\n <ClosedDoor icon={<ArrowRight size={18} />} label=\"Connect an app\" title=\"Sending you back to the app\">\n <p>You can close this tab if the app has already opened.</p>\n </ClosedDoor>\n );\n }\n if (!loaded.result.ok) return <CannotConnect message={loaded.result.error} />;\n const view = loaded.result;\n if (view.status === 'invalid') return <CannotConnect message={view.message} />;\n if (view.status === 'refused') {\n return (\n <ClosedDoor\n icon={<SlashCircle size={18} />}\n label=\"Connect an app\"\n title=\"This request can't be approved\"\n actions={\n <button\n className=\"btn\"\n onClick={() => {\n setLeaving(true);\n location.assign(view.redirect);\n }}\n >\n Back to the app\n </button>\n }\n >\n <p>{view.message}. Nothing was granted; the app is told why.</p>\n </ClosedDoor>\n );\n }\n return (\n <Approve\n view={view}\n email={loaded.email}\n request={loaded.request}\n onLeave={(redirect) => {\n setLeaving(true);\n location.assign(redirect);\n }}\n />\n );\n}\n\n/** A client or redirect that fails its checks: said here, and never redirected to, which would be an open redirect. */\nfunction CannotConnect({ message }: { message: string }) {\n return (\n <ClosedDoor icon={<SlashCircle size={18} />} label=\"Connect an app\" title=\"This app can't connect\">\n <p>{message}</p>\n <p>Nothing was sent to it. If you were trying to connect it, tell whoever makes it.</p>\n </ClosedDoor>\n );\n}\n\nfunction Approve({\n view,\n email,\n request,\n onLeave,\n}: {\n view: Ready;\n email: string;\n request: RouteInput<'GET /oauth/authorizations'>;\n onLeave: (redirect: string) => void;\n}) {\n const coffre = useCoffre();\n const [chosen, setChosen] = useState<ReadonlySet<McpScope>>(() => new Set(view.scopes));\n const [pending, setPending] = useState<'approve' | 'deny' | null>(null);\n const [error, setError] = useState<string | null>(null);\n const { client } = view;\n const unverified = client.registration === 'dcr';\n // A step-up: the connections this one grants all of and more end once the app has its new one.\n const granted = view.scopes.filter((scope) => chosen.has(scope));\n const replaced = view.connections.filter((held) => supersedes(granted, held)).length;\n const kept = view.connections.length - replaced;\n\n async function decide(approve: boolean) {\n setPending(approve ? 'approve' : 'deny');\n try {\n const { redirect } = await coffre.oauth.decide({ request, approve, scopes: [...chosen] });\n onLeave(redirect);\n } catch (error) {\n setError(\n statusOf(error) === undefined ? 'The answer could not be sent. Nothing was approved.' : failureMessage(error),\n );\n setPending(null);\n }\n }\n\n function toggle(scope: McpScope, on: boolean) {\n const next = new Set(chosen);\n if (on) next.add(scope);\n else next.delete(scope);\n setChosen(next);\n }\n\n return (\n <section className=\"card signin\" aria-labelledby=\"consent-title\">\n <div className=\"signin-head\">\n <h1 className=\"signin-title\" id=\"consent-title\">\n Connect {client.name} to coffre?\n </h1>\n <p className=\"signin-lede\">\n Only if you just asked it to connect. It acts as you, and can never do more than you can.\n </p>\n </div>\n\n <div className=\"consent-client\">\n <LinkIcon size={16} />\n {/* The website first, which a name cannot fake; a registration has none, and says so. */}\n <span className=\"cell-stack\">\n {client.host !== null ? (\n <span className=\"consent-host mono\">{client.host}</span>\n ) : (\n <span className=\"consent-host\">{client.name}</span>\n )}\n <span>\n {client.host !== null && <>{client.name} </>}\n {unverified && <span className=\"tag tag-amber\">Unverified</span>}\n {unverified && <small> It registered itself: its name is its own claim.</small>}\n </span>\n </span>\n </div>\n\n <dl className=\"facts device-facts\">\n <div className=\"fact\">\n <dt>As</dt>\n <dd className=\"mono\">{email}</dd>\n </div>\n <div className=\"fact\">\n <dt>Answer goes to</dt>\n <dd className=\"mono\">{view.redirectHost}</dd>\n </div>\n <div className=\"fact\">\n <dt>For</dt>\n <dd>{view.days} days, or until you disconnect it on your account page</dd>\n </div>\n </dl>\n\n <fieldset className=\"consent-scopes\">\n <legend className=\"label\">It may</legend>\n {view.scopes.map((scope) => {\n const { label, description } = MCP_SCOPE_INFO[scope];\n const locked = scope === 'browse';\n return (\n <label key={scope} className=\"consent-scope\">\n <input\n type=\"checkbox\"\n checked={chosen.has(scope)}\n disabled={locked || pending !== null}\n onChange={(event) => toggle(scope, event.target.checked)}\n />\n <span className=\"cell-stack\">\n <span>\n {label}\n {locked && <span className=\"hint\"> · always</span>}\n </span>\n <small>{description}</small>\n </span>\n </label>\n );\n })}\n </fieldset>\n\n <div className=\"consent-notices\">\n {chosen.has('read-values') && (\n <Notice tone=\"bad\">\n Values will be sent to {client.name}. They become part of the conversation: whoever can read\n that conversation, and wherever {client.name} stores it, has them.\n </Notice>\n )}\n {view.loopbackOnly && (\n <Notice tone=\"warn\">\n The answer goes to a program on this computer, <span className=\"mono\">{view.redirectHost}</span>.\n Any program running here could be it: approve only if you just started {client.name} yourself.\n </Notice>\n )}\n {replaced > 0 && (\n <Notice tone=\"info\">\n This replaces your earlier connection{replaced === 1 ? '' : 's'} of {client.name}, with fewer scopes: {replaced === 1 ? 'it ends' : 'they end'} once\n the app has this one.\n </Notice>\n )}\n {kept > 0 && (\n <Notice tone=\"info\">\n You have connected {client.name} {kept === 1 ? 'once' : `${kept} times`} already.\n This adds another connection; your account page lists them.\n </Notice>\n )}\n <ErrorLine error={error} />\n </div>\n\n <div className=\"device-actions\">\n <button className=\"btn\" disabled={pending !== null} onClick={() => void decide(false)}>\n {pending === 'deny' && <Spinner />}\n Deny\n </button>\n <button className=\"btn btn-primary\" disabled={pending !== null} onClick={() => void decide(true)}>\n {pending === 'approve' && <Spinner />}\n Approve\n </button>\n </div>\n </section>\n );\n}\n"],"mappings":";;;;;;;AAWA,IAAM,QAAQ,UAAiC;;;;;;;;AAY/C,SAAgB,qBAAqB;CACnC,MAAM,SAAS,MAAM,cAAc;CACnC,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAE5C,IAAI,SACF,OACE,oBAAC,YAAD;EAAY,MAAM,oBAAC,YAAD,EAAY,MAAM,GAAK,CAAA;EAAG,OAAM;EAAiB,OAAM;YACvE,oBAAC,KAAD,EAAA,UAAG,wDAAwD,CAAA;CACjD,CAAA;CAGhB,IAAI,CAAC,OAAO,OAAO,IAAI,OAAO,oBAAC,eAAD,EAAe,SAAS,OAAO,OAAO,MAAQ,CAAA;CAC5E,MAAM,OAAO,OAAO;CACpB,IAAI,KAAK,WAAW,WAAW,OAAO,oBAAC,eAAD,EAAe,SAAS,KAAK,QAAU,CAAA;CAC7E,IAAI,KAAK,WAAW,WAClB,OACE,oBAAC,YAAD;EACE,MAAM,oBAAC,aAAD,EAAa,MAAM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qBAAC,QAAD;MAAQ,MAAK;gBAAb;OAAoB;OACoB,aAAa,IAAI,KAAK;OAAI;OAAK,OAAO;OAAK;OAAsB,aAAa,IAAI,YAAY;OAAW;MAEzI;;KAET,OAAO,KACN,qBAAC,QAAD;MAAQ,MAAK;gBAAb;OAAoB;OACE,OAAO;OAAK;OAAE,SAAS,IAAI,SAAS,GAAG,KAAK;OAAQ;MAElE;;KAEV,oBAAC,WAAD,EAAkB,MAAQ,CAAA;IACvB;;GAEL,qBAAC,OAAD;IAAK,WAAU;cAAf,CACE,qBAAC,UAAD;KAAQ,WAAU;KAAM,UAAU,YAAY;KAAM,eAAe,KAAK,OAAO,KAAK;eAApF,CACG,YAAY,UAAU,oBAAC,SAAD,CAAU,CAAA,GAAE,MAE7B;QACR,qBAAC,UAAD;KAAQ,WAAU;KAAkB,UAAU,YAAY;KAAM,eAAe,KAAK,OAAO,IAAI;eAA/F,CACG,YAAY,aAAa,oBAAC,SAAD,CAAU,CAAA,GAAE,SAEhC;MACL;;EACE;;AAEb"}
@@ -0,0 +1,6 @@
1
+ //#region src/pages/project-access.d.ts
2
+ /** A project's users: who holds access, and what others read of it through references. */
3
+ export declare function ProjectUsersPage(): import("react").JSX.Element;
4
+ /** A project's service accounts: which hold access. */
5
+ export declare function ProjectServiceAccountsPage(): import("react").JSX.Element;
6
+ //#endregion
@@ -0,0 +1,370 @@
1
+ import { c as Notice, i as EmptyState, l as Spinner, s as Modal } from "../chunks/ui-DJje3gST.js";
2
+ import { A as Key, K as Search, U as Plus, _ as Check, tt as User, u as useCoffre } from "../chunks/page-DvsgZ2Hd.js";
3
+ import { p as queries } from "../chunks/queries-DVR_i3rA.js";
4
+ import { t as useShell } from "../chunks/use-shell-rNKfGjdj.js";
5
+ import { A as projectAccessOptions, O as parseProjectAccess, k as projectAccessLabel, m as grantId, p as grantAccess, t as useChange } from "../chunks/use-change-DUiGO19U.js";
6
+ import { n as PrincipalLink, t as PrincipalAvatar } from "../chunks/principal-BIN-xwZw.js";
7
+ import { r as KIND } from "../chunks/directory-zr3ek7Mc.js";
8
+ import { t as pageRoute } from "../chunks/page-route-Drfw7lmn.js";
9
+ import { a as ReferencesInto } from "../chunks/references-B6pLT1uQ.js";
10
+ import { i as useRefusedGrants, n as GrantsTable, r as RefusedGrants, t as GrantRowView } from "../chunks/grants-Cw1FyGID.js";
11
+ import { t as useProject } from "../chunks/project-page-SRCtRe2g.js";
12
+ import { useId, useState } from "react";
13
+ import { Link } from "@tanstack/react-router";
14
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
15
+ import { useQuery, useSuspenseQuery } from "@tanstack/react-query";
16
+ //#region src/components/principal-picker.tsx
17
+ /**
18
+ * Who a grant is for: picked from the registered users or service accounts, each shown
19
+ * with what it already holds on this project, or typed when the list is not
20
+ * yours to read.
21
+ *
22
+ * Only instance owners may list the directory. Asking on anyone else's behalf
23
+ * would write a refusal to the audit log in their name, so they get a text
24
+ * field and the server's answer instead. The list is asked for when the
25
+ * dialog opens rather than with the page, since most visits never open it,
26
+ * and shared with the Users and Service accounts pages through the cache.
27
+ */
28
+ function PrincipalPicker({ principalType, canList, grants, value, onChange }) {
29
+ const coffre = useCoffre();
30
+ const directory = useQuery(queries.directory(coffre, canList)).data ?? null;
31
+ const [query, setQuery] = useState("");
32
+ const name = useId();
33
+ const kind = KIND[principalType];
34
+ const label = principalType === "user" ? "User" : "Token";
35
+ if (!canList || directory?.ok === false) return /* @__PURE__ */ jsxs("label", {
36
+ className: "field",
37
+ children: [
38
+ /* @__PURE__ */ jsx("span", {
39
+ className: "label",
40
+ children: principalType === "user" ? "Email" : "Service account name"
41
+ }),
42
+ /* @__PURE__ */ jsx("input", {
43
+ className: "input input-mono",
44
+ autoFocus: true,
45
+ spellCheck: false,
46
+ autoComplete: "off",
47
+ placeholder: principalType === "user" ? "someone@acme.example" : "ci-deploy",
48
+ value,
49
+ onChange: (event) => onChange(event.target.value)
50
+ }),
51
+ /* @__PURE__ */ jsxs("span", {
52
+ className: "hint",
53
+ children: [
54
+ "The ",
55
+ kind,
56
+ " must already be registered under ",
57
+ principalType === "user" ? "Users" : "Service accounts",
58
+ "."
59
+ ]
60
+ })
61
+ ]
62
+ });
63
+ const registered = directory?.principals.filter((principal) => principal.principalType === principalType) ?? [];
64
+ const needle = query.trim().toLowerCase();
65
+ const matches = registered.filter((principal) => principal.principalId.toLowerCase().includes(needle));
66
+ return /* @__PURE__ */ jsxs("fieldset", {
67
+ className: "field picker",
68
+ children: [
69
+ /* @__PURE__ */ jsx("legend", {
70
+ className: "label",
71
+ children: label
72
+ }),
73
+ /* @__PURE__ */ jsxs("label", {
74
+ className: "input-group",
75
+ children: [
76
+ /* @__PURE__ */ jsxs("span", {
77
+ className: "visually-hidden",
78
+ children: [
79
+ "Filter ",
80
+ kind,
81
+ "s by name"
82
+ ]
83
+ }),
84
+ /* @__PURE__ */ jsx(Search, {
85
+ size: 14,
86
+ className: "input-icon"
87
+ }),
88
+ /* @__PURE__ */ jsx("input", {
89
+ className: "input",
90
+ type: "search",
91
+ autoFocus: true,
92
+ spellCheck: false,
93
+ autoComplete: "off",
94
+ placeholder: principalType === "user" ? "Filter by email…" : "Filter by name…",
95
+ value: query,
96
+ onChange: (event) => setQuery(event.target.value),
97
+ onKeyDown: (event) => {
98
+ if (event.key === "Enter" && matches.length === 1) {
99
+ event.preventDefault();
100
+ onChange(matches[0].principalId);
101
+ }
102
+ }
103
+ })
104
+ ]
105
+ }),
106
+ /* @__PURE__ */ jsx("div", {
107
+ className: "picker-list",
108
+ children: directory === null ? /* @__PURE__ */ jsxs("p", {
109
+ className: "picker-empty",
110
+ children: [
111
+ /* @__PURE__ */ jsx(Spinner, { size: 13 }),
112
+ "Loading ",
113
+ kind,
114
+ "s…"
115
+ ]
116
+ }) : registered.length === 0 ? /* @__PURE__ */ jsxs("p", {
117
+ className: "picker-empty",
118
+ children: [
119
+ "No ",
120
+ kind,
121
+ "s are registered yet.",
122
+ " ",
123
+ /* @__PURE__ */ jsx(Link, {
124
+ to: principalType === "user" ? "/users" : "/service-accounts",
125
+ children: "Add one"
126
+ }),
127
+ " first."
128
+ ]
129
+ }) : matches.length === 0 ? /* @__PURE__ */ jsxs("p", {
130
+ className: "picker-empty",
131
+ children: [
132
+ "No registered ",
133
+ kind,
134
+ " matches “",
135
+ query.trim(),
136
+ "”."
137
+ ]
138
+ }) : matches.map((principal) => {
139
+ const held = grants.filter((grant) => grant.principalType === principalType && grant.principalId === principal.principalId).map(projectAccessLabel);
140
+ const chosen = principal.principalId === value;
141
+ return /* @__PURE__ */ jsxs("label", {
142
+ className: `picker-option${chosen ? " is-chosen" : ""}`,
143
+ children: [
144
+ /* @__PURE__ */ jsx("input", {
145
+ type: "radio",
146
+ className: "visually-hidden",
147
+ name,
148
+ value: principal.principalId,
149
+ checked: chosen,
150
+ onChange: () => onChange(principal.principalId)
151
+ }),
152
+ /* @__PURE__ */ jsx(PrincipalAvatar, {
153
+ type: principalType,
154
+ id: principal.principalId
155
+ }),
156
+ /* @__PURE__ */ jsx("span", {
157
+ className: "picker-name",
158
+ children: principal.principalId
159
+ }),
160
+ held.length > 0 && /* @__PURE__ */ jsxs("span", {
161
+ className: "picker-held",
162
+ children: [/* @__PURE__ */ jsx("span", {
163
+ className: "visually-hidden",
164
+ children: "holds"
165
+ }), held.map((access) => /* @__PURE__ */ jsx("span", {
166
+ className: "tag",
167
+ children: access
168
+ }, access))]
169
+ }),
170
+ /* @__PURE__ */ jsx(Check, {
171
+ size: 14,
172
+ className: "picker-check"
173
+ })
174
+ ]
175
+ }, principal.principalId);
176
+ })
177
+ })
178
+ ]
179
+ });
180
+ }
181
+ //#endregion
182
+ //#region src/pages/project-access.tsx
183
+ /** A project's users: who holds access, and what others read of it through references. */
184
+ function ProjectUsersPage() {
185
+ const { project: slug } = pageRoute().useParams();
186
+ return /* @__PURE__ */ jsx(ProjectAccess, {
187
+ slug,
188
+ principalType: "user",
189
+ children: /* @__PURE__ */ jsx(ReferencesInto, { project: slug })
190
+ });
191
+ }
192
+ /** A project's service accounts: which hold access. */
193
+ function ProjectServiceAccountsPage() {
194
+ const { project: slug } = pageRoute().useParams();
195
+ return /* @__PURE__ */ jsx(ProjectAccess, {
196
+ slug,
197
+ principalType: "service"
198
+ });
199
+ }
200
+ function ProjectAccess({ slug, principalType, children }) {
201
+ const { project } = useProject(slug);
202
+ const { data: result } = useSuspenseQuery(queries.grants(useCoffre(), slug));
203
+ if (!result.ok) return /* @__PURE__ */ jsx(Notice, {
204
+ tone: "bad",
205
+ children: result.error
206
+ });
207
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(AccessPanel, {
208
+ principalType,
209
+ project: slug,
210
+ environments: project.environments,
211
+ grants: result.grants
212
+ }), children] });
213
+ }
214
+ /** One kind's grants on the project, and below them the way to add one. */
215
+ function AccessPanel({ principalType, project, environments, grants: all }) {
216
+ const people = principalType === "user";
217
+ const kind = KIND[principalType];
218
+ const grants = all.filter((grant) => grant.principalType === principalType);
219
+ const refused = useRefusedGrants(project, grants, principalType);
220
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("section", {
221
+ className: "card",
222
+ "aria-label": people ? "Users with access" : "Service accounts with access",
223
+ children: grants.length === 0 && refused.length === 0 ? /* @__PURE__ */ jsxs(EmptyState, {
224
+ title: `No ${kind} has access`,
225
+ children: [
226
+ "Add a ",
227
+ kind,
228
+ " with permissions on the whole project or on one environment."
229
+ ]
230
+ }) : /* @__PURE__ */ jsxs(GrantsTable, {
231
+ lead: /* @__PURE__ */ jsxs("span", {
232
+ className: "th",
233
+ children: [people ? /* @__PURE__ */ jsx(User, { size: 14 }) : /* @__PURE__ */ jsx(Key, { size: 14 }), people ? "Email" : "Name"]
234
+ }),
235
+ children: [grants.map((grant, index) => /* @__PURE__ */ jsx(GrantRowView, {
236
+ number: index + 1,
237
+ project,
238
+ grant,
239
+ leadLabel: people ? "Email" : "Name",
240
+ lead: /* @__PURE__ */ jsx(PrincipalLink, {
241
+ type: grant.principalType,
242
+ id: grant.principalId
243
+ })
244
+ }, grantId(grant))), /* @__PURE__ */ jsx(RefusedGrants, { refused })]
245
+ })
246
+ }), /* @__PURE__ */ jsx("div", {
247
+ className: "table-actions",
248
+ children: /* @__PURE__ */ jsx(NewGrant, {
249
+ principalType,
250
+ project,
251
+ environments,
252
+ grants: all
253
+ })
254
+ })] });
255
+ }
256
+ function NewGrant({ principalType, project, environments, grants }) {
257
+ const { capabilities } = useShell();
258
+ const [open, setOpen] = useState(false);
259
+ const [principalId, setPrincipalId] = useState("");
260
+ const [permission, setPermission] = useState("viewer:");
261
+ const [expiresAt, setExpiresAt] = useState("");
262
+ const grant = useChange(grantAccess(useCoffre(), project));
263
+ const permissionOptions = projectAccessOptions(environments);
264
+ const kind = KIND[principalType];
265
+ function close() {
266
+ setOpen(false);
267
+ }
268
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("button", {
269
+ className: "btn btn-primary",
270
+ onClick: () => setOpen(true),
271
+ children: [
272
+ /* @__PURE__ */ jsx(Plus, { size: 14 }),
273
+ "Add ",
274
+ kind
275
+ ]
276
+ }), /* @__PURE__ */ jsx(Modal, {
277
+ open,
278
+ onOpenChange: (next) => next ? setOpen(true) : close(),
279
+ title: /* @__PURE__ */ jsxs(Fragment$1, { children: [
280
+ "Give a ",
281
+ kind,
282
+ " access to ",
283
+ /* @__PURE__ */ jsx("span", {
284
+ className: "mono",
285
+ children: project
286
+ })
287
+ ] }),
288
+ wide: true,
289
+ description: "Owners manage the whole project and its access. Read and write can cover every environment, or one.",
290
+ children: /* @__PURE__ */ jsxs("form", {
291
+ className: "form",
292
+ onSubmit: (event) => {
293
+ event.preventDefault();
294
+ const access = parseProjectAccess(permission);
295
+ grant({
296
+ principalType,
297
+ principalId: principalId.trim(),
298
+ role: access.role,
299
+ roleName: permissionOptions.find((option) => option.value === permission)?.label ?? access.role,
300
+ environmentSlug: access.environmentSlug,
301
+ expiresAt: expiresAt === "" ? null : (/* @__PURE__ */ new Date(`${expiresAt}T23:59:59Z`)).toISOString()
302
+ });
303
+ setPrincipalId("");
304
+ setExpiresAt("");
305
+ setPermission("viewer:");
306
+ close();
307
+ },
308
+ children: [
309
+ /* @__PURE__ */ jsx(PrincipalPicker, {
310
+ principalType,
311
+ canList: capabilities.canManageGrants,
312
+ grants,
313
+ value: principalId,
314
+ onChange: setPrincipalId
315
+ }),
316
+ /* @__PURE__ */ jsxs("div", {
317
+ className: "form-row",
318
+ children: [/* @__PURE__ */ jsxs("label", {
319
+ className: "field",
320
+ style: { flexGrow: 2 },
321
+ children: [/* @__PURE__ */ jsx("span", {
322
+ className: "label",
323
+ children: "Permissions"
324
+ }), /* @__PURE__ */ jsx("select", {
325
+ className: "select",
326
+ value: permission,
327
+ onChange: (event) => setPermission(event.target.value),
328
+ children: permissionOptions.map((option) => /* @__PURE__ */ jsx("option", {
329
+ value: option.value,
330
+ children: option.label
331
+ }, option.value))
332
+ })]
333
+ }), /* @__PURE__ */ jsxs("label", {
334
+ className: "field",
335
+ children: [/* @__PURE__ */ jsxs("span", {
336
+ className: "label",
337
+ children: ["Expires ", /* @__PURE__ */ jsx("span", {
338
+ className: "hint",
339
+ children: "(optional)"
340
+ })]
341
+ }), /* @__PURE__ */ jsx("input", {
342
+ className: "input",
343
+ type: "date",
344
+ value: expiresAt,
345
+ onChange: (event) => setExpiresAt(event.target.value)
346
+ })]
347
+ })]
348
+ }),
349
+ /* @__PURE__ */ jsxs("div", {
350
+ className: "dialog-actions",
351
+ children: [/* @__PURE__ */ jsx("button", {
352
+ className: "btn",
353
+ type: "button",
354
+ onClick: close,
355
+ children: "Cancel"
356
+ }), /* @__PURE__ */ jsx("button", {
357
+ className: "btn btn-primary",
358
+ type: "submit",
359
+ disabled: principalId.trim() === "",
360
+ children: "Grant access"
361
+ })]
362
+ })
363
+ ]
364
+ })
365
+ })] });
366
+ }
367
+ //#endregion
368
+ export { ProjectServiceAccountsPage, ProjectUsersPage };
369
+
370
+ //# sourceMappingURL=project-access.js.map