@hypercerts-org/sdk-core 0.8.0-beta.0 → 0.10.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
  ```
@@ -137,9 +141,11 @@ const orgRepo = sdsRepo.repo(organizationDid);
137
141
  // Teammate can now access orgRepo and create hypercerts
138
142
  ```
139
143
 
140
- ### 2. Authentication
144
+ ### 2. Authentication & OAuth Permissions
141
145
 
142
- The SDK uses OAuth 2.0 for authentication with support for both PDS (Personal Data Server) and SDS (Shared Data Server).
146
+ The SDK uses OAuth 2.0 for authentication with granular permission control.
147
+
148
+ #### Basic Authentication
143
149
 
144
150
  ```typescript
145
151
  // First-time user authentication
@@ -160,6 +166,48 @@ const session = await sdk.restoreSession("did:plc:user123");
160
166
  const repo = sdk.getRepository(session);
161
167
  ```
162
168
 
169
+ #### OAuth Scopes & Permissions
170
+
171
+ Control exactly what your app can access using type-safe permission builders:
172
+
173
+ ```typescript
174
+ import { PermissionBuilder, ScopePresets, buildScope } from '@hypercerts-org/sdk-core';
175
+
176
+ // Use ready-made presets
177
+ const scope = ScopePresets.EMAIL_AND_PROFILE; // Request email + profile access
178
+ const scope = ScopePresets.POSTING_APP; // Full posting capabilities
179
+
180
+ // Or build custom permissions
181
+ const scope = buildScope(
182
+ new PermissionBuilder()
183
+ .accountEmail('read') // Read user's email
184
+ .repoWrite('app.bsky.feed.post') // Create/update posts
185
+ .blob(['image/*', 'video/*']) // Upload media
186
+ .build()
187
+ );
188
+
189
+ // Use in OAuth configuration
190
+ const sdk = createATProtoSDK({
191
+ oauth: {
192
+ clientId: 'your-client-id',
193
+ redirectUri: 'https://your-app.com/callback',
194
+ scope: scope, // Your custom scope
195
+ // ... other config
196
+ }
197
+ });
198
+ ```
199
+
200
+ **Available Presets:**
201
+ - `EMAIL_READ` - User's email address
202
+ - `PROFILE_READ` / `PROFILE_WRITE` - Profile access
203
+ - `POST_WRITE` - Create posts
204
+ - `SOCIAL_WRITE` - Likes, reposts, follows
205
+ - `MEDIA_UPLOAD` - Image and video uploads
206
+ - `POSTING_APP` - Full posting with media
207
+ - `EMAIL_AND_PROFILE` - Common combination
208
+
209
+ See [OAuth Permissions Documentation](./docs/implementations/atproto_oauth_scopes.md) for detailed usage.
210
+
163
211
  ### 3. Working with Hypercerts
164
212
 
165
213
  #### Creating a Hypercert
@@ -607,21 +655,134 @@ await mockStore.set(mockSession);
607
655
 
608
656
  ### Working with Lexicons
609
657
 
