@hypercerts-org/sdk-core 0.5.0-beta.0 → 0.7.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.
Files changed (57) hide show
  1. package/README.md +130 -8
  2. package/dist/index.cjs +93 -15
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.ts +64 -1
  5. package/dist/index.mjs +93 -16
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +9 -5
  8. package/.turbo/turbo-build.log +0 -40
  9. package/.turbo/turbo-test.log +0 -119
  10. package/CHANGELOG.md +0 -62
  11. package/eslint.config.mjs +0 -22
  12. package/rollup.config.js +0 -75
  13. package/src/auth/OAuthClient.ts +0 -497
  14. package/src/core/SDK.ts +0 -410
  15. package/src/core/config.ts +0 -243
  16. package/src/core/errors.ts +0 -257
  17. package/src/core/interfaces.ts +0 -324
  18. package/src/core/types.ts +0 -282
  19. package/src/errors.ts +0 -57
  20. package/src/index.ts +0 -107
  21. package/src/lexicons.ts +0 -64
  22. package/src/repository/BlobOperationsImpl.ts +0 -199
  23. package/src/repository/CollaboratorOperationsImpl.ts +0 -442
  24. package/src/repository/HypercertOperationsImpl.ts +0 -1146
  25. package/src/repository/LexiconRegistry.ts +0 -332
  26. package/src/repository/OrganizationOperationsImpl.ts +0 -282
  27. package/src/repository/ProfileOperationsImpl.ts +0 -281
  28. package/src/repository/RecordOperationsImpl.ts +0 -340
  29. package/src/repository/Repository.ts +0 -482
  30. package/src/repository/interfaces.ts +0 -909
  31. package/src/repository/types.ts +0 -111
  32. package/src/services/hypercerts/types.ts +0 -87
  33. package/src/storage/InMemorySessionStore.ts +0 -127
  34. package/src/storage/InMemoryStateStore.ts +0 -146
  35. package/src/storage.ts +0 -63
  36. package/src/testing/index.ts +0 -67
  37. package/src/testing/mocks.ts +0 -142
  38. package/src/testing/stores.ts +0 -285
  39. package/src/testing.ts +0 -64
  40. package/src/types.ts +0 -86
  41. package/tests/auth/OAuthClient.test.ts +0 -164
  42. package/tests/core/SDK.test.ts +0 -176
  43. package/tests/core/errors.test.ts +0 -81
  44. package/tests/repository/BlobOperationsImpl.test.ts +0 -155
  45. package/tests/repository/CollaboratorOperationsImpl.test.ts +0 -438
  46. package/tests/repository/HypercertOperationsImpl.test.ts +0 -652
  47. package/tests/repository/LexiconRegistry.test.ts +0 -192
  48. package/tests/repository/OrganizationOperationsImpl.test.ts +0 -240
  49. package/tests/repository/ProfileOperationsImpl.test.ts +0 -254
  50. package/tests/repository/RecordOperationsImpl.test.ts +0 -375
  51. package/tests/repository/Repository.test.ts +0 -149
  52. package/tests/utils/fixtures.ts +0 -117
  53. package/tests/utils/mocks.ts +0 -109
  54. package/tests/utils/repository-fixtures.ts +0 -78
  55. package/tsconfig.json +0 -11
  56. package/tsconfig.tsbuildinfo +0 -1
  57. package/vitest.config.ts +0 -30
