diff --git a/README.md b/README.md index 6dee5e9..a6cf436 100644 --- a/README.md +++ b/README.md @@ -49,5 +49,9 @@ When initializing the client object, an optional config can also be specified wi // Useful in the situations where the server connects directly to a node to fetch block info // and would like a predictable shard for the validation of tokens blockHashShard: 0; + + // Optional, to put custom HTTP headers in the request that is made to the api + // Useful in situations where a private api is used and is protected by a JTW token + extraRequestHeaders?: { [key: string]: string }; } ``` diff --git a/package-lock.json b/package-lock.json index 5b0142d..5f49112 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@multiversx/sdk-native-auth-client", - "version": "0.1.8", + "version": "1.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@multiversx/sdk-native-auth-client", - "version": "0.1.8", + "version": "1.0.1", "license": "GPL-3.0-or-later", "dependencies": { "axios": "^0.27.2" @@ -4480,20 +4480,6 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", "dev": true }, - "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", @@ -11567,13 +11553,6 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", "dev": true }, - "fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "optional": true - }, "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", diff --git a/package.json b/package.json index e3fe186..47aa5d6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@multiversx/sdk-native-auth-client", - "version": "1.0.0", + "version": "1.0.1", "description": "Native authentication client-side", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", diff --git a/src/entities/native.auth.client.config.ts b/src/entities/native.auth.client.config.ts index 5f0ee77..906c5b9 100644 --- a/src/entities/native.auth.client.config.ts +++ b/src/entities/native.auth.client.config.ts @@ -4,4 +4,5 @@ export class NativeAuthClientConfig { expirySeconds: number = 60 * 60 * 24; blockHashShard?: number; gatewayUrl?: string; + extraRequestHeaders?: { [key: string]: string }; } diff --git a/src/native.auth.client.ts b/src/native.auth.client.ts index 91ab981..54fef04 100644 --- a/src/native.auth.client.ts +++ b/src/native.auth.client.ts @@ -34,7 +34,7 @@ export class NativeAuthClient { private async getCurrentBlockHashWithGateway(): Promise { const round = await this.getCurrentRound(); const url = `${this.config.gatewayUrl}/blocks/by-round/${round}`; - const response = await axios.get(url); + const response = await this.get(url); const blocks = response.data.data.blocks; const block = blocks.filter((block: { shard: number }) => block.shard === this.config.blockHashShard)[0]; return block.hash; @@ -49,7 +49,7 @@ export class NativeAuthClient { } const url = `${this.config.gatewayUrl}/network/status/${this.config.blockHashShard}`; - const response = await axios.get(url); + const response = await this.get(url); const status = response.data.data.status; return status.erd_current_round; } @@ -60,7 +60,7 @@ export class NativeAuthClient { url += `&shard=${this.config.blockHashShard}`; } - const response = await axios.get(url); + const response = await this.get(url); return response.data[0].hash; } @@ -71,4 +71,8 @@ export class NativeAuthClient { private escape(str: string) { return str.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, ""); } + + private async get(url: string): Promise { + return await axios.get(url, { headers: this.config.extraRequestHeaders }); + } }