@bitgen/sdk 0.1.6 → 1.0.4

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.
Files changed (338) hide show
  1. package/CHANGELOG.md +63 -2
  2. package/README.md +27 -106
  3. package/dist/cjs/client.d.ts +20 -8
  4. package/dist/cjs/client.d.ts.map +1 -1
  5. package/dist/cjs/client.js +33 -12
  6. package/dist/cjs/client.js.map +1 -1
  7. package/dist/cjs/constants.d.ts +256 -0
  8. package/dist/cjs/constants.d.ts.map +1 -0
  9. package/dist/cjs/constants.js +214 -0
  10. package/dist/cjs/constants.js.map +1 -0
  11. package/dist/cjs/error.d.ts +17 -10
  12. package/dist/cjs/error.d.ts.map +1 -1
  13. package/dist/cjs/error.js +25 -7
  14. package/dist/cjs/error.js.map +1 -1
  15. package/dist/cjs/http.d.ts +13 -8
  16. package/dist/cjs/http.d.ts.map +1 -1
  17. package/dist/cjs/http.js +135 -44
  18. package/dist/cjs/http.js.map +1 -1
  19. package/dist/cjs/index.d.ts +14 -1
  20. package/dist/cjs/index.d.ts.map +1 -1
  21. package/dist/cjs/index.js +30 -1
  22. package/dist/cjs/index.js.map +1 -1
  23. package/dist/cjs/resources/apikeys.d.ts +18 -0
  24. package/dist/cjs/resources/apikeys.d.ts.map +1 -0
  25. package/dist/cjs/resources/apikeys.js +31 -0
  26. package/dist/cjs/resources/apikeys.js.map +1 -0
  27. package/dist/cjs/resources/asset.d.ts +17 -5
  28. package/dist/cjs/resources/asset.d.ts.map +1 -1
  29. package/dist/cjs/resources/asset.js +17 -6
  30. package/dist/cjs/resources/asset.js.map +1 -1
  31. package/dist/cjs/resources/bank.d.ts +11 -6
  32. package/dist/cjs/resources/bank.d.ts.map +1 -1
  33. package/dist/cjs/resources/bank.js +17 -9
  34. package/dist/cjs/resources/bank.js.map +1 -1
  35. package/dist/cjs/resources/core.d.ts +12 -0
  36. package/dist/cjs/resources/core.d.ts.map +1 -0
  37. package/dist/cjs/resources/core.js +22 -0
  38. package/dist/cjs/resources/core.js.map +1 -0
  39. package/dist/cjs/resources/custody.d.ts +27 -0
  40. package/dist/cjs/resources/custody.d.ts.map +1 -0
  41. package/dist/cjs/resources/custody.js +38 -0
  42. package/dist/cjs/resources/custody.js.map +1 -0
  43. package/dist/cjs/resources/customer.d.ts +20 -0
  44. package/dist/cjs/resources/customer.d.ts.map +1 -0
  45. package/dist/cjs/resources/customer.js +38 -0
  46. package/dist/cjs/resources/customer.js.map +1 -0
  47. package/dist/cjs/resources/staking.d.ts +32 -0
  48. package/dist/cjs/resources/staking.d.ts.map +1 -0
  49. package/dist/cjs/resources/staking.js +69 -0
  50. package/dist/cjs/resources/staking.js.map +1 -0
  51. package/dist/cjs/resources/trading.d.ts +24 -0
  52. package/dist/cjs/resources/trading.d.ts.map +1 -0
  53. package/dist/cjs/resources/trading.js +41 -0
  54. package/dist/cjs/resources/trading.js.map +1 -0
  55. package/dist/cjs/resources/transaction.d.ts +6 -9
  56. package/dist/cjs/resources/transaction.d.ts.map +1 -1
  57. package/dist/cjs/resources/transaction.js +10 -15
  58. package/dist/cjs/resources/transaction.js.map +1 -1
  59. package/dist/cjs/resources/webhooks.d.ts +46 -0
  60. package/dist/cjs/resources/webhooks.d.ts.map +1 -0
  61. package/dist/cjs/resources/webhooks.js +142 -0
  62. package/dist/cjs/resources/webhooks.js.map +1 -0
  63. package/dist/cjs/types/apikeys.d.ts +43 -0
  64. package/dist/cjs/types/apikeys.d.ts.map +1 -0
  65. package/dist/cjs/types/apikeys.js +3 -0
  66. package/dist/cjs/types/apikeys.js.map +1 -0
  67. package/dist/cjs/types/asset.d.ts +57 -0
  68. package/dist/cjs/types/asset.d.ts.map +1 -0
  69. package/dist/cjs/types/asset.js +3 -0
  70. package/dist/cjs/types/asset.js.map +1 -0
  71. package/dist/cjs/types/bank.d.ts +58 -0
  72. package/dist/cjs/types/bank.d.ts.map +1 -0
  73. package/dist/cjs/types/bank.js +3 -0
  74. package/dist/cjs/types/bank.js.map +1 -0
  75. package/dist/cjs/types/core.d.ts +32 -0
  76. package/dist/cjs/types/core.d.ts.map +1 -0
  77. package/dist/cjs/types/core.js +3 -0
  78. package/dist/cjs/types/core.js.map +1 -0
  79. package/dist/cjs/types/custody.d.ts +50 -0
  80. package/dist/cjs/types/custody.d.ts.map +1 -0
  81. package/dist/cjs/types/custody.js +3 -0
  82. package/dist/cjs/types/custody.js.map +1 -0
  83. package/dist/cjs/types/customer.d.ts +190 -0
  84. package/dist/cjs/types/customer.d.ts.map +1 -0
  85. package/dist/cjs/types/customer.js +3 -0
  86. package/dist/cjs/types/customer.js.map +1 -0
  87. package/dist/cjs/types/index.d.ts +78 -194
  88. package/dist/cjs/types/index.d.ts.map +1 -1
  89. package/dist/cjs/types/index.js +0 -1
  90. package/dist/cjs/types/index.js.map +1 -1
  91. package/dist/cjs/types/staking.d.ts +88 -0
  92. package/dist/cjs/types/staking.d.ts.map +1 -0
  93. package/dist/cjs/types/staking.js +3 -0
  94. package/dist/cjs/types/staking.js.map +1 -0
  95. package/dist/cjs/types/trading.d.ts +51 -0
  96. package/dist/cjs/types/trading.d.ts.map +1 -0
  97. package/dist/cjs/types/trading.js +3 -0
  98. package/dist/cjs/types/trading.js.map +1 -0
  99. package/dist/cjs/types/transaction.d.ts +61 -0
  100. package/dist/cjs/types/transaction.d.ts.map +1 -0
  101. package/dist/cjs/types/transaction.js +3 -0
  102. package/dist/cjs/types/transaction.js.map +1 -0
  103. package/dist/cjs/types/webhooks.d.ts +55 -0
  104. package/dist/cjs/types/webhooks.d.ts.map +1 -0
  105. package/dist/cjs/types/webhooks.js +3 -0
  106. package/dist/cjs/types/webhooks.js.map +1 -0
  107. package/dist/cjs/utils.d.ts +21 -2
  108. package/dist/cjs/utils.d.ts.map +1 -1
  109. package/dist/cjs/utils.js +67 -4
  110. package/dist/cjs/utils.js.map +1 -1
  111. package/dist/cjs/version.d.ts +2 -0
  112. package/dist/cjs/version.d.ts.map +1 -0
  113. package/dist/cjs/version.js +6 -0
  114. package/dist/cjs/version.js.map +1 -0
  115. package/dist/esm/client.d.ts +20 -8
  116. package/dist/esm/client.d.ts.map +1 -1
  117. package/dist/esm/client.js +33 -12
  118. package/dist/esm/client.js.map +1 -1
  119. package/dist/esm/constants.d.ts +256 -0
  120. package/dist/esm/constants.d.ts.map +1 -0
  121. package/dist/esm/constants.js +211 -0
  122. package/dist/esm/constants.js.map +1 -0
  123. package/dist/esm/error.d.ts +17 -10
  124. package/dist/esm/error.d.ts.map +1 -1
  125. package/dist/esm/error.js +24 -6
  126. package/dist/esm/error.js.map +1 -1
  127. package/dist/esm/http.d.ts +13 -8
  128. package/dist/esm/http.d.ts.map +1 -1
  129. package/dist/esm/http.js +136 -45
  130. package/dist/esm/http.js.map +1 -1
  131. package/dist/esm/index.d.ts +14 -1
  132. package/dist/esm/index.d.ts.map +1 -1
  133. package/dist/esm/index.js +6 -0
  134. package/dist/esm/index.js.map +1 -1
  135. package/dist/esm/resources/apikeys.d.ts +18 -0
  136. package/dist/esm/resources/apikeys.d.ts.map +1 -0
  137. package/dist/esm/resources/apikeys.js +27 -0
  138. package/dist/esm/resources/apikeys.js.map +1 -0
  139. package/dist/esm/resources/asset.d.ts +17 -5
  140. package/dist/esm/resources/asset.d.ts.map +1 -1
  141. package/dist/esm/resources/asset.js +17 -6
  142. package/dist/esm/resources/asset.js.map +1 -1
  143. package/dist/esm/resources/bank.d.ts +11 -6
  144. package/dist/esm/resources/bank.d.ts.map +1 -1
  145. package/dist/esm/resources/bank.js +18 -10
  146. package/dist/esm/resources/bank.js.map +1 -1
  147. package/dist/esm/resources/core.d.ts +12 -0
  148. package/dist/esm/resources/core.d.ts.map +1 -0
  149. package/dist/esm/resources/core.js +18 -0
  150. package/dist/esm/resources/core.js.map +1 -0
  151. package/dist/esm/resources/custody.d.ts +27 -0
  152. package/dist/esm/resources/custody.d.ts.map +1 -0
  153. package/dist/esm/resources/custody.js +34 -0
  154. package/dist/esm/resources/custody.js.map +1 -0
  155. package/dist/esm/resources/customer.d.ts +20 -0
  156. package/dist/esm/resources/customer.d.ts.map +1 -0
  157. package/dist/esm/resources/customer.js +34 -0
  158. package/dist/esm/resources/customer.js.map +1 -0
  159. package/dist/esm/resources/staking.d.ts +32 -0
  160. package/dist/esm/resources/staking.d.ts.map +1 -0
  161. package/dist/esm/resources/staking.js +65 -0
  162. package/dist/esm/resources/staking.js.map +1 -0
  163. package/dist/esm/resources/trading.d.ts +24 -0
  164. package/dist/esm/resources/trading.d.ts.map +1 -0
  165. package/dist/esm/resources/trading.js +37 -0
  166. package/dist/esm/resources/trading.js.map +1 -0
  167. package/dist/esm/resources/transaction.d.ts +6 -9
  168. package/dist/esm/resources/transaction.d.ts.map +1 -1
  169. package/dist/esm/resources/transaction.js +11 -16
  170. package/dist/esm/resources/transaction.js.map +1 -1
  171. package/dist/esm/resources/webhooks.d.ts +46 -0
  172. package/dist/esm/resources/webhooks.d.ts.map +1 -0
  173. package/dist/esm/resources/webhooks.js +138 -0
  174. package/dist/esm/resources/webhooks.js.map +1 -0
  175. package/dist/esm/types/apikeys.d.ts +43 -0
  176. package/dist/esm/types/apikeys.d.ts.map +1 -0
  177. package/dist/esm/types/apikeys.js +2 -0
  178. package/dist/esm/types/apikeys.js.map +1 -0
  179. package/dist/esm/types/asset.d.ts +57 -0
  180. package/dist/esm/types/asset.d.ts.map +1 -0
  181. package/dist/esm/types/asset.js +2 -0
  182. package/dist/esm/types/asset.js.map +1 -0
  183. package/dist/esm/types/bank.d.ts +58 -0
  184. package/dist/esm/types/bank.d.ts.map +1 -0
  185. package/dist/esm/types/bank.js +2 -0
  186. package/dist/esm/types/bank.js.map +1 -0
  187. package/dist/esm/types/core.d.ts +32 -0
  188. package/dist/esm/types/core.d.ts.map +1 -0
  189. package/dist/esm/types/core.js +2 -0
  190. package/dist/esm/types/core.js.map +1 -0
  191. package/dist/esm/types/custody.d.ts +50 -0
  192. package/dist/esm/types/custody.d.ts.map +1 -0
  193. package/dist/esm/types/custody.js +2 -0
  194. package/dist/esm/types/custody.js.map +1 -0
  195. package/dist/esm/types/customer.d.ts +190 -0
  196. package/dist/esm/types/customer.d.ts.map +1 -0
  197. package/dist/esm/types/customer.js +2 -0
  198. package/dist/esm/types/customer.js.map +1 -0
  199. package/dist/esm/types/index.d.ts +78 -194
  200. package/dist/esm/types/index.d.ts.map +1 -1
  201. package/dist/esm/types/index.js +0 -1
  202. package/dist/esm/types/index.js.map +1 -1
  203. package/dist/esm/types/staking.d.ts +88 -0
  204. package/dist/esm/types/staking.d.ts.map +1 -0
  205. package/dist/esm/types/staking.js +2 -0
  206. package/dist/esm/types/staking.js.map +1 -0
  207. package/dist/esm/types/trading.d.ts +51 -0
  208. package/dist/esm/types/trading.d.ts.map +1 -0
  209. package/dist/esm/types/trading.js +2 -0
  210. package/dist/esm/types/trading.js.map +1 -0
  211. package/dist/esm/types/transaction.d.ts +61 -0
  212. package/dist/esm/types/transaction.d.ts.map +1 -0
  213. package/dist/esm/types/transaction.js +2 -0
  214. package/dist/esm/types/transaction.js.map +1 -0
  215. package/dist/esm/types/webhooks.d.ts +55 -0
  216. package/dist/esm/types/webhooks.d.ts.map +1 -0
  217. package/dist/esm/types/webhooks.js +2 -0
  218. package/dist/esm/types/webhooks.js.map +1 -0
  219. package/dist/esm/utils.d.ts +21 -2
  220. package/dist/esm/utils.d.ts.map +1 -1
  221. package/dist/esm/utils.js +62 -4
  222. package/dist/esm/utils.js.map +1 -1
  223. package/dist/esm/version.d.ts +2 -0
  224. package/dist/esm/version.d.ts.map +1 -0
  225. package/dist/esm/version.js +3 -0
  226. package/dist/esm/version.js.map +1 -0
  227. package/package.json +29 -12
  228. package/readme/concepts.md +128 -0
  229. package/readme/configuration.md +72 -0
  230. package/readme/errors.md +67 -0
  231. package/readme/installation.md +43 -0
  232. package/readme/media/activation.svg +58 -0
  233. package/readme/media/deposit-flow.svg +70 -0
  234. package/readme/media/order-buy.svg +43 -0
  235. package/readme/media/order-sell.svg +47 -0
  236. package/readme/media/purchase-flow.svg +61 -0
  237. package/readme/media/sale-flow.svg +61 -0
  238. package/readme/media/staking-position.svg +75 -0
  239. package/readme/media/transaction-lifecycle.svg +61 -0
  240. package/readme/media/webhook-delivery.svg +53 -0
  241. package/readme/media/withdrawal-flow.svg +64 -0
  242. package/readme/quick-start.md +87 -0
  243. package/readme/resource/apikeys.md +103 -0
  244. package/readme/resource/asset.md +121 -0
  245. package/readme/resource/bank.md +161 -0
  246. package/readme/resource/core.md +91 -0
  247. package/readme/resource/custody.md +166 -0
  248. package/readme/resource/customer.md +210 -0
  249. package/readme/resource/staking.md +281 -0
  250. package/readme/resource/trading.md +171 -0
  251. package/readme/resource/transaction.md +110 -0
  252. package/readme/resource/webhooks.md +309 -0
  253. package/src/client.ts +46 -0
  254. package/src/constants.ts +281 -0
  255. package/src/error.ts +36 -0
  256. package/src/http.ts +201 -0
  257. package/src/index.ts +111 -0
  258. package/src/resources/apikeys.ts +30 -0
  259. package/src/resources/asset.ts +28 -0
  260. package/src/resources/bank.ts +39 -0
  261. package/src/resources/core.ts +19 -0
  262. package/src/resources/custody.ts +37 -0
  263. package/src/resources/customer.ts +46 -0
  264. package/src/resources/staking.ts +88 -0
  265. package/src/resources/trading.ts +41 -0
  266. package/src/resources/transaction.ts +20 -0
  267. package/src/resources/webhooks.ts +169 -0
  268. package/src/types/apikeys.ts +35 -0
  269. package/src/types/asset.ts +59 -0
  270. package/src/types/bank.ts +60 -0
  271. package/src/types/core.ts +32 -0
  272. package/src/types/custody.ts +40 -0
  273. package/src/types/customer.ts +189 -0
  274. package/src/types/index.ts +215 -0
  275. package/src/types/staking.ts +87 -0
  276. package/src/types/trading.ts +56 -0
  277. package/src/types/transaction.ts +62 -0
  278. package/src/types/webhooks.ts +60 -0
  279. package/src/utils.ts +74 -0
  280. package/src/version.ts +2 -0
  281. package/dist/cjs/resources/order.d.ts +0 -17
  282. package/dist/cjs/resources/order.d.ts.map +0 -1
  283. package/dist/cjs/resources/order.js +0 -30
  284. package/dist/cjs/resources/order.js.map +0 -1
  285. package/dist/cjs/resources/stats.d.ts +0 -11
  286. package/dist/cjs/resources/stats.d.ts.map +0 -1
  287. package/dist/cjs/resources/stats.js +0 -18
  288. package/dist/cjs/resources/stats.js.map +0 -1
  289. package/dist/cjs/resources/user.d.ts +0 -22
  290. package/dist/cjs/resources/user.d.ts.map +0 -1
  291. package/dist/cjs/resources/user.js +0 -37
  292. package/dist/cjs/resources/user.js.map +0 -1
  293. package/dist/cjs/resources/wallet.d.ts +0 -11
  294. package/dist/cjs/resources/wallet.d.ts.map +0 -1
  295. package/dist/cjs/resources/wallet.js +0 -19
  296. package/dist/cjs/resources/wallet.js.map +0 -1
  297. package/dist/esm/resources/order.d.ts +0 -17
  298. package/dist/esm/resources/order.d.ts.map +0 -1
  299. package/dist/esm/resources/order.js +0 -26
  300. package/dist/esm/resources/order.js.map +0 -1
  301. package/dist/esm/resources/stats.d.ts +0 -11
  302. package/dist/esm/resources/stats.d.ts.map +0 -1
  303. package/dist/esm/resources/stats.js +0 -14
  304. package/dist/esm/resources/stats.js.map +0 -1
  305. package/dist/esm/resources/user.d.ts +0 -22
  306. package/dist/esm/resources/user.d.ts.map +0 -1
  307. package/dist/esm/resources/user.js +0 -33
  308. package/dist/esm/resources/user.js.map +0 -1
  309. package/dist/esm/resources/wallet.d.ts +0 -11
  310. package/dist/esm/resources/wallet.d.ts.map +0 -1
  311. package/dist/esm/resources/wallet.js +0 -15
  312. package/dist/esm/resources/wallet.js.map +0 -1
  313. package/dist/types/client.d.ts +0 -19
  314. package/dist/types/client.d.ts.map +0 -1
  315. package/dist/types/error.d.ts +0 -15
  316. package/dist/types/error.d.ts.map +0 -1
  317. package/dist/types/http.d.ts +0 -21
  318. package/dist/types/http.d.ts.map +0 -1
  319. package/dist/types/index.d.ts +0 -4
  320. package/dist/types/index.d.ts.map +0 -1
  321. package/dist/types/resources/asset.d.ts +0 -11
  322. package/dist/types/resources/asset.d.ts.map +0 -1
  323. package/dist/types/resources/bank.d.ts +0 -13
  324. package/dist/types/resources/bank.d.ts.map +0 -1
  325. package/dist/types/resources/order.d.ts +0 -17
  326. package/dist/types/resources/order.d.ts.map +0 -1
  327. package/dist/types/resources/stats.d.ts +0 -11
  328. package/dist/types/resources/stats.d.ts.map +0 -1
  329. package/dist/types/resources/transaction.d.ts +0 -15
  330. package/dist/types/resources/transaction.d.ts.map +0 -1
  331. package/dist/types/resources/user.d.ts +0 -22
  332. package/dist/types/resources/user.d.ts.map +0 -1
  333. package/dist/types/resources/wallet.d.ts +0 -11
  334. package/dist/types/resources/wallet.d.ts.map +0 -1
  335. package/dist/types/types/index.d.ts +0 -213
  336. package/dist/types/types/index.d.ts.map +0 -1
  337. package/dist/types/utils.d.ts +0 -7
  338. package/dist/types/utils.d.ts.map +0 -1
