@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.
- package/LICENSE +203 -0
- package/NOTICE +2 -0
- package/PATENTS +12 -0
- package/README.md +93 -2
- package/dist/index.js +125 -0
- package/package.json +57 -4
- package/template/Dockerfile +37 -0
- package/template/README.md +389 -0
- package/template/_dockerignore +6 -0
- package/template/_env.example +122 -0
- package/template/_github/workflows/ci.yml +23 -0
- package/template/_gitignore +8 -0
- package/template/_prettierrc +6 -0
- package/template/apps/api/API.md +119 -0
- package/template/apps/api/package.json +39 -0
- package/template/apps/api/src/auth.ts +55 -0
- package/template/apps/api/src/bound-profiles.ts +590 -0
- package/template/apps/api/src/claims.ts +204 -0
- package/template/apps/api/src/cli.ts +99 -0
- package/template/apps/api/src/config.ts +180 -0
- package/template/apps/api/src/custody.ts +358 -0
- package/template/apps/api/src/dev-index.ts +120 -0
- package/template/apps/api/src/env-file.ts +55 -0
- package/template/apps/api/src/env.ts +14 -0
- package/template/apps/api/src/epcis/exchange.ts +434 -0
- package/template/apps/api/src/epcis/mongo-storage.ts +381 -0
- package/template/apps/api/src/epcis/routes.ts +364 -0
- package/template/apps/api/src/epcis/sources.ts +142 -0
- package/template/apps/api/src/go-live.ts +226 -0
- package/template/apps/api/src/http-error.ts +15 -0
- package/template/apps/api/src/identifiers.ts +57 -0
- package/template/apps/api/src/index-client.ts +261 -0
- package/template/apps/api/src/index-projects.ts +53 -0
- package/template/apps/api/src/lifecycle-authority.ts +49 -0
- package/template/apps/api/src/lifecycle.ts +485 -0
- package/template/apps/api/src/main.ts +58 -0
- package/template/apps/api/src/parties.ts +68 -0
- package/template/apps/api/src/platform.ts +176 -0
- package/template/apps/api/src/portability/commands.ts +224 -0
- package/template/apps/api/src/portability/export.ts +708 -0
- package/template/apps/api/src/portability/package.ts +270 -0
- package/template/apps/api/src/portability/restore.ts +863 -0
- package/template/apps/api/src/profiles.ts +125 -0
- package/template/apps/api/src/reader.ts +265 -0
- package/template/apps/api/src/resolver.ts +159 -0
- package/template/apps/api/src/sector-examples.ts +390 -0
- package/template/apps/api/src/server.ts +613 -0
- package/template/apps/api/src/store.ts +426 -0
- package/template/apps/api/src/validation-engine.ts +172 -0
- package/template/apps/api/src/wallet.ts +359 -0
- package/template/apps/api/src/worker.ts +113 -0
- package/template/apps/api/src/writer.ts +603 -0
- package/template/apps/api/test/bound-http.test.ts +496 -0
- package/template/apps/api/test/bound-profiles.test.ts +547 -0
- package/template/apps/api/test/config.test.ts +160 -0
- package/template/apps/api/test/custody-journal.test.ts +415 -0
- package/template/apps/api/test/custody-recovery-profile.test.ts +224 -0
- package/template/apps/api/test/custom-profile.test.ts +167 -0
- package/template/apps/api/test/env-file.test.ts +53 -0
- package/template/apps/api/test/epcis-fixtures.ts +270 -0
- package/template/apps/api/test/epcis-http.test.ts +1179 -0
- package/template/apps/api/test/epcis-mongo-storage.test.ts +313 -0
- package/template/apps/api/test/epcis-separation.test.ts +253 -0
- package/template/apps/api/test/epcis-web.test.ts +230 -0
- package/template/apps/api/test/exit-exercise.test.ts +1038 -0
- package/template/apps/api/test/external-index.test.ts +32 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/background.ttl +33 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/binding.json +141 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/context.jsonld +36 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/product.schema.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/shapes.ttl +112 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/conflicting-gtin.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/conflicting-serial.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/granularity-mismatch.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/item-gtin-13.json +43 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/item.json +42 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/missing-required-property.json +43 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/model-as-subject.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/no-passport-identifier.json +43 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/other-product.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/part-not-dishwasher-safe.json +45 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/altered-artefact.json +19 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/altered-background.ttl +33 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/conflicting-binding.json +141 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/conflicting-second-registration.json +19 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/untrusted-binding.json +13 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/unlisted-context.json +47 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/wrong-binding-digest.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/binding.json +88 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/product.schema.json +25 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/item.json +26 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/missing-required-property.json +27 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/no-passport-identifier.json +27 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/other-product.json +28 -0
- package/template/apps/api/test/go-live.test.ts +179 -0
- package/template/apps/api/test/gs1-global-setup.ts +33 -0
- package/template/apps/api/test/gs1-test-env.ts +5 -0
- package/template/apps/api/test/identifier-host.test.ts +256 -0
- package/template/apps/api/test/index-projects.test.ts +81 -0
- package/template/apps/api/test/lifecycle-claims.test.ts +546 -0
- package/template/apps/api/test/lifecycle-fixtures.ts +167 -0
- package/template/apps/api/test/lifecycle.test.ts +147 -0
- package/template/apps/api/test/manifest-notice.test.ts +36 -0
- package/template/apps/api/test/network-guard.ts +113 -0
- package/template/apps/api/test/portability.test.ts +655 -0
- package/template/apps/api/test/profile-bundle-resolver.test.ts +198 -0
- package/template/apps/api/test/retired-profiles.test.ts +216 -0
- package/template/apps/api/test/sector-cutover.test.ts +95 -0
- package/template/apps/api/test/sector-forms.test.ts +420 -0
- package/template/apps/api/test/unjoined-index.test.ts +62 -0
- package/template/apps/api/test/validation-engine.test.ts +328 -0
- package/template/apps/api/test/wallet-monitor.test.ts +38 -0
- package/template/apps/api/test/writer-journal.test.ts +327 -0
- package/template/apps/api/tsconfig.json +9 -0
- package/template/apps/api/vitest.config.ts +12 -0
- package/template/apps/web/components.json +21 -0
- package/template/apps/web/index.html +12 -0
- package/template/apps/web/package.json +33 -0
- package/template/apps/web/src/app.tsx +55 -0
- package/template/apps/web/src/components/bits.tsx +188 -0
- package/template/apps/web/src/components/bound/bound-passport-form.tsx +368 -0
- package/template/apps/web/src/components/bound/field-view.tsx +237 -0
- package/template/apps/web/src/components/bound/pieces.tsx +169 -0
- package/template/apps/web/src/components/bound/readings.tsx +152 -0
- package/template/apps/web/src/components/bound/structured-value.tsx +114 -0
- package/template/apps/web/src/components/claim-dialog.tsx +344 -0
- package/template/apps/web/src/components/epcis-events.tsx +119 -0
- package/template/apps/web/src/components/layout.tsx +135 -0
- package/template/apps/web/src/components/lifecycle-claims.tsx +199 -0
- package/template/apps/web/src/components/passport-form.tsx +244 -0
- package/template/apps/web/src/components/read-passport.tsx +49 -0
- package/template/apps/web/src/components/reading.tsx +150 -0
- package/template/apps/web/src/components/ui/alert.tsx +65 -0
- package/template/apps/web/src/components/ui/badge.tsx +47 -0
- package/template/apps/web/src/components/ui/button.tsx +63 -0
- package/template/apps/web/src/components/ui/card.tsx +91 -0
- package/template/apps/web/src/components/ui/dialog.tsx +156 -0
- package/template/apps/web/src/components/ui/input.tsx +20 -0
- package/template/apps/web/src/components/ui/label.tsx +21 -0
- package/template/apps/web/src/components/ui/select.tsx +189 -0
- package/template/apps/web/src/components/ui/separator.tsx +25 -0
- package/template/apps/web/src/components/ui/table.tsx +115 -0
- package/template/apps/web/src/components/ui/tabs.tsx +90 -0
- package/template/apps/web/src/components/ui/textarea.tsx +17 -0
- package/template/apps/web/src/index.css +81 -0
- package/template/apps/web/src/lib/api.ts +396 -0
- package/template/apps/web/src/lib/auth.ts +10 -0
- package/template/apps/web/src/lib/bound/battery-form.ts +269 -0
- package/template/apps/web/src/lib/bound/display.ts +122 -0
- package/template/apps/web/src/lib/bound/fields.ts +128 -0
- package/template/apps/web/src/lib/bound/form-model.ts +521 -0
- package/template/apps/web/src/lib/bound/forms.ts +15 -0
- package/template/apps/web/src/lib/bound/identity.ts +48 -0
- package/template/apps/web/src/lib/bound/textile-form.ts +236 -0
- package/template/apps/web/src/lib/bound/units.ts +37 -0
- package/template/apps/web/src/lib/epcis.ts +345 -0
- package/template/apps/web/src/lib/format.ts +87 -0
- package/template/apps/web/src/lib/lifecycle.ts +350 -0
- package/template/apps/web/src/lib/session.tsx +92 -0
- package/template/apps/web/src/lib/use-load.ts +46 -0
- package/template/apps/web/src/main.tsx +18 -0
- package/template/apps/web/src/pages/accept.tsx +113 -0
- package/template/apps/web/src/pages/brand.tsx +94 -0
- package/template/apps/web/src/pages/brands.tsx +104 -0
- package/template/apps/web/src/pages/events.tsx +388 -0
- package/template/apps/web/src/pages/home.tsx +51 -0
- package/template/apps/web/src/pages/new-passport.tsx +137 -0
- package/template/apps/web/src/pages/operations.tsx +169 -0
- package/template/apps/web/src/pages/passport.tsx +632 -0
- package/template/apps/web/src/pages/public-passport.tsx +64 -0
- package/template/apps/web/src/pages/sign-in.tsx +93 -0
- package/template/apps/web/src/pages/verify.tsx +30 -0
- package/template/apps/web/src/pages/wallet.tsx +141 -0
- package/template/apps/web/tsconfig.json +29 -0
- package/template/apps/web/vite.config.ts +23 -0
- package/template/deploy/compose.yml +38 -0
- package/template/package.json +48 -0
- package/template/tsconfig.base.json +13 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// The frame every page sits in: a header with the name, the navigation and
|
|
2
|
+
// the sign-in state, the page itself, and one footer line.
|
|
3
|
+
import type { ReactNode } from 'react'
|
|
4
|
+
import { cn } from 'cn'
|
|
5
|
+
import { Link, NavLink, Outlet, useNavigate } from 'react-router'
|
|
6
|
+
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
|
|
7
|
+
import { Button } from '@/components/ui/button'
|
|
8
|
+
import { Loading, ToneBadge } from '@/components/bits'
|
|
9
|
+
import { useAccount, useHealth } from '@/lib/session'
|
|
10
|
+
|
|
11
|
+
const navLink = ({ isActive }: { isActive: boolean }) => cn('text-sm transition-colors hover:text-foreground', isActive ? 'font-medium text-foreground' : 'text-muted-foreground')
|
|
12
|
+
|
|
13
|
+
/** A page for a signed-in member: with sign-in on and nobody signed in, say so instead of letting every call answer 401. */
|
|
14
|
+
export function RequireAccount({ children }: { children: ReactNode }) {
|
|
15
|
+
const account = useAccount()
|
|
16
|
+
if (account.pending) return <Loading />
|
|
17
|
+
if (!account.signedIn && account.canSignIn) {
|
|
18
|
+
return (
|
|
19
|
+
<Alert>
|
|
20
|
+
<AlertTitle>Sign in first</AlertTitle>
|
|
21
|
+
<AlertDescription>
|
|
22
|
+
<p>
|
|
23
|
+
This page is for a member of a brand.{' '}
|
|
24
|
+
<Link to="/sign-in" className="underline underline-offset-4">
|
|
25
|
+
Sign in
|
|
26
|
+
</Link>{' '}
|
|
27
|
+
or{' '}
|
|
28
|
+
<Link to="/sign-up" className="underline underline-offset-4">
|
|
29
|
+
sign up
|
|
30
|
+
</Link>
|
|
31
|
+
.
|
|
32
|
+
</p>
|
|
33
|
+
</AlertDescription>
|
|
34
|
+
</Alert>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
if (!account.signedIn) {
|
|
38
|
+
return (
|
|
39
|
+
<Alert variant="destructive">
|
|
40
|
+
<AlertTitle>No session</AlertTitle>
|
|
41
|
+
<AlertDescription>
|
|
42
|
+
<p>The API did not answer, so there is nobody to act as. Check that the API is running.</p>
|
|
43
|
+
</AlertDescription>
|
|
44
|
+
</Alert>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
return <>{children}</>
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** While nothing is live, say so on every page and name the command that changes it. */
|
|
51
|
+
function DevelopmentBanner() {
|
|
52
|
+
const { health } = useHealth()
|
|
53
|
+
if (health == null || health.livePublishing) return null
|
|
54
|
+
return (
|
|
55
|
+
<div className="border-b bg-muted/50">
|
|
56
|
+
<div className="mx-auto w-full max-w-5xl px-4 py-2 text-sm text-muted-foreground">
|
|
57
|
+
Nothing here is on the chain: this app writes drafts to {health.index.inProcess ? 'an index in this process' : 'its index'}. Run <code className="font-mono">npm run go-live</code> to publish for real.
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function Layout() {
|
|
64
|
+
const account = useAccount()
|
|
65
|
+
const { error } = useHealth()
|
|
66
|
+
const navigate = useNavigate()
|
|
67
|
+
|
|
68
|
+
async function signOut() {
|
|
69
|
+
await account.signOut?.()
|
|
70
|
+
navigate('/')
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<div className="flex min-h-screen flex-col">
|
|
75
|
+
<header className="border-b">
|
|
76
|
+
<div className="mx-auto flex w-full max-w-5xl flex-wrap items-center gap-x-6 gap-y-2 px-4 py-3">
|
|
77
|
+
<Link to="/" className="font-semibold tracking-tight">
|
|
78
|
+
Digital Product Passports
|
|
79
|
+
</Link>
|
|
80
|
+
<nav className="flex flex-wrap items-center gap-4" aria-label="Main">
|
|
81
|
+
<NavLink to="/verify" className={navLink}>
|
|
82
|
+
Verify
|
|
83
|
+
</NavLink>
|
|
84
|
+
{account.signedIn ? (
|
|
85
|
+
<>
|
|
86
|
+
<NavLink to="/brands" className={navLink}>
|
|
87
|
+
Brands
|
|
88
|
+
</NavLink>
|
|
89
|
+
<NavLink to="/events" className={navLink}>
|
|
90
|
+
Events
|
|
91
|
+
</NavLink>
|
|
92
|
+
<NavLink to="/operations" className={navLink}>
|
|
93
|
+
Operations
|
|
94
|
+
</NavLink>
|
|
95
|
+
<NavLink to="/wallet" className={navLink}>
|
|
96
|
+
Wallet
|
|
97
|
+
</NavLink>
|
|
98
|
+
</>
|
|
99
|
+
) : null}
|
|
100
|
+
</nav>
|
|
101
|
+
<div className="ml-auto flex items-center gap-3 text-sm">
|
|
102
|
+
{account.pending ? null : account.devSession ? (
|
|
103
|
+
<ToneBadge tone="warn">Developer</ToneBadge>
|
|
104
|
+
) : account.signedIn ? (
|
|
105
|
+
<>
|
|
106
|
+
<span className="text-muted-foreground">{account.name ?? account.email}</span>
|
|
107
|
+
<Button variant="outline" size="sm" onClick={signOut}>
|
|
108
|
+
Sign out
|
|
109
|
+
</Button>
|
|
110
|
+
</>
|
|
111
|
+
) : account.canSignIn ? (
|
|
112
|
+
<>
|
|
113
|
+
<Link to="/sign-in" className="text-muted-foreground hover:text-foreground">
|
|
114
|
+
Sign in
|
|
115
|
+
</Link>
|
|
116
|
+
<Button asChild size="sm">
|
|
117
|
+
<Link to="/sign-up">Sign up</Link>
|
|
118
|
+
</Button>
|
|
119
|
+
</>
|
|
120
|
+
) : (
|
|
121
|
+
<span className="text-muted-foreground">{error == null ? 'Sign-in is off' : 'API unreachable'}</span>
|
|
122
|
+
)}
|
|
123
|
+
</div>
|
|
124
|
+
</div>
|
|
125
|
+
</header>
|
|
126
|
+
<DevelopmentBanner />
|
|
127
|
+
<main className="mx-auto w-full max-w-5xl flex-1 px-4 py-8">
|
|
128
|
+
<Outlet />
|
|
129
|
+
</main>
|
|
130
|
+
<footer className="border-t">
|
|
131
|
+
<div className="mx-auto w-full max-w-5xl px-4 py-4 text-sm text-muted-foreground">Built on the open DPP standard on BSV</div>
|
|
132
|
+
</footer>
|
|
133
|
+
</div>
|
|
134
|
+
)
|
|
135
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// The lifecycle claims of one passport, on the public reading and on the
|
|
2
|
+
// brand's page alike: EPCIS lifecycle claims with each finding on its own
|
|
3
|
+
// line, and historical native claims, labelled as historical, apart from
|
|
4
|
+
// them. No claim gets an overall verdict, and an anchor is never shown as
|
|
5
|
+
// proof of the event, of ownership or of compliance.
|
|
6
|
+
import { Download } from 'lucide-react'
|
|
7
|
+
import { Button } from '@/components/ui/button'
|
|
8
|
+
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'
|
|
9
|
+
import { Mono, ToneBadge, ValueView } from '@/components/bits'
|
|
10
|
+
import { formatTime, humanise } from '@/lib/format'
|
|
11
|
+
import { HISTORICAL_LABEL, HISTORICAL_NOTICE, LIFECYCLE_NOTICE, correctionLabel, findingRows, participationLabel, roleWords, type LifecycleClaimView, type PassportClaimsReading, type RegistryAnswer } from '@/lib/lifecycle'
|
|
12
|
+
|
|
13
|
+
function Registry({ answer }: { answer?: RegistryAnswer }) {
|
|
14
|
+
if (answer == null) return <span className="text-muted-foreground">Not sent to a registry.</span>
|
|
15
|
+
return (
|
|
16
|
+
<span>
|
|
17
|
+
<ToneBadge tone={answer.accepted ? 'neutral' : 'fail'}>{answer.accepted ? 'Accepted by the registry' : `Registry answered HTTP ${answer.status}`}</ToneBadge>
|
|
18
|
+
{answer.detail == null ? null : <span className="ml-2 text-muted-foreground">{answer.detail}</span>}
|
|
19
|
+
</span>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const text = (value: unknown): string | undefined => (typeof value === 'string' ? value : undefined)
|
|
24
|
+
|
|
25
|
+
function LifecycleClaimItem({ claim, passportId, onDeclareError }: { claim: LifecycleClaimView; passportId: string; onDeclareError?: (claim: LifecycleClaimView) => void }) {
|
|
26
|
+
const participation = participationLabel(claim)
|
|
27
|
+
const correction = correctionLabel(claim)
|
|
28
|
+
const event = claim.event ?? {}
|
|
29
|
+
const others = claim.boundPassports.filter((passportId) => !claim.bindingsHere.some((b) => b.passportId === passportId))
|
|
30
|
+
const canDeclare = onDeclareError != null && claim.record != null && !claim.declaresError && claim.findings?.correction.status !== 'declared-in-error'
|
|
31
|
+
return (
|
|
32
|
+
<li className="space-y-3 p-4 text-sm">
|
|
33
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
34
|
+
<span className="font-medium">{claim.eventType ?? 'EPCIS lifecycle claim'}</span>
|
|
35
|
+
{text(event.bizStep) == null ? null : <ToneBadge tone="muted">{humanise(text(event.bizStep)!)}</ToneBadge>}
|
|
36
|
+
{text(event.action) == null ? null : <ToneBadge tone="muted">{text(event.action)}</ToneBadge>}
|
|
37
|
+
<ToneBadge tone={participation.tone}>{participation.label}</ToneBadge>
|
|
38
|
+
{correction == null ? null : <ToneBadge tone={correction.tone}>{correction.label}</ToneBadge>}
|
|
39
|
+
{text(event.eventTime) == null ? null : <span className="text-muted-foreground">{formatTime(text(event.eventTime)!)}</span>}
|
|
40
|
+
</div>
|
|
41
|
+
<p className="text-muted-foreground">{participation.sentence}</p>
|
|
42
|
+
{!claim.held ? (
|
|
43
|
+
<p>
|
|
44
|
+
The claim <Mono>{claim.attestationId}</Mono> could not be read: {claim.unavailable}
|
|
45
|
+
</p>
|
|
46
|
+
) : (
|
|
47
|
+
<>
|
|
48
|
+
<dl className="grid grid-cols-1 gap-x-6 gap-y-1 sm:grid-cols-[10rem_1fr]">
|
|
49
|
+
<dt className="text-muted-foreground">Signed by</dt>
|
|
50
|
+
<dd className="min-w-0">
|
|
51
|
+
<Mono>{claim.issuer}</Mono> <span className="text-muted-foreground">{roleWords(claim.assertedRole)}</span>
|
|
52
|
+
</dd>
|
|
53
|
+
<dt className="text-muted-foreground">Event identifier</dt>
|
|
54
|
+
<dd className="min-w-0">
|
|
55
|
+
<Mono>{claim.eventId}</Mono>
|
|
56
|
+
</dd>
|
|
57
|
+
<dt className="text-muted-foreground">Bound here by</dt>
|
|
58
|
+
<dd className="min-w-0">
|
|
59
|
+
{claim.bindingsHere.length === 0 ? (
|
|
60
|
+
<span className="text-muted-foreground">No binding names this passport.</span>
|
|
61
|
+
) : (
|
|
62
|
+
claim.bindingsHere.map((binding) => (
|
|
63
|
+
<div key={`${binding.field}-${binding.identifier}`}>
|
|
64
|
+
<Mono>{binding.identifier}</Mono>
|
|
65
|
+
<span className="text-muted-foreground">
|
|
66
|
+
{' '}
|
|
67
|
+
in {binding.field}, {binding.level === 'class' ? 'a class of products' : 'one item'}, {binding.status}
|
|
68
|
+
</span>
|
|
69
|
+
</div>
|
|
70
|
+
))
|
|
71
|
+
)}
|
|
72
|
+
</dd>
|
|
73
|
+
<dt className="text-muted-foreground">Other passports</dt>
|
|
74
|
+
<dd>{others.length === 0 ? 'None' : `${others.length} passport${others.length === 1 ? '' : 's'} bound by the same event`}</dd>
|
|
75
|
+
{claim.authorityScope == null ? null : (
|
|
76
|
+
<>
|
|
77
|
+
<dt className="text-muted-foreground">Declared role scope</dt>
|
|
78
|
+
<dd className="min-w-0">
|
|
79
|
+
<p>{claim.authorityScope.includes(passportId) ? 'The issuer declares this role for this passport.' : 'This passport is outside the issuer’s declared role scope.'}</p>
|
|
80
|
+
<ul>{claim.authorityScope.map((id) => <li key={id}><Mono>{id}</Mono></li>)}</ul>
|
|
81
|
+
</dd>
|
|
82
|
+
</>
|
|
83
|
+
)}
|
|
84
|
+
<dt className="text-muted-foreground">Found</dt>
|
|
85
|
+
<dd>{claim.foundBy.map((how) => (how === 'anchor' ? 'by an anchor naming this passport' : "among this application's claims")).join(' and ')}</dd>
|
|
86
|
+
{claim.source == null ? null : (
|
|
87
|
+
<>
|
|
88
|
+
<dt className="text-muted-foreground">Source</dt>
|
|
89
|
+
<dd>
|
|
90
|
+
Imported, from a document with SHA-256 <Mono>{String(claim.source.sourceDigest)}</Mono>. The issuer reports an event someone else supplied.
|
|
91
|
+
</dd>
|
|
92
|
+
</>
|
|
93
|
+
)}
|
|
94
|
+
{claim.record == null ? null : (
|
|
95
|
+
<>
|
|
96
|
+
<dt className="text-muted-foreground">Registry</dt>
|
|
97
|
+
<dd>
|
|
98
|
+
<Registry answer={claim.record.registry} />
|
|
99
|
+
</dd>
|
|
100
|
+
</>
|
|
101
|
+
)}
|
|
102
|
+
</dl>
|
|
103
|
+
<details className="rounded-md border p-3">
|
|
104
|
+
<summary className="cursor-pointer">Findings, one by one</summary>
|
|
105
|
+
{claim.findings == null ? null : (
|
|
106
|
+
<ul className="mt-3 divide-y">
|
|
107
|
+
{findingRows(claim.findings).map((row) => (
|
|
108
|
+
<li key={row.key} className="grid gap-1 py-2 sm:grid-cols-[9rem_8rem_1fr] sm:gap-3">
|
|
109
|
+
<span>{row.key === 'authority' ? 'Authority for declared scope' : row.label}</span>
|
|
110
|
+
<span>
|
|
111
|
+
<ToneBadge tone={row.tone}>{humanise(row.status)}</ToneBadge>
|
|
112
|
+
</span>
|
|
113
|
+
<span className="text-muted-foreground">{row.sentence}</span>
|
|
114
|
+
</li>
|
|
115
|
+
))}
|
|
116
|
+
</ul>
|
|
117
|
+
)}
|
|
118
|
+
</details>
|
|
119
|
+
<details className="rounded-md border p-3">
|
|
120
|
+
<summary className="cursor-pointer">The signed event</summary>
|
|
121
|
+
<div className="mt-3">
|
|
122
|
+
<ValueView value={claim.event} />
|
|
123
|
+
</div>
|
|
124
|
+
</details>
|
|
125
|
+
<div className="flex flex-wrap items-center gap-3">
|
|
126
|
+
{claim.record == null ? null : (
|
|
127
|
+
<a href={`/api/lifecycle-claims/${encodeURIComponent(claim.attestationId)}`} download className="inline-flex items-center gap-1 underline underline-offset-4">
|
|
128
|
+
<Download className="size-3.5" aria-hidden />
|
|
129
|
+
Download the signed claim
|
|
130
|
+
</a>
|
|
131
|
+
)}
|
|
132
|
+
{canDeclare ? (
|
|
133
|
+
<Button variant="outline" size="sm" onClick={() => onDeclareError(claim)}>
|
|
134
|
+
Declare in error
|
|
135
|
+
</Button>
|
|
136
|
+
) : null}
|
|
137
|
+
</div>
|
|
138
|
+
</>
|
|
139
|
+
)}
|
|
140
|
+
</li>
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function LifecycleClaims({ reading, onDeclareError, emptyText }: { reading: PassportClaimsReading; onDeclareError?: (claim: LifecycleClaimView) => void; emptyText?: string }) {
|
|
145
|
+
const incomplete = reading.discovery.index !== 'asked' || reading.discovery.relatedClaims === 'incomplete'
|
|
146
|
+
if (reading.lifecycle.length === 0 && reading.historical.length === 0) {
|
|
147
|
+
return (
|
|
148
|
+
<div className="space-y-2 text-sm text-muted-foreground">
|
|
149
|
+
<p>{!incomplete ? (emptyText ?? 'No lifecycle claim was found for this passport.') : 'No lifecycle claim was found in the available records.'}</p>
|
|
150
|
+
{incomplete ? <p>Claim discovery was incomplete. Additional claims may exist.</p> : null}
|
|
151
|
+
</div>
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
return (
|
|
155
|
+
<div className="space-y-6">
|
|
156
|
+
{incomplete ? <p className="text-sm text-muted-foreground">Claim discovery was incomplete. This list shows the claims found so far.</p> : null}
|
|
157
|
+
{reading.lifecycle.length === 0 ? null : (
|
|
158
|
+
<div className="space-y-3">
|
|
159
|
+
<p className="text-sm text-muted-foreground">{LIFECYCLE_NOTICE}</p>
|
|
160
|
+
<ul className="divide-y rounded-lg border">
|
|
161
|
+
{reading.lifecycle.map((claim) => (
|
|
162
|
+
<LifecycleClaimItem key={claim.attestationId} claim={claim} passportId={reading.passportId} onDeclareError={onDeclareError} />
|
|
163
|
+
))}
|
|
164
|
+
</ul>
|
|
165
|
+
</div>
|
|
166
|
+
)}
|
|
167
|
+
{reading.historical.length === 0 ? null : (
|
|
168
|
+
<div className="space-y-3">
|
|
169
|
+
<h3 className="text-sm font-medium">{HISTORICAL_LABEL}s</h3>
|
|
170
|
+
<p className="text-sm text-muted-foreground">{HISTORICAL_NOTICE}</p>
|
|
171
|
+
<Table>
|
|
172
|
+
<TableHeader>
|
|
173
|
+
<TableRow>
|
|
174
|
+
<TableHead>Historical category</TableHead>
|
|
175
|
+
<TableHead>When</TableHead>
|
|
176
|
+
<TableHead>Issued by</TableHead>
|
|
177
|
+
<TableHead>Signature</TableHead>
|
|
178
|
+
</TableRow>
|
|
179
|
+
</TableHeader>
|
|
180
|
+
<TableBody>
|
|
181
|
+
{reading.historical.map((claim) => (
|
|
182
|
+
<TableRow key={claim.id}>
|
|
183
|
+
<TableCell>
|
|
184
|
+
{claim.claim.eventType} <ToneBadge tone="muted">{HISTORICAL_LABEL}</ToneBadge>
|
|
185
|
+
</TableCell>
|
|
186
|
+
<TableCell>{formatTime(claim.claim.timestamp)}</TableCell>
|
|
187
|
+
<TableCell>{claim.issuedBy}</TableCell>
|
|
188
|
+
<TableCell>
|
|
189
|
+
<ToneBadge tone={claim.signature === 'verified' ? 'pass' : 'fail'}>{claim.signature}</ToneBadge>
|
|
190
|
+
</TableCell>
|
|
191
|
+
</TableRow>
|
|
192
|
+
))}
|
|
193
|
+
</TableBody>
|
|
194
|
+
</Table>
|
|
195
|
+
</div>
|
|
196
|
+
)}
|
|
197
|
+
</div>
|
|
198
|
+
)
|
|
199
|
+
}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
// The product-data form a profile describes: one control per field, chosen
|
|
2
|
+
// from the field's valueType, grouped as the manifest groups them. Public
|
|
3
|
+
// fields go to the payload; every other tier goes to the owner fields the
|
|
4
|
+
// API encrypts off chain. The same form issues and updates.
|
|
5
|
+
import { useMemo, useState, type FormEvent, type ReactNode } from 'react'
|
|
6
|
+
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
|
|
7
|
+
import { Button } from '@/components/ui/button'
|
|
8
|
+
import { Input } from '@/components/ui/input'
|
|
9
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
|
10
|
+
import { Textarea } from '@/components/ui/textarea'
|
|
11
|
+
import { ErrorNotice, Field } from '@/components/bits'
|
|
12
|
+
import type { ManifestProfile, ProfileField } from '@/lib/api'
|
|
13
|
+
import { humanise } from '@/lib/format'
|
|
14
|
+
|
|
15
|
+
export interface PassportFormValues {
|
|
16
|
+
payload: Record<string, unknown>
|
|
17
|
+
ownerFields: Record<string, unknown>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface Props {
|
|
21
|
+
profile: ManifestProfile
|
|
22
|
+
/** Where the values start: the sample for a new passport, the current payload for an update. */
|
|
23
|
+
initial: { payload: Record<string, unknown>; ownerFields?: Record<string, unknown> }
|
|
24
|
+
submitLabel: string
|
|
25
|
+
busy?: boolean
|
|
26
|
+
error?: unknown
|
|
27
|
+
onSubmit: (values: PassportFormValues) => void
|
|
28
|
+
/** Rendered inside the form before the product fields, for the identifier inputs. */
|
|
29
|
+
before?: ReactNode
|
|
30
|
+
/** Rendered after the product fields, for a claim code or a note. */
|
|
31
|
+
after?: ReactNode
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type Control = 'text' | 'textarea' | 'number' | 'select' | 'date' | 'url' | 'json'
|
|
35
|
+
|
|
36
|
+
function controlFor(field: ProfileField): Control {
|
|
37
|
+
if (field.cardinality === 'many' || field.valueType === 'record' || field.valueType === 'multi' || field.valueType === 'any') return 'json'
|
|
38
|
+
switch (field.valueType) {
|
|
39
|
+
case 'decimal':
|
|
40
|
+
case 'integer':
|
|
41
|
+
case 'percent':
|
|
42
|
+
return 'number'
|
|
43
|
+
case 'enum':
|
|
44
|
+
return field.codeList != null && field.codeList.options.length > 0 ? 'select' : 'text'
|
|
45
|
+
case 'date':
|
|
46
|
+
return 'date'
|
|
47
|
+
case 'url':
|
|
48
|
+
case 'document':
|
|
49
|
+
case 'graphic':
|
|
50
|
+
return 'url'
|
|
51
|
+
default:
|
|
52
|
+
return (field.constraints?.maxLength ?? 0) > 200 ? 'textarea' : 'text'
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function placeholderFor(field: ProfileField): string | undefined {
|
|
57
|
+
if (field.constraints?.patternHint != null) return field.constraints.patternHint
|
|
58
|
+
if (field.valueType === 'monthYear') return 'YYYY-MM'
|
|
59
|
+
if (field.valueType === 'country') return 'Two-letter country code, for example AU'
|
|
60
|
+
if (field.valueType === 'url' || field.valueType === 'document' || field.valueType === 'graphic') return 'https://'
|
|
61
|
+
return undefined
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const initialText = (field: ProfileField, value: unknown): string => {
|
|
65
|
+
if (value === undefined || value === null) return ''
|
|
66
|
+
if (controlFor(field) === 'json') return JSON.stringify(value, null, 2)
|
|
67
|
+
return typeof value === 'string' ? value : String(value)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function PassportForm({ profile, initial, submitLabel, busy, error, onSubmit, before, after }: Props) {
|
|
71
|
+
const fields = profile.fields
|
|
72
|
+
const fieldKeys = useMemo(() => new Set(fields.map((f) => f.key)), [fields])
|
|
73
|
+
const [showOptional, setShowOptional] = useState(false)
|
|
74
|
+
const [localError, setLocalError] = useState<string>()
|
|
75
|
+
const [draft, setDraft] = useState<Record<string, string>>(() => {
|
|
76
|
+
const out: Record<string, string> = {}
|
|
77
|
+
for (const field of fields) {
|
|
78
|
+
const source = field.accessTier === 'public' ? initial.payload : (initial.ownerFields ?? {})
|
|
79
|
+
if (field.key in source) out[field.key] = initialText(field, source[field.key])
|
|
80
|
+
}
|
|
81
|
+
return out
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
const groups = useMemo(() => {
|
|
85
|
+
const map = new Map<string, ProfileField[]>()
|
|
86
|
+
for (const field of fields) {
|
|
87
|
+
const group = field.group ?? 'other'
|
|
88
|
+
if (!map.has(group)) map.set(group, [])
|
|
89
|
+
map.get(group)!.push(field)
|
|
90
|
+
}
|
|
91
|
+
return [...map.entries()]
|
|
92
|
+
}, [fields])
|
|
93
|
+
|
|
94
|
+
const optionalCount = fields.filter((f) => f.obligation === 'optional').length
|
|
95
|
+
const notice = typeof initial.payload.notice === 'string' ? initial.payload.notice : undefined
|
|
96
|
+
const set = (key: string, value: string) => setDraft((d) => ({ ...d, [key]: value }))
|
|
97
|
+
|
|
98
|
+
function submit(event: FormEvent) {
|
|
99
|
+
event.preventDefault()
|
|
100
|
+
setLocalError(undefined)
|
|
101
|
+
const payload: Record<string, unknown> = {}
|
|
102
|
+
const ownerFields: Record<string, unknown> = {}
|
|
103
|
+
// Stamps and the notice are not fields; they are carried as they came.
|
|
104
|
+
for (const [key, value] of Object.entries(initial.payload)) if (!fieldKeys.has(key)) payload[key] = value
|
|
105
|
+
for (const field of fields) {
|
|
106
|
+
const raw = draft[field.key] ?? ''
|
|
107
|
+
if (raw.trim() === '') continue
|
|
108
|
+
let value: unknown
|
|
109
|
+
const control = controlFor(field)
|
|
110
|
+
if (control === 'number') {
|
|
111
|
+
value = Number(raw)
|
|
112
|
+
if (Number.isNaN(value)) {
|
|
113
|
+
setLocalError(`${field.label} must be a number.`)
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
} else if (control === 'json') {
|
|
117
|
+
try {
|
|
118
|
+
value = JSON.parse(raw)
|
|
119
|
+
} catch (cause) {
|
|
120
|
+
setLocalError(`${field.label} must be valid JSON: ${cause instanceof Error ? cause.message : String(cause)}`)
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
value = raw
|
|
125
|
+
}
|
|
126
|
+
;(field.accessTier === 'public' ? payload : ownerFields)[field.key] = value
|
|
127
|
+
}
|
|
128
|
+
onSubmit({ payload, ownerFields })
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<form onSubmit={submit} className="space-y-8">
|
|
133
|
+
{notice == null ? null : (
|
|
134
|
+
<Alert>
|
|
135
|
+
<AlertTitle>Demonstration prefix</AlertTitle>
|
|
136
|
+
<AlertDescription>
|
|
137
|
+
<p>This platform issues under the GS1 demonstration prefix, so every passport carries this notice first: "{notice}"</p>
|
|
138
|
+
</AlertDescription>
|
|
139
|
+
</Alert>
|
|
140
|
+
)}
|
|
141
|
+
{before}
|
|
142
|
+
{groups.map(([group, groupFields]) => {
|
|
143
|
+
const shown = groupFields.filter((f) => f.obligation !== 'optional' || showOptional)
|
|
144
|
+
if (shown.length === 0) return null
|
|
145
|
+
return (
|
|
146
|
+
<fieldset key={group} className="space-y-4">
|
|
147
|
+
<legend className="mb-3 text-base font-semibold">{humanise(group)}</legend>
|
|
148
|
+
<div className="grid gap-4 sm:grid-cols-2">
|
|
149
|
+
{shown.map((field) => (
|
|
150
|
+
<FieldControl key={field.key} field={field} value={draft[field.key] ?? ''} onChange={(v) => set(field.key, v)} />
|
|
151
|
+
))}
|
|
152
|
+
</div>
|
|
153
|
+
</fieldset>
|
|
154
|
+
)
|
|
155
|
+
})}
|
|
156
|
+
{optionalCount > 0 ? (
|
|
157
|
+
<label className="flex items-center gap-2 text-sm">
|
|
158
|
+
<input type="checkbox" checked={showOptional} onChange={(e) => setShowOptional(e.target.checked)} />
|
|
159
|
+
Show {optionalCount} optional {optionalCount === 1 ? 'field' : 'fields'}
|
|
160
|
+
</label>
|
|
161
|
+
) : null}
|
|
162
|
+
{after}
|
|
163
|
+
{localError == null ? null : <ErrorNotice error={new Error(localError)} title="Check the form" />}
|
|
164
|
+
{error == null ? null : <ErrorNotice error={error} title="The API refused it" />}
|
|
165
|
+
<div className="flex items-center gap-3">
|
|
166
|
+
<Button type="submit" disabled={busy}>
|
|
167
|
+
{busy ? 'Working' : submitLabel}
|
|
168
|
+
</Button>
|
|
169
|
+
<span className="text-xs text-muted-foreground">
|
|
170
|
+
<span className="text-destructive">*</span> required by the profile
|
|
171
|
+
</span>
|
|
172
|
+
</div>
|
|
173
|
+
</form>
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function FieldControl({ field, value, onChange }: { field: ProfileField; value: string; onChange: (value: string) => void }) {
|
|
178
|
+
const control = controlFor(field)
|
|
179
|
+
const id = `field-${field.key}`
|
|
180
|
+
const required = field.obligation === 'required'
|
|
181
|
+
const tier = field.accessTier === 'public' ? undefined : `${humanise(field.accessTier)} tier, encrypted off chain`
|
|
182
|
+
const help = [field.note, tier, field.obligation === 'recommended' ? 'Recommended' : undefined].filter((h): h is string => h != null).join('. ')
|
|
183
|
+
const label = field.unit == null ? field.label : `${field.label} (${field.unit})`
|
|
184
|
+
const wide = control === 'json' || control === 'textarea'
|
|
185
|
+
|
|
186
|
+
let input: ReactNode
|
|
187
|
+
if (control === 'select' && field.codeList != null) {
|
|
188
|
+
const options = [...field.codeList.options]
|
|
189
|
+
if (value !== '' && !options.some((o) => o.value === value)) options.unshift({ value, label: value })
|
|
190
|
+
input = (
|
|
191
|
+
<Select value={value} onValueChange={onChange}>
|
|
192
|
+
<SelectTrigger id={id} className="w-full" aria-required={required}>
|
|
193
|
+
<SelectValue placeholder="Choose" />
|
|
194
|
+
</SelectTrigger>
|
|
195
|
+
<SelectContent>
|
|
196
|
+
{options.map((o) => (
|
|
197
|
+
<SelectItem key={o.value} value={o.value}>
|
|
198
|
+
{o.label}
|
|
199
|
+
</SelectItem>
|
|
200
|
+
))}
|
|
201
|
+
</SelectContent>
|
|
202
|
+
</Select>
|
|
203
|
+
)
|
|
204
|
+
} else if (control === 'json') {
|
|
205
|
+
input = <Textarea id={id} value={value} onChange={(e) => onChange(e.target.value)} required={required} className="min-h-28 font-mono text-xs" spellCheck={false} placeholder="JSON" />
|
|
206
|
+
} else if (control === 'textarea') {
|
|
207
|
+
input = <Textarea id={id} value={value} onChange={(e) => onChange(e.target.value)} required={required} maxLength={field.constraints?.maxLength} />
|
|
208
|
+
} else if (control === 'number') {
|
|
209
|
+
input = (
|
|
210
|
+
<Input
|
|
211
|
+
id={id}
|
|
212
|
+
type="number"
|
|
213
|
+
inputMode="decimal"
|
|
214
|
+
value={value}
|
|
215
|
+
onChange={(e) => onChange(e.target.value)}
|
|
216
|
+
required={required}
|
|
217
|
+
min={field.constraints?.minimum}
|
|
218
|
+
max={field.constraints?.maximum}
|
|
219
|
+
step={field.constraints?.step ?? (field.valueType === 'integer' ? 1 : 'any')}
|
|
220
|
+
/>
|
|
221
|
+
)
|
|
222
|
+
} else {
|
|
223
|
+
input = (
|
|
224
|
+
<Input
|
|
225
|
+
id={id}
|
|
226
|
+
type={control === 'date' ? 'date' : control === 'url' ? 'url' : 'text'}
|
|
227
|
+
value={value}
|
|
228
|
+
onChange={(e) => onChange(e.target.value)}
|
|
229
|
+
required={required}
|
|
230
|
+
maxLength={field.constraints?.maxLength}
|
|
231
|
+
pattern={field.constraints?.pattern}
|
|
232
|
+
placeholder={placeholderFor(field)}
|
|
233
|
+
/>
|
|
234
|
+
)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return (
|
|
238
|
+
<div className={wide ? 'sm:col-span-2' : undefined}>
|
|
239
|
+
<Field label={label} htmlFor={id} required={required} help={help === '' ? undefined : help}>
|
|
240
|
+
{input}
|
|
241
|
+
</Field>
|
|
242
|
+
</div>
|
|
243
|
+
)
|
|
244
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Read one passport the way the public page and the verify page do: the
|
|
2
|
+
// reader's report from the index, this platform's journal when it has the
|
|
3
|
+
// passport, and the claims. A journal 404 is not a failure: the passport may
|
|
4
|
+
// be another platform's, and the report still stands on its own.
|
|
5
|
+
import { ErrorNotice, Loading } from '@/components/bits'
|
|
6
|
+
import { PassportReading } from '@/components/reading'
|
|
7
|
+
import { api, isNotFound, type PassportView, type Verification } from '@/lib/api'
|
|
8
|
+
import type { PassportClaimsReading } from '@/lib/lifecycle'
|
|
9
|
+
import { useLoad } from '@/lib/use-load'
|
|
10
|
+
|
|
11
|
+
interface Read {
|
|
12
|
+
verification?: Verification
|
|
13
|
+
verifyError?: unknown
|
|
14
|
+
journal?: PassportView
|
|
15
|
+
claims?: PassportClaimsReading
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const unlessNotFound =
|
|
19
|
+
<T,>(fallback: T) =>
|
|
20
|
+
(cause: unknown): T => {
|
|
21
|
+
if (isNotFound(cause)) return fallback
|
|
22
|
+
throw cause
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function read(passportId: string): Promise<Read> {
|
|
26
|
+
const [verification, journal, claims] = await Promise.all([
|
|
27
|
+
api.verify(passportId).then(
|
|
28
|
+
(value): { ok: true; value: Verification } => ({ ok: true, value }),
|
|
29
|
+
(error: unknown): { ok: false; error: unknown } => ({ ok: false, error })
|
|
30
|
+
),
|
|
31
|
+
api.passport(passportId).catch(unlessNotFound<PassportView | undefined>(undefined)),
|
|
32
|
+
api.passportClaims(passportId).catch(unlessNotFound<PassportClaimsReading | undefined>(undefined)),
|
|
33
|
+
])
|
|
34
|
+
return {
|
|
35
|
+
verification: verification.ok ? verification.value : undefined,
|
|
36
|
+
verifyError: verification.ok ? undefined : verification.error,
|
|
37
|
+
journal,
|
|
38
|
+
claims,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function ReadPassport({ passportId, manageLink, publicLink }: { passportId: string; manageLink?: boolean; publicLink?: boolean }) {
|
|
43
|
+
const result = useLoad(() => read(passportId), [passportId])
|
|
44
|
+
if (result.loading) return <Loading what="Reading the passport" />
|
|
45
|
+
if (result.error != null || result.data == null) return <ErrorNotice error={result.error ?? new Error('nothing was read')} title="Could not read the passport" />
|
|
46
|
+
const { verification, verifyError, journal, claims } = result.data
|
|
47
|
+
if (verification == null && journal == null) return <ErrorNotice error={verifyError} title="Nothing was found for this identifier" />
|
|
48
|
+
return <PassportReading passportId={passportId} verification={verification} verifyError={verifyError} journal={journal} claims={claims} manageLink={manageLink} publicLink={publicLink} />
|
|
49
|
+
}
|