@bsv/create-dpp-app 0.0.0-stage → 0.1.0-beta.2

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 (178) hide show
  1. package/LICENSE +203 -0
  2. package/NOTICE +2 -0
  3. package/PATENTS +12 -0
  4. package/README.md +93 -2
  5. package/dist/index.js +125 -0
  6. package/package.json +57 -4
  7. package/template/Dockerfile +37 -0
  8. package/template/README.md +389 -0
  9. package/template/_dockerignore +6 -0
  10. package/template/_env.example +122 -0
  11. package/template/_github/workflows/ci.yml +23 -0
  12. package/template/_gitignore +8 -0
  13. package/template/_prettierrc +6 -0
  14. package/template/apps/api/API.md +119 -0
  15. package/template/apps/api/package.json +39 -0
  16. package/template/apps/api/src/auth.ts +55 -0
  17. package/template/apps/api/src/bound-profiles.ts +590 -0
  18. package/template/apps/api/src/claims.ts +204 -0
  19. package/template/apps/api/src/cli.ts +99 -0
  20. package/template/apps/api/src/config.ts +180 -0
  21. package/template/apps/api/src/custody.ts +358 -0
  22. package/template/apps/api/src/dev-index.ts +120 -0
  23. package/template/apps/api/src/env-file.ts +55 -0
  24. package/template/apps/api/src/env.ts +14 -0
  25. package/template/apps/api/src/epcis/exchange.ts +434 -0
  26. package/template/apps/api/src/epcis/mongo-storage.ts +381 -0
  27. package/template/apps/api/src/epcis/routes.ts +364 -0
  28. package/template/apps/api/src/epcis/sources.ts +142 -0
  29. package/template/apps/api/src/go-live.ts +226 -0
  30. package/template/apps/api/src/http-error.ts +15 -0
  31. package/template/apps/api/src/identifiers.ts +57 -0
  32. package/template/apps/api/src/index-client.ts +261 -0
  33. package/template/apps/api/src/index-projects.ts +53 -0
  34. package/template/apps/api/src/lifecycle-authority.ts +49 -0
  35. package/template/apps/api/src/lifecycle.ts +485 -0
  36. package/template/apps/api/src/main.ts +58 -0
  37. package/template/apps/api/src/parties.ts +68 -0
  38. package/template/apps/api/src/platform.ts +176 -0
  39. package/template/apps/api/src/portability/commands.ts +224 -0
  40. package/template/apps/api/src/portability/export.ts +708 -0
  41. package/template/apps/api/src/portability/package.ts +270 -0
  42. package/template/apps/api/src/portability/restore.ts +863 -0
  43. package/template/apps/api/src/profiles.ts +125 -0
  44. package/template/apps/api/src/reader.ts +265 -0
  45. package/template/apps/api/src/resolver.ts +159 -0
  46. package/template/apps/api/src/sector-examples.ts +390 -0
  47. package/template/apps/api/src/server.ts +613 -0
  48. package/template/apps/api/src/store.ts +426 -0
  49. package/template/apps/api/src/validation-engine.ts +172 -0
  50. package/template/apps/api/src/wallet.ts +359 -0
  51. package/template/apps/api/src/worker.ts +113 -0
  52. package/template/apps/api/src/writer.ts +603 -0
  53. package/template/apps/api/test/bound-http.test.ts +496 -0
  54. package/template/apps/api/test/bound-profiles.test.ts +547 -0
  55. package/template/apps/api/test/config.test.ts +160 -0
  56. package/template/apps/api/test/custody-journal.test.ts +415 -0
  57. package/template/apps/api/test/custody-recovery-profile.test.ts +224 -0
  58. package/template/apps/api/test/custom-profile.test.ts +167 -0
  59. package/template/apps/api/test/env-file.test.ts +53 -0
  60. package/template/apps/api/test/epcis-fixtures.ts +270 -0
  61. package/template/apps/api/test/epcis-http.test.ts +1179 -0
  62. package/template/apps/api/test/epcis-mongo-storage.test.ts +313 -0
  63. package/template/apps/api/test/epcis-separation.test.ts +253 -0
  64. package/template/apps/api/test/epcis-web.test.ts +230 -0
  65. package/template/apps/api/test/exit-exercise.test.ts +1038 -0
  66. package/template/apps/api/test/external-index.test.ts +32 -0
  67. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/background.ttl +33 -0
  68. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/binding.json +141 -0
  69. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/context.jsonld +36 -0
  70. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/product.schema.json +44 -0
  71. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/shapes.ttl +112 -0
  72. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/conflicting-gtin.json +44 -0
  73. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/conflicting-serial.json +44 -0
  74. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/granularity-mismatch.json +44 -0
  75. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/item-gtin-13.json +43 -0
  76. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/item.json +42 -0
  77. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/missing-required-property.json +43 -0
  78. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/model-as-subject.json +44 -0
  79. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/no-passport-identifier.json +43 -0
  80. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/other-product.json +44 -0
  81. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/part-not-dishwasher-safe.json +45 -0
  82. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/altered-artefact.json +19 -0
  83. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/altered-background.ttl +33 -0
  84. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/conflicting-binding.json +141 -0
  85. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/conflicting-second-registration.json +19 -0
  86. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/untrusted-binding.json +13 -0
  87. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/unlisted-context.json +47 -0
  88. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/wrong-binding-digest.json +44 -0
  89. package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/binding.json +88 -0
  90. package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/product.schema.json +25 -0
  91. package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/item.json +26 -0
  92. package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/missing-required-property.json +27 -0
  93. package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/no-passport-identifier.json +27 -0
  94. package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/other-product.json +28 -0
  95. package/template/apps/api/test/go-live.test.ts +179 -0
  96. package/template/apps/api/test/gs1-global-setup.ts +33 -0
  97. package/template/apps/api/test/gs1-test-env.ts +5 -0
  98. package/template/apps/api/test/identifier-host.test.ts +256 -0
  99. package/template/apps/api/test/index-projects.test.ts +81 -0
  100. package/template/apps/api/test/lifecycle-claims.test.ts +546 -0
  101. package/template/apps/api/test/lifecycle-fixtures.ts +167 -0
  102. package/template/apps/api/test/lifecycle.test.ts +147 -0
  103. package/template/apps/api/test/manifest-notice.test.ts +36 -0
  104. package/template/apps/api/test/network-guard.ts +113 -0
  105. package/template/apps/api/test/portability.test.ts +655 -0
  106. package/template/apps/api/test/profile-bundle-resolver.test.ts +198 -0
  107. package/template/apps/api/test/retired-profiles.test.ts +216 -0
  108. package/template/apps/api/test/sector-cutover.test.ts +95 -0
  109. package/template/apps/api/test/sector-forms.test.ts +420 -0
  110. package/template/apps/api/test/unjoined-index.test.ts +62 -0
  111. package/template/apps/api/test/validation-engine.test.ts +328 -0
  112. package/template/apps/api/test/wallet-monitor.test.ts +38 -0
  113. package/template/apps/api/test/writer-journal.test.ts +327 -0
  114. package/template/apps/api/tsconfig.json +9 -0
  115. package/template/apps/api/vitest.config.ts +12 -0
  116. package/template/apps/web/components.json +21 -0
  117. package/template/apps/web/index.html +12 -0
  118. package/template/apps/web/package.json +33 -0
  119. package/template/apps/web/src/app.tsx +55 -0
  120. package/template/apps/web/src/components/bits.tsx +188 -0
  121. package/template/apps/web/src/components/bound/bound-passport-form.tsx +368 -0
  122. package/template/apps/web/src/components/bound/field-view.tsx +237 -0
  123. package/template/apps/web/src/components/bound/pieces.tsx +169 -0
  124. package/template/apps/web/src/components/bound/readings.tsx +152 -0
  125. package/template/apps/web/src/components/bound/structured-value.tsx +114 -0
  126. package/template/apps/web/src/components/claim-dialog.tsx +344 -0
  127. package/template/apps/web/src/components/epcis-events.tsx +119 -0
  128. package/template/apps/web/src/components/layout.tsx +135 -0
  129. package/template/apps/web/src/components/lifecycle-claims.tsx +199 -0
  130. package/template/apps/web/src/components/passport-form.tsx +244 -0
  131. package/template/apps/web/src/components/read-passport.tsx +49 -0
  132. package/template/apps/web/src/components/reading.tsx +150 -0
  133. package/template/apps/web/src/components/ui/alert.tsx +65 -0
  134. package/template/apps/web/src/components/ui/badge.tsx +47 -0
  135. package/template/apps/web/src/components/ui/button.tsx +63 -0
  136. package/template/apps/web/src/components/ui/card.tsx +91 -0
  137. package/template/apps/web/src/components/ui/dialog.tsx +156 -0
  138. package/template/apps/web/src/components/ui/input.tsx +20 -0
  139. package/template/apps/web/src/components/ui/label.tsx +21 -0
  140. package/template/apps/web/src/components/ui/select.tsx +189 -0
  141. package/template/apps/web/src/components/ui/separator.tsx +25 -0
  142. package/template/apps/web/src/components/ui/table.tsx +115 -0
  143. package/template/apps/web/src/components/ui/tabs.tsx +90 -0
  144. package/template/apps/web/src/components/ui/textarea.tsx +17 -0
  145. package/template/apps/web/src/index.css +81 -0
  146. package/template/apps/web/src/lib/api.ts +396 -0
  147. package/template/apps/web/src/lib/auth.ts +10 -0
  148. package/template/apps/web/src/lib/bound/battery-form.ts +269 -0
  149. package/template/apps/web/src/lib/bound/display.ts +122 -0
  150. package/template/apps/web/src/lib/bound/fields.ts +128 -0
  151. package/template/apps/web/src/lib/bound/form-model.ts +521 -0
  152. package/template/apps/web/src/lib/bound/forms.ts +15 -0
  153. package/template/apps/web/src/lib/bound/identity.ts +48 -0
  154. package/template/apps/web/src/lib/bound/textile-form.ts +236 -0
  155. package/template/apps/web/src/lib/bound/units.ts +37 -0
  156. package/template/apps/web/src/lib/epcis.ts +345 -0
  157. package/template/apps/web/src/lib/format.ts +87 -0
  158. package/template/apps/web/src/lib/lifecycle.ts +350 -0
  159. package/template/apps/web/src/lib/session.tsx +92 -0
  160. package/template/apps/web/src/lib/use-load.ts +46 -0
  161. package/template/apps/web/src/main.tsx +18 -0
  162. package/template/apps/web/src/pages/accept.tsx +113 -0
  163. package/template/apps/web/src/pages/brand.tsx +94 -0
  164. package/template/apps/web/src/pages/brands.tsx +104 -0
  165. package/template/apps/web/src/pages/events.tsx +388 -0
  166. package/template/apps/web/src/pages/home.tsx +51 -0
  167. package/template/apps/web/src/pages/new-passport.tsx +137 -0
  168. package/template/apps/web/src/pages/operations.tsx +169 -0
  169. package/template/apps/web/src/pages/passport.tsx +632 -0
  170. package/template/apps/web/src/pages/public-passport.tsx +64 -0
  171. package/template/apps/web/src/pages/sign-in.tsx +93 -0
  172. package/template/apps/web/src/pages/verify.tsx +30 -0
  173. package/template/apps/web/src/pages/wallet.tsx +141 -0
  174. package/template/apps/web/tsconfig.json +29 -0
  175. package/template/apps/web/vite.config.ts +23 -0
  176. package/template/deploy/compose.yml +38 -0
  177. package/template/package.json +48 -0
  178. package/template/tsconfig.base.json +13 -0
