@coffre/ui 0.4.5 → 0.5.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 (117) hide show
  1. package/dist/chunks/{affordances-DAvsVz7u.js → affordances-Bqdevf7w.js} +10 -5
  2. package/dist/chunks/affordances-Bqdevf7w.js.map +1 -0
  3. package/dist/chunks/{audit-sentence-BhHmvQX_.js → audit-sentence-Cm5nby5k.js} +115 -8
  4. package/dist/chunks/audit-sentence-Cm5nby5k.js.map +1 -0
  5. package/dist/chunks/{connected-apps-AZsX9Zvv.js → connected-apps-DTNS7YmY.js} +2 -2
  6. package/dist/chunks/{connected-apps-AZsX9Zvv.js.map → connected-apps-DTNS7YmY.js.map} +1 -1
  7. package/dist/chunks/{delete-place-D6LIZkg9.js → delete-place-CIaOq0mt.js} +3 -3
  8. package/dist/chunks/{delete-place-D6LIZkg9.js.map → delete-place-CIaOq0mt.js.map} +1 -1
  9. package/dist/chunks/{directory-B6FuiCir.js → directory-DSVt5Tya.js} +54 -60
  10. package/dist/chunks/directory-DSVt5Tya.js.map +1 -0
  11. package/dist/chunks/{folders-DvSqBhuu.js → folders-CoGK9oqg.js} +2 -2
  12. package/dist/chunks/{folders-DvSqBhuu.js.map → folders-CoGK9oqg.js.map} +1 -1
  13. package/dist/chunks/grants-CRU7yZhL.js +164 -0
  14. package/dist/chunks/grants-CRU7yZhL.js.map +1 -0
  15. package/dist/chunks/{offboarding-CLJaNTcD.js → offboarding-DVBSiJRZ.js} +7 -3
  16. package/dist/chunks/offboarding-DVBSiJRZ.js.map +1 -0
  17. package/dist/chunks/{principal-page-UtNWKCf8.js → principal-page-BEBr_zW7.js} +350 -91
  18. package/dist/chunks/principal-page-BEBr_zW7.js.map +1 -0
  19. package/dist/chunks/{project-page-C4cEaRFa.js → project-page-B3TZ5_ig.js} +2 -2
  20. package/dist/chunks/{project-page-C4cEaRFa.js.map → project-page-B3TZ5_ig.js.map} +1 -1
  21. package/dist/chunks/{queries-Dew8mIeo.js → queries-DE5nK2y4.js} +132 -54
  22. package/dist/chunks/queries-DE5nK2y4.js.map +1 -0
  23. package/dist/chunks/{references-DWDnXNoW.js → references-uv4Mli9z.js} +4 -3
  24. package/dist/chunks/{references-DWDnXNoW.js.map → references-uv4Mli9z.js.map} +1 -1
  25. package/dist/chunks/role-field-DWhkRY6n.js +192 -0
  26. package/dist/chunks/role-field-DWhkRY6n.js.map +1 -0
  27. package/dist/chunks/use-action-BRgvbUWt.js +49 -0
  28. package/dist/chunks/use-action-BRgvbUWt.js.map +1 -0
  29. package/dist/chunks/{use-change-C4bGRhHY.js → use-change-BJ3dCFHb.js} +40 -14
  30. package/dist/chunks/use-change-BJ3dCFHb.js.map +1 -0
  31. package/dist/chunks/{use-shell-Dkv89nW1.js → use-shell-BO4ZTr1y.js} +2 -2
  32. package/dist/chunks/{use-shell-Dkv89nW1.js.map → use-shell-BO4ZTr1y.js.map} +1 -1
  33. package/dist/chunks/validation-DiHIwZRA.js +37 -0
  34. package/dist/chunks/validation-DiHIwZRA.js.map +1 -0
  35. package/dist/index.d.ts +116 -88
  36. package/dist/index.js +40 -21
  37. package/dist/index.js.map +1 -1
  38. package/dist/pages/account.js +8 -7
  39. package/dist/pages/account.js.map +1 -1
  40. package/dist/pages/approval.js +53 -21
  41. package/dist/pages/approval.js.map +1 -1
  42. package/dist/pages/audit.js +2 -2
  43. package/dist/pages/environment.js +8 -7
  44. package/dist/pages/environment.js.map +1 -1
  45. package/dist/pages/login.js +2 -2
  46. package/dist/pages/login.js.map +1 -1
  47. package/dist/pages/project-access.js +7 -7
  48. package/dist/pages/project-environments.js +26 -21
  49. package/dist/pages/project-environments.js.map +1 -1
  50. package/dist/pages/project-settings.js +9 -8
  51. package/dist/pages/project-settings.js.map +1 -1
  52. package/dist/pages/project.js +1 -1
  53. package/dist/pages/projects.js +8 -13
  54. package/dist/pages/projects.js.map +1 -1
  55. package/dist/pages/service-account.js +294 -88
  56. package/dist/pages/service-account.js.map +1 -1
  57. package/dist/pages/service-accounts.js +7 -7
  58. package/dist/pages/service-accounts.js.map +1 -1
  59. package/dist/pages/settings.js +91 -9
  60. package/dist/pages/settings.js.map +1 -1
  61. package/dist/pages/unregistered.d.ts +1 -1
  62. package/dist/pages/unregistered.js +4 -4
  63. package/dist/pages/unregistered.js.map +1 -1
  64. package/dist/pages/user.d.ts +2 -0
  65. package/dist/pages/user.js +21 -3
  66. package/dist/pages/user.js.map +1 -1
  67. package/dist/pages/users.js +4 -4
  68. package/package.json +3 -3
  69. package/src/components/affordances.ts +7 -3
  70. package/src/components/command-palette.tsx +2 -0
  71. package/src/components/directory.tsx +58 -63
  72. package/src/components/grants.tsx +9 -9
  73. package/src/components/offboarding.tsx +3 -1
  74. package/src/components/principal-page.tsx +124 -74
  75. package/src/components/role-field.tsx +183 -0
  76. package/src/components/scope-picker.tsx +73 -0
  77. package/src/components/service-tokens.tsx +20 -9
  78. package/src/components/shell.tsx +6 -10
  79. package/src/components/trusted-workloads.tsx +121 -42
  80. package/src/index.ts +1 -0
  81. package/src/lib/approval.ts +23 -0
  82. package/src/lib/audit-sentences.ts +109 -3
  83. package/src/lib/bindings.ts +33 -10
  84. package/src/lib/capabilities.ts +28 -8
  85. package/src/lib/changes.ts +22 -13
  86. package/src/lib/project-access.ts +21 -0
  87. package/src/lib/queries.ts +121 -44
  88. package/src/lib/service-setup.ts +41 -0
  89. package/src/lib/validation.ts +7 -0
  90. package/src/options.ts +31 -11
  91. package/src/pages/account.tsx +3 -2
  92. package/src/pages/approval.tsx +18 -17
  93. package/src/pages/login.tsx +1 -1
  94. package/src/pages/project-environments.tsx +12 -15
  95. package/src/pages/project-settings.tsx +3 -3
  96. package/src/pages/projects.tsx +1 -5
  97. package/src/pages/service-account.tsx +7 -5
  98. package/src/pages/service-accounts.tsx +8 -4
  99. package/src/pages/settings.tsx +80 -4
  100. package/src/pages/unregistered.tsx +3 -3
  101. package/src/pages/user.tsx +24 -1
  102. package/src/parity.ts +5 -1
  103. package/src/register.ts +3 -1
  104. package/src/shared/models.ts +8 -4
  105. package/src/styles/globals.css +111 -28
  106. package/dist/chunks/affordances-DAvsVz7u.js.map +0 -1
  107. package/dist/chunks/audit-sentence-BhHmvQX_.js.map +0 -1
  108. package/dist/chunks/directory-B6FuiCir.js.map +0 -1
  109. package/dist/chunks/grants-9kIV6uZ7.js +0 -669
  110. package/dist/chunks/grants-9kIV6uZ7.js.map +0 -1
  111. package/dist/chunks/offboarding-CLJaNTcD.js.map +0 -1
  112. package/dist/chunks/principal-page-UtNWKCf8.js.map +0 -1
  113. package/dist/chunks/queries-Dew8mIeo.js.map +0 -1
  114. package/dist/chunks/use-change-C4bGRhHY.js.map +0 -1
  115. package/dist/chunks/validation-DvPinn8V.js +0 -87
  116. package/dist/chunks/validation-DvPinn8V.js.map +0 -1
  117. package/src/components/every-project.tsx +0 -287
