-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding a function using api client and api client as singleton
- Loading branch information
1 parent
99ac130
commit 1ca0f76
Showing
2 changed files
with
47 additions
and
6 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { apis, baseURL } from "../constants/apis.constant"; | ||
import type { Config, TopsortEvent } from "../interfaces/events.interface"; | ||
import APIClient from "../lib/api-client"; | ||
|
||
/** | ||
* Reports an event to the Topsort API. | ||
* | ||
* @example | ||
* ```js | ||
* const event = { eventType: "test", eventData: {} }; | ||
* const config = { token: "my-token" }; | ||
* const result = await reportEvent(event, config); | ||
* console.log(result); // { ok: true, retry: false } | ||
* ``` | ||
* | ||
* @param event - The event to report. | ||
* @param config - The configuration object containing URL and token. | ||
* @returns {Promise<{ok: boolean, retry: boolean}>} The result of the report, indicating success and if a retry is needed. | ||
*/ | ||
export async function reportEvent( | ||
event: TopsortEvent, | ||
config: Config, | ||
): Promise<{ ok: boolean; retry: boolean }> { | ||
const url = `${config.host || baseURL}/${apis.events}`; | ||
await APIClient.post(url, event); | ||
|
||
return { | ||
ok: true, | ||
retry: false, | ||
}; | ||
} |
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