diff --git a/src/base/BaseTwilio.ts b/src/base/BaseTwilio.ts index 84fc262d8..3020bc9c9 100644 --- a/src/base/BaseTwilio.ts +++ b/src/base/BaseTwilio.ts @@ -109,17 +109,11 @@ namespace Twilio { this.username = username ?? this.env?.TWILIO_ACCOUNT_SID ?? - process.env.TWILIO_ACCOUNT_SID ?? - (() => { - throw new Error("username is required"); - })(); + process.env.TWILIO_ACCOUNT_SID; this.password = password ?? this.env?.TWILIO_AUTH_TOKEN ?? - process.env.TWILIO_AUTH_TOKEN ?? - (() => { - throw new Error("password is required"); - })(); + process.env.TWILIO_AUTH_TOKEN; this.accountSid = ""; this.setAccountSid(this.opts?.accountSid || this.username); this.invalidateOAuth(); @@ -156,8 +150,8 @@ namespace Twilio { } } - setAccountSid(accountSid: string) { - this.accountSid = accountSid; + setAccountSid(accountSid?: string) { + this.accountSid = accountSid || ""; if (this.accountSid && !this.accountSid?.startsWith("AC")) { const apiKeyMsg = this.accountSid?.startsWith("SK") @@ -228,6 +222,20 @@ namespace Twilio { const authStrategy = opts.authStrategy || this.credentialProvider?.toAuthStrategy(); + if (!authStrategy) { + if (!username) { + (() => { + throw new Error("username is required"); + })(); + } + + if (!password) { + (() => { + throw new Error("password is required"); + })(); + } + } + const headers = opts.headers || {}; const pkgVersion = moduleInfo.version;