package/dist/index.d.ts CHANGED
@@ -2987,6 +2987,69 @@ declare class ATProtoSDK {
2987
2987
  */
2988
2988
  declare function createATProtoSDK(config: ATProtoSDKConfig): ATProtoSDK;
2989
2989
 
2990
+ /**
2991
+ * ConfigurableAgent - Agent with configurable service URL routing.
2992
+ *
2993
+ * This module provides an Agent extension that allows routing requests to
2994
+ * a specific server URL, overriding the default URL from the OAuth session.
2995
+ *
2996
+ * @packageDocumentation
2997
+ */
2998
+
2999
+ /**
3000
+ * Agent subclass that routes requests to a configurable service URL.
3001
+ *
3002
+ * The standard Agent uses the service URL embedded in the OAuth session's
3003
+ * fetch handler. This class allows overriding that URL to route requests
3004
+ * to different servers (e.g., PDS vs SDS, or multiple SDS instances).
3005
+ *
3006
+ * @remarks
3007
+ * This is particularly useful for:
3008
+ * - Routing to a Shared Data Server (SDS) while authenticated via PDS
3009
+ * - Supporting multiple SDS instances for different organizations
3010
+ * - Testing against different server environments
3011
+ *
3012
+ * @example Basic usage
3013
+ * ```typescript
3014
+ * const session = await sdk.authorize("user.bsky.social");
3015
+ *
3016
+ * // Create agent routing to SDS instead of session's default PDS
3017
+ * const sdsAgent = new ConfigurableAgent(session, "https://sds.hypercerts.org");
3018
+ *
3019
+ * // All requests will now go to the SDS
3020
+ * await sdsAgent.com.atproto.repo.createRecord({...});
3021
+ * ```
3022
+ *
3023
+ * @example Multiple SDS instances
3024
+ * ```typescript
3025
+ * // Route to organization A's SDS
3026
+ * const orgAAgent = new ConfigurableAgent(session, "https://sds-org-a.example.com");
3027
+ *
3028
+ * // Route to organization B's SDS
3029
+ * const orgBAgent = new ConfigurableAgent(session, "https://sds-org-b.example.com");
3030
+ * ```
3031
+ */
3032
+ declare class ConfigurableAgent extends Agent {
3033
+ private customServiceUrl;
3034
+ /**
3035
+ * Creates a ConfigurableAgent that routes to a specific service URL.
3036
+ *
3037
+ * @param session - OAuth session for authentication
3038
+ * @param serviceUrl - Base URL of the server to route requests to
3039
+ *
3040
+ * @remarks
3041
+ * The agent wraps the session's fetch handler to intercept requests and
3042
+ * prepend the custom service URL instead of using the session's default.
3043
+ */
3044
+ constructor(session: Session, serviceUrl: string);
3045
+ /**
3046
+ * Gets the service URL this agent routes to.
3047
+ *
3048
+ * @returns The base URL of the configured service
3049
+ */
3050
+ getServiceUrl(): string;
3051
+ }
3052
+
2990
3053
  /**
2991
3054
  * Base error class for all SDK errors.
2992
3055
  *
@@ -3464,5 +3527,5 @@ declare class InMemoryStateStore implements StateStore {
3464
3527
  clear(): void;
3465
3528
  }
3466
3529
 
3467
- export { ATProtoSDK, ATProtoSDKConfigSchema, ATProtoSDKError, AuthenticationError, CollaboratorPermissionsSchema, CollaboratorSchema, InMemorySessionStore, InMemoryStateStore, LexiconRegistry, NetworkError, OAuthConfigSchema, OrganizationSchema, Repository, SDSRequiredError, ServerConfigSchema, SessionExpiredError, TimeoutConfigSchema, ValidationError, createATProtoSDK };
3530
+ export { ATProtoSDK, ATProtoSDKConfigSchema, ATProtoSDKError, AuthenticationError, CollaboratorPermissionsSchema, CollaboratorSchema, ConfigurableAgent, InMemorySessionStore, InMemoryStateStore, LexiconRegistry, NetworkError, OAuthConfigSchema, OrganizationSchema, Repository, SDSRequiredError, ServerConfigSchema, SessionExpiredError, TimeoutConfigSchema, ValidationError, createATProtoSDK };
3468
3531
  export type { ATProtoSDKConfig, AuthorizeOptions, BlobOperations, BlobRef, CacheInterface, Collaborator, CollaboratorOperations, CollaboratorPermissions, CreateHypercertParams, CreateHypercertResult, CreateResult, DID, HypercertClaim, HypercertCollection, HypercertCollectionClaimItem, HypercertContribution, HypercertEvaluation, HypercertEvents, HypercertEvidence, HypercertImage, HypercertLocation, HypercertMeasurement, HypercertOperations, HypercertRights, HypercertWithMetadata, ListParams, LoggerInterface, Organization, OrganizationInfo, OrganizationOperations, PaginatedList, ProfileOperations, ProgressStep, RecordOperations, RepositoryAccessGrant, RepositoryOptions, RepositoryRole, Session, SessionStore, StateStore, StrongRef, UpdateResult, ValidationResult };
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import { JoseKey, NodeOAuthClient } from '@atproto/oauth-client-node';
2
2
  import { Lexicons } from '@atproto/lexicon';
3
- import { Agent } from '@atproto/api';
4
3
  import { HYPERCERT_COLLECTIONS, HYPERCERT_LEXICONS } from '@hypercerts-org/lexicon';
5
4
  export { AppCertifiedLocation, ComAtprotoRepoStrongRef, HYPERCERT_COLLECTIONS, HYPERCERT_LEXICONS, OrgHypercertsClaim, OrgHypercertsClaimContribution, OrgHypercertsClaimEvaluation, OrgHypercertsClaimEvidence, OrgHypercertsClaimMeasurement, OrgHypercertsClaimRights, OrgHypercertsCollection, ids, lexicons, schemaDict, schemas, validate } from '@hypercerts-org/lexicon';
5
+ import { Agent } from '@atproto/api';
6
6
  import { EventEmitter } from 'eventemitter3';
7
7
  import { z } from 'zod';
8
8
 
@@ -1245,6 +1245,80 @@ class LexiconRegistry {
1245
1245
  }
1246
1246
  }
1247
1247
 
1248
+ /**
1249
+ * ConfigurableAgent - Agent with configurable service URL routing.
1250
+ *
1251
+ * This module provides an Agent extension that allows routing requests to
1252
+ * a specific server URL, overriding the default URL from the OAuth session.
1253
+ *
1254
+ * @packageDocumentation
1255
+ */
1256
+ /**
1257
+ * Agent subclass that routes requests to a configurable service URL.
1258
+ *
1259
+ * The standard Agent uses the service URL embedded in the OAuth session's
1260
+ * fetch handler. This class allows overriding that URL to route requests
1261
+ * to different servers (e.g., PDS vs SDS, or multiple SDS instances).
1262
+ *
1263
+ * @remarks
1264
+ * This is particularly useful for:
1265
+ * - Routing to a Shared Data Server (SDS) while authenticated via PDS
1266
+ * - Supporting multiple SDS instances for different organizations
1267
+ * - Testing against different server environments
1268
+ *
1269
+ * @example Basic usage
1270
+ * ```typescript
1271
+ * const session = await sdk.authorize("user.bsky.social");
1272
+ *
1273
+ * // Create agent routing to SDS instead of session's default PDS
1274
+ * const sdsAgent = new ConfigurableAgent(session, "https://sds.hypercerts.org");
1275
+ *
1276
+ * // All requests will now go to the SDS
1277
+ * await sdsAgent.com.atproto.repo.createRecord({...});
1278
+ * ```
1279
+ *
1280
+ * @example Multiple SDS instances
1281
+ * ```typescript
1282
+ * // Route to organization A's SDS
1283
+ * const orgAAgent = new ConfigurableAgent(session, "https://sds-org-a.example.com");
1284
+ *
1285
+ * // Route to organization B's SDS
1286
+ * const orgBAgent = new ConfigurableAgent(session, "https://sds-org-b.example.com");
1287
+ * ```
1288
+ */
1289
+ class ConfigurableAgent extends Agent {
1290
+ /**
1291
+ * Creates a ConfigurableAgent that routes to a specific service URL.
1292
+ *
1293
+ * @param session - OAuth session for authentication
1294
+ * @param serviceUrl - Base URL of the server to route requests to
1295
+ *
1296
+ * @remarks
1297
+ * The agent wraps the session's fetch handler to intercept requests and
1298
+ * prepend the custom service URL instead of using the session's default.
1299
+ */
1300
+ constructor(session, serviceUrl) {
1301
+ // Create a custom fetch handler that uses our service URL
1302
+ const customFetchHandler = async (pathname, init) => {
1303
+ // Construct the full URL with our custom service
1304
+ const url = new URL(pathname, serviceUrl).toString();
1305
+ // Use the session's fetch handler for authentication (DPoP, etc.)
1306
+ return session.fetchHandler(url, init);
1307
+ };
1308
+ // Initialize the parent Agent with our custom fetch handler
1309
+ super(customFetchHandler);
1310
+ this.customServiceUrl = serviceUrl;
1311
+ }
1312
+ /**
1313
+ * Gets the service URL this agent routes to.
1314
+ *
1315
+ * @returns The base URL of the configured service
1316
+ */
1317
+ getServiceUrl() {
1318
+ return this.customServiceUrl;
1319
+ }
1320
+ }
1321
+
1248
1322
  /**
1249
1323
  * RecordOperationsImpl - Low-level record CRUD operations.
1250
1324
  *
@@ -3118,23 +3192,24 @@ class CollaboratorOperationsImpl {
3118
3192
  return "viewer";
3119
3193
  }
3120
3194
  /**
3121
- * Converts a permission string array to a permissions object.
3195
+ * Normalizes permissions from SDS API format to SDK format.
3122
3196
  *
3123
- * The SDS API returns permissions as an array of strings (e.g., ["read", "create"]).
3124
- * This method converts them to the boolean flag format used by the SDK.
3197
+ * The SDS API returns permissions as an object with boolean flags
3198
+ * (e.g., `{ read: true, create: true, update: false, ... }`).
3199
+ * This method ensures all expected fields are present with default values.
3125
3200
  *
3126
- * @param permissionArray - Array of permission strings from SDS API
3127
- * @returns Permission flags object
3201
+ * @param permissions - Permissions object from SDS API
3202
+ * @returns Normalized permission flags object
3128
3203
  * @internal
3129
3204
  */
3130
- parsePermissions(permissionArray) {
3205
+ parsePermissions(permissions) {
3131
3206
  return {
3132
- read: permissionArray.includes("read"),
3133
- create: permissionArray.includes("create"),
3134
- update: permissionArray.includes("update"),
3135
- delete: permissionArray.includes("delete"),
3136
- admin: permissionArray.includes("admin"),
3137
- owner: permissionArray.includes("owner"),
3207
+ read: permissions.read ?? false,
3208
+ create: permissions.create ?? false,
3209
+ update: permissions.update ?? false,
3210
+ delete: permissions.delete ?? false,
3211
+ admin: permissions.admin ?? false,
3212
+ owner: permissions.owner ?? false,
3138
3213
  };
3139
3214
  }
3140
3215
  /**
@@ -3770,8 +3845,10 @@ class Repository {
3770
3845
  this.lexiconRegistry = lexiconRegistry;
3771
3846
  this._isSDS = isSDS;
3772
3847
  this.logger = logger;
3773
- // Create Agent with OAuth session
3774
- this.agent = new Agent(session);
3848
+ // Create a ConfigurableAgent that routes requests to the specified server URL
3849
+ // This allows routing to PDS, SDS, or any custom server while maintaining
3850
+ // the OAuth session's authentication
3851
+ this.agent = new ConfigurableAgent(session, serverUrl);
3775
3852
  this.lexiconRegistry.addToAgent(this.agent);
3776
3853
  // Register hypercert lexicons
3777
3854
  this.lexiconRegistry.registerMany(HYPERCERT_LEXICONS);
@@ -4621,5 +4698,5 @@ const CollaboratorSchema = z.object({
4621
4698
  revokedAt: z.string().optional(),
4622
4699
  });
4623
4700
 
4624
- export { ATProtoSDK, ATProtoSDKConfigSchema, ATProtoSDKError, AuthenticationError, CollaboratorPermissionsSchema, CollaboratorSchema, InMemorySessionStore, InMemoryStateStore, LexiconRegistry, NetworkError, OAuthConfigSchema, OrganizationSchema, Repository, SDSRequiredError, ServerConfigSchema, SessionExpiredError, TimeoutConfigSchema, ValidationError, createATProtoSDK };
4701
+ export { ATProtoSDK, ATProtoSDKConfigSchema, ATProtoSDKError, AuthenticationError, CollaboratorPermissionsSchema, CollaboratorSchema, ConfigurableAgent, InMemorySessionStore, InMemoryStateStore, LexiconRegistry, NetworkError, OAuthConfigSchema, OrganizationSchema, Repository, SDSRequiredError, ServerConfigSchema, SessionExpiredError, TimeoutConfigSchema, ValidationError, createATProtoSDK };
4625
4702
  //# sourceMappingURL=index.mjs.map