From c7eb678ff3e8d0fd27ec595945ab944679e54177 Mon Sep 17 00:00:00 2001 From: dkundel Date: Thu, 18 Jul 2019 23:44:08 -0700 Subject: [PATCH] fix(types): improve types for Twilio Functions --- packages/serverless-runtime-types/index.d.ts | 13 ++++++++++++- packages/serverless-runtime-types/types.d.ts | 16 ++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/serverless-runtime-types/index.d.ts b/packages/serverless-runtime-types/index.d.ts index c3ce954e..a11b4bc8 100644 --- a/packages/serverless-runtime-types/index.d.ts +++ b/packages/serverless-runtime-types/index.d.ts @@ -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; } } } diff --git a/packages/serverless-runtime-types/types.d.ts b/packages/serverless-runtime-types/types.d.ts index d8ff82f0..de41d8d8 100644 --- a/packages/serverless-runtime-types/types.d.ts +++ b/packages/serverless-runtime-types/types.d.ts @@ -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; @@ -11,6 +12,13 @@ export type ResourceMap = { }; }; +export type AssetResourceMap = { + [name: string]: { + path: string; + open(): string; + }; +}; + export interface TwilioResponse { setStatusCode(code: number): void; setBody(body: string | object): void; @@ -18,10 +26,14 @@ export interface TwilioResponse { 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 = {