From 2e033ad9b20747bf4e8df086c55e6b0250c89a79 Mon Sep 17 00:00:00 2001 From: Asaf Shushan Date: Wed, 10 Apr 2024 11:04:59 +0300 Subject: [PATCH] fix: modify error message when secretKey missing and fix readme doc --- README.md | 9 ++++----- client/client.ts | 2 +- package-lock.json | 12 ++++++------ tests/client.spec.ts | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 21edc0a..1798d69 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Fireblocks Typescript SDK +# Official Fireblocks TypeScript SDK [![npm version](https://badge.fury.io/js/@fireblocks%2Fts-sdk.svg)](https://badge.fury.io/js/@fireblocks%2Fts-sdk) The Fireblocks SDK allows developers to seamlessly integrate with the Fireblocks platform and perform a variety of operations, including managing vault accounts and executing transactions securely. @@ -98,19 +98,18 @@ async function getVaultPagedAccounts(limit) { To make a transaction between vault accounts, you can use the following function:

```typescript -import { Fireblocks, TransferPeerPathTypeEnum } from "@fireblocks/ts-sdk"; +import { TransferPeerPathType } from "@fireblocks/ts-sdk"; async function createTransaction(assetId, amount, srcId, destId) { - const fireblocks = new Fireblocks(); let payload = { assetId, amount, source: { - type: TransferPeerPathTypeEnum.VaultAccount, + type: TransferPeerPathType.VaultAccount, id: String(srcId) }, destination: { - type: TransferPeerPathTypeEnum.VaultAccount, + type: TransferPeerPathType.VaultAccount, id: String(destId) }, note: "Your first transaction!" diff --git a/client/client.ts b/client/client.ts index 568a464..eaeeced 100644 --- a/client/client.ts +++ b/client/client.ts @@ -93,7 +93,7 @@ export class Fireblocks { let secretKey = conf.secretKey || process.env.FIREBLOCKS_SECRET_KEY; if (!secretKey ) { - throw new Error("apiKey is required either in the configuration or as environment variable FIREBLOCKS_API_KEY"); + throw new Error("secretKey is required either in the configuration or as environment variable FIREBLOCKS_SECRET_KEY"); } let basePath = conf.basePath || process.env.FIREBLOCKS_BASE_PATH; diff --git a/package-lock.json b/package-lock.json index 641d342..a7350dc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1392,9 +1392,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001606", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001606.tgz", - "integrity": "sha512-LPbwnW4vfpJId225pwjZJOgX1m9sGfbw/RKJvw/t0QhYOOaTXHvkjVGFGPpvwEzufrjvTlsULnVTxdy4/6cqkg==", + "version": "1.0.30001608", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001608.tgz", + "integrity": "sha512-cjUJTQkk9fQlJR2s4HMuPMvTiRggl0rAVMtthQuyOlDWuqHXqN8azLq+pi8B2TjwKJ32diHjUqRIKeFX4z1FoA==", "dev": true, "funding": [ { @@ -1638,9 +1638,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.729", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.729.tgz", - "integrity": "sha512-bx7+5Saea/qu14kmPTDHQxkp2UnziG3iajUQu3BxFvCOnpAJdDbMV4rSl+EqFDkkpNNVUFlR1kDfpL59xfy1HA==", + "version": "1.4.731", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.731.tgz", + "integrity": "sha512-+TqVfZjpRz2V/5SPpmJxq9qK620SC5SqCnxQIOi7i/U08ZDcTpKbT7Xjj9FU5CbXTMUb4fywbIr8C7cGv4hcjw==", "dev": true }, "node_modules/emittery": { diff --git a/tests/client.spec.ts b/tests/client.spec.ts index d633f37..8625299 100644 --- a/tests/client.spec.ts +++ b/tests/client.spec.ts @@ -192,6 +192,39 @@ describe("Fireblocks Client Tests", () => { jest.clearAllMocks(); }); + describe('Fireblocks client construction tests', () => { + it('Should construct Fireblocks client', () => { + expect(fireblocks).toBeInstanceOf(Fireblocks); + }); + + it('Should throw an error when apiKey is not provided', () => { + expect(() => { + new Fireblocks({ + basePath: "http://mock-server", + secretKey: "secretKey" + }); + }).toThrowError("apiKey is required either in the configuration or as environment variable FIREBLOCKS_API_KEY"); + }); + + it('Should throw an error when secretKey is not provided', () => { + expect(() => { + new Fireblocks({ + apiKey: "my-api-key", + basePath: "http://mock-server" + }); + }).toThrowError("secretKey is required either in the configuration or as environment variable FIREBLOCKS_SECRET_KEY"); + }); + + it('Should throw an error when basePath is not provided', () => { + expect(() => { + new Fireblocks({ + apiKey: "my-api-key", + secretKey: "secretKey" + }); + }).toThrowError("basePath is required either in the configuration or as environment variable FIREBLOCKS_BASE_PATH"); + }); + }); + describe('Api getters tests', () => { const expectedConfig = new Configuration({ basePath: "http://mock-server" });