@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,237 @@
|
|
|
1
|
+
// One field of a sector form, drawn from its definition: a control for a
|
|
2
|
+
// single value, a box of fields for a nested object, a list of rows for a
|
|
3
|
+
// repeated one. A field starts empty and stays out of the document until
|
|
4
|
+
// something is entered. Findings and problems appear under the field they
|
|
5
|
+
// concern.
|
|
6
|
+
import type { ReactNode } from 'react'
|
|
7
|
+
import { Button } from '@/components/ui/button'
|
|
8
|
+
import { Input } from '@/components/ui/input'
|
|
9
|
+
import { Label } from '@/components/ui/label'
|
|
10
|
+
import { Textarea } from '@/components/ui/textarea'
|
|
11
|
+
import { FindingLines, NativeSelect, TierBadge } from '@/components/bound/pieces'
|
|
12
|
+
import type { CodeLists, Finding } from '@/lib/api'
|
|
13
|
+
import { NODE_ID, escapePointer, referenceText, withReferenceText, type CodeSource, type Field, type GroupField, type LangValue, type QuantityValue, type Tier, type Value } from '@/lib/bound/form-model'
|
|
14
|
+
import { unitName } from '@/lib/bound/units'
|
|
15
|
+
|
|
16
|
+
export interface FieldContext {
|
|
17
|
+
codes: CodeLists
|
|
18
|
+
/** Findings of the last refused attempt, by the field they were placed at. */
|
|
19
|
+
findings: Map<string, Finding[]>
|
|
20
|
+
/** What stops the document being built, by field. */
|
|
21
|
+
problems: Map<string, string[]>
|
|
22
|
+
disabled?: boolean
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface FieldProps {
|
|
26
|
+
field: Field
|
|
27
|
+
value: Value
|
|
28
|
+
onChange: (value: Value) => void
|
|
29
|
+
/** The field's place in the form's values. */
|
|
30
|
+
pointer: string
|
|
31
|
+
context: FieldContext
|
|
32
|
+
/** Shown beside the label of a top-level property. */
|
|
33
|
+
tier?: Tier
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const idOf = (pointer: string): string => `f${pointer.replace(/[^A-Za-z0-9]+/g, '-')}`
|
|
37
|
+
const textOf = (value: Value): string => (typeof value === 'string' ? value : typeof value === 'number' ? String(value) : '')
|
|
38
|
+
|
|
39
|
+
/** The choices for a code field: a fixed list, or the profile's own vocabulary narrowed to what the field is about. */
|
|
40
|
+
function optionsFor(source: CodeSource, codes: CodeLists): Array<{ value: string; label: string }> {
|
|
41
|
+
if ('options' in source) return source.options
|
|
42
|
+
const only = source.only == null ? undefined : new RegExp(source.only)
|
|
43
|
+
return (codes[source.class] ?? []).filter((option) => (source.prefix == null || option.value.startsWith(source.prefix)) && (only == null || only.test(option.value.slice(option.value.indexOf(':') + 1))))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function Shell({ field, pointer, context, tier, children, wide }: { field: Field; pointer: string; context: FieldContext; tier?: Tier; children: ReactNode; wide?: boolean }) {
|
|
47
|
+
return (
|
|
48
|
+
<div className={wide ? 'space-y-1.5 sm:col-span-2' : 'space-y-1.5'}>
|
|
49
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
50
|
+
<Label htmlFor={idOf(pointer)}>
|
|
51
|
+
{field.label}
|
|
52
|
+
{field.required ? <span className="text-destructive" aria-hidden>*</span> : null}
|
|
53
|
+
</Label>
|
|
54
|
+
{tier == null ? null : <TierBadge tier={tier} />}
|
|
55
|
+
</div>
|
|
56
|
+
{children}
|
|
57
|
+
{field.help == null ? null : <p className="text-xs text-muted-foreground">{field.help}</p>}
|
|
58
|
+
<FindingLines findings={context.findings.get(pointer)} problems={context.problems.get(pointer)} />
|
|
59
|
+
</div>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function FieldView({ field, value, onChange, pointer, context, tier }: FieldProps) {
|
|
64
|
+
const id = idOf(pointer)
|
|
65
|
+
const disabled = context.disabled
|
|
66
|
+
switch (field.kind) {
|
|
67
|
+
case 'text':
|
|
68
|
+
case 'url':
|
|
69
|
+
case 'date':
|
|
70
|
+
case 'dateTime':
|
|
71
|
+
case 'integer':
|
|
72
|
+
case 'decimal':
|
|
73
|
+
return (
|
|
74
|
+
<Shell field={field} pointer={pointer} context={context} tier={tier}>
|
|
75
|
+
<Input
|
|
76
|
+
id={id}
|
|
77
|
+
type={field.kind === 'date' ? 'date' : 'text'}
|
|
78
|
+
inputMode={field.kind === 'integer' ? 'numeric' : field.kind === 'decimal' ? 'decimal' : field.kind === 'url' ? 'url' : undefined}
|
|
79
|
+
value={field.kind === 'url' ? referenceText(value) : textOf(value)}
|
|
80
|
+
onChange={(e) => onChange(field.kind === 'url' ? withReferenceText(value, e.target.value) : e.target.value)}
|
|
81
|
+
placeholder={field.kind === 'url' ? 'https://' : field.kind === 'dateTime' ? '2026-11-02T09:30:00Z' : undefined}
|
|
82
|
+
disabled={disabled}
|
|
83
|
+
spellCheck={field.kind === 'text' ? undefined : false}
|
|
84
|
+
/>
|
|
85
|
+
</Shell>
|
|
86
|
+
)
|
|
87
|
+
case 'longText':
|
|
88
|
+
return (
|
|
89
|
+
<Shell field={field} pointer={pointer} context={context} tier={tier} wide>
|
|
90
|
+
<Textarea id={id} value={textOf(value)} onChange={(e) => onChange(e.target.value)} disabled={disabled} />
|
|
91
|
+
</Shell>
|
|
92
|
+
)
|
|
93
|
+
case 'boolean':
|
|
94
|
+
return (
|
|
95
|
+
<Shell field={field} pointer={pointer} context={context} tier={tier}>
|
|
96
|
+
<NativeSelect id={id} value={value === true ? 'yes' : value === false ? 'no' : ''} onChange={(e) => onChange(e.target.value === 'yes' ? true : e.target.value === 'no' ? false : undefined)} disabled={disabled}>
|
|
97
|
+
<option value="">Not stated</option>
|
|
98
|
+
<option value="yes">Yes</option>
|
|
99
|
+
<option value="no">No</option>
|
|
100
|
+
</NativeSelect>
|
|
101
|
+
</Shell>
|
|
102
|
+
)
|
|
103
|
+
case 'langText': {
|
|
104
|
+
const text = (typeof value === 'object' && value !== null && !Array.isArray(value) ? value : { value: '', language: '' }) as unknown as LangValue
|
|
105
|
+
return (
|
|
106
|
+
<Shell field={field} pointer={pointer} context={context} tier={tier} wide>
|
|
107
|
+
<div className="flex gap-2">
|
|
108
|
+
<Input id={id} value={text.value} onChange={(e) => onChange({ value: e.target.value, language: text.language })} disabled={disabled} />
|
|
109
|
+
<Input className="w-24 shrink-0" value={text.language} onChange={(e) => onChange({ value: text.value, language: e.target.value })} placeholder="Language" aria-label={`Language of ${field.label}`} disabled={disabled} spellCheck={false} />
|
|
110
|
+
</div>
|
|
111
|
+
</Shell>
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
case 'quantity': {
|
|
115
|
+
const quantity = (typeof value === 'object' && value !== null && !Array.isArray(value) ? value : { value: '', unit: '' }) as unknown as QuantityValue
|
|
116
|
+
// A unit a loaded document used stays choosable, even when this form would not offer it.
|
|
117
|
+
const units = quantity.unit !== '' && !field.units.includes(quantity.unit) ? [quantity.unit, ...field.units] : field.units
|
|
118
|
+
return (
|
|
119
|
+
<Shell field={field} pointer={pointer} context={context} tier={tier}>
|
|
120
|
+
<div className="flex gap-2">
|
|
121
|
+
<Input id={id} inputMode="decimal" value={typeof quantity.value === 'number' ? String(quantity.value) : quantity.value} onChange={(e) => onChange({ value: e.target.value, unit: quantity.unit })} disabled={disabled} />
|
|
122
|
+
<NativeSelect className="w-44 shrink-0" value={quantity.unit} onChange={(e) => onChange({ value: quantity.value, unit: e.target.value })} aria-label={`Unit of ${field.label}`} disabled={disabled}>
|
|
123
|
+
<option value="">Unit</option>
|
|
124
|
+
{units.map((unit) => (
|
|
125
|
+
<option key={unit} value={unit}>
|
|
126
|
+
{unitName(unit)} ({unit})
|
|
127
|
+
</option>
|
|
128
|
+
))}
|
|
129
|
+
</NativeSelect>
|
|
130
|
+
</div>
|
|
131
|
+
</Shell>
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
case 'code': {
|
|
135
|
+
const current = referenceText(value)
|
|
136
|
+
const set = (text: string): void => onChange(withReferenceText(value, text))
|
|
137
|
+
const offered = optionsFor(field.codes, context.codes)
|
|
138
|
+
const options = current !== '' && !offered.some((option) => option.value === current) ? [{ value: current, label: current }, ...offered] : offered
|
|
139
|
+
return (
|
|
140
|
+
<Shell field={field} pointer={pointer} context={context} tier={tier}>
|
|
141
|
+
{options.length === 0 ? (
|
|
142
|
+
// No list was loaded for this code. The code can still be written by hand, exactly as the profile's vocabulary spells it.
|
|
143
|
+
<Input id={id} value={current} onChange={(e) => set(e.target.value)} placeholder="A code from the profile's vocabulary" disabled={disabled} spellCheck={false} />
|
|
144
|
+
) : (
|
|
145
|
+
<NativeSelect id={id} value={current} onChange={(e) => set(e.target.value)} disabled={disabled}>
|
|
146
|
+
<option value="">Not stated</option>
|
|
147
|
+
{options.map((option) => (
|
|
148
|
+
<option key={option.value} value={option.value}>
|
|
149
|
+
{option.label}
|
|
150
|
+
</option>
|
|
151
|
+
))}
|
|
152
|
+
</NativeSelect>
|
|
153
|
+
)}
|
|
154
|
+
</Shell>
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
case 'country':
|
|
158
|
+
return (
|
|
159
|
+
<Shell field={field} pointer={pointer} context={context} tier={tier}>
|
|
160
|
+
<Input id={id} value={textOf(value)} onChange={(e) => onChange(e.target.value.toUpperCase())} maxLength={2} placeholder="Two letters, for example AU" disabled={disabled} spellCheck={false} />
|
|
161
|
+
</Shell>
|
|
162
|
+
)
|
|
163
|
+
case 'group':
|
|
164
|
+
return (
|
|
165
|
+
<fieldset className="space-y-3 rounded-lg border p-3 sm:col-span-2">
|
|
166
|
+
<legend className="flex items-center gap-2 px-1 text-sm font-medium">
|
|
167
|
+
{field.label}
|
|
168
|
+
{field.required ? <span className="text-destructive" aria-hidden>*</span> : null}
|
|
169
|
+
{tier == null ? null : <TierBadge tier={tier} />}
|
|
170
|
+
</legend>
|
|
171
|
+
{field.help == null ? null : <p className="text-xs text-muted-foreground">{field.help}</p>}
|
|
172
|
+
<FindingLines findings={context.findings.get(pointer)} problems={context.problems.get(pointer)} />
|
|
173
|
+
<GroupFields field={field} value={value} onChange={onChange} pointer={pointer} context={context} />
|
|
174
|
+
</fieldset>
|
|
175
|
+
)
|
|
176
|
+
case 'list': {
|
|
177
|
+
const rows = Array.isArray(value) ? value : []
|
|
178
|
+
const item = { ...field.item, key: field.key } as Field
|
|
179
|
+
const set = (row: number, next: Value): void => onChange(rows.map((entry, at) => (at === row ? next : entry)))
|
|
180
|
+
return (
|
|
181
|
+
<fieldset className="space-y-3 rounded-lg border p-3 sm:col-span-2">
|
|
182
|
+
<legend className="flex items-center gap-2 px-1 text-sm font-medium">
|
|
183
|
+
{field.label}
|
|
184
|
+
{field.required ? <span className="text-destructive" aria-hidden>*</span> : null}
|
|
185
|
+
{tier == null ? null : <TierBadge tier={tier} />}
|
|
186
|
+
</legend>
|
|
187
|
+
{field.help == null ? null : <p className="text-xs text-muted-foreground">{field.help}</p>}
|
|
188
|
+
<FindingLines findings={context.findings.get(pointer)} problems={context.problems.get(pointer)} />
|
|
189
|
+
{rows.map((entry, row) => (
|
|
190
|
+
<div key={row} className="space-y-2 rounded-md border border-dashed p-3">
|
|
191
|
+
<div className="flex items-center justify-between gap-2">
|
|
192
|
+
<span className="text-xs font-medium text-muted-foreground">
|
|
193
|
+
{field.itemLabel[0].toUpperCase() + field.itemLabel.slice(1)} {row + 1}
|
|
194
|
+
</span>
|
|
195
|
+
<Button type="button" variant="ghost" size="sm" onClick={() => onChange(rows.filter((_, at) => at !== row))} disabled={disabled}>
|
|
196
|
+
Remove
|
|
197
|
+
</Button>
|
|
198
|
+
</div>
|
|
199
|
+
{item.kind === 'group' ? (
|
|
200
|
+
<>
|
|
201
|
+
<FindingLines findings={context.findings.get(`${pointer}/${row}`)} problems={context.problems.get(`${pointer}/${row}`)} />
|
|
202
|
+
<GroupFields field={item} value={entry} onChange={(next) => set(row, next)} pointer={`${pointer}/${row}`} context={context} />
|
|
203
|
+
</>
|
|
204
|
+
) : (
|
|
205
|
+
<div className="grid gap-3 sm:grid-cols-2">
|
|
206
|
+
<FieldView field={{ ...item, label: `${field.itemLabel[0].toUpperCase() + field.itemLabel.slice(1)} ${row + 1}` } as Field} value={entry} onChange={(next) => set(row, next)} pointer={`${pointer}/${row}`} context={context} />
|
|
207
|
+
</div>
|
|
208
|
+
)}
|
|
209
|
+
</div>
|
|
210
|
+
))}
|
|
211
|
+
<Button type="button" variant="outline" size="sm" onClick={() => onChange([...rows, undefined])} disabled={disabled}>
|
|
212
|
+
Add {rows.length === 0 ? 'a' : 'another'} {field.itemLabel}
|
|
213
|
+
</Button>
|
|
214
|
+
</fieldset>
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function GroupFields({ field, value, onChange, pointer, context }: { field: GroupField; value: Value; onChange: (value: Value) => void; pointer: string; context: FieldContext }) {
|
|
221
|
+
const group = (typeof value === 'object' && value !== null && !Array.isArray(value) ? value : {}) as { [key: string]: Value }
|
|
222
|
+
const nodeId = group[NODE_ID]
|
|
223
|
+
return (
|
|
224
|
+
<div className="grid gap-3 sm:grid-cols-2">
|
|
225
|
+
{typeof nodeId !== 'string' ? null : (
|
|
226
|
+
// A loaded document gave this node an identifier. It is kept and can be edited; the form never makes one up.
|
|
227
|
+
<div className="space-y-1.5 sm:col-span-2">
|
|
228
|
+
<Label htmlFor={`${idOf(pointer)}-id`}>Identifier</Label>
|
|
229
|
+
<Input id={`${idOf(pointer)}-id`} value={nodeId} onChange={(e) => onChange({ ...group, [NODE_ID]: e.target.value })} disabled={context.disabled} spellCheck={false} />
|
|
230
|
+
</div>
|
|
231
|
+
)}
|
|
232
|
+
{field.fields.map((child) =>
|
|
233
|
+
child.kind === 'fixed' ? null : <FieldView key={child.key} field={child} value={group[child.key]} onChange={(next) => onChange({ ...group, [child.key]: next })} pointer={`${pointer}/${escapePointer(child.key)}`} context={context} />
|
|
234
|
+
)}
|
|
235
|
+
</div>
|
|
236
|
+
)
|
|
237
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// Small pieces the bound-profile pages share: the tier of a property, the
|
|
2
|
+
// outcome of a view, a validator's findings, and the warning that goes with
|
|
3
|
+
// anything public.
|
|
4
|
+
import type { ComponentProps, ReactNode } from 'react'
|
|
5
|
+
import { cn } from 'cn'
|
|
6
|
+
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
|
|
7
|
+
import { Mono, ToneBadge, type Tone } from '@/components/bits'
|
|
8
|
+
import type { Finding, ViewCheck, ViewStatus } from '@/lib/api'
|
|
9
|
+
import type { Tier } from '@/lib/bound/form-model'
|
|
10
|
+
|
|
11
|
+
export function TierBadge({ tier }: { tier: Tier }) {
|
|
12
|
+
return tier === 'public' ? (
|
|
13
|
+
<ToneBadge tone="warn" className="shrink-0">
|
|
14
|
+
<span title="Written on chain. Anyone can read it, for good.">Public</span>
|
|
15
|
+
</ToneBadge>
|
|
16
|
+
) : (
|
|
17
|
+
<ToneBadge tone="neutral" className="shrink-0">
|
|
18
|
+
<span title="Encrypted and kept off chain for the holder.">Restricted</span>
|
|
19
|
+
</ToneBadge>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const VIEW_TONES: Record<ViewStatus, { tone: Tone; label: string }> = {
|
|
24
|
+
pass: { tone: 'pass', label: 'Pass' },
|
|
25
|
+
fail: { tone: 'fail', label: 'Fail' },
|
|
26
|
+
// A check that did not run to a decision is shown as that, never as a pass.
|
|
27
|
+
'not-checked': { tone: 'unknown', label: 'Not checked' },
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function ViewBadge({ status }: { status: ViewStatus }) {
|
|
31
|
+
const entry = VIEW_TONES[status] ?? VIEW_TONES['not-checked']
|
|
32
|
+
return <ToneBadge tone={entry.tone}>{entry.label}</ToneBadge>
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const STEP_LABELS: Record<string, string> = {
|
|
36
|
+
envelope: 'The payload is the profile\'s envelope',
|
|
37
|
+
binding: 'It declares the binding this reader holds',
|
|
38
|
+
access: 'It carries public properties only',
|
|
39
|
+
assembly: 'The two parts rejoin into one document',
|
|
40
|
+
'json-schema': 'The document fits the profile\'s schema',
|
|
41
|
+
'json-ld-expand': 'The document reads under the profile\'s contexts',
|
|
42
|
+
shacl: 'The document keeps the profile\'s rules',
|
|
43
|
+
'passport-identity': 'The document describes this passport\'s item',
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const GENERIC_MESSAGES: Array<[RegExp, string]> = [
|
|
47
|
+
[/^Less than \d+ values?$/i, 'A value is required here.'],
|
|
48
|
+
[/^More than \d+ values?$/i, 'There are too many values here.'],
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
/** What a finding says, in a sentence: the rule's own message, or a plain one where the engine gave only a count. */
|
|
52
|
+
export function findingText(finding: Finding): string {
|
|
53
|
+
const message = finding.message ?? ''
|
|
54
|
+
const plain = GENERIC_MESSAGES.find(([pattern]) => pattern.test(message))?.[1]
|
|
55
|
+
if (plain != null) return plain
|
|
56
|
+
if (message !== '') return /[.!?]$/.test(message) ? message : `${message}.`
|
|
57
|
+
return `The rule ${finding.constraint} does not hold.`
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const severityTone = (severity: Finding['severity']): string => (severity === 'Violation' ? 'text-destructive' : 'text-amber-700 dark:text-amber-300')
|
|
61
|
+
|
|
62
|
+
/** Findings under the field they concern. A warning is reported and does not block. */
|
|
63
|
+
export function FindingLines({ findings, problems }: { findings?: Finding[]; problems?: string[] }) {
|
|
64
|
+
if ((findings == null || findings.length === 0) && (problems == null || problems.length === 0)) return null
|
|
65
|
+
return (
|
|
66
|
+
<ul className="space-y-0.5 text-xs" role="alert">
|
|
67
|
+
{(problems ?? []).map((problem, i) => (
|
|
68
|
+
<li key={`p${i}`} className="text-destructive">
|
|
69
|
+
{problem}
|
|
70
|
+
</li>
|
|
71
|
+
))}
|
|
72
|
+
{(findings ?? []).map((finding, i) => (
|
|
73
|
+
<li key={`f${i}`} className={severityTone(finding.severity)}>
|
|
74
|
+
{finding.severity === 'Violation' ? '' : `${finding.severity}: `}
|
|
75
|
+
{findingText(finding)}
|
|
76
|
+
</li>
|
|
77
|
+
))}
|
|
78
|
+
</ul>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** One view's outcome with its steps and findings. The title says which view it is, so a public result is never read as a statement about restricted data. */
|
|
83
|
+
export function ViewPanel({ title, check, children }: { title: ReactNode; check: ViewCheck; children?: ReactNode }) {
|
|
84
|
+
return (
|
|
85
|
+
<div className="space-y-3 rounded-lg border p-4">
|
|
86
|
+
<div className="flex flex-wrap items-center justify-between gap-2">
|
|
87
|
+
<h3 className="text-sm font-semibold">{title}</h3>
|
|
88
|
+
<span className="flex items-center gap-2">
|
|
89
|
+
<ViewBadge status={check.status} />
|
|
90
|
+
{check.cause == null ? null : <Mono className="text-muted-foreground">{check.cause}</Mono>}
|
|
91
|
+
</span>
|
|
92
|
+
</div>
|
|
93
|
+
<p className="text-sm text-muted-foreground">{check.summary}</p>
|
|
94
|
+
{children}
|
|
95
|
+
{check.steps.length === 0 ? null : (
|
|
96
|
+
<ul className="divide-y rounded-md border text-sm">
|
|
97
|
+
{check.steps.map((step, i) => (
|
|
98
|
+
<li key={`${step.step}${i}`} className="space-y-1 p-2">
|
|
99
|
+
<div className="flex items-center justify-between gap-3">
|
|
100
|
+
<span>{STEP_LABELS[step.step] ?? step.step}</span>
|
|
101
|
+
<ViewBadge status={step.status} />
|
|
102
|
+
</div>
|
|
103
|
+
{step.messages.length === 0 ? null : (
|
|
104
|
+
<ul className="list-disc space-y-0.5 pl-5 text-xs text-muted-foreground">
|
|
105
|
+
{step.messages.map((message, j) => (
|
|
106
|
+
<li key={j}>{message}</li>
|
|
107
|
+
))}
|
|
108
|
+
</ul>
|
|
109
|
+
)}
|
|
110
|
+
</li>
|
|
111
|
+
))}
|
|
112
|
+
</ul>
|
|
113
|
+
)}
|
|
114
|
+
{check.findings.length === 0 ? null : (
|
|
115
|
+
<div className="space-y-1">
|
|
116
|
+
<p className="text-xs font-medium">Findings</p>
|
|
117
|
+
<ul className="space-y-1 text-xs">
|
|
118
|
+
{check.findings.map((finding, i) => (
|
|
119
|
+
<li key={i} className={severityTone(finding.severity)}>
|
|
120
|
+
{finding.severity}: {findingText(finding)} {finding.property == null ? null : <Mono className="text-muted-foreground">{finding.pointer ?? finding.property}</Mono>}
|
|
121
|
+
</li>
|
|
122
|
+
))}
|
|
123
|
+
</ul>
|
|
124
|
+
</div>
|
|
125
|
+
)}
|
|
126
|
+
{check.withheld.length === 0 ? null : (
|
|
127
|
+
<div className="space-y-1">
|
|
128
|
+
<p className="text-xs font-medium">Not decided from this view</p>
|
|
129
|
+
<ul className="list-disc space-y-0.5 pl-5 text-xs text-muted-foreground">
|
|
130
|
+
{check.withheld.map((rule, i) => (
|
|
131
|
+
<li key={i}>
|
|
132
|
+
The rule on <Mono>{rule.property}</Mono> needs a restricted property.
|
|
133
|
+
</li>
|
|
134
|
+
))}
|
|
135
|
+
</ul>
|
|
136
|
+
</div>
|
|
137
|
+
)}
|
|
138
|
+
</div>
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function PublicDataWarning({ split }: { split: boolean }) {
|
|
143
|
+
return (
|
|
144
|
+
<Alert className="border-amber-300 bg-amber-50 text-amber-950 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-100">
|
|
145
|
+
<AlertTitle>Public data is permanent and world-readable</AlertTitle>
|
|
146
|
+
<AlertDescription className="text-current">
|
|
147
|
+
<p>
|
|
148
|
+
{split ? 'Every property marked Public is written to a public blockchain.' : 'This profile makes no split: the whole document is written to a public blockchain.'} Anyone can read it, for good, and it cannot be withdrawn or redacted.
|
|
149
|
+
</p>
|
|
150
|
+
{split ? <p>The split is by property, not by value. A restricted value that you repeat inside a public property, such as a name in a description or a link to a private file, is published with that property.</p> : null}
|
|
151
|
+
</AlertDescription>
|
|
152
|
+
</Alert>
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** A plain select, for forms with many of them. An empty choice writes nothing. */
|
|
157
|
+
export function NativeSelect({ className, children, ...props }: ComponentProps<'select'>) {
|
|
158
|
+
return (
|
|
159
|
+
<select
|
|
160
|
+
className={cn(
|
|
161
|
+
'h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-2 py-1 text-base shadow-xs outline-none transition-[color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:bg-input/30',
|
|
162
|
+
className
|
|
163
|
+
)}
|
|
164
|
+
{...props}
|
|
165
|
+
>
|
|
166
|
+
{children}
|
|
167
|
+
</select>
|
|
168
|
+
)
|
|
169
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// A passport under a profile held by a binding, as a reader sees it. Two
|
|
2
|
+
// checks are shown and they are kept apart. The public view is made by any
|
|
3
|
+
// reader from the public payload, and is a statement about that payload
|
|
4
|
+
// only. The authorised view is made for the holder, who can open the
|
|
5
|
+
// restricted part: the two parts are rejoined and checked whole. Whether
|
|
6
|
+
// the restricted part is the one the record commits to is a third thing,
|
|
7
|
+
// the protocol's owner-tier check, and has a line of its own.
|
|
8
|
+
import { useMemo, useState, type FormEvent } from 'react'
|
|
9
|
+
import { Button } from '@/components/ui/button'
|
|
10
|
+
import { Input } from '@/components/ui/input'
|
|
11
|
+
import { ErrorNotice, Loading, Mono, Section } from '@/components/bits'
|
|
12
|
+
import { ViewBadge, ViewPanel } from '@/components/bound/pieces'
|
|
13
|
+
import { ProductView } from '@/components/bound/structured-value'
|
|
14
|
+
import { api, type AuthorisedReading, type PayloadCheck, type ProductReading, type Verification, type ViewCheck } from '@/lib/api'
|
|
15
|
+
import { describeProduct } from '@/lib/bound/display'
|
|
16
|
+
import { labelsOf } from '@/lib/bound/form-model'
|
|
17
|
+
import { sectorFormFor } from '@/lib/bound/forms'
|
|
18
|
+
import { isRecord, shortTxid } from '@/lib/format'
|
|
19
|
+
import { useLoad } from '@/lib/use-load'
|
|
20
|
+
|
|
21
|
+
/** The envelope of a payload under a binding, when the payload is one. */
|
|
22
|
+
export function boundPayload(payload: unknown): { profile: string; bindingDigest: string; notice?: string; product: Record<string, unknown> } | undefined {
|
|
23
|
+
if (!isRecord(payload) || typeof payload.profile !== 'string' || typeof payload.profile_binding_sha256 !== 'string' || !isRecord(payload.product)) return undefined
|
|
24
|
+
return { profile: `${payload.profile}@${String(payload.profile_version)}`, bindingDigest: payload.profile_binding_sha256, ...(typeof payload.notice === 'string' ? { notice: payload.notice } : {}), product: payload.product }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const labelsFor = (profile: string): Map<string, string> => {
|
|
28
|
+
const form = sectorFormFor(profile)
|
|
29
|
+
return form == null ? new Map() : labelsOf(form)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The check of the newest state's public payload, among the checks of every state. */
|
|
33
|
+
const newestCheck = (verification: Verification | undefined): PayloadCheck | undefined => {
|
|
34
|
+
const tip = verification?.lineage.at(-1)?.txid
|
|
35
|
+
return verification?.payloadChecks?.find((check) => check.txid === tip) ?? verification?.payloadChecks?.at(-1)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function PublicViewPanel({ check, states }: { check: ViewCheck | undefined; states?: PayloadCheck[] }) {
|
|
39
|
+
if (check == null) {
|
|
40
|
+
return (
|
|
41
|
+
<div className="space-y-2 rounded-lg border p-4">
|
|
42
|
+
<div className="flex flex-wrap items-center justify-between gap-2">
|
|
43
|
+
<h3 className="text-sm font-semibold">Public view</h3>
|
|
44
|
+
<ViewBadge status="not-checked" />
|
|
45
|
+
</div>
|
|
46
|
+
<p className="text-sm text-muted-foreground">The public payload was not checked: no report was read for this passport. A check that did not run is not a pass.</p>
|
|
47
|
+
</div>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
const earlier = (states ?? []).slice(0, -1)
|
|
51
|
+
return (
|
|
52
|
+
<ViewPanel title="Public view: the public payload of the newest state" check={check}>
|
|
53
|
+
{earlier.length === 0 ? null : (
|
|
54
|
+
<ul className="space-y-1 text-xs text-muted-foreground">
|
|
55
|
+
{earlier.map((state) => (
|
|
56
|
+
<li key={state.txid} className="flex items-center gap-2">
|
|
57
|
+
Earlier state <Mono>{shortTxid(state.txid)}</Mono> <ViewBadge status={state.publicView.status} />
|
|
58
|
+
</li>
|
|
59
|
+
))}
|
|
60
|
+
</ul>
|
|
61
|
+
)}
|
|
62
|
+
</ViewPanel>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** What any reader has: the public part of the document and the check of it. Nothing here speaks for the restricted part. */
|
|
67
|
+
export function PublicReading({ product, verification }: { product: ProductReading; verification?: Verification }) {
|
|
68
|
+
const labels = useMemo(() => labelsFor(product.profile), [product.profile])
|
|
69
|
+
const properties = useMemo(() => describeProduct({ publicProduct: product.publicProduct, access: product.access }, labels), [product, labels])
|
|
70
|
+
return (
|
|
71
|
+
<>
|
|
72
|
+
<Section title="Product">
|
|
73
|
+
<p className="text-sm text-muted-foreground">
|
|
74
|
+
The public part of the product document, as written on chain under <Mono>{product.profile}</Mono>.{' '}
|
|
75
|
+
{product.access == null ? 'This reader holds no public list for the profile, so it cannot say which other properties exist.' : 'Any other property of the document is restricted: it is not on chain and is not shown here.'}
|
|
76
|
+
</p>
|
|
77
|
+
<ProductView properties={properties} />
|
|
78
|
+
</Section>
|
|
79
|
+
<Section title="Product data checks">
|
|
80
|
+
<PublicViewPanel check={newestCheck(verification)?.publicView} states={verification?.payloadChecks} />
|
|
81
|
+
<div className="space-y-2 rounded-lg border p-4">
|
|
82
|
+
<div className="flex flex-wrap items-center justify-between gap-2">
|
|
83
|
+
<h3 className="text-sm font-semibold">Authorised view: the public payload with the restricted part</h3>
|
|
84
|
+
<ViewBadge status="not-checked" />
|
|
85
|
+
</div>
|
|
86
|
+
<p className="text-sm text-muted-foreground">Not checked here. This page reads the public payload alone, so nothing on it is a statement about restricted data, or about whether a restricted part exists. The holder sees this check on the passport's own page.</p>
|
|
87
|
+
</div>
|
|
88
|
+
</Section>
|
|
89
|
+
</>
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* What the holder has: the same public view, then the authorised view once
|
|
95
|
+
* the restricted part is opened. A recipient opens it with the claim code
|
|
96
|
+
* they accepted with.
|
|
97
|
+
*/
|
|
98
|
+
export function HolderReading({ passportId, payload, needsClaimCode }: { passportId: string; payload: NonNullable<ReturnType<typeof boundPayload>>; needsClaimCode: boolean }) {
|
|
99
|
+
const verification = useLoad(() => api.verify(passportId), [passportId, payload.bindingDigest, JSON.stringify(payload.product)])
|
|
100
|
+
const [claimCode, setClaimCode] = useState('')
|
|
101
|
+
const [asked, setAsked] = useState(!needsClaimCode)
|
|
102
|
+
const authorised = useLoad<AuthorisedReading | undefined>(() => (asked ? api.authorisedView(passportId, needsClaimCode ? claimCode : undefined) : Promise.resolve(undefined)), [passportId, asked, JSON.stringify(payload.product)])
|
|
103
|
+
const labels = useMemo(() => labelsFor(payload.profile), [payload.profile])
|
|
104
|
+
const access = authorised.data?.access ?? verification.data?.product?.access
|
|
105
|
+
const properties = useMemo(() => describeProduct({ publicProduct: payload.product, restrictedProduct: authorised.data?.restrictedProduct, access }, labels), [payload.product, authorised.data, access, labels])
|
|
106
|
+
|
|
107
|
+
function open(event: FormEvent) {
|
|
108
|
+
event.preventDefault()
|
|
109
|
+
if (asked) authorised.reload()
|
|
110
|
+
else setAsked(true)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<>
|
|
115
|
+
<Section title="Product">
|
|
116
|
+
<p className="text-sm text-muted-foreground">
|
|
117
|
+
The product document under <Mono>{payload.profile}</Mono>. A public property is on chain for anyone. A restricted property is sealed off chain{authorised.data?.restrictedProduct == null ? ' and is shown once it is opened below' : ' and was opened for you'}.
|
|
118
|
+
</p>
|
|
119
|
+
<ProductView properties={properties} />
|
|
120
|
+
</Section>
|
|
121
|
+
<Section title="Product data checks">
|
|
122
|
+
{verification.loading ? <Loading what="Reading the public view" /> : verification.error != null ? <ErrorNotice error={verification.error} title="The public view could not be read" /> : <PublicViewPanel check={newestCheck(verification.data)?.publicView} states={verification.data?.payloadChecks} />}
|
|
123
|
+
{needsClaimCode ? (
|
|
124
|
+
<form onSubmit={open} className="flex flex-col gap-2 sm:flex-row sm:items-center">
|
|
125
|
+
<Input value={claimCode} onChange={(e) => setClaimCode(e.target.value)} placeholder="Claim code" aria-label="Claim code" required autoComplete="off" spellCheck={false} className="sm:w-64" />
|
|
126
|
+
<Button type="submit" variant="outline">
|
|
127
|
+
Open the restricted part
|
|
128
|
+
</Button>
|
|
129
|
+
</form>
|
|
130
|
+
) : null}
|
|
131
|
+
{!asked ? (
|
|
132
|
+
<p className="text-sm text-muted-foreground">The authorised view is not checked until the restricted part is opened with the claim code.</p>
|
|
133
|
+
) : authorised.loading ? (
|
|
134
|
+
<Loading what="Opening the restricted part" />
|
|
135
|
+
) : authorised.error != null || authorised.data == null ? (
|
|
136
|
+
<ErrorNotice error={authorised.error ?? new Error('no answer')} title="The authorised view could not be read" />
|
|
137
|
+
) : (
|
|
138
|
+
<>
|
|
139
|
+
<div className="space-y-2 rounded-lg border p-4">
|
|
140
|
+
<div className="flex flex-wrap items-center justify-between gap-2">
|
|
141
|
+
<h3 className="text-sm font-semibold">Owner-tier check: the stored restricted part against the record</h3>
|
|
142
|
+
<ViewBadge status={authorised.data.ownerTier.status} />
|
|
143
|
+
</div>
|
|
144
|
+
<p className="text-sm text-muted-foreground">{authorised.data.ownerTier.detail}</p>
|
|
145
|
+
</div>
|
|
146
|
+
<ViewPanel title="Authorised view: the public payload with the restricted part" check={authorised.data.authorisedView} />
|
|
147
|
+
</>
|
|
148
|
+
)}
|
|
149
|
+
</Section>
|
|
150
|
+
</>
|
|
151
|
+
)
|
|
152
|
+
}
|