@carrot-foundation/schemas 0.1.6
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 +201 -0
- package/README.md +45 -0
- package/dist/index.js +1 -0
- package/dist/mass-id/index.js +2 -0
- package/dist/mass-id/mass-id.data.schema.js +346 -0
- package/dist/mass-id/mass-id.schema.js +162 -0
- package/dist/shared/base.schema.js +127 -0
- package/dist/shared/definitions.schema.js +283 -0
- package/dist/shared/entities/location.schema.js +68 -0
- package/dist/shared/entities/participant.schema.js +24 -0
- package/dist/shared/helpers.schema.js +16 -0
- package/dist/shared/nft.schema.js +193 -0
- package/package.json +89 -0
- package/schemas/ipfs/collection/collection.example.json +25 -0
- package/schemas/ipfs/collection/collection.schema.json +47 -0
- package/schemas/ipfs/credit/credit.example.json +27 -0
- package/schemas/ipfs/credit/credit.schema.json +61 -0
- package/schemas/ipfs/gas-id/gas-id.attributes.schema.json +219 -0
- package/schemas/ipfs/gas-id/gas-id.data.schema.json +120 -0
- package/schemas/ipfs/gas-id/gas-id.example.json +245 -0
- package/schemas/ipfs/gas-id/gas-id.schema.json +29 -0
- package/schemas/ipfs/mass-id/mass-id.example.json +318 -0
- package/schemas/ipfs/mass-id/mass-id.schema.json +1325 -0
- package/schemas/ipfs/mass-id-audit/mass-id-audit.data.schema.json +130 -0
- package/schemas/ipfs/mass-id-audit/mass-id-audit.example.json +291 -0
- package/schemas/ipfs/mass-id-audit/mass-id-audit.schema.json +26 -0
- package/schemas/ipfs/methodology/methodology.data.schema.json +121 -0
- package/schemas/ipfs/methodology/methodology.example.json +222 -0
- package/schemas/ipfs/methodology/methodology.schema.json +26 -0
- package/schemas/ipfs/purchase-id/purchase-id.attributes.schema.json +91 -0
- package/schemas/ipfs/purchase-id/purchase-id.data.schema.json +337 -0
- package/schemas/ipfs/purchase-id/purchase-id.example.json +224 -0
- package/schemas/ipfs/purchase-id/purchase-id.schema.json +29 -0
- package/schemas/ipfs/recycled-id/recycled-id.attributes.schema.json +202 -0
- package/schemas/ipfs/recycled-id/recycled-id.data.schema.json +63 -0
- package/schemas/ipfs/recycled-id/recycled-id.example.json +213 -0
- package/schemas/ipfs/recycled-id/recycled-id.schema.json +29 -0
- package/schemas/ipfs/shared/base/base.schema.json +163 -0
- package/schemas/ipfs/shared/certificate/certificate.schema.json +145 -0
- package/schemas/ipfs/shared/definitions/definitions.schema.json +250 -0
- package/schemas/ipfs/shared/entities/location/location.schema.json +95 -0
- package/schemas/ipfs/shared/entities/participant/participant.schema.json +28 -0
- package/schemas/ipfs/shared/nft/nft.schema.json +182 -0
- package/schemas/ipfs/shared/references/audit-reference/audit-reference.schema.json +42 -0
- package/schemas/ipfs/shared/references/gas-id-reference/gas-id-reference.schema.json +27 -0
- package/schemas/ipfs/shared/references/mass-id-reference/mass-id-reference.schema.json +27 -0
- package/schemas/ipfs/shared/references/methodology-reference/methodology-reference.schema.json +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# 🥕 Carrot IPFS Schemas
|
|
2
|
+
|
|
3
|
+
This repository contains all JSON Schemas used across the Carrot ecosystem.
|
|
4
|
+
|
|
5
|
+
These schemas define the structure of IPFS metadata for tokenized assets.
|
|
6
|
+
They are versioned, publicly referenceable, and used for validation, traceability, and frontend/backend integration.
|
|
7
|
+
|
|
8
|
+
## 📦 Structure
|
|
9
|
+
|
|
10
|
+
- Schemas are organized by type (e.g., `mass-id`, `gas-id`, `shared`) and follow [Semantic Versioning](https://semver.org/), but folder names are not versioned.
|
|
11
|
+
- Each schema lives in its own folder and includes an `example.json` for testing and documentation.
|
|
12
|
+
- Shared components like `signature`, `attribute`, and the `root` schema are located in `schemas/ipfs/shared`.
|
|
13
|
+
|
|
14
|
+
## 🔖 Versioning
|
|
15
|
+
|
|
16
|
+
- Schemas are versioned using Git tags (`vX.Y.Z`); directory names are not versioned.
|
|
17
|
+
- For released versions, each schema’s `$id` must point to the tagged raw URL to remain immutable.
|
|
18
|
+
- During development on `main`, `$id` may reference `refs/heads/main`, but consumers should pin to tags in production.
|
|
19
|
+
- Keep `$ref` paths relative; they resolve against the `$id` base (the tag) at validation time.
|
|
20
|
+
|
|
21
|
+
Example `$id` pinned to a tag:
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
"$id": "https://raw.githubusercontent.com/carrot-foundation/schemas/refs/tags/v0.1.0/schemas/ipfs/collection/collection.schema.json"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## ✅ Usage
|
|
28
|
+
|
|
29
|
+
You may:
|
|
30
|
+
|
|
31
|
+
- Reference any schema via its `$id` (e.g. in IPFS metadata)
|
|
32
|
+
- Validate metadata files using these schemas
|
|
33
|
+
- Link to them from applications, dashboards, or traceability tools
|
|
34
|
+
|
|
35
|
+
You may not:
|
|
36
|
+
|
|
37
|
+
- Redistribute, rebrand, or fork these schemas for other ecosystems
|
|
38
|
+
- Create derivative schemas that use Carrot's identity
|
|
39
|
+
|
|
40
|
+
See [NOTICE](./NOTICE) for full usage guidance.
|
|
41
|
+
|
|
42
|
+
## 🔐 License
|
|
43
|
+
|
|
44
|
+
Licensed under the [Apache License 2.0](./LICENSE).
|
|
45
|
+
See [NOTICE](./NOTICE) for additional terms and usage intentions.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './mass-id';
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { UuidSchema, WasteTypeSchema, WasteSubtypeSchema, NonEmptyStringSchema, NonNegativeFloatSchema, IsoTimestampSchema, IsoDateSchema, HoursSchema, } from '../shared/definitions.schema.js';
|
|
3
|
+
import { LocationSchema } from '../shared/entities/location.schema.js';
|
|
4
|
+
import { ParticipantSchema } from '../shared/entities/participant.schema.js';
|
|
5
|
+
import { uniqueBy } from '../shared/helpers.schema.js';
|
|
6
|
+
const LocalClassificationSchema = z
|
|
7
|
+
.strictObject({
|
|
8
|
+
code: NonEmptyStringSchema.max(20).meta({
|
|
9
|
+
title: 'Classification Code',
|
|
10
|
+
description: 'Local waste classification code',
|
|
11
|
+
examples: ['20 01 01', 'D001', 'EWC-150101', 'IBAMA-A001'],
|
|
12
|
+
}),
|
|
13
|
+
description: NonEmptyStringSchema.max(200).meta({
|
|
14
|
+
title: 'Classification Description',
|
|
15
|
+
description: 'Local waste classification description',
|
|
16
|
+
examples: [
|
|
17
|
+
'Paper and cardboard packaging',
|
|
18
|
+
'Ignitable waste',
|
|
19
|
+
'Paper and cardboard packaging waste',
|
|
20
|
+
'Municipal solid waste - organic fraction',
|
|
21
|
+
],
|
|
22
|
+
}),
|
|
23
|
+
system: NonEmptyStringSchema.max(50).meta({
|
|
24
|
+
title: 'Classification System',
|
|
25
|
+
description: 'Classification system name (e.g., "Ibama Waste Code", "European Waste Catalogue", "US EPA Codes")',
|
|
26
|
+
examples: [
|
|
27
|
+
'European Waste Catalogue',
|
|
28
|
+
'US EPA Codes',
|
|
29
|
+
'Ibama Waste Code',
|
|
30
|
+
'Brazilian ABNT Classification',
|
|
31
|
+
],
|
|
32
|
+
}),
|
|
33
|
+
})
|
|
34
|
+
.meta({
|
|
35
|
+
title: 'Local Classification',
|
|
36
|
+
description: 'Local or regional waste classification codes and descriptions',
|
|
37
|
+
});
|
|
38
|
+
const MeasurementUnitSchema = z.enum(['kg', 'ton']).meta({
|
|
39
|
+
title: 'Measurement Unit',
|
|
40
|
+
description: 'Unit of measurement for the waste quantity',
|
|
41
|
+
examples: ['kg', 'ton'],
|
|
42
|
+
});
|
|
43
|
+
const ContaminationLevelSchema = z
|
|
44
|
+
.enum(['None', 'Low', 'Medium', 'High'])
|
|
45
|
+
.meta({
|
|
46
|
+
title: 'Contamination Level',
|
|
47
|
+
description: 'Level of contamination in the waste batch',
|
|
48
|
+
examples: ['Low', 'Medium', 'None'],
|
|
49
|
+
});
|
|
50
|
+
const WasteClassificationSchema = z
|
|
51
|
+
.strictObject({
|
|
52
|
+
primary_type: WasteTypeSchema.meta({
|
|
53
|
+
title: 'Primary Waste Type',
|
|
54
|
+
description: 'Primary waste material category',
|
|
55
|
+
}),
|
|
56
|
+
subtype: WasteSubtypeSchema.meta({
|
|
57
|
+
title: 'Waste Subtype',
|
|
58
|
+
description: 'Specific subcategory of waste material',
|
|
59
|
+
}),
|
|
60
|
+
local_classification: LocalClassificationSchema.optional(),
|
|
61
|
+
measurement_unit: MeasurementUnitSchema,
|
|
62
|
+
net_weight: NonNegativeFloatSchema.meta({
|
|
63
|
+
title: 'Net Weight',
|
|
64
|
+
description: 'Net weight of the waste batch in the specified measurement unit',
|
|
65
|
+
}),
|
|
66
|
+
contamination_level: ContaminationLevelSchema.optional(),
|
|
67
|
+
})
|
|
68
|
+
.meta({
|
|
69
|
+
title: 'Waste Classification',
|
|
70
|
+
description: 'Standardized waste material classification and regulatory information',
|
|
71
|
+
});
|
|
72
|
+
const EventAttributeFormatSchema = z
|
|
73
|
+
.enum(['KILOGRAM', 'DATE', 'CURRENCY', 'PERCENTAGE', 'COORDINATE'])
|
|
74
|
+
.meta({
|
|
75
|
+
title: 'Event Attribute Format',
|
|
76
|
+
description: 'Data format hint for proper display',
|
|
77
|
+
examples: ['KILOGRAM', 'DATE', 'PERCENTAGE'],
|
|
78
|
+
});
|
|
79
|
+
const EventAttributeSchema = z
|
|
80
|
+
.strictObject({
|
|
81
|
+
name: NonEmptyStringSchema.max(100).meta({
|
|
82
|
+
title: 'Attribute Name',
|
|
83
|
+
description: 'Event attribute name',
|
|
84
|
+
examples: [
|
|
85
|
+
'temperature',
|
|
86
|
+
'humidity',
|
|
87
|
+
'contamination_percentage',
|
|
88
|
+
'quality_grade',
|
|
89
|
+
'batch_number',
|
|
90
|
+
'operator_id',
|
|
91
|
+
'equipment_used',
|
|
92
|
+
'processing_cost',
|
|
93
|
+
],
|
|
94
|
+
}),
|
|
95
|
+
value: z.union([z.string(), z.number(), z.boolean()]).meta({
|
|
96
|
+
title: 'Attribute Value',
|
|
97
|
+
description: 'Event attribute value',
|
|
98
|
+
examples: [
|
|
99
|
+
25.5,
|
|
100
|
+
'Grade A',
|
|
101
|
+
true,
|
|
102
|
+
'BATCH-2024-001',
|
|
103
|
+
12.75,
|
|
104
|
+
'Shredder-X200',
|
|
105
|
+
false,
|
|
106
|
+
'OP-456',
|
|
107
|
+
],
|
|
108
|
+
}),
|
|
109
|
+
format: EventAttributeFormatSchema.optional(),
|
|
110
|
+
})
|
|
111
|
+
.meta({
|
|
112
|
+
title: 'Event Attribute',
|
|
113
|
+
description: 'Additional attribute specific to an event',
|
|
114
|
+
});
|
|
115
|
+
const EventDocumentSchema = z
|
|
116
|
+
.strictObject({
|
|
117
|
+
type: NonEmptyStringSchema.max(50).meta({
|
|
118
|
+
title: 'Document Type',
|
|
119
|
+
description: 'Type of supporting documentation',
|
|
120
|
+
examples: [
|
|
121
|
+
'Waste Transfer Note',
|
|
122
|
+
'Certificate of Disposal',
|
|
123
|
+
'Certificate of Final Destination',
|
|
124
|
+
'Quality Assessment Report',
|
|
125
|
+
'Transport Manifest',
|
|
126
|
+
'Processing Receipt',
|
|
127
|
+
'Environmental Permit',
|
|
128
|
+
'Invoice',
|
|
129
|
+
],
|
|
130
|
+
}),
|
|
131
|
+
document_number: NonEmptyStringSchema.max(50)
|
|
132
|
+
.optional()
|
|
133
|
+
.meta({
|
|
134
|
+
title: 'Document Number',
|
|
135
|
+
description: 'Official document number if applicable',
|
|
136
|
+
examples: [
|
|
137
|
+
'WTN-2024-001234',
|
|
138
|
+
'CD-ENV-456789',
|
|
139
|
+
'INV-2024-QTR1-789',
|
|
140
|
+
'PERMIT-EPA-2024-001',
|
|
141
|
+
'MANIFEST-DOT-567890',
|
|
142
|
+
],
|
|
143
|
+
}),
|
|
144
|
+
reference: NonEmptyStringSchema.meta({
|
|
145
|
+
title: 'Document Reference',
|
|
146
|
+
description: 'Reference to document (IPFS hash, file name, or external URL)',
|
|
147
|
+
examples: [
|
|
148
|
+
'QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o',
|
|
149
|
+
'waste_transfer_note_2024_001.pdf',
|
|
150
|
+
'https://docs.example.com/certificates/disposal_cert_456.pdf',
|
|
151
|
+
'bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi',
|
|
152
|
+
'processing_receipt_20240315.jpg',
|
|
153
|
+
],
|
|
154
|
+
}),
|
|
155
|
+
issue_date: IsoDateSchema.optional().meta({
|
|
156
|
+
title: 'Issue Date',
|
|
157
|
+
description: 'Date the document was issued',
|
|
158
|
+
}),
|
|
159
|
+
issuer: NonEmptyStringSchema.max(100)
|
|
160
|
+
.optional()
|
|
161
|
+
.meta({
|
|
162
|
+
title: 'Document Issuer',
|
|
163
|
+
description: 'Entity that issued the document',
|
|
164
|
+
examples: [
|
|
165
|
+
'Environmental Protection Agency',
|
|
166
|
+
'Waste Management Solutions Ltd',
|
|
167
|
+
'Green Recycling Corp',
|
|
168
|
+
'City Waste Authority',
|
|
169
|
+
'EcoProcess Industries',
|
|
170
|
+
'Regional Environmental Office',
|
|
171
|
+
],
|
|
172
|
+
}),
|
|
173
|
+
})
|
|
174
|
+
.meta({
|
|
175
|
+
title: 'Event Document',
|
|
176
|
+
description: 'Supporting event document',
|
|
177
|
+
});
|
|
178
|
+
const ChainOfCustodyEventSchema = z
|
|
179
|
+
.strictObject({
|
|
180
|
+
event_id: UuidSchema.meta({
|
|
181
|
+
title: 'Event ID',
|
|
182
|
+
description: 'Unique event identifier',
|
|
183
|
+
}),
|
|
184
|
+
event_name: NonEmptyStringSchema.max(50).meta({
|
|
185
|
+
title: 'Event Name',
|
|
186
|
+
description: 'Name of custody or processing event',
|
|
187
|
+
examples: ['Sorting', 'Processing', 'Recycling', 'Weighing'],
|
|
188
|
+
}),
|
|
189
|
+
description: NonEmptyStringSchema.max(200).meta({
|
|
190
|
+
title: 'Event Description',
|
|
191
|
+
description: 'Detailed description of what happened during this event',
|
|
192
|
+
examples: [
|
|
193
|
+
'Waste collected from residential area using collection truck',
|
|
194
|
+
'Material sorted into recyclable and non-recyclable fractions',
|
|
195
|
+
'Plastic waste processed through shredding and washing',
|
|
196
|
+
'Waste transferred to authorized recycling facility',
|
|
197
|
+
'Final disposal at licensed landfill site',
|
|
198
|
+
'Quality inspection and contamination assessment completed',
|
|
199
|
+
],
|
|
200
|
+
}),
|
|
201
|
+
timestamp: IsoTimestampSchema.meta({
|
|
202
|
+
title: 'Event Timestamp',
|
|
203
|
+
description: 'ISO 8601 timestamp when the event occurred',
|
|
204
|
+
}),
|
|
205
|
+
participant_id: UuidSchema.meta({
|
|
206
|
+
title: 'Participant ID',
|
|
207
|
+
description: 'Reference to participant in the participants array',
|
|
208
|
+
}),
|
|
209
|
+
location_id: UuidSchema.meta({
|
|
210
|
+
title: 'Location ID',
|
|
211
|
+
description: 'Reference to location in the locations array',
|
|
212
|
+
}),
|
|
213
|
+
weight: NonNegativeFloatSchema.optional().meta({
|
|
214
|
+
title: 'Event Weight',
|
|
215
|
+
description: 'Mass weight after this event',
|
|
216
|
+
}),
|
|
217
|
+
attributes: z.array(EventAttributeSchema).optional().meta({
|
|
218
|
+
title: 'Event Attributes',
|
|
219
|
+
description: 'Additional attributes specific to this event',
|
|
220
|
+
}),
|
|
221
|
+
documentation: z.array(EventDocumentSchema).optional().meta({
|
|
222
|
+
title: 'Event Documentation',
|
|
223
|
+
description: 'Associated documentation for this event',
|
|
224
|
+
}),
|
|
225
|
+
notes: NonEmptyStringSchema.max(500).optional().meta({
|
|
226
|
+
title: 'Event Notes',
|
|
227
|
+
description: 'Additional notes or comments about this event',
|
|
228
|
+
}),
|
|
229
|
+
})
|
|
230
|
+
.meta({
|
|
231
|
+
title: 'Chain of Custody Event',
|
|
232
|
+
description: 'Chain of custody event',
|
|
233
|
+
});
|
|
234
|
+
const ChainOfCustodySchema = z
|
|
235
|
+
.strictObject({
|
|
236
|
+
events: z.array(ChainOfCustodyEventSchema).min(1).meta({
|
|
237
|
+
title: 'Custody Events',
|
|
238
|
+
description: 'Chronological sequence of custody transfer and processing events',
|
|
239
|
+
}),
|
|
240
|
+
total_distance_km: NonNegativeFloatSchema.meta({
|
|
241
|
+
title: 'Total Distance (km)',
|
|
242
|
+
description: 'Total distance traveled across all transport events',
|
|
243
|
+
}),
|
|
244
|
+
total_duration_hours: HoursSchema.meta({
|
|
245
|
+
title: 'Total Duration (hours)',
|
|
246
|
+
description: 'Total time from first to last event in hours',
|
|
247
|
+
}),
|
|
248
|
+
})
|
|
249
|
+
.meta({
|
|
250
|
+
title: 'Chain of Custody',
|
|
251
|
+
description: 'Complete chain of custody tracking from waste generation to final processing',
|
|
252
|
+
});
|
|
253
|
+
const TransportRouteSchema = z
|
|
254
|
+
.strictObject({
|
|
255
|
+
from_location_id: UuidSchema.meta({
|
|
256
|
+
title: 'From Location ID',
|
|
257
|
+
description: 'Reference to the origin location in the locations array',
|
|
258
|
+
}),
|
|
259
|
+
to_location_id: UuidSchema.meta({
|
|
260
|
+
title: 'To Location ID',
|
|
261
|
+
description: 'Reference to the destination location in the locations array',
|
|
262
|
+
}),
|
|
263
|
+
distance_km: NonNegativeFloatSchema.meta({
|
|
264
|
+
title: 'Distance (km)',
|
|
265
|
+
description: 'Distance for this route segment in kilometers',
|
|
266
|
+
}),
|
|
267
|
+
transport_method: NonEmptyStringSchema.max(50).meta({
|
|
268
|
+
title: 'Transport Method',
|
|
269
|
+
description: 'Method of transportation for this segment',
|
|
270
|
+
examples: [
|
|
271
|
+
'Truck',
|
|
272
|
+
'Rail',
|
|
273
|
+
'Barge',
|
|
274
|
+
'Container Ship',
|
|
275
|
+
'Conveyor Belt',
|
|
276
|
+
'Pipeline',
|
|
277
|
+
'Walking',
|
|
278
|
+
'Forklift',
|
|
279
|
+
],
|
|
280
|
+
}),
|
|
281
|
+
duration_hours: HoursSchema.meta({
|
|
282
|
+
title: 'Duration (hours)',
|
|
283
|
+
description: 'Time taken for this route segment in hours',
|
|
284
|
+
}),
|
|
285
|
+
})
|
|
286
|
+
.meta({
|
|
287
|
+
title: 'Transport Route',
|
|
288
|
+
description: 'Transport route segment information',
|
|
289
|
+
});
|
|
290
|
+
const GeographicDataSchema = z
|
|
291
|
+
.strictObject({
|
|
292
|
+
origin_location_id: UuidSchema.meta({
|
|
293
|
+
title: 'Origin Location ID',
|
|
294
|
+
description: 'Reference to origin location in the locations array',
|
|
295
|
+
}),
|
|
296
|
+
processing_location_ids: z.array(UuidSchema).optional().meta({
|
|
297
|
+
title: 'Processing Location IDs',
|
|
298
|
+
description: 'Locations where the waste was processed or handled',
|
|
299
|
+
}),
|
|
300
|
+
final_destination_id: UuidSchema.meta({
|
|
301
|
+
title: 'Final Destination ID',
|
|
302
|
+
description: 'Reference to final destination in the locations array',
|
|
303
|
+
}),
|
|
304
|
+
transport_routes: z.array(TransportRouteSchema).meta({
|
|
305
|
+
title: 'Transport Routes',
|
|
306
|
+
description: 'Detailed transport route information',
|
|
307
|
+
}),
|
|
308
|
+
})
|
|
309
|
+
.meta({
|
|
310
|
+
title: 'Geographic Data',
|
|
311
|
+
description: 'Geographic information about waste origin and processing locations',
|
|
312
|
+
});
|
|
313
|
+
export const MassIDDataSchema = z
|
|
314
|
+
.strictObject({
|
|
315
|
+
waste_classification: WasteClassificationSchema,
|
|
316
|
+
locations: uniqueBy(LocationSchema, (loc) => loc.id, 'Location IDs must be unique')
|
|
317
|
+
.min(1)
|
|
318
|
+
.meta({
|
|
319
|
+
title: 'Locations',
|
|
320
|
+
description: 'All locations referenced in this MassID, indexed by ID',
|
|
321
|
+
}),
|
|
322
|
+
participants: uniqueBy(ParticipantSchema, (p) => p.id, 'Participant IDs must be unique')
|
|
323
|
+
.min(1)
|
|
324
|
+
.meta({
|
|
325
|
+
title: 'Participants',
|
|
326
|
+
description: 'All participants referenced in this MassID, indexed by ID',
|
|
327
|
+
}),
|
|
328
|
+
chain_of_custody: ChainOfCustodySchema,
|
|
329
|
+
geographic_data: GeographicDataSchema,
|
|
330
|
+
})
|
|
331
|
+
.refine((data) => {
|
|
332
|
+
const participantIdSet = new Set(data.participants.map((participant) => participant.id));
|
|
333
|
+
const eventParticipantIds = data.chain_of_custody.events.map((event) => event.participant_id);
|
|
334
|
+
const allEventParticipantsExist = eventParticipantIds.every((participantId) => participantIdSet.has(participantId));
|
|
335
|
+
return allEventParticipantsExist;
|
|
336
|
+
}, 'All participant IDs in chain of custody events must exist in participants array')
|
|
337
|
+
.refine((data) => {
|
|
338
|
+
const locationIdSet = new Set(data.locations.map((location) => location.id));
|
|
339
|
+
const eventLocationIds = data.chain_of_custody.events.map((event) => event.location_id);
|
|
340
|
+
const allEventLocationsExist = eventLocationIds.every((locationId) => locationIdSet.has(locationId));
|
|
341
|
+
return allEventLocationsExist;
|
|
342
|
+
}, 'All location IDs in chain of custody events must exist in locations array')
|
|
343
|
+
.meta({
|
|
344
|
+
title: 'MassID Data',
|
|
345
|
+
description: 'MassID data containing waste tracking and chain of custody information',
|
|
346
|
+
});
|