@hypercerts-org/sdk-core 0.10.0-beta.5 → 0.10.0-beta.6

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/types.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { OAuthSession, NodeSavedSession, NodeSavedState } from '@atproto/oauth-client-node';
2
2
  import { z } from 'zod';
3
3
  import { EventEmitter } from 'eventemitter3';
4
- import { OrgHypercertsClaimActivity, OrgHypercertsClaimCollection, OrgHypercertsClaimRights, AppCertifiedLocation, OrgHypercertsClaimContributionDetails, OrgHypercertsClaimContributorInformation, OrgHypercertsClaimMeasurement, OrgHypercertsClaimEvaluation, OrgHypercertsHelperWorkScopeTag, OrgHypercertsClaimEvidence, OrgHypercertsDefs } from '@hypercerts-org/lexicon';
4
+ import { OverrideProperties, SetOptional } from 'type-fest';
5
+ import { ComAtprotoRepoStrongRef, AppCertifiedLocation, OrgHypercertsClaimActivity, OrgHypercertsClaimCollection, OrgHypercertsClaimRights, OrgHypercertsClaimContributionDetails, OrgHypercertsClaimContributorInformation, OrgHypercertsClaimMeasurement, OrgHypercertsClaimEvaluation, OrgHypercertsHelperWorkScopeTag, OrgHypercertsClaimEvidence, OrgHypercertsDefs } from '@hypercerts-org/lexicon';
5
6
  export { BlobRef, JsonBlobRef } from '@atproto/lexicon';
6
7
 
7
8
  /**
@@ -1334,6 +1335,7 @@ interface ProgressStep {
1334
1335
  * @packageDocumentation
1335
1336
  */
1336
1337
 
1338
+ type StrongRef = ComAtprotoRepoStrongRef.Main;
1337
1339
  type HypercertClaim = OrgHypercertsClaimActivity.Main;
1338
1340
  type HypercertRights = OrgHypercertsClaimRights.Main;
1339
1341
  type HypercertContributionDetails = OrgHypercertsClaimContributionDetails.Main;
@@ -1352,85 +1354,118 @@ type HypercertLocation = AppCertifiedLocation.Main;
1352
1354
  /**
1353
1355
  * Image input for SDK operations.
1354
1356
  *
1355
- * Can be either:
1356
- * - A URI reference (for external images)
1357
- * - A Blob to be uploaded
1357
+ * Accepts either:
1358
+ * - A string URI reference (for external images)
1359
+ * - A Blob to be uploaded (will be converted to SmallImage or LargeImage)
1358
1360
  *
1359
- * The SDK will convert these to the appropriate lexicon types:
1360
- * - OrgHypercertsDefs.Uri
1361
- * - OrgHypercertsDefs.SmallImage
1362
- * - OrgHypercertsDefs.LargeImage
1361
+ * The SDK will convert these inputs to the appropriate lexicon types.
1363
1362
  */
1364
- type HypercertImage = {
1365
- type: "uri";
1366
- uri: string;
1367
- } | {
1368
- type: "blob";
1369
- blob: Blob;
1370
- };
1363
+ type HypercertImage = string | Blob;
1371
1364
  /**
1372
1365
  * Lexicon-defined image types (union of Uri and image blob types).
1373
- * Use this when working with stored records.
1366
+ *
1367
+ * Used when working with stored records. Can be:
1368
+ * - OrgHypercertsDefs.Uri - External image reference
1369
+ * - OrgHypercertsDefs.SmallImage - Uploaded blob for avatars/thumbnails
1370
+ * - OrgHypercertsDefs.LargeImage - Uploaded blob for banners/covers
1374
1371
  */
1375
1372
  type HypercertImageRecord = OrgHypercertsDefs.Uri | OrgHypercertsDefs.SmallImage | OrgHypercertsDefs.LargeImage;
