@concordium/common-sdk
Advanced tools
Comparing version
@@ -5,6 +5,8 @@ import Provider, { JsonRpcRequest } from './provider'; | ||
request: JsonRpcRequest; | ||
cookie?: string; | ||
/** | ||
* @param internalFetch Fetch function that performs the request. Defaults to using the cross-fetch package. | ||
*/ | ||
constructor(url: string, internalFetch?: typeof fetch); | ||
constructor(url: string, internalFetch?: typeof fetch, onSetCookie?: (cookie: string) => void, initialCookie?: string, autoUpdateCookie?: boolean); | ||
updateCookie(newCookie: string): void; | ||
} |
@@ -14,3 +14,4 @@ "use strict"; | ||
*/ | ||
constructor(url, internalFetch = cross_fetch_1.default) { | ||
constructor(url, internalFetch = cross_fetch_1.default, onSetCookie, initialCookie, autoUpdateCookie = true) { | ||
this.cookie = initialCookie; | ||
this.request = async function (method, params) { | ||
@@ -29,2 +30,3 @@ const request = { | ||
'Content-Type': 'application/json', | ||
...(this.cookie && { cookie: this.cookie }), | ||
}, | ||
@@ -42,6 +44,16 @@ }; | ||
} | ||
const setCookieValue = res.headers.get('set-cookie'); | ||
if (setCookieValue) { | ||
onSetCookie?.(setCookieValue); | ||
if (autoUpdateCookie) { | ||
this.updateCookie(setCookieValue); | ||
} | ||
} | ||
return res.text(); | ||
}; | ||
} | ||
updateCookie(newCookie) { | ||
this.cookie = newCookie; | ||
} | ||
} | ||
exports.HttpProvider = HttpProvider; |
102
package.json
{ | ||
"name": "@concordium/common-sdk", | ||
"version": "5.0.0", | ||
"license": "Apache-2.0", | ||
"engines": { | ||
"node": ">=14.16.0" | ||
}, | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"files": [ | ||
"/lib/**/*" | ||
], | ||
"devDependencies": { | ||
"@types/bs58check": "^2.1.0", | ||
"@types/jest": "^26.0.23", | ||
"@types/json-bigint": "^1.0.1", | ||
"@types/uuid": "^8.3.4", | ||
"@typescript-eslint/eslint-plugin": "^4.28.1", | ||
"@typescript-eslint/parser": "^4.28.1", | ||
"babel-jest": "^27.0.6", | ||
"eslint": "^7.29.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"husky": "^4.2.5", | ||
"jest": "^27.0.6", | ||
"lint-staged": "^12.0.2", | ||
"prettier": "^2.3.2", | ||
"ts-jest": "^27.0.3", | ||
"typescript": "^4.3.5" | ||
}, | ||
"prettier": { | ||
"singleQuote": true, | ||
"tabWidth": 4 | ||
}, | ||
"scripts": { | ||
"lint": "eslint . --cache --ext .ts,.tsx --max-warnings 0", | ||
"lint-fix": "yarn --silent lint --fix; exit 0", | ||
"test": "jest", | ||
"build": "tsc" | ||
}, | ||
"dependencies": { | ||
"@concordium/rust-bindings": "0.5.0", | ||
"@noble/ed25519": "^1.7.1", | ||
"@scure/bip39": "^1.1.0", | ||
"bs58check": "^2.1.2", | ||
"buffer": "^6.0.3", | ||
"cross-fetch": "3.1.5", | ||
"hash.js": "^1.1.7", | ||
"json-bigint": "^1.0.0", | ||
"uuid": "^8.3.2" | ||
} | ||
} | ||
"name": "@concordium/common-sdk", | ||
"version": "5.1.0", | ||
"license": "Apache-2.0", | ||
"engines": { | ||
"node": ">=14.16.0" | ||
}, | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"files": [ | ||
"/lib/**/*" | ||
], | ||
"devDependencies": { | ||
"@types/bs58check": "^2.1.0", | ||
"@types/jest": "^26.0.23", | ||
"@types/json-bigint": "^1.0.1", | ||
"@types/uuid": "^8.3.4", | ||
"@typescript-eslint/eslint-plugin": "^4.28.1", | ||
"@typescript-eslint/parser": "^4.28.1", | ||
"babel-jest": "^27.0.6", | ||
"eslint": "^7.29.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"husky": "^4.2.5", | ||
"jest": "^27.0.6", | ||
"lint-staged": "^12.0.2", | ||
"prettier": "^2.3.2", | ||
"ts-jest": "^27.0.3", | ||
"typescript": "^4.3.5" | ||
}, | ||
"prettier": { | ||
"singleQuote": true, | ||
"tabWidth": 4 | ||
}, | ||
"scripts": { | ||
"lint": "eslint . --cache --ext .ts,.tsx --max-warnings 0", | ||
"lint-fix": "yarn --silent lint --fix; exit 0", | ||
"test": "jest", | ||
"build": "tsc" | ||
}, | ||
"dependencies": { | ||
"@concordium/rust-bindings": "0.5.0", | ||
"@noble/ed25519": "^1.7.1", | ||
"@scure/bip39": "^1.1.0", | ||
"bs58check": "^2.1.2", | ||
"buffer": "^6.0.3", | ||
"cross-fetch": "3.1.5", | ||
"hash.js": "^1.1.7", | ||
"json-bigint": "^1.0.0", | ||
"uuid": "^8.3.2" | ||
} | ||
} |
6196
0.23%310397
-0.93%59
-1.67%