Skip to content

Commit 9953dfe

Browse files
author
SomaticIT
committed
Add ghost module and fix module export issue
1 parent c4a339b commit 9953dfe

File tree

1 file changed

+150
-104
lines changed

1 file changed

+150
-104
lines changed

sendgrid/sendgrid.d.ts

+150-104
Original file line numberDiff line numberDiff line change
@@ -3,121 +3,167 @@
33
// Definitions by: Maxime LUCE <https://github.com/SomaticIT>
44
// Definitions: https://github.com/borisyankov/DefinitelyTyped
55

6-
interface SendgridUriParts {
7-
protocol: string;
8-
host: string;
9-
port: string;
10-
endpoint: string;
11-
}
6+
declare module Sendgrid {
7+
//#region Options
8+
9+
export interface UriParts {
10+
protocol: string;
11+
host: string;
12+
port: string;
13+
endpoint: string;
14+
}
1215

13-
interface SendgridOptions {
14-
protocol?: string;
15-
host?: string;
16-
port?: string;
17-
endpoint?: string;
18-
uri?: string;
19-
}
16+
export interface Options {
17+
protocol?: string;
18+
host?: string;
19+
port?: string;
20+
endpoint?: string;
21+
uri?: string;
22+
proxy?: string;
23+
web?: {
24+
pool?: any;
25+
}
26+
}
2027

21-
interface SendgridOptionsExport {
22-
uriParts: SendgridUriParts;
23-
uri: string;
24-
}
28+
export interface OptionsExport {
29+
uriParts: UriParts;
30+
uri: string;
2531

26-
interface SendgridEmailOptions {
27-
to?: any;
28-
toname?: string;
29-
from?: string;
30-
fromname?: string;
31-
subject?: string;
32-
text?: string;
33-
html?: string;
34-
bcc?: any;
35-
replyto?: string;
36-
date?: Date;
37-
headers?: { [key: string]: string };
38-
files?: SendgridEmailFileOptions[];
39-
smtpapi?: any;
40-
}
32+
proxy?: string;
33+
web?: {
34+
pool?: any;
35+
}
36+
}
4137

42-
declare class PrivateSendgridEmail {
43-
to: any;
44-
toname: string;
45-
from: string;
46-
fromname: string;
47-
subject: string;
48-
text: string;
49-
html: string;
50-
bcc: any;
51-
replyto: string;
52-
date: Date;
53-
headers: { [key: string]: string };
54-
files: PrivateSendgridFile[];
55-
smtpapi: any;
56-
57-
constructor();
58-
constructor(options: SendgridEmailOptions);
59-
60-
addTo(address: string): void;
61-
addHeader(type: string, value: string): void;
62-
addSubstitution(type: string, value: string): void;
63-
addSubstitution(type: string, value: string[]): void;
64-
addSection(section: { [key: string]: string }): void;
65-
addUniqueArg(uarg: { [key: string]: string }): void;
66-
addCategory(category: string): void;
67-
addFilter(filter: string, command: string, value: number): void;
68-
addFilter(filter: string, command: string, value: string): void;
69-
addFile(file: SendgridEmailFileOptions): void;
70-
71-
setFrom(address: string): void;
72-
setSubject(subject: string): void;
73-
setText(text: string): void;
74-
setHtml(html: string): void;
75-
setHeaders(headers: { [key: string]: string }): void;
76-
setSubstitutions(substitutions: { [key: string]: string[] }): void;
77-
setSections(sections: { [key: string]: string }): void;
78-
setUniqueArgs(uargs: { [key: string]: string }): void;
79-
setCategories(categories: string[]): void;
80-
setFilters(filters: any): void;
81-
}
38+
//#endregion
39+
40+
//#region Email
41+
42+
export interface EmailOptions {
43+
to?: any;
44+
toname?: string;
45+
from?: string;
46+
fromname?: string;
47+
subject?: string;
48+
text?: string;
49+
html?: string;
50+
bcc?: any;
51+
replyto?: string;
52+
date?: Date;
53+
headers?: { [key: string]: string };
54+
files?: SendgridEmailFileOptions[];
55+
smtpapi?: any;
56+
}
8257

83-
interface SendgridEmailFileOptions {
84-
filename?: string;
85-
contentType?: string;
86-
cid?: string;
87-
path?: string;
88-
url?: string;
89-
content?: any;
90-
}
58+
export class Email {
59+
to: any;
60+
toname: string;
61+
from: string;
62+
fromname: string;
63+
subject: string;
64+
text: string;
65+
html: string;
66+
bcc: any;
67+
replyto: string;
68+
date: Date;
69+
headers: { [key: string]: string };
70+
files: FileHandler[];
71+
smtpapi: any;
72+
73+
constructor();
74+
constructor(options: EmailOptions);
75+
76+
addTo(address: string): void;
77+
addHeader(type: string, value: string): void;
78+
addSubstitution(type: string, value: string): void;
79+
addSubstitution(type: string, value: string[]): void;
80+
addSection(section: { [key: string]: string }): void;
81+
addUniqueArg(uarg: { [key: string]: string }): void;
82+
addCategory(category: string): void;
83+
addFilter(filter: string, command: string, value: number): void;
84+
addFilter(filter: string, command: string, value: string): void;
85+
addFile(file: FileHandlerOptions): void;
86+
87+
setFrom(address: string): void;
88+
setSubject(subject: string): void;
89+
setText(text: string): void;
90+
setHtml(html: string): void;
91+
setHeaders(headers: { [key: string]: string }): void;
92+
setSubstitutions(substitutions: { [key: string]: string[] }): void;
93+
setSections(sections: { [key: string]: string }): void;
94+
setUniqueArgs(uargs: { [key: string]: string }): void;
95+
setCategories(categories: string[]): void;
96+
setFilters(filters: any): void;
97+
}
9198

92-
declare class PrivateSendgridFile {
93-
filename: string;
94-
contentType: string;
95-
cid: string;
99+
//#endregion
96100

97-
type: string;
98-
content: string;
99-
path: string;
100-
url: string;
101+
//#region FileHandler
101102

102-
loadContent(callback: (hasError: boolean, error: Error) => any): void;
103-
}
103+
export interface FileHandlerOptions {
104+
filename?: string;
105+
contentType?: string;
106+
cid?: string;
107+
path?: string;
108+
url?: string;
109+
content?: any;
110+
}
104111

105-
interface Sendgrid {
106-
version: string;
107-
api_user: string;
108-
api_key: string;
109-
options: SendgridOptionsExport;
110-
Email: typeof PrivateSendgridEmail;
112+
export class FileHandler {
113+
filename: string;
114+
contentType: string;
115+
cid: string;
111116

112-
send(email: SendgridEmailOptions, callback: (err: Error, json: any) => any): void;
113-
send(email: PrivateSendgridEmail, callback: (err: Error, json: any) => any): void;
114-
}
117+
type: string;
118+
content: string;
119+
path: string;
120+
url: string;
115121

116-
declare module "sendgrid" {
117-
interface SendgridConstructor {
118-
(api_user: string, api_key: string, options?: SendgridOptions): Sendgrid;
119-
new (api_user: string, api_key: string, options?: SendgridOptions): Sendgrid;
122+
constructor(options: FileHandlerOptions);
123+
124+
loadContent(callback: HandlerCallback): void;
125+
126+
static handlers: {
127+
content: Handler;
128+
path: Handler;
129+
url: Handler;
130+
none: Handler;
131+
};
132+
}
133+
134+
export interface Handler {
135+
(file: FileHandler, callback: HandlerCallback): void;
136+
}
137+
138+
export interface HandlerCallback {
139+
(hasError: boolean, error: Error): void;
140+
(hasError: boolean, error: string): void;
120141
}
121142

122-
export = SendgridConstructor;
143+
//#endregion
144+
145+
//#region Sendgrid Class
146+
147+
interface Constructor {
148+
(api_user: string, api_key: string, options?: Options): Instance;
149+
new (api_user: string, api_key: string, options?: Options): Instance;
150+
}
151+
152+
export interface Instance {
153+
version: string;
154+
api_user: string;
155+
api_key: string;
156+
options: OptionsExport;
157+
Email: typeof Email;
158+
159+
send(email: EmailOptions, callback: (err: Error, json: any) => any): void;
160+
send(email: Email, callback: (err: Error, json: any) => any): void;
161+
}
162+
163+
//#endregion
164+
}
165+
166+
declare module "sendgrid" {
167+
var ctor: Sendgrid.Constructor;
168+
export = ctor;
123169
}

0 commit comments

Comments
 (0)