@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.
Files changed (178) hide show
  1. package/LICENSE +203 -0
  2. package/NOTICE +2 -0
  3. package/PATENTS +12 -0
  4. package/README.md +93 -2
  5. package/dist/index.js +125 -0
  6. package/package.json +57 -4
  7. package/template/Dockerfile +37 -0
  8. package/template/README.md +389 -0
  9. package/template/_dockerignore +6 -0
  10. package/template/_env.example +122 -0
  11. package/template/_github/workflows/ci.yml +23 -0
  12. package/template/_gitignore +8 -0
  13. package/template/_prettierrc +6 -0
  14. package/template/apps/api/API.md +119 -0
  15. package/template/apps/api/package.json +39 -0
  16. package/template/apps/api/src/auth.ts +55 -0
  17. package/template/apps/api/src/bound-profiles.ts +590 -0
  18. package/template/apps/api/src/claims.ts +204 -0
  19. package/template/apps/api/src/cli.ts +99 -0
  20. package/template/apps/api/src/config.ts +180 -0
  21. package/template/apps/api/src/custody.ts +358 -0
  22. package/template/apps/api/src/dev-index.ts +120 -0
  23. package/template/apps/api/src/env-file.ts +55 -0
  24. package/template/apps/api/src/env.ts +14 -0
  25. package/template/apps/api/src/epcis/exchange.ts +434 -0
  26. package/template/apps/api/src/epcis/mongo-storage.ts +381 -0
  27. package/template/apps/api/src/epcis/routes.ts +364 -0
  28. package/template/apps/api/src/epcis/sources.ts +142 -0
  29. package/template/apps/api/src/go-live.ts +226 -0
  30. package/template/apps/api/src/http-error.ts +15 -0
  31. package/template/apps/api/src/identifiers.ts +57 -0
  32. package/template/apps/api/src/index-client.ts +261 -0
  33. package/template/apps/api/src/index-projects.ts +53 -0
  34. package/template/apps/api/src/lifecycle-authority.ts +49 -0
  35. package/template/apps/api/src/lifecycle.ts +485 -0
  36. package/template/apps/api/src/main.ts +58 -0
  37. package/template/apps/api/src/parties.ts +68 -0
  38. package/template/apps/api/src/platform.ts +176 -0
  39. package/template/apps/api/src/portability/commands.ts +224 -0
  40. package/template/apps/api/src/portability/export.ts +708 -0
  41. package/template/apps/api/src/portability/package.ts +270 -0
  42. package/template/apps/api/src/portability/restore.ts +863 -0
  43. package/template/apps/api/src/profiles.ts +125 -0
  44. package/template/apps/api/src/reader.ts +265 -0
  45. package/template/apps/api/src/resolver.ts +159 -0
  46. package/template/apps/api/src/sector-examples.ts +390 -0
  47. package/template/apps/api/src/server.ts +613 -0
  48. package/template/apps/api/src/store.ts +426 -0
  49. package/template/apps/api/src/validation-engine.ts +172 -0
  50. package/template/apps/api/src/wallet.ts +359 -0
  51. package/template/apps/api/src/worker.ts +113 -0
  52. package/template/apps/api/src/writer.ts +603 -0
  53. package/template/apps/api/test/bound-http.test.ts +496 -0
  54. package/template/apps/api/test/bound-profiles.test.ts +547 -0
  55. package/template/apps/api/test/config.test.ts +160 -0
  56. package/template/apps/api/test/custody-journal.test.ts +415 -0
  57. package/template/apps/api/test/custody-recovery-profile.test.ts +224 -0
  58. package/template/apps/api/test/custom-profile.test.ts +167 -0
  59. package/template/apps/api/test/env-file.test.ts +53 -0
  60. package/template/apps/api/test/epcis-fixtures.ts +270 -0
  61. package/template/apps/api/test/epcis-http.test.ts +1179 -0
  62. package/template/apps/api/test/epcis-mongo-storage.test.ts +313 -0
  63. package/template/apps/api/test/epcis-separation.test.ts +253 -0
  64. package/template/apps/api/test/epcis-web.test.ts +230 -0
  65. package/template/apps/api/test/exit-exercise.test.ts +1038 -0
  66. package/template/apps/api/test/external-index.test.ts +32 -0
  67. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/background.ttl +33 -0
  68. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/binding.json +141 -0
  69. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/context.jsonld +36 -0
  70. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/product.schema.json +44 -0
  71. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/shapes.ttl +112 -0
  72. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/conflicting-gtin.json +44 -0
  73. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/conflicting-serial.json +44 -0
  74. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/granularity-mismatch.json +44 -0
  75. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/item-gtin-13.json +43 -0
  76. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/item.json +42 -0
  77. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/missing-required-property.json +43 -0
  78. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/model-as-subject.json +44 -0
  79. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/no-passport-identifier.json +43 -0
  80. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/other-product.json +44 -0
  81. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/part-not-dishwasher-safe.json +45 -0
  82. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/altered-artefact.json +19 -0
  83. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/altered-background.ttl +33 -0
  84. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/conflicting-binding.json +141 -0
  85. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/conflicting-second-registration.json +19 -0
  86. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/untrusted-binding.json +13 -0
  87. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/unlisted-context.json +47 -0
  88. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/wrong-binding-digest.json +44 -0
  89. package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/binding.json +88 -0
  90. package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/product.schema.json +25 -0
  91. package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/item.json +26 -0
  92. package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/missing-required-property.json +27 -0
  93. package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/no-passport-identifier.json +27 -0
  94. package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/other-product.json +28 -0
  95. package/template/apps/api/test/go-live.test.ts +179 -0
  96. package/template/apps/api/test/gs1-global-setup.ts +33 -0
  97. package/template/apps/api/test/gs1-test-env.ts +5 -0
  98. package/template/apps/api/test/identifier-host.test.ts +256 -0
  99. package/template/apps/api/test/index-projects.test.ts +81 -0
  100. package/template/apps/api/test/lifecycle-claims.test.ts +546 -0
  101. package/template/apps/api/test/lifecycle-fixtures.ts +167 -0
  102. package/template/apps/api/test/lifecycle.test.ts +147 -0
  103. package/template/apps/api/test/manifest-notice.test.ts +36 -0
  104. package/template/apps/api/test/network-guard.ts +113 -0
  105. package/template/apps/api/test/portability.test.ts +655 -0
  106. package/template/apps/api/test/profile-bundle-resolver.test.ts +198 -0
  107. package/template/apps/api/test/retired-profiles.test.ts +216 -0
  108. package/template/apps/api/test/sector-cutover.test.ts +95 -0
  109. package/template/apps/api/test/sector-forms.test.ts +420 -0
  110. package/template/apps/api/test/unjoined-index.test.ts +62 -0
  111. package/template/apps/api/test/validation-engine.test.ts +328 -0
  112. package/template/apps/api/test/wallet-monitor.test.ts +38 -0
  113. package/template/apps/api/test/writer-journal.test.ts +327 -0
  114. package/template/apps/api/tsconfig.json +9 -0
  115. package/template/apps/api/vitest.config.ts +12 -0
  116. package/template/apps/web/components.json +21 -0
  117. package/template/apps/web/index.html +12 -0
  118. package/template/apps/web/package.json +33 -0
  119. package/template/apps/web/src/app.tsx +55 -0
  120. package/template/apps/web/src/components/bits.tsx +188 -0
  121. package/template/apps/web/src/components/bound/bound-passport-form.tsx +368 -0
  122. package/template/apps/web/src/components/bound/field-view.tsx +237 -0
  123. package/template/apps/web/src/components/bound/pieces.tsx +169 -0
  124. package/template/apps/web/src/components/bound/readings.tsx +152 -0
  125. package/template/apps/web/src/components/bound/structured-value.tsx +114 -0
  126. package/template/apps/web/src/components/claim-dialog.tsx +344 -0
  127. package/template/apps/web/src/components/epcis-events.tsx +119 -0
  128. package/template/apps/web/src/components/layout.tsx +135 -0
  129. package/template/apps/web/src/components/lifecycle-claims.tsx +199 -0
  130. package/template/apps/web/src/components/passport-form.tsx +244 -0
  131. package/template/apps/web/src/components/read-passport.tsx +49 -0
  132. package/template/apps/web/src/components/reading.tsx +150 -0
  133. package/template/apps/web/src/components/ui/alert.tsx +65 -0
  134. package/template/apps/web/src/components/ui/badge.tsx +47 -0
  135. package/template/apps/web/src/components/ui/button.tsx +63 -0
  136. package/template/apps/web/src/components/ui/card.tsx +91 -0
  137. package/template/apps/web/src/components/ui/dialog.tsx +156 -0
  138. package/template/apps/web/src/components/ui/input.tsx +20 -0
  139. package/template/apps/web/src/components/ui/label.tsx +21 -0
  140. package/template/apps/web/src/components/ui/select.tsx +189 -0
  141. package/template/apps/web/src/components/ui/separator.tsx +25 -0
  142. package/template/apps/web/src/components/ui/table.tsx +115 -0
  143. package/template/apps/web/src/components/ui/tabs.tsx +90 -0
  144. package/template/apps/web/src/components/ui/textarea.tsx +17 -0
  145. package/template/apps/web/src/index.css +81 -0
  146. package/template/apps/web/src/lib/api.ts +396 -0
  147. package/template/apps/web/src/lib/auth.ts +10 -0
  148. package/template/apps/web/src/lib/bound/battery-form.ts +269 -0
  149. package/template/apps/web/src/lib/bound/display.ts +122 -0
  150. package/template/apps/web/src/lib/bound/fields.ts +128 -0
  151. package/template/apps/web/src/lib/bound/form-model.ts +521 -0
  152. package/template/apps/web/src/lib/bound/forms.ts +15 -0
  153. package/template/apps/web/src/lib/bound/identity.ts +48 -0
  154. package/template/apps/web/src/lib/bound/textile-form.ts +236 -0
  155. package/template/apps/web/src/lib/bound/units.ts +37 -0
  156. package/template/apps/web/src/lib/epcis.ts +345 -0
  157. package/template/apps/web/src/lib/format.ts +87 -0
  158. package/template/apps/web/src/lib/lifecycle.ts +350 -0
  159. package/template/apps/web/src/lib/session.tsx +92 -0
  160. package/template/apps/web/src/lib/use-load.ts +46 -0
  161. package/template/apps/web/src/main.tsx +18 -0
  162. package/template/apps/web/src/pages/accept.tsx +113 -0
  163. package/template/apps/web/src/pages/brand.tsx +94 -0
  164. package/template/apps/web/src/pages/brands.tsx +104 -0
  165. package/template/apps/web/src/pages/events.tsx +388 -0
  166. package/template/apps/web/src/pages/home.tsx +51 -0
  167. package/template/apps/web/src/pages/new-passport.tsx +137 -0
  168. package/template/apps/web/src/pages/operations.tsx +169 -0
  169. package/template/apps/web/src/pages/passport.tsx +632 -0
  170. package/template/apps/web/src/pages/public-passport.tsx +64 -0
  171. package/template/apps/web/src/pages/sign-in.tsx +93 -0
  172. package/template/apps/web/src/pages/verify.tsx +30 -0
  173. package/template/apps/web/src/pages/wallet.tsx +141 -0
  174. package/template/apps/web/tsconfig.json +29 -0
  175. package/template/apps/web/vite.config.ts +23 -0
  176. package/template/deploy/compose.yml +38 -0
  177. package/template/package.json +48 -0
  178. package/template/tsconfig.base.json +13 -0