@@ -1 +1 @@
1
- {"version":3,"file":"references-DWDnXNoW.js","names":[],"sources":["../../src/components/references.tsx"],"sourcesContent":["import { useEffect, useId, useState } from 'react';\nimport { useQuery } from '@tanstack/react-query';\nimport { Link } from '@tanstack/react-router';\nimport type { ListedReference, ReferenceView, SecretKey } from '@coffre/client';\n\nimport { useCoffre } from '../lib/coffre';\nimport { queries } from '../lib/queries';\nimport { useAction } from '../lib/use-action';\nimport { secretKeyProblem } from '../lib/validation';\nimport { ArrowRight } from './icons';\nimport { Card } from './page';\nimport { ConfirmDialog, ErrorLine, Modal, Notice, Timestamp } from './ui';\n\n/**\n * References: a secret read live through another (docs/design/environments.md).\n * The vault makes and checks each one; these only show them.\n */\n\n/** Why a reference does not read, in a few words; null while it does. */\nexport function referenceProblem(state: ReferenceView['state']): string | null {\n switch (state) {\n case 'live':\n return null;\n case 'broken':\n return 'Broken';\n case 'replaced':\n return 'No value';\n case 'source_archived':\n return 'Source archived';\n case 'source_deleted':\n return 'Source deleted';\n case 'source_is_reference':\n return 'Source is a reference';\n case 'source_empty':\n return 'Source has no value';\n }\n}\n\n/** A secret's path as a link to it, when you can open it there. */\nfunction SecretPath({ path, open }: { path: string; open: boolean }) {\n const [project, environment, key] = path.split('/') as [string, string, string];\n if (!open) {\n return (\n <span className=\"mono\" title=\"You can't open the source\">\n {path}\n </span>\n );\n }\n return (\n <Link className=\"mono\" to=\"/projects/$project/$environment\" params={{ project, environment }} search={{ filter: key }}>\n {path}\n </Link>\n );\n}\n\n/**\n * What a key that is a reference shows where its value would be: what it\n * reads, and, when it does not read, why. Reading it is a reveal like any\n * other, logged as a read of the source.\n */\nexport function ReferenceValue({ reference }: { reference: NonNullable<SecretKey['reference']> }) {\n const problem = referenceProblem(reference.state);\n return (\n <span className=\"reference-value\">\n <ArrowRight size={13} aria-label=\"A reference to\" />\n <SecretPath path={reference.source} open={reference.canOpenSource} />\n {problem !== null && (\n <span className=\"tag tag-red\" title={reference.endedBy === null ? undefined : `By ${reference.endedBy}`}>\n {problem}\n </span>\n )}\n </span>\n );\n}\n\n/**\n * The references that read a secret from elsewhere, under its row: where\n * each is held, who made it, who reads through it, and Break for those who\n * may.\n */\nexport function LentReferences({ references, onBreak }: { references: ListedReference[]; onBreak: (reference: ListedReference) => void }) {\n return (\n <ul className=\"lent-references\" aria-label=\"Read through references\">\n {references.map((reference) => (\n <li key={reference.id}>\n <span>\n Read through <SecretPath path={reference.holder} open={false} />, made by {reference.createdBy.replace(/^user:/, '')}{' '}\n <Timestamp iso={reference.createdAt} display=\"relative\" />\n {reference.readers !== null && (\n <span className=\"cell-muted\">\n {' '}\n · {reference.readers.length === 0 ? 'no one reads it by a grant' : `${reference.readers.length} ${reference.readers.length === 1 ? 'person reads' : 'people read'} it: ${reference.readers.map((reader) => reader.replace(/^user:/, '').replace(/^token:/, 'service:')).join(', ')}`}\n </span>\n )}\n </span>\n {reference.canBreak && (\n <button type=\"button\" className=\"btn btn-sm btn-danger-outline\" onClick={() => onBreak(reference)}>\n Break\n </button>\n )}\n </li>\n ))}\n </ul>\n );\n}\n\n/**\n * Make a key a reference to a secret you read, by path: whoever reads its\n * environment reads that secret through it, as it changes. Paths you can\n * read are offered as you type.\n */\nexport function MakeReference({\n open,\n onOpenChange,\n holder,\n environments,\n onMake,\n}: {\n open: boolean;\n onOpenChange: (open: boolean) => void;\n /** `billing/prod/DATABASE_URL`. */\n holder: string;\n /** `market/prod`, each environment you read. */\n environments: readonly string[];\n onMake: (source: string) => void;\n}) {\n const [source, setSource] = useState('');\n const listId = useId();\n useEffect(() => {\n if (open) setSource('');\n }, [open]);\n const [project, environment, key] = source.split('/');\n const problem =\n source === '' ? null\n : source.split('/').length !== 3 || project === '' || environment === '' ? 'A secret, as project/environment/KEY.'\n : secretKeyProblem(key!);\n const holderEnvironment = holder.split('/').slice(0, 2).join('/');\n\n return (\n <Modal\n open={open}\n onOpenChange={onOpenChange}\n title={`Make ${holder.split('/')[2]} a reference`}\n description={`Whoever can read ${holderEnvironment} will read the secret you name, as it changes, even without access to its project. You need read access to that secret.`}\n >\n <form\n className=\"form\"\n onSubmit={(event) => {\n event.preventDefault();\n if (problem !== null || source === '') return;\n onMake(source);\n onOpenChange(false);\n }}\n >\n <label className=\"field\">\n <span className=\"label\">Secret to read</span>\n <input\n className=\"input input-mono\"\n autoFocus\n spellCheck={false}\n autoComplete=\"off\"\n list={listId}\n placeholder=\"market/prod/DATABASE_URL\"\n value={source}\n aria-invalid={problem !== null}\n onChange={(event) => setSource(event.target.value)}\n />\n <datalist id={listId}>\n {environments.map((each) => (\n <option key={each} value={`${each}/`} />\n ))}\n </datalist>\n <span className={`hint${problem !== null ? ' edit-note-error' : ''}`}>\n {problem ?? 'A reference cannot point at a reference: name the secret it reads.'}\n </span>\n </label>\n <div className=\"dialog-actions\">\n <button className=\"btn\" type=\"button\" onClick={() => onOpenChange(false)}>\n Cancel\n </button>\n <button className=\"btn btn-primary\" type=\"submit\" disabled={source === '' || problem !== null}>\n Make reference\n </button>\n </div>\n </form>\n </Modal>\n );\n}\n\n/**\n * A project's secrets that others read through references held elsewhere,\n * and who: on its access tab, beside the grants, since \"who can read this\"\n * includes them. Those who may break one, its source's access managers or\n * whoever writes where it is held, do it here.\n */\nexport function ReferencesInto({ project }: { project: string }) {\n const coffre = useCoffre();\n const { data } = useQuery(queries.references(coffre, project));\n const { run, error } = useAction();\n const [breaking, setBreaking] = useState<ListedReference | null>(null);\n const into = data?.ok === true ? data.references.filter((reference) => reference.source.startsWith(`${project}/`)) : [];\n if (into.length === 0) return null;\n return (\n <Card\n labelledBy=\"references-into\"\n title=\"Also readable through references\"\n description={`Secrets of ${project} that references elsewhere read. Whoever reads a reference's environment reads its source, with no grant here.`}\n >\n <div className=\"dt-wrap\">\n <table className=\"dt stacks\">\n <thead>\n <tr>\n <th>Secret</th>\n <th>Read through</th>\n <th>Readers</th>\n <th className=\"col-actions\">\n <span className=\"visually-hidden\">Actions</span>\n </th>\n </tr>\n </thead>\n <tbody>\n {into.map((reference) => (\n <tr key={reference.id}>\n <td className=\"mono\" data-label=\"Secret\">{reference.source}</td>\n <td data-label=\"Read through\">\n <span className=\"cell-stack\">\n <span className=\"mono\">{reference.holder}</span>\n <small className=\"cell-muted\">\n Made by {reference.createdBy.replace(/^user:/, '')} <Timestamp iso={reference.createdAt} display=\"relative\" />\n </small>\n </span>\n </td>\n <td data-label=\"Readers\">\n {reference.readers === null\n ? '—'\n : reference.readers.length === 0\n ? <span className=\"cell-muted\">No one, by a grant</span>\n : reference.readers.map((reader) => reader.replace(/^user:/, '').replace(/^token:/, 'service:')).join(', ')}\n </td>\n <td className=\"col-actions\">\n {reference.canBreak && (\n <button type=\"button\" className=\"btn btn-sm btn-danger-outline\" onClick={() => setBreaking(reference)}>\n Break\n </button>\n )}\n </td>\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n {error !== null && <ErrorLine error={error} />}\n <ConfirmDialog\n open={breaking !== null}\n onOpenChange={(open) => !open && setBreaking(null)}\n title=\"Break this reference?\"\n body={breaking === null ? '' : `Whoever reads ${breaking.holder.split('/').slice(0, 2).join('/')} stops reading ${breaking.source} through it, and a run there refuses until ${breaking.holder.split('/')[2]} gets a value.`}\n confirmLabel=\"Break\"\n onConfirm={() => {\n const path = breaking!.holder;\n void run(() => coffre.references.break(path), { affects: [['references']] });\n }}\n />\n </Card>\n );\n}\n\n/**\n * The references that archiving `path` would stop, a project, an\n * environment or a key: those reading a secret in it, held outside it in a\n * place not archived itself (D58). Archiving is refused while any read\n * (D41); the server decides, and this shows the dialog what it will say.\n */\nexport function archiveBlockers(path: string, references: readonly ListedReference[]): ListedReference[] {\n const within = (secret: string) => secret === path || secret.startsWith(`${path}/`);\n return references.filter((reference) => reference.state === 'live' && !reference.holderArchived && within(reference.source) && !within(reference.holder));\n}\n\n/**\n * What an archive dialog shows while references read what it would\n * archive: each, and Break for those who may break it. Archive waits until\n * none is left.\n */\nexport function ArchiveBlocked({ references }: { references: readonly ListedReference[] }) {\n const coffre = useCoffre();\n const { run, error, pending } = useAction();\n if (references.length === 0) return null;\n const many = references.length > 1;\n return (\n <div className=\"archive-blocked\">\n <Notice tone=\"bad\">\n {many ? `${references.length} references read it` : 'A reference reads it'} from elsewhere. Break{' '}\n {many ? 'them' : 'it'} first: archiving would stop {many ? 'those reads' : 'that read'}.\n </Notice>\n <ul className=\"archive-blockers\" aria-label=\"References that read it\">\n {references.map((reference) => (\n <li key={reference.id}>\n <span className=\"cell-stack\">\n <span className=\"mono\">{reference.holder}</span>\n <small>\n reads <span className=\"mono\">{reference.source}</span>\n </small>\n </span>\n {reference.canBreak ? (\n <button\n type=\"button\"\n className=\"btn btn-sm btn-danger-outline\"\n disabled={pending}\n onClick={() => void run(() => coffre.references.break(reference.holder), { affects: [['references'], ['secrets']] })}\n >\n Break\n </button>\n ) : (\n <small className=\"cell-muted\">{`${reference.source.split('/')[0]}'s access managers, or whoever writes ${reference.holder.split('/').slice(0, 2).join('/')}, can break it`}</small>\n )}\n </li>\n ))}\n </ul>\n <p className=\"hint\">Once broken, a run where it is held refuses until that key gets a value of its own.</p>\n {error !== null && <ErrorLine error={error} />}\n </div>\n );\n}\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C,QAAD;KAAM,WAAU;eAAhB,CACE,oBAAC,QAAD;MAAM,WAAU;gBAAQ,UAAU;KAAa,CAAA,GAC/C,qBAAC,SAAD,EAAA,UAAA,CAAO,UACC,oBAAC,QAAD;MAAM,WAAU;gBAAQ,UAAU;KAAa,CAAA,CAChD,EAAA,CAAA,CACH;QACL,UAAU,WACT,oBAAC,UAAD;KACE,MAAK;KACL,WAAU;KACV,UAAU;KACV,eAAe,KAAK,UAAU,OAAO,WAAW,MAAM,UAAU,MAAM,GAAG,EAAE,SAAS,CAAC,CAAC,YAAY,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;eACpH;IAEO,CAAA,IAER,oBAAC,SAAD;KAAO,WAAU;eAAc,GAAG,UAAU,OAAO,MAAM,GAAG,CAAC,CAAC,GAAG,wCAAwC,UAAU,OAAO,MAAM,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;IAAuB,CAAA,CAElL,EAAA,GAnBK,UAAU,EAmBf,CACL;GACC,CAAA;GACJ,oBAAC,KAAD;IAAG,WAAU;cAAO;GAAsF,CAAA;GACzG,UAAU,QAAQ,oBAAC,WAAD,EAAkB,MAAQ,CAAA;EAC1C;;AAET"}
1
+ {"version":3,"file":"references-uv4Mli9z.js","names":[],"sources":["../../src/components/references.tsx"],"sourcesContent":["import { useEffect, useId, useState } from 'react';\nimport { useQuery } from '@tanstack/react-query';\nimport { Link } from '@tanstack/react-router';\nimport type { ListedReference, ReferenceView, SecretKey } from '@coffre/client';\n\nimport { useCoffre } from '../lib/coffre';\nimport { queries } from '../lib/queries';\nimport { useAction } from '../lib/use-action';\nimport { secretKeyProblem } from '../lib/validation';\nimport { ArrowRight } from './icons';\nimport { Card } from './page';\nimport { ConfirmDialog, ErrorLine, Modal, Notice, Timestamp } from './ui';\n\n/**\n * References: a secret read live through another (docs/design/environments.md).\n * The vault makes and checks each one; these only show them.\n */\n\n/** Why a reference does not read, in a few words; null while it does. */\nexport function referenceProblem(state: ReferenceView['state']): string | null {\n switch (state) {\n case 'live':\n return null;\n case 'broken':\n return 'Broken';\n case 'replaced':\n return 'No value';\n case 'source_archived':\n return 'Source archived';\n case 'source_deleted':\n return 'Source deleted';\n case 'source_is_reference':\n return 'Source is a reference';\n case 'source_empty':\n return 'Source has no value';\n }\n}\n\n/** A secret's path as a link to it, when you can open it there. */\nfunction SecretPath({ path, open }: { path: string; open: boolean }) {\n const [project, environment, key] = path.split('/') as [string, string, string];\n if (!open) {\n return (\n <span className=\"mono\" title=\"You can't open the source\">\n {path}\n </span>\n );\n }\n return (\n <Link className=\"mono\" to=\"/projects/$project/$environment\" params={{ project, environment }} search={{ filter: key }}>\n {path}\n </Link>\n );\n}\n\n/**\n * What a key that is a reference shows where its value would be: what it\n * reads, and, when it does not read, why. Reading it is a reveal like any\n * other, logged as a read of the source.\n */\nexport function ReferenceValue({ reference }: { reference: NonNullable<SecretKey['reference']> }) {\n const problem = referenceProblem(reference.state);\n return (\n <span className=\"reference-value\">\n <ArrowRight size={13} aria-label=\"A reference to\" />\n <SecretPath path={reference.source} open={reference.canOpenSource} />\n {problem !== null && (\n <span className=\"tag tag-red\" title={reference.endedBy === null ? undefined : `By ${reference.endedBy}`}>\n {problem}\n </span>\n )}\n </span>\n );\n}\n\n/**\n * The references that read a secret from elsewhere, under its row: where\n * each is held, who made it, who reads through it, and Break for those who\n * may.\n */\nexport function LentReferences({ references, onBreak }: { references: ListedReference[]; onBreak: (reference: ListedReference) => void }) {\n return (\n <ul className=\"lent-references\" aria-label=\"Read through references\">\n {references.map((reference) => (\n <li key={reference.id}>\n <span>\n Read through <SecretPath path={reference.holder} open={false} />, made by {reference.createdBy.replace(/^user:/, '')}{' '}\n <Timestamp iso={reference.createdAt} display=\"relative\" />\n {reference.readers !== null && (\n <span className=\"cell-muted\">\n {' '}\n · {reference.readers.length === 0 ? 'no one reads it by a grant' : `${reference.readers.length} ${reference.readers.length === 1 ? 'person reads' : 'people read'} it: ${reference.readers.map((reader) => reader.replace(/^user:/, '').replace(/^token:/, 'service:')).join(', ')}`}\n </span>\n )}\n </span>\n {reference.canBreak && (\n <button type=\"button\" className=\"btn btn-sm btn-danger-outline\" onClick={() => onBreak(reference)}>\n Break\n </button>\n )}\n </li>\n ))}\n </ul>\n );\n}\n\n/**\n * Make a key a reference to a secret you read, by path: whoever reads its\n * environment reads that secret through it, as it changes. Paths you can\n * read are offered as you type.\n */\nexport function MakeReference({\n open,\n onOpenChange,\n holder,\n environments,\n onMake,\n}: {\n open: boolean;\n onOpenChange: (open: boolean) => void;\n /** `billing/prod/DATABASE_URL`. */\n holder: string;\n /** `market/prod`, each environment you read. */\n environments: readonly string[];\n onMake: (source: string) => void;\n}) {\n const [source, setSource] = useState('');\n const listId = useId();\n useEffect(() => {\n if (open) setSource('');\n }, [open]);\n const [project, environment, key] = source.split('/');\n const problem =\n source === '' ? null\n : source.split('/').length !== 3 || project === '' || environment === '' ? 'A secret, as project/environment/KEY.'\n : secretKeyProblem(key!);\n const holderEnvironment = holder.split('/').slice(0, 2).join('/');\n\n return (\n <Modal\n open={open}\n onOpenChange={onOpenChange}\n title={`Make ${holder.split('/')[2]} a reference`}\n description={`Whoever can read ${holderEnvironment} will read the secret you name, as it changes, even without access to its project. You need read access to that secret.`}\n >\n <form\n className=\"form\"\n onSubmit={(event) => {\n event.preventDefault();\n if (problem !== null || source === '') return;\n onMake(source);\n onOpenChange(false);\n }}\n >\n <label className=\"field\">\n <span className=\"label\">Secret to read</span>\n <input\n className=\"input input-mono\"\n autoFocus\n spellCheck={false}\n autoComplete=\"off\"\n list={listId}\n placeholder=\"market/prod/DATABASE_URL\"\n value={source}\n aria-invalid={problem !== null}\n onChange={(event) => setSource(event.target.value)}\n />\n <datalist id={listId}>\n {environments.map((each) => (\n <option key={each} value={`${each}/`} />\n ))}\n </datalist>\n <span className={`hint${problem !== null ? ' edit-note-error' : ''}`}>\n {problem ?? 'A reference cannot point at a reference: name the secret it reads.'}\n </span>\n </label>\n <div className=\"dialog-actions\">\n <button className=\"btn\" type=\"button\" onClick={() => onOpenChange(false)}>\n Cancel\n </button>\n <button className=\"btn btn-primary\" type=\"submit\" disabled={source === '' || problem !== null}>\n Make reference\n </button>\n </div>\n </form>\n </Modal>\n );\n}\n\n/**\n * A project's secrets that others read through references held elsewhere,\n * and who: on its access tab, beside the grants, since \"who can read this\"\n * includes them. Those who may break one, its source's access managers or\n * whoever writes where it is held, do it here.\n */\nexport function ReferencesInto({ project }: { project: string }) {\n const coffre = useCoffre();\n const { data } = useQuery(queries.references(coffre, project));\n const { run, error } = useAction();\n const [breaking, setBreaking] = useState<ListedReference | null>(null);\n const into = data?.ok === true ? data.references.filter((reference) => reference.source.startsWith(`${project}/`)) : [];\n if (into.length === 0) return null;\n return (\n <Card\n labelledBy=\"references-into\"\n title=\"Also readable through references\"\n description={`Secrets of ${project} that references elsewhere read. Whoever reads a reference's environment reads its source, with no grant here.`}\n >\n <div className=\"dt-wrap\">\n <table className=\"dt stacks\">\n <thead>\n <tr>\n <th>Secret</th>\n <th>Read through</th>\n <th>Readers</th>\n <th className=\"col-actions\">\n <span className=\"visually-hidden\">Actions</span>\n </th>\n </tr>\n </thead>\n <tbody>\n {into.map((reference) => (\n <tr key={reference.id}>\n <td className=\"mono\" data-label=\"Secret\">{reference.source}</td>\n <td data-label=\"Read through\">\n <span className=\"cell-stack\">\n <span className=\"mono\">{reference.holder}</span>\n <small className=\"cell-muted\">\n Made by {reference.createdBy.replace(/^user:/, '')} <Timestamp iso={reference.createdAt} display=\"relative\" />\n </small>\n </span>\n </td>\n <td data-label=\"Readers\">\n {reference.readers === null\n ? '—'\n : reference.readers.length === 0\n ? <span className=\"cell-muted\">No one, by a grant</span>\n : reference.readers.map((reader) => reader.replace(/^user:/, '').replace(/^token:/, 'service:')).join(', ')}\n </td>\n <td className=\"col-actions\">\n {reference.canBreak && (\n <button type=\"button\" className=\"btn btn-sm btn-danger-outline\" onClick={() => setBreaking(reference)}>\n Break\n </button>\n )}\n </td>\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n {error !== null && <ErrorLine error={error} />}\n <ConfirmDialog\n open={breaking !== null}\n onOpenChange={(open) => !open && setBreaking(null)}\n title=\"Break this reference?\"\n body={breaking === null ? '' : `Whoever reads ${breaking.holder.split('/').slice(0, 2).join('/')} stops reading ${breaking.source} through it, and a run there refuses until ${breaking.holder.split('/')[2]} gets a value.`}\n confirmLabel=\"Break\"\n onConfirm={() => {\n const path = breaking!.holder;\n void run(() => coffre.references.break(path), { affects: [['references']] });\n }}\n />\n </Card>\n );\n}\n\n/**\n * The references that archiving `path` would stop, a project, an\n * environment or a key: those reading a secret in it, held outside it in a\n * place not archived itself (D58). Archiving is refused while any read\n * (D41); the server decides, and this shows the dialog what it will say.\n */\nexport function archiveBlockers(path: string, references: readonly ListedReference[]): ListedReference[] {\n const within = (secret: string) => secret === path || secret.startsWith(`${path}/`);\n return references.filter((reference) => reference.state === 'live' && !reference.holderArchived && within(reference.source) && !within(reference.holder));\n}\n\n/**\n * What an archive dialog shows while references read what it would\n * archive: each, and Break for those who may break it. Archive waits until\n * none is left.\n */\nexport function ArchiveBlocked({ references }: { references: readonly ListedReference[] }) {\n const coffre = useCoffre();\n const { run, error, pending } = useAction();\n if (references.length === 0) return null;\n const many = references.length > 1;\n return (\n <div className=\"archive-blocked\">\n <Notice tone=\"bad\">\n {many ? `${references.length} references read it` : 'A reference reads it'} from elsewhere. Break{' '}\n {many ? 'them' : 'it'} first: archiving would stop {many ? 'those reads' : 'that read'}.\n </Notice>\n <ul className=\"archive-blockers\" aria-label=\"References that read it\">\n {references.map((reference) => (\n <li key={reference.id}>\n <span className=\"cell-stack\">\n <span className=\"mono\">{reference.holder}</span>\n <small>\n reads <span className=\"mono\">{reference.source}</span>\n </small>\n </span>\n {reference.canBreak ? (\n <button\n type=\"button\"\n className=\"btn btn-sm btn-danger-outline\"\n disabled={pending}\n onClick={() => void run(() => coffre.references.break(reference.holder), { affects: [['references'], ['secrets']] })}\n >\n Break\n </button>\n ) : (\n <small className=\"cell-muted\">{`${reference.source.split('/')[0]}'s access managers, or whoever writes ${reference.holder.split('/').slice(0, 2).join('/')}, can break it`}</small>\n )}\n </li>\n ))}\n </ul>\n <p className=\"hint\">Once broken, a run where it is held refuses until that key gets a value of its own.</p>\n {error !== null && <ErrorLine error={error} />}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,SAAgB,iBAAiB,OAA8C;CAC7E,QAAQ,OAAR;EACE,KAAK,QACH,OAAO;EACT,KAAK,UACH,OAAO;EACT,KAAK,YACH,OAAO;EACT,KAAK,mBACH,OAAO;EACT,KAAK,kBACH,OAAO;EACT,KAAK,uBACH,OAAO;EACT,KAAK,gBACH,OAAO;CACX;AACF;;AAGA,SAAS,WAAW,EAAE,MAAM,QAAyC;CACnE,MAAM,CAAC,SAAS,aAAa,OAAO,KAAK,MAAM,GAAG;CAClD,IAAI,CAAC,MACH,OACE,oBAAC,QAAD;EAAM,WAAU;EAAO,OAAM;YAC1B;CACG,CAAA;CAGV,OACE,oBAAC,MAAD;EAAM,WAAU;EAAO,IAAG;EAAkC,QAAQ;GAAE;GAAS;EAAY;EAAG,QAAQ,EAAE,QAAQ,IAAI;YACjH;CACG,CAAA;AAEV;;;;;;AAOA,SAAgB,eAAe,EAAE,aAAiE;CAChG,MAAM,UAAU,iBAAiB,UAAU,KAAK;CAChD,OACE,qBAAC,QAAD;EAAM,WAAU;YAAhB;GACE,oBAAC,YAAD;IAAY,MAAM;IAAI,cAAW;GAAkB,CAAA;GACnD,oBAAC,YAAD;IAAY,MAAM,UAAU;IAAQ,MAAM,UAAU;GAAgB,CAAA;GACnE,YAAY,QACX,oBAAC,QAAD;IAAM,WAAU;IAAc,OAAO,UAAU,YAAY,OAAO,KAAA,IAAY,MAAM,UAAU;cAC3F;GACG,CAAA;EAEJ;;AAEV;;;;;;AAOA,SAAgB,eAAe,EAAE,YAAY,WAA6F;CACxI,OACE,oBAAC,MAAD;EAAI,WAAU;EAAkB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AAb;KACG,OAAO,GAAG,WAAW,OAAO,uBAAuB;KAAuB;KAAuB;KACjG,OAAO,SAAS;KAAK;KAA8B,OAAO,gBAAgB;KAAY;IACjF;;GACR,oBAAC,MAAD;IAAI,WAAU;IAAmB,cAAW;cACzC,WAAW,KAAK,cACf,qBAAC,MAAD,EAAA,UAAA,CACE,qBAAC,QAAD;KAAM,WAAU;eAAhB,CACE,oBAAC,QAAD;MAAM,WAAU;gBAAQ,UAAU;KAAa,CAAA,GAC/C,qBAAC,SAAD,EAAA,UAAA,CAAO,UACC,oBAAC,QAAD;MAAM,WAAU;gBAAQ,UAAU;KAAa,CAAA,CAChD,EAAA,CAAA,CACH;QACL,UAAU,WACT,oBAAC,UAAD;KACE,MAAK;KACL,WAAU;KACV,UAAU;KACV,eAAe,KAAK,UAAU,OAAO,WAAW,MAAM,UAAU,MAAM,GAAG,EAAE,SAAS,CAAC,CAAC,YAAY,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;eACpH;IAEO,CAAA,IAER,oBAAC,SAAD;KAAO,WAAU;eAAc,GAAG,UAAU,OAAO,MAAM,GAAG,CAAC,CAAC,GAAG,wCAAwC,UAAU,OAAO,MAAM,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;IAAuB,CAAA,CAElL,EAAA,GAnBK,UAAU,EAmBf,CACL;GACC,CAAA;GACJ,oBAAC,KAAD;IAAG,WAAU;cAAO;GAAsF,CAAA;GACzG,UAAU,QAAQ,oBAAC,WAAD,EAAkB,MAAQ,CAAA;EAC1C;;AAET"}
@@ -0,0 +1,192 @@
1
+ import { it as X } from "./page-DvsgZ2Hd.js";
2
+ import { t as useShell } from "./use-shell-BO4ZTr1y.js";
3
+ import { a as slugProblem } from "./validation-DiHIwZRA.js";
4
+ import { useId, useState } from "react";
5
+ import { INSTANCE_ROLES, INSTANCE_ROLE_NAMES } from "@coffre/core/access";
6
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
7
+ //#region src/components/role-field.tsx
8
+ /**
9
+ * A person's instance role, one dropdown, and under it, for every role but
10
+ * Member, where it applies: projects and environments, each All, Only or
11
+ * All except. Projects are picked from those there are; environments are
12
+ * names, so any slug goes, the ones made later too.
13
+ */
14
+ function RoleField({ value, onChange }) {
15
+ const { role, scope } = value;
16
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("label", {
17
+ className: "field",
18
+ children: [
19
+ /* @__PURE__ */ jsx("span", {
20
+ className: "label",
21
+ children: "Instance role"
22
+ }),
23
+ /* @__PURE__ */ jsx("select", {
24
+ className: "select",
25
+ value: role,
26
+ onChange: (event) => onChange({
27
+ role: event.target.value,
28
+ scope
29
+ }),
30
+ children: INSTANCE_ROLE_NAMES.map((name) => /* @__PURE__ */ jsx("option", {
31
+ value: name,
32
+ children: INSTANCE_ROLES[name].name
33
+ }, name))
34
+ }),
35
+ /* @__PURE__ */ jsxs("span", {
36
+ className: "hint",
37
+ children: [INSTANCE_ROLES[role].description, role === "member" ? "" : " Project grants add to it."]
38
+ })
39
+ ]
40
+ }), role !== "member" && /* @__PURE__ */ jsx(ScopeField, {
41
+ scope,
42
+ onChange: (next) => onChange({
43
+ role,
44
+ scope: next
45
+ })
46
+ })] });
47
+ }
48
+ /**
49
+ * Where something applies: projects and environments, each All, Only or All
50
+ * except. A role's scope, and the instance's setting of where people set
51
+ * up service accounts, which has the same shape.
52
+ */
53
+ function ScopeField({ scope, onChange, legend = "Where" }) {
54
+ const { projects } = useShell();
55
+ const slugs = [...new Set(projects.flatMap((project) => project.environments.map((environment) => environment.slug)))].sort();
56
+ return /* @__PURE__ */ jsxs("fieldset", {
57
+ className: "field scope-field",
58
+ children: [
59
+ /* @__PURE__ */ jsx("legend", {
60
+ className: "label",
61
+ children: legend
62
+ }),
63
+ /* @__PURE__ */ jsx(FilterRow, {
64
+ label: "Projects",
65
+ filter: scope.projects,
66
+ options: projects.map((project) => project.slug),
67
+ onChange: (filter) => onChange({
68
+ ...scope,
69
+ projects: filter
70
+ })
71
+ }),
72
+ /* @__PURE__ */ jsx(FilterRow, {
73
+ label: "Environments",
74
+ filter: scope.environments,
75
+ options: slugs,
76
+ free: true,
77
+ onChange: (filter) => onChange({
78
+ ...scope,
79
+ environments: filter
80
+ })
81
+ }),
82
+ scope.environments !== "all" && /* @__PURE__ */ jsx("span", {
83
+ className: "hint",
84
+ children: "Environments match by name in every project, new ones included."
85
+ })
86
+ ]
87
+ });
88
+ }
89
+ var namesOf = (filter) => filter === "all" ? [] : "only" in filter ? filter.only : filter.except;
90
+ function filterOf(mode, names) {
91
+ return mode === "all" ? "all" : mode === "only" ? { only: names } : { except: names };
92
+ }
93
+ /** One filter: All, Only or All except, and the names it lists. */
94
+ function FilterRow({ label, filter, options, free = false, onChange }) {
95
+ const mode = filter === "all" ? "all" : "only" in filter ? "only" : "except";
96
+ const names = namesOf(filter);
97
+ return /* @__PURE__ */ jsxs("div", {
98
+ className: "scope-row",
99
+ children: [
100
+ /* @__PURE__ */ jsx("span", {
101
+ className: "scope-label",
102
+ children: label
103
+ }),
104
+ /* @__PURE__ */ jsxs("select", {
105
+ className: "select select-sm",
106
+ "aria-label": `${label}: which`,
107
+ value: mode,
108
+ onChange: (event) => onChange(filterOf(event.target.value, names)),
109
+ children: [
110
+ /* @__PURE__ */ jsx("option", {
111
+ value: "all",
112
+ children: "All"
113
+ }),
114
+ /* @__PURE__ */ jsx("option", {
115
+ value: "only",
116
+ children: "Only"
117
+ }),
118
+ /* @__PURE__ */ jsx("option", {
119
+ value: "except",
120
+ children: "All except"
121
+ })
122
+ ]
123
+ }),
124
+ mode !== "all" && /* @__PURE__ */ jsx(NamePicker, {
125
+ label,
126
+ names,
127
+ options,
128
+ free,
129
+ onChange: (next) => onChange(filterOf(mode, next))
130
+ })
131
+ ]
132
+ });
133
+ }
134
+ /** Names as chips, and a field to add one: picked from the list, or, where any name goes, typed and entered. */
135
+ function NamePicker({ label, names, options, free, onChange }) {
136
+ const [draft, setDraft] = useState("");
137
+ const list = useId();
138
+ const add = (raw) => {
139
+ const name = raw.trim();
140
+ setDraft("");
141
+ if (name === "" || names.includes(name)) return;
142
+ if (free ? slugProblem(name) !== null : !options.includes(name)) return;
143
+ onChange([...names, name]);
144
+ };
145
+ const offered = options.filter((option) => !names.includes(option));
146
+ return /* @__PURE__ */ jsxs("span", {
147
+ className: "scope-names",
148
+ children: [
149
+ names.map((name) => /* @__PURE__ */ jsxs("span", {
150
+ className: "tag scope-chip",
151
+ children: [/* @__PURE__ */ jsx("span", {
152
+ className: "mono",
153
+ children: name
154
+ }), /* @__PURE__ */ jsx("button", {
155
+ type: "button",
156
+ "aria-label": `Remove ${name}`,
157
+ onClick: () => onChange(names.filter((other) => other !== name)),
158
+ children: /* @__PURE__ */ jsx(X, { size: 11 })
159
+ })]
160
+ }, name)),
161
+ /* @__PURE__ */ jsx("input", {
162
+ className: "input input-mono scope-input",
163
+ list,
164
+ value: draft,
165
+ spellCheck: false,
166
+ autoComplete: "off",
167
+ placeholder: names.length === 0 ? free ? "dev" : "Pick a project" : "Add",
168
+ "aria-label": `Add to ${label}`,
169
+ "aria-invalid": draft !== "" && free && slugProblem(draft.trim()) !== null,
170
+ onChange: (event) => {
171
+ if (event.nativeEvent.inputType === "insertReplacementText" || !free && options.includes(event.target.value)) add(event.target.value);
172
+ else setDraft(event.target.value);
173
+ },
174
+ onKeyDown: (event) => {
175
+ if (event.key === "Enter" || event.key === ",") {
176
+ event.preventDefault();
177
+ add(draft);
178
+ } else if (event.key === "Backspace" && draft === "" && names.length > 0) onChange(names.slice(0, -1));
179
+ },
180
+ onBlur: () => add(draft)
181
+ }),
182
+ /* @__PURE__ */ jsx("datalist", {
183
+ id: list,
184
+ children: offered.map((option) => /* @__PURE__ */ jsx("option", { value: option }, option))
185
+ })
186
+ ]
187
+ });
188
+ }
189
+ //#endregion
190
+ export { ScopeField as n, RoleField as t };
191
+
192
+ //# sourceMappingURL=role-field-DWhkRY6n.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"role-field-DWhkRY6n.js","names":[],"sources":["../../src/components/role-field.tsx"],"sourcesContent":["import { useId, useState } from 'react';\nimport { INSTANCE_ROLE_NAMES, INSTANCE_ROLES, type Filter, type InstanceRole, type Scope } from '@coffre/core/access';\nimport type { RoleVars } from '../lib/changes';\nimport { useShell } from '../lib/use-shell';\nimport { slugProblem } from '../lib/validation';\nimport { X } from './icons';\n\n/**\n * A person's instance role, one dropdown, and under it, for every role but\n * Member, where it applies: projects and environments, each All, Only or\n * All except. Projects are picked from those there are; environments are\n * names, so any slug goes, the ones made later too.\n */\nexport function RoleField({ value, onChange }: { value: RoleVars; onChange: (value: RoleVars) => void }) {\n const { role, scope } = value;\n return (\n <>\n <label className=\"field\">\n <span className=\"label\">Instance role</span>\n <select\n className=\"select\"\n value={role}\n onChange={(event) => onChange({ role: event.target.value as InstanceRole, scope })}\n >\n {INSTANCE_ROLE_NAMES.map((name) => (\n <option key={name} value={name}>\n {INSTANCE_ROLES[name].name}\n </option>\n ))}\n </select>\n <span className=\"hint\">\n {INSTANCE_ROLES[role].description}\n {role === 'member' ? '' : ' Project grants add to it.'}\n </span>\n </label>\n {role !== 'member' && <ScopeField scope={scope} onChange={(next) => onChange({ role, scope: next })} />}\n </>\n );\n}\n\n/**\n * Where something applies: projects and environments, each All, Only or All\n * except. A role's scope, and the instance's setting of where people set\n * up service accounts, which has the same shape.\n */\nexport function ScopeField({ scope, onChange, legend = 'Where' }: { scope: Scope; onChange: (scope: Scope) => void; legend?: string }) {\n const { projects } = useShell();\n const slugs = [...new Set(projects.flatMap((project) => project.environments.map((environment) => environment.slug)))].sort();\n return (\n <fieldset className=\"field scope-field\">\n <legend className=\"label\">{legend}</legend>\n <FilterRow\n label=\"Projects\"\n filter={scope.projects}\n options={projects.map((project) => project.slug)}\n onChange={(filter) => onChange({ ...scope, projects: filter })}\n />\n <FilterRow\n label=\"Environments\"\n filter={scope.environments}\n options={slugs}\n free\n onChange={(filter) => onChange({ ...scope, environments: filter })}\n />\n {scope.environments !== 'all' && <span className=\"hint\">Environments match by name in every project, new ones included.</span>}\n </fieldset>\n );\n}\n\ntype Mode = 'all' | 'only' | 'except';\n\nconst namesOf = (filter: Filter): string[] => (filter === 'all' ? [] : 'only' in filter ? filter.only : filter.except);\n\nfunction filterOf(mode: Mode, names: string[]): Filter {\n return mode === 'all' ? 'all' : mode === 'only' ? { only: names } : { except: names };\n}\n\n/** One filter: All, Only or All except, and the names it lists. */\nfunction FilterRow({\n label,\n filter,\n options,\n free = false,\n onChange,\n}: {\n label: string;\n filter: Filter;\n options: string[];\n /** Whether a name need not be among `options`: an environment's slug, which may come later. */\n free?: boolean;\n onChange: (filter: Filter) => void;\n}) {\n const mode: Mode = filter === 'all' ? 'all' : 'only' in filter ? 'only' : 'except';\n const names = namesOf(filter);\n return (\n <div className=\"scope-row\">\n <span className=\"scope-label\">{label}</span>\n <select\n className=\"select select-sm\"\n aria-label={`${label}: which`}\n value={mode}\n onChange={(event) => onChange(filterOf(event.target.value as Mode, names))}\n >\n <option value=\"all\">All</option>\n <option value=\"only\">Only</option>\n <option value=\"except\">All except</option>\n </select>\n {mode !== 'all' && (\n <NamePicker label={label} names={names} options={options} free={free} onChange={(next) => onChange(filterOf(mode, next))} />\n )}\n </div>\n );\n}\n\n/** Names as chips, and a field to add one: picked from the list, or, where any name goes, typed and entered. */\nfunction NamePicker({\n label,\n names,\n options,\n free,\n onChange,\n}: {\n label: string;\n names: string[];\n options: string[];\n free: boolean;\n onChange: (names: string[]) => void;\n}) {\n const [draft, setDraft] = useState('');\n const list = useId();\n const add = (raw: string) => {\n const name = raw.trim();\n setDraft('');\n if (name === '' || names.includes(name)) return;\n if (free ? slugProblem(name) !== null : !options.includes(name)) return;\n onChange([...names, name]);\n };\n const offered = options.filter((option) => !names.includes(option));\n return (\n <span className=\"scope-names\">\n {names.map((name) => (\n <span key={name} className=\"tag scope-chip\">\n <span className=\"mono\">{name}</span>\n <button type=\"button\" aria-label={`Remove ${name}`} onClick={() => onChange(names.filter((other) => other !== name))}>\n <X size={11} />\n </button>\n </span>\n ))}\n <input\n className=\"input input-mono scope-input\"\n list={list}\n value={draft}\n spellCheck={false}\n autoComplete=\"off\"\n placeholder={names.length === 0 ? (free ? 'dev' : 'Pick a project') : 'Add'}\n aria-label={`Add to ${label}`}\n aria-invalid={draft !== '' && free && slugProblem(draft.trim()) !== null}\n onChange={(event) => {\n // A name picked from the list goes in at once; one typed, on Enter.\n if ((event.nativeEvent as InputEvent).inputType === 'insertReplacementText' || (!free && options.includes(event.target.value))) {\n add(event.target.value);\n } else {\n setDraft(event.target.value);\n }\n }}\n onKeyDown={(event) => {\n if (event.key === 'Enter' || event.key === ',') {\n event.preventDefault();\n add(draft);\n } else if (event.key === 'Backspace' && draft === '' && names.length > 0) {\n onChange(names.slice(0, -1));\n }\n }}\n onBlur={() => add(draft)}\n />\n <datalist id={list}>\n {offered.map((option) => (\n <option key={option} value={option} />\n ))}\n </datalist>\n </span>\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,UAAU,EAAE,OAAO,YAAsE;CACvG,MAAM,EAAE,MAAM,UAAU;CACxB,OACE,qBAAA,YAAA,EAAA,UAAA,CACE,qBAAC,SAAD;EAAO,WAAU;YAAjB;GACE,oBAAC,QAAD;IAAM,WAAU;cAAQ;GAAmB,CAAA;GAC3C,oBAAC,UAAD;IACE,WAAU;IACV,OAAO;IACP,WAAW,UAAU,SAAS;KAAE,MAAM,MAAM,OAAO;KAAuB;IAAM,CAAC;cAEhF,oBAAoB,KAAK,SACxB,oBAAC,UAAD;KAAmB,OAAO;eACvB,eAAe,KAAK,CAAC;IAChB,GAFK,IAEL,CACT;GACK,CAAA;GACR,qBAAC,QAAD;IAAM,WAAU;cAAhB,CACG,eAAe,KAAK,CAAC,aACrB,SAAS,WAAW,KAAK,4BACtB;;EACD;KACN,SAAS,YAAY,oBAAC,YAAD;EAAmB;EAAO,WAAW,SAAS,SAAS;GAAE;GAAM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AAa,MAAM,WAAW,IAAK,OAAO,QAAQ,mBAAoB;IACtE,cAAY,UAAU;IACtB,gBAAc,UAAU,MAAM,QAAQ,YAAY,MAAM,KAAK,CAAC,MAAM;IACpE,WAAW,UAAU;KAEnB,IAAK,MAAM,YAA2B,cAAc,2BAA4B,CAAC,QAAQ,QAAQ,SAAS,MAAM,OAAO,KAAK,GAC1H,IAAI,MAAM,OAAO,KAAK;UAEtB,SAAS,MAAM,OAAO,KAAK;IAE/B;IACA,YAAY,UAAU;KACpB,IAAI,MAAM,QAAQ,WAAW,MAAM,QAAQ,KAAK;MAC9C,MAAM,eAAe;MACrB,IAAI,KAAK;KACX,OAAO,IAAI,MAAM,QAAQ,eAAe,UAAU,MAAM,MAAM,SAAS,GACrE,SAAS,MAAM,MAAM,GAAG,EAAE,CAAC;IAE/B;IACA,cAAc,IAAI,KAAK;GACxB,CAAA;GACD,oBAAC,YAAD;IAAU,IAAI;cACX,QAAQ,KAAK,WACZ,oBAAC,UAAD,EAAqB,OAAO,OAAS,GAAxB,MAAwB,CACtC;GACO,CAAA;EACN;;AAEV"}
@@ -0,0 +1,49 @@
1
+ import { o as failureMessage } from "./page-DvsgZ2Hd.js";
2
+ import { _ as refresh } from "./queries-DE5nK2y4.js";
3
+ import { useState } from "react";
4
+ import { useQueryClient } from "@tanstack/react-query";
5
+ //#region src/lib/use-action.ts
6
+ /**
7
+ * Run a change against the API, then refetch what it touched. A failed call
8
+ * leaves the page as it was and says why, in `error`.
9
+ *
10
+ * Each change names what it touches (`affects` in `lib/queries.ts`), and
11
+ * those queries are refetched before the change counts as done: at once where
12
+ * they are on screen, such as the sidebar's project tree, and on next use
13
+ * where they are not. So your own change always shows, and nothing else is
14
+ * asked for again.
15
+ */
16
+ function useAction() {
17
+ const queryClient = useQueryClient();
18
+ const [pending, setPending] = useState(false);
19
+ const [error, setError] = useState(null);
20
+ async function run(fn, { affects, onSuccess }) {
21
+ setPending(true);
22
+ let result;
23
+ try {
24
+ result = await fn();
25
+ } catch (failure) {
26
+ setError(failureMessage(failure));
27
+ setPending(false);
28
+ return;
29
+ }
30
+ setError(null);
31
+ try {
32
+ await refresh(queryClient, typeof affects === "function" ? affects(result) : affects);
33
+ await onSuccess?.(result);
34
+ } catch {
35
+ setError("The change was saved, but the page could not refresh. Reload before you retry.");
36
+ }
37
+ setPending(false);
38
+ }
39
+ return {
40
+ pending,
41
+ error,
42
+ setError,
43
+ run
44
+ };
45
+ }
46
+ //#endregion
47
+ export { useAction as t };
48
+
49
+ //# sourceMappingURL=use-action-BRgvbUWt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-action-BRgvbUWt.js","names":[],"sources":["../../src/lib/use-action.ts"],"sourcesContent":["import { useQueryClient, type QueryKey } from '@tanstack/react-query';\nimport { useState } from 'react';\n\nimport { failureMessage } from './coffre';\nimport { refresh } from './queries';\n\n/**\n * Run a change against the API, then refetch what it touched. A failed call\n * leaves the page as it was and says why, in `error`.\n *\n * Each change names what it touches (`affects` in `lib/queries.ts`), and\n * those queries are refetched before the change counts as done: at once where\n * they are on screen, such as the sidebar's project tree, and on next use\n * where they are not. So your own change always shows, and nothing else is\n * asked for again.\n */\nexport function useAction() {\n const queryClient = useQueryClient();\n const [pending, setPending] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n async function run<T>(\n fn: () => Promise<T>,\n {\n affects,\n onSuccess,\n }: {\n affects: QueryKey[] | ((result: T) => QueryKey[]);\n // `unknown` rather than `void`, so a one-expression callback can end in\n // `toast.success(...)` -- which returns an id -- without a block body.\n onSuccess?: (result: T) => unknown;\n },\n ): Promise<void> {\n setPending(true);\n let result: T;\n try {\n result = await fn();\n } catch (failure) {\n setError(failureMessage(failure));\n setPending(false);\n return;\n }\n\n setError(null);\n try {\n await refresh(queryClient, typeof affects === 'function' ? affects(result) : affects);\n await onSuccess?.(result);\n } catch {\n setError('The change was saved, but the page could not refresh. Reload before you retry.');\n }\n setPending(false);\n }\n\n return { pending, error, setError, run };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAgB,YAAY;CAC1B,MAAM,cAAc,eAAe;CACnC,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,CAAC,OAAO,YAAY,SAAwB,IAAI;CAEtD,eAAe,IACb,IACA,EACE,SACA,aAOa;EACf,WAAW,IAAI;EACf,IAAI;EACJ,IAAI;GACF,SAAS,MAAM,GAAG;EACpB,SAAS,SAAS;GAChB,SAAS,eAAe,OAAO,CAAC;GAChC,WAAW,KAAK;GAChB;EACF;EAEA,SAAS,IAAI;EACb,IAAI;GACF,MAAM,QAAQ,aAAa,OAAO,YAAY,aAAa,QAAQ,MAAM,IAAI,OAAO;GACpF,MAAM,YAAY,MAAM;EAC1B,QAAQ;GACN,SAAS,gFAAgF;EAC3F;EACA,WAAW,KAAK;CAClB;CAEA,OAAO;EAAE;EAAS;EAAO;EAAU;CAAI;AACzC"}
@@ -1,9 +1,9 @@
1
1
  import { a as Refusal, o as failureMessage, s as memberRef } from "./page-DvsgZ2Hd.js";