@@ -1,7 +1,26 @@
1
- import type { UserRef } from './types/index.js';
1
+ import type { Amount, AssetInput, UserRef } from './types/index.js';
2
2
  /**
3
- * Resolve a UserRef (UUID string or User object) to a UUID string.
3
+ * Resolve a UserRef (uuid or email string, or a model carrying a `uuid`) to its string.
4
4
  * Used by all resource methods that accept a user parameter.
5
5
  */
6
6
  export declare function resolveUuid(ref: UserRef): string;
7
+ /**
8
+ * The uuid of a reference given as a string (sent as is) or as a model carrying a `uuid` (an `Order`, a
9
+ * `StakingPosition`, an `Apikey`…). An empty string, or a model without one, is refused before any request.
10
+ */
11
+ export declare function idOf(ref: string | {
12
+ uuid: string;
13
+ }, name: string): string;
14
+ /** An asset as given — a uuid or ISO code string as is, or the uuid of an `Asset` / `AssetRef` model; empty → `TypeError` before any request */
15
+ export declare function assetId(asset: AssetInput): string;
16
+ /** An optional asset filter of a list: absent or `null` stays absent, otherwise `assetId` */
17
+ export declare function assetFilter(asset: AssetInput | null | undefined): string | undefined;
18
+ /** Validate and encode a value used as a path segment (`/asset/{asset}`, `/account/{user}`…) */
19
+ export declare function pathSegment(value: string, name: string): string;
20
+ /**
21
+ * Normalize an amount for the API, which always receives a string: a string is sent as is
22
+ * (trimmed), a finite number ≥ 0 is converted with `String(n)`. Numbers that `String()` writes
23
+ * in exponent notation (below 1e-6 or from 1e21) are refused: pass them as strings.
24
+ */
25
+ export declare function amount(value: Amount): string;
7
26
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAQ,MAAM,kBAAkB,CAAA;AAErD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAGhD"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAEnE;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAMhD;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAMzE;AAED,gJAAgJ;AAChJ,wBAAgB,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAMjD;AAED,6FAA6F;AAC7F,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAEpF;AAED,gGAAgG;AAChG,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAS/D;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAgB5C"}
package/dist/esm/utils.js CHANGED
@@ -1,10 +1,68 @@
1
1
  /**
2
- * Resolve a UserRef (UUID string or User object) to a UUID string.
2
+ * Resolve a UserRef (uuid or email string, or a model carrying a `uuid`) to its string.
3
3
  * Used by all resource methods that accept a user parameter.
4
4
  */
