@coffre/ui 0.3.0 → 0.4.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 (180) 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/connected-apps-CUOyEZXR.js +146 -0
  4. package/dist/chunks/connected-apps-CUOyEZXR.js.map +1 -0
  5. package/dist/chunks/delete-place-CRX7ntE8.js +206 -0
  6. package/dist/chunks/delete-place-CRX7ntE8.js.map +1 -0
  7. package/dist/chunks/{directory-CSjWWUQ1.js → directory-CxxrnGUL.js} +177 -60
  8. package/dist/chunks/directory-CxxrnGUL.js.map +1 -0
  9. package/dist/chunks/folders-DoBmCwOi.js +207 -0
  10. package/dist/chunks/folders-DoBmCwOi.js.map +1 -0
  11. package/dist/chunks/grants-CXcmhujY.js +669 -0
  12. package/dist/chunks/grants-CXcmhujY.js.map +1 -0
  13. package/dist/chunks/offboarding-6eAduCsM.js +305 -0
  14. package/dist/chunks/offboarding-6eAduCsM.js.map +1 -0
  15. package/dist/chunks/one-time-DXEl9hbg.js +35 -0
  16. package/dist/chunks/one-time-DXEl9hbg.js.map +1 -0
  17. package/dist/chunks/page-DvsgZ2Hd.js +391 -0
  18. package/dist/chunks/page-DvsgZ2Hd.js.map +1 -0
  19. package/dist/chunks/principal-BIN-xwZw.js +42 -0
  20. package/dist/chunks/principal-BIN-xwZw.js.map +1 -0
  21. package/dist/chunks/{principal-page-D_91OA0l.js → principal-page-B9R2zPlp.js} +259 -251
  22. package/dist/chunks/principal-page-B9R2zPlp.js.map +1 -0
  23. package/dist/chunks/project-page-SRCtRe2g.js +17 -0
  24. package/dist/chunks/project-page-SRCtRe2g.js.map +1 -0
  25. package/dist/chunks/{queries-CQ81o4so.js → queries-DVR_i3rA.js} +132 -30
  26. package/dist/chunks/queries-DVR_i3rA.js.map +1 -0
  27. package/dist/chunks/references-B6pLT1uQ.js +343 -0
  28. package/dist/chunks/references-B6pLT1uQ.js.map +1 -0
  29. package/dist/chunks/{row-state-0PsrEzOL.js → row-state-DOPUsjQK.js} +3 -3
  30. package/dist/chunks/{row-state-0PsrEzOL.js.map → row-state-DOPUsjQK.js.map} +1 -1
  31. package/dist/chunks/signin-errors--ykMFuqN.js +57 -0
  32. package/dist/chunks/signin-errors--ykMFuqN.js.map +1 -0
  33. package/dist/chunks/tabs-BmwKfUeK.js +22 -0
  34. package/dist/chunks/tabs-BmwKfUeK.js.map +1 -0
  35. package/dist/chunks/{theme-B2vQolVR.js → theme-DJuz-xLM.js} +3 -3
  36. package/dist/chunks/{theme-B2vQolVR.js.map → theme-DJuz-xLM.js.map} +1 -1
  37. package/dist/chunks/{ui-DixXLQvQ.js → ui-DJje3gST.js} +6 -3
  38. package/dist/chunks/ui-DJje3gST.js.map +1 -0
  39. package/dist/chunks/{use-change-c6CeLRin.js → use-change-CZdI2MJG.js} +75 -21
  40. package/dist/chunks/use-change-CZdI2MJG.js.map +1 -0
  41. package/dist/chunks/{use-shell-jxd7Tzd-.js → use-shell-rNKfGjdj.js} +3 -3
  42. package/dist/chunks/{use-shell-jxd7Tzd-.js.map → use-shell-rNKfGjdj.js.map} +1 -1
  43. package/dist/chunks/validation-D312_NLf.js +87 -0
  44. package/dist/chunks/validation-D312_NLf.js.map +1 -0
  45. package/dist/index.d.ts +385 -31
  46. package/dist/index.js +188 -102
  47. package/dist/index.js.map +1 -1
  48. package/dist/pages/account.d.ts +2 -2
  49. package/dist/pages/account.js +174 -135
  50. package/dist/pages/account.js.map +1 -1
  51. package/dist/pages/approval.d.ts +9 -0
  52. package/dist/pages/approval.js +207 -0
  53. package/dist/pages/approval.js.map +1 -0
  54. package/dist/pages/audit.js +17 -542
  55. package/dist/pages/audit.js.map +1 -1
  56. package/dist/pages/device-login.js +2 -3
  57. package/dist/pages/device-login.js.map +1 -1
  58. package/dist/pages/environment.js +647 -257
  59. package/dist/pages/environment.js.map +1 -1
  60. package/dist/pages/login.js +18 -7
  61. package/dist/pages/login.js.map +1 -1
  62. package/dist/pages/oauth-authorize.d.ts +10 -0
  63. package/dist/pages/oauth-authorize.js +249 -0
  64. package/dist/pages/oauth-authorize.js.map +1 -0
  65. package/dist/pages/project-access.d.ts +6 -0
  66. package/dist/pages/project-access.js +370 -0
  67. package/dist/pages/project-access.js.map +1 -0
  68. package/dist/pages/project-environments.d.ts +4 -0
  69. package/dist/pages/project-environments.js +593 -0
  70. package/dist/pages/project-environments.js.map +1 -0
  71. package/dist/pages/project-settings.d.ts +4 -0
  72. package/dist/pages/project-settings.js +242 -0
  73. package/dist/pages/project-settings.js.map +1 -0
  74. package/dist/pages/project.d.ts +10 -2
  75. package/dist/pages/project.js +57 -934
  76. package/dist/pages/project.js.map +1 -1
  77. package/dist/pages/projects.js +53 -21
  78. package/dist/pages/projects.js.map +1 -1
  79. package/dist/pages/service-account.d.ts +10 -0
  80. package/dist/pages/{token.js → service-account.js} +112 -54
  81. package/dist/pages/service-account.js.map +1 -0
  82. package/dist/pages/service-accounts.d.ts +3 -0
  83. package/dist/pages/service-accounts.js +38 -0
  84. package/dist/pages/service-accounts.js.map +1 -0
  85. package/dist/pages/settings.d.ts +1 -0
  86. package/dist/pages/settings.js +104 -42
  87. package/dist/pages/settings.js.map +1 -1
  88. package/dist/pages/unregistered.js +2 -3
  89. package/dist/pages/unregistered.js.map +1 -1
  90. package/dist/pages/user.d.ts +6 -1
  91. package/dist/pages/user.js +18 -6
  92. package/dist/pages/user.js.map +1 -1
  93. package/dist/pages/users.js +6 -10
  94. package/dist/pages/users.js.map +1 -1
  95. package/package.json +3 -3
  96. package/src/components/actions-log.tsx +117 -0
  97. package/src/components/audit-sentence.tsx +55 -0
  98. package/src/components/command-palette.tsx +4 -4
  99. package/src/components/connected-apps.tsx +138 -0
  100. package/src/components/delete-place.tsx +180 -0
  101. package/src/components/directory.tsx +266 -110
  102. package/src/components/every-project.tsx +287 -0
  103. package/src/components/expiry-field.tsx +42 -0
  104. package/src/components/folders.tsx +219 -0
  105. package/src/components/grants.tsx +11 -4
  106. package/src/components/icons.tsx +2 -0
  107. package/src/components/missing.tsx +110 -0
  108. package/src/components/offboarding.tsx +62 -34
  109. package/src/components/page.tsx +4 -1
  110. package/src/components/principal-page.tsx +154 -108
  111. package/src/components/principal-picker.tsx +5 -5
  112. package/src/components/principal.tsx +4 -4
  113. package/src/components/references.tsx +323 -0
  114. package/src/components/service-tokens.tsx +112 -93
  115. package/src/components/shell.tsx +11 -32
  116. package/src/components/tabs.tsx +18 -0
  117. package/src/components/trusted-workloads.tsx +97 -79
  118. package/src/components/ui.tsx +8 -1
  119. package/src/index.ts +13 -3
  120. package/src/layout.tsx +2 -2
  121. package/src/lib/access-plan.ts +2 -2
  122. package/src/lib/audit-sentences.ts +161 -77
  123. package/src/lib/changes.ts +77 -5
  124. package/src/lib/coffre.ts +3 -2
  125. package/src/lib/one-time.ts +32 -0
  126. package/src/lib/project-access.ts +11 -23
  127. package/src/lib/project-page.ts +14 -0
  128. package/src/lib/queries.ts +126 -32
  129. package/src/lib/search.ts +25 -0
  130. package/src/lib/signin-errors.ts +45 -1
  131. package/src/lib/validation.ts +14 -0
  132. package/src/options.ts +187 -42
  133. package/src/pages/account.tsx +176 -133
  134. package/src/pages/approval.tsx +197 -0
  135. package/src/pages/audit.tsx +9 -61
  136. package/src/pages/environment.tsx +585 -286
  137. package/src/pages/login.tsx +8 -2
  138. package/src/pages/oauth-authorize.tsx +233 -0
  139. package/src/pages/project-access.tsx +219 -0
  140. package/src/pages/project-environments.tsx +582 -0
  141. package/src/pages/project-settings.tsx +259 -0
  142. package/src/pages/project.tsx +52 -879
  143. package/src/pages/projects.tsx +55 -18
  144. package/src/pages/service-account.tsx +50 -0
  145. package/src/pages/{tokens.tsx → service-accounts.tsx} +9 -6
  146. package/src/pages/settings.tsx +62 -8
  147. package/src/pages/user.tsx +16 -4
  148. package/src/pages/users.tsx +2 -2
  149. package/src/parity.ts +160 -0
  150. package/src/register.ts +57 -10
  151. package/src/router.tsx +4 -0
  152. package/src/shared/models.ts +6 -2
  153. package/src/styles/globals.css +536 -31
  154. package/dist/chunks/directory-CSjWWUQ1.js.map +0 -1
  155. package/dist/chunks/grants-saMQagmG.js +0 -160
  156. package/dist/chunks/grants-saMQagmG.js.map +0 -1
  157. package/dist/chunks/icons-D-PfAfnH.js +0 -203
  158. package/dist/chunks/icons-D-PfAfnH.js.map +0 -1
  159. package/dist/chunks/offboarding-C6l30DZR.js +0 -263
  160. package/dist/chunks/offboarding-C6l30DZR.js.map +0 -1
  161. package/dist/chunks/page-C5HcNqf2.js +0 -190
  162. package/dist/chunks/page-C5HcNqf2.js.map +0 -1
  163. package/dist/chunks/principal-page-D_91OA0l.js.map +0 -1
  164. package/dist/chunks/queries-CQ81o4so.js.map +0 -1
  165. package/dist/chunks/signin-errors-BEFlVDbQ.js +0 -30
  166. package/dist/chunks/signin-errors-BEFlVDbQ.js.map +0 -1
  167. package/dist/chunks/ui-DixXLQvQ.js.map +0 -1
  168. package/dist/chunks/use-action-CWsg_YWU.js +0 -49
  169. package/dist/chunks/use-action-CWsg_YWU.js.map +0 -1
  170. package/dist/chunks/use-change-c6CeLRin.js.map +0 -1
  171. package/dist/chunks/validation-BQtqPe2V.js +0 -29
  172. package/dist/chunks/validation-BQtqPe2V.js.map +0 -1
  173. package/dist/pages/token.d.ts +0 -3
  174. package/dist/pages/token.js.map +0 -1
  175. package/dist/pages/tokens.d.ts +0 -3
  176. package/dist/pages/tokens.js +0 -39
  177. package/dist/pages/tokens.js.map +0 -1
  178. package/dist/project-BqIy8gYR.d.ts +0 -5
  179. package/src/lib/instance.ts +0 -13
  180. package/src/pages/token.tsx +0 -34
