-
Notifications
You must be signed in to change notification settings - Fork 548
Description
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a feature request that matches the one I want to file, without success.
- This is not a general Twilio feature request or bug report. It is a feature request for the twilio-node JavaScript package.
Problem Description
Most time, developer only use a little part of the lib, for example, one is developing a sms sender will only use messaging api.
In this case tree shake can remove useless part to reduce the bundle size.
Currently twilio sdk provide a single entrypoint twilioSdk which include all service in it, which make bundler cannot recognize which part is not used, so all the code is include in the bundle.
I do see twilio sdk also export instanceClass like MessageInstance

but the type of paramter is confusing like V2010 need an ApiBase as paramter

and ApiBase use an any

make it hard to use
Proposed Solution
Provide a way to create single service for example:
import { MessageService } from 'twilio';
const service = new MessageService(process.env.ACCOUNT_SID, process.env.AUTH_TOKEN);
const messageInst = await service.create({to:"xx", messagingServiceSid:process.env.MESSAGING_SID, body:"yy"});
Alternatives Considered
Other way it to make a breaking change to the implementation of entry, remove all service from it, only use it as meta configuration, pass it to service function when send request, like
import twilio from 'twilio';
import { MessageService } from 'twilio';
const client= twilio(process.env.ACCOUNT_SID, process.env.AUTH_TOKEN);
const service = new MessageService(client);
const messageInst = await service.create({to:"xx", messagingServiceSid:process.env.MESSAGING_SID, body:"yy"});
Additional Information
No response