@coffre/ui 0.5.1 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/dist/chunks/{affordances-Bqdevf7w.js → affordances-Dtyha68j.js} +11 -3
  2. package/dist/chunks/affordances-Dtyha68j.js.map +1 -0
  3. package/dist/chunks/{audit-sentence-Cm5nby5k.js → audit-sentence-CUUMshIp.js} +22 -6
  4. package/dist/chunks/audit-sentence-CUUMshIp.js.map +1 -0
  5. package/dist/chunks/{connected-apps-DTNS7YmY.js → connected-apps-DTpatjge.js} +5 -5
  6. package/dist/chunks/{connected-apps-DTNS7YmY.js.map → connected-apps-DTpatjge.js.map} +1 -1
  7. package/dist/chunks/{delete-place-CIaOq0mt.js → delete-place-SOOYVt6A.js} +5 -5
  8. package/dist/chunks/{delete-place-CIaOq0mt.js.map → delete-place-SOOYVt6A.js.map} +1 -1
  9. package/dist/chunks/{directory-DSVt5Tya.js → directory-DrtdKny2.js} +60 -37
  10. package/dist/chunks/directory-DrtdKny2.js.map +1 -0
  11. package/dist/chunks/{folders-CoGK9oqg.js → folders-hR2Lnk0k.js} +3 -3
  12. package/dist/chunks/{folders-CoGK9oqg.js.map → folders-hR2Lnk0k.js.map} +1 -1
  13. package/dist/chunks/{grants-CRU7yZhL.js → grants-DDBui9YD.js} +6 -6
  14. package/dist/chunks/{grants-CRU7yZhL.js.map → grants-DDBui9YD.js.map} +1 -1
  15. package/dist/chunks/{offboarding-DVBSiJRZ.js → offboarding-C7ECW5o0.js} +5 -5
  16. package/dist/chunks/{offboarding-DVBSiJRZ.js.map → offboarding-C7ECW5o0.js.map} +1 -1
  17. package/dist/chunks/{page-DvsgZ2Hd.js → page-JTORvh-N.js} +7 -3
  18. package/dist/chunks/page-JTORvh-N.js.map +1 -0
  19. package/dist/chunks/{principal-BIN-xwZw.js → principal-DFBswTBr.js} +2 -2
  20. package/dist/chunks/{principal-BIN-xwZw.js.map → principal-DFBswTBr.js.map} +1 -1
  21. package/dist/chunks/{principal-page-BEBr_zW7.js → principal-page-CB6dAABC.js} +17 -19
  22. package/dist/chunks/principal-page-CB6dAABC.js.map +1 -0
  23. package/dist/chunks/{project-page-B3TZ5_ig.js → project-page-BHNUvr2L.js} +3 -3
  24. package/dist/chunks/{project-page-B3TZ5_ig.js.map → project-page-BHNUvr2L.js.map} +1 -1
  25. package/dist/chunks/{queries-DE5nK2y4.js → queries-DgQo3mC-.js} +27 -12
  26. package/dist/chunks/queries-DgQo3mC-.js.map +1 -0
  27. package/dist/chunks/{references-uv4Mli9z.js → references-BQc35Q9g.js} +5 -5
  28. package/dist/chunks/{references-uv4Mli9z.js.map → references-BQc35Q9g.js.map} +1 -1
  29. package/dist/chunks/{role-field-DWhkRY6n.js → role-field-BfWRCqzl.js} +14 -7
  30. package/dist/chunks/role-field-BfWRCqzl.js.map +1 -0
  31. package/dist/chunks/{row-state-DOPUsjQK.js → row-state-Zf3kZVhd.js} +13 -5
  32. package/dist/chunks/row-state-Zf3kZVhd.js.map +1 -0
  33. package/dist/chunks/{signin-errors--ykMFuqN.js → signin-errors-TlQmQe0t.js} +2 -2
  34. package/dist/chunks/signin-errors-TlQmQe0t.js.map +1 -0
  35. package/dist/chunks/{theme-DJuz-xLM.js → theme-B6-V9JvY.js} +3 -3
  36. package/dist/chunks/{theme-DJuz-xLM.js.map → theme-B6-V9JvY.js.map} +1 -1
  37. package/dist/chunks/{ui-DJje3gST.js → ui-Br-dNUTc.js} +2 -2
  38. package/dist/chunks/{ui-DJje3gST.js.map → ui-Br-dNUTc.js.map} +1 -1
  39. package/dist/chunks/{use-action-BRgvbUWt.js → use-action-DthL5hL8.js} +3 -3
  40. package/dist/chunks/{use-action-BRgvbUWt.js.map → use-action-DthL5hL8.js.map} +1 -1
  41. package/dist/chunks/{use-change-BJ3dCFHb.js → use-change-By4cG8bT.js} +31 -19
  42. package/dist/chunks/use-change-By4cG8bT.js.map +1 -0
  43. package/dist/chunks/{use-shell-BO4ZTr1y.js → use-shell-D6kjSPls.js} +3 -3
  44. package/dist/chunks/{use-shell-BO4ZTr1y.js.map → use-shell-D6kjSPls.js.map} +1 -1
  45. package/dist/index.d.ts +6 -7
  46. package/dist/index.js +8 -9
  47. package/dist/index.js.map +1 -1
  48. package/dist/pages/account.js +12 -13
  49. package/dist/pages/account.js.map +1 -1
  50. package/dist/pages/approval.js +2 -2
  51. package/dist/pages/audit.js +5 -5
  52. package/dist/pages/audit.js.map +1 -1
  53. package/dist/pages/device-login.js +2 -2
  54. package/dist/pages/environment.js +837 -155
  55. package/dist/pages/environment.js.map +1 -1
  56. package/dist/pages/login.js +4 -4
  57. package/dist/pages/oauth-authorize.js +2 -2
  58. package/dist/pages/project-access.js +160 -80
  59. package/dist/pages/project-access.js.map +1 -1
  60. package/dist/pages/project-environments.js +10 -10
  61. package/dist/pages/project-settings.js +8 -8
  62. package/dist/pages/project.js +3 -3
  63. package/dist/pages/projects.js +10 -10
  64. package/dist/pages/projects.js.map +1 -1
  65. package/dist/pages/service-account.js +537 -109
  66. package/dist/pages/service-account.js.map +1 -1
  67. package/dist/pages/service-accounts.js +5 -5
  68. package/dist/pages/settings.js +8 -18
  69. package/dist/pages/settings.js.map +1 -1
  70. package/dist/pages/unregistered.js +3 -3
  71. package/dist/pages/unregistered.js.map +1 -1
  72. package/dist/pages/user.js +6 -6
  73. package/dist/pages/users.js +5 -5
  74. package/package.json +3 -3
  75. package/src/components/affordances.ts +13 -1
  76. package/src/components/directory.tsx +50 -36
  77. package/src/components/generate-value.tsx +362 -0
  78. package/src/components/github-picker.tsx +83 -0
  79. package/src/components/icons.tsx +4 -0
  80. package/src/components/masked.tsx +60 -0
  81. package/src/components/missing.tsx +3 -3
  82. package/src/components/multi-combobox.tsx +94 -0
  83. package/src/components/principal-page.tsx +8 -12
  84. package/src/components/principal-picker.tsx +68 -18
  85. package/src/components/role-field.tsx +7 -5
  86. package/src/components/row-state.tsx +7 -3
  87. package/src/components/shell.tsx +0 -1
  88. package/src/components/trusted-workloads.tsx +157 -62
  89. package/src/lib/audit-sentences.ts +25 -3
  90. package/src/lib/bindings.ts +125 -14
  91. package/src/lib/capabilities.ts +15 -9
  92. package/src/lib/changes.ts +15 -9
  93. package/src/lib/coffre.ts +2 -0
  94. package/src/lib/generate.ts +160 -0
  95. package/src/lib/queries.ts +19 -5
  96. package/src/lib/secret-edit-batch.ts +38 -5
  97. package/src/lib/secret-order.ts +23 -0
  98. package/src/lib/shortcuts.ts +9 -0
  99. package/src/lib/signin-errors.ts +1 -1
  100. package/src/lib/use-github-lookup.ts +70 -0
  101. package/src/pages/account.tsx +1 -2
  102. package/src/pages/audit.tsx +1 -1
  103. package/src/pages/environment.tsx +241 -119
  104. package/src/pages/project-access.tsx +19 -8
  105. package/src/pages/projects.tsx +3 -3
  106. package/src/pages/settings.tsx +0 -10
  107. package/src/pages/unregistered.tsx +1 -1
  108. package/src/parity.ts +3 -1
  109. package/src/shared/models.ts +2 -2
  110. package/src/styles/globals.css +303 -19
  111. package/dist/chunks/affordances-Bqdevf7w.js.map +0 -1
  112. package/dist/chunks/audit-sentence-Cm5nby5k.js.map +0 -1
  113. package/dist/chunks/directory-DSVt5Tya.js.map +0 -1
  114. package/dist/chunks/page-DvsgZ2Hd.js.map +0 -1
  115. package/dist/chunks/principal-page-BEBr_zW7.js.map +0 -1
  116. package/dist/chunks/queries-DE5nK2y4.js.map +0 -1
  117. package/dist/chunks/role-field-DWhkRY6n.js.map +0 -1
  118. package/dist/chunks/row-state-DOPUsjQK.js.map +0 -1
  119. package/dist/chunks/signin-errors--ykMFuqN.js.map +0 -1
  120. package/dist/chunks/use-change-BJ3dCFHb.js.map +0 -1
