-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
590abcc
commit f0baecf
Showing
9 changed files
with
143 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ node_modules/ | |
dist/ | ||
/types/* | ||
lib/ | ||
*.log | ||
*.log | ||
ks/test-results/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
export const env = process.env.TEST_ENV || "prod" | ||
const CURRENT_FILE_DIR = __dirname; | ||
export const getTestConfig = (): Record<string, string> => { | ||
|
||
type config = { | ||
COMPOSIO_API_KEY: string; | ||
BACKEND_HERMES_URL: string; | ||
} | ||
|
||
export const getTestConfig = (): config => { | ||
const path = `${CURRENT_FILE_DIR}/test.config.${env}.json`; | ||
return JSON.parse(JSON.stringify(require(path))); | ||
try { | ||
return JSON.parse(JSON.stringify(require(path))) as unknown as config; | ||
} catch (error) { | ||
console.error("Error loading test config file:", error); | ||
|
||
throw new Error("Error loading test config file. You can create test.{{env}}.json file in the config folder."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import apiClient from "../client/client" | ||
import { client as axiosClient } from "../client/services.gen" | ||
|
||
/** | ||
* Class representing the details required to initialize and configure the API client. | ||
*/ | ||
export class BackendClient { | ||
/** | ||
* The API key used for authenticating requests. | ||
*/ | ||
public apiKey: string; | ||
|
||
/** | ||
* The base URL of the API against which requests will be made. | ||
*/ | ||
public baseUrl: string; | ||
|
||
/** | ||
* The runtime environment where the client is being used. | ||
*/ | ||
public runtime: string; | ||
|
||
/** | ||
* Creates an instance of apiClientDetails. | ||
* @param {string} apiKey - The API key for client initialization. | ||
* @param {string} baseUrl - The base URL for the API client. | ||
* @param {string} runtime - The runtime environment identifier. | ||
* @throws Will throw an error if the API key is not provided. | ||
*/ | ||
constructor(apiKey: string, baseUrl: string, runtime?: string) { | ||
this.runtime = runtime || ''; | ||
this.apiKey = apiKey; | ||
this.baseUrl = baseUrl; | ||
|
||
if (!apiKey) { | ||
throw new Error(`API Key is required for initializing the client`); | ||
} | ||
|
||
this.initializeApiClient(); | ||
} | ||
|
||
/** | ||
* Retrieves the client ID from the user's information. | ||
* @returns {Promise<string>} A promise that resolves to the client ID. | ||
* @throws Will throw an error if the HTTP request fails. | ||
*/ | ||
public async getClientId(): Promise<string> { | ||
const response = await apiClient.clientAuthService.getUserInfo(); | ||
if (response.status !== 200) { | ||
throw new Error(`HTTP Error: ${response.status}`); | ||
} | ||
return (response.data as unknown as Record<string, Record<string, string>>).client.id; | ||
} | ||
|
||
/** | ||
* Initializes the API client with the provided configuration. | ||
* @private | ||
*/ | ||
private initializeApiClient() { | ||
axiosClient.setConfig({ | ||
baseURL: this.baseUrl, | ||
headers: { | ||
'X-API-KEY': `${this.apiKey}`, | ||
'X-SOURCE': 'js_sdk', | ||
'X-RUNTIME': this.runtime | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { get } from "http"; | ||
import { BackendClient } from "../models/backendClient"; | ||
import { getTestConfig } from "../../../config/getTestConfig"; | ||
|
||
|
||
export const getBackendInstance = (): BackendClient => { | ||
const testConfig = getTestConfig(); | ||
if (testConfig["COMPOSIO_API_KEY"] === undefined) { | ||
throw new Error("COMPOSIO_API_KEY is not set in the test config"); | ||
} | ||
if (testConfig["BACKEND_HERMES_URL"] === undefined) { | ||
throw new Error("BACKEND_HERMES_URL is not set in the test config."); | ||
} | ||
const COMPOSIO_API_KEY = testConfig["COMPOSIO_API_KEY"]; | ||
const BACKEND_HERMES_URL = testConfig["BACKEND_HERMES_URL"]; | ||
return new BackendClient(COMPOSIO_API_KEY, BACKEND_HERMES_URL); | ||
} |