Skip to content

Commit

Permalink
fix: Refer only required values from process.env instead of fetching …
Browse files Browse the repository at this point in the history
…all (#933)

* Refer only required values from process.env instead of fetching all of them

* Update BaseTwilio.ts

* Fixing code style issues

* Update BaseTwilio.ts

---------

Co-authored-by: shrutiburman <[email protected]>
  • Loading branch information
AsabuHere and shrutiburman authored Jun 28, 2023
1 parent d8ed575 commit f7fd774
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/base/BaseTwilio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,30 @@ namespace Twilio {

constructor(username?: string, password?: string, opts?: ClientOpts) {
this.opts = opts || {};
this.env = this.opts.env || process.env;
this.env = this.opts.env || {};
this.username =
username ||
this.env.TWILIO_ACCOUNT_SID ||
username ??
this.env.TWILIO_ACCOUNT_SID ??
process.env.TWILIO_ACCOUNT_SID ??
(() => {
throw new Error("username is required");
})();
this.password =
password ||
this.env.TWILIO_AUTH_TOKEN ||
password ??
this.env.TWILIO_AUTH_TOKEN ??
process.env.TWILIO_AUTH_TOKEN ??
(() => {
throw new Error("password is required");
})();
this.accountSid = this.opts.accountSid || this.username;
this.edge = this.opts.edge || this.env.TWILIO_EDGE;
this.region = this.opts.region || this.env.TWILIO_REGION;
this.logLevel = this.opts.logLevel || this.env.TWILIO_LOG_LEVEL;
this.edge =
this.opts.edge ?? this.env.TWILIO_EDGE ?? process.env.TWILIO_EDGE;
this.region =
this.opts.region ?? this.env.TWILIO_REGION ?? process.env.TWILIO_REGION;
this.logLevel =
this.opts.logLevel ??
this.env.TWILIO_LOG_LEVEL ??
process.env.TWILIO_LOG_LEVEL;
this.autoRetry = this.opts.autoRetry || false;
this.maxRetries = this.opts.maxRetries;
this.userAgentExtensions = this.opts.userAgentExtensions || [];
Expand Down

0 comments on commit f7fd774

Please sign in to comment.