Add types for sailthru-client (#39338)

* Add types for sailthru-client

* Avoid exporting RestlerResult interface from sailthru-client
This commit is contained in:
Sergey Smolnikov
2019-10-23 15:06:55 -07:00
committed by Wesley Wigham
parent c70314f567
commit 75e31b0a42
4 changed files with 1007 additions and 0 deletions
+683
View File
@@ -0,0 +1,683 @@
// Type definitions for sailthru-client 3.0
// Project: https://github.com/sailthru/sailthru-node-client
// Definitions by: Sergey Smolnikov <https://github.com/smolnikov>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
import * as Restler from "restler";
import * as http from "http";
export {};
interface RestlerResult {
on(eventName: string, listener: (data?: any, response?: http.ServerResponse) => void): RestlerResult;
}
export type SailthruError = {
statusCode: string,
error: string,
errormsg: string
} | null;
export interface PurchaseItem {
qty: number;
title: string;
price: number;
id: string | number;
url: string;
tags?: string[];
vars?: object;
images?: {
full?: {
url: string
},
thumb?: {
url: string
}
};
}
export type SailthruResponse = object | string;
export type SailthruCallback = (err: SailthruError, response: SailthruResponse) => void;
/**
* API client version
*/
export const VERSION: string;
export function createSailthruClient(apiKey: string, apiSecret: string, apiUrl?: string): SailthruClient;
export function createClient(apiKey: string, apiSecret: string, apiUrl?: string): SailthruClient;
export interface SailthruClient {
logging: boolean;
/**
* Enable Logging
*/
enableLogging(): void;
/**
* Disable Logging
*/
disableLogging(): void;
/**
* Perform an arbitrary API GET request to Sailthru.
* @param action the API endpoint to send a request to
* @param data provide the API options, as outlined in the GET section of the documentation for that endpoint
* @param callback a standard callback function which will be invoked after the API server responds
*/
apiGet(
action: string,
data: object,
callback: SailthruCallback
): void;
/**
* Perform an arbitrary API DELETE request to Sailthru.
* @param action the API endpoint to send a request to
* @param data provide the API options, as outlined in the DELETE section of the documentation for that endpoint
* @param callback a standard callback function which will be invoked after the API server responds
*/
apiDelete(
action: string,
data: object,
callback?: SailthruCallback
): void;
/**
* Perform an arbitrary API POST request to Sailthru.
* @param action the API endpoint to send a request to
* @param data provide the API options, as outlined in the POST section of the documentation for that endpoint
* @param callback a standard callback function which will be invoked after the API server responds
*/
apiPost(
action: string,
data: object,
callback: SailthruCallback
): void;
/**
* Perform an arbitrary API POST request to Sailthru.
* @param action the API endpoint to send a request to
* @param data provide the API options, as outlined in the POST section of the documentation for that endpoint
* @param binary_data_params used to specify file upload details. Should be an array which includes strings, corresponding to fields in the “options” parameter that should be read in as files
* @param callback a standard callback function which will be invoked after the API server responds
*/
apiPost(
action: string,
data: object,
binary_data_params: string[],
callback: SailthruCallback
): void | RestlerResult;
/**
* Perform multipart API POST request to Sailthru
* @param action the API endpoint to send a request to
* @param data provide the API options, as outlined in the POST section of the documentation for that endpoint
* @param binary_data_params used to specify file upload details. Should be an array which includes strings, corresponding to fields in the “options” parameter that should be read in as files
* @param callback a standard callback function which will be invoked after the API server responds
*/
apiPostMultiPart(
action: string,
data: object,
binary_data_param: string[],
callback: SailthruCallback
): RestlerResult;
/**
* Send a single message to email, using the given template.
* @param template Name of the template to use as the basis for the message content
* @param email valid email address to send the message to
* @param callback a standard callback function which will be invoked after the API server responds
*/
send(
template: string,
email: string,
callback: SailthruCallback
): void;
/**
* Send a single message to email, using the given template.
* @param template Name of the template to use as the basis for the message content
* @param email valid email address to send the message to
* @param options a Javascript object that can be used to specify any other valid API parameters for the send POST,
* the full list is available https://getstarted.sailthru.com/new-for-developers-overview/email-and-user-profiles/send/
* @param callback a standard callback function which will be invoked after the API server responds
*/
send(
template: string,
email: string,
options: object,
callback: SailthruCallback
): void;
/**
* Send a message to each of the “emails” specified, using the given “template”.
* @param template Name of the template to use as the basis for the message content
* @param emails valid email addresses to send the message to. This can be either a comma-separated String, or a Javascript Array.
* @param callback a standard callback function which will be invoked after the API server responds
*/
multiSend(
template: string,
emails: string | string[],
callback: SailthruCallback
): void;
/**
* Send a message to each of the “emails” specified, using the given “template”.
* @param template Name of the template to use as the basis for the message content
* @param emails valid email addresses to send the message to. This can be either a comma-separated String, or a Javascript Array.
* @param options a Javascript object that can be used to specify any other valid API parameters for the send POST,
* the full list is available https://getstarted.sailthru.com/new-for-developers-overview/email-and-user-profiles/send/
* @param callback a standard callback function which will be invoked after the API server responds
*/
multiSend(
template: string,
emails: string[],
options: object,
callback: SailthruCallback
): void;
/**
* Looks up the delivery status of a particular send, by its “send_id”.
* @param send_id the send ID which was in the response of a previous send call
* @param callback a standard callback function which will be invoked after the API server responds
*/
getSend(
send_id: string,
callback: SailthruCallback
): void;
/**
* Cancels the scheduled send which is identified by “send_id”. Note that you can only cancel sends which were scheduled in the future with the “schedule_time” parameters.
* @param send_id the send ID which was in the response of a previous send call
* @param callback a standard callback function which will be invoked after the API server responds
*/
cancelSend(
send_id: string,
callback: SailthruCallback
): void;
/**
* Return a user profile by looking up via a Sailthru ID (sid).
* @param sid the sailthru id for a given user
* @param callback a standard callback function which will be invoked after the API server responds
*/
getUserBySid(
sid: string,
callback: SailthruCallback
): void;
/**
* Return a user profile by looking up via a given key and ID.
* @param id the id for a given user
* @param key specify which type of key was provided in the “id” parameter
* @param callback a standard callback function which will be invoked after the API server responds
*/
getUserByKey(
id: string,
key: string,
callback: SailthruCallback
): void;
/**
* Return a user profile by looking up via a given key and ID.
* @param id the id for a given user
* @param key specify which type of key was provided in the “id” parameter
* @param fields specify which fields to return. Options are documented here https://getstarted.sailthru.com/new-for-developers-overview/email-and-user-profiles/user/#fieldstype
* @param callback a standard callback function which will be invoked after the API server responds
*/
getUserByKey(
id: string,
key: string,
fields: object,
callback: SailthruCallback
): void;
/**
* Update a user profile.
* @param sid the sailthru id for a given user
* @param options provide user API options, as outlined in the user POST documentation
* @param callback a standard callback function which will be invoked after the API server responds
*/
saveUserBySid(
sid: string,
options: object,
callback: SailthruCallback
): void | RestlerResult;
/**
* Update a user profile.
* @param id the id for a given user
* @param key specify which type of key was provided in the “id” parameter
* @param options provide user API options, as outlined in the user POST documentation
* @param callback a standard callback function which will be invoked after the API server responds
*/
saveUserByKey(
id: string,
key: string,
options: object,
callback: SailthruCallback
): void | RestlerResult;
/**
* Looks up the details about a particular campaign, using blast ID.
* @param blastId the blast ID which was in the response of a previous blast call
* @param callback a standard callback function which will be invoked after the API server responds
*/
getBlast(
blastId: string | number,
callback: SailthruCallback
): void;
/**
* Delete a previously created campaign, by blast ID. This cannot be undone.
* @param blastId the blast ID which was in the response of a previous blast call
* @param callback a standard callback function which will be invoked after the API server responds
*/
deleteBlast(
blastId: string | number,
callback: SailthruCallback
): void;
/**
* Unschedule a previously scheduled campaign, by blast ID.
* @param blastId the blast ID which was in the response of a previous blast call
* @param callback a standard callback function which will be invoked after the API server responds
*/
unscheduleBlast(
blastId: string | number,
callback: SailthruCallback
): void;
/**
* Pause a currently sending created campaign, by blast ID.
* @param blastId the blast ID which was in the response of a previous blast call
* @param callback a standard callback function which will be invoked after the API server responds
*/
pauseBlast(
blastId: string | number,
callback: SailthruCallback
): void;
/**
* Resume a previously paused campaign, by blast ID.
* @param blastId the blast ID which was in the response of a previous blast call
* @param callback a standard callback function which will be invoked after the API server responds
*/
resumeBlast(
blastId: string | number,
callback: SailthruCallback
): void;
/**
* Cancel a campaign which is currently sending, by blast ID. This cannot be undone.
* @param blastId the blast ID which was in the response of a previous blast call
* @param callback a standard callback function which will be invoked after the API server responds
*/
cancelBlast(
blastId: string | number,
callback: SailthruCallback
): void;
/**
* Modify an existing campaign by setting any field.
* @param blastId the blast ID which was in the response of a previous blast call
* @param callback a standard callback function which will be invoked after the API server responds
*/
updateBlast(
blastId: string | number,
callback: SailthruCallback
): void;
/**
* Modify an existing campaign by setting any field.
* @param blastId the blast ID which was in the response of a previous blast call
* @param options provide additional blast API options, as outlined in the blast POST documentation
* @param callback a standard callback function which will be invoked after the API server responds
*/
updateBlast(
blastId: string | number,
options: object,
callback: SailthruCallback
): void;
/**
* Modify an existing campaign by copying data into it from a Template, and then scheduling it.
* @param blastId the blast ID which was in the response of a previous blast call
* @param template the name of a template to copy from, as the basis for this campaign
* @param list the target list for the campaign
* @param scheduleTime when the campaign should be sent
* @param callback a standard callback function which will be invoked after the API server responds
*/
scheduleBlastFromTemplate(
blastId: string | number,
template: string,
list: string,
scheduleTime: string,
callback: SailthruCallback
): void;
/**
* Modify an existing campaign by copying data into it from a Template, and then scheduling it.
* @param blastId the blast ID which was in the response of a previous blast call
* @param template the name of a template to copy from, as the basis for this campaign
* @param list the target list for the campaign
* @param scheduleTime when the campaign should be sent
* @param options provide additional blast API options, as outlined in the blast POST documentation
* @param callback a standard callback function which will be invoked after the API server responds
*/
scheduleBlastFromTemplate(
blastId: string | number,
template: string,
list: string,
scheduleTime: string,
options: object,
callback: SailthruCallback
): void;
/**
* Modify an existing campaign by setting any field.
* @param blastId the blast ID which was in the response of a previous blast call
* @param scheduleTime when the campaign should be sent
* @param callback a standard callback function which will be invoked after the API server responds
*/
scheduleBlastFromBlast(
blastId: string | number,
scheduleTime: string,
callback: SailthruCallback
): void;
/**
* Modify an existing campaign by setting any field.
* @param blastId the blast ID which was in the response of a previous blast call
* @param scheduleTime when the campaign should be sent
* @param options provide additional blast API options, as outlined in the blast POST documentation
* @param callback a standard callback function which will be invoked after the API server responds
*/
scheduleBlastFromBlast(
blastId: string | number,
scheduleTime: string,
options: object,
callback: SailthruCallback
): void;
/**
* Schedule a new campaign.
* @param name the name for the campaign, which will be used to identify it in Campaign Reporting
* @param list the target list for the campaign
* @param scheduleTime when the campaign should be sent
* @param fromName the from name for the email campaign
* @param fromEmail the from email for the email campaign
* @param subject the email subject line for the campaign
* @param contentHtml the content of the email body, for the HTML version of the campaign
* @param contentText the content of the email body, for the Text version of the campaign
* @param callback a standard callback function which will be invoked after the API server responds
*/
scheduleBlast(
name: string,
list: string,
scheduleTime: string,
fromName: string,
fromEmail: string,
subject: string,
contentHtml: string,
contentText: string,
callback: SailthruCallback
): void;
/**
* Schedule a new campaign.
* @param name the name for the campaign, which will be used to identify it in Campaign Reporting
* @param list the target list for the campaign
* @param scheduleTime when the campaign should be sent
* @param fromName the from name for the email campaign
* @param fromEmail the from email for the email campaign
* @param subject the email subject line for the campaign
* @param contentHtml the content of the email body, for the HTML version of the campaign
* @param contentText the content of the email body, for the Text version of the campaign
* @param options provide additional blast API options, as outlined in the blast POST documentation
* @param callback a standard callback function which will be invoked after the API server responds
*/
scheduleBlast(
name: string,
list: string,
scheduleTime: string,
fromName: string,
fromEmail: string,
subject: string,
contentHtml: string,
contentText: string,
options: object,
callback: SailthruCallback
): void;
/**
* Create or update a template with the given name
* @param template the name of the template
* @param options any template API options, as outlined in the template POST documentation
* @param callback a standard callback function which will be invoked after the API server responds
*/
saveTemplate(
template: string,
options: object,
callback: SailthruCallback
): void;
/**
* Revert a template to one of its previous revisions.
* @param template the name of the template
* @param revision_id a revision_id of the template
* @param callback a standard callback function which will be invoked after the API server responds
*/
saveTemplateFromRevision(
template: string,
revision_id: string,
callback: SailthruCallback
): void;
/**
* Delete a template from your account. This cannot be undone.
* @param template the name of the template
* @param callbacka standard callback function which will be invoked after the API server responds
*/
deleteTemplate(
template: string,
callback: SailthruCallback
): void;
/**
* Return a list of all the lists in your account.
* @param callback a standard callback function which will be invoked after the API server responds
*/
getLists(
callback: SailthruCallback
): void;
/**
* Delete a list from your account, and remove all record of it from your user profiles. This cannot be undone.
* @param list the name of an existing list in your account
* @param callback a standard callback function which will be invoked after the API server responds
*/
deleteList(
list: string,
callback: SailthruCallback
): void;
/**
* Create a new content item.
* @param title the name of the content item being created
* @param url the URL of the content item, which will be used as its unique identifier
* @param callback a standard callback function which will be invoked after the API server responds
*/
pushContent(
title: string,
url: string,
callback: SailthruCallback
): void;
/**
* Create a new content item.
* @param title the name of the content item being created
* @param url the URL of the content item, which will be used as its unique identifier
* @param options provide additional content API options, as outlined in the content POST documentation
* @param callback a standard callback function which will be invoked after the API server responds
*/
pushContent(
title: string,
url: string,
options: object,
callback: SailthruCallback
): void;
/**
* Record a purchase into the Sailthru system.
* @param email the email of the user who made the purchase
* @param items a description of what items the user purchased. See the examples on the main Purchase API page
* @param callback a standard callback function which will be invoked after the API server responds
*/
purchase(
email: string,
items: PurchaseItem[],
callback: SailthruCallback
): void;
/**
* Record a purchase into the Sailthru system.
* @param email the email of the user who made the purchase
* @param items a description of what items the user purchased. See the examples on the main Purchase API page
* @param options provide additional purchase API options, as outlined in the purchase POST documentation
* @param callback a standard callback function which will be invoked after the API server responds
*/
purchase(
email: string,
items: PurchaseItem[],
options: object,
callback: SailthruCallback
): void;
/**
* Fetch stats for any part of Sailthru.
* @param data provide stats API options, as outlined in the stats GET documentation
* @param callback a standard callback function which will be invoked after the API server responds
*/
stats(
data: object,
callback: SailthruCallback
): void;
/**
* Fetch stats for a List within Sailthru.
* @param options provide stats API options, as outlined in the stats GET documentation
* @param callback a standard callback function which will be invoked after the API server responds
*/
statsList(
options: object,
callback: SailthruCallback
): void;
/**
* Fetch stats for a campaign send, or aggregate campaign data over a time period.
* @param options provide stats API options, as outlined in the stats GET documentation
* @param callback a standard callback function which will be invoked after the API server responds
*/
statsBlast(
options: object,
callback: SailthruCallback
): void;
/**
* Fetch the status of a job
* @param job the job ID which was returned from a previous job POST
* @param callback a standard callback function which will be invoked after the API server responds
*/
getJobStatus(
job: string,
callback: SailthruCallback
): void;
/**
* Create a new job with specific options.
* @param job the name of the job to create
* @param callback a standard callback function which will be invoked after the API server responds
*/
processJob(
job: string,
callback: SailthruCallback
): void;
/**
* Create a new job with specific options.
* @param job the name of the job to create
* @param options provide additional job API options, as outlined in the job POST documentation
* @param callback a standard callback function which will be invoked after the API server responds
*/
processJob(
job: string,
options: object,
callback: SailthruCallback
): void;
/**
* Create a new job with specific options.
* @param job the name of the job to create
* @param options provide additional job API options, as outlined in the job POST documentation
* @param report_email the email address that will be emailed when the job completes or fails
* @param callback a standard callback function which will be invoked after the API server responds
*/
processJob(
job: string,
options: object,
report_email: string,
callback: SailthruCallback
): void;
/**
* Create a new job with specific options.
* @param job the name of the job to create
* @param options provide additional job API options, as outlined in the job POST documentation
* @param report_email the email address that will be emailed when the job completes or fails
* @param postback_url the URL which will receive postback data when the job completes or fails
* @param callback a standard callback function which will be invoked after the API server responds
*/
processJob(
job: string,
options: object,
report_email: string,
postback_url: string,
callback: SailthruCallback
): void;
/**
* Create a new job with specific options.
* @param job the name of the job to create
* @param options provide additional job API options, as outlined in the job POST documentation
* @param report_email the email address that will be emailed when the job completes or fails
* @param postback_url the URL which will receive postback data when the job completes or fails
* @param binary_data_params used to specify file upload details. Should be an array which includes strings, corresponding to fields in the “options” parameter that should be read in as files.
* @param callback a standard callback function which will be invoked after the API server responds
*/
processJob(
job: string,
options: object,
report_email: string,
postback_url: string,
binary_data_params: string[],
callback: SailthruCallback
): void;
receiveOptoutPost(): void;
/**
* Retrieve the last known rate limit information for the given action / method combination
* @param action API action to get rate limit information
* @param method API method to get rate limit information
*/
getLastRateLimitInfo(action: string, method: string): {
limit: number,
remaining: number,
reset: number
};
}
@@ -0,0 +1,297 @@
import { createSailthruClient } from "sailthru-client";
// create client instance
const sailthru = createSailthruClient('api_key', 'api_secret');
// enable and disable logging
sailthru.enableLogging();
sailthru.disableLogging();
// send GET request
sailthru.apiGet('purchase', {
purchase_id: '5520b3b39759105e4aa4e69f',
purchase_key: 'sid'
}, (err, response) => {
// handle response
});
// send POST request
sailthru.apiPost('blast', {
copy_blast: 123,
name: 'my copy'
}, (err, response) => {
// handle response
});
// send DELETE request
const data = {
id: "559a8fc63c8aa934460f227d"
};
sailthru.apiDelete('feed', data, (err, response) => {
// handle response
});
// get rate limit information
const rateLimitInfo = sailthru.getLastRateLimitInfo('send', 'POST');
const limitResetTime = rateLimitInfo.reset;
// send single message
sailthru.send('Abandoned Cart Reminder', 'example@example.com', (err, response) => {
// handle response
});
const welcomeOptions = {vars: {color: 'blue'}, schedule_time: 'tomorrow 5pm'};
sailthru.send('Welcome', 'example@example.com', welcomeOptions, (err, response) => {
// handle response
});
// send message to multiple emails
sailthru.multiSend('Abandoned Cart Reminder', 'example1@example.com,example2@example.com', (err, response) => {
// handle response
});
const emails = ['example1@example.com', 'example2@example.com'];
const options = { evars: {
'example1@example.com': {color: 'blue'},
'example2@example.com': {color: 'red'}
}};
sailthru.multiSend('Welcome', emails, options, (err, response) => {
// handle response
});
// check delivery status
sailthru.getSend('V-WWJIO6iCcAi0Vo', (e, r) => {
// handle response
});
// cancel scheduled send
sailthru.cancelSend('V-WWJIO6iCcAi0Vo', (e, r) => {
// handle response
});
// get status of particular job
sailthru.getJobStatus('575b100f83ba8830008b4568', (err, response) => {
// handle response
});
// get user by Sailthru ID
sailthru.getUserBySid('57e54ddc83ba8895008b4567', (e, r) => {
// handle response
});
// get user by looking up via given key and ID
sailthru.getUserByKey('example@example.com', 'email', (e, r) => {
// handle response
});
const fields = {lists: 1};
sailthru.getUserByKey('example@example.com', 'email', fields, (err, response) => {
// handle response
});
// add var to user profile
const userData = {vars: {def: 123}};
sailthru.saveUserBySid('57e54ddc83ba8895008b4567', userData, (err, response) => {
// handle response
});
const userData2 = {vars: {abc: 456}};
sailthru.saveUserByKey('example@example.com', 'email', userData2, (err, response) => {
// handle response
});
// run Jobs
const exportOptions = { list: 'VIP Users' };
sailthru.processJob('export_list_data', exportOptions, (err, response) => {
// handle response
});
const importOptions = { list: 'New List', file: '/path/to/new_users.csv' };
const report_email = 'report@example.com';
const postback_url = 'http://example.com/postback.php';
const binary_data_params = ['file'];
sailthru.processJob('import', importOptions, report_email, postback_url, binary_data_params, (err, response) => {
// handle response
});
// Look up a blast by blast_id
sailthru.getBlast(123, (e, r) => {
// handle response
});
// Delete a previously created blast by blast_id
sailthru.deleteBlast(123, (e, r) => {
// handle response
});
// Unschedule a previously scheduled blast by blast_id
sailthru.unscheduleBlast(123, (e, r) => {
// handle response
});
// Pause a currently sending campaign by blast_id
sailthru.pauseBlast(123, (e, r) => {
// handle response
});
// Resume a previously paused campaign by blast_id
sailthru.resumeBlast(123, (e, r) => {
// handle response
});
// Cancel a sending blast by blast_id
sailthru.cancelBlast(123, (e, r) => {
// handle response
});
// Enable link tracking on a campaign
const blastOptions = {
is_link_tracking: 1
};
sailthru.updateBlast(123, blastOptions, (err, response) => {
// Handle response
});
// Modify a campaign with data copied from “Welcome” template and send in 2 hours
const blastList = 'clicked';
sailthru.scheduleBlastFromTemplate(123, 'Welcome', blastList, '+2 hours', (err, response) => {
// Handle response
});
// Modify a campaign with data copied from “Welcome” template and send in 2 hours, while also setting a report email
const blastOptions2 = {
report_email: 'example@example.com'
};
sailthru.scheduleBlastFromTemplate(123, 'Welcome', blastList, '+2 hours', blastOptions2, (err, response) => {
// Handle response
});
// Schedule an existing campaign to send now
sailthru.scheduleBlastFromBlast(123, 'now', (err, response) => {
// Handle response
});
// Schedule a campaign to send now while also setting the suppress_list using options object
const blastOptions3 = {
suppress_list: ['100users', 'domain']
};
sailthru.scheduleBlastFromBlast(123, 'now', blastOptions3, (err, response) => {
// Handle response
});
// Delete a template called “test template”
sailthru.deleteTemplate('test template', (e, r) => {
// handle response
});
// Return all lists in your account
sailthru.getLists((e, r) => {
// handle response
});
// Delete a list called “test list”
sailthru.deleteList('test list', (e, r) => {
// handle response
});
// Schedule a campaign without using the optional options object
const name = 'my campaign';
const list = 'clicked';
const scheduleTime = '+2 hours';
const fromName = 'Example User';
const fromEmail = 'example@example.com';
const subject = 'my test send';
const contentHtml = '<p>This is a test</p>{beacon}';
const contentText = 'this is a test';
const scheduleBlastOptions = {
suppress_list: ['100users', 'domain']
};
sailthru.scheduleBlast(name, list, scheduleTime, fromName, fromEmail, subject, contentHtml, contentText, (err, response) => {
// Handle response
});
// Schedule a campaign using the options object
sailthru.scheduleBlast(name, list, scheduleTime, fromName, fromEmail, subject, contentHtml, contentText, scheduleBlastOptions, (err, response) => {
// Handle response
});
// Create a new content item
const title = 'my new content';
const url = 'http://test.com/my-new-content';
sailthru.pushContent(title, url, (err, response) => {
// handle response
});
// Create a new content item with certain tags
const contentOptions = {
tags: ['new', 'exciting', 'shoes']
};
sailthru.pushContent(title, url, contentOptions, (err, response) => {
// handle response
});
// Register a purchase for a single product, without any extra options
const items = [
{
qty: 1,
title: "product1",
url: "https://www.example.com/product1",
price: 10000,
id: "id1"
}
];
sailthru.purchase('example@example.com', items, (err, response) => {
// handle response
});
// Register a purchase for two products, including a coupon code var
const newItems = [
{
qty: 2,
title: "Water Bottle",
price: 1099,
id: 1234,
url: "https://example.com/1234/water_bottle"
},
{
qty: 1,
title: "product1",
url: "https://www.example.com/product1",
price: 10000,
id: "id1"
}
];
const purchaseOptions = {
vars: { coupon_code: 'xyz' }
};
sailthru.purchase('example@example.com', newItems, purchaseOptions, (err, response) => {
// handle response
});
// Get stats for the performance of the “Welcome” template over a certain month
const statsData = {
stat: 'send',
template: 'Welcome',
start_date: '2016-10-01',
end_date: '2016-10-31'
};
sailthru.stats(statsData, (err, response) => {
console.log(response);
});
// Get stats for the performance of the “clicked” list on a certain day
const statsOptions = {date: '2016-04-15', list: 'clicked'};
sailthru.statsList(statsOptions, (err, response) => {
// handle response
});
// Get stats for the engagement level performance of campaigns over a certain month
const statsOptions2 = {start_date: '-3 months', end_date: 'today', engagement: 1};
sailthru.statsBlast(statsOptions2, (err, response) => {
// handle response
});
// Get subject line performance for a particular campaign
const statsOptions3 = {blast_id: 225, subject: 1};
sailthru.statsBlast(statsOptions3, (err, response) => {
console.log(err);
console.log(response);
});
+24
View File
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"sailthru-client-tests.ts"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}