Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: support create specificated service to make code tree shakable #1044

Open
4 tasks done
Sczlog opened this issue Nov 7, 2024 · 0 comments
Open
4 tasks done
Labels
type: community enhancement feature request not on Twilio's roadmap

Comments

@Sczlog
Copy link

Sczlog commented Nov 7, 2024

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
image
but the type of paramter is confusing like V2010 need an ApiBase as paramter
image
and ApiBase use an any
image
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

@Sczlog Sczlog added the type: community enhancement feature request not on Twilio's roadmap label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: community enhancement feature request not on Twilio's roadmap
Projects
None yet
Development

No branches or pull requests

1 participant