@@ -0,0 +1,230 @@
1
+ // The words the web client puts on EPCIS answers, exercised here because the
2
+ // web app has no test runner of its own and this module touches neither the
3
+ // page nor the network. Each answer below is a real one, from the API over
4
+ // the module, so the test holds the page's words to what the API sends: that
5
+ // an upload was refused or retained, that a history is partial, and that a
6
+ // valid document is never worded as a signed or verified one. The pages
7
+ // around it are type-checked by the build.
8
+ import { afterAll, beforeAll, describe, expect, it } from 'vitest'
9
+ import {
10
+ SUPPLIED_DATA_NOTICE,
11
+ countsLine,
12
+ describePull,
13
+ describePullRefusal,
14
+ describeRefusal,
15
+ describeRetained,
16
+ describeSource,
17
+ eventCounts,
18
+ extensionMembers,
19
+ findingsOf,
20
+ latestFirst,
21
+ mediaTypeOf,
22
+ originalPath,
23
+ passportSpellings,
24
+ provenanceLabel,
25
+ queryFromForm,
26
+ validityLabel,
27
+ type EpcisEventsAnswer,
28
+ type EpcisImportAnswer,
29
+ type EpcisImportSummary,
30
+ type EpcisPullResult,
31
+ type EpcisSource,
32
+ } from '../../web/src/lib/epcis'
33
+ import { mintPassportId } from '../src/identifiers.js'
34
+ import { epcisDocument, item, objectEvent, startApp, startEpcisSource, testConfig, utf8, type Answer, type FixtureSource, type TestApp } from './epcis-fixtures.js'
35
+
36
+ const PASSPORT = mintPassportId({ host: 'passports.example.com', prefix: '952' }, '100000001', 'WEB-1')
37
+ let api: TestApp
38
+ let fixture: FixtureSource
39
+ let failing: FixtureSource
40
+
41
+ beforeAll(async () => {
42
+ fixture = await startEpcisSource(Array.from({ length: 5 }, (_, index) => objectEvent(index + 1, [item(`WEB-${index + 1}`)])))
43
+ failing = await startEpcisSource(Array.from({ length: 5 }, (_, index) => objectEvent(index + 1, [item(`WEB-${index + 1}`)])), { failRequest: (n) => (n === 2 ? 503 : undefined) })
44
+ api = await startApp({
45
+ config: testConfig({
46
+ EPCIS_SOURCES: 'supplier-a,supplier-b,misconfigured',
47
+ EPCIS_SOURCE_SUPPLIER_A_URL: fixture.baseUrl,
48
+ EPCIS_SOURCE_SUPPLIER_A_LOCAL_TEST: 'true',
49
+ EPCIS_SOURCE_SUPPLIER_A_BEARER_TOKEN: 'a-credential-the-page-never-sees',
50
+ EPCIS_SOURCE_SUPPLIER_B_URL: failing.baseUrl,
51
+ EPCIS_SOURCE_SUPPLIER_B_LOCAL_TEST: 'true',
52
+ EPCIS_SOURCE_MISCONFIGURED_URL: 'https://events.example.org/epcis',
53
+ EPCIS_SOURCE_MISCONFIGURED_ORIGINS: 'https://other.example.org',
54
+ EPCIS_SOURCE_MISCONFIGURED_REPEAT_LISTS: 'true',
55
+ }),
56
+ })
57
+ })
58
+ afterAll(async () => {
59
+ await api.close()
60
+ await fixture.close()
61
+ await failing.close()
62
+ })
63
+
64
+ /** An error answer as the web client's fetch wrapper hands it to a page: the code, the description and everything else. */
65
+ const asApiError = (answer: Answer): { code: string; message: string; details: Record<string, unknown> } => {
66
+ const { error, description, ...details } = answer.body as { error: string; description: string } & Record<string, unknown>
67
+ return { code: error, message: description, details }
68
+ }
69
+
70
+ describe('what the events page says about an upload', () => {
71
+ it('says a retained document is held exactly, and that a valid one is not a signed one', async () => {
72
+ const bytes = utf8(JSON.stringify(epcisDocument([objectEvent(1, [PASSPORT, item('WEB-A')]), objectEvent(2, [item('WEB-A')], { 'example:note': 'seen on the line' })])))
73
+ const first = await api.upload('/api/epcis/imports?requestId=web-1', bytes)
74
+ const described = describeRetained(first.body as EpcisImportAnswer)
75
+ expect(described).toMatchObject({ tone: 'pass', title: 'Retained' })
76
+ expect(described.lines[0]).toBe(`The exact bytes are kept: ${bytes.byteLength} bytes, SHA-256 ${first.body.record.sha256}.`)
77
+ const text = described.lines.join(' ')
78
+ expect(text).toMatch(/passed the format check/)
79
+ expect(text).toMatch(/It is not signed, and nothing here verifies who made it or that its events happened\./)
80
+ expect(text).toMatch(/2 events: 2 new, 0 already held, 0 observed again, 0 in conflict\./)
81
+ expect(described.lines.at(-1)).toBe('Nothing was signed, issued or written to a passport.')
82
+ // Nowhere is a retained document called verified, authentic or trusted.
83
+ expect(text).not.toMatch(/\b(verified|authentic|trusted|proven)\b/)
84
+
85
+ // Sent again, it is the same import and the page says so.
86
+ const again = describeRetained((await api.upload('/api/epcis/imports?requestId=web-1', bytes)).body as EpcisImportAnswer)
87
+ expect(again.title).toBe('Already retained')
88
+ expect(again.lines.join(' ')).toMatch(/already used for the same bytes.*No second copy was kept\./)
89
+ })
90
+
91
+ it('says a document that failed the format check was kept, with its findings, and warns', async () => {
92
+ const { action: _dropped, ...withoutAction } = objectEvent(3, [item('WEB-B')])
93
+ const answer = (await api.upload('/api/epcis/imports?requestId=web-invalid', utf8(JSON.stringify(epcisDocument([withoutAction]))))).body as EpcisImportAnswer
94
+ const described = describeRetained(answer)
95
+ expect(described).toMatchObject({ tone: 'warn', title: 'Retained' })
96
+ expect(described.lines.join(' ')).toMatch(/was kept and did not pass the format check\. \d+ findings? say why\. Its events are not listed against products\./)
97
+ expect(findingsOf(answer.record).length).toBeGreaterThan(0)
98
+ expect(validityLabel(answer.record.documentValidity)).toEqual({ tone: 'warn', label: 'Invalid format, unsigned' })
99
+ })
100
+
101
+ it('says a second body under a held event identifier is kept beside the first', async () => {
102
+ await api.upload('/api/epcis/imports?requestId=web-body-1', utf8(JSON.stringify(epcisDocument([objectEvent(7, [item('WEB-C')])]))))
103
+ const answer = (await api.upload('/api/epcis/imports?requestId=web-body-2', utf8(JSON.stringify(epcisDocument([objectEvent(7, [item('WEB-C')], { disposition: 'in_transit' })]))))).body as EpcisImportAnswer
104
+ const described = describeRetained(answer)
105
+ expect(described.tone).toBe('warn')
106
+ expect(described.lines.join(' ')).toMatch(/1 event arrived with another body than the one already held under the same identifier\. Both are kept until someone records a decision\./)
107
+ expect(eventCounts(answer.record)).toEqual({ total: 1, new: 0, duplicate: 0, newObservation: 0, conflict: 1 })
108
+ })
109
+
110
+ it('says a refused upload was refused, why, and that nothing was kept', async () => {
111
+ const malformed = describeRefusal(asApiError(await api.upload('/api/epcis/imports?requestId=web-bad', utf8('{"type":'))))
112
+ expect(malformed).toMatchObject({ tone: 'fail', title: 'Refused: malformed-json' })
113
+ expect(malformed.lines.at(-1)).toBe('Nothing was kept.')
114
+ const wrongType = describeRefusal(asApiError(await api.upload('/api/epcis/imports?requestId=web-type', utf8('{}'), 'text/csv')))
115
+ expect(wrongType.title).toBe('Refused: unsupported-media-type')
116
+ const conflict = describeRefusal(asApiError(await api.upload('/api/epcis/imports?requestId=web-1', utf8('{}'))))
117
+ expect(conflict.title).toBe('Refused: this request identifier is already used for other bytes')
118
+ expect(conflict.lines.join(' ')).toMatch(/Nothing of this upload was kept\./)
119
+ // A refusal that can be remedied says how.
120
+ expect(describeRefusal({ code: 'gs1-artefact-unavailable', message: 'The GS1 artefact is not in the folder.', details: { remedy: 'Run "dpp-gs1-artefacts fetch".', kept: false } }).lines).toEqual(['The GS1 artefact is not in the folder.', 'Run "dpp-gs1-artefacts fetch".', 'Nothing was kept.'])
121
+ })
122
+ })
123
+
124
+ describe('what the events page says about a pull', () => {
125
+ it('shows the outcome in the module\'s own words, and says an exhausted query is not a complete history', async () => {
126
+ const result = (await api.post('/api/epcis/sources/supplier-a/pulls', { queryId: 'web', query: { perPage: 2 } })).body as EpcisPullResult
127
+ const described = describePull(result)
128
+ expect(described).toMatchObject({ tone: 'pass', title: 'ok: exhausted (exhausted)', partial: false })
129
+ expect(described.lines[0]).toBe(result.detail)
130
+ expect(described.lines[1]).toMatch(/The source named no further page for this query\. That is the end of this query, and not a statement that the source holds nothing else\./)
131
+ expect(described.lines).toContain('3 pages retained in this run. 5 events: 5 new, 0 already held, 0 observed again, 0 in conflict.')
132
+ expect(described.lines).toContain('The local-test option is on for this source: plain http and private addresses were permitted.')
133
+ // Every reason the module gives for the history not being complete is shown as it gave it.
134
+ expect(result.completenessLimits.length).toBeGreaterThan(0)
135
+ for (const limit of result.completenessLimits) expect(described.lines).toContain(`Not complete history: ${limit}.`)
136
+ expect(described.lines.join(' ')).not.toMatch(/complete history of the source is held|all events/i)
137
+ })
138
+
139
+ it('says so when the history is partial, whatever the outcome is called', async () => {
140
+ const stopped = (await api.post('/api/epcis/sources/supplier-b/pulls', { queryId: 'web', query: { perPage: 2 } })).body as EpcisPullResult
141
+ const described = describePull(stopped)
142
+ expect(described).toMatchObject({ tone: 'warn', title: 'source-unavailable: http-error (failed)', partial: true })
143
+ expect(described.lines[1]).toMatch(/^History is partial: this run ended before the source named a last page\./)
144
+ expect(described.lines).toContain('1 page retained in this run. 2 events: 2 new, 0 already held, 0 observed again, 0 in conflict.')
145
+ // The next run continues, and says it did.
146
+ const resumed = describePull((await api.post('/api/epcis/sources/supplier-b/pulls', { queryId: 'web', query: { perPage: 2 } })).body as EpcisPullResult)
147
+ expect(resumed).toMatchObject({ title: 'ok: exhausted (exhausted)', partial: false })
148
+ expect(resumed.lines).toContain('This was run 2. It continued from where the run before it stopped.')
149
+ // A run that retained nothing is a failure, and one a limit stopped is a warning with the module's outcome as its title.
150
+ expect(describePull({ ...stopped, pages: [], events: { total: 0, new: 0, duplicate: 0, newObservation: 0, conflict: 0 } }).tone).toBe('fail')
151
+ expect(describePull({ ...stopped, outcome: 'partial-history', reason: 'page-limit', completion: 'stopped-at-limit', leniencies: ['empty-final-page'] })).toMatchObject({ tone: 'warn', title: 'partial-history: page-limit (stopped-at-limit)', partial: true })
152
+ expect(describePull({ ...stopped, leniencies: ['empty-final-page', 'list-parameters-repeated'] }).lines).toContain('Accepted leniently: empty-final-page, list-parameters-repeated.')
153
+ })
154
+
155
+ it('says a refused pull asked nothing of the source', async () => {
156
+ const refused = describePullRefusal(asApiError(await api.post('/api/epcis/sources/misconfigured/pulls', { queryId: 'web', query: {} })))
157
+ expect(refused).toMatchObject({ tone: 'fail', title: 'Refused: invalid-request' })
158
+ expect(refused.lines.at(-1)).toBe('Nothing was requested from the source, and nothing was kept.')
159
+ })
160
+
161
+ it('describes a source: where it goes, whether a credential is set, and the local-test option', async () => {
162
+ const sources = (await api.get('/api/epcis/sources')).body as EpcisSource[]
163
+ const [first, , misconfigured] = sources
164
+ expect(describeSource(first!)).toEqual([`Queries go to ${fixture.baseUrl}/events.`, `Requests may go to: ${fixture.origin}.`, 'A credential is set on the server (bearer). It is never sent to this page.', 'Local test is on: plain http and private addresses are permitted. Use it only for a source on your own machine.'])
165
+ expect(describeSource(sources[1]!)).toContain('No credential is set.')
166
+ const lines = describeSource(misconfigured!)
167
+ expect(lines).toContain('Lists are sent as repeated parameters, which is recorded as a leniency.')
168
+ expect(lines.at(-1)).toMatch(/^This source cannot be pulled from as it is configured: its permitted origins do not list https:\/\/events\.example\.org/)
169
+ expect(lines.join(' ')).not.toMatch(/Local test is on/)
170
+ // What the page is sent about a source holds no credential to show.
171
+ expect(JSON.stringify(sources)).not.toContain('a-credential-the-page-never-sees')
172
+ expect(queryFromForm({ identifiers: ` ${item('WEB-1')} \n\n${item('WEB-2')},`, eventTypes: 'ObjectEvent', eventIds: '', from: '2026-03-02T08:00:00Z', until: ' ', perPage: '2' })).toEqual({ matchAnyEPC: [item('WEB-1'), item('WEB-2')], eventTypes: ['ObjectEvent'], eventTime: { from: '2026-03-02T08:00:00Z' }, perPage: 2 })
173
+ expect(queryFromForm({ identifiers: '', eventTypes: '', eventIds: '', from: '', until: '', perPage: 'many' })).toEqual({})
174
+ })
175
+ })
176
+
177
+ describe('what a passport page says about the events that name it', () => {
178
+ it('labels every event as supplied data, with its source and its validity, and never as signed or verified', async () => {
179
+ const answer = (await api.get(`/api/epcis/events?identifier=${encodeURIComponent(PASSPORT)}`)).body as EpcisEventsAnswer
180
+ expect(answer.events).toHaveLength(1)
181
+ const [entry] = answer.events
182
+ expect(validityLabel(entry!.source.documentValidity)).toEqual({ tone: 'neutral', label: 'Valid format, unsigned' })
183
+ expect(provenanceLabel(entry!.source.provenance)).toBe('Uploaded file')
184
+ expect(SUPPLIED_DATA_NOTICE).toMatch(/data a source supplied/)
185
+ expect(SUPPLIED_DATA_NOTICE).toMatch(/Nobody signed them here\. Not the holder of this passport, not its brand and not the source\./)
186
+ expect(SUPPLIED_DATA_NOTICE).toMatch(/It does not mean the event happened, or that anyone verified who reported it\./)
187
+ // The label of a valid document is never the green of a passed check.
188
+ for (const validity of ['valid', 'invalid'] as const) expect(validityLabel(validity).tone).not.toBe('pass')
189
+
190
+ const pulled = (await api.get(`/api/epcis/events?identifier=${encodeURIComponent(item('WEB-4'))}`)).body as EpcisEventsAnswer
191
+ expect(provenanceLabel(pulled.events[0]!.source.provenance)).toBe(`Page 2 of a query to ${fixture.origin}`)
192
+ expect(originalPath(pulled.events[0]!.source.importId)).toBe(`/api/epcis/imports/${encodeURIComponent(pulled.events[0]!.source.importId)}/original`)
193
+ })
194
+
195
+ it('shows every extension member of an event, and drops none it has no value for', async () => {
196
+ const answer = (await api.get(`/api/epcis/events?identifier=${encodeURIComponent(item('WEB-A'))}`)).body as EpcisEventsAnswer
197
+ const extended = answer.events.find((entry) => (entry.event?.preservedExtensions.length ?? 0) > 0)!
198
+ expect(extensionMembers(extended)).toEqual([{ name: 'example:note', value: 'seen on the line', held: true }])
199
+ expect(extensionMembers(answer.events.find((entry) => entry !== extended)!)).toEqual([])
200
+ // An entry that names a member and carries no body still lists the member.
201
+ expect(extensionMembers({ event: extended.event })).toEqual([{ name: 'example:note', value: undefined, held: false }])
202
+ expect(extensionMembers({ event: { ...extended.event!, preservedExtensions: ['example:empty', 'example:note'] }, body: { 'example:empty': null, 'example:note': { deep: [1, 2] } } })).toEqual([{ name: 'example:empty', value: null, held: true }, { name: 'example:note', value: { deep: [1, 2] }, held: true }])
203
+ })
204
+
205
+ it('searches the passport\'s own identifier and the same path at the GS1 resolver, and says which', () => {
206
+ expect(passportSpellings(PASSPORT)).toEqual([PASSPORT, PASSPORT.replace('https://passports.example.com', 'https://id.gs1.org')])
207
+ expect(passportSpellings('https://id.gs1.org/01/09521000000011/21/A1')).toEqual(['https://id.gs1.org/01/09521000000011/21/A1'])
208
+ expect(passportSpellings('urn:epc:id:sgtin:9521234.012345.A1')).toEqual(['urn:epc:id:sgtin:9521234.012345.A1'])
209
+ expect(passportSpellings('not an identifier')).toEqual(['not an identifier'])
210
+ })
211
+ })
212
+
213
+ describe('the small things the events page decides', () => {
214
+ it('sends a file under an EPCIS media type when it has one, and lets the API refuse the rest', () => {
215
+ expect(mediaTypeOf({ name: 'events.jsonld', type: '' })).toBe('application/ld+json')
216
+ expect(mediaTypeOf({ name: 'events.json', type: '' })).toBe('application/json')
217
+ expect(mediaTypeOf({ name: 'events.json', type: 'application/ld+json; charset=utf-8' })).toBe('application/ld+json')
218
+ expect(mediaTypeOf({ name: 'events.xml', type: 'text/xml' })).toBe('text/xml')
219
+ expect(mediaTypeOf({ name: 'events', type: '' })).toBe('application/octet-stream')
220
+ })
221
+
222
+ it('lists the latest import first and counts events in plain words', async () => {
223
+ const imports = (await api.get('/api/epcis/imports?limit=200')).body.imports as EpcisImportSummary[]
224
+ const ordered = latestFirst(imports)
225
+ expect(ordered).toHaveLength(imports.length)
226
+ for (let i = 1; i < ordered.length; i += 1) expect(ordered[i - 1]!.receivedAt >= ordered[i]!.receivedAt).toBe(true)
227
+ expect(countsLine({ total: 0, new: 0, duplicate: 0, newObservation: 0, conflict: 0 })).toBe('No events.')
228
+ expect(countsLine({ total: 1, new: 1, duplicate: 0, newObservation: 0, conflict: 0 })).toBe('1 event: 1 new, 0 already held, 0 observed again, 0 in conflict.')
229
+ })
230
+ })