package/src/options.ts CHANGED
@@ -17,12 +17,26 @@
17
17
  // another path is one the links do not reach.
18
18
  import { redirect, type ParsedLocation } from '@tanstack/react-router';
19
19
  import type { QueryClient } from '@tanstack/react-query';
20
- import type { CoffreClient } from '@coffre/client';
20
+ import type { CoffreClient, RouteInput } from '@coffre/client';
21
21
 
22
22
  import { ShellLayout, SoloLayout } from './layout';
23
- import { uiResult } from './lib/coffre';
24
- import { loadDirectory, loadPrincipal, loadProject, loadShell, queries, type AuditSearch } from './lib/queries';
25
- import type { ProjectTab } from './pages/project';
23
+ import { memberRef, uiResult } from './lib/coffre';
24
+ import { stringsOf } from './lib/search';
25
+ import {
26
+ loadAccess,
27
+ loadDirectory,
28
+ loadMember,
29
+ loadProject,
30
+ loadServiceDirectory,
31
+ loadSettings,
32
+ loadShell,
33
+ projectOf,
34
+ queries,
35
+ signInWays,
36
+ type AuditSearch,
37
+ } from './lib/queries';
38
+ import type { Permission } from './shared/models';
39
+ import { loginSearch } from './lib/signin-errors';
26
40
 
