Socket
Socket
Sign inDemoInstall

@dfinity/agent

Package Overview
Dependencies
Maintainers
10
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dfinity/agent - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

lib/cjs/polling/backoff.d.ts

7

lib/cjs/agent/http/index.d.ts

@@ -9,2 +9,3 @@ import { JsonObject } from '@dfinity/candid';

import { ObservableLog } from '../../observable';
import { BackoffStrategyFactory } from '../../polling/backoff';
export * from './transforms';

@@ -52,2 +53,6 @@ export { Nonce, makeNonce } from './types';

/**
* The strategy to use for backoff when retrying requests
*/
backoffStrategy?: BackoffStrategyFactory;
/**
* Whether the agent should verify signatures signed by node keys on query responses. Increases security, but adds overhead and must make a separate request to cache the node keys for the canister's subnet.

@@ -73,3 +78,2 @@ * @default true

private _rootKeyFetched;
private readonly _retryTimes;
readonly _isAgent = true;

@@ -87,3 +91,2 @@ get waterMark(): number;

}, identity?: Identity | Promise<Identity>): Promise<SubmitResponse>;
private _requestAndRetry;
query(canisterId: Principal | string, fields: QueryFields, identity?: Identity | Promise<Identity>): Promise<ApiQueryResponse>;

@@ -90,0 +93,0 @@ createReadStateRequest(fields: ReadStateOptions, identity?: Identity | Promise<Identity>): Promise<any>;

@@ -39,3 +39,3 @@ "use strict";

};
var _HttpAgent_instances, _HttpAgent_waterMark, _HttpAgent_queryPipeline, _HttpAgent_updatePipeline, _HttpAgent_subnetKeys, _HttpAgent_verifyQuerySignatures, _HttpAgent_requestAndRetryQuery, _HttpAgent_verifyQueryResponse;
var _HttpAgent_instances, _HttpAgent_retryTimes, _HttpAgent_backoffStrategy, _HttpAgent_waterMark, _HttpAgent_queryPipeline, _HttpAgent_updatePipeline, _HttpAgent_subnetKeys, _HttpAgent_verifyQuerySignatures, _HttpAgent_requestAndRetryQuery, _HttpAgent_requestAndRetry, _HttpAgent_verifyQueryResponse;
Object.defineProperty(exports, "__esModule", { value: true });

@@ -59,2 +59,3 @@ exports.HttpAgent = exports.IdentityInvalidError = exports.MANAGEMENT_CANISTER_ID = exports.IC_ROOT_KEY = exports.RequestStatusResponseStatus = exports.makeNonce = void 0;

const observable_1 = require("../../observable");
const backoff_1 = require("../../polling/backoff");
__exportStar(require("./transforms"), exports);

@@ -146,2 +147,4 @@ var types_2 = require("./types");

this._rootKeyFetched = false;
_HttpAgent_retryTimes.set(this, void 0); // Retry requests N times before erroring by default
_HttpAgent_backoffStrategy.set(this, void 0);
this._isAgent = true;

@@ -273,3 +276,8 @@ // The UTC time in milliseconds when the latest request was made

// Default is 3
this._retryTimes = (_a = options.retryTimes) !== null && _a !== void 0 ? _a : 3;
__classPrivateFieldSet(this, _HttpAgent_retryTimes, (_a = options.retryTimes) !== null && _a !== void 0 ? _a : 3, "f");
// Delay strategy for retries. Default is exponential backoff
const defaultBackoffFactory = () => new backoff_1.ExponentialBackoff({
maxIterations: __classPrivateFieldGet(this, _HttpAgent_retryTimes, "f"),
});
__classPrivateFieldSet(this, _HttpAgent_backoffStrategy, options.backoffStrategy || defaultBackoffFactory, "f");
// Rewrite to avoid redirects

@@ -373,3 +381,8 @@ if (this._host.hostname.endsWith(IC0_SUB_DOMAIN)) {

// calculate the requestId locally.
const request = this._requestAndRetry(() => this._fetch('' + new URL(`/api/v2/canister/${ecid.toText()}/call`, this._host), Object.assign(Object.assign(Object.assign({}, this._callOptions), transformedRequest.request), { body })));
const backoff = __classPrivateFieldGet(this, _HttpAgent_backoffStrategy, "f").call(this);
const request = __classPrivateFieldGet(this, _HttpAgent_instances, "m", _HttpAgent_requestAndRetry).call(this, {
request: () => this._fetch('' + new URL(`/api/v2/canister/${ecid.toText()}/call`, this._host), Object.assign(Object.assign(Object.assign({}, this._callOptions), transformedRequest.request), { body })),
backoff,
tries: 0,
});
const [response, requestId] = await Promise.all([request, (0, request_id_1.requestIdOf)(submit)]);

@@ -389,35 +402,4 @@ const responseBuffer = await response.arrayBuffer();

}
async _requestAndRetry(request, tries = 0) {
let response;
try {
response = await request();
}
catch (error) {
if (this._retryTimes > tries) {
this.log.warn(`Caught exception while attempting to make request:\n` +
` ${error}\n` +
` Retrying request.`);
return await this._requestAndRetry(request, tries + 1);
}
throw error;
}
if (response.ok) {
return response;
}
const responseText = await response.clone().text();
const errorMessage = `Server returned an error:\n` +
` Code: ${response.status} (${response.statusText})\n` +
` Body: ${responseText}\n`;
if (this._retryTimes > tries) {
this.log.warn(errorMessage + ` Retrying request.`);
return await this._requestAndRetry(request, tries + 1);
}
throw new errors_2.AgentHTTPResponseError(errorMessage, {
ok: response.ok,
status: response.status,
statusText: response.statusText,
headers: (0, transforms_1.httpHeadersTransform)(response.headers),
});
}
async query(canisterId, fields, identity) {
const backoff = __classPrivateFieldGet(this, _HttpAgent_backoffStrategy, "f").call(this);
const ecid = fields.effectiveCanisterId

@@ -463,2 +445,4 @@ ? principal_1.Principal.from(fields.effectiveCanisterId)

requestId,
backoff,
tries: 0,
};

@@ -479,3 +463,2 @@ return await __classPrivateFieldGet(this, _HttpAgent_instances, "m", _HttpAgent_requestAndRetryQuery).call(this, args);

// Attempt to make the query i=retryTimes times
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// Make query and fetch subnet keys in parallel

@@ -535,3 +518,8 @@ const [query, subnetStatus] = await Promise.all([makeQuery(), getSubnetStatus()]);

// TODO - https://dfinity.atlassian.net/browse/SDK-1092
const response = await this._requestAndRetry(() => this._fetch('' + new URL(`/api/v2/canister/${canister}/read_state`, this._host), Object.assign(Object.assign(Object.assign({}, this._fetchOptions), transformedRequest.request), { body })));
const backoff = __classPrivateFieldGet(this, _HttpAgent_backoffStrategy, "f").call(this);
const response = await __classPrivateFieldGet(this, _HttpAgent_instances, "m", _HttpAgent_requestAndRetry).call(this, {
request: () => this._fetch('' + new URL(`/api/v2/canister/${canister.toString()}/read_state`, this._host), Object.assign(Object.assign(Object.assign({}, this._fetchOptions), transformedRequest.request), { body })),
backoff,
tries: 0,
});
if (!response.ok) {

@@ -611,3 +599,8 @@ throw new Error(`Server returned an error:\n` +

this.log(`fetching "/api/v2/status"`);
const response = await this._requestAndRetry(() => this._fetch('' + new URL(`/api/v2/status`, this._host), Object.assign({ headers }, this._fetchOptions)));
const backoff = __classPrivateFieldGet(this, _HttpAgent_backoffStrategy, "f").call(this);
const response = await __classPrivateFieldGet(this, _HttpAgent_instances, "m", _HttpAgent_requestAndRetry).call(this, {
backoff,
request: () => this._fetch('' + new URL(`/api/v2/status`, this._host), Object.assign({ headers }, this._fetchOptions)),
tries: 0,
});
return cbor.decode(await response.arrayBuffer());

@@ -660,8 +653,22 @@ }

exports.HttpAgent = HttpAgent;
_HttpAgent_waterMark = new WeakMap(), _HttpAgent_queryPipeline = new WeakMap(), _HttpAgent_updatePipeline = new WeakMap(), _HttpAgent_subnetKeys = new WeakMap(), _HttpAgent_verifyQuerySignatures = new WeakMap(), _HttpAgent_verifyQueryResponse = new WeakMap(), _HttpAgent_instances = new WeakSet(), _HttpAgent_requestAndRetryQuery = async function _HttpAgent_requestAndRetryQuery(args, tries = 0) {
_HttpAgent_retryTimes = new WeakMap(), _HttpAgent_backoffStrategy = new WeakMap(), _HttpAgent_waterMark = new WeakMap(), _HttpAgent_queryPipeline = new WeakMap(), _HttpAgent_updatePipeline = new WeakMap(), _HttpAgent_subnetKeys = new WeakMap(), _HttpAgent_verifyQuerySignatures = new WeakMap(), _HttpAgent_verifyQueryResponse = new WeakMap(), _HttpAgent_instances = new WeakSet(), _HttpAgent_requestAndRetryQuery = async function _HttpAgent_requestAndRetryQuery(args) {
var _a, _b;
const { ecid, transformedRequest, body, requestId } = args;
const { ecid, transformedRequest, body, requestId, backoff, tries } = args;
const delay = tries === 0 ? 0 : backoff.next();
this.log(`fetching "/api/v2/canister/${ecid.toString()}/query" with tries:`, {
tries,
backoff,
delay,
});
// If delay is null, the backoff strategy is exhausted due to a maximum number of retries, duration, or other reason
if (delay === null) {
throw new errors_1.AgentError(`Timestamp failed to pass the watermark after retrying the configured ${__classPrivateFieldGet(this, _HttpAgent_retryTimes, "f")} times. We cannot guarantee the integrity of the response since it could be a replay attack.`);
}
if (delay > 0) {
await new Promise(resolve => setTimeout(resolve, delay));
}
let response;
// Make the request and retry if it throws an error
try {
this.log(`fetching "/api/v2/canister/${ecid.toString()}/query" with request:`, transformedRequest);
const fetchResponse = await this._fetch('' + new URL(`/api/v2/canister/${ecid.toString()}/query`, this._host), Object.assign(Object.assign(Object.assign({}, this._fetchOptions), transformedRequest.request), { body }));

@@ -689,7 +696,7 @@ if (fetchResponse.status === 200) {

catch (error) {
if (tries < this._retryTimes) {
if (tries < __classPrivateFieldGet(this, _HttpAgent_retryTimes, "f")) {
this.log.warn(`Caught exception while attempting to make query:\n` +
` ${error}\n` +
` Retrying query.`);
return await __classPrivateFieldGet(this, _HttpAgent_instances, "m", _HttpAgent_requestAndRetryQuery).call(this, args, tries + 1);
return await __classPrivateFieldGet(this, _HttpAgent_instances, "m", _HttpAgent_requestAndRetryQuery).call(this, Object.assign(Object.assign({}, args), { tries: tries + 1 }));
}

@@ -719,11 +726,51 @@ throw error;

});
if (tries < this._retryTimes) {
return await __classPrivateFieldGet(this, _HttpAgent_instances, "m", _HttpAgent_requestAndRetryQuery).call(this, args, tries + 1);
if (tries < __classPrivateFieldGet(this, _HttpAgent_retryTimes, "f")) {
return await __classPrivateFieldGet(this, _HttpAgent_instances, "m", _HttpAgent_requestAndRetryQuery).call(this, Object.assign(Object.assign({}, args), { tries: tries + 1 }));
}
{
throw new errors_1.AgentError(`Timestamp failed to pass the watermark after retrying the configured ${this._retryTimes} times. We cannot guarantee the integrity of the response since it could be a replay attack.`);
throw new errors_1.AgentError(`Timestamp failed to pass the watermark after retrying the configured ${__classPrivateFieldGet(this, _HttpAgent_retryTimes, "f")} times. We cannot guarantee the integrity of the response since it could be a replay attack.`);
}
}
return response;
}, _HttpAgent_requestAndRetry = async function _HttpAgent_requestAndRetry(args) {
const { request, backoff, tries } = args;
const delay = tries === 0 ? 0 : backoff.next();
// If delay is null, the backoff strategy is exhausted due to a maximum number of retries, duration, or other reason
if (delay === null) {
throw new errors_1.AgentError(`Timestamp failed to pass the watermark after retrying the configured ${__classPrivateFieldGet(this, _HttpAgent_retryTimes, "f")} times. We cannot guarantee the integrity of the response since it could be a replay attack.`);
}
if (delay > 0) {
await new Promise(resolve => setTimeout(resolve, delay));
}
let response;
try {
response = await request();
}
catch (error) {
if (__classPrivateFieldGet(this, _HttpAgent_retryTimes, "f") > tries) {
this.log.warn(`Caught exception while attempting to make request:\n` +
` ${error}\n` +
` Retrying request.`);
// Delay the request by the configured backoff strategy
return await __classPrivateFieldGet(this, _HttpAgent_instances, "m", _HttpAgent_requestAndRetry).call(this, { request, backoff, tries: tries + 1 });
}
throw error;
}
if (response.ok) {
return response;
}
const responseText = await response.clone().text();
const errorMessage = `Server returned an error:\n` +
` Code: ${response.status} (${response.statusText})\n` +
` Body: ${responseText}\n`;
if (tries < __classPrivateFieldGet(this, _HttpAgent_retryTimes, "f")) {
return await __classPrivateFieldGet(this, _HttpAgent_instances, "m", _HttpAgent_requestAndRetry).call(this, { request, backoff, tries: tries + 1 });
}
throw new errors_2.AgentHTTPResponseError(errorMessage, {
ok: response.ok,
status: response.status,
statusText: response.statusText,
headers: (0, transforms_1.httpHeadersTransform)(response.headers),
});
};
//# sourceMappingURL=index.js.map

@@ -17,3 +17,4 @@ import { Principal } from '@dfinity/principal';

* @param request Request for the readState call.
* @param blsVerify - optional replacement function that verifies the BLS signature of a certificate.
*/
export declare function pollForResponse(agent: Agent, canisterId: Principal, requestId: RequestId, strategy: PollStrategy, request?: any, blsVerify?: CreateCertificateOptions['blsVerify']): Promise<ArrayBuffer>;

