@hypercerts-org/sdk-core 0.7.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/dist/index.d.ts CHANGED
@@ -1179,13 +1179,13 @@ interface CreateHypercertParams {
1179
1179
  *
1180
1180
  * ISO 8601 date format (YYYY-MM-DD).
1181
1181
  */
1182
- workTimeframeFrom: string;
1182
+ workTimeFrameFrom: string;
1183
1183
  /**
1184
1184
  * End date of the work period.
1185
1185
  *
1186
1186
  * ISO 8601 date format (YYYY-MM-DD).
1187
1187
  */
1188
- workTimeframeTo: string;
1188
+ workTimeFrameTo: string;
1189
1189
  /**
1190
1190
  * Rights associated with the hypercert.
1191
1191
  */
@@ -1210,11 +1210,11 @@ interface CreateHypercertParams {
1210
1210
  description: string;
1211
1211
  };
1212
1212
  /**
1213
- * Optional short description for display in lists/cards.
1213
+ * Short description for display in lists/cards.
1214
1214
  *
1215
- * Should be under 200 characters.
1215
+ * Required field. Should be under 300 characters.
1216
1216
  */
1217
- shortDescription?: string;
1217
+ shortDescription: string;
1218
1218
  /**
1219
1219
  * Optional cover image for the hypercert.
1220
1220
  *
@@ -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,17 +2298,16 @@ 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,
2303
+ shortDescription: params.shortDescription,
2301
2304
  description: params.description,
2302
2305
  workScope: params.workScope,
2303
- workTimeframeFrom: params.workTimeframeFrom,
2304
- workTimeframeTo: params.workTimeframeTo,
2306
+ workTimeFrameFrom: params.workTimeFrameFrom,
2307
+ workTimeFrameTo: params.workTimeFrameTo,
2305
2308
  rights: { uri: result.rightsUri, cid: result.rightsCid },
2306
2309
  createdAt,
2307
2310
  };
2308
- if (params.shortDescription) {
2309
- hypercertRecord.shortDescription = params.shortDescription;
2310
- }
2311
2311
  if (imageBlobRef) {
2312
2312
  hypercertRecord.image = imageBlobRef;
2313
2313
  }
@@ -2644,6 +2644,7 @@ class HypercertOperationsImpl extends EventEmitter {
2644
2644
  * await repo.hypercerts.attachLocation(hypercertUri, {
2645
2645
  * value: "San Francisco, CA",
2646
2646
  * name: "SF Bay Area",
2647
+ * srs: "EPSG:4326",
2647
2648
  * });
2648
2649
  * ```
2649
2650
  *
@@ -2662,32 +2663,54 @@ class HypercertOperationsImpl extends EventEmitter {
2662
2663
  */
2663
2664
  async attachLocation(hypercertUri, location) {
2664
2665
  try {
2665
- // Get hypercert to get CID
2666
- const hypercert = await this.get(hypercertUri);
2666
+ // Validate required srs field
2667
+ if (!location.srs) {
2668
+ 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.");
2669
+ }
2670
+ // Validate that hypercert exists (unused but confirms hypercert is valid)
2671
+ await this.get(hypercertUri);
2667
2672
  const createdAt = new Date().toISOString();
2668
- let locationValue = location.value;
2673
+ // Determine location type and prepare location data
2674
+ let locationData;
2675
+ let locationType;
2669
2676
  if (location.geojson) {
2677
+ // Upload GeoJSON as a blob
2670
2678
  const arrayBuffer = await location.geojson.arrayBuffer();
2671
2679
  const uint8Array = new Uint8Array(arrayBuffer);
2672
2680
  const uploadResult = await this.agent.com.atproto.repo.uploadBlob(uint8Array, {
2673
2681
  encoding: location.geojson.type || "application/geo+json",
2674
2682
  });
2675
2683
  if (uploadResult.success) {
2676
- locationValue = {
2684
+ locationData = {
2677
2685
  $type: "blob",
2678
2686
  ref: { $link: uploadResult.data.blob.ref.toString() },
2679
2687
  mimeType: uploadResult.data.blob.mimeType,
2680
2688
  size: uploadResult.data.blob.size,
2681
2689
  };
2690
+ locationType = "geojson-point";
2691
+ }
2692
+ else {
2693
+ throw new NetworkError("Failed to upload GeoJSON blob");
2682
2694
  }
2683
2695
  }
2696
+ else {
2697
+ // Use value as a URI reference
2698
+ locationData = {
2699
+ $type: "app.certified.defs#uri",
2700
+ uri: location.value,
2701
+ };
2702
+ locationType = "coordinate-decimal";
2703
+ }
2704
+ // Build location record according to app.certified.location lexicon
2684
2705
  const locationRecord = {
2685
- hypercert: { uri: hypercert.uri, cid: hypercert.cid },
2686
- value: locationValue,
2706
+ $type: HYPERCERT_COLLECTIONS.LOCATION,
2707
+ lpVersion: "1.0",
2708
+ srs: location.srs,
2709
+ locationType,
2710
+ location: locationData,
2687
2711
  createdAt,
2688
2712
  name: location.name,
2689
2713
  description: location.description,
2690
- srs: location.srs,
2691
2714
  };
2692
2715
  const validation = this.lexiconRegistry.validate(HYPERCERT_COLLECTIONS.LOCATION, locationRecord);
2693
2716
  if (!validation.valid) {
@@ -2774,10 +2797,12 @@ class HypercertOperationsImpl extends EventEmitter {
2774
2797
  try {
2775
2798
  const createdAt = new Date().toISOString();
2776
2799
  const contributionRecord = {
2800
+ $type: HYPERCERT_COLLECTIONS.CONTRIBUTION,
2777
2801
  contributors: params.contributors,
2778
2802
  role: params.role,
2779
2803
  createdAt,
2780
2804
  description: params.description,
2805
+ hypercert: { uri: "", cid: "" }, // Will be set below if hypercertUri provided
2781
2806
  };
2782
2807
  if (params.hypercertUri) {
2783
2808
  const hypercert = await this.get(params.hypercertUri);
@@ -2838,6 +2863,7 @@ class HypercertOperationsImpl extends EventEmitter {
2838
2863
  const hypercert = await this.get(params.hypercertUri);
2839
2864
  const createdAt = new Date().toISOString();
2840
2865
  const measurementRecord = {
2866
+ $type: HYPERCERT_COLLECTIONS.MEASUREMENT,
2841
2867
  hypercert: { uri: hypercert.uri, cid: hypercert.cid },
2842
2868
  measurers: params.measurers,
2843
2869
  metric: params.metric,
@@ -2893,6 +2919,7 @@ class HypercertOperationsImpl extends EventEmitter {
2893
2919
  const subject = await this.get(params.subjectUri);
2894
2920
  const createdAt = new Date().toISOString();
2895
2921
  const evaluationRecord = {
2922
+ $type: HYPERCERT_COLLECTIONS.EVALUATION,
2896
2923
  subject: { uri: subject.uri, cid: subject.cid },
2897
2924
  evaluators: params.evaluators,
2898
2925
  summary: params.summary,
@@ -2967,6 +2994,7 @@ class HypercertOperationsImpl extends EventEmitter {
2967
2994
  }
2968
2995
  }
2969
2996
  const collectionRecord = {
2997
+ $type: HYPERCERT_COLLECTIONS.COLLECTION,
2970
2998
  title: params.title,
2971
2999
  claims: params.claims.map((c) => ({ claim: { uri: c.uri, cid: c.cid }, weight: c.weight })),
2972
3000
  createdAt,