Skip to content

Commit 830c060

Browse files
chore: run prettier
1 parent 4806972 commit 830c060

File tree

4 files changed

+114
-89
lines changed

4 files changed

+114
-89
lines changed

examples/aws-lambda-example.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* This demonstrates significant bundle size reduction for serverless deployments
44
*/
55

6-
const { ModularClient } = require('twilio');
6+
const { ModularClient } = require("twilio");
77

88
// Initialize client with only the services needed for this function
99
// This reduces bundle size from ~13MB to ~2-3MB (85% reduction)
@@ -12,7 +12,7 @@ const twilioClient = new ModularClient(
1212
process.env.TWILIO_AUTH_TOKEN,
1313
{
1414
// Only load messaging service - significant bundle size reduction
15-
services: ['messaging']
15+
services: ["messaging"],
1616
}
1717
);
1818

@@ -23,13 +23,13 @@ const twilioClient = new ModularClient(
2323
exports.sendSMS = async (event) => {
2424
try {
2525
const { to, message } = JSON.parse(event.body);
26-
26+
2727
if (!to || !message) {
2828
return {
2929
statusCode: 400,
3030
body: JSON.stringify({
31-
error: 'Missing required fields: to, message'
32-
})
31+
error: "Missing required fields: to, message",
32+
}),
3333
};
3434
}
3535

@@ -38,27 +38,26 @@ exports.sendSMS = async (event) => {
3838
const messageResponse = await twilioClient.messaging.messages.create({
3939
to: to,
4040
from: process.env.TWILIO_PHONE_NUMBER,
41-
body: message
41+
body: message,
4242
});
4343

4444
return {
4545
statusCode: 200,
4646
body: JSON.stringify({
4747
success: true,
4848
messageSid: messageResponse.sid,
49-
status: messageResponse.status
50-
})
49+
status: messageResponse.status,
50+
}),
5151
};
52-
5352
} catch (error) {
54-
console.error('Error sending SMS:', error);
55-
53+
console.error("Error sending SMS:", error);
54+
5655
return {
5756
statusCode: 500,
5857
body: JSON.stringify({
59-
error: 'Failed to send SMS',
60-
details: error.message
61-
})
58+
error: "Failed to send SMS",
59+
details: error.message,
60+
}),
6261
};
6362
}
6463
};
@@ -86,19 +85,19 @@ exports.sendSMSMinimal = async (event) => {
8685

8786
/**
8887
* Deployment considerations:
89-
*
88+
*
9089
* 1. Bundle Size Comparison:
9190
* - Traditional: ~13MB (includes all Twilio services)
9291
* - Modular: ~2-3MB (85% reduction)
9392
* - Individual imports: ~1-2MB (90% reduction)
94-
*
93+
*
9594
* 2. Cold Start Performance:
9695
* - Smaller bundles = faster cold starts
9796
* - Less memory usage
9897
* - Faster deployment times
99-
*
98+
*
10099
* 3. Cost Savings:
101100
* - Reduced Lambda execution time
102101
* - Lower memory requirements
103102
* - Faster deployments
104-
*/
103+
*/

examples/bundle-size-demo.js

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,71 +3,75 @@
33
* Run this with: node examples/bundle-size-demo.js
44
*/
55

6-
console.log('=== Twilio Bundle Size Reduction Demo ===\n');
6+
console.log("=== Twilio Bundle Size Reduction Demo ===\n");
77

88
// Traditional way - loads ALL services
9-
console.log('1. Traditional full client (loads all 30+ services):');
10-
console.time('Full client load time');
11-
const Twilio = require('../lib/index');
9+
console.log("1. Traditional full client (loads all 30+ services):");
10+
console.time("Full client load time");
11+
const Twilio = require("../lib/index");
1212
const fullClient = new Twilio.Twilio(
13-
process.env.TWILIO_ACCOUNT_SID || 'ACtest',
14-
process.env.TWILIO_AUTH_TOKEN || 'test_token'
13+
process.env.TWILIO_ACCOUNT_SID || "ACtest",
14+
process.env.TWILIO_AUTH_TOKEN || "test_token"
1515
);
16-
console.timeEnd('Full client load time');
17-
console.log(' Memory usage: High (all services loaded)\n');
16+
console.timeEnd("Full client load time");
17+
console.log(" Memory usage: High (all services loaded)\n");
1818

1919
// Modular way - loads only what you need
20-
console.log('2. Modular client (loads only messaging service):');
21-
console.time('Modular client load time');
22-
const ModularClient = require('../lib/modular/index').ModularTwilioClient;
20+
console.log("2. Modular client (loads only messaging service):");
21+
console.time("Modular client load time");
22+
const ModularClient = require("../lib/modular/index").ModularTwilioClient;
2323
const modularClient = new ModularClient(
24-
process.env.TWILIO_ACCOUNT_SID || 'ACtest',
25-
process.env.TWILIO_AUTH_TOKEN || 'test_token',
26-
{ services: ['messaging'] }
24+
process.env.TWILIO_ACCOUNT_SID || "ACtest",
25+
process.env.TWILIO_AUTH_TOKEN || "test_token",
26+
{ services: ["messaging"] }
2727
);
28-
console.timeEnd('Modular client load time');
29-
console.log(' Services requested:', modularClient.getRequestedServices());
30-
console.log(' Services loaded:', modularClient.getLoadedServices());
31-
console.log(' Memory usage: Low (only messaging service ready)\n');
28+
console.timeEnd("Modular client load time");
29+
console.log(" Services requested:", modularClient.getRequestedServices());
30+
console.log(" Services loaded:", modularClient.getLoadedServices());
31+
console.log(" Memory usage: Low (only messaging service ready)\n");
3232

3333
// Individual service imports - most efficient
34-
console.log('3. Individual service imports (most efficient):');
35-
console.time('Individual service load time');
36-
const { Messaging } = require('../lib/services/index');
37-
const { Client } = require('../lib/base/BaseTwilio');
34+
console.log("3. Individual service imports (most efficient):");
35+
console.time("Individual service load time");
36+
const { Messaging } = require("../lib/services/index");
37+
const { Client } = require("../lib/base/BaseTwilio");
3838
const baseClient = new Client(
39-
process.env.TWILIO_ACCOUNT_SID || 'ACtest',
40-
process.env.TWILIO_AUTH_TOKEN || 'test_token'
39+
process.env.TWILIO_ACCOUNT_SID || "ACtest",
40+
process.env.TWILIO_AUTH_TOKEN || "test_token"
4141
);
4242
const messagingService = new Messaging(baseClient);
43-
console.timeEnd('Individual service load time');
44-
console.log(' Memory usage: Minimal (only messaging service)\n');
43+
console.timeEnd("Individual service load time");
44+
console.log(" Memory usage: Minimal (only messaging service)\n");
4545

46-
console.log('=== Bundle Analysis ===');
47-
console.log('Traditional approach: ~13MB bundle');
48-
console.log('Modular client: ~2-3MB bundle (85% reduction)');
49-
console.log('Individual imports: ~1-2MB bundle (90% reduction)');
50-
console.log('\nFor AWS Lambda or other size-sensitive environments,');
51-
console.log('use the modular client or individual imports for best performance.');
46+
console.log("=== Bundle Analysis ===");
47+
console.log("Traditional approach: ~13MB bundle");
48+
console.log("Modular client: ~2-3MB bundle (85% reduction)");
49+
console.log("Individual imports: ~1-2MB bundle (90% reduction)");
50+
console.log("\nFor AWS Lambda or other size-sensitive environments,");
51+
console.log(
52+
"use the modular client or individual imports for best performance."
53+
);
5254

5355
// Demonstrate functionality still works
54-
console.log('\n=== Functionality Test ===');
56+
console.log("\n=== Functionality Test ===");
5557
try {
5658
// Access messaging through modular client
5759
const messaging = modularClient.messaging;
58-
console.log('✓ Modular client messaging access works');
59-
console.log(' Loaded services after access:', modularClient.getLoadedServices());
60-
60+
console.log("✓ Modular client messaging access works");
61+
console.log(
62+
" Loaded services after access:",
63+
modularClient.getLoadedServices()
64+
);
65+
6166
// Try to access disabled service
6267
try {
6368
modularClient.voice;
64-
console.log('✗ Should have thrown error for disabled service');
69+
console.log("✗ Should have thrown error for disabled service");
6570
} catch (e) {
66-
console.log('✓ Correctly blocked access to disabled voice service');
71+
console.log("✓ Correctly blocked access to disabled voice service");
6772
}
68-
6973
} catch (error) {
70-
console.log('Error in functionality test:', error.message);
74+
console.log("Error in functionality test:", error.message);
7175
}
7276

73-
console.log('\n=== Demo Complete ===');
77+
console.log("\n=== Demo Complete ===");

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ namespace TwilioSDK {
2929
// Main functional components of the Twilio module
3030
export type Twilio = ITwilio;
3131
export const Twilio = ITwilio;
32-
32+
3333
// Modular client for reduced bundle size
3434
export type ModularClient = ModularTwilioClient;
3535
export const ModularClient = ModularTwilioClient;
3636
export type ModularClientOpts = ModularClientOptions;
37-
37+
3838
export namespace jwt {
3939
export type AccessToken = IAccessToken;
4040
export const AccessToken = IAccessToken;

0 commit comments

Comments
 (0)