diff --git a/packages/access-client/src/agent.js b/packages/access-client/src/agent.js index e6e939ca9..c7e350159 100644 --- a/packages/access-client/src/agent.js +++ b/packages/access-client/src/agent.js @@ -28,6 +28,10 @@ export { AgentData } const HOST = 'https://access.web3.storage' const PRINCIPAL = DID.parse('did:web:web3.storage') +/** + * @typedef {import('./types').Service} Service + */ + /** * Creates a Ucanto connection for the w3access API * @@ -37,7 +41,6 @@ const PRINCIPAL = DID.parse('did:web:web3.storage') * import { connection } from '@web3-storage/access/agent' * ``` * - * @template {import('./types').Service} Service * @template {Ucanto.DID} T - DID method * @param {object} [options] * @param {Ucanto.Principal} [options.principal] - w3access API Principal @@ -79,7 +82,9 @@ export class Agent { * @param {import('./types').AgentOptions} [options] */ constructor(data, options = {}) { - this.url = options.url ?? new URL(HOST) + /** @type { Client.Channel & { url?: URL } | undefined } */ + const channel = options.connection?.channel + this.url = options.url ?? channel?.url ?? new URL(HOST) this.connection = options.connection ?? connection({