@hypercerts-org/sdk-core 0.8.0-beta.0 → 0.9.0-beta.0

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/README.md CHANGED
@@ -33,11 +33,15 @@ const session = await sdk.callback(callbackParams);
33
33
  const repo = sdk.getRepository(session);
34
34
  const claim = await repo.hypercerts.create({
35
35
  title: "Tree Planting Initiative 2025",
36
- description: "Planted 1000 trees in the rainforest",
37
- impact: {
38
- scope: ["Environmental Conservation"],
39
- work: { from: "2025-01-01", to: "2025-12-31" },
40
- contributors: ["did:plc:contributor1"],
36
+ shortDescription: "1000 trees planted in rainforest",
37
+ description: "Planted 1000 trees in the Amazon rainforest region",
38
+ workScope: "Environmental Conservation",
39
+ workTimeFrameFrom: "2025-01-01T00:00:00Z",
40
+ workTimeFrameTo: "2025-12-31T23:59:59Z",
41
+ rights: {
42
+ name: "Attribution",
43
+ type: "license",
44
+ description: "CC-BY-4.0",
41
45
  },
42
46
  });
43
47
  ```
@@ -607,21 +611,134 @@ await mockStore.set(mockSession);
607
611
 
608
612
  ### Working with Lexicons
609
613
 
614
+ The SDK exports lexicon types and validation utilities from the `@hypercerts-org/lexicon` package for direct record manipulation and validation.
615
+
616
+ #### Lexicon Types
617
+
618
+ All lexicon types are available with proper TypeScript support:
619
+
620
+ ```typescript
621
+ import type {
622
+ HypercertClaim,
623
+ HypercertRights,
624
+ HypercertContribution,
625
+ HypercertCollection,
626
+ HypercertMeasurement,
627
+ HypercertEvaluation,
628
+ HypercertLocation,
629
+ StrongRef,
630
+ } from "@hypercerts-org/sdk-core";
631
+
632
+ // Create a properly typed hypercert claim
633
+ const claim: HypercertClaim = {
634
+ $type: "org.hypercerts.claim",
635
+ title: "Community Garden Project",
636
+ shortDescription: "Urban garden serving 50 families", // REQUIRED
637
+ description: "Detailed description...",
638
+ workScope: "Food Security",
639
+ workTimeFrameFrom: "2024-01-01T00:00:00Z", // Note: Capital 'F'
640
+ workTimeFrameTo: "2024-12-31T00:00:00Z", // Note: Capital 'F'
641
+ rights: { uri: "at://...", cid: "..." },
642
+ createdAt: new Date().toISOString(),
643
+ };
644
+ ```
645
+
646
+ #### Validation
647
+
648
+ Validate records before creating them:
649
+
650
+ ```typescript
651
+ import {
652
+ validate,
653
+ OrgHypercertsClaim,
654
+ HYPERCERT_COLLECTIONS,
655
+ } from "@hypercerts-org/sdk-core";
656
+
657
+ // Validate using the lexicon package
658
+ const validation = validate(
659
+ HYPERCERT_COLLECTIONS.CLAIM, // "org.hypercerts.claim"
660
+ claim
661
+ );
662
+
663
+ if (!validation.valid) {
664
+ console.error("Validation failed:", validation.error);
665
+ }
666
+
667
+ // Or use type-specific validators
668
+ const isValid = OrgHypercertsClaim.isMain(claim);
669
+ const validationResult = OrgHypercertsClaim.validateMain(claim);
670
+ ```
671
+
672
+ #### Using LexiconRegistry
673
+
674
+ For repository-level validation:
675
+
610
676
  ```typescript
611
677
  import {
612
678
  LexiconRegistry,
613
679
  HYPERCERT_LEXICONS,
614
680
  HYPERCERT_COLLECTIONS,
615
- } from "@hypercerts-org/sdk-core/lexicons";
681
+ } from "@hypercerts-org/sdk-core";
616
682
 
617
683
  const registry = new LexiconRegistry();
618
684
  registry.registerLexicons(HYPERCERT_LEXICONS);
619
685
 