1376
- /** Hypercert with AT Protocol metadata */
1377
- interface HypercertWithMetadata {
1378
- uri: string;
1379
- cid: string;
1380
- record: HypercertClaim;
1381
- }
1373
+ /** Hypercert with resolved metadata */
1374
+ type HypercertWithMetadata = HypercertClaim & {
1375
+ resolvedRights?: HypercertRights;
1376
+ resolvedLocation?: HypercertLocation;
1377
+ };
1378
+ /** Project type alias (collection with type="project") */
1379
+ type HypercertProject = HypercertCollection & {
1380
+ type: "project";
1381
+ };
1382
+ /** Project with resolved metadata */
1383
+ type HypercertProjectWithMetadata = HypercertCollection & {
1384
+ resolvedLocation?: HypercertLocation;
1385
+ resolvedActivities?: HypercertClaim[];
1386
+ };
1387
+
1388
+ type CollectionItemInput = SetOptional<OrgHypercertsClaimCollection.Item, "$type">;
1389
+ /**
1390
+ * Parameters for specifying a location in collection/project operations.
1391
+ * Supports three ways to specify location:
1392
+ *
1393
+ * 1. **StrongRef** - Direct reference with uri and cid (no record creation)
1394
+ * 2. **AT-URI string** - Reference to existing location record
1395
+ * 3. **Location object** - Full location data (lpVersion, srs, locationType, location, etc.)
1396
+ * with optional `$type` and `createdAt` fields
1397
+ * where-as location field can be a Blob (e.g., GeoJSON) that will be uploaded
1398
+ *
1399
+ * @example Using a StrongRef (no record creation)
1400
+ * ```typescript
1401
+ * const location: AttachLocationParams = { uri: "at://did:plc:test/app.certified.location/abc", cid: "bafyrei..." };
1402
+ * ```
1403
+ *
1404
+ * @example Using an AT-URI (fetches existing record)
1405
+ * ```typescript
1406
+ * const location: AttachLocationParams = "at://did:plc:test/app.certified.location/xyz";
1407
+ * ```
1408
+ *
1409
+ * @example Using a location object
1410
+ * ```typescript
1411
+ * const location: AttachLocationParams = {
1412
+ * lpVersion: "1.0.0",
1413
+ * srs: "EPSG:4326",
1414
+ * locationType: "coordinate-decimal",
1415
+ * location: "https://locationuri.com",
1416
+ * name: "San Francisco",
1417
+ * };
1418
+ * ```
1419
+ */
1420
+ type CreateLocationParams = OverrideProperties<SetOptional<HypercertLocation, "$type" | "createdAt">, {
1421
+ location: string | Blob | HypercertLocation["location"];
1422
+ }>;
1423
+ type LocationParams = StrongRef | string | CreateLocationParams;
1382
1424
  /**
1383
- * Project type - a HypercertCollection with type='project'.
1425
+ * SDK input parameters for creating a collection.
1426
+ * Derived from lexicon type with $type and createdAt removed.
1427
+ * avatar/banner accept HypercertImage (string URI or Blob) for user convenience.
1428
+ * Location can be provided inline or via attachLocationToCollection().
1384
1429
  */
1385
- interface HypercertProject extends HypercertCollection {
1386
- type: "project";
1387
- }
1430
+ type CreateCollectionParams = OverrideProperties<SetOptional<OrgHypercertsClaimCollection.Main, "$type" | "createdAt">, {
1431
+ avatar?: HypercertImage;
1432
+ banner?: HypercertImage;
1433
+ items: CollectionItemInput[];
1434
+ /**
1435
+ * Optional location to attach to the collection.
1436
+ * Can be:
1437
+ * - StrongRef to reference existing location (uri + cid)
1438
+ * - string (AT-URI) to reference existing location (CID will be fetched)
1439
+ * - Location object to create a new location record
1440
+ */
1441
+ location?: LocationParams;
1442
+ }>;
1388
1443
  /**
1389
- * HypercertProject with AT Protocol metadata.
1444
+ * SDK input parameters for updating a collection.
1445
+ * All fields are optional.
1446
+ * avatar/banner accept HypercertImage (string URI or Blob), or null to remove.
1447
+ * Location can be updated inline or removed with null.
1390
1448
  */
1391
- interface HypercertProjectWithMetadata {
1449
+ type UpdateCollectionParams = Omit<Partial<CreateCollectionParams>, "avatar" | "banner" | "location"> & {
1450
+ avatar?: HypercertImage | null;
1451
+ banner?: HypercertImage | null;
1452
+ location?: LocationParams | null;
1453
+ };
1454
+ type CreateCollectionResult = {
1392
1455
  uri: string;
1393
1456
  cid: string;
1394
- record: HypercertProject;
1395
- }
1457
+ record: HypercertCollection;
1458
+ };
1396
1459
  /**
1397
- * Parameters for creating a project.
1460
+ * SDK input parameters for creating a project.
1461
+ * Projects are collections with type="project" (set automatically).
1398
1462
  */
