@bitgen/sdk 0.1.6 → 1.0.3
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 +55 -2
- package/README.md +27 -106
- package/dist/cjs/client.d.ts +20 -8
- package/dist/cjs/client.d.ts.map +1 -1
- package/dist/cjs/client.js +33 -12
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/constants.d.ts +256 -0
- package/dist/cjs/constants.d.ts.map +1 -0
- package/dist/cjs/constants.js +214 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/error.d.ts +17 -10
- package/dist/cjs/error.d.ts.map +1 -1
- package/dist/cjs/error.js +25 -7
- package/dist/cjs/error.js.map +1 -1
- package/dist/cjs/http.d.ts +13 -8
- package/dist/cjs/http.d.ts.map +1 -1
- package/dist/cjs/http.js +135 -44
- package/dist/cjs/http.js.map +1 -1
- package/dist/cjs/index.d.ts +14 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +30 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/resources/apikeys.d.ts +18 -0
- package/dist/cjs/resources/apikeys.d.ts.map +1 -0
- package/dist/cjs/resources/apikeys.js +31 -0
- package/dist/cjs/resources/apikeys.js.map +1 -0
- package/dist/cjs/resources/asset.d.ts +17 -5
- package/dist/cjs/resources/asset.d.ts.map +1 -1
- package/dist/cjs/resources/asset.js +17 -6
- package/dist/cjs/resources/asset.js.map +1 -1
- package/dist/cjs/resources/bank.d.ts +11 -6
- package/dist/cjs/resources/bank.d.ts.map +1 -1
- package/dist/cjs/resources/bank.js +17 -9
- package/dist/cjs/resources/bank.js.map +1 -1
- package/dist/cjs/resources/core.d.ts +12 -0
- package/dist/cjs/resources/core.d.ts.map +1 -0
- package/dist/cjs/resources/core.js +22 -0
- package/dist/cjs/resources/core.js.map +1 -0
- package/dist/cjs/resources/custody.d.ts +27 -0
- package/dist/cjs/resources/custody.d.ts.map +1 -0
- package/dist/cjs/resources/custody.js +38 -0
- package/dist/cjs/resources/custody.js.map +1 -0
- package/dist/cjs/resources/customer.d.ts +20 -0
- package/dist/cjs/resources/customer.d.ts.map +1 -0
- package/dist/cjs/resources/customer.js +38 -0
- package/dist/cjs/resources/customer.js.map +1 -0
- package/dist/cjs/resources/staking.d.ts +32 -0
- package/dist/cjs/resources/staking.d.ts.map +1 -0
- package/dist/cjs/resources/staking.js +69 -0
- package/dist/cjs/resources/staking.js.map +1 -0
- package/dist/cjs/resources/trading.d.ts +24 -0
- package/dist/cjs/resources/trading.d.ts.map +1 -0
- package/dist/cjs/resources/trading.js +41 -0
- package/dist/cjs/resources/trading.js.map +1 -0
- package/dist/cjs/resources/transaction.d.ts +6 -9
- package/dist/cjs/resources/transaction.d.ts.map +1 -1
- package/dist/cjs/resources/transaction.js +10 -15
- package/dist/cjs/resources/transaction.js.map +1 -1
- package/dist/cjs/resources/webhooks.d.ts +46 -0
- package/dist/cjs/resources/webhooks.d.ts.map +1 -0
- package/dist/cjs/resources/webhooks.js +142 -0
- package/dist/cjs/resources/webhooks.js.map +1 -0
- package/dist/cjs/types/apikeys.d.ts +43 -0
- package/dist/cjs/types/apikeys.d.ts.map +1 -0
- package/dist/cjs/types/apikeys.js +3 -0
- package/dist/cjs/types/apikeys.js.map +1 -0
- package/dist/cjs/types/asset.d.ts +57 -0
- package/dist/cjs/types/asset.d.ts.map +1 -0
- package/dist/cjs/types/asset.js +3 -0
- package/dist/cjs/types/asset.js.map +1 -0
- package/dist/cjs/types/bank.d.ts +58 -0
- package/dist/cjs/types/bank.d.ts.map +1 -0
- package/dist/cjs/types/bank.js +3 -0
- package/dist/cjs/types/bank.js.map +1 -0
- package/dist/cjs/types/core.d.ts +32 -0
- package/dist/cjs/types/core.d.ts.map +1 -0
- package/dist/cjs/types/core.js +3 -0
- package/dist/cjs/types/core.js.map +1 -0
- package/dist/cjs/types/custody.d.ts +50 -0
- package/dist/cjs/types/custody.d.ts.map +1 -0
- package/dist/cjs/types/custody.js +3 -0
- package/dist/cjs/types/custody.js.map +1 -0
- package/dist/cjs/types/customer.d.ts +190 -0
- package/dist/cjs/types/customer.d.ts.map +1 -0
- package/dist/cjs/types/customer.js +3 -0
- package/dist/cjs/types/customer.js.map +1 -0
- package/dist/cjs/types/index.d.ts +78 -194
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/index.js +0 -1
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/staking.d.ts +88 -0
- package/dist/cjs/types/staking.d.ts.map +1 -0
- package/dist/cjs/types/staking.js +3 -0
- package/dist/cjs/types/staking.js.map +1 -0
- package/dist/cjs/types/trading.d.ts +51 -0
- package/dist/cjs/types/trading.d.ts.map +1 -0
- package/dist/cjs/types/trading.js +3 -0
- package/dist/cjs/types/trading.js.map +1 -0
- package/dist/cjs/types/transaction.d.ts +61 -0
- package/dist/cjs/types/transaction.d.ts.map +1 -0
- package/dist/cjs/types/transaction.js +3 -0
- package/dist/cjs/types/transaction.js.map +1 -0
- package/dist/cjs/types/webhooks.d.ts +55 -0
- package/dist/cjs/types/webhooks.d.ts.map +1 -0
- package/dist/cjs/types/webhooks.js +3 -0
- package/dist/cjs/types/webhooks.js.map +1 -0
- package/dist/cjs/utils.d.ts +21 -2
- package/dist/cjs/utils.d.ts.map +1 -1
- package/dist/cjs/utils.js +67 -4
- package/dist/cjs/utils.js.map +1 -1
- package/dist/cjs/version.d.ts +2 -0
- package/dist/cjs/version.d.ts.map +1 -0
- package/dist/cjs/version.js +6 -0
- package/dist/cjs/version.js.map +1 -0
- package/dist/esm/client.d.ts +20 -8
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +33 -12
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/constants.d.ts +256 -0
- package/dist/esm/constants.d.ts.map +1 -0
- package/dist/esm/constants.js +211 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/error.d.ts +17 -10
- package/dist/esm/error.d.ts.map +1 -1
- package/dist/esm/error.js +24 -6
- package/dist/esm/error.js.map +1 -1
- package/dist/esm/http.d.ts +13 -8
- package/dist/esm/http.d.ts.map +1 -1
- package/dist/esm/http.js +136 -45
- package/dist/esm/http.js.map +1 -1
- package/dist/esm/index.d.ts +14 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/resources/apikeys.d.ts +18 -0
- package/dist/esm/resources/apikeys.d.ts.map +1 -0
- package/dist/esm/resources/apikeys.js +27 -0
- package/dist/esm/resources/apikeys.js.map +1 -0
- package/dist/esm/resources/asset.d.ts +17 -5
- package/dist/esm/resources/asset.d.ts.map +1 -1
- package/dist/esm/resources/asset.js +17 -6
- package/dist/esm/resources/asset.js.map +1 -1
- package/dist/esm/resources/bank.d.ts +11 -6
- package/dist/esm/resources/bank.d.ts.map +1 -1
- package/dist/esm/resources/bank.js +18 -10
- package/dist/esm/resources/bank.js.map +1 -1
- package/dist/esm/resources/core.d.ts +12 -0
- package/dist/esm/resources/core.d.ts.map +1 -0
- package/dist/esm/resources/core.js +18 -0
- package/dist/esm/resources/core.js.map +1 -0
- package/dist/esm/resources/custody.d.ts +27 -0
- package/dist/esm/resources/custody.d.ts.map +1 -0
- package/dist/esm/resources/custody.js +34 -0
- package/dist/esm/resources/custody.js.map +1 -0
- package/dist/esm/resources/customer.d.ts +20 -0
- package/dist/esm/resources/customer.d.ts.map +1 -0
- package/dist/esm/resources/customer.js +34 -0
- package/dist/esm/resources/customer.js.map +1 -0
- package/dist/esm/resources/staking.d.ts +32 -0
- package/dist/esm/resources/staking.d.ts.map +1 -0
- package/dist/esm/resources/staking.js +65 -0
- package/dist/esm/resources/staking.js.map +1 -0
- package/dist/esm/resources/trading.d.ts +24 -0
- package/dist/esm/resources/trading.d.ts.map +1 -0
- package/dist/esm/resources/trading.js +37 -0
- package/dist/esm/resources/trading.js.map +1 -0
- package/dist/esm/resources/transaction.d.ts +6 -9
- package/dist/esm/resources/transaction.d.ts.map +1 -1
- package/dist/esm/resources/transaction.js +11 -16
- package/dist/esm/resources/transaction.js.map +1 -1
- package/dist/esm/resources/webhooks.d.ts +46 -0
- package/dist/esm/resources/webhooks.d.ts.map +1 -0
- package/dist/esm/resources/webhooks.js +138 -0
- package/dist/esm/resources/webhooks.js.map +1 -0
- package/dist/esm/types/apikeys.d.ts +43 -0
- package/dist/esm/types/apikeys.d.ts.map +1 -0
- package/dist/esm/types/apikeys.js +2 -0
- package/dist/esm/types/apikeys.js.map +1 -0
- package/dist/esm/types/asset.d.ts +57 -0
- package/dist/esm/types/asset.d.ts.map +1 -0
- package/dist/esm/types/asset.js +2 -0
- package/dist/esm/types/asset.js.map +1 -0
- package/dist/esm/types/bank.d.ts +58 -0
- package/dist/esm/types/bank.d.ts.map +1 -0
- package/dist/esm/types/bank.js +2 -0
- package/dist/esm/types/bank.js.map +1 -0
- package/dist/esm/types/core.d.ts +32 -0
- package/dist/esm/types/core.d.ts.map +1 -0
- package/dist/esm/types/core.js +2 -0
- package/dist/esm/types/core.js.map +1 -0
- package/dist/esm/types/custody.d.ts +50 -0
- package/dist/esm/types/custody.d.ts.map +1 -0
- package/dist/esm/types/custody.js +2 -0
- package/dist/esm/types/custody.js.map +1 -0
- package/dist/esm/types/customer.d.ts +190 -0
- package/dist/esm/types/customer.d.ts.map +1 -0
- package/dist/esm/types/customer.js +2 -0
- package/dist/esm/types/customer.js.map +1 -0
- package/dist/esm/types/index.d.ts +78 -194
- package/dist/esm/types/index.d.ts.map +1 -1
- package/dist/esm/types/index.js +0 -1
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/types/staking.d.ts +88 -0
- package/dist/esm/types/staking.d.ts.map +1 -0
- package/dist/esm/types/staking.js +2 -0
- package/dist/esm/types/staking.js.map +1 -0
- package/dist/esm/types/trading.d.ts +51 -0
- package/dist/esm/types/trading.d.ts.map +1 -0
- package/dist/esm/types/trading.js +2 -0
- package/dist/esm/types/trading.js.map +1 -0
- package/dist/esm/types/transaction.d.ts +61 -0
- package/dist/esm/types/transaction.d.ts.map +1 -0
- package/dist/esm/types/transaction.js +2 -0
- package/dist/esm/types/transaction.js.map +1 -0
- package/dist/esm/types/webhooks.d.ts +55 -0
- package/dist/esm/types/webhooks.d.ts.map +1 -0
- package/dist/esm/types/webhooks.js +2 -0
- package/dist/esm/types/webhooks.js.map +1 -0
- package/dist/esm/utils.d.ts +21 -2
- package/dist/esm/utils.d.ts.map +1 -1
- package/dist/esm/utils.js +62 -4
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/version.d.ts +2 -0
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +3 -0
- package/dist/esm/version.js.map +1 -0
- package/package.json +29 -12
- package/readme/concepts.md +104 -0
- package/readme/configuration.md +72 -0
- package/readme/errors.md +67 -0
- package/readme/installation.md +43 -0
- package/readme/quick-start.md +87 -0
- package/readme/resource/apikeys.md +103 -0
- package/readme/resource/asset.md +121 -0
- package/readme/resource/bank.md +156 -0
- package/readme/resource/core.md +91 -0
- package/readme/resource/custody.md +166 -0
- package/readme/resource/customer.md +208 -0
- package/readme/resource/staking.md +277 -0
- package/readme/resource/trading.md +166 -0
- package/readme/resource/transaction.md +106 -0
- package/readme/resource/webhooks.md +307 -0
- package/src/client.ts +46 -0
- package/src/constants.ts +281 -0
- package/src/error.ts +36 -0
- package/src/http.ts +201 -0
- package/src/index.ts +111 -0
- package/src/resources/apikeys.ts +30 -0
- package/src/resources/asset.ts +28 -0
- package/src/resources/bank.ts +39 -0
- package/src/resources/core.ts +19 -0
- package/src/resources/custody.ts +37 -0
- package/src/resources/customer.ts +46 -0
- package/src/resources/staking.ts +88 -0
- package/src/resources/trading.ts +41 -0
- package/src/resources/transaction.ts +20 -0
- package/src/resources/webhooks.ts +169 -0
- package/src/types/apikeys.ts +35 -0
- package/src/types/asset.ts +59 -0
- package/src/types/bank.ts +60 -0
- package/src/types/core.ts +32 -0
- package/src/types/custody.ts +40 -0
- package/src/types/customer.ts +189 -0
- package/src/types/index.ts +215 -0
- package/src/types/staking.ts +87 -0
- package/src/types/trading.ts +56 -0
- package/src/types/transaction.ts +62 -0
- package/src/types/webhooks.ts +60 -0
- package/src/utils.ts +74 -0
- package/src/version.ts +2 -0
- package/dist/cjs/resources/order.d.ts +0 -17
- package/dist/cjs/resources/order.d.ts.map +0 -1
- package/dist/cjs/resources/order.js +0 -30
- package/dist/cjs/resources/order.js.map +0 -1
- package/dist/cjs/resources/stats.d.ts +0 -11
- package/dist/cjs/resources/stats.d.ts.map +0 -1
- package/dist/cjs/resources/stats.js +0 -18
- package/dist/cjs/resources/stats.js.map +0 -1
- package/dist/cjs/resources/user.d.ts +0 -22
- package/dist/cjs/resources/user.d.ts.map +0 -1
- package/dist/cjs/resources/user.js +0 -37
- package/dist/cjs/resources/user.js.map +0 -1
- package/dist/cjs/resources/wallet.d.ts +0 -11
- package/dist/cjs/resources/wallet.d.ts.map +0 -1
- package/dist/cjs/resources/wallet.js +0 -19
- package/dist/cjs/resources/wallet.js.map +0 -1
- package/dist/esm/resources/order.d.ts +0 -17
- package/dist/esm/resources/order.d.ts.map +0 -1
- package/dist/esm/resources/order.js +0 -26
- package/dist/esm/resources/order.js.map +0 -1
- package/dist/esm/resources/stats.d.ts +0 -11
- package/dist/esm/resources/stats.d.ts.map +0 -1
- package/dist/esm/resources/stats.js +0 -14
- package/dist/esm/resources/stats.js.map +0 -1
- package/dist/esm/resources/user.d.ts +0 -22
- package/dist/esm/resources/user.d.ts.map +0 -1
- package/dist/esm/resources/user.js +0 -33
- package/dist/esm/resources/user.js.map +0 -1
- package/dist/esm/resources/wallet.d.ts +0 -11
- package/dist/esm/resources/wallet.d.ts.map +0 -1
- package/dist/esm/resources/wallet.js +0 -15
- package/dist/esm/resources/wallet.js.map +0 -1
- package/dist/types/client.d.ts +0 -19
- package/dist/types/client.d.ts.map +0 -1
- package/dist/types/error.d.ts +0 -15
- package/dist/types/error.d.ts.map +0 -1
- package/dist/types/http.d.ts +0 -21
- package/dist/types/http.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -4
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/resources/asset.d.ts +0 -11
- package/dist/types/resources/asset.d.ts.map +0 -1
- package/dist/types/resources/bank.d.ts +0 -13
- package/dist/types/resources/bank.d.ts.map +0 -1
- package/dist/types/resources/order.d.ts +0 -17
- package/dist/types/resources/order.d.ts.map +0 -1
- package/dist/types/resources/stats.d.ts +0 -11
- package/dist/types/resources/stats.d.ts.map +0 -1
- package/dist/types/resources/transaction.d.ts +0 -15
- package/dist/types/resources/transaction.d.ts.map +0 -1
- package/dist/types/resources/user.d.ts +0 -22
- package/dist/types/resources/user.d.ts.map +0 -1
- package/dist/types/resources/wallet.d.ts +0 -11
- package/dist/types/resources/wallet.d.ts.map +0 -1
- package/dist/types/types/index.d.ts +0 -213
- package/dist/types/types/index.d.ts.map +0 -1
- package/dist/types/utils.d.ts +0 -7
- package/dist/types/utils.d.ts.map +0 -1
package/src/constants.ts
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/** Target environment — value goes in `BitgenConfig.env` (`env: Env.PRODUCTION`) */
|
|
2
|
+
export const Env = Object.freeze({
|
|
3
|
+
PRODUCTION: 'production',
|
|
4
|
+
SANDBOX: 'sandbox',
|
|
5
|
+
STAGING: 'staging',
|
|
6
|
+
LOCALHOST: 'localhost',
|
|
7
|
+
} as const)
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Asset ISO codes, accepted wherever an asset is expected (the API takes a uuid or an iso in any case).
|
|
11
|
+
* The `iso` returned by the API has its stored case (`ETH` today): compare it case-insensitively.
|
|
12
|
+
* Provisional list — extended once the production list is confirmed.
|
|
13
|
+
*/
|
|
14
|
+
export const Asset = Object.freeze({
|
|
15
|
+
BTC: 'btc',
|
|
16
|
+
ETH: 'eth',
|
|
17
|
+
USDC: 'usdc',
|
|
18
|
+
XRP: 'xrp',
|
|
19
|
+
SOL: 'sol',
|
|
20
|
+
} as const)
|
|
21
|
+
|
|
22
|
+
// ─── Enumerated values (mirror of the API's; value and type share the name, like `Env` and `Asset`) ─────
|
|
23
|
+
|
|
24
|
+
/** States of an API key — `Apikey.state`; `client.apikeys.list` leaves the `REVOKED` ones out unless `includeRevoked` */
|
|
25
|
+
export const ApikeyState = Object.freeze({
|
|
26
|
+
ENABLED: 'ENABLED',
|
|
27
|
+
REVOKED: 'REVOKED',
|
|
28
|
+
} as const)
|
|
29
|
+
/** The values of `ApikeyState` */
|
|
30
|
+
export type ApikeyState = (typeof ApikeyState)[keyof typeof ApikeyState]
|
|
31
|
+
|
|
32
|
+
/** States of an asset — `Asset.state` is a string, compare it with `AssetState.AVAILABLE` */
|
|
33
|
+
export const AssetState = Object.freeze({
|
|
34
|
+
AVAILABLE: 'AVAILABLE',
|
|
35
|
+
UNAVAILABLE: 'UNAVAILABLE',
|
|
36
|
+
ARCHIVED: 'ARCHIVED',
|
|
37
|
+
HIDDEN: 'HIDDEN',
|
|
38
|
+
} as const)
|
|
39
|
+
/** The values of `AssetState` */
|
|
40
|
+
export type AssetState = (typeof AssetState)[keyof typeof AssetState]
|
|
41
|
+
|
|
42
|
+
/** Filter of the EUR operations (`client.bank.operations`) — `ALL` (default), or one kind */
|
|
43
|
+
export const BankDirection = Object.freeze({
|
|
44
|
+
ALL: 'ALL',
|
|
45
|
+
DEPOSIT: 'DEPOSIT',
|
|
46
|
+
WITHDRAWAL: 'WITHDRAWAL',
|
|
47
|
+
PURCHASE: 'PURCHASE',
|
|
48
|
+
SELL: 'SELL',
|
|
49
|
+
} as const)
|
|
50
|
+
/** The values of `BankDirection` */
|
|
51
|
+
export type BankDirection = (typeof BankDirection)[keyof typeof BankDirection]
|
|
52
|
+
|
|
53
|
+
/** States of a connector — `Core.state`; also the `state` filter of `client.core.list` */
|
|
54
|
+
export const CoreState = Object.freeze({
|
|
55
|
+
ENABLED: 'ENABLED',
|
|
56
|
+
DISABLED: 'DISABLED',
|
|
57
|
+
} as const)
|
|
58
|
+
/** The values of `CoreState` */
|
|
59
|
+
export type CoreState = (typeof CoreState)[keyof typeof CoreState]
|
|
60
|
+
|
|
61
|
+
/** Kinds of connectors — `Core.type`; also the `type` filter of `client.core.list` */
|
|
62
|
+
export const CoreType = Object.freeze({
|
|
63
|
+
/** Identity verification service */
|
|
64
|
+
IDENTITY: 'IDENTITY',
|
|
65
|
+
/** Anti-money-laundering service */
|
|
66
|
+
AML: 'AML',
|
|
67
|
+
/** Exchange */
|
|
68
|
+
TRADING: 'TRADING',
|
|
69
|
+
/** Custodian */
|
|
70
|
+
CUSTODY: 'CUSTODY',
|
|
71
|
+
/** Staking provider */
|
|
72
|
+
STAKING: 'STAKING',
|
|
73
|
+
/** Bank */
|
|
74
|
+
RAMP: 'RAMP',
|
|
75
|
+
} as const)
|
|
76
|
+
/** The values of `CoreType` */
|
|
77
|
+
export type CoreType = (typeof CoreType)[keyof typeof CoreType]
|
|
78
|
+
|
|
79
|
+
/** States of a customer — `Customer.state`, compare it with `CustomerState.ENABLED` */
|
|
80
|
+
export const CustomerState = Object.freeze({
|
|
81
|
+
CREATED: 'CREATED',
|
|
82
|
+
ENABLED: 'ENABLED',
|
|
83
|
+
CLOSED: 'CLOSED',
|
|
84
|
+
FROZEN: 'FROZEN',
|
|
85
|
+
} as const)
|
|
86
|
+
/** The values of `CustomerState` */
|
|
87
|
+
export type CustomerState = (typeof CustomerState)[keyof typeof CustomerState]
|
|
88
|
+
|
|
89
|
+
/** `KYC` (a person) or `KYB` (a business) — `Identity.mode` */
|
|
90
|
+
export const IdentityMode = Object.freeze({
|
|
91
|
+
KYC: 'KYC',
|
|
92
|
+
KYB: 'KYB',
|
|
93
|
+
} as const)
|
|
94
|
+
/** The values of `IdentityMode` */
|
|
95
|
+
export type IdentityMode = (typeof IdentityMode)[keyof typeof IdentityMode]
|
|
96
|
+
|
|
97
|
+
/** States of an identity file — `Identity.state` */
|
|
98
|
+
export const IdentityState = Object.freeze({
|
|
99
|
+
CREATED: 'CREATED',
|
|
100
|
+
IN_PROGRESS: 'IN_PROGRESS',
|
|
101
|
+
WAIT: 'WAIT',
|
|
102
|
+
PENDING: 'PENDING',
|
|
103
|
+
VALIDATED: 'VALIDATED',
|
|
104
|
+
REJECTED: 'REJECTED',
|
|
105
|
+
FROZEN: 'FROZEN',
|
|
106
|
+
EXPIRED: 'EXPIRED',
|
|
107
|
+
CLOSED: 'CLOSED',
|
|
108
|
+
} as const)
|
|
109
|
+
/** The values of `IdentityState` */
|
|
110
|
+
export type IdentityState = (typeof IdentityState)[keyof typeof IdentityState]
|
|
111
|
+
|
|
112
|
+
/** Language of the BITGEN web application and of the emails — `Locale.FR` (default) or `Locale.EN` */
|
|
113
|
+
export const Locale = Object.freeze({
|
|
114
|
+
FR: 'FR',
|
|
115
|
+
EN: 'EN',
|
|
116
|
+
} as const)
|
|
117
|
+
/** The values of `Locale` */
|
|
118
|
+
export type Locale = (typeof Locale)[keyof typeof Locale]
|
|
119
|
+
|
|
120
|
+
/** Side of an order — `Order.side` */
|
|
121
|
+
export const OrderSide = Object.freeze({
|
|
122
|
+
BUY: 'BUY',
|
|
123
|
+
SELL: 'SELL',
|
|
124
|
+
} as const)
|
|
125
|
+
/** The values of `OrderSide` */
|
|
126
|
+
export type OrderSide = (typeof OrderSide)[keyof typeof OrderSide]
|
|
127
|
+
|
|
128
|
+
/** States of an order — `Order.state`. A purchase goes `REGISTERED` → `EXECUTING` → `FILLED` → `DELIVERING` → `DONE`; a sale `REGISTERED` → `TRANSFERRING` → `DEPOSITED` → `EXECUTING` → `FILLED` → `DONE`. `PARKED`: executed but nothing was received (terminal); `FAILED` */
|
|
129
|
+
export const OrderState = Object.freeze({
|
|
130
|
+
REGISTERED: 'REGISTERED',
|
|
131
|
+
TRANSFERRING: 'TRANSFERRING',
|
|
132
|
+
DEPOSITED: 'DEPOSITED',
|
|
133
|
+
EXECUTING: 'EXECUTING',
|
|
134
|
+
FILLED: 'FILLED',
|
|
135
|
+
DELIVERING: 'DELIVERING',
|
|
136
|
+
DONE: 'DONE',
|
|
137
|
+
PARKED: 'PARKED',
|
|
138
|
+
FAILED: 'FAILED',
|
|
139
|
+
} as const)
|
|
140
|
+
/** The values of `OrderState` */
|
|
141
|
+
export type OrderState = (typeof OrderState)[keyof typeof OrderState]
|
|
142
|
+
|
|
143
|
+
/** Category of a customer — the `organization` of `client.customer.create` (`CUSTOMER` by default; `B2B` also opens a KYB file) and `setup.choosenOrganization` */
|
|
144
|
+
export const OrganizationCategory = Object.freeze({
|
|
145
|
+
CUSTOMER: 'CUSTOMER',
|
|
146
|
+
B2B: 'B2B',
|
|
147
|
+
} as const)
|
|
148
|
+
/** The values of `OrganizationCategory` */
|
|
149
|
+
export type OrganizationCategory = (typeof OrganizationCategory)[keyof typeof OrganizationCategory]
|
|
150
|
+
|
|
151
|
+
/** Kinds of staking movements — `StakingMovement.kind`; also the `direction` filter of `client.staking.list` / `movements` */
|
|
152
|
+
export const StakingMovementKind = Object.freeze({
|
|
153
|
+
STAKE: 'STAKE',
|
|
154
|
+
UNSTAKE: 'UNSTAKE',
|
|
155
|
+
WITHDRAW: 'WITHDRAW',
|
|
156
|
+
REWARD: 'REWARD',
|
|
157
|
+
} as const)
|
|
158
|
+
/** The values of `StakingMovementKind` */
|
|
159
|
+
export type StakingMovementKind = (typeof StakingMovementKind)[keyof typeof StakingMovementKind]
|
|
160
|
+
|
|
161
|
+
/** States of a staking movement — `StakingMovement.state` */
|
|
162
|
+
export const StakingMovementState = Object.freeze({
|
|
163
|
+
REQUESTED: 'REQUESTED',
|
|
164
|
+
PENDING: 'PENDING',
|
|
165
|
+
COMPLETED: 'COMPLETED',
|
|
166
|
+
FAILED: 'FAILED',
|
|
167
|
+
CANCELED: 'CANCELED',
|
|
168
|
+
} as const)
|
|
169
|
+
/** The values of `StakingMovementState` */
|
|
170
|
+
export type StakingMovementState = (typeof StakingMovementState)[keyof typeof StakingMovementState]
|
|
171
|
+
|
|
172
|
+
/** States of a staking position — `StakingPosition.state` */
|
|
173
|
+
export const StakingPositionState = Object.freeze({
|
|
174
|
+
CREATED: 'CREATED',
|
|
175
|
+
ENABLED: 'ENABLED',
|
|
176
|
+
UNSTAKING: 'UNSTAKING',
|
|
177
|
+
CLOSED: 'CLOSED',
|
|
178
|
+
FAILED: 'FAILED',
|
|
179
|
+
} as const)
|
|
180
|
+
/** The values of `StakingPositionState` */
|
|
181
|
+
export type StakingPositionState = (typeof StakingPositionState)[keyof typeof StakingPositionState]
|
|
182
|
+
|
|
183
|
+
/** States of a webhook subscription (`Subscriber.state`) and of an event of the catalogue (`WebhookType.state`) — `ARCHIVED` ones are left out of `client.webhooks.list` unless `includeArchived` */
|
|
184
|
+
export const SubscriberState = Object.freeze({
|
|
185
|
+
ENABLED: 'ENABLED',
|
|
186
|
+
ARCHIVED: 'ARCHIVED',
|
|
187
|
+
} as const)
|
|
188
|
+
/** The values of `SubscriberState` */
|
|
189
|
+
export type SubscriberState = (typeof SubscriberState)[keyof typeof SubscriberState]
|
|
190
|
+
|
|
191
|
+
/** Filter of `client.trading.list`: only purchases, or only sales — lowercase, as the API expects it */
|
|
192
|
+
export const TradingDirection = Object.freeze({
|
|
193
|
+
BUY: 'buy',
|
|
194
|
+
SELL: 'sell',
|
|
195
|
+
} as const)
|
|
196
|
+
/** The values of `TradingDirection` */
|
|
197
|
+
export type TradingDirection = (typeof TradingDirection)[keyof typeof TradingDirection]
|
|
198
|
+
|
|
199
|
+
/** Direction of a transaction — `Transaction.direction`; also a filter of `client.transaction.list` */
|
|
200
|
+
export const TransactionDirection = Object.freeze({
|
|
201
|
+
IN: 'IN',
|
|
202
|
+
OUT: 'OUT',
|
|
203
|
+
} as const)
|
|
204
|
+
/** The values of `TransactionDirection` */
|
|
205
|
+
export type TransactionDirection = (typeof TransactionDirection)[keyof typeof TransactionDirection]
|
|
206
|
+
|
|
207
|
+
/** Where a transaction comes from: the EUR account (`BANK`) or a custody wallet (`CUSTODY`) — `Transaction.source`; also a filter of `client.transaction.list` */
|
|
208
|
+
export const TransactionSource = Object.freeze({
|
|
209
|
+
BANK: 'BANK',
|
|
210
|
+
CUSTODY: 'CUSTODY',
|
|
211
|
+
} as const)
|
|
212
|
+
/** The values of `TransactionSource` */
|
|
213
|
+
export type TransactionSource = (typeof TransactionSource)[keyof typeof TransactionSource]
|
|
214
|
+
|
|
215
|
+
/** States of a transaction (`TRANSFERING` is the API's spelling) — `Transaction.state`; also the `status` filter of `client.transaction.list` */
|
|
216
|
+
export const TransactionState = Object.freeze({
|
|
217
|
+
ANALYZING: 'ANALYZING',
|
|
218
|
+
PENDING: 'PENDING',
|
|
219
|
+
COMPLETED: 'COMPLETED',
|
|
220
|
+
FROZEN: 'FROZEN',
|
|
221
|
+
FAILED: 'FAILED',
|
|
222
|
+
TRANSFERING: 'TRANSFERING',
|
|
223
|
+
SEIZED: 'SEIZED',
|
|
224
|
+
} as const)
|
|
225
|
+
/** The values of `TransactionState` */
|
|
226
|
+
export type TransactionState = (typeof TransactionState)[keyof typeof TransactionState]
|
|
227
|
+
|
|
228
|
+
/** States of a wallet — `Wallet.state` */
|
|
229
|
+
export const WalletState = Object.freeze({
|
|
230
|
+
CREATED: 'CREATED',
|
|
231
|
+
FROZEN: 'FROZEN',
|
|
232
|
+
} as const)
|
|
233
|
+
/** The values of `WalletState` */
|
|
234
|
+
export type WalletState = (typeof WalletState)[keyof typeof WalletState]
|
|
235
|
+
|
|
236
|
+
/** `USER`: the wallet of a customer — `TREASURY`: a wallet of the organization itself (read-only). `Wallet.type` */
|
|
237
|
+
export const WalletType = Object.freeze({
|
|
238
|
+
USER: 'USER',
|
|
239
|
+
TREASURY: 'TREASURY',
|
|
240
|
+
} as const)
|
|
241
|
+
/** The values of `WalletType` */
|
|
242
|
+
export type WalletType = (typeof WalletType)[keyof typeof WalletType]
|
|
243
|
+
|
|
244
|
+
/** Events of the catalogue — `WebhookEvent.event` and `WebhookType.name` (the catalogue may grow: any string stays accepted); `client.webhooks.subscribe` takes a constant, any name or uuid of the catalogue, or a `WebhookType` */
|
|
245
|
+
export const WebhookEventName = Object.freeze({
|
|
246
|
+
USER_CREATED: 'user.created',
|
|
247
|
+
ORGANIZATION_CREATED: 'organization.created',
|
|
248
|
+
USER_IDENTITY_STARTED: 'user.identity.started',
|
|
249
|
+
USER_IDENTITY_PENDING: 'user.identity.pending',
|
|
250
|
+
USER_IDENTITY_STEP_VALIDATED: 'user.identity.step.validated',
|
|
251
|
+
USER_IDENTITY_STEP_REJECTED: 'user.identity.step.rejected',
|
|
252
|
+
USER_IDENTITY_STEP_REQUESTED: 'user.identity.step.requested',
|
|
253
|
+
USER_IDENTITY_VALIDATED: 'user.identity.validated',
|
|
254
|
+
USER_IDENTITY_RENEW: 'user.identity.renew',
|
|
255
|
+
USER_IDENTITY_REQUEST: 'user.identity.request',
|
|
256
|
+
ORGANIZATION_IDENTITY_STARTED: 'organization.identity.started',
|
|
257
|
+
ORGANIZATION_IDENTITY_PENDING: 'organization.identity.pending',
|
|
258
|
+
ORGANIZATION_IDENTITY_STEP_VALIDATED: 'organization.identity.step.validated',
|
|
259
|
+
ORGANIZATION_IDENTITY_STEP_REJECTED: 'organization.identity.step.rejected',
|
|
260
|
+
ORGANIZATION_IDENTITY_STEP_REQUESTED: 'organization.identity.step.requested',
|
|
261
|
+
ORGANIZATION_IDENTITY_VALIDATED: 'organization.identity.validated',
|
|
262
|
+
ORGANIZATION_IDENTITY_RENEW: 'organization.identity.renew',
|
|
263
|
+
ORGANIZATION_IDENTITY_REQUEST: 'organization.identity.request',
|
|
264
|
+
BANK_CREDITED: 'bank.credited',
|
|
265
|
+
BANK_DEBITED: 'bank.debited',
|
|
266
|
+
BANK_TRANSACTION: 'bank.transaction',
|
|
267
|
+
CUSTODY_TRANSACTION: 'custody.transaction',
|
|
268
|
+
CUSTODY_WALLET_CREATED: 'custody.wallet.created',
|
|
269
|
+
CUSTODY_SENT: 'custody.sent',
|
|
270
|
+
CUSTODY_RECEIVED: 'custody.received',
|
|
271
|
+
TRADING_BUY: 'trading.buy',
|
|
272
|
+
TRADING_SELL: 'trading.sell',
|
|
273
|
+
STAKING_REQUESTED: 'staking.requested',
|
|
274
|
+
STAKING_STATUS: 'staking.status',
|
|
275
|
+
STAKING_REWARDS: 'staking.rewards',
|
|
276
|
+
STAKING_CLAIMED: 'staking.claimed',
|
|
277
|
+
ALERT_OPENED: 'alert.opened',
|
|
278
|
+
ALERT_STATUS: 'alert.status',
|
|
279
|
+
} as const)
|
|
280
|
+
/** Known event names — the catalogue may grow: any string is accepted */
|
|
281
|
+
export type WebhookEventName = (typeof WebhookEventName)[keyof typeof WebhookEventName] | (string & {})
|
package/src/error.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { BitgenErrorBody } from './types/index.js'
|
|
2
|
+
|
|
3
|
+
/** Max length kept for `code`: the API sends short snake_case codes, anything longer is a foreign body (proxy page…) */
|
|
4
|
+
export const MAX_CODE_LENGTH = 200
|
|
5
|
+
|
|
6
|
+
/** Brand shared by every copy of the SDK loaded in a process (ESM and CJS builds side by side) */
|
|
7
|
+
const BRAND = Symbol.for('@bitgen/sdk:BitgenError')
|
|
8
|
+
|
|
9
|
+
export class BitgenError extends Error {
|
|
10
|
+
/** HTTP status code — `0` when no HTTP response was received (`request_timeout`, `network_error`) */
|
|
11
|
+
readonly status: number
|
|
12
|
+
/** Stable BITGEN error code (e.g. `invalid_amount`), or the raw response text (≤ 200 chars) when the API did not answer JSON */
|
|
13
|
+
readonly code: string
|
|
14
|
+
|
|
15
|
+
constructor(status: number, body: BitgenErrorBody, options?: { cause?: unknown }) {
|
|
16
|
+
const code = body.message.slice(0, MAX_CODE_LENGTH)
|
|
17
|
+
super(`[${status}] ${code}`, options)
|
|
18
|
+
this.name = 'BitgenError'
|
|
19
|
+
this.status = status
|
|
20
|
+
this.code = code
|
|
21
|
+
Object.defineProperty(this, BRAND, { value: true })
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** `instanceof` also recognizes a BitgenError thrown by another copy of the SDK (ESM and CJS builds loaded together) */
|
|
25
|
+
static override [Symbol.hasInstance](value: unknown): boolean {
|
|
26
|
+
if (Function.prototype[Symbol.hasInstance].call(this, value)) {
|
|
27
|
+
return true
|
|
28
|
+
}
|
|
29
|
+
return this === BitgenError && typeof value === 'object' && value !== null && BRAND in value
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** `JSON.stringify(err)` → `{ name, message, status, code }` (`cause` is left out) */
|
|
33
|
+
toJSON(): { name: string, message: string, status: number, code: string } {
|
|
34
|
+
return { name: this.name, message: this.message, status: this.status, code: this.code }
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/http.ts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { Env } from './constants.js'
|
|
2
|
+
import { BitgenError, MAX_CODE_LENGTH } from './error.js'
|
|
3
|
+
import type { BitgenConfig, BitgenErrorBody } from './types/index.js'
|
|
4
|
+
import { VERSION } from './version.js'
|
|
5
|
+
|
|
6
|
+
const LOCALHOST_PORT = 3002
|
|
7
|
+
|
|
8
|
+
/** Default request timeout, in seconds (`BitgenConfig.timeout`) */
|
|
9
|
+
const DEFAULT_TIMEOUT = 30
|
|
10
|
+
/** Largest timeout, in seconds: `setTimeout` — hence `AbortSignal.timeout` — accepts at most 2^31 − 1 ms */
|
|
11
|
+
const MAX_TIMEOUT = 2_147_483
|
|
12
|
+
|
|
13
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'
|
|
14
|
+
|
|
15
|
+
/** Query string entries — `undefined` and `null` are skipped */
|
|
16
|
+
export type Query = Record<string, string | number | boolean | null | undefined>
|
|
17
|
+
|
|
18
|
+
interface RequestOptions {
|
|
19
|
+
method?: HttpMethod
|
|
20
|
+
body?: unknown
|
|
21
|
+
query?: Query | undefined
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class HttpClient {
|
|
25
|
+
/** Organization uuid of the key — resources use it where the API expects the organization */
|
|
26
|
+
readonly scope: string
|
|
27
|
+
private readonly baseUrl: string
|
|
28
|
+
private readonly headers: Record<string, string>
|
|
29
|
+
/** Request timeout in milliseconds (`BitgenConfig.timeout` × 1000), `0` = none */
|
|
30
|
+
private readonly timeout: number
|
|
31
|
+
|
|
32
|
+
constructor(config: BitgenConfig) {
|
|
33
|
+
if (typeof fetch !== 'function') {
|
|
34
|
+
throw new Error('@bitgen/sdk needs a global fetch: use Node.js 20 or later')
|
|
35
|
+
}
|
|
36
|
+
requireHeaderValue(config.scope, 'scope')
|
|
37
|
+
requireHeaderValue(config.apiKey, 'apiKey')
|
|
38
|
+
|
|
39
|
+
this.scope = config.scope
|
|
40
|
+
this.baseUrl = resolveBaseUrl(config)
|
|
41
|
+
this.timeout = resolveTimeout(config.timeout)
|
|
42
|
+
this.headers = {
|
|
43
|
+
'Content-Type': 'application/json',
|
|
44
|
+
'User-Agent': `bitgen-sdk-nodejs/${VERSION}`,
|
|
45
|
+
'BITGEN-Scope': config.scope,
|
|
46
|
+
'Api-key': config.apiKey,
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async request<T>(path: string, options: RequestOptions = {}): Promise<T> {
|
|
51
|
+
const { method = 'GET', body, query } = options
|
|
52
|
+
|
|
53
|
+
// Build URL with optional query params — undefined and null entries are skipped
|
|
54
|
+
const url = new URL(path, this.baseUrl)
|
|
55
|
+
if (query) {
|
|
56
|
+
for (const [key, value] of Object.entries(query)) {
|
|
57
|
+
if (value !== undefined && value !== null) {
|
|
58
|
+
url.searchParams.set(key, String(value))
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Redirects are never followed: the API does not redirect, and following one would replay the key to another host
|
|
64
|
+
const init: RequestInit = { method, headers: this.headers, redirect: 'manual' }
|
|
65
|
+
if (body !== undefined) {
|
|
66
|
+
init.body = JSON.stringify(body)
|
|
67
|
+
}
|
|
68
|
+
const signal = this.timeout > 0 ? AbortSignal.timeout(this.timeout) : undefined
|
|
69
|
+
if (signal) {
|
|
70
|
+
init.signal = signal
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let response: Response
|
|
74
|
+
let text: string
|
|
75
|
+
try {
|
|
76
|
+
response = await fetch(url, init)
|
|
77
|
+
text = response.status === 204 ? '' : await response.text()
|
|
78
|
+
} catch (cause) {
|
|
79
|
+
// No HTTP response at all: our own timeout fired, or the network failed (DNS, refused, TLS…)
|
|
80
|
+
const code = signal?.aborted ? 'request_timeout' : 'network_error'
|
|
81
|
+
throw new BitgenError(0, { error: true, message: code, code: 0 }, { cause })
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// v4 sends the real HTTP status: anything outside 2xx is an error
|
|
85
|
+
if (!response.ok) {
|
|
86
|
+
throw new BitgenError(response.status, parseErrorBody(text) ?? rawBody(text, response))
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// 204 No Content or empty body — nothing to parse
|
|
90
|
+
if (text.trim() === '') {
|
|
91
|
+
return undefined as unknown as T
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
return JSON.parse(text) as T
|
|
96
|
+
} catch {
|
|
97
|
+
// A 2xx that is not JSON (proxy page…): reported like a non-JSON error, never rethrown raw
|
|
98
|
+
throw new BitgenError(response.status, rawBody(text, response))
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
get<T>(path: string, query?: Query): Promise<T> {
|
|
103
|
+
return this.request<T>(path, { method: 'GET', query })
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
post<T>(path: string, body?: unknown): Promise<T> {
|
|
107
|
+
return this.request<T>(path, { method: 'POST', body })
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
put<T>(path: string, body?: unknown): Promise<T> {
|
|
111
|
+
return this.request<T>(path, { method: 'PUT', body })
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
patch<T>(path: string, body?: unknown): Promise<T> {
|
|
115
|
+
return this.request<T>(path, { method: 'PATCH', body })
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
delete<T>(path: string, body?: unknown): Promise<T> {
|
|
119
|
+
return this.request<T>(path, { method: 'DELETE', body })
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Fails fast on a missing, empty or non-printable-ASCII header value — never echoes the value itself */
|
|
124
|
+
function requireHeaderValue(value: unknown, name: string): void {
|
|
125
|
+
if (typeof value !== 'string' || value.trim() === '') {
|
|
126
|
+
throw new TypeError(`BitgenConfig.${name} must be a non-empty string`)
|
|
127
|
+
}
|
|
128
|
+
if (!/^[\x20-\x7E]+$/.test(value)) {
|
|
129
|
+
throw new TypeError(`BitgenConfig.${name} contains invalid characters (printable ASCII expected)`)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Seconds from the config → integer milliseconds for `AbortSignal.timeout` (`0` = no timeout, any positive value ≥ 1 ms) */
|
|
134
|
+
function resolveTimeout(value: number | undefined): number {
|
|
135
|
+
const seconds = value === undefined ? DEFAULT_TIMEOUT : value
|
|
136
|
+
if (typeof seconds !== 'number' || !Number.isFinite(seconds) || seconds < 0 || seconds > MAX_TIMEOUT) {
|
|
137
|
+
throw new TypeError(`BitgenConfig.timeout must be a number of seconds between 0 (no timeout) and ${MAX_TIMEOUT}`)
|
|
138
|
+
}
|
|
139
|
+
return seconds === 0 ? 0 : Math.max(1, Math.round(seconds * 1000))
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function resolveBaseUrl(config: BitgenConfig): string {
|
|
143
|
+
if (config.port !== undefined && (!Number.isInteger(config.port) || config.port < 1 || config.port > 65535)) {
|
|
144
|
+
throw new TypeError('BitgenConfig.port must be an integer between 1 and 65535')
|
|
145
|
+
}
|
|
146
|
+
const base = resolveBase(config)
|
|
147
|
+
try {
|
|
148
|
+
new URL(base)
|
|
149
|
+
} catch {
|
|
150
|
+
throw new TypeError('BitgenConfig.host and port do not form a valid URL')
|
|
151
|
+
}
|
|
152
|
+
return base
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function resolveBase(config: BitgenConfig): string {
|
|
156
|
+
// Custom host (e.g. Docker container): bare hostname, scheme and port come from isSsl / port
|
|
157
|
+
if (config.host !== undefined) {
|
|
158
|
+
// Letters, digits, dots, hyphens (and underscores of internal DNS names): a scheme, a port, a path, userinfo (`me@attacker`) or a bracketed IPv6 are refused
|
|
159
|
+
if (typeof config.host !== 'string' || !/^[A-Za-z0-9._-]+$/.test(config.host)) {
|
|
160
|
+
throw new TypeError('BitgenConfig.host must be a bare hostname (no scheme, port or path): use port and isSsl')
|
|
161
|
+
}
|
|
162
|
+
const port = config.port ?? 80
|
|
163
|
+
const scheme = config.isSsl !== false ? 'https' : 'http'
|
|
164
|
+
return `${scheme}://${config.host}:${port}`
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const env = config.env ?? Env.PRODUCTION
|
|
168
|
+
switch (env) {
|
|
169
|
+
case Env.PRODUCTION: return 'https://api.bitgen.com'
|
|
170
|
+
case Env.SANDBOX: return 'https://api.sandbox.bitgen.com'
|
|
171
|
+
case Env.STAGING: return 'https://api.staging.btgn.dev'
|
|
172
|
+
case Env.LOCALHOST: return `http://localhost:${config.port ?? LOCALHOST_PORT}`
|
|
173
|
+
default:
|
|
174
|
+
// The value given is not echoed: a config mix-up must not leak into logs
|
|
175
|
+
throw new TypeError(`BitgenConfig.env must be one of ${Object.values(Env).join(', ')} (see Env)`)
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Error body built from a non-JSON response: the raw text, truncated, stands for the code */
|
|
180
|
+
function rawBody(text: string, response: Response): BitgenErrorBody {
|
|
181
|
+
const message = text.trim().slice(0, MAX_CODE_LENGTH) || response.statusText || String(response.status)
|
|
182
|
+
return { error: true, message, code: response.status }
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Returns the parsed body when it is a v4 error payload `{ error: true, message, code }`, null otherwise */
|
|
186
|
+
function parseErrorBody(text: string): BitgenErrorBody | null {
|
|
187
|
+
try {
|
|
188
|
+
const data: unknown = JSON.parse(text)
|
|
189
|
+
if (
|
|
190
|
+
typeof data === 'object' &&
|
|
191
|
+
data !== null &&
|
|
192
|
+
(data as { error?: unknown }).error === true &&
|
|
193
|
+
typeof (data as { message?: unknown }).message === 'string'
|
|
194
|
+
) {
|
|
195
|
+
return data as BitgenErrorBody
|
|
196
|
+
}
|
|
197
|
+
} catch {
|
|
198
|
+
// not JSON
|
|
199
|
+
}
|
|
200
|
+
return null
|
|
201
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Env, Asset as AssetCodes } from './constants.js'
|
|
2
|
+
import type { Asset as AssetType } from './types/index.js'
|
|
3
|
+
|
|
4
|
+
export { BitgenClient } from './client.js'
|
|
5
|
+
export { BitgenError } from './error.js'
|
|
6
|
+
export { Env }
|
|
7
|
+
|
|
8
|
+
// Enumerated values — each name is both the frozen object of constants and the type of its values (`CoreType.STAKING`)
|
|
9
|
+
export {
|
|
10
|
+
ApikeyState,
|
|
11
|
+
AssetState,
|
|
12
|
+
BankDirection,
|
|
13
|
+
CoreState,
|
|
14
|
+
CoreType,
|
|
15
|
+
CustomerState,
|
|
16
|
+
IdentityMode,
|
|
17
|
+
IdentityState,
|
|
18
|
+
Locale,
|
|
19
|
+
OrderSide,
|
|
20
|
+
OrderState,
|
|
21
|
+
OrganizationCategory,
|
|
22
|
+
StakingMovementKind,
|
|
23
|
+
StakingMovementState,
|
|
24
|
+
StakingPositionState,
|
|
25
|
+
SubscriberState,
|
|
26
|
+
TradingDirection,
|
|
27
|
+
TransactionDirection,
|
|
28
|
+
TransactionSource,
|
|
29
|
+
TransactionState,
|
|
30
|
+
WalletState,
|
|
31
|
+
WalletType,
|
|
32
|
+
WebhookEventName,
|
|
33
|
+
} from './constants.js'
|
|
34
|
+
|
|
35
|
+
/** Asset ISO codes (`Asset.ETH`) — `Asset` is also the type of an asset returned by `client.asset` */
|
|
36
|
+
export const Asset = AssetCodes
|
|
37
|
+
export type Asset = AssetType
|
|
38
|
+
|
|
39
|
+
export type {
|
|
40
|
+
BitgenConfig,
|
|
41
|
+
BitgenEnv,
|
|
42
|
+
UserRef,
|
|
43
|
+
Amount,
|
|
44
|
+
PageParams,
|
|
45
|
+
Page,
|
|
46
|
+
BitgenErrorBody,
|
|
47
|
+
History,
|
|
48
|
+
Created,
|
|
49
|
+
AssetRef,
|
|
50
|
+
AssetInput,
|
|
51
|
+
UserSummary,
|
|
52
|
+
OrganizationHub,
|
|
53
|
+
OrganizationSummary,
|
|
54
|
+
AssetTicker,
|
|
55
|
+
AssetFees,
|
|
56
|
+
AssetNetwork,
|
|
57
|
+
AssetNetworkType,
|
|
58
|
+
KycIdentity,
|
|
59
|
+
KybIdentity,
|
|
60
|
+
Identity,
|
|
61
|
+
CustomerAccount,
|
|
62
|
+
CustomerClient,
|
|
63
|
+
CustomerSetup,
|
|
64
|
+
CollaboratorLink,
|
|
65
|
+
ManagerLink,
|
|
66
|
+
CustomerAlert,
|
|
67
|
+
CustomerBusiness,
|
|
68
|
+
Customer,
|
|
69
|
+
AccountAddress,
|
|
70
|
+
Account,
|
|
71
|
+
CreateCustomerParams,
|
|
72
|
+
CustomerListParams,
|
|
73
|
+
UpdateCustomerParams,
|
|
74
|
+
BankAccount,
|
|
75
|
+
BankOperation,
|
|
76
|
+
BankOperationsParams,
|
|
77
|
+
BankWithdrawParams,
|
|
78
|
+
BankCreditParams,
|
|
79
|
+
Wallet,
|
|
80
|
+
CustodyPortfolio,
|
|
81
|
+
TravelRule,
|
|
82
|
+
CustodyWithdrawParams,
|
|
83
|
+
OrderUser,
|
|
84
|
+
OrderOrganization,
|
|
85
|
+
Order,
|
|
86
|
+
TradingOrderParams,
|
|
87
|
+
TradingListParams,
|
|
88
|
+
TransactionAlert,
|
|
89
|
+
Transaction,
|
|
90
|
+
TransactionListParams,
|
|
91
|
+
CoreConfigField,
|
|
92
|
+
Core,
|
|
93
|
+
CoreListParams,
|
|
94
|
+
CoreRef,
|
|
95
|
+
StakingPosition,
|
|
96
|
+
StakingMovement,
|
|
97
|
+
StakingOperation,
|
|
98
|
+
StakingPortfolio,
|
|
99
|
+
StakeParams,
|
|
100
|
+
StakingListParams,
|
|
101
|
+
StakingAmountParams,
|
|
102
|
+
WebhookType,
|
|
103
|
+
Subscriber,
|
|
104
|
+
WebhookSubscriptions,
|
|
105
|
+
DeliveryLog,
|
|
106
|
+
WebhookEvent,
|
|
107
|
+
VerifyInput,
|
|
108
|
+
Apikey,
|
|
109
|
+
ApikeyLog,
|
|
110
|
+
ApikeyListParams,
|
|
111
|
+
} from './types/index.js'
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { HttpClient } from '../http.js'
|
|
2
|
+
import type { Apikey, ApikeyListParams, ApikeyLog, Page, PageParams } from '../types/index.js'
|
|
3
|
+
import { idOf, pathSegment } from '../utils.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `/organization/{scope}/apikeys` — permission `apikey.read`, read-only: a key cannot be created
|
|
7
|
+
* through the API (and the SDK does not revoke). `{organization}` is always the key's scope.
|
|
8
|
+
*/
|
|
9
|
+
export class ApikeysResource {
|
|
10
|
+
constructor(private readonly http: HttpClient) {}
|
|
11
|
+
|
|
12
|
+
/** Keys of the organization — revoked ones with `includeRevoked` */
|
|
13
|
+
async list(params: ApikeyListParams = {}): Promise<Page<Apikey>> {
|
|
14
|
+
return await this.http.get(`/organization/${this.organization()}/apikeys`, { ...params })
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** One key by uuid, or by model */
|
|
18
|
+
async get(apikey: string | Apikey): Promise<Apikey> {
|
|
19
|
+
return await this.http.get(`/organization/${this.organization()}/apikeys/${pathSegment(idOf(apikey, 'apikey'), 'apikey')}`)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Calls made with the key: path, inputs (PII masked), status, error */
|
|
23
|
+
async logs(apikey: string | Apikey, params: PageParams = {}): Promise<Page<ApikeyLog>> {
|
|
24
|
+
return await this.http.get(`/organization/${this.organization()}/apikeys/${pathSegment(idOf(apikey, 'apikey'), 'apikey')}/logs`, { ...params })
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private organization(): string {
|
|
28
|
+
return pathSegment(this.http.scope, 'scope')
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { HttpClient } from '../http.js'
|
|
2
|
+
import type { Asset, AssetInput, AssetTicker, History, Page } from '../types/index.js'
|
|
3
|
+
import { assetId, pathSegment } from '../utils.js'
|
|
4
|
+
|
|
5
|
+
/** `/asset`, `/ticker` — permission `asset.read` */
|
|
6
|
+
export class AssetResource {
|
|
7
|
+
constructor(private readonly http: HttpClient) {}
|
|
8
|
+
|
|
9
|
+
/** List all assets */
|
|
10
|
+
async list(): Promise<Page<Asset>> {
|
|
11
|
+
return await this.http.get('/asset')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Get one asset by uuid or ISO code (any case, sent as is — `Asset.ETH`), or by model (its uuid is sent) */
|
|
15
|
+
async get(asset: AssetInput): Promise<Asset> {
|
|
16
|
+
return await this.http.get(`/asset/${pathSegment(assetId(asset), 'asset')}`)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Tickers of all assets */
|
|
20
|
+
async tickers(): Promise<Page<{ iso: string, ticker: AssetTicker }>> {
|
|
21
|
+
return await this.http.get('/ticker')
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Ticker and EUR price history of one asset, by ISO code */
|
|
25
|
+
async ticker(iso: string): Promise<{ iso: string, ticker: AssetTicker, history: History }> {
|
|
26
|
+
return await this.http.get(`/ticker/${pathSegment(iso, 'iso')}`)
|
|
27
|
+
}
|
|
28
|
+
}
|