@carrot-foundation/schemas 0.1.53 → 0.1.55

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 (26) hide show
  1. package/dist/index.cjs +193 -77
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +245 -512
  4. package/dist/index.d.ts +245 -512
  5. package/dist/index.js +193 -78
  6. package/dist/index.js.map +1 -1
  7. package/package.json +1 -1
  8. package/schemas/ipfs/collection/collection.example.json +5 -5
  9. package/schemas/ipfs/collection/collection.schema.json +2 -2
  10. package/schemas/ipfs/credit/credit.example.json +5 -5
  11. package/schemas/ipfs/credit/credit.schema.json +2 -2
  12. package/schemas/ipfs/credit-purchase-receipt/credit-purchase-receipt.example.json +5 -5
  13. package/schemas/ipfs/credit-purchase-receipt/credit-purchase-receipt.schema.json +56 -56
  14. package/schemas/ipfs/credit-retirement-receipt/credit-retirement-receipt.example.json +4 -4
  15. package/schemas/ipfs/credit-retirement-receipt/credit-retirement-receipt.schema.json +87 -87
  16. package/schemas/ipfs/gas-id/gas-id.example.json +6 -6
  17. package/schemas/ipfs/gas-id/gas-id.schema.json +495 -63
  18. package/schemas/ipfs/mass-id/mass-id.example.json +5 -5
  19. package/schemas/ipfs/mass-id/mass-id.schema.json +96 -96
  20. package/schemas/ipfs/mass-id-audit/mass-id-audit.example.json +5 -5
  21. package/schemas/ipfs/mass-id-audit/mass-id-audit.schema.json +2 -2
  22. package/schemas/ipfs/methodology/methodology.example.json +5 -5
  23. package/schemas/ipfs/methodology/methodology.schema.json +2 -2
  24. package/schemas/ipfs/recycled-id/recycled-id.example.json +5 -5
  25. package/schemas/ipfs/recycled-id/recycled-id.schema.json +438 -56
  26. package/schemas/schema-hashes.json +10 -10
package/dist/index.cjs CHANGED
@@ -28632,6 +28632,29 @@ function mergeSchemaMeta(schema, newMeta) {
28632
28632
  }
28633
28633
  return merged;
28634
28634
  }
28635
+ function extractTraitType(schema) {
28636
+ try {
28637
+ if (typeof schema === "object" && schema !== null && "shape" in schema && typeof schema.shape === "object" && schema.shape !== null && "trait_type" in schema.shape) {
28638
+ const traitTypeSchema = schema.shape.trait_type;
28639
+ const literalSchema = traitTypeSchema;
28640
+ if (literalSchema.value !== void 0 && typeof literalSchema.value === "string") {
28641
+ return literalSchema.value;
28642
+ }
28643
+ }
28644
+ const meta = getSchemaMetadata(schema);
28645
+ if (meta?.title) {
28646
+ const title = meta.title;
28647
+ if (title.endsWith(" Attribute")) {
28648
+ const inferred = title.slice(0, -11);
28649
+ if (inferred.length > 3) {
28650
+ return inferred;
28651
+ }
28652
+ }
28653
+ }
28654
+ } catch {
28655
+ }
28656
+ return "";
28657
+ }
28635
28658
  function createDateAttributeSchema(params) {
28636
28659
  const { omitMaxValue = true } = params;
28637
28660
  const base = omitMaxValue ? NftAttributeSchema.omit({ max_value: true }) : NftAttributeSchema;
@@ -28682,6 +28705,71 @@ function createNumericAttributeSchema(params) {
28682
28705
  description: `${params.description} attribute with numeric display`
28683
28706
  });
28684
28707
  }