@@ -0,0 +1,113 @@
1
+ import { useState, type ReactNode } from 'react'
2
+ import { Link, useLocation } from 'react-router'
3
+ import { Button } from '@/components/ui/button'
4
+ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
5
+ import { Input } from '@/components/ui/input'
6
+ import { CopyButton, DefinitionList, ErrorNotice, Field, Loading, Mono, PageTitle, ToneBadge, ValueView, statusTone } from '@/components/bits'
7
+ import { api, type AcceptResult, type OfferView } from '@/lib/api'
8
+ import { formatTime, humanise, offerIdFromPath, publicPathOf } from '@/lib/format'
9
+ import { useLoad } from '@/lib/use-load'
10
+
11
+ export function Accept() {
12
+ const requestId = offerIdFromPath(useLocation().pathname)
13
+ if (requestId == null) return <ErrorNotice error={new Error('The offer link contains an invalid request ID.')} title="Could not load the offer" />
14
+ return <AcceptOffer key={requestId} requestId={requestId} />
15
+ }
16
+
17
+ function AcceptOffer({ requestId }: { requestId: string }) {
18
+ const offer = useLoad(() => api.offer(requestId), [requestId])
19
+ const [claimCode, setClaimCode] = useState('')
20
+ const [busy, setBusy] = useState<'accept' | 'decline'>()
21
+ const [error, setError] = useState<unknown>()
22
+ const [accepted, setAccepted] = useState<AcceptResult>()
23
+ const [declined, setDeclined] = useState<OfferView>()
24
+
25
+ if (offer.loading) return <Loading what="Loading the offer" />
26
+ if (offer.error != null || offer.data == null) return <ErrorNotice error={offer.error ?? new Error('no answer')} title="Could not load the offer" />
27
+ const preview = offer.data
28
+ const publicPath = publicPathOf(preview.passportId)
29
+ const open = preview.status === 'open' && accepted == null && declined == null
30
+ const { word, note, ...otherTerms } = preview.terms
31
+
32
+ async function act(kind: 'accept' | 'decline') {
33
+ setBusy(kind)
34
+ setError(undefined)
35
+ try {
36
+ if (kind === 'accept') setAccepted(await api.acceptOffer(requestId, claimCode.trim()))
37
+ else setDeclined(await api.declineOffer(requestId, claimCode.trim()))
38
+ offer.reload()
39
+ } catch (cause) {
40
+ setError(cause)
41
+ } finally {
42
+ setBusy(undefined)
43
+ }
44
+ }
45
+
46
+ return (
47
+ <div className="mx-auto max-w-xl space-y-8">
48
+ <PageTitle title="A passport is offered to you" description={<Mono>{preview.passportId}</Mono>} />
49
+ <DefinitionList
50
+ entries={[
51
+ ['Terms', <span key="w" className="font-medium">{String(word ?? '')}</span>],
52
+ ...(typeof note === 'string' && note !== '' ? [['Note', note] as [string, string]] : []),
53
+ ...Object.entries(otherTerms).map(([k, v]) => [humanise(k), <ValueView key={k} value={v} />] as [string, ReactNode]),
54
+ ['Expires', formatTime(preview.expiresAt)],
55
+ ['Status', <ToneBadge key="s" tone={statusTone(preview.status)}>{preview.status}</ToneBadge>],
56
+ ]}
57
+ />
58
+
59
+ {accepted != null ? (
60
+ <Card className="border-emerald-300 dark:border-emerald-800">
61
+ <CardHeader>
62
+ <CardTitle>Accepted</CardTitle>
63
+ <CardDescription>The transfer was written.</CardDescription>
64
+ </CardHeader>
65
+ <CardContent className="space-y-4">
66
+ <Field label="Transfer txid">
67
+ <span className="flex items-center gap-2">
68
+ <Mono>{accepted.transferTxid}</Mono>
69
+ <CopyButton text={accepted.transferTxid} label="Copy the txid" />
70
+ </span>
71
+ </Field>
72
+ <p className="text-sm">You now hold this passport. Keep your claim code: it is how you act on the passport from here, including handing it on or retiring it.</p>
73
+ {publicPath == null ? null : (
74
+ <Button asChild variant="outline">
75
+ <Link to={publicPath}>Open the passport page</Link>
76
+ </Button>
77
+ )}
78
+ </CardContent>
79
+ </Card>
80
+ ) : declined != null ? (
81
+ <Card>
82
+ <CardHeader>
83
+ <CardTitle>Declined</CardTitle>
84
+ <CardDescription>Nothing was written. The offer is closed.</CardDescription>
85
+ </CardHeader>
86
+ </Card>
87
+ ) : !open ? (
88
+ <p className="text-sm text-muted-foreground">This offer is {preview.status}; nothing can be done with it.</p>
89
+ ) : (
90
+ <Card>
91
+ <CardHeader>
92
+ <CardTitle>Your claim code</CardTitle>
93
+ <CardDescription>The code the current holder gave you. Accepting writes the transfer to you; declining writes nothing.</CardDescription>
94
+ </CardHeader>
95
+ <CardContent className="space-y-4">
96
+ <Field label="Claim code" htmlFor="claimCode" required>
97
+ <Input id="claimCode" value={claimCode} onChange={(e) => setClaimCode(e.target.value)} autoComplete="off" spellCheck={false} />
98
+ </Field>
99
+ {error == null ? null : <ErrorNotice error={error} title="Refused" />}
100
+ <div className="flex gap-2">
101
+ <Button onClick={() => act('accept')} disabled={busy != null || claimCode.trim() === ''}>
102
+ {busy === 'accept' ? 'Working' : 'Accept'}
103
+ </Button>
104
+ <Button variant="outline" onClick={() => act('decline')} disabled={busy != null || claimCode.trim() === ''}>
105
+ {busy === 'decline' ? 'Working' : 'Decline'}
106
+ </Button>
107
+ </div>
108
+ </CardContent>
109
+ </Card>
110
+ )}
111
+ </div>
112
+ )
113
+ }
@@ -0,0 +1,94 @@
1
+ import { Link, useParams } from 'react-router'
2
+ import { Button } from '@/components/ui/button'
3
+ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'
4
+ import { ErrorNotice, Loading, PageTitle, ToneBadge, statusTone } from '@/components/bits'
5
+ import { RequireAccount } from '@/components/layout'
6
+ import { api, passportRef } from '@/lib/api'
7
+ import { parseIdentifier } from '@/lib/format'
8
+ import { useLoad } from '@/lib/use-load'
9
+
10
+ export function Brand() {
11
+ return (
12
+ <RequireAccount>
13
+ <BrandPage />
14
+ </RequireAccount>
15
+ )
16
+ }
17
+
18
+ function BrandPage() {
19
+ const { brandId = '' } = useParams()
20
+ const passports = useLoad(() => api.brandPassports(brandId), [brandId])
21
+ const brands = useLoad(() => api.brands(), [])
22
+ const brand = brands.data?.find((b) => b.id === brandId)
23
+
24
+ return (
25
+ <div className="space-y-8">
26
+ <PageTitle
27
+ title={brand?.name ?? brandId}
28
+ description={
29
+ <span>
30
+ Brand {brandId}.{' '}
31
+ <Link to="/brands" className="underline underline-offset-4">
32
+ All brands
33
+ </Link>
34
+ </span>
35
+ }
36
+ action={
37
+ <Button asChild>
38
+ <Link to={`/brands/${encodeURIComponent(brandId)}/new`}>Issue a passport</Link>
39
+ </Button>
40
+ }
41
+ />
42
+ {passports.loading ? (
43
+ <Loading what="Loading the passports" />
44
+ ) : passports.error != null || passports.data == null ? (
45
+ <ErrorNotice error={passports.error ?? new Error('no answer')} title="Could not load the passports" />
46
+ ) : passports.data.length === 0 ? (
47
+ <p className="text-sm text-muted-foreground">No passports yet.</p>
48
+ ) : (
49
+ <Table>
50
+ <TableHeader>
51
+ <TableRow>
52
+ <TableHead>Identifier</TableHead>
53
+ <TableHead>Profile</TableHead>
54
+ <TableHead>Status</TableHead>
55
+ <TableHead className="text-right">States</TableHead>
56
+ <TableHead className="text-right">Proven</TableHead>
57
+ <TableHead />
58
+ </TableRow>
59
+ </TableHeader>
60
+ <TableBody>
61
+ {passports.data.map((passport) => {
62
+ const ident = parseIdentifier(passport.passportId)
63
+ return (
64
+ <TableRow key={passport.passportId}>
65
+ <TableCell>
66
+ {ident == null ? (
67
+ <span className="font-mono text-xs">{passport.passportId}</span>
68
+ ) : (
69
+ <>
70
+ <div className="font-medium">Serial {ident.serial}</div>
71
+ <div className="text-xs text-muted-foreground">GTIN {ident.gtin}</div>
72
+ </>
73
+ )}
74
+ </TableCell>
75
+ <TableCell>{passport.profile}</TableCell>
76
+ <TableCell>
77
+ <ToneBadge tone={statusTone(passport.status)}>{passport.status}</ToneBadge>
78
+ </TableCell>
79
+ <TableCell className="text-right">{passport.journal.states}</TableCell>
80
+ <TableCell className="text-right">{passport.journal.proven}</TableCell>
81
+ <TableCell className="text-right">
82
+ <Button asChild variant="outline" size="sm">
83
+ <Link to={`/passports/${passportRef(passport.passportId)}`}>Open</Link>
84
+ </Button>
85
+ </TableCell>
86
+ </TableRow>
87
+ )
88
+ })}
89
+ </TableBody>
90
+ </Table>
91
+ )}
92
+ </div>
93
+ )
94
+ }
@@ -0,0 +1,104 @@
1
+ import { useState, type FormEvent } from 'react'
2
+ import { Link } from 'react-router'
3
+ import { Button } from '@/components/ui/button'
4
+ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
5
+ import { Input } from '@/components/ui/input'
6
+ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'
7
+ import { CopyButton, ErrorNotice, Loading, Mono, PageTitle } from '@/components/bits'
8
+ import { RequireAccount } from '@/components/layout'
9
+ import { api } from '@/lib/api'
10
+ import { formatTime, shortKey } from '@/lib/format'
11
+ import { useLoad } from '@/lib/use-load'
12
+
13
+ export function Brands() {
14
+ return (
15
+ <RequireAccount>
16
+ <BrandsPage />
17
+ </RequireAccount>
18
+ )
19
+ }
20
+
21
+ function BrandsPage() {
22
+ const brands = useLoad(() => api.brands(), [])
23
+ const [name, setName] = useState('')
24
+ const [busy, setBusy] = useState(false)
25
+ const [error, setError] = useState<unknown>()
26
+
27
+ async function create(event: FormEvent) {
28
+ event.preventDefault()
29
+ setBusy(true)
30
+ setError(undefined)
31
+ try {
32
+ await api.createBrand(name.trim())
33
+ setName('')
34
+ brands.reload()
35
+ } catch (cause) {
36
+ setError(cause)
37
+ } finally {
38
+ setBusy(false)
39
+ }
40
+ }
41
+
42
+ return (
43
+ <div className="space-y-10">
44
+ <PageTitle title="Brands" description="A brand issues passports and holds them until it hands them on. Its identity key is derived by the platform." />
45
+ {brands.loading ? (
46
+ <Loading what="Loading your brands" />
47
+ ) : brands.error != null || brands.data == null ? (
48
+ <ErrorNotice error={brands.error ?? new Error('no answer')} title="Could not load your brands" />
49
+ ) : brands.data.length === 0 ? (
50
+ <p className="text-sm text-muted-foreground">You are not a member of any brand yet. Create one below.</p>
51
+ ) : (
52
+ <Table>
53
+ <TableHeader>
54
+ <TableRow>
55
+ <TableHead>Name</TableHead>
56
+ <TableHead>Identity key</TableHead>
57
+ <TableHead>Created</TableHead>
58
+ <TableHead />
59
+ </TableRow>
60
+ </TableHeader>
61
+ <TableBody>
62
+ {brands.data.map((brand) => (
63
+ <TableRow key={brand.id}>
64
+ <TableCell>
65
+ <Link to={`/brands/${encodeURIComponent(brand.id)}`} className="font-medium underline-offset-4 hover:underline">
66
+ {brand.name}
67
+ </Link>
68
+ <div className="text-xs text-muted-foreground">{brand.id}</div>
69
+ </TableCell>
70
+ <TableCell>
71
+ <span className="flex items-center gap-1">
72
+ <Mono>{shortKey(brand.identityKey)}</Mono>
73
+ <CopyButton text={brand.identityKey} label="Copy the identity key" />
74
+ </span>
75
+ </TableCell>
76
+ <TableCell>{formatTime(brand.createdAt)}</TableCell>
77
+ <TableCell className="text-right">
78
+ <Button asChild variant="outline" size="sm">
79
+ <Link to={`/brands/${encodeURIComponent(brand.id)}`}>Passports</Link>
80
+ </Button>
81
+ </TableCell>
82
+ </TableRow>
83
+ ))}
84
+ </TableBody>
85
+ </Table>
86
+ )}
87
+ <Card className="max-w-md">
88
+ <CardHeader>
89
+ <CardTitle>Create a brand</CardTitle>
90
+ <CardDescription>You become its first member.</CardDescription>
91
+ </CardHeader>
92
+ <CardContent className="space-y-3">
93
+ <form onSubmit={create} className="flex gap-2">
94
+ <Input value={name} onChange={(e) => setName(e.target.value)} placeholder="Brand name" required aria-label="Brand name" />
95
+ <Button type="submit" disabled={busy || name.trim() === ''}>
96
+ {busy ? 'Working' : 'Create'}
97
+ </Button>
98
+ </form>
99
+ {error == null ? null : <ErrorNotice error={error} title="The brand was not created" />}
100
+ </CardContent>
101
+ </Card>
102
+ </div>
103
+ )
104
+ }