@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,344 @@
|
|
|
1
|
+
// Signing an EPCIS lifecycle claim from the brand's page: from an event the
|
|
2
|
+
// member enters, or from an event the EPCIS exchange retained, and declaring
|
|
3
|
+
// one of this application's claims in error. Signing is one step, done with
|
|
4
|
+
// the member's managed identity; sending to the registry, which anchors the
|
|
5
|
+
// claim once per bound passport, is a second step the member ticks.
|
|
6
|
+
import { useState, type FormEvent } from 'react'
|
|
7
|
+
import { Button } from '@/components/ui/button'
|
|
8
|
+
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
|
9
|
+
import { Input } from '@/components/ui/input'
|
|
10
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
|
11
|
+
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
|
12
|
+
import { Textarea } from '@/components/ui/textarea'
|
|
13
|
+
import { ErrorNotice, Field, Loading, Mono, ToneBadge } from '@/components/bits'
|
|
14
|
+
import { api, type IssueClaimRequest } from '@/lib/api'
|
|
15
|
+
import { passportSpellings } from '@/lib/epcis'
|
|
16
|
+
import { formatTime } from '@/lib/format'
|
|
17
|
+
import { EVENT_FIELDS, LIFECYCLE_ACTIONS, LIFECYCLE_EVENT_TYPES, LIFECYCLE_ROLES, SUGGESTED_BUSINESS_STEPS, SUGGESTED_DISPOSITIONS, emptyEventForm, eventFromForm, findingRows, participationLabel, roleWords, type LifecycleClaimView, type LifecycleEventForm, type LifecycleEventType } from '@/lib/lifecycle'
|
|
18
|
+
import { useLoad } from '@/lib/use-load'
|
|
19
|
+
|
|
20
|
+
function Outcome({ claim, onClose }: { claim: LifecycleClaimView; onClose: () => void }) {
|
|
21
|
+
const participation = participationLabel(claim)
|
|
22
|
+
return (
|
|
23
|
+
<div className="space-y-4 text-sm">
|
|
24
|
+
<p>
|
|
25
|
+
Signed. The claim is <Mono>{claim.attestationId}</Mono>. <ToneBadge tone={participation.tone}>{participation.label}</ToneBadge>
|
|
26
|
+
</p>
|
|
27
|
+
{claim.record?.registry == null ? <p className="text-muted-foreground">It was not sent to a registry, so nothing anchors it yet.</p> : <p>The registry answered HTTP {claim.record.registry.status}{claim.record.registry.detail == null ? '' : `: ${claim.record.registry.detail}`}.</p>}
|
|
28
|
+
{claim.findings == null ? null : (
|
|
29
|
+
<ul className="divide-y rounded-md border">
|
|
30
|
+
{findingRows(claim.findings).map((row) => (
|
|
31
|
+
<li key={row.key} className="flex flex-wrap items-center gap-2 p-2">
|
|
32
|
+
<span className="w-32">{row.label}</span>
|
|
33
|
+
<ToneBadge tone={row.tone}>{row.status}</ToneBadge>
|
|
34
|
+
</li>
|
|
35
|
+
))}
|
|
36
|
+
</ul>
|
|
37
|
+
)}
|
|
38
|
+
<DialogFooter>
|
|
39
|
+
<Button onClick={onClose}>Done</Button>
|
|
40
|
+
</DialogFooter>
|
|
41
|
+
</div>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function RoleFields({ role, setRole, party, setParty, imported }: { role: string; setRole: (role: string) => void; party: string; setParty: (party: string) => void; imported: boolean }) {
|
|
46
|
+
const roles = LIFECYCLE_ROLES.filter((r) => !(imported && r === 'observer'))
|
|
47
|
+
return (
|
|
48
|
+
<>
|
|
49
|
+
<Field label="You sign" htmlFor="claim-role" required help={imported ? 'Choose the role in which you report this supplied event. The operator must have granted it for each passport at the event time.' : 'The operator must have granted this role for every passport the event names, at the time the event occurred.'}>
|
|
50
|
+
<Select value={role} onValueChange={setRole}>
|
|
51
|
+
<SelectTrigger id="claim-role" className="w-full">
|
|
52
|
+
<SelectValue />
|
|
53
|
+
</SelectTrigger>
|
|
54
|
+
<SelectContent>
|
|
55
|
+
{roles.map((r) => (
|
|
56
|
+
<SelectItem key={r} value={r}>
|
|
57
|
+
{roleWords(r)}
|
|
58
|
+
</SelectItem>
|
|
59
|
+
))}
|
|
60
|
+
</SelectContent>
|
|
61
|
+
</Select>
|
|
62
|
+
</Field>
|
|
63
|
+
{role === 'owner' || role === 'custodian' ? (
|
|
64
|
+
<Field label="Your party identifier" htmlFor="claim-party" help="The party the event's owning or possessing roles name as you, such as a PGLN.">
|
|
65
|
+
<Input id="claim-party" value={party} onChange={(e) => setParty(e.target.value)} spellCheck={false} />
|
|
66
|
+
</Field>
|
|
67
|
+
) : null}
|
|
68
|
+
</>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const LIST_LABELS: Record<string, string> = { epcList: 'Objects', childEPCs: 'Contents or components', inputEPCList: 'Inputs', outputEPCList: 'Outputs', quantityList: 'Quantities', childQuantityList: 'Content quantities', inputQuantityList: 'Input quantities', outputQuantityList: 'Output quantities' }
|
|
73
|
+
|
|
74
|
+
function EventFields({ form, setForm }: { form: LifecycleEventForm; setForm: (form: LifecycleEventForm) => void }) {
|
|
75
|
+
const shape = EVENT_FIELDS[form.type]
|
|
76
|
+
const set = (key: keyof LifecycleEventForm) => (e: { target: { value: string } }) => setForm({ ...form, [key]: e.target.value })
|
|
77
|
+
return (
|
|
78
|
+
<div className="grid gap-3 sm:grid-cols-2">
|
|
79
|
+
<Field label="Event type" htmlFor="ev-type" required>
|
|
80
|
+
<Select value={form.type} onValueChange={(v) => setForm({ ...form, type: v as LifecycleEventType })}>
|
|
81
|
+
<SelectTrigger id="ev-type" className="w-full">
|
|
82
|
+
<SelectValue />
|
|
83
|
+
</SelectTrigger>
|
|
84
|
+
<SelectContent>
|
|
85
|
+
{LIFECYCLE_EVENT_TYPES.map((t) => (
|
|
86
|
+
<SelectItem key={t} value={t}>
|
|
87
|
+
{t}
|
|
88
|
+
</SelectItem>
|
|
89
|
+
))}
|
|
90
|
+
</SelectContent>
|
|
91
|
+
</Select>
|
|
92
|
+
</Field>
|
|
93
|
+
{shape.action ? (
|
|
94
|
+
<Field label="Action" htmlFor="ev-action" required>
|
|
95
|
+
<Select value={form.action} onValueChange={(v) => setForm({ ...form, action: v })}>
|
|
96
|
+
<SelectTrigger id="ev-action" className="w-full">
|
|
97
|
+
<SelectValue />
|
|
98
|
+
</SelectTrigger>
|
|
99
|
+
<SelectContent>
|
|
100
|
+
{LIFECYCLE_ACTIONS.map((a) => (
|
|
101
|
+
<SelectItem key={a} value={a}>
|
|
102
|
+
{a}
|
|
103
|
+
</SelectItem>
|
|
104
|
+
))}
|
|
105
|
+
</SelectContent>
|
|
106
|
+
</Select>
|
|
107
|
+
</Field>
|
|
108
|
+
) : (
|
|
109
|
+
<p className="self-end text-xs text-muted-foreground">A transformation has no action.</p>
|
|
110
|
+
)}
|
|
111
|
+
<Field label="Event identifier" htmlFor="ev-id" required help="The event's own eventID. Keep the one your capture system gave it.">
|
|
112
|
+
<Input id="ev-id" value={form.eventID} onChange={set('eventID')} spellCheck={false} />
|
|
113
|
+
</Field>
|
|
114
|
+
<Field label="Event time" htmlFor="ev-time" required help="When it happened, ISO 8601 with a timezone.">
|
|
115
|
+
<Input id="ev-time" value={form.eventTime} onChange={set('eventTime')} spellCheck={false} />
|
|
116
|
+
</Field>
|
|
117
|
+
<Field label="Timezone offset" htmlFor="ev-tz" required>
|
|
118
|
+
<Input id="ev-tz" value={form.eventTimeZoneOffset} onChange={set('eventTimeZoneOffset')} spellCheck={false} />
|
|
119
|
+
</Field>
|
|
120
|
+
<Field label="Business step" htmlFor="ev-step" help="A CBV 2.0 business step, or an extension URI.">
|
|
121
|
+
<Input id="ev-step" list="ev-steps" value={form.bizStep} onChange={set('bizStep')} spellCheck={false} />
|
|
122
|
+
<datalist id="ev-steps">
|
|
123
|
+
{SUGGESTED_BUSINESS_STEPS.map((s) => (
|
|
124
|
+
<option key={s} value={s} />
|
|
125
|
+
))}
|
|
126
|
+
</datalist>
|
|
127
|
+
</Field>
|
|
128
|
+
<Field label="Disposition" htmlFor="ev-disp">
|
|
129
|
+
<Input id="ev-disp" list="ev-disps" value={form.disposition} onChange={set('disposition')} spellCheck={false} />
|
|
130
|
+
<datalist id="ev-disps">
|
|
131
|
+
{SUGGESTED_DISPOSITIONS.map((s) => (
|
|
132
|
+
<option key={s} value={s} />
|
|
133
|
+
))}
|
|
134
|
+
</datalist>
|
|
135
|
+
</Field>
|
|
136
|
+
{shape.parent ? (
|
|
137
|
+
<Field label="Parent" htmlFor="ev-parent" help="The container, assembly or parent object, by its identifier.">
|
|
138
|
+
<Input id="ev-parent" value={form.parentID} onChange={set('parentID')} spellCheck={false} />
|
|
139
|
+
</Field>
|
|
140
|
+
) : null}
|
|
141
|
+
{shape.lists.map((list) => (
|
|
142
|
+
<Field key={list} label={LIST_LABELS[list]} htmlFor={`ev-${list}`} help="One identifier per line, exactly as written.">
|
|
143
|
+
<Textarea id={`ev-${list}`} rows={2} value={form[list]} onChange={set(list)} spellCheck={false} />
|
|
144
|
+
</Field>
|
|
145
|
+
))}
|
|
146
|
+
{shape.quantities.map((list) => (
|
|
147
|
+
<Field key={list} label={LIST_LABELS[list]} htmlFor={`ev-${list}`} help="One per line: a class identifier, then a quantity and a unit code if known. A class never says which items took part.">
|
|
148
|
+
<Textarea id={`ev-${list}`} rows={2} value={form[list]} onChange={set(list)} spellCheck={false} />
|
|
149
|
+
</Field>
|
|
150
|
+
))}
|
|
151
|
+
<Field label="Read point" htmlFor="ev-rp">
|
|
152
|
+
<Input id="ev-rp" value={form.readPoint} onChange={set('readPoint')} spellCheck={false} />
|
|
153
|
+
</Field>
|
|
154
|
+
<Field label="Business location" htmlFor="ev-bl">
|
|
155
|
+
<Input id="ev-bl" value={form.bizLocation} onChange={set('bizLocation')} spellCheck={false} />
|
|
156
|
+
</Field>
|
|
157
|
+
<Field label="Sources" htmlFor="ev-src" help="One per line: owning_party, possessing_party or location, then the party or place.">
|
|
158
|
+
<Textarea id="ev-src" rows={2} value={form.sourceList} onChange={set('sourceList')} spellCheck={false} />
|
|
159
|
+
</Field>
|
|
160
|
+
<Field label="Destinations" htmlFor="ev-dst" help="The same form. Possession and ownership are separate roles.">
|
|
161
|
+
<Textarea id="ev-dst" rows={2} value={form.destinationList} onChange={set('destinationList')} spellCheck={false} />
|
|
162
|
+
</Field>
|
|
163
|
+
<Field label="Business transactions" htmlFor="ev-btx" help="One per line: a type such as po, then its identifier.">
|
|
164
|
+
<Textarea id="ev-btx" rows={2} value={form.bizTransactionList} onChange={set('bizTransactionList')} spellCheck={false} />
|
|
165
|
+
</Field>
|
|
166
|
+
{shape.transformationID ? (
|
|
167
|
+
<Field label="Transformation identifier" htmlFor="ev-tid">
|
|
168
|
+
<Input id="ev-tid" value={form.transformationID} onChange={set('transformationID')} spellCheck={false} />
|
|
169
|
+
</Field>
|
|
170
|
+
) : null}
|
|
171
|
+
<div className="sm:col-span-2">
|
|
172
|
+
<Field label="Sensor elements" htmlFor="ev-sensors" help="EPCIS JSON, a list of sensor elements, exactly as it is to be signed.">
|
|
173
|
+
<Textarea id="ev-sensors" rows={3} value={form.sensorElementList} onChange={set('sensorElementList')} spellCheck={false} className="font-mono text-xs" />
|
|
174
|
+
</Field>
|
|
175
|
+
</div>
|
|
176
|
+
</div>
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function RetainedEvents({ passportId, chosen, setChosen }: { passportId: string; chosen?: string; setChosen: (key: string, imported: { importId: string; pointer: string }) => void }) {
|
|
181
|
+
const found = useLoad(async () => (await Promise.all(passportSpellings(passportId).map((identifier) => api.epcisEvents(identifier, 'instance')))).flatMap((answer) => answer.events), [passportId])
|
|
182
|
+
if (found.loading) return <Loading what="Looking for retained events" />
|
|
183
|
+
if (found.error != null || found.data == null) return <ErrorNotice error={found.error ?? new Error('no answer')} title="Could not look for retained events" />
|
|
184
|
+
if (found.data.length === 0) return <p className="text-sm text-muted-foreground">The EPCIS exchange retains no event that names this passport. Import one on the Events page.</p>
|
|
185
|
+
return (
|
|
186
|
+
<ul className="divide-y rounded-md border text-sm">
|
|
187
|
+
{found.data.map((entry) => {
|
|
188
|
+
const key = `${entry.source.importId} ${entry.association.pointer}`
|
|
189
|
+
return (
|
|
190
|
+
<li key={`${key} ${entry.association.role}`} className="p-2">
|
|
191
|
+
<label className="flex items-start gap-2">
|
|
192
|
+
<input type="radio" name="retained" checked={chosen === key} onChange={() => setChosen(key, { importId: entry.source.importId, pointer: entry.association.pointer })} />
|
|
193
|
+
<span>
|
|
194
|
+
<span className="font-medium">{entry.association.eventType}</span> {entry.association.eventTime == null ? null : <span className="text-muted-foreground">{formatTime(entry.association.eventTime)}</span>}
|
|
195
|
+
<span className="block text-xs text-muted-foreground">
|
|
196
|
+
From {entry.source.sourceId}, received {formatTime(entry.source.receivedAt)}. {entry.event?.eventId == null ? 'It declares no eventID and cannot be signed.' : entry.event.eventId}
|
|
197
|
+
</span>
|
|
198
|
+
</span>
|
|
199
|
+
</label>
|
|
200
|
+
</li>
|
|
201
|
+
)
|
|
202
|
+
})}
|
|
203
|
+
</ul>
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function ClaimDialog({ passportId, onClose, onDone }: { passportId: string; onClose: () => void; onDone: () => void }) {
|
|
208
|
+
const [tab, setTab] = useState<'enter' | 'retained'>('enter')
|
|
209
|
+
const [form, setForm] = useState<LifecycleEventForm>(() => emptyEventForm(passportId))
|
|
210
|
+
const [role, setRole] = useState<string>('observer')
|
|
211
|
+
const [party, setParty] = useState('')
|
|
212
|
+
const [chosen, setChosen] = useState<{ key: string; imported: { importId: string; pointer: string } }>()
|
|
213
|
+
const [submitToRegistry, setSubmitToRegistry] = useState(false)
|
|
214
|
+
const [busy, setBusy] = useState(false)
|
|
215
|
+
const [error, setError] = useState<unknown>()
|
|
216
|
+
const [result, setResult] = useState<LifecycleClaimView>()
|
|
217
|
+
const built = eventFromForm(form)
|
|
218
|
+
|
|
219
|
+
async function submit(event: FormEvent) {
|
|
220
|
+
event.preventDefault()
|
|
221
|
+
setError(undefined)
|
|
222
|
+
let body: IssueClaimRequest
|
|
223
|
+
if (tab === 'retained') {
|
|
224
|
+
if (chosen == null) return setError(new Error('choose a retained event'))
|
|
225
|
+
body = { imported: chosen.imported }
|
|
226
|
+
} else {
|
|
227
|
+
if ('problems' in built) return setError(new Error(built.problems.join('; ')))
|
|
228
|
+
body = { event: built.event }
|
|
229
|
+
}
|
|
230
|
+
const signedRole = tab === 'retained' && role === 'observer' ? 'authorised-reporter' : role
|
|
231
|
+
setBusy(true)
|
|
232
|
+
try {
|
|
233
|
+
setResult(await api.issueClaim(passportId, { ...body, assertedRole: signedRole, ...(party.trim() === '' ? {} : { issuerParty: party.trim() }), ...(submitToRegistry ? { submit: true } : {}) }))
|
|
234
|
+
onDone()
|
|
235
|
+
} catch (cause) {
|
|
236
|
+
setError(cause)
|
|
237
|
+
} finally {
|
|
238
|
+
setBusy(false)
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return (
|
|
243
|
+
<Dialog open onOpenChange={(open) => (open ? undefined : onClose())}>
|
|
244
|
+
<DialogContent className="max-h-[90vh] overflow-y-auto sm:max-w-3xl">
|
|
245
|
+
<DialogHeader>
|
|
246
|
+
<DialogTitle>Sign a lifecycle claim</DialogTitle>
|
|
247
|
+
<DialogDescription>One EPCIS event that happened, signed with your identity and bound to every passport whose product it names. It never spends a passport, and it is never made from a passport operation, an edit or a sale label.</DialogDescription>
|
|
248
|
+
</DialogHeader>
|
|
249
|
+
{result != null ? (
|
|
250
|
+
<Outcome claim={result} onClose={onClose} />
|
|
251
|
+
) : (
|
|
252
|
+
<form onSubmit={submit} className="space-y-4">
|
|
253
|
+
<Tabs value={tab} onValueChange={(v) => setTab(v as 'enter' | 'retained')}>
|
|
254
|
+
<TabsList>
|
|
255
|
+
<TabsTrigger value="enter">Enter the event</TabsTrigger>
|
|
256
|
+
<TabsTrigger value="retained">A retained event</TabsTrigger>
|
|
257
|
+
</TabsList>
|
|
258
|
+
<TabsContent value="enter" className="space-y-3 pt-3">
|
|
259
|
+
<EventFields form={form} setForm={setForm} />
|
|
260
|
+
<details className="rounded-md border p-3 text-sm">
|
|
261
|
+
<summary className="cursor-pointer">The event as it will be signed</summary>
|
|
262
|
+
<pre className="mt-2 overflow-x-auto text-xs">{'event' in built ? JSON.stringify(built.event, null, 2) : built.problems.join('\n')}</pre>
|
|
263
|
+
</details>
|
|
264
|
+
</TabsContent>
|
|
265
|
+
<TabsContent value="retained" className="space-y-3 pt-3">
|
|
266
|
+
<p className="text-sm text-muted-foreground">The event is signed exactly as it was received, with a link to the import it came from. You report it; you did not observe it.</p>
|
|
267
|
+
<RetainedEvents passportId={passportId} chosen={chosen?.key} setChosen={(key, imported) => setChosen({ key, imported })} />
|
|
268
|
+
</TabsContent>
|
|
269
|
+
</Tabs>
|
|
270
|
+
<RoleFields role={tab === 'retained' && role === 'observer' ? 'authorised-reporter' : role} setRole={setRole} party={party} setParty={setParty} imported={tab === 'retained'} />
|
|
271
|
+
<label className="flex items-center gap-2 text-sm">
|
|
272
|
+
<input type="checkbox" checked={submitToRegistry} onChange={(e) => setSubmitToRegistry(e.target.checked)} />
|
|
273
|
+
Then send it to the registry, which anchors it once for each bound passport
|
|
274
|
+
</label>
|
|
275
|
+
{error == null ? null : <ErrorNotice error={error} title="The claim was refused" />}
|
|
276
|
+
<DialogFooter>
|
|
277
|
+
<Button type="submit" disabled={busy}>
|
|
278
|
+
{busy ? 'Working' : 'Sign the claim'}
|
|
279
|
+
</Button>
|
|
280
|
+
</DialogFooter>
|
|
281
|
+
</form>
|
|
282
|
+
)}
|
|
283
|
+
</DialogContent>
|
|
284
|
+
</Dialog>
|
|
285
|
+
)
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export function DeclareErrorDialog({ passportId, claim, onClose, onDone }: { passportId: string; claim: LifecycleClaimView; onClose: () => void; onDone: () => void }) {
|
|
289
|
+
const [reason, setReason] = useState<'incorrect_data' | 'did_not_occur'>('incorrect_data')
|
|
290
|
+
const [busy, setBusy] = useState(false)
|
|
291
|
+
const [error, setError] = useState<unknown>()
|
|
292
|
+
const [result, setResult] = useState<LifecycleClaimView>()
|
|
293
|
+
|
|
294
|
+
async function submit(event: FormEvent) {
|
|
295
|
+
event.preventDefault()
|
|
296
|
+
setBusy(true)
|
|
297
|
+
setError(undefined)
|
|
298
|
+
try {
|
|
299
|
+
setResult(await api.issueClaim(passportId, { correctionOf: claim.attestationId, reason }))
|
|
300
|
+
onDone()
|
|
301
|
+
} catch (cause) {
|
|
302
|
+
setError(cause)
|
|
303
|
+
} finally {
|
|
304
|
+
setBusy(false)
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return (
|
|
309
|
+
<Dialog open onOpenChange={(open) => (open ? undefined : onClose())}>
|
|
310
|
+
<DialogContent>
|
|
311
|
+
<DialogHeader>
|
|
312
|
+
<DialogTitle>Declare the event in error</DialogTitle>
|
|
313
|
+
<DialogDescription>A signed declaration records the correction and preserves the original event. Your role grant must cover every bound passport at the original event time. Correcting another issuer’s original also requires permission to declare its error.</DialogDescription>
|
|
314
|
+
</DialogHeader>
|
|
315
|
+
{result != null ? (
|
|
316
|
+
<Outcome claim={result} onClose={onClose} />
|
|
317
|
+
) : (
|
|
318
|
+
<form onSubmit={submit} className="space-y-4">
|
|
319
|
+
<p className="text-sm">
|
|
320
|
+
Event <Mono>{claim.eventId}</Mono>
|
|
321
|
+
</p>
|
|
322
|
+
<Field label="Reason" htmlFor="declare-reason">
|
|
323
|
+
<Select value={reason} onValueChange={(v) => setReason(v as 'incorrect_data' | 'did_not_occur')}>
|
|
324
|
+
<SelectTrigger id="declare-reason" className="w-full">
|
|
325
|
+
<SelectValue />
|
|
326
|
+
</SelectTrigger>
|
|
327
|
+
<SelectContent>
|
|
328
|
+
<SelectItem value="incorrect_data">The event's data is incorrect</SelectItem>
|
|
329
|
+
<SelectItem value="did_not_occur">The event did not occur</SelectItem>
|
|
330
|
+
</SelectContent>
|
|
331
|
+
</Select>
|
|
332
|
+
</Field>
|
|
333
|
+
{error == null ? null : <ErrorNotice error={error} title="The declaration was refused" />}
|
|
334
|
+
<DialogFooter>
|
|
335
|
+
<Button type="submit" disabled={busy}>
|
|
336
|
+
{busy ? 'Working' : 'Sign the declaration'}
|
|
337
|
+
</Button>
|
|
338
|
+
</DialogFooter>
|
|
339
|
+
</form>
|
|
340
|
+
)}
|
|
341
|
+
</DialogContent>
|
|
342
|
+
</Dialog>
|
|
343
|
+
)
|
|
344
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// EPCIS events on a page: the notice that says what they are, one list of
|
|
2
|
+
// the events that name an identifier, and the box an outcome is shown in.
|
|
3
|
+
//
|
|
4
|
+
// Everything here is supplied data. No badge on an event is green: a "valid"
|
|
5
|
+
// document passed a check of its format and is not signed, and the list must
|
|
6
|
+
// not look like the passport's own evidence, which is checked against the
|
|
7
|
+
// chain.
|
|
8
|
+
import { Download } from 'lucide-react'
|
|
9
|
+
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
|
|
10
|
+
import { ErrorNotice, Loading, Mono, ToneBadge, ValueView } from '@/components/bits'
|
|
11
|
+
import { api } from '@/lib/api'
|
|
12
|
+
import { SUPPLIED_DATA_NOTICE, extensionMembers, originalPath, provenanceLabel, validityLabel, type Described, type EpcisEventEntry } from '@/lib/epcis'
|
|
13
|
+
import { formatTime, humanise } from '@/lib/format'
|
|
14
|
+
import { useLoad } from '@/lib/use-load'
|
|
15
|
+
|
|
16
|
+
export function SuppliedDataNotice() {
|
|
17
|
+
return (
|
|
18
|
+
<Alert>
|
|
19
|
+
<AlertTitle>Supplied data. Not signed, and not verified.</AlertTitle>
|
|
20
|
+
<AlertDescription>
|
|
21
|
+
<p>{SUPPLIED_DATA_NOTICE}</p>
|
|
22
|
+
</AlertDescription>
|
|
23
|
+
</Alert>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** An outcome in words: a title, a tone and the sentences under it. */
|
|
28
|
+
export function DescribedBox({ described }: { described: Described }) {
|
|
29
|
+
return (
|
|
30
|
+
<div className="space-y-2 rounded-lg border p-4" role="status">
|
|
31
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
32
|
+
<ToneBadge tone={described.tone}>{described.title}</ToneBadge>
|
|
33
|
+
</div>
|
|
34
|
+
<ul className="list-disc space-y-1 pl-5 text-sm">
|
|
35
|
+
{described.lines.map((line, i) => (
|
|
36
|
+
<li key={i} className="break-words">
|
|
37
|
+
{line}
|
|
38
|
+
</li>
|
|
39
|
+
))}
|
|
40
|
+
</ul>
|
|
41
|
+
</div>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function EventRow({ entry }: { entry: EpcisEventEntry }) {
|
|
46
|
+
const validity = validityLabel(entry.source.documentValidity)
|
|
47
|
+
const extensions = extensionMembers(entry)
|
|
48
|
+
const { association, event, source } = entry
|
|
49
|
+
return (
|
|
50
|
+
<li className="space-y-2 p-3 text-sm">
|
|
51
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
52
|
+
<span className="font-medium">{association.eventType}</span>
|
|
53
|
+
<ToneBadge tone="muted">{humanise(association.role)}</ToneBadge>
|
|
54
|
+
<ToneBadge tone={validity.tone}>{validity.label}</ToneBadge>
|
|
55
|
+
{association.errorDeclared ? <ToneBadge tone="warn">Declared an error by its source</ToneBadge> : null}
|
|
56
|
+
{event?.conflict == null ? null : <ToneBadge tone="warn">{event.conflict.state === 'open' ? 'Another body is held under this identifier' : 'Conflict decided'}</ToneBadge>}
|
|
57
|
+
<span className="text-muted-foreground">{formatTime(association.eventTime)}</span>
|
|
58
|
+
</div>
|
|
59
|
+
<dl className="grid grid-cols-1 gap-x-6 gap-y-1 sm:grid-cols-[10rem_1fr]">
|
|
60
|
+
<dt className="text-muted-foreground">Source</dt>
|
|
61
|
+
<dd className="min-w-0">
|
|
62
|
+
<Mono>{source.sourceId}</Mono>
|
|
63
|
+
<span className="text-muted-foreground"> · {provenanceLabel(source.provenance)} · received {formatTime(source.receivedAt)}</span>
|
|
64
|
+
</dd>
|
|
65
|
+
<dt className="text-muted-foreground">Event identifier</dt>
|
|
66
|
+
<dd className="min-w-0">{event == null ? <span className="text-muted-foreground">not recorded</span> : event.identityKind === 'event-id' ? <Mono>{event.identity}</Mono> : <span className="text-muted-foreground">The event declares none. A local identity was assigned on import.</span>}</dd>
|
|
67
|
+
{association.quantity == null ? null : (
|
|
68
|
+
<>
|
|
69
|
+
<dt className="text-muted-foreground">Quantity</dt>
|
|
70
|
+
<dd>
|
|
71
|
+
{association.quantity} {association.uom ?? ''}
|
|
72
|
+
</dd>
|
|
73
|
+
</>
|
|
74
|
+
)}
|
|
75
|
+
<dt className="text-muted-foreground">Original</dt>
|
|
76
|
+
<dd>
|
|
77
|
+
<a href={originalPath(source.importId)} download className="inline-flex items-center gap-1 underline underline-offset-4">
|
|
78
|
+
<Download className="size-3.5" aria-hidden />
|
|
79
|
+
Download the document as received
|
|
80
|
+
</a>
|
|
81
|
+
</dd>
|
|
82
|
+
</dl>
|
|
83
|
+
{extensions.length === 0 ? null : (
|
|
84
|
+
<div className="space-y-1">
|
|
85
|
+
<p className="text-muted-foreground">Extension members. They are outside the EPCIS schema, kept as received and not interpreted.</p>
|
|
86
|
+
<dl className="grid grid-cols-1 gap-x-6 gap-y-1 sm:grid-cols-[10rem_1fr]">
|
|
87
|
+
{extensions.map((member) => (
|
|
88
|
+
<div key={member.name} className="contents">
|
|
89
|
+
<dt>
|
|
90
|
+
<Mono>{member.name}</Mono>
|
|
91
|
+
</dt>
|
|
92
|
+
<dd className="min-w-0">{member.held ? <ValueView value={member.value} /> : <span className="text-muted-foreground">Named by the import record. Its value is in the original.</span>}</dd>
|
|
93
|
+
</div>
|
|
94
|
+
))}
|
|
95
|
+
</dl>
|
|
96
|
+
</div>
|
|
97
|
+
)}
|
|
98
|
+
</li>
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function EpcisEventList({ entries }: { entries: EpcisEventEntry[] }) {
|
|
103
|
+
if (entries.length === 0) return <p className="text-sm text-muted-foreground">No retained event names this identifier.</p>
|
|
104
|
+
return (
|
|
105
|
+
<ul className="divide-y rounded-lg border">
|
|
106
|
+
{entries.map((entry, i) => (
|
|
107
|
+
<EventRow key={`${entry.source.importId}-${entry.association.pointer}-${entry.association.role}-${i}`} entry={entry} />
|
|
108
|
+
))}
|
|
109
|
+
</ul>
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The events that name each of the identifiers given, searched exactly as written. */
|
|
114
|
+
export function EventsNaming({ identifiers, granularity = 'instance' }: { identifiers: string[]; granularity?: 'instance' | 'class' }) {
|
|
115
|
+
const found = useLoad(async () => (await Promise.all(identifiers.map((identifier) => api.epcisEvents(identifier, granularity)))).flatMap((answer) => answer.events), [identifiers.join('\n'), granularity])
|
|
116
|
+
if (found.loading) return <Loading what="Looking for events" />
|
|
117
|
+
if (found.error != null || found.data == null) return <ErrorNotice error={found.error ?? new Error('no answer')} title="Could not look for events" />
|
|
118
|
+
return <EpcisEventList entries={found.data} />
|
|
119
|
+
}
|
|
@@ -47,6 +47,19 @@ export function RequireAccount({ children }: { children: ReactNode }) {
|
|
|
47
47
|
return <>{children}</>
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/** While nothing is live, say so on every page and name the command that changes it. */
|
|
51
|
+
function DevelopmentBanner() {
|
|
52
|
+
const { health } = useHealth()
|
|
53
|
+
if (health == null || health.livePublishing) return null
|
|
54
|
+
return (
|
|
55
|
+
<div className="border-b bg-muted/50">
|
|
56
|
+
<div className="mx-auto w-full max-w-5xl px-4 py-2 text-sm text-muted-foreground">
|
|
57
|
+
Nothing here is on the chain: this app writes drafts to {health.index.inProcess ? 'an index in this process' : 'its index'}. Run <code className="font-mono">npm run go-live</code> to publish for real.
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
50
63
|
export function Layout() {
|
|
51
64
|
const account = useAccount()
|
|
52
65
|
const { error } = useHealth()
|
|
@@ -73,6 +86,9 @@ export function Layout() {
|
|
|
73
86
|
<NavLink to="/brands" className={navLink}>
|
|
74
87
|
Brands
|
|
75
88
|
</NavLink>
|
|
89
|
+
<NavLink to="/events" className={navLink}>
|
|
90
|
+
Events
|
|
91
|
+
</NavLink>
|
|
76
92
|
<NavLink to="/operations" className={navLink}>
|
|
77
93
|
Operations
|
|
78
94
|
</NavLink>
|
|
@@ -107,6 +123,7 @@ export function Layout() {
|
|
|
107
123
|
</div>
|
|
108
124
|
</div>
|
|
109
125
|
</header>
|
|
126
|
+
<DevelopmentBanner />
|
|
110
127
|
<main className="mx-auto w-full max-w-5xl flex-1 px-4 py-8">
|
|
111
128
|
<Outlet />
|
|
112
129
|
</main>
|