From fb31d4b78cfcaf88a2b4254dcc4c650c575bf84c Mon Sep 17 00:00:00 2001 From: Akinmade Bond Date: Sat, 18 Mar 2017 13:41:51 +0100 Subject: [PATCH 01/19] update inboundDomains --- sparkpost/index.d.ts | 46 ++++++++++++++++++++++++++---- sparkpost/sparkpost-tests.ts | 54 ++++++++++++++++++++++++++++++++++-- 2 files changed, 91 insertions(+), 9 deletions(-) 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); From e938e689297302548b42ddb218fc3dedbe24e362 Mon Sep 17 00:00:00 2001 From: Akinmade Bond Date: Sat, 18 Mar 2017 13:48:05 +0100 Subject: [PATCH 02/19] update messageEvents --- sparkpost/index.d.ts | 6 +++++ sparkpost/sparkpost-tests.ts | 46 ++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/sparkpost/index.d.ts b/sparkpost/index.d.ts index de26de735a..1acad061a1 100644 --- a/sparkpost/index.d.ts +++ b/sparkpost/index.d.ts @@ -67,6 +67,12 @@ declare class SparkPost { * @param callback The request callback with MessageEvent results array */ search(parameters: SparkPost.MessageEventParameters, callback: SparkPost.ResultsCallback): void; + /** + * Retrieves list of message events according to given params + * @param parameters Query parameters + * @returns Promise The MessageEvent results array + */ + search(parameters: SparkPost.MessageEventParameters): SparkPost.ResultsPromise; }; /** A recipient list is a collection of recipients that can be used in a transmission. */ recipientLists: { diff --git a/sparkpost/sparkpost-tests.ts b/sparkpost/sparkpost-tests.ts index 83ecf9a13d..6e28ce055b 100644 --- a/sparkpost/sparkpost-tests.ts +++ b/sparkpost/sparkpost-tests.ts @@ -98,6 +98,7 @@ client.inboundDomains.list() console.log(err); }); +// Callback client.messageEvents.search({}, function(err, res) { if (err) { console.log(err); @@ -107,6 +108,7 @@ client.messageEvents.search({}, function(err, res) { } }); +// Callback client.messageEvents.search({ events: "click", campaign_ids: "monday_mailshot" @@ -119,6 +121,7 @@ client.messageEvents.search({ } }); +// Callback client.messageEvents.search({ from: "2016-01-01T00:00", to: "2016-01-02T23:59", @@ -135,6 +138,49 @@ client.messageEvents.search({ } }); +// Promise +client.messageEvents.search({ + events: 'click', + campaign_ids: 'monday_mailshot' +}) + .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); +}); + +// Promise +client.messageEvents.search({}) + .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); +}); + +// Promise +client.messageEvents.search({ + from: '2016-01-01T00:00', + to: '2016-01-02T23:59', + page: 1, + per_page: 5, + events: ['bounce', 'out_of_band'], + bounce_classes: [10] +}) + .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.recipientLists.create({ id: "UNIQUE_TEST_ID", name: "Test Recipient List", From f1ad8e3cc2a0c1802b515ce7336a5ed44f524807 Mon Sep 17 00:00:00 2001 From: Akinmade Bond Date: Sat, 18 Mar 2017 12:51:45 +0100 Subject: [PATCH 03/19] Update recipientLists --- sparkpost/index.d.ts | 72 +++++++++++++++++---- sparkpost/sparkpost-tests.ts | 120 ++++++++++++++++++++++++++++++++--- 2 files changed, 172 insertions(+), 20 deletions(-) diff --git a/sparkpost/index.d.ts b/sparkpost/index.d.ts index 1acad061a1..a47d1504bd 100644 --- a/sparkpost/index.d.ts +++ b/sparkpost/index.d.ts @@ -78,24 +78,46 @@ declare class SparkPost { recipientLists: { /** * List a summary of all recipient lists. The recipients for each list are not included in the results. - * To retrieve recipient details, use the RETRIEVE API for a specified recipient list. + * To retrieve recipient details, use the [Retrieve a Recipient List endpoint]{@link https://developers.sparkpost.com/api/recipient-lists.html#recipient-lists-retrieve-get}, + * and specify the recipient list. + * * @param callback The request callback with RecipientList results array */ - all(callback: SparkPost.ResultsCallback): void; + list(callback: SparkPost.ResultsCallback): void; + /** + * List a summary of all recipient lists. The recipients for each list are not included in the results. + * To retrieve recipient details, use the [Retrieve a Recipient List endpoint]{@link https://developers.sparkpost.com/api/recipient-lists.html#recipient-lists-retrieve-get}, + * and specify the recipient list. + * + * @returns Promise The RecipientList results array + */ + list(): SparkPost.ResultsPromise; /** * Retrieve details about a specified recipient list by specifying its id in the URI path. * To retrieve the recipients contained in a list, the show_recipients parameter must be set to true. - * @param options The find options - * @param callback The request callback with RecipientList results + * + * @param {string} id + * @param {{ show_recipients?: boolean }} specifies whether to retrieve the recipients. Defaults to false + * @param {SparkPost.Callback} callback */ - find(options: { id: string, show_recipients?: false }, callback: SparkPost.Callback): void; + get(id: string, options: { show_recipients?: boolean }, callback: SparkPost.Callback): void; /** * Retrieve details about a specified recipient list by specifying its id in the URI path. * To retrieve the recipients contained in a list, the show_recipients parameter must be set to true. - * @param options The find options - * @param callback The request callback with RecipientList results (with recipients) + * + * @param {string} id + * @param {SparkPost.Callback} callback */ - find(options: { id: string, show_recipients: true }, callback: SparkPost.Callback): void; + get(id: string, callback: SparkPost.Callback): void; + /** + * Retrieve details about a specified recipient list by specifying its id in the URI path. + * To retrieve the recipients contained in a list, the show_recipients parameter must be set to true. + * + * @param {string} id + * @param {{ show_recipients?: boolean }} [options] specifies whether to retrieve the recipients. Defaults to false + * @returns {Promise} + */ + get(id: string, options?: { show_recipients?: boolean }): Promise; /** * Create a recipient list by providing a recipient list object as the POST request body. * At a minimum, the “recipients” array is required, which must contain a valid “address”. @@ -105,19 +127,47 @@ declare class SparkPost { * @param callback The request callback with metadata results */ create(options: SparkPost.CreateRecipientList, callback: SparkPost.ResultsCallback): void; + /** + * Create a recipient list by providing a recipient list object as the POST request body. + * At a minimum, the “recipients” array is required, which must contain a valid “address”. + * If the recipient list “id” is not provided in the POST request body, one will be generated and returned in the results body. + * Use the num_rcpt_errors parameter to limit the number of recipient errors returned. + * @param options The create options + * @returns Promise metadata results + */ + create(options: SparkPost.CreateRecipientList): SparkPost.ResultsPromise; /** * Update an existing recipient list by specifying its ID in the URI path and use a recipient list object as the PUT request body. * Use the num_rcpt_errors parameter to limit the number of recipient errors returned. + * + * @param {string} id Identifier of the recipient list * @param options The update options * @param callback The request callback with metadata results */ - update(options: SparkPost.UpdateRecipientList, callback: SparkPost.ResultsCallback): void; + update(id: string, options: SparkPost.UpdateRecipientList, callback: SparkPost.ResultsCallback): void; + /** + * Update an existing recipient list by specifying its ID in the URI path and use a recipient list object as the PUT request body. + * Use the num_rcpt_errors parameter to limit the number of recipient errors returned. + * + * @param {string} id Identifier of the recipient list + * @param {SparkPost.UpdateRecipientList} options + * @returns {SparkPost.ResultsPromise} + */ + update(id: string, options: SparkPost.UpdateRecipientList): SparkPost.ResultsPromise; /** * Permanently delete the specified recipient list. + * * @param id The list id * @param callback The request callback */ delete(id: string, callback: SparkPost.Callback): void; + /** + * Permanently delete the specified recipient list. + * + * @param id The list id + * @returns Promise void + */ + delete(id: string): Promise; }; /** Relay Webhooks are a way to instruct SparkPost to accept inbound email on your behalf and forward it to you over HTTP for your own consumption. */ relayWebhooks: { @@ -573,10 +623,8 @@ declare namespace SparkPost { description?: string; /** Recipient list attribute object */ attributes?: any; - /** limit the number of recipient errors returned. */ - num_rcpt_errors?: number; /** Array of recipient objects */ - recipients?: Recipient[]; + recipients: Recipient[]; } export interface BaseRecipient { diff --git a/sparkpost/sparkpost-tests.ts b/sparkpost/sparkpost-tests.ts index 6e28ce055b..e7e9145cb8 100644 --- a/sparkpost/sparkpost-tests.ts +++ b/sparkpost/sparkpost-tests.ts @@ -181,6 +181,7 @@ client.messageEvents.search({ console.log(err); }); +// Callback client.recipientLists.create({ id: "UNIQUE_TEST_ID", name: "Test Recipient List", @@ -208,6 +209,36 @@ client.recipientLists.create({ } }); +// Promise +client.recipientLists.create({ + id: "UNIQUE_TEST_ID", + name: "Test Recipient List", + recipients: [ + { + address: { + email: "test1@test.com" + } + }, { + address: { + email: "test2@test.com" + } + }, { + address: { + email: "test3@test.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.recipientLists.delete("UNIQUE_TEST_ID", function(err, res) { if (err) { console.log(err); @@ -217,7 +248,19 @@ client.recipientLists.delete("UNIQUE_TEST_ID", function(err, res) { } }); -client.recipientLists.all(function(err, res) { +// Promise +client.recipientLists.delete('UNIQUE_TEST_ID') + .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.recipientLists.list(function(err, res) { if (err) { console.log(err); } else { @@ -226,9 +269,19 @@ client.recipientLists.all(function(err, res) { } }); -client.recipientLists.find({ - id: "UNIQUE_TEST_ID" -}, function(err, res) { +// Promise +client.recipientLists.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); +}); + +// Callback +client.recipientLists.get('UNIQUE_TEST_ID', function(err, res) { if (err) { console.log(err); } else { @@ -237,8 +290,8 @@ client.recipientLists.find({ } }); -client.recipientLists.find({ - id: "UNIQUE_TEST_ID", +// Callback +client.recipientLists.get('UNIQUE_TEST_ID', { show_recipients: true }, function(err, res) { if (err) { @@ -249,8 +302,32 @@ client.recipientLists.find({ } }); -client.recipientLists.update({ - id: "EXISTING_TEST_ID", +// Promise +client.recipientLists.get('UNIQUE_TEST_ID', { + show_recipients: true +}) + .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); +}); + +// Promise +client.recipientLists.get('UNIQUE_TEST_ID') + .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.recipientLists.update('EXISTING_TEST_ID', { name: "Test Recipient List", recipients: [ { @@ -276,6 +353,33 @@ client.recipientLists.update({ } }); +// Promise +client.recipientLists.update('EXISTING_TEST_ID', { + name: "Test Recipient List", + recipients: [ + { + address: { + email: "test1@test.com" + } + }, { + address: { + email: "test2@test.com" + } + }, { + address: { + email: "test3@test.com" + } + } + ] +}) + .then(data => { + console.log('Congrats you can use our client library!'); + console.log(data); + }) + .catch(err => { + console.log(err); + }); + client.relayWebhooks.create({ name: "Test Relay Webhook", target: "http://client.test.com/test-webhook", From 854765bce388216773e69f0a93d48aa1ea8ca44d Mon Sep 17 00:00:00 2001 From: Akinmade Bond Date: Sat, 18 Mar 2017 14:08:05 +0100 Subject: [PATCH 04/19] update relayWebhooks --- sparkpost/index.d.ts | 37 ++++++++++++++++-- sparkpost/sparkpost-tests.ts | 74 ++++++++++++++++++++++++++++++++++-- 2 files changed, 103 insertions(+), 8 deletions(-) diff --git a/sparkpost/index.d.ts b/sparkpost/index.d.ts index a47d1504bd..9e380f4476 100644 --- a/sparkpost/index.d.ts +++ b/sparkpost/index.d.ts @@ -175,31 +175,60 @@ declare class SparkPost { * List all your relay webhooks. * @param callback The request callback with RelayWebhook results array */ - all(callback: SparkPost.ResultsCallback): void; + list(callback: SparkPost.ResultsCallback): void; + /** + * List all your relay webhooks. + * @returns Promise The RelayWebhook results array + */ + list(): SparkPost.ResultsPromise; /** * Delete a relay webhook by specifying the webhook ID in the URI path. * @param relayWebhookId The webhook id * @param callback The request callback with RelayWebhook results */ - find(relayWebhookId: string, callback: SparkPost.ResultsCallback): void; + get(relayWebhookId: string, callback: SparkPost.ResultsCallback): void; + /** + * Delete a relay webhook by specifying the webhook ID in the URI path. + * @param relayWebhookId The webhook id + * @returns Promise The RelayWebhook results + */ + get(relayWebhookId: string): SparkPost.ResultsPromise; /** * Create a relay webhook by providing a relay webhooks object as the POST request body. * @param options The create options * @param callback The request callback with webhook id results */ create(options: SparkPost.RelayWebhook, callback: SparkPost.ResultsCallback<{ id: string }>): void; + /** + * Create a relay webhook by providing a relay webhooks object as the POST request body. + * @param options The create options + * @returns Promise The webhook id results + */ + create(options: SparkPost.RelayWebhook): SparkPost.ResultsPromise<{ id: string }>; /** * Update a relay webhook by specifying the webhook ID in the URI path. * @param options The update options * @param callback The request callback with webhook id results */ - update(options: SparkPost.UpdateRelayWebhook & { relayWebhookId: string }, callback: SparkPost.ResultsCallback<{ id: string }>): void; + update(id: string, options: SparkPost.UpdateRelayWebhook, callback: SparkPost.ResultsCallback<{ id: string }>): void; + /** + * Update a relay webhook by specifying the webhook ID in the URI path. + * @param options The update options + * @returns Promise The webhook id results + */ + update(id: string, options: SparkPost.UpdateRelayWebhook): SparkPost.ResultsPromise<{ id: string }>; /** * Delete a relay webhook by specifying the webhook ID in the URI path. * @param relayWebhookId The webhook id * @param callback The request callback */ delete(relayWebhookId: string, callback: SparkPost.Callback): void; + /** + * Delete a relay webhook by specifying the webhook ID in the URI path. + * @param relayWebhookId The webhook id + * @returns Promise void + */ + delete(relayWebhookId: string): Promise; }; sendingDomains: { /** @@ -688,7 +717,7 @@ declare namespace SparkPost { /** User-friendly name no example: Inbound Customer Replies */ name?: string; /** URL of the target to which to POST relay batches */ - target?: string; + target: string; /** Authentication token to present in the X-MessageSystems-Webhook-Token header of POST requests to target */ auth_token?: string; /** Restrict which inbound messages will be relayed to the target */ diff --git a/sparkpost/sparkpost-tests.ts b/sparkpost/sparkpost-tests.ts index e7e9145cb8..667b5c89aa 100644 --- a/sparkpost/sparkpost-tests.ts +++ b/sparkpost/sparkpost-tests.ts @@ -380,6 +380,7 @@ client.recipientLists.update('EXISTING_TEST_ID', { console.log(err); }); +// Callback client.relayWebhooks.create({ name: "Test Relay Webhook", target: "http://client.test.com/test-webhook", @@ -395,6 +396,24 @@ client.relayWebhooks.create({ } }); +// Promise +client.relayWebhooks.create({ + name: 'Test Relay Webhook', + target: 'http://client.test.com/test-webhook', + match: { + domain: 'inbound.example.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.relayWebhooks.delete("123456789", function(err, res) { if (err) { console.log(err); @@ -404,7 +423,19 @@ client.relayWebhooks.delete("123456789", function(err, res) { } }); -client.relayWebhooks.find("123456789", function(err, res) { +// Promise +client.relayWebhooks.delete('123456789') + .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.relayWebhooks.get('123456789', function(err, res) { if (err) { console.log(err); } else { @@ -413,7 +444,18 @@ client.relayWebhooks.find("123456789", function(err, res) { } }); -client.relayWebhooks.all(function(err, res) { +// Promise +client.relayWebhooks.get('123456789') + .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.relayWebhooks.list(function(err, res) { if (err) { console.log(err); } else { @@ -422,8 +464,19 @@ client.relayWebhooks.all(function(err, res) { } }); -client.relayWebhooks.update({ - relayWebhookId: "123456789", +// Promise +client.relayWebhooks.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); +}); + +// Callback +client.relayWebhooks.update('123456789', { target: "http://client.test.com/test-webhook" }, function(err, res) { if (err) { @@ -434,6 +487,19 @@ client.relayWebhooks.update({ } }); +// Promise +client.relayWebhooks.update('123456789', { + target: 'http://client.test.com/test-webhook' +}) + .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.sendingDomains.create({ domain: "example1.com", dkim: { From 71a5bcf3b6e7b8f4be6a38bf4b6b8de92388fd90 Mon Sep 17 00:00:00 2001 From: Akinmade Bond Date: Sat, 18 Mar 2017 14:43:15 +0100 Subject: [PATCH 05/19] update sendingDomains --- sparkpost/index.d.ts | 105 +++++++++++++++++++++++++++---- sparkpost/sparkpost-tests.ts | 116 +++++++++++++++++++++++++++++------ 2 files changed, 192 insertions(+), 29 deletions(-) diff --git a/sparkpost/index.d.ts b/sparkpost/index.d.ts index 9e380f4476..df9cba1855 100644 --- a/sparkpost/index.d.ts +++ b/sparkpost/index.d.ts @@ -235,37 +235,82 @@ declare class SparkPost { * List an overview of all sending domains in the system. * @param callback The request callback with SendingDomain results array */ - all(callback: SparkPost.ResultsCallback): void; + list(callback: SparkPost.ResultsCallback): void; + /** + * List an overview of all sending domains in the system. + * + * @returns The SendingDomain results array + */ + list(): SparkPost.ResultsPromise; /** * Retrieve a sending domain by specifying its domain name in the URI path. The response includes details about its DKIM key configuration. * @param domain The domain * @param callback The request callback with SendingDomain results */ - find(domain: string, callback: SparkPost.ResultsCallback): void; + get(domain: string, callback: SparkPost.ResultsCallback): void; + /** + * Retrieve a sending domain by specifying its domain name in the URI path. The response includes details about its DKIM key configuration. + * + * @param domain The domain + * @returns Promise The SendingDomain results + */ + get(domain: string): SparkPost.ResultsPromise; /** * Create a sending domain by providing a sending domain object as the POST request body. * @param options The create options * @param callback The request callback with basic info results */ create(options: SparkPost.CreateSendingDomain, callback: SparkPost.ResultsCallback<{ message: string, domain: string }>): void; + /** + * Create a sending domain by providing a sending domain object as the POST request body. + * + * @param options The create options + * @returns Promise The basic info results + */ + create(options: SparkPost.CreateSendingDomain): SparkPost.ResultsPromise<{ message: string, domain: string }>; /** * Update the attributes of an existing sending domain by specifying its domain name in the URI path and use a sending domain object as the PUT request body. - * @param options The update options + * @param domain The domain + * @param updateOpts The update options * @param callback The request callback with basic info results */ - update(options: SparkPost.UpdateSendingDomain, callback: SparkPost.ResultsCallback<{ message: string, domain: string }>): void; + update(domain: string, updateOpts: SparkPost.UpdateSendingDomain, callback: SparkPost.ResultsCallback<{ message: string, domain: string }>): void; + /** + * Update the attributes of an existing sending domain by specifying its domain name in the URI path and use a sending domain object as the PUT request body. + * + * @param domain The domain + * @param updateOpts The update options + * @returns Promise The basic info results + */ + update(domain: string, updateOpts: SparkPost.UpdateSendingDomain): SparkPost.ResultsPromise<{ message: string, domain: string }>; /** * Delete an existing sending domain. * @param domain The domain * @param callback The request callback */ delete(domain: string, callback: SparkPost.Callback): void; + /** + * Delete an existing sending domain. + * + * @param domain The domain + * @returns Promise void + */ + delete(domain: string): Promise; /** * Verify a Sending Domain - * @param options The verify options + * @param domain The domain + * @param options a hash of [verify attributes]{@link https://developers.sparkpost.com/api/sending-domains#header-verify-attributes} * @param callback The request callback with verify results */ - verify(options: SparkPost.VerifyOptions, callback: SparkPost.ResultsCallback): void; + verify(domain: string, options: SparkPost.VerifyOptions, callback: SparkPost.ResultsCallback): void; + /** + * Verify a Sending Domain + * + * @param domain The domain + * @param options a hash of [verify attributes]{@link https://developers.sparkpost.com/api/sending-domains#header-verify-attributes} + * @returns Promise The verify results + */ + verify(domain: string, options: SparkPost.VerifyOptions): SparkPost.ResultsPromise; }; subaccounts: { /** @@ -768,8 +813,6 @@ declare namespace SparkPost { } export interface UpdateSendingDomain { - /** Name of the sending domain. */ - domain: string; /** Associated tracking domain. */ tracking_domain?: string; /** JSON object in which DKIM key configuration is defined. */ @@ -811,9 +854,49 @@ declare namespace SparkPost { } export interface VerifyOptions { - domain: string; - verifyDKIM?: boolean; - verifySPF?: boolean; + /** + * Request verification of DKIM record + * + * @type {boolean} + * @memberOf VerifyOptions + */ + dkim_verify?: boolean; + /** + * Request verification of SPF record + * + * @type {boolean} + * @deprecated + * @memberOf VerifyOptions + */ + spf_verify?: boolean; + /** + * Request an email with a verification link to be sent to the sending domain’s postmaster@ mailbox. + * + * @type {boolean} + * @memberOf VerifyOptions + */ + postmaster_at_verify?: boolean; + /** + * Request an email with a verification link to be sent to the sending domain’s abuse@ mailbox. + * + * @type {boolean} + * @memberOf VerifyOptions + */ + abuse_at_verify?: boolean; + /** + * A token retrieved from the verification link contained in the postmaster@ verification email. + * + * @type {string} + * @memberOf VerifyOptions + */ + postmaster_at_token?: string; + /** + * A token retrieved from the verification link contained in the abuse@ verification email. + * + * @type {string} + * @memberOf VerifyOptions + */ + abuse_at_token?: string; } export interface VerifyResults extends Status { diff --git a/sparkpost/sparkpost-tests.ts b/sparkpost/sparkpost-tests.ts index 667b5c89aa..8235a0e4d1 100644 --- a/sparkpost/sparkpost-tests.ts +++ b/sparkpost/sparkpost-tests.ts @@ -500,6 +500,7 @@ client.relayWebhooks.update('123456789', { console.log(err); }); +// Callback client.sendingDomains.create({ domain: "example1.com", dkim: { @@ -517,7 +518,26 @@ client.sendingDomains.create({ } }); +// Promise +client.sendingDomains.create({ + domain: 'example1.com', + dkim: { + 'private': 'MIICXgIBAAKBgQC+W6scd3XWwvC/hPRksfDYFi3ztgyS9OSqnnjtNQeDdTSD1DRx/xFar2wjmzxp2+SnJ5pspaF77VZveN3P/HVmXZVghr3asoV9WBx/uW1nDIUxU35L4juXiTwsMAbgMyh3NqIKTNKyMDy4P8vpEhtH1iv/BrwMdBjHDVCycB8WnwIDAQABAoGBAITb3BCRPBi5lGhHdn+1RgC7cjUQEbSb4eFHm+ULRwQ0UIPWHwiVWtptZ09usHq989fKp1g/PfcNzm8c78uTS6gCxfECweFCRK6EdO6cCCr1cfWvmBdSjzYhODUdQeyWZi2ozqd0FhGWoV4VHseh4iLj36DzleTLtOZj3FhAo1WJAkEA68T+KkGeDyWwvttYtuSiQCCTrXYAWTQnkIUxduCp7Ap6tVeIDn3TaXTj74UbEgaNgLhjG4bX//fdeDW6PaK9YwJBAM6xJmwHLPMgwNVjiz3u/6fhY3kaZTWcxtMkXCjh1QE82KzDwqyrCg7EFjTtFysSHCAZxXZMcivGl4TZLHnydJUCQQCx16+M+mAatuiCnvxlQUMuMiSTNK6Amzm45u9v53nlZeY3weYMYFdHdfe1pebMiwrT7MI9clKebz6svYJVmdtXAkApDAc8VuR3WB7TgdRKNWdyGJGfoD1PO1ZE4iinOcoKV+IT1UCY99Kkgg6C7j62n/8T5OpRBvd5eBPpHxP1F9BNAkEA5Nf2VO9lcTetksHdIeKK+F7sio6UZn0Rv7iUo3ALrN1D1cGfWIh2dj3ko1iSreyNVSwGW0ePP27qDmU+u6/Y1g==', + 'public': 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+W6scd3XWwvC/hPRksfDYFi3ztgyS9OSqnnjtNQeDdTSD1DRx/xFar2wjmzxp2+SnJ5pspaF77VZveN3P/HVmXZVghr3asoV9WBx/uW1nDIUxU35L4juXiTwsMAbgMyh3NqIKTNKyMDy4P8vpEhtH1iv/BrwMdBjHDVCycB8WnwIDAQAB', + selector: 'brisbane', + headers: 'from:to:subject:date' + } +}) + .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.sendingDomains.delete("example1.com", function(err, data) { if (err) { console.log(err); @@ -527,7 +547,19 @@ client.sendingDomains.delete("example1.com", function(err, data) { } }); -client.sendingDomains.all(function(err, res) { +// Promise +client.sendingDomains.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.sendingDomains.list(function(err, res) { if (err) { console.log(err); } else { @@ -536,7 +568,19 @@ client.sendingDomains.all(function(err, res) { } }); -client.sendingDomains.find("example1.com", function(err, res) { +// Promise +client.sendingDomains.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); +}); + +// Callback +client.sendingDomains.get('example1.com', function(err, res) { if (err) { console.log(err); } else { @@ -545,8 +589,19 @@ client.sendingDomains.find("example1.com", function(err, res) { } }); -client.sendingDomains.update({ - domain: "example1.com", +// Promise +client.sendingDomains.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.sendingDomains.update('example1.com', { dkim: { "private": "MIICXgIBAAKBgQC+W6scd3XWwvC/hPRksfDYFi3ztgyS9OSqnnjtNQeDdTSD1DRx/xFar2wjmzxp2+SnJ5pspaF77VZveN3P/HVmXZVghr3asoV9WBx/uW1nDIUxU35L4juXiTwsMAbgMyh3NqIKTNKyMDy4P8vpEhtH1iv/BrwMdBjHDVCycB8WnwIDAQABAoGBAITb3BCRPBi5lGhHdn+1RgC7cjUQEbSb4eFHm+ULRwQ0UIPWHwiVWtptZ09usHq989fKp1g/PfcNzm8c78uTS6gCxfECweFCRK6EdO6cCCr1cfWvmBdSjzYhODUdQeyWZi2ozqd0FhGWoV4VHseh4iLj36DzleTLtOZj3FhAo1WJAkEA68T+KkGeDyWwvttYtuSiQCCTrXYAWTQnkIUxduCp7Ap6tVeIDn3TaXTj74UbEgaNgLhjG4bX//fdeDW6PaK9YwJBAM6xJmwHLPMgwNVjiz3u/6fhY3kaZTWcxtMkXCjh1QE82KzDwqyrCg7EFjTtFysSHCAZxXZMcivGl4TZLHnydJUCQQCx16+M+mAatuiCnvxlQUMuMiSTNK6Amzm45u9v53nlZeY3weYMYFdHdfe1pebMiwrT7MI9clKebz6svYJVmdtXAkApDAc8VuR3WB7TgdRKNWdyGJGfoD1PO1ZE4iinOcoKV+IT1UCY99Kkgg6C7j62n/8T5OpRBvd5eBPpHxP1F9BNAkEA5Nf2VO9lcTetksHdIeKK+F7sio6UZn0Rv7iUo3ALrN1D1cGfWIh2dj3ko1iSreyNVSwGW0ePP27qDmU+u6/Y1g==", "public": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+W6scd3XWwvC/hPRksfDYFi3ztgyS9OSqnnjtNQeDdTSD1DRx/xFar2wjmzxp2+SnJ5pspaF77VZveN3P/HVmXZVghr3asoV9WBx/uW1nDIUxU35L4juXiTwsMAbgMyh3NqIKTNKyMDy4P8vpEhtH1iv/BrwMdBjHDVCycB8WnwIDAQAB", @@ -562,8 +617,29 @@ client.sendingDomains.update({ } }); -client.sendingDomains.verify({ - domain: "example1.com" +client.sendingDomains.update('example1.com', { + dkim: { + 'private': 'MIICXgIBAAKBgQC+W6scd3XWwvC/hPRksfDYFi3ztgyS9OSqnnjtNQeDdTSD1DRx/xFar2wjmzxp2+SnJ5pspaF77VZveN3P/HVmXZVghr3asoV9WBx/uW1nDIUxU35L4juXiTwsMAbgMyh3NqIKTNKyMDy4P8vpEhtH1iv/BrwMdBjHDVCycB8WnwIDAQABAoGBAITb3BCRPBi5lGhHdn+1RgC7cjUQEbSb4eFHm+ULRwQ0UIPWHwiVWtptZ09usHq989fKp1g/PfcNzm8c78uTS6gCxfECweFCRK6EdO6cCCr1cfWvmBdSjzYhODUdQeyWZi2ozqd0FhGWoV4VHseh4iLj36DzleTLtOZj3FhAo1WJAkEA68T+KkGeDyWwvttYtuSiQCCTrXYAWTQnkIUxduCp7Ap6tVeIDn3TaXTj74UbEgaNgLhjG4bX//fdeDW6PaK9YwJBAM6xJmwHLPMgwNVjiz3u/6fhY3kaZTWcxtMkXCjh1QE82KzDwqyrCg7EFjTtFysSHCAZxXZMcivGl4TZLHnydJUCQQCx16+M+mAatuiCnvxlQUMuMiSTNK6Amzm45u9v53nlZeY3weYMYFdHdfe1pebMiwrT7MI9clKebz6svYJVmdtXAkApDAc8VuR3WB7TgdRKNWdyGJGfoD1PO1ZE4iinOcoKV+IT1UCY99Kkgg6C7j62n/8T5OpRBvd5eBPpHxP1F9BNAkEA5Nf2VO9lcTetksHdIeKK+F7sio6UZn0Rv7iUo3ALrN1D1cGfWIh2dj3ko1iSreyNVSwGW0ePP27qDmU+u6/Y1g==', + 'public': 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+W6scd3XWwvC/hPRksfDYFi3ztgyS9OSqnnjtNQeDdTSD1DRx/xFar2wjmzxp2+SnJ5pspaF77VZveN3P/HVmXZVghr3asoV9WBx/uW1nDIUxU35L4juXiTwsMAbgMyh3NqIKTNKyMDy4P8vpEhtH1iv/BrwMdBjHDVCycB8WnwIDAQAB', + selector: 'hello_selector', + headers: 'from:to:subject:date' + } +}) + .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.sendingDomains.verify('example1.com', { + dkim_verify: true, + spf_verify: true, + abuse_at_verify: true, + postmaster_at_verify: true }, function(err, res) { if (err) { console.log(err); @@ -573,9 +649,9 @@ client.sendingDomains.verify({ } }); -client.sendingDomains.verify({ - domain: "example1.com", - verifySPF: false +// Callback +client.sendingDomains.verify('example1.com', { + dkim_verify: false }, function(err, res) { if (err) { console.log(err); @@ -585,16 +661,20 @@ client.sendingDomains.verify({ } }); -client.sendingDomains.verify({ - domain: "example1.com", - verifyDKIM: false -}, function(err, res) { - if (err) { +// Promise +client.sendingDomains.verify('example1.com', { + dkim_verify: true, + spf_verify: true, + abuse_at_verify: true, + postmaster_at_verify: true +}) + .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); - } else { - console.log(res.body); - console.log("Congrats you can use our SDK!"); - } }); client.subaccounts.create({ From f721d62192656ffdc6c70e54f1d010b41c861810 Mon Sep 17 00:00:00 2001 From: Akinmade Bond Date: Sat, 18 Mar 2017 15:16:02 +0100 Subject: [PATCH 06/19] update subaccounts --- sparkpost/index.d.ts | 58 ++++++++++++++++++++++-------- sparkpost/sparkpost-tests.ts | 69 ++++++++++++++++++++++++++++++++---- 2 files changed, 107 insertions(+), 20 deletions(-) diff --git a/sparkpost/index.d.ts b/sparkpost/index.d.ts index df9cba1855..bd5ad9f4a9 100644 --- a/sparkpost/index.d.ts +++ b/sparkpost/index.d.ts @@ -318,25 +318,57 @@ declare class SparkPost { * This endpoint only returns information about the subaccounts themselves, not the data associated with the subaccount. * @param callback The request callback with subaccount information results array */ - all(callback: SparkPost.ResultsCallback): void; + list(callback: SparkPost.ResultsCallback): void; /** + * Endpoint for retrieving a list of your subaccounts. + * This endpoint only returns information about the subaccounts themselves, not the data associated with the subaccount. * - * @param subaccountId The webhook id + * @returns Promise The subaccount information results array + */ + list(): SparkPost.ResultsPromise; + /** + * Get details about a specified subaccount by its id + * + * @param id the id of the subaccount you want to look up * @param callback The request callback with subaccount information results */ - find(subaccountId: string | number, callback: SparkPost.ResultsCallback): void; + get(id: string | number, callback: SparkPost.ResultsCallback): void; + /** + * Get details about a specified subaccount by its id + * + * @param id the id of the subaccount you want to look up + * @returns Promise The subaccount information results + */ + get(id: string | number): SparkPost.ResultsPromise; /** * Provisions a new subaccount and an initial subaccount API key. - * @param options The create options + * @param subaccount The create options * @param callback The request callback with basic subaccount information results */ - create(options: SparkPost.CreateSubaccount, callback: SparkPost.ResultsCallback): void; + create(subaccount: SparkPost.CreateSubaccount, callback: SparkPost.ResultsCallback): void; + /** + * Provisions a new subaccount and an initial subaccount API key. + * + * @param subaccount The create options + * @returns Promise The basic subaccount information results + */ + create(subaccount: SparkPost.CreateSubaccount): SparkPost.ResultsPromise; /** * Update an existing subaccount’s information. - * @param options The create options + * + * @param id the id of the subaccount you want to update + * @param subaccount an object of [updatable subaccount attributes]{@link https://developers.sparkpost.com/api/subaccounts#header-request-body-attributes-1} * @param callback The request callback with webhook id results */ - update(options: SparkPost.UpdateSubaccount, callback: SparkPost.ResultsCallback<{ message: string }>): void; + update(id: string, subaccount: SparkPost.UpdateSubaccount, callback: SparkPost.ResultsCallback<{ message: string }>): void; + /** + * Update an existing subaccount’s information. + * + * @param id the id of the subaccount you want to update + * @param subaccount an object of [updatable subaccount attributes]{@link https://developers.sparkpost.com/api/subaccounts#header-request-body-attributes-1} + * @returns Promise The webhook id results + */ + update(id: string, subaccount: SparkPost.UpdateSubaccount): SparkPost.ResultsPromise<{ message: string }>; }; suppressionList: { /** @@ -910,13 +942,13 @@ declare namespace SparkPost { /** user-friendly name */ name: string; /** user-friendly identifier for subaccount API key */ - keyLabel: string; + key_label: string; /** list of grants to give the subaccount API key */ - keyGrants: string[]; + key_grants: string[]; /** list of IPs the subaccount may be used from */ - keyValidIps?: string[]; + key_valid_ips?: string[]; /** id of the default IP pool assigned to subaccount"s transmissions */ - ipPool?: string; + ip_pool?: string; } export interface CreateSubaccountResponse { @@ -927,14 +959,12 @@ declare namespace SparkPost { } export interface UpdateSubaccount { - /** the id of the subaccount you want to update */ - subaccountId: string | number; /** user-friendly name */ name: string; /** status of the subaccount */ status: string; /** id of the default IP pool assigned to subaccount"s transmissions */ - ipPool?: string; + ip_pool?: string; } export interface SubaccountInformation { diff --git a/sparkpost/sparkpost-tests.ts b/sparkpost/sparkpost-tests.ts index 8235a0e4d1..b940994c0a 100644 --- a/sparkpost/sparkpost-tests.ts +++ b/sparkpost/sparkpost-tests.ts @@ -677,10 +677,11 @@ client.sendingDomains.verify('example1.com', { console.log(err); }); +// Callback client.subaccounts.create({ name: "Test Subaccount", - keyLabel: "Test Subaccount key", - keyGrants: [ + key_label: 'Test Subaccount key', + key_grants: [ "smtp/inject", "transmissions/modify" ] @@ -693,7 +694,26 @@ client.subaccounts.create({ } }); -client.subaccounts.all(function(err, res) { +// Promise +client.subaccounts.create({ + name: 'Test Subaccount', + key_label: 'Test Subaccount key', + key_grants: [ + 'smtp/inject', + 'transmissions/modify' + ] +}) + .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.subaccounts.list(function(err, res) { if (err) { console.log(err); } else { @@ -702,7 +722,19 @@ client.subaccounts.all(function(err, res) { } }); -client.subaccounts.find(123, function(err, res) { +// Promise +client.subaccounts.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); +}); + +// Callback +client.subaccounts.get(123, function(err, res) { if (err) { console.log(err); } else { @@ -711,8 +743,19 @@ client.subaccounts.find(123, function(err, res) { } }); -client.subaccounts.update({ - subaccountId: 123, +// Promise +client.subaccounts.get('123') + .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.subaccounts.update('123', { name: "Test Subaccount", status: "suspended" }, function(err, res) { @@ -724,6 +767,20 @@ client.subaccounts.update({ } }); +// Promise +client.subaccounts.update('123', { + name: 'Test Subaccount', + status: 'suspended' +}) + .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.suppressionList.checkStatus("test@test.com", function(err, res) { if (err) { console.log(err); From d1cf11fb26145edabc797b513562e8ed6a62af38 Mon Sep 17 00:00:00 2001 From: Akinmade Bond Date: Sun, 19 Mar 2017 00:11:10 +0100 Subject: [PATCH 07/19] update suppressionList --- sparkpost/index.d.ts | 184 ++++++++++++++++++++++++++++++----- sparkpost/sparkpost-tests.ts | 171 ++++++++++++++++++++++++++------ 2 files changed, 301 insertions(+), 54 deletions(-) diff --git a/sparkpost/index.d.ts b/sparkpost/index.d.ts index bd5ad9f4a9..9c5eb5c2d0 100644 --- a/sparkpost/index.d.ts +++ b/sparkpost/index.d.ts @@ -372,29 +372,61 @@ declare class SparkPost { }; suppressionList: { /** - * Perform a filtered search for entries in your suppression list. - * @param parameters Object of search parameters - * @param callback The request callback with RelayWebhook results + * List all entries in your suppression list, filtered by an optional set of search parameters. + * + * @param {SparkPost.SupressionSearchParameters} [parameters] an object of [search parameters]{@link https://developers.sparkpost.com/api/suppression-list#suppression-list-search-get} + * @param {Promise} [callback] */ - search(parameters: SparkPost.SupressionSearch, callback: SparkPost.ResultsCallback): void; + list(parameters: SparkPost.SupressionSearchParameters, callback: SparkPost.ResultsCallback): void; /** - * Retrieve the suppression status for a specific recipient by specifying the recipient’s email address in the URI path. - * @param email Email address to check - * @param callback The request callback with webhook id results + * List all entries in your suppression list, filtered by an optional set of search parameters. + * + * @param {SparkPost.SupressionSearchParameters} [parameters] an object of [search parameters]{@link https://developers.sparkpost.com/api/suppression-list#suppression-list-search-get} + * @returns {Promise} */ - checkStatus(email: string, callback: SparkPost.ResultsCallback): void; + list(parameters?: SparkPost.SupressionSearchParameters): SparkPost.ResultsPromise; + /** + * Retrieve an entry by recipient email. + * + * @param {string} email address to check + * @returns void + */ + get(email: string, callback: SparkPost.ResultsCallback): void; + /** + * Retrieve an entry by recipient email. + * + * @param {string} email address to check + * @returns void + */ + get(email: string): SparkPost.ResultsPromise; /** * Delete a recipient from the list by specifying the recipient’s email address in the URI path. - * @param email Email address to check - * @param callback The request callback + * + * @param {string} email Recipient email address + * @param callback */ - removeStatus(email: string, callback: SparkPost.Callback): void; + delete(email: string, callback: SparkPost.Callback): void; /** - * Bulk insert or update entries in the customer-specific exclusion list. + * Delete a recipient from the list by specifying the recipient’s email address in the URI path. + * + * @param {string} email Recipient email address + * @returns {Promise} void + */ + delete(email: string): Promise; + /** + * Insert or update one or many entries. + * * @param parameters The suppression entry list * @param callback The request callback */ - upsert(parameters: SparkPost.CreateSupressionListEntry | SparkPost.CreateSupressionListEntry[], callback: SparkPost.ResultsCallback<{ message: string }>): void; + upsert(listEntries: SparkPost.CreateSupressionListEntry | SparkPost.CreateSupressionListEntry[], callback: SparkPost.ResultsCallback<{ message: string }>): void; + /** + * Insert or update one or many entries. + * + * @param {(SparkPost.CreateSupressionListEntry | SparkPost.CreateSupressionListEntry[])} listEntries The suppression entry list + * @returns {Promise<{ message: string }>} + */ + upsert(listEntries: SparkPost.CreateSupressionListEntry | SparkPost.CreateSupressionListEntry[]): SparkPost.ResultsPromise<{ message: string }>; }; templates: { /** @@ -980,41 +1012,149 @@ declare namespace SparkPost { } export interface CreateSupressionListEntry { + /** + * Email address to be suppressed + * + * @type {string} + * @memberOf CreateSupressionListEntry + */ recipient: string; - /** Whether the recipient requested to not receive any transactional messages. At a minimum, transactional or non_transactional is required upon creation of the entry. */ + /** + * Type of suppression record + * + * @type {("transactional" | "non_transactional")} + * @memberOf CreateSupressionListEntry + */ + type?: "transactional" | "non_transactional"; + /** + * Whether the recipient requested to not receive any non-transactional messages + * Not required if a valid type is passed + * + * @deprecated Available, but deprecated in favor of type + * @type {boolean} + * @memberOf CreateSupressionListEntry + */ transactional?: boolean; - /** Whether the recipient requested to not receive any non-transactional messages. At a minimum, transactional or non_transactional is required upon creation of the entry. */ + /** + * Whether the recipient requested to not receive any non-transactional messages + * Not required if a valid type is passed + * + * @deprecated Available, but deprecated in favor of type + * @type {boolean} + * @memberOf CreateSupressionListEntry + */ non_transactional?: boolean; + /** + * Source responsible for inserting the list entry + * no - entries created by the user are marked as Manually Added + * + * @type {("Spam Complaint" | "List Unsubscribe" | "Bounce Rule" | "Unsubscribe Link" | "Manually Added" | "Compliance")} + * @memberOf CreateSupressionListEntry + */ + readonly source?: "Spam Complaint" | "List Unsubscribe" | "Bounce Rule" | "Unsubscribe Link" | "Manually Added" | "Compliance"; /** Short explanation of the suppression */ description?: string; } export interface SupressionListEntry { + /** + * Email address to be suppressed + * + * @type {string} + * @memberOf SupressionListEntry + */ recipient: string; - /** Whether the recipient requested to not receive any transactional messages. At a minimum, transactional or non_transactional is required upon creation of the entry. */ + /** + * Whether the recipient requested to not receive any transactional messages + * Not required if a valid type is passed + * + * @deprecated Available, but deprecated in favor of type + * @type {boolean} + * @memberOf SupressionListEntry + */ transactional?: boolean; - /** Whether the recipient requested to not receive any non-transactional messages. At a minimum, transactional or non_transactional is required upon creation of the entry. */ + /** + * Whether the recipient requested to not receive any non-transactional messages + * Not required if a valid type is passed + * + * @deprecated Available, but deprecated in favor of type + * @type {boolean} + * @memberOf SupressionListEntry + */ non_transactional?: boolean; - /** Coming soon */ + /** Type of suppression record: transactional or non_transactional */ type?: "transactional" | "non_transactional"; - /** Source responsible for inserting the list entry. Valid values include: Spam Complaint, List Unsubscribe, Bounce Rule, Unsubscribe Link, Manually Added, Compliance. */ - source?: string; + /** + * Source responsible for inserting the list entry + * + * no - entries created by the user are marked as Manually Added + * + * @type {("Spam Complaint" | "List Unsubscribe" | "Bounce Rule" | "Unsubscribe Link" | "Manually Added" | "Compliance")} + * @memberOf SupressionListEntry + */ + source?: "Spam Complaint" | "List Unsubscribe" | "Bounce Rule" | "Unsubscribe Link" | "Manually Added" | "Compliance"; /** Short explanation of the suppression */ description?: string; created: string; updated: string; } - export interface SupressionSearch { + export interface SupressionSearchParameters { /** Datetime the entries were last updated, in the format of YYYY-MM-DDTHH:mm:ssZ */ to?: string; /** Datetime the entries were last updated, in the format YYYY-MM-DDTHH:mm:ssZ */ from?: string; + /** + * Domain of entries to include in the search. ( Note: SparkPost only) + * + * @type {string} + * @memberOf SupressionSearch + */ + domain?: string; + /** + * The results cursor location to return, to start paging with cursor, use the value of ‘initial’. + * When cursor is provided the page parameter is ignored. (Note: SparkPost only) + * + * @type {string} + * @memberOf SupressionSearch + */ + cursor?: string; + /** + * Maximum number of results to return per page. Must be between 1 and 10,000. + * ( Note: SparkPost only) + * @default 1000 + * @type {string} + * @memberOf SupressionSearch + */ + per_page?: string | number; + /** + * The results page number to return. Used with per_page for paging through results. + * The page parameter works up to 10,000 results. + * You must use the cursor parameter and start with cursor=initial to page result sets larger than 10,000 + * ( Note: SparkPost only) + * + * @type {string} + * @memberOf SupressionSearch + */ + page?: string | number; /** Types of entries to include in the search, i.e. entries with “transactional” and/or “non_transactional” keys set to true */ types?: string; /** Sources of the entries to include in the search, i.e. entries that were added by this source */ sources?: string; - /** Maximum number of results to return. Must be between 1 and 100000. Default value is 100000. */ + /** + * Description of the entries to include in the search, i.e descriptions that include the text submitted. + * ( Note: SparkPost only) + * + * @type {string} + * @memberOf SupressionSearch + */ + description?: string; + /** + * Maximum number of results to return per page. Must be between 1 and 10,000. + * @type {number} + * @deprecated use per_page instead + * @memberOf SupressionSearch + */ limit?: number; } diff --git a/sparkpost/sparkpost-tests.ts b/sparkpost/sparkpost-tests.ts index b940994c0a..46046c5e05 100644 --- a/sparkpost/sparkpost-tests.ts +++ b/sparkpost/sparkpost-tests.ts @@ -781,62 +781,169 @@ client.subaccounts.update('123', { console.log(err); }); -client.suppressionList.checkStatus("test@test.com", function(err, res) { +// Callback +client.suppressionList.delete('test@test.com', function(err, data) { if (err) { + console.log('Whoops! Something went wrong'); console.log(err); } else { - console.log(res.body); - console.log("Congrats you can use our client library!"); + console.log('Congrats you can use our client library!'); + console.log(data); } }); -client.suppressionList.removeStatus("test@test.com", function(err, res) { +// Promise +client.suppressionList.delete('test@test.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); +}); + +// Promise +client.suppressionList.get('test@test.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.suppressionList.get('test@test.com', function(err, data) { if (err) { + console.log('Whoops! Something went wrong'); console.log(err); } else { - console.log(res.body); - console.log("Congrats you can use our client library!"); + console.log('Congrats you can use our client library!'); + console.log(data); } }); -client.suppressionList.search({ - from: "2015-05-07T00:00:00+0000", - to: "2015-05-07T23:59:59+0000", - limit: 5 -}, function(err, res) { +// Promise +client.suppressionList.list({ + from: '2015-05-07T00:00:00+0000', + to: '2015-05-07T23:59:59+0000', + limit: 5 +}) + .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.suppressionList.list({ + from: '2015-05-07T00:00:00+0000', + to: '2015-05-07T23:59:59+0000', + limit: 5 +}, function(err, data) { if (err) { + console.log('Whoops! Something went wrong'); console.log(err); } else { - console.log(res.body); - console.log("Congrats you can use our client library!"); + console.log('Congrats you can use our client library!'); + console.log(data); } }); -client.suppressionList.upsert([ - { - recipient: "test1@test.com", +// Promise +client.suppressionList.upsert({ + recipient: 'test1@test.com', transactional: false, non_transactional: true, - description: "Test description 1" - }, - { - recipient: "test2@test.com", - transactional: true, + description: 'Test description 1' +}) + .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.suppressionList.upsert({ + recipient: 'test1@test.com', + transactional: false, non_transactional: true, - description: "Test description 2" - }, - { - recipient: "test3@test.com", - transactional: true, - non_transactional: false, - description: "Test description 3" - } -], function(err, res) { + description: 'Test description 1' +}, function(err, data) { if (err) { + console.log('Whoops! Something went wrong'); console.log(err); } else { - console.log(res.body); - console.log("Congrats you can use our client library!"); + console.log('Congrats you can use our client library!'); + console.log(data); + } +}); + +// Promise +client.suppressionList.upsert([ + { + recipient: 'test1@test.com', + transactional: false, + non_transactional: true, + description: 'Test description 1' + }, + { + recipient: 'test2@test.com', + transactional: true, + non_transactional: true, + description: 'Test description 2' + }, + { + recipient: 'test3@test.com', + transactional: true, + non_transactional: false, + description: 'Test description 3' + } +]) + .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.suppressionList.upsert([ + { + recipient: 'test1@test.com', + transactional: false, + non_transactional: true, + description: 'Test description 1' + }, + { + recipient: 'test2@test.com', + transactional: true, + non_transactional: true, + description: 'Test description 2' + }, + { + recipient: 'test3@test.com', + transactional: true, + non_transactional: false, + description: 'Test description 3' + } +], function(err, data) { + if (err) { + console.log('Whoops! Something went wrong'); + console.log(err); + } else { + console.log('Congrats you can use our client library!'); + console.log(data); } }); From a380d1788358d11107f7eb0d16c1eb625958b208 Mon Sep 17 00:00:00 2001 From: Akinmade Bond Date: Sun, 19 Mar 2017 02:29:24 +0100 Subject: [PATCH 08/19] update templates --- sparkpost/index.d.ts | 98 +++++++++++++++++++++--- sparkpost/sparkpost-tests.ts | 141 ++++++++++++++++++++++++++++------- 2 files changed, 200 insertions(+), 39 deletions(-) diff --git a/sparkpost/index.d.ts b/sparkpost/index.d.ts index 9c5eb5c2d0..5944495e1b 100644 --- a/sparkpost/index.d.ts +++ b/sparkpost/index.d.ts @@ -433,41 +433,119 @@ declare class SparkPost { * List a summary of all templates. * @param callback The request callback with TemplateMeta results array */ - all(callback: SparkPost.ResultsCallback): void; + list(callback: SparkPost.ResultsCallback): void; + /** + * List a summary of all templates. + * + * @returns {SparkPost.ResultsPromise} The TemplateMeta results array + */ + list(): SparkPost.ResultsPromise; /** * Retrieve details about a specified template by its id - * @param options The id and draft status information + * + * @param id the id of the template you want to look up + * @param options specifies a draft or published template * @param callback The request callback with Template results */ - find(options: { id: string, draft?: boolean }, callback: SparkPost.ResultsCallback): void; + get(id: string, options: { draft?: boolean }, callback: SparkPost.ResultsCallback): void; + /** + * Retrieve details about a specified template by its id + * + * @param {string} id the id of the template you want to look up + * @param {SparkPost.ResultsCallback} callback The request callback with Template results + */ + get(id: string, callback: SparkPost.ResultsCallback): void; + /** + * Retrieve details about a specified template by its id + * + * @param {string} id the id of the template you want to look up + * @param {{ draft?: boolean }} [options] specifies a draft or published template + * @returns {SparkPost.ResultsPromise} The Template results + */ + get(id: string, options?: { draft?: boolean }): SparkPost.ResultsPromise; /** * Create a new template - * @param options The create options + * + * @param template an object of [template attributes]{@link https://developers.sparkpost.com/api/templates#header-template-attributes} * @param callback The request callback with template id results */ - create(options: { template: SparkPost.CreateTemplate }, callback: SparkPost.ResultsCallback<{ id: string }>): void; + create(template: SparkPost.CreateTemplate, callback: SparkPost.ResultsCallback<{ id: string }>): void; + /** + * Create a new template + * + * @param {SparkPost.CreateTemplate} template an object of [template attributes]{@link https://developers.sparkpost.com/api/templates#header-template-attributes} + * @returns {SparkPost.ResultsPromise<{ id: string }>} The template id results + */ + create(template: SparkPost.CreateTemplate): SparkPost.ResultsPromise<{ id: string }>; /** * Update an existing template - * @param options The create options + * + * @param {string} id the id of the template you want to update + * @param template an object of [template attributes]{@link https://developers.sparkpost.com/api/templates#header-template-attributes} + * @param options The create options. If true, directly overwrite the existing published template. If false, create a new draft * @param callback The request callback with template id results */ - update(options: { - id: string, - template: SparkPost.UpdateTemplate, + update(id: string, template: SparkPost.UpdateTemplate, options: { update_published?: boolean; }, callback: SparkPost.ResultsCallback<{ id: string }>): void; + /** + * Update an existing template + * + * @param {string} id the id of the template you want to update + * @param {SparkPost.UpdateTemplate} template an object of [template attributes]{@link https://developers.sparkpost.com/api/templates#header-template-attributes} + * @param {SparkPost.ResultsCallback<{ id: string }>} callback The request callback with template id results + */ + update(id: string, template: SparkPost.UpdateTemplate, + callback: SparkPost.ResultsCallback<{ id: string }>): void; + /** + * Update an existing template + * + * @param {string} id the id of the template you want to update + * @param {SparkPost.UpdateTemplate} template an object of [template attributes]{@link https://developers.sparkpost.com/api/templates#header-template-attributes} + * @param {{ + * update_published?: boolean; + * }} [options] If true, directly overwrite the existing published template. If false, create a new draft + * @returns {SparkPost.ResultsPromise<{ id: string }>} The template id results + */ + update(id: string, template: SparkPost.UpdateTemplate, options?: { + update_published?: boolean; + }): SparkPost.ResultsPromise<{ id: string }>; /** * Delete an existing template * @param id The template id * @param callback The request callback */ delete(id: string, callback: SparkPost.Callback): void; + /** + * Delete an existing template + * + * @param id The template id + * @returns Promise void + */ + delete(id: string): Promise; /** * Preview the most recent version of an existing template by id + * + * @param {string} id the id of the template you want to look up * @param options The preview options * @param callback The request callback with webhook id results */ - preview(options: { id: string, data: any, draft?: boolean }, callback: SparkPost.ResultsCallback): void; + preview(id: string, options: { data: any, draft?: boolean }, callback: SparkPost.ResultsCallback): void; + /** + * Preview the most recent version of an existing template by id + * + * @param {string} id the id of the template you want to look up + * @param {SparkPost.ResultsCallback} callback The request callback with webhook id results + */ + preview(id: string, callback: SparkPost.ResultsCallback): void; + /** + * Preview the most recent version of an existing template by id + * + * @param {string} id the id of the template you want to look up + * @param {{ data: any, draft?: boolean }} [options] + * @returns {SparkPost.ResultsPromise} The webhook id results + */ + preview(id: string, options?: { data: any, draft?: boolean }): SparkPost.ResultsPromise; }; transmissions: { /** diff --git a/sparkpost/sparkpost-tests.ts b/sparkpost/sparkpost-tests.ts index 46046c5e05..1317083c60 100644 --- a/sparkpost/sparkpost-tests.ts +++ b/sparkpost/sparkpost-tests.ts @@ -947,8 +947,8 @@ client.suppressionList.upsert([ } }); +// Callback client.templates.create({ - template: { id: "TEST_ID", name: "Test Template", content: { @@ -956,7 +956,6 @@ client.templates.create({ subject: "Test email template!", html: "This is a test email template!" } - } }, function(err, res) { if (err) { console.log(err); @@ -966,6 +965,26 @@ client.templates.create({ } }); +// Promise +client.templates.create({ + id: 'TEST_ID', + name: 'Test Template', + content: { + from: 'test@test.com', + subject: 'Test email template!', + html: 'This is a test email template!' + } +}) + .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.templates.delete("TEST_ID", function(err, res) { if (err) { console.log(err); @@ -975,8 +994,19 @@ client.templates.delete("TEST_ID", function(err, res) { } }); +// Promise +client.templates.delete('TEST_ID') + .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.templates.all(function(err, res) { +// Callback +client.templates.list(function(err, res) { if (err) { console.log(err); } else { @@ -985,8 +1015,19 @@ client.templates.all(function(err, res) { } }); -client.templates.find({ - id: "TEST_ID", +// Promise +client.templates.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); +}); + +// Callback +client.templates.get('TEST_ID', { draft: true }, function(err, res) { if (err) { @@ -997,9 +1038,8 @@ client.templates.find({ } }); -client.templates.find({ - id: "TEST_ID" -}, function(err, res) { +// Callback +client.templates.get('TEST_ID', function(err, res) { if (err) { console.log(err); } else { @@ -1008,8 +1048,19 @@ client.templates.find({ } }); -client.templates.preview({ - id: "TEST_ID", +// Promise +client.templates.get('TEST_ID') + .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.templates.preview('TEST_ID', { data: {} }, function(err, res) { if (err) { @@ -1020,16 +1071,48 @@ client.templates.preview({ } }); -client.templates.update({ - id: "TEST_ID", - template: { +// Promise +client.templates.preview('TEST_ID', { + data: { + name: 'Natalie', + age: 35, + member: true + }, + draft: true +}) + .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.templates.update('TEST_ID', { content: { from: "test@test.com", subject: "Updated Published Test email template!", html: "This is a published test email template! Updated!" + }, +}, { update_published: true }, +function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +// Callback +client.templates.update('TEST_ID', { + content: { + from: "test@test.com", + subject: "Updated Test email template!", + html: "This is a test email template! Updated!" } - }, - update_published: true }, function(err, res) { if (err) { console.log(err); @@ -1039,23 +1122,23 @@ client.templates.update({ } }); -client.templates.update({ - id: "TEST_ID", - template: { +// Promise +client.templates.update('TEST_ID', { content: { - from: "test@test.com", - subject: "Updated Test email template!", - html: "This is a test email template! Updated!" + from: 'test@test.com', + subject: 'Updated Test email template!', + html: 'This is a test email template! Updated!' } - } -}, function(err, res) { - if (err) { +}) + .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); - } else { - console.log(res.body); - console.log("Congrats you can use our SDK!"); - } -}); + }); + client.transmissions.all(function(err, res) { if (err) { From 1e4cef0643c22c913d7d7526cdf3dc5f611f8f45 Mon Sep 17 00:00:00 2001 From: Akinmade Bond Date: Sun, 19 Mar 2017 03:09:02 +0100 Subject: [PATCH 09/19] update transmissions --- sparkpost/index.d.ts | 82 ++++++++++++++-- sparkpost/sparkpost-tests.ts | 177 +++++++++++++++++++++++++++++------ 2 files changed, 221 insertions(+), 38 deletions(-) diff --git a/sparkpost/index.d.ts b/sparkpost/index.d.ts index 5944495e1b..2fbdb6432b 100644 --- a/sparkpost/index.d.ts +++ b/sparkpost/index.d.ts @@ -550,31 +550,81 @@ declare class SparkPost { transmissions: { /** * List an overview of all transmissions in the account + * * @param callback The request callback with Transmission results array */ - all(callback: SparkPost.ResultsCallback): void; + list(callback: SparkPost.ResultsCallback): void; /** - * List an overview of all transmissions in the account, with added filters - * @param options The search options { campaign_id?, template_id? } - * @param callback The request callback with Transmission results array + * List an overview of all transmissions in the account + * + * @param {{ campaign_id?: string, template_id: string }} options + * @param {SparkPost.ResultsCallback} callback The request callback with Transmission results array */ - all(options: { campaign_id?: string, template_id?: string }, callback: SparkPost.ResultsCallback): void; + list(options: { campaign_id?: string, template_id?: string }, callback: SparkPost.ResultsCallback): void; + /** + * List an overview of all transmissions in the account + * + * @param {{ campaign_id?: string, template_id: string }} [options] + * @returns {SparkPost.ResultsPromise} The Transmission results array + */ + list(options?: { campaign_id?: string, template_id?: string }): SparkPost.ResultsPromise; /** * Retrieve the details about a transmission by its ID - * @param transmissionID The transmission id + * + * @param id The id of the transmission you want to look up * @param callback The request callback with Transmission results */ - find(transmissionID: string, callback: SparkPost.ResultsCallback): void; + get(transmissionID: string, callback: SparkPost.ResultsCallback): void; + /** + * Retrieve the details about a transmission by its ID + * + * @param {string} id The id of the transmission you want to look up + * @returns {SparkPost.ResultsPromise} The Transmission results + */ + get(id: string): SparkPost.ResultsPromise; /** * Sends a message by creating a new transmission - * @param options The create options + * + * @param transmission an object of [transmission attributes]{@link https://developers.sparkpost.com/api/transmissions#header-transmission-attributes} + * @param options The create options. Specify maximum number of recipient errors returned * @param callback The request callback with metadata and id results */ - send(options: { transmissionBody: SparkPost.CreateTransmission, num_rcpt_errors?: number }, callback: SparkPost.ResultsCallback<{ + send(transmission: SparkPost.CreateTransmission, options: { num_rcpt_errors?: number }, callback: SparkPost.ResultsCallback<{ total_rejected_recipients: number; total_accepted_recipients: number; id: string; }>): void; + /** + * + * + * @param {SparkPost.CreateTransmission} transmission an object of [transmission attributes]{@link https://developers.sparkpost.com/api/transmissions#header-transmission-attributes} + * @param {SparkPost.ResultsCallback<{ + * total_rejected_recipients: number; + * total_accepted_recipients: number; + * id: string; + * }>} callback The request callback with metadata and id results + */ + send(transmission: SparkPost.CreateTransmission, callback: SparkPost.ResultsCallback<{ + total_rejected_recipients: number; + total_accepted_recipients: number; + id: string; + }>): void; + /** + * Sends a message by creating a new transmission + * + * @param {SparkPost.CreateTransmission} transmission an object of [transmission attributes]{@link https://developers.sparkpost.com/api/transmissions#header-transmission-attributes} + * @param {{ num_rcpt_errors?: number }} [options] specify maximum number of recipient errors returned + * @returns {SparkPost.ResultsPromise<{ + * total_rejected_recipients: number; + * total_accepted_recipients: number; + * id: string; + * }>} The metadata and id results + */ + send(transmission: SparkPost.CreateTransmission, options?: { num_rcpt_errors?: number }): SparkPost.ResultsPromise<{ + total_rejected_recipients: number; + total_accepted_recipients: number; + id: string; + }>; }; webhooks: { /** @@ -1345,6 +1395,20 @@ declare namespace SparkPost { export interface CreateTransmission { /** JSON object in which transmission options are defined */ options?: TransmissionOptions; + /** + * Recipients to receive a carbon copy of the transmission + * + * @type {Recipient[]} + * @memberOf CreateTransmission + */ + cc?: Recipient[]; + /** + * Recipients to discreetly receive a carbon copy of the transmission + * + * @type {Recipient[]} + * @memberOf CreateTransmission + */ + bcc?: Recipient[]; /** Inline recipient objects or object containing stored recipient list ID */ recipients?: Recipient[] | { list_id: string }; /** Name of the campaign */ diff --git a/sparkpost/sparkpost-tests.ts b/sparkpost/sparkpost-tests.ts index 1317083c60..a64811cd24 100644 --- a/sparkpost/sparkpost-tests.ts +++ b/sparkpost/sparkpost-tests.ts @@ -1139,8 +1139,8 @@ client.templates.update('TEST_ID', { console.log(err); }); - -client.transmissions.all(function(err, res) { +// Callback +client.transmissions.list(function(err, res) { if (err) { console.log(err); } else { @@ -1149,16 +1149,17 @@ client.transmissions.all(function(err, res) { } }); -client.transmissions.find("YOUR-TRANSMISSION-KEY", function(err, res) { - if (err) { +// Promise +client.transmissions.list() + .then(data => { + console.log(data); + console.log('Congrats you can use our client library!'); + }) + .catch(err => { console.log(err); - } else { - console.log(res.body); - console.log("Congrats you can use our SDK!"); - } -}); + }); -client.transmissions.all({ +client.transmissions.list({ campaign_id: "my_campaign" }, function(err, res) { if (err) { @@ -1169,7 +1170,7 @@ client.transmissions.all({ } }); -client.transmissions.all({ +client.transmissions.list({ template_id: "my_template" }, function(err, res) { if (err) { @@ -1180,8 +1181,29 @@ client.transmissions.all({ } }); +// Callback +client.transmissions.get("YOUR-TRANSMISSION-KEY", function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +// Promise +client.transmissions.get('YOUR-TRANSMISSION-KEY') + .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.transmissions.send({ - transmissionBody: { recipients: [{ address: { email: "john.doe@example.com" } }], content: { from: "From Envelope ", @@ -1193,7 +1215,6 @@ client.transmissions.send({ open_tracking: true, click_tracking: true } - } }, function(err, res) { if (err) { console.log(err); @@ -1203,13 +1224,12 @@ client.transmissions.send({ } }); +// Callback client.transmissions.send({ - transmissionBody: { recipients: [{address: {email: "john.doe@example.com"}}], content: { email_rfc822: "Content-Type: text/plain\nFrom: From Envelope \nSubject: Example Email\n\nHello World" } - } }, function(err, res) { if (err) { console.log(err); @@ -1219,8 +1239,8 @@ client.transmissions.send({ } }); +// Callback client.transmissions.send({ - transmissionBody: { options: { open_tracking: true, click_tracking: true @@ -1266,8 +1286,7 @@ client.transmissions.send({ }, text: "Hi {{address.name}} \nSave big this Christmas in your area {{place}}! \nClick http://www.mysite.com and get huge discount\n Hurry, this offer is only to {{customer_type}}\n {{sender}}", html: "