2
2
  import { o as announce } from "./row-state-DOPUsjQK.js";
3
- import { m as refresh, r as keys, t as affects } from "./queries-Dew8mIeo.js";
3
+ import { _ as refresh, i as keys, t as affects } from "./queries-DE5nK2y4.js";
4
4
  import { useCallback } from "react";
5
+ import { EVERYWHERE, ROLES, unscoped } from "@coffre/core/access";
5
6
  import { useMutation, useMutationState, useQueryClient } from "@tanstack/react-query";
6
- import { ROLES } from "@coffre/core/access";
7
7
  //#region src/lib/project-access.ts
8
8
  function projectAccessOptions(environments) {
9
9
  const options = [{
@@ -43,6 +43,22 @@ function projectAccessLabel(grant) {
43
43
  if (grant.role === "owner") return name;
44
44
  return `${name}: ${grant.environmentSlug ?? "all"}`;
45
45
  }
46
+ /**
47
+ * The Access tab's rows, project by project: a row per grant, and a project
48
+ * whose read failed keeps a row of its own that says why, so a failure
49
+ * never reads as no access.
50
+ */
51
+ function accessRows(access) {
52
+ return access.flatMap(({ project, grants, grantsError }) => grantsError === null ? grants.map((grant) => ({
53
+ project,
54
+ grant,
55
+ error: null
56
+ })) : [{
57
+ project,
58
+ grant: null,
59
+ error: grantsError
60
+ }]);
61
+ }
46
62
  //#endregion
47
63
  //#region src/lib/secret-edit-batch.ts
48
64
  function secretChangeFor(changes, key) {
@@ -199,10 +215,10 @@ var removing = (id) => ({
199
215
  id,
200
216
  kind: "removing"
201
217
  });
202
- /** A grant's identity, before the server has given it an id: who, and where. */
218
+ /** A grant's identity, before the server has given it an id: who, and where; or who, by their instance role. */
203
219
  function grantId(grant) {
204
- const everywhere = grant.scope === "every-project" ? "*/" : "";
205
- return `${memberRef(grant.principalType, grant.principalId)}@${everywhere}${grant.environmentSlug ?? ""}`;
220
+ const member = memberRef(grant.principalType, grant.principalId);
221
+ return grant.scope === "instance-role" ? `${member}#role` : `${member}@${grant.environmentSlug ?? ""}`;
206
222
  }
207
223
  function grantsList(project) {
208
224
  return listOf(keys.grants(project), "grants", grantId);
@@ -261,8 +277,15 @@ function revokeGrant(client, project) {
261
277
  };
262
278
  }
263
279
  var principalId = (principal) => memberRef(principal.principalType, principal.principalId);
264
- /** The directory as owners read it: the only ones who change it. */
280
+ /** The directory as admins and owners read it: the only ones who change it. */
265
281
  var directoryList = listOf([...keys.directory, { owner: true }], "principals", principalId);
282
+ /** What the API takes for a role: the scope only when it narrows anything. */
283
+ function roleInput({ role, scope }) {
284
+ return role === "member" || unscoped(scope) ? { role } : {
285
+ role,
286
+ scope
287
+ };
288
+ }
266
289
  function invite(client) {
267
290
  return {
268
291
  list: directoryList,
@@ -271,7 +294,8 @@ function invite(client) {
271
294
  apply: (principals, vars) => principals.some((principal) => principalId(principal) === principalId(vars)) ? principals : [...principals, {
272
295
  principalType: vars.principalType,
273
296
  principalId: vars.principalId,
274
- instanceRole: vars.owner ? "owner" : "user",
297
+ instanceRole: vars.principalType === "user" ? vars.role : "member",
298
+ scope: vars.principalType === "user" ? vars.scope : EVERYWHERE,
275
299
  isRootAdmin: false
276
300
  }],
277
301
  affects: () => affects.admission(),
@@ -279,7 +303,7 @@ function invite(client) {
279
303
  const member = memberRef(vars.principalType, vars.principalId);
280
304
  const { members } = await client.members.list();
281
305
  if (members.some((entry) => entry.member === member)) throw new Refusal("That principal already exists.");
282
- await client.members.add(member, { owner: vars.principalType === "user" && vars.owner });
306
+ await client.members.add(member, vars.principalType === "user" ? roleInput(vars) : {});
283
307
  }
284
308
  };
285
309
  }
@@ -291,10 +315,11 @@ function changeRole(client) {
291
315
  targets: (vars) => [saving(id(vars))],
292
316
  apply: (principals, vars) => principals.map((principal) => principalId(principal) === id(vars) ? {
293
317
  ...principal,
294
- instanceRole: vars.owner ? "owner" : "user"
318
+ instanceRole: vars.role,
319
+ scope: vars.scope
295
320
  } : principal),
296
321
  affects: (vars) => affects.role(id(vars)),
297
- run: (vars) => client.members.add(id(vars), { owner: vars.owner })
322
+ run: (vars) => client.members.add(id(vars), roleInput(vars))
298
323
  };
299
324
  }
300
325
  function removeMember(client) {
@@ -405,9 +430,10 @@ function createProject(client) {
405
430
  archivedAt: null,
406
431
  folder: null,
407
432
  permissions: [
408
- "project.manage",
433
+ "audit.read",
409
434
  "environment.manage",
410
- "grant.manage"
435
+ "grant.manage",
436
+ "project.manage"
411
437
  ],
412
438
  environments: [],
413
439
  secretCount: null
@@ -813,6 +839,6 @@ function useChangeStatus(list) {
813
839
  };
814
840
  }
815
841
  //#endregion
816
- export { projectAccessLabel as A, revokeCredential as C, hasSecretEditConflict as D, unlinkIdentity as E, secretChangeFor as O, restoreSecret as S, saveSecrets as T, moveSecret as _, archiveSecret as a, removeMember as b, createProject as c, disconnectMemberApp as d, endSession as f, invite as g, grantId as h, archiveEnvironment as i, projectAccessOptions as j, parseProjectAccess as k, directoryList as l, grantAccess as m, useChangeStatus as n, changeRole as o, environmentId as p, UnsavedEdits as r, createEnvironment as s, useChange as t, disconnectApp as u, projectsList as v, revokeGrant as w, renameEnvironment as x, removeBinding as y };
842
+ export { parseProjectAccess as A, revokeCredential as C, hasSecretEditConflict as D, unlinkIdentity as E, projectAccessOptions as M, secretChangeFor as O, restoreSecret as S, saveSecrets as T, moveSecret as _, archiveSecret as a, removeMember as b, createProject as c, disconnectMemberApp as d, endSession as f, invite as g, grantId as h, archiveEnvironment as i, projectAccessLabel as j, accessRows as k, directoryList as l, grantAccess as m, useChangeStatus as n, changeRole as o, environmentId as p, UnsavedEdits as r, createEnvironment as s, useChange as t, disconnectApp as u, projectsList as v, revokeGrant as w, renameEnvironment as x, removeBinding as y };
817
843
 
818
- //# sourceMappingURL=use-change-C4bGRhHY.js.map
844
+ //# sourceMappingURL=use-change-BJ3dCFHb.js.map