@@ -41,2 +41,3 @@ "use strict";

* @param request Request for the readState call.
* @param blsVerify - optional replacement function that verifies the BLS signature of a certificate.
*/

@@ -43,0 +44,0 @@ async function pollForResponse(agent, canisterId, requestId, strategy,

@@ -9,2 +9,3 @@ import { JsonObject } from '@dfinity/candid';

import { ObservableLog } from '../../observable';
import { BackoffStrategyFactory } from '../../polling/backoff';
export * from './transforms';

@@ -52,2 +53,6 @@ export { Nonce, makeNonce } from './types';

/**
* The strategy to use for backoff when retrying requests
*/
backoffStrategy?: BackoffStrategyFactory;
/**
* Whether the agent should verify signatures signed by node keys on query responses. Increases security, but adds overhead and must make a separate request to cache the node keys for the canister's subnet.

@@ -73,3 +78,2 @@ * @default true

private _rootKeyFetched;
private readonly _retryTimes;
readonly _isAgent = true;

@@ -87,3 +91,2 @@ get waterMark(): number;

}, identity?: Identity | Promise<Identity>): Promise<SubmitResponse>;
private _requestAndRetry;
query(canisterId: Principal | string, fields: QueryFields, identity?: Identity | Promise<Identity>): Promise<ApiQueryResponse>;

@@ -90,0 +93,0 @@ createReadStateRequest(fields: ReadStateOptions, identity?: Identity | Promise<Identity>): Promise<any>;

@@ -12,3 +12,3 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {

};
var _HttpAgent_instances, _HttpAgent_waterMark, _HttpAgent_queryPipeline, _HttpAgent_updatePipeline, _HttpAgent_subnetKeys, _HttpAgent_verifyQuerySignatures, _HttpAgent_requestAndRetryQuery, _HttpAgent_verifyQueryResponse;
var _HttpAgent_instances, _HttpAgent_retryTimes, _HttpAgent_backoffStrategy, _HttpAgent_waterMark, _HttpAgent_queryPipeline, _HttpAgent_updatePipeline, _HttpAgent_subnetKeys, _HttpAgent_verifyQuerySignatures, _HttpAgent_requestAndRetryQuery, _HttpAgent_requestAndRetry, _HttpAgent_verifyQueryResponse;
import { Principal } from '@dfinity/principal';

@@ -30,2 +30,3 @@ import { AgentError } from '../../errors';

import { ObservableLog } from '../../observable';
import { ExponentialBackoff } from '../../polling/backoff';
export * from './transforms';

@@ -115,2 +116,4 @@ export { makeNonce } from './types';

this._rootKeyFetched = false;
_HttpAgent_retryTimes.set(this, void 0); // Retry requests N times before erroring by default
_HttpAgent_backoffStrategy.set(this, void 0);
this._isAgent = true;

@@ -242,3 +245,8 @@ // The UTC time in milliseconds when the latest request was made

// Default is 3
this._retryTimes = (_a = options.retryTimes) !== null && _a !== void 0 ? _a : 3;
__classPrivateFieldSet(this, _HttpAgent_retryTimes, (_a = options.retryTimes) !== null && _a !== void 0 ? _a : 3, "f");
// Delay strategy for retries. Default is exponential backoff
const defaultBackoffFactory = () => new ExponentialBackoff({
maxIterations: __classPrivateFieldGet(this, _HttpAgent_retryTimes, "f"),
});
__classPrivateFieldSet(this, _HttpAgent_backoffStrategy, options.backoffStrategy || defaultBackoffFactory, "f");
// Rewrite to avoid redirects

@@ -342,3 +350,8 @@ if (this._host.hostname.endsWith(IC0_SUB_DOMAIN)) {

// calculate the requestId locally.
const request = this._requestAndRetry(() => this._fetch('' + new URL(`/api/v2/canister/${ecid.toText()}/call`, this._host), Object.assign(Object.assign(Object.assign({}, this._callOptions), transformedRequest.request), { body })));
const backoff = __classPrivateFieldGet(this, _HttpAgent_backoffStrategy, "f").call(this);
const request = __classPrivateFieldGet(this, _HttpAgent_instances, "m", _HttpAgent_requestAndRetry).call(this, {
request: () => this._fetch('' + new URL(`/api/v2/canister/${ecid.toText()}/call`, this._host), Object.assign(Object.assign(Object.assign({}, this._callOptions), transformedRequest.request), { body })),
backoff,
tries: 0,
});
const [response, requestId] = await Promise.all([request, requestIdOf(submit)]);

@@ -358,35 +371,4 @@ const responseBuffer = await response.arrayBuffer();

}
async _requestAndRetry(request, tries = 0) {
let response;
try {
response = await request();
}
catch (error) {
if (this._retryTimes > tries) {
this.log.warn(`Caught exception while attempting to make request:\n` +
` ${error}\n` +
` Retrying request.`);
return await this._requestAndRetry(request, tries + 1);
}
throw error;
}
if (response.ok) {
return response;
}
const responseText = await response.clone().text();
const errorMessage = `Server returned an error:\n` +
` Code: ${response.status} (${response.statusText})\n` +
` Body: ${responseText}\n`;
if (this._retryTimes > tries) {
this.log.warn(errorMessage + ` Retrying request.`);
return await this._requestAndRetry(request, tries + 1);
}
throw new AgentHTTPResponseError(errorMessage, {
ok: response.ok,
status: response.status,
statusText: response.statusText,
headers: httpHeadersTransform(response.headers),
});
}
async query(canisterId, fields, identity) {
const backoff = __classPrivateFieldGet(this, _HttpAgent_backoffStrategy, "f").call(this);
const ecid = fields.effectiveCanisterId

@@ -432,2 +414,4 @@ ? Principal.from(fields.effectiveCanisterId)

requestId,
backoff,
tries: 0,
};

@@ -448,3 +432,2 @@ return await __classPrivateFieldGet(this, _HttpAgent_instances, "m", _HttpAgent_requestAndRetryQuery).call(this, args);

// Attempt to make the query i=retryTimes times
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// Make query and fetch subnet keys in parallel

@@ -504,3 +487,8 @@ const [query, subnetStatus] = await Promise.all([makeQuery(), getSubnetStatus()]);

// TODO - https://dfinity.atlassian.net/browse/SDK-1092
const response = await this._requestAndRetry(() => this._fetch('' + new URL(`/api/v2/canister/${canister}/read_state`, this._host), Object.assign(Object.assign(Object.assign({}, this._fetchOptions), transformedRequest.request), { body })));
const backoff = __classPrivateFieldGet(this, _HttpAgent_backoffStrategy, "f").call(this);
const response = await __classPrivateFieldGet(this, _HttpAgent_instances, "m", _HttpAgent_requestAndRetry).call(this, {
request: () => this._fetch('' + new URL(`/api/v2/canister/${canister.toString()}/read_state`, this._host), Object.assign(Object.assign(Object.assign({}, this._fetchOptions), transformedRequest.request), { body })),
backoff,
tries: 0,
});
if (!response.ok) {

@@ -580,3 +568,8 @@ throw new Error(`Server returned an error:\n` +

this.log(`fetching "/api/v2/status"`);
const response = await this._requestAndRetry(() => this._fetch('' + new URL(`/api/v2/status`, this._host), Object.assign({ headers }, this._fetchOptions)));
const backoff = __classPrivateFieldGet(this, _HttpAgent_backoffStrategy, "f").call(this);
const response = await __classPrivateFieldGet(this, _HttpAgent_instances, "m", _HttpAgent_requestAndRetry).call(this, {
backoff,
request: () => this._fetch('' + new URL(`/api/v2/status`, this._host), Object.assign({ headers }, this._fetchOptions)),
tries: 0,
});
return cbor.decode(await response.arrayBuffer());

@@ -628,8 +621,22 @@ }

}
_HttpAgent_waterMark = new WeakMap(), _HttpAgent_queryPipeline = new WeakMap(), _HttpAgent_updatePipeline = new WeakMap(), _HttpAgent_subnetKeys = new WeakMap(), _HttpAgent_verifyQuerySignatures = new WeakMap(), _HttpAgent_verifyQueryResponse = new WeakMap(), _HttpAgent_instances = new WeakSet(), _HttpAgent_requestAndRetryQuery = async function _HttpAgent_requestAndRetryQuery(args, tries = 0) {
_HttpAgent_retryTimes = new WeakMap(), _HttpAgent_backoffStrategy = new WeakMap(), _HttpAgent_waterMark = new WeakMap(), _HttpAgent_queryPipeline = new WeakMap(), _HttpAgent_updatePipeline = new WeakMap(), _HttpAgent_subnetKeys = new WeakMap(), _HttpAgent_verifyQuerySignatures = new WeakMap(), _HttpAgent_verifyQueryResponse = new WeakMap(), _HttpAgent_instances = new WeakSet(), _HttpAgent_requestAndRetryQuery = async function _HttpAgent_requestAndRetryQuery(args) {
var _a, _b;
const { ecid, transformedRequest, body, requestId } = args;
const { ecid, transformedRequest, body, requestId, backoff, tries } = args;
const delay = tries === 0 ? 0 : backoff.next();
this.log(`fetching "/api/v2/canister/${ecid.toString()}/query" with tries:`, {
tries,
backoff,
delay,
});
// If delay is null, the backoff strategy is exhausted due to a maximum number of retries, duration, or other reason
if (delay === null) {
throw new AgentError(`Timestamp failed to pass the watermark after retrying the configured ${__classPrivateFieldGet(this, _HttpAgent_retryTimes, "f")} times. We cannot guarantee the integrity of the response since it could be a replay attack.`);
}
if (delay > 0) {
await new Promise(resolve => setTimeout(resolve, delay));
}
let response;
// Make the request and retry if it throws an error
try {
this.log(`fetching "/api/v2/canister/${ecid.toString()}/query" with request:`, transformedRequest);
const fetchResponse = await this._fetch('' + new URL(`/api/v2/canister/${ecid.toString()}/query`, this._host), Object.assign(Object.assign(Object.assign({}, this._fetchOptions), transformedRequest.request), { body }));

@@ -657,7 +664,7 @@ if (fetchResponse.status === 200) {

catch (error) {
if (tries < this._retryTimes) {
if (tries < __classPrivateFieldGet(this, _HttpAgent_retryTimes, "f")) {
this.log.warn(`Caught exception while attempting to make query:\n` +
` ${error}\n` +
` Retrying query.`);
return await __classPrivateFieldGet(this, _HttpAgent_instances, "m", _HttpAgent_requestAndRetryQuery).call(this, args, tries + 1);
return await __classPrivateFieldGet(this, _HttpAgent_instances, "m", _HttpAgent_requestAndRetryQuery).call(this, Object.assign(Object.assign({}, args), { tries: tries + 1 }));
}

@@ -687,11 +694,51 @@ throw error;

});
if (tries < this._retryTimes) {
return await __classPrivateFieldGet(this, _HttpAgent_instances, "m", _HttpAgent_requestAndRetryQuery).call(this, args, tries + 1);
if (tries < __classPrivateFieldGet(this, _HttpAgent_retryTimes, "f")) {
return await __classPrivateFieldGet(this, _HttpAgent_instances, "m", _HttpAgent_requestAndRetryQuery).call(this, Object.assign(Object.assign({}, args), { tries: tries + 1 }));
}
{
throw new AgentError(`Timestamp failed to pass the watermark after retrying the configured ${this._retryTimes} times. We cannot guarantee the integrity of the response since it could be a replay attack.`);
throw new AgentError(`Timestamp failed to pass the watermark after retrying the configured ${__classPrivateFieldGet(this, _HttpAgent_retryTimes, "f")} times. We cannot guarantee the integrity of the response since it could be a replay attack.`);
}
}
return response;
}, _HttpAgent_requestAndRetry = async function _HttpAgent_requestAndRetry(args) {
const { request, backoff, tries } = args;
const delay = tries === 0 ? 0 : backoff.next();
// If delay is null, the backoff strategy is exhausted due to a maximum number of retries, duration, or other reason
if (delay === null) {
throw new AgentError(`Timestamp failed to pass the watermark after retrying the configured ${__classPrivateFieldGet(this, _HttpAgent_retryTimes, "f")} times. We cannot guarantee the integrity of the response since it could be a replay attack.`);
}
if (delay > 0) {
await new Promise(resolve => setTimeout(resolve, delay));
}
let response;
try {
response = await request();
}
catch (error) {
if (__classPrivateFieldGet(this, _HttpAgent_retryTimes, "f") > tries) {
this.log.warn(`Caught exception while attempting to make request:\n` +
` ${error}\n` +
` Retrying request.`);
// Delay the request by the configured backoff strategy
return await __classPrivateFieldGet(this, _HttpAgent_instances, "m", _HttpAgent_requestAndRetry).call(this, { request, backoff, tries: tries + 1 });
}
throw error;
}
if (response.ok) {
return response;
}
const responseText = await response.clone().text();
const errorMessage = `Server returned an error:\n` +
` Code: ${response.status} (${response.statusText})\n` +
` Body: ${responseText}\n`;
if (tries < __classPrivateFieldGet(this, _HttpAgent_retryTimes, "f")) {
return await __classPrivateFieldGet(this, _HttpAgent_instances, "m", _HttpAgent_requestAndRetry).call(this, { request, backoff, tries: tries + 1 });
}
throw new AgentHTTPResponseError(errorMessage, {
ok: response.ok,
status: response.status,
statusText: response.statusText,
headers: httpHeadersTransform(response.headers),
});
};
//# sourceMappingURL=index.js.map

@@ -17,3 +17,4 @@ import { Principal } from '@dfinity/principal';

* @param request Request for the readState call.
* @param blsVerify - optional replacement function that verifies the BLS signature of a certificate.
*/
export declare function pollForResponse(agent: Agent, canisterId: Principal, requestId: RequestId, strategy: PollStrategy, request?: any, blsVerify?: CreateCertificateOptions['blsVerify']): Promise<ArrayBuffer>;

@@ -14,2 +14,3 @@ import { RequestStatusResponseStatus } from '../agent';

* @param request Request for the readState call.
* @param blsVerify - optional replacement function that verifies the BLS signature of a certificate.
*/

@@ -16,0 +17,0 @@ export async function pollForResponse(agent, canisterId, requestId, strategy,

{
"name": "@dfinity/agent",
"version": "1.2.1",
"version": "1.3.0",
"author": "DFINITY Stiftung <sdk@dfinity.org>",

@@ -50,4 +50,4 @@ "license": "Apache-2.0",

"peerDependencies": {
"@dfinity/candid": "^1.2.1",
"@dfinity/principal": "^1.2.1"
"@dfinity/candid": "^1.3.0",
"@dfinity/principal": "^1.3.0"
},

@@ -54,0 +54,0 @@ "dependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc