From 4a98de9efb269ecfc40ed6e8f5215b733cceb9a6 Mon Sep 17 00:00:00 2001 From: Oren Date: Mon, 16 Jan 2023 12:48:04 +0200 Subject: [PATCH 1/7] Add version to user-agent --- package.json | 4 ++-- src/api-client.ts | 3 ++- tsconfig.json | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 360695aa..fb49f15b 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "fireblocks-sdk", "version": "3.1.2", - "main": "dist/fireblocks-sdk.js", - "types": "dist/fireblocks-sdk.d.ts", + "main": "dist/src/fireblocks-sdk.js", + "types": "dist/src/fireblocks-sdk.d.ts", "scripts": { "build": "tsc && npm run tslint", "tslint": "tslint -c tslint.json -p tsconfig.json --fix", diff --git a/src/api-client.ts b/src/api-client.ts index 83cc51d5..a2f51357 100644 --- a/src/api-client.ts +++ b/src/api-client.ts @@ -4,6 +4,7 @@ import { IAuthProvider } from "./iauth-provider"; import { RequestOptions } from "./types"; import { SDKOptions } from "./fireblocks-sdk"; import axios, { AxiosInstance } from "axios"; +import { version as SDK_VERSION } from "../package.json"; export class ApiClient { private axiosInstance: AxiosInstance; @@ -21,7 +22,7 @@ export class ApiClient { } private getUserAgent(): string { - let userAgent = `fireblocks-sdk-js`; + let userAgent = `fireblocks-sdk-js/${SDK_VERSION}`; if (!this.options?.anonymousPlatform) { userAgent += ` (${os.type()} ${os.release()}; ${platform.name} ${platform.version}; ${os.arch()})`; } diff --git a/tsconfig.json b/tsconfig.json index 73c98c32..f029d1c1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,8 @@ "declaration": true, "sourceMap": true, "outDir": "dist", - "baseUrl": "." + "baseUrl": ".", + "resolveJsonModule": true }, "include": [ "./src/**/*" From 30e42386fc67a5bc81f771315712108c82d6a7c9 Mon Sep 17 00:00:00 2001 From: Oren Date: Mon, 16 Jan 2023 13:23:55 +0200 Subject: [PATCH 2/7] Add userAgent to SDKOptions --- README.md | 1 + src/api-client.ts | 3 +++ src/fireblocks-sdk.ts | 1 + 3 files changed, 5 insertions(+) diff --git a/README.md b/README.md index e0431091..7848c4f4 100644 --- a/README.md +++ b/README.md @@ -44,5 +44,6 @@ interface SDKOptions { timeoutInMs?: number; // HTTP request timeout proxy?: AxiosProxyConfig | false; // Proxy configuration anonymousPlatform?: boolean; // Whether to remove platform from User-Agent header + userAgent?: string; // Extra data to be passed in the User-Agent header } ``` diff --git a/src/api-client.ts b/src/api-client.ts index a2f51357..d1d063e9 100644 --- a/src/api-client.ts +++ b/src/api-client.ts @@ -26,6 +26,9 @@ export class ApiClient { if (!this.options?.anonymousPlatform) { userAgent += ` (${os.type()} ${os.release()}; ${platform.name} ${platform.version}; ${os.arch()})`; } + if (this.options?.userAgent) { + userAgent += `/${this.options.userAgent}`; + } return userAgent; } diff --git a/src/fireblocks-sdk.ts b/src/fireblocks-sdk.ts index d5aa098d..ca99e99d 100644 --- a/src/fireblocks-sdk.ts +++ b/src/fireblocks-sdk.ts @@ -76,6 +76,7 @@ export interface SDKOptions { timeoutInMs?: number; proxy?: AxiosProxyConfig | false; anonymousPlatform?: boolean; + userAgent?: string; } export class FireblocksSDK { From e800890d196f76482e9ab0a156ef47c4dd22fde4 Mon Sep 17 00:00:00 2001 From: Oren Date: Tue, 17 Jan 2023 09:33:47 +0200 Subject: [PATCH 3/7] Prepend userAgent instead of appending it According to RFC7231: > By convention, the product identifiers are listed in decreasing order of their significance for identifying the user agent software. https://www.rfc-editor.org/rfc/rfc7231#section-5.5.3 --- README.md | 2 +- src/api-client.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7848c4f4..95c9e288 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,6 @@ interface SDKOptions { timeoutInMs?: number; // HTTP request timeout proxy?: AxiosProxyConfig | false; // Proxy configuration anonymousPlatform?: boolean; // Whether to remove platform from User-Agent header - userAgent?: string; // Extra data to be passed in the User-Agent header + userAgent?: string; // Additional product identifier to be prepended to the User-Agent header } ``` diff --git a/src/api-client.ts b/src/api-client.ts index d1d063e9..6dfc78cd 100644 --- a/src/api-client.ts +++ b/src/api-client.ts @@ -27,7 +27,7 @@ export class ApiClient { userAgent += ` (${os.type()} ${os.release()}; ${platform.name} ${platform.version}; ${os.arch()})`; } if (this.options?.userAgent) { - userAgent += `/${this.options.userAgent}`; + userAgent = `${this.options.userAgent} ${userAgent}`; } return userAgent; } From e17e9ccc12300e2e7cc92453a93a83d7627cff80 Mon Sep 17 00:00:00 2001 From: Oren Date: Tue, 17 Jan 2023 16:42:33 +0200 Subject: [PATCH 4/7] Use node v16 for publishing --- .github/workflows/publish-npm.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml index 63e56a51..7edc38ee 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -13,7 +13,7 @@ jobs: token: ${{ secrets.RELEASE_TOKEN }} - uses: actions/setup-node@v2 with: - node-version: '12.x' + node-version: '16.x' registry-url: 'https://registry.npmjs.org' - run: npm install - run: | From 2ede51d13619c95c698b0014107fe666e17b2beb Mon Sep 17 00:00:00 2001 From: Oren Date: Wed, 18 Jan 2023 09:37:02 +0200 Subject: [PATCH 5/7] Use npm v8 for building --- .github/workflows/node.js.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 3dc69d00..56478007 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -26,5 +26,7 @@ jobs: with: node-version: ${{ matrix.node-version }} cache: 'npm' + - run: npm install -g npm@8 - run: npm ci - run: npm run build --if-present + - run: npm pack From 82bdd168a721d6afce7cbdaebfaf2b420af7cb2e Mon Sep 17 00:00:00 2001 From: Oren Date: Thu, 19 Jan 2023 17:41:23 +0200 Subject: [PATCH 6/7] Add comments to SDKOptions definition --- src/fireblocks-sdk.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/fireblocks-sdk.ts b/src/fireblocks-sdk.ts index ca99e99d..13192a06 100644 --- a/src/fireblocks-sdk.ts +++ b/src/fireblocks-sdk.ts @@ -73,10 +73,10 @@ import { AxiosProxyConfig } from "axios"; export * from "./types"; export interface SDKOptions { - timeoutInMs?: number; - proxy?: AxiosProxyConfig | false; - anonymousPlatform?: boolean; - userAgent?: string; + timeoutInMs?: number; // HTTP request timeout + proxy?: AxiosProxyConfig | false; // Proxy configuration + anonymousPlatform?: boolean; // Whether to remove platform from User-Agent header + userAgent?: string; // Additional product identifier to be prepended to the User-Agent header } export class FireblocksSDK { From cbb0927e2960faf9ff19788e7ec3b30e55f6caf2 Mon Sep 17 00:00:00 2001 From: Oren Date: Thu, 19 Jan 2023 17:57:03 +0200 Subject: [PATCH 7/7] Use TSDoc notation For improved IDE integration on hover --- README.md | 15 +++++++++++---- src/fireblocks-sdk.ts | 15 +++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 95c9e288..d66c7339 100644 --- a/README.md +++ b/README.md @@ -41,9 +41,16 @@ const fireblocks = new FireblocksSDK(privateKey, apiKey, baseUrl, authProvider, The `options` argument has the following structure: ```typescript interface SDKOptions { - timeoutInMs?: number; // HTTP request timeout - proxy?: AxiosProxyConfig | false; // Proxy configuration - anonymousPlatform?: boolean; // Whether to remove platform from User-Agent header - userAgent?: string; // Additional product identifier to be prepended to the User-Agent header + /** HTTP request timeout */ + timeoutInMs?: number; + + /** Proxy configurations */ + proxy?: AxiosProxyConfig | false; + + /** Whether to remove platform from User-Agent header */ + anonymousPlatform?: boolean; + + /** Additional product identifier to be prepended to the User-Agent header */ + userAgent?: string; } ``` diff --git a/src/fireblocks-sdk.ts b/src/fireblocks-sdk.ts index 13192a06..e6a3d9a3 100644 --- a/src/fireblocks-sdk.ts +++ b/src/fireblocks-sdk.ts @@ -73,10 +73,17 @@ import { AxiosProxyConfig } from "axios"; export * from "./types"; export interface SDKOptions { - timeoutInMs?: number; // HTTP request timeout - proxy?: AxiosProxyConfig | false; // Proxy configuration - anonymousPlatform?: boolean; // Whether to remove platform from User-Agent header - userAgent?: string; // Additional product identifier to be prepended to the User-Agent header + /** HTTP request timeout */ + timeoutInMs?: number; + + /** Proxy configurations */ + proxy?: AxiosProxyConfig | false; + + /** Whether to remove platform from User-Agent header */ + anonymousPlatform?: boolean; + + /** Additional product identifier to be prepended to the User-Agent header */ + userAgent?: string; } export class FireblocksSDK {