@@ -1,17 +1,20 @@
1
- import { a as ErrorLine, c as Notice, i as EmptyState, l as Spinner, r as CopyButton, s as Modal, t as ConfirmButton, u as Timestamp } from "../chunks/ui-DJje3gST.js";
2
- import { A as Key, E as GitHub, N as Link, U as Plus, it as X, s as memberRef, t as Card, u as useCoffre } from "../chunks/page-DvsgZ2Hd.js";
3
- import { a as rowClass, i as RowPending, r as RowFailure } from "../chunks/row-state-DOPUsjQK.js";
4
- import { a as listsAccess, g as queries, t as affects, y as signInWays } from "../chunks/queries-DE5nK2y4.js";
5
- import { t as useShell } from "../chunks/use-shell-BO4ZTr1y.js";
6
- import { C as revokeCredential, n as useChangeStatus, t as useChange, y as removeBinding } from "../chunks/use-change-BJ3dCFHb.js";
1
+ import { a as ErrorLine, c as Notice, i as EmptyState, l as Spinner, r as CopyButton, s as Modal, t as ConfirmButton, u as Timestamp, y as usePreferences } from "../chunks/ui-Br-dNUTc.js";
2
+ import { F as Link, G as Plus, M as Key, O as GitHub, _ as Check, c as statusOf, s as memberRef, st as X, t as Card, u as useCoffre, v as CheckCircle } from "../chunks/page-JTORvh-N.js";
3
+ import { a as rowClass, i as RowPending, r as RowFailure } from "../chunks/row-state-Zf3kZVhd.js";
4
+ import { a as listsAccess, g as queries, t as affects, y as signInWays } from "../chunks/queries-DgQo3mC-.js";
5
+ import { t as useShell } from "../chunks/use-shell-D6kjSPls.js";
6
+ import { C as revokeCredential, n as useChangeStatus, t as useChange, y as removeBinding } from "../chunks/use-change-By4cG8bT.js";
7
7
  import { t as pageRoute } from "../chunks/page-route-Drfw7lmn.js";
8
- import { t as useAction } from "../chunks/use-action-BRgvbUWt.js";
9
- import { n as PrincipalLayout, r as ActionsLog, t as PrincipalAccess } from "../chunks/principal-page-BEBr_zW7.js";
10
- import { Fragment, useState } from "react";
8
+ import { t as useAction } from "../chunks/use-action-DthL5hL8.js";
9
+ import { n as PrincipalLayout, r as ActionsLog, t as PrincipalAccess } from "../chunks/principal-page-CB6dAABC.js";
10
+ import { Fragment, useEffect, useId, useState } from "react";
11
11
  import { ROLES, ROLE_NAMES, assignableToEnvironment, credentialScopeInWords } from "@coffre/core/access";