28708
+ function createOrderedAttributesSchema(params) {
28709
+ const {
28710
+ required,
28711
+ optional = [],
28712
+ title,
28713
+ description,
28714
+ uniqueBySelector,
28715
+ maxItems,
28716
+ requiredTraitTypes,
28717
+ optionalTraitTypes
28718
+ } = params;
28719
+ const allSchemas = [...required, ...optional];
28720
+ let unionSchema;
28721
+ if (allSchemas.length === 0) {
28722
+ unionSchema = zod.z.never();
28723
+ } else if (allSchemas.length === 1) {
28724
+ unionSchema = allSchemas[0];
28725
+ } else {
28726
+ unionSchema = zod.z.union(
28727
+ allSchemas
28728
+ );
28729
+ }
28730
+ const requiredTypes = requiredTraitTypes ?? required.map(extractTraitType).filter(Boolean);
28731
+ const optionalTypes = optionalTraitTypes ?? optional.map(extractTraitType).filter(Boolean);
28732
+ const isDynamic = description.includes("Dynamic attributes");
28733
+ const descriptionParts = [description];
28734
+ if (requiredTypes.length > 0) {
28735
+ descriptionParts.push(
28736
+ `
28737
+
28738
+ Required attributes (${required.length}): ${requiredTypes.join(", ")}`
28739
+ );
28740
+ }
28741
+ if (optionalTypes.length > 0 && !isDynamic) {
28742
+ descriptionParts.push(
28743
+ `
28744
+ Optional attributes (${optional.length}): ${optionalTypes.join(", ")}`
28745
+ );
28746
+ }
28747
+ let arraySchema = uniqueBy(unionSchema, uniqueBySelector).min(
28748
+ required.length
28749
+ );
28750
+ if (maxItems !== void 0) {
28751
+ arraySchema = arraySchema.max(maxItems);
28752
+ } else if (optional.length > 0 && !isDynamic) {
28753
+ arraySchema = arraySchema.max(required.length + optional.length);
28754
+ }
28755
+ return arraySchema.superRefine((attributes, ctx) => {
28756
+ const traitTypes = new Set(
28757
+ attributes.map(uniqueBySelector)
28758
+ );
28759
+ for (const traitType of requiredTypes) {
28760
+ if (traitType && !traitTypes.has(traitType)) {
28761
+ ctx.addIssue({
28762
+ code: "custom",
28763
+ message: `Required attribute '${traitType}' is missing`,
28764
+ path: []
28765
+ });
28766
+ }
28767
+ }
28768
+ }).meta({
28769
+ title,
28770
+ description: descriptionParts.join("")
28771
+ });
28772
+ }
28685
28773
  var MethodologyAttributeSchema = NftAttributeSchema.safeExtend({
28686
28774
  trait_type: zod.z.literal("Methodology"),
28687
28775
  value: MethodologyNameSchema
@@ -29357,7 +29445,7 @@ function buildSchemaUrl(schemaPath) {
29357
29445
  return `${getSchemaBaseUrl()}/${cleanPath}`;
29358
29446
  }
29359
29447
  function getSchemaVersionOrDefault() {
29360
- return "0.1.53";
29448
+ return "0.1.55";
29361
29449
  }
29362
29450
 
29363
29451
  // src/shared/schema-validation.ts
@@ -29628,27 +29716,48 @@ var MassIDAttributeRecyclingDateSchema = createDateAttributeSchema({
29628
29716
  title: "Recycling Date",
29629
29717
  description: "Unix timestamp in milliseconds when the waste was recycled/processed"
29630
29718
  });
29631
- var MassIDAttributesSchema = uniqueBy(
29632
- zod.z.union([
29633
- MassIDAttributeWasteTypeSchema,
29634
- MassIDAttributeWasteSubtypeSchema,
29635
- MassIDAttributeWeightSchema,
29636
- MassIDAttributeOriginCitySchema,
29637
- MassIDAttributePickUpVehicleTypeSchema,
29638
- MassIDAttributeRecyclingMethodSchema,
29639
- MassIDAttributeLocalWasteClassificationIdSchema,
29640
- MassIDAttributeRecyclingManifestCodeSchema,
29641
- MassIDAttributeTransportManifestCodeSchema,
29642
- MassIDAttributeWeighingCaptureMethodSchema,
29643
- MassIDAttributeScaleTypeSchema,
29644
- MassIDAttributePickUpDateSchema,
29645
- MassIDAttributeDropOffDateSchema,
29646
- MassIDAttributeRecyclingDateSchema
29647
- ]),
29648
- (attr) => attr.trait_type
29649
- ).min(9).max(14).meta({
29719
+ var REQUIRED_MASS_ID_ATTRIBUTES = [
29720
+ MassIDAttributeWasteTypeSchema,
29721
+ MassIDAttributeWasteSubtypeSchema,
29722
+ MassIDAttributeWeightSchema,
29723
+ MassIDAttributeOriginCitySchema,
29724
+ MassIDAttributePickUpVehicleTypeSchema,
29725
+ MassIDAttributeRecyclingMethodSchema,
29726
+ MassIDAttributePickUpDateSchema,
29727
+ MassIDAttributeDropOffDateSchema,
29728
+ MassIDAttributeRecyclingDateSchema
29729
+ ];
29730
+ var OPTIONAL_MASS_ID_ATTRIBUTES = [
29731
+ MassIDAttributeLocalWasteClassificationIdSchema,
29732
+ MassIDAttributeRecyclingManifestCodeSchema,
29733
+ MassIDAttributeTransportManifestCodeSchema,
29734
+ MassIDAttributeWeighingCaptureMethodSchema,
29735
+ MassIDAttributeScaleTypeSchema
29736
+ ];
29737
+ var MassIDAttributesSchema = createOrderedAttributesSchema({
29738
+ required: REQUIRED_MASS_ID_ATTRIBUTES,
29739
+ optional: OPTIONAL_MASS_ID_ATTRIBUTES,
29650
29740
  title: "MassID Attributes",
29651
- description: "Array of NFT attributes describing waste characteristics, origin, logistics, and lifecycle events."
29741
+ description: "Array of NFT attributes describing waste characteristics, origin, logistics, and lifecycle events.",
29742
+ uniqueBySelector: (attr) => attr.trait_type,
29743
+ requiredTraitTypes: [
29744
+ "Waste Type",
29745
+ "Waste Subtype",
29746
+ "Weight (kg)",
29747
+ "Origin City",
29748
+ "Pick-up Vehicle Type",
29749
+ "Recycling Method",
29750
+ "Pick-up Date",
29751
+ "Drop-off Date",
29752
+ "Recycling Date"
29753
+ ],
29754
+ optionalTraitTypes: [
29755
+ "Local Waste Classification ID",
29756
+ "Recycling Manifest Number",
29757
+ "Transport Manifest Number",
29758
+ "Weighing Capture Method",
29759
+ "Scale Type"
29760
+ ]
29652
29761
  });
29653
29762
  var MassIDLocalClassificationSchema = zod.z.strictObject({
29654
29763
  code: IbamaWasteClassificationSchema,
@@ -30082,7 +30191,7 @@ var GasIDAttributesSchema = zod.z.tuple([
30082
30191
  GasIDAttributeCertificateIssuanceDateSchema
30083
30192
  ]).meta({
30084
30193
  title: "GasID NFT Attribute Array",
30085
- description: "Schema for the fixed set of GasID NFT attributes, enforcing order and type for each trait"
30194
+ description: "Schema for the fixed set of GasID NFT attributes, enforcing order and type for each trait.\n\nRequired attributes (11, in order): Methodology, Gas Type, CO\u2082e Prevented (kg), Credit Amount, Credit Type, Source Waste Type, Source Weight (kg), Origin City, MassID, MassID Recycling Date, Certificate Issuance Date."
30086
30195
  });
30087
30196
  var GasIDSummarySchema = zod.z.strictObject({
30088
30197
  gas_type: GasTypeSchema,
@@ -30135,9 +30244,9 @@ var PreventedEmissionsCalculationSchema = zod.z.strictObject({
30135
30244
  description: "Method used to calculate the prevented emissions",
30136
30245
  examples: ["UNFCCC AMS-III.F"]
30137
30246
  }),
30138
- date: IsoDateSchema.meta({
30139
- title: "Calculation Date",
30140
- description: "Date when the calculation was performed"
30247
+ calculated_at: IsoDateTimeSchema.meta({
30248
+ title: "Calculated At",
30249
+ description: "ISO 8601 timestamp when the calculation was performed"
30141
30250
  }),
30142
30251
  values: zod.z.array(CalculationValueSchema).min(1).meta({
30143
30252
  title: "Calculation Values",
@@ -30176,17 +30285,8 @@ var GasIDIpfsSchema = NftIpfsSchema.safeExtend({
30176
30285
  description: "GasID NFT schema type"
30177
30286
  })
30178
30287
  }),
30288
+ attributes: GasIDAttributesSchema,
30179
30289
  data: GasIDDataSchema
30180
- }).superRefine((value, ctx) => {
30181
- const attributesResult = GasIDAttributesSchema.safeParse(value.attributes);
30182
- if (!attributesResult.success) {
30183
- attributesResult.error.issues.forEach((issue) => {
30184
- ctx.addIssue({
30185
- ...issue,
30186
- path: ["attributes", ...issue.path]
30187
- });
30188
- });
30189
- }
30190
30290
  }).meta(GasIDIpfsSchemaMeta);
30191
30291
  var RecycledIDAttributeMethodologySchema = MethodologyAttributeSchema;
30192
30292
  var RecycledIDAttributeRecycledMassWeightSchema = createWeightAttributeSchema(
@@ -30217,7 +30317,7 @@ var RecycledIDAttributesSchema = zod.z.tuple([
30217
30317
  RecycledIDAttributeCertificateIssuanceDateSchema
30218
30318
  ]).meta({
30219
30319
  title: "RecycledID NFT Attribute Array",
30220
- description: "Schema for the fixed set of RecycledID NFT attributes, enforcing order and type for each trait"
30320
+ description: "Schema for the fixed set of RecycledID NFT attributes, enforcing order and type for each trait.\n\nRequired attributes (10, in order): Methodology, Recycled Mass Weight (kg), Credit Amount, Credit Type, Source Waste Type, Source Weight (kg), Origin City, MassID, MassID Recycling Date, Certificate Issuance Date."
30221
30321
  });
30222
30322
  var RecycledIDSummarySchema = zod.z.strictObject({
30223
30323
  recycled_mass_kg: WeightKgSchema.meta({
@@ -30262,19 +30362,8 @@ var RecycledIDIpfsSchema = NftIpfsSchema.safeExtend({
30262
30362
  description: "RecycledID NFT schema type"
30263
30363
  })
30264
30364
  }),
30365
+ attributes: RecycledIDAttributesSchema,
30265
30366
  data: RecycledIDDataSchema
30266
- }).superRefine((value, ctx) => {
30267
- const attributesResult = RecycledIDAttributesSchema.safeParse(
30268
- value.attributes
30269
- );
30270
- if (!attributesResult.success) {
30271
- attributesResult.error.issues.forEach((issue) => {
30272
- ctx.addIssue({
30273
- ...issue,
30274
- path: ["attributes", ...issue.path]
30275
- });
30276
- });
30277
- }
30278
30367
  }).meta(RecycledIDIpfsSchemaMeta);
30279
30368
  var CreditPurchaseReceiptCreditAttributeSchema = NftAttributeSchema.safeExtend({
30280
30369
  trait_type: CreditTokenSymbolSchema,
@@ -30335,21 +30424,34 @@ var CreditPurchaseReceiptCollectionAttributeSchema = NftAttributeSchema.safeExte
30335
30424
  title: "Collection Attribute",
30336
30425
  description: "Attribute representing the amount of credits purchased from a collection"
30337
30426
  });
30338
- var CreditPurchaseReceiptAttributesSchema = uniqueBy(
30339
- zod.z.union([
30340
- CreditPurchaseReceiptCreditAttributeSchema,
30341
- CreditPurchaseReceiptTotalCreditsAttributeSchema,
30342
- CreditPurchaseReceiptTotalUsdcAttributeSchema,
30343
- CreditPurchaseReceiptPurchaseDateAttributeSchema,
30344
- CreditPurchaseReceiptCertificatesAttributeSchema,
30345
- CreditPurchaseReceiptReceiverAttributeSchema,
30346
- CreditPurchaseReceiptCollectionAttributeSchema
30347
- ]),
30348
- (attribute) => attribute.trait_type,
30349
- "Attribute trait_type values must be unique"
30350
- ).min(5).meta({
30427
+ var REQUIRED_CREDIT_PURCHASE_RECEIPT_ATTRIBUTES = [
30428
+ CreditPurchaseReceiptTotalCreditsAttributeSchema,
30429
+ CreditPurchaseReceiptTotalUsdcAttributeSchema,
30430
+ CreditPurchaseReceiptPurchaseDateAttributeSchema,
30431
+ CreditPurchaseReceiptCertificatesAttributeSchema
30432
+ ];
30433
+ var CONDITIONAL_CREDIT_PURCHASE_RECEIPT_ATTRIBUTES = [
30434
+ CreditPurchaseReceiptReceiverAttributeSchema
30435
+ ];
30436
+ var DYNAMIC_CREDIT_PURCHASE_RECEIPT_ATTRIBUTES = [
30437
+ CreditPurchaseReceiptCreditAttributeSchema,
30438
+ CreditPurchaseReceiptCollectionAttributeSchema
30439
+ ];
30440
+ var CreditPurchaseReceiptAttributesSchema = createOrderedAttributesSchema({
30441
+ required: REQUIRED_CREDIT_PURCHASE_RECEIPT_ATTRIBUTES,
30442
+ optional: [
30443
+ ...CONDITIONAL_CREDIT_PURCHASE_RECEIPT_ATTRIBUTES,
30444
+ ...DYNAMIC_CREDIT_PURCHASE_RECEIPT_ATTRIBUTES
30445
+ ],
30351
30446
  title: "Credit Purchase Receipt NFT Attribute Array",
30352
- description: "Attributes for credit purchase receipts including per-credit breakdowns, totals, receiver, purchase date, and per-collection amounts. Attributes must have unique trait types."
30447
+ description: "Attributes for credit purchase receipts including per-credit breakdowns, totals, receiver, purchase date, and per-collection amounts. Fixed required attributes: Total Credits Purchased, Total USDC Amount, Purchase Date, Certificates Purchased. Conditional attributes: Receiver (required when receiver.identity.name is provided). Dynamic attributes: Credit attributes (one per credit symbol in data.credits), Collection attributes (one per collection name in data.collections).",
30448
+ uniqueBySelector: (attribute) => attribute.trait_type,
30449
+ requiredTraitTypes: [
30450
+ "Total Credits Purchased",
30451
+ "Total USDC Amount",
30452
+ "Purchase Date",
30453
+ "Certificates Purchased"
30454
+ ]
30353
30455
  });
30354
30456
  var CreditPurchaseReceiptIdentitySchema = ReceiptIdentitySchema;
30355
30457
  var CreditPurchaseReceiptReceiverSchema = zod.z.strictObject({
@@ -30860,21 +30962,34 @@ var CreditRetirementReceiptCollectionAttributeSchema = NftAttributeSchema.safeEx
30860
30962
  title: "Collection Attribute",
30861
30963
  description: "Attribute representing the amount of credits retired from a collection"
30862
30964
  });
30863
- var CreditRetirementReceiptAttributesSchema = uniqueBy(
30864
- zod.z.union([
30865
- CreditRetirementReceiptCreditAttributeSchema,
30866
- CreditRetirementReceiptTotalCreditsAttributeSchema,
30867
- CreditRetirementReceiptBeneficiaryAttributeSchema,
30868
- CreditRetirementReceiptCreditHolderAttributeSchema,
30869
- CreditRetirementReceiptRetirementDateAttributeSchema,
30870
- CreditRetirementReceiptCertificatesAttributeSchema,
30871
- CreditRetirementReceiptCollectionAttributeSchema
30872
- ]),
30873
- (attribute) => attribute.trait_type,
30874
- "Attribute trait_type values must be unique"
30875
- ).min(6).meta({
30965
+ var REQUIRED_CREDIT_RETIREMENT_RECEIPT_ATTRIBUTES = [
30966
+ CreditRetirementReceiptTotalCreditsAttributeSchema,
30967
+ CreditRetirementReceiptBeneficiaryAttributeSchema,
30968
+ CreditRetirementReceiptRetirementDateAttributeSchema,
30969
+ CreditRetirementReceiptCertificatesAttributeSchema
30970
+ ];
30971
+ var CONDITIONAL_CREDIT_RETIREMENT_RECEIPT_ATTRIBUTES = [
30972
+ CreditRetirementReceiptCreditHolderAttributeSchema
30973
+ ];
30974
+ var DYNAMIC_CREDIT_RETIREMENT_RECEIPT_ATTRIBUTES = [
30975
+ CreditRetirementReceiptCreditAttributeSchema,
30976
+ CreditRetirementReceiptCollectionAttributeSchema
30977
+ ];
30978
+ var CreditRetirementReceiptAttributesSchema = createOrderedAttributesSchema({
30979
+ required: REQUIRED_CREDIT_RETIREMENT_RECEIPT_ATTRIBUTES,
30980
+ optional: [
30981
+ ...CONDITIONAL_CREDIT_RETIREMENT_RECEIPT_ATTRIBUTES,
30982
+ ...DYNAMIC_CREDIT_RETIREMENT_RECEIPT_ATTRIBUTES
30983
+ ],
30876
30984
  title: "Credit Retirement Receipt NFT Attribute Array",
30877
- description: "Attributes for credit retirement receipts including per-credit breakdowns, totals, beneficiary, credit holder, retirement date, certificate count, and per-collection amounts. Attributes must have unique trait types."
30985
+ description: "Attributes for credit retirement receipts including per-credit breakdowns, totals, beneficiary, credit holder, retirement date, certificate count, and per-collection amounts. Fixed required attributes: Total Credits Retired, Beneficiary, Retirement Date, Certificates Retired. Conditional attributes: Credit Holder (required when credit_holder.identity.name is provided). Dynamic attributes: Credit attributes (one per credit symbol in data.credits), Collection attributes (one per collection name in data.collections).",
30986
+ uniqueBySelector: (attribute) => attribute.trait_type,
30987
+ requiredTraitTypes: [
30988
+ "Total Credits Retired",
30989
+ "Beneficiary",
30990
+ "Retirement Date",
30991
+ "Certificates Retired"
30992
+ ]
30878
30993
  });
30879
30994
  var CreditRetirementReceiptIdentitySchema = ReceiptIdentitySchema;
30880
30995
  var CreditRetirementReceiptBeneficiarySchema = zod.z.strictObject({
@@ -31473,7 +31588,7 @@ var MassIDAuditSchema = BaseIpfsSchema.safeExtend({
31473
31588
  }),
31474
31589
  data: MassIDAuditDataSchema
31475
31590
  }).meta(MassIDAuditSchemaMeta);
31476
- /* v8 ignore next -- @preserve */
31591
+ /* v8 ignore file -- @preserve */
31477
31592
 
31478
31593
  exports.ALLOWED_BLOCKCHAIN_NETWORKS = ALLOWED_BLOCKCHAIN_NETWORKS;
31479
31594
  exports.AuditReferenceSchema = AuditReferenceSchema;
@@ -31607,6 +31722,7 @@ exports.canonicalizeForHash = canonicalizeForHash;
31607
31722
  exports.createAttributeMap = createAttributeMap;
31608
31723
  exports.createDateAttributeSchema = createDateAttributeSchema;
31609
31724
  exports.createNumericAttributeSchema = createNumericAttributeSchema;
31725
+ exports.createOrderedAttributesSchema = createOrderedAttributesSchema;
31610
31726
  exports.createReceiptCertificateSchema = createReceiptCertificateSchema;
31611
31727
  exports.createReceiptCollectionSchema = createReceiptCollectionSchema;
31612
31728
  exports.createReceiptCreditSchema = createReceiptCreditSchema;