@ledgerhq/coin-module-framework 11.0.1 → 11.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/lib/api/getBlock/assertBlockHeight.d.ts +2 -0
- package/lib/api/getBlock/assertBlockHeight.d.ts.map +1 -0
- package/lib/api/getBlock/assertBlockHeight.js +12 -0
- package/lib/api/getBlock/assertBlockHeight.js.map +1 -0
- package/lib/api/impl.d.ts +22 -3
- package/lib/api/impl.d.ts.map +1 -1
- package/lib/api/impl.js +2 -0
- package/lib/api/impl.js.map +1 -1
- package/lib/api/notSupportedApi.d.ts.map +1 -1
- package/lib/api/notSupportedApi.js +1 -0
- package/lib/api/notSupportedApi.js.map +1 -1
- package/lib/api/types.d.ts +130 -2
- package/lib/api/types.d.ts.map +1 -1
- package/lib/api/withDefaults.d.ts +13 -2
- package/lib/api/withDefaults.d.ts.map +1 -1
- package/lib/api/withDefaults.js +36 -1
- package/lib/api/withDefaults.js.map +1 -1
- package/lib/currencies/formatCurrencyUnit.js +1 -1
- package/lib/currencies/formatCurrencyUnit.js.map +1 -1
- package/lib/currencies/parseCurrencyUnit.js +1 -1
- package/lib/currencies/parseCurrencyUnit.js.map +1 -1
- package/lib/errors.d.ts +37 -1
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +71 -2
- package/lib/errors.js.map +1 -1
- package/lib/promises/promises.d.ts +1 -1
- package/lib/promises/promises.d.ts.map +1 -1
- package/lib/promises/promises.js +1 -1
- package/lib/promises/promises.js.map +1 -1
- package/lib/utils.d.ts +1 -0
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +9 -0
- package/lib/utils.js.map +1 -1
- package/lib-es/api/getBlock/assertBlockHeight.d.ts +2 -0
- package/lib-es/api/getBlock/assertBlockHeight.d.ts.map +1 -0
- package/lib-es/api/getBlock/assertBlockHeight.js +9 -0
- package/lib-es/api/getBlock/assertBlockHeight.js.map +1 -0
- package/lib-es/api/impl.d.ts +22 -3
- package/lib-es/api/impl.d.ts.map +1 -1
- package/lib-es/api/impl.js +2 -0
- package/lib-es/api/impl.js.map +1 -1
- package/lib-es/api/notSupportedApi.d.ts.map +1 -1
- package/lib-es/api/notSupportedApi.js +1 -0
- package/lib-es/api/notSupportedApi.js.map +1 -1
- package/lib-es/api/types.d.ts +130 -2
- package/lib-es/api/types.d.ts.map +1 -1
- package/lib-es/api/withDefaults.d.ts +13 -2
- package/lib-es/api/withDefaults.d.ts.map +1 -1
- package/lib-es/api/withDefaults.js +36 -1
- package/lib-es/api/withDefaults.js.map +1 -1
- package/lib-es/currencies/formatCurrencyUnit.js +1 -1
- package/lib-es/currencies/formatCurrencyUnit.js.map +1 -1
- package/lib-es/currencies/parseCurrencyUnit.js +1 -1
- package/lib-es/currencies/parseCurrencyUnit.js.map +1 -1
- package/lib-es/errors.d.ts +37 -1
- package/lib-es/errors.d.ts.map +1 -1
- package/lib-es/errors.js +64 -1
- package/lib-es/errors.js.map +1 -1
- package/lib-es/promises/promises.d.ts +1 -1
- package/lib-es/promises/promises.d.ts.map +1 -1
- package/lib-es/promises/promises.js +1 -1
- package/lib-es/promises/promises.js.map +1 -1
- package/lib-es/utils.d.ts +1 -0
- package/lib-es/utils.d.ts.map +1 -1
- package/lib-es/utils.js +8 -0
- package/lib-es/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/api/getBalance/rejectBalanceOptions.test.ts +8 -0
- package/src/api/getBlock/assertBlockHeight.test.ts +28 -0
- package/src/api/getBlock/assertBlockHeight.ts +10 -0
- package/src/api/impl.test.ts +3 -0
- package/src/api/impl.ts +24 -1
- package/src/api/notSupportedApi.ts +1 -0
- package/src/api/types.ts +155 -3
- package/src/api/withDefaults.test.ts +154 -1
- package/src/api/withDefaults.ts +66 -3
- package/src/currencies/formatCurrencyUnit.test.ts +14 -0
- package/src/currencies/formatCurrencyUnit.ts +1 -1
- package/src/currencies/parseCurrencyUnit.test.ts +5 -0
- package/src/currencies/parseCurrencyUnit.ts +1 -1
- package/src/errors.test.ts +89 -0
- package/src/errors.ts +59 -1
- package/src/promises/promises.test.ts +1 -1
- package/src/promises/promises.ts +1 -1
- package/src/test-utils/capabilities.test.ts +1 -0
- package/src/utils.test.ts +24 -1
- package/src/utils.ts +11 -0
package/src/errors.ts
CHANGED
|
@@ -121,11 +121,69 @@ export class UnknownError extends Error {
|
|
|
121
121
|
|
|
122
122
|
export class BlockNotFoundError extends Error {
|
|
123
123
|
override name = 'BlockNotFoundError'
|
|
124
|
-
|
|
124
|
+
readonly statusCode = 404
|
|
125
|
+
constructor(message?: string, fields?: Record<string, unknown>, options?: { cause?: unknown }) {
|
|
125
126
|
super(message || 'BlockNotFoundError')
|
|
127
|
+
if (fields) Object.assign(this, fields)
|
|
128
|
+
if (options?.cause !== undefined) Object.assign(this, { cause: options.cause })
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export class InvalidBlockHeightError extends Error {
|
|
133
|
+
override name = 'InvalidBlockHeightError'
|
|
134
|
+
readonly statusCode = 400
|
|
135
|
+
constructor(message?: string, fields?: Record<string, unknown>, options?: { cause?: unknown }) {
|
|
136
|
+
super(message || 'InvalidBlockHeightError')
|
|
137
|
+
if (fields) Object.assign(this, fields)
|
|
138
|
+
if (options?.cause !== undefined) Object.assign(this, { cause: options.cause })
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export class RateLimitError extends Error {
|
|
143
|
+
override name = 'RateLimitError'
|
|
144
|
+
readonly statusCode = 429
|
|
145
|
+
constructor(message?: string, fields?: Record<string, unknown>, options?: { cause?: unknown }) {
|
|
146
|
+
super(message || 'Upstream rate limit exceeded (429), please retry later')
|
|
147
|
+
if (fields) Object.assign(this, fields)
|
|
148
|
+
if (options?.cause !== undefined) Object.assign(this, { cause: options.cause })
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export class InvalidExplorerResponse extends Error {
|
|
153
|
+
override name = 'InvalidExplorerResponse'
|
|
154
|
+
constructor(message?: string, fields?: Record<string, unknown>, options?: { cause?: unknown }) {
|
|
155
|
+
super(message || 'InvalidExplorerResponse')
|
|
156
|
+
if (fields) Object.assign(this, fields)
|
|
157
|
+
if (options?.cause !== undefined) Object.assign(this, { cause: options.cause })
|
|
126
158
|
}
|
|
127
159
|
}
|
|
128
160
|
|
|
161
|
+
export class GetBlockInfoError extends Error {
|
|
162
|
+
override name = 'GetBlockInfoError'
|
|
163
|
+
constructor(message?: string, fields?: Record<string, unknown>, options?: { cause?: unknown }) {
|
|
164
|
+
super(message || 'GetBlockInfoError')
|
|
165
|
+
if (fields) Object.assign(this, fields)
|
|
166
|
+
if (options?.cause !== undefined) Object.assign(this, { cause: options.cause })
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export class GetBlockError extends Error {
|
|
171
|
+
override name = 'GetBlockError'
|
|
172
|
+
constructor(message?: string, fields?: Record<string, unknown>, options?: { cause?: unknown }) {
|
|
173
|
+
super(message || 'GetBlockError')
|
|
174
|
+
if (fields) Object.assign(this, fields)
|
|
175
|
+
if (options?.cause !== undefined) Object.assign(this, { cause: options.cause })
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function statusCodeOf(error: unknown): number | undefined {
|
|
180
|
+
if (error instanceof Error && 'statusCode' in error && typeof error.statusCode === 'number') {
|
|
181
|
+
return error.statusCode
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return undefined
|
|
185
|
+
}
|
|
186
|
+
|
|
129
187
|
export class UnexpectedGetBalanceError extends Error {
|
|
130
188
|
override name = 'UnexpectedGetBalanceError'
|
|
131
189
|
cause: unknown
|
package/src/promises/promises.ts
CHANGED
|
@@ -9,7 +9,7 @@ const defaults = {
|
|
|
9
9
|
interval: 300,
|
|
10
10
|
intervalMultiplicator: 1.5,
|
|
11
11
|
context: '',
|
|
12
|
-
retryCondition: (
|
|
12
|
+
retryCondition: (_error: unknown) => true,
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export function retry<A>(f: () => Promise<A>, options?: Partial<typeof defaults>): Promise<A> {
|
package/src/utils.test.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import BigNumber from 'bignumber.js'
|
|
5
|
-
import { fromBigNumberToBigInt } from './utils'
|
|
5
|
+
import { fromBigNumberToBigInt, isHttpTooManyRequests } from './utils'
|
|
6
6
|
|
|
7
7
|
describe('bigNumberToBigInt', () => {
|
|
8
8
|
it('should convert BigNumber to BigInt', () => {
|
|
@@ -24,3 +24,26 @@ describe('bigNumberToBigInt', () => {
|
|
|
24
24
|
expect(valBigint).toEqual(BigInt(valueStr))
|
|
25
25
|
})
|
|
26
26
|
})
|
|
27
|
+
|
|
28
|
+
describe('isHttpTooManyRequests', () => {
|
|
29
|
+
it('detects an error whose response status is 429', () => {
|
|
30
|
+
expect(
|
|
31
|
+
isHttpTooManyRequests(Object.assign(new Error('429'), { response: { status: 429 } }))
|
|
32
|
+
).toBe(true)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it.each<[string, unknown]>([
|
|
36
|
+
[
|
|
37
|
+
'a response with another status',
|
|
38
|
+
Object.assign(new Error('500'), { response: { status: 500 } }),
|
|
39
|
+
],
|
|
40
|
+
['a response without status', Object.assign(new Error('x'), { response: {} })],
|
|
41
|
+
['a null response', Object.assign(new Error('x'), { response: null })],
|
|
42
|
+
['a non-object response', Object.assign(new Error('x'), { response: 429 })],
|
|
43
|
+
['an error without response', new Error('x')],
|
|
44
|
+
['a non-error with a 429 response', { response: { status: 429 } }],
|
|
45
|
+
['nothing', undefined],
|
|
46
|
+
])('rejects %s', (_label, error) => {
|
|
47
|
+
expect(isHttpTooManyRequests(error)).toBe(false)
|
|
48
|
+
})
|
|
49
|
+
})
|
package/src/utils.ts
CHANGED
|
@@ -26,3 +26,14 @@ export function isSendTransactionIntent(tx: TransactionIntent): tx is SendTransa
|
|
|
26
26
|
export function isStakingTransactionIntent(tx: TransactionIntent): tx is StakingTransactionIntent {
|
|
27
27
|
return tx.intentType === 'staking'
|
|
28
28
|
}
|
|
29
|
+
|
|
30
|
+
export function isHttpTooManyRequests(error: unknown): boolean {
|
|
31
|
+
return (
|
|
32
|
+
error instanceof Error &&
|
|
33
|
+
'response' in error &&
|
|
34
|
+
typeof error.response === 'object' &&
|
|
35
|
+
error.response !== null &&
|
|
36
|
+
'status' in error.response &&
|
|
37
|
+
error.response.status === 429
|
|
38
|
+
)
|
|
39
|
+
}
|