Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

## [Unreleased]

### Changed

- feat!: removes the unused `defaultAgent` global concept and the `getDefaultAgent` function. The `HttpAgent` constructor is now the only way to create an agent.
- feat!: removes the `ProxyAgent` class.

## [2.4.1] - 2025-04-10

### Changed
Expand Down
6 changes: 3 additions & 3 deletions packages/agent/src/actor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Buffer } from 'buffer/';
import {
Agent,
getDefaultAgent,
HttpDetailsResponse,
QueryResponseRejected,
QueryResponseStatus,
Expand All @@ -19,6 +18,7 @@ import { toHex } from './utils/buffer';
import { Certificate, CreateCertificateOptions, lookupResultToBuffer } from './certificate';
import managementCanisterIdl from './canisters/management_idl';
import _SERVICE, { canister_install_mode, canister_settings } from './canisters/management_service';
import { HttpAgent } from './agent/http';

export class ActorCallError extends AgentError {
constructor(
Expand Down Expand Up @@ -483,7 +483,7 @@ function _createActorMethod(
}),
};

const agent = options.agent || actor[metadataSymbol].config.agent || getDefaultAgent();
const agent = options.agent || actor[metadataSymbol].config.agent || new HttpAgent();
const cid = Principal.from(options.canisterId || actor[metadataSymbol].config.canisterId);
const arg = IDL.encode(func.argTypes, args);

Expand Down Expand Up @@ -521,7 +521,7 @@ function _createActorMethod(
}),
};

const agent = options.agent || actor[metadataSymbol].config.agent || getDefaultAgent();
const agent = options.agent || actor[metadataSymbol].config.agent || HttpAgent.createSync();
const { canisterId, effectiveCanisterId, pollingStrategyFactory } = {
...DEFAULT_ACTOR_CONFIG,
...actor[metadataSymbol].config,
Expand Down
9 changes: 2 additions & 7 deletions packages/agent/src/agent/http/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ import {
} from '../..';
import { Ed25519KeyIdentity } from '@dfinity/identity';
import { AgentError } from '../../errors';
import {
AgentCallError,
AgentHTTPResponseError,
AgentQueryError,
AgentReadStateError,
} from './errors';
import { AgentCallError, AgentQueryError, AgentReadStateError } from './errors';
const { window } = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`);
window.fetch = global.fetch;
(global as any).window = window;
Expand Down Expand Up @@ -996,7 +991,7 @@ describe('await fetching root keys before making a call to the network.', () =>
ok: true,
status: 200,
statusText: 'OK',
body: 'd9d9f7a66e69635f6170695f76657273696f6e66302e31382e3068726f6f745f6b65795885308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100a05a4707525774767f395a97ea9cd670ebf8694c4649421cdec91d86fa16beee0250e1ef64ec3b1eecb2ece53235ae0e0433592804c8947359694912cd743e5cba7d9bf705f875da3b36d12ec7eb94fb437bd31c255d2a6d65b964e0430f93686c696d706c5f76657273696f6e65302e392e3069696d706c5f68617368784064653637663631313363383031616332613738646366373962343137653030636534336136623363613663616134636661623963623665353338383136643534757265706c6963615f6865616c74685f737461747573676865616c746879706365727469666965645f6865696768741a0003f560',
body: 'd9d9f7a66e69635f6170695f76657273696f6e66302e31382e3068726f6f745f6b65795885308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100a05a4707525774767f395a97ea9cd670ebf8694c4649421cdec91d86fa16beee0250e1ef64ec3b1eecb2ece53235ae0e0433592804c8947359694912cd743e5cba7d9bf705f875da3b36d12ec7eb94fb437bd31c255d2a6d65b964e0430f93686c696d706c5f76657273696f6e65302e392e3069696d706c5f686173687840646536376636313133633830316163326137386463663739623431376530306365343361366233636136636161346366616239636236653338383136643534757265706c6963615f6865616c74685f737461747573676865616c746879706365727469666965645f6865696768741a0003f560',
now: 1737766080180,
};
jest.useFakeTimers();
Expand Down
25 changes: 0 additions & 25 deletions packages/agent/src/agent/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,3 @@
import { GlobalInternetComputer } from '../index';
import { Agent } from './api';

export * from './api';
export * from './http';
export * from './http/errors';
export * from './proxy';

declare const window: GlobalInternetComputer;
declare const global: GlobalInternetComputer;
declare const self: GlobalInternetComputer;

export function getDefaultAgent(): Agent {
const agent =
typeof window === 'undefined'
? typeof global === 'undefined'
? typeof self === 'undefined'
? undefined
: self.ic.agent
: global.ic.agent
: window.ic.agent;

if (!agent) {
throw new Error('No Agent could be found.');
}

return agent;
}
250 changes: 0 additions & 250 deletions packages/agent/src/agent/proxy.ts

This file was deleted.

36 changes: 0 additions & 36 deletions packages/agent/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ActorSubclass } from './actor';

export * from './actor';
export * from './agent';
export * from './agent/http/transforms';
Expand All @@ -26,39 +24,5 @@ export * as CanisterStatus from './canisterStatus';
* The primary method for this namespace is {@link CanisterStatus.request}
*/

import { Agent, HttpAgent } from './agent';
import { IDL } from '@dfinity/candid';

export * as Cbor from './cbor';
export * from './polling';

export interface GlobalInternetComputer {
ic: {
agent: Agent;
HttpAgent: typeof HttpAgent;
IDL: typeof IDL;
/**
* Simple advertisement of features in whoever is managing this `globalThis.ic`.
* Use Case
* - Scripts that know they need an ic feature can detect using this and, if not present
* (e.g. old bootstrap version), they can dynamically include their own and continue
* operating (e.g. polyfill).
* This is useful when adding features to bootstrap. You can still deploy your canister to
* an ic with old bootstrap, then just dynamically reload your own new-version bootstrap if
* needed.
*/
features?: {
/** This is falsy if authn isn't supported at all */
authentication?: boolean;
};
/**
* The Actor for the canister being used for the frontend. Normally should correspond to the
* canister represented by the canister id in the URL.
*
* It does not have any functions configured.
*
* If a canister ID could not be found, no actor were created and this is undefined.
*/
canister: ActorSubclass | undefined;
};
}
Loading
Loading