@bsv/create-dpp-app 0.1.0-beta.1 → 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/NOTICE +2 -0
- package/PATENTS +12 -0
- package/README.md +26 -6
- package/dist/index.js +36 -8
- package/package.json +9 -5
- package/template/Dockerfile +4 -2
- package/template/README.md +297 -42
- package/template/_env.example +82 -13
- package/template/_github/workflows/ci.yml +3 -3
- package/template/apps/api/API.md +86 -16
- package/template/apps/api/package.json +9 -4
- package/template/apps/api/src/bound-profiles.ts +590 -0
- package/template/apps/api/src/claims.ts +175 -56
- package/template/apps/api/src/cli.ts +64 -7
- package/template/apps/api/src/config.ts +124 -10
- package/template/apps/api/src/custody.ts +241 -69
- package/template/apps/api/src/dev-index.ts +58 -9
- package/template/apps/api/src/env-file.ts +55 -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 +1 -1
- package/template/apps/api/src/index-client.ts +131 -6
- 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 +10 -2
- package/template/apps/api/src/parties.ts +2 -2
- package/template/apps/api/src/platform.ts +72 -17
- 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 +38 -13
- package/template/apps/api/src/reader.ts +172 -3
- 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 +253 -60
- package/template/apps/api/src/store.ts +198 -21
- package/template/apps/api/src/validation-engine.ts +172 -0
- package/template/apps/api/src/wallet.ts +30 -17
- package/template/apps/api/src/worker.ts +20 -13
- package/template/apps/api/src/writer.ts +383 -131
- 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 +148 -3
- 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 +3 -2
- 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 +17 -6
- 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/vitest.config.ts +3 -0
- package/template/apps/web/src/app.tsx +8 -4
- 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 +17 -0
- package/template/apps/web/src/components/lifecycle-claims.tsx +199 -0
- package/template/apps/web/src/components/passport-form.tsx +2 -2
- package/template/apps/web/src/components/read-passport.tsx +4 -3
- package/template/apps/web/src/components/reading.tsx +32 -39
- package/template/apps/web/src/lib/api.ts +136 -26
- 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 +27 -4
- package/template/apps/web/src/lib/lifecycle.ts +350 -0
- package/template/apps/web/src/pages/accept.tsx +8 -3
- package/template/apps/web/src/pages/events.tsx +388 -0
- package/template/apps/web/src/pages/new-passport.tsx +25 -2
- package/template/apps/web/src/pages/operations.tsx +22 -3
- package/template/apps/web/src/pages/passport.tsx +226 -162
- package/template/apps/web/src/pages/public-passport.tsx +50 -10
- package/template/apps/web/src/pages/wallet.tsx +1 -1
- package/template/apps/web/vite.config.ts +12 -4
- package/template/deploy/compose.yml +14 -2
- package/template/package.json +9 -3
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
// The brand's view of one passport: what is in the journal, and every action
|
|
2
2
|
// on it in a dialog. A passport that was handed on is held by a recipient,
|
|
3
3
|
// and every action then needs the claim code they accepted with.
|
|
4
|
-
import { useState, type FormEvent, type ReactNode } from 'react'
|
|
4
|
+
import { useRef, useState, type FormEvent, type ReactNode } from 'react'
|
|
5
5
|
import { Link, useParams } from 'react-router'
|
|
6
6
|
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
|
|
7
7
|
import { Button } from '@/components/ui/button'
|
|
8
8
|
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
|
9
9
|
import { Input } from '@/components/ui/input'
|
|
10
|
-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
|
11
10
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'
|
|
12
11
|
import { Textarea } from '@/components/ui/textarea'
|
|
13
12
|
import { CopyButton, DefinitionList, ErrorNotice, Field, Loading, Mono, PageTitle, Section, ToneBadge, YesNo, entriesOf, indexTone, networkTone, statusTone } from '@/components/bits'
|
|
13
|
+
import { BoundPassportForm, type BoundSubmission } from '@/components/bound/bound-passport-form'
|
|
14
|
+
import { EventsNaming, SuppliedDataNotice } from '@/components/epcis-events'
|
|
15
|
+
import { HolderReading, boundPayload } from '@/components/bound/readings'
|
|
14
16
|
import { RequireAccount } from '@/components/layout'
|
|
15
17
|
import { PassportForm, type PassportFormValues } from '@/components/passport-form'
|
|
16
|
-
import {
|
|
18
|
+
import { passportSpellings } from '@/lib/epcis'
|
|
19
|
+
import { RecordNotice } from '@/components/reading'
|
|
20
|
+
import { ClaimDialog, DeclareErrorDialog } from '@/components/claim-dialog'
|
|
21
|
+
import { LifecycleClaims } from '@/components/lifecycle-claims'
|
|
22
|
+
import { api, type AuthorisedReading, type BoundProfile, type OfferView, type PassportView } from '@/lib/api'
|
|
23
|
+
import type { LifecycleClaimView } from '@/lib/lifecycle'
|
|
17
24
|
import { formatTime, holderLabel, humanise, isRecord, parseIdentifier, passportIdFromRef, publicPathOf, shortKey, shortTxid } from '@/lib/format'
|
|
25
|
+
import { useHealth } from '@/lib/session'
|
|
18
26
|
import { useLoad } from '@/lib/use-load'
|
|
19
27
|
|
|
20
28
|
type DialogKind = 'update' | 'offer' | 'retire' | 'claim'
|
|
@@ -34,6 +42,7 @@ function PassportPage() {
|
|
|
34
42
|
const offers = useLoad(() => api.passportOffers(passportId), [passportId])
|
|
35
43
|
const claims = useLoad(() => api.passportClaims(passportId), [passportId])
|
|
36
44
|
const [dialog, setDialog] = useState<DialogKind>()
|
|
45
|
+
const [declaring, setDeclaring] = useState<LifecycleClaimView>()
|
|
37
46
|
|
|
38
47
|
if (passport.loading) return <Loading what="Loading the passport" />
|
|
39
48
|
if (passport.error != null || passport.data == null) return <ErrorNotice error={passport.error ?? new Error('no answer')} title="Could not load the passport" />
|
|
@@ -41,9 +50,14 @@ function PassportPage() {
|
|
|
41
50
|
const view = passport.data
|
|
42
51
|
const needsClaimCode = view.holder.party.startsWith('recipient:')
|
|
43
52
|
const retired = view.status === 'retired'
|
|
53
|
+
// A passport under a retired profile is shown as it was written. The API refuses every write for it, so none is offered.
|
|
54
|
+
const profileRetired = view.profileRetired
|
|
55
|
+
const closed = view.status !== 'active' || profileRetired != null || view.states.some((s) => s.network !== 'accepted' && s.network !== 'dry-run')
|
|
44
56
|
const ident = parseIdentifier(view.passportId)
|
|
45
57
|
const publicPath = publicPathOf(view.passportId)
|
|
46
58
|
const close = () => setDialog(undefined)
|
|
59
|
+
// Under a profile held by a binding the payload is one product document, split into a public and a restricted part.
|
|
60
|
+
const bound = boundPayload(view.payload)
|
|
47
61
|
|
|
48
62
|
return (
|
|
49
63
|
<div className="space-y-10">
|
|
@@ -81,6 +95,17 @@ function PassportPage() {
|
|
|
81
95
|
</span>
|
|
82
96
|
</div>
|
|
83
97
|
|
|
98
|
+
{profileRetired == null ? null : (
|
|
99
|
+
<Alert>
|
|
100
|
+
<AlertTitle>Profile {view.profile} is retired</AlertTitle>
|
|
101
|
+
<AlertDescription>
|
|
102
|
+
<p>
|
|
103
|
+
This passport stays as it was written, and its product data is not checked against the retired profile. No further state, hand-on or claim is made for it. {profileRetired.replacedBy} replaces the profile, and nothing converts this passport: issue a new one under the replacement.
|
|
104
|
+
</p>
|
|
105
|
+
</AlertDescription>
|
|
106
|
+
</Alert>
|
|
107
|
+
)}
|
|
108
|
+
|
|
84
109
|
{needsClaimCode ? (
|
|
85
110
|
<Alert>
|
|
86
111
|
<AlertTitle>Held by a recipient</AlertTitle>
|
|
@@ -91,24 +116,29 @@ function PassportPage() {
|
|
|
91
116
|
) : null}
|
|
92
117
|
|
|
93
118
|
<div className="flex flex-wrap gap-2">
|
|
94
|
-
<Button onClick={() => setDialog('update')} disabled={
|
|
119
|
+
<Button onClick={() => setDialog('update')} disabled={closed}>
|
|
95
120
|
Update
|
|
96
121
|
</Button>
|
|
97
|
-
<Button variant="outline" onClick={() => setDialog('offer')} disabled={
|
|
122
|
+
<Button variant="outline" onClick={() => setDialog('offer')} disabled={closed}>
|
|
98
123
|
Hand on
|
|
99
124
|
</Button>
|
|
100
|
-
<Button variant="outline" onClick={() => setDialog('retire')} disabled={
|
|
125
|
+
<Button variant="outline" onClick={() => setDialog('retire')} disabled={closed}>
|
|
101
126
|
Retire
|
|
102
127
|
</Button>
|
|
103
|
-
<Button variant="outline" onClick={() => setDialog('claim')}>
|
|
104
|
-
|
|
128
|
+
<Button variant="outline" onClick={() => setDialog('claim')} disabled={profileRetired != null}>
|
|
129
|
+
Sign a lifecycle claim
|
|
105
130
|
</Button>
|
|
106
131
|
{retired ? <span className="self-center text-sm text-muted-foreground">Retired: no further state can be written.</span> : null}
|
|
107
132
|
</div>
|
|
108
133
|
|
|
109
|
-
<
|
|
110
|
-
|
|
111
|
-
|
|
134
|
+
<RecordNotice payload={view.payload} />
|
|
135
|
+
{bound == null ? (
|
|
136
|
+
<Section title="Public payload">
|
|
137
|
+
<DefinitionList entries={entriesOf(view.payload, new Set(['notice']), humanise)} />
|
|
138
|
+
</Section>
|
|
139
|
+
) : (
|
|
140
|
+
<HolderReading passportId={view.passportId} payload={bound} needsClaimCode={needsClaimCode} />
|
|
141
|
+
)}
|
|
112
142
|
|
|
113
143
|
<Section title="Journal">
|
|
114
144
|
<div className="grid grid-cols-2 gap-3 sm:grid-cols-4">
|
|
@@ -211,50 +241,44 @@ function PassportPage() {
|
|
|
211
241
|
)}
|
|
212
242
|
</Section>
|
|
213
243
|
|
|
214
|
-
<Section title="
|
|
244
|
+
<Section title="Lifecycle claims">
|
|
215
245
|
{claims.loading ? (
|
|
216
246
|
<Loading what="Loading the claims" />
|
|
217
247
|
) : claims.error != null || claims.data == null ? (
|
|
218
248
|
<ErrorNotice error={claims.error ?? new Error('no answer')} title="Could not load the claims" />
|
|
219
|
-
) : claims.data.length === 0 ? (
|
|
220
|
-
<p className="text-sm text-muted-foreground">No claims. A claim is a signed statement about the passport on its own rail; it never spends the passport.</p>
|
|
221
249
|
) : (
|
|
222
|
-
<
|
|
223
|
-
<TableHeader>
|
|
224
|
-
<TableRow>
|
|
225
|
-
<TableHead>Event</TableHead>
|
|
226
|
-
<TableHead>When</TableHead>
|
|
227
|
-
<TableHead>Issued by</TableHead>
|
|
228
|
-
<TableHead>Signature</TableHead>
|
|
229
|
-
<TableHead>Registry</TableHead>
|
|
230
|
-
</TableRow>
|
|
231
|
-
</TableHeader>
|
|
232
|
-
<TableBody>
|
|
233
|
-
{claims.data.map((claim) => (
|
|
234
|
-
<TableRow key={claim.id}>
|
|
235
|
-
<TableCell>
|
|
236
|
-
{claim.claim.eventType}
|
|
237
|
-
<div className="text-xs text-muted-foreground">{claim.id}</div>
|
|
238
|
-
</TableCell>
|
|
239
|
-
<TableCell>{formatTime(claim.claim.timestamp)}</TableCell>
|
|
240
|
-
<TableCell>{claim.issuedBy}</TableCell>
|
|
241
|
-
<TableCell>
|
|
242
|
-
<ToneBadge tone={claim.verified === 'verified' ? 'pass' : 'fail'}>{claim.verified}</ToneBadge>
|
|
243
|
-
</TableCell>
|
|
244
|
-
<TableCell className="whitespace-normal">
|
|
245
|
-
<RegistryAnswer claim={claim} />
|
|
246
|
-
</TableCell>
|
|
247
|
-
</TableRow>
|
|
248
|
-
))}
|
|
249
|
-
</TableBody>
|
|
250
|
-
</Table>
|
|
250
|
+
<LifecycleClaims reading={claims.data} onDeclareError={closed ? undefined : setDeclaring} emptyText="No lifecycle claim concerns this passport. A claim is one EPCIS event a named party signed, on its own rail; it never spends the passport." />
|
|
251
251
|
)}
|
|
252
252
|
</Section>
|
|
253
253
|
|
|
254
|
-
{
|
|
255
|
-
|
|
254
|
+
{/* Kept apart from everything above. The sections above are this passport's own record: states its holder signed and claims their issuers signed. What follows is data other parties supplied, and none of it is signed. */}
|
|
255
|
+
<Section title="Events that name this product">
|
|
256
|
+
<div className="space-y-3 rounded-lg border border-dashed p-4">
|
|
257
|
+
<SuppliedDataNotice />
|
|
258
|
+
<p className="text-sm text-muted-foreground">
|
|
259
|
+
This list is separate from the passport's own record above. It changes nothing in it: an event here moved no custody and wrote no state. Events are found under the exact identifier they write. Searched:{' '}
|
|
260
|
+
{passportSpellings(view.passportId).map((spelling, i) => (
|
|
261
|
+
<span key={spelling}>
|
|
262
|
+
{i === 0 ? null : ' and '}
|
|
263
|
+
<Mono>{spelling}</Mono>
|
|
264
|
+
</span>
|
|
265
|
+
))}
|
|
266
|
+
. An event that writes this product another way, as an EPC URN for one, is found on the{' '}
|
|
267
|
+
<Link to="/events" className="underline underline-offset-4">
|
|
268
|
+
Events page
|
|
269
|
+
</Link>
|
|
270
|
+
.
|
|
271
|
+
</p>
|
|
272
|
+
<EventsNaming identifiers={passportSpellings(view.passportId)} />
|
|
273
|
+
</div>
|
|
274
|
+
</Section>
|
|
275
|
+
|
|
276
|
+
{dialog === 'update' && bound == null ? <UpdateDialog passport={view} needsClaimCode={needsClaimCode} onClose={close} onDone={passport.setData} /> : null}
|
|
277
|
+
{dialog === 'update' && bound != null ? <BoundUpdateDialog passport={view} publicProduct={bound.product} needsClaimCode={needsClaimCode} onClose={close} onDone={passport.setData} /> : null}
|
|
278
|
+
{dialog === 'offer' ? <HandOnDialog passportId={view.passportId} needsClaimCode={needsClaimCode} onClose={close} refreshOffers={offers.reload} /> : null}
|
|
256
279
|
{dialog === 'retire' ? <RetireDialog passportId={view.passportId} needsClaimCode={needsClaimCode} onClose={close} onDone={passport.setData} /> : null}
|
|
257
280
|
{dialog === 'claim' ? <ClaimDialog passportId={view.passportId} onClose={close} onDone={claims.reload} /> : null}
|
|
281
|
+
{declaring == null ? null : <DeclareErrorDialog passportId={view.passportId} claim={declaring} onClose={() => setDeclaring(undefined)} onDone={claims.reload} />}
|
|
258
282
|
</div>
|
|
259
283
|
)
|
|
260
284
|
}
|
|
@@ -268,35 +292,23 @@ function Stat({ label, value }: { label: string; value: ReactNode }) {
|
|
|
268
292
|
)
|
|
269
293
|
}
|
|
270
294
|
|
|
271
|
-
function
|
|
272
|
-
if (claim.registry == null) return <span className="text-muted-foreground">not sent</span>
|
|
273
|
-
return (
|
|
274
|
-
<span className="text-xs">
|
|
275
|
-
<ToneBadge tone={claim.registry.accepted ? 'pass' : 'fail'}>{claim.registry.accepted ? 'accepted' : `HTTP ${claim.registry.status}`}</ToneBadge>
|
|
276
|
-
{claim.registry.attestationId == null ? null : <span className="ml-2 font-mono">{claim.registry.attestationId}</span>}
|
|
277
|
-
{claim.registry.detail == null ? null : <div className="mt-1 text-muted-foreground">{claim.registry.detail}</div>}
|
|
278
|
-
</span>
|
|
279
|
-
)
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
function ClaimCodeField({ value, onChange }: { value: string; onChange: (value: string) => void }) {
|
|
295
|
+
function ClaimCodeField({ value, onChange, disabled = false }: { value: string; onChange: (value: string) => void; disabled?: boolean }) {
|
|
283
296
|
return (
|
|
284
297
|
<Field label="Claim code" htmlFor="claimCode" required help="The holder acts with the claim code they accepted with.">
|
|
285
|
-
<Input id="claimCode" value={value} onChange={(e) => onChange(e.target.value)} required autoComplete="off" spellCheck={false} />
|
|
298
|
+
<Input id="claimCode" disabled={disabled} value={value} onChange={(e) => onChange(e.target.value)} required autoComplete="off" spellCheck={false} />
|
|
286
299
|
</Field>
|
|
287
300
|
)
|
|
288
301
|
}
|
|
289
302
|
|
|
290
|
-
function WithdrawButton({ offer, needsClaimCode, onDone }: { offer: OfferView; needsClaimCode: boolean; onDone: () => void }) {
|
|
291
|
-
const [claimCode, setClaimCode] = useState('')
|
|
303
|
+
function WithdrawButton({ offer, needsClaimCode, holderClaimCode, onDone }: { offer: OfferView; needsClaimCode: boolean; holderClaimCode?: string; onDone: (withdrawn: OfferView) => void }) {
|
|
304
|
+
const [claimCode, setClaimCode] = useState(holderClaimCode ?? '')
|
|
292
305
|
const [busy, setBusy] = useState(false)
|
|
293
306
|
const [error, setError] = useState<unknown>()
|
|
294
307
|
async function withdraw() {
|
|
295
308
|
setBusy(true)
|
|
296
309
|
setError(undefined)
|
|
297
310
|
try {
|
|
298
|
-
await api.withdrawOffer(offer.requestId, needsClaimCode ? claimCode : undefined)
|
|
299
|
-
onDone()
|
|
311
|
+
onDone(await api.withdrawOffer(offer.requestId, needsClaimCode ? claimCode : undefined))
|
|
300
312
|
} catch (cause) {
|
|
301
313
|
setError(cause)
|
|
302
314
|
} finally {
|
|
@@ -306,7 +318,7 @@ function WithdrawButton({ offer, needsClaimCode, onDone }: { offer: OfferView; n
|
|
|
306
318
|
return (
|
|
307
319
|
<div className="flex flex-col items-end gap-1">
|
|
308
320
|
<div className="flex items-center gap-2">
|
|
309
|
-
{needsClaimCode ? <Input value={claimCode} onChange={(e) => setClaimCode(e.target.value)} placeholder="Claim code" className="h-8 w-40" aria-label="Claim code" /> : null}
|
|
321
|
+
{needsClaimCode && holderClaimCode == null ? <Input value={claimCode} onChange={(e) => setClaimCode(e.target.value)} placeholder="Claim code" className="h-8 w-40" aria-label="Claim code" /> : null}
|
|
310
322
|
<Button variant="outline" size="sm" onClick={withdraw} disabled={busy || (needsClaimCode && claimCode === '')}>
|
|
311
323
|
{busy ? 'Working' : 'Withdraw'}
|
|
312
324
|
</Button>
|
|
@@ -351,7 +363,7 @@ function UpdateDialog({ passport, needsClaimCode, onClose, onDone }: { passport:
|
|
|
351
363
|
</Alert>
|
|
352
364
|
{profile.loading ? (
|
|
353
365
|
<Loading what="Loading the profile" />
|
|
354
|
-
) : profile.error != null || profile.data == null ? (
|
|
366
|
+
) : profile.error != null || profile.data == null || profile.data.format !== 'manifest' ? (
|
|
355
367
|
<ErrorNotice error={profile.error ?? new Error('no answer')} title={`Could not load ${passport.profile}`} />
|
|
356
368
|
) : (
|
|
357
369
|
<PassportForm
|
|
@@ -369,7 +381,100 @@ function UpdateDialog({ passport, needsClaimCode, onClose, onDone }: { passport:
|
|
|
369
381
|
)
|
|
370
382
|
}
|
|
371
383
|
|
|
372
|
-
|
|
384
|
+
/**
|
|
385
|
+
* An update under a profile held by a binding: a new complete product
|
|
386
|
+
* document. The form starts from the document as it stands, which needs the
|
|
387
|
+
* restricted part opened. Where it cannot be opened the form starts from
|
|
388
|
+
* the public part and says what that means.
|
|
389
|
+
*/
|
|
390
|
+
function BoundUpdateDialog({ passport, publicProduct, needsClaimCode, onClose, onDone }: { passport: PassportView; publicProduct: Record<string, unknown>; needsClaimCode: boolean; onClose: () => void; onDone: (view: PassportView) => void }) {
|
|
391
|
+
const { health } = useHealth()
|
|
392
|
+
const profile = useLoad(() => api.profile(passport.profile), [passport.profile])
|
|
393
|
+
const [claimCode, setClaimCode] = useState('')
|
|
394
|
+
const [opened, setOpened] = useState<{ reading?: AuthorisedReading; error?: unknown }>()
|
|
395
|
+
const [busy, setBusy] = useState(false)
|
|
396
|
+
const [error, setError] = useState<unknown>()
|
|
397
|
+
// A brand member's restricted part is opened straight away; a recipient gives the claim code first.
|
|
398
|
+
const auto = useLoad(() => (needsClaimCode ? Promise.resolve(undefined) : api.authorisedView(passport.passportId)), [passport.passportId, needsClaimCode])
|
|
399
|
+
const reading = opened?.reading ?? auto.data
|
|
400
|
+
const ready = needsClaimCode ? opened != null : !auto.loading
|
|
401
|
+
|
|
402
|
+
async function open(event: FormEvent) {
|
|
403
|
+
event.preventDefault()
|
|
404
|
+
try {
|
|
405
|
+
setOpened({ reading: await api.authorisedView(passport.passportId, claimCode) })
|
|
406
|
+
} catch (cause) {
|
|
407
|
+
setOpened({ error: cause })
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
async function submit(submission: BoundSubmission) {
|
|
412
|
+
setBusy(true)
|
|
413
|
+
setError(undefined)
|
|
414
|
+
try {
|
|
415
|
+
const view = await api.updatePassport(passport.passportId, { product: submission.product, ...(needsClaimCode ? { claimCode } : {}) })
|
|
416
|
+
onDone(view)
|
|
417
|
+
onClose()
|
|
418
|
+
} catch (cause) {
|
|
419
|
+
setError(cause)
|
|
420
|
+
} finally {
|
|
421
|
+
setBusy(false)
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
const whole = reading?.product
|
|
426
|
+
return (
|
|
427
|
+
<Dialog open onOpenChange={(open) => (open ? undefined : onClose())}>
|
|
428
|
+
<DialogContent className="max-h-[90vh] overflow-y-auto sm:max-w-4xl">
|
|
429
|
+
<DialogHeader>
|
|
430
|
+
<DialogTitle>Update the passport</DialogTitle>
|
|
431
|
+
<DialogDescription>A new state carrying the complete product document you submit. Its public part is written on chain and its restricted part is sealed again.</DialogDescription>
|
|
432
|
+
</DialogHeader>
|
|
433
|
+
{needsClaimCode && opened?.reading == null ? (
|
|
434
|
+
<form onSubmit={open} className="space-y-3">
|
|
435
|
+
<ClaimCodeField value={claimCode} onChange={setClaimCode} />
|
|
436
|
+
{opened?.error == null ? null : <ErrorNotice error={opened.error} title="The restricted part was not opened" />}
|
|
437
|
+
<Button type="submit" variant="outline">
|
|
438
|
+
Open the document
|
|
439
|
+
</Button>
|
|
440
|
+
</form>
|
|
441
|
+
) : null}
|
|
442
|
+
{!ready || profile.loading ? (
|
|
443
|
+
needsClaimCode && opened == null ? null : <Loading what="Loading the document" />
|
|
444
|
+
) : profile.error != null || profile.data == null || profile.data.format !== 'binding' ? (
|
|
445
|
+
<ErrorNotice error={profile.error ?? new Error(`${passport.profile} is not registered in this application, so its documents cannot be written here`)} title={`Could not load ${passport.profile}`} />
|
|
446
|
+
) : (
|
|
447
|
+
<>
|
|
448
|
+
{whole == null ? (
|
|
449
|
+
<Alert>
|
|
450
|
+
<AlertTitle>The restricted part is not filled in</AlertTitle>
|
|
451
|
+
<AlertDescription>
|
|
452
|
+
<p>
|
|
453
|
+
{reading?.authorisedView.summary ?? (auto.error instanceof Error ? auto.error.message : 'The restricted part could not be opened.')} The form starts from the public part alone. What you submit becomes the whole document: a restricted property you do not enter again is no longer
|
|
454
|
+
part of it.
|
|
455
|
+
</p>
|
|
456
|
+
</AlertDescription>
|
|
457
|
+
</Alert>
|
|
458
|
+
) : null}
|
|
459
|
+
<BoundPassportForm
|
|
460
|
+
key={whole == null ? 'public' : 'whole'}
|
|
461
|
+
profile={profile.data as BoundProfile}
|
|
462
|
+
policy={{ host: health?.identifiers.host ?? window.location.host, prefix: health?.identifiers.prefix ?? '952' }}
|
|
463
|
+
passportId={passport.passportId}
|
|
464
|
+
initialProduct={whole ?? publicProduct}
|
|
465
|
+
submitLabel="Write the update"
|
|
466
|
+
busy={busy}
|
|
467
|
+
error={error}
|
|
468
|
+
onSubmit={submit}
|
|
469
|
+
/>
|
|
470
|
+
</>
|
|
471
|
+
)}
|
|
472
|
+
</DialogContent>
|
|
473
|
+
</Dialog>
|
|
474
|
+
)
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
function HandOnDialog({ passportId, needsClaimCode, onClose, refreshOffers }: { passportId: string; needsClaimCode: boolean; onClose: () => void; refreshOffers: () => void }) {
|
|
373
478
|
const [word, setWord] = useState('Handed on')
|
|
374
479
|
const [note, setNote] = useState('')
|
|
375
480
|
const [claimCode, setClaimCode] = useState('')
|
|
@@ -377,21 +482,32 @@ function HandOnDialog({ passportId, needsClaimCode, onClose, onDone }: { passpor
|
|
|
377
482
|
const [error, setError] = useState<unknown>()
|
|
378
483
|
const [result, setResult] = useState<{ offer: OfferView; claimCode?: string }>()
|
|
379
484
|
|
|
485
|
+
const attempt = useRef<{ termsKey: string; requestId: string; pending: boolean } | undefined>(undefined)
|
|
486
|
+
|
|
380
487
|
async function submit(event: FormEvent) {
|
|
381
488
|
event.preventDefault()
|
|
489
|
+
if (attempt.current?.pending) return
|
|
490
|
+
const terms = { word: word.trim(), ...(note.trim() === '' ? {} : { note: note.trim() }) }
|
|
491
|
+
const termsKey = JSON.stringify([passportId, terms])
|
|
492
|
+
if (attempt.current?.termsKey !== termsKey) attempt.current = { termsKey, requestId: crypto.randomUUID(), pending: false }
|
|
493
|
+
const submission = attempt.current
|
|
494
|
+
submission.pending = true
|
|
382
495
|
setBusy(true)
|
|
383
496
|
setError(undefined)
|
|
384
497
|
try {
|
|
385
|
-
const answer = await api.offerPassport(passportId, {
|
|
498
|
+
const answer = await api.offerPassport(passportId, { requestId: submission.requestId, terms, ...(needsClaimCode ? { claimCode } : {}) })
|
|
386
499
|
setResult(answer)
|
|
387
|
-
onDone()
|
|
388
500
|
} catch (cause) {
|
|
389
501
|
setError(cause)
|
|
390
502
|
} finally {
|
|
503
|
+
submission.pending = false
|
|
391
504
|
setBusy(false)
|
|
505
|
+
// The server may have saved the offer even if its response was lost.
|
|
506
|
+
refreshOffers()
|
|
392
507
|
}
|
|
393
508
|
}
|
|
394
509
|
|
|
510
|
+
const open = result?.offer.status === 'open' && Date.parse(result.offer.expiresAt) > Date.now()
|
|
395
511
|
const acceptUrl = result == null ? '' : `${window.location.origin}/accept/${encodeURIComponent(result.offer.requestId)}`
|
|
396
512
|
|
|
397
513
|
return (
|
|
@@ -404,13 +520,13 @@ function HandOnDialog({ passportId, needsClaimCode, onClose, onDone }: { passpor
|
|
|
404
520
|
{result == null ? (
|
|
405
521
|
<form onSubmit={submit} className="space-y-4">
|
|
406
522
|
<Field label="Terms word" htmlFor="offer-word" required help="One word for what is happening, for example Sold or Gifted.">
|
|
407
|
-
<Input id="offer-word" value={word} onChange={(e) => setWord(e.target.value)} required maxLength={40} />
|
|
523
|
+
<Input id="offer-word" disabled={busy} value={word} onChange={(e) => setWord(e.target.value)} required maxLength={40} />
|
|
408
524
|
</Field>
|
|
409
525
|
<Field label="Note" htmlFor="offer-note" help="Shown to the recipient before they decide.">
|
|
410
|
-
<Textarea id="offer-note" value={note} onChange={(e) => setNote(e.target.value)} maxLength={400} />
|
|
526
|
+
<Textarea id="offer-note" disabled={busy} value={note} onChange={(e) => setNote(e.target.value)} maxLength={400} />
|
|
411
527
|
</Field>
|
|
412
|
-
{needsClaimCode ? <ClaimCodeField value={claimCode} onChange={setClaimCode} /> : null}
|
|
413
|
-
{error == null ? null : <ErrorNotice error={error} title="
|
|
528
|
+
{needsClaimCode ? <ClaimCodeField value={claimCode} onChange={setClaimCode} disabled={busy} /> : null}
|
|
529
|
+
{error == null ? null : <ErrorNotice error={error} title="Could not confirm the offer" />}
|
|
414
530
|
<DialogFooter>
|
|
415
531
|
<Button type="submit" disabled={busy || word.trim() === ''}>
|
|
416
532
|
{busy ? 'Working' : 'Make the offer'}
|
|
@@ -419,24 +535,47 @@ function HandOnDialog({ passportId, needsClaimCode, onClose, onDone }: { passpor
|
|
|
419
535
|
</form>
|
|
420
536
|
) : (
|
|
421
537
|
<div className="space-y-4">
|
|
422
|
-
<
|
|
423
|
-
|
|
424
|
-
<div className="mt-1 flex items-center gap-2">
|
|
425
|
-
<code className="text-2xl font-semibold tracking-wider">{result.claimCode ?? 'none'}</code>
|
|
426
|
-
{result.claimCode == null ? null : <CopyButton text={result.claimCode} label="Copy the claim code" />}
|
|
427
|
-
</div>
|
|
428
|
-
<p className="mt-3 text-sm">Give this code to the recipient out of band. It is shown once and never stored.</p>
|
|
429
|
-
</div>
|
|
430
|
-
<Field label="Accept link" help="Where the recipient enters the code.">
|
|
431
|
-
<div className="flex items-center gap-2">
|
|
432
|
-
<Mono>{acceptUrl}</Mono>
|
|
433
|
-
<CopyButton text={acceptUrl} label="Copy the accept link" />
|
|
434
|
-
</div>
|
|
435
|
-
</Field>
|
|
436
|
-
<p className="text-sm text-muted-foreground">
|
|
437
|
-
Offer {result.offer.requestId}, open until {formatTime(result.offer.expiresAt)}.
|
|
538
|
+
<p className="text-sm">
|
|
539
|
+
Offer {result.offer.requestId} is {result.offer.status === 'open' && !open ? 'expired' : result.offer.status}. {open ? `Expires ${formatTime(result.offer.expiresAt)}.` : null}
|
|
438
540
|
</p>
|
|
541
|
+
{result.offer.status === 'open' && result.claimCode == null ? (
|
|
542
|
+
<div className="space-y-2">
|
|
543
|
+
<p>The claim code was returned when this offer was created. If you need a replacement code, withdraw this offer and make a new one.</p>
|
|
544
|
+
<WithdrawButton
|
|
545
|
+
offer={result.offer}
|
|
546
|
+
needsClaimCode={needsClaimCode}
|
|
547
|
+
holderClaimCode={claimCode}
|
|
548
|
+
onDone={(offer) => {
|
|
549
|
+
setResult({ offer })
|
|
550
|
+
refreshOffers()
|
|
551
|
+
}}
|
|
552
|
+
/>
|
|
553
|
+
</div>
|
|
554
|
+
) : null}
|
|
555
|
+
{open ? (
|
|
556
|
+
<>
|
|
557
|
+
{result.claimCode != null ? (
|
|
558
|
+
<div className="rounded-lg border-2 border-amber-400 bg-amber-50 p-4 dark:border-amber-700 dark:bg-amber-950">
|
|
559
|
+
<p className="text-xs font-medium uppercase tracking-wide text-muted-foreground">Claim code</p>
|
|
560
|
+
<div className="mt-1 flex items-center gap-2">
|
|
561
|
+
<code className="text-2xl font-semibold tracking-wider">{result.claimCode}</code>
|
|
562
|
+
<CopyButton text={result.claimCode} label="Copy the claim code" />
|
|
563
|
+
</div>
|
|
564
|
+
<p className="mt-3 text-sm">Give this code to the recipient out of band. It is shown once and never stored.</p>
|
|
565
|
+
</div>
|
|
566
|
+
) : null}
|
|
567
|
+
<Field label="Accept link" help="Where the recipient enters the code.">
|
|
568
|
+
<div className="flex items-center gap-2">
|
|
569
|
+
<Mono>{acceptUrl}</Mono>
|
|
570
|
+
<CopyButton text={acceptUrl} label="Copy the accept link" />
|
|
571
|
+
</div>
|
|
572
|
+
</Field>
|
|
573
|
+
</>
|
|
574
|
+
) : null}
|
|
439
575
|
<DialogFooter>
|
|
576
|
+
{result.offer.status === 'withdrawn' ? (
|
|
577
|
+
<Button variant="outline" onClick={() => { attempt.current = undefined; setResult(undefined) }}>Make a new offer</Button>
|
|
578
|
+
) : null}
|
|
440
579
|
<Button onClick={onClose}>Done</Button>
|
|
441
580
|
</DialogFooter>
|
|
442
581
|
</div>
|
|
@@ -491,78 +630,3 @@ function RetireDialog({ passportId, needsClaimCode, onClose, onDone }: { passpor
|
|
|
491
630
|
)
|
|
492
631
|
}
|
|
493
632
|
|
|
494
|
-
function ClaimDialog({ passportId, onClose, onDone }: { passportId: string; onClose: () => void; onDone: () => void }) {
|
|
495
|
-
const [eventType, setEventType] = useState<EventType>('Origin')
|
|
496
|
-
const [submitToRegistry, setSubmitToRegistry] = useState(false)
|
|
497
|
-
const [busy, setBusy] = useState(false)
|
|
498
|
-
const [error, setError] = useState<unknown>()
|
|
499
|
-
const [result, setResult] = useState<ClaimView>()
|
|
500
|
-
|
|
501
|
-
async function submit(event: FormEvent) {
|
|
502
|
-
event.preventDefault()
|
|
503
|
-
setBusy(true)
|
|
504
|
-
setError(undefined)
|
|
505
|
-
try {
|
|
506
|
-
const claim = await api.addClaim(passportId, { eventType, ...(submitToRegistry ? { submit: true } : {}) })
|
|
507
|
-
setResult(claim)
|
|
508
|
-
onDone()
|
|
509
|
-
} catch (cause) {
|
|
510
|
-
setError(cause)
|
|
511
|
-
} finally {
|
|
512
|
-
setBusy(false)
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
return (
|
|
517
|
-
<Dialog open onOpenChange={(open) => (open ? undefined : onClose())}>
|
|
518
|
-
<DialogContent>
|
|
519
|
-
<DialogHeader>
|
|
520
|
-
<DialogTitle>Add a claim</DialogTitle>
|
|
521
|
-
<DialogDescription>A signed statement about the passport's current state, on its own rail. It never spends the passport.</DialogDescription>
|
|
522
|
-
</DialogHeader>
|
|
523
|
-
{result == null ? (
|
|
524
|
-
<form onSubmit={submit} className="space-y-4">
|
|
525
|
-
<Field label="Event type" htmlFor="claim-event" required>
|
|
526
|
-
<Select value={eventType} onValueChange={(v) => setEventType(v as EventType)}>
|
|
527
|
-
<SelectTrigger id="claim-event" className="w-full">
|
|
528
|
-
<SelectValue />
|
|
529
|
-
</SelectTrigger>
|
|
530
|
-
<SelectContent>
|
|
531
|
-
{EVENT_TYPES.map((t) => (
|
|
532
|
-
<SelectItem key={t} value={t}>
|
|
533
|
-
{t}
|
|
534
|
-
</SelectItem>
|
|
535
|
-
))}
|
|
536
|
-
</SelectContent>
|
|
537
|
-
</Select>
|
|
538
|
-
</Field>
|
|
539
|
-
<label className="flex items-center gap-2 text-sm">
|
|
540
|
-
<input type="checkbox" checked={submitToRegistry} onChange={(e) => setSubmitToRegistry(e.target.checked)} />
|
|
541
|
-
Send to the registry
|
|
542
|
-
</label>
|
|
543
|
-
{error == null ? null : <ErrorNotice error={error} title="The claim was refused" />}
|
|
544
|
-
<DialogFooter>
|
|
545
|
-
<Button type="submit" disabled={busy}>
|
|
546
|
-
{busy ? 'Working' : 'Sign the claim'}
|
|
547
|
-
</Button>
|
|
548
|
-
</DialogFooter>
|
|
549
|
-
</form>
|
|
550
|
-
) : (
|
|
551
|
-
<div className="space-y-4">
|
|
552
|
-
<DefinitionList
|
|
553
|
-
entries={[
|
|
554
|
-
['Claim', <Mono key="id">{result.id}</Mono>],
|
|
555
|
-
['Event', result.claim.eventType],
|
|
556
|
-
['Signature', <ToneBadge key="v" tone={result.verified == null || result.verified === 'verified' ? 'pass' : 'fail'}>{result.verified ?? 'signed'}</ToneBadge>],
|
|
557
|
-
['Registry', <RegistryAnswer key="r" claim={result} />],
|
|
558
|
-
]}
|
|
559
|
-
/>
|
|
560
|
-
<DialogFooter>
|
|
561
|
-
<Button onClick={onClose}>Done</Button>
|
|
562
|
-
</DialogFooter>
|
|
563
|
-
</div>
|
|
564
|
-
)}
|
|
565
|
-
</DialogContent>
|
|
566
|
-
</Dialog>
|
|
567
|
-
)
|
|
568
|
-
}
|
|
@@ -1,24 +1,64 @@
|
|
|
1
|
-
// The public
|
|
2
|
-
// identifier
|
|
3
|
-
// the
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
// The public pages, where the resolver sends a browser that asked for an
|
|
2
|
+
// identifier: /passport/01/<gtin>/21/<serial> for an item's passport, and
|
|
3
|
+
// /passport/01/<gtin> for the product. The identifier is the platform's
|
|
4
|
+
// passport host plus the path after /passport, which is what the brand
|
|
5
|
+
// minted; in development the API's host may differ from the Vite origin, so
|
|
6
|
+
// the host comes from /api/health before the origin is assumed.
|
|
7
|
+
import { Link, useLocation, useParams } from 'react-router'
|
|
8
|
+
import { Button } from '@/components/ui/button'
|
|
9
|
+
import { CopyButton, ErrorNotice, Loading, Mono, PageTitle } from '@/components/bits'
|
|
7
10
|
import { ReadPassport } from '@/components/read-passport'
|
|
11
|
+
import { PAGE_PREFIX } from '@/lib/format'
|
|
8
12
|
import { useHealth } from '@/lib/session'
|
|
9
13
|
|
|
10
|
-
|
|
14
|
+
/** The identifier a public page is about: the passport host, or this origin when the API has not said, and the page's path without its prefix. */
|
|
15
|
+
function useIdentifier(): { identifier: string; loading: boolean; error: unknown } {
|
|
11
16
|
const { health, loading, error } = useHealth()
|
|
12
17
|
const location = useLocation()
|
|
18
|
+
const host = health?.identifiers.host
|
|
19
|
+
const path = location.pathname.slice(PAGE_PREFIX.length)
|
|
20
|
+
return { identifier: host == null || host === '' ? `${window.location.origin}${path}` : `https://${host}${path}`, loading, error }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function PublicPassport() {
|
|
24
|
+
const { identifier, loading, error } = useIdentifier()
|
|
13
25
|
|
|
14
26
|
if (loading) return <Loading what="Reading the passport" />
|
|
15
|
-
const host = health?.identifiers.host
|
|
16
|
-
const passportId = host == null || host === '' ? `${window.location.origin}${location.pathname}` : `https://${host}${location.pathname}`
|
|
17
27
|
|
|
18
28
|
return (
|
|
19
29
|
<div className="mx-auto max-w-2xl space-y-6">
|
|
20
30
|
{error == null ? null : <ErrorNotice error={error} title="The API is not answering" />}
|
|
21
|
-
<ReadPassport passportId={
|
|
31
|
+
<ReadPassport passportId={identifier} />
|
|
32
|
+
</div>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The page a product's identifier leads to. A passport belongs to one item, so this page holds none: it says what the identifier names and where an item's passport is found. */
|
|
37
|
+
export function PublicProduct() {
|
|
38
|
+
const { identifier, loading, error } = useIdentifier()
|
|
39
|
+
const { gtin } = useParams()
|
|
40
|
+
|
|
41
|
+
if (loading) return <Loading />
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<div className="mx-auto max-w-2xl space-y-6">
|
|
45
|
+
{error == null ? null : <ErrorNotice error={error} title="The API is not answering" />}
|
|
46
|
+
<PageTitle
|
|
47
|
+
title={`GTIN ${gtin ?? ''}`}
|
|
48
|
+
description={
|
|
49
|
+
<span className="flex flex-wrap items-center gap-2">
|
|
50
|
+
<Mono>{identifier}</Mono>
|
|
51
|
+
<CopyButton text={identifier} label="Copy the identifier" />
|
|
52
|
+
</span>
|
|
53
|
+
}
|
|
54
|
+
/>
|
|
55
|
+
<p className="text-sm leading-relaxed">
|
|
56
|
+
This identifier names a product, not one item of it. A passport belongs to one item and is found under the item's own identifier, which ends with its serial: <Mono>{identifier}/21/<serial></Mono>. Scan the code on the item, or paste its
|
|
57
|
+
identifier to verify it.
|
|
58
|
+
</p>
|
|
59
|
+
<Button asChild variant="outline">
|
|
60
|
+
<Link to="/verify">Verify a passport</Link>
|
|
61
|
+
</Button>
|
|
22
62
|
</div>
|
|
23
63
|
)
|
|
24
64
|
}
|
|
@@ -58,7 +58,7 @@ function WalletPage() {
|
|
|
58
58
|
|
|
59
59
|
return (
|
|
60
60
|
<div className="space-y-10">
|
|
61
|
-
<PageTitle title="Wallet" description="The platform wallet publishes
|
|
61
|
+
<PageTitle title="Wallet" description="The platform wallet publishes passport states and pays the fees. The current holder’s managed key controls each new passport output." />
|
|
62
62
|
{wallet.loading ? (
|
|
63
63
|
<Loading what="Loading the wallet" />
|
|
64
64
|
) : wallet.error != null || wallet.data == null ? (
|