@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 @@
1
+ {"version":3,"file":"grants-Cw1FyGID.js","names":[],"sources":["../../src/lib/access-plan.ts","../../src/components/expiry-field.tsx","../../src/components/every-project.tsx","../../src/components/grants.tsx"],"sourcesContent":["import type { AccessValue } from '@coffre/client';\nimport type { Role } from '@coffre/core/access';\n\nimport type { GrantRow } from '../shared/models';\n\n/** Read or write on one environment, and when it ends: an ISO instant, or null for never. */\nexport type EnvironmentAccess = { role: Extract<Role, 'viewer' | 'developer'>; expiresAt: string | null };\n\n/**\n * What one project is set to in a principal's access editor: nothing, owner,\n * read or write everywhere, or read or write per environment. Every grant the\n * plan asks for carries its own expiry.\n *\n * `custom` is for grants that do not fit that shape -- an auditor grant, or\n * read everywhere plus write on one environment. The editor shows them and\n * leaves them alone unless another setting is picked.\n */\nexport type AccessPlan = {\n level: 'none' | Extract<Role, 'owner' | 'viewer' | 'developer'> | 'env' | 'custom';\n /** When the project-wide level ends. */\n expiresAt: string | null;\n /** Environments without an entry get no access. */\n environments: Record<string, EnvironmentAccess>;\n};\n\nexport type HeldGrant = Pick<\n GrantRow,\n 'id' | 'role' | 'roleName' | 'environmentSlug' | 'expiresAt'\n>;\n\nexport type AccessChange =\n | { kind: 'create'; role: string; environmentSlug: string | null; expiresAt: string | null }\n | { kind: 'expiry'; grant: HeldGrant; expiresAt: string | null }\n | { kind: 'revoke'; grant: HeldGrant };\n\n/** An environment's access in a plan; slugs like `constructor` are not inherited. */\nexport function environmentAccess(plan: AccessPlan, slug: string): EnvironmentAccess | null {\n return Object.hasOwn(plan.environments, slug) ? plan.environments[slug] : null;\n}\n\n/**\n * Read what a principal holds on a project back into the editor's terms.\n * `environments` are the ones the editor can set: live, and not archived.\n */\nexport function planFromGrants(\n grants: readonly HeldGrant[],\n environments: readonly string[],\n): AccessPlan {\n if (grants.length === 0) return { level: 'none', expiresAt: null, environments: {} };\n\n const [only] = grants;\n if (\n grants.length === 1 &&\n only.environmentSlug === null &&\n (only.role === 'owner' || only.role === 'viewer' || only.role === 'developer')\n ) {\n return { level: only.role, expiresAt: only.expiresAt, environments: {} };\n }\n\n const perEnvironment: Record<string, EnvironmentAccess> = {};\n for (const grant of grants) {\n const slug = grant.environmentSlug;\n if (\n slug === null ||\n !environments.includes(slug) ||\n Object.hasOwn(perEnvironment, slug) ||\n (grant.role !== 'viewer' && grant.role !== 'developer')\n ) {\n return { level: 'custom', expiresAt: null, environments: {} };\n }\n perEnvironment[slug] = { role: grant.role, expiresAt: grant.expiresAt };\n }\n return { level: 'env', expiresAt: null, environments: perEnvironment };\n}\n\n/**\n * Switch a plan's level. Going from read or write everywhere to per\n * environment starts every environment at that level and expiry, so the\n * switch alone keeps the same reach.\n */\nexport function withLevel(\n plan: AccessPlan,\n level: AccessPlan['level'],\n environments: readonly string[],\n): AccessPlan {\n if (\n level === 'env' &&\n (plan.level === 'viewer' || plan.level === 'developer') &&\n Object.keys(plan.environments).length === 0\n ) {\n const access = { role: plan.level, expiresAt: plan.expiresAt };\n return {\n ...plan,\n level,\n environments: Object.fromEntries(environments.map((slug) => [slug, access])),\n };\n }\n return { ...plan, level };\n}\n\n/** Set one environment's access, or take it away with `null`. */\nexport function withEnvironment(\n plan: AccessPlan,\n slug: string,\n access: EnvironmentAccess | null,\n): AccessPlan {\n const environments = { ...plan.environments };\n if (access === null) delete environments[slug];\n else environments[slug] = access;\n return { ...plan, environments };\n}\n\nfunction grantsFor(\n plan: AccessPlan,\n): { role: string; environmentSlug: string | null; expiresAt: string | null }[] {\n switch (plan.level) {\n case 'none':\n case 'custom':\n return [];\n case 'owner':\n case 'viewer':\n case 'developer':\n return [{ role: plan.level, environmentSlug: null, expiresAt: plan.expiresAt }];\n case 'env':\n return Object.entries(plan.environments).map(([environmentSlug, access]) => ({\n environmentSlug,\n ...access,\n }));\n }\n}\n\n/** The server and the date field spell the same instant differently. */\nfunction sameExpiry(a: string | null, b: string | null): boolean {\n return a === b || (a !== null && b !== null && Date.parse(a) === Date.parse(b));\n}\n\n/**\n * The changes that take what is held to the plan: grants to create, grants\n * whose expiry moves, and grants to revoke, in that order. Asking for what is\n * already held yields nothing, so applying the same plan twice is a no-op.\n */\nexport function accessChanges(grants: readonly HeldGrant[], plan: AccessPlan): AccessChange[] {\n if (plan.level === 'custom') return [];\n\n const key = (grant: { role: string; environmentSlug: string | null }) =>\n `${grant.role}@${grant.environmentSlug ?? ''}`;\n const wanted = new Map(grantsFor(plan).map((grant) => [key(grant), grant]));\n const held = new Map(grants.map((grant) => [key(grant), grant]));\n\n const changes: AccessChange[] = [];\n for (const [id, grant] of wanted) {\n if (!held.has(id)) changes.push({ kind: 'create', ...grant });\n }\n for (const [id, grant] of held) {\n const want = wanted.get(id);\n if (want !== undefined && !sameExpiry(grant.expiresAt, want.expiresAt)) {\n changes.push({ kind: 'expiry', grant, expiresAt: want.expiresAt });\n }\n }\n for (const [id, grant] of held) {\n if (!wanted.has(id)) changes.push({ kind: 'revoke', grant });\n }\n return changes;\n}\n\n/**\n * The changes as the API's access patch for one project: each place it\n * touches, and the role to hold there until when, or `null` for none.\n *\n * { \"market\": null, \"market/dev\": { \"role\": \"developer\", \"until\": \"2026-12-31T23:59:59.000Z\" } }\n *\n * A place holds one role, so where a level changes, the revoke of the old\n * role and the create of the new land on the same place, and the new role\n * wins: the server replaces one with the other, never passing through none.\n */\nexport function accessPatch(project: string, changes: readonly AccessChange[]): Record<string, AccessValue> {\n const place = (environmentSlug: string | null) =>\n environmentSlug === null ? project : `${project}/${environmentSlug}`;\n const holding = (role: string, expiresAt: string | null): AccessValue =>\n expiresAt === null ? (role as Role) : { role: role as Role, until: expiresAt };\n\n const patch: Record<string, AccessValue> = {};\n for (const change of changes) {\n if (change.kind === 'revoke') patch[place(change.grant.environmentSlug)] = null;\n }\n for (const change of changes) {\n if (change.kind === 'expiry') patch[place(change.grant.environmentSlug)] = holding(change.grant.role, change.expiresAt);\n if (change.kind === 'create') patch[place(change.environmentSlug)] = holding(change.role, change.expiresAt);\n }\n return patch;\n}\n\n/** A date field's value as the instant access ends: the close of that day, UTC. */\nexport function expiryFromDate(date: string): string | null {\n return date === '' ? null : new Date(`${date}T23:59:59Z`).toISOString();\n}\n\n/** A date field's value for an expiry. Expiries are shown as UTC dates everywhere. */\nexport function dateFromExpiry(expiresAt: string | null): string {\n return expiresAt === null ? '' : expiresAt.slice(0, 10);\n}\n","import { dateFromExpiry, expiryFromDate } from '../lib/access-plan';\nimport { X } from './icons';\n\n/**\n * When one grant ends, as a date: access lasts through that day, UTC. Blank\n * reads \"Never\" where the browser lets the empty field be restyled.\n */\nexport function ExpiryField({\n label,\n expiresAt,\n onChange,\n}: {\n label: string;\n expiresAt: string | null;\n onChange: (expiresAt: string | null) => void;\n}) {\n const date = dateFromExpiry(expiresAt);\n return (\n <span className={`expiry${date === '' ? ' is-never' : ''}`}>\n <input\n className=\"input select-sm\"\n type=\"date\"\n aria-label={label}\n min={new Date().toISOString().slice(0, 10)}\n value={date}\n onChange={(event) => onChange(expiryFromDate(event.target.value))}\n />\n <span className=\"expiry-never\" aria-hidden=\"true\">\n Never\n </span>\n <button\n className=\"btn btn-quiet btn-sm btn-icon\"\n type=\"button\"\n aria-label={`${label}: never`}\n title=\"Never expires\"\n onClick={() => onChange(null)}\n >\n <X size={12} />\n </button>\n </span>\n );\n}\n","import { useState } from 'react';\nimport { useSuspenseQuery } from '@tanstack/react-query';\nimport { toast } from 'sonner';\nimport type { InheritedGrant } from '@coffre/client';\nimport { assignableToEnvironment, EVERY_PROJECT, ROLE_NAMES, ROLES, type Role } from '@coffre/core/access';\nimport { memberRef, useCoffre } from '../lib/coffre';\nimport { affects, queries } from '../lib/queries';\nimport { useAction } from '../lib/use-action';\nimport { useShell } from '../lib/use-shell';\nimport { slugProblem } from '../lib/validation';\nimport { ExpiryField } from './expiry-field';\nimport { GrantsTable } from './grants';\nimport { Layers, Plus } from './icons';\nimport { ConfirmButton, ErrorLine, Modal, Notice, Spinner } from './ui';\n\n/**\n * Grants on every project (`*`, the projects made later too) and on one\n * environment slug in every project (`*` and the slug): only owners give\n * and take them, here, from the CLI or the API; the pages show who holds\n * them to whoever sees the grants of a project they reach.\n */\n\n/** Where a grant on every project is, as people read it: \"All projects\", or \"dev in every project\". */\nexport function everyProjectPlace(environmentSlug: string | null): string {\n return environmentSlug === null ? 'All projects' : `${environmentSlug} in every project`;\n}\n\n/** The slug a grant on every project covers, from its path: null for `*`. */\nfunction slugOf(place: string): string | null {\n return place === '*' ? null : place.slice('*/'.length);\n}\n\n/** The grants on every project, for those shown them: who makes places, and who manages access. */\nexport function useEveryProject(): InheritedGrant[] {\n const { data } = useSuspenseQuery(queries.projects(useCoffre()));\n return data.ok ? data.everyProject : [];\n}\n\n/** Those grants that reach a place: a project (`environment` null), or an environment of that slug. */\nexport function reaching(grants: InheritedGrant[], environment: string | null): InheritedGrant[] {\n return grants.filter((grant) => grant.place === '*' || (environment !== null && slugOf(grant.place) === environment));\n}\n\n/** A member as a line names them: `ada@acme.example`, or a token's name. */\nfunction who(member: string): string {\n return member.slice(member.indexOf(':') + 1);\n}\n\n/**\n * Who reaches a place through grants on every project, said in its dialog\n * before it is made or renamed: making a place there gives them access at once.\n */\nexport function ReachedBy({ grants, lead }: { grants: InheritedGrant[]; lead: string }) {\n if (grants.length === 0) return null;\n return (\n <Notice tone=\"info\">\n {lead}{' '}\n {grants.map((grant, index) => (\n <span key={`${grant.member} ${grant.place}`}>\n {index > 0 && ', '}\n <strong className=\"mono\">{who(grant.member)}</strong> ({grant.roleName.toLowerCase()},{' '}\n {everyProjectPlace(slugOf(grant.place)).toLowerCase()})\n </span>\n ))}\n .\n </Notice>\n );\n}\n\n/**\n * One member's grants on every project, on their Access tab: \"All projects ·\n * Developer\". Owners grant and revoke them here; whoever else sees them, as\n * on a project they reach, sees them only.\n */\nexport function EveryProjectGrants({ principalType, principalId }: { principalType: 'user' | 'service'; principalId: string }) {\n const member = memberRef(principalType, principalId);\n const { capabilities } = useShell();\n const owner = capabilities.canManageGrants;\n const grants = useEveryProject().filter((grant) => grant.member === member);\n if (grants.length === 0 && !owner) return null;\n return (\n <section className=\"every-project\" aria-label=\"Access to every project\">\n <h2 className=\"section-title\">Every project</h2>\n {grants.length > 0 && (\n <section className=\"card\">\n <GrantsTable\n lead={\n <span className=\"th\">\n <Layers size={14} />\n Where\n </span>\n }\n >\n {grants.map((grant, index) => (\n <EveryProjectRow key={grant.place} number={index + 1} grant={grant} principalId={principalId} owner={owner} />\n ))}\n </GrantsTable>\n </section>\n )}\n {owner ? (\n <div className=\"table-actions\">\n <GrantEveryProject principalType={principalType} principalId={principalId} />\n </div>\n ) : (\n <p className=\"hint section-foot\">Only owners grant or revoke on every project.</p>\n )}\n </section>\n );\n}\n\nfunction EveryProjectRow({ number, grant, principalId, owner }: { number: number; grant: InheritedGrant; principalId: string; owner: boolean }) {\n const coffre = useCoffre();\n const { pending, error, run } = useAction();\n const where = everyProjectPlace(slugOf(grant.place));\n return (\n <>\n <tr>\n <td className=\"n\">{number}</td>\n <td className=\"col-lead\" data-label=\"Where\">\n {where}\n </td>\n <td className=\"col-access\" data-label=\"Permissions\">\n <span className={`tag${grant.role === 'owner' ? ' tag-violet' : ''}`}>{grant.roleName}</span>\n </td>\n <td className={`col-expires cell-mono cell-muted${grant.expiresAt === null ? ' is-never' : ''}`} data-label=\"Expires\">\n {grant.expiresAt === null ? 'Never' : grant.expiresAt.slice(0, 10)}\n </td>\n <td className=\"col-actions\">\n {owner && (\n <ConfirmButton\n trigger={\n <button className=\"act act-danger\" disabled={pending}>\n Revoke\n </button>\n }\n title={\n <>\n Revoke {grant.roleName.toLowerCase()} on {where.toLowerCase()} from <span className=\"mono\">{principalId}</span>?\n </>\n }\n body={\n <>\n They lose it at once, wherever it reaches, including any process using it right now.\n Grants they hold on projects themselves still apply.\n </>\n }\n confirmLabel=\"Revoke access\"\n onConfirm={() =>\n run(() => coffre.access.set(grant.member, { [grant.place]: null }), {\n affects: affects.everyProject(grant.member),\n onSuccess: () => toast.success(`Revoked ${grant.roleName.toLowerCase()} on ${where.toLowerCase()}`),\n })\n }\n />\n )}\n </td>\n </tr>\n {error !== null && (\n <tr>\n <td colSpan={5}>\n <ErrorLine error={error} />\n </td>\n </tr>\n )}\n </>\n );\n}\n\n/** The roles a grant on every project takes: all of them, or, on one environment name, those an environment can hold. */\nconst ROLE_CHOICES: { role: Role; name: string; environment: boolean }[] = ROLE_NAMES.map((role) => ({\n role,\n name: ROLES[role].name,\n environment: assignableToEnvironment(role),\n}));\n\n/**\n * Give a member a role on every project, the ones created later too, or on\n * one environment name in every project. Owners only, as the API.\n */\nfunction GrantEveryProject({ principalType, principalId }: { principalType: 'user' | 'service'; principalId: string }) {\n const coffre = useCoffre();\n const member = memberRef(principalType, principalId);\n const [open, setOpen] = useState(false);\n const [environment, setEnvironment] = useState('');\n const [role, setRole] = useState<Role>('viewer');\n const [expiresAt, setExpiresAt] = useState<string | null>(null);\n const { pending, error, setError, run } = useAction();\n const slug = environment.trim();\n const slugError = slug === '' ? null : slugProblem(slug);\n const roles = ROLE_CHOICES.filter((choice) => slug === '' || choice.environment);\n const chosen = roles.some((choice) => choice.role === role) ? role : 'viewer';\n const where = everyProjectPlace(slug === '' ? null : slug);\n\n function close() {\n setOpen(false);\n setEnvironment('');\n setRole('viewer');\n setExpiresAt(null);\n setError(null);\n }\n\n return (\n <>\n <button className=\"btn\" onClick={() => setOpen(true)}>\n <Plus size={14} />\n Grant on every project\n </button>\n\n <Modal\n open={open}\n onOpenChange={(next) => (next ? setOpen(true) : close())}\n title={\n <>\n Grant <span className=\"mono\">{principalId}</span> on every project\n </>\n }\n description=\"A role on every project, including ones created later. With an environment name, only the environment of that name in each project.\"\n >\n <form\n className=\"form\"\n onSubmit={(event) => {\n event.preventDefault();\n const place = slug === '' ? EVERY_PROJECT : `${EVERY_PROJECT}/${slug}`;\n run(() => coffre.access.set(member, { [place]: expiresAt === null ? chosen : { role: chosen, until: expiresAt } }), {\n affects: affects.everyProject(member),\n onSuccess: () => {\n toast.success(`Granted ${ROLES[chosen].name.toLowerCase()} on ${where.toLowerCase()}`);\n close();\n },\n });\n }}\n >\n <label className=\"field\">\n <span className=\"label\">Environment name</span>\n <input\n className=\"input input-mono\"\n spellCheck={false}\n autoComplete=\"off\"\n placeholder=\"Every environment\"\n value={environment}\n aria-invalid={slugError !== null}\n aria-describedby=\"every-project-environment-hint\"\n onChange={(event) => setEnvironment(event.target.value)}\n />\n <span className={`hint${slugError !== null ? ' edit-note-error' : ''}`} id=\"every-project-environment-hint\">\n {slugError ??\n (slug === ''\n ? 'Every environment of every project.'\n : `Only the environment named ${slug} in each project, including projects created later.`)}\n </span>\n </label>\n\n <div className=\"form-row\">\n <label className=\"field\" style={{ flexGrow: 2 }}>\n <span className=\"label\">Role</span>\n <select className=\"select\" value={chosen} onChange={(event) => setRole(event.target.value as Role)}>\n {roles.map((choice) => (\n <option key={choice.role} value={choice.role}>\n {choice.name}\n </option>\n ))}\n </select>\n </label>\n <label className=\"field\">\n <span className=\"label\">Expires</span>\n <ExpiryField label=\"Expires\" expiresAt={expiresAt} onChange={setExpiresAt} />\n </label>\n </div>\n\n <p className=\"hint\">\n {where} · {ROLES[chosen].name}: {ROLES[chosen].description}\n </p>\n <ErrorLine error={error} />\n\n <div className=\"dialog-actions\">\n <button className=\"btn\" type=\"button\" onClick={close}>\n Cancel\n </button>\n <button className=\"btn btn-primary\" type=\"submit\" disabled={pending || slugError !== null}>\n {pending ? <Spinner /> : 'Grant'}\n </button>\n </div>\n </form>\n </Modal>\n </>\n );\n}\n","import type { ReactNode } from 'react';\nimport { grantId, revokeGrant, type GrantVars } from '../lib/changes';\nimport type { FailedAdd } from '../lib/optimistic';\nimport { useCoffre } from '../lib/coffre';\nimport { projectAccessLabel } from '../lib/project-access';\nimport { everyProjectPlace } from './every-project';\nimport { keys } from '../lib/queries';\nimport { useChange, useChangeStatus } from '../lib/use-change';\nimport type { GrantRow } from '../shared/models';\nimport { RowFailure, RowPending, rowClass } from './row-state';\nimport { ConfirmButton } from './ui';\nimport { Clock, ShieldCheck } from './icons';\n\n/**\n * Grants as a table: who or where in the first column, then the access, when\n * it lapses, and a revoke.\n *\n * A project's page leads each row with the principal; a user's page leads with\n * the project. Everything after the first column is the same grant either way.\n */\nexport function GrantsTable({ lead, children }: { lead: ReactNode; children: ReactNode }) {\n return (\n <div className=\"dt-wrap\">\n <table className=\"dt grants stacks\">\n <thead>\n <tr>\n <th className=\"n\">#</th>\n <th className=\"col-principal\">{lead}</th>\n <th>\n <span className=\"th\">\n <ShieldCheck size={14} />\n Permissions\n </span>\n </th>\n <th className=\"col-expires\">\n <span className=\"th\">\n <Clock size={14} />\n Expires\n </span>\n </th>\n <th className=\"col-actions\">\n <span className=\"visually-hidden\">Actions</span>\n </th>\n </tr>\n </thead>\n <tbody>{children}</tbody>\n </table>\n </div>\n );\n}\n\nexport function GrantRowView({\n number,\n project,\n grant,\n lead,\n leadLabel,\n}: {\n number: number;\n project: string;\n grant: GrantRow;\n lead: ReactNode;\n leadLabel: string;\n}) {\n const revoke = useChange(revokeGrant(useCoffre(), project));\n const { status, dismiss } = useChangeStatus(keys.grants(project));\n const state = status(grantId(grant));\n // A grant on every project is shown where it reaches, and changed only by owners, with the CLI.\n const everywhere = grant.scope === 'every-project';\n const label = everywhere ? `${everyProjectPlace(grant.environmentSlug)} · ${grant.roleName}` : projectAccessLabel(grant);\n const expired = grant.expiresAt !== null && new Date(grant.expiresAt).getTime() < Date.now();\n\n return (\n <>\n <tr className={rowClass(state)}>\n <td className=\"n\">{number}</td>\n <td className=\"col-lead\" data-label={leadLabel}>\n {lead}\n </td>\n <td className=\"col-access\" data-label=\"Permissions\">\n <span className={`tag${grant.role === 'owner' ? ' tag-violet' : ''}`}>{label}</span>\n </td>\n <td\n className={`col-expires cell-mono cell-muted${grant.expiresAt === null ? ' is-never' : ''}`}\n data-label=\"Expires\"\n >\n {grant.expiresAt === null ? (\n 'Never'\n ) : (\n <>\n <span className=\"narrow-only\">Expires </span>\n {grant.expiresAt.slice(0, 10)}\n {expired && (\n <>\n {' '}\n <span className=\"tag tag-red\">Expired</span>\n </>\n )}\n </>\n )}\n </td>\n <td className=\"col-actions\">\n {state.state === 'pending' ? (\n <RowPending status={state} />\n ) : everywhere ? (\n <span className=\"cell-muted every-project-note\" title=\"Owners change grants on every project with coffre grant '*' and coffre revoke '*'\">\n every project\n </span>\n ) : (\n <ConfirmButton\n trigger={<button className=\"act act-danger\">Revoke</button>}\n title={\n <>\n Revoke {label} from <span className=\"mono\">{grant.principalId}</span>?\n </>\n }\n body={\n <>\n They lose <strong>{label}</strong> on <span className=\"mono\">{project}</span>{' '}\n immediately, including any process using it right now. Other grants they hold\n still apply.\n </>\n }\n confirmLabel=\"Revoke access\"\n onConfirm={() => revoke(grant)}\n />\n )}\n </td>\n </tr>\n <RowFailure\n status={state}\n columns={5}\n onDismiss={() => state.state === 'failed' && dismiss(state.mutationId)}\n />\n </>\n );\n}\n\n/**\n * Grants the server refused to give: rolled back, so no row of theirs is\n * left, and listed here, after the table's rows, saying why.\n */\nexport function RefusedGrants({ refused }: { refused: RefusedGrant[] }) {\n return refused.map(({ mutationId, vars, status, dismiss }) => (\n <RowFailure key={mutationId} status={status} columns={5} onDismiss={dismiss}>\n {vars.principalId} was not given {vars.roleName.toLowerCase()}.\n </RowFailure>\n ));\n}\n\ntype RefusedGrant = FailedAdd<GrantVars> & { dismiss: () => void };\n\n/** The grants of one kind the server refused to give in a project, still to be said. */\nexport function useRefusedGrants(project: string, grants: GrantRow[], principalType?: GrantRow['principalType']): RefusedGrant[] {\n const { failedAdds, dismiss } = useChangeStatus(keys.grants(project));\n return failedAdds<GrantVars>(grants.map(grantId))\n .filter(({ vars }) => principalType === undefined || vars.principalType === principalType)\n .map((refused) => ({ ...refused, dismiss: () => dismiss(refused.mutationId) }));\n}\n"],"mappings":";;;;;;;;;;;;;;AAoCA,SAAgB,kBAAkB,MAAkB,MAAwC;CAC1F,OAAO,OAAO,OAAO,KAAK,cAAc,IAAI,IAAI,KAAK,aAAa,QAAQ;AAC5E;;;;;AAMA,SAAgB,eACd,QACA,cACY;CACZ,IAAI,OAAO,WAAW,GAAG,OAAO;EAAE,OAAO;EAAQ,WAAW;EAAM,cAAc,CAAC;CAAE;CAEnF,MAAM,CAAC,QAAQ;CACf,IACE,OAAO,WAAW,KAClB,KAAK,oBAAoB,SACxB,KAAK,SAAS,WAAW,KAAK,SAAS,YAAY,KAAK,SAAS,cAElE,OAAO;EAAE,OAAO,KAAK;EAAM,WAAW,KAAK;E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;EACT,iBAAiB,MAAM,UAAU,YAAY,QAAQ,MAAM,UAAU;CACtE,CAAA,CACD,EAAA,CAAA;AAEN;;;;;AAMA,SAAgB,cAAc,EAAE,WAAwC;CACtE,OAAO,QAAQ,KAAK,EAAE,YAAY,MAAM,QAAQ,cAC9C,qBAAC,YAAD;EAAqC;EAAQ,SAAS;EAAG,WAAW;YAApE;GACG,KAAK;GAAY;GAAgB,KAAK,SAAS,YAAY;GAAE;EACpD;IAFK,UAEL,CACb;AACH;;AAKA,SAAgB,iBAAiB,SAAiB,QAAoB,eAA2D;CAC/H,MAAM,EAAE,YAAY,YAAY,gBAAgB,KAAK,OAAO,OAAO,CAAC;CACpE,OAAO,WAAsB,OAAO,IAAI,OAAO,CAAC,CAAC,CAC9C,QAAQ,EAAE,WAAW,kBAAkB,KAAA,KAAa,KAAK,kBAAkB,aAAa,CAAC,CACzF,KAAK,aAAa;EAAE,GAAG;EAAS,eAAe,QAAQ,QAAQ,UAAU;CAAE,EAAE;AAClF"}
@@ -0,0 +1,305 @@
1
+ import { c as Notice, i as EmptyState, u as Timestamp } from "./ui-DJje3gST.js";
2
+ import { A as Key, t as Card, tt as User, y as ChevronRight } from "./page-DvsgZ2Hd.js";
3
+ import { n as PrincipalLink } from "./principal-BIN-xwZw.js";
4
+ import { s as referenceProblem } from "./references-B6pLT1uQ.js";
5
+ import { Link } from "@tanstack/react-router";
6
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
+ import { serviceName } from "@coffre/client";
8
+ //#region src/components/offboarding.tsx
9
+ /**
10
+ * The part of a user's or token's page that answers "what do we change now
11
+ * they have left?". Owners only. Once someone is removed everything that let
12
+ * them in is gone, but what they saw is not, nor tokens they issued.
13
+ */
14
+ function PrincipalReportCards({ report }) {
15
+ const person = report.principalType === "user";
16
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
17
+ report.status === "removed" && /* @__PURE__ */ jsx(ConsiderRotating, {
18
+ report,
19
+ person
20
+ }),
21
+ report.issuedTokens.length > 0 && /* @__PURE__ */ jsx(IssuedTokens, { report }),
22
+ report.references.length > 0 && /* @__PURE__ */ jsx(MadeReferences, { report })
23
+ ] });
24
+ }
25
+ function RemovedNotice({ report }) {
26
+ const person = report.principalType === "user";
27
+ return /* @__PURE__ */ jsx("div", {
28
+ className: "report-notice",
29
+ children: /* @__PURE__ */ jsxs(Notice, { children: [
30
+ "Removed",
31
+ report.removedBy !== null && /* @__PURE__ */ jsxs(Fragment, { children: [
32
+ " ",
33
+ "by ",
34
+ /* @__PURE__ */ jsx("span", {
35
+ className: "mono",
36
+ children: report.removedBy
37
+ })
38
+ ] }),
39
+ report.removedAt !== null && /* @__PURE__ */ jsxs(Fragment, { children: [
40
+ " ",
41
+ "on ",
42
+ /* @__PURE__ */ jsx(Timestamp, { iso: report.removedAt })
43
+ ] }),
44
+ ".",
45
+ " ",
46
+ person ? "Their project access, sessions, CLI logins and linked sign-in accounts were revoked at the same time, so adding them again starts from nothing." : "Its project access and every token issued to it were revoked at the same time, so adding it again starts from nothing."
47
+ ] })
48
+ });
49
+ }
50
+ /**
51
+ * The people or service accounts removed from the directory, under the live ones.
52
+ * Removal ends their access but not the work it leaves, so they stay one click
53
+ * away until every value they saw has been rotated.
54
+ */
55
+ function RemovedList({ principalType, removed }) {
56
+ const users = principalType === "user";
57
+ const rows = removed.filter((principal) => principal.principalType === principalType);
58
+ if (rows.length === 0) return null;
59
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("h2", {
60
+ className: "section-title",
61
+ children: "Removed"
62
+ }), /* @__PURE__ */ jsx("section", {
63
+ className: "card",
64
+ "aria-label": users ? "Removed users" : "Removed service accounts",
65
+ children: /* @__PURE__ */ jsx("div", {
66
+ className: "dt-wrap",
67
+ children: /* @__PURE__ */ jsxs("table", {
68
+ className: "dt directory stacks",
69
+ children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
70
+ /* @__PURE__ */ jsx("th", {
71
+ className: "n",
72
+ children: "#"
73
+ }),
74
+ /* @__PURE__ */ jsx("th", {
75
+ className: "col-principal",
76
+ children: /* @__PURE__ */ jsxs("span", {
77
+ className: "th",
78
+ children: [users ? /* @__PURE__ */ jsx(User, { size: 14 }) : /* @__PURE__ */ jsx(Key, { size: 14 }), users ? "Email" : "Name"]
79
+ })
80
+ }),
81
+ /* @__PURE__ */ jsx("th", {
82
+ className: "col-role",
83
+ children: "Consider rotating"
84
+ }),
85
+ /* @__PURE__ */ jsx("th", {
86
+ className: "col-actions",
87
+ children: /* @__PURE__ */ jsx("span", {
88
+ className: "visually-hidden",
89
+ children: "Report"
90
+ })
91
+ })
92
+ ] }) }), /* @__PURE__ */ jsx("tbody", { children: rows.map((principal, index) => /* @__PURE__ */ jsxs("tr", {
93
+ className: "row-link",
94
+ children: [
95
+ /* @__PURE__ */ jsx("td", {
96
+ className: "n",
97
+ children: index + 1
98
+ }),
99
+ /* @__PURE__ */ jsx("td", {
100
+ className: "col-lead",
101
+ "data-label": users ? "Email" : "Name",
102
+ children: /* @__PURE__ */ jsx(PrincipalLink, {
103
+ type: principal.principalType,
104
+ id: principal.principalId,
105
+ stretch: true
106
+ })
107
+ }),
108
+ /* @__PURE__ */ jsx("td", {
109
+ className: "col-role",
110
+ "data-label": "Consider rotating",
111
+ children: principal.toRotate === 0 ? /* @__PURE__ */ jsx("span", {
112
+ className: "cell-muted",
113
+ children: "Nothing"
114
+ }) : `${principal.toRotate} ${principal.toRotate === 1 ? "value" : "values"}`
115
+ }),
116
+ /* @__PURE__ */ jsx("td", {
117
+ className: "col-actions col-open cell-muted",
118
+ "aria-hidden": "true",
119
+ children: /* @__PURE__ */ jsx(ChevronRight, { size: 16 })
120
+ })
121
+ ]
122
+ }, principal.principalId)) })]
123
+ })
124
+ })
125
+ })] });
126
+ }
127
+ /** Values a removed member saw that nobody has changed since. */
128
+ function ConsiderRotating({ report, person }) {
129
+ const they = person ? "they" : "it";
130
+ return /* @__PURE__ */ jsx(Card, {
131
+ labelledBy: "seen-values",
132
+ title: "Consider rotating",
133
+ description: `Values ${they} read or wrote that nobody has changed since, so ${they} may still hold them. Rotate each where it comes from, such as a new API key or database password, then save the new value here and it leaves this list.`,
134
+ actions: report.rotated > 0 && /* @__PURE__ */ jsxs("span", {
135
+ className: "card-aside",
136
+ children: [report.rotated, " already rotated"]
137
+ }),
138
+ children: report.exposed.length === 0 ? /* @__PURE__ */ jsx(EmptyState, {
139
+ title: "Nothing left to rotate",
140
+ children: report.rotated > 0 ? `Every value ${they} saw has had a new version since.` : `${person ? "They have" : "It has"} not read or written a value that is still current.`
141
+ }) : /* @__PURE__ */ jsx("div", {
142
+ className: "dt-wrap",
143
+ children: /* @__PURE__ */ jsxs("table", {
144
+ className: "dt report-values",
145
+ children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
146
+ /* @__PURE__ */ jsx("th", { children: "Secret" }),
147
+ /* @__PURE__ */ jsx("th", {
148
+ className: "col-shrink",
149
+ children: "Version"
150
+ }),
151
+ /* @__PURE__ */ jsx("th", {
152
+ className: "col-shrink",
153
+ children: "Last seen"
154
+ })
155
+ ] }) }), /* @__PURE__ */ jsx("tbody", { children: report.exposed.map((secret) => /* @__PURE__ */ jsxs("tr", { children: [
156
+ /* @__PURE__ */ jsx("td", { children: /* @__PURE__ */ jsxs(Link, {
157
+ className: "cell-link mono",
158
+ to: "/projects/$project/$environment",
159
+ params: {
160
+ project: secret.project,
161
+ environment: secret.environment
162
+ },
163
+ search: { filter: secret.key },
164
+ children: [/* @__PURE__ */ jsxs("span", {
165
+ className: "report-path",
166
+ children: [
167
+ secret.project,
168
+ "/",
169
+ secret.environment,
170
+ "/"
171
+ ]
172
+ }), secret.key]
173
+ }) }),
174
+ /* @__PURE__ */ jsxs("td", {
175
+ className: "col-shrink cell-mono cell-muted",
176
+ children: ["v", secret.version]
177
+ }),
178
+ /* @__PURE__ */ jsxs("td", {
179
+ className: "col-shrink nowrap",
180
+ children: [
181
+ secret.how === "wrote" ? "Wrote" : "Read",
182
+ " ",
183
+ /* @__PURE__ */ jsx(Timestamp, {
184
+ iso: secret.at,
185
+ display: "relative"
186
+ })
187
+ ]
188
+ })
189
+ ] }, `${secret.project}/${secret.environment}/${secret.key}`)) })]
190
+ })
191
+ })
192
+ });
193
+ }
194
+ /**
195
+ * References they made, as the log names them: each belongs to the
196
+ * environment that holds it, like a value, not to them (D46), so their
197
+ * leaving ends none. Listed to review.
198
+ */
199
+ function MadeReferences({ report }) {
200
+ return /* @__PURE__ */ jsx(Card, {
201
+ labelledBy: "made-references",
202
+ title: "References they made",
203
+ description: "Each belongs to the environment that holds it, like a value, and stays when they leave: whoever reads that environment reads another secret through it. Review them; the source's access managers, or whoever writes where one is held, can break it.",
204
+ children: /* @__PURE__ */ jsx("div", {
205
+ className: "dt-wrap",
206
+ children: /* @__PURE__ */ jsxs("table", {
207
+ className: "dt stacks",
208
+ children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
209
+ /* @__PURE__ */ jsx("th", { children: "Reference" }),
210
+ /* @__PURE__ */ jsx("th", { children: "Reads" }),
211
+ /* @__PURE__ */ jsx("th", {
212
+ className: "col-shrink",
213
+ children: "Made"
214
+ })
215
+ ] }) }), /* @__PURE__ */ jsx("tbody", { children: report.references.map((reference) => /* @__PURE__ */ jsxs("tr", { children: [
216
+ /* @__PURE__ */ jsx("td", {
217
+ className: "mono",
218
+ "data-label": "Reference",
219
+ children: reference.holder
220
+ }),
221
+ /* @__PURE__ */ jsxs("td", {
222
+ "data-label": "Reads",
223
+ children: [/* @__PURE__ */ jsx("span", {
224
+ className: "mono",
225
+ children: reference.source
226
+ }), reference.state !== "live" && /* @__PURE__ */ jsxs("span", {
227
+ className: "cell-muted",
228
+ children: [" · ", referenceProblem(reference.state)]
229
+ })]
230
+ }),
231
+ /* @__PURE__ */ jsx("td", {
232
+ className: "col-shrink nowrap",
233
+ "data-label": "Made",
234
+ children: /* @__PURE__ */ jsx(Timestamp, {
235
+ iso: reference.createdAt,
236
+ display: "relative"
237
+ })
238
+ })
239
+ ] }, reference.id)) })]
240
+ })
241
+ })
242
+ });
243
+ }
244
+ function IssuedTokens({ report }) {
245
+ return /* @__PURE__ */ jsx(Card, {
246
+ labelledBy: "issued-tokens",
247
+ title: "Bearer tokens they issued",
248
+ description: "Bearer tokens they issued to service accounts that still work. Each was shown to them once, when it was made; revoke any they may have kept a copy of.",
249
+ children: /* @__PURE__ */ jsx("div", {
250
+ className: "dt-wrap",
251
+ children: /* @__PURE__ */ jsxs("table", {
252
+ className: "dt report-tokens",
253
+ children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
254
+ /* @__PURE__ */ jsx("th", { children: "Token" }),
255
+ /* @__PURE__ */ jsx("th", {
256
+ className: "col-shrink",
257
+ children: "Expires"
258
+ }),
259
+ /* @__PURE__ */ jsx("th", {
260
+ className: "col-shrink col-hide-narrow",
261
+ children: "Last used"
262
+ })
263
+ ] }) }), /* @__PURE__ */ jsx("tbody", { children: report.issuedTokens.map((token) => /* @__PURE__ */ jsxs("tr", { children: [
264
+ /* @__PURE__ */ jsx("td", { children: /* @__PURE__ */ jsxs("span", {
265
+ className: "cell-stack",
266
+ children: [/* @__PURE__ */ jsxs(Link, {
267
+ className: "cell-link mono",
268
+ to: "/service-accounts/$account",
269
+ params: { account: serviceName(token.service) },
270
+ children: ["service:", serviceName(token.service)]
271
+ }), /* @__PURE__ */ jsxs("small", { children: [
272
+ token.label ?? "No label",
273
+ " · ",
274
+ /* @__PURE__ */ jsx("span", {
275
+ className: "mono",
276
+ children: token.hint
277
+ })
278
+ ] })]
279
+ }) }),
280
+ /* @__PURE__ */ jsx("td", {
281
+ className: "col-shrink nowrap",
282
+ children: /* @__PURE__ */ jsx(Timestamp, {
283
+ iso: token.expiresAt,
284
+ display: "relative"
285
+ })
286
+ }),
287
+ /* @__PURE__ */ jsx("td", {
288
+ className: "col-shrink col-hide-narrow nowrap",
289
+ children: token.lastUsedAt === null ? /* @__PURE__ */ jsx("span", {
290
+ className: "cell-muted",
291
+ children: "Never"
292
+ }) : /* @__PURE__ */ jsx(Timestamp, {
293
+ iso: token.lastUsedAt,
294
+ display: "relative"
295
+ })
296
+ })
297
+ ] }, token.id)) })]
298
+ })
299
+ })
300
+ });
301
+ }
302
+ //#endregion
303
+ export { RemovedList as n, RemovedNotice as r, PrincipalReportCards as t };
304
+
305
+ //# sourceMappingURL=offboarding-CE6d7um1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"offboarding-CE6d7um1.js","names":[],"sources":["../../src/components/offboarding.tsx"],"sourcesContent":["import { Link } from '@tanstack/react-router';\nimport type { PrincipalReport, RemovedPrincipal } from '../shared/models';\nimport { Card } from './page';\nimport { EmptyState, Notice, Timestamp } from './ui';\nimport { PrincipalLink } from './principal';\nimport { referenceProblem } from './references';\nimport { ChevronRight, Key, User } from './icons';\nimport { serviceName } from '@coffre/client';\n\n/**\n * The part of a user's or token's page that answers \"what do we change now\n * they have left?\". Owners only. Once someone is removed everything that let\n * them in is gone, but what they saw is not, nor tokens they issued.\n */\nexport function PrincipalReportCards({ report }: { report: PrincipalReport }) {\n const person = report.principalType === 'user';\n return (\n <>\n {report.status === 'removed' && <ConsiderRotating report={report} person={person} />}\n {report.issuedTokens.length > 0 && <IssuedTokens report={report} />}\n {report.references.length > 0 && <MadeReferences report={report} />}\n </>\n );\n}\n\nexport function RemovedNotice({ report }: { report: PrincipalReport }) {\n const person = report.principalType === 'user';\n return (\n <div className=\"report-notice\">\n <Notice>\n Removed\n {report.removedBy !== null && (\n <>\n {' '}by <span className=\"mono\">{report.removedBy}</span>\n </>\n )}\n {report.removedAt !== null && (\n <>\n {' '}on <Timestamp iso={report.removedAt} />\n </>\n )}\n .{' '}\n {person\n ? 'Their project access, sessions, CLI logins and linked sign-in accounts were revoked at the same time, so adding them again starts from nothing.'\n : 'Its project access and every token issued to it were revoked at the same time, so adding it again starts from nothing.'}\n </Notice>\n </div>\n );\n}\n\n/**\n * The people or service accounts removed from the directory, under the live ones.\n * Removal ends their access but not the work it leaves, so they stay one click\n * away until every value they saw has been rotated.\n */\nexport function RemovedList({\n principalType,\n removed,\n}: {\n principalType: RemovedPrincipal['principalType'];\n removed: RemovedPrincipal[];\n}) {\n const users = principalType === 'user';\n const rows = removed.filter((principal) => principal.principalType === principalType);\n if (rows.length === 0) return null;\n return (\n <>\n <h2 className=\"section-title\">Removed</h2>\n <section className=\"card\" aria-label={users ? 'Removed users' : 'Removed service accounts'}>\n <div className=\"dt-wrap\">\n <table className=\"dt directory stacks\">\n <thead>\n <tr>\n <th className=\"n\">#</th>\n <th className=\"col-principal\">\n <span className=\"th\">\n {users ? <User size={14} /> : <Key size={14} />}\n {users ? 'Email' : 'Name'}\n </span>\n </th>\n <th className=\"col-role\">Consider rotating</th>\n <th className=\"col-actions\">\n <span className=\"visually-hidden\">Report</span>\n </th>\n </tr>\n </thead>\n <tbody>\n {rows.map((principal, index) => (\n <tr key={principal.principalId} className=\"row-link\">\n <td className=\"n\">{index + 1}</td>\n <td className=\"col-lead\" data-label={users ? 'Email' : 'Name'}>\n <PrincipalLink type={principal.principalType} id={principal.principalId} stretch />\n </td>\n <td className=\"col-role\" data-label=\"Consider rotating\">\n {principal.toRotate === 0 ? (\n <span className=\"cell-muted\">Nothing</span>\n ) : (\n `${principal.toRotate} ${principal.toRotate === 1 ? 'value' : 'values'}`\n )}\n </td>\n {/* The row opens the report; the chevron says it does. */}\n <td className=\"col-actions col-open cell-muted\" aria-hidden=\"true\">\n <ChevronRight size={16} />\n </td>\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n </section>\n </>\n );\n}\n\n/** Values a removed member saw that nobody has changed since. */\nfunction ConsiderRotating({ report, person }: { report: PrincipalReport; person: boolean }) {\n const they = person ? 'they' : 'it';\n return (\n <Card\n labelledBy=\"seen-values\"\n title=\"Consider rotating\"\n description={`Values ${they} read or wrote that nobody has changed since, so ${they} may still hold them. Rotate each where it comes from, such as a new API key or database password, then save the new value here and it leaves this list.`}\n actions={\n report.rotated > 0 && (\n <span className=\"card-aside\">{report.rotated} already rotated</span>\n )\n }\n >\n {report.exposed.length === 0 ? (\n <EmptyState title=\"Nothing left to rotate\">\n {report.rotated > 0\n ? `Every value ${they} saw has had a new version since.`\n : `${person ? 'They have' : 'It has'} not read or written a value that is still current.`}\n </EmptyState>\n ) : (\n <div className=\"dt-wrap\">\n <table className=\"dt report-values\">\n <thead>\n <tr>\n <th>Secret</th>\n <th className=\"col-shrink\">Version</th>\n <th className=\"col-shrink\">Last seen</th>\n </tr>\n </thead>\n <tbody>\n {report.exposed.map((secret) => (\n <tr key={`${secret.project}/${secret.environment}/${secret.key}`}>\n <td>\n <Link\n className=\"cell-link mono\"\n to=\"/projects/$project/$environment\"\n params={{ project: secret.project, environment: secret.environment }}\n search={{ filter: secret.key }}\n >\n <span className=\"report-path\">\n {secret.project}/{secret.environment}/\n </span>\n {secret.key}\n </Link>\n </td>\n <td className=\"col-shrink cell-mono cell-muted\">v{secret.version}</td>\n <td className=\"col-shrink nowrap\">\n {secret.how === 'wrote' ? 'Wrote' : 'Read'}{' '}\n <Timestamp iso={secret.at} display=\"relative\" />\n </td>\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n )}\n </Card>\n );\n}\n\n/**\n * References they made, as the log names them: each belongs to the\n * environment that holds it, like a value, not to them (D46), so their\n * leaving ends none. Listed to review.\n */\nfunction MadeReferences({ report }: { report: PrincipalReport }) {\n return (\n <Card\n labelledBy=\"made-references\"\n title=\"References they made\"\n description=\"Each belongs to the environment that holds it, like a value, and stays when they leave: whoever reads that environment reads another secret through it. Review them; the source's access managers, or whoever writes where one is held, can break it.\"\n >\n <div className=\"dt-wrap\">\n <table className=\"dt stacks\">\n <thead>\n <tr>\n <th>Reference</th>\n <th>Reads</th>\n <th className=\"col-shrink\">Made</th>\n </tr>\n </thead>\n <tbody>\n {report.references.map((reference) => (\n <tr key={reference.id}>\n <td className=\"mono\" data-label=\"Reference\">{reference.holder}</td>\n <td data-label=\"Reads\">\n <span className=\"mono\">{reference.source}</span>\n {reference.state !== 'live' && <span className=\"cell-muted\"> · {referenceProblem(reference.state)}</span>}\n </td>\n <td className=\"col-shrink nowrap\" data-label=\"Made\">\n <Timestamp iso={reference.createdAt} display=\"relative\" />\n </td>\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n </Card>\n );\n}\n\nfunction IssuedTokens({ report }: { report: PrincipalReport }) {\n return (\n <Card\n labelledBy=\"issued-tokens\"\n title=\"Bearer tokens they issued\"\n description=\"Bearer tokens they issued to service accounts that still work. Each was shown to them once, when it was made; revoke any they may have kept a copy of.\"\n >\n <div className=\"dt-wrap\">\n <table className=\"dt report-tokens\">\n <thead>\n <tr>\n <th>Token</th>\n <th className=\"col-shrink\">Expires</th>\n <th className=\"col-shrink col-hide-narrow\">Last used</th>\n </tr>\n </thead>\n <tbody>\n {report.issuedTokens.map((token) => (\n <tr key={token.id}>\n <td>\n <span className=\"cell-stack\">\n <Link className=\"cell-link mono\" to=\"/service-accounts/$account\" params={{ account: serviceName(token.service) }}>\n service:{serviceName(token.service)}\n </Link>\n <small>\n {token.label ?? 'No label'} · <span className=\"mono\">{token.hint}</span>\n </small>\n </span>\n </td>\n <td className=\"col-shrink nowrap\">\n <Timestamp iso={token.expiresAt} display=\"relative\" />\n </td>\n <td className=\"col-shrink col-hide-narrow nowrap\">\n {token.lastUsedAt === null ? (\n <span className=\"cell-muted\">Never</span>\n ) : (\n <Timestamp iso={token.lastUsedAt} display=\"relative\" />\n )}\n </td>\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n </Card>\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAgB,qBAAqB,EAAE,UAAuC;CAC5E,MAAM,SAAS,OAAO,kBAAkB;CACxC,OACE,qBAAA,UAAA,EAAA,UAAA;EACG,OAAO,WAAW,aAAa,oBAAC,kBAAD;GAA0B;GAAgB;EAAS,CAAA;EAClF,OAAO,aAAa,SAAS,KA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MAAM,WAAU;gBAAhB,CACE,qBAAC,MAAD;OAAM,WAAU;OAAiB,IAAG;OAA6B,QAAQ,EAAE,SAAS,YAAY,MAAM,OAAO,EAAE;iBAA/G,CAAkH,YACvG,YAAY,MAAM,OAAO,CAC9B;UACN,qBAAC,SAAD,EAAA,UAAA;OACG,MAAM,SAAS;OAAW;OAAG,oBAAC,QAAD;QAAM,WAAU;kBAAQ,MAAM;OAAW,CAAA;MAClE,EAAA,CAAA,CACH;QACJ,CAAA;KACJ,oBAAC,MAAD;MAAI,WAAU;gBACZ,oBAAC,WAAD;OAAW,KAAK,MAAM;OAAW,SAAQ;MAAY,CAAA;KACnD,CAAA;KACJ,oBAAC,MAAD;MAAI,WAAU;gBACX,MAAM,eAAe,OACpB,oBAAC,QAAD;OAAM,WAAU;iBAAa;MAAW,CAAA,IAExC,oBAAC,WAAD;OAAW,KAAK,MAAM;OAAY,SAAQ;MAAY,CAAA;KAEtD,CAAA;IACF,EAAA,GArBK,MAAM,EAqBX,CACL,EACI,CAAA,CACF;;EACJ,CAAA;CACD,CAAA;AAEV"}
@@ -0,0 +1,35 @@
1
+ import { useEffect, useState } from "react";
2
+ import { useNavigate } from "@tanstack/react-router";
3
+ //#region src/lib/one-time.ts
4
+ /**
5
+ * A notice that rides in the URL once, as a sign-in's `?error=` does: read
6
+ * as the page first renders, on the server, so it shows without JavaScript;
7
+ * then taken out of the address, the history entry replaced, so that a
8
+ * reload is a clean retry and a copied link carries no stale error. What was
9
+ * read stays shown until the page is left.
10
+ *
11
+ * Why the URL and not a one-time cookie: the URL is the one thing the server
12
+ * renders from, so nothing has to be set on the redirect, read by the
13
+ * render and cleared by exactly the right response, which streaming and the
14
+ * requests a page fires beside it make fragile. The cost: without
15
+ * JavaScript, a reload shows the notice again, and coffre's pages need
16
+ * JavaScript for everything else.
17
+ */
18
+ function useOneTime(search, names) {
19
+ const [kept] = useState(() => Object.fromEntries(names.map((name) => [name, search[name]])));
20
+ const navigate = useNavigate();
21
+ const present = names.some((name) => search[name] !== void 0);
22
+ useEffect(() => {
23
+ if (!present) return;
24
+ navigate({
25
+ to: ".",
26
+ search: (previous) => Object.fromEntries(Object.entries(previous).filter(([name]) => !names.includes(name))),
27
+ replace: true
28
+ });
29
+ }, []);
30
+ return kept;
31
+ }
32
+ //#endregion
33
+ export { useOneTime as t };
34
+
35
+ //# sourceMappingURL=one-time-DXEl9hbg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"one-time-DXEl9hbg.js","names":[],"sources":["../../src/lib/one-time.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { useNavigate } from '@tanstack/react-router';\n\n/**\n * A notice that rides in the URL once, as a sign-in's `?error=` does: read\n * as the page first renders, on the server, so it shows without JavaScript;\n * then taken out of the address, the history entry replaced, so that a\n * reload is a clean retry and a copied link carries no stale error. What was\n * read stays shown until the page is left.\n *\n * Why the URL and not a one-time cookie: the URL is the one thing the server\n * renders from, so nothing has to be set on the redirect, read by the\n * render and cleared by exactly the right response, which streaming and the\n * requests a page fires beside it make fragile. The cost: without\n * JavaScript, a reload shows the notice again, and coffre's pages need\n * JavaScript for everything else.\n */\nexport function useOneTime<T extends Record<string, unknown>, K extends keyof T & string>(search: T, names: readonly K[]): Pick<T, K> {\n const [kept] = useState(() => Object.fromEntries(names.map((name) => [name, search[name]])) as Pick<T, K>);\n const navigate = useNavigate();\n const present = names.some((name) => search[name] !== undefined);\n useEffect(() => {\n if (!present) return;\n void navigate({\n to: '.',\n search: (previous: Record<string, unknown>) => Object.fromEntries(Object.entries(previous).filter(([name]) => !(names as readonly string[]).includes(name))),\n replace: true,\n });\n // Once, after hydration: later renders keep what was read.\n }, []);\n return kept;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,SAAgB,WAA0E,QAAW,OAAiC;CACpI,MAAM,CAAC,QAAQ,eAAe,OAAO,YAAY,MAAM,KAAK,SAAS,CAAC,MAAM,OAAO,KAAK,CAAC,CAAC,CAAe;CACzG,MAAM,WAAW,YAAY;CAC7B,MAAM,UAAU,MAAM,MAAM,SAAS,OAAO,UAAU,KAAA,CAAS;CAC/D,gBAAgB;EACd,IAAI,CAAC,SAAS;EACd,SAAc;GACZ,IAAI;GACJ,SAAS,aAAsC,OAAO,YAAY,OAAO,QAAQ,QAAQ,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAE,MAA4B,SAAS,IAAI,CAAC,CAAC;GAC3J,SAAS;EACX,CAAC;CAEH,GAAG,CAAC,CAAC;CACL,OAAO;AACT"}