1399
- interface CreateProjectParams {
1400
- title: string;
1401
- shortDescription: string;
1402
- description?: unknown;
1403
- avatar?: Blob;
1404
- banner?: Blob;
1405
- activities?: Array<{
1406
- uri: string;
1407
- cid: string;
1408
- weight: string;
1409
- }>;
1410
- location?: {
1411
- uri: string;
1412
- cid: string;
1413
- };
1414
- }
1463
+ type CreateProjectParams = CreateCollectionParams;
1415
1464
  /**
1416
- * Parameters for updating a project.
1465
+ * SDK input parameters for updating a project.
1417
1466
  */
1418
- interface UpdateProjectParams {
1419
- title?: string;
1420
- shortDescription?: string;
1421
- description?: unknown;
1422
- avatar?: Blob;
1423
- banner?: Blob;
1424
- activities?: Array<{
1425
- uri: string;
1426
- cid: string;
1427
- weight: string;
1428
- }>;
1429
- location?: {
1430
- uri: string;
1431
- cid: string;
1432
- };
1433
- }
1467
+ type UpdateProjectParams = UpdateCollectionParams;
1468
+ type CreateProjectResult = CreateCollectionResult;
1434
1469
 
1435
1470
  /**
1436
1471
  * Parameters for creating a new hypercert.
@@ -1569,7 +1604,7 @@ interface CreateHypercertParams {
1569
1604
  /**
1570
1605
  * Optional geographic location of the impact.
1571
1606
  */
1572
- location?: AttachLocationParams;
1607
+ location?: LocationParams;
1573
1608
  /**
1574
1609
  * Optional list of contributions to the impact.
1575
1610
  *
@@ -1658,49 +1693,6 @@ interface CreateHypercertEvidenceParams {
1658
1693
  */
1659
1694
  [k: string]: unknown;
1660
1695
  }
1661
- /**
1662
- * Parameters for attaching a location to a hypercert.
1663
- *
1664
- * @example Using a string location
1665
- * ```typescript
1666
- * const params: AttachLocationParams = {
1667
- * lpVersion: "1.0.0",
1668
- * srs: "EPSG:4326",
1669
- * locationType: "coordinate-decimal",
1670
- * location: "https://locationuri.com",
1671
- * name: "San Francisco",
1672
- * description: "Project location in SF Bay Area",
1673
- * };
1674
- * ```
1675
- *
1676
- * @example Using a GeoJSON Blob
1677
- * ```typescript
1678
- * const geojsonBlob = new Blob(
1679
- * [JSON.stringify({ type: "Point", coordinates: [-122.4194, 37.7749] })],
1680
- * { type: "application/geo+json" }
1681
- * );
1682
- * const params: AttachLocationParams = {
1683
- * lpVersion: "1.0.0",
1684
- * srs: "EPSG:4326",
1685
- * locationType: "geojson-point",
1686
- * location: geojsonBlob,
1687
- * };
1688
- * ```
1689
- */
1690
- interface AttachLocationParams {
1691
- /** The version of the Location Protocol */
1692
- lpVersion: string;
1693
- /** The Spatial Reference System URI (e.g., http://www.opengis.net/def/crs/OGC/1.3/CRS84) that defines the coordinate system. */
1694
- srs: string;
1695
- /** An identifier for the format of the location data (e.g., coordinate-decimal, geojson-point) */
1696
- locationType: "coordinate-decimal" | "geojson-point" | (string & {});
1697
- /** Location data as either a URL string or a GeoJSON Blob */
1698
- location: string | Blob;
1699
- /** Optional name for this location */
1700
- name?: string;
1701
- /** Optional description for this location */
1702
- description?: string;
1703
- }
1704
1696
  /**
1705
1697
  * Result of creating a hypercert.
1706
1698
  *
@@ -2049,6 +2041,33 @@ interface HypercertEvents {
2049
2041
  uri: string;
2050
2042
  cid: string;
2051
2043
  };
2044
+ /**
2045
+ * Emitted when a collection is updated.
2046
+ */
2047
+ collectionUpdated: {
2048
+ uri: string;
2049
+ cid: string;
2050
+ };
2051
+ /**
2052
+ * Emitted when a collection is deleted.
2053
+ */
2054
+ collectionDeleted: {
2055
+ uri: string;
2056
+ };
2057
+ /**
2058
+ * Emitted when a location is attached to a collection.
2059
+ */
2060
+ locationAttachedToCollection: {
2061
+ uri: string;
2062
+ cid: string;
2063
+ collectionUri: string;
2064
+ };
2065
+ /**
2066
+ * Emitted when a location is removed from a collection.
2067
+ */
2068
+ locationRemovedFromCollection: {
2069
+ collectionUri: string;
2070
+ };
2052
2071
  /**
2053
2072
  * Emitted when a project is created.
2054
2073
  */
