Skip to content

mergeClientOptions

function mergeClientOptions<S, O>(shared, overrides): S & O;

Defined in: lib/utils/twilio.utils.ts:117

Merge a named client’s overrides onto the shared options from forRoot().

Only defined values override. A key that is present but undefined inherits, rather than clearing the inherited value.

This deliberately differs from the plain object spread @nestjs/bullmq uses. The common way to configure a client is from the environment, and region: process.env.TWILIO_REGION is undefined whenever that variable is unset. Under a plain spread that silently clears an inherited region and sends traffic to the default edge. Nothing is lost by inheriting instead: region and edge are named values, so returning one client to the default is expressed by naming it (region: 'us1') rather than by erasing it.

Credentials are the exception: authToken and apiKey/apiSecret are alternative authentication modes, not independent settings, so they are inherited as a unit. A client that supplies either mode drops the inherited other one. Merging them field-by-field means an inherited authToken wins over an explicitly configured apiKey, making it impossible to register an API-key client beneath an auth-token root.

Type Parameter
S extends object
O extends object
Parameter Type Description
shared S | undefined Options from forRoot(), or undefined when none is registered.
overrides O The named client’s own options.

S & O

Transport settings inherit

mergeClientOptions(
{ accountSid: 'ACroot', authToken: 'r', region: 'ie1' },
{ name: 'billing', accountSid: 'ACbilling', authToken: 'b', region: undefined },
);
// => { accountSid: 'ACbilling', authToken: 'b', region: 'ie1' }

Credentials do not mix modes

mergeClientOptions(
{ accountSid: 'ACroot', authToken: 'r', region: 'ie1' },
{ name: 'realtime', apiKey: 'SKxxx', apiSecret: 's' },
);
// => { accountSid: 'ACroot', apiKey: 'SKxxx', apiSecret: 's', region: 'ie1' }
// the inherited authToken is dropped, not preferred over the API key