diff --git a/sparkpost/index.d.ts b/sparkpost/index.d.ts index c88fab5d92..de26de735a 100644 --- a/sparkpost/index.d.ts +++ b/sparkpost/index.d.ts @@ -16,25 +16,48 @@ declare class SparkPost { * List all your inbound domains. * @param callback The request callback with Domain results array */ - all(callback: SparkPost.ResultsCallback): void; + list(callback: SparkPost.ResultsCallback): void; + /** + * List all your inbound domains. + * @returns Promise The Domain results array + */ + list(): SparkPost.ResultsPromise; /** * Retrieve an inbound domain by specifying its domain name in the URI path. * @param domain Domain name * @param callback The request callback with Domain results */ - find(domain: string, callback: SparkPost.ResultsCallback): void; + get(domain: string, callback: SparkPost.ResultsCallback): void; + /** + * Retrieve an inbound domain by specifying its domain name in the URI path. + * @param domain Domain name + * @returns Promise The Domain results + */ + get(domain: string): SparkPost.ResultsPromise; /** * Create an inbound domain by providing an inbound domains object as the POST request body. - * @param domain Domain name + * @param createOpts a hash of [inbound domain attributes]{@link https://developers.sparkpost.com/api/inbound-domains#header-inbound-domains-attributes} * @param callback The request callback */ - create(domain: string, callback: SparkPost.Callback): void; + create(createOpts: SparkPost.CreateOpts, callback: SparkPost.Callback): void; + /** + * Create an inbound domain by providing an inbound domains object as the POST request body. + * @param createOpts a hash of [inbound domain attributes]{@link https://developers.sparkpost.com/api/inbound-domains#header-inbound-domains-attributes} + * @returns Promise void + */ + create(createOpts: SparkPost.CreateOpts): Promise; /** * Delete an inbound domain by specifying its domain name in the URI path. * @param domain Domain name * @param callback The request callback */ delete(domain: string, callback: SparkPost.Callback): void; + /** + * Delete an inbound domain by specifying its domain name in the URI path. + * @param domain Domain name + * @returns Promise void + */ + delete(domain: string): Promise; }; /** The Message Events API provides the means to search the raw events generated by SparkPost. */ messageEvents: { @@ -167,7 +190,7 @@ declare class SparkPost { */ all(callback: SparkPost.ResultsCallback): void; /** - * + * * @param subaccountId The webhook id * @param callback The request callback with subaccount information results */ @@ -343,7 +366,7 @@ declare class SparkPost { }[]>): void; /** * Lists descriptions of the events, event types, and event fields that could be included in a Webhooks post to your target URL. - * @param callback The request callback containing documentation results + * @param callback The request callback containing documentation results */ getDocumentation(callback: SparkPost.ResultsCallback): void; /** @@ -405,6 +428,7 @@ declare namespace SparkPost { (err: Error | SparkPostError | null, res: Response): void; } export type ResultsCallback = Callback<{ results: T }>; + export type ResultsPromise = Promise<{ results: T }>; export interface Domain { domain: string; @@ -1061,6 +1085,16 @@ declare namespace SparkPost { method: string[]; }[]; } + + export interface CreateOpts { + /** + * Domain (or subdomain) name for which SparkPost will receive inbound emails + * + * @type {string} + * @memberOf CreateOpts + */ + domain: string; + } } export = SparkPost; diff --git a/sparkpost/sparkpost-tests.ts b/sparkpost/sparkpost-tests.ts index 9f7f47b44d..83ecf9a13d 100644 --- a/sparkpost/sparkpost-tests.ts +++ b/sparkpost/sparkpost-tests.ts @@ -14,7 +14,8 @@ client.get({ console.log(data.body); }); -client.inboundDomains.create("example1.com", function(err, res) { +// Callback +client.inboundDomains.create({ domain: 'example1.com' }, function(err, res) { if (err) { console.log(err); } else { @@ -23,6 +24,18 @@ client.inboundDomains.create("example1.com", function(err, res) { } }); +// Promise +client.inboundDomains.create({ domain: 'example1.com' }) + .then(data => { + console.log('Congrats you can use our client library!'); + console.log(data); + }) + .catch(err => { + console.log('Whoops! Something went wrong'); + console.log(err); +}); + +// Callback client.inboundDomains.delete("example1.com", function(err, res) { if (err) { console.log(err); @@ -32,7 +45,19 @@ client.inboundDomains.delete("example1.com", function(err, res) { } }); -client.inboundDomains.find("example1.com", function(err, res) { +// Promise +client.inboundDomains.delete('example1.com') + .then(data => { + console.log('Congrats you can use our client library!'); + console.log(data); + }) + .catch(err => { + console.log('Whoops! Something went wrong'); + console.log(err); +}); + +// Callback +client.inboundDomains.get("example1.com", function(err, res) { if (err) { console.log(err); } else { @@ -41,7 +66,19 @@ client.inboundDomains.find("example1.com", function(err, res) { } }); -client.inboundDomains.all(function(err, res) { +// Promise +client.inboundDomains.get('example1.com') + .then(data => { + console.log('Congrats you can use our client library!'); + console.log(data); + }) + .catch(err => { + console.log('Whoops! Something went wrong'); + console.log(err); +}); + +// Callback +client.inboundDomains.list(function(err, res) { if (err) { console.log(err); } else { @@ -50,6 +87,17 @@ client.inboundDomains.all(function(err, res) { } }); +// Promise +client.inboundDomains.list() + .then(data => { + console.log('Congrats you can use our client library!'); + console.log(data); + }) + .catch(err => { + console.log('Whoops! Something went wrong'); + console.log(err); +}); + client.messageEvents.search({}, function(err, res) { if (err) { console.log(err);