Hi {{address.name}} \nSave big this Christmas in your area {{place}}! \nClick http://www.mysite.com and get huge discount\n

Hurry, this offer is only to {{customer_type}}\n

{{sender}}

" - } - } + } }, function(err, res) { if (err) { console.log(err); @@ -1277,8 +1296,8 @@ client.transmissions.send({ } }); +// Callback client.transmissions.send({ - transmissionBody: { recipients: [ { address: { @@ -1308,7 +1327,6 @@ client.transmissions.send({ text: "An example email using bcc with SparkPost to the {{recipient_type}} recipient.", html: "

An example email using bcc with SparkPost to the {{recipient_type}} recipient.

" } - } }, function(err, res) { if (err) { console.log(err); @@ -1318,8 +1336,8 @@ client.transmissions.send({ } }); +// Callback client.transmissions.send({ - transmissionBody: { recipients: [ { address: { @@ -1353,7 +1371,6 @@ client.transmissions.send({ text: "An example email using cc with SparkPost to the {{recipient_type}} recipient.", html: "

An example email using cc with SparkPost to the {{recipient_type}} recipient.

" } - } }, function(err, res) { if (err) { console.log(err); @@ -1363,8 +1380,8 @@ client.transmissions.send({ } }); +// Callback client.transmissions.send({ - transmissionBody: { recipients: { list_id: "example-list" }, @@ -1374,7 +1391,6 @@ client.transmissions.send({ html: "

