@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
|
@@ -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
|
+
}
|
|
@@ -9,7 +9,7 @@ import { Input } from '@/components/ui/input'
|
|
|
9
9
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
|
10
10
|
import { Textarea } from '@/components/ui/textarea'
|
|
11
11
|
import { ErrorNotice, Field } from '@/components/bits'
|
|
12
|
-
import type {
|
|
12
|
+
import type { ManifestProfile, ProfileField } from '@/lib/api'
|
|
13
13
|
import { humanise } from '@/lib/format'
|
|
14
14
|
|
|
15
15
|
export interface PassportFormValues {
|
|
@@ -18,7 +18,7 @@ export interface PassportFormValues {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
interface Props {
|
|
21
|
-
profile:
|
|
21
|
+
profile: ManifestProfile
|
|
22
22
|
/** Where the values start: the sample for a new passport, the current payload for an update. */
|
|
23
23
|
initial: { payload: Record<string, unknown>; ownerFields?: Record<string, unknown> }
|
|
24
24
|
submitLabel: string
|
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
// be another platform's, and the report still stands on its own.
|
|
5
5
|
import { ErrorNotice, Loading } from '@/components/bits'
|
|
6
6
|
import { PassportReading } from '@/components/reading'
|
|
7
|
-
import { api, isNotFound, type
|
|
7
|
+
import { api, isNotFound, type PassportView, type Verification } from '@/lib/api'
|
|
8
|
+
import type { PassportClaimsReading } from '@/lib/lifecycle'
|
|
8
9
|
import { useLoad } from '@/lib/use-load'
|
|
9
10
|
|
|
10
11
|
interface Read {
|
|
11
12
|
verification?: Verification
|
|
12
13
|
verifyError?: unknown
|
|
13
14
|
journal?: PassportView
|
|
14
|
-
claims
|
|
15
|
+
claims?: PassportClaimsReading
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
const unlessNotFound =
|
|
@@ -28,7 +29,7 @@ async function read(passportId: string): Promise<Read> {
|
|
|
28
29
|
(error: unknown): { ok: false; error: unknown } => ({ ok: false, error })
|
|
29
30
|
),
|
|
30
31
|
api.passport(passportId).catch(unlessNotFound<PassportView | undefined>(undefined)),
|
|
31
|
-
api.passportClaims(passportId).catch(unlessNotFound<
|
|
32
|
+
api.passportClaims(passportId).catch(unlessNotFound<PassportClaimsReading | undefined>(undefined)),
|
|
32
33
|
])
|
|
33
34
|
return {
|
|
34
35
|
verification: verification.ok ? verification.value : undefined,
|
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
// answers, and a reader decides what they mean for their own purpose.
|
|
5
5
|
import { Link } from 'react-router'
|
|
6
6
|
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
|
|
7
|
-
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'
|
|
8
7
|
import { CheckBadge, CopyButton, DefinitionList, ErrorNotice, Mono, Section, ToneBadge, entriesOf } from '@/components/bits'
|
|
9
|
-
import
|
|
8
|
+
import { PublicReading, boundPayload } from '@/components/bound/readings'
|
|
9
|
+
import { LifecycleClaims } from '@/components/lifecycle-claims'
|
|
10
|
+
import type { Check, PassportView, Verification } from '@/lib/api'
|
|
11
|
+
import type { PassportClaimsReading } from '@/lib/lifecycle'
|
|
10
12
|
import { STAMP_KEYS, formatTime, humanise, isRecord, publicPathOf, shortTxid } from '@/lib/format'
|
|
11
13
|
|
|
12
14
|
export function ReportChecks({ checks }: { checks: Check[] }) {
|
|
@@ -28,12 +30,24 @@ export function ReportChecks({ checks }: { checks: Check[] }) {
|
|
|
28
30
|
)
|
|
29
31
|
}
|
|
30
32
|
|
|
33
|
+
export function RecordNotice({ payload }: { payload: unknown }) {
|
|
34
|
+
if (!isRecord(payload) || typeof payload.notice !== 'string') return null
|
|
35
|
+
return (
|
|
36
|
+
<Alert className="border-amber-300 bg-amber-50 text-amber-950 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-100">
|
|
37
|
+
<AlertTitle>Notice</AlertTitle>
|
|
38
|
+
<AlertDescription className="text-current">
|
|
39
|
+
<p className="text-base">{payload.notice}</p>
|
|
40
|
+
</AlertDescription>
|
|
41
|
+
</Alert>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
31
45
|
interface ReadingProps {
|
|
32
46
|
passportId: string
|
|
33
47
|
verification?: Verification
|
|
34
48
|
verifyError?: unknown
|
|
35
49
|
journal?: PassportView
|
|
36
|
-
claims?:
|
|
50
|
+
claims?: PassportClaimsReading
|
|
37
51
|
/** Link to the brand's view when this platform's journal holds the passport. */
|
|
38
52
|
manageLink?: boolean
|
|
39
53
|
/** Link to the identifier's own page; off when this is that page. */
|
|
@@ -43,21 +57,16 @@ interface ReadingProps {
|
|
|
43
57
|
export function PassportReading({ passportId, verification, verifyError, journal, claims, manageLink, publicLink }: ReadingProps) {
|
|
44
58
|
const latestPayload = journal?.payload ?? verification?.lineage.at(-1)?.payloadPublic
|
|
45
59
|
const payload = isRecord(latestPayload) ? latestPayload : undefined
|
|
46
|
-
const notice = typeof payload?.notice === 'string' ? payload.notice : undefined
|
|
47
60
|
const profile = journal?.profile ?? (payload?.profile == null ? undefined : `${String(payload.profile)}@${String(payload.profile_version ?? '')}`)
|
|
48
61
|
const history = verification?.lineage.map((entry) => ({ op: entry.op, txid: entry.txid, timestamp: entry.timestamp })) ?? journal?.states.map((s) => ({ op: s.op, txid: s.txid, timestamp: s.timestamp })) ?? []
|
|
49
62
|
const path = publicPathOf(passportId)
|
|
63
|
+
// The report's own reading of the product document, or the journal's payload when no report was read.
|
|
64
|
+
const envelope = boundPayload(payload)
|
|
65
|
+
const product = verification?.product ?? (envelope == null ? undefined : { profile: envelope.profile, bindingDigest: envelope.bindingDigest, publicProduct: envelope.product })
|
|
50
66
|
|
|
51
67
|
return (
|
|
52
68
|
<div className="space-y-10">
|
|
53
|
-
{
|
|
54
|
-
<Alert className="border-amber-300 bg-amber-50 text-amber-950 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-100">
|
|
55
|
-
<AlertTitle>Notice</AlertTitle>
|
|
56
|
-
<AlertDescription className="text-current">
|
|
57
|
-
<p className="text-base">{notice}</p>
|
|
58
|
-
</AlertDescription>
|
|
59
|
-
</Alert>
|
|
60
|
-
)}
|
|
69
|
+
<RecordNotice payload={payload} />
|
|
61
70
|
|
|
62
71
|
<div className="space-y-2">
|
|
63
72
|
<div className="flex flex-wrap items-center gap-2">
|
|
@@ -72,9 +81,14 @@ export function PassportReading({ passportId, verification, verifyError, journal
|
|
|
72
81
|
</div>
|
|
73
82
|
</div>
|
|
74
83
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
84
|
+
{product != null ? (
|
|
85
|
+
// A product document under a binding: its public part as structure, and the check of that part, kept apart from anything about restricted data.
|
|
86
|
+
<PublicReading product={product} verification={verification} />
|
|
87
|
+
) : (
|
|
88
|
+
<Section title="Product">
|
|
89
|
+
{payload == null ? <p className="text-sm text-muted-foreground">No payload was read.</p> : <DefinitionList entries={entriesOf(payload, STAMP_KEYS, humanise)} />}
|
|
90
|
+
</Section>
|
|
91
|
+
)}
|
|
78
92
|
|
|
79
93
|
<Section title="Verification">
|
|
80
94
|
{verifyError != null ? <ErrorNotice error={verifyError} title="The reader could not verify this passport" /> : null}
|
|
@@ -111,30 +125,9 @@ export function PassportReading({ passportId, verification, verifyError, journal
|
|
|
111
125
|
)}
|
|
112
126
|
</Section>
|
|
113
127
|
|
|
114
|
-
{claims != null && claims.length > 0 ? (
|
|
115
|
-
<Section title="
|
|
116
|
-
<
|
|
117
|
-
<TableHeader>
|
|
118
|
-
<TableRow>
|
|
119
|
-
<TableHead>Event</TableHead>
|
|
120
|
-
<TableHead>When</TableHead>
|
|
121
|
-
<TableHead>Issued by</TableHead>
|
|
122
|
-
<TableHead>Signature</TableHead>
|
|
123
|
-
</TableRow>
|
|
124
|
-
</TableHeader>
|
|
125
|
-
<TableBody>
|
|
126
|
-
{claims.map((claim) => (
|
|
127
|
-
<TableRow key={claim.id}>
|
|
128
|
-
<TableCell>{claim.claim.eventType}</TableCell>
|
|
129
|
-
<TableCell>{formatTime(claim.claim.timestamp)}</TableCell>
|
|
130
|
-
<TableCell>{claim.issuedBy}</TableCell>
|
|
131
|
-
<TableCell>
|
|
132
|
-
<ToneBadge tone={claim.verified === 'verified' ? 'pass' : 'fail'}>{claim.verified}</ToneBadge>
|
|
133
|
-
</TableCell>
|
|
134
|
-
</TableRow>
|
|
135
|
-
))}
|
|
136
|
-
</TableBody>
|
|
137
|
-
</Table>
|
|
128
|
+
{claims != null && (claims.lifecycle.length > 0 || claims.historical.length > 0) ? (
|
|
129
|
+
<Section title="Lifecycle claims">
|
|
130
|
+
<LifecycleClaims reading={claims} />
|
|
138
131
|
</Section>
|
|
139
132
|
) : null}
|
|
140
133
|
|
|
@@ -2,16 +2,21 @@
|
|
|
2
2
|
// answer into an Error, and a typed helper for every route in apps/api/API.md.
|
|
3
3
|
// Reads are open; writes carry the session cookie, which a same-origin fetch
|
|
4
4
|
// sends by itself.
|
|
5
|
+
import type { EpcisEventsAnswer, EpcisImportAnswer, EpcisImportRecord, EpcisImportSummary, EpcisPullPage, EpcisPullQuery, EpcisPullResult, EpcisPullState, EpcisSource, EpcisStatus } from './epcis'
|
|
6
|
+
import type { LifecycleClaimView, PassportClaimsReading } from './lifecycle'
|
|
5
7
|
|
|
6
8
|
export class ApiError extends Error {
|
|
7
9
|
readonly code: string
|
|
8
10
|
readonly status: number
|
|
11
|
+
/** Everything else the API put in its answer: for a refused product document, the validation with its findings. */
|
|
12
|
+
readonly details: Record<string, unknown>
|
|
9
13
|
|
|
10
|
-
constructor(message: string, code: string, status: number) {
|
|
14
|
+
constructor(message: string, code: string, status: number, details: Record<string, unknown> = {}) {
|
|
11
15
|
super(message)
|
|
12
16
|
this.name = 'ApiError'
|
|
13
17
|
this.code = code
|
|
14
18
|
this.status = status
|
|
19
|
+
this.details = details
|
|
15
20
|
}
|
|
16
21
|
}
|
|
17
22
|
|
|
@@ -23,7 +28,11 @@ async function request<T>(path: string, method: 'GET' | 'POST' = 'GET', body?: u
|
|
|
23
28
|
init.headers = { ...init.headers, 'content-type': 'application/json' }
|
|
24
29
|
init.body = JSON.stringify(body)
|
|
25
30
|
}
|
|
26
|
-
|
|
31
|
+
return await answerOf<T>(await fetch(path, init))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The API's answer as a value, or as the error it describes. */
|
|
35
|
+
async function answerOf<T>(response: Response): Promise<T> {
|
|
27
36
|
const text = await response.text()
|
|
28
37
|
let parsed: unknown
|
|
29
38
|
try {
|
|
@@ -32,8 +41,9 @@ async function request<T>(path: string, method: 'GET' | 'POST' = 'GET', body?: u
|
|
|
32
41
|
parsed = undefined
|
|
33
42
|
}
|
|
34
43
|
if (!response.ok) {
|
|
35
|
-
const failure = (parsed
|
|
36
|
-
|
|
44
|
+
const failure = (typeof parsed === 'object' && parsed !== null ? parsed : {}) as { error?: string; description?: string } & Record<string, unknown>
|
|
45
|
+
const { error: code, description, ...details } = failure
|
|
46
|
+
throw new ApiError(description ?? `the API answered HTTP ${response.status}`, code ?? `http-${response.status}`, response.status, details)
|
|
37
47
|
}
|
|
38
48
|
if (parsed === undefined) throw new ApiError('the API answered with something that is not JSON', 'not-json', response.status)
|
|
39
49
|
return parsed as T
|
|
@@ -50,19 +60,28 @@ export const passportRef = (passportId: string): string => encodeURIComponent(pa
|
|
|
50
60
|
export interface Health {
|
|
51
61
|
ok: boolean
|
|
52
62
|
network: 'main' | 'test'
|
|
53
|
-
index
|
|
63
|
+
/** The index in use: in this process until the app has joined the configured one. */
|
|
64
|
+
index: { url: string; joined: boolean; inProcess: boolean; configured?: string }
|
|
54
65
|
publisherKey: string
|
|
55
66
|
wallet: 'toolbox' | 'test'
|
|
56
67
|
livePublishing: boolean
|
|
68
|
+
/** False when the validation engine cannot be used: its libraries did not load, or the validator service did not answer. A profile held by a binding then cannot be written, and its readings say "not checked". */
|
|
69
|
+
validationEngine: boolean
|
|
70
|
+
/** Where the engine runs: in the API's own process, or in the validator service its settings name. */
|
|
71
|
+
validationEngineKind?: 'in-process' | 'service'
|
|
57
72
|
identifiers: { host: string; prefix: string; demonstration: boolean }
|
|
58
73
|
signIn: boolean
|
|
59
74
|
devSession?: { name: string; brandIds: string[] }
|
|
60
75
|
}
|
|
61
76
|
|
|
62
77
|
export interface ProfileSummary {
|
|
78
|
+
/** The edition offered for new passports when this profile is historical. */
|
|
79
|
+
issueSuccessor?: string
|
|
63
80
|
id: string
|
|
64
81
|
title: string
|
|
65
82
|
description?: string
|
|
83
|
+
/** `manifest`: a field list this application's form is drawn from. `binding`: a data model defined elsewhere, written as one product document. */
|
|
84
|
+
format: 'manifest' | 'binding'
|
|
66
85
|
}
|
|
67
86
|
|
|
68
87
|
export interface CodeList {
|
|
@@ -94,13 +113,85 @@ export interface ProfileField {
|
|
|
94
113
|
cardinality?: 'one' | 'many'
|
|
95
114
|
}
|
|
96
115
|
|
|
97
|
-
export interface
|
|
116
|
+
export interface ManifestProfile extends ProfileSummary {
|
|
117
|
+
format: 'manifest'
|
|
98
118
|
fields: ProfileField[]
|
|
99
119
|
publicSchema: unknown
|
|
100
120
|
restrictedSchema: unknown
|
|
101
121
|
sample: Record<string, unknown>
|
|
102
122
|
}
|
|
103
123
|
|
|
124
|
+
/** A profile held by a binding: its product document is split by top-level property into a public part, on chain, and a restricted part, sealed off chain. */
|
|
125
|
+
export interface BoundProfile extends ProfileSummary {
|
|
126
|
+
format: 'binding'
|
|
127
|
+
bindingDigest: string
|
|
128
|
+
steps: string[]
|
|
129
|
+
/** The binding's public list. Every other property is restricted. Absent when the binding makes no split: the whole document is then public. */
|
|
130
|
+
access?: { policy: string; public: string[] }
|
|
131
|
+
contexts: Array<{ path: string; uri: string }>
|
|
132
|
+
prefixes: Record<string, string>
|
|
133
|
+
engine: { available: boolean; kind?: 'in-process' | 'service'; problem?: string }
|
|
134
|
+
/** Complete product documents of invented data, minted for this deployment's host and prefix. */
|
|
135
|
+
examples: Array<{ title: string; itemReference: string; serial: string; passportId: string; product: Record<string, unknown> }>
|
|
136
|
+
demonstration: boolean
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export type Profile = ManifestProfile | BoundProfile
|
|
140
|
+
|
|
141
|
+
export type CodeLists = Record<string, Array<{ value: string; label: string }>>
|
|
142
|
+
|
|
143
|
+
/** How a view of a payload came out. `not-checked` is never a pass. */
|
|
144
|
+
export type ViewStatus = 'pass' | 'fail' | 'not-checked'
|
|
145
|
+
|
|
146
|
+
export interface Finding {
|
|
147
|
+
severity: 'Violation' | 'Warning' | 'Info'
|
|
148
|
+
constraint: string
|
|
149
|
+
step: string
|
|
150
|
+
focusNode?: string
|
|
151
|
+
path?: string
|
|
152
|
+
message?: string
|
|
153
|
+
value?: string
|
|
154
|
+
/** A JSON pointer into the product document, when the finding could be placed. */
|
|
155
|
+
pointer?: string
|
|
156
|
+
property?: string
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface ViewCheck {
|
|
160
|
+
view: 'public' | 'authorised' | 'whole'
|
|
161
|
+
status: ViewStatus
|
|
162
|
+
cause?: string
|
|
163
|
+
summary: string
|
|
164
|
+
steps: Array<{ step: string; status: ViewStatus; cause?: string; messages: string[] }>
|
|
165
|
+
findings: Finding[]
|
|
166
|
+
withheld: Array<{ step: string; property: string; constraint: string; message?: string }>
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface PayloadCheck {
|
|
170
|
+
txid: string
|
|
171
|
+
stateIndex: number
|
|
172
|
+
profile: string
|
|
173
|
+
publicView: ViewCheck
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface ProductReading {
|
|
177
|
+
profile: string
|
|
178
|
+
bindingDigest: string
|
|
179
|
+
notice?: string
|
|
180
|
+
publicProduct: Record<string, unknown>
|
|
181
|
+
access?: { policy: string; public: string[] }
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** The holder's view of a passport under a bound profile. The owner-tier check is the protocol's, and the only statement about the on-chain commitment. */
|
|
185
|
+
export interface AuthorisedReading {
|
|
186
|
+
passportId: string
|
|
187
|
+
profile?: string
|
|
188
|
+
ownerTier: { status: ViewStatus; txid?: string; detail: string }
|
|
189
|
+
authorisedView: ViewCheck
|
|
190
|
+
restrictedProduct?: Record<string, unknown>
|
|
191
|
+
product?: Record<string, unknown>
|
|
192
|
+
access?: { policy: string; public: string[] }
|
|
193
|
+
}
|
|
194
|
+
|
|
104
195
|
export type CheckStatus = 'pass' | 'fail' | 'unknown' | 'not-applicable'
|
|
105
196
|
|
|
106
197
|
export interface Check {
|
|
@@ -125,6 +216,10 @@ export interface Verification {
|
|
|
125
216
|
checks: Check[]
|
|
126
217
|
report: { checkedAt?: string; limits?: string[]; [key: string]: unknown }
|
|
127
218
|
publisherKeys: string[]
|
|
219
|
+
/** One entry per state whose payload declares a profile, genesis first. */
|
|
220
|
+
payloadChecks?: PayloadCheck[]
|
|
221
|
+
/** Present when the newest state carries a product document under a binding. */
|
|
222
|
+
product?: ProductReading
|
|
128
223
|
}
|
|
129
224
|
|
|
130
225
|
export type Op = 'ISSUE' | 'UPDATE' | 'TRANSFER' | 'RETIRE'
|
|
@@ -153,7 +248,9 @@ export interface PassportView {
|
|
|
153
248
|
passportId: string
|
|
154
249
|
brandId: string
|
|
155
250
|
profile: string
|
|
156
|
-
|
|
251
|
+
/** Present when the passport's profile is retired: nothing further is written for it, and this names the profile that replaces it. */
|
|
252
|
+
profileRetired?: { replacedBy: string }
|
|
253
|
+
status: 'active' | 'retired' | 'awaiting-send' | 'not-issued'
|
|
157
254
|
demonstration: boolean
|
|
158
255
|
holder: { party: string; controllerKey: string }
|
|
159
256
|
createdAt: string
|
|
@@ -163,18 +260,6 @@ export interface PassportView {
|
|
|
163
260
|
acceptanceRecords: unknown[]
|
|
164
261
|
}
|
|
165
262
|
|
|
166
|
-
export interface ClaimView {
|
|
167
|
-
id: string
|
|
168
|
-
passportId: string
|
|
169
|
-
issuer: string
|
|
170
|
-
issuedBy: string
|
|
171
|
-
claim: { eventType: string; timestamp: string; recordId?: string; [key: string]: unknown }
|
|
172
|
-
registry?: { url: string; status: number; accepted: boolean; attestationId?: string; detail?: string }
|
|
173
|
-
createdAt: string
|
|
174
|
-
/** The signature check, on the list route only; the record a POST returns has none, and was refused if it did not verify. */
|
|
175
|
-
verified?: string
|
|
176
|
-
}
|
|
177
|
-
|
|
178
263
|
export type OfferStatus = 'open' | 'accepted' | 'transferred' | 'declined' | 'withdrawn' | 'expired'
|
|
179
264
|
|
|
180
265
|
export interface OfferPreview {
|
|
@@ -230,6 +315,8 @@ export interface Duty {
|
|
|
230
315
|
export interface Operations {
|
|
231
316
|
duties: Duty[]
|
|
232
317
|
passports: Array<{ passportId: string; brandId: string; status: string; journal: JournalSummary }>
|
|
318
|
+
/** The validation engine's problem as it is now, where bound profiles are read from, and each profile folder or bundle that was refused at start. */
|
|
319
|
+
profiles?: { engine: { available: boolean; kind?: 'in-process' | 'service'; problem?: string }; source?: 'package' | 'bundle'; refused: Array<{ source: string; code: string; detail: string }> }
|
|
233
320
|
}
|
|
234
321
|
|
|
235
322
|
export interface WalletView {
|
|
@@ -247,8 +334,12 @@ export interface FundingAddress {
|
|
|
247
334
|
senderIdentityKey: string
|
|
248
335
|
}
|
|
249
336
|
|
|
250
|
-
|
|
251
|
-
export
|
|
337
|
+
/** What a member sends to sign an EPCIS lifecycle claim: the event they entered, one the EPCIS exchange retained, or a claim to declare in error. */
|
|
338
|
+
export type IssueClaimRequest = ({ event: Record<string, unknown> } | { imported: { importId: string; pointer: string } } | { correctionOf: string; reason?: 'did_not_occur' | 'incorrect_data' }) & {
|
|
339
|
+
assertedRole?: string
|
|
340
|
+
issuerParty?: string
|
|
341
|
+
submit?: boolean
|
|
342
|
+
}
|
|
252
343
|
|
|
253
344
|
// ------------------------------------------------------------------ routes
|
|
254
345
|
|
|
@@ -256,9 +347,10 @@ export const api = {
|
|
|
256
347
|
health: () => get<Health>('/api/health'),
|
|
257
348
|
profiles: () => get<ProfileSummary[]>('/api/profiles'),
|
|
258
349
|
profile: (id: string) => get<Profile>(`/api/profiles/${encodeURIComponent(id)}`),
|
|
350
|
+
profileCodes: (id: string, classes: string[]) => (classes.length === 0 ? Promise.resolve<CodeLists>({}) : get<CodeLists>(`/api/profiles/${encodeURIComponent(id)}/codes?${classes.map((name) => `class=${encodeURIComponent(name)}`).join('&')}`)),
|
|
259
351
|
verify: (passportId: string) => get<Verification>(`/api/verify?passportId=${encodeURIComponent(passportId)}`),
|
|
260
352
|
passport: (passportId: string) => get<PassportView>(`/api/passports/${passportRef(passportId)}`),
|
|
261
|
-
passportClaims: (passportId: string) => get<
|
|
353
|
+
passportClaims: (passportId: string) => get<PassportClaimsReading>(`/api/passports/${passportRef(passportId)}/claims`),
|
|
262
354
|
offer: (requestId: string) => get<OfferPreview>(`/api/offers/${encodeURIComponent(requestId)}`),
|
|
263
355
|
acceptOffer: (requestId: string, claimCode: string) => post<AcceptResult>(`/api/offers/${encodeURIComponent(requestId)}/accept`, { claimCode }),
|
|
264
356
|
declineOffer: (requestId: string, claimCode: string) => post<OfferView>(`/api/offers/${encodeURIComponent(requestId)}/decline`, { claimCode }),
|
|
@@ -267,20 +359,38 @@ export const api = {
|
|
|
267
359
|
brands: () => get<Brand[]>('/api/brands'),
|
|
268
360
|
createBrand: (name: string) => post<Brand>('/api/brands', { name }),
|
|
269
361
|
brandPassports: (brandId: string) => get<PassportView[]>(`/api/brands/${encodeURIComponent(brandId)}/passports`),
|
|
270
|
-
issuePassport: (brandId: string, body: { profile: string; itemReference: string; serial: string
|
|
362
|
+
issuePassport: (brandId: string, body: { profile: string; itemReference: string; serial: string } & ({ payload: Record<string, unknown>; ownerFields: Record<string, unknown> } | { product: Record<string, unknown> })) =>
|
|
271
363
|
post<PassportView>(`/api/brands/${encodeURIComponent(brandId)}/passports`, body),
|
|
272
|
-
updatePassport: (passportId: string, body: { payload: Record<string, unknown>; ownerFields: Record<string, unknown
|
|
364
|
+
updatePassport: (passportId: string, body: ({ payload: Record<string, unknown>; ownerFields: Record<string, unknown> } | { product: Record<string, unknown> }) & { eventData?: Record<string, unknown>; claimCode?: string }) =>
|
|
273
365
|
post<PassportView>(`/api/passports/${passportRef(passportId)}/update`, body),
|
|
274
|
-
|
|
366
|
+
authorisedView: (passportId: string, claimCode?: string) => post<AuthorisedReading>(`/api/passports/${passportRef(passportId)}/authorised-view`, claimCode == null ? {} : { claimCode }),
|
|
367
|
+
offerPassport: (passportId: string, body: { requestId?: string; terms: { word: string; note?: string }; claimCode?: string }) =>
|
|
275
368
|
post<{ offer: OfferView; claimCode?: string }>(`/api/passports/${passportRef(passportId)}/offer`, body),
|
|
276
369
|
passportOffers: (passportId: string) => get<OfferView[]>(`/api/passports/${passportRef(passportId)}/offers`),
|
|
277
370
|
withdrawOffer: (requestId: string, claimCode?: string) => post<OfferView>(`/api/offers/${encodeURIComponent(requestId)}/withdraw`, claimCode == null ? {} : { claimCode }),
|
|
278
371
|
retirePassport: (passportId: string, body: { reason: string; claimCode?: string }) => post<PassportView>(`/api/passports/${passportRef(passportId)}/retire`, body),
|
|
279
|
-
|
|
372
|
+
issueClaim: (passportId: string, body: IssueClaimRequest) => post<LifecycleClaimView>(`/api/passports/${passportRef(passportId)}/claims`, body),
|
|
280
373
|
|
|
281
374
|
operations: () => get<Operations>('/api/operations'),
|
|
282
375
|
runOperations: () => post<{ done: string[] }>('/api/operations/run'),
|
|
283
376
|
wallet: () => get<WalletView>('/api/wallet'),
|
|
284
377
|
fundingAddress: () => post<FundingAddress>('/api/wallet/funding-address'),
|
|
285
378
|
internalize: (txid: string, funding: FundingAddress) => post<{ satoshis: number }>('/api/wallet/internalize', { txid, funding }),
|
|
379
|
+
|
|
380
|
+
// EPCIS exchange. An import or a pull retains data and changes no passport.
|
|
381
|
+
epcisStatus: () => get<EpcisStatus>('/api/epcis/status'),
|
|
382
|
+
epcisSources: () => get<EpcisSource[]>('/api/epcis/sources'),
|
|
383
|
+
/**
|
|
384
|
+
* Upload a document. The file is sent as the bytes it is, never read and written out again, so what is retained
|
|
385
|
+
* and later exported is exactly what was chosen. `requestId` is chosen once for a file: sending it again is the same request.
|
|
386
|
+
*/
|
|
387
|
+
epcisImport: async (file: Blob, options: { requestId: string; mediaType: string; sourceId?: string; filename?: string }) => {
|
|
388
|
+
const query = new URLSearchParams({ requestId: options.requestId, ...(options.sourceId == null || options.sourceId === '' ? {} : { sourceId: options.sourceId }), ...(options.filename == null ? {} : { filename: options.filename }) })
|
|
389
|
+
return await answerOf<EpcisImportAnswer>(await fetch(`/api/epcis/imports?${query.toString()}`, { method: 'POST', headers: { accept: 'application/json', 'content-type': options.mediaType }, body: file }))
|
|
390
|
+
},
|
|
391
|
+
epcisImports: (after?: string) => get<{ imports: EpcisImportSummary[]; next?: string }>(`/api/epcis/imports?limit=200${after == null ? '' : `&after=${encodeURIComponent(after)}`}`),
|
|
392
|
+
epcisImportRecord: (importId: string) => get<EpcisImportRecord>(`/api/epcis/imports/${encodeURIComponent(importId)}`),
|
|
393
|
+
epcisPull: (sourceId: string, body: { queryId: string; query: EpcisPullQuery }) => post<EpcisPullResult>(`/api/epcis/sources/${encodeURIComponent(sourceId)}/pulls`, body),
|
|
394
|
+
epcisPullState: (sourceId: string, queryId: string) => get<{ pull: EpcisPullState; pages: EpcisPullPage[] }>(`/api/epcis/sources/${encodeURIComponent(sourceId)}/pulls/${encodeURIComponent(queryId)}`),
|
|
395
|
+
epcisEvents: (identifier: string, granularity: 'instance' | 'class' = 'instance') => get<EpcisEventsAnswer>(`/api/epcis/events?identifier=${encodeURIComponent(identifier)}&granularity=${granularity}`),
|
|
286
396
|
}
|