@injectivelabs/utils
Advanced tools
Comparing version 1.14.40 to 1.14.41-alpha.0
@@ -8,2 +8,4 @@ "use strict"; | ||
class HttpClient { | ||
client; | ||
config = {}; | ||
constructor(endpoint, options = { | ||
@@ -14,5 +16,8 @@ headers: { | ||
}) { | ||
this.client = axios_1.default.create({ | ||
baseURL: endpoint, | ||
timeout: 15000, | ||
...options, | ||
}); | ||
this.config = {}; | ||
this.client = axios_1.default.create(Object.assign({ baseURL: endpoint, timeout: 15000 }, options)); | ||
this.config = {}; | ||
} | ||
@@ -24,3 +29,3 @@ setConfig(config) { | ||
get(endpoint, params = {}) { | ||
return this.client.get(endpoint, Object.assign({ params }, this.config)); | ||
return this.client.get(endpoint, { params, ...this.config }); | ||
} | ||
@@ -34,3 +39,3 @@ post(endpoint, data = {}) { | ||
delete(endpoint, params = {}) { | ||
return this.client.delete(endpoint, Object.assign({ params }, this.config)); | ||
return this.client.delete(endpoint, { params, ...this.config }); | ||
} | ||
@@ -37,0 +42,0 @@ } |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -31,2 +22,4 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
class HttpRestClient { | ||
client; | ||
endpoint; | ||
constructor(endpoint, options = {}) { | ||
@@ -40,77 +33,66 @@ this.client = new HttpClient_js_1.default(endpoint, options); | ||
} | ||
get(endpoint_1) { | ||
return __awaiter(this, arguments, void 0, function* (endpoint, params = {}) { | ||
try { | ||
return yield this.client.get(endpoint, params); | ||
} | ||
catch (e) { | ||
const error = e; | ||
if (axios_1.default.isAxiosError(error)) { | ||
if (error.code === 'ECONNABORTED') { | ||
throw new exceptions_1.HttpRequestException(new Error(error.message), { | ||
code: http_status_codes_1.StatusCodes.REQUEST_TOO_LONG, | ||
context: endpoint, | ||
}); | ||
} | ||
const message = getErrorMessage(error, endpoint); | ||
throw new exceptions_1.HttpRequestException(new Error(message), { | ||
async get(endpoint, params = {}) { | ||
try { | ||
return await this.client.get(endpoint, params); | ||
} | ||
catch (e) { | ||
const error = e; | ||
if (axios_1.default.isAxiosError(error)) { | ||
if (error.code === 'ECONNABORTED') { | ||
throw new exceptions_1.HttpRequestException(new Error(error.message), { | ||
code: http_status_codes_1.StatusCodes.REQUEST_TOO_LONG, | ||
context: endpoint, | ||
code: error.response | ||
? error.response.status | ||
: http_status_codes_1.StatusCodes.BAD_REQUEST, | ||
}); | ||
} | ||
throw new exceptions_1.HttpRequestException(new Error(error.message), { | ||
code: exceptions_1.UnspecifiedErrorCode, | ||
const message = getErrorMessage(error, endpoint); | ||
throw new exceptions_1.HttpRequestException(new Error(message), { | ||
context: endpoint, | ||
code: error.response | ||
? error.response.status | ||
: http_status_codes_1.StatusCodes.BAD_REQUEST, | ||
}); | ||
} | ||
}); | ||
} | ||
retry(httpCall_1) { | ||
return __awaiter(this, arguments, void 0, function* (httpCall, retries = 3, delay = 1000) { | ||
const retryHttpCall = (...args_1) => __awaiter(this, [...args_1], void 0, function* (attempt = 1) { | ||
try { | ||
return (yield httpCall()); | ||
} | ||
catch (e) { | ||
if (e instanceof exceptions_1.HttpRequestException) { | ||
if (e.code === http_status_codes_1.StatusCodes.REQUEST_TOO_LONG) { | ||
throw e; | ||
} | ||
} | ||
if (attempt >= retries) { | ||
throw e; | ||
} | ||
return new Promise((resolve) => setTimeout(() => resolve(retryHttpCall(attempt + 1)), delay * attempt)); | ||
} | ||
throw new exceptions_1.HttpRequestException(new Error(error.message), { | ||
code: exceptions_1.UnspecifiedErrorCode, | ||
context: endpoint, | ||
}); | ||
return retryHttpCall(); | ||
}); | ||
} | ||
} | ||
post(endpoint_1) { | ||
return __awaiter(this, arguments, void 0, function* (endpoint, params = {}) { | ||
async retry(httpCall, retries = 3, delay = 1000) { | ||
const retryHttpCall = async (attempt = 1) => { | ||
try { | ||
return yield this.client.post(endpoint, params); | ||
return (await httpCall()); | ||
} | ||
catch (e) { | ||
const error = e; | ||
if (axios_1.default.isAxiosError(error)) { | ||
if (error.code === 'ECONNABORTED') { | ||
throw new exceptions_1.HttpRequestException(new Error(error.message), { | ||
code: http_status_codes_1.StatusCodes.REQUEST_TOO_LONG, | ||
method: exceptions_1.HttpRequestMethod.Post, | ||
}); | ||
if (e instanceof exceptions_1.HttpRequestException) { | ||
if (e.code === http_status_codes_1.StatusCodes.REQUEST_TOO_LONG) { | ||
throw e; | ||
} | ||
const message = getErrorMessage(error, endpoint); | ||
throw new exceptions_1.HttpRequestException(new Error(message), { | ||
code: error.response | ||
? error.response.status | ||
: http_status_codes_1.StatusCodes.BAD_REQUEST, | ||
context: endpoint, | ||
contextModule: exceptions_1.HttpRequestMethod.Post, | ||
} | ||
if (attempt >= retries) { | ||
throw e; | ||
} | ||
return new Promise((resolve) => setTimeout(() => resolve(retryHttpCall(attempt + 1)), delay * attempt)); | ||
} | ||
}; | ||
return retryHttpCall(); | ||
} | ||
async post(endpoint, params = {}) { | ||
try { | ||
return await this.client.post(endpoint, params); | ||
} | ||
catch (e) { | ||
const error = e; | ||
if (axios_1.default.isAxiosError(error)) { | ||
if (error.code === 'ECONNABORTED') { | ||
throw new exceptions_1.HttpRequestException(new Error(error.message), { | ||
code: http_status_codes_1.StatusCodes.REQUEST_TOO_LONG, | ||
method: exceptions_1.HttpRequestMethod.Post, | ||
}); | ||
} | ||
throw new exceptions_1.HttpRequestException(new Error(error.message), { | ||
code: exceptions_1.UnspecifiedErrorCode, | ||
const message = getErrorMessage(error, endpoint); | ||
throw new exceptions_1.HttpRequestException(new Error(message), { | ||
code: error.response | ||
? error.response.status | ||
: http_status_codes_1.StatusCodes.BAD_REQUEST, | ||
context: endpoint, | ||
@@ -120,3 +102,8 @@ contextModule: exceptions_1.HttpRequestMethod.Post, | ||
} | ||
}); | ||
throw new exceptions_1.HttpRequestException(new Error(error.message), { | ||
code: exceptions_1.UnspecifiedErrorCode, | ||
context: endpoint, | ||
contextModule: exceptions_1.HttpRequestMethod.Post, | ||
}); | ||
} | ||
} | ||
@@ -123,0 +110,0 @@ } |
@@ -18,9 +18,19 @@ "use strict"; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importStar = (this && this.__importStar) || (function () { | ||
var ownKeys = function(o) { | ||
ownKeys = Object.getOwnPropertyNames || function (o) { | ||
var ar = []; | ||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | ||
return ar; | ||
}; | ||
return ownKeys(o); | ||
}; | ||
return function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
})(); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -27,0 +37,0 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const store2_1 = __importDefault(require("store2")); | ||
const store2_1 = require("store2"); | ||
class LocalStorage { | ||
storage; | ||
constructor(namespace) { | ||
this.storage = store2_1.default.namespace(namespace); | ||
this.storage = store2_1.store.namespace(namespace); | ||
} | ||
@@ -11,0 +9,0 @@ get(key, defaultValue = {}) { |
@@ -13,2 +13,3 @@ "use strict"; | ||
class Status { | ||
status; | ||
constructor(status = StatusType.Idle) { | ||
@@ -15,0 +16,0 @@ this.status = status; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class StreamManager { | ||
constructor() { | ||
this.streams = new Map(); | ||
} | ||
streams = new Map(); | ||
set(stream, streamKey) { | ||
@@ -8,0 +6,0 @@ if (this.streams.has(streamKey)) { |
@@ -15,3 +15,3 @@ import { Awaited } from './types.js'; | ||
chunkSize: number; | ||
filter?: ((item: T) => boolean) | undefined; | ||
filter?: (item: T) => boolean; | ||
}) => T[][]; | ||
@@ -18,0 +18,0 @@ export declare const getStdFeeForToken: (token?: { |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -16,3 +7,2 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
exports.getStdFee = exports.getStdFeeFromString = exports.getDefaultStdFee = exports.getStdFeeFromObject = exports.getStdFeeForToken = exports.splitArrayToChunks = exports.awaitForAll = exports.awaitAll = exports.sleep = void 0; | ||
const bignumber_js_1 = __importDefault(require("bignumber.js")); | ||
const constants_js_1 = require("./constants.js"); | ||
@@ -26,3 +16,3 @@ const BigNumberInBase_js_1 = __importDefault(require("./classes/BigNumber/BigNumberInBase.js")); | ||
*/ | ||
const awaitAll = (array, callback) => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.all(array.map((item) => __awaiter(void 0, void 0, void 0, function* () { return yield callback(item); }))); }); | ||
const awaitAll = async (array, callback) => await Promise.all(array.map(async (item) => await callback(item))); | ||
exports.awaitAll = awaitAll; | ||
@@ -33,7 +23,7 @@ /** | ||
*/ | ||
const awaitForAll = (array, callback) => __awaiter(void 0, void 0, void 0, function* () { | ||
const awaitForAll = async (array, callback) => { | ||
const result = []; | ||
for (let i = 0; i < array.length; i += 1) { | ||
try { | ||
result.push(yield callback(array[i])); | ||
result.push(await callback(array[i])); | ||
} | ||
@@ -45,3 +35,3 @@ catch (e) { | ||
return result; | ||
}); | ||
}; | ||
exports.awaitForAll = awaitForAll; | ||
@@ -67,3 +57,3 @@ const splitArrayToChunks = ({ array, chunkSize, filter, }) => { | ||
.toFixed(0); | ||
const gasNormalized = new bignumber_js_1.default(gasLimit || constants_js_1.DEFAULT_GAS_LIMIT).toFixed(0); | ||
const gasNormalized = new BigNumberInBase_js_1.default(gasLimit || constants_js_1.DEFAULT_GAS_LIMIT).toFixed(0); | ||
return { | ||
@@ -87,4 +77,4 @@ amount: [ | ||
const { gas = constants_js_1.DEFAULT_GAS_LIMIT.toString(), gasPrice = constants_js_1.DEFAULT_GAS_PRICE, payer, granter, feePayer, } = args; | ||
const gasNormalized = new bignumber_js_1.default(gas).toFixed(0); | ||
const gasPriceNormalized = new bignumber_js_1.default(gasPrice).toFixed(0); | ||
const gasNormalized = new BigNumberInBase_js_1.default(gas).toFixed(0); | ||
const gasPriceNormalized = new BigNumberInBase_js_1.default(gasPrice).toFixed(0); | ||
return { | ||
@@ -94,3 +84,3 @@ amount: [ | ||
denom: 'inj', | ||
amount: new bignumber_js_1.default(gasNormalized) | ||
amount: new BigNumberInBase_js_1.default(gasNormalized) | ||
.times(gasPriceNormalized) | ||
@@ -100,3 +90,3 @@ .toFixed(), | ||
], | ||
gas: new bignumber_js_1.default(gasNormalized).toFixed(), | ||
gas: new BigNumberInBase_js_1.default(gasNormalized).toFixed(), | ||
payer /** for Web3Gateway fee delegation */, | ||
@@ -130,5 +120,5 @@ granter, | ||
} | ||
return (0, exports.getStdFeeFromObject)(Object.assign({}, args)); | ||
return (0, exports.getStdFeeFromObject)({ ...args }); | ||
}; | ||
exports.getStdFee = getStdFee; | ||
//# sourceMappingURL=helpers.js.map |
@@ -15,3 +15,3 @@ "use strict"; | ||
const trailingZeros = 13 - timestamp.toString().length; | ||
return timestampInBigNumber.times(Math.pow(10, trailingZeros)).toNumber(); | ||
return timestampInBigNumber.times(10 ** trailingZeros).toNumber(); | ||
} | ||
@@ -18,0 +18,0 @@ return timestampInBigNumber.toNumber(); |
@@ -1,2 +0,2 @@ | ||
import store from 'store2'; | ||
import { store } from 'store2'; | ||
export default class LocalStorage { | ||
@@ -3,0 +3,0 @@ storage; |
@@ -15,3 +15,3 @@ import { Awaited } from './types.js'; | ||
chunkSize: number; | ||
filter?: ((item: T) => boolean) | undefined; | ||
filter?: (item: T) => boolean; | ||
}) => T[][]; | ||
@@ -18,0 +18,0 @@ export declare const getStdFeeForToken: (token?: { |
@@ -1,2 +0,1 @@ | ||
import BigNumber from 'bignumber.js'; | ||
import { DEFAULT_STD_FEE, DEFAULT_GAS_LIMIT, DEFAULT_GAS_PRICE, } from './constants.js'; | ||
@@ -44,3 +43,3 @@ import BigNumberInBase from './classes/BigNumber/BigNumberInBase.js'; | ||
.toFixed(0); | ||
const gasNormalized = new BigNumber(gasLimit || DEFAULT_GAS_LIMIT).toFixed(0); | ||
const gasNormalized = new BigNumberInBase(gasLimit || DEFAULT_GAS_LIMIT).toFixed(0); | ||
return { | ||
@@ -63,4 +62,4 @@ amount: [ | ||
const { gas = DEFAULT_GAS_LIMIT.toString(), gasPrice = DEFAULT_GAS_PRICE, payer, granter, feePayer, } = args; | ||
const gasNormalized = new BigNumber(gas).toFixed(0); | ||
const gasPriceNormalized = new BigNumber(gasPrice).toFixed(0); | ||
const gasNormalized = new BigNumberInBase(gas).toFixed(0); | ||
const gasPriceNormalized = new BigNumberInBase(gasPrice).toFixed(0); | ||
return { | ||
@@ -70,3 +69,3 @@ amount: [ | ||
denom: 'inj', | ||
amount: new BigNumber(gasNormalized) | ||
amount: new BigNumberInBase(gasNormalized) | ||
.times(gasPriceNormalized) | ||
@@ -76,3 +75,3 @@ .toFixed(), | ||
], | ||
gas: new BigNumber(gasNormalized).toFixed(), | ||
gas: new BigNumberInBase(gasNormalized).toFixed(), | ||
payer /** for Web3Gateway fee delegation */, | ||
@@ -79,0 +78,0 @@ granter, |
{ | ||
"name": "@injectivelabs/utils", | ||
"description": "List of utils and helper functions that can be reused throughout Injective's projects.", | ||
"version": "1.14.40", | ||
"version": "1.14.41-alpha.0", | ||
"sideEffects": false, | ||
"type": "module", | ||
"author": { | ||
@@ -37,2 +38,22 @@ "name": "InjectiveLabs", | ||
} | ||
}, | ||
"./test-utils": { | ||
"react-native": { | ||
"import": "./dist/esm/test-utils/index.js", | ||
"require": "./dist/cjs/test-utils/index.js", | ||
"types": "./dist/cjs/test-utils/index.d.ts", | ||
"default": "./dist/cjs/test-utils/index.js" | ||
}, | ||
"require": { | ||
"types": "./dist/cjs/test-utils/index.d.ts", | ||
"default": "./dist/cjs/test-utils/index.js" | ||
}, | ||
"import": { | ||
"types": "./dist/esm/test-utils/index.d.ts", | ||
"default": "./dist/esm/test-utils/index.js" | ||
}, | ||
"default": { | ||
"types": "./dist/cjs/test-utils/index.d.ts", | ||
"default": "./dist/cjs/test-utils/index.js" | ||
} | ||
} | ||
@@ -59,12 +80,14 @@ }, | ||
"dependencies": { | ||
"@injectivelabs/exceptions": "^1.14.40", | ||
"@injectivelabs/ts-types": "^1.14.40", | ||
"@injectivelabs/exceptions": "^1.14.41-alpha.0", | ||
"@injectivelabs/networks": "^1.14.41-alpha.0", | ||
"@injectivelabs/ts-types": "^1.14.41-alpha.0", | ||
"axios": "^1.6.4", | ||
"bignumber.js": "^9.0.1", | ||
"http-status-codes": "^2.2.0", | ||
"shx": "^0.3.2", | ||
"snakecase-keys": "^5.1.2", | ||
"store2": "^2.12.0" | ||
"store2": "^2.14.3" | ||
}, | ||
"gitHead": "3530a66d35278bd939700098d2fbec98f1484253" | ||
"devDependencies": { | ||
"shx": "^0.3.2" | ||
}, | ||
"gitHead": "0d2a71e8f8c59500fa4a45f2be48ead6c8bd2d93" | ||
} |
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
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
182498
7
165
2494
Yes
1
2
+ Added@injectivelabs/exceptions@1.14.41-alpha.0(transitive)
+ Added@injectivelabs/networks@1.14.41-beta.1(transitive)
+ Added@injectivelabs/ts-types@1.14.41-alpha.0(transitive)
+ Added@injectivelabs/utils@1.14.40(transitive)
- Removedshx@^0.3.2
- Removedsnakecase-keys@^5.1.2
Updatedstore2@^2.14.3