Hello World

", text: "Hello World!" } - } }, function(err, res) { if (err) { console.log(err); @@ -1384,8 +1400,8 @@ client.transmissions.send({ } }); +// Callback client.transmissions.send({ - transmissionBody: { recipients: { list_id: "example-list" }, @@ -1394,7 +1410,6 @@ client.transmissions.send({ subject: "Example Email for Stored List and Template", template_id: "my-template" } - } }, function(err, res) { if (err) { console.log(err); @@ -1404,15 +1419,15 @@ client.transmissions.send({ } }); +// Callback client.transmissions.send({ - num_rcpt_errors: 3, - transmissionBody: { campaign_id: "ricks-campaign", content: { template_id: "ricks-template" }, recipients: [{ address: { email: "rick.sanchez@rickandmorty100years.com", name: "Rick Sanchez" } }] - } +}, { + num_rcpt_errors: 3 }, function(err, res) { if (err) { console.log(err); @@ -1422,6 +1437,110 @@ client.transmissions.send({ } }); + +// Promise +client.transmissions.send({ + options: { + open_tracking: true, + click_tracking: true + }, + campaign_id: 'christmas_campaign', + metadata: { + user_type: 'students' + }, + substitution_data: { + sender: 'Big Store Team' + }, + cc: [], + bcc: [], + recipients: [ + { + address: { + email: 'wilma@flintstone.com', + name: 'Wilma Flintstone' + }, + tags: [ + 'greeting', + 'prehistoric', + 'fred', + 'flintstone' + ], + metadata: { + place: 'Bedrock' + }, + substitution_data: { + customer_type: 'Platinum' + } + } + ], + content: { + from: { + name: 'Fred Flintstone', + email: 'fred@flintstone.com' + }, + subject: 'Big Christmas savings!', + reply_to: 'Christmas Sales ', + headers: { + 'X-Customer-Campaign-ID': 'christmas_campaign' + }, + text: 'Hi {{address.name}} \nSave big this Christmas in your area {{place}}! \nClick http://www.mysite.com and get huge discount\n Hurry, this offer is only to {{customer_type}}\n {{sender}}', + html: '