12
+ import { Autocomplete } from "@base-ui/react/autocomplete";
12
13
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
13
- import { useSuspenseQuery } from "@tanstack/react-query";
14
+ import { useQuery, useSuspenseQuery } from "@tanstack/react-query";
15
+ import { CoffreError } from "@coffre/client";
14
16
  import { EVENT_EXPOSURE, GITLAB_PIPELINE_SOURCES, claimValues, fullRef, githubEventsAt, githubReusable, githubWorkflow, gitlabProject } from "@coffre/core/workloads";
17
+ import { Combobox } from "@base-ui/react/combobox";
15
18
  //#region src/components/scope-picker.tsx
16
19
  var pathOf = (grant) => grant.environment === null ? grant.project : `${grant.project}/${grant.environment}`;
17
20
  /** Everything the account holds, each grant as it is: what a new token or binding reaches unless narrowed. */
@@ -382,11 +385,12 @@ function summary(binding) {
382
385
  const events = claimValues(binding.claims.event_name).join(", ");
383
386
  const short = (ref) => ref?.replace(/^refs\/(heads|tags)\//, "") ?? "";
384
387
  const [workflow, at] = (claims.workflow_ref ?? "").split("@");
388
+ const environment = claims.environment === void 0 ? "" : `, in environment ${claims.environment}`;
385
389
  if (binding.profile === "github") {
386
390
  const [owner, repository, , , file] = (workflow ?? "").split("/");
387
391
  return {
388
392
  title: `${owner}/${repository} · ${file}`,
389
- detail: `${events} at ${short(at)}`
393
+ detail: `${events} at ${short(at)}${environment}`
390
394
  };
391
395
  }
392
396
  if (binding.profile.startsWith("github-reusable")) {
@@ -394,7 +398,7 @@ function summary(binding) {
394
398
  const from = binding.profile === "github-reusable-organization" ? "any repository of the organization" : `repository ${claims.repository_id}`;
395
399
  return {
396
400
  title: `${called} @ ${claims.job_workflow_sha?.slice(0, 7)}`,
397
- detail: `${events} at ${short(claims.ref)}, from ${from}`
401
+ detail: `${events} at ${short(claims.ref)}, from ${from}${environment}`
398
402
  };
399
403
  }
400
404
  if (binding.profile === "gitlab") return {
@@ -422,9 +426,12 @@ var EMPTY_FORM = {
422
426
  label: "",
423
427
  reusable: false,
424
428
  repository: "",
429
+ owner: "",
430
+ typedIds: false,
425
431
  repositoryId: "",
426
432
  ownerId: "",
427
433
  workflow: "",
434
+ environment: "",
428
435
  events: ["push"],
429
436
  refKind: "branch",
430
437
  refName: "main",
@@ -440,8 +447,84 @@ var EMPTY_FORM = {
440
447
  sub: "",
441
448
  extra: ""
442
449
  };
443
- /** The binding the form describes, or why it does not describe one yet. The server checks the rest. */
444
- function bindingOf(form) {
450
+ /** What a GitHub App's listing tells of names' IDs: each repository's, and its owner's, once each. */
451
+ function listedIds(repositories) {
452
+ const owners = new Map(repositories.map(({ github, ownerId }) => [github.split("/")[0], ownerId]));
453
+ return [...repositories.map(({ github, repositoryId, ownerId }) => ({
454
+ github,
455
+ repositoryId,
456
+ ownerId
457
+ })), ...[...owners].map(([github, ownerId]) => ({
458
+ github,
459
+ ownerId
460
+ }))];
461
+ }
462
+ /**
463
+ * What a GitHub App's listing lacks, as the dialog says it under the field:
464
+ * it stopped short (`partial`), which comes first since an empty partial
465
+ * list may only lack what it did not reach; or, whole, the app is installed
466
+ * on no account, or, for a repository, reaches none of theirs.
467
+ */
468
+ function listingGap(listed, owner) {
469
+ if (listed.truncated) return "partial";
470
+ if (listed.installations.length === 0) return "not_installed";
471
+ return !owner && listed.repositories.length === 0 ? "no_repositories" : null;
472
+ }
473
+ /** Who the GitHub form names: a repository, or for a reusable workflow called from any of its repositories, an owner. */
474
+ function githubTarget(form) {
475
+ return form.reusable && form.anyRepository ? {
476
+ kind: "owner",
477
+ name: form.owner.trim()
478
+ } : {
479
+ kind: "repository",
480
+ name: form.repository.trim()
481
+ };
482
+ }
483
+ var GITHUB_NAME = {
484
+ repository: /^[A-Za-z0-9-]{1,39}\/[A-Za-z0-9._-]{1,100}$/,
485
+ owner: /^[A-Za-z0-9-]{1,39}$/
486
+ };
487
+ /** Whether a name is one GitHub could know: `acme/api` for a repository, `acme` for an owner; not `acme/` while it is typed. */
488
+ function lookupable(target) {
489
+ return GITHUB_NAME[target.kind].test(target.name);
490
+ }
491
+ /** How the dialog remembers a lookup, by name in any case: GitHub's names are case-insensitive. */
492
+ var lookupKey = (name) => name.trim().toLowerCase();
493
+ /** What the page knows of the name the form names: nothing yet, or nothing to ask while it reads as no name. */
494
+ function lookupOf(known, target) {
495
+ return lookupable(target) ? known.get(lookupKey(target.name)) ?? null : null;
496
+ }
497
+ /**
498
+ * The lookups with one more answer. IDs found always stand. Anything else
499
+ * replaces only the lookup under way for that name: a failure arriving after
500
+ * the name was found otherwise, as a repository's owner, changes nothing.
501
+ */
502
+ function answered(known, name, answer) {
503
+ const key = lookupKey(name);
504
+ if (answer.state !== "found" && answer.state !== "looking" && known.get(key)?.state !== "looking") return known;
505
+ return new Map(known).set(key, answer);
506
+ }
507
+ /** A lookup that failed, as the dialog says it. */
508
+ function lookupFailure(name, failure) {
509
+ if (failure instanceof CoffreError && failure.status === 404) return {
510
+ state: "missing",
511
+ message: failure.reason === "not_installed" ? failure.message : `GitHub shows nothing public at ${name}.`
512
+ };
513
+ if (failure instanceof CoffreError && failure.status === 429) return {
514
+ state: "failed",
515
+ message: "GitHub's hourly limit on lookups without signing in is spent. Enter the IDs, or try again later."
516
+ };
517
+ return {
518
+ state: "failed",
519
+ message: failure instanceof Error ? failure.message : "GitHub could not be asked."
520
+ };
521
+ }
522
+ /**
523
+ * The binding the form describes, or why it does not describe one yet. The
524
+ * server checks the rest. A GitHub binding takes its IDs, and its
525
+ * repository's name as GitHub spells it, from `found`, unless typed in.
526
+ */
527
+ function bindingOf(form, found = null) {
445
528
  const needed = (value, what) => {
446
529
  if (value.trim() === "") throw new Error(`${what} is needed`);
447
530
  return value.trim();
@@ -451,36 +534,60 @@ function bindingOf(form) {
451
534
  return values;
452
535
  };
453
536
  if (form.platform === "github") {
537
+ const target = githubTarget(form);
538
+ const what = target.kind === "owner" ? "The organization" : "The repository";
539
+ needed(target.name, what);
540
+ const ids = form.typedIds ? {
541
+ github: target.name,
542
+ ...target.kind === "repository" ? { repositoryId: needed(form.repositoryId, "The repository's ID") } : {},
543
+ ownerId: needed(form.ownerId, "The owner's ID")
544
+ } : found !== null && lookupKey(found.github) === lookupKey(target.name) ? found : null;
545
+ if (ids === null) throw new Error(`${what}'s IDs are needed: wait for GitHub to find ${target.name}, or enter them`);
454
546
  const ref = fullRef(form.refKind, needed(form.refName, form.refKind === "branch" ? "The branch" : "The tag"));
547
+ const environment = form.environment.trim() === "" ? void 0 : form.environment.trim();
548
+ const events = some(form.events, "event");
455
549
  if (form.reusable) {
456
550
  const called = needed(form.called, "The called workflow");
457
551
  const sha = needed(form.sha, "The called workflow's commit");
458
- const ownerId = needed(form.ownerId, "The owner's ID");
552
+ if (form.anyRepository) return {
553
+ ...githubReusable({
554
+ repositoryId: null,
555
+ ownerId: ids.ownerId,
556
+ ref,
557
+ events,
558
+ called,
559
+ sha,
560
+ environment
561
+ }),
562
+ issuer: null
563
+ };
459
564
  const caller = form.workflow.trim() === "" ? void 0 : {
460
- repository: needed(form.repository, "The repository"),
565
+ repository: ids.github,
461
566
  workflow: form.workflow.trim()
462
567
  };
463
568
  return {
464
569
  ...githubReusable({
465
- repositoryId: form.anyRepository ? null : needed(form.repositoryId, "The repository's ID"),
466
- ownerId,
570
+ repositoryId: needed(ids.repositoryId ?? "", "The repository's ID"),
571
+ ownerId: ids.ownerId,
467
572
  ref,
468
- events: some(form.events, "event"),
573
+ events,
469
574
  called,
470
575
  sha,
471
- caller
576
+ caller,
577
+ environment
472
578
  }),
473
579
  issuer: null
474
580
  };
475
581
  }
476
582
  return {
477
583
  ...githubWorkflow({
478
- repository: needed(form.repository, "The repository"),
479
- repositoryId: needed(form.repositoryId, "The repository's ID"),
480
- ownerId: needed(form.ownerId, "The owner's ID"),
584
+ repository: ids.github,
585
+ repositoryId: needed(ids.repositoryId ?? "", "The repository's ID"),
586
+ ownerId: ids.ownerId,
481
587
  workflow: needed(form.workflow, "The workflow file"),
482
588
  ref,
483
- events: some(form.events, "event")
589
+ events,
590
+ environment
484
591
  }),
485
592
  issuer: null
486
593
  };
@@ -507,6 +614,227 @@ function bindingOf(form) {
507
614
  claims
508
615
  };
509
616
  }
617
+ /**
618
+ * A GitHub repository's or owner's IDs, looked up through coffre once its
619
+ * name has rested in the field for `LOOKUP_PAUSE_MS`, or at once when the
620
+ * field loses focus (`settle`). GitHub answers 60 lookups an hour to a
621
+ * server that does not sign in, shared by everyone a Workers deployment
622
+ * serves, so each name is asked once for as long as the page lives, whatever
623
+ * its case. Nothing public there is final; no answer, such as when the
624
+ * hour's are spent, is asked again on the next `settle`.
625
+ *
626
+ * `remember` records IDs known otherwise, so that they are never asked for:
627
+ * a repository's owner, once the repository is found, or what a picker
628
+ * knows of the repositories it lists.
629
+ */
630
+ function useGitHubLookup(target) {
631
+ const coffre = useCoffre();
632
+ const [known, setKnown] = useState(/* @__PURE__ */ new Map());
633
+ const key = lookupKey(target.name);
634
+ const valid = lookupable(target);
635
+ const lookup = lookupOf(known, target);
636
+ const record = (name, answer) => setKnown((current) => answered(current, name, answer));
637
+ /** IDs found stand whatever was asked before (`answered`): all of them in one change, however many a picker lists. */
638
+ function remember(...found) {
639
+ setKnown((current) => {
640
+ const next = new Map(current);
641
+ for (const ids of found) next.set(lookupKey(ids.github), {
642
+ state: "found",
643
+ ids
644
+ });
645
+ return next;
646
+ });
647
+ }
648
+ function ask(name) {
649
+ record(name, { state: "looking" });
650
+ coffre.bindings.lookup({ github: name }).then((ids) => {
651
+ if (!("github" in ids)) return;
652
+ remember(ids);
653
+ if ("repositoryId" in ids) remember({
654
+ github: ids.github.split("/")[0],
655
+ ownerId: ids.ownerId
656
+ });
657
+ }, (failure) => record(name, lookupFailure(name, failure)));
658
+ }
659
+ useEffect(() => {
660
+ if (!valid || lookup !== null) return;
661
+ const timer = setTimeout(() => ask(target.name), 700);
662
+ return () => clearTimeout(timer);
663
+ }, [
664
+ key,
665
+ valid,
666
+ lookup === null
667
+ ]);
668
+ return {
669
+ lookup,
670
+ settle: () => {
671
+ if (valid && (lookup === null || lookup.state === "failed")) ask(target.name);
672
+ },
673
+ remember
674
+ };
675
+ }
676
+ //#endregion
677
+ //#region src/components/github-picker.tsx
678
+ /** The most the list shows at once: typing narrows it. */
679
+ var LIMIT = 50;
680
+ /**
681
+ * The Trust dialog's repository or organization field, offering what the
682
+ * deployment's GitHub App is installed on as the name is typed. It stays a
683
+ * text field: a name the list lacks is typed whole, and looked up as
684
+ * without the app. With nothing to offer (`options` null: no app, or its
685
+ * list not there yet) its list never opens, and it is the same input
686
+ * either way, so that the list arriving mid-word moves neither focus nor
687
+ * caret. Base UI's autocomplete does the keyboard and ARIA: Down Arrow
688
+ * opens the list, arrows move through it, Enter takes one, Escape closes
689
+ * it.
690
+ */
691
+ function GitHubPicker({ label, value, onChange, onPick, onBlur, options, placeholder, empty }) {
692
+ const { portal } = usePreferences();
693
+ const id = useId();
694
+ const labelId = useId();
695
+ const [open, setOpen] = useState(false);
696
+ const hidden = new Set((options ?? []).filter((option) => option.private === true).map((option) => option.name));
697
+ return /* @__PURE__ */ jsxs(Autocomplete.Root, {
698
+ items: (options ?? []).map((option) => option.name),
699
+ value,
700
+ onValueChange: (next, details) => details.reason === "item-press" ? onPick(next) : onChange(next),
701
+ open: open && options !== null,
702
+ onOpenChange: setOpen,
703
+ openOnInputClick: true,
704
+ limit: LIMIT,
705
+ children: [/* @__PURE__ */ jsxs("div", {
706
+ className: "field",
707
+ children: [/* @__PURE__ */ jsx("label", {
708
+ className: "label",
709
+ id: labelId,
710
+ htmlFor: id,
711
+ children: label
712
+ }), /* @__PURE__ */ jsx(Autocomplete.Input, {
713
+ id,
714
+ "aria-labelledby": labelId,
715
+ className: "input mono",
716
+ placeholder,
717
+ spellCheck: false,
718
+ onBlur
719
+ })]
720
+ }), /* @__PURE__ */ jsx(Autocomplete.Portal, {
721
+ container: portal,
722
+ children: /* @__PURE__ */ jsx(Autocomplete.Positioner, {
723
+ className: "menu-positioner",
724
+ sideOffset: 4,
725
+ align: "start",
726
+ children: /* @__PURE__ */ jsxs(Autocomplete.Popup, {
727
+ className: "menu combo-popup",
728
+ children: [/* @__PURE__ */ jsx(Autocomplete.Empty, {
729
+ className: "combo-empty",
730
+ children: empty
731
+ }), /* @__PURE__ */ jsx(Autocomplete.List, { children: (name) => /* @__PURE__ */ jsxs(Autocomplete.Item, {
732
+ value: name,
733
+ className: "menu-item mono",
734
+ children: [/* @__PURE__ */ jsx("span", {
735
+ className: "combo-option",
736
+ children: name
737
+ }), hidden.has(name) && /* @__PURE__ */ jsx("span", {
738
+ className: "tag",
739
+ children: "private"
740
+ })]
741
+ }, name) })]
742
+ })
743
+ })
744
+ })]
745
+ });
746
+ }
747
+ //#endregion
748
+ //#region src/components/multi-combobox.tsx
749
+ /**
750
+ * Several of a fixed list, chosen by typing: each chosen one a chip in the
751
+ * field, the rest offered below as the text filters them. Base UI's
752
+ * combobox does the keyboard and ARIA: arrows move through the options,
753
+ * Enter takes one, Backspace in an empty field removes the last chip, and
754
+ * Left Arrow from the start of the field walks the chips.
755
+ *
756
+ * The value keeps the options' order, whatever order they were chosen in.
757
+ */
758
+ function MultiCombobox({ label, options, value, onChange, placeholder, hint, note, mono = false }) {
759
+ const { portal } = usePreferences();
760
+ const id = useId();
761
+ const labelId = useId();
762
+ const hintId = useId();
763
+ return /* @__PURE__ */ jsxs(Combobox.Root, {
764
+ items: options,
765
+ multiple: true,
766
+ value,
767
+ onValueChange: (next) => onChange(options.filter((option) => next.includes(option))),
768
+ children: [/* @__PURE__ */ jsxs("div", {
769
+ className: "field",
770
+ children: [
771
+ /* @__PURE__ */ jsx("label", {
772
+ className: "label",
773
+ htmlFor: id,
774
+ id: labelId,
775
+ children: label
776
+ }),
777
+ /* @__PURE__ */ jsx(Combobox.InputGroup, {
778
+ className: `combo${mono ? " combo-mono" : ""}`,
779
+ children: /* @__PURE__ */ jsxs(Combobox.Chips, {
780
+ className: "combo-chips",
781
+ "aria-label": value.length > 0 ? "Chosen" : void 0,
782
+ children: [value.map((option) => /* @__PURE__ */ jsxs(Combobox.Chip, {
783
+ className: "combo-chip",
784
+ "aria-label": option,
785
+ "aria-description": "Press Backspace or Delete to remove",
786
+ children: [option, /* @__PURE__ */ jsx(Combobox.ChipRemove, {
787
+ className: "combo-chip-remove",
788
+ "aria-label": `Remove ${option}`,
789
+ children: /* @__PURE__ */ jsx(X, { size: 12 })
790
+ })]
791
+ }, option)), /* @__PURE__ */ jsx(Combobox.Input, {
792
+ id,
793
+ "aria-labelledby": labelId,
794
+ className: "combo-input",
795
+ placeholder: value.length > 0 ? void 0 : placeholder,
796
+ "aria-describedby": hint === void 0 ? void 0 : hintId,
797
+ "aria-description": value.length > 0 ? `${value.length} chosen. From the start of the field, press Left Arrow to reach them` : void 0
798
+ })]
799
+ })
800
+ }),
801
+ hint !== void 0 && /* @__PURE__ */ jsx("span", {
802
+ className: "hint",
803
+ id: hintId,
804
+ children: hint
805
+ })
806
+ ]
807
+ }), /* @__PURE__ */ jsx(Combobox.Portal, {
808
+ container: portal,
809
+ children: /* @__PURE__ */ jsx(Combobox.Positioner, {
810
+ className: "menu-positioner",
811
+ sideOffset: 4,
812
+ align: "start",
813
+ children: /* @__PURE__ */ jsxs(Combobox.Popup, {
814
+ className: "menu combo-popup",
815
+ children: [/* @__PURE__ */ jsx(Combobox.Empty, {
816
+ className: "combo-empty",
817
+ children: "Nothing matches."
818
+ }), /* @__PURE__ */ jsx(Combobox.List, { children: (option) => /* @__PURE__ */ jsxs(Combobox.Item, {
819
+ value: option,
820
+ className: `menu-item${mono ? " mono" : ""}`,
821
+ children: [
822
+ /* @__PURE__ */ jsx("span", {
823
+ className: "combo-check",
824
+ children: /* @__PURE__ */ jsx(Combobox.ItemIndicator, { children: /* @__PURE__ */ jsx(Check, { size: 14 }) })
825
+ }),
826
+ /* @__PURE__ */ jsx("span", {
827
+ className: "combo-option",
828
+ children: option
829
+ }),
830
+ note?.(option)
831
+ ]
832
+ }, option) })]
833
+ })
834
+ })
835
+ })]
836
+ });
837
+ }
510
838
  //#endregion
511
839
  //#region src/components/trusted-workloads.tsx
512
840
  /**
@@ -681,33 +1009,88 @@ function Claims({ binding }) {
681
1009
  ] })
682
1010
  });
683
1011
  }
684
- /** Checkboxes for what may start a run: GitHub's events, or GitLab's pipeline sources. */
685
- function Choices(props) {
686
- const { options, chosen } = props;
687
- return /* @__PURE__ */ jsxs("fieldset", {
688
- className: "field checks",
689
- children: [
690
- /* @__PURE__ */ jsx("legend", {
691
- className: "label",
692
- children: props.label
693
- }),
694
- /* @__PURE__ */ jsx("div", {
695
- className: "checks-row",
696
- children: options.map((option) => /* @__PURE__ */ jsxs("label", {
697
- className: "check mono",
698
- children: [/* @__PURE__ */ jsx("input", {
699
- type: "checkbox",
700
- checked: chosen.includes(option),
701
- onChange: (event) => props.onChange(options.filter((each) => each === option ? event.target.checked : chosen.includes(each)))
702
- }), option]
703
- }, option))
704
- }),
705
- props.hint !== void 0 && /* @__PURE__ */ jsx("span", {
706
- className: "hint",
707
- children: props.hint
708
- })
709
- ]
1012
+ /** Beside `pull_request` and `workflow_run` in the events' list: they run code nobody reviewed, said in full once chosen. */
1013
+ function exposureNote(event) {
1014
+ return EVENT_EXPOSURE[event] === void 0 ? null : /* @__PURE__ */ jsx("span", {
1015
+ className: "tag tag-amber",
1016
+ children: "unreviewed code"
1017
+ });
1018
+ }
1019
+ /**
1020
+ * What GitHub said of the repository or owner the form names: who it is,
1021
+ * as confirmation, or why it could not say, with the way to type its IDs.
1022
+ */
1023
+ function GitHubFound({ lookup, kind }) {
1024
+ if (lookup === null) return null;
1025
+ if (lookup.state === "looking") return /* @__PURE__ */ jsxs("p", {
1026
+ className: "lookup",
1027
+ role: "status",
1028
+ children: [/* @__PURE__ */ jsx(Spinner, { size: 13 }), "Looking it up on GitHub…"]
1029
+ });
1030
+ if (lookup.state === "found") {
1031
+ const { github, repositoryId, ownerId } = lookup.ids;
1032
+ return /* @__PURE__ */ jsxs("p", {
1033
+ className: "lookup lookup-found",
1034
+ role: "status",
1035
+ children: [/* @__PURE__ */ jsx(CheckCircle, { size: 14 }), /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("span", {
1036
+ className: "mono lookup-name",
1037
+ children: github
1038
+ }), kind === "repository" ? ` · ID ${repositoryId}, owned by ${github.split("/")[0]} (ID ${ownerId})` : ` · ID ${ownerId}`] })]
1039
+ });
1040
+ }
1041
+ return /* @__PURE__ */ jsx("p", {
1042
+ className: "lookup lookup-failed",
1043
+ role: "status",
1044
+ children: lookup.message
1045
+ });
1046
+ }
1047
+ /**
1048
+ * What the deployment's GitHub App could not list, said under the field (`listingGap`): it
1049
+ * is installed nowhere yet, or reaches no repository, with where to change
1050
+ * that, or GitHub did not answer. Nothing without an app, or while it lists.
1051
+ */
1052
+ function Listing({ listing, owner }) {
1053
+ if (listing.error !== null && listing.error !== void 0) return /* @__PURE__ */ jsxs("p", {
1054
+ className: "hint",
1055
+ children: ["The GitHub App's repositories could not be listed", statusOf(listing.error) === 503 ? `: ${listing.error.message}` : ". Type the name: it is still looked up."]
1056
+ });
1057
+ const listed = listing.data;
1058
+ if (listed === void 0 || !("repositories" in listed)) return null;
1059
+ const install = (words) => /* @__PURE__ */ jsx("a", {
1060
+ href: listed.app.installUrl,
1061
+ target: "_blank",
1062
+ rel: "noreferrer",
1063
+ children: words
710
1064
  });
1065
+ switch (listingGap(listed, owner)) {
1066
+ case "partial": return /* @__PURE__ */ jsxs("p", {
1067
+ className: "hint",
1068
+ children: [
1069
+ "Only some of ",
1070
+ listed.app.name,
1071
+ "'s repositories are listed: type any other by name."
1072
+ ]
1073
+ });
1074
+ case "not_installed": return /* @__PURE__ */ jsxs("p", {
1075
+ className: "hint",
1076
+ children: [
1077
+ listed.app.name,
1078
+ " is installed on no account yet: ",
1079
+ install("install it"),
1080
+ " on yours to pick its repositories here."
1081
+ ]
1082
+ });
1083
+ case "no_repositories": return /* @__PURE__ */ jsxs("p", {
1084
+ className: "hint",
1085
+ children: [
1086
+ listed.app.name,
1087
+ " reaches no repository yet: ",
1088
+ install("choose some"),
1089
+ " to pick them here."
1090
+ ]
1091
+ });
1092
+ case null: return null;
1093
+ }
711
1094
  }
712
1095
  /** What trusting `pull_request` or `workflow_run` exposes, said where the owner chooses it and again before saving. */
713
1096
  function Exposure({ events }) {
@@ -757,6 +1140,20 @@ function TrustWorkload({ serviceId, grants, bindings }) {
757
1140
  const member = memberRef("service", serviceId);
758
1141
  const { pending, error, setError, run } = useAction();
759
1142
  const lookup = useAction();
1143
+ const target = githubTarget(form);
1144
+ const github = useGitHubLookup(form.typedIds ? {
1145
+ ...target,
1146
+ name: ""
1147
+ } : target);
1148
+ const found = github.lookup?.state === "found" ? github.lookup.ids : null;
1149
+ const listing = useQuery({
1150
+ ...queries.githubRepositories(coffre),
1151
+ enabled: open && form.platform === "github"
1152
+ });
1153
+ const listed = listing.data !== void 0 && "repositories" in listing.data ? listing.data : null;
1154
+ useEffect(() => {
1155
+ if (listed !== null) github.remember(...listedIds(listed.repositories));
1156
+ }, [listed]);
760
1157
  const set = (changes) => {
761
1158
  setForm((current) => ({
762
1159
  ...current,
@@ -765,7 +1162,7 @@ function TrustWorkload({ serviceId, grants, bindings }) {
765
1162
  setPlan(null);
766
1163
  };
767
1164
  const input = () => ({
768
- ...bindingOf(form),
1165
+ ...bindingOf(form, found),
769
1166
  ...askedScope(choice),
770
1167
  label: form.label.trim() === "" ? null : form.label.trim(),
771
1168
  replaces: []
@@ -805,7 +1202,9 @@ function TrustWorkload({ serviceId, grants, bindings }) {
805
1202
  className: `input${props.mono ? " mono" : ""}`,
806
1203
  value: form[key],
807
1204
  placeholder: props.placeholder,
808
- onChange: (event) => set({ [key]: event.target.value })
1205
+ spellCheck: props.mono ? false : void 0,
1206
+ onChange: (event) => set({ [key]: event.target.value }),
1207
+ onBlur: props.onBlur
809
1208
  }),
810
1209
  props.hint !== void 0 && /* @__PURE__ */ jsx("span", {
811
1210
  className: "hint",
@@ -813,6 +1212,70 @@ function TrustWorkload({ serviceId, grants, bindings }) {
813
1212
  })
814
1213
  ]
815
1214
  });
1215
+ const owner = target.kind === "owner";
1216
+ const lookedUp = github.lookup;
1217
+ const named = owner ? {
1218
+ label: "Organization",
1219
+ key: "owner",
1220
+ placeholder: "acme"
1221
+ } : {
1222
+ label: "Repository",
1223
+ key: "repository",
1224
+ placeholder: "acme/api"
1225
+ };
1226
+ const githubIds = /* @__PURE__ */ jsxs("div", {
1227
+ className: "lookup-group",
1228
+ children: [
1229
+ /* @__PURE__ */ jsx(GitHubPicker, {
1230
+ label: named.label,
1231
+ value: form[named.key],
1232
+ onChange: (name) => set({ [named.key]: name }),
1233
+ onPick: (name) => set({
1234
+ [named.key]: name,
1235
+ typedIds: false,
1236
+ repositoryId: "",
1237
+ ownerId: ""
1238
+ }),
1239
+ onBlur: github.settle,
1240
+ options: listed === null ? null : owner ? listed.installations.map((name) => ({ name })) : listed.repositories.map((each) => ({
1241
+ name: each.github,
1242
+ private: each.private
1243
+ })),
1244
+ placeholder: named.placeholder,
1245
+ empty: listed === null ? "" : `None of ${listed.app.name}'s ${owner ? "accounts" : "repositories"} match: type the whole name.`
1246
+ }),
1247
+ /* @__PURE__ */ jsx(Listing, {
1248
+ listing,
1249
+ owner
1250
+ }),
1251
+ !form.typedIds && /* @__PURE__ */ jsx(GitHubFound, {
1252
+ lookup: lookedUp,
1253
+ kind: target.kind
1254
+ }),
1255
+ (form.typedIds || lookedUp?.state === "missing" || lookedUp?.state === "failed") && /* @__PURE__ */ jsxs("details", {
1256
+ className: "disclosure",
1257
+ open: form.typedIds,
1258
+ onToggle: (event) => set({ typedIds: event.currentTarget.open }),
1259
+ children: [/* @__PURE__ */ jsx("summary", { children: owner ? "Enter its ID" : "Private repository? Enter IDs" }), /* @__PURE__ */ jsxs("div", {
1260
+ className: "disclosure-body",
1261
+ children: [/* @__PURE__ */ jsxs("div", {
1262
+ className: "form-row",
1263
+ children: [!owner && field("Repository ID", "repositoryId", { mono: true }), field("Owner ID", "ownerId", { mono: true })]
1264
+ }), /* @__PURE__ */ jsxs("p", {
1265
+ className: "hint",
1266
+ children: [
1267
+ "Bindings use IDs, since a name can pass to someone else. Get them with",
1268
+ " ",
1269
+ /* @__PURE__ */ jsx("span", {
1270
+ className: "mono",
1271
+ children: owner ? `gh api users/${target.name || "acme"} --jq .id` : `gh api repos/${target.name || "acme/api"} --jq '.id, .owner.id'`
1272
+ })
1273
+ ]
1274
+ })]
1275
+ })]
1276
+ })
1277
+ ]
1278
+ });
816
1279
  const ref = /* @__PURE__ */ jsxs("div", {
817
1280
  className: "form-row",
818
1281
  children: [/* @__PURE__ */ jsxs("label", {
@@ -886,52 +1349,6 @@ function TrustWorkload({ serviceId, grants, bindings }) {
886
1349
  children: "A reusable workflow"
887
1350
  })]
888
1351
  }),
889
- /* @__PURE__ */ jsxs("div", {
890
- className: "form-row",
891
- children: [field("Repository", "repository", {
892
- placeholder: "acme/api",
893
- mono: true
894
- }), /* @__PURE__ */ jsx("div", {
895
- className: "field",
896
- style: {
897
- flex: "0 0 auto",
898
- alignSelf: "end"
899
- },
900
- children: /* @__PURE__ */ jsxs("button", {
901
- className: "btn",
902
- type: "button",
903
- disabled: lookup.pending || form.repository.trim() === "",
904
- onClick: () => void lookup.run(() => coffre.bindings.lookup({ github: form.repository.trim() }), {
905
- affects: [],
906
- onSuccess: (ids) => "repositoryId" in ids && set({
907
- repositoryId: ids.repositoryId,
908
- ownerId: ids.ownerId
909
- })
910
- }),
911
- children: [lookup.pending && /* @__PURE__ */ jsx(Spinner, {}), "Look up IDs"]
912
- })
913
- })]
914
- }),
915
- /* @__PURE__ */ jsxs("div", {
916
- className: "form-row",
917
- children: [!(form.reusable && form.anyRepository) && field("Repository ID", "repositoryId", { mono: true }), field("Owner ID", "ownerId", { mono: true })]
918
- }),
919
- /* @__PURE__ */ jsxs("p", {
920
- className: "hint",
921
- children: [
922
- "Bindings use IDs, since a name can pass to someone else. For a private repository:",
923
- " ",
924
- /* @__PURE__ */ jsxs("span", {
925
- className: "mono",
926
- children: [
927
- "gh api repos/",
928
- form.repository.trim() || "acme/api",
929
- " --jq '.id, .owner.id'"
930
- ]
931
- })
932
- ]
933
- }),
934
- /* @__PURE__ */ jsx(ErrorLine, { error: lookup.error }),
935
1352
  form.reusable ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
936
1353
  field("Called workflow", "called", {
937
1354
  placeholder: "acme/deploy/.github/workflows/release.yml@refs/heads/main",
@@ -942,11 +1359,6 @@ function TrustWorkload({ serviceId, grants, bindings }) {
942
1359
  mono: true,
943
1360
  hint: "A new version of the workflow needs a new binding."
944
1361
  }),
945
- field("Calling workflow (optional)", "workflow", {
946
- placeholder: "deploy.yml",
947
- mono: true,
948
- hint: "Left out, every workflow of the repository at the ref below may call it."
949
- }),
950
1362
  /* @__PURE__ */ jsxs("label", {
951
1363
  className: "check",
952
1364
  children: [/* @__PURE__ */ jsx("input", {
@@ -954,19 +1366,33 @@ function TrustWorkload({ serviceId, grants, bindings }) {
954
1366
  checked: form.anyRepository,
955
1367
  onChange: (event) => set({ anyRepository: event.target.checked })
956
1368
  }), "Called from any repository of the organization"]
1369
+ }),
1370
+ githubIds,
1371
+ !form.anyRepository && field("Calling workflow (optional)", "workflow", {
1372
+ placeholder: "deploy.yml",
1373
+ mono: true,
1374
+ hint: "Left out, every workflow of the repository at the ref below may call it."
957
1375
  })
958
- ] }) : field("Workflow file", "workflow", {
1376
+ ] }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [githubIds, field("Workflow file", "workflow", {
959
1377
  placeholder: "deploy.yml",
960
1378
  mono: true
961
- }),
1379
+ })] }),
962
1380
  ref,
963
- /* @__PURE__ */ jsx(Choices, {
1381
+ /* @__PURE__ */ jsx(MultiCombobox, {
964
1382
  label: "Events",
965
1383
  options: githubEventsAt(form.refKind),
966
- chosen: form.events,
1384
+ value: form.events,
967
1385
  onChange: (events) => set({ events }),
1386
+ placeholder: "push, workflow_dispatch…",
1387
+ note: exposureNote,
1388
+ mono: true,
968
1389
  hint: form.events.includes("pull_request") ? `A pull request matches by the branch it merges into: ${form.refName.trim() || "main"}.` : void 0
969
1390
  }),
1391
+ field("GitHub environment (optional)", "environment", {
1392
+ placeholder: "production",
1393
+ mono: true,
1394
+ hint: "Only jobs that run in this environment sign in, once its protection rules, such as required reviewers, let them."
1395
+ }),
970
1396
  /* @__PURE__ */ jsx(Exposure, { events: form.events })
971
1397
  ] }),
972
1398
  form.platform === "gitlab" && /* @__PURE__ */ jsxs(Fragment$1, { children: [
@@ -1009,11 +1435,13 @@ function TrustWorkload({ serviceId, grants, bindings }) {
1009
1435
  }),
1010
1436
  /* @__PURE__ */ jsx(ErrorLine, { error: lookup.error }),
1011
1437
  ref,
1012
- /* @__PURE__ */ jsx(Choices, {
1438
+ /* @__PURE__ */ jsx(MultiCombobox, {
1013
1439
  label: "Pipeline sources",
1014
1440
  options: GITLAB_PIPELINE_SOURCES,
1015
- chosen: form.sources,
1441
+ value: form.sources,
1016
1442
  onChange: (sources) => set({ sources }),
1443
+ placeholder: "push, web, schedule",
1444
+ mono: true,
1017
1445
  hint: "Merge-request pipelines are never trusted: they name another project."
1018
1446
  })
1019
1447
  ] }),