Skip to content

Commit

Permalink
fix(types): improve types for Twilio Functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dkundel committed Jul 19, 2019
1 parent 69b50b7 commit c7eb678
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
13 changes: 12 additions & 1 deletion packages/serverless-runtime-types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import { RuntimeInstance, TwilioResponse, GlobalTwilio } from './types';
import * as twilio from 'twilio';
import {
GlobalTwilio,
ResourceMap,
ResponseConstructor,
RuntimeInstance,
} from './types';

declare global {
var Twilio: GlobalTwilio;
var Runtime: RuntimeInstance;
var Functions: ResourceMap;
var twilioClient: null | twilio.Twilio;

namespace NodeJS {
interface Global {
Twilio: GlobalTwilio;
Runtime: RuntimeInstance;
Functions: ResourceMap;
Response: ResponseConstructor;
twilioClient: null | twilio.Twilio;
}
}
}
16 changes: 14 additions & 2 deletions packages/serverless-runtime-types/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as twilio from 'twilio';
import { ServiceContext } from 'twilio/lib/rest/sync/v1/service';
import { TwilioClientOptions } from 'twilio/lib/rest/Twilio';

export type EnvironmentVariables = {
[key: string]: string | undefined;
Expand All @@ -11,17 +12,28 @@ export type ResourceMap = {
};
};

export type AssetResourceMap = {
[name: string]: {
path: string;
open(): string;
};
};

export interface TwilioResponse {
setStatusCode(code: number): void;
setBody(body: string | object): void;
appendHeader(key: string, value: string): void;
setHeaders(headers: { [key: string]: string }): void;
}

export type RuntimeSyncClientOptions = TwilioClientOptions & {
serviceName?: string;
};

export type RuntimeInstance = {
getAssets(): ResourceMap;
getAssets(): AssetResourceMap;
getFunctions(): ResourceMap;
getSync(config?: { serviceName: string }): ServiceContext;
getSync(options?: RuntimeSyncClientOptions): ServiceContext;
};

export type Context<T = {}> = {
Expand Down

0 comments on commit c7eb678

Please sign in to comment.