@hypercerts-org/sdk-core 0.7.0-beta.0 → 0.8.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/dist/index.d.ts CHANGED
@@ -1242,11 +1242,11 @@ interface CreateHypercertParams {
1242
1242
  */
1243
1243
  description?: string;
1244
1244
  /**
1245
- * Spatial Reference System identifier.
1245
+ * Spatial Reference System identifier (required if location is provided).
1246
1246
  *
1247
1247
  * @example "EPSG:4326" for WGS84
1248
1248
  */
1249
- srs?: string;
1249
+ srs: string;
1250
1250
  /**
1251
1251
  * GeoJSON file as a Blob for precise boundaries.
1252
1252
  */
@@ -1723,13 +1723,18 @@ interface HypercertOperations extends EventEmitter<HypercertEvents> {
1723
1723
  *
1724
1724
  * @param uri - AT-URI of the hypercert
1725
1725
  * @param location - Location data
1726
+ * @param location.value - Location value (address, coordinates, or description)
1727
+ * @param location.srs - Spatial Reference System (required). Use 'EPSG:4326' for WGS84 lat/lon coordinates.
1728
+ * @param location.name - Optional human-readable location name
1729
+ * @param location.description - Optional description of the location
1730
+ * @param location.geojson - Optional GeoJSON blob for precise boundaries
1726
1731
  * @returns Promise resolving to location record result
1727
1732
  */
1728
1733
  attachLocation(uri: string, location: {
1729
1734
  value: string;
1730
1735
  name?: string;
1731
1736
  description?: string;
1732
- srs?: string;
1737
+ srs: string;
1733
1738
  geojson?: Blob;
1734
1739
  }): Promise<CreateResult>;
1735
1740
  /**
package/dist/index.mjs CHANGED
@@ -2269,6 +2269,7 @@ class HypercertOperationsImpl extends EventEmitter {
2269
2269
  // Step 2: Create rights record
2270
2270
  this.emitProgress(params.onProgress, { name: "createRights", status: "start" });
2271
2271
  const rightsRecord = {
2272
+ $type: HYPERCERT_COLLECTIONS.RIGHTS,
2272
2273
  rightsName: params.rights.name,
2273
2274
  rightsType: params.rights.type,
2274
2275
  rightsDescription: params.rights.description,
@@ -2297,6 +2298,7 @@ class HypercertOperationsImpl extends EventEmitter {
2297
2298
  // Step 3: Create hypercert record
2298
2299
  this.emitProgress(params.onProgress, { name: "createHypercert", status: "start" });
2299
2300
  const hypercertRecord = {
2301
+ $type: HYPERCERT_COLLECTIONS.CLAIM,
2300
2302
  title: params.title,
2301
2303
  description: params.description,
2302
2304
  workScope: params.workScope,
@@ -2644,6 +2646,7 @@ class HypercertOperationsImpl extends EventEmitter {
2644
2646
  * await repo.hypercerts.attachLocation(hypercertUri, {
2645
2647
  * value: "San Francisco, CA",
2646
2648
  * name: "SF Bay Area",
2649
+ * srs: "EPSG:4326",
2647
2650
  * });
2648
2651
  * ```
2649
2652
  *
@@ -2662,32 +2665,54 @@ class HypercertOperationsImpl extends EventEmitter {
2662
2665
  */
2663
2666
  async attachLocation(hypercertUri, location) {
2664
2667
  try {
2665
- // Get hypercert to get CID
2666
- const hypercert = await this.get(hypercertUri);
2668
+ // Validate required srs field
2669
+ if (!location.srs) {
2670
+ throw new ValidationError("srs (Spatial Reference System) is required. Example: 'EPSG:4326' for WGS84 coordinates, or 'http://www.opengis.net/def/crs/OGC/1.3/CRS84' for CRS84.");
2671
+ }
2672
+ // Validate that hypercert exists (unused but confirms hypercert is valid)
2673
+ await this.get(hypercertUri);
2667
2674
  const createdAt = new Date().toISOString();
2668
- let locationValue = location.value;
2675
+ // Determine location type and prepare location data
2676
+ let locationData;
2677
+ let locationType;
2669
2678
  if (location.geojson) {
2679
+ // Upload GeoJSON as a blob
2670
2680
  const arrayBuffer = await location.geojson.arrayBuffer();
2671
2681
  const uint8Array = new Uint8Array(arrayBuffer);
2672
2682
  const uploadResult = await this.agent.com.atproto.repo.uploadBlob(uint8Array, {
2673
2683
  encoding: location.geojson.type || "application/geo+json",
2674
2684
  });
2675
2685
  if (uploadResult.success) {
2676
- locationValue = {
2686
+ locationData = {
2677
2687
  $type: "blob",
2678
2688
  ref: { $link: uploadResult.data.blob.ref.toString() },
2679
2689
  mimeType: uploadResult.data.blob.mimeType,
2680
2690
  size: uploadResult.data.blob.size,
2681
2691
  };
2692
+ locationType = "geojson-point";
2693
+ }
2694
+ else {
2695
+ throw new NetworkError("Failed to upload GeoJSON blob");
2682
2696
  }
2683
2697
  }
2698
+ else {
2699
+ // Use value as a URI reference
2700
+ locationData = {
2701
+ $type: "app.certified.defs#uri",
2702
+ uri: location.value,
2703
+ };
2704
+ locationType = "coordinate-decimal";
2705
+ }
2706
+ // Build location record according to app.certified.location lexicon
2684
2707
  const locationRecord = {
2685
- hypercert: { uri: hypercert.uri, cid: hypercert.cid },
2686
- value: locationValue,
2708
+ $type: HYPERCERT_COLLECTIONS.LOCATION,
2709
+ lpVersion: "1.0",
2710
+ srs: location.srs,
2711
+ locationType,
2712
+ location: locationData,
2687
2713
  createdAt,
2688
2714
  name: location.name,
2689
2715
  description: location.description,
2690
- srs: location.srs,
2691
2716
  };
2692
2717
  const validation = this.lexiconRegistry.validate(HYPERCERT_COLLECTIONS.LOCATION, locationRecord);
2693
2718
  if (!validation.valid) {
@@ -2774,10 +2799,12 @@ class HypercertOperationsImpl extends EventEmitter {
2774
2799
  try {
2775
2800
  const createdAt = new Date().toISOString();
2776
2801
  const contributionRecord = {
2802
+ $type: HYPERCERT_COLLECTIONS.CONTRIBUTION,
2777
2803
  contributors: params.contributors,
2778
2804
  role: params.role,
2779
2805
  createdAt,
2780
2806
  description: params.description,
2807
+ hypercert: { uri: "", cid: "" }, // Will be set below if hypercertUri provided
2781
2808
  };
2782
2809
  if (params.hypercertUri) {
2783
2810
  const hypercert = await this.get(params.hypercertUri);
@@ -2838,6 +2865,7 @@ class HypercertOperationsImpl extends EventEmitter {
2838
2865
  const hypercert = await this.get(params.hypercertUri);
2839
2866
  const createdAt = new Date().toISOString();
2840
2867
  const measurementRecord = {
2868
+ $type: HYPERCERT_COLLECTIONS.MEASUREMENT,
2841
2869
  hypercert: { uri: hypercert.uri, cid: hypercert.cid },
2842
2870
  measurers: params.measurers,
2843
2871
  metric: params.metric,
@@ -2893,6 +2921,7 @@ class HypercertOperationsImpl extends EventEmitter {
2893
2921
  const subject = await this.get(params.subjectUri);
2894
2922
  const createdAt = new Date().toISOString();
2895
2923
  const evaluationRecord = {
2924
+ $type: HYPERCERT_COLLECTIONS.EVALUATION,
2896
2925
  subject: { uri: subject.uri, cid: subject.cid },
2897
2926
  evaluators: params.evaluators,
2898
2927
  summary: params.summary,
@@ -2967,6 +2996,7 @@ class HypercertOperationsImpl extends EventEmitter {
2967
2996
  }
2968
2997
  }
2969
2998
  const collectionRecord = {
2999
+ $type: HYPERCERT_COLLECTIONS.COLLECTION,
2970
3000
  title: params.title,
2971
3001
  claims: params.claims.map((c) => ({ claim: { uri: c.uri, cid: c.cid }, weight: c.weight })),
2972
3002
  createdAt,