@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,388 @@
|
|
|
1
|
+
// EPCIS events: upload a document, pull from a configured source, find the
|
|
2
|
+
// events that name an identifier, and download what was received.
|
|
3
|
+
//
|
|
4
|
+
// Everything on this page is data a source supplied. Nothing here signs,
|
|
5
|
+
// issues or changes a passport, and the page says so wherever an outcome is
|
|
6
|
+
// shown.
|
|
7
|
+
import { Fragment, useState, type FormEvent } from 'react'
|
|
8
|
+
import { Download } from 'lucide-react'
|
|
9
|
+
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
|
|
10
|
+
import { Button } from '@/components/ui/button'
|
|
11
|
+
import { Input } from '@/components/ui/input'
|
|
12
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
|
13
|
+
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'
|
|
14
|
+
import { Textarea } from '@/components/ui/textarea'
|
|
15
|
+
import { ErrorNotice, Field, Loading, Mono, PageTitle, Section, ToneBadge } from '@/components/bits'
|
|
16
|
+
import { DescribedBox, EventsNaming, SuppliedDataNotice } from '@/components/epcis-events'
|
|
17
|
+
import { RequireAccount } from '@/components/layout'
|
|
18
|
+
import { ApiError, api } from '@/lib/api'
|
|
19
|
+
import {
|
|
20
|
+
countsLine,
|
|
21
|
+
describePull,
|
|
22
|
+
describePullRefusal,
|
|
23
|
+
describeRefusal,
|
|
24
|
+
describeRetained,
|
|
25
|
+
describeSource,
|
|
26
|
+
eventCounts,
|
|
27
|
+
findingsOf,
|
|
28
|
+
latestFirst,
|
|
29
|
+
mediaTypeOf,
|
|
30
|
+
originalPath,
|
|
31
|
+
provenanceLabel,
|
|
32
|
+
queryFromForm,
|
|
33
|
+
validityLabel,
|
|
34
|
+
type Described,
|
|
35
|
+
type EpcisImportRecord,
|
|
36
|
+
type EpcisImportSummary,
|
|
37
|
+
type EpcisSource,
|
|
38
|
+
} from '@/lib/epcis'
|
|
39
|
+
import { formatTime } from '@/lib/format'
|
|
40
|
+
import { useLoad } from '@/lib/use-load'
|
|
41
|
+
|
|
42
|
+
export function Events() {
|
|
43
|
+
return (
|
|
44
|
+
<RequireAccount>
|
|
45
|
+
<EventsPage />
|
|
46
|
+
</RequireAccount>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** An identifier for one upload. It stays with the chosen file, so sending the file again is the same request and is kept once. */
|
|
51
|
+
const newRequestId = (): string => `upload-${crypto.randomUUID()}`
|
|
52
|
+
|
|
53
|
+
/** An error the API did not describe is shown as it is. */
|
|
54
|
+
const unexpected = (cause: unknown, what: string): Described => ({ tone: 'fail', title: what, lines: [cause instanceof Error ? cause.message : String(cause)] })
|
|
55
|
+
|
|
56
|
+
function EventsPage() {
|
|
57
|
+
const status = useLoad(() => api.epcisStatus(), [])
|
|
58
|
+
const imports = useLoad(async () => latestFirst((await api.epcisImports()).imports), [])
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<div className="space-y-10">
|
|
62
|
+
<PageTitle
|
|
63
|
+
title="Events"
|
|
64
|
+
description="EPCIS events this application holds: documents you upload, and pages pulled from a source your server is configured for. An import keeps the exact bytes it was given. It signs nothing and changes no passport."
|
|
65
|
+
/>
|
|
66
|
+
<SuppliedDataNotice />
|
|
67
|
+
{status.data?.artefacts.state === 'unavailable' ? (
|
|
68
|
+
<Alert variant="destructive">
|
|
69
|
+
<AlertTitle>Imports and pulls are refused until the GS1 files are provided</AlertTitle>
|
|
70
|
+
<AlertDescription>
|
|
71
|
+
<p>
|
|
72
|
+
Documents are checked against the EPCIS files GS1 publishes, and this server does not have them in <Mono>{status.data.artefacts.dir}</Mono>. {status.data.artefacts.remedy}
|
|
73
|
+
</p>
|
|
74
|
+
</AlertDescription>
|
|
75
|
+
</Alert>
|
|
76
|
+
) : null}
|
|
77
|
+
{status.data?.storage === 'memory' ? <p className="text-sm text-muted-foreground">Without MongoDB, what is imported here is held in memory and is gone when the API stops.</p> : null}
|
|
78
|
+
|
|
79
|
+
<Upload onDone={imports.reload} />
|
|
80
|
+
<Pull sources={status.data?.sources} loading={status.loading} error={status.error} onDone={imports.reload} />
|
|
81
|
+
<Find />
|
|
82
|
+
|
|
83
|
+
<Section title="Imports">
|
|
84
|
+
{imports.loading ? (
|
|
85
|
+
<Loading what="Loading the imports" />
|
|
86
|
+
) : imports.error != null || imports.data == null ? (
|
|
87
|
+
<ErrorNotice error={imports.error ?? new Error('no answer')} title="Could not load the imports" />
|
|
88
|
+
) : imports.data.length === 0 ? (
|
|
89
|
+
<p className="text-sm text-muted-foreground">Nothing has been imported.</p>
|
|
90
|
+
) : (
|
|
91
|
+
<ImportTable imports={imports.data} />
|
|
92
|
+
)}
|
|
93
|
+
</Section>
|
|
94
|
+
</div>
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function Upload({ onDone }: { onDone: () => void }) {
|
|
99
|
+
const [file, setFile] = useState<File>()
|
|
100
|
+
const [requestId, setRequestId] = useState('')
|
|
101
|
+
const [sourceId, setSourceId] = useState('upload')
|
|
102
|
+
const [busy, setBusy] = useState(false)
|
|
103
|
+
const [outcome, setOutcome] = useState<Described>()
|
|
104
|
+
const [record, setRecord] = useState<EpcisImportRecord>()
|
|
105
|
+
|
|
106
|
+
function choose(chosen: File | undefined) {
|
|
107
|
+
setFile(chosen)
|
|
108
|
+
setOutcome(undefined)
|
|
109
|
+
setRecord(undefined)
|
|
110
|
+
// A new file is a new request. The same file sent again keeps the identifier it was given here.
|
|
111
|
+
setRequestId(chosen == null ? '' : newRequestId())
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function send(event: FormEvent) {
|
|
115
|
+
event.preventDefault()
|
|
116
|
+
if (file == null) return
|
|
117
|
+
setBusy(true)
|
|
118
|
+
setOutcome(undefined)
|
|
119
|
+
setRecord(undefined)
|
|
120
|
+
try {
|
|
121
|
+
const answer = await api.epcisImport(file, { requestId, mediaType: mediaTypeOf(file), sourceId: sourceId.trim(), filename: file.name })
|
|
122
|
+
setOutcome(describeRetained(answer))
|
|
123
|
+
setRecord(answer.record)
|
|
124
|
+
onDone()
|
|
125
|
+
} catch (cause) {
|
|
126
|
+
setOutcome(cause instanceof ApiError ? describeRefusal(cause) : unexpected(cause, 'The upload did not reach the API. Send it again: it is the same request.'))
|
|
127
|
+
} finally {
|
|
128
|
+
setBusy(false)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<Section title="Upload a document">
|
|
134
|
+
<form onSubmit={send} className="grid gap-4 sm:grid-cols-[2fr_1fr_auto] sm:items-end">
|
|
135
|
+
<Field label="EPCIS 2.0 document" htmlFor="epcis-file" help="A JSON or JSON-LD file. It is sent and kept as the bytes it is.">
|
|
136
|
+
<Input id="epcis-file" type="file" accept=".json,.jsonld,application/json,application/ld+json" onChange={(event) => choose(event.target.files?.[0])} />
|
|
137
|
+
</Field>
|
|
138
|
+
<Field label="Source name" htmlFor="epcis-source" help="Events are filed under it. Two sources are never merged.">
|
|
139
|
+
<Input id="epcis-source" value={sourceId} onChange={(event) => setSourceId(event.target.value)} />
|
|
140
|
+
</Field>
|
|
141
|
+
<Button type="submit" disabled={file == null || busy}>
|
|
142
|
+
{busy ? 'Uploading' : 'Upload'}
|
|
143
|
+
</Button>
|
|
144
|
+
</form>
|
|
145
|
+
{outcome == null ? null : <DescribedBox described={outcome} />}
|
|
146
|
+
{record == null ? null : <ImportFindings record={record} />}
|
|
147
|
+
</Section>
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function Pull({ sources, loading, error, onDone }: { sources: EpcisSource[] | undefined; loading: boolean; error: Error | undefined; onDone: () => void }) {
|
|
152
|
+
const [sourceId, setSourceId] = useState<string>()
|
|
153
|
+
const [queryId, setQueryId] = useState('default')
|
|
154
|
+
const [form, setForm] = useState({ identifiers: '', eventTypes: '', eventIds: '', from: '', until: '', perPage: '' })
|
|
155
|
+
const [busy, setBusy] = useState(false)
|
|
156
|
+
const [outcome, setOutcome] = useState<Described>()
|
|
157
|
+
const selected = sources?.find((source) => source.sourceId === (sourceId ?? sources[0]?.sourceId))
|
|
158
|
+
|
|
159
|
+
async function run(event: FormEvent) {
|
|
160
|
+
event.preventDefault()
|
|
161
|
+
if (selected == null) return
|
|
162
|
+
setBusy(true)
|
|
163
|
+
setOutcome(undefined)
|
|
164
|
+
try {
|
|
165
|
+
setOutcome(describePull(await api.epcisPull(selected.sourceId, { queryId: queryId.trim(), query: queryFromForm(form) })))
|
|
166
|
+
onDone()
|
|
167
|
+
} catch (cause) {
|
|
168
|
+
setOutcome(cause instanceof ApiError ? describePullRefusal(cause) : unexpected(cause, 'The request did not reach the API'))
|
|
169
|
+
} finally {
|
|
170
|
+
setBusy(false)
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return (
|
|
175
|
+
<Section title="Pull from a source">
|
|
176
|
+
{loading ? (
|
|
177
|
+
<Loading what="Loading the sources" />
|
|
178
|
+
) : error != null || sources == null ? (
|
|
179
|
+
<ErrorNotice error={error ?? new Error('no answer')} title="Could not load the sources" />
|
|
180
|
+
) : sources.length === 0 || selected == null ? (
|
|
181
|
+
<p className="text-sm text-muted-foreground">
|
|
182
|
+
No source is configured. A source is set on the server, in <Mono>.env</Mono>: its name in <Mono>EPCIS_SOURCES</Mono>, then its address and, if it needs one, its credential. The README says how.
|
|
183
|
+
</p>
|
|
184
|
+
) : (
|
|
185
|
+
<form onSubmit={run} className="space-y-4">
|
|
186
|
+
<div className="grid gap-4 sm:grid-cols-2">
|
|
187
|
+
<Field label="Source" htmlFor="pull-source">
|
|
188
|
+
<Select value={selected.sourceId} onValueChange={setSourceId}>
|
|
189
|
+
<SelectTrigger id="pull-source" className="w-full">
|
|
190
|
+
<SelectValue />
|
|
191
|
+
</SelectTrigger>
|
|
192
|
+
<SelectContent>
|
|
193
|
+
{sources.map((source) => (
|
|
194
|
+
<SelectItem key={source.sourceId} value={source.sourceId}>
|
|
195
|
+
{source.sourceId}
|
|
196
|
+
</SelectItem>
|
|
197
|
+
))}
|
|
198
|
+
</SelectContent>
|
|
199
|
+
</Select>
|
|
200
|
+
</Field>
|
|
201
|
+
<Field label="Query name" htmlFor="pull-query" help="A later run under the same name continues this query from where it stopped. The same name with other filters is refused.">
|
|
202
|
+
<Input id="pull-query" value={queryId} onChange={(event) => setQueryId(event.target.value)} required />
|
|
203
|
+
</Field>
|
|
204
|
+
</div>
|
|
205
|
+
<div className="space-y-1 rounded-lg border p-3 text-sm">
|
|
206
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
207
|
+
<Mono>{selected.sourceId}</Mono>
|
|
208
|
+
{selected.localTest ? <ToneBadge tone="warn">Local test</ToneBadge> : null}
|
|
209
|
+
{selected.problem == null ? null : <ToneBadge tone="fail">Cannot be pulled from</ToneBadge>}
|
|
210
|
+
</div>
|
|
211
|
+
<ul className="list-disc space-y-1 pl-5 text-muted-foreground">
|
|
212
|
+
{describeSource(selected).map((line, i) => (
|
|
213
|
+
<li key={i} className="break-words">
|
|
214
|
+
{line}
|
|
215
|
+
</li>
|
|
216
|
+
))}
|
|
217
|
+
</ul>
|
|
218
|
+
</div>
|
|
219
|
+
<div className="grid gap-4 sm:grid-cols-2">
|
|
220
|
+
<Field label="Product identifiers" htmlFor="pull-identifiers" help="One a line, exactly as the source writes them. Empty asks for every event.">
|
|
221
|
+
<Textarea id="pull-identifiers" rows={2} value={form.identifiers} onChange={(event) => setForm({ ...form, identifiers: event.target.value })} />
|
|
222
|
+
</Field>
|
|
223
|
+
<Field label="Event types" htmlFor="pull-types" help="Such as ObjectEvent, one a line. Empty asks for every type.">
|
|
224
|
+
<Textarea id="pull-types" rows={2} value={form.eventTypes} onChange={(event) => setForm({ ...form, eventTypes: event.target.value })} />
|
|
225
|
+
</Field>
|
|
226
|
+
<Field label="Event time from" htmlFor="pull-from" help="A date and time with a zone, such as 2026-03-02T08:00:00Z.">
|
|
227
|
+
<Input id="pull-from" value={form.from} onChange={(event) => setForm({ ...form, from: event.target.value })} />
|
|
228
|
+
</Field>
|
|
229
|
+
<Field label="Event time until" htmlFor="pull-until">
|
|
230
|
+
<Input id="pull-until" value={form.until} onChange={(event) => setForm({ ...form, until: event.target.value })} />
|
|
231
|
+
</Field>
|
|
232
|
+
<Field label="Events a page" htmlFor="pull-per-page" help="Empty uses the limit in force.">
|
|
233
|
+
<Input id="pull-per-page" inputMode="numeric" value={form.perPage} onChange={(event) => setForm({ ...form, perPage: event.target.value })} />
|
|
234
|
+
</Field>
|
|
235
|
+
</div>
|
|
236
|
+
<Button type="submit" disabled={busy || queryId.trim() === ''}>
|
|
237
|
+
{busy ? 'Pulling' : 'Run one pull'}
|
|
238
|
+
</Button>
|
|
239
|
+
<p className="text-xs text-muted-foreground">One run reads a bounded number of pages and then stops. Run it again to continue.</p>
|
|
240
|
+
</form>
|
|
241
|
+
)}
|
|
242
|
+
{outcome == null ? null : <DescribedBox described={outcome} />}
|
|
243
|
+
</Section>
|
|
244
|
+
)
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function Find() {
|
|
248
|
+
const [text, setText] = useState('')
|
|
249
|
+
const [granularity, setGranularity] = useState<'instance' | 'class'>('instance')
|
|
250
|
+
const [asked, setAsked] = useState<{ identifier: string; granularity: 'instance' | 'class' }>()
|
|
251
|
+
|
|
252
|
+
function find(event: FormEvent) {
|
|
253
|
+
event.preventDefault()
|
|
254
|
+
if (text.trim() !== '') setAsked({ identifier: text.trim(), granularity })
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return (
|
|
258
|
+
<Section title="Events that name an identifier">
|
|
259
|
+
<form onSubmit={find} className="grid gap-4 sm:grid-cols-[3fr_1fr_auto] sm:items-end">
|
|
260
|
+
<Field label="Identifier" htmlFor="find-identifier" help="Exactly as events write it. Another spelling of the same product is another search.">
|
|
261
|
+
<Input id="find-identifier" value={text} onChange={(event) => setText(event.target.value)} placeholder="urn:epc:id:sgtin:9521234.012345.SER1" />
|
|
262
|
+
</Field>
|
|
263
|
+
<Field label="Names" htmlFor="find-granularity">
|
|
264
|
+
<Select value={granularity} onValueChange={(value) => setGranularity(value === 'class' ? 'class' : 'instance')}>
|
|
265
|
+
<SelectTrigger id="find-granularity" className="w-full">
|
|
266
|
+
<SelectValue />
|
|
267
|
+
</SelectTrigger>
|
|
268
|
+
<SelectContent>
|
|
269
|
+
<SelectItem value="instance">One item</SelectItem>
|
|
270
|
+
<SelectItem value="class">A class or a lot</SelectItem>
|
|
271
|
+
</SelectContent>
|
|
272
|
+
</Select>
|
|
273
|
+
</Field>
|
|
274
|
+
<Button type="submit" variant="outline" disabled={text.trim() === ''}>
|
|
275
|
+
Find
|
|
276
|
+
</Button>
|
|
277
|
+
</form>
|
|
278
|
+
{asked == null ? null : <EventsNaming identifiers={[asked.identifier]} granularity={asked.granularity} />}
|
|
279
|
+
</Section>
|
|
280
|
+
)
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function ImportTable({ imports }: { imports: EpcisImportSummary[] }) {
|
|
284
|
+
const [open, setOpen] = useState<string>()
|
|
285
|
+
return (
|
|
286
|
+
<Table>
|
|
287
|
+
<TableHeader>
|
|
288
|
+
<TableRow>
|
|
289
|
+
<TableHead>Received</TableHead>
|
|
290
|
+
<TableHead>Source</TableHead>
|
|
291
|
+
<TableHead>Format check</TableHead>
|
|
292
|
+
<TableHead className="text-right">Events</TableHead>
|
|
293
|
+
<TableHead className="text-right">Findings</TableHead>
|
|
294
|
+
<TableHead className="text-right">Bytes</TableHead>
|
|
295
|
+
<TableHead>Original</TableHead>
|
|
296
|
+
<TableHead />
|
|
297
|
+
</TableRow>
|
|
298
|
+
</TableHeader>
|
|
299
|
+
<TableBody>
|
|
300
|
+
{imports.map((entry) => {
|
|
301
|
+
const validity = validityLabel(entry.documentValidity)
|
|
302
|
+
return (
|
|
303
|
+
<Fragment key={entry.importId}>
|
|
304
|
+
<TableRow>
|
|
305
|
+
<TableCell>{formatTime(entry.receivedAt)}</TableCell>
|
|
306
|
+
<TableCell className="whitespace-normal">
|
|
307
|
+
<Mono>{entry.sourceId}</Mono>
|
|
308
|
+
<div className="text-xs text-muted-foreground">{provenanceLabel(entry.provenance)}</div>
|
|
309
|
+
</TableCell>
|
|
310
|
+
<TableCell>
|
|
311
|
+
<ToneBadge tone={validity.tone}>{validity.label}</ToneBadge>
|
|
312
|
+
{entry.conflicts > 0 ? (
|
|
313
|
+
<ToneBadge tone="warn" className="ml-1">
|
|
314
|
+
{entry.conflicts} in conflict
|
|
315
|
+
</ToneBadge>
|
|
316
|
+
) : null}
|
|
317
|
+
</TableCell>
|
|
318
|
+
<TableCell className="text-right">{entry.events}</TableCell>
|
|
319
|
+
<TableCell className="text-right">{entry.findings}</TableCell>
|
|
320
|
+
<TableCell className="text-right">{entry.byteLength}</TableCell>
|
|
321
|
+
<TableCell>
|
|
322
|
+
<a href={originalPath(entry.importId)} download className="inline-flex items-center gap-1 text-sm underline underline-offset-4">
|
|
323
|
+
<Download className="size-3.5" aria-hidden />
|
|
324
|
+
Download
|
|
325
|
+
</a>
|
|
326
|
+
</TableCell>
|
|
327
|
+
<TableCell className="text-right">
|
|
328
|
+
<Button type="button" variant="ghost" size="sm" onClick={() => setOpen(open === entry.importId ? undefined : entry.importId)} aria-expanded={open === entry.importId}>
|
|
329
|
+
{open === entry.importId ? 'Hide' : 'Findings'}
|
|
330
|
+
</Button>
|
|
331
|
+
</TableCell>
|
|
332
|
+
</TableRow>
|
|
333
|
+
{open === entry.importId ? (
|
|
334
|
+
<TableRow>
|
|
335
|
+
<TableCell colSpan={8} className="whitespace-normal">
|
|
336
|
+
<ImportDetail importId={entry.importId} />
|
|
337
|
+
</TableCell>
|
|
338
|
+
</TableRow>
|
|
339
|
+
) : null}
|
|
340
|
+
</Fragment>
|
|
341
|
+
)
|
|
342
|
+
})}
|
|
343
|
+
</TableBody>
|
|
344
|
+
</Table>
|
|
345
|
+
)
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function ImportDetail({ importId }: { importId: string }) {
|
|
349
|
+
const record = useLoad(() => api.epcisImportRecord(importId), [importId])
|
|
350
|
+
if (record.loading) return <Loading what="Loading the import" />
|
|
351
|
+
if (record.error != null || record.data == null) return <ErrorNotice error={record.error ?? new Error('no answer')} title="Could not load the import" />
|
|
352
|
+
return <ImportFindings record={record.data} />
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function ImportFindings({ record }: { record: EpcisImportRecord }) {
|
|
356
|
+
const findings = findingsOf(record)
|
|
357
|
+
return (
|
|
358
|
+
<div className="space-y-2 py-2 text-sm">
|
|
359
|
+
<p>
|
|
360
|
+
<span className="text-muted-foreground">SHA-256 of the bytes as received </span>
|
|
361
|
+
<Mono>{record.sha256}</Mono>
|
|
362
|
+
</p>
|
|
363
|
+
<p>{countsLine(eventCounts(record))}</p>
|
|
364
|
+
{record.preservedExtensions.length === 0 ? null : (
|
|
365
|
+
<p>
|
|
366
|
+
<span className="text-muted-foreground">Document members outside the EPCIS schema, kept as received: </span>
|
|
367
|
+
<Mono>{record.preservedExtensions.join(', ')}</Mono>
|
|
368
|
+
</p>
|
|
369
|
+
)}
|
|
370
|
+
{findings.length === 0 ? (
|
|
371
|
+
<p className="text-muted-foreground">No findings.</p>
|
|
372
|
+
) : (
|
|
373
|
+
<ul className="divide-y rounded-lg border">
|
|
374
|
+
{findings.map((finding, i) => (
|
|
375
|
+
<li key={i} className="space-y-1 p-2">
|
|
376
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
377
|
+
<ToneBadge tone={finding.severity === 'error' ? 'fail' : finding.severity === 'warning' ? 'warn' : 'muted'}>{finding.severity}</ToneBadge>
|
|
378
|
+
<Mono>{finding.code}</Mono>
|
|
379
|
+
{finding.path === '' ? null : <Mono className="text-muted-foreground">{finding.path}</Mono>}
|
|
380
|
+
</div>
|
|
381
|
+
<p className="break-words">{finding.message}</p>
|
|
382
|
+
</li>
|
|
383
|
+
))}
|
|
384
|
+
</ul>
|
|
385
|
+
)}
|
|
386
|
+
</div>
|
|
387
|
+
)
|
|
388
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Link } from 'react-router'
|
|
2
|
+
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
|
|
3
|
+
import { Button } from '@/components/ui/button'
|
|
4
|
+
import { ErrorNotice, Loading } from '@/components/bits'
|
|
5
|
+
import { useAccount, useHealth } from '@/lib/session'
|
|
6
|
+
|
|
7
|
+
export function Home() {
|
|
8
|
+
const { health, error, loading } = useHealth()
|
|
9
|
+
const account = useAccount()
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<div className="mx-auto max-w-2xl space-y-8">
|
|
13
|
+
<h1 className="text-3xl font-semibold tracking-tight">Digital Product Passports on BSV</h1>
|
|
14
|
+
<p className="text-base leading-relaxed text-muted-foreground">
|
|
15
|
+
Brands issue a passport for each product they make and keep it current through the product's life. Every state is a transaction on BSV, signed by the brand and countersigned by this platform, and anyone holding the identifier, or the QR code it
|
|
16
|
+
is printed as, can verify the whole history without asking the brand.
|
|
17
|
+
</p>
|
|
18
|
+
{loading ? <Loading /> : null}
|
|
19
|
+
{error == null ? null : <ErrorNotice error={error} title="The API is not answering" />}
|
|
20
|
+
{health?.devSession == null ? null : (
|
|
21
|
+
<Alert>
|
|
22
|
+
<AlertTitle>Development session</AlertTitle>
|
|
23
|
+
<AlertDescription>
|
|
24
|
+
<p>Sign-in is off: you are the developer, a member of Development brand. Configure MongoDB for sign-in.</p>
|
|
25
|
+
</AlertDescription>
|
|
26
|
+
</Alert>
|
|
27
|
+
)}
|
|
28
|
+
<div className="flex flex-wrap gap-3">
|
|
29
|
+
<Button asChild>
|
|
30
|
+
<Link to="/verify">Verify a passport</Link>
|
|
31
|
+
</Button>
|
|
32
|
+
{account.signedIn ? (
|
|
33
|
+
<Button asChild variant="outline">
|
|
34
|
+
<Link to="/brands">Your brands</Link>
|
|
35
|
+
</Button>
|
|
36
|
+
) : null}
|
|
37
|
+
{!account.signedIn && account.canSignIn ? (
|
|
38
|
+
<Button asChild variant="outline">
|
|
39
|
+
<Link to="/sign-in">Sign in</Link>
|
|
40
|
+
</Button>
|
|
41
|
+
) : null}
|
|
42
|
+
</div>
|
|
43
|
+
{health == null ? null : (
|
|
44
|
+
<p className="text-xs text-muted-foreground">
|
|
45
|
+
Network {health.network}. Identifiers under https://{health.identifiers.host} with GS1 prefix {health.identifiers.prefix}
|
|
46
|
+
{health.identifiers.demonstration ? ' (the demonstration prefix)' : ''}. Live publishing {health.livePublishing ? 'on' : 'off'}.
|
|
47
|
+
</p>
|
|
48
|
+
)}
|
|
49
|
+
</div>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import { Link, useNavigate, useParams } from 'react-router'
|
|
3
|
+
import { Input } from '@/components/ui/input'
|
|
4
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
|
5
|
+
import { ErrorNotice, Field, Loading, PageTitle } from '@/components/bits'
|
|
6
|
+
import { BoundPassportForm, type BoundSubmission } from '@/components/bound/bound-passport-form'
|
|
7
|
+
import { RequireAccount } from '@/components/layout'
|
|
8
|
+
import { PassportForm, type PassportFormValues } from '@/components/passport-form'
|
|
9
|
+
import { api, passportRef, type Profile } from '@/lib/api'
|
|
10
|
+
import { useHealth } from '@/lib/session'
|
|
11
|
+
import { useLoad } from '@/lib/use-load'
|
|
12
|
+
|
|
13
|
+
export function NewPassport() {
|
|
14
|
+
return (
|
|
15
|
+
<RequireAccount>
|
|
16
|
+
<NewPassportPage />
|
|
17
|
+
</RequireAccount>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function NewPassportPage() {
|
|
22
|
+
const { brandId = '' } = useParams()
|
|
23
|
+
const navigate = useNavigate()
|
|
24
|
+
const { health } = useHealth()
|
|
25
|
+
const profiles = useLoad(() => api.profiles(), [])
|
|
26
|
+
const [profileId, setProfileId] = useState('')
|
|
27
|
+
const profile = useLoad<Profile | undefined>(() => (profileId === '' ? Promise.resolve(undefined) : api.profile(profileId)), [profileId])
|
|
28
|
+
const [itemReference, setItemReference] = useState('')
|
|
29
|
+
const [serial, setSerial] = useState('')
|
|
30
|
+
const [busy, setBusy] = useState(false)
|
|
31
|
+
const [error, setError] = useState<unknown>()
|
|
32
|
+
|
|
33
|
+
async function issue(values: PassportFormValues) {
|
|
34
|
+
setBusy(true)
|
|
35
|
+
setError(undefined)
|
|
36
|
+
try {
|
|
37
|
+
const view = await api.issuePassport(brandId, { profile: profileId, itemReference: itemReference.trim(), serial: serial.trim(), ...values })
|
|
38
|
+
navigate(`/passports/${passportRef(view.passportId)}`)
|
|
39
|
+
} catch (cause) {
|
|
40
|
+
setError(cause)
|
|
41
|
+
} finally {
|
|
42
|
+
setBusy(false)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** A profile held by a binding: the whole product document goes to the API, which splits it. */
|
|
47
|
+
async function issueBound(submission: BoundSubmission) {
|
|
48
|
+
setBusy(true)
|
|
49
|
+
setError(undefined)
|
|
50
|
+
try {
|
|
51
|
+
const view = await api.issuePassport(brandId, { profile: profileId, ...submission })
|
|
52
|
+
navigate(`/passports/${passportRef(view.passportId)}`)
|
|
53
|
+
} catch (cause) {
|
|
54
|
+
setError(cause)
|
|
55
|
+
} finally {
|
|
56
|
+
setBusy(false)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const chosen = profiles.data?.find((p) => p.id === profileId)
|
|
61
|
+
const prefix = health?.identifiers.prefix ?? '952'
|
|
62
|
+
const digits = Math.max(0, 12 - prefix.length)
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<div className="mx-auto max-w-3xl space-y-8">
|
|
66
|
+
<PageTitle
|
|
67
|
+
title="Issue a passport"
|
|
68
|
+
description={
|
|
69
|
+
<span>
|
|
70
|
+
For brand {brandId}.{' '}
|
|
71
|
+
<Link to={`/brands/${encodeURIComponent(brandId)}`} className="underline underline-offset-4">
|
|
72
|
+
Back to the brand
|
|
73
|
+
</Link>
|
|
74
|
+
</span>
|
|
75
|
+
}
|
|
76
|
+
/>
|
|
77
|
+
<div className="max-w-md space-y-2">
|
|
78
|
+
<Field label="Profile" htmlFor="profile" required help={chosen?.description}>
|
|
79
|
+
{profiles.loading ? (
|
|
80
|
+
<Loading what="Loading the profiles" />
|
|
81
|
+
) : profiles.error != null || profiles.data == null ? (
|
|
82
|
+
<ErrorNotice error={profiles.error ?? new Error('no answer')} title="Could not load the profiles" />
|
|
83
|
+
) : (
|
|
84
|
+
<Select
|
|
85
|
+
value={profileId}
|
|
86
|
+
onValueChange={(id) => {
|
|
87
|
+
setProfileId(id)
|
|
88
|
+
setError(undefined)
|
|
89
|
+
}}
|
|
90
|
+
>
|
|
91
|
+
<SelectTrigger id="profile" className="w-full">
|
|
92
|
+
<SelectValue placeholder="Choose a profile" />
|
|
93
|
+
</SelectTrigger>
|
|
94
|
+
<SelectContent>
|
|
95
|
+
{profiles.data.filter((p) => p.issueSuccessor == null).map((p) => (
|
|
96
|
+
<SelectItem key={p.id} value={p.id}>
|
|
97
|
+
{p.title} ({p.id})
|
|
98
|
+
</SelectItem>
|
|
99
|
+
))}
|
|
100
|
+
</SelectContent>
|
|
101
|
+
</Select>
|
|
102
|
+
)}
|
|
103
|
+
</Field>
|
|
104
|
+
</div>
|
|
105
|
+
{profileId === '' ? null : profile.loading ? (
|
|
106
|
+
<Loading what="Loading the profile" />
|
|
107
|
+
) : profile.error != null || profile.data == null ? (
|
|
108
|
+
<ErrorNotice error={profile.error ?? new Error('no answer')} title={`Could not load ${profileId}`} />
|
|
109
|
+
) : profile.data.format === 'binding' ? (
|
|
110
|
+
<BoundPassportForm key={profileId} profile={profile.data} policy={{ host: health?.identifiers.host ?? window.location.host, prefix }} submitLabel="Issue the passport" busy={busy} error={error} onSubmit={issueBound} />
|
|
111
|
+
) : (
|
|
112
|
+
<PassportForm
|
|
113
|
+
key={profileId}
|
|
114
|
+
profile={profile.data}
|
|
115
|
+
initial={{ payload: profile.data.sample }}
|
|
116
|
+
submitLabel="Issue the passport"
|
|
117
|
+
busy={busy}
|
|
118
|
+
error={error}
|
|
119
|
+
onSubmit={issue}
|
|
120
|
+
before={
|
|
121
|
+
<fieldset className="space-y-4">
|
|
122
|
+
<legend className="mb-3 text-base font-semibold">Identifier</legend>
|
|
123
|
+
<div className="grid gap-4 sm:grid-cols-2">
|
|
124
|
+
<Field label="Item reference" htmlFor="itemReference" required help={`The digits after the GS1 prefix, nine for prefix 952. This platform's prefix is ${prefix}, so ${digits} digits.`}>
|
|
125
|
+
<Input id="itemReference" value={itemReference} onChange={(e) => setItemReference(e.target.value)} required inputMode="numeric" pattern="[0-9]+" placeholder={'0'.repeat(digits)} />
|
|
126
|
+
</Field>
|
|
127
|
+
<Field label="Serial" htmlFor="serial" required help="The item's serial, 1 to 20 characters.">
|
|
128
|
+
<Input id="serial" value={serial} onChange={(e) => setSerial(e.target.value)} required maxLength={20} />
|
|
129
|
+
</Field>
|
|
130
|
+
</div>
|
|
131
|
+
</fieldset>
|
|
132
|
+
}
|
|
133
|
+
/>
|
|
134
|
+
)}
|
|
135
|
+
</div>
|
|
136
|
+
)
|
|
137
|
+
}
|