@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,32 @@
1
+ import { createServer } from 'node:http'
2
+ import { once } from 'node:events'
3
+ import type { AddressInfo } from 'node:net'
4
+ import { expect, it } from 'vitest'
5
+ import { loadConfig } from '../src/config.js'
6
+ import { openPlatform } from '../src/platform.js'
7
+
8
+ it.each([false, true])('uses the joined index with configured retraction support %s and reports its failure', async (supportsRetraction) => {
9
+ let healthy = true
10
+ const requests: string[] = []
11
+ const server = createServer((request, response) => {
12
+ requests.push(request.url ?? '')
13
+ response.writeHead(healthy ? 200 : 503, { 'Content-Type': 'application/json' })
14
+ response.end(JSON.stringify({ publisherPolicy: { publisherKeys: ['configured-provider'] } }))
15
+ })
16
+ server.listen(0, '127.0.0.1')
17
+ await once(server, 'listening')
18
+ const url = `http://127.0.0.1:${(server.address() as AddressInfo).port}`
19
+ const platform = await openPlatform({ config: loadConfig({ INDEX_URL: url, INDEX_RETRACTION_URL: supportsRetraction ? url : undefined, INDEX_SUBMIT_TOKEN: 'a'.repeat(64), INDEX_CALLBACK_TOKEN: 'b'.repeat(64), LIVE_PUBLISHING: 'false' }), mode: 'test', log: () => {} })
20
+ try {
21
+ expect(platform.index.url).toBe(url)
22
+ expect(platform.index.supportsRetraction).toBe(supportsRetraction)
23
+ expect(await platform.index.publisherKeys()).toEqual(['configured-provider'])
24
+ healthy = false
25
+ await expect(platform.index.publisherKeys()).rejects.toThrow('HTTP 503')
26
+ expect(platform.index.url).toBe(url)
27
+ expect(requests).toEqual(['/capabilities', '/capabilities'])
28
+ } finally {
29
+ await platform.close()
30
+ await new Promise<void>((resolve, reject) => server.close(error => error ? reject(error) : resolve()))
31
+ }
32
+ })
@@ -0,0 +1,33 @@
1
+ # Background facts for the example bottle profile, version 1: the materials a
2
+ # part may be made of and whether each withstands a dishwasher. The shapes
3
+ # read these facts beside the product document.
4
+
5
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
6
+ @prefix bottle: <https://profiles.example/bottle/v1#> .
7
+
8
+ bottle:Material a rdfs:Class ;
9
+ rdfs:label "Material"@en .
10
+
11
+ bottle:stainless-steel a bottle:Material ;
12
+ rdfs:label "Stainless steel"@en ;
13
+ bottle:withstandsDishwasher true .
14
+
15
+ bottle:glass a bottle:Material ;
16
+ rdfs:label "Glass"@en ;
17
+ bottle:withstandsDishwasher true .
18
+
19
+ bottle:polypropylene a bottle:Material ;
20
+ rdfs:label "Polypropylene"@en ;
21
+ bottle:withstandsDishwasher true .
22
+
23
+ bottle:silicone a bottle:Material ;
24
+ rdfs:label "Silicone"@en ;
25
+ bottle:withstandsDishwasher true .
26
+
27
+ bottle:bamboo a bottle:Material ;
28
+ rdfs:label "Bamboo"@en ;
29
+ bottle:withstandsDishwasher false .
30
+
31
+ bottle:cork a bottle:Material ;
32
+ rdfs:label "Cork"@en ;
33
+ bottle:withstandsDishwasher false .
@@ -0,0 +1,141 @@
1
+ {
2
+ "bindingVersion": "1",
3
+ "id": "example-bottle",
4
+ "version": 1,
5
+ "profile": "example-bottle@1",
6
+ "title": "Example refillable bottle, serialised item",
7
+ "scope": "An example written for this repository to show how a custom profile is bound. The name states which data model the product document uses. It makes no claim that a product or a passport complies with any law or standard.",
8
+ "publisher": {
9
+ "name": "Example publisher",
10
+ "registration": "local"
11
+ },
12
+ "source": {
13
+ "name": "Digital Product Passport standard, example profiles",
14
+ "repository": "https://github.com/bsv-blockchain/dpp",
15
+ "licence": "Apache-2.0",
16
+ "notices": []
17
+ },
18
+ "granularity": "item",
19
+ "payload": {
20
+ "root": "/product",
21
+ "mediaType": "application/ld+json",
22
+ "documents": "one-self-contained"
23
+ },
24
+ "artefacts": [
25
+ {
26
+ "role": "schema",
27
+ "path": "product.schema.json",
28
+ "mediaType": "application/schema+json",
29
+ "byteLength": 2072,
30
+ "sha256": "c0246d22d4bfcbb8a24d2c06e047234c313d026ca376f0a34504f3350a31659e",
31
+ "licence": "Apache-2.0"
32
+ },
33
+ {
34
+ "role": "context",
35
+ "path": "context.jsonld",
36
+ "uri": "https://profiles.example/bottle/v1/context.jsonld",
37
+ "mediaType": "application/ld+json",
38
+ "byteLength": 1137,
39
+ "sha256": "51c2663755c6c1d856a0ee2ba2fedc922a22e35b14eb1ef0894e670af119f699",
40
+ "licence": "Apache-2.0"
41
+ },
42
+ {
43
+ "role": "shapes",
44
+ "path": "shapes.ttl",
45
+ "mediaType": "text/turtle",
46
+ "byteLength": 2846,
47
+ "sha256": "d7d4cb7951e7c4e6269c41a0ed824ed4280b1d3ebc9d707c97f6f091d7ed592f",
48
+ "licence": "Apache-2.0"
49
+ },
50
+ {
51
+ "role": "background",
52
+ "path": "background.ttl",
53
+ "mediaType": "text/turtle",
54
+ "byteLength": 1001,
55
+ "sha256": "9ee7ed8eff1f11b075cf142ae309522f410337a54189b44569a6f60cd45c99b3",
56
+ "licence": "Apache-2.0"
57
+ }
58
+ ],
59
+ "validation": {
60
+ "steps": [
61
+ "json-schema",
62
+ "json-ld-expand",
63
+ "shacl",
64
+ "passport-identity"
65
+ ],
66
+ "engine": {
67
+ "requires": [
68
+ "json-schema-2020-12",
69
+ "shacl-core",
70
+ "shacl-sparql-constraints"
71
+ ]
72
+ },
73
+ "blockingSeverities": [
74
+ "Violation"
75
+ ]
76
+ },
77
+ "identity": {
78
+ "scheme": "gs1-digital-link",
79
+ "comparison": "gs1-key-tuple",
80
+ "subject": {
81
+ "pointers": [
82
+ "/product/id"
83
+ ],
84
+ "keys": [
85
+ "01",
86
+ "21"
87
+ ]
88
+ },
89
+ "mustEqual": [
90
+ {
91
+ "pointer": "/product/gtin",
92
+ "part": "gtin"
93
+ },
94
+ {
95
+ "pointer": "/product/serialNumber",
96
+ "part": "serial"
97
+ }
98
+ ],
99
+ "mustNotContradict": [
100
+ {
101
+ "pointer": "/product/model"
102
+ }
103
+ ],
104
+ "granularityMember": {
105
+ "pointer": "/product/granularity",
106
+ "whenPresent": "item"
107
+ },
108
+ "related": [
109
+ {
110
+ "pointer": "/product/batch",
111
+ "relation": "batch"
112
+ }
113
+ ]
114
+ },
115
+ "vectors": {
116
+ "positive": [
117
+ "vectors/item.json",
118
+ "vectors/item-gtin-13.json"
119
+ ],
120
+ "negative": [
121
+ "vectors/other-product.json",
122
+ "vectors/conflicting-serial.json",
123
+ "vectors/conflicting-gtin.json",
124
+ "vectors/model-as-subject.json",
125
+ "vectors/granularity-mismatch.json",
126
+ "vectors/missing-required-property.json",
127
+ "vectors/unlisted-context.json",
128
+ "vectors/no-passport-identifier.json",
129
+ "vectors/wrong-binding-digest.json",
130
+ "vectors/part-not-dishwasher-safe.json",
131
+ "vectors/registration/altered-artefact.json",
132
+ "vectors/registration/untrusted-binding.json",
133
+ "vectors/registration/conflicting-second-registration.json"
134
+ ]
135
+ },
136
+ "baseline": "native-baseline@2",
137
+ "roles": [
138
+ "passport-writer",
139
+ "passport-reader"
140
+ ]
141
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ "@context": {
3
+ "@version": 1.1,
4
+ "@protected": true,
5
+ "id": "@id",
6
+ "type": "@type",
7
+ "bottle": "https://profiles.example/bottle/v1#",
8
+ "xsd": "http://www.w3.org/2001/XMLSchema#",
9
+ "Bottle": "bottle:Bottle",
10
+ "Part": "bottle:Part",
11
+ "name": "bottle:name",
12
+ "gtin": "bottle:gtin",
13
+ "serialNumber": "bottle:serialNumber",
14
+ "granularity": "bottle:granularity",
15
+ "model": { "@id": "bottle:model", "@type": "@id" },
16
+ "batch": "bottle:batch",
17
+ "capacityMillilitres": "bottle:capacityMillilitres",
18
+ "recycledContentPercent": "bottle:recycledContentPercent",
19
+ "dishwasherSafe": "bottle:dishwasherSafe",
20
+ "careNote": "bottle:careNote",
21
+ "parts": { "@id": "bottle:part", "@container": "@set" },
22
+ "massGrams": "bottle:massGrams",
23
+ "material": {
24
+ "@id": "bottle:material",
25
+ "@type": "@vocab",
26
+ "@context": {
27
+ "stainless-steel": "bottle:stainless-steel",
28
+ "glass": "bottle:glass",
29
+ "polypropylene": "bottle:polypropylene",
30
+ "silicone": "bottle:silicone",
31
+ "bamboo": "bottle:bamboo",
32
+ "cork": "bottle:cork"
33
+ }
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://profiles.example/bottle/v1/product.schema.json",
4
+ "title": "Example bottle, version 1: the product document",
5
+ "description": "The structure of the product document a passport carries under example-bottle@1. Which contexts the document may name is the binding's rule, and whether the document describes the passport's own item is the identity rule, so this schema decides neither.",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "required": ["@context", "id", "type", "name", "gtin", "serialNumber", "capacityMillilitres", "dishwasherSafe", "parts"],
9
+ "properties": {
10
+ "@context": {
11
+ "anyOf": [
12
+ { "type": "string", "minLength": 1 },
13
+ { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 1 } }
14
+ ]
15
+ },
16
+ "id": { "type": "string", "minLength": 1 },
17
+ "type": { "const": "Bottle" },
18
+ "name": { "type": "string", "minLength": 1 },
19
+ "gtin": { "type": "string", "pattern": "^([0-9]{8}|[0-9]{12,14})$" },
20
+ "serialNumber": { "type": "string", "minLength": 1, "maxLength": 20 },
21
+ "granularity": { "enum": ["item", "batch", "model"] },
22
+ "model": { "type": "string", "minLength": 1 },
23
+ "batch": { "type": "string", "minLength": 1 },
24
+ "capacityMillilitres": { "type": "integer", "minimum": 100, "maximum": 5000 },
25
+ "recycledContentPercent": { "type": "number", "minimum": 0, "maximum": 100 },
26
+ "dishwasherSafe": { "type": "boolean" },
27
+ "careNote": { "type": "string", "minLength": 1 },
28
+ "parts": {
29
+ "type": "array",
30
+ "minItems": 1,
31
+ "items": {
32
+ "type": "object",
33
+ "additionalProperties": false,
34
+ "required": ["type", "name", "material"],
35
+ "properties": {
36
+ "type": { "const": "Part" },
37
+ "name": { "type": "string", "minLength": 1 },
38
+ "material": { "enum": ["stainless-steel", "glass", "polypropylene", "silicone", "bamboo", "cork"] },
39
+ "massGrams": { "type": "number", "exclusiveMinimum": 0 }
40
+ }
41
+ }
42
+ }
43
+ }
44
+ }
@@ -0,0 +1,112 @@
1
+ # Shapes for the example bottle profile, version 1.
2
+ # Written for this repository as a worked example of a custom profile.
3
+
4
+ @prefix sh: <http://www.w3.org/ns/shacl#> .
5
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
6
+ @prefix owl: <http://www.w3.org/2002/07/owl#> .
7
+ @prefix bottle: <https://profiles.example/bottle/v1#> .
8
+
9
+ <https://profiles.example/bottle/v1/shapes>
10
+ a owl:Ontology ;
11
+ sh:declare [
12
+ sh:prefix "bottle" ;
13
+ sh:namespace "https://profiles.example/bottle/v1#"^^xsd:anyURI
14
+ ] .
15
+
16
+ bottle:BottleShape
17
+ a sh:NodeShape ;
18
+ sh:targetClass bottle:Bottle ;
19
+ sh:property [
20
+ sh:path bottle:name ;
21
+ sh:datatype xsd:string ;
22
+ sh:minLength 1 ;
23
+ sh:minCount 1 ;
24
+ sh:maxCount 1
25
+ ] ;
26
+ sh:property [
27
+ sh:path bottle:gtin ;
28
+ sh:pattern "^([0-9]{8}|[0-9]{12,14})$" ;
29
+ sh:minCount 1 ;
30
+ sh:maxCount 1
31
+ ] ;
32
+ sh:property [
33
+ sh:path bottle:serialNumber ;
34
+ sh:datatype xsd:string ;
35
+ sh:minLength 1 ;
36
+ sh:maxLength 20 ;
37
+ sh:minCount 1 ;
38
+ sh:maxCount 1
39
+ ] ;
40
+ sh:property [
41
+ sh:path bottle:granularity ;
42
+ sh:in ( "item" "batch" "model" ) ;
43
+ sh:maxCount 1
44
+ ] ;
45
+ sh:property [
46
+ sh:path bottle:capacityMillilitres ;
47
+ sh:datatype xsd:integer ;
48
+ sh:minInclusive 100 ;
49
+ sh:maxInclusive 5000 ;
50
+ sh:minCount 1 ;
51
+ sh:maxCount 1
52
+ ] ;
53
+ sh:property [
54
+ sh:path bottle:recycledContentPercent ;
55
+ sh:minInclusive 0 ;
56
+ sh:maxInclusive 100 ;
57
+ sh:maxCount 1
58
+ ] ;
59
+ sh:property [
60
+ sh:path bottle:dishwasherSafe ;
61
+ sh:datatype xsd:boolean ;
62
+ sh:minCount 1 ;
63
+ sh:maxCount 1
64
+ ] ;
65
+ sh:property [
66
+ sh:path bottle:part ;
67
+ sh:node bottle:PartShape ;
68
+ sh:minCount 1
69
+ ] ;
70
+ # A recommendation, not a requirement: the binding blocks on violations only.
71
+ sh:property [
72
+ sh:path bottle:careNote ;
73
+ sh:minCount 1 ;
74
+ sh:severity sh:Warning ;
75
+ sh:message "A care note is recommended."
76
+ ] ;
77
+ # No core constraint can say this: it joins each part's material to a fact
78
+ # the background file states about that material.
79
+ sh:sparql [
80
+ sh:message "A bottle declared dishwasher safe has a part made of a material that does not withstand a dishwasher." ;
81
+ sh:prefixes <https://profiles.example/bottle/v1/shapes> ;
82
+ sh:select """
83
+ SELECT $this ?value
84
+ WHERE {
85
+ $this bottle:dishwasherSafe true ;
86
+ bottle:part ?part .
87
+ ?part bottle:material ?value .
88
+ ?value bottle:withstandsDishwasher false .
89
+ }
90
+ """
91
+ ] .
92
+
93
+ bottle:PartShape
94
+ a sh:NodeShape ;
95
+ sh:property [
96
+ sh:path bottle:name ;
97
+ sh:datatype xsd:string ;
98
+ sh:minLength 1 ;
99
+ sh:minCount 1 ;
100
+ sh:maxCount 1
101
+ ] ;
102
+ sh:property [
103
+ sh:path bottle:material ;
104
+ sh:class bottle:Material ;
105
+ sh:minCount 1 ;
106
+ sh:maxCount 1
107
+ ] ;
108
+ sh:property [
109
+ sh:path bottle:massGrams ;
110
+ sh:minExclusive 0 ;
111
+ sh:maxCount 1
112
+ ] .
@@ -0,0 +1,44 @@
1
+ {
2
+ "description": "The identifier carries one GTIN and the GTIN member another. Both are valid numbers.",
3
+ "kind": "payload",
4
+ "passportId": "https://passports.example/01/09521234543213/21/BTL-0001",
5
+ "payload": {
6
+ "notice": "Demonstration record: this passport describes no real product.",
7
+ "profile": "example-bottle",
8
+ "profile_version": 1,
9
+ "profile_binding_sha256": "5c63b1ad50c8c6fc299199fa80fccf47029d76db616213cd671d86844e204456",
10
+ "product": {
11
+ "@context": "https://profiles.example/bottle/v1/context.jsonld",
12
+ "id": "https://id.example/01/09521234543213/21/BTL-0001",
13
+ "type": "Bottle",
14
+ "name": "Trail bottle 750",
15
+ "gtin": "09521234543220",
16
+ "serialNumber": "BTL-0001",
17
+ "granularity": "item",
18
+ "model": "https://id.example/01/09521234543213",
19
+ "batch": "LOT-2026-07",
20
+ "capacityMillilitres": 750,
21
+ "recycledContentPercent": 60,
22
+ "dishwasherSafe": true,
23
+ "parts": [
24
+ {
25
+ "type": "Part",
26
+ "name": "Body",
27
+ "material": "stainless-steel",
28
+ "massGrams": 240
29
+ },
30
+ {
31
+ "type": "Part",
32
+ "name": "Cap",
33
+ "material": "polypropylene",
34
+ "massGrams": 35
35
+ }
36
+ ]
37
+ }
38
+ },
39
+ "expected": {
40
+ "status": "fail",
41
+ "cause": "product-identity-mismatch",
42
+ "step": "passport-identity"
43
+ }
44
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "description": "The identifier names serial BTL-0001 and the serial number member says BTL-0009.",
3
+ "kind": "payload",
4
+ "passportId": "https://passports.example/01/09521234543213/21/BTL-0001",
5
+ "payload": {
6
+ "notice": "Demonstration record: this passport describes no real product.",
7
+ "profile": "example-bottle",
8
+ "profile_version": 1,
9
+ "profile_binding_sha256": "5c63b1ad50c8c6fc299199fa80fccf47029d76db616213cd671d86844e204456",
10
+ "product": {
11
+ "@context": "https://profiles.example/bottle/v1/context.jsonld",
12
+ "id": "https://id.example/01/09521234543213/21/BTL-0001",
13
+ "type": "Bottle",
14
+ "name": "Trail bottle 750",
15
+ "gtin": "09521234543213",
16
+ "serialNumber": "BTL-0009",
17
+ "granularity": "item",
18
+ "model": "https://id.example/01/09521234543213",
19
+ "batch": "LOT-2026-07",
20
+ "capacityMillilitres": 750,
21
+ "recycledContentPercent": 60,
22
+ "dishwasherSafe": true,
23
+ "parts": [
24
+ {
25
+ "type": "Part",
26
+ "name": "Body",
27
+ "material": "stainless-steel",
28
+ "massGrams": 240
29
+ },
30
+ {
31
+ "type": "Part",
32
+ "name": "Cap",
33
+ "material": "polypropylene",
34
+ "massGrams": 35
35
+ }
36
+ ]
37
+ }
38
+ },
39
+ "expected": {
40
+ "status": "fail",
41
+ "cause": "product-identity-mismatch",
42
+ "step": "passport-identity"
43
+ }
44
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "description": "An item document that declares model granularity.",
3
+ "kind": "payload",
4
+ "passportId": "https://passports.example/01/09521234543213/21/BTL-0001",
5
+ "payload": {
6
+ "notice": "Demonstration record: this passport describes no real product.",
7
+ "profile": "example-bottle",
8
+ "profile_version": 1,
9
+ "profile_binding_sha256": "5c63b1ad50c8c6fc299199fa80fccf47029d76db616213cd671d86844e204456",
10
+ "product": {
11
+ "@context": "https://profiles.example/bottle/v1/context.jsonld",
12
+ "id": "https://id.example/01/09521234543213/21/BTL-0001",
13
+ "type": "Bottle",
14
+ "name": "Trail bottle 750",
15
+ "gtin": "09521234543213",
16
+ "serialNumber": "BTL-0001",
17
+ "granularity": "model",
18
+ "model": "https://id.example/01/09521234543213",
19
+ "batch": "LOT-2026-07",
20
+ "capacityMillilitres": 750,
21
+ "recycledContentPercent": 60,
22
+ "dishwasherSafe": true,
23
+ "parts": [
24
+ {
25
+ "type": "Part",
26
+ "name": "Body",
27
+ "material": "stainless-steel",
28
+ "massGrams": 240
29
+ },
30
+ {
31
+ "type": "Part",
32
+ "name": "Cap",
33
+ "material": "polypropylene",
34
+ "massGrams": 35
35
+ }
36
+ ]
37
+ }
38
+ },
39
+ "expected": {
40
+ "status": "fail",
41
+ "cause": "product-identity-mismatch",
42
+ "step": "passport-identity"
43
+ }
44
+ }
@@ -0,0 +1,43 @@
1
+ {
2
+ "description": "The same bottle with its GTIN written at thirteen digits, its model link at another host and a care note. The GTIN widths are equivalent and the host is never compared.",
3
+ "kind": "payload",
4
+ "passportId": "https://passports.example/01/09521234543213/21/BTL-0001",
5
+ "payload": {
6
+ "notice": "Demonstration record: this passport describes no real product.",
7
+ "profile": "example-bottle",
8
+ "profile_version": 1,
9
+ "profile_binding_sha256": "5c63b1ad50c8c6fc299199fa80fccf47029d76db616213cd671d86844e204456",
10
+ "product": {
11
+ "@context": "https://profiles.example/bottle/v1/context.jsonld",
12
+ "id": "https://id.example/01/09521234543213/21/BTL-0001",
13
+ "type": "Bottle",
14
+ "name": "Trail bottle 750",
15
+ "gtin": "9521234543213",
16
+ "serialNumber": "BTL-0001",
17
+ "granularity": "item",
18
+ "model": "https://resolver.example/01/09521234543213",
19
+ "batch": "LOT-2026-07",
20
+ "capacityMillilitres": 750,
21
+ "recycledContentPercent": 60,
22
+ "dishwasherSafe": true,
23
+ "parts": [
24
+ {
25
+ "type": "Part",
26
+ "name": "Body",
27
+ "material": "stainless-steel",
28
+ "massGrams": 240
29
+ },
30
+ {
31
+ "type": "Part",
32
+ "name": "Cap",
33
+ "material": "polypropylene",
34
+ "massGrams": 35
35
+ }
36
+ ],
37
+ "careNote": "Rinse before first use."
38
+ }
39
+ },
40
+ "expected": {
41
+ "status": "pass"
42
+ }
43
+ }
@@ -0,0 +1,42 @@
1
+ {
2
+ "description": "A bottle that satisfies every rule, under its own passport. It states no care note, which the shapes recommend: the warning is reported and does not block.",
3
+ "kind": "payload",
4
+ "passportId": "https://passports.example/01/09521234543213/21/BTL-0001",
5
+ "payload": {
6
+ "notice": "Demonstration record: this passport describes no real product.",
7
+ "profile": "example-bottle",
8
+ "profile_version": 1,
9
+ "profile_binding_sha256": "5c63b1ad50c8c6fc299199fa80fccf47029d76db616213cd671d86844e204456",
10
+ "product": {
11
+ "@context": "https://profiles.example/bottle/v1/context.jsonld",
12
+ "id": "https://id.example/01/09521234543213/21/BTL-0001",
13
+ "type": "Bottle",
14
+ "name": "Trail bottle 750",
15
+ "gtin": "09521234543213",
16
+ "serialNumber": "BTL-0001",
17
+ "granularity": "item",
18
+ "model": "https://id.example/01/09521234543213",
19
+ "batch": "LOT-2026-07",
20
+ "capacityMillilitres": 750,
21
+ "recycledContentPercent": 60,
22
+ "dishwasherSafe": true,
23
+ "parts": [
24
+ {
25
+ "type": "Part",
26
+ "name": "Body",
27
+ "material": "stainless-steel",
28
+ "massGrams": 240
29
+ },
30
+ {
31
+ "type": "Part",
32
+ "name": "Cap",
33
+ "material": "polypropylene",
34
+ "massGrams": 35
35
+ }
36
+ ]
37
+ }
38
+ },
39
+ "expected": {
40
+ "status": "pass"
41
+ }
42
+ }
@@ -0,0 +1,43 @@
1
+ {
2
+ "description": "The capacity is missing. The schema requires it and so do the shapes.",
3
+ "kind": "payload",
4
+ "passportId": "https://passports.example/01/09521234543213/21/BTL-0001",
5
+ "payload": {
6
+ "notice": "Demonstration record: this passport describes no real product.",
7
+ "profile": "example-bottle",
8
+ "profile_version": 1,
9
+ "profile_binding_sha256": "5c63b1ad50c8c6fc299199fa80fccf47029d76db616213cd671d86844e204456",
10
+ "product": {
11
+ "@context": "https://profiles.example/bottle/v1/context.jsonld",
12
+ "id": "https://id.example/01/09521234543213/21/BTL-0001",
13
+ "type": "Bottle",
14
+ "name": "Trail bottle 750",
15
+ "gtin": "09521234543213",
16
+ "serialNumber": "BTL-0001",
17
+ "granularity": "item",
18
+ "model": "https://id.example/01/09521234543213",
19
+ "batch": "LOT-2026-07",
20
+ "recycledContentPercent": 60,
21
+ "dishwasherSafe": true,
22
+ "parts": [
23
+ {
24
+ "type": "Part",
25
+ "name": "Body",
26
+ "material": "stainless-steel",
27
+ "massGrams": 240
28
+ },
29
+ {
30
+ "type": "Part",
31
+ "name": "Cap",
32
+ "material": "polypropylene",
33
+ "massGrams": 35
34
+ }
35
+ ]
36
+ }
37
+ },
38
+ "expected": {
39
+ "status": "fail",
40
+ "cause": "schema-invalid",
41
+ "step": "json-schema"
42
+ }
43
+ }