Skip to content

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

@Sczlog

Description

@Sczlog

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions