bitpay-rates 2.0.0 → 3.1.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/LICENSE +21 -0
- package/README.md +109 -67
- package/dist/index.d.mts +52 -0
- package/dist/index.mjs +1 -0
- package/package.json +45 -29
- package/dist/index.d.ts +0 -11
- package/dist/index.js +0 -39
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) colkito
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,101 +1,143 @@
|
|
|
1
1
|
# bitpay-rates
|
|
2
2
|
|
|
3
|
-
](https://bundlephobia.com/result?p=bitpay-rates)
|
|
3
|
+
[](https://github.com/colkito/bitpay-rates/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/bitpay-rates)
|
|
6
5
|
|
|
7
|
-
A lightweight Node.js wrapper for [BitPay
|
|
6
|
+
A lightweight Node.js wrapper for [BitPay exchange rates](https://www.bitpay.com/exchange-rates), written in TypeScript.
|
|
8
7
|
|
|
9
|
-
Zero-
|
|
8
|
+
Zero runtime dependencies, promise-based, ESM (and `require()` on Node 22.12+).
|
|
9
|
+
Talks to the official public
|
|
10
|
+
[Rates API](https://developer.bitpay.com/reference/rates)
|
|
11
|
+
(`X-Accept-Version: 2.0.0`).
|
|
10
12
|
|
|
11
13
|
## Requirements
|
|
12
14
|
|
|
13
|
-
-
|
|
15
|
+
- Node.js >= 22.12
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
```bash
|
|
18
|
+
npm install bitpay-rates
|
|
19
|
+
```
|
|
16
20
|
|
|
17
|
-
|
|
21
|
+
## Breaking changes in v3
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
- **Promise-only.** The legacy callback signature (`get(code, cb)`) is gone —
|
|
24
|
+
use `async/await` or `.then()` / `.catch()`.
|
|
25
|
+
- **Named arguments.** `get()` now takes a single `{ base, quote }` object, so
|
|
26
|
+
there is no argument order to remember: `get('USD', 'ETH')` becomes
|
|
27
|
+
`get({ base: 'ETH', quote: 'USD' })`.
|
|
28
|
+
- `get({ base })` returns the **whole table** for that base, which v2 could not
|
|
29
|
+
express. `get({ quote })` returns that one rate against BTC.
|
|
30
|
+
- Dual ESM + CJS (the CJS file is gone in 3.1 — see below).
|
|
31
|
+
- Node.js >= 22 (3.1 requires >= 22.12).
|
|
32
|
+
- Requests time out after 10 seconds.
|
|
33
|
+
- Currency codes are validated (`/^[A-Z0-9]{2,10}$/`); anything else rejects
|
|
34
|
+
with a `TypeError` before a request is made.
|
|
35
|
+
|
|
36
|
+
v3.1 ships a **single ESM file**. `require('bitpay-rates')` still works on
|
|
37
|
+
Node 22.12+ (`require(esm)`). Node 22.0–22.11 need `import` or an upgrade.
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
### ESM / TypeScript
|
|
21
42
|
|
|
22
|
-
|
|
43
|
+
```ts
|
|
44
|
+
import { get, type RateObj } from 'bitpay-rates';
|
|
23
45
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
46
|
+
const all: RateObj[] = await get();
|
|
47
|
+
// GET /rates/BTC → every rate against BTC
|
|
48
|
+
|
|
49
|
+
const vsEth: RateObj[] = await get({ base: 'ETH' });
|
|
50
|
+
// GET /rates/ETH → every rate against ETH
|
|
51
|
+
|
|
52
|
+
const usd: RateObj = await get({ quote: 'USD' });
|
|
53
|
+
// GET /rates/BTC/USD → { code: 'USD', name: 'US Dollar', rate: 76471.42 }
|
|
54
|
+
|
|
55
|
+
const ethUsd: RateObj = await get({ base: 'ETH', quote: 'USD' });
|
|
56
|
+
// GET /rates/ETH/USD
|
|
31
57
|
```
|
|
32
58
|
|
|
33
|
-
|
|
59
|
+
`base` is the cryptocurrency you are pricing (default `BTC`); `quote` is the
|
|
60
|
+
currency you want the price in. Omitting `quote` gives the full table. The
|
|
61
|
+
return type follows from that: `RateObj[]` without `quote`, `RateObj` with it.
|
|
34
62
|
|
|
35
|
-
|
|
63
|
+
The default export is a namespace object holding the same function, so the v2
|
|
64
|
+
import style keeps working:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
36
67
|
import bitpayRates from 'bitpay-rates';
|
|
37
68
|
|
|
38
|
-
|
|
39
|
-
bitpayRates
|
|
40
|
-
.get('INVALID')
|
|
41
|
-
.then((rate) => console.log('[Promise][INVALID] Rate:', rate))
|
|
42
|
-
.catch((err) => console.error('[Promise][INVALID] Error:', err));
|
|
69
|
+
const usd = await bitpayRates.get({ quote: 'USD' });
|
|
43
70
|
```
|
|
44
71
|
|
|
45
|
-
|
|
72
|
+
### CommonJS
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
const { get } = require('bitpay-rates');
|
|
76
|
+
// or: const bitpayRates = require('bitpay-rates'); bitpayRates.get({ quote: 'USD' })
|
|
46
77
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"name": "Argentine Peso",
|
|
51
|
-
"rate": 60612542.16
|
|
52
|
-
}
|
|
78
|
+
get({ quote: 'USD' })
|
|
79
|
+
.then((rate) => console.log(rate))
|
|
80
|
+
.catch((err) => console.error(err));
|
|
53
81
|
```
|
|
54
82
|
|
|
55
|
-
|
|
83
|
+
All four styles — named or default, ESM or CommonJS — are asserted against the
|
|
84
|
+
built artifact on every CI run and before every publish (`npm run smoke`).
|
|
85
|
+
|
|
86
|
+
### Errors
|
|
87
|
+
|
|
88
|
+
`get()` rejects when BitPay returns a non-2xx status, an `{ error }` payload,
|
|
89
|
+
malformed JSON, a network failure, or when the request exceeds 10 seconds. It
|
|
90
|
+
rejects with a `TypeError` — before any request — when a code is not 2-10
|
|
91
|
+
alphanumeric characters.
|
|
92
|
+
|
|
93
|
+
It also rejects when the response shape does not match what you asked for.
|
|
94
|
+
`GET /rates/{code}` is polymorphic: a base with a rate table answers with a
|
|
95
|
+
list, anything else answers with a single rate. So `get({ base: 'USD' })`
|
|
96
|
+
rejects rather than handing you a `RateObj` typed as `RateObj[]`.
|
|
56
97
|
|
|
57
98
|
```js
|
|
58
|
-
import
|
|
99
|
+
import { get } from 'bitpay-rates';
|
|
59
100
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
console.log('[Async/Await] Rates:', rates);
|
|
64
|
-
} catch (err) {
|
|
65
|
-
console.error('[Async/Await] Error:', err);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Handling an invalid currency code
|
|
69
|
-
bitpayRates
|
|
70
|
-
.get('INVALID')
|
|
71
|
-
.then((rate) => console.log('[Promise][INVALID] Rate:', rate))
|
|
72
|
-
.catch((err) => console.error('[Promise][INVALID] Error:', err));
|
|
101
|
+
get({ quote: 'INVALID' })
|
|
102
|
+
.then((rate) => console.log(rate))
|
|
103
|
+
.catch((err) => console.error(err));
|
|
73
104
|
```
|
|
74
105
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
"rate": 57818.28
|
|
88
|
-
},
|
|
89
|
-
{...}
|
|
90
|
-
]
|
|
106
|
+
More examples in [`example/rates-example.mjs`](example/rates-example.mjs)
|
|
107
|
+
(run `npm run build` first).
|
|
108
|
+
|
|
109
|
+
## Types
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
type RateObj = { code: string; name: string; rate: number };
|
|
113
|
+
type RateQuery = { base?: string; quote?: string };
|
|
114
|
+
|
|
115
|
+
function get(): Promise<RateObj[]>;
|
|
116
|
+
function get(query: { base?: string; quote?: undefined }): Promise<RateObj[]>;
|
|
117
|
+
function get(query: { base?: string; quote: string }): Promise<RateObj>;
|
|
91
118
|
```
|
|
92
119
|
|
|
93
|
-
|
|
120
|
+
Both codes are uppercased automatically and must match `/^[A-Z0-9]{2,10}$/`.
|
|
121
|
+
Default `base` is `BTC`.
|
|
122
|
+
|
|
123
|
+
## Available codes
|
|
124
|
+
|
|
125
|
+
See [CODES.md](CODES.md). It is regenerated from `GET /rates/BTC` on every
|
|
126
|
+
release PR (`npm run update-codes`). Codes containing `_` (chain-specific
|
|
127
|
+
variants such as `USDC_arb`) appear in that table, but BitPay rejects them as a
|
|
128
|
+
`base` or `quote`, so they cannot be queried individually.
|
|
129
|
+
|
|
130
|
+
## Security
|
|
131
|
+
|
|
132
|
+
Zero runtime dependencies, published from CI only via npm Trusted Publishing
|
|
133
|
+
(OIDC) with a provenance attestation, and every release is gated on a human
|
|
134
|
+
publishing the draft GitHub Release. See
|
|
135
|
+
[SECURITY.md](.github/SECURITY.md) to report a vulnerability.
|
|
94
136
|
|
|
95
|
-
##
|
|
137
|
+
## Contributing
|
|
96
138
|
|
|
97
|
-
|
|
139
|
+
PRs only — see [CONTRIBUTING.md](.github/CONTRIBUTING.md). MIT licensed.
|
|
98
140
|
|
|
99
|
-
## Related
|
|
141
|
+
## Related packages
|
|
100
142
|
|
|
101
143
|
- [Blockchain Exchange Rates API](https://npmjs.com/blockchain-rates)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//#region src/index.d.mts
|
|
2
|
+
export type RateObj = {
|
|
3
|
+
code: string;
|
|
4
|
+
name: string;
|
|
5
|
+
rate: number;
|
|
6
|
+
};
|
|
7
|
+
export type RateResponse = RateObj | RateObj[];
|
|
8
|
+
/** Arguments for {@link get}. Named so neither code can be passed in the wrong position. */
|
|
9
|
+
export type RateQuery = {
|
|
10
|
+
/**
|
|
11
|
+
* Base cryptocurrency: the asset being priced.
|
|
12
|
+
*
|
|
13
|
+
* @defaultValue `'BTC'`
|
|
14
|
+
*/
|
|
15
|
+
base?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Quote currency: what to price `base` in. Omit for every rate against
|
|
18
|
+
* `base`.
|
|
19
|
+
*/
|
|
20
|
+
quote?: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Fetch BitPay exchange rates.
|
|
24
|
+
*
|
|
25
|
+
* @param query - `{ base, quote }`. Omit `quote` for the full table, omit both for BTC.
|
|
26
|
+
* @returns Every rate for `base` when `quote` is omitted, otherwise that single {@link RateObj}.
|
|
27
|
+
* @throws `TypeError` if a code is not 2-10 alphanumeric characters, before any request is made.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* await get(); // every rate against BTC
|
|
31
|
+
* await get({ base: 'ETH' }); // every rate against ETH
|
|
32
|
+
* await get({ quote: 'USD' }); // BTC/USD
|
|
33
|
+
* await get({ base: 'ETH', quote: 'USD' }); // ETH/USD
|
|
34
|
+
*/
|
|
35
|
+
export declare function get(): Promise<RateObj[]>;
|
|
36
|
+
export declare function get(query: {
|
|
37
|
+
base?: string;
|
|
38
|
+
quote?: undefined;
|
|
39
|
+
}): Promise<RateObj[]>;
|
|
40
|
+
export declare function get(query: {
|
|
41
|
+
base?: string;
|
|
42
|
+
quote: string;
|
|
43
|
+
}): Promise<RateObj>;
|
|
44
|
+
/**
|
|
45
|
+
* Namespace object, so `import bitpayRates` / `require(...)` + `.get()` works
|
|
46
|
+
* the same as the named export.
|
|
47
|
+
*/
|
|
48
|
+
declare const _default: {
|
|
49
|
+
get: typeof get;
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
export { _default as default };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=`https://bitpay.com/rates`,t=1e4,n=/^[A-Z0-9]{2,10}$/,r={"X-Accept-Version":`2.0.0`,Accept:`application/json`,"User-Agent":`bitpay-rates`};async function i(n={}){let{quote:r}=n,i=a(n.base??`BTC`,`base`),c=r===void 0,l=c?`${e}/${i}`:`${e}/${i}/${a(r,`quote`)}`;try{return await o(l,AbortSignal.timeout(t),c)}catch(e){throw s(e)?Error(`Request to ${l} timed out after ${t}ms`):e}}function a(e,t){let r=e.toUpperCase();if(!n.test(r))throw TypeError(`Invalid ${t} currency code: ${JSON.stringify(e)}`);return r}async function o(e,t,n){let i=await fetch(e,{headers:r,signal:t}),a=await i.text(),o;try{o=JSON.parse(a)}catch(t){throw i.ok?t:Error(`Request to ${e} failed with HTTP ${i.status}`)}if(c(o)&&o.error!=null)throw Error(String(o.error));if(!i.ok)throw Error(`Request to ${e} failed with HTTP ${i.status}`);let s=c(o)?o.data:void 0;if(n){if(!Array.isArray(s)||!s.every(l))throw Error(`Unexpected response from ${e}: expected a list of rates`)}else if(!l(s))throw Error(`Unexpected response from ${e}: expected a single rate`);return s}function s(e){return e instanceof Error?e.name===`TimeoutError`||e.cause instanceof Error&&e.cause.name===`TimeoutError`:!1}function c(e){return typeof e==`object`&&!!e}function l(e){return c(e)&&typeof e.code==`string`&&typeof e.name==`string`&&typeof e.rate==`number`}var u={get:i};export{u as default,i as get};
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bitpay-rates",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "A tiny Node.js wrapper for the BitPay Rates API",
|
|
5
5
|
"engines": {
|
|
6
|
-
"node": ">=
|
|
6
|
+
"node": ">=22.12"
|
|
7
7
|
},
|
|
8
8
|
"keywords": [
|
|
9
9
|
"bitcoin",
|
|
@@ -12,44 +12,60 @@
|
|
|
12
12
|
"countries",
|
|
13
13
|
"price"
|
|
14
14
|
],
|
|
15
|
-
"author": "
|
|
15
|
+
"author": "colkito <dev@colkito.com>",
|
|
16
16
|
"license": "MIT",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "./dist/index.mjs",
|
|
19
|
+
"types": "./dist/index.d.mts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.mts",
|
|
23
|
+
"default": "./dist/index.mjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
19
26
|
"repository": {
|
|
20
27
|
"type": "git",
|
|
21
|
-
"url": "https://github.com/colkito/bitpay-rates.git"
|
|
28
|
+
"url": "git+https://github.com/colkito/bitpay-rates.git"
|
|
22
29
|
},
|
|
23
30
|
"bugs": {
|
|
24
31
|
"url": "https://github.com/colkito/bitpay-rates/issues"
|
|
25
32
|
},
|
|
26
33
|
"homepage": "https://github.com/colkito/bitpay-rates#readme",
|
|
27
34
|
"scripts": {
|
|
28
|
-
"
|
|
29
|
-
"test
|
|
30
|
-
"test:
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
35
|
+
"verify": "npm run lint && npm run knip && npm test && npm run build && npm run smoke",
|
|
36
|
+
"test": "node --test src/index.test.mts scripts/codes-markdown.test.mts scripts/guard-protected-refs.test.mts",
|
|
37
|
+
"test:watch": "node --test --watch src/index.test.mts scripts/codes-markdown.test.mts scripts/guard-protected-refs.test.mts",
|
|
38
|
+
"test:coverage": "node --test --experimental-test-coverage src/index.test.mts scripts/codes-markdown.test.mts scripts/guard-protected-refs.test.mts",
|
|
39
|
+
"lint": "tsc --noEmit && biome check",
|
|
40
|
+
"format": "biome check --write",
|
|
41
|
+
"knip": "knip",
|
|
42
|
+
"build": "tsdown",
|
|
43
|
+
"smoke": "node scripts/smoke.mts",
|
|
44
|
+
"update-codes": "node scripts/update-codes.mts",
|
|
45
|
+
"prepare": "node scripts/install-git-hooks.mjs",
|
|
46
|
+
"prepublishOnly": "npm run build && npm run smoke"
|
|
47
|
+
},
|
|
48
|
+
"knip": {
|
|
49
|
+
"ignore": [
|
|
50
|
+
"example/**"
|
|
51
|
+
]
|
|
38
52
|
},
|
|
39
53
|
"devDependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"@types/node": "
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"eslint-config-prettier": "^9.1.0",
|
|
46
|
-
"eslint-plugin-prettier": "^5.2.1",
|
|
47
|
-
"jest": "^29.7.0",
|
|
48
|
-
"prettier": "^3.4.2",
|
|
49
|
-
"ts-jest": "^29.2.5",
|
|
50
|
-
"typescript": "^5.7.2"
|
|
54
|
+
"@biomejs/biome": "2.5.13",
|
|
55
|
+
"@types/node": "22.20.2",
|
|
56
|
+
"knip": "6.35.1",
|
|
57
|
+
"tsdown": "0.23.0",
|
|
58
|
+
"typescript": "7.0.2"
|
|
51
59
|
},
|
|
60
|
+
"sideEffects": false,
|
|
52
61
|
"files": [
|
|
53
|
-
"dist
|
|
54
|
-
]
|
|
62
|
+
"dist"
|
|
63
|
+
],
|
|
64
|
+
"devEngines": {
|
|
65
|
+
"runtime": {
|
|
66
|
+
"name": "node",
|
|
67
|
+
"version": ">=22.18.0",
|
|
68
|
+
"onFail": "error"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
55
71
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export type RateObj = {
|
|
2
|
-
code: string;
|
|
3
|
-
name: string;
|
|
4
|
-
rate: number;
|
|
5
|
-
};
|
|
6
|
-
export type RateResponse = RateObj | RateObj[];
|
|
7
|
-
export type Callback = (err: Error | null, data?: RateResponse) => void;
|
|
8
|
-
export declare function get(code?: string): Promise<RateResponse>;
|
|
9
|
-
export declare function get(code: string, cb: Callback): void;
|
|
10
|
-
export declare function get(cb: Callback): void;
|
|
11
|
-
export default get;
|
package/dist/index.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.get = get;
|
|
7
|
-
const https_1 = __importDefault(require("https"));
|
|
8
|
-
function get(codeOrCb, cb) {
|
|
9
|
-
const code = typeof codeOrCb === 'string' ? codeOrCb : undefined;
|
|
10
|
-
const callback = typeof codeOrCb === 'function' ? codeOrCb : cb;
|
|
11
|
-
const p = new Promise((resolve, reject) => {
|
|
12
|
-
https_1.default
|
|
13
|
-
.get(`https://bitpay.com/api/rates${code ? `/${code.toUpperCase()}` : ''}`, (res) => {
|
|
14
|
-
let d = '';
|
|
15
|
-
res.on('data', (c) => (d += c));
|
|
16
|
-
res.on('end', () => {
|
|
17
|
-
var _a;
|
|
18
|
-
try {
|
|
19
|
-
const json = JSON.parse(d);
|
|
20
|
-
if (json.error)
|
|
21
|
-
reject(new Error(json.error));
|
|
22
|
-
else
|
|
23
|
-
resolve((_a = json.data) !== null && _a !== void 0 ? _a : json);
|
|
24
|
-
}
|
|
25
|
-
catch (e) {
|
|
26
|
-
reject(e);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
})
|
|
30
|
-
.on('error', reject);
|
|
31
|
-
});
|
|
32
|
-
if (callback) {
|
|
33
|
-
p.then((data) => callback(null, data)).catch((err) => callback(err));
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
return p;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.default = get;
|