27
41
  /**
28
42
  * What coffre's routes read through the router: the API as the visitor
@@ -73,28 +87,85 @@ export const projects = {
73
87
  },
74
88
  };
75
89
 
76
- /** `/projects/$project`. */
90
+ /**
91
+ * `/projects/$project`, the layout of a project's tabs: its header, and the
92
+ * tabs its visitor may open. Each tab is a page under it that reads its own.
93
+ */
77
94
  export const project = {
78
- // The tab lives in the URL so a link can land on a project's access list.
79
- // Environments is the default and so has no parameter.
80
- validateSearch: (search: Record<string, unknown>): { tab?: Exclude<ProjectTab, 'environments'> } => ({
81
- tab: search.tab === 'users' || search.tab === 'tokens' || search.tab === 'settings' ? search.tab : undefined,
82
- }),
95
+ loader: ({ context }: Loader<{ project: string }>) => {
96
+ const { coffre, queryClient } = coffreOf(context);
97
+ return queryClient.fetchQuery(queries.projects(coffre));
98
+ },
99
+ };
100
+
101
+ /** `/projects/$project/`, its environments, and who can open each when you manage its access. */
102
+ export const projectEnvironments = {
83
103
  loader: ({ context, params }: Loader<{ project: string }>) => {
84
104
  const { coffre, queryClient } = coffreOf(context);
85
105
  return loadProject(queryClient, coffre, params.project);
86
106
  },
87
107
  };