Hi {{address.name}} \nSave big this Christmas in your area {{place}}! \nClick http://www.mysite.com and get huge discount\n

Hurry, this offer is only to {{customer_type}}\n

{{sender}}

' + } +}) + .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); +}); + +// Promise +client.transmissions.send({ + recipients: [ + { + address: { + email: 'original.recipient@example.com', + name: 'Original Recipient' + }, + substitution_data: { + recipient_type: 'Original' + } + }, + { + address: { + email: 'cc.recipient@example.com', + name: 'Carbon Copy Recipient', + header_to: '"Original Recipient" ' + }, + substitution_data: { + recipient_type: 'CC' + } + } + ], + content: { + from: { + name: 'Node CC Test', + email: 'from@example.com' + }, + headers: { + 'CC': '"Carbon Copy Recipient" ' + }, + subject: 'Example email using cc', + text: 'An example email using cc with SparkPost to the {{recipient_type}} recipient.', + html: '

An example email using cc with SparkPost to the {{recipient_type}} recipient.

' + } +}) + .then(data => { + console.log('Congrats! You sent an email with cc using SparkPost!'); + console.log(data); + }) + .catch(err => { + console.log('Whoops! Something went wrong'); + console.log(err); +}); + client.webhooks.create({ name: "Test webhook", target: "http://client.test.com/test-webhook", From 3f70f8ae6a668a5de78d4abaf428f807c83f888b Mon Sep 17 00:00:00 2001 From: Akinmade Bond Date: Sun, 19 Mar 2017 04:20:42 +0100 Subject: [PATCH 10/19] update webhooks --- sparkpost/index.d.ts | 154 +++++++++++++++++++++++++++++++--- sparkpost/sparkpost-tests.ts | 156 ++++++++++++++++++++++++++++++++--- 2 files changed, 285 insertions(+), 25 deletions(-) diff --git a/sparkpost/index.d.ts b/sparkpost/index.d.ts index 2fbdb6432b..63c0d83bb2 100644 --- a/sparkpost/index.d.ts +++ b/sparkpost/index.d.ts @@ -631,43 +631,93 @@ declare class SparkPost { * List currently existing webhooks. * @param callback The request callback with RelayWebhook results array */ - all(callback: SparkPost.ResultsCallback>): void; + list(callback: SparkPost.ResultsCallback>): void; /** * List currently existing webhooks. * @param options Object containing optional timezone * @param callback The request callback with RelayWebhook results array */ - all(options: { timezone?: string }, callback: SparkPost.ResultsCallback>): void; + list(options: { timezone?: string }, callback: SparkPost.ResultsCallback>): void; + /** + * List currently existing webhooks.the timezone to use for the last_successful and last_failure properties | Default: UTC + * + * @param {{ timezone?: string }} [options] + * @returns {(SparkPost.ResultsPromise>)} + */ + list(options?: { timezone?: string }): SparkPost.ResultsPromise>; /** * Retrieve details about a specified webhook by its id + * + * @param {string} id The id of the webhook to get * @param options Object containing id and optional timezone * @param callback The request callback with RelayWebhook results */ - describe(options: { id: string, timezone?: string }, callback: SparkPost.ResultsCallback): void; + get(id: string, options: { timezone?: string }, callback: SparkPost.ResultsCallback): void; + /** + * Retrieve details about a specified webhook by its id + * + * @param {string} id The id of the webhook to get + * @param {(SparkPost.ResultsCallback)} callback The request callback with RelayWebhook results + */ + get(id: string, callback: SparkPost.ResultsCallback): void; + /** + * Retrieve details about a specified webhook by its id + * + * @param {string} id The id of the webhook to get + * @param {{ timezone?: string }} [options] the timezone to use for the last_successful and last_failure properties + * @returns {(SparkPost.ResultsPromise)} The RelayWebhook results + */ + get(id: string, options?: { timezone?: string }): SparkPost.ResultsPromise; /** * Create a new webhook - * @param options The create options + * + * @param options a hash of [webhook attributes]{@link https://developers.sparkpost.com/api/webhooks#header-webhooks-object-properties} * @param callback The request callback with webhook id results */ create(options: SparkPost.Webhook, callback: SparkPost.ResultsCallback): void; + /** + * Create a new webhook + * + * @param {SparkPost.Webhook} options a hash of [webhook attributes]{@link https://developers.sparkpost.com/api/webhooks#header-webhooks-object-properties} + * @returns {(SparkPost.ResultsPromise)} The webhook id results + */ + create(options: SparkPost.Webhook): SparkPost.ResultsPromise; /** * Update an existing webhook - * @param options The update options + * @param {string} id the id of the webhook to update + * @param options A hash of [webhook attribues]{@link https://developers.sparkpost.com/api/webhooks#header-webhooks-object-properties} * @param callback The request callback with webhook id results */ - update(options: SparkPost.UpdateWebhook, callback: SparkPost.ResultsCallback): void; + update(id: string, options: SparkPost.UpdateWebhook, callback: SparkPost.ResultsCallback): void; + /** + * Update an existing webhook + * + * @param {string} id + * @param {SparkPost.UpdateWebhook} options + * @returns {(SparkPost.ResultsPromise)} + */ + update(id: string, options: SparkPost.UpdateWebhook): SparkPost.ResultsPromise; /** * Delete an existing webhook * @param id The webhook id * @param callback The request callback */ delete(id: string, callback: SparkPost.Callback): void; + /** + * Delete an existing webhook. + * + * @param {string} id The id of the webhook to delete + * @returns {Promise} + */ + delete(id: string): Promise; /** * Sends an example message event batch from the Webhook API to the target URL - * @param options The webhook id and message + * + * @param {string} id The id of the webhook to validate + * @param options the message (payload) to send to the webhook consumer * @param callback The request callback with validation results */ - validate(options: { id: string, message: any }, callback: SparkPost.ResultsCallback<{ + validate(id: string, options: { message: any }, callback: SparkPost.ResultsCallback<{ msg: string; response: { status: number; @@ -676,21 +726,86 @@ declare class SparkPost { } }>): void; /** - * Sends an example message event batch from the Webhook API to the target URL - * @param options The webhook id and optional limit + * Sends an example message event batch from the Webhook API to the target URL. + * + * @param {string} id The id of the webhook to validate + * @param {{ message: any }} options The message (payload) to send to the webhook consumer + * @returns {SparkPost.ResultsPromise<{ + * msg: string; + * response: { + * status: number; + * headers: any; + * body: string; + * } + * }>} The validation results + */ + validate(id: string, options: { message: any }): SparkPost.ResultsPromise<{ + msg: string; + response: { + status: number; + headers: any; + body: string; + } + }>; + /** + * Gets recent status information about a webhook. + * + * @param {string} id The id of the webhook + * @param options An optional limit that specifies the maximum number of results to return. Defaults to 1000 * @param callback The request callback with status results */ - getBatchStatus(options: { id: string, limit?: number }, callback: SparkPost.ResultsCallback<{ + getBatchStatus(id: string, options: { limit?: number }, callback: SparkPost.ResultsCallback<{ batch_id: string; ts: string; attempts: number; response_code: number; }[]>): void; + /** + * Gets recent status information about a webhook. + * + * @param {string} id The id of the webhook + * @param {SparkPost.ResultsCallback<{ + * batch_id: string; + * ts: string; + * attempts: number; + * response_code: number; + * }[]>} callback The request callback with status results + */ + getBatchStatus(id: string, callback: SparkPost.ResultsCallback<{ + batch_id: string; + ts: string; + attempts: number; + response_code: number; + }[]>): void; + /** + * Gets recent status information about a webhook. + * + * @param {string} id The id of the webhook + * @param {{ limit?: number }} Maximum number of results to return. Defaults to 1000 + * @returns {SparkPost.ResultsPromise<{ + * batch_id: string; + * ts: string; + * attempts: number; + * response_code: number; + * }[]>} The status results + */ + getBatchStatus(id: string, options: { limit?: number }): SparkPost.ResultsPromise<{ + batch_id: string; + ts: string; + attempts: number; + response_code: number; + }[]>; /** * 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 */ getDocumentation(callback: SparkPost.ResultsCallback): void; + /** + * Lists descriptions of the events, event types, and event fields that could be included in a Webhooks post to your target URL. + * + * @returns {SparkPost.ResultsPromise} The documentation results + */ + getDocumentation(): SparkPost.ResultsPromise; /** * List an example of the event data that will be posted by a Webhook for the specified events. * @param callback The request callback containing examples @@ -702,6 +817,13 @@ declare class SparkPost { * @param callback The request callback containing examples */ getSamples(options: { events?: string }, callback: SparkPost.Callback): void; + /** + * List an example of the event data that will be posted by a Webhook for the specified events. + * + * @param {{ events?: string }} options [event types]{@link https://support.sparkpost.com/customer/portal/articles/1976204} for which to get a sample payload | Default: all event types returned + * @returns {Promise>} + */ + getSamples(options?: { events?: string }): Promise>; }; /** @@ -1528,6 +1650,14 @@ declare namespace SparkPost { target: string; /** Array of event types this webhook will receive */ events: string[]; + /** + * Reserved for future use + * + * @default {true} + * @type {boolean} + * @memberOf Webhook + */ + active?: boolean; /** Type of authentication to be used during POST requests to target */ auth_type?: string; /** Object containing details needed to request authorization credentials, as necessary */ @@ -1539,13 +1669,13 @@ declare namespace SparkPost { } export interface UpdateWebhook { - id: string; /** User-friendly name for webhook */ name?: string; /** URL of the target to which to POST event batches */ target?: string; /** Array of event types this webhook will receive */ events?: string[]; + active?: boolean; /** Type of authentication to be used during POST requests to target */ auth_type?: string; /** Object containing details needed to request authorization credentials, as necessary */ diff --git a/sparkpost/sparkpost-tests.ts b/sparkpost/sparkpost-tests.ts index a64811cd24..de025997b5 100644 --- a/sparkpost/sparkpost-tests.ts +++ b/sparkpost/sparkpost-tests.ts @@ -1541,6 +1541,7 @@ client.transmissions.send({ console.log(err); }); +// Callback client.webhooks.create({ name: "Test webhook", target: "http://client.test.com/test-webhook", @@ -1560,6 +1561,28 @@ client.webhooks.create({ } }); +// Promise +client.webhooks.create({ + name: 'Test Webhook', + target: 'http://client.test.com/test-webhook', + auth_token: 'AUTH_TOKEN', + events: [ + 'delivery', + 'injection', + 'open', + 'click' + ] +}) + .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.webhooks.delete("TEST_WEBHOOK_UUID", function(err, res) { if (err) { console.log(err); @@ -1569,20 +1592,45 @@ client.webhooks.delete("TEST_WEBHOOK_UUID", function(err, res) { } }); -client.webhooks.describe({ - id: "TEST_WEBHOOK_UUID", - timezone: "America/New_York" -}, function(err, res) { +// Promise +client.webhooks.delete('TEST_WEBHOOK_UUID') + .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.webhooks.get('TEST_WEBHOOK_UUID', { + timezone: 'America/New_York' +}, function(err, data) { if (err) { + console.log('Whoops! Something went wrong'); console.log(err); } else { - console.log(res.body); - console.log("Congrats you can use our SDK!"); + console.log('Congrats you can use our client library!'); + console.log(data); } }); -client.webhooks.getBatchStatus({ - id: "TEST_WEBHOOK_UUID", +// Promise +client.webhooks.get('TEST_WEBHOOK_UUID', { + timezone: 'America/New_York' +}) + .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.webhooks.getBatchStatus('TEST_WEBHOOK_UUID', { limit: 1000 }, function(err, res) { if (err) { @@ -1593,7 +1641,20 @@ client.webhooks.getBatchStatus({ } }); +// Promise +client.webhooks.getBatchStatus('TEST_WEBHOOK_UUID', { + limit: 1000 +}) + .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.webhooks.getDocumentation(function(err, res) { if (err) { console.log(err); @@ -1603,6 +1664,18 @@ client.webhooks.getDocumentation(function(err, res) { } }); +// Promise +client.webhooks.getDocumentation() + .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.webhooks.getSamples({ events: "bounce" }, function(err, res) { @@ -1614,7 +1687,21 @@ client.webhooks.getSamples({ } }); -client.webhooks.all(function(err, res) { +// Promise +client.webhooks.getSamples({ + events: 'bounce' +}) + .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.webhooks.list(function(err, res) { if (err) { console.log(err); } else { @@ -1623,8 +1710,19 @@ client.webhooks.all(function(err, res) { } }); -client.webhooks.update({ - id: "TEST_WEBHOOK_UUID", +// Promise +client.webhooks.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); +}); + +// Callback +client.webhooks.update('TEST_WEBHOOK_UUID', { name: "Renamed Test webhook", events: [ "policy_rejection", @@ -1639,8 +1737,25 @@ client.webhooks.update({ } }); -client.webhooks.validate({ - id: "TEST_WEBHOOK_UUID", +// Promise +client.webhooks.update('TEST_WEBHOOK_UUID', { + name: 'Renamed Test Webhook', + events: [ + 'policy_rejection', + 'delay' + ] +}) + .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.webhooks.validate('TEST_WEBHOOK_UUID',{ message: { msys: {} } @@ -1652,3 +1767,18 @@ client.webhooks.validate({ console.log("Congrats you can use our SDK!"); } }); + +// Promise +client.webhooks.validate('TEST_WEBHOOK_UUID', { + message: { + msys: {} + } +}) + .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); + }); From 8295ee65d76ed45dea0c6d75d68c84f70104e340 Mon Sep 17 00:00:00 2001 From: Akinmade Bond Date: Sun, 19 Mar 2017 04:28:28 +0100 Subject: [PATCH 11/19] update Constructor --- sparkpost/index.d.ts | 5 +++++ sparkpost/sparkpost-tests.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/sparkpost/index.d.ts b/sparkpost/index.d.ts index 63c0d83bb2..4bd777f933 100644 --- a/sparkpost/index.d.ts +++ b/sparkpost/index.d.ts @@ -834,10 +834,15 @@ declare class SparkPost { constructor(apiKey?: string, options?: SparkPost.ConstructorOptions); request(options: Request.Options, callback: SparkPost.Callback): void; + request(options: Request.Options): Promise>; get(options: Request.Options, callback: SparkPost.Callback): void; + get(options: Request.Options): Promise>; post(options: Request.Options, callback: SparkPost.Callback): void; + post(options: Request.Options): Promise>; put(options: Request.Options, callback: SparkPost.Callback): void; + put(options: Request.Options): Promise>; delete(options: Request.Options, callback: SparkPost.Callback): void; + delete(options: Request.Options): Promise>; } declare namespace SparkPost { diff --git a/sparkpost/sparkpost-tests.ts b/sparkpost/sparkpost-tests.ts index de025997b5..0f43e41832 100644 --- a/sparkpost/sparkpost-tests.ts +++ b/sparkpost/sparkpost-tests.ts @@ -3,6 +3,7 @@ import * as SparkPost from "sparkpost"; let key = "YOURAPIKEY"; let client = new SparkPost(key); +// Callback client.get({ uri: "metrics/domains" }, function(err, data) { @@ -14,6 +15,17 @@ client.get({ console.log(data.body); }); +// Promise +client.get({ + uri: 'metrics/domains' +}) + .then(data => { + console.log(data); + }) + .catch(err => { + console.log(err); + }); + // Callback client.inboundDomains.create({ domain: 'example1.com' }, function(err, res) { if (err) { From 704f68a26bf038bf661ce96e34561e8800d47b65 Mon Sep 17 00:00:00 2001 From: Akinmade Bond Date: Sun, 19 Mar 2017 05:43:43 +0100 Subject: [PATCH 12/19] Add Tests Add tslint.json file to enable tests. Only Arrow function config is truned off. --- sparkpost/index.d.ts | 74 +++++++++++++++++++++++++++++++----- sparkpost/sparkpost-tests.ts | 22 +++++------ sparkpost/tsconfig.json | 4 +- sparkpost/tslint.json | 8 ++++ 4 files changed, 85 insertions(+), 23 deletions(-) create mode 100644 sparkpost/tslint.json diff --git a/sparkpost/index.d.ts b/sparkpost/index.d.ts index 4bd777f933..56b23382fa 100644 --- a/sparkpost/index.d.ts +++ b/sparkpost/index.d.ts @@ -3,7 +3,6 @@ // Definitions by: Joshua DeVinney // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// /// import * as Request from "request"; @@ -820,7 +819,8 @@ declare class SparkPost { /** * List an example of the event data that will be posted by a Webhook for the specified events. * - * @param {{ events?: string }} options [event types]{@link https://support.sparkpost.com/customer/portal/articles/1976204} for which to get a sample payload | Default: all event types returned + * @param {{ events?: string }} options [event types]{@link https://support.sparkpost.com/customer/portal/articles/1976204} for which to get a sample payload + * Default: all event types returned * @returns {Promise>} */ getSamples(options?: { events?: string }): Promise>; @@ -1035,9 +1035,21 @@ declare namespace SparkPost { address: Address | string; } export interface RecipientWithMultichannelAddresses { - /** Address information for a recipient. At a minimum, address or multichannel_addresses is required. If both address and multichannel_addresses are specified only multichannel_addresses will be used. */ + /** + * Address information for a recipient. At a minimum, address or multichannel_addresses is required. + * If both address and multichannel_addresses are specified only multichannel_addresses will be used. + * + * @type {(Address | string)} + * @memberOf RecipientWithMultichannelAddresses + */ address?: Address | string; - /** Array of Multichannel Address objects for a recipient. At a minimum, address or multichannel_addresses is required. If both address and multichannel_addresses are specified only multichannel_addresses will be used. */ + /** + * Array of Multichannel Address objects for a recipient. At a minimum, address or multichannel_addresses is required. + * If both address and multichannel_addresses are specified only multichannel_addresses will be used. + * + * @type {MultichannelAddress[]} + * @memberOf RecipientWithMultichannelAddresses + */ multichannel_addresses: MultichannelAddress[]; } export type Recipient = (RecipientWithAddress | RecipientWithMultichannelAddresses) & BaseRecipient; @@ -1420,7 +1432,13 @@ declare namespace SparkPost { text: string; /** Email subject line. */ subject: string; - /** Address “from” : "deals@company.com" or JSON object composed of the “name” and “email” fields “from” : { “name” : “My Company”, “email” : "deals@company.com" } used to compose the email’s “From” header. */ + /** + * Address "from" : "deals@company.com" or JSON object composed of the "name" and "email" fields. + * "from" : { "name" : "My Company", "email" : "deals@company.com" } used to compose the email’s "From" header. + * + * @type {(Address | string)} + * @memberOf TemplateContent + */ from: Address | string; /** Email address used to compose the email’s “Reply-To” header. */ reply_to?: string; @@ -1435,7 +1453,13 @@ declare namespace SparkPost { text?: string; /** Email subject line. */ subject: string; - /** Address “from” : "deals@company.com" or JSON object composed of the “name” and “email” fields “from” : { “name” : “My Company”, “email” : "deals@company.com" } used to compose the email’s “From” header. */ + /** + * Address "from" : "deals@company.com" or JSON object composed of the "name" and "email" fields. + * "from" : { "name" : "My Company", "email" : "deals@company.com" } used to compose the email’s "From" header. + * + * @type {(Address | string)} + * @memberOf TemplateContent + */ from: Address | string; /** Email address used to compose the email’s “Reply-To” header. */ reply_to?: string; @@ -1455,7 +1479,15 @@ declare namespace SparkPost { } export interface Template { - /** Short, unique, alphanumeric ID used to reference the template At a minimum, id or name is required upon creation. It is auto generated if not provided. After a template has been created, this property cannot be changed. Maximum length - 64 bytes */ + /** + * Short, unique, alphanumeric ID used to reference the template. + * At a minimum, id or name is required upon creation. + * It is auto generated if not provided. + * After a template has been created, this property cannot be changed. Maximum length - 64 bytes + * + * @type {string} + * @memberOf Template + */ id: string; /** Content that will be used to construct a message yes For a full description, see the Content Attributes. Maximum length - 20 MBs */ content: TemplateContent | { email_rfc822: string }; @@ -1474,7 +1506,15 @@ declare namespace SparkPost { } export interface CreateTemplate { - /** Short, unique, alphanumeric ID used to reference the template At a minimum, id or name is required upon creation. It is auto generated if not provided. After a template has been created, this property cannot be changed. Maximum length - 64 bytes */ + /** + * Short, unique, alphanumeric ID used to reference the template. + * At a minimum, id or name is required upon creation. + * It is auto generated if not provided. + * After a template has been created, this property cannot be changed. Maximum length - 64 bytes + * + * @type {string} + * @memberOf CreateTemplate + */ id?: string; /** Content that will be used to construct a message yes For a full description, see the Content Attributes. Maximum length - 20 MBs */ content: CreateTemplateContent | { email_rfc822: string }; @@ -1640,11 +1680,25 @@ declare namespace SparkPost { } export interface Attachment { - /** The MIME type of the attachment; e.g., “text/plain”, “image/jpeg”, “audio/mp3”, “video/mp4”, “application/msword”, “application/pdf”, etc., including the “charset” parameter (text/html; charset=“UTF-8”) if needed. The value will apply “as-is” to the “Content-Type” header of the generated MIME part for the attachment. */ + /** + * The MIME type of the attachment; e.g., “text/plain”, “image/jpeg”, “audio/mp3”, “video/mp4”, “application/msword”, “application/pdf”, etc., + * including the “charset” parameter (text/html; charset=“UTF-8”) if needed. + * The value will apply “as-is” to the “Content-Type” header of the generated MIME part for the attachment. + * + * @type {string} + * @memberOf Attachment + */ type: string; /** The filename of the attachment (for example, “document.pdf”). This is inserted into the filename parameter of the Content-Disposition header. */ name: string; - /** The content of the attachment as a Base64 encoded string. The string should not contain \r\n line breaks. The SparkPost systems will add line breaks as necessary to ensure the Base64 encoded lines contain no more than 76 characters each. */ + /** + * The content of the attachment as a Base64 encoded string. + * The string should not contain \r\n line breaks. + * The SparkPost systems will add line breaks as necessary to ensure the Base64 encoded lines contain no more than 76 characters each. + * + * @type {string} + * @memberOf Attachment + */ data: string; } diff --git a/sparkpost/sparkpost-tests.ts b/sparkpost/sparkpost-tests.ts index 0f43e41832..ac994ab31b 100644 --- a/sparkpost/sparkpost-tests.ts +++ b/sparkpost/sparkpost-tests.ts @@ -516,8 +516,8 @@ client.relayWebhooks.update('123456789', { client.sendingDomains.create({ domain: "example1.com", dkim: { - "private": "MIICXgIBAAKBgQC+W6scd3XWwvC/hPRksfDYFi3ztgyS9OSqnnjtNQeDdTSD1DRx/xFar2wjmzxp2+SnJ5pspaF77VZveN3P/HVmXZVghr3asoV9WBx/uW1nDIUxU35L4juXiTwsMAbgMyh3NqIKTNKyMDy4P8vpEhtH1iv/BrwMdBjHDVCycB8WnwIDAQABAoGBAITb3BCRPBi5lGhHdn+1RgC7cjUQEbSb4eFHm+ULRwQ0UIPWHwiVWtptZ09usHq989fKp1g/PfcNzm8c78uTS6gCxfECweFCRK6EdO6cCCr1cfWvmBdSjzYhODUdQeyWZi2ozqd0FhGWoV4VHseh4iLj36DzleTLtOZj3FhAo1WJAkEA68T+KkGeDyWwvttYtuSiQCCTrXYAWTQnkIUxduCp7Ap6tVeIDn3TaXTj74UbEgaNgLhjG4bX//fdeDW6PaK9YwJBAM6xJmwHLPMgwNVjiz3u/6fhY3kaZTWcxtMkXCjh1QE82KzDwqyrCg7EFjTtFysSHCAZxXZMcivGl4TZLHnydJUCQQCx16+M+mAatuiCnvxlQUMuMiSTNK6Amzm45u9v53nlZeY3weYMYFdHdfe1pebMiwrT7MI9clKebz6svYJVmdtXAkApDAc8VuR3WB7TgdRKNWdyGJGfoD1PO1ZE4iinOcoKV+IT1UCY99Kkgg6C7j62n/8T5OpRBvd5eBPpHxP1F9BNAkEA5Nf2VO9lcTetksHdIeKK+F7sio6UZn0Rv7iUo3ALrN1D1cGfWIh2dj3ko1iSreyNVSwGW0ePP27qDmU+u6/Y1g==", - "public": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+W6scd3XWwvC/hPRksfDYFi3ztgyS9OSqnnjtNQeDdTSD1DRx/xFar2wjmzxp2+SnJ5pspaF77VZveN3P/HVmXZVghr3asoV9WBx/uW1nDIUxU35L4juXiTwsMAbgMyh3NqIKTNKyMDy4P8vpEhtH1iv/BrwMdBjHDVCycB8WnwIDAQAB", + "private": "MIICXgIBAAKBgQC+W6scd3XWwvC/hPRksfDYFi3ztgyS9OSqnnjtNQeDdTSD1DRx/==", + "public": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+W6scd3XWwvC/==", selector: "brisbane", headers: "from:to:subject:date" } @@ -534,8 +534,8 @@ client.sendingDomains.create({ client.sendingDomains.create({ domain: 'example1.com', dkim: { - 'private': 'MIICXgIBAAKBgQC+W6scd3XWwvC/hPRksfDYFi3ztgyS9OSqnnjtNQeDdTSD1DRx/xFar2wjmzxp2+SnJ5pspaF77VZveN3P/HVmXZVghr3asoV9WBx/uW1nDIUxU35L4juXiTwsMAbgMyh3NqIKTNKyMDy4P8vpEhtH1iv/BrwMdBjHDVCycB8WnwIDAQABAoGBAITb3BCRPBi5lGhHdn+1RgC7cjUQEbSb4eFHm+ULRwQ0UIPWHwiVWtptZ09usHq989fKp1g/PfcNzm8c78uTS6gCxfECweFCRK6EdO6cCCr1cfWvmBdSjzYhODUdQeyWZi2ozqd0FhGWoV4VHseh4iLj36DzleTLtOZj3FhAo1WJAkEA68T+KkGeDyWwvttYtuSiQCCTrXYAWTQnkIUxduCp7Ap6tVeIDn3TaXTj74UbEgaNgLhjG4bX//fdeDW6PaK9YwJBAM6xJmwHLPMgwNVjiz3u/6fhY3kaZTWcxtMkXCjh1QE82KzDwqyrCg7EFjTtFysSHCAZxXZMcivGl4TZLHnydJUCQQCx16+M+mAatuiCnvxlQUMuMiSTNK6Amzm45u9v53nlZeY3weYMYFdHdfe1pebMiwrT7MI9clKebz6svYJVmdtXAkApDAc8VuR3WB7TgdRKNWdyGJGfoD1PO1ZE4iinOcoKV+IT1UCY99Kkgg6C7j62n/8T5OpRBvd5eBPpHxP1F9BNAkEA5Nf2VO9lcTetksHdIeKK+F7sio6UZn0Rv7iUo3ALrN1D1cGfWIh2dj3ko1iSreyNVSwGW0ePP27qDmU+u6/Y1g==', - 'public': 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+W6scd3XWwvC/hPRksfDYFi3ztgyS9OSqnnjtNQeDdTSD1DRx/xFar2wjmzxp2+SnJ5pspaF77VZveN3P/HVmXZVghr3asoV9WBx/uW1nDIUxU35L4juXiTwsMAbgMyh3NqIKTNKyMDy4P8vpEhtH1iv/BrwMdBjHDVCycB8WnwIDAQAB', + 'private': 'MIICXgIBAAKBgQC+W6scd3XWwvC/hPRksfDYFi3ztgyS9OSqnnjtNQeDdTSD1DRx/==', + 'public': 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+W6scd3XWwvC/==', selector: 'brisbane', headers: 'from:to:subject:date' } @@ -615,8 +615,8 @@ client.sendingDomains.get('example1.com') // Callback client.sendingDomains.update('example1.com', { dkim: { - "private": "MIICXgIBAAKBgQC+W6scd3XWwvC/hPRksfDYFi3ztgyS9OSqnnjtNQeDdTSD1DRx/xFar2wjmzxp2+SnJ5pspaF77VZveN3P/HVmXZVghr3asoV9WBx/uW1nDIUxU35L4juXiTwsMAbgMyh3NqIKTNKyMDy4P8vpEhtH1iv/BrwMdBjHDVCycB8WnwIDAQABAoGBAITb3BCRPBi5lGhHdn+1RgC7cjUQEbSb4eFHm+ULRwQ0UIPWHwiVWtptZ09usHq989fKp1g/PfcNzm8c78uTS6gCxfECweFCRK6EdO6cCCr1cfWvmBdSjzYhODUdQeyWZi2ozqd0FhGWoV4VHseh4iLj36DzleTLtOZj3FhAo1WJAkEA68T+KkGeDyWwvttYtuSiQCCTrXYAWTQnkIUxduCp7Ap6tVeIDn3TaXTj74UbEgaNgLhjG4bX//fdeDW6PaK9YwJBAM6xJmwHLPMgwNVjiz3u/6fhY3kaZTWcxtMkXCjh1QE82KzDwqyrCg7EFjTtFysSHCAZxXZMcivGl4TZLHnydJUCQQCx16+M+mAatuiCnvxlQUMuMiSTNK6Amzm45u9v53nlZeY3weYMYFdHdfe1pebMiwrT7MI9clKebz6svYJVmdtXAkApDAc8VuR3WB7TgdRKNWdyGJGfoD1PO1ZE4iinOcoKV+IT1UCY99Kkgg6C7j62n/8T5OpRBvd5eBPpHxP1F9BNAkEA5Nf2VO9lcTetksHdIeKK+F7sio6UZn0Rv7iUo3ALrN1D1cGfWIh2dj3ko1iSreyNVSwGW0ePP27qDmU+u6/Y1g==", - "public": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+W6scd3XWwvC/hPRksfDYFi3ztgyS9OSqnnjtNQeDdTSD1DRx/xFar2wjmzxp2+SnJ5pspaF77VZveN3P/HVmXZVghr3asoV9WBx/uW1nDIUxU35L4juXiTwsMAbgMyh3NqIKTNKyMDy4P8vpEhtH1iv/BrwMdBjHDVCycB8WnwIDAQAB", + "private": "MIICXgIBAAKBgQC+W6scd3XWwvC/hPRksfDYFi3ztgyS9OSqnnjtNQeDdTSD1DRx/Y1g==", + "public": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+W6scd3XWwvC/==", selector: "hello_selector", headers: "from:to:subject:date" } @@ -631,8 +631,8 @@ client.sendingDomains.update('example1.com', { client.sendingDomains.update('example1.com', { dkim: { - 'private': 'MIICXgIBAAKBgQC+W6scd3XWwvC/hPRksfDYFi3ztgyS9OSqnnjtNQeDdTSD1DRx/xFar2wjmzxp2+SnJ5pspaF77VZveN3P/HVmXZVghr3asoV9WBx/uW1nDIUxU35L4juXiTwsMAbgMyh3NqIKTNKyMDy4P8vpEhtH1iv/BrwMdBjHDVCycB8WnwIDAQABAoGBAITb3BCRPBi5lGhHdn+1RgC7cjUQEbSb4eFHm+ULRwQ0UIPWHwiVWtptZ09usHq989fKp1g/PfcNzm8c78uTS6gCxfECweFCRK6EdO6cCCr1cfWvmBdSjzYhODUdQeyWZi2ozqd0FhGWoV4VHseh4iLj36DzleTLtOZj3FhAo1WJAkEA68T+KkGeDyWwvttYtuSiQCCTrXYAWTQnkIUxduCp7Ap6tVeIDn3TaXTj74UbEgaNgLhjG4bX//fdeDW6PaK9YwJBAM6xJmwHLPMgwNVjiz3u/6fhY3kaZTWcxtMkXCjh1QE82KzDwqyrCg7EFjTtFysSHCAZxXZMcivGl4TZLHnydJUCQQCx16+M+mAatuiCnvxlQUMuMiSTNK6Amzm45u9v53nlZeY3weYMYFdHdfe1pebMiwrT7MI9clKebz6svYJVmdtXAkApDAc8VuR3WB7TgdRKNWdyGJGfoD1PO1ZE4iinOcoKV+IT1UCY99Kkgg6C7j62n/8T5OpRBvd5eBPpHxP1F9BNAkEA5Nf2VO9lcTetksHdIeKK+F7sio6UZn0Rv7iUo3ALrN1D1cGfWIh2dj3ko1iSreyNVSwGW0ePP27qDmU+u6/Y1g==', - 'public': 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+W6scd3XWwvC/hPRksfDYFi3ztgyS9OSqnnjtNQeDdTSD1DRx/xFar2wjmzxp2+SnJ5pspaF77VZveN3P/HVmXZVghr3asoV9WBx/uW1nDIUxU35L4juXiTwsMAbgMyh3NqIKTNKyMDy4P8vpEhtH1iv/BrwMdBjHDVCycB8WnwIDAQAB', + 'private': 'MIICXgIBAAKBgQC+W6scd3XWwvC/hPRksfDYFi3ztgyS9OSqnnjtNQeDdTSD1DRx/Y1g==', + 'public': 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+W6scd3XWwvC/==', selector: 'hello_selector', headers: 'from:to:subject:date' } @@ -1297,7 +1297,7 @@ client.transmissions.send({ "X-Customer-Campaign-ID": "christmas_campaign" }, text: "Hi {{address.name}} \nSave big this Christmas in your area {{place}}! \nClick http://www.mysite.com and get huge discount\n Hurry, this offer is only to {{customer_type}}\n {{sender}}", - html: "

