Skip to content

Commit

Permalink
Add TypeScript definitions for v6 packages
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Aug 29, 2017
1 parent 01a9efe commit a01a277
Show file tree
Hide file tree
Showing 34 changed files with 1,244 additions and 124 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ script:
- yarn test:mail
- yarn test:client
- yarn test:helpers
- yarn test:typescript
notifications:
hipchat:
rooms:
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"mocha-clean": "^1.0.0",
"mocha-sinon": "^2.0.0",
"sinon": "^2.3.2",
"sinon-chai": "^2.10.0"
"sinon-chai": "^2.10.0",
"typescript": "~2.4.2"
},
"scripts": {
"lint": "eslint . --fix",
Expand All @@ -30,6 +31,7 @@
"test:helpers": "babel-node ./node_modules/istanbul/lib/cli cover ./node_modules/mocha/bin/_mocha \"packages/helpers/**/*.spec.js\"",
"test:client": "babel-node ./node_modules/istanbul/lib/cli cover ./node_modules/mocha/bin/_mocha \"packages/client/**/*.spec.js\"",
"test:mail": "babel-node ./node_modules/istanbul/lib/cli cover ./node_modules/mocha/bin/_mocha \"packages/mail/**/*.spec.js\"",
"test:typescript": "tsc",
"test": "npm run test:all -s",
"coverage": "open -a \"Google Chrome\" ./coverage/lcov-report/index.html"
}
Expand Down
3 changes: 3 additions & 0 deletions packages/client/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Client = require("@sendgrid/client/src/client");

