From 6d6b2340896a3dfc8ee237803614f64bd93c3eae Mon Sep 17 00:00:00 2001 From: Dom Webber Date: Wed, 20 Nov 2024 18:12:36 +0000 Subject: [PATCH] Offload authentication to use-case --- .changeset/red-wasps-turn.md | 5 +++++ src/Client.ts | 11 ----------- 2 files changed, 5 insertions(+), 11 deletions(-) create mode 100644 .changeset/red-wasps-turn.md diff --git a/.changeset/red-wasps-turn.md b/.changeset/red-wasps-turn.md new file mode 100644 index 00000000..602a60e7 --- /dev/null +++ b/.changeset/red-wasps-turn.md @@ -0,0 +1,5 @@ +--- +"@great-detail/whatsapp": patch +--- + +Offload authentication to use-case diff --git a/src/Client.ts b/src/Client.ts index 81d6a8a0..7a13cdc7 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -12,7 +12,6 @@ import Webhook from "./Webhook/index.js"; import type { Options as KyOptions } from "ky"; export interface Options { - accessToken?: string; prefixUrl?: string; graphVersion?: `v${string}` | (string & NonNullable); } @@ -25,21 +24,11 @@ export default class Client { public webhook: Webhook; constructor({ - accessToken = process.env.WHATSAPP_ACCESS_TOKEN, prefixUrl = "https://graph.facebook.com", graphVersion = "v20.0", }: Options = {}) { - if (!accessToken) { - throw new Error( - "No access token set in process.env.WHATSAPP_ACCESS_TOKEN", - ); - } - this._request = { prefixUrl: prefixUrl.replace(/\/$/, "") + graphVersion, - headers: { - Authorization: "Bearer " + accessToken, - }, }; this.message = new Message(this._request);