Hi {{address.name}} \nSave big this Christmas in your area {{place}}! \nClick http://www.mysite.com and get huge discount\n

Hurry, this offer is only to {{customer_type}}\n

{{sender}}

" + html: "

Hi {{address.name}} \nSave big this Christmas in your area {{place}}! \nClick http://www.mysite.com and get huge discount\n

" } }, function(err, res) { if (err) { @@ -1496,7 +1496,7 @@ client.transmissions.send({ 'X-Customer-Campaign-ID': 'christmas_campaign' }, text: 'Hi {{address.name}} \nSave big this Christmas in your area {{place}}! \nClick http://www.mysite.com and get huge discount\n Hurry, this offer is only to {{customer_type}}\n {{sender}}', - html: '

Hi {{address.name}} \nSave big this Christmas in your area {{place}}! \nClick http://www.mysite.com and get huge discount\n

Hurry, this offer is only to {{customer_type}}\n

{{sender}}

' + html: '

Hi {{address.name}} \nSave big this Christmas in your area {{place}}! \nClick http://www.mysite.com and get huge discount\n

' } }) .then(data => { @@ -1767,7 +1767,7 @@ client.webhooks.update('TEST_WEBHOOK_UUID', { }); // Callback -client.webhooks.validate('TEST_WEBHOOK_UUID',{ +client.webhooks.validate('TEST_WEBHOOK_UUID', { message: { msys: {} } diff --git a/sparkpost/tsconfig.json b/sparkpost/tsconfig.json index 0ef33f26af..e40a56608b 100644 --- a/sparkpost/tsconfig.json +++ b/sparkpost/tsconfig.json @@ -6,7 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ "../" @@ -19,4 +19,4 @@ "index.d.ts", "sparkpost-tests.ts" ] -} \ No newline at end of file +} diff --git a/sparkpost/tslint.json b/sparkpost/tslint.json new file mode 100644 index 0000000000..e77aa7b0ee --- /dev/null +++ b/sparkpost/tslint.json @@ -0,0 +1,8 @@ +{ + "extends": "../tslint.json", + "rules": { + "only-arrow-functions-2": [ + false + ] + } +} From d8cbfe8edc77885d16dab5f633df2529e795bef3 Mon Sep 17 00:00:00 2001 From: Akinmade Bond Date: Sun, 19 Mar 2017 05:44:06 +0100 Subject: [PATCH 13/19] Bump package version --- sparkpost/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sparkpost/index.d.ts b/sparkpost/index.d.ts index 56b23382fa..f16cabc3b5 100644 --- a/sparkpost/index.d.ts +++ b/sparkpost/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for sparkpost v1.3 +// Type definitions for sparkpost 2.1 // Project: https://github.com/SparkPost/node-sparkpost // Definitions by: Joshua DeVinney // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped From 75c6770274e614dcd687635264169715363749c8 Mon Sep 17 00:00:00 2001 From: Akinmade Bond Date: Sun, 19 Mar 2017 05:45:14 +0100 Subject: [PATCH 14/19] Update author header. --- sparkpost/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sparkpost/index.d.ts b/sparkpost/index.d.ts index f16cabc3b5..a12d9dbfa4 100644 --- a/sparkpost/index.d.ts +++ b/sparkpost/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for sparkpost 2.1 // Project: https://github.com/SparkPost/node-sparkpost -// Definitions by: Joshua DeVinney +// Definitions by: Joshua DeVinney , Bond // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// From ab4f1f0934f43986e4e81ab6224446d83b31a1c3 Mon Sep 17 00:00:00 2001 From: Akinmade Bond Date: Sun, 19 Mar 2017 13:12:29 +0100 Subject: [PATCH 15/19] move old typings to v1 folder Fix tests --- sparkpost/v1/index.d.ts | 1114 +++++++++++++++++++++++++++++++ sparkpost/v1/sparkpost-tests.ts | 944 ++++++++++++++++++++++++++ sparkpost/v1/tsconfig.json | 26 + 3 files changed, 2084 insertions(+) create mode 100644 sparkpost/v1/index.d.ts create mode 100644 sparkpost/v1/sparkpost-tests.ts create mode 100644 sparkpost/v1/tsconfig.json diff --git a/sparkpost/v1/index.d.ts b/sparkpost/v1/index.d.ts new file mode 100644 index 0000000000..cb7e0431f7 --- /dev/null +++ b/sparkpost/v1/index.d.ts @@ -0,0 +1,1114 @@ +/// + +import * as Request from "request"; +import * as Http from "http"; + +declare class SparkPost { + /** Specifying an inbound domain enables you to customize the address to which inbound messages are sent. */ + inboundDomains: { + /** + * List all your inbound domains. + * @param callback The request callback with Domain results array + */ + all(callback: SparkPost.ResultsCallback): void; + /** + * 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; + /** + * Create an inbound domain by providing an inbound domains object as the POST request body. + * @param domain Domain name + * @param callback The request callback + */ + create(domain: string, callback: SparkPost.Callback): void; + /** + * 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; + }; + /** The Message Events API provides the means to search the raw events generated by SparkPost. */ + messageEvents: { + /** + * Retrieves list of message events according to given params + * @param parameters Query parameters + * @param callback The request callback with MessageEvent results array + */ + search(parameters: SparkPost.MessageEventParameters, callback: SparkPost.ResultsCallback): void; + }; + /** A recipient list is a collection of recipients that can be used in a transmission. */ + recipientLists: { + /** + * List a summary of all recipient lists. The recipients for each list are not included in the results. + * To retrieve recipient details, use the RETRIEVE API for a specified recipient list. + * @param callback The request callback with RecipientList results array + */ + all(callback: SparkPost.ResultsCallback): void; + /** + * Retrieve details about a specified recipient list by specifying its id in the URI path. + * To retrieve the recipients contained in a list, the show_recipients parameter must be set to true. + * @param options The find options + * @param callback The request callback with RecipientList results + */ + find(options: { id: string, show_recipients?: false }, callback: SparkPost.Callback): void; + /** + * Retrieve details about a specified recipient list by specifying its id in the URI path. + * To retrieve the recipients contained in a list, the show_recipients parameter must be set to true. + * @param options The find options + * @param callback The request callback with RecipientList results (with recipients) + */ + find(options: { id: string, show_recipients: true }, callback: SparkPost.Callback): void; + /** + * Create a recipient list by providing a recipient list object as the POST request body. + * At a minimum, the “recipients” array is required, which must contain a valid “address”. + * If the recipient list “id” is not provided in the POST request body, one will be generated and returned in the results body. + * Use the num_rcpt_errors parameter to limit the number of recipient errors returned. + * @param options The create options + * @param callback The request callback with metadata results + */ + create(options: SparkPost.CreateRecipientList, callback: SparkPost.ResultsCallback): void; + /** + * Update an existing recipient list by specifying its ID in the URI path and use a recipient list object as the PUT request body. + * Use the num_rcpt_errors parameter to limit the number of recipient errors returned. + * @param options The update options + * @param callback The request callback with metadata results + */ + update(options: SparkPost.UpdateRecipientList, callback: SparkPost.ResultsCallback): void; + /** + * Permanently delete the specified recipient list. + * @param id The list id + * @param callback The request callback + */ + delete(id: string, callback: SparkPost.Callback): void; + }; + /** Relay Webhooks are a way to instruct SparkPost to accept inbound email on your behalf and forward it to you over HTTP for your own consumption. */ + relayWebhooks: { + /** + * List all your relay webhooks. + * @param callback The request callback with RelayWebhook results array + */ + all(callback: SparkPost.ResultsCallback): void; + /** + * Delete a relay webhook by specifying the webhook ID in the URI path. + * @param relayWebhookId The webhook id + * @param callback The request callback with RelayWebhook results + */ + find(relayWebhookId: string, callback: SparkPost.ResultsCallback): void; + /** + * Create a relay webhook by providing a relay webhooks object as the POST request body. + * @param options The create options + * @param callback The request callback with webhook id results + */ + create(options: SparkPost.RelayWebhook, callback: SparkPost.ResultsCallback<{ id: string }>): void; + /** + * Update a relay webhook by specifying the webhook ID in the URI path. + * @param options The update options + * @param callback The request callback with webhook id results + */ + update(options: SparkPost.UpdateRelayWebhook & { relayWebhookId: string }, callback: SparkPost.ResultsCallback<{ id: string }>): void; + /** + * Delete a relay webhook by specifying the webhook ID in the URI path. + * @param relayWebhookId The webhook id + * @param callback The request callback + */ + delete(relayWebhookId: string, callback: SparkPost.Callback): void; + }; + sendingDomains: { + /** + * List an overview of all sending domains in the system. + * @param callback The request callback with SendingDomain results array + */ + all(callback: SparkPost.ResultsCallback): void; + /** + * Retrieve a sending domain by specifying its domain name in the URI path. The response includes details about its DKIM key configuration. + * @param domain The domain + * @param callback The request callback with SendingDomain results + */ + find(domain: string, callback: SparkPost.ResultsCallback): void; + /** + * Create a sending domain by providing a sending domain object as the POST request body. + * @param options The create options + * @param callback The request callback with basic info results + */ + create(options: SparkPost.CreateSendingDomain, callback: SparkPost.ResultsCallback<{ message: string, domain: string }>): void; + /** + * Update the attributes of an existing sending domain by specifying its domain name in the URI path and use a sending domain object as the PUT request body. + * @param options The update options + * @param callback The request callback with basic info results + */ + update(options: SparkPost.UpdateSendingDomain, callback: SparkPost.ResultsCallback<{ message: string, domain: string }>): void; + /** + * Delete an existing sending domain. + * @param domain The domain + * @param callback The request callback + */ + delete(domain: string, callback: SparkPost.Callback): void; + /** + * Verify a Sending Domain + * @param options The verify options + * @param callback The request callback with verify results + */ + verify(options: SparkPost.VerifyOptions, callback: SparkPost.ResultsCallback): void; + }; + subaccounts: { + /** + * Endpoint for retrieving a list of your subaccounts. + * This endpoint only returns information about the subaccounts themselves, not the data associated with the subaccount. + * @param callback The request callback with subaccount information results array + */ + all(callback: SparkPost.ResultsCallback): void; + /** + * + * @param subaccountId The webhook id + * @param callback The request callback with subaccount information results + */ + find(subaccountId: string | number, callback: SparkPost.ResultsCallback): void; + /** + * Provisions a new subaccount and an initial subaccount API key. + * @param options The create options + * @param callback The request callback with basic subaccount information results + */ + create(options: SparkPost.CreateSubaccount, callback: SparkPost.ResultsCallback): void; + /** + * Update an existing subaccount’s information. + * @param options The create options + * @param callback The request callback with webhook id results + */ + update(options: SparkPost.UpdateSubaccount, callback: SparkPost.ResultsCallback<{ message: string }>): void; + }; + suppressionList: { + /** + * Perform a filtered search for entries in your suppression list. + * @param parameters Object of search parameters + * @param callback The request callback with RelayWebhook results + */ + search(parameters: SparkPost.SupressionSearch, callback: SparkPost.ResultsCallback): void; + /** + * Retrieve the suppression status for a specific recipient by specifying the recipient’s email address in the URI path. + * @param email Email address to check + * @param callback The request callback with webhook id results + */ + checkStatus(email: string, callback: SparkPost.ResultsCallback): void; + /** + * Delete a recipient from the list by specifying the recipient’s email address in the URI path. + * @param email Email address to check + * @param callback The request callback + */ + removeStatus(email: string, callback: SparkPost.Callback): void; + /** + * Bulk insert or update entries in the customer-specific exclusion list. + * @param parameters The suppression entry list + * @param callback The request callback + */ + upsert(parameters: SparkPost.CreateSupressionListEntry | SparkPost.CreateSupressionListEntry[], callback: SparkPost.ResultsCallback<{ message: string }>): void; + }; + templates: { + /** + * List a summary of all templates. + * @param callback The request callback with TemplateMeta results array + */ + all(callback: SparkPost.ResultsCallback): void; + /** + * Retrieve details about a specified template by its id + * @param options The id and draft status information + * @param callback The request callback with Template results + */ + find(options: { id: string, draft?: boolean }, callback: SparkPost.ResultsCallback): void; + /** + * Create a new template + * @param options The create options + * @param callback The request callback with template id results + */ + create(options: { template: SparkPost.CreateTemplate }, callback: SparkPost.ResultsCallback<{ id: string }>): void; + /** + * Update an existing template + * @param options The create options + * @param callback The request callback with template id results + */ + update(options: { + id: string, + template: SparkPost.UpdateTemplate, + update_published?: boolean; + }, callback: SparkPost.ResultsCallback<{ id: string }>): void; + /** + * Delete an existing template + * @param id The template id + * @param callback The request callback + */ + delete(id: string, callback: SparkPost.Callback): void; + /** + * Preview the most recent version of an existing template by id + * @param options The preview options + * @param callback The request callback with webhook id results + */ + preview(options: { id: string, data: any, draft?: boolean }, callback: SparkPost.ResultsCallback): void; + }; + transmissions: { + /** + * List an overview of all transmissions in the account + * @param callback The request callback with Transmission results array + */ + all(callback: SparkPost.ResultsCallback): void; + /** + * List an overview of all transmissions in the account, with added filters + * @param options The search options { campaign_id?, template_id? } + * @param callback The request callback with Transmission results array + */ + all(options: { campaign_id?: string, template_id?: string }, callback: SparkPost.ResultsCallback): void; + /** + * Retrieve the details about a transmission by its ID + * @param transmissionID The transmission id + * @param callback The request callback with Transmission results + */ + find(transmissionID: string, callback: SparkPost.ResultsCallback): void; + /** + * Sends a message by creating a new transmission + * @param options The create options + * @param callback The request callback with metadata and id results + */ + send(options: { transmissionBody: SparkPost.CreateTransmission, num_rcpt_errors?: number }, callback: SparkPost.ResultsCallback<{ + total_rejected_recipients: number; + total_accepted_recipients: number; + id: string; + }>): void; + }; + webhooks: { + /** + * List currently existing webhooks. + * @param callback The request callback with RelayWebhook results array + */ + all(callback: SparkPost.ResultsCallback>): void; + /** + * List currently existing webhooks. + * @param options Object containing optional timezone + * @param callback The request callback with RelayWebhook results array + */ + all(options: { timezone?: string }, callback: SparkPost.ResultsCallback>): void; + /** + * Retrieve details about a specified webhook by its id + * @param options Object containing id and optional timezone + * @param callback The request callback with RelayWebhook results + */ + describe(options: { id: string, timezone?: string }, callback: SparkPost.ResultsCallback): void; + /** + * Create a new webhook + * @param options The create options + * @param callback The request callback with webhook id results + */ + create(options: SparkPost.Webhook, callback: SparkPost.ResultsCallback): void; + /** + * Update an existing webhook + * @param options The update options + * @param callback The request callback with webhook id results + */ + update(options: SparkPost.UpdateWebhook, callback: SparkPost.ResultsCallback): void; + /** + * Delete an existing webhook + * @param id The webhook id + * @param callback The request callback + */ + delete(id: string, callback: SparkPost.Callback): void; + /** + * Sends an example message event batch from the Webhook API to the target URL + * @param options The webhook id and message + * @param callback The request callback with validation results + */ + validate(options: { id: string, message: any }, callback: SparkPost.ResultsCallback<{ + msg: string; + response: { + status: number; + headers: any; + body: string; + } + }>): void; + /** + * Sends an example message event batch from the Webhook API to the target URL + * @param options The webhook id and optional limit + * @param callback The request callback with status results + */ + getBatchStatus(options: { id: string, limit?: number }, callback: SparkPost.ResultsCallback<{ + batch_id: string; + ts: string; + attempts: number; + response_code: number; + }[]>): 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 + */ + getDocumentation(callback: SparkPost.ResultsCallback): void; + /** + * List an example of the event data that will be posted by a Webhook for the specified events. + * @param callback The request callback containing examples + */ + getSamples(callback: SparkPost.Callback): void; + /** + * List an example of the event data that will be posted by a Webhook for the specified events. + * @param options The optional event name + * @param callback The request callback containing examples + */ + getSamples(options: { events?: string }, callback: SparkPost.Callback): void; + }; + + /** + * The official Node.js binding for your favorite SparkPost APIs! + * @param apiKey A passed in apiKey will take precedence over an environment variable + * @param options Additional options + */ + constructor(apiKey?: string, options?: SparkPost.ConstructorOptions); + + request(options: Request.Options, callback: SparkPost.Callback): void; + get(options: Request.Options, callback: SparkPost.Callback): void; + post(options: Request.Options, callback: SparkPost.Callback): void; + put(options: Request.Options, callback: SparkPost.Callback): void; + delete(options: Request.Options, callback: SparkPost.Callback): void; +} + +declare namespace SparkPost { + + export interface ErrorWithDescription { + message: string; + code: string; + description: string; + } + export interface ErrorWithParam { + message: string; + param: string; + value: string | null; + } + export interface SparkPostError extends Error { + name: "SparkPostError"; + errors: ErrorWithDescription[] | ErrorWithParam[]; + statusCode: number; + } + + export interface ConstructorOptions { + origin?: string; + endpoint?: string; + apiVersion?: string; + headers?: any; + } + + export interface Response extends Http.IncomingMessage { + body: T; + } + export interface Callback { + (err: Error | SparkPostError | null, res: Response): void; + } + export type ResultsCallback = Callback<{ results: T }>; + + export interface Domain { + domain: string; + } + + export interface MessageEvent { + /** Type of event this record describes */ + type: string; + /** Classification code for a given message (see [Bounce Classification Codes](https://support.sparkpost.com/customer/portal/articles/1929896)) */ + bounce_class: string; + /** Campaign of which this message was a part */ + campaign_id: string; + /** SparkPost-customer identifier through which this message was sent */ + customer_id: string; + /** Protocol by which SparkPost delivered this message */ + delv_method: string; + /** Token of the device / application targeted by this PUSH notification message. Applies only when delv_method is gcm or apn. */ + device_token: string; + /** Error code by which the remote server described a failed delivery attempt */ + error_code: string; + /** IP address of the host to which SparkPost delivered this message; in engagement events, the IP address of the host where the HTTP request originated */ + ip_address: string; + /** SparkPost-cluster-wide unique identifier for this message */ + message_id: string; + /** Sender address used on this message"s SMTP envelope */ + msg_from: string; + /** Message"s size in bytes */ + msg_size: string; + /** Number of failed attempts before this message was successfully delivered; when the first attempt succeeds, zero */ + num_retries: string; + /** Metadata describing the message recipient */ + rcpt_meta: any; + /** Tags applied to the message which generated this event */ + rcpt_tags: string[]; + /** Recipient address used on this message"s SMTP envelope */ + rcpt_to: string; + /** Indicates that a recipient address appeared in the Cc or Bcc header or the archive JSON array */ + rcpt_type: string; + /** Unmodified, exact response returned by the remote server due to a failed delivery attempt */ + raw_reason: string; + /** Canonicalized text of the response returned by the remote server due to a failed delivery attempt */ + reason: string; + /** Domain receiving this message */ + routing_domain: string; + /** Subject line from the email header */ + subject: string; + /** Slug of the template used to construct this message */ + template_id: string; + /** Version of the template used to construct this message */ + template_version: string; + /** Event date and time formatted as: YYYY-MM-DDTHH:MM:SS.SSS±hh:mm */ + timestamp: string; + /** Transmission which originated this message */ + transmission_id: string; + } + + export interface MessageEventParameters { + /** delimited list of bounce classification codes to search. (See Bounce Classification Codes.) */ + bounce_classes?: Array | string | number; + /** delimited list of campaign ID’s to search (i.e. the campaign id used during creation of a transmission). */ + campaign_ids?: string[] | string; + /** Specifies the delimiter for query parameter lists */ + delimiter?: string; + /** delimited list of event types to search. Defaults to all event types. */ + events?: string[] | string; + /** delimited list of friendly from emails to search. */ + friendly_froms?: string[] | string; + /** Datetime in format of YYYY-MM-DDTHH:MM. */ + from?: string; + /** delimited list of message ID’s to search. */ + message_ids?: string[] | string; + /** The results page number to return. Used with per_page for paging through results. */ + page?: number; + /** Number of results to return per page. Must be between 1 and 10,000 (inclusive). */ + per_page?: number; + /** Bounce/failure/rejection reason that will be matched using a wildcard (e.g., %reason%). */ + reason?: string[] | string; + /** delimited list of recipients to search. */ + recipients?: string[] | string; + /** delimited list of subaccount ID’s to search. */ + subaccounts?: number[] | number; + /** delimited list of template ID’s to search. */ + template_ids?: string[] | string; + /** Standard timezone identification string. */ + timezone?: string; + /** Datetime in format of YYYY-MM-DDTHH:MM. */ + to?: string; + /** delimited list of transmission ID’s to search (i.e. id generated during creation of a transmission). */ + transmission_ids?: string[] | string; + } + + export interface RecipientListMetadata { + total_rejected_recipients: number; + total_accepted_recipients: number; + id: string; + name: string; + } + + export interface RecipientList { + /** Short, unique, recipient list identifier */ + id: string; + /** Short, pretty/readable recipient list display name, not required to be unique */ + name: string; + /** Detailed description of the recipient list */ + description: string; + /** Recipient list attribute object */ + attributes: any; + /** Number of accepted recipients */ + total_accepted_recipients: number; + } + export interface RecipientListWithRecipients extends RecipientList { + /** Array of recipient objects */ + recipients: Recipient[]; + } + + export interface CreateRecipientList { + /** Short, unique, recipient list identifier */ + id?: string; + /** Short, pretty/readable recipient list display name, not required to be unique */ + name?: string; + /** Detailed description of the recipient list */ + description?: string; + /** Recipient list attribute object */ + attributes?: any; + /** limit the number of recipient errors returned. */ + num_rcpt_errors?: number; + /** Array of recipient objects */ + recipients: Recipient[]; + } + export interface UpdateRecipientList { + /** Short, unique, recipient list identifier */ + id?: string; + /** Short, pretty/readable recipient list display name, not required to be unique */ + name?: string; + /** Detailed description of the recipient list */ + description?: string; + /** Recipient list attribute object */ + attributes?: any; + /** limit the number of recipient errors returned. */ + num_rcpt_errors?: number; + /** Array of recipient objects */ + recipients?: Recipient[]; + } + + export interface BaseRecipient { + /** SparkPost Enterprise API only. Email to use for envelope FROM. */ + return_path?: string; + /** Array of text labels associated with a recipient. */ + tags?: string[]; + /** Key/value pairs associated with a recipient. */ + metadata?: any; + /** Key/value pairs associated with a recipient that are provided to the substitution engine. */ + substitution_data?: any; + } + export interface RecipientWithAddress { + /** Address information for a recipient At a minimum, address or multichannel_addresses is required. */ + address: Address | string; + } + export interface RecipientWithMultichannelAddresses { + /** + * Address information for a recipient. + * At a minimum, address or multichannel_addresses is required. + * If both address and multichannel_addresses are specified only multichannel_addresses will be used. + * + * @type {(Address | string)} + * @memberOf RecipientWithMultichannelAddresses + */ + address?: Address | string; + /** + * Array of Multichannel Address objects for a recipient. + * At a minimum, address or multichannel_addresses is required. + * If both address and multichannel_addresses are specified only multichannel_addresses will be used. + * + * @type {MultichannelAddress[]} + * @memberOf RecipientWithMultichannelAddresses + */ + multichannel_addresses: MultichannelAddress[]; + } + export type Recipient = (RecipientWithAddress | RecipientWithMultichannelAddresses) & BaseRecipient; + + export interface Address { + /** Valid email address */ + email: string; + /** User-friendly name for the email address */ + name?: string; + /** Email address to display in the “To” header instead of address.email (for CC and BCC) */ + header_to?: string; + } + + export interface MultichannelAddress { + /** The communication channel used to reach recipient. Valid values are “email”, “gcm”, “apns”. */ + channel: string; + /** Valid email address. Required if channel is “email”. */ + email: string; + /** User-friendly name for the email address. Used when channel is “email” */ + name: string; + /** Email address to display in the “To” header instead of address.email (for BCC). Used when channel is “email” */ + header_to: string; + /** SparkPost Enterprise API only. Required if channel is “gcm” or “apns” */ + token: string; + /** SparkPost Enterprise API only. Required if channel is “gcm” or “apns” */ + app_id: string; + } + + export interface RelayWebhook { + /** User-friendly name no example: Inbound Customer Replies */ + name?: string; + /** URL of the target to which to POST relay batches */ + target: string; + /** Authentication token to present in the X-MessageSystems-Webhook-Token header of POST requests to target */ + auth_token?: string; + /** Restrict which inbound messages will be relayed to the target */ + match: Match; + } + + export interface UpdateRelayWebhook { + /** User-friendly name no example: Inbound Customer Replies */ + name?: string; + /** URL of the target to which to POST relay batches */ + target?: string; + /** Authentication token to present in the X-MessageSystems-Webhook-Token header of POST requests to target */ + auth_token?: string; + /** Restrict which inbound messages will be relayed to the target */ + match?: Match; + } + + export interface Match { + /** Inbound messaging protocol associated with this webhook. Defaults to “SMTP” */ + protocol?: string; + /** Inbound domain associated with this webhook. Required when protocol is “SMTP”. */ + domain?: string; + /** ESME address binding associated with this webhook yes, when protocol is “SMPP”. SparkPost Enterprise API only. */ + esme_address?: string; + } + + export interface SendingDomain { + /** Name of the sending domain. */ + domain: string; + /** Associated tracking domain. */ + tracking_domain: string; + /** JSON object containing status details, including whether this domain’s ownership has been verified. */ + status: Status; + /** JSON object in which DKIM key configuration is defined. */ + dkim?: DKIM; + /** Whether to generate a DKIM keypair on creation. */ + generate_dkim?: boolean; + /** Size, in bits, of the DKIM private key to be generated. This option only applies if generate_dkim is ‘true’. */ + dkim_key_length?: number; + /** Setting to true allows this domain to be used by subaccounts. Defaults to false, only available to domains belonging to a master account. */ + shared_with_subaccounts: boolean; + } + + export interface CreateSendingDomain { + /** Name of the sending domain. */ + domain: string; + /** Associated tracking domain. */ + tracking_domain?: string; + /** JSON object containing status details, including whether this domain’s ownership has been verified. */ + status?: Status; + /** JSON object in which DKIM key configuration is defined. */ + dkim?: DKIM; + /** Whether to generate a DKIM keypair on creation. */ + generate_dkim?: boolean; + /** Size, in bits, of the DKIM private key to be generated. This option only applies if generate_dkim is ‘true’. */ + dkim_key_length?: number; + /** Setting to true allows this domain to be used by subaccounts. Defaults to false, only available to domains belonging to a master account. */ + shared_with_subaccounts?: boolean; + } + + export interface UpdateSendingDomain { + /** Name of the sending domain. */ + domain: string; + /** Associated tracking domain. */ + tracking_domain?: string; + /** JSON object in which DKIM key configuration is defined. */ + dkim?: DKIM; + /** Whether to generate a DKIM keypair on creation. */ + generate_dkim?: boolean; + /** Size, in bits, of the DKIM private key to be generated. This option only applies if generate_dkim is ‘true’. */ + dkim_key_length?: number; + /** Setting to true allows this domain to be used by subaccounts. Defaults to false, only available to domains belonging to a master account. */ + shared_with_subaccounts?: boolean; + } + + export interface DKIM { + /** Signing Domain Identifier (SDID). SparkPost Enterprise API only. */ + signing_domain?: string; + /** DKIM private key. */ + private?: string; + /** DKIM public key. */ + public: string; + /** DomainKey selector. */ + selector: string; + /** Header fields to be included in the DKIM signature. This field is currently ignored. */ + headers?: string; + } + + export interface Status { + /** Whether domain ownership has been verified */ + ownership_verified: boolean; + /** Verification status of SPF configuration */ + spf_status: "valid" | "invalid" | "unverified" | "pending"; + /** Compliance status */ + compliance_status: "valid" | "pending" | "blocked"; + /** Verification status of DKIM configuration */ + dkim_status: "valid" | "invalid" | "unverified" | "pending"; + /** Verification status of abuse@ mailbox */ + abuse_at_status: "valid" | "invalid" | "unverified" | "pending"; + /** Verification status of postmaster@ mailbox */ + postmaster_at_status: "valid" | "invalid" | "unverified" | "pending"; + } + + export interface VerifyOptions { + domain: string; + verifyDKIM?: boolean; + verifySPF?: boolean; + } + + export interface VerifyResults extends Status { + dns?: { + dkim_record: string; + spf_record: string; + }; + } + + export interface CreateSubaccount { + /** user-friendly name */ + name: string; + /** user-friendly identifier for subaccount API key */ + keyLabel: string; + /** list of grants to give the subaccount API key */ + keyGrants: string[]; + /** list of IPs the subaccount may be used from */ + keyValidIps?: string[]; + /** id of the default IP pool assigned to subaccount"s transmissions */ + ipPool?: string; + } + + export interface CreateSubaccountResponse { + subaccount_id: number; + key: string; + label: string; + short_key: string; + } + + export interface UpdateSubaccount { + /** the id of the subaccount you want to update */ + subaccountId: string | number; + /** user-friendly name */ + name: string; + /** status of the subaccount */ + status: string; + /** id of the default IP pool assigned to subaccount"s transmissions */ + ipPool?: string; + } + + export interface SubaccountInformation { + /** ID of subaccount */ + id: number; + /** User friendly identifier for a specific subaccount */ + name: string; + /** Status of the account */ + status: "active" | "suspended" | "terminated"; + /** The ID of the default IP Pool assigned to this subaccount’s transmissions */ + ip_pool?: string; + compliance_status: string; + } + + export interface CreateSupressionListEntry { + recipient: string; + /** Whether the recipient requested to not receive any transactional messages. At a minimum, transactional or non_transactional is required upon creation of the entry. */ + transactional?: boolean; + /** Whether the recipient requested to not receive any non-transactional messages. At a minimum, transactional or non_transactional is required upon creation of the entry. */ + non_transactional?: boolean; + /** Short explanation of the suppression */ + description?: string; + } + + export interface SupressionListEntry { + recipient: string; + /** Whether the recipient requested to not receive any transactional messages. At a minimum, transactional or non_transactional is required upon creation of the entry. */ + transactional?: boolean; + /** Whether the recipient requested to not receive any non-transactional messages. At a minimum, transactional or non_transactional is required upon creation of the entry. */ + non_transactional?: boolean; + /** Coming soon */ + type?: "transactional" | "non_transactional"; + /** Source responsible for inserting the list entry. Valid values include: Spam Complaint, List Unsubscribe, Bounce Rule, Unsubscribe Link, Manually Added, Compliance. */ + source?: string; + /** Short explanation of the suppression */ + description?: string; + created: string; + updated: string; + } + + export interface SupressionSearch { + /** Datetime the entries were last updated, in the format of YYYY-MM-DDTHH:mm:ssZ */ + to?: string; + /** Datetime the entries were last updated, in the format YYYY-MM-DDTHH:mm:ssZ */ + from?: string; + /** Types of entries to include in the search, i.e. entries with “transactional” and/or “non_transactional” keys set to true */ + types?: string; + /** Sources of the entries to include in the search, i.e. entries that were added by this source */ + sources?: string; + /** Maximum number of results to return. Must be between 1 and 100000. Default value is 100000. */ + limit?: number; + } + + export interface TemplateContent { + /** HTML content for the email’s text/html MIME part */ + html: string; + /** Text content for the email’s text/plain MIME part */ + text: string; + /** Email subject line. */ + subject: string; + /** + * Address “from” : "deals@company.com" or JSON object composed of the “name” and “email” fields + * “from” : { “name” : “My Company”, “email” : "deals@company.com" } used to compose the email’s “From” header. + * + * @type {(Address | string)} + * @memberOf CreateTemplateContent + */ + from: Address | string; + /** Email address used to compose the email’s “Reply-To” header. */ + reply_to?: string; + /** JSON dictionary containing headers other than “Subject”, “From”, “To”, and “Reply-To”. */ + headers?: any; + } + + export interface CreateTemplateContent { + /** HTML content for the email’s text/html MIME part */ + html?: string; + /** Text content for the email’s text/plain MIME part */ + text?: string; + /** Email subject line. */ + subject: string; + /** + * Address “from” : "deals@company.com" or JSON object composed of the “name” and “email” fields + * “from” : { “name” : “My Company”, “email” : "deals@company.com" } used to compose the email’s “From” header. + * + * @type {(Address | string)} + * @memberOf CreateTemplateContent + */ + from: Address | string; + /** Email address used to compose the email’s “Reply-To” header. */ + reply_to?: string; + /** JSON dictionary containing headers other than “Subject”, “From”, “To”, and “Reply-To”. */ + headers?: any; + } + + export interface TemplateMeta { + /** Unique template ID */ + id: string; + /** Template name */ + name: string; + /** Published state of the template (true = published, false = draft) */ + published: boolean; + /** Template description */ + description: string; + } + + export interface Template { + /** + * Short, unique, alphanumeric ID used to reference the template. + * At a minimum, id or name is required upon creation. It is auto generated if not provided. + * After a template has been created, this property cannot be changed. Maximum length - 64 bytes + * + * @type {string} + * @memberOf CreateTemplate + */ + id: string; + /** Content that will be used to construct a message yes For a full description, see the Content Attributes. Maximum length - 20 MBs */ + content: TemplateContent | { email_rfc822: string }; + /** Whether the template is published or is a draft version no - defaults to false A template cannot be changed from published to draft. */ + published: boolean; + /** Editable display name At a minimum, id or name is required upon creation. The name does not have to be unique. Maximum length - 1024 bytes */ + name: string; + /** Detailed description of the template no Maximum length - 1024 bytes */ + description: string; + /** JSON object in which template options are defined no For a full description, see the Options Attributes. */ + options: TemplateOptions; + /** The “last_update_time” is the time the template was last updated, for both draft and published versions */ + last_update_time: string; + /** The “last_use” time represents the last time any version of this template was used (draft or published). */ + last_use?: string; + } + + export interface CreateTemplate { + /** + * Short, unique, alphanumeric ID used to reference the template. + * At a minimum, id or name is required upon creation. It is auto generated if not provided. + * After a template has been created, this property cannot be changed. Maximum length - 64 bytes + * + * @type {string} + * @memberOf CreateTemplate + */ + id?: string; + /** Content that will be used to construct a message yes For a full description, see the Content Attributes. Maximum length - 20 MBs */ + content: CreateTemplateContent | { email_rfc822: string }; + /** Whether the template is published or is a draft version no - defaults to false A template cannot be changed from published to draft. */ + published?: boolean; + /** Editable display name At a minimum, id or name is required upon creation. The name does not have to be unique. Maximum length - 1024 bytes */ + name?: string; + /** Detailed description of the template no Maximum length - 1024 bytes */ + description?: string; + /** JSON object in which template options are defined no For a full description, see the Options Attributes. */ + options?: CreateTemplateOptions; + } + + export interface UpdateTemplate { + /** Content that will be used to construct a message yes For a full description, see the Content Attributes. Maximum length - 20 MBs */ + content?: CreateTemplateContent | { email_rfc822: string }; + /** Whether the template is published or is a draft version no - defaults to false A template cannot be changed from published to draft. */ + published?: boolean; + /** Editable display name At a minimum, id or name is required upon creation. The name does not have to be unique. Maximum length - 1024 bytes */ + name?: string; + /** Detailed description of the template no Maximum length - 1024 bytes */ + description?: string; + /** JSON object in which template options are defined no For a full description, see the Options Attributes. */ + options?: CreateTemplateOptions; + } + + export interface TemplateOptions { + /** Enable or disable open tracking */ + open_tracking: boolean; + /** Enable or disable click tracking */ + click_tracking: boolean; + /** Distinguish between transactional and non-transactional messages for unsubscribe and suppression purposes */ + transactional: boolean; + } + + export interface CreateTemplateOptions { + /** Enable or disable open tracking */ + open_tracking?: boolean; + /** Enable or disable click tracking */ + click_tracking?: boolean; + /** Distinguish between transactional and non-transactional messages for unsubscribe and suppression purposes */ + transactional?: boolean; + } + + export interface CreateTransmission { + /** JSON object in which transmission options are defined */ + options?: TransmissionOptions; + /** Inline recipient objects or object containing stored recipient list ID */ + recipients?: Recipient[] | { list_id: string }; + /** Name of the campaign */ + campaign_id?: string; + /** Description of the transmission */ + description?: string; + /** Transmission level metadata containing key/value pairs */ + metadata?: any; + /** Key/value pairs that are provided to the substitution engine */ + substitution_data?: any; + /** SparkPost Enterprise API only: email to use for envelope FROM */ + return_path?: string; + /** Content that will be used to construct a message */ + content: InlineContent | { template_id: string, use_draft_template?: boolean } | { email_rfc822: string }; + } + + export interface TransmissionSummary { + /** ID of the transmission */ + id: string; + /** State of the transmission */ + state: "submitted" | "Generating" | "Success" | "Canceled"; + /** Description of the transmission */ + description: string; + /** Name of the campaign */ + campaign_id: string; + /** Content that will be used to construct a message */ + content: { template_id: string }; + } + + export interface Transmission { + /** ID of the transmission */ + id: string; + /** State of the transmission */ + state: "submitted" | "Generating" | "Success" | "Canceled"; + /** JSON object in which transmission options are defined */ + options: TransmissionOptions; + /** Name of the campaign */ + campaign_id: string; + /** Description of the transmission */ + description: string; + /** Transmission level metadata containing key/value pairs */ + metadata: any; + /** Key/value pairs that are provided to the substitution engine */ + substitution_data: any; + /** Content that will be used to construct a message */ + content: InlineContent | { template_id: string, use_draft_template?: boolean } | { email_rfc822: string }; + /** Computed total number of messages generated */ + num_generated: number; + /** Computed total number of failed messages */ + num_failed_generation: number; + /** Number of recipients that failed input validation */ + num_invalid_recipients: number; + rcpt_list_chunk_size: number; + rcpt_list_total_chunks: number; + } + + export interface TransmissionOptions { + /** Delay generation of messages until this datetime. */ + start_time?: string; + /** Whether open tracking is enabled for this transmission */ + open_tracking?: boolean; + /** Whether click tracking is enabled for this transmission */ + click_tracking?: boolean; + /** Whether message is transactional or non-transactional for unsubscribe and suppression purposes */ + transactional?: boolean; + /** Whether or not to use the sandbox sending domain */ + sandbox?: boolean; + /** SparkPost Enterprise API only: Whether or not to ignore customer suppression rules, for this transmission only. Only applicable if your configuration supports this parameter. */ + skip_suppression?: boolean; + /** The ID of a dedicated IP pool associated with your account ( Note: SparkPost only ). */ + ip_pool?: string; + /** Whether or not to perform CSS inlining in HTML content */ + inline_css?: boolean; + } + + export interface InlineContent { + /** HTML content for the email’s text/html MIME part At a minimum, html, text, or push is required. */ + html?: string; + /** Text content for the email’s text/plain MIME part At a minimum, html, text, or push is required. */ + text?: string; + /** Content of push notifications At a minimum, html, text, or push is required. SparkPost Enterprise API only. */ + push?: PushData; + /** Email subject line required for email transmissions Expected in the UTF-8 charset without RFC2047 encoding. Substitution syntax is supported. */ + subject?: string; + /** "deals@company.com" or JSON object composed of the “name” and “email” fields “from” : { “name” : “My Company”, “email” : "deals@company.com" } used to compose the email’s “From” header */ + from?: string | { email: string, name: string }; + /** Email address used to compose the email’s “Reply-To” header */ + reply_to?: string; + /** JSON dictionary containing headers other than “Subject”, “From”, “To”, and “Reply-To” */ + headers?: any; + /** JSON array of attachments. */ + attachments?: Attachment[]; + /** JSON array of inline images. */ + inline_images?: Attachment[]; + } + + export interface PushData { + /** payload for APNs messages */ + apns?: any; + /** payload for GCM messages */ + gcm?: any; + } + + export interface Attachment { + /** + * The MIME type of the attachment; e.g., “text/plain”, “image/jpeg”, “audio/mp3”, “video/mp4”, “application/msword”, “application/pdf”, etc., + * including the “charset” parameter (text/html; charset=“UTF-8”) if needed. + * The value will apply “as-is” to the “Content-Type” header of the generated MIME part for the attachment. + * + * @type {string} + * @memberOf Attachment + */ + type: string; + /** The filename of the attachment (for example, “document.pdf”). This is inserted into the filename parameter of the Content-Disposition header. */ + name: string; + /** + * The content of the attachment as a Base64 encoded string. + * The string should not contain \r\n line breaks. + * The SparkPost systems will add line breaks as necessary to ensure the Base64 encoded lines contain no more than 76 characters each. + * + * @type {string} + * @memberOf Attachment + */ + data: string; + } + + export interface Webhook { + /** User-friendly name for webhook */ + name: string; + /** URL of the target to which to POST event batches */ + target: string; + /** Array of event types this webhook will receive */ + events: string[]; + /** Type of authentication to be used during POST requests to target */ + auth_type?: string; + /** Object containing details needed to request authorization credentials, as necessary */ + auth_request_details?: any; + /** Object containing credentials needed to make authorized POST requests to target */ + auth_credentials?: any; + /** Authentication token to present in the X-MessageSystems-Webhook-Token header of POST requests to target */ + auth_token?: string; + } + + export interface UpdateWebhook { + id: string; + /** User-friendly name for webhook */ + name?: string; + /** URL of the target to which to POST event batches */ + target?: string; + /** Array of event types this webhook will receive */ + events?: string[]; + /** Type of authentication to be used during POST requests to target */ + auth_type?: string; + /** Object containing details needed to request authorization credentials, as necessary */ + auth_request_details?: any; + /** Object containing credentials needed to make authorized POST requests to target */ + auth_credentials?: any; + /** Authentication token to present in the X-MessageSystems-Webhook-Token header of POST requests to target */ + auth_token?: string; + } + + export interface WebhookLinks { + links: { + href: string; + rel: string; + method: string[]; + }[]; + } +} + +export = SparkPost; diff --git a/sparkpost/v1/sparkpost-tests.ts b/sparkpost/v1/sparkpost-tests.ts new file mode 100644 index 0000000000..0b8a41ab0a --- /dev/null +++ b/sparkpost/v1/sparkpost-tests.ts @@ -0,0 +1,944 @@ +import * as SparkPost from "sparkpost"; + +let key = "YOURAPIKEY"; +let client = new SparkPost(key); + +client.get({ + uri: "metrics/domains" +}, function(err, data) { + if (err) { + console.log(err); + return; + } + + console.log(data.body); +}); + +client.inboundDomains.create("example1.com", function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our client library!"); + } +}); + +client.inboundDomains.delete("example1.com", function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our client library!"); + } +}); + +client.inboundDomains.find("example1.com", function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our client library!"); + } +}); + +client.inboundDomains.all(function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our client library!"); + } +}); + +client.messageEvents.search({}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.messageEvents.search({ + events: "click", + campaign_ids: "monday_mailshot" +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.messageEvents.search({ + from: "2016-01-01T00:00", + to: "2016-01-02T23:59", + page: 1, + per_page: 5, + events: ["bounce", "out_of_band"], + bounce_classes: [10] +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.recipientLists.create({ + id: "UNIQUE_TEST_ID", + name: "Test Recipient List", + recipients: [ + { + address: { + email: "test1@test.com" + } + }, { + address: { + email: "test2@test.com" + } + }, { + address: { + email: "test3@test.com" + } + } + ] +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.recipientLists.delete("UNIQUE_TEST_ID", function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.recipientLists.all(function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.recipientLists.find({ + id: "UNIQUE_TEST_ID" +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.recipientLists.find({ + id: "UNIQUE_TEST_ID", + show_recipients: true +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.recipientLists.update({ + id: "EXISTING_TEST_ID", + name: "Test Recipient List", + recipients: [ + { + address: { + email: "test1@test.com" + } + }, { + address: { + email: "test2@test.com" + } + }, { + address: { + email: "test3@test.com" + } + } + ] +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.relayWebhooks.create({ + name: "Test Relay Webhook", + target: "http://client.test.com/test-webhook", + match: { + domain: "inbound.example.com" + } +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our client library!"); + } +}); + +client.relayWebhooks.delete("123456789", function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our client library!"); + } +}); + +client.relayWebhooks.find("123456789", function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our client library!"); + } +}); + +client.relayWebhooks.all(function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our client library!"); + } +}); + +client.relayWebhooks.update({ + relayWebhookId: "123456789", + target: "http://client.test.com/test-webhook" +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our client library!"); + } +}); + +client.sendingDomains.create({ + domain: "example1.com", + dkim: { + "private": "MIICXgIBAAKBgQC+W6scd3XWwvC//Y1g==", + "public": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+W6scd3XWwvC/==", + selector: "brisbane", + headers: "from:to:subject:date" + } +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + + +client.sendingDomains.delete("example1.com", function(err, data) { + if (err) { + console.log(err); + } else { + console.log(data); + console.log("Congrats you can use our client library!"); + } +}); + +client.sendingDomains.all(function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.sendingDomains.find("example1.com", function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.sendingDomains.update({ + domain: "example1.com", + dkim: { + "private": "MIICXgIBAAKBgQC+W6scd3XWwvC/hPRksfDYFi3ztgyS9OSqnnjtNQeDdTSD1DRx//Y1g==", + "public": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+W6scd3XWwvC/==", + selector: "hello_selector", + headers: "from:to:subject:date" + } +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.sendingDomains.verify({ + domain: "example1.com" +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.sendingDomains.verify({ + domain: "example1.com", + verifySPF: false +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.sendingDomains.verify({ + domain: "example1.com", + verifyDKIM: false +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.subaccounts.create({ + name: "Test Subaccount", + keyLabel: "Test Subaccount key", + keyGrants: [ + "smtp/inject", + "transmissions/modify" + ] +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res); + console.log("Congrats you can use our client library!"); + } +}); + +client.subaccounts.all(function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our client library!"); + } +}); + +client.subaccounts.find(123, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our client library!"); + } +}); + +client.subaccounts.update({ + subaccountId: 123, + name: "Test Subaccount", + status: "suspended" +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our client library!"); + } +}); + +client.suppressionList.checkStatus("test@test.com", function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our client library!"); + } +}); + +client.suppressionList.removeStatus("test@test.com", function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our client library!"); + } +}); + +client.suppressionList.search({ + from: "2015-05-07T00:00:00+0000", + to: "2015-05-07T23:59:59+0000", + limit: 5 +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our client library!"); + } +}); + +client.suppressionList.upsert([ + { + recipient: "test1@test.com", + transactional: false, + non_transactional: true, + description: "Test description 1" + }, + { + recipient: "test2@test.com", + transactional: true, + non_transactional: true, + description: "Test description 2" + }, + { + recipient: "test3@test.com", + transactional: true, + non_transactional: false, + description: "Test description 3" + } +], function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our client library!"); + } +}); + +client.templates.create({ + template: { + id: "TEST_ID", + name: "Test Template", + content: { + from: "test@test.com", + subject: "Test email template!", + html: "This is a test email template!" + } + } +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.templates.delete("TEST_ID", function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + + +client.templates.all(function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.templates.find({ + id: "TEST_ID", + draft: true +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.templates.find({ + id: "TEST_ID" +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.templates.preview({ + id: "TEST_ID", + data: {} +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.templates.update({ + id: "TEST_ID", + template: { + content: { + from: "test@test.com", + subject: "Updated Published Test email template!", + html: "This is a published test email template! Updated!" + } + }, + update_published: true +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.templates.update({ + id: "TEST_ID", + template: { + content: { + from: "test@test.com", + subject: "Updated Test email template!", + html: "This is a test email template! Updated!" + } + } +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.transmissions.all(function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.transmissions.find("YOUR-TRANSMISSION-KEY", function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.transmissions.all({ + campaign_id: "my_campaign" +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.transmissions.all({ + template_id: "my_template" +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.transmissions.send({ + transmissionBody: { + recipients: [{ address: { email: "john.doe@example.com" } }], + content: { + from: "From Envelope ", + subject: "Example Email for MIME Parts", + html: "

