Skip to content

Commit c7eb678

Browse files
committed
fix(types): improve types for Twilio Functions
1 parent 69b50b7 commit c7eb678

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed
+12-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
import { RuntimeInstance, TwilioResponse, GlobalTwilio } from './types';
1+
import * as twilio from 'twilio';
2+
import {
3+
GlobalTwilio,
4+
ResourceMap,
5+
ResponseConstructor,
6+
RuntimeInstance,
7+
} from './types';
28

39
declare global {
410
var Twilio: GlobalTwilio;
511
var Runtime: RuntimeInstance;
12+
var Functions: ResourceMap;
13+
var twilioClient: null | twilio.Twilio;
614

715
namespace NodeJS {
816
interface Global {
917
Twilio: GlobalTwilio;
1018
Runtime: RuntimeInstance;
19+
Functions: ResourceMap;
20+
Response: ResponseConstructor;
21+
twilioClient: null | twilio.Twilio;
1122
}
1223
}
1324
}

packages/serverless-runtime-types/types.d.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as twilio from 'twilio';
22
import { ServiceContext } from 'twilio/lib/rest/sync/v1/service';
3+
import { TwilioClientOptions } from 'twilio/lib/rest/Twilio';
34

45
export type EnvironmentVariables = {
56
[key: string]: string | undefined;
@@ -11,17 +12,28 @@ export type ResourceMap = {
1112
};
1213
};
1314

15+
export type AssetResourceMap = {
16+
[name: string]: {
17+
path: string;
18+
open(): string;
19+
};
20+
};
21+
1422
export interface TwilioResponse {
1523
setStatusCode(code: number): void;
1624
setBody(body: string | object): void;
1725
appendHeader(key: string, value: string): void;
1826
setHeaders(headers: { [key: string]: string }): void;
1927
}
2028

29+
export type RuntimeSyncClientOptions = TwilioClientOptions & {
30+
serviceName?: string;
31+
};
32+
2133
export type RuntimeInstance = {
22-
getAssets(): ResourceMap;
34+
getAssets(): AssetResourceMap;
2335
getFunctions(): ResourceMap;
24-
getSync(config?: { serviceName: string }): ServiceContext;
36+
getSync(options?: RuntimeSyncClientOptions): ServiceContext;
2537
};
2638

2739
export type Context<T = {}> = {

0 commit comments

Comments
 (0)