Skip to content

Commit

Permalink
chore: use cloudflare worker env
Browse files Browse the repository at this point in the history
  • Loading branch information
gitcoindev committed Jan 29, 2024
1 parent 89d9644 commit a9867d9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { EmitterWebhookEvent as WebhookEvent, EmitterWebhookEventName as Webhook
import { createClient } from "@supabase/supabase-js";
import { Database } from "./types/database";
import { Logs } from "ubiquibot-logger";

const supabaseClient = createClient<Database>(process.env.SUPABASE_URL, process.env.SUPABASE_KEY, {
auth: { persistSession: false },
});
import { Env } from "./worker";

export class Context<T extends WebhookEventName = WebhookEventName> {
public key: WebhookEventName;
Expand All @@ -14,7 +11,7 @@ export class Context<T extends WebhookEventName = WebhookEventName> {
public payload: WebhookEvent<T>["payload"];
public logger: Logs;

constructor(event: WebhookEvent<T>) {
constructor(event: WebhookEvent<T>, env: Env) {
this.name = event.name;
this.id = event.id;
this.payload = event.payload;
Expand All @@ -23,7 +20,10 @@ export class Context<T extends WebhookEventName = WebhookEventName> {
} else {
this.key = this.name;
}
this.logger = new Logs(supabaseClient, process.env.LOG_RETRY_LIMIT, process.env.LOG_LEVEL, "ubiquibot-kernel");
const supabaseClient = createClient<Database>(env.SUPABASE_URL, env.SUPABASE_KEY, {
auth: { persistSession: false },
});
this.logger = new Logs(supabaseClient, env.LOG_RETRY_LIMIT, env.LOG_LEVEL, "ubiquibot-kernel");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/webhooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EmitterWebhookEvent } from "@octokit/webhooks";

export async function handleEvent(event: EmitterWebhookEvent) {
logger.info("Event received", { id: event.id, name: event.name });
event.logger.info("Event received", { id: event.id, name: event.name });
console.log(event);
}
6 changes: 5 additions & 1 deletion src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import { bindHandlers } from "./handlers";

const envSchema = T.Object({
WEBHOOK_SECRET: T.String(),
SUPABASE_URL: T.String(),
SUPABASE_KEY: T.String(),
LOG_LEVEL: T.String(),
LOG_RETRY_LIMIT: T.String(),
});

type Env = Static<typeof envSchema>;
export type Env = Static<typeof envSchema>;

export default {
async fetch(request: Request, env: Env): Promise<Response> {
Expand Down

0 comments on commit a9867d9

Please sign in to comment.