88
108
 
109
+ /** `/projects/$project/users`: who holds access, and what others read of it through references. */
110
+ export const projectUsers = {
111
+ loader: async ({ context, params }: Loader<{ project: string }>) => {
112
+ const { coffre, queryClient } = coffreOf(context);
113
+ if (!(await projectTab(context, params.project, 'grant.manage'))) return;
114
+ await Promise.all([
115
+ queryClient.fetchQuery(queries.grants(coffre, params.project)),
116
+ queryClient.fetchQuery(queries.references(coffre, params.project)),
117
+ ]);
118
+ },
119
+ };
120
+
121
+ /** `/projects/$project/service-accounts`. */
122
+ export const projectServiceAccounts = {
123
+ loader: async ({ context, params }: Loader<{ project: string }>) => {
124
+ const { coffre, queryClient } = coffreOf(context);
125
+ if (await projectTab(context, params.project, 'grant.manage')) await queryClient.fetchQuery(queries.grants(coffre, params.project));
126
+ },
127
+ };
128
+
129
+ /** `/projects/$project/settings`: the project itself, which its layout read. */
130
+ export const projectSettings = {
131
+ loader: async ({ context, params }: Loader<{ project: string }>) => {
132
+ await projectTab(context, params.project, 'project.manage');
133
+ },
134
+ };
135
+
136
+ /**
137
+ * Whether a project's tab reads anything: not for a project its visitor
138
+ * cannot see, whose layout shows a closed door instead; and a tab they may
139
+ * not open sends them to the first, so a link someone shared still lands
140
+ * somewhere useful.
141
+ */
142
+ async function projectTab(context: unknown, slug: string, permission: Permission): Promise<boolean> {
143
+ const { coffre, queryClient } = coffreOf(context);
144
+ const found = projectOf(await queryClient.fetchQuery(queries.projects(coffre)), slug);
145
+ if (!found.ok) return false;
146
+ if (!found.project.permissions.includes(permission)) throw redirect({ to: '/projects/$project', params: { project: slug } });
147
+ return true;
148
+ }
149
+
89
150
  /** `/projects/$project/$environment`. */