export = Client;
3 changes: 2 additions & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
},
"dependencies": {
"@sendgrid/helpers": "^6.0.0",
"request": "^2.81.0"
"request": "^2.81.0",
"@types/request": "^2.0.3"
},
"tags": [
"http",
Expand Down
38 changes: 38 additions & 0 deletions packages/client/src/client.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {ResponseError} from "@sendgrid/helpers/classes";
import {OptionsWithUrl} from "request";

declare type ClientRequest = OptionsWithUrl;

declare class Client {
/**
* Set API key
*/
setApiKey(apiKey: string): void;

/**
* Set default header
*/
setDefaultHeader(key: string, value: string): this;

/**
* Set default request
*/
setDefaultRequest<K extends keyof ClientRequest>(key: K, value: ClientRequest[K]): this;

/**
* Create headers for request
*/
createHeaders(data: { [key: string]: string }): { [key: string]: string };

/**
* Create request
*/
createRequest(data: ClientRequest): ClientRequest;

/**
* Do a request
*/
request(data: ClientRequest, cb?: (err: ResponseError, response: any[]) => void): Promise<any[]>;
}

export = new Client()
68 changes: 64 additions & 4 deletions packages/client/yarn.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@sendgrid/helpers@^6.0.0":
version "6.0.0"
resolved "https://registry.yarnpkg.com/@sendgrid/helpers/-/helpers-6.0.0.tgz#b7ae9b927822e6a3a3e44abb2486e68d03e25220"
dependencies:
chalk "^2.0.1"

"@types/form-data@*":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@types/form-data/-/form-data-2.2.0.tgz#a98aac91dc99857b6af24caef7ca6df302f31565"
dependencies:
"@types/node" "*"

"@types/node@*":
version "8.0.25"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.25.tgz#66ecaf4df93f5281b48427ee96fbcdfc4f0cdce1"

"@types/request@^2.0.3":
version "2.0.3"
resolved "https://registry.yarnpkg.com/@types/request/-/request-2.0.3.tgz#bdf0fba9488c822f77e97de3dd8fe357b2fb8c06"
dependencies:
"@types/form-data" "*"
"@types/node" "*"

ajv@^4.9.1:
version "4.11.8"
Expand All @@ -9,18 +30,24 @@ ajv@^4.9.1:
co "^4.6.0"
json-stable-stringify "^1.0.1"

ansi-styles@^3.1.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.0.tgz#c159b8d5be0f9e5a6f346dab94f16ce022161b88"
dependencies:
color-convert "^1.9.0"

asn1@~0.2.3:
version "0.2.3"
resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.3.tgz#dac8787713c9966849fc8180777ebe9c1ddf3b86"

assert-plus@1.0.0, assert-plus@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525"

assert-plus@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-0.2.0.tgz#d74e1b87e7affc0db8aadb7021f3fe48101ab234"

assert-plus@^1.0.0, assert-plus@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525"

asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
Expand Down Expand Up @@ -49,10 +76,28 @@ caseless@~0.12.0:
version "0.12.0"
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"

chalk@^2.0.1:
version "2.1.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.1.0.tgz#ac5becf14fa21b99c6c92ca7a7d7cfd5b17e743e"
dependencies:
ansi-styles "^3.1.0"
escape-string-regexp "^1.0.5"
supports-color "^4.0.0"

co@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184"

color-convert@^1.9.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.0.tgz#1accf97dd739b983bf994d56fec8f95853641b7a"
dependencies:
color-name "^1.1.1"

color-name@^1.1.1:
version "1.1.3"
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"

combined-stream@^1.0.5, combined-stream@~1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.5.tgz#938370a57b4a51dea2c77c15d5c5fdf895164009"
Expand Down Expand Up @@ -81,6 +126,10 @@ ecc-jsbn@~0.1.1:
dependencies:
jsbn "~0.1.0"

escape-string-regexp@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"

extend@~3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.1.tgz#a755ea7bc1adfcc5a31ce7e762dbaadc5e636444"
Expand Down Expand Up @@ -118,6 +167,10 @@ har-validator@~4.2.1:
ajv "^4.9.1"
har-schema "^1.0.5"

has-flag@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-2.0.0.tgz#e8207af1cc7b30d446cc70b734b5e8be18f88d51"

hawk@~3.1.3:
version "3.1.3"
resolved "https://registry.yarnpkg.com/hawk/-/hawk-3.1.3.tgz#078444bd7c1640b0fe540d2c9b73d59678e8e1c4"
Expand Down Expand Up @@ -259,6 +312,12 @@ stringstream@~0.0.4:
version "0.0.5"
resolved "https://registry.yarnpkg.com/stringstream/-/stringstream-0.0.5.tgz#4e484cd4de5a0bbbee18e46307710a8a81621878"

supports-color@^4.0.0:
version "4.2.1"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-4.2.1.tgz#65a4bb2631e90e02420dba5554c375a4754bb836"
dependencies:
has-flag "^2.0.0"

tough-cookie@~2.3.0:
version "2.3.2"
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.2.tgz#f081f76e4c85720e6c37a5faced737150d84072a"
Expand All @@ -284,3 +343,4 @@ verror@1.3.6:
resolved "https://registry.yarnpkg.com/verror/-/verror-1.3.6.tgz#cff5df12946d297d2baaefaa2689e25be01c005c"
dependencies:
extsprintf "1.0.2"

3 changes: 3 additions & 0 deletions packages/contact-importer/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Importer = require("@sendgrid/contact-importer/src/importer");

export = Importer;
30 changes: 30 additions & 0 deletions packages/contact-importer/src/importer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
declare interface ContactImporterOptions {
batchSize?: number;
rateLimitLimit?: number;
rateLimitPeriod?: number;
}

declare interface Contact {
email: string;
first_name?: string;
last_name?: string;
age?: number;
}

declare class ContactImporter {
constructor(sg, options?: ContactImporterOptions);

push(data: Contact|Contact[])

on(event: "success", cb: (result: any, batch: Contact[]) => void): void;
on(event: "error", cb: (err: Error, batch?: Contact[]) => void): void;
on(event: "drain", cb: () => void): void;
on(event: string, cb: (data: any) => void): void;

once(event: "success", cb: (result: any, batch: Contact[]) => void): void;
once(event: "error", cb: (err: Error, batch?: Contact[]) => void): void;
once(event: "drain", cb: () => void): void;
once(event: string, cb: (data: any) => void): void;
}

export = ContactImporter;
27 changes: 27 additions & 0 deletions packages/helpers/classes/attachment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export interface AttachmentData {
content: string;
filename: string;
type?: string;
disposition?: string;
contentId?: string;
}

export interface AttachmentJSON {
content: string;
filename: string;
type?: string;
disposition?: string;
content_id?: string;
}

export default class Attachment {
constructor(data?: AttachmentData);

fromData(data: AttachmentData): void;
setContent(content: string): void;
setFilename(filename: string): void;
setType(type: string): void;
setDisposition(disposition: string): void;
setContentId(contentId: string): void;
toJSON(): AttachmentJSON;
}
24 changes: 24 additions & 0 deletions packages/helpers/classes/email-address.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export type EmailData = string|{ name?: string; email: string; }

export type EmailJSON = { name?: string; email: string }

export default class EmailAddress {
constructor(data?: EmailData);

/**
* From data
*/
fromData(data: EmailData);

/**
* Set name
*/
setName(name: string);

/**
* Set email (mandatory)
*/
setEmail(email: string);

toJSON(): EmailJSON;
}
13 changes: 13 additions & 0 deletions packages/helpers/classes/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Attachment from "@sendgrid/helpers/classes/attachment";
import EmailAddress from "@sendgrid/helpers/classes/email-address";
import Mail from "@sendgrid/helpers/classes/mail"
import Personalization from "@sendgrid/helpers/classes/personalization";
import ResponseError from "@sendgrid/helpers/classes/response-error";

export {
Attachment,
EmailAddress,
Mail,
Personalization,
ResponseError,
}
Loading

0 comments on commit a01a277

Please sign in to comment.