5
5
  export function resolveUuid(ref) {
6
- if (typeof ref === 'string')
7
- return ref;
8
- return ref.uuid;
6
+ const value = typeof ref === 'string' ? ref : ref?.uuid;
7
+ if (typeof value !== 'string' || value.trim() === '') {
8
+ throw new TypeError('user must be a non-empty uuid or email, or a model with a non-empty uuid');
9
+ }
10
+ return value;
11
+ }
12
+ /**
13
+ * The uuid of a reference given as a string (sent as is) or as a model carrying a `uuid` (an `Order`, a
14
+ * `StakingPosition`, an `Apikey`…). An empty string, or a model without one, is refused before any request.
15
+ */
16
+ export function idOf(ref, name) {
17
+ const value = typeof ref === 'string' ? ref : ref?.uuid;
18
+ if (typeof value !== 'string' || value.trim() === '') {
19
+ throw new TypeError(`${name} must be a non-empty string, or a model with a non-empty uuid`);
20
+ }
21
+ return value;
22
+ }
23
+ /** An asset as given — a uuid or ISO code string as is, or the uuid of an `Asset` / `AssetRef` model; empty → `TypeError` before any request */
24
+ export function assetId(asset) {
25
+ const value = typeof asset === 'string' ? asset : asset?.uuid;
26
+ if (typeof value !== 'string' || value.trim() === '') {
27
+ throw new TypeError('asset must be a uuid or an ISO code, or a model with a non-empty uuid');
28
+ }
29
+ return value;
30
+ }
31
+ /** An optional asset filter of a list: absent or `null` stays absent, otherwise `assetId` */
32
+ export function assetFilter(asset) {
33
+ return asset === undefined || asset === null ? undefined : assetId(asset);
34
+ }
35
+ /** Validate and encode a value used as a path segment (`/asset/{asset}`, `/account/{user}`…) */
36
+ export function pathSegment(value, name) {
37
+ if (typeof value !== 'string' || value.trim() === '') {
38
+ throw new TypeError(`${name} must be a non-empty string`);
39
+ }
40
+ // `.` and `..` are not encoded by encodeURIComponent and would be normalized away by the URL parser
41
+ if (value === '.' || value === '..') {
42
+ throw new TypeError(`${name} must not be "." or ".."`);
43
+ }
44
+ return encodeURIComponent(value);
45
+ }
46
+ /**
47
+ * Normalize an amount for the API, which always receives a string: a string is sent as is
48
+ * (trimmed), a finite number ≥ 0 is converted with `String(n)`. Numbers that `String()` writes
49
+ * in exponent notation (below 1e-6 or from 1e21) are refused: pass them as strings.
50
+ */
51
+ export function amount(value) {
52
+ if (typeof value === 'string') {
53
+ const trimmed = value.trim();
54
+ if (trimmed === '') {
55
+ throw new TypeError('amount must be a non-empty string or a finite number >= 0');
56
+ }
57
+ return trimmed;
58
+ }
59
+ if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {
60
+ throw new TypeError('amount must be a non-empty string or a finite number >= 0');
61
+ }
62
+ const text = String(value);
63
+ if (text.includes('e')) {
64
+ throw new TypeError(`amount ${text} would be sent in exponent notation: pass it as a decimal string`);
65
+ }
66
+ return text;
9
67
  }
