Skip to content

Commit

Permalink
Add possibility to turn off auth for specific socket
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Warda committed Mar 22, 2024
1 parent 4b6a34f commit 796abc0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export function usePipelineRun(
payload: unknown
) => void = () => {},
onBlockStatusChange: (blockId: string, isWorking: boolean) => void = () => {},
onError: (blockId: string, errors: string[]) => void
onError: (blockId: string, errors: string[]) => void,
useAuth: boolean = true
) {
const buildel = useRef<BuildelSocket>();
const run = useRef<BuildelRun>();
Expand All @@ -39,6 +40,7 @@ export function usePipelineRun(
useEffect(() => {
buildel.current = new BuildelSocket(organizationId, {
socketUrl: "/super-api/socket",
useAuth,
});
buildel.current.connect().then((buildel) => {
run.current = buildel.run(pipelineId, {
Expand Down
9 changes: 8 additions & 1 deletion packages/buildel/src/buildel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,30 @@ interface BuildelSocketOptions {
socketUrl?: string;
authUrl?: string;
headers?: Record<string, string>;
useAuth?: boolean;
}
export class BuildelSocket {
private readonly socket: Socket;
private readonly id: string;
private readonly authUrl: string;
private readonly socketUrl: string;
private readonly headers: Record<string, string>;
private readonly useAuth: boolean = true;

constructor(
private readonly organizationId: number,
options: BuildelSocketOptions = {}
) {
this.authUrl = options.authUrl ?? "/super-api/channel_auth";
this.socketUrl = options.socketUrl ?? "wss://buildel-api.fly.dev/socket";
this.socketUrl = options.socketUrl ?? "wss://api.buildel.ai/socket";
this.headers = options.headers ?? {};
this.id = v4();
this.socket = new Socket(this.socketUrl, {
params: {
id: this.id,
},
});
this.useAuth = options.useAuth ?? true;
}

public async connect() {
Expand Down Expand Up @@ -81,6 +84,7 @@ export class BuildelSocket {
pipelineId,
this.authUrl,
this.headers,
this.useAuth,
{ onBlockOutput, onBlockStatusChange, onStatusChange, onBlockError }
);
}
Expand All @@ -96,6 +100,7 @@ export class BuildelRun {
private readonly pipelineId: number,
private readonly authUrl: string,
private readonly headers: Record<string, string>,
private readonly useAuth: boolean,
private readonly handlers: {
onBlockOutput: (
blockId: string,
Expand Down Expand Up @@ -202,6 +207,8 @@ export class BuildelRun {
}

private async authenticateChannel() {
if (!this.useAuth) return {};

return await fetch(this.authUrl, {
headers: {
"Content-Type": "application/json",
Expand Down

0 comments on commit 796abc0

Please sign in to comment.