Hello World!

", + text: "Hello World!" + }, + options: { + open_tracking: true, + click_tracking: true + } + } +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.transmissions.send({ + transmissionBody: { + recipients: [{address: {email: "john.doe@example.com"}}], + content: { + email_rfc822: "Content-Type: text/plain\nFrom: From Envelope \nSubject: Example Email\n\nHello World" + } + } +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.transmissions.send({ + transmissionBody: { + options: { + open_tracking: true, + click_tracking: true + }, + campaign_id: "christmas_campaign", + return_path: "bounces-christmas-campaign@flintstone.com", + metadata: { + user_type: "students" + }, + substitution_data: { + sender: "Big Store Team" + }, + recipients: [ + { + return_path: "123@bounces.flintstone.com", + address: { + email: "wilma@flintstone.com", + name: "Wilma Flintstone" + }, + tags: [ + "greeting", + "prehistoric", + "fred", + "flintstone" + ], + metadata: { + place: "Bedrock" + }, + substitution_data: { + customer_type: "Platinum" + } + } + ], + content: { + from: { + name: "Fred Flintstone", + email: "fred@flintstone.com" + }, + subject: "Big Christmas savings!", + reply_to: "Christmas Sales ", + headers: { + "X-Customer-Campaign-ID": "christmas_campaign" + }, + text: "Hi {{address.name}} \nSave big this Christmas in your area {{place}}! \nClick http://www.mysite.com and get huge discount\n Hurry, this offer is only to {{customer_type}}\n {{sender}}", + html: "