10
68
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,GAAG,CAAA;IACvC,OAAQ,GAAY,CAAC,IAAI,CAAA;AAC3B,CAAC"}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,MAAM,KAAK,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAA;IACvD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACrD,MAAM,IAAI,SAAS,CAAC,0EAA0E,CAAC,CAAA;IACjG,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,IAAI,CAAC,GAA8B,EAAE,IAAY;IAC/D,MAAM,KAAK,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAA;IACvD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACrD,MAAM,IAAI,SAAS,CAAC,GAAG,IAAI,+DAA+D,CAAC,CAAA;IAC7F,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED,gJAAgJ;AAChJ,MAAM,UAAU,OAAO,CAAC,KAAiB;IACvC,MAAM,KAAK,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAA;IAC7D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACrD,MAAM,IAAI,SAAS,CAAC,uEAAuE,CAAC,CAAA;IAC9F,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,WAAW,CAAC,KAAoC;IAC9D,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC3E,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,IAAY;IACrD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACrD,MAAM,IAAI,SAAS,CAAC,GAAG,IAAI,6BAA6B,CAAC,CAAA;IAC3D,CAAC;IACD,oGAAoG;IACpG,IAAI,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACpC,MAAM,IAAI,SAAS,CAAC,GAAG,IAAI,0BAA0B,CAAC,CAAA;IACxD,CAAC;IACD,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAA;AAClC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,KAAa;IAClC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAA;QAC5B,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;YACnB,MAAM,IAAI,SAAS,CAAC,2DAA2D,CAAC,CAAA;QAClF,CAAC;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACtE,MAAM,IAAI,SAAS,CAAC,2DAA2D,CAAC,CAAA;IAClF,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;IAC1B,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,SAAS,CAAC,UAAU,IAAI,kEAAkE,CAAC,CAAA;IACvG,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const VERSION = "1.0.4";
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO,UAAU,CAAA"}
@@ -0,0 +1,3 @@
1
+ // Generated by scripts/prebuild.js from package.json — do not edit
2
+ export const VERSION = "1.0.4";
3
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAA"}
package/package.json CHANGED
@@ -1,28 +1,41 @@
1
1
  {
2
2
  "name": "@bitgen/sdk",
3
- "version": "0.1.6",
4
- "license": "private",
3
+ "version": "1.0.4",
4
+ "license": "UNLICENSED",
5
5
  "author": "BITGEN",
6
- "description": "Official Node.js SDK for the BITGEN API v3.1.x",
6
+ "description": "Official Node.js SDK for the BITGEN API v4.0.x",
7
7
  "main": "./dist/cjs/index.js",
8
8
  "module": "./dist/esm/index.js",
9
9
  "type": "module",
10
- "types": "./dist/types/index.d.ts",
10
+ "types": "./dist/esm/index.d.ts",
11
11
  "exports": {
12
12
  ".": {
13
- "import": "./dist/esm/index.js",
14
- "require": "./dist/cjs/index.js",
15
- "types": "./dist/types/index.d.ts"
13
+ "import": {
14
+ "types": "./dist/esm/index.d.ts",
15
+ "default": "./dist/esm/index.js"
16
+ },
17
+ "require": {
18
+ "types": "./dist/cjs/index.d.ts",
19
+ "default": "./dist/cjs/index.js"
20
+ }
16
21
  }
17
22
  },
23
+ "sideEffects": false,
18
24
  "files": [
19
25
  "dist",
26
+ "src",
27
+ "readme",
20
28
  "README.md",
21
29
  "CHANGELOG.md"
22
30
  ],
23
31
  "scripts": {
24
- "build": "tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && tsc -p tsconfig.types.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
25
- "prepublishOnly": "npm run build"
32
+ "prebuild": "node scripts/prebuild.js",
33
+ "build": "tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
34
+ "lint": "eslint .",
35
+ "pretest": "npm run build",
36
+ "test": "node --test",
37
+ "prepublishOnly": "npm run lint && npm test",
38
+ "version": "node scripts/prebuild.js && git add src/version.ts"
26
39
  },
27
40
  "keywords": [
28
41
  "bitgen",
@@ -31,16 +44,20 @@
31
44
  ],
32
45
  "repository": {
33
46
  "type": "git",
34
- "url": "https://github.com/bitgenplatform/sdk-js.git"
47
+ "url": "git+https://github.com/bitgenplatform/sdk-js.git"
35
48
  },
36
49
  "homepage": "https://github.com/bitgenplatform/sdk-js#readme",
37
50
  "bugs": {
38
51
  "url": "https://github.com/bitgenplatform/sdk-js/issues"
39
52
  },
40
53
  "engines": {
41
- "node": ">=18.0.0"
54
+ "node": ">=20.0.0"
42
55
  },
43
56
  "devDependencies": {
44
- "typescript": "^5.9.3"
57
+ "@eslint/js": "^10.0.1",
58
+ "@types/node": "^20.19.43",
59
+ "eslint": "^10.10.0",
60
+ "typescript": "^5.9.3",
61
+ "typescript-eslint": "^8.70.0"
45
62
  }
46
63
  }
