Skip to content

Commit f7fd774

Browse files
fix: Refer only required values from process.env instead of fetching 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 <87537688+shrutiburman@users.noreply.github.com>
1 parent d8ed575 commit f7fd774

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/base/BaseTwilio.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,30 @@ namespace Twilio {
7575

7676
constructor(username?: string, password?: string, opts?: ClientOpts) {
7777
this.opts = opts || {};
78-
this.env = this.opts.env || process.env;
78+
this.env = this.opts.env || {};
7979
this.username =
80-
username ||
81-
this.env.TWILIO_ACCOUNT_SID ||
80+
username ??
81+
this.env.TWILIO_ACCOUNT_SID ??
82+
process.env.TWILIO_ACCOUNT_SID ??
8283
(() => {
8384
throw new Error("username is required");
8485
})();
8586
this.password =
86-
password ||
87-
this.env.TWILIO_AUTH_TOKEN ||
87+
password ??
88+
this.env.TWILIO_AUTH_TOKEN ??
89+
process.env.TWILIO_AUTH_TOKEN ??
8890
(() => {
8991
throw new Error("password is required");
9092
})();
9193
this.accountSid = this.opts.accountSid || this.username;
92-
this.edge = this.opts.edge || this.env.TWILIO_EDGE;
93-
this.region = this.opts.region || this.env.TWILIO_REGION;
94-
this.logLevel = this.opts.logLevel || this.env.TWILIO_LOG_LEVEL;
94+
this.edge =
95+
this.opts.edge ?? this.env.TWILIO_EDGE ?? process.env.TWILIO_EDGE;
96+
this.region =
97+
this.opts.region ?? this.env.TWILIO_REGION ?? process.env.TWILIO_REGION;
98+
this.logLevel =
99+
this.opts.logLevel ??
100+
this.env.TWILIO_LOG_LEVEL ??
101+
process.env.TWILIO_LOG_LEVEL;
95102
this.autoRetry = this.opts.autoRetry || false;
96103
this.maxRetries = this.opts.maxRetries;
97104
this.userAgentExtensions = this.opts.userAgentExtensions || [];

0 commit comments

Comments
 (0)