Hi {{address.name}} \nSave big this Christmas in your area {{place}}! \nClick http://www.mysite.com and get huge discount\n

" + } + } +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.transmissions.send({ + transmissionBody: { + recipients: [ + { + address: { + email: "original.recipient@example.com", + name: "Original Recipient" + }, + substitution_data: { + recipient_type: "Original" + } + }, + { + address: { + email: "bcc.recipient@example.com", + header_to: "\"Original Recipient\" " + }, + substitution_data: { + recipient_type: "BCC" + } + } + ], + content: { + from: { + name: "Node BCC Test", + email: "from@example.com" + }, + subject: "Example email using bcc", + text: "An example email using bcc with SparkPost to the {{recipient_type}} recipient.", + html: "

An example email using bcc with SparkPost to the {{recipient_type}} recipient.

" + } + } +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats! You sent an email with bcc using SparkPost!"); + } +}); + +client.transmissions.send({ + transmissionBody: { + recipients: [ + { + address: { + email: "original.recipient@example.com", + name: "Original Recipient" + }, + substitution_data: { + recipient_type: "Original" + } + }, + { + address: { + email: "cc.recipient@example.com", + name: "Carbon Copy Recipient", + header_to: "\"Original Recipient\" " + }, + substitution_data: { + recipient_type: "CC" + } + } + ], + content: { + from: { + name: "Node CC Test", + email: "from@example.com" + }, + headers: { + "CC": "\"Carbon Copy Recipient\" " + }, + subject: "Example email using cc", + text: "An example email using cc with SparkPost to the {{recipient_type}} recipient.", + html: "

An example email using cc with SparkPost to the {{recipient_type}} recipient.

" + } + } +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats! You sent an email with cc using SparkPost!"); + } +}); + +client.transmissions.send({ + transmissionBody: { + recipients: { + list_id: "example-list" + }, + content: { + from: "From Envelope ", + subject: "Example Email for Stored List and Inline Content", + html: "

Hello World

", + text: "Hello World!" + } + } +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.transmissions.send({ + transmissionBody: { + recipients: { + list_id: "example-list" + }, + content: { + from: "From Envelope ", + subject: "Example Email for Stored List and Template", + template_id: "my-template" + } + } +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.transmissions.send({ + num_rcpt_errors: 3, + transmissionBody: { + campaign_id: "ricks-campaign", + content: { + template_id: "ricks-template" + }, + recipients: [{ address: { email: "rick.sanchez@rickandmorty100years.com", name: "Rick Sanchez" } }] + } +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("What up my glib globs! SparkPost!"); + } +}); + +client.webhooks.create({ + name: "Test webhook", + target: "http://client.test.com/test-webhook", + auth_token: "AUTH_TOKEN", + events: [ + "delivery", + "injection", + "open", + "click" + ] +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.webhooks.delete("TEST_WEBHOOK_UUID", function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.webhooks.describe({ + id: "TEST_WEBHOOK_UUID", + timezone: "America/New_York" +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.webhooks.getBatchStatus({ + id: "TEST_WEBHOOK_UUID", + limit: 1000 +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + + +client.webhooks.getDocumentation(function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.webhooks.getSamples({ + events: "bounce" +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.webhooks.all(function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.webhooks.update({ + id: "TEST_WEBHOOK_UUID", + name: "Renamed Test webhook", + events: [ + "policy_rejection", + "delay" + ] +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); + +client.webhooks.validate({ + id: "TEST_WEBHOOK_UUID", + message: { + msys: {} + } +}, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(res.body); + console.log("Congrats you can use our SDK!"); + } +}); diff --git a/sparkpost/v1/tsconfig.json b/sparkpost/v1/tsconfig.json new file mode 100644 index 0000000000..54f30b3435 --- /dev/null +++ b/sparkpost/v1/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "paths": { + "sparkpost": ["sparkpost/v1"], + "sparkpost/*": ["sparkpost/v1/*"] + }, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "sparkpost-tests.ts" + ] +} From 12b979da39e9f8ad1efa335923dbfb9c20cb7c33 Mon Sep 17 00:00:00 2001 From: Akinmade Bond Date: Sun, 19 Mar 2017 13:17:56 +0100 Subject: [PATCH 16/19] restore type headers in v1 folder Local lint test was failing but Travis CI wants this. :meh: --- sparkpost/v1/index.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sparkpost/v1/index.d.ts b/sparkpost/v1/index.d.ts index cb7e0431f7..b12f3712ab 100644 --- a/sparkpost/v1/index.d.ts +++ b/sparkpost/v1/index.d.ts @@ -1,3 +1,8 @@ +// Type definitions for sparkpost v1.3 +// Project: https://github.com/SparkPost/node-sparkpost +// Definitions by: Joshua DeVinney +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + /// import * as Request from "request"; From 4cfda1e42d32f8684db14d672d84081fec5bd080 Mon Sep 17 00:00:00 2001 From: Akinmade Bond Date: Mon, 20 Mar 2017 17:44:28 +0100 Subject: [PATCH 17/19] update recipientLists get return type Should already return ResultsPromise, must've slipped through the cracks. --- sparkpost/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sparkpost/index.d.ts b/sparkpost/index.d.ts index a12d9dbfa4..edef477f3d 100644 --- a/sparkpost/index.d.ts +++ b/sparkpost/index.d.ts @@ -116,7 +116,7 @@ declare class SparkPost { * @param {{ show_recipients?: boolean }} [options] specifies whether to retrieve the recipients. Defaults to false * @returns {Promise} */ - get(id: string, options?: { show_recipients?: boolean }): Promise; + get(id: string, options?: { show_recipients?: boolean }): SparkPost.ResultsPromise; /** * Create a recipient list by providing a recipient list object as the POST request body. * At a minimum, the “recipients” array is required, which must contain a valid “address”. From cda8d042738faf159ca32b06a47fcbf72f405881 Mon Sep 17 00:00:00 2001 From: Akinmade Bond Date: Mon, 20 Mar 2017 17:58:39 +0100 Subject: [PATCH 18/19] Add overload to suppressionList `list` [parameters](https://github.com/SparkPost/node-sparkpost/blob/master/docs/resources/suppressionList.md#methods) is an optional argument --- sparkpost/index.d.ts | 14 ++++++++++---- sparkpost/sparkpost-tests.ts | 11 +++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/sparkpost/index.d.ts b/sparkpost/index.d.ts index edef477f3d..e21cd1cf24 100644 --- a/sparkpost/index.d.ts +++ b/sparkpost/index.d.ts @@ -373,15 +373,21 @@ declare class SparkPost { /** * List all entries in your suppression list, filtered by an optional set of search parameters. * - * @param {SparkPost.SupressionSearchParameters} [parameters] an object of [search parameters]{@link https://developers.sparkpost.com/api/suppression-list#suppression-list-search-get} - * @param {Promise} [callback] + * @param {SparkPost.ResultsCallback} callback The request callback with supression lists. + */ + list(callback: SparkPost.ResultsCallback): void; + /** + * List all entries in your suppression list, filtered by an optional set of search parameters. + * + * @param {SparkPost.SupressionSearchParameters} parameters an object of [search parameters]{@link https://developers.sparkpost.com/api/suppression-list#suppression-list-search-get} + * @param {SparkPost.ResultsCallback} callback The request callback with supression lists. */ list(parameters: SparkPost.SupressionSearchParameters, callback: SparkPost.ResultsCallback): void; /** * List all entries in your suppression list, filtered by an optional set of search parameters. * * @param {SparkPost.SupressionSearchParameters} [parameters] an object of [search parameters]{@link https://developers.sparkpost.com/api/suppression-list#suppression-list-search-get} - * @returns {Promise} + * @returns {Promise} Promise The supression lists */ list(parameters?: SparkPost.SupressionSearchParameters): SparkPost.ResultsPromise; /** @@ -415,7 +421,7 @@ declare class SparkPost { /** * Insert or update one or many entries. * - * @param parameters The suppression entry list + * @param listEntries The suppression entry list * @param callback The request callback */ upsert(listEntries: SparkPost.CreateSupressionListEntry | SparkPost.CreateSupressionListEntry[], callback: SparkPost.ResultsCallback<{ message: string }>): void; diff --git a/sparkpost/sparkpost-tests.ts b/sparkpost/sparkpost-tests.ts index ac994ab31b..fdfe3e71cc 100644 --- a/sparkpost/sparkpost-tests.ts +++ b/sparkpost/sparkpost-tests.ts @@ -867,6 +867,17 @@ client.suppressionList.list({ } }); +// Callback +client.suppressionList.list(function(err, data) { + if (err) { + console.log('Whoops! Something went wrong'); + console.log(err); + } else { + console.log('Congrats you can use our client library!'); + console.log(data); + } +}); + // Promise client.suppressionList.upsert({ recipient: 'test1@test.com', From 7838fcc3407a880ef6fb7a57d801e78c4a6ab845 Mon Sep 17 00:00:00 2001 From: Akinmade Bond Date: Mon, 20 Mar 2017 18:11:41 +0100 Subject: [PATCH 19/19] fix `template preview` method. Option type is substitution_data not data --- sparkpost/index.d.ts | 6 +++--- sparkpost/sparkpost-tests.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sparkpost/index.d.ts b/sparkpost/index.d.ts index e21cd1cf24..fc6e408949 100644 --- a/sparkpost/index.d.ts +++ b/sparkpost/index.d.ts @@ -535,7 +535,7 @@ declare class SparkPost { * @param options The preview options * @param callback The request callback with webhook id results */ - preview(id: string, options: { data: any, draft?: boolean }, callback: SparkPost.ResultsCallback): void; + preview(id: string, options: { substitution_data?: any, draft?: boolean }, callback: SparkPost.ResultsCallback): void; /** * Preview the most recent version of an existing template by id * @@ -547,10 +547,10 @@ declare class SparkPost { * Preview the most recent version of an existing template by id * * @param {string} id the id of the template you want to look up - * @param {{ data: any, draft?: boolean }} [options] + * @param {{ substitution_data: any, draft?: boolean }} [options] * @returns {SparkPost.ResultsPromise} The webhook id results */ - preview(id: string, options?: { data: any, draft?: boolean }): SparkPost.ResultsPromise; + preview(id: string, options?: { substitution_data?: any, draft?: boolean }): SparkPost.ResultsPromise; }; transmissions: { /** diff --git a/sparkpost/sparkpost-tests.ts b/sparkpost/sparkpost-tests.ts index fdfe3e71cc..d3fef264f0 100644 --- a/sparkpost/sparkpost-tests.ts +++ b/sparkpost/sparkpost-tests.ts @@ -1084,7 +1084,7 @@ client.templates.get('TEST_ID') // Callback client.templates.preview('TEST_ID', { - data: {} + substitution_data: {} }, function(err, res) { if (err) { console.log(err); @@ -1096,7 +1096,7 @@ client.templates.preview('TEST_ID', { // Promise client.templates.preview('TEST_ID', { - data: { + substitution_data: { name: 'Natalie', age: 35, member: true