Async HttpAgent and call response changes
Some small but backwards incompatible changes come with this release, but it enables some advanced use cases for libraries building with the HttpAgent.
Change 1 - HttpAgent constructor deprecation
The HttpAgent has a TSDoc warning against being constructed with the new
constructor. We now prefer await HttpAgent.create()
, which will automatically fetch the root key if you pass shouldFetchRootKey: true
(for local development) to the HttpAgentOptions. HttpAgent.create
will also automatically run the syncTime
method, and configure the agent to calculate the difference between the system clock and the Internet Computer replica’s time, which should reduce the occurrence of device sync issues. Since not all of your code may run inside of an async
function, you can consider running a simple find and replace when upgrading to > v2.0.0.
The createSync
method has identical behavior to new
currently, and is preferred over accessing the constructor going forward.
function getActor(options){
- return new HttpAgent(options);
+ return HttpAgent.createSync(options);
}
Change 2 - Raw Call
In order to support ICRC-49, we need the HttpAgent to provide more details back after making a call. With this change, HttpAgent.call
will provide:
requestId - the computed request ID to poll for
response - the raw `http` response from the boundary node
requestDetails - the details sent to the canister, used to compute the request ID
In addition, the output from pollForResponse
needs to be updated as well. PollForResponse now returns
certificate: the Certificate tree sent along with the reply
reply: the certified response from the replica
[!NOTE]
The v2 Actor is able to use olderHttpAgent
interfaces with backwards compatibility, but thepollForResponse
type has a breaking return signature. You must use a v1 polling strategy with a v1 actor, and a v2 strategy with a v2 actor.
What’s Changed
- ci: npm cache and cypress action by @krpeacock in ci: npm cache and cypress action by krpeacock · Pull Request #897 · dfinity/agent-js · GitHub
- ci: fix cypress by @krpeacock in ci: fix cypress by krpeacock · Pull Request #898 · dfinity/agent-js · GitHub
- ci: removing headless browser tests pending a rewrite by @krpeacock in ci: removing headless browser tests pending a rewrite by krpeacock · Pull Request #900 · dfinity/agent-js · GitHub
- feat!: support getting certificate back from call by @krpeacock in feat!: support getting certificate back from call by krpeacock · Pull Request #892 · dfinity/agent-js · GitHub
- feat: deprecate
HttpAgent
constructor in favor of newcreate
by @krpeacock in feat: deprecate `HttpAgent` constructor in favor of new `create` by krpeacock · Pull Request #873 · dfinity/agent-js · GitHub - chore: v1 agent compatibility with v2 actor tests by @krpeacock in chore: v1 agent compatibility with v2 actor tests by krpeacock · Pull Request #902 · dfinity/agent-js · GitHub
- ci: changing github token for creating release by @krpeacock in ci: changing github token for creating release by krpeacock · Pull Request #903 · dfinity/agent-js · GitHub
Full Changelog: Comparing v1.4.0...v2.0.0 · dfinity/agent-js · GitHub
Release Notes: Release Release 2.0.0 · dfinity/agent-js · GitHub