Skip to content

Commit

Permalink
feat: added method to override and exported command error
Browse files Browse the repository at this point in the history
  • Loading branch information
flowcore-platform committed Jan 12, 2025
1 parent 9ee6808 commit e78a053
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/common/flowcore-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export type ClientOptions = ClientOptionsBearer | ClientOptionsApiKey
*/
export class FlowcoreClient {
private mode: "apiKey" | "bearer"
private baseUrl: string | undefined

constructor(private readonly options: ClientOptions) {
if ((this.options as ClientOptionsBearer).getBearerToken) {
this.mode = "bearer"
Expand Down Expand Up @@ -90,8 +92,9 @@ export class FlowcoreClient {
const authHeader = await this.getAuthHeader()

let response: Response
const url = this.baseUrl ? this.baseUrl + request.path : request.baseUrl + request.path
try {
response = await fetch(request.baseUrl + request.path, {
response = await fetch(url, {
method: request.method,
headers: {
...request.headers,
Expand Down Expand Up @@ -134,6 +137,13 @@ export class FlowcoreClient {
return request.waitForResponse(this, parsedBody)
}

/**
* Override the base URL for all commands
*/
setBaseUrl(baseUrl: string): void {
this.baseUrl = baseUrl
}

/**
* Execute a command
*/
Expand Down
1 change: 1 addition & 0 deletions src/exceptions/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./client-error.ts"
export * from "./invalid-response.ts"
export * from "./not-found.ts"
export * from "./command-error.ts"

0 comments on commit e78a053

Please sign in to comment.