90
151
  export const environment = {
91
152
  // `?filter=KEY` opens the ledger narrowed to matching keys, for links to one secret.
92
153
  validateSearch: (search: Record<string, unknown>): { filter?: string } => ({
93
154
  filter: typeof search.filter === 'string' && search.filter !== '' ? search.filter : undefined,
94
155
  }),
95
- loader: ({ context, params }: Loader<{ project: string; environment: string }>) => {
156
+ loader: async ({ context, params }: Loader<{ project: string; environment: string }>) => {
96
157
  const { coffre, queryClient } = coffreOf(context);
97
- return queryClient.fetchQuery(queries.secrets(coffre, params));
158
+ const secrets = await queryClient.fetchQuery(queries.secrets(coffre, params));
159
+ // Then, for whoever reads it, the references that read its secrets from
160
+ // elsewhere and the keys it lacks, rendered with them. Asked only then,
161
+ // so a refused visit is one refusal in the log, not three.
162
+ if (secrets.ok) {
163
+ await Promise.all([
164
+ queryClient.fetchQuery(queries.references(coffre, `${params.project}/${params.environment}`)),
165
+ queryClient.fetchQuery(queries.missing(coffre, params)),
166
+ ]);
167
+ }
168
+ return secrets;
98
169
  },
99
170
  };
100
171
 
@@ -104,7 +175,7 @@ export const audit = {
104
175
  validateSearch: (search: Record<string, unknown>): AuditSearch => ({
105
176
  decision: search.decision === 'deny' ? 'deny' : undefined,
106
177
  actorId: typeof search.actorId === 'string' && search.actorId !== '' ? search.actorId : undefined,
107
- detail: search.detail === '1' || search.detail === 1 ? '1' : undefined,
178
+ detail: search.detail === '1' ? '1' : undefined,
108
179
  }),
109
180
  loaderDeps: ({ search }: { search: AuditSearch }) => search,
110
181
  // The entries only: the verification is asked for once the page is up
@@ -115,13 +186,6 @@ export const audit = {
115
186
  },
116
187
  };
117
188
 
118
- /** `/access`: the access page became the users page, and old links land there. */
119
- export const access = {
120
- beforeLoad: () => {
121
- throw redirect({ to: '/users' });
122
- },
123
- };
124
-
125
189
  /** `/users`. */
126
190
  export const users = {
127
191
  loader: ({ context }: Loader) => {
@@ -130,38 +194,91 @@ export const users = {
130
194
  },
131
195
  };
132
196
 
133
- /** `/users/$user`. */
197
+ /** `/users/$user`, the layout of a user's tabs: who they are to the instance, for owners. */
134
198
  export const user = {
135
199
  loader: ({ context, params }: Loader<{ user: string }>) => {
136
200
  const { coffre, queryClient } = coffreOf(context);
137
- return loadPrincipal(queryClient, coffre, 'user', params.user);
201
+ return loadMember(queryClient, coffre, memberRef('user', params.user));
138
202
  },
139
203
  };
140
204
 
141
- /** `/tokens`. */
142
- export const tokens = {
205
+ /** `/users/$user/`, their access on every project where you manage it. */
206
+ export const userAccess = {
143
207
  loader: ({ context }: Loader) => {
144
208
  const { coffre, queryClient } = coffreOf(context);
145
- return loadDirectory(queryClient, coffre);
209
+ return loadAccess(queryClient, coffre);
210
+ },
211
+ };
212
+
213
+ /** `/users/$user/activity`, for whoever reads the audit log; the others are sent to the first tab. */
214
+ export const userActivity = {
215
+ loader: async ({ context, params }: Loader<{ user: string }>) => {
216
+ const { coffre, queryClient } = coffreOf(context);
217
+ const shell = await loadShell(queryClient, coffre);
218
+ if (!shell.capabilities.canReadAudit) throw redirect({ to: '/users/$user', params });
219
+ },
220
+ };
221
+
222
+ /** `/service-accounts`. */
223
+ export const serviceAccounts = {
224
+ loader: ({ context }: Loader) => {
225
+ const { coffre, queryClient } = coffreOf(context);
226
+ return loadServiceDirectory(queryClient, coffre);
146
227
  },
147
228
  };
148
229
 
149
- /** `/tokens/$token`. */
150
- export const token = {
151
- loader: ({ context, params }: Loader<{ token: string }>) => {
230
+ /** `/service-accounts/$account`, the layout of a service account's tabs: who it is to the instance, for owners. */
231
+ export const serviceAccount = {
232
+ loader: ({ context, params }: Loader<{ account: string }>) => {
152
233
  const { coffre, queryClient } = coffreOf(context);
153
- return loadPrincipal(queryClient, coffre, 'service', params.token);
234
+ return loadMember(queryClient, coffre, memberRef('service', params.account));
235
+ },
236
+ };
237
+
238
+ /**
239
+ * `/service-accounts/$account/`, how it signs in: its trusted workloads and
240
+ * bearer tokens. Only an owner manages them, and only while it is active;
241
+ * anyone else is sent to its access.
242
+ */
243
+ export const serviceAccountSignIn = {
244
+ loader: async ({ context, params }: Loader<{ account: string }>) => {
245
+ const { coffre, queryClient } = coffreOf(context);
246
+ const member = memberRef('service', params.account);
247
+ const [shell, report] = await Promise.all([loadShell(queryClient, coffre), loadMember(queryClient, coffre, member)]);
248
+ const ways = signInWays(shell, report);
249
+ if (ways === null) throw redirect({ to: '/service-accounts/$account/access', params });
250
+ await Promise.all([
251
+ queryClient.fetchQuery(queries.credentials(coffre, member, ways.tokens)),
252
+ queryClient.fetchQuery(queries.bindings(coffre, member, ways.workloads)),
253
+ ]);
254
+ },
255
+ };
256
+
257
+ /** `/service-accounts/$account/access`. */
258
+ export const serviceAccountAccess = {
259
+ loader: ({ context }: Loader) => {
260
+ const { coffre, queryClient } = coffreOf(context);
261
+ return loadAccess(queryClient, coffre);
262
+ },
263
+ };
264
+
265
+ /** `/service-accounts/$account/activity`, as a user's. */
266
+ export const serviceAccountActivity = {
267
+ loader: async ({ context, params }: Loader<{ account: string }>) => {
268
+ const { coffre, queryClient } = coffreOf(context);
269
+ const shell = await loadShell(queryClient, coffre);
270
+ if (!shell.capabilities.canReadAudit) throw redirect({ to: '/service-accounts/$account', params });
154
271
  },
155
272
  };
156
273
 
157
274
  /** `/settings`. */
158
275
  export const settings = {
159
- // Instance facts come from the directory, which only owners may list.
160
- // Asking on everyone's behalf would write a refusal to the audit log for
161
- // every user who opens the page, so it is only asked for them.
276
+ // Instance facts come from the directory and the key checks, which only
277
+ // owners may read. Asking on everyone's behalf would write a refusal to the
278
+ // audit log for every user who opens the page, so they are only asked for them.
162
279
  loader: ({ context }: Loader) => {
163
280
  const { coffre, queryClient } = coffreOf(context);
164
- return loadDirectory(queryClient, coffre);
281
+ return loadSettings(queryClient, coffre);
165
282
  },
166
283
  };
167
284
 
@@ -191,15 +308,8 @@ export const account = {
191
308
 
192
309
  /** `/login`. */
193
310
  export const login = {
194
- // Where to resume after signing in. Same-origin paths only: an absolute URL
195
- // accepted here would make the sign-in page an open redirect.
196
- validateSearch: (search: Record<string, unknown>): { next?: string; error?: string } => {
197
- const out: { next?: string; error?: string } = {};
198
- const { next, error } = search;
199
- if (typeof next === 'string' && next.startsWith('/') && !next.startsWith('//')) out.next = next;
200
- if (typeof error === 'string' && /^[a-z_]{1,40}$/.test(error)) out.error = error;
201
- return out;
202
- },
311
+ // Where to resume after signing in, and the sign-in's error, shown once (`loginSearch`).
312
+ validateSearch: loginSearch,
203
313
  loader: async ({ context }: Loader) => {
204
314
  const { coffre, queryClient } = coffreOf(context);
205
315
  const shell = await loadShell(queryClient, coffre);
@@ -238,3 +348,38 @@ export const deviceLogin = {
238
348
  return uiResult(() => coffre.deviceLogins.get(code));
239
349
  },
240
350
  };
351
+
352
+ /**
353
+ * `/approvals/$approval`: a change an MCP client asked for, which its person
354
+ * decides here. Its own read: the page shows what the change would do now.
355
+ */
356
+ export const approval = {
357
+ loader: async ({ context, params, location }: Loader<{ approval: string }>) => {
358
+ const { coffre, queryClient } = coffreOf(context);
359
+ const shell = await loadShell(queryClient, coffre);
360
+ if (shell.registrationRequired) throw redirect({ to: '/unregistered' });
361
+ if (shell.principal === null) throw redirect({ to: '/login', search: { next: location.href } });
362
+ return uiResult(() => coffre.approvals.get(params.approval));
363
+ },
364
+ };
365
+
366
+ type AuthorizationSearch = RouteInput<'GET /oauth/authorizations'>;
367
+
368
+ /**
369
+ * `/oauth/authorize`: an MCP client asking to connect. Its parameters go to
370
+ * the API as sent, which says which it takes; the router keeps them strings,
371
+ * so a `state` of `1e5` goes back as `1e5`.
372
+ */
373
+ export const oauthAuthorize = {
374
+ validateSearch: (search: Record<string, unknown>): AuthorizationSearch => stringsOf(search),
375
+ loaderDeps: ({ search }: { search: AuthorizationSearch }) => ({ request: search }),
376
+ // Its own read, as the device login's: every authorization is checked afresh.
377
+ loader: async ({ context, deps, location }: Loader & { deps: { request: AuthorizationSearch } }) => {
378
+ const { coffre, queryClient } = coffreOf(context);
379
+ const shell = await loadShell(queryClient, coffre);
380
+ if (shell.registrationRequired) throw redirect({ to: '/unregistered' });
381
+ if (shell.principal === null) throw redirect({ to: '/login', search: { next: location.href } });
382
+ const { request } = deps;
383
+ return { request, email: shell.principal.id, result: await uiResult(() => coffre.oauth.describe(request)) };
384
+ },
385
+ };