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
23 changes: 9 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,18 @@
"require": "./dist/interface.js",
"default": "./dist/interface.js"
},
"./transactions": {
"types": "./dist/transactions/index.d.ts",
"import": "./dist/esm/transactions/index.js",
"require": "./dist/transactions/index.js",
"default": "./dist/transactions/index.js"
},
"./transactions/ledger": {
"types": "./dist/transactions/ledger.d.ts",
"import": "./dist/esm/transactions/ledger.js",
"require": "./dist/transactions/ledger.js",
"default": "./dist/transactions/ledger.js"
},
"./dist/*.js": {
"types": "./dist/*.d.ts",
"import": "./dist/esm/*.js",
"require": "./dist/*.js",
"default": "./dist/*.js"
},
"./dist/*": {
"types": "./dist/*.d.ts",
"import": "./dist/esm/*.js",
"require": "./dist/*.js",
"default": "./dist/*.js"
},
"./package.json": "./package.json"
},
"repository": "https://github.com/MetaNames/sdk.git",
Expand All @@ -61,14 +55,15 @@
"dist"
],
"scripts": {
"build": "yarn build:cjs && yarn build:esm",
"build": "yarn clean && yarn build:cjs && yarn build:esm",
"docs": "typedoc --out docs src",
"format": "eslint --fix src",
"test": "jest -i",
"prepublishOnly": "yarn build",
"audit-ci": "bash scripts/audit-ci.sh",
"build:cjs": "tsc",
"build:esm": "tsc -p tsconfig.esm.json && node scripts/finalize-esm.js"
"build:esm": "tsc -p tsconfig.esm.json && node scripts/finalize-esm.js",
"clean": "rm -rf dist"
},
"dependencies": {
"@ledgerhq/hw-transport": "^6.34.0",
Expand Down
20 changes: 18 additions & 2 deletions src/repositories/helpers/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,27 @@ function buildOptions(method: RequestType, headers: Record<string, string>, sign
}

export function getRequest<R>(url: string, timeoutMs = DEFAULT_TIMEOUT_MS): Promise<R | undefined> {
return handleFetch(promiseRetry(() => fetchWithTimeout(url, "GET", jsonHeaders, undefined, timeoutMs)))
return handleFetch(promiseRetry(() => request(url, "GET", jsonHeaders, undefined, timeoutMs)))
}

export function postRequest<R>(url: string, body: unknown, timeoutMs = DEFAULT_TIMEOUT_MS): Promise<R | undefined> {
return handleFetch(promiseRetry(() => fetchWithTimeout(url, "POST", jsonBodyHeaders, body, timeoutMs)))
return handleFetch(promiseRetry(() => request(url, "POST", jsonBodyHeaders, body, timeoutMs)))
}

/**
* A reader node under load answers 429 or 503. That answer is not the
* contract's state, but returning it as `undefined` made every caller report a
* missing contract: `getAll()` against a busy node surfaced as "Contract not
* found". Those statuses are retried instead. 404 and the other client errors
* still fall through to `undefined`, which is how a missing AVL value is
* reported.
*/
function request(url: string, method: RequestType, headers: Record<string, string>, body: unknown, timeoutMs: number): Promise<Response> {
return fetchWithTimeout(url, method, headers, body, timeoutMs).then((response) => {
if (response.status === 429 || response.status >= 500) throw new Error(`${method} ${url} failed with HTTP ${response.status}`)

return response
})
}

async function fetchWithTimeout(url: string, method: RequestType, headers: Record<string, string>, body: unknown, timeoutMs: number): Promise<Response> {
Expand Down
Loading