@@ -2069,6 +2088,20 @@ interface HypercertEvents {
2069
2088
  projectDeleted: {
2070
2089
  uri: string;
2071
2090
  };
2091
+ /**
2092
+ * Emitted when a location is attached to a project.
2093
+ */
2094
+ locationAttachedToProject: {
2095
+ uri: string;
2096
+ cid: string;
2097
+ projectUri: string;
2098
+ };
2099
+ /**
2100
+ * Emitted when a location is removed from a project.
2101
+ */
2102
+ locationRemovedFromProject: {
2103
+ projectUri: string;
2104
+ };
2072
2105
  }
2073
2106
  /**
2074
2107
  * High-level hypercert operations.
@@ -2124,7 +2157,7 @@ interface HypercertOperations extends EventEmitter<HypercertEvents> {
2124
2157
  */
2125
2158
  update(params: {
2126
2159
  uri: string;
2127
- updates: Partial<Omit<HypercertClaim, "$type" | "createdAt" | "rights">>;
2160
+ updates: Partial<CreateHypercertParams>;
2128
2161
  image?: Blob | null;
2129
2162
  }): Promise<UpdateResult>;
2130
2163
  /**
@@ -2170,7 +2203,7 @@ interface HypercertOperations extends EventEmitter<HypercertEvents> {
2170
2203
  * @param location.geojson - Optional GeoJSON blob for precise boundaries
2171
2204
  * @returns Promise resolving to location record result
2172
2205
  */
2173
- attachLocation(uri: string, location: AttachLocationParams): Promise<CreateResult>;
2206
+ attachLocation(uri: string, location: LocationParams): Promise<CreateResult>;
2174
2207
  /**
2175
2208
  * Adds evidence to an existing hypercert.
2176
2209
  *
@@ -2219,18 +2252,9 @@ interface HypercertOperations extends EventEmitter<HypercertEvents> {
2219
2252
  * Creates a collection of hypercerts.
2220
2253
  *
2221
2254
  * @param params - Collection parameters
2222
- * @returns Promise resolving to collection record result
2223
- */
2224
- createCollection(params: {
2225
- title: string;
2226
- claims: Array<{
2227
- uri: string;
2228
- cid: string;
2229
- weight: string;
2230
- }>;
2231
- shortDescription?: string;
2232
- banner?: Blob;
2233
- }): Promise<CreateResult>;
2255
+ * @returns Promise resolving to collection record result with optional location URI
2256
+ */
2257
+ createCollection(params: CreateCollectionParams): Promise<CreateCollectionResult>;
2234
2258
  /**
2235
2259
  * Gets a collection by URI.
2236
2260
  *
@@ -2253,24 +2277,45 @@ interface HypercertOperations extends EventEmitter<HypercertEvents> {
2253
2277
  cid: string;
2254
2278
  record: HypercertCollection;
2255
2279
  }>>;
2280
+ /**
2281
+ * Updates a collection.
2282
+ *
2283
+ * @param uri - AT-URI of the collection
2284
+ * @param updates - Fields to update
2285
+ * @returns Promise resolving to update result
2286
+ */
2287
+ updateCollection(uri: string, updates: UpdateCollectionParams): Promise<UpdateResult>;
2288
+ /**
2289
+ * Deletes a collection.
2290
+ *
2291
+ * @param uri - AT-URI of the collection
2292
+ * @returns Promise resolving when deleted
2293
+ */
2294
+ deleteCollection(uri: string): Promise<void>;
2295
+ /**
2296
+ * Attaches a location to a collection.
2297
+ *
2298
+ * @param uri - AT-URI of the collection
2299
+ * @param location - Location data
2300
+ * @returns Promise resolving to location record result
2301
+ */
2302
+ attachLocationToCollection(uri: string, location: LocationParams): Promise<CreateResult>;
2303
+ /**
2304
+ * Removes a location from a collection.
2305
+ *
2306
+ * @param uri - AT-URI of the collection
2307
+ * @returns Promise resolving when location is removed
2308
+ */
2309
+ removeLocationFromCollection(uri: string): Promise<void>;
2256
2310
  /**
2257
2311
  * Creates a project.
2258
2312
  *
2313
+ * A project is a collection with type='project' and optional location sidecar.
2314
+ *
2259
2315
  * @param params - Project parameters
2260
- * @returns Promise resolving to project record result
2261
- */
2262
- createProject(params: {
2263
- title: string;
2264
- shortDescription: string;
2265
- description?: unknown;
2266
- avatar?: Blob;
2267
- banner?: Blob;
2268
- activities?: Array<{
2269
- uri: string;
2270
- cid: string;
2271
- weight: string;
2272
- }>;
2273
- }): Promise<CreateResult>;
2316
+ * @returns Promise resolving to project record result with optional location URI
2317
+ */
2318
+ createProject(params: CreateProjectParams): Promise<CreateProjectResult>;
2274
2319
  /**
2275
2320
  * Gets a project by URI.
2276
2321
  *
@@ -2304,18 +2349,7 @@ interface HypercertOperations extends EventEmitter<HypercertEvents> {
2304
2349
  * @param updates - Fields to update
2305
2350
  * @returns Promise resolving to update result
2306
2351
  */
2307
- updateProject(uri: string, updates: {
2308
- title?: string;
2309
- shortDescription?: string;
2310
- description?: unknown;
2311
- avatar?: Blob | null;
2312
- banner?: Blob | null;
2313
- activities?: Array<{
2314
- uri: string;
2315
- cid: string;
2316
- weight: string;
2317
- }>;
2318
- }): Promise<UpdateResult>;
2352
+ updateProject(uri: string, updates: UpdateProjectParams): Promise<UpdateResult>;
2319
2353
  /**
2320
2354
  * Deletes a project.
2321
2355
  *
@@ -2323,6 +2357,21 @@ interface HypercertOperations extends EventEmitter<HypercertEvents> {
2323
2357
  * @returns Promise resolving when deleted
2324
2358
  */
2325
2359
  deleteProject(uri: string): Promise<void>;
2360
+ /**
2361
+ * Attaches a location to a project.
2362
+ *
2363
+ * @param uri - AT-URI of the project
2364
+ * @param location - Location data
2365
+ * @returns Promise resolving to location record result
2366
+ */
2367
+ attachLocationToProject(uri: string, location: LocationParams): Promise<CreateResult>;
2368
+ /**
2369
+ * Removes a location from a project.
2370
+ *
2371
+ * @param uri - AT-URI of the project
2372
+ * @returns Promise resolving when location is removed
2373
+ */
2374
+ removeLocationFromProject(uri: string): Promise<void>;
2326
2375
  }
2327
2376
  /**
2328
2377
  * Collaborator operations for SDS access control.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hypercerts-org/sdk-core",
3
- "version": "0.10.0-beta.5",
3
+ "version": "0.10.0-beta.6",
4
4
  "description": "Framework-agnostic ATProto SDK core for authentication, repository operations, and lexicon management",
5
5
  "main": "dist/index.cjs",
6
6
  "repository": {
@@ -76,8 +76,9 @@
76
76
  "@atproto/lexicon": "^0.5.1",
77
77
  "@atproto/oauth-client": "^0.5.10",
78
78
  "@atproto/oauth-client-node": "^0.3.12",
79
- "@hypercerts-org/lexicon": "0.10.0-beta.10",
79
+ "@hypercerts-org/lexicon": "0.10.0-beta.11",
80
80
  "eventemitter3": "^5.0.1",
81
+ "type-fest": "^5.4.1",
81
82
  "zod": "^3.24.4"
82
83
  },
83
84
  "scripts": {