620
686
  // Validate a record
621
- const isValid = registry.validate(
622
- "org.hypercerts.claim",
687
+ const result = registry.validate(
688
+ HYPERCERT_COLLECTIONS.CLAIM,
623
689
  claimData
624
690
  );
691
+
692
+ if (!result.valid) {
693
+ console.error("Invalid record:", result.error);
694
+ }
695
+ ```
696
+
697
+ #### Creating Records with Proper Types
698
+
699
+ ```typescript
700
+ import type {
701
+ HypercertContribution,
702
+ StrongRef,
703
+ } from "@hypercerts-org/sdk-core";
704
+ import { HYPERCERT_COLLECTIONS } from "@hypercerts-org/sdk-core";
705
+
706
+ // Create a contribution record
707
+ const contribution: HypercertContribution = {
708
+ $type: HYPERCERT_COLLECTIONS.CONTRIBUTION,
709
+ hypercert: {
710
+ uri: "at://did:plc:abc/org.hypercerts.claim/xyz",
711
+ cid: "bafyrei...",
712
+ } as StrongRef,
713
+ contributors: ["did:plc:contributor1", "did:plc:contributor2"],
714
+ role: "implementer",
715
+ description: "On-ground implementation team",
716
+ workTimeframeFrom: "2024-01-01T00:00:00Z", // Note: lowercase 'f' for contributions
717
+ workTimeframeTo: "2024-06-30T00:00:00Z", // Note: lowercase 'f' for contributions
718
+ createdAt: new Date().toISOString(),
719
+ };
720
+
721
+ // Use with repository operations
722
+ await repo.records.create({
723
+ collection: HYPERCERT_COLLECTIONS.CONTRIBUTION,
724
+ record: contribution,
725
+ });
726
+ ```
727
+
728
+ #### Available Lexicon Collections
729
+
730
+ ```typescript
731
+ import { HYPERCERT_COLLECTIONS } from "@hypercerts-org/sdk-core";
732
+
733
+ // Collection NSIDs
734
+ HYPERCERT_COLLECTIONS.CLAIM // "org.hypercerts.claim"
735
+ HYPERCERT_COLLECTIONS.RIGHTS // "org.hypercerts.claim.rights"
736
+ HYPERCERT_COLLECTIONS.CONTRIBUTION // "org.hypercerts.claim.contribution"
737
+ HYPERCERT_COLLECTIONS.MEASUREMENT // "org.hypercerts.claim.measurement"
738
+ HYPERCERT_COLLECTIONS.EVALUATION // "org.hypercerts.claim.evaluation"
739
+ HYPERCERT_COLLECTIONS.EVIDENCE // "org.hypercerts.claim.evidence"
740
+ HYPERCERT_COLLECTIONS.COLLECTION // "org.hypercerts.collection"
741
+ HYPERCERT_COLLECTIONS.LOCATION // "app.certified.location"
625
742
  ```
626
743
 
627
744
  ## Development
package/dist/index.cjs CHANGED
@@ -2301,16 +2301,14 @@ class HypercertOperationsImpl extends eventemitter3.EventEmitter {
2301
2301
  const hypercertRecord = {
2302
2302
  $type: lexicon.HYPERCERT_COLLECTIONS.CLAIM,
2303
2303
  title: params.title,
2304
+ shortDescription: params.shortDescription,
2304
2305
  description: params.description,
2305
2306
  workScope: params.workScope,
2306
- workTimeframeFrom: params.workTimeframeFrom,
2307
- workTimeframeTo: params.workTimeframeTo,
2307
+ workTimeFrameFrom: params.workTimeFrameFrom,
2308
+ workTimeFrameTo: params.workTimeFrameTo,
2308
2309
  rights: { uri: result.rightsUri, cid: result.rightsCid },
2309
2310
  createdAt,
2310
2311
  };
2311
- if (params.shortDescription) {
2312
- hypercertRecord.shortDescription = params.shortDescription;
2313
- }
2314
2312
  if (imageBlobRef) {
2315
2313
  hypercertRecord.image = imageBlobRef;
2316
2314
  }