658
+ The SDK exports lexicon types and validation utilities from the `@hypercerts-org/lexicon` package for direct record manipulation and validation.
659
+
660
+ #### Lexicon Types
661
+
662
+ All lexicon types are available with proper TypeScript support:
663
+
664
+ ```typescript
665
+ import type {
666
+ HypercertClaim,
667
+ HypercertRights,
668
+ HypercertContribution,
669
+ HypercertCollection,
670
+ HypercertMeasurement,
671
+ HypercertEvaluation,
672
+ HypercertLocation,
673
+ StrongRef,
674
+ } from "@hypercerts-org/sdk-core";
675
+
676
+ // Create a properly typed hypercert claim
677
+ const claim: HypercertClaim = {
678
+ $type: "org.hypercerts.claim",
679
+ title: "Community Garden Project",
680
+ shortDescription: "Urban garden serving 50 families", // REQUIRED
681
+ description: "Detailed description...",
682
+ workScope: "Food Security",
683
+ workTimeFrameFrom: "2024-01-01T00:00:00Z", // Note: Capital 'F'
684
+ workTimeFrameTo: "2024-12-31T00:00:00Z", // Note: Capital 'F'
685
+ rights: { uri: "at://...", cid: "..." },
686
+ createdAt: new Date().toISOString(),
687
+ };
688
+ ```
689
+
690
+ #### Validation
691
+
692
+ Validate records before creating them:
693
+
694
+ ```typescript
695
+ import {
696
+ validate,
697
+ OrgHypercertsClaim,
698
+ HYPERCERT_COLLECTIONS,
699
+ } from "@hypercerts-org/sdk-core";
700
+
701
+ // Validate using the lexicon package
702
+ const validation = validate(
703
+ HYPERCERT_COLLECTIONS.CLAIM, // "org.hypercerts.claim"
704
+ claim
705
+ );
706
+
707
+ if (!validation.valid) {
708
+ console.error("Validation failed:", validation.error);
709
+ }
710
+
711
+ // Or use type-specific validators
712
+ const isValid = OrgHypercertsClaim.isMain(claim);
713
+ const validationResult = OrgHypercertsClaim.validateMain(claim);
714
+ ```
715
+
716
+ #### Using LexiconRegistry
717
+
718
+ For repository-level validation:
719
+
610
720
  ```typescript
611
721
  import {
612
722
  LexiconRegistry,
613
723
  HYPERCERT_LEXICONS,
614
724
  HYPERCERT_COLLECTIONS,
615
- } from "@hypercerts-org/sdk-core/lexicons";
725
+ } from "@hypercerts-org/sdk-core";
616
726
 
617
727
  const registry = new LexiconRegistry();
618
728
  registry.registerLexicons(HYPERCERT_LEXICONS);
619
729
 
620
730
  // Validate a record
621
- const isValid = registry.validate(
622
- "org.hypercerts.claim",
731
+ const result = registry.validate(
732
+ HYPERCERT_COLLECTIONS.CLAIM,
623
733
  claimData
624
734
  );
735
+
736
+ if (!result.valid) {
737
+ console.error("Invalid record:", result.error);
738
+ }
739
+ ```
740
+
741
+ #### Creating Records with Proper Types
742
+
743
+ ```typescript
744
+ import type {
745
+ HypercertContribution,
746
+ StrongRef,
747
+ } from "@hypercerts-org/sdk-core";
748
+ import { HYPERCERT_COLLECTIONS } from "@hypercerts-org/sdk-core";
749
+
750
+ // Create a contribution record
751
+ const contribution: HypercertContribution = {
752
+ $type: HYPERCERT_COLLECTIONS.CONTRIBUTION,
753
+ hypercert: {
754
+ uri: "at://did:plc:abc/org.hypercerts.claim/xyz",
755
+ cid: "bafyrei...",
756
+ } as StrongRef,
757
+ contributors: ["did:plc:contributor1", "did:plc:contributor2"],
758
+ role: "implementer",
759
+ description: "On-ground implementation team",
760
+ workTimeframeFrom: "2024-01-01T00:00:00Z", // Note: lowercase 'f' for contributions
761
+ workTimeframeTo: "2024-06-30T00:00:00Z", // Note: lowercase 'f' for contributions
762
+ createdAt: new Date().toISOString(),
763
+ };
764
+
765
+ // Use with repository operations
766
+ await repo.records.create({
767
+ collection: HYPERCERT_COLLECTIONS.CONTRIBUTION,
768
+ record: contribution,
769
+ });
770
+ ```
771
+
772
+ #### Available Lexicon Collections
773
+
774
+ ```typescript
775
+ import { HYPERCERT_COLLECTIONS } from "@hypercerts-org/sdk-core";
776
+
777
+ // Collection NSIDs
778
+ HYPERCERT_COLLECTIONS.CLAIM // "org.hypercerts.claim"
779
+ HYPERCERT_COLLECTIONS.RIGHTS // "org.hypercerts.claim.rights"
780
+ HYPERCERT_COLLECTIONS.CONTRIBUTION // "org.hypercerts.claim.contribution"
781
+ HYPERCERT_COLLECTIONS.MEASUREMENT // "org.hypercerts.claim.measurement"
782
+ HYPERCERT_COLLECTIONS.EVALUATION // "org.hypercerts.claim.evaluation"
783
+ HYPERCERT_COLLECTIONS.EVIDENCE // "org.hypercerts.claim.evidence"
784
+ HYPERCERT_COLLECTIONS.COLLECTION // "org.hypercerts.collection"
785
+ HYPERCERT_COLLECTIONS.LOCATION // "app.certified.location"
625
786
  ```
626
787
 
627
788
  ## Development