1
1
<h1 align =" center " >@twilio-labs/serverless-runtime-types</h1 >
2
- <p align =" center " >A module to interact with the < a href = " https://www.twilio.com/functions " > Twilio Serverless</ a > API. For example to deploy projects. < br >Full reference documentation at < a href = " https://serverless-api.twilio-labs.com " >serverless-api.twilio-labs.com</ a > </p >
2
+ <p align =" center " >TypeScript definitions to define globals for the Twilio Serverless runtime </p >
3
3
<p align =" center " >
4
- <img alt =" npm (scoped) " src =" https://img.shields.io/npm/v/@twilio-labs/serverless-api .svg?style=flat-square " > <img alt =" npm " src =" https://img.shields.io/npm/dt/@twilio-labs/serverless-api .svg?style=flat-square " > <img alt =" GitHub " src =" https://img.shields.io/github/license/twilio-labs/serverless-api .svg?style=flat-square " > <a href =" #contributors " ><img alt =" All Contributors " src =" https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square " /></a > <a href =" https://github.com/twilio-labs/.github/blob/master/CODE_OF_CONDUCT.md " ><img alt =" Code of Conduct " src =" https://img.shields.io/badge/%F0%9F%92%96-Code%20of%20Conduct-blueviolet.svg?style=flat-square " ></a > <a href =" http://makeapullrequest.com " ><img src =" https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square " alt =" PRs Welcome " /></a > </<a >
4
+ <img alt =" npm (scoped) " src =" https://img.shields.io/npm/v/@twilio-labs/serverless-runtime-types .svg?style=flat-square " > <img alt =" npm " src =" https://img.shields.io/npm/dt/@twilio-labs/serverless-runtime-types .svg?style=flat-square " > <img alt =" GitHub " src =" https://img.shields.io/github/license/twilio-labs/serverless-runtime-types .svg?style=flat-square " > <a href =" #contributors " ><img alt =" All Contributors " src =" https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square " /></a > <a href =" https://github.com/twilio-labs/.github/blob/master/CODE_OF_CONDUCT.md " ><img alt =" Code of Conduct " src =" https://img.shields.io/badge/%F0%9F%92%96-Code%20of%20Conduct-blueviolet.svg?style=flat-square " ></a > <a href =" http://makeapullrequest.com " ><img src =" https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square " alt =" PRs Welcome " /></a > </<a >
5
5
<hr >
6
6
7
- - [ ⚠️ ** IMPORTANT** ] ( #%E2%9A%A0%EF%B8%8F-IMPORTANT )
8
7
- [ Installation] ( #Installation )
9
8
- [ Example] ( #Example )
10
- - [ API] ( #API )
11
- - [ ` client.activateBuild(activateConfig: ActivateConfig): Promise<ActivateResult> ` ] ( #clientactivateBuildactivateConfig-ActivateConfig-PromiseActivateResult )
12
- - [ ` client.deployLocalProject(deployConfig: DeployLocalProjectConfig): Promise<DeployResult> ` ] ( #clientdeployLocalProjectdeployConfig-DeployLocalProjectConfig-PromiseDeployResult )
13
- - [ ` client.deployProject(deployConfig: DeployProjectConfig): Promise<DeployResult> ` ] ( #clientdeployProjectdeployConfig-DeployProjectConfig-PromiseDeployResult )
14
- - [ ` client.getClient(): GotClient ` ] ( #clientgetClient-GotClient )
15
- - [ ` client.list(listConfig: ListConfig): Promise<ListResult> ` ] ( #clientlistlistConfig-ListConfig-PromiseListResult )
16
- - [ ` api ` and ` fsHelpers ` ] ( #api-and-fsHelpers )
9
+ - [ In JavaScript] ( #In-JavaScript )
10
+ - [ In TypeScript] ( #In-TypeScript )
11
+ - [ Option 1: Modify your ` tsconfig.json ` ] ( #Option-1-Modify-your-tsconfigjson )
12
+ - [ Option 2: Import the file] ( #Option-2-Import-the-file )
13
+ - [ Alternative Usage] ( #Alternative-Usage )
17
14
- [ Contributing] ( #Contributing )
18
15
- [ Code of Conduct] ( #Code-of-Conduct )
19
16
- [ Contributors] ( #Contributors )
20
17
- [ License] ( #License )
18
+ - [ Contributors ✨] ( #Contributors-%E2%9C%A8 )
21
19
22
20
## Installation
23
21
@@ -27,32 +25,51 @@ npm install @twilio-labs/serverless-runtime-types
27
25
28
26
## Example
29
27
30
- If you want to deploy a local project you can do this using:
28
+ ### In JavaScript
29
+
30
+ If you want to use the types in JavaScript to get autocomplete in VS Code and
31
+ other editors using the TypeScript language server:
31
32
32
33
``` js
33
- const TwilioServerlessApiClient = require (' @twilio-labs/serverless-api' );
34
-
35
- const client = new TwilioServerlessApiClient ({
36
- accountSid: ' ...' ,
37
- authToken: ' ...'
38
- });
39
-
40
- client .on (' status-update' , evt => {
41
- console .log (evt .message );
42
- });
43
-
44
- const result = await client .deployLocalProject ({
45
- cwd: ' ...' ,
46
- envPath: ' ...' ,
47
- accountSid: ' ...' ,
48
- authToken: ' ...' ,
49
- env: { },
50
- pkgJson: {},
51
- projectName: ' serverless-example' ,
52
- functionsEnv: ' dev' ,
53
- assetsFolderName: ' static' ,
54
- functionsFolderName: ' src'
55
- });
34
+ // / <reference path="../../node_modules/twilio-runtime-types/index.d.ts"/>
35
+
36
+ exports .handler = function (context , event , callback ) {
37
+ let twiml = new Twilio.twiml.MessagingResponse ();
38
+ twiml .message (' Hello World' );
39
+ callback (null , twiml);
40
+ };
41
+ ```
42
+
43
+ ### In TypeScript
44
+
45
+ For TypeScript you can use the same technique if you want to limit the global
46
+ types to that file. Alternatively, you can use one of the following two options
47
+ to use the definitions.
48
+
49
+ #### Option 1: Modify your ` tsconfig.json `
50
+
51
+ #### Option 2: Import the file
52
+
53
+ ``` ts
54
+ import ' @twilio-labs/serverless-runtime-types' ;
55
+
56
+ export function handler(context , event , callback ) {
57
+ let twiml = new Twilio .twiml .MessagingResponse ();
58
+ twiml .message (' Hello World' );
59
+ callback (null , twiml );
60
+ }
61
+ ```
62
+
63
+ ## Alternative Usage
64
+
65
+ You can also import the specific types without setting the global types:
66
+
67
+ ``` ts
68
+ import { RuntimeInstance } from ' @twilio-labs/serverless-runtime-types/types' ;
69
+
70
+ function listSyncDocuments(runtime : RuntimeInstance ) {
71
+ return runtime .getSync ().documents .list ()
72
+ }
56
73
```
57
74
58
75
## Contributing
@@ -71,7 +88,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
71
88
<!-- prettier-ignore -->
72
89
<table >
73
90
<tr >
74
- <td align="center"><a href="https://dkundel.com"><img src="https://avatars3.githubusercontent.com/u/1505101?v=4" width="100px;" alt="Dominik Kundel"/><br /><sub><b>Dominik Kundel</b></sub></a><br /><a href="https://github.com/twilio-labs/serverless-runtime-types /commits?author=dkundel" title="Code">💻</a> <a href="https://github.com/twilio-labs/serverless-runtime-types /commits?author=dkundel" title="Documentation">📖</a></td>
91
+ <td align="center"><a href="https://dkundel.com"><img src="https://avatars3.githubusercontent.com/u/1505101?v=4" width="100px;" alt="Dominik Kundel"/><br /><sub><b>Dominik Kundel</b></sub></a><br /><a href="https://github.com/twilio-labs/plugin-serverless /commits?author=dkundel" title="Code">💻</a> <a href="https://github.com/twilio-labs/plugin-serverless /commits?author=dkundel" title="Documentation">📖</a></td>
75
92
</tr >
76
93
</table >
77
94
0 commit comments