Agent-JS v2.0.0 is released!

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 older HttpAgent interfaces with backwards compatibility, but the pollForResponse 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

Full Changelog: Comparing v1.4.0...v2.0.0 · dfinity/agent-js · GitHub
Release Notes: Release Release 2.0.0 · dfinity/agent-js · GitHub

8 Likes

Adding to todo list: Upgrade ic-use-actor to use new version of Agent-JS. :grinning:

Changes look great!

2 Likes