@hypercerts-org/sdk-core 0.6.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.
- package/README.md +130 -8
- package/dist/index.cjs +80 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +64 -1
- package/dist/index.mjs +80 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
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
|
*
|
|
@@ -3771,11 +3845,10 @@ class Repository {
|
|
|
3771
3845
|
this.lexiconRegistry = lexiconRegistry;
|
|
3772
3846
|
this._isSDS = isSDS;
|
|
3773
3847
|
this.logger = logger;
|
|
3774
|
-
// Create
|
|
3775
|
-
|
|
3776
|
-
//
|
|
3777
|
-
|
|
3778
|
-
this.agent.api.xrpc.uri = new URL(serverUrl);
|
|
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);
|
|
3779
3852
|
this.lexiconRegistry.addToAgent(this.agent);
|
|
3780
3853
|
// Register hypercert lexicons
|
|
3781
3854
|
this.lexiconRegistry.registerMany(HYPERCERT_LEXICONS);
|
|
@@ -4625,5 +4698,5 @@ const CollaboratorSchema = z.object({
|
|
|
4625
4698
|
revokedAt: z.string().optional(),
|
|
4626
4699
|
});
|
|
4627
4700
|
|
|
4628
|
-
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 };
|
|
4629
4702
|
//# sourceMappingURL=index.mjs.map
|