Skip to content

Commit b8177f7

Browse files
committed
feat: add initial release
1 parent 01ed72f commit b8177f7

File tree

7 files changed

+125
-35
lines changed

7 files changed

+125
-35
lines changed

Diff for: packages/serverless-runtime-types/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@ typings/
5959

6060
# next.js build output
6161
.next
62+
63+
package-lock.json

Diff for: packages/serverless-runtime-types/.npmrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
message="release: v%s"
2+
package-lock=false

Diff for: packages/serverless-runtime-types/README.md

+52-35
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
<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>
33
<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>
55
<hr>
66

7-
- [⚠️ **IMPORTANT**](#%E2%9A%A0%EF%B8%8F-IMPORTANT)
87
- [Installation](#Installation)
98
- [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)
1714
- [Contributing](#Contributing)
1815
- [Code of Conduct](#Code-of-Conduct)
1916
- [Contributors](#Contributors)
2017
- [License](#License)
18+
- [Contributors ✨](#Contributors-%E2%9C%A8)
2119

2220
## Installation
2321

@@ -27,32 +25,51 @@ npm install @twilio-labs/serverless-runtime-types
2725

2826
## Example
2927

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:
3132

3233
```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+
}
5673
```
5774

5875
## Contributing
@@ -71,7 +88,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
7188
<!-- prettier-ignore -->
7289
<table>
7390
<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>
7592
</tr>
7693
</table>
7794

Diff for: packages/serverless-runtime-types/index.d.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import TwilioLib = require('twilio');
2+
import { RuntimeInstance } from './types';
3+
4+
declare global {
5+
var Twilio: typeof TwilioLib;
6+
var Runtime: RuntimeInstance;
7+
8+
namespace NodeJS {
9+
interface Global {
10+
Twilio: typeof TwilioLib;
11+
Runtime: RuntimeInstance;
12+
}
13+
}
14+
}

Diff for: packages/serverless-runtime-types/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Intentionally left empty

Diff for: packages/serverless-runtime-types/package.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "@twilio-labs/serverless-runtime-types",
3+
"version": "1.0.0",
4+
"description": "TypeScript definitions to define globals for the Twilio Serverless runtime",
5+
"main": "index.js",
6+
"types": "index.d.ts",
7+
"scripts": {
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "git+https://github.com/twilio-labs/twilio-runtime-types.git"
13+
},
14+
"keywords": [
15+
"twilio",
16+
"serverless",
17+
"typescript",
18+
"types"
19+
],
20+
"author": "Dominik Kundel <[email protected]> (https://dkundel.com)",
21+
"license": "MIT",
22+
"bugs": {
23+
"url": "https://github.com/twilio-labs/twilio-runtime-types/issues"
24+
},
25+
"homepage": "https://github.com/twilio-labs/twilio-runtime-types#readme",
26+
"dependencies": {
27+
"twilio": "^3.33.0"
28+
},
29+
"devDependencies": {
30+
"all-contributors-cli": "^6.7.0"
31+
},
32+
"publishConfig": {
33+
"access": "public"
34+
},
35+
"files": [
36+
"README.md",
37+
"index.js",
38+
"index.d.ts",
39+
"types.d.ts"
40+
]
41+
}

Diff for: packages/serverless-runtime-types/types.d.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ServiceContext } from 'twilio/lib/rest/sync/v1/service';
2+
3+
export type ResourceMap = {
4+
[name: string]: {
5+
path: string;
6+
};
7+
};
8+
9+
export type RuntimeInstance = {
10+
getAssets(): ResourceMap;
11+
getFunctions(): ResourceMap;
12+
getSync(config?: { serviceName: string }): ServiceContext;
13+
};

0 commit comments

Comments
 (0)