@@ -0,0 +1,128 @@
1
+ # Concepts
2
+
3
+ The conventions shared by every resource of the SDK: how a customer is designated, how amounts, pages, booleans, assets and dates travel, and which customers the financial resources accept. Examples use `client`, a configured `BitgenClient` ([Configuration](configuration.md)).
4
+
5
+ ## User references
6
+
7
+ Wherever a method expects a customer, it takes a `UserRef`: a string — the customer's **uuid** — or one of the models that carry it. The SDK sends the uuid of the model: the `Created` returned by `client.customer.create`, a `Customer` of `client.customer.list`, an `Account` of `client.customer.get`, the `user` of an `Order`, the `owner` of a `Transaction` or of a `StakingMovement`.
8
+
9
+ ```
10
+ type UserRef = string | Created | Customer | Account | UserSummary | OrderUser
11
+ ```
12
+
13
+ ```ts
14
+ await client.customer.get('CUSTOMER_UUID')
15
+ await client.customer.get(customer) // the Created returned by client.customer.create
16
+ ```
17
+
18
+ An email works too where the API resolves it (`customer`, `bank`, `custody`, `staking` — not `trading`, nor the `user` filter of the lists), but the uuid is cheaper for the API — prefer it. TypeScript checks the shape, not the origin: any object carrying a `uuid` string is accepted as a `UserRef`, a `Wallet` included — a uuid that is not a customer's is refused by the API, with the code of the resource called (`404 unknown_user`, `404 unknown_bank`, `403 org_forbidden`…).
19
+
20
+ The same goes for the other objects the SDK returns: wherever a method expects the uuid of an order, a movement, a position, a connector, a transaction, a subscription, an event of the catalogue or a key, it also takes the model itself (`client.staking.rewards(movement.staking)`, `client.trading.get(order)`) and sends its uuid — there, passing another model (a `StakingMovement` as a position, a `Wallet` as an order) is a type error in TypeScript.
21
+
22
+ ## Amounts
23
+
24
+ The API handles crypto amounts as **strings** (up to 18 decimals): a JavaScript `number` only keeps about 15 significant digits and nothing on the server side restores what it lost. The SDK therefore:
25
+
26
+ - accepts an `Amount = string | number` and always sends it as a string — a string is sent as is, a number is converted with `String(n)`;
27
+ - rejects, with a `TypeError` and before any request, an empty string, a negative or non-finite number, and a number that `String()` would write in exponent notation (`1e-8`, `1e21`): pass those as strings;
28
+ - never rounds or reformats a string: `'0.000000000000000001'` reaches the API untouched.
29
+
30
+ **Prefer strings**, even for EUR. In responses, crypto quantities are strings (`Wallet.balance`, `Order.amount`, `StakingMovement.amount`) and EUR amounts are numbers with 2 decimals (`BankAccount.balance`, `BankOperation.amount`, `StakingPortfolio.balances`).
31
+
32
+ **Minimums.** Purchases, sales, on-chain withdrawals and staking movements have minimums — set by BITGEN per environment, subject to change, never hard-coded in the SDK. The API's answer is the source of truth: `416 invalid_amount` for a purchase or a sale, `416 withdraw_below_minimum` for an on-chain withdrawal, `422 amount_below_minimum` for a staking movement. For staking, the provider's minimums are readable in its configuration (`client.staking.providers()`, [Staking](resource/staking.md#providers)).
33
+
34
+ ## Pagination
35
+
36
+ Paginated lists take `PageParams` and return a `Page`:
37
+
38
+ ```ts
39
+ interface PageParams { offset?: number, limit?: number } // limit: default 10, max 50
40
+ interface Page<T> { count: number, items: T[] }
41
+ ```
42
+
43
+ `transaction.list` accepts a `limit` up to 100.
44
+
45
+ ```ts
46
+ const { count, items } = await client.customer.list({ offset: 0, limit: 50 })
47
+ ```
48
+
49
+ `client.core.list` is not paginated: its `count` is everything that matches.
50
+
51
+ ## Query booleans
52
+
53
+ The boolean filters of the lists — `includeClosed` (`customer.list`), `includeRevoked` (`apikeys.list`), `includeArchived` (`webhooks.list`) — are sent as `true` / `false`. The API also reads `1` / `0`, treats an absent parameter as `false`, and answers `422 invalid_<param>` for any other value: `invalid_include_closed`, `invalid_include_revoked`, `invalid_include_archived`.
54
+
55
+ ## Assets
56
+
57
+ Wherever an asset is expected, the SDK accepts its **uuid** or its **ISO code** as a string, in any case (the API normalizes it) — or an `Asset` / `AssetRef` model returned by the SDK, whose uuid is then sent. The `Asset` constants are the ISO codes of the main assets; any other code known to the catalogue ([Assets](resource/asset.md)) is passed as a plain string.
58
+
59
+ ```ts
60
+ import { Asset } from '@bitgen/sdk'
61
+
62
+ Asset.BTC // 'btc'
63
+ Asset.ETH // 'eth'
64
+ Asset.USDC // 'usdc'
65
+ Asset.XRP // 'xrp'
66
+ Asset.SOL // 'sol'
67
+
68
+ const eth = await client.asset.get(Asset.ETH) // or by uuid
69
+ const wallet = await client.custody.wallet(customer, eth) // the model: its uuid is sent
70
+ ```
71
+
72
+ The `iso` the API returns has the case it is stored with (`ETH` today): **compare it case-insensitively**. In TypeScript, `Asset` is also the type of an asset returned by `client.asset`; `AssetInput` is the type of an asset argument (`string | Asset | AssetRef`).
73
+
74
+ ## Constants
75
+
76
+ Every value the API enumerates is a **frozen object of string constants**, exported by the package with a type of the same name — `Env.SANDBOX` is `'sandbox'`, `Locale.FR` is `'FR'`, `TradingDirection.BUY` is `'buy'`, `AssetState.AVAILABLE` is `'AVAILABLE'`, `WebhookEventName.CUSTODY_SENT` is `'custody.sent'`. Inputs take the constant; outputs are strings you compare with the constants.
77
+
78
+ ```ts
79
+ import { Asset, AssetState, Locale } from '@bitgen/sdk'
80
+
81
+ const eth = await client.asset.get(Asset.ETH)
82
+ if (eth.state === AssetState.AVAILABLE) { // outputs are strings: compare them with the constants
83
+ await client.customer.update(customer, { locale: Locale.EN }) // inputs take the constant
84
+ }
85
+ console.log(Object.values(Locale)) // [ 'FR', 'EN' ]
86
+ ```
87
+
88
+ In TypeScript, an input that is not one of the values (`locale: 'en'`, `direction: 'Buy'`) is a compile-time error: the case matters. From JavaScript the string is sent as is, and the API's answer is the source of truth. An output the SDK does not know yet (a state the API added) is kept as is, as a string — `WebhookEventName` accepts any string, as the catalogue may grow.
89
+
90
+ ## Timestamps and histories
91
+
92
+ Timestamps are **epochs in seconds** (`createdAt`, `updatedAt`, `date`, `expiresAt`…). Time series are a `History`:
93
+
94
+ ```ts
95
+ type History = Record<'d' | 'w' | 'm' | 'y' | 'all', [number, number][]>
96
+ ```
97
+
98
+ Each key is a list of `[epoch seconds, value]` points: `d` covers the last 24 hours with one point per hour, `w` and `m` one point per day, `y` and `all` one point per month; the last point is the current value. Histories are the EUR price of an asset (`client.asset`), the EUR balance of a bank account, the EUR value of a wallet or of a whole custody, and the capital and revenues of a staking portfolio.
99
+
100
+ ## Activation and identity
101
+
102
+ By default `client.customer.create` sends the customer an activation email. Until they click it, the account stays `CustomerState.CREATED` (`setup.needActivation` is `true`) and the **financial resources do not see it**: `client.bank` answers `404 unknown_bank`, `client.custody` and `client.staking` `403 org_forbidden`, `client.trading` `403 user_not_in_scope`. Only `client.customer.list` (where the customer appears as `CREATED`) and `client.customer.get` see it. An organization that handles onboarding itself creates its customers with `needActivation: false` — usable right away, no BITGEN email — and `notify: false` for no BITGEN emails at all ([Customers › create](resource/customer.md#create)).
103
+
104
+ If your organization uses BITGEN's identity verification, the customer's identity (KYC for a person, KYB for a business) must be validated first — `412 owner_identity_not_validated` when reading the EUR account, `403 kyc_not_validated` on custody, trading and staking otherwise. An organization that verifies the identity of its customers by its own means has no such requirement. The verification itself is not part of the SDK; its state is `identity.state` ([Customers › Identity](resource/customer.md#identity)).
105
+
106
+ ![Activation and identity: from the creation of a customer to the financial resources](media/activation.svg)
107
+
108
+ ## Following a purchase and a sale
109
+
110
+ A purchase moves money across four resources. Placing the order reserves the EUR on the customer's bank account — an operation `PURCHASE` ([Bank accounts](resource/bank.md)); the exchange of the platform executes it — `EXECUTING`, then `FILLED` with the price, the fee and the quantity received ([Trading](resource/trading.md)); the quantity is delivered to the customer's custody wallet — `DELIVERING`, then `DONE` ([Custody wallets](resource/custody.md)) — where it appears as a custody transaction `IN` ([Transactions](resource/transaction.md)). Afterwards, the order carries the result, the operations of the bank account show the debit, the journal the delivery, the wallet its new balance, and the event `trading.buy` is sent ([Webhooks](resource/webhooks.md)).
111
+
112
+ ![A purchase: the EUR reserved, the execution at the exchange, the delivery to the custody wallet, and what you read afterwards](media/purchase-flow.svg)
113
+
114
+ A sale goes the other way. The quantity leaves the customer's custody wallet through an internal transfer to the exchange — a `silent` custody transaction `OUT` in the journal ([Custody wallets](resource/custody.md), [Transactions](resource/transaction.md)); the exchange executes it — `EXECUTING`, then `FILLED` at `executedPrice`, minus `fee` ([Trading](resource/trading.md)); the EUR received are credited on the customer's EUR account — `DONE`, an operation `SELL` and the event `bank.credited` ([Bank accounts](resource/bank.md)); the event `trading.sell` is sent ([Webhooks](resource/webhooks.md)).
115
+
116
+ ![A sale: the crypto moved from the custody wallet to the exchange, the execution, the EUR credited on the ledger, and what your organization reads afterwards](media/sale-flow.svg)
117
+
118
+ ## Following a deposit and a withdrawal
119
+
120
+ The EUR of a customer are held by the bank provider of your organization, on the organization's account — one IBAN, the same for all your customers, that you give them yourself. BITGEN holds no funds: it keeps the **ledger** of each customer — `balance`, `pending`, `history`, operations ([Bank accounts](resource/bank.md)). The provider receives the wires and pays the withdrawals; you read the ledger and receive the events ([Webhooks](resource/webhooks.md)).
121
+
122
+ ![An EUR deposit: the wire to the organization account at the bank provider, its report, the matching by reference, the compliance analysis, the credit of the ledger](media/deposit-flow.svg)
123
+
124
+ A deposit: the customer wires EUR to the organization's account with the reference `BTGN` followed by the code of their account (`message`) → the provider reports the wire to BITGEN — with a manual bank, you declare it ([credit](resource/bank.md#credit)) → BITGEN matches the reference and the amount enters `pending.in` → compliance analysis: a `BANK` `IN` transaction, `bank.transaction` (`PENDING` if an alert holds it — [Transactions](resource/transaction.md)) → `balance` credited, operation `DEPOSIT`, `bank.credited`. The credit is never immediate; without a valid reference the wire is never credited, and the compliance of your organization is notified.
125
+
126
+ ![An EUR withdrawal: the reserve on the ledger, the compliance analysis, the wire from the organization account to the customer IBAN, the debit at confirmation](media/withdrawal-flow.svg)
127
+
128
+ A withdrawal: you request it ([Withdraw](resource/bank.md#withdraw)) — the amount is reserved in `pending.out`, `balance` untouched, `transaction` identifies the withdrawal → compliance analysis, `bank.transaction` → the provider wires from the organization's account to the customer's IBAN → at confirmation, `balance` debited, operation `WITHDRAWAL`, `bank.debited` with `amount`, `fee` and `net`. If it fails, the reserve is released.
@@ -0,0 +1,72 @@
1
+ # Configuration
2
+
3
+ A `BitgenClient` is built once per API key and reused: it holds the credentials, the target environment and the request timeout. Every resource hangs off it (`client.customer`, `client.bank`, `client.custody`…).
4
+
5
+ ```ts
6
+ import { BitgenClient, Env } from '@bitgen/sdk'
7
+
8
+ const client = new BitgenClient({
9
+ scope: 'YOUR_SCOPE_UUID',
10
+ apiKey: 'YOUR_API_KEY',
11
+ env: Env.PRODUCTION, // default
12
+ timeout: 30, // seconds, default 30
13
+ })
14
+ ```
15
+
16
+ ## Credentials
17
+
18
+ | Option | Description |
19
+ |---|---|
20
+ | `scope` | uuid of the organization that owns the key. Sent as the `BITGEN-Scope` header. It is also the organization the SDK uses wherever the API expects yours (webhooks, API keys, the organization of a new customer). |
21
+ | `apiKey` | The raw key, shown once when it is created. Sent as the `Api-key` header. |
22
+
23
+ A missing key, an unknown, revoked or expired key, or a `scope` that is not the key's organization, is refused with a `401` ([Common errors](errors.md#common-errors)).
24
+
25
+ ## Environments
26
+
27
+ | `env` | Constant | URL |
28
+ |---|---|---|
29
+ | `production` | `Env.PRODUCTION` (default) | `https://api.bitgen.com` |
30
+ | `sandbox` | `Env.SANDBOX` | `https://api.sandbox.bitgen.com` |
31
+
32
+ `Env` holds these names as a frozen object (`Object.values(Env)` lists them): pass the constant — the type of its values is `BitgenEnv`. Anything else is refused before any request ([Validation](#validation), [Constants](concepts.md#constants)).
33
+
34
+ ## Custom host
35
+
36
+ To reach the API through another hostname — a container, a tunnel — give `host` instead of `env`:
37
+
38
+ ```ts
39
+ const client = new BitgenClient({
40
+ scope: 'YOUR_SCOPE_UUID',
41
+ apiKey: 'YOUR_API_KEY',
42
+ host: 'my-hostname', // bare hostname: no scheme, port or path
43
+ port: 8080, // default 80
44
+ isSsl: false, // default true (https)
45
+ })
46
+ ```
47
+
48
+ ## Timeout
49
+
50
+ `timeout` is the maximum time, in seconds, the SDK waits for the API to answer: `30` by default, `0` disables it. When it expires, the call rejects with `BitgenError { status: 0, code: 'request_timeout' }` ([No HTTP response](errors.md#no-http-response)).
51
+
52
+ ## Requests
53
+
54
+ Every request carries the headers `BITGEN-Scope`, `Api-key`, `Content-Type: application/json` and `User-Agent: bitgen-sdk-nodejs/<version>`, where `<version>` is the installed version of the SDK. Redirects are never followed.
55
+
56
+ ## Validation
57
+
58
+ An invalid configuration throws a `TypeError` from the constructor, before any request is sent: empty `scope` or `apiKey` (or one that is not printable ASCII), `env` that is not one of `Env`, `host` that is not a bare hostname (letters, digits, `.`, `-` and `_` only — no scheme, port, path, credentials or brackets), `port` outside 1–65535, `timeout` that is not a number of seconds between `0` and `2_147_483`. The values of `scope`, `apiKey` and `env` never appear in the message. This is the only synchronous error of the SDK: everything else rejects a promise ([Rejected promises](errors.md#rejected-promises)).
59
+
60
+ ## Options
61
+
62
+ `BitgenConfig`:
63
+
64
+ | Option | Type | Default | Description |
65
+ |---|---|---|---|
66
+ | `scope` | `string` | — | Organization uuid |
67
+ | `apiKey` | `string` | — | API key |
68
+ | `env` | `BitgenEnv` | `Env.PRODUCTION` | Target environment — an `Env` constant |
69
+ | `host` | `string` | — | Custom hostname, used instead of `env` |
70
+ | `port` | `number` | `80` | Port, with `host` |
71
+ | `isSsl` | `boolean` | `true` | `https` or `http`, with `host` |
72
+ | `timeout` | `number` | `30` | Request timeout in seconds, `0` = none |
@@ -0,0 +1,67 @@
1
+ # Errors
2
+
3
+ The API answers with real HTTP status codes and, on failure, a JSON body `{ error: true, message: '<code>', code: <status> }` where `message` is a stable snake_case code (`invalid_amount`, `unknown_asset`…), never a sentence. The SDK turns every non-2xx answer — and every request that gets no HTTP answer at all — into a `BitgenError` that rejects the returned promise.
4
+
5
+ Examples use `client`, a configured `BitgenClient` ([Configuration](configuration.md)).
6
+
7
+ ## BitgenError
8
+
9
+ | Property | Type | Description |
10
+ |---|---|---|
11
+ | `status` | `number` | The HTTP status (`416`…), or `0` when no HTTP response was received |
12
+ | `code` | `string` | The stable code of the API (`requested_amount_error`), or the raw response text when the body is not the API's JSON error |
13
+ | `message` | `string` | `"[<status>] <code>"` |
14
+ | `cause` | `unknown` | The native error, for `network_error` |
15
+ | `name` | `string` | `'BitgenError'` |
16
+
17
+ ```ts
18
+ import { BitgenError } from '@bitgen/sdk'
19
+
20
+ try {
21
+ await client.bank.withdraw('CUSTOMER_UUID', { amount: '50.00' })
22
+ } catch (err) {
23
+ if (err instanceof BitgenError) {
24
+ console.log(err.status) // 416
25
+ console.log(err.code) // 'requested_amount_error'
26
+ console.log(err.message) // '[416] requested_amount_error'
27
+ }
28
+ }
29
+ ```
30
+
31
+ `instanceof BitgenError` is reliable even when the ESM and CommonJS builds of the SDK are both loaded in the same process. `JSON.stringify(err)` gives `{ name, message, status, code }` — `cause` is left out.
32
+
33
+ ## No HTTP response
34
+
35
+ | Status | `code` | Meaning |
36
+ |---|---|---|
37
+ | `0` | `request_timeout` | No response within the configured `timeout` — 30 seconds by default ([Timeout](configuration.md#timeout)) |
38
+ | `0` | `network_error` | The request never got an HTTP answer: DNS, connection refused, TLS… `err.cause` holds the native error |
39
+
40
+ ## Unexpected answers
41
+
42
+ When the body is not the API's JSON error payload (proxy error page, unexpected `500`…), `code` holds the raw response text, truncated to 200 characters; the same goes for a 2xx answer that is not JSON. A `500` is not always a failure of the API: it is also its answer to a request it does not recognize — with a custom `host`, check that it reaches the API unchanged. Redirects are never followed: a `3xx` answer is reported as a `BitgenError`, and the key is never replayed to another host. A value the SDK enumerates (a `state`, a `mode`…) is never checked: the API may add one, the types keep it as a string ([Constants](concepts.md#constants)).
43
+
44
+ ## Rejected promises
45
+
46
+ Every method returns a promise. An invalid argument — an empty user, asset, order or amount, a model without uuid, a negative or non-finite number, a `tolerance` that is not a number of seconds… — rejects it with a `TypeError` **before any request is sent**, so `.catch()` and `Promise.all` see every failure. The only synchronous error of the SDK is an invalid configuration, thrown by `new BitgenClient()` ([Validation](configuration.md#validation)).
47
+
48
+ ## Common errors
49
+
50
+ The errors any call can answer. Each resource page lists its own codes.
51
+
52
+ | Status | `code` | Meaning |
53
+ |---|---|---|
54
+ | `401` | `auth_missing` | The `BITGEN-Scope` or `Api-key` header is missing |
55
+ | `401` | `api_key_missmatch` | The key is unknown, revoked or expired, or `scope` is not the key's organization |
56
+ | `403` | `unknown_organization` | The organization of the key is unknown |
57
+ | `403` | `organization_not_enabled` | The organization is not enabled |
58
+ | `403` | `api_disabled` | API access is not enabled for the organization |
59
+ | `403` | `invalid_api_key` | The key is invalid |
60
+ | `403` | `expired_api_key` | The key has expired |
61
+ | `403` | `forbidden_permission` | The key does not carry the permission for this call — contact BITGEN |
62
+ | `400` | `required_index_missing::<field>` | A mandatory field is missing or empty |
63
+ | `404` | `unknown_<resource>` | The target does not exist — `unknown_user`, `unknown_asset`, `unknown_bank`… — or the API does not reveal it |
64
+ | `422` | `invalid_<param>` | A boolean filter (`includeClosed`, `includeRevoked`, `includeArchived`) is not a boolean value ([Query booleans](concepts.md#query-booleans)) |
65
+ | `423` | `blocked_by_alert` | The customer is under an active compliance alert (each resource page lists its `423` codes, with `account_frozen` and the lock codes) |
66
+
67
+ Webhook verification has its own codes, with `status: 0`: [Webhooks › verify](resource/webhooks.md#verify).
@@ -0,0 +1,43 @@
1
+ # Installation
2
+
3
+ `@bitgen/sdk` is the official Node.js SDK for the BITGEN API v4. It runs server-side only: the API accepts browser requests from a fixed list of origins, so the SDK is not meant to be used from a browser.
4
+
5
+ ## Requirements
6
+
7
+ - Node.js 20 or later
8
+ - No dependency: the SDK only uses what Node.js 20 already provides
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install @bitgen/sdk
14
+ ```
15
+
16
+ ## Import
17
+
18
+ ESM:
19
+
20
+ ```ts
21
+ import { BitgenClient, BitgenError, Env, Asset } from '@bitgen/sdk'
22
+ ```
23
+
24
+ CommonJS:
25
+
26
+ ```js
27
+ const { BitgenClient, BitgenError, Env, Asset } = require('@bitgen/sdk')
28
+ ```
29
+
30
+ The package exports the client (`BitgenClient`), its error class (`BitgenError`), two constants — `Env`, the environments, and `Asset`, the ISO codes of the main assets ([Configuration](configuration.md), [Assets](concepts.md#assets)) — and the constants naming the known values of the API (`AssetState`, `OrderState`, `Locale`, `OrganizationCategory`…), each also a type ([Constants](concepts.md#constants)).
31
+
32
+ ## TypeScript
33
+
34
+ Type declarations ship with the package: nothing else to install. Every type a method takes or returns is exported under the same name as in the documentation (`BitgenConfig`, `Customer`, `Wallet`, `Order`, `UserRef`, `AssetInput`…):
35
+
36
+ ```ts
37
+ import type { BitgenConfig, Customer, Wallet } from '@bitgen/sdk'
38
+ ```
39
+
40
+ ## Next steps
41
+
42
+ - [Quick start](quick-start.md) — create the client and run a first customer journey
43
+ - [Configuration](configuration.md) — credentials, environments, custom host, timeout
@@ -0,0 +1,58 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 560" role="img" aria-labelledby="title">
2
+ <title id="title">Activation and identity: from the creation of a customer to the financial resources</title>
3
+ <defs>
4
+ <marker id="m94a3b8" viewBox="0 0 8 8" refX="7" refY="4" markerWidth="8" markerHeight="8" markerUnits="userSpaceOnUse" orient="auto"><path d="M0,0.5 L7,4 L0,7.5 z" fill="#94a3b8"/></marker>
5
+ <pattern id="grid" width="16" height="16" patternUnits="userSpaceOnUse"><circle cx="8" cy="8" r="1" fill="#e2e8f0"/></pattern>
6
+ <filter id="shadow" x="-10%" y="-20%" width="120%" height="160%"><feDropShadow dx="0" dy="1" stdDeviation="2" flood-color="#0f172a" flood-opacity="0.10"/></filter>
7
+ </defs>
8
+ <rect width="1000" height="560" fill="#ffffff"/>
9
+ <rect width="1000" height="560" fill="url(#grid)"/>
10
+ <text x="520.0" y="34.5" font-family="Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="14" font-weight="600" fill="#0f172a" text-anchor="middle">Activation and identity</text>
11
+ <rect x="420" y="54" width="200" height="40" rx="10" fill="#ffffff" stroke="#e2e8f0" filter="url(#shadow)"/>
12
+ <text x="520.0" y="78.7" font-family="Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="13" font-weight="500" fill="#0f172a" text-anchor="middle">Create a customer</text>
13
+ <path d="M520,95 V116" fill="none" stroke="#94a3b8" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" marker-end="url(#m94a3b8)"/>
14
+ <rect x="455" y="118" width="130" height="24" rx="12.0" fill="#0f172a"/>
15
+ <text x="520.0" y="134.1" font-family="'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="11.5" font-weight="500" fill="#ffffff" text-anchor="middle">needActivation?</text>
16
+ <path d="M520,143 V178" fill="none" stroke="#94a3b8" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" marker-end="url(#m94a3b8)"/>
17
+ <rect x="533" y="148" width="66" height="24" rx="12.0" fill="#f1f5f9"/>
18
+ <text x="566.0" y="164.1" font-family="Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="11.5" font-weight="500" fill="#475569" text-anchor="middle">default</text>
19
+ <rect x="360" y="180" width="320" height="56" rx="10" fill="#ffffff" stroke="#e2e8f0" filter="url(#shadow)"/>
20
+ <text x="520.0" y="204.2" font-family="Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="13" font-weight="400" fill="#0f172a" text-anchor="middle">Activation email sent, account <tspan font-family="'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="0.92em" font-weight="600" fill="#4338ca">CREATED</tspan></text>
21
+ <text x="520.0" y="221.2" font-family="Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="13" font-weight="400" fill="#0f172a" text-anchor="middle">until the customer clicks it</text>
22
+ <path d="M520,237 V282" fill="none" stroke="#94a3b8" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" marker-end="url(#m94a3b8)"/>
23
+ <rect x="529" y="247" width="54" height="24" rx="12.0" fill="#f1f5f9"/>
24
+ <text x="556.0" y="263.1" font-family="Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="11.5" font-weight="500" fill="#475569" text-anchor="middle">click</text>
25
+ <path d="M590,130 H790 Q800,130 800,140 V306 Q800,316 790,316 H612" fill="none" stroke="#94a3b8" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" marker-end="url(#m94a3b8)"/>
26
+ <rect x="713" y="118" width="54" height="24" rx="12.0" fill="#f1f5f9"/>
27
+ <text x="740.0" y="134.1" font-family="Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="11.5" font-weight="500" fill="#475569" text-anchor="middle">false</text>
28
+ <rect x="430" y="296" width="180" height="40" rx="10" fill="#ffffff" stroke="#e2e8f0" filter="url(#shadow)"/>
29
+ <text x="520.0" y="320.7" font-family="Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="13" font-weight="400" fill="#0f172a" text-anchor="middle">Account <tspan font-family="'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="0.92em" font-weight="600" fill="#4338ca">ENABLED</tspan></text>
30
+ <rect x="40" y="176" width="340" height="106" rx="10" fill="#ffffff" stroke="#e2e8f0" filter="url(#shadow)"/>
31
+ <path d="M50,188 V270" stroke="#dc2626" stroke-width="3" stroke-linecap="round"/>
32
+ <text x="64.0" y="200.0" font-family="Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="12" font-weight="600" fill="#0f172a" text-anchor="start">Meanwhile, only the customer resource sees it</text>
33
+ <text x="64.0" y="220.0" font-family="Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="11.5" font-weight="400" fill="#475569" text-anchor="start">bank: <tspan font-family="'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="0.92em" font-weight="600" fill="#dc2626">404 unknown_bank</tspan></text>
34
+ <text x="64.0" y="237.0" font-family="Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="11.5" font-weight="400" fill="#475569" text-anchor="start">custody, staking: <tspan font-family="'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="0.92em" font-weight="600" fill="#dc2626">403 org_forbidden</tspan></text>
35
+ <text x="64.0" y="254.0" font-family="Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="11.5" font-weight="400" fill="#475569" text-anchor="start">trading: <tspan font-family="'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="0.92em" font-weight="600" fill="#dc2626">403 user_not_in_scope</tspan></text>
36
+ <path d="M380,229 H358" fill="none" stroke="#cbd5e1" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="4 4"/>
37
+ <path d="M520,337 V358" fill="none" stroke="#94a3b8" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" marker-end="url(#m94a3b8)"/>
38
+ <rect x="418" y="360" width="205" height="24" rx="12.0" fill="#0f172a"/>
39
+ <text x="520.0" y="376.1" font-family="Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="11.5" font-weight="500" fill="#ffffff" text-anchor="middle">BITGEN identity verification?</text>
40
+ <path d="M520,385 V420" fill="none" stroke="#94a3b8" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" marker-end="url(#m94a3b8)"/>
41
+ <rect x="530" y="390" width="41" height="24" rx="12.0" fill="#f1f5f9"/>
42
+ <text x="550.0" y="406.1" font-family="Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="11.5" font-weight="500" fill="#475569" text-anchor="middle">yes</text>
43
+ <rect x="360" y="422" width="320" height="56" rx="10" fill="#ffffff" stroke="#e2e8f0" filter="url(#shadow)"/>
44
+ <text x="520.0" y="446.2" font-family="Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="13" font-weight="400" fill="#0f172a" text-anchor="middle">Identity verification, KYC or KYB,</text>
45
+ <text x="520.0" y="463.2" font-family="Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="13" font-weight="400" fill="#0f172a" text-anchor="middle">until the identity is <tspan font-family="'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="0.92em" font-weight="600" fill="#4338ca">VALIDATED</tspan></text>
46
+ <path d="M520,479 V510" fill="none" stroke="#94a3b8" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" marker-end="url(#m94a3b8)"/>
47
+ <path d="M620,372 H790 Q800,372 800,382 V520 Q800,530 790,530 H672" fill="none" stroke="#94a3b8" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" marker-end="url(#m94a3b8)"/>
48
+ <rect x="733" y="360" width="35" height="24" rx="12.0" fill="#f1f5f9"/>
49
+ <text x="750.0" y="376.1" font-family="Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="11.5" font-weight="500" fill="#475569" text-anchor="middle">no</text>
50
+ <rect x="40" y="412" width="340" height="88" rx="10" fill="#ffffff" stroke="#e2e8f0" filter="url(#shadow)"/>
51
+ <path d="M50,424 V488" stroke="#dc2626" stroke-width="3" stroke-linecap="round"/>
52
+ <text x="64.0" y="436.0" font-family="Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="12" font-weight="600" fill="#0f172a" text-anchor="start">Before that</text>
53
+ <text x="64.0" y="456.0" font-family="Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="11.5" font-weight="400" fill="#475569" text-anchor="start">EUR account: <tspan font-family="'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="0.92em" font-weight="600" fill="#dc2626">412 owner_identity_not_validated</tspan></text>
54
+ <text x="64.0" y="473.0" font-family="Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="11.5" font-weight="400" fill="#475569" text-anchor="start">custody, trading, staking: <tspan font-family="'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="0.92em" font-weight="600" fill="#dc2626">403 kyc_not_validated</tspan></text>
55
+ <path d="M380,456 H358" fill="none" stroke="#cbd5e1" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="4 4"/>
56
+ <rect x="370" y="510" width="300" height="40" rx="10" fill="#dcfce7" stroke="#bbf7d0" filter="url(#shadow)"/>
57
+ <text x="520.0" y="534.7" font-family="Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="13" font-weight="600" fill="#15803d" text-anchor="middle">Bank account, custody, trading and staking</text>
58
+ </svg>